* Fixes NB#59753, the account that is created is now visible if it's the unique...
authorSergio Villar Senin <svillar@igalia.com>
Wed, 13 Jun 2007 11:03:46 +0000 (11:03 +0000)
committerSergio Villar Senin <svillar@igalia.com>
Wed, 13 Jun 2007 11:03:46 +0000 (11:03 +0000)
* The visible account key is removed if the currently visible account is deleted
* the View->AccountX option to view a particular account works again
* Fixed a bug when opening messages that are already opened
* The folder view now listens to account-remove signal
* refactored modest_tny_account_store_get_tny_account_by_* in a single function
* Fixed a bug when removing the visible account, now the default one is selected as the new visible account

pmo-trunk-r2198

src/modest-account-mgr-priv.h
src/modest-account-mgr.c
src/modest-init.c
src/modest-tny-account-store.c
src/modest-tny-account-store.h
src/modest-tny-account.c
src/modest-ui-actions.c
src/modest-widget-memory.c
src/widgets/modest-account-view.c
src/widgets/modest-folder-view.c

index e1411b1..eb518d1 100644 (file)
@@ -53,6 +53,7 @@ struct _ModestAccountMgrPrivate {
        /* We store these as they change, and send notifications every X seconds: */
        GSList *changed_conf_keys; 
        guint timeout;
+       gulong key_changed_handler_uid;
 };
 
 #define MODEST_ACCOUNT_MGR_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \
