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 #include "maemo/modest-maemo-utils.h"
52 #include "maemo/modest-hildon-includes.h"
53 #endif /* MODEST_PLATFORM_MAEMO */
55 #include "widgets/modest-ui-constants.h"
56 #include <widgets/modest-main-window.h>
57 #include <widgets/modest-msg-view-window.h>
58 #include <widgets/modest-account-view-window.h>
59 #include <widgets/modest-details-dialog.h>
60 #include <widgets/modest-attachments-view.h>
61 #include "widgets/modest-folder-view.h"
62 #include "widgets/modest-global-settings-dialog.h"
63 #include "modest-connection-specific-smtp-window.h"
64 #include "modest-account-mgr-helpers.h"
65 #include "modest-mail-operation.h"
66 #include "modest-text-utils.h"
68 #ifdef MODEST_HAVE_EASYSETUP
69 #include "easysetup/modest-easysetup-wizard.h"
70 #endif /* MODEST_HAVE_EASYSETUP */
72 #include <modest-widget-memory.h>
73 #include <tny-error.h>
74 #include <tny-simple-list.h>
75 #include <tny-msg-view.h>
76 #include <tny-device.h>
77 #include <tny-merge-folder.h>
79 #include <gtkhtml/gtkhtml.h>
81 typedef struct _GetMsgAsyncHelper {
83 ModestMailOperation *mail_op;
90 typedef enum _ReplyForwardAction {
96 typedef struct _ReplyForwardHelper {
97 guint reply_forward_type;
98 ReplyForwardAction action;
100 GtkWidget *parent_window;
101 } ReplyForwardHelper;
103 typedef struct _PasteAsAttachmentHelper {
104 ModestMsgEditWindow *window;
106 } PasteAsAttachmentHelper;
110 * The do_headers_action uses this kind of functions to perform some
111 * action to each member of a list of headers
113 typedef void (*HeadersFunc) (TnyHeader *header, ModestWindow *win, gpointer user_data);
115 static void do_headers_action (ModestWindow *win,
119 static void open_msg_cb (ModestMailOperation *mail_op,
124 static void reply_forward_cb (ModestMailOperation *mail_op,
129 static void reply_forward (ReplyForwardAction action, ModestWindow *win);
131 static void folder_refreshed_cb (ModestMailOperation *mail_op,
135 static void _on_send_receive_progress_changed (ModestMailOperation *mail_op,
136 ModestMailOperationState *state,
140 download_uncached_messages (TnyList *header_list, GtkWindow *win,
145 run_account_setup_wizard (ModestWindow *win)
147 ModestEasysetupWizardDialog *wizard;
149 g_return_if_fail (MODEST_IS_WINDOW(win));
151 wizard = modest_easysetup_wizard_dialog_new ();
152 gtk_window_set_transient_for (GTK_WINDOW (wizard), GTK_WINDOW (win));
153 gtk_window_set_modal (GTK_WINDOW (wizard), TRUE);
154 gtk_dialog_run (GTK_DIALOG (wizard));
155 gtk_widget_destroy (GTK_WIDGET (wizard));
160 modest_ui_actions_on_about (GtkAction *action, ModestWindow *win)
163 const gchar *authors[] = {
164 "Dirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>",
167 about = gtk_about_dialog_new ();
168 gtk_about_dialog_set_name (GTK_ABOUT_DIALOG(about), PACKAGE_NAME);
169 gtk_about_dialog_set_version (GTK_ABOUT_DIALOG(about),PACKAGE_VERSION);
170 gtk_about_dialog_set_copyright (GTK_ABOUT_DIALOG(about),
171 _("Copyright (c) 2006, Nokia Corporation\n"
172 "All rights reserved."));
173 gtk_about_dialog_set_comments (GTK_ABOUT_DIALOG(about),
174 _("a modest e-mail client\n\n"
175 "design and implementation: Dirk-Jan C. Binnema\n"
176 "contributions from the fine people at KC and Ig\n"
177 "uses the tinymail email framework written by Philip van Hoof"));
178 gtk_about_dialog_set_authors (GTK_ABOUT_DIALOG(about), authors);
179 gtk_about_dialog_set_website (GTK_ABOUT_DIALOG(about), "http://modest.garage.maemo.org");
180 gtk_window_set_transient_for (GTK_WINDOW (about), GTK_WINDOW (win));
181 gtk_window_set_modal (GTK_WINDOW (about), TRUE);
183 gtk_dialog_run (GTK_DIALOG (about));
184 gtk_widget_destroy(about);
188 * Gets the list of currently selected messages. If the win is the
189 * main window, then it returns a newly allocated list of the headers
190 * selected in the header view. If win is the msg view window, then
191 * the value returned is a list with just a single header.
193 * The caller of this funcion must free the list.
196 get_selected_headers (ModestWindow *win)
198 if (MODEST_IS_MAIN_WINDOW(win)) {
199 GtkWidget *header_view;
201 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
202 MODEST_WIDGET_TYPE_HEADER_VIEW);
203 return modest_header_view_get_selected_headers (MODEST_HEADER_VIEW(header_view));
205 } else if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
206 /* for MsgViewWindows, we simply return a list with one element */
208 TnyList *list = NULL;
210 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
211 if (header != NULL) {
212 list = tny_simple_list_new ();
213 tny_list_prepend (list, G_OBJECT(header));
214 g_object_unref (G_OBJECT(header));
224 headers_action_mark_as_read (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) return;
234 tny_header_set_flags (header, TNY_HEADER_FLAG_SEEN);
238 headers_action_mark_as_unread (TnyHeader *header,
242 TnyHeaderFlags flags;
244 g_return_if_fail (TNY_IS_HEADER(header));
246 flags = tny_header_get_flags (header);
247 if (flags & TNY_HEADER_FLAG_SEEN) {
248 tny_header_unset_flags (header, TNY_HEADER_FLAG_SEEN);
252 /** A convenience method, because deleting a message is
253 * otherwise complicated, and it's best to change it in one place
256 void modest_do_message_delete (TnyHeader *header, ModestWindow *win)
258 ModestMailOperation *mail_op = NULL;
259 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_DELETE,
260 win ? G_OBJECT(win) : NULL);
261 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
264 /* Always delete. TODO: Move to trash still not supported */
265 modest_mail_operation_remove_msg (mail_op, header, FALSE);
266 g_object_unref (G_OBJECT (mail_op));
270 headers_action_delete (TnyHeader *header,
274 modest_do_message_delete (header, win);
277 /** After deleing a message that is currently visible in a window,
278 * show the next message from the list, or close the window if there are no more messages.
280 void modest_ui_actions_refresh_message_window_after_delete (ModestMsgViewWindow* win)
282 /* Close msg view window or select next */
283 if (modest_msg_view_window_last_message_selected (win) &&
284 modest_msg_view_window_first_message_selected (win)) {
285 modest_ui_actions_on_close_window (NULL, MODEST_WINDOW (win));
287 modest_msg_view_window_select_next_message (win);
292 modest_ui_actions_on_delete_message (GtkAction *action, ModestWindow *win)
294 TnyList *header_list = NULL;
295 TnyIterator *iter = NULL;
296 TnyHeader *header = NULL;
297 gchar *message = NULL;
300 ModestWindowMgr *mgr;
301 GtkWidget *header_view = NULL;
303 g_return_if_fail (MODEST_IS_WINDOW(win));
305 /* Check first if the header view has the focus */
306 if (MODEST_IS_MAIN_WINDOW (win)) {
308 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
309 MODEST_WIDGET_TYPE_HEADER_VIEW);
310 if (!gtk_widget_is_focus (header_view))
314 header_list = get_selected_headers (win);
315 if (!header_list) return;
317 /* Check if any of the headers are already opened, or in the process of being opened */
318 if (MODEST_IS_MAIN_WINDOW (win)) {
320 iter = tny_list_create_iterator (header_list);
322 mgr = modest_runtime_get_window_mgr ();
323 while (!tny_iterator_is_done (iter) && !found) {
324 header = TNY_HEADER (tny_iterator_get_current (iter));
326 found = modest_window_mgr_find_registered_header (mgr, header, NULL);
327 g_object_unref (header);
330 tny_iterator_next (iter);
332 g_object_unref (iter);
337 num = g_strdup_printf ("%d", tny_list_get_length (header_list));
338 msg = g_strdup_printf (_("mcen_nc_unable_to_delete_n_messages"), num);
340 modest_platform_run_information_dialog (GTK_WINDOW (win), (const gchar *) msg);
344 g_object_unref (header_list);
350 if (tny_list_get_length(header_list) == 1) {
351 iter = tny_list_create_iterator (header_list);
352 header = TNY_HEADER (tny_iterator_get_current (iter));
354 desc = g_strdup_printf ("%s", tny_header_get_subject (header));
355 g_object_unref (header);
358 g_object_unref (iter);
360 message = g_strdup_printf(ngettext("emev_nc_delete_message", "emev_nc_delete_messages",
361 tny_list_get_length(header_list)), desc);
363 /* Confirmation dialog */
364 printf("DEBUG: %s\n", __FUNCTION__);
365 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
369 if (response == GTK_RESPONSE_OK) {
370 ModestWindow *main_window = NULL;
371 ModestWindowMgr *mgr = NULL;
372 GtkTreeModel *model = NULL;
373 GtkTreeSelection *sel = NULL;
374 GList *sel_list = NULL, *tmp = NULL;
375 GtkTreeRowReference *row_reference = NULL;
376 GtkTreePath *next_path = NULL;
378 /* Find last selected row */
379 if (MODEST_IS_MAIN_WINDOW (win)) {
380 model = gtk_tree_view_get_model (GTK_TREE_VIEW (header_view));
381 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
382 sel_list = gtk_tree_selection_get_selected_rows (sel, &model);
383 for (tmp=sel_list; tmp; tmp=tmp->next) {
384 if (tmp->next == NULL) {
385 next_path = gtk_tree_path_copy((GtkTreePath *) tmp->data);
386 gtk_tree_path_next (next_path);
387 row_reference = gtk_tree_row_reference_new (model, next_path);
388 gtk_tree_path_free (next_path);
393 /* Remove each header. If it's a view window header_view == NULL */
394 do_headers_action (win, headers_action_delete, header_view);
396 /* refresh the header view (removing marked-as-deleted)*/
397 modest_header_view_refilter (MODEST_HEADER_VIEW(header_view));
399 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
400 modest_ui_actions_refresh_message_window_after_delete (MODEST_MSG_VIEW_WINDOW (win));
402 /* Get main window */
403 mgr = modest_runtime_get_window_mgr ();
404 main_window = modest_window_mgr_get_main_window (mgr);
407 /* Move cursor to next row */
410 /* Select next row */
411 if (gtk_tree_row_reference_valid (row_reference)) {
412 next_path = gtk_tree_row_reference_get_path (row_reference);
413 gtk_tree_selection_select_path (sel, next_path);
414 gtk_tree_path_free (next_path);
416 if (row_reference != NULL)
417 gtk_tree_row_reference_free (row_reference);
420 /* Update toolbar dimming state */
421 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
424 g_list_foreach (sel_list, (GFunc) gtk_tree_path_free, NULL);
425 g_list_free (sel_list);
431 g_object_unref (header_list);
437 /* delete either message or folder, based on where we are */
439 modest_ui_actions_on_delete_message_or_folder (GtkAction *action, ModestWindow *win)
441 g_return_if_fail (MODEST_IS_WINDOW(win));
443 /* Check first if the header view has the focus */
444 if (MODEST_IS_MAIN_WINDOW (win)) {
446 w = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
447 MODEST_WIDGET_TYPE_FOLDER_VIEW);
448 if (gtk_widget_is_focus (w)) {
449 modest_ui_actions_on_delete_folder (action, MODEST_MAIN_WINDOW(win));
453 modest_ui_actions_on_delete_message (action, win);
459 modest_ui_actions_on_quit (GtkAction *action, ModestWindow *win)
461 #ifdef MODEST_PLATFORM_MAEMO
462 modest_osso_save_state();
463 #endif /* MODEST_PLATFORM_MAEMO */
465 g_debug ("closing down, clearing %d item(s) from operation queue",
466 modest_mail_operation_queue_num_elements
467 (modest_runtime_get_mail_operation_queue()));
469 /* cancel all outstanding operations */
470 modest_mail_operation_queue_cancel_all
471 (modest_runtime_get_mail_operation_queue());
473 g_debug ("queue has been cleared");
475 /* note: when modest-tny-account-store is finalized,
476 it will automatically set all network connections
483 modest_ui_actions_on_close_window (GtkAction *action, ModestWindow *win)
487 g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value);
489 /* if (MODEST_IS_MSG_VIEW_WINDOW (win)) { */
490 /* gtk_widget_destroy (GTK_WIDGET (win)); */
491 /* } else if (MODEST_IS_MSG_EDIT_WINDOW (win)) { */
492 /* gboolean ret_value; */
493 /* g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value); */
494 /* } else if (MODEST_IS_WINDOW (win)) { */
495 /* gtk_widget_destroy (GTK_WIDGET (win)); */
497 /* g_return_if_reached (); */
502 modest_ui_actions_on_add_to_contacts (GtkAction *action, ModestWindow *win)
504 GtkClipboard *clipboard = NULL;
505 gchar *selection = NULL;
507 clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
508 selection = gtk_clipboard_wait_for_text (clipboard);
510 /* Question: why is the clipboard being used here?
511 * It doesn't really make a lot of sense. */
515 modest_address_book_add_address (selection);
521 modest_ui_actions_on_accounts (GtkAction *action, ModestWindow *win)
523 /* This is currently only implemented for Maemo */
524 #ifdef MODEST_PLATFORM_MAEMO /* Defined in config.h */
525 if (!modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE)) {
526 run_account_setup_wizard (win);
529 /* Show the list of accounts: */
530 GtkDialog *account_win = GTK_DIALOG(modest_account_view_window_new ());
531 gtk_window_set_transient_for (GTK_WINDOW (account_win), GTK_WINDOW (win));
532 gtk_window_set_modal (GTK_WINDOW (account_win), TRUE);
533 modest_maemo_show_dialog_and_forget (GTK_WINDOW (win), account_win);
536 GtkWidget *dialog, *label;
538 /* Create the widgets */
540 dialog = gtk_dialog_new_with_buttons ("Message",
542 GTK_DIALOG_DESTROY_WITH_PARENT,
546 label = gtk_label_new ("Hello World!");
548 /* Ensure that the dialog box is destroyed when the user responds. */
550 g_signal_connect_swapped (dialog, "response",
551 G_CALLBACK (gtk_widget_destroy),
554 /* Add the label, and show everything we've added to the dialog. */
556 gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox),
558 gtk_widget_show_all (dialog);
559 #endif /* MODEST_PLATFORM_MAEMO */
563 on_smtp_servers_window_hide (GtkWindow* window, gpointer user_data)
565 ModestWindow *main_window = MODEST_WINDOW (user_data);
567 /* Save any changes. */
568 modest_connection_specific_smtp_window_save_server_accounts (
569 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (window),
570 modest_window_get_active_account (main_window));
571 gtk_widget_destroy (GTK_WIDGET (window));
577 modest_ui_actions_on_smtp_servers (GtkAction *action, ModestWindow *win)
579 /* This is currently only implemented for Maemo,
580 * because it requires an API (libconic) to detect different connection
583 #ifdef MODEST_PLATFORM_MAEMO /* Defined in config.h */
585 /* Create the window if necessary: */
586 const gchar *active_account_name = modest_window_get_active_account (win);
588 /* TODO: Dim the menu item (not in the UI spec)? or show a warning,
589 * or show the default account?
590 * If we show the default account then the account name should be shown in
591 * the window when we show it. */
592 if (!active_account_name) {
593 g_warning ("%s: No account is active.", __FUNCTION__);
597 GtkWidget *specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
598 modest_connection_specific_smtp_window_fill_with_connections (
599 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (specific_window),
600 modest_runtime_get_account_mgr(),
601 active_account_name);
603 /* Show the window: */
604 gtk_window_set_transient_for (GTK_WINDOW (specific_window), GTK_WINDOW (win));
605 gtk_window_set_modal (GTK_WINDOW (specific_window), TRUE);
606 gtk_widget_show (specific_window);
608 /* Save changes when the window is hidden: */
609 g_signal_connect (specific_window, "hide",
610 G_CALLBACK (on_smtp_servers_window_hide), win);
611 #endif /* MODEST_PLATFORM_MAEMO */
615 modest_ui_actions_on_new_msg (GtkAction *action, ModestWindow *win)
617 ModestWindow *msg_win = NULL;
619 TnyFolder *folder = NULL;
620 gchar *account_name = NULL;
621 gchar *from_str = NULL;
622 /* GError *err = NULL; */
623 TnyAccount *account = NULL;
624 ModestWindowMgr *mgr;
625 gchar *signature = NULL, *blank_and_signature = NULL;
627 /* if there are no accounts yet, just show the wizard */
628 if (!modest_account_mgr_has_accounts (modest_runtime_get_account_mgr(), TRUE)) {
629 run_account_setup_wizard (win);
633 account_name = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr ());
635 account_name = g_strdup (modest_window_get_active_account (win));
637 g_printerr ("modest: no account found\n");
641 account = modest_tny_account_store_get_server_account (modest_runtime_get_account_store(),
643 TNY_ACCOUNT_TYPE_STORE);
645 g_printerr ("modest: failed to get tnyaccount for '%s'\n", account_name);
649 from_str = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(), account_name);
651 g_printerr ("modest: failed get from string for '%s'\n", account_name);
655 if (modest_account_mgr_get_bool (modest_runtime_get_account_mgr (), account_name,
656 MODEST_ACCOUNT_USE_SIGNATURE, FALSE)) {
657 signature = modest_account_mgr_get_string (modest_runtime_get_account_mgr (), account_name,
658 MODEST_ACCOUNT_SIGNATURE, FALSE);
659 blank_and_signature = g_strconcat ("\n", signature, NULL);
662 blank_and_signature = g_strdup ("");
665 msg = modest_tny_msg_new ("", from_str, "", "", "", blank_and_signature, NULL);
667 g_printerr ("modest: failed to create new msg\n");
671 folder = modest_tny_account_get_special_folder (account, TNY_FOLDER_TYPE_DRAFTS);
673 g_printerr ("modest: failed to find Drafts folder\n");
678 /* Create and register edit window */
679 /* This is destroyed by TOOD. */
680 msg_win = modest_msg_edit_window_new (msg, account_name);
681 mgr = modest_runtime_get_window_mgr ();
682 modest_window_mgr_register_window (mgr, msg_win);
685 gtk_window_set_transient_for (GTK_WINDOW (msg_win),
687 gtk_widget_show_all (GTK_WIDGET (msg_win));
690 g_free (account_name);
692 g_free (blank_and_signature);
694 g_object_unref (msg_win);
696 g_object_unref (G_OBJECT(account));
698 g_object_unref (G_OBJECT(msg));
700 g_object_unref (G_OBJECT(folder));
704 modest_ui_actions_msg_retrieval_check (ModestMailOperation *mail_op,
708 ModestMailOperationStatus status;
710 /* If there is no message or the operation was not successful */
711 status = modest_mail_operation_get_status (mail_op);
712 if (!msg || status != MODEST_MAIL_OPERATION_STATUS_SUCCESS) {
714 /* Remove the header from the preregistered uids */
715 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (),
725 open_msg_cb (ModestMailOperation *mail_op,
730 ModestWindowMgr *mgr = NULL;
731 ModestWindow *parent_win = NULL;
732 ModestWindow *win = NULL;
733 TnyFolderType folder_type = TNY_FOLDER_TYPE_UNKNOWN;
734 gchar *account = NULL;
737 /* Do nothing if there was any problem with the mail
738 operation. The error will be shown by the error_handler of
739 the mail operation */
740 if (!modest_ui_actions_msg_retrieval_check (mail_op, header, msg)) {
744 parent_win = (ModestWindow *) modest_mail_operation_get_source (mail_op);
745 folder = tny_header_get_folder (header);
747 /* Mark header as read */
748 headers_action_mark_as_read (header, MODEST_WINDOW(parent_win), NULL);
751 account = g_strdup (modest_window_get_active_account (MODEST_WINDOW (parent_win)));
753 account = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
755 /* Gets folder type (OUTBOX headers will be opened in edit window */
756 if (modest_tny_folder_is_local_folder (folder))
757 folder_type = modest_tny_folder_get_local_or_mmc_folder_type (folder);
759 /* If the header is in the drafts folder then open the editor,
760 else the message view window */
761 if ((folder_type == TNY_FOLDER_TYPE_DRAFTS) ||
762 (folder_type == TNY_FOLDER_TYPE_OUTBOX)) {
763 /* we cannot edit without a valid account... */
764 if (!modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE)) {
765 run_account_setup_wizard(parent_win);
768 win = modest_msg_edit_window_new (msg, account);
770 gchar *uid = modest_tny_folder_get_header_unique_id (header);
772 if (MODEST_IS_MAIN_WINDOW (parent_win)) {
773 GtkWidget *header_view;
774 GtkTreeSelection *sel;
775 GList *sel_list = NULL;
778 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(parent_win),
779 MODEST_WIDGET_TYPE_HEADER_VIEW);
781 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
782 sel_list = gtk_tree_selection_get_selected_rows (sel, &model);
784 if (sel_list != NULL) {
785 GtkTreeRowReference *row_reference;
787 row_reference = gtk_tree_row_reference_new (model, (GtkTreePath *) sel_list->data);
788 g_list_foreach (sel_list, (GFunc) gtk_tree_path_free, NULL);
789 g_list_free (sel_list);
791 win = modest_msg_view_window_new_with_header_model (msg,
796 gtk_tree_row_reference_free (row_reference);
798 win = modest_msg_view_window_new (msg, account, (const gchar*) uid);
801 win = modest_msg_view_window_new (msg, account, (const gchar*) uid);
806 /* Register and show new window */
808 mgr = modest_runtime_get_window_mgr ();
809 modest_window_mgr_register_window (mgr, win);
810 g_object_unref (win);
811 gtk_window_set_transient_for (GTK_WINDOW (win), GTK_WINDOW (parent_win));
812 gtk_widget_show_all (GTK_WIDGET(win));
815 /* Update toolbar dimming state */
816 if (MODEST_IS_MAIN_WINDOW (parent_win)) {
817 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (parent_win));
823 g_object_unref (parent_win);
824 g_object_unref (folder);
828 modest_ui_actions_get_msgs_full_error_handler (ModestMailOperation *mail_op,
832 GObject *win = modest_mail_operation_get_source (mail_op);
834 error = modest_mail_operation_get_error (mail_op);
835 printf ("DEBUG: %s: Error: code=%d, text=%s\n", __FUNCTION__, error->code, error->message);
837 if (error->code == MODEST_MAIL_OPERATION_ERROR_MESSAGE_SIZE_LIMIT) {
839 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
842 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
843 _("mail_ni_ui_folder_get_msg_folder_error"));
847 g_object_unref (win);
851 * This function is used by both modest_ui_actions_on_open and
852 * modest_ui_actions_on_header_activated. This way we always do the
853 * same when trying to open messages.
856 _modest_ui_actions_open (TnyList *headers, ModestWindow *win)
858 ModestWindowMgr *mgr = NULL;
859 TnyIterator *iter = NULL;
860 ModestMailOperation *mail_op = NULL;
861 TnyList *not_opened_headers = NULL;
862 TnyHeaderFlags flags = 0;
864 /* Look if we already have a message view for each header. If
865 true, then remove the header from the list of headers to
867 mgr = modest_runtime_get_window_mgr ();
868 iter = tny_list_create_iterator (headers);
869 not_opened_headers = tny_simple_list_new ();
871 while (!tny_iterator_is_done (iter)) {
873 ModestWindow *window = NULL;
874 TnyHeader *header = NULL;
875 gboolean found = FALSE;
877 header = TNY_HEADER (tny_iterator_get_current (iter));
879 flags = tny_header_get_flags (header);
882 found = modest_window_mgr_find_registered_header (mgr, header, &window);
884 /* Do not open again the message and present the
885 window to the user */
888 gtk_window_present (GTK_WINDOW (window));
890 /* the header has been registered already, we don't do
891 * anything but wait for the window to come up*/
892 g_debug ("header %p already registered, waiting for window", header);
894 tny_list_append (not_opened_headers, G_OBJECT (header));
898 g_object_unref (header);
900 tny_iterator_next (iter);
902 g_object_unref (iter);
905 /* If some messages would have to be downloaded, ask the user to
906 * make a connection. It's generally easier to do this here (in the mainloop)
907 * than later in a thread:
909 if (tny_list_get_length (not_opened_headers) > 0) {
911 gboolean found = FALSE;
913 iter = tny_list_create_iterator (not_opened_headers);
914 while (!tny_iterator_is_done (iter) && !found) {
915 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter));
916 if (!(tny_header_get_flags (header) & TNY_HEADER_FLAG_CACHED))
919 tny_iterator_next (iter);
921 g_object_unref (header);
923 g_object_unref (iter);
925 if (found && !modest_platform_connect_and_wait (GTK_WINDOW (win), NULL)) {
926 g_object_unref (not_opened_headers);
931 /* Register the headers before actually creating the windows: */
932 TnyIterator *iter_not_opened = tny_list_create_iterator (not_opened_headers);
933 while (!tny_iterator_is_done (iter_not_opened)) {
934 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter_not_opened));
936 modest_window_mgr_register_header (mgr, header);
937 g_object_unref (header);
940 tny_iterator_next (iter_not_opened);
942 g_object_unref (iter_not_opened);
943 iter_not_opened = NULL;
945 /* Open each message */
946 if (tny_list_get_length (not_opened_headers) > 0) {
947 mail_op = modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE,
949 modest_ui_actions_get_msgs_full_error_handler,
951 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
952 if (tny_list_get_length (not_opened_headers) > 1) {
953 modest_mail_operation_get_msgs_full (mail_op,
959 TnyIterator *iter = tny_list_create_iterator (not_opened_headers);
960 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter));
961 modest_mail_operation_get_msg (mail_op, header, open_msg_cb, NULL);
962 g_object_unref (header);
963 g_object_unref (iter);
965 g_object_unref (mail_op);
969 if (not_opened_headers != NULL)
970 g_object_unref (not_opened_headers);
974 modest_ui_actions_on_open (GtkAction *action, ModestWindow *win)
979 headers = get_selected_headers (win);
984 _modest_ui_actions_open (headers, win);
986 g_object_unref(headers);
991 free_reply_forward_helper (gpointer data)
993 ReplyForwardHelper *helper;
995 helper = (ReplyForwardHelper *) data;
996 g_free (helper->account_name);
997 g_slice_free (ReplyForwardHelper, helper);
1001 reply_forward_cb (ModestMailOperation *mail_op,
1007 ReplyForwardHelper *rf_helper;
1008 ModestWindow *msg_win = NULL;
1009 ModestEditType edit_type;
1011 TnyAccount *account = NULL;
1012 ModestWindowMgr *mgr = NULL;
1013 gchar *signature = NULL;
1015 /* If there was any error. The mail operation could be NULL,
1016 this means that we already have the message downloaded and
1017 that we didn't do a mail operation to retrieve it */
1018 if (mail_op && !modest_ui_actions_msg_retrieval_check (mail_op, header, msg))
1021 g_return_if_fail (user_data != NULL);
1022 rf_helper = (ReplyForwardHelper *) user_data;
1024 from = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(),
1025 rf_helper->account_name);
1026 if (modest_account_mgr_get_bool (modest_runtime_get_account_mgr(),
1027 rf_helper->account_name,
1028 MODEST_ACCOUNT_USE_SIGNATURE, FALSE)) {
1029 signature = modest_account_mgr_get_string (modest_runtime_get_account_mgr (),
1030 rf_helper->account_name,
1031 MODEST_ACCOUNT_SIGNATURE, FALSE);
1034 /* Create reply mail */
1035 switch (rf_helper->action) {
1038 modest_tny_msg_create_reply_msg (msg, from, signature,
1039 rf_helper->reply_forward_type,
1040 MODEST_TNY_MSG_REPLY_MODE_SENDER);
1042 case ACTION_REPLY_TO_ALL:
1044 modest_tny_msg_create_reply_msg (msg, from, signature, rf_helper->reply_forward_type,
1045 MODEST_TNY_MSG_REPLY_MODE_ALL);
1046 edit_type = MODEST_EDIT_TYPE_REPLY;
1048 case ACTION_FORWARD:
1050 modest_tny_msg_create_forward_msg (msg, from, signature, rf_helper->reply_forward_type);
1051 edit_type = MODEST_EDIT_TYPE_FORWARD;
1054 g_return_if_reached ();
1061 g_printerr ("modest: failed to create message\n");
1065 account = modest_tny_account_store_get_server_account (modest_runtime_get_account_store(),
1066 rf_helper->account_name,
1067 TNY_ACCOUNT_TYPE_STORE);
1069 g_printerr ("modest: failed to get tnyaccount for '%s'\n", rf_helper->account_name);
1073 /* Create and register the windows */
1074 msg_win = modest_msg_edit_window_new (new_msg, rf_helper->account_name);
1075 mgr = modest_runtime_get_window_mgr ();
1076 modest_window_mgr_register_window (mgr, msg_win);
1078 if (rf_helper->parent_window != NULL) {
1079 gdouble parent_zoom;
1081 parent_zoom = modest_window_get_zoom (MODEST_WINDOW (rf_helper->parent_window));
1082 modest_window_set_zoom (msg_win, parent_zoom);
1085 /* Show edit window */
1086 gtk_widget_show_all (GTK_WIDGET (msg_win));
1090 g_object_unref (msg_win);
1092 g_object_unref (G_OBJECT (new_msg));
1094 g_object_unref (G_OBJECT (account));
1095 /* g_object_unref (msg); */
1096 g_object_unref (header);
1097 free_reply_forward_helper (rf_helper);
1101 * Checks a list of headers. If any of them are not currently
1102 * downloaded (CACHED) then it asks the user for permission to
1105 * Returns FALSE if the user does not want to download the
1106 * messages. Returns TRUE if the user allowed the download or if all
1107 * of them are currently downloaded
1110 download_uncached_messages (TnyList *header_list,
1116 gint uncached_messages = 0;
1118 iter = tny_list_create_iterator (header_list);
1119 while (!tny_iterator_is_done (iter)) {
1122 header = TNY_HEADER (tny_iterator_get_current (iter));
1124 if (!(tny_header_get_flags (header) & TNY_HEADER_FLAG_CACHED))
1125 uncached_messages ++;
1126 g_object_unref (header);
1129 tny_iterator_next (iter);
1131 g_object_unref (iter);
1133 /* Ask for user permission to download the messages */
1135 if (uncached_messages > 0) {
1136 GtkResponseType response;
1138 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
1139 _("emev_nc_include_original"));
1142 modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
1143 ngettext("mcen_nc_get_msg",
1145 uncached_messages));
1146 if (response == GTK_RESPONSE_CANCEL)
1149 /* If a download will be necessary, make sure that we have a connection: */
1150 retval = modest_platform_connect_and_wait(win, NULL);
1158 * Common code for the reply and forward actions
1161 reply_forward (ReplyForwardAction action, ModestWindow *win)
1163 ModestMailOperation *mail_op = NULL;
1164 TnyList *header_list = NULL;
1165 ReplyForwardHelper *rf_helper = NULL;
1166 guint reply_forward_type;
1167 gboolean continue_download;
1169 g_return_if_fail (MODEST_IS_WINDOW(win));
1171 /* we need an account when editing */
1172 if (!modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE)) {
1173 run_account_setup_wizard (win);
1177 header_list = get_selected_headers (win);
1181 /* Check that the messages have been previously downloaded */
1182 continue_download = download_uncached_messages (header_list, GTK_WINDOW (win), TRUE);
1183 if (!continue_download) {
1184 g_object_unref (header_list);
1188 reply_forward_type =
1189 modest_conf_get_int (modest_runtime_get_conf (),
1190 (action == ACTION_FORWARD) ? MODEST_CONF_FORWARD_TYPE : MODEST_CONF_REPLY_TYPE,
1192 /* We assume that we can only select messages of the
1193 same folder and that we reply all of them from the
1194 same account. In fact the interface currently only
1195 allows single selection */
1198 rf_helper = g_slice_new0 (ReplyForwardHelper);
1199 rf_helper->reply_forward_type = reply_forward_type;
1200 rf_helper->action = action;
1201 rf_helper->account_name = g_strdup (modest_window_get_active_account (win));
1203 if ((win != NULL) && (MODEST_IS_WINDOW (win)))
1204 rf_helper->parent_window = GTK_WIDGET (win);
1205 if (!rf_helper->account_name)
1206 rf_helper->account_name =
1207 modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
1209 if (MODEST_IS_MSG_VIEW_WINDOW(win)) {
1212 /* Get header and message. Do not free them here, the
1213 reply_forward_cb must do it */
1214 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW(win));
1215 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW(win));
1216 if (!msg || !header) {
1218 g_object_unref (msg);
1220 g_object_unref (header);
1221 g_printerr ("modest: no message found\n");
1224 reply_forward_cb (NULL, header, msg, rf_helper);
1230 /* Retrieve messages */
1231 mail_op = modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE,
1233 modest_ui_actions_get_msgs_full_error_handler,
1235 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
1237 /* Only reply/forward to one message */
1238 iter = tny_list_create_iterator (header_list);
1239 header = TNY_HEADER (tny_iterator_get_current (iter));
1240 g_object_unref (iter);
1243 modest_mail_operation_get_msg (mail_op,
1248 /* modest_mail_operation_get_msgs_full (mail_op, */
1250 /* reply_forward_cb, */
1252 /* free_reply_forward_helper); */
1254 g_object_unref (header);
1258 g_object_unref(mail_op);
1262 g_object_unref (header_list);
1266 modest_ui_actions_on_reply (GtkAction *action, ModestWindow *win)
1268 g_return_if_fail (MODEST_IS_WINDOW(win));
1270 reply_forward (ACTION_REPLY, win);
1274 modest_ui_actions_on_forward (GtkAction *action, ModestWindow *win)
1276 g_return_if_fail (MODEST_IS_WINDOW(win));
1278 reply_forward (ACTION_FORWARD, win);
1282 modest_ui_actions_on_reply_all (GtkAction *action, ModestWindow *win)
1284 g_return_if_fail (MODEST_IS_WINDOW(win));
1286 reply_forward (ACTION_REPLY_TO_ALL, win);
1290 modest_ui_actions_on_next (GtkAction *action,
1291 ModestWindow *window)
1293 if (MODEST_IS_MAIN_WINDOW (window)) {
1294 GtkWidget *header_view;
1296 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
1297 MODEST_WIDGET_TYPE_HEADER_VIEW);
1301 modest_header_view_select_next (MODEST_HEADER_VIEW(header_view));
1302 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
1303 modest_msg_view_window_select_next_message (MODEST_MSG_VIEW_WINDOW (window));
1305 g_return_if_reached ();
1310 modest_ui_actions_on_prev (GtkAction *action,
1311 ModestWindow *window)
1313 g_return_if_fail (MODEST_IS_WINDOW(window));
1315 if (MODEST_IS_MAIN_WINDOW (window)) {
1316 GtkWidget *header_view;
1317 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
1318 MODEST_WIDGET_TYPE_HEADER_VIEW);
1322 modest_header_view_select_prev (MODEST_HEADER_VIEW(header_view));
1323 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
1324 modest_msg_view_window_select_previous_message (MODEST_MSG_VIEW_WINDOW (window));
1326 g_return_if_reached ();
1331 modest_ui_actions_on_sort (GtkAction *action,
1332 ModestWindow *window)
1334 g_return_if_fail (MODEST_IS_WINDOW(window));
1336 if (MODEST_IS_MAIN_WINDOW (window)) {
1337 GtkWidget *header_view;
1338 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
1339 MODEST_WIDGET_TYPE_HEADER_VIEW);
1341 modest_platform_information_banner (NULL, NULL, _CS("ckdg_ib_nothing_to_sort"));
1346 /* Show sorting dialog */
1347 modest_platform_run_sort_dialog (GTK_WINDOW (window), MODEST_SORT_HEADERS);
1352 new_messages_arrived (ModestMailOperation *self,
1356 if (new_messages == 0)
1359 modest_platform_on_new_msg ();
1363 * This function performs the send & receive required actions. The
1364 * window is used to create the mail operation. Typically it should
1365 * always be the main window, but we pass it as argument in order to
1369 modest_ui_actions_do_send_receive (const gchar *account_name, ModestWindow *win)
1371 gchar *acc_name = NULL;
1372 ModestMailOperation *mail_op;
1374 /* If no account name was provided then get the current account, and if
1375 there is no current account then pick the default one: */
1376 if (!account_name) {
1377 acc_name = g_strdup (modest_window_get_active_account(win));
1379 acc_name = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
1381 g_printerr ("modest: cannot get default account\n");
1385 acc_name = g_strdup (account_name);
1388 /* Set send/receive operation in progress */
1389 modest_main_window_notify_send_receive_initied (MODEST_MAIN_WINDOW(win));
1391 mail_op = modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE,
1393 modest_ui_actions_send_receive_error_handler,
1396 g_signal_connect (G_OBJECT(mail_op), "progress-changed",
1397 G_CALLBACK (_on_send_receive_progress_changed),
1400 /* Send & receive. */
1401 /* TODO: The spec wants us to first do any pending deletions, before receiving. */
1402 /* Receive and then send. The operation is tagged initially as
1403 a receive operation because the account update performs a
1404 receive and then a send. The operation changes its type
1405 internally, so the progress objects will receive the proper
1406 progress information */
1407 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
1408 modest_mail_operation_update_account (mail_op, acc_name, new_messages_arrived, NULL);
1409 g_object_unref (G_OBJECT (mail_op));
1417 modest_ui_actions_do_cancel_send (const gchar *account_name,
1420 TnyTransportAccount *transport_account;
1421 TnySendQueue *send_queue = NULL;
1422 GError *error = NULL;
1424 /* Get transport account */
1426 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
1427 (modest_runtime_get_account_store(),
1429 TNY_ACCOUNT_TYPE_TRANSPORT));
1430 if (!transport_account) {
1431 g_printerr ("modest: no transport account found for '%s'\n", account_name);
1436 send_queue = TNY_SEND_QUEUE (modest_runtime_get_send_queue (transport_account));
1437 if (!TNY_IS_SEND_QUEUE(send_queue)) {
1438 g_set_error (&error, MODEST_MAIL_OPERATION_ERROR,
1439 MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND,
1440 "modest: could not find send queue for account\n");
1442 /* Keeep messages in outbox folder */
1443 tny_send_queue_cancel (send_queue, FALSE, &error);
1447 if (transport_account != NULL)
1448 g_object_unref (G_OBJECT (transport_account));
1452 modest_ui_actions_cancel_send_all (ModestWindow *win)
1454 GSList *account_names, *iter;
1456 account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
1459 iter = account_names;
1461 modest_ui_actions_do_cancel_send ((const char*) iter->data, win);
1462 iter = g_slist_next (iter);
1465 modest_account_mgr_free_account_names (account_names);
1466 account_names = NULL;
1470 modest_ui_actions_cancel_send (GtkAction *action, ModestWindow *win)
1473 /* Check if accounts exist */
1474 gboolean accounts_exist =
1475 modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
1477 /* If not, allow the user to create an account before trying to send/receive. */
1478 if (!accounts_exist)
1479 modest_ui_actions_on_accounts (NULL, win);
1481 /* Cancel all sending operaitons */
1482 modest_ui_actions_cancel_send_all (win);
1486 * Refreshes all accounts. This function will be used by automatic
1490 modest_ui_actions_do_send_receive_all (ModestWindow *win)
1492 GSList *account_names, *iter;
1494 account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
1497 iter = account_names;
1499 modest_ui_actions_do_send_receive ((const char*) iter->data, win);
1500 iter = g_slist_next (iter);
1503 modest_account_mgr_free_account_names (account_names);
1504 account_names = NULL;
1508 modest_do_refresh_current_folder(ModestWindow *win)
1510 /* Refresh currently selected folder. Note that if we only
1511 want to retreive the headers, then the refresh only will
1512 invoke a poke_status over all folders, i.e., only the
1513 total/unread count will be updated */
1514 if (MODEST_IS_MAIN_WINDOW (win)) {
1515 GtkWidget *header_view, *folder_view;
1516 TnyFolderStore *folder_store;
1518 /* Get folder and header view */
1520 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
1521 MODEST_WIDGET_TYPE_FOLDER_VIEW);
1523 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
1525 if (folder_store && TNY_IS_FOLDER (folder_store)) {
1527 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
1528 MODEST_WIDGET_TYPE_HEADER_VIEW);
1530 /* We do not need to set the contents style
1531 because it hasn't changed. We also do not
1532 need to save the widget status. Just force
1534 modest_header_view_set_folder (MODEST_HEADER_VIEW(header_view),
1535 TNY_FOLDER (folder_store),
1536 folder_refreshed_cb,
1537 MODEST_MAIN_WINDOW (win));
1541 g_object_unref (folder_store);
1547 * Handler of the click on Send&Receive button in the main toolbar
1550 modest_ui_actions_on_send_receive (GtkAction *action, ModestWindow *win)
1552 /* Check if accounts exist */
1553 gboolean accounts_exist =
1554 modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
1556 /* If not, allow the user to create an account before trying to send/receive. */
1557 if (!accounts_exist)
1558 modest_ui_actions_on_accounts (NULL, win);
1560 modest_do_refresh_current_folder (win);
1562 /* Refresh the active account */
1563 modest_ui_actions_do_send_receive (NULL, win);
1568 modest_ui_actions_toggle_header_list_view (GtkAction *action, ModestMainWindow *main_window)
1571 GtkWidget *header_view;
1573 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1575 header_view = modest_main_window_get_child_widget (main_window,
1576 MODEST_WIDGET_TYPE_HEADER_VIEW);
1580 conf = modest_runtime_get_conf ();
1582 /* what is saved/restored is depending on the style; thus; we save with
1583 * old style, then update the style, and restore for this new style
1585 modest_widget_memory_save (conf, G_OBJECT(header_view), MODEST_CONF_HEADER_VIEW_KEY);
1587 if (modest_header_view_get_style
1588 (MODEST_HEADER_VIEW(header_view)) == MODEST_HEADER_VIEW_STYLE_DETAILS)
1589 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
1590 MODEST_HEADER_VIEW_STYLE_TWOLINES);
1592 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
1593 MODEST_HEADER_VIEW_STYLE_DETAILS);
1595 modest_widget_memory_restore (conf, G_OBJECT(header_view),
1596 MODEST_CONF_HEADER_VIEW_KEY);
1601 modest_ui_actions_on_header_selected (ModestHeaderView *header_view,
1603 ModestMainWindow *main_window)
1605 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1606 g_return_if_fail (MODEST_IS_HEADER_VIEW (header_view));
1608 /* If no header has been selected then exit */
1613 if (!gtk_widget_is_focus (GTK_WIDGET(header_view)))
1614 gtk_widget_grab_focus (GTK_WIDGET(header_view));
1616 /* Update Main window title */
1617 if (gtk_widget_is_focus (GTK_WIDGET(header_view))) {
1618 const gchar *subject = tny_header_get_subject (header);
1619 if (subject && strlen(subject) > 0)
1620 gtk_window_set_title (GTK_WINDOW (main_window), subject);
1622 gtk_window_set_title (GTK_WINDOW (main_window), _("mail_va_no_subject"));
1625 /* Update toolbar dimming state */
1626 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
1630 modest_ui_actions_on_header_activated (ModestHeaderView *header_view,
1632 ModestMainWindow *main_window)
1636 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1641 headers = tny_simple_list_new ();
1642 tny_list_prepend (headers, G_OBJECT (header));
1644 _modest_ui_actions_open (headers, MODEST_WINDOW (main_window));
1646 g_object_unref (headers);
1650 set_active_account_from_tny_account (TnyAccount *account,
1651 ModestWindow *window)
1653 const gchar *server_acc_name = tny_account_get_id (account);
1655 /* We need the TnyAccount provided by the
1656 account store because that is the one that
1657 knows the name of the Modest account */
1658 TnyAccount *modest_server_account = modest_server_account =
1659 modest_tny_account_store_get_tny_account_by (modest_runtime_get_account_store (),
1660 MODEST_TNY_ACCOUNT_STORE_QUERY_ID,
1663 const gchar *modest_acc_name =
1664 modest_tny_account_get_parent_modest_account_name_for_server_account (modest_server_account);
1665 modest_window_set_active_account (window, modest_acc_name);
1666 g_object_unref (modest_server_account);
1671 folder_refreshed_cb (ModestMailOperation *mail_op,
1675 ModestMainWindow *win = NULL;
1676 GtkWidget *header_view;
1677 TnyFolder *current_folder;
1679 g_return_if_fail (TNY_IS_FOLDER (folder));
1681 win = MODEST_MAIN_WINDOW (user_data);
1683 modest_main_window_get_child_widget(win, MODEST_WIDGET_TYPE_HEADER_VIEW);
1686 current_folder = modest_header_view_get_folder (MODEST_HEADER_VIEW (header_view));
1687 if (current_folder != NULL && folder != current_folder) {
1692 /* Check if folder is empty and set headers view contents style */
1693 if (tny_folder_get_all_count (folder) == 0) {
1694 printf ("DEBUG: %s: tny_folder_get_all_count() returned 0.\n", __FUNCTION__);
1695 modest_main_window_set_contents_style (win,
1696 MODEST_MAIN_WINDOW_CONTENTS_STYLE_EMPTY);
1698 printf ("DEBUG: %s: tny_folder_get_all_count() returned >0.\n", __FUNCTION__);
1703 modest_ui_actions_on_folder_selection_changed (ModestFolderView *folder_view,
1704 TnyFolderStore *folder_store,
1706 ModestMainWindow *main_window)
1709 GtkWidget *header_view;
1711 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1713 header_view = modest_main_window_get_child_widget(main_window,
1714 MODEST_WIDGET_TYPE_HEADER_VIEW);
1718 conf = modest_runtime_get_conf ();
1720 if (TNY_IS_ACCOUNT (folder_store)) {
1722 /* Update active account */
1723 set_active_account_from_tny_account (TNY_ACCOUNT (folder_store), MODEST_WINDOW (main_window));
1724 /* Show account details */
1725 modest_main_window_set_contents_style (main_window, MODEST_MAIN_WINDOW_CONTENTS_STYLE_DETAILS);
1728 if (TNY_IS_FOLDER (folder_store) && selected) {
1730 /* Update the active account */
1731 TnyAccount *account = modest_tny_folder_get_account (TNY_FOLDER (folder_store));
1733 set_active_account_from_tny_account (account, MODEST_WINDOW (main_window));
1734 g_object_unref (account);
1738 /* Set the header style by default, it could
1739 be changed later by the refresh callback to
1741 modest_main_window_set_contents_style (main_window,
1742 MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS);
1744 /* Set folder on header view. This function
1745 will call tny_folder_refresh_async so we
1746 pass a callback that will be called when
1747 finished. We use that callback to set the
1748 empty view if there are no messages */
1749 modest_header_view_set_folder (MODEST_HEADER_VIEW(header_view),
1750 TNY_FOLDER (folder_store),
1751 folder_refreshed_cb,
1754 /* Restore configuration. We need to do this
1755 *after* the set_folder because the widget
1756 memory asks the header view about its
1758 modest_widget_memory_restore (modest_runtime_get_conf (),
1759 G_OBJECT(header_view),
1760 MODEST_CONF_HEADER_VIEW_KEY);
1762 /* Update the active account */
1763 modest_window_set_active_account (MODEST_WINDOW (main_window), NULL);
1764 /* Save only if we're seeing headers */
1765 if (modest_main_window_get_contents_style (main_window) ==
1766 MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS)
1767 modest_widget_memory_save (conf, G_OBJECT (header_view),
1768 MODEST_CONF_HEADER_VIEW_KEY);
1769 modest_header_view_clear (MODEST_HEADER_VIEW(header_view));
1773 /* Update toolbar dimming state */
1774 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
1778 modest_ui_actions_on_item_not_found (ModestHeaderView *header_view,ModestItemType type,
1785 item = (type == MODEST_ITEM_TYPE_FOLDER) ? "folder" : "message";
1787 online = tny_device_is_online (modest_runtime_get_device());
1790 /* already online -- the item is simply not there... */
1791 dialog = gtk_message_dialog_new (GTK_WINDOW (win),
1793 GTK_MESSAGE_WARNING,
1795 _("The %s you selected cannot be found"),
1797 gtk_dialog_run (GTK_DIALOG(dialog));
1799 dialog = gtk_dialog_new_with_buttons (_("Connection requested"),
1803 GTK_RESPONSE_REJECT,
1805 GTK_RESPONSE_ACCEPT,
1807 txt = g_strdup_printf (_("This %s is not available in offline mode.\n"
1808 "Do you want to get online?"), item);
1809 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
1810 gtk_label_new (txt), FALSE, FALSE, 0);
1811 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
1814 gtk_window_set_default_size (GTK_WINDOW(dialog), 300, 300);
1815 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
1816 /* TODO: Comment about why is this commented out: */
1817 /* modest_platform_connect_and_wait (); */
1820 gtk_widget_destroy (dialog);
1824 modest_ui_actions_on_msg_link_hover (ModestMsgView *msgview, const gchar* link,
1827 /* g_message ("%s %s", __FUNCTION__, link); */
1832 modest_ui_actions_on_msg_link_clicked (ModestMsgView *msgview, const gchar* link,
1835 modest_platform_activate_uri (link);
1839 modest_ui_actions_on_msg_link_contextual (ModestMsgView *msgview, const gchar* link,
1842 modest_platform_show_uri_popup (link);
1846 modest_ui_actions_on_msg_attachment_clicked (ModestMsgView *msgview, TnyMimePart *mime_part,
1849 modest_msg_view_window_view_attachment (MODEST_MSG_VIEW_WINDOW (win), mime_part);
1853 modest_ui_actions_on_msg_recpt_activated (ModestMsgView *msgview,
1854 const gchar *address,
1857 /* g_message ("%s %s", __FUNCTION__, address); */
1861 modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edit_window)
1863 TnyTransportAccount *transport_account;
1864 ModestMailOperation *mail_operation;
1866 gchar *account_name, *from;
1867 ModestAccountMgr *account_mgr;
1868 gchar *info_text = NULL;
1870 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window));
1872 data = modest_msg_edit_window_get_msg_data (edit_window);
1874 account_mgr = modest_runtime_get_account_mgr();
1875 account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
1877 account_name = modest_account_mgr_get_default_account (account_mgr);
1878 if (!account_name) {
1879 g_printerr ("modest: no account found\n");
1880 modest_msg_edit_window_free_msg_data (edit_window, data);
1884 if (!strcmp (account_name, MODEST_LOCAL_FOLDERS_ACCOUNT_ID)) {
1885 account_name = g_strdup (data->account_name);
1889 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
1890 (modest_runtime_get_account_store(),
1892 TNY_ACCOUNT_TYPE_TRANSPORT));
1893 if (!transport_account) {
1894 g_printerr ("modest: no transport account found for '%s'\n", account_name);
1895 g_free (account_name);
1896 modest_msg_edit_window_free_msg_data (edit_window, data);
1899 from = modest_account_mgr_get_from_string (account_mgr, account_name);
1901 /* Create the mail operation */
1902 mail_operation = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_INFO, G_OBJECT(edit_window));
1903 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
1905 modest_mail_operation_save_to_drafts (mail_operation,
1917 data->priority_flags);
1920 g_free (account_name);
1921 g_object_unref (G_OBJECT (transport_account));
1922 g_object_unref (G_OBJECT (mail_operation));
1924 modest_msg_edit_window_free_msg_data (edit_window, data);
1926 info_text = g_strdup_printf (_("mail_va_saved_to_drafts"), _("mcen_me_folder_drafts"));
1927 modest_platform_information_banner (NULL, NULL, info_text);
1931 /* For instance, when clicking the Send toolbar button when editing a message: */
1933 modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
1935 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window));
1937 if (!modest_msg_edit_window_check_names (edit_window, TRUE))
1940 /* Offer the connection dialog, if necessary: */
1941 if (!modest_platform_connect_and_wait (GTK_WINDOW (edit_window), NULL))
1944 /* FIXME: Code added just for testing. The final version will
1945 use the send queue provided by tinymail and some
1947 ModestAccountMgr *account_mgr = modest_runtime_get_account_mgr();
1948 gchar *account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
1950 account_name = modest_account_mgr_get_default_account (account_mgr);
1952 if (!account_name) {
1953 g_printerr ("modest: no account found\n");
1957 MsgData *data = modest_msg_edit_window_get_msg_data (edit_window);
1959 if (!strcmp (account_name, MODEST_LOCAL_FOLDERS_ACCOUNT_ID)) {
1960 account_name = g_strdup (data->account_name);
1963 /* Get the currently-active transport account for this modest account: */
1964 TnyTransportAccount *transport_account =
1965 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_transport_account_for_open_connection
1966 (modest_runtime_get_account_store(),
1968 if (!transport_account) {
1969 g_printerr ("modest: no transport account found for '%s'\n", account_name);
1970 g_free (account_name);
1971 modest_msg_edit_window_free_msg_data (edit_window, data);
1975 gchar *from = modest_account_mgr_get_from_string (account_mgr, account_name);
1977 /* mail content checks and dialogs */
1978 if (data->subject == NULL || data->subject[0] == '\0') {
1979 GtkResponseType response;
1980 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (edit_window),
1981 _("mcen_nc_subject_is_empty_send"));
1982 if (response == GTK_RESPONSE_CANCEL) {
1983 g_free (account_name);
1988 if (data->plain_body == NULL || data->plain_body[0] == '\0') {
1989 GtkResponseType response;
1990 gchar *note_message;
1991 gchar *note_subject = data->subject;
1992 if (note_subject == NULL || note_subject[0] == '\0')
1993 note_subject = _("mail_va_no_subject");
1994 note_message = g_strdup_printf (_("emev_ni_ui_smtp_message_null"), note_subject);
1995 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (edit_window),
1997 g_free (note_message);
1998 if (response == GTK_RESPONSE_CANCEL) {
1999 g_free (account_name);
2004 modest_platform_information_banner (NULL, NULL, _("mcen_ib_outbox_waiting_to_be_sent"));
2006 /* Create the mail operation */
2007 ModestMailOperation *mail_operation = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_SEND, G_OBJECT(edit_window));
2008 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
2010 modest_mail_operation_send_new_mail (mail_operation,
2021 data->priority_flags);
2025 g_free (account_name);
2026 g_object_unref (G_OBJECT (transport_account));
2027 g_object_unref (G_OBJECT (mail_operation));
2029 modest_msg_edit_window_free_msg_data (edit_window, data);
2030 modest_msg_edit_window_set_sent (edit_window, TRUE);
2032 /* Save settings and close the window: */
2033 modest_ui_actions_on_close_window (NULL, MODEST_WINDOW (edit_window));
2037 modest_ui_actions_on_toggle_bold (GtkToggleAction *action,
2038 ModestMsgEditWindow *window)
2040 ModestMsgEditFormatState *format_state = NULL;
2042 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2043 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
2045 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2048 format_state = modest_msg_edit_window_get_format_state (window);
2049 g_return_if_fail (format_state != NULL);
2051 format_state->bold = gtk_toggle_action_get_active (action);
2052 modest_msg_edit_window_set_format_state (window, format_state);
2053 g_free (format_state);
2058 modest_ui_actions_on_toggle_italics (GtkToggleAction *action,
2059 ModestMsgEditWindow *window)
2061 ModestMsgEditFormatState *format_state = NULL;
2063 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2064 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
2066 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2069 format_state = modest_msg_edit_window_get_format_state (window);
2070 g_return_if_fail (format_state != NULL);
2072 format_state->italics = gtk_toggle_action_get_active (action);
2073 modest_msg_edit_window_set_format_state (window, format_state);
2074 g_free (format_state);
2079 modest_ui_actions_on_toggle_bullets (GtkToggleAction *action,
2080 ModestMsgEditWindow *window)
2082 ModestMsgEditFormatState *format_state = NULL;
2084 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2085 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
2087 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2090 format_state = modest_msg_edit_window_get_format_state (window);
2091 g_return_if_fail (format_state != NULL);
2093 format_state->bullet = gtk_toggle_action_get_active (action);
2094 modest_msg_edit_window_set_format_state (window, format_state);
2095 g_free (format_state);
2100 modest_ui_actions_on_change_justify (GtkRadioAction *action,
2101 GtkRadioAction *selected,
2102 ModestMsgEditWindow *window)
2104 ModestMsgEditFormatState *format_state = NULL;
2105 GtkJustification value;
2107 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2109 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2112 value = gtk_radio_action_get_current_value (selected);
2114 format_state = modest_msg_edit_window_get_format_state (window);
2115 g_return_if_fail (format_state != NULL);
2117 format_state->justification = value;
2118 modest_msg_edit_window_set_format_state (window, format_state);
2119 g_free (format_state);
2123 modest_ui_actions_on_select_editor_color (GtkAction *action,
2124 ModestMsgEditWindow *window)
2126 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2127 g_return_if_fail (GTK_IS_ACTION (action));
2129 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2132 modest_msg_edit_window_select_color (window);
2136 modest_ui_actions_on_select_editor_background_color (GtkAction *action,
2137 ModestMsgEditWindow *window)
2139 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2140 g_return_if_fail (GTK_IS_ACTION (action));
2142 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2145 modest_msg_edit_window_select_background_color (window);
2149 modest_ui_actions_on_insert_image (GtkAction *action,
2150 ModestMsgEditWindow *window)
2152 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2153 g_return_if_fail (GTK_IS_ACTION (action));
2155 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2158 modest_msg_edit_window_insert_image (window);
2162 modest_ui_actions_on_attach_file (GtkAction *action,
2163 ModestMsgEditWindow *window)
2165 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2166 g_return_if_fail (GTK_IS_ACTION (action));
2168 modest_msg_edit_window_offer_attach_file (window);
2172 modest_ui_actions_on_remove_attachments (GtkAction *action,
2173 ModestMsgEditWindow *window)
2175 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2176 g_return_if_fail (GTK_IS_ACTION (action));
2178 modest_msg_edit_window_remove_attachments (window, NULL);
2182 modest_ui_actions_new_folder_error_handler (ModestMailOperation *mail_op,
2185 ModestMainWindow *window = MODEST_MAIN_WINDOW (user_data);
2186 const GError *error = modest_mail_operation_get_error (mail_op);
2190 modest_platform_information_banner (GTK_WIDGET (window), NULL,
2191 modest_mail_operation_get_error (mail_op)->message);
2196 modest_ui_actions_create_folder(GtkWidget *parent_window,
2197 GtkWidget *folder_view)
2199 TnyFolderStore *parent_folder;
2201 parent_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
2203 if (parent_folder) {
2204 gboolean finished = FALSE;
2206 gchar *folder_name = NULL, *suggested_name = NULL;
2208 /* Run the new folder dialog */
2210 result = modest_platform_run_new_folder_dialog (GTK_WINDOW (parent_window),
2215 g_free (suggested_name);
2216 suggested_name = NULL;
2218 if (result == GTK_RESPONSE_REJECT) {
2221 ModestMailOperation *mail_op;
2222 TnyFolder *new_folder = NULL;
2224 mail_op = modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_INFO,
2225 G_OBJECT(parent_window),
2226 modest_ui_actions_new_folder_error_handler,
2229 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
2231 new_folder = modest_mail_operation_create_folder (mail_op,
2233 (const gchar *) folder_name);
2235 modest_folder_view_select_folder (MODEST_FOLDER_VIEW(folder_view),
2238 g_object_unref (new_folder);
2241 g_object_unref (mail_op);
2244 suggested_name = folder_name;
2248 g_object_unref (parent_folder);
2253 modest_ui_actions_on_new_folder (GtkAction *action, ModestMainWindow *main_window)
2255 GtkWidget *folder_view;
2257 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2259 folder_view = modest_main_window_get_child_widget (main_window,
2260 MODEST_WIDGET_TYPE_FOLDER_VIEW);
2264 modest_ui_actions_create_folder (GTK_WIDGET (main_window), folder_view);
2268 modest_ui_actions_rename_folder_error_handler (ModestMailOperation *mail_op,
2271 GObject *win = modest_mail_operation_get_source (mail_op);
2272 const GError *error = NULL;
2273 const gchar *message = NULL;
2275 /* Get error message */
2276 error = modest_mail_operation_get_error (mail_op);
2277 if (error != NULL && error->message != NULL) {
2278 message = error->message;
2280 message = _("!!! FIXME: Unable to rename");
2283 /* Show notification dialog */
2284 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL, message);
2285 g_object_unref (win);
2289 modest_ui_actions_on_rename_folder (GtkAction *action,
2290 ModestMainWindow *main_window)
2292 TnyFolderStore *folder;
2293 GtkWidget *folder_view;
2294 GtkWidget *header_view;
2296 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2298 folder_view = modest_main_window_get_child_widget (main_window,
2299 MODEST_WIDGET_TYPE_FOLDER_VIEW);
2303 header_view = modest_main_window_get_child_widget (main_window,
2304 MODEST_WIDGET_TYPE_HEADER_VIEW);
2309 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
2313 /* Offer the connection dialog if necessary: */
2314 if (!modest_platform_connect_and_wait_if_network_folderstore (NULL, folder)) {
2315 g_object_unref (G_OBJECT (folder));
2320 if (TNY_IS_FOLDER (folder)) {
2323 const gchar *current_name;
2325 current_name = tny_folder_get_name (TNY_FOLDER (folder));
2326 response = modest_platform_run_rename_folder_dialog (GTK_WINDOW (main_window), NULL,
2327 current_name, &folder_name);
2329 if (response == GTK_RESPONSE_ACCEPT && strlen (folder_name) > 0) {
2330 ModestMailOperation *mail_op;
2333 modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_INFO,
2334 G_OBJECT(main_window),
2335 modest_ui_actions_rename_folder_error_handler,
2339 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
2342 modest_header_view_clear (MODEST_HEADER_VIEW (header_view));
2344 modest_folder_view_select_folder (MODEST_FOLDER_VIEW(folder_view),
2345 TNY_FOLDER(folder), TRUE);
2348 modest_header_view_clear ((ModestHeaderView *) header_view);
2350 modest_mail_operation_rename_folder (mail_op,
2351 TNY_FOLDER (folder),
2352 (const gchar *) folder_name);
2354 g_object_unref (mail_op);
2355 g_free (folder_name);
2358 g_object_unref (folder);
2362 modest_ui_actions_delete_folder_error_handler (ModestMailOperation *mail_op,
2365 GObject *win = modest_mail_operation_get_source (mail_op);
2367 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
2368 _("mail_in_ui_folder_delete_error"));
2369 g_object_unref (win);
2373 delete_folder (ModestMainWindow *main_window, gboolean move_to_trash)
2375 TnyFolderStore *folder;
2376 GtkWidget *folder_view;
2380 g_return_if_fail (MODEST_IS_MAIN_WINDOW (main_window));
2382 folder_view = modest_main_window_get_child_widget (main_window,
2383 MODEST_WIDGET_TYPE_FOLDER_VIEW);
2387 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
2389 /* Show an error if it's an account */
2390 if (!TNY_IS_FOLDER (folder)) {
2391 modest_platform_run_information_dialog (GTK_WINDOW (main_window),
2392 _("mail_in_ui_folder_delete_error"));
2393 g_object_unref (G_OBJECT (folder));
2397 /* Offer the connection dialog if necessary: */
2398 if (!modest_platform_connect_and_wait_if_network_folderstore (NULL, folder)) {
2399 g_object_unref (G_OBJECT (folder));
2404 message = g_strdup_printf (_("mcen_nc_delete_folder_text"),
2405 tny_folder_get_name (TNY_FOLDER (folder)));
2406 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (main_window),
2407 (const gchar *) message);
2410 if (response == GTK_RESPONSE_OK) {
2411 ModestMailOperation *mail_op =
2412 modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_DELETE,
2413 G_OBJECT(main_window),
2414 modest_ui_actions_delete_folder_error_handler,
2417 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
2419 modest_mail_operation_remove_folder (mail_op, TNY_FOLDER (folder), move_to_trash);
2420 g_object_unref (G_OBJECT (mail_op));
2423 g_object_unref (G_OBJECT (folder));
2427 modest_ui_actions_on_delete_folder (GtkAction *action,
2428 ModestMainWindow *main_window)
2430 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2432 delete_folder (main_window, FALSE);
2436 modest_ui_actions_on_move_folder_to_trash_folder (GtkAction *action, ModestMainWindow *main_window)
2438 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2440 delete_folder (main_window, TRUE);
2445 show_error (GtkWidget *parent_widget, const gchar* text)
2447 hildon_banner_show_information(parent_widget, NULL, text);
2450 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_window, text)); */
2452 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
2459 gtk_dialog_run (dialog);
2460 gtk_widget_destroy (GTK_WIDGET (dialog));
2465 modest_ui_actions_on_password_requested (TnyAccountStore *account_store,
2466 const gchar* server_account_name,
2471 ModestMainWindow *main_window)
2473 g_return_if_fail(server_account_name);
2474 /* printf("DEBUG: %s: server_account_name=%s\n", __FUNCTION__, server_account_name); */
2476 /* Initalize output parameters: */
2483 #ifdef MODEST_PLATFORM_MAEMO
2484 /* Maemo uses a different (awkward) button order,
2485 * It should probably just use gtk_alternative_dialog_button_order ().
2487 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
2491 GTK_RESPONSE_ACCEPT,
2493 GTK_RESPONSE_REJECT,
2496 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
2500 GTK_RESPONSE_REJECT,
2502 GTK_RESPONSE_ACCEPT,
2504 #endif /* MODEST_PLATFORM_MAEMO */
2506 gtk_window_set_transient_for (GTK_WINDOW(dialog), GTK_WINDOW(main_window));
2508 gchar *server_name = modest_server_account_get_hostname (
2509 modest_runtime_get_account_mgr(), server_account_name);
2510 if (!server_name) {/* This happened once, though I don't know why. murrayc. */
2511 g_warning("%s: Could not get server name for server account '%s'", __FUNCTION__, server_account_name);
2516 /* This causes a warning because the logical ID has no %s in it,
2517 * though the translation does, but there is not much we can do about that: */
2518 gchar *txt = g_strdup_printf (_("mail_ia_password_info"), server_name);
2519 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), gtk_label_new(txt),
2522 g_free (server_name);
2526 gchar *initial_username = modest_server_account_get_username (
2527 modest_runtime_get_account_mgr(), server_account_name);
2529 GtkWidget *entry_username = gtk_entry_new ();
2530 if (initial_username)
2531 gtk_entry_set_text (GTK_ENTRY (entry_username), initial_username);
2532 /* Dim this if a connection has ever succeeded with this username,
2533 * as per the UI spec: */
2534 const gboolean username_known =
2535 modest_server_account_get_username_has_succeeded(
2536 modest_runtime_get_account_mgr(), server_account_name);
2537 gtk_widget_set_sensitive (entry_username, !username_known);
2539 #ifdef MODEST_PLATFORM_MAEMO
2540 /* Auto-capitalization is the default, so let's turn it off: */
2541 hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_username), HILDON_GTK_INPUT_MODE_FULL);
2543 /* Create a size group to be used by all captions.
2544 * Note that HildonCaption does not create a default size group if we do not specify one.
2545 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
2546 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
2548 GtkWidget *caption = hildon_caption_new (sizegroup,
2549 _("mail_fi_username"), entry_username, NULL, HILDON_CAPTION_MANDATORY);
2550 gtk_widget_show (entry_username);
2551 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
2552 FALSE, FALSE, MODEST_MARGIN_HALF);
2553 gtk_widget_show (caption);
2555 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry_username,
2557 #endif /* MODEST_PLATFORM_MAEMO */
2560 GtkWidget *entry_password = gtk_entry_new ();
2561 gtk_entry_set_visibility (GTK_ENTRY(entry_password), FALSE);
2562 /* gtk_entry_set_invisible_char (GTK_ENTRY(entry_password), "*"); */
2564 #ifdef MODEST_PLATFORM_MAEMO
2565 /* Auto-capitalization is the default, so let's turn it off: */
2566 hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_password),
2567 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
2569 caption = hildon_caption_new (sizegroup,
2570 _("mail_fi_password"), entry_password, NULL, HILDON_CAPTION_MANDATORY);
2571 gtk_widget_show (entry_password);
2572 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
2573 FALSE, FALSE, MODEST_MARGIN_HALF);
2574 gtk_widget_show (caption);
2575 g_object_unref (sizegroup);
2577 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry_password,
2579 #endif /* MODEST_PLATFORM_MAEMO */
2581 /* This is not in the Maemo UI spec:
2582 remember_pass_check = gtk_check_button_new_with_label (_("Remember password"));
2583 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), remember_pass_check,
2587 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
2589 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
2591 *username = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_username)));
2593 modest_server_account_set_username (
2594 modest_runtime_get_account_mgr(), server_account_name,
2597 const gboolean username_was_changed =
2598 (strcmp (*username, initial_username) != 0);
2599 if (username_was_changed) {
2600 g_warning ("%s: tinymail does not yet support changing the "
2601 "username in the get_password() callback.\n", __FUNCTION__);
2606 *password = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_password)));
2608 /* We do not save the password in the configuration,
2609 * because this function is only called for passwords that should
2610 * not be remembered:
2611 modest_server_account_set_password (
2612 modest_runtime_get_account_mgr(), server_account_name,
2621 show_error(GTK_WIDGET (main_window), _("mail_ib_login_cancelled"));
2633 /* This is not in the Maemo UI spec:
2634 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (remember_pass_check)))
2640 gtk_widget_destroy (dialog);
2642 /* printf ("DEBUG: %s: cancel=%d\n", __FUNCTION__, *cancel); */
2646 modest_ui_actions_on_cut (GtkAction *action,
2647 ModestWindow *window)
2649 GtkWidget *focused_widget;
2650 GtkClipboard *clipboard;
2652 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
2653 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
2654 if (GTK_IS_EDITABLE (focused_widget)) {
2655 gtk_editable_cut_clipboard (GTK_EDITABLE(focused_widget));
2656 gtk_clipboard_set_can_store (clipboard, NULL, 0);
2657 gtk_clipboard_store (clipboard);
2658 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
2659 GtkTextBuffer *buffer;
2661 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
2662 gtk_text_buffer_cut_clipboard (buffer, clipboard, TRUE);
2663 gtk_clipboard_set_can_store (clipboard, NULL, 0);
2664 gtk_clipboard_store (clipboard);
2665 } else if (MODEST_IS_HEADER_VIEW (focused_widget)) {
2666 modest_header_view_cut_selection (MODEST_HEADER_VIEW (focused_widget));
2667 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
2668 modest_folder_view_cut_selection (MODEST_FOLDER_VIEW (focused_widget));
2673 modest_ui_actions_on_copy (GtkAction *action,
2674 ModestWindow *window)
2676 GtkClipboard *clipboard;
2677 GtkWidget *focused_widget;
2679 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
2680 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
2682 if (GTK_IS_LABEL (focused_widget)) {
2683 gtk_clipboard_set_text (clipboard, gtk_label_get_text (GTK_LABEL (focused_widget)), -1);
2684 gtk_clipboard_set_can_store (clipboard, NULL, 0);
2685 gtk_clipboard_store (clipboard);
2686 } else if (GTK_IS_EDITABLE (focused_widget)) {
2687 gtk_editable_copy_clipboard (GTK_EDITABLE(focused_widget));
2688 gtk_clipboard_set_can_store (clipboard, NULL, 0);
2689 gtk_clipboard_store (clipboard);
2690 } else if (GTK_IS_HTML (focused_widget)) {
2691 gtk_html_copy (GTK_HTML (focused_widget));
2692 gtk_clipboard_set_can_store (clipboard, NULL, 0);
2693 gtk_clipboard_store (clipboard);
2694 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
2695 GtkTextBuffer *buffer;
2696 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
2697 gtk_text_buffer_copy_clipboard (buffer, clipboard);
2698 gtk_clipboard_set_can_store (clipboard, NULL, 0);
2699 gtk_clipboard_store (clipboard);
2700 } else if (MODEST_IS_HEADER_VIEW (focused_widget)) {
2701 TnyList *header_list = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW (focused_widget));
2702 TnyIterator *iter = tny_list_create_iterator (header_list);
2703 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter));
2705 gboolean ask = FALSE;
2707 TnyFolder *folder = tny_header_get_folder (header);
2708 TnyAccount *account = tny_folder_get_account (folder);
2709 const gchar *proto_str = tny_account_get_proto (TNY_ACCOUNT (account));
2710 /* If it's POP then ask */
2711 ask = (modest_protocol_info_get_transport_store_protocol (proto_str) ==
2712 MODEST_PROTOCOL_STORE_POP) ? TRUE : FALSE;
2713 g_object_unref (account);
2714 g_object_unref (folder);
2715 g_object_unref (header);
2718 g_object_unref (iter);
2720 /* Check that the messages have been previously downloaded */
2721 gboolean continue_download = TRUE;
2723 continue_download = download_uncached_messages (header_list, GTK_WINDOW (window), FALSE);
2724 if (continue_download)
2725 modest_header_view_copy_selection (MODEST_HEADER_VIEW (focused_widget));
2726 g_object_unref (header_list);
2727 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
2728 modest_folder_view_copy_selection (MODEST_FOLDER_VIEW (focused_widget));
2731 /* Show information banner */
2732 modest_platform_information_banner (NULL, NULL, _CS("ecoc_ib_edwin_copied"));
2737 modest_ui_actions_on_undo (GtkAction *action,
2738 ModestWindow *window)
2740 ModestEmailClipboard *clipboard = NULL;
2742 if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
2743 modest_msg_edit_window_undo (MODEST_MSG_EDIT_WINDOW (window));
2744 } else if (MODEST_IS_MAIN_WINDOW (window)) {
2745 /* Clear clipboard source */
2746 clipboard = modest_runtime_get_email_clipboard ();
2747 modest_email_clipboard_clear (clipboard);
2750 g_return_if_reached ();
2755 modest_ui_actions_on_redo (GtkAction *action,
2756 ModestWindow *window)
2758 if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
2759 modest_msg_edit_window_redo (MODEST_MSG_EDIT_WINDOW (window));
2762 g_return_if_reached ();
2768 paste_msgs_cb (const GObject *object, gpointer user_data)
2770 g_return_if_fail (MODEST_IS_MAIN_WINDOW (object));
2771 g_return_if_fail (GTK_IS_WIDGET (user_data));
2773 /* destroy information note */
2774 gtk_widget_destroy (GTK_WIDGET(user_data));
2778 paste_as_attachment_free (gpointer data)
2780 PasteAsAttachmentHelper *helper = (PasteAsAttachmentHelper *) data;
2782 gtk_widget_destroy (helper->banner);
2783 g_object_unref (helper->banner);
2788 paste_msg_as_attachment_cb (ModestMailOperation *mail_op,
2793 PasteAsAttachmentHelper *helper = (PasteAsAttachmentHelper *) userdata;
2794 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (helper->window));
2799 modest_msg_edit_window_add_part (MODEST_MSG_EDIT_WINDOW (helper->window), TNY_MIME_PART (msg));
2804 modest_ui_actions_on_paste (GtkAction *action,
2805 ModestWindow *window)
2807 GtkWidget *focused_widget = NULL;
2808 GtkWidget *inf_note = NULL;
2809 ModestMailOperation *mail_op = NULL;
2811 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
2812 if (GTK_IS_EDITABLE (focused_widget)) {
2813 gtk_editable_paste_clipboard (GTK_EDITABLE(focused_widget));
2814 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
2815 ModestEmailClipboard *e_clipboard = NULL;
2816 e_clipboard = modest_runtime_get_email_clipboard ();
2817 if (modest_email_clipboard_cleared (e_clipboard)) {
2818 GtkTextBuffer *buffer;
2819 GtkClipboard *clipboard;
2821 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
2822 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
2823 gtk_text_buffer_paste_clipboard (buffer, clipboard, NULL, TRUE);
2824 } else if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
2825 ModestMailOperation *mail_op;
2826 TnyFolder *src_folder;
2829 PasteAsAttachmentHelper *helper = g_new0 (PasteAsAttachmentHelper, 1);
2830 helper->window = MODEST_MSG_EDIT_WINDOW (window);
2831 helper->banner = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
2832 _CS("ckct_nw_pasting"));
2833 modest_email_clipboard_get_data (e_clipboard, &src_folder, &data, &delete);
2834 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_RECEIVE,
2836 if (helper->banner != NULL) {
2837 g_object_ref (G_OBJECT (helper->banner));
2838 gtk_window_set_modal (GTK_WINDOW (helper->banner), FALSE);
2839 gtk_widget_show (GTK_WIDGET (helper->banner));
2843 modest_mail_operation_get_msgs_full (mail_op,
2845 (GetMsgAsyncUserCallback) paste_msg_as_attachment_cb,
2847 paste_as_attachment_free);
2850 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
2851 ModestEmailClipboard *clipboard = NULL;
2852 TnyFolder *src_folder = NULL;
2853 TnyFolderStore *folder_store = NULL;
2854 TnyList *data = NULL;
2855 gboolean delete = FALSE;
2857 /* Check clipboard source */
2858 clipboard = modest_runtime_get_email_clipboard ();
2859 if (modest_email_clipboard_cleared (clipboard))
2862 /* Get elements to paste */
2863 modest_email_clipboard_get_data (clipboard, &src_folder, &data, &delete);
2865 /* Create a new mail operation */
2866 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_RECEIVE, G_OBJECT(window));
2867 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
2870 /* Get destination folder */
2871 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (focused_widget));
2873 /* Launch notification */
2874 inf_note = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
2875 _CS("ckct_nw_pasting"));
2876 if (inf_note != NULL) {
2877 gtk_window_set_modal (GTK_WINDOW(inf_note), FALSE);
2878 gtk_widget_show (GTK_WIDGET(inf_note));
2881 /* transfer messages */
2883 modest_mail_operation_xfer_msgs (mail_op,
2885 TNY_FOLDER (folder_store),
2890 } else if (src_folder != NULL) {
2891 modest_mail_operation_xfer_folder (mail_op,
2901 g_object_unref (data);
2902 if (src_folder != NULL)
2903 g_object_unref (src_folder);
2904 if (folder_store != NULL)
2905 g_object_unref (folder_store);
2911 modest_ui_actions_on_select_all (GtkAction *action,
2912 ModestWindow *window)
2914 GtkWidget *focused_widget;
2916 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
2917 if (MODEST_IS_ATTACHMENTS_VIEW (focused_widget)) {
2918 modest_attachments_view_select_all (MODEST_ATTACHMENTS_VIEW (focused_widget));
2919 } else if (GTK_IS_LABEL (focused_widget)) {
2920 gtk_label_select_region (GTK_LABEL (focused_widget), 0, -1);
2921 } else if (GTK_IS_EDITABLE (focused_widget)) {
2922 gtk_editable_select_region (GTK_EDITABLE(focused_widget), 0, -1);
2923 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
2924 GtkTextBuffer *buffer;
2925 GtkTextIter start, end;
2927 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
2928 gtk_text_buffer_get_start_iter (buffer, &start);
2929 gtk_text_buffer_get_end_iter (buffer, &end);
2930 gtk_text_buffer_select_range (buffer, &start, &end);
2931 } else if (GTK_IS_HTML (focused_widget)) {
2932 gtk_html_select_all (GTK_HTML (focused_widget));
2933 } else if (MODEST_IS_MAIN_WINDOW (window)) {
2934 GtkWidget *header_view = focused_widget;
2935 GtkTreeSelection *selection = NULL;
2937 if (!(MODEST_IS_HEADER_VIEW (focused_widget)))
2938 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (window),
2939 MODEST_WIDGET_TYPE_HEADER_VIEW);
2941 /* Select all messages */
2942 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(header_view));
2943 gtk_tree_selection_select_all (selection);
2945 /* Set focuse on header view */
2946 gtk_widget_grab_focus (header_view);
2952 modest_ui_actions_on_mark_as_read (GtkAction *action,
2953 ModestWindow *window)
2955 g_return_if_fail (MODEST_IS_WINDOW(window));
2957 /* Mark each header as read */
2958 do_headers_action (window, headers_action_mark_as_read, NULL);
2962 modest_ui_actions_on_mark_as_unread (GtkAction *action,
2963 ModestWindow *window)
2965 g_return_if_fail (MODEST_IS_WINDOW(window));
2967 /* Mark each header as read */
2968 do_headers_action (window, headers_action_mark_as_unread, NULL);
2972 modest_ui_actions_on_change_zoom (GtkRadioAction *action,
2973 GtkRadioAction *selected,
2974 ModestWindow *window)
2978 value = gtk_radio_action_get_current_value (selected);
2979 if (MODEST_IS_WINDOW (window)) {
2980 modest_window_set_zoom (MODEST_WINDOW (window), ((gdouble)value)/100);
2984 void modest_ui_actions_msg_edit_on_change_priority (GtkRadioAction *action,
2985 GtkRadioAction *selected,
2986 ModestWindow *window)
2988 TnyHeaderFlags flags;
2989 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2991 flags = gtk_radio_action_get_current_value (selected);
2992 modest_msg_edit_window_set_priority_flags (MODEST_MSG_EDIT_WINDOW (window), flags);
2995 void modest_ui_actions_msg_edit_on_change_file_format (GtkRadioAction *action,
2996 GtkRadioAction *selected,
2997 ModestWindow *window)
3001 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3003 file_format = gtk_radio_action_get_current_value (selected);
3004 modest_msg_edit_window_set_file_format (MODEST_MSG_EDIT_WINDOW (window), file_format);
3009 modest_ui_actions_on_zoom_plus (GtkAction *action,
3010 ModestWindow *window)
3012 g_return_if_fail (MODEST_IS_WINDOW (window));
3014 modest_window_zoom_plus (MODEST_WINDOW (window));
3018 modest_ui_actions_on_zoom_minus (GtkAction *action,
3019 ModestWindow *window)
3021 g_return_if_fail (MODEST_IS_WINDOW (window));
3023 modest_window_zoom_minus (MODEST_WINDOW (window));
3027 modest_ui_actions_on_toggle_fullscreen (GtkToggleAction *toggle,
3028 ModestWindow *window)
3030 ModestWindowMgr *mgr;
3031 gboolean fullscreen, active;
3032 g_return_if_fail (MODEST_IS_WINDOW (window));
3034 mgr = modest_runtime_get_window_mgr ();
3036 active = (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle)))?1:0;
3037 fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
3039 if (active != fullscreen) {
3040 modest_window_mgr_set_fullscreen_mode (mgr, active);
3041 gtk_window_present (GTK_WINDOW (window));
3046 modest_ui_actions_on_change_fullscreen (GtkAction *action,
3047 ModestWindow *window)
3049 ModestWindowMgr *mgr;
3050 gboolean fullscreen;
3052 g_return_if_fail (MODEST_IS_WINDOW (window));
3054 mgr = modest_runtime_get_window_mgr ();
3055 fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
3056 modest_window_mgr_set_fullscreen_mode (mgr, !fullscreen);
3058 gtk_window_present (GTK_WINDOW (window));
3062 * Used by modest_ui_actions_on_details to call do_headers_action
3065 headers_action_show_details (TnyHeader *header,
3066 ModestWindow *window,
3073 dialog = modest_details_dialog_new_with_header (GTK_WINDOW (window), header);
3076 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
3077 gtk_widget_show_all (dialog);
3078 gtk_dialog_run (GTK_DIALOG (dialog));
3080 gtk_widget_destroy (dialog);
3084 * Show the folder details in a ModestDetailsDialog widget
3087 show_folder_details (TnyFolder *folder,
3093 dialog = modest_details_dialog_new_with_folder (window, folder);
3096 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
3097 gtk_widget_show_all (dialog);
3098 gtk_dialog_run (GTK_DIALOG (dialog));
3100 gtk_widget_destroy (dialog);
3104 * Show the header details in a ModestDetailsDialog widget
3107 modest_ui_actions_on_details (GtkAction *action,
3110 TnyList * headers_list;
3114 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
3117 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW (win));
3120 g_object_unref (msg);
3122 headers_list = get_selected_headers (win);
3126 iter = tny_list_create_iterator (headers_list);
3128 header = TNY_HEADER (tny_iterator_get_current (iter));
3130 headers_action_show_details (header, win, NULL);
3131 g_object_unref (header);
3134 g_object_unref (iter);
3135 g_object_unref (headers_list);
3137 } else if (MODEST_IS_MAIN_WINDOW (win)) {
3138 GtkWidget *folder_view, *header_view;
3140 /* Check which widget has the focus */
3141 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
3142 MODEST_WIDGET_TYPE_FOLDER_VIEW);
3143 if (gtk_widget_is_focus (folder_view)) {
3144 TnyFolderStore *folder_store
3145 = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
3146 if (!folder_store) {
3147 g_warning ("%s: No item was selected.\n", __FUNCTION__);
3150 /* Show only when it's a folder */
3151 /* This function should not be called for account items,
3152 * because we dim the menu item for them. */
3153 if (TNY_IS_FOLDER (folder_store)) {
3154 show_folder_details (TNY_FOLDER (folder_store), GTK_WINDOW (win));
3157 g_object_unref (folder_store);
3160 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
3161 MODEST_WIDGET_TYPE_HEADER_VIEW);
3162 /* Show details of each header */
3163 do_headers_action (win, headers_action_show_details, header_view);
3169 modest_ui_actions_on_toggle_show_cc (GtkToggleAction *toggle,
3170 ModestMsgEditWindow *window)
3172 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3174 modest_msg_edit_window_show_cc (window, gtk_toggle_action_get_active (toggle));
3178 modest_ui_actions_on_toggle_show_bcc (GtkToggleAction *toggle,
3179 ModestMsgEditWindow *window)
3181 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3183 modest_msg_edit_window_show_bcc (window, gtk_toggle_action_get_active (toggle));
3187 modest_ui_actions_toggle_folders_view (GtkAction *action,
3188 ModestMainWindow *main_window)
3190 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
3192 if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)))
3193 modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SPLIT);
3195 modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SIMPLE);
3199 modest_ui_actions_on_toggle_toolbar (GtkToggleAction *toggle,
3200 ModestWindow *window)
3202 gboolean active, fullscreen = FALSE;
3203 ModestWindowMgr *mgr;
3205 active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle));
3207 /* Check if we want to toggle the toolbar vuew in fullscreen
3209 if (!strcmp (gtk_action_get_name (GTK_ACTION (toggle)),
3210 "ViewShowToolbarFullScreen")) {
3214 /* Toggle toolbar */
3215 mgr = modest_runtime_get_window_mgr ();
3216 modest_window_mgr_show_toolbars (mgr, active, fullscreen);
3220 modest_ui_actions_msg_edit_on_select_font (GtkAction *action,
3221 ModestMsgEditWindow *window)
3223 modest_msg_edit_window_select_font (window);
3227 modest_ui_actions_on_folder_display_name_changed (ModestFolderView *folder_view,
3228 const gchar *display_name,
3231 /* Do not change the application name if the widget has not
3232 the focus. This callback could be called even if the folder
3233 view has not the focus, because the handled signal could be
3234 emitted when the folder view is redrawn */
3235 if (gtk_widget_is_focus (GTK_WIDGET (folder_view))) {
3237 gtk_window_set_title (window, display_name);
3239 gtk_window_set_title (window, " ");
3244 modest_ui_actions_on_select_contacts (GtkAction *action, ModestMsgEditWindow *window)
3246 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3247 modest_msg_edit_window_select_contacts (window);
3251 modest_ui_actions_on_check_names (GtkAction *action, ModestMsgEditWindow *window)
3253 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3254 modest_msg_edit_window_check_names (window, FALSE);
3258 create_move_to_dialog_on_new_folder(GtkWidget *button, gpointer user_data)
3260 modest_ui_actions_create_folder (gtk_widget_get_toplevel (button),
3261 GTK_WIDGET (user_data));
3265 create_move_to_dialog (GtkWindow *win,
3266 GtkWidget *folder_view,
3267 GtkWidget **tree_view)
3269 GtkWidget *dialog, *scroll;
3270 GtkWidget *new_button;
3272 dialog = gtk_dialog_new_with_buttons (_("mcen_ti_moveto_folders_title"),
3274 GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR | GTK_DIALOG_DESTROY_WITH_PARENT,
3277 gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_OK, GTK_RESPONSE_ACCEPT);
3278 /* We do this manually so GTK+ does not associate a response ID for
3280 new_button = gtk_button_new_from_stock (GTK_STOCK_NEW);
3281 gtk_box_pack_end (GTK_BOX (GTK_DIALOG (dialog)->action_area), new_button, FALSE, FALSE, 0);
3282 gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT);
3284 /* Create scrolled window */
3285 scroll = gtk_scrolled_window_new (NULL, NULL);
3286 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll),
3287 GTK_POLICY_AUTOMATIC,
3288 GTK_POLICY_AUTOMATIC);
3290 /* Create folder view */
3291 *tree_view = modest_platform_create_folder_view (NULL);
3293 g_signal_connect (G_OBJECT (new_button), "clicked", G_CALLBACK(create_move_to_dialog_on_new_folder), *tree_view);
3295 /* It could happen that we're trying to move a message from a
3296 window (msg window for example) after the main window was
3297 closed, so we can not just get the model of the folder
3299 if (MODEST_IS_FOLDER_VIEW (folder_view))
3300 gtk_tree_view_set_model (GTK_TREE_VIEW (*tree_view),
3301 gtk_tree_view_get_model (GTK_TREE_VIEW (folder_view)));
3303 modest_folder_view_update_model (MODEST_FOLDER_VIEW (*tree_view),
3304 TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()));
3306 modest_folder_view_show_non_move_folders (MODEST_FOLDER_VIEW (*tree_view), FALSE);
3308 gtk_container_add (GTK_CONTAINER (scroll), *tree_view);
3310 /* Add scroll to dialog */
3311 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
3312 scroll, TRUE, TRUE, 0);
3314 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
3315 gtk_window_set_default_size (GTK_WINDOW (dialog), 300, 300);
3321 * Returns TRUE if at least one of the headers of the list belongs to
3322 * a message that has been fully retrieved.
3325 has_retrieved_msgs (TnyList *list)
3328 gboolean found = FALSE;
3330 iter = tny_list_create_iterator (list);
3331 while (tny_iterator_is_done (iter) && !found) {
3333 TnyHeaderFlags flags = 0;
3335 header = TNY_HEADER (tny_iterator_get_current (iter));
3337 flags = tny_header_get_flags (header);
3338 if (!(flags & TNY_HEADER_FLAG_PARTIAL))
3341 g_object_unref (header);
3345 tny_iterator_next (iter);
3347 g_object_unref (iter);
3353 * Shows a confirmation dialog to the user when we're moving messages
3354 * from a remote server to the local storage. Returns the dialog
3355 * response. If it's other kind of movement the it always returns
3359 msgs_move_to_confirmation (GtkWindow *win,
3360 TnyFolder *dest_folder,
3363 gint response = GTK_RESPONSE_OK;
3365 /* If the destination is a local folder */
3366 if (modest_tny_folder_is_local_folder (dest_folder)) {
3367 TnyFolder *src_folder = NULL;
3368 TnyIterator *iter = NULL;
3369 TnyHeader *header = NULL;
3371 /* Get source folder */
3372 iter = tny_list_create_iterator (headers);
3373 header = TNY_HEADER (tny_iterator_get_current (iter));
3375 src_folder = tny_header_get_folder (header);
3376 g_object_unref (header);
3379 g_object_unref (iter);
3381 /* if no src_folder, message may be an attahcment */
3382 if (src_folder == NULL)
3383 return GTK_RESPONSE_CANCEL;
3385 /* If the source is a remote folder */
3386 if (!modest_tny_folder_is_local_folder (src_folder)) {
3387 const gchar *message;
3389 if (has_retrieved_msgs (headers))
3390 message = ngettext ("mcen_nc_move_retrieve", "mcen_nc_move_retrieves",
3391 tny_list_get_length (headers));
3393 message = ngettext ("mcen_nc_move_header", "mcen_nc_move_headers",
3394 tny_list_get_length (headers));
3396 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
3397 (const gchar *) message);
3400 g_object_unref (src_folder);
3409 transfer_msgs_from_viewer_cb (const GObject *object, gpointer user_data)
3411 ModestMsgViewWindow *self = NULL;
3413 g_return_if_fail (MODEST_IS_MSG_VIEW_WINDOW (object));
3414 self = MODEST_MSG_VIEW_WINDOW (object);
3416 if (!modest_msg_view_window_select_next_message (self))
3417 if (!modest_msg_view_window_select_previous_message (self))
3418 /* No more messages to view, so close this window */
3419 modest_ui_actions_on_close_window (NULL, MODEST_WINDOW(self));
3423 modest_ui_actions_move_folder_error_handler (ModestMailOperation *mail_op,
3426 GObject *win = modest_mail_operation_get_source (mail_op);
3427 const GError *error = NULL;
3428 const gchar *message = NULL;
3430 /* Get error message */
3431 error = modest_mail_operation_get_error (mail_op);
3432 if (error != NULL && error->message != NULL) {
3433 message = error->message;
3435 message = _("mail_in_ui_folder_move_target_error");
3438 /* Show notification dialog */
3439 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL, message);
3440 g_object_unref (win);
3444 modest_ui_actions_send_receive_error_handler (ModestMailOperation *mail_op,
3447 GObject *win = modest_mail_operation_get_source (mail_op);
3448 const GError *error = modest_mail_operation_get_error (mail_op);
3450 g_return_if_fail (error != NULL);
3451 if (error->message != NULL)
3452 g_printerr ("modest: %s\n", error->message);
3454 g_printerr ("modest: unkonw error on send&receive operation");
3456 /* Show error message */
3457 /* if (modest_mail_operation_get_id (mail_op) == MODEST_MAIL_OPERATION_TYPE_RECEIVE) */
3458 /* modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL, */
3459 /* _CS("sfil_ib_unable_to_receive")); */
3461 /* modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL, */
3462 /* _CS("sfil_ib_unable_to_send")); */
3463 g_object_unref (win);
3467 open_msg_for_purge_cb (ModestMailOperation *mail_op,
3474 gint pending_purges = 0;
3475 gboolean some_purged = FALSE;
3476 ModestWindow *win = MODEST_WINDOW (user_data);
3477 ModestWindowMgr *mgr = modest_runtime_get_window_mgr ();
3479 /* If there was any error */
3480 if (!modest_ui_actions_msg_retrieval_check (mail_op, header, msg)) {
3481 modest_window_mgr_unregister_header (mgr, header);
3485 /* Once the message has been retrieved for purging, we check if
3486 * it's all ok for purging */
3488 parts = tny_simple_list_new ();
3489 tny_mime_part_get_parts (TNY_MIME_PART (msg), parts);
3490 iter = tny_list_create_iterator (parts);
3492 while (!tny_iterator_is_done (iter)) {
3494 part = TNY_MIME_PART (tny_iterator_get_current (iter));
3495 if (part && (tny_mime_part_is_attachment (part) || TNY_IS_MSG (part))) {
3496 if (tny_mime_part_is_purged (part))
3503 g_object_unref (part);
3505 tny_iterator_next (iter);
3508 if (pending_purges>0) {
3510 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),_("mcen_nc_purge_file_text_inbox"));
3512 if (response == GTK_RESPONSE_OK) {
3513 modest_platform_information_banner (NULL, NULL, _("mcen_ib_removing_attachment"));
3514 tny_iterator_first (iter);
3515 while (!tny_iterator_is_done (iter)) {
3518 part = TNY_MIME_PART (tny_iterator_get_current (iter));
3519 if (part && (tny_mime_part_is_attachment (part) || TNY_IS_MSG (part)))
3520 tny_mime_part_set_purged (part);
3523 g_object_unref (part);
3525 tny_iterator_next (iter);
3528 tny_msg_rewrite_cache (msg);
3531 modest_platform_information_banner (NULL, NULL, _("mail_ib_attachment_already_purged"));
3534 /* remove attachments */
3535 tny_iterator_first (iter);
3536 while (!tny_iterator_is_done (iter)) {
3539 part = TNY_MIME_PART (tny_iterator_get_current (iter));
3541 /* One for the reference given by tny_iterator_get_current(): */
3542 g_object_unref (part);
3544 /* TODO: Is this meant to remove the attachment by doing another unref()?
3545 * Otherwise, this seems useless. */
3548 tny_iterator_next (iter);
3550 modest_window_mgr_unregister_header (mgr, header);
3552 g_object_unref (iter);
3553 g_object_unref (parts);
3557 modest_ui_actions_on_main_window_remove_attachments (GtkAction *action,
3558 ModestMainWindow *win)
3560 GtkWidget *header_view;
3561 TnyList *header_list;
3564 TnyHeaderFlags flags;
3565 ModestWindow *msg_view_window = NULL;
3568 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win));
3570 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
3571 MODEST_WIDGET_TYPE_HEADER_VIEW);
3573 header_list = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW (header_view));
3575 if (tny_list_get_length (header_list) == 1) {
3576 iter = tny_list_create_iterator (header_list);
3577 header = TNY_HEADER (tny_iterator_get_current (iter));
3578 g_object_unref (iter);
3583 found = modest_window_mgr_find_registered_header (modest_runtime_get_window_mgr (),
3584 header, &msg_view_window);
3585 flags = tny_header_get_flags (header);
3586 if (!(flags & TNY_HEADER_FLAG_CACHED))
3589 if (msg_view_window != NULL)
3590 modest_msg_view_window_remove_attachments (MODEST_MSG_VIEW_WINDOW (msg_view_window), TRUE);
3592 /* do nothing; uid was registered before, so window is probably on it's way */
3593 g_warning ("debug: header %p has already been registered", header);
3596 ModestMailOperation *mail_op = NULL;
3597 modest_window_mgr_register_header (modest_runtime_get_window_mgr (), header);
3598 mail_op = modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE,
3600 modest_ui_actions_get_msgs_full_error_handler,
3602 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
3603 modest_mail_operation_get_msg (mail_op, header, open_msg_for_purge_cb, win);
3605 g_object_unref (mail_op);
3608 g_object_unref (header);
3610 g_object_unref (header_list);
3614 * Utility function that transfer messages from both the main window
3615 * and the msg view window when using the "Move to" dialog
3618 modest_ui_actions_xfer_messages_from_move_to (TnyFolderStore *dst_folder,
3621 TnyList *headers = NULL;
3624 if (!TNY_IS_FOLDER (dst_folder)) {
3625 modest_platform_information_banner (GTK_WIDGET (win),
3627 _CS("ckdg_ib_unable_to_move_to_current_location"));
3631 /* Get selected headers */
3632 headers = get_selected_headers (MODEST_WINDOW (win));
3634 /* Ask for user confirmation */
3635 response = msgs_move_to_confirmation (GTK_WINDOW (win),
3636 TNY_FOLDER (dst_folder),
3639 /* Transfer messages */
3640 if (response == GTK_RESPONSE_OK) {
3641 ModestMailOperation *mail_op =
3642 modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE,
3644 modest_ui_actions_move_folder_error_handler,
3646 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
3649 modest_mail_operation_xfer_msgs (mail_op,
3651 TNY_FOLDER (dst_folder),
3653 (MODEST_IS_MSG_VIEW_WINDOW (win)) ? transfer_msgs_from_viewer_cb : NULL,
3656 g_object_unref (G_OBJECT (mail_op));
3658 g_object_unref (headers);
3663 * UI handler for the "Move to" action when invoked from the
3667 modest_ui_actions_on_main_window_move_to (GtkAction *action,
3668 GtkWidget *folder_view,
3669 TnyFolderStore *dst_folder,
3670 ModestMainWindow *win)
3672 GtkWidget *header_view = NULL;
3673 ModestMailOperation *mail_op = NULL;
3674 TnyFolderStore *src_folder;
3676 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win));
3678 /* Get the source folder */
3679 src_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
3681 /* Offer the connection dialog if necessary, if the source folder is in a networked account: */
3682 if (!modest_platform_connect_and_wait_if_network_folderstore (GTK_WINDOW (win),
3686 /* Get header view */
3688 modest_main_window_get_child_widget (win, MODEST_WIDGET_TYPE_HEADER_VIEW);
3690 /* Get folder or messages to transfer */
3691 if (gtk_widget_is_focus (folder_view)) {
3693 /* Allow only to transfer folders to the local root folder */
3694 if (TNY_IS_ACCOUNT (dst_folder) &&
3695 !MODEST_IS_TNY_LOCAL_FOLDERS_ACCOUNT (dst_folder))
3698 /* Clean folder on header view before moving it */
3699 modest_header_view_clear (MODEST_HEADER_VIEW (header_view));
3701 if (TNY_IS_FOLDER (src_folder)) {
3703 modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE,
3705 modest_ui_actions_move_folder_error_handler,
3707 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
3710 modest_mail_operation_xfer_folder (mail_op,
3711 TNY_FOLDER (src_folder),
3714 /* Unref mail operation */
3715 g_object_unref (G_OBJECT (mail_op));
3717 g_warning ("%s: src_folder is not a TnyFolder.\n", __FUNCTION__);
3719 } else if (gtk_widget_is_focus (header_view)) {
3720 /* Transfer messages */
3721 modest_ui_actions_xfer_messages_from_move_to (dst_folder, MODEST_WINDOW (win));
3726 g_object_unref (src_folder);
3731 * UI handler for the "Move to" action when invoked from the
3732 * ModestMsgViewWindow
3735 modest_ui_actions_on_msg_view_window_move_to (GtkAction *action,
3736 TnyFolderStore *dst_folder,
3737 ModestMsgViewWindow *win)
3739 TnyHeader *header = NULL;
3740 TnyFolder *src_folder;
3742 /* Create header list */
3743 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
3744 src_folder = tny_header_get_folder(header);
3745 g_object_unref (header);
3747 /* Transfer the message */
3748 if (modest_platform_connect_and_wait_if_network_folderstore (NULL, TNY_FOLDER_STORE (src_folder)))
3749 modest_ui_actions_xfer_messages_from_move_to (dst_folder, MODEST_WINDOW (win));
3751 g_object_unref (src_folder);
3755 modest_ui_actions_on_move_to (GtkAction *action,
3758 GtkWidget *dialog = NULL, *folder_view = NULL, *tree_view = NULL;
3760 TnyFolderStore *dst_folder = NULL;
3761 ModestMainWindow *main_window;
3763 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win) ||
3764 MODEST_IS_MSG_VIEW_WINDOW (win));
3766 /* Get the main window if exists */
3767 if (MODEST_IS_MAIN_WINDOW (win))
3768 main_window = MODEST_MAIN_WINDOW (win);
3771 MODEST_MAIN_WINDOW (modest_window_mgr_get_main_window (modest_runtime_get_window_mgr ()));
3773 /* Get the folder view widget if exists */
3775 folder_view = modest_main_window_get_child_widget (main_window,
3776 MODEST_WIDGET_TYPE_FOLDER_VIEW);
3780 /* Create and run the dialog */
3781 dialog = create_move_to_dialog (GTK_WINDOW (win), folder_view, &tree_view);
3782 modest_folder_view_select_first_inbox_or_local (MODEST_FOLDER_VIEW (tree_view));
3783 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
3784 result = gtk_dialog_run (GTK_DIALOG(dialog));
3785 g_object_ref (tree_view);
3786 gtk_widget_destroy (dialog);
3788 if (result != GTK_RESPONSE_ACCEPT)
3791 dst_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (tree_view));
3792 /* Offer the connection dialog if necessary: */
3793 if (modest_platform_connect_and_wait_if_network_folderstore (GTK_WINDOW (win),
3796 /* Do window specific stuff */
3797 if (MODEST_IS_MAIN_WINDOW (win))
3798 modest_ui_actions_on_main_window_move_to (action,
3801 MODEST_MAIN_WINDOW (win));
3803 modest_ui_actions_on_msg_view_window_move_to (action,
3805 MODEST_MSG_VIEW_WINDOW (win));
3808 g_object_unref (dst_folder);
3812 * Calls #HeadersFunc for each header already selected in the main
3813 * window or the message currently being shown in the msg view window
3816 do_headers_action (ModestWindow *win,
3820 TnyList *headers_list = NULL;
3821 TnyIterator *iter = NULL;
3822 TnyHeader *header = NULL;
3823 TnyFolder *folder = NULL;
3826 headers_list = get_selected_headers (win);
3830 /* Get the folder */
3831 iter = tny_list_create_iterator (headers_list);
3832 header = TNY_HEADER (tny_iterator_get_current (iter));
3834 folder = tny_header_get_folder (header);
3835 g_object_unref (header);
3838 /* Call the function for each header */
3839 while (!tny_iterator_is_done (iter)) {
3840 header = TNY_HEADER (tny_iterator_get_current (iter));
3841 func (header, win, user_data);
3842 g_object_unref (header);
3843 tny_iterator_next (iter);
3846 /* Trick: do a poke status in order to speed up the signaling
3848 tny_folder_poke_status (folder);
3851 g_object_unref (folder);
3852 g_object_unref (iter);
3853 g_object_unref (headers_list);
3857 modest_ui_actions_view_attachment (GtkAction *action,
3858 ModestWindow *window)
3860 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
3861 modest_msg_view_window_view_attachment (MODEST_MSG_VIEW_WINDOW (window), NULL);
3863 /* not supported window for this action */
3864 g_return_if_reached ();
3869 modest_ui_actions_save_attachments (GtkAction *action,
3870 ModestWindow *window)
3872 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
3873 modest_msg_view_window_save_attachments (MODEST_MSG_VIEW_WINDOW (window), NULL);
3875 /* not supported window for this action */
3876 g_return_if_reached ();
3881 modest_ui_actions_remove_attachments (GtkAction *action,
3882 ModestWindow *window)
3884 if (MODEST_IS_MAIN_WINDOW (window)) {
3885 modest_ui_actions_on_main_window_remove_attachments (action, MODEST_MAIN_WINDOW (window));
3886 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
3887 modest_msg_view_window_remove_attachments (MODEST_MSG_VIEW_WINDOW (window), FALSE);
3889 /* not supported window for this action */
3890 g_return_if_reached ();
3895 modest_ui_actions_on_settings (GtkAction *action,
3900 dialog = modest_platform_get_global_settings_dialog ();
3901 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (win));
3902 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
3903 gtk_widget_show_all (dialog);
3905 gtk_dialog_run (GTK_DIALOG (dialog));
3907 gtk_widget_destroy (dialog);
3911 modest_ui_actions_on_help (GtkAction *action,
3914 const gchar *help_id = NULL;
3916 if (MODEST_IS_MAIN_WINDOW (win)) {
3917 const gchar *action_name;
3918 action_name = gtk_action_get_name (action);
3920 if (!strcmp (action_name, "FolderViewCSMHelp") ||
3921 !strcmp (action_name, "HeaderViewCSMHelp")) {
3922 GtkWidget *folder_view;
3923 TnyFolderStore *folder_store;
3924 /* Get selected folder */
3925 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
3926 MODEST_WIDGET_TYPE_FOLDER_VIEW);
3927 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
3929 /* Switch help_id */
3930 if (TNY_IS_FOLDER (folder_store)) {
3931 switch (modest_tny_folder_guess_folder_type (TNY_FOLDER (folder_store))) {
3932 case TNY_FOLDER_TYPE_NORMAL:
3933 help_id = "applications_email_managefolders";
3935 case TNY_FOLDER_TYPE_INBOX:
3936 help_id = "applications_email_inbox";
3938 case TNY_FOLDER_TYPE_OUTBOX:
3939 help_id = "applications_email_outbox";
3941 case TNY_FOLDER_TYPE_SENT:
3942 help_id = "applications_email_sent";
3944 case TNY_FOLDER_TYPE_DRAFTS:
3945 help_id = "applications_email_drafts";
3947 case TNY_FOLDER_TYPE_ARCHIVE:
3948 help_id = "applications_email_managefolders";
3951 help_id = "applications_email_managefolders";
3954 help_id = "applications_email_mainview";
3956 g_object_unref (folder_store);
3958 help_id = "applications_email_mainview";
3960 } else if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
3961 help_id = "applications_email_viewer";
3962 } else if (MODEST_IS_MSG_EDIT_WINDOW (win))
3963 help_id = "applications_email_editor";
3965 modest_platform_show_help (GTK_WINDOW (win), help_id);
3969 modest_ui_actions_on_retrieve_msg_contents (GtkAction *action,
3970 ModestWindow *window)
3972 ModestMailOperation *mail_op;
3976 headers = get_selected_headers (window);
3980 /* Create mail operation */
3981 mail_op = modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE,
3983 modest_ui_actions_get_msgs_full_error_handler,
3985 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
3986 modest_mail_operation_get_msgs_full (mail_op, headers, NULL, NULL, NULL);
3989 g_object_unref (headers);
3990 g_object_unref (mail_op);
3994 modest_ui_actions_on_email_menu_activated (GtkAction *action,
3995 ModestWindow *window)
3997 g_return_if_fail (MODEST_IS_WINDOW (window));
4000 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4004 modest_ui_actions_on_edit_menu_activated (GtkAction *action,
4005 ModestWindow *window)
4007 g_return_if_fail (MODEST_IS_WINDOW (window));
4010 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4014 modest_ui_actions_on_view_menu_activated (GtkAction *action,
4015 ModestWindow *window)
4017 g_return_if_fail (MODEST_IS_WINDOW (window));
4020 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4024 modest_ui_actions_on_tools_menu_activated (GtkAction *action,
4025 ModestWindow *window)
4027 g_return_if_fail (MODEST_IS_WINDOW (window));
4030 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4034 modest_ui_actions_on_attachment_menu_activated (GtkAction *action,
4035 ModestWindow *window)
4037 g_return_if_fail (MODEST_IS_WINDOW (window));
4040 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4044 modest_ui_actions_on_toolbar_csm_menu_activated (GtkAction *action,
4045 ModestWindow *window)
4047 g_return_if_fail (MODEST_IS_WINDOW (window));
4050 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4054 modest_ui_actions_on_folder_view_csm_menu_activated (GtkAction *action,
4055 ModestWindow *window)
4057 g_return_if_fail (MODEST_IS_WINDOW (window));
4060 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4064 modest_ui_actions_on_header_view_csm_menu_activated (GtkAction *action,
4065 ModestWindow *window)
4067 g_return_if_fail (MODEST_IS_WINDOW (window));
4070 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4074 modest_ui_actions_check_toolbar_dimming_rules (ModestWindow *window)
4076 g_return_if_fail (MODEST_IS_WINDOW (window));
4079 modest_window_check_dimming_rules_group (window, "ModestToolbarDimmingRules");
4083 modest_ui_actions_on_search_messages (GtkAction *action, ModestWindow *window)
4085 g_return_if_fail (MODEST_IS_WINDOW (window));
4087 modest_platform_show_search_messages (GTK_WINDOW (window));
4091 modest_ui_actions_on_open_addressbook (GtkAction *action, ModestWindow *win)
4093 g_return_if_fail (MODEST_IS_WINDOW (win));
4094 modest_platform_show_addressbook (GTK_WINDOW (win));
4099 modest_ui_actions_on_toggle_find_in_page (GtkToggleAction *action,
4100 ModestWindow *window)
4102 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4104 modest_msg_edit_window_toggle_find_toolbar (MODEST_MSG_EDIT_WINDOW (window), gtk_toggle_action_get_active (action));
4108 _on_send_receive_progress_changed (ModestMailOperation *mail_op,
4109 ModestMailOperationState *state,
4112 g_return_if_fail (MODEST_IS_MAIN_WINDOW(user_data));
4114 /* Set send/receive operation finished */
4115 if (state->status != MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS)
4116 modest_main_window_notify_send_receive_completed (MODEST_MAIN_WINDOW(user_data));