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, see <http://www.gnu.org/licenses/>.
22 #include "gtkrecentchooser.h"
23 #include "gtkrecentchooserprivate.h"
24 #include "gtkrecentmanager.h"
25 #include "gtkrecentaction.h"
26 #include "gtkactivatable.h"
28 #include "gtktypebuiltins.h"
29 #include "gtkprivate.h"
30 #include "gtkmarshalers.h"
33 * SECTION:gtkrecentchooser
34 * @Short_description: Interface implemented by widgets displaying recently
36 * @Title: GtkRecentChooser
37 * @See_also: #GtkRecentManager, #GtkRecentChooserDialog,
38 * #GtkRecentChooserWidget, #GtkRecentChooserMenu
40 * #GtkRecentChooser is an interface that can be implemented by widgets
41 * displaying the list of recently used files. In GTK+, the main objects
42 * that implement this interface are #GtkRecentChooserWidget,
43 * #GtkRecentChooserDialog and #GtkRecentChooserMenu.
45 * Recently used files are supported since GTK+ 2.10.
57 static gboolean recent_chooser_has_show_numbers (GtkRecentChooser *chooser);
59 static GQuark quark_gtk_related_action = 0;
60 static GQuark quark_gtk_use_action_appearance = 0;
61 static const gchar gtk_related_action_key[] = "gtk-related-action";
62 static const gchar gtk_use_action_appearance_key[] = "gtk-use-action-appearance";
65 static guint chooser_signals[LAST_SIGNAL] = { 0, };
68 typedef GtkRecentChooserIface GtkRecentChooserInterface;
69 G_DEFINE_INTERFACE (GtkRecentChooser, gtk_recent_chooser, G_TYPE_OBJECT);
73 gtk_recent_chooser_default_init (GtkRecentChooserInterface *iface)
75 GType iface_type = G_TYPE_FROM_INTERFACE (iface);
77 quark_gtk_related_action = g_quark_from_static_string (gtk_related_action_key);
78 quark_gtk_use_action_appearance = g_quark_from_static_string (gtk_use_action_appearance_key);
81 * GtkRecentChooser::selection-changed:
82 * @chooser: the object which received the signal
84 * This signal is emitted when there is a change in the set of
85 * selected recently used resources. This can happen when a user
86 * modifies the selection with the mouse or the keyboard, or when
87 * explicitely calling functions to change the selection.
91 chooser_signals[SELECTION_CHANGED] =
92 g_signal_new (I_("selection-changed"),
95 G_STRUCT_OFFSET (GtkRecentChooserIface, selection_changed),
97 g_cclosure_marshal_VOID__VOID,
101 * GtkRecentChooser::item-activated:
102 * @chooser: the object which received the signal
104 * This signal is emitted when the user "activates" a recent item
105 * in the recent chooser. This can happen by double-clicking on an item
106 * in the recently used resources list, or by pressing
107 * <keycap>Enter</keycap>.
111 chooser_signals[ITEM_ACTIVATED] =
112 g_signal_new (I_("item-activated"),
115 G_STRUCT_OFFSET (GtkRecentChooserIface, item_activated),
117 g_cclosure_marshal_VOID__VOID,
121 * GtkRecentChooser:recent-manager:
123 * The #GtkRecentManager instance used by the #GtkRecentChooser to
124 * display the list of recently used resources.
128 g_object_interface_install_property (iface,
129 g_param_spec_object ("recent-manager",
130 P_("Recent Manager"),
131 P_("The RecentManager object to use"),
132 GTK_TYPE_RECENT_MANAGER,
133 GTK_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
135 * GtkRecentManager:show-private:
137 * Whether this #GtkRecentChooser should display recently used resources
138 * marked with the "private" flag. Such resources should be considered
139 * private to the applications and groups that have added them.
143 g_object_interface_install_property (iface,
144 g_param_spec_boolean ("show-private",
146 P_("Whether the private items should be displayed"),
148 GTK_PARAM_READWRITE));
150 * GtkRecentChooser:show-tips:
152 * Whether this #GtkRecentChooser should display a tooltip containing the
153 * full path of the recently used resources.
157 g_object_interface_install_property (iface,
158 g_param_spec_boolean ("show-tips",
160 P_("Whether there should be a tooltip on the item"),
162 GTK_PARAM_READWRITE));
164 * GtkRecentChooser:show-icons:
166 * Whether this #GtkRecentChooser should display an icon near the item.
170 g_object_interface_install_property (iface,
171 g_param_spec_boolean ("show-icons",
173 P_("Whether there should be an icon near the item"),
175 GTK_PARAM_READWRITE));
177 * GtkRecentChooser:show-not-found:
179 * Whether this #GtkRecentChooser should display the recently used resources
180 * even if not present anymore. Setting this to %FALSE will perform a
181 * potentially expensive check on every local resource (every remote
182 * resource will always be displayed).
186 g_object_interface_install_property (iface,
187 g_param_spec_boolean ("show-not-found",
188 P_("Show Not Found"),
189 P_("Whether the items pointing to unavailable resources should be displayed"),
191 GTK_PARAM_READWRITE));
193 * GtkRecentChooser:select-multiple:
195 * Allow the user to select multiple resources.
199 g_object_interface_install_property (iface,
200 g_param_spec_boolean ("select-multiple",
201 P_("Select Multiple"),
202 P_("Whether to allow multiple items to be selected"),
204 GTK_PARAM_READWRITE));
206 * GtkRecentChooser:local-only:
208 * Whether this #GtkRecentChooser should display only local (file:)
213 g_object_interface_install_property (iface,
214 g_param_spec_boolean ("local-only",
216 P_("Whether the selected resource(s) should be limited to local file: URIs"),
218 GTK_PARAM_READWRITE));
220 * GtkRecentChooser:limit:
222 * The maximum number of recently used resources to be displayed,
223 * or -1 to display all items. By default, the
224 * GtkSetting:gtk-recent-files-limit setting is respected: you can
225 * override that limit on a particular instance of #GtkRecentChooser
226 * by setting this property.
230 g_object_interface_install_property (iface,
231 g_param_spec_int ("limit",
233 P_("The maximum number of items to be displayed"),
237 GTK_PARAM_READWRITE));
239 * GtkRecentChooser:sort-type:
241 * Sorting order to be used when displaying the recently used resources.
245 g_object_interface_install_property (iface,
246 g_param_spec_enum ("sort-type",
248 P_("The sorting order of the items displayed"),
249 GTK_TYPE_RECENT_SORT_TYPE,
250 GTK_RECENT_SORT_NONE,
251 GTK_PARAM_READWRITE));
253 * GtkRecentChooser:filter:
255 * The #GtkRecentFilter object to be used when displaying
256 * the recently used resources.
260 g_object_interface_install_property (iface,
261 g_param_spec_object ("filter",
263 P_("The current filter for selecting which resources are displayed"),
264 GTK_TYPE_RECENT_FILTER,
265 GTK_PARAM_READWRITE));
269 gtk_recent_chooser_error_quark (void)
271 return g_quark_from_static_string ("gtk-recent-chooser-error-quark");
275 * _gtk_recent_chooser_get_recent_manager:
276 * @chooser: a #GtkRecentChooser
278 * Gets the #GtkRecentManager used by @chooser.
280 * Return value: the recent manager for @chooser.
285 _gtk_recent_chooser_get_recent_manager (GtkRecentChooser *chooser)
287 g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), NULL);
289 return GTK_RECENT_CHOOSER_GET_IFACE (chooser)->get_recent_manager (chooser);
293 * gtk_recent_chooser_set_show_private:
294 * @chooser: a #GtkRecentChooser
295 * @show_private: %TRUE to show private items, %FALSE otherwise
297 * Whether to show recently used resources marked registered as private.
302 gtk_recent_chooser_set_show_private (GtkRecentChooser *chooser,
303 gboolean show_private)
305 g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
307 g_object_set (chooser, "show-private", show_private, NULL);
311 * gtk_recent_chooser_get_show_private:
312 * @chooser: a #GtkRecentChooser
314 * Returns whether @chooser should display recently used resources
315 * registered as private.
317 * Return value: %TRUE if the recent chooser should show private items,
323 gtk_recent_chooser_get_show_private (GtkRecentChooser *chooser)
325 gboolean show_private;
327 g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), FALSE);
329 g_object_get (chooser, "show-private", &show_private, NULL);
335 * gtk_recent_chooser_set_show_not_found:
336 * @chooser: a #GtkRecentChooser
337 * @show_not_found: whether to show the local items we didn't find
339 * Sets whether @chooser should display the recently used resources that
340 * it didn't find. This only applies to local resources.
345 gtk_recent_chooser_set_show_not_found (GtkRecentChooser *chooser,
346 gboolean show_not_found)
348 g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
350 g_object_set (chooser, "show-not-found", show_not_found, NULL);
354 * gtk_recent_chooser_get_show_not_found:
355 * @chooser: a #GtkRecentChooser
357 * Retrieves whether @chooser should show the recently used resources that
360 * Return value: %TRUE if the resources not found should be displayed, and
366 gtk_recent_chooser_get_show_not_found (GtkRecentChooser *chooser)
368 gboolean show_not_found;
370 g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), FALSE);
372 g_object_get (chooser, "show-not-found", &show_not_found, NULL);
374 return show_not_found;
378 * gtk_recent_chooser_set_show_icons:
379 * @chooser: a #GtkRecentChooser
380 * @show_icons: whether to show an icon near the resource
382 * Sets whether @chooser should show an icon near the resource when
388 gtk_recent_chooser_set_show_icons (GtkRecentChooser *chooser,
391 g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
393 g_object_set (chooser, "show-icons", show_icons, NULL);
397 * gtk_recent_chooser_get_show_icons:
398 * @chooser: a #GtkRecentChooser
400 * Retrieves whether @chooser should show an icon near the resource.
402 * Return value: %TRUE if the icons should be displayed, %FALSE otherwise.
407 gtk_recent_chooser_get_show_icons (GtkRecentChooser *chooser)
411 g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), FALSE);
413 g_object_get (chooser, "show-icons", &show_icons, NULL);
419 * gtk_recent_chooser_set_select_multiple:
420 * @chooser: a #GtkRecentChooser
421 * @select_multiple: %TRUE if @chooser can select more than one item
423 * Sets whether @chooser can select multiple items.
428 gtk_recent_chooser_set_select_multiple (GtkRecentChooser *chooser,
429 gboolean select_multiple)
431 g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
433 g_object_set (chooser, "select-multiple", select_multiple, NULL);
437 * gtk_recent_chooser_get_select_multiple:
438 * @chooser: a #GtkRecentChooser
440 * Gets whether @chooser can select multiple items.
442 * Return value: %TRUE if @chooser can select more than one item.
447 gtk_recent_chooser_get_select_multiple (GtkRecentChooser *chooser)
449 gboolean select_multiple;
451 g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), FALSE);
453 g_object_get (chooser, "select-multiple", &select_multiple, NULL);
455 return select_multiple;
459 * gtk_recent_chooser_set_local_only:
460 * @chooser: a #GtkRecentChooser
461 * @local_only: %TRUE if only local files can be shown
463 * Sets whether only local resources, that is resources using the file:// URI
464 * scheme, should be shown in the recently used resources selector. If
465 * @local_only is %TRUE (the default) then the shown resources are guaranteed
466 * to be accessible through the operating system native file system.
471 gtk_recent_chooser_set_local_only (GtkRecentChooser *chooser,
474 g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
476 g_object_set (chooser, "local-only", local_only, NULL);
480 * gtk_recent_chooser_get_local_only:
481 * @chooser: a #GtkRecentChooser
483 * Gets whether only local resources should be shown in the recently used
484 * resources selector. See gtk_recent_chooser_set_local_only()
486 * Return value: %TRUE if only local resources should be shown.
491 gtk_recent_chooser_get_local_only (GtkRecentChooser *chooser)
495 g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), FALSE);
497 g_object_get (chooser, "local-only", &local_only, NULL);
503 * gtk_recent_chooser_set_limit:
504 * @chooser: a #GtkRecentChooser
505 * @limit: a positive integer, or -1 for all items
507 * Sets the number of items that should be returned by
508 * gtk_recent_chooser_get_items() and gtk_recent_chooser_get_uris().
513 gtk_recent_chooser_set_limit (GtkRecentChooser *chooser,
516 g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
518 g_object_set (chooser, "limit", limit, NULL);
522 * gtk_recent_chooser_get_limit:
523 * @chooser: a #GtkRecentChooser
525 * Gets the number of items returned by gtk_recent_chooser_get_items()
526 * and gtk_recent_chooser_get_uris().
528 * Return value: A positive integer, or -1 meaning that all items are
534 gtk_recent_chooser_get_limit (GtkRecentChooser *chooser)
538 g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), 10);
540 g_object_get (chooser, "limit", &limit, NULL);
546 * gtk_recent_chooser_set_show_tips:
547 * @chooser: a #GtkRecentChooser
548 * @show_tips: %TRUE if tooltips should be shown
550 * Sets whether to show a tooltips containing the full path of each
551 * recently used resource in a #GtkRecentChooser widget.
556 gtk_recent_chooser_set_show_tips (GtkRecentChooser *chooser,
559 g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
561 g_object_set (chooser, "show-tips", show_tips, NULL);
565 * gtk_recent_chooser_get_show_tips:
566 * @chooser: a #GtkRecentChooser
568 * Gets whether @chooser should display tooltips containing the full path
569 * of a recently user resource.
571 * Return value: %TRUE if the recent chooser should show tooltips,
577 gtk_recent_chooser_get_show_tips (GtkRecentChooser *chooser)
581 g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), FALSE);
583 g_object_get (chooser, "show-tips", &show_tips, NULL);
589 recent_chooser_has_show_numbers (GtkRecentChooser *chooser)
593 /* This is the result of a minor screw up: the "show-numbers" property
594 * was removed from the GtkRecentChooser interface, but the accessors
595 * remained in the interface API; now we need to check whether the
596 * implementation of the RecentChooser interface has a "show-numbers"
597 * boolean property installed before accessing it, and avoid an
598 * assertion failure using a more graceful warning. This should really
599 * go away as soon as we can break API and remove these accessors.
601 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (chooser),
604 return (pspec && pspec->value_type == G_TYPE_BOOLEAN);
608 * gtk_recent_chooser_set_sort_type:
609 * @chooser: a #GtkRecentChooser
610 * @sort_type: sort order that the chooser should use
612 * Changes the sorting order of the recently used resources list displayed by
618 gtk_recent_chooser_set_sort_type (GtkRecentChooser *chooser,
619 GtkRecentSortType sort_type)
621 g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
623 g_object_set (chooser, "sort-type", sort_type, NULL);
627 * gtk_recent_chooser_get_sort_type:
628 * @chooser: a #GtkRecentChooser
630 * Gets the value set by gtk_recent_chooser_set_sort_type().
632 * Return value: the sorting order of the @chooser.
637 gtk_recent_chooser_get_sort_type (GtkRecentChooser *chooser)
639 GtkRecentSortType sort_type;
641 g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), GTK_RECENT_SORT_NONE);
643 g_object_get (chooser, "sort-type", &sort_type, NULL);
649 * gtk_recent_chooser_set_sort_func:
650 * @chooser: a #GtkRecentChooser
651 * @sort_func: the comparison function
652 * @sort_data: (allow-none): user data to pass to @sort_func, or %NULL
653 * @data_destroy: (allow-none): destroy notifier for @sort_data, or %NULL
655 * Sets the comparison function used when sorting to be @sort_func. If
656 * the @chooser has the sort type set to #GTK_RECENT_SORT_CUSTOM then
657 * the chooser will sort using this function.
659 * To the comparison function will be passed two #GtkRecentInfo structs and
660 * @sort_data; @sort_func should return a positive integer if the first
661 * item comes before the second, zero if the two items are equal and
662 * a negative integer if the first item comes after the second.
667 gtk_recent_chooser_set_sort_func (GtkRecentChooser *chooser,
668 GtkRecentSortFunc sort_func,
670 GDestroyNotify data_destroy)
672 g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
674 GTK_RECENT_CHOOSER_GET_IFACE (chooser)->set_sort_func (chooser,
681 * gtk_recent_chooser_set_current_uri:
682 * @chooser: a #GtkRecentChooser
684 * @error: (allow-none): return location for a #GError, or %NULL
686 * Sets @uri as the current URI for @chooser.
688 * Return value: %TRUE if the URI was found.
693 gtk_recent_chooser_set_current_uri (GtkRecentChooser *chooser,
697 g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), FALSE);
699 return GTK_RECENT_CHOOSER_GET_IFACE (chooser)->set_current_uri (chooser, uri, error);
703 * gtk_recent_chooser_get_current_uri:
704 * @chooser: a #GtkRecentChooser
706 * Gets the URI currently selected by @chooser.
708 * Return value: a newly allocated string holding a URI.
713 gtk_recent_chooser_get_current_uri (GtkRecentChooser *chooser)
715 g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), NULL);
717 return GTK_RECENT_CHOOSER_GET_IFACE (chooser)->get_current_uri (chooser);
721 * gtk_recent_chooser_get_current_item:
722 * @chooser: a #GtkRecentChooser
724 * Gets the #GtkRecentInfo currently selected by @chooser.
726 * Return value: a #GtkRecentInfo. Use gtk_recent_info_unref() when
727 * when you have finished using it.
732 gtk_recent_chooser_get_current_item (GtkRecentChooser *chooser)
734 GtkRecentManager *manager;
735 GtkRecentInfo *retval;
738 g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), NULL);
740 uri = gtk_recent_chooser_get_current_uri (chooser);
744 manager = _gtk_recent_chooser_get_recent_manager (chooser);
745 retval = gtk_recent_manager_lookup_item (manager, uri, NULL);
752 * gtk_recent_chooser_select_uri:
753 * @chooser: a #GtkRecentChooser
755 * @error: (allow-none): return location for a #GError, or %NULL
757 * Selects @uri inside @chooser.
759 * Return value: %TRUE if @uri was found.
764 gtk_recent_chooser_select_uri (GtkRecentChooser *chooser,
768 g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), FALSE);
770 return GTK_RECENT_CHOOSER_GET_IFACE (chooser)->select_uri (chooser, uri, error);
774 * gtk_recent_chooser_unselect_uri:
775 * @chooser: a #GtkRecentChooser
778 * Unselects @uri inside @chooser.
783 gtk_recent_chooser_unselect_uri (GtkRecentChooser *chooser,
786 g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
788 GTK_RECENT_CHOOSER_GET_IFACE (chooser)->unselect_uri (chooser, uri);
792 * gtk_recent_chooser_select_all:
793 * @chooser: a #GtkRecentChooser
795 * Selects all the items inside @chooser, if the @chooser supports
796 * multiple selection.
801 gtk_recent_chooser_select_all (GtkRecentChooser *chooser)
803 g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
805 GTK_RECENT_CHOOSER_GET_IFACE (chooser)->select_all (chooser);
809 * gtk_recent_chooser_unselect_all:
810 * @chooser: a #GtkRecentChooser
812 * Unselects all the items inside @chooser.
817 gtk_recent_chooser_unselect_all (GtkRecentChooser *chooser)
819 g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
821 GTK_RECENT_CHOOSER_GET_IFACE (chooser)->unselect_all (chooser);
825 * gtk_recent_chooser_get_items:
826 * @chooser: a #GtkRecentChooser
828 * Gets the list of recently used resources in form of #GtkRecentInfo objects.
830 * The return value of this function is affected by the "sort-type" and
831 * "limit" properties of @chooser.
833 * Return value: (element-type GtkRecentInfo) (transfer full): A newly allocated
834 * list of #GtkRecentInfo objects. You should
835 * use gtk_recent_info_unref() on every item of the list, and then free
836 * the list itself using g_list_free().
841 gtk_recent_chooser_get_items (GtkRecentChooser *chooser)
843 g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), NULL);
845 return GTK_RECENT_CHOOSER_GET_IFACE (chooser)->get_items (chooser);
849 * gtk_recent_chooser_get_uris:
850 * @chooser: a #GtkRecentChooser
851 * @length: (allow-none): return location for a the length of the URI list, or %NULL
853 * Gets the URI of the recently used resources.
855 * The return value of this function is affected by the "sort-type" and "limit"
856 * properties of @chooser.
858 * Since the returned array is %NULL terminated, @length may be %NULL.
860 * Return value: (array length=length zero-terminated=1) (transfer full):
861 * A newly allocated, %NULL-terminated array of strings. Use
862 * g_strfreev() to free it.
867 gtk_recent_chooser_get_uris (GtkRecentChooser *chooser,
874 items = gtk_recent_chooser_get_items (chooser);
876 n_items = g_list_length (items);
877 retval = g_new0 (gchar *, n_items + 1);
879 for (l = items, i = 0; l != NULL; l = l->next)
881 GtkRecentInfo *info = (GtkRecentInfo *) l->data;
884 g_assert (info != NULL);
886 uri = gtk_recent_info_get_uri (info);
887 g_assert (uri != NULL);
889 retval[i++] = g_strdup (uri);
896 g_list_free_full (items, (GDestroyNotify) gtk_recent_info_unref);
902 * gtk_recent_chooser_add_filter:
903 * @chooser: a #GtkRecentChooser
904 * @filter: a #GtkRecentFilter
906 * Adds @filter to the list of #GtkRecentFilter objects held by @chooser.
908 * If no previous filter objects were defined, this function will call
909 * gtk_recent_chooser_set_filter().
914 gtk_recent_chooser_add_filter (GtkRecentChooser *chooser,
915 GtkRecentFilter *filter)
917 g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
918 g_return_if_fail (GTK_IS_RECENT_FILTER (filter));
920 GTK_RECENT_CHOOSER_GET_IFACE (chooser)->add_filter (chooser, filter);
924 * gtk_recent_chooser_remove_filter:
925 * @chooser: a #GtkRecentChooser
926 * @filter: a #GtkRecentFilter
928 * Removes @filter from the list of #GtkRecentFilter objects held by @chooser.
933 gtk_recent_chooser_remove_filter (GtkRecentChooser *chooser,
934 GtkRecentFilter *filter)
936 g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
937 g_return_if_fail (GTK_IS_RECENT_FILTER (filter));
939 GTK_RECENT_CHOOSER_GET_IFACE (chooser)->remove_filter (chooser, filter);
943 * gtk_recent_chooser_list_filters:
944 * @chooser: a #GtkRecentChooser
946 * Gets the #GtkRecentFilter objects held by @chooser.
948 * Return value: (element-type GtkRecentFilter) (transfer container): A singly linked list
949 * of #GtkRecentFilter objects. You
950 * should just free the returned list using g_slist_free().
955 gtk_recent_chooser_list_filters (GtkRecentChooser *chooser)
957 g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), NULL);
959 return GTK_RECENT_CHOOSER_GET_IFACE (chooser)->list_filters (chooser);
963 * gtk_recent_chooser_set_filter:
964 * @chooser: a #GtkRecentChooser
965 * @filter: a #GtkRecentFilter
967 * Sets @filter as the current #GtkRecentFilter object used by @chooser
968 * to affect the displayed recently used resources.
973 gtk_recent_chooser_set_filter (GtkRecentChooser *chooser,
974 GtkRecentFilter *filter)
976 g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
977 g_return_if_fail (GTK_IS_RECENT_FILTER (filter));
979 g_object_set (G_OBJECT (chooser), "filter", filter, NULL);
983 * gtk_recent_chooser_get_filter:
984 * @chooser: a #GtkRecentChooser
986 * Gets the #GtkRecentFilter object currently used by @chooser to affect
987 * the display of the recently used resources.
989 * Return value: (transfer none): a #GtkRecentFilter object.
994 gtk_recent_chooser_get_filter (GtkRecentChooser *chooser)
996 GtkRecentFilter *filter;
998 g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), NULL);
1000 g_object_get (G_OBJECT (chooser), "filter", &filter, NULL);
1002 /* we need this hack because g_object_get() increases the refcount
1003 * of the returned object; see also gtk_file_chooser_get_filter()
1004 * inside gtkfilechooser.c
1007 g_object_unref (filter);
1013 _gtk_recent_chooser_item_activated (GtkRecentChooser *chooser)
1015 g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
1017 g_signal_emit (chooser, chooser_signals[ITEM_ACTIVATED], 0);
1021 _gtk_recent_chooser_selection_changed (GtkRecentChooser *chooser)
1023 g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
1025 g_signal_emit (chooser, chooser_signals[SELECTION_CHANGED], 0);
1029 _gtk_recent_chooser_update (GtkActivatable *activatable,
1031 const gchar *property_name)
1033 GtkRecentChooser *recent_chooser = GTK_RECENT_CHOOSER (activatable);
1034 GtkRecentChooser *action_chooser = GTK_RECENT_CHOOSER (action);
1035 GtkRecentAction *recent_action = GTK_RECENT_ACTION (action);
1037 if (strcmp (property_name, "show-numbers") == 0 && recent_chooser_has_show_numbers (recent_chooser))
1038 g_object_set (recent_chooser, "show-numbers",
1039 gtk_recent_action_get_show_numbers (recent_action), NULL);
1040 else if (strcmp (property_name, "show-private") == 0)
1041 gtk_recent_chooser_set_show_private (recent_chooser, gtk_recent_chooser_get_show_private (action_chooser));
1042 else if (strcmp (property_name, "show-not-found") == 0)
1043 gtk_recent_chooser_set_show_not_found (recent_chooser, gtk_recent_chooser_get_show_not_found (action_chooser));
1044 else if (strcmp (property_name, "show-tips") == 0)
1045 gtk_recent_chooser_set_show_tips (recent_chooser, gtk_recent_chooser_get_show_tips (action_chooser));
1046 else if (strcmp (property_name, "show-icons") == 0)
1047 gtk_recent_chooser_set_show_icons (recent_chooser, gtk_recent_chooser_get_show_icons (action_chooser));
1048 else if (strcmp (property_name, "limit") == 0)
1049 gtk_recent_chooser_set_limit (recent_chooser, gtk_recent_chooser_get_limit (action_chooser));
1050 else if (strcmp (property_name, "local-only") == 0)
1051 gtk_recent_chooser_set_local_only (recent_chooser, gtk_recent_chooser_get_local_only (action_chooser));
1052 else if (strcmp (property_name, "sort-type") == 0)
1053 gtk_recent_chooser_set_sort_type (recent_chooser, gtk_recent_chooser_get_sort_type (action_chooser));
1054 else if (strcmp (property_name, "filter") == 0)
1055 gtk_recent_chooser_set_filter (recent_chooser, gtk_recent_chooser_get_filter (action_chooser));
1059 _gtk_recent_chooser_sync_action_properties (GtkActivatable *activatable,
1062 GtkRecentChooser *recent_chooser = GTK_RECENT_CHOOSER (activatable);
1063 GtkRecentChooser *action_chooser = GTK_RECENT_CHOOSER (action);
1068 if (recent_chooser_has_show_numbers (recent_chooser))
1069 g_object_set (recent_chooser, "show-numbers",
1070 gtk_recent_action_get_show_numbers (GTK_RECENT_ACTION (action)),
1072 gtk_recent_chooser_set_show_private (recent_chooser, gtk_recent_chooser_get_show_private (action_chooser));
1073 gtk_recent_chooser_set_show_not_found (recent_chooser, gtk_recent_chooser_get_show_not_found (action_chooser));
1074 gtk_recent_chooser_set_show_tips (recent_chooser, gtk_recent_chooser_get_show_tips (action_chooser));
1075 gtk_recent_chooser_set_show_icons (recent_chooser, gtk_recent_chooser_get_show_icons (action_chooser));
1076 gtk_recent_chooser_set_limit (recent_chooser, gtk_recent_chooser_get_limit (action_chooser));
1077 gtk_recent_chooser_set_local_only (recent_chooser, gtk_recent_chooser_get_local_only (action_chooser));
1078 gtk_recent_chooser_set_sort_type (recent_chooser, gtk_recent_chooser_get_sort_type (action_chooser));
1079 gtk_recent_chooser_set_filter (recent_chooser, gtk_recent_chooser_get_filter (action_chooser));
1083 _gtk_recent_chooser_set_related_action (GtkRecentChooser *recent_chooser,
1086 GtkAction *prev_action;
1088 prev_action = g_object_get_qdata (G_OBJECT (recent_chooser), quark_gtk_related_action);
1090 if (prev_action == action)
1093 gtk_activatable_do_set_related_action (GTK_ACTIVATABLE (recent_chooser), action);
1094 g_object_set_qdata (G_OBJECT (recent_chooser), quark_gtk_related_action, action);
1098 _gtk_recent_chooser_get_related_action (GtkRecentChooser *recent_chooser)
1100 return g_object_get_qdata (G_OBJECT (recent_chooser), quark_gtk_related_action);
1103 /* The default for use-action-appearance is TRUE, so we try to set the
1104 * qdata backwards for this case.
1107 _gtk_recent_chooser_set_use_action_appearance (GtkRecentChooser *recent_chooser,
1108 gboolean use_appearance)
1111 gboolean use_action_appearance;
1113 action = g_object_get_qdata (G_OBJECT (recent_chooser), quark_gtk_related_action);
1114 use_action_appearance = !GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (recent_chooser), quark_gtk_use_action_appearance));
1116 if (use_action_appearance != use_appearance)
1119 g_object_set_qdata (G_OBJECT (recent_chooser), quark_gtk_use_action_appearance, GINT_TO_POINTER (!use_appearance));
1121 gtk_activatable_sync_action_properties (GTK_ACTIVATABLE (recent_chooser), action);
1126 _gtk_recent_chooser_get_use_action_appearance (GtkRecentChooser *recent_chooser)
1128 return !GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (recent_chooser), quark_gtk_use_action_appearance));