* when removing an account, also remove the corresponding server_accounts
authorDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Thu, 12 Apr 2007 14:29:57 +0000 (14:29 +0000)
committerDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Thu, 12 Apr 2007 14:29:57 +0000 (14:29 +0000)
pmo-trunk-r1551

src/modest-account-mgr.c
src/modest-account-mgr.h
src/modest-ui-actions.c

index e6859df..dfaec74 100644 (file)
@@ -504,6 +504,31 @@ modest_account_mgr_remove_account (ModestAccountMgr * self,
                return FALSE;
        }
 
+       /* in case we're not deleting an account, also delete the dependent store and transport account */
+       if (!server_account) {
+               gchar *server_account_name;
+               
+               server_account_name = modest_account_mgr_get_string (self, name, MODEST_ACCOUNT_STORE_ACCOUNT,
+                                                                   FALSE);
+               if (server_account_name) {
+                       if (!modest_account_mgr_remove_account (self, server_account_name, TRUE))
+                               g_printerr ("modest: failed to remove store account '%s' (%s)\n",
+                                           server_account_name, name);
+                       g_free (server_account_name);
+               } else
+                       g_printerr ("modest: could not find the store account for %s\n", name);
+               
+               server_account_name = modest_account_mgr_get_string (self, name, MODEST_ACCOUNT_TRANSPORT_ACCOUNT,
+                                                                   FALSE);
+               if (server_account_name) {
+                       if (!modest_account_mgr_remove_account (self, server_account_name, TRUE))
+                               g_printerr ("modest: failed to remove transport account '%s' (%s)\n",
+                                           server_account_name, name);
+                       g_free (server_account_name);
+               } else
+                       g_printerr ("modest: could not find the transport account for %s\n", name);
+       }                       
+                       
        priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self);
        key = _modest_account_mgr_get_account_keyname (name, NULL, server_account);
        
index 1e2e27b..84df591 100644 (file)
@@ -151,7 +151,9 @@ gboolean modest_account_mgr_add_server_account_uri    (ModestAccountMgr *self,
  * @server_account: TRUE if the account to remove is a server account
  * @err: a #GError ptr, or NULL to ignore.
  * 
- * remove an existing account. the account with @name should already exist
+ * remove an existing account. the account with @name should already exist; note
+ * that when deleting an account, also the corresponding server accounts will
+ * be deleted
  *
  * Returns: TRUE if the creation succeeded, FALSE otherwise,
  * @err gives details in case of error
index 7a3c3ce..4894a4e 100644 (file)
@@ -289,12 +289,16 @@ modest_ui_actions_on_new_msg (GtkAction *action, ModestWindow *win)
        gchar *account_name = NULL;
        gchar *from_str = NULL;
        GError *err = NULL;
-       TnyAccount *account;
+       TnyAccount *account = NULL;
        ModestWindowMgr *mgr;
        
        account_name = g_strdup(modest_window_get_active_account (win));
        if (!account_name)
                account_name = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
+       if (!account_name) {
+               g_printerr ("modest: no account found\n");
+               goto cleanup;
+       }
        
        account = modest_tny_account_store_get_tny_account_by_account (modest_runtime_get_account_store(),
                                                                       account_name,