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 _MoveToHelper {
107 ModestMailOperation *mail_op;
111 typedef struct _PasteAsAttachmentHelper {
112 ModestMsgEditWindow *window;
114 } PasteAsAttachmentHelper;
118 * The do_headers_action uses this kind of functions to perform some
119 * action to each member of a list of headers
121 typedef void (*HeadersFunc) (TnyHeader *header, ModestWindow *win, gpointer user_data);
123 static void do_headers_action (ModestWindow *win,
127 static void open_msg_cb (ModestMailOperation *mail_op,
132 static void reply_forward_cb (ModestMailOperation *mail_op,
137 static void reply_forward (ReplyForwardAction action, ModestWindow *win);
139 static void folder_refreshed_cb (ModestMailOperation *mail_op,
143 static void _on_send_receive_progress_changed (ModestMailOperation *mail_op,
144 ModestMailOperationState *state,
147 static gint header_list_count_uncached_msgs (
148 TnyList *header_list,
150 static gboolean connect_to_get_msg (
152 gint num_of_uncached_msgs);
156 /* Show the account creation wizard dialog.
157 * returns: TRUE if an account was created. FALSE if the user cancelled.
160 modest_run_account_setup_wizard (ModestWindow *win)
162 gboolean result = FALSE;
165 wizard = modest_window_mgr_get_easysetup_dialog
166 (modest_runtime_get_window_mgr());
168 /* old wizard is active already; present it and
169 * act as if the user cancelled the non-existing
172 printf ("wizard already active\n");
175 /* there is no such wizard yet */
176 wizard = GTK_DIALOG(modest_easysetup_wizard_dialog_new ());
177 modest_window_mgr_set_easysetup_dialog
178 (modest_runtime_get_window_mgr(), GTK_DIALOG(wizard));
182 /* always present a main window in the background
183 * we do it here, so we cannot end up with to wizards (as this
184 * function might be called in modest_window_mgr_get_main_window as well */
186 win = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr());
188 /* make sure the mainwindow is visible */
189 gtk_widget_show_all (GTK_WIDGET(win));
190 gtk_window_present (GTK_WINDOW(win));
193 gtk_window_set_transient_for (GTK_WINDOW (wizard), GTK_WINDOW (win));
195 /* Don't make this a modal window, because secondary windows will then
196 * be unusable, freezing the UI: */
197 /* gtk_window_set_modal (GTK_WINDOW (wizard), TRUE); */
199 gint dialog_response = gtk_dialog_run (GTK_DIALOG (wizard));
200 if (dialog_response == GTK_RESPONSE_CANCEL)
203 /* Check whether an account was created: */
204 result = modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
207 gtk_widget_destroy (GTK_WIDGET (wizard));
209 /* clear it from the window mgr */
210 modest_window_mgr_set_easysetup_dialog
211 (modest_runtime_get_window_mgr(), NULL);
218 modest_ui_actions_on_about (GtkAction *action, ModestWindow *win)
221 const gchar *authors[] = {
222 "Dirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>",
225 about = gtk_about_dialog_new ();
226 gtk_about_dialog_set_name (GTK_ABOUT_DIALOG(about), PACKAGE_NAME);
227 gtk_about_dialog_set_version (GTK_ABOUT_DIALOG(about),PACKAGE_VERSION);
228 gtk_about_dialog_set_copyright (GTK_ABOUT_DIALOG(about),
229 _("Copyright (c) 2006, Nokia Corporation\n"
230 "All rights reserved."));
231 gtk_about_dialog_set_comments (GTK_ABOUT_DIALOG(about),
232 _("a modest e-mail client\n\n"
233 "design and implementation: Dirk-Jan C. Binnema\n"
234 "contributions from the fine people at KC and Ig\n"
235 "uses the tinymail email framework written by Philip van Hoof"));
236 gtk_about_dialog_set_authors (GTK_ABOUT_DIALOG(about), authors);
237 gtk_about_dialog_set_website (GTK_ABOUT_DIALOG(about), "http://modest.garage.maemo.org");
238 gtk_window_set_transient_for (GTK_WINDOW (about), GTK_WINDOW (win));
239 gtk_window_set_modal (GTK_WINDOW (about), TRUE);
241 gtk_dialog_run (GTK_DIALOG (about));
242 gtk_widget_destroy(about);
246 * Gets the list of currently selected messages. If the win is the
247 * main window, then it returns a newly allocated list of the headers
248 * selected in the header view. If win is the msg view window, then
249 * the value returned is a list with just a single header.
251 * The caller of this funcion must free the list.
254 get_selected_headers (ModestWindow *win)
256 if (MODEST_IS_MAIN_WINDOW(win)) {
257 GtkWidget *header_view;
259 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
260 MODEST_WIDGET_TYPE_HEADER_VIEW);
261 return modest_header_view_get_selected_headers (MODEST_HEADER_VIEW(header_view));
263 } else if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
264 /* for MsgViewWindows, we simply return a list with one element */
266 TnyList *list = NULL;
268 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
269 if (header != NULL) {
270 list = tny_simple_list_new ();
271 tny_list_prepend (list, G_OBJECT(header));
272 g_object_unref (G_OBJECT(header));
282 headers_action_mark_as_read (TnyHeader *header,
286 TnyHeaderFlags flags;
288 g_return_if_fail (TNY_IS_HEADER(header));
290 flags = tny_header_get_flags (header);
291 if (flags & TNY_HEADER_FLAG_SEEN) return;
292 tny_header_set_flags (header, TNY_HEADER_FLAG_SEEN);
296 headers_action_mark_as_unread (TnyHeader *header,
300 TnyHeaderFlags flags;
302 g_return_if_fail (TNY_IS_HEADER(header));
304 flags = tny_header_get_flags (header);
305 if (flags & TNY_HEADER_FLAG_SEEN) {
306 tny_header_unset_flags (header, TNY_HEADER_FLAG_SEEN);
310 /** A convenience method, because deleting a message is
311 * otherwise complicated, and it's best to change it in one place
314 void modest_do_message_delete (TnyHeader *header, ModestWindow *win)
316 ModestMailOperation *mail_op = NULL;
317 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_DELETE,
318 win ? G_OBJECT(win) : NULL);
319 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
322 /* Always delete. TODO: Move to trash still not supported */
323 modest_mail_operation_remove_msg (mail_op, header, FALSE);
324 g_object_unref (G_OBJECT (mail_op));
327 /** A convenience method, because deleting a message is
328 * otherwise complicated, and it's best to change it in one place
331 void modest_do_messages_delete (TnyList *headers, ModestWindow *win)
333 ModestMailOperation *mail_op = NULL;
334 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_DELETE,
335 win ? G_OBJECT(win) : NULL);
336 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
339 /* Always delete. TODO: Move to trash still not supported */
340 modest_mail_operation_remove_msgs (mail_op, headers, FALSE);
341 g_object_unref (G_OBJECT (mail_op));
345 /* headers_action_delete (TnyHeader *header, */
346 /* ModestWindow *win, */
347 /* gpointer user_data) */
349 /* modest_do_message_delete (header, win); */
353 /** After deleing a message that is currently visible in a window,
354 * show the next message from the list, or close the window if there are no more messages.
356 void modest_ui_actions_refresh_message_window_after_delete (ModestMsgViewWindow* win)
358 /* Close msg view window or select next */
359 if (modest_msg_view_window_last_message_selected (win) &&
360 modest_msg_view_window_first_message_selected (win)) {
361 modest_ui_actions_on_close_window (NULL, MODEST_WINDOW (win));
363 if (!modest_msg_view_window_select_next_message (win)) {
365 g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value);
371 modest_ui_actions_on_delete_message (GtkAction *action, ModestWindow *win)
373 TnyList *header_list = NULL;
374 TnyIterator *iter = NULL;
375 TnyHeader *header = NULL;
376 gchar *message = NULL;
379 ModestWindowMgr *mgr;
380 GtkWidget *header_view = NULL;
382 g_return_if_fail (MODEST_IS_WINDOW(win));
384 /* Check first if the header view has the focus */
385 if (MODEST_IS_MAIN_WINDOW (win)) {
387 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
388 MODEST_WIDGET_TYPE_HEADER_VIEW);
389 if (!gtk_widget_is_focus (header_view))
393 /* Get the headers, either from the header view (if win is the main window),
394 * or from the message view window: */
395 header_list = get_selected_headers (win);
396 if (!header_list) return;
398 /* Check if any of the headers are already opened, or in the process of being opened */
399 if (MODEST_IS_MAIN_WINDOW (win)) {
401 iter = tny_list_create_iterator (header_list);
403 mgr = modest_runtime_get_window_mgr ();
404 while (!tny_iterator_is_done (iter) && !found) {
405 header = TNY_HEADER (tny_iterator_get_current (iter));
407 found = modest_window_mgr_find_registered_header (mgr, header, NULL);
408 g_object_unref (header);
411 tny_iterator_next (iter);
413 g_object_unref (iter);
418 num = g_strdup_printf ("%d", tny_list_get_length (header_list));
419 msg = g_strdup_printf (_("mcen_nc_unable_to_delete_n_messages"), num);
421 modest_platform_run_information_dialog (GTK_WINDOW (win), (const gchar *) msg);
425 g_object_unref (header_list);
431 if (tny_list_get_length(header_list) == 1) {
432 iter = tny_list_create_iterator (header_list);
433 header = TNY_HEADER (tny_iterator_get_current (iter));
435 desc = g_strdup_printf ("%s", tny_header_get_subject (header));
436 g_object_unref (header);
439 g_object_unref (iter);
441 message = g_strdup_printf(ngettext("emev_nc_delete_message", "emev_nc_delete_messages",
442 tny_list_get_length(header_list)), desc);
444 /* Confirmation dialog */
445 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
449 if (response == GTK_RESPONSE_OK) {
450 ModestWindow *main_window = NULL;
451 ModestWindowMgr *mgr = NULL;
452 GtkTreeModel *model = NULL;
453 GtkTreeSelection *sel = NULL;
454 GList *sel_list = NULL, *tmp = NULL;
455 GtkTreeRowReference *row_reference = NULL;
456 GtkTreePath *next_path = NULL;
459 /* Find last selected row */
460 if (MODEST_IS_MAIN_WINDOW (win)) {
461 model = gtk_tree_view_get_model (GTK_TREE_VIEW (header_view));
462 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
463 sel_list = gtk_tree_selection_get_selected_rows (sel, &model);
464 for (tmp=sel_list; tmp; tmp=tmp->next) {
465 if (tmp->next == NULL) {
466 next_path = gtk_tree_path_copy((GtkTreePath *) tmp->data);
467 gtk_tree_path_next (next_path);
468 row_reference = gtk_tree_row_reference_new (model, next_path);
469 gtk_tree_path_free (next_path);
474 /* Disable window dimming management */
475 modest_window_disable_dimming (MODEST_WINDOW(win));
477 /* Remove each header. If it's a view window header_view == NULL */
478 /* do_headers_action (win, headers_action_delete, header_view); */
479 modest_do_messages_delete (header_list, win);
482 /* Enable window dimming management */
483 gtk_tree_selection_unselect_all (sel);
484 modest_window_enable_dimming (MODEST_WINDOW(win));
486 /* FIXME: May be folder_monitor will also refilter treemode on EXPUNGE changes ? */
487 /* refresh the header view (removing marked-as-deleted) */
488 /* modest_header_view_refilter (MODEST_HEADER_VIEW(header_view)); */
490 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
491 modest_ui_actions_refresh_message_window_after_delete (MODEST_MSG_VIEW_WINDOW (win));
493 /* Get main window */
494 mgr = modest_runtime_get_window_mgr ();
495 main_window = modest_window_mgr_get_main_window (mgr);
498 /* Move cursor to next row */
501 /* Select next row */
502 if (gtk_tree_row_reference_valid (row_reference)) {
503 next_path = gtk_tree_row_reference_get_path (row_reference);
504 gtk_tree_selection_select_path (sel, next_path);
505 gtk_tree_path_free (next_path);
507 if (row_reference != NULL)
508 gtk_tree_row_reference_free (row_reference);
512 printf ("DEBUG: %s: Error: code=%d, text=%s\n", __FUNCTION__, err->code, err->message);
516 /* Update toolbar dimming state */
517 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
520 g_list_foreach (sel_list, (GFunc) gtk_tree_path_free, NULL);
521 g_list_free (sel_list);
527 g_object_unref (header_list);
533 /* delete either message or folder, based on where we are */
535 modest_ui_actions_on_delete_message_or_folder (GtkAction *action, ModestWindow *win)
537 g_return_if_fail (MODEST_IS_WINDOW(win));
539 /* Check first if the header view has the focus */
540 if (MODEST_IS_MAIN_WINDOW (win)) {
542 w = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
543 MODEST_WIDGET_TYPE_FOLDER_VIEW);
544 if (gtk_widget_is_focus (w)) {
545 modest_ui_actions_on_delete_folder (action, MODEST_MAIN_WINDOW(win));
549 modest_ui_actions_on_delete_message (action, win);
555 modest_ui_actions_on_quit (GtkAction *action, ModestWindow *win)
557 #ifdef MODEST_PLATFORM_MAEMO
558 modest_osso_save_state();
559 #endif /* MODEST_PLATFORM_MAEMO */
561 g_debug ("closing down, clearing %d item(s) from operation queue",
562 modest_mail_operation_queue_num_elements
563 (modest_runtime_get_mail_operation_queue()));
565 /* cancel all outstanding operations */
566 modest_mail_operation_queue_cancel_all
567 (modest_runtime_get_mail_operation_queue());
569 g_debug ("queue has been cleared");
571 /* note: when modest-tny-account-store is finalized,
572 it will automatically set all network connections
579 modest_ui_actions_on_close_window (GtkAction *action, ModestWindow *win)
583 g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value);
585 /* if (MODEST_IS_MSG_VIEW_WINDOW (win)) { */
586 /* gtk_widget_destroy (GTK_WIDGET (win)); */
587 /* } else if (MODEST_IS_MSG_EDIT_WINDOW (win)) { */
588 /* gboolean ret_value; */
589 /* g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value); */
590 /* } else if (MODEST_IS_WINDOW (win)) { */
591 /* gtk_widget_destroy (GTK_WIDGET (win)); */
593 /* g_return_if_reached (); */
598 modest_ui_actions_on_add_to_contacts (GtkAction *action, ModestWindow *win)
600 GtkClipboard *clipboard = NULL;
601 gchar *selection = NULL;
603 clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
604 selection = gtk_clipboard_wait_for_text (clipboard);
606 /* Question: why is the clipboard being used here?
607 * It doesn't really make a lot of sense. */
611 modest_address_book_add_address (selection);
617 modest_ui_actions_on_accounts (GtkAction *action, ModestWindow *win)
619 /* This is currently only implemented for Maemo */
620 #ifdef MODEST_PLATFORM_MAEMO /* Defined in config.h */
621 if (!modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE)) {
622 modest_run_account_setup_wizard (win);
625 /* Show the list of accounts: */
626 GtkDialog *account_win = GTK_DIALOG(modest_account_view_window_new ());
627 gtk_window_set_transient_for (GTK_WINDOW (account_win), GTK_WINDOW (win));
629 /* Don't make this a modal window, because secondary windows will then
630 * be unusable, freezing the UI: */
631 /* gtk_window_set_modal (GTK_WINDOW (account_win), TRUE); */
632 modest_maemo_show_dialog_and_forget (GTK_WINDOW (win), account_win);
635 GtkWidget *dialog, *label;
637 /* Create the widgets */
639 dialog = gtk_dialog_new_with_buttons ("Message",
641 GTK_DIALOG_DESTROY_WITH_PARENT,
645 label = gtk_label_new ("Hello World!");
647 /* Ensure that the dialog box is destroyed when the user responds. */
649 g_signal_connect_swapped (dialog, "response",
650 G_CALLBACK (gtk_widget_destroy),
653 /* Add the label, and show everything we've added to the dialog. */
655 gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox),
657 gtk_widget_show_all (dialog);
658 #endif /* MODEST_PLATFORM_MAEMO */
662 on_smtp_servers_window_hide (GtkWindow* window, gpointer user_data)
664 /* Save any changes. */
665 modest_connection_specific_smtp_window_save_server_accounts (
666 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (window));
667 gtk_widget_destroy (GTK_WIDGET (window));
673 modest_ui_actions_on_smtp_servers (GtkAction *action, ModestWindow *win)
675 /* This is currently only implemented for Maemo,
676 * because it requires an API (libconic) to detect different connection
679 #ifdef MODEST_PLATFORM_MAEMO /* Defined in config.h */
681 /* Create the window if necessary: */
682 GtkWidget *specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
683 modest_connection_specific_smtp_window_fill_with_connections (
684 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (specific_window),
685 modest_runtime_get_account_mgr());
687 /* Show the window: */
688 gtk_window_set_transient_for (GTK_WINDOW (specific_window), GTK_WINDOW (win));
689 gtk_window_set_modal (GTK_WINDOW (specific_window), TRUE);
690 gtk_widget_show (specific_window);
692 /* Save changes when the window is hidden: */
693 g_signal_connect (specific_window, "hide",
694 G_CALLBACK (on_smtp_servers_window_hide), win);
695 #endif /* MODEST_PLATFORM_MAEMO */
699 modest_ui_actions_on_new_msg (GtkAction *action, ModestWindow *win)
701 ModestWindow *msg_win = NULL;
703 TnyFolder *folder = NULL;
704 gchar *account_name = NULL;
705 gchar *from_str = NULL;
706 /* GError *err = NULL; */
707 TnyAccount *account = NULL;
708 ModestWindowMgr *mgr;
709 gchar *signature = NULL, *blank_and_signature = NULL;
711 /* if there are no accounts yet, just show the wizard */
712 if (!modest_account_mgr_has_accounts (modest_runtime_get_account_mgr(), TRUE)) {
713 const gboolean created = modest_run_account_setup_wizard (win);
718 account_name = g_strdup (modest_window_get_active_account (win));
720 account_name = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr ());
722 g_printerr ("modest: no account found\n");
726 account = modest_tny_account_store_get_server_account (modest_runtime_get_account_store(),
728 TNY_ACCOUNT_TYPE_STORE);
730 g_printerr ("modest: failed to get tnyaccount for '%s'\n", account_name);
734 from_str = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(), account_name);
736 g_printerr ("modest: failed get from string for '%s'\n", account_name);
740 gboolean use_signature = FALSE;
741 signature = modest_account_mgr_get_signature (modest_runtime_get_account_mgr (), account_name, &use_signature);
744 blank_and_signature = g_strconcat ("\n", signature, NULL);
746 blank_and_signature = g_strdup ("");
751 msg = modest_tny_msg_new ("", from_str, "", "", "", blank_and_signature, NULL);
753 g_printerr ("modest: failed to create new msg\n");
757 folder = modest_tny_account_get_special_folder (account, TNY_FOLDER_TYPE_DRAFTS);
759 g_printerr ("modest: failed to find Drafts folder\n");
764 /* Create and register edit window */
765 /* This is destroyed by TODO. */
766 msg_win = modest_msg_edit_window_new (msg, account_name, FALSE);
767 mgr = modest_runtime_get_window_mgr ();
768 modest_window_mgr_register_window (mgr, msg_win);
771 gtk_window_set_transient_for (GTK_WINDOW (msg_win),
773 gtk_widget_show_all (GTK_WIDGET (msg_win));
776 g_free (account_name);
778 g_free (blank_and_signature);
780 g_object_unref (msg_win);
782 g_object_unref (G_OBJECT(account));
784 g_object_unref (G_OBJECT(msg));
786 g_object_unref (G_OBJECT(folder));
790 modest_ui_actions_msg_retrieval_check (ModestMailOperation *mail_op,
794 ModestMailOperationStatus status;
796 /* If there is no message or the operation was not successful */
797 status = modest_mail_operation_get_status (mail_op);
798 if (!msg || status != MODEST_MAIL_OPERATION_STATUS_SUCCESS) {
800 /* Remove the header from the preregistered uids */
801 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (),
811 open_msg_cb (ModestMailOperation *mail_op, TnyHeader *header, TnyMsg *msg, gpointer user_data)
813 ModestWindowMgr *mgr = NULL;
814 ModestWindow *parent_win = NULL;
815 ModestWindow *win = NULL;
816 TnyFolderType folder_type = TNY_FOLDER_TYPE_UNKNOWN;
817 gchar *account = NULL;
820 /* Do nothing if there was any problem with the mail
821 operation. The error will be shown by the error_handler of
822 the mail operation */
823 if (!modest_ui_actions_msg_retrieval_check (mail_op, header, msg))
826 parent_win = (ModestWindow *) modest_mail_operation_get_source (mail_op);
827 folder = tny_header_get_folder (header);
829 /* Mark header as read */
830 headers_action_mark_as_read (header, MODEST_WINDOW(parent_win), NULL);
833 account = g_strdup (modest_window_get_active_account (MODEST_WINDOW (parent_win)));
835 account = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
837 /* Gets folder type (OUTBOX headers will be opened in edit window */
838 if (modest_tny_folder_is_local_folder (folder))
839 folder_type = modest_tny_folder_get_local_or_mmc_folder_type (folder);
841 /* If the header is in the drafts folder then open the editor,
842 else the message view window */
843 if ((folder_type == TNY_FOLDER_TYPE_DRAFTS) ||
844 (folder_type == TNY_FOLDER_TYPE_OUTBOX)) {
845 /* we cannot edit without a valid account... */
846 if (!modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE)) {
847 const gboolean created = modest_run_account_setup_wizard(parent_win);
851 win = modest_msg_edit_window_new (msg, account, TRUE);
855 modest_platform_information_banner (NULL, NULL, _("mail_ib_opening_draft_message"));
858 gchar *uid = modest_tny_folder_get_header_unique_id (header);
860 if (MODEST_IS_MAIN_WINDOW (parent_win)) {
861 GtkWidget *header_view;
862 GtkTreeSelection *sel;
863 GList *sel_list = NULL;
866 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(parent_win),
867 MODEST_WIDGET_TYPE_HEADER_VIEW);
869 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
870 sel_list = gtk_tree_selection_get_selected_rows (sel, &model);
872 if (sel_list != NULL) {
873 GtkTreeRowReference *row_reference;
875 row_reference = gtk_tree_row_reference_new (model, (GtkTreePath *) sel_list->data);
876 g_list_foreach (sel_list, (GFunc) gtk_tree_path_free, NULL);
877 g_list_free (sel_list);
879 win = modest_msg_view_window_new_with_header_model (
880 msg, account, (const gchar*) uid,
881 model, row_reference);
882 gtk_tree_row_reference_free (row_reference);
884 win = modest_msg_view_window_new_for_attachment (msg, account, (const gchar*) uid);
887 win = modest_msg_view_window_new_for_attachment (msg, account, (const gchar*) uid);
892 /* Register and show new window */
894 mgr = modest_runtime_get_window_mgr ();
895 modest_window_mgr_register_window (mgr, win);
896 g_object_unref (win);
897 gtk_window_set_transient_for (GTK_WINDOW (win), GTK_WINDOW (parent_win));
898 gtk_widget_show_all (GTK_WIDGET(win));
901 /* Update toolbar dimming state */
902 if (MODEST_IS_MAIN_WINDOW (parent_win)) {
903 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (parent_win));
909 g_object_unref (parent_win);
910 g_object_unref (folder);
914 modest_ui_actions_get_msgs_full_error_handler (ModestMailOperation *mail_op,
918 GObject *win = modest_mail_operation_get_source (mail_op);
920 error = modest_mail_operation_get_error (mail_op);
921 printf ("DEBUG: %s: Error: code=%d, text=%s\n", __FUNCTION__, error->code, error->message);
923 if (error->code == MODEST_MAIL_OPERATION_ERROR_MESSAGE_SIZE_LIMIT) {
925 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
928 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
929 _("mail_ni_ui_folder_get_msg_folder_error"));
933 g_object_unref (win);
937 * This function is used by both modest_ui_actions_on_open and
938 * modest_ui_actions_on_header_activated. This way we always do the
939 * same when trying to open messages.
942 _modest_ui_actions_open (TnyList *headers, ModestWindow *win)
944 ModestWindowMgr *mgr = NULL;
945 TnyIterator *iter = NULL;
946 ModestMailOperation *mail_op = NULL;
947 TnyList *not_opened_headers = NULL;
948 TnyHeaderFlags flags = 0;
950 g_return_if_fail (headers != NULL);
952 /* Check that only one message is selected for opening */
953 if (tny_list_get_length (headers) != 1) {
954 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
955 _("mcen_ib_select_one_message"));
960 /* Look if we already have a message view for each header. If
961 true, then remove the header from the list of headers to
963 mgr = modest_runtime_get_window_mgr ();
964 iter = tny_list_create_iterator (headers);
965 not_opened_headers = tny_simple_list_new ();
967 while (!tny_iterator_is_done (iter)) {
969 ModestWindow *window = NULL;
970 TnyHeader *header = NULL;
971 gboolean found = FALSE;
973 header = TNY_HEADER (tny_iterator_get_current (iter));
975 flags = tny_header_get_flags (header);
978 found = modest_window_mgr_find_registered_header (mgr, header, &window);
980 /* Do not open again the message and present the
981 window to the user */
984 gtk_window_present (GTK_WINDOW (window));
986 /* the header has been registered already, we don't do
987 * anything but wait for the window to come up*/
988 g_debug ("header %p already registered, waiting for window", header);
990 tny_list_append (not_opened_headers, G_OBJECT (header));
994 g_object_unref (header);
996 tny_iterator_next (iter);
998 g_object_unref (iter);
1001 /* If some messages would have to be downloaded, ask the user to
1002 * make a connection. It's generally easier to do this here (in the mainloop)
1003 * than later in a thread:
1005 if (tny_list_get_length (not_opened_headers) > 0) {
1007 gboolean found = FALSE;
1009 iter = tny_list_create_iterator (not_opened_headers);
1010 while (!tny_iterator_is_done (iter) && !found) {
1011 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter));
1012 if (!(tny_header_get_flags (header) & TNY_HEADER_FLAG_CACHED))
1015 tny_iterator_next (iter);
1017 g_object_unref (header);
1019 g_object_unref (iter);
1021 if (found && !modest_platform_connect_and_wait (GTK_WINDOW (win), NULL)) {
1022 g_object_unref (not_opened_headers);
1027 /* Register the headers before actually creating the windows: */
1028 TnyIterator *iter_not_opened = tny_list_create_iterator (not_opened_headers);
1029 while (!tny_iterator_is_done (iter_not_opened)) {
1030 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter_not_opened));
1032 modest_window_mgr_register_header (mgr, header);
1033 g_object_unref (header);
1036 tny_iterator_next (iter_not_opened);
1038 g_object_unref (iter_not_opened);
1039 iter_not_opened = NULL;
1041 /* Open each message */
1042 if (tny_list_get_length (not_opened_headers) > 0) {
1043 mail_op = modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE,
1045 modest_ui_actions_get_msgs_full_error_handler,
1047 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
1048 if (tny_list_get_length (not_opened_headers) > 1) {
1049 modest_mail_operation_get_msgs_full (mail_op,
1055 TnyIterator *iter = tny_list_create_iterator (not_opened_headers);
1056 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter));
1057 modest_mail_operation_get_msg (mail_op, header, open_msg_cb, NULL);
1058 g_object_unref (header);
1059 g_object_unref (iter);
1061 g_object_unref (mail_op);
1065 if (not_opened_headers != NULL)
1066 g_object_unref (not_opened_headers);
1070 modest_ui_actions_on_open (GtkAction *action, ModestWindow *win)
1075 headers = get_selected_headers (win);
1080 _modest_ui_actions_open (headers, win);
1082 g_object_unref(headers);
1087 free_reply_forward_helper (gpointer data)
1089 ReplyForwardHelper *helper;
1091 helper = (ReplyForwardHelper *) data;
1092 g_free (helper->account_name);
1093 g_slice_free (ReplyForwardHelper, helper);
1097 reply_forward_cb (ModestMailOperation *mail_op, TnyHeader *header, TnyMsg *msg,
1101 ReplyForwardHelper *rf_helper;
1102 ModestWindow *msg_win = NULL;
1103 ModestEditType edit_type;
1105 TnyAccount *account = NULL;
1106 ModestWindowMgr *mgr = NULL;
1107 gchar *signature = NULL;
1109 /* If there was any error. The mail operation could be NULL,
1110 this means that we already have the message downloaded and
1111 that we didn't do a mail operation to retrieve it */
1112 if (mail_op && !modest_ui_actions_msg_retrieval_check (mail_op, header, msg))
1115 g_return_if_fail (user_data != NULL);
1116 rf_helper = (ReplyForwardHelper *) user_data;
1118 from = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(),
1119 rf_helper->account_name);
1120 if (modest_account_mgr_get_bool (modest_runtime_get_account_mgr(),
1121 rf_helper->account_name,
1122 MODEST_ACCOUNT_USE_SIGNATURE, FALSE)) {
1123 signature = modest_account_mgr_get_string (modest_runtime_get_account_mgr (),
1124 rf_helper->account_name,
1125 MODEST_ACCOUNT_SIGNATURE, FALSE);
1128 /* Create reply mail */
1129 switch (rf_helper->action) {
1132 modest_tny_msg_create_reply_msg (msg, header, from, signature,
1133 rf_helper->reply_forward_type,
1134 MODEST_TNY_MSG_REPLY_MODE_SENDER);
1136 case ACTION_REPLY_TO_ALL:
1138 modest_tny_msg_create_reply_msg (msg, header, from, signature, rf_helper->reply_forward_type,
1139 MODEST_TNY_MSG_REPLY_MODE_ALL);
1140 edit_type = MODEST_EDIT_TYPE_REPLY;
1142 case ACTION_FORWARD:
1144 modest_tny_msg_create_forward_msg (msg, from, signature, rf_helper->reply_forward_type);
1145 edit_type = MODEST_EDIT_TYPE_FORWARD;
1148 g_return_if_reached ();
1155 g_printerr ("modest: failed to create message\n");
1159 account = modest_tny_account_store_get_server_account (modest_runtime_get_account_store(),
1160 rf_helper->account_name,
1161 TNY_ACCOUNT_TYPE_STORE);
1163 g_printerr ("modest: failed to get tnyaccount for '%s'\n", rf_helper->account_name);
1167 /* Create and register the windows */
1168 msg_win = modest_msg_edit_window_new (new_msg, rf_helper->account_name, FALSE);
1169 mgr = modest_runtime_get_window_mgr ();
1170 modest_window_mgr_register_window (mgr, msg_win);
1172 if (rf_helper->parent_window != NULL) {
1173 gdouble parent_zoom;
1175 parent_zoom = modest_window_get_zoom (MODEST_WINDOW (rf_helper->parent_window));
1176 modest_window_set_zoom (msg_win, parent_zoom);
1179 /* Show edit window */
1180 gtk_widget_show_all (GTK_WIDGET (msg_win));
1184 g_object_unref (msg_win);
1186 g_object_unref (G_OBJECT (new_msg));
1188 g_object_unref (G_OBJECT (account));
1189 /* g_object_unref (msg); */
1190 free_reply_forward_helper (rf_helper);
1193 /* Checks a list of headers. If any of them are not currently
1194 * downloaded (CACHED) then returns TRUE else returns FALSE.
1197 header_list_count_uncached_msgs (
1198 TnyList *header_list,
1202 gint uncached_messages = 0;
1204 iter = tny_list_create_iterator (header_list);
1205 while (!tny_iterator_is_done (iter)) {
1208 header = TNY_HEADER (tny_iterator_get_current (iter));
1210 if (!(tny_header_get_flags (header) & TNY_HEADER_FLAG_CACHED))
1211 uncached_messages ++;
1212 g_object_unref (header);
1215 tny_iterator_next (iter);
1217 g_object_unref (iter);
1219 return uncached_messages;
1222 /* Returns FALSE if the user does not want to download the
1223 * messages. Returns TRUE if the user allowed the download.
1226 connect_to_get_msg (GtkWindow *win,
1227 gint num_of_uncached_msgs)
1229 /* Allways download if we are online. */
1230 if (tny_device_is_online (modest_runtime_get_device ()))
1233 /* If offline, then ask for user permission to download the messages */
1234 GtkResponseType response;
1235 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
1236 ngettext("mcen_nc_get_msg",
1238 num_of_uncached_msgs));
1239 if (response == GTK_RESPONSE_CANCEL)
1242 return modest_platform_connect_and_wait(win, NULL);
1246 * Common code for the reply and forward actions
1249 reply_forward (ReplyForwardAction action, ModestWindow *win)
1251 ModestMailOperation *mail_op = NULL;
1252 TnyList *header_list = NULL;
1253 ReplyForwardHelper *rf_helper = NULL;
1254 guint reply_forward_type;
1255 gboolean continue_download = TRUE;
1256 gboolean do_retrieve = TRUE;
1258 g_return_if_fail (MODEST_IS_WINDOW(win));
1260 /* we need an account when editing */
1261 if (!modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE)) {
1262 const gboolean created = modest_run_account_setup_wizard (win);
1267 header_list = get_selected_headers (win);
1271 reply_forward_type =
1272 modest_conf_get_int (modest_runtime_get_conf (),
1273 (action == ACTION_FORWARD) ? MODEST_CONF_FORWARD_TYPE : MODEST_CONF_REPLY_TYPE,
1276 /* check if we need to download msg before asking about it */
1277 do_retrieve = (action == ACTION_FORWARD) ||
1278 (reply_forward_type != MODEST_TNY_MSG_REPLY_TYPE_CITE);
1281 gint num_of_unc_msgs;
1282 /* check that the messages have been previously downloaded */
1283 num_of_unc_msgs = header_list_count_uncached_msgs(
1286 /* If there are any uncached message ask the user
1287 * whether he/she wants to download them. */
1288 if (num_of_unc_msgs)
1289 continue_download = connect_to_get_msg (
1294 if (!continue_download) {
1295 g_object_unref (header_list);
1299 /* We assume that we can only select messages of the
1300 same folder and that we reply all of them from the
1301 same account. In fact the interface currently only
1302 allows single selection */
1305 rf_helper = g_slice_new0 (ReplyForwardHelper);
1306 rf_helper->reply_forward_type = reply_forward_type;
1307 rf_helper->action = action;
1308 rf_helper->account_name = g_strdup (modest_window_get_active_account (win));
1310 if ((win != NULL) && (MODEST_IS_WINDOW (win)))
1311 rf_helper->parent_window = GTK_WIDGET (win);
1312 if (!rf_helper->account_name)
1313 rf_helper->account_name =
1314 modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
1316 if (MODEST_IS_MSG_VIEW_WINDOW(win)) {
1319 /* Get header and message. Do not free them here, the
1320 reply_forward_cb must do it */
1321 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW(win));
1322 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW(win));
1323 if (!msg || !header) {
1325 g_object_unref (msg);
1326 g_printerr ("modest: no message found\n");
1329 reply_forward_cb (NULL, header, msg, rf_helper);
1332 g_object_unref (header);
1337 /* Only reply/forward to one message */
1338 iter = tny_list_create_iterator (header_list);
1339 header = TNY_HEADER (tny_iterator_get_current (iter));
1340 g_object_unref (iter);
1343 /* Retrieve messages */
1345 mail_op = modest_mail_operation_new_with_error_handling (
1346 MODEST_MAIL_OPERATION_TYPE_RECEIVE,
1348 modest_ui_actions_get_msgs_full_error_handler,
1350 modest_mail_operation_queue_add (
1351 modest_runtime_get_mail_operation_queue (), mail_op);
1353 modest_mail_operation_get_msg (mail_op,
1358 g_object_unref(mail_op);
1360 /* we put a ref here to prevent double unref as the reply
1361 * forward callback unrefs the header at its end */
1362 reply_forward_cb (NULL, header, NULL, rf_helper);
1366 g_object_unref (header);
1372 g_object_unref (header_list);
1376 modest_ui_actions_on_reply (GtkAction *action, ModestWindow *win)
1378 g_return_if_fail (MODEST_IS_WINDOW(win));
1380 reply_forward (ACTION_REPLY, win);
1384 modest_ui_actions_on_forward (GtkAction *action, ModestWindow *win)
1386 g_return_if_fail (MODEST_IS_WINDOW(win));
1388 reply_forward (ACTION_FORWARD, win);
1392 modest_ui_actions_on_reply_all (GtkAction *action, ModestWindow *win)
1394 g_return_if_fail (MODEST_IS_WINDOW(win));
1396 reply_forward (ACTION_REPLY_TO_ALL, win);
1400 modest_ui_actions_on_next (GtkAction *action,
1401 ModestWindow *window)
1403 if (MODEST_IS_MAIN_WINDOW (window)) {
1404 GtkWidget *header_view;
1406 header_view = modest_main_window_get_child_widget (
1407 MODEST_MAIN_WINDOW(window),
1408 MODEST_WIDGET_TYPE_HEADER_VIEW);
1412 modest_header_view_select_next (
1413 MODEST_HEADER_VIEW(header_view));
1414 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
1415 modest_msg_view_window_select_next_message (
1416 MODEST_MSG_VIEW_WINDOW (window));
1418 g_return_if_reached ();
1423 modest_ui_actions_on_prev (GtkAction *action,
1424 ModestWindow *window)
1426 g_return_if_fail (MODEST_IS_WINDOW(window));
1428 if (MODEST_IS_MAIN_WINDOW (window)) {
1429 GtkWidget *header_view;
1430 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
1431 MODEST_WIDGET_TYPE_HEADER_VIEW);
1435 modest_header_view_select_prev (MODEST_HEADER_VIEW(header_view));
1436 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
1437 modest_msg_view_window_select_previous_message (MODEST_MSG_VIEW_WINDOW (window));
1439 g_return_if_reached ();
1444 modest_ui_actions_on_sort (GtkAction *action,
1445 ModestWindow *window)
1447 g_return_if_fail (MODEST_IS_WINDOW(window));
1449 if (MODEST_IS_MAIN_WINDOW (window)) {
1450 GtkWidget *header_view;
1451 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
1452 MODEST_WIDGET_TYPE_HEADER_VIEW);
1454 modest_platform_information_banner (NULL, NULL, _CS("ckdg_ib_nothing_to_sort"));
1459 /* Show sorting dialog */
1460 modest_platform_run_sort_dialog (GTK_WINDOW (window), MODEST_SORT_HEADERS);
1465 new_messages_arrived (ModestMailOperation *self,
1469 ModestMainWindow *win = NULL;
1470 GtkWidget *folder_view = NULL;
1471 TnyFolderStore *folder = NULL;
1472 gboolean folder_empty = FALSE;
1474 g_return_if_fail (MODEST_IS_MAIN_WINDOW (user_data));
1475 win = MODEST_MAIN_WINDOW (user_data);
1477 /* Set contents style of headers view */
1478 if (modest_main_window_get_contents_style (win) == MODEST_MAIN_WINDOW_CONTENTS_STYLE_EMPTY) {
1479 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
1480 MODEST_WIDGET_TYPE_FOLDER_VIEW);
1481 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
1484 folder_empty = (tny_folder_get_all_count (TNY_FOLDER (folder)) == 0);
1487 modest_main_window_set_contents_style (win,
1488 MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS);
1491 /* Notify new messages have been downloaded */
1492 if (new_messages > 0)
1493 modest_platform_on_new_msg ();
1497 * This function performs the send & receive required actions. The
1498 * window is used to create the mail operation. Typically it should
1499 * always be the main window, but we pass it as argument in order to
1503 modest_ui_actions_do_send_receive (const gchar *account_name, ModestWindow *win)
1505 gchar *acc_name = NULL;
1506 ModestMailOperation *mail_op;
1508 /* If no account name was provided then get the current account, and if
1509 there is no current account then pick the default one: */
1510 if (!account_name) {
1511 acc_name = g_strdup (modest_window_get_active_account(win));
1513 acc_name = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
1515 g_printerr ("modest: cannot get default account\n");
1519 acc_name = g_strdup (account_name);
1522 /* Set send/receive operation in progress */
1523 modest_main_window_notify_send_receive_initied (MODEST_MAIN_WINDOW(win));
1525 mail_op = modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE,
1527 modest_ui_actions_send_receive_error_handler,
1530 g_signal_connect (G_OBJECT(mail_op), "progress-changed",
1531 G_CALLBACK (_on_send_receive_progress_changed),
1534 /* Send & receive. */
1535 /* TODO: The spec wants us to first do any pending deletions, before receiving. */
1536 /* Receive and then send. The operation is tagged initially as
1537 a receive operation because the account update performs a
1538 receive and then a send. The operation changes its type
1539 internally, so the progress objects will receive the proper
1540 progress information */
1541 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
1542 modest_mail_operation_update_account (mail_op, acc_name, new_messages_arrived, win);
1543 g_object_unref (G_OBJECT (mail_op));
1551 modest_ui_actions_do_cancel_send (const gchar *account_name,
1554 TnyTransportAccount *transport_account;
1555 TnySendQueue *send_queue = NULL;
1556 GError *error = NULL;
1558 /* Get transport account */
1560 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
1561 (modest_runtime_get_account_store(),
1563 TNY_ACCOUNT_TYPE_TRANSPORT));
1564 if (!transport_account) {
1565 g_printerr ("modest: no transport account found for '%s'\n", account_name);
1570 send_queue = TNY_SEND_QUEUE (modest_runtime_get_send_queue (transport_account));
1571 if (!TNY_IS_SEND_QUEUE(send_queue)) {
1572 g_set_error (&error, MODEST_MAIL_OPERATION_ERROR,
1573 MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND,
1574 "modest: could not find send queue for account\n");
1576 /* Keeep messages in outbox folder */
1577 tny_send_queue_cancel (send_queue, FALSE, &error);
1581 if (transport_account != NULL)
1582 g_object_unref (G_OBJECT (transport_account));
1586 modest_ui_actions_cancel_send_all (ModestWindow *win)
1588 GSList *account_names, *iter;
1590 account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
1593 iter = account_names;
1595 modest_ui_actions_do_cancel_send ((const char*) iter->data, win);
1596 iter = g_slist_next (iter);
1599 modest_account_mgr_free_account_names (account_names);
1600 account_names = NULL;
1604 modest_ui_actions_cancel_send (GtkAction *action, ModestWindow *win)
1607 /* Check if accounts exist */
1608 gboolean accounts_exist =
1609 modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
1611 /* If not, allow the user to create an account before trying to send/receive. */
1612 if (!accounts_exist)
1613 modest_ui_actions_on_accounts (NULL, win);
1615 /* Cancel all sending operaitons */
1616 modest_ui_actions_cancel_send_all (win);
1620 * Refreshes all accounts. This function will be used by automatic
1624 modest_ui_actions_do_send_receive_all (ModestWindow *win)
1626 GSList *account_names, *iter;
1628 account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
1631 iter = account_names;
1633 modest_ui_actions_do_send_receive ((const char*) iter->data, win);
1634 iter = g_slist_next (iter);
1637 modest_account_mgr_free_account_names (account_names);
1638 account_names = NULL;
1642 modest_do_refresh_current_folder(ModestWindow *win)
1644 /* Refresh currently selected folder. Note that if we only
1645 want to retreive the headers, then the refresh only will
1646 invoke a poke_status over all folders, i.e., only the
1647 total/unread count will be updated */
1648 if (MODEST_IS_MAIN_WINDOW (win)) {
1649 GtkWidget *header_view, *folder_view;
1650 TnyFolderStore *folder_store;
1652 /* Get folder and header view */
1654 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
1655 MODEST_WIDGET_TYPE_FOLDER_VIEW);
1659 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
1661 if (folder_store && TNY_IS_FOLDER (folder_store)) {
1663 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
1664 MODEST_WIDGET_TYPE_HEADER_VIEW);
1666 /* We do not need to set the contents style
1667 because it hasn't changed. We also do not
1668 need to save the widget status. Just force
1670 modest_header_view_set_folder (MODEST_HEADER_VIEW(header_view),
1671 TNY_FOLDER (folder_store),
1672 folder_refreshed_cb,
1673 MODEST_MAIN_WINDOW (win));
1677 g_object_unref (folder_store);
1683 * Handler of the click on Send&Receive button in the main toolbar
1686 modest_ui_actions_on_send_receive (GtkAction *action, ModestWindow *win)
1688 /* Check if accounts exist */
1689 gboolean accounts_exist =
1690 modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
1692 /* If not, allow the user to create an account before trying to send/receive. */
1693 if (!accounts_exist)
1694 modest_ui_actions_on_accounts (NULL, win);
1696 modest_do_refresh_current_folder (win);
1698 /* Refresh the active account */
1699 modest_ui_actions_do_send_receive (NULL, win);
1704 modest_ui_actions_toggle_header_list_view (GtkAction *action, ModestMainWindow *main_window)
1707 GtkWidget *header_view;
1709 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1711 header_view = modest_main_window_get_child_widget (main_window,
1712 MODEST_WIDGET_TYPE_HEADER_VIEW);
1716 conf = modest_runtime_get_conf ();
1718 /* what is saved/restored is depending on the style; thus; we save with
1719 * old style, then update the style, and restore for this new style
1721 modest_widget_memory_save (conf, G_OBJECT(header_view), MODEST_CONF_HEADER_VIEW_KEY);
1723 if (modest_header_view_get_style
1724 (MODEST_HEADER_VIEW(header_view)) == MODEST_HEADER_VIEW_STYLE_DETAILS)
1725 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
1726 MODEST_HEADER_VIEW_STYLE_TWOLINES);
1728 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
1729 MODEST_HEADER_VIEW_STYLE_DETAILS);
1731 modest_widget_memory_restore (conf, G_OBJECT(header_view),
1732 MODEST_CONF_HEADER_VIEW_KEY);
1737 modest_ui_actions_on_header_selected (ModestHeaderView *header_view,
1739 ModestMainWindow *main_window)
1741 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1742 g_return_if_fail (MODEST_IS_HEADER_VIEW (header_view));
1744 /* in the case the folder is empty, show the empty folder message and focus
1746 if (!header && gtk_widget_is_focus (GTK_WIDGET (header_view))) {
1747 if (modest_header_view_is_empty (header_view)) {
1748 TnyFolder *folder = modest_header_view_get_folder (header_view);
1749 GtkWidget *folder_view =
1750 modest_main_window_get_child_widget (main_window,
1751 MODEST_WIDGET_TYPE_FOLDER_VIEW);
1753 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view), folder, FALSE);
1754 gtk_widget_grab_focus (GTK_WIDGET (folder_view));
1758 /* If no header has been selected then exit */
1763 if (!gtk_widget_is_focus (GTK_WIDGET(header_view)))
1764 gtk_widget_grab_focus (GTK_WIDGET(header_view));
1766 /* Update toolbar dimming state */
1767 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
1771 modest_ui_actions_on_header_activated (ModestHeaderView *header_view,
1773 ModestMainWindow *main_window)
1777 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1783 /* headers = tny_simple_list_new (); */
1784 /* tny_list_prepend (headers, G_OBJECT (header)); */
1785 headers = modest_header_view_get_selected_headers (header_view);
1787 _modest_ui_actions_open (headers, MODEST_WINDOW (main_window));
1789 g_object_unref (headers);
1793 set_active_account_from_tny_account (TnyAccount *account,
1794 ModestWindow *window)
1796 const gchar *server_acc_name = tny_account_get_id (account);
1798 /* We need the TnyAccount provided by the
1799 account store because that is the one that
1800 knows the name of the Modest account */
1801 TnyAccount *modest_server_account = modest_server_account =
1802 modest_tny_account_store_get_tny_account_by (modest_runtime_get_account_store (),
1803 MODEST_TNY_ACCOUNT_STORE_QUERY_ID,
1805 if (!modest_server_account) {
1806 g_warning ("%s: could not get tny account\n", __FUNCTION__);
1810 /* Update active account, but only if it's not a pseudo-account */
1811 if ((!modest_tny_account_is_virtual_local_folders(modest_server_account)) &&
1812 (!modest_tny_account_is_memory_card_account(modest_server_account))) {
1813 const gchar *modest_acc_name =
1814 modest_tny_account_get_parent_modest_account_name_for_server_account (modest_server_account);
1815 if (modest_acc_name)
1816 modest_window_set_active_account (window, modest_acc_name);
1819 g_object_unref (modest_server_account);
1824 folder_refreshed_cb (ModestMailOperation *mail_op,
1828 ModestMainWindow *win = NULL;
1829 GtkWidget *header_view;
1830 gboolean folder_empty = FALSE;
1831 gboolean all_marked_as_deleted = FALSE;
1833 g_return_if_fail (TNY_IS_FOLDER (folder));
1835 win = MODEST_MAIN_WINDOW (user_data);
1837 modest_main_window_get_child_widget(win, MODEST_WIDGET_TYPE_HEADER_VIEW);
1840 TnyFolder *current_folder;
1842 current_folder = modest_header_view_get_folder (MODEST_HEADER_VIEW (header_view));
1843 if (current_folder != NULL && folder != current_folder) {
1844 g_object_unref (current_folder);
1847 g_object_unref (current_folder);
1850 /* Check if folder is empty and set headers view contents style */
1851 folder_empty = (tny_folder_get_all_count (folder) == 0);
1852 all_marked_as_deleted = modest_header_view_is_empty (MODEST_HEADER_VIEW(header_view));
1853 if (folder_empty || all_marked_as_deleted)
1854 modest_main_window_set_contents_style (win,
1855 MODEST_MAIN_WINDOW_CONTENTS_STYLE_EMPTY);
1859 modest_ui_actions_on_folder_selection_changed (ModestFolderView *folder_view,
1860 TnyFolderStore *folder_store,
1862 ModestMainWindow *main_window)
1865 GtkWidget *header_view;
1867 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1869 header_view = modest_main_window_get_child_widget(main_window,
1870 MODEST_WIDGET_TYPE_HEADER_VIEW);
1874 conf = modest_runtime_get_conf ();
1876 if (TNY_IS_ACCOUNT (folder_store)) {
1878 set_active_account_from_tny_account (TNY_ACCOUNT (folder_store), MODEST_WINDOW (main_window));
1880 /* Show account details */
1881 modest_main_window_set_contents_style (main_window, MODEST_MAIN_WINDOW_CONTENTS_STYLE_DETAILS);
1884 if (TNY_IS_FOLDER (folder_store) && selected) {
1886 /* Update the active account */
1887 TnyAccount *account = modest_tny_folder_get_account (TNY_FOLDER (folder_store));
1889 set_active_account_from_tny_account (account, MODEST_WINDOW (main_window));
1890 g_object_unref (account);
1894 /* Set the header style by default, it could
1895 be changed later by the refresh callback to
1897 modest_main_window_set_contents_style (main_window,
1898 MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS);
1900 /* Set folder on header view. This function
1901 will call tny_folder_refresh_async so we
1902 pass a callback that will be called when
1903 finished. We use that callback to set the
1904 empty view if there are no messages */
1905 modest_header_view_set_folder (MODEST_HEADER_VIEW(header_view),
1906 TNY_FOLDER (folder_store),
1907 folder_refreshed_cb,
1910 /* Restore configuration. We need to do this
1911 *after* the set_folder because the widget
1912 memory asks the header view about its
1914 modest_widget_memory_restore (modest_runtime_get_conf (),
1915 G_OBJECT(header_view),
1916 MODEST_CONF_HEADER_VIEW_KEY);
1918 /* Update the active account */
1919 //modest_window_set_active_account (MODEST_WINDOW (main_window), NULL);
1920 /* Save only if we're seeing headers */
1921 if (modest_main_window_get_contents_style (main_window) ==
1922 MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS)
1923 modest_widget_memory_save (conf, G_OBJECT (header_view),
1924 MODEST_CONF_HEADER_VIEW_KEY);
1925 modest_header_view_clear (MODEST_HEADER_VIEW(header_view));
1929 /* Update toolbar dimming state */
1930 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
1934 modest_ui_actions_on_item_not_found (ModestHeaderView *header_view,ModestItemType type,
1941 item = (type == MODEST_ITEM_TYPE_FOLDER) ? "folder" : "message";
1943 online = tny_device_is_online (modest_runtime_get_device());
1946 /* already online -- the item is simply not there... */
1947 dialog = gtk_message_dialog_new (GTK_WINDOW (win),
1949 GTK_MESSAGE_WARNING,
1951 _("The %s you selected cannot be found"),
1953 gtk_dialog_add_button (GTK_DIALOG (dialog),_("mcen_bd_dialog_ok"), GTK_RESPONSE_ACCEPT);
1954 gtk_dialog_run (GTK_DIALOG(dialog));
1956 dialog = gtk_dialog_new_with_buttons (_("Connection requested"),
1959 _("mcen_bd_dialog_cancel"),
1960 GTK_RESPONSE_REJECT,
1961 _("mcen_bd_dialog_ok"),
1962 GTK_RESPONSE_ACCEPT,
1964 txt = g_strdup_printf (_("This %s is not available in offline mode.\n"
1965 "Do you want to get online?"), item);
1966 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
1967 gtk_label_new (txt), FALSE, FALSE, 0);
1968 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
1971 gtk_window_set_default_size (GTK_WINDOW(dialog), 300, 300);
1972 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
1973 /* TODO: Comment about why is this commented out: */
1974 /* modest_platform_connect_and_wait (); */
1977 gtk_widget_destroy (dialog);
1981 modest_ui_actions_on_msg_link_hover (ModestMsgView *msgview, const gchar* link,
1984 /* g_message ("%s %s", __FUNCTION__, link); */
1989 modest_ui_actions_on_msg_link_clicked (ModestMsgView *msgview, const gchar* link,
1992 modest_platform_activate_uri (link);
1996 modest_ui_actions_on_msg_link_contextual (ModestMsgView *msgview, const gchar* link,
1999 modest_platform_show_uri_popup (link);
2003 modest_ui_actions_on_msg_attachment_clicked (ModestMsgView *msgview, TnyMimePart *mime_part,
2006 modest_msg_view_window_view_attachment (MODEST_MSG_VIEW_WINDOW (win), mime_part);
2010 modest_ui_actions_on_msg_recpt_activated (ModestMsgView *msgview,
2011 const gchar *address,
2014 /* g_message ("%s %s", __FUNCTION__, address); */
2018 modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edit_window)
2020 TnyTransportAccount *transport_account;
2021 ModestMailOperation *mail_operation;
2023 gchar *account_name, *from;
2024 ModestAccountMgr *account_mgr;
2025 gchar *info_text = NULL;
2027 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window));
2029 data = modest_msg_edit_window_get_msg_data (edit_window);
2031 account_mgr = modest_runtime_get_account_mgr();
2032 account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
2034 account_name = modest_account_mgr_get_default_account (account_mgr);
2035 if (!account_name) {
2036 g_printerr ("modest: no account found\n");
2037 modest_msg_edit_window_free_msg_data (edit_window, data);
2041 if (!strcmp (account_name, MODEST_LOCAL_FOLDERS_ACCOUNT_ID)) {
2042 account_name = g_strdup (data->account_name);
2046 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
2047 (modest_runtime_get_account_store(),
2049 TNY_ACCOUNT_TYPE_TRANSPORT));
2050 if (!transport_account) {
2051 g_printerr ("modest: no transport account found for '%s'\n", account_name);
2052 g_free (account_name);
2053 modest_msg_edit_window_free_msg_data (edit_window, data);
2056 from = modest_account_mgr_get_from_string (account_mgr, account_name);
2058 /* Create the mail operation */
2059 mail_operation = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_INFO, G_OBJECT(edit_window));
2060 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
2062 modest_mail_operation_save_to_drafts (mail_operation,
2074 data->priority_flags);
2077 g_free (account_name);
2078 g_object_unref (G_OBJECT (transport_account));
2079 g_object_unref (G_OBJECT (mail_operation));
2081 modest_msg_edit_window_free_msg_data (edit_window, data);
2083 info_text = g_strdup_printf (_("mail_va_saved_to_drafts"), _("mcen_me_folder_drafts"));
2084 modest_platform_information_banner (NULL, NULL, info_text);
2088 /* For instance, when clicking the Send toolbar button when editing a message: */
2090 modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
2092 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window));
2094 if (!modest_msg_edit_window_check_names (edit_window, TRUE))
2097 /* Offer the connection dialog, if necessary: */
2098 if (!modest_platform_connect_and_wait (GTK_WINDOW (edit_window), NULL))
2101 /* FIXME: Code added just for testing. The final version will
2102 use the send queue provided by tinymail and some
2104 ModestAccountMgr *account_mgr = modest_runtime_get_account_mgr();
2105 gchar *account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
2107 account_name = modest_account_mgr_get_default_account (account_mgr);
2109 if (!account_name) {
2110 /* Run account setup wizard */
2111 const gboolean created = modest_run_account_setup_wizard(MODEST_WINDOW(edit_window));
2116 MsgData *data = modest_msg_edit_window_get_msg_data (edit_window);
2118 if (!strcmp (account_name, MODEST_LOCAL_FOLDERS_ACCOUNT_ID)) {
2119 account_name = g_strdup (data->account_name);
2122 /* Get the currently-active transport account for this modest account: */
2123 TnyTransportAccount *transport_account =
2124 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_transport_account_for_open_connection
2125 (modest_runtime_get_account_store(),
2127 if (!transport_account) {
2128 /* Run account setup wizard */
2129 const gboolean created = modest_run_account_setup_wizard(MODEST_WINDOW(edit_window));
2134 gchar *from = modest_account_mgr_get_from_string (account_mgr, account_name);
2136 /* Create the mail operation */
2137 ModestMailOperation *mail_operation = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_SEND, G_OBJECT(edit_window));
2138 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
2140 modest_mail_operation_send_new_mail (mail_operation,
2151 data->priority_flags);
2155 g_free (account_name);
2156 g_object_unref (G_OBJECT (transport_account));
2157 g_object_unref (G_OBJECT (mail_operation));
2159 modest_msg_edit_window_free_msg_data (edit_window, data);
2160 modest_msg_edit_window_set_sent (edit_window, TRUE);
2162 /* Save settings and close the window: */
2163 modest_ui_actions_on_close_window (NULL, MODEST_WINDOW (edit_window));
2167 modest_ui_actions_on_toggle_bold (GtkToggleAction *action,
2168 ModestMsgEditWindow *window)
2170 ModestMsgEditFormatState *format_state = NULL;
2172 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2173 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
2175 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2178 format_state = modest_msg_edit_window_get_format_state (window);
2179 g_return_if_fail (format_state != NULL);
2181 format_state->bold = gtk_toggle_action_get_active (action);
2182 modest_msg_edit_window_set_format_state (window, format_state);
2183 g_free (format_state);
2188 modest_ui_actions_on_toggle_italics (GtkToggleAction *action,
2189 ModestMsgEditWindow *window)
2191 ModestMsgEditFormatState *format_state = NULL;
2193 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2194 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
2196 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2199 format_state = modest_msg_edit_window_get_format_state (window);
2200 g_return_if_fail (format_state != NULL);
2202 format_state->italics = gtk_toggle_action_get_active (action);
2203 modest_msg_edit_window_set_format_state (window, format_state);
2204 g_free (format_state);
2209 modest_ui_actions_on_toggle_bullets (GtkToggleAction *action,
2210 ModestMsgEditWindow *window)
2212 ModestMsgEditFormatState *format_state = NULL;
2214 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2215 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
2217 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2220 format_state = modest_msg_edit_window_get_format_state (window);
2221 g_return_if_fail (format_state != NULL);
2223 format_state->bullet = gtk_toggle_action_get_active (action);
2224 modest_msg_edit_window_set_format_state (window, format_state);
2225 g_free (format_state);
2230 modest_ui_actions_on_change_justify (GtkRadioAction *action,
2231 GtkRadioAction *selected,
2232 ModestMsgEditWindow *window)
2234 ModestMsgEditFormatState *format_state = NULL;
2235 GtkJustification value;
2237 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2239 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2242 value = gtk_radio_action_get_current_value (selected);
2244 format_state = modest_msg_edit_window_get_format_state (window);
2245 g_return_if_fail (format_state != NULL);
2247 format_state->justification = value;
2248 modest_msg_edit_window_set_format_state (window, format_state);
2249 g_free (format_state);
2253 modest_ui_actions_on_select_editor_color (GtkAction *action,
2254 ModestMsgEditWindow *window)
2256 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2257 g_return_if_fail (GTK_IS_ACTION (action));
2259 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2262 modest_msg_edit_window_select_color (window);
2266 modest_ui_actions_on_select_editor_background_color (GtkAction *action,
2267 ModestMsgEditWindow *window)
2269 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2270 g_return_if_fail (GTK_IS_ACTION (action));
2272 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2275 modest_msg_edit_window_select_background_color (window);
2279 modest_ui_actions_on_insert_image (GtkAction *action,
2280 ModestMsgEditWindow *window)
2282 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2283 g_return_if_fail (GTK_IS_ACTION (action));
2285 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2288 modest_msg_edit_window_insert_image (window);
2292 modest_ui_actions_on_attach_file (GtkAction *action,
2293 ModestMsgEditWindow *window)
2295 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2296 g_return_if_fail (GTK_IS_ACTION (action));
2298 modest_msg_edit_window_offer_attach_file (window);
2302 modest_ui_actions_on_remove_attachments (GtkAction *action,
2303 ModestMsgEditWindow *window)
2305 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2306 g_return_if_fail (GTK_IS_ACTION (action));
2308 modest_msg_edit_window_remove_attachments (window, NULL);
2312 modest_ui_actions_new_folder_error_handler (ModestMailOperation *mail_op,
2315 ModestMainWindow *window = MODEST_MAIN_WINDOW (user_data);
2316 const GError *error = modest_mail_operation_get_error (mail_op);
2320 modest_platform_information_banner (GTK_WIDGET (window), NULL,
2321 modest_mail_operation_get_error (mail_op)->message);
2326 modest_ui_actions_create_folder(GtkWidget *parent_window,
2327 GtkWidget *folder_view)
2329 TnyFolderStore *parent_folder;
2331 parent_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
2333 if (parent_folder) {
2334 gboolean finished = FALSE;
2336 gchar *folder_name = NULL, *suggested_name = NULL;
2337 const gchar *proto_str = NULL;
2338 TnyAccount *account;
2340 if (TNY_IS_ACCOUNT (parent_folder))
2341 account = g_object_ref (parent_folder);
2343 account = tny_folder_get_account (TNY_FOLDER (parent_folder));
2344 proto_str = tny_account_get_proto (TNY_ACCOUNT (account));
2346 if (proto_str && modest_protocol_info_get_transport_store_protocol (proto_str) ==
2347 MODEST_PROTOCOL_STORE_POP) {
2349 hildon_banner_show_information (NULL, NULL, _("mail_in_ui_folder_create_error"));
2351 g_object_unref (account);
2353 /* Run the new folder dialog */
2355 result = modest_platform_run_new_folder_dialog (GTK_WINDOW (parent_window),
2360 g_free (suggested_name);
2361 suggested_name = NULL;
2363 if (result == GTK_RESPONSE_REJECT) {
2366 ModestMailOperation *mail_op;
2367 TnyFolder *new_folder = NULL;
2369 mail_op = modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_INFO,
2370 G_OBJECT(parent_window),
2371 modest_ui_actions_new_folder_error_handler,
2374 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
2376 new_folder = modest_mail_operation_create_folder (mail_op,
2378 (const gchar *) folder_name);
2380 modest_folder_view_select_folder (MODEST_FOLDER_VIEW(folder_view),
2383 g_object_unref (new_folder);
2386 g_object_unref (mail_op);
2389 suggested_name = folder_name;
2393 g_object_unref (parent_folder);
2398 modest_ui_actions_on_new_folder (GtkAction *action, ModestMainWindow *main_window)
2400 GtkWidget *folder_view;
2402 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2404 folder_view = modest_main_window_get_child_widget (main_window,
2405 MODEST_WIDGET_TYPE_FOLDER_VIEW);
2409 modest_ui_actions_create_folder (GTK_WIDGET (main_window), folder_view);
2413 modest_ui_actions_rename_folder_error_handler (ModestMailOperation *mail_op,
2416 ModestMainWindow *window = MODEST_MAIN_WINDOW (user_data);
2417 const GError *error = NULL;
2418 const gchar *message = NULL;
2420 /* Get error message */
2421 error = modest_mail_operation_get_error (mail_op);
2423 g_return_if_reached ();
2425 switch (error->code) {
2426 case MODEST_MAIL_OPERATION_ERROR_FOLDER_EXISTS:
2427 message = _CS("ckdg_ib_folder_already_exists");
2430 g_return_if_reached ();
2433 modest_platform_information_banner (GTK_WIDGET (window), NULL, message);
2437 modest_ui_actions_on_rename_folder (GtkAction *action,
2438 ModestMainWindow *main_window)
2440 TnyFolderStore *folder;
2441 GtkWidget *folder_view;
2442 GtkWidget *header_view;
2444 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2446 folder_view = modest_main_window_get_child_widget (main_window,
2447 MODEST_WIDGET_TYPE_FOLDER_VIEW);
2451 header_view = modest_main_window_get_child_widget (main_window,
2452 MODEST_WIDGET_TYPE_HEADER_VIEW);
2457 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
2462 if (TNY_IS_FOLDER (folder)) {
2465 const gchar *current_name;
2466 TnyFolderStore *parent;
2467 gboolean do_rename = TRUE;
2469 current_name = tny_folder_get_name (TNY_FOLDER (folder));
2470 parent = tny_folder_get_folder_store (TNY_FOLDER (folder));
2471 response = modest_platform_run_rename_folder_dialog (GTK_WINDOW (main_window),
2472 parent, current_name,
2474 g_object_unref (parent);
2476 if (response != GTK_RESPONSE_ACCEPT || strlen (folder_name) == 0) {
2478 } else if (modest_platform_is_network_folderstore(folder) &&
2479 !tny_device_is_online (modest_runtime_get_device())) {
2480 TnyAccount *account = tny_folder_get_account(TNY_FOLDER(folder));
2481 do_rename = modest_platform_connect_and_wait(GTK_WINDOW(main_window), account);
2482 g_object_unref(account);
2486 ModestMailOperation *mail_op;
2487 GtkTreeSelection *sel = NULL;
2490 modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_INFO,
2491 G_OBJECT(main_window),
2492 modest_ui_actions_rename_folder_error_handler,
2495 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
2498 /* Clear the headers view */
2499 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_view));
2500 gtk_tree_selection_unselect_all (sel);
2502 /* Select *after* the changes */
2503 modest_folder_view_select_folder (MODEST_FOLDER_VIEW(folder_view),
2504 TNY_FOLDER(folder), TRUE);
2506 /* Actually rename the folder */
2507 modest_mail_operation_rename_folder (mail_op,
2508 TNY_FOLDER (folder),
2509 (const gchar *) folder_name);
2511 g_object_unref (mail_op);
2512 g_free (folder_name);
2515 g_object_unref (folder);
2519 modest_ui_actions_delete_folder_error_handler (ModestMailOperation *mail_op,
2522 GObject *win = modest_mail_operation_get_source (mail_op);
2524 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
2525 _("mail_in_ui_folder_delete_error"));
2526 g_object_unref (win);
2530 delete_folder (ModestMainWindow *main_window, gboolean move_to_trash)
2532 TnyFolderStore *folder;
2533 GtkWidget *folder_view;
2536 gboolean do_delete = TRUE;
2538 g_return_if_fail (MODEST_IS_MAIN_WINDOW (main_window));
2540 folder_view = modest_main_window_get_child_widget (main_window,
2541 MODEST_WIDGET_TYPE_FOLDER_VIEW);
2545 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
2547 /* Show an error if it's an account */
2548 if (!TNY_IS_FOLDER (folder)) {
2549 modest_platform_run_information_dialog (GTK_WINDOW (main_window),
2550 _("mail_in_ui_folder_delete_error"));
2551 g_object_unref (G_OBJECT (folder));
2556 message = g_strdup_printf (_("mcen_nc_delete_folder_text"),
2557 tny_folder_get_name (TNY_FOLDER (folder)));
2558 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (main_window),
2559 (const gchar *) message);
2562 if (response != GTK_RESPONSE_OK) {
2564 } else if (modest_platform_is_network_folderstore(folder) &&
2565 !tny_device_is_online (modest_runtime_get_device())) {
2566 TnyAccount *account = tny_folder_get_account(TNY_FOLDER(folder));
2567 do_delete = modest_platform_connect_and_wait(GTK_WINDOW(main_window), account);
2568 g_object_unref(account);
2572 ModestMailOperation *mail_op;
2573 GtkTreeSelection *sel;
2575 /* Unselect the folder before deleting it to free the headers */
2576 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_view));
2577 gtk_tree_selection_unselect_all (sel);
2579 /* Create the mail operation */
2581 modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_DELETE,
2582 G_OBJECT(main_window),
2583 modest_ui_actions_delete_folder_error_handler,
2586 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
2588 modest_mail_operation_remove_folder (mail_op, TNY_FOLDER (folder), move_to_trash);
2589 g_object_unref (G_OBJECT (mail_op));
2592 g_object_unref (G_OBJECT (folder));
2596 modest_ui_actions_on_delete_folder (GtkAction *action,
2597 ModestMainWindow *main_window)
2599 GtkWidget *folder_view;
2600 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2602 delete_folder (main_window, FALSE);
2603 folder_view = modest_main_window_get_child_widget (main_window,
2604 MODEST_WIDGET_TYPE_FOLDER_VIEW);
2607 modest_folder_view_select_first_inbox_or_local (MODEST_FOLDER_VIEW (folder_view));
2611 modest_ui_actions_on_move_folder_to_trash_folder (GtkAction *action, ModestMainWindow *main_window)
2613 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2615 delete_folder (main_window, TRUE);
2620 show_error (GtkWidget *parent_widget, const gchar* text)
2622 hildon_banner_show_information(parent_widget, NULL, text);
2625 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_window, text)); */
2627 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
2634 gtk_dialog_run (dialog);
2635 gtk_widget_destroy (GTK_WIDGET (dialog));
2640 modest_ui_actions_on_password_requested (TnyAccountStore *account_store,
2641 const gchar* server_account_name,
2646 ModestMainWindow *main_window)
2648 g_return_if_fail(server_account_name);
2649 /* printf("DEBUG: %s: server_account_name=%s\n", __FUNCTION__, server_account_name); */
2651 /* Initalize output parameters: */
2658 #ifdef MODEST_PLATFORM_MAEMO
2659 /* Maemo uses a different (awkward) button order,
2660 * It should probably just use gtk_alternative_dialog_button_order ().
2662 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
2665 _("mcen_bd_dialog_ok"),
2666 GTK_RESPONSE_ACCEPT,
2667 _("mcen_bd_dialog_cancel"),
2668 GTK_RESPONSE_REJECT,
2671 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
2675 GTK_RESPONSE_REJECT,
2677 GTK_RESPONSE_ACCEPT,
2679 #endif /* MODEST_PLATFORM_MAEMO */
2681 gtk_window_set_transient_for (GTK_WINDOW(dialog), GTK_WINDOW(main_window));
2683 gchar *server_name = modest_server_account_get_hostname (
2684 modest_runtime_get_account_mgr(), server_account_name);
2685 if (!server_name) {/* This happened once, though I don't know why. murrayc. */
2686 g_warning("%s: Could not get server name for server account '%s'", __FUNCTION__, server_account_name);
2691 /* This causes a warning because the logical ID has no %s in it,
2692 * though the translation does, but there is not much we can do about that: */
2693 gchar *txt = g_strdup_printf (_("mail_ia_password_info"), server_name);
2694 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), gtk_label_new(txt),
2697 g_free (server_name);
2701 gchar *initial_username = modest_server_account_get_username (
2702 modest_runtime_get_account_mgr(), server_account_name);
2704 GtkWidget *entry_username = gtk_entry_new ();
2705 if (initial_username)
2706 gtk_entry_set_text (GTK_ENTRY (entry_username), initial_username);
2707 /* Dim this if a connection has ever succeeded with this username,
2708 * as per the UI spec: */
2709 const gboolean username_known =
2710 modest_server_account_get_username_has_succeeded(
2711 modest_runtime_get_account_mgr(), server_account_name);
2712 gtk_widget_set_sensitive (entry_username, !username_known);
2714 #ifdef MODEST_PLATFORM_MAEMO
2715 /* Auto-capitalization is the default, so let's turn it off: */
2716 hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_username), HILDON_GTK_INPUT_MODE_FULL);
2718 /* Create a size group to be used by all captions.
2719 * Note that HildonCaption does not create a default size group if we do not specify one.
2720 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
2721 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
2723 GtkWidget *caption = hildon_caption_new (sizegroup,
2724 _("mail_fi_username"), entry_username, NULL, HILDON_CAPTION_MANDATORY);
2725 gtk_widget_show (entry_username);
2726 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
2727 FALSE, FALSE, MODEST_MARGIN_HALF);
2728 gtk_widget_show (caption);
2730 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry_username,
2732 #endif /* MODEST_PLATFORM_MAEMO */
2735 GtkWidget *entry_password = gtk_entry_new ();
2736 gtk_entry_set_visibility (GTK_ENTRY(entry_password), FALSE);
2737 /* gtk_entry_set_invisible_char (GTK_ENTRY(entry_password), "*"); */
2739 #ifdef MODEST_PLATFORM_MAEMO
2740 /* Auto-capitalization is the default, so let's turn it off: */
2741 hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_password),
2742 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
2744 caption = hildon_caption_new (sizegroup,
2745 _("mail_fi_password"), entry_password, NULL, HILDON_CAPTION_MANDATORY);
2746 gtk_widget_show (entry_password);
2747 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
2748 FALSE, FALSE, MODEST_MARGIN_HALF);
2749 gtk_widget_show (caption);
2750 g_object_unref (sizegroup);
2752 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry_password,
2754 #endif /* MODEST_PLATFORM_MAEMO */
2756 /* This is not in the Maemo UI spec:
2757 remember_pass_check = gtk_check_button_new_with_label (_("Remember password"));
2758 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), remember_pass_check,
2762 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
2764 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
2766 *username = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_username)));
2768 modest_server_account_set_username (
2769 modest_runtime_get_account_mgr(), server_account_name,
2772 const gboolean username_was_changed =
2773 (strcmp (*username, initial_username) != 0);
2774 if (username_was_changed) {
2775 g_warning ("%s: tinymail does not yet support changing the "
2776 "username in the get_password() callback.\n", __FUNCTION__);
2781 *password = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_password)));
2783 /* We do not save the password in the configuration,
2784 * because this function is only called for passwords that should
2785 * not be remembered:
2786 modest_server_account_set_password (
2787 modest_runtime_get_account_mgr(), server_account_name,
2796 show_error(GTK_WIDGET (main_window), _("mail_ib_login_cancelled"));
2808 /* This is not in the Maemo UI spec:
2809 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (remember_pass_check)))
2815 gtk_widget_destroy (dialog);
2817 /* printf ("DEBUG: %s: cancel=%d\n", __FUNCTION__, *cancel); */
2821 modest_ui_actions_on_cut (GtkAction *action,
2822 ModestWindow *window)
2824 GtkWidget *focused_widget;
2825 GtkClipboard *clipboard;
2827 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
2828 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
2829 if (GTK_IS_EDITABLE (focused_widget)) {
2830 gtk_editable_cut_clipboard (GTK_EDITABLE(focused_widget));
2831 gtk_clipboard_set_can_store (clipboard, NULL, 0);
2832 gtk_clipboard_store (clipboard);
2833 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
2834 GtkTextBuffer *buffer;
2836 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
2837 gtk_text_buffer_cut_clipboard (buffer, clipboard, TRUE);
2838 gtk_clipboard_set_can_store (clipboard, NULL, 0);
2839 gtk_clipboard_store (clipboard);
2840 } else if (MODEST_IS_HEADER_VIEW (focused_widget)) {
2841 TnyList *header_list = modest_header_view_get_selected_headers (
2842 MODEST_HEADER_VIEW (focused_widget));
2843 gboolean continue_download = FALSE;
2844 gint num_of_unc_msgs;
2846 num_of_unc_msgs = header_list_count_uncached_msgs(
2847 header_list, GTK_WINDOW (window));
2849 if (num_of_unc_msgs)
2850 continue_download = connect_to_get_msg(
2851 GTK_WINDOW (window),
2854 if (num_of_unc_msgs == 0 || continue_download) {
2855 /* modest_platform_information_banner (
2856 NULL, NULL, _CS("mcen_ib_getting_items"));*/
2857 modest_header_view_cut_selection (
2858 MODEST_HEADER_VIEW (focused_widget));
2861 g_object_unref (header_list);
2862 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
2863 modest_folder_view_cut_selection (MODEST_FOLDER_VIEW (focused_widget));
2868 modest_ui_actions_on_copy (GtkAction *action,
2869 ModestWindow *window)
2871 GtkClipboard *clipboard;
2872 GtkWidget *focused_widget;
2873 gboolean copied = TRUE;
2875 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
2876 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
2878 if (GTK_IS_LABEL (focused_widget)) {
2879 gtk_clipboard_set_text (clipboard, gtk_label_get_text (GTK_LABEL (focused_widget)), -1);
2880 gtk_clipboard_set_can_store (clipboard, NULL, 0);
2881 gtk_clipboard_store (clipboard);
2882 } else if (GTK_IS_EDITABLE (focused_widget)) {
2883 gtk_editable_copy_clipboard (GTK_EDITABLE(focused_widget));
2884 gtk_clipboard_set_can_store (clipboard, NULL, 0);
2885 gtk_clipboard_store (clipboard);
2886 } else if (GTK_IS_HTML (focused_widget)) {
2887 gtk_html_copy (GTK_HTML (focused_widget));
2888 gtk_clipboard_set_can_store (clipboard, NULL, 0);
2889 gtk_clipboard_store (clipboard);
2890 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
2891 GtkTextBuffer *buffer;
2892 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
2893 gtk_text_buffer_copy_clipboard (buffer, clipboard);
2894 gtk_clipboard_set_can_store (clipboard, NULL, 0);
2895 gtk_clipboard_store (clipboard);
2896 } else if (MODEST_IS_HEADER_VIEW (focused_widget)) {
2897 TnyList *header_list = modest_header_view_get_selected_headers (
2898 MODEST_HEADER_VIEW (focused_widget));
2899 gboolean continue_download = FALSE;
2900 gint num_of_unc_msgs;
2902 num_of_unc_msgs = header_list_count_uncached_msgs(
2904 GTK_WINDOW (window));
2906 if (num_of_unc_msgs)
2907 continue_download = connect_to_get_msg(
2908 GTK_WINDOW (window),
2911 if (num_of_unc_msgs == 0 || continue_download) {
2912 modest_platform_information_banner (
2913 NULL, NULL, _CS("mcen_ib_getting_items"));
2914 modest_header_view_copy_selection (
2915 MODEST_HEADER_VIEW (focused_widget));
2919 g_object_unref (header_list);
2921 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
2922 modest_folder_view_copy_selection (MODEST_FOLDER_VIEW (focused_widget));
2925 /* Show information banner if there was a copy to clipboard */
2927 modest_platform_information_banner (
2928 NULL, NULL, _CS("ecoc_ib_edwin_copied"));
2932 modest_ui_actions_on_undo (GtkAction *action,
2933 ModestWindow *window)
2935 ModestEmailClipboard *clipboard = NULL;
2937 if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
2938 modest_msg_edit_window_undo (MODEST_MSG_EDIT_WINDOW (window));
2939 } else if (MODEST_IS_MAIN_WINDOW (window)) {
2940 /* Clear clipboard source */
2941 clipboard = modest_runtime_get_email_clipboard ();
2942 modest_email_clipboard_clear (clipboard);
2945 g_return_if_reached ();
2950 modest_ui_actions_on_redo (GtkAction *action,
2951 ModestWindow *window)
2953 if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
2954 modest_msg_edit_window_redo (MODEST_MSG_EDIT_WINDOW (window));
2957 g_return_if_reached ();
2963 paste_msgs_cb (const GObject *object, gpointer user_data)
2965 g_return_if_fail (MODEST_IS_MAIN_WINDOW (object));
2966 g_return_if_fail (GTK_IS_WIDGET (user_data));
2968 /* destroy information note */
2969 gtk_widget_destroy (GTK_WIDGET(user_data));
2974 paste_as_attachment_free (gpointer data)
2976 PasteAsAttachmentHelper *helper = (PasteAsAttachmentHelper *) data;
2978 gtk_widget_destroy (helper->banner);
2979 g_object_unref (helper->banner);
2984 paste_msg_as_attachment_cb (ModestMailOperation *mail_op,
2989 PasteAsAttachmentHelper *helper = (PasteAsAttachmentHelper *) userdata;
2990 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (helper->window));
2995 modest_msg_edit_window_add_part (MODEST_MSG_EDIT_WINDOW (helper->window), TNY_MIME_PART (msg));
3000 modest_ui_actions_on_paste (GtkAction *action,
3001 ModestWindow *window)
3003 GtkWidget *focused_widget = NULL;
3004 GtkWidget *inf_note = NULL;
3005 ModestMailOperation *mail_op = NULL;
3007 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
3008 if (GTK_IS_EDITABLE (focused_widget)) {
3009 gtk_editable_paste_clipboard (GTK_EDITABLE(focused_widget));
3010 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
3011 ModestEmailClipboard *e_clipboard = NULL;
3012 e_clipboard = modest_runtime_get_email_clipboard ();
3013 if (modest_email_clipboard_cleared (e_clipboard)) {
3014 GtkTextBuffer *buffer;
3015 GtkClipboard *clipboard;
3017 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
3018 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
3019 gtk_text_buffer_paste_clipboard (buffer, clipboard, NULL, TRUE);
3020 } else if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
3021 ModestMailOperation *mail_op;
3022 TnyFolder *src_folder;
3025 PasteAsAttachmentHelper *helper = g_new0 (PasteAsAttachmentHelper, 1);
3026 helper->window = MODEST_MSG_EDIT_WINDOW (window);
3027 helper->banner = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
3028 _CS("ckct_nw_pasting"));
3029 modest_email_clipboard_get_data (e_clipboard, &src_folder, &data, &delete);
3030 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_RECEIVE,
3032 if (helper->banner != NULL) {
3033 g_object_ref (G_OBJECT (helper->banner));
3034 gtk_window_set_modal (GTK_WINDOW (helper->banner), FALSE);
3035 gtk_widget_show (GTK_WIDGET (helper->banner));
3039 modest_mail_operation_get_msgs_full (mail_op,
3041 (GetMsgAsyncUserCallback) paste_msg_as_attachment_cb,
3043 paste_as_attachment_free);
3046 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
3047 ModestEmailClipboard *clipboard = NULL;
3048 TnyFolder *src_folder = NULL;
3049 TnyFolderStore *folder_store = NULL;
3050 TnyList *data = NULL;
3051 gboolean delete = FALSE;
3053 /* Check clipboard source */
3054 clipboard = modest_runtime_get_email_clipboard ();
3055 if (modest_email_clipboard_cleared (clipboard))
3058 /* Get elements to paste */
3059 modest_email_clipboard_get_data (clipboard, &src_folder, &data, &delete);
3061 /* Create a new mail operation */
3062 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_RECEIVE, G_OBJECT(window));
3064 /* Get destination folder */
3065 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (focused_widget));
3067 /* transfer messages */
3071 /* Ask for user confirmation */
3072 response = msgs_move_to_confirmation (GTK_WINDOW (window),
3073 TNY_FOLDER (folder_store),
3077 if (response == GTK_RESPONSE_OK) {
3078 /* Launch notification */
3079 inf_note = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
3080 _CS("ckct_nw_pasting"));
3081 if (inf_note != NULL) {
3082 gtk_window_set_modal (GTK_WINDOW(inf_note), FALSE);
3083 gtk_widget_show (GTK_WIDGET(inf_note));
3086 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
3087 modest_mail_operation_xfer_msgs (mail_op,
3089 TNY_FOLDER (folder_store),
3094 g_object_unref (mail_op);
3097 } else if (src_folder != NULL) {
3098 /* Launch notification */
3099 inf_note = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
3100 _CS("ckct_nw_pasting"));
3101 if (inf_note != NULL) {
3102 gtk_window_set_modal (GTK_WINDOW(inf_note), FALSE);
3103 gtk_widget_show (GTK_WIDGET(inf_note));
3106 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
3107 modest_mail_operation_xfer_folder (mail_op,
3117 g_object_unref (data);
3118 if (src_folder != NULL)
3119 g_object_unref (src_folder);
3120 if (folder_store != NULL)
3121 g_object_unref (folder_store);
3127 modest_ui_actions_on_select_all (GtkAction *action,
3128 ModestWindow *window)
3130 GtkWidget *focused_widget;
3132 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
3133 if (MODEST_IS_ATTACHMENTS_VIEW (focused_widget)) {
3134 modest_attachments_view_select_all (MODEST_ATTACHMENTS_VIEW (focused_widget));
3135 } else if (GTK_IS_LABEL (focused_widget)) {
3136 gtk_label_select_region (GTK_LABEL (focused_widget), 0, -1);
3137 } else if (GTK_IS_EDITABLE (focused_widget)) {
3138 gtk_editable_select_region (GTK_EDITABLE(focused_widget), 0, -1);
3139 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
3140 GtkTextBuffer *buffer;
3141 GtkTextIter start, end;
3143 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
3144 gtk_text_buffer_get_start_iter (buffer, &start);
3145 gtk_text_buffer_get_end_iter (buffer, &end);
3146 gtk_text_buffer_select_range (buffer, &start, &end);
3147 } else if (GTK_IS_HTML (focused_widget)) {
3148 gtk_html_select_all (GTK_HTML (focused_widget));
3149 } else if (MODEST_IS_MAIN_WINDOW (window)) {
3150 GtkWidget *header_view = focused_widget;
3151 GtkTreeSelection *selection = NULL;
3153 if (!(MODEST_IS_HEADER_VIEW (focused_widget))) {
3154 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (window),
3155 MODEST_WIDGET_TYPE_HEADER_VIEW);
3158 /* Disable window dimming management */
3159 modest_window_disable_dimming (MODEST_WINDOW(window));
3161 /* Select all messages */
3162 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(header_view));
3163 gtk_tree_selection_select_all (selection);
3165 /* Set focuse on header view */
3166 gtk_widget_grab_focus (header_view);
3169 /* Enable window dimming management */
3170 modest_window_enable_dimming (MODEST_WINDOW(window));
3171 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (window));
3177 modest_ui_actions_on_mark_as_read (GtkAction *action,
3178 ModestWindow *window)
3180 g_return_if_fail (MODEST_IS_WINDOW(window));
3182 /* Mark each header as read */
3183 do_headers_action (window, headers_action_mark_as_read, NULL);
3187 modest_ui_actions_on_mark_as_unread (GtkAction *action,
3188 ModestWindow *window)
3190 g_return_if_fail (MODEST_IS_WINDOW(window));
3192 /* Mark each header as read */
3193 do_headers_action (window, headers_action_mark_as_unread, NULL);
3197 modest_ui_actions_on_change_zoom (GtkRadioAction *action,
3198 GtkRadioAction *selected,
3199 ModestWindow *window)
3203 value = gtk_radio_action_get_current_value (selected);
3204 if (MODEST_IS_WINDOW (window)) {
3205 modest_window_set_zoom (MODEST_WINDOW (window), ((gdouble)value)/100);
3210 modest_ui_actions_msg_edit_on_change_priority (GtkRadioAction *action,
3211 GtkRadioAction *selected,
3212 ModestWindow *window)
3214 TnyHeaderFlags flags;
3215 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3217 flags = gtk_radio_action_get_current_value (selected);
3218 modest_msg_edit_window_set_priority_flags (MODEST_MSG_EDIT_WINDOW (window), flags);
3222 modest_ui_actions_msg_edit_on_change_file_format (GtkRadioAction *action,
3223 GtkRadioAction *selected,
3224 ModestWindow *window)
3228 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3230 file_format = gtk_radio_action_get_current_value (selected);
3231 modest_msg_edit_window_set_file_format (MODEST_MSG_EDIT_WINDOW (window), file_format);
3236 modest_ui_actions_on_zoom_plus (GtkAction *action,
3237 ModestWindow *window)
3239 g_return_if_fail (MODEST_IS_WINDOW (window));
3241 modest_window_zoom_plus (MODEST_WINDOW (window));
3245 modest_ui_actions_on_zoom_minus (GtkAction *action,
3246 ModestWindow *window)
3248 g_return_if_fail (MODEST_IS_WINDOW (window));
3250 modest_window_zoom_minus (MODEST_WINDOW (window));
3254 modest_ui_actions_on_toggle_fullscreen (GtkToggleAction *toggle,
3255 ModestWindow *window)
3257 ModestWindowMgr *mgr;
3258 gboolean fullscreen, active;
3259 g_return_if_fail (MODEST_IS_WINDOW (window));
3261 mgr = modest_runtime_get_window_mgr ();
3263 active = (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle)))?1:0;
3264 fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
3266 if (active != fullscreen) {
3267 modest_window_mgr_set_fullscreen_mode (mgr, active);
3268 gtk_window_present (GTK_WINDOW (window));
3273 modest_ui_actions_on_change_fullscreen (GtkAction *action,
3274 ModestWindow *window)
3276 ModestWindowMgr *mgr;
3277 gboolean fullscreen;
3279 g_return_if_fail (MODEST_IS_WINDOW (window));
3281 mgr = modest_runtime_get_window_mgr ();
3282 fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
3283 modest_window_mgr_set_fullscreen_mode (mgr, !fullscreen);
3285 gtk_window_present (GTK_WINDOW (window));
3289 * Used by modest_ui_actions_on_details to call do_headers_action
3292 headers_action_show_details (TnyHeader *header,
3293 ModestWindow *window,
3300 dialog = modest_details_dialog_new_with_header (GTK_WINDOW (window), header);
3303 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
3304 gtk_widget_show_all (dialog);
3305 gtk_dialog_run (GTK_DIALOG (dialog));
3307 gtk_widget_destroy (dialog);
3311 * Show the folder details in a ModestDetailsDialog widget
3314 show_folder_details (TnyFolder *folder,
3320 dialog = modest_details_dialog_new_with_folder (window, folder);
3323 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
3324 gtk_widget_show_all (dialog);
3325 gtk_dialog_run (GTK_DIALOG (dialog));
3327 gtk_widget_destroy (dialog);
3331 * Show the header details in a ModestDetailsDialog widget
3334 modest_ui_actions_on_details (GtkAction *action,
3337 TnyList * headers_list;
3341 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
3344 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW (win));
3347 g_object_unref (msg);
3349 headers_list = get_selected_headers (win);
3353 iter = tny_list_create_iterator (headers_list);
3355 header = TNY_HEADER (tny_iterator_get_current (iter));
3357 headers_action_show_details (header, win, NULL);
3358 g_object_unref (header);
3361 g_object_unref (iter);
3362 g_object_unref (headers_list);
3364 } else if (MODEST_IS_MAIN_WINDOW (win)) {
3365 GtkWidget *folder_view, *header_view;
3367 /* Check which widget has the focus */
3368 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
3369 MODEST_WIDGET_TYPE_FOLDER_VIEW);
3370 if (gtk_widget_is_focus (folder_view)) {
3371 TnyFolderStore *folder_store
3372 = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
3373 if (!folder_store) {
3374 g_warning ("%s: No item was selected.\n", __FUNCTION__);
3377 /* Show only when it's a folder */
3378 /* This function should not be called for account items,
3379 * because we dim the menu item for them. */
3380 if (TNY_IS_FOLDER (folder_store)) {
3381 show_folder_details (TNY_FOLDER (folder_store), GTK_WINDOW (win));
3384 g_object_unref (folder_store);
3387 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
3388 MODEST_WIDGET_TYPE_HEADER_VIEW);
3389 /* Show details of each header */
3390 do_headers_action (win, headers_action_show_details, header_view);
3396 modest_ui_actions_on_toggle_show_cc (GtkToggleAction *toggle,
3397 ModestMsgEditWindow *window)
3399 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3401 modest_msg_edit_window_show_cc (window, gtk_toggle_action_get_active (toggle));
3405 modest_ui_actions_on_toggle_show_bcc (GtkToggleAction *toggle,
3406 ModestMsgEditWindow *window)
3408 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3410 modest_msg_edit_window_show_bcc (window, gtk_toggle_action_get_active (toggle));
3414 modest_ui_actions_toggle_folders_view (GtkAction *action,
3415 ModestMainWindow *main_window)
3417 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
3419 if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)))
3420 modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SPLIT);
3422 modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SIMPLE);
3426 modest_ui_actions_on_toggle_toolbar (GtkToggleAction *toggle,
3427 ModestWindow *window)
3429 gboolean active, fullscreen = FALSE;
3430 ModestWindowMgr *mgr;
3432 active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle));
3434 /* Check if we want to toggle the toolbar vuew in fullscreen
3436 if (!strcmp (gtk_action_get_name (GTK_ACTION (toggle)),
3437 "ViewShowToolbarFullScreen")) {
3441 /* Toggle toolbar */
3442 mgr = modest_runtime_get_window_mgr ();
3443 modest_window_mgr_show_toolbars (mgr, G_TYPE_FROM_INSTANCE (window), active, fullscreen);
3447 modest_ui_actions_msg_edit_on_select_font (GtkAction *action,
3448 ModestMsgEditWindow *window)
3450 modest_msg_edit_window_select_font (window);
3454 modest_ui_actions_on_folder_display_name_changed (ModestFolderView *folder_view,
3455 const gchar *display_name,
3458 /* Do not change the application name if the widget has not
3459 the focus. This callback could be called even if the folder
3460 view has not the focus, because the handled signal could be
3461 emitted when the folder view is redrawn */
3462 if (gtk_widget_is_focus (GTK_WIDGET (folder_view))) {
3464 gtk_window_set_title (window, display_name);
3466 gtk_window_set_title (window, " ");
3471 modest_ui_actions_on_select_contacts (GtkAction *action, ModestMsgEditWindow *window)
3473 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3474 modest_msg_edit_window_select_contacts (window);
3478 modest_ui_actions_on_check_names (GtkAction *action, ModestMsgEditWindow *window)
3480 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3481 modest_msg_edit_window_check_names (window, FALSE);
3485 create_move_to_dialog_on_new_folder(GtkWidget *button, gpointer user_data)
3487 modest_ui_actions_create_folder (gtk_widget_get_toplevel (button),
3488 GTK_WIDGET (user_data));
3492 * This function is used to track changes in the selection of the
3493 * folder view that is inside the "move to" dialog to enable/disable
3494 * the OK button because we do not want the user to select a disallowed
3495 * destination for a folder.
3496 * The user also not desired to be able to use NEW button on items where
3497 * folder creation is not possibel.
3500 on_move_to_dialog_folder_selection_changed (ModestFolderView* self,
3501 TnyFolderStore *folder_store,
3505 GtkWidget *dialog = NULL;
3506 GtkWidget *ok_button = NULL, *new_button = NULL;
3507 GList *children = NULL;
3508 gboolean ok_sensitive = TRUE, new_sensitive = TRUE;
3509 gboolean moving_folder = FALSE;
3510 gboolean is_local_account = TRUE;
3511 GtkWidget *folder_view = NULL;
3512 ModestTnyFolderRules rules;
3517 /* Get the OK button */
3518 dialog = gtk_widget_get_ancestor (GTK_WIDGET (self), GTK_TYPE_DIALOG);
3522 children = gtk_container_get_children (GTK_CONTAINER (GTK_DIALOG (dialog)->action_area));
3523 ok_button = GTK_WIDGET (children->next->next->data);
3524 new_button = GTK_WIDGET (children->next->data);
3525 g_list_free (children);
3527 /* check if folder_store is an remote account */
3528 if (TNY_IS_ACCOUNT (folder_store)) {
3529 TnyAccount *local_account = NULL;
3530 ModestTnyAccountStore *account_store = NULL;
3532 account_store = modest_runtime_get_account_store ();
3533 local_account = modest_tny_account_store_get_local_folders_account (account_store);
3535 if ((gpointer) local_account != (gpointer) folder_store) {
3536 is_local_account = FALSE;
3537 /* New button should be dimmed on remote
3539 new_sensitive = FALSE;
3541 g_object_unref (local_account);
3544 /* Check the target folder rules */
3545 if (TNY_IS_FOLDER (folder_store)) {
3546 rules = modest_tny_folder_get_rules (TNY_FOLDER (folder_store));
3547 if (rules & MODEST_FOLDER_RULES_FOLDER_NON_WRITEABLE) {
3548 ok_sensitive = FALSE;
3549 new_sensitive = FALSE;
3554 /* Check if we're moving a folder */
3555 if (MODEST_IS_MAIN_WINDOW (user_data)) {
3556 /* Get the widgets */
3557 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (user_data),
3558 MODEST_WIDGET_TYPE_FOLDER_VIEW);
3559 if (gtk_widget_is_focus (folder_view))
3560 moving_folder = TRUE;
3563 if (moving_folder) {
3564 TnyFolderStore *moved_folder = NULL, *parent = NULL;
3566 /* Get the folder to move */
3567 moved_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
3569 /* Check that we're not moving to the same folder */
3570 if (TNY_IS_FOLDER (moved_folder)) {
3571 parent = tny_folder_get_folder_store (TNY_FOLDER (moved_folder));
3572 if (parent == folder_store)
3573 ok_sensitive = FALSE;
3574 g_object_unref (parent);
3577 if (ok_sensitive && TNY_IS_ACCOUNT (folder_store)) {
3578 /* Do not allow to move to an account unless it's the
3579 local folders account */
3580 if (!is_local_account)
3581 ok_sensitive = FALSE;
3584 if (ok_sensitive && (moved_folder == folder_store)) {
3585 /* Do not allow to move to itself */
3586 ok_sensitive = FALSE;
3588 g_object_unref (moved_folder);
3590 TnyHeader *header = NULL;
3591 TnyFolder *src_folder = NULL;
3593 /* Moving a message */
3594 if (MODEST_IS_MSG_VIEW_WINDOW (user_data)) {
3595 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (user_data));
3596 src_folder = tny_header_get_folder (header);
3597 g_object_unref (header);
3600 TNY_FOLDER (modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view)));
3603 /* Do not allow to move the msg to the same folder */
3604 /* Do not allow to move the msg to an account */
3605 if ((gpointer) src_folder == (gpointer) folder_store ||
3606 TNY_IS_ACCOUNT (folder_store))
3607 ok_sensitive = FALSE;
3608 g_object_unref (src_folder);
3612 /* Set sensitivity of the OK button */
3613 gtk_widget_set_sensitive (ok_button, ok_sensitive);
3614 /* Set sensitivity of the NEW button */
3615 gtk_widget_set_sensitive (new_button, new_sensitive);
3619 create_move_to_dialog (GtkWindow *win,
3620 GtkWidget *folder_view,
3621 GtkWidget **tree_view)
3623 GtkWidget *dialog, *scroll;
3624 GtkWidget *new_button;
3626 dialog = gtk_dialog_new_with_buttons (_("mcen_ti_moveto_folders_title"),
3628 GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR | GTK_DIALOG_DESTROY_WITH_PARENT,
3631 gtk_dialog_add_button (GTK_DIALOG (dialog), _("mcen_bd_dialog_ok"), GTK_RESPONSE_ACCEPT);
3632 /* We do this manually so GTK+ does not associate a response ID for
3634 new_button = gtk_button_new_from_stock (_("mcen_bd_new"));
3635 gtk_box_pack_end (GTK_BOX (GTK_DIALOG (dialog)->action_area), new_button, FALSE, FALSE, 0);
3636 gtk_dialog_add_button (GTK_DIALOG (dialog), _("mcen_bd_dialog_cancel"), GTK_RESPONSE_REJECT);
3638 /* Create scrolled window */
3639 scroll = gtk_scrolled_window_new (NULL, NULL);
3640 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll),
3641 GTK_POLICY_AUTOMATIC,
3642 GTK_POLICY_AUTOMATIC);
3644 /* Create folder view */
3645 *tree_view = modest_platform_create_folder_view (NULL);
3647 /* Track changes in the selection to
3648 * disable the OK button whenever "Move to" is not possible
3649 * disbale NEW button whenever New is not possible */
3650 g_signal_connect (*tree_view,
3651 "folder_selection_changed",
3652 G_CALLBACK (on_move_to_dialog_folder_selection_changed),
3655 /* Listen to clicks on New button */
3656 g_signal_connect (G_OBJECT (new_button),
3658 G_CALLBACK(create_move_to_dialog_on_new_folder),
3661 /* It could happen that we're trying to move a message from a
3662 window (msg window for example) after the main window was
3663 closed, so we can not just get the model of the folder
3665 if (MODEST_IS_FOLDER_VIEW (folder_view)) {
3666 const gchar *visible_id = NULL;
3668 modest_folder_view_copy_model (MODEST_FOLDER_VIEW(folder_view),
3669 MODEST_FOLDER_VIEW(*tree_view));
3672 modest_folder_view_get_account_id_of_visible_server_account (MODEST_FOLDER_VIEW(folder_view));
3674 /* Show the same account than the one that is shown in the main window */
3675 modest_folder_view_set_account_id_of_visible_server_account (MODEST_FOLDER_VIEW(*tree_view),
3678 const gchar *active_account_name = NULL;
3679 ModestAccountMgr *mgr = NULL;
3680 ModestAccountData *acc_data = NULL;
3682 modest_folder_view_update_model (MODEST_FOLDER_VIEW (*tree_view),
3683 TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()));
3685 active_account_name = modest_window_get_active_account (MODEST_WINDOW (win));
3686 mgr = modest_runtime_get_account_mgr ();
3687 acc_data = modest_account_mgr_get_account_data (mgr, active_account_name);
3689 /* Set the new visible & active account */
3690 if (acc_data && acc_data->store_account) {
3691 modest_folder_view_set_account_id_of_visible_server_account (MODEST_FOLDER_VIEW (*tree_view),
3692 acc_data->store_account->account_name);
3693 modest_account_mgr_free_account_data (mgr, acc_data);
3697 /* Hide special folders */
3698 modest_folder_view_show_non_move_folders (MODEST_FOLDER_VIEW (*tree_view), FALSE);
3700 gtk_container_add (GTK_CONTAINER (scroll), *tree_view);
3702 /* Add scroll to dialog */
3703 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
3704 scroll, TRUE, TRUE, 0);
3706 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
3707 gtk_window_set_default_size (GTK_WINDOW (dialog), 300, 300);
3713 * Returns TRUE if at least one of the headers of the list belongs to
3714 * a message that has been fully retrieved.
3716 #if 0 /* no longer in use. delete in 2007.10 */
3718 has_retrieved_msgs (TnyList *list)
3721 gboolean found = FALSE;
3723 iter = tny_list_create_iterator (list);
3724 while (!tny_iterator_is_done (iter) && !found) {
3726 TnyHeaderFlags flags = 0;
3728 header = TNY_HEADER (tny_iterator_get_current (iter));
3730 flags = tny_header_get_flags (header);
3731 if (flags & TNY_HEADER_FLAG_CACHED)
3732 /* if (!(flags & TNY_HEADER_FLAG_PARTIAL)) */
3735 g_object_unref (header);
3739 tny_iterator_next (iter);
3741 g_object_unref (iter);
3749 * Shows a confirmation dialog to the user when we're moving messages
3750 * from a remote server to the local storage. Returns the dialog
3751 * response. If it's other kind of movement then it always returns
3754 * This one is used by the next functions:
3755 * modest_ui_actions_xfer_messages_from_move_to
3756 * modest_ui_actions_on_paste - commented out
3757 * drag_and_drop_from_header_view (for d&d in modest_folder_view.c)
3760 msgs_move_to_confirmation (GtkWindow *win,
3761 TnyFolder *dest_folder,
3765 gint response = GTK_RESPONSE_OK;
3767 /* return with OK if the destination is a remote folder */
3768 if (modest_tny_folder_is_remote_folder (dest_folder))
3769 return GTK_RESPONSE_OK;
3771 TnyFolder *src_folder = NULL;
3772 TnyIterator *iter = NULL;
3773 TnyHeader *header = NULL;
3775 /* Get source folder */
3776 iter = tny_list_create_iterator (headers);
3777 header = TNY_HEADER (tny_iterator_get_current (iter));
3779 src_folder = tny_header_get_folder (header);
3780 g_object_unref (header);
3782 g_object_unref (iter);
3784 /* if no src_folder, message may be an attahcment */
3785 if (src_folder == NULL)
3786 return GTK_RESPONSE_CANCEL;
3788 /* If the source is a local or MMC folder */
3789 if (!modest_tny_folder_is_remote_folder (src_folder)) {
3790 g_object_unref (src_folder);
3791 return GTK_RESPONSE_OK;
3793 g_object_unref (src_folder);
3795 /* now if offline we ask the user */
3796 if(connect_to_get_msg( GTK_WINDOW (win),
3797 tny_list_get_length (headers)))
3798 response = GTK_RESPONSE_OK;
3800 response = GTK_RESPONSE_CANCEL;
3808 move_to_cb (const GObject *object, gpointer user_data)
3810 ModestMsgViewWindow *self = NULL;
3811 g_return_if_fail (GTK_IS_WIDGET (user_data));
3812 g_return_if_fail (MODEST_IS_WINDOW (object));
3814 if (MODEST_IS_MSG_VIEW_WINDOW (object)) {
3815 self = MODEST_MSG_VIEW_WINDOW (object);
3817 if (!modest_msg_view_window_select_next_message (self))
3818 if (!modest_msg_view_window_select_previous_message (self))
3819 /* No more messages to view, so close this window */
3820 modest_ui_actions_on_close_window (NULL, MODEST_WINDOW(self));
3822 gtk_widget_destroy (GTK_WIDGET(user_data));
3826 modest_ui_actions_move_folder_error_handler (ModestMailOperation *mail_op,
3829 ModestMainWindow *main_window = NULL;
3830 GtkWidget *folder_view = NULL;
3831 GObject *win = modest_mail_operation_get_source (mail_op);
3832 const GError *error = NULL;
3833 const gchar *message = NULL;
3835 /* Get error message */
3836 error = modest_mail_operation_get_error (mail_op);
3837 if (error != NULL && error->message != NULL) {
3838 message = error->message;
3840 message = _("mail_in_ui_folder_move_target_error");
3843 /* Disable next automatic folder selection */
3844 if (MODEST_IS_MAIN_WINDOW (user_data)) {
3845 main_window = MODEST_MAIN_WINDOW(user_data);
3846 folder_view = modest_main_window_get_child_widget (main_window,
3847 MODEST_WIDGET_TYPE_FOLDER_VIEW);
3848 modest_folder_view_disable_next_folder_selection (MODEST_FOLDER_VIEW(folder_view));
3851 /* Show notification dialog */
3852 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL, message);
3853 g_object_unref (win);
3857 modest_ui_actions_send_receive_error_handler (ModestMailOperation *mail_op,
3860 GObject *win = modest_mail_operation_get_source (mail_op);
3861 const GError *error = modest_mail_operation_get_error (mail_op);
3863 g_return_if_fail (error != NULL);
3864 if (error->message != NULL)
3865 g_printerr ("modest: %s\n", error->message);
3867 g_printerr ("modest: unkonw error on send&receive operation");
3869 /* Show error message */
3870 /* if (modest_mail_operation_get_id (mail_op) == MODEST_MAIL_OPERATION_TYPE_RECEIVE) */
3871 /* modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL, */
3872 /* _CS("sfil_ib_unable_to_receive")); */
3874 /* modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL, */
3875 /* _CS("sfil_ib_unable_to_send")); */
3876 g_object_unref (win);
3880 open_msg_for_purge_cb (ModestMailOperation *mail_op,
3887 gint pending_purges = 0;
3888 gboolean some_purged = FALSE;
3889 ModestWindow *win = MODEST_WINDOW (user_data);
3890 ModestWindowMgr *mgr = modest_runtime_get_window_mgr ();
3892 /* If there was any error */
3893 if (!modest_ui_actions_msg_retrieval_check (mail_op, header, msg)) {
3894 modest_window_mgr_unregister_header (mgr, header);
3898 /* Once the message has been retrieved for purging, we check if
3899 * it's all ok for purging */
3901 parts = tny_simple_list_new ();
3902 tny_mime_part_get_parts (TNY_MIME_PART (msg), parts);
3903 iter = tny_list_create_iterator (parts);
3905 while (!tny_iterator_is_done (iter)) {
3907 part = TNY_MIME_PART (tny_iterator_get_current (iter));
3908 if (part && (tny_mime_part_is_attachment (part) || TNY_IS_MSG (part))) {
3909 if (tny_mime_part_is_purged (part))
3916 g_object_unref (part);
3918 tny_iterator_next (iter);
3921 if (pending_purges>0) {
3923 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),_("mcen_nc_purge_file_text_inbox"));
3925 if (response == GTK_RESPONSE_OK) {
3926 modest_platform_information_banner (NULL, NULL, _("mcen_ib_removing_attachment"));
3927 tny_iterator_first (iter);
3928 while (!tny_iterator_is_done (iter)) {
3931 part = TNY_MIME_PART (tny_iterator_get_current (iter));
3932 if (part && (tny_mime_part_is_attachment (part) || TNY_IS_MSG (part)))
3933 tny_mime_part_set_purged (part);
3936 g_object_unref (part);
3938 tny_iterator_next (iter);
3941 tny_msg_rewrite_cache (msg);
3944 modest_platform_information_banner (NULL, NULL, _("mail_ib_attachment_already_purged"));
3947 /* remove attachments */
3948 tny_iterator_first (iter);
3949 while (!tny_iterator_is_done (iter)) {
3952 part = TNY_MIME_PART (tny_iterator_get_current (iter));
3954 /* One for the reference given by tny_iterator_get_current(): */
3955 g_object_unref (part);
3957 /* TODO: Is this meant to remove the attachment by doing another unref()?
3958 * Otherwise, this seems useless. */
3961 tny_iterator_next (iter);
3963 modest_window_mgr_unregister_header (mgr, header);
3965 g_object_unref (iter);
3966 g_object_unref (parts);
3970 modest_ui_actions_on_main_window_remove_attachments (GtkAction *action,
3971 ModestMainWindow *win)
3973 GtkWidget *header_view;
3974 TnyList *header_list;
3977 TnyHeaderFlags flags;
3978 ModestWindow *msg_view_window = NULL;
3981 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win));
3983 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
3984 MODEST_WIDGET_TYPE_HEADER_VIEW);
3986 header_list = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW (header_view));
3988 if (tny_list_get_length (header_list) == 1) {
3989 iter = tny_list_create_iterator (header_list);
3990 header = TNY_HEADER (tny_iterator_get_current (iter));
3991 g_object_unref (iter);
3996 found = modest_window_mgr_find_registered_header (modest_runtime_get_window_mgr (),
3997 header, &msg_view_window);
3998 flags = tny_header_get_flags (header);
3999 if (!(flags & TNY_HEADER_FLAG_CACHED))
4002 if (msg_view_window != NULL)
4003 modest_msg_view_window_remove_attachments (MODEST_MSG_VIEW_WINDOW (msg_view_window), TRUE);
4005 /* do nothing; uid was registered before, so window is probably on it's way */
4006 g_warning ("debug: header %p has already been registered", header);
4009 ModestMailOperation *mail_op = NULL;
4010 modest_window_mgr_register_header (modest_runtime_get_window_mgr (), header);
4011 mail_op = modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE,
4013 modest_ui_actions_get_msgs_full_error_handler,
4015 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
4016 modest_mail_operation_get_msg (mail_op, header, open_msg_for_purge_cb, win);
4018 g_object_unref (mail_op);
4021 g_object_unref (header);
4023 g_object_unref (header_list);
4027 * Utility function that transfer messages from both the main window
4028 * and the msg view window when using the "Move to" dialog
4031 modest_ui_actions_xfer_messages_from_move_to (TnyFolderStore *dst_folder,
4034 TnyList *headers = NULL;
4036 TnyAccount *dst_account = NULL;
4037 const gchar *proto_str = NULL;
4038 gboolean dst_is_pop = FALSE;
4040 if (!TNY_IS_FOLDER (dst_folder)) {
4041 modest_platform_information_banner (GTK_WIDGET (win),
4043 _CS("ckdg_ib_unable_to_move_to_current_location"));
4047 dst_account = tny_folder_get_account (TNY_FOLDER (dst_folder));
4048 proto_str = tny_account_get_proto (dst_account);
4050 /* tinymail will return NULL for local folders it seems */
4051 dst_is_pop = proto_str &&
4052 (modest_protocol_info_get_transport_store_protocol (proto_str) ==
4053 MODEST_PROTOCOL_STORE_POP);
4055 g_object_unref (dst_account);
4057 /* Get selected headers */
4058 headers = get_selected_headers (MODEST_WINDOW (win));
4061 modest_platform_information_banner (GTK_WIDGET (win),
4063 ngettext("mail_in_ui_folder_move_target_error",
4064 "mail_in_ui_folder_move_targets_error",
4065 tny_list_get_length (headers)));
4066 g_object_unref (headers);
4070 /* Ask for user confirmation */
4071 response = msgs_move_to_confirmation (GTK_WINDOW (win),
4072 TNY_FOLDER (dst_folder),
4076 /* Transfer messages */
4077 if (response == GTK_RESPONSE_OK) {
4078 GtkWidget *inf_note;
4079 inf_note = modest_platform_animation_banner (GTK_WIDGET (win), NULL,
4080 _CS("ckct_nw_pasting"));
4081 if (inf_note != NULL) {
4082 gtk_window_set_modal (GTK_WINDOW(inf_note), FALSE);
4083 gtk_widget_show (GTK_WIDGET(inf_note));
4086 ModestMailOperation *mail_op =
4087 modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE,
4089 modest_ui_actions_move_folder_error_handler,
4091 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
4094 modest_mail_operation_xfer_msgs (mail_op,
4096 TNY_FOLDER (dst_folder),
4101 g_object_unref (G_OBJECT (mail_op));
4103 g_object_unref (headers);
4107 * UI handler for the "Move to" action when invoked from the
4111 modest_ui_actions_on_main_window_move_to (GtkAction *action,
4112 GtkWidget *folder_view,
4113 TnyFolderStore *dst_folder,
4114 ModestMainWindow *win)
4116 ModestHeaderView *header_view = NULL;
4117 ModestMailOperation *mail_op = NULL;
4118 TnyFolderStore *src_folder;
4119 gboolean online = (tny_device_is_online (modest_runtime_get_device()));
4121 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win));
4123 /* Get the source folder */
4124 src_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
4126 /* Get header view */
4127 header_view = MODEST_HEADER_VIEW(modest_main_window_get_child_widget (win, MODEST_WIDGET_TYPE_HEADER_VIEW));
4129 /* Get folder or messages to transfer */
4130 if (gtk_widget_is_focus (folder_view)) {
4131 GtkTreeSelection *sel;
4132 gboolean do_xfer = TRUE;
4134 /* Allow only to transfer folders to the local root folder */
4135 if (TNY_IS_ACCOUNT (dst_folder) &&
4136 !MODEST_IS_TNY_LOCAL_FOLDERS_ACCOUNT (dst_folder)) {
4138 } else if (!TNY_IS_FOLDER (src_folder)) {
4139 g_warning ("%s: src_folder is not a TnyFolder.\n", __FUNCTION__);
4141 } else if (!online && modest_platform_is_network_folderstore(src_folder)) {
4142 guint num_headers = tny_folder_get_all_count(TNY_FOLDER(src_folder));
4143 if (!connect_to_get_msg(GTK_WINDOW(win), num_headers)) {
4149 GtkWidget *inf_note;
4150 inf_note = modest_platform_animation_banner (GTK_WIDGET (win), NULL,
4151 _CS("ckct_nw_pasting"));
4152 if (inf_note != NULL) {
4153 gtk_window_set_modal (GTK_WINDOW(inf_note), FALSE);
4154 gtk_widget_show (GTK_WIDGET(inf_note));
4156 /* Clean folder on header view before moving it */
4157 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_view));
4158 gtk_tree_selection_unselect_all (sel);
4161 modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE,
4163 modest_ui_actions_move_folder_error_handler,
4165 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
4168 /* Select *after* the changes */
4169 /* TODO: this function hangs UI after transfer */
4170 /* modest_folder_view_select_folder (MODEST_FOLDER_VIEW(folder_view), */
4171 /* TNY_FOLDER (src_folder), TRUE); */
4173 modest_mail_operation_xfer_folder (mail_op,
4174 TNY_FOLDER (src_folder),
4176 TRUE, move_to_cb, inf_note);
4177 /* Unref mail operation */
4178 g_object_unref (G_OBJECT (mail_op));
4180 } else if (gtk_widget_is_focus (GTK_WIDGET(header_view))) {
4181 gboolean do_xfer = TRUE;
4182 /* Ask for confirmation if the source folder is remote and we're not connected */
4183 if (!online && modest_platform_is_network_folderstore(src_folder)) {
4184 guint num_headers = modest_header_view_count_selected_headers(header_view);
4185 if (!connect_to_get_msg(GTK_WINDOW(win), num_headers)) {
4189 if (do_xfer) /* Transfer messages */
4190 modest_ui_actions_xfer_messages_from_move_to (dst_folder, MODEST_WINDOW (win));
4194 g_object_unref (src_folder);
4199 * UI handler for the "Move to" action when invoked from the
4200 * ModestMsgViewWindow
4203 modest_ui_actions_on_msg_view_window_move_to (GtkAction *action,
4204 TnyFolderStore *dst_folder,
4205 ModestMsgViewWindow *win)
4207 TnyHeader *header = NULL;
4208 TnyFolderStore *src_folder;
4210 /* Create header list */
4211 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
4212 src_folder = TNY_FOLDER_STORE(tny_header_get_folder(header));
4213 g_object_unref (header);
4215 /* Transfer the message if online or confirmed by the user */
4216 if (tny_device_is_online (modest_runtime_get_device()) ||
4217 (modest_platform_is_network_folderstore(src_folder) && connect_to_get_msg(GTK_WINDOW(win), 1))) {
4218 modest_ui_actions_xfer_messages_from_move_to (dst_folder, MODEST_WINDOW (win));
4221 g_object_unref (src_folder);
4225 modest_ui_actions_on_move_to (GtkAction *action,
4228 GtkWidget *dialog = NULL, *folder_view = NULL, *tree_view = NULL;
4230 TnyFolderStore *dst_folder = NULL;
4231 ModestMainWindow *main_window;
4233 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win) ||
4234 MODEST_IS_MSG_VIEW_WINDOW (win));
4236 /* Get the main window if exists */
4237 if (MODEST_IS_MAIN_WINDOW (win))
4238 main_window = MODEST_MAIN_WINDOW (win);
4241 MODEST_MAIN_WINDOW (modest_window_mgr_get_main_window (modest_runtime_get_window_mgr ()));
4243 /* Get the folder view widget if exists */
4245 folder_view = modest_main_window_get_child_widget (main_window,
4246 MODEST_WIDGET_TYPE_FOLDER_VIEW);
4250 /* Create and run the dialog */
4251 dialog = create_move_to_dialog (GTK_WINDOW (win), folder_view, &tree_view);
4252 modest_folder_view_select_first_inbox_or_local (MODEST_FOLDER_VIEW (tree_view));
4253 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
4254 result = gtk_dialog_run (GTK_DIALOG(dialog));
4255 g_object_ref (tree_view);
4256 gtk_widget_destroy (dialog);
4258 if (result != GTK_RESPONSE_ACCEPT)
4261 dst_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (tree_view));
4262 /* Do window specific stuff */
4263 if (MODEST_IS_MAIN_WINDOW (win)) {
4264 modest_ui_actions_on_main_window_move_to (action,
4267 MODEST_MAIN_WINDOW (win));
4269 modest_ui_actions_on_msg_view_window_move_to (action,
4271 MODEST_MSG_VIEW_WINDOW (win));
4275 g_object_unref (dst_folder);
4279 * Calls #HeadersFunc for each header already selected in the main
4280 * window or the message currently being shown in the msg view window
4283 do_headers_action (ModestWindow *win,
4287 TnyList *headers_list = NULL;
4288 TnyIterator *iter = NULL;
4289 TnyHeader *header = NULL;
4290 TnyFolder *folder = NULL;
4293 headers_list = get_selected_headers (win);
4297 /* Get the folder */
4298 iter = tny_list_create_iterator (headers_list);
4299 header = TNY_HEADER (tny_iterator_get_current (iter));
4301 folder = tny_header_get_folder (header);
4302 g_object_unref (header);
4305 /* Call the function for each header */
4306 while (!tny_iterator_is_done (iter)) {
4307 header = TNY_HEADER (tny_iterator_get_current (iter));
4308 func (header, win, user_data);
4309 g_object_unref (header);
4310 tny_iterator_next (iter);
4313 /* Trick: do a poke status in order to speed up the signaling
4315 tny_folder_poke_status (folder);
4318 g_object_unref (folder);
4319 g_object_unref (iter);
4320 g_object_unref (headers_list);
4324 modest_ui_actions_view_attachment (GtkAction *action,
4325 ModestWindow *window)
4327 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
4328 modest_msg_view_window_view_attachment (MODEST_MSG_VIEW_WINDOW (window), NULL);
4330 /* not supported window for this action */
4331 g_return_if_reached ();
4336 modest_ui_actions_save_attachments (GtkAction *action,
4337 ModestWindow *window)
4339 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
4340 modest_msg_view_window_save_attachments (MODEST_MSG_VIEW_WINDOW (window), NULL);
4342 /* not supported window for this action */
4343 g_return_if_reached ();
4348 modest_ui_actions_remove_attachments (GtkAction *action,
4349 ModestWindow *window)
4351 if (MODEST_IS_MAIN_WINDOW (window)) {
4352 modest_ui_actions_on_main_window_remove_attachments (action, MODEST_MAIN_WINDOW (window));
4353 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
4354 modest_msg_view_window_remove_attachments (MODEST_MSG_VIEW_WINDOW (window), FALSE);
4356 /* not supported window for this action */
4357 g_return_if_reached ();
4362 modest_ui_actions_on_settings (GtkAction *action,
4367 dialog = modest_platform_get_global_settings_dialog ();
4368 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (win));
4369 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
4370 gtk_widget_show_all (dialog);
4372 gtk_dialog_run (GTK_DIALOG (dialog));
4374 gtk_widget_destroy (dialog);
4378 modest_ui_actions_on_help (GtkAction *action,
4381 const gchar *help_id = NULL;
4383 if (MODEST_IS_MAIN_WINDOW (win)) {
4384 GtkWidget *folder_view;
4385 TnyFolderStore *folder_store;
4387 /* Get selected folder */
4388 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
4389 MODEST_WIDGET_TYPE_FOLDER_VIEW);
4390 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
4392 /* Switch help_id */
4393 if (TNY_IS_FOLDER (folder_store)) {
4394 switch (modest_tny_folder_guess_folder_type (TNY_FOLDER (folder_store))) {
4395 case TNY_FOLDER_TYPE_NORMAL:
4396 help_id = "applications_email_managefolders";
4398 case TNY_FOLDER_TYPE_INBOX:
4399 help_id = "applications_email_inbox";
4401 case TNY_FOLDER_TYPE_OUTBOX:
4402 help_id = "applications_email_outbox";
4404 case TNY_FOLDER_TYPE_SENT:
4405 help_id = "applications_email_sent";
4407 case TNY_FOLDER_TYPE_DRAFTS:
4408 help_id = "applications_email_drafts";
4410 case TNY_FOLDER_TYPE_ARCHIVE:
4411 help_id = "applications_email_managefolders";
4414 help_id = "applications_email_managefolders";
4417 help_id = "applications_email_mainview";
4419 g_object_unref (folder_store);
4420 } else if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
4421 help_id = "applications_email_viewer";
4422 } else if (MODEST_IS_MSG_EDIT_WINDOW (win))
4423 help_id = "applications_email_editor";
4425 modest_platform_show_help (GTK_WINDOW (win), help_id);
4429 modest_ui_actions_on_retrieve_msg_contents (GtkAction *action,
4430 ModestWindow *window)
4432 ModestMailOperation *mail_op;
4436 headers = get_selected_headers (window);
4440 /* Create mail operation */
4441 mail_op = modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE,
4443 modest_ui_actions_get_msgs_full_error_handler,
4445 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
4446 modest_mail_operation_get_msgs_full (mail_op, headers, NULL, NULL, NULL);
4449 g_object_unref (headers);
4450 g_object_unref (mail_op);
4454 modest_ui_actions_on_email_menu_activated (GtkAction *action,
4455 ModestWindow *window)
4457 g_return_if_fail (MODEST_IS_WINDOW (window));
4460 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4464 modest_ui_actions_on_edit_menu_activated (GtkAction *action,
4465 ModestWindow *window)
4467 g_return_if_fail (MODEST_IS_WINDOW (window));
4470 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4474 modest_ui_actions_on_view_menu_activated (GtkAction *action,
4475 ModestWindow *window)
4477 g_return_if_fail (MODEST_IS_WINDOW (window));
4480 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4484 modest_ui_actions_on_tools_menu_activated (GtkAction *action,
4485 ModestWindow *window)
4487 g_return_if_fail (MODEST_IS_WINDOW (window));
4490 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4494 modest_ui_actions_on_attachment_menu_activated (GtkAction *action,
4495 ModestWindow *window)
4497 g_return_if_fail (MODEST_IS_WINDOW (window));
4500 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4504 modest_ui_actions_on_toolbar_csm_menu_activated (GtkAction *action,
4505 ModestWindow *window)
4507 g_return_if_fail (MODEST_IS_WINDOW (window));
4510 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4514 modest_ui_actions_on_folder_view_csm_menu_activated (GtkAction *action,
4515 ModestWindow *window)
4517 g_return_if_fail (MODEST_IS_WINDOW (window));
4520 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4524 modest_ui_actions_on_header_view_csm_menu_activated (GtkAction *action,
4525 ModestWindow *window)
4527 g_return_if_fail (MODEST_IS_WINDOW (window));
4530 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4534 modest_ui_actions_check_toolbar_dimming_rules (ModestWindow *window)
4536 g_return_if_fail (MODEST_IS_WINDOW (window));
4539 modest_window_check_dimming_rules_group (window, "ModestToolbarDimmingRules");
4543 modest_ui_actions_on_search_messages (GtkAction *action, ModestWindow *window)
4545 g_return_if_fail (MODEST_IS_WINDOW (window));
4547 modest_platform_show_search_messages (GTK_WINDOW (window));
4551 modest_ui_actions_on_open_addressbook (GtkAction *action, ModestWindow *win)
4553 g_return_if_fail (MODEST_IS_WINDOW (win));
4554 modest_platform_show_addressbook (GTK_WINDOW (win));
4559 modest_ui_actions_on_toggle_find_in_page (GtkToggleAction *action,
4560 ModestWindow *window)
4562 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4564 modest_msg_edit_window_toggle_find_toolbar (MODEST_MSG_EDIT_WINDOW (window), gtk_toggle_action_get_active (action));
4568 _on_send_receive_progress_changed (ModestMailOperation *mail_op,
4569 ModestMailOperationState *state,
4572 g_return_if_fail (MODEST_IS_MAIN_WINDOW(user_data));
4574 /* Set send/receive operation finished */
4575 if (state->status != MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS)
4576 modest_main_window_notify_send_receive_completed (MODEST_MAIN_WINDOW(user_data));