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"
43 /* the file where we store the recently used items */
44 #define GTK_RECENTLY_USED_FILE ".recently-used.xbel"
46 /* return all items by default */
47 #define DEFAULT_LIMIT -1
49 /* keep in sync with xdgmime */
50 #define GTK_RECENT_DEFAULT_MIME "application/octet-stream"
76 GHashTable *apps_lookup;
88 struct _GtkRecentManagerPrivate
97 GBookmarkFile *recent_items;
99 GFileMonitor *monitor;
111 static void gtk_recent_manager_dispose (GObject *object);
112 static void gtk_recent_manager_finalize (GObject *object);
113 static void gtk_recent_manager_set_property (GObject *object,
117 static void gtk_recent_manager_get_property (GObject *object,
121 static void gtk_recent_manager_add_item_query_info (GObject *source_object,
124 static void gtk_recent_manager_monitor_changed (GFileMonitor *monitor,
127 GFileMonitorEvent event_type,
129 static void gtk_recent_manager_changed (GtkRecentManager *manager);
130 static void gtk_recent_manager_real_changed (GtkRecentManager *manager);
131 static void gtk_recent_manager_set_filename (GtkRecentManager *manager,
132 const gchar *filename);
133 static void gtk_recent_manager_clamp_to_age (GtkRecentManager *manager,
137 static void build_recent_items_list (GtkRecentManager *manager);
138 static void purge_recent_items_list (GtkRecentManager *manager,
141 static RecentAppInfo *recent_app_info_new (const gchar *app_name);
142 static void recent_app_info_free (RecentAppInfo *app_info);
144 static GtkRecentInfo *gtk_recent_info_new (const gchar *uri);
145 static void gtk_recent_info_free (GtkRecentInfo *recent_info);
147 static guint signal_changed = 0;
149 static GtkRecentManager *recent_manager_singleton = NULL;
151 G_DEFINE_TYPE (GtkRecentManager, gtk_recent_manager, G_TYPE_OBJECT)
154 filename_warning (const gchar *format,
155 const gchar *filename,
156 const gchar *message)
158 gchar *utf8 = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
159 g_warning (format, utf8 ? utf8 : "(invalid filename)", message);
163 /* Test of haystack has the needle prefix, comparing case
164 * insensitive. haystack may be UTF-8, but needle must
165 * contain only lowercase ascii. */
167 has_case_prefix (const gchar *haystack,
172 /* Eat one character at a time. */
176 while (*n && *h && *n == g_ascii_tolower (*h))
186 gtk_recent_manager_error_quark (void)
188 return g_quark_from_static_string ("gtk-recent-manager-error-quark");
192 gtk_recent_manager_class_init (GtkRecentManagerClass *klass)
194 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
196 gobject_class->set_property = gtk_recent_manager_set_property;
197 gobject_class->get_property = gtk_recent_manager_get_property;
198 gobject_class->dispose = gtk_recent_manager_dispose;
199 gobject_class->finalize = gtk_recent_manager_finalize;
202 * GtkRecentManager:filename
204 * The full path to the file to be used to store and read the recently
205 * used resources list
209 g_object_class_install_property (gobject_class,
211 g_param_spec_string ("filename",
213 P_("The full path to the file to be used to store and read the list"),
215 (G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE)));
217 * GtkRecentManager:limit
219 * The maximum number of items to be returned by the
220 * gtk_recent_manager_get_items() function.
224 g_object_class_install_property (gobject_class,
226 g_param_spec_int ("limit",
228 P_("The maximum number of items to be returned by gtk_recent_manager_get_items()"),
234 * GtkRecentManager:size
236 * The size of the recently used resources list.
240 g_object_class_install_property (gobject_class,
242 g_param_spec_int ("size",
244 P_("The size of the recently used resources list"),
251 * GtkRecentManager::changed
252 * @recent_manager: the recent manager
254 * Emitted when the current recently used resources manager changes its
260 g_signal_new (I_("changed"),
261 G_TYPE_FROM_CLASS (klass),
263 G_STRUCT_OFFSET (GtkRecentManagerClass, changed),
265 g_cclosure_marshal_VOID__VOID,
268 klass->changed = gtk_recent_manager_real_changed;
270 g_type_class_add_private (klass, sizeof (GtkRecentManagerPrivate));
274 gtk_recent_manager_init (GtkRecentManager *manager)
276 GtkRecentManagerPrivate *priv;
278 manager->priv = G_TYPE_INSTANCE_GET_PRIVATE (manager,
279 GTK_TYPE_RECENT_MANAGER,
280 GtkRecentManagerPrivate);
281 priv = manager->priv;
283 priv->limit = DEFAULT_LIMIT;
286 priv->filename = NULL;
290 gtk_recent_manager_set_property (GObject *object,
295 GtkRecentManager *recent_manager = GTK_RECENT_MANAGER (object);
300 gtk_recent_manager_set_filename (recent_manager, g_value_get_string (value));
303 gtk_recent_manager_set_limit (recent_manager, g_value_get_int (value));
306 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
312 gtk_recent_manager_get_property (GObject *object,
317 GtkRecentManager *recent_manager = GTK_RECENT_MANAGER (object);
322 g_value_set_string (value, recent_manager->priv->filename);
325 g_value_set_int (value, recent_manager->priv->limit);
328 g_value_set_int (value, recent_manager->priv->size);
331 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
337 gtk_recent_manager_dispose (GObject *object)
339 GtkRecentManager *manager = GTK_RECENT_MANAGER (object);
340 GtkRecentManagerPrivate *priv = manager->priv;
344 g_signal_handlers_disconnect_by_func (priv->monitor,
345 G_CALLBACK (gtk_recent_manager_monitor_changed),
347 g_object_unref (priv->monitor);
348 priv->monitor = NULL;
351 G_OBJECT_CLASS (gtk_recent_manager_parent_class)->dispose (object);
355 gtk_recent_manager_finalize (GObject *object)
357 GtkRecentManager *manager = GTK_RECENT_MANAGER (object);
358 GtkRecentManagerPrivate *priv = manager->priv;
360 g_free (priv->filename);
362 if (priv->recent_items)
363 g_bookmark_file_free (priv->recent_items);
365 G_OBJECT_CLASS (gtk_recent_manager_parent_class)->finalize (object);
369 gtk_recent_manager_real_changed (GtkRecentManager *manager)
371 GtkRecentManagerPrivate *priv = manager->priv;
373 g_object_freeze_notify (G_OBJECT (manager));
379 /* we are marked as dirty, so we dump the content of our
380 * recently used items list
382 g_assert (priv->filename != NULL);
384 if (!priv->recent_items)
386 /* if no container object has been defined, we create a new
387 * empty container, and dump it
389 priv->recent_items = g_bookmark_file_new ();
394 GtkSettings *settings = gtk_settings_get_default ();
397 g_object_get (G_OBJECT (settings), "gtk-recent-files-max-age", &age, NULL);
399 gtk_recent_manager_clamp_to_age (manager, age);
402 g_bookmark_file_free (priv->recent_items);
403 priv->recent_items = NULL;
405 priv->recent_items = g_bookmark_file_new ();
410 g_bookmark_file_to_file (priv->recent_items, priv->filename, &write_error);
413 filename_warning ("Attempting to store changes into `%s', "
416 write_error->message);
417 g_error_free (write_error);
420 if (g_chmod (priv->filename, 0600) < 0)
422 filename_warning ("Attempting to set the permissions of `%s', "
428 /* mark us as clean */
429 priv->is_dirty = FALSE;
433 /* we are not marked as dirty, so we have been called
434 * because the recently used resources file has been
435 * changed (and not from us).
437 build_recent_items_list (manager);
440 g_object_thaw_notify (G_OBJECT (manager));
444 gtk_recent_manager_monitor_changed (GFileMonitor *monitor,
447 GFileMonitorEvent event_type,
450 GtkRecentManager *manager = user_data;
454 case G_FILE_MONITOR_EVENT_CHANGED:
455 case G_FILE_MONITOR_EVENT_CREATED:
456 gtk_recent_manager_changed (manager);
459 case G_FILE_MONITOR_EVENT_DELETED:
468 gtk_recent_manager_set_filename (GtkRecentManager *manager,
469 const gchar *filename)
471 GtkRecentManagerPrivate *priv;
475 g_assert (GTK_IS_RECENT_MANAGER (manager));
477 priv = manager->priv;
479 /* if a filename is already set and filename is not NULL, then copy
480 * it and reset the monitor; otherwise, if it's NULL we're being
481 * called from the finalization sequence, so we simply disconnect the
482 * monitoring and return.
484 * if no filename is set and filename is NULL, use the default.
488 g_free (priv->filename);
492 g_signal_handlers_disconnect_by_func (priv->monitor,
493 G_CALLBACK (gtk_recent_manager_monitor_changed),
495 g_object_unref (priv->monitor);
496 priv->monitor = NULL;
499 if (!filename || *filename == '\0')
502 priv->filename = g_strdup (filename);
506 if (!filename || *filename == '\0')
507 priv->filename = g_build_filename (g_get_home_dir (),
508 GTK_RECENTLY_USED_FILE,
511 priv->filename = g_strdup (filename);
514 g_assert (priv->filename != NULL);
515 file = g_file_new_for_path (priv->filename);
518 priv->monitor = g_file_monitor_file (file, G_FILE_MONITOR_NONE, NULL, &error);
521 filename_warning ("Unable to monitor `%s': %s\n"
522 "The GtkRecentManager will not update its contents "
523 "if the file is changed from other instances",
526 g_error_free (error);
529 g_signal_connect (priv->monitor, "changed",
530 G_CALLBACK (gtk_recent_manager_monitor_changed),
533 g_object_unref (file);
535 priv->is_dirty = FALSE;
536 build_recent_items_list (manager);
539 /* reads the recently used resources file and builds the items list.
540 * we keep the items list inside the parser object, and build the
541 * RecentInfo object only on user's demand to avoid useless replication.
542 * this function resets the dirty bit of the manager.
545 build_recent_items_list (GtkRecentManager *manager)
547 GtkRecentManagerPrivate *priv = manager->priv;
551 g_assert (priv->filename != NULL);
553 if (!priv->recent_items)
555 priv->recent_items = g_bookmark_file_new ();
559 /* the file exists, and it's valid (we hope); if not, destroy the container
560 * object and hope for a better result when the next "changed" signal is
563 g_bookmark_file_load_from_file (priv->recent_items, priv->filename, &read_error);
566 /* if the file does not exist we just wait for the first write
567 * operation on this recent manager instance, to avoid creating
568 * empty files and leading to spurious file system events (Sabayon
569 * will not be happy about those)
571 if (read_error->domain == G_FILE_ERROR &&
572 read_error->code != G_FILE_ERROR_NOENT)
573 filename_warning ("Attempting to read the recently used resources "
574 "file at `%s', but the parser failed: %s.",
576 read_error->message);
578 g_bookmark_file_free (priv->recent_items);
579 priv->recent_items = NULL;
581 g_error_free (read_error);
585 size = g_bookmark_file_get_size (priv->recent_items);
586 if (priv->size != size)
590 g_object_notify (G_OBJECT (manager), "size");
594 priv->is_dirty = FALSE;
598 /********************
600 ********************/
604 * gtk_recent_manager_new:
606 * Creates a new recent manager object. Recent manager objects are used to
607 * handle the list of recently used resources. A #GtkRecentManager object
608 * monitors the recently used resources list, and emits the "changed" signal
609 * each time something inside the list changes.
611 * #GtkRecentManager objects are expensive: be sure to create them only when
612 * needed. You should use gtk_recent_manager_get_default() instead.
614 * Return value: A newly created #GtkRecentManager object.
619 gtk_recent_manager_new (void)
621 return g_object_new (GTK_TYPE_RECENT_MANAGER, NULL);
625 * gtk_recent_manager_get_default:
627 * Gets a unique instance of #GtkRecentManager, that you can share
628 * in your application without caring about memory management. The
629 * returned instance will be freed when you application terminates.
631 * Return value: (transfer none): A unique #GtkRecentManager. Do not ref or unref it.
636 gtk_recent_manager_get_default (void)
638 if (G_UNLIKELY (!recent_manager_singleton))
639 recent_manager_singleton = gtk_recent_manager_new ();
641 return recent_manager_singleton;
645 * gtk_recent_manager_set_limit:
646 * @manager: a #GtkRecentManager
647 * @limit: the maximum number of items to return, or -1.
649 * Sets the maximum number of item that the gtk_recent_manager_get_items()
650 * function should return. If @limit is set to -1, then return all the
656 gtk_recent_manager_set_limit (GtkRecentManager *manager,
659 GtkRecentManagerPrivate *priv;
661 g_return_if_fail (GTK_IS_RECENT_MANAGER (manager));
663 priv = manager->priv;
668 * gtk_recent_manager_get_limit:
669 * @manager: a #GtkRecentManager
671 * Gets the maximum number of items that the gtk_recent_manager_get_items()
672 * function should return.
674 * Return value: the number of items to return, or -1 for every item.
679 gtk_recent_manager_get_limit (GtkRecentManager *manager)
681 GtkRecentManagerPrivate *priv;
683 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), DEFAULT_LIMIT);
685 priv = manager->priv;
690 gtk_recent_manager_add_item_query_info (GObject *source_object,
694 GFile *file = G_FILE (source_object);
695 GtkRecentManager *manager = user_data;
696 GtkRecentData recent_data;
697 GFileInfo *file_info;
701 uri = g_file_get_uri (file);
704 file_info = g_file_query_info_finish (file, res, &error);
707 g_warning ("Unable to retrieve the file info for `%s': %s",
710 g_error_free (error);
714 recent_data.display_name = NULL;
715 recent_data.description = NULL;
721 content_type = g_file_info_get_attribute_as_string (file_info, G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE);
723 if (G_LIKELY (content_type))
724 recent_data.mime_type = g_content_type_get_mime_type (content_type);
726 recent_data.mime_type = g_strdup (GTK_RECENT_DEFAULT_MIME);
728 g_free (content_type);
729 g_object_unref (file_info);
732 recent_data.mime_type = g_strdup (GTK_RECENT_DEFAULT_MIME);
734 recent_data.app_name = g_strdup (g_get_application_name ());
735 recent_data.app_exec = g_strjoin (" ", g_get_prgname (), "%u", NULL);
736 recent_data.groups = NULL;
737 recent_data.is_private = FALSE;
739 /* Ignore return value, this can't fail anyway since all required
741 gtk_recent_manager_add_full (manager, uri, &recent_data);
743 manager->priv->is_dirty = TRUE;
744 gtk_recent_manager_changed (manager);
746 g_free (recent_data.mime_type);
747 g_free (recent_data.app_name);
748 g_free (recent_data.app_exec);
751 g_object_unref (manager);
756 * gtk_recent_manager_add_item:
757 * @manager: a #GtkRecentManager
760 * Adds a new resource, pointed by @uri, into the recently used
763 * This function automatically retrieves some of the needed
764 * metadata and setting other metadata to common default values; it
765 * then feeds the data to gtk_recent_manager_add_full().
767 * See gtk_recent_manager_add_full() if you want to explicitly
768 * define the metadata for the resource pointed by @uri.
770 * Return value: %TRUE if the new item was successfully added
771 * to the recently used resources list
776 gtk_recent_manager_add_item (GtkRecentManager *manager,
781 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), FALSE);
782 g_return_val_if_fail (uri != NULL, FALSE);
784 file = g_file_new_for_uri (uri);
786 g_file_query_info_async (file,
787 G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE,
789 G_FILE_QUERY_INFO_NONE,
791 gtk_recent_manager_add_item_query_info,
792 g_object_ref (manager));
794 g_object_unref (file);
800 * gtk_recent_manager_add_full:
801 * @manager: a #GtkRecentManager
803 * @recent_data: metadata of the resource
805 * Adds a new resource, pointed by @uri, into the recently used
806 * resources list, using the metadata specified inside the #GtkRecentData
807 * structure passed in @recent_data.
809 * The passed URI will be used to identify this resource inside the
812 * In order to register the new recently used resource, metadata about
813 * the resource must be passed as well as the URI; the metadata is
814 * stored in a #GtkRecentData structure, which must contain the MIME
815 * type of the resource pointed by the URI; the name of the application
816 * that is registering the item, and a command line to be used when
817 * launching the item.
819 * Optionally, a #GtkRecentData structure might contain a UTF-8 string
820 * to be used when viewing the item instead of the last component of the
821 * URI; a short description of the item; whether the item should be
822 * considered private - that is, should be displayed only by the
823 * applications that have registered it.
825 * Return value: %TRUE if the new item was successfully added to the
826 * recently used resources list, %FALSE otherwise.
831 gtk_recent_manager_add_full (GtkRecentManager *manager,
833 const GtkRecentData *data)
835 GtkRecentManagerPrivate *priv;
837 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), FALSE);
838 g_return_val_if_fail (uri != NULL, FALSE);
839 g_return_val_if_fail (data != NULL, FALSE);
842 if ((data->display_name) &&
843 (!g_utf8_validate (data->display_name, -1, NULL)))
845 g_warning ("Attempting to add `%s' to the list of recently used "
846 "resources, but the display name is not a valid UTF-8 "
852 if ((data->description) &&
853 (!g_utf8_validate (data->description, -1, NULL)))
855 g_warning ("Attempting to add `%s' to the list of recently used "
856 "resources, but the description is not a valid UTF-8 "
863 if (!data->mime_type)
865 g_warning ("Attempting to add `%s' to the list of recently used "
866 "resources, but not MIME type was defined",
873 g_warning ("Attempting to add `%s' to the list of recently used "
874 "resources, but no name of the application that is "
875 "registering it was defined",
882 g_warning ("Attempting to add `%s' to the list of recently used "
883 "resources, but no command line for the application "
884 "that is registering it was defined",
889 priv = manager->priv;
891 if (!priv->recent_items)
893 priv->recent_items = g_bookmark_file_new ();
897 if (data->display_name)
898 g_bookmark_file_set_title (priv->recent_items, uri, data->display_name);
900 if (data->description)
901 g_bookmark_file_set_description (priv->recent_items, uri, data->description);
903 g_bookmark_file_set_mime_type (priv->recent_items, uri, data->mime_type);
905 if (data->groups && data->groups[0] != '\0')
909 for (j = 0; (data->groups)[j] != NULL; j++)
910 g_bookmark_file_add_group (priv->recent_items, uri, (data->groups)[j]);
913 /* register the application; this will take care of updating the
914 * registration count and time in case the application has
915 * already registered the same document inside the list
917 g_bookmark_file_add_application (priv->recent_items, uri,
921 g_bookmark_file_set_is_private (priv->recent_items, uri,
924 /* mark us as dirty, so that when emitting the "changed" signal we
925 * will dump our changes
927 priv->is_dirty = TRUE;
929 gtk_recent_manager_changed (manager);
935 * gtk_recent_manager_remove_item:
936 * @manager: a #GtkRecentManager
937 * @uri: the URI of the item you wish to remove
938 * @error: (allow-none): return location for a #GError, or %NULL
940 * Removes a resource pointed by @uri from the recently used resources
941 * list handled by a recent manager.
943 * Return value: %TRUE if the item pointed by @uri has been successfully
944 * removed by the recently used resources list, and %FALSE otherwise.
949 gtk_recent_manager_remove_item (GtkRecentManager *manager,
953 GtkRecentManagerPrivate *priv;
954 GError *remove_error = NULL;
956 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), FALSE);
957 g_return_val_if_fail (uri != NULL, FALSE);
958 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
960 priv = manager->priv;
962 if (!priv->recent_items)
964 priv->recent_items = g_bookmark_file_new ();
967 g_set_error (error, GTK_RECENT_MANAGER_ERROR,
968 GTK_RECENT_MANAGER_ERROR_NOT_FOUND,
969 _("Unable to find an item with URI '%s'"),
975 g_bookmark_file_remove_item (priv->recent_items, uri, &remove_error);
978 g_error_free (remove_error);
980 g_set_error (error, GTK_RECENT_MANAGER_ERROR,
981 GTK_RECENT_MANAGER_ERROR_NOT_FOUND,
982 _("Unable to find an item with URI '%s'"),
988 priv->is_dirty = TRUE;
990 gtk_recent_manager_changed (manager);
996 * gtk_recent_manager_has_item:
997 * @manager: a #GtkRecentManager
1000 * Checks whether there is a recently used resource registered
1001 * with @uri inside the recent manager.
1003 * Return value: %TRUE if the resource was found, %FALSE otherwise.
1008 gtk_recent_manager_has_item (GtkRecentManager *manager,
1011 GtkRecentManagerPrivate *priv;
1013 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), FALSE);
1014 g_return_val_if_fail (uri != NULL, FALSE);
1016 priv = manager->priv;
1017 g_return_val_if_fail (priv->recent_items != NULL, FALSE);
1019 return g_bookmark_file_has_item (priv->recent_items, uri);
1023 build_recent_info (GBookmarkFile *bookmarks,
1024 GtkRecentInfo *info)
1026 gchar **apps, **groups;
1027 gsize apps_len, groups_len, i;
1029 g_assert (bookmarks != NULL);
1030 g_assert (info != NULL);
1032 info->display_name = g_bookmark_file_get_title (bookmarks, info->uri, NULL);
1033 info->description = g_bookmark_file_get_description (bookmarks, info->uri, NULL);
1034 info->mime_type = g_bookmark_file_get_mime_type (bookmarks, info->uri, NULL);
1036 info->is_private = g_bookmark_file_get_is_private (bookmarks, info->uri, NULL);
1038 info->added = g_bookmark_file_get_added (bookmarks, info->uri, NULL);
1039 info->modified = g_bookmark_file_get_modified (bookmarks, info->uri, NULL);
1040 info->visited = g_bookmark_file_get_visited (bookmarks, info->uri, NULL);
1042 groups = g_bookmark_file_get_groups (bookmarks, info->uri, &groups_len, NULL);
1043 for (i = 0; i < groups_len; i++)
1045 gchar *group_name = g_strdup (groups[i]);
1047 info->groups = g_slist_append (info->groups, group_name);
1050 g_strfreev (groups);
1052 apps = g_bookmark_file_get_applications (bookmarks, info->uri, &apps_len, NULL);
1053 for (i = 0; i < apps_len; i++)
1055 gchar *app_name, *app_exec;
1058 RecentAppInfo *app_info;
1063 res = g_bookmark_file_get_app_info (bookmarks, info->uri, app_name,
1071 app_info = recent_app_info_new (app_name);
1072 app_info->exec = app_exec;
1073 app_info->count = count;
1074 app_info->stamp = stamp;
1076 info->applications = g_slist_prepend (info->applications, app_info);
1077 g_hash_table_replace (info->apps_lookup, app_info->name, app_info);
1084 * gtk_recent_manager_lookup_item:
1085 * @manager: a #GtkRecentManager
1087 * @error: (allow-none): a return location for a #GError, or %NULL
1089 * Searches for a URI inside the recently used resources list, and
1090 * returns a structure containing informations about the resource
1091 * like its MIME type, or its display name.
1093 * Return value: a #GtkRecentInfo structure containing information
1094 * about the resource pointed by @uri, or %NULL if the URI was
1095 * not registered in the recently used resources list. Free with
1096 * gtk_recent_info_unref().
1101 gtk_recent_manager_lookup_item (GtkRecentManager *manager,
1105 GtkRecentManagerPrivate *priv;
1106 GtkRecentInfo *info = NULL;
1108 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), NULL);
1109 g_return_val_if_fail (uri != NULL, NULL);
1110 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
1112 priv = manager->priv;
1113 if (!priv->recent_items)
1115 priv->recent_items = g_bookmark_file_new ();
1118 g_set_error (error, GTK_RECENT_MANAGER_ERROR,
1119 GTK_RECENT_MANAGER_ERROR_NOT_FOUND,
1120 _("Unable to find an item with URI '%s'"),
1126 if (!g_bookmark_file_has_item (priv->recent_items, uri))
1128 g_set_error (error, GTK_RECENT_MANAGER_ERROR,
1129 GTK_RECENT_MANAGER_ERROR_NOT_FOUND,
1130 _("Unable to find an item with URI '%s'"),
1135 info = gtk_recent_info_new (uri);
1136 g_return_val_if_fail (info != NULL, NULL);
1138 /* fill the RecentInfo structure with the data retrieved by our
1139 * parser object from the storage file
1141 build_recent_info (priv->recent_items, info);
1147 * gtk_recent_manager_move_item:
1148 * @manager: a #GtkRecentManager
1149 * @uri: the URI of a recently used resource
1150 * @new_uri: (allow-none): the new URI of the recently used resource, or %NULL to
1151 * remove the item pointed by @uri in the list
1152 * @error: (allow-none): a return location for a #GError, or %NULL
1154 * Changes the location of a recently used resource from @uri to @new_uri.
1156 * Please note that this function will not affect the resource pointed
1157 * by the URIs, but only the URI used in the recently used resources list.
1159 * Return value: %TRUE on success.
1164 gtk_recent_manager_move_item (GtkRecentManager *recent_manager,
1166 const gchar *new_uri,
1169 GtkRecentManagerPrivate *priv;
1173 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (recent_manager), FALSE);
1174 g_return_val_if_fail (uri != NULL, FALSE);
1175 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
1177 priv = recent_manager->priv;
1179 if (!priv->recent_items)
1181 g_set_error (error, GTK_RECENT_MANAGER_ERROR,
1182 GTK_RECENT_MANAGER_ERROR_NOT_FOUND,
1183 _("Unable to find an item with URI '%s'"),
1188 if (!g_bookmark_file_has_item (priv->recent_items, uri))
1190 g_set_error (error, GTK_RECENT_MANAGER_ERROR,
1191 GTK_RECENT_MANAGER_ERROR_NOT_FOUND,
1192 _("Unable to find an item with URI '%s'"),
1198 res = g_bookmark_file_move_item (priv->recent_items,
1203 g_error_free (move_error);
1205 g_set_error (error, GTK_RECENT_MANAGER_ERROR,
1206 GTK_RECENT_MANAGER_ERROR_NOT_FOUND,
1207 _("Unable to find an item with URI '%s'"),
1212 priv->is_dirty = TRUE;
1214 gtk_recent_manager_changed (recent_manager);
1220 * gtk_recent_manager_get_items:
1221 * @manager: a #GtkRecentManager
1223 * Gets the list of recently used resources.
1225 * Return value: (element-type GtkRecentInfo) (transfer full): a list of
1226 * newly allocated #GtkRecentInfo objects. Use
1227 * gtk_recent_info_unref() on each item inside the list, and then
1228 * free the list itself using g_list_free().
1233 gtk_recent_manager_get_items (GtkRecentManager *manager)
1235 GtkRecentManagerPrivate *priv;
1236 GList *retval = NULL;
1240 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), NULL);
1242 priv = manager->priv;
1243 if (!priv->recent_items)
1246 if (priv->limit == 0)
1249 uris = g_bookmark_file_get_uris (priv->recent_items, &uris_len);
1250 for (i = 0; i < uris_len; i++)
1252 GtkRecentInfo *info;
1254 if (priv->limit != -1 && i == priv->limit)
1257 info = gtk_recent_info_new (uris[i]);
1258 build_recent_info (priv->recent_items, info);
1260 retval = g_list_prepend (retval, info);
1269 purge_recent_items_list (GtkRecentManager *manager,
1272 GtkRecentManagerPrivate *priv = manager->priv;
1274 if (!priv->recent_items)
1277 g_bookmark_file_free (priv->recent_items);
1278 priv->recent_items = NULL;
1280 priv->recent_items = g_bookmark_file_new ();
1282 priv->is_dirty = TRUE;
1284 /* emit the changed signal, to ensure that the purge is written */
1285 gtk_recent_manager_changed (manager);
1289 * gtk_recent_manager_purge_items:
1290 * @manager: a #GtkRecentManager
1291 * @error: (allow-none): a return location for a #GError, or %NULL
1293 * Purges every item from the recently used resources list.
1295 * Return value: the number of items that have been removed from the
1296 * recently used resources list.
1301 gtk_recent_manager_purge_items (GtkRecentManager *manager,
1304 GtkRecentManagerPrivate *priv;
1307 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), -1);
1309 priv = manager->priv;
1310 if (!priv->recent_items)
1313 count = g_bookmark_file_get_size (priv->recent_items);
1317 purge_recent_items_list (manager, error);
1319 purged = count - g_bookmark_file_get_size (priv->recent_items);
1325 gtk_recent_manager_changed (GtkRecentManager *recent_manager)
1327 g_signal_emit (recent_manager, signal_changed, 0);
1331 gtk_recent_manager_clamp_to_age (GtkRecentManager *manager,
1334 GtkRecentManagerPrivate *priv = manager->priv;
1339 if (G_UNLIKELY (!priv->recent_items))
1344 uris = g_bookmark_file_get_uris (priv->recent_items, &n_uris);
1346 for (i = 0; i < n_uris; i++)
1348 const gchar *uri = uris[i];
1352 modified = g_bookmark_file_get_modified (priv->recent_items, uri, NULL);
1353 item_age = (gint) ((now - modified) / (60 * 60 * 24));
1355 g_bookmark_file_remove_item (priv->recent_items, uri, NULL);
1366 gtk_recent_info_get_type (void)
1368 static GType info_type = 0;
1371 info_type = g_boxed_type_register_static (I_("GtkRecentInfo"),
1372 (GBoxedCopyFunc) gtk_recent_info_ref,
1373 (GBoxedFreeFunc) gtk_recent_info_unref);
1377 static GtkRecentInfo *
1378 gtk_recent_info_new (const gchar *uri)
1380 GtkRecentInfo *info;
1382 g_assert (uri != NULL);
1384 info = g_new0 (GtkRecentInfo, 1);
1385 info->uri = g_strdup (uri);
1387 info->applications = NULL;
1388 info->apps_lookup = g_hash_table_new (g_str_hash, g_str_equal);
1390 info->groups = NULL;
1392 info->ref_count = 1;
1398 gtk_recent_info_free (GtkRecentInfo *recent_info)
1403 g_free (recent_info->uri);
1404 g_free (recent_info->display_name);
1405 g_free (recent_info->description);
1406 g_free (recent_info->mime_type);
1408 if (recent_info->applications)
1410 g_slist_foreach (recent_info->applications,
1411 (GFunc) recent_app_info_free,
1413 g_slist_free (recent_info->applications);
1415 recent_info->applications = NULL;
1418 if (recent_info->apps_lookup)
1419 g_hash_table_destroy (recent_info->apps_lookup);
1421 if (recent_info->groups)
1423 g_slist_foreach (recent_info->groups,
1426 g_slist_free (recent_info->groups);
1428 recent_info->groups = NULL;
1431 if (recent_info->icon)
1432 g_object_unref (recent_info->icon);
1434 g_free (recent_info);
1438 * gtk_recent_info_ref:
1439 * @info: a #GtkRecentInfo
1441 * Increases the reference count of @recent_info by one.
1443 * Return value: the recent info object with its reference count increased
1449 gtk_recent_info_ref (GtkRecentInfo *info)
1451 g_return_val_if_fail (info != NULL, NULL);
1452 g_return_val_if_fail (info->ref_count > 0, NULL);
1454 info->ref_count += 1;
1460 * gtk_recent_info_unref:
1461 * @info: a #GtkRecentInfo
1463 * Decreases the reference count of @info by one. If the reference
1464 * count reaches zero, @info is deallocated, and the memory freed.
1469 gtk_recent_info_unref (GtkRecentInfo *info)
1471 g_return_if_fail (info != NULL);
1472 g_return_if_fail (info->ref_count > 0);
1474 info->ref_count -= 1;
1476 if (info->ref_count == 0)
1477 gtk_recent_info_free (info);
1481 * gtk_recent_info_get_uri:
1482 * @info: a #GtkRecentInfo
1484 * Gets the URI of the resource.
1486 * Return value: the URI of the resource. The returned string is
1487 * owned by the recent manager, and should not be freed.
1491 G_CONST_RETURN gchar *
1492 gtk_recent_info_get_uri (GtkRecentInfo *info)
1494 g_return_val_if_fail (info != NULL, NULL);
1500 * gtk_recent_info_get_display_name:
1501 * @info: a #GtkRecentInfo
1503 * Gets the name of the resource. If none has been defined, the basename
1504 * of the resource is obtained.
1506 * Return value: the display name of the resource. The returned string
1507 * is owned by the recent manager, and should not be freed.
1511 G_CONST_RETURN gchar *
1512 gtk_recent_info_get_display_name (GtkRecentInfo *info)
1514 g_return_val_if_fail (info != NULL, NULL);
1516 if (!info->display_name)
1517 info->display_name = gtk_recent_info_get_short_name (info);
1519 return info->display_name;
1523 * gtk_recent_info_get_description:
1524 * @info: a #GtkRecentInfo
1526 * Gets the (short) description of the resource.
1528 * Return value: the description of the resource. The returned string
1529 * is owned by the recent manager, and should not be freed.
1533 G_CONST_RETURN gchar *
1534 gtk_recent_info_get_description (GtkRecentInfo *info)
1536 g_return_val_if_fail (info != NULL, NULL);
1538 return info->description;
1542 * gtk_recent_info_get_mime_type:
1543 * @info: a #GtkRecentInfo
1545 * Gets the MIME type of the resource.
1547 * Return value: the MIME type of the resource. The returned string
1548 * is owned by the recent manager, and should not be freed.
1552 G_CONST_RETURN gchar *
1553 gtk_recent_info_get_mime_type (GtkRecentInfo *info)
1555 g_return_val_if_fail (info != NULL, NULL);
1557 if (!info->mime_type)
1558 info->mime_type = g_strdup (GTK_RECENT_DEFAULT_MIME);
1560 return info->mime_type;
1564 * gtk_recent_info_get_added:
1565 * @info: a #GtkRecentInfo
1567 * Gets the timestamp (seconds from system's Epoch) when the resource
1568 * was added to the recently used resources list.
1570 * Return value: the number of seconds elapsed from system's Epoch when
1571 * the resource was added to the list, or -1 on failure.
1576 gtk_recent_info_get_added (GtkRecentInfo *info)
1578 g_return_val_if_fail (info != NULL, (time_t) -1);
1584 * gtk_recent_info_get_modified:
1585 * @info: a #GtkRecentInfo
1587 * Gets the timestamp (seconds from system's Epoch) when the resource
1588 * was last modified.
1590 * Return value: the number of seconds elapsed from system's Epoch when
1591 * the resource was last modified, or -1 on failure.
1596 gtk_recent_info_get_modified (GtkRecentInfo *info)
1598 g_return_val_if_fail (info != NULL, (time_t) -1);
1600 return info->modified;
1604 * gtk_recent_info_get_visited:
1605 * @info: a #GtkRecentInfo
1607 * Gets the timestamp (seconds from system's Epoch) when the resource
1610 * Return value: the number of seconds elapsed from system's Epoch when
1611 * the resource was last visited, or -1 on failure.
1616 gtk_recent_info_get_visited (GtkRecentInfo *info)
1618 g_return_val_if_fail (info != NULL, (time_t) -1);
1620 return info->visited;
1624 * gtk_recent_info_get_private_hint:
1625 * @info: a #GtkRecentInfo
1627 * Gets the value of the "private" flag. Resources in the recently used
1628 * list that have this flag set to %TRUE should only be displayed by the
1629 * applications that have registered them.
1631 * Return value: %TRUE if the private flag was found, %FALSE otherwise.
1636 gtk_recent_info_get_private_hint (GtkRecentInfo *info)
1638 g_return_val_if_fail (info != NULL, FALSE);
1640 return info->is_private;
1644 static RecentAppInfo *
1645 recent_app_info_new (const gchar *app_name)
1647 RecentAppInfo *app_info;
1649 g_assert (app_name != NULL);
1651 app_info = g_slice_new0 (RecentAppInfo);
1652 app_info->name = g_strdup (app_name);
1653 app_info->exec = NULL;
1654 app_info->count = 1;
1655 app_info->stamp = 0;
1661 recent_app_info_free (RecentAppInfo *app_info)
1666 g_free (app_info->name);
1667 g_free (app_info->exec);
1669 g_slice_free (RecentAppInfo, app_info);
1673 * gtk_recent_info_get_application_info:
1674 * @info: a #GtkRecentInfo
1675 * @app_name: the name of the application that has registered this item
1676 * @app_exec: (transfer none) (out): return location for the string containing the command line
1677 * @count: (out): return location for the number of times this item was registered
1678 * @time_: (out): return location for the timestamp this item was last registered
1679 * for this application
1681 * Gets the data regarding the application that has registered the resource
1684 * If the command line contains any escape characters defined inside the
1685 * storage specification, they will be expanded.
1687 * Return value: %TRUE if an application with @app_name has registered this
1688 * resource inside the recently used list, or %FALSE otherwise. The
1689 * @app_exec string is owned by the #GtkRecentInfo and should not be
1695 gtk_recent_info_get_application_info (GtkRecentInfo *info,
1696 const gchar *app_name,
1697 const gchar **app_exec,
1703 g_return_val_if_fail (info != NULL, FALSE);
1704 g_return_val_if_fail (app_name != NULL, FALSE);
1706 ai = (RecentAppInfo *) g_hash_table_lookup (info->apps_lookup,
1710 g_warning ("No registered application with name '%s' "
1711 "for item with URI '%s' found",
1718 *app_exec = ai->exec;
1730 * gtk_recent_info_get_applications:
1731 * @info: a #GtkRecentInfo
1732 * @length: (out) (allow-none): return location for the length of the returned list
1734 * Retrieves the list of applications that have registered this resource.
1736 * Return value: (array length=length zero-terminated=1): a newly allocated
1737 * %NULL-terminated array of strings. Use g_strfreev() to free it.
1742 gtk_recent_info_get_applications (GtkRecentInfo *info,
1749 g_return_val_if_fail (info != NULL, NULL);
1751 if (!info->applications)
1759 n_apps = g_slist_length (info->applications);
1761 retval = g_new0 (gchar *, n_apps + 1);
1763 for (l = info->applications, i = 0;
1767 RecentAppInfo *ai = (RecentAppInfo *) l->data;
1769 g_assert (ai != NULL);
1771 retval[i++] = g_strdup (ai->name);
1782 * gtk_recent_info_has_application:
1783 * @info: a #GtkRecentInfo
1784 * @app_name: a string containing an application name
1786 * Checks whether an application registered this resource using @app_name.
1788 * Return value: %TRUE if an application with name @app_name was found,
1794 gtk_recent_info_has_application (GtkRecentInfo *info,
1795 const gchar *app_name)
1797 g_return_val_if_fail (info != NULL, FALSE);
1798 g_return_val_if_fail (app_name != NULL, FALSE);
1800 return (NULL != g_hash_table_lookup (info->apps_lookup, app_name));
1804 * gtk_recent_info_last_application:
1805 * @info: a #GtkRecentInfo
1807 * Gets the name of the last application that have registered the
1808 * recently used resource represented by @info.
1810 * Return value: an application name. Use g_free() to free it.
1815 gtk_recent_info_last_application (GtkRecentInfo *info)
1818 time_t last_stamp = (time_t) -1;
1821 g_return_val_if_fail (info != NULL, NULL);
1823 for (l = info->applications; l != NULL; l = l->next)
1825 RecentAppInfo *ai = (RecentAppInfo *) l->data;
1827 if (ai->stamp > last_stamp)
1830 last_stamp = ai->stamp;
1834 return g_strdup (name);
1838 get_icon_for_mime_type (const char *mime_type,
1841 GtkIconTheme *icon_theme;
1847 icon_theme = gtk_icon_theme_get_default ();
1849 content_type = g_content_type_from_mime_type (mime_type);
1854 icon = g_content_type_get_icon (content_type);
1855 info = gtk_icon_theme_lookup_by_gicon (icon_theme,
1858 GTK_ICON_LOOKUP_USE_BUILTIN);
1859 g_free (content_type);
1860 g_object_unref (icon);
1865 pixbuf = gtk_icon_info_load_icon (info, NULL);
1866 gtk_icon_info_free (info);
1872 get_icon_fallback (const gchar *icon_name,
1875 GtkIconTheme *icon_theme;
1878 icon_theme = gtk_icon_theme_get_default ();
1880 retval = gtk_icon_theme_load_icon (icon_theme, icon_name,
1882 GTK_ICON_LOOKUP_USE_BUILTIN,
1884 g_assert (retval != NULL);
1890 * gtk_recent_info_get_icon:
1891 * @info: a #GtkRecentInfo
1892 * @size: the size of the icon in pixels
1894 * Retrieves the icon of size @size associated to the resource MIME type.
1896 * Return value: a #GdkPixbuf containing the icon, or %NULL. Use
1897 * g_object_unref() when finished using the icon.
1902 gtk_recent_info_get_icon (GtkRecentInfo *info,
1905 GdkPixbuf *retval = NULL;
1907 g_return_val_if_fail (info != NULL, NULL);
1909 if (info->mime_type)
1910 retval = get_icon_for_mime_type (info->mime_type, size);
1912 /* this function should never fail */
1915 if (info->mime_type &&
1916 strcmp (info->mime_type, "x-directory/normal") == 0)
1917 retval = get_icon_fallback (GTK_STOCK_DIRECTORY, size);
1919 retval = get_icon_fallback (GTK_STOCK_FILE, size);
1926 * gtk_recent_info_is_local:
1927 * @info: a #GtkRecentInfo
1929 * Checks whether the resource is local or not by looking at the
1930 * scheme of its URI.
1932 * Return value: %TRUE if the resource is local.
1937 gtk_recent_info_is_local (GtkRecentInfo *info)
1939 g_return_val_if_fail (info != NULL, FALSE);
1941 return has_case_prefix (info->uri, "file:/");
1945 * gtk_recent_info_exists:
1946 * @info: a #GtkRecentInfo
1948 * Checks whether the resource pointed by @info still exists. At
1949 * the moment this check is done only on resources pointing to local files.
1951 * Return value: %TRUE if the resource exists
1956 gtk_recent_info_exists (GtkRecentInfo *info)
1959 struct stat stat_buf;
1960 gboolean retval = FALSE;
1962 g_return_val_if_fail (info != NULL, FALSE);
1964 /* we guarantee only local resources */
1965 if (!gtk_recent_info_is_local (info))
1968 filename = g_filename_from_uri (info->uri, NULL, NULL);
1971 if (stat (filename, &stat_buf) == 0)
1981 * gtk_recent_info_match:
1982 * @info_a: a #GtkRecentInfo
1983 * @info_b: a #GtkRecentInfo
1985 * Checks whether two #GtkRecentInfo structures point to the same
1988 * Return value: %TRUE if both #GtkRecentInfo structures point to se same
1989 * resource, %FALSE otherwise.
1994 gtk_recent_info_match (GtkRecentInfo *info_a,
1995 GtkRecentInfo *info_b)
1997 g_return_val_if_fail (info_a != NULL, FALSE);
1998 g_return_val_if_fail (info_b != NULL, FALSE);
2000 return (0 == strcmp (info_a->uri, info_b->uri));
2003 /* taken from gnome-vfs-uri.c */
2004 static const gchar *
2005 get_method_string (const gchar *substring,
2006 gchar **method_string)
2012 g_ascii_isalnum (*p) || *p == '+' || *p == '-' || *p == '.';
2019 !(p == substring + 1 && g_ascii_isalpha (*substring))
2023 /* Found toplevel method specification. */
2024 method = g_strndup (substring, p - substring);
2025 *method_string = g_ascii_strdown (method, -1);
2031 *method_string = g_strdup ("file");
2038 /* Stolen from gnome_vfs_make_valid_utf8() */
2040 make_valid_utf8 (const char *name)
2043 const char *remainder, *invalid;
2044 int remaining_bytes, valid_bytes;
2048 remaining_bytes = name ? strlen (name) : 0;
2050 while (remaining_bytes != 0)
2052 if (g_utf8_validate (remainder, remaining_bytes, &invalid))
2055 valid_bytes = invalid - remainder;
2058 string = g_string_sized_new (remaining_bytes);
2060 g_string_append_len (string, remainder, valid_bytes);
2061 g_string_append_c (string, '?');
2063 remaining_bytes -= valid_bytes + 1;
2064 remainder = invalid + 1;
2068 return g_strdup (name);
2070 g_string_append (string, remainder);
2071 g_assert (g_utf8_validate (string->str, -1, NULL));
2073 return g_string_free (string, FALSE);
2077 get_uri_shortname_for_display (const gchar *uri)
2080 gboolean validated = FALSE;
2082 if (has_case_prefix (uri, "file:/"))
2086 local_file = g_filename_from_uri (uri, NULL, NULL);
2090 name = g_filename_display_basename (local_file);
2094 g_free (local_file);
2103 rest = get_method_string (uri, &method);
2104 local_file = g_filename_display_basename (rest);
2106 name = g_strconcat (method, ": ", local_file, NULL);
2108 g_free (local_file);
2112 g_assert (name != NULL);
2114 if (!validated && !g_utf8_validate (name, -1, NULL))
2118 utf8_name = make_valid_utf8 (name);
2128 * gtk_recent_info_get_short_name:
2129 * @info: an #GtkRecentInfo
2131 * Computes a valid UTF-8 string that can be used as the name of the item in a
2132 * menu or list. For example, calling this function on an item that refers to
2133 * "file:///foo/bar.txt" will yield "bar.txt".
2135 * Return value: A newly-allocated string in UTF-8 encoding; free it with
2141 gtk_recent_info_get_short_name (GtkRecentInfo *info)
2145 g_return_val_if_fail (info != NULL, NULL);
2147 if (info->uri == NULL)
2150 short_name = get_uri_shortname_for_display (info->uri);
2156 * gtk_recent_info_get_uri_display:
2157 * @info: a #GtkRecentInfo
2159 * Gets a displayable version of the resource's URI. If the resource
2160 * is local, it returns a local path; if the resource is not local,
2161 * it returns the UTF-8 encoded content of gtk_recent_info_get_uri().
2163 * Return value: a newly allocated UTF-8 string containing the
2164 * resource's URI or %NULL. Use g_free() when done using it.
2169 gtk_recent_info_get_uri_display (GtkRecentInfo *info)
2173 g_return_val_if_fail (info != NULL, NULL);
2176 if (gtk_recent_info_is_local (info))
2180 filename = g_filename_from_uri (info->uri, NULL, NULL);
2184 retval = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
2189 retval = make_valid_utf8 (info->uri);
2196 * gtk_recent_info_get_age:
2197 * @info: a #GtkRecentInfo
2199 * Gets the number of days elapsed since the last update of the resource
2202 * Return value: a positive integer containing the number of days elapsed
2203 * since the time this resource was last modified.
2208 gtk_recent_info_get_age (GtkRecentInfo *info)
2213 g_return_val_if_fail (info != NULL, -1);
2217 delta = now - info->modified;
2219 retval = (gint) (delta / (60 * 60 * 24));
2225 * gtk_recent_info_get_groups:
2226 * @info: a #GtkRecentInfo
2227 * @length: (out) (allow-none): return location for the number of groups returned
2229 * Returns all groups registered for the recently used item @info. The
2230 * array of returned group names will be %NULL terminated, so length might
2231 * optionally be %NULL.
2233 * Return value: (array length=length zero-terminated=1): a newly allocated
2234 * %NULL terminated array of strings. Use g_strfreev() to free it.
2239 gtk_recent_info_get_groups (GtkRecentInfo *info,
2246 g_return_val_if_fail (info != NULL, NULL);
2256 n_groups = g_slist_length (info->groups);
2258 retval = g_new0 (gchar *, n_groups + 1);
2260 for (l = info->groups, i = 0;
2264 gchar *group_name = (gchar *) l->data;
2266 g_assert (group_name != NULL);
2268 retval[i++] = g_strdup (group_name);
2279 * gtk_recent_info_has_group:
2280 * @info: a #GtkRecentInfo
2281 * @group_name: name of a group
2283 * Checks whether @group_name appears inside the groups registered for the
2284 * recently used item @info.
2286 * Return value: %TRUE if the group was found.
2291 gtk_recent_info_has_group (GtkRecentInfo *info,
2292 const gchar *group_name)
2296 g_return_val_if_fail (info != NULL, FALSE);
2297 g_return_val_if_fail (group_name != NULL, FALSE);
2302 for (l = info->groups; l != NULL; l = l->next)
2304 gchar *g = (gchar *) l->data;
2306 if (strcmp (g, group_name) == 0)
2314 * _gtk_recent_manager_sync:
2316 * Private function for synchronising the recent manager singleton.
2319 _gtk_recent_manager_sync (void)
2321 if (recent_manager_singleton)
2323 /* force a dump of the contents of the recent manager singleton */
2324 recent_manager_singleton->priv->is_dirty = TRUE;
2325 gtk_recent_manager_real_changed (recent_manager_singleton);