1 /* GTK - The GIMP Toolkit
2 * gtkrecentmanager.c: a manager for the recently used resources
4 * Copyright (C) 2006 Emmanuele Bassi
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 #include <sys/types.h>
32 #include <glib/gstdio.h>
34 #include "gtkrecentmanager.h"
37 #include "gtkicontheme.h"
38 #include "gtktypebuiltins.h"
39 #include "gtkprivate.h"
40 #include "gtkmarshalers.h"
44 #define XDG_PREFIX _gtk_xdg
45 #include "xdgmime/xdgmime.h"
48 /* the file where we store the recently used items */
49 #define GTK_RECENTLY_USED_FILE ".recently-used.xbel"
51 /* a poll approximately every five seconds */
54 /* return all items by default */
55 #define DEFAULT_LIMIT -1
57 /* keep in sync with xdgmime */
58 #define GTK_RECENT_DEFAULT_MIME "application/octet-stream"
64 GDestroyNotify notify;
91 GHashTable *apps_lookup;
102 struct _GtkRecentManagerPrivate
107 guint write_in_progress : 1;
108 guint read_in_progress : 1;
113 GBookmarkFile *recent_items;
128 static void gtk_recent_manager_finalize (GObject *object);
130 static void gtk_recent_manager_set_property (GObject *object,
134 static void gtk_recent_manager_get_property (GObject *object,
138 static void gtk_recent_manager_changed (GtkRecentManager *manager);
140 static void gtk_recent_manager_real_changed (GtkRecentManager *manager);
141 static gboolean gtk_recent_manager_poll_timeout (gpointer data);
142 static void gtk_recent_manager_set_filename (GtkRecentManager *manager,
143 const gchar *filename);
145 static void build_recent_items_list (GtkRecentManager *manager);
146 static void purge_recent_items_list (GtkRecentManager *manager,
149 static RecentAppInfo *recent_app_info_new (const gchar *app_name);
150 static void recent_app_info_free (RecentAppInfo *app_info);
152 static GtkRecentInfo *gtk_recent_info_new (const gchar *uri);
153 static void gtk_recent_info_free (GtkRecentInfo *recent_info);
155 static guint signal_changed = 0;
157 static GtkRecentManager *recent_manager_singleton = NULL;
159 G_DEFINE_TYPE (GtkRecentManager, gtk_recent_manager, G_TYPE_OBJECT)
162 filename_warning (const gchar *format,
163 const gchar *filename,
164 const gchar *message)
166 gchar *utf8 = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
167 g_warning (format, utf8 ? utf8 : "(invalid filename)", message);
171 /* Test of haystack has the needle prefix, comparing case
172 * insensitive. haystack may be UTF-8, but needle must
173 * contain only lowercase ascii. */
175 has_case_prefix (const gchar *haystack,
180 /* Eat one character at a time. */
184 while (*n && *h && *n == g_ascii_tolower (*h))
194 gtk_recent_manager_error_quark (void)
196 return g_quark_from_static_string ("gtk-recent-manager-error-quark");
200 threads_dispatch (gpointer data)
202 ThreadsDispatch *dispatch = data;
203 gboolean res = FALSE;
205 GDK_THREADS_ENTER ();
207 if (!g_source_is_destroyed (g_main_current_source ()))
208 res = dispatch->func (dispatch->data);
210 GDK_THREADS_LEAVE ();
216 threads_free (gpointer data)
218 ThreadsDispatch *dispatch = data;
220 if (dispatch->notify)
221 dispatch->notify (dispatch->data);
223 g_slice_free (ThreadsDispatch, dispatch);
227 gtk_recent_manager_class_init (GtkRecentManagerClass *klass)
229 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
231 gtk_recent_manager_parent_class = g_type_class_peek_parent (klass);
233 gobject_class->set_property = gtk_recent_manager_set_property;
234 gobject_class->get_property = gtk_recent_manager_get_property;
235 gobject_class->finalize = gtk_recent_manager_finalize;
238 * GtkRecentManager:filename
240 * The full path to the file to be used to store and read the recently
241 * used resources list
245 g_object_class_install_property (gobject_class,
247 g_param_spec_string ("filename",
249 P_("The full path to the file to be used to store and read the list"),
251 (G_PARAM_CONSTRUCT_ONLY | G_PARAM_READABLE | G_PARAM_WRITABLE)));
253 * GtkRecentManager:limit
255 * The maximum number of items to be returned by the
256 * gtk_recent_manager_get_items() function.
260 g_object_class_install_property (gobject_class,
262 g_param_spec_int ("limit",
264 P_("The maximum number of items to be returned by gtk_recent_manager_get_items()"),
270 * GtkRecentManager:size
272 * The size of the recently used resources list.
276 g_object_class_install_property (gobject_class,
278 g_param_spec_int ("size",
280 P_("The size of the recently used resources list"),
287 * GtkRecentManager::changed
288 * @recent_manager: the recent manager
290 * Emitted when the current recently used resources manager changes its
296 g_signal_new (I_("changed"),
297 G_TYPE_FROM_CLASS (klass),
299 G_STRUCT_OFFSET (GtkRecentManagerClass, changed),
301 g_cclosure_marshal_VOID__VOID,
304 klass->changed = gtk_recent_manager_real_changed;
306 g_type_class_add_private (klass, sizeof (GtkRecentManagerPrivate));
310 gtk_recent_manager_init (GtkRecentManager *manager)
312 GtkRecentManagerPrivate *priv;
313 ThreadsDispatch *dispatch;
315 priv = g_type_instance_get_private ((GTypeInstance *) manager,
316 GTK_TYPE_RECENT_MANAGER);
317 manager->priv = priv;
319 priv->limit = DEFAULT_LIMIT;
322 priv->is_dirty = FALSE;
323 priv->write_in_progress = FALSE;
324 priv->read_in_progress = FALSE;
326 priv->filename = g_build_filename (g_get_home_dir (),
327 GTK_RECENTLY_USED_FILE,
330 dispatch = g_slice_new (ThreadsDispatch);
331 dispatch->func = gtk_recent_manager_poll_timeout;
332 dispatch->data = manager;
333 dispatch->notify = NULL;
334 priv->poll_timeout = g_timeout_add_seconds_full (G_PRIORITY_DEFAULT + 30,
340 build_recent_items_list (manager);
344 gtk_recent_manager_set_property (GObject *object,
349 GtkRecentManager *recent_manager = GTK_RECENT_MANAGER (object);
354 gtk_recent_manager_set_filename (recent_manager, g_value_get_string (value));
357 gtk_recent_manager_set_limit (recent_manager, g_value_get_int (value));
360 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
366 gtk_recent_manager_get_property (GObject *object,
371 GtkRecentManager *recent_manager = GTK_RECENT_MANAGER (object);
376 g_value_set_string (value, recent_manager->priv->filename);
379 g_value_set_int (value, recent_manager->priv->limit);
382 g_value_set_int (value, recent_manager->priv->size);
385 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
391 gtk_recent_manager_finalize (GObject *object)
393 GtkRecentManager *manager = GTK_RECENT_MANAGER (object);
394 GtkRecentManagerPrivate *priv = manager->priv;
396 /* remove the poll timeout */
397 if (priv->poll_timeout)
398 g_source_remove (priv->poll_timeout);
400 g_free (priv->filename);
402 if (priv->recent_items)
403 g_bookmark_file_free (priv->recent_items);
405 /* chain up parent's finalize method */
406 G_OBJECT_CLASS (gtk_recent_manager_parent_class)->finalize (object);
410 gtk_recent_manager_real_changed (GtkRecentManager *manager)
412 GtkRecentManagerPrivate *priv = manager->priv;
414 g_object_freeze_notify (G_OBJECT (manager));
419 struct stat stat_buf;
421 /* we are marked as dirty, so we dump the content of our
422 * recently used items list
424 g_assert (priv->filename != NULL);
426 priv->write_in_progress = TRUE;
428 /* if no container object has been defined, we create a new
429 * empty container, and dump it
431 if (!priv->recent_items)
433 priv->recent_items = g_bookmark_file_new ();
438 g_bookmark_file_to_file (priv->recent_items,
444 filename_warning ("Attempting to store changes into `%s', "
447 write_error->message);
448 g_error_free (write_error);
451 priv->write_in_progress = FALSE;
453 /* we have sync'ed our list with the storage file, so we
454 * update the file mtime in order to skip the timed check
455 * and spare us from a re-read.
457 if (g_stat (priv->filename, &stat_buf) < 0)
459 filename_warning ("Unable to stat() the recently used resources file "
464 g_object_thaw_notify (G_OBJECT (manager));
469 priv->last_mtime = stat_buf.st_mtime;
471 /* mark us as clean */
472 priv->is_dirty = FALSE;
476 /* we are not marked as dirty, so we have been called
477 * because the recently used resources file has been
478 * changed (and not from us).
480 build_recent_items_list (manager);
483 g_object_thaw_notify (G_OBJECT (manager));
486 /* timed poll()-ing of the recently used resources file.
487 * an event-based system would be more efficient.
490 gtk_recent_manager_poll_timeout (gpointer data)
492 GtkRecentManager *manager = GTK_RECENT_MANAGER (data);
493 GtkRecentManagerPrivate *priv = manager->priv;
494 struct stat stat_buf;
497 /* wait for the next timeout if we have a read/write in progress */
498 if (priv->write_in_progress || priv->read_in_progress)
501 stat_res = g_stat (priv->filename, &stat_buf);
504 /* the file does not exist, yet, so we wait */
508 filename_warning ("Unable to stat() the recently used resources file "
516 /* the file didn't change from the last poll(), so we bail out */
517 if (stat_buf.st_mtime == priv->last_mtime)
520 /* the file has been changed, hence we emit the "changed" signal */
521 gtk_recent_manager_changed (manager);
527 gtk_recent_manager_set_filename (GtkRecentManager *manager,
528 const gchar *filename)
530 GtkRecentManagerPrivate *priv;
531 ThreadsDispatch *dispatch;
533 g_assert (GTK_IS_RECENT_MANAGER (manager));
534 priv = manager->priv;
536 if (!filename || filename[0] == '\0')
539 g_free (manager->priv->filename);
541 if (manager->priv->poll_timeout)
543 g_source_remove (manager->priv->poll_timeout);
544 manager->priv->poll_timeout = 0;
547 priv->filename = g_strdup (filename);
549 dispatch = g_slice_new (ThreadsDispatch);
550 dispatch->func = gtk_recent_manager_poll_timeout;
551 dispatch->data = manager;
552 dispatch->notify = NULL;
553 priv->poll_timeout = g_timeout_add_seconds_full (G_PRIORITY_DEFAULT + 30,
559 /* mark us clean, so that we can re-read the list
560 * of recently used resources
562 priv->is_dirty = FALSE;
563 build_recent_items_list (manager);
566 /* reads the recently used resources file and builds the items list.
567 * we keep the items list inside the parser object, and build the
568 * RecentInfo object only on user's demand to avoid useless replication.
569 * this function resets the dirty bit of the manager.
572 build_recent_items_list (GtkRecentManager *manager)
574 GtkRecentManagerPrivate *priv;
575 struct stat stat_buf;
581 priv = manager->priv;
582 g_assert (priv->filename != NULL);
584 if (!priv->recent_items)
586 priv->recent_items = g_bookmark_file_new ();
590 stat_res = g_stat (priv->filename, &stat_buf);
593 /* the file doesn't exists, so we bail out and wait for the first
601 filename_warning ("Attempting to read the recently used resources file "
602 "at `%s', but an error occurred: %s. Aborting.",
610 /* record the last mtime, for later use */
611 priv->last_mtime = stat_buf.st_mtime;
613 priv->read_in_progress = TRUE;
615 /* the file exists, and it's valid (we hope); if not, destroy the container
616 * object and hope for a better result when the next "changed" signal is
619 res = g_bookmark_file_load_from_file (priv->recent_items,
624 filename_warning ("Attempting to read the recently used resources file "
625 "at `%s', but the parser failed: %s.",
627 read_error->message);
629 g_bookmark_file_free (priv->recent_items);
630 priv->recent_items = NULL;
632 g_error_free (read_error);
635 size = g_bookmark_file_get_size (priv->recent_items);
636 if (priv->size != size)
640 g_object_notify (G_OBJECT (manager), "size");
643 priv->read_in_progress = FALSE;
644 priv->is_dirty = FALSE;
648 /********************
650 ********************/
654 * gtk_recent_manager_new:
656 * Creates a new recent manager object. Recent manager objects are used to
657 * handle the list of recently used resources. A #GtkRecentManager object
658 * monitors the recently used resources list, and emits the "changed" signal
659 * each time something inside the list changes.
661 * #GtkRecentManager objects are expensive: be sure to create them only when
662 * needed. You should use gtk_recent_manager_get_default() instead.
664 * Return value: A newly created #GtkRecentManager object.
669 gtk_recent_manager_new (void)
671 return g_object_new (GTK_TYPE_RECENT_MANAGER, NULL);
675 * gtk_recent_manager_get_default:
677 * Gets a unique instance of #GtkRecentManager, that you can share
678 * in your application without caring about memory management. The
679 * returned instance will be freed when you application terminates.
681 * Return value: A unique #GtkRecentManager. Do not ref or unref it.
686 gtk_recent_manager_get_default (void)
688 if (G_UNLIKELY (!recent_manager_singleton))
689 recent_manager_singleton = gtk_recent_manager_new ();
691 return recent_manager_singleton;
695 * gtk_recent_manager_get_for_screen:
696 * @screen: a #GdkScreen
698 * Gets the recent manager object associated with @screen; if this
699 * function has not previously been called for the given screen,
700 * a new recent manager object will be created and associated with
701 * the screen. Recent manager objects are fairly expensive to create,
702 * so using this function is usually a better choice than calling
703 * gtk_recent_manager_new() and setting the screen yourself; by using
704 * this function a single recent manager object will be shared between
707 * Return value: A unique #GtkRecentManager associated with the given
708 * screen. This recent manager is associated to the with the screen
709 * and can be used as long as the screen is open. Do not ref or
712 * @Deprecated: 2.12: This function has been deprecated and should
713 * not be used in newly written code. Calling this function is
714 * equivalent to calling gtk_recent_manager_get_default().
719 gtk_recent_manager_get_for_screen (GdkScreen *screen)
721 return gtk_recent_manager_get_default ();
725 * gtk_recent_manager_set_screen:
726 * @manager: a #GtkRecentManager
727 * @screen: a #GdkScreen
729 * Sets the screen for a recent manager; the screen is used to
730 * track the user's currently configured recently used documents
735 * @Deprecated: 2.12: This function has been deprecated and should
736 * not be used in newly written code. Calling this function has
740 gtk_recent_manager_set_screen (GtkRecentManager *manager,
747 * gtk_recent_manager_set_limit:
748 * @manager: a #GtkRecentManager
749 * @limit: the maximum number of items to return, or -1.
751 * Sets the maximum number of item that the gtk_recent_manager_get_items()
752 * function should return. If @limit is set to -1, then return all the
758 gtk_recent_manager_set_limit (GtkRecentManager *manager,
761 GtkRecentManagerPrivate *priv;
763 g_return_if_fail (GTK_IS_RECENT_MANAGER (manager));
765 priv = manager->priv;
770 * gtk_recent_manager_get_limit:
771 * @manager: a #GtkRecentManager
773 * Gets the maximum number of items that the gtk_recent_manager_get_items()
774 * function should return.
776 * Return value: the number of items to return, or -1 for every item.
781 gtk_recent_manager_get_limit (GtkRecentManager *manager)
783 GtkRecentManagerPrivate *priv;
785 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), DEFAULT_LIMIT);
787 priv = manager->priv;
792 * gtk_recent_manager_add_item:
793 * @manager: a #GtkRecentManager
796 * Adds a new resource, pointed by @uri, into the recently used
799 * This function automatically retrieving some of the needed
800 * metadata and setting other metadata to common default values; it
801 * then feeds the data to gtk_recent_manager_add_full().
803 * See gtk_recent_manager_add_full() if you want to explicitely
804 * define the metadata for the resource pointed by @uri.
806 * Return value: %TRUE if the new item was successfully added
807 * to the recently used resources list
812 gtk_recent_manager_add_item (GtkRecentManager *manager,
815 GtkRecentData recent_data;
818 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), FALSE);
819 g_return_val_if_fail (uri != NULL, FALSE);
821 recent_data.display_name = NULL;
822 recent_data.description = NULL;
823 recent_data.mime_type = NULL;
826 if (has_case_prefix (uri, "file:/"))
829 const gchar *mime_type;
831 filename = g_filename_from_uri (uri, NULL, NULL);
834 mime_type = xdg_mime_get_mime_type_for_file (filename, NULL);
836 recent_data.mime_type = g_strdup (mime_type);
841 if (!recent_data.mime_type)
842 recent_data.mime_type = g_strdup (GTK_RECENT_DEFAULT_MIME);
846 recent_data.mime_type = g_strdup (GTK_RECENT_DEFAULT_MIME);
848 recent_data.app_name = g_strdup (g_get_application_name ());
849 recent_data.app_exec = g_strjoin (" ", g_get_prgname (), "%u", NULL);
850 recent_data.groups = NULL;
851 recent_data.is_private = FALSE;
853 retval = gtk_recent_manager_add_full (manager, uri, &recent_data);
855 g_free (recent_data.mime_type);
856 g_free (recent_data.app_name);
857 g_free (recent_data.app_exec);
863 * gtk_recent_manager_add_full:
864 * @manager: a #GtkRecentManager
866 * @recent_data: metadata of the resource
868 * Adds a new resource, pointed by @uri, into the recently used
869 * resources list, using the metadata specified inside the #GtkRecentData
870 * structure passed in @recent_data.
872 * The passed URI will be used to identify this resource inside the
875 * In order to register the new recently used resource, metadata about
876 * the resource must be passed as well as the URI; the metadata is
877 * stored in a #GtkRecentData structure, which must contain the MIME
878 * type of the resource pointed by the URI; the name of the application
879 * that is registering the item, and a command line to be used when
880 * launching the item.
882 * Optionally, a #GtkRecentData structure might contain a UTF-8 string
883 * to be used when viewing the item instead of the last component of the
884 * URI; a short description of the item; whether the item should be
885 * considered private - that is, should be displayed only by the
886 * applications that have registered it.
888 * Return value: %TRUE if the new item was successfully added to the
889 * recently used resources list, %FALSE otherwise.
894 gtk_recent_manager_add_full (GtkRecentManager *manager,
896 const GtkRecentData *data)
898 GtkRecentManagerPrivate *priv;
900 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), FALSE);
901 g_return_val_if_fail (uri != NULL, FALSE);
902 g_return_val_if_fail (data != NULL, FALSE);
905 if ((data->display_name) &&
906 (!g_utf8_validate (data->display_name, -1, NULL)))
908 g_warning ("Attempting to add `%s' to the list of recently used "
909 "resources, but the display name is not a valid UTF-8 "
915 if ((data->description) &&
916 (!g_utf8_validate (data->description, -1, NULL)))
918 g_warning ("Attempting to add `%s' to the list of recently used "
919 "resources, but the description is not a valid UTF-8 "
926 if (!data->mime_type)
928 g_warning ("Attempting to add `%s' to the list of recently used "
929 "resources, but not MIME type was defined",
936 g_warning ("Attempting to add `%s' to the list of recently used "
937 "resources, but no name of the application that is "
938 "registering it was defined",
945 g_warning ("Attempting to add `%s' to the list of recently used "
946 "resources, but no command line for the application "
947 "that is registering it was defined",
952 priv = manager->priv;
954 if (!priv->recent_items)
956 priv->recent_items = g_bookmark_file_new ();
960 if (data->display_name)
961 g_bookmark_file_set_title (priv->recent_items, uri, data->display_name);
963 if (data->description)
964 g_bookmark_file_set_description (priv->recent_items, uri, data->description);
966 g_bookmark_file_set_mime_type (priv->recent_items, uri, data->mime_type);
968 if (data->groups && data->groups[0] != '\0')
972 for (j = 0; (data->groups)[j] != NULL; j++)
973 g_bookmark_file_add_group (priv->recent_items, uri, (data->groups)[j]);
976 /* register the application; this will take care of updating the
977 * registration count and time in case the application has
978 * already registered the same document inside the list
980 g_bookmark_file_add_application (priv->recent_items, uri,
984 g_bookmark_file_set_is_private (priv->recent_items, uri,
987 /* mark us as dirty, so that when emitting the "changed" signal we
988 * will dump our changes
990 priv->is_dirty = TRUE;
992 gtk_recent_manager_changed (manager);
998 * gtk_recent_manager_remove_item:
999 * @manager: a #GtkRecentManager
1000 * @uri: the URI of the item you wish to remove
1001 * @error: return location for a #GError, or %NULL
1003 * Removes a resource pointed by @uri from the recently used resources
1004 * list handled by a recent manager.
1006 * Return value: %TRUE if the item pointed by @uri has been successfully
1007 * removed by the recently used resources list, and %FALSE otherwise.
1012 gtk_recent_manager_remove_item (GtkRecentManager *manager,
1016 GtkRecentManagerPrivate *priv;
1017 GError *remove_error = NULL;
1019 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), FALSE);
1020 g_return_val_if_fail (uri != NULL, FALSE);
1021 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
1023 priv = manager->priv;
1025 if (!priv->recent_items)
1027 priv->recent_items = g_bookmark_file_new ();
1030 g_set_error (error, GTK_RECENT_MANAGER_ERROR,
1031 GTK_RECENT_MANAGER_ERROR_NOT_FOUND,
1032 _("Unable to find an item with URI '%s'"),
1038 g_bookmark_file_remove_item (priv->recent_items, uri, &remove_error);
1041 g_propagate_error (error, remove_error);
1046 priv->is_dirty = TRUE;
1048 gtk_recent_manager_changed (manager);
1054 * gtk_recent_manager_has_item:
1055 * @manager: a #GtkRecentManager
1058 * Checks whether there is a recently used resource registered
1059 * with @uri inside the recent manager.
1061 * Return value: %TRUE if the resource was found, %FALSE otherwise.
1066 gtk_recent_manager_has_item (GtkRecentManager *manager,
1069 GtkRecentManagerPrivate *priv;
1071 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), FALSE);
1072 g_return_val_if_fail (uri != NULL, FALSE);
1074 priv = manager->priv;
1075 g_return_val_if_fail (priv->recent_items != NULL, FALSE);
1077 return g_bookmark_file_has_item (priv->recent_items, uri);
1081 build_recent_info (GBookmarkFile *bookmarks,
1082 GtkRecentInfo *info)
1084 gchar **apps, **groups;
1085 gsize apps_len, groups_len, i;
1087 g_assert (bookmarks != NULL);
1088 g_assert (info != NULL);
1090 info->display_name = g_bookmark_file_get_title (bookmarks, info->uri, NULL);
1091 info->description = g_bookmark_file_get_description (bookmarks, info->uri, NULL);
1092 info->mime_type = g_bookmark_file_get_mime_type (bookmarks, info->uri, NULL);
1094 info->is_private = g_bookmark_file_get_is_private (bookmarks, info->uri, NULL);
1096 info->added = g_bookmark_file_get_added (bookmarks, info->uri, NULL);
1097 info->modified = g_bookmark_file_get_modified (bookmarks, info->uri, NULL);
1098 info->visited = g_bookmark_file_get_visited (bookmarks, info->uri, NULL);
1100 groups = g_bookmark_file_get_groups (bookmarks, info->uri, &groups_len, NULL);
1101 for (i = 0; i < groups_len; i++)
1103 gchar *group_name = g_strdup (groups[i]);
1105 info->groups = g_slist_append (info->groups, group_name);
1108 g_strfreev (groups);
1110 apps = g_bookmark_file_get_applications (bookmarks, info->uri, &apps_len, NULL);
1111 for (i = 0; i < apps_len; i++)
1113 gchar *app_name, *app_exec;
1116 RecentAppInfo *app_info;
1121 res = g_bookmark_file_get_app_info (bookmarks, info->uri, app_name,
1129 app_info = recent_app_info_new (app_name);
1130 app_info->exec = app_exec;
1131 app_info->count = count;
1132 app_info->stamp = stamp;
1134 info->applications = g_slist_append (info->applications,
1136 g_hash_table_replace (info->apps_lookup, app_info->name, app_info);
1143 * gtk_recent_manager_lookup_item:
1144 * @manager: a #GtkRecentManager
1146 * @error: a return location for a #GError, or %NULL
1148 * Searches for a URI inside the recently used resources list, and
1149 * returns a structure containing informations about the resource
1150 * like its MIME type, or its display name.
1152 * Return value: a #GtkRecentInfo structure containing information
1153 * about the resource pointed by @uri, or %NULL if the URI was
1154 * not registered in the recently used resources list. Free with
1155 * gtk_recent_info_unref().
1160 gtk_recent_manager_lookup_item (GtkRecentManager *manager,
1164 GtkRecentManagerPrivate *priv;
1165 GtkRecentInfo *info = NULL;
1167 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), NULL);
1168 g_return_val_if_fail (uri != NULL, NULL);
1169 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
1171 priv = manager->priv;
1172 if (!priv->recent_items)
1174 priv->recent_items = g_bookmark_file_new ();
1177 g_set_error (error, GTK_RECENT_MANAGER_ERROR,
1178 GTK_RECENT_MANAGER_ERROR_NOT_FOUND,
1179 _("Unable to find an item with URI '%s'"),
1185 if (!g_bookmark_file_has_item (priv->recent_items, uri))
1187 g_set_error (error, GTK_RECENT_MANAGER_ERROR,
1188 GTK_RECENT_MANAGER_ERROR_NOT_FOUND,
1189 _("Unable to find an item with URI '%s'"),
1194 info = gtk_recent_info_new (uri);
1195 g_return_val_if_fail (info != NULL, NULL);
1197 /* fill the RecentInfo structure with the data retrieved by our
1198 * parser object from the storage file
1200 build_recent_info (priv->recent_items, info);
1206 * gtk_recent_manager_move_item:
1207 * @manager: a #GtkRecentManager
1208 * @uri: the URI of a recently used resource
1209 * @new_uri: the new URI of the recently used resource, or %NULL to
1210 * remove the item pointed by @uri in the list
1211 * @error: a return location for a #GError, or %NULL
1213 * Changes the location of a recently used resource from @uri to @new_uri.
1215 * Please note that this function will not affect the resource pointed
1216 * by the URIs, but only the URI used in the recently used resources list.
1218 * Return value: %TRUE on success.
1223 gtk_recent_manager_move_item (GtkRecentManager *recent_manager,
1225 const gchar *new_uri,
1228 GtkRecentManagerPrivate *priv;
1232 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (recent_manager), FALSE);
1233 g_return_val_if_fail (uri != NULL, FALSE);
1234 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
1236 priv = recent_manager->priv;
1238 if (!g_bookmark_file_has_item (priv->recent_items, uri))
1240 g_set_error (error, GTK_RECENT_MANAGER_ERROR,
1241 GTK_RECENT_MANAGER_ERROR_NOT_FOUND,
1242 _("Unable to find an item with URI '%s'"),
1248 res = g_bookmark_file_move_item (priv->recent_items,
1253 g_propagate_error (error, move_error);
1257 priv->is_dirty = TRUE;
1259 gtk_recent_manager_changed (recent_manager);
1265 * gtk_recent_manager_get_items:
1266 * @manager: a #GtkRecentManager
1268 * Gets the list of recently used resources.
1270 * Return value: a list of newly allocated #GtkRecentInfo objects. Use
1271 * gtk_recent_info_unref() on each item inside the list, and then
1272 * free the list itself using g_list_free().
1277 gtk_recent_manager_get_items (GtkRecentManager *manager)
1279 GtkRecentManagerPrivate *priv;
1280 GList *retval = NULL;
1284 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), NULL);
1286 priv = manager->priv;
1287 if (!priv->recent_items)
1290 if (priv->limit == 0)
1293 uris = g_bookmark_file_get_uris (priv->recent_items, &uris_len);
1294 for (i = 0; i < uris_len; i++)
1296 GtkRecentInfo *info;
1298 if (priv->limit != -1 && i == priv->limit)
1301 info = gtk_recent_info_new (uris[i]);
1302 build_recent_info (priv->recent_items, info);
1304 retval = g_list_prepend (retval, info);
1313 purge_recent_items_list (GtkRecentManager *manager,
1316 GtkRecentManagerPrivate *priv = manager->priv;
1318 if (!priv->recent_items)
1321 g_bookmark_file_free (priv->recent_items);
1322 priv->recent_items = NULL;
1324 priv->recent_items = g_bookmark_file_new ();
1326 priv->is_dirty = TRUE;
1328 /* emit the changed signal, to ensure that the purge is written */
1329 gtk_recent_manager_changed (manager);
1333 * gtk_recent_manager_purge_items:
1334 * @manager: a #GtkRecentManager
1335 * @error: a return location for a #GError, or %NULL
1337 * Purges every item from the recently used resources list.
1339 * Return value: the number of items that have been removed from the
1340 * recently used resources list.
1345 gtk_recent_manager_purge_items (GtkRecentManager *manager,
1348 GtkRecentManagerPrivate *priv;
1351 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), -1);
1353 priv = manager->priv;
1354 if (!priv->recent_items)
1357 count = g_bookmark_file_get_size (priv->recent_items);
1361 purge_recent_items_list (manager, error);
1363 purged = count - g_bookmark_file_get_size (priv->recent_items);
1369 gtk_recent_manager_changed (GtkRecentManager *recent_manager)
1371 g_signal_emit (recent_manager, signal_changed, 0);
1379 gtk_recent_info_get_type (void)
1381 static GType info_type = 0;
1384 info_type = g_boxed_type_register_static (I_("GtkRecentInfo"),
1385 (GBoxedCopyFunc) gtk_recent_info_ref,
1386 (GBoxedFreeFunc) gtk_recent_info_unref);
1390 static GtkRecentInfo *
1391 gtk_recent_info_new (const gchar *uri)
1393 GtkRecentInfo *info;
1395 g_assert (uri != NULL);
1397 info = g_new0 (GtkRecentInfo, 1);
1398 info->uri = g_strdup (uri);
1400 info->applications = NULL;
1401 info->apps_lookup = g_hash_table_new (g_str_hash, g_str_equal);
1403 info->groups = NULL;
1405 info->ref_count = 1;
1411 gtk_recent_info_free (GtkRecentInfo *recent_info)
1416 g_free (recent_info->uri);
1417 g_free (recent_info->display_name);
1418 g_free (recent_info->description);
1419 g_free (recent_info->mime_type);
1421 if (recent_info->applications)
1423 g_slist_foreach (recent_info->applications,
1424 (GFunc) recent_app_info_free,
1426 g_slist_free (recent_info->applications);
1428 recent_info->applications = NULL;
1431 if (recent_info->apps_lookup)
1432 g_hash_table_destroy (recent_info->apps_lookup);
1434 if (recent_info->groups)
1436 g_slist_foreach (recent_info->groups,
1439 g_slist_free (recent_info->groups);
1441 recent_info->groups = NULL;
1444 if (recent_info->icon)
1445 g_object_unref (recent_info->icon);
1447 g_free (recent_info);
1451 * gtk_recent_info_ref:
1452 * @info: a #GtkRecentInfo
1454 * Increases the reference count of @recent_info by one.
1456 * Return value: the recent info object with its reference count increased
1462 gtk_recent_info_ref (GtkRecentInfo *info)
1464 g_return_val_if_fail (info != NULL, NULL);
1465 g_return_val_if_fail (info->ref_count > 0, NULL);
1467 info->ref_count += 1;
1473 * gtk_recent_info_unref:
1474 * @info: a #GtkRecentInfo
1476 * Decreases the reference count of @info by one. If the reference
1477 * count reaches zero, @info is deallocated, and the memory freed.
1482 gtk_recent_info_unref (GtkRecentInfo *info)
1484 g_return_if_fail (info != NULL);
1485 g_return_if_fail (info->ref_count > 0);
1487 info->ref_count -= 1;
1489 if (info->ref_count == 0)
1490 gtk_recent_info_free (info);
1494 * gtk_recent_info_get_uri:
1495 * @info: a #GtkRecentInfo
1497 * Gets the URI of the resource.
1499 * Return value: the URI of the resource. The returned string is
1500 * owned by the recent manager, and should not be freed.
1504 G_CONST_RETURN gchar *
1505 gtk_recent_info_get_uri (GtkRecentInfo *info)
1507 g_return_val_if_fail (info != NULL, NULL);
1513 * gtk_recent_info_get_display_name:
1514 * @info: a #GtkRecentInfo
1516 * Gets the name of the resource. If none has been defined, the basename
1517 * of the resource is obtained.
1519 * Return value: the display name of the resource. The returned string
1520 * is owned by the recent manager, and should not be freed.
1524 G_CONST_RETURN gchar *
1525 gtk_recent_info_get_display_name (GtkRecentInfo *info)
1527 g_return_val_if_fail (info != NULL, NULL);
1529 if (!info->display_name)
1530 info->display_name = gtk_recent_info_get_short_name (info);
1532 return info->display_name;
1536 * gtk_recent_info_get_description:
1537 * @info: a #GtkRecentInfo
1539 * Gets the (short) description of the resource.
1541 * Return value: the description of the resource. The returned string
1542 * is owned by the recent manager, and should not be freed.
1546 G_CONST_RETURN gchar *
1547 gtk_recent_info_get_description (GtkRecentInfo *info)
1549 g_return_val_if_fail (info != NULL, NULL);
1551 return info->description;
1555 * gtk_recent_info_get_mime_type:
1556 * @info: a #GtkRecentInfo
1558 * Gets the MIME type of the resource.
1560 * Return value: the MIME type of the resource. The returned string
1561 * is owned by the recent manager, and should not be freed.
1565 G_CONST_RETURN gchar *
1566 gtk_recent_info_get_mime_type (GtkRecentInfo *info)
1568 g_return_val_if_fail (info != NULL, NULL);
1570 if (!info->mime_type)
1571 info->mime_type = g_strdup (GTK_RECENT_DEFAULT_MIME);
1573 return info->mime_type;
1577 * gtk_recent_info_get_added:
1578 * @info: a #GtkRecentInfo
1580 * Gets the timestamp (seconds from system's Epoch) when the resource
1581 * was added to the recently used resources list.
1583 * Return value: the number of seconds elapsed from system's Epoch when
1584 * the resource was added to the list, or -1 on failure.
1589 gtk_recent_info_get_added (GtkRecentInfo *info)
1591 g_return_val_if_fail (info != NULL, (time_t) -1);
1597 * gtk_recent_info_get_modified:
1598 * @info: a #GtkRecentInfo
1600 * Gets the timestamp (seconds from system's Epoch) when the resource
1601 * was last modified.
1603 * Return value: the number of seconds elapsed from system's Epoch when
1604 * the resource was last modified, or -1 on failure.
1609 gtk_recent_info_get_modified (GtkRecentInfo *info)
1611 g_return_val_if_fail (info != NULL, (time_t) -1);
1613 return info->modified;
1617 * gtk_recent_info_get_visited:
1618 * @info: a #GtkRecentInfo
1620 * Gets the timestamp (seconds from system's Epoch) when the resource
1623 * Return value: the number of seconds elapsed from system's Epoch when
1624 * the resource was last visited, or -1 on failure.
1629 gtk_recent_info_get_visited (GtkRecentInfo *info)
1631 g_return_val_if_fail (info != NULL, (time_t) -1);
1633 return info->visited;
1637 * gtk_recent_info_get_private_hint:
1638 * @info: a #GtkRecentInfo
1640 * Gets the value of the "private" flag. Resources in the recently used
1641 * list that have this flag set to %TRUE should only be displayed by the
1642 * applications that have registered them.
1644 * Return value: %TRUE if the private flag was found, %FALSE otherwise.
1649 gtk_recent_info_get_private_hint (GtkRecentInfo *info)
1651 g_return_val_if_fail (info != NULL, FALSE);
1653 return info->is_private;
1657 static RecentAppInfo *
1658 recent_app_info_new (const gchar *app_name)
1660 RecentAppInfo *app_info;
1662 g_assert (app_name != NULL);
1664 app_info = g_new0 (RecentAppInfo, 1);
1665 app_info->name = g_strdup (app_name);
1666 app_info->exec = NULL;
1667 app_info->count = 1;
1668 app_info->stamp = time (NULL);
1674 recent_app_info_free (RecentAppInfo *app_info)
1679 g_free (app_info->name);
1681 g_free (app_info->exec);
1687 * gtk_recent_info_get_application_info:
1688 * @info: a #GtkRecentInfo
1689 * @app_name: the name of the application that has registered this item
1690 * @app_exec: return location for the string containing the command line
1691 * @count: return location for the number of times this item was registered
1692 * @time_: return location for the timestamp this item was last registered
1693 * for this application
1695 * Gets the data regarding the application that has registered the resource
1698 * If the command line contains any escape characters defined inside the
1699 * storage specification, they will be expanded.
1701 * Return value: %TRUE if an application with @app_name has registered this
1702 * resource inside the recently used list, or %FALSE otherwise. You should
1703 * free the returned command line using g_free().
1708 gtk_recent_info_get_application_info (GtkRecentInfo *info,
1709 const gchar *app_name,
1716 g_return_val_if_fail (info != NULL, FALSE);
1717 g_return_val_if_fail (app_name != NULL, FALSE);
1719 ai = (RecentAppInfo *) g_hash_table_lookup (info->apps_lookup,
1723 g_warning ("No registered application with name '%s' "
1724 "for item with URI '%s' found",
1731 *app_exec = ai->exec;
1743 * gtk_recent_info_get_applications:
1744 * @info: a #GtkRecentInfo
1745 * @length: return location for the length of the returned list, or %NULL
1747 * Retrieves the list of applications that have registered this resource.
1749 * Return value: a newly allocated %NULL-terminated array of strings.
1750 * Use g_strfreev() to free it.
1755 gtk_recent_info_get_applications (GtkRecentInfo *info,
1762 g_return_val_if_fail (info != NULL, NULL);
1764 if (!info->applications)
1772 n_apps = g_slist_length (info->applications);
1774 retval = g_new0 (gchar *, n_apps + 1);
1776 for (l = info->applications, i = 0;
1780 RecentAppInfo *ai = (RecentAppInfo *) l->data;
1782 g_assert (ai != NULL);
1784 retval[i++] = g_strdup (ai->name);
1795 * gtk_recent_info_has_application:
1796 * @info: a #GtkRecentInfo
1797 * @app_name: a string containing an application name
1799 * Checks whether an application registered this resource using @app_name.
1801 * Return value: %TRUE if an application with name @app_name was found,
1807 gtk_recent_info_has_application (GtkRecentInfo *info,
1808 const gchar *app_name)
1810 g_return_val_if_fail (info != NULL, FALSE);
1811 g_return_val_if_fail (app_name != NULL, FALSE);
1813 return (NULL != g_hash_table_lookup (info->apps_lookup, app_name));
1817 * gtk_recent_info_last_application:
1818 * @info: a #GtkRecentInfo
1820 * Gets the name of the last application that have registered the
1821 * recently used resource represented by @info.
1823 * Return value: an application name. Use g_free() to free it.
1828 gtk_recent_info_last_application (GtkRecentInfo *info)
1831 time_t last_stamp = (time_t) -1;
1834 g_return_val_if_fail (info != NULL, NULL);
1836 for (l = info->applications; l != NULL; l = l->next)
1838 RecentAppInfo *ai = (RecentAppInfo *) l->data;
1840 if (ai->stamp > last_stamp)
1843 last_stamp = ai->stamp;
1847 return g_strdup (name);
1851 get_icon_for_mime_type (const char *mime_type,
1854 GtkIconTheme *icon_theme;
1855 const char *separator;
1859 separator = strchr (mime_type, '/');
1863 icon_theme = gtk_icon_theme_get_default ();
1865 /* try with the three icon name variants for MIME types */
1867 /* canonicalize MIME type: foo/x-bar -> foo-x-bar */
1868 icon_name = g_string_new (NULL);
1869 g_string_append_len (icon_name, mime_type, separator - mime_type);
1870 g_string_append_c (icon_name, '-');
1871 g_string_append (icon_name, separator + 1);
1872 pixbuf = gtk_icon_theme_load_icon (icon_theme, icon_name->str,
1876 g_string_free (icon_name, TRUE);
1880 /* canonicalize MIME type, and prepend "gnome-mime-" */
1881 icon_name = g_string_new ("gnome-mime-");
1882 g_string_append_len (icon_name, mime_type, separator - mime_type);
1883 g_string_append_c (icon_name, '-');
1884 g_string_append (icon_name, separator + 1);
1885 pixbuf = gtk_icon_theme_load_icon (icon_theme, icon_name->str,
1889 g_string_free (icon_name, TRUE);
1893 /* try the MIME family icon */
1894 icon_name = g_string_new ("gnome-mime-");
1895 g_string_append_len (icon_name, mime_type, separator - mime_type);
1896 pixbuf = gtk_icon_theme_load_icon (icon_theme, icon_name->str,
1900 g_string_free (icon_name, TRUE);
1906 get_icon_fallback (const gchar *icon_name,
1909 GtkIconTheme *icon_theme;
1912 icon_theme = gtk_icon_theme_get_default ();
1914 retval = gtk_icon_theme_load_icon (icon_theme, icon_name,
1916 GTK_ICON_LOOKUP_USE_BUILTIN,
1918 g_assert (retval != NULL);
1924 * gtk_recent_info_get_icon:
1925 * @info: a #GtkRecentInfo
1926 * @size: the size of the icon in pixels
1928 * Retrieves the icon of size @size associated to the resource MIME type.
1930 * Return value: a #GdkPixbuf containing the icon, or %NULL.
1935 gtk_recent_info_get_icon (GtkRecentInfo *info,
1938 GdkPixbuf *retval = NULL;
1940 g_return_val_if_fail (info != NULL, NULL);
1942 if (info->mime_type)
1943 retval = get_icon_for_mime_type (info->mime_type, size);
1945 /* this function should never fail */
1948 if (info->mime_type &&
1949 strcmp (info->mime_type, "x-directory/normal") == 0)
1950 retval = get_icon_fallback (GTK_STOCK_DIRECTORY, size);
1952 retval = get_icon_fallback (GTK_STOCK_FILE, size);
1959 * gtk_recent_info_is_local:
1960 * @info: a #GtkRecentInfo
1962 * Checks whether the resource is local or not by looking at the
1963 * scheme of its URI.
1965 * Return value: %TRUE if the resource is local.
1970 gtk_recent_info_is_local (GtkRecentInfo *info)
1972 g_return_val_if_fail (info != NULL, FALSE);
1974 return has_case_prefix (info->uri, "file:/");
1978 * gtk_recent_info_exists:
1979 * @info: a #GtkRecentInfo
1981 * Checks whether the resource pointed by @info still exists. At
1982 * the moment this check is done only on resources pointing to local files.
1984 * Return value: %TRUE if the resource exists
1989 gtk_recent_info_exists (GtkRecentInfo *info)
1992 struct stat stat_buf;
1993 gboolean retval = FALSE;
1995 g_return_val_if_fail (info != NULL, FALSE);
1997 /* we guarantee only local resources */
1998 if (!gtk_recent_info_is_local (info))
2001 filename = g_filename_from_uri (info->uri, NULL, NULL);
2004 if (stat (filename, &stat_buf) == 0)
2014 * gtk_recent_info_match:
2015 * @info_a: a #GtkRecentInfo
2016 * @info_b: a #GtkRecentInfo
2018 * Checks whether two #GtkRecentInfo structures point to the same
2021 * Return value: %TRUE if both #GtkRecentInfo structures point to se same
2022 * resource, %FALSE otherwise.
2027 gtk_recent_info_match (GtkRecentInfo *info_a,
2028 GtkRecentInfo *info_b)
2030 g_return_val_if_fail (info_a != NULL, FALSE);
2031 g_return_val_if_fail (info_b != NULL, FALSE);
2033 return (0 == strcmp (info_a->uri, info_b->uri));
2036 /* taken from gnome-vfs-uri.c */
2037 static const gchar *
2038 get_method_string (const gchar *substring,
2039 gchar **method_string)
2045 g_ascii_isalnum (*p) || *p == '+' || *p == '-' || *p == '.';
2052 !(p == substring + 1 && g_ascii_isalpha (*substring))
2056 /* Found toplevel method specification. */
2057 method = g_strndup (substring, p - substring);
2058 *method_string = g_ascii_strdown (method, -1);
2064 *method_string = g_strdup ("file");
2071 /* Stolen from gnome_vfs_make_valid_utf8() */
2073 make_valid_utf8 (const char *name)
2076 const char *remainder, *invalid;
2077 int remaining_bytes, valid_bytes;
2081 remaining_bytes = name ? strlen (name) : 0;
2083 while (remaining_bytes != 0)
2085 if (g_utf8_validate (remainder, remaining_bytes, &invalid))
2088 valid_bytes = invalid - remainder;
2091 string = g_string_sized_new (remaining_bytes);
2093 g_string_append_len (string, remainder, valid_bytes);
2094 g_string_append_c (string, '?');
2096 remaining_bytes -= valid_bytes + 1;
2097 remainder = invalid + 1;
2101 return g_strdup (name);
2103 g_string_append (string, remainder);
2104 g_assert (g_utf8_validate (string->str, -1, NULL));
2106 return g_string_free (string, FALSE);
2110 get_uri_shortname_for_display (const gchar *uri)
2113 gboolean validated = FALSE;
2115 if (has_case_prefix (uri, "file:/"))
2119 local_file = g_filename_from_uri (uri, NULL, NULL);
2123 name = g_filename_display_basename (local_file);
2127 g_free (local_file);
2136 rest = get_method_string (uri, &method);
2137 local_file = g_filename_display_basename (rest);
2139 name = g_strdup_printf ("%s: %s", method, local_file);
2141 g_free (local_file);
2145 g_assert (name != NULL);
2147 if (!validated && !g_utf8_validate (name, -1, NULL))
2151 utf8_name = make_valid_utf8 (name);
2161 * gtk_recent_info_get_short_name:
2162 * @info: an #GtkRecentInfo
2164 * Computes a valid UTF-8 string that can be used as the name of the item in a
2165 * menu or list. For example, calling this function on an item that refers to
2166 * "file:///foo/bar.txt" will yield "bar.txt".
2168 * Return value: A newly-allocated string in UTF-8 encoding; free it with
2174 gtk_recent_info_get_short_name (GtkRecentInfo *info)
2178 g_return_val_if_fail (info != NULL, NULL);
2180 if (info->uri == NULL)
2183 short_name = get_uri_shortname_for_display (info->uri);
2189 * gtk_recent_info_get_uri_display:
2190 * @info: a #GtkRecentInfo
2192 * Gets a displayable version of the resource's URI. If the resource
2193 * is local, it returns a local path; if the resource is not local,
2194 * it returns the UTF-8 encoded content of gtk_recent_info_get_uri().
2196 * Return value: a UTF-8 string containing the resource's URI or %NULL
2201 gtk_recent_info_get_uri_display (GtkRecentInfo *info)
2205 g_return_val_if_fail (info != NULL, NULL);
2208 if (gtk_recent_info_is_local (info))
2212 filename = g_filename_from_uri (info->uri, NULL, NULL);
2216 retval = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
2221 retval = make_valid_utf8 (info->uri);
2228 * gtk_recent_info_get_age:
2229 * @info: a #GtkRecentInfo
2231 * Gets the number of days elapsed since the last update of the resource
2234 * Return value: a positive integer containing the number of days elapsed
2235 * since the time this resource was last modified.
2240 gtk_recent_info_get_age (GtkRecentInfo *info)
2245 g_return_val_if_fail (info != NULL, -1);
2249 delta = now - info->modified;
2251 retval = (gint) (delta / (60 * 60 * 24));
2257 * gtk_recent_info_get_groups:
2258 * @info: a #GtkRecentInfo
2259 * @length: return location for the number of groups returned, or %NULL
2261 * Returns all groups registered for the recently used item @info. The
2262 * array of returned group names will be %NULL terminated, so length might
2263 * optionally be %NULL.
2265 * Return value: a newly allocated %NULL terminated array of strings. Use
2266 * g_strfreev() to free it.
2271 gtk_recent_info_get_groups (GtkRecentInfo *info,
2278 g_return_val_if_fail (info != NULL, NULL);
2288 n_groups = g_slist_length (info->groups);
2290 retval = g_new0 (gchar *, n_groups + 1);
2292 for (l = info->groups, i = 0;
2296 gchar *group_name = (gchar *) l->data;
2298 g_assert (group_name != NULL);
2300 retval[i++] = g_strdup (group_name);
2311 * gtk_recent_info_has_group:
2312 * @info: a #GtkRecentInfo
2313 * @group_name: name of a group
2315 * Checks whether @group_name appears inside the groups registered for the
2316 * recently used item @info.
2318 * Return value: %TRUE if the group was found.
2323 gtk_recent_info_has_group (GtkRecentInfo *info,
2324 const gchar *group_name)
2328 g_return_val_if_fail (info != NULL, FALSE);
2329 g_return_val_if_fail (group_name != NULL, FALSE);
2334 for (l = info->groups; l != NULL; l = l->next)
2336 gchar *g = (gchar *) l->data;
2338 if (strcmp (g, group_name) == 0)
2346 * _gtk_recent_manager_sync:
2348 * Private function for synchronising the recent manager singleton.
2351 _gtk_recent_manager_sync (void)
2353 if (recent_manager_singleton)
2355 /* force a dump of the contents of the recent manager singleton */
2356 recent_manager_singleton->priv->is_dirty = TRUE;
2357 gtk_recent_manager_real_changed (recent_manager_singleton);
2361 #define __GTK_RECENT_MANAGER_C__
2362 #include "gtkaliasdef.c"