]> Pileus Git - ~andy/gtk/blob - gtk/gtkrecentchooser.c
Drop GtkSelectionWindow
[~andy/gtk] / gtk / gtkrecentchooser.c
1 /* GTK - The GIMP Toolkit
2  * gtkrecentchooser.c - Abstract interface for recent file selectors GUIs
3  *
4  * Copyright (C) 2006, Emmanuele Bassi
5  * 
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.
10  *
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.
15  *
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/>.
18  */
19
20 #include "config.h"
21
22 #include "gtkrecentchooser.h"
23 #include "gtkrecentchooserprivate.h"
24 #include "gtkrecentmanager.h"
25 #include "gtkrecentaction.h"
26 #include "gtkactivatable.h"
27 #include "gtkintl.h"
28 #include "gtktypebuiltins.h"
29 #include "gtkprivate.h"
30 #include "gtkmarshalers.h"
31
32 /**
33  * SECTION:gtkrecentchooser
34  * @Short_description: Interface implemented by widgets displaying recently
35  *   used files
36  * @Title: GtkRecentChooser
37  * @See_also: #GtkRecentManager, #GtkRecentChooserDialog,
38  *   #GtkRecentChooserWidget, #GtkRecentChooserMenu
39  *
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.
44  *
45  * Recently used files are supported since GTK+ 2.10.
46  */
47
48
49 enum
50 {
51   ITEM_ACTIVATED,
52   SELECTION_CHANGED,
53
54   LAST_SIGNAL
55 };
56
57 static gboolean recent_chooser_has_show_numbers       (GtkRecentChooser *chooser);
58
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";
63
64
65 static guint chooser_signals[LAST_SIGNAL] = { 0, };
66
67
68 typedef GtkRecentChooserIface GtkRecentChooserInterface;
69 G_DEFINE_INTERFACE (GtkRecentChooser, gtk_recent_chooser, G_TYPE_OBJECT);
70
71
72 static void
73 gtk_recent_chooser_default_init (GtkRecentChooserInterface *iface)
74 {
75   GType iface_type = G_TYPE_FROM_INTERFACE (iface);
76
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);
79   
80   /**
81    * GtkRecentChooser::selection-changed:
82    * @chooser: the object which received the signal
83    *
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.
88    *
89    * Since: 2.10
90    */
91   chooser_signals[SELECTION_CHANGED] =
92     g_signal_new (I_("selection-changed"),
93                   iface_type,
94                   G_SIGNAL_RUN_LAST,
95                   G_STRUCT_OFFSET (GtkRecentChooserIface, selection_changed),
96                   NULL, NULL,
97                   g_cclosure_marshal_VOID__VOID,
98                   G_TYPE_NONE, 0);
99    
100   /**
101    * GtkRecentChooser::item-activated:
102    * @chooser: the object which received the signal
103    *
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>.
108    *
109    * Since: 2.10
110    */
111   chooser_signals[ITEM_ACTIVATED] =
112     g_signal_new (I_("item-activated"),
113                   iface_type,
114                   G_SIGNAL_RUN_LAST,
115                   G_STRUCT_OFFSET (GtkRecentChooserIface, item_activated),
116                   NULL, NULL,
117                   g_cclosure_marshal_VOID__VOID,
118                   G_TYPE_NONE, 0);
119
120   /**
121    * GtkRecentChooser:recent-manager:
122    *
123    * The #GtkRecentManager instance used by the #GtkRecentChooser to
124    * display the list of recently used resources.
125    *
126    * Since: 2.10
127    */
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));
134   /**
135    * GtkRecentManager:show-private:
136    *
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.
140    *
141    * Since: 2.10
142    */
143   g_object_interface_install_property (iface,
144                                        g_param_spec_boolean ("show-private",
145                                                              P_("Show Private"),
146                                                              P_("Whether the private items should be displayed"),
147                                                              FALSE,
148                                                              GTK_PARAM_READWRITE));
149   /**
150    * GtkRecentChooser:show-tips:
151    *
152    * Whether this #GtkRecentChooser should display a tooltip containing the
153    * full path of the recently used resources.
154    *
155    * Since: 2.10
156    */
157   g_object_interface_install_property (iface,
158                                        g_param_spec_boolean ("show-tips",
159                                                              P_("Show Tooltips"),
160                                                              P_("Whether there should be a tooltip on the item"),
161                                                              FALSE,
162                                                              GTK_PARAM_READWRITE));
163   /**
164    * GtkRecentChooser:show-icons:
165    *
166    * Whether this #GtkRecentChooser should display an icon near the item.
167    *
168    * Since: 2.10
169    */
170   g_object_interface_install_property (iface,
171                                        g_param_spec_boolean ("show-icons",
172                                                              P_("Show Icons"),
173                                                              P_("Whether there should be an icon near the item"),
174                                                              TRUE,
175                                                              GTK_PARAM_READWRITE));
176   /**
177    * GtkRecentChooser:show-not-found:
178    *
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).
183    *
184    * Since: 2.10
185    */
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"),
190                                                              TRUE,
191                                                              GTK_PARAM_READWRITE));
192   /**
193    * GtkRecentChooser:select-multiple:
194    *
195    * Allow the user to select multiple resources.
196    *
197    * Since: 2.10
198    */
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"),
203                                                              FALSE,
204                                                              GTK_PARAM_READWRITE));
205   /**
206    * GtkRecentChooser:local-only:
207    *
208    * Whether this #GtkRecentChooser should display only local (file:)
209    * resources.
210    *
211    * Since: 2.10
212    */
213   g_object_interface_install_property (iface,
214                                        g_param_spec_boolean ("local-only",
215                                                              P_("Local only"),
216                                                              P_("Whether the selected resource(s) should be limited to local file: URIs"),
217                                                              TRUE,
218                                                              GTK_PARAM_READWRITE));
219   /**
220    * GtkRecentChooser:limit:
221    *
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.
227    *
228    * Since: 2.10
229    */
230   g_object_interface_install_property (iface,
231                                        g_param_spec_int ("limit",
232                                                          P_("Limit"),
233                                                          P_("The maximum number of items to be displayed"),
234                                                          -1,
235                                                          G_MAXINT,
236                                                          -1,
237                                                          GTK_PARAM_READWRITE));
238   /**
239    * GtkRecentChooser:sort-type:
240    *
241    * Sorting order to be used when displaying the recently used resources.
242    *
243    * Since: 2.10
244    */
245   g_object_interface_install_property (iface,
246                                        g_param_spec_enum ("sort-type",
247                                                           P_("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));
252   /**
253    * GtkRecentChooser:filter:
254    *
255    * The #GtkRecentFilter object to be used when displaying
256    * the recently used resources.
257    *
258    * Since: 2.10
259    */
260   g_object_interface_install_property (iface,
261                                        g_param_spec_object ("filter",
262                                                             P_("Filter"),
263                                                             P_("The current filter for selecting which resources are displayed"),
264                                                             GTK_TYPE_RECENT_FILTER,
265                                                             GTK_PARAM_READWRITE));
266 }
267
268 GQuark
269 gtk_recent_chooser_error_quark (void)
270 {
271   return g_quark_from_static_string ("gtk-recent-chooser-error-quark");
272 }
273
274 /**
275  * _gtk_recent_chooser_get_recent_manager:
276  * @chooser: a #GtkRecentChooser
277  *
278  * Gets the #GtkRecentManager used by @chooser.
279  *
280  * Return value: the recent manager for @chooser.
281  *
282  * Since: 2.10
283  */
284 GtkRecentManager *
285 _gtk_recent_chooser_get_recent_manager (GtkRecentChooser *chooser)
286 {
287   g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), NULL);
288   
289   return GTK_RECENT_CHOOSER_GET_IFACE (chooser)->get_recent_manager (chooser);
290 }
291
292 /**
293  * gtk_recent_chooser_set_show_private:
294  * @chooser: a #GtkRecentChooser
295  * @show_private: %TRUE to show private items, %FALSE otherwise
296  *
297  * Whether to show recently used resources marked registered as private.
298  *
299  * Since: 2.10
300  */
301 void
302 gtk_recent_chooser_set_show_private (GtkRecentChooser *chooser,
303                                      gboolean          show_private)
304 {
305   g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
306   
307   g_object_set (chooser, "show-private", show_private, NULL);
308 }
309
310 /**
311  * gtk_recent_chooser_get_show_private:
312  * @chooser: a #GtkRecentChooser
313  *
314  * Returns whether @chooser should display recently used resources
315  * registered as private.
316  *
317  * Return value: %TRUE if the recent chooser should show private items,
318  *   %FALSE otherwise.
319  *
320  * Since: 2.10
321  */
322 gboolean
323 gtk_recent_chooser_get_show_private (GtkRecentChooser *chooser)
324 {
325   gboolean show_private;
326   
327   g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), FALSE);
328   
329   g_object_get (chooser, "show-private", &show_private, NULL);
330   
331   return show_private;
332 }
333
334 /**
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
338  *
339  * Sets whether @chooser should display the recently used resources that
340  * it didn't find.  This only applies to local resources.
341  *
342  * Since: 2.10
343  */
344 void
345 gtk_recent_chooser_set_show_not_found (GtkRecentChooser *chooser,
346                                        gboolean          show_not_found)
347 {
348   g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
349   
350   g_object_set (chooser, "show-not-found", show_not_found, NULL);
351 }
352
353 /**
354  * gtk_recent_chooser_get_show_not_found:
355  * @chooser: a #GtkRecentChooser
356  *
357  * Retrieves whether @chooser should show the recently used resources that
358  * were not found.
359  *
360  * Return value: %TRUE if the resources not found should be displayed, and
361  *   %FALSE otheriwse.
362  *
363  * Since: 2.10
364  */
365 gboolean
366 gtk_recent_chooser_get_show_not_found (GtkRecentChooser *chooser)
367 {
368   gboolean show_not_found;
369   
370   g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), FALSE);
371   
372   g_object_get (chooser, "show-not-found", &show_not_found, NULL);
373   
374   return show_not_found;
375 }
376
377 /**
378  * gtk_recent_chooser_set_show_icons:
379  * @chooser: a #GtkRecentChooser
380  * @show_icons: whether to show an icon near the resource
381  *
382  * Sets whether @chooser should show an icon near the resource when
383  * displaying it.
384  *
385  * Since: 2.10
386  */
387 void
388 gtk_recent_chooser_set_show_icons (GtkRecentChooser *chooser,
389                                    gboolean          show_icons)
390 {
391   g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
392   
393   g_object_set (chooser, "show-icons", show_icons, NULL);
394 }
395
396 /**
397  * gtk_recent_chooser_get_show_icons:
398  * @chooser: a #GtkRecentChooser
399  *
400  * Retrieves whether @chooser should show an icon near the resource.
401  *
402  * Return value: %TRUE if the icons should be displayed, %FALSE otherwise.
403  *
404  * Since: 2.10
405  */
406 gboolean
407 gtk_recent_chooser_get_show_icons (GtkRecentChooser *chooser)
408 {
409   gboolean show_icons;
410   
411   g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), FALSE);
412   
413   g_object_get (chooser, "show-icons", &show_icons, NULL);
414   
415   return show_icons;
416 }
417
418 /**
419  * gtk_recent_chooser_set_select_multiple:
420  * @chooser: a #GtkRecentChooser
421  * @select_multiple: %TRUE if @chooser can select more than one item
422  *
423  * Sets whether @chooser can select multiple items.
424  *
425  * Since: 2.10
426  */
427 void
428 gtk_recent_chooser_set_select_multiple (GtkRecentChooser *chooser,
429                                         gboolean          select_multiple)
430 {
431   g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
432   
433   g_object_set (chooser, "select-multiple", select_multiple, NULL);
434 }
435
436 /**
437  * gtk_recent_chooser_get_select_multiple:
438  * @chooser: a #GtkRecentChooser
439  *
440  * Gets whether @chooser can select multiple items.
441  *
442  * Return value: %TRUE if @chooser can select more than one item.
443  *
444  * Since: 2.10
445  */
446 gboolean
447 gtk_recent_chooser_get_select_multiple (GtkRecentChooser *chooser)
448 {
449   gboolean select_multiple;
450   
451   g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), FALSE);
452   
453   g_object_get (chooser, "select-multiple", &select_multiple, NULL);
454   
455   return select_multiple;
456 }
457
458 /**
459  * gtk_recent_chooser_set_local_only:
460  * @chooser: a #GtkRecentChooser
461  * @local_only: %TRUE if only local files can be shown
462  * 
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.
467  *
468  * Since: 2.10
469  */
470 void
471 gtk_recent_chooser_set_local_only (GtkRecentChooser *chooser,
472                                    gboolean          local_only)
473 {
474   g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
475
476   g_object_set (chooser, "local-only", local_only, NULL);
477 }
478
479 /**
480  * gtk_recent_chooser_get_local_only:
481  * @chooser: a #GtkRecentChooser
482  *
483  * Gets whether only local resources should be shown in the recently used
484  * resources selector.  See gtk_recent_chooser_set_local_only()
485  *
486  * Return value: %TRUE if only local resources should be shown.
487  *
488  * Since: 2.10
489  */
490 gboolean
491 gtk_recent_chooser_get_local_only (GtkRecentChooser *chooser)
492 {
493   gboolean local_only;
494
495   g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), FALSE);
496
497   g_object_get (chooser, "local-only", &local_only, NULL);
498
499   return local_only;
500 }
501
502 /**
503  * gtk_recent_chooser_set_limit:
504  * @chooser: a #GtkRecentChooser
505  * @limit: a positive integer, or -1 for all items
506  *
507  * Sets the number of items that should be returned by
508  * gtk_recent_chooser_get_items() and gtk_recent_chooser_get_uris().
509  *
510  * Since: 2.10
511  */
512 void
513 gtk_recent_chooser_set_limit (GtkRecentChooser *chooser,
514                               gint              limit)
515 {
516   g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
517   
518   g_object_set (chooser, "limit", limit, NULL);
519 }
520
521 /**
522  * gtk_recent_chooser_get_limit:
523  * @chooser: a #GtkRecentChooser
524  *
525  * Gets the number of items returned by gtk_recent_chooser_get_items()
526  * and gtk_recent_chooser_get_uris().
527  *
528  * Return value: A positive integer, or -1 meaning that all items are
529  *   returned.
530  *
531  * Since: 2.10
532  */
533 gint
534 gtk_recent_chooser_get_limit (GtkRecentChooser *chooser)
535 {
536   gint limit;
537   
538   g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), 10);
539   
540   g_object_get (chooser, "limit", &limit, NULL);
541   
542   return limit;
543 }
544
545 /**
546  * gtk_recent_chooser_set_show_tips:
547  * @chooser: a #GtkRecentChooser
548  * @show_tips: %TRUE if tooltips should be shown
549  *
550  * Sets whether to show a tooltips containing the full path of each
551  * recently used resource in a #GtkRecentChooser widget.
552  *
553  * Since: 2.10
554  */
555 void
556 gtk_recent_chooser_set_show_tips (GtkRecentChooser *chooser,
557                                   gboolean          show_tips)
558 {
559   g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
560   
561   g_object_set (chooser, "show-tips", show_tips, NULL);
562 }
563
564 /**
565  * gtk_recent_chooser_get_show_tips:
566  * @chooser: a #GtkRecentChooser
567  *
568  * Gets whether @chooser should display tooltips containing the full path
569  * of a recently user resource.
570  *
571  * Return value: %TRUE if the recent chooser should show tooltips,
572  *   %FALSE otherwise.
573  *
574  * Since: 2.10
575  */
576 gboolean
577 gtk_recent_chooser_get_show_tips (GtkRecentChooser *chooser)
578 {
579   gboolean show_tips;
580   
581   g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), FALSE);
582   
583   g_object_get (chooser, "show-tips", &show_tips, NULL);
584   
585   return show_tips;
586 }
587
588 static gboolean
589 recent_chooser_has_show_numbers (GtkRecentChooser *chooser)
590 {
591   GParamSpec *pspec;
592   
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.
600    */
601   pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (chooser),
602                                         "show-numbers");
603
604   return (pspec && pspec->value_type == G_TYPE_BOOLEAN);
605 }
606
607 /**
608  * gtk_recent_chooser_set_sort_type:
609  * @chooser: a #GtkRecentChooser
610  * @sort_type: sort order that the chooser should use
611  *
612  * Changes the sorting order of the recently used resources list displayed by
613  * @chooser.
614  *
615  * Since: 2.10
616  */
617 void
618 gtk_recent_chooser_set_sort_type (GtkRecentChooser  *chooser,
619                                   GtkRecentSortType  sort_type)
620 {  
621   g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
622   
623   g_object_set (chooser, "sort-type", sort_type, NULL);
624 }
625
626 /**
627  * gtk_recent_chooser_get_sort_type:
628  * @chooser: a #GtkRecentChooser
629  *
630  * Gets the value set by gtk_recent_chooser_set_sort_type().
631  *
632  * Return value: the sorting order of the @chooser.
633  *
634  * Since: 2.10
635  */
636 GtkRecentSortType
637 gtk_recent_chooser_get_sort_type (GtkRecentChooser *chooser)
638 {
639   GtkRecentSortType sort_type;
640   
641   g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), GTK_RECENT_SORT_NONE);
642   
643   g_object_get (chooser, "sort-type", &sort_type, NULL);
644
645   return sort_type;
646 }
647
648 /**
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
654  *
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.
658  *
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.
663  *
664  * Since: 2.10
665  */
666 void
667 gtk_recent_chooser_set_sort_func  (GtkRecentChooser  *chooser,
668                                    GtkRecentSortFunc  sort_func,
669                                    gpointer           sort_data,
670                                    GDestroyNotify     data_destroy)
671 {
672   g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
673   
674   GTK_RECENT_CHOOSER_GET_IFACE (chooser)->set_sort_func (chooser,
675                                                          sort_func,
676                                                          sort_data,
677                                                          data_destroy);
678 }
679
680 /**
681  * gtk_recent_chooser_set_current_uri:
682  * @chooser: a #GtkRecentChooser
683  * @uri: a URI
684  * @error: (allow-none): return location for a #GError, or %NULL
685  *
686  * Sets @uri as the current URI for @chooser.
687  *
688  * Return value: %TRUE if the URI was found.
689  *
690  * Since: 2.10
691  */
692 gboolean
693 gtk_recent_chooser_set_current_uri (GtkRecentChooser  *chooser,
694                                     const gchar       *uri,
695                                     GError           **error)
696 {
697   g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), FALSE);
698   
699   return GTK_RECENT_CHOOSER_GET_IFACE (chooser)->set_current_uri (chooser, uri, error);
700 }
701
702 /**
703  * gtk_recent_chooser_get_current_uri:
704  * @chooser: a #GtkRecentChooser
705  *
706  * Gets the URI currently selected by @chooser.
707  *
708  * Return value: a newly allocated string holding a URI.
709  *
710  * Since: 2.10
711  */
712 gchar *
713 gtk_recent_chooser_get_current_uri (GtkRecentChooser *chooser)
714 {
715   g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), NULL);
716   
717   return GTK_RECENT_CHOOSER_GET_IFACE (chooser)->get_current_uri (chooser);
718 }
719
720 /**
721  * gtk_recent_chooser_get_current_item:
722  * @chooser: a #GtkRecentChooser
723  * 
724  * Gets the #GtkRecentInfo currently selected by @chooser.
725  *
726  * Return value: a #GtkRecentInfo.  Use gtk_recent_info_unref() when
727  *   when you have finished using it.
728  *
729  * Since: 2.10
730  */
731 GtkRecentInfo *
732 gtk_recent_chooser_get_current_item (GtkRecentChooser *chooser)
733 {
734   GtkRecentManager *manager;
735   GtkRecentInfo *retval;
736   gchar *uri;
737   
738   g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), NULL);
739   
740   uri = gtk_recent_chooser_get_current_uri (chooser);
741   if (!uri)
742     return NULL;
743   
744   manager = _gtk_recent_chooser_get_recent_manager (chooser);
745   retval = gtk_recent_manager_lookup_item (manager, uri, NULL);
746   g_free (uri);
747   
748   return retval;
749 }
750
751 /**
752  * gtk_recent_chooser_select_uri:
753  * @chooser: a #GtkRecentChooser
754  * @uri: a URI
755  * @error: (allow-none): return location for a #GError, or %NULL
756  *
757  * Selects @uri inside @chooser.
758  *
759  * Return value: %TRUE if @uri was found.
760  *
761  * Since: 2.10
762  */
763 gboolean
764 gtk_recent_chooser_select_uri (GtkRecentChooser  *chooser,
765                                const gchar       *uri,
766                                GError           **error)
767 {
768   g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), FALSE);
769   
770   return GTK_RECENT_CHOOSER_GET_IFACE (chooser)->select_uri (chooser, uri, error);
771 }
772
773 /**
774  * gtk_recent_chooser_unselect_uri:
775  * @chooser: a #GtkRecentChooser
776  * @uri: a URI
777  *
778  * Unselects @uri inside @chooser.
779  *
780  * Since: 2.10
781  */
782 void
783 gtk_recent_chooser_unselect_uri (GtkRecentChooser *chooser,
784                                  const gchar      *uri)
785 {
786   g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
787   
788   GTK_RECENT_CHOOSER_GET_IFACE (chooser)->unselect_uri (chooser, uri);
789 }
790
791 /**
792  * gtk_recent_chooser_select_all:
793  * @chooser: a #GtkRecentChooser
794  *
795  * Selects all the items inside @chooser, if the @chooser supports
796  * multiple selection.
797  *
798  * Since: 2.10
799  */
800 void
801 gtk_recent_chooser_select_all (GtkRecentChooser *chooser)
802 {
803   g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
804   
805   GTK_RECENT_CHOOSER_GET_IFACE (chooser)->select_all (chooser);
806 }
807
808 /**
809  * gtk_recent_chooser_unselect_all:
810  * @chooser: a #GtkRecentChooser
811  *
812  * Unselects all the items inside @chooser.
813  * 
814  * Since: 2.10
815  */
816 void
817 gtk_recent_chooser_unselect_all (GtkRecentChooser *chooser)
818 {
819   g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
820   
821   GTK_RECENT_CHOOSER_GET_IFACE (chooser)->unselect_all (chooser);
822 }
823
824 /**
825  * gtk_recent_chooser_get_items:
826  * @chooser: a #GtkRecentChooser
827  *
828  * Gets the list of recently used resources in form of #GtkRecentInfo objects.
829  *
830  * The return value of this function is affected by the "sort-type" and
831  * "limit" properties of @chooser.
832  *
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().
837  *
838  * Since: 2.10
839  */
840 GList *
841 gtk_recent_chooser_get_items (GtkRecentChooser *chooser)
842 {
843   g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), NULL);
844   
845   return GTK_RECENT_CHOOSER_GET_IFACE (chooser)->get_items (chooser);
846 }
847
848 /**
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
852  *
853  * Gets the URI of the recently used resources.
854  *
855  * The return value of this function is affected by the "sort-type" and "limit"
856  * properties of @chooser.
857  *
858  * Since the returned array is %NULL terminated, @length may be %NULL.
859  * 
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.
863  *
864  * Since: 2.10
865  */
866 gchar **
867 gtk_recent_chooser_get_uris (GtkRecentChooser *chooser,
868                              gsize            *length)
869 {
870   GList *items, *l;
871   gchar **retval;
872   gsize n_items, i;
873   
874   items = gtk_recent_chooser_get_items (chooser);
875   
876   n_items = g_list_length (items);
877   retval = g_new0 (gchar *, n_items + 1);
878   
879   for (l = items, i = 0; l != NULL; l = l->next)
880     {
881       GtkRecentInfo *info = (GtkRecentInfo *) l->data;
882       const gchar *uri;
883       
884       g_assert (info != NULL);
885       
886       uri = gtk_recent_info_get_uri (info);
887       g_assert (uri != NULL);
888       
889       retval[i++] = g_strdup (uri);
890     }
891   retval[i] = NULL;
892   
893   if (length)
894     *length = i;
895   
896   g_list_free_full (items, (GDestroyNotify) gtk_recent_info_unref);
897   
898   return retval;
899 }
900
901 /**
902  * gtk_recent_chooser_add_filter:
903  * @chooser: a #GtkRecentChooser
904  * @filter: a #GtkRecentFilter
905  *
906  * Adds @filter to the list of #GtkRecentFilter objects held by @chooser.
907  *
908  * If no previous filter objects were defined, this function will call
909  * gtk_recent_chooser_set_filter().
910  *
911  * Since: 2.10
912  */
913 void
914 gtk_recent_chooser_add_filter (GtkRecentChooser *chooser,
915                                GtkRecentFilter  *filter)
916 {
917   g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
918   g_return_if_fail (GTK_IS_RECENT_FILTER (filter));
919   
920   GTK_RECENT_CHOOSER_GET_IFACE (chooser)->add_filter (chooser, filter);
921 }
922
923 /**
924  * gtk_recent_chooser_remove_filter:
925  * @chooser: a #GtkRecentChooser
926  * @filter: a #GtkRecentFilter
927  *
928  * Removes @filter from the list of #GtkRecentFilter objects held by @chooser.
929  *
930  * Since: 2.10
931  */
932 void
933 gtk_recent_chooser_remove_filter (GtkRecentChooser *chooser,
934                                   GtkRecentFilter  *filter)
935 {
936   g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
937   g_return_if_fail (GTK_IS_RECENT_FILTER (filter));
938   
939   GTK_RECENT_CHOOSER_GET_IFACE (chooser)->remove_filter (chooser, filter);
940 }
941
942 /**
943  * gtk_recent_chooser_list_filters:
944  * @chooser: a #GtkRecentChooser
945  *
946  * Gets the #GtkRecentFilter objects held by @chooser.
947  *
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().
951  *
952  * Since: 2.10
953  */
954 GSList *
955 gtk_recent_chooser_list_filters (GtkRecentChooser *chooser)
956 {
957   g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), NULL);
958   
959   return GTK_RECENT_CHOOSER_GET_IFACE (chooser)->list_filters (chooser);
960 }
961
962 /**
963  * gtk_recent_chooser_set_filter:
964  * @chooser: a #GtkRecentChooser
965  * @filter: a #GtkRecentFilter
966  *
967  * Sets @filter as the current #GtkRecentFilter object used by @chooser
968  * to affect the displayed recently used resources.
969  *
970  * Since: 2.10
971  */
972 void
973 gtk_recent_chooser_set_filter (GtkRecentChooser *chooser,
974                                GtkRecentFilter  *filter)
975 {
976   g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
977   g_return_if_fail (GTK_IS_RECENT_FILTER (filter));
978   
979   g_object_set (G_OBJECT (chooser), "filter", filter, NULL);
980 }
981
982 /**
983  * gtk_recent_chooser_get_filter:
984  * @chooser: a #GtkRecentChooser
985  *
986  * Gets the #GtkRecentFilter object currently used by @chooser to affect
987  * the display of the recently used resources.
988  *
989  * Return value: (transfer none): a #GtkRecentFilter object.
990  *
991  * Since: 2.10
992  */
993 GtkRecentFilter *
994 gtk_recent_chooser_get_filter (GtkRecentChooser *chooser)
995 {
996   GtkRecentFilter *filter;
997   
998   g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), NULL);
999   
1000   g_object_get (G_OBJECT (chooser), "filter", &filter, NULL);
1001   
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
1005    */
1006   if (filter)
1007     g_object_unref (filter);
1008   
1009   return filter;
1010 }
1011
1012 void
1013 _gtk_recent_chooser_item_activated (GtkRecentChooser *chooser)
1014 {
1015   g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
1016   
1017   g_signal_emit (chooser, chooser_signals[ITEM_ACTIVATED], 0);
1018 }
1019
1020 void
1021 _gtk_recent_chooser_selection_changed (GtkRecentChooser *chooser)
1022 {
1023   g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
1024
1025   g_signal_emit (chooser, chooser_signals[SELECTION_CHANGED], 0);
1026 }
1027
1028 void
1029 _gtk_recent_chooser_update (GtkActivatable *activatable,
1030                             GtkAction      *action,
1031                             const gchar    *property_name)
1032 {
1033   GtkRecentChooser *recent_chooser = GTK_RECENT_CHOOSER (activatable);
1034   GtkRecentChooser *action_chooser = GTK_RECENT_CHOOSER (action);
1035   GtkRecentAction  *recent_action  = GTK_RECENT_ACTION (action);
1036
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));
1056 }
1057
1058 void
1059 _gtk_recent_chooser_sync_action_properties (GtkActivatable *activatable,
1060                                             GtkAction      *action)
1061 {
1062   GtkRecentChooser *recent_chooser = GTK_RECENT_CHOOSER (activatable);
1063   GtkRecentChooser *action_chooser = GTK_RECENT_CHOOSER (action);
1064
1065   if (!action)
1066     return;
1067
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)),
1071                   NULL);
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));
1080 }
1081
1082 void
1083 _gtk_recent_chooser_set_related_action (GtkRecentChooser *recent_chooser,
1084                                         GtkAction        *action)
1085 {
1086   GtkAction *prev_action;
1087
1088   prev_action = g_object_get_qdata (G_OBJECT (recent_chooser), quark_gtk_related_action);
1089
1090   if (prev_action == action)
1091     return;
1092
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);
1095 }
1096
1097 GtkAction *
1098 _gtk_recent_chooser_get_related_action (GtkRecentChooser *recent_chooser)
1099 {
1100   return g_object_get_qdata (G_OBJECT (recent_chooser), quark_gtk_related_action);
1101 }
1102
1103 /* The default for use-action-appearance is TRUE, so we try to set the
1104  * qdata backwards for this case.
1105  */
1106 void
1107 _gtk_recent_chooser_set_use_action_appearance (GtkRecentChooser *recent_chooser, 
1108                                                gboolean          use_appearance)
1109 {
1110   GtkAction *action;
1111   gboolean   use_action_appearance;
1112
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));
1115
1116   if (use_action_appearance != use_appearance)
1117     {
1118
1119       g_object_set_qdata (G_OBJECT (recent_chooser), quark_gtk_use_action_appearance, GINT_TO_POINTER (!use_appearance));
1120  
1121       gtk_activatable_sync_action_properties (GTK_ACTIVATABLE (recent_chooser), action);
1122     }
1123 }
1124
1125 gboolean
1126 _gtk_recent_chooser_get_use_action_appearance (GtkRecentChooser *recent_chooser)
1127 {
1128   return !GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (recent_chooser), quark_gtk_use_action_appearance));
1129 }