* restore some functionality after the changes, by reenabling the key-changed
authorDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Tue, 31 Jul 2007 12:36:22 +0000 (12:36 +0000)
committerDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Tue, 31 Jul 2007 12:36:22 +0000 (12:36 +0000)
  signal in modest-account-mgr, and change it's listeners.

Note: updating account name in the Accounts dialog works now; but it's not
  propagated correctly to the account in the folder view yet.

pmo-trunk-r2868

src/modest-account-mgr.c
src/modest-account-mgr.h
src/modest-marshal.list
src/widgets/modest-account-view.c

index 624bff0..75fa3b8 100644 (file)
@@ -81,65 +81,70 @@ static guint signals[LAST_SIGNAL] = {0};
 /*     return TRUE; /\* Call this again later. *\/ */
 /* } */
 
 /*     return TRUE; /\* Call this again later. *\/ */
 /* } */
 
-/* static void */
-/* on_key_change (ModestConf *conf, const gchar *key, ModestConfEvent event, gpointer user_data) */
-/* { */
-/*     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 *\/ */
-/*     if (key && strcmp (key, MODEST_CONF_DEFAULT_ACCOUNT) == 0) { */
-/*             /\* Get the default account instead. *\/ */
-               
-/*             /\* 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, */
-/*                     (gpointer) g_strdup (key)); */
-/*     } */
+static void
+on_key_change (ModestConf *conf, const gchar *key, ModestConfEvent event,
+              ModestConfNotificationId id, gpointer user_data)
+{
+       ModestAccountMgr *self = MODEST_ACCOUNT_MGR (user_data);
+       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 */
+       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, key, FALSE);
+                       g_free(default_account);
+                       return;
+               }       
+       }
        
        
-/*     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. 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; */
-/*     } */
+       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. 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;
+       }
 
 
-/*     /\* is this account enabled? *\/ */
-/*     gboolean enabled = FALSE; */
-/*     if (is_server_account) */
-/*             enabled = TRUE; */
-/*     else */
-/*             enabled = modest_account_mgr_get_enabled (self, account); */
-
-/*     /\* Notify is server account was changed, default account was changed */
-/*      * or when enabled/disabled changes: */
-/*      *\/ */
-/*     if (enabled || */
-/*         g_str_has_suffix (key, MODEST_ACCOUNT_ENABLED) || */
-/*         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, */
-/*                     (gpointer) g_strdup (key)); */
-/*     } */
-/*     g_free (account); */
-/* } */
+       /* is this account enabled? */
+       gboolean enabled = FALSE;
+       if (is_server_account)
+               enabled = TRUE;
+       else
+               enabled = modest_account_mgr_get_enabled (self, account);
+
+       /* Notify is server account was changed, default account was changed
+        * or when enabled/disabled changes:
+        */
+       if (enabled ||
+           g_str_has_suffix (key, MODEST_ACCOUNT_ENABLED) ||
+           strcmp (key, MODEST_CONF_DEFAULT_ACCOUNT) == 0) {
+               g_signal_emit (G_OBJECT(self), signals[ACCOUNT_CHANGED_SIGNAL], 0, 
+                              account, key, is_server_account);
+               /* Store the key for later notification in our timeout callback.
+                * Notifying for every key change would cause unnecessary work: */
+       }
+       g_free (account);
+}
 
 
 GType
 
 
 GType
@@ -199,8 +204,8 @@ modest_account_mgr_base_init (gpointer g_class)
                                      G_SIGNAL_RUN_FIRST,
                                      G_STRUCT_OFFSET(ModestAccountMgrClass,account_changed),
                                      NULL, NULL,
                                      G_SIGNAL_RUN_FIRST,
                                      G_STRUCT_OFFSET(ModestAccountMgrClass,account_changed),
                                      NULL, NULL,
-                                     modest_marshal_VOID__STRING_POINTER_BOOLEAN,
-                                     G_TYPE_NONE, 3, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_BOOLEAN);
+                                     modest_marshal_VOID__STRING_STRING_BOOLEAN,
+                                     G_TYPE_NONE, 3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN);
 
                signals[ACCOUNT_BUSY_SIGNAL] =
                        g_signal_new ("account_busy_changed",
 
                signals[ACCOUNT_BUSY_SIGNAL] =
                        g_signal_new ("account_busy_changed",
@@ -290,10 +295,10 @@ modest_account_mgr_new (ModestConf *conf)
        g_object_ref (G_OBJECT(conf));
        priv->modest_conf = conf;
 
        g_object_ref (G_OBJECT(conf));
        priv->modest_conf = conf;
 
-/*     priv->key_changed_handler_uid = */
-/*             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);
 }
        
        return MODEST_ACCOUNT_MGR (obj);
 }
index f93a712..ae33f39 100644 (file)
@@ -66,7 +66,7 @@ struct _ModestAccountMgrClass {
 
        void (* account_changed)   (ModestAccountMgr *obj, 
                                    const gchar* account,
 
        void (* account_changed)   (ModestAccountMgr *obj, 
                                    const gchar* account,
-                                   const GSList* key, 
+                                   const gchar* key, 
                                    gboolean server_account,
                                    gpointer user_data);
 
                                    gboolean server_account,
                                    gpointer user_data);
 
index 5fe145e..38e7b11 100644 (file)
@@ -1,6 +1,7 @@
 VOID:POINTER,POINTER
 VOID:POINTER,POINTER,POINTER
 VOID:STRING,POINTER,POINTER,POINTER,POINTER
 VOID:POINTER,POINTER
 VOID:POINTER,POINTER,POINTER
 VOID:STRING,POINTER,POINTER,POINTER,POINTER
+VOID:STRING,STRING,BOOL        
 VOID:POINTER,BOOL
 VOID:STRING,INT
 VOID:STRING,INT,INT
 VOID:POINTER,BOOL
 VOID:STRING,INT
 VOID:STRING,INT,INT
index 5fd4710..a131674 100644 (file)
@@ -65,9 +65,8 @@ struct _ModestAccountViewPrivate {
        ModestAccountMgr *account_mgr;
 
        /* Signal handlers */
        ModestAccountMgr *account_mgr;
 
        /* Signal handlers */
-       gulong acc_inserted_handler;
-       gulong acc_removed_handler;
-       gulong sig3;
+       gulong acc_inserted_handler, acc_removed_handler,
+               acc_busy_changed_handler, acc_changed_handler;
 };
 #define MODEST_ACCOUNT_VIEW_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \
                                                  MODEST_TYPE_ACCOUNT_VIEW, \
 };
 #define MODEST_ACCOUNT_VIEW_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \
                                                  MODEST_TYPE_ACCOUNT_VIEW, \
