[geary] Use geary.ini in ~/.config/geary. Bug 741883



commit d3891021273ae663479d42a69b921fb702000fce
Author: Oskar Viljasaar <oskar viljasaar gmail com>
Date:   Mon Jul 4 23:02:28 2016 +0200

    Use geary.ini in ~/.config/geary. Bug 741883
    
    Untangle the configuration and storage directory variables by doing so.

 src/engine/api/geary-account-information.vala      |   65 ++++++++++++--------
 src/engine/api/geary-engine.vala                   |   14 +++--
 .../imap-engine/imap-engine-generic-account.vala   |    4 +-
 3 files changed, 51 insertions(+), 32 deletions(-)
---
diff --git a/src/engine/api/geary-account-information.vala b/src/engine/api/geary-account-information.vala
index 027f2d7..5eedbc8 100644
--- a/src/engine/api/geary-account-information.vala
+++ b/src/engine/api/geary-account-information.vala
@@ -58,10 +58,11 @@ public class Geary.AccountInformation : BaseObject {
      * Location account information is stored (as well as other data, including database and
      * attachment files.
      */
-    public File? settings_dir { get; private set; default = null; }
-    
+    public File? config_dir { get; private set; default = null; }
+    public File? data_dir { get; private set; default = null; }
+
     internal File? file = null;
-    
+
     //
     // IMPORTANT: When adding new properties, be sure to add them to the copy method.
     //
@@ -159,18 +160,19 @@ public class Geary.AccountInformation : BaseObject {
      */
     public signal void untrusted_host(Endpoint endpoint, Endpoint.SecurityType security,
         TlsConnection cx, Service service);
-    
+
     // Used to create temporary AccountInformation objects.  (Note that these cannot be saved.)
     public AccountInformation.temp_copy(AccountInformation copy) {
         copy_from(copy);
     }
-    
+
     // This constructor is used internally to load accounts from disk.
-    internal AccountInformation.from_file(File directory) {
-        this.email = directory.get_basename();
-        this.settings_dir = directory;
-        this.file = settings_dir.get_child(SETTINGS_FILENAME);
-        
+    internal AccountInformation.from_file(File config_directory, File data_directory) {
+        this.email = config_directory.get_basename();
+        this.config_dir = config_directory;
+        this.data_dir = data_directory;
+        this.file = config_dir.get_child(SETTINGS_FILENAME);
+
         KeyFile key_file = new KeyFile();
         try {
             key_file.load_from_file(file.get_path() ?? "", KeyFileFlags.NONE);
@@ -772,26 +774,35 @@ public class Geary.AccountInformation : BaseObject {
         
         return def;
     }
-    
+
     private uint16 get_uint16_value(KeyFile key_file, string group, string key, uint16 def = 0) {
         return (uint16) get_int_value(key_file, group, key);
     }
-    
+
     public async void store_async(Cancellable? cancellable = null) {
-        if (file == null || settings_dir == null) {
+        if (file == null || config_dir == null) {
             warning("Cannot save account, no file set.\n");
             return;
         }
-        
-        if (!settings_dir.query_exists(cancellable)) {
+
+        if (!config_dir.query_exists(cancellable)) {
             try {
-                settings_dir.make_directory_with_parents();
+                config_dir.make_directory_with_parents();
             } catch (Error err) {
-                error("Error creating settings directory for email '%s': %s", email,
+                error("Error creating configuration directory for email '%s': %s", email,
                     err.message);
             }
         }
-        
+
+        if (!data_dir.query_exists(cancellable)) {
+            try {
+                data_dir.make_directory_with_parents();
+            } catch (Error err) {
+                error("Error creating storage directory for email '%s': %s", email,
+                    err.message);
+            }
+        }
+
         if (!file.query_exists(cancellable)) {
             try {
                 yield file.create_async(FileCreateFlags.REPLACE_DESTINATION);
@@ -891,9 +902,16 @@ public class Geary.AccountInformation : BaseObject {
      * normally be invoked directly.
      */
     internal async void remove_async(Cancellable? cancellable = null) {
-        if (file == null || settings_dir == null) {
-            warning("Cannot remove account; nothing to remove\n");
-            return;
+        if (data_dir == null) {
+            warning("Cannot remove account storage directory; nothing to remove");
+        } else {
+            yield Files.recursive_delete_async(data_dir, cancellable);
+        }
+
+        if (config_dir == null) {
+            warning("Cannot remove account configuration directory; nothing to remove");
+        } else {
+            yield Files.recursive_delete_async(config_dir, cancellable);
         }
         
         try {
@@ -901,11 +919,8 @@ public class Geary.AccountInformation : BaseObject {
         } catch (Error e) {
             debug("Error clearing SMTP password: %s", e.message);
         }
-        
-        // Delete files.
-        yield Files.recursive_delete_async(settings_dir, cancellable);
     }
-    
+
     /**
      * Returns a MailboxAddress object for this account.
      */
diff --git a/src/engine/api/geary-engine.vala b/src/engine/api/geary-engine.vala
index c2d2938..462bd9f 100644
--- a/src/engine/api/geary-engine.vala
+++ b/src/engine/api/geary-engine.vala
@@ -50,6 +50,7 @@ public class Geary.Engine : BaseObject {
     }
 
     public File? user_data_dir { get; private set; default = null; }
+    public File? user_config_dir { get; private set; default = null; }
     public File? resource_dir { get; private set; default = null; }
     public Geary.CredentialsMediator? authentication_mediator { get; private set; default = null; }
     
@@ -135,7 +136,7 @@ public class Geary.Engine : BaseObject {
      * given authentication mediator will be used to retrieve all passwords
      * when necessary.
      */
-    public async void open_async(File user_data_dir, File resource_dir,
+    public async void open_async(File user_config_dir, File user_data_dir, File resource_dir,
         Geary.CredentialsMediator? authentication_mediator, Cancellable? cancellable = null) throws Error {
         // initialize *before* opening the Engine ... all initialize code should assume the Engine
         // is closed
@@ -144,6 +145,7 @@ public class Geary.Engine : BaseObject {
         if (is_open)
             throw new EngineError.ALREADY_OPEN("Geary.Engine instance already open");
         
+        this.user_config_dir = user_config_dir;
         this.user_data_dir = user_data_dir;
         this.resource_dir = resource_dir;
         this.authentication_mediator = authentication_mediator;
@@ -167,7 +169,7 @@ public class Geary.Engine : BaseObject {
         }
 
         FileEnumerator enumerator
-            = yield user_data_dir.enumerate_children_async("standard::*",
+            = yield user_config_dir.enumerate_children_async("standard::*",
                 FileQueryInfoFlags.NONE, Priority.DEFAULT, cancellable);
         
         Gee.List<AccountInformation> account_list = new Gee.ArrayList<AccountInformation>();
@@ -187,10 +189,11 @@ public class Geary.Engine : BaseObject {
             FileInfo info = info_list.nth_data(0);
             if (info.get_file_type() == FileType.DIRECTORY) {
                 // TODO: check for geary.ini
-                account_list.add(new AccountInformation.from_file(user_data_dir.get_child(info.get_name())));
+                account_list.add(new AccountInformation.from_file(user_config_dir.get_child(info.get_name()),
+                    user_data_dir.get_child(info.get_name())));
             }
         }
-        
+
         foreach(AccountInformation info in account_list)
             add_account(info);
      }
@@ -236,7 +239,8 @@ public class Geary.Engine : BaseObject {
         if (accounts.has_key(email))
             throw new EngineError.ALREADY_EXISTS("Account %s already exists", email);
 
-        return new AccountInformation.from_file(user_data_dir.get_child(email));
+        return new AccountInformation.from_file(user_config_dir.get_child(email),
+            user_data_dir.get_child(email));
     }
     
     /**
diff --git a/src/engine/imap-engine/imap-engine-generic-account.vala 
b/src/engine/imap-engine/imap-engine-generic-account.vala
index ae9077a..16e04da 100644
--- a/src/engine/imap-engine/imap-engine-generic-account.vala
+++ b/src/engine/imap-engine/imap-engine-generic-account.vala
@@ -137,7 +137,7 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.Account {
     
     private async void internal_open_async(Cancellable? cancellable) throws Error {
         try {
-            yield local.open_async(information.settings_dir, Engine.instance.resource_dir.get_child("sql"),
+            yield local.open_async(information.data_dir, Engine.instance.resource_dir.get_child("sql"),
                 cancellable);
         } catch (Error err) {
             // convert database-open errors
@@ -237,7 +237,7 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.Account {
         // get all the storage locations associated with this Account
         File db_file;
         File attachments_dir;
-        ImapDB.Account.get_imap_db_storage_locations(information.settings_dir, out db_file,
+        ImapDB.Account.get_imap_db_storage_locations(information.data_dir, out db_file,
             out attachments_dir);
         
         if (yield Files.query_exists_async(db_file, cancellable)) {


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