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