1 /* gtkrecentchooserutils.h - Private utility functions for implementing a
2 * GtkRecentChooser interface
4 * Copyright (C) 2006 Emmanuele Bassi
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
23 * Based on gtkfilechooserutils.c:
24 * Copyright (C) 2003 Red Hat, Inc.
29 #include "gtkrecentchooserutils.h"
32 static void delegate_set_sort_func (GtkRecentChooser *chooser,
33 GtkRecentSortFunc sort_func,
35 GDestroyNotify data_destroy);
36 static void delegate_add_filter (GtkRecentChooser *chooser,
37 GtkRecentFilter *filter);
38 static void delegate_remove_filter (GtkRecentChooser *chooser,
39 GtkRecentFilter *filter);
40 static GSList *delegate_list_filters (GtkRecentChooser *chooser);
41 static gboolean delegate_select_uri (GtkRecentChooser *chooser,
44 static void delegate_unselect_uri (GtkRecentChooser *chooser,
46 static GList *delegate_get_items (GtkRecentChooser *chooser);
47 static GtkRecentManager *delegate_get_recent_manager (GtkRecentChooser *chooser);
48 static void delegate_select_all (GtkRecentChooser *chooser);
49 static void delegate_unselect_all (GtkRecentChooser *chooser);
50 static gboolean delegate_set_current_uri (GtkRecentChooser *chooser,
53 static gchar * delegate_get_current_uri (GtkRecentChooser *chooser);
56 static void delegate_notify (GObject *object,
59 static void delegate_selection_changed (GtkRecentChooser *receiver,
61 static void delegate_item_activated (GtkRecentChooser *receiver,
65 * _gtk_recent_chooser_install_properties:
66 * @klass: the class structure for a type deriving from #GObject
68 * Installs the necessary properties for a class implementing
69 * #GtkRecentChooser. A #GtkParamSpecOverride property is installed
70 * for each property, using the values from the #GtkRecentChooserProp
71 * enumeration. The caller must make sure itself that the enumeration
72 * values don't collide with some other property values they
76 _gtk_recent_chooser_install_properties (GObjectClass *klass)
78 g_object_class_override_property (klass,
79 GTK_RECENT_CHOOSER_PROP_RECENT_MANAGER,
81 g_object_class_override_property (klass,
82 GTK_RECENT_CHOOSER_PROP_SHOW_PRIVATE,
84 g_object_class_override_property (klass,
85 GTK_RECENT_CHOOSER_PROP_SHOW_TIPS,
87 g_object_class_override_property (klass,
88 GTK_RECENT_CHOOSER_PROP_SHOW_ICONS,
90 g_object_class_override_property (klass,
91 GTK_RECENT_CHOOSER_PROP_SHOW_NOT_FOUND,
93 g_object_class_override_property (klass,
94 GTK_RECENT_CHOOSER_PROP_SELECT_MULTIPLE,
96 g_object_class_override_property (klass,
97 GTK_RECENT_CHOOSER_PROP_LIMIT,
99 g_object_class_override_property (klass,
100 GTK_RECENT_CHOOSER_PROP_LOCAL_ONLY,
102 g_object_class_override_property (klass,
103 GTK_RECENT_CHOOSER_PROP_SORT_TYPE,
105 g_object_class_override_property (klass,
106 GTK_RECENT_CHOOSER_PROP_FILTER,
111 * _gtk_recent_chooser_delegate_iface_init:
112 * @iface: a #GtkRecentChooserIface
114 * An interface-initialization function for use in cases where
115 * an object is simply delegating the methods, signals of
116 * the #GtkRecentChooser interface to another object.
117 * _gtk_recent_chooser_set_delegate() must be called on each
118 * instance of the object so that the delegate object can
122 _gtk_recent_chooser_delegate_iface_init (GtkRecentChooserIface *iface)
124 iface->set_current_uri = delegate_set_current_uri;
125 iface->get_current_uri = delegate_get_current_uri;
126 iface->select_uri = delegate_select_uri;
127 iface->unselect_uri = delegate_unselect_uri;
128 iface->select_all = delegate_select_all;
129 iface->unselect_all = delegate_unselect_all;
130 iface->get_items = delegate_get_items;
131 iface->get_recent_manager = delegate_get_recent_manager;
132 iface->set_sort_func = delegate_set_sort_func;
133 iface->add_filter = delegate_add_filter;
134 iface->remove_filter = delegate_remove_filter;
135 iface->list_filters = delegate_list_filters;
139 * _gtk_recent_chooser_set_delegate:
140 * @receiver: a #GObject implementing #GtkRecentChooser
141 * @delegate: another #GObject implementing #GtkRecentChooser
143 * Establishes that calls on @receiver for #GtkRecentChooser
144 * methods should be delegated to @delegate, and that
145 * #GtkRecentChooser signals emitted on @delegate should be
146 * forwarded to @receiver. Must be used in conjunction with
147 * _gtk_recent_chooser_delegate_iface_init().
150 _gtk_recent_chooser_set_delegate (GtkRecentChooser *receiver,
151 GtkRecentChooser *delegate)
153 g_return_if_fail (GTK_IS_RECENT_CHOOSER (receiver));
154 g_return_if_fail (GTK_IS_RECENT_CHOOSER (delegate));
156 g_object_set_data (G_OBJECT (receiver),
157 "gtk-recent-chooser-delegate", delegate);
159 g_signal_connect (delegate, "notify",
160 G_CALLBACK (delegate_notify), receiver);
161 g_signal_connect (delegate, "selection-changed",
162 G_CALLBACK (delegate_selection_changed), receiver);
163 g_signal_connect (delegate, "item_activated",
164 G_CALLBACK (delegate_item_activated), receiver);
168 _gtk_recent_chooser_delegate_get_quark (void)
170 static GQuark quark = 0;
172 if (G_UNLIKELY (quark == 0))
173 quark = g_quark_from_static_string ("gtk-recent-chooser-delegate");
178 static GtkRecentChooser *
179 get_delegate (GtkRecentChooser *receiver)
181 return g_object_get_qdata (G_OBJECT (receiver),
182 GTK_RECENT_CHOOSER_DELEGATE_QUARK);
186 delegate_set_sort_func (GtkRecentChooser *chooser,
187 GtkRecentSortFunc sort_func,
189 GDestroyNotify data_destroy)
191 gtk_recent_chooser_set_sort_func (get_delegate (chooser),
198 delegate_add_filter (GtkRecentChooser *chooser,
199 GtkRecentFilter *filter)
201 gtk_recent_chooser_add_filter (get_delegate (chooser), filter);
205 delegate_remove_filter (GtkRecentChooser *chooser,
206 GtkRecentFilter *filter)
208 gtk_recent_chooser_remove_filter (get_delegate (chooser), filter);
212 delegate_list_filters (GtkRecentChooser *chooser)
214 return gtk_recent_chooser_list_filters (get_delegate (chooser));
218 delegate_select_uri (GtkRecentChooser *chooser,
222 return gtk_recent_chooser_select_uri (get_delegate (chooser), uri, error);
226 delegate_unselect_uri (GtkRecentChooser *chooser,
229 gtk_recent_chooser_unselect_uri (get_delegate (chooser), uri);
233 delegate_get_items (GtkRecentChooser *chooser)
235 return gtk_recent_chooser_get_items (get_delegate (chooser));
238 static GtkRecentManager *
239 delegate_get_recent_manager (GtkRecentChooser *chooser)
241 return _gtk_recent_chooser_get_recent_manager (get_delegate (chooser));
245 delegate_select_all (GtkRecentChooser *chooser)
247 gtk_recent_chooser_select_all (get_delegate (chooser));
251 delegate_unselect_all (GtkRecentChooser *chooser)
253 gtk_recent_chooser_unselect_all (get_delegate (chooser));
257 delegate_set_current_uri (GtkRecentChooser *chooser,
261 return gtk_recent_chooser_set_current_uri (get_delegate (chooser), uri, error);
265 delegate_get_current_uri (GtkRecentChooser *chooser)
267 return gtk_recent_chooser_get_current_uri (get_delegate (chooser));
271 delegate_notify (GObject *object,
277 iface = g_type_interface_peek (g_type_class_peek (G_OBJECT_TYPE (object)),
278 gtk_recent_chooser_get_type ());
279 if (g_object_interface_find_property (iface, pspec->name))
280 g_object_notify (user_data, pspec->name);
284 delegate_selection_changed (GtkRecentChooser *receiver,
287 _gtk_recent_chooser_selection_changed (GTK_RECENT_CHOOSER (user_data));
291 delegate_item_activated (GtkRecentChooser *receiver,
294 _gtk_recent_chooser_item_activated (GTK_RECENT_CHOOSER (user_data));