]> Pileus Git - ~andy/gtk/blob - gtk/gtkrecentchooser.c
Bug 457086 - numpad does not work when the Thai-Lao input method is used
[~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 enum
37 {
38   ITEM_ACTIVATED,
39   SELECTION_CHANGED,
40
41   LAST_SIGNAL
42 };
43
44 static void     gtk_recent_chooser_class_init         (gpointer          g_iface);
45 static gboolean recent_chooser_has_show_numbers       (GtkRecentChooser *chooser);
46
47 static GQuark      quark_gtk_related_action               = 0;
48 static GQuark      quark_gtk_use_action_appearance        = 0;
49 static const gchar gtk_related_action_key[]               = "gtk-related-action";
50 static const gchar gtk_use_action_appearance_key[]        = "gtk-use-action-appearance";
51
52
53 static guint chooser_signals[LAST_SIGNAL] = { 0, };
54
55 GType
56 gtk_recent_chooser_get_type (void)
57 {
58   static GType chooser_type = 0;
59   
60   if (!chooser_type)
61     {
62       chooser_type = g_type_register_static_simple (G_TYPE_INTERFACE,
63                                                     I_("GtkRecentChooser"),
64                                                     sizeof (GtkRecentChooserIface),
65                                                     (GClassInitFunc) gtk_recent_chooser_class_init,
66                                                     0, NULL, 0);
67       
68       g_type_interface_add_prerequisite (chooser_type, G_TYPE_OBJECT);
69     }
70   
71   return chooser_type;
72 }
73
74 static void
75 gtk_recent_chooser_class_init (gpointer g_iface)
76 {
77   GType iface_type = G_TYPE_FROM_INTERFACE (g_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 (g_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 (g_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 (g_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 (g_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 (g_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 (g_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 (g_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 (g_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 (g_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 (g_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_show_numbers:
611  * @chooser: a #GtkRecentChooser
612  * @show_numbers: %TRUE to show numbers, %FALSE otherwise
613  *
614  * Whether to show recently used resources prepended by a unique number.
615  *
616  * Deprecated: 2.12: Use gtk_recent_chooser_menu_set_show_numbers() instead.
617  *
618  * Since: 2.10
619  */
620 void
621 gtk_recent_chooser_set_show_numbers (GtkRecentChooser *chooser,
622                                      gboolean          show_numbers)
623 {
624   g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
625
626   if (!recent_chooser_has_show_numbers (chooser))
627     {
628       g_warning ("Choosers of type `%s' do not support showing numbers",
629                  G_OBJECT_TYPE_NAME (chooser));
630       
631       return;
632     }
633   
634   g_object_set (chooser, "show-numbers", show_numbers, NULL);
635 }
636
637 /**
638  * gtk_recent_chooser_get_show_numbers:
639  * @chooser: a #GtkRecentChooser
640  *
641  * Returns whether @chooser should display recently used resources
642  * prepended by a unique number.
643  *
644  * Deprecated: 2.12: use gtk_recent_chooser_menu_get_show_numbers() instead.
645  *
646  * Return value: %TRUE if the recent chooser should show display numbers,
647  *   %FALSE otherwise.
648  *
649  * Since: 2.10
650  */
651 gboolean
652 gtk_recent_chooser_get_show_numbers (GtkRecentChooser *chooser)
653 {
654   GParamSpec *pspec;
655   gboolean show_numbers;
656   
657   g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), FALSE);
658
659   pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (chooser),
660                                         "show-numbers");
661   if (!pspec || pspec->value_type != G_TYPE_BOOLEAN)
662     {
663       g_warning ("Choosers of type `%s' do not support showing numbers",
664                  G_OBJECT_TYPE_NAME (chooser));
665
666       return FALSE;
667     }
668   
669   g_object_get (chooser, "show-numbers", &show_numbers, NULL);
670   
671   return show_numbers;
672 }
673
674
675 /**
676  * gtk_recent_chooser_set_sort_type:
677  * @chooser: a #GtkRecentChooser
678  * @sort_type: sort order that the chooser should use
679  *
680  * Changes the sorting order of the recently used resources list displayed by
681  * @chooser.
682  *
683  * Since: 2.10
684  */
685 void
686 gtk_recent_chooser_set_sort_type (GtkRecentChooser  *chooser,
687                                   GtkRecentSortType  sort_type)
688 {  
689   g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
690   
691   g_object_set (chooser, "sort-type", sort_type, NULL);
692 }
693
694 /**
695  * gtk_recent_chooser_get_sort_type:
696  * @chooser: a #GtkRecentChooser
697  *
698  * Gets the value set by gtk_recent_chooser_set_sort_type().
699  *
700  * Return value: the sorting order of the @chooser.
701  *
702  * Since: 2.10
703  */
704 GtkRecentSortType
705 gtk_recent_chooser_get_sort_type (GtkRecentChooser *chooser)
706 {
707   GtkRecentSortType sort_type;
708   
709   g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), GTK_RECENT_SORT_NONE);
710   
711   g_object_get (chooser, "sort-type", &sort_type, NULL);
712
713   return sort_type;
714 }
715
716 /**
717  * gtk_recent_chooser_set_sort_func:
718  * @chooser: a #GtkRecentChooser
719  * @sort_func: the comparison function
720  * @sort_data: user data to pass to @sort_func, or %NULL
721  * @data_destroy: destroy notifier for @sort_data, or %NULL
722  *
723  * Sets the comparison function used when sorting to be @sort_func.  If
724  * the @chooser has the sort type set to #GTK_RECENT_SORT_CUSTOM then
725  * the chooser will sort using this function.
726  *
727  * To the comparison function will be passed two #GtkRecentInfo structs and
728  * @sort_data;  @sort_func should return a positive integer if the first
729  * item comes before the second, zero if the two items are equal and
730  * a negative integer if the first item comes after the second.
731  *
732  * Since: 2.10
733  */
734 void
735 gtk_recent_chooser_set_sort_func  (GtkRecentChooser  *chooser,
736                                    GtkRecentSortFunc  sort_func,
737                                    gpointer           sort_data,
738                                    GDestroyNotify     data_destroy)
739 {
740   g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
741   
742   GTK_RECENT_CHOOSER_GET_IFACE (chooser)->set_sort_func (chooser,
743                                                          sort_func,
744                                                          sort_data,
745                                                          data_destroy);
746 }
747
748 /**
749  * gtk_recent_chooser_set_current_uri:
750  * @chooser: a #GtkRecentChooser
751  * @uri: a URI
752  * @error: return location for a #GError, or %NULL
753  *
754  * Sets @uri as the current URI for @chooser.
755  *
756  * Return value: %TRUE if the URI was found.
757  *
758  * Since: 2.10
759  */
760 gboolean
761 gtk_recent_chooser_set_current_uri (GtkRecentChooser  *chooser,
762                                     const gchar       *uri,
763                                     GError           **error)
764 {
765   g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), FALSE);
766   
767   return GTK_RECENT_CHOOSER_GET_IFACE (chooser)->set_current_uri (chooser, uri, error);
768 }
769
770 /**
771  * gtk_recent_chooser_get_current_uri:
772  * @chooser: a #GtkRecentChooser
773  *
774  * Gets the URI currently selected by @chooser.
775  *
776  * Return value: a newly allocated string holding a URI.
777  *
778  * Since: 2.10
779  */
780 gchar *
781 gtk_recent_chooser_get_current_uri (GtkRecentChooser *chooser)
782 {
783   g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), NULL);
784   
785   return GTK_RECENT_CHOOSER_GET_IFACE (chooser)->get_current_uri (chooser);
786 }
787
788 /**
789  * gtk_recent_chooser_get_current_item:
790  * @chooser: a #GtkRecentChooser
791  * 
792  * Gets the #GtkRecentInfo currently selected by @chooser.
793  *
794  * Return value: a #GtkRecentInfo.  Use gtk_recent_info_unref() when
795  *   when you have finished using it.
796  *
797  * Since: 2.10
798  */
799 GtkRecentInfo *
800 gtk_recent_chooser_get_current_item (GtkRecentChooser *chooser)
801 {
802   GtkRecentManager *manager;
803   GtkRecentInfo *retval;
804   gchar *uri;
805   
806   g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), NULL);
807   
808   uri = gtk_recent_chooser_get_current_uri (chooser);
809   if (!uri)
810     return NULL;
811   
812   manager = _gtk_recent_chooser_get_recent_manager (chooser);
813   retval = gtk_recent_manager_lookup_item (manager, uri, NULL);
814   g_free (uri);
815   
816   return retval;
817 }
818
819 /**
820  * gtk_recent_chooser_select_uri:
821  * @chooser: a #GtkRecentChooser
822  * @uri: a URI
823  * @error: return location for a #GError, or %NULL
824  *
825  * Selects @uri inside @chooser.
826  *
827  * Return value: %TRUE if @uri was found.
828  *
829  * Since: 2.10
830  */
831 gboolean
832 gtk_recent_chooser_select_uri (GtkRecentChooser  *chooser,
833                                const gchar       *uri,
834                                GError           **error)
835 {
836   g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), FALSE);
837   
838   return GTK_RECENT_CHOOSER_GET_IFACE (chooser)->select_uri (chooser, uri, error);
839 }
840
841 /**
842  * gtk_recent_chooser_unselect_uri:
843  * @chooser: a #GtkRecentChooser
844  * @uri: a URI
845  *
846  * Unselects @uri inside @chooser.
847  *
848  * Since: 2.10
849  */
850 void
851 gtk_recent_chooser_unselect_uri (GtkRecentChooser *chooser,
852                                  const gchar      *uri)
853 {
854   g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
855   
856   GTK_RECENT_CHOOSER_GET_IFACE (chooser)->unselect_uri (chooser, uri);
857 }
858
859 /**
860  * gtk_recent_chooser_select_all:
861  * @chooser: a #GtkRecentChooser
862  *
863  * Selects all the items inside @chooser, if the @chooser supports
864  * multiple selection.
865  *
866  * Since: 2.10
867  */
868 void
869 gtk_recent_chooser_select_all (GtkRecentChooser *chooser)
870 {
871   g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
872   
873   GTK_RECENT_CHOOSER_GET_IFACE (chooser)->select_all (chooser);
874 }
875
876 /**
877  * gtk_recent_chooser_unselect_all:
878  * @chooser: a #GtkRecentChooser
879  *
880  * Unselects all the items inside @chooser.
881  * 
882  * Since: 2.10
883  */
884 void
885 gtk_recent_chooser_unselect_all (GtkRecentChooser *chooser)
886 {
887   g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
888   
889   GTK_RECENT_CHOOSER_GET_IFACE (chooser)->unselect_all (chooser);
890 }
891
892 /**
893  * gtk_recent_chooser_get_items:
894  * @chooser: a #GtkRecentChooser
895  *
896  * Gets the list of recently used resources in form of #GtkRecentInfo objects.
897  *
898  * The return value of this function is affected by the "sort-type" and
899  * "limit" properties of @chooser.
900  *
901  * Return value: A newly allocated list of #GtkRecentInfo objects.  You should
902  *   use gtk_recent_info_unref() on every item of the list, and then free
903  *   the list itself using g_list_free().
904  *
905  * Since: 2.10
906  */
907 GList *
908 gtk_recent_chooser_get_items (GtkRecentChooser *chooser)
909 {
910   g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), NULL);
911   
912   return GTK_RECENT_CHOOSER_GET_IFACE (chooser)->get_items (chooser);
913 }
914
915 /**
916  * gtk_recent_chooser_get_uris:
917  * @chooser: a #GtkRecentChooser
918  * @length: return location for a the length of the URI list, or %NULL
919  *
920  * Gets the URI of the recently used resources.
921  *
922  * The return value of this function is affected by the "sort-type" and "limit"
923  * properties of @chooser.
924  *
925  * Since the returned array is %NULL terminated, @length may be %NULL.
926  * 
927  * Return value: A newly allocated, %NULL terminated array of strings. Use
928  *   g_strfreev() to free it.
929  *
930  * Since: 2.10
931  */
932 gchar **
933 gtk_recent_chooser_get_uris (GtkRecentChooser *chooser,
934                              gsize            *length)
935 {
936   GList *items, *l;
937   gchar **retval;
938   gsize n_items, i;
939   
940   items = gtk_recent_chooser_get_items (chooser);
941   
942   n_items = g_list_length (items);
943   retval = g_new0 (gchar *, n_items + 1);
944   
945   for (l = items, i = 0; l != NULL; l = l->next)
946     {
947       GtkRecentInfo *info = (GtkRecentInfo *) l->data;
948       const gchar *uri;
949       
950       g_assert (info != NULL);
951       
952       uri = gtk_recent_info_get_uri (info);
953       g_assert (uri != NULL);
954       
955       retval[i++] = g_strdup (uri);
956     }
957   retval[i] = NULL;
958   
959   if (length)
960     *length = i;
961   
962   g_list_foreach (items,
963                   (GFunc) gtk_recent_info_unref,
964                   NULL);
965   g_list_free (items);
966   
967   return retval;
968 }
969
970 /**
971  * gtk_recent_chooser_add_filter:
972  * @chooser: a #GtkRecentChooser
973  * @filter: a #GtkRecentFilter
974  *
975  * Adds @filter to the list of #GtkRecentFilter objects held by @chooser.
976  *
977  * If no previous filter objects were defined, this function will call
978  * gtk_recent_chooser_set_filter().
979  *
980  * Since: 2.10
981  */
982 void
983 gtk_recent_chooser_add_filter (GtkRecentChooser *chooser,
984                                GtkRecentFilter  *filter)
985 {
986   g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
987   g_return_if_fail (GTK_IS_RECENT_FILTER (filter));
988   
989   GTK_RECENT_CHOOSER_GET_IFACE (chooser)->add_filter (chooser, filter);
990 }
991
992 /**
993  * gtk_recent_chooser_remove_filter:
994  * @chooser: a #GtkRecentChooser
995  * @filter: a #GtkRecentFilter
996  *
997  * Removes @filter from the list of #GtkRecentFilter objects held by @chooser.
998  *
999  * Since: 2.10
1000  */
1001 void
1002 gtk_recent_chooser_remove_filter (GtkRecentChooser *chooser,
1003                                   GtkRecentFilter  *filter)
1004 {
1005   g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
1006   g_return_if_fail (GTK_IS_RECENT_FILTER (filter));
1007   
1008   GTK_RECENT_CHOOSER_GET_IFACE (chooser)->remove_filter (chooser, filter);
1009 }
1010
1011 /**
1012  * gtk_recent_chooser_list_filters:
1013  * @chooser: a #GtkRecentChooser
1014  *
1015  * Gets the #GtkRecentFilter objects held by @chooser.
1016  *
1017  * Return value: A singly linked list of #GtkRecentFilter objects.  You
1018  *   should just free the returned list using g_slist_free().
1019  *
1020  * Since: 2.10
1021  */
1022 GSList *
1023 gtk_recent_chooser_list_filters (GtkRecentChooser *chooser)
1024 {
1025   g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), NULL);
1026   
1027   return GTK_RECENT_CHOOSER_GET_IFACE (chooser)->list_filters (chooser);
1028 }
1029
1030 /**
1031  * gtk_recent_chooser_set_filter:
1032  * @chooser: a #GtkRecentChooser
1033  * @filter: a #GtkRecentFilter
1034  *
1035  * Sets @filter as the current #GtkRecentFilter object used by @chooser
1036  * to affect the displayed recently used resources.
1037  *
1038  * Since: 2.10
1039  */
1040 void
1041 gtk_recent_chooser_set_filter (GtkRecentChooser *chooser,
1042                                GtkRecentFilter  *filter)
1043 {
1044   g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
1045   g_return_if_fail (GTK_IS_RECENT_FILTER (filter));
1046   
1047   g_object_set (G_OBJECT (chooser), "filter", filter, NULL);
1048 }
1049
1050 /**
1051  * gtk_recent_chooser_get_filter:
1052  * @chooser: a #GtkRecentChooser
1053  *
1054  * Gets the #GtkRecentFilter object currently used by @chooser to affect
1055  * the display of the recently used resources.
1056  *
1057  * Return value: a #GtkRecentFilter object.
1058  *
1059  * Since: 2.10
1060  */
1061 GtkRecentFilter *
1062 gtk_recent_chooser_get_filter (GtkRecentChooser *chooser)
1063 {
1064   GtkRecentFilter *filter;
1065   
1066   g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), NULL);
1067   
1068   g_object_get (G_OBJECT (chooser), "filter", &filter, NULL);
1069   
1070   /* we need this hack because g_object_get() increases the refcount
1071    * of the returned object; see also gtk_file_chooser_get_filter()
1072    * inside gtkfilechooser.c
1073    */
1074   if (filter)
1075     g_object_unref (filter);
1076   
1077   return filter;
1078 }
1079
1080 void
1081 _gtk_recent_chooser_item_activated (GtkRecentChooser *chooser)
1082 {
1083   g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
1084   
1085   g_signal_emit (chooser, chooser_signals[ITEM_ACTIVATED], 0);
1086 }
1087
1088 void
1089 _gtk_recent_chooser_selection_changed (GtkRecentChooser *chooser)
1090 {
1091   g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
1092
1093   g_signal_emit (chooser, chooser_signals[SELECTION_CHANGED], 0);
1094 }
1095
1096 void
1097 _gtk_recent_chooser_update (GtkActivatable *activatable,
1098                             GtkAction      *action,
1099                             const gchar    *property_name)
1100 {
1101   GtkRecentChooser *recent_chooser = GTK_RECENT_CHOOSER (activatable);
1102   GtkRecentChooser *action_chooser = GTK_RECENT_CHOOSER (action);
1103   GtkRecentAction  *recent_action  = GTK_RECENT_ACTION (action);
1104
1105   if (strcmp (property_name, "show-numbers") == 0 && recent_chooser_has_show_numbers (recent_chooser))
1106     g_object_set (recent_chooser, "show-numbers",
1107                   gtk_recent_action_get_show_numbers (recent_action), NULL);
1108   else if (strcmp (property_name, "show-private") == 0)
1109     gtk_recent_chooser_set_show_private (recent_chooser, gtk_recent_chooser_get_show_private (action_chooser));
1110   else if (strcmp (property_name, "show-not-found") == 0)
1111     gtk_recent_chooser_set_show_not_found (recent_chooser, gtk_recent_chooser_get_show_not_found (action_chooser));
1112   else if (strcmp (property_name, "show-tips") == 0)
1113     gtk_recent_chooser_set_show_tips (recent_chooser, gtk_recent_chooser_get_show_tips (action_chooser));
1114   else if (strcmp (property_name, "show-icons") == 0)
1115     gtk_recent_chooser_set_show_icons (recent_chooser, gtk_recent_chooser_get_show_icons (action_chooser));
1116   else if (strcmp (property_name, "limit") == 0)
1117     gtk_recent_chooser_set_limit (recent_chooser, gtk_recent_chooser_get_limit (action_chooser));
1118   else if (strcmp (property_name, "local-only") == 0)
1119     gtk_recent_chooser_set_local_only (recent_chooser, gtk_recent_chooser_get_local_only (action_chooser));
1120   else if (strcmp (property_name, "sort-type") == 0)
1121     gtk_recent_chooser_set_sort_type (recent_chooser, gtk_recent_chooser_get_sort_type (action_chooser));
1122   else if (strcmp (property_name, "filter") == 0)
1123     gtk_recent_chooser_set_filter (recent_chooser, gtk_recent_chooser_get_filter (action_chooser));
1124 }
1125
1126 void
1127 _gtk_recent_chooser_sync_action_properties (GtkActivatable *activatable,
1128                                             GtkAction      *action)
1129 {
1130   GtkRecentChooser *recent_chooser = GTK_RECENT_CHOOSER (activatable);
1131   GtkRecentChooser *action_chooser = GTK_RECENT_CHOOSER (action);
1132
1133   if (!action)
1134     return;
1135
1136   if (recent_chooser_has_show_numbers (recent_chooser))
1137     g_object_set (recent_chooser, "show-numbers", 
1138                   gtk_recent_action_get_show_numbers (GTK_RECENT_ACTION (action)),
1139                   NULL);
1140   gtk_recent_chooser_set_show_private (recent_chooser, gtk_recent_chooser_get_show_private (action_chooser));
1141   gtk_recent_chooser_set_show_not_found (recent_chooser, gtk_recent_chooser_get_show_not_found (action_chooser));
1142   gtk_recent_chooser_set_show_tips (recent_chooser, gtk_recent_chooser_get_show_tips (action_chooser));
1143   gtk_recent_chooser_set_show_icons (recent_chooser, gtk_recent_chooser_get_show_icons (action_chooser));
1144   gtk_recent_chooser_set_limit (recent_chooser, gtk_recent_chooser_get_limit (action_chooser));
1145   gtk_recent_chooser_set_local_only (recent_chooser, gtk_recent_chooser_get_local_only (action_chooser));
1146   gtk_recent_chooser_set_sort_type (recent_chooser, gtk_recent_chooser_get_sort_type (action_chooser));
1147   gtk_recent_chooser_set_filter (recent_chooser, gtk_recent_chooser_get_filter (action_chooser));
1148 }
1149
1150 void
1151 _gtk_recent_chooser_set_related_action (GtkRecentChooser *recent_chooser,
1152                                         GtkAction        *action)
1153 {
1154   GtkAction *prev_action;
1155
1156   prev_action = g_object_get_qdata (G_OBJECT (recent_chooser), quark_gtk_related_action);
1157
1158   if (prev_action == action)
1159     return;
1160
1161   gtk_activatable_do_set_related_action (GTK_ACTIVATABLE (recent_chooser), action);
1162   g_object_set_qdata (G_OBJECT (recent_chooser), quark_gtk_related_action, action);
1163 }
1164
1165 GtkAction *
1166 _gtk_recent_chooser_get_related_action (GtkRecentChooser *recent_chooser)
1167 {
1168   return g_object_get_qdata (G_OBJECT (recent_chooser), quark_gtk_related_action);
1169 }
1170
1171 /* The default for use-action-appearance is TRUE, so we try to set the
1172  * qdata backwards for this case.
1173  */
1174 void
1175 _gtk_recent_chooser_set_use_action_appearance (GtkRecentChooser *recent_chooser, 
1176                                                gboolean          use_appearance)
1177 {
1178   GtkAction *action;
1179   gboolean   use_action_appearance;
1180
1181   action                = g_object_get_qdata (G_OBJECT (recent_chooser), quark_gtk_related_action);
1182   use_action_appearance = !GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (recent_chooser), quark_gtk_use_action_appearance));
1183
1184   if (use_action_appearance != use_appearance)
1185     {
1186
1187       g_object_set_qdata (G_OBJECT (recent_chooser), quark_gtk_use_action_appearance, GINT_TO_POINTER (!use_appearance));
1188  
1189       gtk_activatable_sync_action_properties (GTK_ACTIVATABLE (recent_chooser), action);
1190     }
1191 }
1192
1193 gboolean
1194 _gtk_recent_chooser_get_use_action_appearance (GtkRecentChooser *recent_chooser)
1195 {
1196   return !GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (recent_chooser), quark_gtk_use_action_appearance));
1197 }
1198
1199 #define __GTK_RECENT_CHOOSER_C__
1200 #include "gtkaliasdef.c"