[geary] Configure saving drafts on/off per account: Bug #726728



commit 9741f648728a193ba8bf6dff330e93f275757159
Author: Jim Nelson <jim yorba org>
Date:   Tue May 27 18:41:43 2014 -0700

    Configure saving drafts on/off per account: Bug #726728
    
    Saving drafts may not be configured per-account.  This is to assist
    users who (a) are using Gmail clients that include trashed messages
    in their conversations (which is where Geary's drafts wind up when
    discarded) or (b) Gmail users where, for unexplained reasons, Geary
    can't expunge their draft messages (bug #729136).

 src/client/accounts/add-edit-page.vala        |   19 +++++-
 src/client/composer/composer-widget.vala      |    6 ++-
 src/engine/api/geary-account-information.vala |    8 ++
 ui/login.glade                                |   90 +++++++++++++++----------
 4 files changed, 85 insertions(+), 38 deletions(-)
---
diff --git a/src/client/accounts/add-edit-page.vala b/src/client/accounts/add-edit-page.vala
index 2a5539a..c59f274 100644
--- a/src/client/accounts/add-edit-page.vala
+++ b/src/client/accounts/add-edit-page.vala
@@ -126,7 +126,12 @@ public class AddEditPage : Gtk.Box {
         get { return check_smtp_noauth.active; }
         set { check_smtp_noauth.active = value; }
     }
