1 /* GTK - The GIMP Toolkit
2 * gtkrecentmanager.c: a manager for the recently used resources
4 * Copyright (C) 2006 Emmanuele Bassi
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.
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.
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,
23 #include <sys/types.h>
32 #include <glib/gstdio.h>
34 #include "gtkrecentmanager.h"
37 #include "gtkicontheme.h"
38 #include "gtktypebuiltins.h"
39 #include "gtkprivate.h"
40 #include "gtkmarshalers.h"
44 #define XDG_PREFIX _gtk_xdg
45 #include "xdgmime/xdgmime.h"
48 /* the file where we store the recently used items */
49 #define GTK_RECENTLY_USED_FILE ".recently-used.xbel"
51 /* a poll approximately every five seconds */
54 /* return all items by default */
55 #define DEFAULT_LIMIT -1
57 /* keep in sync with xdgmime */
58 #define GTK_RECENT_DEFAULT_MIME "application/octet-stream"
64 GDestroyNotify notify;
91 GHashTable *apps_lookup;
102 struct _GtkRecentManagerPrivate
107 guint write_in_progress : 1;
108 guint read_in_progress : 1;
113 GBookmarkFile *recent_items;
128 static void gtk_recent_manager_dispose (GObject *object);
129 static void gtk_recent_manager_finalize (GObject *object);
131 static void gtk_recent_manager_set_property (GObject *object,
135 static void gtk_recent_manager_get_property (GObject *object,
139 static void gtk_recent_manager_changed (GtkRecentManager *manager);
141 static void gtk_recent_manager_real_changed (GtkRecentManager *manager);
142 static gboolean gtk_recent_manager_poll_timeout (gpointer data);
143 static void gtk_recent_manager_set_filename (GtkRecentManager *manager,
144 const gchar *filename);
146 static void build_recent_items_list (GtkRecentManager *manager);
147 static void purge_recent_items_list (GtkRecentManager *manager,
150 static RecentAppInfo *recent_app_info_new (const gchar *app_name);
151 static void recent_app_info_free (RecentAppInfo *app_info);
153 static GtkRecentInfo *gtk_recent_info_new (const gchar *uri);
154 static void gtk_recent_info_free (GtkRecentInfo *recent_info);
156 static guint signal_changed = 0;
158 static GtkRecentManager *recent_manager_singleton = NULL;
160 G_DEFINE_TYPE (GtkRecentManager, gtk_recent_manager, G_TYPE_OBJECT)
163 filename_warning (const gchar *format,
164 const gchar *filename,
165 const gchar *message)
167 gchar *utf8 = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
168 g_warning (format, utf8 ? utf8 : "(invalid filename)", message);
172 /* Test of haystack has the needle prefix, comparing case
173 * insensitive. haystack may be UTF-8, but needle must
174 * contain only lowercase ascii. */
176 has_case_prefix (const gchar *haystack,
181 /* Eat one character at a time. */
185 while (*n && *h && *n == g_ascii_tolower (*h))
195 gtk_recent_manager_error_quark (void)
197 return g_quark_from_static_string ("gtk-recent-manager-error-quark");
201 threads_dispatch (gpointer data)
203 ThreadsDispatch *dispatch = data;
204 gboolean res = FALSE;
206 GDK_THREADS_ENTER ();
208 if (!g_source_is_destroyed (g_main_current_source ()))
209 res = dispatch->func (dispatch->data);
211 GDK_THREADS_LEAVE ();
217 threads_free (gpointer data)
219 ThreadsDispatch *dispatch = data;
221 if (dispatch->notify)
222 dispatch->notify (dispatch->data);
224 g_slice_free (ThreadsDispatch, dispatch);
228 gtk_recent_manager_class_init (GtkRecentManagerClass *klass)
230 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
232 gtk_recent_manager_parent_class = g_type_class_peek_parent (klass);
234 gobject_class->set_property = gtk_recent_manager_set_property;
235 gobject_class->get_property = gtk_recent_manager_get_property;
236 gobject_class->dispose = gtk_recent_manager_dispose;
237 gobject_class->finalize = gtk_recent_manager_finalize;
240 * GtkRecentManager:filename
242 * The full path to the file to be used to store and read the recently
243 * used resources list
247 g_object_class_install_property (gobject_class,
249 g_param_spec_string ("filename",
251 P_("The full path to the file to be used to store and read the list"),
253 (G_PARAM_CONSTRUCT_ONLY | G_PARAM_READABLE | G_PARAM_WRITABLE)));
255 * GtkRecentManager:limit
257 * The maximum number of items to be returned by the
258 * gtk_recent_manager_get_items() function.
262 g_object_class_install_property (gobject_class,
264 g_param_spec_int ("limit",
266 P_("The maximum number of items to be returned by gtk_recent_manager_get_items()"),
272 * GtkRecentManager:size
274 * The size of the recently used resources list.
278 g_object_class_install_property (gobject_class,
280 g_param_spec_int ("size",
282 P_("The size of the recently used resources list"),
289 * GtkRecentManager::changed
290 * @recent_manager: the recent manager
292 * Emitted when the current recently used resources manager changes its
298 g_signal_new (I_("changed"),
299 G_TYPE_FROM_CLASS (klass),
301 G_STRUCT_OFFSET (GtkRecentManagerClass, changed),
303 g_cclosure_marshal_VOID__VOID,
306 klass->changed = gtk_recent_manager_real_changed;
308 g_type_class_add_private (klass, sizeof (GtkRecentManagerPrivate));
312 gtk_recent_manager_init (GtkRecentManager *manager)
314 GtkRecentManagerPrivate *priv;
315 ThreadsDispatch *dispatch;
317 priv = g_type_instance_get_private ((GTypeInstance *) manager,
318 GTK_TYPE_RECENT_MANAGER);
319 manager->priv = priv;
321 priv->limit = DEFAULT_LIMIT;
324 priv->is_dirty = FALSE;
325 priv->write_in_progress = FALSE;
326 priv->read_in_progress = FALSE;
328 priv->filename = g_build_filename (g_get_home_dir (),
329 GTK_RECENTLY_USED_FILE,
332 dispatch = g_slice_new (ThreadsDispatch);
333 dispatch->func = gtk_recent_manager_poll_timeout;
334 dispatch->data = manager;
335 dispatch->notify = NULL;
336 priv->poll_timeout = g_timeout_add_seconds_full (G_PRIORITY_DEFAULT + 30,
342 build_recent_items_list (manager);
346 gtk_recent_manager_set_property (GObject *object,
351 GtkRecentManager *recent_manager = GTK_RECENT_MANAGER (object);
356 gtk_recent_manager_set_filename (recent_manager, g_value_get_string (value));
359 gtk_recent_manager_set_limit (recent_manager, g_value_get_int (value));
362 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
368 gtk_recent_manager_get_property (GObject *object,
373 GtkRecentManager *recent_manager = GTK_RECENT_MANAGER (object);
378 g_value_set_string (value, recent_manager->priv->filename);
381 g_value_set_int (value, recent_manager->priv->limit);
384 g_value_set_int (value, recent_manager->priv->size);
387 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
393 gtk_recent_manager_dispose (GObject *object)
395 GtkRecentManager *manager = GTK_RECENT_MANAGER (object);
396 GtkRecentManagerPrivate *priv = manager->priv;
398 if (priv->poll_timeout)
400 g_source_remove (priv->poll_timeout);
401 priv->poll_timeout = 0;
404 G_OBJECT_CLASS (gtk_recent_manager_parent_class)->dispose (object);
408 gtk_recent_manager_finalize (GObject *object)
410 GtkRecentManager *manager = GTK_RECENT_MANAGER (object);
411 GtkRecentManagerPrivate *priv = manager->priv;
413 g_free (priv->filename);
415 if (priv->recent_items)
416 g_bookmark_file_free (priv->recent_items);
418 G_OBJECT_CLASS (gtk_recent_manager_parent_class)->finalize (object);
422 gtk_recent_manager_real_changed (GtkRecentManager *manager)
424 GtkRecentManagerPrivate *priv = manager->priv;
426 g_object_freeze_notify (G_OBJECT (manager));
431 struct stat stat_buf;
433 /* we are marked as dirty, so we dump the content of our
434 * recently used items list
436 g_assert (priv->filename != NULL);
438 priv->write_in_progress = TRUE;
440 /* if no container object has been defined, we create a new
441 * empty container, and dump it
443 if (!priv->recent_items)
445 priv->recent_items = g_bookmark_file_new ();
450 g_bookmark_file_to_file (priv->recent_items, priv->filename, &write_error);
453 filename_warning ("Attempting to store changes into `%s', "
456 write_error->message);
457 g_error_free (write_error);
460 priv->write_in_progress = FALSE;
462 /* we have sync'ed our list with the storage file, so we
463 * update the file mtime in order to skip the timed check
464 * and spare us from a re-read.
466 if (g_stat (priv->filename, &stat_buf) < 0)
468 filename_warning ("Unable to stat() the recently used resources file "
473 g_object_thaw_notify (G_OBJECT (manager));
478 priv->last_mtime = stat_buf.st_mtime;
480 /* mark us as clean */
481 priv->is_dirty = FALSE;
485 /* we are not marked as dirty, so we have been called
486 * because the recently used resources file has been
487 * changed (and not from us).
489 build_recent_items_list (manager);
492 g_object_thaw_notify (G_OBJECT (manager));
495 /* timed poll()-ing of the recently used resources file.
496 * an event-based system would be more efficient.
499 gtk_recent_manager_poll_timeout (gpointer data)
501 GtkRecentManager *manager = GTK_RECENT_MANAGER (data);
502 GtkRecentManagerPrivate *priv = manager->priv;
504 struct stat stat_buf;
507 /* wait for the next timeout if we have a read/write in progress */
508 if (priv->write_in_progress || priv->read_in_progress)
511 /* do not stat the file if we're within 5 seconds from the last stat() */
513 if (now < priv->last_mtime + 5);
516 stat_res = g_stat (priv->filename, &stat_buf);
519 /* the file does not exist, yet, so we wait */
523 filename_warning ("Unable to stat() the recently used resources file "
531 /* the file didn't change from the last poll, so we bail out */
532 if (stat_buf.st_mtime == priv->last_mtime)
535 /* the file has been changed, hence we emit the "changed" signal */
536 gtk_recent_manager_changed (manager);
542 gtk_recent_manager_set_filename (GtkRecentManager *manager,
543 const gchar *filename)
545 GtkRecentManagerPrivate *priv;
546 ThreadsDispatch *dispatch;
548 g_assert (GTK_IS_RECENT_MANAGER (manager));
549 priv = manager->priv;
551 if (!filename || filename[0] == '\0')
554 g_free (manager->priv->filename);
556 if (manager->priv->poll_timeout)
558 g_source_remove (manager->priv->poll_timeout);
559 manager->priv->poll_timeout = 0;
562 priv->filename = g_strdup (filename);
564 dispatch = g_slice_new (ThreadsDispatch);
565 dispatch->func = gtk_recent_manager_poll_timeout;
566 dispatch->data = manager;
567 dispatch->notify = NULL;
568 priv->poll_timeout = g_timeout_add_seconds_full (G_PRIORITY_DEFAULT + 30,
574 /* mark us clean, so that we can re-read the list
575 * of recently used resources
577 priv->is_dirty = FALSE;
578 build_recent_items_list (manager);
581 /* reads the recently used resources file and builds the items list.
582 * we keep the items list inside the parser object, and build the
583 * RecentInfo object only on user's demand to avoid useless replication.
584 * this function resets the dirty bit of the manager.
587 build_recent_items_list (GtkRecentManager *manager)
589 GtkRecentManagerPrivate *priv;
590 struct stat stat_buf;
596 priv = manager->priv;
597 g_assert (priv->filename != NULL);
599 if (!priv->recent_items)
601 priv->recent_items = g_bookmark_file_new ();
605 stat_res = g_stat (priv->filename, &stat_buf);
608 /* the file doesn't exists, so we bail out and wait for the first
616 filename_warning ("Attempting to read the recently used resources file "
617 "at `%s', but an error occurred: %s. Aborting.",
625 /* record the last mtime, for later use */
626 priv->last_mtime = stat_buf.st_mtime;
628 priv->read_in_progress = TRUE;
630 /* the file exists, and it's valid (we hope); if not, destroy the container
631 * object and hope for a better result when the next "changed" signal is
634 res = g_bookmark_file_load_from_file (priv->recent_items,
639 filename_warning ("Attempting to read the recently used resources file "
640 "at `%s', but the parser failed: %s.",
642 read_error->message);
644 g_bookmark_file_free (priv->recent_items);
645 priv->recent_items = NULL;
647 g_error_free (read_error);
650 size = g_bookmark_file_get_size (priv->recent_items);
651 if (priv->size != size)
655 g_object_notify (G_OBJECT (manager), "size");
658 priv->read_in_progress = FALSE;
659 priv->is_dirty = FALSE;
663 /********************
665 ********************/
669 * gtk_recent_manager_new:
671 * Creates a new recent manager object. Recent manager objects are used to
672 * handle the list of recently used resources. A #GtkRecentManager object
673 * monitors the recently used resources list, and emits the "changed" signal
674 * each time something inside the list changes.
676 * #GtkRecentManager objects are expensive: be sure to create them only when
677 * needed. You should use gtk_recent_manager_get_default() instead.
679 * Return value: A newly created #GtkRecentManager object.
684 gtk_recent_manager_new (void)
686 return g_object_new (GTK_TYPE_RECENT_MANAGER, NULL);
690 * gtk_recent_manager_get_default:
692 * Gets a unique instance of #GtkRecentManager, that you can share
693 * in your application without caring about memory management. The
694 * returned instance will be freed when you application terminates.
696 * Return value: A unique #GtkRecentManager. Do not ref or unref it.
701 gtk_recent_manager_get_default (void)
703 if (G_UNLIKELY (!recent_manager_singleton))
704 recent_manager_singleton = gtk_recent_manager_new ();
706 return recent_manager_singleton;
710 * gtk_recent_manager_get_for_screen:
711 * @screen: a #GdkScreen
713 * Gets the recent manager object associated with @screen; if this
714 * function has not previously been called for the given screen,
715 * a new recent manager object will be created and associated with
716 * the screen. Recent manager objects are fairly expensive to create,
717 * so using this function is usually a better choice than calling
718 * gtk_recent_manager_new() and setting the screen yourself; by using
719 * this function a single recent manager object will be shared between
722 * Return value: A unique #GtkRecentManager associated with the given
723 * screen. This recent manager is associated to the with the screen
724 * and can be used as long as the screen is open. Do not ref or
727 * Deprecated: 2.12: This function has been deprecated and should
728 * not be used in newly written code. Calling this function is
729 * equivalent to calling gtk_recent_manager_get_default().
734 gtk_recent_manager_get_for_screen (GdkScreen *screen)
736 return gtk_recent_manager_get_default ();
740 * gtk_recent_manager_set_screen:
741 * @manager: a #GtkRecentManager
742 * @screen: a #GdkScreen
744 * Sets the screen for a recent manager; the screen is used to
745 * track the user's currently configured recently used documents
750 * Deprecated: 2.12: This function has been deprecated and should
751 * not be used in newly written code. Calling this function has
755 gtk_recent_manager_set_screen (GtkRecentManager *manager,
762 * gtk_recent_manager_set_limit:
763 * @manager: a #GtkRecentManager
764 * @limit: the maximum number of items to return, or -1.
766 * Sets the maximum number of item that the gtk_recent_manager_get_items()
767 * function should return. If @limit is set to -1, then return all the
773 gtk_recent_manager_set_limit (GtkRecentManager *manager,
776 GtkRecentManagerPrivate *priv;
778 g_return_if_fail (GTK_IS_RECENT_MANAGER (manager));
780 priv = manager->priv;
785 * gtk_recent_manager_get_limit:
786 * @manager: a #GtkRecentManager
788 * Gets the maximum number of items that the gtk_recent_manager_get_items()
789 * function should return.
791 * Return value: the number of items to return, or -1 for every item.
796 gtk_recent_manager_get_limit (GtkRecentManager *manager)
798 GtkRecentManagerPrivate *priv;
800 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), DEFAULT_LIMIT);
802 priv = manager->priv;
807 * gtk_recent_manager_add_item:
808 * @manager: a #GtkRecentManager
811 * Adds a new resource, pointed by @uri, into the recently used
814 * This function automatically retrieves some of the needed
815 * metadata and setting other metadata to common default values; it
816 * then feeds the data to gtk_recent_manager_add_full().
818 * See gtk_recent_manager_add_full() if you want to explicitly
819 * define the metadata for the resource pointed by @uri.
821 * Return value: %TRUE if the new item was successfully added
822 * to the recently used resources list
827 gtk_recent_manager_add_item (GtkRecentManager *manager,
830 GtkRecentData recent_data;
833 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), FALSE);
834 g_return_val_if_fail (uri != NULL, FALSE);
836 recent_data.display_name = NULL;
837 recent_data.description = NULL;
838 recent_data.mime_type = NULL;
841 if (has_case_prefix (uri, "file:/"))
844 const gchar *mime_type;
846 filename = g_filename_from_uri (uri, NULL, NULL);
849 mime_type = xdg_mime_get_mime_type_for_file (filename, NULL);
851 recent_data.mime_type = g_strdup (mime_type);
856 if (!recent_data.mime_type)
857 recent_data.mime_type = g_strdup (GTK_RECENT_DEFAULT_MIME);
861 recent_data.mime_type = g_strdup (GTK_RECENT_DEFAULT_MIME);
863 recent_data.app_name = g_strdup (g_get_application_name ());
864 recent_data.app_exec = g_strjoin (" ", g_get_prgname (), "%u", NULL);
865 recent_data.groups = NULL;
866 recent_data.is_private = FALSE;
868 retval = gtk_recent_manager_add_full (manager, uri, &recent_data);
870 g_free (recent_data.mime_type);
871 g_free (recent_data.app_name);
872 g_free (recent_data.app_exec);
878 * gtk_recent_manager_add_full:
879 * @manager: a #GtkRecentManager
881 * @recent_data: metadata of the resource
883 * Adds a new resource, pointed by @uri, into the recently used
884 * resources list, using the metadata specified inside the #GtkRecentData
885 * structure passed in @recent_data.
887 * The passed URI will be used to identify this resource inside the
890 * In order to register the new recently used resource, metadata about
891 * the resource must be passed as well as the URI; the metadata is
892 * stored in a #GtkRecentData structure, which must contain the MIME
893 * type of the resource pointed by the URI; the name of the application
894 * that is registering the item, and a command line to be used when
895 * launching the item.
897 * Optionally, a #GtkRecentData structure might contain a UTF-8 string
898 * to be used when viewing the item instead of the last component of the
899 * URI; a short description of the item; whether the item should be
900 * considered private - that is, should be displayed only by the
901 * applications that have registered it.
903 * Return value: %TRUE if the new item was successfully added to the
904 * recently used resources list, %FALSE otherwise.
909 gtk_recent_manager_add_full (GtkRecentManager *manager,
911 const GtkRecentData *data)
913 GtkRecentManagerPrivate *priv;
915 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), FALSE);
916 g_return_val_if_fail (uri != NULL, FALSE);
917 g_return_val_if_fail (data != NULL, FALSE);
920 if ((data->display_name) &&
921 (!g_utf8_validate (data->display_name, -1, NULL)))
923 g_warning ("Attempting to add `%s' to the list of recently used "
924 "resources, but the display name is not a valid UTF-8 "
930 if ((data->description) &&
931 (!g_utf8_validate (data->description, -1, NULL)))
933 g_warning ("Attempting to add `%s' to the list of recently used "
934 "resources, but the description is not a valid UTF-8 "
941 if (!data->mime_type)
943 g_warning ("Attempting to add `%s' to the list of recently used "
944 "resources, but not MIME type was defined",
951 g_warning ("Attempting to add `%s' to the list of recently used "
952 "resources, but no name of the application that is "
953 "registering it was defined",
960 g_warning ("Attempting to add `%s' to the list of recently used "
961 "resources, but no command line for the application "
962 "that is registering it was defined",
967 priv = manager->priv;
969 if (!priv->recent_items)
971 priv->recent_items = g_bookmark_file_new ();
975 if (data->display_name)
976 g_bookmark_file_set_title (priv->recent_items, uri, data->display_name);
978 if (data->description)
979 g_bookmark_file_set_description (priv->recent_items, uri, data->description);
981 g_bookmark_file_set_mime_type (priv->recent_items, uri, data->mime_type);
983 if (data->groups && data->groups[0] != '\0')
987 for (j = 0; (data->groups)[j] != NULL; j++)
988 g_bookmark_file_add_group (priv->recent_items, uri, (data->groups)[j]);
991 /* register the application; this will take care of updating the
992 * registration count and time in case the application has
993 * already registered the same document inside the list
995 g_bookmark_file_add_application (priv->recent_items, uri,
999 g_bookmark_file_set_is_private (priv->recent_items, uri,
1002 /* mark us as dirty, so that when emitting the "changed" signal we
1003 * will dump our changes
1005 priv->is_dirty = TRUE;
1007 gtk_recent_manager_changed (manager);
1013 * gtk_recent_manager_remove_item:
1014 * @manager: a #GtkRecentManager
1015 * @uri: the URI of the item you wish to remove
1016 * @error: return location for a #GError, or %NULL
1018 * Removes a resource pointed by @uri from the recently used resources
1019 * list handled by a recent manager.
1021 * Return value: %TRUE if the item pointed by @uri has been successfully
1022 * removed by the recently used resources list, and %FALSE otherwise.
1027 gtk_recent_manager_remove_item (GtkRecentManager *manager,
1031 GtkRecentManagerPrivate *priv;
1032 GError *remove_error = NULL;
1034 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), FALSE);
1035 g_return_val_if_fail (uri != NULL, FALSE);
1036 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
1038 priv = manager->priv;
1040 if (!priv->recent_items)
1042 priv->recent_items = g_bookmark_file_new ();
1045 g_set_error (error, GTK_RECENT_MANAGER_ERROR,
1046 GTK_RECENT_MANAGER_ERROR_NOT_FOUND,
1047 _("Unable to find an item with URI '%s'"),
1053 g_bookmark_file_remove_item (priv->recent_items, uri, &remove_error);
1056 g_propagate_error (error, remove_error);
1061 priv->is_dirty = TRUE;
1063 gtk_recent_manager_changed (manager);
1069 * gtk_recent_manager_has_item:
1070 * @manager: a #GtkRecentManager
1073 * Checks whether there is a recently used resource registered
1074 * with @uri inside the recent manager.
1076 * Return value: %TRUE if the resource was found, %FALSE otherwise.
1081 gtk_recent_manager_has_item (GtkRecentManager *manager,
1084 GtkRecentManagerPrivate *priv;
1086 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), FALSE);
1087 g_return_val_if_fail (uri != NULL, FALSE);
1089 priv = manager->priv;
1090 g_return_val_if_fail (priv->recent_items != NULL, FALSE);
1092 return g_bookmark_file_has_item (priv->recent_items, uri);
1096 build_recent_info (GBookmarkFile *bookmarks,
1097 GtkRecentInfo *info)
1099 gchar **apps, **groups;
1100 gsize apps_len, groups_len, i;
1102 g_assert (bookmarks != NULL);
1103 g_assert (info != NULL);
1105 info->display_name = g_bookmark_file_get_title (bookmarks, info->uri, NULL);
1106 info->description = g_bookmark_file_get_description (bookmarks, info->uri, NULL);
1107 info->mime_type = g_bookmark_file_get_mime_type (bookmarks, info->uri, NULL);
1109 info->is_private = g_bookmark_file_get_is_private (bookmarks, info->uri, NULL);
1111 info->added = g_bookmark_file_get_added (bookmarks, info->uri, NULL);
1112 info->modified = g_bookmark_file_get_modified (bookmarks, info->uri, NULL);
1113 info->visited = g_bookmark_file_get_visited (bookmarks, info->uri, NULL);
1115 groups = g_bookmark_file_get_groups (bookmarks, info->uri, &groups_len, NULL);
1116 for (i = 0; i < groups_len; i++)
1118 gchar *group_name = g_strdup (groups[i]);
1120 info->groups = g_slist_append (info->groups, group_name);
1123 g_strfreev (groups);
1125 apps = g_bookmark_file_get_applications (bookmarks, info->uri, &apps_len, NULL);
1126 for (i = 0; i < apps_len; i++)
1128 gchar *app_name, *app_exec;
1131 RecentAppInfo *app_info;
1136 res = g_bookmark_file_get_app_info (bookmarks, info->uri, app_name,
1144 app_info = recent_app_info_new (app_name);
1145 app_info->exec = app_exec;
1146 app_info->count = count;
1147 app_info->stamp = stamp;
1149 info->applications = g_slist_append (info->applications,
1151 g_hash_table_replace (info->apps_lookup, app_info->name, app_info);
1158 * gtk_recent_manager_lookup_item:
1159 * @manager: a #GtkRecentManager
1161 * @error: a return location for a #GError, or %NULL
1163 * Searches for a URI inside the recently used resources list, and
1164 * returns a structure containing informations about the resource
1165 * like its MIME type, or its display name.
1167 * Return value: a #GtkRecentInfo structure containing information
1168 * about the resource pointed by @uri, or %NULL if the URI was
1169 * not registered in the recently used resources list. Free with
1170 * gtk_recent_info_unref().
1175 gtk_recent_manager_lookup_item (GtkRecentManager *manager,
1179 GtkRecentManagerPrivate *priv;
1180 GtkRecentInfo *info = NULL;
1182 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), NULL);
1183 g_return_val_if_fail (uri != NULL, NULL);
1184 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
1186 priv = manager->priv;
1187 if (!priv->recent_items)
1189 priv->recent_items = g_bookmark_file_new ();
1192 g_set_error (error, GTK_RECENT_MANAGER_ERROR,
1193 GTK_RECENT_MANAGER_ERROR_NOT_FOUND,
1194 _("Unable to find an item with URI '%s'"),
1200 if (!g_bookmark_file_has_item (priv->recent_items, uri))
1202 g_set_error (error, GTK_RECENT_MANAGER_ERROR,
1203 GTK_RECENT_MANAGER_ERROR_NOT_FOUND,
1204 _("Unable to find an item with URI '%s'"),
1209 info = gtk_recent_info_new (uri);
1210 g_return_val_if_fail (info != NULL, NULL);
1212 /* fill the RecentInfo structure with the data retrieved by our
1213 * parser object from the storage file
1215 build_recent_info (priv->recent_items, info);
1221 * gtk_recent_manager_move_item:
1222 * @manager: a #GtkRecentManager
1223 * @uri: the URI of a recently used resource
1224 * @new_uri: the new URI of the recently used resource, or %NULL to
1225 * remove the item pointed by @uri in the list
1226 * @error: a return location for a #GError, or %NULL
1228 * Changes the location of a recently used resource from @uri to @new_uri.
1230 * Please note that this function will not affect the resource pointed
1231 * by the URIs, but only the URI used in the recently used resources list.
1233 * Return value: %TRUE on success.
1238 gtk_recent_manager_move_item (GtkRecentManager *recent_manager,
1240 const gchar *new_uri,
1243 GtkRecentManagerPrivate *priv;
1247 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (recent_manager), FALSE);
1248 g_return_val_if_fail (uri != NULL, FALSE);
1249 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
1251 priv = recent_manager->priv;
1253 if (!g_bookmark_file_has_item (priv->recent_items, uri))
1255 g_set_error (error, GTK_RECENT_MANAGER_ERROR,
1256 GTK_RECENT_MANAGER_ERROR_NOT_FOUND,
1257 _("Unable to find an item with URI '%s'"),
1263 res = g_bookmark_file_move_item (priv->recent_items,
1268 g_propagate_error (error, move_error);
1272 priv->is_dirty = TRUE;
1274 gtk_recent_manager_changed (recent_manager);
1280 * gtk_recent_manager_get_items:
1281 * @manager: a #GtkRecentManager
1283 * Gets the list of recently used resources.
1285 * Return value: a list of newly allocated #GtkRecentInfo objects. Use
1286 * gtk_recent_info_unref() on each item inside the list, and then
1287 * free the list itself using g_list_free().
1292 gtk_recent_manager_get_items (GtkRecentManager *manager)
1294 GtkRecentManagerPrivate *priv;
1295 GList *retval = NULL;
1299 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), NULL);
1301 priv = manager->priv;
1302 if (!priv->recent_items)
1305 if (priv->limit == 0)
1308 uris = g_bookmark_file_get_uris (priv->recent_items, &uris_len);
1309 for (i = 0; i < uris_len; i++)
1311 GtkRecentInfo *info;
1313 if (priv->limit != -1 && i == priv->limit)
1316 info = gtk_recent_info_new (uris[i]);
1317 build_recent_info (priv->recent_items, info);
1319 retval = g_list_prepend (retval, info);
1328 purge_recent_items_list (GtkRecentManager *manager,
1331 GtkRecentManagerPrivate *priv = manager->priv;
1333 if (!priv->recent_items)
1336 g_bookmark_file_free (priv->recent_items);
1337 priv->recent_items = NULL;
1339 priv->recent_items = g_bookmark_file_new ();
1341 priv->is_dirty = TRUE;
1343 /* emit the changed signal, to ensure that the purge is written */
1344 gtk_recent_manager_changed (manager);
1348 * gtk_recent_manager_purge_items:
1349 * @manager: a #GtkRecentManager
1350 * @error: a return location for a #GError, or %NULL
1352 * Purges every item from the recently used resources list.
1354 * Return value: the number of items that have been removed from the
1355 * recently used resources list.
1360 gtk_recent_manager_purge_items (GtkRecentManager *manager,
1363 GtkRecentManagerPrivate *priv;
1366 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), -1);
1368 priv = manager->priv;
1369 if (!priv->recent_items)
1372 count = g_bookmark_file_get_size (priv->recent_items);
1376 purge_recent_items_list (manager, error);
1378 purged = count - g_bookmark_file_get_size (priv->recent_items);
1384 gtk_recent_manager_changed (GtkRecentManager *recent_manager)
1386 g_signal_emit (recent_manager, signal_changed, 0);
1394 gtk_recent_info_get_type (void)
1396 static GType info_type = 0;
1399 info_type = g_boxed_type_register_static (I_("GtkRecentInfo"),
1400 (GBoxedCopyFunc) gtk_recent_info_ref,
1401 (GBoxedFreeFunc) gtk_recent_info_unref);
1405 static GtkRecentInfo *
1406 gtk_recent_info_new (const gchar *uri)
1408 GtkRecentInfo *info;
1410 g_assert (uri != NULL);
1412 info = g_new0 (GtkRecentInfo, 1);
1413 info->uri = g_strdup (uri);
1415 info->applications = NULL;
1416 info->apps_lookup = g_hash_table_new (g_str_hash, g_str_equal);
1418 info->groups = NULL;
1420 info->ref_count = 1;
1426 gtk_recent_info_free (GtkRecentInfo *recent_info)
1431 g_free (recent_info->uri);
1432 g_free (recent_info->display_name);
1433 g_free (recent_info->description);
1434 g_free (recent_info->mime_type);
1436 if (recent_info->applications)
1438 g_slist_foreach (recent_info->applications,
1439 (GFunc) recent_app_info_free,
1441 g_slist_free (recent_info->applications);
1443 recent_info->applications = NULL;
1446 if (recent_info->apps_lookup)
1447 g_hash_table_destroy (recent_info->apps_lookup);
1449 if (recent_info->groups)
1451 g_slist_foreach (recent_info->groups,
1454 g_slist_free (recent_info->groups);
1456 recent_info->groups = NULL;
1459 if (recent_info->icon)
1460 g_object_unref (recent_info->icon);
1462 g_free (recent_info);
1466 * gtk_recent_info_ref:
1467 * @info: a #GtkRecentInfo
1469 * Increases the reference count of @recent_info by one.
1471 * Return value: the recent info object with its reference count increased
1477 gtk_recent_info_ref (GtkRecentInfo *info)
1479 g_return_val_if_fail (info != NULL, NULL);
1480 g_return_val_if_fail (info->ref_count > 0, NULL);
1482 info->ref_count += 1;
1488 * gtk_recent_info_unref:
1489 * @info: a #GtkRecentInfo
1491 * Decreases the reference count of @info by one. If the reference
1492 * count reaches zero, @info is deallocated, and the memory freed.
1497 gtk_recent_info_unref (GtkRecentInfo *info)
1499 g_return_if_fail (info != NULL);
1500 g_return_if_fail (info->ref_count > 0);
1502 info->ref_count -= 1;
1504 if (info->ref_count == 0)
1505 gtk_recent_info_free (info);
1509 * gtk_recent_info_get_uri:
1510 * @info: a #GtkRecentInfo
1512 * Gets the URI of the resource.
1514 * Return value: the URI of the resource. The returned string is
1515 * owned by the recent manager, and should not be freed.
1519 G_CONST_RETURN gchar *
1520 gtk_recent_info_get_uri (GtkRecentInfo *info)
1522 g_return_val_if_fail (info != NULL, NULL);
1528 * gtk_recent_info_get_display_name:
1529 * @info: a #GtkRecentInfo
1531 * Gets the name of the resource. If none has been defined, the basename
1532 * of the resource is obtained.
1534 * Return value: the display name of the resource. The returned string
1535 * is owned by the recent manager, and should not be freed.
1539 G_CONST_RETURN gchar *
1540 gtk_recent_info_get_display_name (GtkRecentInfo *info)
1542 g_return_val_if_fail (info != NULL, NULL);
1544 if (!info->display_name)
1545 info->display_name = gtk_recent_info_get_short_name (info);
1547 return info->display_name;
1551 * gtk_recent_info_get_description:
1552 * @info: a #GtkRecentInfo
1554 * Gets the (short) description of the resource.
1556 * Return value: the description of the resource. The returned string
1557 * is owned by the recent manager, and should not be freed.
1561 G_CONST_RETURN gchar *
1562 gtk_recent_info_get_description (GtkRecentInfo *info)
1564 g_return_val_if_fail (info != NULL, NULL);
1566 return info->description;
1570 * gtk_recent_info_get_mime_type:
1571 * @info: a #GtkRecentInfo
1573 * Gets the MIME type of the resource.
1575 * Return value: the MIME type of the resource. The returned string
1576 * is owned by the recent manager, and should not be freed.
1580 G_CONST_RETURN gchar *
1581 gtk_recent_info_get_mime_type (GtkRecentInfo *info)
1583 g_return_val_if_fail (info != NULL, NULL);
1585 if (!info->mime_type)
1586 info->mime_type = g_strdup (GTK_RECENT_DEFAULT_MIME);
1588 return info->mime_type;
1592 * gtk_recent_info_get_added:
1593 * @info: a #GtkRecentInfo
1595 * Gets the timestamp (seconds from system's Epoch) when the resource
1596 * was added to the recently used resources list.
1598 * Return value: the number of seconds elapsed from system's Epoch when
1599 * the resource was added to the list, or -1 on failure.
1604 gtk_recent_info_get_added (GtkRecentInfo *info)
1606 g_return_val_if_fail (info != NULL, (time_t) -1);
1612 * gtk_recent_info_get_modified:
1613 * @info: a #GtkRecentInfo
1615 * Gets the timestamp (seconds from system's Epoch) when the resource
1616 * was last modified.
1618 * Return value: the number of seconds elapsed from system's Epoch when
1619 * the resource was last modified, or -1 on failure.
1624 gtk_recent_info_get_modified (GtkRecentInfo *info)
1626 g_return_val_if_fail (info != NULL, (time_t) -1);
1628 return info->modified;
1632 * gtk_recent_info_get_visited:
1633 * @info: a #GtkRecentInfo
1635 * Gets the timestamp (seconds from system's Epoch) when the resource
1638 * Return value: the number of seconds elapsed from system's Epoch when
1639 * the resource was last visited, or -1 on failure.
1644 gtk_recent_info_get_visited (GtkRecentInfo *info)
1646 g_return_val_if_fail (info != NULL, (time_t) -1);
1648 return info->visited;
1652 * gtk_recent_info_get_private_hint:
1653 * @info: a #GtkRecentInfo
1655 * Gets the value of the "private" flag. Resources in the recently used
1656 * list that have this flag set to %TRUE should only be displayed by the
1657 * applications that have registered them.
1659 * Return value: %TRUE if the private flag was found, %FALSE otherwise.
1664 gtk_recent_info_get_private_hint (GtkRecentInfo *info)
1666 g_return_val_if_fail (info != NULL, FALSE);
1668 return info->is_private;
1672 static RecentAppInfo *
1673 recent_app_info_new (const gchar *app_name)
1675 RecentAppInfo *app_info;
1677 g_assert (app_name != NULL);
1679 app_info = g_new0 (RecentAppInfo, 1);
1680 app_info->name = g_strdup (app_name);
1681 app_info->exec = NULL;
1682 app_info->count = 1;
1683 app_info->stamp = time (NULL);
1689 recent_app_info_free (RecentAppInfo *app_info)
1694 g_free (app_info->name);
1696 g_free (app_info->exec);
1702 * gtk_recent_info_get_application_info:
1703 * @info: a #GtkRecentInfo
1704 * @app_name: the name of the application that has registered this item
1705 * @app_exec: return location for the string containing the command line
1706 * @count: return location for the number of times this item was registered
1707 * @time_: return location for the timestamp this item was last registered
1708 * for this application
1710 * Gets the data regarding the application that has registered the resource
1713 * If the command line contains any escape characters defined inside the
1714 * storage specification, they will be expanded.
1716 * Return value: %TRUE if an application with @app_name has registered this
1717 * resource inside the recently used list, or %FALSE otherwise. You should
1718 * free the returned command line using g_free().
1723 gtk_recent_info_get_application_info (GtkRecentInfo *info,
1724 const gchar *app_name,
1731 g_return_val_if_fail (info != NULL, FALSE);
1732 g_return_val_if_fail (app_name != NULL, FALSE);
1734 ai = (RecentAppInfo *) g_hash_table_lookup (info->apps_lookup,
1738 g_warning ("No registered application with name '%s' "
1739 "for item with URI '%s' found",
1746 *app_exec = ai->exec;
1758 * gtk_recent_info_get_applications:
1759 * @info: a #GtkRecentInfo
1760 * @length: return location for the length of the returned list, or %NULL
1762 * Retrieves the list of applications that have registered this resource.
1764 * Return value: a newly allocated %NULL-terminated array of strings.
1765 * Use g_strfreev() to free it.
1770 gtk_recent_info_get_applications (GtkRecentInfo *info,
1777 g_return_val_if_fail (info != NULL, NULL);
1779 if (!info->applications)
1787 n_apps = g_slist_length (info->applications);
1789 retval = g_new0 (gchar *, n_apps + 1);
1791 for (l = info->applications, i = 0;
1795 RecentAppInfo *ai = (RecentAppInfo *) l->data;
1797 g_assert (ai != NULL);
1799 retval[i++] = g_strdup (ai->name);
1810 * gtk_recent_info_has_application:
1811 * @info: a #GtkRecentInfo
1812 * @app_name: a string containing an application name
1814 * Checks whether an application registered this resource using @app_name.
1816 * Return value: %TRUE if an application with name @app_name was found,
1822 gtk_recent_info_has_application (GtkRecentInfo *info,
1823 const gchar *app_name)
1825 g_return_val_if_fail (info != NULL, FALSE);
1826 g_return_val_if_fail (app_name != NULL, FALSE);
1828 return (NULL != g_hash_table_lookup (info->apps_lookup, app_name));
1832 * gtk_recent_info_last_application:
1833 * @info: a #GtkRecentInfo
1835 * Gets the name of the last application that have registered the
1836 * recently used resource represented by @info.
1838 * Return value: an application name. Use g_free() to free it.
1843 gtk_recent_info_last_application (GtkRecentInfo *info)
1846 time_t last_stamp = (time_t) -1;
1849 g_return_val_if_fail (info != NULL, NULL);
1851 for (l = info->applications; l != NULL; l = l->next)
1853 RecentAppInfo *ai = (RecentAppInfo *) l->data;
1855 if (ai->stamp > last_stamp)
1858 last_stamp = ai->stamp;
1862 return g_strdup (name);
1866 get_icon_for_mime_type (const char *mime_type,
1869 GtkIconTheme *icon_theme;
1870 const char *separator;
1874 separator = strchr (mime_type, '/');
1878 icon_theme = gtk_icon_theme_get_default ();
1880 /* try with the three icon name variants for MIME types */
1882 /* canonicalize MIME type: foo/x-bar -> foo-x-bar */
1883 icon_name = g_string_new (NULL);
1884 g_string_append_len (icon_name, mime_type, separator - mime_type);
1885 g_string_append_c (icon_name, '-');
1886 g_string_append (icon_name, separator + 1);
1887 pixbuf = gtk_icon_theme_load_icon (icon_theme, icon_name->str,
1891 g_string_free (icon_name, TRUE);
1895 /* canonicalize MIME type, and prepend "gnome-mime-" */
1896 icon_name = g_string_new ("gnome-mime-");
1897 g_string_append_len (icon_name, mime_type, separator - mime_type);
1898 g_string_append_c (icon_name, '-');
1899 g_string_append (icon_name, separator + 1);
1900 pixbuf = gtk_icon_theme_load_icon (icon_theme, icon_name->str,
1904 g_string_free (icon_name, TRUE);
1908 /* try the MIME family icon */
1909 icon_name = g_string_new ("gnome-mime-");
1910 g_string_append_len (icon_name, mime_type, separator - mime_type);
1911 pixbuf = gtk_icon_theme_load_icon (icon_theme, icon_name->str,
1915 g_string_free (icon_name, TRUE);
1921 get_icon_fallback (const gchar *icon_name,
1924 GtkIconTheme *icon_theme;
1927 icon_theme = gtk_icon_theme_get_default ();
1929 retval = gtk_icon_theme_load_icon (icon_theme, icon_name,
1931 GTK_ICON_LOOKUP_USE_BUILTIN,
1933 g_assert (retval != NULL);
1939 * gtk_recent_info_get_icon:
1940 * @info: a #GtkRecentInfo
1941 * @size: the size of the icon in pixels
1943 * Retrieves the icon of size @size associated to the resource MIME type.
1945 * Return value: a #GdkPixbuf containing the icon, or %NULL.
1950 gtk_recent_info_get_icon (GtkRecentInfo *info,
1953 GdkPixbuf *retval = NULL;
1955 g_return_val_if_fail (info != NULL, NULL);
1957 if (info->mime_type)
1958 retval = get_icon_for_mime_type (info->mime_type, size);
1960 /* this function should never fail */
1963 if (info->mime_type &&
1964 strcmp (info->mime_type, "x-directory/normal") == 0)
1965 retval = get_icon_fallback (GTK_STOCK_DIRECTORY, size);
1967 retval = get_icon_fallback (GTK_STOCK_FILE, size);
1974 * gtk_recent_info_is_local:
1975 * @info: a #GtkRecentInfo
1977 * Checks whether the resource is local or not by looking at the
1978 * scheme of its URI.
1980 * Return value: %TRUE if the resource is local.
1985 gtk_recent_info_is_local (GtkRecentInfo *info)
1987 g_return_val_if_fail (info != NULL, FALSE);
1989 return has_case_prefix (info->uri, "file:/");
1993 * gtk_recent_info_exists:
1994 * @info: a #GtkRecentInfo
1996 * Checks whether the resource pointed by @info still exists. At
1997 * the moment this check is done only on resources pointing to local files.
1999 * Return value: %TRUE if the resource exists
2004 gtk_recent_info_exists (GtkRecentInfo *info)
2007 struct stat stat_buf;
2008 gboolean retval = FALSE;
2010 g_return_val_if_fail (info != NULL, FALSE);
2012 /* we guarantee only local resources */
2013 if (!gtk_recent_info_is_local (info))
2016 filename = g_filename_from_uri (info->uri, NULL, NULL);
2019 if (stat (filename, &stat_buf) == 0)
2029 * gtk_recent_info_match:
2030 * @info_a: a #GtkRecentInfo
2031 * @info_b: a #GtkRecentInfo
2033 * Checks whether two #GtkRecentInfo structures point to the same
2036 * Return value: %TRUE if both #GtkRecentInfo structures point to se same
2037 * resource, %FALSE otherwise.
2042 gtk_recent_info_match (GtkRecentInfo *info_a,
2043 GtkRecentInfo *info_b)
2045 g_return_val_if_fail (info_a != NULL, FALSE);
2046 g_return_val_if_fail (info_b != NULL, FALSE);
2048 return (0 == strcmp (info_a->uri, info_b->uri));
2051 /* taken from gnome-vfs-uri.c */
2052 static const gchar *
2053 get_method_string (const gchar *substring,
2054 gchar **method_string)
2060 g_ascii_isalnum (*p) || *p == '+' || *p == '-' || *p == '.';
2067 !(p == substring + 1 && g_ascii_isalpha (*substring))
2071 /* Found toplevel method specification. */
2072 method = g_strndup (substring, p - substring);
2073 *method_string = g_ascii_strdown (method, -1);
2079 *method_string = g_strdup ("file");
2086 /* Stolen from gnome_vfs_make_valid_utf8() */
2088 make_valid_utf8 (const char *name)
2091 const char *remainder, *invalid;
2092 int remaining_bytes, valid_bytes;
2096 remaining_bytes = name ? strlen (name) : 0;
2098 while (remaining_bytes != 0)
2100 if (g_utf8_validate (remainder, remaining_bytes, &invalid))
2103 valid_bytes = invalid - remainder;
2106 string = g_string_sized_new (remaining_bytes);
2108 g_string_append_len (string, remainder, valid_bytes);
2109 g_string_append_c (string, '?');
2111 remaining_bytes -= valid_bytes + 1;
2112 remainder = invalid + 1;
2116 return g_strdup (name);
2118 g_string_append (string, remainder);
2119 g_assert (g_utf8_validate (string->str, -1, NULL));
2121 return g_string_free (string, FALSE);
2125 get_uri_shortname_for_display (const gchar *uri)
2128 gboolean validated = FALSE;
2130 if (has_case_prefix (uri, "file:/"))
2134 local_file = g_filename_from_uri (uri, NULL, NULL);
2138 name = g_filename_display_basename (local_file);
2142 g_free (local_file);
2151 rest = get_method_string (uri, &method);
2152 local_file = g_filename_display_basename (rest);
2154 name = g_strconcat (method, ": ", local_file, NULL);
2156 g_free (local_file);
2160 g_assert (name != NULL);
2162 if (!validated && !g_utf8_validate (name, -1, NULL))
2166 utf8_name = make_valid_utf8 (name);
2176 * gtk_recent_info_get_short_name:
2177 * @info: an #GtkRecentInfo
2179 * Computes a valid UTF-8 string that can be used as the name of the item in a
2180 * menu or list. For example, calling this function on an item that refers to
2181 * "file:///foo/bar.txt" will yield "bar.txt".
2183 * Return value: A newly-allocated string in UTF-8 encoding; free it with
2189 gtk_recent_info_get_short_name (GtkRecentInfo *info)
2193 g_return_val_if_fail (info != NULL, NULL);
2195 if (info->uri == NULL)
2198 short_name = get_uri_shortname_for_display (info->uri);
2204 * gtk_recent_info_get_uri_display:
2205 * @info: a #GtkRecentInfo
2207 * Gets a displayable version of the resource's URI. If the resource
2208 * is local, it returns a local path; if the resource is not local,
2209 * it returns the UTF-8 encoded content of gtk_recent_info_get_uri().
2211 * Return value: a UTF-8 string containing the resource's URI or %NULL
2216 gtk_recent_info_get_uri_display (GtkRecentInfo *info)
2220 g_return_val_if_fail (info != NULL, NULL);
2223 if (gtk_recent_info_is_local (info))
2227 filename = g_filename_from_uri (info->uri, NULL, NULL);
2231 retval = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
2236 retval = make_valid_utf8 (info->uri);
2243 * gtk_recent_info_get_age:
2244 * @info: a #GtkRecentInfo
2246 * Gets the number of days elapsed since the last update of the resource
2249 * Return value: a positive integer containing the number of days elapsed
2250 * since the time this resource was last modified.
2255 gtk_recent_info_get_age (GtkRecentInfo *info)
2260 g_return_val_if_fail (info != NULL, -1);
2264 delta = now - info->modified;
2266 retval = (gint) (delta / (60 * 60 * 24));
2272 * gtk_recent_info_get_groups:
2273 * @info: a #GtkRecentInfo
2274 * @length: return location for the number of groups returned, or %NULL
2276 * Returns all groups registered for the recently used item @info. The
2277 * array of returned group names will be %NULL terminated, so length might
2278 * optionally be %NULL.
2280 * Return value: a newly allocated %NULL terminated array of strings. Use
2281 * g_strfreev() to free it.
2286 gtk_recent_info_get_groups (GtkRecentInfo *info,
2293 g_return_val_if_fail (info != NULL, NULL);
2303 n_groups = g_slist_length (info->groups);
2305 retval = g_new0 (gchar *, n_groups + 1);
2307 for (l = info->groups, i = 0;
2311 gchar *group_name = (gchar *) l->data;
2313 g_assert (group_name != NULL);
2315 retval[i++] = g_strdup (group_name);
2326 * gtk_recent_info_has_group:
2327 * @info: a #GtkRecentInfo
2328 * @group_name: name of a group
2330 * Checks whether @group_name appears inside the groups registered for the
2331 * recently used item @info.
2333 * Return value: %TRUE if the group was found.
2338 gtk_recent_info_has_group (GtkRecentInfo *info,
2339 const gchar *group_name)
2343 g_return_val_if_fail (info != NULL, FALSE);
2344 g_return_val_if_fail (group_name != NULL, FALSE);
2349 for (l = info->groups; l != NULL; l = l->next)
2351 gchar *g = (gchar *) l->data;
2353 if (strcmp (g, group_name) == 0)
2361 * _gtk_recent_manager_sync:
2363 * Private function for synchronising the recent manager singleton.
2366 _gtk_recent_manager_sync (void)
2368 if (recent_manager_singleton)
2370 /* force a dump of the contents of the recent manager singleton */
2371 recent_manager_singleton->priv->is_dirty = TRUE;
2372 gtk_recent_manager_real_changed (recent_manager_singleton);
2376 #define __GTK_RECENT_MANAGER_C__
2377 #include "gtkaliasdef.c"