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"
48 #ifdef MODEST_PLATFORM_MAEMO
49 #include "maemo/modest-osso-state-saving.h"
50 #endif /* MODEST_PLATFORM_MAEMO */
52 #include "widgets/modest-ui-constants.h"
53 #include <widgets/modest-main-window.h>
54 #include <widgets/modest-msg-view-window.h>
55 #include <widgets/modest-account-view-window.h>
56 #include <widgets/modest-details-dialog.h>
57 #include <widgets/modest-attachments-view.h>
58 #include "widgets/modest-folder-view.h"
59 #include "widgets/modest-global-settings-dialog.h"
60 #include "modest-connection-specific-smtp-window.h"
61 #include "modest-account-mgr-helpers.h"
62 #include "modest-mail-operation.h"
63 #include "modest-text-utils.h"
65 #ifdef MODEST_HAVE_EASYSETUP
66 #include "easysetup/modest-easysetup-wizard.h"
67 #endif /* MODEST_HAVE_EASYSETUP */
69 #include <modest-widget-memory.h>
70 #include <tny-error.h>
71 #include <tny-simple-list.h>
72 #include <tny-msg-view.h>
73 #include <tny-device.h>
74 #include <tny-merge-folder.h>
76 #include <gtkhtml/gtkhtml.h>
78 typedef struct _GetMsgAsyncHelper {
80 ModestMailOperation *mail_op;
87 typedef enum _ReplyForwardAction {
93 typedef struct _ReplyForwardHelper {
94 guint reply_forward_type;
95 ReplyForwardAction action;
97 GtkWidget *parent_window;
102 * The do_headers_action uses this kind of functions to perform some
103 * action to each member of a list of headers
105 typedef void (*HeadersFunc) (TnyHeader *header, ModestWindow *win, gpointer user_data);
108 do_headers_action (ModestWindow *win,
113 static void open_msg_cb (ModestMailOperation *mail_op,
118 static void reply_forward_cb (ModestMailOperation *mail_op,
123 static void reply_forward (ReplyForwardAction action, ModestWindow *win);
126 static void _on_send_receive_progress_changed (ModestMailOperation *mail_op,
127 ModestMailOperationState *state,
133 run_account_setup_wizard (ModestWindow *win)
135 ModestEasysetupWizardDialog *wizard;
137 g_return_if_fail (MODEST_IS_WINDOW(win));
139 wizard = modest_easysetup_wizard_dialog_new ();
140 gtk_window_set_transient_for (GTK_WINDOW (wizard), GTK_WINDOW (win));
141 gtk_dialog_run (GTK_DIALOG (wizard));
142 gtk_widget_destroy (GTK_WIDGET (wizard));
147 modest_ui_actions_on_about (GtkAction *action, ModestWindow *win)
150 const gchar *authors[] = {
151 "Dirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>",
154 about = gtk_about_dialog_new ();
155 gtk_about_dialog_set_name (GTK_ABOUT_DIALOG(about), PACKAGE_NAME);
156 gtk_about_dialog_set_version (GTK_ABOUT_DIALOG(about),PACKAGE_VERSION);
157 gtk_about_dialog_set_copyright (GTK_ABOUT_DIALOG(about),
158 _("Copyright (c) 2006, Nokia Corporation\n"
159 "All rights reserved."));
160 gtk_about_dialog_set_comments (GTK_ABOUT_DIALOG(about),
161 _("a modest e-mail client\n\n"
162 "design and implementation: Dirk-Jan C. Binnema\n"
163 "contributions from the fine people at KC and Ig\n"
164 "uses the tinymail email framework written by Philip van Hoof"));
165 gtk_about_dialog_set_authors (GTK_ABOUT_DIALOG(about), authors);
166 gtk_about_dialog_set_website (GTK_ABOUT_DIALOG(about), "http://modest.garage.maemo.org");
168 gtk_dialog_run (GTK_DIALOG (about));
169 gtk_widget_destroy(about);
173 * Gets the list of currently selected messages. If the win is the
174 * main window, then it returns a newly allocated list of the headers
175 * selected in the header view. If win is the msg view window, then
176 * the value returned is a list with just a single header.
178 * The caller of this funcion must free the list.
181 get_selected_headers (ModestWindow *win)
183 if (MODEST_IS_MAIN_WINDOW(win)) {
184 GtkWidget *header_view;
186 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
187 MODEST_WIDGET_TYPE_HEADER_VIEW);
188 return modest_header_view_get_selected_headers (MODEST_HEADER_VIEW(header_view));
190 } else if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
191 /* for MsgViewWindows, we simply return a list with one element */
193 TnyList *list = NULL;
195 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
196 if (header != NULL) {
197 list = tny_simple_list_new ();
198 tny_list_prepend (list, G_OBJECT(header));
199 g_object_unref (G_OBJECT(header));
209 headers_action_mark_as_read (TnyHeader *header,
213 TnyHeaderFlags flags;
215 g_return_if_fail (TNY_IS_HEADER(header));
217 flags = tny_header_get_flags (header);
218 if (flags & TNY_HEADER_FLAG_SEEN) return;
219 tny_header_set_flags (header, TNY_HEADER_FLAG_SEEN);
223 headers_action_mark_as_unread (TnyHeader *header,
227 TnyHeaderFlags flags;
229 g_return_if_fail (TNY_IS_HEADER(header));
231 flags = tny_header_get_flags (header);
232 if (flags & TNY_HEADER_FLAG_SEEN) {
233 tny_header_unset_flags (header, TNY_HEADER_FLAG_SEEN);
239 headers_action_delete (TnyHeader *header,
243 ModestMailOperation *mail_op = NULL;
245 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_DELETE, G_OBJECT(win));
246 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
249 /* Always delete. TODO: Move to trash still not supported */
250 modest_mail_operation_remove_msg (mail_op, header, FALSE);
251 g_object_unref (G_OBJECT (mail_op));
255 modest_ui_actions_on_delete (GtkAction *action, ModestWindow *win)
257 TnyList *header_list = NULL;
258 TnyIterator *iter = NULL;
259 TnyHeader *header = NULL;
260 gchar *message = NULL;
264 ModestWindowMgr *mgr;
265 GtkWidget *header_view;
267 g_return_if_fail (MODEST_IS_WINDOW(win));
269 /* Check first if the header view has the focus */
270 if (MODEST_IS_MAIN_WINDOW (win)) {
271 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
272 MODEST_WIDGET_TYPE_HEADER_VIEW);
273 if (!gtk_widget_is_focus (header_view))
277 header_list = get_selected_headers (win);
278 if (!header_list) return;
280 /* Check if any of the headers is already opened */
281 iter = tny_list_create_iterator (header_list);
283 mgr = modest_runtime_get_window_mgr ();
284 while (!tny_iterator_is_done (iter) && !found) {
285 header = TNY_HEADER (tny_iterator_get_current (iter));
286 if (modest_window_mgr_find_window_by_header (mgr, header))
288 g_object_unref (header);
289 tny_iterator_next (iter);
291 g_object_unref (iter);
296 num = g_strdup_printf ("%d", tny_list_get_length (header_list));
297 msg = g_strdup_printf (_("mcen_nc_unable_to_delete_n_messages"), num);
299 modest_platform_run_information_dialog (GTK_WINDOW (win), (const gchar *) msg);
303 g_object_unref (header_list);
308 if (tny_list_get_length(header_list) == 1) {
309 iter = tny_list_create_iterator (header_list);
310 header = TNY_HEADER (tny_iterator_get_current (iter));
311 desc = g_strdup_printf ("%s", tny_header_get_subject (header));
312 g_object_unref (header);
313 g_object_unref (iter);
315 message = g_strdup_printf(ngettext("emev_nc_delete_message", "emev_nc_delete_messages",
316 tny_list_get_length(header_list)), desc);
318 /* Confirmation dialog */
319 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
323 if (response == GTK_RESPONSE_OK) {
324 if (MODEST_IS_MSG_EDIT_WINDOW (win)) {
326 g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value);
330 /* Remove each header */
331 do_headers_action (win, headers_action_delete, NULL);
333 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
334 gtk_widget_destroy (GTK_WIDGET(win));
341 g_object_unref (header_list);
346 modest_ui_actions_on_quit (GtkAction *action, ModestWindow *win)
348 #ifdef MODEST_PLATFORM_MAEMO
349 modest_osso_save_state();
350 #endif /* MODEST_PLATFORM_MAEMO */
356 modest_ui_actions_on_close_window (GtkAction *action, ModestWindow *win)
358 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
359 gtk_widget_destroy (GTK_WIDGET (win));
360 } else if (MODEST_IS_MSG_EDIT_WINDOW (win)) {
362 g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value);
363 } else if (MODEST_IS_WINDOW (win)) {
364 gtk_widget_destroy (GTK_WIDGET (win));
366 g_return_if_reached ();
371 modest_ui_actions_on_add_to_contacts (GtkAction *action, ModestWindow *win)
373 GtkClipboard *clipboard = NULL;
374 gchar *selection = NULL;
376 clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
377 selection = gtk_clipboard_wait_for_text (clipboard);
379 /* Question: why is the clipboard being used here?
380 * It doesn't really make a lot of sense. */
384 modest_address_book_add_address (selection);
390 modest_ui_actions_on_accounts (GtkAction *action, ModestWindow *win)
392 /* This is currently only implemented for Maemo */
393 #ifdef MODEST_PLATFORM_MAEMO /* Defined in config.h */
394 if (!modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE)) {
395 run_account_setup_wizard (win);
398 /* Show the list of accounts: */
399 GtkDialog *account_win = GTK_DIALOG(modest_account_view_window_new ());
400 gtk_window_set_transient_for (GTK_WINDOW (account_win), GTK_WINDOW(win));
401 gtk_dialog_run (account_win);
402 gtk_widget_destroy (GTK_WIDGET(account_win));
405 GtkWidget *dialog, *label;
407 /* Create the widgets */
409 dialog = gtk_dialog_new_with_buttons ("Message",
411 GTK_DIALOG_DESTROY_WITH_PARENT,
415 label = gtk_label_new ("Hello World!");
417 /* Ensure that the dialog box is destroyed when the user responds. */
419 g_signal_connect_swapped (dialog, "response",
420 G_CALLBACK (gtk_widget_destroy),
423 /* Add the label, and show everything we've added to the dialog. */
425 gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox),
427 gtk_widget_show_all (dialog);
428 #endif /* MODEST_PLATFORM_MAEMO */
432 on_smtp_servers_window_hide (GtkWindow* window, gpointer user_data)
434 ModestWindow *main_window = MODEST_WINDOW (user_data);
436 /* Save any changes. */
437 modest_connection_specific_smtp_window_save_server_accounts (
438 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (window),
439 modest_window_get_active_account (main_window));
440 gtk_widget_destroy (GTK_WIDGET (window));
446 modest_ui_actions_on_smtp_servers (GtkAction *action, ModestWindow *win)
448 /* This is currently only implemented for Maemo,
449 * because it requires an API (libconic) to detect different connection
452 #ifdef MODEST_PLATFORM_MAEMO /* Defined in config.h */
454 /* Create the window if necessary: */
455 const gchar *active_account_name = modest_window_get_active_account (win);
457 /* TODO: Dim the menu item (not in the UI spec)? or show a warning,
458 * or show the default account?
459 * If we show the default account then the account name should be shown in
460 * the window when we show it. */
461 if (!active_account_name) {
462 g_warning ("%s: No account is active.", __FUNCTION__);
466 GtkWidget *specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
467 modest_connection_specific_smtp_window_fill_with_connections (
468 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (specific_window),
469 modest_runtime_get_account_mgr(),
470 active_account_name);
472 /* Show the window: */
473 gtk_window_set_transient_for (GTK_WINDOW (specific_window), GTK_WINDOW (win));
474 gtk_window_set_modal (GTK_WINDOW (specific_window), TRUE);
475 gtk_widget_show (specific_window);
477 /* Save changes when the window is hidden: */
478 g_signal_connect (specific_window, "hide",
479 G_CALLBACK (on_smtp_servers_window_hide), win);
480 #endif /* MODEST_PLATFORM_MAEMO */
484 modest_ui_actions_on_new_msg (GtkAction *action, ModestWindow *win)
486 ModestWindow *msg_win;
488 TnyFolder *folder = NULL;
489 gchar *account_name = NULL;
490 gchar *from_str = NULL;
491 /* GError *err = NULL; */
492 TnyAccount *account = NULL;
493 ModestWindowMgr *mgr;
494 gchar *signature = NULL, *blank_and_signature = NULL;
496 /* if there are no accounts yet, just show the wizard */
497 if (!modest_account_mgr_has_accounts (modest_runtime_get_account_mgr(), TRUE)) {
498 run_account_setup_wizard (win);
502 account_name = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr ());
504 account_name = g_strdup (modest_window_get_active_account (win));
506 g_printerr ("modest: no account found\n");
510 account = modest_tny_account_store_get_server_account (modest_runtime_get_account_store(),
512 TNY_ACCOUNT_TYPE_STORE);
514 g_printerr ("modest: failed to get tnyaccount for '%s'\n", account_name);
518 from_str = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(), account_name);
520 g_printerr ("modest: failed get from string for '%s'\n", account_name);
524 if (modest_account_mgr_get_bool (modest_runtime_get_account_mgr (), account_name,
525 MODEST_ACCOUNT_USE_SIGNATURE, FALSE)) {
526 signature = modest_account_mgr_get_string (modest_runtime_get_account_mgr (), account_name,
527 MODEST_ACCOUNT_SIGNATURE, FALSE);
528 blank_and_signature = g_strconcat ("\n", signature, NULL);
531 blank_and_signature = g_strdup ("");
534 msg = modest_tny_msg_new ("", from_str, "", "", "", blank_and_signature, NULL);
536 g_printerr ("modest: failed to create new msg\n");
540 folder = modest_tny_account_get_special_folder (account, TNY_FOLDER_TYPE_DRAFTS);
542 g_printerr ("modest: failed to find Drafts folder\n");
547 /* Create and register edit window */
548 /* This is destroyed by TOOD. */
549 msg_win = modest_msg_edit_window_new (msg, account_name);
550 mgr = modest_runtime_get_window_mgr ();
551 modest_window_mgr_register_window (mgr, msg_win);
554 gtk_window_set_transient_for (GTK_WINDOW (msg_win),
556 gtk_widget_show_all (GTK_WIDGET (msg_win));
559 g_free (account_name);
561 g_free (blank_and_signature);
563 g_object_unref (G_OBJECT(account));
565 g_object_unref (G_OBJECT(msg));
567 g_object_unref (G_OBJECT(folder));
571 open_msg_cb (ModestMailOperation *mail_op,
576 ModestWindowMgr *mgr = NULL;
577 ModestWindow *parent_win = NULL;
578 ModestWindow *win = NULL;
579 TnyFolderType folder_type = TNY_FOLDER_TYPE_UNKNOWN;
580 gchar *account = NULL;
583 /* TODO: Show an error? (review the specs) */
587 parent_win = (ModestWindow *) modest_mail_operation_get_source (mail_op);
588 folder = tny_header_get_folder (header);
590 /* Mark header as read */
591 headers_action_mark_as_read (header, MODEST_WINDOW(parent_win), NULL);
594 account = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
596 account = g_strdup (modest_window_get_active_account (MODEST_WINDOW (parent_win)));
598 /* Gets folder type (OUTBOX headers will be opened in edit window */
599 if (modest_tny_folder_is_local_folder (folder))
600 folder_type = modest_tny_folder_get_local_folder_type (folder);
602 /* If the header is in the drafts folder then open the editor,
603 else the message view window */
604 if (folder_type == TNY_FOLDER_TYPE_DRAFTS) {
605 /* we cannot edit without a valid account... */
606 if (!modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE)) {
607 run_account_setup_wizard(parent_win);
610 win = modest_msg_edit_window_new (msg, account);
612 gchar *uid = modest_tny_folder_get_header_unique_id (header);
614 if (MODEST_IS_MAIN_WINDOW (parent_win)) {
615 GtkWidget *header_view;
616 GtkTreeSelection *sel;
617 GList *sel_list = NULL;
620 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(parent_win),
621 MODEST_WIDGET_TYPE_HEADER_VIEW);
623 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
624 sel_list = gtk_tree_selection_get_selected_rows (sel, &model);
626 if (sel_list != NULL) {
627 GtkTreeRowReference *row_reference;
629 row_reference = gtk_tree_row_reference_new (model, (GtkTreePath *) sel_list->data);
630 g_list_foreach (sel_list, (GFunc) gtk_tree_path_free, NULL);
631 g_list_free (sel_list);
633 win = modest_msg_view_window_new_with_header_model (msg,
638 gtk_tree_row_reference_free (row_reference);
640 win = modest_msg_view_window_new (msg, account, (const gchar*) uid);
643 win = modest_msg_view_window_new (msg, account, (const gchar*) uid);
648 /* Register and show new window */
650 mgr = modest_runtime_get_window_mgr ();
651 modest_window_mgr_register_window (mgr, win);
652 gtk_window_set_transient_for (GTK_WINDOW (win), GTK_WINDOW (parent_win));
653 gtk_widget_show_all (GTK_WIDGET(win));
659 g_object_unref (parent_win);
660 g_object_unref (msg);
661 g_object_unref (folder);
662 g_object_unref (header);
666 * This function is the error handler of the
667 * modest_mail_operation_get_msgs_full operation
670 modest_ui_actions_get_msgs_full_error_handler (ModestMailOperation *mail_op,
675 error = modest_mail_operation_get_error (mail_op);
676 if (error->code == MODEST_MAIL_OPERATION_ERROR_MESSAGE_SIZE_LIMIT) {
677 GObject *win = modest_mail_operation_get_source (mail_op);
679 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
681 g_object_unref (win);
686 * This function is used by both modest_ui_actions_on_open and
687 * modest_ui_actions_on_header_activated. This way we always do the
688 * same when trying to open messages.
691 _modest_ui_actions_open (TnyList *headers, ModestWindow *win)
693 ModestWindowMgr *mgr;
695 ModestMailOperation *mail_op;
696 TnyList *not_opened_headers;
698 /* Look if we already have a message view for each header. If
699 true, then remove the header from the list of headers to
701 mgr = modest_runtime_get_window_mgr ();
702 iter = tny_list_create_iterator (headers);
703 not_opened_headers = tny_simple_list_new ();
704 while (!tny_iterator_is_done (iter)) {
705 ModestWindow *window;
708 header = TNY_HEADER (tny_iterator_get_current (iter));
709 window = modest_window_mgr_find_window_by_header (mgr, header);
710 /* Do not open again the message and present the
711 window to the user */
713 gtk_window_present (GTK_WINDOW (window));
715 tny_list_append (not_opened_headers, G_OBJECT (header));
717 g_object_unref (header);
718 tny_iterator_next (iter);
721 /* Open each message */
722 mail_op = modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE,
724 modest_ui_actions_get_msgs_full_error_handler,
726 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
727 if (tny_list_get_length (not_opened_headers) > 1) {
728 modest_mail_operation_get_msgs_full (mail_op,
734 TnyIterator *iter = tny_list_create_iterator (not_opened_headers);
735 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter));
736 modest_mail_operation_get_msg (mail_op, header, open_msg_cb, NULL);
737 g_object_unref (header);
738 g_object_unref (iter);
742 g_object_unref (not_opened_headers);
743 g_object_unref (iter);
744 g_object_unref (mail_op);
748 modest_ui_actions_on_open (GtkAction *action, ModestWindow *win)
753 headers = get_selected_headers (win);
758 _modest_ui_actions_open (headers, win);
760 g_object_unref(headers);
765 free_reply_forward_helper (gpointer data)
767 ReplyForwardHelper *helper;
769 helper = (ReplyForwardHelper *) data;
770 g_free (helper->account_name);
771 g_slice_free (ReplyForwardHelper, helper);
775 reply_forward_cb (ModestMailOperation *mail_op,
781 ReplyForwardHelper *rf_helper;
782 ModestWindow *msg_win;
783 ModestEditType edit_type;
785 TnyAccount *account = NULL;
786 ModestWindowMgr *mgr;
787 gchar *signature = NULL;
789 g_return_if_fail (user_data != NULL);
790 rf_helper = (ReplyForwardHelper *) user_data;
792 from = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(),
793 rf_helper->account_name);
794 if (modest_account_mgr_get_bool (modest_runtime_get_account_mgr(),
795 rf_helper->account_name,
796 MODEST_ACCOUNT_USE_SIGNATURE, FALSE)) {
797 signature = modest_account_mgr_get_string (modest_runtime_get_account_mgr (),
798 rf_helper->account_name,
799 MODEST_ACCOUNT_SIGNATURE, FALSE);
802 /* Create reply mail */
803 switch (rf_helper->action) {
806 modest_tny_msg_create_reply_msg (msg, from, signature,
807 rf_helper->reply_forward_type,
808 MODEST_TNY_MSG_REPLY_MODE_SENDER);
810 case ACTION_REPLY_TO_ALL:
812 modest_tny_msg_create_reply_msg (msg, from, signature, rf_helper->reply_forward_type,
813 MODEST_TNY_MSG_REPLY_MODE_ALL);
814 edit_type = MODEST_EDIT_TYPE_REPLY;
818 modest_tny_msg_create_forward_msg (msg, from, signature, rf_helper->reply_forward_type);
819 edit_type = MODEST_EDIT_TYPE_FORWARD;
822 g_return_if_reached ();
829 g_printerr ("modest: failed to create message\n");
833 account = modest_tny_account_store_get_server_account (modest_runtime_get_account_store(),
834 rf_helper->account_name,
835 TNY_ACCOUNT_TYPE_STORE);
837 g_printerr ("modest: failed to get tnyaccount for '%s'\n", rf_helper->account_name);
841 /* Create and register the windows */
842 msg_win = modest_msg_edit_window_new (new_msg, rf_helper->account_name);
843 mgr = modest_runtime_get_window_mgr ();
844 modest_window_mgr_register_window (mgr, msg_win);
846 if (rf_helper->parent_window != NULL) {
849 parent_zoom = modest_window_get_zoom (MODEST_WINDOW (rf_helper->parent_window));
850 modest_window_set_zoom (msg_win, parent_zoom);
853 /* Show edit window */
854 gtk_widget_show_all (GTK_WIDGET (msg_win));
858 g_object_unref (G_OBJECT (new_msg));
860 g_object_unref (G_OBJECT (account));
861 g_object_unref (msg);
862 g_object_unref (header);
866 * Checks a list of headers. If any of them are not currently
867 * downloaded (CACHED) then it asks the user for permission to
870 * Returns FALSE if the user does not want to download the
871 * messages. Returns TRUE if the user allowed the download or if all
872 * of them are currently downloaded
875 download_uncached_messages (TnyList *header_list, GtkWindow *win)
878 gboolean found, retval;
880 iter = tny_list_create_iterator (header_list);
882 while (!tny_iterator_is_done (iter) && !found) {
884 TnyHeaderFlags flags;
886 header = TNY_HEADER (tny_iterator_get_current (iter));
887 flags = tny_header_get_flags (header);
888 /* TODO: is this the right flag?, it seems that some
889 headers that have been previously downloaded do not
891 found = !(flags & TNY_HEADER_FLAG_CACHED);
892 g_object_unref (header);
893 tny_iterator_next (iter);
895 g_object_unref (iter);
897 /* Ask for user permission to download the messages */
900 GtkResponseType response;
902 modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
903 _("mcen_nc_get_multi_msg_txt"));
904 if (response == GTK_RESPONSE_CANCEL)
912 * Common code for the reply and forward actions
915 reply_forward (ReplyForwardAction action, ModestWindow *win)
917 ModestMailOperation *mail_op = NULL;
918 TnyList *header_list = NULL;
919 ReplyForwardHelper *rf_helper = NULL;
920 guint reply_forward_type;
921 gboolean continue_download;
923 g_return_if_fail (MODEST_IS_WINDOW(win));
925 /* we need an account when editing */
926 if (!modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE)) {
927 run_account_setup_wizard (win);
931 header_list = get_selected_headers (win);
935 /* Check that the messages have been previously downloaded */
936 continue_download = download_uncached_messages (header_list, GTK_WINDOW (win));
937 if (!continue_download) {
938 g_object_unref (header_list);
943 modest_conf_get_int (modest_runtime_get_conf (),
944 (action == ACTION_FORWARD) ? MODEST_CONF_FORWARD_TYPE : MODEST_CONF_REPLY_TYPE,
946 /* We assume that we can only select messages of the
947 same folder and that we reply all of them from the
948 same account. In fact the interface currently only
949 allows single selection */
952 rf_helper = g_slice_new0 (ReplyForwardHelper);
953 rf_helper->reply_forward_type = reply_forward_type;
954 rf_helper->action = action;
955 rf_helper->account_name = g_strdup (modest_window_get_active_account (win));
956 if ((win != NULL) && (MODEST_IS_WINDOW (win)))
957 rf_helper->parent_window = GTK_WIDGET (win);
958 if (!rf_helper->account_name)
959 rf_helper->account_name =
960 modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
962 if (MODEST_IS_MSG_VIEW_WINDOW(win)) {
965 /* Get header and message. Do not free them here, the
966 reply_forward_cb must do it */
967 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW(win));
968 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW(win));
969 if (!msg || !header) {
971 g_object_unref (msg);
973 g_object_unref (header);
974 g_printerr ("modest: no message found\n");
977 reply_forward_cb (NULL, header, msg, rf_helper);
979 /* Retrieve messages */
980 mail_op = modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE,
982 modest_ui_actions_get_msgs_full_error_handler,
984 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
985 modest_mail_operation_get_msgs_full (mail_op,
989 free_reply_forward_helper);
992 g_object_unref(mail_op);
996 g_object_unref (header_list);
1000 modest_ui_actions_on_reply (GtkAction *action, ModestWindow *win)
1002 g_return_if_fail (MODEST_IS_WINDOW(win));
1004 reply_forward (ACTION_REPLY, win);
1008 modest_ui_actions_on_forward (GtkAction *action, ModestWindow *win)
1010 g_return_if_fail (MODEST_IS_WINDOW(win));
1012 reply_forward (ACTION_FORWARD, win);
1016 modest_ui_actions_on_reply_all (GtkAction *action, ModestWindow *win)
1018 g_return_if_fail (MODEST_IS_WINDOW(win));
1020 reply_forward (ACTION_REPLY_TO_ALL, win);
1024 modest_ui_actions_on_next (GtkAction *action,
1025 ModestWindow *window)
1027 if (MODEST_IS_MAIN_WINDOW (window)) {
1028 GtkWidget *header_view;
1030 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
1031 MODEST_WIDGET_TYPE_HEADER_VIEW);
1035 modest_header_view_select_next (MODEST_HEADER_VIEW(header_view));
1036 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
1037 modest_msg_view_window_select_next_message (MODEST_MSG_VIEW_WINDOW (window));
1039 g_return_if_reached ();
1044 modest_ui_actions_on_prev (GtkAction *action,
1045 ModestWindow *window)
1047 g_return_if_fail (MODEST_IS_WINDOW(window));
1049 if (MODEST_IS_MAIN_WINDOW (window)) {
1050 GtkWidget *header_view;
1051 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
1052 MODEST_WIDGET_TYPE_HEADER_VIEW);
1056 modest_header_view_select_prev (MODEST_HEADER_VIEW(header_view));
1057 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
1058 modest_msg_view_window_select_previous_message (MODEST_MSG_VIEW_WINDOW (window));
1060 g_return_if_reached ();
1065 modest_ui_actions_on_sort (GtkAction *action,
1066 ModestWindow *window)
1068 g_return_if_fail (MODEST_IS_WINDOW(window));
1070 if (MODEST_IS_MAIN_WINDOW (window)) {
1071 GtkWidget *header_view;
1072 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
1073 MODEST_WIDGET_TYPE_HEADER_VIEW);
1077 /* Show sorting dialog */
1078 modest_platform_run_sort_dialog (GTK_WINDOW (window), MODEST_SORT_HEADERS);
1083 new_messages_arrived (ModestMailOperation *self,
1087 if (new_messages == 0)
1090 modest_platform_on_new_msg ();
1094 * This function performs the send & receive required actions. The
1095 * window is used to create the mail operation. Typically it should
1096 * always be the main window, but we pass it as argument in order to
1100 modest_ui_actions_do_send_receive (const gchar *account_name, ModestWindow *win)
1102 gchar *acc_name = NULL;
1103 ModestMailOperation *mail_op;
1105 /* If no account name was provided then get the current account, and if
1106 there is no current account then pick the default one: */
1107 if (!account_name) {
1108 acc_name = g_strdup (modest_window_get_active_account(win));
1110 acc_name = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
1112 g_printerr ("modest: cannot get default account\n");
1116 acc_name = g_strdup (account_name);
1119 /* Set send/receive operation in progress */
1120 modest_main_window_notify_send_receive_initied (MODEST_MAIN_WINDOW(win));
1122 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_RECEIVE, G_OBJECT(win));
1123 g_signal_connect (G_OBJECT(mail_op), "progress-changed",
1124 G_CALLBACK (_on_send_receive_progress_changed),
1127 /* Send & receive. */
1128 /* TODO: The spec wants us to first do any pending deletions, before receiving. */
1129 /* Receive and then send. The operation is tagged initially as
1130 a receive operation because the account update performs a
1131 receive and then a send. The operation changes its type
1132 internally, so the progress objects will receive the proper
1133 progress information */
1134 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
1135 modest_mail_operation_update_account (mail_op, acc_name, new_messages_arrived, NULL);
1136 g_object_unref (G_OBJECT (mail_op));
1143 * Refreshes all accounts. This function will be used by automatic
1147 modest_ui_actions_do_send_receive_all (ModestWindow *win)
1149 GSList *account_names, *iter;
1151 account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
1154 iter = account_names;
1156 modest_ui_actions_do_send_receive ((const char*) iter->data, win);
1157 iter = g_slist_next (iter);
1160 modest_account_mgr_free_account_names (account_names);
1161 account_names = NULL;
1165 * Handler of the click on Send&Receive button in the main toolbar
1168 modest_ui_actions_on_send_receive (GtkAction *action, ModestWindow *win)
1170 /* Check if accounts exist */
1171 gboolean accounts_exist =
1172 modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
1174 /* If not, allow the user to create an account before trying to send/receive. */
1175 if (!accounts_exist)
1176 modest_ui_actions_on_accounts (NULL, win);
1178 /* Refresh the active account */
1179 modest_ui_actions_do_send_receive (NULL, win);
1184 modest_ui_actions_toggle_header_list_view (GtkAction *action, ModestMainWindow *main_window)
1187 GtkWidget *header_view;
1189 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1191 header_view = modest_main_window_get_child_widget (main_window,
1192 MODEST_WIDGET_TYPE_HEADER_VIEW);
1196 conf = modest_runtime_get_conf ();
1198 /* what is saved/restored is depending on the style; thus; we save with
1199 * old style, then update the style, and restore for this new style
1201 modest_widget_memory_save (conf, G_OBJECT(header_view), MODEST_CONF_HEADER_VIEW_KEY);
1203 if (modest_header_view_get_style
1204 (MODEST_HEADER_VIEW(header_view)) == MODEST_HEADER_VIEW_STYLE_DETAILS)
1205 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
1206 MODEST_HEADER_VIEW_STYLE_TWOLINES);
1208 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
1209 MODEST_HEADER_VIEW_STYLE_DETAILS);
1211 modest_widget_memory_restore (conf, G_OBJECT(header_view),
1212 MODEST_CONF_HEADER_VIEW_KEY);
1217 modest_ui_actions_on_header_selected (ModestHeaderView *header_view,
1219 ModestMainWindow *main_window)
1221 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1222 g_return_if_fail (MODEST_IS_HEADER_VIEW (header_view));
1224 /* If no header has been selected then exit */
1228 /* Update Main window title */
1229 if (gtk_widget_is_focus (GTK_WIDGET(header_view))) {
1230 const gchar *subject = tny_header_get_subject (header);
1231 if (subject && strlen(subject) > 0)
1232 gtk_window_set_title (GTK_WINDOW (main_window), subject);
1234 gtk_window_set_title (GTK_WINDOW (main_window), _("mail_va_no_subject"));
1237 /* Update toolbar dimming state */
1238 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
1242 modest_ui_actions_on_header_activated (ModestHeaderView *header_view,
1244 ModestMainWindow *main_window)
1248 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1253 headers = tny_simple_list_new ();
1254 tny_list_prepend (headers, G_OBJECT (header));
1256 _modest_ui_actions_open (headers, MODEST_WINDOW (main_window));
1258 g_object_unref (headers);
1262 set_active_account_from_tny_account (TnyAccount *account,
1263 ModestWindow *window)
1265 const gchar *server_acc_name = tny_account_get_id (account);
1267 /* We need the TnyAccount provided by the
1268 account store because that is the one that
1269 knows the name of the Modest account */
1270 TnyAccount *modest_server_account = modest_server_account =
1271 modest_tny_account_store_get_tny_account_by (modest_runtime_get_account_store (),
1272 MODEST_TNY_ACCOUNT_STORE_QUERY_ID,
1275 const gchar *modest_acc_name =
1276 modest_tny_account_get_parent_modest_account_name_for_server_account (modest_server_account);
1277 modest_window_set_active_account (window, modest_acc_name);
1278 g_object_unref (modest_server_account);
1283 folder_refreshed_cb (const GObject *obj,
1287 ModestMainWindow *win = NULL;
1288 GtkWidget *header_view;
1290 g_return_if_fail (TNY_IS_FOLDER (folder));
1292 win = MODEST_MAIN_WINDOW (user_data);
1294 modest_main_window_get_child_widget(win, MODEST_WIDGET_TYPE_HEADER_VIEW);
1296 /* Check if folder is empty and set headers view contents style */
1297 if (tny_folder_get_all_count (folder) == 0) {
1298 printf ("DEBUG: %s: tny_folder_get_all_count() returned 0.\n", __FUNCTION__);
1299 modest_main_window_set_contents_style (win,
1300 MODEST_MAIN_WINDOW_CONTENTS_STYLE_EMPTY);
1302 printf ("DEBUG: %s: tny_folder_get_all_count() returned >0.\n", __FUNCTION__);
1307 modest_ui_actions_on_folder_selection_changed (ModestFolderView *folder_view,
1308 TnyFolderStore *folder_store,
1310 ModestMainWindow *main_window)
1313 GtkWidget *header_view;
1315 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1317 header_view = modest_main_window_get_child_widget(main_window,
1318 MODEST_WIDGET_TYPE_HEADER_VIEW);
1322 conf = modest_runtime_get_conf ();
1324 if (TNY_IS_ACCOUNT (folder_store)) {
1326 /* Update active account */
1327 set_active_account_from_tny_account (TNY_ACCOUNT (folder_store), MODEST_WINDOW (main_window));
1328 /* Show account details */
1329 modest_main_window_set_contents_style (main_window, MODEST_MAIN_WINDOW_CONTENTS_STYLE_DETAILS);
1332 if (TNY_IS_FOLDER (folder_store) && selected) {
1334 /* Update the active account */
1335 TnyAccount *account = modest_tny_folder_get_account (TNY_FOLDER (folder_store));
1337 set_active_account_from_tny_account (account, MODEST_WINDOW (main_window));
1338 g_object_unref (account);
1342 /* Set the header style by default, it could
1343 be changed later by the refresh callback to
1345 modest_main_window_set_contents_style (main_window,
1346 MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS);
1348 /* Set folder on header view. This function
1349 will call tny_folder_refresh_async so we
1350 pass a callback that will be called when
1351 finished. We use that callback to set the
1352 empty view if there are no messages */
1353 modest_header_view_set_folder (MODEST_HEADER_VIEW(header_view),
1354 TNY_FOLDER (folder_store),
1355 folder_refreshed_cb,
1358 /* Restore configuration. We need to do this
1359 *after* the set_folder because the widget
1360 memory asks the header view about its
1362 modest_widget_memory_restore (modest_runtime_get_conf (),
1363 G_OBJECT(header_view),
1364 MODEST_CONF_HEADER_VIEW_KEY);
1366 /* Update the active account */
1367 modest_window_set_active_account (MODEST_WINDOW (main_window), NULL);
1368 /* Save only if we're seeing headers */
1369 if (modest_main_window_get_contents_style (main_window) ==
1370 MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS)
1371 modest_widget_memory_save (conf, G_OBJECT (header_view),
1372 MODEST_CONF_HEADER_VIEW_KEY);
1373 modest_header_view_clear (MODEST_HEADER_VIEW(header_view));
1377 /* Update toolbar dimming state */
1378 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
1382 modest_ui_actions_on_item_not_found (ModestHeaderView *header_view,ModestItemType type,
1389 item = (type == MODEST_ITEM_TYPE_FOLDER) ? "folder" : "message";
1391 if (g_main_depth > 0)
1392 gdk_threads_enter ();
1393 online = tny_device_is_online (modest_runtime_get_device());
1396 /* already online -- the item is simply not there... */
1397 dialog = gtk_message_dialog_new (GTK_WINDOW (win),
1399 GTK_MESSAGE_WARNING,
1401 _("The %s you selected cannot be found"),
1403 gtk_dialog_run (GTK_DIALOG(dialog));
1405 dialog = gtk_dialog_new_with_buttons (_("Connection requested"),
1409 GTK_RESPONSE_REJECT,
1411 GTK_RESPONSE_ACCEPT,
1413 txt = g_strdup_printf (_("This %s is not available in offline mode.\n"
1414 "Do you want to get online?"), item);
1415 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
1416 gtk_label_new (txt), FALSE, FALSE, 0);
1417 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
1420 gtk_window_set_default_size (GTK_WINDOW(dialog), 300, 300);
1421 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
1422 // modest_platform_connect_and_wait ();
1425 gtk_widget_destroy (dialog);
1426 if (g_main_depth > 0)
1427 gdk_threads_leave ();
1431 modest_ui_actions_on_msg_link_hover (ModestMsgView *msgview, const gchar* link,
1434 /* g_message ("%s %s", __FUNCTION__, link); */
1439 modest_ui_actions_on_msg_link_clicked (ModestMsgView *msgview, const gchar* link,
1442 modest_platform_activate_uri (link);
1446 modest_ui_actions_on_msg_link_contextual (ModestMsgView *msgview, const gchar* link,
1449 modest_platform_show_uri_popup (link);
1453 modest_ui_actions_on_msg_attachment_clicked (ModestMsgView *msgview, TnyMimePart *mime_part,
1456 modest_msg_view_window_view_attachment (MODEST_MSG_VIEW_WINDOW (win), mime_part);
1460 modest_ui_actions_on_msg_recpt_activated (ModestMsgView *msgview,
1461 const gchar *address,
1464 /* g_message ("%s %s", __FUNCTION__, address); */
1468 modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edit_window)
1470 TnyTransportAccount *transport_account;
1471 ModestMailOperation *mail_operation;
1473 gchar *account_name, *from;
1474 ModestAccountMgr *account_mgr;
1476 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window));
1478 data = modest_msg_edit_window_get_msg_data (edit_window);
1480 account_mgr = modest_runtime_get_account_mgr();
1481 account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
1483 account_name = modest_account_mgr_get_default_account (account_mgr);
1484 if (!account_name) {
1485 g_printerr ("modest: no account found\n");
1486 modest_msg_edit_window_free_msg_data (edit_window, data);
1490 if (!strcmp (account_name, MODEST_LOCAL_FOLDERS_ACCOUNT_ID)) {
1491 account_name = g_strdup (data->account_name);
1495 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
1496 (modest_runtime_get_account_store(),
1498 TNY_ACCOUNT_TYPE_TRANSPORT));
1499 if (!transport_account) {
1500 g_printerr ("modest: no transport account found for '%s'\n", account_name);
1501 g_free (account_name);
1502 modest_msg_edit_window_free_msg_data (edit_window, data);
1505 from = modest_account_mgr_get_from_string (account_mgr, account_name);
1507 /* Create the mail operation */
1508 mail_operation = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_INFO, G_OBJECT(edit_window));
1509 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
1511 modest_mail_operation_save_to_drafts (mail_operation,
1522 data->priority_flags);
1525 g_free (account_name);
1526 g_object_unref (G_OBJECT (transport_account));
1527 g_object_unref (G_OBJECT (mail_operation));
1529 modest_msg_edit_window_free_msg_data (edit_window, data);
1531 /* Save settings and close the window */
1532 gtk_widget_destroy (GTK_WIDGET (edit_window));
1535 /* For instance, when clicking the Send toolbar button when editing a message: */
1537 modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
1539 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window));
1541 if (!modest_msg_edit_window_check_names (edit_window))
1544 /* FIXME: Code added just for testing. The final version will
1545 use the send queue provided by tinymail and some
1547 ModestAccountMgr *account_mgr = modest_runtime_get_account_mgr();
1548 gchar *account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
1550 account_name = modest_account_mgr_get_default_account (account_mgr);
1552 if (!account_name) {
1553 g_printerr ("modest: no account found\n");
1557 MsgData *data = modest_msg_edit_window_get_msg_data (edit_window);
1559 if (!strcmp (account_name, MODEST_LOCAL_FOLDERS_ACCOUNT_ID)) {
1560 account_name = g_strdup (data->account_name);
1563 /* Get the currently-active transport account for this modest account: */
1564 TnyTransportAccount *transport_account =
1565 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_transport_account_for_open_connection
1566 (modest_runtime_get_account_store(),
1568 if (!transport_account) {
1569 g_printerr ("modest: no transport account found for '%s'\n", account_name);
1570 g_free (account_name);
1571 modest_msg_edit_window_free_msg_data (edit_window, data);
1575 gchar *from = modest_account_mgr_get_from_string (account_mgr, account_name);
1577 /* mail content checks and dialogs */
1578 if (data->subject == NULL || data->subject[0] == '\0') {
1579 GtkResponseType response;
1580 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (edit_window),
1581 _("mcen_nc_subject_is_empty_send"));
1582 if (response == GTK_RESPONSE_CANCEL) {
1583 g_free (account_name);
1588 if (data->plain_body == NULL || data->plain_body[0] == '\0') {
1589 GtkResponseType response;
1590 gchar *note_message;
1591 gchar *note_subject = data->subject;
1592 if (note_subject == NULL || note_subject[0] == '\0')
1593 note_subject = _("mail_va_no_subject");
1594 note_message = g_strdup_printf (_("emev_ni_ui_smtp_message_null"), note_subject);
1595 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (edit_window),
1597 g_free (note_message);
1598 if (response == GTK_RESPONSE_CANCEL) {
1599 g_free (account_name);
1604 modest_platform_information_banner (NULL, NULL, _("mcen_ib_outbox_waiting_to_be_sent"));
1606 /* Create the mail operation */
1607 ModestMailOperation *mail_operation = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_SEND, G_OBJECT(edit_window));
1608 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
1610 modest_mail_operation_send_new_mail (mail_operation,
1621 data->priority_flags);
1625 g_free (account_name);
1626 g_object_unref (G_OBJECT (transport_account));
1627 g_object_unref (G_OBJECT (mail_operation));
1629 modest_msg_edit_window_free_msg_data (edit_window, data);
1631 /* Save settings and close the window: */
1632 gtk_widget_destroy (GTK_WIDGET (edit_window));
1636 modest_ui_actions_on_toggle_bold (GtkToggleAction *action,
1637 ModestMsgEditWindow *window)
1639 ModestMsgEditFormatState *format_state = NULL;
1641 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1642 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
1644 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
1647 format_state = modest_msg_edit_window_get_format_state (window);
1648 g_return_if_fail (format_state != NULL);
1650 format_state->bold = gtk_toggle_action_get_active (action);
1651 modest_msg_edit_window_set_format_state (window, format_state);
1652 g_free (format_state);
1657 modest_ui_actions_on_toggle_italics (GtkToggleAction *action,
1658 ModestMsgEditWindow *window)
1660 ModestMsgEditFormatState *format_state = NULL;
1662 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1663 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
1665 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
1668 format_state = modest_msg_edit_window_get_format_state (window);
1669 g_return_if_fail (format_state != NULL);
1671 format_state->italics = gtk_toggle_action_get_active (action);
1672 modest_msg_edit_window_set_format_state (window, format_state);
1673 g_free (format_state);
1678 modest_ui_actions_on_toggle_bullets (GtkToggleAction *action,
1679 ModestMsgEditWindow *window)
1681 ModestMsgEditFormatState *format_state = NULL;
1683 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1684 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
1686 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
1689 format_state = modest_msg_edit_window_get_format_state (window);
1690 g_return_if_fail (format_state != NULL);
1692 format_state->bullet = gtk_toggle_action_get_active (action);
1693 modest_msg_edit_window_set_format_state (window, format_state);
1694 g_free (format_state);
1699 modest_ui_actions_on_change_justify (GtkRadioAction *action,
1700 GtkRadioAction *selected,
1701 ModestMsgEditWindow *window)
1703 ModestMsgEditFormatState *format_state = NULL;
1704 GtkJustification value;
1706 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1708 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
1711 value = gtk_radio_action_get_current_value (selected);
1713 format_state = modest_msg_edit_window_get_format_state (window);
1714 g_return_if_fail (format_state != NULL);
1716 format_state->justification = value;
1717 modest_msg_edit_window_set_format_state (window, format_state);
1718 g_free (format_state);
1722 modest_ui_actions_on_select_editor_color (GtkAction *action,
1723 ModestMsgEditWindow *window)
1725 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1726 g_return_if_fail (GTK_IS_ACTION (action));
1728 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
1731 modest_msg_edit_window_select_color (window);
1735 modest_ui_actions_on_select_editor_background_color (GtkAction *action,
1736 ModestMsgEditWindow *window)
1738 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1739 g_return_if_fail (GTK_IS_ACTION (action));
1741 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
1744 modest_msg_edit_window_select_background_color (window);
1748 modest_ui_actions_on_insert_image (GtkAction *action,
1749 ModestMsgEditWindow *window)
1751 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1752 g_return_if_fail (GTK_IS_ACTION (action));
1754 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
1757 modest_msg_edit_window_insert_image (window);
1761 modest_ui_actions_on_attach_file (GtkAction *action,
1762 ModestMsgEditWindow *window)
1764 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1765 g_return_if_fail (GTK_IS_ACTION (action));
1767 modest_msg_edit_window_attach_file (window);
1771 modest_ui_actions_on_remove_attachments (GtkAction *action,
1772 ModestMsgEditWindow *window)
1774 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1775 g_return_if_fail (GTK_IS_ACTION (action));
1777 modest_msg_edit_window_remove_attachments (window, NULL);
1781 modest_ui_actions_on_new_folder (GtkAction *action, ModestMainWindow *main_window)
1783 TnyFolderStore *parent_folder;
1784 GtkWidget *folder_view;
1786 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1788 folder_view = modest_main_window_get_child_widget (main_window,
1789 MODEST_WIDGET_TYPE_FOLDER_VIEW);
1793 parent_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
1795 if (parent_folder) {
1796 gboolean finished = FALSE;
1798 gchar *folder_name = NULL, *suggested_name = NULL;
1800 /* Run the new folder dialog */
1802 result = modest_platform_run_new_folder_dialog (GTK_WINDOW (main_window),
1807 if (result == GTK_RESPONSE_REJECT) {
1810 ModestMailOperation *mail_op;
1811 TnyFolder *new_folder = NULL;
1813 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_INFO,
1814 G_OBJECT(main_window));
1815 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
1817 new_folder = modest_mail_operation_create_folder (mail_op,
1819 (const gchar *) folder_name);
1821 g_object_unref (new_folder);
1824 g_object_unref (mail_op);
1826 g_free (folder_name);
1830 g_object_unref (parent_folder);
1835 modest_ui_actions_on_rename_folder (GtkAction *action,
1836 ModestMainWindow *main_window)
1838 TnyFolderStore *folder;
1839 GtkWidget *folder_view;
1840 GtkWidget *header_view;
1842 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1844 folder_view = modest_main_window_get_child_widget (main_window,
1845 MODEST_WIDGET_TYPE_FOLDER_VIEW);
1849 header_view = modest_main_window_get_child_widget (main_window,
1850 MODEST_WIDGET_TYPE_HEADER_VIEW);
1855 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
1857 if (folder && TNY_IS_FOLDER (folder)) {
1860 const gchar *current_name;
1862 current_name = tny_folder_get_name (TNY_FOLDER (folder));
1863 response = modest_platform_run_rename_folder_dialog (GTK_WINDOW (main_window), NULL,
1864 current_name, &folder_name);
1866 if (response == GTK_RESPONSE_OK && strlen (folder_name) > 0) {
1867 ModestMailOperation *mail_op;
1869 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_INFO, G_OBJECT(main_window));
1870 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
1873 modest_header_view_clear (MODEST_HEADER_VIEW (header_view));
1875 modest_mail_operation_rename_folder (mail_op,
1876 TNY_FOLDER (folder),
1877 (const gchar *) folder_name);
1879 g_object_unref (mail_op);
1880 g_free (folder_name);
1882 g_object_unref (folder);
1887 modest_ui_actions_delete_folder_error_handler (ModestMailOperation *mail_op,
1890 GObject *win = modest_mail_operation_get_source (mail_op);
1892 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
1893 _("mail_in_ui_folder_delete_error"));
1894 g_object_unref (win);
1898 delete_folder (ModestMainWindow *main_window, gboolean move_to_trash)
1900 TnyFolderStore *folder;
1901 GtkWidget *folder_view;
1905 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1907 folder_view = modest_main_window_get_child_widget (main_window,
1908 MODEST_WIDGET_TYPE_FOLDER_VIEW);
1912 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
1914 /* Show an error if it's an account */
1915 if (!TNY_IS_FOLDER (folder)) {
1916 modest_platform_run_information_dialog (GTK_WINDOW (main_window),
1917 _("mail_in_ui_folder_delete_error"));
1922 message = g_strdup_printf (_("mcen_nc_delete_folder_text"),
1923 tny_folder_get_name (TNY_FOLDER (folder)));
1924 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (main_window),
1925 (const gchar *) message);
1928 if (response == GTK_RESPONSE_OK) {
1929 ModestMailOperation *mail_op =
1930 modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_DELETE,
1931 G_OBJECT(main_window),
1932 modest_ui_actions_delete_folder_error_handler,
1935 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
1937 modest_mail_operation_remove_folder (mail_op, TNY_FOLDER (folder), move_to_trash);
1938 g_object_unref (G_OBJECT (mail_op));
1941 g_object_unref (G_OBJECT (folder));
1945 modest_ui_actions_on_delete_folder (GtkAction *action,
1946 ModestMainWindow *main_window)
1948 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1950 delete_folder (main_window, FALSE);
1954 modest_ui_actions_on_move_folder_to_trash_folder (GtkAction *action, ModestMainWindow *main_window)
1956 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1958 delete_folder (main_window, TRUE);
1962 modest_ui_actions_on_password_requested (TnyAccountStore *account_store,
1963 const gchar* server_account_name,
1968 ModestMainWindow *main_window)
1970 g_return_if_fail(server_account_name);
1971 /* printf("DEBUG: %s: server_account_name=%s\n", __FUNCTION__, server_account_name); */
1973 /* Initalize output parameters: */
1980 #ifdef MODEST_PLATFORM_MAEMO
1981 /* Maemo uses a different (awkward) button order,
1982 * It should probably just use gtk_alternative_dialog_button_order ().
1984 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
1988 GTK_RESPONSE_ACCEPT,
1990 GTK_RESPONSE_REJECT,
1993 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
1997 GTK_RESPONSE_REJECT,
1999 GTK_RESPONSE_ACCEPT,
2001 #endif /* MODEST_PLATFORM_MAEMO */
2003 gtk_window_set_transient_for (GTK_WINDOW(dialog), GTK_WINDOW(main_window));
2005 gchar *server_name = modest_server_account_get_hostname (
2006 modest_runtime_get_account_mgr(), server_account_name);
2007 if (!server_name) {/* This happened once, though I don't know why. murrayc. */
2008 g_warning("%s: Could not get server name for server account '%s'", __FUNCTION__, server_account_name);
2013 /* This causes a warning because the logical ID has no %s in it,
2014 * though the translation does, but there is not much we can do about that: */
2015 gchar *txt = g_strdup_printf (_("mail_ia_password_info"), server_name);
2016 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), gtk_label_new(txt),
2019 g_free (server_name);
2023 gchar *initial_username = modest_server_account_get_username (
2024 modest_runtime_get_account_mgr(), server_account_name);
2026 GtkWidget *entry_username = gtk_entry_new ();
2027 if (initial_username)
2028 gtk_entry_set_text (GTK_ENTRY (entry_username), initial_username);
2029 /* Dim this if a connection has ever succeeded with this username,
2030 * as per the UI spec: */
2031 const gboolean username_known =
2032 modest_server_account_get_username_has_succeeded(
2033 modest_runtime_get_account_mgr(), server_account_name);
2034 gtk_widget_set_sensitive (entry_username, !username_known);
2036 #ifdef MODEST_PLATFORM_MAEMO
2037 /* Auto-capitalization is the default, so let's turn it off: */
2038 hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_username), HILDON_GTK_INPUT_MODE_FULL);
2040 /* Create a size group to be used by all captions.
2041 * Note that HildonCaption does not create a default size group if we do not specify one.
2042 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
2043 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
2045 GtkWidget *caption = hildon_caption_new (sizegroup,
2046 _("mail_fi_username"), entry_username, NULL, HILDON_CAPTION_MANDATORY);
2047 gtk_widget_show (entry_username);
2048 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
2049 FALSE, FALSE, MODEST_MARGIN_HALF);
2050 gtk_widget_show (caption);
2052 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry_username,
2054 #endif /* MODEST_PLATFORM_MAEMO */
2057 GtkWidget *entry_password = gtk_entry_new ();
2058 gtk_entry_set_visibility (GTK_ENTRY(entry_password), FALSE);
2059 /* gtk_entry_set_invisible_char (GTK_ENTRY(entry_password), "*"); */
2061 #ifdef MODEST_PLATFORM_MAEMO
2062 /* Auto-capitalization is the default, so let's turn it off: */
2063 hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_password),
2064 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
2066 caption = hildon_caption_new (sizegroup,
2067 _("mail_fi_password"), entry_password, NULL, HILDON_CAPTION_MANDATORY);
2068 gtk_widget_show (entry_password);
2069 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
2070 FALSE, FALSE, MODEST_MARGIN_HALF);
2071 gtk_widget_show (caption);
2072 g_object_unref (sizegroup);
2074 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry_password,
2076 #endif /* MODEST_PLATFORM_MAEMO */
2078 /* This is not in the Maemo UI spec:
2079 remember_pass_check = gtk_check_button_new_with_label (_("Remember password"));
2080 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), remember_pass_check,
2084 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
2086 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
2088 *username = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_username)));
2090 modest_server_account_set_username (
2091 modest_runtime_get_account_mgr(), server_account_name,
2094 const gboolean username_was_changed =
2095 (strcmp (*username, initial_username) != 0);
2096 if (username_was_changed) {
2097 /* To actually use a changed username,
2098 * we must reset the connection, according to pvanhoof.
2099 * This _might_ be a sensible way to do that: */
2100 TnyDevice *device = modest_runtime_get_device();
2101 tny_device_force_offline (device);
2102 tny_device_force_online (device);
2107 *password = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_password)));
2109 /* We do not save the password in the configuration,
2110 * because this function is only called for passwords that should
2111 * not be remembered:
2112 modest_server_account_set_password (
2113 modest_runtime_get_account_mgr(), server_account_name,
2132 /* This is not in the Maemo UI spec:
2133 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (remember_pass_check)))
2139 gtk_widget_destroy (dialog);
2141 /* printf ("DEBUG: %s: cancel=%d\n", __FUNCTION__, *cancel); */
2145 modest_ui_actions_on_cut (GtkAction *action,
2146 ModestWindow *window)
2148 GtkWidget *focused_widget;
2150 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
2151 if (GTK_IS_EDITABLE (focused_widget)) {
2152 gtk_editable_cut_clipboard (GTK_EDITABLE(focused_widget));
2153 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
2154 GtkTextBuffer *buffer;
2155 GtkClipboard *clipboard;
2157 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
2158 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
2159 gtk_text_buffer_cut_clipboard (buffer, clipboard, TRUE);
2160 } else if (MODEST_IS_HEADER_VIEW (focused_widget)) {
2161 modest_header_view_cut_selection (MODEST_HEADER_VIEW (focused_widget));
2162 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
2163 modest_folder_view_cut_selection (MODEST_FOLDER_VIEW (focused_widget));
2168 modest_ui_actions_on_copy (GtkAction *action,
2169 ModestWindow *window)
2171 GtkClipboard *clipboard;
2172 GtkWidget *focused_widget;
2174 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
2175 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
2177 if (GTK_IS_LABEL (focused_widget)) {
2178 gtk_clipboard_set_text (clipboard, gtk_label_get_text (GTK_LABEL (focused_widget)), -1);
2179 } else if (GTK_IS_EDITABLE (focused_widget)) {
2180 gtk_editable_copy_clipboard (GTK_EDITABLE(focused_widget));
2181 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
2182 GtkTextBuffer *buffer;
2183 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
2184 gtk_text_buffer_copy_clipboard (buffer, clipboard);
2185 modest_header_view_copy_selection (MODEST_HEADER_VIEW (focused_widget));
2186 } else if (MODEST_IS_HEADER_VIEW (focused_widget)) {
2187 TnyList *header_list = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW (focused_widget));
2188 TnyIterator *iter = tny_list_create_iterator (header_list);
2189 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter));
2190 TnyFolder *folder = tny_header_get_folder (header);
2191 TnyAccount *account = tny_folder_get_account (folder);
2192 const gchar *proto_str = tny_account_get_proto (TNY_ACCOUNT (account));
2193 /* If it's POP then ask */
2194 gboolean ask = (modest_protocol_info_get_transport_store_protocol (proto_str) ==
2195 MODEST_PROTOCOL_STORE_POP) ? TRUE : FALSE;
2196 g_object_unref (account);
2197 g_object_unref (folder);
2198 g_object_unref (header);
2199 g_object_unref (iter);
2201 /* Check that the messages have been previously downloaded */
2202 gboolean continue_download = TRUE;
2204 continue_download = download_uncached_messages (header_list, GTK_WINDOW (window));
2205 if (continue_download)
2206 modest_header_view_copy_selection (MODEST_HEADER_VIEW (focused_widget));
2207 g_object_unref (header_list);
2208 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
2209 modest_folder_view_copy_selection (MODEST_FOLDER_VIEW (focused_widget));
2214 modest_ui_actions_on_undo (GtkAction *action,
2215 ModestWindow *window)
2217 if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
2218 modest_msg_edit_window_undo (MODEST_MSG_EDIT_WINDOW (window));
2220 g_return_if_reached ();
2225 modest_ui_actions_on_paste (GtkAction *action,
2226 ModestWindow *window)
2228 GtkWidget *focused_widget;
2229 ModestMailOperation *mail_op = NULL;
2231 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
2232 if (GTK_IS_EDITABLE (focused_widget)) {
2233 gtk_editable_paste_clipboard (GTK_EDITABLE(focused_widget));
2234 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
2235 GtkTextBuffer *buffer;
2236 GtkClipboard *clipboard;
2238 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
2239 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
2240 gtk_text_buffer_paste_clipboard (buffer, clipboard, NULL, TRUE);
2241 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
2242 ModestEmailClipboard *clipboard = NULL;
2243 TnyFolder *src_folder = NULL;
2244 TnyFolderStore *folder_store = NULL;
2245 TnyList *data = NULL;
2246 gboolean delete = FALSE;
2248 /* Check clipboard source */
2249 clipboard = modest_runtime_get_email_clipboard ();
2250 if (modest_email_clipboard_cleared (clipboard))
2253 /* Get elements to paste */
2254 modest_email_clipboard_get_data (clipboard, &src_folder, &data, &delete);
2256 /* Create a new mail operation */
2257 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_RECEIVE, G_OBJECT(window));
2258 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
2261 /* Get destination folder */
2262 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (focused_widget));
2264 /* transfer messages */
2266 modest_mail_operation_xfer_msgs (mail_op,
2268 TNY_FOLDER (folder_store),
2273 } else if (src_folder != NULL) {
2274 modest_mail_operation_xfer_folder (mail_op,
2282 g_object_unref (data);
2283 if (src_folder != NULL)
2284 g_object_unref (src_folder);
2285 if (folder_store != NULL)
2286 g_object_unref (folder_store);
2291 modest_ui_actions_on_select_all (GtkAction *action,
2292 ModestWindow *window)
2294 GtkWidget *focused_widget;
2296 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
2297 if (MODEST_IS_ATTACHMENTS_VIEW (focused_widget)) {
2298 modest_attachments_view_select_all (MODEST_ATTACHMENTS_VIEW (focused_widget));
2299 } else if (GTK_IS_LABEL (focused_widget)) {
2300 gtk_label_select_region (GTK_LABEL (focused_widget), 0, -1);
2301 } else if (GTK_IS_EDITABLE (focused_widget)) {
2302 gtk_editable_select_region (GTK_EDITABLE(focused_widget), 0, -1);
2303 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
2304 GtkTextBuffer *buffer;
2305 GtkTextIter start, end;
2307 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
2308 gtk_text_buffer_get_start_iter (buffer, &start);
2309 gtk_text_buffer_get_end_iter (buffer, &end);
2310 gtk_text_buffer_select_range (buffer, &start, &end);
2312 else if ((MODEST_IS_FOLDER_VIEW (focused_widget)) ||
2313 (MODEST_IS_HEADER_VIEW (focused_widget))) {
2315 GtkTreeSelection *selection = NULL;
2317 /* Get header view */
2318 GtkWidget *header_view = focused_widget;
2319 if (MODEST_IS_FOLDER_VIEW (focused_widget))
2320 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (window),
2321 MODEST_WIDGET_TYPE_HEADER_VIEW);
2323 /* Select all messages */
2324 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(header_view));
2325 gtk_tree_selection_select_all (selection);
2327 /* Set focuse on header view */
2328 gtk_widget_grab_focus (header_view);
2330 } else if (GTK_IS_HTML (focused_widget)) {
2331 gtk_html_select_all (GTK_HTML (focused_widget));
2336 modest_ui_actions_on_mark_as_read (GtkAction *action,
2337 ModestWindow *window)
2339 g_return_if_fail (MODEST_IS_WINDOW(window));
2341 /* Mark each header as read */
2342 do_headers_action (window, headers_action_mark_as_read, NULL);
2346 modest_ui_actions_on_mark_as_unread (GtkAction *action,
2347 ModestWindow *window)
2349 g_return_if_fail (MODEST_IS_WINDOW(window));
2351 /* Mark each header as read */
2352 do_headers_action (window, headers_action_mark_as_unread, NULL);
2356 modest_ui_actions_on_change_zoom (GtkRadioAction *action,
2357 GtkRadioAction *selected,
2358 ModestWindow *window)
2362 value = gtk_radio_action_get_current_value (selected);
2363 if (MODEST_IS_WINDOW (window)) {
2364 modest_window_set_zoom (MODEST_WINDOW (window), ((gdouble)value)/100);
2368 void modest_ui_actions_msg_edit_on_change_priority (GtkRadioAction *action,
2369 GtkRadioAction *selected,
2370 ModestWindow *window)
2372 TnyHeaderFlags flags;
2373 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2375 flags = gtk_radio_action_get_current_value (selected);
2376 modest_msg_edit_window_set_priority_flags (MODEST_MSG_EDIT_WINDOW (window), flags);
2379 void modest_ui_actions_msg_edit_on_change_file_format (GtkRadioAction *action,
2380 GtkRadioAction *selected,
2381 ModestWindow *window)
2385 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2387 file_format = gtk_radio_action_get_current_value (selected);
2388 modest_msg_edit_window_set_file_format (MODEST_MSG_EDIT_WINDOW (window), file_format);
2393 modest_ui_actions_on_zoom_plus (GtkAction *action,
2394 ModestWindow *window)
2396 g_return_if_fail (MODEST_IS_WINDOW (window));
2398 modest_window_zoom_plus (MODEST_WINDOW (window));
2402 modest_ui_actions_on_zoom_minus (GtkAction *action,
2403 ModestWindow *window)
2405 g_return_if_fail (MODEST_IS_WINDOW (window));
2407 modest_window_zoom_minus (MODEST_WINDOW (window));
2411 modest_ui_actions_on_toggle_fullscreen (GtkToggleAction *toggle,
2412 ModestWindow *window)
2414 ModestWindowMgr *mgr;
2415 gboolean fullscreen, active;
2416 g_return_if_fail (MODEST_IS_WINDOW (window));
2418 mgr = modest_runtime_get_window_mgr ();
2420 active = (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle)))?1:0;
2421 fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
2423 if (active != fullscreen) {
2424 modest_window_mgr_set_fullscreen_mode (mgr, active);
2425 gtk_window_present (GTK_WINDOW (window));
2430 modest_ui_actions_on_change_fullscreen (GtkAction *action,
2431 ModestWindow *window)
2433 ModestWindowMgr *mgr;
2434 gboolean fullscreen;
2436 g_return_if_fail (MODEST_IS_WINDOW (window));
2438 mgr = modest_runtime_get_window_mgr ();
2439 fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
2440 modest_window_mgr_set_fullscreen_mode (mgr, !fullscreen);
2442 gtk_window_present (GTK_WINDOW (window));
2446 * Used by modest_ui_actions_on_details to call do_headers_action
2449 headers_action_show_details (TnyHeader *header,
2450 ModestWindow *window,
2457 dialog = modest_details_dialog_new_with_header (GTK_WINDOW (window), header);
2460 gtk_widget_show_all (dialog);
2461 gtk_dialog_run (GTK_DIALOG (dialog));
2463 gtk_widget_destroy (dialog);
2467 * Show the folder details in a ModestDetailsDialog widget
2470 show_folder_details (TnyFolder *folder,
2476 dialog = modest_details_dialog_new_with_folder (window, folder);
2479 gtk_widget_show_all (dialog);
2480 gtk_dialog_run (GTK_DIALOG (dialog));
2482 gtk_widget_destroy (dialog);
2486 * Show the header details in a ModestDetailsDialog widget
2489 modest_ui_actions_on_details (GtkAction *action,
2492 TnyList * headers_list;
2496 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
2499 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW (win));
2502 g_object_unref (msg);
2504 headers_list = get_selected_headers (win);
2508 iter = tny_list_create_iterator (headers_list);
2510 header = TNY_HEADER (tny_iterator_get_current (iter));
2511 headers_action_show_details (header, win, NULL);
2512 g_object_unref (header);
2514 g_object_unref (iter);
2515 g_object_unref (headers_list);
2517 } else if (MODEST_IS_MAIN_WINDOW (win)) {
2518 GtkWidget *folder_view, *header_view;
2520 /* Check which widget has the focus */
2521 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
2522 MODEST_WIDGET_TYPE_FOLDER_VIEW);
2523 if (gtk_widget_is_focus (folder_view)) {
2524 TnyFolderStore *folder_store
2525 = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
2526 if (!folder_store) {
2527 g_warning ("%s: No item was selected.\n", __FUNCTION__);
2530 /* Show only when it's a folder */
2531 /* This function should not be called for account items,
2532 * because we dim the menu item for them. */
2533 if (TNY_IS_FOLDER (folder_store)) {
2534 show_folder_details (TNY_FOLDER (folder_store), GTK_WINDOW (win));
2537 g_object_unref (folder_store);
2540 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
2541 MODEST_WIDGET_TYPE_HEADER_VIEW);
2542 /* Show details of each header */
2543 do_headers_action (win, headers_action_show_details, header_view);
2549 modest_ui_actions_on_toggle_show_cc (GtkToggleAction *toggle,
2550 ModestMsgEditWindow *window)
2552 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2554 modest_msg_edit_window_show_cc (window, gtk_toggle_action_get_active (toggle));
2558 modest_ui_actions_on_toggle_show_bcc (GtkToggleAction *toggle,
2559 ModestMsgEditWindow *window)
2561 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2563 modest_msg_edit_window_show_bcc (window, gtk_toggle_action_get_active (toggle));
2567 modest_ui_actions_toggle_folders_view (GtkAction *action,
2568 ModestMainWindow *main_window)
2572 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2574 conf = modest_runtime_get_conf ();
2576 if (modest_main_window_get_style (main_window) == MODEST_MAIN_WINDOW_STYLE_SPLIT)
2577 modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SIMPLE);
2579 modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SPLIT);
2583 modest_ui_actions_on_toggle_toolbar (GtkToggleAction *toggle,
2584 ModestWindow *window)
2586 gboolean active, fullscreen = FALSE;
2587 ModestWindowMgr *mgr;
2589 active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle));
2591 /* Check if we want to toggle the toolbar vuew in fullscreen
2593 if (!strcmp (gtk_action_get_name (GTK_ACTION (toggle)),
2594 "ViewShowToolbarFullScreen")) {
2598 /* Toggle toolbar */
2599 mgr = modest_runtime_get_window_mgr ();
2600 modest_window_mgr_show_toolbars (mgr, active, fullscreen);
2604 modest_ui_actions_msg_edit_on_select_font (GtkAction *action,
2605 ModestMsgEditWindow *window)
2607 modest_msg_edit_window_select_font (window);
2611 modest_ui_actions_on_folder_display_name_changed (ModestFolderView *folder_view,
2612 const gchar *display_name,
2615 /* Do not change the application name if the widget has not
2616 the focus. This callback could be called even if the folder
2617 view has not the focus, because the handled signal could be
2618 emitted when the folder view is redrawn */
2619 if (gtk_widget_is_focus (GTK_WIDGET (folder_view))) {
2621 gtk_window_set_title (window, display_name);
2623 gtk_window_set_title (window, " ");
2628 modest_ui_actions_on_select_contacts (GtkAction *action, ModestMsgEditWindow *window)
2630 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2631 modest_msg_edit_window_select_contacts (window);
2635 modest_ui_actions_on_check_names (GtkAction *action, ModestMsgEditWindow *window)
2637 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2638 modest_msg_edit_window_check_names (window);
2643 create_move_to_dialog (ModestWindow *win,
2644 GtkWidget *folder_view,
2645 GtkWidget **tree_view)
2647 GtkWidget *dialog, *scroll;
2649 dialog = gtk_dialog_new_with_buttons (_("mcen_ti_moveto_folders_title"),
2651 GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR | GTK_DIALOG_DESTROY_WITH_PARENT,
2653 GTK_RESPONSE_ACCEPT,
2655 GTK_RESPONSE_REJECT,
2658 /* Create scrolled window */
2659 scroll = gtk_scrolled_window_new (NULL, NULL);
2660 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll),
2661 GTK_POLICY_AUTOMATIC,
2662 GTK_POLICY_AUTOMATIC);
2664 /* Create folder view */
2665 *tree_view = modest_platform_create_folder_view (NULL);
2667 /* It could happen that we're trying to move a message from a
2668 window (msg window for example) after the main window was
2669 closed, so we can not just get the model of the folder
2671 if (MODEST_IS_FOLDER_VIEW (folder_view))
2672 gtk_tree_view_set_model (GTK_TREE_VIEW (*tree_view),
2673 gtk_tree_view_get_model (GTK_TREE_VIEW (folder_view)));
2675 modest_folder_view_update_model (MODEST_FOLDER_VIEW (*tree_view),
2676 TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()));
2678 gtk_container_add (GTK_CONTAINER (scroll), *tree_view);
2680 /* Add scroll to dialog */
2681 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
2682 scroll, FALSE, FALSE, 0);
2684 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
2686 /* Select INBOX or local account */
2687 modest_folder_view_select_first_inbox_or_local (MODEST_FOLDER_VIEW (*tree_view));
2693 * Returns TRUE if at least one of the headers of the list belongs to
2694 * a message that has been fully retrieved.
2697 has_retrieved_msgs (TnyList *list)
2700 gboolean found = FALSE;
2702 iter = tny_list_create_iterator (list);
2703 while (tny_iterator_is_done (iter) && !found) {
2705 TnyHeaderFlags flags;
2707 header = TNY_HEADER (tny_iterator_get_current (iter));
2708 flags = tny_header_get_flags (header);
2709 if (!(flags & TNY_HEADER_FLAG_PARTIAL))
2713 tny_iterator_next (iter);
2715 g_object_unref (iter);
2721 * Shows a confirmation dialog to the user when we're moving messages
2722 * from a remote server to the local storage. Returns the dialog
2723 * response. If it's other kind of movement the it always returns
2727 msgs_move_to_confirmation (GtkWindow *win,
2728 TnyFolder *dest_folder,
2731 gint response = GTK_RESPONSE_OK;
2733 /* If the destination is a local folder */
2734 if (modest_tny_folder_is_local_folder (dest_folder)) {
2735 TnyFolder *src_folder;
2739 /* Get source folder */
2740 iter = tny_list_create_iterator (headers);
2741 header = TNY_HEADER (tny_iterator_get_current (iter));
2742 src_folder = tny_header_get_folder (header);
2743 g_object_unref (header);
2744 g_object_unref (iter);
2746 /* If the source is a remote folder */
2747 if (!modest_tny_folder_is_local_folder (src_folder)) {
2748 const gchar *message;
2750 if (has_retrieved_msgs (headers))
2751 message = ngettext ("mcen_nc_move_retrieve", "mcen_nc_move_retrieves",
2752 tny_list_get_length (headers));
2754 message = ngettext ("mcen_nc_move_header", "mcen_nc_move_headers",
2755 tny_list_get_length (headers));
2757 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
2758 (const gchar *) message);
2760 g_object_unref (src_folder);
2767 transfer_msgs_from_viewer_cb (const GObject *object, gpointer user_data)
2769 ModestMsgViewWindow *self = NULL;
2771 g_return_if_fail (MODEST_IS_MSG_VIEW_WINDOW (object));
2772 self = MODEST_MSG_VIEW_WINDOW (object);
2774 /* If there are not more messages don't do anything. The
2775 viewer will show the same message */
2776 if (!modest_msg_view_window_select_first_message (self))
2781 modest_ui_actions_move_folder_error_handler (ModestMailOperation *mail_op,
2784 GObject *win = modest_mail_operation_get_source (mail_op);
2786 /* TODO: show error message */
2787 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
2788 _("mail_in_ui_folder_move_target_error"));
2789 g_object_unref (win);
2793 * UI handler for the "Move to" action when invoked from the
2797 modest_ui_actions_on_main_window_move_to (GtkAction *action,
2798 ModestMainWindow *win)
2800 GtkWidget *dialog = NULL, *folder_view = NULL, *tree_view = NULL;
2801 GtkWidget *header_view = NULL;
2803 TnyFolderStore *folder_store = NULL;
2804 ModestMailOperation *mail_op = NULL;
2806 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win));
2808 /* Get the folder view */
2809 folder_view = modest_main_window_get_child_widget (win,
2810 MODEST_WIDGET_TYPE_FOLDER_VIEW);
2812 /* Get header view */
2813 header_view = modest_main_window_get_child_widget (win,
2814 MODEST_WIDGET_TYPE_HEADER_VIEW);
2816 /* Create and run the dialog */
2817 dialog = create_move_to_dialog (MODEST_WINDOW (win), folder_view, &tree_view);
2818 modest_folder_view_select_first_inbox_or_local (MODEST_FOLDER_VIEW (tree_view));
2819 result = gtk_dialog_run (GTK_DIALOG(dialog));
2820 g_object_ref (tree_view);
2822 /* We do this to save an indentation level ;-) */
2823 if (result != GTK_RESPONSE_ACCEPT)
2826 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (tree_view));
2828 if (TNY_IS_ACCOUNT (folder_store))
2831 /* Get folder or messages to transfer */
2832 if (gtk_widget_is_focus (folder_view)) {
2833 TnyFolderStore *src_folder;
2834 src_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
2836 /* Clean folder on header view before moving it */
2837 modest_header_view_clear (MODEST_HEADER_VIEW (header_view));
2839 if (TNY_IS_FOLDER (src_folder)) {
2841 modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE,
2843 modest_ui_actions_move_folder_error_handler,
2845 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
2847 modest_mail_operation_xfer_folder (mail_op,
2848 TNY_FOLDER (src_folder),
2851 /* Unref mail operation */
2852 g_object_unref (G_OBJECT (mail_op));
2856 g_object_unref (G_OBJECT (src_folder));
2858 if (gtk_widget_is_focus (header_view)) {
2862 headers = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW (header_view));
2864 /* Ask for user confirmation */
2865 response = msgs_move_to_confirmation (GTK_WINDOW (win),
2866 TNY_FOLDER (folder_store),
2869 /* Transfer messages */
2870 if (response == GTK_RESPONSE_OK) {
2871 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_RECEIVE, G_OBJECT(win));
2872 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
2875 modest_mail_operation_xfer_msgs (mail_op,
2877 TNY_FOLDER (folder_store),
2882 g_object_unref (G_OBJECT (mail_op));
2884 g_object_unref (headers);
2887 g_object_unref (folder_store);
2889 gtk_widget_destroy (dialog);
2894 * UI handler for the "Move to" action when invoked from the
2895 * ModestMsgViewWindow
2898 modest_ui_actions_on_msg_view_window_move_to (GtkAction *action,
2899 ModestMsgViewWindow *win)
2901 GtkWidget *dialog, *folder_view, *tree_view = NULL;
2903 ModestMainWindow *main_window;
2907 /* Get the folder view */
2908 main_window = MODEST_MAIN_WINDOW (modest_window_mgr_get_main_window (modest_runtime_get_window_mgr ()));
2910 folder_view = modest_main_window_get_child_widget (main_window,
2911 MODEST_WIDGET_TYPE_FOLDER_VIEW);
2915 /* Create and run the dialog */
2916 dialog = create_move_to_dialog (MODEST_WINDOW (win), folder_view, &tree_view);
2917 result = gtk_dialog_run (GTK_DIALOG(dialog));
2918 g_object_ref (tree_view);
2920 if (result == GTK_RESPONSE_ACCEPT) {
2921 TnyFolderStore *folder_store;
2924 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (tree_view));
2926 /* Create header list */
2927 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
2928 headers = tny_simple_list_new ();
2929 tny_list_prepend (headers, G_OBJECT (header));
2930 g_object_unref (header);
2932 /* Ask user for confirmation. MSG-NOT404 */
2933 response = msgs_move_to_confirmation (GTK_WINDOW (win),
2934 TNY_FOLDER (folder_store),
2937 /* Transfer current msg */
2938 if (response == GTK_RESPONSE_OK) {
2939 ModestMailOperation *mail_op;
2941 /* Create mail op */
2942 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_RECEIVE, G_OBJECT(win));
2943 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
2946 /* Transfer messages */
2947 modest_mail_operation_xfer_msgs (mail_op,
2949 TNY_FOLDER (folder_store),
2951 transfer_msgs_from_viewer_cb,
2953 g_object_unref (G_OBJECT (mail_op));
2955 g_object_unref (headers);
2956 g_object_unref (folder_store);
2958 gtk_widget_destroy (dialog);
2962 modest_ui_actions_on_move_to (GtkAction *action,
2965 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win) ||
2966 MODEST_IS_MSG_VIEW_WINDOW (win));
2968 if (MODEST_IS_MAIN_WINDOW (win))
2969 modest_ui_actions_on_main_window_move_to (action,
2970 MODEST_MAIN_WINDOW (win));
2972 modest_ui_actions_on_msg_view_window_move_to (action,
2973 MODEST_MSG_VIEW_WINDOW (win));
2977 * Calls #HeadersFunc for each header already selected in the main
2978 * window or the message currently being shown in the msg view window
2981 do_headers_action (ModestWindow *win,
2985 TnyList *headers_list;
2991 headers_list = get_selected_headers (win);
2995 /* Get the folder */
2996 iter = tny_list_create_iterator (headers_list);
2997 header = TNY_HEADER (tny_iterator_get_current (iter));
2998 folder = tny_header_get_folder (header);
2999 g_object_unref (header);
3001 /* Call the function for each header */
3002 while (!tny_iterator_is_done (iter)) {
3003 header = TNY_HEADER (tny_iterator_get_current (iter));
3004 func (header, win, user_data);
3005 g_object_unref (header);
3006 tny_iterator_next (iter);
3009 /* Trick: do a poke status in order to speed up the signaling
3011 tny_folder_poke_status (folder);
3014 g_object_unref (folder);
3015 g_object_unref (iter);
3016 g_object_unref (headers_list);
3020 modest_ui_actions_view_attachment (GtkAction *action,
3021 ModestWindow *window)
3023 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
3024 modest_msg_view_window_view_attachment (MODEST_MSG_VIEW_WINDOW (window), NULL);
3026 /* not supported window for this action */
3027 g_return_if_reached ();
3032 modest_ui_actions_save_attachments (GtkAction *action,
3033 ModestWindow *window)
3035 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
3036 modest_msg_view_window_save_attachments (MODEST_MSG_VIEW_WINDOW (window), NULL);
3038 /* not supported window for this action */
3039 g_return_if_reached ();
3044 modest_ui_actions_remove_attachments (GtkAction *action,
3045 ModestWindow *window)
3047 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
3048 modest_msg_view_window_remove_attachments (MODEST_MSG_VIEW_WINDOW (window), NULL);
3050 /* not supported window for this action */
3051 g_return_if_reached ();
3056 modest_ui_actions_on_settings (GtkAction *action,
3061 dialog = modest_platform_get_global_settings_dialog ();
3062 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (win));
3063 gtk_widget_show (dialog);
3065 gtk_dialog_run (GTK_DIALOG (dialog));
3067 gtk_widget_destroy (dialog);
3071 modest_ui_actions_on_help (GtkAction *action,
3074 const gchar *help_id = NULL;
3076 if (MODEST_IS_MAIN_WINDOW (win)) {
3077 const gchar *action_name;
3078 action_name = gtk_action_get_name (action);
3080 if (!strcmp (action_name, "FolderViewCSMHelp") ||
3081 !strcmp (action_name, "HeaderViewCSMHelp")) {
3082 GtkWidget *folder_view;
3083 TnyFolderStore *folder_store;
3084 /* Get selected folder */
3085 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
3086 MODEST_WIDGET_TYPE_FOLDER_VIEW);
3087 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
3089 /* Switch help_id */
3090 if (TNY_IS_FOLDER (folder_store)) {
3091 switch (tny_folder_get_folder_type (TNY_FOLDER (folder_store))) {
3092 case TNY_FOLDER_TYPE_NORMAL:
3093 help_id = "applications_email_userfolder";
3095 case TNY_FOLDER_TYPE_INBOX:
3096 help_id = "applications_email_inbox";
3098 case TNY_FOLDER_TYPE_OUTBOX:
3099 help_id = "applications_email_outbox";
3101 case TNY_FOLDER_TYPE_SENT:
3102 help_id = "applications_email_sent";
3104 case TNY_FOLDER_TYPE_DRAFTS:
3105 help_id = "applications_email_drafts";
3107 case TNY_FOLDER_TYPE_ARCHIVE:
3108 help_id = "applications_email_archive";
3114 g_object_unref (folder_store);
3116 help_id = "applications_email_mainview";
3118 } else if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
3119 help_id = "applications_email_viewer";
3120 } else if (MODEST_IS_MSG_EDIT_WINDOW (win))
3121 help_id = "applications_email_editor";
3123 modest_platform_show_help (GTK_WINDOW (win), help_id);
3127 modest_ui_actions_on_retrieve_msg_contents (GtkAction *action,
3128 ModestWindow *window)
3130 ModestMailOperation *mail_op;
3134 headers = get_selected_headers (window);
3138 /* Create mail operation */
3139 mail_op = modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE,
3141 modest_ui_actions_get_msgs_full_error_handler,
3143 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
3144 modest_mail_operation_get_msgs_full (mail_op, headers, NULL, NULL, NULL);
3147 g_object_unref (headers);
3148 g_object_unref (mail_op);
3152 modest_ui_actions_on_email_menu_activated (GtkAction *action,
3153 ModestWindow *window)
3155 g_return_if_fail (MODEST_IS_WINDOW (window));
3158 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
3162 modest_ui_actions_on_edit_menu_activated (GtkAction *action,
3163 ModestWindow *window)
3165 g_return_if_fail (MODEST_IS_WINDOW (window));
3168 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
3172 modest_ui_actions_on_view_menu_activated (GtkAction *action,
3173 ModestWindow *window)
3175 g_return_if_fail (MODEST_IS_WINDOW (window));
3178 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
3182 modest_ui_actions_on_tools_menu_activated (GtkAction *action,
3183 ModestWindow *window)
3185 g_return_if_fail (MODEST_IS_WINDOW (window));
3188 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
3192 modest_ui_actions_on_attachment_menu_activated (GtkAction *action,
3193 ModestWindow *window)
3195 g_return_if_fail (MODEST_IS_WINDOW (window));
3198 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
3202 modest_ui_actions_on_toolbar_csm_menu_activated (GtkAction *action,
3203 ModestWindow *window)
3205 g_return_if_fail (MODEST_IS_WINDOW (window));
3208 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
3212 modest_ui_actions_on_folder_view_csm_menu_activated (GtkAction *action,
3213 ModestWindow *window)
3215 g_return_if_fail (MODEST_IS_WINDOW (window));
3218 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
3222 modest_ui_actions_on_header_view_csm_menu_activated (GtkAction *action,
3223 ModestWindow *window)
3225 g_return_if_fail (MODEST_IS_WINDOW (window));
3228 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
3232 modest_ui_actions_check_toolbar_dimming_rules (ModestWindow *window)
3234 g_return_if_fail (MODEST_IS_WINDOW (window));
3237 modest_window_check_dimming_rules_group (window, "ModestToolbarDimmingRules");
3241 modest_ui_actions_on_search_messages (GtkAction *action, ModestWindow *window)
3243 g_return_if_fail (MODEST_IS_WINDOW (window));
3245 modest_platform_show_search_messages (GTK_WINDOW (window));
3249 modest_ui_actions_on_open_addressbook (GtkAction *action, ModestWindow *win)
3251 g_return_if_fail (MODEST_IS_WINDOW (win));
3252 modest_platform_show_addressbook (GTK_WINDOW (win));
3257 modest_ui_actions_on_toggle_find_in_page (GtkToggleAction *action,
3258 ModestWindow *window)
3260 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3262 modest_msg_edit_window_toggle_find_toolbar (MODEST_MSG_EDIT_WINDOW (window), gtk_toggle_action_get_active (action));
3266 _on_send_receive_progress_changed (ModestMailOperation *mail_op,
3267 ModestMailOperationState *state,
3270 g_return_if_fail (MODEST_IS_MAIN_WINDOW(user_data));
3272 /* Set send/receive operation finished */
3273 if (state->status != MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS)
3274 modest_main_window_notify_send_receive_completed (MODEST_MAIN_WINDOW(user_data));