fix bug 4155, 'remember directory of last saving'
authorPaul <paul@claws-mail.org>
Thu, 14 Feb 2019 14:12:35 +0000 (14:12 +0000)
committerPaul <paul@claws-mail.org>
Thu, 14 Feb 2019 14:12:35 +0000 (14:12 +0000)
drop messageview_save_as(), use only summary_save_as()

src/messageview.c
src/summaryview.c

index fe9767d..62d63ad 100644 (file)
@@ -1813,52 +1813,6 @@ gboolean messageview_is_visible(MessageView *messageview)
        return messageview->visible;
 }
 
-static void messageview_save_as(MessageView *messageview)
-{
-       gchar *filename = NULL;
-       MsgInfo *msginfo;
-       gchar *src, *dest, *tmp;
-
-       if (!messageview->msginfo) return;
-       msginfo = messageview->msginfo;
-
-       if (msginfo->subject) {
-               Xstrdup_a(filename, msginfo->subject, return);
-               subst_for_filename(filename);
-       }
-       if (filename && !g_utf8_validate(filename, -1, NULL)) {
-               gchar *oldstr = filename;
-               filename = conv_codeset_strdup(filename,
-                                              conv_get_locale_charset_str(),
-                                              CS_UTF_8);
-               if (!filename) {
-                       g_warning("messageview_save_as(): failed to convert character set.");
-                       filename = g_strdup(oldstr);
-               }
-               dest = filesel_select_file_save(_("Save as"), filename);
-               g_free(filename);
-       } else
-               dest = filesel_select_file_save(_("Save as"), filename);
-       if (!dest) return;
-       if (is_file_exist(dest)) {
-               AlertValue aval;
-
-               aval = alertpanel(_("Overwrite"),
-                                 _("Overwrite existing file?"),
-                                 GTK_STOCK_CANCEL, GTK_STOCK_OK, NULL, ALERTFOCUS_FIRST);
-               if (G_ALERTALTERNATE != aval) return;
-       }
-
-       src = procmsg_get_message_file(msginfo);
-       if (copy_file(src, dest, TRUE) < 0) {
-               tmp =  g_path_get_basename(dest);
-               alertpanel_error(_("Couldn't save the file '%s'."), tmp);
-               g_free(tmp);
-       }
-       g_free(dest);
-       g_free(src);
-}
-
 static gint messageview_delete_cb(GtkWidget *widget, GdkEventAny *event,
                                  MessageView *messageview)
 {
@@ -2199,7 +2153,7 @@ gchar *messageview_get_selection(MessageView *msgview)
 static void save_as_cb(GtkAction *action, gpointer data)
 {
        MessageView *messageview = (MessageView *)data;
-       messageview_save_as(messageview);
+       summary_save_as(messageview->mainwin->summaryview);
 }
 
 static void print_mimeview(MimeView *mimeview, gint sel_start, gint sel_end, gint partnum) 
index 99b30c8..59bd9d6 100644 (file)
@@ -4995,6 +4995,7 @@ void summary_save_as(SummaryView *summaryview)
        gchar *filename = NULL;
        gchar *src, *dest;
        gchar *tmp;
+       gchar *filedir = NULL;
 
        AlertValue aval = 0;
 
@@ -5018,12 +5019,17 @@ void summary_save_as(SummaryView *summaryview)
                        g_warning("summary_save_as(): failed to convert character set.");
                        filename = g_strdup(oldstr);
                }
-               dest = filesel_select_file_save(_("Save as"), filename);
+               dest = filename;
                g_free(filename);
        } else
-               dest = filesel_select_file_save(_("Save as"), filename);
+               dest = filename;
        filename = NULL;
        if (!dest) return;
+       if (prefs_common.attach_save_dir && *prefs_common.attach_save_dir)
+               dest = g_strconcat(prefs_common.attach_save_dir, G_DIR_SEPARATOR_S,
+                                  dest, NULL);
+       dest = filesel_select_file_save(_("Save as"), dest);
+
        if (is_file_exist(dest)) {
                aval = alertpanel(_("Append or Overwrite"),
                                  _("Append or overwrite existing file?"),
@@ -5060,6 +5066,13 @@ void summary_save_as(SummaryView *summaryview)
                }
                g_free(src);
        }
+
+       filedir = g_path_get_dirname(dest);
+       if (filedir && strcmp(filedir, ".")) {
+               g_free(prefs_common.attach_save_dir);
+               prefs_common.attach_save_dir = g_filename_to_utf8(filedir, -1, NULL, NULL, NULL);
+       }
+
        g_free(dest);
        g_free(tmp);
 }