]> Pileus Git - ~andy/gtk/blob - gtk/gtkfilechooserprivate.h
GtkFileChooser search fixes and recent files support. (#435342)
[~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 "gtkrecentmanager.h"
29 #include "gtksearchengine.h"
30 #include "gtkquery.h"
31 #include "gtktooltips.h"
32 #include "gtktreemodelsort.h"
33 #include "gtktreestore.h"
34 #include "gtktreeview.h"
35 #include "gtkvbox.h"
36
37 G_BEGIN_DECLS
38
39 #define GTK_FILE_CHOOSER_GET_IFACE(inst)  (G_TYPE_INSTANCE_GET_INTERFACE ((inst), GTK_TYPE_FILE_CHOOSER, GtkFileChooserIface))
40
41 typedef struct _GtkFileChooserIface GtkFileChooserIface;
42
43 struct _GtkFileChooserIface
44 {
45   GTypeInterface base_iface;
46
47   /* Methods
48    */
49   gboolean       (*set_current_folder)     (GtkFileChooser    *chooser,
50                                             const GtkFilePath *path,
51                                             GError           **error);
52   GtkFilePath *  (*get_current_folder)     (GtkFileChooser    *chooser);
53   void           (*set_current_name)       (GtkFileChooser    *chooser,
54                                             const gchar       *name);
55   gboolean       (*select_path)            (GtkFileChooser    *chooser,
56                                             const GtkFilePath *path,
57                                             GError           **error);
58   void           (*unselect_path)          (GtkFileChooser    *chooser,
59                                             const GtkFilePath *path);
60   void           (*select_all)             (GtkFileChooser    *chooser);
61   void           (*unselect_all)           (GtkFileChooser    *chooser);
62   GSList *       (*get_paths)              (GtkFileChooser    *chooser);
63   GtkFilePath *  (*get_preview_path)       (GtkFileChooser    *chooser);
64   GtkFileSystem *(*get_file_system)        (GtkFileChooser    *chooser);
65   void           (*add_filter)             (GtkFileChooser    *chooser,
66                                             GtkFileFilter     *filter);
67   void           (*remove_filter)          (GtkFileChooser    *chooser,
68                                             GtkFileFilter     *filter);
69   GSList *       (*list_filters)           (GtkFileChooser    *chooser);
70   gboolean       (*add_shortcut_folder)    (GtkFileChooser    *chooser,
71                                             const GtkFilePath *path,
72                                             GError           **error);
73   gboolean       (*remove_shortcut_folder) (GtkFileChooser    *chooser,
74                                             const GtkFilePath *path,
75                                             GError           **error);
76   GSList *       (*list_shortcut_folders)  (GtkFileChooser    *chooser);
77   
78   /* Signals
79    */
80   void (*current_folder_changed) (GtkFileChooser *chooser);
81   void (*selection_changed)      (GtkFileChooser *chooser);
82   void (*update_preview)         (GtkFileChooser *chooser);
83   void (*file_activated)         (GtkFileChooser *chooser);
84   GtkFileChooserConfirmation (*confirm_overwrite) (GtkFileChooser *chooser);
85 };
86
87 GtkFileSystem *_gtk_file_chooser_get_file_system         (GtkFileChooser    *chooser);
88 gboolean       _gtk_file_chooser_set_current_folder_path (GtkFileChooser    *chooser,
89                                                           const GtkFilePath *path,
90                                                           GError           **error);
91 GtkFilePath *  _gtk_file_chooser_get_current_folder_path (GtkFileChooser    *chooser);
92 gboolean       _gtk_file_chooser_select_path             (GtkFileChooser    *chooser,
93                                                           const GtkFilePath *path,
94                                                           GError           **error);
95 void           _gtk_file_chooser_unselect_path           (GtkFileChooser    *chooser,
96                                                           const GtkFilePath *path);
97 GSList *       _gtk_file_chooser_get_paths               (GtkFileChooser    *chooser);
98 GtkFilePath *  _gtk_file_chooser_get_preview_path        (GtkFileChooser    *chooser);
99 gboolean       _gtk_file_chooser_add_shortcut_folder     (GtkFileChooser    *chooser,
100                                                           const GtkFilePath *path,
101                                                           GError           **error);
102 gboolean       _gtk_file_chooser_remove_shortcut_folder  (GtkFileChooser    *chooser,
103                                                           const GtkFilePath *path,
104                                                           GError           **error);
105
106 /* GtkFileChooserDialog private */
107
108 struct _GtkFileChooserDialogPrivate
109 {
110   GtkWidget *widget;
111   
112   char *file_system;
113
114   /* for use with GtkFileChooserEmbed */
115   gint default_width;
116   gint default_height;
117   gboolean resize_horizontally;
118   gboolean resize_vertically;
119   gboolean response_requested;
120 };
121
122
123 /* GtkFileChooserWidget private */
124
125 struct _GtkFileChooserWidgetPrivate
126 {
127   GtkWidget *impl;
128
129   char *file_system;
130 };
131
132
133 /* GtkFileChooserDefault private */
134
135 typedef enum {
136   LOAD_EMPTY,                   /* There is no model */
137   LOAD_PRELOAD,                 /* Model is loading and a timer is running; model isn't inserted into the tree yet */
138   LOAD_LOADING,                 /* Timeout expired, model is inserted into the tree, but not fully loaded yet */
139   LOAD_FINISHED                 /* Model is fully loaded and inserted into the tree */
140 } LoadState;
141
142 typedef enum {
143   RELOAD_EMPTY,                 /* No folder has been set */
144   RELOAD_HAS_FOLDER,            /* We have a folder, although it may not be completely loaded yet; no need to reload */
145   RELOAD_WAS_UNMAPPED           /* We had a folder but got unmapped; reload is needed */
146 } ReloadState;
147
148 typedef enum {
149   LOCATION_MODE_PATH_BAR,
150   LOCATION_MODE_FILENAME_ENTRY
151 } LocationMode;
152
153 typedef enum {
154   OPERATION_MODE_BROWSE,
155   OPERATION_MODE_SEARCH,
156   OPERATION_MODE_RECENT
157 } OperationMode;
158
159 struct _GtkFileChooserDefault
160 {
161   GtkVBox parent_instance;
162
163   GtkFileChooserAction action;
164
165   GtkFileSystem *file_system;
166
167   /* Save mode widgets */
168   GtkWidget *save_widgets;
169
170   GtkWidget *save_folder_label;
171   GtkWidget *save_folder_combo;
172   GtkWidget *save_expander;
173
174   /* The file browsing widgets */
175   GtkWidget *browse_widgets;
176   GtkWidget *browse_shortcuts_tree_view;
177   GtkWidget *browse_shortcuts_add_button;
178   GtkWidget *browse_shortcuts_remove_button;
179   GtkWidget *browse_shortcuts_popup_menu;
180   GtkWidget *browse_shortcuts_popup_menu_remove_item;
181   GtkWidget *browse_shortcuts_popup_menu_rename_item;
182   GtkWidget *browse_files_tree_view;
183   GtkWidget *browse_files_popup_menu;
184   GtkWidget *browse_files_popup_menu_add_shortcut_item;
185   GtkWidget *browse_files_popup_menu_hidden_files_item;
186   GtkWidget *browse_new_folder_button;
187   GtkWidget *browse_path_bar_hbox;
188   GtkWidget *browse_path_bar;
189
190   GtkFileSystemModel *browse_files_model;
191   char *browse_files_last_selected_name;
192
193   /* Search */
194   GtkWidget *search_hbox;
195   GtkWidget *search_entry;
196   GtkSearchEngine *search_engine;
197   GtkQuery *search_query;
198   GtkListStore *search_model;
199
200   /* Recently Used */
201   GtkRecentManager *recent_manager;
202   GtkListStore *recent_model;
203   guint load_recent_id;
204
205   GtkWidget *filter_combo_hbox;
206   GtkWidget *filter_combo;
207   GtkWidget *preview_box;
208   GtkWidget *preview_label;
209   GtkWidget *preview_widget;
210   GtkWidget *extra_align;
211   GtkWidget *extra_widget;
212
213   GtkWidget *location_button;
214   GtkWidget *location_entry_box;
215   GtkWidget *location_label;
216   GtkWidget *location_entry;
217   LocationMode location_mode;
218
219   GtkListStore *shortcuts_model;
220
221   /* Filter for the shortcuts pane.  We filter out the "current folder" row and
222    * the separator that we use for the "Save in folder" combo.
223    */
224   GtkTreeModel *shortcuts_pane_filter_model;
225   
226   /* Filter for the "Save in folder" combo.  We filter out the Search row and
227    * its separator.
228    */
229   GtkTreeModel *shortcuts_combo_filter_model;
230
231   GtkTreeModelSort *sort_model;
232
233   /* Handles */
234   GSList *loading_shortcuts;
235   GSList *reload_icon_handles;
236   GtkFileSystemHandle *file_list_drag_data_received_handle;
237   GtkFileSystemHandle *update_current_folder_handle;
238   GtkFileSystemHandle *show_and_select_paths_handle;
239   GtkFileSystemHandle *should_respond_get_info_handle;
240   GtkFileSystemHandle *file_exists_get_info_handle;
241   GtkFileSystemHandle *update_from_entry_handle;
242   GtkFileSystemHandle *shortcuts_activate_iter_handle;
243   GSList *pending_handles;
244
245   LoadState load_state;
246   ReloadState reload_state;
247   guint load_timeout_id;
248
249   OperationMode operation_mode;
250
251   GSList *pending_select_paths;
252
253   GtkFileFilter *current_filter;
254   GSList *filters;
255
256   GtkTooltips *tooltips;
257
258   int num_volumes;
259   int num_shortcuts;
260   int num_bookmarks;
261
262   gulong volumes_changed_id;
263   gulong bookmarks_changed_id;
264
265   GtkFilePath *current_volume_path;
266   GtkFilePath *current_folder;
267   GtkFilePath *preview_path;
268   char *preview_display_name;
269
270   GtkTreeViewColumn *list_name_column;
271   GtkCellRenderer *list_name_renderer;
272   GtkTreeViewColumn *list_mtime_column;
273
274   GSource *edited_idle;
275   char *edited_new_text;
276
277   gulong settings_signal_id;
278   int icon_size;
279
280   gulong toplevel_set_focus_id;
281   GtkWidget *toplevel_last_focus_widget;
282
283 #if 0
284   GdkDragContext *shortcuts_drag_context;
285   GSource *shortcuts_drag_outside_idle;
286 #endif
287
288   /* Flags */
289
290   guint local_only : 1;
291   guint preview_widget_active : 1;
292   guint use_preview_label : 1;
293   guint select_multiple : 1;
294   guint show_hidden : 1;
295   guint do_overwrite_confirmation : 1;
296   guint list_sort_ascending : 1;
297   guint changing_folder : 1;
298   guint shortcuts_current_folder_active : 1;
299   guint expand_folders : 1;
300   guint has_home : 1;
301   guint has_desktop : 1;
302   guint has_search : 1;
303   guint has_recent : 1;
304
305 #if 0
306   guint shortcuts_drag_outside : 1;
307 #endif
308 };
309
310
311 /* GtkFileSystemModel private */
312
313 typedef struct _FileModelNode           FileModelNode;
314
315 struct _GtkFileSystemModel
316 {
317   GObject parent_instance;
318
319   GtkFileSystem  *file_system;
320   GtkFileInfoType types;
321   FileModelNode  *roots;
322   GtkFileFolder  *root_folder;
323   GtkFilePath    *root_path;
324
325   GtkFileSystemModelFilter filter_func;
326   gpointer filter_data;
327
328   GSList *idle_clears;
329   GSource *idle_clear_source;
330
331   gushort max_depth;
332
333   GSList *pending_handles;
334   
335   guint show_hidden : 1;
336   guint show_folders : 1;
337   guint show_files : 1;
338   guint folders_only : 1;
339   guint has_editable : 1;
340 };
341
342 struct _FileModelNode
343 {
344   GtkFilePath *path;
345   FileModelNode *next;
346
347   GtkFileInfo *info;
348   GtkFileFolder *folder;
349   
350   FileModelNode *children;
351   FileModelNode *parent;
352   GtkFileSystemModel *model;
353
354   guint ref_count;
355   guint n_referenced_children;
356
357   gushort depth;
358
359   guint has_dummy : 1;
360   guint is_dummy : 1;
361   guint is_visible : 1;
362   guint loaded : 1;
363   guint idle_clear : 1;
364   guint load_pending : 1;
365 };
366
367
368 G_END_DECLS
369
370 #endif /* __GTK_FILE_CHOOSER_PRIVATE_H__ */