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 /* mark us as clean */
420 priv->is_dirty = FALSE;
424 /* we are not marked as dirty, so we have been called
425 * because the recently used resources file has been
426 * changed (and not from us).
428 build_recent_items_list (manager);
431 g_object_thaw_notify (G_OBJECT (manager));
435 gtk_recent_manager_monitor_changed (GFileMonitor *monitor,
438 GFileMonitorEvent event_type,
441 GtkRecentManager *manager = user_data;
445 case G_FILE_MONITOR_EVENT_CHANGED:
446 case G_FILE_MONITOR_EVENT_CREATED:
447 gtk_recent_manager_changed (manager);
450 case G_FILE_MONITOR_EVENT_DELETED:
459 gtk_recent_manager_set_filename (GtkRecentManager *manager,
460 const gchar *filename)
462 GtkRecentManagerPrivate *priv;
466 g_assert (GTK_IS_RECENT_MANAGER (manager));
468 priv = manager->priv;
470 /* if a filename is already set and filename is not NULL, then copy
471 * it and reset the monitor; otherwise, if it's NULL we're being
472 * called from the finalization sequence, so we simply disconnect the
473 * monitoring and return.
475 * if no filename is set and filename is NULL, use the default.
479 g_free (priv->filename);
483 g_signal_handlers_disconnect_by_func (priv->monitor,
484 G_CALLBACK (gtk_recent_manager_monitor_changed),
486 g_object_unref (priv->monitor);
487 priv->monitor = NULL;
490 if (!filename || *filename == '\0')
493 priv->filename = g_strdup (filename);
497 if (!filename || *filename == '\0')
498 priv->filename = g_build_filename (g_get_home_dir (),
499 GTK_RECENTLY_USED_FILE,
502 priv->filename = g_strdup (filename);
505 g_assert (priv->filename != NULL);
506 file = g_file_new_for_path (priv->filename);
509 priv->monitor = g_file_monitor_file (file, G_FILE_MONITOR_NONE, NULL, &error);
512 filename_warning ("Unable to monitor `%s': %s\n"
513 "The GtkRecentManager will not update its contents "
514 "if the file is changed from other instances",
517 g_error_free (error);
520 g_signal_connect (priv->monitor, "changed",
521 G_CALLBACK (gtk_recent_manager_monitor_changed),
524 g_object_unref (file);
526 priv->is_dirty = FALSE;
527 build_recent_items_list (manager);
530 /* reads the recently used resources file and builds the items list.
531 * we keep the items list inside the parser object, and build the
532 * RecentInfo object only on user's demand to avoid useless replication.
533 * this function resets the dirty bit of the manager.
536 build_recent_items_list (GtkRecentManager *manager)
538 GtkRecentManagerPrivate *priv = manager->priv;
542 g_assert (priv->filename != NULL);
544 if (!priv->recent_items)
546 priv->recent_items = g_bookmark_file_new ();
550 /* the file exists, and it's valid (we hope); if not, destroy the container
551 * object and hope for a better result when the next "changed" signal is
554 g_bookmark_file_load_from_file (priv->recent_items, priv->filename, &read_error);
557 /* if the file does not exist we just wait for the first write
558 * operation on this recent manager instance, to avoid creating
559 * empty files and leading to spurious file system events (Sabayon
560 * will not be happy about those)
562 if (read_error->domain == G_FILE_ERROR &&
563 read_error->code != G_FILE_ERROR_NOENT)
564 filename_warning ("Attempting to read the recently used resources "
565 "file at `%s', but the parser failed: %s.",
567 read_error->message);
569 g_bookmark_file_free (priv->recent_items);
570 priv->recent_items = NULL;
572 g_error_free (read_error);
576 size = g_bookmark_file_get_size (priv->recent_items);
577 if (priv->size != size)
581 g_object_notify (G_OBJECT (manager), "size");
585 priv->is_dirty = FALSE;
589 /********************
591 ********************/
595 * gtk_recent_manager_new:
597 * Creates a new recent manager object. Recent manager objects are used to
598 * handle the list of recently used resources. A #GtkRecentManager object
599 * monitors the recently used resources list, and emits the "changed" signal
600 * each time something inside the list changes.
602 * #GtkRecentManager objects are expensive: be sure to create them only when
603 * needed. You should use gtk_recent_manager_get_default() instead.
605 * Return value: A newly created #GtkRecentManager object.
610 gtk_recent_manager_new (void)
612 return g_object_new (GTK_TYPE_RECENT_MANAGER, NULL);
616 * gtk_recent_manager_get_default:
618 * Gets a unique instance of #GtkRecentManager, that you can share
619 * in your application without caring about memory management. The
620 * returned instance will be freed when you application terminates.
622 * Return value: A unique #GtkRecentManager. Do not ref or unref it.
627 gtk_recent_manager_get_default (void)
629 if (G_UNLIKELY (!recent_manager_singleton))
630 recent_manager_singleton = gtk_recent_manager_new ();
632 return recent_manager_singleton;
636 * gtk_recent_manager_get_for_screen:
637 * @screen: a #GdkScreen
639 * Gets the recent manager object associated with @screen; if this
640 * function has not previously been called for the given screen,
641 * a new recent manager object will be created and associated with
642 * the screen. Recent manager objects are fairly expensive to create,
643 * so using this function is usually a better choice than calling
644 * gtk_recent_manager_new() and setting the screen yourself; by using
645 * this function a single recent manager object will be shared between
648 * Return value: A unique #GtkRecentManager associated with the given
649 * screen. This recent manager is associated to the with the screen
650 * and can be used as long as the screen is open. Do not ref or
653 * Deprecated: 2.12: This function has been deprecated and should
654 * not be used in newly written code. Calling this function is
655 * equivalent to calling gtk_recent_manager_get_default().
660 gtk_recent_manager_get_for_screen (GdkScreen *screen)
662 return gtk_recent_manager_get_default ();
666 * gtk_recent_manager_set_screen:
667 * @manager: a #GtkRecentManager
668 * @screen: a #GdkScreen
670 * Sets the screen for a recent manager; the screen is used to
671 * track the user's currently configured recently used documents
676 * Deprecated: 2.12: This function has been deprecated and should
677 * not be used in newly written code. Calling this function has
681 gtk_recent_manager_set_screen (GtkRecentManager *manager,
688 * gtk_recent_manager_set_limit:
689 * @manager: a #GtkRecentManager
690 * @limit: the maximum number of items to return, or -1.
692 * Sets the maximum number of item that the gtk_recent_manager_get_items()
693 * function should return. If @limit is set to -1, then return all the
699 gtk_recent_manager_set_limit (GtkRecentManager *manager,
702 GtkRecentManagerPrivate *priv;
704 g_return_if_fail (GTK_IS_RECENT_MANAGER (manager));
706 priv = manager->priv;
711 * gtk_recent_manager_get_limit:
712 * @manager: a #GtkRecentManager
714 * Gets the maximum number of items that the gtk_recent_manager_get_items()
715 * function should return.
717 * Return value: the number of items to return, or -1 for every item.
722 gtk_recent_manager_get_limit (GtkRecentManager *manager)
724 GtkRecentManagerPrivate *priv;
726 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), DEFAULT_LIMIT);
728 priv = manager->priv;
733 gtk_recent_manager_add_item_query_info (GObject *source_object,
737 GFile *file = G_FILE (source_object);
738 GtkRecentManager *manager = user_data;
739 GtkRecentData recent_data;
740 GFileInfo *file_info;
744 uri = g_file_get_uri (file);
747 file_info = g_file_query_info_finish (file, res, &error);
750 g_warning ("Unable to retrieve the file info for `%s': %s",
753 g_error_free (error);
757 recent_data.display_name = NULL;
758 recent_data.description = NULL;
764 content_type = g_file_info_get_attribute_as_string (file_info, G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE);
766 if (G_LIKELY (content_type))
767 recent_data.mime_type = g_content_type_get_mime_type (content_type);
769 recent_data.mime_type = g_strdup (GTK_RECENT_DEFAULT_MIME);
771 g_free (content_type);
772 g_object_unref (file_info);
775 recent_data.mime_type = g_strdup (GTK_RECENT_DEFAULT_MIME);
777 recent_data.app_name = g_strdup (g_get_application_name ());
778 recent_data.app_exec = g_strjoin (" ", g_get_prgname (), "%u", NULL);
779 recent_data.groups = NULL;
780 recent_data.is_private = FALSE;
782 /* Ignore return value, this can't fail anyway since all required
784 gtk_recent_manager_add_full (manager, uri, &recent_data);
786 manager->priv->is_dirty = TRUE;
787 gtk_recent_manager_changed (manager);
789 g_free (recent_data.mime_type);
790 g_free (recent_data.app_name);
791 g_free (recent_data.app_exec);
794 g_object_unref (manager);
799 * gtk_recent_manager_add_item:
800 * @manager: a #GtkRecentManager
803 * Adds a new resource, pointed by @uri, into the recently used
806 * This function automatically retrieves some of the needed
807 * metadata and setting other metadata to common default values; it
808 * then feeds the data to gtk_recent_manager_add_full().
810 * See gtk_recent_manager_add_full() if you want to explicitly
811 * define the metadata for the resource pointed by @uri.
813 * Return value: %TRUE if the new item was successfully added
814 * to the recently used resources list
819 gtk_recent_manager_add_item (GtkRecentManager *manager,
824 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), FALSE);
825 g_return_val_if_fail (uri != NULL, FALSE);
827 file = g_file_new_for_uri (uri);
829 g_file_query_info_async (file,
830 G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE,
832 G_FILE_QUERY_INFO_NONE,
834 gtk_recent_manager_add_item_query_info,
835 g_object_ref (manager));
837 g_object_unref (file);
843 * gtk_recent_manager_add_full:
844 * @manager: a #GtkRecentManager
846 * @recent_data: metadata of the resource
848 * Adds a new resource, pointed by @uri, into the recently used
849 * resources list, using the metadata specified inside the #GtkRecentData
850 * structure passed in @recent_data.
852 * The passed URI will be used to identify this resource inside the
855 * In order to register the new recently used resource, metadata about
856 * the resource must be passed as well as the URI; the metadata is
857 * stored in a #GtkRecentData structure, which must contain the MIME
858 * type of the resource pointed by the URI; the name of the application
859 * that is registering the item, and a command line to be used when
860 * launching the item.
862 * Optionally, a #GtkRecentData structure might contain a UTF-8 string
863 * to be used when viewing the item instead of the last component of the
864 * URI; a short description of the item; whether the item should be
865 * considered private - that is, should be displayed only by the
866 * applications that have registered it.
868 * Return value: %TRUE if the new item was successfully added to the
869 * recently used resources list, %FALSE otherwise.
874 gtk_recent_manager_add_full (GtkRecentManager *manager,
876 const GtkRecentData *data)
878 GtkRecentManagerPrivate *priv;
880 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), FALSE);
881 g_return_val_if_fail (uri != NULL, FALSE);
882 g_return_val_if_fail (data != NULL, FALSE);
885 if ((data->display_name) &&
886 (!g_utf8_validate (data->display_name, -1, NULL)))
888 g_warning ("Attempting to add `%s' to the list of recently used "
889 "resources, but the display name is not a valid UTF-8 "
895 if ((data->description) &&
896 (!g_utf8_validate (data->description, -1, NULL)))
898 g_warning ("Attempting to add `%s' to the list of recently used "
899 "resources, but the description is not a valid UTF-8 "
906 if (!data->mime_type)
908 g_warning ("Attempting to add `%s' to the list of recently used "
909 "resources, but not MIME type was defined",
916 g_warning ("Attempting to add `%s' to the list of recently used "
917 "resources, but no name of the application that is "
918 "registering it was defined",
925 g_warning ("Attempting to add `%s' to the list of recently used "
926 "resources, but no command line for the application "
927 "that is registering it was defined",
932 priv = manager->priv;
934 if (!priv->recent_items)
936 priv->recent_items = g_bookmark_file_new ();
940 if (data->display_name)
941 g_bookmark_file_set_title (priv->recent_items, uri, data->display_name);
943 if (data->description)
944 g_bookmark_file_set_description (priv->recent_items, uri, data->description);
946 g_bookmark_file_set_mime_type (priv->recent_items, uri, data->mime_type);
948 if (data->groups && data->groups[0] != '\0')
952 for (j = 0; (data->groups)[j] != NULL; j++)
953 g_bookmark_file_add_group (priv->recent_items, uri, (data->groups)[j]);
956 /* register the application; this will take care of updating the
957 * registration count and time in case the application has
958 * already registered the same document inside the list
960 g_bookmark_file_add_application (priv->recent_items, uri,
964 g_bookmark_file_set_is_private (priv->recent_items, uri,
967 /* mark us as dirty, so that when emitting the "changed" signal we
968 * will dump our changes
970 priv->is_dirty = TRUE;
972 gtk_recent_manager_changed (manager);
978 * gtk_recent_manager_remove_item:
979 * @manager: a #GtkRecentManager
980 * @uri: the URI of the item you wish to remove
981 * @error: return location for a #GError, or %NULL
983 * Removes a resource pointed by @uri from the recently used resources
984 * list handled by a recent manager.
986 * Return value: %TRUE if the item pointed by @uri has been successfully
987 * removed by the recently used resources list, and %FALSE otherwise.
992 gtk_recent_manager_remove_item (GtkRecentManager *manager,
996 GtkRecentManagerPrivate *priv;
997 GError *remove_error = NULL;
999 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), FALSE);
1000 g_return_val_if_fail (uri != NULL, FALSE);
1001 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
1003 priv = manager->priv;
1005 if (!priv->recent_items)
1007 priv->recent_items = g_bookmark_file_new ();
1010 g_set_error (error, GTK_RECENT_MANAGER_ERROR,
1011 GTK_RECENT_MANAGER_ERROR_NOT_FOUND,
1012 _("Unable to find an item with URI '%s'"),
1018 g_bookmark_file_remove_item (priv->recent_items, uri, &remove_error);
1021 g_error_free (remove_error);
1023 g_set_error (error, GTK_RECENT_MANAGER_ERROR,
1024 GTK_RECENT_MANAGER_ERROR_NOT_FOUND,
1025 _("Unable to find an item with URI '%s'"),
1031 priv->is_dirty = TRUE;
1033 gtk_recent_manager_changed (manager);
1039 * gtk_recent_manager_has_item:
1040 * @manager: a #GtkRecentManager
1043 * Checks whether there is a recently used resource registered
1044 * with @uri inside the recent manager.
1046 * Return value: %TRUE if the resource was found, %FALSE otherwise.
1051 gtk_recent_manager_has_item (GtkRecentManager *manager,
1054 GtkRecentManagerPrivate *priv;
1056 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), FALSE);
1057 g_return_val_if_fail (uri != NULL, FALSE);
1059 priv = manager->priv;
1060 g_return_val_if_fail (priv->recent_items != NULL, FALSE);
1062 return g_bookmark_file_has_item (priv->recent_items, uri);
1066 build_recent_info (GBookmarkFile *bookmarks,
1067 GtkRecentInfo *info)
1069 gchar **apps, **groups;
1070 gsize apps_len, groups_len, i;
1072 g_assert (bookmarks != NULL);
1073 g_assert (info != NULL);
1075 info->display_name = g_bookmark_file_get_title (bookmarks, info->uri, NULL);
1076 info->description = g_bookmark_file_get_description (bookmarks, info->uri, NULL);
1077 info->mime_type = g_bookmark_file_get_mime_type (bookmarks, info->uri, NULL);
1079 info->is_private = g_bookmark_file_get_is_private (bookmarks, info->uri, NULL);
1081 info->added = g_bookmark_file_get_added (bookmarks, info->uri, NULL);
1082 info->modified = g_bookmark_file_get_modified (bookmarks, info->uri, NULL);
1083 info->visited = g_bookmark_file_get_visited (bookmarks, info->uri, NULL);
1085 groups = g_bookmark_file_get_groups (bookmarks, info->uri, &groups_len, NULL);
1086 for (i = 0; i < groups_len; i++)
1088 gchar *group_name = g_strdup (groups[i]);
1090 info->groups = g_slist_append (info->groups, group_name);
1093 g_strfreev (groups);
1095 apps = g_bookmark_file_get_applications (bookmarks, info->uri, &apps_len, NULL);
1096 for (i = 0; i < apps_len; i++)
1098 gchar *app_name, *app_exec;
1101 RecentAppInfo *app_info;
1106 res = g_bookmark_file_get_app_info (bookmarks, info->uri, app_name,
1114 app_info = recent_app_info_new (app_name);
1115 app_info->exec = app_exec;
1116 app_info->count = count;
1117 app_info->stamp = stamp;
1119 info->applications = g_slist_prepend (info->applications, app_info);
1120 g_hash_table_replace (info->apps_lookup, app_info->name, app_info);
1127 * gtk_recent_manager_lookup_item:
1128 * @manager: a #GtkRecentManager
1130 * @error: a return location for a #GError, or %NULL
1132 * Searches for a URI inside the recently used resources list, and
1133 * returns a structure containing informations about the resource
1134 * like its MIME type, or its display name.
1136 * Return value: a #GtkRecentInfo structure containing information
1137 * about the resource pointed by @uri, or %NULL if the URI was
1138 * not registered in the recently used resources list. Free with
1139 * gtk_recent_info_unref().
1144 gtk_recent_manager_lookup_item (GtkRecentManager *manager,
1148 GtkRecentManagerPrivate *priv;
1149 GtkRecentInfo *info = NULL;
1151 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), NULL);
1152 g_return_val_if_fail (uri != NULL, NULL);
1153 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
1155 priv = manager->priv;
1156 if (!priv->recent_items)
1158 priv->recent_items = g_bookmark_file_new ();
1161 g_set_error (error, GTK_RECENT_MANAGER_ERROR,
1162 GTK_RECENT_MANAGER_ERROR_NOT_FOUND,
1163 _("Unable to find an item with URI '%s'"),
1169 if (!g_bookmark_file_has_item (priv->recent_items, uri))
1171 g_set_error (error, GTK_RECENT_MANAGER_ERROR,
1172 GTK_RECENT_MANAGER_ERROR_NOT_FOUND,
1173 _("Unable to find an item with URI '%s'"),
1178 info = gtk_recent_info_new (uri);
1179 g_return_val_if_fail (info != NULL, NULL);
1181 /* fill the RecentInfo structure with the data retrieved by our
1182 * parser object from the storage file
1184 build_recent_info (priv->recent_items, info);
1190 * gtk_recent_manager_move_item:
1191 * @manager: a #GtkRecentManager
1192 * @uri: the URI of a recently used resource
1193 * @new_uri: the new URI of the recently used resource, or %NULL to
1194 * remove the item pointed by @uri in the list
1195 * @error: a return location for a #GError, or %NULL
1197 * Changes the location of a recently used resource from @uri to @new_uri.
1199 * Please note that this function will not affect the resource pointed
1200 * by the URIs, but only the URI used in the recently used resources list.
1202 * Return value: %TRUE on success.
1207 gtk_recent_manager_move_item (GtkRecentManager *recent_manager,
1209 const gchar *new_uri,
1212 GtkRecentManagerPrivate *priv;
1216 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (recent_manager), FALSE);
1217 g_return_val_if_fail (uri != NULL, FALSE);
1218 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
1220 priv = recent_manager->priv;
1222 if (!priv->recent_items)
1224 g_set_error (error, GTK_RECENT_MANAGER_ERROR,
1225 GTK_RECENT_MANAGER_ERROR_NOT_FOUND,
1226 _("Unable to find an item with URI '%s'"),
1231 if (!g_bookmark_file_has_item (priv->recent_items, uri))
1233 g_set_error (error, GTK_RECENT_MANAGER_ERROR,
1234 GTK_RECENT_MANAGER_ERROR_NOT_FOUND,
1235 _("Unable to find an item with URI '%s'"),
1241 res = g_bookmark_file_move_item (priv->recent_items,
1246 g_error_free (move_error);
1248 g_set_error (error, GTK_RECENT_MANAGER_ERROR,
1249 GTK_RECENT_MANAGER_ERROR_NOT_FOUND,
1250 _("Unable to find an item with URI '%s'"),
1255 priv->is_dirty = TRUE;
1257 gtk_recent_manager_changed (recent_manager);
1263 * gtk_recent_manager_get_items:
1264 * @manager: a #GtkRecentManager
1266 * Gets the list of recently used resources.
1268 * Return value: a list of newly allocated #GtkRecentInfo objects. Use
1269 * gtk_recent_info_unref() on each item inside the list, and then
1270 * free the list itself using g_list_free().
1275 gtk_recent_manager_get_items (GtkRecentManager *manager)
1277 GtkRecentManagerPrivate *priv;
1278 GList *retval = NULL;
1282 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), NULL);
1284 priv = manager->priv;
1285 if (!priv->recent_items)
1288 if (priv->limit == 0)
1291 uris = g_bookmark_file_get_uris (priv->recent_items, &uris_len);
1292 for (i = 0; i < uris_len; i++)
1294 GtkRecentInfo *info;
1296 if (priv->limit != -1 && i == priv->limit)
1299 info = gtk_recent_info_new (uris[i]);
1300 build_recent_info (priv->recent_items, info);
1302 retval = g_list_prepend (retval, info);
1311 purge_recent_items_list (GtkRecentManager *manager,
1314 GtkRecentManagerPrivate *priv = manager->priv;
1316 if (!priv->recent_items)
1319 g_bookmark_file_free (priv->recent_items);
1320 priv->recent_items = NULL;
1322 priv->recent_items = g_bookmark_file_new ();
1324 priv->is_dirty = TRUE;
1326 /* emit the changed signal, to ensure that the purge is written */
1327 gtk_recent_manager_changed (manager);
1331 * gtk_recent_manager_purge_items:
1332 * @manager: a #GtkRecentManager
1333 * @error: a return location for a #GError, or %NULL
1335 * Purges every item from the recently used resources list.
1337 * Return value: the number of items that have been removed from the
1338 * recently used resources list.
1343 gtk_recent_manager_purge_items (GtkRecentManager *manager,
1346 GtkRecentManagerPrivate *priv;
1349 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), -1);
1351 priv = manager->priv;
1352 if (!priv->recent_items)
1355 count = g_bookmark_file_get_size (priv->recent_items);
1359 purge_recent_items_list (manager, error);
1361 purged = count - g_bookmark_file_get_size (priv->recent_items);
1367 gtk_recent_manager_changed (GtkRecentManager *recent_manager)
1369 g_signal_emit (recent_manager, signal_changed, 0);
1373 gtk_recent_manager_clamp_to_age (GtkRecentManager *manager,
1376 GtkRecentManagerPrivate *priv = manager->priv;
1381 if (G_UNLIKELY (!priv->recent_items))
1386 uris = g_bookmark_file_get_uris (priv->recent_items, &n_uris);
1388 for (i = 0; i < n_uris; i++)
1390 const gchar *uri = uris[i];
1394 modified = g_bookmark_file_get_modified (priv->recent_items, uri, NULL);
1395 item_age = (gint) ((now - modified) / (60 * 60 * 24));
1397 g_bookmark_file_remove_item (priv->recent_items, uri, NULL);
1408 gtk_recent_info_get_type (void)
1410 static GType info_type = 0;
1413 info_type = g_boxed_type_register_static (I_("GtkRecentInfo"),
1414 (GBoxedCopyFunc) gtk_recent_info_ref,
1415 (GBoxedFreeFunc) gtk_recent_info_unref);
1419 static GtkRecentInfo *
1420 gtk_recent_info_new (const gchar *uri)
1422 GtkRecentInfo *info;
1424 g_assert (uri != NULL);
1426 info = g_new0 (GtkRecentInfo, 1);
1427 info->uri = g_strdup (uri);
1429 info->applications = NULL;
1430 info->apps_lookup = g_hash_table_new (g_str_hash, g_str_equal);
1432 info->groups = NULL;
1434 info->ref_count = 1;
1440 gtk_recent_info_free (GtkRecentInfo *recent_info)
1445 g_free (recent_info->uri);
1446 g_free (recent_info->display_name);
1447 g_free (recent_info->description);
1448 g_free (recent_info->mime_type);
1450 if (recent_info->applications)
1452 g_slist_foreach (recent_info->applications,
1453 (GFunc) recent_app_info_free,
1455 g_slist_free (recent_info->applications);
1457 recent_info->applications = NULL;
1460 if (recent_info->apps_lookup)
1461 g_hash_table_destroy (recent_info->apps_lookup);
1463 if (recent_info->groups)
1465 g_slist_foreach (recent_info->groups,
1468 g_slist_free (recent_info->groups);
1470 recent_info->groups = NULL;
1473 if (recent_info->icon)
1474 g_object_unref (recent_info->icon);
1476 g_free (recent_info);
1480 * gtk_recent_info_ref:
1481 * @info: a #GtkRecentInfo
1483 * Increases the reference count of @recent_info by one.
1485 * Return value: the recent info object with its reference count increased
1491 gtk_recent_info_ref (GtkRecentInfo *info)
1493 g_return_val_if_fail (info != NULL, NULL);
1494 g_return_val_if_fail (info->ref_count > 0, NULL);
1496 info->ref_count += 1;
1502 * gtk_recent_info_unref:
1503 * @info: a #GtkRecentInfo
1505 * Decreases the reference count of @info by one. If the reference
1506 * count reaches zero, @info is deallocated, and the memory freed.
1511 gtk_recent_info_unref (GtkRecentInfo *info)
1513 g_return_if_fail (info != NULL);
1514 g_return_if_fail (info->ref_count > 0);
1516 info->ref_count -= 1;
1518 if (info->ref_count == 0)
1519 gtk_recent_info_free (info);
1523 * gtk_recent_info_get_uri:
1524 * @info: a #GtkRecentInfo
1526 * Gets the URI of the resource.
1528 * Return value: the URI of the resource. The returned string is
1529 * owned by the recent manager, and should not be freed.
1533 G_CONST_RETURN gchar *
1534 gtk_recent_info_get_uri (GtkRecentInfo *info)
1536 g_return_val_if_fail (info != NULL, NULL);
1542 * gtk_recent_info_get_display_name:
1543 * @info: a #GtkRecentInfo
1545 * Gets the name of the resource. If none has been defined, the basename
1546 * of the resource is obtained.
1548 * Return value: the display name of the resource. The returned string
1549 * is owned by the recent manager, and should not be freed.
1553 G_CONST_RETURN gchar *
1554 gtk_recent_info_get_display_name (GtkRecentInfo *info)
1556 g_return_val_if_fail (info != NULL, NULL);
1558 if (!info->display_name)
1559 info->display_name = gtk_recent_info_get_short_name (info);
1561 return info->display_name;
1565 * gtk_recent_info_get_description:
1566 * @info: a #GtkRecentInfo
1568 * Gets the (short) description of the resource.
1570 * Return value: the description of the resource. The returned string
1571 * is owned by the recent manager, and should not be freed.
1575 G_CONST_RETURN gchar *
1576 gtk_recent_info_get_description (GtkRecentInfo *info)
1578 g_return_val_if_fail (info != NULL, NULL);
1580 return info->description;
1584 * gtk_recent_info_get_mime_type:
1585 * @info: a #GtkRecentInfo
1587 * Gets the MIME type of the resource.
1589 * Return value: the MIME type of the resource. The returned string
1590 * is owned by the recent manager, and should not be freed.
1594 G_CONST_RETURN gchar *
1595 gtk_recent_info_get_mime_type (GtkRecentInfo *info)
1597 g_return_val_if_fail (info != NULL, NULL);
1599 if (!info->mime_type)
1600 info->mime_type = g_strdup (GTK_RECENT_DEFAULT_MIME);
1602 return info->mime_type;
1606 * gtk_recent_info_get_added:
1607 * @info: a #GtkRecentInfo
1609 * Gets the timestamp (seconds from system's Epoch) when the resource
1610 * was added to the recently used resources list.
1612 * Return value: the number of seconds elapsed from system's Epoch when
1613 * the resource was added to the list, or -1 on failure.
1618 gtk_recent_info_get_added (GtkRecentInfo *info)
1620 g_return_val_if_fail (info != NULL, (time_t) -1);
1626 * gtk_recent_info_get_modified:
1627 * @info: a #GtkRecentInfo
1629 * Gets the timestamp (seconds from system's Epoch) when the resource
1630 * was last modified.
1632 * Return value: the number of seconds elapsed from system's Epoch when
1633 * the resource was last modified, or -1 on failure.
1638 gtk_recent_info_get_modified (GtkRecentInfo *info)
1640 g_return_val_if_fail (info != NULL, (time_t) -1);
1642 return info->modified;
1646 * gtk_recent_info_get_visited:
1647 * @info: a #GtkRecentInfo
1649 * Gets the timestamp (seconds from system's Epoch) when the resource
1652 * Return value: the number of seconds elapsed from system's Epoch when
1653 * the resource was last visited, or -1 on failure.
1658 gtk_recent_info_get_visited (GtkRecentInfo *info)
1660 g_return_val_if_fail (info != NULL, (time_t) -1);
1662 return info->visited;
1666 * gtk_recent_info_get_private_hint:
1667 * @info: a #GtkRecentInfo
1669 * Gets the value of the "private" flag. Resources in the recently used
1670 * list that have this flag set to %TRUE should only be displayed by the
1671 * applications that have registered them.
1673 * Return value: %TRUE if the private flag was found, %FALSE otherwise.
1678 gtk_recent_info_get_private_hint (GtkRecentInfo *info)
1680 g_return_val_if_fail (info != NULL, FALSE);
1682 return info->is_private;
1686 static RecentAppInfo *
1687 recent_app_info_new (const gchar *app_name)
1689 RecentAppInfo *app_info;
1691 g_assert (app_name != NULL);
1693 app_info = g_new0 (RecentAppInfo, 1);
1694 app_info->name = g_strdup (app_name);
1695 app_info->exec = NULL;
1696 app_info->count = 1;
1697 app_info->stamp = time (NULL);
1703 recent_app_info_free (RecentAppInfo *app_info)
1708 g_free (app_info->name);
1710 g_free (app_info->exec);
1716 * gtk_recent_info_get_application_info:
1717 * @info: a #GtkRecentInfo
1718 * @app_name: the name of the application that has registered this item
1719 * @app_exec: return location for the string containing the command line
1720 * @count: return location for the number of times this item was registered
1721 * @time_: return location for the timestamp this item was last registered
1722 * for this application
1724 * Gets the data regarding the application that has registered the resource
1727 * If the command line contains any escape characters defined inside the
1728 * storage specification, they will be expanded.
1730 * Return value: %TRUE if an application with @app_name has registered this
1731 * resource inside the recently used list, or %FALSE otherwise. You should
1732 * free the returned command line using g_free().
1737 gtk_recent_info_get_application_info (GtkRecentInfo *info,
1738 const gchar *app_name,
1745 g_return_val_if_fail (info != NULL, FALSE);
1746 g_return_val_if_fail (app_name != NULL, FALSE);
1748 ai = (RecentAppInfo *) g_hash_table_lookup (info->apps_lookup,
1752 g_warning ("No registered application with name '%s' "
1753 "for item with URI '%s' found",
1760 *app_exec = ai->exec;
1772 * gtk_recent_info_get_applications:
1773 * @info: a #GtkRecentInfo
1774 * @length: return location for the length of the returned list, or %NULL
1776 * Retrieves the list of applications that have registered this resource.
1778 * Return value: a newly allocated %NULL-terminated array of strings.
1779 * Use g_strfreev() to free it.
1784 gtk_recent_info_get_applications (GtkRecentInfo *info,
1791 g_return_val_if_fail (info != NULL, NULL);
1793 if (!info->applications)
1801 n_apps = g_slist_length (info->applications);
1803 retval = g_new0 (gchar *, n_apps + 1);
1805 for (l = info->applications, i = 0;
1809 RecentAppInfo *ai = (RecentAppInfo *) l->data;
1811 g_assert (ai != NULL);
1813 retval[i++] = g_strdup (ai->name);
1824 * gtk_recent_info_has_application:
1825 * @info: a #GtkRecentInfo
1826 * @app_name: a string containing an application name
1828 * Checks whether an application registered this resource using @app_name.
1830 * Return value: %TRUE if an application with name @app_name was found,
1836 gtk_recent_info_has_application (GtkRecentInfo *info,
1837 const gchar *app_name)
1839 g_return_val_if_fail (info != NULL, FALSE);
1840 g_return_val_if_fail (app_name != NULL, FALSE);
1842 return (NULL != g_hash_table_lookup (info->apps_lookup, app_name));
1846 * gtk_recent_info_last_application:
1847 * @info: a #GtkRecentInfo
1849 * Gets the name of the last application that have registered the
1850 * recently used resource represented by @info.
1852 * Return value: an application name. Use g_free() to free it.
1857 gtk_recent_info_last_application (GtkRecentInfo *info)
1860 time_t last_stamp = (time_t) -1;
1863 g_return_val_if_fail (info != NULL, NULL);
1865 for (l = info->applications; l != NULL; l = l->next)
1867 RecentAppInfo *ai = (RecentAppInfo *) l->data;
1869 if (ai->stamp > last_stamp)
1872 last_stamp = ai->stamp;
1876 return g_strdup (name);
1880 get_icon_for_mime_type (const char *mime_type,
1883 GtkIconTheme *icon_theme;
1889 icon_theme = gtk_icon_theme_get_default ();
1891 content_type = g_content_type_from_mime_type (mime_type);
1896 icon = g_content_type_get_icon (content_type);
1897 info = gtk_icon_theme_lookup_by_gicon (icon_theme,
1900 GTK_ICON_LOOKUP_USE_BUILTIN);
1901 g_free (content_type);
1902 g_object_unref (icon);
1907 pixbuf = gtk_icon_info_load_icon (info, NULL);
1908 gtk_icon_info_free (info);
1914 get_icon_fallback (const gchar *icon_name,
1917 GtkIconTheme *icon_theme;
1920 icon_theme = gtk_icon_theme_get_default ();
1922 retval = gtk_icon_theme_load_icon (icon_theme, icon_name,
1924 GTK_ICON_LOOKUP_USE_BUILTIN,
1926 g_assert (retval != NULL);
1932 * gtk_recent_info_get_icon:
1933 * @info: a #GtkRecentInfo
1934 * @size: the size of the icon in pixels
1936 * Retrieves the icon of size @size associated to the resource MIME type.
1938 * Return value: a #GdkPixbuf containing the icon, or %NULL. Use
1939 * g_object_unref() when finished using the icon.
1944 gtk_recent_info_get_icon (GtkRecentInfo *info,
1947 GdkPixbuf *retval = NULL;
1949 g_return_val_if_fail (info != NULL, NULL);
1951 if (info->mime_type)
1952 retval = get_icon_for_mime_type (info->mime_type, size);
1954 /* this function should never fail */
1957 if (info->mime_type &&
1958 strcmp (info->mime_type, "x-directory/normal") == 0)
1959 retval = get_icon_fallback (GTK_STOCK_DIRECTORY, size);
1961 retval = get_icon_fallback (GTK_STOCK_FILE, size);
1968 * gtk_recent_info_is_local:
1969 * @info: a #GtkRecentInfo
1971 * Checks whether the resource is local or not by looking at the
1972 * scheme of its URI.
1974 * Return value: %TRUE if the resource is local.
1979 gtk_recent_info_is_local (GtkRecentInfo *info)
1981 g_return_val_if_fail (info != NULL, FALSE);
1983 return has_case_prefix (info->uri, "file:/");
1987 * gtk_recent_info_exists:
1988 * @info: a #GtkRecentInfo
1990 * Checks whether the resource pointed by @info still exists. At
1991 * the moment this check is done only on resources pointing to local files.
1993 * Return value: %TRUE if the resource exists
1998 gtk_recent_info_exists (GtkRecentInfo *info)
2001 struct stat stat_buf;
2002 gboolean retval = FALSE;
2004 g_return_val_if_fail (info != NULL, FALSE);
2006 /* we guarantee only local resources */
2007 if (!gtk_recent_info_is_local (info))
2010 filename = g_filename_from_uri (info->uri, NULL, NULL);
2013 if (stat (filename, &stat_buf) == 0)
2023 * gtk_recent_info_match:
2024 * @info_a: a #GtkRecentInfo
2025 * @info_b: a #GtkRecentInfo
2027 * Checks whether two #GtkRecentInfo structures point to the same
2030 * Return value: %TRUE if both #GtkRecentInfo structures point to se same
2031 * resource, %FALSE otherwise.
2036 gtk_recent_info_match (GtkRecentInfo *info_a,
2037 GtkRecentInfo *info_b)
2039 g_return_val_if_fail (info_a != NULL, FALSE);
2040 g_return_val_if_fail (info_b != NULL, FALSE);
2042 return (0 == strcmp (info_a->uri, info_b->uri));
2045 /* taken from gnome-vfs-uri.c */
2046 static const gchar *
2047 get_method_string (const gchar *substring,
2048 gchar **method_string)
2054 g_ascii_isalnum (*p) || *p == '+' || *p == '-' || *p == '.';
2061 !(p == substring + 1 && g_ascii_isalpha (*substring))
2065 /* Found toplevel method specification. */
2066 method = g_strndup (substring, p - substring);
2067 *method_string = g_ascii_strdown (method, -1);
2073 *method_string = g_strdup ("file");
2080 /* Stolen from gnome_vfs_make_valid_utf8() */
2082 make_valid_utf8 (const char *name)
2085 const char *remainder, *invalid;
2086 int remaining_bytes, valid_bytes;
2090 remaining_bytes = name ? strlen (name) : 0;
2092 while (remaining_bytes != 0)
2094 if (g_utf8_validate (remainder, remaining_bytes, &invalid))
2097 valid_bytes = invalid - remainder;
2100 string = g_string_sized_new (remaining_bytes);
2102 g_string_append_len (string, remainder, valid_bytes);
2103 g_string_append_c (string, '?');
2105 remaining_bytes -= valid_bytes + 1;
2106 remainder = invalid + 1;
2110 return g_strdup (name);
2112 g_string_append (string, remainder);
2113 g_assert (g_utf8_validate (string->str, -1, NULL));
2115 return g_string_free (string, FALSE);
2119 get_uri_shortname_for_display (const gchar *uri)
2122 gboolean validated = FALSE;
2124 if (has_case_prefix (uri, "file:/"))
2128 local_file = g_filename_from_uri (uri, NULL, NULL);
2132 name = g_filename_display_basename (local_file);
2136 g_free (local_file);
2145 rest = get_method_string (uri, &method);
2146 local_file = g_filename_display_basename (rest);
2148 name = g_strconcat (method, ": ", local_file, NULL);
2150 g_free (local_file);
2154 g_assert (name != NULL);
2156 if (!validated && !g_utf8_validate (name, -1, NULL))
2160 utf8_name = make_valid_utf8 (name);
2170 * gtk_recent_info_get_short_name:
2171 * @info: an #GtkRecentInfo
2173 * Computes a valid UTF-8 string that can be used as the name of the item in a
2174 * menu or list. For example, calling this function on an item that refers to
2175 * "file:///foo/bar.txt" will yield "bar.txt".
2177 * Return value: A newly-allocated string in UTF-8 encoding; free it with
2183 gtk_recent_info_get_short_name (GtkRecentInfo *info)
2187 g_return_val_if_fail (info != NULL, NULL);
2189 if (info->uri == NULL)
2192 short_name = get_uri_shortname_for_display (info->uri);
2198 * gtk_recent_info_get_uri_display:
2199 * @info: a #GtkRecentInfo
2201 * Gets a displayable version of the resource's URI. If the resource
2202 * is local, it returns a local path; if the resource is not local,
2203 * it returns the UTF-8 encoded content of gtk_recent_info_get_uri().
2205 * Return value: a newly allocated UTF-8 string containing the
2206 * resource's URI or %NULL. Use g_free() when done using it.
2211 gtk_recent_info_get_uri_display (GtkRecentInfo *info)
2215 g_return_val_if_fail (info != NULL, NULL);
2218 if (gtk_recent_info_is_local (info))
2222 filename = g_filename_from_uri (info->uri, NULL, NULL);
2226 retval = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
2231 retval = make_valid_utf8 (info->uri);
2238 * gtk_recent_info_get_age:
2239 * @info: a #GtkRecentInfo
2241 * Gets the number of days elapsed since the last update of the resource
2244 * Return value: a positive integer containing the number of days elapsed
2245 * since the time this resource was last modified.
2250 gtk_recent_info_get_age (GtkRecentInfo *info)
2255 g_return_val_if_fail (info != NULL, -1);
2259 delta = now - info->modified;
2261 retval = (gint) (delta / (60 * 60 * 24));
2267 * gtk_recent_info_get_groups:
2268 * @info: a #GtkRecentInfo
2269 * @length: return location for the number of groups returned, or %NULL
2271 * Returns all groups registered for the recently used item @info. The
2272 * array of returned group names will be %NULL terminated, so length might
2273 * optionally be %NULL.
2275 * Return value: a newly allocated %NULL terminated array of strings. Use
2276 * g_strfreev() to free it.
2281 gtk_recent_info_get_groups (GtkRecentInfo *info,
2288 g_return_val_if_fail (info != NULL, NULL);
2298 n_groups = g_slist_length (info->groups);
2300 retval = g_new0 (gchar *, n_groups + 1);
2302 for (l = info->groups, i = 0;
2306 gchar *group_name = (gchar *) l->data;
2308 g_assert (group_name != NULL);
2310 retval[i++] = g_strdup (group_name);
2321 * gtk_recent_info_has_group:
2322 * @info: a #GtkRecentInfo
2323 * @group_name: name of a group
2325 * Checks whether @group_name appears inside the groups registered for the
2326 * recently used item @info.
2328 * Return value: %TRUE if the group was found.
2333 gtk_recent_info_has_group (GtkRecentInfo *info,
2334 const gchar *group_name)
2338 g_return_val_if_fail (info != NULL, FALSE);
2339 g_return_val_if_fail (group_name != NULL, FALSE);
2344 for (l = info->groups; l != NULL; l = l->next)
2346 gchar *g = (gchar *) l->data;
2348 if (strcmp (g, group_name) == 0)
2356 * _gtk_recent_manager_sync:
2358 * Private function for synchronising the recent manager singleton.
2361 _gtk_recent_manager_sync (void)
2363 if (recent_manager_singleton)
2365 /* force a dump of the contents of the recent manager singleton */
2366 recent_manager_singleton->priv->is_dirty = TRUE;
2367 gtk_recent_manager_real_changed (recent_manager_singleton);
2371 #define __GTK_RECENT_MANAGER_C__
2372 #include "gtkaliasdef.c"