1 /* GTK - The GIMP Toolkit
2 * gtkfilechooserwidget.c: Embeddable file selector widget
3 * Copyright (C) 2003, Red Hat, Inc.
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.
22 #include "gtkfilechooserprivate.h"
23 #include "gtkfilechooserwidget.h"
24 #include "gtkfilechooserdefault.h"
25 #include "gtkfilechooserutils.h"
26 #include "gtktypebuiltins.h"
27 #include "gtkfilechooserembed.h"
31 #define GTK_FILE_CHOOSER_WIDGET_GET_PRIVATE(o) (GTK_FILE_CHOOSER_WIDGET (o)->priv)
33 static void gtk_file_chooser_widget_class_init (GtkFileChooserWidgetClass *class);
34 static void gtk_file_chooser_widget_init (GtkFileChooserWidget *chooser_widget);
35 static void gtk_file_chooser_widget_finalize (GObject *object);
37 static GObject* gtk_file_chooser_widget_constructor (GType type,
38 guint n_construct_properties,
39 GObjectConstructParam *construct_params);
40 static void gtk_file_chooser_widget_set_property (GObject *object,
44 static void gtk_file_chooser_widget_get_property (GObject *object,
49 static GObjectClass *parent_class;
52 gtk_file_chooser_widget_get_type (void)
54 static GType file_chooser_widget_type = 0;
56 if (!file_chooser_widget_type)
58 static const GTypeInfo file_chooser_widget_info =
60 sizeof (GtkFileChooserWidgetClass),
62 NULL, /* base_finalize */
63 (GClassInitFunc) gtk_file_chooser_widget_class_init,
64 NULL, /* class_finalize */
65 NULL, /* class_data */
66 sizeof (GtkFileChooserWidget),
68 (GInstanceInitFunc) gtk_file_chooser_widget_init,
71 static const GInterfaceInfo file_chooser_info =
73 (GInterfaceInitFunc) _gtk_file_chooser_delegate_iface_init, /* interface_init */
74 NULL, /* interface_finalize */
75 NULL /* interface_data */
78 static const GInterfaceInfo file_chooser_embed_info =
80 (GInterfaceInitFunc) _gtk_file_chooser_embed_delegate_iface_init, /* interface_init */
81 NULL, /* interface_finalize */
82 NULL /* interface_data */
85 file_chooser_widget_type = g_type_register_static (GTK_TYPE_VBOX, I_("GtkFileChooserWidget"),
86 &file_chooser_widget_info, 0);
88 g_type_add_interface_static (file_chooser_widget_type,
89 GTK_TYPE_FILE_CHOOSER,
91 g_type_add_interface_static (file_chooser_widget_type,
92 GTK_TYPE_FILE_CHOOSER_EMBED,
93 &file_chooser_embed_info);
96 return file_chooser_widget_type;
100 gtk_file_chooser_widget_class_init (GtkFileChooserWidgetClass *class)
102 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
104 parent_class = g_type_class_peek_parent (class);
106 gobject_class->constructor = gtk_file_chooser_widget_constructor;
107 gobject_class->set_property = gtk_file_chooser_widget_set_property;
108 gobject_class->get_property = gtk_file_chooser_widget_get_property;
109 gobject_class->finalize = gtk_file_chooser_widget_finalize;
111 _gtk_file_chooser_install_properties (gobject_class);
113 g_type_class_add_private (class, sizeof (GtkFileChooserWidgetPrivate));
117 gtk_file_chooser_widget_init (GtkFileChooserWidget *chooser_widget)
119 GtkFileChooserWidgetPrivate *priv = G_TYPE_INSTANCE_GET_PRIVATE (chooser_widget,
120 GTK_TYPE_FILE_CHOOSER_WIDGET,
121 GtkFileChooserWidgetPrivate);
122 chooser_widget->priv = priv;
126 gtk_file_chooser_widget_finalize (GObject *object)
128 GtkFileChooserWidget *chooser = GTK_FILE_CHOOSER_WIDGET (object);
130 g_free (chooser->priv->file_system);
132 G_OBJECT_CLASS (parent_class)->finalize (object);
136 gtk_file_chooser_widget_constructor (GType type,
137 guint n_construct_properties,
138 GObjectConstructParam *construct_params)
140 GtkFileChooserWidgetPrivate *priv;
142 gchar *current_folder;
144 object = parent_class->constructor (type,
145 n_construct_properties,
147 priv = GTK_FILE_CHOOSER_WIDGET_GET_PRIVATE (object);
149 gtk_widget_push_composite_child ();
151 priv->impl = _gtk_file_chooser_default_new (priv->file_system);
153 gtk_box_pack_start (GTK_BOX (object), priv->impl, TRUE, TRUE, 0);
154 gtk_widget_show (priv->impl);
156 current_folder = g_get_current_dir ();
157 gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (priv->impl), current_folder);
158 g_free (current_folder);
160 _gtk_file_chooser_set_delegate (GTK_FILE_CHOOSER (object),
161 GTK_FILE_CHOOSER (priv->impl));
163 _gtk_file_chooser_embed_set_delegate (GTK_FILE_CHOOSER_EMBED (object),
164 GTK_FILE_CHOOSER_EMBED (priv->impl));
166 gtk_widget_pop_composite_child ();
172 gtk_file_chooser_widget_set_property (GObject *object,
177 GtkFileChooserWidgetPrivate *priv = GTK_FILE_CHOOSER_WIDGET_GET_PRIVATE (object);
181 case GTK_FILE_CHOOSER_PROP_FILE_SYSTEM_BACKEND:
182 g_free (priv->file_system);
183 priv->file_system = g_value_dup_string (value);
186 g_object_set_property (G_OBJECT (priv->impl), pspec->name, value);
192 gtk_file_chooser_widget_get_property (GObject *object,
197 GtkFileChooserWidgetPrivate *priv = GTK_FILE_CHOOSER_WIDGET_GET_PRIVATE (object);
199 g_object_get_property (G_OBJECT (priv->impl), pspec->name, value);
203 * gtk_file_chooser_widget_new:
204 * @action: Open or save mode for the widget
206 * Creates a new #GtkFileChooserWidget. This is a file chooser widget that can
207 * be embedded in custom windows, and it is the same widget that is used by
208 * #GtkFileChooserDialog.
210 * Return value: a new #GtkFileChooserWidget
215 gtk_file_chooser_widget_new (GtkFileChooserAction action)
217 return g_object_new (GTK_TYPE_FILE_CHOOSER_WIDGET,
223 * gtk_file_chooser_widget_new_with_backend:
224 * @action: Open or save mode for the widget
225 * @backend: The name of the specific filesystem backend to use.
227 * Creates a new #GtkFileChooserWidget with a specified backend. This is
228 * especially useful if you use gtk_file_chooser_set_local_only() to allow
229 * non-local files. This is a file chooser widget that can be embedded in
230 * custom windows and it is the same widget that is used by
231 * #GtkFileChooserDialog.
233 * Return value: a new #GtkFileChooserWidget
238 gtk_file_chooser_widget_new_with_backend (GtkFileChooserAction action,
239 const gchar *backend)
241 return g_object_new (GTK_TYPE_FILE_CHOOSER_WIDGET,
243 "file-system-backend", backend,
247 #define __GTK_FILE_CHOOSER_WIDGET_C__
248 #include "gtkaliasdef.c"