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"
28 #include "gtktypebuiltins.h"
29 #include "gtkprivate.h"
30 #include "gtkmarshalers.h"
42 static void gtk_recent_chooser_class_init (gpointer g_iface);
44 static guint chooser_signals[LAST_SIGNAL] = { 0, };
47 gtk_recent_chooser_get_type (void)
49 static GType chooser_type = 0;
53 chooser_type = g_type_register_static_simple (G_TYPE_INTERFACE,
54 I_("GtkRecentChooser"),
55 sizeof (GtkRecentChooserIface),
56 (GClassInitFunc) gtk_recent_chooser_class_init,
59 g_type_interface_add_prerequisite (chooser_type, GTK_TYPE_OBJECT);
66 gtk_recent_chooser_class_init (gpointer g_iface)
68 GType iface_type = G_TYPE_FROM_INTERFACE (g_iface);
71 * GtkRecentChooser::selection-changed
72 * @chooser: the object which received the signal
74 * This signal is emitted when there is a change in the set of
75 * selected recently used resources. This can happen when a user
76 * modifies the selection with the mouse or the keyboard, or when
77 * explicitely calling functions to change the selection.
81 chooser_signals[SELECTION_CHANGED] =
82 g_signal_new (I_("selection-changed"),
85 G_STRUCT_OFFSET (GtkRecentChooserIface, selection_changed),
87 g_cclosure_marshal_VOID__VOID,
91 * GtkRecentChooser::item-activated
92 * @chooser: the object which received the signal
94 * This signal is emitted when the user "activates" a recent item
95 * in the recent chooser. This can happen by double-clicking on an item
96 * in the recently used resources list, or by pressing
97 * <keycap>Enter</keycap>.
101 chooser_signals[ITEM_ACTIVATED] =
102 g_signal_new (I_("item-activated"),
105 G_STRUCT_OFFSET (GtkRecentChooserIface, item_activated),
107 g_cclosure_marshal_VOID__VOID,
110 g_object_interface_install_property (g_iface,
111 g_param_spec_object ("recent-manager",
112 P_("Recent Manager"),
113 P_("The RecentManager object to use"),
114 GTK_TYPE_RECENT_MANAGER,
115 G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
116 g_object_interface_install_property (g_iface,
117 g_param_spec_boolean ("show-private",
119 P_("Whether the private items should be displayed"),
122 g_object_interface_install_property (g_iface,
123 g_param_spec_boolean ("show-tips",
125 P_("Whether there should be a tooltip on the item"),
128 g_object_interface_install_property (g_iface,
129 g_param_spec_boolean ("show-icons",
131 P_("Whether there should be an icon near the item"),
134 g_object_interface_install_property (g_iface,
135 g_param_spec_boolean ("show-not-found",
136 P_("Show Not Found"),
137 P_("Whether the items pointing to unavailable resources should be displayed"),
140 g_object_interface_install_property (g_iface,
141 g_param_spec_boolean ("select-multiple",
142 P_("Select Multiple"),
143 P_("Whether to allow multiple items to be selected"),
146 g_object_interface_install_property (g_iface,
147 g_param_spec_boolean ("local-only",
149 P_("Whether the selected resource(s) should be limited to local file: URIs"),
152 g_object_interface_install_property (g_iface,
153 g_param_spec_int ("limit",
155 P_("The maximum number of items to be displayed"),
160 g_object_interface_install_property (g_iface,
161 g_param_spec_enum ("sort-type",
163 P_("The sorting order of the items displayed"),
164 GTK_TYPE_RECENT_SORT_TYPE,
165 GTK_RECENT_SORT_NONE,
167 g_object_interface_install_property (g_iface,
168 g_param_spec_object ("filter",
170 P_("The current filter for selecting which resources are displayed"),
171 GTK_TYPE_RECENT_FILTER,
176 gtk_recent_chooser_error_quark (void)
178 return g_quark_from_static_string ("gtk-recent-chooser-error-quark");
182 * _gtk_recent_chooser_get_recent_manager:
183 * @chooser: a #GtkRecentChooser
185 * Gets the #GtkRecentManager used by @chooser.
187 * Return value: the recent manager for @chooser.
192 _gtk_recent_chooser_get_recent_manager (GtkRecentChooser *chooser)
194 g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), NULL);
196 return GTK_RECENT_CHOOSER_GET_IFACE (chooser)->get_recent_manager (chooser);
200 * gtk_recent_chooser_set_show_private:
201 * @chooser: a #GtkRecentChooser
202 * @show_private: %TRUE to show private items, %FALSE otherwise
204 * Whether to show recently used resources marked registered as private.
209 gtk_recent_chooser_set_show_private (GtkRecentChooser *chooser,
210 gboolean show_private)
212 g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
214 g_object_set (chooser, "show-private", show_private, NULL);
218 * gtk_recent_chooser_get_show_private:
219 * @chooser: a #GtkRecentChooser
221 * Returns whether @chooser should display recently used resources
222 * registered as private.
224 * Return value: %TRUE if the recent chooser should show private items,
230 gtk_recent_chooser_get_show_private (GtkRecentChooser *chooser)
232 gboolean show_private;
234 g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), FALSE);
236 g_object_get (chooser, "show-private", &show_private, NULL);
242 * gtk_recent_chooser_set_show_not_found:
243 * @chooser: a #GtkRecentChooser
244 * @show_not_found: whether to show the local items we didn't find
246 * Sets whether @chooser should display the recently used resources that
247 * it didn't find. This only applies to local resources.
252 gtk_recent_chooser_set_show_not_found (GtkRecentChooser *chooser,
253 gboolean show_not_found)
255 g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
257 g_object_set (chooser, "show-not-found", show_not_found, NULL);
261 * gtk_recent_chooser_get_show_not_found:
262 * @chooser: a #GtkRecentChooser
264 * Retrieves whether @chooser should show the recently used resources that
267 * Return value: %TRUE if the resources not found should be displayed, and
273 gtk_recent_chooser_get_show_not_found (GtkRecentChooser *chooser)
275 gboolean show_not_found;
277 g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), FALSE);
279 g_object_get (chooser, "show-not-found", &show_not_found, NULL);
281 return show_not_found;
285 * gtk_recent_chooser_set_show_icons:
286 * @chooser: a #GtkRecentChooser
287 * @show_icons: whether to show an icon near the resource
289 * Sets whether @chooser should show an icon near the resource when
295 gtk_recent_chooser_set_show_icons (GtkRecentChooser *chooser,
298 g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
300 g_object_set (chooser, "show-icons", show_icons, NULL);
304 * gtk_recent_chooser_get_show_icons:
305 * @chooser: a #GtkRecentChooser
307 * Retrieves whether @chooser should show an icon near the resource.
309 * Return value: %TRUE if the icons should be displayed, %FALSE otherwise.
314 gtk_recent_chooser_get_show_icons (GtkRecentChooser *chooser)
318 g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), FALSE);
320 g_object_get (chooser, "show-icons", &show_icons, NULL);
326 * gtk_recent_chooser_set_select_multiple:
327 * @chooser: a #GtkRecentChooser
328 * @select_multiple: %TRUE if @chooser can select more than one item
330 * Sets whether @chooser can select multiple items.
335 gtk_recent_chooser_set_select_multiple (GtkRecentChooser *chooser,
336 gboolean select_multiple)
338 g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
340 g_object_set (chooser, "select-multiple", select_multiple, NULL);
344 * gtk_recent_chooser_get_select_multiple:
345 * @chooser: a #GtkRecentChooser
347 * Gets whether @chooser can select multiple items.
349 * Return value: %TRUE if @chooser can select more than one item.
354 gtk_recent_chooser_get_select_multiple (GtkRecentChooser *chooser)
356 gboolean select_multiple;
358 g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), FALSE);
360 g_object_get (chooser, "select-multiple", &select_multiple, NULL);
362 return select_multiple;
366 * gtk_recent_chooser_set_local_only:
367 * @chooser: a #GtkRecentChooser
368 * @local_only: %TRUE if only local files can be shown
370 * Sets whether only local resources, that is resources using the file:// URI
371 * scheme, should be shown in the recently used resources selector. If
372 * @local_only is %TRUE (the default) then the shown resources are guaranteed
373 * to be accessible through the operating system native file system.
378 gtk_recent_chooser_set_local_only (GtkRecentChooser *chooser,
381 g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
383 g_object_set (chooser, "local-only", local_only, NULL);
387 * gtk_recent_chooser_get_local_only:
388 * @chooser: a #GtkRecentChooser
390 * Gets whether only local resources should be shown in the recently used
391 * resources selector. See gtk_recent_chooser_set_local_only()
393 * Return value: %TRUE if only local resources should be shown.
398 gtk_recent_chooser_get_local_only (GtkRecentChooser *chooser)
402 g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), FALSE);
404 g_object_get (chooser, "local-only", &local_only, NULL);
410 * gtk_recent_chooser_set_limit:
411 * @chooser: a #GtkRecentChooser
412 * @limit: a positive integer, or -1 for all items
414 * Sets the number of items that should be returned by
415 * gtk_recent_chooser_get_items() and gtk_recent_chooser_get_uris().
420 gtk_recent_chooser_set_limit (GtkRecentChooser *chooser,
423 g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
425 g_object_set (chooser, "limit", limit, NULL);
429 * gtk_recent_chooser_get_limit:
430 * @chooser: a #GtkRecentChooser
432 * Gets the number of items returned by gtk_recent_chooser_get_items()
433 * and gtk_recent_chooser_get_uris().
435 * Return value: A positive integer, or -1 meaning that all items are
441 gtk_recent_chooser_get_limit (GtkRecentChooser *chooser)
445 g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), 10);
447 g_object_get (chooser, "limit", &limit, NULL);
453 * gtk_recent_chooser_set_show_tips:
454 * @chooser: a #GtkRecentChooser
455 * @show_tips: %TRUE if tooltips should be shown
457 * Sets whether to show a tooltips on the widget.
462 gtk_recent_chooser_set_show_tips (GtkRecentChooser *chooser,
465 g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
467 g_object_set (chooser, "show-tips", show_tips, NULL);
471 * gtk_recent_chooser_get_show_tips:
472 * @chooser: a #GtkRecentChooser
474 * Gets whether @chooser should display tooltips.
476 * Return value: %TRUE if the recent chooser should show tooltips,
482 gtk_recent_chooser_get_show_tips (GtkRecentChooser *chooser)
486 g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), FALSE);
488 g_object_get (chooser, "show-tips", &show_tips, NULL);
494 * gtk_recent_chooser_set_show_numbers:
495 * @chooser: a #GtkRecentChooser
496 * @show_numbers: %TRUE to show numbers, %FALSE otherwise
498 * Whether to show recently used resources prepended by a unique number.
503 gtk_recent_chooser_set_show_numbers (GtkRecentChooser *chooser,
504 gboolean show_numbers)
506 g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
508 g_object_set (chooser, "show-numbers", show_numbers, NULL);
512 * gtk_recent_chooser_get_show_numbers:
513 * @chooser: a #GtkRecentChooser
515 * Returns whether @chooser should display recently used resources
516 * prepended by a unique number.
518 * Return value: %TRUE if the recent chooser should show display numbers,
524 gtk_recent_chooser_get_show_numbers (GtkRecentChooser *chooser)
526 gboolean show_numbers;
528 g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), FALSE);
530 g_object_get (chooser, "show-numbers", &show_numbers, NULL);
537 * gtk_recent_chooser_set_sort_type:
538 * @chooser: a #GtkRecentChooser
539 * @sort_type: sort order that the chooser should use
541 * Changes the sorting order of the recently used resources list displayed by
547 gtk_recent_chooser_set_sort_type (GtkRecentChooser *chooser,
548 GtkRecentSortType sort_type)
550 g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
552 g_object_set (chooser, "sort-type", sort_type, NULL);
556 * gtk_recent_chooser_get_sort_type:
557 * @chooser: a #GtkRecentChooser
559 * Gets the value set by gtk_recent_chooser_set_sort_type().
561 * Return value: the sorting order of the @chooser.
566 gtk_recent_chooser_get_sort_type (GtkRecentChooser *chooser)
568 GtkRecentSortType sort_type;
570 g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), GTK_RECENT_SORT_NONE);
572 g_object_get (chooser, "sort-type", &sort_type, NULL);
578 * gtk_recent_chooser_set_sort_func:
579 * @chooser: a #GtkRecentChooser
580 * @sort_func: the comparison function
581 * @sort_data: user data to pass to @sort_func, or %NULL
582 * @data_destroy: destroy notifier for @sort_data, or %NULL
584 * Sets the comparison function used when sorting to be @sort_func. If
585 * the @chooser has the sort type set to #GTK_RECENT_SORT_CUSTOM then
586 * the chooser will sort using this function.
588 * To the comparison function will be passed two #GtkRecentInfo structs and
589 * @sort_data; @sort_func should return a positive integer if the first
590 * item comes before the second, zero if the two items are equal and
591 * a negative integer if the first item comes after the second.
596 gtk_recent_chooser_set_sort_func (GtkRecentChooser *chooser,
597 GtkRecentSortFunc sort_func,
599 GDestroyNotify data_destroy)
601 g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
603 GTK_RECENT_CHOOSER_GET_IFACE (chooser)->set_sort_func (chooser,
610 * gtk_recent_chooser_set_current_uri:
611 * @chooser: a #GtkRecentChooser
613 * @error: return location for a #GError, or %NULL
615 * Sets @uri as the current URI for @chooser.
617 * Return value: %TRUE if the URI was found.
622 gtk_recent_chooser_set_current_uri (GtkRecentChooser *chooser,
626 g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), FALSE);
628 return GTK_RECENT_CHOOSER_GET_IFACE (chooser)->set_current_uri (chooser, uri, error);
632 * gtk_recent_chooser_get_current_uri:
633 * @chooser: a #GtkRecentChooser
635 * Gets the URI currently selected by @chooser.
637 * Return value: a newly allocated string holding a URI.
642 gtk_recent_chooser_get_current_uri (GtkRecentChooser *chooser)
644 g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), NULL);
646 return GTK_RECENT_CHOOSER_GET_IFACE (chooser)->get_current_uri (chooser);
650 * gtk_recent_chooser_get_current_item:
651 * @chooser: a #GtkRecentChooser
653 * Gets the #GtkRecentInfo currently selected by @chooser.
655 * Return value: a #GtkRecentInfo. Use gtk_recent_info_unref() when
656 * when you have finished using it.
661 gtk_recent_chooser_get_current_item (GtkRecentChooser *chooser)
663 GtkRecentManager *manager;
664 GtkRecentInfo *retval;
667 g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), NULL);
669 uri = gtk_recent_chooser_get_current_uri (chooser);
673 manager = _gtk_recent_chooser_get_recent_manager (chooser);
674 retval = gtk_recent_manager_lookup_item (manager, uri, NULL);
681 * gtk_recent_chooser_select_uri:
682 * @chooser: a #GtkRecentChooser
684 * @error: return location for a #GError, or %NULL
686 * Selects @uri inside @chooser.
688 * Return value: %TRUE if @uri was found.
693 gtk_recent_chooser_select_uri (GtkRecentChooser *chooser,
697 g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), FALSE);
699 return GTK_RECENT_CHOOSER_GET_IFACE (chooser)->select_uri (chooser, uri, error);
703 * gtk_recent_chooser_unselect_uri:
704 * @chooser: a #GtkRecentChooser
707 * Unselects @uri inside @chooser.
712 gtk_recent_chooser_unselect_uri (GtkRecentChooser *chooser,
715 g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
717 GTK_RECENT_CHOOSER_GET_IFACE (chooser)->unselect_uri (chooser, uri);
721 * gtk_recent_chooser_select_all:
722 * @chooser: a #GtkRecentChooser
724 * Selects all the items inside @chooser, if the @chooser supports
725 * multiple selection.
730 gtk_recent_chooser_select_all (GtkRecentChooser *chooser)
732 g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
734 GTK_RECENT_CHOOSER_GET_IFACE (chooser)->select_all (chooser);
738 * gtk_recent_chooser_unselect_all:
739 * @chooser: a #GtkRecentChooser
741 * Unselects all the items inside @chooser.
746 gtk_recent_chooser_unselect_all (GtkRecentChooser *chooser)
748 g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
750 GTK_RECENT_CHOOSER_GET_IFACE (chooser)->unselect_all (chooser);
754 * gtk_recent_chooser_get_items:
755 * @chooser: a #GtkRecentChooser
757 * Gets the list of recently used resources in form of #GtkRecentInfo objects.
759 * The return value of this function is affected by the "sort-type" and
760 * "limit" properties of @chooser.
762 * Return value: A newly allocated list of #GtkRecentInfo objects. You should
763 * use gtk_recent_info_unref() on every item of the list, and then free
764 * the list itself using g_list_free().
769 gtk_recent_chooser_get_items (GtkRecentChooser *chooser)
771 g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), NULL);
773 return GTK_RECENT_CHOOSER_GET_IFACE (chooser)->get_items (chooser);
777 * gtk_recent_chooser_get_uris:
778 * @chooser: a #GtkRecentChooser
779 * @length: return location for a the length of the URI list, or %NULL
781 * Gets the URI of the recently used resources.
783 * The return value of this function is affected by the "sort-type" and "limit"
784 * properties of @chooser.
786 * Since the returned array is %NULL terminated, @length may be %NULL.
788 * Return value: A newly allocated, %NULL terminated array of strings. Use
789 * g_strfreev() to free it.
794 gtk_recent_chooser_get_uris (GtkRecentChooser *chooser,
801 items = gtk_recent_chooser_get_items (chooser);
805 n_items = g_list_length (items);
806 retval = g_new0 (gchar *, n_items + 1);
808 for (l = items, i = 0; l != NULL; l = l->next)
810 GtkRecentInfo *info = (GtkRecentInfo *) l->data;
813 g_assert (info != NULL);
815 uri = gtk_recent_info_get_uri (info);
816 g_assert (uri != NULL);
818 retval[i++] = g_strdup (uri);
825 g_list_foreach (items,
826 (GFunc) gtk_recent_info_unref,
834 * gtk_recent_chooser_add_filter:
835 * @chooser: a #GtkRecentChooser
836 * @filter: a #GtkRecentFilter
838 * Adds @filter to the list of #GtkRecentFilter objects held by @chooser.
840 * If no previous filter objects were defined, this function will call
841 * gtk_recent_chooser_set_filter().
846 gtk_recent_chooser_add_filter (GtkRecentChooser *chooser,
847 GtkRecentFilter *filter)
849 g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
851 GTK_RECENT_CHOOSER_GET_IFACE (chooser)->add_filter (chooser, filter);
855 * gtk_recent_chooser_remove_filter:
856 * @chooser: a #GtkRecentChooser
857 * @filter: a #GtkRecentFilter
859 * Removes @filter from the list of #GtkRecentFilter objects held by @chooser.
864 gtk_recent_chooser_remove_filter (GtkRecentChooser *chooser,
865 GtkRecentFilter *filter)
867 g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
869 GTK_RECENT_CHOOSER_GET_IFACE (chooser)->remove_filter (chooser, filter);
873 * gtk_recent_chooser_list_filters:
874 * @chooser: a #GtkRecentChooser
876 * Gets the #GtkRecentFilter objects held by @chooser.
878 * Return value: A singly linked list of #GtkRecentFilter objects. You
879 * should just free the returned list using g_slist_free().
884 gtk_recent_chooser_list_filters (GtkRecentChooser *chooser)
886 g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), NULL);
888 return GTK_RECENT_CHOOSER_GET_IFACE (chooser)->list_filters (chooser);
892 * gtk_recent_chooser_set_filter:
893 * @chooser: a #GtkRecentChooser
894 * @filter: a #GtkRecentFilter
896 * Sets @filter as the current #GtkRecentFilter object used by @chooser
897 * to affect the displayed recently used resources.
902 gtk_recent_chooser_set_filter (GtkRecentChooser *chooser,
903 GtkRecentFilter *filter)
905 g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
907 g_object_set (G_OBJECT (chooser), "filter", filter, NULL);
911 * gtk_recent_chooser_get_filter:
912 * @chooser: a #GtkRecentChooser
914 * Gets the #GtkRecentFilter object currently used by @chooser to affect
915 * the display of the recently used resources.
917 * Return value: a #GtkRecentFilter object.
922 gtk_recent_chooser_get_filter (GtkRecentChooser *chooser)
924 GtkRecentFilter *filter;
926 g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), NULL);
928 g_object_get (G_OBJECT (chooser), "filter", &filter, NULL);
930 /* we need this hack because g_object_get() increases the refcount
931 * of the returned object; see also gtk_file_chooser_get_filter()
932 * inside gtkfilechooser.c
935 g_object_unref (filter);
941 _gtk_recent_chooser_item_activated (GtkRecentChooser *chooser)
943 g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
945 g_signal_emit (chooser, chooser_signals[ITEM_ACTIVATED], 0);
949 _gtk_recent_chooser_selection_changed (GtkRecentChooser *chooser)
951 g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
953 g_signal_emit (chooser, chooser_signals[SELECTION_CHANGED], 0);
956 #define __GTK_RECENT_CHOOSER_C__
957 #include "gtkaliasdef.c"