@@ -121,7 +120,8 @@ modest_account_view_init (ModestAccountView *obj)
        priv->account_mgr = NULL; 
        priv->acc_inserted_handler = 0;
        priv->acc_removed_handler = 0;
        priv->account_mgr = NULL; 
        priv->acc_inserted_handler = 0;
        priv->acc_removed_handler = 0;
-       priv->sig3 = 0;
+       priv->acc_busy_changed_handler = 0;
+       priv->acc_changed_handler = 0;
 }
 
 static void
 }
 
 static void
@@ -142,8 +142,10 @@ modest_account_view_finalize (GObject *obj)
                        g_signal_handler_disconnect (modest_runtime_get_account_store (), 
                                                     priv->acc_removed_handler);
 
                        g_signal_handler_disconnect (modest_runtime_get_account_store (), 
                                                     priv->acc_removed_handler);
 
-               if (priv->sig3)
-                       g_signal_handler_disconnect (priv->account_mgr, priv->sig3);
+               if (priv->acc_busy_changed_handler)
+                       g_signal_handler_disconnect (priv->account_mgr, priv->acc_busy_changed_handler);
+               if (priv->acc_changed_handler)
+                       g_signal_handler_disconnect (priv->account_mgr, priv->acc_changed_handler);
                
                g_object_unref (G_OBJECT(priv->account_mgr));
                priv->account_mgr = NULL; 
                
                g_object_unref (G_OBJECT(priv->account_mgr));
                priv->account_mgr = NULL; 
@@ -313,34 +315,21 @@ on_account_removed (TnyAccountStore *account_store,
 }
 
 
 }
 
 
-/* currently unused */
-#if 0 
 static void
 static void
-on_account_enable_toggled (GtkCellRendererToggle *cell_renderer, gchar *path,
-                          ModestAccountView *self)
+on_account_changed (ModestAccountMgr *obj, const gchar* account,
+                   const gchar* key, gboolean server_account,
+                   gpointer user_data)
 {
 {
-       GtkTreeIter iter;
+       ModestAccountView *self;
        ModestAccountViewPrivate *priv;
        ModestAccountViewPrivate *priv;
-       GtkTreeModel *model;
-       gchar *account_name;
-       gboolean enabled;
-       
-       priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE(self);
-       model = gtk_tree_view_get_model (GTK_TREE_VIEW(self));
-       
-       if (!gtk_tree_model_get_iter_from_string (model, &iter, path)) {
-               g_printerr ("modest: cannot find iterator\n");
-               return;
-       }
-       gtk_tree_model_get (model, &iter, MODEST_ACCOUNT_VIEW_IS_ENABLED_COLUMN, &enabled,
-                           MODEST_ACCOUNT_VIEW_NAME_COLUMN, &account_name,
-                           -1);
-       
-       /* toggle enabled / disabled */
-       modest_account_mgr_set_enabled (priv->account_mgr, account_name, !enabled);
-       g_free (account_name);
+
+       self = MODEST_ACCOUNT_VIEW (user_data);
+       priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE (self);
+
+       update_account_view (priv->account_mgr, self);
 }
 }
-#endif
+
+
 
 static gboolean
 find_default_account(ModestAccountView *self, GtkTreeIter *iter)
 
 static gboolean
 find_default_account(ModestAccountView *self, GtkTreeIter *iter)
@@ -492,8 +481,13 @@ init_view (ModestAccountView *self)
                                                       "account_inserted",
                                                       G_CALLBACK(on_account_inserted), self);
        
                                                       "account_inserted",
                                                       G_CALLBACK(on_account_inserted), self);
        
-       priv->sig3 = g_signal_connect (G_OBJECT(priv->account_mgr), "account_busy_changed",
-                                                        G_CALLBACK(on_account_busy_changed), self);
+       priv->acc_busy_changed_handler = g_signal_connect (G_OBJECT(priv->account_mgr),
+                                                          "account_busy_changed",
+                                                          G_CALLBACK(on_account_busy_changed), self);
+
+       priv->acc_changed_handler = g_signal_connect (G_OBJECT(priv->account_mgr),
+                                                     "account_changed",
+                                                     G_CALLBACK(on_account_changed), self);
 }
 
 
 }