* Added a new signal to the account mgr that notifies changes in the default account...
authorSergio Villar Senin <svillar@igalia.com>
Thu, 20 Sep 2007 18:07:29 +0000 (18:07 +0000)
committerSergio Villar Senin <svillar@igalia.com>
Thu, 20 Sep 2007 18:07:29 +0000 (18:07 +0000)
* Fixed a hang when creating the first account, now the accounts are not updated if the status is connecting

pmo-trunk-r3376

src/maemo/modest-main-window.c
src/modest-account-mgr.c
src/modest-account-mgr.h
src/modest-conf.c
src/modest-tny-account-store.c
src/widgets/modest-account-view.c
src/widgets/modest-folder-view.c

index 20d9990..c91ac35 100644 (file)
@@ -123,9 +123,8 @@ on_account_removed (TnyAccountStore *accoust_store,
                     gpointer user_data);
 
 static void
-on_account_changed (ModestAccountMgr* mgr,
-                    const gchar* account,
-                    gpointer user_data);
+on_default_account_changed (ModestAccountMgr* mgr,
+                           gpointer user_data);
 
 static gboolean on_inner_widgets_key_pressed  (GtkWidget *widget,
                                               GdkEventKey *event,
@@ -220,8 +219,6 @@ struct _ModestMainWindowPrivate {
        /* Signal handler UIDs */
        GList *queue_err_signals;
        GSList *sighandlers;
-       
-       ModestConfNotificationId notification_id;
 };
 #define MODEST_MAIN_WINDOW_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \
                                                 MODEST_TYPE_MAIN_WINDOW, \
@@ -354,12 +351,6 @@ modest_main_window_finalize (GObject *obj)
 
        priv = MODEST_MAIN_WINDOW_GET_PRIVATE(obj);
 
-       if (priv->notification_id) {
-               modest_conf_forget_namespace (modest_runtime_get_conf (),
-                                             MODEST_CONF_NAMESPACE,
-                                             priv->notification_id);
-       }
-       
        /* Sanity check: shouldn't be needed, the window mgr should
           call this function before */
        modest_main_window_disconnect_signals (MODEST_WINDOW (obj));
@@ -859,8 +850,6 @@ connect_signals (ModestMainWindow *self)
                                                       "queue-changed", G_CALLBACK (on_queue_changed), self);
        
        /* Track changes in the device name */
-       priv->notification_id =  modest_conf_listen_to_namespace (modest_runtime_get_conf (), 
-                                                                 MODEST_CONF_NAMESPACE);
        priv->sighandlers = modest_signal_mgr_connect (priv->sighandlers,G_OBJECT(modest_runtime_get_conf ()),
                                                       "key_changed", G_CALLBACK (on_configuration_key_changed), 
                                                       self);
@@ -875,8 +864,10 @@ connect_signals (ModestMainWindow *self)
 
        /* We need to refresh the send & receive menu to change the bold
         * account when the default account changes. */
-       priv->sighandlers = modest_signal_mgr_connect (priv->sighandlers,G_OBJECT (modest_runtime_get_account_mgr ()),
-                                                      "account_changed", G_CALLBACK (on_account_changed),
+       priv->sighandlers = modest_signal_mgr_connect (priv->sighandlers,
+                                                      G_OBJECT (modest_runtime_get_account_mgr ()),
+                                                      "default_account_changed", 
+                                                      G_CALLBACK (on_default_account_changed),
                                                       self);
 
        /* Account store */
@@ -1400,19 +1391,10 @@ on_account_inserted (TnyAccountStore *accoust_store,
 }
 
 static void
-on_account_changed (ModestAccountMgr* mgr,
-                    const gchar* account,
-                    gpointer user_data)
+on_default_account_changed (ModestAccountMgr* mgr,
+                           gpointer user_data)
 {
-       gchar *default_account = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr ());
-
-       /* Actually, we only want to know when another account has become
-        * the default account, but there is no default_account_changed
-        * signal in ModestAccountMgr. */
-       if(strcmp(account, default_account) == 0)
-               update_menus (MODEST_MAIN_WINDOW (user_data));
-
-       g_free (default_account);
+       update_menus (MODEST_MAIN_WINDOW (user_data));
 }
 
 static void
@@ -1815,15 +1797,15 @@ on_configuration_key_changed (ModestConf* conf,
        ModestMainWindowPrivate *priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self);
        TnyAccount *account = NULL;
 
