2009-08-21 [colin] 3.7.2cvs22
authorColin Leroy <colin@colino.net>
Fri, 21 Aug 2009 15:56:29 +0000 (15:56 +0000)
committerColin Leroy <colin@colino.net>
Fri, 21 Aug 2009 15:56:29 +0000 (15:56 +0000)
* src/compose.c
* src/prefs_common.c
* src/prefs_common.h
* src/prefs_compose_writing.c
* src/common/utils.c
Fix bug 1986, "New feature: warn user when inserting
a large file in the message body". Patch by Didier
Barvaux

ChangeLog
PATCHSETS
configure.ac
src/common/utils.c
src/compose.c
src/prefs_common.c
src/prefs_common.h
src/prefs_compose_writing.c

index a809f35..7be1fc3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,10 +1,21 @@
+2009-08-21 [colin]     3.7.2cvs22
+
+       * src/compose.c
+       * src/prefs_common.c
+       * src/prefs_common.h
+       * src/prefs_compose_writing.c
+       * src/common/utils.c
+               Fix bug 1986, "New feature: warn user when inserting 
+               a large file in the message body". Patch by Didier
+               Barvaux
+
 2009-08-21 [colin]     3.7.2cvs21
 
        * AUTHORS
        * src/gtk/authors.h
        * src/common/utils.c
-               Add Réf. : reply prefix (french Lotus Notes); patch
-               by Didier Barvaux
+               Fix bug 1984: Add Réf. : reply prefix (french 
+               Lotus Notes); patch by Didier Barvaux
 
 2009-08-21 [colin]     3.7.2cvs20
 
index 29a8832..16b9530 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( cvs diff -u -r 1.382.2.519 -r 1.382.2.520 src/compose.c;  cvs diff -u -r 1.50.2.54 -r 1.50.2.55 src/compose.h;  ) > 3.7.2cvs19.patchset
 ( cvs diff -u -r 1.65.2.68 -r 1.65.2.69 src/codeconv.c;  cvs diff -u -r 1.15.2.22 -r 1.15.2.23 src/codeconv.h;  ) > 3.7.2cvs20.patchset
 ( cvs diff -u -r 1.100.2.72 -r 1.100.2.73 AUTHORS;  cvs diff -u -r 1.1.2.60 -r 1.1.2.61 src/gtk/authors.h;  cvs diff -u -r 1.36.2.172 -r 1.36.2.173 src/common/utils.c;  ) > 3.7.2cvs21.patchset
+( cvs diff -u -r 1.382.2.520 -r 1.382.2.521 src/compose.c;  cvs diff -u -r 1.204.2.191 -r 1.204.2.192 src/prefs_common.c;  cvs diff -u -r 1.103.2.124 -r 1.103.2.125 src/prefs_common.h;  cvs diff -u -r 1.1.2.26 -r 1.1.2.27 src/prefs_compose_writing.c;  cvs diff -u -r 1.36.2.173 -r 1.36.2.174 src/common/utils.c;  ) > 3.7.2cvs22.patchset
index d6de5cb..7411836 100644 (file)
@@ -12,7 +12,7 @@ MINOR_VERSION=7
 MICRO_VERSION=2
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=21
+EXTRA_VERSION=22
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
index d99c44e..8b80f8f 100644 (file)
@@ -346,6 +346,13 @@ gchar *itos(gint n)
        d = (d*100) >> divisor;         \
 }
 
