]> Pileus Git - ~andy/gtk/blob - gtk/gtkfilechooserwidget.c
- Add GnomeVFS backend
[~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 "gtkfilechooserwidget.h"
22 #include "gtkfilechooserimpldefault.h"
23 #include "gtkfilechooserenums.h"
24 #include "gtkfilechooserutils.h"
25 #include "gtkfilesystemgnomevfs.h"
26 #include "gtkfilesystemunix.h"
27
28 struct _GtkFileChooserWidgetPrivate
29 {
30   GtkWidget *impl;
31 };
32
33 #define GTK_FILE_CHOOSER_WIDGET_GET_PRIVATE(o)  (GTK_FILE_CHOOSER_WIDGET (o)->priv)
34
35 static void gtk_file_chooser_widget_class_init   (GtkFileChooserWidgetClass *class);
36 static void gtk_file_chooser_widget_init         (GtkFileChooserWidget      *chooser_widget);
37 static void gtk_file_chooser_widget_set_property (GObject                   *object,
38                                                   guint                      prop_id,
39                                                   const GValue              *value,
40                                                   GParamSpec                *pspec);
41 static void gtk_file_chooser_widget_get_property (GObject                   *object,
42                                                   guint                      prop_id,
43                                                   GValue                    *value,
44                                                   GParamSpec                *pspec);
45
46 GType
47 gtk_file_chooser_widget_get_type (void)
48 {
49   static GType file_chooser_widget_type = 0;
50
51   if (!file_chooser_widget_type)
52     {
53       static const GTypeInfo file_chooser_widget_info =
54       {
55         sizeof (GtkFileChooserWidgetClass),
56         NULL,           /* base_init */
57         NULL,           /* base_finalize */
58         (GClassInitFunc) gtk_file_chooser_widget_class_init,
59         NULL,           /* class_finalize */
60         NULL,           /* class_data */
61         sizeof (GtkFileChooserWidget),
62         0,              /* n_preallocs */
63         (GInstanceInitFunc) gtk_file_chooser_widget_init,
64       };
65       
66       static const GInterfaceInfo file_chooser_info =
67       {
68         (GInterfaceInitFunc) _gtk_file_chooser_delegate_iface_init, /* interface_init */
69         NULL,                                                       /* interface_finalize */
70         NULL                                                        /* interface_data */
71       };
72
73       file_chooser_widget_type = g_type_register_static (GTK_TYPE_VBOX, "GtkFileChooserWidget",
74                                                          &file_chooser_widget_info, 0);
75       g_type_add_interface_static (file_chooser_widget_type,
76                                    GTK_TYPE_FILE_CHOOSER,
77                                    &file_chooser_info);
78     }
79
80   return file_chooser_widget_type;
81 }
82
83 static void
84 gtk_file_chooser_widget_class_init (GtkFileChooserWidgetClass *class)
85 {
86   GObjectClass *gobject_class = G_OBJECT_CLASS (class);
87
88   gobject_class->set_property = gtk_file_chooser_widget_set_property;
89   gobject_class->get_property = gtk_file_chooser_widget_get_property;
90
91   _gtk_file_chooser_install_properties (gobject_class);
92
93   g_type_class_add_private (class, sizeof (GtkFileChooserWidgetPrivate));
94 }
95
96 static void
97 gtk_file_chooser_widget_init (GtkFileChooserWidget *chooser_widget)
98 {
99   GtkFileChooserWidgetPrivate *priv = G_TYPE_INSTANCE_GET_PRIVATE (chooser_widget,
100                                                                    GTK_TYPE_FILE_CHOOSER_WIDGET,
101                                                                    GtkFileChooserWidgetPrivate);
102   gchar *current_folder;
103   gchar *current_folder_uri;
104   
105   chooser_widget->priv = priv;
106   
107   gtk_widget_push_composite_child ();
108
109   priv->impl = _gtk_file_chooser_impl_default_new (_gtk_file_system_gnome_vfs_new ());
110   gtk_box_pack_start (GTK_BOX (chooser_widget), priv->impl, TRUE, TRUE, 0);
111   gtk_widget_show (priv->impl);
112
113   current_folder = g_get_current_dir ();
114   current_folder_uri = g_filename_to_uri (current_folder, NULL, NULL);
115   if (current_folder_uri)
116     {
117       gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER (priv->impl), current_folder_uri);
118       g_free (current_folder_uri);
119     }
120   g_free (current_folder);
121   
122   _gtk_file_chooser_set_delegate (GTK_FILE_CHOOSER (chooser_widget),
123                                   GTK_FILE_CHOOSER (priv->impl));
124   
125   gtk_widget_pop_composite_child ();
126 }
127
128 static void
129 gtk_file_chooser_widget_set_property (GObject         *object,
130                                       guint            prop_id,
131                                       const GValue    *value,
132                                       GParamSpec      *pspec)
133 {
134   GtkFileChooserWidgetPrivate *priv = GTK_FILE_CHOOSER_WIDGET_GET_PRIVATE (object);
135   
136   g_object_set_property (G_OBJECT (priv->impl), pspec->name, value);
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 GtkWidget *
151 gtk_file_chooser_widget_new (GtkFileChooserAction action)
152 {
153   return g_object_new (GTK_TYPE_FILE_CHOOSER_WIDGET,
154                        "action", action,
155                        NULL);
156 }