+translate_path (gchar **path)
+{
+ gchar **parts;
+ gchar **current;
+ GString *output;
+ gboolean add_separator;
+
+ parts = g_strsplit (*path, MOVE_TO_FOLDER_SEPARATOR, 0);
+ g_free (*path);
+
+ current = parts;
+ output = g_string_new ("");
+ add_separator = FALSE;
+
+ while (*current != NULL) {
+ TnyFolderType folder_type;
+ gchar *downcase;
+
+ if (add_separator) {
+ output = g_string_append (output, MOVE_TO_FOLDER_SEPARATOR);
+ } else {
+ add_separator = TRUE;
+ }
+
+ downcase = g_ascii_strdown (*current, -1);
+ folder_type = modest_local_folder_info_get_type (downcase);
+ if (strcmp (downcase, "inbox") == 0) {
+ output = g_string_append (output, _("mcen_me_folder_inbox"));
+ } else if (folder_type == TNY_FOLDER_TYPE_ARCHIVE ||
+ folder_type == TNY_FOLDER_TYPE_DRAFTS ||
+ folder_type == TNY_FOLDER_TYPE_SENT ||
+ folder_type == TNY_FOLDER_TYPE_OUTBOX) {
+ output = g_string_append (output, modest_local_folder_info_get_type_display_name (folder_type));
+ } else {
+ output = g_string_append (output, *current);
+ }
+ g_free (downcase);
+
+ current++;
+ }
+
+ g_strfreev (parts);
+ *path = g_string_free (output, FALSE);
+}
+
+static void
+move_to_dialog_set_selected_folder_store (GtkWidget *dialog,
+ TnyFolderStore *folder_store)
+{
+ GtkWidget *action_button;
+ GtkWidget *image = NULL;
+ TnyAccount *account;
+ gchar *account_name = NULL, *short_name = NULL;
+
+ action_button = GTK_WIDGET (g_object_get_data (G_OBJECT (dialog), MOVE_TO_DIALOG_ACTION_BUTTON));
+
+ /* Get account name */
+ if (TNY_IS_FOLDER (folder_store))
+ account = tny_folder_get_account (TNY_FOLDER (folder_store));
+ else
+ account = g_object_ref (folder_store);
+
+ if (modest_tny_account_is_virtual_local_folders (account))
+ account_name = modest_conf_get_string (modest_runtime_get_conf(),
+ MODEST_CONF_DEVICE_NAME, NULL);
+
+ if (!account_name)
+ account_name = g_strdup (tny_account_get_name (account));
+
+ g_object_unref (account);
+
+ /* Set title of button: account or folder name */
+ if (TNY_IS_FOLDER (folder_store))
+ short_name = folder_store_get_display_name (folder_store);
+ else
+ short_name = g_strdup (account_name);
+
+ hildon_button_set_title (HILDON_BUTTON (action_button), short_name);
+
+ /* Set value of button, folder full name */
+ if (TNY_IS_CAMEL_FOLDER (folder_store)) {
+ const gchar *camel_full_name;
+ gchar *last_slash, *full_name;
+
+ camel_full_name = tny_camel_folder_get_full_name (TNY_CAMEL_FOLDER (folder_store));
+ last_slash = g_strrstr (camel_full_name, "/");
+ if (last_slash) {
+ gchar *prefix = g_strndup (camel_full_name, last_slash - camel_full_name + 1);
+ full_name = g_strconcat (account_name, MOVE_TO_FOLDER_SEPARATOR, prefix, short_name, NULL);
+ g_free (prefix);
+ } else {
+ full_name = g_strconcat (account_name, MOVE_TO_FOLDER_SEPARATOR,
+ short_name,
+ NULL);
+ }
+ translate_path (&full_name);
+ hildon_button_set_value (HILDON_BUTTON (action_button), full_name);
+ g_free (full_name);
+ }
+ g_free (account_name);
+ g_free (short_name);
+
+ /* Set image for the button */
+ image = get_image_for_folder_store (folder_store, MODEST_ICON_SIZE_BIG);
+ if (image)
+ hildon_button_set_image (HILDON_BUTTON (action_button), image);
+}
+
+static void
+move_to_dialog_show_accounts (GtkWidget *dialog)
+{
+ GtkWidget *back_button;
+ GtkWidget *folder_view;
+ GtkWidget *pannable;
+ GtkWidget *action_button;
+
+ back_button = GTK_WIDGET (g_object_get_data (G_OBJECT (dialog), MOVE_TO_DIALOG_BACK_BUTTON));
+ action_button = GTK_WIDGET (g_object_get_data (G_OBJECT (dialog), MOVE_TO_DIALOG_ACTION_BUTTON));
+ folder_view = GTK_WIDGET (g_object_get_data (G_OBJECT (dialog), MOVE_TO_DIALOG_FOLDER_VIEW));
+ pannable = GTK_WIDGET (g_object_get_data (G_OBJECT (dialog), MOVE_TO_DIALOG_PANNABLE));
+
+ gtk_widget_set_sensitive (back_button, FALSE);
+ gtk_widget_set_sensitive (action_button, FALSE);
+
+ /* Need to set this here, otherwise callbacks called because
+ of filtering won't perform correctly */
+ g_object_set_data (G_OBJECT (dialog), MOVE_TO_DIALOG_SHOWING_FOLDERS, GINT_TO_POINTER (FALSE));
+
+ /* Reset action button */
+ hildon_button_set_title (HILDON_BUTTON (action_button), NULL);
+ hildon_button_set_value (HILDON_BUTTON (action_button), NULL);
+ hildon_button_set_image (HILDON_BUTTON (action_button), NULL);
+
+ modest_folder_view_set_account_id_of_visible_server_account (MODEST_FOLDER_VIEW (folder_view), NULL);
+ modest_folder_view_show_non_move_folders (MODEST_FOLDER_VIEW (folder_view), TRUE);
+ modest_folder_view_set_style (MODEST_FOLDER_VIEW (folder_view), MODEST_FOLDER_VIEW_STYLE_SHOW_ALL);
+ modest_folder_view_unset_filter (MODEST_FOLDER_VIEW (folder_view),
+ MODEST_FOLDER_VIEW_FILTER_HIDE_MCC_FOLDERS);
+ modest_folder_view_unset_filter (MODEST_FOLDER_VIEW (folder_view),
+ MODEST_FOLDER_VIEW_FILTER_HIDE_LOCAL_FOLDERS);
+ modest_folder_view_unset_filter (MODEST_FOLDER_VIEW (folder_view),
+ MODEST_FOLDER_VIEW_FILTER_HIDE_ACCOUNTS);
+ modest_folder_view_set_filter (MODEST_FOLDER_VIEW (folder_view),
+ MODEST_FOLDER_VIEW_FILTER_HIDE_FOLDERS);
+ hildon_pannable_area_jump_to (HILDON_PANNABLE_AREA (pannable), 0, 0);
+}
+
+static void
+move_to_dialog_show_folders (GtkWidget *dialog, TnyFolderStore *folder_store)
+{
+ GtkWidget *back_button;
+ GtkWidget *folder_view;
+ TnyAccount *account;
+ const gchar *account_id;
+ GtkWidget *pannable;
+ GtkWidget *action_button;
+
+ back_button =
+ GTK_WIDGET (g_object_get_data (G_OBJECT (dialog), MOVE_TO_DIALOG_BACK_BUTTON));
+ action_button =
+ GTK_WIDGET (g_object_get_data (G_OBJECT (dialog), MOVE_TO_DIALOG_ACTION_BUTTON));
+ folder_view =
+ GTK_WIDGET (g_object_get_data (G_OBJECT (dialog), MOVE_TO_DIALOG_FOLDER_VIEW));
+ pannable =
+ GTK_WIDGET (g_object_get_data (G_OBJECT (dialog), MOVE_TO_DIALOG_PANNABLE));
+
+ gtk_widget_set_sensitive (back_button, TRUE);
+ gtk_widget_set_sensitive (action_button, TRUE);
+
+ /* Need to set this here, otherwise callbacks called because
+ of filtering won't perform correctly */
+ g_object_set_data (G_OBJECT (dialog),
+ MOVE_TO_DIALOG_SHOWING_FOLDERS,
+ GINT_TO_POINTER (TRUE));
+
+ account = TNY_ACCOUNT (folder_store);
+ if (modest_tny_account_is_virtual_local_folders (account)) {
+ account_id = tny_account_get_id (account);
+ modest_folder_view_set_filter (MODEST_FOLDER_VIEW (folder_view),
+ MODEST_FOLDER_VIEW_FILTER_HIDE_MCC_FOLDERS);
+ } else if (modest_tny_account_is_memory_card_account (account)) {
+ account_id = tny_account_get_id (account);
+ modest_folder_view_set_filter (MODEST_FOLDER_VIEW (folder_view),
+ MODEST_FOLDER_VIEW_FILTER_HIDE_LOCAL_FOLDERS);
+ } else {
+ account_id = tny_account_get_id (account);
+ modest_folder_view_set_filter (MODEST_FOLDER_VIEW (folder_view),
+ MODEST_FOLDER_VIEW_FILTER_HIDE_LOCAL_FOLDERS);
+ modest_folder_view_set_filter (MODEST_FOLDER_VIEW (folder_view),
+ MODEST_FOLDER_VIEW_FILTER_HIDE_MCC_FOLDERS);
+ }
+
+ move_to_dialog_set_selected_folder_store (dialog, folder_store);
+ modest_folder_view_set_account_id_of_visible_server_account (MODEST_FOLDER_VIEW (folder_view),
+ account_id);
+
+ modest_folder_view_show_non_move_folders (MODEST_FOLDER_VIEW (folder_view), FALSE);
+ modest_folder_view_set_style (MODEST_FOLDER_VIEW (folder_view), MODEST_FOLDER_VIEW_STYLE_SHOW_ONE);
+ modest_folder_view_set_filter (MODEST_FOLDER_VIEW (folder_view), MODEST_FOLDER_VIEW_FILTER_HIDE_ACCOUNTS);
+ modest_folder_view_unset_filter (MODEST_FOLDER_VIEW (folder_view), MODEST_FOLDER_VIEW_FILTER_HIDE_FOLDERS);
+ hildon_pannable_area_jump_to (HILDON_PANNABLE_AREA (pannable), 0, 0);
+}
+
+static void
+on_move_to_dialog_back_clicked (GtkButton *button,
+ gpointer userdata)
+{
+ GtkWidget *dialog = (GtkWidget *) userdata;
+
+ /* Back to show accounts */
+ move_to_dialog_show_accounts (dialog);
+}
+
+static void
+on_move_to_dialog_row_activated (GtkTreeView *tree_view,