]> Pileus Git - ~andy/gtk/blob - gtk/gtkrecentchooserdefault.c
Deprecate flag macros for toplevel, state, no window and composite child
[~andy/gtk] / gtk / gtkrecentchooserdefault.c
1 /* GTK - The GIMP Toolkit
2  * gtkrecentchooserdefault.c
3  * Copyright (C) 2005-2006, Emmanuele Bassi
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 #include "config.h"
22
23 #include <string.h>
24 #include <time.h>
25 #include <errno.h>
26 #include <sys/types.h>
27 #include <sys/stat.h>
28 #ifdef HAVE_UNISTD_H
29 #include <unistd.h>
30 #endif
31
32 #include "gtkstock.h"
33 #include "gtkicontheme.h"
34 #include "gtkiconfactory.h"
35 #include "gtksettings.h"
36 #include "gtktreeview.h"
37 #include "gtkliststore.h"
38 #include "gtkbutton.h"
39 #include "gtkcelllayout.h"
40 #include "gtkcellrendererpixbuf.h"
41 #include "gtkcellrenderertext.h"
42 #include "gtkcheckmenuitem.h"
43 #include "gtkclipboard.h"
44 #include "gtkcombobox.h"
45 #include "gtkentry.h"
46 #include "gtkeventbox.h"
47 #include "gtkexpander.h"
48 #include "gtkframe.h"
49 #include "gtkhbox.h"
50 #include "gtkhpaned.h"
51 #include "gtkimage.h"
52 #include "gtkimagemenuitem.h"
53 #include "gtkintl.h"
54 #include "gtklabel.h"
55 #include "gtkmenuitem.h"
56 #include "gtkmessagedialog.h"
57 #include "gtkscrolledwindow.h"
58 #include "gtkseparatormenuitem.h"
59 #include "gtksizegroup.h"
60 #include "gtktable.h"
61 #include "gtktreemodelsort.h"
62 #include "gtktreemodelfilter.h"
63 #include "gtktreeselection.h"
64 #include "gtktreestore.h"
65 #include "gtktooltip.h"
66 #include "gtktypebuiltins.h"
67 #include "gtkvbox.h"
68 #include "gtkactivatable.h"
69
70 #include "gtkrecentmanager.h"
71 #include "gtkrecentfilter.h"
72 #include "gtkrecentchooser.h"
73 #include "gtkrecentchooserprivate.h"
74 #include "gtkrecentchooserutils.h"
75 #include "gtkrecentchooserdefault.h"
76
77 #include "gtkprivate.h"
78 #include "gtkalias.h"
79
80 enum 
81 {
82   PROP_0,
83
84   /* activatable properties */
85   PROP_ACTIVATABLE_RELATED_ACTION,
86   PROP_ACTIVATABLE_USE_ACTION_APPEARANCE
87 };
88
89
90 struct _GtkRecentChooserDefault
91 {
92   GtkVBox parent_instance;
93   
94   GtkRecentManager *manager;
95   gulong manager_changed_id;
96   guint local_manager : 1;
97   
98   gint icon_size;
99
100   /* RecentChooser properties */
101   gint limit;  
102   GtkRecentSortType sort_type;
103   guint show_private : 1;
104   guint show_not_found : 1;
105   guint select_multiple : 1;
106   guint show_tips : 1;
107   guint show_icons : 1;
108   guint local_only : 1;
109
110   guint limit_set : 1;
111   
112   GSList *filters;
113   GtkRecentFilter *current_filter;
114   GtkWidget *filter_combo_hbox;
115   GtkWidget *filter_combo;
116   
117   GtkRecentSortFunc sort_func;
118   gpointer sort_data;
119   GDestroyNotify sort_data_destroy;
120
121   GtkIconTheme *icon_theme;
122   
123   GtkWidget *recent_view;
124   GtkListStore *recent_store;
125   GtkTreeViewColumn *icon_column;
126   GtkTreeViewColumn *meta_column;
127   GtkCellRenderer *meta_renderer;
128   GtkTreeSelection *selection;
129   
130   GtkWidget *recent_popup_menu;
131   GtkWidget *recent_popup_menu_copy_item;
132   GtkWidget *recent_popup_menu_remove_item;
133   GtkWidget *recent_popup_menu_clear_item;
134   GtkWidget *recent_popup_menu_show_private_item;
135  
136   guint load_id;
137   GList *recent_items;
138   gint n_recent_items;
139   gint loaded_items;
140   guint load_state;
141 };
142
143 typedef struct _GtkRecentChooserDefaultClass
144 {
145   GtkVBoxClass parent_class;
146 } GtkRecentChooserDefaultClass;
147
148 enum {
149   RECENT_URI_COLUMN,
150   RECENT_DISPLAY_NAME_COLUMN,
151   RECENT_INFO_COLUMN,
152     
153   N_RECENT_COLUMNS
154 };
155
156 enum {
157   LOAD_EMPTY,    /* initial state: the model is empty */
158   LOAD_PRELOAD,  /* the model is loading and not inserted in the tree yet */
159   LOAD_LOADING,  /* the model is fully loaded but not inserted */
160   LOAD_FINISHED  /* the model is fully loaded and inserted */
161 };
162
163 /* Icon size for if we can't get it from the theme */
164 #define FALLBACK_ICON_SIZE  48
165 #define FALLBACK_ITEM_LIMIT 20
166
167 #define NUM_CHARS 40
168 #define NUM_LINES 9
169
170 \f
171
172 /* GObject */
173 static void     _gtk_recent_chooser_default_class_init  (GtkRecentChooserDefaultClass *klass);
174 static void     _gtk_recent_chooser_default_init        (GtkRecentChooserDefault      *impl);
175 static GObject *gtk_recent_chooser_default_constructor  (GType                         type,
176                                                          guint                         n_construct_prop,
177                                                          GObjectConstructParam        *construct_params);
178 static void     gtk_recent_chooser_default_finalize     (GObject                      *object);
179 static void     gtk_recent_chooser_default_dispose      (GObject                      *object);
180 static void     gtk_recent_chooser_default_set_property (GObject                      *object,
181                                                          guint                         prop_id,
182                                                          const GValue                 *value,
183                                                          GParamSpec                   *pspec);
184 static void     gtk_recent_chooser_default_get_property (GObject                      *object,
185                                                          guint                         prop_id,
186                                                          GValue                       *value,
187                                                          GParamSpec                   *pspec);
188
189 /* GtkRecentChooserIface */
190 static void              gtk_recent_chooser_iface_init                 (GtkRecentChooserIface  *iface);
191 static gboolean          gtk_recent_chooser_default_set_current_uri    (GtkRecentChooser       *chooser,
192                                                                         const gchar            *uri,
193                                                                         GError                **error);
194 static gchar *           gtk_recent_chooser_default_get_current_uri    (GtkRecentChooser       *chooser);
195 static gboolean          gtk_recent_chooser_default_select_uri         (GtkRecentChooser       *chooser,
196                                                                         const gchar            *uri,
197                                                                         GError                **error);
198 static void              gtk_recent_chooser_default_unselect_uri       (GtkRecentChooser       *chooser,
199                                                                         const gchar            *uri);
200 static void              gtk_recent_chooser_default_select_all         (GtkRecentChooser       *chooser);
201 static void              gtk_recent_chooser_default_unselect_all       (GtkRecentChooser       *chooser);
202 static GList *           gtk_recent_chooser_default_get_items          (GtkRecentChooser       *chooser);
203 static GtkRecentManager *gtk_recent_chooser_default_get_recent_manager (GtkRecentChooser       *chooser);
204 static void              gtk_recent_chooser_default_set_sort_func      (GtkRecentChooser       *chooser,
205                                                                         GtkRecentSortFunc       sort_func,
206                                                                         gpointer                sort_data,
207                                                                         GDestroyNotify          data_destroy);
208 static void              gtk_recent_chooser_default_add_filter         (GtkRecentChooser       *chooser,
209                                                                         GtkRecentFilter        *filter);
210 static void              gtk_recent_chooser_default_remove_filter      (GtkRecentChooser       *chooser,
211                                                                         GtkRecentFilter        *filter);
212 static GSList *          gtk_recent_chooser_default_list_filters       (GtkRecentChooser       *chooser);
213
214
215 static void gtk_recent_chooser_default_map      (GtkWidget *widget);
216 static void gtk_recent_chooser_default_show_all (GtkWidget *widget);
217
218 static void set_current_filter        (GtkRecentChooserDefault *impl,
219                                        GtkRecentFilter         *filter);
220
221 static GtkIconTheme *get_icon_theme_for_widget (GtkWidget   *widget);
222 static gint          get_icon_size_for_widget  (GtkWidget   *widget,
223                                                 GtkIconSize  icon_size);
224 static gint          get_recent_files_limit    (GtkWidget   *widget);
225
226 static void reload_recent_items (GtkRecentChooserDefault *impl);
227 static void chooser_set_model   (GtkRecentChooserDefault *impl);
228
229 static void set_recent_manager (GtkRecentChooserDefault *impl,
230                                 GtkRecentManager        *manager);
231
232 static void chooser_set_sort_type (GtkRecentChooserDefault *impl,
233                                    GtkRecentSortType        sort_type);
234
235 static void recent_manager_changed_cb (GtkRecentManager  *manager,
236                                        gpointer           user_data);
237 static void recent_icon_data_func     (GtkTreeViewColumn *tree_column,
238                                        GtkCellRenderer   *cell,
239                                        GtkTreeModel      *model,
240                                        GtkTreeIter       *iter,
241                                        gpointer           user_data);
242 static void recent_meta_data_func     (GtkTreeViewColumn *tree_column,
243                                        GtkCellRenderer   *cell,
244                                        GtkTreeModel      *model,
245                                        GtkTreeIter       *iter,
246                                        gpointer           user_data);
247
248 static void selection_changed_cb      (GtkTreeSelection  *z,
249                                        gpointer           user_data);
250 static void row_activated_cb          (GtkTreeView       *tree_view,
251                                        GtkTreePath       *tree_path,
252                                        GtkTreeViewColumn *tree_column,
253                                        gpointer           user_data);
254 static void filter_combo_changed_cb   (GtkComboBox       *combo_box,
255                                        gpointer           user_data);
256
257 static void remove_all_activated_cb   (GtkMenuItem       *menu_item,
258                                        gpointer           user_data);
259 static void remove_item_activated_cb  (GtkMenuItem       *menu_item,
260                                        gpointer           user_data);
261 static void show_private_toggled_cb   (GtkCheckMenuItem  *menu_item,
262                                        gpointer           user_data);
263
264 static gboolean recent_view_popup_menu_cb   (GtkWidget      *widget,
265                                              gpointer        user_data);
266 static gboolean recent_view_button_press_cb (GtkWidget      *widget,
267                                              GdkEventButton *event,
268                                              gpointer        user_data);
269
270 static void     recent_view_drag_begin_cb         (GtkWidget        *widget,
271                                                    GdkDragContext   *context,
272                                                    gpointer          user_data);
273 static void     recent_view_drag_data_get_cb      (GtkWidget        *widget,
274                                                    GdkDragContext   *context,
275                                                    GtkSelectionData *selection_data,
276                                                    guint             info,
277                                                    guint32           time_,
278                                                    gpointer          data);
279 static gboolean recent_view_query_tooltip_cb      (GtkWidget        *widget,
280                                                    gint              x,
281                                                    gint              y,
282                                                    gboolean          keyboard_tip,
283                                                    GtkTooltip       *tooltip,
284                                                    gpointer          user_data);
285
286 static void gtk_recent_chooser_activatable_iface_init (GtkActivatableIface  *iface);
287 static void gtk_recent_chooser_update                 (GtkActivatable       *activatable,
288                                                        GtkAction            *action,
289                                                        const gchar          *property_name);
290 static void gtk_recent_chooser_sync_action_properties (GtkActivatable       *activatable,
291                                                        GtkAction            *action);
292
293 G_DEFINE_TYPE_WITH_CODE (GtkRecentChooserDefault,
294                          _gtk_recent_chooser_default,
295                          GTK_TYPE_VBOX,
296                          G_IMPLEMENT_INTERFACE (GTK_TYPE_RECENT_CHOOSER,
297                                                 gtk_recent_chooser_iface_init)
298                          G_IMPLEMENT_INTERFACE (GTK_TYPE_ACTIVATABLE,
299                                                 gtk_recent_chooser_activatable_iface_init))
300
301
302 \f
303
304 static void
305 gtk_recent_chooser_iface_init (GtkRecentChooserIface *iface)
306 {
307   iface->set_current_uri = gtk_recent_chooser_default_set_current_uri;
308   iface->get_current_uri = gtk_recent_chooser_default_get_current_uri;
309   iface->select_uri = gtk_recent_chooser_default_select_uri;
310   iface->unselect_uri = gtk_recent_chooser_default_unselect_uri;
311   iface->select_all = gtk_recent_chooser_default_select_all;
312   iface->unselect_all = gtk_recent_chooser_default_unselect_all;
313   iface->get_items = gtk_recent_chooser_default_get_items;
314   iface->get_recent_manager = gtk_recent_chooser_default_get_recent_manager;
315   iface->set_sort_func = gtk_recent_chooser_default_set_sort_func;
316   iface->add_filter = gtk_recent_chooser_default_add_filter;
317   iface->remove_filter = gtk_recent_chooser_default_remove_filter;
318   iface->list_filters = gtk_recent_chooser_default_list_filters;
319 }
320
321 static void
322 gtk_recent_chooser_activatable_iface_init (GtkActivatableIface *iface)
323
324 {
325   iface->update = gtk_recent_chooser_update;
326   iface->sync_action_properties = gtk_recent_chooser_sync_action_properties;
327 }
328
329 static void
330 _gtk_recent_chooser_default_class_init (GtkRecentChooserDefaultClass *klass)
331 {
332   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
333   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
334
335   gobject_class->constructor = gtk_recent_chooser_default_constructor;
336   gobject_class->set_property = gtk_recent_chooser_default_set_property;
337   gobject_class->get_property = gtk_recent_chooser_default_get_property;
338   gobject_class->dispose = gtk_recent_chooser_default_dispose;
339   gobject_class->finalize = gtk_recent_chooser_default_finalize;
340   
341   widget_class->map = gtk_recent_chooser_default_map;
342   widget_class->show_all = gtk_recent_chooser_default_show_all;
343   
344   _gtk_recent_chooser_install_properties (gobject_class);
345
346   g_object_class_override_property (gobject_class, PROP_ACTIVATABLE_RELATED_ACTION, "related-action");
347   g_object_class_override_property (gobject_class, PROP_ACTIVATABLE_USE_ACTION_APPEARANCE, "use-action-appearance");
348 }
349
350 static void
351 _gtk_recent_chooser_default_init (GtkRecentChooserDefault *impl)
352 {
353   gtk_box_set_spacing (GTK_BOX (impl), 6);
354
355   /* by default, we use the global manager */
356   impl->local_manager = FALSE;
357   
358   impl->limit = FALLBACK_ITEM_LIMIT;
359   impl->sort_type = GTK_RECENT_SORT_NONE;
360
361   impl->show_icons = TRUE;
362   impl->show_private = FALSE;
363   impl->show_not_found = TRUE;
364   impl->show_tips = FALSE;
365   impl->select_multiple = FALSE;
366   impl->local_only = TRUE;
367   
368   impl->icon_size = FALLBACK_ICON_SIZE;
369   impl->icon_theme = NULL;
370   
371   impl->current_filter = NULL;
372
373   impl->recent_items = NULL;
374   impl->n_recent_items = 0;
375   impl->loaded_items = 0;
376   
377   impl->load_state = LOAD_EMPTY;
378 }
379
380 static GObject *
381 gtk_recent_chooser_default_constructor (GType                  type,
382                                         guint                  n_params,
383                                         GObjectConstructParam *params)
384 {
385   GObjectClass *parent_class;
386   GtkRecentChooserDefault *impl;
387   GObject *object;
388   GtkWidget *scrollw;
389   GtkCellRenderer *renderer;
390
391   parent_class = G_OBJECT_CLASS (_gtk_recent_chooser_default_parent_class);
392   object = parent_class->constructor (type, n_params, params);
393   impl = GTK_RECENT_CHOOSER_DEFAULT (object);
394   
395   g_assert (impl->manager);
396   
397   gtk_widget_push_composite_child ();
398
399   impl->limit = get_recent_files_limit (GTK_WIDGET (impl));
400   
401   scrollw = gtk_scrolled_window_new (NULL, NULL);
402   gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrollw),
403                                        GTK_SHADOW_IN);
404   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrollw),
405                                   GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
406   gtk_box_pack_start (GTK_BOX (impl), scrollw, TRUE, TRUE, 0);
407   gtk_widget_show (scrollw);
408   
409   impl->recent_view = gtk_tree_view_new ();
410   gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (impl->recent_view), FALSE);
411   g_signal_connect (impl->recent_view, "row-activated",
412                     G_CALLBACK (row_activated_cb), impl);
413   g_signal_connect (impl->recent_view, "popup-menu",
414                     G_CALLBACK (recent_view_popup_menu_cb), impl);
415   g_signal_connect (impl->recent_view, "button-press-event",
416                     G_CALLBACK (recent_view_button_press_cb), impl);
417   g_signal_connect (impl->recent_view, "drag-begin",
418                     G_CALLBACK (recent_view_drag_begin_cb), impl);
419   g_signal_connect (impl->recent_view, "drag-data-get",
420                     G_CALLBACK (recent_view_drag_data_get_cb), impl);
421
422   g_object_set (impl->recent_view, "has-tooltip", TRUE, NULL);
423   g_signal_connect (impl->recent_view, "query-tooltip",
424                     G_CALLBACK (recent_view_query_tooltip_cb), impl);
425
426   g_object_set_data (G_OBJECT (impl->recent_view),
427                      "GtkRecentChooserDefault", impl);
428   
429   gtk_container_add (GTK_CONTAINER (scrollw), impl->recent_view);
430   gtk_widget_show (impl->recent_view);
431   
432   impl->icon_column = gtk_tree_view_column_new ();
433   gtk_tree_view_column_set_expand (impl->icon_column, FALSE);
434   gtk_tree_view_column_set_resizable (impl->icon_column, FALSE);
435   
436   renderer = gtk_cell_renderer_pixbuf_new ();
437   gtk_tree_view_column_pack_start (impl->icon_column, renderer, FALSE);
438   gtk_tree_view_column_set_cell_data_func (impl->icon_column,
439                                            renderer,
440                                            recent_icon_data_func,
441                                            impl,
442                                            NULL);
443   gtk_tree_view_append_column (GTK_TREE_VIEW (impl->recent_view),
444                                impl->icon_column);
445   
446   impl->meta_column = gtk_tree_view_column_new ();
447   gtk_tree_view_column_set_expand (impl->meta_column, TRUE);
448   gtk_tree_view_column_set_resizable (impl->meta_column, FALSE);
449   
450   impl->meta_renderer = gtk_cell_renderer_text_new ();
451   g_object_set (G_OBJECT (impl->meta_renderer),
452                 "ellipsize", PANGO_ELLIPSIZE_END,
453                 NULL);
454   gtk_tree_view_column_pack_start (impl->meta_column, impl->meta_renderer, TRUE);
455   gtk_tree_view_column_set_cell_data_func (impl->meta_column,
456                                            impl->meta_renderer,
457                                            recent_meta_data_func,
458                                            impl,
459                                            NULL);
460   gtk_tree_view_append_column (GTK_TREE_VIEW (impl->recent_view),
461                                impl->meta_column);
462   
463   impl->selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->recent_view));
464   gtk_tree_selection_set_mode (impl->selection, GTK_SELECTION_SINGLE);
465   g_signal_connect (impl->selection, "changed", G_CALLBACK (selection_changed_cb), impl);
466
467   /* drag and drop */
468   gtk_drag_source_set (impl->recent_view,
469                        GDK_BUTTON1_MASK,
470                        NULL, 0,
471                        GDK_ACTION_COPY);
472   gtk_drag_source_add_uri_targets (impl->recent_view);
473
474   impl->filter_combo_hbox = gtk_hbox_new (FALSE, 12);
475   
476   impl->filter_combo = gtk_combo_box_new_text ();
477   gtk_combo_box_set_focus_on_click (GTK_COMBO_BOX (impl->filter_combo), FALSE);
478   g_signal_connect (impl->filter_combo, "changed",
479                     G_CALLBACK (filter_combo_changed_cb), impl);
480   gtk_widget_set_tooltip_text (impl->filter_combo,
481                                _("Select which type of documents are shown"));
482   
483   gtk_box_pack_end (GTK_BOX (impl->filter_combo_hbox),
484                     impl->filter_combo,
485                     FALSE, FALSE, 0);
486   gtk_widget_show (impl->filter_combo);
487   
488   gtk_box_pack_end (GTK_BOX (impl), impl->filter_combo_hbox, FALSE, FALSE, 0);
489   
490   gtk_widget_pop_composite_child ();
491   
492   impl->recent_store = gtk_list_store_new (N_RECENT_COLUMNS,
493                                            G_TYPE_STRING,       /* uri */
494                                            G_TYPE_STRING,       /* display_name */
495                                            GTK_TYPE_RECENT_INFO /* info */);
496   
497   return object;
498 }
499
500 static void
501 gtk_recent_chooser_default_set_property (GObject      *object,
502                                          guint         prop_id,
503                                          const GValue *value,
504                                          GParamSpec   *pspec)
505 {
506   GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (object);
507   
508   switch (prop_id)
509     {
510     case GTK_RECENT_CHOOSER_PROP_RECENT_MANAGER:
511       set_recent_manager (impl, g_value_get_object (value));
512       break;
513     case GTK_RECENT_CHOOSER_PROP_SHOW_PRIVATE:
514       impl->show_private = g_value_get_boolean (value);
515       if (impl->recent_popup_menu_show_private_item)
516         {
517           GtkCheckMenuItem *item = GTK_CHECK_MENU_ITEM (impl->recent_popup_menu_show_private_item);
518           g_signal_handlers_block_by_func (item, G_CALLBACK (show_private_toggled_cb), impl);
519           gtk_check_menu_item_set_active (item, impl->show_private);
520           g_signal_handlers_unblock_by_func (item, G_CALLBACK (show_private_toggled_cb), impl);
521         }
522       reload_recent_items (impl);
523       break;
524     case GTK_RECENT_CHOOSER_PROP_SHOW_NOT_FOUND:
525       impl->show_not_found = g_value_get_boolean (value);
526       reload_recent_items (impl);
527       break;
528     case GTK_RECENT_CHOOSER_PROP_SHOW_TIPS:
529       impl->show_tips = g_value_get_boolean (value);
530       break;
531     case GTK_RECENT_CHOOSER_PROP_SHOW_ICONS:
532       impl->show_icons = g_value_get_boolean (value);
533       gtk_tree_view_column_set_visible (impl->icon_column, impl->show_icons);
534       break;
535     case GTK_RECENT_CHOOSER_PROP_SELECT_MULTIPLE:
536       impl->select_multiple = g_value_get_boolean (value);
537       
538       if (impl->select_multiple)
539         gtk_tree_selection_set_mode (impl->selection, GTK_SELECTION_MULTIPLE);
540       else
541         gtk_tree_selection_set_mode (impl->selection, GTK_SELECTION_SINGLE);
542       break;
543     case GTK_RECENT_CHOOSER_PROP_LOCAL_ONLY:
544       impl->local_only = g_value_get_boolean (value);
545       reload_recent_items (impl);
546       break;
547     case GTK_RECENT_CHOOSER_PROP_LIMIT:
548       impl->limit = g_value_get_int (value);
549       impl->limit_set = TRUE;
550       reload_recent_items (impl);
551       break;
552     case GTK_RECENT_CHOOSER_PROP_SORT_TYPE:
553       chooser_set_sort_type (impl, g_value_get_enum (value));
554       break;
555     case GTK_RECENT_CHOOSER_PROP_FILTER:
556       set_current_filter (impl, g_value_get_object (value));
557       break;
558     case PROP_ACTIVATABLE_RELATED_ACTION:
559       _gtk_recent_chooser_set_related_action (GTK_RECENT_CHOOSER (impl), g_value_get_object (value));
560       break;
561     case PROP_ACTIVATABLE_USE_ACTION_APPEARANCE: 
562       _gtk_recent_chooser_set_use_action_appearance (GTK_RECENT_CHOOSER (impl), g_value_get_boolean (value));
563       break;
564     default:
565       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
566       break;
567     }
568 }
569
570 static void
571 gtk_recent_chooser_default_get_property (GObject    *object,
572                                          guint       prop_id,
573                                          GValue     *value,
574                                          GParamSpec *pspec)
575 {
576   GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (object);
577   
578   switch (prop_id)
579     {
580     case GTK_RECENT_CHOOSER_PROP_LIMIT:
581       g_value_set_int (value, impl->limit);
582       break;
583     case GTK_RECENT_CHOOSER_PROP_SORT_TYPE:
584       g_value_set_enum (value, impl->sort_type);
585       break;
586     case GTK_RECENT_CHOOSER_PROP_SHOW_PRIVATE:
587       g_value_set_boolean (value, impl->show_private);
588       break;
589     case GTK_RECENT_CHOOSER_PROP_SHOW_ICONS:
590       g_value_set_boolean (value, impl->show_icons);
591       break;
592     case GTK_RECENT_CHOOSER_PROP_SHOW_NOT_FOUND:
593       g_value_set_boolean (value, impl->show_not_found);
594       break;
595     case GTK_RECENT_CHOOSER_PROP_SHOW_TIPS:
596       g_value_set_boolean (value, impl->show_tips);
597       break;
598     case GTK_RECENT_CHOOSER_PROP_LOCAL_ONLY:
599       g_value_set_boolean (value, impl->local_only);
600       break;
601     case GTK_RECENT_CHOOSER_PROP_SELECT_MULTIPLE:
602       g_value_set_boolean (value, impl->select_multiple);
603       break;
604     case GTK_RECENT_CHOOSER_PROP_FILTER:
605       g_value_set_object (value, impl->current_filter);
606       break;
607     case PROP_ACTIVATABLE_RELATED_ACTION:
608       g_value_set_object (value, _gtk_recent_chooser_get_related_action (GTK_RECENT_CHOOSER (impl)));
609       break;
610     case PROP_ACTIVATABLE_USE_ACTION_APPEARANCE: 
611       g_value_set_boolean (value, _gtk_recent_chooser_get_use_action_appearance (GTK_RECENT_CHOOSER (impl)));
612       break;
613     default:
614       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
615       break;
616     }
617 }
618
619 static void
620 gtk_recent_chooser_default_dispose (GObject *object)
621 {
622   GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (object);
623
624   if (impl->load_id)
625     {
626       g_source_remove (impl->load_id);
627       impl->load_state = LOAD_EMPTY;
628       impl->load_id = 0;
629     }
630
631   if (impl->recent_items)
632     {
633       g_list_foreach (impl->recent_items, (GFunc) gtk_recent_info_unref, NULL);
634       g_list_free (impl->recent_items);
635       impl->recent_items = NULL;
636     }
637
638   if (impl->manager && impl->manager_changed_id)
639     {
640       g_signal_handler_disconnect (impl->manager, impl->manager_changed_id);
641       impl->manager_changed_id = 0;
642     }
643
644   if (impl->filters)
645     {
646       g_slist_foreach (impl->filters, (GFunc) g_object_unref, NULL);
647       g_slist_free (impl->filters);
648       impl->filters = NULL;
649     }
650   
651   if (impl->current_filter)
652     {
653       g_object_unref (impl->current_filter);
654       impl->current_filter = NULL;
655     }
656
657   if (impl->recent_store)
658     {
659       g_object_unref (impl->recent_store);
660       impl->recent_store = NULL;
661     }
662
663   G_OBJECT_CLASS (_gtk_recent_chooser_default_parent_class)->dispose (object);
664 }
665
666 static void
667 gtk_recent_chooser_default_finalize (GObject *object)
668 {
669   GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (object);
670
671   impl->manager = NULL; 
672   
673   if (impl->sort_data_destroy)
674     {
675       impl->sort_data_destroy (impl->sort_data);
676       impl->sort_data_destroy = NULL;
677     }
678   
679   impl->sort_data = NULL;
680   impl->sort_func = NULL;
681   
682   G_OBJECT_CLASS (_gtk_recent_chooser_default_parent_class)->finalize (object);
683 }
684
685 /* override GtkWidget::show_all since we have internal widgets we wish to keep
686  * hidden unless we decide otherwise, like the filter combo box.
687  */
688 static void
689 gtk_recent_chooser_default_show_all (GtkWidget *widget)
690 {
691   gtk_widget_show (widget);
692 }
693
694
695
696 /* Shows an error dialog set as transient for the specified window */
697 static void
698 error_message_with_parent (GtkWindow   *parent,
699                            const gchar *msg,
700                            const gchar *detail)
701 {
702   GtkWidget *dialog;
703
704   dialog = gtk_message_dialog_new (parent,
705                                    GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
706                                    GTK_MESSAGE_ERROR,
707                                    GTK_BUTTONS_OK,
708                                    "%s",
709                                    msg);
710   gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
711                                             "%s", detail);
712
713   if (parent->group)
714     gtk_window_group_add_window (parent->group, GTK_WINDOW (dialog));
715
716   gtk_dialog_run (GTK_DIALOG (dialog));
717   gtk_widget_destroy (dialog);
718 }
719
720 /* Returns a toplevel GtkWindow, or NULL if none */
721 static GtkWindow *
722 get_toplevel (GtkWidget *widget)
723 {
724   GtkWidget *toplevel;
725
726   toplevel = gtk_widget_get_toplevel (widget);
727   if (!gtk_widget_is_toplevel (toplevel))
728     return NULL;
729   else
730     return GTK_WINDOW (toplevel);
731 }
732
733 /* Shows an error dialog for the file chooser */
734 static void
735 error_message (GtkRecentChooserDefault *impl,
736                const gchar             *msg,
737                const gchar             *detail)
738 {
739   error_message_with_parent (get_toplevel (GTK_WIDGET (impl)), msg, detail);
740 }
741
742 static void
743 set_busy_cursor (GtkRecentChooserDefault *impl,
744                  gboolean                 show_busy_cursor)
745 {
746   GtkWindow *toplevel;
747   GdkDisplay *display;
748   GdkCursor *cursor;
749
750   toplevel = get_toplevel (GTK_WIDGET (impl));
751   if (!toplevel || !GTK_WIDGET_REALIZED (toplevel))
752     return;
753   
754   display = gtk_widget_get_display (GTK_WIDGET (toplevel));
755   
756   cursor = NULL;
757   if (show_busy_cursor)
758     cursor = gdk_cursor_new_for_display (display, GDK_WATCH);
759
760   gdk_window_set_cursor (GTK_WIDGET (toplevel)->window, cursor);
761   gdk_display_flush (display);
762
763   if (cursor)
764     gdk_cursor_unref (cursor);
765 }
766
767 static void
768 chooser_set_model (GtkRecentChooserDefault *impl)
769 {
770   g_assert (impl->recent_store != NULL);
771   g_assert (impl->load_state == LOAD_LOADING);
772
773   gtk_tree_view_set_model (GTK_TREE_VIEW (impl->recent_view),
774                            GTK_TREE_MODEL (impl->recent_store));
775   gtk_tree_view_columns_autosize (GTK_TREE_VIEW (impl->recent_view));
776   gtk_tree_view_set_enable_search (GTK_TREE_VIEW (impl->recent_view), TRUE);
777   gtk_tree_view_set_search_column (GTK_TREE_VIEW (impl->recent_view),
778                                    RECENT_DISPLAY_NAME_COLUMN);
779
780   impl->load_state = LOAD_FINISHED;
781 }
782
783 static gboolean
784 load_recent_items (gpointer user_data)
785 {
786   GtkRecentChooserDefault *impl;
787   GtkRecentInfo *info;
788   GtkTreeIter iter;
789   const gchar *uri, *name;
790   gboolean retval;
791   
792   impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
793   
794   g_assert ((impl->load_state == LOAD_EMPTY) ||
795             (impl->load_state == LOAD_PRELOAD));
796   
797   /* store the items for multiple runs */
798   if (!impl->recent_items)
799     {
800       impl->recent_items = gtk_recent_chooser_get_items (GTK_RECENT_CHOOSER (impl));
801       if (!impl->recent_items)
802         {
803           impl->load_state = LOAD_FINISHED;
804           
805           return FALSE;
806         }
807         
808       impl->n_recent_items = g_list_length (impl->recent_items);
809       impl->loaded_items = 0;
810       impl->load_state = LOAD_PRELOAD;
811     }
812   
813   info = (GtkRecentInfo *) g_list_nth_data (impl->recent_items,
814                                             impl->loaded_items);
815   g_assert (info);
816
817   uri = gtk_recent_info_get_uri (info);
818   name = gtk_recent_info_get_display_name (info);
819   
820   /* at this point, everything goes inside the model; operations on the
821    * visualization of items inside the model are done in the cell data
822    * funcs (remember that there are two of those: one for the icon and
823    * one for the text), while the filtering is done only when a filter
824    * is actually loaded. */
825   gtk_list_store_append (impl->recent_store, &iter);
826   gtk_list_store_set (impl->recent_store, &iter,
827                       RECENT_URI_COLUMN, uri,           /* uri  */
828                       RECENT_DISPLAY_NAME_COLUMN, name, /* display_name */
829                       RECENT_INFO_COLUMN, info,         /* info */
830                       -1);
831   
832   impl->loaded_items += 1;
833
834   if (impl->loaded_items == impl->n_recent_items)
835     {
836       /* we have finished loading, so we remove the items cache */
837       impl->load_state = LOAD_LOADING;
838       
839       g_list_foreach (impl->recent_items,
840                       (GFunc) gtk_recent_info_unref,
841                       NULL);
842       g_list_free (impl->recent_items);
843       
844       impl->recent_items = NULL;
845       impl->n_recent_items = 0;
846       impl->loaded_items = 0;
847
848       /* load the filled up model */
849       chooser_set_model (impl);
850
851       retval = FALSE;
852     }
853   else
854     {
855       /* we did not finish, so continue loading */
856       retval = TRUE;
857     }
858   
859   return retval;
860 }
861
862 static void
863 cleanup_after_load (gpointer user_data)
864 {
865   GtkRecentChooserDefault *impl;
866   
867   impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
868
869   if (impl->load_id != 0)
870     {
871       g_assert ((impl->load_state == LOAD_EMPTY) ||
872                 (impl->load_state == LOAD_PRELOAD) ||
873                 (impl->load_state == LOAD_LOADING) ||
874                 (impl->load_state == LOAD_FINISHED));
875       
876       /* we have officialy finished loading all the items,
877        * so we can reset the state machine
878        */
879       g_source_remove (impl->load_id);
880       impl->load_id = 0;
881       impl->load_state = LOAD_EMPTY;
882     }
883   else
884     g_assert ((impl->load_state == LOAD_EMPTY) ||
885               (impl->load_state == LOAD_LOADING) ||
886               (impl->load_state == LOAD_FINISHED));
887
888   set_busy_cursor (impl, FALSE);
889 }
890
891 /* clears the current model and reloads the recently used resources */
892 static void
893 reload_recent_items (GtkRecentChooserDefault *impl)
894 {
895   GtkWidget *widget;
896
897   /* reload is already in progress - do not disturb */
898   if (impl->load_id)
899     return;
900   
901   widget = GTK_WIDGET (impl);
902
903   gtk_tree_view_set_model (GTK_TREE_VIEW (impl->recent_view), NULL);
904   gtk_list_store_clear (impl->recent_store);
905   
906   if (!impl->icon_theme)
907     impl->icon_theme = get_icon_theme_for_widget (widget);
908
909   impl->icon_size = get_icon_size_for_widget (widget,
910                                               GTK_ICON_SIZE_BUTTON);
911
912   if (!impl->limit_set)
913     impl->limit = get_recent_files_limit (widget);
914
915   set_busy_cursor (impl, TRUE);
916
917   impl->load_state = LOAD_EMPTY;
918   impl->load_id = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 30,
919                                              load_recent_items,
920                                              impl,
921                                              cleanup_after_load);
922 }
923
924 /* taken form gtkfilechooserdialog.c */
925 static void
926 set_default_size (GtkRecentChooserDefault *impl)
927 {
928   GtkWidget *widget;
929   gint width, height;
930   gint font_size;
931   GdkScreen *screen;
932   gint monitor_num;
933   GtkRequisition req;
934   GdkRectangle monitor;
935
936   widget = GTK_WIDGET (impl);
937
938   /* Size based on characters and the icon size */
939   font_size = pango_font_description_get_size (widget->style->font_desc);
940   font_size = PANGO_PIXELS (font_size);
941
942   width = impl->icon_size + font_size * NUM_CHARS;
943   height = (impl->icon_size + font_size) * NUM_LINES;
944
945   /* Use at least the requisition size... */
946   gtk_widget_size_request (widget, &req);
947   width = MAX (width, req.width);
948   height = MAX (height, req.height);
949
950   /* ... but no larger than the monitor */
951   screen = gtk_widget_get_screen (widget);
952   monitor_num = gdk_screen_get_monitor_at_window (screen, widget->window);
953
954   gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
955
956   width = MIN (width, monitor.width * 3 / 4);
957   height = MIN (height, monitor.height * 3 / 4);
958
959   /* Set size */
960   gtk_widget_set_size_request (impl->recent_view, width, height);
961 }
962
963 static void
964 gtk_recent_chooser_default_map (GtkWidget *widget)
965 {
966   GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (widget);
967
968   GTK_WIDGET_CLASS (_gtk_recent_chooser_default_parent_class)->map (widget);
969
970   /* reloads everything */
971   reload_recent_items (impl);
972
973   set_default_size (impl);
974 }
975
976 static void
977 recent_icon_data_func (GtkTreeViewColumn *tree_column,
978                        GtkCellRenderer   *cell,
979                        GtkTreeModel      *model,
980                        GtkTreeIter       *iter,
981                        gpointer           user_data)
982 {
983   GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
984   GtkRecentInfo *info = NULL;
985   GdkPixbuf *pixbuf;
986   
987   gtk_tree_model_get (model, iter,
988                       RECENT_INFO_COLUMN, &info,
989                       -1);
990   g_assert (info != NULL);
991   
992   pixbuf = gtk_recent_info_get_icon (info, impl->icon_size);
993   
994   g_object_set (cell,
995                 "pixbuf", pixbuf,
996                 NULL);
997   
998   if (pixbuf)  
999     g_object_unref (pixbuf);
1000
1001   gtk_recent_info_unref (info);
1002 }
1003
1004 static void
1005 recent_meta_data_func (GtkTreeViewColumn *tree_column,
1006                        GtkCellRenderer   *cell,
1007                        GtkTreeModel      *model,
1008                        GtkTreeIter       *iter,
1009                        gpointer           user_data)
1010 {
1011   GtkRecentInfo *info = NULL;
1012   gchar *name;
1013   
1014   gtk_tree_model_get (model, iter,
1015                       RECENT_DISPLAY_NAME_COLUMN, &name,
1016                       RECENT_INFO_COLUMN, &info,
1017                       -1);
1018   g_assert (info != NULL);
1019   
1020   if (!name)
1021     name = gtk_recent_info_get_short_name (info);
1022
1023   g_object_set (cell, "text", name, NULL);
1024   
1025   g_free (name);
1026   gtk_recent_info_unref (info);
1027 }
1028
1029
1030 static gchar *
1031 gtk_recent_chooser_default_get_current_uri (GtkRecentChooser *chooser)
1032 {
1033   GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
1034   
1035   g_assert (impl->selection != NULL);
1036   
1037   if (!impl->select_multiple)
1038     {
1039       GtkTreeModel *model;
1040       GtkTreeIter iter;
1041       gchar *uri = NULL;
1042       
1043       if (!gtk_tree_selection_get_selected (impl->selection, &model, &iter))
1044         return NULL;
1045       
1046       gtk_tree_model_get (model, &iter, RECENT_URI_COLUMN, &uri, -1);
1047       
1048       return uri;
1049     }
1050   
1051   return NULL;
1052 }
1053
1054 typedef struct
1055 {
1056   guint found : 1;
1057   guint do_select : 1;
1058   guint do_activate : 1;
1059   
1060   gchar *uri;
1061   
1062   GtkRecentChooserDefault *impl;
1063 } SelectURIData;
1064
1065 static gboolean
1066 scan_for_uri_cb (GtkTreeModel *model,
1067                  GtkTreePath  *path,
1068                  GtkTreeIter  *iter,
1069                  gpointer      user_data)
1070 {
1071   SelectURIData *select_data = (SelectURIData *) user_data;
1072   gchar *uri = NULL;
1073   
1074   if (!select_data)
1075     return TRUE;
1076   
1077   if (select_data->found)
1078     return TRUE;
1079   
1080   gtk_tree_model_get (model, iter, RECENT_URI_COLUMN, &uri, -1);
1081   if (!uri)
1082     return FALSE;
1083   
1084   if (strcmp (uri, select_data->uri) == 0)
1085     {
1086       select_data->found = TRUE;
1087       
1088       if (select_data->do_activate)
1089         gtk_tree_view_row_activated (GTK_TREE_VIEW (select_data->impl->recent_view),
1090                                      path,
1091                                      select_data->impl->meta_column);
1092       
1093       if (select_data->do_select)
1094         gtk_tree_selection_select_path (select_data->impl->selection, path);
1095       else
1096         gtk_tree_selection_unselect_path (select_data->impl->selection, path);
1097
1098       g_free (uri);
1099       
1100       return TRUE;
1101     }
1102
1103   g_free (uri);
1104   
1105   return FALSE;
1106 }
1107
1108 static gboolean
1109 gtk_recent_chooser_default_set_current_uri (GtkRecentChooser  *chooser,
1110                                             const gchar       *uri,
1111                                             GError           **error)
1112 {
1113   GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
1114   SelectURIData *data;
1115   
1116   data = g_new0 (SelectURIData, 1);
1117   data->uri = g_strdup (uri);
1118   data->impl = impl;
1119   data->found = FALSE;
1120   data->do_activate = TRUE;
1121   data->do_select = TRUE;
1122   
1123   gtk_tree_model_foreach (GTK_TREE_MODEL (impl->recent_store),
1124                           scan_for_uri_cb,
1125                           data);
1126   
1127   if (!data->found)
1128     {
1129       g_free (data->uri);
1130       g_free (data);
1131       
1132       g_set_error (error, GTK_RECENT_CHOOSER_ERROR,
1133                    GTK_RECENT_CHOOSER_ERROR_NOT_FOUND,
1134                    _("No item for URI '%s' found"),
1135                    uri);
1136       return FALSE;
1137     }
1138   
1139   g_free (data->uri);
1140   g_free (data);
1141
1142   return TRUE;
1143 }
1144
1145 static gboolean
1146 gtk_recent_chooser_default_select_uri (GtkRecentChooser  *chooser,
1147                                        const gchar       *uri,
1148                                        GError           **error)
1149 {
1150   GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
1151   SelectURIData *data;
1152   
1153   data = g_new0 (SelectURIData, 1);
1154   data->uri = g_strdup (uri);
1155   data->impl = impl;
1156   data->found = FALSE;
1157   data->do_activate = FALSE;
1158   data->do_select = TRUE;
1159   
1160   gtk_tree_model_foreach (GTK_TREE_MODEL (impl->recent_store),
1161                           scan_for_uri_cb,
1162                           data);
1163   
1164   if (!data->found)
1165     {
1166       g_free (data->uri);
1167       g_free (data);
1168       
1169       g_set_error (error, GTK_RECENT_CHOOSER_ERROR,
1170                    GTK_RECENT_CHOOSER_ERROR_NOT_FOUND,
1171                    _("No item for URI '%s' found"),
1172                    uri);
1173       return FALSE;
1174     }
1175   
1176   g_free (data->uri);
1177   g_free (data);
1178
1179   return TRUE;
1180 }
1181
1182 static void
1183 gtk_recent_chooser_default_unselect_uri (GtkRecentChooser *chooser,
1184                                          const gchar      *uri)
1185 {
1186   GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
1187   SelectURIData *data;
1188   
1189   data = g_new0 (SelectURIData, 1);
1190   data->uri = g_strdup (uri);
1191   data->impl = impl;
1192   data->found = FALSE;
1193   data->do_activate = FALSE;
1194   data->do_select = FALSE;
1195   
1196   gtk_tree_model_foreach (GTK_TREE_MODEL (impl->recent_store),
1197                           scan_for_uri_cb,
1198                           data);
1199   
1200   g_free (data->uri);
1201   g_free (data);
1202 }
1203
1204 static void
1205 gtk_recent_chooser_default_select_all (GtkRecentChooser *chooser)
1206 {
1207   GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
1208   
1209   if (!impl->select_multiple)
1210     return;
1211   
1212   gtk_tree_selection_select_all (impl->selection);
1213 }
1214
1215 static void
1216 gtk_recent_chooser_default_unselect_all (GtkRecentChooser *chooser)
1217 {
1218   GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
1219   
1220   gtk_tree_selection_unselect_all (impl->selection);
1221 }
1222
1223 static void
1224 gtk_recent_chooser_default_set_sort_func (GtkRecentChooser  *chooser,
1225                                           GtkRecentSortFunc  sort_func,
1226                                           gpointer           sort_data,
1227                                           GDestroyNotify     data_destroy)
1228 {
1229   GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
1230   
1231   if (impl->sort_data_destroy)
1232     {
1233       impl->sort_data_destroy (impl->sort_data);
1234       impl->sort_data_destroy = NULL;
1235     }
1236       
1237   impl->sort_func = NULL;
1238   impl->sort_data = NULL;
1239   
1240   if (sort_func)
1241     {
1242       impl->sort_func = sort_func;
1243       impl->sort_data = sort_data;
1244       impl->sort_data_destroy = data_destroy;
1245     }
1246 }
1247
1248 static GList *
1249 gtk_recent_chooser_default_get_items (GtkRecentChooser *chooser)
1250 {
1251   GtkRecentChooserDefault *impl;
1252
1253   impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
1254
1255   return _gtk_recent_chooser_get_items (chooser,
1256                                         impl->current_filter,
1257                                         impl->sort_func,
1258                                         impl->sort_data);
1259 }
1260
1261 static GtkRecentManager *
1262 gtk_recent_chooser_default_get_recent_manager (GtkRecentChooser *chooser)
1263 {
1264   return GTK_RECENT_CHOOSER_DEFAULT (chooser)->manager;
1265 }
1266
1267 static void
1268 show_filters (GtkRecentChooserDefault *impl,
1269               gboolean                 show)
1270 {
1271   if (show)
1272     gtk_widget_show (impl->filter_combo_hbox);
1273   else
1274     gtk_widget_hide (impl->filter_combo_hbox);
1275 }
1276
1277 static void
1278 gtk_recent_chooser_default_add_filter (GtkRecentChooser *chooser,
1279                                        GtkRecentFilter  *filter)
1280 {
1281   GtkRecentChooserDefault *impl;
1282   const gchar *name;
1283
1284   impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
1285   
1286   if (g_slist_find (impl->filters, filter))
1287     {
1288       g_warning ("gtk_recent_chooser_add_filter() called on filter already in list\n");
1289       return;
1290     }
1291   
1292   g_object_ref_sink (filter);
1293   impl->filters = g_slist_append (impl->filters, filter);
1294   
1295   /* display new filter */
1296   name = gtk_recent_filter_get_name (filter);
1297   if (!name)
1298     name = _("Untitled filter");
1299     
1300   gtk_combo_box_append_text (GTK_COMBO_BOX (impl->filter_combo), name);
1301   
1302   if (!g_slist_find (impl->filters, impl->current_filter))
1303     set_current_filter (impl, filter);
1304   
1305   show_filters (impl, TRUE);
1306 }
1307
1308 static void
1309 gtk_recent_chooser_default_remove_filter (GtkRecentChooser *chooser,
1310                                           GtkRecentFilter  *filter)
1311 {
1312   GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
1313   GtkTreeModel *model;
1314   GtkTreeIter iter;
1315   gint filter_idx;
1316   
1317   filter_idx = g_slist_index (impl->filters, filter);
1318   
1319   if (filter_idx < 0)
1320     {
1321       g_warning ("gtk_recent_chooser_remove_filter() called on filter not in list\n");
1322       return;  
1323     }
1324   
1325   impl->filters = g_slist_remove (impl->filters, filter);
1326   
1327   if (filter == impl->current_filter)
1328     {
1329       if (impl->filters)
1330         set_current_filter (impl, impl->filters->data);
1331       else
1332         set_current_filter (impl, NULL);
1333     }
1334   
1335   model = gtk_combo_box_get_model (GTK_COMBO_BOX (impl->filter_combo));
1336   gtk_tree_model_iter_nth_child (model, &iter, NULL, filter_idx);
1337   gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
1338   
1339   g_object_unref (filter);
1340   
1341   if (!impl->filters)
1342     show_filters (impl, FALSE);
1343 }
1344
1345 static GSList *
1346 gtk_recent_chooser_default_list_filters (GtkRecentChooser *chooser)
1347 {
1348   GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
1349   
1350   return g_slist_copy (impl->filters);
1351 }
1352
1353 static void
1354 set_current_filter (GtkRecentChooserDefault *impl,
1355                     GtkRecentFilter         *filter)
1356 {
1357   if (impl->current_filter != filter)
1358     {
1359       gint filter_idx;
1360       
1361       filter_idx = g_slist_index (impl->filters, filter);
1362       if (impl->filters && filter && filter_idx < 0)
1363         return;
1364       
1365       if (impl->current_filter)
1366         g_object_unref (impl->current_filter);
1367       
1368       impl->current_filter = filter;
1369       
1370       if (impl->current_filter)     
1371         {
1372           g_object_ref_sink (impl->current_filter);
1373         }
1374       
1375       if (impl->filters)
1376         gtk_combo_box_set_active (GTK_COMBO_BOX (impl->filter_combo),
1377                                   filter_idx);
1378       
1379       if (impl->recent_store)
1380         reload_recent_items (impl);
1381
1382       g_object_notify (G_OBJECT (impl), "filter");
1383     }
1384 }
1385
1386 static void
1387 chooser_set_sort_type (GtkRecentChooserDefault *impl,
1388                        GtkRecentSortType        sort_type)
1389 {
1390   if (impl->sort_type != sort_type)
1391     {
1392       impl->sort_type = sort_type;
1393       reload_recent_items (impl);
1394
1395       g_object_notify (G_OBJECT (impl), "sort-type");
1396     }
1397 }
1398
1399
1400 static GtkIconTheme *
1401 get_icon_theme_for_widget (GtkWidget *widget)
1402 {
1403   if (gtk_widget_has_screen (widget))
1404     return gtk_icon_theme_get_for_screen (gtk_widget_get_screen (widget));
1405
1406   return gtk_icon_theme_get_default ();
1407 }
1408
1409 static gint
1410 get_icon_size_for_widget (GtkWidget   *widget,
1411                           GtkIconSize  icon_size)
1412 {
1413   GtkSettings *settings;
1414   gint width, height;
1415
1416   if (gtk_widget_has_screen (widget))
1417     settings = gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
1418   else
1419     settings = gtk_settings_get_default ();
1420
1421   if (gtk_icon_size_lookup_for_settings (settings, icon_size,
1422                                          &width, &height))
1423     return MAX (width, height);
1424
1425   return FALLBACK_ICON_SIZE;
1426 }
1427
1428 static gint
1429 get_recent_files_limit (GtkWidget *widget)
1430 {
1431   GtkSettings *settings;
1432   gint limit;
1433
1434   if (gtk_widget_has_screen (widget))
1435     settings = gtk_settings_get_for_screen (gtk_widget_get_screen (widget));
1436   else
1437     settings = gtk_settings_get_default ();
1438   
1439   g_object_get (G_OBJECT (settings), "gtk-recent-files-limit", &limit, NULL);
1440
1441   return limit;
1442 }
1443
1444 static void
1445 recent_manager_changed_cb (GtkRecentManager *manager,
1446                            gpointer          user_data)
1447 {
1448   GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
1449
1450   reload_recent_items (impl);
1451 }
1452
1453 static void
1454 selection_changed_cb (GtkTreeSelection *selection,
1455                       gpointer          user_data)
1456 {
1457   _gtk_recent_chooser_selection_changed (GTK_RECENT_CHOOSER (user_data));
1458 }
1459
1460 static void
1461 row_activated_cb (GtkTreeView       *tree_view,
1462                   GtkTreePath       *tree_path,
1463                   GtkTreeViewColumn *tree_column,
1464                   gpointer           user_data)
1465 {
1466   _gtk_recent_chooser_item_activated (GTK_RECENT_CHOOSER (user_data));
1467 }
1468
1469 static void
1470 filter_combo_changed_cb (GtkComboBox *combo_box,
1471                          gpointer     user_data)
1472 {
1473   GtkRecentChooserDefault *impl;
1474   gint new_index;
1475   GtkRecentFilter *filter;
1476   
1477   impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
1478   
1479   new_index = gtk_combo_box_get_active (combo_box);
1480   filter = g_slist_nth_data (impl->filters, new_index);
1481   
1482   set_current_filter (impl, filter);
1483 }
1484
1485 static GdkPixbuf *
1486 get_drag_pixbuf (GtkRecentChooserDefault *impl)
1487 {
1488   GtkRecentInfo *info;
1489   GdkPixbuf *retval;
1490   gint size;
1491   
1492   g_assert (GTK_IS_RECENT_CHOOSER_DEFAULT (impl));
1493
1494   info = gtk_recent_chooser_get_current_item (GTK_RECENT_CHOOSER (impl));
1495   if (!info)
1496     return NULL;
1497
1498   size = get_icon_size_for_widget (GTK_WIDGET (impl), GTK_ICON_SIZE_DND);
1499
1500   retval = gtk_recent_info_get_icon (info, size);
1501   gtk_recent_info_unref (info);
1502
1503   return retval;
1504 }
1505
1506 static void
1507 recent_view_drag_begin_cb (GtkWidget      *widget,
1508                            GdkDragContext *context,
1509                            gpointer        user_data)
1510 {
1511   GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
1512   GdkPixbuf *pixbuf;
1513
1514   pixbuf = get_drag_pixbuf (impl);
1515   if (pixbuf)
1516     {
1517       gtk_drag_set_icon_pixbuf (context, pixbuf, 0, 0);
1518       g_object_unref (pixbuf);
1519     }
1520   else
1521     gtk_drag_set_icon_default (context);
1522 }
1523
1524 typedef struct
1525 {
1526   gchar **uri_list;
1527   gsize next_pos;
1528 } DragData;
1529
1530 static void
1531 append_uri_to_urilist (GtkTreeModel *model,
1532                        GtkTreePath  *path,
1533                        GtkTreeIter  *iter,
1534                        gpointer      user_data)
1535 {
1536   DragData *drag_data = (DragData *) user_data;
1537   GtkTreeModel *child_model;
1538   GtkTreeIter child_iter;
1539   gchar *uri = NULL;
1540   gsize pos;
1541
1542   child_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
1543   gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model),
1544                                                     &child_iter,
1545                                                     iter);
1546   gtk_tree_model_get (child_model, &child_iter,
1547                       RECENT_URI_COLUMN, &uri,
1548                       -1);
1549   g_assert (uri != NULL);
1550
1551   pos = drag_data->next_pos;
1552   drag_data->uri_list[pos] = g_strdup (uri);
1553   drag_data->next_pos = pos + 1;
1554 }
1555
1556 static void
1557 recent_view_drag_data_get_cb (GtkWidget        *widget,
1558                               GdkDragContext   *context,
1559                               GtkSelectionData *selection_data,
1560                               guint             info,
1561                               guint32           time_,
1562                               gpointer          data)
1563 {
1564   GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (data);
1565   DragData drag_data;
1566   gsize n_uris;
1567   
1568   n_uris = gtk_tree_selection_count_selected_rows (impl->selection);
1569   if (n_uris == 0)
1570     return;
1571
1572   drag_data.uri_list = g_new0 (gchar *, n_uris + 1);
1573   drag_data.next_pos = 0;
1574   
1575   gtk_tree_selection_selected_foreach (impl->selection,
1576                                        append_uri_to_urilist,
1577                                        &drag_data);
1578   
1579   gtk_selection_data_set_uris (selection_data, drag_data.uri_list);
1580
1581   g_strfreev (drag_data.uri_list);
1582 }
1583
1584 static gboolean
1585 recent_view_query_tooltip_cb (GtkWidget  *widget,
1586                               gint        x,
1587                               gint        y,
1588                               gboolean    keyboard_tip,
1589                               GtkTooltip *tooltip,
1590                               gpointer    user_data)
1591 {
1592   GtkRecentChooserDefault *impl = user_data;
1593   GtkTreeView *tree_view;
1594   GtkTreeIter iter;
1595   GtkTreePath *path = NULL;
1596   GtkRecentInfo *info = NULL;
1597   gchar *uri_display;
1598
1599   if (!impl->show_tips)
1600     return FALSE;
1601
1602   tree_view = GTK_TREE_VIEW (impl->recent_view);
1603
1604   gtk_tree_view_get_tooltip_context (tree_view,
1605                                      &x, &y,
1606                                      keyboard_tip,
1607                                      NULL, &path, NULL);
1608   if (!path)
1609     return FALSE;
1610
1611   if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->recent_store), &iter, path))
1612     {
1613       gtk_tree_path_free (path);
1614       return FALSE;
1615     }
1616
1617   gtk_tree_model_get (GTK_TREE_MODEL (impl->recent_store), &iter,
1618                       RECENT_INFO_COLUMN, &info,
1619                       -1);
1620
1621   uri_display = gtk_recent_info_get_uri_display (info);
1622   
1623   gtk_tooltip_set_text (tooltip, uri_display);
1624   gtk_tree_view_set_tooltip_row (tree_view, tooltip, path);
1625
1626   g_free (uri_display);
1627   gtk_tree_path_free (path);
1628   gtk_recent_info_unref (info);
1629
1630   return TRUE;
1631 }
1632
1633 static void
1634 remove_selected_from_list (GtkRecentChooserDefault *impl)
1635 {
1636   gchar *uri;
1637   GError *err;
1638   
1639   if (impl->select_multiple)
1640     return;
1641   
1642   uri = gtk_recent_chooser_get_current_uri (GTK_RECENT_CHOOSER (impl));
1643   if (!uri)
1644     return;
1645   
1646   err = NULL;
1647   if (!gtk_recent_manager_remove_item (impl->manager, uri, &err))
1648     {
1649       gchar *msg;
1650    
1651       msg = g_strdup (_("Could not remove item"));
1652       error_message (impl, msg, err->message);
1653       
1654       g_free (msg);
1655       g_error_free (err);
1656     }
1657   
1658   g_free (uri);
1659 }
1660
1661 static void
1662 copy_activated_cb (GtkMenuItem *menu_item,
1663                    gpointer     user_data)
1664 {
1665   GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
1666   GtkRecentInfo *info;
1667   gchar *utf8_uri;
1668
1669   info = gtk_recent_chooser_get_current_item (GTK_RECENT_CHOOSER (impl));
1670   if (!info)
1671     return;
1672
1673   utf8_uri = gtk_recent_info_get_uri_display (info);
1674   
1675   gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (impl),
1676                                                     GDK_SELECTION_CLIPBOARD),
1677                           utf8_uri, -1);
1678
1679   gtk_recent_info_unref (info);
1680   g_free (utf8_uri);
1681 }
1682
1683 static void
1684 remove_all_activated_cb (GtkMenuItem *menu_item,
1685                          gpointer     user_data)
1686 {
1687   GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
1688   GError *err = NULL;
1689   
1690   gtk_recent_manager_purge_items (impl->manager, &err);
1691   if (err)
1692     {
1693        gchar *msg;
1694
1695        msg = g_strdup (_("Could not clear list"));
1696
1697        error_message (impl, msg, err->message);
1698        
1699        g_free (msg);
1700        g_error_free (err);
1701     }
1702 }
1703
1704 static void
1705 remove_item_activated_cb (GtkMenuItem *menu_item,
1706                           gpointer     user_data)
1707 {
1708   GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
1709   
1710   remove_selected_from_list (impl);
1711 }
1712
1713 static void
1714 show_private_toggled_cb (GtkCheckMenuItem *menu_item,
1715                          gpointer          user_data)
1716 {
1717   GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
1718   
1719   g_object_set (G_OBJECT (impl),
1720                 "show-private", gtk_check_menu_item_get_active (menu_item),
1721                 NULL);
1722 }
1723
1724 static void
1725 recent_popup_menu_detach_cb (GtkWidget *attach_widget,
1726                              GtkMenu   *menu)
1727 {
1728   GtkRecentChooserDefault *impl;
1729   
1730   impl = g_object_get_data (G_OBJECT (attach_widget), "GtkRecentChooserDefault");
1731   g_assert (GTK_IS_RECENT_CHOOSER_DEFAULT (impl));
1732   
1733   impl->recent_popup_menu = NULL;
1734   impl->recent_popup_menu_remove_item = NULL;
1735   impl->recent_popup_menu_copy_item = NULL;
1736   impl->recent_popup_menu_clear_item = NULL;
1737   impl->recent_popup_menu_show_private_item = NULL;
1738 }
1739
1740 static void
1741 recent_view_menu_ensure_state (GtkRecentChooserDefault *impl)
1742 {
1743   gint count;
1744   
1745   g_assert (GTK_IS_RECENT_CHOOSER_DEFAULT (impl));
1746   g_assert (impl->recent_popup_menu != NULL);
1747
1748   if (!impl->manager)
1749     count = 0;
1750   else
1751     g_object_get (G_OBJECT (impl->manager), "size", &count, NULL);
1752
1753   if (count == 0)
1754     {
1755       gtk_widget_set_sensitive (impl->recent_popup_menu_remove_item, FALSE);
1756       gtk_widget_set_sensitive (impl->recent_popup_menu_copy_item, FALSE);
1757       gtk_widget_set_sensitive (impl->recent_popup_menu_clear_item, FALSE);
1758       gtk_widget_set_sensitive (impl->recent_popup_menu_show_private_item, FALSE);
1759     }
1760 }
1761
1762 static void
1763 recent_view_menu_build (GtkRecentChooserDefault *impl)
1764 {
1765   GtkWidget *item;
1766   
1767   if (impl->recent_popup_menu)
1768     {
1769       recent_view_menu_ensure_state (impl);
1770       
1771       return;
1772     }
1773   
1774   impl->recent_popup_menu = gtk_menu_new ();
1775   gtk_menu_attach_to_widget (GTK_MENU (impl->recent_popup_menu),
1776                              impl->recent_view,
1777                              recent_popup_menu_detach_cb);
1778   
1779   item = gtk_image_menu_item_new_with_mnemonic (_("Copy _Location"));
1780   impl->recent_popup_menu_copy_item = item;
1781   gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item),
1782                                  gtk_image_new_from_stock (GTK_STOCK_COPY, GTK_ICON_SIZE_MENU));
1783   g_signal_connect (item, "activate",
1784                     G_CALLBACK (copy_activated_cb), impl);
1785   gtk_widget_show (item);
1786   gtk_menu_shell_append (GTK_MENU_SHELL (impl->recent_popup_menu), item);
1787
1788   item = gtk_separator_menu_item_new ();
1789   gtk_widget_show (item);
1790   gtk_menu_shell_append (GTK_MENU_SHELL (impl->recent_popup_menu), item);
1791   
1792   item = gtk_image_menu_item_new_with_mnemonic (_("_Remove From List"));
1793   impl->recent_popup_menu_remove_item = item;
1794   gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item),
1795                                  gtk_image_new_from_stock (GTK_STOCK_REMOVE, GTK_ICON_SIZE_MENU));
1796   g_signal_connect (item, "activate",
1797                     G_CALLBACK (remove_item_activated_cb), impl);
1798   gtk_widget_show (item);
1799   gtk_menu_shell_append (GTK_MENU_SHELL (impl->recent_popup_menu), item);
1800
1801   item = gtk_image_menu_item_new_with_mnemonic (_("_Clear List"));
1802   impl->recent_popup_menu_clear_item = item;
1803   gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item),
1804                                  gtk_image_new_from_stock (GTK_STOCK_CLEAR, GTK_ICON_SIZE_MENU));
1805   g_signal_connect (item, "activate",
1806                     G_CALLBACK (remove_all_activated_cb), impl);
1807   
1808   gtk_widget_show (item);
1809   gtk_menu_shell_append (GTK_MENU_SHELL (impl->recent_popup_menu), item);
1810   
1811   item = gtk_separator_menu_item_new ();
1812   gtk_widget_show (item);
1813   gtk_menu_shell_append (GTK_MENU_SHELL (impl->recent_popup_menu), item);
1814   
1815   item = gtk_check_menu_item_new_with_mnemonic (_("Show _Private Resources"));
1816   impl->recent_popup_menu_show_private_item = item;
1817   gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), impl->show_private);
1818   g_signal_connect (item, "toggled",
1819                     G_CALLBACK (show_private_toggled_cb), impl);
1820   gtk_widget_show (item);
1821   gtk_menu_shell_append (GTK_MENU_SHELL (impl->recent_popup_menu), item);
1822   
1823   recent_view_menu_ensure_state (impl);
1824 }
1825
1826 /* taken from gtkfilechooserdefault.c */
1827 static void
1828 popup_position_func (GtkMenu   *menu,
1829                      gint      *x,
1830                      gint      *y,
1831                      gboolean  *push_in,
1832                      gpointer   user_data)
1833 {
1834   GtkWidget *widget = GTK_WIDGET (user_data);
1835   GdkScreen *screen = gtk_widget_get_screen (widget);
1836   GtkRequisition req;
1837   gint monitor_num;
1838   GdkRectangle monitor;
1839
1840   if (G_UNLIKELY (!GTK_WIDGET_REALIZED (widget)))
1841     return;
1842
1843   gdk_window_get_origin (widget->window, x, y);
1844
1845   gtk_widget_size_request (GTK_WIDGET (menu), &req);
1846
1847   *x += (widget->allocation.width - req.width) / 2;
1848   *y += (widget->allocation.height - req.height) / 2;
1849
1850   monitor_num = gdk_screen_get_monitor_at_point (screen, *x, *y);
1851   gtk_menu_set_monitor (menu, monitor_num);
1852   gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
1853
1854   *x = CLAMP (*x, monitor.x, monitor.x + MAX (0, monitor.width - req.width));
1855   *y = CLAMP (*y, monitor.y, monitor.y + MAX (0, monitor.height - req.height));
1856
1857   *push_in = FALSE;
1858 }
1859
1860
1861 static void
1862 recent_view_menu_popup (GtkRecentChooserDefault *impl,
1863                         GdkEventButton          *event)
1864 {
1865   recent_view_menu_build (impl);
1866   
1867   if (event)
1868     gtk_menu_popup (GTK_MENU (impl->recent_popup_menu),
1869                     NULL, NULL, NULL, NULL,
1870                     event->button, event->time);
1871   else
1872     {
1873       gtk_menu_popup (GTK_MENU (impl->recent_popup_menu),
1874                       NULL, NULL,
1875                       popup_position_func, impl->recent_view,
1876                       0, GDK_CURRENT_TIME);
1877       gtk_menu_shell_select_first (GTK_MENU_SHELL (impl->recent_popup_menu),
1878                                    FALSE);
1879     }
1880 }
1881
1882 static gboolean
1883 recent_view_popup_menu_cb (GtkWidget *widget,
1884                            gpointer   user_data)
1885 {
1886   recent_view_menu_popup (GTK_RECENT_CHOOSER_DEFAULT (user_data), NULL);
1887   return TRUE;
1888 }
1889
1890 static gboolean
1891 recent_view_button_press_cb (GtkWidget      *widget,
1892                              GdkEventButton *event,
1893                              gpointer        user_data)
1894 {
1895   GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
1896   
1897   if (event->button == 3)
1898     {
1899       GtkTreePath *path;
1900       gboolean res;
1901
1902       if (event->window != gtk_tree_view_get_bin_window (GTK_TREE_VIEW (impl->recent_view)))
1903         return FALSE;
1904
1905       res = gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (impl->recent_view),
1906                                            event->x, event->y,
1907                                            &path,
1908                                            NULL, NULL, NULL);
1909       if (!res)
1910         return FALSE;
1911
1912       /* select the path before creating the popup menu */
1913       gtk_tree_selection_select_path (impl->selection, path);
1914       gtk_tree_path_free (path);
1915       
1916       recent_view_menu_popup (impl, event);
1917
1918       return TRUE;
1919     }
1920   
1921   return FALSE;
1922 }
1923
1924 static void
1925 set_recent_manager (GtkRecentChooserDefault *impl,
1926                     GtkRecentManager        *manager)
1927 {
1928   if (impl->manager)
1929     {
1930       if (impl->manager_changed_id)
1931         {
1932           g_signal_handler_disconnect (impl, impl->manager_changed_id);
1933           impl->manager_changed_id = 0;
1934         }
1935
1936       impl->manager = NULL;
1937     }
1938   
1939   if (manager)
1940     impl->manager = manager;
1941   else
1942     impl->manager = gtk_recent_manager_get_default ();
1943   
1944   if (impl->manager)
1945     {
1946       impl->manager_changed_id = g_signal_connect (impl->manager, "changed",
1947                                                    G_CALLBACK (recent_manager_changed_cb),
1948                                                    impl);
1949     }
1950 }
1951
1952 static void
1953 gtk_recent_chooser_update (GtkActivatable *activatable,
1954                            GtkAction      *action,
1955                            const gchar    *property_name)
1956 {
1957   if (strcmp (property_name, "visible") == 0)
1958     {
1959       if (gtk_action_is_visible (action))
1960         gtk_widget_show (GTK_WIDGET (activatable));
1961       else
1962         gtk_widget_hide (GTK_WIDGET (activatable));
1963     }
1964
1965   if (strcmp (property_name, "sensitive") == 0)
1966     gtk_widget_set_sensitive (GTK_WIDGET (activatable), gtk_action_is_sensitive (action));
1967
1968   _gtk_recent_chooser_update (activatable, action, property_name);
1969 }
1970
1971
1972 static void 
1973 gtk_recent_chooser_sync_action_properties (GtkActivatable *activatable,
1974                                            GtkAction      *action)
1975 {
1976   if (action)
1977     {
1978       if (gtk_action_is_visible (action))
1979         gtk_widget_show (GTK_WIDGET (activatable));
1980       else
1981         gtk_widget_hide (GTK_WIDGET (activatable));
1982       
1983       gtk_widget_set_sensitive (GTK_WIDGET (activatable), gtk_action_is_sensitive (action));
1984     }
1985
1986   _gtk_recent_chooser_sync_action_properties (activatable, action);
1987 }
1988
1989
1990 GtkWidget *
1991 _gtk_recent_chooser_default_new (GtkRecentManager *manager)
1992 {
1993   return g_object_new (GTK_TYPE_RECENT_CHOOSER_DEFAULT,
1994                        "recent-manager", manager,
1995                        NULL);
1996 }