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.
21 #include "gtkfilechooserwidget.h"
22 #include "gtkfilechooserimpldefault.h"
23 #include "gtkfilechooserenums.h"
24 #include "gtkfilechooserutils.h"
25 #include "gtkfilesystemunix.h"
27 struct _GtkFileChooserWidgetPrivate
31 GtkFileSystem *file_system;
34 #define GTK_FILE_CHOOSER_WIDGET_GET_PRIVATE(o) (GTK_FILE_CHOOSER_WIDGET (o)->priv)
36 static void gtk_file_chooser_widget_class_init (GtkFileChooserWidgetClass *class);
37 static void gtk_file_chooser_widget_init (GtkFileChooserWidget *chooser_widget);
39 static GObject* gtk_file_chooser_widget_constructor (GType type,
40 guint n_construct_properties,
41 GObjectConstructParam *construct_params);
42 static void gtk_file_chooser_widget_set_property (GObject *object,
46 static void gtk_file_chooser_widget_get_property (GObject *object,
51 static GObjectClass *parent_class;
54 gtk_file_chooser_widget_get_type (void)
56 static GType file_chooser_widget_type = 0;
58 if (!file_chooser_widget_type)
60 static const GTypeInfo file_chooser_widget_info =
62 sizeof (GtkFileChooserWidgetClass),
64 NULL, /* base_finalize */
65 (GClassInitFunc) gtk_file_chooser_widget_class_init,
66 NULL, /* class_finalize */
67 NULL, /* class_data */
68 sizeof (GtkFileChooserWidget),
70 (GInstanceInitFunc) gtk_file_chooser_widget_init,
73 static const GInterfaceInfo file_chooser_info =
75 (GInterfaceInitFunc) _gtk_file_chooser_delegate_iface_init, /* interface_init */
76 NULL, /* interface_finalize */
77 NULL /* interface_data */
80 file_chooser_widget_type = g_type_register_static (GTK_TYPE_VBOX, "GtkFileChooserWidget",
81 &file_chooser_widget_info, 0);
82 g_type_add_interface_static (file_chooser_widget_type,
83 GTK_TYPE_FILE_CHOOSER,
87 return file_chooser_widget_type;
91 gtk_file_chooser_widget_class_init (GtkFileChooserWidgetClass *class)
93 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
95 parent_class = g_type_class_peek_parent (class);
97 gobject_class->constructor = gtk_file_chooser_widget_constructor;
98 gobject_class->set_property = gtk_file_chooser_widget_set_property;
99 gobject_class->get_property = gtk_file_chooser_widget_get_property;
101 _gtk_file_chooser_install_properties (gobject_class);
103 g_type_class_add_private (class, sizeof (GtkFileChooserWidgetPrivate));
107 gtk_file_chooser_widget_init (GtkFileChooserWidget *chooser_widget)
109 GtkFileChooserWidgetPrivate *priv = G_TYPE_INSTANCE_GET_PRIVATE (chooser_widget,
110 GTK_TYPE_FILE_CHOOSER_WIDGET,
111 GtkFileChooserWidgetPrivate);
112 chooser_widget->priv = priv;
116 gtk_file_chooser_widget_constructor (GType type,
117 guint n_construct_properties,
118 GObjectConstructParam *construct_params)
120 GtkFileChooserWidgetPrivate *priv;
122 gchar *current_folder;
123 gchar *current_folder_uri;
125 object = parent_class->constructor (type,
126 n_construct_properties,
128 priv = GTK_FILE_CHOOSER_WIDGET_GET_PRIVATE (object);
130 gtk_widget_push_composite_child ();
132 if (!priv->file_system)
133 priv->file_system = gtk_file_system_unix_new ();
135 priv->impl = _gtk_file_chooser_impl_default_new (priv->file_system);
136 gtk_box_pack_start (GTK_BOX (object), priv->impl, TRUE, TRUE, 0);
137 gtk_widget_show (priv->impl);
139 current_folder = g_get_current_dir ();
140 current_folder_uri = g_filename_to_uri (current_folder, NULL, NULL);
141 if (current_folder_uri)
143 gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (priv->impl), current_folder_uri);
144 g_free (current_folder_uri);
146 g_free (current_folder);
148 _gtk_file_chooser_set_delegate (GTK_FILE_CHOOSER (object),
149 GTK_FILE_CHOOSER (priv->impl));
151 gtk_widget_pop_composite_child ();
157 gtk_file_chooser_widget_set_property (GObject *object,
162 GtkFileChooserWidgetPrivate *priv = GTK_FILE_CHOOSER_WIDGET_GET_PRIVATE (object);
166 case GTK_FILE_CHOOSER_PROP_FILE_SYSTEM:
168 GtkFileSystem *file_system = g_value_get_object (value);
169 if (priv->file_system != file_system)
171 if (priv->file_system)
172 g_object_unref (priv->file_system);
173 priv->file_system = file_system;
174 if (priv->file_system)
175 g_object_ref (priv->file_system);
180 g_object_set_property (G_OBJECT (priv->impl), pspec->name, value);
186 gtk_file_chooser_widget_get_property (GObject *object,
191 GtkFileChooserWidgetPrivate *priv = GTK_FILE_CHOOSER_WIDGET_GET_PRIVATE (object);
193 g_object_get_property (G_OBJECT (priv->impl), pspec->name, value);
197 gtk_file_chooser_widget_new (GtkFileChooserAction action)
199 return g_object_new (GTK_TYPE_FILE_CHOOSER_WIDGET,