From 01db4e94dcf1e9818000eb08c90bc3b09c3a5071 Mon Sep 17 00:00:00 2001 From: Murray Cumming Date: Wed, 1 Aug 2007 18:29:35 +0000 Subject: [PATCH] 2007-08-01 Murray Cumming * src/modest-account-mgr-helpers.h: * src/modest-account-mgr-helpers.c: Added modest_account_mgr_get_first_account_name(), using code from modest_account_mgr_set_first_account_as_default(). * src/maemo/modest-main-window.c: Added set_at_least_one_account_visible(). (account_number_changed): Call set_at_least_one_account_visible() so that the first account is visible when first added, without the user having to use the View menu. I do wonder how this worked before. pmo-trunk-r2900 --- ChangeLog2 | 13 ++++++++ src/maemo/modest-main-window.c | 66 ++++++++++++++++++++++++++++---------- src/modest-account-mgr-helpers.c | 49 +++++++++++++++++----------- src/modest-account-mgr-helpers.h | 4 +++ 4 files changed, 96 insertions(+), 36 deletions(-) diff --git a/ChangeLog2 b/ChangeLog2 index 884db61..bf3ba61 100644 --- a/ChangeLog2 +++ b/ChangeLog2 @@ -1,5 +1,18 @@ 2007-08-01 Murray Cumming + * src/modest-account-mgr-helpers.h: + * src/modest-account-mgr-helpers.c: + Added modest_account_mgr_get_first_account_name(), + using code from modest_account_mgr_set_first_account_as_default(). + + * src/maemo/modest-main-window.c: Added set_at_least_one_account_visible(). + (account_number_changed): Call set_at_least_one_account_visible() so that + the first account is visible when first added, without the user having to + use the View menu. + I do wonder how this worked before. + +2007-08-01 Murray Cumming + * src/modest-tny-account-store.c: (show_password_warning_only), (show_wrong_password), (request_password_and_wait), (get_password), (modest_tny_account_store_alert): Remove the (incomplete anyway) diff --git a/src/maemo/modest-main-window.c b/src/maemo/modest-main-window.c index 9bb6f3f..5fd735c 100644 --- a/src/maemo/modest-main-window.c +++ b/src/maemo/modest-main-window.c @@ -161,6 +161,9 @@ modest_main_window_on_folder_selection_changed (ModestFolderView *folder_view, TnyFolderStore *folder_store, gboolean selected, ModestMainWindow *main_window); + +static void +set_at_least_one_account_visible(ModestMainWindow *self); /* list my signals */ enum { @@ -399,8 +402,6 @@ modest_main_window_get_child_widget (ModestMainWindow *self, static void restore_settings (ModestMainWindow *self, gboolean do_folder_view_too) { - printf ("DEBUGDEBUG: %s\n", __FUNCTION__); - ModestConf *conf; ModestMainWindowPrivate *priv; @@ -1253,7 +1254,7 @@ static void account_number_changed (TnyAccountStore *account_store, const gchar *account_name, gpointer user_data) -{ +{ GSList *account_names, *iter, *accounts; ModestMainWindow *self; ModestMainWindowPrivate *priv; @@ -1515,6 +1516,11 @@ account_number_changed (TnyAccountStore *account_store, /* Frees */ g_slist_free (accounts); g_free (default_account); + + + /* Make sure that at least one account is viewed if there are any + * accounts, for instance when adding the first account: */ + set_at_least_one_account_visible (self); } /* @@ -2158,23 +2164,14 @@ on_queue_changed (ModestMailOperationQueue *queue, } -static void -on_show_account_action_activated (GtkAction *action, - gpointer user_data) +static void +set_account_visible(ModestMainWindow *self, const gchar *acc_name) { - ModestAccountData *acc_data; - ModestMainWindow *self; - ModestMainWindowPrivate *priv; - ModestAccountMgr *mgr; - const gchar *acc_name; - - self = MODEST_MAIN_WINDOW (user_data); - priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self); + ModestMainWindowPrivate *priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self); /* Get account data */ - acc_name = gtk_action_get_name (action); - mgr = modest_runtime_get_account_mgr (); - acc_data = modest_account_mgr_get_account_data (mgr, acc_name); + ModestAccountMgr *mgr = modest_runtime_get_account_mgr (); + ModestAccountData *acc_data = modest_account_mgr_get_account_data (mgr, acc_name); /* Set the new visible & active account */ if (acc_data && acc_data->store_account) { @@ -2190,6 +2187,41 @@ on_show_account_action_activated (GtkAction *action, modest_account_mgr_free_account_data (mgr, acc_data); } +/* Make sure that at least one account is "viewed": */ +static void +set_at_least_one_account_visible(ModestMainWindow *self) +{ + ModestMainWindowPrivate *priv = MODEST_MAIN_WINDOW_GET_PRIVATE(self); + ModestAccountMgr *account_mgr = modest_runtime_get_account_mgr(); + + if (!(priv->folder_view)) { + /* It is too early to do this. */ + return; + } + + const gchar *active_server_account_name = + modest_folder_view_get_account_id_of_visible_server_account (priv->folder_view); + if (!active_server_account_name || + !modest_account_mgr_account_exists (account_mgr, active_server_account_name, TRUE)) + { + gchar* first_modest_name = modest_account_mgr_get_first_account_name (account_mgr); + if (first_modest_name) { + set_account_visible (self, first_modest_name); + g_free (first_modest_name); + } + } +} + +static void +on_show_account_action_activated (GtkAction *action, + gpointer user_data) +{ + ModestMainWindow *self = MODEST_MAIN_WINDOW (user_data); + + const gchar *acc_name = gtk_action_get_name (action); + set_account_visible (self, acc_name); +} + static void refresh_account (const gchar *account_name) { diff --git a/src/modest-account-mgr-helpers.c b/src/modest-account-mgr-helpers.c index 6d08c40..2bd6b3e 100644 --- a/src/modest-account-mgr-helpers.c +++ b/src/modest-account-mgr-helpers.c @@ -614,48 +614,59 @@ gint on_accounts_list_sort_by_title(gconstpointer a, gconstpointer b) return g_utf8_collate((const gchar*)a, (const gchar*)b); } -gboolean -modest_account_mgr_set_first_account_as_default (ModestAccountMgr *self) +/** Get the first one, alphabetically, by title. */ +gchar* +modest_account_mgr_get_first_account_name (ModestAccountMgr *self) { - gchar *old_default; - gboolean result = FALSE, found; - GSList* list_sorted, *iter; const gchar* account_name = NULL; GSList *account_names = modest_account_mgr_account_names (self, TRUE /* only enabled */); /* Return TRUE if there is no account */ if (!account_names) - return TRUE; - + return NULL; + /* Get the first one, alphabetically, by title: */ - old_default = modest_account_mgr_get_default_account (self); - list_sorted = g_slist_sort (account_names, on_accounts_list_sort_by_title); + /* gchar *old_default = modest_account_mgr_get_default_account (self); */ + GSList* list_sorted = g_slist_sort (account_names, on_accounts_list_sort_by_title); - iter = list_sorted; - found = FALSE; + GSList* iter = list_sorted; + gboolean found = FALSE; while (iter && !found) { account_name = (const gchar*)list_sorted->data; - if (old_default) { - /* The new should be different than the old one */ - if (strcmp (old_default, account_name)) - found = TRUE; - } else + if (account_name) found = TRUE; if (!found) iter = g_slist_next (iter); } - if (found && account_name) - result = modest_account_mgr_set_default_account (self, account_name); - + gchar* result = NULL; + if (account_name) + result = g_strdup (account_name); + modest_account_mgr_free_account_names (account_names); account_names = NULL; return result; } +gboolean +modest_account_mgr_set_first_account_as_default (ModestAccountMgr *self) +{ + gboolean result = FALSE; + + gchar* account_name = modest_account_mgr_get_first_account_name(self); + if (account_name) { + result = modest_account_mgr_set_default_account (self, account_name); + g_free (account_name); + } + else + result = TRUE; /* If there are no accounts then it's not a failure. */ + + return result; +} + gchar* modest_account_mgr_get_from_string (ModestAccountMgr *self, const gchar* name) { diff --git a/src/modest-account-mgr-helpers.h b/src/modest-account-mgr-helpers.h index d5b020e..5143220 100644 --- a/src/modest-account-mgr-helpers.h +++ b/src/modest-account-mgr-helpers.h @@ -128,6 +128,10 @@ gboolean modest_account_mgr_unset_default_account (ModestAccountMgr *self); gboolean modest_account_mgr_set_first_account_as_default (ModestAccountMgr *self); +/** Get the first one, alphabetically, by title. */ +gchar* +modest_account_mgr_get_first_account_name (ModestAccountMgr *self); + /** * modest_account_mgr_free_account_data: * @self: a ModestAccountMgr instance -- 1.7.9.5