1 /* GTK - The GIMP Toolkit
2 * gtkrecentmanager.c: a manager for the recently used resources
4 * Copyright (C) 2006 Emmanuele Bassi
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 #include <sys/types.h>
32 #include <glib/gstdio.h>
35 #include "gtkrecentmanager.h"
38 #include "gtkicontheme.h"
39 #include "gtktypebuiltins.h"
40 #include "gtkprivate.h"
41 #include "gtkmarshalers.h"
44 /* the file where we store the recently used items */
45 #define GTK_RECENTLY_USED_FILE ".recently-used.xbel"
47 /* return all items by default */
48 #define DEFAULT_LIMIT -1
50 /* keep in sync with xdgmime */
51 #define GTK_RECENT_DEFAULT_MIME "application/octet-stream"
77 GHashTable *apps_lookup;
88 #define GTK_RECENT_MANAGER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_RECENT_MANAGER, GtkRecentManagerPrivate))
90 struct _GtkRecentManagerPrivate
99 GBookmarkFile *recent_items;
101 GFileMonitor *monitor;
113 static void gtk_recent_manager_dispose (GObject *object);
114 static void gtk_recent_manager_finalize (GObject *object);
115 static void gtk_recent_manager_set_property (GObject *object,
119 static void gtk_recent_manager_get_property (GObject *object,
123 static void gtk_recent_manager_add_item_query_info (GObject *source_object,
126 static void gtk_recent_manager_monitor_changed (GFileMonitor *monitor,
129 GFileMonitorEvent event_type,
131 static void gtk_recent_manager_changed (GtkRecentManager *manager);
132 static void gtk_recent_manager_real_changed (GtkRecentManager *manager);
133 static void gtk_recent_manager_set_filename (GtkRecentManager *manager,
134 const gchar *filename);
135 static void gtk_recent_manager_clamp_to_age (GtkRecentManager *manager,
139 static void build_recent_items_list (GtkRecentManager *manager);
140 static void purge_recent_items_list (GtkRecentManager *manager,
143 static RecentAppInfo *recent_app_info_new (const gchar *app_name);
144 static void recent_app_info_free (RecentAppInfo *app_info);
146 static GtkRecentInfo *gtk_recent_info_new (const gchar *uri);
147 static void gtk_recent_info_free (GtkRecentInfo *recent_info);
149 static guint signal_changed = 0;
151 static GtkRecentManager *recent_manager_singleton = NULL;
153 G_DEFINE_TYPE (GtkRecentManager, gtk_recent_manager, G_TYPE_OBJECT)
156 filename_warning (const gchar *format,
157 const gchar *filename,
158 const gchar *message)
160 gchar *utf8 = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
161 g_warning (format, utf8 ? utf8 : "(invalid filename)", message);
165 /* Test of haystack has the needle prefix, comparing case
166 * insensitive. haystack may be UTF-8, but needle must
167 * contain only lowercase ascii. */
169 has_case_prefix (const gchar *haystack,
174 /* Eat one character at a time. */
178 while (*n && *h && *n == g_ascii_tolower (*h))
188 gtk_recent_manager_error_quark (void)
190 return g_quark_from_static_string ("gtk-recent-manager-error-quark");
194 gtk_recent_manager_class_init (GtkRecentManagerClass *klass)
196 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
198 gobject_class->set_property = gtk_recent_manager_set_property;
199 gobject_class->get_property = gtk_recent_manager_get_property;
200 gobject_class->dispose = gtk_recent_manager_dispose;
201 gobject_class->finalize = gtk_recent_manager_finalize;
204 * GtkRecentManager:filename
206 * The full path to the file to be used to store and read the recently
207 * used resources list
211 g_object_class_install_property (gobject_class,
213 g_param_spec_string ("filename",
215 P_("The full path to the file to be used to store and read the list"),
217 (G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE)));
219 * GtkRecentManager:limit
221 * The maximum number of items to be returned by the
222 * gtk_recent_manager_get_items() function.
226 g_object_class_install_property (gobject_class,
228 g_param_spec_int ("limit",
230 P_("The maximum number of items to be returned by gtk_recent_manager_get_items()"),
236 * GtkRecentManager:size
238 * The size of the recently used resources list.
242 g_object_class_install_property (gobject_class,
244 g_param_spec_int ("size",
246 P_("The size of the recently used resources list"),
253 * GtkRecentManager::changed
254 * @recent_manager: the recent manager
256 * Emitted when the current recently used resources manager changes its
262 g_signal_new (I_("changed"),
263 G_TYPE_FROM_CLASS (klass),
265 G_STRUCT_OFFSET (GtkRecentManagerClass, changed),
267 g_cclosure_marshal_VOID__VOID,
270 klass->changed = gtk_recent_manager_real_changed;
272 g_type_class_add_private (klass, sizeof (GtkRecentManagerPrivate));
276 gtk_recent_manager_init (GtkRecentManager *manager)
278 GtkRecentManagerPrivate *priv;
280 manager->priv = priv = GTK_RECENT_MANAGER_GET_PRIVATE (manager);
282 priv->limit = DEFAULT_LIMIT;
285 priv->filename = NULL;
289 gtk_recent_manager_set_property (GObject *object,
294 GtkRecentManager *recent_manager = GTK_RECENT_MANAGER (object);
299 gtk_recent_manager_set_filename (recent_manager, g_value_get_string (value));
302 gtk_recent_manager_set_limit (recent_manager, g_value_get_int (value));
305 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
311 gtk_recent_manager_get_property (GObject *object,
316 GtkRecentManager *recent_manager = GTK_RECENT_MANAGER (object);
321 g_value_set_string (value, recent_manager->priv->filename);
324 g_value_set_int (value, recent_manager->priv->limit);
327 g_value_set_int (value, recent_manager->priv->size);
330 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
336 gtk_recent_manager_dispose (GObject *object)
338 GtkRecentManager *manager = GTK_RECENT_MANAGER (object);
339 GtkRecentManagerPrivate *priv = manager->priv;
343 g_signal_handlers_disconnect_by_func (priv->monitor,
344 G_CALLBACK (gtk_recent_manager_monitor_changed),
346 g_object_unref (priv->monitor);
347 priv->monitor = NULL;
350 G_OBJECT_CLASS (gtk_recent_manager_parent_class)->dispose (object);
354 gtk_recent_manager_finalize (GObject *object)
356 GtkRecentManager *manager = GTK_RECENT_MANAGER (object);
357 GtkRecentManagerPrivate *priv = manager->priv;
359 g_free (priv->filename);
361 if (priv->recent_items)
362 g_bookmark_file_free (priv->recent_items);
364 G_OBJECT_CLASS (gtk_recent_manager_parent_class)->finalize (object);
368 gtk_recent_manager_real_changed (GtkRecentManager *manager)
370 GtkRecentManagerPrivate *priv = manager->priv;
372 g_object_freeze_notify (G_OBJECT (manager));
378 /* we are marked as dirty, so we dump the content of our
379 * recently used items list
381 g_assert (priv->filename != NULL);
383 if (!priv->recent_items)
385 /* if no container object has been defined, we create a new
386 * empty container, and dump it
388 priv->recent_items = g_bookmark_file_new ();
393 GtkSettings *settings = gtk_settings_get_default ();
396 g_object_get (G_OBJECT (settings), "gtk-recent-files-max-age", &age, NULL);
398 gtk_recent_manager_clamp_to_age (manager, age);
401 g_bookmark_file_free (priv->recent_items);
402 priv->recent_items = NULL;
404 priv->recent_items = g_bookmark_file_new ();
409 g_bookmark_file_to_file (priv->recent_items, priv->filename, &write_error);
412 filename_warning ("Attempting to store changes into `%s', "
415 write_error->message);
416 g_error_free (write_error);
419 if (g_chmod (priv->filename, 0600) < 0)
421 filename_warning ("Attempting to set the permissions of `%s', "
427 /* mark us as clean */
428 priv->is_dirty = FALSE;
432 /* we are not marked as dirty, so we have been called
433 * because the recently used resources file has been
434 * changed (and not from us).
436 build_recent_items_list (manager);
439 g_object_thaw_notify (G_OBJECT (manager));
443 gtk_recent_manager_monitor_changed (GFileMonitor *monitor,
446 GFileMonitorEvent event_type,
449 GtkRecentManager *manager = user_data;
453 case G_FILE_MONITOR_EVENT_CHANGED:
454 case G_FILE_MONITOR_EVENT_CREATED:
455 gtk_recent_manager_changed (manager);
458 case G_FILE_MONITOR_EVENT_DELETED:
467 gtk_recent_manager_set_filename (GtkRecentManager *manager,
468 const gchar *filename)
470 GtkRecentManagerPrivate *priv;
474 g_assert (GTK_IS_RECENT_MANAGER (manager));
476 priv = manager->priv;
478 /* if a filename is already set and filename is not NULL, then copy
479 * it and reset the monitor; otherwise, if it's NULL we're being
480 * called from the finalization sequence, so we simply disconnect the
481 * monitoring and return.
483 * if no filename is set and filename is NULL, use the default.
487 g_free (priv->filename);
491 g_signal_handlers_disconnect_by_func (priv->monitor,
492 G_CALLBACK (gtk_recent_manager_monitor_changed),
494 g_object_unref (priv->monitor);
495 priv->monitor = NULL;
498 if (!filename || *filename == '\0')
501 priv->filename = g_strdup (filename);
505 if (!filename || *filename == '\0')
506 priv->filename = g_build_filename (g_get_home_dir (),
507 GTK_RECENTLY_USED_FILE,
510 priv->filename = g_strdup (filename);
513 g_assert (priv->filename != NULL);
514 file = g_file_new_for_path (priv->filename);
517 priv->monitor = g_file_monitor_file (file, G_FILE_MONITOR_NONE, NULL, &error);
520 filename_warning ("Unable to monitor `%s': %s\n"
521 "The GtkRecentManager will not update its contents "
522 "if the file is changed from other instances",
525 g_error_free (error);
528 g_signal_connect (priv->monitor, "changed",
529 G_CALLBACK (gtk_recent_manager_monitor_changed),
532 g_object_unref (file);
534 priv->is_dirty = FALSE;
535 build_recent_items_list (manager);
538 /* reads the recently used resources file and builds the items list.
539 * we keep the items list inside the parser object, and build the
540 * RecentInfo object only on user's demand to avoid useless replication.
541 * this function resets the dirty bit of the manager.
544 build_recent_items_list (GtkRecentManager *manager)
546 GtkRecentManagerPrivate *priv = manager->priv;
550 g_assert (priv->filename != NULL);
552 if (!priv->recent_items)
554 priv->recent_items = g_bookmark_file_new ();
558 /* the file exists, and it's valid (we hope); if not, destroy the container
559 * object and hope for a better result when the next "changed" signal is
562 g_bookmark_file_load_from_file (priv->recent_items, priv->filename, &read_error);
565 /* if the file does not exist we just wait for the first write
566 * operation on this recent manager instance, to avoid creating
567 * empty files and leading to spurious file system events (Sabayon
568 * will not be happy about those)
570 if (read_error->domain == G_FILE_ERROR &&
571 read_error->code != G_FILE_ERROR_NOENT)
572 filename_warning ("Attempting to read the recently used resources "
573 "file at `%s', but the parser failed: %s.",
575 read_error->message);
577 g_bookmark_file_free (priv->recent_items);
578 priv->recent_items = NULL;
580 g_error_free (read_error);
584 size = g_bookmark_file_get_size (priv->recent_items);
585 if (priv->size != size)
589 g_object_notify (G_OBJECT (manager), "size");
593 priv->is_dirty = FALSE;
597 /********************
599 ********************/
603 * gtk_recent_manager_new:
605 * Creates a new recent manager object. Recent manager objects are used to
606 * handle the list of recently used resources. A #GtkRecentManager object
607 * monitors the recently used resources list, and emits the "changed" signal
608 * each time something inside the list changes.
610 * #GtkRecentManager objects are expensive: be sure to create them only when
611 * needed. You should use gtk_recent_manager_get_default() instead.
613 * Return value: A newly created #GtkRecentManager object.
618 gtk_recent_manager_new (void)
620 return g_object_new (GTK_TYPE_RECENT_MANAGER, NULL);
624 * gtk_recent_manager_get_default:
626 * Gets a unique instance of #GtkRecentManager, that you can share
627 * in your application without caring about memory management. The
628 * returned instance will be freed when you application terminates.
630 * Return value: (transfer none): A unique #GtkRecentManager. Do not ref or unref it.
635 gtk_recent_manager_get_default (void)
637 if (G_UNLIKELY (!recent_manager_singleton))
638 recent_manager_singleton = gtk_recent_manager_new ();
640 return recent_manager_singleton;
644 * gtk_recent_manager_set_limit:
645 * @manager: a #GtkRecentManager
646 * @limit: the maximum number of items to return, or -1.
648 * Sets the maximum number of item that the gtk_recent_manager_get_items()
649 * function should return. If @limit is set to -1, then return all the
655 gtk_recent_manager_set_limit (GtkRecentManager *manager,
658 GtkRecentManagerPrivate *priv;
660 g_return_if_fail (GTK_IS_RECENT_MANAGER (manager));
662 priv = manager->priv;
667 * gtk_recent_manager_get_limit:
668 * @manager: a #GtkRecentManager
670 * Gets the maximum number of items that the gtk_recent_manager_get_items()
671 * function should return.
673 * Return value: the number of items to return, or -1 for every item.
678 gtk_recent_manager_get_limit (GtkRecentManager *manager)
680 GtkRecentManagerPrivate *priv;
682 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), DEFAULT_LIMIT);
684 priv = manager->priv;
689 gtk_recent_manager_add_item_query_info (GObject *source_object,
693 GFile *file = G_FILE (source_object);
694 GtkRecentManager *manager = user_data;
695 GtkRecentData recent_data;
696 GFileInfo *file_info;
700 uri = g_file_get_uri (file);
703 file_info = g_file_query_info_finish (file, res, &error);
706 g_warning ("Unable to retrieve the file info for `%s': %s",
709 g_error_free (error);
713 recent_data.display_name = NULL;
714 recent_data.description = NULL;
720 content_type = g_file_info_get_attribute_as_string (file_info, G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE);
722 if (G_LIKELY (content_type))
723 recent_data.mime_type = g_content_type_get_mime_type (content_type);
725 recent_data.mime_type = g_strdup (GTK_RECENT_DEFAULT_MIME);
727 g_free (content_type);
728 g_object_unref (file_info);
731 recent_data.mime_type = g_strdup (GTK_RECENT_DEFAULT_MIME);
733 recent_data.app_name = g_strdup (g_get_application_name ());
734 recent_data.app_exec = g_strjoin (" ", g_get_prgname (), "%u", NULL);
735 recent_data.groups = NULL;
736 recent_data.is_private = FALSE;
738 /* Ignore return value, this can't fail anyway since all required
740 gtk_recent_manager_add_full (manager, uri, &recent_data);
742 manager->priv->is_dirty = TRUE;
743 gtk_recent_manager_changed (manager);
745 g_free (recent_data.mime_type);
746 g_free (recent_data.app_name);
747 g_free (recent_data.app_exec);
750 g_object_unref (manager);
755 * gtk_recent_manager_add_item:
756 * @manager: a #GtkRecentManager
759 * Adds a new resource, pointed by @uri, into the recently used
762 * This function automatically retrieves some of the needed
763 * metadata and setting other metadata to common default values; it
764 * then feeds the data to gtk_recent_manager_add_full().
766 * See gtk_recent_manager_add_full() if you want to explicitly
767 * define the metadata for the resource pointed by @uri.
769 * Return value: %TRUE if the new item was successfully added
770 * to the recently used resources list
775 gtk_recent_manager_add_item (GtkRecentManager *manager,
780 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), FALSE);
781 g_return_val_if_fail (uri != NULL, FALSE);
783 file = g_file_new_for_uri (uri);
785 g_file_query_info_async (file,
786 G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE,
788 G_FILE_QUERY_INFO_NONE,
790 gtk_recent_manager_add_item_query_info,
791 g_object_ref (manager));
793 g_object_unref (file);
799 * gtk_recent_manager_add_full:
800 * @manager: a #GtkRecentManager
802 * @recent_data: metadata of the resource
804 * Adds a new resource, pointed by @uri, into the recently used
805 * resources list, using the metadata specified inside the #GtkRecentData
806 * structure passed in @recent_data.
808 * The passed URI will be used to identify this resource inside the
811 * In order to register the new recently used resource, metadata about
812 * the resource must be passed as well as the URI; the metadata is
813 * stored in a #GtkRecentData structure, which must contain the MIME
814 * type of the resource pointed by the URI; the name of the application
815 * that is registering the item, and a command line to be used when
816 * launching the item.
818 * Optionally, a #GtkRecentData structure might contain a UTF-8 string
819 * to be used when viewing the item instead of the last component of the
820 * URI; a short description of the item; whether the item should be
821 * considered private - that is, should be displayed only by the
822 * applications that have registered it.
824 * Return value: %TRUE if the new item was successfully added to the
825 * recently used resources list, %FALSE otherwise.
830 gtk_recent_manager_add_full (GtkRecentManager *manager,
832 const GtkRecentData *data)
834 GtkRecentManagerPrivate *priv;
836 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), FALSE);
837 g_return_val_if_fail (uri != NULL, FALSE);
838 g_return_val_if_fail (data != NULL, FALSE);
841 if ((data->display_name) &&
842 (!g_utf8_validate (data->display_name, -1, NULL)))
844 g_warning ("Attempting to add `%s' to the list of recently used "
845 "resources, but the display name is not a valid UTF-8 "
851 if ((data->description) &&
852 (!g_utf8_validate (data->description, -1, NULL)))
854 g_warning ("Attempting to add `%s' to the list of recently used "
855 "resources, but the description is not a valid UTF-8 "
862 if (!data->mime_type)
864 g_warning ("Attempting to add `%s' to the list of recently used "
865 "resources, but not MIME type was defined",
872 g_warning ("Attempting to add `%s' to the list of recently used "
873 "resources, but no name of the application that is "
874 "registering it was defined",
881 g_warning ("Attempting to add `%s' to the list of recently used "
882 "resources, but no command line for the application "
883 "that is registering it was defined",
888 priv = manager->priv;
890 if (!priv->recent_items)
892 priv->recent_items = g_bookmark_file_new ();
896 if (data->display_name)
897 g_bookmark_file_set_title (priv->recent_items, uri, data->display_name);
899 if (data->description)
900 g_bookmark_file_set_description (priv->recent_items, uri, data->description);
902 g_bookmark_file_set_mime_type (priv->recent_items, uri, data->mime_type);
904 if (data->groups && data->groups[0] != '\0')
908 for (j = 0; (data->groups)[j] != NULL; j++)
909 g_bookmark_file_add_group (priv->recent_items, uri, (data->groups)[j]);
912 /* register the application; this will take care of updating the
913 * registration count and time in case the application has
914 * already registered the same document inside the list
916 g_bookmark_file_add_application (priv->recent_items, uri,
920 g_bookmark_file_set_is_private (priv->recent_items, uri,
923 /* mark us as dirty, so that when emitting the "changed" signal we
924 * will dump our changes
926 priv->is_dirty = TRUE;
928 gtk_recent_manager_changed (manager);
934 * gtk_recent_manager_remove_item:
935 * @manager: a #GtkRecentManager
936 * @uri: the URI of the item you wish to remove
937 * @error: (allow-none): return location for a #GError, or %NULL
939 * Removes a resource pointed by @uri from the recently used resources
940 * list handled by a recent manager.
942 * Return value: %TRUE if the item pointed by @uri has been successfully
943 * removed by the recently used resources list, and %FALSE otherwise.
948 gtk_recent_manager_remove_item (GtkRecentManager *manager,
952 GtkRecentManagerPrivate *priv;
953 GError *remove_error = NULL;
955 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), FALSE);
956 g_return_val_if_fail (uri != NULL, FALSE);
957 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
959 priv = manager->priv;
961 if (!priv->recent_items)
963 priv->recent_items = g_bookmark_file_new ();
966 g_set_error (error, GTK_RECENT_MANAGER_ERROR,
967 GTK_RECENT_MANAGER_ERROR_NOT_FOUND,
968 _("Unable to find an item with URI '%s'"),
974 g_bookmark_file_remove_item (priv->recent_items, uri, &remove_error);
977 g_error_free (remove_error);
979 g_set_error (error, GTK_RECENT_MANAGER_ERROR,
980 GTK_RECENT_MANAGER_ERROR_NOT_FOUND,
981 _("Unable to find an item with URI '%s'"),
987 priv->is_dirty = TRUE;
989 gtk_recent_manager_changed (manager);
995 * gtk_recent_manager_has_item:
996 * @manager: a #GtkRecentManager
999 * Checks whether there is a recently used resource registered
1000 * with @uri inside the recent manager.
1002 * Return value: %TRUE if the resource was found, %FALSE otherwise.
1007 gtk_recent_manager_has_item (GtkRecentManager *manager,
1010 GtkRecentManagerPrivate *priv;
1012 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), FALSE);
1013 g_return_val_if_fail (uri != NULL, FALSE);
1015 priv = manager->priv;
1016 g_return_val_if_fail (priv->recent_items != NULL, FALSE);
1018 return g_bookmark_file_has_item (priv->recent_items, uri);
1022 build_recent_info (GBookmarkFile *bookmarks,
1023 GtkRecentInfo *info)
1025 gchar **apps, **groups;
1026 gsize apps_len, groups_len, i;
1028 g_assert (bookmarks != NULL);
1029 g_assert (info != NULL);
1031 info->display_name = g_bookmark_file_get_title (bookmarks, info->uri, NULL);
1032 info->description = g_bookmark_file_get_description (bookmarks, info->uri, NULL);
1033 info->mime_type = g_bookmark_file_get_mime_type (bookmarks, info->uri, NULL);
1035 info->is_private = g_bookmark_file_get_is_private (bookmarks, info->uri, NULL);
1037 info->added = g_bookmark_file_get_added (bookmarks, info->uri, NULL);
1038 info->modified = g_bookmark_file_get_modified (bookmarks, info->uri, NULL);
1039 info->visited = g_bookmark_file_get_visited (bookmarks, info->uri, NULL);
1041 groups = g_bookmark_file_get_groups (bookmarks, info->uri, &groups_len, NULL);
1042 for (i = 0; i < groups_len; i++)
1044 gchar *group_name = g_strdup (groups[i]);
1046 info->groups = g_slist_append (info->groups, group_name);
1049 g_strfreev (groups);
1051 apps = g_bookmark_file_get_applications (bookmarks, info->uri, &apps_len, NULL);
1052 for (i = 0; i < apps_len; i++)
1054 gchar *app_name, *app_exec;
1057 RecentAppInfo *app_info;
1062 res = g_bookmark_file_get_app_info (bookmarks, info->uri, app_name,
1070 app_info = recent_app_info_new (app_name);
1071 app_info->exec = app_exec;
1072 app_info->count = count;
1073 app_info->stamp = stamp;
1075 info->applications = g_slist_prepend (info->applications, app_info);
1076 g_hash_table_replace (info->apps_lookup, app_info->name, app_info);
1083 * gtk_recent_manager_lookup_item:
1084 * @manager: a #GtkRecentManager
1086 * @error: (allow-none): a return location for a #GError, or %NULL
1088 * Searches for a URI inside the recently used resources list, and
1089 * returns a structure containing informations about the resource
1090 * like its MIME type, or its display name.
1092 * Return value: a #GtkRecentInfo structure containing information
1093 * about the resource pointed by @uri, or %NULL if the URI was
1094 * not registered in the recently used resources list. Free with
1095 * gtk_recent_info_unref().
1100 gtk_recent_manager_lookup_item (GtkRecentManager *manager,
1104 GtkRecentManagerPrivate *priv;
1105 GtkRecentInfo *info = NULL;
1107 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), NULL);
1108 g_return_val_if_fail (uri != NULL, NULL);
1109 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
1111 priv = manager->priv;
1112 if (!priv->recent_items)
1114 priv->recent_items = g_bookmark_file_new ();
1117 g_set_error (error, GTK_RECENT_MANAGER_ERROR,
1118 GTK_RECENT_MANAGER_ERROR_NOT_FOUND,
1119 _("Unable to find an item with URI '%s'"),
1125 if (!g_bookmark_file_has_item (priv->recent_items, uri))
1127 g_set_error (error, GTK_RECENT_MANAGER_ERROR,
1128 GTK_RECENT_MANAGER_ERROR_NOT_FOUND,
1129 _("Unable to find an item with URI '%s'"),
1134 info = gtk_recent_info_new (uri);
1135 g_return_val_if_fail (info != NULL, NULL);
1137 /* fill the RecentInfo structure with the data retrieved by our
1138 * parser object from the storage file
1140 build_recent_info (priv->recent_items, info);
1146 * gtk_recent_manager_move_item:
1147 * @manager: a #GtkRecentManager
1148 * @uri: the URI of a recently used resource
1149 * @new_uri: (allow-none): the new URI of the recently used resource, or %NULL to
1150 * remove the item pointed by @uri in the list
1151 * @error: (allow-none): a return location for a #GError, or %NULL
1153 * Changes the location of a recently used resource from @uri to @new_uri.
1155 * Please note that this function will not affect the resource pointed
1156 * by the URIs, but only the URI used in the recently used resources list.
1158 * Return value: %TRUE on success.
1163 gtk_recent_manager_move_item (GtkRecentManager *recent_manager,
1165 const gchar *new_uri,
1168 GtkRecentManagerPrivate *priv;
1172 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (recent_manager), FALSE);
1173 g_return_val_if_fail (uri != NULL, FALSE);
1174 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
1176 priv = recent_manager->priv;
1178 if (!priv->recent_items)
1180 g_set_error (error, GTK_RECENT_MANAGER_ERROR,
1181 GTK_RECENT_MANAGER_ERROR_NOT_FOUND,
1182 _("Unable to find an item with URI '%s'"),
1187 if (!g_bookmark_file_has_item (priv->recent_items, uri))
1189 g_set_error (error, GTK_RECENT_MANAGER_ERROR,
1190 GTK_RECENT_MANAGER_ERROR_NOT_FOUND,
1191 _("Unable to find an item with URI '%s'"),
1197 res = g_bookmark_file_move_item (priv->recent_items,
1202 g_error_free (move_error);
1204 g_set_error (error, GTK_RECENT_MANAGER_ERROR,
1205 GTK_RECENT_MANAGER_ERROR_NOT_FOUND,
1206 _("Unable to find an item with URI '%s'"),
1211 priv->is_dirty = TRUE;
1213 gtk_recent_manager_changed (recent_manager);
1219 * gtk_recent_manager_get_items:
1220 * @manager: a #GtkRecentManager
1222 * Gets the list of recently used resources.
1224 * Return value: (element-type GtkRecentInfo) (transfer full): a list of
1225 * newly allocated #GtkRecentInfo objects. Use
1226 * gtk_recent_info_unref() on each item inside the list, and then
1227 * free the list itself using g_list_free().
1232 gtk_recent_manager_get_items (GtkRecentManager *manager)
1234 GtkRecentManagerPrivate *priv;
1235 GList *retval = NULL;
1239 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), NULL);
1241 priv = manager->priv;
1242 if (!priv->recent_items)
1245 if (priv->limit == 0)
1248 uris = g_bookmark_file_get_uris (priv->recent_items, &uris_len);
1249 for (i = 0; i < uris_len; i++)
1251 GtkRecentInfo *info;
1253 if (priv->limit != -1 && i == priv->limit)
1256 info = gtk_recent_info_new (uris[i]);
1257 build_recent_info (priv->recent_items, info);
1259 retval = g_list_prepend (retval, info);
1268 purge_recent_items_list (GtkRecentManager *manager,
1271 GtkRecentManagerPrivate *priv = manager->priv;
1273 if (!priv->recent_items)
1276 g_bookmark_file_free (priv->recent_items);
1277 priv->recent_items = NULL;
1279 priv->recent_items = g_bookmark_file_new ();
1281 priv->is_dirty = TRUE;
1283 /* emit the changed signal, to ensure that the purge is written */
1284 gtk_recent_manager_changed (manager);
1288 * gtk_recent_manager_purge_items:
1289 * @manager: a #GtkRecentManager
1290 * @error: (allow-none): a return location for a #GError, or %NULL
1292 * Purges every item from the recently used resources list.
1294 * Return value: the number of items that have been removed from the
1295 * recently used resources list.
1300 gtk_recent_manager_purge_items (GtkRecentManager *manager,
1303 GtkRecentManagerPrivate *priv;
1306 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), -1);
1308 priv = manager->priv;
1309 if (!priv->recent_items)
1312 count = g_bookmark_file_get_size (priv->recent_items);
1316 purge_recent_items_list (manager, error);
1318 purged = count - g_bookmark_file_get_size (priv->recent_items);
1324 gtk_recent_manager_changed (GtkRecentManager *recent_manager)
1326 g_signal_emit (recent_manager, signal_changed, 0);
1330 gtk_recent_manager_clamp_to_age (GtkRecentManager *manager,
1333 GtkRecentManagerPrivate *priv = manager->priv;
1338 if (G_UNLIKELY (!priv->recent_items))
1343 uris = g_bookmark_file_get_uris (priv->recent_items, &n_uris);
1345 for (i = 0; i < n_uris; i++)
1347 const gchar *uri = uris[i];
1351 modified = g_bookmark_file_get_modified (priv->recent_items, uri, NULL);
1352 item_age = (gint) ((now - modified) / (60 * 60 * 24));
1354 g_bookmark_file_remove_item (priv->recent_items, uri, NULL);
1365 gtk_recent_info_get_type (void)
1367 static GType info_type = 0;
1370 info_type = g_boxed_type_register_static (I_("GtkRecentInfo"),
1371 (GBoxedCopyFunc) gtk_recent_info_ref,
1372 (GBoxedFreeFunc) gtk_recent_info_unref);
1376 static GtkRecentInfo *
1377 gtk_recent_info_new (const gchar *uri)
1379 GtkRecentInfo *info;
1381 g_assert (uri != NULL);
1383 info = g_new0 (GtkRecentInfo, 1);
1384 info->uri = g_strdup (uri);
1386 info->applications = NULL;
1387 info->apps_lookup = g_hash_table_new (g_str_hash, g_str_equal);
1389 info->groups = NULL;
1391 info->ref_count = 1;
1397 gtk_recent_info_free (GtkRecentInfo *recent_info)
1402 g_free (recent_info->uri);
1403 g_free (recent_info->display_name);
1404 g_free (recent_info->description);
1405 g_free (recent_info->mime_type);
1407 if (recent_info->applications)
1409 g_slist_foreach (recent_info->applications,
1410 (GFunc) recent_app_info_free,
1412 g_slist_free (recent_info->applications);
1414 recent_info->applications = NULL;
1417 if (recent_info->apps_lookup)
1418 g_hash_table_destroy (recent_info->apps_lookup);
1420 if (recent_info->groups)
1422 g_slist_foreach (recent_info->groups,
1425 g_slist_free (recent_info->groups);
1427 recent_info->groups = NULL;
1430 if (recent_info->icon)
1431 g_object_unref (recent_info->icon);
1433 g_free (recent_info);
1437 * gtk_recent_info_ref:
1438 * @info: a #GtkRecentInfo
1440 * Increases the reference count of @recent_info by one.
1442 * Return value: the recent info object with its reference count increased
1448 gtk_recent_info_ref (GtkRecentInfo *info)
1450 g_return_val_if_fail (info != NULL, NULL);
1451 g_return_val_if_fail (info->ref_count > 0, NULL);
1453 info->ref_count += 1;
1459 * gtk_recent_info_unref:
1460 * @info: a #GtkRecentInfo
1462 * Decreases the reference count of @info by one. If the reference
1463 * count reaches zero, @info is deallocated, and the memory freed.
1468 gtk_recent_info_unref (GtkRecentInfo *info)
1470 g_return_if_fail (info != NULL);
1471 g_return_if_fail (info->ref_count > 0);
1473 info->ref_count -= 1;
1475 if (info->ref_count == 0)
1476 gtk_recent_info_free (info);
1480 * gtk_recent_info_get_uri:
1481 * @info: a #GtkRecentInfo
1483 * Gets the URI of the resource.
1485 * Return value: the URI of the resource. The returned string is
1486 * owned by the recent manager, and should not be freed.
1490 G_CONST_RETURN gchar *
1491 gtk_recent_info_get_uri (GtkRecentInfo *info)
1493 g_return_val_if_fail (info != NULL, NULL);
1499 * gtk_recent_info_get_display_name:
1500 * @info: a #GtkRecentInfo
1502 * Gets the name of the resource. If none has been defined, the basename
1503 * of the resource is obtained.
1505 * Return value: the display name of the resource. The returned string
1506 * is owned by the recent manager, and should not be freed.
1510 G_CONST_RETURN gchar *
1511 gtk_recent_info_get_display_name (GtkRecentInfo *info)
1513 g_return_val_if_fail (info != NULL, NULL);
1515 if (!info->display_name)
1516 info->display_name = gtk_recent_info_get_short_name (info);
1518 return info->display_name;
1522 * gtk_recent_info_get_description:
1523 * @info: a #GtkRecentInfo
1525 * Gets the (short) description of the resource.
1527 * Return value: the description of the resource. The returned string
1528 * is owned by the recent manager, and should not be freed.
1532 G_CONST_RETURN gchar *
1533 gtk_recent_info_get_description (GtkRecentInfo *info)
1535 g_return_val_if_fail (info != NULL, NULL);
1537 return info->description;
1541 * gtk_recent_info_get_mime_type:
1542 * @info: a #GtkRecentInfo
1544 * Gets the MIME type of the resource.
1546 * Return value: the MIME type of the resource. The returned string
1547 * is owned by the recent manager, and should not be freed.
1551 G_CONST_RETURN gchar *
1552 gtk_recent_info_get_mime_type (GtkRecentInfo *info)
1554 g_return_val_if_fail (info != NULL, NULL);
1556 if (!info->mime_type)
1557 info->mime_type = g_strdup (GTK_RECENT_DEFAULT_MIME);
1559 return info->mime_type;
1563 * gtk_recent_info_get_added:
1564 * @info: a #GtkRecentInfo
1566 * Gets the timestamp (seconds from system's Epoch) when the resource
1567 * was added to the recently used resources list.
1569 * Return value: the number of seconds elapsed from system's Epoch when
1570 * the resource was added to the list, or -1 on failure.
1575 gtk_recent_info_get_added (GtkRecentInfo *info)
1577 g_return_val_if_fail (info != NULL, (time_t) -1);
1583 * gtk_recent_info_get_modified:
1584 * @info: a #GtkRecentInfo
1586 * Gets the timestamp (seconds from system's Epoch) when the resource
1587 * was last modified.
1589 * Return value: the number of seconds elapsed from system's Epoch when
1590 * the resource was last modified, or -1 on failure.
1595 gtk_recent_info_get_modified (GtkRecentInfo *info)
1597 g_return_val_if_fail (info != NULL, (time_t) -1);
1599 return info->modified;
1603 * gtk_recent_info_get_visited:
1604 * @info: a #GtkRecentInfo
1606 * Gets the timestamp (seconds from system's Epoch) when the resource
1609 * Return value: the number of seconds elapsed from system's Epoch when
1610 * the resource was last visited, or -1 on failure.
1615 gtk_recent_info_get_visited (GtkRecentInfo *info)
1617 g_return_val_if_fail (info != NULL, (time_t) -1);
1619 return info->visited;
1623 * gtk_recent_info_get_private_hint:
1624 * @info: a #GtkRecentInfo
1626 * Gets the value of the "private" flag. Resources in the recently used
1627 * list that have this flag set to %TRUE should only be displayed by the
1628 * applications that have registered them.
1630 * Return value: %TRUE if the private flag was found, %FALSE otherwise.
1635 gtk_recent_info_get_private_hint (GtkRecentInfo *info)
1637 g_return_val_if_fail (info != NULL, FALSE);
1639 return info->is_private;
1643 static RecentAppInfo *
1644 recent_app_info_new (const gchar *app_name)
1646 RecentAppInfo *app_info;
1648 g_assert (app_name != NULL);
1650 app_info = g_slice_new0 (RecentAppInfo);
1651 app_info->name = g_strdup (app_name);
1652 app_info->exec = NULL;
1653 app_info->count = 1;
1654 app_info->stamp = 0;
1660 recent_app_info_free (RecentAppInfo *app_info)
1665 g_free (app_info->name);
1666 g_free (app_info->exec);
1668 g_slice_free (RecentAppInfo, app_info);
1672 * gtk_recent_info_get_application_info:
1673 * @info: a #GtkRecentInfo
1674 * @app_name: the name of the application that has registered this item
1675 * @app_exec: (transfer none) (out): return location for the string containing the command line
1676 * @count: (out): return location for the number of times this item was registered
1677 * @time_: (out): return location for the timestamp this item was last registered
1678 * for this application
1680 * Gets the data regarding the application that has registered the resource
1683 * If the command line contains any escape characters defined inside the
1684 * storage specification, they will be expanded.
1686 * Return value: %TRUE if an application with @app_name has registered this
1687 * resource inside the recently used list, or %FALSE otherwise. The
1688 * @app_exec string is owned by the #GtkRecentInfo and should not be
1694 gtk_recent_info_get_application_info (GtkRecentInfo *info,
1695 const gchar *app_name,
1696 const gchar **app_exec,
1702 g_return_val_if_fail (info != NULL, FALSE);
1703 g_return_val_if_fail (app_name != NULL, FALSE);
1705 ai = (RecentAppInfo *) g_hash_table_lookup (info->apps_lookup,
1709 g_warning ("No registered application with name '%s' "
1710 "for item with URI '%s' found",
1717 *app_exec = ai->exec;
1729 * gtk_recent_info_get_applications:
1730 * @info: a #GtkRecentInfo
1731 * @length: (out) (allow-none): return location for the length of the returned list
1733 * Retrieves the list of applications that have registered this resource.
1735 * Return value: (array length=length zero-terminated=1): a newly allocated
1736 * %NULL-terminated array of strings. Use g_strfreev() to free it.
1741 gtk_recent_info_get_applications (GtkRecentInfo *info,
1748 g_return_val_if_fail (info != NULL, NULL);
1750 if (!info->applications)
1758 n_apps = g_slist_length (info->applications);
1760 retval = g_new0 (gchar *, n_apps + 1);
1762 for (l = info->applications, i = 0;
1766 RecentAppInfo *ai = (RecentAppInfo *) l->data;
1768 g_assert (ai != NULL);
1770 retval[i++] = g_strdup (ai->name);
1781 * gtk_recent_info_has_application:
1782 * @info: a #GtkRecentInfo
1783 * @app_name: a string containing an application name
1785 * Checks whether an application registered this resource using @app_name.
1787 * Return value: %TRUE if an application with name @app_name was found,
1793 gtk_recent_info_has_application (GtkRecentInfo *info,
1794 const gchar *app_name)
1796 g_return_val_if_fail (info != NULL, FALSE);
1797 g_return_val_if_fail (app_name != NULL, FALSE);
1799 return (NULL != g_hash_table_lookup (info->apps_lookup, app_name));
1803 * gtk_recent_info_last_application:
1804 * @info: a #GtkRecentInfo
1806 * Gets the name of the last application that have registered the
1807 * recently used resource represented by @info.
1809 * Return value: an application name. Use g_free() to free it.
1814 gtk_recent_info_last_application (GtkRecentInfo *info)
1817 time_t last_stamp = (time_t) -1;
1820 g_return_val_if_fail (info != NULL, NULL);
1822 for (l = info->applications; l != NULL; l = l->next)
1824 RecentAppInfo *ai = (RecentAppInfo *) l->data;
1826 if (ai->stamp > last_stamp)
1829 last_stamp = ai->stamp;
1833 return g_strdup (name);
1837 get_icon_for_mime_type (const char *mime_type,
1840 GtkIconTheme *icon_theme;
1846 icon_theme = gtk_icon_theme_get_default ();
1848 content_type = g_content_type_from_mime_type (mime_type);
1853 icon = g_content_type_get_icon (content_type);
1854 info = gtk_icon_theme_lookup_by_gicon (icon_theme,
1857 GTK_ICON_LOOKUP_USE_BUILTIN);
1858 g_free (content_type);
1859 g_object_unref (icon);
1864 pixbuf = gtk_icon_info_load_icon (info, NULL);
1865 gtk_icon_info_free (info);
1871 get_icon_fallback (const gchar *icon_name,
1874 GtkIconTheme *icon_theme;
1877 icon_theme = gtk_icon_theme_get_default ();
1879 retval = gtk_icon_theme_load_icon (icon_theme, icon_name,
1881 GTK_ICON_LOOKUP_USE_BUILTIN,
1883 g_assert (retval != NULL);
1889 * gtk_recent_info_get_icon:
1890 * @info: a #GtkRecentInfo
1891 * @size: the size of the icon in pixels
1893 * Retrieves the icon of size @size associated to the resource MIME type.
1895 * Return value: a #GdkPixbuf containing the icon, or %NULL. Use
1896 * g_object_unref() when finished using the icon.
1901 gtk_recent_info_get_icon (GtkRecentInfo *info,
1904 GdkPixbuf *retval = NULL;
1906 g_return_val_if_fail (info != NULL, NULL);
1908 if (info->mime_type)
1909 retval = get_icon_for_mime_type (info->mime_type, size);
1911 /* this function should never fail */
1914 if (info->mime_type &&
1915 strcmp (info->mime_type, "x-directory/normal") == 0)
1916 retval = get_icon_fallback (GTK_STOCK_DIRECTORY, size);
1918 retval = get_icon_fallback (GTK_STOCK_FILE, size);
1925 * gtk_recent_info_is_local:
1926 * @info: a #GtkRecentInfo
1928 * Checks whether the resource is local or not by looking at the
1929 * scheme of its URI.
1931 * Return value: %TRUE if the resource is local.
1936 gtk_recent_info_is_local (GtkRecentInfo *info)
1938 g_return_val_if_fail (info != NULL, FALSE);
1940 return has_case_prefix (info->uri, "file:/");
1944 * gtk_recent_info_exists:
1945 * @info: a #GtkRecentInfo
1947 * Checks whether the resource pointed by @info still exists. At
1948 * the moment this check is done only on resources pointing to local files.
1950 * Return value: %TRUE if the resource exists
1955 gtk_recent_info_exists (GtkRecentInfo *info)
1958 struct stat stat_buf;
1959 gboolean retval = FALSE;
1961 g_return_val_if_fail (info != NULL, FALSE);
1963 /* we guarantee only local resources */
1964 if (!gtk_recent_info_is_local (info))
1967 filename = g_filename_from_uri (info->uri, NULL, NULL);
1970 if (stat (filename, &stat_buf) == 0)
1980 * gtk_recent_info_match:
1981 * @info_a: a #GtkRecentInfo
1982 * @info_b: a #GtkRecentInfo
1984 * Checks whether two #GtkRecentInfo structures point to the same
1987 * Return value: %TRUE if both #GtkRecentInfo structures point to se same
1988 * resource, %FALSE otherwise.
1993 gtk_recent_info_match (GtkRecentInfo *info_a,
1994 GtkRecentInfo *info_b)
1996 g_return_val_if_fail (info_a != NULL, FALSE);
1997 g_return_val_if_fail (info_b != NULL, FALSE);
1999 return (0 == strcmp (info_a->uri, info_b->uri));
2002 /* taken from gnome-vfs-uri.c */
2003 static const gchar *
2004 get_method_string (const gchar *substring,
2005 gchar **method_string)
2011 g_ascii_isalnum (*p) || *p == '+' || *p == '-' || *p == '.';
2018 !(p == substring + 1 && g_ascii_isalpha (*substring))
2022 /* Found toplevel method specification. */
2023 method = g_strndup (substring, p - substring);
2024 *method_string = g_ascii_strdown (method, -1);
2030 *method_string = g_strdup ("file");
2037 /* Stolen from gnome_vfs_make_valid_utf8() */
2039 make_valid_utf8 (const char *name)
2042 const char *remainder, *invalid;
2043 int remaining_bytes, valid_bytes;
2047 remaining_bytes = name ? strlen (name) : 0;
2049 while (remaining_bytes != 0)
2051 if (g_utf8_validate (remainder, remaining_bytes, &invalid))
2054 valid_bytes = invalid - remainder;
2057 string = g_string_sized_new (remaining_bytes);
2059 g_string_append_len (string, remainder, valid_bytes);
2060 g_string_append_c (string, '?');
2062 remaining_bytes -= valid_bytes + 1;
2063 remainder = invalid + 1;
2067 return g_strdup (name);
2069 g_string_append (string, remainder);
2070 g_assert (g_utf8_validate (string->str, -1, NULL));
2072 return g_string_free (string, FALSE);
2076 get_uri_shortname_for_display (const gchar *uri)
2079 gboolean validated = FALSE;
2081 if (has_case_prefix (uri, "file:/"))
2085 local_file = g_filename_from_uri (uri, NULL, NULL);
2089 name = g_filename_display_basename (local_file);
2093 g_free (local_file);
2102 rest = get_method_string (uri, &method);
2103 local_file = g_filename_display_basename (rest);
2105 name = g_strconcat (method, ": ", local_file, NULL);
2107 g_free (local_file);
2111 g_assert (name != NULL);
2113 if (!validated && !g_utf8_validate (name, -1, NULL))
2117 utf8_name = make_valid_utf8 (name);
2127 * gtk_recent_info_get_short_name:
2128 * @info: an #GtkRecentInfo
2130 * Computes a valid UTF-8 string that can be used as the name of the item in a
2131 * menu or list. For example, calling this function on an item that refers to
2132 * "file:///foo/bar.txt" will yield "bar.txt".
2134 * Return value: A newly-allocated string in UTF-8 encoding; free it with
2140 gtk_recent_info_get_short_name (GtkRecentInfo *info)
2144 g_return_val_if_fail (info != NULL, NULL);
2146 if (info->uri == NULL)
2149 short_name = get_uri_shortname_for_display (info->uri);
2155 * gtk_recent_info_get_uri_display:
2156 * @info: a #GtkRecentInfo
2158 * Gets a displayable version of the resource's URI. If the resource
2159 * is local, it returns a local path; if the resource is not local,
2160 * it returns the UTF-8 encoded content of gtk_recent_info_get_uri().
2162 * Return value: a newly allocated UTF-8 string containing the
2163 * resource's URI or %NULL. Use g_free() when done using it.
2168 gtk_recent_info_get_uri_display (GtkRecentInfo *info)
2172 g_return_val_if_fail (info != NULL, NULL);
2175 if (gtk_recent_info_is_local (info))
2179 filename = g_filename_from_uri (info->uri, NULL, NULL);
2183 retval = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
2188 retval = make_valid_utf8 (info->uri);
2195 * gtk_recent_info_get_age:
2196 * @info: a #GtkRecentInfo
2198 * Gets the number of days elapsed since the last update of the resource
2201 * Return value: a positive integer containing the number of days elapsed
2202 * since the time this resource was last modified.
2207 gtk_recent_info_get_age (GtkRecentInfo *info)
2212 g_return_val_if_fail (info != NULL, -1);
2216 delta = now - info->modified;
2218 retval = (gint) (delta / (60 * 60 * 24));
2224 * gtk_recent_info_get_groups:
2225 * @info: a #GtkRecentInfo
2226 * @length: (out) (allow-none): return location for the number of groups returned
2228 * Returns all groups registered for the recently used item @info. The
2229 * array of returned group names will be %NULL terminated, so length might
2230 * optionally be %NULL.
2232 * Return value: (array length=length zero-terminated=1): a newly allocated
2233 * %NULL terminated array of strings. Use g_strfreev() to free it.
2238 gtk_recent_info_get_groups (GtkRecentInfo *info,
2245 g_return_val_if_fail (info != NULL, NULL);
2255 n_groups = g_slist_length (info->groups);
2257 retval = g_new0 (gchar *, n_groups + 1);
2259 for (l = info->groups, i = 0;
2263 gchar *group_name = (gchar *) l->data;
2265 g_assert (group_name != NULL);
2267 retval[i++] = g_strdup (group_name);
2278 * gtk_recent_info_has_group:
2279 * @info: a #GtkRecentInfo
2280 * @group_name: name of a group
2282 * Checks whether @group_name appears inside the groups registered for the
2283 * recently used item @info.
2285 * Return value: %TRUE if the group was found.
2290 gtk_recent_info_has_group (GtkRecentInfo *info,
2291 const gchar *group_name)
2295 g_return_val_if_fail (info != NULL, FALSE);
2296 g_return_val_if_fail (group_name != NULL, FALSE);
2301 for (l = info->groups; l != NULL; l = l->next)
2303 gchar *g = (gchar *) l->data;
2305 if (strcmp (g, group_name) == 0)
2313 * _gtk_recent_manager_sync:
2315 * Private function for synchronising the recent manager singleton.
2318 _gtk_recent_manager_sync (void)
2320 if (recent_manager_singleton)
2322 /* force a dump of the contents of the recent manager singleton */
2323 recent_manager_singleton->priv->is_dirty = TRUE;
2324 gtk_recent_manager_real_changed (recent_manager_singleton);
2328 #define __GTK_RECENT_MANAGER_C__
2329 #include "gtkaliasdef.c"