Revision 601

libsylph/utils.c (revision 601)
1045 1045
	subst_chars(str, " \t\r\n\"'/\\", '_');
1046 1046
}
1047 1047

  
1048
gchar *get_alt_filename(const gchar *filename, gint count)
1049
{
1050
	const gchar *ext;
1051
	gchar *alt_filename;
1052

  
1053
	ext = strrchr(filename, '.');
1054

  
1055
	if (ext) {
1056
		gchar *base;
1057

  
1058
		base = g_strndup(filename, ext - filename);
1059
		alt_filename = g_strdup_printf("%s-%d%s", base, count, ext);
1060
		g_free(base);
1061
	} else
1062
		alt_filename = g_strdup_printf("%s-%d", filename, count);
1063

  
1064
	return alt_filename;
1065
}
1066

  
1048 1067
gboolean is_header_line(const gchar *str)
1049 1068
{
1050 1069
	if (str[0] == ':') return FALSE;
libsylph/utils.h (revision 601)
300 300
					 gint		 len,
301 301
					 gchar		 subst);
302 302
void subst_for_filename			(gchar		*str);
303

  
304
gchar *get_alt_filename			(const gchar	*filename,
305
					 gint		 count);
306

  
303 307
gboolean is_header_line			(const gchar	*str);
304 308
gboolean is_ascii_str			(const gchar	*str);
309

  
305 310
gint get_quote_level			(const gchar	*str);
306 311
gint check_line_length			(const gchar	*str,
307 312
					 gint		 max_chars,
libsylph/procmime.c (revision 601)
697 697
	return 0;
698 698
}
699 699

  
700
gint procmime_get_all_parts(const gchar *dir, const gchar *infile,
701
			    MimeInfo *mimeinfo)
702
{
703
	FILE *fp;
704
	MimeInfo *partinfo;
705
	gchar *base, *filename;
706

  
707
	g_return_val_if_fail(dir != NULL, -1);
708
	g_return_val_if_fail(infile != NULL, -1);
709
	g_return_val_if_fail(mimeinfo != NULL, -1);
710

  
711
	if (!is_dir_exist(dir)) {
712
		g_warning("%s: directory not exist.\n", dir);
713
		return -1;
714
	}
715

  
716
	if ((fp = g_fopen(infile, "rb")) == NULL) {
717
		FILE_OP_ERROR(infile, "fopen");
718
		return -1;
719
	}
720

  
721
	for (partinfo = mimeinfo; partinfo != NULL;
722
	     partinfo = procmime_mimeinfo_next(partinfo)) {
723
		if (partinfo->filename || partinfo->name) {
724
			gint count = 1;
725

  
726
			base = procmime_get_part_file_name(partinfo);
727
			filename = g_strconcat(dir, G_DIR_SEPARATOR_S, base,
728
					       NULL);
729

  
730
			while (is_file_entry_exist(filename)) {
731
				gchar *base_alt;
732

  
733
				base_alt = get_alt_filename(base, count++);
734
				g_free(filename);
735
				filename = g_strconcat
736
					(dir, G_DIR_SEPARATOR_S, base_alt,
737
					 NULL);
738
				g_free(base_alt);
739
			}
740

  
741
			procmime_get_part_fp(filename, fp, partinfo);
742

  
743
			g_free(filename);
744
			g_free(base);
745
		}
746
	}
747

  
748
	fclose(fp);
749

  
750
	return 0;
751
}
752

  
700 753
FILE *procmime_get_text_content(MimeInfo *mimeinfo, FILE *infp,
701 754
				const gchar *encoding)
