Add preference to allow disabling automatic drafting of encrypted
authorColin Leroy <colin@colino.net>
Fri, 20 Dec 2013 10:53:18 +0000 (11:53 +0100)
committerColin Leroy <colin@colino.net>
Fri, 20 Dec 2013 10:53:18 +0000 (11:53 +0100)
messages.

src/compose.c
src/prefs_common.c
src/prefs_common.h
src/prefs_compose_writing.c

index 48170ae..69bfac6 100644 (file)
@@ -10055,6 +10055,14 @@ void compose_close_toolbar(Compose *compose)
        compose_close_cb(NULL, compose);
 }
 
+static gboolean compose_can_autosave(Compose *compose)
+{
+       if (compose->privacy_system && compose->use_encryption)
+               return prefs_common.autosave && prefs_common.autosave_encrypted;
+       else
+               return prefs_common.autosave;
+}
+
 static void compose_close_cb(GtkAction *action, gpointer data)
 {
        Compose *compose = (Compose *)data;
@@ -10089,8 +10097,8 @@ static void compose_close_cb(GtkAction *action, gpointer data)
                g_mutex_unlock(compose->mutex);
                switch (val) {
                case G_ALERTDEFAULT:
-                       if (prefs_common.autosave && !reedit)
-                               compose_remove_draft(compose);                  
+                       if (compose_can_autosave(compose) && !reedit)
+                               compose_remove_draft(compose);
                        break;
                case G_ALERTALTERNATE:
                        compose_draft(data, COMPOSE_QUIT_EDITING);
@@ -11306,7 +11314,7 @@ static void text_inserted(GtkTextBuffer *buffer, GtkTextIter *iter,
                                          compose);
        g_signal_stop_emission_by_name(G_OBJECT(buffer), "insert-text");
 
-       if (prefs_common.autosave && 
+       if (compose_can_autosave(compose) && 
            gtk_text_buffer_get_char_count(buffer) % prefs_common.autosave_length == 0 &&
            compose->draft_timeout_tag != -2 /* disabled while loading */)
                compose->draft_timeout_tag = g_timeout_add
index c42bbb8..09680b3 100644 (file)
@@ -239,6 +239,8 @@ static PrefParam param[] = {
         P_BOOL, NULL, NULL, NULL},
         {"autosave_length", "50", &prefs_common.autosave_length, P_INT,
         NULL, NULL, NULL},
+        {"autosave_encrypted", "TRUE", &prefs_common.autosave_encrypted,
+        P_BOOL, 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,
index 16966c8..11b3e55 100644 (file)
@@ -150,6 +150,7 @@ struct _PrefsCommon
        gboolean show_ruler;
        gboolean autosave;
        gint autosave_length;
+       gboolean autosave_encrypted;
        gboolean warn_large_insert;
        gint warn_large_insert_size;
        gboolean compose_no_markup;
index 6248121..46dd621 100644 (file)
@@ -63,6 +63,7 @@ typedef struct _WritingPage
        GtkWidget *checkbtn_redirect_keep_from;
        GtkWidget *checkbtn_autosave;
        GtkWidget *spinbtn_autosave_length;
+       GtkWidget *checkbtn_autosave_encrypted;
        GtkWidget *checkbtn_warn_large_insert;
        GtkWidget *spinbtn_warn_large_insert_size;
        GtkWidget *optmenu_dnd_insert_or_attach;
@@ -106,7 +107,10 @@ static void prefs_compose_writing_create_widget(PrefsPage *_page, GtkWindow *win
        GtkAdjustment *spinbtn_autosave_adj;
        GtkWidget *spinbtn_autosave_length;
        GtkWidget *label_autosave_length;
-       
+
+       GtkWidget *hbox_autosave_encrypted;
+       GtkWidget *checkbtn_autosave_encrypted;
+
        GtkWidget *hbox_dnd_insert_or_attach;
        GtkWidget *label_dnd_insert_or_attach;
        GtkWidget *optmenu_dnd_insert_or_attach;
@@ -154,11 +158,20 @@ static void prefs_compose_writing_create_widget(PrefsPage *_page, GtkWindow *win
        gtk_widget_show (spinbtn_autosave_length);
        gtk_box_pack_start (GTK_BOX (hbox_autosave), spinbtn_autosave_length, FALSE, FALSE, 0);
        gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_autosave_length), TRUE);
-       
+
        label_autosave_length = gtk_label_new(_("characters"));
        gtk_widget_show (label_autosave_length);
        gtk_box_pack_start (GTK_BOX (hbox_autosave), label_autosave_length, FALSE, FALSE, 0);
-       
+
+       /* Editing: automatically save draft when encrypted */
+       hbox_autosave_encrypted = gtk_hbox_new (FALSE, 8);
+       gtk_box_pack_start(GTK_BOX(hbox_autosave_encrypted), gtk_label_new("   "), FALSE, FALSE, 0);
+       gtk_widget_show_all (hbox_autosave_encrypted);
+       gtk_box_pack_start (GTK_BOX (vbox2), hbox_autosave_encrypted, FALSE, FALSE, 0);
+
+       PACK_CHECK_BUTTON (hbox_autosave_encrypted, checkbtn_autosave_encrypted,
+                          _("Even if message is to be encrypted"));
+
        /* Editing: undo level */
        hbox_undolevel = gtk_hbox_new (FALSE, 8);
        gtk_widget_show (hbox_undolevel);
@@ -240,6 +253,7 @@ 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_autosave, checkbtn_autosave_encrypted);
 
        SET_TOGGLE_SENSITIVITY (checkbtn_warn_large_insert, spinbtn_warn_large_insert_size);
        SET_TOGGLE_SENSITIVITY (checkbtn_warn_large_insert, label_warn_large_insert_size);
@@ -256,6 +270,8 @@ 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_autosave_encrypted     = checkbtn_autosave_encrypted;
+
        prefs_writing->checkbtn_warn_large_insert = checkbtn_warn_large_insert;
        prefs_writing->spinbtn_warn_large_insert_size = spinbtn_warn_large_insert_size;
        
@@ -276,6 +292,8 @@ static void prefs_compose_writing_create_widget(PrefsPage *_page, GtkWindow *win
                prefs_common.redirect_keep_from);
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_writing->checkbtn_autosave),
                prefs_common.autosave);
+       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_writing->checkbtn_autosave_encrypted),
+               prefs_common.autosave_encrypted);
        gtk_spin_button_set_value(GTK_SPIN_BUTTON(prefs_writing->spinbtn_autosave_length),
                prefs_common.autosave_length);
        gtk_spin_button_set_value(GTK_SPIN_BUTTON(prefs_writing->spinbtn_undolevel),
@@ -312,6 +330,8 @@ static void prefs_compose_writing_save(PrefsPage *_page)
                gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_redirect_keep_from));
        prefs_common.autosave = 
                gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_autosave));
+       prefs_common.autosave_encrypted = 
+               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page->checkbtn_autosave_encrypted));
        prefs_common.autosave_length =
                gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(page->spinbtn_autosave_length));
        prefs_common.undolevels =