1 /* Copyright (c) 2006, Nokia Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of the Nokia Corporation nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #endif /*HAVE_CONFIG_H*/
34 #include <glib/gi18n.h>
35 #include <glib/gprintf.h>
37 #include <modest-runtime.h>
38 #include <modest-tny-folder.h>
39 #include <modest-tny-msg.h>
40 #include <modest-tny-account.h>
41 #include <modest-address-book.h>
42 #include "modest-error.h"
43 #include "modest-ui-actions.h"
45 #include "modest-tny-platform-factory.h"
46 #include "modest-platform.h"
47 #include <tny-mime-part.h>
48 #include <tny-camel-folder.h>
49 #include <tny-camel-imap-folder.h>
50 #include <tny-camel-pop-folder.h>
52 #ifdef MODEST_PLATFORM_MAEMO
53 #include "maemo/modest-osso-state-saving.h"
54 #include "maemo/modest-maemo-utils.h"
55 #include "maemo/modest-hildon-includes.h"
56 #endif /* MODEST_PLATFORM_MAEMO */
58 #include "widgets/modest-ui-constants.h"
59 #include <widgets/modest-main-window.h>
60 #include <widgets/modest-msg-view-window.h>
61 #include <widgets/modest-account-view-window.h>
62 #include <widgets/modest-details-dialog.h>
63 #include <widgets/modest-attachments-view.h>
64 #include "widgets/modest-folder-view.h"
65 #include "widgets/modest-global-settings-dialog.h"
66 #include "modest-connection-specific-smtp-window.h"
67 #include "modest-account-mgr-helpers.h"
68 #include "modest-mail-operation.h"
69 #include "modest-text-utils.h"
71 #ifdef MODEST_HAVE_EASYSETUP
72 #include "easysetup/modest-easysetup-wizard.h"
73 #endif /* MODEST_HAVE_EASYSETUP */
75 #include <modest-widget-memory.h>
76 #include <tny-error.h>
77 #include <tny-simple-list.h>
78 #include <tny-msg-view.h>
79 #include <tny-device.h>
80 #include <tny-merge-folder.h>
82 #include <gtkhtml/gtkhtml.h>
84 typedef struct _GetMsgAsyncHelper {
86 ModestMailOperation *mail_op;
93 typedef enum _ReplyForwardAction {
99 typedef struct _ReplyForwardHelper {
100 guint reply_forward_type;
101 ReplyForwardAction action;
103 GtkWidget *parent_window;
104 } ReplyForwardHelper;
106 typedef struct _PasteAsAttachmentHelper {
107 ModestMsgEditWindow *window;
109 } PasteAsAttachmentHelper;
113 * The do_headers_action uses this kind of functions to perform some
114 * action to each member of a list of headers
116 typedef void (*HeadersFunc) (TnyHeader *header, ModestWindow *win, gpointer user_data);
118 static void do_headers_action (ModestWindow *win,
122 static void open_msg_cb (ModestMailOperation *mail_op,
127 static void reply_forward_cb (ModestMailOperation *mail_op,
132 static void reply_forward (ReplyForwardAction action, ModestWindow *win);
134 static void folder_refreshed_cb (ModestMailOperation *mail_op,
138 static void _on_send_receive_progress_changed (ModestMailOperation *mail_op,
139 ModestMailOperationState *state,
142 static gint header_list_count_uncached_msgs (
143 TnyList *header_list,
145 static gboolean connect_to_get_msg (
147 gint num_of_uncached_msgs);
151 /* Show the account creation wizard dialog.
152 * returns: TRUE if an account was created. FALSE if the user cancelled.
155 modest_run_account_setup_wizard (ModestWindow *win)
157 gboolean result = FALSE;
160 wizard = modest_window_mgr_get_easysetup_dialog
161 (modest_runtime_get_window_mgr());
163 /* old wizard is active already; present it and
164 * act as if the user cancelled the non-existing
167 printf ("wizard already active\n");
170 /* there is no such wizard yet */
171 wizard = GTK_DIALOG(modest_easysetup_wizard_dialog_new ());
172 modest_window_mgr_set_easysetup_dialog
173 (modest_runtime_get_window_mgr(), GTK_DIALOG(wizard));
177 /* always present a main window in the background
178 * we do it here, so we cannot end up with to wizards (as this
179 * function might be called in modest_window_mgr_get_main_window as well */
181 win = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr());
183 /* make sure the mainwindow is visible */
184 gtk_widget_show_all (GTK_WIDGET(win));
185 gtk_window_present (GTK_WINDOW(win));
188 gtk_window_set_transient_for (GTK_WINDOW (wizard), GTK_WINDOW (win));
190 /* Don't make this a modal window, because secondary windows will then
191 * be unusable, freezing the UI: */
192 /* gtk_window_set_modal (GTK_WINDOW (wizard), TRUE); */
194 gint dialog_response = gtk_dialog_run (GTK_DIALOG (wizard));
195 if (dialog_response == GTK_RESPONSE_CANCEL)
198 /* Check whether an account was created: */
199 result = modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
202 gtk_widget_destroy (GTK_WIDGET (wizard));
204 /* clear it from the window mgr */
205 modest_window_mgr_set_easysetup_dialog
206 (modest_runtime_get_window_mgr(), NULL);
213 modest_ui_actions_on_about (GtkAction *action, ModestWindow *win)
216 const gchar *authors[] = {
217 "Dirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>",
220 about = gtk_about_dialog_new ();
221 gtk_about_dialog_set_name (GTK_ABOUT_DIALOG(about), PACKAGE_NAME);
222 gtk_about_dialog_set_version (GTK_ABOUT_DIALOG(about),PACKAGE_VERSION);
223 gtk_about_dialog_set_copyright (GTK_ABOUT_DIALOG(about),
224 _("Copyright (c) 2006, Nokia Corporation\n"
225 "All rights reserved."));
226 gtk_about_dialog_set_comments (GTK_ABOUT_DIALOG(about),
227 _("a modest e-mail client\n\n"
228 "design and implementation: Dirk-Jan C. Binnema\n"
229 "contributions from the fine people at KC and Ig\n"
230 "uses the tinymail email framework written by Philip van Hoof"));
231 gtk_about_dialog_set_authors (GTK_ABOUT_DIALOG(about), authors);
232 gtk_about_dialog_set_website (GTK_ABOUT_DIALOG(about), "http://modest.garage.maemo.org");
233 gtk_window_set_transient_for (GTK_WINDOW (about), GTK_WINDOW (win));
234 gtk_window_set_modal (GTK_WINDOW (about), TRUE);
236 gtk_dialog_run (GTK_DIALOG (about));
237 gtk_widget_destroy(about);
241 * Gets the list of currently selected messages. If the win is the
242 * main window, then it returns a newly allocated list of the headers
243 * selected in the header view. If win is the msg view window, then
244 * the value returned is a list with just a single header.
246 * The caller of this funcion must free the list.
249 get_selected_headers (ModestWindow *win)
251 if (MODEST_IS_MAIN_WINDOW(win)) {
252 GtkWidget *header_view;
254 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
255 MODEST_WIDGET_TYPE_HEADER_VIEW);
256 return modest_header_view_get_selected_headers (MODEST_HEADER_VIEW(header_view));
258 } else if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
259 /* for MsgViewWindows, we simply return a list with one element */
261 TnyList *list = NULL;
263 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
264 if (header != NULL) {
265 list = tny_simple_list_new ();
266 tny_list_prepend (list, G_OBJECT(header));
267 g_object_unref (G_OBJECT(header));
277 headers_action_mark_as_read (TnyHeader *header,
281 TnyHeaderFlags flags;
283 g_return_if_fail (TNY_IS_HEADER(header));
285 flags = tny_header_get_flags (header);
286 if (flags & TNY_HEADER_FLAG_SEEN) return;
287 tny_header_set_flags (header, TNY_HEADER_FLAG_SEEN);
291 headers_action_mark_as_unread (TnyHeader *header,
295 TnyHeaderFlags flags;
297 g_return_if_fail (TNY_IS_HEADER(header));
299 flags = tny_header_get_flags (header);
300 if (flags & TNY_HEADER_FLAG_SEEN) {
301 tny_header_unset_flags (header, TNY_HEADER_FLAG_SEEN);
305 /** A convenience method, because deleting a message is
306 * otherwise complicated, and it's best to change it in one place
309 void modest_do_message_delete (TnyHeader *header, ModestWindow *win)
311 ModestMailOperation *mail_op = NULL;
312 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_DELETE,
313 win ? G_OBJECT(win) : NULL);
314 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
317 /* Always delete. TODO: Move to trash still not supported */
318 modest_mail_operation_remove_msg (mail_op, header, FALSE);
319 g_object_unref (G_OBJECT (mail_op));
322 /** A convenience method, because deleting a message is
323 * otherwise complicated, and it's best to change it in one place
326 void modest_do_messages_delete (TnyList *headers, ModestWindow *win)
328 ModestMailOperation *mail_op = NULL;
329 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_DELETE,
330 win ? G_OBJECT(win) : NULL);
331 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
334 /* Always delete. TODO: Move to trash still not supported */
335 modest_mail_operation_remove_msgs (mail_op, headers, FALSE);
336 g_object_unref (G_OBJECT (mail_op));
340 /* headers_action_delete (TnyHeader *header, */
341 /* ModestWindow *win, */
342 /* gpointer user_data) */
344 /* modest_do_message_delete (header, win); */
348 /** After deleing a message that is currently visible in a window,
349 * show the next message from the list, or close the window if there are no more messages.
351 void modest_ui_actions_refresh_message_window_after_delete (ModestMsgViewWindow* win)
353 /* Close msg view window or select next */
354 if (modest_msg_view_window_last_message_selected (win) &&
355 modest_msg_view_window_first_message_selected (win)) {
356 modest_ui_actions_on_close_window (NULL, MODEST_WINDOW (win));
358 if (!modest_msg_view_window_select_next_message (win)) {
360 g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value);
366 modest_ui_actions_on_delete_message (GtkAction *action, ModestWindow *win)
368 TnyList *header_list = NULL;
369 TnyIterator *iter = NULL;
370 TnyHeader *header = NULL;
371 gchar *message = NULL;
374 ModestWindowMgr *mgr;
375 GtkWidget *header_view = NULL;
377 g_return_if_fail (MODEST_IS_WINDOW(win));
379 /* Check first if the header view has the focus */
380 if (MODEST_IS_MAIN_WINDOW (win)) {
382 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
383 MODEST_WIDGET_TYPE_HEADER_VIEW);
384 if (!gtk_widget_is_focus (header_view))
388 /* Get the headers, either from the header view (if win is the main window),
389 * or from the message view window: */
390 header_list = get_selected_headers (win);
391 if (!header_list) return;
393 /* Check if any of the headers are already opened, or in the process of being opened */
394 if (MODEST_IS_MAIN_WINDOW (win)) {
396 iter = tny_list_create_iterator (header_list);
398 mgr = modest_runtime_get_window_mgr ();
399 while (!tny_iterator_is_done (iter) && !found) {
400 header = TNY_HEADER (tny_iterator_get_current (iter));
402 found = modest_window_mgr_find_registered_header (mgr, header, NULL);
403 g_object_unref (header);
406 tny_iterator_next (iter);
408 g_object_unref (iter);
413 num = g_strdup_printf ("%d", tny_list_get_length (header_list));
414 msg = g_strdup_printf (_("mcen_nc_unable_to_delete_n_messages"), num);
416 modest_platform_run_information_dialog (GTK_WINDOW (win), (const gchar *) msg);
420 g_object_unref (header_list);
426 if (tny_list_get_length(header_list) == 1) {
427 iter = tny_list_create_iterator (header_list);
428 header = TNY_HEADER (tny_iterator_get_current (iter));
430 desc = g_strdup_printf ("%s", tny_header_get_subject (header));
431 g_object_unref (header);
434 g_object_unref (iter);
436 message = g_strdup_printf(ngettext("emev_nc_delete_message", "emev_nc_delete_messages",
437 tny_list_get_length(header_list)), desc);
439 /* Confirmation dialog */
440 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
444 if (response == GTK_RESPONSE_OK) {
445 ModestWindow *main_window = NULL;
446 ModestWindowMgr *mgr = NULL;
447 GtkTreeModel *model = NULL;
448 GtkTreeSelection *sel = NULL;
449 GList *sel_list = NULL, *tmp = NULL;
450 GtkTreeRowReference *row_reference = NULL;
451 GtkTreePath *next_path = NULL;
454 /* Find last selected row */
455 if (MODEST_IS_MAIN_WINDOW (win)) {
456 model = gtk_tree_view_get_model (GTK_TREE_VIEW (header_view));
457 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
458 sel_list = gtk_tree_selection_get_selected_rows (sel, &model);
459 for (tmp=sel_list; tmp; tmp=tmp->next) {
460 if (tmp->next == NULL) {
461 next_path = gtk_tree_path_copy((GtkTreePath *) tmp->data);
462 gtk_tree_path_next (next_path);
463 row_reference = gtk_tree_row_reference_new (model, next_path);
464 gtk_tree_path_free (next_path);
469 /* Disable window dimming management */
470 modest_window_disable_dimming (MODEST_WINDOW(win));
472 /* Remove each header. If it's a view window header_view == NULL */
473 /* do_headers_action (win, headers_action_delete, header_view); */
474 modest_do_messages_delete (header_list, win);
477 /* Enable window dimming management */
478 gtk_tree_selection_unselect_all (sel);
479 modest_window_enable_dimming (MODEST_WINDOW(win));
481 /* FIXME: May be folder_monitor will also refilter treemode on EXPUNGE changes ? */
482 /* refresh the header view (removing marked-as-deleted) */
483 /* modest_header_view_refilter (MODEST_HEADER_VIEW(header_view)); */
485 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
486 modest_ui_actions_refresh_message_window_after_delete (MODEST_MSG_VIEW_WINDOW (win));
488 /* Get main window */
489 mgr = modest_runtime_get_window_mgr ();
490 main_window = modest_window_mgr_get_main_window (mgr);
493 /* Move cursor to next row */
496 /* Select next row */
497 if (gtk_tree_row_reference_valid (row_reference)) {
498 next_path = gtk_tree_row_reference_get_path (row_reference);
499 gtk_tree_selection_select_path (sel, next_path);
500 gtk_tree_path_free (next_path);
502 if (row_reference != NULL)
503 gtk_tree_row_reference_free (row_reference);
507 printf ("DEBUG: %s: Error: code=%d, text=%s\n", __FUNCTION__, err->code, err->message);
511 /* Update toolbar dimming state */
512 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
515 g_list_foreach (sel_list, (GFunc) gtk_tree_path_free, NULL);
516 g_list_free (sel_list);
522 g_object_unref (header_list);
528 /* delete either message or folder, based on where we are */
530 modest_ui_actions_on_delete_message_or_folder (GtkAction *action, ModestWindow *win)
532 g_return_if_fail (MODEST_IS_WINDOW(win));
534 /* Check first if the header view has the focus */
535 if (MODEST_IS_MAIN_WINDOW (win)) {
537 w = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
538 MODEST_WIDGET_TYPE_FOLDER_VIEW);
539 if (gtk_widget_is_focus (w)) {
540 modest_ui_actions_on_delete_folder (action, MODEST_MAIN_WINDOW(win));
544 modest_ui_actions_on_delete_message (action, win);
550 modest_ui_actions_on_quit (GtkAction *action, ModestWindow *win)
552 #ifdef MODEST_PLATFORM_MAEMO
553 modest_osso_save_state();
554 #endif /* MODEST_PLATFORM_MAEMO */
556 g_debug ("closing down, clearing %d item(s) from operation queue",
557 modest_mail_operation_queue_num_elements
558 (modest_runtime_get_mail_operation_queue()));
560 /* cancel all outstanding operations */
561 modest_mail_operation_queue_cancel_all
562 (modest_runtime_get_mail_operation_queue());
564 g_debug ("queue has been cleared");
566 /* note: when modest-tny-account-store is finalized,
567 it will automatically set all network connections
574 modest_ui_actions_on_close_window (GtkAction *action, ModestWindow *win)
578 g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value);
580 /* if (MODEST_IS_MSG_VIEW_WINDOW (win)) { */
581 /* gtk_widget_destroy (GTK_WIDGET (win)); */
582 /* } else if (MODEST_IS_MSG_EDIT_WINDOW (win)) { */
583 /* gboolean ret_value; */
584 /* g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value); */
585 /* } else if (MODEST_IS_WINDOW (win)) { */
586 /* gtk_widget_destroy (GTK_WIDGET (win)); */
588 /* g_return_if_reached (); */
593 modest_ui_actions_on_add_to_contacts (GtkAction *action, ModestWindow *win)
595 GtkClipboard *clipboard = NULL;
596 gchar *selection = NULL;
598 clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
599 selection = gtk_clipboard_wait_for_text (clipboard);
601 /* Question: why is the clipboard being used here?
602 * It doesn't really make a lot of sense. */
606 modest_address_book_add_address (selection);
612 modest_ui_actions_on_accounts (GtkAction *action, ModestWindow *win)
614 /* This is currently only implemented for Maemo */
615 #ifdef MODEST_PLATFORM_MAEMO /* Defined in config.h */
616 if (!modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE)) {
617 modest_run_account_setup_wizard (win);
620 /* Show the list of accounts: */
621 GtkDialog *account_win = GTK_DIALOG(modest_account_view_window_new ());
622 gtk_window_set_transient_for (GTK_WINDOW (account_win), GTK_WINDOW (win));
624 /* Don't make this a modal window, because secondary windows will then
625 * be unusable, freezing the UI: */
626 /* gtk_window_set_modal (GTK_WINDOW (account_win), TRUE); */
627 modest_maemo_show_dialog_and_forget (GTK_WINDOW (win), account_win);
630 GtkWidget *dialog, *label;
632 /* Create the widgets */
634 dialog = gtk_dialog_new_with_buttons ("Message",
636 GTK_DIALOG_DESTROY_WITH_PARENT,
640 label = gtk_label_new ("Hello World!");
642 /* Ensure that the dialog box is destroyed when the user responds. */
644 g_signal_connect_swapped (dialog, "response",
645 G_CALLBACK (gtk_widget_destroy),
648 /* Add the label, and show everything we've added to the dialog. */
650 gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox),
652 gtk_widget_show_all (dialog);
653 #endif /* MODEST_PLATFORM_MAEMO */
657 on_smtp_servers_window_hide (GtkWindow* window, gpointer user_data)
659 ModestWindow *main_window = MODEST_WINDOW (user_data);
661 /* Save any changes. */
662 modest_connection_specific_smtp_window_save_server_accounts (
663 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (window),
664 modest_window_get_active_account (main_window));
665 gtk_widget_destroy (GTK_WIDGET (window));
671 modest_ui_actions_on_smtp_servers (GtkAction *action, ModestWindow *win)
673 /* This is currently only implemented for Maemo,
674 * because it requires an API (libconic) to detect different connection
677 #ifdef MODEST_PLATFORM_MAEMO /* Defined in config.h */
679 /* Create the window if necessary: */
680 const gchar *active_account_name = modest_window_get_active_account (win);
682 /* TODO: Dim the menu item (not in the UI spec)? or show a warning,
683 * or show the default account?
684 * If we show the default account then the account name should be shown in
685 * the window when we show it. */
686 if (!active_account_name) {
687 g_warning ("%s: No account is active.", __FUNCTION__);
691 GtkWidget *specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
692 modest_connection_specific_smtp_window_fill_with_connections (
693 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (specific_window),
694 modest_runtime_get_account_mgr(),
695 active_account_name);
697 /* Show the window: */
698 gtk_window_set_transient_for (GTK_WINDOW (specific_window), GTK_WINDOW (win));
699 gtk_window_set_modal (GTK_WINDOW (specific_window), TRUE);
700 gtk_widget_show (specific_window);
702 /* Save changes when the window is hidden: */
703 g_signal_connect (specific_window, "hide",
704 G_CALLBACK (on_smtp_servers_window_hide), win);
705 #endif /* MODEST_PLATFORM_MAEMO */
709 modest_ui_actions_on_new_msg (GtkAction *action, ModestWindow *win)
711 ModestWindow *msg_win = NULL;
713 TnyFolder *folder = NULL;
714 gchar *account_name = NULL;
715 gchar *from_str = NULL;
716 /* GError *err = NULL; */
717 TnyAccount *account = NULL;
718 ModestWindowMgr *mgr;
719 gchar *signature = NULL, *blank_and_signature = NULL;
721 /* if there are no accounts yet, just show the wizard */
722 if (!modest_account_mgr_has_accounts (modest_runtime_get_account_mgr(), TRUE)) {
723 const gboolean created = modest_run_account_setup_wizard (win);
728 account_name = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr ());
730 account_name = g_strdup (modest_window_get_active_account (win));
732 g_printerr ("modest: no account found\n");
736 account = modest_tny_account_store_get_server_account (modest_runtime_get_account_store(),
738 TNY_ACCOUNT_TYPE_STORE);
740 g_printerr ("modest: failed to get tnyaccount for '%s'\n", account_name);
744 from_str = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(), account_name);
746 g_printerr ("modest: failed get from string for '%s'\n", account_name);
750 gboolean use_signature = FALSE;
751 signature = modest_account_mgr_get_signature (modest_runtime_get_account_mgr (), account_name, &use_signature);
754 blank_and_signature = g_strconcat ("\n", signature, NULL);
756 blank_and_signature = g_strdup ("");
761 msg = modest_tny_msg_new ("", from_str, "", "", "", blank_and_signature, NULL);
763 g_printerr ("modest: failed to create new msg\n");
767 folder = modest_tny_account_get_special_folder (account, TNY_FOLDER_TYPE_DRAFTS);
769 g_printerr ("modest: failed to find Drafts folder\n");
774 /* Create and register edit window */
775 /* This is destroyed by TODO. */
776 msg_win = modest_msg_edit_window_new (msg, account_name, FALSE);
777 mgr = modest_runtime_get_window_mgr ();
778 modest_window_mgr_register_window (mgr, msg_win);
781 gtk_window_set_transient_for (GTK_WINDOW (msg_win),
783 gtk_widget_show_all (GTK_WIDGET (msg_win));
786 g_free (account_name);
788 g_free (blank_and_signature);
790 g_object_unref (msg_win);
792 g_object_unref (G_OBJECT(account));
794 g_object_unref (G_OBJECT(msg));
796 g_object_unref (G_OBJECT(folder));
800 modest_ui_actions_msg_retrieval_check (ModestMailOperation *mail_op,
804 ModestMailOperationStatus status;
806 /* If there is no message or the operation was not successful */
807 status = modest_mail_operation_get_status (mail_op);
808 if (!msg || status != MODEST_MAIL_OPERATION_STATUS_SUCCESS) {
810 /* Remove the header from the preregistered uids */
811 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (),
821 open_msg_cb (ModestMailOperation *mail_op,
826 ModestWindowMgr *mgr = NULL;
827 ModestWindow *parent_win = NULL;
828 ModestWindow *win = NULL;
829 TnyFolderType folder_type = TNY_FOLDER_TYPE_UNKNOWN;
830 gchar *account = NULL;
833 /* Do nothing if there was any problem with the mail
834 operation. The error will be shown by the error_handler of
835 the mail operation */
836 if (!modest_ui_actions_msg_retrieval_check (mail_op, header, msg)) {
840 parent_win = (ModestWindow *) modest_mail_operation_get_source (mail_op);
841 folder = tny_header_get_folder (header);
843 /* Mark header as read */
844 headers_action_mark_as_read (header, MODEST_WINDOW(parent_win), NULL);
847 account = g_strdup (modest_window_get_active_account (MODEST_WINDOW (parent_win)));
849 account = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
851 /* Gets folder type (OUTBOX headers will be opened in edit window */
852 if (modest_tny_folder_is_local_folder (folder))
853 folder_type = modest_tny_folder_get_local_or_mmc_folder_type (folder);
855 /* If the header is in the drafts folder then open the editor,
856 else the message view window */
857 if ((folder_type == TNY_FOLDER_TYPE_DRAFTS) ||
858 (folder_type == TNY_FOLDER_TYPE_OUTBOX)) {
859 /* we cannot edit without a valid account... */
860 if (!modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE)) {
861 const gboolean created = modest_run_account_setup_wizard(parent_win);
865 win = modest_msg_edit_window_new (msg, account, TRUE);
868 gchar *uid = modest_tny_folder_get_header_unique_id (header);
870 if (MODEST_IS_MAIN_WINDOW (parent_win)) {
871 GtkWidget *header_view;
872 GtkTreeSelection *sel;
873 GList *sel_list = NULL;
876 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(parent_win),
877 MODEST_WIDGET_TYPE_HEADER_VIEW);
879 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
880 sel_list = gtk_tree_selection_get_selected_rows (sel, &model);
882 if (sel_list != NULL) {
883 GtkTreeRowReference *row_reference;
885 row_reference = gtk_tree_row_reference_new (model, (GtkTreePath *) sel_list->data);
886 g_list_foreach (sel_list, (GFunc) gtk_tree_path_free, NULL);
887 g_list_free (sel_list);
889 win = modest_msg_view_window_new_with_header_model (
890 msg, account, (const gchar*) uid,
891 model, row_reference);
892 gtk_tree_row_reference_free (row_reference);
894 win = modest_msg_view_window_new_for_attachment (msg, account, (const gchar*) uid);
897 win = modest_msg_view_window_new_for_attachment (msg, account, (const gchar*) uid);
902 /* Register and show new window */
904 mgr = modest_runtime_get_window_mgr ();
905 modest_window_mgr_register_window (mgr, win);
906 g_object_unref (win);
907 gtk_window_set_transient_for (GTK_WINDOW (win), GTK_WINDOW (parent_win));
908 gtk_widget_show_all (GTK_WIDGET(win));
911 /* Update toolbar dimming state */
912 if (MODEST_IS_MAIN_WINDOW (parent_win)) {
913 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (parent_win));
919 g_object_unref (parent_win);
920 g_object_unref (folder);
924 modest_ui_actions_get_msgs_full_error_handler (ModestMailOperation *mail_op,
928 GObject *win = modest_mail_operation_get_source (mail_op);
930 error = modest_mail_operation_get_error (mail_op);
931 printf ("DEBUG: %s: Error: code=%d, text=%s\n", __FUNCTION__, error->code, error->message);
933 if (error->code == MODEST_MAIL_OPERATION_ERROR_MESSAGE_SIZE_LIMIT) {
935 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
938 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
939 _("mail_ni_ui_folder_get_msg_folder_error"));
943 g_object_unref (win);
947 * This function is used by both modest_ui_actions_on_open and
948 * modest_ui_actions_on_header_activated. This way we always do the
949 * same when trying to open messages.
952 _modest_ui_actions_open (TnyList *headers, ModestWindow *win)
954 ModestWindowMgr *mgr = NULL;
955 TnyIterator *iter = NULL;
956 ModestMailOperation *mail_op = NULL;
957 TnyList *not_opened_headers = NULL;
958 TnyHeaderFlags flags = 0;
960 g_return_if_fail (headers != NULL);
962 /* Check that only one message is selected for opening */
963 if (tny_list_get_length (headers) != 1) {
964 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
965 _("mcen_ib_select_one_message"));
970 /* Look if we already have a message view for each header. If
971 true, then remove the header from the list of headers to
973 mgr = modest_runtime_get_window_mgr ();
974 iter = tny_list_create_iterator (headers);
975 not_opened_headers = tny_simple_list_new ();
977 while (!tny_iterator_is_done (iter)) {
979 ModestWindow *window = NULL;
980 TnyHeader *header = NULL;
981 gboolean found = FALSE;
983 header = TNY_HEADER (tny_iterator_get_current (iter));
985 flags = tny_header_get_flags (header);
988 found = modest_window_mgr_find_registered_header (mgr, header, &window);
990 /* Do not open again the message and present the
991 window to the user */
994 gtk_window_present (GTK_WINDOW (window));
996 /* the header has been registered already, we don't do
997 * anything but wait for the window to come up*/
998 g_debug ("header %p already registered, waiting for window", header);
1000 tny_list_append (not_opened_headers, G_OBJECT (header));
1004 g_object_unref (header);
1006 tny_iterator_next (iter);
1008 g_object_unref (iter);
1011 /* If some messages would have to be downloaded, ask the user to
1012 * make a connection. It's generally easier to do this here (in the mainloop)
1013 * than later in a thread:
1015 if (tny_list_get_length (not_opened_headers) > 0) {
1017 gboolean found = FALSE;
1019 iter = tny_list_create_iterator (not_opened_headers);
1020 while (!tny_iterator_is_done (iter) && !found) {
1021 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter));
1022 if (!(tny_header_get_flags (header) & TNY_HEADER_FLAG_CACHED))
1025 tny_iterator_next (iter);
1027 g_object_unref (header);
1029 g_object_unref (iter);
1031 if (found && !modest_platform_connect_and_wait (GTK_WINDOW (win), NULL)) {
1032 g_object_unref (not_opened_headers);
1037 /* Register the headers before actually creating the windows: */
1038 TnyIterator *iter_not_opened = tny_list_create_iterator (not_opened_headers);
1039 while (!tny_iterator_is_done (iter_not_opened)) {
1040 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter_not_opened));
1042 modest_window_mgr_register_header (mgr, header);
1043 g_object_unref (header);
1046 tny_iterator_next (iter_not_opened);
1048 g_object_unref (iter_not_opened);
1049 iter_not_opened = NULL;
1051 /* Open each message */
1052 if (tny_list_get_length (not_opened_headers) > 0) {
1053 mail_op = modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE,
1055 modest_ui_actions_get_msgs_full_error_handler,
1057 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
1058 if (tny_list_get_length (not_opened_headers) > 1) {
1059 modest_mail_operation_get_msgs_full (mail_op,
1065 TnyIterator *iter = tny_list_create_iterator (not_opened_headers);
1066 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter));
1067 modest_mail_operation_get_msg (mail_op, header, open_msg_cb, NULL);
1068 g_object_unref (header);
1069 g_object_unref (iter);
1071 g_object_unref (mail_op);
1075 if (not_opened_headers != NULL)
1076 g_object_unref (not_opened_headers);
1080 modest_ui_actions_on_open (GtkAction *action, ModestWindow *win)
1085 headers = get_selected_headers (win);
1090 _modest_ui_actions_open (headers, win);
1092 g_object_unref(headers);
1097 free_reply_forward_helper (gpointer data)
1099 ReplyForwardHelper *helper;
1101 helper = (ReplyForwardHelper *) data;
1102 g_free (helper->account_name);
1103 g_slice_free (ReplyForwardHelper, helper);
1107 reply_forward_cb (ModestMailOperation *mail_op,
1113 ReplyForwardHelper *rf_helper;
1114 ModestWindow *msg_win = NULL;
1115 ModestEditType edit_type;
1117 TnyAccount *account = NULL;
1118 ModestWindowMgr *mgr = NULL;
1119 gchar *signature = NULL;
1121 /* If there was any error. The mail operation could be NULL,
1122 this means that we already have the message downloaded and
1123 that we didn't do a mail operation to retrieve it */
1124 if (mail_op && !modest_ui_actions_msg_retrieval_check (mail_op, header, msg))
1127 g_return_if_fail (user_data != NULL);
1128 rf_helper = (ReplyForwardHelper *) user_data;
1130 from = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(),
1131 rf_helper->account_name);
1132 if (modest_account_mgr_get_bool (modest_runtime_get_account_mgr(),
1133 rf_helper->account_name,
1134 MODEST_ACCOUNT_USE_SIGNATURE, FALSE)) {
1135 signature = modest_account_mgr_get_string (modest_runtime_get_account_mgr (),
1136 rf_helper->account_name,
1137 MODEST_ACCOUNT_SIGNATURE, FALSE);
1140 /* Create reply mail */
1141 switch (rf_helper->action) {
1144 modest_tny_msg_create_reply_msg (msg, header, from, signature,
1145 rf_helper->reply_forward_type,
1146 MODEST_TNY_MSG_REPLY_MODE_SENDER);
1148 case ACTION_REPLY_TO_ALL:
1150 modest_tny_msg_create_reply_msg (msg, header, from, signature, rf_helper->reply_forward_type,
1151 MODEST_TNY_MSG_REPLY_MODE_ALL);
1152 edit_type = MODEST_EDIT_TYPE_REPLY;
1154 case ACTION_FORWARD:
1156 modest_tny_msg_create_forward_msg (msg, from, signature, rf_helper->reply_forward_type);
1157 edit_type = MODEST_EDIT_TYPE_FORWARD;
1160 g_return_if_reached ();
1167 g_printerr ("modest: failed to create message\n");
1171 account = modest_tny_account_store_get_server_account (modest_runtime_get_account_store(),
1172 rf_helper->account_name,
1173 TNY_ACCOUNT_TYPE_STORE);
1175 g_printerr ("modest: failed to get tnyaccount for '%s'\n", rf_helper->account_name);
1179 /* Create and register the windows */
1180 msg_win = modest_msg_edit_window_new (new_msg, rf_helper->account_name, FALSE);
1181 mgr = modest_runtime_get_window_mgr ();
1182 modest_window_mgr_register_window (mgr, msg_win);
1184 if (rf_helper->parent_window != NULL) {
1185 gdouble parent_zoom;
1187 parent_zoom = modest_window_get_zoom (MODEST_WINDOW (rf_helper->parent_window));
1188 modest_window_set_zoom (msg_win, parent_zoom);
1191 /* Show edit window */
1192 gtk_widget_show_all (GTK_WIDGET (msg_win));
1196 g_object_unref (msg_win);
1198 g_object_unref (G_OBJECT (new_msg));
1200 g_object_unref (G_OBJECT (account));
1201 /* g_object_unref (msg); */
1202 free_reply_forward_helper (rf_helper);
1205 /* Checks a list of headers. If any of them are not currently
1206 * downloaded (CACHED) then returns TRUE else returns FALSE.
1209 header_list_count_uncached_msgs (
1210 TnyList *header_list,
1214 gint uncached_messages = 0;
1216 iter = tny_list_create_iterator (header_list);
1217 while (!tny_iterator_is_done (iter)) {
1220 header = TNY_HEADER (tny_iterator_get_current (iter));
1222 if (!(tny_header_get_flags (header) & TNY_HEADER_FLAG_CACHED))
1223 uncached_messages ++;
1224 g_object_unref (header);
1227 tny_iterator_next (iter);
1229 g_object_unref (iter);
1231 return uncached_messages;
1234 /* Returns FALSE if the user does not want to download the
1235 * messages. Returns TRUE if the user allowed the download.
1238 connect_to_get_msg (GtkWindow *win,
1239 gint num_of_uncached_msgs)
1241 /* Allways download if we are online. */
1242 if (tny_device_is_online (modest_runtime_get_device ()))
1245 /* If offline, then ask for user permission to download the messages */
1246 GtkResponseType response;
1247 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
1248 ngettext("mcen_nc_get_msg",
1250 num_of_uncached_msgs));
1251 if (response == GTK_RESPONSE_CANCEL)
1254 return modest_platform_connect_and_wait(win, NULL);
1258 * Common code for the reply and forward actions
1261 reply_forward (ReplyForwardAction action, ModestWindow *win)
1263 ModestMailOperation *mail_op = NULL;
1264 TnyList *header_list = NULL;
1265 ReplyForwardHelper *rf_helper = NULL;
1266 guint reply_forward_type;
1267 gboolean continue_download = TRUE;
1268 gboolean do_retrieve = TRUE;
1270 g_return_if_fail (MODEST_IS_WINDOW(win));
1272 /* we need an account when editing */
1273 if (!modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE)) {
1274 const gboolean created = modest_run_account_setup_wizard (win);
1279 header_list = get_selected_headers (win);
1283 reply_forward_type =
1284 modest_conf_get_int (modest_runtime_get_conf (),
1285 (action == ACTION_FORWARD) ? MODEST_CONF_FORWARD_TYPE : MODEST_CONF_REPLY_TYPE,
1288 /* check if we need to download msg before asking about it */
1289 do_retrieve = (action == ACTION_FORWARD) ||
1290 (reply_forward_type != MODEST_TNY_MSG_REPLY_TYPE_CITE);
1293 gint num_of_unc_msgs;
1294 /* check that the messages have been previously downloaded */
1295 num_of_unc_msgs = header_list_count_uncached_msgs(
1298 /* If there are any uncached message ask the user
1299 * whether he/she wants to download them. */
1300 if (num_of_unc_msgs)
1301 continue_download = connect_to_get_msg (
1306 if (!continue_download) {
1307 g_object_unref (header_list);
1311 /* We assume that we can only select messages of the
1312 same folder and that we reply all of them from the
1313 same account. In fact the interface currently only
1314 allows single selection */
1317 rf_helper = g_slice_new0 (ReplyForwardHelper);
1318 rf_helper->reply_forward_type = reply_forward_type;
1319 rf_helper->action = action;
1320 rf_helper->account_name = g_strdup (modest_window_get_active_account (win));
1322 if ((win != NULL) && (MODEST_IS_WINDOW (win)))
1323 rf_helper->parent_window = GTK_WIDGET (win);
1324 if (!rf_helper->account_name)
1325 rf_helper->account_name =
1326 modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
1328 if (MODEST_IS_MSG_VIEW_WINDOW(win)) {
1331 /* Get header and message. Do not free them here, the
1332 reply_forward_cb must do it */
1333 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW(win));
1334 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW(win));
1335 if (!msg || !header) {
1337 g_object_unref (msg);
1338 g_printerr ("modest: no message found\n");
1341 reply_forward_cb (NULL, header, msg, rf_helper);
1344 g_object_unref (header);
1349 /* Only reply/forward to one message */
1350 iter = tny_list_create_iterator (header_list);
1351 header = TNY_HEADER (tny_iterator_get_current (iter));
1352 g_object_unref (iter);
1355 /* Retrieve messages */
1357 mail_op = modest_mail_operation_new_with_error_handling (
1358 MODEST_MAIL_OPERATION_TYPE_RECEIVE,
1360 modest_ui_actions_get_msgs_full_error_handler,
1362 modest_mail_operation_queue_add (
1363 modest_runtime_get_mail_operation_queue (), mail_op);
1365 modest_mail_operation_get_msg (mail_op,
1370 g_object_unref(mail_op);
1372 /* we put a ref here to prevent double unref as the reply
1373 * forward callback unrefs the header at its end */
1374 reply_forward_cb (NULL, header, NULL, rf_helper);
1378 g_object_unref (header);
1384 g_object_unref (header_list);
1388 modest_ui_actions_on_reply (GtkAction *action, ModestWindow *win)
1390 g_return_if_fail (MODEST_IS_WINDOW(win));
1392 reply_forward (ACTION_REPLY, win);
1396 modest_ui_actions_on_forward (GtkAction *action, ModestWindow *win)
1398 g_return_if_fail (MODEST_IS_WINDOW(win));
1400 reply_forward (ACTION_FORWARD, win);
1404 modest_ui_actions_on_reply_all (GtkAction *action, ModestWindow *win)
1406 g_return_if_fail (MODEST_IS_WINDOW(win));
1408 reply_forward (ACTION_REPLY_TO_ALL, win);
1412 modest_ui_actions_on_next (GtkAction *action,
1413 ModestWindow *window)
1415 if (MODEST_IS_MAIN_WINDOW (window)) {
1416 GtkWidget *header_view;
1418 header_view = modest_main_window_get_child_widget (
1419 MODEST_MAIN_WINDOW(window),
1420 MODEST_WIDGET_TYPE_HEADER_VIEW);
1424 modest_header_view_select_next (
1425 MODEST_HEADER_VIEW(header_view));
1426 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
1427 modest_msg_view_window_select_next_message (
1428 MODEST_MSG_VIEW_WINDOW (window));
1430 g_return_if_reached ();
1435 modest_ui_actions_on_prev (GtkAction *action,
1436 ModestWindow *window)
1438 g_return_if_fail (MODEST_IS_WINDOW(window));
1440 if (MODEST_IS_MAIN_WINDOW (window)) {
1441 GtkWidget *header_view;
1442 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
1443 MODEST_WIDGET_TYPE_HEADER_VIEW);
1447 modest_header_view_select_prev (MODEST_HEADER_VIEW(header_view));
1448 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
1449 modest_msg_view_window_select_previous_message (MODEST_MSG_VIEW_WINDOW (window));
1451 g_return_if_reached ();
1456 modest_ui_actions_on_sort (GtkAction *action,
1457 ModestWindow *window)
1459 g_return_if_fail (MODEST_IS_WINDOW(window));
1461 if (MODEST_IS_MAIN_WINDOW (window)) {
1462 GtkWidget *header_view;
1463 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
1464 MODEST_WIDGET_TYPE_HEADER_VIEW);
1466 modest_platform_information_banner (NULL, NULL, _CS("ckdg_ib_nothing_to_sort"));
1471 /* Show sorting dialog */
1472 modest_platform_run_sort_dialog (GTK_WINDOW (window), MODEST_SORT_HEADERS);
1477 new_messages_arrived (ModestMailOperation *self,
1481 ModestMainWindow *win = NULL;
1482 GtkWidget *folder_view = NULL;
1483 TnyFolderStore *folder = NULL;
1484 gboolean folder_empty = FALSE;
1486 g_return_if_fail (MODEST_IS_MAIN_WINDOW (user_data));
1487 win = MODEST_MAIN_WINDOW (user_data);
1489 /* Set contents style of headers view */
1490 if (modest_main_window_get_contents_style (win) == MODEST_MAIN_WINDOW_CONTENTS_STYLE_EMPTY) {
1491 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
1492 MODEST_WIDGET_TYPE_FOLDER_VIEW);
1493 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
1496 folder_empty = (tny_folder_get_all_count (TNY_FOLDER (folder)) == 0);
1499 modest_main_window_set_contents_style (win,
1500 MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS);
1503 /* Notify new messages have been downloaded */
1504 if (new_messages > 0)
1505 modest_platform_on_new_msg ();
1509 * This function performs the send & receive required actions. The
1510 * window is used to create the mail operation. Typically it should
1511 * always be the main window, but we pass it as argument in order to
1515 modest_ui_actions_do_send_receive (const gchar *account_name, ModestWindow *win)
1517 gchar *acc_name = NULL;
1518 ModestMailOperation *mail_op;
1520 /* If no account name was provided then get the current account, and if
1521 there is no current account then pick the default one: */
1522 if (!account_name) {
1523 acc_name = g_strdup (modest_window_get_active_account(win));
1525 acc_name = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
1527 g_printerr ("modest: cannot get default account\n");
1531 acc_name = g_strdup (account_name);
1534 /* Set send/receive operation in progress */
1535 modest_main_window_notify_send_receive_initied (MODEST_MAIN_WINDOW(win));
1537 mail_op = modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE,
1539 modest_ui_actions_send_receive_error_handler,
1542 g_signal_connect (G_OBJECT(mail_op), "progress-changed",
1543 G_CALLBACK (_on_send_receive_progress_changed),
1546 /* Send & receive. */
1547 /* TODO: The spec wants us to first do any pending deletions, before receiving. */
1548 /* Receive and then send. The operation is tagged initially as
1549 a receive operation because the account update performs a
1550 receive and then a send. The operation changes its type
1551 internally, so the progress objects will receive the proper
1552 progress information */
1553 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
1554 modest_mail_operation_update_account (mail_op, acc_name, new_messages_arrived, win);
1555 g_object_unref (G_OBJECT (mail_op));
1563 modest_ui_actions_do_cancel_send (const gchar *account_name,
1566 TnyTransportAccount *transport_account;
1567 TnySendQueue *send_queue = NULL;
1568 GError *error = NULL;
1570 /* Get transport account */
1572 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
1573 (modest_runtime_get_account_store(),
1575 TNY_ACCOUNT_TYPE_TRANSPORT));
1576 if (!transport_account) {
1577 g_printerr ("modest: no transport account found for '%s'\n", account_name);
1582 send_queue = TNY_SEND_QUEUE (modest_runtime_get_send_queue (transport_account));
1583 if (!TNY_IS_SEND_QUEUE(send_queue)) {
1584 g_set_error (&error, MODEST_MAIL_OPERATION_ERROR,
1585 MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND,
1586 "modest: could not find send queue for account\n");
1588 /* Keeep messages in outbox folder */
1589 tny_send_queue_cancel (send_queue, FALSE, &error);
1593 if (transport_account != NULL)
1594 g_object_unref (G_OBJECT (transport_account));
1598 modest_ui_actions_cancel_send_all (ModestWindow *win)
1600 GSList *account_names, *iter;
1602 account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
1605 iter = account_names;
1607 modest_ui_actions_do_cancel_send ((const char*) iter->data, win);
1608 iter = g_slist_next (iter);
1611 modest_account_mgr_free_account_names (account_names);
1612 account_names = NULL;
1616 modest_ui_actions_cancel_send (GtkAction *action, ModestWindow *win)
1619 /* Check if accounts exist */
1620 gboolean accounts_exist =
1621 modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
1623 /* If not, allow the user to create an account before trying to send/receive. */
1624 if (!accounts_exist)
1625 modest_ui_actions_on_accounts (NULL, win);
1627 /* Cancel all sending operaitons */
1628 modest_ui_actions_cancel_send_all (win);
1632 * Refreshes all accounts. This function will be used by automatic
1636 modest_ui_actions_do_send_receive_all (ModestWindow *win)
1638 GSList *account_names, *iter;
1640 account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
1643 iter = account_names;
1645 modest_ui_actions_do_send_receive ((const char*) iter->data, win);
1646 iter = g_slist_next (iter);
1649 modest_account_mgr_free_account_names (account_names);
1650 account_names = NULL;
1654 modest_do_refresh_current_folder(ModestWindow *win)
1656 /* Refresh currently selected folder. Note that if we only
1657 want to retreive the headers, then the refresh only will
1658 invoke a poke_status over all folders, i.e., only the
1659 total/unread count will be updated */
1660 if (MODEST_IS_MAIN_WINDOW (win)) {
1661 GtkWidget *header_view, *folder_view;
1662 TnyFolderStore *folder_store;
1664 /* Get folder and header view */
1666 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
1667 MODEST_WIDGET_TYPE_FOLDER_VIEW);
1671 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
1673 if (folder_store && TNY_IS_FOLDER (folder_store)) {
1675 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
1676 MODEST_WIDGET_TYPE_HEADER_VIEW);
1678 /* We do not need to set the contents style
1679 because it hasn't changed. We also do not
1680 need to save the widget status. Just force
1682 modest_header_view_set_folder (MODEST_HEADER_VIEW(header_view),
1683 TNY_FOLDER (folder_store),
1684 folder_refreshed_cb,
1685 MODEST_MAIN_WINDOW (win));
1689 g_object_unref (folder_store);
1695 * Handler of the click on Send&Receive button in the main toolbar
1698 modest_ui_actions_on_send_receive (GtkAction *action, ModestWindow *win)
1700 /* Check if accounts exist */
1701 gboolean accounts_exist =
1702 modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
1704 /* If not, allow the user to create an account before trying to send/receive. */
1705 if (!accounts_exist)
1706 modest_ui_actions_on_accounts (NULL, win);
1708 modest_do_refresh_current_folder (win);
1710 /* Refresh the active account */
1711 modest_ui_actions_do_send_receive (NULL, win);
1716 modest_ui_actions_toggle_header_list_view (GtkAction *action, ModestMainWindow *main_window)
1719 GtkWidget *header_view;
1721 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1723 header_view = modest_main_window_get_child_widget (main_window,
1724 MODEST_WIDGET_TYPE_HEADER_VIEW);
1728 conf = modest_runtime_get_conf ();
1730 /* what is saved/restored is depending on the style; thus; we save with
1731 * old style, then update the style, and restore for this new style
1733 modest_widget_memory_save (conf, G_OBJECT(header_view), MODEST_CONF_HEADER_VIEW_KEY);
1735 if (modest_header_view_get_style
1736 (MODEST_HEADER_VIEW(header_view)) == MODEST_HEADER_VIEW_STYLE_DETAILS)
1737 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
1738 MODEST_HEADER_VIEW_STYLE_TWOLINES);
1740 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
1741 MODEST_HEADER_VIEW_STYLE_DETAILS);
1743 modest_widget_memory_restore (conf, G_OBJECT(header_view),
1744 MODEST_CONF_HEADER_VIEW_KEY);
1749 modest_ui_actions_on_header_selected (ModestHeaderView *header_view,
1751 ModestMainWindow *main_window)
1753 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1754 g_return_if_fail (MODEST_IS_HEADER_VIEW (header_view));
1756 /* in the case the folder is empty, show the empty folder message and focus
1758 if (!header && gtk_widget_is_focus (GTK_WIDGET (header_view))) {
1759 if (modest_header_view_is_empty (header_view)) {
1760 TnyFolder *folder = modest_header_view_get_folder (header_view);
1761 GtkWidget *folder_view =
1762 modest_main_window_get_child_widget (main_window,
1763 MODEST_WIDGET_TYPE_FOLDER_VIEW);
1765 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view), folder, FALSE);
1766 gtk_widget_grab_focus (GTK_WIDGET (folder_view));
1770 /* If no header has been selected then exit */
1775 if (!gtk_widget_is_focus (GTK_WIDGET(header_view)))
1776 gtk_widget_grab_focus (GTK_WIDGET(header_view));
1778 /* Update toolbar dimming state */
1779 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
1783 modest_ui_actions_on_header_activated (ModestHeaderView *header_view,
1785 ModestMainWindow *main_window)
1789 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1795 /* headers = tny_simple_list_new (); */
1796 /* tny_list_prepend (headers, G_OBJECT (header)); */
1797 headers = modest_header_view_get_selected_headers (header_view);
1799 _modest_ui_actions_open (headers, MODEST_WINDOW (main_window));
1801 g_object_unref (headers);
1805 set_active_account_from_tny_account (TnyAccount *account,
1806 ModestWindow *window)
1808 const gchar *server_acc_name = tny_account_get_id (account);
1810 /* We need the TnyAccount provided by the
1811 account store because that is the one that
1812 knows the name of the Modest account */
1813 TnyAccount *modest_server_account = modest_server_account =
1814 modest_tny_account_store_get_tny_account_by (modest_runtime_get_account_store (),
1815 MODEST_TNY_ACCOUNT_STORE_QUERY_ID,
1818 const gchar *modest_acc_name =
1819 modest_tny_account_get_parent_modest_account_name_for_server_account (modest_server_account);
1820 modest_window_set_active_account (window, modest_acc_name);
1821 g_object_unref (modest_server_account);
1826 folder_refreshed_cb (ModestMailOperation *mail_op,
1830 ModestMainWindow *win = NULL;
1831 GtkWidget *header_view;
1832 TnyFolder *current_folder;
1833 gboolean folder_empty = FALSE;
1834 gboolean all_marked_as_deleted = FALSE;
1836 g_return_if_fail (TNY_IS_FOLDER (folder));
1838 win = MODEST_MAIN_WINDOW (user_data);
1840 modest_main_window_get_child_widget(win, MODEST_WIDGET_TYPE_HEADER_VIEW);
1843 current_folder = modest_header_view_get_folder (MODEST_HEADER_VIEW (header_view));
1844 if (current_folder != NULL && folder != current_folder) {
1849 /* Check if folder is empty and set headers view contents style */
1850 folder_empty = (tny_folder_get_all_count (folder) == 0);
1851 all_marked_as_deleted = modest_header_view_is_empty (MODEST_HEADER_VIEW(header_view));
1852 folder_empty = folder_empty || all_marked_as_deleted ;
1855 printf ("DEBUG: %s: tny_folder_get_all_count() returned 0.\n", __FUNCTION__);
1856 modest_main_window_set_contents_style (win,
1857 MODEST_MAIN_WINDOW_CONTENTS_STYLE_EMPTY);
1859 printf ("DEBUG: %s: tny_folder_get_all_count() returned >0.\n", __FUNCTION__);
1864 modest_ui_actions_on_folder_selection_changed (ModestFolderView *folder_view,
1865 TnyFolderStore *folder_store,
1867 ModestMainWindow *main_window)
1870 GtkWidget *header_view;
1872 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1874 header_view = modest_main_window_get_child_widget(main_window,
1875 MODEST_WIDGET_TYPE_HEADER_VIEW);
1879 conf = modest_runtime_get_conf ();
1881 if (TNY_IS_ACCOUNT (folder_store)) {
1883 /* Update active account */
1884 set_active_account_from_tny_account (TNY_ACCOUNT (folder_store), MODEST_WINDOW (main_window));
1885 /* Show account details */
1886 modest_main_window_set_contents_style (main_window, MODEST_MAIN_WINDOW_CONTENTS_STYLE_DETAILS);
1889 if (TNY_IS_FOLDER (folder_store) && selected) {
1891 /* Update the active account */
1892 TnyAccount *account = modest_tny_folder_get_account (TNY_FOLDER (folder_store));
1894 set_active_account_from_tny_account (account, MODEST_WINDOW (main_window));
1895 g_object_unref (account);
1899 /* Set the header style by default, it could
1900 be changed later by the refresh callback to
1902 modest_main_window_set_contents_style (main_window,
1903 MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS);
1905 /* Set folder on header view. This function
1906 will call tny_folder_refresh_async so we
1907 pass a callback that will be called when
1908 finished. We use that callback to set the
1909 empty view if there are no messages */
1910 modest_header_view_set_folder (MODEST_HEADER_VIEW(header_view),
1911 TNY_FOLDER (folder_store),
1912 folder_refreshed_cb,
1915 /* Restore configuration. We need to do this
1916 *after* the set_folder because the widget
1917 memory asks the header view about its
1919 modest_widget_memory_restore (modest_runtime_get_conf (),
1920 G_OBJECT(header_view),
1921 MODEST_CONF_HEADER_VIEW_KEY);
1923 /* Update the active account */
1924 modest_window_set_active_account (MODEST_WINDOW (main_window), NULL);
1925 /* Save only if we're seeing headers */
1926 if (modest_main_window_get_contents_style (main_window) ==
1927 MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS)
1928 modest_widget_memory_save (conf, G_OBJECT (header_view),
1929 MODEST_CONF_HEADER_VIEW_KEY);
1930 modest_header_view_clear (MODEST_HEADER_VIEW(header_view));
1934 /* Update toolbar dimming state */
1935 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
1939 modest_ui_actions_on_item_not_found (ModestHeaderView *header_view,ModestItemType type,
1946 item = (type == MODEST_ITEM_TYPE_FOLDER) ? "folder" : "message";
1948 online = tny_device_is_online (modest_runtime_get_device());
1951 /* already online -- the item is simply not there... */
1952 dialog = gtk_message_dialog_new (GTK_WINDOW (win),
1954 GTK_MESSAGE_WARNING,
1956 _("The %s you selected cannot be found"),
1958 gtk_dialog_add_button (GTK_DIALOG (dialog),_("mcen_bd_dialog_ok"), GTK_RESPONSE_ACCEPT);
1959 gtk_dialog_run (GTK_DIALOG(dialog));
1961 dialog = gtk_dialog_new_with_buttons (_("Connection requested"),
1964 _("mcen_bd_dialog_cancel"),
1965 GTK_RESPONSE_REJECT,
1966 _("mcen_bd_dialog_ok"),
1967 GTK_RESPONSE_ACCEPT,
1969 txt = g_strdup_printf (_("This %s is not available in offline mode.\n"
1970 "Do you want to get online?"), item);
1971 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
1972 gtk_label_new (txt), FALSE, FALSE, 0);
1973 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
1976 gtk_window_set_default_size (GTK_WINDOW(dialog), 300, 300);
1977 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
1978 /* TODO: Comment about why is this commented out: */
1979 /* modest_platform_connect_and_wait (); */
1982 gtk_widget_destroy (dialog);
1986 modest_ui_actions_on_msg_link_hover (ModestMsgView *msgview, const gchar* link,
1989 /* g_message ("%s %s", __FUNCTION__, link); */
1994 modest_ui_actions_on_msg_link_clicked (ModestMsgView *msgview, const gchar* link,
1997 modest_platform_activate_uri (link);
2001 modest_ui_actions_on_msg_link_contextual (ModestMsgView *msgview, const gchar* link,
2004 modest_platform_show_uri_popup (link);
2008 modest_ui_actions_on_msg_attachment_clicked (ModestMsgView *msgview, TnyMimePart *mime_part,
2011 modest_msg_view_window_view_attachment (MODEST_MSG_VIEW_WINDOW (win), mime_part);
2015 modest_ui_actions_on_msg_recpt_activated (ModestMsgView *msgview,
2016 const gchar *address,
2019 /* g_message ("%s %s", __FUNCTION__, address); */
2023 modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edit_window)
2025 TnyTransportAccount *transport_account;
2026 ModestMailOperation *mail_operation;
2028 gchar *account_name, *from;
2029 ModestAccountMgr *account_mgr;
2030 gchar *info_text = NULL;
2032 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window));
2034 data = modest_msg_edit_window_get_msg_data (edit_window);
2036 account_mgr = modest_runtime_get_account_mgr();
2037 account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
2039 account_name = modest_account_mgr_get_default_account (account_mgr);
2040 if (!account_name) {
2041 g_printerr ("modest: no account found\n");
2042 modest_msg_edit_window_free_msg_data (edit_window, data);
2046 if (!strcmp (account_name, MODEST_LOCAL_FOLDERS_ACCOUNT_ID)) {
2047 account_name = g_strdup (data->account_name);
2051 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
2052 (modest_runtime_get_account_store(),
2054 TNY_ACCOUNT_TYPE_TRANSPORT));
2055 if (!transport_account) {
2056 g_printerr ("modest: no transport account found for '%s'\n", account_name);
2057 g_free (account_name);
2058 modest_msg_edit_window_free_msg_data (edit_window, data);
2061 from = modest_account_mgr_get_from_string (account_mgr, account_name);
2063 /* Create the mail operation */
2064 mail_operation = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_INFO, G_OBJECT(edit_window));
2065 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
2067 modest_mail_operation_save_to_drafts (mail_operation,
2079 data->priority_flags);
2082 g_free (account_name);
2083 g_object_unref (G_OBJECT (transport_account));
2084 g_object_unref (G_OBJECT (mail_operation));
2086 modest_msg_edit_window_free_msg_data (edit_window, data);
2088 info_text = g_strdup_printf (_("mail_va_saved_to_drafts"), _("mcen_me_folder_drafts"));
2089 modest_platform_information_banner (NULL, NULL, info_text);
2093 /* For instance, when clicking the Send toolbar button when editing a message: */
2095 modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
2097 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window));
2099 if (!modest_msg_edit_window_check_names (edit_window, TRUE))
2102 /* Offer the connection dialog, if necessary: */
2103 if (!modest_platform_connect_and_wait (GTK_WINDOW (edit_window), NULL))
2106 /* FIXME: Code added just for testing. The final version will
2107 use the send queue provided by tinymail and some
2109 ModestAccountMgr *account_mgr = modest_runtime_get_account_mgr();
2110 gchar *account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
2112 account_name = modest_account_mgr_get_default_account (account_mgr);
2114 if (!account_name) {
2115 /* Run account setup wizard */
2116 const gboolean created = modest_run_account_setup_wizard(MODEST_WINDOW(edit_window));
2121 MsgData *data = modest_msg_edit_window_get_msg_data (edit_window);
2123 if (!strcmp (account_name, MODEST_LOCAL_FOLDERS_ACCOUNT_ID)) {
2124 account_name = g_strdup (data->account_name);
2127 /* Get the currently-active transport account for this modest account: */
2128 TnyTransportAccount *transport_account =
2129 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_transport_account_for_open_connection
2130 (modest_runtime_get_account_store(),
2132 if (!transport_account) {
2133 /* Run account setup wizard */
2134 const gboolean created = modest_run_account_setup_wizard(MODEST_WINDOW(edit_window));
2139 gchar *from = modest_account_mgr_get_from_string (account_mgr, account_name);
2141 /* Create the mail operation */
2142 ModestMailOperation *mail_operation = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_SEND, G_OBJECT(edit_window));
2143 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
2145 modest_mail_operation_send_new_mail (mail_operation,
2156 data->priority_flags);
2160 g_free (account_name);
2161 g_object_unref (G_OBJECT (transport_account));
2162 g_object_unref (G_OBJECT (mail_operation));
2164 modest_msg_edit_window_free_msg_data (edit_window, data);
2165 modest_msg_edit_window_set_sent (edit_window, TRUE);
2167 /* Save settings and close the window: */
2168 modest_ui_actions_on_close_window (NULL, MODEST_WINDOW (edit_window));
2172 modest_ui_actions_on_toggle_bold (GtkToggleAction *action,
2173 ModestMsgEditWindow *window)
2175 ModestMsgEditFormatState *format_state = NULL;
2177 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2178 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
2180 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2183 format_state = modest_msg_edit_window_get_format_state (window);
2184 g_return_if_fail (format_state != NULL);
2186 format_state->bold = gtk_toggle_action_get_active (action);
2187 modest_msg_edit_window_set_format_state (window, format_state);
2188 g_free (format_state);
2193 modest_ui_actions_on_toggle_italics (GtkToggleAction *action,
2194 ModestMsgEditWindow *window)
2196 ModestMsgEditFormatState *format_state = NULL;
2198 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2199 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
2201 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2204 format_state = modest_msg_edit_window_get_format_state (window);
2205 g_return_if_fail (format_state != NULL);
2207 format_state->italics = gtk_toggle_action_get_active (action);
2208 modest_msg_edit_window_set_format_state (window, format_state);
2209 g_free (format_state);
2214 modest_ui_actions_on_toggle_bullets (GtkToggleAction *action,
2215 ModestMsgEditWindow *window)
2217 ModestMsgEditFormatState *format_state = NULL;
2219 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2220 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
2222 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2225 format_state = modest_msg_edit_window_get_format_state (window);
2226 g_return_if_fail (format_state != NULL);
2228 format_state->bullet = gtk_toggle_action_get_active (action);
2229 modest_msg_edit_window_set_format_state (window, format_state);
2230 g_free (format_state);
2235 modest_ui_actions_on_change_justify (GtkRadioAction *action,
2236 GtkRadioAction *selected,
2237 ModestMsgEditWindow *window)
2239 ModestMsgEditFormatState *format_state = NULL;
2240 GtkJustification value;
2242 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2244 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2247 value = gtk_radio_action_get_current_value (selected);
2249 format_state = modest_msg_edit_window_get_format_state (window);
2250 g_return_if_fail (format_state != NULL);
2252 format_state->justification = value;
2253 modest_msg_edit_window_set_format_state (window, format_state);
2254 g_free (format_state);
2258 modest_ui_actions_on_select_editor_color (GtkAction *action,
2259 ModestMsgEditWindow *window)
2261 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2262 g_return_if_fail (GTK_IS_ACTION (action));
2264 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2267 modest_msg_edit_window_select_color (window);
2271 modest_ui_actions_on_select_editor_background_color (GtkAction *action,
2272 ModestMsgEditWindow *window)
2274 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2275 g_return_if_fail (GTK_IS_ACTION (action));
2277 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2280 modest_msg_edit_window_select_background_color (window);
2284 modest_ui_actions_on_insert_image (GtkAction *action,
2285 ModestMsgEditWindow *window)
2287 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2288 g_return_if_fail (GTK_IS_ACTION (action));
2290 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2293 modest_msg_edit_window_insert_image (window);
2297 modest_ui_actions_on_attach_file (GtkAction *action,
2298 ModestMsgEditWindow *window)
2300 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2301 g_return_if_fail (GTK_IS_ACTION (action));
2303 modest_msg_edit_window_offer_attach_file (window);
2307 modest_ui_actions_on_remove_attachments (GtkAction *action,
2308 ModestMsgEditWindow *window)
2310 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2311 g_return_if_fail (GTK_IS_ACTION (action));
2313 modest_msg_edit_window_remove_attachments (window, NULL);
2317 modest_ui_actions_new_folder_error_handler (ModestMailOperation *mail_op,
2320 ModestMainWindow *window = MODEST_MAIN_WINDOW (user_data);
2321 const GError *error = modest_mail_operation_get_error (mail_op);
2325 modest_platform_information_banner (GTK_WIDGET (window), NULL,
2326 modest_mail_operation_get_error (mail_op)->message);
2331 modest_ui_actions_create_folder(GtkWidget *parent_window,
2332 GtkWidget *folder_view)
2334 TnyFolderStore *parent_folder;
2336 parent_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
2338 if (parent_folder) {
2339 gboolean finished = FALSE;
2341 gchar *folder_name = NULL, *suggested_name = NULL;
2342 const gchar *proto_str = NULL;
2343 TnyAccount *account;
2345 if (TNY_IS_ACCOUNT (parent_folder))
2346 account = g_object_ref (parent_folder);
2348 account = tny_folder_get_account (TNY_FOLDER (parent_folder));
2349 proto_str = tny_account_get_proto (TNY_ACCOUNT (account));
2351 if (proto_str && modest_protocol_info_get_transport_store_protocol (proto_str) ==
2352 MODEST_PROTOCOL_STORE_POP) {
2354 hildon_banner_show_information (NULL, NULL, _("mail_in_ui_folder_create_error"));
2356 g_object_unref (account);
2358 /* Run the new folder dialog */
2360 result = modest_platform_run_new_folder_dialog (GTK_WINDOW (parent_window),
2365 g_free (suggested_name);
2366 suggested_name = NULL;
2368 if (result == GTK_RESPONSE_REJECT) {
2371 ModestMailOperation *mail_op;
2372 TnyFolder *new_folder = NULL;
2374 mail_op = modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_INFO,
2375 G_OBJECT(parent_window),
2376 modest_ui_actions_new_folder_error_handler,
2379 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
2381 new_folder = modest_mail_operation_create_folder (mail_op,
2383 (const gchar *) folder_name);
2385 modest_folder_view_select_folder (MODEST_FOLDER_VIEW(folder_view),
2388 g_object_unref (new_folder);
2391 g_object_unref (mail_op);
2394 suggested_name = folder_name;
2398 g_object_unref (parent_folder);
2403 modest_ui_actions_on_new_folder (GtkAction *action, ModestMainWindow *main_window)
2405 GtkWidget *folder_view;
2407 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2409 folder_view = modest_main_window_get_child_widget (main_window,
2410 MODEST_WIDGET_TYPE_FOLDER_VIEW);
2414 modest_ui_actions_create_folder (GTK_WIDGET (main_window), folder_view);
2418 modest_ui_actions_rename_folder_error_handler (ModestMailOperation *mail_op,
2421 ModestMainWindow *window = MODEST_MAIN_WINDOW (user_data);
2422 const GError *error = NULL;
2423 const gchar *message = NULL;
2425 /* Get error message */
2426 error = modest_mail_operation_get_error (mail_op);
2428 g_return_if_reached ();
2430 switch (error->code) {
2431 case MODEST_MAIL_OPERATION_ERROR_FOLDER_EXISTS:
2432 message = _CS("ckdg_ib_folder_already_exists");
2435 g_return_if_reached ();
2438 modest_platform_information_banner (GTK_WIDGET (window), NULL, message);
2442 modest_ui_actions_on_rename_folder (GtkAction *action,
2443 ModestMainWindow *main_window)
2445 TnyFolderStore *folder;
2446 GtkWidget *folder_view;
2447 GtkWidget *header_view;
2449 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2451 folder_view = modest_main_window_get_child_widget (main_window,
2452 MODEST_WIDGET_TYPE_FOLDER_VIEW);
2456 header_view = modest_main_window_get_child_widget (main_window,
2457 MODEST_WIDGET_TYPE_HEADER_VIEW);
2462 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
2467 if (TNY_IS_FOLDER (folder)) {
2470 const gchar *current_name;
2471 TnyFolderStore *parent;
2472 gboolean do_rename = TRUE;
2474 current_name = tny_folder_get_name (TNY_FOLDER (folder));
2475 parent = tny_folder_get_folder_store (TNY_FOLDER (folder));
2476 response = modest_platform_run_rename_folder_dialog (GTK_WINDOW (main_window),
2477 parent, current_name,
2479 g_object_unref (parent);
2481 if (response != GTK_RESPONSE_ACCEPT || strlen (folder_name) == 0) {
2483 } else if (modest_platform_is_network_folderstore(folder) &&
2484 !tny_device_is_online (modest_runtime_get_device())) {
2485 TnyAccount *account = tny_folder_get_account(TNY_FOLDER(folder));
2486 do_rename = modest_platform_connect_and_wait(GTK_WINDOW(main_window), account);
2487 g_object_unref(account);
2491 ModestMailOperation *mail_op;
2492 GtkTreeSelection *sel = NULL;
2495 modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_INFO,
2496 G_OBJECT(main_window),
2497 modest_ui_actions_rename_folder_error_handler,
2500 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
2503 /* Clear the headers view */
2504 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_view));
2505 gtk_tree_selection_unselect_all (sel);
2507 /* Select *after* the changes */
2508 modest_folder_view_select_folder (MODEST_FOLDER_VIEW(folder_view),
2509 TNY_FOLDER(folder), TRUE);
2511 modest_mail_operation_rename_folder (mail_op,
2512 TNY_FOLDER (folder),
2513 (const gchar *) folder_name);
2515 g_object_unref (mail_op);
2516 g_free (folder_name);
2519 g_object_unref (folder);
2523 modest_ui_actions_delete_folder_error_handler (ModestMailOperation *mail_op,
2526 GObject *win = modest_mail_operation_get_source (mail_op);
2528 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
2529 _("mail_in_ui_folder_delete_error"));
2530 g_object_unref (win);
2534 delete_folder (ModestMainWindow *main_window, gboolean move_to_trash)
2536 TnyFolderStore *folder;
2537 GtkWidget *folder_view;
2540 gboolean do_delete = TRUE;
2542 g_return_if_fail (MODEST_IS_MAIN_WINDOW (main_window));
2544 folder_view = modest_main_window_get_child_widget (main_window,
2545 MODEST_WIDGET_TYPE_FOLDER_VIEW);
2549 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
2551 /* Show an error if it's an account */
2552 if (!TNY_IS_FOLDER (folder)) {
2553 modest_platform_run_information_dialog (GTK_WINDOW (main_window),
2554 _("mail_in_ui_folder_delete_error"));
2555 g_object_unref (G_OBJECT (folder));
2560 message = g_strdup_printf (_("mcen_nc_delete_folder_text"),
2561 tny_folder_get_name (TNY_FOLDER (folder)));
2562 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (main_window),
2563 (const gchar *) message);
2566 if (response != GTK_RESPONSE_OK) {
2568 } else if (modest_platform_is_network_folderstore(folder) &&
2569 !tny_device_is_online (modest_runtime_get_device())) {
2570 TnyAccount *account = tny_folder_get_account(TNY_FOLDER(folder));
2571 do_delete = modest_platform_connect_and_wait(GTK_WINDOW(main_window), account);
2572 g_object_unref(account);
2576 ModestMailOperation *mail_op;
2577 GtkTreeSelection *sel;
2579 /* Unselect the folder before deleting it to free the headers */
2580 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_view));
2581 gtk_tree_selection_unselect_all (sel);
2583 /* Create the mail operation */
2585 modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_DELETE,
2586 G_OBJECT(main_window),
2587 modest_ui_actions_delete_folder_error_handler,
2590 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
2592 modest_mail_operation_remove_folder (mail_op, TNY_FOLDER (folder), move_to_trash);
2593 g_object_unref (G_OBJECT (mail_op));
2596 g_object_unref (G_OBJECT (folder));
2600 modest_ui_actions_on_delete_folder (GtkAction *action,
2601 ModestMainWindow *main_window)
2603 GtkWidget *folder_view;
2604 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2606 delete_folder (main_window, FALSE);
2607 folder_view = modest_main_window_get_child_widget (main_window,
2608 MODEST_WIDGET_TYPE_FOLDER_VIEW);
2611 modest_folder_view_select_first_inbox_or_local (MODEST_FOLDER_VIEW (folder_view));
2615 modest_ui_actions_on_move_folder_to_trash_folder (GtkAction *action, ModestMainWindow *main_window)
2617 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2619 delete_folder (main_window, TRUE);
2624 show_error (GtkWidget *parent_widget, const gchar* text)
2626 hildon_banner_show_information(parent_widget, NULL, text);
2629 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_window, text)); */
2631 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
2638 gtk_dialog_run (dialog);
2639 gtk_widget_destroy (GTK_WIDGET (dialog));
2644 modest_ui_actions_on_password_requested (TnyAccountStore *account_store,
2645 const gchar* server_account_name,
2650 ModestMainWindow *main_window)
2652 g_return_if_fail(server_account_name);
2653 /* printf("DEBUG: %s: server_account_name=%s\n", __FUNCTION__, server_account_name); */
2655 /* Initalize output parameters: */
2662 #ifdef MODEST_PLATFORM_MAEMO
2663 /* Maemo uses a different (awkward) button order,
2664 * It should probably just use gtk_alternative_dialog_button_order ().
2666 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
2669 _("mcen_bd_dialog_ok"),
2670 GTK_RESPONSE_ACCEPT,
2671 _("mcen_bd_dialog_cancel"),
2672 GTK_RESPONSE_REJECT,
2675 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
2679 GTK_RESPONSE_REJECT,
2681 GTK_RESPONSE_ACCEPT,
2683 #endif /* MODEST_PLATFORM_MAEMO */
2685 gtk_window_set_transient_for (GTK_WINDOW(dialog), GTK_WINDOW(main_window));
2687 gchar *server_name = modest_server_account_get_hostname (
2688 modest_runtime_get_account_mgr(), server_account_name);
2689 if (!server_name) {/* This happened once, though I don't know why. murrayc. */
2690 g_warning("%s: Could not get server name for server account '%s'", __FUNCTION__, server_account_name);
2695 /* This causes a warning because the logical ID has no %s in it,
2696 * though the translation does, but there is not much we can do about that: */
2697 gchar *txt = g_strdup_printf (_("mail_ia_password_info"), server_name);
2698 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), gtk_label_new(txt),
2701 g_free (server_name);
2705 gchar *initial_username = modest_server_account_get_username (
2706 modest_runtime_get_account_mgr(), server_account_name);
2708 GtkWidget *entry_username = gtk_entry_new ();
2709 if (initial_username)
2710 gtk_entry_set_text (GTK_ENTRY (entry_username), initial_username);
2711 /* Dim this if a connection has ever succeeded with this username,
2712 * as per the UI spec: */
2713 const gboolean username_known =
2714 modest_server_account_get_username_has_succeeded(
2715 modest_runtime_get_account_mgr(), server_account_name);
2716 gtk_widget_set_sensitive (entry_username, !username_known);
2718 #ifdef MODEST_PLATFORM_MAEMO
2719 /* Auto-capitalization is the default, so let's turn it off: */
2720 hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_username), HILDON_GTK_INPUT_MODE_FULL);
2722 /* Create a size group to be used by all captions.
2723 * Note that HildonCaption does not create a default size group if we do not specify one.
2724 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
2725 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
2727 GtkWidget *caption = hildon_caption_new (sizegroup,
2728 _("mail_fi_username"), entry_username, NULL, HILDON_CAPTION_MANDATORY);
2729 gtk_widget_show (entry_username);
2730 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
2731 FALSE, FALSE, MODEST_MARGIN_HALF);
2732 gtk_widget_show (caption);
2734 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry_username,
2736 #endif /* MODEST_PLATFORM_MAEMO */
2739 GtkWidget *entry_password = gtk_entry_new ();
2740 gtk_entry_set_visibility (GTK_ENTRY(entry_password), FALSE);
2741 /* gtk_entry_set_invisible_char (GTK_ENTRY(entry_password), "*"); */
2743 #ifdef MODEST_PLATFORM_MAEMO
2744 /* Auto-capitalization is the default, so let's turn it off: */
2745 hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_password),
2746 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
2748 caption = hildon_caption_new (sizegroup,
2749 _("mail_fi_password"), entry_password, NULL, HILDON_CAPTION_MANDATORY);
2750 gtk_widget_show (entry_password);
2751 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
2752 FALSE, FALSE, MODEST_MARGIN_HALF);
2753 gtk_widget_show (caption);
2754 g_object_unref (sizegroup);
2756 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry_password,
2758 #endif /* MODEST_PLATFORM_MAEMO */
2760 /* This is not in the Maemo UI spec:
2761 remember_pass_check = gtk_check_button_new_with_label (_("Remember password"));
2762 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), remember_pass_check,
2766 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
2768 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
2770 *username = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_username)));
2772 modest_server_account_set_username (
2773 modest_runtime_get_account_mgr(), server_account_name,
2776 const gboolean username_was_changed =
2777 (strcmp (*username, initial_username) != 0);
2778 if (username_was_changed) {
2779 g_warning ("%s: tinymail does not yet support changing the "
2780 "username in the get_password() callback.\n", __FUNCTION__);
2785 *password = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_password)));
2787 /* We do not save the password in the configuration,
2788 * because this function is only called for passwords that should
2789 * not be remembered:
2790 modest_server_account_set_password (
2791 modest_runtime_get_account_mgr(), server_account_name,
2800 show_error(GTK_WIDGET (main_window), _("mail_ib_login_cancelled"));
2812 /* This is not in the Maemo UI spec:
2813 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (remember_pass_check)))
2819 gtk_widget_destroy (dialog);
2821 /* printf ("DEBUG: %s: cancel=%d\n", __FUNCTION__, *cancel); */
2825 modest_ui_actions_on_cut (GtkAction *action,
2826 ModestWindow *window)
2828 GtkWidget *focused_widget;
2829 GtkClipboard *clipboard;
2831 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
2832 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
2833 if (GTK_IS_EDITABLE (focused_widget)) {
2834 gtk_editable_cut_clipboard (GTK_EDITABLE(focused_widget));
2835 gtk_clipboard_set_can_store (clipboard, NULL, 0);
2836 gtk_clipboard_store (clipboard);
2837 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
2838 GtkTextBuffer *buffer;
2840 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
2841 gtk_text_buffer_cut_clipboard (buffer, clipboard, TRUE);
2842 gtk_clipboard_set_can_store (clipboard, NULL, 0);
2843 gtk_clipboard_store (clipboard);
2844 } else if (MODEST_IS_HEADER_VIEW (focused_widget)) {
2845 TnyList *header_list = modest_header_view_get_selected_headers (
2846 MODEST_HEADER_VIEW (focused_widget));
2847 gboolean continue_download = FALSE;
2848 gint num_of_unc_msgs;
2850 num_of_unc_msgs = header_list_count_uncached_msgs(
2851 header_list, GTK_WINDOW (window));
2853 if (num_of_unc_msgs)
2854 continue_download = connect_to_get_msg(
2855 GTK_WINDOW (window),
2858 if (num_of_unc_msgs == 0 || continue_download) {
2859 /* modest_platform_information_banner (
2860 NULL, NULL, _CS("mcen_ib_getting_items"));*/
2861 modest_header_view_cut_selection (
2862 MODEST_HEADER_VIEW (focused_widget));
2865 g_object_unref (header_list);
2866 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
2867 modest_folder_view_cut_selection (MODEST_FOLDER_VIEW (focused_widget));
2872 modest_ui_actions_on_copy (GtkAction *action,
2873 ModestWindow *window)
2875 GtkClipboard *clipboard;
2876 GtkWidget *focused_widget;
2877 gboolean copied = TRUE;
2879 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
2880 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
2882 if (GTK_IS_LABEL (focused_widget)) {
2883 gtk_clipboard_set_text (clipboard, gtk_label_get_text (GTK_LABEL (focused_widget)), -1);
2884 gtk_clipboard_set_can_store (clipboard, NULL, 0);
2885 gtk_clipboard_store (clipboard);
2886 } else if (GTK_IS_EDITABLE (focused_widget)) {
2887 gtk_editable_copy_clipboard (GTK_EDITABLE(focused_widget));
2888 gtk_clipboard_set_can_store (clipboard, NULL, 0);
2889 gtk_clipboard_store (clipboard);
2890 } else if (GTK_IS_HTML (focused_widget)) {
2891 gtk_html_copy (GTK_HTML (focused_widget));
2892 gtk_clipboard_set_can_store (clipboard, NULL, 0);
2893 gtk_clipboard_store (clipboard);
2894 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
2895 GtkTextBuffer *buffer;
2896 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
2897 gtk_text_buffer_copy_clipboard (buffer, clipboard);
2898 gtk_clipboard_set_can_store (clipboard, NULL, 0);
2899 gtk_clipboard_store (clipboard);
2900 } else if (MODEST_IS_HEADER_VIEW (focused_widget)) {
2901 TnyList *header_list = modest_header_view_get_selected_headers (
2902 MODEST_HEADER_VIEW (focused_widget));
2903 gboolean continue_download = FALSE;
2904 gint num_of_unc_msgs;
2906 num_of_unc_msgs = header_list_count_uncached_msgs(
2908 GTK_WINDOW (window));
2910 if (num_of_unc_msgs)
2911 continue_download = connect_to_get_msg(
2912 GTK_WINDOW (window),
2915 if (num_of_unc_msgs == 0 || continue_download) {
2916 modest_platform_information_banner (
2917 NULL, NULL, _CS("mcen_ib_getting_items"));
2918 modest_header_view_copy_selection (
2919 MODEST_HEADER_VIEW (focused_widget));
2923 g_object_unref (header_list);
2925 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
2926 modest_folder_view_copy_selection (MODEST_FOLDER_VIEW (focused_widget));
2929 /* Show information banner if there was a copy to clipboard */
2931 modest_platform_information_banner (
2932 NULL, NULL, _CS("ecoc_ib_edwin_copied"));
2936 modest_ui_actions_on_undo (GtkAction *action,
2937 ModestWindow *window)
2939 ModestEmailClipboard *clipboard = NULL;
2941 if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
2942 modest_msg_edit_window_undo (MODEST_MSG_EDIT_WINDOW (window));
2943 } else if (MODEST_IS_MAIN_WINDOW (window)) {
2944 /* Clear clipboard source */
2945 clipboard = modest_runtime_get_email_clipboard ();
2946 modest_email_clipboard_clear (clipboard);
2949 g_return_if_reached ();
2954 modest_ui_actions_on_redo (GtkAction *action,
2955 ModestWindow *window)
2957 if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
2958 modest_msg_edit_window_redo (MODEST_MSG_EDIT_WINDOW (window));
2961 g_return_if_reached ();
2967 paste_msgs_cb (const GObject *object, gpointer user_data)
2969 g_return_if_fail (MODEST_IS_MAIN_WINDOW (object));
2970 g_return_if_fail (GTK_IS_WIDGET (user_data));
2972 /* destroy information note */
2973 gtk_widget_destroy (GTK_WIDGET(user_data));
2977 paste_as_attachment_free (gpointer data)
2979 PasteAsAttachmentHelper *helper = (PasteAsAttachmentHelper *) data;
2981 gtk_widget_destroy (helper->banner);
2982 g_object_unref (helper->banner);
2987 paste_msg_as_attachment_cb (ModestMailOperation *mail_op,
2992 PasteAsAttachmentHelper *helper = (PasteAsAttachmentHelper *) userdata;
2993 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (helper->window));
2998 modest_msg_edit_window_add_part (MODEST_MSG_EDIT_WINDOW (helper->window), TNY_MIME_PART (msg));
3003 modest_ui_actions_on_paste (GtkAction *action,
3004 ModestWindow *window)
3006 GtkWidget *focused_widget = NULL;
3007 GtkWidget *inf_note = NULL;
3008 ModestMailOperation *mail_op = NULL;
3010 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
3011 if (GTK_IS_EDITABLE (focused_widget)) {
3012 gtk_editable_paste_clipboard (GTK_EDITABLE(focused_widget));
3013 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
3014 ModestEmailClipboard *e_clipboard = NULL;
3015 e_clipboard = modest_runtime_get_email_clipboard ();
3016 if (modest_email_clipboard_cleared (e_clipboard)) {
3017 GtkTextBuffer *buffer;
3018 GtkClipboard *clipboard;
3020 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
3021 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
3022 gtk_text_buffer_paste_clipboard (buffer, clipboard, NULL, TRUE);
3023 } else if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
3024 ModestMailOperation *mail_op;
3025 TnyFolder *src_folder;
3028 PasteAsAttachmentHelper *helper = g_new0 (PasteAsAttachmentHelper, 1);
3029 helper->window = MODEST_MSG_EDIT_WINDOW (window);
3030 helper->banner = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
3031 _CS("ckct_nw_pasting"));
3032 modest_email_clipboard_get_data (e_clipboard, &src_folder, &data, &delete);
3033 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_RECEIVE,
3035 if (helper->banner != NULL) {
3036 g_object_ref (G_OBJECT (helper->banner));
3037 gtk_window_set_modal (GTK_WINDOW (helper->banner), FALSE);
3038 gtk_widget_show (GTK_WIDGET (helper->banner));
3042 modest_mail_operation_get_msgs_full (mail_op,
3044 (GetMsgAsyncUserCallback) paste_msg_as_attachment_cb,
3046 paste_as_attachment_free);
3049 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
3050 ModestEmailClipboard *clipboard = NULL;
3051 TnyFolder *src_folder = NULL;
3052 TnyFolderStore *folder_store = NULL;
3053 TnyList *data = NULL;
3054 gboolean delete = FALSE;
3056 /* Check clipboard source */
3057 clipboard = modest_runtime_get_email_clipboard ();
3058 if (modest_email_clipboard_cleared (clipboard))
3061 /* Get elements to paste */
3062 modest_email_clipboard_get_data (clipboard, &src_folder, &data, &delete);
3064 /* Create a new mail operation */
3065 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_RECEIVE, G_OBJECT(window));
3067 /* Get destination folder */
3068 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (focused_widget));
3070 /* transfer messages */
3074 /* Ask for user confirmation */
3075 response = msgs_move_to_confirmation (GTK_WINDOW (window),
3076 TNY_FOLDER (folder_store),
3080 if (response == GTK_RESPONSE_OK) {
3081 /* Launch notification */
3082 inf_note = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
3083 _CS("ckct_nw_pasting"));
3084 if (inf_note != NULL) {
3085 gtk_window_set_modal (GTK_WINDOW(inf_note), FALSE);
3086 gtk_widget_show (GTK_WIDGET(inf_note));
3089 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
3090 modest_mail_operation_xfer_msgs (mail_op,
3092 TNY_FOLDER (folder_store),
3097 g_object_unref (mail_op);
3100 } else if (src_folder != NULL) {
3101 /* Launch notification */
3102 inf_note = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
3103 _CS("ckct_nw_pasting"));
3104 if (inf_note != NULL) {
3105 gtk_window_set_modal (GTK_WINDOW(inf_note), FALSE);
3106 gtk_widget_show (GTK_WIDGET(inf_note));
3109 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
3110 modest_mail_operation_xfer_folder (mail_op,
3120 g_object_unref (data);
3121 if (src_folder != NULL)
3122 g_object_unref (src_folder);
3123 if (folder_store != NULL)
3124 g_object_unref (folder_store);
3130 modest_ui_actions_on_select_all (GtkAction *action,
3131 ModestWindow *window)
3133 GtkWidget *focused_widget;
3135 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
3136 if (MODEST_IS_ATTACHMENTS_VIEW (focused_widget)) {
3137 modest_attachments_view_select_all (MODEST_ATTACHMENTS_VIEW (focused_widget));
3138 } else if (GTK_IS_LABEL (focused_widget)) {
3139 gtk_label_select_region (GTK_LABEL (focused_widget), 0, -1);
3140 } else if (GTK_IS_EDITABLE (focused_widget)) {
3141 gtk_editable_select_region (GTK_EDITABLE(focused_widget), 0, -1);
3142 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
3143 GtkTextBuffer *buffer;
3144 GtkTextIter start, end;
3146 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
3147 gtk_text_buffer_get_start_iter (buffer, &start);
3148 gtk_text_buffer_get_end_iter (buffer, &end);
3149 gtk_text_buffer_select_range (buffer, &start, &end);
3150 } else if (GTK_IS_HTML (focused_widget)) {
3151 gtk_html_select_all (GTK_HTML (focused_widget));
3152 } else if (MODEST_IS_MAIN_WINDOW (window)) {
3153 GtkWidget *header_view = focused_widget;
3154 GtkTreeSelection *selection = NULL;
3156 if (!(MODEST_IS_HEADER_VIEW (focused_widget))) {
3157 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (window),
3158 MODEST_WIDGET_TYPE_HEADER_VIEW);
3161 /* Disable window dimming management */
3162 modest_window_disable_dimming (MODEST_WINDOW(window));
3164 /* Select all messages */
3165 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(header_view));
3166 gtk_tree_selection_select_all (selection);
3168 /* Set focuse on header view */
3169 gtk_widget_grab_focus (header_view);
3172 /* Enable window dimming management */
3173 modest_window_enable_dimming (MODEST_WINDOW(window));
3174 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (window));
3180 modest_ui_actions_on_mark_as_read (GtkAction *action,
3181 ModestWindow *window)
3183 g_return_if_fail (MODEST_IS_WINDOW(window));
3185 /* Mark each header as read */
3186 do_headers_action (window, headers_action_mark_as_read, NULL);
3190 modest_ui_actions_on_mark_as_unread (GtkAction *action,
3191 ModestWindow *window)
3193 g_return_if_fail (MODEST_IS_WINDOW(window));
3195 /* Mark each header as read */
3196 do_headers_action (window, headers_action_mark_as_unread, NULL);
3200 modest_ui_actions_on_change_zoom (GtkRadioAction *action,
3201 GtkRadioAction *selected,
3202 ModestWindow *window)
3206 value = gtk_radio_action_get_current_value (selected);
3207 if (MODEST_IS_WINDOW (window)) {
3208 modest_window_set_zoom (MODEST_WINDOW (window), ((gdouble)value)/100);
3212 void modest_ui_actions_msg_edit_on_change_priority (GtkRadioAction *action,
3213 GtkRadioAction *selected,
3214 ModestWindow *window)
3216 TnyHeaderFlags flags;
3217 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3219 flags = gtk_radio_action_get_current_value (selected);
3220 modest_msg_edit_window_set_priority_flags (MODEST_MSG_EDIT_WINDOW (window), flags);
3223 void modest_ui_actions_msg_edit_on_change_file_format (GtkRadioAction *action,
3224 GtkRadioAction *selected,
3225 ModestWindow *window)
3229 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3231 file_format = gtk_radio_action_get_current_value (selected);
3232 modest_msg_edit_window_set_file_format (MODEST_MSG_EDIT_WINDOW (window), file_format);
3237 modest_ui_actions_on_zoom_plus (GtkAction *action,
3238 ModestWindow *window)
3240 g_return_if_fail (MODEST_IS_WINDOW (window));
3242 modest_window_zoom_plus (MODEST_WINDOW (window));
3246 modest_ui_actions_on_zoom_minus (GtkAction *action,
3247 ModestWindow *window)
3249 g_return_if_fail (MODEST_IS_WINDOW (window));
3251 modest_window_zoom_minus (MODEST_WINDOW (window));
3255 modest_ui_actions_on_toggle_fullscreen (GtkToggleAction *toggle,
3256 ModestWindow *window)
3258 ModestWindowMgr *mgr;
3259 gboolean fullscreen, active;
3260 g_return_if_fail (MODEST_IS_WINDOW (window));
3262 mgr = modest_runtime_get_window_mgr ();
3264 active = (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle)))?1:0;
3265 fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
3267 if (active != fullscreen) {
3268 modest_window_mgr_set_fullscreen_mode (mgr, active);
3269 gtk_window_present (GTK_WINDOW (window));
3274 modest_ui_actions_on_change_fullscreen (GtkAction *action,
3275 ModestWindow *window)
3277 ModestWindowMgr *mgr;
3278 gboolean fullscreen;
3280 g_return_if_fail (MODEST_IS_WINDOW (window));
3282 mgr = modest_runtime_get_window_mgr ();
3283 fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
3284 modest_window_mgr_set_fullscreen_mode (mgr, !fullscreen);
3286 gtk_window_present (GTK_WINDOW (window));
3290 * Used by modest_ui_actions_on_details to call do_headers_action
3293 headers_action_show_details (TnyHeader *header,
3294 ModestWindow *window,
3301 dialog = modest_details_dialog_new_with_header (GTK_WINDOW (window), header);
3304 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
3305 gtk_widget_show_all (dialog);
3306 gtk_dialog_run (GTK_DIALOG (dialog));
3308 gtk_widget_destroy (dialog);
3312 * Show the folder details in a ModestDetailsDialog widget
3315 show_folder_details (TnyFolder *folder,
3321 dialog = modest_details_dialog_new_with_folder (window, folder);
3324 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
3325 gtk_widget_show_all (dialog);
3326 gtk_dialog_run (GTK_DIALOG (dialog));
3328 gtk_widget_destroy (dialog);
3332 * Show the header details in a ModestDetailsDialog widget
3335 modest_ui_actions_on_details (GtkAction *action,
3338 TnyList * headers_list;
3342 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
3345 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW (win));
3348 g_object_unref (msg);
3350 headers_list = get_selected_headers (win);
3354 iter = tny_list_create_iterator (headers_list);
3356 header = TNY_HEADER (tny_iterator_get_current (iter));
3358 headers_action_show_details (header, win, NULL);
3359 g_object_unref (header);
3362 g_object_unref (iter);
3363 g_object_unref (headers_list);
3365 } else if (MODEST_IS_MAIN_WINDOW (win)) {
3366 GtkWidget *folder_view, *header_view;
3368 /* Check which widget has the focus */
3369 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
3370 MODEST_WIDGET_TYPE_FOLDER_VIEW);
3371 if (gtk_widget_is_focus (folder_view)) {
3372 TnyFolderStore *folder_store
3373 = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
3374 if (!folder_store) {
3375 g_warning ("%s: No item was selected.\n", __FUNCTION__);
3378 /* Show only when it's a folder */
3379 /* This function should not be called for account items,
3380 * because we dim the menu item for them. */
3381 if (TNY_IS_FOLDER (folder_store)) {
3382 show_folder_details (TNY_FOLDER (folder_store), GTK_WINDOW (win));
3385 g_object_unref (folder_store);
3388 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
3389 MODEST_WIDGET_TYPE_HEADER_VIEW);
3390 /* Show details of each header */
3391 do_headers_action (win, headers_action_show_details, header_view);
3397 modest_ui_actions_on_toggle_show_cc (GtkToggleAction *toggle,
3398 ModestMsgEditWindow *window)
3400 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3402 modest_msg_edit_window_show_cc (window, gtk_toggle_action_get_active (toggle));
3406 modest_ui_actions_on_toggle_show_bcc (GtkToggleAction *toggle,
3407 ModestMsgEditWindow *window)
3409 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3411 modest_msg_edit_window_show_bcc (window, gtk_toggle_action_get_active (toggle));
3415 modest_ui_actions_toggle_folders_view (GtkAction *action,
3416 ModestMainWindow *main_window)
3418 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
3420 if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)))
3421 modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SPLIT);
3423 modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SIMPLE);
3427 modest_ui_actions_on_toggle_toolbar (GtkToggleAction *toggle,
3428 ModestWindow *window)
3430 gboolean active, fullscreen = FALSE;
3431 ModestWindowMgr *mgr;
3433 active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle));
3435 /* Check if we want to toggle the toolbar vuew in fullscreen
3437 if (!strcmp (gtk_action_get_name (GTK_ACTION (toggle)),
3438 "ViewShowToolbarFullScreen")) {
3442 /* Toggle toolbar */
3443 mgr = modest_runtime_get_window_mgr ();
3444 modest_window_mgr_show_toolbars (mgr, active, fullscreen);
3448 modest_ui_actions_msg_edit_on_select_font (GtkAction *action,
3449 ModestMsgEditWindow *window)
3451 modest_msg_edit_window_select_font (window);
3455 modest_ui_actions_on_folder_display_name_changed (ModestFolderView *folder_view,
3456 const gchar *display_name,
3459 /* Do not change the application name if the widget has not
3460 the focus. This callback could be called even if the folder
3461 view has not the focus, because the handled signal could be
3462 emitted when the folder view is redrawn */
3463 if (gtk_widget_is_focus (GTK_WIDGET (folder_view))) {
3465 gtk_window_set_title (window, display_name);
3467 gtk_window_set_title (window, " ");
3472 modest_ui_actions_on_select_contacts (GtkAction *action, ModestMsgEditWindow *window)
3474 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3475 modest_msg_edit_window_select_contacts (window);
3479 modest_ui_actions_on_check_names (GtkAction *action, ModestMsgEditWindow *window)
3481 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3482 modest_msg_edit_window_check_names (window, FALSE);
3486 create_move_to_dialog_on_new_folder(GtkWidget *button, gpointer user_data)
3488 modest_ui_actions_create_folder (gtk_widget_get_toplevel (button),
3489 GTK_WIDGET (user_data));
3493 * This function is used to track changes in the selection of the
3494 * folder view that is inside the "move to" dialog to enable/disable
3495 * the OK button because we do not want the user to select a disallowed
3496 * destination for a folder.
3497 * The user also not desired to be able to use NEW button on items where
3498 * folder creation is not possibel.
3501 on_move_to_dialog_folder_selection_changed (ModestFolderView* self,
3502 TnyFolderStore *folder_store,
3506 GtkWidget *dialog = NULL;
3507 GtkWidget *ok_button = NULL, *new_button = NULL;
3508 GList *children = NULL;
3509 gboolean ok_sensitive = TRUE, new_sensitive = TRUE;
3510 gboolean moving_folder = FALSE;
3511 gboolean is_local_account = TRUE;
3512 GtkWidget *folder_view = NULL;
3513 ModestTnyFolderRules rules;
3518 /* Get the OK button */
3519 dialog = gtk_widget_get_ancestor (GTK_WIDGET (self), GTK_TYPE_DIALOG);
3523 children = gtk_container_get_children (GTK_CONTAINER (GTK_DIALOG (dialog)->action_area));
3524 ok_button = GTK_WIDGET (children->next->next->data);
3525 new_button = GTK_WIDGET (children->next->data);
3526 g_list_free (children);
3528 /* check if folder_store is an remote account */
3529 if (TNY_IS_ACCOUNT (folder_store)) {
3530 TnyAccount *local_account = NULL;
3531 ModestTnyAccountStore *account_store = NULL;
3533 account_store = modest_runtime_get_account_store ();
3534 local_account = modest_tny_account_store_get_local_folders_account (account_store);
3536 if ((gpointer) local_account != (gpointer) folder_store) {
3537 is_local_account = FALSE;
3538 /* New button should be dimmed on remote
3540 new_sensitive = FALSE;
3542 g_object_unref (local_account);
3545 /* Check the target folder rules */
3546 if (TNY_IS_FOLDER (folder_store)) {
3547 rules = modest_tny_folder_get_rules (TNY_FOLDER (folder_store));
3548 if (rules & MODEST_FOLDER_RULES_FOLDER_NON_WRITEABLE) {
3549 ok_sensitive = FALSE;
3550 new_sensitive = FALSE;
3555 /* Check if we're moving a folder */
3556 if (MODEST_IS_MAIN_WINDOW (user_data)) {
3557 /* Get the widgets */
3558 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (user_data),
3559 MODEST_WIDGET_TYPE_FOLDER_VIEW);
3560 if (gtk_widget_is_focus (folder_view))
3561 moving_folder = TRUE;
3564 if (moving_folder) {
3565 TnyFolderStore *moved_folder = NULL, *parent = NULL;
3567 /* Get the folder to move */
3568 moved_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
3570 /* Check that we're not moving to the same folder */
3571 if (TNY_IS_FOLDER (moved_folder)) {
3572 parent = tny_folder_get_folder_store (TNY_FOLDER (moved_folder));
3573 if (parent == folder_store)
3574 ok_sensitive = FALSE;
3575 g_object_unref (parent);
3578 if (ok_sensitive && TNY_IS_ACCOUNT (folder_store)) {
3579 /* Do not allow to move to an account unless it's the
3580 local folders account */
3581 if (!is_local_account)
3582 ok_sensitive = FALSE;
3585 if (ok_sensitive && (moved_folder == folder_store)) {
3586 /* Do not allow to move to itself */
3587 ok_sensitive = FALSE;
3589 g_object_unref (moved_folder);
3591 TnyHeader *header = NULL;
3592 TnyFolder *src_folder = NULL;
3594 /* Moving a message */
3595 if (MODEST_IS_MSG_VIEW_WINDOW (user_data)) {
3596 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (user_data));
3597 src_folder = tny_header_get_folder (header);
3598 g_object_unref (header);
3601 TNY_FOLDER (modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view)));
3604 /* Do not allow to move the msg to the same folder */
3605 /* Do not allow to move the msg to an account */
3606 if ((gpointer) src_folder == (gpointer) folder_store ||
3607 TNY_IS_ACCOUNT (folder_store))
3608 ok_sensitive = FALSE;
3609 g_object_unref (src_folder);
3613 /* Set sensitivity of the OK button */
3614 gtk_widget_set_sensitive (ok_button, ok_sensitive);
3615 /* Set sensitivity of the NEW button */
3616 gtk_widget_set_sensitive (new_button, new_sensitive);
3620 create_move_to_dialog (GtkWindow *win,
3621 GtkWidget *folder_view,
3622 GtkWidget **tree_view)
3624 GtkWidget *dialog, *scroll;
3625 GtkWidget *new_button;
3627 dialog = gtk_dialog_new_with_buttons (_("mcen_ti_moveto_folders_title"),
3629 GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR | GTK_DIALOG_DESTROY_WITH_PARENT,
3632 gtk_dialog_add_button (GTK_DIALOG (dialog), _("mcen_bd_dialog_ok"), GTK_RESPONSE_ACCEPT);
3633 /* We do this manually so GTK+ does not associate a response ID for
3635 new_button = gtk_button_new_from_stock (_("mcen_bd_new"));
3636 gtk_box_pack_end (GTK_BOX (GTK_DIALOG (dialog)->action_area), new_button, FALSE, FALSE, 0);
3637 gtk_dialog_add_button (GTK_DIALOG (dialog), _("mcen_bd_dialog_cancel"), GTK_RESPONSE_REJECT);
3639 /* Create scrolled window */
3640 scroll = gtk_scrolled_window_new (NULL, NULL);
3641 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll),
3642 GTK_POLICY_AUTOMATIC,
3643 GTK_POLICY_AUTOMATIC);
3645 /* Create folder view */
3646 *tree_view = modest_platform_create_folder_view (NULL);
3648 /* Track changes in the selection to
3649 * disable the OK button whenever "Move to" is not possible
3650 * disbale NEW button whenever New is not possible */
3651 g_signal_connect (*tree_view,
3652 "folder_selection_changed",
3653 G_CALLBACK (on_move_to_dialog_folder_selection_changed),
3656 /* Listen to clicks on New button */
3657 g_signal_connect (G_OBJECT (new_button),
3659 G_CALLBACK(create_move_to_dialog_on_new_folder),
3662 /* It could happen that we're trying to move a message from a
3663 window (msg window for example) after the main window was
3664 closed, so we can not just get the model of the folder
3666 if (MODEST_IS_FOLDER_VIEW (folder_view)) {
3667 const gchar *visible_id = NULL;
3669 modest_folder_view_copy_model (MODEST_FOLDER_VIEW(folder_view),
3670 MODEST_FOLDER_VIEW(*tree_view));
3673 modest_folder_view_get_account_id_of_visible_server_account (MODEST_FOLDER_VIEW(folder_view));
3675 /* Show the same account than the one that is shown in the main window */
3676 modest_folder_view_set_account_id_of_visible_server_account (MODEST_FOLDER_VIEW(*tree_view),
3679 const gchar *active_account_name = NULL;
3680 ModestAccountMgr *mgr = NULL;
3681 ModestAccountData *acc_data = NULL;
3683 modest_folder_view_update_model (MODEST_FOLDER_VIEW (*tree_view),
3684 TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()));
3686 active_account_name = modest_window_get_active_account (MODEST_WINDOW (win));
3687 mgr = modest_runtime_get_account_mgr ();
3688 acc_data = modest_account_mgr_get_account_data (mgr, active_account_name);
3690 /* Set the new visible & active account */
3691 if (acc_data && acc_data->store_account) {
3692 modest_folder_view_set_account_id_of_visible_server_account (MODEST_FOLDER_VIEW (*tree_view),
3693 acc_data->store_account->account_name);
3694 modest_account_mgr_free_account_data (mgr, acc_data);
3698 /* Hide special folders */
3699 modest_folder_view_show_non_move_folders (MODEST_FOLDER_VIEW (*tree_view), FALSE);
3701 gtk_container_add (GTK_CONTAINER (scroll), *tree_view);
3703 /* Add scroll to dialog */
3704 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
3705 scroll, TRUE, TRUE, 0);
3707 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
3708 gtk_window_set_default_size (GTK_WINDOW (dialog), 300, 300);
3714 * Returns TRUE if at least one of the headers of the list belongs to
3715 * a message that has been fully retrieved.
3717 #if 0 /* no longer in use. delete in 2007.10 */
3719 has_retrieved_msgs (TnyList *list)
3722 gboolean found = FALSE;
3724 iter = tny_list_create_iterator (list);
3725 while (!tny_iterator_is_done (iter) && !found) {
3727 TnyHeaderFlags flags = 0;
3729 header = TNY_HEADER (tny_iterator_get_current (iter));
3731 flags = tny_header_get_flags (header);
3732 if (flags & TNY_HEADER_FLAG_CACHED)
3733 /* if (!(flags & TNY_HEADER_FLAG_PARTIAL)) */
3736 g_object_unref (header);
3740 tny_iterator_next (iter);
3742 g_object_unref (iter);
3750 * Shows a confirmation dialog to the user when we're moving messages
3751 * from a remote server to the local storage. Returns the dialog
3752 * response. If it's other kind of movement then it always returns
3755 * This one is used by the next functions:
3756 * modest_ui_actions_xfer_messages_from_move_to
3757 * modest_ui_actions_on_paste - commented out
3758 * drag_and_drop_from_header_view (for d&d in modest_folder_view.c)
3761 msgs_move_to_confirmation (GtkWindow *win,
3762 TnyFolder *dest_folder,
3766 gint response = GTK_RESPONSE_OK;
3768 /* return with OK if the destination is a remote folder */
3769 if (modest_tny_folder_is_remote_folder (dest_folder))
3770 return GTK_RESPONSE_OK;
3772 TnyFolder *src_folder = NULL;
3773 TnyIterator *iter = NULL;
3774 TnyHeader *header = NULL;
3776 /* Get source folder */
3777 iter = tny_list_create_iterator (headers);
3778 header = TNY_HEADER (tny_iterator_get_current (iter));
3780 src_folder = tny_header_get_folder (header);
3781 g_object_unref (header);
3783 g_object_unref (iter);
3785 /* if no src_folder, message may be an attahcment */
3786 if (src_folder == NULL)
3787 return GTK_RESPONSE_CANCEL;
3789 /* If the source is a local or MMC folder */
3790 if (!modest_tny_folder_is_remote_folder (src_folder)) {
3791 g_object_unref (src_folder);
3792 return GTK_RESPONSE_OK;
3794 g_object_unref (src_folder);
3796 /* now if offline we ask the user */
3797 if(connect_to_get_msg( GTK_WINDOW (win),
3798 tny_list_get_length (headers)))
3799 response = GTK_RESPONSE_OK;
3801 response = GTK_RESPONSE_CANCEL;
3809 transfer_msgs_from_viewer_cb (const GObject *object, gpointer user_data)
3811 ModestMsgViewWindow *self = NULL;
3813 g_return_if_fail (MODEST_IS_MSG_VIEW_WINDOW (object));
3814 self = MODEST_MSG_VIEW_WINDOW (object);
3816 if (!modest_msg_view_window_select_next_message (self))
3817 if (!modest_msg_view_window_select_previous_message (self))
3818 /* No more messages to view, so close this window */
3819 modest_ui_actions_on_close_window (NULL, MODEST_WINDOW(self));
3823 modest_ui_actions_move_folder_error_handler (ModestMailOperation *mail_op,
3826 GObject *win = modest_mail_operation_get_source (mail_op);
3827 const GError *error = NULL;
3828 const gchar *message = NULL;
3830 /* Get error message */
3831 error = modest_mail_operation_get_error (mail_op);
3832 if (error != NULL && error->message != NULL) {
3833 message = error->message;
3835 message = _("mail_in_ui_folder_move_target_error");
3838 /* Show notification dialog */
3839 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL, message);
3840 g_object_unref (win);
3844 modest_ui_actions_send_receive_error_handler (ModestMailOperation *mail_op,
3847 GObject *win = modest_mail_operation_get_source (mail_op);
3848 const GError *error = modest_mail_operation_get_error (mail_op);
3850 g_return_if_fail (error != NULL);
3851 if (error->message != NULL)
3852 g_printerr ("modest: %s\n", error->message);
3854 g_printerr ("modest: unkonw error on send&receive operation");
3856 /* Show error message */
3857 /* if (modest_mail_operation_get_id (mail_op) == MODEST_MAIL_OPERATION_TYPE_RECEIVE) */
3858 /* modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL, */
3859 /* _CS("sfil_ib_unable_to_receive")); */
3861 /* modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL, */
3862 /* _CS("sfil_ib_unable_to_send")); */
3863 g_object_unref (win);
3867 open_msg_for_purge_cb (ModestMailOperation *mail_op,
3874 gint pending_purges = 0;
3875 gboolean some_purged = FALSE;
3876 ModestWindow *win = MODEST_WINDOW (user_data);
3877 ModestWindowMgr *mgr = modest_runtime_get_window_mgr ();
3879 /* If there was any error */
3880 if (!modest_ui_actions_msg_retrieval_check (mail_op, header, msg)) {
3881 modest_window_mgr_unregister_header (mgr, header);
3885 /* Once the message has been retrieved for purging, we check if
3886 * it's all ok for purging */
3888 parts = tny_simple_list_new ();
3889 tny_mime_part_get_parts (TNY_MIME_PART (msg), parts);
3890 iter = tny_list_create_iterator (parts);
3892 while (!tny_iterator_is_done (iter)) {
3894 part = TNY_MIME_PART (tny_iterator_get_current (iter));
3895 if (part && (tny_mime_part_is_attachment (part) || TNY_IS_MSG (part))) {
3896 if (tny_mime_part_is_purged (part))
3903 g_object_unref (part);
3905 tny_iterator_next (iter);
3908 if (pending_purges>0) {
3910 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),_("mcen_nc_purge_file_text_inbox"));
3912 if (response == GTK_RESPONSE_OK) {
3913 modest_platform_information_banner (NULL, NULL, _("mcen_ib_removing_attachment"));
3914 tny_iterator_first (iter);
3915 while (!tny_iterator_is_done (iter)) {
3918 part = TNY_MIME_PART (tny_iterator_get_current (iter));
3919 if (part && (tny_mime_part_is_attachment (part) || TNY_IS_MSG (part)))
3920 tny_mime_part_set_purged (part);
3923 g_object_unref (part);
3925 tny_iterator_next (iter);
3928 tny_msg_rewrite_cache (msg);
3931 modest_platform_information_banner (NULL, NULL, _("mail_ib_attachment_already_purged"));
3934 /* remove attachments */
3935 tny_iterator_first (iter);
3936 while (!tny_iterator_is_done (iter)) {
3939 part = TNY_MIME_PART (tny_iterator_get_current (iter));
3941 /* One for the reference given by tny_iterator_get_current(): */
3942 g_object_unref (part);
3944 /* TODO: Is this meant to remove the attachment by doing another unref()?
3945 * Otherwise, this seems useless. */
3948 tny_iterator_next (iter);
3950 modest_window_mgr_unregister_header (mgr, header);
3952 g_object_unref (iter);
3953 g_object_unref (parts);
3957 modest_ui_actions_on_main_window_remove_attachments (GtkAction *action,
3958 ModestMainWindow *win)
3960 GtkWidget *header_view;
3961 TnyList *header_list;
3964 TnyHeaderFlags flags;
3965 ModestWindow *msg_view_window = NULL;
3968 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win));
3970 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
3971 MODEST_WIDGET_TYPE_HEADER_VIEW);
3973 header_list = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW (header_view));
3975 if (tny_list_get_length (header_list) == 1) {
3976 iter = tny_list_create_iterator (header_list);
3977 header = TNY_HEADER (tny_iterator_get_current (iter));
3978 g_object_unref (iter);
3983 found = modest_window_mgr_find_registered_header (modest_runtime_get_window_mgr (),
3984 header, &msg_view_window);
3985 flags = tny_header_get_flags (header);
3986 if (!(flags & TNY_HEADER_FLAG_CACHED))
3989 if (msg_view_window != NULL)
3990 modest_msg_view_window_remove_attachments (MODEST_MSG_VIEW_WINDOW (msg_view_window), TRUE);
3992 /* do nothing; uid was registered before, so window is probably on it's way */
3993 g_warning ("debug: header %p has already been registered", header);
3996 ModestMailOperation *mail_op = NULL;
3997 modest_window_mgr_register_header (modest_runtime_get_window_mgr (), header);
3998 mail_op = modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE,
4000 modest_ui_actions_get_msgs_full_error_handler,
4002 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
4003 modest_mail_operation_get_msg (mail_op, header, open_msg_for_purge_cb, win);
4005 g_object_unref (mail_op);
4008 g_object_unref (header);
4010 g_object_unref (header_list);
4014 * Utility function that transfer messages from both the main window
4015 * and the msg view window when using the "Move to" dialog
4018 modest_ui_actions_xfer_messages_from_move_to (TnyFolderStore *dst_folder,
4021 TnyList *headers = NULL;
4023 TnyAccount *dst_account = NULL;
4024 const gchar *proto_str = NULL;
4025 gboolean dst_is_pop = FALSE;
4027 if (!TNY_IS_FOLDER (dst_folder)) {
4028 modest_platform_information_banner (GTK_WIDGET (win),
4030 _CS("ckdg_ib_unable_to_move_to_current_location"));
4034 dst_account = tny_folder_get_account (TNY_FOLDER (dst_folder));
4035 proto_str = tny_account_get_proto (dst_account);
4037 /* tinymail will return NULL for local folders it seems */
4038 dst_is_pop = proto_str &&
4039 (modest_protocol_info_get_transport_store_protocol (proto_str) ==
4040 MODEST_PROTOCOL_STORE_POP);
4042 g_object_unref (dst_account);
4044 /* Get selected headers */
4045 headers = get_selected_headers (MODEST_WINDOW (win));
4048 modest_platform_information_banner (GTK_WIDGET (win),
4050 ngettext("mail_in_ui_folder_move_target_error",
4051 "mail_in_ui_folder_move_targets_error",
4052 tny_list_get_length (headers)));
4053 g_object_unref (headers);
4057 /* Ask for user confirmation */
4058 response = msgs_move_to_confirmation (GTK_WINDOW (win),
4059 TNY_FOLDER (dst_folder),
4063 /* Transfer messages */
4064 if (response == GTK_RESPONSE_OK) {
4065 ModestMailOperation *mail_op =
4066 modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE,
4068 modest_ui_actions_move_folder_error_handler,
4070 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
4073 modest_mail_operation_xfer_msgs (mail_op,
4075 TNY_FOLDER (dst_folder),
4077 (MODEST_IS_MSG_VIEW_WINDOW (win)) ? transfer_msgs_from_viewer_cb : NULL,
4080 g_object_unref (G_OBJECT (mail_op));
4082 g_object_unref (headers);
4086 * UI handler for the "Move to" action when invoked from the
4090 modest_ui_actions_on_main_window_move_to (GtkAction *action,
4091 GtkWidget *folder_view,
4092 TnyFolderStore *dst_folder,
4093 ModestMainWindow *win)
4095 ModestHeaderView *header_view = NULL;
4096 ModestMailOperation *mail_op = NULL;
4097 TnyFolderStore *src_folder;
4098 gboolean online = (tny_device_is_online (modest_runtime_get_device()));
4100 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win));
4102 /* Get the source folder */
4103 src_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
4105 /* Get header view */
4106 header_view = MODEST_HEADER_VIEW(modest_main_window_get_child_widget (win, MODEST_WIDGET_TYPE_HEADER_VIEW));
4108 /* Get folder or messages to transfer */
4109 if (gtk_widget_is_focus (folder_view)) {
4110 GtkTreeSelection *sel;
4111 gboolean do_xfer = TRUE;
4113 /* Allow only to transfer folders to the local root folder */
4114 if (TNY_IS_ACCOUNT (dst_folder) &&
4115 !MODEST_IS_TNY_LOCAL_FOLDERS_ACCOUNT (dst_folder)) {
4117 } else if (!TNY_IS_FOLDER (src_folder)) {
4118 g_warning ("%s: src_folder is not a TnyFolder.\n", __FUNCTION__);
4120 } else if (!online && modest_platform_is_network_folderstore(src_folder)) {
4121 guint num_headers = tny_folder_get_all_count(TNY_FOLDER(src_folder));
4122 if (!connect_to_get_msg(GTK_WINDOW(win), num_headers)) {
4128 /* Clean folder on header view before moving it */
4129 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_view));
4130 gtk_tree_selection_unselect_all (sel);
4133 modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE,
4135 modest_ui_actions_move_folder_error_handler,
4137 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
4140 modest_mail_operation_xfer_folder (mail_op,
4141 TNY_FOLDER (src_folder),
4144 /* Unref mail operation */
4145 g_object_unref (G_OBJECT (mail_op));
4147 } else if (gtk_widget_is_focus (GTK_WIDGET(header_view))) {
4148 gboolean do_xfer = TRUE;
4149 /* Ask for confirmation if the source folder is remote and we're not connected */
4150 if (!online && modest_platform_is_network_folderstore(src_folder)) {
4151 guint num_headers = modest_header_view_count_selected_headers(header_view);
4152 if (!connect_to_get_msg(GTK_WINDOW(win), num_headers)) {
4156 if (do_xfer) /* Transfer messages */
4157 modest_ui_actions_xfer_messages_from_move_to (dst_folder, MODEST_WINDOW (win));
4161 g_object_unref (src_folder);
4166 * UI handler for the "Move to" action when invoked from the
4167 * ModestMsgViewWindow
4170 modest_ui_actions_on_msg_view_window_move_to (GtkAction *action,
4171 TnyFolderStore *dst_folder,
4172 ModestMsgViewWindow *win)
4174 TnyHeader *header = NULL;
4175 TnyFolderStore *src_folder;
4177 /* Create header list */
4178 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
4179 src_folder = TNY_FOLDER_STORE(tny_header_get_folder(header));
4180 g_object_unref (header);
4182 /* Transfer the message if online or confirmed by the user */
4183 if (tny_device_is_online (modest_runtime_get_device()) ||
4184 (modest_platform_is_network_folderstore(src_folder) && connect_to_get_msg(GTK_WINDOW(win), 1))) {
4185 modest_ui_actions_xfer_messages_from_move_to (dst_folder, MODEST_WINDOW (win));
4188 g_object_unref (src_folder);
4192 modest_ui_actions_on_move_to (GtkAction *action,
4195 GtkWidget *dialog = NULL, *folder_view = NULL, *tree_view = NULL;
4197 TnyFolderStore *dst_folder = NULL;
4198 ModestMainWindow *main_window;
4200 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win) ||
4201 MODEST_IS_MSG_VIEW_WINDOW (win));
4203 /* Get the main window if exists */
4204 if (MODEST_IS_MAIN_WINDOW (win))
4205 main_window = MODEST_MAIN_WINDOW (win);
4208 MODEST_MAIN_WINDOW (modest_window_mgr_get_main_window (modest_runtime_get_window_mgr ()));
4210 /* Get the folder view widget if exists */
4212 folder_view = modest_main_window_get_child_widget (main_window,
4213 MODEST_WIDGET_TYPE_FOLDER_VIEW);
4217 /* Create and run the dialog */
4218 dialog = create_move_to_dialog (GTK_WINDOW (win), folder_view, &tree_view);
4219 modest_folder_view_select_first_inbox_or_local (MODEST_FOLDER_VIEW (tree_view));
4220 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
4221 result = gtk_dialog_run (GTK_DIALOG(dialog));
4222 g_object_ref (tree_view);
4223 gtk_widget_destroy (dialog);
4225 if (result != GTK_RESPONSE_ACCEPT)
4228 dst_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (tree_view));
4229 /* Do window specific stuff */
4230 if (MODEST_IS_MAIN_WINDOW (win)) {
4231 modest_ui_actions_on_main_window_move_to (action,
4234 MODEST_MAIN_WINDOW (win));
4236 modest_ui_actions_on_msg_view_window_move_to (action,
4238 MODEST_MSG_VIEW_WINDOW (win));
4242 g_object_unref (dst_folder);
4246 * Calls #HeadersFunc for each header already selected in the main
4247 * window or the message currently being shown in the msg view window
4250 do_headers_action (ModestWindow *win,
4254 TnyList *headers_list = NULL;
4255 TnyIterator *iter = NULL;
4256 TnyHeader *header = NULL;
4257 TnyFolder *folder = NULL;
4260 headers_list = get_selected_headers (win);
4264 /* Get the folder */
4265 iter = tny_list_create_iterator (headers_list);
4266 header = TNY_HEADER (tny_iterator_get_current (iter));
4268 folder = tny_header_get_folder (header);
4269 g_object_unref (header);
4272 /* Call the function for each header */
4273 while (!tny_iterator_is_done (iter)) {
4274 header = TNY_HEADER (tny_iterator_get_current (iter));
4275 func (header, win, user_data);
4276 g_object_unref (header);
4277 tny_iterator_next (iter);
4280 /* Trick: do a poke status in order to speed up the signaling
4282 tny_folder_poke_status (folder);
4285 g_object_unref (folder);
4286 g_object_unref (iter);
4287 g_object_unref (headers_list);
4291 modest_ui_actions_view_attachment (GtkAction *action,
4292 ModestWindow *window)
4294 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
4295 modest_msg_view_window_view_attachment (MODEST_MSG_VIEW_WINDOW (window), NULL);
4297 /* not supported window for this action */
4298 g_return_if_reached ();
4303 modest_ui_actions_save_attachments (GtkAction *action,
4304 ModestWindow *window)
4306 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
4307 modest_msg_view_window_save_attachments (MODEST_MSG_VIEW_WINDOW (window), NULL);
4309 /* not supported window for this action */
4310 g_return_if_reached ();
4315 modest_ui_actions_remove_attachments (GtkAction *action,
4316 ModestWindow *window)
4318 if (MODEST_IS_MAIN_WINDOW (window)) {
4319 modest_ui_actions_on_main_window_remove_attachments (action, MODEST_MAIN_WINDOW (window));
4320 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
4321 modest_msg_view_window_remove_attachments (MODEST_MSG_VIEW_WINDOW (window), FALSE);
4323 /* not supported window for this action */
4324 g_return_if_reached ();
4329 modest_ui_actions_on_settings (GtkAction *action,
4334 dialog = modest_platform_get_global_settings_dialog ();
4335 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (win));
4336 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
4337 gtk_widget_show_all (dialog);
4339 gtk_dialog_run (GTK_DIALOG (dialog));
4341 gtk_widget_destroy (dialog);
4345 modest_ui_actions_on_help (GtkAction *action,
4348 const gchar *help_id = NULL;
4350 if (MODEST_IS_MAIN_WINDOW (win)) {
4351 const gchar *action_name;
4352 action_name = gtk_action_get_name (action);
4354 if (!strcmp (action_name, "FolderViewCSMHelp") ||
4355 !strcmp (action_name, "HeaderViewCSMHelp")) {
4356 GtkWidget *folder_view;
4357 TnyFolderStore *folder_store;
4358 /* Get selected folder */
4359 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
4360 MODEST_WIDGET_TYPE_FOLDER_VIEW);
4361 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
4363 /* Switch help_id */
4364 if (TNY_IS_FOLDER (folder_store)) {
4365 switch (modest_tny_folder_guess_folder_type (TNY_FOLDER (folder_store))) {
4366 case TNY_FOLDER_TYPE_NORMAL:
4367 help_id = "applications_email_managefolders";
4369 case TNY_FOLDER_TYPE_INBOX:
4370 help_id = "applications_email_inbox";
4372 case TNY_FOLDER_TYPE_OUTBOX:
4373 help_id = "applications_email_outbox";
4375 case TNY_FOLDER_TYPE_SENT:
4376 help_id = "applications_email_sent";
4378 case TNY_FOLDER_TYPE_DRAFTS:
4379 help_id = "applications_email_drafts";
4381 case TNY_FOLDER_TYPE_ARCHIVE:
4382 help_id = "applications_email_managefolders";
4385 help_id = "applications_email_managefolders";
4388 help_id = "applications_email_mainview";
4390 g_object_unref (folder_store);
4392 help_id = "applications_email_mainview";
4394 } else if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
4395 help_id = "applications_email_viewer";
4396 } else if (MODEST_IS_MSG_EDIT_WINDOW (win))
4397 help_id = "applications_email_editor";
4399 modest_platform_show_help (GTK_WINDOW (win), help_id);
4403 modest_ui_actions_on_retrieve_msg_contents (GtkAction *action,
4404 ModestWindow *window)
4406 ModestMailOperation *mail_op;
4410 headers = get_selected_headers (window);
4414 /* Create mail operation */
4415 mail_op = modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE,
4417 modest_ui_actions_get_msgs_full_error_handler,
4419 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
4420 modest_mail_operation_get_msgs_full (mail_op, headers, NULL, NULL, NULL);
4423 g_object_unref (headers);
4424 g_object_unref (mail_op);
4428 modest_ui_actions_on_email_menu_activated (GtkAction *action,
4429 ModestWindow *window)
4431 g_return_if_fail (MODEST_IS_WINDOW (window));
4434 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4438 modest_ui_actions_on_edit_menu_activated (GtkAction *action,
4439 ModestWindow *window)
4441 g_return_if_fail (MODEST_IS_WINDOW (window));
4444 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4448 modest_ui_actions_on_view_menu_activated (GtkAction *action,
4449 ModestWindow *window)
4451 g_return_if_fail (MODEST_IS_WINDOW (window));
4454 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4458 modest_ui_actions_on_tools_menu_activated (GtkAction *action,
4459 ModestWindow *window)
4461 g_return_if_fail (MODEST_IS_WINDOW (window));
4464 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4468 modest_ui_actions_on_attachment_menu_activated (GtkAction *action,
4469 ModestWindow *window)
4471 g_return_if_fail (MODEST_IS_WINDOW (window));
4474 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4478 modest_ui_actions_on_toolbar_csm_menu_activated (GtkAction *action,
4479 ModestWindow *window)
4481 g_return_if_fail (MODEST_IS_WINDOW (window));
4484 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4488 modest_ui_actions_on_folder_view_csm_menu_activated (GtkAction *action,
4489 ModestWindow *window)
4491 g_return_if_fail (MODEST_IS_WINDOW (window));
4494 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4498 modest_ui_actions_on_header_view_csm_menu_activated (GtkAction *action,
4499 ModestWindow *window)
4501 g_return_if_fail (MODEST_IS_WINDOW (window));
4504 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4508 modest_ui_actions_check_toolbar_dimming_rules (ModestWindow *window)
4510 g_return_if_fail (MODEST_IS_WINDOW (window));
4513 modest_window_check_dimming_rules_group (window, "ModestToolbarDimmingRules");
4517 modest_ui_actions_on_search_messages (GtkAction *action, ModestWindow *window)
4519 g_return_if_fail (MODEST_IS_WINDOW (window));
4521 modest_platform_show_search_messages (GTK_WINDOW (window));
4525 modest_ui_actions_on_open_addressbook (GtkAction *action, ModestWindow *win)
4527 g_return_if_fail (MODEST_IS_WINDOW (win));
4528 modest_platform_show_addressbook (GTK_WINDOW (win));
4533 modest_ui_actions_on_toggle_find_in_page (GtkToggleAction *action,
4534 ModestWindow *window)
4536 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4538 modest_msg_edit_window_toggle_find_toolbar (MODEST_MSG_EDIT_WINDOW (window), gtk_toggle_action_get_active (action));
4542 _on_send_receive_progress_changed (ModestMailOperation *mail_op,
4543 ModestMailOperationState *state,
4546 g_return_if_fail (MODEST_IS_MAIN_WINDOW(user_data));
4548 /* Set send/receive operation finished */
4549 if (state->status != MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS)
4550 modest_main_window_notify_send_receive_completed (MODEST_MAIN_WINDOW(user_data));