1 /* Copyright (c) 2006, Nokia Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of the Nokia Corporation nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #endif /*HAVE_CONFIG_H*/
34 #include <glib/gi18n.h>
35 #include <glib/gprintf.h>
37 #include <modest-runtime.h>
38 #include <modest-tny-folder.h>
39 #include <modest-tny-msg.h>
40 #include <modest-tny-account.h>
41 #include <modest-address-book.h>
42 #include "modest-error.h"
43 #include "modest-ui-actions.h"
45 #include "modest-tny-platform-factory.h"
46 #include "modest-platform.h"
47 #include <tny-mime-part.h>
49 #ifdef MODEST_PLATFORM_MAEMO
50 #include "maemo/modest-osso-state-saving.h"
51 #endif /* MODEST_PLATFORM_MAEMO */
53 #include "widgets/modest-ui-constants.h"
54 #include <widgets/modest-main-window.h>
55 #include <widgets/modest-msg-view-window.h>
56 #include <widgets/modest-account-view-window.h>
57 #include <widgets/modest-details-dialog.h>
58 #include <widgets/modest-attachments-view.h>
59 #include "widgets/modest-folder-view.h"
60 #include "widgets/modest-global-settings-dialog.h"
61 #include "modest-connection-specific-smtp-window.h"
62 #include "modest-account-mgr-helpers.h"
63 #include "modest-mail-operation.h"
64 #include "modest-text-utils.h"
66 #ifdef MODEST_HAVE_EASYSETUP
67 #include "easysetup/modest-easysetup-wizard.h"
68 #endif /* MODEST_HAVE_EASYSETUP */
70 #include <modest-widget-memory.h>
71 #include <tny-error.h>
72 #include <tny-simple-list.h>
73 #include <tny-msg-view.h>
74 #include <tny-device.h>
75 #include <tny-merge-folder.h>
77 #include <gtkhtml/gtkhtml.h>
79 typedef struct _GetMsgAsyncHelper {
81 ModestMailOperation *mail_op;
88 typedef enum _ReplyForwardAction {
94 typedef struct _ReplyForwardHelper {
95 guint reply_forward_type;
96 ReplyForwardAction action;
98 GtkWidget *parent_window;
103 * The do_headers_action uses this kind of functions to perform some
104 * action to each member of a list of headers
106 typedef void (*HeadersFunc) (TnyHeader *header, ModestWindow *win, gpointer user_data);
109 do_headers_action (ModestWindow *win,
114 static void open_msg_cb (ModestMailOperation *mail_op,
119 static void reply_forward_cb (ModestMailOperation *mail_op,
124 static void reply_forward (ReplyForwardAction action, ModestWindow *win);
127 static void _on_send_receive_progress_changed (ModestMailOperation *mail_op,
128 ModestMailOperationState *state,
134 run_account_setup_wizard (ModestWindow *win)
136 ModestEasysetupWizardDialog *wizard;
138 g_return_if_fail (MODEST_IS_WINDOW(win));
140 wizard = modest_easysetup_wizard_dialog_new ();
141 gtk_window_set_transient_for (GTK_WINDOW (wizard), GTK_WINDOW (win));
142 gtk_dialog_run (GTK_DIALOG (wizard));
143 gtk_widget_destroy (GTK_WIDGET (wizard));
148 modest_ui_actions_on_about (GtkAction *action, ModestWindow *win)
151 const gchar *authors[] = {
152 "Dirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>",
155 about = gtk_about_dialog_new ();
156 gtk_about_dialog_set_name (GTK_ABOUT_DIALOG(about), PACKAGE_NAME);
157 gtk_about_dialog_set_version (GTK_ABOUT_DIALOG(about),PACKAGE_VERSION);
158 gtk_about_dialog_set_copyright (GTK_ABOUT_DIALOG(about),
159 _("Copyright (c) 2006, Nokia Corporation\n"
160 "All rights reserved."));
161 gtk_about_dialog_set_comments (GTK_ABOUT_DIALOG(about),
162 _("a modest e-mail client\n\n"
163 "design and implementation: Dirk-Jan C. Binnema\n"
164 "contributions from the fine people at KC and Ig\n"
165 "uses the tinymail email framework written by Philip van Hoof"));
166 gtk_about_dialog_set_authors (GTK_ABOUT_DIALOG(about), authors);
167 gtk_about_dialog_set_website (GTK_ABOUT_DIALOG(about), "http://modest.garage.maemo.org");
169 gtk_dialog_run (GTK_DIALOG (about));
170 gtk_widget_destroy(about);
174 * Gets the list of currently selected messages. If the win is the
175 * main window, then it returns a newly allocated list of the headers
176 * selected in the header view. If win is the msg view window, then
177 * the value returned is a list with just a single header.
179 * The caller of this funcion must free the list.
182 get_selected_headers (ModestWindow *win)
184 if (MODEST_IS_MAIN_WINDOW(win)) {
185 GtkWidget *header_view;
187 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
188 MODEST_WIDGET_TYPE_HEADER_VIEW);
189 return modest_header_view_get_selected_headers (MODEST_HEADER_VIEW(header_view));
191 } else if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
192 /* for MsgViewWindows, we simply return a list with one element */
194 TnyList *list = NULL;
196 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
197 if (header != NULL) {
198 list = tny_simple_list_new ();
199 tny_list_prepend (list, G_OBJECT(header));
200 g_object_unref (G_OBJECT(header));
210 headers_action_mark_as_read (TnyHeader *header,
214 TnyHeaderFlags flags;
216 g_return_if_fail (TNY_IS_HEADER(header));
218 flags = tny_header_get_flags (header);
219 if (flags & TNY_HEADER_FLAG_SEEN) return;
220 tny_header_set_flags (header, TNY_HEADER_FLAG_SEEN);
224 headers_action_mark_as_unread (TnyHeader *header,
228 TnyHeaderFlags flags;
230 g_return_if_fail (TNY_IS_HEADER(header));
232 flags = tny_header_get_flags (header);
233 if (flags & TNY_HEADER_FLAG_SEEN) {
234 tny_header_unset_flags (header, TNY_HEADER_FLAG_SEEN);
240 headers_action_delete (TnyHeader *header,
244 ModestMailOperation *mail_op = NULL;
246 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_DELETE, G_OBJECT(win));
247 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
250 /* Always delete. TODO: Move to trash still not supported */
251 modest_mail_operation_remove_msg (mail_op, header, FALSE);
252 g_object_unref (G_OBJECT (mail_op));
256 modest_ui_actions_on_delete (GtkAction *action, ModestWindow *win)
258 TnyList *header_list = NULL;
259 TnyIterator *iter = NULL;
260 TnyHeader *header = NULL;
261 gchar *message = NULL;
265 ModestWindowMgr *mgr;
266 GtkWidget *header_view;
268 g_return_if_fail (MODEST_IS_WINDOW(win));
270 /* Check first if the header view has the focus */
271 if (MODEST_IS_MAIN_WINDOW (win)) {
272 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
273 MODEST_WIDGET_TYPE_HEADER_VIEW);
274 if (!gtk_widget_is_focus (header_view))
278 header_list = get_selected_headers (win);
279 if (!header_list) return;
281 /* Check if any of the headers is already opened, or in the process of being opened */
282 iter = tny_list_create_iterator (header_list);
284 mgr = modest_runtime_get_window_mgr ();
285 while (!tny_iterator_is_done (iter) && !found) {
286 header = TNY_HEADER (tny_iterator_get_current (iter));
287 found = modest_window_mgr_find_registered_header (mgr, header, NULL);
288 g_object_unref (header);
289 tny_iterator_next (iter);
291 g_object_unref (iter);
296 num = g_strdup_printf ("%d", tny_list_get_length (header_list));
297 msg = g_strdup_printf (_("mcen_nc_unable_to_delete_n_messages"), num);
299 modest_platform_run_information_dialog (GTK_WINDOW (win), (const gchar *) msg);
303 g_object_unref (header_list);
308 if (tny_list_get_length(header_list) == 1) {
309 iter = tny_list_create_iterator (header_list);
310 header = TNY_HEADER (tny_iterator_get_current (iter));
311 desc = g_strdup_printf ("%s", tny_header_get_subject (header));
312 g_object_unref (header);
313 g_object_unref (iter);
315 message = g_strdup_printf(ngettext("emev_nc_delete_message", "emev_nc_delete_messages",
316 tny_list_get_length(header_list)), desc);
318 /* Confirmation dialog */
319 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
323 if (response == GTK_RESPONSE_OK) {
324 if (MODEST_IS_MSG_EDIT_WINDOW (win)) {
326 g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value);
330 /* Remove each header */
331 do_headers_action (win, headers_action_delete, NULL);
333 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
334 gtk_widget_destroy (GTK_WIDGET(win));
338 /* Update toolbar dimming state */
339 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (win));
344 g_object_unref (header_list);
349 modest_ui_actions_on_quit (GtkAction *action, ModestWindow *win)
351 #ifdef MODEST_PLATFORM_MAEMO
352 modest_osso_save_state();
353 #endif /* MODEST_PLATFORM_MAEMO */
355 g_debug ("closing down, clearing %d item(s) from operation queue",
356 modest_mail_operation_queue_num_elements
357 (modest_runtime_get_mail_operation_queue()));
359 /* cancel all outstanding operations */
360 modest_mail_operation_queue_cancel_all
361 (modest_runtime_get_mail_operation_queue());
363 g_debug ("queue has been cleared");
365 /* note: when modest-tny-account-store is finalized,
366 it will automatically set all network connections
373 modest_ui_actions_on_close_window (GtkAction *action, ModestWindow *win)
376 g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value);
378 /* if (MODEST_IS_MSG_VIEW_WINDOW (win)) { */
379 /* gtk_widget_destroy (GTK_WIDGET (win)); */
380 /* } else if (MODEST_IS_MSG_EDIT_WINDOW (win)) { */
381 /* gboolean ret_value; */
382 /* g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value); */
383 /* } else if (MODEST_IS_WINDOW (win)) { */
384 /* gtk_widget_destroy (GTK_WIDGET (win)); */
386 /* g_return_if_reached (); */
391 modest_ui_actions_on_add_to_contacts (GtkAction *action, ModestWindow *win)
393 GtkClipboard *clipboard = NULL;
394 gchar *selection = NULL;
396 clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
397 selection = gtk_clipboard_wait_for_text (clipboard);
399 /* Question: why is the clipboard being used here?
400 * It doesn't really make a lot of sense. */
404 modest_address_book_add_address (selection);
410 modest_ui_actions_on_accounts (GtkAction *action, ModestWindow *win)
412 /* This is currently only implemented for Maemo */
413 #ifdef MODEST_PLATFORM_MAEMO /* Defined in config.h */
414 if (!modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE)) {
415 run_account_setup_wizard (win);
418 /* Show the list of accounts: */
419 GtkDialog *account_win = GTK_DIALOG(modest_account_view_window_new ());
420 gtk_window_set_transient_for (GTK_WINDOW (account_win), GTK_WINDOW(win));
421 gtk_dialog_run (account_win);
422 gtk_widget_destroy (GTK_WIDGET(account_win));
425 GtkWidget *dialog, *label;
427 /* Create the widgets */
429 dialog = gtk_dialog_new_with_buttons ("Message",
431 GTK_DIALOG_DESTROY_WITH_PARENT,
435 label = gtk_label_new ("Hello World!");
437 /* Ensure that the dialog box is destroyed when the user responds. */
439 g_signal_connect_swapped (dialog, "response",
440 G_CALLBACK (gtk_widget_destroy),
443 /* Add the label, and show everything we've added to the dialog. */
445 gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox),
447 gtk_widget_show_all (dialog);
448 #endif /* MODEST_PLATFORM_MAEMO */
452 on_smtp_servers_window_hide (GtkWindow* window, gpointer user_data)
454 ModestWindow *main_window = MODEST_WINDOW (user_data);
456 /* Save any changes. */
457 modest_connection_specific_smtp_window_save_server_accounts (
458 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (window),
459 modest_window_get_active_account (main_window));
460 gtk_widget_destroy (GTK_WIDGET (window));
466 modest_ui_actions_on_smtp_servers (GtkAction *action, ModestWindow *win)
468 /* This is currently only implemented for Maemo,
469 * because it requires an API (libconic) to detect different connection
472 #ifdef MODEST_PLATFORM_MAEMO /* Defined in config.h */
474 /* Create the window if necessary: */
475 const gchar *active_account_name = modest_window_get_active_account (win);
477 /* TODO: Dim the menu item (not in the UI spec)? or show a warning,
478 * or show the default account?
479 * If we show the default account then the account name should be shown in
480 * the window when we show it. */
481 if (!active_account_name) {
482 g_warning ("%s: No account is active.", __FUNCTION__);
486 GtkWidget *specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
487 modest_connection_specific_smtp_window_fill_with_connections (
488 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (specific_window),
489 modest_runtime_get_account_mgr(),
490 active_account_name);
492 /* Show the window: */
493 gtk_window_set_transient_for (GTK_WINDOW (specific_window), GTK_WINDOW (win));
494 gtk_window_set_modal (GTK_WINDOW (specific_window), TRUE);
495 gtk_widget_show (specific_window);
497 /* Save changes when the window is hidden: */
498 g_signal_connect (specific_window, "hide",
499 G_CALLBACK (on_smtp_servers_window_hide), win);
500 #endif /* MODEST_PLATFORM_MAEMO */
504 modest_ui_actions_on_new_msg (GtkAction *action, ModestWindow *win)
506 ModestWindow *msg_win = NULL;
508 TnyFolder *folder = NULL;
509 gchar *account_name = NULL;
510 gchar *from_str = NULL;
511 /* GError *err = NULL; */
512 TnyAccount *account = NULL;
513 ModestWindowMgr *mgr;
514 gchar *signature = NULL, *blank_and_signature = NULL;
516 /* if there are no accounts yet, just show the wizard */
517 if (!modest_account_mgr_has_accounts (modest_runtime_get_account_mgr(), TRUE)) {
518 run_account_setup_wizard (win);
522 account_name = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr ());
524 account_name = g_strdup (modest_window_get_active_account (win));
526 g_printerr ("modest: no account found\n");
530 account = modest_tny_account_store_get_server_account (modest_runtime_get_account_store(),
532 TNY_ACCOUNT_TYPE_STORE);
534 g_printerr ("modest: failed to get tnyaccount for '%s'\n", account_name);
538 from_str = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(), account_name);
540 g_printerr ("modest: failed get from string for '%s'\n", account_name);
544 if (modest_account_mgr_get_bool (modest_runtime_get_account_mgr (), account_name,
545 MODEST_ACCOUNT_USE_SIGNATURE, FALSE)) {
546 signature = modest_account_mgr_get_string (modest_runtime_get_account_mgr (), account_name,
547 MODEST_ACCOUNT_SIGNATURE, FALSE);
548 blank_and_signature = g_strconcat ("\n", signature, NULL);
551 blank_and_signature = g_strdup ("");
554 msg = modest_tny_msg_new ("", from_str, "", "", "", blank_and_signature, NULL);
556 g_printerr ("modest: failed to create new msg\n");
560 folder = modest_tny_account_get_special_folder (account, TNY_FOLDER_TYPE_DRAFTS);
562 g_printerr ("modest: failed to find Drafts folder\n");
567 /* Create and register edit window */
568 /* This is destroyed by TOOD. */
569 msg_win = modest_msg_edit_window_new (msg, account_name);
570 mgr = modest_runtime_get_window_mgr ();
571 modest_window_mgr_register_window (mgr, msg_win);
574 gtk_window_set_transient_for (GTK_WINDOW (msg_win),
576 gtk_widget_show_all (GTK_WIDGET (msg_win));
579 g_free (account_name);
581 g_free (blank_and_signature);
583 g_object_unref (msg_win);
585 g_object_unref (G_OBJECT(account));
587 g_object_unref (G_OBJECT(msg));
589 g_object_unref (G_OBJECT(folder));
593 open_msg_cb (ModestMailOperation *mail_op,
598 ModestWindowMgr *mgr = NULL;
599 ModestWindow *parent_win = NULL;
600 ModestWindow *win = NULL;
601 TnyFolderType folder_type = TNY_FOLDER_TYPE_UNKNOWN;
602 gchar *account = NULL;
605 /* TODO: Show an error? (review the specs) */
609 parent_win = (ModestWindow *) modest_mail_operation_get_source (mail_op);
610 folder = tny_header_get_folder (header);
612 /* Mark header as read */
613 headers_action_mark_as_read (header, MODEST_WINDOW(parent_win), NULL);
616 account = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
618 account = g_strdup (modest_window_get_active_account (MODEST_WINDOW (parent_win)));
620 /* Gets folder type (OUTBOX headers will be opened in edit window */
621 if (modest_tny_folder_is_local_folder (folder))
622 folder_type = modest_tny_folder_get_local_folder_type (folder);
624 /* If the header is in the drafts folder then open the editor,
625 else the message view window */
626 if (folder_type == TNY_FOLDER_TYPE_DRAFTS) {
627 /* we cannot edit without a valid account... */
628 if (!modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE)) {
629 run_account_setup_wizard(parent_win);
632 win = modest_msg_edit_window_new (msg, account);
634 gchar *uid = modest_tny_folder_get_header_unique_id (header);
636 if (MODEST_IS_MAIN_WINDOW (parent_win)) {
637 GtkWidget *header_view;
638 GtkTreeSelection *sel;
639 GList *sel_list = NULL;
642 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(parent_win),
643 MODEST_WIDGET_TYPE_HEADER_VIEW);
645 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
646 sel_list = gtk_tree_selection_get_selected_rows (sel, &model);
648 if (sel_list != NULL) {
649 GtkTreeRowReference *row_reference;
651 row_reference = gtk_tree_row_reference_new (model, (GtkTreePath *) sel_list->data);
652 g_list_foreach (sel_list, (GFunc) gtk_tree_path_free, NULL);
653 g_list_free (sel_list);
655 win = modest_msg_view_window_new_with_header_model (msg,
660 gtk_tree_row_reference_free (row_reference);
662 win = modest_msg_view_window_new (msg, account, (const gchar*) uid);
665 win = modest_msg_view_window_new (msg, account, (const gchar*) uid);
670 /* Register and show new window */
672 mgr = modest_runtime_get_window_mgr ();
673 modest_window_mgr_register_window (mgr, win);
674 g_object_unref (win);
675 gtk_window_set_transient_for (GTK_WINDOW (win), GTK_WINDOW (parent_win));
676 gtk_widget_show_all (GTK_WIDGET(win));
679 /* Update toolbar dimming state */
680 if (MODEST_IS_MAIN_WINDOW (parent_win)) {
681 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (parent_win));
687 g_object_unref (parent_win);
688 /* g_object_unref (msg); */
689 g_object_unref (folder);
693 * This function is the error handler of the
694 * modest_mail_operation_get_msgs_full operation
697 modest_ui_actions_get_msgs_full_error_handler (ModestMailOperation *mail_op,
702 error = modest_mail_operation_get_error (mail_op);
703 if (error->code == MODEST_MAIL_OPERATION_ERROR_MESSAGE_SIZE_LIMIT) {
704 GObject *win = modest_mail_operation_get_source (mail_op);
706 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
708 g_object_unref (win);
713 * This function is used by both modest_ui_actions_on_open and
714 * modest_ui_actions_on_header_activated. This way we always do the
715 * same when trying to open messages.
718 _modest_ui_actions_open (TnyList *headers, ModestWindow *win)
720 ModestWindowMgr *mgr = NULL;
721 TnyIterator *iter = NULL;
722 ModestMailOperation *mail_op1 = NULL;
723 ModestMailOperation *mail_op2 = NULL;
724 TnyList *not_opened_headers = NULL;
725 TnyList *not_opened_cached_headers = NULL;
726 TnyHeaderFlags flags;
728 /* Look if we already have a message view for each header. If
729 true, then remove the header from the list of headers to
731 mgr = modest_runtime_get_window_mgr ();
732 iter = tny_list_create_iterator (headers);
733 not_opened_headers = tny_simple_list_new ();
734 not_opened_cached_headers = tny_simple_list_new ();
735 while (!tny_iterator_is_done (iter)) {
737 ModestWindow *window;
741 header = TNY_HEADER (tny_iterator_get_current (iter));
742 flags = tny_header_get_flags (header);
745 found = modest_window_mgr_find_registered_header (mgr, header, &window);
747 /* Do not open again the message and present the
748 window to the user */
751 gtk_window_present (GTK_WINDOW (window));
753 /* the header has been registered already, we don't do
754 * anything but wait for the window to come up*/
755 g_warning ("debug: header %p already registered, waiting for window",
758 /* register the header before actually creating the window */
759 modest_window_mgr_register_header (mgr, header);
761 if (!(flags & TNY_HEADER_FLAG_CACHED))
762 tny_list_append (not_opened_headers, G_OBJECT (header));
763 /* Check if msg has already been retreived */
765 tny_list_append (not_opened_cached_headers, G_OBJECT (header));
767 g_object_unref (header);
768 tny_iterator_next (iter);
771 /* Open each uncached message */
772 if (tny_list_get_length (not_opened_headers) > 0) {
773 mail_op1 = modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE,
775 modest_ui_actions_get_msgs_full_error_handler,
777 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op1);
778 if (tny_list_get_length (not_opened_headers) > 1) {
779 modest_mail_operation_get_msgs_full (mail_op1,
785 TnyIterator *iter = tny_list_create_iterator (not_opened_headers);
786 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter));
787 modest_mail_operation_get_msg (mail_op1, header, open_msg_cb, NULL);
788 g_object_unref (header);
789 g_object_unref (iter);
793 /* Open each cached message */
794 if (tny_list_get_length (not_opened_cached_headers) > 0) {
795 mail_op2 = modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_OPEN,
797 modest_ui_actions_get_msgs_full_error_handler,
799 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op2);
800 if (tny_list_get_length (not_opened_cached_headers) > 1) {
801 modest_mail_operation_get_msgs_full (mail_op2,
807 TnyIterator *iter = tny_list_create_iterator (not_opened_cached_headers);
808 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter));
809 modest_mail_operation_get_msg (mail_op2, header, open_msg_cb, NULL);
810 g_object_unref (header);
811 g_object_unref (iter);
816 if (not_opened_headers != NULL)
817 g_object_unref (not_opened_headers);
818 if (not_opened_cached_headers != NULL)
819 g_object_unref (not_opened_cached_headers);
821 g_object_unref (iter);
822 if (mail_op1 != NULL)
823 g_object_unref (mail_op1);
824 if (mail_op2 != NULL)
825 g_object_unref (mail_op2);
829 modest_ui_actions_on_open (GtkAction *action, ModestWindow *win)
834 headers = get_selected_headers (win);
839 _modest_ui_actions_open (headers, win);
841 g_object_unref(headers);
846 free_reply_forward_helper (gpointer data)
848 ReplyForwardHelper *helper;
850 helper = (ReplyForwardHelper *) data;
851 g_free (helper->account_name);
852 g_slice_free (ReplyForwardHelper, helper);
856 reply_forward_cb (ModestMailOperation *mail_op,
862 ReplyForwardHelper *rf_helper;
863 ModestWindow *msg_win = NULL;
864 ModestEditType edit_type;
866 TnyAccount *account = NULL;
867 ModestWindowMgr *mgr = NULL;
868 gchar *signature = NULL;
870 g_return_if_fail (user_data != NULL);
871 rf_helper = (ReplyForwardHelper *) user_data;
873 from = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(),
874 rf_helper->account_name);
875 if (modest_account_mgr_get_bool (modest_runtime_get_account_mgr(),
876 rf_helper->account_name,
877 MODEST_ACCOUNT_USE_SIGNATURE, FALSE)) {
878 signature = modest_account_mgr_get_string (modest_runtime_get_account_mgr (),
879 rf_helper->account_name,
880 MODEST_ACCOUNT_SIGNATURE, FALSE);
883 /* Create reply mail */
884 switch (rf_helper->action) {
887 modest_tny_msg_create_reply_msg (msg, from, signature,
888 rf_helper->reply_forward_type,
889 MODEST_TNY_MSG_REPLY_MODE_SENDER);
891 case ACTION_REPLY_TO_ALL:
893 modest_tny_msg_create_reply_msg (msg, from, signature, rf_helper->reply_forward_type,
894 MODEST_TNY_MSG_REPLY_MODE_ALL);
895 edit_type = MODEST_EDIT_TYPE_REPLY;
899 modest_tny_msg_create_forward_msg (msg, from, signature, rf_helper->reply_forward_type);
900 edit_type = MODEST_EDIT_TYPE_FORWARD;
903 g_return_if_reached ();
910 g_printerr ("modest: failed to create message\n");
914 account = modest_tny_account_store_get_server_account (modest_runtime_get_account_store(),
915 rf_helper->account_name,
916 TNY_ACCOUNT_TYPE_STORE);
918 g_printerr ("modest: failed to get tnyaccount for '%s'\n", rf_helper->account_name);
922 /* Create and register the windows */
923 msg_win = modest_msg_edit_window_new (new_msg, rf_helper->account_name);
924 mgr = modest_runtime_get_window_mgr ();
925 modest_window_mgr_register_window (mgr, msg_win);
927 if (rf_helper->parent_window != NULL) {
930 parent_zoom = modest_window_get_zoom (MODEST_WINDOW (rf_helper->parent_window));
931 modest_window_set_zoom (msg_win, parent_zoom);
934 /* Show edit window */
935 gtk_widget_show_all (GTK_WIDGET (msg_win));
939 g_object_unref (msg_win);
941 g_object_unref (G_OBJECT (new_msg));
943 g_object_unref (G_OBJECT (account));
944 /* g_object_unref (msg); */
945 g_object_unref (header);
949 * Checks a list of headers. If any of them are not currently
950 * downloaded (CACHED) then it asks the user for permission to
953 * Returns FALSE if the user does not want to download the
954 * messages. Returns TRUE if the user allowed the download or if all
955 * of them are currently downloaded
958 download_uncached_messages (TnyList *header_list, GtkWindow *win)
962 gint uncached_messages = 0;
964 iter = tny_list_create_iterator (header_list);
965 while (!tny_iterator_is_done (iter)) {
967 TnyHeaderFlags flags;
969 header = TNY_HEADER (tny_iterator_get_current (iter));
970 flags = tny_header_get_flags (header);
971 /* TODO: is this the right flag?, it seems that some
972 headers that have been previously downloaded do not
974 if (! (flags & TNY_HEADER_FLAG_CACHED))
975 uncached_messages ++;
976 g_object_unref (header);
977 tny_iterator_next (iter);
979 g_object_unref (iter);
981 /* Ask for user permission to download the messages */
983 if (uncached_messages > 0) {
984 GtkResponseType response;
986 modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
987 ngettext("mcen_nc_get_msg",
990 if (response == GTK_RESPONSE_CANCEL)
998 * Common code for the reply and forward actions
1001 reply_forward (ReplyForwardAction action, ModestWindow *win)
1003 ModestMailOperation *mail_op = NULL;
1004 TnyList *header_list = NULL;
1005 ReplyForwardHelper *rf_helper = NULL;
1006 guint reply_forward_type;
1007 gboolean continue_download;
1009 g_return_if_fail (MODEST_IS_WINDOW(win));
1011 /* we need an account when editing */
1012 if (!modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE)) {
1013 run_account_setup_wizard (win);
1017 header_list = get_selected_headers (win);
1021 /* Check that the messages have been previously downloaded */
1022 continue_download = download_uncached_messages (header_list, GTK_WINDOW (win));
1023 if (!continue_download) {
1024 g_object_unref (header_list);
1028 reply_forward_type =
1029 modest_conf_get_int (modest_runtime_get_conf (),
1030 (action == ACTION_FORWARD) ? MODEST_CONF_FORWARD_TYPE : MODEST_CONF_REPLY_TYPE,
1032 /* We assume that we can only select messages of the
1033 same folder and that we reply all of them from the
1034 same account. In fact the interface currently only
1035 allows single selection */
1038 rf_helper = g_slice_new0 (ReplyForwardHelper);
1039 rf_helper->reply_forward_type = reply_forward_type;
1040 rf_helper->action = action;
1041 rf_helper->account_name = g_strdup (modest_window_get_active_account (win));
1042 if ((win != NULL) && (MODEST_IS_WINDOW (win)))
1043 rf_helper->parent_window = GTK_WIDGET (win);
1044 if (!rf_helper->account_name)
1045 rf_helper->account_name =
1046 modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
1048 if (MODEST_IS_MSG_VIEW_WINDOW(win)) {
1051 /* Get header and message. Do not free them here, the
1052 reply_forward_cb must do it */
1053 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW(win));
1054 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW(win));
1055 if (!msg || !header) {
1057 g_object_unref (msg);
1059 g_object_unref (header);
1060 g_printerr ("modest: no message found\n");
1063 reply_forward_cb (NULL, header, msg, rf_helper);
1065 /* Retrieve messages */
1066 mail_op = modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE,
1068 modest_ui_actions_get_msgs_full_error_handler,
1070 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
1071 modest_mail_operation_get_msgs_full (mail_op,
1075 free_reply_forward_helper);
1078 g_object_unref(mail_op);
1082 g_object_unref (header_list);
1086 modest_ui_actions_on_reply (GtkAction *action, ModestWindow *win)
1088 g_return_if_fail (MODEST_IS_WINDOW(win));
1090 reply_forward (ACTION_REPLY, win);
1094 modest_ui_actions_on_forward (GtkAction *action, ModestWindow *win)
1096 g_return_if_fail (MODEST_IS_WINDOW(win));
1098 reply_forward (ACTION_FORWARD, win);
1102 modest_ui_actions_on_reply_all (GtkAction *action, ModestWindow *win)
1104 g_return_if_fail (MODEST_IS_WINDOW(win));
1106 reply_forward (ACTION_REPLY_TO_ALL, win);
1110 modest_ui_actions_on_next (GtkAction *action,
1111 ModestWindow *window)
1113 if (MODEST_IS_MAIN_WINDOW (window)) {
1114 GtkWidget *header_view;
1116 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
1117 MODEST_WIDGET_TYPE_HEADER_VIEW);
1121 modest_header_view_select_next (MODEST_HEADER_VIEW(header_view));
1122 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
1123 modest_msg_view_window_select_next_message (MODEST_MSG_VIEW_WINDOW (window));
1125 g_return_if_reached ();
1130 modest_ui_actions_on_prev (GtkAction *action,
1131 ModestWindow *window)
1133 g_return_if_fail (MODEST_IS_WINDOW(window));
1135 if (MODEST_IS_MAIN_WINDOW (window)) {
1136 GtkWidget *header_view;
1137 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
1138 MODEST_WIDGET_TYPE_HEADER_VIEW);
1142 modest_header_view_select_prev (MODEST_HEADER_VIEW(header_view));
1143 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
1144 modest_msg_view_window_select_previous_message (MODEST_MSG_VIEW_WINDOW (window));
1146 g_return_if_reached ();
1151 modest_ui_actions_on_sort (GtkAction *action,
1152 ModestWindow *window)
1154 g_return_if_fail (MODEST_IS_WINDOW(window));
1156 if (MODEST_IS_MAIN_WINDOW (window)) {
1157 GtkWidget *header_view;
1158 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
1159 MODEST_WIDGET_TYPE_HEADER_VIEW);
1163 /* Show sorting dialog */
1164 modest_platform_run_sort_dialog (GTK_WINDOW (window), MODEST_SORT_HEADERS);
1169 new_messages_arrived (ModestMailOperation *self,
1173 if (new_messages == 0)
1176 modest_platform_on_new_msg ();
1180 * This function performs the send & receive required actions. The
1181 * window is used to create the mail operation. Typically it should
1182 * always be the main window, but we pass it as argument in order to
1186 modest_ui_actions_do_send_receive (const gchar *account_name, ModestWindow *win)
1188 gchar *acc_name = NULL;
1189 ModestMailOperation *mail_op;
1191 /* If no account name was provided then get the current account, and if
1192 there is no current account then pick the default one: */
1193 if (!account_name) {
1194 acc_name = g_strdup (modest_window_get_active_account(win));
1196 acc_name = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
1198 g_printerr ("modest: cannot get default account\n");
1202 acc_name = g_strdup (account_name);
1205 /* Set send/receive operation in progress */
1206 modest_main_window_notify_send_receive_initied (MODEST_MAIN_WINDOW(win));
1208 /* mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_RECEIVE, G_OBJECT(win)); */
1209 mail_op = modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_OPEN,
1211 modest_ui_actions_send_receive_error_handler,
1214 g_signal_connect (G_OBJECT(mail_op), "progress-changed",
1215 G_CALLBACK (_on_send_receive_progress_changed),
1218 /* Send & receive. */
1219 /* TODO: The spec wants us to first do any pending deletions, before receiving. */
1220 /* Receive and then send. The operation is tagged initially as
1221 a receive operation because the account update performs a
1222 receive and then a send. The operation changes its type
1223 internally, so the progress objects will receive the proper
1224 progress information */
1225 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
1226 modest_mail_operation_update_account (mail_op, acc_name, new_messages_arrived, NULL);
1227 g_object_unref (G_OBJECT (mail_op));
1234 * Refreshes all accounts. This function will be used by automatic
1238 modest_ui_actions_do_send_receive_all (ModestWindow *win)
1240 GSList *account_names, *iter;
1242 account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
1245 iter = account_names;
1247 modest_ui_actions_do_send_receive ((const char*) iter->data, win);
1248 iter = g_slist_next (iter);
1251 modest_account_mgr_free_account_names (account_names);
1252 account_names = NULL;
1256 * Handler of the click on Send&Receive button in the main toolbar
1259 modest_ui_actions_on_send_receive (GtkAction *action, ModestWindow *win)
1261 /* Check if accounts exist */
1262 gboolean accounts_exist =
1263 modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
1265 /* If not, allow the user to create an account before trying to send/receive. */
1266 if (!accounts_exist)
1267 modest_ui_actions_on_accounts (NULL, win);
1269 /* Refresh the active account */
1270 modest_ui_actions_do_send_receive (NULL, win);
1275 modest_ui_actions_toggle_header_list_view (GtkAction *action, ModestMainWindow *main_window)
1278 GtkWidget *header_view;
1280 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1282 header_view = modest_main_window_get_child_widget (main_window,
1283 MODEST_WIDGET_TYPE_HEADER_VIEW);
1287 conf = modest_runtime_get_conf ();
1289 /* what is saved/restored is depending on the style; thus; we save with
1290 * old style, then update the style, and restore for this new style
1292 modest_widget_memory_save (conf, G_OBJECT(header_view), MODEST_CONF_HEADER_VIEW_KEY);
1294 if (modest_header_view_get_style
1295 (MODEST_HEADER_VIEW(header_view)) == MODEST_HEADER_VIEW_STYLE_DETAILS)
1296 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
1297 MODEST_HEADER_VIEW_STYLE_TWOLINES);
1299 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
1300 MODEST_HEADER_VIEW_STYLE_DETAILS);
1302 modest_widget_memory_restore (conf, G_OBJECT(header_view),
1303 MODEST_CONF_HEADER_VIEW_KEY);
1308 modest_ui_actions_on_header_selected (ModestHeaderView *header_view,
1310 ModestMainWindow *main_window)
1312 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1313 g_return_if_fail (MODEST_IS_HEADER_VIEW (header_view));
1315 /* If no header has been selected then exit */
1320 if (!gtk_widget_is_focus (GTK_WIDGET(header_view)))
1321 gtk_widget_grab_focus (GTK_WIDGET(header_view));
1323 /* Update Main window title */
1324 if (gtk_widget_is_focus (GTK_WIDGET(header_view))) {
1325 const gchar *subject = tny_header_get_subject (header);
1326 if (subject && strlen(subject) > 0)
1327 gtk_window_set_title (GTK_WINDOW (main_window), subject);
1329 gtk_window_set_title (GTK_WINDOW (main_window), _("mail_va_no_subject"));
1332 /* Update toolbar dimming state */
1333 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
1337 modest_ui_actions_on_header_activated (ModestHeaderView *header_view,
1339 ModestMainWindow *main_window)
1343 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1348 headers = tny_simple_list_new ();
1349 tny_list_prepend (headers, G_OBJECT (header));
1351 _modest_ui_actions_open (headers, MODEST_WINDOW (main_window));
1353 g_object_unref (headers);
1357 set_active_account_from_tny_account (TnyAccount *account,
1358 ModestWindow *window)
1360 const gchar *server_acc_name = tny_account_get_id (account);
1362 /* We need the TnyAccount provided by the
1363 account store because that is the one that
1364 knows the name of the Modest account */
1365 TnyAccount *modest_server_account = modest_server_account =
1366 modest_tny_account_store_get_tny_account_by (modest_runtime_get_account_store (),
1367 MODEST_TNY_ACCOUNT_STORE_QUERY_ID,
1370 const gchar *modest_acc_name =
1371 modest_tny_account_get_parent_modest_account_name_for_server_account (modest_server_account);
1372 modest_window_set_active_account (window, modest_acc_name);
1373 g_object_unref (modest_server_account);
1378 folder_refreshed_cb (const GObject *obj,
1382 ModestMainWindow *win = NULL;
1383 GtkWidget *header_view;
1385 g_return_if_fail (TNY_IS_FOLDER (folder));
1387 win = MODEST_MAIN_WINDOW (user_data);
1389 modest_main_window_get_child_widget(win, MODEST_WIDGET_TYPE_HEADER_VIEW);
1391 /* Check if folder is empty and set headers view contents style */
1392 if (tny_folder_get_all_count (folder) == 0) {
1393 printf ("DEBUG: %s: tny_folder_get_all_count() returned 0.\n", __FUNCTION__);
1394 modest_main_window_set_contents_style (win,
1395 MODEST_MAIN_WINDOW_CONTENTS_STYLE_EMPTY);
1397 printf ("DEBUG: %s: tny_folder_get_all_count() returned >0.\n", __FUNCTION__);
1402 modest_ui_actions_on_folder_selection_changed (ModestFolderView *folder_view,
1403 TnyFolderStore *folder_store,
1405 ModestMainWindow *main_window)
1408 GtkWidget *header_view;
1410 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1412 header_view = modest_main_window_get_child_widget(main_window,
1413 MODEST_WIDGET_TYPE_HEADER_VIEW);
1417 conf = modest_runtime_get_conf ();
1419 if (TNY_IS_ACCOUNT (folder_store)) {
1421 /* Update active account */
1422 set_active_account_from_tny_account (TNY_ACCOUNT (folder_store), MODEST_WINDOW (main_window));
1423 /* Show account details */
1424 modest_main_window_set_contents_style (main_window, MODEST_MAIN_WINDOW_CONTENTS_STYLE_DETAILS);
1427 if (TNY_IS_FOLDER (folder_store) && selected) {
1429 /* Update the active account */
1430 TnyAccount *account = modest_tny_folder_get_account (TNY_FOLDER (folder_store));
1432 set_active_account_from_tny_account (account, MODEST_WINDOW (main_window));
1433 g_object_unref (account);
1437 /* Set the header style by default, it could
1438 be changed later by the refresh callback to
1440 modest_main_window_set_contents_style (main_window,
1441 MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS);
1443 /* Set folder on header view. This function
1444 will call tny_folder_refresh_async so we
1445 pass a callback that will be called when
1446 finished. We use that callback to set the
1447 empty view if there are no messages */
1448 modest_header_view_set_folder (MODEST_HEADER_VIEW(header_view),
1449 TNY_FOLDER (folder_store),
1450 folder_refreshed_cb,
1453 /* Restore configuration. We need to do this
1454 *after* the set_folder because the widget
1455 memory asks the header view about its
1457 modest_widget_memory_restore (modest_runtime_get_conf (),
1458 G_OBJECT(header_view),
1459 MODEST_CONF_HEADER_VIEW_KEY);
1461 /* Update the active account */
1462 modest_window_set_active_account (MODEST_WINDOW (main_window), NULL);
1463 /* Save only if we're seeing headers */
1464 if (modest_main_window_get_contents_style (main_window) ==
1465 MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS)
1466 modest_widget_memory_save (conf, G_OBJECT (header_view),
1467 MODEST_CONF_HEADER_VIEW_KEY);
1468 modest_header_view_clear (MODEST_HEADER_VIEW(header_view));
1472 /* Update toolbar dimming state */
1473 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
1477 modest_ui_actions_on_item_not_found (ModestHeaderView *header_view,ModestItemType type,
1484 item = (type == MODEST_ITEM_TYPE_FOLDER) ? "folder" : "message";
1486 online = tny_device_is_online (modest_runtime_get_device());
1489 /* already online -- the item is simply not there... */
1490 dialog = gtk_message_dialog_new (GTK_WINDOW (win),
1492 GTK_MESSAGE_WARNING,
1494 _("The %s you selected cannot be found"),
1496 gtk_dialog_run (GTK_DIALOG(dialog));
1498 dialog = gtk_dialog_new_with_buttons (_("Connection requested"),
1502 GTK_RESPONSE_REJECT,
1504 GTK_RESPONSE_ACCEPT,
1506 txt = g_strdup_printf (_("This %s is not available in offline mode.\n"
1507 "Do you want to get online?"), item);
1508 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
1509 gtk_label_new (txt), FALSE, FALSE, 0);
1510 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
1513 gtk_window_set_default_size (GTK_WINDOW(dialog), 300, 300);
1514 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
1515 // modest_platform_connect_and_wait ();
1518 gtk_widget_destroy (dialog);
1522 modest_ui_actions_on_msg_link_hover (ModestMsgView *msgview, const gchar* link,
1525 /* g_message ("%s %s", __FUNCTION__, link); */
1530 modest_ui_actions_on_msg_link_clicked (ModestMsgView *msgview, const gchar* link,
1533 modest_platform_activate_uri (link);
1537 modest_ui_actions_on_msg_link_contextual (ModestMsgView *msgview, const gchar* link,
1540 modest_platform_show_uri_popup (link);
1544 modest_ui_actions_on_msg_attachment_clicked (ModestMsgView *msgview, TnyMimePart *mime_part,
1547 modest_msg_view_window_view_attachment (MODEST_MSG_VIEW_WINDOW (win), mime_part);
1551 modest_ui_actions_on_msg_recpt_activated (ModestMsgView *msgview,
1552 const gchar *address,
1555 /* g_message ("%s %s", __FUNCTION__, address); */
1559 modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edit_window)
1561 TnyTransportAccount *transport_account;
1562 ModestMailOperation *mail_operation;
1564 gchar *account_name, *from;
1565 ModestAccountMgr *account_mgr;
1566 gchar *info_text = NULL;
1568 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window));
1570 data = modest_msg_edit_window_get_msg_data (edit_window);
1572 account_mgr = modest_runtime_get_account_mgr();
1573 account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
1575 account_name = modest_account_mgr_get_default_account (account_mgr);
1576 if (!account_name) {
1577 g_printerr ("modest: no account found\n");
1578 modest_msg_edit_window_free_msg_data (edit_window, data);
1582 if (!strcmp (account_name, MODEST_LOCAL_FOLDERS_ACCOUNT_ID)) {
1583 account_name = g_strdup (data->account_name);
1587 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
1588 (modest_runtime_get_account_store(),
1590 TNY_ACCOUNT_TYPE_TRANSPORT));
1591 if (!transport_account) {
1592 g_printerr ("modest: no transport account found for '%s'\n", account_name);
1593 g_free (account_name);
1594 modest_msg_edit_window_free_msg_data (edit_window, data);
1597 from = modest_account_mgr_get_from_string (account_mgr, account_name);
1599 /* Create the mail operation */
1600 mail_operation = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_INFO, G_OBJECT(edit_window));
1601 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
1603 modest_mail_operation_save_to_drafts (mail_operation,
1614 data->priority_flags);
1617 g_free (account_name);
1618 g_object_unref (G_OBJECT (transport_account));
1619 g_object_unref (G_OBJECT (mail_operation));
1621 modest_msg_edit_window_free_msg_data (edit_window, data);
1623 info_text = g_strdup_printf (_("mail_va_saved_to_drafts"), _("mcen_me_folder_drafts"));
1624 modest_platform_information_banner (NULL, NULL, info_text);
1628 /* For instance, when clicking the Send toolbar button when editing a message: */
1630 modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
1632 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window));
1634 if (!modest_msg_edit_window_check_names (edit_window))
1637 /* FIXME: Code added just for testing. The final version will
1638 use the send queue provided by tinymail and some
1640 ModestAccountMgr *account_mgr = modest_runtime_get_account_mgr();
1641 gchar *account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
1643 account_name = modest_account_mgr_get_default_account (account_mgr);
1645 if (!account_name) {
1646 g_printerr ("modest: no account found\n");
1650 MsgData *data = modest_msg_edit_window_get_msg_data (edit_window);
1652 if (!strcmp (account_name, MODEST_LOCAL_FOLDERS_ACCOUNT_ID)) {
1653 account_name = g_strdup (data->account_name);
1656 /* Get the currently-active transport account for this modest account: */
1657 TnyTransportAccount *transport_account =
1658 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_transport_account_for_open_connection
1659 (modest_runtime_get_account_store(),
1661 if (!transport_account) {
1662 g_printerr ("modest: no transport account found for '%s'\n", account_name);
1663 g_free (account_name);
1664 modest_msg_edit_window_free_msg_data (edit_window, data);
1668 gchar *from = modest_account_mgr_get_from_string (account_mgr, account_name);
1670 /* mail content checks and dialogs */
1671 if (data->subject == NULL || data->subject[0] == '\0') {
1672 GtkResponseType response;
1673 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (edit_window),
1674 _("mcen_nc_subject_is_empty_send"));
1675 if (response == GTK_RESPONSE_CANCEL) {
1676 g_free (account_name);
1681 if (data->plain_body == NULL || data->plain_body[0] == '\0') {
1682 GtkResponseType response;
1683 gchar *note_message;
1684 gchar *note_subject = data->subject;
1685 if (note_subject == NULL || note_subject[0] == '\0')
1686 note_subject = _("mail_va_no_subject");
1687 note_message = g_strdup_printf (_("emev_ni_ui_smtp_message_null"), note_subject);
1688 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (edit_window),
1690 g_free (note_message);
1691 if (response == GTK_RESPONSE_CANCEL) {
1692 g_free (account_name);
1697 modest_platform_information_banner (NULL, NULL, _("mcen_ib_outbox_waiting_to_be_sent"));
1699 /* Create the mail operation */
1700 ModestMailOperation *mail_operation = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_SEND, G_OBJECT(edit_window));
1701 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
1703 modest_mail_operation_send_new_mail (mail_operation,
1714 data->priority_flags);
1718 g_free (account_name);
1719 g_object_unref (G_OBJECT (transport_account));
1720 g_object_unref (G_OBJECT (mail_operation));
1722 modest_msg_edit_window_free_msg_data (edit_window, data);
1723 modest_msg_edit_window_set_sent (edit_window, TRUE);
1725 /* Save settings and close the window: */
1726 gtk_widget_destroy (GTK_WIDGET (edit_window));
1730 modest_ui_actions_on_toggle_bold (GtkToggleAction *action,
1731 ModestMsgEditWindow *window)
1733 ModestMsgEditFormatState *format_state = NULL;
1735 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1736 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
1738 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
1741 format_state = modest_msg_edit_window_get_format_state (window);
1742 g_return_if_fail (format_state != NULL);
1744 format_state->bold = gtk_toggle_action_get_active (action);
1745 modest_msg_edit_window_set_format_state (window, format_state);
1746 g_free (format_state);
1751 modest_ui_actions_on_toggle_italics (GtkToggleAction *action,
1752 ModestMsgEditWindow *window)
1754 ModestMsgEditFormatState *format_state = NULL;
1756 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1757 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
1759 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
1762 format_state = modest_msg_edit_window_get_format_state (window);
1763 g_return_if_fail (format_state != NULL);
1765 format_state->italics = gtk_toggle_action_get_active (action);
1766 modest_msg_edit_window_set_format_state (window, format_state);
1767 g_free (format_state);
1772 modest_ui_actions_on_toggle_bullets (GtkToggleAction *action,
1773 ModestMsgEditWindow *window)
1775 ModestMsgEditFormatState *format_state = NULL;
1777 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1778 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
1780 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
1783 format_state = modest_msg_edit_window_get_format_state (window);
1784 g_return_if_fail (format_state != NULL);
1786 format_state->bullet = gtk_toggle_action_get_active (action);
1787 modest_msg_edit_window_set_format_state (window, format_state);
1788 g_free (format_state);
1793 modest_ui_actions_on_change_justify (GtkRadioAction *action,
1794 GtkRadioAction *selected,
1795 ModestMsgEditWindow *window)
1797 ModestMsgEditFormatState *format_state = NULL;
1798 GtkJustification value;
1800 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1802 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
1805 value = gtk_radio_action_get_current_value (selected);
1807 format_state = modest_msg_edit_window_get_format_state (window);
1808 g_return_if_fail (format_state != NULL);
1810 format_state->justification = value;
1811 modest_msg_edit_window_set_format_state (window, format_state);
1812 g_free (format_state);
1816 modest_ui_actions_on_select_editor_color (GtkAction *action,
1817 ModestMsgEditWindow *window)
1819 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1820 g_return_if_fail (GTK_IS_ACTION (action));
1822 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
1825 modest_msg_edit_window_select_color (window);
1829 modest_ui_actions_on_select_editor_background_color (GtkAction *action,
1830 ModestMsgEditWindow *window)
1832 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1833 g_return_if_fail (GTK_IS_ACTION (action));
1835 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
1838 modest_msg_edit_window_select_background_color (window);
1842 modest_ui_actions_on_insert_image (GtkAction *action,
1843 ModestMsgEditWindow *window)
1845 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1846 g_return_if_fail (GTK_IS_ACTION (action));
1848 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
1851 modest_msg_edit_window_insert_image (window);
1855 modest_ui_actions_on_attach_file (GtkAction *action,
1856 ModestMsgEditWindow *window)
1858 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1859 g_return_if_fail (GTK_IS_ACTION (action));
1861 modest_msg_edit_window_attach_file (window);
1865 modest_ui_actions_on_remove_attachments (GtkAction *action,
1866 ModestMsgEditWindow *window)
1868 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1869 g_return_if_fail (GTK_IS_ACTION (action));
1871 modest_msg_edit_window_remove_attachments (window, NULL);
1875 modest_ui_actions_on_new_folder (GtkAction *action, ModestMainWindow *main_window)
1877 TnyFolderStore *parent_folder;
1878 GtkWidget *folder_view;
1880 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1882 folder_view = modest_main_window_get_child_widget (main_window,
1883 MODEST_WIDGET_TYPE_FOLDER_VIEW);
1887 parent_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
1889 if (parent_folder) {
1890 gboolean finished = FALSE;
1892 gchar *folder_name = NULL, *suggested_name = NULL;
1894 /* Run the new folder dialog */
1896 result = modest_platform_run_new_folder_dialog (GTK_WINDOW (main_window),
1901 if (result == GTK_RESPONSE_REJECT) {
1904 ModestMailOperation *mail_op;
1905 TnyFolder *new_folder = NULL;
1907 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_INFO,
1908 G_OBJECT(main_window));
1909 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
1911 new_folder = modest_mail_operation_create_folder (mail_op,
1913 (const gchar *) folder_name);
1915 g_object_unref (new_folder);
1918 g_object_unref (mail_op);
1920 g_free (folder_name);
1924 g_object_unref (parent_folder);
1929 modest_ui_actions_rename_folder_error_handler (ModestMailOperation *mail_op,
1932 GObject *win = modest_mail_operation_get_source (mail_op);
1934 /* TODO: what should we do in case of this error ? */
1935 g_warning ("Invalid folder name");
1937 g_object_unref (win);
1941 modest_ui_actions_on_rename_folder (GtkAction *action,
1942 ModestMainWindow *main_window)
1944 TnyFolderStore *folder;
1945 GtkWidget *folder_view;
1946 GtkWidget *header_view;
1948 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1950 folder_view = modest_main_window_get_child_widget (main_window,
1951 MODEST_WIDGET_TYPE_FOLDER_VIEW);
1955 header_view = modest_main_window_get_child_widget (main_window,
1956 MODEST_WIDGET_TYPE_HEADER_VIEW);
1961 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
1963 if (folder && TNY_IS_FOLDER (folder)) {
1966 const gchar *current_name;
1968 current_name = tny_folder_get_name (TNY_FOLDER (folder));
1969 response = modest_platform_run_rename_folder_dialog (GTK_WINDOW (main_window), NULL,
1970 current_name, &folder_name);
1972 if (response == GTK_RESPONSE_ACCEPT && strlen (folder_name) > 0) {
1973 ModestMailOperation *mail_op;
1976 modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_INFO,
1977 G_OBJECT(main_window),
1978 modest_ui_actions_rename_folder_error_handler,
1982 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
1985 modest_header_view_clear (MODEST_HEADER_VIEW (header_view));
1987 modest_mail_operation_rename_folder (mail_op,
1988 TNY_FOLDER (folder),
1989 (const gchar *) folder_name);
1991 g_object_unref (mail_op);
1992 g_free (folder_name);
1994 g_object_unref (folder);
1999 modest_ui_actions_delete_folder_error_handler (ModestMailOperation *mail_op,
2002 GObject *win = modest_mail_operation_get_source (mail_op);
2004 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
2005 _("mail_in_ui_folder_delete_error"));
2006 g_object_unref (win);
2010 delete_folder (ModestMainWindow *main_window, gboolean move_to_trash)
2012 TnyFolderStore *folder;
2013 GtkWidget *folder_view;
2017 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2019 folder_view = modest_main_window_get_child_widget (main_window,
2020 MODEST_WIDGET_TYPE_FOLDER_VIEW);
2024 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
2026 /* Show an error if it's an account */
2027 if (!TNY_IS_FOLDER (folder)) {
2028 modest_platform_run_information_dialog (GTK_WINDOW (main_window),
2029 _("mail_in_ui_folder_delete_error"));
2034 message = g_strdup_printf (_("mcen_nc_delete_folder_text"),
2035 tny_folder_get_name (TNY_FOLDER (folder)));
2036 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (main_window),
2037 (const gchar *) message);
2040 if (response == GTK_RESPONSE_OK) {
2041 ModestMailOperation *mail_op =
2042 modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_DELETE,
2043 G_OBJECT(main_window),
2044 modest_ui_actions_delete_folder_error_handler,
2047 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
2049 modest_mail_operation_remove_folder (mail_op, TNY_FOLDER (folder), move_to_trash);
2050 g_object_unref (G_OBJECT (mail_op));
2053 g_object_unref (G_OBJECT (folder));
2057 modest_ui_actions_on_delete_folder (GtkAction *action,
2058 ModestMainWindow *main_window)
2060 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2062 delete_folder (main_window, FALSE);
2066 modest_ui_actions_on_move_folder_to_trash_folder (GtkAction *action, ModestMainWindow *main_window)
2068 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2070 delete_folder (main_window, TRUE);
2074 modest_ui_actions_on_password_requested (TnyAccountStore *account_store,
2075 const gchar* server_account_name,
2080 ModestMainWindow *main_window)
2082 g_return_if_fail(server_account_name);
2083 /* printf("DEBUG: %s: server_account_name=%s\n", __FUNCTION__, server_account_name); */
2085 /* Initalize output parameters: */
2092 #ifdef MODEST_PLATFORM_MAEMO
2093 /* Maemo uses a different (awkward) button order,
2094 * It should probably just use gtk_alternative_dialog_button_order ().
2096 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
2100 GTK_RESPONSE_ACCEPT,
2102 GTK_RESPONSE_REJECT,
2105 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
2109 GTK_RESPONSE_REJECT,
2111 GTK_RESPONSE_ACCEPT,
2113 #endif /* MODEST_PLATFORM_MAEMO */
2115 gtk_window_set_transient_for (GTK_WINDOW(dialog), GTK_WINDOW(main_window));
2117 gchar *server_name = modest_server_account_get_hostname (
2118 modest_runtime_get_account_mgr(), server_account_name);
2119 if (!server_name) {/* This happened once, though I don't know why. murrayc. */
2120 g_warning("%s: Could not get server name for server account '%s'", __FUNCTION__, server_account_name);
2125 /* This causes a warning because the logical ID has no %s in it,
2126 * though the translation does, but there is not much we can do about that: */
2127 gchar *txt = g_strdup_printf (_("mail_ia_password_info"), server_name);
2128 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), gtk_label_new(txt),
2131 g_free (server_name);
2135 gchar *initial_username = modest_server_account_get_username (
2136 modest_runtime_get_account_mgr(), server_account_name);
2138 GtkWidget *entry_username = gtk_entry_new ();
2139 if (initial_username)
2140 gtk_entry_set_text (GTK_ENTRY (entry_username), initial_username);
2141 /* Dim this if a connection has ever succeeded with this username,
2142 * as per the UI spec: */
2143 const gboolean username_known =
2144 modest_server_account_get_username_has_succeeded(
2145 modest_runtime_get_account_mgr(), server_account_name);
2146 gtk_widget_set_sensitive (entry_username, !username_known);
2148 #ifdef MODEST_PLATFORM_MAEMO
2149 /* Auto-capitalization is the default, so let's turn it off: */
2150 hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_username), HILDON_GTK_INPUT_MODE_FULL);
2152 /* Create a size group to be used by all captions.
2153 * Note that HildonCaption does not create a default size group if we do not specify one.
2154 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
2155 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
2157 GtkWidget *caption = hildon_caption_new (sizegroup,
2158 _("mail_fi_username"), entry_username, NULL, HILDON_CAPTION_MANDATORY);
2159 gtk_widget_show (entry_username);
2160 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
2161 FALSE, FALSE, MODEST_MARGIN_HALF);
2162 gtk_widget_show (caption);
2164 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry_username,
2166 #endif /* MODEST_PLATFORM_MAEMO */
2169 GtkWidget *entry_password = gtk_entry_new ();
2170 gtk_entry_set_visibility (GTK_ENTRY(entry_password), FALSE);
2171 /* gtk_entry_set_invisible_char (GTK_ENTRY(entry_password), "*"); */
2173 #ifdef MODEST_PLATFORM_MAEMO
2174 /* Auto-capitalization is the default, so let's turn it off: */
2175 hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_password),
2176 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
2178 caption = hildon_caption_new (sizegroup,
2179 _("mail_fi_password"), entry_password, NULL, HILDON_CAPTION_MANDATORY);
2180 gtk_widget_show (entry_password);
2181 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
2182 FALSE, FALSE, MODEST_MARGIN_HALF);
2183 gtk_widget_show (caption);
2184 g_object_unref (sizegroup);
2186 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry_password,
2188 #endif /* MODEST_PLATFORM_MAEMO */
2190 /* This is not in the Maemo UI spec:
2191 remember_pass_check = gtk_check_button_new_with_label (_("Remember password"));
2192 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), remember_pass_check,
2196 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
2198 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
2200 *username = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_username)));
2202 modest_server_account_set_username (
2203 modest_runtime_get_account_mgr(), server_account_name,
2206 const gboolean username_was_changed =
2207 (strcmp (*username, initial_username) != 0);
2208 if (username_was_changed) {
2209 g_warning ("%s: tinymail does not yet support changing the "
2210 "username in the get_password() callback.\n", __FUNCTION__);
2215 *password = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_password)));
2217 /* We do not save the password in the configuration,
2218 * because this function is only called for passwords that should
2219 * not be remembered:
2220 modest_server_account_set_password (
2221 modest_runtime_get_account_mgr(), server_account_name,
2240 /* This is not in the Maemo UI spec:
2241 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (remember_pass_check)))
2247 gtk_widget_destroy (dialog);
2249 /* printf ("DEBUG: %s: cancel=%d\n", __FUNCTION__, *cancel); */
2253 modest_ui_actions_on_cut (GtkAction *action,
2254 ModestWindow *window)
2256 GtkWidget *focused_widget;
2258 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
2259 if (GTK_IS_EDITABLE (focused_widget)) {
2260 gtk_editable_cut_clipboard (GTK_EDITABLE(focused_widget));
2261 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
2262 GtkTextBuffer *buffer;
2263 GtkClipboard *clipboard;
2265 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
2266 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
2267 gtk_text_buffer_cut_clipboard (buffer, clipboard, TRUE);
2268 } else if (MODEST_IS_HEADER_VIEW (focused_widget)) {
2269 modest_header_view_cut_selection (MODEST_HEADER_VIEW (focused_widget));
2270 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
2271 modest_folder_view_cut_selection (MODEST_FOLDER_VIEW (focused_widget));
2276 modest_ui_actions_on_copy (GtkAction *action,
2277 ModestWindow *window)
2279 GtkClipboard *clipboard;
2280 GtkWidget *focused_widget;
2282 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
2283 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
2285 if (GTK_IS_LABEL (focused_widget)) {
2286 gtk_clipboard_set_text (clipboard, gtk_label_get_text (GTK_LABEL (focused_widget)), -1);
2287 } else if (GTK_IS_EDITABLE (focused_widget)) {
2288 gtk_editable_copy_clipboard (GTK_EDITABLE(focused_widget));
2289 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
2290 GtkTextBuffer *buffer;
2291 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
2292 gtk_text_buffer_copy_clipboard (buffer, clipboard);
2293 modest_header_view_copy_selection (MODEST_HEADER_VIEW (focused_widget));
2294 } else if (MODEST_IS_HEADER_VIEW (focused_widget)) {
2295 TnyList *header_list = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW (focused_widget));
2296 TnyIterator *iter = tny_list_create_iterator (header_list);
2297 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter));
2298 TnyFolder *folder = tny_header_get_folder (header);
2299 TnyAccount *account = tny_folder_get_account (folder);
2300 const gchar *proto_str = tny_account_get_proto (TNY_ACCOUNT (account));
2301 /* If it's POP then ask */
2302 gboolean ask = (modest_protocol_info_get_transport_store_protocol (proto_str) ==
2303 MODEST_PROTOCOL_STORE_POP) ? TRUE : FALSE;
2304 g_object_unref (account);
2305 g_object_unref (folder);
2306 g_object_unref (header);
2307 g_object_unref (iter);
2309 /* Check that the messages have been previously downloaded */
2310 gboolean continue_download = TRUE;
2312 continue_download = download_uncached_messages (header_list, GTK_WINDOW (window));
2313 if (continue_download)
2314 modest_header_view_copy_selection (MODEST_HEADER_VIEW (focused_widget));
2315 g_object_unref (header_list);
2316 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
2317 modest_folder_view_copy_selection (MODEST_FOLDER_VIEW (focused_widget));
2320 /* Show information banner */
2321 modest_platform_information_banner (NULL, NULL, _CS("ecoc_ib_edwin_copied"));
2326 modest_ui_actions_on_undo (GtkAction *action,
2327 ModestWindow *window)
2329 ModestEmailClipboard *clipboard = NULL;
2331 if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
2332 modest_msg_edit_window_undo (MODEST_MSG_EDIT_WINDOW (window));
2333 } if (MODEST_IS_MAIN_WINDOW (window)) {
2334 /* Clear clipboard source */
2335 clipboard = modest_runtime_get_email_clipboard ();
2336 modest_email_clipboard_clear (clipboard);
2339 g_return_if_reached ();
2344 modest_ui_actions_on_paste (GtkAction *action,
2345 ModestWindow *window)
2347 GtkWidget *focused_widget;
2348 ModestMailOperation *mail_op = NULL;
2350 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
2351 if (GTK_IS_EDITABLE (focused_widget)) {
2352 gtk_editable_paste_clipboard (GTK_EDITABLE(focused_widget));
2353 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
2354 GtkTextBuffer *buffer;
2355 GtkClipboard *clipboard;
2357 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
2358 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
2359 gtk_text_buffer_paste_clipboard (buffer, clipboard, NULL, TRUE);
2360 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
2361 ModestEmailClipboard *clipboard = NULL;
2362 TnyFolder *src_folder = NULL;
2363 TnyFolderStore *folder_store = NULL;
2364 TnyList *data = NULL;
2365 gboolean delete = FALSE;
2367 /* Check clipboard source */
2368 clipboard = modest_runtime_get_email_clipboard ();
2369 if (modest_email_clipboard_cleared (clipboard))
2372 /* Get elements to paste */
2373 modest_email_clipboard_get_data (clipboard, &src_folder, &data, &delete);
2375 /* Create a new mail operation */
2376 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_RECEIVE, G_OBJECT(window));
2377 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
2380 /* Get destination folder */
2381 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (focused_widget));
2383 /* transfer messages */
2385 modest_mail_operation_xfer_msgs (mail_op,
2387 TNY_FOLDER (folder_store),
2392 } else if (src_folder != NULL) {
2393 modest_mail_operation_xfer_folder (mail_op,
2401 g_object_unref (data);
2402 if (src_folder != NULL)
2403 g_object_unref (src_folder);
2404 if (folder_store != NULL)
2405 g_object_unref (folder_store);
2410 modest_ui_actions_on_select_all (GtkAction *action,
2411 ModestWindow *window)
2413 GtkWidget *focused_widget;
2415 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
2416 if (MODEST_IS_ATTACHMENTS_VIEW (focused_widget)) {
2417 modest_attachments_view_select_all (MODEST_ATTACHMENTS_VIEW (focused_widget));
2418 } else if (GTK_IS_LABEL (focused_widget)) {
2419 gtk_label_select_region (GTK_LABEL (focused_widget), 0, -1);
2420 } else if (GTK_IS_EDITABLE (focused_widget)) {
2421 gtk_editable_select_region (GTK_EDITABLE(focused_widget), 0, -1);
2422 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
2423 GtkTextBuffer *buffer;
2424 GtkTextIter start, end;
2426 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
2427 gtk_text_buffer_get_start_iter (buffer, &start);
2428 gtk_text_buffer_get_end_iter (buffer, &end);
2429 gtk_text_buffer_select_range (buffer, &start, &end);
2430 } else if (GTK_IS_HTML (focused_widget)) {
2431 gtk_html_select_all (GTK_HTML (focused_widget));
2432 } else if (MODEST_IS_MAIN_WINDOW (window)) {
2433 GtkWidget *header_view = focused_widget;
2434 GtkTreeSelection *selection = NULL;
2436 if (!(MODEST_IS_HEADER_VIEW (focused_widget)))
2437 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (window),
2438 MODEST_WIDGET_TYPE_HEADER_VIEW);
2440 /* Select all messages */
2441 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(header_view));
2442 gtk_tree_selection_select_all (selection);
2444 /* Set focuse on header view */
2445 gtk_widget_grab_focus (header_view);
2451 modest_ui_actions_on_mark_as_read (GtkAction *action,
2452 ModestWindow *window)
2454 g_return_if_fail (MODEST_IS_WINDOW(window));
2456 /* Mark each header as read */
2457 do_headers_action (window, headers_action_mark_as_read, NULL);
2461 modest_ui_actions_on_mark_as_unread (GtkAction *action,
2462 ModestWindow *window)
2464 g_return_if_fail (MODEST_IS_WINDOW(window));
2466 /* Mark each header as read */
2467 do_headers_action (window, headers_action_mark_as_unread, NULL);
2471 modest_ui_actions_on_change_zoom (GtkRadioAction *action,
2472 GtkRadioAction *selected,
2473 ModestWindow *window)
2477 value = gtk_radio_action_get_current_value (selected);
2478 if (MODEST_IS_WINDOW (window)) {
2479 modest_window_set_zoom (MODEST_WINDOW (window), ((gdouble)value)/100);
2483 void modest_ui_actions_msg_edit_on_change_priority (GtkRadioAction *action,
2484 GtkRadioAction *selected,
2485 ModestWindow *window)
2487 TnyHeaderFlags flags;
2488 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2490 flags = gtk_radio_action_get_current_value (selected);
2491 modest_msg_edit_window_set_priority_flags (MODEST_MSG_EDIT_WINDOW (window), flags);
2494 void modest_ui_actions_msg_edit_on_change_file_format (GtkRadioAction *action,
2495 GtkRadioAction *selected,
2496 ModestWindow *window)
2500 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2502 file_format = gtk_radio_action_get_current_value (selected);
2503 modest_msg_edit_window_set_file_format (MODEST_MSG_EDIT_WINDOW (window), file_format);
2508 modest_ui_actions_on_zoom_plus (GtkAction *action,
2509 ModestWindow *window)
2511 g_return_if_fail (MODEST_IS_WINDOW (window));
2513 modest_window_zoom_plus (MODEST_WINDOW (window));
2517 modest_ui_actions_on_zoom_minus (GtkAction *action,
2518 ModestWindow *window)
2520 g_return_if_fail (MODEST_IS_WINDOW (window));
2522 modest_window_zoom_minus (MODEST_WINDOW (window));
2526 modest_ui_actions_on_toggle_fullscreen (GtkToggleAction *toggle,
2527 ModestWindow *window)
2529 ModestWindowMgr *mgr;
2530 gboolean fullscreen, active;
2531 g_return_if_fail (MODEST_IS_WINDOW (window));
2533 mgr = modest_runtime_get_window_mgr ();
2535 active = (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle)))?1:0;
2536 fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
2538 if (active != fullscreen) {
2539 modest_window_mgr_set_fullscreen_mode (mgr, active);
2540 gtk_window_present (GTK_WINDOW (window));
2545 modest_ui_actions_on_change_fullscreen (GtkAction *action,
2546 ModestWindow *window)
2548 ModestWindowMgr *mgr;
2549 gboolean fullscreen;
2551 g_return_if_fail (MODEST_IS_WINDOW (window));
2553 mgr = modest_runtime_get_window_mgr ();
2554 fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
2555 modest_window_mgr_set_fullscreen_mode (mgr, !fullscreen);
2557 gtk_window_present (GTK_WINDOW (window));
2561 * Used by modest_ui_actions_on_details to call do_headers_action
2564 headers_action_show_details (TnyHeader *header,
2565 ModestWindow *window,
2572 dialog = modest_details_dialog_new_with_header (GTK_WINDOW (window), header);
2575 gtk_widget_show_all (dialog);
2576 gtk_dialog_run (GTK_DIALOG (dialog));
2578 gtk_widget_destroy (dialog);
2582 * Show the folder details in a ModestDetailsDialog widget
2585 show_folder_details (TnyFolder *folder,
2591 dialog = modest_details_dialog_new_with_folder (window, folder);
2594 gtk_widget_show_all (dialog);
2595 gtk_dialog_run (GTK_DIALOG (dialog));
2597 gtk_widget_destroy (dialog);
2601 * Show the header details in a ModestDetailsDialog widget
2604 modest_ui_actions_on_details (GtkAction *action,
2607 TnyList * headers_list;
2611 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
2614 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW (win));
2617 g_object_unref (msg);
2619 headers_list = get_selected_headers (win);
2623 iter = tny_list_create_iterator (headers_list);
2625 header = TNY_HEADER (tny_iterator_get_current (iter));
2626 headers_action_show_details (header, win, NULL);
2627 g_object_unref (header);
2629 g_object_unref (iter);
2630 g_object_unref (headers_list);
2632 } else if (MODEST_IS_MAIN_WINDOW (win)) {
2633 GtkWidget *folder_view, *header_view;
2635 /* Check which widget has the focus */
2636 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
2637 MODEST_WIDGET_TYPE_FOLDER_VIEW);
2638 if (gtk_widget_is_focus (folder_view)) {
2639 TnyFolderStore *folder_store
2640 = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
2641 if (!folder_store) {
2642 g_warning ("%s: No item was selected.\n", __FUNCTION__);
2645 /* Show only when it's a folder */
2646 /* This function should not be called for account items,
2647 * because we dim the menu item for them. */
2648 if (TNY_IS_FOLDER (folder_store)) {
2649 show_folder_details (TNY_FOLDER (folder_store), GTK_WINDOW (win));
2652 g_object_unref (folder_store);
2655 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
2656 MODEST_WIDGET_TYPE_HEADER_VIEW);
2657 /* Show details of each header */
2658 do_headers_action (win, headers_action_show_details, header_view);
2664 modest_ui_actions_on_toggle_show_cc (GtkToggleAction *toggle,
2665 ModestMsgEditWindow *window)
2667 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2669 modest_msg_edit_window_show_cc (window, gtk_toggle_action_get_active (toggle));
2673 modest_ui_actions_on_toggle_show_bcc (GtkToggleAction *toggle,
2674 ModestMsgEditWindow *window)
2676 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2678 modest_msg_edit_window_show_bcc (window, gtk_toggle_action_get_active (toggle));
2682 modest_ui_actions_toggle_folders_view (GtkAction *action,
2683 ModestMainWindow *main_window)
2687 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2689 conf = modest_runtime_get_conf ();
2691 if (modest_main_window_get_style (main_window) == MODEST_MAIN_WINDOW_STYLE_SPLIT)
2692 modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SIMPLE);
2694 modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SPLIT);
2698 modest_ui_actions_on_toggle_toolbar (GtkToggleAction *toggle,
2699 ModestWindow *window)
2701 gboolean active, fullscreen = FALSE;
2702 ModestWindowMgr *mgr;
2704 active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle));
2706 /* Check if we want to toggle the toolbar vuew in fullscreen
2708 if (!strcmp (gtk_action_get_name (GTK_ACTION (toggle)),
2709 "ViewShowToolbarFullScreen")) {
2713 /* Toggle toolbar */
2714 mgr = modest_runtime_get_window_mgr ();
2715 modest_window_mgr_show_toolbars (mgr, active, fullscreen);
2719 modest_ui_actions_msg_edit_on_select_font (GtkAction *action,
2720 ModestMsgEditWindow *window)
2722 modest_msg_edit_window_select_font (window);
2726 modest_ui_actions_on_folder_display_name_changed (ModestFolderView *folder_view,
2727 const gchar *display_name,
2730 /* Do not change the application name if the widget has not
2731 the focus. This callback could be called even if the folder
2732 view has not the focus, because the handled signal could be
2733 emitted when the folder view is redrawn */
2734 if (gtk_widget_is_focus (GTK_WIDGET (folder_view))) {
2736 gtk_window_set_title (window, display_name);
2738 gtk_window_set_title (window, " ");
2743 modest_ui_actions_on_select_contacts (GtkAction *action, ModestMsgEditWindow *window)
2745 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2746 modest_msg_edit_window_select_contacts (window);
2750 modest_ui_actions_on_check_names (GtkAction *action, ModestMsgEditWindow *window)
2752 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2753 modest_msg_edit_window_check_names (window);
2758 create_move_to_dialog (ModestWindow *win,
2759 GtkWidget *folder_view,
2760 GtkWidget **tree_view)
2762 GtkWidget *dialog, *scroll;
2764 dialog = gtk_dialog_new_with_buttons (_("mcen_ti_moveto_folders_title"),
2766 GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR | GTK_DIALOG_DESTROY_WITH_PARENT,
2768 GTK_RESPONSE_ACCEPT,
2770 GTK_RESPONSE_REJECT,
2773 /* Create scrolled window */
2774 scroll = gtk_scrolled_window_new (NULL, NULL);
2775 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll),
2776 GTK_POLICY_AUTOMATIC,
2777 GTK_POLICY_AUTOMATIC);
2779 /* Create folder view */
2780 *tree_view = modest_platform_create_folder_view (NULL);
2782 /* It could happen that we're trying to move a message from a
2783 window (msg window for example) after the main window was
2784 closed, so we can not just get the model of the folder
2786 if (MODEST_IS_FOLDER_VIEW (folder_view))
2787 gtk_tree_view_set_model (GTK_TREE_VIEW (*tree_view),
2788 gtk_tree_view_get_model (GTK_TREE_VIEW (folder_view)));
2790 modest_folder_view_update_model (MODEST_FOLDER_VIEW (*tree_view),
2791 TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()));
2793 gtk_container_add (GTK_CONTAINER (scroll), *tree_view);
2795 /* Add scroll to dialog */
2796 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
2797 scroll, FALSE, FALSE, 0);
2799 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
2801 /* Select INBOX or local account */
2802 modest_folder_view_select_first_inbox_or_local (MODEST_FOLDER_VIEW (*tree_view));
2808 * Returns TRUE if at least one of the headers of the list belongs to
2809 * a message that has been fully retrieved.
2812 has_retrieved_msgs (TnyList *list)
2815 gboolean found = FALSE;
2817 iter = tny_list_create_iterator (list);
2818 while (tny_iterator_is_done (iter) && !found) {
2820 TnyHeaderFlags flags;
2822 header = TNY_HEADER (tny_iterator_get_current (iter));
2823 flags = tny_header_get_flags (header);
2824 if (!(flags & TNY_HEADER_FLAG_PARTIAL))
2828 tny_iterator_next (iter);
2830 g_object_unref (iter);
2836 * Shows a confirmation dialog to the user when we're moving messages
2837 * from a remote server to the local storage. Returns the dialog
2838 * response. If it's other kind of movement the it always returns
2842 msgs_move_to_confirmation (GtkWindow *win,
2843 TnyFolder *dest_folder,
2846 gint response = GTK_RESPONSE_OK;
2848 /* If the destination is a local folder */
2849 if (modest_tny_folder_is_local_folder (dest_folder)) {
2850 TnyFolder *src_folder;
2854 /* Get source folder */
2855 iter = tny_list_create_iterator (headers);
2856 header = TNY_HEADER (tny_iterator_get_current (iter));
2857 src_folder = tny_header_get_folder (header);
2858 g_object_unref (header);
2859 g_object_unref (iter);
2861 /* if no src_folder, message may be an attahcment */
2862 if (src_folder == NULL)
2863 return GTK_RESPONSE_CANCEL;
2865 /* If the source is a remote folder */
2866 if (!modest_tny_folder_is_local_folder (src_folder)) {
2867 const gchar *message;
2869 if (has_retrieved_msgs (headers))
2870 message = ngettext ("mcen_nc_move_retrieve", "mcen_nc_move_retrieves",
2871 tny_list_get_length (headers));
2873 message = ngettext ("mcen_nc_move_header", "mcen_nc_move_headers",
2874 tny_list_get_length (headers));
2876 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
2877 (const gchar *) message);
2879 g_object_unref (src_folder);
2886 transfer_msgs_from_viewer_cb (const GObject *object, gpointer user_data)
2888 ModestMsgViewWindow *self = NULL;
2889 gboolean last, first;
2891 g_return_if_fail (MODEST_IS_MSG_VIEW_WINDOW (object));
2892 self = MODEST_MSG_VIEW_WINDOW (object);
2894 last = modest_msg_view_window_last_message_selected (self);
2895 first = modest_msg_view_window_first_message_selected (self);
2897 /* No more messages to view, so close this window */
2898 /* gboolean ret_value; */
2899 /* g_signal_emit_by_name (G_OBJECT (self), "delete-event", NULL, &ret_value); */
2900 modest_ui_actions_on_close_window (NULL, MODEST_WINDOW(self));
2902 modest_msg_view_window_select_previous_message (self);
2904 modest_msg_view_window_select_next_message (self);
2908 modest_ui_actions_move_folder_error_handler (ModestMailOperation *mail_op,
2911 GObject *win = modest_mail_operation_get_source (mail_op);
2913 /* TODO: show error message */
2914 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
2915 _("mail_in_ui_folder_move_target_error"));
2916 g_object_unref (win);
2920 modest_ui_actions_send_receive_error_handler (ModestMailOperation *mail_op,
2923 GObject *win = modest_mail_operation_get_source (mail_op);
2924 const GError *error = modest_mail_operation_get_error (mail_op);
2926 g_return_if_fail (error != NULL);
2927 if (error->message != NULL)
2928 g_printerr ("modest: %s\n", error->message);
2930 g_printerr ("modest: unkonw error on sedn&receive operation");
2932 /* Show error message */
2933 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
2934 _CS("sfil_ib_unable_to_send"));
2935 /* g_object_unref (win); */
2939 open_msg_for_purge_cb (ModestMailOperation *mail_op,
2946 gint pending_purges = 0;
2947 gboolean some_purged = FALSE;
2948 ModestWindow *win = MODEST_WINDOW (user_data);
2952 /* Once the message has been retrieved for purging, we check if
2953 * it's all ok for purging */
2955 parts = tny_simple_list_new ();
2956 tny_mime_part_get_parts (TNY_MIME_PART (msg), parts);
2957 iter = tny_list_create_iterator (parts);
2959 while (!tny_iterator_is_done (iter)) {
2961 part = TNY_MIME_PART (tny_iterator_get_current (iter));
2962 if (tny_mime_part_is_attachment (part) || TNY_IS_MSG (part)) {
2963 if (tny_mime_part_is_purged (part))
2968 tny_iterator_next (iter);
2971 if (pending_purges>0) {
2973 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),_("mcen_nc_purge_file_text_inbox"));
2975 if (response == GTK_RESPONSE_OK) {
2976 modest_platform_information_banner (NULL, NULL, _("mcen_ib_removing_attachment"));
2977 tny_iterator_first (iter);
2978 while (!tny_iterator_is_done (iter)) {
2981 part = TNY_MIME_PART (tny_iterator_get_current (iter));
2982 if (tny_mime_part_is_attachment (part) || TNY_IS_MSG (part))
2983 tny_mime_part_set_purged (part);
2984 tny_iterator_next (iter);
2987 tny_msg_rewrite_cache (msg);
2990 modest_platform_information_banner (NULL, NULL, _("mail_ib_attachment_already_purged"));
2993 /* remove attachments */
2994 tny_iterator_first (iter);
2995 while (!tny_iterator_is_done (iter)) {
2998 part = TNY_MIME_PART (tny_iterator_get_current (iter));
2999 g_object_unref (part);
3000 tny_iterator_next (iter);
3003 g_object_unref (iter);
3004 g_object_unref (parts);
3008 modest_ui_actions_on_main_window_remove_attachments (GtkAction *action,
3009 ModestMainWindow *win)
3011 GtkWidget *header_view;
3012 TnyList *header_list;
3015 TnyHeaderFlags flags;
3016 ModestWindow *msg_view_window = NULL;
3019 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win));
3021 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
3022 MODEST_WIDGET_TYPE_HEADER_VIEW);
3024 header_list = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW (header_view));
3026 if (tny_list_get_length (header_list) == 1) {
3027 iter = tny_list_create_iterator (header_list);
3028 header = TNY_HEADER (tny_iterator_get_current (iter));
3029 g_object_unref (iter);
3034 found = modest_window_mgr_find_registered_header (modest_runtime_get_window_mgr (),
3035 header, &msg_view_window);
3036 flags = tny_header_get_flags (header);
3037 if (!(flags & TNY_HEADER_FLAG_CACHED))
3040 if (msg_view_window != NULL)
3041 modest_msg_view_window_remove_attachments (MODEST_MSG_VIEW_WINDOW (msg_view_window), TRUE);
3043 /* do nothing; uid was registered before, so window is probably on it's way */
3044 g_warning ("debug: header %p has already been registered", header);
3047 ModestMailOperation *mail_op = NULL;
3048 modest_window_mgr_register_header (modest_runtime_get_window_mgr (), header);
3049 mail_op = modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_OPEN,
3051 modest_ui_actions_get_msgs_full_error_handler,
3053 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
3054 modest_mail_operation_get_msg (mail_op, header, open_msg_for_purge_cb, win);
3056 g_object_unref (mail_op);
3059 g_object_unref (header);
3061 g_object_unref (header_list);
3065 * UI handler for the "Move to" action when invoked from the
3069 modest_ui_actions_on_main_window_move_to (GtkAction *action,
3070 ModestMainWindow *win)
3072 GtkWidget *dialog = NULL, *folder_view = NULL, *tree_view = NULL;
3073 GtkWidget *header_view = NULL;
3075 TnyFolderStore *folder_store = NULL;
3076 ModestMailOperation *mail_op = NULL;
3078 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win));
3080 /* Get the folder view */
3081 folder_view = modest_main_window_get_child_widget (win,
3082 MODEST_WIDGET_TYPE_FOLDER_VIEW);
3084 /* Get header view */
3085 header_view = modest_main_window_get_child_widget (win,
3086 MODEST_WIDGET_TYPE_HEADER_VIEW);
3088 /* Create and run the dialog */
3089 dialog = create_move_to_dialog (MODEST_WINDOW (win), folder_view, &tree_view);
3090 modest_folder_view_select_first_inbox_or_local (MODEST_FOLDER_VIEW (tree_view));
3091 result = gtk_dialog_run (GTK_DIALOG(dialog));
3092 g_object_ref (tree_view);
3094 /* We do this to save an indentation level ;-) */
3095 if (result != GTK_RESPONSE_ACCEPT)
3098 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (tree_view));
3100 if (TNY_IS_ACCOUNT (folder_store) &&
3101 !MODEST_IS_TNY_LOCAL_FOLDERS_ACCOUNT (folder_store))
3104 /* Get folder or messages to transfer */
3105 if (gtk_widget_is_focus (folder_view)) {
3106 TnyFolderStore *src_folder;
3107 src_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
3109 /* Clean folder on header view before moving it */
3110 modest_header_view_clear (MODEST_HEADER_VIEW (header_view));
3112 if (TNY_IS_FOLDER (src_folder)) {
3114 modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE,
3116 modest_ui_actions_move_folder_error_handler,
3118 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
3120 modest_mail_operation_xfer_folder (mail_op,
3121 TNY_FOLDER (src_folder),
3124 /* Unref mail operation */
3125 g_object_unref (G_OBJECT (mail_op));
3129 g_object_unref (G_OBJECT (src_folder));
3131 if (gtk_widget_is_focus (header_view)) {
3135 headers = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW (header_view));
3137 /* Ask for user confirmation */
3138 response = msgs_move_to_confirmation (GTK_WINDOW (win),
3139 TNY_FOLDER (folder_store),
3142 /* Transfer messages */
3143 if (response == GTK_RESPONSE_OK) {
3144 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_RECEIVE, G_OBJECT(win));
3145 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
3148 modest_mail_operation_xfer_msgs (mail_op,
3150 TNY_FOLDER (folder_store),
3155 g_object_unref (G_OBJECT (mail_op));
3157 g_object_unref (headers);
3161 if (folder_store != NULL)
3162 g_object_unref (folder_store);
3163 gtk_widget_destroy (dialog);
3168 * UI handler for the "Move to" action when invoked from the
3169 * ModestMsgViewWindow
3172 modest_ui_actions_on_msg_view_window_move_to (GtkAction *action,
3173 ModestMsgViewWindow *win)
3175 GtkWidget *dialog, *folder_view, *tree_view = NULL;
3177 ModestMainWindow *main_window;
3181 /* Get the folder view */
3182 main_window = MODEST_MAIN_WINDOW (modest_window_mgr_get_main_window (modest_runtime_get_window_mgr ()));
3184 folder_view = modest_main_window_get_child_widget (main_window,
3185 MODEST_WIDGET_TYPE_FOLDER_VIEW);
3189 /* Create and run the dialog */
3190 dialog = create_move_to_dialog (MODEST_WINDOW (win), folder_view, &tree_view);
3191 result = gtk_dialog_run (GTK_DIALOG(dialog));
3192 g_object_ref (tree_view);
3194 if (result == GTK_RESPONSE_ACCEPT) {
3195 TnyFolderStore *folder_store;
3198 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (tree_view));
3200 /* Create header list */
3201 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
3203 headers = tny_simple_list_new ();
3204 tny_list_prepend (headers, G_OBJECT (header));
3205 g_object_unref (header);
3207 /* Ask user for confirmation. MSG-NOT404 */
3208 response = msgs_move_to_confirmation (GTK_WINDOW (win),
3209 TNY_FOLDER (folder_store),
3212 /* Transfer current msg */
3213 if (response == GTK_RESPONSE_OK) {
3214 ModestMailOperation *mail_op;
3216 /* Create mail op */
3217 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_RECEIVE, G_OBJECT(win));
3218 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
3221 /* Transfer messages */
3222 modest_mail_operation_xfer_msgs (mail_op,
3224 TNY_FOLDER (folder_store),
3226 transfer_msgs_from_viewer_cb,
3228 g_object_unref (G_OBJECT (mail_op));
3230 g_object_unref (headers);
3231 g_object_unref (folder_store);
3233 gtk_widget_destroy (dialog);
3237 modest_ui_actions_on_move_to (GtkAction *action,
3240 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win) ||
3241 MODEST_IS_MSG_VIEW_WINDOW (win));
3243 if (MODEST_IS_MAIN_WINDOW (win))
3244 modest_ui_actions_on_main_window_move_to (action,
3245 MODEST_MAIN_WINDOW (win));
3247 modest_ui_actions_on_msg_view_window_move_to (action,
3248 MODEST_MSG_VIEW_WINDOW (win));
3252 * Calls #HeadersFunc for each header already selected in the main
3253 * window or the message currently being shown in the msg view window
3256 do_headers_action (ModestWindow *win,
3260 TnyList *headers_list;
3266 headers_list = get_selected_headers (win);
3270 /* Get the folder */
3271 iter = tny_list_create_iterator (headers_list);
3272 header = TNY_HEADER (tny_iterator_get_current (iter));
3273 folder = tny_header_get_folder (header);
3274 g_object_unref (header);
3276 /* Call the function for each header */
3277 while (!tny_iterator_is_done (iter)) {
3278 header = TNY_HEADER (tny_iterator_get_current (iter));
3279 func (header, win, user_data);
3280 g_object_unref (header);
3281 tny_iterator_next (iter);
3284 /* Trick: do a poke status in order to speed up the signaling
3286 tny_folder_poke_status (folder);
3289 g_object_unref (folder);
3290 g_object_unref (iter);
3291 g_object_unref (headers_list);
3295 modest_ui_actions_view_attachment (GtkAction *action,
3296 ModestWindow *window)
3298 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
3299 modest_msg_view_window_view_attachment (MODEST_MSG_VIEW_WINDOW (window), NULL);
3301 /* not supported window for this action */
3302 g_return_if_reached ();
3307 modest_ui_actions_save_attachments (GtkAction *action,
3308 ModestWindow *window)
3310 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
3311 modest_msg_view_window_save_attachments (MODEST_MSG_VIEW_WINDOW (window), NULL);
3313 /* not supported window for this action */
3314 g_return_if_reached ();
3319 modest_ui_actions_remove_attachments (GtkAction *action,
3320 ModestWindow *window)
3322 if (MODEST_IS_MAIN_WINDOW (window)) {
3323 modest_ui_actions_on_main_window_remove_attachments (action, MODEST_MAIN_WINDOW (window));
3324 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
3325 modest_msg_view_window_remove_attachments (MODEST_MSG_VIEW_WINDOW (window), FALSE);
3327 /* not supported window for this action */
3328 g_return_if_reached ();
3333 modest_ui_actions_on_settings (GtkAction *action,
3338 dialog = modest_platform_get_global_settings_dialog ();
3339 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (win));
3340 gtk_widget_show_all (dialog);
3342 gtk_dialog_run (GTK_DIALOG (dialog));
3344 gtk_widget_destroy (dialog);
3348 modest_ui_actions_on_help (GtkAction *action,
3351 const gchar *help_id = NULL;
3353 if (MODEST_IS_MAIN_WINDOW (win)) {
3354 const gchar *action_name;
3355 action_name = gtk_action_get_name (action);
3357 if (!strcmp (action_name, "FolderViewCSMHelp") ||
3358 !strcmp (action_name, "HeaderViewCSMHelp")) {
3359 GtkWidget *folder_view;
3360 TnyFolderStore *folder_store;
3361 /* Get selected folder */
3362 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
3363 MODEST_WIDGET_TYPE_FOLDER_VIEW);
3364 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
3366 /* Switch help_id */
3367 if (TNY_IS_FOLDER (folder_store)) {
3368 switch (tny_folder_get_folder_type (TNY_FOLDER (folder_store))) {
3369 case TNY_FOLDER_TYPE_NORMAL:
3370 help_id = "applications_email_userfolder";
3372 case TNY_FOLDER_TYPE_INBOX:
3373 help_id = "applications_email_inbox";
3375 case TNY_FOLDER_TYPE_OUTBOX:
3376 help_id = "applications_email_outbox";
3378 case TNY_FOLDER_TYPE_SENT:
3379 help_id = "applications_email_sent";
3381 case TNY_FOLDER_TYPE_DRAFTS:
3382 help_id = "applications_email_drafts";
3384 case TNY_FOLDER_TYPE_ARCHIVE:
3385 help_id = "applications_email_archive";
3391 g_object_unref (folder_store);
3393 help_id = "applications_email_mainview";
3395 } else if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
3396 help_id = "applications_email_viewer";
3397 } else if (MODEST_IS_MSG_EDIT_WINDOW (win))
3398 help_id = "applications_email_editor";
3400 modest_platform_show_help (GTK_WINDOW (win), help_id);
3404 modest_ui_actions_on_retrieve_msg_contents (GtkAction *action,
3405 ModestWindow *window)
3407 ModestMailOperation *mail_op;
3411 headers = get_selected_headers (window);
3415 /* Create mail operation */
3416 mail_op = modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE,
3418 modest_ui_actions_get_msgs_full_error_handler,
3420 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
3421 modest_mail_operation_get_msgs_full (mail_op, headers, NULL, NULL, NULL);
3424 g_object_unref (headers);
3425 g_object_unref (mail_op);
3429 modest_ui_actions_on_email_menu_activated (GtkAction *action,
3430 ModestWindow *window)
3432 g_return_if_fail (MODEST_IS_WINDOW (window));
3435 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
3439 modest_ui_actions_on_edit_menu_activated (GtkAction *action,
3440 ModestWindow *window)
3442 g_return_if_fail (MODEST_IS_WINDOW (window));
3445 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
3449 modest_ui_actions_on_view_menu_activated (GtkAction *action,
3450 ModestWindow *window)
3452 g_return_if_fail (MODEST_IS_WINDOW (window));
3455 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
3459 modest_ui_actions_on_tools_menu_activated (GtkAction *action,
3460 ModestWindow *window)
3462 g_return_if_fail (MODEST_IS_WINDOW (window));
3465 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
3469 modest_ui_actions_on_attachment_menu_activated (GtkAction *action,
3470 ModestWindow *window)
3472 g_return_if_fail (MODEST_IS_WINDOW (window));
3475 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
3479 modest_ui_actions_on_toolbar_csm_menu_activated (GtkAction *action,
3480 ModestWindow *window)
3482 g_return_if_fail (MODEST_IS_WINDOW (window));
3485 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
3489 modest_ui_actions_on_folder_view_csm_menu_activated (GtkAction *action,
3490 ModestWindow *window)
3492 g_return_if_fail (MODEST_IS_WINDOW (window));
3495 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
3499 modest_ui_actions_on_header_view_csm_menu_activated (GtkAction *action,
3500 ModestWindow *window)
3502 g_return_if_fail (MODEST_IS_WINDOW (window));
3505 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
3509 modest_ui_actions_check_toolbar_dimming_rules (ModestWindow *window)
3511 g_return_if_fail (MODEST_IS_WINDOW (window));
3514 modest_window_check_dimming_rules_group (window, "ModestToolbarDimmingRules");
3518 modest_ui_actions_on_search_messages (GtkAction *action, ModestWindow *window)
3520 g_return_if_fail (MODEST_IS_WINDOW (window));
3522 modest_platform_show_search_messages (GTK_WINDOW (window));
3526 modest_ui_actions_on_open_addressbook (GtkAction *action, ModestWindow *win)
3528 g_return_if_fail (MODEST_IS_WINDOW (win));
3529 modest_platform_show_addressbook (GTK_WINDOW (win));
3534 modest_ui_actions_on_toggle_find_in_page (GtkToggleAction *action,
3535 ModestWindow *window)
3537 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3539 modest_msg_edit_window_toggle_find_toolbar (MODEST_MSG_EDIT_WINDOW (window), gtk_toggle_action_get_active (action));
3543 _on_send_receive_progress_changed (ModestMailOperation *mail_op,
3544 ModestMailOperationState *state,
3547 g_return_if_fail (MODEST_IS_MAIN_WINDOW(user_data));
3549 /* Set send/receive operation finished */
3550 if (state->status != MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS)
3551 modest_main_window_notify_send_receive_completed (MODEST_MAIN_WINDOW(user_data));