+
+/* This allows us to pass more than one piece of data to the signal handler,
+ * and get a result: */
+typedef struct
+{
+ ModestAccountView* self;
+ const gchar *account_name;
+} ForEachData;
+
+static gboolean
+on_model_foreach_select_account(GtkTreeModel *model,
+ GtkTreePath *path, GtkTreeIter *iter, gpointer user_data)
+{
+ ForEachData *state = (ForEachData*)(user_data);
+
+ /* Select the item if it has the matching account name: */
+ gchar *this_account_name = NULL;
+ gtk_tree_model_get (model, iter,
+ MODEST_ACCOUNT_VIEW_NAME_COLUMN, &this_account_name,
+ -1);
+ if(this_account_name && state->account_name
+ && (strcmp (this_account_name, state->account_name) == 0)) {
+
+ GtkTreeSelection *selection =
+ gtk_tree_view_get_selection (GTK_TREE_VIEW (state->self));
+ gtk_tree_selection_select_iter (selection, iter);
+
+ return TRUE; /* Stop walking the tree. */
+ }
+
+ return FALSE; /* Keep walking the tree. */
+}
+
+static void
+modest_account_view_select_account (ModestAccountView *account_view,
+ const gchar* account_name)
+{
+ /* Create a state instance so we can send two items of data to the signal handler: */
+ ForEachData *state = g_new0 (ForEachData, 1);
+ state->self = account_view;
+ state->account_name = account_name;
+
+ GtkTreeModel *model = gtk_tree_view_get_model (
+ GTK_TREE_VIEW (account_view));
+ gtk_tree_model_foreach (model,
+ on_model_foreach_select_account, state);
+
+ g_free (state);
+}
+
+static void
+modest_account_view_select_first_account (ModestAccountView *account_view)
+{
+ GtkTreeIter iter;
+ GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (account_view));
+
+ if (gtk_tree_model_get_iter_first (model, &iter)) {
+ GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (account_view));
+
+ gtk_tree_selection_select_iter (selection, &iter);
+ }
+}
+
+static void
+on_default_account_changed (ModestAccountMgr *mgr,
+ gpointer user_data)
+{
+ GtkTreeIter iter;
+ gchar *default_account_name;
+ GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (user_data));
+
+ if (!gtk_tree_model_get_iter_first(model, &iter))
+ return;
+
+ default_account_name = modest_account_mgr_get_default_account (mgr);
+
+ do {
+ gboolean is_default;
+ gchar *name;
+
+ gtk_tree_model_get (model, &iter,
+ MODEST_ACCOUNT_VIEW_NAME_COLUMN, &name,
+ MODEST_ACCOUNT_VIEW_IS_DEFAULT_COLUMN, &is_default,
+ -1);
+
+ /* Update the default account column */
+ if ((default_account_name != NULL) && (!strcmp (name, default_account_name)))
+ gtk_list_store_set (GTK_LIST_STORE (model), &iter,
+ MODEST_ACCOUNT_VIEW_IS_DEFAULT_COLUMN, TRUE, -1);
+ else
+ gtk_list_store_set (GTK_LIST_STORE (model), &iter,
+ MODEST_ACCOUNT_VIEW_IS_DEFAULT_COLUMN, FALSE, -1);
+
+ g_free (name);
+
+ } while (gtk_tree_model_iter_next(model, &iter));
+
+ /* Free and force a redraw */
+ g_free (default_account_name);
+ gtk_widget_queue_draw (GTK_WIDGET (user_data));
+}
+
+static void
+on_display_name_changed (ModestAccountMgr *mgr,
+ const gchar *account,
+ gpointer user_data)
+{
+ /* Update the view */
+ update_account_view (mgr, MODEST_ACCOUNT_VIEW (user_data));
+}