]> Pileus Git - ~andy/gtk/blob - gtk/gtkrecentmanager.c
Replace uses of xdgmime with g_content_type.
[~andy/gtk] / gtk / gtkrecentmanager.c
1 /* GTK - The GIMP Toolkit
2  * gtkrecentmanager.c: a manager for the recently used resources
3  *
4  * Copyright (C) 2006 Emmanuele Bassi
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  */
20
21 #include "config.h"
22
23 #include <sys/types.h>
24 #include <sys/stat.h>
25 #ifdef HAVE_UNISTD_H
26 #include <unistd.h>
27 #endif
28 #include <errno.h>
29 #include <string.h>
30 #include <stdlib.h>
31 #include <glib.h>
32 #include <glib/gstdio.h>
33 #include <gio/gio.h>
34
35 #include "gtkrecentmanager.h"
36 #include "gtkintl.h"
37 #include "gtkstock.h"
38 #include "gtkicontheme.h"
39 #include "gtktypebuiltins.h"
40 #include "gtkprivate.h"
41 #include "gtkmarshalers.h"
42 #include "gtkalias.h"
43
44 /* the file where we store the recently used items */
45 #define GTK_RECENTLY_USED_FILE  ".recently-used.xbel"
46
47 /* return all items by default */
48 #define DEFAULT_LIMIT   -1
49
50 /* keep in sync with xdgmime */
51 #define GTK_RECENT_DEFAULT_MIME "application/octet-stream"
52
53 typedef struct
54 {
55   gchar *name;
56   gchar *exec;
57   
58   guint count;
59   
60   time_t stamp;
61 } RecentAppInfo;
62
63 struct _GtkRecentInfo
64 {
65   gchar *uri;
66   
67   gchar *display_name;
68   gchar *description;
69   
70   time_t added;
71   time_t modified;
72   time_t visited;
73   
74   gchar *mime_type;
75   
76   GSList *applications;
77   GHashTable *apps_lookup;
78   
79   GSList *groups;
80   
81   gboolean is_private;
82   
83   GdkPixbuf *icon;
84   
85   gint ref_count;
86 };
87
88 #define GTK_RECENT_MANAGER_GET_PRIVATE(obj)     (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_RECENT_MANAGER, GtkRecentManagerPrivate))
89
90 struct _GtkRecentManagerPrivate
91 {
92   gchar *filename;
93
94   guint is_dirty : 1;
95   
96   gint limit;
97   gint size;
98
99   GBookmarkFile *recent_items;
100
101   GFileMonitor *monitor;
102 };
103
104 enum
105 {
106   PROP_0,
107
108   PROP_FILENAME,  
109   PROP_LIMIT,
110   PROP_SIZE
111 };
112
113 static void     gtk_recent_manager_dispose             (GObject           *object);
114 static void     gtk_recent_manager_finalize            (GObject           *object);
115 static void     gtk_recent_manager_set_property        (GObject           *object,
116                                                         guint              prop_id,
117                                                         const GValue      *value,
118                                                         GParamSpec        *pspec);
119 static void     gtk_recent_manager_get_property        (GObject           *object,
120                                                         guint              prop_id,
121                                                         GValue            *value,
122                                                         GParamSpec        *pspec);
123 static void     gtk_recent_manager_add_item_query_info (GObject           *source_object,
124                                                         GAsyncResult      *res,
125                                                         gpointer           user_data);
126 static void     gtk_recent_manager_monitor_changed     (GFileMonitor      *monitor,
127                                                         GFile             *file,
128                                                         GFile             *other_file,
129                                                         GFileMonitorEvent  event_type,
130                                                         gpointer           user_data);
131 static void     gtk_recent_manager_changed             (GtkRecentManager  *manager);
132 static void     gtk_recent_manager_real_changed        (GtkRecentManager  *manager);
133 static void     gtk_recent_manager_set_filename        (GtkRecentManager  *manager,
134                                                         const gchar       *filename);
135 static void     gtk_recent_manager_clamp_to_age        (GtkRecentManager  *manager,
136                                                         gint               age);
137
138
139 static void build_recent_items_list (GtkRecentManager  *manager);
140 static void purge_recent_items_list (GtkRecentManager  *manager,
141                                      GError           **error);
142
143 static RecentAppInfo *recent_app_info_new  (const gchar   *app_name);
144 static void           recent_app_info_free (RecentAppInfo *app_info);
145
146 static GtkRecentInfo *gtk_recent_info_new  (const gchar   *uri);
147 static void           gtk_recent_info_free (GtkRecentInfo *recent_info);
148
149 static guint signal_changed = 0;
150
151 static GtkRecentManager *recent_manager_singleton = NULL;
152
153 G_DEFINE_TYPE (GtkRecentManager, gtk_recent_manager, G_TYPE_OBJECT)
154
155 static void
156 filename_warning (const gchar *format, 
157                   const gchar *filename, 
158                   const gchar *message)
159 {
160   gchar *utf8 = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
161   g_warning (format, utf8 ? utf8 : "(invalid filename)", message);
162   g_free (utf8);
163 }
164
165 /* Test of haystack has the needle prefix, comparing case
166  * insensitive. haystack may be UTF-8, but needle must
167  * contain only lowercase ascii. */
168 static gboolean
169 has_case_prefix (const gchar *haystack, 
170                  const gchar *needle)
171 {
172   const gchar *h, *n;
173
174   /* Eat one character at a time. */
175   h = haystack;
176   n = needle;
177
178   while (*n && *h && *n == g_ascii_tolower (*h))
179     {
180       n++;
181       h++;
182     }
183
184   return *n == '\0';
185 }
186
187 GQuark
188 gtk_recent_manager_error_quark (void)
189 {
190   return g_quark_from_static_string ("gtk-recent-manager-error-quark");
191 }
192
193 static void
194 gtk_recent_manager_class_init (GtkRecentManagerClass *klass)
195 {
196   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
197   
198   gobject_class->set_property = gtk_recent_manager_set_property;
199   gobject_class->get_property = gtk_recent_manager_get_property;
200   gobject_class->dispose = gtk_recent_manager_dispose;
201   gobject_class->finalize = gtk_recent_manager_finalize;
202   
203   /**
204    * GtkRecentManager:filename
205    *
206    * The full path to the file to be used to store and read the recently
207    * used resources list
208    *
209    * Since: 2.10
210    */
211   g_object_class_install_property (gobject_class,
212                                    PROP_FILENAME,
213                                    g_param_spec_string ("filename",
214                                                         P_("Filename"),
215                                                         P_("The full path to the file to be used to store and read the list"),
216                                                         NULL,
217                                                         (G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE)));
218   /**
219    * GtkRecentManager:limit
220    *
221    * The maximum number of items to be returned by the
222    * gtk_recent_manager_get_items() function.
223    *
224    * Since: 2.10
225    */
226   g_object_class_install_property (gobject_class,
227                                    PROP_LIMIT,
228                                    g_param_spec_int ("limit",
229                                                      P_("Limit"),
230                                                      P_("The maximum number of items to be returned by gtk_recent_manager_get_items()"),
231                                                      -1,
232                                                      G_MAXINT,
233                                                      DEFAULT_LIMIT,
234                                                      G_PARAM_READWRITE));
235   /**
236    * GtkRecentManager:size
237    * 
238    * The size of the recently used resources list.
239    *
240    * Since: 2.10
241    */
242   g_object_class_install_property (gobject_class,
243                                    PROP_SIZE,
244                                    g_param_spec_int ("size",
245                                                      P_("Size"),
246                                                      P_("The size of the recently used resources list"),
247                                                      -1,
248                                                      G_MAXINT,
249                                                      0,
250                                                      G_PARAM_READABLE));
251   
252   /**
253    * GtkRecentManager::changed
254    * @recent_manager: the recent manager
255    *
256    * Emitted when the current recently used resources manager changes its
257    * contents.
258    *
259    * Since: 2.10
260    */
261   signal_changed =
262     g_signal_new (I_("changed"),
263                   G_TYPE_FROM_CLASS (klass),
264                   G_SIGNAL_RUN_FIRST,
265                   G_STRUCT_OFFSET (GtkRecentManagerClass, changed),
266                   NULL, NULL,
267                   g_cclosure_marshal_VOID__VOID,
268                   G_TYPE_NONE, 0);
269   
270   klass->changed = gtk_recent_manager_real_changed;
271   
272   g_type_class_add_private (klass, sizeof (GtkRecentManagerPrivate));
273 }
274
275 static void
276 gtk_recent_manager_init (GtkRecentManager *manager)
277 {
278   GtkRecentManagerPrivate *priv;
279
280   manager->priv = priv = GTK_RECENT_MANAGER_GET_PRIVATE (manager);
281   
282   priv->limit = DEFAULT_LIMIT;
283   priv->size = 0;
284
285   priv->filename = NULL;
286 }
287
288 static void
289 gtk_recent_manager_set_property (GObject               *object,
290                                  guint                  prop_id,
291                                  const GValue          *value,
292                                  GParamSpec            *pspec)
293 {
294   GtkRecentManager *recent_manager = GTK_RECENT_MANAGER (object);
295  
296   switch (prop_id)
297     {
298     case PROP_FILENAME:
299       gtk_recent_manager_set_filename (recent_manager, g_value_get_string (value));
300       break;      
301     case PROP_LIMIT:
302       gtk_recent_manager_set_limit (recent_manager, g_value_get_int (value));
303       break;
304     default:
305       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
306       break;
307     }
308 }
309
310 static void
311 gtk_recent_manager_get_property (GObject               *object,
312                                  guint                  prop_id,
313                                  GValue                *value,
314                                  GParamSpec            *pspec)
315 {
316   GtkRecentManager *recent_manager = GTK_RECENT_MANAGER (object);
317   
318   switch (prop_id)
319     {
320     case PROP_FILENAME:
321       g_value_set_string (value, recent_manager->priv->filename);
322       break;
323     case PROP_LIMIT:
324       g_value_set_int (value, recent_manager->priv->limit);
325       break;
326     case PROP_SIZE:
327       g_value_set_int (value, recent_manager->priv->size);
328       break;
329     default:
330       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
331       break;
332     }
333
334
335 static void
336 gtk_recent_manager_dispose (GObject *object)
337 {
338   GtkRecentManager *manager = GTK_RECENT_MANAGER (object);
339   GtkRecentManagerPrivate *priv = manager->priv;
340
341   if (priv->monitor)
342     {
343       g_signal_handlers_disconnect_by_func (priv->monitor,
344                                             G_CALLBACK (gtk_recent_manager_monitor_changed),
345                                             manager);
346       g_object_unref (priv->monitor);
347       priv->monitor = NULL;
348     }
349
350   G_OBJECT_CLASS (gtk_recent_manager_parent_class)->dispose (object);
351 }
352
353 static void
354 gtk_recent_manager_finalize (GObject *object)
355 {
356   GtkRecentManager *manager = GTK_RECENT_MANAGER (object);
357   GtkRecentManagerPrivate *priv = manager->priv;
358
359   g_free (priv->filename);
360   
361   if (priv->recent_items)
362     g_bookmark_file_free (priv->recent_items);
363
364   G_OBJECT_CLASS (gtk_recent_manager_parent_class)->finalize (object);
365 }
366
367 static void
368 gtk_recent_manager_real_changed (GtkRecentManager *manager)
369 {
370   GtkRecentManagerPrivate *priv = manager->priv;
371
372   g_object_freeze_notify (G_OBJECT (manager));
373
374   if (priv->is_dirty)
375     {
376       GError *write_error;
377       
378       /* we are marked as dirty, so we dump the content of our
379        * recently used items list
380        */
381       g_assert (priv->filename != NULL);
382
383       if (!priv->recent_items)
384         {
385           /* if no container object has been defined, we create a new
386            * empty container, and dump it
387            */
388           priv->recent_items = g_bookmark_file_new ();
389           priv->size = 0;
390         }
391       else
392         {
393           GtkSettings *settings = gtk_settings_get_default ();
394           gint age = 30;
395
396           g_object_get (G_OBJECT (settings), "gtk-recent-files-max-age", &age, NULL);
397           if (age > 0)
398             gtk_recent_manager_clamp_to_age (manager, age);
399           else if (age == 0)
400             {
401               g_bookmark_file_free (priv->recent_items);
402               priv->recent_items = NULL;
403
404               priv->recent_items = g_bookmark_file_new ();
405             }
406         }
407
408       write_error = NULL;
409       g_bookmark_file_to_file (priv->recent_items, priv->filename, &write_error);
410       if (write_error)
411         {
412           filename_warning ("Attempting to store changes into `%s', "
413                             "but failed: %s",
414                             priv->filename,
415                             write_error->message);
416           g_error_free (write_error);
417         }
418
419       /* mark us as clean */
420       priv->is_dirty = FALSE;
421     }
422   else
423     {
424       /* we are not marked as dirty, so we have been called
425        * because the recently used resources file has been
426        * changed (and not from us).
427        */
428       build_recent_items_list (manager);
429     }
430
431   g_object_thaw_notify (G_OBJECT (manager));
432 }
433
434 static void
435 gtk_recent_manager_monitor_changed (GFileMonitor      *monitor,
436                                     GFile             *file,
437                                     GFile             *other_file,
438                                     GFileMonitorEvent  event_type,
439                                     gpointer           user_data)
440 {
441   GtkRecentManager *manager = user_data;
442
443   switch (event_type)
444     {
445     case G_FILE_MONITOR_EVENT_CHANGED:
446     case G_FILE_MONITOR_EVENT_CREATED:
447       gtk_recent_manager_changed (manager);
448       break;
449
450     case G_FILE_MONITOR_EVENT_DELETED:
451       break;
452
453     default:
454       break;
455     }
456 }
457
458 static void
459 gtk_recent_manager_set_filename (GtkRecentManager *manager,
460                                  const gchar      *filename)
461 {
462   GtkRecentManagerPrivate *priv;
463   GFile *file;
464   GError *error;
465   
466   g_assert (GTK_IS_RECENT_MANAGER (manager));
467
468   priv = manager->priv;
469
470   /* if a filename is already set and filename is not NULL, then copy
471    * it and reset the monitor; otherwise, if it's NULL we're being
472    * called from the finalization sequence, so we simply disconnect the
473    * monitoring and return.
474    *
475    * if no filename is set and filename is NULL, use the default.
476    */
477   if (priv->filename)
478     {
479       g_free (priv->filename);
480
481       if (priv->monitor)
482         {
483           g_signal_handlers_disconnect_by_func (priv->monitor,
484                                                 G_CALLBACK (gtk_recent_manager_monitor_changed),
485                                                 manager);
486           g_object_unref (priv->monitor);
487           priv->monitor = NULL;
488         }
489
490       if (!filename || *filename == '\0')
491         return;
492       else
493         priv->filename = g_strdup (filename);
494     }
495   else
496     {
497       if (!filename || *filename == '\0')
498         priv->filename = g_build_filename (g_get_home_dir (),
499                                            GTK_RECENTLY_USED_FILE,
500                                            NULL);
501       else
502         priv->filename = g_strdup (filename);
503     }
504
505   g_assert (priv->filename != NULL);
506   file = g_file_new_for_path (priv->filename);
507
508   error = NULL;
509   priv->monitor = g_file_monitor_file (file, G_FILE_MONITOR_NONE, NULL, &error);
510   if (error)
511     {
512       filename_warning ("Unable to monitor `%s': %s\n"
513                         "The GtkRecentManager will not update its contents "
514                         "if the file is changed from other instances",
515                         priv->filename,
516                         error->message);
517       g_error_free (error);
518     }
519   else
520     g_signal_connect (priv->monitor, "changed",
521                       G_CALLBACK (gtk_recent_manager_monitor_changed),
522                       manager);
523
524   g_object_unref (file);
525
526   priv->is_dirty = FALSE;
527   build_recent_items_list (manager);
528 }
529
530 /* reads the recently used resources file and builds the items list.
531  * we keep the items list inside the parser object, and build the
532  * RecentInfo object only on user's demand to avoid useless replication.
533  * this function resets the dirty bit of the manager.
534  */
535 static void
536 build_recent_items_list (GtkRecentManager *manager)
537 {
538   GtkRecentManagerPrivate *priv = manager->priv;
539   GError *read_error;
540   gint size;
541
542   g_assert (priv->filename != NULL);
543   
544   if (!priv->recent_items)
545     {
546       priv->recent_items = g_bookmark_file_new ();
547       priv->size = 0;
548     }
549
550   /* the file exists, and it's valid (we hope); if not, destroy the container
551    * object and hope for a better result when the next "changed" signal is
552    * fired. */
553   read_error = NULL;
554   g_bookmark_file_load_from_file (priv->recent_items, priv->filename, &read_error);
555   if (read_error)
556     {
557       /* if the file does not exist we just wait for the first write
558        * operation on this recent manager instance, to avoid creating
559        * empty files and leading to spurious file system events (Sabayon
560        * will not be happy about those)
561        */
562       if (read_error->domain == G_FILE_ERROR &&
563           read_error->code != G_FILE_ERROR_NOENT)
564         filename_warning ("Attempting to read the recently used resources "
565                           "file at `%s', but the parser failed: %s.",
566                           priv->filename,
567                           read_error->message);
568
569       g_bookmark_file_free (priv->recent_items);
570       priv->recent_items = NULL;
571
572       g_error_free (read_error);
573     }
574   else
575     {
576       size = g_bookmark_file_get_size (priv->recent_items);
577       if (priv->size != size)
578         {
579           priv->size = size;
580
581           g_object_notify (G_OBJECT (manager), "size");
582         }
583     }
584
585   priv->is_dirty = FALSE;
586 }
587
588
589 /********************
590  * GtkRecentManager *
591  ********************/
592
593
594 /**
595  * gtk_recent_manager_new:
596  * 
597  * Creates a new recent manager object.  Recent manager objects are used to
598  * handle the list of recently used resources.  A #GtkRecentManager object
599  * monitors the recently used resources list, and emits the "changed" signal
600  * each time something inside the list changes.
601  *
602  * #GtkRecentManager objects are expensive: be sure to create them only when
603  * needed. You should use gtk_recent_manager_get_default() instead.
604  *
605  * Return value: A newly created #GtkRecentManager object.
606  *
607  * Since: 2.10
608  */
609 GtkRecentManager *
610 gtk_recent_manager_new (void)
611 {
612   return g_object_new (GTK_TYPE_RECENT_MANAGER, NULL);
613 }
614
615 /**
616  * gtk_recent_manager_get_default:
617  *
618  * Gets a unique instance of #GtkRecentManager, that you can share
619  * in your application without caring about memory management. The
620  * returned instance will be freed when you application terminates.
621  *
622  * Return value: A unique #GtkRecentManager. Do not ref or unref it.
623  *
624  * Since: 2.10
625  */
626 GtkRecentManager *
627 gtk_recent_manager_get_default (void)
628 {
629   if (G_UNLIKELY (!recent_manager_singleton))
630     recent_manager_singleton = gtk_recent_manager_new ();
631
632   return recent_manager_singleton;
633 }
634
635 /**
636  * gtk_recent_manager_get_for_screen:
637  * @screen: a #GdkScreen
638  *
639  * Gets the recent manager object associated with @screen; if this
640  * function has not previously been called for the given screen,
641  * a new recent manager object will be created and associated with
642  * the screen. Recent manager objects are fairly expensive to create,
643  * so using this function is usually a better choice than calling 
644  * gtk_recent_manager_new() and setting the screen yourself; by using
645  * this function a single recent manager object will be shared between
646  * users.
647  *
648  * Return value: A unique #GtkRecentManager associated with the given
649  *   screen. This recent manager is associated to the with the screen
650  *   and can be used as long as the screen is open. Do not ref or
651  *   unref it.
652  *
653  * Deprecated: 2.12: This function has been deprecated and should
654  *   not be used in newly written code. Calling this function is
655  *   equivalent to calling gtk_recent_manager_get_default().
656  *
657  * Since: 2.10
658  */
659 GtkRecentManager *
660 gtk_recent_manager_get_for_screen (GdkScreen *screen)
661 {
662   return gtk_recent_manager_get_default ();
663 }
664
665 /**
666  * gtk_recent_manager_set_screen:
667  * @manager: a #GtkRecentManager
668  * @screen: a #GdkScreen
669  *
670  * Sets the screen for a recent manager; the screen is used to
671  * track the user's currently configured recently used documents
672  * storage.
673  * 
674  * Since: 2.10
675  *
676  * Deprecated: 2.12: This function has been deprecated and should
677  *   not be used in newly written code. Calling this function has
678  *   no effect.
679  */
680 void
681 gtk_recent_manager_set_screen (GtkRecentManager *manager,
682                                GdkScreen        *screen)
683 {
684
685 }
686
687 /**
688  * gtk_recent_manager_set_limit:
689  * @manager: a #GtkRecentManager
690  * @limit: the maximum number of items to return, or -1.
691  *
692  * Sets the maximum number of item that the gtk_recent_manager_get_items()
693  * function should return.  If @limit is set to -1, then return all the
694  * items.
695  *
696  * Since: 2.10
697  */
698 void
699 gtk_recent_manager_set_limit (GtkRecentManager *manager,
700                               gint              limit)
701 {
702   GtkRecentManagerPrivate *priv;
703   
704   g_return_if_fail (GTK_IS_RECENT_MANAGER (manager));
705   
706   priv = manager->priv;
707   priv->limit = limit;
708 }
709
710 /**
711  * gtk_recent_manager_get_limit:
712  * @manager: a #GtkRecentManager
713  *
714  * Gets the maximum number of items that the gtk_recent_manager_get_items()
715  * function should return.
716  *
717  * Return value: the number of items to return, or -1 for every item.
718  *
719  * Since: 2.10
720  */
721 gint
722 gtk_recent_manager_get_limit (GtkRecentManager *manager)
723 {
724   GtkRecentManagerPrivate *priv;
725   
726   g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), DEFAULT_LIMIT);
727   
728   priv = manager->priv;
729   return priv->limit;
730 }
731
732 static void
733 gtk_recent_manager_add_item_query_info (GObject      *source_object,
734                                         GAsyncResult *res,
735                                         gpointer      user_data)
736 {
737   GFile *file = G_FILE (source_object);
738   GtkRecentManager *manager = user_data;
739   GtkRecentData recent_data;
740   GFileInfo *file_info;
741   gchar *uri;
742   GError *error;
743
744   uri = g_file_get_uri (file);
745
746   error = NULL;
747   file_info = g_file_query_info_finish (file, res, &error);
748   if (error)
749     {
750       g_warning ("Unable to retrieve the file info for `%s': %s",
751                  uri,
752                  error->message);
753       g_error_free (error);
754       goto out;
755     }
756
757   recent_data.display_name = NULL;
758   recent_data.description = NULL;
759
760   if (file_info)
761     {
762       gchar *content_type;
763
764       content_type = g_file_info_get_attribute_as_string (file_info, G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE);
765
766       if (G_LIKELY (content_type))
767         recent_data.mime_type = g_content_type_get_mime_type (content_type);
768       else
769         recent_data.mime_type = g_strdup (GTK_RECENT_DEFAULT_MIME);
770
771       g_free (content_type);
772       g_object_unref (file_info);
773     }
774   else
775     recent_data.mime_type = g_strdup (GTK_RECENT_DEFAULT_MIME);
776
777   recent_data.app_name = g_strdup (g_get_application_name ());
778   recent_data.app_exec = g_strjoin (" ", g_get_prgname (), "%u", NULL);
779   recent_data.groups = NULL;
780   recent_data.is_private = FALSE;
781
782   /* Ignore return value, this can't fail anyway since all required
783    * fields are set */
784   gtk_recent_manager_add_full (manager, uri, &recent_data);
785
786   manager->priv->is_dirty = TRUE;
787   gtk_recent_manager_changed (manager);
788
789   g_free (recent_data.mime_type);
790   g_free (recent_data.app_name);
791   g_free (recent_data.app_exec);
792
793 out:
794   g_object_unref (manager);
795   g_free (uri);
796 }
797
798 /**
799  * gtk_recent_manager_add_item:
800  * @manager: a #GtkRecentManager
801  * @uri: a valid URI
802  *
803  * Adds a new resource, pointed by @uri, into the recently used
804  * resources list.
805  *
806  * This function automatically retrieves some of the needed
807  * metadata and setting other metadata to common default values; it
808  * then feeds the data to gtk_recent_manager_add_full().
809  * 
810  * See gtk_recent_manager_add_full() if you want to explicitly
811  * define the metadata for the resource pointed by @uri.
812  *
813  * Return value: %TRUE if the new item was successfully added
814  *   to the recently used resources list
815  *
816  * Since: 2.10
817  */
818 gboolean
819 gtk_recent_manager_add_item (GtkRecentManager  *manager,
820                              const gchar       *uri)
821 {
822   GFile* file;
823   
824   g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), FALSE);
825   g_return_val_if_fail (uri != NULL, FALSE);
826
827   file = g_file_new_for_uri (uri);
828
829   g_file_query_info_async (file,
830                            G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE,
831                            G_PRIORITY_DEFAULT,
832                            G_FILE_QUERY_INFO_NONE,
833                            NULL,
834                            gtk_recent_manager_add_item_query_info,
835                            g_object_ref (manager));
836
837   g_object_unref (file);
838
839   return TRUE;
840 }
841
842 /**
843  * gtk_recent_manager_add_full:
844  * @manager: a #GtkRecentManager
845  * @uri: a valid URI
846  * @recent_data: metadata of the resource
847  *
848  * Adds a new resource, pointed by @uri, into the recently used
849  * resources list, using the metadata specified inside the #GtkRecentData
850  * structure passed in @recent_data.
851  *
852  * The passed URI will be used to identify this resource inside the
853  * list.
854  *
855  * In order to register the new recently used resource, metadata about
856  * the resource must be passed as well as the URI; the metadata is
857  * stored in a #GtkRecentData structure, which must contain the MIME
858  * type of the resource pointed by the URI; the name of the application
859  * that is registering the item, and a command line to be used when
860  * launching the item.
861  *
862  * Optionally, a #GtkRecentData structure might contain a UTF-8 string
863  * to be used when viewing the item instead of the last component of the
864  * URI; a short description of the item; whether the item should be
865  * considered private - that is, should be displayed only by the
866  * applications that have registered it.
867  *
868  * Return value: %TRUE if the new item was successfully added to the
869  * recently used resources list, %FALSE otherwise.
870  *
871  * Since: 2.10
872  */
873 gboolean
874 gtk_recent_manager_add_full (GtkRecentManager     *manager,
875                              const gchar          *uri,
876                              const GtkRecentData  *data)
877 {
878   GtkRecentManagerPrivate *priv;
879   
880   g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), FALSE);
881   g_return_val_if_fail (uri != NULL, FALSE);
882   g_return_val_if_fail (data != NULL, FALSE);
883
884   /* sanity checks */
885   if ((data->display_name) &&
886       (!g_utf8_validate (data->display_name, -1, NULL)))
887     {
888       g_warning ("Attempting to add `%s' to the list of recently used "
889                  "resources, but the display name is not a valid UTF-8 "
890                  "encoded string",
891                  uri);
892       return FALSE;
893     }
894   
895   if ((data->description) &&
896       (!g_utf8_validate (data->description, -1, NULL)))
897     {
898       g_warning ("Attempting to add `%s' to the list of recently used "
899                  "resources, but the description is not a valid UTF-8 "
900                  "encoded string",
901                  uri);
902       return FALSE;
903     }
904
905  
906   if (!data->mime_type)
907     {
908       g_warning ("Attempting to add `%s' to the list of recently used "
909                  "resources, but not MIME type was defined",
910                  uri);
911       return FALSE;
912     }
913   
914   if (!data->app_name)
915     {
916       g_warning ("Attempting to add `%s' to the list of recently used "
917                  "resources, but no name of the application that is "
918                  "registering it was defined",
919                  uri);
920       return FALSE;
921     }
922   
923   if (!data->app_exec)
924     {
925       g_warning ("Attempting to add `%s' to the list of recently used "
926                  "resources, but no command line for the application "
927                  "that is registering it was defined",
928                  uri);
929       return FALSE;
930     }
931   
932   priv = manager->priv;
933
934   if (!priv->recent_items)
935     {
936       priv->recent_items = g_bookmark_file_new ();
937       priv->size = 0;
938     }
939
940   if (data->display_name)  
941     g_bookmark_file_set_title (priv->recent_items, uri, data->display_name);
942   
943   if (data->description)
944     g_bookmark_file_set_description (priv->recent_items, uri, data->description);
945
946   g_bookmark_file_set_mime_type (priv->recent_items, uri, data->mime_type);
947   
948   if (data->groups && data->groups[0] != '\0')
949     {
950       gint j;
951       
952       for (j = 0; (data->groups)[j] != NULL; j++)
953         g_bookmark_file_add_group (priv->recent_items, uri, (data->groups)[j]);
954     }
955   
956   /* register the application; this will take care of updating the
957    * registration count and time in case the application has
958    * already registered the same document inside the list
959    */
960   g_bookmark_file_add_application (priv->recent_items, uri,
961                                    data->app_name,
962                                    data->app_exec);
963   
964   g_bookmark_file_set_is_private (priv->recent_items, uri,
965                                   data->is_private);
966   
967   /* mark us as dirty, so that when emitting the "changed" signal we
968    * will dump our changes
969    */
970   priv->is_dirty = TRUE;
971   
972   gtk_recent_manager_changed (manager);
973   
974   return TRUE;
975 }
976
977 /**
978  * gtk_recent_manager_remove_item:
979  * @manager: a #GtkRecentManager
980  * @uri: the URI of the item you wish to remove
981  * @error: return location for a #GError, or %NULL
982  *
983  * Removes a resource pointed by @uri from the recently used resources
984  * list handled by a recent manager.
985  *
986  * Return value: %TRUE if the item pointed by @uri has been successfully
987  *   removed by the recently used resources list, and %FALSE otherwise.
988  *
989  * Since: 2.10
990  */
991 gboolean
992 gtk_recent_manager_remove_item (GtkRecentManager  *manager,
993                                 const gchar       *uri,
994                                 GError           **error)
995 {
996   GtkRecentManagerPrivate *priv;
997   GError *remove_error = NULL;
998
999   g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), FALSE);
1000   g_return_val_if_fail (uri != NULL, FALSE);
1001   g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
1002   
1003   priv = manager->priv;
1004   
1005   if (!priv->recent_items)
1006     {
1007       priv->recent_items = g_bookmark_file_new ();
1008       priv->size = 0;
1009
1010       g_set_error (error, GTK_RECENT_MANAGER_ERROR,
1011                    GTK_RECENT_MANAGER_ERROR_NOT_FOUND,
1012                    _("Unable to find an item with URI '%s'"),
1013                    uri);
1014
1015       return FALSE;
1016     }
1017
1018   g_bookmark_file_remove_item (priv->recent_items, uri, &remove_error);
1019   if (remove_error)
1020     {
1021       g_propagate_error (error, remove_error);
1022       
1023       return FALSE;
1024     }
1025
1026   priv->is_dirty = TRUE;
1027
1028   gtk_recent_manager_changed (manager);
1029   
1030   return TRUE;
1031 }
1032
1033 /**
1034  * gtk_recent_manager_has_item:
1035  * @manager: a #GtkRecentManager
1036  * @uri: a URI
1037  *
1038  * Checks whether there is a recently used resource registered
1039  * with @uri inside the recent manager.
1040  *
1041  * Return value: %TRUE if the resource was found, %FALSE otherwise.
1042  *
1043  * Since: 2.10
1044  */
1045 gboolean
1046 gtk_recent_manager_has_item (GtkRecentManager *manager,
1047                              const gchar      *uri)
1048 {
1049   GtkRecentManagerPrivate *priv;
1050
1051   g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), FALSE);
1052   g_return_val_if_fail (uri != NULL, FALSE);
1053
1054   priv = manager->priv;
1055   g_return_val_if_fail (priv->recent_items != NULL, FALSE);
1056
1057   return g_bookmark_file_has_item (priv->recent_items, uri);
1058 }
1059
1060 static void
1061 build_recent_info (GBookmarkFile  *bookmarks,
1062                    GtkRecentInfo  *info)
1063 {
1064   gchar **apps, **groups;
1065   gsize apps_len, groups_len, i;
1066
1067   g_assert (bookmarks != NULL);
1068   g_assert (info != NULL);
1069   
1070   info->display_name = g_bookmark_file_get_title (bookmarks, info->uri, NULL);
1071   info->description = g_bookmark_file_get_description (bookmarks, info->uri, NULL);
1072   info->mime_type = g_bookmark_file_get_mime_type (bookmarks, info->uri, NULL);
1073     
1074   info->is_private = g_bookmark_file_get_is_private (bookmarks, info->uri, NULL);
1075   
1076   info->added = g_bookmark_file_get_added (bookmarks, info->uri, NULL);
1077   info->modified = g_bookmark_file_get_modified (bookmarks, info->uri, NULL);
1078   info->visited = g_bookmark_file_get_visited (bookmarks, info->uri, NULL);
1079   
1080   groups = g_bookmark_file_get_groups (bookmarks, info->uri, &groups_len, NULL);
1081   for (i = 0; i < groups_len; i++)
1082     {
1083       gchar *group_name = g_strdup (groups[i]);
1084       
1085       info->groups = g_slist_append (info->groups, group_name);
1086     }
1087
1088   g_strfreev (groups);
1089   
1090   apps = g_bookmark_file_get_applications (bookmarks, info->uri, &apps_len, NULL);
1091   for (i = 0; i < apps_len; i++)
1092     {
1093       gchar *app_name, *app_exec;
1094       guint count;
1095       time_t stamp;
1096       RecentAppInfo *app_info;
1097       gboolean res;
1098       
1099       app_name = apps[i];
1100       
1101       res = g_bookmark_file_get_app_info (bookmarks, info->uri, app_name,
1102                                           &app_exec,
1103                                           &count,
1104                                           &stamp,
1105                                           NULL);
1106       if (!res)
1107         continue;
1108       
1109       app_info = recent_app_info_new (app_name);
1110       app_info->exec = app_exec;
1111       app_info->count = count;
1112       app_info->stamp = stamp;
1113       
1114       info->applications = g_slist_prepend (info->applications, app_info);
1115       g_hash_table_replace (info->apps_lookup, app_info->name, app_info);
1116     }
1117   
1118   g_strfreev (apps);
1119 }
1120
1121 /**
1122  * gtk_recent_manager_lookup_item:
1123  * @manager: a #GtkRecentManager
1124  * @uri: a URI
1125  * @error: a return location for a #GError, or %NULL
1126  *
1127  * Searches for a URI inside the recently used resources list, and
1128  * returns a structure containing informations about the resource
1129  * like its MIME type, or its display name.
1130  *
1131  * Return value: a #GtkRecentInfo structure containing information
1132  *   about the resource pointed by @uri, or %NULL if the URI was
1133  *   not registered in the recently used resources list.  Free with
1134  *   gtk_recent_info_unref().
1135  *
1136  * Since: 2.10
1137  */
1138 GtkRecentInfo *
1139 gtk_recent_manager_lookup_item (GtkRecentManager  *manager,
1140                                 const gchar       *uri,
1141                                 GError           **error)
1142 {
1143   GtkRecentManagerPrivate *priv;
1144   GtkRecentInfo *info = NULL;
1145   
1146   g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), NULL);
1147   g_return_val_if_fail (uri != NULL, NULL);
1148   g_return_val_if_fail (error == NULL || *error == NULL, NULL);
1149   
1150   priv = manager->priv;
1151   if (!priv->recent_items)
1152     {
1153       priv->recent_items = g_bookmark_file_new ();
1154       priv->size = 0;
1155
1156       g_set_error (error, GTK_RECENT_MANAGER_ERROR,
1157                    GTK_RECENT_MANAGER_ERROR_NOT_FOUND,
1158                    _("Unable to find an item with URI '%s'"),
1159                    uri);
1160
1161       return NULL;
1162     }
1163   
1164   if (!g_bookmark_file_has_item (priv->recent_items, uri))
1165     {
1166       g_set_error (error, GTK_RECENT_MANAGER_ERROR,
1167                    GTK_RECENT_MANAGER_ERROR_NOT_FOUND,
1168                    _("Unable to find an item with URI '%s'"),
1169                    uri);
1170       return NULL;
1171     }
1172   
1173   info = gtk_recent_info_new (uri);
1174   g_return_val_if_fail (info != NULL, NULL);
1175   
1176   /* fill the RecentInfo structure with the data retrieved by our
1177    * parser object from the storage file 
1178    */
1179   build_recent_info (priv->recent_items, info);
1180
1181   return info;
1182 }
1183
1184 /**
1185  * gtk_recent_manager_move_item:
1186  * @manager: a #GtkRecentManager
1187  * @uri: the URI of a recently used resource
1188  * @new_uri: the new URI of the recently used resource, or %NULL to
1189  *    remove the item pointed by @uri in the list
1190  * @error: a return location for a #GError, or %NULL
1191  *
1192  * Changes the location of a recently used resource from @uri to @new_uri.
1193  * 
1194  * Please note that this function will not affect the resource pointed
1195  * by the URIs, but only the URI used in the recently used resources list.
1196  *
1197  * Return value: %TRUE on success.
1198  *
1199  * Since: 2.10
1200  */ 
1201 gboolean
1202 gtk_recent_manager_move_item (GtkRecentManager  *recent_manager,
1203                               const gchar       *uri,
1204                               const gchar       *new_uri,
1205                               GError           **error)
1206 {
1207   GtkRecentManagerPrivate *priv;
1208   GError *move_error;
1209   gboolean res;
1210   
1211   g_return_val_if_fail (GTK_IS_RECENT_MANAGER (recent_manager), FALSE);
1212   g_return_val_if_fail (uri != NULL, FALSE);
1213   g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
1214   
1215   priv = recent_manager->priv;
1216
1217   if (!g_bookmark_file_has_item (priv->recent_items, uri))
1218     {
1219       g_set_error (error, GTK_RECENT_MANAGER_ERROR,
1220                    GTK_RECENT_MANAGER_ERROR_NOT_FOUND,
1221                    _("Unable to find an item with URI '%s'"),
1222                    uri);
1223       return FALSE;
1224     }
1225   
1226   move_error = NULL;
1227   res = g_bookmark_file_move_item (priv->recent_items,
1228                                    uri, new_uri,
1229                                    &move_error);
1230   if (move_error)
1231     {
1232       g_propagate_error (error, move_error);
1233       return FALSE;
1234     }
1235   
1236   priv->is_dirty = TRUE;
1237
1238   gtk_recent_manager_changed (recent_manager);
1239   
1240   return TRUE;
1241 }
1242
1243 /**
1244  * gtk_recent_manager_get_items:
1245  * @manager: a #GtkRecentManager
1246  *
1247  * Gets the list of recently used resources.
1248  *
1249  * Return value: a list of newly allocated #GtkRecentInfo objects. Use
1250  *   gtk_recent_info_unref() on each item inside the list, and then
1251  *   free the list itself using g_list_free().
1252  *
1253  * Since: 2.10
1254  */
1255 GList *
1256 gtk_recent_manager_get_items (GtkRecentManager *manager)
1257 {
1258   GtkRecentManagerPrivate *priv;
1259   GList *retval = NULL;
1260   gchar **uris;
1261   gsize uris_len, i;
1262   
1263   g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), NULL);
1264   
1265   priv = manager->priv;
1266   if (!priv->recent_items)
1267     return NULL;
1268
1269   if (priv->limit == 0)
1270     return NULL;
1271   
1272   uris = g_bookmark_file_get_uris (priv->recent_items, &uris_len);
1273   for (i = 0; i < uris_len; i++)
1274     {
1275       GtkRecentInfo *info;
1276       
1277       if (priv->limit != -1 && i == priv->limit)
1278         break;
1279       
1280       info = gtk_recent_info_new (uris[i]);
1281       build_recent_info (priv->recent_items, info);
1282       
1283       retval = g_list_prepend (retval, info);
1284     }
1285   
1286   g_strfreev (uris);
1287   
1288   return retval;
1289 }
1290
1291 static void
1292 purge_recent_items_list (GtkRecentManager  *manager,
1293                          GError           **error)
1294 {
1295   GtkRecentManagerPrivate *priv = manager->priv;
1296
1297   if (!priv->recent_items)
1298     return;
1299   
1300   g_bookmark_file_free (priv->recent_items);
1301   priv->recent_items = NULL;
1302       
1303   priv->recent_items = g_bookmark_file_new ();
1304   priv->size = 0;
1305   priv->is_dirty = TRUE;
1306       
1307   /* emit the changed signal, to ensure that the purge is written */
1308   gtk_recent_manager_changed (manager);
1309 }
1310
1311 /**
1312  * gtk_recent_manager_purge_items:
1313  * @manager: a #GtkRecentManager
1314  * @error: a return location for a #GError, or %NULL
1315  *
1316  * Purges every item from the recently used resources list.
1317  *
1318  * Return value: the number of items that have been removed from the
1319  *   recently used resources list.
1320  *
1321  * Since: 2.10
1322  */
1323 gint
1324 gtk_recent_manager_purge_items (GtkRecentManager  *manager,
1325                                 GError           **error)
1326 {
1327   GtkRecentManagerPrivate *priv;
1328   gint count, purged;
1329   
1330   g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), -1);
1331
1332   priv = manager->priv;
1333   if (!priv->recent_items)
1334     return 0;
1335   
1336   count = g_bookmark_file_get_size (priv->recent_items);
1337   if (!count)
1338     return 0;
1339   
1340   purge_recent_items_list (manager, error);
1341   
1342   purged = count - g_bookmark_file_get_size (priv->recent_items);
1343
1344   return purged;
1345 }
1346
1347 static void
1348 gtk_recent_manager_changed (GtkRecentManager *recent_manager)
1349 {
1350   g_signal_emit (recent_manager, signal_changed, 0);
1351 }
1352
1353 static void
1354 gtk_recent_manager_clamp_to_age (GtkRecentManager *manager,
1355                                  gint              age)
1356 {
1357   GtkRecentManagerPrivate *priv = manager->priv;
1358   gchar **uris;
1359   gsize n_uris, i;
1360   time_t now;
1361
1362   if (G_UNLIKELY (!priv->recent_items))
1363     return;
1364
1365   now = time (NULL);
1366
1367   uris = g_bookmark_file_get_uris (priv->recent_items, &n_uris);
1368
1369   for (i = 0; i < n_uris; i++)
1370     {
1371       const gchar *uri = uris[i];
1372       time_t modified;
1373       gint item_age;
1374
1375       modified = g_bookmark_file_get_modified (priv->recent_items, uri, NULL);
1376       item_age = (gint) ((now - modified) / (60 * 60 * 24));
1377       if (item_age > age)
1378         g_bookmark_file_remove_item (priv->recent_items, uri, NULL);
1379     }
1380
1381   g_strfreev (uris);
1382 }
1383
1384 /*****************
1385  * GtkRecentInfo *
1386  *****************/
1387  
1388 GType
1389 gtk_recent_info_get_type (void)
1390 {
1391   static GType info_type = 0;
1392   
1393   if (!info_type)
1394     info_type = g_boxed_type_register_static (I_("GtkRecentInfo"),
1395                                               (GBoxedCopyFunc) gtk_recent_info_ref,
1396                                               (GBoxedFreeFunc) gtk_recent_info_unref);
1397   return info_type;
1398 }
1399
1400 static GtkRecentInfo *
1401 gtk_recent_info_new (const gchar *uri)
1402 {
1403   GtkRecentInfo *info;
1404
1405   g_assert (uri != NULL);
1406
1407   info = g_new0 (GtkRecentInfo, 1);
1408   info->uri = g_strdup (uri);
1409   
1410   info->applications = NULL;
1411   info->apps_lookup = g_hash_table_new (g_str_hash, g_str_equal);
1412   
1413   info->groups = NULL;
1414   
1415   info->ref_count = 1;
1416
1417   return info;
1418 }
1419
1420 static void
1421 gtk_recent_info_free (GtkRecentInfo *recent_info)
1422 {
1423   if (!recent_info)
1424     return;
1425
1426   g_free (recent_info->uri);
1427   g_free (recent_info->display_name);
1428   g_free (recent_info->description);
1429   g_free (recent_info->mime_type);
1430   
1431   if (recent_info->applications)
1432     {
1433       g_slist_foreach (recent_info->applications,
1434                        (GFunc) recent_app_info_free,
1435                        NULL);
1436       g_slist_free (recent_info->applications);
1437       
1438       recent_info->applications = NULL;
1439     }
1440   
1441   if (recent_info->apps_lookup)
1442     g_hash_table_destroy (recent_info->apps_lookup);
1443
1444   if (recent_info->groups)
1445     {
1446       g_slist_foreach (recent_info->groups,
1447                        (GFunc) g_free,
1448                        NULL);
1449       g_slist_free (recent_info->groups);
1450
1451       recent_info->groups = NULL;
1452     }
1453   
1454   if (recent_info->icon)
1455     g_object_unref (recent_info->icon);
1456
1457   g_free (recent_info);
1458 }
1459
1460 /**
1461  * gtk_recent_info_ref:
1462  * @info: a #GtkRecentInfo
1463  *
1464  * Increases the reference count of @recent_info by one.
1465  *
1466  * Return value: the recent info object with its reference count increased
1467  *   by one.
1468  *
1469  * Since: 2.10
1470  */
1471 GtkRecentInfo *
1472 gtk_recent_info_ref (GtkRecentInfo *info)
1473 {
1474   g_return_val_if_fail (info != NULL, NULL);
1475   g_return_val_if_fail (info->ref_count > 0, NULL);
1476   
1477   info->ref_count += 1;
1478     
1479   return info;
1480 }
1481
1482 /**
1483  * gtk_recent_info_unref:
1484  * @info: a #GtkRecentInfo
1485  *
1486  * Decreases the reference count of @info by one.  If the reference
1487  * count reaches zero, @info is deallocated, and the memory freed.
1488  *
1489  * Since: 2.10
1490  */
1491 void
1492 gtk_recent_info_unref (GtkRecentInfo *info)
1493 {
1494   g_return_if_fail (info != NULL);
1495   g_return_if_fail (info->ref_count > 0);
1496
1497   info->ref_count -= 1;
1498   
1499   if (info->ref_count == 0)
1500     gtk_recent_info_free (info);
1501 }
1502
1503 /**
1504  * gtk_recent_info_get_uri:
1505  * @info: a #GtkRecentInfo
1506  *
1507  * Gets the URI of the resource.
1508  *
1509  * Return value: the URI of the resource.  The returned string is
1510  *   owned by the recent manager, and should not be freed.
1511  *
1512  * Since: 2.10
1513  */
1514 G_CONST_RETURN gchar *
1515 gtk_recent_info_get_uri (GtkRecentInfo *info)
1516 {
1517   g_return_val_if_fail (info != NULL, NULL);
1518   
1519   return info->uri;
1520 }
1521
1522 /**
1523  * gtk_recent_info_get_display_name:
1524  * @info: a #GtkRecentInfo
1525  *
1526  * Gets the name of the resource.  If none has been defined, the basename
1527  * of the resource is obtained.
1528  *
1529  * Return value: the display name of the resource.  The returned string
1530  *   is owned by the recent manager, and should not be freed.
1531  *
1532  * Since: 2.10
1533  */
1534 G_CONST_RETURN gchar *
1535 gtk_recent_info_get_display_name (GtkRecentInfo *info)
1536 {
1537   g_return_val_if_fail (info != NULL, NULL);
1538   
1539   if (!info->display_name)
1540     info->display_name = gtk_recent_info_get_short_name (info);
1541   
1542   return info->display_name;
1543 }
1544
1545 /**
1546  * gtk_recent_info_get_description:
1547  * @info: a #GtkRecentInfo
1548  *
1549  * Gets the (short) description of the resource.
1550  *
1551  * Return value: the description of the resource.  The returned string
1552  *   is owned by the recent manager, and should not be freed.
1553  *
1554  * Since: 2.10
1555  **/
1556 G_CONST_RETURN gchar *
1557 gtk_recent_info_get_description (GtkRecentInfo *info)
1558 {
1559   g_return_val_if_fail (info != NULL, NULL);
1560   
1561   return info->description;
1562 }
1563
1564 /**
1565  * gtk_recent_info_get_mime_type:
1566  * @info: a #GtkRecentInfo
1567  *
1568  * Gets the MIME type of the resource.
1569  *
1570  * Return value: the MIME type of the resource.  The returned string
1571  *   is owned by the recent manager, and should not be freed.
1572  *
1573  * Since: 2.10
1574  */
1575 G_CONST_RETURN gchar *
1576 gtk_recent_info_get_mime_type (GtkRecentInfo *info)
1577 {
1578   g_return_val_if_fail (info != NULL, NULL);
1579   
1580   if (!info->mime_type)
1581     info->mime_type = g_strdup (GTK_RECENT_DEFAULT_MIME);
1582   
1583   return info->mime_type;
1584 }
1585
1586 /**
1587  * gtk_recent_info_get_added:
1588  * @info: a #GtkRecentInfo
1589  *
1590  * Gets the timestamp (seconds from system's Epoch) when the resource
1591  * was added to the recently used resources list.
1592  *
1593  * Return value: the number of seconds elapsed from system's Epoch when
1594  *   the resource was added to the list, or -1 on failure.
1595  *
1596  * Since: 2.10
1597  */
1598 time_t
1599 gtk_recent_info_get_added (GtkRecentInfo *info)
1600 {
1601   g_return_val_if_fail (info != NULL, (time_t) -1);
1602   
1603   return info->added;
1604 }
1605
1606 /**
1607  * gtk_recent_info_get_modified:
1608  * @info: a #GtkRecentInfo
1609  *
1610  * Gets the timestamp (seconds from system's Epoch) when the resource
1611  * was last modified.
1612  *
1613  * Return value: the number of seconds elapsed from system's Epoch when
1614  *   the resource was last modified, or -1 on failure.
1615  *
1616  * Since: 2.10
1617  */
1618 time_t
1619 gtk_recent_info_get_modified (GtkRecentInfo *info)
1620 {
1621   g_return_val_if_fail (info != NULL, (time_t) -1);
1622   
1623   return info->modified;
1624 }
1625
1626 /**
1627  * gtk_recent_info_get_visited:
1628  * @info: a #GtkRecentInfo
1629  *
1630  * Gets the timestamp (seconds from system's Epoch) when the resource
1631  * was last visited.
1632  *
1633  * Return value: the number of seconds elapsed from system's Epoch when
1634  *   the resource was last visited, or -1 on failure.
1635  *
1636  * Since: 2.10
1637  */
1638 time_t
1639 gtk_recent_info_get_visited (GtkRecentInfo *info)
1640 {
1641   g_return_val_if_fail (info != NULL, (time_t) -1);
1642   
1643   return info->visited;
1644 }
1645
1646 /**
1647  * gtk_recent_info_get_private_hint:
1648  * @info: a #GtkRecentInfo
1649  *
1650  * Gets the value of the "private" flag.  Resources in the recently used
1651  * list that have this flag set to %TRUE should only be displayed by the
1652  * applications that have registered them.
1653  *
1654  * Return value: %TRUE if the private flag was found, %FALSE otherwise.
1655  *
1656  * Since: 2.10
1657  */
1658 gboolean
1659 gtk_recent_info_get_private_hint (GtkRecentInfo *info)
1660 {
1661   g_return_val_if_fail (info != NULL, FALSE);
1662   
1663   return info->is_private;
1664 }
1665
1666
1667 static RecentAppInfo *
1668 recent_app_info_new (const gchar *app_name)
1669 {
1670   RecentAppInfo *app_info;
1671
1672   g_assert (app_name != NULL);
1673   
1674   app_info = g_new0 (RecentAppInfo, 1);
1675   app_info->name = g_strdup (app_name);
1676   app_info->exec = NULL;
1677   app_info->count = 1;
1678   app_info->stamp = time (NULL);
1679   
1680   return app_info;
1681 }
1682
1683 static void
1684 recent_app_info_free (RecentAppInfo *app_info)
1685 {
1686   if (!app_info)
1687     return;
1688   
1689   g_free (app_info->name);
1690   
1691   g_free (app_info->exec);
1692   
1693   g_free (app_info);
1694 }
1695
1696 /**
1697  * gtk_recent_info_get_application_info:
1698  * @info: a #GtkRecentInfo
1699  * @app_name: the name of the application that has registered this item
1700  * @app_exec: return location for the string containing the command line
1701  * @count: return location for the number of times this item was registered
1702  * @time_: return location for the timestamp this item was last registered
1703  *    for this application
1704  *
1705  * Gets the data regarding the application that has registered the resource
1706  * pointed by @info.
1707  *
1708  * If the command line contains any escape characters defined inside the
1709  * storage specification, they will be expanded.
1710  *
1711  * Return value: %TRUE if an application with @app_name has registered this
1712  *   resource inside the recently used list, or %FALSE otherwise.  You should
1713  *   free the returned command line using g_free().
1714  *
1715  * Since: 2.10
1716  */
1717 gboolean
1718 gtk_recent_info_get_application_info (GtkRecentInfo  *info,
1719                                       const gchar    *app_name,
1720                                       gchar         **app_exec,
1721                                       guint          *count,
1722                                       time_t         *time_)
1723 {
1724   RecentAppInfo *ai;
1725   
1726   g_return_val_if_fail (info != NULL, FALSE);
1727   g_return_val_if_fail (app_name != NULL, FALSE);
1728   
1729   ai = (RecentAppInfo *) g_hash_table_lookup (info->apps_lookup,
1730                                               app_name);
1731   if (!ai)
1732     {
1733       g_warning ("No registered application with name '%s' "
1734                  "for item with URI '%s' found",
1735                  app_name,
1736                  info->uri);
1737       return FALSE;
1738     }
1739   
1740   if (app_exec)
1741     *app_exec = ai->exec;
1742   
1743   if (count)
1744     *count = ai->count;
1745   
1746   if (time_)
1747     *time_ = ai->stamp;
1748
1749   return TRUE;
1750 }
1751
1752 /**
1753  * gtk_recent_info_get_applications:
1754  * @info: a #GtkRecentInfo
1755  * @length: return location for the length of the returned list, or %NULL
1756  *
1757  * Retrieves the list of applications that have registered this resource.
1758  *
1759  * Return value: a newly allocated %NULL-terminated array of strings.
1760  *   Use g_strfreev() to free it.
1761  *
1762  * Since: 2.10
1763  */                           
1764 gchar **
1765 gtk_recent_info_get_applications (GtkRecentInfo *info,
1766                                   gsize         *length)
1767 {
1768   GSList *l;
1769   gchar **retval;
1770   gsize n_apps, i;
1771   
1772   g_return_val_if_fail (info != NULL, NULL);
1773   
1774   if (!info->applications)
1775     {
1776       if (length)
1777         *length = 0;
1778       
1779       return NULL;    
1780     }
1781   
1782   n_apps = g_slist_length (info->applications);
1783   
1784   retval = g_new0 (gchar *, n_apps + 1);
1785   
1786   for (l = info->applications, i = 0;
1787        l != NULL;
1788        l = l->next)
1789     {
1790       RecentAppInfo *ai = (RecentAppInfo *) l->data;
1791       
1792       g_assert (ai != NULL);
1793       
1794       retval[i++] = g_strdup (ai->name);
1795     }
1796   retval[i] = NULL;
1797   
1798   if (length)
1799     *length = i;
1800   
1801   return retval;
1802 }
1803
1804 /**
1805  * gtk_recent_info_has_application:
1806  * @info: a #GtkRecentInfo
1807  * @app_name: a string containing an application name
1808  *
1809  * Checks whether an application registered this resource using @app_name.
1810  *
1811  * Return value: %TRUE if an application with name @app_name was found,
1812  *   %FALSE otherwise.
1813  *
1814  * Since: 2.10
1815  */
1816 gboolean
1817 gtk_recent_info_has_application (GtkRecentInfo *info,
1818                                  const gchar   *app_name)
1819 {
1820   g_return_val_if_fail (info != NULL, FALSE);
1821   g_return_val_if_fail (app_name != NULL, FALSE);
1822   
1823   return (NULL != g_hash_table_lookup (info->apps_lookup, app_name));
1824 }
1825
1826 /**
1827  * gtk_recent_info_last_application:
1828  * @info: a #GtkRecentInfo
1829  *
1830  * Gets the name of the last application that have registered the
1831  * recently used resource represented by @info.
1832  *
1833  * Return value: an application name.  Use g_free() to free it.
1834  *
1835  * Since: 2.10
1836  */
1837 gchar *
1838 gtk_recent_info_last_application (GtkRecentInfo  *info)
1839 {
1840   GSList *l;
1841   time_t last_stamp = (time_t) -1;
1842   gchar *name = NULL;
1843   
1844   g_return_val_if_fail (info != NULL, NULL);
1845   
1846   for (l = info->applications; l != NULL; l = l->next)
1847     {
1848       RecentAppInfo *ai = (RecentAppInfo *) l->data;
1849       
1850       if (ai->stamp > last_stamp)
1851         {
1852           name = ai->name;
1853           last_stamp = ai->stamp;
1854         }
1855     }
1856   
1857   return g_strdup (name);
1858 }
1859
1860 static GdkPixbuf *
1861 get_icon_for_mime_type (const char *mime_type,
1862                         gint        pixel_size)
1863 {
1864   GtkIconTheme *icon_theme;
1865   const char *separator;
1866   GString *icon_name;
1867   GdkPixbuf *pixbuf;
1868
1869   separator = strchr (mime_type, '/');
1870   if (!separator)
1871     return NULL;
1872
1873   icon_theme = gtk_icon_theme_get_default ();
1874
1875   /* try with the three icon name variants for MIME types */
1876
1877   /* canonicalize MIME type: foo/x-bar -> foo-x-bar */
1878   icon_name = g_string_new (NULL);
1879   g_string_append_len (icon_name, mime_type, separator - mime_type);
1880   g_string_append_c (icon_name, '-');
1881   g_string_append (icon_name, separator + 1);
1882   pixbuf = gtk_icon_theme_load_icon (icon_theme, icon_name->str,
1883                                      pixel_size,
1884                                      0,
1885                                      NULL);
1886   g_string_free (icon_name, TRUE);
1887   if (pixbuf)
1888     return pixbuf;
1889
1890   /* canonicalize MIME type, and prepend "gnome-mime-" */
1891   icon_name = g_string_new ("gnome-mime-");
1892   g_string_append_len (icon_name, mime_type, separator - mime_type);
1893   g_string_append_c (icon_name, '-');
1894   g_string_append (icon_name, separator + 1);
1895   pixbuf = gtk_icon_theme_load_icon (icon_theme, icon_name->str,
1896                                      pixel_size,
1897                                      0,
1898                                      NULL);
1899   g_string_free (icon_name, TRUE);
1900   if (pixbuf)
1901     return pixbuf;
1902
1903   /* try the MIME family icon */
1904   icon_name = g_string_new ("gnome-mime-");
1905   g_string_append_len (icon_name, mime_type, separator - mime_type);
1906   pixbuf = gtk_icon_theme_load_icon (icon_theme, icon_name->str,
1907                                      pixel_size,
1908                                      0,
1909                                      NULL);
1910   g_string_free (icon_name, TRUE);
1911
1912   return pixbuf;
1913 }
1914
1915 static GdkPixbuf *
1916 get_icon_fallback (const gchar *icon_name,
1917                    gint         size)
1918 {
1919   GtkIconTheme *icon_theme;
1920   GdkPixbuf *retval;
1921
1922   icon_theme = gtk_icon_theme_get_default ();
1923   
1924   retval = gtk_icon_theme_load_icon (icon_theme, icon_name,
1925                                      size,
1926                                      GTK_ICON_LOOKUP_USE_BUILTIN,
1927                                      NULL);
1928   g_assert (retval != NULL);
1929   
1930   return retval; 
1931 }
1932
1933 /**
1934  * gtk_recent_info_get_icon:
1935  * @info: a #GtkRecentInfo
1936  * @size: the size of the icon in pixels
1937  *
1938  * Retrieves the icon of size @size associated to the resource MIME type.
1939  *
1940  * Return value: a #GdkPixbuf containing the icon, or %NULL. Use
1941  *   g_object_unref() when finished using the icon.
1942  *
1943  * Since: 2.10
1944  */
1945 GdkPixbuf *
1946 gtk_recent_info_get_icon (GtkRecentInfo *info,
1947                           gint           size)
1948 {
1949   GdkPixbuf *retval = NULL;
1950   
1951   g_return_val_if_fail (info != NULL, NULL);
1952   
1953   if (info->mime_type)
1954     retval = get_icon_for_mime_type (info->mime_type, size);
1955
1956   /* this function should never fail */  
1957   if (!retval)
1958     {
1959       if (info->mime_type &&
1960           strcmp (info->mime_type, "x-directory/normal") == 0)
1961         retval = get_icon_fallback (GTK_STOCK_DIRECTORY, size);
1962       else
1963         retval = get_icon_fallback (GTK_STOCK_FILE, size);
1964     }
1965   
1966   return retval;
1967 }
1968
1969 /**
1970  * gtk_recent_info_is_local:
1971  * @info: a #GtkRecentInfo
1972  *
1973  * Checks whether the resource is local or not by looking at the
1974  * scheme of its URI.
1975  *
1976  * Return value: %TRUE if the resource is local.
1977  *
1978  * Since: 2.10
1979  */
1980 gboolean
1981 gtk_recent_info_is_local (GtkRecentInfo *info)
1982 {
1983   g_return_val_if_fail (info != NULL, FALSE);
1984   
1985   return has_case_prefix (info->uri, "file:/");
1986 }
1987
1988 /**
1989  * gtk_recent_info_exists:
1990  * @info: a #GtkRecentInfo
1991  *
1992  * Checks whether the resource pointed by @info still exists.  At
1993  * the moment this check is done only on resources pointing to local files.
1994  *
1995  * Return value: %TRUE if the resource exists
1996  *
1997  * Since: 2.10
1998  */
1999 gboolean
2000 gtk_recent_info_exists (GtkRecentInfo *info)
2001 {
2002   gchar *filename;
2003   struct stat stat_buf;
2004   gboolean retval = FALSE;
2005   
2006   g_return_val_if_fail (info != NULL, FALSE);
2007   
2008   /* we guarantee only local resources */
2009   if (!gtk_recent_info_is_local (info))
2010     return FALSE;
2011   
2012   filename = g_filename_from_uri (info->uri, NULL, NULL);
2013   if (filename)
2014     {
2015       if (stat (filename, &stat_buf) == 0)
2016         retval = TRUE;
2017      
2018       g_free (filename);
2019     }
2020   
2021   return retval;
2022 }
2023
2024 /**
2025  * gtk_recent_info_match:
2026  * @info_a: a #GtkRecentInfo
2027  * @info_b: a #GtkRecentInfo
2028  *
2029  * Checks whether two #GtkRecentInfo structures point to the same
2030  * resource.
2031  *
2032  * Return value: %TRUE if both #GtkRecentInfo structures point to se same
2033  *   resource, %FALSE otherwise.
2034  *
2035  * Since: 2.10
2036  */
2037 gboolean
2038 gtk_recent_info_match (GtkRecentInfo *info_a,
2039                        GtkRecentInfo *info_b)
2040 {
2041   g_return_val_if_fail (info_a != NULL, FALSE);
2042   g_return_val_if_fail (info_b != NULL, FALSE);
2043   
2044   return (0 == strcmp (info_a->uri, info_b->uri));
2045 }
2046
2047 /* taken from gnome-vfs-uri.c */
2048 static const gchar *
2049 get_method_string (const gchar  *substring, 
2050                    gchar       **method_string)
2051 {
2052   const gchar *p;
2053   char *method;
2054         
2055   for (p = substring;
2056        g_ascii_isalnum (*p) || *p == '+' || *p == '-' || *p == '.';
2057        p++)
2058     ;
2059
2060   if (*p == ':'
2061 #ifdef G_OS_WIN32
2062                 &&
2063       !(p == substring + 1 && g_ascii_isalpha (*substring))
2064 #endif
2065                                                            )
2066     {
2067       /* Found toplevel method specification.  */
2068       method = g_strndup (substring, p - substring);
2069       *method_string = g_ascii_strdown (method, -1);
2070       g_free (method);
2071       p++;
2072     }
2073   else
2074     {
2075       *method_string = g_strdup ("file");
2076       p = substring;
2077     }
2078   
2079   return p;
2080 }
2081
2082 /* Stolen from gnome_vfs_make_valid_utf8() */
2083 static char *
2084 make_valid_utf8 (const char *name)
2085 {
2086   GString *string;
2087   const char *remainder, *invalid;
2088   int remaining_bytes, valid_bytes;
2089
2090   string = NULL;
2091   remainder = name;
2092   remaining_bytes = name ? strlen (name) : 0;
2093
2094   while (remaining_bytes != 0)
2095     {
2096       if (g_utf8_validate (remainder, remaining_bytes, &invalid))
2097         break;
2098       
2099       valid_bytes = invalid - remainder;
2100       
2101       if (string == NULL)
2102         string = g_string_sized_new (remaining_bytes);
2103       
2104       g_string_append_len (string, remainder, valid_bytes);
2105       g_string_append_c (string, '?');
2106       
2107       remaining_bytes -= valid_bytes + 1;
2108       remainder = invalid + 1;
2109     }
2110   
2111   if (string == NULL)
2112     return g_strdup (name);
2113
2114   g_string_append (string, remainder);
2115   g_assert (g_utf8_validate (string->str, -1, NULL));
2116
2117   return g_string_free (string, FALSE);
2118 }
2119
2120 static gchar *
2121 get_uri_shortname_for_display (const gchar *uri)
2122 {
2123   gchar *name = NULL;
2124   gboolean validated = FALSE;
2125
2126   if (has_case_prefix (uri, "file:/"))
2127     {
2128       gchar *local_file;
2129       
2130       local_file = g_filename_from_uri (uri, NULL, NULL);
2131       
2132       if (local_file)
2133         {
2134           name = g_filename_display_basename (local_file);
2135           validated = TRUE;
2136         }
2137                 
2138       g_free (local_file);
2139     } 
2140   
2141   if (!name)
2142     {
2143       gchar *method;
2144       gchar *local_file;
2145       const gchar *rest;
2146       
2147       rest = get_method_string (uri, &method);
2148       local_file = g_filename_display_basename (rest);
2149       
2150       name = g_strconcat (method, ": ", local_file, NULL);
2151       
2152       g_free (local_file);
2153       g_free (method);
2154     }
2155   
2156   g_assert (name != NULL);
2157   
2158   if (!validated && !g_utf8_validate (name, -1, NULL))
2159     {
2160       gchar *utf8_name;
2161       
2162       utf8_name = make_valid_utf8 (name);
2163       g_free (name);
2164       
2165       name = utf8_name;
2166     }
2167
2168   return name;
2169 }
2170
2171 /**
2172  * gtk_recent_info_get_short_name:
2173  * @info: an #GtkRecentInfo
2174  *
2175  * Computes a valid UTF-8 string that can be used as the name of the item in a
2176  * menu or list.  For example, calling this function on an item that refers to
2177  * "file:///foo/bar.txt" will yield "bar.txt".
2178  *
2179  * Return value: A newly-allocated string in UTF-8 encoding; free it with
2180  *   g_free().
2181  *
2182  * Since: 2.10
2183  */
2184 gchar *
2185 gtk_recent_info_get_short_name (GtkRecentInfo *info)
2186 {
2187   gchar *short_name;
2188
2189   g_return_val_if_fail (info != NULL, NULL);
2190
2191   if (info->uri == NULL)
2192     return NULL;
2193
2194   short_name = get_uri_shortname_for_display (info->uri);
2195
2196   return short_name;
2197 }
2198
2199 /**
2200  * gtk_recent_info_get_uri_display:
2201  * @info: a #GtkRecentInfo
2202  *
2203  * Gets a displayable version of the resource's URI.  If the resource
2204  * is local, it returns a local path; if the resource is not local,
2205  * it returns the UTF-8 encoded content of gtk_recent_info_get_uri().
2206  *
2207  * Return value: a newly allocated UTF-8 string containing the
2208  *   resource's URI or %NULL. Use g_free() when done using it.
2209  *
2210  * Since: 2.10
2211  */
2212 gchar *
2213 gtk_recent_info_get_uri_display (GtkRecentInfo *info)
2214 {
2215   gchar *retval;
2216   
2217   g_return_val_if_fail (info != NULL, NULL);
2218
2219   retval = NULL;
2220   if (gtk_recent_info_is_local (info))
2221     {
2222       gchar *filename;
2223
2224       filename = g_filename_from_uri (info->uri, NULL, NULL);
2225       if (!filename)
2226         return NULL;
2227       
2228       retval = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
2229       g_free (filename);
2230     }
2231   else
2232     {
2233       retval = make_valid_utf8 (info->uri);
2234     }
2235
2236   return retval;
2237 }
2238
2239 /**
2240  * gtk_recent_info_get_age:
2241  * @info: a #GtkRecentInfo
2242  *
2243  * Gets the number of days elapsed since the last update of the resource
2244  * pointed by @info.
2245  *
2246  * Return value: a positive integer containing the number of days elapsed
2247  *   since the time this resource was last modified.  
2248  *
2249  * Since: 2.10
2250  */
2251 gint
2252 gtk_recent_info_get_age (GtkRecentInfo *info)
2253 {
2254   time_t now, delta;
2255   gint retval;
2256
2257   g_return_val_if_fail (info != NULL, -1);
2258
2259   now = time (NULL);
2260   
2261   delta = now - info->modified;
2262   
2263   retval = (gint) (delta / (60 * 60 * 24));
2264   
2265   return retval;
2266 }
2267
2268 /**
2269  * gtk_recent_info_get_groups:
2270  * @info: a #GtkRecentInfo
2271  * @length: return location for the number of groups returned, or %NULL
2272  *
2273  * Returns all groups registered for the recently used item @info.  The
2274  * array of returned group names will be %NULL terminated, so length might
2275  * optionally be %NULL.
2276  *
2277  * Return value: a newly allocated %NULL terminated array of strings.  Use
2278  *   g_strfreev() to free it.
2279  *
2280  * Since: 2.10
2281  */
2282 gchar **
2283 gtk_recent_info_get_groups (GtkRecentInfo *info,
2284                             gsize         *length)
2285 {
2286   GSList *l;
2287   gchar **retval;
2288   gsize n_groups, i;
2289   
2290   g_return_val_if_fail (info != NULL, NULL);
2291   
2292   if (!info->groups)
2293     {
2294       if (length)
2295         *length = 0;
2296       
2297       return NULL;
2298     }
2299   
2300   n_groups = g_slist_length (info->groups);
2301   
2302   retval = g_new0 (gchar *, n_groups + 1);
2303   
2304   for (l = info->groups, i = 0;
2305        l != NULL;
2306        l = l->next)
2307     {
2308       gchar *group_name = (gchar *) l->data;
2309       
2310       g_assert (group_name != NULL);
2311       
2312       retval[i++] = g_strdup (group_name);
2313     }
2314   retval[i] = NULL;
2315   
2316   if (length)
2317     *length = i;
2318   
2319   return retval;
2320 }
2321
2322 /**
2323  * gtk_recent_info_has_group:
2324  * @info: a #GtkRecentInfo
2325  * @group_name: name of a group
2326  *
2327  * Checks whether @group_name appears inside the groups registered for the
2328  * recently used item @info.
2329  *
2330  * Return value: %TRUE if the group was found.
2331  *
2332  * Since: 2.10
2333  */
2334 gboolean
2335 gtk_recent_info_has_group (GtkRecentInfo *info,
2336                            const gchar   *group_name)
2337 {
2338   GSList *l;
2339   
2340   g_return_val_if_fail (info != NULL, FALSE);
2341   g_return_val_if_fail (group_name != NULL, FALSE);
2342
2343   if (!info->groups)
2344     return FALSE;
2345
2346   for (l = info->groups; l != NULL; l = l->next)
2347     {
2348       gchar *g = (gchar *) l->data;
2349
2350       if (strcmp (g, group_name) == 0)
2351         return TRUE;
2352     }
2353
2354   return FALSE;
2355 }
2356
2357 /*
2358  * _gtk_recent_manager_sync:
2359  * 
2360  * Private function for synchronising the recent manager singleton.
2361  */
2362 void
2363 _gtk_recent_manager_sync (void)
2364 {
2365   if (recent_manager_singleton)
2366     {
2367       /* force a dump of the contents of the recent manager singleton */
2368       recent_manager_singleton->priv->is_dirty = TRUE;
2369       gtk_recent_manager_real_changed (recent_manager_singleton);
2370     }
2371 }
2372
2373 #define __GTK_RECENT_MANAGER_C__
2374 #include "gtkaliasdef.c"