From f13a2425f1f0f22fce4d2416b2cefe429fcce615 Mon Sep 17 00:00:00 2001 From: Jose Dapena Paz Date: Thu, 24 Apr 2008 17:31:14 +0000 Subject: [PATCH] Avoid a blank message list pane when an account os defined/removed (fixes NB#84714). pmo-trunk-r4468 --- src/modest-ui-actions.c | 1 - src/widgets/modest-folder-view.c | 104 +++++++++++++++++++++++--------------- 2 files changed, 64 insertions(+), 41 deletions(-) diff --git a/src/modest-ui-actions.c b/src/modest-ui-actions.c index 1c86dc9..9d27ff4 100644 --- a/src/modest-ui-actions.c +++ b/src/modest-ui-actions.c @@ -648,7 +648,6 @@ modest_ui_actions_on_accounts (GtkAction *action, } else { /* Show the list of accounts */ GtkWindow *account_win = GTK_WINDOW (modest_account_view_window_new ()); - gtk_window_set_transient_for (account_win, GTK_WINDOW (win)); /* The accounts dialog must be modal */ modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), account_win); diff --git a/src/widgets/modest-folder-view.c b/src/widgets/modest-folder-view.c index 8a9ba72..fe5ab9c 100644 --- a/src/widgets/modest-folder-view.c +++ b/src/widgets/modest-folder-view.c @@ -1246,14 +1246,60 @@ on_account_inserted (TnyAccountStore *account_store, } +static gboolean +same_account_selected (ModestFolderView *self, + TnyAccount *account) +{ + ModestFolderViewPrivate *priv; + gboolean same_account = FALSE; + + priv = MODEST_FOLDER_VIEW_GET_PRIVATE (self); + + if (priv->cur_folder_store) { + TnyAccount *selected_folder_account = NULL; + + if (TNY_IS_FOLDER (priv->cur_folder_store)) { + selected_folder_account = + tny_folder_get_account (TNY_FOLDER (priv->cur_folder_store)); + } else { + selected_folder_account = + TNY_ACCOUNT (g_object_ref (priv->cur_folder_store)); + } + + if (selected_folder_account == account) + same_account = TRUE; + + g_object_unref (selected_folder_account); + } + return same_account; +} + +/** + * + * Selects the first inbox or the local account in an idle + */ +static gboolean +on_idle_select_first_inbox_or_local (gpointer user_data) +{ + ModestFolderView *self = MODEST_FOLDER_VIEW (user_data); + + gdk_threads_enter (); + modest_folder_view_select_first_inbox_or_local (self); + gdk_threads_leave (); + + return FALSE; +} + static void on_account_changed (TnyAccountStore *account_store, TnyAccount *tny_account, gpointer user_data) { + ModestFolderView *self; ModestFolderViewPrivate *priv; GtkTreeModel *sort_model, *filter_model; GtkTreeSelection *sel; + gboolean same_account; /* Ignore transport account insertions, we're not showing them in the folder view */ @@ -1265,7 +1311,7 @@ on_account_changed (TnyAccountStore *account_store, return; } - + self = MODEST_FOLDER_VIEW (user_data); priv = MODEST_FOLDER_VIEW_GET_PRIVATE (user_data); /* Get the inner model */ @@ -1275,16 +1321,19 @@ on_account_changed (TnyAccountStore *account_store, return; } - sort_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (filter_model)); if (!GTK_IS_TREE_MODEL_SORT(sort_model)) { g_warning ("BUG: %s: not a valid sort model", __FUNCTION__); return; } - /* Unselect the folder, clear the header list */ - sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (user_data)); - gtk_tree_selection_unselect_all (sel); + /* Invalidate the cur_folder_store only if the selected folder + belongs to the account that is being removed */ + same_account = same_account_selected (self, tny_account); + if (same_account) { + sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (self)); + gtk_tree_selection_unselect_all (sel); + } /* Remove the account from the model */ tny_list_remove (TNY_LIST (gtk_tree_model_sort_get_model (GTK_TREE_MODEL_SORT (sort_model))), @@ -1296,25 +1345,13 @@ on_account_changed (TnyAccountStore *account_store, /* Refilter the model */ gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (filter_model)); -} -/** - * - * Selects the first inbox or the local account in an idle - */ -static gboolean -on_idle_select_first_inbox_or_local (gpointer user_data) -{ - ModestFolderView *self = MODEST_FOLDER_VIEW (user_data); - - gdk_threads_enter (); - modest_folder_view_select_first_inbox_or_local (self); - gdk_threads_leave (); - - return FALSE; + /* Select the first INBOX if the currently selected folder + belongs to the account that is being deleted */ + if (same_account) + g_idle_add (on_idle_select_first_inbox_or_local, self); } - static void on_account_removed (TnyAccountStore *account_store, TnyAccount *account, @@ -1324,7 +1361,7 @@ on_account_removed (TnyAccountStore *account_store, ModestFolderViewPrivate *priv; GtkTreeModel *sort_model, *filter_model; GtkTreeSelection *sel = NULL; - gboolean same_account_selected = FALSE; + gboolean same_account = FALSE; /* Ignore transport account removals, we're not showing them in the folder view */ @@ -1341,23 +1378,10 @@ on_account_removed (TnyAccountStore *account_store, /* Invalidate the cur_folder_store only if the selected folder belongs to the account that is being removed */ - if (priv->cur_folder_store) { - TnyAccount *selected_folder_account = NULL; - - if (TNY_IS_FOLDER (priv->cur_folder_store)) { - selected_folder_account = - tny_folder_get_account (TNY_FOLDER (priv->cur_folder_store)); - } else { - selected_folder_account = - TNY_ACCOUNT (g_object_ref (priv->cur_folder_store)); - } - - if (selected_folder_account == account) { - sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (self)); - gtk_tree_selection_unselect_all (sel); - same_account_selected = TRUE; - } - g_object_unref (selected_folder_account); + same_account = same_account_selected (self, account); + if (same_account) { + sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (self)); + gtk_tree_selection_unselect_all (sel); } /* Invalidate row to select only if the folder to select @@ -1408,7 +1432,7 @@ on_account_removed (TnyAccountStore *account_store, /* Select the first INBOX if the currently selected folder belongs to the account that is being deleted */ - if (same_account_selected) + if (same_account) g_idle_add (on_idle_select_first_inbox_or_local, self); } -- 1.7.9.5