Revision 3258

View differences:

src/messageview.c
913 913
	gchar *filename = NULL;
914 914
	MsgInfo *msginfo;
915 915
	gchar *src, *dest;
916
	GSList *types;
916
	FileselFileType types[4] = {{NULL, NULL}};
917 917
	gint selected_type = 0;
918 918
	gint result;
919 919
	gboolean all_headers;
......
928 928
	}
929 929
	subst_for_filename(filename);
930 930

  
931
	types = g_slist_append(NULL, _("Original (EML/RFC 822)"));
932
	types = g_slist_append(types, _("Text"));
933
	types = g_slist_append(types, _("Text (UTF-8)"));
931
	types[0].type = _("Original (EML/RFC 822)");
932
	types[0].ext = "eml";
933
	types[1].type = _("Text");
934
	types[1].ext = "txt";
935
	types[2].type = _("Text (UTF-8)");
936
	types[2].ext = "txt";
934 937
	dest = filesel_save_as_type(filename, types, 0, &selected_type);
935
	g_slist_free(types);
936 938

  
937 939
	g_free(filename);
938 940
	if (!dest)
src/filesel.c
47 47
					 const gchar		*file,
48 48
					 GtkFileChooserAction	 action,
49 49
					 gboolean		 multiple,
50
					 GSList			*types,
50
					 FileselFileType	*types,
51 51
					 gint			 default_type,
52 52
					 gint			*selected_type);
53 53

  
......
58 58
						    gboolean	 expanded);
59 59
static gboolean filesel_save_expander_get_expanded (GtkWidget	*dialog);
60 60

  
61
static void filesel_combo_changed_cb	(GtkComboBox		*combo_box,
62
					 gpointer		 data);
63

  
61 64
#if GTK_CHECK_VERSION(2, 8, 0)
62 65
static GtkFileChooserConfirmation filesel_confirm_overwrite_cb
63 66
					(GtkFileChooser		*chooser,
......
160 163
static GSList *filesel_select_file_full(const gchar *title, const gchar *file,
161 164
					GtkFileChooserAction action,
162 165
					gboolean multiple,
163
					GSList *types,
166
					FileselFileType *types,
164 167
					gint default_type, gint *selected_type)
165 168
{
166 169
	gchar *cwd;
......
202 205

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

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

  
213 216
		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);
217
		for (i = 0; types[i].type != NULL; i++) {
218
			gtk_combo_box_append_text(GTK_COMBO_BOX(combo), types[i].type);
216 219
		}
217 220
		gtk_box_pack_start(GTK_BOX(hbox), combo, FALSE, FALSE, 0);
218 221

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

  
226
		g_object_set_data(G_OBJECT(combo), "types", types);
227
		g_signal_connect(GTK_COMBO_BOX(combo), "changed",
228
				 G_CALLBACK(filesel_combo_changed_cb), dialog);
222 229
	}
223 230

  
224 231
	gtk_widget_show(dialog);
......
296 303
	return filename;
297 304
}
298 305

  
299
gchar *filesel_save_as_type(const gchar *file, GSList *types,
306
gchar *filesel_save_as_type(const gchar *file, FileselFileType *types,
300 307
			    gint default_type, gint *selected_type)
301 308
{
302 309
	GSList *list;
......
304 311

  
305 312
	list = filesel_select_file_full(_("Save as"), file,
306 313
					GTK_FILE_CHOOSER_ACTION_SAVE, FALSE,
307
					types, default_type, selected_type);
314
					types,
315
					default_type, selected_type);
308 316
	if (list) {
309 317
		filename = (gchar *)list->data;
310 318
		slist_free_strings(list->next);
......
415 423
		return FALSE;
416 424
}
417 425

  
426
static void filesel_combo_changed_cb(GtkComboBox *combo_box, gpointer data)
427
{
428
	GtkFileChooser *chooser = data;
429
	gint active;
430
	gchar *filename;
431
	gchar *base;
432
	gchar *new_filename;
433
	gchar *p;
434
	FileselFileType *types;
435

  
436
	active = gtk_combo_box_get_active(combo_box);
437
	filename = gtk_file_chooser_get_filename(chooser);
438
	types = g_object_get_data(G_OBJECT(combo_box), "types");
439
	g_print("active: %d filename: %s\n", active, filename);
440
	g_print("type ext: %s\n", types[active].ext);
441
	base = g_path_get_basename(filename);
442
	p = strrchr(base, '.');
443
	if (p)
444
		*p = '\0';
445
	new_filename = g_strconcat(base, ".", types[active].ext, NULL);
446
	g_print("new_filename: %s\n", new_filename);
447
	gtk_file_chooser_set_current_name(chooser, new_filename);
448
	g_free(new_filename);
449
	g_free(base);
450
	g_free(filename);
451
}
452

  
418 453
#if GTK_CHECK_VERSION(2, 8, 0)
419 454
static GtkFileChooserConfirmation filesel_confirm_overwrite_cb
420 455
					(GtkFileChooser		*chooser,
src/filesel.h
23 23
#include <glib.h>
24 24
#include <gtk/gtkfilechooser.h>
25 25

  
26
typedef struct _FileselFileType	FileselFileType;
27

  
28
struct _FileselFileType
29
{
30
	gchar *type;
31
	gchar *ext;
32
};
33

  
26 34
gchar *filesel_select_file	(const gchar		*title,
27 35
				 const gchar		*file,
28 36
				 GtkFileChooserAction	 action);
......
32 40

  
33 41
gchar *filesel_save_as		(const gchar		*file);
34 42
gchar *filesel_save_as_type	(const gchar		*file,
35
				 GSList			*types,
43
				 FileselFileType	*types,
36 44
				 gint			 default_type,
37 45
				 gint			*selected_type);
38 46
gchar *filesel_select_dir	(const gchar		*dir);
src/summaryview.c
3891 3891
	MsgInfo *msginfo = NULL;
3892 3892
	gchar *filename;
3893 3893
	gchar *src, *dest;
3894
	GSList *types;
3894
	FileselFileType types[4] = {{NULL, NULL}};
3895 3895
	gint selected_type = 0;
3896 3896
	gint result;
3897 3897
	gboolean all_headers;
......
3912 3912
	}
3913 3913
	subst_for_filename(filename);
3914 3914

  
3915
	types = g_slist_append(NULL, _("Original (EML/RFC 822)"));
3916
	types = g_slist_append(types, _("Text"));
3917
	types = g_slist_append(types, _("Text (UTF-8)"));
3915
	types[0].type = _("Original (EML/RFC 822)");
3916
	types[0].ext = "eml";
3917
	types[1].type = _("Text");
3918
	types[1].ext = "txt";
3919
	types[2].type = _("Text (UTF-8)");
3920
	types[2].ext = "txt";
3921
	
3918 3922
	dest = filesel_save_as_type(filename, types, 0, &selected_type);
3919
	g_slist_free(types);
3920 3923

  
3921 3924
	g_free(filename);
3922 3925
	if (!dest)
ChangeLog
1
2013-05-21
2

  
3
	* src/filesel.[ch]
4
	  src/messageview.c
5
	  src/summaryview.c: automatically modify file extension when
6
	  file type is changed.
7

  
1 8
2013-05-20
2 9

  
3 10
	* src/textview.c: textview_write_link(): insert space between

Also available in: Unified diff