]> Pileus Git - ~andy/gtk/blob - gtk/gtkfilechooserprivate.h
change file_exists_and_is_not_folder checks to get the file info for the
[~andy/gtk] / gtk / gtkfilechooserprivate.h
1 /* GTK - The GIMP Toolkit
2  * gtkfilechooserprivate.h: Interface definition for file selector GUIs
3  * Copyright (C) 2003, Red Hat, Inc.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 #ifndef __GTK_FILE_CHOOSER_PRIVATE_H__
22 #define __GTK_FILE_CHOOSER_PRIVATE_H__
23
24 #include "gtkfilechooser.h"
25 #include "gtkfilesystem.h"
26 #include "gtkfilesystemmodel.h"
27 #include "gtkliststore.h"
28 #include "gtktooltips.h"
29 #include "gtktreemodelsort.h"
30 #include "gtktreestore.h"
31 #include "gtktreeview.h"
32 #include "gtkvbox.h"
33
34 G_BEGIN_DECLS
35
36 #define GTK_FILE_CHOOSER_GET_IFACE(inst)  (G_TYPE_INSTANCE_GET_INTERFACE ((inst), GTK_TYPE_FILE_CHOOSER, GtkFileChooserIface))
37
38 typedef struct _GtkFileChooserIface GtkFileChooserIface;
39
40 struct _GtkFileChooserIface
41 {
42   GTypeInterface base_iface;
43
44   /* Methods
45    */
46   gboolean       (*set_current_folder)     (GtkFileChooser    *chooser,
47                                             const GtkFilePath *path,
48                                             GError           **error);
49   GtkFilePath *  (*get_current_folder)     (GtkFileChooser    *chooser);
50   void           (*set_current_name)       (GtkFileChooser    *chooser,
51                                             const gchar       *name);
52   gboolean       (*select_path)            (GtkFileChooser    *chooser,
53                                             const GtkFilePath *path,
54                                             GError           **error);
55   void           (*unselect_path)          (GtkFileChooser    *chooser,
56                                             const GtkFilePath *path);
57   void           (*select_all)             (GtkFileChooser    *chooser);
58   void           (*unselect_all)           (GtkFileChooser    *chooser);
59   GSList *       (*get_paths)              (GtkFileChooser    *chooser);
60   GtkFilePath *  (*get_preview_path)       (GtkFileChooser    *chooser);
61   GtkFileSystem *(*get_file_system)        (GtkFileChooser    *chooser);
62   void           (*add_filter)             (GtkFileChooser    *chooser,
63                                             GtkFileFilter     *filter);
64   void           (*remove_filter)          (GtkFileChooser    *chooser,
65                                             GtkFileFilter     *filter);
66   GSList *       (*list_filters)           (GtkFileChooser    *chooser);
67   gboolean       (*add_shortcut_folder)    (GtkFileChooser    *chooser,
68                                             const GtkFilePath *path,
69                                             GError           **error);
70   gboolean       (*remove_shortcut_folder) (GtkFileChooser    *chooser,
71                                             const GtkFilePath *path,
72                                             GError           **error);
73   GSList *       (*list_shortcut_folders)  (GtkFileChooser    *chooser);
74   
75   /* Signals
76    */
77   void (*current_folder_changed) (GtkFileChooser *chooser);
78   void (*selection_changed)      (GtkFileChooser *chooser);
79   void (*update_preview)         (GtkFileChooser *chooser);
80   void (*file_activated)         (GtkFileChooser *chooser);
81   GtkFileChooserConfirmation (*confirm_overwrite) (GtkFileChooser *chooser);
82 };
83
84 GtkFileSystem *_gtk_file_chooser_get_file_system         (GtkFileChooser    *chooser);
85 gboolean       _gtk_file_chooser_set_current_folder_path (GtkFileChooser    *chooser,
86                                                           const GtkFilePath *path,
87                                                           GError           **error);
88 GtkFilePath *  _gtk_file_chooser_get_current_folder_path (GtkFileChooser    *chooser);
89 gboolean       _gtk_file_chooser_select_path             (GtkFileChooser    *chooser,
90                                                           const GtkFilePath *path,
91                                                           GError           **error);
92 void           _gtk_file_chooser_unselect_path           (GtkFileChooser    *chooser,
93                                                           const GtkFilePath *path);
94 GSList *       _gtk_file_chooser_get_paths               (GtkFileChooser    *chooser);
95 GtkFilePath *  _gtk_file_chooser_get_preview_path        (GtkFileChooser    *chooser);
96 gboolean       _gtk_file_chooser_add_shortcut_folder     (GtkFileChooser    *chooser,
97                                                           const GtkFilePath *path,
98                                                           GError           **error);
99 gboolean       _gtk_file_chooser_remove_shortcut_folder  (GtkFileChooser    *chooser,
100                                                           const GtkFilePath *path,
101                                                           GError           **error);
102
103 /* GtkFileChooserDialog private */
104
105 struct _GtkFileChooserDialogPrivate
106 {
107   GtkWidget *widget;
108   
109   char *file_system;
110
111   /* for use with GtkFileChooserEmbed */
112   gint default_width;
113   gint default_height;
114   gboolean resize_horizontally;
115   gboolean resize_vertically;
116   gboolean response_requested;
117 };
118
119
120 /* GtkFileChooserWidget private */
121
122 struct _GtkFileChooserWidgetPrivate
123 {
124   GtkWidget *impl;
125
126   char *file_system;
127 };
128
129
130 /* GtkFileChooserDefault private */
131
132 typedef enum {
133   LOAD_EMPTY,                   /* There is no model */
134   LOAD_PRELOAD,                 /* Model is loading and a timer is running; model isn't inserted into the tree yet */
135   LOAD_LOADING,                 /* Timeout expired, model is inserted into the tree, but not fully loaded yet */
136   LOAD_FINISHED                 /* Model is fully loaded and inserted into the tree */
137 } LoadState;
138
139 typedef enum {
140   RELOAD_EMPTY,                 /* No folder has been set */
141   RELOAD_HAS_FOLDER,            /* We have a folder, although it may not be completely loaded yet; no need to reload */
142   RELOAD_WAS_UNMAPPED           /* We had a folder but got unmapped; reload is needed */
143 } ReloadState;
144
145 typedef enum {
146   LOCATION_MODE_PATH_BAR,
147   LOCATION_MODE_FILENAME_ENTRY
148 } LocationMode;
149
150 struct _GtkFileChooserDefault
151 {
152   GtkVBox parent_instance;
153
154   GtkFileChooserAction action;
155
156   GtkFileSystem *file_system;
157
158   /* Save mode widgets */
159   GtkWidget *save_widgets;
160
161   GtkWidget *save_folder_label;
162   GtkWidget *save_folder_combo;
163   GtkWidget *save_expander;
164
165   /* The file browsing widgets */
166   GtkWidget *browse_widgets;
167   GtkWidget *browse_shortcuts_tree_view;
168   GtkWidget *browse_shortcuts_add_button;
169   GtkWidget *browse_shortcuts_remove_button;
170   GtkWidget *browse_shortcuts_popup_menu;
171   GtkWidget *browse_shortcuts_popup_menu_remove_item;
172   GtkWidget *browse_shortcuts_popup_menu_rename_item;
173   GtkWidget *browse_files_tree_view;
174   GtkWidget *browse_files_popup_menu;
175   GtkWidget *browse_files_popup_menu_add_shortcut_item;
176   GtkWidget *browse_files_popup_menu_hidden_files_item;
177   GtkWidget *browse_new_folder_button;
178   GtkWidget *browse_path_bar;
179
180   GtkFileSystemModel *browse_files_model;
181   char *browse_files_last_selected_name;
182
183   GtkWidget *filter_combo_hbox;
184   GtkWidget *filter_combo;
185   GtkWidget *preview_box;
186   GtkWidget *preview_label;
187   GtkWidget *preview_widget;
188   GtkWidget *extra_align;
189   GtkWidget *extra_widget;
190
191   GtkWidget *location_button;
192   GtkWidget *location_entry_box;
193   GtkWidget *location_label;
194   GtkWidget *location_entry;
195   LocationMode location_mode;
196
197   GtkListStore *shortcuts_model;
198   GtkTreeModel *shortcuts_filter_model;
199
200   GtkTreeModelSort *sort_model;
201
202   /* Handles */
203   GSList *loading_shortcuts;
204   GSList *reload_icon_handles;
205   GtkFileSystemHandle *file_list_drag_data_received_handle;
206   GtkFileSystemHandle *update_current_folder_handle;
207   GtkFileSystemHandle *show_and_select_paths_handle;
208   GtkFileSystemHandle *should_respond_get_info_handle;
209   GtkFileSystemHandle *file_exists_get_info_handle;
210   GtkFileSystemHandle *update_from_entry_handle;
211   GtkFileSystemHandle *shortcuts_activate_iter_handle;
212   GSList *pending_handles;
213
214   LoadState load_state;
215   ReloadState reload_state;
216   guint load_timeout_id;
217
218   GSList *pending_select_paths;
219
220   GtkFileFilter *current_filter;
221   GSList *filters;
222
223   GtkTooltips *tooltips;
224
225   gboolean has_home;
226   gboolean has_desktop;
227
228   int num_volumes;
229   int num_shortcuts;
230   int num_bookmarks;
231
232   gulong volumes_changed_id;
233   gulong bookmarks_changed_id;
234
235   GtkFilePath *current_volume_path;
236   GtkFilePath *current_folder;
237   GtkFilePath *preview_path;
238   char *preview_display_name;
239
240   GtkTreeViewColumn *list_name_column;
241   GtkCellRenderer *list_name_renderer;
242
243   GSource *edited_idle;
244   char *edited_new_text;
245
246   gulong settings_signal_id;
247   int icon_size;
248
249   gulong toplevel_set_focus_id;
250   GtkWidget *toplevel_last_focus_widget;
251
252 #if 0
253   GdkDragContext *shortcuts_drag_context;
254   GSource *shortcuts_drag_outside_idle;
255 #endif
256
257   /* Flags */
258
259   guint local_only : 1;
260   guint preview_widget_active : 1;
261   guint use_preview_label : 1;
262   guint select_multiple : 1;
263   guint show_hidden : 1;
264   guint do_overwrite_confirmation : 1;
265   guint list_sort_ascending : 1;
266   guint changing_folder : 1;
267   guint shortcuts_current_folder_active : 1;
268
269 #if 0
270   guint shortcuts_drag_outside : 1;
271 #endif
272 };
273
274
275 /* GtkFileSystemModel private */
276
277 typedef struct _FileModelNode           FileModelNode;
278
279 struct _GtkFileSystemModel
280 {
281   GObject parent_instance;
282
283   GtkFileSystem  *file_system;
284   GtkFileInfoType types;
285   FileModelNode  *roots;
286   GtkFileFolder  *root_folder;
287   GtkFilePath    *root_path;
288
289   GtkFileSystemModelFilter filter_func;
290   gpointer filter_data;
291
292   GSList *idle_clears;
293   GSource *idle_clear_source;
294
295   gushort max_depth;
296
297   GSList *pending_handles;
298   
299   guint show_hidden : 1;
300   guint show_folders : 1;
301   guint show_files : 1;
302   guint folders_only : 1;
303   guint has_editable : 1;
304 };
305
306 struct _FileModelNode
307 {
308   GtkFilePath *path;
309   FileModelNode *next;
310
311   GtkFileInfo *info;
312   GtkFileFolder *folder;
313   
314   FileModelNode *children;
315   FileModelNode *parent;
316   GtkFileSystemModel *model;
317
318   guint ref_count;
319   guint n_referenced_children;
320
321   gushort depth;
322
323   guint has_dummy : 1;
324   guint is_dummy : 1;
325   guint is_visible : 1;
326   guint loaded : 1;
327   guint idle_clear : 1;
328   guint load_pending : 1;
329 };
330
331
332 G_END_DECLS
333
334 #endif /* __GTK_FILE_CHOOSER_PRIVATE_H__ */