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>
35 #include "gtkrecentmanager.h"
38 #include "gtkicontheme.h"
39 #include "gtktypebuiltins.h"
40 #include "gtkprivate.h"
41 #include "gtkmarshalers.h"
44 /* the file where we store the recently used items */
45 #define GTK_RECENTLY_USED_FILE ".recently-used.xbel"
47 /* return all items by default */
48 #define DEFAULT_LIMIT -1
50 /* keep in sync with xdgmime */
51 #define GTK_RECENT_DEFAULT_MIME "application/octet-stream"
77 GHashTable *apps_lookup;
88 #define GTK_RECENT_MANAGER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_RECENT_MANAGER, GtkRecentManagerPrivate))
90 struct _GtkRecentManagerPrivate
99 GBookmarkFile *recent_items;
101 GFileMonitor *monitor;
113 static void gtk_recent_manager_dispose (GObject *object);
114 static void gtk_recent_manager_finalize (GObject *object);
115 static void gtk_recent_manager_set_property (GObject *object,
119 static void gtk_recent_manager_get_property (GObject *object,
123 static void gtk_recent_manager_add_item_query_info (GObject *source_object,
126 static void gtk_recent_manager_monitor_changed (GFileMonitor *monitor,
129 GFileMonitorEvent event_type,
131 static void gtk_recent_manager_changed (GtkRecentManager *manager);
132 static void gtk_recent_manager_real_changed (GtkRecentManager *manager);
133 static void gtk_recent_manager_set_filename (GtkRecentManager *manager,
134 const gchar *filename);
135 static void gtk_recent_manager_clamp_to_age (GtkRecentManager *manager,
139 static void build_recent_items_list (GtkRecentManager *manager);
140 static void purge_recent_items_list (GtkRecentManager *manager,
143 static RecentAppInfo *recent_app_info_new (const gchar *app_name);
144 static void recent_app_info_free (RecentAppInfo *app_info);
146 static GtkRecentInfo *gtk_recent_info_new (const gchar *uri);
147 static void gtk_recent_info_free (GtkRecentInfo *recent_info);
149 static guint signal_changed = 0;
151 static GtkRecentManager *recent_manager_singleton = NULL;
153 G_DEFINE_TYPE (GtkRecentManager, gtk_recent_manager, G_TYPE_OBJECT)
156 filename_warning (const gchar *format,
157 const gchar *filename,
158 const gchar *message)
160 gchar *utf8 = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
161 g_warning (format, utf8 ? utf8 : "(invalid filename)", message);
165 /* Test of haystack has the needle prefix, comparing case
166 * insensitive. haystack may be UTF-8, but needle must
167 * contain only lowercase ascii. */
169 has_case_prefix (const gchar *haystack,
174 /* Eat one character at a time. */
178 while (*n && *h && *n == g_ascii_tolower (*h))
188 gtk_recent_manager_error_quark (void)
190 return g_quark_from_static_string ("gtk-recent-manager-error-quark");
194 gtk_recent_manager_class_init (GtkRecentManagerClass *klass)
196 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
198 gobject_class->set_property = gtk_recent_manager_set_property;
199 gobject_class->get_property = gtk_recent_manager_get_property;
200 gobject_class->dispose = gtk_recent_manager_dispose;
201 gobject_class->finalize = gtk_recent_manager_finalize;
204 * GtkRecentManager:filename
206 * The full path to the file to be used to store and read the recently
207 * used resources list
211 g_object_class_install_property (gobject_class,
213 g_param_spec_string ("filename",
215 P_("The full path to the file to be used to store and read the list"),
217 (G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE)));
219 * GtkRecentManager:limit
221 * The maximum number of items to be returned by the
222 * gtk_recent_manager_get_items() function.
226 g_object_class_install_property (gobject_class,
228 g_param_spec_int ("limit",
230 P_("The maximum number of items to be returned by gtk_recent_manager_get_items()"),
236 * GtkRecentManager:size
238 * The size of the recently used resources list.
242 g_object_class_install_property (gobject_class,
244 g_param_spec_int ("size",
246 P_("The size of the recently used resources list"),
253 * GtkRecentManager::changed
254 * @recent_manager: the recent manager
256 * Emitted when the current recently used resources manager changes its
262 g_signal_new (I_("changed"),
263 G_TYPE_FROM_CLASS (klass),
265 G_STRUCT_OFFSET (GtkRecentManagerClass, changed),
267 g_cclosure_marshal_VOID__VOID,
270 klass->changed = gtk_recent_manager_real_changed;
272 g_type_class_add_private (klass, sizeof (GtkRecentManagerPrivate));
276 gtk_recent_manager_init (GtkRecentManager *manager)
278 GtkRecentManagerPrivate *priv;
280 manager->priv = priv = GTK_RECENT_MANAGER_GET_PRIVATE (manager);
282 priv->limit = DEFAULT_LIMIT;
285 priv->filename = NULL;
289 gtk_recent_manager_set_property (GObject *object,
294 GtkRecentManager *recent_manager = GTK_RECENT_MANAGER (object);
299 gtk_recent_manager_set_filename (recent_manager, g_value_get_string (value));
302 gtk_recent_manager_set_limit (recent_manager, g_value_get_int (value));
305 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
311 gtk_recent_manager_get_property (GObject *object,
316 GtkRecentManager *recent_manager = GTK_RECENT_MANAGER (object);
321 g_value_set_string (value, recent_manager->priv->filename);
324 g_value_set_int (value, recent_manager->priv->limit);
327 g_value_set_int (value, recent_manager->priv->size);
330 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
336 gtk_recent_manager_dispose (GObject *object)
338 GtkRecentManager *manager = GTK_RECENT_MANAGER (object);
339 GtkRecentManagerPrivate *priv = manager->priv;
343 g_signal_handlers_disconnect_by_func (priv->monitor,
344 G_CALLBACK (gtk_recent_manager_monitor_changed),
346 g_object_unref (priv->monitor);
347 priv->monitor = NULL;
350 G_OBJECT_CLASS (gtk_recent_manager_parent_class)->dispose (object);
354 gtk_recent_manager_finalize (GObject *object)
356 GtkRecentManager *manager = GTK_RECENT_MANAGER (object);
357 GtkRecentManagerPrivate *priv = manager->priv;
359 g_free (priv->filename);
361 if (priv->recent_items)
362 g_bookmark_file_free (priv->recent_items);
364 G_OBJECT_CLASS (gtk_recent_manager_parent_class)->finalize (object);
368 gtk_recent_manager_real_changed (GtkRecentManager *manager)
370 GtkRecentManagerPrivate *priv = manager->priv;
372 g_object_freeze_notify (G_OBJECT (manager));
378 /* we are marked as dirty, so we dump the content of our
379 * recently used items list
381 g_assert (priv->filename != NULL);
383 if (!priv->recent_items)
385 /* if no container object has been defined, we create a new
386 * empty container, and dump it
388 priv->recent_items = g_bookmark_file_new ();
393 GtkSettings *settings = gtk_settings_get_default ();
396 g_object_get (G_OBJECT (settings), "gtk-recent-files-max-age", &age, NULL);
398 gtk_recent_manager_clamp_to_age (manager, age);
401 g_bookmark_file_free (priv->recent_items);
402 priv->recent_items = NULL;
404 priv->recent_items = g_bookmark_file_new ();
409 g_bookmark_file_to_file (priv->recent_items, priv->filename, &write_error);
412 filename_warning ("Attempting to store changes into `%s', "
415 write_error->message);
416 g_error_free (write_error);
419 if (g_chmod (priv->filename, 0600) < 0)
421 filename_warning ("Attempting to set the permissions of `%s', "
427 /* mark us as clean */
428 priv->is_dirty = FALSE;
432 /* we are not marked as dirty, so we have been called
433 * because the recently used resources file has been
434 * changed (and not from us).
436 build_recent_items_list (manager);
439 g_object_thaw_notify (G_OBJECT (manager));
443 gtk_recent_manager_monitor_changed (GFileMonitor *monitor,
446 GFileMonitorEvent event_type,
449 GtkRecentManager *manager = user_data;
453 case G_FILE_MONITOR_EVENT_CHANGED:
454 case G_FILE_MONITOR_EVENT_CREATED:
455 gtk_recent_manager_changed (manager);
458 case G_FILE_MONITOR_EVENT_DELETED:
467 gtk_recent_manager_set_filename (GtkRecentManager *manager,
468 const gchar *filename)
470 GtkRecentManagerPrivate *priv;
474 g_assert (GTK_IS_RECENT_MANAGER (manager));
476 priv = manager->priv;
478 /* if a filename is already set and filename is not NULL, then copy
479 * it and reset the monitor; otherwise, if it's NULL we're being
480 * called from the finalization sequence, so we simply disconnect the
481 * monitoring and return.
483 * if no filename is set and filename is NULL, use the default.
487 g_free (priv->filename);
491 g_signal_handlers_disconnect_by_func (priv->monitor,
492 G_CALLBACK (gtk_recent_manager_monitor_changed),
494 g_object_unref (priv->monitor);
495 priv->monitor = NULL;
498 if (!filename || *filename == '\0')
501 priv->filename = g_strdup (filename);
505 if (!filename || *filename == '\0')
506 priv->filename = g_build_filename (g_get_home_dir (),
507 GTK_RECENTLY_USED_FILE,
510 priv->filename = g_strdup (filename);
513 g_assert (priv->filename != NULL);
514 file = g_file_new_for_path (priv->filename);
517 priv->monitor = g_file_monitor_file (file, G_FILE_MONITOR_NONE, NULL, &error);
520 filename_warning ("Unable to monitor `%s': %s\n"
521 "The GtkRecentManager will not update its contents "
522 "if the file is changed from other instances",
525 g_error_free (error);
528 g_signal_connect (priv->monitor, "changed",
529 G_CALLBACK (gtk_recent_manager_monitor_changed),
532 g_object_unref (file);
534 priv->is_dirty = FALSE;
535 build_recent_items_list (manager);
538 /* reads the recently used resources file and builds the items list.
539 * we keep the items list inside the parser object, and build the
540 * RecentInfo object only on user's demand to avoid useless replication.
541 * this function resets the dirty bit of the manager.
544 build_recent_items_list (GtkRecentManager *manager)
546 GtkRecentManagerPrivate *priv = manager->priv;
550 g_assert (priv->filename != NULL);
552 if (!priv->recent_items)
554 priv->recent_items = g_bookmark_file_new ();
558 /* the file exists, and it's valid (we hope); if not, destroy the container
559 * object and hope for a better result when the next "changed" signal is
562 g_bookmark_file_load_from_file (priv->recent_items, priv->filename, &read_error);
565 /* if the file does not exist we just wait for the first write
566 * operation on this recent manager instance, to avoid creating
567 * empty files and leading to spurious file system events (Sabayon
568 * will not be happy about those)
570 if (read_error->domain == G_FILE_ERROR &&
571 read_error->code != G_FILE_ERROR_NOENT)
572 filename_warning ("Attempting to read the recently used resources "
573 "file at `%s', but the parser failed: %s.",
575 read_error->message);
577 g_bookmark_file_free (priv->recent_items);
578 priv->recent_items = NULL;
580 g_error_free (read_error);
584 size = g_bookmark_file_get_size (priv->recent_items);
585 if (priv->size != size)
589 g_object_notify (G_OBJECT (manager), "size");
593 priv->is_dirty = FALSE;
597 /********************
599 ********************/
603 * gtk_recent_manager_new:
605 * Creates a new recent manager object. Recent manager objects are used to
606 * handle the list of recently used resources. A #GtkRecentManager object
607 * monitors the recently used resources list, and emits the "changed" signal
608 * each time something inside the list changes.
610 * #GtkRecentManager objects are expensive: be sure to create them only when
611 * needed. You should use gtk_recent_manager_get_default() instead.
613 * Return value: A newly created #GtkRecentManager object.
618 gtk_recent_manager_new (void)
620 return g_object_new (GTK_TYPE_RECENT_MANAGER, NULL);
624 * gtk_recent_manager_get_default:
626 * Gets a unique instance of #GtkRecentManager, that you can share
627 * in your application without caring about memory management. The
628 * returned instance will be freed when you application terminates.
630 * Return value: (transfer none): A unique #GtkRecentManager. Do not ref or unref it.
635 gtk_recent_manager_get_default (void)
637 if (G_UNLIKELY (!recent_manager_singleton))
638 recent_manager_singleton = gtk_recent_manager_new ();
640 return recent_manager_singleton;
644 * gtk_recent_manager_get_for_screen:
645 * @screen: a #GdkScreen
647 * Gets the recent manager object associated with @screen; if this
648 * function has not previously been called for the given screen,
649 * a new recent manager object will be created and associated with
650 * the screen. Recent manager objects are fairly expensive to create,
651 * so using this function is usually a better choice than calling
652 * gtk_recent_manager_new() and setting the screen yourself; by using
653 * this function a single recent manager object will be shared between
656 * Return value: A unique #GtkRecentManager associated with the given
657 * screen. This recent manager is associated to the with the screen
658 * and can be used as long as the screen is open. Do not ref or
661 * Deprecated: 2.12: This function has been deprecated and should
662 * not be used in newly written code. Calling this function is
663 * equivalent to calling gtk_recent_manager_get_default().
668 gtk_recent_manager_get_for_screen (GdkScreen *screen)
670 return gtk_recent_manager_get_default ();
674 * gtk_recent_manager_set_screen:
675 * @manager: a #GtkRecentManager
676 * @screen: a #GdkScreen
678 * Sets the screen for a recent manager; the screen is used to
679 * track the user's currently configured recently used documents
684 * Deprecated: 2.12: This function has been deprecated and should
685 * not be used in newly written code. Calling this function has
689 gtk_recent_manager_set_screen (GtkRecentManager *manager,
696 * gtk_recent_manager_set_limit:
697 * @manager: a #GtkRecentManager
698 * @limit: the maximum number of items to return, or -1.
700 * Sets the maximum number of item that the gtk_recent_manager_get_items()
701 * function should return. If @limit is set to -1, then return all the
707 gtk_recent_manager_set_limit (GtkRecentManager *manager,
710 GtkRecentManagerPrivate *priv;
712 g_return_if_fail (GTK_IS_RECENT_MANAGER (manager));
714 priv = manager->priv;
719 * gtk_recent_manager_get_limit:
720 * @manager: a #GtkRecentManager
722 * Gets the maximum number of items that the gtk_recent_manager_get_items()
723 * function should return.
725 * Return value: the number of items to return, or -1 for every item.
730 gtk_recent_manager_get_limit (GtkRecentManager *manager)
732 GtkRecentManagerPrivate *priv;
734 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), DEFAULT_LIMIT);
736 priv = manager->priv;
741 gtk_recent_manager_add_item_query_info (GObject *source_object,
745 GFile *file = G_FILE (source_object);
746 GtkRecentManager *manager = user_data;
747 GtkRecentData recent_data;
748 GFileInfo *file_info;
752 uri = g_file_get_uri (file);
755 file_info = g_file_query_info_finish (file, res, &error);
758 g_warning ("Unable to retrieve the file info for `%s': %s",
761 g_error_free (error);
765 recent_data.display_name = NULL;
766 recent_data.description = NULL;
772 content_type = g_file_info_get_attribute_as_string (file_info, G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE);
774 if (G_LIKELY (content_type))
775 recent_data.mime_type = g_content_type_get_mime_type (content_type);
777 recent_data.mime_type = g_strdup (GTK_RECENT_DEFAULT_MIME);
779 g_free (content_type);
780 g_object_unref (file_info);
783 recent_data.mime_type = g_strdup (GTK_RECENT_DEFAULT_MIME);
785 recent_data.app_name = g_strdup (g_get_application_name ());
786 recent_data.app_exec = g_strjoin (" ", g_get_prgname (), "%u", NULL);
787 recent_data.groups = NULL;
788 recent_data.is_private = FALSE;
790 /* Ignore return value, this can't fail anyway since all required
792 gtk_recent_manager_add_full (manager, uri, &recent_data);
794 manager->priv->is_dirty = TRUE;
795 gtk_recent_manager_changed (manager);
797 g_free (recent_data.mime_type);
798 g_free (recent_data.app_name);
799 g_free (recent_data.app_exec);
802 g_object_unref (manager);
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,
832 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), FALSE);
833 g_return_val_if_fail (uri != NULL, FALSE);
835 file = g_file_new_for_uri (uri);
837 g_file_query_info_async (file,
838 G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE,
840 G_FILE_QUERY_INFO_NONE,
842 gtk_recent_manager_add_item_query_info,
843 g_object_ref (manager));
845 g_object_unref (file);
851 * gtk_recent_manager_add_full:
852 * @manager: a #GtkRecentManager
854 * @recent_data: metadata of the resource
856 * Adds a new resource, pointed by @uri, into the recently used
857 * resources list, using the metadata specified inside the #GtkRecentData
858 * structure passed in @recent_data.
860 * The passed URI will be used to identify this resource inside the
863 * In order to register the new recently used resource, metadata about
864 * the resource must be passed as well as the URI; the metadata is
865 * stored in a #GtkRecentData structure, which must contain the MIME
866 * type of the resource pointed by the URI; the name of the application
867 * that is registering the item, and a command line to be used when
868 * launching the item.
870 * Optionally, a #GtkRecentData structure might contain a UTF-8 string
871 * to be used when viewing the item instead of the last component of the
872 * URI; a short description of the item; whether the item should be
873 * considered private - that is, should be displayed only by the
874 * applications that have registered it.
876 * Return value: %TRUE if the new item was successfully added to the
877 * recently used resources list, %FALSE otherwise.
882 gtk_recent_manager_add_full (GtkRecentManager *manager,
884 const GtkRecentData *data)
886 GtkRecentManagerPrivate *priv;
888 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), FALSE);
889 g_return_val_if_fail (uri != NULL, FALSE);
890 g_return_val_if_fail (data != NULL, FALSE);
893 if ((data->display_name) &&
894 (!g_utf8_validate (data->display_name, -1, NULL)))
896 g_warning ("Attempting to add `%s' to the list of recently used "
897 "resources, but the display name is not a valid UTF-8 "
903 if ((data->description) &&
904 (!g_utf8_validate (data->description, -1, NULL)))
906 g_warning ("Attempting to add `%s' to the list of recently used "
907 "resources, but the description is not a valid UTF-8 "
914 if (!data->mime_type)
916 g_warning ("Attempting to add `%s' to the list of recently used "
917 "resources, but not MIME type was defined",
924 g_warning ("Attempting to add `%s' to the list of recently used "
925 "resources, but no name of the application that is "
926 "registering it was defined",
933 g_warning ("Attempting to add `%s' to the list of recently used "
934 "resources, but no command line for the application "
935 "that is registering it was defined",
940 priv = manager->priv;
942 if (!priv->recent_items)
944 priv->recent_items = g_bookmark_file_new ();
948 if (data->display_name)
949 g_bookmark_file_set_title (priv->recent_items, uri, data->display_name);
951 if (data->description)
952 g_bookmark_file_set_description (priv->recent_items, uri, data->description);
954 g_bookmark_file_set_mime_type (priv->recent_items, uri, data->mime_type);
956 if (data->groups && data->groups[0] != '\0')
960 for (j = 0; (data->groups)[j] != NULL; j++)
961 g_bookmark_file_add_group (priv->recent_items, uri, (data->groups)[j]);
964 /* register the application; this will take care of updating the
965 * registration count and time in case the application has
966 * already registered the same document inside the list
968 g_bookmark_file_add_application (priv->recent_items, uri,
972 g_bookmark_file_set_is_private (priv->recent_items, uri,
975 /* mark us as dirty, so that when emitting the "changed" signal we
976 * will dump our changes
978 priv->is_dirty = TRUE;
980 gtk_recent_manager_changed (manager);
986 * gtk_recent_manager_remove_item:
987 * @manager: a #GtkRecentManager
988 * @uri: the URI of the item you wish to remove
989 * @error: (allow-none): return location for a #GError, or %NULL
991 * Removes a resource pointed by @uri from the recently used resources
992 * list handled by a recent manager.
994 * Return value: %TRUE if the item pointed by @uri has been successfully
995 * removed by the recently used resources list, and %FALSE otherwise.
1000 gtk_recent_manager_remove_item (GtkRecentManager *manager,
1004 GtkRecentManagerPrivate *priv;
1005 GError *remove_error = NULL;
1007 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), FALSE);
1008 g_return_val_if_fail (uri != NULL, FALSE);
1009 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
1011 priv = manager->priv;
1013 if (!priv->recent_items)
1015 priv->recent_items = g_bookmark_file_new ();
1018 g_set_error (error, GTK_RECENT_MANAGER_ERROR,
1019 GTK_RECENT_MANAGER_ERROR_NOT_FOUND,
1020 _("Unable to find an item with URI '%s'"),
1026 g_bookmark_file_remove_item (priv->recent_items, uri, &remove_error);
1029 g_error_free (remove_error);
1031 g_set_error (error, GTK_RECENT_MANAGER_ERROR,
1032 GTK_RECENT_MANAGER_ERROR_NOT_FOUND,
1033 _("Unable to find an item with URI '%s'"),
1039 priv->is_dirty = TRUE;
1041 gtk_recent_manager_changed (manager);
1047 * gtk_recent_manager_has_item:
1048 * @manager: a #GtkRecentManager
1051 * Checks whether there is a recently used resource registered
1052 * with @uri inside the recent manager.
1054 * Return value: %TRUE if the resource was found, %FALSE otherwise.
1059 gtk_recent_manager_has_item (GtkRecentManager *manager,
1062 GtkRecentManagerPrivate *priv;
1064 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), FALSE);
1065 g_return_val_if_fail (uri != NULL, FALSE);
1067 priv = manager->priv;
1068 g_return_val_if_fail (priv->recent_items != NULL, FALSE);
1070 return g_bookmark_file_has_item (priv->recent_items, uri);
1074 build_recent_info (GBookmarkFile *bookmarks,
1075 GtkRecentInfo *info)
1077 gchar **apps, **groups;
1078 gsize apps_len, groups_len, i;
1080 g_assert (bookmarks != NULL);
1081 g_assert (info != NULL);
1083 info->display_name = g_bookmark_file_get_title (bookmarks, info->uri, NULL);
1084 info->description = g_bookmark_file_get_description (bookmarks, info->uri, NULL);
1085 info->mime_type = g_bookmark_file_get_mime_type (bookmarks, info->uri, NULL);
1087 info->is_private = g_bookmark_file_get_is_private (bookmarks, info->uri, NULL);
1089 info->added = g_bookmark_file_get_added (bookmarks, info->uri, NULL);
1090 info->modified = g_bookmark_file_get_modified (bookmarks, info->uri, NULL);
1091 info->visited = g_bookmark_file_get_visited (bookmarks, info->uri, NULL);
1093 groups = g_bookmark_file_get_groups (bookmarks, info->uri, &groups_len, NULL);
1094 for (i = 0; i < groups_len; i++)
1096 gchar *group_name = g_strdup (groups[i]);
1098 info->groups = g_slist_append (info->groups, group_name);
1101 g_strfreev (groups);
1103 apps = g_bookmark_file_get_applications (bookmarks, info->uri, &apps_len, NULL);
1104 for (i = 0; i < apps_len; i++)
1106 gchar *app_name, *app_exec;
1109 RecentAppInfo *app_info;
1114 res = g_bookmark_file_get_app_info (bookmarks, info->uri, app_name,
1122 app_info = recent_app_info_new (app_name);
1123 app_info->exec = app_exec;
1124 app_info->count = count;
1125 app_info->stamp = stamp;
1127 info->applications = g_slist_prepend (info->applications, app_info);
1128 g_hash_table_replace (info->apps_lookup, app_info->name, app_info);
1135 * gtk_recent_manager_lookup_item:
1136 * @manager: a #GtkRecentManager
1138 * @error: (allow-none): a return location for a #GError, or %NULL
1140 * Searches for a URI inside the recently used resources list, and
1141 * returns a structure containing informations about the resource
1142 * like its MIME type, or its display name.
1144 * Return value: a #GtkRecentInfo structure containing information
1145 * about the resource pointed by @uri, or %NULL if the URI was
1146 * not registered in the recently used resources list. Free with
1147 * gtk_recent_info_unref().
1152 gtk_recent_manager_lookup_item (GtkRecentManager *manager,
1156 GtkRecentManagerPrivate *priv;
1157 GtkRecentInfo *info = NULL;
1159 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), NULL);
1160 g_return_val_if_fail (uri != NULL, NULL);
1161 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
1163 priv = manager->priv;
1164 if (!priv->recent_items)
1166 priv->recent_items = g_bookmark_file_new ();
1169 g_set_error (error, GTK_RECENT_MANAGER_ERROR,
1170 GTK_RECENT_MANAGER_ERROR_NOT_FOUND,
1171 _("Unable to find an item with URI '%s'"),
1177 if (!g_bookmark_file_has_item (priv->recent_items, uri))
1179 g_set_error (error, GTK_RECENT_MANAGER_ERROR,
1180 GTK_RECENT_MANAGER_ERROR_NOT_FOUND,
1181 _("Unable to find an item with URI '%s'"),
1186 info = gtk_recent_info_new (uri);
1187 g_return_val_if_fail (info != NULL, NULL);
1189 /* fill the RecentInfo structure with the data retrieved by our
1190 * parser object from the storage file
1192 build_recent_info (priv->recent_items, info);
1198 * gtk_recent_manager_move_item:
1199 * @manager: a #GtkRecentManager
1200 * @uri: the URI of a recently used resource
1201 * @new_uri: (allow-none): the new URI of the recently used resource, or %NULL to
1202 * remove the item pointed by @uri in the list
1203 * @error: (allow-none): a return location for a #GError, or %NULL
1205 * Changes the location of a recently used resource from @uri to @new_uri.
1207 * Please note that this function will not affect the resource pointed
1208 * by the URIs, but only the URI used in the recently used resources list.
1210 * Return value: %TRUE on success.
1215 gtk_recent_manager_move_item (GtkRecentManager *recent_manager,
1217 const gchar *new_uri,
1220 GtkRecentManagerPrivate *priv;
1224 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (recent_manager), FALSE);
1225 g_return_val_if_fail (uri != NULL, FALSE);
1226 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
1228 priv = recent_manager->priv;
1230 if (!priv->recent_items)
1232 g_set_error (error, GTK_RECENT_MANAGER_ERROR,
1233 GTK_RECENT_MANAGER_ERROR_NOT_FOUND,
1234 _("Unable to find an item with URI '%s'"),
1239 if (!g_bookmark_file_has_item (priv->recent_items, uri))
1241 g_set_error (error, GTK_RECENT_MANAGER_ERROR,
1242 GTK_RECENT_MANAGER_ERROR_NOT_FOUND,
1243 _("Unable to find an item with URI '%s'"),
1249 res = g_bookmark_file_move_item (priv->recent_items,
1254 g_error_free (move_error);
1256 g_set_error (error, GTK_RECENT_MANAGER_ERROR,
1257 GTK_RECENT_MANAGER_ERROR_NOT_FOUND,
1258 _("Unable to find an item with URI '%s'"),
1263 priv->is_dirty = TRUE;
1265 gtk_recent_manager_changed (recent_manager);
1271 * gtk_recent_manager_get_items:
1272 * @manager: a #GtkRecentManager
1274 * Gets the list of recently used resources.
1276 * Return value: (element-type GtkRecentInfo) (transfer full): a list of
1277 * newly allocated #GtkRecentInfo objects. Use
1278 * gtk_recent_info_unref() on each item inside the list, and then
1279 * free the list itself using g_list_free().
1284 gtk_recent_manager_get_items (GtkRecentManager *manager)
1286 GtkRecentManagerPrivate *priv;
1287 GList *retval = NULL;
1291 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), NULL);
1293 priv = manager->priv;
1294 if (!priv->recent_items)
1297 if (priv->limit == 0)
1300 uris = g_bookmark_file_get_uris (priv->recent_items, &uris_len);
1301 for (i = 0; i < uris_len; i++)
1303 GtkRecentInfo *info;
1305 if (priv->limit != -1 && i == priv->limit)
1308 info = gtk_recent_info_new (uris[i]);
1309 build_recent_info (priv->recent_items, info);
1311 retval = g_list_prepend (retval, info);
1320 purge_recent_items_list (GtkRecentManager *manager,
1323 GtkRecentManagerPrivate *priv = manager->priv;
1325 if (!priv->recent_items)
1328 g_bookmark_file_free (priv->recent_items);
1329 priv->recent_items = NULL;
1331 priv->recent_items = g_bookmark_file_new ();
1333 priv->is_dirty = TRUE;
1335 /* emit the changed signal, to ensure that the purge is written */
1336 gtk_recent_manager_changed (manager);
1340 * gtk_recent_manager_purge_items:
1341 * @manager: a #GtkRecentManager
1342 * @error: (allow-none): a return location for a #GError, or %NULL
1344 * Purges every item from the recently used resources list.
1346 * Return value: the number of items that have been removed from the
1347 * recently used resources list.
1352 gtk_recent_manager_purge_items (GtkRecentManager *manager,
1355 GtkRecentManagerPrivate *priv;
1358 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), -1);
1360 priv = manager->priv;
1361 if (!priv->recent_items)
1364 count = g_bookmark_file_get_size (priv->recent_items);
1368 purge_recent_items_list (manager, error);
1370 purged = count - g_bookmark_file_get_size (priv->recent_items);
1376 gtk_recent_manager_changed (GtkRecentManager *recent_manager)
1378 g_signal_emit (recent_manager, signal_changed, 0);
1382 gtk_recent_manager_clamp_to_age (GtkRecentManager *manager,
1385 GtkRecentManagerPrivate *priv = manager->priv;
1390 if (G_UNLIKELY (!priv->recent_items))
1395 uris = g_bookmark_file_get_uris (priv->recent_items, &n_uris);
1397 for (i = 0; i < n_uris; i++)
1399 const gchar *uri = uris[i];
1403 modified = g_bookmark_file_get_modified (priv->recent_items, uri, NULL);
1404 item_age = (gint) ((now - modified) / (60 * 60 * 24));
1406 g_bookmark_file_remove_item (priv->recent_items, uri, NULL);
1417 gtk_recent_info_get_type (void)
1419 static GType info_type = 0;
1422 info_type = g_boxed_type_register_static (I_("GtkRecentInfo"),
1423 (GBoxedCopyFunc) gtk_recent_info_ref,
1424 (GBoxedFreeFunc) gtk_recent_info_unref);
1428 static GtkRecentInfo *
1429 gtk_recent_info_new (const gchar *uri)
1431 GtkRecentInfo *info;
1433 g_assert (uri != NULL);
1435 info = g_new0 (GtkRecentInfo, 1);
1436 info->uri = g_strdup (uri);
1438 info->applications = NULL;
1439 info->apps_lookup = g_hash_table_new (g_str_hash, g_str_equal);
1441 info->groups = NULL;
1443 info->ref_count = 1;
1449 gtk_recent_info_free (GtkRecentInfo *recent_info)
1454 g_free (recent_info->uri);
1455 g_free (recent_info->display_name);
1456 g_free (recent_info->description);
1457 g_free (recent_info->mime_type);
1459 if (recent_info->applications)
1461 g_slist_foreach (recent_info->applications,
1462 (GFunc) recent_app_info_free,
1464 g_slist_free (recent_info->applications);
1466 recent_info->applications = NULL;
1469 if (recent_info->apps_lookup)
1470 g_hash_table_destroy (recent_info->apps_lookup);
1472 if (recent_info->groups)
1474 g_slist_foreach (recent_info->groups,
1477 g_slist_free (recent_info->groups);
1479 recent_info->groups = NULL;
1482 if (recent_info->icon)
1483 g_object_unref (recent_info->icon);
1485 g_free (recent_info);
1489 * gtk_recent_info_ref:
1490 * @info: a #GtkRecentInfo
1492 * Increases the reference count of @recent_info by one.
1494 * Return value: the recent info object with its reference count increased
1500 gtk_recent_info_ref (GtkRecentInfo *info)
1502 g_return_val_if_fail (info != NULL, NULL);
1503 g_return_val_if_fail (info->ref_count > 0, NULL);
1505 info->ref_count += 1;
1511 * gtk_recent_info_unref:
1512 * @info: a #GtkRecentInfo
1514 * Decreases the reference count of @info by one. If the reference
1515 * count reaches zero, @info is deallocated, and the memory freed.
1520 gtk_recent_info_unref (GtkRecentInfo *info)
1522 g_return_if_fail (info != NULL);
1523 g_return_if_fail (info->ref_count > 0);
1525 info->ref_count -= 1;
1527 if (info->ref_count == 0)
1528 gtk_recent_info_free (info);
1532 * gtk_recent_info_get_uri:
1533 * @info: a #GtkRecentInfo
1535 * Gets the URI of the resource.
1537 * Return value: the URI of the resource. The returned string is
1538 * owned by the recent manager, and should not be freed.
1542 G_CONST_RETURN gchar *
1543 gtk_recent_info_get_uri (GtkRecentInfo *info)
1545 g_return_val_if_fail (info != NULL, NULL);
1551 * gtk_recent_info_get_display_name:
1552 * @info: a #GtkRecentInfo
1554 * Gets the name of the resource. If none has been defined, the basename
1555 * of the resource is obtained.
1557 * Return value: the display name of the resource. The returned string
1558 * is owned by the recent manager, and should not be freed.
1562 G_CONST_RETURN gchar *
1563 gtk_recent_info_get_display_name (GtkRecentInfo *info)
1565 g_return_val_if_fail (info != NULL, NULL);
1567 if (!info->display_name)
1568 info->display_name = gtk_recent_info_get_short_name (info);
1570 return info->display_name;
1574 * gtk_recent_info_get_description:
1575 * @info: a #GtkRecentInfo
1577 * Gets the (short) description of the resource.
1579 * Return value: the description of the resource. The returned string
1580 * is owned by the recent manager, and should not be freed.
1584 G_CONST_RETURN gchar *
1585 gtk_recent_info_get_description (GtkRecentInfo *info)
1587 g_return_val_if_fail (info != NULL, NULL);
1589 return info->description;
1593 * gtk_recent_info_get_mime_type:
1594 * @info: a #GtkRecentInfo
1596 * Gets the MIME type of the resource.
1598 * Return value: the MIME type of the resource. The returned string
1599 * is owned by the recent manager, and should not be freed.
1603 G_CONST_RETURN gchar *
1604 gtk_recent_info_get_mime_type (GtkRecentInfo *info)
1606 g_return_val_if_fail (info != NULL, NULL);
1608 if (!info->mime_type)
1609 info->mime_type = g_strdup (GTK_RECENT_DEFAULT_MIME);
1611 return info->mime_type;
1615 * gtk_recent_info_get_added:
1616 * @info: a #GtkRecentInfo
1618 * Gets the timestamp (seconds from system's Epoch) when the resource
1619 * was added to the recently used resources list.
1621 * Return value: the number of seconds elapsed from system's Epoch when
1622 * the resource was added to the list, or -1 on failure.
1627 gtk_recent_info_get_added (GtkRecentInfo *info)
1629 g_return_val_if_fail (info != NULL, (time_t) -1);
1635 * gtk_recent_info_get_modified:
1636 * @info: a #GtkRecentInfo
1638 * Gets the timestamp (seconds from system's Epoch) when the resource
1639 * was last modified.
1641 * Return value: the number of seconds elapsed from system's Epoch when
1642 * the resource was last modified, or -1 on failure.
1647 gtk_recent_info_get_modified (GtkRecentInfo *info)
1649 g_return_val_if_fail (info != NULL, (time_t) -1);
1651 return info->modified;
1655 * gtk_recent_info_get_visited:
1656 * @info: a #GtkRecentInfo
1658 * Gets the timestamp (seconds from system's Epoch) when the resource
1661 * Return value: the number of seconds elapsed from system's Epoch when
1662 * the resource was last visited, or -1 on failure.
1667 gtk_recent_info_get_visited (GtkRecentInfo *info)
1669 g_return_val_if_fail (info != NULL, (time_t) -1);
1671 return info->visited;
1675 * gtk_recent_info_get_private_hint:
1676 * @info: a #GtkRecentInfo
1678 * Gets the value of the "private" flag. Resources in the recently used
1679 * list that have this flag set to %TRUE should only be displayed by the
1680 * applications that have registered them.
1682 * Return value: %TRUE if the private flag was found, %FALSE otherwise.
1687 gtk_recent_info_get_private_hint (GtkRecentInfo *info)
1689 g_return_val_if_fail (info != NULL, FALSE);
1691 return info->is_private;
1695 static RecentAppInfo *
1696 recent_app_info_new (const gchar *app_name)
1698 RecentAppInfo *app_info;
1700 g_assert (app_name != NULL);
1702 app_info = g_slice_new0 (RecentAppInfo);
1703 app_info->name = g_strdup (app_name);
1704 app_info->exec = NULL;
1705 app_info->count = 1;
1706 app_info->stamp = 0;
1712 recent_app_info_free (RecentAppInfo *app_info)
1717 g_free (app_info->name);
1718 g_free (app_info->exec);
1720 g_slice_free (RecentAppInfo, app_info);
1724 * gtk_recent_info_get_application_info:
1725 * @info: a #GtkRecentInfo
1726 * @app_name: the name of the application that has registered this item
1727 * @app_exec: (transfer none) (out): return location for the string containing the command line
1728 * @count: (out): return location for the number of times this item was registered
1729 * @time_: (out): return location for the timestamp this item was last registered
1730 * for this application
1732 * Gets the data regarding the application that has registered the resource
1735 * If the command line contains any escape characters defined inside the
1736 * storage specification, they will be expanded.
1738 * Return value: %TRUE if an application with @app_name has registered this
1739 * resource inside the recently used list, or %FALSE otherwise. The
1740 * @app_exec string is owned by the #GtkRecentInfo and should not be
1746 gtk_recent_info_get_application_info (GtkRecentInfo *info,
1747 const gchar *app_name,
1748 const gchar **app_exec,
1754 g_return_val_if_fail (info != NULL, FALSE);
1755 g_return_val_if_fail (app_name != NULL, FALSE);
1757 ai = (RecentAppInfo *) g_hash_table_lookup (info->apps_lookup,
1761 g_warning ("No registered application with name '%s' "
1762 "for item with URI '%s' found",
1769 *app_exec = ai->exec;
1781 * gtk_recent_info_get_applications:
1782 * @info: a #GtkRecentInfo
1783 * @length: (out) (allow-none): return location for the length of the returned list
1785 * Retrieves the list of applications that have registered this resource.
1787 * Return value: (array length=length zero-terminated=1): a newly allocated
1788 * %NULL-terminated array of strings. Use g_strfreev() to free it.
1793 gtk_recent_info_get_applications (GtkRecentInfo *info,
1800 g_return_val_if_fail (info != NULL, NULL);
1802 if (!info->applications)
1810 n_apps = g_slist_length (info->applications);
1812 retval = g_new0 (gchar *, n_apps + 1);
1814 for (l = info->applications, i = 0;
1818 RecentAppInfo *ai = (RecentAppInfo *) l->data;
1820 g_assert (ai != NULL);
1822 retval[i++] = g_strdup (ai->name);
1833 * gtk_recent_info_has_application:
1834 * @info: a #GtkRecentInfo
1835 * @app_name: a string containing an application name
1837 * Checks whether an application registered this resource using @app_name.
1839 * Return value: %TRUE if an application with name @app_name was found,
1845 gtk_recent_info_has_application (GtkRecentInfo *info,
1846 const gchar *app_name)
1848 g_return_val_if_fail (info != NULL, FALSE);
1849 g_return_val_if_fail (app_name != NULL, FALSE);
1851 return (NULL != g_hash_table_lookup (info->apps_lookup, app_name));
1855 * gtk_recent_info_last_application:
1856 * @info: a #GtkRecentInfo
1858 * Gets the name of the last application that have registered the
1859 * recently used resource represented by @info.
1861 * Return value: an application name. Use g_free() to free it.
1866 gtk_recent_info_last_application (GtkRecentInfo *info)
1869 time_t last_stamp = (time_t) -1;
1872 g_return_val_if_fail (info != NULL, NULL);
1874 for (l = info->applications; l != NULL; l = l->next)
1876 RecentAppInfo *ai = (RecentAppInfo *) l->data;
1878 if (ai->stamp > last_stamp)
1881 last_stamp = ai->stamp;
1885 return g_strdup (name);
1889 get_icon_for_mime_type (const char *mime_type,
1892 GtkIconTheme *icon_theme;
1898 icon_theme = gtk_icon_theme_get_default ();
1900 content_type = g_content_type_from_mime_type (mime_type);
1905 icon = g_content_type_get_icon (content_type);
1906 info = gtk_icon_theme_lookup_by_gicon (icon_theme,
1909 GTK_ICON_LOOKUP_USE_BUILTIN);
1910 g_free (content_type);
1911 g_object_unref (icon);
1916 pixbuf = gtk_icon_info_load_icon (info, NULL);
1917 gtk_icon_info_free (info);
1923 get_icon_fallback (const gchar *icon_name,
1926 GtkIconTheme *icon_theme;
1929 icon_theme = gtk_icon_theme_get_default ();
1931 retval = gtk_icon_theme_load_icon (icon_theme, icon_name,
1933 GTK_ICON_LOOKUP_USE_BUILTIN,
1935 g_assert (retval != NULL);
1941 * gtk_recent_info_get_icon:
1942 * @info: a #GtkRecentInfo
1943 * @size: the size of the icon in pixels
1945 * Retrieves the icon of size @size associated to the resource MIME type.
1947 * Return value: a #GdkPixbuf containing the icon, or %NULL. Use
1948 * g_object_unref() when finished using the icon.
1953 gtk_recent_info_get_icon (GtkRecentInfo *info,
1956 GdkPixbuf *retval = NULL;
1958 g_return_val_if_fail (info != NULL, NULL);
1960 if (info->mime_type)
1961 retval = get_icon_for_mime_type (info->mime_type, size);
1963 /* this function should never fail */
1966 if (info->mime_type &&
1967 strcmp (info->mime_type, "x-directory/normal") == 0)
1968 retval = get_icon_fallback (GTK_STOCK_DIRECTORY, size);
1970 retval = get_icon_fallback (GTK_STOCK_FILE, size);
1977 * gtk_recent_info_is_local:
1978 * @info: a #GtkRecentInfo
1980 * Checks whether the resource is local or not by looking at the
1981 * scheme of its URI.
1983 * Return value: %TRUE if the resource is local.
1988 gtk_recent_info_is_local (GtkRecentInfo *info)
1990 g_return_val_if_fail (info != NULL, FALSE);
1992 return has_case_prefix (info->uri, "file:/");
1996 * gtk_recent_info_exists:
1997 * @info: a #GtkRecentInfo
1999 * Checks whether the resource pointed by @info still exists. At
2000 * the moment this check is done only on resources pointing to local files.
2002 * Return value: %TRUE if the resource exists
2007 gtk_recent_info_exists (GtkRecentInfo *info)
2010 struct stat stat_buf;
2011 gboolean retval = FALSE;
2013 g_return_val_if_fail (info != NULL, FALSE);
2015 /* we guarantee only local resources */
2016 if (!gtk_recent_info_is_local (info))
2019 filename = g_filename_from_uri (info->uri, NULL, NULL);
2022 if (stat (filename, &stat_buf) == 0)
2032 * gtk_recent_info_match:
2033 * @info_a: a #GtkRecentInfo
2034 * @info_b: a #GtkRecentInfo
2036 * Checks whether two #GtkRecentInfo structures point to the same
2039 * Return value: %TRUE if both #GtkRecentInfo structures point to se same
2040 * resource, %FALSE otherwise.
2045 gtk_recent_info_match (GtkRecentInfo *info_a,
2046 GtkRecentInfo *info_b)
2048 g_return_val_if_fail (info_a != NULL, FALSE);
2049 g_return_val_if_fail (info_b != NULL, FALSE);
2051 return (0 == strcmp (info_a->uri, info_b->uri));
2054 /* taken from gnome-vfs-uri.c */
2055 static const gchar *
2056 get_method_string (const gchar *substring,
2057 gchar **method_string)
2063 g_ascii_isalnum (*p) || *p == '+' || *p == '-' || *p == '.';
2070 !(p == substring + 1 && g_ascii_isalpha (*substring))
2074 /* Found toplevel method specification. */
2075 method = g_strndup (substring, p - substring);
2076 *method_string = g_ascii_strdown (method, -1);
2082 *method_string = g_strdup ("file");
2089 /* Stolen from gnome_vfs_make_valid_utf8() */
2091 make_valid_utf8 (const char *name)
2094 const char *remainder, *invalid;
2095 int remaining_bytes, valid_bytes;
2099 remaining_bytes = name ? strlen (name) : 0;
2101 while (remaining_bytes != 0)
2103 if (g_utf8_validate (remainder, remaining_bytes, &invalid))
2106 valid_bytes = invalid - remainder;
2109 string = g_string_sized_new (remaining_bytes);
2111 g_string_append_len (string, remainder, valid_bytes);
2112 g_string_append_c (string, '?');
2114 remaining_bytes -= valid_bytes + 1;
2115 remainder = invalid + 1;
2119 return g_strdup (name);
2121 g_string_append (string, remainder);
2122 g_assert (g_utf8_validate (string->str, -1, NULL));
2124 return g_string_free (string, FALSE);
2128 get_uri_shortname_for_display (const gchar *uri)
2131 gboolean validated = FALSE;
2133 if (has_case_prefix (uri, "file:/"))
2137 local_file = g_filename_from_uri (uri, NULL, NULL);
2141 name = g_filename_display_basename (local_file);
2145 g_free (local_file);
2154 rest = get_method_string (uri, &method);
2155 local_file = g_filename_display_basename (rest);
2157 name = g_strconcat (method, ": ", local_file, NULL);
2159 g_free (local_file);
2163 g_assert (name != NULL);
2165 if (!validated && !g_utf8_validate (name, -1, NULL))
2169 utf8_name = make_valid_utf8 (name);
2179 * gtk_recent_info_get_short_name:
2180 * @info: an #GtkRecentInfo
2182 * Computes a valid UTF-8 string that can be used as the name of the item in a
2183 * menu or list. For example, calling this function on an item that refers to
2184 * "file:///foo/bar.txt" will yield "bar.txt".
2186 * Return value: A newly-allocated string in UTF-8 encoding; free it with
2192 gtk_recent_info_get_short_name (GtkRecentInfo *info)
2196 g_return_val_if_fail (info != NULL, NULL);
2198 if (info->uri == NULL)
2201 short_name = get_uri_shortname_for_display (info->uri);
2207 * gtk_recent_info_get_uri_display:
2208 * @info: a #GtkRecentInfo
2210 * Gets a displayable version of the resource's URI. If the resource
2211 * is local, it returns a local path; if the resource is not local,
2212 * it returns the UTF-8 encoded content of gtk_recent_info_get_uri().
2214 * Return value: a newly allocated UTF-8 string containing the
2215 * resource's URI or %NULL. Use g_free() when done using it.
2220 gtk_recent_info_get_uri_display (GtkRecentInfo *info)
2224 g_return_val_if_fail (info != NULL, NULL);
2227 if (gtk_recent_info_is_local (info))
2231 filename = g_filename_from_uri (info->uri, NULL, NULL);
2235 retval = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
2240 retval = make_valid_utf8 (info->uri);
2247 * gtk_recent_info_get_age:
2248 * @info: a #GtkRecentInfo
2250 * Gets the number of days elapsed since the last update of the resource
2253 * Return value: a positive integer containing the number of days elapsed
2254 * since the time this resource was last modified.
2259 gtk_recent_info_get_age (GtkRecentInfo *info)
2264 g_return_val_if_fail (info != NULL, -1);
2268 delta = now - info->modified;
2270 retval = (gint) (delta / (60 * 60 * 24));
2276 * gtk_recent_info_get_groups:
2277 * @info: a #GtkRecentInfo
2278 * @length: (out) (allow-none): return location for the number of groups returned
2280 * Returns all groups registered for the recently used item @info. The
2281 * array of returned group names will be %NULL terminated, so length might
2282 * optionally be %NULL.
2284 * Return value: (array length=length zero-terminated=1): a newly allocated
2285 * %NULL terminated array of strings. Use g_strfreev() to free it.
2290 gtk_recent_info_get_groups (GtkRecentInfo *info,
2297 g_return_val_if_fail (info != NULL, NULL);
2307 n_groups = g_slist_length (info->groups);
2309 retval = g_new0 (gchar *, n_groups + 1);
2311 for (l = info->groups, i = 0;
2315 gchar *group_name = (gchar *) l->data;
2317 g_assert (group_name != NULL);
2319 retval[i++] = g_strdup (group_name);
2330 * gtk_recent_info_has_group:
2331 * @info: a #GtkRecentInfo
2332 * @group_name: name of a group
2334 * Checks whether @group_name appears inside the groups registered for the
2335 * recently used item @info.
2337 * Return value: %TRUE if the group was found.
2342 gtk_recent_info_has_group (GtkRecentInfo *info,
2343 const gchar *group_name)
2347 g_return_val_if_fail (info != NULL, FALSE);
2348 g_return_val_if_fail (group_name != NULL, FALSE);
2353 for (l = info->groups; l != NULL; l = l->next)
2355 gchar *g = (gchar *) l->data;
2357 if (strcmp (g, group_name) == 0)
2365 * _gtk_recent_manager_sync:
2367 * Private function for synchronising the recent manager singleton.
2370 _gtk_recent_manager_sync (void)
2372 if (recent_manager_singleton)
2374 /* force a dump of the contents of the recent manager singleton */
2375 recent_manager_singleton->priv->is_dirty = TRUE;
2376 gtk_recent_manager_real_changed (recent_manager_singleton);
2380 #define __GTK_RECENT_MANAGER_C__
2381 #include "gtkaliasdef.c"