patch by Satoshi Nagayasu: allows appending / saving multiple
authorAlfons Hoogervorst <alfons@proteus.demon.nl>
Tue, 24 Sep 2002 18:58:07 +0000 (18:58 +0000)
committerAlfons Hoogervorst <alfons@proteus.demon.nl>
Tue, 24 Sep 2002 18:58:07 +0000 (18:58 +0000)
selected files (closes "[ 612279 ] save multiple mesg(s) in
'Save as ...'")

* AUTHORS
add Satoshi Nagayasu
* src/summaryview.c
summary_save_as(): allow saving selected files to
one file
summary_set_menu_sensitive: enable "Save As..." when
multiple files are selected
* src/utils.[ch]
append_file(): new function

AUTHORS
ChangeLog.claws
configure.in
src/summaryview.c
src/utils.c
src/utils.h

diff --git a/AUTHORS b/AUTHORS
index 4006123..c67c22f 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -156,3 +156,4 @@ contributors (beside the above; based on Changelog)
        Urosevic Aleksandar
        Martin Kluge
        George Danchev
+       Satoshi Nagayasu
index 98d71d9..b395d74 100644 (file)
@@ -1,3 +1,19 @@
+2002-09-24 [alfons]    0.8.3claws21
+
+       patch by Satoshi Nagayasu: allows appending / saving multiple 
+       selected files (closes "[ 612279 ] save multiple mesg(s) in 
+       'Save as ...'")
+
+       * AUTHORS
+               add Satoshi Nagayasu
+       * src/summaryview.c
+               summary_save_as(): allow saving selected files to
+               one file
+               summary_set_menu_sensitive: enable "Save As..." when
+               multiple files are selected
+       * src/utils.[ch]
+               append_file(): new function
+
 2002-09-24 [colin]     0.8.3claws20
 
        * src/procmime.c
index 594666b..13c9a15 100644 (file)
@@ -10,7 +10,7 @@ MINOR_VERSION=8
 MICRO_VERSION=3
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=claws20
+EXTRA_VERSION=claws21
 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION
 
 dnl set $target
index fe116ea..826a3be 100644 (file)
@@ -1174,7 +1174,7 @@ static void summary_set_menu_sensitive(SummaryView *summaryview)
        else
                menu_set_sensitive(ifactory, "/Re-edit", FALSE);
 
-       menu_set_sensitive(ifactory, "/Save as...", sens);
+       menu_set_sensitive(ifactory, "/Save as...", TRUE);
        menu_set_sensitive(ifactory, "/Print...",   TRUE);
 
        menu_set_sensitive(ifactory, "/Select all", TRUE);
@@ -3271,6 +3271,8 @@ void summary_save_as(SummaryView *summaryview)
        gchar *filename = NULL;
        gchar *src, *dest;
 
+       AlertValue aval;
+
        if (!summaryview->selected) return;
        msginfo = gtk_ctree_node_get_row_data(ctree, summaryview->selected);
        if (!msginfo) return;
@@ -3282,20 +3284,41 @@ void summary_save_as(SummaryView *summaryview)
        dest = filesel_select_file(_("Save as"), filename);
        if (!dest) return;
        if (is_file_exist(dest)) {
-               AlertValue aval;
-
-               aval = alertpanel(_("Overwrite"),
-                                 _("Overwrite existing file?"),
-                                 _("OK"), _("Cancel"), NULL);
-               if (G_ALERTDEFAULT != aval) return;
+               aval = alertpanel(_("Append or Overwrite"),
+                                 _("Append or overwrite existing file?"),
+                                 _("Append"), _("Overwrite"), _("Cancel"));
+               if (aval!=0 && aval!=1) return;
        }
 
        src = procmsg_get_message_file(msginfo);
-       if (copy_file(src, dest, TRUE) < 0) {
-               alertpanel_error(_("Can't save the file `%s'."),
-                                g_basename(dest));
+       if ( aval==0 ) { /* append */
+               if (append_file(src, dest, TRUE) < 0) 
+                       alertpanel_error(_("Can't save the file `%s'."),
+                                        g_basename(dest));
+       } else { /* overwrite */
+               if (copy_file(src, dest, TRUE) < 0)
+                       alertpanel_error(_("Can't save the file `%s'."),
+                                        g_basename(dest));
        }
        g_free(src);
+
+       
+       /*
+        * If two or more msgs are selected,
+        * append them to the output file.
+        */
+       if (GTK_CLIST(ctree)->selection->next) {
+               GList *item;
+               for (item = GTK_CLIST(ctree)->selection->next; item != NULL; item=item->next) {
+                       msginfo = gtk_ctree_node_get_row_data(ctree, (GtkCTreeNode*)item->data);
+                       if (!msginfo) break;
+                       src = procmsg_get_message_file(msginfo);
+                       if (append_file(src, dest, TRUE) < 0)
+                               alertpanel_error(_("Can't save the file `%s'."),
+                                                g_basename(dest));
+               }
+               g_free(src);
+       }
 }
 
 void summary_print(SummaryView *summaryview)
index ae24967..df158ec 100644 (file)
@@ -2000,6 +2000,65 @@ gint copy_file(const gchar *src, const gchar *dest)
 }
 #endif
 
+
+/*
+ * Append src file body to the tail of dest file.
+ * Now keep_backup has no effects.
+ */
+gint append_file(const gchar *src, const gchar *dest, gboolean keep_backup)
+{
+       FILE *src_fp, *dest_fp;
+       gint n_read;
+       gchar buf[BUFSIZ];
+
+       gboolean err = FALSE;
+
+       if ((src_fp = fopen(src, "rb")) == NULL) {
+               FILE_OP_ERROR(src, "fopen");
+               return -1;
+       }
+       
+       if ((dest_fp = fopen(dest, "ab")) == NULL) {
+               FILE_OP_ERROR(dest, "fopen");
+               fclose(src_fp);
+               return -1;
+       }
+
+       if (change_file_mode_rw(dest_fp, dest) < 0) {
+               FILE_OP_ERROR(dest, "chmod");
+               g_warning(_("can't change file mode\n"));
+       }
+
+       while ((n_read = fread(buf, sizeof(gchar), sizeof(buf), src_fp)) > 0) {
+               if (n_read < sizeof(buf) && ferror(src_fp))
+                       break;
+               if (fwrite(buf, n_read, 1, dest_fp) < 1) {
+                       g_warning(_("writing to %s failed.\n"), dest);
+                       fclose(dest_fp);
+                       fclose(src_fp);
+                       unlink(dest);
+                       return -1;
+               }
+       }
+
+       if (ferror(src_fp)) {
+               FILE_OP_ERROR(src, "fread");
+               err = TRUE;
+       }
+       fclose(src_fp);
+       if (fclose(dest_fp) == EOF) {
+               FILE_OP_ERROR(dest, "fclose");
+               err = TRUE;
+       }
+
+       if (err) {
+               unlink(dest);
+               return -1;
+       }
+
+       return 0;
+}
+
 gint copy_file(const gchar *src, const gchar *dest, gboolean keep_backup)
 {
        FILE *src_fp, *dest_fp;
index fa7ee02..d2344d5 100644 (file)
@@ -330,6 +330,9 @@ gint remove_all_numbered_files      (const gchar    *dir);
 gint remove_expired_files      (const gchar    *dir,
                                 guint           hours);
 gint remove_dir_recursive      (const gchar    *dir);
+gint append_file               (const gchar    *src,
+                                const gchar    *dest,
+                                gboolean        keep_backup);
 gint copy_file                 (const gchar    *src,
                                 const gchar    *dest,
                                 gboolean        keep_backup);