1 /* GTK - The GIMP Toolkit
2 * gtkrecentchooserwidget.c: embeddable recently used resources chooser widget
3 * Copyright (C) 2006 Emmanuele Bassi
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
23 #include "gtkrecentchooserwidget.h"
24 #include "gtkrecentchooserdefault.h"
25 #include "gtkrecentchooserutils.h"
26 #include "gtktypebuiltins.h"
29 * SECTION:gtkrecentchooserwidget
30 * @Short_description: Displays recently used files
31 * @Title: GtkRecentChooserWidget
32 * @See_also:#GtkRecentChooser, #GtkRecentChooserDialog
34 * #GtkRecentChooserWidget is a widget suitable for selecting recently used
35 * files. It is the main building block of a #GtkRecentChooserDialog. Most
36 * applications will only need to use the latter; you can use
37 * #GtkRecentChooserWidget as part of a larger window if you have special needs.
39 * Note that #GtkRecentChooserWidget does not have any methods of its own.
40 * Instead, you should use the functions that work on a #GtkRecentChooser.
42 * Recently used files are supported since GTK+ 2.10.
46 struct _GtkRecentChooserWidgetPrivate
48 GtkRecentManager *manager;
53 #define GTK_RECENT_CHOOSER_WIDGET_GET_PRIVATE(obj) (GTK_RECENT_CHOOSER_WIDGET (obj)->priv)
55 static GObject *gtk_recent_chooser_widget_constructor (GType type,
57 GObjectConstructParam *params);
58 static void gtk_recent_chooser_widget_set_property (GObject *object,
62 static void gtk_recent_chooser_widget_get_property (GObject *object,
66 static void gtk_recent_chooser_widget_finalize (GObject *object);
69 G_DEFINE_TYPE_WITH_CODE (GtkRecentChooserWidget,
70 gtk_recent_chooser_widget,
72 G_IMPLEMENT_INTERFACE (GTK_TYPE_RECENT_CHOOSER,
73 _gtk_recent_chooser_delegate_iface_init))
76 gtk_recent_chooser_widget_class_init (GtkRecentChooserWidgetClass *klass)
78 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
80 gobject_class->constructor = gtk_recent_chooser_widget_constructor;
81 gobject_class->set_property = gtk_recent_chooser_widget_set_property;
82 gobject_class->get_property = gtk_recent_chooser_widget_get_property;
83 gobject_class->finalize = gtk_recent_chooser_widget_finalize;
85 _gtk_recent_chooser_install_properties (gobject_class);
87 g_type_class_add_private (klass, sizeof (GtkRecentChooserWidgetPrivate));
92 gtk_recent_chooser_widget_init (GtkRecentChooserWidget *widget)
94 widget->priv = G_TYPE_INSTANCE_GET_PRIVATE (widget, GTK_TYPE_RECENT_CHOOSER_WIDGET,
95 GtkRecentChooserWidgetPrivate);
99 gtk_recent_chooser_widget_constructor (GType type,
101 GObjectConstructParam *params)
104 GtkRecentChooserWidgetPrivate *priv;
106 object = G_OBJECT_CLASS (gtk_recent_chooser_widget_parent_class)->constructor (type,
110 priv = GTK_RECENT_CHOOSER_WIDGET_GET_PRIVATE (object);
111 priv->chooser = _gtk_recent_chooser_default_new (priv->manager);
114 gtk_container_add (GTK_CONTAINER (object), priv->chooser);
115 gtk_widget_show (priv->chooser);
116 _gtk_recent_chooser_set_delegate (GTK_RECENT_CHOOSER (object),
117 GTK_RECENT_CHOOSER (priv->chooser));
123 gtk_recent_chooser_widget_set_property (GObject *object,
128 GtkRecentChooserWidgetPrivate *priv;
130 priv = GTK_RECENT_CHOOSER_WIDGET_GET_PRIVATE (object);
134 case GTK_RECENT_CHOOSER_PROP_RECENT_MANAGER:
135 priv->manager = g_value_get_object (value);
138 g_object_set_property (G_OBJECT (priv->chooser), pspec->name, value);
144 gtk_recent_chooser_widget_get_property (GObject *object,
149 GtkRecentChooserWidgetPrivate *priv;
151 priv = GTK_RECENT_CHOOSER_WIDGET_GET_PRIVATE (object);
153 g_object_get_property (G_OBJECT (priv->chooser), pspec->name, value);
157 gtk_recent_chooser_widget_finalize (GObject *object)
159 GtkRecentChooserWidgetPrivate *priv;
161 priv = GTK_RECENT_CHOOSER_WIDGET_GET_PRIVATE (object);
162 priv->manager = NULL;
164 G_OBJECT_CLASS (gtk_recent_chooser_widget_parent_class)->finalize (object);
172 * gtk_recent_chooser_widget_new:
174 * Creates a new #GtkRecentChooserWidget object. This is an embeddable widget
175 * used to access the recently used resources list.
177 * Return value: a new #GtkRecentChooserWidget
182 gtk_recent_chooser_widget_new (void)
184 return g_object_new (GTK_TYPE_RECENT_CHOOSER_WIDGET, NULL);
188 * gtk_recent_chooser_widget_new_for_manager:
189 * @manager: a #GtkRecentManager
191 * Creates a new #GtkRecentChooserWidget with a specified recent manager.
193 * This is useful if you have implemented your own recent manager, or if you
194 * have a customized instance of a #GtkRecentManager object.
196 * Return value: a new #GtkRecentChooserWidget
201 gtk_recent_chooser_widget_new_for_manager (GtkRecentManager *manager)
203 g_return_val_if_fail (manager == NULL || GTK_IS_RECENT_MANAGER (manager), NULL);
205 return g_object_new (GTK_TYPE_RECENT_CHOOSER_WIDGET,
206 "recent-manager", manager,