2007-05-09 Murray Cumming <murrayc@murrayc.com>
authorMurray Cumming <murrayc@murrayc.com>
Wed, 9 May 2007 15:59:30 +0000 (15:59 +0000)
committerMurray Cumming <murrayc@murrayc.com>
Wed, 9 May 2007 15:59:30 +0000 (15:59 +0000)
* src/widgets/modest-account-view.h:
        * src/widgets/modest-account-view.c: (on_account_changed),
        (on_account_removed). Added a boolean flag, set/unset by
        modest_account_view_block_conf_updates(),
        modest_account_view_unblock_conf_updates() to prevent unnecessary
        updates, but this is not very useful because the gconf notifications are
        so delays (maybe only on Maemo Bora).
        So auto-updating is turned off, and these functions do an explicit
        update when necessary.
        However, something else is still doing too much work when adding/removing
        accounts, probably in another part of the application.

        * src/maemo/modest-account-view-window.c:
        (on_delete_button_clicked), (on_edit_button_clicked),
        (on_new_button_clicked): Use the new functions.

pmo-trunk-r1806

ChangeLog2
src/maemo/modest-account-view-window.c
src/modest-account-mgr.c
src/widgets/modest-account-view.c
src/widgets/modest-account-view.h

index 42526c3..c4ad253 100644 (file)
@@ -1,5 +1,23 @@
 2007-05-09  Murray Cumming  <murrayc@murrayc.com>
 
+       * src/widgets/modest-account-view.h:
+       * src/widgets/modest-account-view.c: (on_account_changed),
+       (on_account_removed). Added a boolean flag, set/unset by 
+       modest_account_view_block_conf_updates(), 
+       modest_account_view_unblock_conf_updates() to prevent unnecessary 
+       updates, but this is not very useful because the gconf notifications are 
+       so delays (maybe only on Maemo Bora).
+       So auto-updating is turned off, and these functions do an explicit 
+       update when necessary.
+       However, something else is still doing too much work when adding/removing 
+       accounts, probably in another part of the application.
+       
+       * src/maemo/modest-account-view-window.c:
+       (on_delete_button_clicked), (on_edit_button_clicked),
+       (on_new_button_clicked): Use the new functions.
+
+2007-05-09  Murray Cumming  <murrayc@murrayc.com>
+
        * src/modest-account-mgr-helpers.c:
        (modest_account_mgr_set_first_account_as_default):
        Sort the list of names alphabetically-by-title, so we choose the first one 
index eba9ad3..0307e4e 100644 (file)
@@ -167,6 +167,10 @@ on_delete_button_clicked (GtkWidget *button, ModestAccountViewWindow *self)
                GtkWidget *dialog;
                gchar *txt;
 
+               /* Freeze updates, so we can do just one update afterwards, 
+                * instead of responding to every conf key change: */
+               modest_account_view_block_conf_updates (priv->account_view);
+               
                dialog = gtk_dialog_new_with_buttons (_("Confirmation dialog"),
                                                      GTK_WINDOW (self),
                                                      GTK_DIALOG_MODAL,
@@ -213,6 +217,9 @@ on_delete_button_clicked (GtkWidget *button, ModestAccountViewWindow *self)
                gtk_widget_destroy (dialog);
                g_free (account_title);
                g_free (account_name);
+               
+               /* Update the view: */
+               modest_account_view_unblock_conf_updates (priv->account_view);
        }
 }
 
@@ -225,6 +232,10 @@ on_edit_button_clicked (GtkWidget *button, ModestAccountViewWindow *self)
        if (!account_name)
                return;
                
+       /* Freeze updates, so we can do just one update afterwards, 
+        * instead of responding to every conf key change: */
+       modest_account_view_block_conf_updates (priv->account_view);
+               
        /* Show the Account Settings window: */
        ModestAccountSettingsDialog *dialog = modest_account_settings_dialog_new ();
        modest_account_settings_dialog_set_account_name (dialog, account_name);
@@ -234,16 +245,28 @@ on_edit_button_clicked (GtkWidget *button, ModestAccountViewWindow *self)
        gtk_widget_destroy (GTK_WIDGET (dialog));
        
        g_free (account_name);
+       
+       /* Update the view: */
+       modest_account_view_unblock_conf_updates (priv->account_view);  
 }
 
 static void
 on_new_button_clicked (GtkWidget *button, ModestAccountViewWindow *self)
 {
+       ModestAccountViewWindowPrivate *priv = MODEST_ACCOUNT_VIEW_WINDOW_GET_PRIVATE(self);
+       
+       /* Freeze updates, so we can do just one update afterwards, 
+        * instead of responding to every conf key change: */
+       modest_account_view_block_conf_updates (priv->account_view);
+       
        /* Show the easy-setup wizard: */
        ModestEasysetupWizardDialog *wizard = modest_easysetup_wizard_dialog_new ();
        gtk_window_set_transient_for (GTK_WINDOW (wizard), GTK_WINDOW (self));
        gtk_dialog_run (GTK_DIALOG (wizard));
        gtk_widget_destroy (GTK_WIDGET (wizard));
+       
+       /* Allow updates: */
+       modest_account_view_unblock_conf_updates (priv->account_view);
 }
 
 
