]> Pileus Git - ~andy/gtk/blob - gtk/gtkfilechooserwidget.c
Add hidden aliases for exported symbols which are used internally in order
[~andy/gtk] / gtk / gtkfilechooserwidget.c
1 /* GTK - The GIMP Toolkit
2  * gtkfilechooserwidget.c: Embeddable file selector widget
3  * Copyright (C) 2003, Red Hat, Inc.
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 #include "gtkalias.h"
23 #include "gtkfilechooserwidget.h"
24 #include "gtkfilechooserdefault.h"
25 #include "gtkfilechooserutils.h"
26 #include "gtktypebuiltins.h"
27 #include "gtkfilechooserembed.h"
28
29 struct _GtkFileChooserWidgetPrivate
30 {
31   GtkWidget *impl;
32
33   char *file_system;
34 };
35
36 #define GTK_FILE_CHOOSER_WIDGET_GET_PRIVATE(o)  (GTK_FILE_CHOOSER_WIDGET (o)->priv)
37
38 static void gtk_file_chooser_widget_class_init   (GtkFileChooserWidgetClass *class);
39 static void gtk_file_chooser_widget_init         (GtkFileChooserWidget      *chooser_widget);
40 static void gtk_file_chooser_widget_finalize     (GObject                   *object);
41
42 static GObject* gtk_file_chooser_widget_constructor  (GType                  type,
43                                                       guint                  n_construct_properties,
44                                                       GObjectConstructParam *construct_params);
45 static void     gtk_file_chooser_widget_set_property (GObject               *object,
46                                                       guint                  prop_id,
47                                                       const GValue          *value,
48                                                       GParamSpec            *pspec);
49 static void     gtk_file_chooser_widget_get_property (GObject               *object,
50                                                       guint                  prop_id,
51                                                       GValue                *value,
52                                                       GParamSpec            *pspec);
53
54 static GObjectClass *parent_class;
55
56 GType
57 gtk_file_chooser_widget_get_type (void)
58 {
59   static GType file_chooser_widget_type = 0;
60
61   if (!file_chooser_widget_type)
62     {
63       static const GTypeInfo file_chooser_widget_info =
64       {
65         sizeof (GtkFileChooserWidgetClass),
66         NULL,           /* base_init */
67         NULL,           /* base_finalize */
68         (GClassInitFunc) gtk_file_chooser_widget_class_init,
69         NULL,           /* class_finalize */
70         NULL,           /* class_data */
71         sizeof (GtkFileChooserWidget),
72         0,              /* n_preallocs */
73         (GInstanceInitFunc) gtk_file_chooser_widget_init,
74       };
75       
76       static const GInterfaceInfo file_chooser_info =
77       {
78         (GInterfaceInitFunc) _gtk_file_chooser_delegate_iface_init, /* interface_init */
79         NULL,                                                       /* interface_finalize */
80         NULL                                                        /* interface_data */
81       };
82
83       static const GInterfaceInfo file_chooser_embed_info =
84       {
85         (GInterfaceInitFunc) _gtk_file_chooser_embed_delegate_iface_init, /* interface_init */
86         NULL,                                                             /* interface_finalize */
87         NULL                                                              /* interface_data */
88       };
89
90       file_chooser_widget_type = g_type_register_static (GTK_TYPE_VBOX, "GtkFileChooserWidget",
91                                                          &file_chooser_widget_info, 0);
92
93       g_type_add_interface_static (file_chooser_widget_type,
94                                    GTK_TYPE_FILE_CHOOSER,
95                                    &file_chooser_info);
96       g_type_add_interface_static (file_chooser_widget_type,
97                                    GTK_TYPE_FILE_CHOOSER_EMBED,
98                                    &file_chooser_embed_info);
99     }
100
101   return file_chooser_widget_type;
102 }
103
104 static void
105 gtk_file_chooser_widget_class_init (GtkFileChooserWidgetClass *class)
106 {
107   GObjectClass *gobject_class = G_OBJECT_CLASS (class);
108
109   parent_class = g_type_class_peek_parent (class);
110
111   gobject_class->constructor = gtk_file_chooser_widget_constructor;
112   gobject_class->set_property = gtk_file_chooser_widget_set_property;
113   gobject_class->get_property = gtk_file_chooser_widget_get_property;
114   gobject_class->finalize = gtk_file_chooser_widget_finalize;
115
116   _gtk_file_chooser_install_properties (gobject_class);
117
118   g_type_class_add_private (class, sizeof (GtkFileChooserWidgetPrivate));
119 }
120
121 static void
122 gtk_file_chooser_widget_init (GtkFileChooserWidget *chooser_widget)
123 {
124   GtkFileChooserWidgetPrivate *priv = G_TYPE_INSTANCE_GET_PRIVATE (chooser_widget,
125                                                                    GTK_TYPE_FILE_CHOOSER_WIDGET,
126                                                                    GtkFileChooserWidgetPrivate);
127   chooser_widget->priv = priv;
128 }
129
130 static void
131 gtk_file_chooser_widget_finalize (GObject *object)
132 {
133   GtkFileChooserWidget *chooser = GTK_FILE_CHOOSER_WIDGET (object);
134
135   g_free (chooser->priv->file_system);
136
137   G_OBJECT_CLASS (parent_class)->finalize (object);
138 }
139
140 static GObject*
141 gtk_file_chooser_widget_constructor (GType                  type,
142                                      guint                  n_construct_properties,
143                                      GObjectConstructParam *construct_params)
144 {
145   GtkFileChooserWidgetPrivate *priv;
146   GObject *object;
147   gchar *current_folder;
148   
149   object = parent_class->constructor (type,
150                                       n_construct_properties,
151                                       construct_params);
152   priv = GTK_FILE_CHOOSER_WIDGET_GET_PRIVATE (object);
153
154   gtk_widget_push_composite_child ();
155
156   priv->impl = _gtk_file_chooser_default_new (priv->file_system);
157   
158   gtk_box_pack_start (GTK_BOX (object), priv->impl, TRUE, TRUE, 0);
159   gtk_widget_show (priv->impl);
160
161   current_folder = g_get_current_dir ();
162   gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (priv->impl), current_folder);
163   g_free (current_folder);
164   
165   _gtk_file_chooser_set_delegate (GTK_FILE_CHOOSER (object),
166                                   GTK_FILE_CHOOSER (priv->impl));
167
168   _gtk_file_chooser_embed_set_delegate (GTK_FILE_CHOOSER_EMBED (object),
169                                         GTK_FILE_CHOOSER_EMBED (priv->impl));
170   
171   gtk_widget_pop_composite_child ();
172
173   return object;
174 }
175
176 static void
177 gtk_file_chooser_widget_set_property (GObject         *object,
178                                       guint            prop_id,
179                                       const GValue    *value,
180                                       GParamSpec      *pspec)
181 {
182   GtkFileChooserWidgetPrivate *priv = GTK_FILE_CHOOSER_WIDGET_GET_PRIVATE (object);
183
184   switch (prop_id)
185     {
186     case GTK_FILE_CHOOSER_PROP_FILE_SYSTEM_BACKEND:
187       g_free (priv->file_system);
188       priv->file_system = g_value_dup_string (value);
189       break;
190     default:
191       g_object_set_property (G_OBJECT (priv->impl), pspec->name, value);
192       break;
193     }
194 }
195
196 static void
197 gtk_file_chooser_widget_get_property (GObject         *object,
198                                       guint            prop_id,
199                                       GValue          *value,
200                                       GParamSpec      *pspec)
201 {
202   GtkFileChooserWidgetPrivate *priv = GTK_FILE_CHOOSER_WIDGET_GET_PRIVATE (object);
203   
204   g_object_get_property (G_OBJECT (priv->impl), pspec->name, value);
205 }
206
207 /**
208  * gtk_file_chooser_widget_new:
209  * @action: Open or save mode for the widget
210  * 
211  * Creates a new #GtkFileChooserWidget.  This is a file chooser widget that can
212  * be embedded in custom windows, and it is the same widget that is used by
213  * #GtkFileChooserDialog.
214  * 
215  * Return value: a new #GtkFileChooserWidget
216  *
217  * Since: 2.4
218  **/
219 GtkWidget *
220 gtk_file_chooser_widget_new (GtkFileChooserAction action)
221 {
222   return g_object_new (GTK_TYPE_FILE_CHOOSER_WIDGET,
223                        "action", action,
224                        NULL);
225 }
226
227 /**
228  * gtk_file_chooser_widget_new_with_backend:
229  * @action: Open or save mode for the widget
230  * @backend: The name of the specific filesystem backend to use.
231  * 
232  * Creates a new #GtkFileChooserWidget with a specified backend.  This is
233  * especially useful if you use gtk_file_chooser_set_local_only() to allow
234  * non-local files.  This is a file chooser widget that can be embedded in
235  * custom windows and it is the same widget that is used by
236  * #GtkFileChooserDialog.
237  * 
238  * Return value: a new #GtkFileChooserWidget
239  *
240  * Since: 2.4
241  **/
242 GtkWidget *
243 gtk_file_chooser_widget_new_with_backend (GtkFileChooserAction  action,
244                                           const gchar          *backend)
245 {
246   return g_object_new (GTK_TYPE_FILE_CHOOSER_WIDGET,
247                        "action", action,
248                        "file-system-backend", backend,
249                        NULL);
250 }