-       if (!key || 
-           priv->notification_id != id ||
-           strcmp (key, MODEST_CONF_DEVICE_NAME))
+       if (!key || strcmp (key, MODEST_CONF_DEVICE_NAME))
                return;
 
        if (priv->contents_style != MODEST_MAIN_WINDOW_CONTENTS_STYLE_DETAILS)
                return;
+
        if (priv->folder_view) 
                account = (TnyAccount *) modest_folder_view_get_selected (priv->folder_view);
+
        if (account && TNY_IS_ACCOUNT (account) &&
            strcmp (tny_account_get_id (account), MODEST_LOCAL_FOLDERS_ACCOUNT_ID) == 0) {
                GList *children;
index 56e29ab..b9e6727 100644 (file)
@@ -45,6 +45,7 @@ enum {
        ACCOUNT_CHANGED_SIGNAL,
        ACCOUNT_REMOVED_SIGNAL,
        ACCOUNT_BUSY_SIGNAL,
+       DEFAULT_ACCOUNT_CHANGED_SIGNAL,
        LAST_SIGNAL
 };
 
@@ -105,7 +106,7 @@ on_timeout_notify_changes (gpointer data)
        while (cursor) {
                const gchar *account = cursor->data;
                if (account)
-                       g_signal_emit (G_OBJECT(self), signals[ACCOUNT_CHANGED_SIGNAL], 0, 
+                       g_signal_emit (G_OBJECT(self), signals[ACCOUNT_CHANGED_SIGNAL], 0,
                                       account);
                cursor = g_slist_next (cursor);
        }
@@ -156,20 +157,10 @@ on_key_change (ModestConf *conf, const gchar *key, ModestConfEvent event,
        gboolean is_server_account;
        gchar* account_name = NULL;
 
-       /* there is only one not-really-account key which will still emit
-        * a signal: a change in MODEST_CONF_DEFAULT_ACCOUNT */
+       /* Notify that the default account has changed */
        if (key && strcmp (key, MODEST_CONF_DEFAULT_ACCOUNT) == 0) {
-               /* Get the default account instead. */
-               gchar *default_account =  modest_account_mgr_get_default_account (self);
-               if (!default_account) {
-                       g_warning ("BUG: cannot find default account");
-                       return;
-               } else {
-                       g_signal_emit (G_OBJECT(self), signals[ACCOUNT_CHANGED_SIGNAL], 0, 
-                                      default_account);
-                       g_free(default_account);
-                       return;
-               }       
+               g_signal_emit (G_OBJECT(self), signals[DEFAULT_ACCOUNT_CHANGED_SIGNAL], 0);
+               return;
        }
        
        is_account_key = FALSE;
@@ -181,11 +172,6 @@ on_key_change (ModestConf *conf, const gchar *key, ModestConfEvent event,
        if (!account_name)
                return;
 
-       /* ignore server account changes */
-       if (is_server_account)
-               /* change in place: retrieve the parent account name */
-               get_account_name_from_server_account (account_name);
-
        /* 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
@@ -196,6 +182,11 @@ on_key_change (ModestConf *conf, const gchar *key, ModestConfEvent event,
                return;
        }
 
+       /* ignore server account changes */
+       if (is_server_account)
+               /* change in place: retrieve the parent account name */
+               get_account_name_from_server_account (account_name);
+
        /* is this account enabled? */
        gboolean enabled = FALSE;
        if (is_server_account)
@@ -214,9 +205,9 @@ on_key_change (ModestConf *conf, const gchar *key, ModestConfEvent event,
                                                                  account_name);
                        /* hmm, small race when this object is destroyed within
                         * 500ms of the last change, and there are multiple timeouts... */
-                       priv->timeout = g_timeout_add (500, (GSourceFunc)on_timeout_notify_changes,
+                       priv->timeout = g_timeout_add (500, (GSourceFunc) on_timeout_notify_changes,
                                                       self);
-               }   
+               }
        }
        g_free (account_name);
 }
@@ -259,7 +250,7 @@ modest_account_mgr_base_init (gpointer g_class)
                        g_signal_new ("account_inserted",
                                      MODEST_TYPE_ACCOUNT_MGR,
                                      G_SIGNAL_RUN_FIRST,
-                                     G_STRUCT_OFFSET(ModestAccountMgrClass,account_inserted),
+                                     G_STRUCT_OFFSET(ModestAccountMgrClass, account_inserted),
                                      NULL, NULL,
                                      g_cclosure_marshal_VOID__STRING,
                                      G_TYPE_NONE, 1, G_TYPE_STRING);
@@ -268,7 +259,7 @@ modest_account_mgr_base_init (gpointer g_class)
                        g_signal_new ("account_removed",
                                      MODEST_TYPE_ACCOUNT_MGR,
                                      G_SIGNAL_RUN_FIRST,
-                                     G_STRUCT_OFFSET(ModestAccountMgrClass,account_removed),
+                                     G_STRUCT_OFFSET(ModestAccountMgrClass, account_removed),
                                      NULL, NULL,
                                      g_cclosure_marshal_VOID__STRING,
                                      G_TYPE_NONE, 1, G_TYPE_STRING);
@@ -277,20 +268,29 @@ modest_account_mgr_base_init (gpointer g_class)
                        g_signal_new ("account_changed",
                                      MODEST_TYPE_ACCOUNT_MGR,
                                      G_SIGNAL_RUN_FIRST,
-                                     G_STRUCT_OFFSET(ModestAccountMgrClass,account_changed),
+                                     G_STRUCT_OFFSET(ModestAccountMgrClass, account_changed),
                                      NULL, NULL,
                                      g_cclosure_marshal_VOID__STRING,
-                                     G_TYPE_NONE, 1, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN);
+                                     G_TYPE_NONE, 1, G_TYPE_STRING);
 
                signals[ACCOUNT_BUSY_SIGNAL] =
                        g_signal_new ("account_busy_changed",
                                      MODEST_TYPE_ACCOUNT_MGR,
                                      G_SIGNAL_RUN_FIRST,
-                                     G_STRUCT_OFFSET(ModestAccountMgrClass,account_busy_changed),
+                                     G_STRUCT_OFFSET(ModestAccountMgrClass, account_busy_changed),
                                      NULL, NULL,
                                      modest_marshal_VOID__STRING_BOOLEAN,
                                      G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_BOOLEAN);
 