+
+/*!
+ * \brief Convert a given size in bytes in a human-readable string
+ *
+ * \param size  The size expressed in bytes to convert in string
+ * \return      The string that respresents the size in an human-readable way
+ */
 gchar *to_human_readable(goffset size)
 {
        static gchar str[14];
index d8e6e26..45a0e11 100644 (file)
@@ -9379,15 +9379,60 @@ static void compose_insert_file_cb(GtkAction *action, gpointer data)
                        gchar *file = (gchar *) tmp->data;
                        gchar *filedup = g_strdup(file);
                        gchar *shortfile = g_path_get_basename(filedup);
+                       struct stat file_stat;
+                       gboolean do_insert;
                        ComposeInsertResult res;
+                       int ret;
+
+                       do_insert = TRUE;
+
+                       /* get the size of the file we are about to insert */
+                       ret = g_stat(file, &file_stat);
+                       if (ret != 0) {
+                               alertpanel_error(_("Could not get size of file '%s'."), shortfile);
+                               do_insert = FALSE;
+                       } else if (prefs_common.warn_large_insert == TRUE) {
+
+                               /* ask user for confirmation if the file is large */
+                               if (prefs_common.warn_large_insert_size < 0 ||
+                                   file_stat.st_size > (prefs_common.warn_large_insert_size * 1024)) {
+                                       AlertValue aval;
+                                       gchar *msg;
+                                       
+                                       msg = g_strdup_printf(_("You are about to insert a file of %s "
+                                                               "in the message body. Are your sure to do that?"),
+                                                               to_human_readable(file_stat.st_size));
+                                       aval = alertpanel_full(_("Are you sure?"), msg, GTK_STOCK_CANCEL,
+                                                       _("+_Insert"), NULL, TRUE, NULL, ALERT_QUESTION, G_ALERTDEFAULT);
+                                       g_free(msg);
+
+                                       /* do we ask for confirmation next time? */
+                                       if (aval & G_ALERTDISABLE) {
+                                               /* no confirmation next time, disable feature in preferences */
+                                               aval &= ~G_ALERTDISABLE;
+                                               prefs_common.warn_large_insert = FALSE;
+                                       }
 
-                       res = compose_insert_file(compose, file);
-                       if (res == COMPOSE_INSERT_READ_ERROR) {
-                               alertpanel_error(_("File '%s' could not be read."), shortfile);
-                       } else if (res == COMPOSE_INSERT_INVALID_CHARACTER) {
-                               alertpanel_error(_("File '%s' contained invalid characters\n"
-                                                  "for the current encoding, insertion may be incorrect."), shortfile);
+                                       /* abort file insertion if user canceled action */
+                                       if (aval != G_ALERTALTERNATE) {
+                                               do_insert = FALSE;
+                                       }
+                               }
                        }
+
+                       /* insert the file if the file is short or if the user confirmed that
+                          he/she wants to insert the large file */
+                       if (do_insert) {
+                               res = compose_insert_file(compose, file);
+                               if (res == COMPOSE_INSERT_READ_ERROR) {
+                                       alertpanel_error(_("File '%s' could not be read."), shortfile);
+                               } else if (res == COMPOSE_INSERT_INVALID_CHARACTER) {
+                                       alertpanel_error(_("File '%s' contained invalid characters\n"
+                                                               "for the current encoding, insertion may be incorrect."),
+                                                               shortfile);
+                               }
+                       }
+
                        g_free(shortfile);
                        g_free(filedup);
                        g_free(file);
index 7ed07c9..bada8ee 100644 (file)
@@ -243,6 +243,10 @@ static PrefParam param[] = {
         P_BOOL, NULL, NULL, NULL},
         {"autosave_length", "50", &prefs_common.autosave_length, P_INT,
         NULL, NULL, NULL},
+        {"warn_large_insert", "TRUE", &prefs_common.warn_large_insert,
+        P_BOOL, NULL, NULL, NULL},
+        {"warn_large_insert_size", "500", &prefs_common.warn_large_insert_size,
+        P_INT, NULL, NULL, NULL},
 
        {"enable_aspell", "TRUE", &prefs_common.enable_aspell, P_BOOL,
         NULL, NULL, NULL},
index 5cbcc76..e091671 100644 (file)
@@ -150,6 +150,8 @@ struct _PrefsCommon
        gboolean show_ruler;
        gboolean autosave;
        gint autosave_length;
+       gboolean warn_large_insert;
+       gint warn_large_insert_size;
        gboolean compose_no_markup;
        ComposeDndInsertOrAttach compose_dnd_mode;
        gboolean compose_with_format;
index 64bab72..18079d9 100644 (file)
@@ -60,9 +60,10 @@ typedef struct _WritingPage
        GtkWidget *checkbtn_default_reply_list;
        GtkWidget *checkbtn_forward_as_attachment;
        GtkWidget *checkbtn_redirect_keep_from;
-       GtkWidget *hbox_autosave;
        GtkWidget *checkbtn_autosave;
        GtkWidget *spinbtn_autosave_length;
+       GtkWidget *checkbtn_warn_large_insert;
+       GtkWidget *spinbtn_warn_large_insert_size;
        GtkWidget *optmenu_dnd_insert_or_attach;
 } WritingPage;
 
@@ -87,6 +88,12 @@ static void prefs_compose_writing_create_widget(PrefsPage *_page, GtkWindow *win
        GtkObject *spinbtn_undolevel_adj;
        GtkWidget *spinbtn_undolevel;
 
+       GtkWidget *hbox_warn_large_insert;
+       GtkWidget *checkbtn_warn_large_insert;
+       GtkObject *spinbtn_warn_large_insert_adj;
+       GtkWidget *spinbtn_warn_large_insert_size;
+       GtkWidget *label_warn_large_insert_size;
+
        GtkWidget *checkbtn_reply_with_quote;
        GtkWidget *checkbtn_default_reply_list;
 
@@ -124,11 +131,14 @@ static void prefs_compose_writing_create_widget(PrefsPage *_page, GtkWindow *win
        PACK_CHECK_BUTTON (hbox_autosel, checkbtn_reedit_account_autosel,
                           _("when re-editing"));
 
+       /* Editing */
        vbox2 = gtkut_get_options_frame(vbox1, &frame, _("Editing"));
 
+       /* Editing: automatically start the text editor */
        PACK_CHECK_BUTTON (vbox2, checkbtn_autoextedit,
                           _("Automatically launch the external editor"));
 
+       /* Editing: automatically save draft */
        hbox_autosave = gtk_hbox_new (FALSE, 8);
        gtk_widget_show (hbox_autosave);
        gtk_box_pack_start (GTK_BOX (vbox2), hbox_autosave, FALSE, FALSE, 0);
@@ -148,6 +158,7 @@ static void prefs_compose_writing_create_widget(PrefsPage *_page, GtkWindow *win
        gtk_widget_show (label_autosave_length);
        gtk_box_pack_start (GTK_BOX (hbox_autosave), label_autosave_length, FALSE, FALSE, 0);
        
+       /* Editing: undo level */
        hbox_undolevel = gtk_hbox_new (FALSE, 8);
        gtk_widget_show (hbox_undolevel);
        gtk_box_pack_start (GTK_BOX (vbox2), hbox_undolevel, FALSE, FALSE, 0);
@@ -163,7 +174,31 @@ static void prefs_compose_writing_create_widget(PrefsPage *_page, GtkWindow *win
        gtk_box_pack_start (GTK_BOX (hbox_undolevel), spinbtn_undolevel, FALSE, FALSE, 0);
        gtk_widget_set_size_request (spinbtn_undolevel, 64, -1);
        gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_undolevel), TRUE);
-       
+
+       /* Editing: warn when inserting large files in message body */
+       hbox_warn_large_insert = gtk_hbox_new (FALSE, 8);
+       gtk_widget_show (hbox_warn_large_insert);
+       gtk_box_pack_start (GTK_BOX (vbox2), hbox_warn_large_insert, FALSE, FALSE, 0);
+
+       PACK_CHECK_BUTTON (hbox_warn_large_insert, checkbtn_warn_large_insert,
+                          _("Warn when inserting in message body a file larger than"));
+
+       spinbtn_warn_large_insert_adj = gtk_adjustment_new (50, 0, 1000, 1, 10, 0);
+       spinbtn_warn_large_insert_size = gtk_spin_button_new
+               (GTK_ADJUSTMENT (spinbtn_warn_large_insert_adj), 1, 0);
+       gtk_widget_set_size_request (spinbtn_warn_large_insert_size, 64, -1);   
+       gtk_widget_show (spinbtn_warn_large_insert_size);
+       gtk_box_pack_start (GTK_BOX (hbox_warn_large_insert),
+                       spinbtn_warn_large_insert_size, FALSE, FALSE, 0);
+       gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_warn_large_insert_size),
+                       TRUE);
+
+       label_warn_large_insert_size = gtk_label_new(_("KB"));
+       gtk_widget_show (label_warn_large_insert_size);
+       gtk_box_pack_start (GTK_BOX (hbox_warn_large_insert),
+                       label_warn_large_insert_size, FALSE, FALSE, 0);
+
+       /* Replying */
        vbox2 = gtkut_get_options_frame(vbox1, &frame, _("Replying"));
 
        PACK_CHECK_BUTTON (vbox2, checkbtn_reply_with_quote,
@@ -205,6 +240,9 @@ static void prefs_compose_writing_create_widget(PrefsPage *_page, GtkWindow *win
        SET_TOGGLE_SENSITIVITY (checkbtn_autosave, spinbtn_autosave_length);
        SET_TOGGLE_SENSITIVITY (checkbtn_autosave, label_autosave_length);
 
+       SET_TOGGLE_SENSITIVITY (checkbtn_warn_large_insert, spinbtn_warn_large_insert_size);
+       SET_TOGGLE_SENSITIVITY (checkbtn_warn_large_insert, label_warn_large_insert_size);
+
 
        prefs_writing->checkbtn_autoextedit = checkbtn_autoextedit;
 
@@ -216,6 +254,9 @@ static void prefs_compose_writing_create_widget(PrefsPage *_page, GtkWindow *win
 
        prefs_writing->checkbtn_autosave     = checkbtn_autosave;
        prefs_writing->spinbtn_autosave_length = spinbtn_autosave_length;
+
+       prefs_writing->checkbtn_warn_large_insert = checkbtn_warn_large_insert;
+       prefs_writing->spinbtn_warn_large_insert_size = spinbtn_warn_large_insert_size;
        
        prefs_writing->checkbtn_forward_as_attachment =
                checkbtn_forward_as_attachment;
@@ -238,6 +279,10 @@ static void prefs_compose_writing_create_widget(PrefsPage *_page, GtkWindow *win
                prefs_common.autosave_length);
        gtk_spin_button_set_value(GTK_SPIN_BUTTON(prefs_writing->spinbtn_undolevel),
                prefs_common.undolevels);
+       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_writing->checkbtn_warn_large_insert),
+               prefs_common.warn_large_insert);
+       gtk_spin_button_set_value(GTK_SPIN_BUTTON(prefs_writing->spinbtn_warn_large_insert_size),
+               prefs_common.warn_large_insert_size);
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_writing->checkbtn_reply_account_autosel),
                prefs_common.reply_account_autosel);
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_writing->checkbtn_forward_account_autosel),
@@ -270,6 +315,10 @@ static void prefs_compose_writing_save(PrefsPage *_page)
                gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(page->spinbtn_autosave_length));
        prefs_common.undolevels = 
                gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(page->spinbtn_undolevel));
+       prefs_common.warn_large_insert = 
+               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_warn_large_insert));
+       prefs_common.warn_large_insert_size =
+               gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(page->spinbtn_warn_large_insert_size));
                
        prefs_common.reply_account_autosel =
                gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_reply_account_autosel));