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