]> Pileus Git - ~andy/gtk/blob - gtk/gtkrecentchooserwidget.c
Merge branch 'windows_list'
[~andy/gtk] / gtk / gtkrecentchooserwidget.c
1 /* GTK - The GIMP Toolkit
2  * gtkrecentchooserwidget.c: embeddable recently used resources chooser widget
3  * Copyright (C) 2006 Emmanuele Bassi
4  * 
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.
9  *
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.
14  *
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.
19  */
20
21 #include "config.h"
22
23 #include "gtkrecentchooserwidget.h"
24 #include "gtkrecentchooserdefault.h"
25 #include "gtkrecentchooserutils.h"
26 #include "gtktypebuiltins.h"
27
28 /**
29  * SECTION:gtkrecentchooserwidget
30  * @Short_description: Displays recently used files
31  * @Title: GtkRecentChooserWidget
32  * @See_also:#GtkRecentChooser, #GtkRecentChooserDialog
33  *
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.
38  *
39  * Note that #GtkRecentChooserWidget does not have any methods of its own.
40  * Instead, you should use the functions that work on a #GtkRecentChooser.
41  *
42  * Recently used files are supported since GTK+ 2.10.
43  */
44
45
46 struct _GtkRecentChooserWidgetPrivate
47 {
48   GtkRecentManager *manager;
49   
50   GtkWidget *chooser;
51 };
52
53 #define GTK_RECENT_CHOOSER_WIDGET_GET_PRIVATE(obj)      (GTK_RECENT_CHOOSER_WIDGET (obj)->priv)
54
55 static GObject *gtk_recent_chooser_widget_constructor  (GType                  type,
56                                                         guint                  n_params,
57                                                         GObjectConstructParam *params);
58 static void     gtk_recent_chooser_widget_set_property (GObject               *object,
59                                                         guint                  prop_id,
60                                                         const GValue          *value,
61                                                         GParamSpec            *pspec);
62 static void     gtk_recent_chooser_widget_get_property (GObject               *object,
63                                                         guint                  prop_id,
64                                                         GValue                *value,
65                                                         GParamSpec            *pspec);
66 static void     gtk_recent_chooser_widget_finalize     (GObject               *object);
67
68
69 G_DEFINE_TYPE_WITH_CODE (GtkRecentChooserWidget,
70                          gtk_recent_chooser_widget,
71                          GTK_TYPE_VBOX,
72                          G_IMPLEMENT_INTERFACE (GTK_TYPE_RECENT_CHOOSER,
73                                                 _gtk_recent_chooser_delegate_iface_init))
74
75 static void
76 gtk_recent_chooser_widget_class_init (GtkRecentChooserWidgetClass *klass)
77 {
78   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
79
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;
84
85   _gtk_recent_chooser_install_properties (gobject_class);
86
87   g_type_class_add_private (klass, sizeof (GtkRecentChooserWidgetPrivate));
88 }
89
90
91 static void
92 gtk_recent_chooser_widget_init (GtkRecentChooserWidget *widget)
93 {
94   widget->priv = G_TYPE_INSTANCE_GET_PRIVATE (widget, GTK_TYPE_RECENT_CHOOSER_WIDGET,
95                                               GtkRecentChooserWidgetPrivate);
96 }
97
98 static GObject *
99 gtk_recent_chooser_widget_constructor (GType                  type,
100                                        guint                  n_params,
101                                        GObjectConstructParam *params)
102 {
103   GObject *object;
104   GtkRecentChooserWidgetPrivate *priv;
105
106   object = G_OBJECT_CLASS (gtk_recent_chooser_widget_parent_class)->constructor (type,
107                                                                                  n_params,
108                                                                                  params);
109
110   priv = GTK_RECENT_CHOOSER_WIDGET_GET_PRIVATE (object);
111   priv->chooser = _gtk_recent_chooser_default_new (priv->manager);
112   
113   
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));
118
119   return object;
120 }
121
122 static void
123 gtk_recent_chooser_widget_set_property (GObject      *object,
124                                         guint         prop_id,
125                                         const GValue *value,
126                                         GParamSpec   *pspec)
127 {
128   GtkRecentChooserWidgetPrivate *priv;
129
130   priv = GTK_RECENT_CHOOSER_WIDGET_GET_PRIVATE (object);
131   
132   switch (prop_id)
133     {
134     case GTK_RECENT_CHOOSER_PROP_RECENT_MANAGER:
135       priv->manager = g_value_get_object (value);
136       break;
137     default:
138       g_object_set_property (G_OBJECT (priv->chooser), pspec->name, value);
139       break;
140     }
141 }
142
143 static void
144 gtk_recent_chooser_widget_get_property (GObject    *object,
145                                         guint       prop_id,
146                                         GValue     *value,
147                                         GParamSpec *pspec)
148 {
149   GtkRecentChooserWidgetPrivate *priv;
150
151   priv = GTK_RECENT_CHOOSER_WIDGET_GET_PRIVATE (object);
152
153   g_object_get_property (G_OBJECT (priv->chooser), pspec->name, value);
154 }
155
156 static void
157 gtk_recent_chooser_widget_finalize (GObject *object)
158 {
159   GtkRecentChooserWidgetPrivate *priv;
160   
161   priv = GTK_RECENT_CHOOSER_WIDGET_GET_PRIVATE (object);
162   priv->manager = NULL;
163   
164   G_OBJECT_CLASS (gtk_recent_chooser_widget_parent_class)->finalize (object);
165 }
166
167 /*
168  * Public API
169  */
170
171 /**
172  * gtk_recent_chooser_widget_new:
173  * 
174  * Creates a new #GtkRecentChooserWidget object.  This is an embeddable widget
175  * used to access the recently used resources list.
176  *
177  * Return value: a new #GtkRecentChooserWidget
178  *
179  * Since: 2.10
180  */
181 GtkWidget *
182 gtk_recent_chooser_widget_new (void)
183 {
184   return g_object_new (GTK_TYPE_RECENT_CHOOSER_WIDGET, NULL);
185 }
186
187 /**
188  * gtk_recent_chooser_widget_new_for_manager:
189  * @manager: a #GtkRecentManager
190  *
191  * Creates a new #GtkRecentChooserWidget with a specified recent manager.
192  *
193  * This is useful if you have implemented your own recent manager, or if you
194  * have a customized instance of a #GtkRecentManager object.
195  *
196  * Return value: a new #GtkRecentChooserWidget
197  *
198  * Since: 2.10
199  */
200 GtkWidget *
201 gtk_recent_chooser_widget_new_for_manager (GtkRecentManager *manager)
202 {
203   g_return_val_if_fail (manager == NULL || GTK_IS_RECENT_MANAGER (manager), NULL);
204   
205   return g_object_new (GTK_TYPE_RECENT_CHOOSER_WIDGET,
206                        "recent-manager", manager,
207                        NULL);
208 }