[geary/wip/delete-folder-714357: 2/4] Making folder removal work in the basic case



commit 4ba9a0b86bcc293e3d7810fb2c04f6b795c9af7c
Author: Charles Lindsay <chaz yorba org>
Date:   Wed Feb 12 15:39:46 2014 -0800

    Making folder removal work in the basic case

 src/client/application/geary-controller.vala       |   11 ++++++++++
 src/engine/imap-db/imap-db-account.vala            |    2 +-
 .../imap-engine/imap-engine-generic-account.vala   |   21 +++++++++++++++----
 3 files changed, 28 insertions(+), 6 deletions(-)
---
diff --git a/src/client/application/geary-controller.vala b/src/client/application/geary-controller.vala
index a198bcf..c3429af 100644
--- a/src/client/application/geary-controller.vala
+++ b/src/client/application/geary-controller.vala
@@ -1230,10 +1230,21 @@ public class GearyController : Geary.BaseObject {
         
         if (unavailable != null) {
             foreach (Geary.Folder folder in unavailable) {
+                main_window.folder_list.remove_folder(folder);
+                if (folder.account == current_account) {
+                    if (main_window.main_toolbar.copy_folder_menu.has_folder(folder))
+                        main_window.main_toolbar.copy_folder_menu.remove_folder(folder);
+                    if (main_window.main_toolbar.move_folder_menu.has_folder(folder))
+                        main_window.main_toolbar.move_folder_menu.remove_folder(folder);
+                }
+                
                 if (folder.special_folder_type == Geary.SpecialFolderType.INBOX &&
                     inboxes.has_key(folder.account)) {
+                    inboxes.unset(folder.account);
                     new_messages_monitor.remove_folder(folder);
                 }
+                
+                folder.special_folder_type_changed.disconnect(on_special_folder_type_changed);
             }
         }
     }
diff --git a/src/engine/imap-db/imap-db-account.vala b/src/engine/imap-db/imap-db-account.vala
index 97892bf..19c23f7 100644
--- a/src/engine/imap-db/imap-db-account.vala
+++ b/src/engine/imap-db/imap-db-account.vala
@@ -227,7 +227,7 @@ private class Geary.ImapDB.Account : BaseObject {
             if (folder_id == Db.INVALID_ROWID)
                 return Db.TransactionOutcome.ROLLBACK;
             
-            if (do_has_children(folder_id, cancellable)) {
+            if (do_has_children(cx, folder_id, cancellable)) {
                 debug("Can't delete folder %s because it has children", folder.to_string());
                 return Db.TransactionOutcome.ROLLBACK;
             }
diff --git a/src/engine/imap-engine/imap-engine-generic-account.vala 
b/src/engine/imap-engine/imap-engine-generic-account.vala
index 87741b6..30d8465 100644
--- a/src/engine/imap-engine/imap-engine-generic-account.vala
+++ b/src/engine/imap-engine/imap-engine-generic-account.vala
@@ -633,12 +633,23 @@ private abstract class Geary.ImapEngine.GenericAccount : Geary.AbstractAccount {
         Gee.Collection<MinimalFolder> engine_added = new Gee.ArrayList<Geary.Folder>();
         engine_added.add_all(build_folders(folders_to_build));
         
-        // TODO: Remove local folders no longer available remotely.
-        foreach (Geary.Folder folder in to_remove)
-            debug(@"Need to remove folder $folder");
+        notify_folders_available_unavailable(null, to_remove);
         
-        if (engine_added.size > 0)
-            notify_folders_added_removed(sort_by_path(engine_added), null);
+        Gee.ArrayList<Geary.Folder> engine_removed = new Gee.ArrayList<Geary.Folder>();
+        foreach (Geary.Folder folder in to_remove) {
+            // TODO: sort folder paths by length, longest first
+            try {
+                debug("Locally deleting removed folder %s", folder.to_string());
+                
+                yield local.delete_folder_async(folder, cancellable);
+                engine_removed.add(folder);
+            } catch (Error e) {
+                debug("Unable to locally delete removed folder %s: %s", folder.to_string(), e.message);
+            }
+        }
+        
+        if (engine_added.size > 0 || engine_removed.size > 0)
+            notify_folders_added_removed(sort_by_path(engine_added), sort_by_path(engine_removed));
         
         // report all altered folders
         if (altered_paths.size > 0) {


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