[geary/wip/create-folders-713492] Finish up this push



commit ea25790b7d96dcf619eb5909b7e7ee55cafeb951
Author: Charles Lindsay <chaz yorba org>
Date:   Wed Feb 5 16:26:52 2014 -0800

    Finish up this push

 src/engine/api/geary-account-information.vala      |   92 ++++++++++++++++----
 .../imap-engine/imap-engine-generic-account.vala   |   72 +++------------
 2 files changed, 90 insertions(+), 74 deletions(-)
---
diff --git a/src/engine/api/geary-account-information.vala b/src/engine/api/geary-account-information.vala
index 161e71b..bd7d1b2 100644
--- a/src/engine/api/geary-account-information.vala
+++ b/src/engine/api/geary-account-information.vala
@@ -152,18 +152,14 @@ public class Geary.AccountInformation : BaseObject {
                 }
             }
             
-            drafts_folder_path = get_string_value(key_file, GROUP, DRAFTS_FOLDER_KEY);
-            if (Geary.String.is_empty_or_whitespace(drafts_folder_path))
-                drafts_folder_path = null;
-            sent_mail_folder_path = get_string_value(key_file, GROUP, SENT_MAIL_FOLDER_KEY);
-            if (Geary.String.is_empty_or_whitespace(sent_mail_folder_path))
-                sent_mail_folder_path = null;
-            spam_folder_path = get_string_value(key_file, GROUP, SPAM_FOLDER_KEY);
-            if (Geary.String.is_empty_or_whitespace(spam_folder_path))
-                spam_folder_path = null;
-            trash_folder_path = get_string_value(key_file, GROUP, TRASH_FOLDER_KEY);
-            if (Geary.String.is_empty_or_whitespace(trash_folder_path))
-                trash_folder_path = null;
+            drafts_folder_path = build_folder_path(get_string_list_value(
+                key_file, GROUP, DRAFTS_FOLDER_KEY));
+            sent_mail_folder_path = build_folder_path(get_string_list_value(
+                key_file, GROUP, SENT_MAIL_FOLDER_KEY));
+            spam_folder_path = build_folder_path(get_string_list_value(
+                key_file, GROUP, SPAM_FOLDER_KEY));
+            trash_folder_path = build_folder_path(get_string_list_value(
+                key_file, GROUP, TRASH_FOLDER_KEY));
         }
     }
     
@@ -206,6 +202,48 @@ public class Geary.AccountInformation : BaseObject {
         return service_provider != ServiceProvider.GMAIL;
     }
     
