X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fmodest-ui-actions.c;h=736eeb01ac4451a6fe621b26c247750585b19aae;hp=a7529153725274852e7ebf9b44f9c77f95a11f49;hb=85ea9236bffbc0205a4b6c1a7afa1ad440a47212;hpb=837a00595080e7b3d8bf137b8afd468acf33ecd5 diff --git a/src/modest-ui-actions.c b/src/modest-ui-actions.c index a752915..736eeb0 100644 --- a/src/modest-ui-actions.c +++ b/src/modest-ui-actions.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -54,6 +55,7 @@ #include #include #include +#include #endif #ifdef MODEST_PLATFORM_MAEMO @@ -177,10 +179,12 @@ static void modest_ui_actions_on_main_window_move_to (GtkAction *action, GtkWidget *folder_view, TnyFolderStore *dst_folder, ModestMainWindow *win); +#ifdef MODEST_TOOLKIT_HILDON2 static void modest_ui_actions_on_folder_window_move_to (GtkWidget *folder_view, TnyFolderStore *dst_folder, TnyList *selection, GtkWindow *win); +#endif static void modest_ui_actions_on_window_move_to (GtkAction *action, TnyList *list_to_move, @@ -221,14 +225,47 @@ modest_ui_actions_run_account_setup_wizard (ModestWindow *win) wizard = GTK_WINDOW (modest_platform_get_account_settings_wizard ()); modest_window_mgr_set_modal (modest_runtime_get_window_mgr(), GTK_WINDOW (wizard), (GtkWindow *) win); +#ifndef MODEST_TOOLKIT_HILDON2 /* always present a main window in the background * we do it here, so we cannot end up with two wizards (as this * function might be called in modest_window_mgr_get_main_window as well */ - if (!win) + if (!win) win = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr(), TRUE); /* create if not existent */ +#else + if (!win) { + GList *window_list; + ModestWindowMgr *mgr; + + mgr = modest_runtime_get_window_mgr (); - gtk_window_set_transient_for (GTK_WINDOW (wizard), GTK_WINDOW (win)); + window_list = modest_window_mgr_get_window_list (mgr); + if (window_list == NULL) { + ModestWindow *old_win; + win = MODEST_WINDOW (modest_accounts_window_new ()); + if (modest_window_mgr_register_window (mgr, win, NULL)) { + gtk_widget_show_all (GTK_WIDGET (win)); + } else { + gtk_widget_destroy (GTK_WIDGET (win)); + win = NULL; + } + + old_win = win; + win = MODEST_WINDOW (modest_folder_window_new (NULL)); + if (modest_window_mgr_register_window (mgr, win, NULL)) { + gtk_widget_show_all (GTK_WIDGET (win)); + } else { + gtk_widget_destroy (GTK_WIDGET (win)); + win = old_win; + } + } else { + g_list_free (window_list); + } + } +#endif + + if (win) + gtk_window_set_transient_for (GTK_WINDOW (wizard), GTK_WINDOW (win)); /* make sure the mainwindow is visible. We need to present the wizard again to give it the focus back. show_all are needed @@ -872,21 +909,37 @@ modest_ui_actions_msg_retrieval_check (ModestMailOperation *mail_op, error->code == MODEST_MAIL_OPERATION_ERROR_LOW_MEMORY) { GObject *source = modest_mail_operation_get_source (mail_op); modest_platform_run_information_dialog (GTK_IS_WINDOW (source) ? GTK_WINDOW (source) : NULL, - dgettext("ke-recv","memr_ib_operation_disabled"), + _KR("memr_ib_operation_disabled"), TRUE); g_object_unref (source); } if (error && ((error->code == TNY_SERVICE_ERROR_NO_SUCH_MESSAGE) || error->code == TNY_SERVICE_ERROR_MESSAGE_NOT_AVAILABLE)) { - gchar *subject, *msg; + gchar *subject, *msg, *format = NULL; + TnyAccount *account; subject = tny_header_dup_subject (header); if (!subject) - subject = g_strdup (_("mail_va_no_subject"));; - msg = g_strdup_printf (_("emev_ni_ui_imap_message_not_available_in_server"), - subject); + subject = g_strdup (_("mail_va_no_subject")); + + account = modest_mail_operation_get_account (mail_op); + if (account) { + ModestProtocol *protocol; + ModestProtocolType proto; + proto = modest_tny_account_get_protocol_type (account); + protocol = modest_protocol_registry_get_protocol_by_type (modest_runtime_get_protocol_registry (), proto); + if (protocol) + format = modest_protocol_get_translation (protocol, MODEST_PROTOCOL_TRANSLATION_MSG_NOT_AVAILABLE, subject); + g_object_unref (account); + } + + if (!format) + format = g_strdup (_("emev_ni_ui_imap_message_not_available_in_server")); + + msg = g_strdup_printf (format, subject); modest_platform_run_information_dialog (NULL, msg, FALSE); g_free (msg); + g_free (format); g_free (subject); } @@ -921,13 +974,12 @@ open_msg_banner_idle (gpointer userdata) gdk_threads_enter (); banner_info->idle_handler = 0; banner_info->banner = modest_platform_animation_banner (NULL, NULL, banner_info->message); - if (banner_info) + if (banner_info->banner) g_object_ref (banner_info->banner); - + gdk_threads_leave (); return FALSE; - } static GtkWidget * @@ -950,13 +1002,14 @@ get_header_view_from_window (ModestWindow *window) } static gchar * -get_info_from_header (TnyHeader *header, gboolean *is_draft) +get_info_from_header (TnyHeader *header, gboolean *is_draft, gboolean *can_open) { TnyFolder *folder; gchar *account = NULL; TnyFolderType folder_type = TNY_FOLDER_TYPE_UNKNOWN; *is_draft = FALSE; + *can_open = TRUE; folder = tny_header_get_folder (header); /* Gets folder type (OUTBOX headers will be opened in edit window */ @@ -965,7 +1018,7 @@ get_info_from_header (TnyHeader *header, gboolean *is_draft) if (folder_type == TNY_FOLDER_TYPE_INVALID) g_warning ("%s: BUG: TNY_FOLDER_TYPE_INVALID", __FUNCTION__); } - + if (folder_type == TNY_FOLDER_TYPE_OUTBOX) { TnyTransportAccount *traccount = NULL; ModestTnyAccountStore *accstore = modest_runtime_get_account_store(); @@ -991,7 +1044,7 @@ get_info_from_header (TnyHeader *header, gboolean *is_draft) open any message from outbox which is not in failed state */ - g_object_unref(traccount); + *can_open = FALSE; } #endif } @@ -1003,6 +1056,15 @@ get_info_from_header (TnyHeader *header, gboolean *is_draft) *is_draft = TRUE; /* Open in editor if the message is in the Drafts folder */ } + if (!account) { + TnyAccount *acc = tny_folder_get_account (folder); + if (acc) { + account = + g_strdup (modest_tny_account_get_parent_modest_account_name_for_server_account (acc)); + g_object_unref (acc); + } + } + g_object_unref (folder); return account; @@ -1021,8 +1083,9 @@ open_msg_cb (ModestMailOperation *mail_op, ModestWindow *win = NULL; gchar *account = NULL; gboolean open_in_editor = FALSE; + gboolean can_open; OpenMsgHelper *helper = (OpenMsgHelper *) user_data; - + /* Do nothing if there was any problem with the mail operation. The error will be shown by the error_handler of the mail operation */ @@ -1034,14 +1097,14 @@ open_msg_cb (ModestMailOperation *mail_op, /* Mark header as read */ headers_action_mark_as_read (header, MODEST_WINDOW(parent_win), NULL); - account = get_info_from_header (header, &open_in_editor); + account = get_info_from_header (header, &open_in_editor, &can_open); /* Get account */ if (!account) account = g_strdup (modest_window_get_active_account (MODEST_WINDOW (parent_win))); if (!account) account = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr()); - + if (open_in_editor) { ModestAccountMgr *mgr = modest_runtime_get_account_mgr (); gchar *from_header = NULL, *acc_name; @@ -1069,7 +1132,7 @@ open_msg_cb (ModestMailOperation *mail_op, } else { gchar *uid = modest_tny_folder_get_header_unique_id (header); - if (helper->rowref && helper->model) { + if (helper->rowref && helper->model) { win = modest_msg_view_window_new_with_header_model (msg, account, (const gchar*) uid, helper->model, helper->rowref); } else { @@ -1077,7 +1140,7 @@ open_msg_cb (ModestMailOperation *mail_op, } g_free (uid); } - + /* Register and show new window */ if (win != NULL) { mgr = modest_runtime_get_window_mgr (); @@ -1100,20 +1163,39 @@ cleanup: } static gboolean -is_memory_full_error (GError *error) +is_memory_full_error (GError *error, ModestMailOperation *mail_op) { gboolean enough_free_space = TRUE; GnomeVFSURI *cache_dir_uri; - const gchar *cache_dir; + const gchar *cache_dir = NULL; GnomeVFSFileSize free_space; + TnyAccountStore *acc_store; + + acc_store = TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()); + + /* Cache dir is different in case we're using an external storage (like MMC account) */ + if (mail_op) { + TnyAccount *account = modest_mail_operation_get_account (mail_op); + if (account) { + if (modest_tny_account_is_memory_card_account (account)) { + cache_dir = g_getenv (MODEST_MMC1_VOLUMEPATH_ENV); + } + g_object_unref (account); + } + } + + /* Get the default local cache dir */ + if (!cache_dir) + cache_dir = tny_account_store_get_cache_dir (acc_store); - cache_dir = tny_account_store_get_cache_dir (TNY_ACCOUNT_STORE (modest_runtime_get_account_store ())); cache_dir_uri = gnome_vfs_uri_new (cache_dir); - if (gnome_vfs_get_volume_free_space (cache_dir_uri, &free_space) == GNOME_VFS_OK) { - if (free_space < MIN_FREE_SPACE) - enough_free_space = FALSE; + if (cache_dir_uri) { + if (gnome_vfs_get_volume_free_space (cache_dir_uri, &free_space) == GNOME_VFS_OK) { + if (free_space < MIN_FREE_SPACE) + enough_free_space = FALSE; + } + gnome_vfs_uri_unref (cache_dir_uri); } - gnome_vfs_uri_unref (cache_dir_uri); if ((error->code == TNY_SYSTEM_ERROR_MEMORY || /* When asking for a mail and no space left on device @@ -1136,14 +1218,13 @@ check_memory_full_error (GtkWidget *parent_window, GError *err) if (err == NULL) return FALSE; - if (is_memory_full_error (err)) + if (is_memory_full_error (err, NULL)) modest_platform_information_banner (parent_window, - NULL, dgettext("ke-recv", - "cerm_device_memory_full")); + NULL, _KR("cerm_device_memory_full")); else if (err->code == TNY_SYSTEM_ERROR_MEMORY) /* If the account was created in memory full conditions then tinymail won't be able to - connect so it'll return this error code */ + connect so it'll return this error code */ modest_platform_information_banner (parent_window, NULL, _("emev_ui_imap_inbox_select_error")); else @@ -1167,17 +1248,16 @@ modest_ui_actions_disk_operations_error_handler (ModestMailOperation *mail_op, /* If the mail op has been cancelled then it's not an error: don't show any message */ if (status != MODEST_MAIL_OPERATION_STATUS_CANCELED) { - if (is_memory_full_error ((GError *) error)) { + if (is_memory_full_error ((GError *) error, mail_op)) { modest_platform_information_banner ((GtkWidget *) win, - NULL, dgettext("ke-recv", - "cerm_device_memory_full")); + NULL, _KR("cerm_device_memory_full")); } else if (error->code == TNY_SYSTEM_ERROR_MEMORY) { modest_platform_information_banner ((GtkWidget *) win, NULL, _("emev_ui_imap_inbox_select_error")); } else if (error->domain == MODEST_MAIL_OPERATION_ERROR && error->code == MODEST_MAIL_OPERATION_ERROR_FILE_IO) { modest_platform_information_banner ((GtkWidget *) win, - NULL, dgettext ("hildon-common-strings", "sfil_ni_unable_to_open_file_not_found")); + NULL, _CS ("sfil_ni_unable_to_open_file_not_found")); } else if (user_data) { modest_platform_information_banner ((GtkWidget *) win, NULL, user_data); @@ -1241,7 +1321,6 @@ get_account_from_header (TnyHeader *header) account = tny_folder_get_account (folder); g_object_unref (folder); } - return account; } @@ -1278,11 +1357,13 @@ open_msg_performer(gboolean canceled, gpointer user_data) { ModestMailOperation *mail_op = NULL; - gchar *error_msg; + gchar *error_msg = NULL; ModestProtocolType proto; TnyConnectionStatus status; - gboolean show_open_draft = FALSE; OpenMsgHelper *helper = NULL; + ModestProtocol *protocol; + ModestProtocolRegistry *protocol_registry; + gchar *subject; helper = (OpenMsgHelper *) user_data; @@ -1291,10 +1372,10 @@ open_msg_performer(gboolean canceled, modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (), helper->header); /* Free the helper */ open_msg_helper_destroyer (helper); - + /* In memory full conditions we could get this error here */ check_memory_full_error ((GtkWidget *) parent_window, err); - + goto clean; } @@ -1303,11 +1384,7 @@ open_msg_performer(gboolean canceled, if (proto == MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) { proto = MODEST_PROTOCOLS_STORE_MAILDIR; } - - ModestProtocol *protocol; - ModestProtocolRegistry *protocol_registry; - gchar *subject; - + protocol_registry = modest_runtime_get_protocol_registry (); subject = tny_header_dup_subject (helper->header); @@ -1315,11 +1392,13 @@ open_msg_performer(gboolean canceled, error_msg = modest_protocol_get_translation (protocol, MODEST_PROTOCOL_TRANSLATION_MSG_NOT_AVAILABLE, subject); if (subject) g_free (subject); - + if (error_msg == NULL) { error_msg = g_strdup (_("mail_ni_ui_folder_get_msg_folder_error")); } +#ifndef MODEST_TOOLKIT_HILDON2 + gboolean show_open_draft = FALSE; if (modest_protocol_registry_protocol_type_has_tag (protocol_registry, proto, MODEST_PROTOCOL_REGISTRY_LOCAL_STORE_PROTOCOLS)) { @@ -1331,10 +1410,19 @@ open_msg_performer(gboolean canceled, show_open_draft = (folder_type == TNY_FOLDER_TYPE_DRAFTS); g_object_unref (folder); } +#endif #ifdef MODEST_TOOLKIT_HILDON2 gboolean is_draft; - gchar *account_name = get_info_from_header (helper->header, &is_draft); + gboolean can_open; + gchar *account_name = get_info_from_header (helper->header, &is_draft, &can_open); + + if (!can_open) { + modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (), helper->header); + g_free (account_name); + open_msg_helper_destroyer (helper); + goto clean; + } if (!is_draft) { ModestWindow *window; @@ -1366,21 +1454,21 @@ open_msg_performer(gboolean canceled, mail_op = modest_mail_operation_new_with_error_handling ((GObject *) parent_window, modest_ui_actions_disk_operations_error_handler, - error_msg, g_free); + g_strdup (error_msg), g_free); modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op); + +#ifndef MODEST_TOOLKIT_HILDON2 if (show_open_draft) { helper->banner_info = g_slice_new (OpenMsgBannerInfo); -#ifdef MODEST_TOOLKIT_HILDON2 - helper->banner_info->message = g_strdup (_("mail_me_opening")); -#else helper->banner_info->message = g_strdup (_("mail_ib_opening_draft_message")); -#endif helper->banner_info->banner = NULL; helper->banner_info->idle_handler = g_timeout_add (500, open_msg_banner_idle, helper->banner_info); } +#endif + TnyList *headers; headers = TNY_LIST (tny_simple_list_new ()); @@ -1394,6 +1482,8 @@ open_msg_performer(gboolean canceled, /* Frees */ clean: + if (error_msg) + g_free (error_msg); if (mail_op) g_object_unref (mail_op); g_object_unref (account); @@ -1414,7 +1504,7 @@ open_msg_from_header (TnyHeader *header, GtkTreeRowReference *rowref, ModestWind GtkWidget *header_view = NULL; OpenMsgHelper *helper; ModestWindow *window; - + g_return_if_fail (header != NULL && rowref != NULL); mgr = modest_runtime_get_window_mgr (); @@ -1431,7 +1521,7 @@ open_msg_from_header (TnyHeader *header, GtkTreeRowReference *rowref, ModestWind window = NULL; found = modest_window_mgr_find_registered_header (mgr, header, &window); - + /* Do not open again the message and present the window to the user */ if (found) { @@ -1999,12 +2089,12 @@ modest_ui_actions_on_sort (GtkAction *action, if (!header_view) { modest_platform_information_banner (NULL, NULL, _CS("ckdg_ib_nothing_to_sort")); - + return; } /* Show sorting dialog */ - modest_utils_run_sort_dialog (GTK_WINDOW (window), MODEST_SORT_HEADERS); + modest_utils_run_sort_dialog (GTK_WINDOW (window), MODEST_SORT_HEADERS); } static void @@ -2472,7 +2562,7 @@ folder_refreshed_cb (ModestMailOperation *mail_op, if (error && error->domain == MODEST_MAIL_OPERATION_ERROR && error->code == MODEST_MAIL_OPERATION_ERROR_LOW_MEMORY) { modest_platform_run_information_dialog (GTK_WINDOW (win), - dgettext("ke-recv","memr_ib_operation_disabled"), + _KR("memr_ib_operation_disabled"), TRUE); return; } @@ -2731,8 +2821,7 @@ enough_space_for_message (ModestMsgEditWindow *edit_window, expected_size > available_disk) { modest_platform_information_banner (NULL, NULL, - dgettext("ke-recv", - "cerm_device_memory_full")); + _KR("cerm_device_memory_full")); return FALSE; } @@ -2755,7 +2844,7 @@ enough_space_for_message (ModestMsgEditWindow *edit_window, if (expected_size > MODEST_MAX_ATTACHMENT_SIZE) { modest_platform_run_information_dialog ( GTK_WINDOW(edit_window), - dgettext("ke-recv","memr_ib_operation_disabled"), + _KR("memr_ib_operation_disabled"), TRUE); return FALSE; } @@ -3124,11 +3213,10 @@ modest_ui_actions_on_select_editor_background_color (GtkAction *action, } void -modest_ui_actions_on_insert_image (GtkAction *action, +modest_ui_actions_on_insert_image (GObject *object, ModestMsgEditWindow *window) { g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window)); - g_return_if_fail (GTK_IS_ACTION (action)); if (modest_platform_check_memory_low (MODEST_WINDOW(window), TRUE)) @@ -3162,38 +3250,6 @@ modest_ui_actions_on_remove_attachments (GtkAction *action, modest_msg_edit_window_remove_attachments (window, NULL); } - -#ifndef MODEST_TOOLKIT_GTK -typedef struct { - guint handler; - gchar *name; - GtkWindow *win; - TnyFolderStore *folder; -} CreateFolderHelper; - -static gboolean -show_create_folder_in_timeout (gpointer data) -{ - CreateFolderHelper *helper = (CreateFolderHelper *) data; - - /* Remove the timeout ASAP, we can not wait until the dialog - is shown because it could take a lot of time and so the - timeout could be called twice or more times */ - g_source_remove (helper->handler); - - gdk_threads_enter (); - do_create_folder (helper->win, helper->folder, helper->name); - gdk_threads_leave (); - - g_object_unref (helper->win); - g_object_unref (helper->folder); - g_free (helper->name); - g_slice_free (CreateFolderHelper, helper); - - return FALSE; -} -#endif - static void do_create_folder_cb (ModestMailOperation *mail_op, TnyFolderStore *parent_folder, @@ -3202,8 +3258,10 @@ do_create_folder_cb (ModestMailOperation *mail_op, { gchar *suggested_name = (gchar *) user_data; GtkWindow *source_win = (GtkWindow *) modest_mail_operation_get_source (mail_op); + const GError *error; - if (modest_mail_operation_get_error (mail_op)) { + error = modest_mail_operation_get_error (mail_op); + if (error) { /* Show an error. If there was some problem writing to disk, show it, otherwise show the generic folder @@ -3215,24 +3273,10 @@ do_create_folder_cb (ModestMailOperation *mail_op, modest_ui_actions_disk_operations_error_handler (mail_op, _("mail_in_ui_folder_create_error")); - /* Try again. Do *NOT* show any error because the mail - operations system will do it for us because we - created the mail_op with new_with_error_handler */ -#ifndef MODEST_TOOLKIT_GTK - CreateFolderHelper *helper; - helper = g_slice_new0 (CreateFolderHelper); - helper->name = g_strdup (suggested_name); - helper->folder = g_object_ref (parent_folder); - helper->win = g_object_ref (source_win); - - /* Ugly but neccesary stuff. The problem is that the - dialog when is shown calls a function that destroys - all the temporary windows, so the banner is - destroyed */ - helper->handler = g_timeout_add (2000, show_create_folder_in_timeout, helper); -#else - do_create_folder (source_win, parent_folder, (const gchar *) suggested_name); -#endif + if (!is_memory_full_error ((GError *) error, mail_op)) { + /* Try again if there is no full memory condition */ + do_create_folder (source_win, parent_folder, (const gchar *) suggested_name); + } } else { /* the 'source_win' is either the ModestMainWindow, or the 'Move to folder'-dialog * FIXME: any other? */ @@ -3259,6 +3303,46 @@ do_create_folder_cb (ModestMailOperation *mail_op, g_object_unref (source_win); } +typedef struct { + gchar *folder_name; + TnyFolderStore *parent; +} CreateFolderConnect; + +static void +do_create_folder_performer (gboolean canceled, + GError *err, + GtkWindow *parent_window, + TnyAccount *account, + gpointer user_data) +{ + CreateFolderConnect *helper = (CreateFolderConnect *) user_data; + ModestMailOperation *mail_op; + + if (canceled || err) { + /* In memory full conditions we could get this error here */ + check_memory_full_error ((GtkWidget *) parent_window, err); + goto frees; + } + + mail_op = modest_mail_operation_new ((GObject *) parent_window); + modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), + mail_op); + modest_mail_operation_create_folder (mail_op, + helper->parent, + (const gchar *) helper->folder_name, + do_create_folder_cb, + g_strdup (helper->folder_name)); + g_object_unref (mail_op); + + frees: + if (helper->parent) + g_object_unref (helper->parent); + if (helper->folder_name) + g_free (helper->folder_name); + g_slice_free (CreateFolderConnect, helper); +} + + static void do_create_folder (GtkWindow *parent_window, TnyFolderStore *suggested_parent, @@ -3266,50 +3350,30 @@ do_create_folder (GtkWindow *parent_window, { gint result; gchar *folder_name = NULL; - TnyFolderStore *parent_folder; + TnyFolderStore *parent_folder = NULL; result = modest_platform_run_new_folder_dialog (GTK_WINDOW (parent_window), suggested_parent, (gchar *) suggested_name, &folder_name, &parent_folder); - - if (result == GTK_RESPONSE_ACCEPT && parent_folder) { - ModestMailOperation *mail_op; - - mail_op = modest_mail_operation_new ((GObject *) parent_window); - modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), - mail_op); - modest_mail_operation_create_folder (mail_op, - parent_folder, - (const gchar *) folder_name, - do_create_folder_cb, - folder_name); - g_object_unref (mail_op); - } - g_object_unref (parent_folder); -} -static void -create_folder_performer (gboolean canceled, - GError *err, - GtkWindow *parent_window, - TnyAccount *account, - gpointer user_data) -{ - TnyFolderStore *parent_folder = TNY_FOLDER_STORE (user_data); + if (result == GTK_RESPONSE_ACCEPT && parent_folder) { + CreateFolderConnect *helper = (CreateFolderConnect *) g_slice_new0 (CreateFolderConnect); + helper->folder_name = g_strdup (folder_name); + helper->parent = g_object_ref (parent_folder); - if (canceled || err) { - /* In memory full conditions we could get this error here */ - check_memory_full_error ((GtkWidget *) parent_window, err); - goto frees; + modest_platform_connect_if_remote_and_perform (GTK_WINDOW (parent_window), + TRUE, + parent_folder, + do_create_folder_performer, + helper); } - /* Run the new folder dialog */ - do_create_folder (GTK_WINDOW (parent_window), parent_folder, NULL); - - frees: - g_object_unref (parent_folder); + if (folder_name) + g_free (folder_name); + if (parent_folder) + g_object_unref (parent_folder); } static void @@ -3319,26 +3383,19 @@ modest_ui_actions_create_folder(GtkWidget *parent_window, TnyFolderStore *parent_folder; #ifdef MODEST_TOOLKIT_HILDON2 - const gchar *active_account; - TnyAccount *account; + ModestTnyAccountStore *acc_store; - /* In hildon 2.2 we use the current account as default parent */ - active_account = modest_window_get_active_account (MODEST_WINDOW (parent_window)); - account = modest_tny_account_store_get_server_account (modest_runtime_get_account_store (), - active_account, - TNY_ACCOUNT_TYPE_STORE); - parent_folder = TNY_FOLDER_STORE (account); + acc_store = modest_runtime_get_account_store (); + + parent_folder = (TnyFolderStore *) + modest_tny_account_store_get_local_folders_account (acc_store); #else parent_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view)); #endif if (parent_folder) { - /* The parent folder will be freed in the callback */ - modest_platform_connect_if_remote_and_perform (GTK_WINDOW (parent_window), - TRUE, - parent_folder, - create_folder_performer, - parent_folder); + do_create_folder (GTK_WINDOW (parent_window), parent_folder, NULL); + g_object_unref (parent_folder); } } @@ -3390,7 +3447,7 @@ modest_ui_actions_rename_folder_error_handler (ModestMailOperation *mail_op, message is opened for example */ message = _("emev_ni_internal_error"); } else { - message = _("emev_ib_ui_imap_unable_to_rename"); + message = _CS("ckdg_ib_unable_to_rename"); } /* We don't set a parent for the dialog because the dialog @@ -3422,7 +3479,7 @@ on_rename_folder_cb (ModestMailOperation *mail_op, } else { modest_folder_view_select_first_inbox_or_local (folder_view); } - gtk_widget_grab_focus (GTK_WIDGET (folder_view)); + gtk_widget_grab_focus (GTK_WIDGET (folder_view)); } static void @@ -3442,7 +3499,7 @@ on_rename_folder_performer (gboolean canceled, check_memory_full_error ((GtkWidget *) parent_window, err); } else { - mail_op = + mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT(parent_window), modest_ui_actions_rename_folder_error_handler, parent_window, NULL); @@ -3455,13 +3512,17 @@ on_rename_folder_performer (gboolean canceled, folder_view = modest_main_window_get_child_widget ( MODEST_MAIN_WINDOW (parent_window), MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW); - - /* Clear the headers view */ - sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_view)); - gtk_tree_selection_unselect_all (sel); - } else { - folder_view = NULL; + } +#ifdef MODEST_TOOLKIT_HILDON2 + else if (MODEST_IS_FOLDER_WINDOW (parent_window)) { + ModestFolderWindow *folder_window = (ModestFolderWindow *) parent_window; + folder_view = GTK_WIDGET (modest_folder_window_get_folder_view (folder_window)); } +#endif + + /* Clear the folders view */ + sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_view)); + gtk_tree_selection_unselect_all (sel); /* Actually rename the folder */ modest_mail_operation_rename_folder (mail_op, @@ -3469,10 +3530,10 @@ on_rename_folder_performer (gboolean canceled, (const gchar *) (data->new_name), on_rename_folder_cb, folder_view); - g_object_unref (data->folder); g_object_unref (mail_op); } + g_object_unref (data->folder); g_free (data->new_name); g_free (data); } @@ -3635,6 +3696,9 @@ delete_folder (ModestWindow *window, gboolean move_to_trash) folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view)); + if (!folder) + return FALSE; + /* Show an error if it's an account */ if (!TNY_IS_FOLDER (folder)) { modest_platform_run_information_dialog (GTK_WINDOW (window), @@ -3644,7 +3708,7 @@ delete_folder (ModestWindow *window, gboolean move_to_trash) return FALSE; } - /* Ask the user */ + /* Ask the user */ message = g_strdup_printf (_("mcen_nc_delete_folder_text"), tny_folder_get_name (TNY_FOLDER (folder))); response = modest_platform_run_confirmation_dialog (GTK_WINDOW (window), @@ -3707,11 +3771,19 @@ password_dialog_check_field (GtkEditable *editable, const gchar *value; gboolean any_value_empty = FALSE; +#ifdef MODEST_TOOLKIT_HILDON2 + value = hildon_entry_get_text (HILDON_ENTRY (fields->username)); +#else value = gtk_entry_get_text (GTK_ENTRY (fields->username)); +#endif if ((value == NULL) || value[0] == '\0') { any_value_empty = TRUE; } +#ifdef MODEST_TOOLKIT_HILDON2 + value = hildon_entry_get_text (HILDON_ENTRY (fields->password)); +#else value = gtk_entry_get_text (GTK_ENTRY (fields->password)); +#endif if ((value == NULL) || value[0] == '\0') { any_value_empty = TRUE; } @@ -3750,6 +3822,8 @@ modest_ui_actions_on_password_requested (TnyAccountStore *account_store, _HL("wdgt_bd_done"), GTK_RESPONSE_ACCEPT, NULL); + gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), + HILDON_MARGIN_DOUBLE); #else GtkWidget *dialog = gtk_dialog_new_with_buttons (_("mail_ti_password_protected"), @@ -3786,19 +3860,27 @@ modest_ui_actions_on_password_requested (TnyAccountStore *account_store, } gchar *txt = g_strdup_printf (_("mail_ia_password_info"), server_name); - gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), gtk_label_new(txt), - FALSE, FALSE, 0); + GtkWidget *label = gtk_label_new (txt); + gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); g_free (txt); g_free (server_name); + gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), label, + FALSE, FALSE, 0); server_name = NULL; /* username: */ gchar *initial_username = modest_account_mgr_get_server_account_username ( modest_runtime_get_account_mgr(), server_account_name); +#ifdef MODEST_TOOLKIT_HILDON2 + GtkWidget *entry_username = hildon_entry_new (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH); + if (initial_username) + hildon_entry_set_text (HILDON_ENTRY (entry_username), initial_username); +#else GtkWidget *entry_username = gtk_entry_new (); if (initial_username) gtk_entry_set_text (GTK_ENTRY (entry_username), initial_username); +#endif /* Dim this if a connection has ever succeeded with this username, * as per the UI spec: */ /* const gboolean username_known = */ @@ -3820,8 +3902,14 @@ modest_ui_actions_on_password_requested (TnyAccountStore *account_store, * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */ GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); +#ifdef MODEST_TOOLKIT_HILDON2 + GtkWidget *caption = modest_maemo_utils_create_captioned (sizegroup, NULL, + _("mail_fi_username"), FALSE, + entry_username); +#else GtkWidget *caption = hildon_caption_new (sizegroup, _("mail_fi_username"), entry_username, NULL, HILDON_CAPTION_MANDATORY); +#endif gtk_widget_show (entry_username); gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption, FALSE, FALSE, MODEST_MARGIN_HALF); @@ -3832,7 +3920,11 @@ modest_ui_actions_on_password_requested (TnyAccountStore *account_store, #endif /* !MODEST_TOOLKIT_GTK */ /* password: */ +#ifdef MODEST_TOOLKIT_HILDON2 + GtkWidget *entry_password = hildon_entry_new (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH); +#else GtkWidget *entry_password = gtk_entry_new (); +#endif gtk_entry_set_visibility (GTK_ENTRY(entry_password), FALSE); /* gtk_entry_set_invisible_char (GTK_ENTRY(entry_password), "*"); */ @@ -3841,8 +3933,14 @@ modest_ui_actions_on_password_requested (TnyAccountStore *account_store, hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_password), HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE); +#ifdef MODEST_TOOLKIT_HILDON2 + caption = modest_maemo_utils_create_captioned (sizegroup, NULL, + _("mail_fi_password"), FALSE, + entry_password); +#else caption = hildon_caption_new (sizegroup, _("mail_fi_password"), entry_password, NULL, HILDON_CAPTION_MANDATORY); +#endif gtk_widget_show (entry_password); gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption, FALSE, FALSE, MODEST_MARGIN_HALF); @@ -3877,7 +3975,11 @@ modest_ui_actions_on_password_requested (TnyAccountStore *account_store, if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) { if (username) { +#ifdef MODEST_TOOLKIT_HILDON2 + *username = g_strdup (hildon_entry_get_text (HILDON_ENTRY(entry_username))); +#else *username = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_username))); +#endif /* Note that an empty field becomes the "" string */ if (*username && strlen (*username) > 0) { @@ -3903,7 +4005,11 @@ modest_ui_actions_on_password_requested (TnyAccountStore *account_store, } if (password) { +#ifdef MODEST_TOOLKIT_HILDON2 + *password = g_strdup (hildon_entry_get_text (HILDON_ENTRY(entry_password))); +#else *password = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_password))); +#endif /* We do not save the password in the configuration, * because this function is only called for passwords that should @@ -4451,7 +4557,7 @@ modest_ui_actions_on_change_fullscreen (GtkAction *action, * Used by modest_ui_actions_on_details to call do_headers_action */ static void -headers_action_show_details (TnyHeader *header, +headers_action_show_details (TnyHeader *header, ModestWindow *window, gpointer user_data) @@ -4462,36 +4568,24 @@ headers_action_show_details (TnyHeader *header, /* * Show the header details in a ModestDetailsDialog widget */ -void -modest_ui_actions_on_details (GtkAction *action, +void +modest_ui_actions_on_details (GtkAction *action, ModestWindow *win) { - TnyList * headers_list; - TnyIterator *iter; - TnyHeader *header; - if (MODEST_IS_MSG_VIEW_WINDOW (win)) { TnyMsg *msg; + TnyHeader *header; msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW (win)); if (!msg) return; - g_object_unref (msg); - - headers_list = get_selected_headers (win); - if (!headers_list) - return; - iter = tny_list_create_iterator (headers_list); - - header = TNY_HEADER (tny_iterator_get_current (iter)); + header = tny_msg_get_header (msg); if (header) { headers_action_show_details (header, win, NULL); g_object_unref (header); } - - g_object_unref (iter); - g_object_unref (headers_list); + g_object_unref (msg); } else if (MODEST_IS_MAIN_WINDOW (win)) { GtkWidget *folder_view, *header_view; @@ -4785,41 +4879,58 @@ on_move_to_dialog_response (GtkDialog *dialog, gint response, gpointer user_data) { - GtkWidget *parent_win, *folder_view; + GtkWidget *parent_win; MoveToInfo *helper = NULL; + ModestFolderView *folder_view; helper = (MoveToInfo *) user_data; parent_win = (GtkWidget *) helper->win; - folder_view = GTK_WIDGET (g_object_get_data (G_OBJECT (dialog), - MODEST_MOVE_TO_DIALOG_FOLDER_VIEW)); + folder_view = MODEST_FOLDER_VIEW (g_object_get_data (G_OBJECT (dialog), + MODEST_MOVE_TO_DIALOG_FOLDER_VIEW)); switch (response) { TnyFolderStore *dst_folder; case MODEST_GTK_RESPONSE_NEW_FOLDER: - modest_ui_actions_create_folder (GTK_WIDGET (parent_win), folder_view); + modest_ui_actions_create_folder (GTK_WIDGET (dialog), GTK_WIDGET (folder_view)); return; case GTK_RESPONSE_NONE: case GTK_RESPONSE_CANCEL: case GTK_RESPONSE_DELETE_EVENT: break; case GTK_RESPONSE_OK: - dst_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view)); - /* Do window specific stuff */ + dst_folder = modest_folder_view_get_selected (folder_view); + if (MODEST_IS_MAIN_WINDOW (parent_win)) { + /* Clean list to move used for filtering */ + modest_folder_view_set_list_to_move (folder_view, NULL); + modest_ui_actions_on_main_window_move_to (NULL, - folder_view, + GTK_WIDGET (folder_view), dst_folder, MODEST_MAIN_WINDOW (parent_win)); #ifdef MODEST_TOOLKIT_HILDON2 } else if (MODEST_IS_FOLDER_WINDOW (parent_win)) { - modest_ui_actions_on_folder_window_move_to (folder_view, + /* Clean list to move used for filtering */ + modest_folder_view_set_list_to_move (folder_view, NULL); + + modest_ui_actions_on_folder_window_move_to (GTK_WIDGET (folder_view), dst_folder, helper->list, GTK_WINDOW (parent_win)); #endif } else { + /* if the user selected a root folder + (account) then do not perform any action */ + if (TNY_IS_ACCOUNT (dst_folder)) { + g_signal_stop_emission_by_name (dialog, "response"); + return; + } + + /* Clean list to move used for filtering */ + modest_folder_view_set_list_to_move (folder_view, NULL); + /* Moving from headers window in edit mode */ modest_ui_actions_on_window_move_to (NULL, helper->list, dst_folder, @@ -4835,14 +4946,16 @@ on_move_to_dialog_response (GtkDialog *dialog, } /* Free the helper and exit */ - g_object_unref (helper->list); + if (helper->list) + g_object_unref (helper->list); g_slice_free (MoveToInfo, helper); gtk_widget_destroy (GTK_WIDGET (dialog)); } static GtkWidget* create_move_to_dialog (GtkWindow *win, - GtkWidget *folder_view) + GtkWidget *folder_view, + TnyList *list_to_move) { GtkWidget *dialog, *tree_view = NULL; @@ -4911,6 +5024,8 @@ create_move_to_dialog (GtkWindow *win, /* Hide special folders */ modest_folder_view_show_non_move_folders (MODEST_FOLDER_VIEW (tree_view), FALSE); + if (list_to_move) + modest_folder_view_set_list_to_move (MODEST_FOLDER_VIEW (tree_view), list_to_move); #ifndef MODEST_TOOLKIT_HILDON2 modest_folder_view_select_first_inbox_or_local (MODEST_FOLDER_VIEW (tree_view)); #endif @@ -5003,40 +5118,42 @@ move_to_cb (ModestMailOperation *mail_op, gpointer user_data) { MoveToHelper *helper = (MoveToHelper *) user_data; + GObject *object = modest_mail_operation_get_source (mail_op); /* Note that the operation could have failed, in that case do nothing */ - if (modest_mail_operation_get_status (mail_op) == - MODEST_MAIL_OPERATION_STATUS_SUCCESS) { - - GObject *object = modest_mail_operation_get_source (mail_op); - if (MODEST_IS_MSG_VIEW_WINDOW (object)) { - ModestMsgViewWindow *self = MODEST_MSG_VIEW_WINDOW (object); + if (modest_mail_operation_get_status (mail_op) != + MODEST_MAIL_OPERATION_STATUS_SUCCESS) + goto frees; - if (!modest_msg_view_window_select_next_message (self) && - !modest_msg_view_window_select_previous_message (self)) { - /* No more messages to view, so close this window */ - modest_ui_actions_on_close_window (NULL, MODEST_WINDOW(self)); - } - } else if (MODEST_IS_MAIN_WINDOW (object) && - gtk_tree_row_reference_valid (helper->reference)) { - GtkWidget *header_view; - GtkTreePath *path; - GtkTreeSelection *sel; + if (MODEST_IS_MSG_VIEW_WINDOW (object)) { + ModestMsgViewWindow *self = MODEST_MSG_VIEW_WINDOW (object); - header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(object), - MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW); - sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view)); - path = gtk_tree_row_reference_get_path (helper->reference); - /* We need to unselect the previous one - because we could be copying instead of - moving */ - gtk_tree_selection_unselect_all (sel); - gtk_tree_selection_select_path (sel, path); - gtk_tree_path_free (path); + if (!modest_msg_view_window_select_next_message (self) && + !modest_msg_view_window_select_previous_message (self)) { + /* No more messages to view, so close this window */ + modest_ui_actions_on_close_window (NULL, MODEST_WINDOW(self)); } - g_object_unref (object); - } + } else if (MODEST_IS_MAIN_WINDOW (object) && + gtk_tree_row_reference_valid (helper->reference)) { + GtkWidget *header_view; + GtkTreePath *path; + GtkTreeSelection *sel; + + header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(object), + MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW); + sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view)); + path = gtk_tree_row_reference_get_path (helper->reference); + /* We need to unselect the previous one + because we could be copying instead of + moving */ + gtk_tree_selection_unselect_all (sel); + gtk_tree_selection_select_path (sel, path); + gtk_tree_path_free (path); + } + g_object_unref (object); + + frees: /* Destroy the helper */ move_to_helper_destroyer (helper); } @@ -5074,32 +5191,34 @@ void modest_ui_actions_move_folder_error_handler (ModestMailOperation *mail_op, gpointer user_data) { + GObject *win = NULL; + +#ifndef MODEST_TOOLKIT_HILDON2 ModestWindow *main_window = NULL; - + /* Disable next automatic folder selection */ main_window = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (), FALSE); /* don't create */ if (main_window) { - GObject *win = NULL; GtkWidget *folder_view = NULL; - + folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (main_window), MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW); modest_folder_view_disable_next_folder_selection (MODEST_FOLDER_VIEW(folder_view)); - + if (user_data && TNY_IS_FOLDER (user_data)) { modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view), TNY_FOLDER (user_data), FALSE); } - - /* Show notification dialog only if the main window exists */ - win = modest_mail_operation_get_source (mail_op); - modest_platform_run_information_dialog ((GtkWindow *) win, - _("mail_in_ui_folder_move_target_error"), - FALSE); - if (win) - g_object_unref (win); } +#endif + /* Show notification dialog only if the main window exists */ + win = modest_mail_operation_get_source (mail_op); + modest_platform_run_information_dialog ((GtkWindow *) win, + _("mail_in_ui_folder_move_target_error"), + FALSE); + if (win) + g_object_unref (win); } static void @@ -5249,7 +5368,7 @@ modest_ui_actions_on_main_window_remove_attachments (GtkAction *action, * Checks if we need a connection to do the transfer and if the user * wants to connect to complete it */ -void +static void modest_ui_actions_xfer_messages_check (GtkWindow *parent_window, TnyFolderStore *src_folder, TnyList *headers, @@ -5261,8 +5380,6 @@ modest_ui_actions_xfer_messages_check (GtkWindow *parent_window, TnyAccount *src_account; gint uncached_msgs = 0; - uncached_msgs = header_list_count_uncached_msgs (headers); - /* We don't need any further check if * * 1- the source folder is local OR @@ -5284,6 +5401,7 @@ modest_ui_actions_xfer_messages_check (GtkWindow *parent_window, * offline, it'll take place the next time we get a * connection) */ + uncached_msgs = header_list_count_uncached_msgs (headers); src_account = get_account_from_folder_store (src_folder); if (uncached_msgs > 0) { guint num_headers; @@ -5306,11 +5424,11 @@ modest_ui_actions_xfer_messages_check (GtkWindow *parent_window, if (remote_folder_has_leave_on_server (src_folder) && delete_originals) { const gchar *account_name; gboolean leave_on_server; - + account_name = modest_tny_account_get_parent_modest_account_name_for_server_account (src_account); leave_on_server = modest_account_mgr_get_leave_on_server (modest_runtime_get_account_mgr (), account_name); - + if (leave_on_server == TRUE) { *need_connection = FALSE; } else { @@ -5329,20 +5447,21 @@ static void xfer_messages_error_handler (ModestMailOperation *mail_op, gpointer user_data) { - ModestWindow *main_window = NULL; + GObject *win; + const GError *error; - /* Disable next automatic folder selection */ - main_window = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (), - FALSE); /* don't create */ - if (main_window) { - GObject *win = modest_mail_operation_get_source (mail_op); + win = modest_mail_operation_get_source (mail_op); + error = modest_mail_operation_get_error (mail_op); + + if (error && is_memory_full_error ((GError *) error, mail_op)) + modest_platform_information_banner ((GtkWidget *) win, + NULL, _KR("cerm_device_memory_full")); + else modest_platform_run_information_dialog ((GtkWindow *) win, _("mail_in_ui_folder_move_target_error"), FALSE); - if (win) - g_object_unref (win); - } - move_to_helper_destroyer (user_data); + if (win) + g_object_unref (win); } typedef struct { @@ -5396,12 +5515,15 @@ xfer_messages_performer (gboolean canceled, } movehelper = g_new0 (MoveToHelper, 1); + +#ifndef MODEST_TOOLKIT_HILDON2 movehelper->banner = modest_platform_animation_banner (GTK_WIDGET (win), NULL, _CS("ckct_nw_pasting")); if (movehelper->banner != NULL) { g_object_ref (movehelper->banner); gtk_widget_show (GTK_WIDGET (movehelper->banner)); } +#endif if (MODEST_IS_MAIN_WINDOW (win)) { GtkWidget *header_view = @@ -5445,21 +5567,23 @@ on_move_folder_cb (gboolean canceled, GError *err, GtkWindow *parent_window, MoveFolderInfo *info = (MoveFolderInfo*)user_data; GtkTreeSelection *sel; ModestMailOperation *mail_op = NULL; - + if (canceled || err || !MODEST_IS_WINDOW (parent_window)) { g_object_unref (G_OBJECT (info->src_folder)); g_object_unref (G_OBJECT (info->dst_folder)); g_free (info); return; } - + MoveToHelper *helper = g_new0 (MoveToHelper, 1); +#ifndef MODEST_TOOLKIT_HILDON2 helper->banner = modest_platform_animation_banner (GTK_WIDGET (parent_window), NULL, _CS("ckct_nw_pasting")); if (helper->banner != NULL) { g_object_ref (helper->banner); gtk_widget_show (GTK_WIDGET(helper->banner)); } +#endif /* Clean folder on header view before moving it */ sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (info->folder_view)); gtk_tree_selection_unselect_all (sel); @@ -5613,6 +5737,10 @@ modest_ui_actions_on_folder_window_move_to (GtkWidget *folder_view, !MODEST_IS_TNY_LOCAL_FOLDERS_ACCOUNT (dst_folder) && !modest_tny_account_is_memory_card_account (TNY_ACCOUNT (dst_folder))) { do_xfer = FALSE; + /* Show an error */ + modest_platform_run_information_dialog (win, + _("mail_in_ui_folder_move_target_error"), + FALSE); } else if (!TNY_IS_FOLDER (src_folder)) { g_warning ("%s: src_folder is not a TnyFolder.\n", __FUNCTION__); do_xfer = FALSE; @@ -5621,7 +5749,7 @@ modest_ui_actions_on_folder_window_move_to (GtkWidget *folder_view, if (do_xfer) { MoveFolderInfo *info = g_new0 (MoveFolderInfo, 1); DoubleConnectionInfo *connect_info = g_slice_new (DoubleConnectionInfo); - + info->src_folder = g_object_ref (src_folder); info->dst_folder = g_object_ref (dst_folder); info->delete_original = TRUE; @@ -5635,6 +5763,7 @@ modest_ui_actions_on_folder_window_move_to (GtkWidget *folder_view, TNY_FOLDER_STORE (src_folder), connect_info); } + /* Frees */ g_object_unref (src_folder); } @@ -5730,36 +5859,42 @@ modest_ui_actions_on_move_to (GtkAction *action, gboolean modest_ui_actions_on_edit_mode_move_to (ModestWindow *win) { - GtkWidget *dialog = NULL, *folder_view = NULL; - ModestMainWindow *main_window; + GtkWidget *dialog = NULL; MoveToInfo *helper = NULL; + TnyList *list_to_move; g_return_val_if_fail (MODEST_IS_WINDOW (win), FALSE); +#ifndef MODEST_TOOLKIT_HILDON2 /* Get the main window if exists */ + ModestMainWindow *main_window; if (MODEST_IS_MAIN_WINDOW (win)) main_window = MODEST_MAIN_WINDOW (win); else main_window = MODEST_MAIN_WINDOW (modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (), FALSE)); /* don't create */ +#endif - /* Get the folder view widget if exists */ - if (main_window) - folder_view = modest_main_window_get_child_widget (main_window, - MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW); - else - folder_view = NULL; + list_to_move = modest_platform_get_list_to_move (MODEST_WINDOW (win)); + + if (!list_to_move) + return FALSE; + + if (tny_list_get_length (list_to_move) < 1) { + g_object_unref (list_to_move); + return FALSE; + } /* Create and run the dialog */ - dialog = create_move_to_dialog (GTK_WINDOW (win), folder_view); + dialog = create_move_to_dialog (GTK_WINDOW (win), NULL, list_to_move); modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (dialog), (GtkWindow *) win); /* Create helper */ helper = g_slice_new0 (MoveToInfo); - helper->list = modest_platform_get_list_to_move (MODEST_WINDOW (win)); + helper->list = list_to_move; helper->win = win; /* Listen to response signal */ @@ -5808,10 +5943,12 @@ do_headers_action (ModestWindow *win, /* Trick: do a poke status in order to speed up the signaling of observers */ - tny_folder_poke_status (folder); + if (folder) { + tny_folder_poke_status (folder); + g_object_unref (folder); + } /* Frees */ - g_object_unref (folder); g_object_unref (iter); g_object_unref (headers_list); } @@ -6140,12 +6277,19 @@ modest_ui_actions_on_open_addressbook (GtkAction *action, ModestWindow *win) void -modest_ui_actions_on_toggle_find_in_page (GtkToggleAction *action, +modest_ui_actions_on_toggle_find_in_page (GtkAction *action, ModestWindow *window) { + gboolean active; g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window)); - modest_msg_edit_window_toggle_find_toolbar (MODEST_MSG_EDIT_WINDOW (window), gtk_toggle_action_get_active (action)); + if (GTK_IS_TOGGLE_ACTION (action)) + active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)); + else + active = TRUE; + + modest_msg_edit_window_toggle_find_toolbar (MODEST_MSG_EDIT_WINDOW (window), + active); } static void @@ -6202,7 +6346,7 @@ on_send_receive_finished (ModestMailOperation *mail_op, } -void +void modest_ui_actions_on_send_queue_error_happened (TnySendQueue *self, TnyHeader *header, TnyMsg *msg, @@ -6210,8 +6354,9 @@ modest_ui_actions_on_send_queue_error_happened (TnySendQueue *self, gpointer user_data) { const gchar* server_name = NULL; - TnyTransportAccount *server_account; + TnyTransportAccount *transport; gchar *message = NULL; + ModestProtocol *protocol; /* Don't show anything if the user cancelled something or the * send receive request is not interactive. Authentication @@ -6223,35 +6368,61 @@ modest_ui_actions_on_send_queue_error_happened (TnySendQueue *self, return; - /* Get the server name: */ - server_account = - TNY_TRANSPORT_ACCOUNT (tny_camel_send_queue_get_transport_account (TNY_CAMEL_SEND_QUEUE (self))); - if (server_account) - server_name = tny_account_get_hostname (TNY_ACCOUNT (server_account)); - else - g_return_if_reached (); + /* Get the server name. Note that we could be using a + connection specific transport account */ + transport = (TnyTransportAccount *) + tny_camel_send_queue_get_transport_account (TNY_CAMEL_SEND_QUEUE (self)); + if (transport) { + ModestTnyAccountStore *acc_store; + const gchar *acc_name; + TnyTransportAccount *conn_specific; + + acc_store = modest_runtime_get_account_store(); + acc_name = modest_tny_account_get_parent_modest_account_name_for_server_account (TNY_ACCOUNT (transport)); + conn_specific = (TnyTransportAccount *) + modest_tny_account_store_get_transport_account_for_open_connection (acc_store, acc_name); + if (conn_specific) { + server_name = tny_account_get_hostname (TNY_ACCOUNT (conn_specific)); + g_object_unref (conn_specific); + } else { + server_name = tny_account_get_hostname (TNY_ACCOUNT (transport)); + } + g_object_unref (transport); + } + + /* Get protocol */ + protocol = modest_protocol_registry_get_protocol_by_name (modest_runtime_get_protocol_registry (), + MODEST_PROTOCOL_REGISTRY_TRANSPORT_STORE_PROTOCOLS, + tny_account_get_proto (TNY_ACCOUNT (transport))); + if (!protocol) { + g_warning ("%s: Account with no proto", __FUNCTION__); + return; + } /* Show the appropriate message text for the GError: */ switch (err->code) { case TNY_SERVICE_ERROR_CONNECT: - message = g_strdup_printf (_("emev_ib_ui_smtp_server_invalid"), server_name); + message = modest_protocol_get_translation (protocol, + MODEST_PROTOCOL_TRANSLATION_ACCOUNT_CONNECTION_ERROR, + server_name); break; case TNY_SERVICE_ERROR_SEND: - message = g_strdup (dgettext("hildon-common-strings", "sfil_ib_unable_to_send")); + message = g_strdup (_CS("sfil_ib_unable_to_send")); break; case TNY_SERVICE_ERROR_UNAVAILABLE: - message = g_strdup_printf (_("emev_ib_ui_smtp_server_invalid"), server_name); + message = modest_protocol_get_translation (protocol, + MODEST_PROTOCOL_TRANSLATION_CONNECT_ERROR, + server_name); break; default: g_warning ("%s: unexpected ERROR %d", __FUNCTION__, err->code); - message = g_strdup (dgettext("hildon-common-strings", "sfil_ib_unable_to_send")); - break; + message = g_strdup (_CS("sfil_ib_unable_to_send")); + break; } modest_platform_run_information_dialog (NULL, message, FALSE); g_free (message); - g_object_unref (server_account); } void @@ -6260,63 +6431,71 @@ modest_ui_actions_on_send_queue_status_changed (ModestTnySendQueue *send_queue, guint status, gpointer user_data) { - ModestMainWindow *main_window = NULL; + ModestWindow *top_window = NULL; ModestWindowMgr *mgr = NULL; - GtkWidget *folder_view = NULL, *header_view = NULL; - TnyFolderStore *selected_folder = NULL; + GtkWidget *header_view = NULL; + TnyFolder *selected_folder = NULL; TnyFolderType folder_type; mgr = modest_runtime_get_window_mgr (); - main_window = MODEST_MAIN_WINDOW (modest_window_mgr_get_main_window (mgr, - FALSE));/* don't create */ - if (!main_window) + top_window = modest_window_mgr_get_current_top (mgr); + + if (!top_window) return; - /* Check if selected folder is OUTBOX */ - folder_view = modest_main_window_get_child_widget (main_window, - MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW); - header_view = modest_main_window_get_child_widget (main_window, - MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW); +#ifndef MODEST_TOOLKIT_HILDON2 + if (MODEST_IS_MAIN_WINDOW (top_window)) { + header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (top_window), + MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW); + } +#else + if (MODEST_IS_HEADER_WINDOW (top_window)) { + header_view = (GtkWidget *) + modest_header_window_get_header_view (MODEST_HEADER_WINDOW (top_window)); + } +#endif - selected_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view)); - if (!TNY_IS_FOLDER (selected_folder)) - goto frees; + /* Get selected folder */ + if (header_view) + selected_folder = modest_header_view_get_folder (MODEST_HEADER_VIEW (header_view)); + if (!selected_folder) + return; /* gtk_tree_view_column_queue_resize is only available in GTK+ 2.8 */ -#if GTK_CHECK_VERSION(2, 8, 0) - folder_type = modest_tny_folder_guess_folder_type (TNY_FOLDER (selected_folder)); - if (folder_type == TNY_FOLDER_TYPE_OUTBOX) { +#if GTK_CHECK_VERSION(2, 8, 0) + folder_type = modest_tny_folder_guess_folder_type (selected_folder); + if (folder_type == TNY_FOLDER_TYPE_OUTBOX) { GtkTreeViewColumn *tree_column; - tree_column = gtk_tree_view_get_column (GTK_TREE_VIEW (header_view), + tree_column = gtk_tree_view_get_column (GTK_TREE_VIEW (header_view), TNY_GTK_HEADER_LIST_MODEL_FROM_COLUMN); if (tree_column) gtk_tree_view_column_queue_resize (tree_column); - } -#else + } +#else /* #if GTK_CHECK_VERSION(2, 8, 0) */ gtk_widget_queue_draw (header_view); -#endif +#endif +#ifndef MODEST_TOOLKIT_HILDON2 /* Rerun dimming rules, because the message could become deletable for example */ - modest_window_check_dimming_rules_group (MODEST_WINDOW (main_window), + modest_window_check_dimming_rules_group (MODEST_WINDOW (top_window), MODEST_DIMMING_RULES_TOOLBAR); - modest_window_check_dimming_rules_group (MODEST_WINDOW (main_window), + modest_window_check_dimming_rules_group (MODEST_WINDOW (top_window), MODEST_DIMMING_RULES_MENU); - +#endif + /* Free */ - frees: - if (selected_folder != NULL) - g_object_unref (selected_folder); + g_object_unref (selected_folder); } -void +void modest_ui_actions_on_account_connection_error (GtkWindow *parent_window, TnyAccount *account) { ModestProtocolType protocol_type; ModestProtocol *protocol; gchar *error_note = NULL; - + protocol_type = modest_tny_account_get_protocol_type (account); protocol = modest_protocol_registry_get_protocol_by_type (modest_runtime_get_protocol_registry (), protocol_type); @@ -6381,6 +6560,9 @@ modest_ui_actions_get_msg_already_deleted_error_msg (ModestWindow *win) folder = TNY_FOLDER_STORE (tny_header_get_folder (header)); } + if (!header || !folder) + goto frees; + /* Get the account type */ account = tny_folder_get_account (TNY_FOLDER (folder)); proto = modest_tny_account_get_protocol_type (account); @@ -6395,10 +6577,14 @@ modest_ui_actions_get_msg_already_deleted_error_msg (ModestWindow *win) msg = g_strdup_printf (_("mail_ni_ui_folder_get_msg_folder_error")); } + frees: /* Frees */ - g_object_unref (account); - g_object_unref (folder); - g_object_unref (header); + if (account) + g_object_unref (account); + if (folder) + g_object_unref (folder); + if (header) + g_object_unref (header); return msg; }