Revision 3245 src/filesel.c

View differences:

filesel.c
1 1
/*
2 2
 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3
 * Copyright (C) 1999-2012 Hiroyuki Yamamoto
3
 * Copyright (C) 1999-2013 Hiroyuki Yamamoto
4 4
 *
5 5
 * This program is free software; you can redistribute it and/or modify
6 6
 * it under the terms of the GNU General Public License as published by
......
23 23
#include <gtk/gtkversion.h>
24 24
#include <gtk/gtkfilechooserdialog.h>
25 25
#include <gtk/gtkexpander.h>
26
#include <gtk/gtkcombobox.h>
26 27
#include <gtk/gtkstock.h>
27 28

  
28 29
#ifdef G_OS_WIN32
......
45 46
static GSList *filesel_select_file_full	(const gchar		*title,
46 47
					 const gchar		*file,
47 48
					 GtkFileChooserAction	 action,
48
					 gboolean		 multiple);
49
					 gboolean		 multiple,
50
					 GSList			*types,
51
					 gint			 default_type,
52
					 gint			*selected_type);
49 53

  
50 54
static GtkWidget *filesel_create	(const gchar		*title,
51 55
					 GtkFileChooserAction	 action);
......
74 78
	GSList *list;
75 79
	gchar *selected = NULL;
76 80

  
77
	list = filesel_select_file_full(title, file, action, FALSE);
81
	list = filesel_select_file_full(title, file, action, FALSE, NULL, 0, NULL);
78 82
	if (list) {
79 83
		selected = (gchar *)list->data;
80 84
		slist_free_strings(list->next);
......
87 91
GSList *filesel_select_files(const gchar *title, const gchar *file,
88 92
			     GtkFileChooserAction action)
89 93
{
90
	return filesel_select_file_full(title, file, action, TRUE);
94
	return filesel_select_file_full(title, file, action, TRUE, NULL, 0, NULL);
91 95
}
92 96

  
93 97
static void filesel_change_dir_for_action(GtkFileChooserAction action)
......
155 159

  
156 160
static GSList *filesel_select_file_full(const gchar *title, const gchar *file,
157 161
					GtkFileChooserAction action,
158
					gboolean multiple)
162
					gboolean multiple,
163
					GSList *types,
164
					gint default_type, gint *selected_type)
159 165
{
160 166
	gchar *cwd;
161 167
	GtkWidget *dialog;
162 168
	gchar *prev_dir;
163 169
	static gboolean save_expander_expanded = FALSE;
164 170
	GSList *list = NULL;
171
	GtkWidget *combo = NULL;
165 172

  
166 173
	prev_dir = g_get_current_dir();
167 174

  
......
193 200
	}
194 201
#endif
195 202

  
203
	/* create types combo box */
204
	if (types) {
205
		GSList *cur;
206
		GtkWidget *hbox;
207
		GtkWidget *label;
208

  
209
		hbox = gtk_hbox_new(FALSE, 12);
210
		label = gtk_label_new(_("File type:"));
211
		gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
212

  
213
		combo = gtk_combo_box_new_text();
214
		for (cur = types; cur != NULL; cur = cur->next) {
215
			gtk_combo_box_append_text(GTK_COMBO_BOX(combo), (const gchar *)cur->data);
216
		}
217
		gtk_box_pack_start(GTK_BOX(hbox), combo, FALSE, FALSE, 0);
218

  
219
		gtk_widget_show_all(hbox);
220
		gtk_file_chooser_set_extra_widget(GTK_FILE_CHOOSER(dialog), hbox);
221
		gtk_combo_box_set_active(GTK_COMBO_BOX(combo), default_type);
222
	}
223

  
196 224
	gtk_widget_show(dialog);
197 225

  
198 226
	change_dir(prev_dir);
......
230 258

  
231 259
	inc_unlock();
232 260

  
261
	if (combo && selected_type) {
262
		*selected_type = gtk_combo_box_get_active(GTK_COMBO_BOX(combo));
263
	}
264

  
233 265
	if (action == GTK_FILE_CHOOSER_ACTION_SAVE)
234 266
		save_expander_expanded =
235 267
			filesel_save_expander_get_expanded(dialog);
......
264 296
	return filename;
265 297
}
266 298

  
299
gchar *filesel_save_as_type(const gchar *file, GSList *types,
300
			    gint default_type, gint *selected_type)
301
{
302
	GSList *list;
303
	gchar *filename = NULL;
304

  
305
	list = filesel_select_file_full(_("Save as"), file,
306
					GTK_FILE_CHOOSER_ACTION_SAVE, FALSE,
307
					types, default_type, selected_type);
308
	if (list) {
309
		filename = (gchar *)list->data;
310
		slist_free_strings(list->next);
311
	}
312
	g_slist_free(list);
313

  
314
#if !GTK_CHECK_VERSION(2, 8, 0)
315
	if (filename && is_file_exist(filename)) {
316
		AlertValue aval;
317

  
318
		aval = alertpanel(_("Overwrite existing file"),
319
				  _("The file already exists. Do you want to replace it?"),
320
				  GTK_STOCK_YES, GTK_STOCK_NO, NULL);
321
		if (G_ALERTDEFAULT != aval) {
322
			g_free(filename);
323
			filename = NULL;
324
		}
325
	}
326
#endif
327

  
328
	return filename;
329
}
330

  
267 331
gchar *filesel_select_dir(const gchar *dir)
268 332
{
269 333
	GSList *list;
......
271 335

  
272 336
	list = filesel_select_file_full(_("Select folder"), dir,
273 337
					GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
274
					FALSE);
338
					FALSE, NULL, 0, NULL);
275 339
	if (list) {
276 340
		selected = (gchar *)list->data;
277 341
		slist_free_strings(list->next);

Also available in: Unified diff