-
+    
+    public bool save_drafts { 
+        get { return check_save_drafts.active; }
+        set { check_save_drafts.active = value; }
+    }
+    
     // these are tied to the values in the Glade file
     private enum Encryption {
         NONE = 0,
@@ -168,7 +173,9 @@ public class AddEditPage : Gtk.Box {
     private Gtk.ComboBox combo_smtp_encryption;
     private Gtk.CheckButton check_smtp_use_imap_credentials;
     private Gtk.CheckButton check_smtp_noauth;
-
+    
+    private Gtk.CheckButton check_save_drafts;
+    
     private string smtp_username_store;
     private string smtp_password_store;
     
@@ -245,6 +252,7 @@ public class AddEditPage : Gtk.Box {
         combo_smtp_encryption = (Gtk.ComboBox) builder.get_object("combo: smtp encryption");
         check_smtp_use_imap_credentials = (Gtk.CheckButton) builder.get_object("check: use imap 
credentials");
         check_smtp_noauth = (Gtk.CheckButton) builder.get_object("check: smtp no authentication");
+        check_save_drafts = (Gtk.CheckButton) builder.get_object("check: save_drafts"); 
 
         // Build list of service providers.
         foreach (Geary.ServiceProvider p in Geary.ServiceProvider.get_providers())
@@ -270,6 +278,7 @@ public class AddEditPage : Gtk.Box {
         entry_smtp_password.changed.connect(on_changed);
         check_smtp_use_imap_credentials.toggled.connect(on_changed);
         check_smtp_noauth.toggled.connect(on_changed);
+        check_save_drafts.toggled.connect(on_changed);
         
         entry_email.changed.connect(on_email_changed);
         entry_password.changed.connect(on_password_changed);
@@ -313,6 +322,7 @@ public class AddEditPage : Gtk.Box {
             info.default_smtp_use_imap_credentials,
             info.default_smtp_server_noauth,
             info.prefetch_period_days,
+            info.save_drafts,
             result);
     }
     
@@ -340,6 +350,7 @@ public class AddEditPage : Gtk.Box {
         bool initial_default_smtp_use_imap_credentials = false,
         bool initial_default_smtp_noauth = false,
         int prefetch_period_days = Geary.AccountInformation.DEFAULT_PREFETCH_PERIOD_DAYS,
+        bool initial_save_drafts = true,
         Geary.Engine.ValidationResult result = Geary.Engine.ValidationResult.OK) {
         
         // Set defaults
@@ -372,6 +383,8 @@ public class AddEditPage : Gtk.Box {
         smtp_use_imap_credentials = initial_default_smtp_use_imap_credentials;
         smtp_noauth = initial_default_smtp_noauth;
         
+        save_drafts = initial_save_drafts;
+        
         set_validation_result(result);
         
         set_storage_length(prefetch_period_days);
@@ -594,6 +607,7 @@ public class AddEditPage : Gtk.Box {
         account_information.default_smtp_use_imap_credentials = smtp_use_imap_credentials;
         account_information.default_smtp_server_noauth = smtp_noauth;
         account_information.prefetch_period_days = get_storage_length();
+        account_information.save_drafts = save_drafts;
         
         if (smtp_noauth)
             account_information.smtp_credentials = null;
@@ -620,6 +634,7 @@ public class AddEditPage : Gtk.Box {
         entry_nickname.visible = label_nickname.visible = mode != PageMode.WELCOME;
         storage_container.visible = mode == PageMode.EDIT;
         check_save_sent_mail.visible = mode == PageMode.EDIT;
+        check_save_drafts.visible = mode == PageMode.EDIT;
         
         if (get_service_provider() == Geary.ServiceProvider.OTHER) {
             // Display all options for custom providers.
diff --git a/src/client/composer/composer-widget.vala b/src/client/composer/composer-widget.vala
index 35f7bed..593335e 100644
--- a/src/client/composer/composer-widget.vala
+++ b/src/client/composer/composer-widget.vala
@@ -795,7 +795,8 @@ public class ComposerWidget : Gtk.EventBox {
     
     private bool can_save() {
         return (drafts_folder != null && drafts_folder.get_open_state() == Geary.Folder.OpenState.BOTH
-            && !drafts_folder.properties.create_never_returns_id && editor.can_undo());
+            && !drafts_folder.properties.create_never_returns_id && editor.can_undo()
+            && account.information.save_drafts);
     }
 
     public CloseStatus should_close() {
@@ -945,6 +946,9 @@ public class ComposerWidget : Gtk.EventBox {
     private async void open_drafts_folder_async(Cancellable cancellable) throws Error {
         yield close_drafts_folder_async(cancellable);
         
+        if (!account.information.save_drafts)
+            return;
+        
         Geary.FolderSupport.Create? folder = (yield account.get_required_special_folder_async(
             Geary.SpecialFolderType.DRAFTS, cancellable)) as Geary.FolderSupport.Create;
         
diff --git a/src/engine/api/geary-account-information.vala b/src/engine/api/geary-account-information.vala
index 0c0e4e9..9c3155d 100644
--- a/src/engine/api/geary-account-information.vala
+++ b/src/engine/api/geary-account-information.vala
@@ -32,6 +32,7 @@ public class Geary.AccountInformation : BaseObject {
     private const string SENT_MAIL_FOLDER_KEY = "sent_mail_folder";
     private const string SPAM_FOLDER_KEY = "spam_folder";
     private const string TRASH_FOLDER_KEY = "trash_folder";
+    private const string SAVE_DRAFTS_KEY = "save_drafts";
     
     //
     // "Retired" keys
@@ -97,6 +98,8 @@ public class Geary.AccountInformation : BaseObject {
     public Geary.Credentials? smtp_credentials { get; set; default = new Geary.Credentials(null, null); }
     public bool smtp_remember_password { get; set; default = true; }
     
+    public bool save_drafts { get; set; default = true; }
+    
     private bool _save_sent_mail = true;
     
     // Used to create temporary AccountInformation objects.  (Note that these cannot be saved.)
@@ -165,6 +168,8 @@ public class Geary.AccountInformation : BaseObject {
                 key_file, GROUP, SPAM_FOLDER_KEY));
             trash_folder_path = build_folder_path(get_string_list_value(
                 key_file, GROUP, TRASH_FOLDER_KEY));
+            
+            save_drafts = get_bool_value(key_file, GROUP, SAVE_DRAFTS_KEY, true);
         }
     }
     
@@ -195,6 +200,7 @@ public class Geary.AccountInformation : BaseObject {
         sent_mail_folder_path = from.sent_mail_folder_path;
         spam_folder_path = from.spam_folder_path;
         trash_folder_path = from.trash_folder_path;
+        save_drafts = from.save_drafts;
     }
     
     /**
@@ -605,6 +611,8 @@ public class Geary.AccountInformation : BaseObject {
         key_file.set_string_list(GROUP, TRASH_FOLDER_KEY, (trash_folder_path != null
             ? trash_folder_path.as_list().to_array() : new string[] {}));
         
+        key_file.set_boolean(GROUP, SAVE_DRAFTS_KEY, save_drafts);
+        
         string data = key_file.to_data();
         string new_etag;
         
diff --git a/ui/login.glade b/ui/login.glade
index 91e12c4..a971933 100644
--- a/ui/login.glade
+++ b/ui/login.glade
@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.16.1 -->
 <interface>
-  <!-- interface-requires gtk+ 3.0 -->
+  <requires lib="gtk+" version="3.0"/>
   <object class="GtkBox" id="container">
     <property name="visible">True</property>
     <property name="can_focus">False</property>
@@ -292,6 +293,26 @@
           </packing>
         </child>
         <child>
+          <object class="GtkCheckButton" id="check: save_drafts">
+            <property name="label" translatable="yes">Save dra_fts on server</property>
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="receives_default">False</property>
+            <property name="use_underline">True</property>
+            <property name="xalign">0</property>
+            <property name="draw_indicator">True</property>
+          </object>
+          <packing>
+            <property name="left_attach">1</property>
+            <property name="top_attach">7</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+        <child>
+          <placeholder/>
+        </child>
+        <child>
           <placeholder/>
         </child>
         <child>
@@ -340,9 +361,9 @@
                 <property name="label" translatable="yes">Se_rver</property>
                 <property name="use_underline">True</property>
                 <property name="mnemonic_widget">entry: imap host</property>
-            <style>
-              <class name="dim-label"/>
-            </style>
+                <style>
+                  <class name="dim-label"/>
+                </style>
               </object>
               <packing>
                 <property name="left_attach">0</property>
@@ -376,9 +397,9 @@
                 <property name="label" translatable="yes">P_ort</property>
                 <property name="use_underline">True</property>
                 <property name="mnemonic_widget">entry: imap port</property>
-            <style>
-              <class name="dim-label"/>
-            </style>
+                <style>
+                  <class name="dim-label"/>
+                </style>
               </object>
               <packing>
                 <property name="left_attach">2</property>
@@ -395,10 +416,9 @@
                 <property name="activates_default">True</property>
                 <property name="width_chars">5</property>
                 <property name="text">993</property>
-                <property name="invisible_char_set">True</property>
-            <style>
-              <class name="dim-label"/>
-            </style>
+                <style>
+                  <class name="dim-label"/>
+                </style>
               </object>
               <packing>
                 <property name="left_attach">3</property>
@@ -449,9 +469,9 @@
                 <property name="label" translatable="yes">Ser_ver</property>
                 <property name="use_underline">True</property>
                 <property name="mnemonic_widget">entry: smtp host</property>
-            <style>
-              <class name="dim-label"/>
-            </style>
+                <style>
+                  <class name="dim-label"/>
+                </style>
               </object>
               <packing>
                 <property name="left_attach">0</property>
@@ -469,9 +489,9 @@
                 <property name="label" translatable="yes">Por_t</property>
                 <property name="use_underline">True</property>
                 <property name="mnemonic_widget">entry: smtp port</property>
-            <style>
-              <class name="dim-label"/>
-            </style>
+                <style>
+                  <class name="dim-label"/>
+                </style>
               </object>
               <packing>
                 <property name="left_attach">2</property>
@@ -508,9 +528,9 @@
                 <property name="label" translatable="yes">User_name</property>
                 <property name="use_underline">True</property>
                 <property name="mnemonic_widget">entry: smtp username</property>
-            <style>
-              <class name="dim-label"/>
-            </style>
+                <style>
+                  <class name="dim-label"/>
+                </style>
               </object>
               <packing>
                 <property name="left_attach">0</property>
@@ -528,9 +548,9 @@
                 <property name="label" translatable="yes">Pass_word</property>
                 <property name="use_underline">True</property>
                 <property name="mnemonic_widget">entry: smtp password</property>
-            <style>
-              <class name="dim-label"/>
-            </style>
+                <style>
+                  <class name="dim-label"/>
+                </style>
               </object>
               <packing>
                 <property name="left_attach">0</property>
@@ -579,9 +599,9 @@
                 <property name="label" translatable="yes">_Username</property>
                 <property name="use_underline">True</property>
                 <property name="mnemonic_widget">entry: imap username</property>
-            <style>
-              <class name="dim-label"/>
-            </style>
+                <style>
+                  <class name="dim-label"/>
+                </style>
               </object>
               <packing>
                 <property name="left_attach">0</property>
@@ -599,9 +619,9 @@
                 <property name="label" translatable="yes">_Password</property>
                 <property name="use_underline">True</property>
                 <property name="mnemonic_widget">entry: imap password</property>
-            <style>
-              <class name="dim-label"/>
-            </style>
+                <style>
+                  <class name="dim-label"/>
+                </style>
               </object>
               <packing>
                 <property name="left_attach">0</property>
@@ -652,9 +672,9 @@
                 <property name="use_underline">True</property>
                 <property name="justify">center</property>
                 <property name="mnemonic_widget">combo: imap encryption</property>
-            <style>
-              <class name="dim-label"/>
-            </style>
+                <style>
+                  <class name="dim-label"/>
+                </style>
               </object>
               <packing>
                 <property name="left_attach">0</property>
@@ -674,9 +694,9 @@
                 <property name="use_underline">True</property>
                 <property name="justify">fill</property>
                 <property name="mnemonic_widget">combo: smtp encryption</property>
-            <style>
-              <class name="dim-label"/>
-            </style>
+                <style>
+                  <class name="dim-label"/>
+                </style>
               </object>
               <packing>
                 <property name="left_attach">0</property>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]