]> Pileus Git - ~andy/gtk/blob - gtk/gtkfilechooserwidget.c
Updated Norwegian bokmål translation
[~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
32 /**
33  * SECTION:gtkfilechooserwidget
34  * @Short_description: File chooser widget that can be embedded in other widgets
35  * @Title: GtkFileChooserWidget
36  * @See_also: #GtkFileChooser, #GtkFileChooserDialog
37  *
38  * #GtkFileChooserWidget is a widget suitable for selecting files.
39  * It is the main building block of a #GtkFileChooserDialog.  Most
40  * applications will only need to use the latter; you can use
41  * #GtkFileChooserWidget as part of a larger window if you have
42  * special needs.
43  *
44  * Note that #GtkFileChooserWidget does not have any methods of its
45  * own.  Instead, you should use the functions that work on a
46  * #GtkFileChooser.
47  */
48
49
50 #define GTK_FILE_CHOOSER_WIDGET_GET_PRIVATE(o)  (GTK_FILE_CHOOSER_WIDGET (o)->priv)
51
52 static void gtk_file_chooser_widget_finalize     (GObject                   *object);
53
54 static GObject* gtk_file_chooser_widget_constructor  (GType                  type,
55                                                       guint                  n_construct_properties,
56                                                       GObjectConstructParam *construct_params);
57 static void     gtk_file_chooser_widget_set_property (GObject               *object,
58                                                       guint                  prop_id,
59                                                       const GValue          *value,
60                                                       GParamSpec            *pspec);
61 static void     gtk_file_chooser_widget_get_property (GObject               *object,
62                                                       guint                  prop_id,
63                                                       GValue                *value,
64                                                       GParamSpec            *pspec);
65
66 G_DEFINE_TYPE_WITH_CODE (GtkFileChooserWidget, gtk_file_chooser_widget, GTK_TYPE_VBOX,
67                          G_IMPLEMENT_INTERFACE (GTK_TYPE_FILE_CHOOSER,
68                                                 _gtk_file_chooser_delegate_iface_init)
69                          G_IMPLEMENT_INTERFACE (GTK_TYPE_FILE_CHOOSER_EMBED,
70                                                 _gtk_file_chooser_embed_delegate_iface_init))
71
72 static void
73 gtk_file_chooser_widget_class_init (GtkFileChooserWidgetClass *class)
74 {
75   GObjectClass *gobject_class = G_OBJECT_CLASS (class);
76
77   gobject_class->constructor = gtk_file_chooser_widget_constructor;
78   gobject_class->set_property = gtk_file_chooser_widget_set_property;
79   gobject_class->get_property = gtk_file_chooser_widget_get_property;
80   gobject_class->finalize = gtk_file_chooser_widget_finalize;
81
82   _gtk_file_chooser_install_properties (gobject_class);
83
84   g_type_class_add_private (class, sizeof (GtkFileChooserWidgetPrivate));
85 }
86
87 static void
88 gtk_file_chooser_widget_init (GtkFileChooserWidget *chooser_widget)
89 {
90   GtkFileChooserWidgetPrivate *priv = G_TYPE_INSTANCE_GET_PRIVATE (chooser_widget,
91                                                                    GTK_TYPE_FILE_CHOOSER_WIDGET,
92                                                                    GtkFileChooserWidgetPrivate);
93   chooser_widget->priv = priv;
94 }
95
96 static void
97 gtk_file_chooser_widget_finalize (GObject *object)
98 {
99   GtkFileChooserWidget *chooser = GTK_FILE_CHOOSER_WIDGET (object);
100
101   g_free (chooser->priv->file_system);
102
103   G_OBJECT_CLASS (gtk_file_chooser_widget_parent_class)->finalize (object);
104 }
105
106 static GObject*
107 gtk_file_chooser_widget_constructor (GType                  type,
108                                      guint                  n_construct_properties,
109                                      GObjectConstructParam *construct_params)
110 {
111   GtkFileChooserWidgetPrivate *priv;
112   GObject *object;
113   
114   object = G_OBJECT_CLASS (gtk_file_chooser_widget_parent_class)->constructor (type,
115                                                                                n_construct_properties,
116                                                                                construct_params);
117   priv = GTK_FILE_CHOOSER_WIDGET_GET_PRIVATE (object);
118
119   gtk_widget_push_composite_child ();
120
121   priv->impl = _gtk_file_chooser_default_new ();
122   
123   gtk_box_pack_start (GTK_BOX (object), priv->impl, TRUE, TRUE, 0);
124   gtk_widget_show (priv->impl);
125
126   _gtk_file_chooser_set_delegate (GTK_FILE_CHOOSER (object),
127                                   GTK_FILE_CHOOSER (priv->impl));
128
129   _gtk_file_chooser_embed_set_delegate (GTK_FILE_CHOOSER_EMBED (object),
130                                         GTK_FILE_CHOOSER_EMBED (priv->impl));
131   
132   gtk_widget_pop_composite_child ();
133
134   return object;
135 }
136
137 static void
138 gtk_file_chooser_widget_set_property (GObject         *object,
139                                       guint            prop_id,
140                                       const GValue    *value,
141                                       GParamSpec      *pspec)
142 {
143   GtkFileChooserWidgetPrivate *priv = GTK_FILE_CHOOSER_WIDGET_GET_PRIVATE (object);
144
145   switch (prop_id)
146     {
147     default:
148       g_object_set_property (G_OBJECT (priv->impl), pspec->name, value);
149       break;
150     }
151 }
152
153 static void
154 gtk_file_chooser_widget_get_property (GObject         *object,
155                                       guint            prop_id,
156                                       GValue          *value,
157                                       GParamSpec      *pspec)
158 {
159   GtkFileChooserWidgetPrivate *priv = GTK_FILE_CHOOSER_WIDGET_GET_PRIVATE (object);
160   
161   g_object_get_property (G_OBJECT (priv->impl), pspec->name, value);
162 }
163
164 /**
165  * gtk_file_chooser_widget_new:
166  * @action: Open or save mode for the widget
167  * 
168  * Creates a new #GtkFileChooserWidget.  This is a file chooser widget that can
169  * be embedded in custom windows, and it is the same widget that is used by
170  * #GtkFileChooserDialog.
171  * 
172  * Return value: a new #GtkFileChooserWidget
173  *
174  * Since: 2.4
175  **/
176 GtkWidget *
177 gtk_file_chooser_widget_new (GtkFileChooserAction action)
178 {
179   return g_object_new (GTK_TYPE_FILE_CHOOSER_WIDGET,
180                        "action", action,
181                        NULL);
182 }