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);
125 static gchar* ask_for_folder_name (GtkWindow *parent_window, const gchar *title);
128 static void _on_send_receive_progress_changed (ModestMailOperation *mail_op,
129 ModestMailOperationState *state,
135 run_account_setup_wizard (ModestWindow *win)
137 ModestEasysetupWizardDialog *wizard;
139 g_return_if_fail (MODEST_IS_WINDOW(win));
141 wizard = modest_easysetup_wizard_dialog_new ();
142 gtk_window_set_transient_for (GTK_WINDOW (wizard), GTK_WINDOW (win));
143 gtk_dialog_run (GTK_DIALOG (wizard));
144 gtk_widget_destroy (GTK_WIDGET (wizard));
149 modest_ui_actions_on_about (GtkAction *action, ModestWindow *win)
152 const gchar *authors[] = {
153 "Dirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>",
156 about = gtk_about_dialog_new ();
157 gtk_about_dialog_set_name (GTK_ABOUT_DIALOG(about), PACKAGE_NAME);
158 gtk_about_dialog_set_version (GTK_ABOUT_DIALOG(about),PACKAGE_VERSION);
159 gtk_about_dialog_set_copyright (GTK_ABOUT_DIALOG(about),
160 _("Copyright (c) 2006, Nokia Corporation\n"
161 "All rights reserved."));
162 gtk_about_dialog_set_comments (GTK_ABOUT_DIALOG(about),
163 _("a modest e-mail client\n\n"
164 "design and implementation: Dirk-Jan C. Binnema\n"
165 "contributions from the fine people at KC and Ig\n"
166 "uses the tinymail email framework written by Philip van Hoof"));
167 gtk_about_dialog_set_authors (GTK_ABOUT_DIALOG(about), authors);
168 gtk_about_dialog_set_website (GTK_ABOUT_DIALOG(about), "http://modest.garage.maemo.org");
170 gtk_dialog_run (GTK_DIALOG (about));
171 gtk_widget_destroy(about);
175 * Gets the list of currently selected messages. If the win is the
176 * main window, then it returns a newly allocated list of the headers
177 * selected in the header view. If win is the msg view window, then
178 * the value returned is a list with just a single header.
180 * The caller of this funcion must free the list.
183 get_selected_headers (ModestWindow *win)
185 if (MODEST_IS_MAIN_WINDOW(win)) {
186 GtkWidget *header_view;
188 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
189 MODEST_WIDGET_TYPE_HEADER_VIEW);
190 return modest_header_view_get_selected_headers (MODEST_HEADER_VIEW(header_view));
192 } else if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
193 /* for MsgViewWindows, we simply return a list with one element */
195 TnyList *list = NULL;
197 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
198 if (header != NULL) {
199 list = tny_simple_list_new ();
200 tny_list_prepend (list, G_OBJECT(header));
201 g_object_unref (G_OBJECT(header));
211 headers_action_mark_as_read (TnyHeader *header,
215 TnyHeaderFlags flags;
217 g_return_if_fail (TNY_IS_HEADER(header));
219 flags = tny_header_get_flags (header);
220 if (flags & TNY_HEADER_FLAG_SEEN) return;
221 tny_header_set_flags (header, TNY_HEADER_FLAG_SEEN);
225 headers_action_mark_as_unread (TnyHeader *header,
229 TnyHeaderFlags flags;
231 g_return_if_fail (TNY_IS_HEADER(header));
233 flags = tny_header_get_flags (header);
234 if (flags & TNY_HEADER_FLAG_SEEN) {
235 tny_header_unset_flags (header, TNY_HEADER_FLAG_SEEN);
241 headers_action_delete (TnyHeader *header,
245 ModestMailOperation *mail_op = NULL;
247 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_DELETE, G_OBJECT(win));
248 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
251 /* Always delete. TODO: Move to trash still not supported */
252 modest_mail_operation_remove_msg (mail_op, header, FALSE);
253 g_object_unref (G_OBJECT (mail_op));
257 modest_ui_actions_on_delete (GtkAction *action, ModestWindow *win)
259 TnyList *header_list = NULL;
260 TnyIterator *iter = NULL;
261 TnyHeader *header = NULL;
262 gchar *message = NULL;
266 ModestWindowMgr *mgr;
268 g_return_if_fail (MODEST_IS_WINDOW(win));
270 header_list = get_selected_headers (win);
271 if (!header_list) return;
273 /* Check if any of the headers is already opened */
274 iter = tny_list_create_iterator (header_list);
276 mgr = modest_runtime_get_window_mgr ();
277 while (!tny_iterator_is_done (iter) && !found) {
278 header = TNY_HEADER (tny_iterator_get_current (iter));
279 if (modest_window_mgr_find_window_by_header (mgr, header))
281 g_object_unref (header);
282 tny_iterator_next (iter);
284 g_object_unref (iter);
289 num = g_strdup_printf ("%d", tny_list_get_length (header_list));
290 msg = g_strdup_printf (_("mcen_nc_unable_to_delete_n_messages"), num);
292 modest_platform_run_information_dialog (GTK_WINDOW (win), (const gchar *) msg);
296 g_object_unref (header_list);
301 if (tny_list_get_length(header_list) > 1)
302 message = g_strdup(_("emev_nc_delete_messages"));
304 iter = tny_list_create_iterator (header_list);
305 header = TNY_HEADER (tny_iterator_get_current (iter));
306 desc = g_strdup_printf ("%s", tny_header_get_subject (header));
307 message = g_strdup_printf(_("emev_nc_delete_message"), desc);
308 g_object_unref (header);
309 g_object_unref (iter);
312 /* Confirmation dialog */
313 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
317 if (response == GTK_RESPONSE_OK) {
318 if (MODEST_IS_MSG_EDIT_WINDOW (win)) {
320 g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value);
324 /* Remove each header */
325 do_headers_action (win, headers_action_delete, NULL);
327 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
328 gtk_widget_destroy (GTK_WIDGET(win));
335 g_object_unref (header_list);
340 modest_ui_actions_on_quit (GtkAction *action, ModestWindow *win)
342 #ifdef MODEST_PLATFORM_MAEMO
343 modest_osso_save_state();
344 #endif /* MODEST_PLATFORM_MAEMO */
350 modest_ui_actions_on_close_window (GtkAction *action, ModestWindow *win)
352 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
353 gtk_widget_destroy (GTK_WIDGET (win));
354 } else if (MODEST_IS_MSG_EDIT_WINDOW (win)) {
356 g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value);
357 } else if (MODEST_IS_WINDOW (win)) {
358 gtk_widget_destroy (GTK_WIDGET (win));
360 g_return_if_reached ();
365 modest_ui_actions_on_add_to_contacts (GtkAction *action, ModestWindow *win)
367 GtkClipboard *clipboard = NULL;
368 gchar *selection = NULL;
370 clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
371 selection = gtk_clipboard_wait_for_text (clipboard);
373 /* Question: why is the clipboard being used here?
374 * It doesn't really make a lot of sense. */
378 modest_address_book_add_address (selection);
384 modest_ui_actions_on_accounts (GtkAction *action, ModestWindow *win)
386 /* This is currently only implemented for Maemo */
387 #ifdef MODEST_PLATFORM_MAEMO /* Defined in config.h */
388 if (!modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE)) {
389 run_account_setup_wizard (win);
392 /* Show the list of accounts: */
393 GtkDialog *account_win = GTK_DIALOG(modest_account_view_window_new ());
394 gtk_window_set_transient_for (GTK_WINDOW (account_win), GTK_WINDOW(win));
395 gtk_dialog_run (account_win);
396 gtk_widget_destroy (GTK_WIDGET(account_win));
399 GtkWidget *dialog, *label;
401 /* Create the widgets */
403 dialog = gtk_dialog_new_with_buttons ("Message",
405 GTK_DIALOG_DESTROY_WITH_PARENT,
409 label = gtk_label_new ("Hello World!");
411 /* Ensure that the dialog box is destroyed when the user responds. */
413 g_signal_connect_swapped (dialog, "response",
414 G_CALLBACK (gtk_widget_destroy),
417 /* Add the label, and show everything we've added to the dialog. */
419 gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox),
421 gtk_widget_show_all (dialog);
422 #endif /* MODEST_PLATFORM_MAEMO */
426 on_smtp_servers_window_hide (GtkWindow* window, gpointer user_data)
428 ModestWindow *main_window = MODEST_WINDOW (user_data);
430 /* Save any changes. */
431 modest_connection_specific_smtp_window_save_server_accounts (
432 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (window),
433 modest_window_get_active_account (main_window));
434 gtk_widget_destroy (GTK_WIDGET (window));
440 modest_ui_actions_on_smtp_servers (GtkAction *action, ModestWindow *win)
442 /* This is currently only implemented for Maemo,
443 * because it requires an API (libconic) to detect different connection
446 #ifdef MODEST_PLATFORM_MAEMO /* Defined in config.h */
448 /* Create the window if necessary: */
449 const gchar *active_account_name = modest_window_get_active_account (win);
451 /* TODO: Dim the menu item (not in the UI spec)? or show a warning,
452 * or show the default account?
453 * If we show the default account then the account name should be shown in
454 * the window when we show it. */
455 if (!active_account_name) {
456 g_warning ("%s: No account is active.", __FUNCTION__);
460 GtkWidget *specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
461 modest_connection_specific_smtp_window_fill_with_connections (
462 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (specific_window),
463 modest_runtime_get_account_mgr(),
464 active_account_name);
466 /* Show the window: */
467 gtk_window_set_transient_for (GTK_WINDOW (specific_window), GTK_WINDOW (win));
468 gtk_window_set_modal (GTK_WINDOW (specific_window), TRUE);
469 gtk_widget_show (specific_window);
471 /* Save changes when the window is hidden: */
472 g_signal_connect (specific_window, "hide",
473 G_CALLBACK (on_smtp_servers_window_hide), win);
474 #endif /* MODEST_PLATFORM_MAEMO */
478 modest_ui_actions_on_new_msg (GtkAction *action, ModestWindow *win)
480 ModestWindow *msg_win;
482 TnyFolder *folder = NULL;
483 gchar *account_name = NULL;
484 gchar *from_str = NULL;
485 /* GError *err = NULL; */
486 TnyAccount *account = NULL;
487 ModestWindowMgr *mgr;
488 gchar *signature = NULL, *blank_and_signature = NULL;
490 /* if there are no accounts yet, just show the wizard */
491 if (!modest_account_mgr_has_accounts (modest_runtime_get_account_mgr(), TRUE)) {
492 run_account_setup_wizard (win);
496 account_name = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr ());
498 account_name = g_strdup (modest_window_get_active_account (win));
500 g_printerr ("modest: no account found\n");
504 account = modest_tny_account_store_get_server_account (modest_runtime_get_account_store(),
506 TNY_ACCOUNT_TYPE_STORE);
508 g_printerr ("modest: failed to get tnyaccount for '%s'\n", account_name);
512 from_str = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(), account_name);
514 g_printerr ("modest: failed get from string for '%s'\n", account_name);
518 if (modest_account_mgr_get_bool (modest_runtime_get_account_mgr (), account_name,
519 MODEST_ACCOUNT_USE_SIGNATURE, FALSE)) {
520 signature = modest_account_mgr_get_string (modest_runtime_get_account_mgr (), account_name,
521 MODEST_ACCOUNT_SIGNATURE, FALSE);
522 blank_and_signature = g_strconcat ("\n", signature, NULL);
525 blank_and_signature = g_strdup ("");
528 msg = modest_tny_msg_new ("", from_str, "", "", "", blank_and_signature, NULL);
530 g_printerr ("modest: failed to create new msg\n");
534 folder = modest_tny_account_get_special_folder (account, TNY_FOLDER_TYPE_DRAFTS);
536 g_printerr ("modest: failed to find Drafts folder\n");
541 /* Create and register edit window */
542 /* This is destroyed by TOOD. */
543 msg_win = modest_msg_edit_window_new (msg, account_name);
544 mgr = modest_runtime_get_window_mgr ();
545 modest_window_mgr_register_window (mgr, msg_win);
548 gtk_window_set_transient_for (GTK_WINDOW (msg_win),
550 gtk_widget_show_all (GTK_WIDGET (msg_win));
553 g_free (account_name);
555 g_free (blank_and_signature);
557 g_object_unref (G_OBJECT(account));
559 g_object_unref (G_OBJECT(msg));
561 g_object_unref (G_OBJECT(folder));
565 open_msg_cb (ModestMailOperation *mail_op,
570 ModestWindowMgr *mgr = NULL;
571 ModestWindow *parent_win = NULL;
572 ModestWindow *win = NULL;
573 TnyFolderType folder_type = TNY_FOLDER_TYPE_UNKNOWN;
574 gchar *account = NULL;
577 /* TODO: Show an error? (review the specs) */
581 parent_win = (ModestWindow *) modest_mail_operation_get_source (mail_op);
582 folder = tny_header_get_folder (header);
584 /* Mark header as read */
585 headers_action_mark_as_read (header, MODEST_WINDOW(parent_win), NULL);
588 account = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
590 account = g_strdup (modest_window_get_active_account (MODEST_WINDOW (parent_win)));
592 /* Gets folder type (OUTBOX headers will be opened in edit window */
593 if (modest_tny_folder_is_local_folder (folder))
594 folder_type = modest_tny_folder_get_local_folder_type (folder);
596 /* If the header is in the drafts folder then open the editor,
597 else the message view window */
598 if (folder_type == TNY_FOLDER_TYPE_DRAFTS) {
599 /* we cannot edit without a valid account... */
600 if (!modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE)) {
601 run_account_setup_wizard(parent_win);
604 win = modest_msg_edit_window_new (msg, account);
606 gchar *uid = modest_tny_folder_get_header_unique_id (header);
608 if (MODEST_IS_MAIN_WINDOW (parent_win)) {
609 GtkWidget *header_view;
610 GtkTreeSelection *sel;
611 GList *sel_list = NULL;
614 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(parent_win),
615 MODEST_WIDGET_TYPE_HEADER_VIEW);
617 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
618 sel_list = gtk_tree_selection_get_selected_rows (sel, &model);
620 if (sel_list != NULL) {
621 GtkTreeRowReference *row_reference;
623 row_reference = gtk_tree_row_reference_new (model, (GtkTreePath *) sel_list->data);
624 g_list_foreach (sel_list, (GFunc) gtk_tree_path_free, NULL);
625 g_list_free (sel_list);
627 win = modest_msg_view_window_new_with_header_model (msg,
632 gtk_tree_row_reference_free (row_reference);
634 win = modest_msg_view_window_new (msg, account, (const gchar*) uid);
637 win = modest_msg_view_window_new (msg, account, (const gchar*) uid);
642 /* Register and show new window */
644 mgr = modest_runtime_get_window_mgr ();
645 modest_window_mgr_register_window (mgr, win);
646 gtk_window_set_transient_for (GTK_WINDOW (win), GTK_WINDOW (parent_win));
647 gtk_widget_show_all (GTK_WIDGET(win));
653 g_object_unref (msg);
654 g_object_unref (folder);
655 g_object_unref (header);
659 * This function is the error handler of the
660 * modest_mail_operation_get_msgs_full operation
663 modest_ui_actions_get_msgs_full_error_handler (ModestMailOperation *mail_op,
668 error = modest_mail_operation_get_error (mail_op);
669 if (error->code == MODEST_MAIL_OPERATION_ERROR_MESSAGE_SIZE_LIMIT) {
670 GObject *win = modest_mail_operation_get_source (mail_op);
672 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
678 * This function is used by both modest_ui_actions_on_open and
679 * modest_ui_actions_on_header_activated. This way we always do the
680 * same when trying to open messages.
683 _modest_ui_actions_open (TnyList *headers, ModestWindow *win)
685 ModestWindowMgr *mgr;
687 ModestMailOperation *mail_op;
688 TnyList *not_opened_headers;
690 /* Look if we already have a message view for each header. If
691 true, then remove the header from the list of headers to
693 mgr = modest_runtime_get_window_mgr ();
694 iter = tny_list_create_iterator (headers);
695 not_opened_headers = tny_simple_list_new ();
696 while (!tny_iterator_is_done (iter)) {
697 ModestWindow *window;
700 header = TNY_HEADER (tny_iterator_get_current (iter));
701 window = modest_window_mgr_find_window_by_header (mgr, header);
702 /* Do not open again the message and present the
703 window to the user */
705 gtk_window_present (GTK_WINDOW (window));
707 tny_list_append (not_opened_headers, G_OBJECT (header));
709 g_object_unref (header);
710 tny_iterator_next (iter);
713 /* Open each message */
714 mail_op = modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE,
716 modest_ui_actions_get_msgs_full_error_handler,
718 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
719 modest_mail_operation_get_msgs_full (mail_op,
725 g_object_unref (not_opened_headers);
726 g_object_unref (iter);
727 g_object_unref (mail_op);
731 modest_ui_actions_on_open (GtkAction *action, ModestWindow *win)
736 headers = get_selected_headers (win);
741 _modest_ui_actions_open (headers, win);
743 g_object_unref(headers);
748 free_reply_forward_helper (gpointer data)
750 ReplyForwardHelper *helper;
752 helper = (ReplyForwardHelper *) data;
753 g_free (helper->account_name);
754 g_slice_free (ReplyForwardHelper, helper);
758 reply_forward_cb (ModestMailOperation *mail_op,
764 ReplyForwardHelper *rf_helper;
765 ModestWindow *msg_win;
766 ModestEditType edit_type;
768 TnyAccount *account = NULL;
769 ModestWindowMgr *mgr;
770 gchar *signature = NULL;
772 g_return_if_fail (user_data != NULL);
773 rf_helper = (ReplyForwardHelper *) user_data;
775 from = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(),
776 rf_helper->account_name);
777 if (modest_account_mgr_get_bool (modest_runtime_get_account_mgr(),
778 rf_helper->account_name,
779 MODEST_ACCOUNT_USE_SIGNATURE, FALSE)) {
780 signature = modest_account_mgr_get_string (modest_runtime_get_account_mgr (),
781 rf_helper->account_name,
782 MODEST_ACCOUNT_SIGNATURE, FALSE);
785 /* Create reply mail */
786 switch (rf_helper->action) {
789 modest_tny_msg_create_reply_msg (msg, from, signature,
790 rf_helper->reply_forward_type,
791 MODEST_TNY_MSG_REPLY_MODE_SENDER);
793 case ACTION_REPLY_TO_ALL:
795 modest_tny_msg_create_reply_msg (msg, from, signature, rf_helper->reply_forward_type,
796 MODEST_TNY_MSG_REPLY_MODE_ALL);
797 edit_type = MODEST_EDIT_TYPE_REPLY;
801 modest_tny_msg_create_forward_msg (msg, from, signature, rf_helper->reply_forward_type);
802 edit_type = MODEST_EDIT_TYPE_FORWARD;
805 g_return_if_reached ();
812 g_printerr ("modest: failed to create message\n");
816 account = modest_tny_account_store_get_server_account (modest_runtime_get_account_store(),
817 rf_helper->account_name,
818 TNY_ACCOUNT_TYPE_STORE);
820 g_printerr ("modest: failed to get tnyaccount for '%s'\n", rf_helper->account_name);
824 /* Create and register the windows */
825 msg_win = modest_msg_edit_window_new (new_msg, rf_helper->account_name);
826 mgr = modest_runtime_get_window_mgr ();
827 modest_window_mgr_register_window (mgr, msg_win);
829 if (rf_helper->parent_window != NULL) {
832 parent_zoom = modest_window_get_zoom (MODEST_WINDOW (rf_helper->parent_window));
833 modest_window_set_zoom (msg_win, parent_zoom);
836 /* Show edit window */
837 gtk_widget_show_all (GTK_WIDGET (msg_win));
841 g_object_unref (G_OBJECT (new_msg));
843 g_object_unref (G_OBJECT (account));
844 g_object_unref (msg);
845 g_object_unref (header);
849 * Checks a list of headers. If any of them are not currently
850 * downloaded (CACHED) then it asks the user for permission to
853 * Returns FALSE if the user does not want to download the
854 * messages. Returns TRUE if the user allowed the download or if all
855 * of them are currently downloaded
858 download_uncached_messages (TnyList *header_list, GtkWindow *win)
861 gboolean found, retval;
863 iter = tny_list_create_iterator (header_list);
865 while (!tny_iterator_is_done (iter) && !found) {
867 TnyHeaderFlags flags;
869 header = TNY_HEADER (tny_iterator_get_current (iter));
870 flags = tny_header_get_flags (header);
871 /* TODO: is this the right flag?, it seems that some
872 headers that have been previously downloaded do not
874 found = !(flags & TNY_HEADER_FLAG_CACHED);
875 g_object_unref (header);
876 tny_iterator_next (iter);
878 g_object_unref (iter);
880 /* Ask for user permission to download the messages */
883 GtkResponseType response;
885 modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
886 _("mcen_nc_get_multi_msg_txt"));
887 if (response == GTK_RESPONSE_CANCEL)
895 * Common code for the reply and forward actions
898 reply_forward (ReplyForwardAction action, ModestWindow *win)
900 ModestMailOperation *mail_op = NULL;
901 TnyList *header_list = NULL;
902 ReplyForwardHelper *rf_helper = NULL;
903 guint reply_forward_type;
904 gboolean continue_download;
906 g_return_if_fail (MODEST_IS_WINDOW(win));
908 /* we need an account when editing */
909 if (!modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE)) {
910 run_account_setup_wizard (win);
914 header_list = get_selected_headers (win);
918 /* Check that the messages have been previously downloaded */
919 continue_download = download_uncached_messages (header_list, GTK_WINDOW (win));
920 if (!continue_download) {
921 g_object_unref (header_list);
926 modest_conf_get_int (modest_runtime_get_conf (),
927 (action == ACTION_FORWARD) ? MODEST_CONF_FORWARD_TYPE : MODEST_CONF_REPLY_TYPE,
929 /* We assume that we can only select messages of the
930 same folder and that we reply all of them from the
931 same account. In fact the interface currently only
932 allows single selection */
935 rf_helper = g_slice_new0 (ReplyForwardHelper);
936 rf_helper->reply_forward_type = reply_forward_type;
937 rf_helper->action = action;
938 rf_helper->account_name = g_strdup (modest_window_get_active_account (win));
939 if ((win != NULL) && (MODEST_IS_WINDOW (win)))
940 rf_helper->parent_window = GTK_WIDGET (win);
941 if (!rf_helper->account_name)
942 rf_helper->account_name =
943 modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
945 if (MODEST_IS_MSG_VIEW_WINDOW(win)) {
948 /* Get header and message. Do not free them here, the
949 reply_forward_cb must do it */
950 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW(win));
951 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW(win));
952 if (!msg || !header) {
954 g_object_unref (msg);
956 g_object_unref (header);
957 g_printerr ("modest: no message found\n");
960 reply_forward_cb (NULL, header, msg, rf_helper);
962 /* Retrieve messages */
963 mail_op = modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE,
965 modest_ui_actions_get_msgs_full_error_handler,
967 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
968 modest_mail_operation_get_msgs_full (mail_op,
972 free_reply_forward_helper);
975 g_object_unref(mail_op);
979 g_object_unref (header_list);
983 modest_ui_actions_on_reply (GtkAction *action, ModestWindow *win)
985 g_return_if_fail (MODEST_IS_WINDOW(win));
987 reply_forward (ACTION_REPLY, win);
991 modest_ui_actions_on_forward (GtkAction *action, ModestWindow *win)
993 g_return_if_fail (MODEST_IS_WINDOW(win));
995 reply_forward (ACTION_FORWARD, win);
999 modest_ui_actions_on_reply_all (GtkAction *action, ModestWindow *win)
1001 g_return_if_fail (MODEST_IS_WINDOW(win));
1003 reply_forward (ACTION_REPLY_TO_ALL, win);
1007 modest_ui_actions_on_next (GtkAction *action,
1008 ModestWindow *window)
1010 if (MODEST_IS_MAIN_WINDOW (window)) {
1011 GtkWidget *header_view;
1013 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
1014 MODEST_WIDGET_TYPE_HEADER_VIEW);
1018 modest_header_view_select_next (MODEST_HEADER_VIEW(header_view));
1019 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
1020 modest_msg_view_window_select_next_message (MODEST_MSG_VIEW_WINDOW (window));
1022 g_return_if_reached ();
1027 modest_ui_actions_on_prev (GtkAction *action,
1028 ModestWindow *window)
1030 g_return_if_fail (MODEST_IS_WINDOW(window));
1032 if (MODEST_IS_MAIN_WINDOW (window)) {
1033 GtkWidget *header_view;
1034 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
1035 MODEST_WIDGET_TYPE_HEADER_VIEW);
1039 modest_header_view_select_prev (MODEST_HEADER_VIEW(header_view));
1040 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
1041 modest_msg_view_window_select_previous_message (MODEST_MSG_VIEW_WINDOW (window));
1043 g_return_if_reached ();
1048 modest_ui_actions_on_sort (GtkAction *action,
1049 ModestWindow *window)
1051 g_return_if_fail (MODEST_IS_WINDOW(window));
1053 if (MODEST_IS_MAIN_WINDOW (window)) {
1054 GtkWidget *header_view;
1055 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
1056 MODEST_WIDGET_TYPE_HEADER_VIEW);
1060 /* Show sorting dialog */
1061 modest_platform_run_sort_dialog (GTK_WINDOW (window), MODEST_SORT_HEADERS);
1066 * This function performs the send & receive required actions. The
1067 * window is used to create the mail operation. Typically it should
1068 * always be the main window, but we pass it as argument in order to
1072 modest_ui_actions_do_send_receive (const gchar *account_name, ModestWindow *win)
1074 gchar *acc_name = NULL;
1075 ModestMailOperation *mail_op;
1077 /* If no account name was provided then get the current account, and if
1078 there is no current account then pick the default one: */
1079 if (!account_name) {
1080 acc_name = g_strdup (modest_window_get_active_account(win));
1082 acc_name = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
1084 g_printerr ("modest: cannot get default account\n");
1088 acc_name = g_strdup (account_name);
1091 /* Set send/receive operation in progress */
1092 modest_main_window_notify_send_receive_initied (MODEST_MAIN_WINDOW(win));
1094 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_RECEIVE, G_OBJECT(win));
1095 g_signal_connect (G_OBJECT(mail_op), "progress-changed",
1096 G_CALLBACK (_on_send_receive_progress_changed),
1099 /* Send & receive. */
1100 /* TODO: The spec wants us to first do any pending deletions, before receiving. */
1101 /* Receive and then send. The operation is tagged initially as
1102 a receive operation because the account update performs a
1103 receive and then a send. The operation changes its type
1104 internally, so the progress objects will receive the proper
1105 progress information */
1106 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
1107 modest_mail_operation_update_account (mail_op, acc_name);
1108 g_object_unref (G_OBJECT (mail_op));
1115 * Refreshes all accounts. This function will be used by automatic
1119 modest_ui_actions_do_send_receive_all (ModestWindow *win)
1121 GSList *account_names, *iter;
1123 account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
1126 iter = account_names;
1128 modest_ui_actions_do_send_receive ((const char*) iter->data, win);
1129 iter = g_slist_next (iter);
1132 g_slist_foreach (account_names, (GFunc) g_free, NULL);
1133 g_slist_free (account_names);
1137 * Handler of the click on Send&Receive button in the main toolbar
1140 modest_ui_actions_on_send_receive (GtkAction *action, ModestWindow *win)
1142 /* Check if accounts exist */
1143 gboolean accounts_exist =
1144 modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
1146 /* If not, allow the user to create an account before trying to send/receive. */
1147 if (!accounts_exist)
1148 modest_ui_actions_on_accounts (NULL, win);
1150 /* Refresh the active account */
1151 modest_ui_actions_do_send_receive (NULL, win);
1156 modest_ui_actions_toggle_header_list_view (GtkAction *action, ModestMainWindow *main_window)
1159 GtkWidget *header_view;
1161 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1163 header_view = modest_main_window_get_child_widget (main_window,
1164 MODEST_WIDGET_TYPE_HEADER_VIEW);
1168 conf = modest_runtime_get_conf ();
1170 /* what is saved/restored is depending on the style; thus; we save with
1171 * old style, then update the style, and restore for this new style
1173 modest_widget_memory_save (conf, G_OBJECT(header_view), MODEST_CONF_HEADER_VIEW_KEY);
1175 if (modest_header_view_get_style
1176 (MODEST_HEADER_VIEW(header_view)) == MODEST_HEADER_VIEW_STYLE_DETAILS)
1177 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
1178 MODEST_HEADER_VIEW_STYLE_TWOLINES);
1180 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
1181 MODEST_HEADER_VIEW_STYLE_DETAILS);
1183 modest_widget_memory_restore (conf, G_OBJECT(header_view),
1184 MODEST_CONF_HEADER_VIEW_KEY);
1189 modest_ui_actions_on_header_selected (ModestHeaderView *header_view,
1191 ModestMainWindow *main_window)
1193 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1194 g_return_if_fail (MODEST_IS_HEADER_VIEW (header_view));
1196 /* If no header has been selected then exit */
1200 /* Update Main window title */
1201 if (GTK_WIDGET_HAS_FOCUS (header_view)) {
1202 const gchar *subject = tny_header_get_subject (header);
1203 if (subject && strlen(subject) > 0)
1204 gtk_window_set_title (GTK_WINDOW (main_window), subject);
1206 gtk_window_set_title (GTK_WINDOW (main_window), _("mail_va_no_subject"));
1209 /* Update toolbar dimming state */
1210 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
1214 modest_ui_actions_on_header_activated (ModestHeaderView *header_view,
1216 ModestMainWindow *main_window)
1220 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1225 headers = tny_simple_list_new ();
1226 tny_list_prepend (headers, G_OBJECT (header));
1228 _modest_ui_actions_open (headers, MODEST_WINDOW (main_window));
1230 g_object_unref (headers);
1234 set_active_account_from_tny_account (TnyAccount *account,
1235 ModestWindow *window)
1237 const gchar *server_acc_name = tny_account_get_id (account);
1239 /* We need the TnyAccount provided by the
1240 account store because that is the one that
1241 knows the name of the Modest account */
1242 TnyAccount *modest_server_account = modest_server_account =
1243 modest_tny_account_store_get_tny_account_by (modest_runtime_get_account_store (),
1244 MODEST_TNY_ACCOUNT_STORE_QUERY_ID,
1247 const gchar *modest_acc_name =
1248 modest_tny_account_get_parent_modest_account_name_for_server_account (modest_server_account);
1249 modest_window_set_active_account (window, modest_acc_name);
1250 g_object_unref (modest_server_account);
1255 folder_refreshed_cb (const GObject *obj,
1259 printf ("DEBUG: %s\n", __FUNCTION__);
1260 ModestMainWindow *win = NULL;
1261 GtkWidget *header_view;
1263 g_return_if_fail (TNY_IS_FOLDER (folder));
1265 win = MODEST_MAIN_WINDOW (user_data);
1267 modest_main_window_get_child_widget(win, MODEST_WIDGET_TYPE_HEADER_VIEW);
1269 /* Check if folder is empty and set headers view contents style */
1270 if (tny_folder_get_all_count (folder) == 0) {
1271 printf ("DEBUG: %s: tny_folder_get_all_count() returned 0.\n", __FUNCTION__);
1272 modest_main_window_set_contents_style (win,
1273 MODEST_MAIN_WINDOW_CONTENTS_STYLE_EMPTY);
1275 printf ("DEBUG: %s: tny_folder_get_all_count() returned >0.\n", __FUNCTION__);
1277 /* Set the header view, we could change it to
1278 the empty view after the refresh. We do not
1279 need to save the configuration because we
1280 have already done that when unselecting the
1282 modest_main_window_set_contents_style (win,
1283 MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS);
1285 /* Restore configuration. There is no need to set the
1286 contents style to headers because it was already
1287 being done in folder_selection_changed */
1288 modest_widget_memory_restore (modest_runtime_get_conf (),
1289 G_OBJECT(header_view),
1290 MODEST_CONF_HEADER_VIEW_KEY);
1295 modest_ui_actions_on_folder_selection_changed (ModestFolderView *folder_view,
1296 TnyFolderStore *folder_store,
1298 ModestMainWindow *main_window)
1301 GtkWidget *header_view;
1303 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1305 header_view = modest_main_window_get_child_widget(main_window,
1306 MODEST_WIDGET_TYPE_HEADER_VIEW);
1310 conf = modest_runtime_get_conf ();
1312 if (TNY_IS_ACCOUNT (folder_store)) {
1313 /* Update active account */
1314 set_active_account_from_tny_account (TNY_ACCOUNT (folder_store), MODEST_WINDOW (main_window));
1315 /* Show account details */
1316 modest_main_window_set_contents_style (main_window, MODEST_MAIN_WINDOW_CONTENTS_STYLE_DETAILS);
1318 if (TNY_IS_FOLDER (folder_store) && selected) {
1320 if (!TNY_IS_MERGE_FOLDER (folder_store)) { /* TnyMergeFolder can have no get_account() implementation. */
1321 /* Update the active account */
1322 TnyAccount *account = modest_tny_folder_get_account (TNY_FOLDER (folder_store));
1323 set_active_account_from_tny_account (account, MODEST_WINDOW (main_window));
1324 g_object_unref (account);
1327 /* Set folder on header view. This function
1328 will call tny_folder_refresh_async so we
1329 pass a callback that will be called when
1330 finished. We use that callback to set the
1331 empty view if there are no messages */
1332 modest_header_view_set_folder (MODEST_HEADER_VIEW(header_view),
1333 TNY_FOLDER (folder_store),
1334 folder_refreshed_cb,
1337 /* Update the active account */
1338 modest_window_set_active_account (MODEST_WINDOW (main_window), NULL);
1339 /* Do not show folder */
1340 modest_widget_memory_save (conf, G_OBJECT (header_view), MODEST_CONF_HEADER_VIEW_KEY);
1341 modest_header_view_clear (MODEST_HEADER_VIEW(header_view));
1345 /* Update toolbar dimming state */
1346 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
1350 modest_ui_actions_on_item_not_found (ModestHeaderView *header_view,ModestItemType type,
1357 item = (type == MODEST_ITEM_TYPE_FOLDER) ? "folder" : "message";
1359 if (g_main_depth > 0)
1360 gdk_threads_enter ();
1361 online = tny_device_is_online (modest_runtime_get_device());
1364 /* already online -- the item is simply not there... */
1365 dialog = gtk_message_dialog_new (GTK_WINDOW (win),
1367 GTK_MESSAGE_WARNING,
1369 _("The %s you selected cannot be found"),
1371 gtk_dialog_run (GTK_DIALOG(dialog));
1373 dialog = gtk_dialog_new_with_buttons (_("Connection requested"),
1377 GTK_RESPONSE_REJECT,
1379 GTK_RESPONSE_ACCEPT,
1381 txt = g_strdup_printf (_("This %s is not available in offline mode.\n"
1382 "Do you want to get online?"), item);
1383 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
1384 gtk_label_new (txt), FALSE, FALSE, 0);
1385 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
1388 gtk_window_set_default_size (GTK_WINDOW(dialog), 300, 300);
1389 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
1390 // modest_platform_connect_and_wait ();
1393 gtk_widget_destroy (dialog);
1394 if (g_main_depth > 0)
1395 gdk_threads_leave ();
1399 modest_ui_actions_on_msg_link_hover (ModestMsgView *msgview, const gchar* link,
1402 /* g_message ("%s %s", __FUNCTION__, link); */
1407 modest_ui_actions_on_msg_link_clicked (ModestMsgView *msgview, const gchar* link,
1410 modest_platform_activate_uri (link);
1414 modest_ui_actions_on_msg_link_contextual (ModestMsgView *msgview, const gchar* link,
1417 modest_platform_show_uri_popup (link);
1421 modest_ui_actions_on_msg_attachment_clicked (ModestMsgView *msgview, TnyMimePart *mime_part,
1424 modest_msg_view_window_view_attachment (MODEST_MSG_VIEW_WINDOW (win), mime_part);
1428 modest_ui_actions_on_msg_recpt_activated (ModestMsgView *msgview,
1429 const gchar *address,
1432 /* g_message ("%s %s", __FUNCTION__, address); */
1436 modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edit_window)
1438 TnyTransportAccount *transport_account;
1439 ModestMailOperation *mail_operation;
1441 gchar *account_name, *from;
1442 ModestAccountMgr *account_mgr;
1444 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window));
1446 data = modest_msg_edit_window_get_msg_data (edit_window);
1448 account_mgr = modest_runtime_get_account_mgr();
1449 account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
1451 account_name = modest_account_mgr_get_default_account (account_mgr);
1452 if (!account_name) {
1453 g_printerr ("modest: no account found\n");
1454 modest_msg_edit_window_free_msg_data (edit_window, data);
1458 if (!strcmp (account_name, MODEST_LOCAL_FOLDERS_ACCOUNT_ID)) {
1459 account_name = g_strdup (data->account_name);
1463 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
1464 (modest_runtime_get_account_store(),
1466 TNY_ACCOUNT_TYPE_TRANSPORT));
1467 if (!transport_account) {
1468 g_printerr ("modest: no transport account found for '%s'\n", account_name);
1469 g_free (account_name);
1470 modest_msg_edit_window_free_msg_data (edit_window, data);
1473 from = modest_account_mgr_get_from_string (account_mgr, account_name);
1475 /* Create the mail operation */
1476 mail_operation = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_INFO, G_OBJECT(edit_window));
1477 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
1479 modest_mail_operation_save_to_drafts (mail_operation,
1490 data->priority_flags);
1493 g_free (account_name);
1494 g_object_unref (G_OBJECT (transport_account));
1495 g_object_unref (G_OBJECT (mail_operation));
1497 modest_msg_edit_window_free_msg_data (edit_window, data);
1499 /* Save settings and close the window */
1500 gtk_widget_destroy (GTK_WIDGET (edit_window));
1503 /* For instance, when clicking the Send toolbar button when editing a message: */
1505 modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
1507 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window));
1509 if (!modest_msg_edit_window_check_names (edit_window))
1512 /* FIXME: Code added just for testing. The final version will
1513 use the send queue provided by tinymail and some
1515 ModestAccountMgr *account_mgr = modest_runtime_get_account_mgr();
1516 gchar *account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
1518 account_name = modest_account_mgr_get_default_account (account_mgr);
1520 if (!account_name) {
1521 g_printerr ("modest: no account found\n");
1525 MsgData *data = modest_msg_edit_window_get_msg_data (edit_window);
1527 if (!strcmp (account_name, MODEST_LOCAL_FOLDERS_ACCOUNT_ID)) {
1528 account_name = g_strdup (data->account_name);
1531 /* Get the currently-active transport account for this modest account: */
1532 TnyTransportAccount *transport_account =
1533 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_transport_account_for_open_connection
1534 (modest_runtime_get_account_store(),
1536 if (!transport_account) {
1537 g_printerr ("modest: no transport account found for '%s'\n", account_name);
1538 g_free (account_name);
1539 modest_msg_edit_window_free_msg_data (edit_window, data);
1543 gchar *from = modest_account_mgr_get_from_string (account_mgr, account_name);
1545 /* mail content checks and dialogs */
1546 if (data->subject == NULL || data->subject[0] == '\0') {
1547 GtkResponseType response;
1548 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (edit_window),
1549 _("mcen_nc_subject_is_empty_send"));
1550 if (response == GTK_RESPONSE_CANCEL) {
1551 g_free (account_name);
1556 if (data->plain_body == NULL || data->plain_body[0] == '\0') {
1557 GtkResponseType response;
1558 gchar *note_message;
1559 gchar *note_subject = data->subject;
1560 if (note_subject == NULL || note_subject[0] == '\0')
1561 note_subject = _("mail_va_no_subject");
1562 note_message = g_strdup_printf (_("emev_ni_ui_smtp_message_null"), note_subject);
1563 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (edit_window),
1565 g_free (note_message);
1566 if (response == GTK_RESPONSE_CANCEL) {
1567 g_free (account_name);
1572 /* Create the mail operation */
1573 ModestMailOperation *mail_operation = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_SEND, G_OBJECT(edit_window));
1574 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
1576 modest_mail_operation_send_new_mail (mail_operation,
1587 data->priority_flags);
1591 g_free (account_name);
1592 g_object_unref (G_OBJECT (transport_account));
1593 g_object_unref (G_OBJECT (mail_operation));
1595 modest_msg_edit_window_free_msg_data (edit_window, data);
1597 /* Save settings and close the window: */
1598 gtk_widget_destroy (GTK_WIDGET (edit_window));
1602 modest_ui_actions_on_toggle_bold (GtkToggleAction *action,
1603 ModestMsgEditWindow *window)
1605 ModestMsgEditFormatState *format_state = NULL;
1607 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1608 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
1610 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
1613 format_state = modest_msg_edit_window_get_format_state (window);
1614 g_return_if_fail (format_state != NULL);
1616 format_state->bold = gtk_toggle_action_get_active (action);
1617 modest_msg_edit_window_set_format_state (window, format_state);
1618 g_free (format_state);
1623 modest_ui_actions_on_toggle_italics (GtkToggleAction *action,
1624 ModestMsgEditWindow *window)
1626 ModestMsgEditFormatState *format_state = NULL;
1628 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1629 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
1631 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
1634 format_state = modest_msg_edit_window_get_format_state (window);
1635 g_return_if_fail (format_state != NULL);
1637 format_state->italics = gtk_toggle_action_get_active (action);
1638 modest_msg_edit_window_set_format_state (window, format_state);
1639 g_free (format_state);
1644 modest_ui_actions_on_toggle_bullets (GtkToggleAction *action,
1645 ModestMsgEditWindow *window)
1647 ModestMsgEditFormatState *format_state = NULL;
1649 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1650 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
1652 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
1655 format_state = modest_msg_edit_window_get_format_state (window);
1656 g_return_if_fail (format_state != NULL);
1658 format_state->bullet = gtk_toggle_action_get_active (action);
1659 modest_msg_edit_window_set_format_state (window, format_state);
1660 g_free (format_state);
1665 modest_ui_actions_on_change_justify (GtkRadioAction *action,
1666 GtkRadioAction *selected,
1667 ModestMsgEditWindow *window)
1669 ModestMsgEditFormatState *format_state = NULL;
1670 GtkJustification value;
1672 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1674 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
1677 value = gtk_radio_action_get_current_value (selected);
1679 format_state = modest_msg_edit_window_get_format_state (window);
1680 g_return_if_fail (format_state != NULL);
1682 format_state->justification = value;
1683 modest_msg_edit_window_set_format_state (window, format_state);
1684 g_free (format_state);
1688 modest_ui_actions_on_select_editor_color (GtkAction *action,
1689 ModestMsgEditWindow *window)
1691 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1692 g_return_if_fail (GTK_IS_ACTION (action));
1694 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
1697 modest_msg_edit_window_select_color (window);
1701 modest_ui_actions_on_select_editor_background_color (GtkAction *action,
1702 ModestMsgEditWindow *window)
1704 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1705 g_return_if_fail (GTK_IS_ACTION (action));
1707 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
1710 modest_msg_edit_window_select_background_color (window);
1714 modest_ui_actions_on_insert_image (GtkAction *action,
1715 ModestMsgEditWindow *window)
1717 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1718 g_return_if_fail (GTK_IS_ACTION (action));
1720 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
1723 modest_msg_edit_window_insert_image (window);
1727 modest_ui_actions_on_attach_file (GtkAction *action,
1728 ModestMsgEditWindow *window)
1730 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1731 g_return_if_fail (GTK_IS_ACTION (action));
1733 modest_msg_edit_window_attach_file (window);
1737 modest_ui_actions_on_remove_attachments (GtkAction *action,
1738 ModestMsgEditWindow *window)
1740 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1741 g_return_if_fail (GTK_IS_ACTION (action));
1743 modest_msg_edit_window_remove_attachments (window, NULL);
1747 * Shows a dialog with an entry that asks for some text. The returned
1748 * value must be freed by the caller. The dialog window title will be
1752 ask_for_folder_name (GtkWindow *parent_window,
1755 GtkWidget *dialog, *entry;
1756 gchar *folder_name = NULL;
1758 /* Ask for folder name */
1759 dialog = gtk_dialog_new_with_buttons (_("New Folder Name"),
1763 GTK_RESPONSE_REJECT,
1765 GTK_RESPONSE_ACCEPT,
1767 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
1768 gtk_label_new(title),
1771 entry = gtk_entry_new_with_max_length (40);
1772 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
1776 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
1778 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
1779 folder_name = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry)));
1781 gtk_widget_destroy (dialog);
1787 modest_ui_actions_on_new_folder (GtkAction *action, ModestMainWindow *main_window)
1789 TnyFolderStore *parent_folder;
1790 GtkWidget *folder_view;
1792 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1794 folder_view = modest_main_window_get_child_widget (main_window,
1795 MODEST_WIDGET_TYPE_FOLDER_VIEW);
1799 parent_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
1801 if (parent_folder) {
1802 gboolean finished = FALSE;
1804 gchar *folder_name = NULL, *suggested_name = NULL;
1806 /* Run the new folder dialog */
1808 result = modest_platform_run_new_folder_dialog (GTK_WINDOW (main_window),
1813 if (result == GTK_RESPONSE_REJECT) {
1816 ModestMailOperation *mail_op;
1817 TnyFolder *new_folder = NULL;
1819 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_INFO,
1820 G_OBJECT(main_window));
1821 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
1823 new_folder = modest_mail_operation_create_folder (mail_op,
1825 (const gchar *) folder_name);
1827 g_object_unref (new_folder);
1830 g_object_unref (mail_op);
1832 g_free (folder_name);
1836 g_object_unref (parent_folder);
1841 modest_ui_actions_on_rename_folder (GtkAction *action,
1842 ModestMainWindow *main_window)
1844 TnyFolderStore *folder;
1845 GtkWidget *folder_view;
1846 GtkWidget *header_view;
1848 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1850 folder_view = modest_main_window_get_child_widget (main_window,
1851 MODEST_WIDGET_TYPE_FOLDER_VIEW);
1855 header_view = modest_main_window_get_child_widget (main_window,
1856 MODEST_WIDGET_TYPE_HEADER_VIEW);
1861 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
1863 if (folder && TNY_IS_FOLDER (folder)) {
1865 folder_name = ask_for_folder_name (GTK_WINDOW (main_window),
1866 _("Please enter a new name for the folder"));
1868 if (folder_name != NULL && strlen (folder_name) > 0) {
1869 ModestMailOperation *mail_op;
1871 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_INFO, G_OBJECT(main_window));
1872 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
1875 modest_header_view_clear (MODEST_HEADER_VIEW (header_view));
1877 modest_mail_operation_rename_folder (mail_op,
1878 TNY_FOLDER (folder),
1879 (const gchar *) folder_name);
1881 g_object_unref (mail_op);
1882 g_free (folder_name);
1884 g_object_unref (folder);
1889 modest_ui_actions_delete_folder_error_handler (ModestMailOperation *mail_op,
1892 GObject *win = modest_mail_operation_get_source (mail_op);
1894 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
1895 _("mail_in_ui_folder_delete_error"));
1899 delete_folder (ModestMainWindow *main_window, gboolean move_to_trash)
1901 TnyFolderStore *folder;
1902 GtkWidget *folder_view;
1906 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1908 folder_view = modest_main_window_get_child_widget (main_window,
1909 MODEST_WIDGET_TYPE_FOLDER_VIEW);
1913 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
1915 /* Show an error if it's an account */
1916 if (!TNY_IS_FOLDER (folder)) {
1917 modest_platform_run_information_dialog (GTK_WINDOW (main_window),
1918 _("mail_in_ui_folder_delete_error"));
1923 message = g_strdup_printf (_("mcen_nc_delete_folder_text"),
1924 tny_folder_get_name (TNY_FOLDER (folder)));
1925 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (main_window),
1926 (const gchar *) message);
1929 if (response == GTK_RESPONSE_OK) {
1930 ModestMailOperation *mail_op =
1931 modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_DELETE,
1932 G_OBJECT(main_window),
1933 modest_ui_actions_delete_folder_error_handler,
1936 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
1938 modest_mail_operation_remove_folder (mail_op, TNY_FOLDER (folder), move_to_trash);
1939 g_object_unref (G_OBJECT (mail_op));
1942 g_object_unref (G_OBJECT (folder));
1946 modest_ui_actions_on_delete_folder (GtkAction *action,
1947 ModestMainWindow *main_window)
1949 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1951 delete_folder (main_window, FALSE);
1955 modest_ui_actions_on_move_folder_to_trash_folder (GtkAction *action, ModestMainWindow *main_window)
1957 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1959 delete_folder (main_window, TRUE);
1963 modest_ui_actions_on_password_requested (TnyAccountStore *account_store,
1964 const gchar* server_account_name,
1969 ModestMainWindow *main_window)
1971 g_return_if_fail(server_account_name);
1972 /* printf("DEBUG: %s: server_account_name=%s\n", __FUNCTION__, server_account_name); */
1974 /* Initalize output parameters: */
1981 #ifdef MODEST_PLATFORM_MAEMO
1982 /* Maemo uses a different (awkward) button order,
1983 * It should probably just use gtk_alternative_dialog_button_order ().
1985 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
1989 GTK_RESPONSE_ACCEPT,
1991 GTK_RESPONSE_REJECT,
1994 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
1998 GTK_RESPONSE_REJECT,
2000 GTK_RESPONSE_ACCEPT,
2002 #endif /* MODEST_PLATFORM_MAEMO */
2004 gtk_window_set_transient_for (GTK_WINDOW(dialog), GTK_WINDOW(main_window));
2006 gchar *server_name = modest_server_account_get_hostname (
2007 modest_runtime_get_account_mgr(), server_account_name);
2008 if (!server_name) {/* This happened once, though I don't know why. murrayc. */
2009 g_warning("%s: Could not get server name for server account '%s'", __FUNCTION__, server_account_name);
2014 /* This causes a warning because the logical ID has no %s in it,
2015 * though the translation does, but there is not much we can do about that: */
2016 gchar *txt = g_strdup_printf (_("mail_ia_password_info"), server_name);
2017 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), gtk_label_new(txt),
2020 g_free (server_name);
2024 gchar *initial_username = modest_server_account_get_username (
2025 modest_runtime_get_account_mgr(), server_account_name);
2027 GtkWidget *entry_username = gtk_entry_new ();
2028 if (initial_username)
2029 gtk_entry_set_text (GTK_ENTRY (entry_username), initial_username);
2030 /* Dim this if a connection has ever succeeded with this username,
2031 * as per the UI spec: */
2032 const gboolean username_known =
2033 modest_server_account_get_username_has_succeeded(
2034 modest_runtime_get_account_mgr(), server_account_name);
2035 gtk_widget_set_sensitive (entry_username, !username_known);
2037 #ifdef MODEST_PLATFORM_MAEMO
2038 /* Auto-capitalization is the default, so let's turn it off: */
2039 hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_username), HILDON_GTK_INPUT_MODE_FULL);
2041 /* Create a size group to be used by all captions.
2042 * Note that HildonCaption does not create a default size group if we do not specify one.
2043 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
2044 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
2046 GtkWidget *caption = hildon_caption_new (sizegroup,
2047 _("mail_fi_username"), entry_username, NULL, HILDON_CAPTION_MANDATORY);
2048 gtk_widget_show (entry_username);
2049 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
2050 FALSE, FALSE, MODEST_MARGIN_HALF);
2051 gtk_widget_show (caption);
2053 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry_username,
2055 #endif /* MODEST_PLATFORM_MAEMO */
2058 GtkWidget *entry_password = gtk_entry_new ();
2059 gtk_entry_set_visibility (GTK_ENTRY(entry_password), FALSE);
2060 /* gtk_entry_set_invisible_char (GTK_ENTRY(entry_password), "*"); */
2062 #ifdef MODEST_PLATFORM_MAEMO
2063 /* Auto-capitalization is the default, so let's turn it off: */
2064 hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_password),
2065 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
2067 caption = hildon_caption_new (sizegroup,
2068 _("mail_fi_password"), entry_password, NULL, HILDON_CAPTION_MANDATORY);
2069 gtk_widget_show (entry_password);
2070 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
2071 FALSE, FALSE, MODEST_MARGIN_HALF);
2072 gtk_widget_show (caption);
2073 g_object_unref (sizegroup);
2075 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry_password,
2077 #endif /* MODEST_PLATFORM_MAEMO */
2079 /* This is not in the Maemo UI spec:
2080 remember_pass_check = gtk_check_button_new_with_label (_("Remember password"));
2081 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), remember_pass_check,
2085 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
2087 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
2089 *username = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_username)));
2091 modest_server_account_set_username (
2092 modest_runtime_get_account_mgr(), server_account_name,
2095 const gboolean username_was_changed =
2096 (strcmp (*username, initial_username) != 0);
2097 if (username_was_changed) {
2098 /* To actually use a changed username,
2099 * we must reset the connection, according to pvanhoof.
2100 * This _might_ be a sensible way to do that: */
2101 TnyDevice *device = modest_runtime_get_device();
2102 tny_device_force_offline (device);
2103 tny_device_force_online (device);
2108 *password = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_password)));
2110 /* We do not save the password in the configuration,
2111 * because this function is only called for passwords that should
2112 * not be remembered:
2113 modest_server_account_set_password (
2114 modest_runtime_get_account_mgr(), server_account_name,
2133 /* This is not in the Maemo UI spec:
2134 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (remember_pass_check)))
2140 gtk_widget_destroy (dialog);
2142 /* printf ("DEBUG: %s: cancel=%d\n", __FUNCTION__, *cancel); */
2146 modest_ui_actions_on_cut (GtkAction *action,
2147 ModestWindow *window)
2149 GtkWidget *focused_widget;
2151 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
2152 if (GTK_IS_EDITABLE (focused_widget)) {
2153 gtk_editable_cut_clipboard (GTK_EDITABLE(focused_widget));
2154 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
2155 GtkTextBuffer *buffer;
2156 GtkClipboard *clipboard;
2158 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
2159 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
2160 gtk_text_buffer_cut_clipboard (buffer, clipboard, TRUE);
2161 } else if (MODEST_IS_HEADER_VIEW (focused_widget)) {
2162 modest_header_view_cut_selection (MODEST_HEADER_VIEW (focused_widget));
2163 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
2164 modest_folder_view_cut_selection (MODEST_FOLDER_VIEW (focused_widget));
2169 modest_ui_actions_on_copy (GtkAction *action,
2170 ModestWindow *window)
2172 GtkClipboard *clipboard;
2173 GtkWidget *focused_widget;
2175 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
2176 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 modest_header_view_copy_selection (MODEST_HEADER_VIEW (focused_widget));
2188 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
2189 modest_folder_view_copy_selection (MODEST_FOLDER_VIEW (focused_widget));
2194 modest_ui_actions_on_undo (GtkAction *action,
2195 ModestWindow *window)
2197 if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
2198 modest_msg_edit_window_undo (MODEST_MSG_EDIT_WINDOW (window));
2200 g_return_if_reached ();
2205 modest_ui_actions_on_paste (GtkAction *action,
2206 ModestWindow *window)
2208 GtkWidget *focused_widget;
2209 ModestMailOperation *mail_op = NULL;
2211 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
2212 if (GTK_IS_EDITABLE (focused_widget)) {
2213 gtk_editable_paste_clipboard (GTK_EDITABLE(focused_widget));
2214 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
2215 GtkTextBuffer *buffer;
2216 GtkClipboard *clipboard;
2218 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
2219 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
2220 gtk_text_buffer_paste_clipboard (buffer, clipboard, NULL, TRUE);
2221 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
2222 ModestEmailClipboard *clipboard = NULL;
2223 TnyFolder *src_folder = NULL;
2224 TnyFolderStore *folder_store = NULL;
2225 TnyList *data = NULL;
2226 gboolean delete = FALSE;
2228 /* Check clipboard source */
2229 clipboard = modest_runtime_get_email_clipboard ();
2230 if (modest_email_clipboard_cleared (clipboard))
2233 /* Get elements to paste */
2234 modest_email_clipboard_get_data (clipboard, &src_folder, &data, &delete);
2236 /* Create a new mail operation */
2237 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_RECEIVE, G_OBJECT(window));
2238 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
2241 /* Get destination folder */
2242 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (focused_widget));
2244 /* transfer messages */
2246 modest_mail_operation_xfer_msgs (mail_op,
2248 TNY_FOLDER (folder_store),
2253 } else if (src_folder != NULL) {
2254 modest_mail_operation_xfer_folder (mail_op,
2262 g_object_unref (data);
2263 if (src_folder != NULL)
2264 g_object_unref (src_folder);
2265 if (folder_store != NULL)
2266 g_object_unref (folder_store);
2271 modest_ui_actions_on_select_all (GtkAction *action,
2272 ModestWindow *window)
2274 GtkWidget *focused_widget;
2276 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
2277 if (MODEST_IS_ATTACHMENTS_VIEW (focused_widget)) {
2278 modest_attachments_view_select_all (MODEST_ATTACHMENTS_VIEW (focused_widget));
2279 } else if (GTK_IS_LABEL (focused_widget)) {
2280 gtk_label_select_region (GTK_LABEL (focused_widget), 0, -1);
2281 } else if (GTK_IS_EDITABLE (focused_widget)) {
2282 gtk_editable_select_region (GTK_EDITABLE(focused_widget), 0, -1);
2283 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
2284 GtkTextBuffer *buffer;
2285 GtkTextIter start, end;
2287 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
2288 gtk_text_buffer_get_start_iter (buffer, &start);
2289 gtk_text_buffer_get_end_iter (buffer, &end);
2290 gtk_text_buffer_select_range (buffer, &start, &end);
2292 else if ((MODEST_IS_FOLDER_VIEW (focused_widget)) ||
2293 (MODEST_IS_HEADER_VIEW (focused_widget))) {
2295 GtkTreeSelection *selection = NULL;
2297 /* Get header view */
2298 GtkWidget *header_view = focused_widget;
2299 if (MODEST_IS_FOLDER_VIEW (focused_widget))
2300 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (window),
2301 MODEST_WIDGET_TYPE_HEADER_VIEW);
2303 /* Select all messages */
2304 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(header_view));
2305 gtk_tree_selection_select_all (selection);
2306 } else if (GTK_IS_HTML (focused_widget)) {
2307 gtk_html_select_all (GTK_HTML (focused_widget));
2312 modest_ui_actions_on_mark_as_read (GtkAction *action,
2313 ModestWindow *window)
2315 g_return_if_fail (MODEST_IS_WINDOW(window));
2317 /* Mark each header as read */
2318 do_headers_action (window, headers_action_mark_as_read, NULL);
2322 modest_ui_actions_on_mark_as_unread (GtkAction *action,
2323 ModestWindow *window)
2325 g_return_if_fail (MODEST_IS_WINDOW(window));
2327 /* Mark each header as read */
2328 do_headers_action (window, headers_action_mark_as_unread, NULL);
2332 modest_ui_actions_on_change_zoom (GtkRadioAction *action,
2333 GtkRadioAction *selected,
2334 ModestWindow *window)
2338 value = gtk_radio_action_get_current_value (selected);
2339 if (MODEST_IS_WINDOW (window)) {
2340 modest_window_set_zoom (MODEST_WINDOW (window), ((gdouble)value)/100);
2344 void modest_ui_actions_msg_edit_on_change_priority (GtkRadioAction *action,
2345 GtkRadioAction *selected,
2346 ModestWindow *window)
2348 TnyHeaderFlags flags;
2349 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2351 flags = gtk_radio_action_get_current_value (selected);
2352 modest_msg_edit_window_set_priority_flags (MODEST_MSG_EDIT_WINDOW (window), flags);
2355 void modest_ui_actions_msg_edit_on_change_file_format (GtkRadioAction *action,
2356 GtkRadioAction *selected,
2357 ModestWindow *window)
2361 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2363 file_format = gtk_radio_action_get_current_value (selected);
2364 modest_msg_edit_window_set_file_format (MODEST_MSG_EDIT_WINDOW (window), file_format);
2369 modest_ui_actions_on_zoom_plus (GtkAction *action,
2370 ModestWindow *window)
2372 g_return_if_fail (MODEST_IS_WINDOW (window));
2374 modest_window_zoom_plus (MODEST_WINDOW (window));
2378 modest_ui_actions_on_zoom_minus (GtkAction *action,
2379 ModestWindow *window)
2381 g_return_if_fail (MODEST_IS_WINDOW (window));
2383 modest_window_zoom_minus (MODEST_WINDOW (window));
2387 modest_ui_actions_on_toggle_fullscreen (GtkToggleAction *toggle,
2388 ModestWindow *window)
2390 ModestWindowMgr *mgr;
2391 gboolean fullscreen, active;
2392 g_return_if_fail (MODEST_IS_WINDOW (window));
2394 mgr = modest_runtime_get_window_mgr ();
2396 active = (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle)))?1:0;
2397 fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
2399 if (active != fullscreen) {
2400 modest_window_mgr_set_fullscreen_mode (mgr, active);
2401 gtk_window_present (GTK_WINDOW (window));
2406 modest_ui_actions_on_change_fullscreen (GtkAction *action,
2407 ModestWindow *window)
2409 ModestWindowMgr *mgr;
2410 gboolean fullscreen;
2412 g_return_if_fail (MODEST_IS_WINDOW (window));
2414 mgr = modest_runtime_get_window_mgr ();
2415 fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
2416 modest_window_mgr_set_fullscreen_mode (mgr, !fullscreen);
2418 gtk_window_present (GTK_WINDOW (window));
2422 * Used by modest_ui_actions_on_details to call do_headers_action
2425 headers_action_show_details (TnyHeader *header,
2426 ModestWindow *window,
2433 dialog = modest_details_dialog_new_with_header (GTK_WINDOW (window), header);
2436 gtk_widget_show_all (dialog);
2437 gtk_dialog_run (GTK_DIALOG (dialog));
2439 gtk_widget_destroy (dialog);
2443 * Show the folder details in a ModestDetailsDialog widget
2446 show_folder_details (TnyFolder *folder,
2452 dialog = modest_details_dialog_new_with_folder (window, folder);
2455 gtk_widget_show_all (dialog);
2456 gtk_dialog_run (GTK_DIALOG (dialog));
2458 gtk_widget_destroy (dialog);
2462 * Show the header details in a ModestDetailsDialog widget
2465 modest_ui_actions_on_details (GtkAction *action,
2468 TnyList * headers_list;
2472 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
2475 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW (win));
2478 g_object_unref (msg);
2480 headers_list = get_selected_headers (win);
2484 iter = tny_list_create_iterator (headers_list);
2486 header = TNY_HEADER (tny_iterator_get_current (iter));
2487 headers_action_show_details (header, win, NULL);
2488 g_object_unref (header);
2490 g_object_unref (iter);
2491 g_object_unref (headers_list);
2493 } else if (MODEST_IS_MAIN_WINDOW (win)) {
2494 GtkWidget *folder_view, *header_view;
2496 /* Check which widget has the focus */
2497 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
2498 MODEST_WIDGET_TYPE_FOLDER_VIEW);
2499 if (gtk_widget_is_focus (folder_view)) {
2502 folder = (TnyFolder *) modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
2504 /* Show only when it's a folder */
2505 if (!folder || !TNY_IS_FOLDER (folder))
2508 show_folder_details (folder, GTK_WINDOW (win));
2511 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
2512 MODEST_WIDGET_TYPE_HEADER_VIEW);
2513 /* Show details of each header */
2514 do_headers_action (win, headers_action_show_details, header_view);
2520 modest_ui_actions_on_toggle_show_cc (GtkToggleAction *toggle,
2521 ModestMsgEditWindow *window)
2523 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2525 modest_msg_edit_window_show_cc (window, gtk_toggle_action_get_active (toggle));
2529 modest_ui_actions_on_toggle_show_bcc (GtkToggleAction *toggle,
2530 ModestMsgEditWindow *window)
2532 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2534 modest_msg_edit_window_show_bcc (window, gtk_toggle_action_get_active (toggle));
2538 modest_ui_actions_toggle_folders_view (GtkAction *action,
2539 ModestMainWindow *main_window)
2543 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2545 conf = modest_runtime_get_conf ();
2547 if (modest_main_window_get_style (main_window) == MODEST_MAIN_WINDOW_STYLE_SPLIT)
2548 modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SIMPLE);
2550 modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SPLIT);
2554 modest_ui_actions_on_toggle_toolbar (GtkToggleAction *toggle,
2555 ModestWindow *window)
2557 gboolean active, fullscreen = FALSE;
2558 ModestWindowMgr *mgr;
2560 active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle));
2562 /* Check if we want to toggle the toolbar vuew in fullscreen
2564 if (!strcmp (gtk_action_get_name (GTK_ACTION (toggle)),
2565 "ViewShowToolbarFullScreen")) {
2569 /* Toggle toolbar */
2570 mgr = modest_runtime_get_window_mgr ();
2571 modest_window_mgr_show_toolbars (mgr, active, fullscreen);
2575 modest_ui_actions_msg_edit_on_select_font (GtkAction *action,
2576 ModestMsgEditWindow *window)
2578 modest_msg_edit_window_select_font (window);
2582 modest_ui_actions_on_folder_display_name_changed (ModestFolderView *folder_view,
2583 const gchar *display_name,
2586 /* Do not change the application name if the widget has not
2587 the focus. This callback could be called even if the folder
2588 view has not the focus, because the handled signal could be
2589 emitted when the folder view is redrawn */
2590 if (gtk_widget_is_focus (GTK_WIDGET (folder_view))) {
2592 gtk_window_set_title (window, display_name);
2594 gtk_window_set_title (window, " ");
2599 modest_ui_actions_on_select_contacts (GtkAction *action, ModestMsgEditWindow *window)
2601 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2602 modest_msg_edit_window_select_contacts (window);
2606 modest_ui_actions_on_check_names (GtkAction *action, ModestMsgEditWindow *window)
2608 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2609 modest_msg_edit_window_check_names (window);
2614 create_move_to_dialog (ModestWindow *win,
2615 GtkWidget *folder_view,
2616 GtkWidget **tree_view)
2618 GtkWidget *dialog, *scroll;
2620 dialog = gtk_dialog_new_with_buttons (_("mcen_ti_moveto_folders_title"),
2622 GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR | GTK_DIALOG_DESTROY_WITH_PARENT,
2624 GTK_RESPONSE_ACCEPT,
2626 GTK_RESPONSE_REJECT,
2629 /* Create scrolled window */
2630 scroll = gtk_scrolled_window_new (NULL, NULL);
2631 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll),
2632 GTK_POLICY_AUTOMATIC,
2633 GTK_POLICY_AUTOMATIC);
2635 /* Create folder view */
2636 *tree_view = modest_platform_create_folder_view (NULL);
2638 /* It could happen that we're trying to move a message from a
2639 window (msg window for example) after the main window was
2640 closed, so we can not just get the model of the folder
2642 if (MODEST_IS_FOLDER_VIEW (folder_view))
2643 gtk_tree_view_set_model (GTK_TREE_VIEW (*tree_view),
2644 gtk_tree_view_get_model (GTK_TREE_VIEW (folder_view)));
2646 modest_folder_view_update_model (MODEST_FOLDER_VIEW (*tree_view),
2647 TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()));
2649 gtk_container_add (GTK_CONTAINER (scroll), *tree_view);
2651 /* Add scroll to dialog */
2652 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
2653 scroll, FALSE, FALSE, 0);
2655 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
2657 /* Select INBOX or local account */
2658 modest_folder_view_select_first_inbox_or_local (MODEST_FOLDER_VIEW (*tree_view));
2664 * Returns TRUE if at least one of the headers of the list belongs to
2665 * a message that has been fully retrieved.
2668 has_retrieved_msgs (TnyList *list)
2671 gboolean found = FALSE;
2673 iter = tny_list_create_iterator (list);
2674 while (tny_iterator_is_done (iter) && !found) {
2676 TnyHeaderFlags flags;
2678 header = TNY_HEADER (tny_iterator_get_current (iter));
2679 flags = tny_header_get_flags (header);
2680 if (!(flags & TNY_HEADER_FLAG_PARTIAL))
2684 tny_iterator_next (iter);
2686 g_object_unref (iter);
2692 * Shows a confirmation dialog to the user when we're moving messages
2693 * from a remote server to the local storage. Returns the dialog
2694 * response. If it's other kind of movement the it always returns
2698 msgs_move_to_confirmation (GtkWindow *win,
2699 TnyFolder *dest_folder,
2702 gint response = GTK_RESPONSE_OK;
2704 /* If the destination is a local folder */
2705 if (modest_tny_folder_is_local_folder (dest_folder)) {
2706 TnyFolder *src_folder;
2710 /* Get source folder */
2711 iter = tny_list_create_iterator (headers);
2712 header = TNY_HEADER (tny_iterator_get_current (iter));
2713 src_folder = tny_header_get_folder (header);
2714 g_object_unref (header);
2715 g_object_unref (iter);
2717 /* If the source is a remote folder */
2718 if (!modest_tny_folder_is_local_folder (src_folder)) {
2719 const gchar *message;
2721 if (tny_list_get_length (headers) == 1)
2722 if (has_retrieved_msgs (headers))
2723 message = _("mcen_nc_move_retrieve");
2725 message = _("mcen_nc_move_header");
2727 if (has_retrieved_msgs (headers))
2728 message = _("mcen_nc_move_retrieves");
2730 message = _("mcen_nc_move_headers");
2732 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
2733 (const gchar *) message);
2735 g_object_unref (src_folder);
2742 transfer_msgs_from_viewer_cb (const GObject *object, gpointer user_data)
2744 ModestMsgViewWindow *self = NULL;
2746 g_return_if_fail (MODEST_IS_MSG_VIEW_WINDOW (object));
2747 self = MODEST_MSG_VIEW_WINDOW (object);
2749 /* If there are not more messages don't do anything. The
2750 viewer will show the same message */
2751 if (!modest_msg_view_window_select_first_message (self))
2756 modest_ui_actions_move_folder_error_handler (ModestMailOperation *mail_op,
2759 GObject *win = modest_mail_operation_get_source (mail_op);
2761 /* TODO: show error message */
2762 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
2763 _("mail_in_ui_folder_move_target_error"));
2767 * UI handler for the "Move to" action when invoked from the
2771 modest_ui_actions_on_main_window_move_to (GtkAction *action,
2772 ModestMainWindow *win)
2774 GtkWidget *dialog = NULL, *folder_view = NULL, *tree_view = NULL;
2775 GtkWidget *header_view = NULL;
2777 TnyFolderStore *folder_store = NULL;
2778 ModestMailOperation *mail_op = NULL;
2780 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win));
2782 /* Get the folder view */
2783 folder_view = modest_main_window_get_child_widget (win,
2784 MODEST_WIDGET_TYPE_FOLDER_VIEW);
2786 /* Get header view */
2787 header_view = modest_main_window_get_child_widget (win,
2788 MODEST_WIDGET_TYPE_HEADER_VIEW);
2790 /* Create and run the dialog */
2791 dialog = create_move_to_dialog (MODEST_WINDOW (win), folder_view, &tree_view);
2792 modest_folder_view_select_first_inbox_or_local (MODEST_FOLDER_VIEW (tree_view));
2793 result = gtk_dialog_run (GTK_DIALOG(dialog));
2794 g_object_ref (tree_view);
2796 /* We do this to save an indentation level ;-) */
2797 if (result != GTK_RESPONSE_ACCEPT)
2800 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (tree_view));
2802 if (TNY_IS_ACCOUNT (folder_store))
2805 /* Get folder or messages to transfer */
2806 if (gtk_widget_is_focus (folder_view)) {
2807 TnyFolderStore *src_folder;
2808 src_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
2810 /* Clean folder on header view before moving it */
2811 modest_header_view_clear (MODEST_HEADER_VIEW (header_view));
2813 if (TNY_IS_FOLDER (src_folder)) {
2815 modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE,
2817 modest_ui_actions_move_folder_error_handler,
2819 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
2821 modest_mail_operation_xfer_folder (mail_op,
2822 TNY_FOLDER (src_folder),
2825 /* Unref mail operation */
2826 g_object_unref (G_OBJECT (mail_op));
2830 g_object_unref (G_OBJECT (src_folder));
2832 if (gtk_widget_is_focus (header_view)) {
2836 headers = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW (header_view));
2838 /* Ask for user confirmation */
2839 response = msgs_move_to_confirmation (GTK_WINDOW (win),
2840 TNY_FOLDER (folder_store),
2843 /* Transfer messages */
2844 if (response == GTK_RESPONSE_OK) {
2845 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_RECEIVE, G_OBJECT(win));
2846 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
2849 modest_mail_operation_xfer_msgs (mail_op,
2851 TNY_FOLDER (folder_store),
2856 g_object_unref (G_OBJECT (mail_op));
2858 g_object_unref (headers);
2861 g_object_unref (folder_store);
2863 gtk_widget_destroy (dialog);
2868 * UI handler for the "Move to" action when invoked from the
2869 * ModestMsgViewWindow
2872 modest_ui_actions_on_msg_view_window_move_to (GtkAction *action,
2873 ModestMsgViewWindow *win)
2875 GtkWidget *dialog, *folder_view, *tree_view = NULL;
2877 ModestMainWindow *main_window;
2881 /* Get the folder view */
2882 main_window = MODEST_MAIN_WINDOW (modest_window_mgr_get_main_window (modest_runtime_get_window_mgr ()));
2884 folder_view = modest_main_window_get_child_widget (main_window,
2885 MODEST_WIDGET_TYPE_FOLDER_VIEW);
2889 /* Create and run the dialog */
2890 dialog = create_move_to_dialog (MODEST_WINDOW (win), folder_view, &tree_view);
2891 result = gtk_dialog_run (GTK_DIALOG(dialog));
2892 g_object_ref (tree_view);
2894 if (result == GTK_RESPONSE_ACCEPT) {
2895 TnyFolderStore *folder_store;
2898 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (tree_view));
2900 /* Create header list */
2901 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
2902 headers = tny_simple_list_new ();
2903 tny_list_prepend (headers, G_OBJECT (header));
2904 g_object_unref (header);
2906 /* Ask user for confirmation. MSG-NOT404 */
2907 response = msgs_move_to_confirmation (GTK_WINDOW (win),
2908 TNY_FOLDER (folder_store),
2911 /* Transfer current msg */
2912 if (response == GTK_RESPONSE_OK) {
2913 ModestMailOperation *mail_op;
2915 /* Create mail op */
2916 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_RECEIVE, G_OBJECT(win));
2917 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
2920 /* Transfer messages */
2921 modest_mail_operation_xfer_msgs (mail_op,
2923 TNY_FOLDER (folder_store),
2925 transfer_msgs_from_viewer_cb,
2927 g_object_unref (G_OBJECT (mail_op));
2929 g_object_unref (headers);
2930 g_object_unref (folder_store);
2932 gtk_widget_destroy (dialog);
2936 modest_ui_actions_on_move_to (GtkAction *action,
2939 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win) ||
2940 MODEST_IS_MSG_VIEW_WINDOW (win));
2942 if (MODEST_IS_MAIN_WINDOW (win))
2943 modest_ui_actions_on_main_window_move_to (action,
2944 MODEST_MAIN_WINDOW (win));
2946 modest_ui_actions_on_msg_view_window_move_to (action,
2947 MODEST_MSG_VIEW_WINDOW (win));
2951 * Calls #HeadersFunc for each header already selected in the main
2952 * window or the message currently being shown in the msg view window
2955 do_headers_action (ModestWindow *win,
2959 TnyList *headers_list;
2965 headers_list = get_selected_headers (win);
2969 /* Get the folder */
2970 iter = tny_list_create_iterator (headers_list);
2971 header = TNY_HEADER (tny_iterator_get_current (iter));
2972 folder = tny_header_get_folder (header);
2973 g_object_unref (header);
2975 /* Call the function for each header */
2976 while (!tny_iterator_is_done (iter)) {
2977 header = TNY_HEADER (tny_iterator_get_current (iter));
2978 func (header, win, user_data);
2979 g_object_unref (header);
2980 tny_iterator_next (iter);
2983 /* Trick: do a poke status in order to speed up the signaling
2985 tny_folder_poke_status (folder);
2988 g_object_unref (folder);
2989 g_object_unref (iter);
2990 g_object_unref (headers_list);
2994 modest_ui_actions_view_attachment (GtkAction *action,
2995 ModestWindow *window)
2997 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
2998 modest_msg_view_window_view_attachment (MODEST_MSG_VIEW_WINDOW (window), NULL);
3000 /* not supported window for this action */
3001 g_return_if_reached ();
3006 modest_ui_actions_save_attachments (GtkAction *action,
3007 ModestWindow *window)
3009 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
3010 modest_msg_view_window_save_attachments (MODEST_MSG_VIEW_WINDOW (window), NULL);
3012 /* not supported window for this action */
3013 g_return_if_reached ();
3018 modest_ui_actions_remove_attachments (GtkAction *action,
3019 ModestWindow *window)
3021 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
3022 modest_msg_view_window_remove_attachments (MODEST_MSG_VIEW_WINDOW (window), NULL);
3024 /* not supported window for this action */
3025 g_return_if_reached ();
3030 modest_ui_actions_on_settings (GtkAction *action,
3035 dialog = modest_platform_get_global_settings_dialog ();
3036 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (win));
3037 gtk_widget_show (dialog);
3039 gtk_dialog_run (GTK_DIALOG (dialog));
3041 gtk_widget_destroy (dialog);
3045 modest_ui_actions_on_help (GtkAction *action,
3048 const gchar *help_id = NULL;
3050 if (MODEST_IS_MAIN_WINDOW (win)) {
3051 const gchar *action_name;
3052 action_name = gtk_action_get_name (action);
3054 if (!strcmp (action_name, "FolderViewCSMHelp") ||
3055 !strcmp (action_name, "HeaderViewCSMHelp")) {
3056 GtkWidget *folder_view;
3057 TnyFolderStore *folder_store;
3058 /* Get selected folder */
3059 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
3060 MODEST_WIDGET_TYPE_FOLDER_VIEW);
3061 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
3063 /* Switch help_id */
3064 if (TNY_IS_FOLDER (folder_store)) {
3065 switch (tny_folder_get_folder_type (TNY_FOLDER (folder_store))) {
3066 case TNY_FOLDER_TYPE_NORMAL:
3067 help_id = "applications_email_userfolder";
3069 case TNY_FOLDER_TYPE_INBOX:
3070 help_id = "applications_email_inbox";
3072 case TNY_FOLDER_TYPE_OUTBOX:
3073 help_id = "applications_email_outbox";
3075 case TNY_FOLDER_TYPE_SENT:
3076 help_id = "applications_email_sent";
3078 case TNY_FOLDER_TYPE_DRAFTS:
3079 help_id = "applications_email_drafts";
3081 case TNY_FOLDER_TYPE_ARCHIVE:
3082 help_id = "applications_email_archive";
3089 help_id = "applications_email_mainview";
3091 } else if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
3092 help_id = "applications_email_viewer";
3093 } else if (MODEST_IS_MSG_EDIT_WINDOW (win))
3094 help_id = "applications_email_editor";
3096 modest_platform_show_help (GTK_WINDOW (win), help_id);
3100 modest_ui_actions_on_retrieve_msg_contents (GtkAction *action,
3101 ModestWindow *window)
3103 ModestMailOperation *mail_op;
3107 headers = get_selected_headers (window);
3111 /* Create mail operation */
3112 mail_op = modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE,
3114 modest_ui_actions_get_msgs_full_error_handler,
3116 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
3117 modest_mail_operation_get_msgs_full (mail_op, headers, NULL, NULL, NULL);
3120 g_object_unref (headers);
3121 g_object_unref (mail_op);
3125 modest_ui_actions_on_email_menu_activated (GtkAction *action,
3126 ModestWindow *window)
3128 g_return_if_fail (MODEST_IS_WINDOW (window));
3131 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
3135 modest_ui_actions_on_edit_menu_activated (GtkAction *action,
3136 ModestWindow *window)
3138 g_return_if_fail (MODEST_IS_WINDOW (window));
3141 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
3145 modest_ui_actions_on_view_menu_activated (GtkAction *action,
3146 ModestWindow *window)
3148 g_return_if_fail (MODEST_IS_WINDOW (window));
3151 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
3155 modest_ui_actions_on_tools_menu_activated (GtkAction *action,
3156 ModestWindow *window)
3158 g_return_if_fail (MODEST_IS_WINDOW (window));
3161 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
3165 modest_ui_actions_on_attachment_menu_activated (GtkAction *action,
3166 ModestWindow *window)
3168 g_return_if_fail (MODEST_IS_WINDOW (window));
3171 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
3175 modest_ui_actions_on_toolbar_csm_menu_activated (GtkAction *action,
3176 ModestWindow *window)
3178 g_return_if_fail (MODEST_IS_WINDOW (window));
3181 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
3185 modest_ui_actions_on_folder_view_csm_menu_activated (GtkAction *action,
3186 ModestWindow *window)
3188 g_return_if_fail (MODEST_IS_WINDOW (window));
3191 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
3195 modest_ui_actions_on_header_view_csm_menu_activated (GtkAction *action,
3196 ModestWindow *window)
3198 g_return_if_fail (MODEST_IS_WINDOW (window));
3201 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
3205 modest_ui_actions_check_toolbar_dimming_rules (ModestWindow *window)
3207 g_return_if_fail (MODEST_IS_WINDOW (window));
3210 modest_window_check_dimming_rules_group (window, "ModestToolbarDimmingRules");
3214 modest_ui_actions_on_search_messages (GtkAction *action, ModestWindow *window)
3216 g_return_if_fail (MODEST_IS_WINDOW (window));
3218 modest_platform_show_search_messages (GTK_WINDOW (window));
3222 modest_ui_actions_on_open_addressbook (GtkAction *action, ModestWindow *win)
3224 g_return_if_fail (MODEST_IS_WINDOW (win));
3225 modest_platform_show_addressbook (GTK_WINDOW (win));
3230 modest_ui_actions_on_toggle_find_in_page (GtkToggleAction *action,
3231 ModestWindow *window)
3233 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3235 modest_msg_edit_window_toggle_find_toolbar (MODEST_MSG_EDIT_WINDOW (window), gtk_toggle_action_get_active (action));
3239 _on_send_receive_progress_changed (ModestMailOperation *mail_op,
3240 ModestMailOperationState *state,
3243 g_return_if_fail (MODEST_IS_MAIN_WINDOW(user_data));
3245 /* Set send/receive operation finished */
3246 if (state->status != MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS)
3247 modest_main_window_notify_send_receive_completed (MODEST_MAIN_WINDOW(user_data));