2007-08-01 Murray Cumming <murrayc@murrayc.com>
+ * 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 <murrayc@murrayc.com>
+
* 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)
TnyFolderStore *folder_store,
gboolean selected,
ModestMainWindow *main_window);
+
+static void
+set_at_least_one_account_visible(ModestMainWindow *self);
/* list my signals */
enum {
static void
restore_settings (ModestMainWindow *self, gboolean do_folder_view_too)
{
- printf ("DEBUGDEBUG: %s\n", __FUNCTION__);
-
ModestConf *conf;
ModestMainWindowPrivate *priv;
account_number_changed (TnyAccountStore *account_store,
const gchar *account_name,
gpointer user_data)
-{
+{
GSList *account_names, *iter, *accounts;
ModestMainWindow *self;
ModestMainWindowPrivate *priv;
/* 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);
}
/*
}
-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) {
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)
{
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)
{
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