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"
45 #define XDG_PREFIX _gtk_xdg
46 #include "xdgmime/xdgmime.h"
49 /* the file where we store the recently used items */
50 #define GTK_RECENTLY_USED_FILE ".recently-used.xbel"
52 /* return all items by default */
53 #define DEFAULT_LIMIT -1
55 /* keep in sync with xdgmime */
56 #define GTK_RECENT_DEFAULT_MIME "application/octet-stream"
82 GHashTable *apps_lookup;
93 #define GTK_RECENT_MANAGER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_RECENT_MANAGER, GtkRecentManagerPrivate))
95 struct _GtkRecentManagerPrivate
104 GBookmarkFile *recent_items;
106 GFileMonitor *monitor;
118 static void gtk_recent_manager_dispose (GObject *object);
119 static void gtk_recent_manager_finalize (GObject *object);
120 static void gtk_recent_manager_set_property (GObject *object,
124 static void gtk_recent_manager_get_property (GObject *object,
128 static void gtk_recent_manager_add_item_query_info_cb (GObject *source_object,
131 static void gtk_recent_manager_monitor_changed (GFileMonitor *monitor,
134 GFileMonitorEvent event_type,
136 static void gtk_recent_manager_changed (GtkRecentManager *manager);
137 static void gtk_recent_manager_real_changed (GtkRecentManager *manager);
138 static void gtk_recent_manager_set_filename (GtkRecentManager *manager,
139 const gchar *filename);
141 static void build_recent_items_list (GtkRecentManager *manager);
142 static void purge_recent_items_list (GtkRecentManager *manager,
145 static RecentAppInfo *recent_app_info_new (const gchar *app_name);
146 static void recent_app_info_free (RecentAppInfo *app_info);
148 static GtkRecentInfo *gtk_recent_info_new (const gchar *uri);
149 static void gtk_recent_info_free (GtkRecentInfo *recent_info);
151 static guint signal_changed = 0;
153 static GtkRecentManager *recent_manager_singleton = NULL;
155 G_DEFINE_TYPE (GtkRecentManager, gtk_recent_manager, G_TYPE_OBJECT)
158 filename_warning (const gchar *format,
159 const gchar *filename,
160 const gchar *message)
162 gchar *utf8 = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
163 g_warning (format, utf8 ? utf8 : "(invalid filename)", message);
167 /* Test of haystack has the needle prefix, comparing case
168 * insensitive. haystack may be UTF-8, but needle must
169 * contain only lowercase ascii. */
171 has_case_prefix (const gchar *haystack,
176 /* Eat one character at a time. */
180 while (*n && *h && *n == g_ascii_tolower (*h))
190 gtk_recent_manager_error_quark (void)
192 return g_quark_from_static_string ("gtk-recent-manager-error-quark");
196 gtk_recent_manager_class_init (GtkRecentManagerClass *klass)
198 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
200 gobject_class->set_property = gtk_recent_manager_set_property;
201 gobject_class->get_property = gtk_recent_manager_get_property;
202 gobject_class->dispose = gtk_recent_manager_dispose;
203 gobject_class->finalize = gtk_recent_manager_finalize;
206 * GtkRecentManager:filename
208 * The full path to the file to be used to store and read the recently
209 * used resources list
213 g_object_class_install_property (gobject_class,
215 g_param_spec_string ("filename",
217 P_("The full path to the file to be used to store and read the list"),
219 (G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE)));
221 * GtkRecentManager:limit
223 * The maximum number of items to be returned by the
224 * gtk_recent_manager_get_items() function.
228 g_object_class_install_property (gobject_class,
230 g_param_spec_int ("limit",
232 P_("The maximum number of items to be returned by gtk_recent_manager_get_items()"),
238 * GtkRecentManager:size
240 * The size of the recently used resources list.
244 g_object_class_install_property (gobject_class,
246 g_param_spec_int ("size",
248 P_("The size of the recently used resources list"),
255 * GtkRecentManager::changed
256 * @recent_manager: the recent manager
258 * Emitted when the current recently used resources manager changes its
264 g_signal_new (I_("changed"),
265 G_TYPE_FROM_CLASS (klass),
267 G_STRUCT_OFFSET (GtkRecentManagerClass, changed),
269 g_cclosure_marshal_VOID__VOID,
272 klass->changed = gtk_recent_manager_real_changed;
274 g_type_class_add_private (klass, sizeof (GtkRecentManagerPrivate));
278 gtk_recent_manager_init (GtkRecentManager *manager)
280 GtkRecentManagerPrivate *priv;
283 manager->priv = priv = GTK_RECENT_MANAGER_GET_PRIVATE (manager);
285 priv->limit = DEFAULT_LIMIT;
288 /* this will take care of building the files list */
289 filename = g_build_filename (g_get_home_dir (),
290 GTK_RECENTLY_USED_FILE,
292 gtk_recent_manager_set_filename (manager, filename);
297 gtk_recent_manager_set_property (GObject *object,
302 GtkRecentManager *recent_manager = GTK_RECENT_MANAGER (object);
307 gtk_recent_manager_set_filename (recent_manager, g_value_get_string (value));
310 gtk_recent_manager_set_limit (recent_manager, g_value_get_int (value));
313 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
319 gtk_recent_manager_get_property (GObject *object,
324 GtkRecentManager *recent_manager = GTK_RECENT_MANAGER (object);
329 g_value_set_string (value, recent_manager->priv->filename);
332 g_value_set_int (value, recent_manager->priv->limit);
335 g_value_set_int (value, recent_manager->priv->size);
338 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
344 gtk_recent_manager_dispose (GObject *object)
346 GtkRecentManager *manager = GTK_RECENT_MANAGER (object);
347 GtkRecentManagerPrivate *priv = manager->priv;
351 g_signal_handlers_disconnect_by_func (priv->monitor,
352 G_CALLBACK (gtk_recent_manager_monitor_changed),
354 g_object_unref (priv->monitor);
355 priv->monitor = NULL;
358 G_OBJECT_CLASS (gtk_recent_manager_parent_class)->dispose (object);
362 gtk_recent_manager_finalize (GObject *object)
364 GtkRecentManager *manager = GTK_RECENT_MANAGER (object);
365 GtkRecentManagerPrivate *priv = manager->priv;
367 g_free (priv->filename);
369 if (priv->recent_items)
370 g_bookmark_file_free (priv->recent_items);
372 G_OBJECT_CLASS (gtk_recent_manager_parent_class)->finalize (object);
376 gtk_recent_manager_real_changed (GtkRecentManager *manager)
378 GtkRecentManagerPrivate *priv = manager->priv;
380 g_object_freeze_notify (G_OBJECT (manager));
386 /* we are marked as dirty, so we dump the content of our
387 * recently used items list
389 g_assert (priv->filename != NULL);
391 /* if no container object has been defined, we create a new
392 * empty container, and dump it
394 if (!priv->recent_items)
396 priv->recent_items = g_bookmark_file_new ();
401 g_bookmark_file_to_file (priv->recent_items, priv->filename, &write_error);
404 filename_warning ("Attempting to store changes into `%s', "
407 write_error->message);
408 g_error_free (write_error);
411 /* mark us as clean */
412 priv->is_dirty = FALSE;
416 /* we are not marked as dirty, so we have been called
417 * because the recently used resources file has been
418 * changed (and not from us).
420 build_recent_items_list (manager);
423 g_object_thaw_notify (G_OBJECT (manager));
427 gtk_recent_manager_monitor_changed (GFileMonitor *monitor,
430 GFileMonitorEvent event_type,
433 GtkRecentManager *manager = user_data;
437 case G_FILE_MONITOR_EVENT_CHANGED:
438 case G_FILE_MONITOR_EVENT_CREATED:
439 gtk_recent_manager_changed (manager);
442 case G_FILE_MONITOR_EVENT_DELETED:
451 gtk_recent_manager_set_filename (GtkRecentManager *manager,
452 const gchar *filename)
454 GtkRecentManagerPrivate *priv;
458 g_assert (GTK_IS_RECENT_MANAGER (manager));
460 priv = manager->priv;
462 g_free (priv->filename);
466 g_signal_handlers_disconnect_by_func (priv->monitor,
467 G_CALLBACK (gtk_recent_manager_monitor_changed),
469 g_object_unref (priv->monitor);
470 priv->monitor = NULL;
473 if (!filename || filename[0] == '\0')
476 priv->filename = g_strdup (filename);
477 file = g_file_new_for_path (priv->filename);
480 priv->monitor = g_file_monitor_file (file, G_FILE_MONITOR_NONE, NULL, &error);
483 filename_warning ("Unable to monitor `%s': %s\n"
484 "The GtkRecentManager will not update its contents "
485 "if the file is changed from other instances",
488 g_error_free (error);
491 g_signal_connect (priv->monitor, "changed",
492 G_CALLBACK (gtk_recent_manager_monitor_changed),
495 g_object_unref (file);
497 priv->is_dirty = FALSE;
498 build_recent_items_list (manager);
501 /* reads the recently used resources file and builds the items list.
502 * we keep the items list inside the parser object, and build the
503 * RecentInfo object only on user's demand to avoid useless replication.
504 * this function resets the dirty bit of the manager.
507 build_recent_items_list (GtkRecentManager *manager)
509 GtkRecentManagerPrivate *priv = manager->priv;
513 g_assert (priv->filename != NULL);
515 if (!priv->recent_items)
517 priv->recent_items = g_bookmark_file_new ();
521 /* the file exists, and it's valid (we hope); if not, destroy the container
522 * object and hope for a better result when the next "changed" signal is
525 g_bookmark_file_load_from_file (priv->recent_items, priv->filename, &read_error);
528 /* if the file does not exist we just wait for the first write
529 * operation on this recent manager instance, to avoid creating
530 * empty files and leading to spurious file system events (Sabayon
531 * will not be happy about those)
533 if (read_error->domain == G_FILE_ERROR &&
534 read_error->code != G_FILE_ERROR_NOENT)
535 filename_warning ("Attempting to read the recently used resources "
536 "file at `%s', but the parser failed: %s.",
538 read_error->message);
540 g_bookmark_file_free (priv->recent_items);
541 priv->recent_items = NULL;
543 g_error_free (read_error);
547 size = g_bookmark_file_get_size (priv->recent_items);
548 if (priv->size != size)
552 g_object_notify (G_OBJECT (manager), "size");
556 priv->is_dirty = FALSE;
560 /********************
562 ********************/
566 * gtk_recent_manager_new:
568 * Creates a new recent manager object. Recent manager objects are used to
569 * handle the list of recently used resources. A #GtkRecentManager object
570 * monitors the recently used resources list, and emits the "changed" signal
571 * each time something inside the list changes.
573 * #GtkRecentManager objects are expensive: be sure to create them only when
574 * needed. You should use gtk_recent_manager_get_default() instead.
576 * Return value: A newly created #GtkRecentManager object.
581 gtk_recent_manager_new (void)
583 return g_object_new (GTK_TYPE_RECENT_MANAGER, NULL);
587 * gtk_recent_manager_get_default:
589 * Gets a unique instance of #GtkRecentManager, that you can share
590 * in your application without caring about memory management. The
591 * returned instance will be freed when you application terminates.
593 * Return value: A unique #GtkRecentManager. Do not ref or unref it.
598 gtk_recent_manager_get_default (void)
600 if (G_UNLIKELY (!recent_manager_singleton))
601 recent_manager_singleton = gtk_recent_manager_new ();
603 return recent_manager_singleton;
607 * gtk_recent_manager_get_for_screen:
608 * @screen: a #GdkScreen
610 * Gets the recent manager object associated with @screen; if this
611 * function has not previously been called for the given screen,
612 * a new recent manager object will be created and associated with
613 * the screen. Recent manager objects are fairly expensive to create,
614 * so using this function is usually a better choice than calling
615 * gtk_recent_manager_new() and setting the screen yourself; by using
616 * this function a single recent manager object will be shared between
619 * Return value: A unique #GtkRecentManager associated with the given
620 * screen. This recent manager is associated to the with the screen
621 * and can be used as long as the screen is open. Do not ref or
624 * Deprecated: 2.12: This function has been deprecated and should
625 * not be used in newly written code. Calling this function is
626 * equivalent to calling gtk_recent_manager_get_default().
631 gtk_recent_manager_get_for_screen (GdkScreen *screen)
633 return gtk_recent_manager_get_default ();
637 * gtk_recent_manager_set_screen:
638 * @manager: a #GtkRecentManager
639 * @screen: a #GdkScreen
641 * Sets the screen for a recent manager; the screen is used to
642 * track the user's currently configured recently used documents
647 * Deprecated: 2.12: This function has been deprecated and should
648 * not be used in newly written code. Calling this function has
652 gtk_recent_manager_set_screen (GtkRecentManager *manager,
659 * gtk_recent_manager_set_limit:
660 * @manager: a #GtkRecentManager
661 * @limit: the maximum number of items to return, or -1.
663 * Sets the maximum number of item that the gtk_recent_manager_get_items()
664 * function should return. If @limit is set to -1, then return all the
670 gtk_recent_manager_set_limit (GtkRecentManager *manager,
673 GtkRecentManagerPrivate *priv;
675 g_return_if_fail (GTK_IS_RECENT_MANAGER (manager));
677 priv = manager->priv;
682 * gtk_recent_manager_get_limit:
683 * @manager: a #GtkRecentManager
685 * Gets the maximum number of items that the gtk_recent_manager_get_items()
686 * function should return.
688 * Return value: the number of items to return, or -1 for every item.
693 gtk_recent_manager_get_limit (GtkRecentManager *manager)
695 GtkRecentManagerPrivate *priv;
697 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), DEFAULT_LIMIT);
699 priv = manager->priv;
704 gtk_recent_manager_add_item_query_info_cb (GObject *source_object,
708 GFile *file = G_FILE (source_object);
709 GtkRecentManager *manager = user_data;
710 GtkRecentData recent_data;
711 GFileInfo *file_info;
715 uri = g_file_get_uri (file);
718 file_info = g_file_query_info_finish (file, res, &error);
721 g_warning ("Unable to retrieve the file info for `%s': %s",
724 g_error_free (error);
728 recent_data.display_name = NULL;
729 recent_data.description = NULL;
733 recent_data.mime_type = g_content_type_get_mime_type (g_file_info_get_content_type (file_info));
734 g_object_unref (file_info);
737 recent_data.mime_type = g_strdup (GTK_RECENT_DEFAULT_MIME);
739 recent_data.app_name = g_strdup (g_get_application_name ());
740 recent_data.app_exec = g_strjoin (" ", g_get_prgname (), "%u", NULL);
741 recent_data.groups = NULL;
742 recent_data.is_private = FALSE;
744 /* Ignore return value, this can't fail anyway since all required
746 gtk_recent_manager_add_full (manager, uri, &recent_data);
748 g_free (recent_data.mime_type);
749 g_free (recent_data.app_name);
750 g_free (recent_data.app_exec);
753 g_object_unref (manager);
758 * gtk_recent_manager_add_item:
759 * @manager: a #GtkRecentManager
762 * Adds a new resource, pointed by @uri, into the recently used
765 * This function automatically retrieves some of the needed
766 * metadata and setting other metadata to common default values; it
767 * then feeds the data to gtk_recent_manager_add_full().
769 * See gtk_recent_manager_add_full() if you want to explicitly
770 * define the metadata for the resource pointed by @uri.
772 * Return value: %TRUE if the new item was successfully added
773 * to the recently used resources list
778 gtk_recent_manager_add_item (GtkRecentManager *manager,
783 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), FALSE);
784 g_return_val_if_fail (uri != NULL, FALSE);
786 file = g_file_new_for_uri (uri);
788 g_file_query_info_async (file,
789 G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE,
791 G_FILE_QUERY_INFO_NONE,
793 gtk_recent_manager_add_item_query_info_cb,
794 g_object_ref (manager));
796 g_object_unref (file);
802 * gtk_recent_manager_add_full:
803 * @manager: a #GtkRecentManager
805 * @recent_data: metadata of the resource
807 * Adds a new resource, pointed by @uri, into the recently used
808 * resources list, using the metadata specified inside the #GtkRecentData
809 * structure passed in @recent_data.
811 * The passed URI will be used to identify this resource inside the
814 * In order to register the new recently used resource, metadata about
815 * the resource must be passed as well as the URI; the metadata is
816 * stored in a #GtkRecentData structure, which must contain the MIME
817 * type of the resource pointed by the URI; the name of the application
818 * that is registering the item, and a command line to be used when
819 * launching the item.
821 * Optionally, a #GtkRecentData structure might contain a UTF-8 string
822 * to be used when viewing the item instead of the last component of the
823 * URI; a short description of the item; whether the item should be
824 * considered private - that is, should be displayed only by the
825 * applications that have registered it.
827 * Return value: %TRUE if the new item was successfully added to the
828 * recently used resources list, %FALSE otherwise.
833 gtk_recent_manager_add_full (GtkRecentManager *manager,
835 const GtkRecentData *data)
837 GtkRecentManagerPrivate *priv;
839 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), FALSE);
840 g_return_val_if_fail (uri != NULL, FALSE);
841 g_return_val_if_fail (data != NULL, FALSE);
844 if ((data->display_name) &&
845 (!g_utf8_validate (data->display_name, -1, NULL)))
847 g_warning ("Attempting to add `%s' to the list of recently used "
848 "resources, but the display name is not a valid UTF-8 "
854 if ((data->description) &&
855 (!g_utf8_validate (data->description, -1, NULL)))
857 g_warning ("Attempting to add `%s' to the list of recently used "
858 "resources, but the description is not a valid UTF-8 "
865 if (!data->mime_type)
867 g_warning ("Attempting to add `%s' to the list of recently used "
868 "resources, but not MIME type was defined",
875 g_warning ("Attempting to add `%s' to the list of recently used "
876 "resources, but no name of the application that is "
877 "registering it was defined",
884 g_warning ("Attempting to add `%s' to the list of recently used "
885 "resources, but no command line for the application "
886 "that is registering it was defined",
891 priv = manager->priv;
893 if (!priv->recent_items)
895 priv->recent_items = g_bookmark_file_new ();
899 if (data->display_name)
900 g_bookmark_file_set_title (priv->recent_items, uri, data->display_name);
902 if (data->description)
903 g_bookmark_file_set_description (priv->recent_items, uri, data->description);
905 g_bookmark_file_set_mime_type (priv->recent_items, uri, data->mime_type);
907 if (data->groups && data->groups[0] != '\0')
911 for (j = 0; (data->groups)[j] != NULL; j++)
912 g_bookmark_file_add_group (priv->recent_items, uri, (data->groups)[j]);
915 /* register the application; this will take care of updating the
916 * registration count and time in case the application has
917 * already registered the same document inside the list
919 g_bookmark_file_add_application (priv->recent_items, uri,
923 g_bookmark_file_set_is_private (priv->recent_items, uri,
926 /* mark us as dirty, so that when emitting the "changed" signal we
927 * will dump our changes
929 priv->is_dirty = TRUE;
931 gtk_recent_manager_changed (manager);
937 * gtk_recent_manager_remove_item:
938 * @manager: a #GtkRecentManager
939 * @uri: the URI of the item you wish to remove
940 * @error: return location for a #GError, or %NULL
942 * Removes a resource pointed by @uri from the recently used resources
943 * list handled by a recent manager.
945 * Return value: %TRUE if the item pointed by @uri has been successfully
946 * removed by the recently used resources list, and %FALSE otherwise.
951 gtk_recent_manager_remove_item (GtkRecentManager *manager,
955 GtkRecentManagerPrivate *priv;
956 GError *remove_error = NULL;
958 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), FALSE);
959 g_return_val_if_fail (uri != NULL, FALSE);
960 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
962 priv = manager->priv;
964 if (!priv->recent_items)
966 priv->recent_items = g_bookmark_file_new ();
969 g_set_error (error, GTK_RECENT_MANAGER_ERROR,
970 GTK_RECENT_MANAGER_ERROR_NOT_FOUND,
971 _("Unable to find an item with URI '%s'"),
977 g_bookmark_file_remove_item (priv->recent_items, uri, &remove_error);
980 g_propagate_error (error, remove_error);
985 priv->is_dirty = TRUE;
987 gtk_recent_manager_changed (manager);
993 * gtk_recent_manager_has_item:
994 * @manager: a #GtkRecentManager
997 * Checks whether there is a recently used resource registered
998 * with @uri inside the recent manager.
1000 * Return value: %TRUE if the resource was found, %FALSE otherwise.
1005 gtk_recent_manager_has_item (GtkRecentManager *manager,
1008 GtkRecentManagerPrivate *priv;
1010 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), FALSE);
1011 g_return_val_if_fail (uri != NULL, FALSE);
1013 priv = manager->priv;
1014 g_return_val_if_fail (priv->recent_items != NULL, FALSE);
1016 return g_bookmark_file_has_item (priv->recent_items, uri);
1020 build_recent_info (GBookmarkFile *bookmarks,
1021 GtkRecentInfo *info)
1023 gchar **apps, **groups;
1024 gsize apps_len, groups_len, i;
1026 g_assert (bookmarks != NULL);
1027 g_assert (info != NULL);
1029 info->display_name = g_bookmark_file_get_title (bookmarks, info->uri, NULL);
1030 info->description = g_bookmark_file_get_description (bookmarks, info->uri, NULL);
1031 info->mime_type = g_bookmark_file_get_mime_type (bookmarks, info->uri, NULL);
1033 info->is_private = g_bookmark_file_get_is_private (bookmarks, info->uri, NULL);
1035 info->added = g_bookmark_file_get_added (bookmarks, info->uri, NULL);
1036 info->modified = g_bookmark_file_get_modified (bookmarks, info->uri, NULL);
1037 info->visited = g_bookmark_file_get_visited (bookmarks, info->uri, NULL);
1039 groups = g_bookmark_file_get_groups (bookmarks, info->uri, &groups_len, NULL);
1040 for (i = 0; i < groups_len; i++)
1042 gchar *group_name = g_strdup (groups[i]);
1044 info->groups = g_slist_append (info->groups, group_name);
1047 g_strfreev (groups);
1049 apps = g_bookmark_file_get_applications (bookmarks, info->uri, &apps_len, NULL);
1050 for (i = 0; i < apps_len; i++)
1052 gchar *app_name, *app_exec;
1055 RecentAppInfo *app_info;
1060 res = g_bookmark_file_get_app_info (bookmarks, info->uri, app_name,
1068 app_info = recent_app_info_new (app_name);
1069 app_info->exec = app_exec;
1070 app_info->count = count;
1071 app_info->stamp = stamp;
1073 info->applications = g_slist_prepend (info->applications, app_info);
1074 g_hash_table_replace (info->apps_lookup, app_info->name, app_info);
1081 * gtk_recent_manager_lookup_item:
1082 * @manager: a #GtkRecentManager
1084 * @error: a return location for a #GError, or %NULL
1086 * Searches for a URI inside the recently used resources list, and
1087 * returns a structure containing informations about the resource
1088 * like its MIME type, or its display name.
1090 * Return value: a #GtkRecentInfo structure containing information
1091 * about the resource pointed by @uri, or %NULL if the URI was
1092 * not registered in the recently used resources list. Free with
1093 * gtk_recent_info_unref().
1098 gtk_recent_manager_lookup_item (GtkRecentManager *manager,
1102 GtkRecentManagerPrivate *priv;
1103 GtkRecentInfo *info = NULL;
1105 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), NULL);
1106 g_return_val_if_fail (uri != NULL, NULL);
1107 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
1109 priv = manager->priv;
1110 if (!priv->recent_items)
1112 priv->recent_items = g_bookmark_file_new ();
1115 g_set_error (error, GTK_RECENT_MANAGER_ERROR,
1116 GTK_RECENT_MANAGER_ERROR_NOT_FOUND,
1117 _("Unable to find an item with URI '%s'"),
1123 if (!g_bookmark_file_has_item (priv->recent_items, uri))
1125 g_set_error (error, GTK_RECENT_MANAGER_ERROR,
1126 GTK_RECENT_MANAGER_ERROR_NOT_FOUND,
1127 _("Unable to find an item with URI '%s'"),
1132 info = gtk_recent_info_new (uri);
1133 g_return_val_if_fail (info != NULL, NULL);
1135 /* fill the RecentInfo structure with the data retrieved by our
1136 * parser object from the storage file
1138 build_recent_info (priv->recent_items, info);
1144 * gtk_recent_manager_move_item:
1145 * @manager: a #GtkRecentManager
1146 * @uri: the URI of a recently used resource
1147 * @new_uri: the new URI of the recently used resource, or %NULL to
1148 * remove the item pointed by @uri in the list
1149 * @error: a return location for a #GError, or %NULL
1151 * Changes the location of a recently used resource from @uri to @new_uri.
1153 * Please note that this function will not affect the resource pointed
1154 * by the URIs, but only the URI used in the recently used resources list.
1156 * Return value: %TRUE on success.
1161 gtk_recent_manager_move_item (GtkRecentManager *recent_manager,
1163 const gchar *new_uri,
1166 GtkRecentManagerPrivate *priv;
1170 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (recent_manager), FALSE);
1171 g_return_val_if_fail (uri != NULL, FALSE);
1172 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
1174 priv = recent_manager->priv;
1176 if (!g_bookmark_file_has_item (priv->recent_items, uri))
1178 g_set_error (error, GTK_RECENT_MANAGER_ERROR,
1179 GTK_RECENT_MANAGER_ERROR_NOT_FOUND,
1180 _("Unable to find an item with URI '%s'"),
1186 res = g_bookmark_file_move_item (priv->recent_items,
1191 g_propagate_error (error, move_error);
1195 priv->is_dirty = TRUE;
1197 gtk_recent_manager_changed (recent_manager);
1203 * gtk_recent_manager_get_items:
1204 * @manager: a #GtkRecentManager
1206 * Gets the list of recently used resources.
1208 * Return value: a list of newly allocated #GtkRecentInfo objects. Use
1209 * gtk_recent_info_unref() on each item inside the list, and then
1210 * free the list itself using g_list_free().
1215 gtk_recent_manager_get_items (GtkRecentManager *manager)
1217 GtkRecentManagerPrivate *priv;
1218 GList *retval = NULL;
1222 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), NULL);
1224 priv = manager->priv;
1225 if (!priv->recent_items)
1228 if (priv->limit == 0)
1231 uris = g_bookmark_file_get_uris (priv->recent_items, &uris_len);
1232 for (i = 0; i < uris_len; i++)
1234 GtkRecentInfo *info;
1236 if (priv->limit != -1 && i == priv->limit)
1239 info = gtk_recent_info_new (uris[i]);
1240 build_recent_info (priv->recent_items, info);
1242 retval = g_list_prepend (retval, info);
1251 purge_recent_items_list (GtkRecentManager *manager,
1254 GtkRecentManagerPrivate *priv = manager->priv;
1256 if (!priv->recent_items)
1259 g_bookmark_file_free (priv->recent_items);
1260 priv->recent_items = NULL;
1262 priv->recent_items = g_bookmark_file_new ();
1264 priv->is_dirty = TRUE;
1266 /* emit the changed signal, to ensure that the purge is written */
1267 gtk_recent_manager_changed (manager);
1271 * gtk_recent_manager_purge_items:
1272 * @manager: a #GtkRecentManager
1273 * @error: a return location for a #GError, or %NULL
1275 * Purges every item from the recently used resources list.
1277 * Return value: the number of items that have been removed from the
1278 * recently used resources list.
1283 gtk_recent_manager_purge_items (GtkRecentManager *manager,
1286 GtkRecentManagerPrivate *priv;
1289 g_return_val_if_fail (GTK_IS_RECENT_MANAGER (manager), -1);
1291 priv = manager->priv;
1292 if (!priv->recent_items)
1295 count = g_bookmark_file_get_size (priv->recent_items);
1299 purge_recent_items_list (manager, error);
1301 purged = count - g_bookmark_file_get_size (priv->recent_items);
1307 gtk_recent_manager_changed (GtkRecentManager *recent_manager)
1309 g_signal_emit (recent_manager, signal_changed, 0);
1317 gtk_recent_info_get_type (void)
1319 static GType info_type = 0;
1322 info_type = g_boxed_type_register_static (I_("GtkRecentInfo"),
1323 (GBoxedCopyFunc) gtk_recent_info_ref,
1324 (GBoxedFreeFunc) gtk_recent_info_unref);
1328 static GtkRecentInfo *
1329 gtk_recent_info_new (const gchar *uri)
1331 GtkRecentInfo *info;
1333 g_assert (uri != NULL);
1335 info = g_new0 (GtkRecentInfo, 1);
1336 info->uri = g_strdup (uri);
1338 info->applications = NULL;
1339 info->apps_lookup = g_hash_table_new (g_str_hash, g_str_equal);
1341 info->groups = NULL;
1343 info->ref_count = 1;
1349 gtk_recent_info_free (GtkRecentInfo *recent_info)
1354 g_free (recent_info->uri);
1355 g_free (recent_info->display_name);
1356 g_free (recent_info->description);
1357 g_free (recent_info->mime_type);
1359 if (recent_info->applications)
1361 g_slist_foreach (recent_info->applications,
1362 (GFunc) recent_app_info_free,
1364 g_slist_free (recent_info->applications);
1366 recent_info->applications = NULL;
1369 if (recent_info->apps_lookup)
1370 g_hash_table_destroy (recent_info->apps_lookup);
1372 if (recent_info->groups)
1374 g_slist_foreach (recent_info->groups,
1377 g_slist_free (recent_info->groups);
1379 recent_info->groups = NULL;
1382 if (recent_info->icon)
1383 g_object_unref (recent_info->icon);
1385 g_free (recent_info);
1389 * gtk_recent_info_ref:
1390 * @info: a #GtkRecentInfo
1392 * Increases the reference count of @recent_info by one.
1394 * Return value: the recent info object with its reference count increased
1400 gtk_recent_info_ref (GtkRecentInfo *info)
1402 g_return_val_if_fail (info != NULL, NULL);
1403 g_return_val_if_fail (info->ref_count > 0, NULL);
1405 info->ref_count += 1;
1411 * gtk_recent_info_unref:
1412 * @info: a #GtkRecentInfo
1414 * Decreases the reference count of @info by one. If the reference
1415 * count reaches zero, @info is deallocated, and the memory freed.
1420 gtk_recent_info_unref (GtkRecentInfo *info)
1422 g_return_if_fail (info != NULL);
1423 g_return_if_fail (info->ref_count > 0);
1425 info->ref_count -= 1;
1427 if (info->ref_count == 0)
1428 gtk_recent_info_free (info);
1432 * gtk_recent_info_get_uri:
1433 * @info: a #GtkRecentInfo
1435 * Gets the URI of the resource.
1437 * Return value: the URI of the resource. The returned string is
1438 * owned by the recent manager, and should not be freed.
1442 G_CONST_RETURN gchar *
1443 gtk_recent_info_get_uri (GtkRecentInfo *info)
1445 g_return_val_if_fail (info != NULL, NULL);
1451 * gtk_recent_info_get_display_name:
1452 * @info: a #GtkRecentInfo
1454 * Gets the name of the resource. If none has been defined, the basename
1455 * of the resource is obtained.
1457 * Return value: the display name of the resource. The returned string
1458 * is owned by the recent manager, and should not be freed.
1462 G_CONST_RETURN gchar *
1463 gtk_recent_info_get_display_name (GtkRecentInfo *info)
1465 g_return_val_if_fail (info != NULL, NULL);
1467 if (!info->display_name)
1468 info->display_name = gtk_recent_info_get_short_name (info);
1470 return info->display_name;
1474 * gtk_recent_info_get_description:
1475 * @info: a #GtkRecentInfo
1477 * Gets the (short) description of the resource.
1479 * Return value: the description of the resource. The returned string
1480 * is owned by the recent manager, and should not be freed.
1484 G_CONST_RETURN gchar *
1485 gtk_recent_info_get_description (GtkRecentInfo *info)
1487 g_return_val_if_fail (info != NULL, NULL);
1489 return info->description;
1493 * gtk_recent_info_get_mime_type:
1494 * @info: a #GtkRecentInfo
1496 * Gets the MIME type of the resource.
1498 * Return value: the MIME type of the resource. The returned string
1499 * is owned by the recent manager, and should not be freed.
1503 G_CONST_RETURN gchar *
1504 gtk_recent_info_get_mime_type (GtkRecentInfo *info)
1506 g_return_val_if_fail (info != NULL, NULL);
1508 if (!info->mime_type)
1509 info->mime_type = g_strdup (GTK_RECENT_DEFAULT_MIME);
1511 return info->mime_type;
1515 * gtk_recent_info_get_added:
1516 * @info: a #GtkRecentInfo
1518 * Gets the timestamp (seconds from system's Epoch) when the resource
1519 * was added to the recently used resources list.
1521 * Return value: the number of seconds elapsed from system's Epoch when
1522 * the resource was added to the list, or -1 on failure.
1527 gtk_recent_info_get_added (GtkRecentInfo *info)
1529 g_return_val_if_fail (info != NULL, (time_t) -1);
1535 * gtk_recent_info_get_modified:
1536 * @info: a #GtkRecentInfo
1538 * Gets the timestamp (seconds from system's Epoch) when the resource
1539 * was last modified.
1541 * Return value: the number of seconds elapsed from system's Epoch when
1542 * the resource was last modified, or -1 on failure.
1547 gtk_recent_info_get_modified (GtkRecentInfo *info)
1549 g_return_val_if_fail (info != NULL, (time_t) -1);
1551 return info->modified;
1555 * gtk_recent_info_get_visited:
1556 * @info: a #GtkRecentInfo
1558 * Gets the timestamp (seconds from system's Epoch) when the resource
1561 * Return value: the number of seconds elapsed from system's Epoch when
1562 * the resource was last visited, or -1 on failure.
1567 gtk_recent_info_get_visited (GtkRecentInfo *info)
1569 g_return_val_if_fail (info != NULL, (time_t) -1);
1571 return info->visited;
1575 * gtk_recent_info_get_private_hint:
1576 * @info: a #GtkRecentInfo
1578 * Gets the value of the "private" flag. Resources in the recently used
1579 * list that have this flag set to %TRUE should only be displayed by the
1580 * applications that have registered them.
1582 * Return value: %TRUE if the private flag was found, %FALSE otherwise.
1587 gtk_recent_info_get_private_hint (GtkRecentInfo *info)
1589 g_return_val_if_fail (info != NULL, FALSE);
1591 return info->is_private;
1595 static RecentAppInfo *
1596 recent_app_info_new (const gchar *app_name)
1598 RecentAppInfo *app_info;
1600 g_assert (app_name != NULL);
1602 app_info = g_new0 (RecentAppInfo, 1);
1603 app_info->name = g_strdup (app_name);
1604 app_info->exec = NULL;
1605 app_info->count = 1;
1606 app_info->stamp = time (NULL);
1612 recent_app_info_free (RecentAppInfo *app_info)
1617 g_free (app_info->name);
1619 g_free (app_info->exec);
1625 * gtk_recent_info_get_application_info:
1626 * @info: a #GtkRecentInfo
1627 * @app_name: the name of the application that has registered this item
1628 * @app_exec: return location for the string containing the command line
1629 * @count: return location for the number of times this item was registered
1630 * @time_: return location for the timestamp this item was last registered
1631 * for this application
1633 * Gets the data regarding the application that has registered the resource
1636 * If the command line contains any escape characters defined inside the
1637 * storage specification, they will be expanded.
1639 * Return value: %TRUE if an application with @app_name has registered this
1640 * resource inside the recently used list, or %FALSE otherwise. You should
1641 * free the returned command line using g_free().
1646 gtk_recent_info_get_application_info (GtkRecentInfo *info,
1647 const gchar *app_name,
1654 g_return_val_if_fail (info != NULL, FALSE);
1655 g_return_val_if_fail (app_name != NULL, FALSE);
1657 ai = (RecentAppInfo *) g_hash_table_lookup (info->apps_lookup,
1661 g_warning ("No registered application with name '%s' "
1662 "for item with URI '%s' found",
1669 *app_exec = ai->exec;
1681 * gtk_recent_info_get_applications:
1682 * @info: a #GtkRecentInfo
1683 * @length: return location for the length of the returned list, or %NULL
1685 * Retrieves the list of applications that have registered this resource.
1687 * Return value: a newly allocated %NULL-terminated array of strings.
1688 * Use g_strfreev() to free it.
1693 gtk_recent_info_get_applications (GtkRecentInfo *info,
1700 g_return_val_if_fail (info != NULL, NULL);
1702 if (!info->applications)
1710 n_apps = g_slist_length (info->applications);
1712 retval = g_new0 (gchar *, n_apps + 1);
1714 for (l = info->applications, i = 0;
1718 RecentAppInfo *ai = (RecentAppInfo *) l->data;
1720 g_assert (ai != NULL);
1722 retval[i++] = g_strdup (ai->name);
1733 * gtk_recent_info_has_application:
1734 * @info: a #GtkRecentInfo
1735 * @app_name: a string containing an application name
1737 * Checks whether an application registered this resource using @app_name.
1739 * Return value: %TRUE if an application with name @app_name was found,
1745 gtk_recent_info_has_application (GtkRecentInfo *info,
1746 const gchar *app_name)
1748 g_return_val_if_fail (info != NULL, FALSE);
1749 g_return_val_if_fail (app_name != NULL, FALSE);
1751 return (NULL != g_hash_table_lookup (info->apps_lookup, app_name));
1755 * gtk_recent_info_last_application:
1756 * @info: a #GtkRecentInfo
1758 * Gets the name of the last application that have registered the
1759 * recently used resource represented by @info.
1761 * Return value: an application name. Use g_free() to free it.
1766 gtk_recent_info_last_application (GtkRecentInfo *info)
1769 time_t last_stamp = (time_t) -1;
1772 g_return_val_if_fail (info != NULL, NULL);
1774 for (l = info->applications; l != NULL; l = l->next)
1776 RecentAppInfo *ai = (RecentAppInfo *) l->data;
1778 if (ai->stamp > last_stamp)
1781 last_stamp = ai->stamp;
1785 return g_strdup (name);
1789 get_icon_for_mime_type (const char *mime_type,
1792 GtkIconTheme *icon_theme;
1793 const char *separator;
1797 separator = strchr (mime_type, '/');
1801 icon_theme = gtk_icon_theme_get_default ();
1803 /* try with the three icon name variants for MIME types */
1805 /* canonicalize MIME type: foo/x-bar -> foo-x-bar */
1806 icon_name = g_string_new (NULL);
1807 g_string_append_len (icon_name, mime_type, separator - mime_type);
1808 g_string_append_c (icon_name, '-');
1809 g_string_append (icon_name, separator + 1);
1810 pixbuf = gtk_icon_theme_load_icon (icon_theme, icon_name->str,
1814 g_string_free (icon_name, TRUE);
1818 /* canonicalize MIME type, and prepend "gnome-mime-" */
1819 icon_name = g_string_new ("gnome-mime-");
1820 g_string_append_len (icon_name, mime_type, separator - mime_type);
1821 g_string_append_c (icon_name, '-');
1822 g_string_append (icon_name, separator + 1);
1823 pixbuf = gtk_icon_theme_load_icon (icon_theme, icon_name->str,
1827 g_string_free (icon_name, TRUE);
1831 /* try the MIME family icon */
1832 icon_name = g_string_new ("gnome-mime-");
1833 g_string_append_len (icon_name, mime_type, separator - mime_type);
1834 pixbuf = gtk_icon_theme_load_icon (icon_theme, icon_name->str,
1838 g_string_free (icon_name, TRUE);
1844 get_icon_fallback (const gchar *icon_name,
1847 GtkIconTheme *icon_theme;
1850 icon_theme = gtk_icon_theme_get_default ();
1852 retval = gtk_icon_theme_load_icon (icon_theme, icon_name,
1854 GTK_ICON_LOOKUP_USE_BUILTIN,
1856 g_assert (retval != NULL);
1862 * gtk_recent_info_get_icon:
1863 * @info: a #GtkRecentInfo
1864 * @size: the size of the icon in pixels
1866 * Retrieves the icon of size @size associated to the resource MIME type.
1868 * Return value: a #GdkPixbuf containing the icon, or %NULL. Use
1869 * g_object_unref() when finished using the icon.
1874 gtk_recent_info_get_icon (GtkRecentInfo *info,
1877 GdkPixbuf *retval = NULL;
1879 g_return_val_if_fail (info != NULL, NULL);
1881 if (info->mime_type)
1882 retval = get_icon_for_mime_type (info->mime_type, size);
1884 /* this function should never fail */
1887 if (info->mime_type &&
1888 strcmp (info->mime_type, "x-directory/normal") == 0)
1889 retval = get_icon_fallback (GTK_STOCK_DIRECTORY, size);
1891 retval = get_icon_fallback (GTK_STOCK_FILE, size);
1898 * gtk_recent_info_is_local:
1899 * @info: a #GtkRecentInfo
1901 * Checks whether the resource is local or not by looking at the
1902 * scheme of its URI.
1904 * Return value: %TRUE if the resource is local.
1909 gtk_recent_info_is_local (GtkRecentInfo *info)
1911 g_return_val_if_fail (info != NULL, FALSE);
1913 return has_case_prefix (info->uri, "file:/");
1917 * gtk_recent_info_exists:
1918 * @info: a #GtkRecentInfo
1920 * Checks whether the resource pointed by @info still exists. At
1921 * the moment this check is done only on resources pointing to local files.
1923 * Return value: %TRUE if the resource exists
1928 gtk_recent_info_exists (GtkRecentInfo *info)
1931 struct stat stat_buf;
1932 gboolean retval = FALSE;
1934 g_return_val_if_fail (info != NULL, FALSE);
1936 /* we guarantee only local resources */
1937 if (!gtk_recent_info_is_local (info))
1940 filename = g_filename_from_uri (info->uri, NULL, NULL);
1943 if (stat (filename, &stat_buf) == 0)
1953 * gtk_recent_info_match:
1954 * @info_a: a #GtkRecentInfo
1955 * @info_b: a #GtkRecentInfo
1957 * Checks whether two #GtkRecentInfo structures point to the same
1960 * Return value: %TRUE if both #GtkRecentInfo structures point to se same
1961 * resource, %FALSE otherwise.
1966 gtk_recent_info_match (GtkRecentInfo *info_a,
1967 GtkRecentInfo *info_b)
1969 g_return_val_if_fail (info_a != NULL, FALSE);
1970 g_return_val_if_fail (info_b != NULL, FALSE);
1972 return (0 == strcmp (info_a->uri, info_b->uri));
1975 /* taken from gnome-vfs-uri.c */
1976 static const gchar *
1977 get_method_string (const gchar *substring,
1978 gchar **method_string)
1984 g_ascii_isalnum (*p) || *p == '+' || *p == '-' || *p == '.';
1991 !(p == substring + 1 && g_ascii_isalpha (*substring))
1995 /* Found toplevel method specification. */
1996 method = g_strndup (substring, p - substring);
1997 *method_string = g_ascii_strdown (method, -1);
2003 *method_string = g_strdup ("file");
2010 /* Stolen from gnome_vfs_make_valid_utf8() */
2012 make_valid_utf8 (const char *name)
2015 const char *remainder, *invalid;
2016 int remaining_bytes, valid_bytes;
2020 remaining_bytes = name ? strlen (name) : 0;
2022 while (remaining_bytes != 0)
2024 if (g_utf8_validate (remainder, remaining_bytes, &invalid))
2027 valid_bytes = invalid - remainder;
2030 string = g_string_sized_new (remaining_bytes);
2032 g_string_append_len (string, remainder, valid_bytes);
2033 g_string_append_c (string, '?');
2035 remaining_bytes -= valid_bytes + 1;
2036 remainder = invalid + 1;
2040 return g_strdup (name);
2042 g_string_append (string, remainder);
2043 g_assert (g_utf8_validate (string->str, -1, NULL));
2045 return g_string_free (string, FALSE);
2049 get_uri_shortname_for_display (const gchar *uri)
2052 gboolean validated = FALSE;
2054 if (has_case_prefix (uri, "file:/"))
2058 local_file = g_filename_from_uri (uri, NULL, NULL);
2062 name = g_filename_display_basename (local_file);
2066 g_free (local_file);
2075 rest = get_method_string (uri, &method);
2076 local_file = g_filename_display_basename (rest);
2078 name = g_strconcat (method, ": ", local_file, NULL);
2080 g_free (local_file);
2084 g_assert (name != NULL);
2086 if (!validated && !g_utf8_validate (name, -1, NULL))
2090 utf8_name = make_valid_utf8 (name);
2100 * gtk_recent_info_get_short_name:
2101 * @info: an #GtkRecentInfo
2103 * Computes a valid UTF-8 string that can be used as the name of the item in a
2104 * menu or list. For example, calling this function on an item that refers to
2105 * "file:///foo/bar.txt" will yield "bar.txt".
2107 * Return value: A newly-allocated string in UTF-8 encoding; free it with
2113 gtk_recent_info_get_short_name (GtkRecentInfo *info)
2117 g_return_val_if_fail (info != NULL, NULL);
2119 if (info->uri == NULL)
2122 short_name = get_uri_shortname_for_display (info->uri);
2128 * gtk_recent_info_get_uri_display:
2129 * @info: a #GtkRecentInfo
2131 * Gets a displayable version of the resource's URI. If the resource
2132 * is local, it returns a local path; if the resource is not local,
2133 * it returns the UTF-8 encoded content of gtk_recent_info_get_uri().
2135 * Return value: a newly allocated UTF-8 string containing the
2136 * resource's URI or %NULL. Use g_free() when done using it.
2141 gtk_recent_info_get_uri_display (GtkRecentInfo *info)
2145 g_return_val_if_fail (info != NULL, NULL);
2148 if (gtk_recent_info_is_local (info))
2152 filename = g_filename_from_uri (info->uri, NULL, NULL);
2156 retval = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
2161 retval = make_valid_utf8 (info->uri);
2168 * gtk_recent_info_get_age:
2169 * @info: a #GtkRecentInfo
2171 * Gets the number of days elapsed since the last update of the resource
2174 * Return value: a positive integer containing the number of days elapsed
2175 * since the time this resource was last modified.
2180 gtk_recent_info_get_age (GtkRecentInfo *info)
2185 g_return_val_if_fail (info != NULL, -1);
2189 delta = now - info->modified;
2191 retval = (gint) (delta / (60 * 60 * 24));
2197 * gtk_recent_info_get_groups:
2198 * @info: a #GtkRecentInfo
2199 * @length: return location for the number of groups returned, or %NULL
2201 * Returns all groups registered for the recently used item @info. The
2202 * array of returned group names will be %NULL terminated, so length might
2203 * optionally be %NULL.
2205 * Return value: a newly allocated %NULL terminated array of strings. Use
2206 * g_strfreev() to free it.
2211 gtk_recent_info_get_groups (GtkRecentInfo *info,
2218 g_return_val_if_fail (info != NULL, NULL);
2228 n_groups = g_slist_length (info->groups);
2230 retval = g_new0 (gchar *, n_groups + 1);
2232 for (l = info->groups, i = 0;
2236 gchar *group_name = (gchar *) l->data;
2238 g_assert (group_name != NULL);
2240 retval[i++] = g_strdup (group_name);
2251 * gtk_recent_info_has_group:
2252 * @info: a #GtkRecentInfo
2253 * @group_name: name of a group
2255 * Checks whether @group_name appears inside the groups registered for the
2256 * recently used item @info.
2258 * Return value: %TRUE if the group was found.
2263 gtk_recent_info_has_group (GtkRecentInfo *info,
2264 const gchar *group_name)
2268 g_return_val_if_fail (info != NULL, FALSE);
2269 g_return_val_if_fail (group_name != NULL, FALSE);
2274 for (l = info->groups; l != NULL; l = l->next)
2276 gchar *g = (gchar *) l->data;
2278 if (strcmp (g, group_name) == 0)
2286 * _gtk_recent_manager_sync:
2288 * Private function for synchronising the recent manager singleton.
2291 _gtk_recent_manager_sync (void)
2293 if (recent_manager_singleton)
2295 /* force a dump of the contents of the recent manager singleton */
2296 recent_manager_singleton->priv->is_dirty = TRUE;
2297 gtk_recent_manager_real_changed (recent_manager_singleton);
2301 #define __GTK_RECENT_MANAGER_C__
2302 #include "gtkaliasdef.c"