1 /* GTK - The GIMP Toolkit
2 * gtkfilechooserdialog.c: File selector dialog
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 "gtkfilechooserdialog.h"
22 #include "gtkfilechooserwidget.h"
23 #include "gtkfilechooserutils.h"
24 #include "gtkfilesystem.h"
25 #include "gtktypebuiltins.h"
29 struct _GtkFileChooserDialogPrivate
33 GtkFileSystem *file_system;
36 #define GTK_FILE_CHOOSER_DIALOG_GET_PRIVATE(o) (GTK_FILE_CHOOSER_DIALOG (o)->priv)
38 static void gtk_file_chooser_dialog_class_init (GtkFileChooserDialogClass *class);
39 static void gtk_file_chooser_dialog_init (GtkFileChooserDialog *dialog);
41 static GObject* gtk_file_chooser_dialog_constructor (GType type,
42 guint n_construct_properties,
43 GObjectConstructParam *construct_params);
44 static void gtk_file_chooser_dialog_set_property (GObject *object,
48 static void gtk_file_chooser_dialog_get_property (GObject *object,
53 static GObjectClass *parent_class;
56 gtk_file_chooser_dialog_get_type (void)
58 static GType file_chooser_dialog_type = 0;
60 if (!file_chooser_dialog_type)
62 static const GTypeInfo file_chooser_dialog_info =
64 sizeof (GtkFileChooserDialogClass),
66 NULL, /* base_finalize */
67 (GClassInitFunc) gtk_file_chooser_dialog_class_init,
68 NULL, /* class_finalize */
69 NULL, /* class_data */
70 sizeof (GtkFileChooserDialog),
72 (GInstanceInitFunc) gtk_file_chooser_dialog_init,
75 static const GInterfaceInfo file_chooser_info =
77 (GInterfaceInitFunc) _gtk_file_chooser_delegate_iface_init, /* interface_init */
78 NULL, /* interface_finalize */
79 NULL /* interface_data */
82 file_chooser_dialog_type = g_type_register_static (GTK_TYPE_DIALOG, "GtkFileChooserDialog",
83 &file_chooser_dialog_info, 0);
84 g_type_add_interface_static (file_chooser_dialog_type,
85 GTK_TYPE_FILE_CHOOSER,
89 return file_chooser_dialog_type;
93 gtk_file_chooser_dialog_class_init (GtkFileChooserDialogClass *class)
95 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
97 parent_class = g_type_class_peek_parent (class);
99 gobject_class->constructor = gtk_file_chooser_dialog_constructor;
100 gobject_class->set_property = gtk_file_chooser_dialog_set_property;
101 gobject_class->get_property = gtk_file_chooser_dialog_get_property;
103 _gtk_file_chooser_install_properties (gobject_class);
105 g_type_class_add_private (class, sizeof (GtkFileChooserDialogPrivate));
109 gtk_file_chooser_dialog_init (GtkFileChooserDialog *dialog)
111 GtkFileChooserDialogPrivate *priv = G_TYPE_INSTANCE_GET_PRIVATE (dialog,
112 GTK_TYPE_FILE_CHOOSER_DIALOG,
113 GtkFileChooserDialogPrivate);
117 /* Callback used when the user activates a file in the file chooser widget */
119 file_chooser_widget_file_activated (GtkFileChooser *chooser,
120 GtkFileChooserDialog *dialog)
122 gtk_window_activate_default (GTK_WINDOW (dialog));
126 gtk_file_chooser_dialog_constructor (GType type,
127 guint n_construct_properties,
128 GObjectConstructParam *construct_params)
130 GtkFileChooserDialogPrivate *priv;
133 object = parent_class->constructor (type,
134 n_construct_properties,
136 priv = GTK_FILE_CHOOSER_DIALOG_GET_PRIVATE (object);
138 gtk_widget_push_composite_child ();
140 if (priv->file_system)
141 priv->widget = g_object_new (GTK_TYPE_FILE_CHOOSER_WIDGET,
142 "file-system", priv->file_system,
145 priv->widget = g_object_new (GTK_TYPE_FILE_CHOOSER_WIDGET, NULL);
147 g_signal_connect (priv->widget, "file-activated",
148 G_CALLBACK (file_chooser_widget_file_activated), object);
150 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (object)->vbox), priv->widget, TRUE, TRUE, 0);
151 gtk_widget_show (priv->widget);
153 _gtk_file_chooser_set_delegate (GTK_FILE_CHOOSER (object),
154 GTK_FILE_CHOOSER (priv->widget));
156 gtk_widget_pop_composite_child ();
162 gtk_file_chooser_dialog_set_property (GObject *object,
168 GtkFileChooserDialogPrivate *priv = GTK_FILE_CHOOSER_DIALOG_GET_PRIVATE (object);
172 case GTK_FILE_CHOOSER_PROP_FILE_SYSTEM:
174 GtkFileSystem *file_system = g_value_get_object (value);
175 if (priv->file_system != file_system)
177 if (priv->file_system)
178 g_object_unref (priv->file_system);
179 priv->file_system = file_system;
180 if (priv->file_system)
181 g_object_ref (priv->file_system);
186 g_object_set_property (G_OBJECT (priv->widget), pspec->name, value);
192 gtk_file_chooser_dialog_get_property (GObject *object,
197 GtkFileChooserDialogPrivate *priv = GTK_FILE_CHOOSER_DIALOG_GET_PRIVATE (object);
199 g_object_get_property (G_OBJECT (priv->widget), pspec->name, value);
203 * gtk_file_chooser_dialog_new:
204 * @title: Title of the dialog, or %NULL
205 * @parent: Transient parent of the dialog, or %NULL
206 * @action: Open or save mode for the dialog
207 * @first_button_text: stock ID or text to go in the first button, or %NULL
208 * @Varargs: response ID for the first button, then additional (button, id) pairs, ending with %NULL
210 * Creates a new #GtkFileChooserDialog. This function is analogous to
211 * gtk_dialog_new_with_buttons().
213 * Return value: a new #GtkFileChooserDialog
216 gtk_file_chooser_dialog_new (const gchar *title,
218 GtkFileChooserAction action,
219 const gchar *first_button_text,
224 const char *button_text = first_button_text;
227 result = g_object_new (GTK_TYPE_FILE_CHOOSER_DIALOG,
233 gtk_window_set_transient_for (GTK_WINDOW (result), parent);
235 va_start (varargs, first_button_text);
239 response_id = va_arg (varargs, gint);
240 gtk_dialog_add_button (GTK_DIALOG (result), button_text, response_id);
241 button_text = va_arg (varargs, const gchar *);