2
* Copyright (C) 2003 Marco Pesenti Gritti
3
* Copyright (C) 2003 Christian Persch
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2, or (at your option)
10
* This program 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
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25
#include "gul-file-chooser.h"
26
#include "eel-gconf-extensions.h"
27
#include "gul-state.h"
28
#include "galeon-debug.h"
30
#include <gtk/gtkstock.h>
31
#include <libgnomevfs/gnome-vfs-utils.h>
33
#define GUL_FILE_CHOOSER_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), GUL_TYPE_FILE_CHOOSER, GulFileChooserPrivate))
35
struct GulFileChooserPrivate
40
static void gul_file_chooser_class_init (GulFileChooserClass *klass);
41
static void gul_file_chooser_init (GulFileChooser *dialog);
49
static GObjectClass *parent_class = NULL;
52
gul_file_chooser_get_type (void)
54
static GType type = 0;
58
static const GTypeInfo our_info =
60
sizeof (GulFileChooserClass),
63
(GClassInitFunc) gul_file_chooser_class_init,
66
sizeof (GulFileChooser),
68
(GInstanceInitFunc) gul_file_chooser_init
71
type = g_type_register_static (GTK_TYPE_FILE_CHOOSER_DIALOG,
80
current_folder_changed_cb (GtkFileChooser *chooser, GulFileChooser *dialog)
82
if (dialog->priv->persist_key != NULL)
87
dir = gtk_file_chooser_get_current_folder (chooser);
89
converted = g_filename_to_utf8 (dir, -1, NULL, NULL, NULL);
90
eel_gconf_set_string (dialog->priv->persist_key, converted);
98
gul_file_chooser_init (GulFileChooser *dialog)
100
dialog->priv = GUL_FILE_CHOOSER_GET_PRIVATE (dialog);
102
dialog->priv->persist_key = NULL;
106
gul_file_chooser_finalize (GObject *object)
108
GulFileChooser *dialog = GUL_FILE_CHOOSER (object);
110
g_free (dialog->priv->persist_key);
112
LOG ("GulFileChooser finalised")
114
G_OBJECT_CLASS (parent_class)->finalize (object);
118
gul_file_chooser_set_persist_key (GulFileChooser *dialog, const char *key)
120
char *dir, *expanded, *converted;
122
g_return_if_fail (key != NULL && key[0] != '\0');
124
dialog->priv->persist_key = g_strdup (key);
126
dir = eel_gconf_get_string (key);
129
converted = g_filename_from_utf8
130
(dir, -1, NULL, NULL, NULL);
132
if (converted != NULL)
134
expanded = gnome_vfs_expand_initial_tilde (converted);
136
gtk_file_chooser_set_current_folder
137
(GTK_FILE_CHOOSER (dialog), expanded);
146
g_signal_connect (dialog, "current-folder-changed",
147
G_CALLBACK (current_folder_changed_cb), dialog);
151
gul_file_chooser_get_persist_key (GulFileChooser *dialog)
153
g_return_val_if_fail (GUL_IS_FILE_CHOOSER (dialog), NULL);
155
return dialog->priv->persist_key;
159
gul_file_chooser_set_property (GObject *object,
164
GulFileChooser *dialog = GUL_FILE_CHOOSER (object);
168
case PROP_PERSIST_KEY:
169
gul_file_chooser_set_persist_key (dialog, g_value_get_string (value));
175
gul_file_chooser_get_property (GObject *object,
180
GulFileChooser *dialog = GUL_FILE_CHOOSER (object);
184
case PROP_PERSIST_KEY:
185
g_value_set_string (value, gul_file_chooser_get_persist_key (dialog));
191
gul_file_chooser_class_init (GulFileChooserClass *klass)
193
GObjectClass *object_class = G_OBJECT_CLASS (klass);
195
parent_class = g_type_class_peek_parent (klass);
197
object_class->finalize = gul_file_chooser_finalize;
198
object_class->get_property = gul_file_chooser_get_property;
199
object_class->set_property = gul_file_chooser_set_property;
201
g_object_class_install_property (object_class,
203
g_param_spec_string ("persist-key",
205
"The gconf key to which to persist the selected directory",
209
g_type_class_add_private (object_class, sizeof (GulFileChooserPrivate));
213
gul_file_chooser_new (const char *title,
215
GtkFileChooserAction action,
216
const char *persist_key)
218
GulFileChooser *dialog;
220
dialog = GUL_FILE_CHOOSER (g_object_new (GUL_TYPE_FILE_CHOOSER,
225
/* NOTE: We cannot set this property on object construction time.
226
* This is because GtkFileChooserDialog overrides the gobject
227
* constructor; the GtkFileChooser delegate will only be set
228
* _after_ our instance_init and construct-param setters will have
231
if (persist_key != NULL)
233
gul_file_chooser_set_persist_key (dialog, persist_key);
236
if (action == GTK_FILE_CHOOSER_ACTION_OPEN ||
237
action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER ||
238
action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
240
gtk_dialog_add_buttons (GTK_DIALOG (dialog),
241
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
242
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
244
gtk_dialog_set_default_response (GTK_DIALOG (dialog),
245
GTK_RESPONSE_ACCEPT);
247
else if (action == GTK_FILE_CHOOSER_ACTION_SAVE)
249
gtk_dialog_add_buttons (GTK_DIALOG (dialog),
250
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
251
GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
253
gtk_dialog_set_default_response (GTK_DIALOG (dialog),
254
GTK_RESPONSE_ACCEPT);
259
gtk_window_set_transient_for (GTK_WINDOW (dialog),
260
GTK_WINDOW (parent));
262
gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);