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