1 /* GTK - The GIMP Toolkit
2 * gtkrecentchooser.c - Abstract interface for recent file selectors GUIs
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 Lesser 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 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
24 #include "gtkrecentchooser.h"
25 #include "gtkrecentchooserprivate.h"
26 #include "gtkrecentmanager.h"
27 #include "gtkrecentaction.h"
28 #include "gtkactivatable.h"
30 #include "gtktypebuiltins.h"
31 #include "gtkprivate.h"
32 #include "gtkmarshalers.h"
35 * SECTION:gtkrecentchooser
36 * @Short_description: Interface implemented by widgets displaying recently
38 * @Title: GtkRecentChooser
39 * @See_also: #GtkRecentManager, #GtkRecentChooserDialog,
40 * #GtkRecentChooserWidget, #GtkRecentChooserMenu
42 * #GtkRecentChooser is an interface that can be implemented by widgets
43 * displaying the list of recently used files. In GTK+, the main objects
44 * that implement this interface are #GtkRecentChooserWidget,
45 * #GtkRecentChooserDialog and #GtkRecentChooserMenu.
47 * Recently used files are supported since GTK+ 2.10.
59 static gboolean recent_chooser_has_show_numbers (GtkRecentChooser *chooser);
61 static GQuark quark_gtk_related_action = 0;
62 static GQuark quark_gtk_use_action_appearance = 0;
63 static const gchar gtk_related_action_key[] = "gtk-related-action";
64 static const gchar gtk_use_action_appearance_key[] = "gtk-use-action-appearance";
67 static guint chooser_signals[LAST_SIGNAL] = { 0, };
70 typedef GtkRecentChooserIface GtkRecentChooserInterface;
71 G_DEFINE_INTERFACE (GtkRecentChooser, gtk_recent_chooser, G_TYPE_OBJECT);
75 gtk_recent_chooser_default_init (GtkRecentChooserInterface *iface)
77 GType iface_type = G_TYPE_FROM_INTERFACE (iface);
79 quark_gtk_related_action = g_quark_from_static_string (gtk_related_action_key);
80 quark_gtk_use_action_appearance = g_quark_from_static_string (gtk_use_action_appearance_key);
83 * GtkRecentChooser::selection-changed
84 * @chooser: the object which received the signal
86 * This signal is emitted when there is a change in the set of
87 * selected recently used resources. This can happen when a user
88 * modifies the selection with the mouse or the keyboard, or when
89 * explicitely calling functions to change the selection.
93 chooser_signals[SELECTION_CHANGED] =
94 g_signal_new (I_("selection-changed"),
97 G_STRUCT_OFFSET (GtkRecentChooserIface, selection_changed),
99 g_cclosure_marshal_VOID__VOID,
103 * GtkRecentChooser::item-activated
104 * @chooser: the object which received the signal
106 * This signal is emitted when the user "activates" a recent item
107 * in the recent chooser. This can happen by double-clicking on an item
108 * in the recently used resources list, or by pressing
109 * <keycap>Enter</keycap>.
113 chooser_signals[ITEM_ACTIVATED] =
114 g_signal_new (I_("item-activated"),
117 G_STRUCT_OFFSET (GtkRecentChooserIface, item_activated),
119 g_cclosure_marshal_VOID__VOID,
123 * GtkRecentChooser:recent-manager:
125 * The #GtkRecentManager instance used by the #GtkRecentChooser to
126 * display the list of recently used resources.
130 g_object_interface_install_property (iface,
131 g_param_spec_object ("recent-manager",
132 P_("Recent Manager"),
133 P_("The RecentManager object to use"),
134 GTK_TYPE_RECENT_MANAGER,
135 GTK_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
137 * GtkRecentManager:show-private:
139 * Whether this #GtkRecentChooser should display recently used resources
140 * marked with the "private" flag. Such resources should be considered
141 * private to the applications and groups that have added them.
145 g_object_interface_install_property (iface,
146 g_param_spec_boolean ("show-private",
148 P_("Whether the private items should be displayed"),
150 GTK_PARAM_READWRITE));
152 * GtkRecentChooser:show-tips:
154 * Whether this #GtkRecentChooser should display a tooltip containing the
155 * full path of the recently used resources.
159 g_object_interface_install_property (iface,
160 g_param_spec_boolean ("show-tips",
162 P_("Whether there should be a tooltip on the item"),
164 GTK_PARAM_READWRITE));
166 * GtkRecentChooser:show-icons:
168 * Whether this #GtkRecentChooser should display an icon near the item.
172 g_object_interface_install_property (iface,
173 g_param_spec_boolean ("show-icons",
175 P_("Whether there should be an icon near the item"),
177 GTK_PARAM_READWRITE));
179 * GtkRecentChooser:show-not-found:
181 * Whether this #GtkRecentChooser should display the recently used resources
182 * even if not present anymore. Setting this to %FALSE will perform a
183 * potentially expensive check on every local resource (every remote
184 * resource will always be displayed).
188 g_object_interface_install_property (iface,
189 g_param_spec_boolean ("show-not-found",
190 P_("Show Not Found"),
191 P_("Whether the items pointing to unavailable resources should be displayed"),
193 GTK_PARAM_READWRITE));
195 * GtkRecentChooser:select-multiple:
197 * Allow the user to select multiple resources.
201 g_object_interface_install_property (iface,
202 g_param_spec_boolean ("select-multiple",
203 P_("Select Multiple"),
204 P_("Whether to allow multiple items to be selected"),
206 GTK_PARAM_READWRITE));
208 * GtkRecentChooser:local-only:
210 * Whether this #GtkRecentChooser should display only local (file:)
215 g_object_interface_install_property (iface,
216 g_param_spec_boolean ("local-only",
218 P_("Whether the selected resource(s) should be limited to local file: URIs"),
220 GTK_PARAM_READWRITE));
222 * GtkRecentChooser:limit:
224 * The maximum number of recently used resources to be displayed,
225 * or -1 to display all items. By default, the
226 * GtkSetting:gtk-recent-files-limit setting is respected: you can
227 * override that limit on a particular instance of #GtkRecentChooser
228 * by setting this property.
232 g_object_interface_install_property (iface,
233 g_param_spec_int ("limit",
235 P_("The maximum number of items to be displayed"),
239 GTK_PARAM_READWRITE));
241 * GtkRecentChooser:sort-type:
243 * Sorting order to be used when displaying the recently used resources.
247 g_object_interface_install_property (iface,
248 g_param_spec_enum ("sort-type",
250 P_("The sorting order of the items displayed"),
251 GTK_TYPE_RECENT_SORT_TYPE,
252 GTK_RECENT_SORT_NONE,
253 GTK_PARAM_READWRITE));
255 * GtkRecentChooser:filter:
257 * The #GtkRecentFilter object to be used when displaying
258 * the recently used resources.
262 g_object_interface_install_property (iface,
263 g_param_spec_object ("filter",
265 P_("The current filter for selecting which resources are displayed"),
266 GTK_TYPE_RECENT_FILTER,
267 GTK_PARAM_READWRITE));
271 gtk_recent_chooser_error_quark (void)
273 return g_quark_from_static_string ("gtk-recent-chooser-error-quark");
277 * _gtk_recent_chooser_get_recent_manager:
278 * @chooser: a #GtkRecentChooser
280 * Gets the #GtkRecentManager used by @chooser.
282 * Return value: the recent manager for @chooser.
287 _gtk_recent_chooser_get_recent_manager (GtkRecentChooser *chooser)
289 g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), NULL);
291 return GTK_RECENT_CHOOSER_GET_IFACE (chooser)->get_recent_manager (chooser);
295 * gtk_recent_chooser_set_show_private:
296 * @chooser: a #GtkRecentChooser
297 * @show_private: %TRUE to show private items, %FALSE otherwise
299 * Whether to show recently used resources marked registered as private.
304 gtk_recent_chooser_set_show_private (GtkRecentChooser *chooser,
305 gboolean show_private)
307 g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
309 g_object_set (chooser, "show-private", show_private, NULL);
313 * gtk_recent_chooser_get_show_private:
314 * @chooser: a #GtkRecentChooser
316 * Returns whether @chooser should display recently used resources
317 * registered as private.
319 * Return value: %TRUE if the recent chooser should show private items,
325 gtk_recent_chooser_get_show_private (GtkRecentChooser *chooser)
327 gboolean show_private;
329 g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), FALSE);
331 g_object_get (chooser, "show-private", &show_private, NULL);
337 * gtk_recent_chooser_set_show_not_found:
338 * @chooser: a #GtkRecentChooser
339 * @show_not_found: whether to show the local items we didn't find
341 * Sets whether @chooser should display the recently used resources that
342 * it didn't find. This only applies to local resources.
347 gtk_recent_chooser_set_show_not_found (GtkRecentChooser *chooser,
348 gboolean show_not_found)
350 g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
352 g_object_set (chooser, "show-not-found", show_not_found, NULL);
356 * gtk_recent_chooser_get_show_not_found:
357 * @chooser: a #GtkRecentChooser
359 * Retrieves whether @chooser should show the recently used resources that
362 * Return value: %TRUE if the resources not found should be displayed, and
368 gtk_recent_chooser_get_show_not_found (GtkRecentChooser *chooser)
370 gboolean show_not_found;
372 g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), FALSE);
374 g_object_get (chooser, "show-not-found", &show_not_found, NULL);
376 return show_not_found;
380 * gtk_recent_chooser_set_show_icons:
381 * @chooser: a #GtkRecentChooser
382 * @show_icons: whether to show an icon near the resource
384 * Sets whether @chooser should show an icon near the resource when
390 gtk_recent_chooser_set_show_icons (GtkRecentChooser *chooser,
393 g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
395 g_object_set (chooser, "show-icons", show_icons, NULL);
399 * gtk_recent_chooser_get_show_icons:
400 * @chooser: a #GtkRecentChooser
402 * Retrieves whether @chooser should show an icon near the resource.
404 * Return value: %TRUE if the icons should be displayed, %FALSE otherwise.
409 gtk_recent_chooser_get_show_icons (GtkRecentChooser *chooser)
413 g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), FALSE);
415 g_object_get (chooser, "show-icons", &show_icons, NULL);
421 * gtk_recent_chooser_set_select_multiple:
422 * @chooser: a #GtkRecentChooser
423 * @select_multiple: %TRUE if @chooser can select more than one item
425 * Sets whether @chooser can select multiple items.
430 gtk_recent_chooser_set_select_multiple (GtkRecentChooser *chooser,
431 gboolean select_multiple)
433 g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
435 g_object_set (chooser, "select-multiple", select_multiple, NULL);
439 * gtk_recent_chooser_get_select_multiple:
440 * @chooser: a #GtkRecentChooser
442 * Gets whether @chooser can select multiple items.
444 * Return value: %TRUE if @chooser can select more than one item.
449 gtk_recent_chooser_get_select_multiple (GtkRecentChooser *chooser)
451 gboolean select_multiple;
453 g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), FALSE);
455 g_object_get (chooser, "select-multiple", &select_multiple, NULL);
457 return select_multiple;
461 * gtk_recent_chooser_set_local_only:
462 * @chooser: a #GtkRecentChooser
463 * @local_only: %TRUE if only local files can be shown
465 * Sets whether only local resources, that is resources using the file:// URI
466 * scheme, should be shown in the recently used resources selector. If
467 * @local_only is %TRUE (the default) then the shown resources are guaranteed
468 * to be accessible through the operating system native file system.
473 gtk_recent_chooser_set_local_only (GtkRecentChooser *chooser,
476 g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
478 g_object_set (chooser, "local-only", local_only, NULL);
482 * gtk_recent_chooser_get_local_only:
483 * @chooser: a #GtkRecentChooser
485 * Gets whether only local resources should be shown in the recently used
486 * resources selector. See gtk_recent_chooser_set_local_only()
488 * Return value: %TRUE if only local resources should be shown.
493 gtk_recent_chooser_get_local_only (GtkRecentChooser *chooser)
497 g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), FALSE);
499 g_object_get (chooser, "local-only", &local_only, NULL);
505 * gtk_recent_chooser_set_limit:
506 * @chooser: a #GtkRecentChooser
507 * @limit: a positive integer, or -1 for all items
509 * Sets the number of items that should be returned by
510 * gtk_recent_chooser_get_items() and gtk_recent_chooser_get_uris().
515 gtk_recent_chooser_set_limit (GtkRecentChooser *chooser,
518 g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
520 g_object_set (chooser, "limit", limit, NULL);
524 * gtk_recent_chooser_get_limit:
525 * @chooser: a #GtkRecentChooser
527 * Gets the number of items returned by gtk_recent_chooser_get_items()
528 * and gtk_recent_chooser_get_uris().
530 * Return value: A positive integer, or -1 meaning that all items are
536 gtk_recent_chooser_get_limit (GtkRecentChooser *chooser)
540 g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), 10);
542 g_object_get (chooser, "limit", &limit, NULL);
548 * gtk_recent_chooser_set_show_tips:
549 * @chooser: a #GtkRecentChooser
550 * @show_tips: %TRUE if tooltips should be shown
552 * Sets whether to show a tooltips containing the full path of each
553 * recently used resource in a #GtkRecentChooser widget.
558 gtk_recent_chooser_set_show_tips (GtkRecentChooser *chooser,
561 g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
563 g_object_set (chooser, "show-tips", show_tips, NULL);
567 * gtk_recent_chooser_get_show_tips:
568 * @chooser: a #GtkRecentChooser
570 * Gets whether @chooser should display tooltips containing the full path
571 * of a recently user resource.
573 * Return value: %TRUE if the recent chooser should show tooltips,
579 gtk_recent_chooser_get_show_tips (GtkRecentChooser *chooser)
583 g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), FALSE);
585 g_object_get (chooser, "show-tips", &show_tips, NULL);
591 recent_chooser_has_show_numbers (GtkRecentChooser *chooser)
595 /* This is the result of a minor screw up: the "show-numbers" property
596 * was removed from the GtkRecentChooser interface, but the accessors
597 * remained in the interface API; now we need to check whether the
598 * implementation of the RecentChooser interface has a "show-numbers"
599 * boolean property installed before accessing it, and avoid an
600 * assertion failure using a more graceful warning. This should really
601 * go away as soon as we can break API and remove these accessors.
603 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (chooser),
606 return (pspec && pspec->value_type == G_TYPE_BOOLEAN);
610 * gtk_recent_chooser_set_sort_type:
611 * @chooser: a #GtkRecentChooser
612 * @sort_type: sort order that the chooser should use
614 * Changes the sorting order of the recently used resources list displayed by
620 gtk_recent_chooser_set_sort_type (GtkRecentChooser *chooser,
621 GtkRecentSortType sort_type)
623 g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
625 g_object_set (chooser, "sort-type", sort_type, NULL);
629 * gtk_recent_chooser_get_sort_type:
630 * @chooser: a #GtkRecentChooser
632 * Gets the value set by gtk_recent_chooser_set_sort_type().
634 * Return value: the sorting order of the @chooser.
639 gtk_recent_chooser_get_sort_type (GtkRecentChooser *chooser)
641 GtkRecentSortType sort_type;
643 g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), GTK_RECENT_SORT_NONE);
645 g_object_get (chooser, "sort-type", &sort_type, NULL);
651 * gtk_recent_chooser_set_sort_func:
652 * @chooser: a #GtkRecentChooser
653 * @sort_func: the comparison function
654 * @sort_data: (allow-none): user data to pass to @sort_func, or %NULL
655 * @data_destroy: (allow-none): destroy notifier for @sort_data, or %NULL
657 * Sets the comparison function used when sorting to be @sort_func. If
658 * the @chooser has the sort type set to #GTK_RECENT_SORT_CUSTOM then
659 * the chooser will sort using this function.
661 * To the comparison function will be passed two #GtkRecentInfo structs and
662 * @sort_data; @sort_func should return a positive integer if the first
663 * item comes before the second, zero if the two items are equal and
664 * a negative integer if the first item comes after the second.
669 gtk_recent_chooser_set_sort_func (GtkRecentChooser *chooser,
670 GtkRecentSortFunc sort_func,
672 GDestroyNotify data_destroy)
674 g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
676 GTK_RECENT_CHOOSER_GET_IFACE (chooser)->set_sort_func (chooser,
683 * gtk_recent_chooser_set_current_uri:
684 * @chooser: a #GtkRecentChooser
686 * @error: (allow-none): return location for a #GError, or %NULL
688 * Sets @uri as the current URI for @chooser.
690 * Return value: %TRUE if the URI was found.
695 gtk_recent_chooser_set_current_uri (GtkRecentChooser *chooser,
699 g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), FALSE);
701 return GTK_RECENT_CHOOSER_GET_IFACE (chooser)->set_current_uri (chooser, uri, error);
705 * gtk_recent_chooser_get_current_uri:
706 * @chooser: a #GtkRecentChooser
708 * Gets the URI currently selected by @chooser.
710 * Return value: a newly allocated string holding a URI.
715 gtk_recent_chooser_get_current_uri (GtkRecentChooser *chooser)
717 g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), NULL);
719 return GTK_RECENT_CHOOSER_GET_IFACE (chooser)->get_current_uri (chooser);
723 * gtk_recent_chooser_get_current_item:
724 * @chooser: a #GtkRecentChooser
726 * Gets the #GtkRecentInfo currently selected by @chooser.
728 * Return value: a #GtkRecentInfo. Use gtk_recent_info_unref() when
729 * when you have finished using it.
734 gtk_recent_chooser_get_current_item (GtkRecentChooser *chooser)
736 GtkRecentManager *manager;
737 GtkRecentInfo *retval;
740 g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), NULL);
742 uri = gtk_recent_chooser_get_current_uri (chooser);
746 manager = _gtk_recent_chooser_get_recent_manager (chooser);
747 retval = gtk_recent_manager_lookup_item (manager, uri, NULL);
754 * gtk_recent_chooser_select_uri:
755 * @chooser: a #GtkRecentChooser
757 * @error: (allow-none): return location for a #GError, or %NULL
759 * Selects @uri inside @chooser.
761 * Return value: %TRUE if @uri was found.
766 gtk_recent_chooser_select_uri (GtkRecentChooser *chooser,
770 g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), FALSE);
772 return GTK_RECENT_CHOOSER_GET_IFACE (chooser)->select_uri (chooser, uri, error);
776 * gtk_recent_chooser_unselect_uri:
777 * @chooser: a #GtkRecentChooser
780 * Unselects @uri inside @chooser.
785 gtk_recent_chooser_unselect_uri (GtkRecentChooser *chooser,
788 g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
790 GTK_RECENT_CHOOSER_GET_IFACE (chooser)->unselect_uri (chooser, uri);
794 * gtk_recent_chooser_select_all:
795 * @chooser: a #GtkRecentChooser
797 * Selects all the items inside @chooser, if the @chooser supports
798 * multiple selection.
803 gtk_recent_chooser_select_all (GtkRecentChooser *chooser)
805 g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
807 GTK_RECENT_CHOOSER_GET_IFACE (chooser)->select_all (chooser);
811 * gtk_recent_chooser_unselect_all:
812 * @chooser: a #GtkRecentChooser
814 * Unselects all the items inside @chooser.
819 gtk_recent_chooser_unselect_all (GtkRecentChooser *chooser)
821 g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
823 GTK_RECENT_CHOOSER_GET_IFACE (chooser)->unselect_all (chooser);
827 * gtk_recent_chooser_get_items:
828 * @chooser: a #GtkRecentChooser
830 * Gets the list of recently used resources in form of #GtkRecentInfo objects.
832 * The return value of this function is affected by the "sort-type" and
833 * "limit" properties of @chooser.
835 * Return value: (element-type GtkRecentInfo) (transfer full): A newly allocated
836 * list of #GtkRecentInfo objects. You should
837 * use gtk_recent_info_unref() on every item of the list, and then free
838 * the list itself using g_list_free().
843 gtk_recent_chooser_get_items (GtkRecentChooser *chooser)
845 g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), NULL);
847 return GTK_RECENT_CHOOSER_GET_IFACE (chooser)->get_items (chooser);
851 * gtk_recent_chooser_get_uris:
852 * @chooser: a #GtkRecentChooser
853 * @length: (allow-none): return location for a the length of the URI list, or %NULL
855 * Gets the URI of the recently used resources.
857 * The return value of this function is affected by the "sort-type" and "limit"
858 * properties of @chooser.
860 * Since the returned array is %NULL terminated, @length may be %NULL.
862 * Return value: A newly allocated, %NULL terminated array of strings. Use
863 * g_strfreev() to free it.
868 gtk_recent_chooser_get_uris (GtkRecentChooser *chooser,
875 items = gtk_recent_chooser_get_items (chooser);
877 n_items = g_list_length (items);
878 retval = g_new0 (gchar *, n_items + 1);
880 for (l = items, i = 0; l != NULL; l = l->next)
882 GtkRecentInfo *info = (GtkRecentInfo *) l->data;
885 g_assert (info != NULL);
887 uri = gtk_recent_info_get_uri (info);
888 g_assert (uri != NULL);
890 retval[i++] = g_strdup (uri);
897 g_list_foreach (items,
898 (GFunc) gtk_recent_info_unref,
906 * gtk_recent_chooser_add_filter:
907 * @chooser: a #GtkRecentChooser
908 * @filter: a #GtkRecentFilter
910 * Adds @filter to the list of #GtkRecentFilter objects held by @chooser.
912 * If no previous filter objects were defined, this function will call
913 * gtk_recent_chooser_set_filter().
918 gtk_recent_chooser_add_filter (GtkRecentChooser *chooser,
919 GtkRecentFilter *filter)
921 g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
922 g_return_if_fail (GTK_IS_RECENT_FILTER (filter));
924 GTK_RECENT_CHOOSER_GET_IFACE (chooser)->add_filter (chooser, filter);
928 * gtk_recent_chooser_remove_filter:
929 * @chooser: a #GtkRecentChooser
930 * @filter: a #GtkRecentFilter
932 * Removes @filter from the list of #GtkRecentFilter objects held by @chooser.
937 gtk_recent_chooser_remove_filter (GtkRecentChooser *chooser,
938 GtkRecentFilter *filter)
940 g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
941 g_return_if_fail (GTK_IS_RECENT_FILTER (filter));
943 GTK_RECENT_CHOOSER_GET_IFACE (chooser)->remove_filter (chooser, filter);
947 * gtk_recent_chooser_list_filters:
948 * @chooser: a #GtkRecentChooser
950 * Gets the #GtkRecentFilter objects held by @chooser.
952 * Return value: (element-type GtkRecentFilter) (transfer container): A singly linked list
953 * of #GtkRecentFilter objects. You
954 * should just free the returned list using g_slist_free().
959 gtk_recent_chooser_list_filters (GtkRecentChooser *chooser)
961 g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), NULL);
963 return GTK_RECENT_CHOOSER_GET_IFACE (chooser)->list_filters (chooser);
967 * gtk_recent_chooser_set_filter:
968 * @chooser: a #GtkRecentChooser
969 * @filter: a #GtkRecentFilter
971 * Sets @filter as the current #GtkRecentFilter object used by @chooser
972 * to affect the displayed recently used resources.
977 gtk_recent_chooser_set_filter (GtkRecentChooser *chooser,
978 GtkRecentFilter *filter)
980 g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
981 g_return_if_fail (GTK_IS_RECENT_FILTER (filter));
983 g_object_set (G_OBJECT (chooser), "filter", filter, NULL);
987 * gtk_recent_chooser_get_filter:
988 * @chooser: a #GtkRecentChooser
990 * Gets the #GtkRecentFilter object currently used by @chooser to affect
991 * the display of the recently used resources.
993 * Return value: a #GtkRecentFilter object.
998 gtk_recent_chooser_get_filter (GtkRecentChooser *chooser)
1000 GtkRecentFilter *filter;
1002 g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), NULL);
1004 g_object_get (G_OBJECT (chooser), "filter", &filter, NULL);
1006 /* we need this hack because g_object_get() increases the refcount
1007 * of the returned object; see also gtk_file_chooser_get_filter()
1008 * inside gtkfilechooser.c
1011 g_object_unref (filter);
1017 _gtk_recent_chooser_item_activated (GtkRecentChooser *chooser)
1019 g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
1021 g_signal_emit (chooser, chooser_signals[ITEM_ACTIVATED], 0);
1025 _gtk_recent_chooser_selection_changed (GtkRecentChooser *chooser)
1027 g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
1029 g_signal_emit (chooser, chooser_signals[SELECTION_CHANGED], 0);
1033 _gtk_recent_chooser_update (GtkActivatable *activatable,
1035 const gchar *property_name)
1037 GtkRecentChooser *recent_chooser = GTK_RECENT_CHOOSER (activatable);
1038 GtkRecentChooser *action_chooser = GTK_RECENT_CHOOSER (action);
1039 GtkRecentAction *recent_action = GTK_RECENT_ACTION (action);
1041 if (strcmp (property_name, "show-numbers") == 0 && recent_chooser_has_show_numbers (recent_chooser))
1042 g_object_set (recent_chooser, "show-numbers",
1043 gtk_recent_action_get_show_numbers (recent_action), NULL);
1044 else if (strcmp (property_name, "show-private") == 0)
1045 gtk_recent_chooser_set_show_private (recent_chooser, gtk_recent_chooser_get_show_private (action_chooser));
1046 else if (strcmp (property_name, "show-not-found") == 0)
1047 gtk_recent_chooser_set_show_not_found (recent_chooser, gtk_recent_chooser_get_show_not_found (action_chooser));
1048 else if (strcmp (property_name, "show-tips") == 0)
1049 gtk_recent_chooser_set_show_tips (recent_chooser, gtk_recent_chooser_get_show_tips (action_chooser));
1050 else if (strcmp (property_name, "show-icons") == 0)
1051 gtk_recent_chooser_set_show_icons (recent_chooser, gtk_recent_chooser_get_show_icons (action_chooser));
1052 else if (strcmp (property_name, "limit") == 0)
1053 gtk_recent_chooser_set_limit (recent_chooser, gtk_recent_chooser_get_limit (action_chooser));
1054 else if (strcmp (property_name, "local-only") == 0)
1055 gtk_recent_chooser_set_local_only (recent_chooser, gtk_recent_chooser_get_local_only (action_chooser));
1056 else if (strcmp (property_name, "sort-type") == 0)
1057 gtk_recent_chooser_set_sort_type (recent_chooser, gtk_recent_chooser_get_sort_type (action_chooser));
1058 else if (strcmp (property_name, "filter") == 0)
1059 gtk_recent_chooser_set_filter (recent_chooser, gtk_recent_chooser_get_filter (action_chooser));
1063 _gtk_recent_chooser_sync_action_properties (GtkActivatable *activatable,
1066 GtkRecentChooser *recent_chooser = GTK_RECENT_CHOOSER (activatable);
1067 GtkRecentChooser *action_chooser = GTK_RECENT_CHOOSER (action);
1072 if (recent_chooser_has_show_numbers (recent_chooser))
1073 g_object_set (recent_chooser, "show-numbers",
1074 gtk_recent_action_get_show_numbers (GTK_RECENT_ACTION (action)),
1076 gtk_recent_chooser_set_show_private (recent_chooser, gtk_recent_chooser_get_show_private (action_chooser));
1077 gtk_recent_chooser_set_show_not_found (recent_chooser, gtk_recent_chooser_get_show_not_found (action_chooser));
1078 gtk_recent_chooser_set_show_tips (recent_chooser, gtk_recent_chooser_get_show_tips (action_chooser));
1079 gtk_recent_chooser_set_show_icons (recent_chooser, gtk_recent_chooser_get_show_icons (action_chooser));
1080 gtk_recent_chooser_set_limit (recent_chooser, gtk_recent_chooser_get_limit (action_chooser));
1081 gtk_recent_chooser_set_local_only (recent_chooser, gtk_recent_chooser_get_local_only (action_chooser));
1082 gtk_recent_chooser_set_sort_type (recent_chooser, gtk_recent_chooser_get_sort_type (action_chooser));
1083 gtk_recent_chooser_set_filter (recent_chooser, gtk_recent_chooser_get_filter (action_chooser));
1087 _gtk_recent_chooser_set_related_action (GtkRecentChooser *recent_chooser,
1090 GtkAction *prev_action;
1092 prev_action = g_object_get_qdata (G_OBJECT (recent_chooser), quark_gtk_related_action);
1094 if (prev_action == action)
1097 gtk_activatable_do_set_related_action (GTK_ACTIVATABLE (recent_chooser), action);
1098 g_object_set_qdata (G_OBJECT (recent_chooser), quark_gtk_related_action, action);
1102 _gtk_recent_chooser_get_related_action (GtkRecentChooser *recent_chooser)
1104 return g_object_get_qdata (G_OBJECT (recent_chooser), quark_gtk_related_action);
1107 /* The default for use-action-appearance is TRUE, so we try to set the
1108 * qdata backwards for this case.
1111 _gtk_recent_chooser_set_use_action_appearance (GtkRecentChooser *recent_chooser,
1112 gboolean use_appearance)
1115 gboolean use_action_appearance;
1117 action = g_object_get_qdata (G_OBJECT (recent_chooser), quark_gtk_related_action);
1118 use_action_appearance = !GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (recent_chooser), quark_gtk_use_action_appearance));
1120 if (use_action_appearance != use_appearance)
1123 g_object_set_qdata (G_OBJECT (recent_chooser), quark_gtk_use_action_appearance, GINT_TO_POINTER (!use_appearance));
1125 gtk_activatable_sync_action_properties (GTK_ACTIVATABLE (recent_chooser), action);
1130 _gtk_recent_chooser_get_use_action_appearance (GtkRecentChooser *recent_chooser)
1132 return !GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (recent_chooser), quark_gtk_use_action_appearance));