+
+/*
+ * This function manages the navigation through the folders using the
+ * keyboard or the hardware keys in the device
+ */
+static gboolean
+on_key_pressed (GtkWidget *self,
+ GdkEventKey *event,
+ gpointer user_data)
+{
+ GtkTreeSelection *selection;
+ GtkTreeIter iter;
+ GtkTreeModel *model;
+ gboolean retval = FALSE;
+
+ /* Up and Down are automatically managed by the treeview */
+ if (event->keyval == GDK_Return) {
+ /* Expand/Collapse the selected row */
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (self));
+ if (gtk_tree_selection_get_selected (selection, &model, &iter)) {
+ GtkTreePath *path;
+
+ path = gtk_tree_model_get_path (model, &iter);
+
+ if (gtk_tree_view_row_expanded (GTK_TREE_VIEW (self), path))
+ gtk_tree_view_collapse_row (GTK_TREE_VIEW (self), path);
+ else
+ gtk_tree_view_expand_row (GTK_TREE_VIEW (self), path, FALSE);
+ gtk_tree_path_free (path);
+ }
+ /* No further processing */
+ retval = TRUE;
+ }
+
+ return retval;
+}
+
+/*
+ * We listen to the changes in the local folder account name key,
+ * because we want to show the right name in the view. The local
+ * folder account name corresponds to the device name in the Maemo
+ * version. We do this because we do not want to query gconf on each
+ * tree view refresh. It's better to cache it and change whenever
+ * necessary.
+ */
+static void
+on_configuration_key_changed (ModestConf* conf,
+ const gchar *key,
+ ModestConfEvent event,
+ ModestFolderView *self)
+{
+ ModestFolderViewPrivate *priv;
+
+ if (!key)
+ return;
+
+ priv = MODEST_FOLDER_VIEW_GET_PRIVATE(self);
+
+ if (!strcmp (key, MODEST_CONF_DEVICE_NAME)) {
+ g_free (priv->local_account_name);
+
+ if (event == MODEST_CONF_EVENT_KEY_UNSET)
+ priv->local_account_name = g_strdup (MODEST_LOCAL_FOLDERS_DEFAULT_DISPLAY_NAME);
+ else
+ priv->local_account_name = modest_conf_get_string (modest_runtime_get_conf(),
+ MODEST_CONF_DEVICE_NAME, NULL);
+
+ /* Force a redraw */
+#if GTK_CHECK_VERSION(2, 8, 0) /* gtk_tree_view_column_queue_resize is only available in GTK+ 2.8 */
+ GtkTreeViewColumn * tree_column = gtk_tree_view_get_column (GTK_TREE_VIEW (self),
+ TNY_GTK_FOLDER_STORE_TREE_MODEL_NAME_COLUMN);
+ gtk_tree_view_column_queue_resize (tree_column);
+#endif
+ }
+}
+
+void
+modest_folder_view_set_style (ModestFolderView *self,
+ ModestFolderViewStyle style)
+{
+ ModestFolderViewPrivate *priv;
+
+ g_return_if_fail (self);
+
+ priv = MODEST_FOLDER_VIEW_GET_PRIVATE(self);
+
+ priv->style = style;
+}
+
+void
+modest_folder_view_set_account_id_of_visible_server_account (ModestFolderView *self,
+ const gchar *account_id)
+{
+ ModestFolderViewPrivate *priv;
+ ModestConf *conf;
+
+ g_return_if_fail (self);
+
+ priv = MODEST_FOLDER_VIEW_GET_PRIVATE(self);
+
+ if (priv->visible_account_id)
+ g_free (priv->visible_account_id);
+ priv->visible_account_id = g_strdup (account_id);
+
+ /* Save preferences */
+ conf = modest_runtime_get_conf ();
+ modest_widget_memory_save (conf, G_OBJECT (self), MODEST_CONF_FOLDER_VIEW_KEY);
+}
+
+const gchar *
+modest_folder_view_get_account_id_of_visible_server_account (ModestFolderView *self)
+{
+ ModestFolderViewPrivate *priv;
+
+ g_return_val_if_fail (self, NULL);
+
+ priv = MODEST_FOLDER_VIEW_GET_PRIVATE(self);
+
+ return (const gchar *) priv->visible_account_id;
+}