+               signals[DEFAULT_ACCOUNT_CHANGED_SIGNAL] =
+                       g_signal_new ("default_account_changed",
+                                     MODEST_TYPE_ACCOUNT_MGR,
+                                     G_SIGNAL_RUN_FIRST,
+                                     G_STRUCT_OFFSET(ModestAccountMgrClass, default_account_changed),
+                                     NULL, NULL,
+                                     g_cclosure_marshal_VOID__VOID,
+                                     G_TYPE_NONE, 0);
+
                modest_account_mgr_initialized = TRUE;
        }
 }
index 4a8e04c..eef1cdf 100644 (file)
@@ -72,6 +72,9 @@ struct _ModestAccountMgrClass {
                                         const gchar* account,
                                         gboolean busy,
                                         gpointer user_data);   
+
+       void (* default_account_changed)(ModestAccountMgr *obj, 
+                                        gpointer user_data);
 };
 
 /**
index 767f5b9..7536ec5 100644 (file)
@@ -115,9 +115,8 @@ modest_conf_init (ModestConf *obj)
 {
        GConfClient *conf = NULL;
        ModestConfPrivate *priv = MODEST_CONF_GET_PRIVATE(obj);
-/*     GError *err      = NULL; */
+       GError *err      = NULL;
 
-       
        priv->gconf_client = NULL;
        
        conf = gconf_client_get_default ();
@@ -125,27 +124,7 @@ modest_conf_init (ModestConf *obj)
                g_printerr ("modest: could not get gconf client\n");
                return;
        }
-/*     gconf_client_add_dir (conf,MODEST_CONF_NAMESPACE, */
-/*                           GCONF_CLIENT_PRELOAD_NONE, */
-/*                           &err); */
-/*     if (err) { */
-/*             g_printerr ("modest: error %d with gconf_client_add_dir: '%s'\n", */
-/*                         err->code, err->message); */
-/*             g_object_unref (conf); */
-/*             g_error_free (err); */
-/*             return; */
-/*     } */
-       
-/*     gconf_client_notify_add (conf, MODEST_CONF_NAMESPACE, */
-/*                              modest_conf_on_change, */
-/*                              obj, NULL, &err); */
-/*     if (err) { */
-/*             g_printerr ("modest: gconf_client_notify_add error %d: '%s'\n", */
-/*                         err->code, err->message); */
-/*             g_object_unref (conf); */
-/*             g_error_free (err); */
-/*             return; */
-/*     } */
+
        priv->gconf_client = conf;      /* all went well! */
 }
 