index 44d7421..25656ab 100644 (file)
@@ -82,6 +82,9 @@ on_key_change (ModestConf *conf, const gchar *key, ModestConfEvent event, gpoint
 {
        ModestAccountMgr *self = MODEST_ACCOUNT_MGR (user_data);
        ModestAccountMgrPrivate *priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self);
+       gboolean is_account_key;
+       gboolean is_server_account;
+       gchar* account = NULL;
 
        /* there is only one not-really-account key which will still emit
         * a signal: a change in MODEST_CONF_DEFAULT_ACCOUNT */
@@ -90,24 +93,25 @@ on_key_change (ModestConf *conf, const gchar *key, ModestConfEvent event, gpoint
                
                /* Store the key for later notification in our timeout callback.
                 * Notifying for every key change would cause unnecessary work: */
-               priv->changed_conf_keys = g_slist_append (priv->changed_conf_keys, 
+               priv->changed_conf_keys = g_slist_append (priv->changed_conf_keys,
                        (gpointer) g_strdup (key));
        }
        
-       gboolean is_account_key = FALSE;
-       gboolean is_server_account = FALSE;
-       gchar* account = _modest_account_mgr_account_from_key (key, &is_account_key, &is_server_account);
-       
+       is_account_key = FALSE;
+       is_server_account = FALSE;
+       account = _modest_account_mgr_account_from_key (key, &is_account_key, 
+                                                       &is_server_account);
+
        /* if this is not an account-related key change, ignore */
        if (!account)
                return;
 
-       /* account was removed -- emit this, even if the account was
-          disabled. This should not happen unless the user directly
-          does it in gconf */
-       if (is_account_key && event == MODEST_CONF_EVENT_KEY_UNSET) {
-               g_signal_emit (G_OBJECT(self), signals[ACCOUNT_REMOVED_SIGNAL], 0, 
-                              account, is_server_account);
+       /* account was removed. Do not emit an account removed signal
+          because it was already being done in the remove_account
+          method. Do not notify also the removal of the server
+          account keys for the same reason */
+       if ((is_account_key || is_server_account) && 
+           event == MODEST_CONF_EVENT_KEY_UNSET) {
                g_free (account);
                return;
        }
@@ -116,7 +120,7 @@ on_key_change (ModestConf *conf, const gchar *key, ModestConfEvent event, gpoint
        gboolean enabled = FALSE;
        if (is_server_account)
                enabled = TRUE;
-       else 
+       else
                enabled = modest_account_mgr_get_enabled (self, account);
 
        /* Notify is server account was changed, default account was changed
@@ -127,10 +131,9 @@ on_key_change (ModestConf *conf, const gchar *key, ModestConfEvent event, gpoint
            strcmp (key, MODEST_CONF_DEFAULT_ACCOUNT) == 0) {
                /* Store the key for later notification in our timeout callback.
                 * Notifying for every key change would cause unnecessary work: */
-               priv->changed_conf_keys = g_slist_append (NULL, 
+               priv->changed_conf_keys = g_slist_append (NULL,
                        (gpointer) g_strdup (key));
        }
-
        g_free (account);
 }
 
@@ -200,7 +203,6 @@ modest_account_mgr_init (ModestAccountMgr * obj)
                MODEST_ACCOUNT_MGR_GET_PRIVATE (obj);
 
        priv->modest_conf = NULL;
-       
        priv->timeout = g_timeout_add (1000 /* milliseconds */, on_timeout_notify_changes, obj);
 }
 
@@ -210,6 +212,12 @@ modest_account_mgr_finalize (GObject * obj)
        ModestAccountMgrPrivate *priv = 
                MODEST_ACCOUNT_MGR_GET_PRIVATE (obj);
 
+       if (priv->key_changed_handler_uid) {
+               g_signal_handler_disconnect (priv->modest_conf, 
+                                            priv->key_changed_handler_uid);
+               priv->key_changed_handler_uid = 0;
+       }
+
        if (priv->modest_conf) {
                g_object_unref (G_OBJECT(priv->modest_conf));
                priv->modest_conf = NULL;
@@ -241,9 +249,10 @@ modest_account_mgr_new (ModestConf *conf)
        g_object_ref (G_OBJECT(conf));
        priv->modest_conf = conf;
 
-       g_signal_connect (G_OBJECT (conf), "key_changed",
-                         G_CALLBACK (on_key_change),
-                         obj);
+       priv->key_changed_handler_uid =
+               g_signal_connect (G_OBJECT (conf), "key_changed",
+                                 G_CALLBACK (on_key_change),
+                                 obj);
        
        return MODEST_ACCOUNT_MGR (obj);
 }
@@ -274,7 +283,7 @@ modest_account_mgr_add_account (ModestAccountMgr *self,
        g_return_val_if_fail (strchr(name, '/') == NULL, FALSE);
        
        priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self);
-       
+
        /*
         * we create the account by adding an account 'dir', with the name <name>,
         * and in that the 'display_name' string key
@@ -308,7 +317,6 @@ modest_account_mgr_add_account (ModestAccountMgr *self,
                                g_printerr ("modest: Error adding store account conf: %s\n", err->message);
                                g_error_free (err);
                        }
-                       
                        return FALSE;
                }
        }
@@ -343,7 +351,7 @@ modest_account_mgr_add_account (ModestAccountMgr *self,
        if (!default_account)
                modest_account_mgr_set_default_account (self, name);
        g_free (default_account);
-       
+
        return TRUE;
 }
 
@@ -361,13 +369,13 @@ modest_account_mgr_add_server_account (ModestAccountMgr * self,
        gchar *key;
        gboolean ok = TRUE;
        GError *err = NULL;
-       
+
        g_return_val_if_fail (MODEST_IS_ACCOUNT_MGR(self), FALSE);
        g_return_val_if_fail (name, FALSE);
        g_return_val_if_fail (strchr(name, '/') == NULL, FALSE);
                              
        priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self);
-       
+
        /* hostname */
        key = _modest_account_mgr_get_account_keyname (name, MODEST_ACCOUNT_HOSTNAME, TRUE);
        if (modest_conf_key_exists (priv->modest_conf, key, &err)) {
@@ -511,8 +519,6 @@ modest_account_mgr_add_server_account_uri (ModestAccountMgr * self,
        return TRUE;
 }
 
-
-
 gboolean
 modest_account_mgr_remove_account (ModestAccountMgr * self,
                                   const gchar* name,  gboolean server_account)
@@ -530,18 +536,10 @@ modest_account_mgr_remove_account (ModestAccountMgr * self,
                return FALSE;
        }
 
-       /* Notify the observers. We need to do that here because they
-          could need to use the configuration keys before deleting
-          them, i.e., the account store will delete the cache. We
-          only notify about removals of modest accounts */
-       if (!server_account)
-               g_signal_emit (G_OBJECT(self), signals[ACCOUNT_REMOVED_SIGNAL], 0, 
-                              name, server_account);
-
-       /* in case we're deleting an account, also delete the dependent store and transport account */
        if (!server_account) {
                gchar *server_account_name;
-               
+
+               /* in case we're deleting an account, also delete the dependent store and transport account */
                server_account_name = modest_account_mgr_get_string (self, name, MODEST_ACCOUNT_STORE_ACCOUNT,
                                                                    FALSE);
                if (server_account_name) {
@@ -561,7 +559,7 @@ modest_account_mgr_remove_account (ModestAccountMgr * self,
                        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);
@@ -583,6 +581,12 @@ modest_account_mgr_remove_account (ModestAccountMgr * self,
                
                /* pick another one as the new default account */
                modest_account_mgr_set_first_account_as_default (self);
+
+               /* Notify the observers. We do this *after* deleting
+                  the keys, because otherwise a call to account_names
+                  will retrieve also the deleted account */
+               g_signal_emit (G_OBJECT(self), signals[ACCOUNT_REMOVED_SIGNAL], 0,
+                              name, server_account);
        }
        return retval;
 }
@@ -669,9 +673,9 @@ modest_account_mgr_account_names (ModestAccountMgr * self, gboolean only_enabled
        g_return_val_if_fail (self, NULL);
 
        priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self);
-       
        accounts = modest_conf_list_subkeys (priv->modest_conf,
                                              MODEST_ACCOUNT_NAMESPACE, &err);
+
        if (err) {
                g_printerr ("modest: failed to get subkeys (%s): %s\n",
                            MODEST_ACCOUNT_NAMESPACE, err->message);
index 12c7d04..56ffe53 100644 (file)
@@ -174,7 +174,7 @@ modest_init_init_core (void)
                return FALSE;
        }
        
-       if (!init_default_account_maybe(modest_runtime_get_account_mgr ())) {
+       if (!init_default_account_maybe (modest_runtime_get_account_mgr ())) {
                modest_init_uninit ();
                g_printerr ("modest: failed to init default account\n");
                return FALSE;
index 0bc71a9..2b82794 100644 (file)
@@ -81,9 +81,9 @@ static void    modest_tny_account_store_instance_init (ModestTnyAccountStore *ob
 static void    modest_tny_account_store_init          (gpointer g, gpointer iface_data);
 
 
-static void
-get_server_accounts  (TnyAccountStore *self, TnyList *list, TnyAccountType type);
-
+static void    get_server_accounts                    (TnyAccountStore *self, 
+                                                      TnyList *list, 
+                                                      TnyAccountType type);
 
 /* list my signals */
 enum {
@@ -326,12 +326,16 @@ on_account_removed (ModestAccountMgr *acc_mgr,
        TnyAccount *store_account;
        
        /* Clear the account cache */
-       store_account =
-               modest_tny_account_store_get_server_account (self,
-                                                            account,
-                                                            TNY_ACCOUNT_TYPE_STORE);
+       store_account = modest_tny_account_store_get_tny_account_by  (self, 
+                                                                     MODEST_TNY_ACCOUNT_STORE_QUERY_NAME, 
+                                                                     account);
        if (store_account) {
                tny_store_account_delete_cache (TNY_STORE_ACCOUNT (store_account));
+               
+               g_signal_emit (G_OBJECT (self), 
+                                        tny_account_store_signals [TNY_ACCOUNT_STORE_ACCOUNT_REMOVED], 
+                                        0, store_account);
+
                g_object_unref (store_account);
        } else
                g_printerr ("modest: cannot find server account for %s", account);
@@ -341,7 +345,7 @@ on_account_removed (ModestAccountMgr *acc_mgr,
         * affect tny accounts at all (such as 'last_update')
         */
        recreate_all_accounts (self);
-       
+
        g_signal_emit (G_OBJECT(self), signals[ACCOUNT_UPDATE_SIGNAL], 0,
                       account);
 }
@@ -359,10 +363,9 @@ on_account_changed (ModestAccountMgr *acc_mgr, const gchar *account,
                return;
 
        /* FIXME: make this more finegrained; changes do not really affect _all_
-        * accounts, and some do not affect tny accounts at all (such as 'last_update')
+        * accounts
         */
-       if (server_account)
-               recreate_all_accounts (self);
+       recreate_all_accounts (self);
 
        g_signal_emit (G_OBJECT(self), signals[ACCOUNT_UPDATE_SIGNAL], 0,
                       account);
@@ -650,8 +653,8 @@ get_server_accounts  (TnyAccountStore *self, TnyList *list, TnyAccountType type)
                        return;
        }
        
-       GSList                       *account_names = NULL, *cursor = NULL;
-       GSList                       *accounts = NULL;
+       GSList *account_names = NULL, *cursor = NULL;
+       GSList *accounts = NULL;
 
        /* These are account names, not server_account names */
        account_names = modest_account_mgr_account_names (priv->account_mgr,FALSE);
@@ -903,35 +906,9 @@ modest_tny_account_store_get_device (TnyAccountStore *self)
 static TnyAccount*
 modest_tny_account_store_find_account_by_url (TnyAccountStore *self, const gchar* url_string)
 {
-       TnyAccount *account = NULL;
-       ModestTnyAccountStorePrivate *priv;     
-       GSList *cursor;
-       
-       g_return_val_if_fail (self, NULL);
-       g_return_val_if_fail (url_string, NULL);
-       
-       priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
-
-       for (cursor = priv->store_accounts; cursor ; cursor = cursor->next) {
-               if (tny_account_matches_url_string (TNY_ACCOUNT(cursor->data), url_string)) {
-                       account = TNY_ACCOUNT(cursor->data);
-                       break;
-               }
-       }
-
-       if (!account) {
-               for (cursor = priv->transport_accounts; !account && cursor ; cursor = cursor->next) {
-                       if (tny_account_matches_url_string (TNY_ACCOUNT(cursor->data), url_string)) {
-                               account = TNY_ACCOUNT(cursor->data);
-                               break;
-                       }
-               }
-       }
-
-       if (account)
-               g_object_ref (G_OBJECT(account));
-
-       return account;
+       return modest_tny_account_store_get_tny_account_by (MODEST_TNY_ACCOUNT_STORE (self), 
+                                                           MODEST_TNY_ACCOUNT_STORE_QUERY_URL,
+                                                           url_string);
 }
 
 
@@ -966,8 +943,8 @@ modest_tny_account_store_alert (TnyAccountStore *self, TnyAlertType type,
                 * specific dialog messages from Chapter 12 of the UI spec.
                 */
                case TNY_ACCOUNT_STORE_ERROR_UNKNOWN_ALERT: 
-                   g_debug ("%s: Handling GError domain=%d, code=%d, message=%s", 
-                               __FUNCTION__, error->domain, error->code, error->message);
+/*                 g_debug ("%s: Handling GError domain=%d, code=%d, message=%s",  */
+/*                             __FUNCTION__, error->domain, error->code, error->message); */
                        
                        /* TODO: Remove the internal error message for the real release.
                         * This is just so the testers can give us more information: */
@@ -1115,35 +1092,70 @@ modest_tny_account_store_get_session  (TnyAccountStore *self)
 
 
 TnyAccount*
-modest_tny_account_store_get_tny_account_by_id  (ModestTnyAccountStore *self, const gchar *id)
+modest_tny_account_store_get_tny_account_by (ModestTnyAccountStore *self, 
+                                            ModestTnyAccountStoreQueryType type,
+                                            const gchar *str)
 {
        TnyAccount *account = NULL;
        ModestTnyAccountStorePrivate *priv;     
        GSList *cursor;
+       const gchar *val;
 
        g_return_val_if_fail (self, NULL);
-       g_return_val_if_fail (id, NULL);
+       g_return_val_if_fail (str, NULL);
        
        priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
 
-
+       /* Search in store accounts */
        for (cursor = priv->store_accounts; cursor ; cursor = cursor->next) {
-               const gchar *acc_id = tny_account_get_id (TNY_ACCOUNT(cursor->data));
-               if (acc_id && strcmp (acc_id, id) == 0) {
-                       account = TNY_ACCOUNT(cursor->data);
+               switch (type) {
+               case MODEST_TNY_ACCOUNT_STORE_QUERY_ID:
+                       val = tny_account_get_id (TNY_ACCOUNT(cursor->data));
+                       break;
+               case MODEST_TNY_ACCOUNT_STORE_QUERY_NAME:
+                       val = modest_tny_account_get_parent_modest_account_name_for_server_account (TNY_ACCOUNT(cursor->data));
+                       break;
+               case MODEST_TNY_ACCOUNT_STORE_QUERY_URL:
+                       val = tny_account_get_url_string (TNY_ACCOUNT(cursor->data));
                        break;
                }
+               if (type == MODEST_TNY_ACCOUNT_STORE_QUERY_URL && 
+                   tny_account_matches_url_string (TNY_ACCOUNT(cursor->data), val)) {
+                       account = TNY_ACCOUNT (cursor->data);
+                       goto end;
+               } else {
+                       if (strcmp (val, str) == 0) {
+                               account = TNY_ACCOUNT(cursor->data);
+                               goto end;
+                       }
+               }
        }
                
        /* if we already found something, no need to search the transport accounts */
        for (cursor = priv->transport_accounts; !account && cursor ; cursor = cursor->next) {
-               const gchar *acc_id = tny_account_get_id (TNY_ACCOUNT(cursor->data));
-               if (acc_id && strcmp (acc_id, id) == 0) {
-                       account = TNY_ACCOUNT(cursor->data);
+               switch (type) {
+               case MODEST_TNY_ACCOUNT_STORE_QUERY_ID:
+                       val = tny_account_get_id (TNY_ACCOUNT(cursor->data));
+                       break;
+               case MODEST_TNY_ACCOUNT_STORE_QUERY_NAME:
+                       val = tny_account_get_name (TNY_ACCOUNT(cursor->data));
+                       break;
+               case MODEST_TNY_ACCOUNT_STORE_QUERY_URL:
+                       val = tny_account_get_url_string (TNY_ACCOUNT(cursor->data));
                        break;
                }
+               if (type == MODEST_TNY_ACCOUNT_STORE_QUERY_URL && 
+                   tny_account_matches_url_string (TNY_ACCOUNT(cursor->data), val)) {
+                       account = TNY_ACCOUNT (cursor->data);
+                       goto end;
+               } else {
+                       if (strcmp (val, str) == 0) {
+                               account = TNY_ACCOUNT(cursor->data);
+                               goto end;
+                       }
+               }
        }
-
+ end:
        if (account)
                g_object_ref (G_OBJECT(account));
        
@@ -1195,7 +1207,7 @@ modest_tny_account_store_get_server_account (ModestTnyAccountStore *self,
                g_printerr ("modest: could not get an id for account %s\n",
                            account_name);
        else    
-               account = modest_tny_account_store_get_tny_account_by_id (self, id);
+               account = modest_tny_account_store_get_tny_account_by (self, MODEST_TNY_ACCOUNT_STORE_QUERY_ID, id);
 
        if (!account)
                g_printerr ("modest: could not get tny %s account for %s (id=%s)\n",
@@ -1242,7 +1254,9 @@ get_smtp_specific_transport_account_for_open_connection (ModestTnyAccountStore *
                return NULL; /* No connection-specific SMTP server was specified for this connection. */
        }
                
-       TnyAccount* account = modest_tny_account_store_get_tny_account_by_id (self, server_account_name);
+       TnyAccount* account = modest_tny_account_store_get_tny_account_by (self, 
+                                                                          MODEST_TNY_ACCOUNT_STORE_QUERY_ID, 
+                                                                          server_account_name);
 
        /* printf ("DEBUG: %s: account=%p\n", __FUNCTION__, account); */
        g_free (server_account_name);   
index 463c2da..9081753 100644 (file)
@@ -77,6 +77,13 @@ struct _ModestTnyAccountStoreClass {
                                       gpointer user_data);
 };
 
+typedef enum {
+       MODEST_TNY_ACCOUNT_STORE_QUERY_ID,
+       MODEST_TNY_ACCOUNT_STORE_QUERY_NAME,
+       MODEST_TNY_ACCOUNT_STORE_QUERY_URL,
+} ModestTnyAccountStoreQueryType;
+
+
 /**
  * modest_tny_account_store_get_type:
  *
@@ -97,17 +104,18 @@ ModestTnyAccountStore*    modest_tny_account_store_new (ModestAccountMgr *accoun
 
 
 /**
- * modest_tny_account_store_get_account_by_id 
+ * modest_tny_account_store_get_account_by 
  * @self: a ModestTnyAccountStore instance
  * @id: some ID
  * 
- * get the account with the given ID or NULL if it's not found
+ * get the account with the given str or NULL if it's not found
  * 
  * Returns: the tnyaccount or NULL,
  * g_object_unref when it's no longer needed
  */
-TnyAccount* modest_tny_account_store_get_tny_account_by_id  (ModestTnyAccountStore *self,
-                                                            const gchar *id);
+TnyAccount* modest_tny_account_store_get_tny_account_by  (ModestTnyAccountStore *self,
+                                                         ModestTnyAccountStoreQueryType type,
+                                                         const gchar *str);
 
 /**
  * modest_tny_account_store_get_server_account
index c3c6614..834e9c2 100644 (file)
@@ -79,13 +79,15 @@ modest_tny_account_get_special_folder (TnyAccount *account,
                        MODEST_PER_ACCOUNT_LOCAL_OUTBOX_FOLDER_ACCOUNT_ID_PREFIX "%s", 
                        modest_account_name);
                
-               local_account = modest_tny_account_store_get_tny_account_by_id (modest_runtime_get_account_store(),
-                                                                       account_id);
+               local_account = modest_tny_account_store_get_tny_account_by (modest_runtime_get_account_store(),
+                                                                            MODEST_TNY_ACCOUNT_STORE_QUERY_ID,
+                                                                            account_id);
                g_free (account_id);
        } else {
                /* Other local folders are all in one on-disk directory: */
-               local_account = modest_tny_account_store_get_tny_account_by_id (modest_runtime_get_account_store(),
-                                                                               MODEST_LOCAL_FOLDERS_ACCOUNT_ID);
+               local_account = modest_tny_account_store_get_tny_account_by (modest_runtime_get_account_store(),
+                                                                            MODEST_TNY_ACCOUNT_STORE_QUERY_ID,
+                                                                            MODEST_LOCAL_FOLDERS_ACCOUNT_ID);
        }
        
        if (!local_account) {
index 1e6d467..37ee649 100644 (file)
@@ -669,29 +669,30 @@ _modest_ui_actions_open (TnyList *headers, ModestWindow *win)
        ModestWindowMgr *mgr;
        TnyIterator *iter;
        ModestMailOperation *mail_op;
+       TnyList *not_opened_headers;
 
        /* Look if we already have a message view for each header. If
           true, then remove the header from the list of headers to
           open */
        mgr = modest_runtime_get_window_mgr ();
        iter = tny_list_create_iterator (headers);
+       not_opened_headers = tny_simple_list_new ();
        while (!tny_iterator_is_done (iter)) {
                ModestWindow *window;
                TnyHeader *header;
                
                header = TNY_HEADER (tny_iterator_get_current (iter));
                window = modest_window_mgr_find_window_by_header (mgr, header);
-               if (window) {
-                       /* Do not open again the message and present
-                          the window to the user */
-                       tny_list_remove (headers, G_OBJECT (header));
+               /* Do not open again the message and present the
+                  window to the user */
+               if (window)
                        gtk_window_present (GTK_WINDOW (window));
-               }
+               else
+                       tny_list_append (not_opened_headers, G_OBJECT (header));
 
                g_object_unref (header);
                tny_iterator_next (iter);
        }
-
        
        /* Open each message */
        mail_op = modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE, 
@@ -700,13 +701,14 @@ _modest_ui_actions_open (TnyList *headers, ModestWindow *win)
                                                                 NULL);
        modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
        modest_mail_operation_get_msgs_full (mail_op, 
-                                            headers, 
+                                            not_opened_headers, 
                                             open_msg_cb, 
                                             NULL, 
                                             NULL);
        /* Clean */
+       g_object_unref (not_opened_headers);
        g_object_unref (iter);
-       g_object_unref(mail_op);
+       g_object_unref (mail_op);
 }
 
 void
@@ -1216,8 +1218,9 @@ set_active_account_from_tny_account (TnyAccount *account,
           account store because that is the one that
           knows the name of the Modest account */
        TnyAccount *modest_server_account = modest_server_account = 
-               modest_tny_account_store_get_tny_account_by_id  (modest_runtime_get_account_store (), 
-                                                                server_acc_name);
+               modest_tny_account_store_get_tny_account_by (modest_runtime_get_account_store (),
+                                                            MODEST_TNY_ACCOUNT_STORE_QUERY_ID, 
+                                                            server_acc_name);
        
        const gchar *modest_acc_name = 
                modest_tny_account_get_parent_modest_account_name_for_server_account (modest_server_account);
index 54393d9..a5ceb76 100644 (file)
@@ -400,9 +400,10 @@ save_settings_folder_view (ModestConf *conf, ModestFolderView *folder_view,
        account_id = modest_folder_view_get_account_id_of_visible_server_account (folder_view);
        if (account_id)
                modest_conf_set_string (conf, key, account_id, NULL);
+       else
+               modest_conf_remove_key (conf, key, NULL);
        g_free (key);
 
-
        return TRUE;
 }
 
index 34fe761..6da9f7a 100644 (file)
@@ -268,8 +268,8 @@ static void
 on_account_removed (ModestAccountMgr *account_mgr,
                    const gchar* account, gboolean server_account,
                    ModestAccountView *self)
-{
-       on_account_changed (account_mgr, account, NULL, server_account, self);
+{               
+       update_account_view (account_mgr, self);
 }
 
 
index a5e4978..d95c3a6 100644 (file)
@@ -51,7 +51,6 @@
 #include "modest-folder-view.h"
 #include <modest-dnd.h>
 #include <modest-platform.h>
-#include <modest-account-mgr-helpers.h>
 #include <modest-widget-memory.h>
 #include <modest-ui-actions.h>
 
@@ -72,6 +71,10 @@ static void         on_account_update      (TnyAccountStore *account_store,
                                            const gchar *account,
                                            gpointer user_data);
 
+static void         on_account_removed     (TnyAccountStore *self, 
+                                           TnyAccount *account,
+                                           gpointer user_data);
+
 static void         on_accounts_reloaded   (TnyAccountStore *store, 
                                            gpointer user_data);
 
@@ -135,6 +138,7 @@ struct _ModestFolderViewPrivate {
        gulong                account_update_signal;
        gulong                changed_signal;
        gulong                accounts_reloaded_signal;
+       gulong                account_removed_signal;
        
        TnyFolderStoreQuery  *query;
        guint                 timer_expander;
@@ -518,6 +522,8 @@ modest_folder_view_finalize (GObject *obj)
                                             priv->account_update_signal);
                g_signal_handler_disconnect (G_OBJECT(priv->account_store),
                                             priv->accounts_reloaded_signal);
+               g_signal_handler_disconnect (G_OBJECT(priv->account_store),
+                                            priv->account_removed_signal);
                g_object_unref (G_OBJECT(priv->account_store));
                priv->account_store = NULL;
        }
@@ -560,6 +566,10 @@ modest_folder_view_set_account_store (TnyAccountStoreView *self, TnyAccountStore
                                                   priv->accounts_reloaded_signal))
                        g_signal_handler_disconnect (G_OBJECT (priv->account_store), 
                                                     priv->accounts_reloaded_signal);
+               if (g_signal_handler_is_connected (G_OBJECT (priv->account_store), 
+                                                  priv->account_removed_signal))
+                       g_signal_handler_disconnect (G_OBJECT (priv->account_store), 
+                                                    priv->account_removed_signal);
 
                g_object_unref (G_OBJECT (priv->account_store));
        }
@@ -570,6 +580,10 @@ modest_folder_view_set_account_store (TnyAccountStoreView *self, TnyAccountStore
                g_signal_connect (G_OBJECT(account_store), "account_update",
                                  G_CALLBACK (on_account_update), self);
 
+       priv->account_removed_signal = 
+               g_signal_connect (G_OBJECT(account_store), "account_removed",
+                                 G_CALLBACK (on_account_removed), self);
+
        priv->accounts_reloaded_signal = 
                g_signal_connect (G_OBJECT(account_store), "accounts_reloaded",
                                  G_CALLBACK (on_accounts_reloaded), self);
@@ -580,11 +594,36 @@ modest_folder_view_set_account_store (TnyAccountStoreView *self, TnyAccountStore
 }
 
 static void
-on_account_update (TnyAccountStore *account_store, const gchar *account,
+on_account_removed (TnyAccountStore *account_store, 
+                   TnyAccount *account,
+                   gpointer user_data)
+{
+       ModestFolderView *self = MODEST_FOLDER_VIEW (user_data);
+       ModestFolderViewPrivate *priv;
+
+       priv = MODEST_FOLDER_VIEW_GET_PRIVATE (self);
+
+       /* If the removed account is the currently viewed one then
+          clear the configuration value. The new visible account will be the default account */
+       if (!strcmp (priv->visible_account_id, tny_account_get_id (account))) {
+               modest_folder_view_set_account_id_of_visible_server_account (self, NULL);
+       }
+}
+
+static void
+on_account_update (TnyAccountStore *account_store, 
+                  const gchar *account,
                   gpointer user_data)
 {
-       if (!modest_folder_view_update_model (MODEST_FOLDER_VIEW(user_data), 
-                                             account_store))
+       ModestFolderView *self = MODEST_FOLDER_VIEW (user_data);
+       ModestFolderViewPrivate *priv;
+
+       priv = MODEST_FOLDER_VIEW_GET_PRIVATE (self);
+       if (!priv->visible_account_id)
+               modest_widget_memory_restore (modest_runtime_get_conf(), G_OBJECT(self),
+                                             MODEST_CONF_FOLDER_VIEW_KEY);
+
+       if (!modest_folder_view_update_model (self, account_store))
                g_printerr ("modest: failed to update model for changes in '%s'",
                            account);
 }
@@ -593,11 +632,7 @@ static void
 on_accounts_reloaded   (TnyAccountStore *account_store, 
                        gpointer user_data)
 {
-       ModestConf *conf = modest_runtime_get_conf ();
-
-       modest_widget_memory_save (conf, G_OBJECT (user_data), MODEST_CONF_FOLDER_VIEW_KEY);
        modest_folder_view_update_model (MODEST_FOLDER_VIEW (user_data), account_store);
-       modest_widget_memory_restore (conf, G_OBJECT (user_data), MODEST_CONF_FOLDER_VIEW_KEY);
 }
 
 void
@@ -683,7 +718,7 @@ filter_row (GtkTreeModel *model,
                if (TNY_IS_ACCOUNT (instance)) {
                        TnyAccount *acc = TNY_ACCOUNT (instance);
                        const gchar *account_id = tny_account_get_id (acc);
-                       
+       
                        /* If it isn't a special folder, 
                         * don't show it unless it is the visible account: */
                        if (!modest_tny_account_is_virtual_local_folders (acc) &&
@@ -1542,14 +1577,21 @@ modest_folder_view_set_account_id_of_visible_server_account (ModestFolderView *s
 
        /* This will be used by the filter_row callback,
         * to decided which rows to show: */
-       if (priv->visible_account_id)
+       if (priv->visible_account_id) {
                g_free (priv->visible_account_id);
-       priv->visible_account_id = g_strdup (account_id);
+               priv->visible_account_id = NULL;
+       }
+       if (account_id)
+               priv->visible_account_id = g_strdup (account_id);
 
        /* Refilter */
        model = gtk_tree_view_get_model (GTK_TREE_VIEW (self));
        if (GTK_IS_TREE_MODEL_FILTER (model))
                gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (model));
+
+       /* Save settings to gconf */
+       modest_widget_memory_save (modest_runtime_get_conf (), G_OBJECT(self),
+                                  MODEST_CONF_FOLDER_VIEW_KEY);
 }
 
 const gchar *