702 755
{
libsylph/procmime.h (revision 601)
159 159
gint procmime_get_part_fp		(const gchar	*outfile,
160 160
					 FILE		*infp,
161 161
					 MimeInfo	*mimeinfo);
162
gint procmime_get_all_parts		(const gchar	*dir,
163
					 const gchar	*infile,
164
					 MimeInfo	*mimeinfo);
162 165
FILE *procmime_get_text_content		(MimeInfo	*mimeinfo,
163 166
					 FILE		*infp,
164 167
					 const gchar	*encoding);
src/mimeview.c (revision 601)
124 124
	{N_("/_Open"),		  NULL, mimeview_launch,	  0, NULL},
125 125
	{N_("/Open _with..."),	  NULL, mimeview_open_with,	  0, NULL},
126 126
	{N_("/_Display as text"), NULL, mimeview_display_as_text, 0, NULL},
127
	{N_("/_Save as..."),	  NULL, mimeview_save_as,	  0, NULL}
127
	{N_("/_Save as..."),	  NULL, mimeview_save_as,	  0, NULL},
128
	{N_("/Save _all..."),	  NULL, mimeview_save_all,	  0, NULL}
128 129
#if USE_GPGME
129 130
        ,
130 131
        {N_("/_Check signature"), NULL, mimeview_check_signature, 0, NULL}
......
1024 1025
	g_free(filename);
1025 1026
}
1026 1027

  
1028
void mimeview_save_all(MimeView *mimeview)
1029
{
1030
	gchar *dir;
1031

  
1032
	dir = filesel_select_dir(NULL);
1033
	if (!dir) return;
1034

  
1035
	if (procmime_get_all_parts(dir, mimeview->file, mimeview->mimeinfo) < 0)
1036
		alertpanel_error(_("Can't save the attachments."));
1037

  
1038
	g_free(dir);
1039
}
1040

  
1027 1041
static void mimeview_launch(MimeView *mimeview)
1028 1042
{
1029 1043
	MimeInfo *partinfo;
src/mimeview.h (revision 601)
88 88
					 GdkEventKey	*event);
89 89

  
90 90
void mimeview_save_as			(MimeView	*mimeview);
91
void mimeview_save_all			(MimeView	*mimeview);
91 92

  
92 93
#endif /* __MIMEVIEW_H__ */
src/filesel.c (revision 601)
151 151
	return filename;
152 152
}
153 153

  
154
gchar *filesel_select_dir(const gchar *dir)
155
{
156
	GSList *list;
157
	gchar *selected = NULL;
158

  
159
	list = filesel_select_file_full(_("Select directory"), dir,
160
					GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
161
					FALSE);
162
	if (list) {
163
		selected = (gchar *)list->data;
164
		slist_free_strings(list->next);
165
	}
166
	g_slist_free(list);
167

  
168
	return selected;
169
}
170

  
154 171
static GtkWidget *filesel_create(const gchar *title,
155 172
				 GtkFileChooserAction action)
156 173
{
......
160 177
		dialog = gtk_file_chooser_dialog_new
161 178
			(title, NULL, action,
162 179
			 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
163
			 action == GTK_FILE_CHOOSER_ACTION_SAVE ? GTK_STOCK_SAVE
164
			 : GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
180
			 (action == GTK_FILE_CHOOSER_ACTION_SAVE ||
181
			  action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
182
			 ? GTK_STOCK_SAVE : GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
165 183
			 NULL);
166 184
	else
167 185
		dialog = gtk_file_chooser_dialog_new
168 186
			(title, NULL, action,
169
			 action == GTK_FILE_CHOOSER_ACTION_SAVE ? GTK_STOCK_SAVE
170
			 : GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
187
			 (action == GTK_FILE_CHOOSER_ACTION_SAVE ||
188
			  action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
189
			 ? GTK_STOCK_SAVE : GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
171 190
			 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
172 191
			 NULL);
173 192
	gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER);
src/filesel.h (revision 601)
31 31
				 GtkFileChooserAction	 action);
32 32

  
33 33
gchar *filesel_save_as		(const gchar		*file);
34
gchar *filesel_select_dir	(const gchar		*dir);
34 35

  
35 36
#endif /* __FILESEL_H__ */
ChangeLog.ja (revision 601)
1 1
2005-09-22
2 2

  
3
	* libsylph/utils.[ch]
4
	  libsylph/procmime.[ch]
5
	  src/mimeview.[ch]
6
	  src/filesel.[ch]: ???å????????Τ??٤Ƥ?ź?եե?????????¸????
7
	  ?֤??٤???¸?פ???????
8

  
9
2005-09-22
10

  
3 11
	* src/gtkutils.[ch]
4 12
	  src/summaryview.[ch]: ??????????ü??ã?????Ȥ????????Ԥ???????
5 13
	  ???֤????褦?ˤ?????
ChangeLog (revision 601)
1 1
2005-09-22
2 2

  
3
	* libsylph/utils.[ch]
4
	  libsylph/procmime.[ch]
5
	  src/mimeview.[ch]
6
	  src/filesel.[ch]: implemented "Save all", which saves all
7
	  attachments in a message.
8

  
9
2005-09-22
10

  
3 11
	* src/gtkutils.[ch]
4 12
	  src/summaryview.[ch]: align selected row to center when reached to
5 13
	  the edge on key operation.

Also available in: Unified diff