index 3bf60fc..b96c249 100644 (file)
@@ -465,12 +465,17 @@ update_tny_account_for_account (ModestTnyAccountStore *self, ModestAccountMgr *a
                TnyAccount *tny_account;
                tny_account = TNY_ACCOUNT (tny_iterator_get_current (iter));
                if (tny_account) {
-                       const gchar* parent_name =
-                               modest_tny_account_get_parent_modest_account_name_for_server_account (tny_account);
-                       if (parent_name && strcmp (parent_name, account_name) == 0) {
-                               found = TRUE;
-                               modest_tny_account_update_from_account (tny_account, acc_mgr, account_name, type);
-                               g_signal_emit (G_OBJECT(self), signals[ACCOUNT_CHANGED_SIGNAL], 0, tny_account);
+                       TnyConnectionStatus conn_status = tny_account_get_connection_status (tny_account);
+
+                       if (conn_status != TNY_CONNECTION_STATUS_RECONNECTING &&
+                           conn_status != TNY_CONNECTION_STATUS_INIT) {
+                               const gchar* parent_name;
+                               parent_name = modest_tny_account_get_parent_modest_account_name_for_server_account (tny_account);
+                               if (parent_name && strcmp (parent_name, account_name) == 0) {
+                                       found = TRUE;
+                                       modest_tny_account_update_from_account (tny_account, acc_mgr, account_name, type);
+                                       g_signal_emit (G_OBJECT(self), signals[ACCOUNT_CHANGED_SIGNAL], 0, tny_account);
+                               }
                        }
                        g_object_unref (tny_account);
                }
@@ -491,11 +496,11 @@ on_account_changed (ModestAccountMgr *acc_mgr,
 {
        ModestTnyAccountStore *self = MODEST_TNY_ACCOUNT_STORE(user_data);
 
-       g_debug ("DEBUG: modest: %s\n", __FUNCTION__);
+/*     g_debug ("DEBUG: modest: %s\n", __FUNCTION__); */
 
-       /* Ignore the change if it's a change in the last_updated value */
-//     if (key && g_str_has_suffix ((const gchar *) key, MODEST_ACCOUNT_LAST_UPDATED))
-//             return;
+/*     /\* Ignore the change if it's a change in the last_updated value *\/ */
+/*     if (key && g_str_has_suffix ((const gchar *) key, MODEST_ACCOUNT_LAST_UPDATED)) */
+/*             return; */
        
        if (!update_tny_account_for_account (self, acc_mgr, account_name, TNY_ACCOUNT_TYPE_STORE))
                g_warning ("%s: failed to update store account for %s", __FUNCTION__, account_name);
index aa03c39..b178409 100644 (file)
@@ -409,12 +409,12 @@ on_account_default_toggled (GtkCellRendererToggle *cell_renderer, gchar *path,
        }
        
        gchar *account_name = NULL;
-       gtk_tree_model_get (model, &iter, MODEST_ACCOUNT_VIEW_NAME_COLUMN, &account_name,
-                           -1);
+       gtk_tree_model_get (model, &iter, 
+                           MODEST_ACCOUNT_VIEW_NAME_COLUMN, 
+                           &account_name, -1);
        
        /* Set this previously-non-default account as the default: */
-       if (modest_account_mgr_set_default_account (priv->account_mgr, account_name))
-       {
+       if (modest_account_mgr_set_default_account (priv->account_mgr, account_name)) {
                /* Explicitely set default column because we are ignoring gconf changes */
                GtkTreeIter old_default_iter;
                if (find_default_account (self, &old_default_iter)) {
index 20819f7..b810e84 100644 (file)
@@ -673,7 +673,7 @@ modest_folder_view_init (ModestFolderView *obj)
         * Track changes in the local account name (in the device it
         * will be the device name)
         */
-       priv->notification_id = modest_conf_listen_to_namespace (conf, 
+       priv->notification_id = modest_conf_listen_to_namespace (conf,
                                                                 MODEST_CONF_NAMESPACE);
        priv->conf_key_signal = g_signal_connect (G_OBJECT(conf), 
                                                  "key_changed",