+
+gchar *
+modest_account_view_get_path_account (ModestAccountView *self, GtkTreePath *path)
+{
+ gchar *account_name = NULL;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+
+ g_return_val_if_fail (MODEST_IS_ACCOUNT_VIEW (self), NULL);
+
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (self));
+ if (gtk_tree_model_get_iter (model, &iter, path)) {
+ gtk_tree_model_get (model, &iter,
+ MODEST_ACCOUNT_VIEW_NAME_COLUMN,
+ &account_name, -1);
+ }
+
+ return account_name;
+}
+
+/* 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)
+{
+#ifdef MODEST_TOOLKIT_HILDON2
+ return;
+#endif
+ /* 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);
+}
+
+#ifndef MODEST_TOOLKIT_HILDON2
+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);
+ }
+}
+#endif
+
+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));
+}
+
+static void
+on_notify_style (GObject *obj, GParamSpec *spec, gpointer userdata)
+{
+ if (strcmp ("style", spec->name) == 0) {
+ gtk_widget_queue_draw (GTK_WIDGET (obj));
+ }
+}
+
+static void
+update_display_mode (ModestAccountView *self)
+{
+ ModestAccountViewPrivate *priv;
+ GtkTreeViewColumn *column;
+ GList *renderers;
+ GtkCellRenderer *renderer;
+
+ g_return_if_fail (MODEST_IS_ACCOUNT_VIEW (self));
+ priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE(self);
+
+ /* Last updated column */
+ column = gtk_tree_view_get_column (GTK_TREE_VIEW (self), 2);
+ gtk_tree_view_column_set_visible (column, !priv->picker_mode);
+
+ /* Name column */
+ column = gtk_tree_view_get_column (GTK_TREE_VIEW (self), 1);
+ renderers = gtk_tree_view_column_get_cell_renderers (column);
+ renderer = (GtkCellRenderer *) renderers->data;
+ g_object_set (renderer,
+ "align-set", TRUE,
+ "alignment", priv->picker_mode?PANGO_ALIGN_CENTER:PANGO_ALIGN_LEFT,
+ NULL);
+ g_list_free (renderers);
+}
+
+void
+modest_account_view_set_picker_mode (ModestAccountView *self, gboolean enable)
+{
+ ModestAccountViewPrivate *priv;
+
+ g_return_if_fail (MODEST_IS_ACCOUNT_VIEW (self));
+ priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE(self);
+
+ priv->picker_mode = enable;
+ update_display_mode (self);
+}
+
+gboolean
+modest_account_view_get_picker_mode (ModestAccountView *self)
+{
+ ModestAccountViewPrivate *priv;
+
+ g_return_val_if_fail (MODEST_IS_ACCOUNT_VIEW (self), FALSE);
+ priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE(self);
+
+ return priv->picker_mode;
+}
+
+void
+modest_account_view_set_show_last_update (ModestAccountView *self,
+ gboolean show)
+{
+ ModestAccountViewPrivate *priv;
+
+ g_return_if_fail (MODEST_IS_ACCOUNT_VIEW (self));
+ priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE(self);
+
+ priv->show_last_updated = show;
+ update_account_view (priv->account_mgr, self);
+}
+
+gboolean
+modest_account_view_get_show_last_updated (ModestAccountView *self)
+{
+ ModestAccountViewPrivate *priv;
+
+ g_return_val_if_fail (MODEST_IS_ACCOUNT_VIEW (self), FALSE);
+ priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE(self);
+
+ return priv->show_last_updated;
+}
+
+GtkTreeModel *
+modest_account_view_get_model (ModestAccountView *self)
+{
+ ModestAccountViewPrivate *priv;
+
+ priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE (self);
+
+ return priv->model;
+}
+
+GtkTreeModel *
+modest_account_view_get_filter (ModestAccountView *self)
+{
+ ModestAccountViewPrivate *priv;
+
+ priv = MODEST_ACCOUNT_VIEW_GET_PRIVATE (self);
+
+ return priv->filter;
+}
+
+#ifdef MODEST_TOOLKIT_HILDON2
+static gboolean
+live_search_visible_func (GtkTreeModel *model,
+ GtkTreeIter *iter,
+ gchar *text,
+ gpointer data)
+{
+ gchar *display_name;
+ gboolean result;
+ gtk_tree_model_get(model, iter,
+ MODEST_ACCOUNT_VIEW_DISPLAY_NAME_COLUMN,
+ &display_name, -1);
+
+ result = modest_text_utils_live_search_find (display_name, text);
+
+ g_free (display_name);
+
+ return result;
+}
+
+GtkWidget *
+modest_account_view_setup_live_search (ModestAccountView *self)
+{
+ GtkWidget *live_search;
+ live_search = hildon_live_search_new ();
+ hildon_live_search_set_filter (HILDON_LIVE_SEARCH (live_search),
+ GTK_TREE_MODEL_FILTER (modest_account_view_get_filter (MODEST_ACCOUNT_VIEW (self))));
+ hildon_live_search_set_visible_func (HILDON_LIVE_SEARCH (live_search), live_search_visible_func, self, NULL);
+ hildon_live_search_set_text_column (HILDON_LIVE_SEARCH (live_search),
+ MODEST_ACCOUNT_VIEW_DISPLAY_NAME_COLUMN);
+
+ return live_search;
+}
+#endif