+    public Geary.FolderPath? get_special_folder_path(Geary.SpecialFolderType special) {
+        switch (special) {
+            case Geary.SpecialFolderType.DRAFTS:
+                return drafts_folder_path;
+            
+            case Geary.SpecialFolderType.SENT:
+                return sent_mail_folder_path;
+            
+            case Geary.SpecialFolderType.SPAM:
+                return spam_folder_path;
+            
+            case Geary.SpecialFolderType.TRASH:
+                return trash_folder_path;
+            
+            default:
+                assert_not_reached();
+        }
+    }
+    
+    public void set_special_folder_path(Geary.SpecialFolderType special, Geary.FolderPath? path) {
+        switch (special) {
+            case Geary.SpecialFolderType.DRAFTS:
+                drafts_folder_path = path;
+            break;
+            
+            case Geary.SpecialFolderType.SENT:
+                sent_mail_folder_path = path;
+            break;
+            
+            case Geary.SpecialFolderType.SPAM:
+                spam_folder_path = path;
+            break;
+            
+            case Geary.SpecialFolderType.TRASH:
+                trash_folder_path = path;
+            break;
+            
+            default:
+                assert_not_reached();
+        }
+    }
+    
     /**
      * Fetch the passwords for the given services.  For each service, if the
      * password is unset, use get_passwords_async() first; if the password is
@@ -432,6 +470,16 @@ public class Geary.AccountInformation : BaseObject {
         }
     }
     
+    private Geary.FolderPath? build_folder_path(Gee.List<string>? parts) {
+        if (parts == null || parts.size == 0)
+            return null;
+        
+        Geary.FolderPath path = new Imap.FolderRoot(parts[0], null);
+        for (int i = 1; i < parts.size; i++)
+            path = path.get_child(parts.get(i));
+        return path;
+    }
+    
     private string get_string_value(KeyFile key_file, string group, string key, string def = "") {
         try {
             return key_file.get_value(group, key);
@@ -442,6 +490,18 @@ public class Geary.AccountInformation : BaseObject {
         return def;
     }
     
+    private Gee.List<string> get_string_list_value(KeyFile key_file, string group, string key) {
+        try {
+            string[] list = key_file.get_string_list(group, key);
+            if (list.length > 0)
+                return new Gee.ArrayList<string>.wrap(list);
+        } catch(KeyFileError err) {
+            // Ignore.
+        }
+        
+        return new Gee.ArrayList<string>();
+    }
+    
     private bool get_bool_value(KeyFile key_file, string group, string key, bool def = false) {
         try {
             return key_file.get_boolean(group, key);
@@ -517,13 +577,13 @@ public class Geary.AccountInformation : BaseObject {
         }
         
         key_file.set_string_list(GROUP, DRAFTS_FOLDER_KEY, (drafts_folder_path != null
-            ? drafts_folder_path.as_list().to_array() : string[] { }));
+            ? drafts_folder_path.as_list().to_array() : new string[] {}));
         key_file.set_string_list(GROUP, SENT_MAIL_FOLDER_KEY, (sent_mail_folder_path != null
-            ? sent_mail_folder_path.as_list().to_array() : string[] { }));
+            ? sent_mail_folder_path.as_list().to_array() : new string[] {}));
         key_file.set_string_list(GROUP, SPAM_FOLDER_KEY, (spam_folder_path != null
-            ? spam_folder_path.as_list().to_array() : string[] { }));
+            ? spam_folder_path.as_list().to_array() : new string[] {}));
         key_file.set_string_list(GROUP, TRASH_FOLDER_KEY, (trash_folder_path != null
-            ? trash_folder_path.as_list().to_array() : string[] { }));
+            ? trash_folder_path.as_list().to_array() : new string[] {}));
         
         string data = key_file.to_data();
         string new_etag;
diff --git a/src/engine/imap-engine/imap-engine-generic-account.vala 
b/src/engine/imap-engine/imap-engine-generic-account.vala
index a1e60c8..79e892d 100644
--- a/src/engine/imap-engine/imap-engine-generic-account.vala
+++ b/src/engine/imap-engine/imap-engine-generic-account.vala
@@ -470,41 +470,15 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.AbstractAccount {
         if (folder != null)
             return folder;
         
-        string? name;
-        switch (special) {
-            case Geary.SpecialFolderType.DRAFTS:
-                name = information.drafts_folder_name;
-            break;
-            
-            case Geary.SpecialFolderType.SENT:
-                name = information.sent_mail_folder_name;
-            break;
-            
-            case Geary.SpecialFolderType.SPAM:
-                name = information.spam_folder_name;
-            break;
-            
-            case Geary.SpecialFolderType.TRASH:
-                name = information.trash_folder_name;
-            break;
-            
-            default:
-                assert_not_reached();
-        }
-        
-        Geary.FolderPath? path = null;
-        if (!Geary.String.is_empty_or_whitespace(name)) {
-            // We picked which folder to create previously, so always continue
-            // to use that name.
-            
-            // TODO: look at key file's save string array function
-            path = FolderPath.deserialize(name);
-        } else {
-            // We are picking for the first time the folder to use.
+        GenericFolder? generic_folder = null;
+        Geary.FolderPath? path = information.get_special_folder_path(special);
+        if (path == null) {
+            // This is the first time we're turning a non-special folder into a special one.
+            // After we do this, we'll record which one we picked in the account info.
             
             Gee.ArrayList<string> search_names = get_mailbox_search_names().get(special);
             foreach (string search_name in search_names) {
-                Geary.FolderPath search_path = FolderPath.deserialize(search_name);
+                Geary.FolderPath search_path = new Imap.FolderRoot(search_name, null);
                 // TODO: normalize strings before searching...
                 if (search_path in folder_map.keys) {
                     path = search_path;
@@ -513,7 +487,8 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.AbstractAccount {
             }
             if (path == null) {
                 foreach (string search_name in search_names) {
-                    Geary.FolderPath search_path = null;// TODO: Construct INBOX.path...
+                    Geary.FolderPath search_path = new Imap.FolderRoot(
+                        Imap.MailboxSpecifier.CANONICAL_INBOX_NAME, null).get_child(search_name);
                     if (search_path in folder_map.keys) {
                         path = search_path;
                         break;
@@ -522,41 +497,22 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.AbstractAccount {
             }
             
             if (path == null)
-                path = FolderPath.deserialize(search_names[0]);
+                path = new Imap.FolderRoot(search_names[0], null);
             
-            switch (special) {
-                case Geary.SpecialFolderType.DRAFTS:
-                    information.drafts_folder_name = path.serialize();
-                break;
-                
-                case Geary.SpecialFolderType.SENT:
-                    information.sent_mail_folder_name = path.serialize();
-                break;
-                
-                case Geary.SpecialFolderType.SPAM:
-                    information.spam_folder_name = path.serialize();
-                break;
-                
-                case Geary.SpecialFolderType.TRASH:
-                    information.trash_folder_name = path.serialize();
-                break;
-                
-                default:
-                    assert_not_reached();
-            }
+            information.set_special_folder_path(special, path);
             // TODO: save information?
         }
         
         if (path in folder_map.keys) {
-            folder = folder_map.get(path);
+            generic_folder = folder_map.get(path);
         } else {
             // TODO: ignore error due to already existing.
             yield remote.create_folder_async(path, cancellable);
-            folder = yield fetch_folder_async(path, cancellable);
+            generic_folder = (GenericFolder) yield fetch_folder_async(path, cancellable);
         }
         
-        folder.set_special_folder_type(special);
-        return folder;
+        generic_folder.set_special_folder_type(special);
+        return generic_folder;
     }
     
     public override async Geary.Folder get_required_special_folder_async(Geary.SpecialFolderType special,


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