X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fmodest-ui-actions.c;h=f69a922dda6696d1aa9b5e25044cb05361ab5241;hp=9961f4fde034120c240ca994d9ba527ac5433f53;hb=a656e616f249f2de29c6abe2afb12667305669c6;hpb=34fde15dc10aa5e4eae67789e7cb4c4ba8569fc6 diff --git a/src/modest-ui-actions.c b/src/modest-ui-actions.c index 9961f4f..f69a922 100644 --- a/src/modest-ui-actions.c +++ b/src/modest-ui-actions.c @@ -164,11 +164,6 @@ static GtkWidget* get_folder_view_from_move_to_dialog (GtkWidget *move_to_dialog static TnyAccount *get_account_from_folder_store (TnyFolderStore *folder_store); -static void transfer_messages_helper (GtkWindow *win, - TnyFolder *src_folder, - TnyList *headers, - TnyFolder *dst_folder); - /* * This function checks whether a TnyFolderStore is a pop account */ @@ -427,7 +422,7 @@ modest_ui_actions_on_delete_message (GtkAction *action, ModestWindow *win) msg = g_strdup_printf (_("mcen_nc_unable_to_delete_n_messages"), opened_headers); - modest_platform_run_information_dialog (GTK_WINDOW (win), (const gchar *) msg); + modest_platform_run_information_dialog (GTK_WINDOW (win), (const gchar *) msg, FALSE); g_free (msg); g_object_unref (header_list); @@ -440,7 +435,10 @@ modest_ui_actions_on_delete_message (GtkAction *action, ModestWindow *win) iter = tny_list_create_iterator (header_list); header = TNY_HEADER (tny_iterator_get_current (iter)); if (header) { - desc = g_strdup_printf ("%s", tny_header_get_subject (header)); + gchar *subject; + subject = tny_header_dup_subject (header); + desc = g_strdup_printf ("%s", subject); + g_free (subject); g_object_unref (header); } @@ -528,7 +526,7 @@ modest_ui_actions_on_delete_message (GtkAction *action, ModestWindow *win) if (prev_row_reference != NULL) gtk_tree_row_reference_free (prev_row_reference); if (prev_path != NULL) - gtk_tree_path_free (prev_path); + gtk_tree_path_free (prev_path); } /* Update toolbar dimming state */ @@ -650,7 +648,6 @@ modest_ui_actions_on_accounts (GtkAction *action, } else { /* Show the list of accounts */ GtkWindow *account_win = GTK_WINDOW (modest_account_view_window_new ()); - gtk_window_set_transient_for (account_win, GTK_WINDOW (win)); /* The accounts dialog must be modal */ modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), account_win); @@ -658,18 +655,6 @@ modest_ui_actions_on_accounts (GtkAction *action, } } -#ifdef MODEST_PLATFORM_MAEMO -static void -on_smtp_servers_window_hide (GtkWindow* window, gpointer user_data) -{ - /* Save any changes. */ - modest_connection_specific_smtp_window_save_server_accounts ( - MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (window)); - gtk_widget_destroy (GTK_WIDGET (window)); -} -#endif - - void modest_ui_actions_on_smtp_servers (GtkAction *action, ModestWindow *win) { @@ -685,14 +670,10 @@ modest_ui_actions_on_smtp_servers (GtkAction *action, ModestWindow *win) MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (specific_window), modest_runtime_get_account_mgr()); - /* Show the window: */ - gtk_window_set_transient_for (GTK_WINDOW (specific_window), GTK_WINDOW (win)); - gtk_window_set_modal (GTK_WINDOW (specific_window), TRUE); + /* Show the window: */ + modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), + GTK_WINDOW (specific_window)); gtk_widget_show (specific_window); - - /* Save changes when the window is hidden: */ - g_signal_connect (specific_window, "hide", - G_CALLBACK (on_smtp_servers_window_hide), win); #endif /* MODEST_PLATFORM_MAEMO */ } @@ -715,6 +696,13 @@ modest_ui_actions_compose_msg(ModestWindow *win, ModestWindow *msg_win = NULL; ModestAccountMgr *mgr = modest_runtime_get_account_mgr(); ModestTnyAccountStore *store = modest_runtime_get_account_store(); + GnomeVFSFileSize total_size, allowed_size; + + /* we check for low-mem; in that case, show a warning, and don't allow + * composing a message with attachments + */ + if (attachments && modest_platform_check_memory_low (win)) + goto cleanup; account_name = modest_account_mgr_get_default_account(mgr); if (!account_name) { @@ -744,7 +732,7 @@ modest_ui_actions_compose_msg(ModestWindow *win, body = use_signature ? g_strconcat("\n", signature, NULL) : g_strdup(""); } - msg = modest_tny_msg_new (to_str, from_str, cc_str, bcc_str, subject_str, body, NULL); + msg = modest_tny_msg_new (to_str, from_str, cc_str, bcc_str, subject_str, body, NULL, NULL); if (!msg) { g_printerr ("modest: failed to create new msg\n"); goto cleanup; @@ -752,10 +740,22 @@ modest_ui_actions_compose_msg(ModestWindow *win, /* Create and register edit window */ /* This is destroyed by TODO. */ + total_size = 0; + allowed_size = MODEST_MAX_ATTACHMENT_SIZE; msg_win = modest_msg_edit_window_new (msg, account_name, FALSE); while (attachments) { - modest_msg_edit_window_attach_file_one((ModestMsgEditWindow *)msg_win, - attachments->data); + total_size += + modest_msg_edit_window_attach_file_one( + (ModestMsgEditWindow *)msg_win, + attachments->data, allowed_size); + + if (total_size > allowed_size) { + g_warning ("%s: total size: %u", + __FUNCTION__, (unsigned int)total_size); + break; + } + allowed_size -= total_size; + attachments = g_slist_next(attachments); } modest_window_mgr_register_window (modest_runtime_get_window_mgr(), msg_win); @@ -768,10 +768,14 @@ cleanup: g_free (signature); g_free (body); g_free (account_name); - if (account) g_object_unref (G_OBJECT(account)); - if (folder) g_object_unref (G_OBJECT(folder)); - if (msg_win) g_object_unref (G_OBJECT(msg_win)); - if (msg) g_object_unref (G_OBJECT(msg)); + if (account) + g_object_unref (G_OBJECT(account)); + if (folder) + g_object_unref (G_OBJECT(folder)); + if (msg_win) + g_object_unref (G_OBJECT(msg_win)); + if (msg) + g_object_unref (G_OBJECT(msg)); } void @@ -828,7 +832,8 @@ 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); - g_object_ref (banner_info->banner); + if (banner_info) + g_object_ref (banner_info->banner); gdk_threads_leave (); @@ -883,7 +888,7 @@ open_msg_cb (ModestMailOperation *mail_op, char *msg_id; account = g_strdup(modest_tny_account_get_parent_modest_account_name_for_server_account( TNY_ACCOUNT(traccount))); - send_queue = modest_runtime_get_send_queue(traccount); + send_queue = modest_runtime_get_send_queue(traccount, TRUE); msg_id = modest_tny_send_queue_get_msg_id (header); status = modest_tny_send_queue_get_msg_status(send_queue, msg_id); /* Only open messages in outbox with the editor if they are in Failed state */ @@ -907,30 +912,46 @@ open_msg_cb (ModestMailOperation *mail_op, if (open_in_editor) { ModestAccountMgr *mgr = modest_runtime_get_account_mgr (); - const gchar *from_header = NULL; + gchar *from_header = NULL; - from_header = tny_header_get_from (header); + from_header = tny_header_dup_from (header); /* we cannot edit without a valid account... */ if (!modest_account_mgr_has_accounts(mgr, TRUE)) { - if (!modest_ui_actions_run_account_setup_wizard(parent_win)) + if (!modest_ui_actions_run_account_setup_wizard(parent_win)) { + modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (), + header); + g_free (from_header); goto cleanup; + } } if (from_header) { GSList *accounts = modest_account_mgr_account_names (mgr, TRUE); GSList *node = NULL; + gchar *from_header_email; + + from_header_email = modest_text_utils_get_email_address ((const gchar *) from_header); + for (node = accounts; node != NULL; node = g_slist_next (node)) { - gchar *from = modest_account_mgr_get_from_string (mgr, node->data); + gchar *from, *from_email; - if (from && (strcmp (from_header, from) == 0)) { - g_free (account); - account = g_strdup (node->data); + from = modest_account_mgr_get_from_string (mgr, node->data); + if (from) { + from_email = modest_text_utils_get_email_address ((const gchar *) from); + if (strcmp (from_header_email, from_email) == 0) { + g_free (account); + account = g_strdup (node->data); + g_free (from_email); + g_free (from); + break; + } + g_free (from_email); g_free (from); - break; } - g_free (from); } + g_free (from_header_email); + g_free (from_header); g_slist_foreach (accounts, (GFunc) g_free, NULL); g_slist_free (accounts); } @@ -1006,6 +1027,9 @@ modest_ui_actions_disk_operations_error_handler (ModestMailOperation *mail_op, modest_platform_information_banner ((GtkWidget *) win, NULL, dgettext("ke-recv", "cerm_device_memory_full")); + } else if (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")); } else if (user_data) { modest_platform_information_banner ((GtkWidget *) win, NULL, user_data); @@ -1143,8 +1167,10 @@ open_msgs_performer(gboolean canceled, } else if (proto == MODEST_PROTOCOL_STORE_IMAP) { TnyIterator *iter = tny_list_create_iterator (not_opened_headers); TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter)); + gchar *subject = tny_header_dup_subject (header); error_msg = g_strdup_printf (_("emev_ni_ui_imap_message_not_available_in_server"), - tny_header_get_subject (header)); + subject); + g_free (subject); g_object_unref (header); g_object_unref (iter); } else { @@ -1371,6 +1397,12 @@ void modest_ui_actions_on_open (GtkAction *action, ModestWindow *win) { TnyList *headers; + + /* we check for low-mem; in that case, show a warning, and don't allow + * opening + */ + if (modest_platform_check_memory_low (MODEST_WINDOW(win))) + return; /* Get headers */ headers = get_selected_headers (win); @@ -1564,6 +1596,13 @@ reply_forward (ReplyForwardAction action, ModestWindow *win) g_return_if_fail (MODEST_IS_WINDOW(win)); + + /* we check for low-mem; in that case, show a warning, and don't allow + * reply/forward (because it could potentially require a lot of memory */ + if (modest_platform_check_memory_low (MODEST_WINDOW(win))) + return; + + /* we need an account when editing */ if (!modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE)) { if (!modest_ui_actions_run_account_setup_wizard (win)) @@ -1659,6 +1698,7 @@ reply_forward (ReplyForwardAction action, ModestWindow *win) modest_mail_operation_get_msg (mail_op, header, + TRUE, reply_forward_cb, rf_helper); /* Clean */ @@ -1820,6 +1860,7 @@ typedef struct { gchar *account_name; gboolean poke_status; gboolean interactive; + ModestMailOperation *mail_op; } SendReceiveInfo; static void @@ -1829,7 +1870,6 @@ do_send_receive_performer (gboolean canceled, TnyAccount *account, gpointer user_data) { - ModestMailOperation *mail_op; SendReceiveInfo *info; info = (SendReceiveInfo *) user_data; @@ -1841,6 +1881,10 @@ do_send_receive_performer (gboolean canceled, NULL, dgettext("ke-recv", "cerm_device_memory_full")); } + if (info->mail_op) { + modest_mail_operation_queue_remove (modest_runtime_get_mail_operation_queue (), + info->mail_op); + } goto clean; } @@ -1848,25 +1892,21 @@ do_send_receive_performer (gboolean canceled, if (info->win && MODEST_IS_MAIN_WINDOW (info->win)) { modest_main_window_notify_send_receive_initied (MODEST_MAIN_WINDOW (info->win)); } - - mail_op = modest_mail_operation_new_with_error_handling ((info->win) ? G_OBJECT (info->win) : NULL, - modest_ui_actions_disk_operations_error_handler, - NULL, NULL); if (info->win && MODEST_IS_MAIN_WINDOW (info->win)) - g_signal_connect (G_OBJECT(mail_op), "operation-finished", + g_signal_connect (G_OBJECT (info->mail_op), "operation-finished", G_CALLBACK (on_send_receive_finished), info->win); /* Send & receive. */ - modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op); - modest_mail_operation_update_account (mail_op, info->account_name, info->poke_status, info->interactive, + modest_mail_operation_update_account (info->mail_op, info->account_name, info->poke_status, info->interactive, (info->win) ? retrieve_all_messages_cb : NULL, new_messages_arrived, info->win); - g_object_unref (G_OBJECT (mail_op)); clean: /* Frees */ + if (info->mail_op) + g_object_unref (G_OBJECT (info->mail_op)); if (info->account_name) g_free (info->account_name); if (info->win) @@ -1918,6 +1958,13 @@ modest_ui_actions_do_send_receive (const gchar *account_name, info->interactive = interactive; info->account = modest_tny_account_store_get_server_account (acc_store, acc_name, TNY_ACCOUNT_TYPE_STORE); + /* We need to create the operation here, because otherwise it + could happen that the queue emits the queue-empty signal + while we're trying to connect the account */ + info->mail_op = modest_mail_operation_new_with_error_handling ((info->win) ? G_OBJECT (info->win) : NULL, + modest_ui_actions_disk_operations_error_handler, + NULL, NULL); + modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), info->mail_op); /* Invoke the connect and perform */ modest_platform_connect_and_perform ((win) ? GTK_WINDOW (win) : NULL, @@ -1946,7 +1993,7 @@ modest_ui_actions_do_cancel_send (const gchar *account_name, } /* Get send queue*/ - send_queue = TNY_SEND_QUEUE (modest_runtime_get_send_queue (transport_account)); + send_queue = TNY_SEND_QUEUE (modest_runtime_get_send_queue (transport_account, TRUE)); if (!TNY_IS_SEND_QUEUE(send_queue)) { g_set_error (&error, MODEST_MAIL_OPERATION_ERROR, MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND, @@ -2138,6 +2185,7 @@ modest_ui_actions_on_header_activated (ModestHeaderView *header_view, ModestMainWindow *main_window) { TnyList *headers; + GtkWidget *open_widget; g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window)); @@ -2149,6 +2197,16 @@ modest_ui_actions_on_header_activated (ModestHeaderView *header_view, return; } + /* we check for low-mem; in that case, show a warning, and don't allow + * activating headers + */ + if (modest_platform_check_memory_low (MODEST_WINDOW(main_window))) + return; + + modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (main_window)); + open_widget = modest_window_get_action_widget (MODEST_WINDOW (main_window), "/MenuBar/EmailMenu/EmailOpenMenu"); + if (!GTK_WIDGET_IS_SENSITIVE (open_widget)) + return; /* headers = tny_simple_list_new (); */ /* tny_list_prepend (headers, G_OBJECT (header)); */ @@ -2219,6 +2277,7 @@ folder_refreshed_cb (ModestMailOperation *mail_op, if (tny_folder_get_all_count (folder) == 0) modest_main_window_set_contents_style (win, MODEST_MAIN_WINDOW_CONTENTS_STYLE_EMPTY); + } void @@ -2281,18 +2340,24 @@ modest_ui_actions_on_folder_selection_changed (ModestFolderView *folder_view, G_OBJECT(header_view), MODEST_CONF_HEADER_VIEW_KEY); } else { - /* Update the active account */ - //modest_window_set_active_account (MODEST_WINDOW (main_window), NULL); - /* Save only if we're seeing headers */ + /* No need to save the header view + configuration for Maemo because it only + saves the sorting stuff and that it's + already being done by the sort + dialog. Remove it when the GNOME version + has the same behaviour */ +#ifdef MODEST_PLATFORM_GNOME if (modest_main_window_get_contents_style (main_window) == MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS) modest_widget_memory_save (conf, G_OBJECT (header_view), MODEST_CONF_HEADER_VIEW_KEY); +#endif modest_header_view_clear (MODEST_HEADER_VIEW(header_view)); } } - /* Update toolbar dimming state */ + /* Update dimming state */ + modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (main_window)); modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window)); } @@ -2368,7 +2433,13 @@ modest_ui_actions_on_msg_link_contextual (ModestMsgView *msgview, const gchar* l void modest_ui_actions_on_msg_attachment_clicked (ModestMsgView *msgview, TnyMimePart *mime_part, ModestWindow *win) -{ +{ + /* we check for low-mem; in that case, show a warning, and don't allow + * viewing attachments + */ + if (modest_platform_check_memory_low (MODEST_WINDOW(win))) + return; + modest_msg_view_window_view_attachment (MODEST_MSG_VIEW_WINDOW (win), mime_part); } @@ -2442,6 +2513,35 @@ modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edi return FALSE; } + /* + * djcb: if we're in low-memory state, we only allow for + * saving messages smaller than + * MODEST_MAX_LOW_MEMORY_MESSAGE_SIZE (see modest-defs.h) this + * should still allow for sending anything critical... + */ + if (expected_size > MODEST_MAX_LOW_MEMORY_MESSAGE_SIZE) { + + if (modest_platform_check_memory_low (MODEST_WINDOW(edit_window))) { + modest_msg_edit_window_free_msg_data (edit_window, data); + return FALSE; + } + } + + /* + * djcb: we also make sure that the attachments are smaller than the max size + * this is for the case where we'd try to forward a message with attachments + * bigger than our max allowed size, or sending an message from drafts which + * somehow got past our checks when attaching. + */ + if (expected_size > MODEST_MAX_ATTACHMENT_SIZE) { + modest_platform_run_information_dialog ( + GTK_WINDOW(edit_window), + dgettext("ke-recv","memr_ib_operation_disabled"), + TRUE); + modest_msg_edit_window_free_msg_data (edit_window, data); + return FALSE; + } + account_name = g_strdup (data->account_name); account_mgr = modest_runtime_get_account_mgr(); if (!account_name) @@ -2584,6 +2684,34 @@ modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window) return FALSE; } + + /* + * djcb: if we're in low-memory state, we only allow for sending messages + * smaller than MODEST_MAX_LOW_MEMORY_MESSAGE_SIZE (see modest-defs.h) + * this should still allow for sending anything critical... + */ + if (expected_size > MODEST_MAX_LOW_MEMORY_MESSAGE_SIZE) { + if (modest_platform_check_memory_low (MODEST_WINDOW(edit_window))) { + modest_msg_edit_window_free_msg_data (edit_window, data); + return FALSE; + } + } + + /* + * djcb: we also make sure that the attachments are smaller than the max size + * this is for the case where we'd try to forward a message with attachments + * bigger than our max allowed size, or sending an message from drafts which + * somehow got past our checks when attaching. + */ + if (expected_size > MODEST_MAX_ATTACHMENT_SIZE) { + modest_platform_run_information_dialog ( + GTK_WINDOW(edit_window), + dgettext("ke-recv","memr_ib_operation_disabled"), + TRUE); + modest_msg_edit_window_free_msg_data (edit_window, data); + return FALSE; + } + ModestAccountMgr *account_mgr = modest_runtime_get_account_mgr(); gchar *account_name = g_strdup (data->account_name); if (!account_name) @@ -2617,7 +2745,7 @@ modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window) gchar *from = modest_account_mgr_get_from_string (account_mgr, account_name); /* Create the mail operation */ - ModestMailOperation *mail_operation = modest_mail_operation_new (NULL); + ModestMailOperation *mail_operation = modest_mail_operation_new_with_error_handling (NULL, modest_ui_actions_disk_operations_error_handler, NULL, NULL); modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation); modest_mail_operation_send_new_mail (mail_operation, @@ -2784,6 +2912,10 @@ modest_ui_actions_on_insert_image (GtkAction *action, 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))) + return; + if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT) return; @@ -2797,6 +2929,9 @@ modest_ui_actions_on_attach_file (GtkAction *action, 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))) + return; + modest_msg_edit_window_offer_attach_file (window); } @@ -2848,9 +2983,12 @@ do_create_folder_cb (ModestMailOperation *mail_op, folder_view = get_folder_view_from_move_to_dialog (GTK_WIDGET(source_win)); - /* Select the newly created folder */ - modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view), - new_folder, FALSE); + /* Select the newly created folder. It could happen + that the widget is no longer there (i.e. the window + has been destroyed, so we need to check this */ + if (folder_view) + modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view), + new_folder, FALSE); g_object_unref (new_folder); } /* Free. Note that the first time it'll be NULL so noop */ @@ -2874,7 +3012,7 @@ do_create_folder (GtkWindow *parent_window, if (result == GTK_RESPONSE_ACCEPT) { ModestMailOperation *mail_op; - mail_op = modest_mail_operation_new (NULL); + 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, @@ -2982,6 +3120,11 @@ on_rename_folder_cb (ModestMailOperation *mail_op, { ModestFolderView *folder_view; + /* If the window was closed when renaming a folder this could + happen */ + if (!MODEST_IS_FOLDER_VIEW (user_data)) + return; + folder_view = MODEST_FOLDER_VIEW (user_data); /* Note that if the rename fails new_folder will be NULL */ if (new_folder) { @@ -2989,6 +3132,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)); } static void @@ -3101,7 +3245,8 @@ modest_ui_actions_delete_folder_error_handler (ModestMailOperation *mail_op, GObject *win = modest_mail_operation_get_source (mail_op); modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL, - _("mail_in_ui_folder_delete_error")); + _("mail_in_ui_folder_delete_error"), + FALSE); g_object_unref (win); } @@ -3173,7 +3318,8 @@ delete_folder (ModestMainWindow *main_window, gboolean move_to_trash) /* Show an error if it's an account */ if (!TNY_IS_FOLDER (folder)) { modest_platform_run_information_dialog (GTK_WINDOW (main_window), - _("mail_in_ui_folder_delete_error")); + _("mail_in_ui_folder_delete_error"), + FALSE); g_object_unref (G_OBJECT (folder)); return; } @@ -3219,6 +3365,30 @@ modest_ui_actions_on_move_folder_to_trash_folder (GtkAction *action, ModestMainW } +typedef struct _PasswordDialogFields { + GtkWidget *username; + GtkWidget *password; + GtkWidget *dialog; +} PasswordDialogFields; + +static void +password_dialog_check_field (GtkEditable *editable, + PasswordDialogFields *fields) +{ + const gchar *value; + gboolean any_value_empty = FALSE; + + value = gtk_entry_get_text (GTK_ENTRY (fields->username)); + if ((value == NULL) || value[0] == '\0') { + any_value_empty = TRUE; + } + value = gtk_entry_get_text (GTK_ENTRY (fields->password)); + if ((value == NULL) || value[0] == '\0') { + any_value_empty = TRUE; + } + gtk_dialog_set_response_sensitive (GTK_DIALOG (fields->dialog), GTK_RESPONSE_ACCEPT, !any_value_empty); +} + void modest_ui_actions_on_password_requested (TnyAccountStore *account_store, const gchar* server_account_name, @@ -3230,6 +3400,7 @@ modest_ui_actions_on_password_requested (TnyAccountStore *account_store, { g_return_if_fail(server_account_name); gboolean completed = FALSE; + PasswordDialogFields *fields = NULL; /* Initalize output parameters: */ if (cancel) @@ -3290,11 +3461,16 @@ modest_ui_actions_on_password_requested (TnyAccountStore *account_store, gtk_entry_set_text (GTK_ENTRY (entry_username), initial_username); /* Dim this if a connection has ever succeeded with this username, * as per the UI spec: */ - const gboolean username_known = - modest_account_mgr_get_server_account_username_has_succeeded( - modest_runtime_get_account_mgr(), server_account_name); - gtk_widget_set_sensitive (entry_username, !username_known); - + /* const gboolean username_known = */ + /* modest_account_mgr_get_server_account_username_has_succeeded( */ + /* modest_runtime_get_account_mgr(), server_account_name); */ + /* gtk_widget_set_sensitive (entry_username, !username_known); */ + + /* We drop the username sensitive code and disallow changing it here + * as tinymail does not support really changing the username in the callback + */ + gtk_widget_set_sensitive (entry_username, FALSE); + #ifdef MODEST_PLATFORM_MAEMO /* Auto-capitalization is the default, so let's turn it off: */ hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_username), HILDON_GTK_INPUT_MODE_FULL); @@ -3346,6 +3522,15 @@ modest_ui_actions_on_password_requested (TnyAccountStore *account_store, TRUE, FALSE, 0); */ + fields = g_slice_new0 (PasswordDialogFields); + fields->username = entry_username; + fields->password = entry_password; + fields->dialog = dialog; + + g_signal_connect (entry_username, "changed", G_CALLBACK (password_dialog_check_field), fields); + g_signal_connect (entry_password, "changed", G_CALLBACK (password_dialog_check_field), fields); + password_dialog_check_field (NULL, fields); + gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox)); while (!completed) { @@ -3409,6 +3594,7 @@ modest_ui_actions_on_password_requested (TnyAccountStore *account_store, */ gtk_widget_destroy (dialog); + g_slice_free (PasswordDialogFields, fields); /* printf ("DEBUG: %s: cancel=%d\n", __FUNCTION__, *cancel); */ } @@ -3588,8 +3774,10 @@ paste_as_attachment_free (gpointer data) { PasteAsAttachmentHelper *helper = (PasteAsAttachmentHelper *) data; - gtk_widget_destroy (helper->banner); - g_object_unref (helper->banner); + if (helper->banner) { + gtk_widget_destroy (helper->banner); + g_object_unref (helper->banner); + } g_free (helper); } @@ -3643,7 +3831,6 @@ modest_ui_actions_on_paste (GtkAction *action, mail_op = modest_mail_operation_new (G_OBJECT (window)); if (helper->banner != NULL) { g_object_ref (G_OBJECT (helper->banner)); - gtk_window_set_modal (GTK_WINDOW (helper->banner), FALSE); gtk_widget_show (GTK_WIDGET (helper->banner)); } @@ -4376,40 +4563,6 @@ create_move_to_dialog (GtkWindow *win, return dialog; } -/* - * Returns TRUE if at least one of the headers of the list belongs to - * a message that has been fully retrieved. - */ -#if 0 /* no longer in use. delete in 2007.10 */ -static gboolean -has_retrieved_msgs (TnyList *list) -{ - TnyIterator *iter; - gboolean found = FALSE; - - iter = tny_list_create_iterator (list); - while (!tny_iterator_is_done (iter) && !found) { - TnyHeader *header; - TnyHeaderFlags flags = 0; - - header = TNY_HEADER (tny_iterator_get_current (iter)); - if (header) { - flags = tny_header_get_flags (header); - if (flags & TNY_HEADER_FLAG_CACHED) -/* if (!(flags & TNY_HEADER_FLAG_PARTIAL)) */ - found = TRUE; - - g_object_unref (header); - } - - if (!found) - tny_iterator_next (iter); - } - g_object_unref (iter); - - return found; -} -#endif /* 0 */ /* @@ -4502,6 +4655,10 @@ move_to_cb (ModestMailOperation *mail_op, 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); } @@ -4509,7 +4666,10 @@ move_to_cb (ModestMailOperation *mail_op, } /* Close the "Pasting" information banner */ - gtk_widget_destroy (GTK_WIDGET(helper->banner)); + if (helper->banner) { + gtk_widget_destroy (GTK_WIDGET(helper->banner)); + g_object_unref (helper->banner); + } if (helper->reference != NULL) gtk_tree_row_reference_free (helper->reference); g_free (helper); @@ -4545,12 +4705,12 @@ modest_ui_actions_move_folder_error_handler (ModestMailOperation *mail_op, gpointer user_data) { ModestWindow *main_window = NULL; - GObject *win = 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), @@ -4561,13 +4721,15 @@ modest_ui_actions_move_folder_error_handler (ModestMailOperation *mail_op, modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view), TNY_FOLDER (user_data), FALSE); } - } - /* Show notification dialog */ - win = modest_mail_operation_get_source (mail_op); - modest_platform_run_information_dialog ((GtkWindow *) win, _("mail_in_ui_folder_move_target_error")); - if (win) - g_object_unref (win); + /* 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 @@ -4702,7 +4864,7 @@ modest_ui_actions_on_main_window_remove_attachments (GtkAction *action, modest_ui_actions_disk_operations_error_handler, NULL, NULL); modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op); - modest_mail_operation_get_msg (mail_op, header, open_msg_for_purge_cb, win); + modest_mail_operation_get_msg (mail_op, header, FALSE, open_msg_for_purge_cb, win); g_object_unref (mail_op); } @@ -4792,6 +4954,24 @@ modest_ui_actions_xfer_messages_check (GtkWindow *parent_window, g_object_unref (src_account); } +static void +xfer_messages_error_handler (ModestMailOperation *mail_op, + gpointer user_data) +{ + 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 = 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); + } +} /** * Utility function that transfer messages from both the main window @@ -4811,8 +4991,11 @@ xfer_messages_performer (gboolean canceled, const gchar *proto_str = NULL; gboolean dst_is_pop = FALSE; - if (canceled || err) { - if (err && is_memory_full_error (err)) { + if (canceled) + goto end; + + if (err) { + if (is_memory_full_error (err)) { modest_platform_information_banner ((GtkWidget *) parent_window, NULL, dgettext("ke-recv", "cerm_device_memory_full")); @@ -4820,8 +5003,7 @@ xfer_messages_performer (gboolean canceled, /* Show the proper error message */ modest_ui_actions_on_account_connection_error (parent_window, account); } - g_object_unref (dst_folder); - return; + goto end; } dst_account = tny_folder_get_account (TNY_FOLDER (dst_folder)); @@ -4838,10 +5020,9 @@ xfer_messages_performer (gboolean canceled, headers = get_selected_headers (MODEST_WINDOW (win)); if (!headers) { g_warning ("%s: no headers selected", __FUNCTION__); - return; + goto end; } - if (dst_is_pop) { modest_platform_information_banner (GTK_WIDGET (win), NULL, @@ -4849,14 +5030,14 @@ xfer_messages_performer (gboolean canceled, "mail_in_ui_folder_move_targets_error", tny_list_get_length (headers))); g_object_unref (headers); - return; + goto end; } MoveToHelper *helper = g_new0 (MoveToHelper, 1); helper->banner = modest_platform_animation_banner (GTK_WIDGET (win), NULL, _CS("ckct_nw_pasting")); if (helper->banner != NULL) { - gtk_window_set_modal (GTK_WINDOW(helper->banner), FALSE); + g_object_ref (helper->banner); gtk_widget_show (GTK_WIDGET(helper->banner)); } @@ -4869,7 +5050,7 @@ xfer_messages_performer (gboolean canceled, ModestMailOperation *mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT(win), - modest_ui_actions_move_folder_error_handler, + xfer_messages_error_handler, NULL, NULL); modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op); @@ -4883,6 +5064,7 @@ xfer_messages_performer (gboolean canceled, g_object_unref (G_OBJECT (mail_op)); g_object_unref (headers); + end: g_object_unref (dst_folder); } @@ -4912,7 +5094,7 @@ on_move_folder_cb (gboolean canceled, GError *err, GtkWindow *parent_window, helper->banner = modest_platform_animation_banner (GTK_WIDGET (parent_window), NULL, _CS("ckct_nw_pasting")); if (helper->banner != NULL) { - gtk_window_set_modal (GTK_WINDOW(helper->banner), FALSE); + g_object_ref (helper->banner); gtk_widget_show (GTK_WIDGET(helper->banner)); } /* Clean folder on header view before moving it */ @@ -4940,21 +5122,21 @@ on_move_folder_cb (gboolean canceled, GError *err, GtkWindow *parent_window, /* modest_folder_view_select_folder (MODEST_FOLDER_VIEW(folder_view), */ /* TNY_FOLDER (src_folder), TRUE); */ + modest_folder_view_select_folder (MODEST_FOLDER_VIEW(info->folder_view), + TNY_FOLDER (info->dst_folder), TRUE); modest_mail_operation_xfer_folder (mail_op, TNY_FOLDER (info->src_folder), info->dst_folder, info->delete_original, folder_move_to_cb, helper); + g_object_unref (G_OBJECT (info->src_folder)); - if (modest_mail_operation_get_status (mail_op) == MODEST_MAIL_OPERATION_STATUS_SUCCESS) { - modest_folder_view_select_folder (MODEST_FOLDER_VIEW(info->folder_view), - TNY_FOLDER (info->dst_folder), TRUE); - } + /* if (modest_mail_operation_get_status (mail_op) == MODEST_MAIL_OPERATION_STATUS_SUCCESS) { */ + /* } */ /* Unref mail operation */ g_object_unref (G_OBJECT (mail_op)); - g_object_unref (G_OBJECT (info->src_folder)); g_object_unref (G_OBJECT (info->dst_folder)); g_free (user_data); } @@ -5026,8 +5208,8 @@ modest_ui_actions_on_main_window_move_to (GtkAction *action, headers = modest_header_view_get_selected_headers(header_view); /* Transfer the messages */ - transfer_messages_helper (GTK_WINDOW (win), TNY_FOLDER (src_folder), - headers, TNY_FOLDER (dst_folder)); + modest_ui_actions_transfer_messages_helper (GTK_WINDOW (win), TNY_FOLDER (src_folder), + headers, TNY_FOLDER (dst_folder)); g_object_unref (headers); } @@ -5037,11 +5219,11 @@ modest_ui_actions_on_main_window_move_to (GtkAction *action, } -static void -transfer_messages_helper (GtkWindow *win, - TnyFolder *src_folder, - TnyList *headers, - TnyFolder *dst_folder) +void +modest_ui_actions_transfer_messages_helper (GtkWindow *win, + TnyFolder *src_folder, + TnyList *headers, + TnyFolder *dst_folder) { gboolean need_connection = TRUE; gboolean do_xfer = TRUE; @@ -5067,8 +5249,7 @@ transfer_messages_helper (GtkWindow *win, } else { TnyAccount *src_account = get_account_from_folder_store (TNY_FOLDER_STORE (src_folder)); xfer_messages_performer (FALSE, NULL, GTK_WINDOW (win), - src_account, - g_object_ref (dst_folder)); + src_account, g_object_ref (dst_folder)); g_object_unref (src_account); } } @@ -5095,8 +5276,8 @@ modest_ui_actions_on_msg_view_window_move_to (GtkAction *action, tny_list_append (headers, G_OBJECT (header)); /* Transfer the messages */ - transfer_messages_helper (GTK_WINDOW (win), src_folder, headers, - TNY_FOLDER (dst_folder)); + modest_ui_actions_transfer_messages_helper (GTK_WINDOW (win), src_folder, headers, + TNY_FOLDER (dst_folder)); /* Frees */ g_object_unref (header); @@ -5220,6 +5401,10 @@ modest_ui_actions_save_attachments (GtkAction *action, ModestWindow *window) { if (MODEST_IS_MSG_VIEW_WINDOW (window)) { + + if (modest_platform_check_memory_low (MODEST_WINDOW(window))) + return; + modest_msg_view_window_save_attachments (MODEST_MSG_VIEW_WINDOW (window), NULL); } else { /* not supported window for this action */ @@ -5455,6 +5640,12 @@ modest_ui_actions_on_search_messages (GtkAction *action, ModestWindow *window) { g_return_if_fail (MODEST_IS_WINDOW (window)); + /* we check for low-mem; in that case, show a warning, and don't allow + * searching + */ + if (modest_platform_check_memory_low (window)) + return; + modest_platform_show_search_messages (GTK_WINDOW (window)); } @@ -5462,6 +5653,15 @@ void modest_ui_actions_on_open_addressbook (GtkAction *action, ModestWindow *win) { g_return_if_fail (MODEST_IS_WINDOW (win)); + + + /* we check for low-mem; in that case, show a warning, and don't allow + * for the addressbook + */ + if (modest_platform_check_memory_low (win)) + return; + + modest_platform_show_addressbook (GTK_WINDOW (win)); } @@ -5580,7 +5780,7 @@ modest_ui_actions_on_send_queue_error_happened (TnySendQueue *self, should show the Accounts Settings dialog or the Connection specific SMTP server window */ - modest_platform_run_information_dialog (NULL, message); + modest_platform_run_information_dialog (NULL, message, FALSE); g_free (message); g_object_unref (server_account); } @@ -5666,7 +5866,7 @@ modest_ui_actions_on_account_connection_error (GtkWindow *parent_window, } if (error_note) { - modest_platform_run_information_dialog (parent_window, error_note); + modest_platform_run_information_dialog (parent_window, error_note, FALSE); g_free (error_note); } } @@ -5708,8 +5908,11 @@ modest_ui_actions_get_msg_already_deleted_error_msg (ModestWindow *win) if (proto == MODEST_PROTOCOL_STORE_POP) { msg = g_strdup (_("emev_ni_ui_pop3_msg_recv_error")); } else if (proto == MODEST_PROTOCOL_STORE_IMAP) { + gchar *subject; + subject = tny_header_dup_subject (header); msg = g_strdup_printf (_("emev_ni_ui_imap_message_not_available_in_server"), - tny_header_get_subject (header)); + subject); + g_free (subject); } else { msg = g_strdup_printf (_("mail_ni_ui_folder_get_msg_folder_error")); }