aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2005-09-22 11:18:22 +0000
committerhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2005-09-22 11:18:22 +0000
commite804cac393c2dd84a8c570541fec5d6f7245d945 (patch)
treea0480475e799431680bfac040b30d30a0b41aeac
parent39a1d4cf0bd2ae39c2300b12f9c826514acd560e (diff)
implemented 'Save all'.
git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@601 ee746299-78ed-0310-b773-934348b2243d
-rw-r--r--ChangeLog8
-rw-r--r--ChangeLog.ja8
-rw-r--r--libsylph/procmime.c53
-rw-r--r--libsylph/procmime.h3
-rw-r--r--libsylph/utils.c19
-rw-r--r--libsylph/utils.h5
-rw-r--r--src/filesel.c27
-rw-r--r--src/filesel.h1
-rw-r--r--src/mimeview.c16
-rw-r--r--src/mimeview.h1
10 files changed, 136 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 80954c2b..ab6bae89 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
2005-09-22
+ * libsylph/utils.[ch]
+ libsylph/procmime.[ch]
+ src/mimeview.[ch]
+ src/filesel.[ch]: implemented "Save all", which saves all
+ attachments in a message.
+
+2005-09-22
+
* src/gtkutils.[ch]
src/summaryview.[ch]: align selected row to center when reached to
the edge on key operation.
diff --git a/ChangeLog.ja b/ChangeLog.ja
index 2424227a..e34ca4da 100644
--- a/ChangeLog.ja
+++ b/ChangeLog.ja
@@ -1,5 +1,13 @@
2005-09-22
+ * libsylph/utils.[ch]
+ libsylph/procmime.[ch]
+ src/mimeview.[ch]
+ src/filesel.[ch]: メッセージ中のすべての添付ファイルを保存する
+ 「すべて保存」を実装。
+
+2005-09-22
+
* src/gtkutils.[ch]
src/summaryview.[ch]: キー操作で端に達したときに選択行を中央に
配置するようにした。
diff --git a/libsylph/procmime.c b/libsylph/procmime.c
index a9b93a99..7c2105b6 100644
--- a/libsylph/procmime.c
+++ b/libsylph/procmime.c
@@ -697,6 +697,59 @@ gint procmime_get_part_fp(const gchar *outfile, FILE *infp, MimeInfo *mimeinfo)
return 0;
}
+gint procmime_get_all_parts(const gchar *dir, const gchar *infile,
+ MimeInfo *mimeinfo)
+{
+ FILE *fp;
+ MimeInfo *partinfo;
+ gchar *base, *filename;
+
+ g_return_val_if_fail(dir != NULL, -1);
+ g_return_val_if_fail(infile != NULL, -1);
+ g_return_val_if_fail(mimeinfo != NULL, -1);
+
+ if (!is_dir_exist(dir)) {
+ g_warning("%s: directory not exist.\n", dir);
+ return -1;
+ }
+
+ if ((fp = g_fopen(infile, "rb")) == NULL) {
+ FILE_OP_ERROR(infile, "fopen");
+ return -1;
+ }
+
+ for (partinfo = mimeinfo; partinfo != NULL;
+ partinfo = procmime_mimeinfo_next(partinfo)) {
+ if (partinfo->filename || partinfo->name) {
+ gint count = 1;
+
+ base = procmime_get_part_file_name(partinfo);
+ filename = g_strconcat(dir, G_DIR_SEPARATOR_S, base,
+ NULL);
+
+ while (is_file_entry_exist(filename)) {
+ gchar *base_alt;
+
+ base_alt = get_alt_filename(base, count++);
+ g_free(filename);
+ filename = g_strconcat
+ (dir, G_DIR_SEPARATOR_S, base_alt,
+ NULL);
+ g_free(base_alt);
+ }
+
+ procmime_get_part_fp(filename, fp, partinfo);
+
+ g_free(filename);
+ g_free(base);
+ }
+ }
+
+ fclose(fp);
+
+ return 0;
+}
+
FILE *procmime_get_text_content(MimeInfo *mimeinfo, FILE *infp,
const gchar *encoding)
{
diff --git a/libsylph/procmime.h b/libsylph/procmime.h
index b0697f62..722bc88f 100644
--- a/libsylph/procmime.h
+++ b/libsylph/procmime.h
@@ -159,6 +159,9 @@ gint procmime_get_part (const gchar *outfile,
gint procmime_get_part_fp (const gchar *outfile,
FILE *infp,
MimeInfo *mimeinfo);
+gint procmime_get_all_parts (const gchar *dir,
+ const gchar *infile,
+ MimeInfo *mimeinfo);
FILE *procmime_get_text_content (MimeInfo *mimeinfo,
FILE *infp,
const gchar *encoding);
diff --git a/libsylph/utils.c b/libsylph/utils.c
index 5c0ba893..7164ed5c 100644
--- a/libsylph/utils.c
+++ b/libsylph/utils.c
@@ -1045,6 +1045,25 @@ void subst_for_filename(gchar *str)
subst_chars(str, " \t\r\n\"'/\\", '_');
}
+gchar *get_alt_filename(const gchar *filename, gint count)
+{
+ const gchar *ext;
+ gchar *alt_filename;
+
+ ext = strrchr(filename, '.');
+
+ if (ext) {
+ gchar *base;
+
+ base = g_strndup(filename, ext - filename);
+ alt_filename = g_strdup_printf("%s-%d%s", base, count, ext);
+ g_free(base);
+ } else
+ alt_filename = g_strdup_printf("%s-%d", filename, count);
+
+ return alt_filename;
+}
+
gboolean is_header_line(const gchar *str)
{
if (str[0] == ':') return FALSE;
diff --git a/libsylph/utils.h b/libsylph/utils.h
index 41760bb5..7796541b 100644
--- a/libsylph/utils.h
+++ b/libsylph/utils.h
@@ -300,8 +300,13 @@ void subst_null (gchar *str,
gint len,
gchar subst);
void subst_for_filename (gchar *str);
+
+gchar *get_alt_filename (const gchar *filename,
+ gint count);
+
gboolean is_header_line (const gchar *str);
gboolean is_ascii_str (const gchar *str);
+
gint get_quote_level (const gchar *str);
gint check_line_length (const gchar *str,
gint max_chars,
diff --git a/src/filesel.c b/src/filesel.c
index 1921901f..7d87a928 100644
--- a/src/filesel.c
+++ b/src/filesel.c
@@ -151,6 +151,23 @@ gchar *filesel_save_as(const gchar *file)
return filename;
}
+gchar *filesel_select_dir(const gchar *dir)
+{
+ GSList *list;
+ gchar *selected = NULL;
+
+ list = filesel_select_file_full(_("Select directory"), dir,
+ GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
+ FALSE);
+ if (list) {
+ selected = (gchar *)list->data;
+ slist_free_strings(list->next);
+ }
+ g_slist_free(list);
+
+ return selected;
+}
+
static GtkWidget *filesel_create(const gchar *title,
GtkFileChooserAction action)
{
@@ -160,14 +177,16 @@ static GtkWidget *filesel_create(const gchar *title,
dialog = gtk_file_chooser_dialog_new
(title, NULL, action,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
- action == GTK_FILE_CHOOSER_ACTION_SAVE ? GTK_STOCK_SAVE
- : GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
+ (action == GTK_FILE_CHOOSER_ACTION_SAVE ||
+ action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
+ ? GTK_STOCK_SAVE : GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
NULL);
else
dialog = gtk_file_chooser_dialog_new
(title, NULL, action,
- action == GTK_FILE_CHOOSER_ACTION_SAVE ? GTK_STOCK_SAVE
- : GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
+ (action == GTK_FILE_CHOOSER_ACTION_SAVE ||
+ action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)
+ ? GTK_STOCK_SAVE : GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
NULL);
gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER);
diff --git a/src/filesel.h b/src/filesel.h
index 24764d9c..43b48ec8 100644
--- a/src/filesel.h
+++ b/src/filesel.h
@@ -31,5 +31,6 @@ GSList *filesel_select_files (const gchar *title,
GtkFileChooserAction action);
gchar *filesel_save_as (const gchar *file);
+gchar *filesel_select_dir (const gchar *dir);
#endif /* __FILESEL_H__ */
diff --git a/src/mimeview.c b/src/mimeview.c
index 10439bdd..1e3014d2 100644
--- a/src/mimeview.c
+++ b/src/mimeview.c
@@ -124,7 +124,8 @@ static GtkItemFactoryEntry mimeview_popup_entries[] =
{N_("/_Open"), NULL, mimeview_launch, 0, NULL},
{N_("/Open _with..."), NULL, mimeview_open_with, 0, NULL},
{N_("/_Display as text"), NULL, mimeview_display_as_text, 0, NULL},
- {N_("/_Save as..."), NULL, mimeview_save_as, 0, NULL}
+ {N_("/_Save as..."), NULL, mimeview_save_as, 0, NULL},
+ {N_("/Save _all..."), NULL, mimeview_save_all, 0, NULL}
#if USE_GPGME
,
{N_("/_Check signature"), NULL, mimeview_check_signature, 0, NULL}
@@ -1024,6 +1025,19 @@ void mimeview_save_as(MimeView *mimeview)
g_free(filename);
}
+void mimeview_save_all(MimeView *mimeview)
+{
+ gchar *dir;
+
+ dir = filesel_select_dir(NULL);
+ if (!dir) return;
+
+ if (procmime_get_all_parts(dir, mimeview->file, mimeview->mimeinfo) < 0)
+ alertpanel_error(_("Can't save the attachments."));
+
+ g_free(dir);
+}
+
static void mimeview_launch(MimeView *mimeview)
{
MimeInfo *partinfo;
diff --git a/src/mimeview.h b/src/mimeview.h
index 72d3f6fd..6e11f9fe 100644
--- a/src/mimeview.h
+++ b/src/mimeview.h
@@ -88,5 +88,6 @@ void mimeview_pass_key_press_event (MimeView *mimeview,
GdkEventKey *event);
void mimeview_save_as (MimeView *mimeview);
+void mimeview_save_all (MimeView *mimeview);
#endif /* __MIMEVIEW_H__ */