From 6ebf456ad9d34d07c36667fa1e05118076d5dc38 Mon Sep 17 00:00:00 2001 From: Murray Cumming Date: Wed, 9 May 2007 15:59:30 +0000 Subject: [PATCH] 2007-05-09 Murray Cumming * 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 | 18 ++++++++++++++ src/maemo/modest-account-view-window.c | 23 ++++++++++++++++++ src/modest-account-mgr.c | 6 +++-- src/widgets/modest-account-view.c | 40 ++++++++++++++++++++++++++++++-- src/widgets/modest-account-view.h | 19 +++++++++++++++ 5 files changed, 102 insertions(+), 4 deletions(-) diff --git a/ChangeLog2 b/ChangeLog2 index 42526c3..c4ad253 100644 --- a/ChangeLog2 +++ b/ChangeLog2 @@ -1,5 +1,23 @@ 2007-05-09 Murray Cumming + * 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 + * 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 diff --git a/src/maemo/modest-account-view-window.c b/src/maemo/modest-account-view-window.c index eba9ad3..0307e4e 100644 --- a/src/maemo/modest-account-view-window.c +++ b/src/maemo/modest-account-view-window.c @@ -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); } diff --git a/src/modest-account-mgr.c b/src/modest-account-mgr.c index abe555f..99d40ef 100644 --- a/src/modest-account-mgr.c +++ b/src/modest-account-mgr.c @@ -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) || diff --git a/src/widgets/modest-account-view.c b/src/widgets/modest-account-view.c index eec3b42..b53e10b 100644 --- a/src/widgets/modest-account-view.c +++ b/src/widgets/modest-account-view.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -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); +} diff --git a/src/widgets/modest-account-view.h b/src/widgets/modest-account-view.h index aa16dd2..ba5992c 100644 --- a/src/widgets/modest-account-view.h +++ b/src/widgets/modest-account-view.h @@ -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__ */ -- 1.7.9.5