index abe555f..99d40ef 100644 (file)
@@ -53,6 +53,8 @@ static guint signals[LAST_SIGNAL] = {0};
 static void
 on_key_change (ModestConf *conf, const gchar *key, ModestConfEvent event, gpointer user_data)
 {
+       /* printf("DEBUG: %s: key=%s\n", __FUNCTION__, key); */
+       
        ModestAccountMgr *self = MODEST_ACCOUNT_MGR (user_data);
        /* ModestAccountMgrPrivate *priv = MODEST_ACCOUNT_MGR_GET_PRIVATE (self); */
 
@@ -90,8 +92,8 @@ on_key_change (ModestConf *conf, const gchar *key, ModestConfEvent event, gpoint
        else 
                enabled = modest_account_mgr_get_enabled (self, account);
 
-       /* server account was changed, default account was changed
-        * and always notify when enabled/disabled changes
+       /* 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) ||
index eec3b42..b53e10b 100644 (file)
@@ -33,6 +33,7 @@
 #include <modest-account-mgr.h>
 #include <modest-account-mgr-helpers.h>
 #include <modest-text-utils.h>
+#include <modest-runtime.h>
 
 #include <gtk/gtkcellrenderertoggle.h>
 #include <gtk/gtkcellrenderertext.h>
@@ -69,6 +70,10 @@ struct _ModestAccountViewPrivate {
        ModestAccountMgr *account_mgr;
        gulong sig1, sig2;
        
+       /* When this is TRUE, we ignore configuration key changes.
+        * This is useful when making many changes. */
+       gboolean block_conf_updates;
+       
 };
 #define MODEST_ACCOUNT_VIEW_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \
                                                  MODEST_TYPE_ACCOUNT_VIEW, \
@@ -229,7 +234,21 @@ on_account_changed (ModestAccountMgr *account_mgr,
                    const gchar* account, const gchar* key,
                    gboolean server_account, ModestAccountView *self)
 {      
-       update_account_view (account_mgr, self);
+       /* Never update the view in response to gconf changes.
+        * Always do it explicitly instead.
+        * This is because we have no way to avoid 10 updates when changing 
+        * 10 items, and this blocks the UI.
+        *
+        * But this block/unblock API might be useful on platforms where the 
+        * notification does not happen so long after the key was set.
+        * (We have no way to know when the last key was set, to do a final update)..
+        */
+        return;
+        
+       ModestAccountViewPrivate* priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE(self);
+       
+       if (!priv->block_conf_updates)
+               update_account_view (account_mgr, self);
 }
 
 
@@ -238,7 +257,9 @@ on_account_removed (ModestAccountMgr *account_mgr,
                    const gchar* account, gboolean server_account,
                    ModestAccountView *self)
 {
-       on_account_changed (account_mgr, account, NULL, server_account, self);
+       ModestAccountViewPrivate* priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE(self);
+       if (!priv->block_conf_updates)
+               on_account_changed (account_mgr, account, NULL, server_account, self);
 }
 
 
@@ -430,3 +451,18 @@ modest_account_view_get_selected_account (ModestAccountView *self)
 
        return account_name;
 }
+
+
+void modest_account_view_block_conf_updates (ModestAccountView *account_view)
+{
+       ModestAccountViewPrivate* priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE(account_view);
+       priv->block_conf_updates = TRUE;
+}
+
+void modest_account_view_unblock_conf_updates (ModestAccountView *account_view)
+{
+       ModestAccountViewPrivate* priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE(account_view);
+       priv->block_conf_updates = FALSE;
+       
+       update_account_view (modest_runtime_get_account_mgr(), account_view);
+}
index aa16dd2..ba5992c 100644 (file)
@@ -87,6 +87,25 @@ ModestAccountView*   modest_account_view_new         (ModestAccountMgr *account_
  **/
 gchar*   modest_account_view_get_selected_account    (ModestAccountView *account_view);
 
+/** 
+ * modest_account_view_block_conf_updates
+ * @account_view: a #ModestAccountView
+ * 
+ * Stops the widget from updating in response to configuration key changes.
+ * This can be a useful optimization when making many configuration changes.
+ **/
+void modest_account_view_block_conf_updates    (ModestAccountView *account_view);
+
+/** 
+ * modest_account_view_unblock_conf_updates
+ * @account_view: a #ModestAccountView
+ * 
+ * Allows the widget tp update again in response to configuration key changes.
+ * When this is called it will cause the widget to immediately update its view from the 
+ * configuration data.
+ **/
+void modest_account_view_unblock_conf_updates    (ModestAccountView *account_view);
+
 G_END_DECLS
 
 #endif /* __MODEST_ACCOUNT_VIEW_H__ */