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