]> Pileus Git - ~andy/gtk/blob - gtk/gtkfilechooserwidget.c
Updated galician translations
[~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 "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
31 #define GTK_FILE_CHOOSER_WIDGET_GET_PRIVATE(o)  (GTK_FILE_CHOOSER_WIDGET (o)->priv)
32
33 static void gtk_file_chooser_widget_finalize     (GObject                   *object);
34
35 static GObject* gtk_file_chooser_widget_constructor  (GType                  type,
36                                                       guint                  n_construct_properties,
37                                                       GObjectConstructParam *construct_params);
38 static void     gtk_file_chooser_widget_set_property (GObject               *object,
39                                                       guint                  prop_id,
40                                                       const GValue          *value,
41                                                       GParamSpec            *pspec);
42 static void     gtk_file_chooser_widget_get_property (GObject               *object,
43                                                       guint                  prop_id,
44                                                       GValue                *value,
45                                                       GParamSpec            *pspec);
46
47 G_DEFINE_TYPE_WITH_CODE (GtkFileChooserWidget, gtk_file_chooser_widget, GTK_TYPE_VBOX,
48                          G_IMPLEMENT_INTERFACE (GTK_TYPE_FILE_CHOOSER,
49                                                 _gtk_file_chooser_delegate_iface_init)
50                          G_IMPLEMENT_INTERFACE (GTK_TYPE_FILE_CHOOSER_EMBED,
51                                                 _gtk_file_chooser_embed_delegate_iface_init))
52
53 static void
54 gtk_file_chooser_widget_class_init (GtkFileChooserWidgetClass *class)
55 {
56   GObjectClass *gobject_class = G_OBJECT_CLASS (class);
57
58   gobject_class->constructor = gtk_file_chooser_widget_constructor;
59   gobject_class->set_property = gtk_file_chooser_widget_set_property;
60   gobject_class->get_property = gtk_file_chooser_widget_get_property;
61   gobject_class->finalize = gtk_file_chooser_widget_finalize;
62
63   _gtk_file_chooser_install_properties (gobject_class);
64
65   g_type_class_add_private (class, sizeof (GtkFileChooserWidgetPrivate));
66 }
67
68 static void
69 gtk_file_chooser_widget_init (GtkFileChooserWidget *chooser_widget)
70 {
71   GtkFileChooserWidgetPrivate *priv = G_TYPE_INSTANCE_GET_PRIVATE (chooser_widget,
72                                                                    GTK_TYPE_FILE_CHOOSER_WIDGET,
73                                                                    GtkFileChooserWidgetPrivate);
74   chooser_widget->priv = priv;
75 }
76
77 static void
78 gtk_file_chooser_widget_finalize (GObject *object)
79 {
80   GtkFileChooserWidget *chooser = GTK_FILE_CHOOSER_WIDGET (object);
81
82   g_free (chooser->priv->file_system);
83
84   G_OBJECT_CLASS (gtk_file_chooser_widget_parent_class)->finalize (object);
85 }
86
87 static GObject*
88 gtk_file_chooser_widget_constructor (GType                  type,
89                                      guint                  n_construct_properties,
90                                      GObjectConstructParam *construct_params)
91 {
92   GtkFileChooserWidgetPrivate *priv;
93   GObject *object;
94   
95   object = G_OBJECT_CLASS (gtk_file_chooser_widget_parent_class)->constructor (type,
96                                                                                n_construct_properties,
97                                                                                construct_params);
98   priv = GTK_FILE_CHOOSER_WIDGET_GET_PRIVATE (object);
99
100   gtk_widget_push_composite_child ();
101
102   priv->impl = _gtk_file_chooser_default_new ();
103   
104   gtk_box_pack_start (GTK_BOX (object), priv->impl, TRUE, TRUE, 0);
105   gtk_widget_show (priv->impl);
106
107   _gtk_file_chooser_set_delegate (GTK_FILE_CHOOSER (object),
108                                   GTK_FILE_CHOOSER (priv->impl));
109
110   _gtk_file_chooser_embed_set_delegate (GTK_FILE_CHOOSER_EMBED (object),
111                                         GTK_FILE_CHOOSER_EMBED (priv->impl));
112   
113   gtk_widget_pop_composite_child ();
114
115   return object;
116 }
117
118 static void
119 gtk_file_chooser_widget_set_property (GObject         *object,
120                                       guint            prop_id,
121                                       const GValue    *value,
122                                       GParamSpec      *pspec)
123 {
124   GtkFileChooserWidgetPrivate *priv = GTK_FILE_CHOOSER_WIDGET_GET_PRIVATE (object);
125
126   switch (prop_id)
127     {
128     default:
129       g_object_set_property (G_OBJECT (priv->impl), pspec->name, value);
130       break;
131     }
132 }
133
134 static void
135 gtk_file_chooser_widget_get_property (GObject         *object,
136                                       guint            prop_id,
137                                       GValue          *value,
138                                       GParamSpec      *pspec)
139 {
140   GtkFileChooserWidgetPrivate *priv = GTK_FILE_CHOOSER_WIDGET_GET_PRIVATE (object);
141   
142   g_object_get_property (G_OBJECT (priv->impl), pspec->name, value);
143 }
144
145 /**
146  * gtk_file_chooser_widget_new:
147  * @action: Open or save mode for the widget
148  * 
149  * Creates a new #GtkFileChooserWidget.  This is a file chooser widget that can
150  * be embedded in custom windows, and it is the same widget that is used by
151  * #GtkFileChooserDialog.
152  * 
153  * Return value: a new #GtkFileChooserWidget
154  *
155  * Since: 2.4
156  **/
157 GtkWidget *
158 gtk_file_chooser_widget_new (GtkFileChooserAction action)
159 {
160   return g_object_new (GTK_TYPE_FILE_CHOOSER_WIDGET,
161                        "action", action,
162                        NULL);
163 }