]> 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   /* OPERATION_MODE_SEARCH */
194   GtkWidget *search_hbox;
195   GtkWidget *search_entry;
196   GtkSearchEngine *search_engine;
197   GtkQuery *search_query;
198   GtkListStore *search_model;
199   GtkTreeModelFilter *search_model_filter;
200
201   /* OPERATION_MODE_RECENT */
202   GtkRecentManager *recent_manager;
203   GtkListStore *recent_model;
204   guint load_recent_id;
205   GtkTreeModelFilter *recent_model_filter;
206
207   GtkWidget *filter_combo_hbox;
208   GtkWidget *filter_combo;
209   GtkWidget *preview_box;
210   GtkWidget *preview_label;
211   GtkWidget *preview_widget;
212   GtkWidget *extra_align;
213   GtkWidget *extra_widget;
214
215   GtkWidget *location_button;
216   GtkWidget *location_entry_box;
217   GtkWidget *location_label;
218   GtkWidget *location_entry;
219   LocationMode location_mode;
220
221   GtkListStore *shortcuts_model;
222
223   /* Filter for the shortcuts pane.  We filter out the "current folder" row and
224    * the separator that we use for the "Save in folder" combo.
225    */
226   GtkTreeModel *shortcuts_pane_filter_model;
227   
228   /* Filter for the "Save in folder" combo.  We filter out the Search row and
229    * its separator.
230    */
231   GtkTreeModel *shortcuts_combo_filter_model;
232
233   GtkTreeModelSort *sort_model;
234
235   /* Handles */
236   GSList *loading_shortcuts;
237   GSList *reload_icon_handles;
238   GtkFileSystemHandle *file_list_drag_data_received_handle;
239   GtkFileSystemHandle *update_current_folder_handle;
240   GtkFileSystemHandle *show_and_select_paths_handle;
241   GtkFileSystemHandle *should_respond_get_info_handle;
242   GtkFileSystemHandle *file_exists_get_info_handle;
243   GtkFileSystemHandle *update_from_entry_handle;
244   GtkFileSystemHandle *shortcuts_activate_iter_handle;
245   GSList *pending_handles;
246
247   LoadState load_state;
248   ReloadState reload_state;
249   guint load_timeout_id;
250
251   OperationMode operation_mode;
252
253   GSList *pending_select_paths;
254
255   GtkFileFilter *current_filter;
256   GSList *filters;
257
258   GtkTooltips *tooltips;
259
260   int num_volumes;
261   int num_shortcuts;
262   int num_bookmarks;
263
264   gulong volumes_changed_id;
265   gulong bookmarks_changed_id;
266
267   GtkFilePath *current_volume_path;
268   GtkFilePath *current_folder;
269   GtkFilePath *preview_path;
270   char *preview_display_name;
271
272   GtkTreeViewColumn *list_name_column;
273   GtkCellRenderer *list_name_renderer;
274   GtkTreeViewColumn *list_mtime_column;
275
276   GSource *edited_idle;
277   char *edited_new_text;
278
279   gulong settings_signal_id;
280   int icon_size;
281
282   gulong toplevel_set_focus_id;
283   GtkWidget *toplevel_last_focus_widget;
284
285 #if 0
286   GdkDragContext *shortcuts_drag_context;
287   GSource *shortcuts_drag_outside_idle;
288 #endif
289
290   /* Flags */
291
292   guint local_only : 1;
293   guint preview_widget_active : 1;
294   guint use_preview_label : 1;
295   guint select_multiple : 1;
296   guint show_hidden : 1;
297   guint do_overwrite_confirmation : 1;
298   guint list_sort_ascending : 1;
299   guint changing_folder : 1;
300   guint shortcuts_current_folder_active : 1;
301   guint expand_folders : 1;
302   guint has_home : 1;
303   guint has_desktop : 1;
304   guint has_search : 1;
305   guint has_recent : 1;
306
307 #if 0
308   guint shortcuts_drag_outside : 1;
309 #endif
310 };
311
312
313 /* GtkFileSystemModel private */
314
315 typedef struct _FileModelNode           FileModelNode;
316
317 struct _GtkFileSystemModel
318 {
319   GObject parent_instance;
320
321   GtkFileSystem  *file_system;
322   GtkFileInfoType types;
323   FileModelNode  *roots;
324   GtkFileFolder  *root_folder;
325   GtkFilePath    *root_path;
326
327   GtkFileSystemModelFilter filter_func;
328   gpointer filter_data;
329
330   GSList *idle_clears;
331   GSource *idle_clear_source;
332
333   gushort max_depth;
334
335   GSList *pending_handles;
336   
337   guint show_hidden : 1;
338   guint show_folders : 1;
339   guint show_files : 1;
340   guint folders_only : 1;
341   guint has_editable : 1;
342 };
343
344 struct _FileModelNode
345 {
346   GtkFilePath *path;
347   FileModelNode *next;
348
349   GtkFileInfo *info;
350   GtkFileFolder *folder;
351   
352   FileModelNode *children;
353   FileModelNode *parent;
354   GtkFileSystemModel *model;
355
356   guint ref_count;
357   guint n_referenced_children;
358
359   gushort depth;
360
361   guint has_dummy : 1;
362   guint is_dummy : 1;
363   guint is_visible : 1;
364   guint loaded : 1;
365   guint idle_clear : 1;
366   guint load_pending : 1;
367 };
368
369
370 G_END_DECLS
371
372 #endif /* __GTK_FILE_CHOOSER_PRIVATE_H__ */