+
+}
+
+typedef struct _FolderChooserData {
+ TnyFolderStore *store;
+ GtkWidget *dialog;
+} FolderChooserData;
+
+static void
+folder_chooser_activated (ModestFolderView *folder_view,
+ TnyFolderStore *folder,
+ FolderChooserData *userdata)
+{
+ userdata->store = folder;
+ gtk_dialog_response (GTK_DIALOG (userdata->dialog), GTK_RESPONSE_OK);
+}
+
+static TnyFolderStore *
+folder_chooser_dialog_run (ModestFolderView *original)
+{
+ GtkWidget *folder_view;
+ FolderChooserData userdata = {NULL, NULL};
+ GtkWidget *pannable;
+ const gchar *visible_id = NULL;
+
+ userdata.dialog = hildon_dialog_new ();
+ pannable = hildon_pannable_area_new ();
+ folder_view = modest_platform_create_folder_view (NULL);
+ modest_folder_view_set_filter (MODEST_FOLDER_VIEW (folder_view),
+ MODEST_FOLDER_VIEW_FILTER_CAN_HAVE_FOLDERS);
+
+ modest_folder_view_copy_model (MODEST_FOLDER_VIEW (original),
+ MODEST_FOLDER_VIEW (folder_view));
+
+ visible_id =
+ modest_folder_view_get_account_id_of_visible_server_account (MODEST_FOLDER_VIEW(original));
+ modest_folder_view_set_account_id_of_visible_server_account (MODEST_FOLDER_VIEW(folder_view),
+ visible_id);
+
+ gtk_container_add (GTK_CONTAINER (GTK_DIALOG (userdata.dialog)->vbox), pannable);
+ gtk_container_add (GTK_CONTAINER (pannable), folder_view);
+ gtk_widget_set_size_request (pannable, -1, 320);
+
+ gtk_widget_show (folder_view);
+ gtk_widget_show (pannable);
+ gtk_widget_show (userdata.dialog);
+ g_signal_connect (G_OBJECT (folder_view), "folder-activated",
+ G_CALLBACK (folder_chooser_activated),
+ (gpointer) &userdata);
+
+ gtk_dialog_run (GTK_DIALOG (userdata.dialog));
+ gtk_widget_destroy (userdata.dialog);
+
+ return userdata.store;
+}
+
+static gchar *
+folder_store_get_display_name (TnyFolderStore *store)
+{
+ if (TNY_IS_ACCOUNT (store)) {
+ return g_strdup (tny_account_get_name (TNY_ACCOUNT (store)));
+ } else {
+ gchar *fname;
+ TnyFolderType type = TNY_FOLDER_TYPE_UNKNOWN;
+
+ fname = g_strdup (tny_folder_get_name (TNY_FOLDER (store)));
+ type = tny_folder_get_folder_type (TNY_FOLDER (store));
+ if (modest_tny_folder_is_local_folder (TNY_FOLDER (store)) ||
+ modest_tny_folder_is_memory_card_folder (TNY_FOLDER (store))) {
+ type = modest_tny_folder_get_local_or_mmc_folder_type (TNY_FOLDER (store));
+ if (type != TNY_FOLDER_TYPE_UNKNOWN) {
+ g_free (fname);
+ fname = g_strdup (modest_local_folder_info_get_type_display_name (type));
+ }
+ } else {
+ /* Sometimes an special folder is reported by the server as
+ NORMAL, like some versions of Dovecot */
+ if (type == TNY_FOLDER_TYPE_NORMAL ||
+ type == TNY_FOLDER_TYPE_UNKNOWN) {
+ type = modest_tny_folder_guess_folder_type (TNY_FOLDER (store));
+ }
+ }
+
+ if (type == TNY_FOLDER_TYPE_INBOX) {
+ g_free (fname);
+ fname = g_strdup (_("mcen_me_folder_inbox"));
+ }
+ return fname;
+ }
+}
+
+static void
+folder_picker_set_store (GtkButton *button, TnyFolderStore *store)
+{
+ gchar *name;
+
+ if (store == NULL) {
+ g_object_set_data (G_OBJECT (button), FOLDER_PICKER_CURRENT_FOLDER, NULL);
+ } else {
+ GdkPixbuf *pixbuf;
+ const gchar *icon_name = NULL;
+
+ g_object_ref (store);
+ g_object_set_data_full (G_OBJECT (button), FOLDER_PICKER_CURRENT_FOLDER,
+ store, (GDestroyNotify) g_object_unref);
+ name = folder_store_get_display_name (store);
+ hildon_button_set_value (HILDON_BUTTON (button), name);
+ g_free (name);
+
+ /* Select icon */
+ if (TNY_IS_ACCOUNT (store)) {
+ if (modest_tny_account_is_virtual_local_folders (TNY_ACCOUNT (store)))
+ icon_name = MODEST_FOLDER_ICON_LOCAL_FOLDERS;
+ else if (modest_tny_account_is_memory_card_account (TNY_ACCOUNT (store)))
+ icon_name = MODEST_FOLDER_ICON_MMC;
+ else
+ icon_name = MODEST_FOLDER_ICON_ACCOUNT;
+ } else {
+ if (modest_tny_folder_is_remote_folder (TNY_FOLDER (store))) {
+ TnyFolderType type = modest_tny_folder_guess_folder_type (TNY_FOLDER (store));
+ switch (type) {
+ case TNY_FOLDER_TYPE_INBOX:
+ icon_name = MODEST_FOLDER_ICON_INBOX;
+ break;
+ default:
+ icon_name = MODEST_FOLDER_ICON_ACCOUNT;
+ }
+ } else if (modest_tny_folder_is_local_folder (TNY_FOLDER (store)))
+ icon_name = MODEST_FOLDER_ICON_NORMAL;
+ else if (modest_tny_folder_is_memory_card_folder (TNY_FOLDER (store)))
+ icon_name = MODEST_FOLDER_ICON_MMC_FOLDER;
+ }
+
+ /* Set icon */
+ pixbuf = modest_platform_get_icon (icon_name, MODEST_ICON_SIZE_SMALL);
+
+ if (pixbuf) {
+ hildon_button_set_image (HILDON_BUTTON (button),
+ gtk_image_new_from_pixbuf (pixbuf));
+ g_object_unref (pixbuf);
+ }
+ }