]> Pileus Git - ~andy/gtk/blob - gtk/gtkfilechooserwidget.c
Practically everything changed.
[~andy/gtk] / gtk / gtkfilechooserwidget.c
1 /* GTK - The GTK+ 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 "gtkfilechooserprivate.h"
23
24 #include "gtkfilechooserwidget.h"
25 #include "gtkfilechooserdefault.h"
26 #include "gtkfilechooserutils.h"
27 #include "gtktypebuiltins.h"
28 #include "gtkfilechooserembed.h"
29 #include "gtkintl.h"
30 #include "gtkalias.h"
31
32 #define GTK_FILE_CHOOSER_WIDGET_GET_PRIVATE(o)  (GTK_FILE_CHOOSER_WIDGET (o)->priv)
33
34 static void gtk_file_chooser_widget_finalize     (GObject                   *object);
35
36 static GObject* gtk_file_chooser_widget_constructor  (GType                  type,
37                                                       guint                  n_construct_properties,
38                                                       GObjectConstructParam *construct_params);
39 static void     gtk_file_chooser_widget_set_property (GObject               *object,
40                                                       guint                  prop_id,
41                                                       const GValue          *value,
42                                                       GParamSpec            *pspec);
43 static void     gtk_file_chooser_widget_get_property (GObject               *object,
44                                                       guint                  prop_id,
45                                                       GValue                *value,
46                                                       GParamSpec            *pspec);
47
48 G_DEFINE_TYPE_WITH_CODE (GtkFileChooserWidget, gtk_file_chooser_widget, GTK_TYPE_VBOX,
49                          G_IMPLEMENT_INTERFACE (GTK_TYPE_FILE_CHOOSER,
50                                                 _gtk_file_chooser_delegate_iface_init)
51                          G_IMPLEMENT_INTERFACE (GTK_TYPE_FILE_CHOOSER_EMBED,
52                                                 _gtk_file_chooser_embed_delegate_iface_init))
53
54 static void
55 gtk_file_chooser_widget_class_init (GtkFileChooserWidgetClass *class)
56 {
57   GObjectClass *gobject_class = G_OBJECT_CLASS (class);
58
59   gobject_class->constructor = gtk_file_chooser_widget_constructor;
60   gobject_class->set_property = gtk_file_chooser_widget_set_property;
61   gobject_class->get_property = gtk_file_chooser_widget_get_property;
62   gobject_class->finalize = gtk_file_chooser_widget_finalize;
63
64   _gtk_file_chooser_install_properties (gobject_class);
65
66   g_type_class_add_private (class, sizeof (GtkFileChooserWidgetPrivate));
67 }
68
69 static void
70 gtk_file_chooser_widget_init (GtkFileChooserWidget *chooser_widget)
71 {
72   GtkFileChooserWidgetPrivate *priv = G_TYPE_INSTANCE_GET_PRIVATE (chooser_widget,
73                                                                    GTK_TYPE_FILE_CHOOSER_WIDGET,
74                                                                    GtkFileChooserWidgetPrivate);
75   chooser_widget->priv = priv;
76 }
77
78 static void
79 gtk_file_chooser_widget_finalize (GObject *object)
80 {
81   GtkFileChooserWidget *chooser = GTK_FILE_CHOOSER_WIDGET (object);
82
83   g_free (chooser->priv->file_system);
84
85   G_OBJECT_CLASS (gtk_file_chooser_widget_parent_class)->finalize (object);
86 }
87
88 static GObject*
89 gtk_file_chooser_widget_constructor (GType                  type,
90                                      guint                  n_construct_properties,
91                                      GObjectConstructParam *construct_params)
92 {
93   GtkFileChooserWidgetPrivate *priv;
94   GObject *object;
95   
96   object = G_OBJECT_CLASS (gtk_file_chooser_widget_parent_class)->constructor (type,
97                                                                                n_construct_properties,
98                                                                                construct_params);
99   priv = GTK_FILE_CHOOSER_WIDGET_GET_PRIVATE (object);
100
101   gtk_widget_push_composite_child ();
102
103   priv->impl = _gtk_file_chooser_default_new (priv->file_system);
104   
105   gtk_box_pack_start (GTK_BOX (object), priv->impl, TRUE, TRUE, 0);
106   gtk_widget_show (priv->impl);
107
108   _gtk_file_chooser_set_delegate (GTK_FILE_CHOOSER (object),
109                                   GTK_FILE_CHOOSER (priv->impl));
110
111   _gtk_file_chooser_embed_set_delegate (GTK_FILE_CHOOSER_EMBED (object),
112                                         GTK_FILE_CHOOSER_EMBED (priv->impl));
113   
114   gtk_widget_pop_composite_child ();
115
116   return object;
117 }
118
119 static void
120 gtk_file_chooser_widget_set_property (GObject         *object,
121                                       guint            prop_id,
122                                       const GValue    *value,
123                                       GParamSpec      *pspec)
124 {
125   GtkFileChooserWidgetPrivate *priv = GTK_FILE_CHOOSER_WIDGET_GET_PRIVATE (object);
126
127   switch (prop_id)
128     {
129     case GTK_FILE_CHOOSER_PROP_FILE_SYSTEM_BACKEND:
130       g_free (priv->file_system);
131       priv->file_system = g_value_dup_string (value);
132       break;
133     default:
134       g_object_set_property (G_OBJECT (priv->impl), pspec->name, value);
135       break;
136     }
137 }
138
139 static void
140 gtk_file_chooser_widget_get_property (GObject         *object,
141                                       guint            prop_id,
142                                       GValue          *value,
143                                       GParamSpec      *pspec)
144 {
145   GtkFileChooserWidgetPrivate *priv = GTK_FILE_CHOOSER_WIDGET_GET_PRIVATE (object);
146   
147   g_object_get_property (G_OBJECT (priv->impl), pspec->name, value);
148 }
149
150 /**
151  * gtk_file_chooser_widget_new:
152  * @action: Open or save mode for the widget
153  * 
154  * Creates a new #GtkFileChooserWidget.  This is a file chooser widget that can
155  * be embedded in custom windows, and it is the same widget that is used by
156  * #GtkFileChooserDialog.
157  * 
158  * Return value: a new #GtkFileChooserWidget
159  *
160  * Since: 2.4
161  **/
162 GtkWidget *
163 gtk_file_chooser_widget_new (GtkFileChooserAction action)
164 {
165   return g_object_new (GTK_TYPE_FILE_CHOOSER_WIDGET,
166                        "action", action,
167                        NULL);
168 }
169
170 /**
171  * gtk_file_chooser_widget_new_with_backend:
172  * @action: Open or save mode for the widget
173  * @backend: The name of the specific filesystem backend to use.
174  * 
175  * Creates a new #GtkFileChooserWidget with a specified backend.  This is
176  * especially useful if you use gtk_file_chooser_set_local_only() to allow
177  * non-local files.  This is a file chooser widget that can be embedded in
178  * custom windows and it is the same widget that is used by
179  * #GtkFileChooserDialog.
180  * 
181  * Return value: a new #GtkFileChooserWidget
182  *
183  * Since: 2.4
184  **/
185 GtkWidget *
186 gtk_file_chooser_widget_new_with_backend (GtkFileChooserAction  action,
187                                           const gchar          *backend)
188 {
189   return g_object_new (GTK_TYPE_FILE_CHOOSER_WIDGET,
190                        "action", action,
191                        "file-system-backend", backend,
192                        NULL);
193 }
194
195 #define __GTK_FILE_CHOOSER_WIDGET_C__
196 #include "gtkaliasdef.c"