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"
44 #include "modest-protocol-info.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 GtkTreeRowReference *reference;
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_finished (ModestMailOperation *mail_op,
146 static gint header_list_count_uncached_msgs (TnyList *header_list);
148 static gboolean connect_to_get_msg (ModestWindow *win,
149 gint num_of_uncached_msgs,
150 TnyAccount *account);
152 static gboolean remote_folder_is_pop (const TnyFolderStore *folder);
154 static gboolean msgs_already_deleted_from_server ( TnyList *headers,
155 const TnyFolderStore *src_folder);
159 * This function checks whether a TnyFolderStore is a pop account
162 remote_folder_is_pop (const TnyFolderStore *folder)
164 const gchar *proto = NULL;
165 TnyAccount *account = NULL;
167 g_return_val_if_fail (TNY_IS_FOLDER_STORE(folder), FALSE);
169 if (TNY_IS_ACCOUNT (folder)) {
170 account = TNY_ACCOUNT(folder);
171 g_object_ref(account);
172 } else if (TNY_IS_FOLDER (folder)) {
173 account = tny_folder_get_account(TNY_FOLDER(folder));
176 if (!account && !TNY_IS_ACCOUNT(account)) {
177 g_warning ("%s: could not get account", __FUNCTION__);
181 proto = tny_account_get_proto(account);
182 g_object_unref (account);
185 (modest_protocol_info_get_transport_store_protocol (proto) == MODEST_PROTOCOL_STORE_POP);
189 * This functions checks whether if a list of messages are already
190 * deleted from the server: that is, if the server is a POP account
191 * and all messages are already cached.
194 msgs_already_deleted_from_server (TnyList *headers, const TnyFolderStore *src_folder)
196 g_return_val_if_fail (TNY_IS_FOLDER_STORE(src_folder), FALSE);
197 g_return_val_if_fail (TNY_IS_LIST(headers), FALSE);
199 gboolean src_is_pop = remote_folder_is_pop (src_folder);
200 gint uncached_msgs = header_list_count_uncached_msgs (headers);
202 return (src_is_pop && !uncached_msgs);
206 /* FIXME: this should be merged with the similar code in modest-account-view-window */
207 /* Show the account creation wizard dialog.
208 * returns: TRUE if an account was created. FALSE if the user cancelled.
211 modest_ui_actions_run_account_setup_wizard (ModestWindow *win)
213 gboolean result = FALSE;
214 GtkWindow *dialog, *wizard;
215 gint dialog_response;
217 /* Show the easy-setup wizard: */
218 dialog = modest_window_mgr_get_modal (modest_runtime_get_window_mgr());
219 if (dialog && MODEST_IS_EASYSETUP_WIZARD_DIALOG(dialog)) {
220 /* old wizard is active already;
222 gtk_window_present (GTK_WINDOW(dialog));
227 /* there is no such wizard yet */
228 wizard = GTK_WINDOW (modest_easysetup_wizard_dialog_new ());
229 modest_window_mgr_set_modal (modest_runtime_get_window_mgr(), wizard);
231 /* always present a main window in the background
232 * we do it here, so we cannot end up with two wizards (as this
233 * function might be called in modest_window_mgr_get_main_window as well */
235 win = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr(),
236 TRUE); /* create if not existent */
238 /* make sure the mainwindow is visible */
239 gtk_widget_show_all (GTK_WIDGET(win));
240 gtk_window_present (GTK_WINDOW(win));
242 dialog_response = gtk_dialog_run (GTK_DIALOG (wizard));
243 gtk_widget_destroy (GTK_WIDGET (wizard));
244 if (gtk_events_pending ())
245 gtk_main_iteration ();
247 if (dialog_response == GTK_RESPONSE_CANCEL) {
250 /* Check whether an account was created: */
251 result = modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
259 modest_ui_actions_on_about (GtkAction *action, ModestWindow *win)
262 const gchar *authors[] = {
263 "Dirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>",
266 about = gtk_about_dialog_new ();
267 gtk_about_dialog_set_name (GTK_ABOUT_DIALOG(about), PACKAGE_NAME);
268 gtk_about_dialog_set_version (GTK_ABOUT_DIALOG(about),PACKAGE_VERSION);
269 gtk_about_dialog_set_copyright (GTK_ABOUT_DIALOG(about),
270 _("Copyright (c) 2006, Nokia Corporation\n"
271 "All rights reserved."));
272 gtk_about_dialog_set_comments (GTK_ABOUT_DIALOG(about),
273 _("a modest e-mail client\n\n"
274 "design and implementation: Dirk-Jan C. Binnema\n"
275 "contributions from the fine people at KC and Ig\n"
276 "uses the tinymail email framework written by Philip van Hoof"));
277 gtk_about_dialog_set_authors (GTK_ABOUT_DIALOG(about), authors);
278 gtk_about_dialog_set_website (GTK_ABOUT_DIALOG(about), "http://modest.garage.maemo.org");
279 gtk_window_set_transient_for (GTK_WINDOW (about), GTK_WINDOW (win));
280 gtk_window_set_modal (GTK_WINDOW (about), TRUE);
282 gtk_dialog_run (GTK_DIALOG (about));
283 gtk_widget_destroy(about);
287 * Gets the list of currently selected messages. If the win is the
288 * main window, then it returns a newly allocated list of the headers
289 * selected in the header view. If win is the msg view window, then
290 * the value returned is a list with just a single header.
292 * The caller of this funcion must free the list.
295 get_selected_headers (ModestWindow *win)
297 if (MODEST_IS_MAIN_WINDOW(win)) {
298 GtkWidget *header_view;
300 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
301 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
302 return modest_header_view_get_selected_headers (MODEST_HEADER_VIEW(header_view));
304 } else if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
305 /* for MsgViewWindows, we simply return a list with one element */
307 TnyList *list = NULL;
309 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
310 if (header != NULL) {
311 list = tny_simple_list_new ();
312 tny_list_prepend (list, G_OBJECT(header));
313 g_object_unref (G_OBJECT(header));
322 static GtkTreeRowReference *
323 get_next_after_selected_headers (ModestHeaderView *header_view)
325 GtkTreeSelection *sel;
326 GList *selected_rows, *node;
328 GtkTreeRowReference *result;
331 model = gtk_tree_view_get_model (GTK_TREE_VIEW (header_view));
332 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
333 selected_rows = gtk_tree_selection_get_selected_rows (sel, NULL);
335 if (selected_rows == NULL)
338 node = g_list_last (selected_rows);
339 path = gtk_tree_path_copy ((GtkTreePath *) node->data);
340 gtk_tree_path_next (path);
342 result = gtk_tree_row_reference_new (model, path);
344 gtk_tree_path_free (path);
345 g_list_foreach (selected_rows, (GFunc) gtk_tree_path_free, NULL);
346 g_list_free (selected_rows);
352 headers_action_mark_as_read (TnyHeader *header,
356 TnyHeaderFlags flags;
358 g_return_if_fail (TNY_IS_HEADER(header));
360 flags = tny_header_get_flags (header);
361 if (flags & TNY_HEADER_FLAG_SEEN) return;
362 tny_header_set_flag (header, TNY_HEADER_FLAG_SEEN);
366 headers_action_mark_as_unread (TnyHeader *header,
370 TnyHeaderFlags flags;
372 g_return_if_fail (TNY_IS_HEADER(header));
374 flags = tny_header_get_flags (header);
375 if (flags & TNY_HEADER_FLAG_SEEN) {
376 tny_header_unset_flag (header, TNY_HEADER_FLAG_SEEN);
380 /** After deleing a message that is currently visible in a window,
381 * show the next message from the list, or close the window if there are no more messages.
384 modest_ui_actions_refresh_message_window_after_delete (ModestMsgViewWindow* win)
386 /* Close msg view window or select next */
387 if (modest_msg_view_window_last_message_selected (win) &&
388 modest_msg_view_window_first_message_selected (win)) {
389 modest_ui_actions_on_close_window (NULL, MODEST_WINDOW (win));
390 } else if (!modest_msg_view_window_select_next_message (win)) {
392 g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value);
398 modest_ui_actions_on_delete_message (GtkAction *action, ModestWindow *win)
400 TnyList *header_list = NULL;
401 TnyIterator *iter = NULL;
402 TnyHeader *header = NULL;
403 gchar *message = NULL;
406 ModestWindowMgr *mgr;
407 GtkWidget *header_view = NULL;
409 g_return_if_fail (MODEST_IS_WINDOW(win));
411 /* Check first if the header view has the focus */
412 if (MODEST_IS_MAIN_WINDOW (win)) {
414 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
415 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
416 if (!gtk_widget_is_focus (header_view))
420 /* Get the headers, either from the header view (if win is the main window),
421 * or from the message view window: */
422 header_list = get_selected_headers (win);
423 if (!header_list) return;
425 /* Check if any of the headers are already opened, or in the process of being opened */
426 if (MODEST_IS_MAIN_WINDOW (win)) {
427 gint opened_headers = 0;
429 iter = tny_list_create_iterator (header_list);
430 mgr = modest_runtime_get_window_mgr ();
431 while (!tny_iterator_is_done (iter)) {
432 header = TNY_HEADER (tny_iterator_get_current (iter));
434 if (modest_window_mgr_find_registered_header (mgr, header, NULL))
436 g_object_unref (header);
438 tny_iterator_next (iter);
440 g_object_unref (iter);
442 if (opened_headers > 0) {
445 msg = g_strdup_printf (_("mcen_nc_unable_to_delete_n_messages"),
448 modest_platform_run_information_dialog (GTK_WINDOW (win), (const gchar *) msg);
451 g_object_unref (header_list);
457 if (tny_list_get_length(header_list) == 1) {
458 iter = tny_list_create_iterator (header_list);
459 header = TNY_HEADER (tny_iterator_get_current (iter));
461 desc = g_strdup_printf ("%s", tny_header_get_subject (header));
462 g_object_unref (header);
465 g_object_unref (iter);
467 message = g_strdup_printf(ngettext("emev_nc_delete_message", "emev_nc_delete_messages",
468 tny_list_get_length(header_list)), desc);
470 /* Confirmation dialog */
471 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
475 if (response == GTK_RESPONSE_OK) {
476 ModestWindow *main_window = NULL;
477 ModestWindowMgr *mgr = NULL;
478 GtkTreeModel *model = NULL;
479 GtkTreeSelection *sel = NULL;
480 GList *sel_list = NULL, *tmp = NULL;
481 GtkTreeRowReference *next_row_reference = NULL;
482 GtkTreeRowReference *prev_row_reference = NULL;
483 GtkTreePath *next_path = NULL;
484 GtkTreePath *prev_path = NULL;
485 ModestMailOperation *mail_op = NULL;
487 /* Find last selected row */
488 if (MODEST_IS_MAIN_WINDOW (win)) {
489 model = gtk_tree_view_get_model (GTK_TREE_VIEW (header_view));
490 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
491 sel_list = gtk_tree_selection_get_selected_rows (sel, &model);
492 for (tmp=sel_list; tmp; tmp=tmp->next) {
493 if (tmp->next == NULL) {
494 prev_path = gtk_tree_path_copy((GtkTreePath *) tmp->data);
495 next_path = gtk_tree_path_copy((GtkTreePath *) tmp->data);
497 gtk_tree_path_prev (prev_path);
498 gtk_tree_path_next (next_path);
500 prev_row_reference = gtk_tree_row_reference_new (model, prev_path);
501 next_row_reference = gtk_tree_row_reference_new (model, next_path);
506 /* Disable window dimming management */
507 modest_window_disable_dimming (MODEST_WINDOW(win));
509 /* Remove each header. If it's a view window header_view == NULL */
510 mail_op = modest_mail_operation_new ((GObject *) win);
511 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
513 modest_mail_operation_remove_msgs (mail_op, header_list, FALSE);
514 g_object_unref (mail_op);
516 /* Enable window dimming management */
518 gtk_tree_selection_unselect_all (sel);
520 modest_window_enable_dimming (MODEST_WINDOW(win));
522 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
523 modest_ui_actions_refresh_message_window_after_delete (MODEST_MSG_VIEW_WINDOW (win));
525 /* Get main window */
526 mgr = modest_runtime_get_window_mgr ();
527 main_window = modest_window_mgr_get_main_window (mgr, FALSE); /* don't create */
529 /* Move cursor to next row */
532 /* Select next or previous row */
533 if (gtk_tree_row_reference_valid (next_row_reference)) {
534 /* next_path = gtk_tree_row_reference_get_path (row_reference); */
535 gtk_tree_selection_select_path (sel, next_path);
537 else if (gtk_tree_row_reference_valid (prev_row_reference)) {
538 gtk_tree_selection_select_path (sel, prev_path);
542 if (next_row_reference != NULL)
543 gtk_tree_row_reference_free (next_row_reference);
544 if (next_path != NULL)
545 gtk_tree_path_free (next_path);
546 if (prev_row_reference != NULL)
547 gtk_tree_row_reference_free (prev_row_reference);
548 if (prev_path != NULL)
549 gtk_tree_path_free (prev_path);
552 /* Update toolbar dimming state */
554 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
557 g_list_foreach (sel_list, (GFunc) gtk_tree_path_free, NULL);
558 g_list_free (sel_list);
564 g_object_unref (header_list);
570 /* delete either message or folder, based on where we are */
572 modest_ui_actions_on_delete_message_or_folder (GtkAction *action, ModestWindow *win)
574 g_return_if_fail (MODEST_IS_WINDOW(win));
576 /* Check first if the header view has the focus */
577 if (MODEST_IS_MAIN_WINDOW (win)) {
579 w = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
580 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
581 if (gtk_widget_is_focus (w)) {
582 modest_ui_actions_on_delete_folder (action, MODEST_MAIN_WINDOW(win));
586 modest_ui_actions_on_delete_message (action, win);
592 modest_ui_actions_on_quit (GtkAction *action, ModestWindow *win)
594 ModestWindowMgr *mgr = NULL;
596 #ifdef MODEST_PLATFORM_MAEMO
597 modest_osso_save_state();
598 #endif /* MODEST_PLATFORM_MAEMO */
600 g_debug ("closing down, clearing %d item(s) from operation queue",
601 modest_mail_operation_queue_num_elements
602 (modest_runtime_get_mail_operation_queue()));
604 /* cancel all outstanding operations */
605 modest_mail_operation_queue_cancel_all
606 (modest_runtime_get_mail_operation_queue());
608 g_debug ("queue has been cleared");
611 /* Check if there are opened editing windows */
612 mgr = modest_runtime_get_window_mgr ();
613 modest_window_mgr_close_all_windows (mgr);
615 /* note: when modest-tny-account-store is finalized,
616 it will automatically set all network connections
619 /* gtk_main_quit (); */
623 modest_ui_actions_on_close_window (GtkAction *action, ModestWindow *win)
627 g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value);
629 /* if (MODEST_IS_MSG_VIEW_WINDOW (win)) { */
630 /* gtk_widget_destroy (GTK_WIDGET (win)); */
631 /* } else if (MODEST_IS_MSG_EDIT_WINDOW (win)) { */
632 /* gboolean ret_value; */
633 /* g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value); */
634 /* } else if (MODEST_IS_WINDOW (win)) { */
635 /* gtk_widget_destroy (GTK_WIDGET (win)); */
637 /* g_return_if_reached (); */
642 modest_ui_actions_on_add_to_contacts (GtkAction *action, ModestWindow *win)
644 GtkClipboard *clipboard = NULL;
645 gchar *selection = NULL;
647 clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
648 selection = gtk_clipboard_wait_for_text (clipboard);
650 /* Question: why is the clipboard being used here?
651 * It doesn't really make a lot of sense. */
655 modest_address_book_add_address (selection);
661 modest_ui_actions_on_accounts (GtkAction *action,
664 /* This is currently only implemented for Maemo */
665 #ifdef MODEST_PLATFORM_MAEMO /* Defined in config.h */
666 if (!modest_account_mgr_has_accounts (modest_runtime_get_account_mgr(), TRUE)) {
667 if (!modest_ui_actions_run_account_setup_wizard (win))
668 g_debug ("%s: wizard was already running", __FUNCTION__);
672 /* Show the list of accounts */
673 GtkWindow *account_win = GTK_WINDOW (modest_account_view_window_new ());
674 gtk_window_set_transient_for (account_win, GTK_WINDOW (win));
676 /* The accounts dialog must be modal */
677 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), account_win);
678 modest_maemo_show_dialog_and_forget (GTK_WINDOW (win), GTK_DIALOG (account_win));
681 GtkWidget *dialog, *label;
683 /* Create the widgets */
685 dialog = gtk_dialog_new_with_buttons ("Message",
687 GTK_DIALOG_DESTROY_WITH_PARENT,
691 label = gtk_label_new ("Hello World!");
693 /* Ensure that the dialog box is destroyed when the user responds. */
695 g_signal_connect_swapped (dialog, "response",
696 G_CALLBACK (gtk_widget_destroy),
699 /* Add the label, and show everything we've added to the dialog. */
701 gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox),
703 gtk_widget_show_all (dialog);
704 #endif /* MODEST_PLATFORM_MAEMO */
708 on_smtp_servers_window_hide (GtkWindow* window, gpointer user_data)
710 /* Save any changes. */
711 modest_connection_specific_smtp_window_save_server_accounts (
712 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (window));
713 gtk_widget_destroy (GTK_WIDGET (window));
719 modest_ui_actions_on_smtp_servers (GtkAction *action, ModestWindow *win)
721 /* This is currently only implemented for Maemo,
722 * because it requires an API (libconic) to detect different connection
725 #ifdef MODEST_PLATFORM_MAEMO /* Defined in config.h */
727 /* Create the window if necessary: */
728 GtkWidget *specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
729 modest_connection_specific_smtp_window_fill_with_connections (
730 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (specific_window),
731 modest_runtime_get_account_mgr());
733 /* Show the window: */
734 gtk_window_set_transient_for (GTK_WINDOW (specific_window), GTK_WINDOW (win));
735 gtk_window_set_modal (GTK_WINDOW (specific_window), TRUE);
736 gtk_widget_show (specific_window);
738 /* Save changes when the window is hidden: */
739 g_signal_connect (specific_window, "hide",
740 G_CALLBACK (on_smtp_servers_window_hide), win);
741 #endif /* MODEST_PLATFORM_MAEMO */
745 modest_ui_actions_compose_msg(ModestWindow *win,
748 const gchar *bcc_str,
749 const gchar *subject_str,
750 const gchar *body_str,
753 gchar *account_name = NULL;
755 TnyAccount *account = NULL;
756 TnyFolder *folder = NULL;
757 gchar *from_str = NULL, *signature = NULL, *body = NULL;
758 gboolean use_signature = FALSE;
759 ModestWindow *msg_win = NULL;
760 ModestAccountMgr *mgr = modest_runtime_get_account_mgr();
761 ModestTnyAccountStore *store = modest_runtime_get_account_store();
763 if (win) account_name = g_strdup (modest_window_get_active_account (win));
764 if (!account_name) account_name = modest_account_mgr_get_default_account(mgr);
766 g_printerr ("modest: no account found\n");
769 account = modest_tny_account_store_get_server_account (store, account_name, TNY_ACCOUNT_TYPE_STORE);
771 g_printerr ("modest: failed to get tnyaccount for '%s'\n", account_name);
774 folder = modest_tny_account_get_special_folder (account, TNY_FOLDER_TYPE_DRAFTS);
776 g_printerr ("modest: failed to find Drafts folder\n");
779 from_str = modest_account_mgr_get_from_string (mgr, account_name);
781 g_printerr ("modest: failed get from string for '%s'\n", account_name);
785 signature = modest_account_mgr_get_signature (mgr, account_name, &use_signature);
786 if (body_str != NULL) {
787 body = use_signature ? g_strconcat(body_str, "\n", signature, NULL) : g_strdup(body_str);
789 body = use_signature ? g_strconcat("\n", signature, NULL) : g_strdup("");
792 msg = modest_tny_msg_new (to_str, from_str, cc_str, bcc_str, subject_str, body, NULL);
794 g_printerr ("modest: failed to create new msg\n");
798 /* Create and register edit window */
799 /* This is destroyed by TODO. */
800 msg_win = modest_msg_edit_window_new (msg, account_name, FALSE);
801 while (attachments) {
802 modest_msg_edit_window_attach_file_one((ModestMsgEditWindow *)msg_win,
804 attachments = g_slist_next(attachments);
806 modest_window_mgr_register_window (modest_runtime_get_window_mgr(), msg_win);
809 gtk_window_set_transient_for (GTK_WINDOW (msg_win),
812 gtk_widget_show_all (GTK_WIDGET (msg_win));
818 g_free (account_name);
819 if (account) g_object_unref (G_OBJECT(account));
820 if (folder) g_object_unref (G_OBJECT(folder));
821 if (msg_win) g_object_unref (G_OBJECT(msg_win));
822 if (msg) g_object_unref (G_OBJECT(msg));
826 modest_ui_actions_on_new_msg (GtkAction *action, ModestWindow *win)
828 /* if there are no accounts yet, just show the wizard */
829 if (!modest_account_mgr_has_accounts (modest_runtime_get_account_mgr(), TRUE))
830 if (!modest_ui_actions_run_account_setup_wizard (win))
833 modest_ui_actions_compose_msg(win, NULL, NULL, NULL, NULL, NULL, NULL);
837 modest_ui_actions_msg_retrieval_check (ModestMailOperation *mail_op,
841 ModestMailOperationStatus status;
843 /* If there is no message or the operation was not successful */
844 status = modest_mail_operation_get_status (mail_op);
845 if (!msg || status != MODEST_MAIL_OPERATION_STATUS_SUCCESS) {
847 /* Remove the header from the preregistered uids */
848 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (),
858 open_msg_cb (ModestMailOperation *mail_op, TnyHeader *header, TnyMsg *msg, gpointer user_data)
860 ModestWindowMgr *mgr = NULL;
861 ModestWindow *parent_win = NULL;
862 ModestWindow *win = NULL;
863 TnyFolderType folder_type = TNY_FOLDER_TYPE_UNKNOWN;
864 gchar *account = NULL;
866 gboolean open_in_editor = FALSE;
868 /* Do nothing if there was any problem with the mail
869 operation. The error will be shown by the error_handler of
870 the mail operation */
871 if (!modest_ui_actions_msg_retrieval_check (mail_op, header, msg))
874 parent_win = (ModestWindow *) modest_mail_operation_get_source (mail_op);
875 folder = tny_header_get_folder (header);
877 /* Mark header as read */
878 headers_action_mark_as_read (header, MODEST_WINDOW(parent_win), NULL);
880 /* Gets folder type (OUTBOX headers will be opened in edit window */
881 if (modest_tny_folder_is_local_folder (folder)) {
882 folder_type = modest_tny_folder_get_local_or_mmc_folder_type (folder);
883 if (folder_type == TNY_FOLDER_TYPE_INVALID)
884 g_warning ("%s: BUG: TNY_FOLDER_TYPE_INVALID", __FUNCTION__);
888 if (folder_type == TNY_FOLDER_TYPE_OUTBOX) {
889 TnyTransportAccount *traccount = NULL;
890 ModestTnyAccountStore *accstore = modest_runtime_get_account_store();
891 traccount = modest_tny_account_store_get_transport_account_from_outbox_header(accstore, header);
893 ModestTnySendQueue *send_queue = NULL;
894 ModestTnySendQueueStatus status;
896 account = g_strdup(modest_tny_account_get_parent_modest_account_name_for_server_account(
897 TNY_ACCOUNT(traccount)));
898 send_queue = modest_runtime_get_send_queue(traccount);
899 msg_id = modest_tny_send_queue_get_msg_id (header);
900 status = modest_tny_send_queue_get_msg_status(send_queue, msg_id);
901 /* Only open messages in outbox with the editor if they are in Failed state */
902 if (status == MODEST_TNY_SEND_QUEUE_FAILED) {
903 open_in_editor = TRUE;
906 g_object_unref(traccount);
908 g_warning("Cannot get transport account for message in outbox!!");
910 } else if (folder_type == TNY_FOLDER_TYPE_DRAFTS) {
911 open_in_editor = TRUE; /* Open in editor if the message is in the Drafts folder */
916 account = g_strdup (modest_window_get_active_account (MODEST_WINDOW (parent_win)));
918 account = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
920 if (open_in_editor) {
921 ModestAccountMgr *mgr = modest_runtime_get_account_mgr ();
922 const gchar *from_header = NULL;
924 from_header = tny_header_get_from (header);
926 /* we cannot edit without a valid account... */
927 if (!modest_account_mgr_has_accounts(mgr, TRUE)) {
928 if (!modest_ui_actions_run_account_setup_wizard(parent_win))
933 GSList *accounts = modest_account_mgr_account_names (mgr, TRUE);
935 for (node = accounts; node != NULL; node = g_slist_next (node)) {
936 gchar *from = modest_account_mgr_get_from_string (mgr, node->data);
938 if (from && (strcmp (from_header, from) == 0)) {
940 account = g_strdup (node->data);
946 g_slist_foreach (accounts, (GFunc) g_free, NULL);
947 g_slist_free (accounts);
950 win = modest_msg_edit_window_new (msg, account, TRUE);
954 modest_platform_information_banner (NULL, NULL, _("mail_ib_opening_draft_message"));
957 gchar *uid = modest_tny_folder_get_header_unique_id (header);
959 if (MODEST_IS_MAIN_WINDOW (parent_win)) {
960 GtkWidget *header_view;
961 GtkTreeSelection *sel;
962 GList *sel_list = NULL;
965 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(parent_win),
966 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
968 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
969 sel_list = gtk_tree_selection_get_selected_rows (sel, &model);
971 if (sel_list != NULL) {
972 GtkTreeRowReference *row_reference;
974 row_reference = gtk_tree_row_reference_new (model, (GtkTreePath *) sel_list->data);
975 g_list_foreach (sel_list, (GFunc) gtk_tree_path_free, NULL);
976 g_list_free (sel_list);
978 win = modest_msg_view_window_new_with_header_model (
979 msg, account, (const gchar*) uid,
980 model, row_reference);
981 gtk_tree_row_reference_free (row_reference);
983 win = modest_msg_view_window_new_for_attachment (msg, account, (const gchar*) uid);
986 win = modest_msg_view_window_new_for_attachment (msg, account, (const gchar*) uid);
991 /* Register and show new window */
993 mgr = modest_runtime_get_window_mgr ();
994 modest_window_mgr_register_window (mgr, win);
995 g_object_unref (win);
996 gtk_widget_show_all (GTK_WIDGET(win));
999 /* Update toolbar dimming state */
1000 if (MODEST_IS_MAIN_WINDOW (parent_win)) {
1001 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (parent_win));
1007 g_object_unref (parent_win);
1008 g_object_unref (folder);
1013 open_msg_error_handler (ModestMailOperation *mail_op,
1016 /* Show the message error */
1017 GObject *win = modest_mail_operation_get_source (mail_op);
1019 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
1020 (gchar *) user_data);
1022 g_object_unref (win);
1026 modest_ui_actions_get_msgs_full_error_handler (ModestMailOperation *mail_op,
1029 const GError *error;
1030 GObject *win = modest_mail_operation_get_source (mail_op);
1032 error = modest_mail_operation_get_error (mail_op);
1034 if (error->code == MODEST_MAIL_OPERATION_ERROR_MESSAGE_SIZE_LIMIT) {
1036 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
1039 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
1040 _("mail_ni_ui_folder_get_msg_folder_error"));
1044 g_object_unref (win);
1048 * Returns the account a list of headers belongs to. It returns a
1049 * *new* reference so don't forget to unref it
1052 get_account_from_header_list (TnyList *headers)
1054 TnyAccount *account = NULL;
1056 if (tny_list_get_length (headers) > 0) {
1057 TnyIterator *iter = tny_list_create_iterator (headers);
1058 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter));
1059 TnyFolder *folder = tny_header_get_folder (header);
1060 account = tny_folder_get_account (folder);
1061 g_object_unref (folder);
1062 g_object_unref (header);
1063 g_object_unref (iter);
1069 * This function is used by both modest_ui_actions_on_open and
1070 * modest_ui_actions_on_header_activated. This way we always do the
1071 * same when trying to open messages.
1074 _modest_ui_actions_open (TnyList *headers, ModestWindow *win)
1076 ModestWindowMgr *mgr = NULL;
1077 TnyIterator *iter = NULL, *iter_not_opened = NULL;
1078 ModestMailOperation *mail_op = NULL;
1079 TnyList *not_opened_headers = NULL;
1080 TnyHeaderFlags flags = 0;
1081 TnyAccount *account;
1083 g_return_if_fail (headers != NULL);
1085 /* Check that only one message is selected for opening */
1086 if (tny_list_get_length (headers) != 1) {
1087 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
1088 _("mcen_ib_select_one_message"));
1092 mgr = modest_runtime_get_window_mgr ();
1093 iter = tny_list_create_iterator (headers);
1095 /* Get the account */
1096 account = get_account_from_header_list (headers);
1098 /* Look if we already have a message view for each header. If
1099 true, then remove the header from the list of headers to
1101 not_opened_headers = tny_simple_list_new ();
1102 while (!tny_iterator_is_done (iter)) {
1104 ModestWindow *window = NULL;
1105 TnyHeader *header = NULL;
1106 gboolean found = FALSE;
1108 header = TNY_HEADER (tny_iterator_get_current (iter));
1110 flags = tny_header_get_flags (header);
1113 found = modest_window_mgr_find_registered_header (mgr, header, &window);
1115 /* Do not open again the message and present the
1116 window to the user */
1119 gtk_window_present (GTK_WINDOW (window));
1121 /* the header has been registered already, we don't do
1122 * anything but wait for the window to come up*/
1123 g_debug ("header %p already registered, waiting for window", header);
1125 tny_list_append (not_opened_headers, G_OBJECT (header));
1129 g_object_unref (header);
1131 tny_iterator_next (iter);
1133 g_object_unref (iter);
1136 /* Open each message */
1137 if (tny_list_get_length (not_opened_headers) == 0)
1140 /* If some messages would have to be downloaded, ask the user to
1141 * make a connection. It's generally easier to do this here (in the mainloop)
1142 * than later in a thread:
1144 if (tny_list_get_length (not_opened_headers) > 0) {
1146 gboolean found = FALSE;
1148 iter = tny_list_create_iterator (not_opened_headers);
1149 while (!tny_iterator_is_done (iter) && !found) {
1150 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter));
1151 if (!(tny_header_get_flags (header) & TNY_HEADER_FLAG_CACHED))
1154 tny_iterator_next (iter);
1156 g_object_unref (header);
1158 g_object_unref (iter);
1160 /* Ask the user if there are any uncached messages */
1161 if (found && !connect_to_get_msg (win,
1162 header_list_count_uncached_msgs (not_opened_headers),
1167 /* Register the headers before actually creating the windows: */
1168 iter_not_opened = tny_list_create_iterator (not_opened_headers);
1169 while (!tny_iterator_is_done (iter_not_opened)) {
1170 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter_not_opened));
1172 modest_window_mgr_register_header (mgr, header, NULL);
1173 g_object_unref (header);
1175 tny_iterator_next (iter_not_opened);
1177 g_object_unref (iter_not_opened);
1178 iter_not_opened = NULL;
1180 /* Create the mail operation */
1181 if (tny_list_get_length (not_opened_headers) > 1) {
1182 mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT (win),
1183 modest_ui_actions_get_msgs_full_error_handler,
1185 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
1187 modest_mail_operation_get_msgs_full (mail_op,
1193 TnyIterator *iter = tny_list_create_iterator (not_opened_headers);
1194 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter));
1195 const gchar *proto_name;
1197 ModestTransportStoreProtocol proto;
1199 /* Get the error message depending on the protocol */
1200 proto_name = tny_account_get_proto (account);
1201 if (proto_name != NULL) {
1202 proto = modest_protocol_info_get_transport_store_protocol (proto_name);
1204 proto = MODEST_PROTOCOL_STORE_MAILDIR;
1207 if (proto == MODEST_PROTOCOL_STORE_POP) {
1208 error_msg = g_strdup (_("emev_ni_ui_pop3_msg_recv_error"));
1209 } else if (proto == MODEST_PROTOCOL_STORE_IMAP) {
1210 error_msg = g_strdup_printf (_("emev_ni_ui_imap_message_not_available_in_server"),
1211 tny_header_get_subject (header));
1213 error_msg = g_strdup (_("mail_ni_ui_folder_get_msg_folder_error"));
1216 /* Create and call the mail operation */
1217 mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT (win),
1218 open_msg_error_handler,
1221 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
1223 modest_mail_operation_get_msg (mail_op, header, open_msg_cb, NULL);
1225 g_object_unref (header);
1226 g_object_unref (iter);
1228 g_object_unref (mail_op);
1233 g_object_unref (account);
1234 if (not_opened_headers)
1235 g_object_unref (not_opened_headers);
1239 modest_ui_actions_on_open (GtkAction *action, ModestWindow *win)
1244 headers = get_selected_headers (win);
1249 _modest_ui_actions_open (headers, win);
1251 g_object_unref(headers);
1256 free_reply_forward_helper (gpointer data)
1258 ReplyForwardHelper *helper;
1260 helper = (ReplyForwardHelper *) data;
1261 g_free (helper->account_name);
1262 g_slice_free (ReplyForwardHelper, helper);
1266 reply_forward_cb (ModestMailOperation *mail_op, TnyHeader *header, TnyMsg *msg,
1270 ReplyForwardHelper *rf_helper;
1271 ModestWindow *msg_win = NULL;
1272 ModestEditType edit_type;
1274 TnyAccount *account = NULL;
1275 ModestWindowMgr *mgr = NULL;
1276 gchar *signature = NULL;
1277 gboolean use_signature;
1279 /* If there was any error. The mail operation could be NULL,
1280 this means that we already have the message downloaded and
1281 that we didn't do a mail operation to retrieve it */
1282 if (mail_op && !modest_ui_actions_msg_retrieval_check (mail_op, header, msg))
1285 g_return_if_fail (user_data != NULL);
1286 rf_helper = (ReplyForwardHelper *) user_data;
1288 from = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(),
1289 rf_helper->account_name);
1290 signature = modest_account_mgr_get_signature (modest_runtime_get_account_mgr(),
1291 rf_helper->account_name,
1294 /* Create reply mail */
1295 switch (rf_helper->action) {
1298 modest_tny_msg_create_reply_msg (msg, header, from, signature,
1299 rf_helper->reply_forward_type,
1300 MODEST_TNY_MSG_REPLY_MODE_SENDER);
1302 case ACTION_REPLY_TO_ALL:
1304 modest_tny_msg_create_reply_msg (msg, header, from, signature, rf_helper->reply_forward_type,
1305 MODEST_TNY_MSG_REPLY_MODE_ALL);
1306 edit_type = MODEST_EDIT_TYPE_REPLY;
1308 case ACTION_FORWARD:
1310 modest_tny_msg_create_forward_msg (msg, from, signature, rf_helper->reply_forward_type);
1311 edit_type = MODEST_EDIT_TYPE_FORWARD;
1314 g_return_if_reached ();
1321 g_printerr ("modest: failed to create message\n");
1325 account = modest_tny_account_store_get_server_account (modest_runtime_get_account_store(),
1326 rf_helper->account_name,
1327 TNY_ACCOUNT_TYPE_STORE);
1329 g_printerr ("modest: failed to get tnyaccount for '%s'\n", rf_helper->account_name);
1333 /* Create and register the windows */
1334 msg_win = modest_msg_edit_window_new (new_msg, rf_helper->account_name, FALSE);
1335 mgr = modest_runtime_get_window_mgr ();
1336 modest_window_mgr_register_window (mgr, msg_win);
1338 if (rf_helper->parent_window != NULL) {
1339 gdouble parent_zoom;
1341 parent_zoom = modest_window_get_zoom (MODEST_WINDOW (rf_helper->parent_window));
1342 modest_window_set_zoom (msg_win, parent_zoom);
1345 /* Show edit window */
1346 gtk_widget_show_all (GTK_WIDGET (msg_win));
1350 g_object_unref (msg_win);
1352 g_object_unref (G_OBJECT (new_msg));
1354 g_object_unref (G_OBJECT (account));
1355 /* g_object_unref (msg); */
1356 free_reply_forward_helper (rf_helper);
1359 /* Checks a list of headers. If any of them are not currently
1360 * downloaded (CACHED) then returns TRUE else returns FALSE.
1363 header_list_count_uncached_msgs (TnyList *header_list)
1366 gint uncached_messages = 0;
1368 iter = tny_list_create_iterator (header_list);
1369 while (!tny_iterator_is_done (iter)) {
1372 header = TNY_HEADER (tny_iterator_get_current (iter));
1374 if (!(tny_header_get_flags (header) & TNY_HEADER_FLAG_CACHED))
1375 uncached_messages ++;
1376 g_object_unref (header);
1379 tny_iterator_next (iter);
1381 g_object_unref (iter);
1383 return uncached_messages;
1386 /* Returns FALSE if the user does not want to download the
1387 * messages. Returns TRUE if the user allowed the download.
1390 connect_to_get_msg (ModestWindow *win,
1391 gint num_of_uncached_msgs,
1392 TnyAccount *account)
1394 GtkResponseType response;
1396 /* Allways download if we are online. */
1397 if (tny_device_is_online (modest_runtime_get_device ()))
1400 /* If offline, then ask for user permission to download the messages */
1401 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
1402 ngettext("mcen_nc_get_msg",
1404 num_of_uncached_msgs));
1406 if (response == GTK_RESPONSE_CANCEL)
1409 return modest_platform_connect_and_wait((GtkWindow *) win, account);
1413 * Common code for the reply and forward actions
1416 reply_forward (ReplyForwardAction action, ModestWindow *win)
1418 ModestMailOperation *mail_op = NULL;
1419 TnyList *header_list = NULL;
1420 ReplyForwardHelper *rf_helper = NULL;
1421 guint reply_forward_type;
1422 gboolean continue_download = TRUE;
1423 gboolean do_retrieve = TRUE;
1425 g_return_if_fail (MODEST_IS_WINDOW(win));
1427 /* we need an account when editing */
1428 if (!modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE)) {
1429 if (!modest_ui_actions_run_account_setup_wizard (win))
1433 header_list = get_selected_headers (win);
1437 reply_forward_type =
1438 modest_conf_get_int (modest_runtime_get_conf (),
1439 (action == ACTION_FORWARD) ? MODEST_CONF_FORWARD_TYPE : MODEST_CONF_REPLY_TYPE,
1442 /* check if we need to download msg before asking about it */
1443 do_retrieve = (action == ACTION_FORWARD) ||
1444 (reply_forward_type != MODEST_TNY_MSG_REPLY_TYPE_CITE);
1447 gint num_of_unc_msgs;
1449 /* check that the messages have been previously downloaded */
1450 num_of_unc_msgs = header_list_count_uncached_msgs(header_list);
1451 /* If there are any uncached message ask the user
1452 * whether he/she wants to download them. */
1453 if (num_of_unc_msgs) {
1454 TnyAccount *account = get_account_from_header_list (header_list);
1455 continue_download = connect_to_get_msg (win, num_of_unc_msgs, account);
1456 g_object_unref (account);
1460 if (!continue_download) {
1461 g_object_unref (header_list);
1465 /* We assume that we can only select messages of the
1466 same folder and that we reply all of them from the
1467 same account. In fact the interface currently only
1468 allows single selection */
1471 rf_helper = g_slice_new0 (ReplyForwardHelper);
1472 rf_helper->reply_forward_type = reply_forward_type;
1473 rf_helper->action = action;
1474 rf_helper->account_name = g_strdup (modest_window_get_active_account (win));
1476 if ((win != NULL) && (MODEST_IS_WINDOW (win)))
1477 rf_helper->parent_window = GTK_WIDGET (win);
1478 if (!rf_helper->account_name)
1479 rf_helper->account_name =
1480 modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
1482 if (MODEST_IS_MSG_VIEW_WINDOW(win)) {
1485 /* Get header and message. Do not free them here, the
1486 reply_forward_cb must do it */
1487 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW(win));
1488 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW(win));
1489 if (!msg || !header) {
1491 g_object_unref (msg);
1492 g_printerr ("modest: no message found\n");
1495 reply_forward_cb (NULL, header, msg, rf_helper);
1498 g_object_unref (header);
1503 /* Only reply/forward to one message */
1504 iter = tny_list_create_iterator (header_list);
1505 header = TNY_HEADER (tny_iterator_get_current (iter));
1506 g_object_unref (iter);
1509 /* Retrieve messages */
1512 modest_mail_operation_new_with_error_handling (G_OBJECT(win),
1513 modest_ui_actions_get_msgs_full_error_handler,
1515 modest_mail_operation_queue_add (
1516 modest_runtime_get_mail_operation_queue (), mail_op);
1518 modest_mail_operation_get_msg (mail_op,
1523 g_object_unref(mail_op);
1525 /* we put a ref here to prevent double unref as the reply
1526 * forward callback unrefs the header at its end */
1527 reply_forward_cb (NULL, header, NULL, rf_helper);
1531 g_object_unref (header);
1537 g_object_unref (header_list);
1541 modest_ui_actions_on_reply (GtkAction *action, ModestWindow *win)
1543 g_return_if_fail (MODEST_IS_WINDOW(win));
1545 reply_forward (ACTION_REPLY, win);
1549 modest_ui_actions_on_forward (GtkAction *action, ModestWindow *win)
1551 g_return_if_fail (MODEST_IS_WINDOW(win));
1553 reply_forward (ACTION_FORWARD, win);
1557 modest_ui_actions_on_reply_all (GtkAction *action, ModestWindow *win)
1559 g_return_if_fail (MODEST_IS_WINDOW(win));
1561 reply_forward (ACTION_REPLY_TO_ALL, win);
1565 modest_ui_actions_on_next (GtkAction *action,
1566 ModestWindow *window)
1568 if (MODEST_IS_MAIN_WINDOW (window)) {
1569 GtkWidget *header_view;
1571 header_view = modest_main_window_get_child_widget (
1572 MODEST_MAIN_WINDOW(window),
1573 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1577 modest_header_view_select_next (
1578 MODEST_HEADER_VIEW(header_view));
1579 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
1580 modest_msg_view_window_select_next_message (
1581 MODEST_MSG_VIEW_WINDOW (window));
1583 g_return_if_reached ();
1588 modest_ui_actions_on_prev (GtkAction *action,
1589 ModestWindow *window)
1591 g_return_if_fail (MODEST_IS_WINDOW(window));
1593 if (MODEST_IS_MAIN_WINDOW (window)) {
1594 GtkWidget *header_view;
1595 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
1596 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1600 modest_header_view_select_prev (MODEST_HEADER_VIEW(header_view));
1601 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
1602 modest_msg_view_window_select_previous_message (MODEST_MSG_VIEW_WINDOW (window));
1604 g_return_if_reached ();
1609 modest_ui_actions_on_sort (GtkAction *action,
1610 ModestWindow *window)
1612 g_return_if_fail (MODEST_IS_WINDOW(window));
1614 if (MODEST_IS_MAIN_WINDOW (window)) {
1615 GtkWidget *header_view;
1616 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
1617 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1619 modest_platform_information_banner (NULL, NULL, _CS("ckdg_ib_nothing_to_sort"));
1624 /* Show sorting dialog */
1625 modest_platform_run_sort_dialog (GTK_WINDOW (window), MODEST_SORT_HEADERS);
1630 new_messages_arrived (ModestMailOperation *self,
1631 TnyList *new_headers,
1636 source = modest_mail_operation_get_source (self);
1638 /* Notify new messages have been downloaded. Do not notify if
1639 the send&receive was invoked by the user, i.e, if the mail
1640 operation has a source (the main window) */
1641 if ((new_headers != NULL) && (tny_list_get_length (new_headers) > 0) && !source)
1642 modest_platform_on_new_headers_received (new_headers);
1645 g_object_unref (source);
1649 TnyAccount *account;
1651 gchar *account_name;
1655 do_send_receive_performer (gboolean canceled,
1657 GtkWindow *parent_window,
1658 TnyAccount *account,
1661 ModestMailOperation *mail_op;
1662 SendReceiveInfo *info;
1664 info = (SendReceiveInfo *) user_data;
1666 if (err || canceled) {
1671 /* Set send/receive operation in progress */
1672 if (info->win && MODEST_IS_MAIN_WINDOW (info->win)) {
1673 modest_main_window_notify_send_receive_initied (MODEST_MAIN_WINDOW (info->win));
1676 mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT (info->win),
1677 modest_ui_actions_send_receive_error_handler,
1680 if (info->win && MODEST_IS_MAIN_WINDOW (info->win))
1681 g_signal_connect (G_OBJECT(mail_op), "operation-finished",
1682 G_CALLBACK (on_send_receive_finished),
1685 /* Send & receive. */
1686 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
1687 modest_mail_operation_update_account (mail_op, info->account_name, new_messages_arrived, info->win);
1688 g_object_unref (G_OBJECT (mail_op));
1692 if (info->account_name)
1693 g_free (info->account_name);
1695 g_object_unref (info->win);
1697 g_object_unref (info->account);
1698 g_slice_free (SendReceiveInfo, info);
1702 * This function performs the send & receive required actions. The
1703 * window is used to create the mail operation. Typically it should
1704 * always be the main window, but we pass it as argument in order to
1708 modest_ui_actions_do_send_receive (const gchar *account_name,
1711 gchar *acc_name = NULL;
1712 SendReceiveInfo *info;
1713 ModestTnyAccountStore *acc_store;
1715 /* If no account name was provided then get the current account, and if
1716 there is no current account then pick the default one: */
1717 if (!account_name) {
1719 acc_name = g_strdup (modest_window_get_active_account (win));
1721 acc_name = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
1723 g_printerr ("modest: cannot get default account\n");
1727 acc_name = g_strdup (account_name);
1730 acc_store = modest_runtime_get_account_store ();
1732 /* Create the info for the connect and perform */
1733 info = g_slice_new (SendReceiveInfo);
1734 info->account_name = acc_name;
1735 info->win = (win) ? g_object_ref (win) : NULL;
1736 info->account = modest_tny_account_store_get_server_account (acc_store, acc_name,
1737 TNY_ACCOUNT_TYPE_STORE);
1739 /* Invoke the connect and perform */
1740 modest_platform_connect_and_perform ((win) ? GTK_WINDOW (win) : NULL, info->account,
1741 do_send_receive_performer, info);
1746 modest_ui_actions_do_cancel_send (const gchar *account_name,
1749 TnyTransportAccount *transport_account;
1750 TnySendQueue *send_queue = NULL;
1751 GError *error = NULL;
1753 /* Get transport account */
1755 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
1756 (modest_runtime_get_account_store(),
1758 TNY_ACCOUNT_TYPE_TRANSPORT));
1759 if (!transport_account) {
1760 g_printerr ("modest: no transport account found for '%s'\n", account_name);
1765 send_queue = TNY_SEND_QUEUE (modest_runtime_get_send_queue (transport_account));
1766 if (!TNY_IS_SEND_QUEUE(send_queue)) {
1767 g_set_error (&error, MODEST_MAIL_OPERATION_ERROR,
1768 MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND,
1769 "modest: could not find send queue for account\n");
1771 /* Keeep messages in outbox folder */
1772 tny_send_queue_cancel (send_queue, FALSE, &error);
1776 if (transport_account != NULL)
1777 g_object_unref (G_OBJECT (transport_account));
1781 modest_ui_actions_cancel_send_all (ModestWindow *win)
1783 GSList *account_names, *iter;
1785 account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
1788 iter = account_names;
1790 modest_ui_actions_do_cancel_send ((const char*) iter->data, win);
1791 iter = g_slist_next (iter);
1794 modest_account_mgr_free_account_names (account_names);
1795 account_names = NULL;
1799 modest_ui_actions_cancel_send (GtkAction *action, ModestWindow *win)
1802 /* Check if accounts exist */
1803 gboolean accounts_exist =
1804 modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
1806 /* If not, allow the user to create an account before trying to send/receive. */
1807 if (!accounts_exist)
1808 modest_ui_actions_on_accounts (NULL, win);
1810 /* Cancel all sending operaitons */
1811 modest_ui_actions_cancel_send_all (win);
1815 * Refreshes all accounts. This function will be used by automatic
1819 modest_ui_actions_do_send_receive_all (ModestWindow *win)
1821 GSList *account_names, *iter;
1823 account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
1826 iter = account_names;
1828 modest_ui_actions_do_send_receive ((const char*) iter->data, win);
1829 iter = g_slist_next (iter);
1832 modest_account_mgr_free_account_names (account_names);
1833 account_names = NULL;
1837 * Handler of the click on Send&Receive button in the main toolbar
1840 modest_ui_actions_on_send_receive (GtkAction *action, ModestWindow *win)
1842 /* Check if accounts exist */
1843 gboolean accounts_exist =
1844 modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
1846 /* If not, allow the user to create an account before trying to send/receive. */
1847 if (!accounts_exist)
1848 modest_ui_actions_on_accounts (NULL, win);
1850 /* Refresh the active account */
1851 modest_ui_actions_do_send_receive (NULL, win);
1856 modest_ui_actions_toggle_header_list_view (GtkAction *action, ModestMainWindow *main_window)
1859 GtkWidget *header_view;
1861 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1863 header_view = modest_main_window_get_child_widget (main_window,
1864 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1868 conf = modest_runtime_get_conf ();
1870 /* what is saved/restored is depending on the style; thus; we save with
1871 * old style, then update the style, and restore for this new style
1873 modest_widget_memory_save (conf, G_OBJECT(header_view), MODEST_CONF_HEADER_VIEW_KEY);
1875 if (modest_header_view_get_style
1876 (MODEST_HEADER_VIEW(header_view)) == MODEST_HEADER_VIEW_STYLE_DETAILS)
1877 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
1878 MODEST_HEADER_VIEW_STYLE_TWOLINES);
1880 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
1881 MODEST_HEADER_VIEW_STYLE_DETAILS);
1883 modest_widget_memory_restore (conf, G_OBJECT(header_view),
1884 MODEST_CONF_HEADER_VIEW_KEY);
1889 modest_ui_actions_on_header_selected (ModestHeaderView *header_view,
1891 ModestMainWindow *main_window)
1893 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1894 g_return_if_fail (MODEST_IS_HEADER_VIEW (header_view));
1896 /* in the case the folder is empty, show the empty folder message and focus
1898 if (!header && gtk_widget_is_focus (GTK_WIDGET (header_view))) {
1899 if (modest_header_view_is_empty (header_view)) {
1900 TnyFolder *folder = modest_header_view_get_folder (header_view);
1901 GtkWidget *folder_view =
1902 modest_main_window_get_child_widget (main_window,
1903 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
1905 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view), folder, FALSE);
1906 gtk_widget_grab_focus (GTK_WIDGET (folder_view));
1910 /* If no header has been selected then exit */
1915 if (!gtk_widget_is_focus (GTK_WIDGET(header_view)))
1916 gtk_widget_grab_focus (GTK_WIDGET(header_view));
1918 /* Update toolbar dimming state */
1919 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
1923 modest_ui_actions_on_header_activated (ModestHeaderView *header_view,
1925 ModestMainWindow *main_window)
1929 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1934 if (modest_header_view_count_selected_headers (header_view) > 1) {
1935 hildon_banner_show_information (NULL, NULL, _("mcen_ib_select_one_message"));
1940 /* headers = tny_simple_list_new (); */
1941 /* tny_list_prepend (headers, G_OBJECT (header)); */
1942 headers = modest_header_view_get_selected_headers (header_view);
1944 _modest_ui_actions_open (headers, MODEST_WINDOW (main_window));
1946 g_object_unref (headers);
1950 set_active_account_from_tny_account (TnyAccount *account,
1951 ModestWindow *window)
1953 const gchar *server_acc_name = tny_account_get_id (account);
1955 /* We need the TnyAccount provided by the
1956 account store because that is the one that
1957 knows the name of the Modest account */
1958 TnyAccount *modest_server_account = modest_server_account =
1959 modest_tny_account_store_get_tny_account_by (modest_runtime_get_account_store (),
1960 MODEST_TNY_ACCOUNT_STORE_QUERY_ID,
1962 if (!modest_server_account) {
1963 g_warning ("%s: could not get tny account\n", __FUNCTION__);
1967 /* Update active account, but only if it's not a pseudo-account */
1968 if ((!modest_tny_account_is_virtual_local_folders(modest_server_account)) &&
1969 (!modest_tny_account_is_memory_card_account(modest_server_account))) {
1970 const gchar *modest_acc_name =
1971 modest_tny_account_get_parent_modest_account_name_for_server_account (modest_server_account);
1972 if (modest_acc_name)
1973 modest_window_set_active_account (window, modest_acc_name);
1976 g_object_unref (modest_server_account);
1981 folder_refreshed_cb (ModestMailOperation *mail_op,
1985 ModestMainWindow *win = NULL;
1986 GtkWidget *header_view;
1987 gboolean folder_empty = FALSE;
1988 gboolean all_marked_as_deleted = FALSE;
1990 g_return_if_fail (TNY_IS_FOLDER (folder));
1992 win = MODEST_MAIN_WINDOW (user_data);
1994 modest_main_window_get_child_widget(win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1997 TnyFolder *current_folder;
1999 current_folder = modest_header_view_get_folder (MODEST_HEADER_VIEW (header_view));
2000 if (current_folder != NULL && folder != current_folder) {
2001 g_object_unref (current_folder);
2004 g_object_unref (current_folder);
2007 /* Check if folder is empty and set headers view contents style */
2008 folder_empty = (tny_folder_get_all_count (folder) == 0);
2009 all_marked_as_deleted = modest_header_view_is_empty (MODEST_HEADER_VIEW(header_view));
2010 if (folder_empty || all_marked_as_deleted)
2011 modest_main_window_set_contents_style (win,
2012 MODEST_MAIN_WINDOW_CONTENTS_STYLE_EMPTY);
2016 modest_ui_actions_on_folder_selection_changed (ModestFolderView *folder_view,
2017 TnyFolderStore *folder_store,
2019 ModestMainWindow *main_window)
2022 GtkWidget *header_view;
2024 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2026 header_view = modest_main_window_get_child_widget(main_window,
2027 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2031 conf = modest_runtime_get_conf ();
2033 if (TNY_IS_ACCOUNT (folder_store)) {
2035 set_active_account_from_tny_account (TNY_ACCOUNT (folder_store), MODEST_WINDOW (main_window));
2037 /* Show account details */
2038 modest_main_window_set_contents_style (main_window, MODEST_MAIN_WINDOW_CONTENTS_STYLE_DETAILS);
2041 if (TNY_IS_FOLDER (folder_store) && selected) {
2043 /* Update the active account */
2044 TnyAccount *account = modest_tny_folder_get_account (TNY_FOLDER (folder_store));
2046 set_active_account_from_tny_account (account, MODEST_WINDOW (main_window));
2047 g_object_unref (account);
2051 /* Set the header style by default, it could
2052 be changed later by the refresh callback to
2054 modest_main_window_set_contents_style (main_window,
2055 MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS);
2057 /* Set folder on header view. This function
2058 will call tny_folder_refresh_async so we
2059 pass a callback that will be called when
2060 finished. We use that callback to set the
2061 empty view if there are no messages */
2062 modest_header_view_set_folder (MODEST_HEADER_VIEW(header_view),
2063 TNY_FOLDER (folder_store),
2064 folder_refreshed_cb,
2067 /* Restore configuration. We need to do this
2068 *after* the set_folder because the widget
2069 memory asks the header view about its
2071 modest_widget_memory_restore (modest_runtime_get_conf (),
2072 G_OBJECT(header_view),
2073 MODEST_CONF_HEADER_VIEW_KEY);
2075 /* Update the active account */
2076 //modest_window_set_active_account (MODEST_WINDOW (main_window), NULL);
2077 /* Save only if we're seeing headers */
2078 if (modest_main_window_get_contents_style (main_window) ==
2079 MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS)
2080 modest_widget_memory_save (conf, G_OBJECT (header_view),
2081 MODEST_CONF_HEADER_VIEW_KEY);
2082 modest_header_view_clear (MODEST_HEADER_VIEW(header_view));
2086 /* Update toolbar dimming state */
2087 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
2091 modest_ui_actions_on_item_not_found (ModestHeaderView *header_view,ModestItemType type,
2098 item = (type == MODEST_ITEM_TYPE_FOLDER) ? "folder" : "message";
2100 online = tny_device_is_online (modest_runtime_get_device());
2103 /* already online -- the item is simply not there... */
2104 dialog = gtk_message_dialog_new (GTK_WINDOW (win),
2106 GTK_MESSAGE_WARNING,
2108 _("The %s you selected cannot be found"),
2110 gtk_dialog_add_button (GTK_DIALOG (dialog),_("mcen_bd_dialog_ok"), GTK_RESPONSE_ACCEPT);
2111 gtk_dialog_run (GTK_DIALOG(dialog));
2113 dialog = gtk_dialog_new_with_buttons (_("Connection requested"),
2116 _("mcen_bd_dialog_cancel"),
2117 GTK_RESPONSE_REJECT,
2118 _("mcen_bd_dialog_ok"),
2119 GTK_RESPONSE_ACCEPT,
2121 txt = g_strdup_printf (_("This %s is not available in offline mode.\n"
2122 "Do you want to get online?"), item);
2123 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
2124 gtk_label_new (txt), FALSE, FALSE, 0);
2125 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
2128 gtk_window_set_default_size (GTK_WINDOW(dialog), 300, 300);
2129 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
2130 /* TODO: Comment about why is this commented out: */
2131 /* modest_platform_connect_and_wait (); */
2134 gtk_widget_destroy (dialog);
2138 modest_ui_actions_on_msg_link_hover (ModestMsgView *msgview, const gchar* link,
2141 /* g_message ("%s %s", __FUNCTION__, link); */
2146 modest_ui_actions_on_msg_link_clicked (ModestMsgView *msgview, const gchar* link,
2149 modest_platform_activate_uri (link);
2153 modest_ui_actions_on_msg_link_contextual (ModestMsgView *msgview, const gchar* link,
2156 modest_platform_show_uri_popup (link);
2160 modest_ui_actions_on_msg_attachment_clicked (ModestMsgView *msgview, TnyMimePart *mime_part,
2163 modest_msg_view_window_view_attachment (MODEST_MSG_VIEW_WINDOW (win), mime_part);
2167 modest_ui_actions_on_msg_recpt_activated (ModestMsgView *msgview,
2168 const gchar *address,
2171 /* g_message ("%s %s", __FUNCTION__, address); */
2175 on_save_to_drafts_cb (ModestMailOperation *mail_op,
2176 TnyMsg *saved_draft,
2179 ModestMsgEditWindow *edit_window;
2182 edit_window = MODEST_MSG_EDIT_WINDOW (user_data);
2184 /* If there was any error do nothing */
2185 if (modest_mail_operation_get_error (mail_op) != NULL)
2188 modest_msg_edit_window_set_draft (edit_window, saved_draft);
2189 info_text = g_strdup_printf (_("mail_va_saved_to_drafts"), _("mcen_me_folder_drafts"));
2190 modest_platform_information_banner (NULL, NULL, info_text);
2195 modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edit_window)
2197 TnyTransportAccount *transport_account;
2198 ModestMailOperation *mail_operation;
2200 gchar *account_name, *from;
2201 ModestAccountMgr *account_mgr;
2203 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window));
2205 data = modest_msg_edit_window_get_msg_data (edit_window);
2207 account_name = g_strdup (data->account_name);
2208 account_mgr = modest_runtime_get_account_mgr();
2210 account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
2212 account_name = modest_account_mgr_get_default_account (account_mgr);
2213 if (!account_name) {
2214 g_printerr ("modest: no account found\n");
2215 modest_msg_edit_window_free_msg_data (edit_window, data);
2219 if (!strcmp (account_name, MODEST_LOCAL_FOLDERS_ACCOUNT_ID)) {
2220 account_name = g_strdup (data->account_name);
2224 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
2225 (modest_runtime_get_account_store(),
2227 TNY_ACCOUNT_TYPE_TRANSPORT));
2228 if (!transport_account) {
2229 g_printerr ("modest: no transport account found for '%s'\n", account_name);
2230 g_free (account_name);
2231 modest_msg_edit_window_free_msg_data (edit_window, data);
2234 from = modest_account_mgr_get_from_string (account_mgr, account_name);
2236 /* Create the mail operation */
2237 mail_operation = modest_mail_operation_new (G_OBJECT(edit_window));
2238 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
2240 modest_mail_operation_save_to_drafts (mail_operation,
2252 data->priority_flags,
2253 on_save_to_drafts_cb,
2257 g_free (account_name);
2258 g_object_unref (G_OBJECT (transport_account));
2259 g_object_unref (G_OBJECT (mail_operation));
2261 modest_msg_edit_window_free_msg_data (edit_window, data);
2262 modest_msg_edit_window_reset_modified (edit_window);
2265 /* For instance, when clicking the Send toolbar button when editing a message: */
2267 modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
2269 TnyTransportAccount *transport_account = NULL;
2271 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window));
2273 if (!modest_msg_edit_window_check_names (edit_window, TRUE))
2276 /* FIXME: Code added just for testing. The final version will
2277 use the send queue provided by tinymail and some
2279 MsgData *data = modest_msg_edit_window_get_msg_data (edit_window);
2281 ModestAccountMgr *account_mgr = modest_runtime_get_account_mgr();
2282 gchar *account_name = g_strdup (data->account_name);
2284 g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
2287 account_name = modest_account_mgr_get_default_account (account_mgr);
2289 if (!account_name) {
2290 modest_msg_edit_window_free_msg_data (edit_window, data);
2291 /* Run account setup wizard */
2292 if (!modest_ui_actions_run_account_setup_wizard (MODEST_WINDOW(edit_window)))
2296 /* Get the currently-active transport account for this modest account: */
2297 /* TnyTransportAccount *transport_account = */
2298 /* TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_transport_account_for_open_connection */
2299 /* (modest_runtime_get_account_store(), */
2300 /* account_name)); */
2301 if (strcmp (account_name, MODEST_LOCAL_FOLDERS_ACCOUNT_ID) != 0) {
2302 transport_account = TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
2303 (modest_runtime_get_account_store(),
2304 account_name, TNY_ACCOUNT_TYPE_TRANSPORT));
2307 if (!transport_account) {
2308 /* Run account setup wizard */
2309 if (!modest_ui_actions_run_account_setup_wizard(MODEST_WINDOW(edit_window)))
2313 gchar *from = modest_account_mgr_get_from_string (account_mgr, account_name);
2315 /* Create the mail operation */
2316 ModestMailOperation *mail_operation = modest_mail_operation_new (G_OBJECT(edit_window));
2317 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
2319 modest_mail_operation_send_new_mail (mail_operation,
2331 data->priority_flags);
2335 g_free (account_name);
2336 g_object_unref (G_OBJECT (transport_account));
2337 g_object_unref (G_OBJECT (mail_operation));
2339 modest_msg_edit_window_free_msg_data (edit_window, data);
2340 modest_msg_edit_window_set_sent (edit_window, TRUE);
2342 /* Save settings and close the window: */
2343 modest_ui_actions_on_close_window (NULL, MODEST_WINDOW (edit_window));
2347 modest_ui_actions_on_toggle_bold (GtkToggleAction *action,
2348 ModestMsgEditWindow *window)
2350 ModestMsgEditFormatState *format_state = NULL;
2352 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2353 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
2355 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2358 format_state = modest_msg_edit_window_get_format_state (window);
2359 g_return_if_fail (format_state != NULL);
2361 format_state->bold = gtk_toggle_action_get_active (action);
2362 modest_msg_edit_window_set_format_state (window, format_state);
2363 g_free (format_state);
2368 modest_ui_actions_on_toggle_italics (GtkToggleAction *action,
2369 ModestMsgEditWindow *window)
2371 ModestMsgEditFormatState *format_state = NULL;
2373 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2374 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
2376 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2379 format_state = modest_msg_edit_window_get_format_state (window);
2380 g_return_if_fail (format_state != NULL);
2382 format_state->italics = gtk_toggle_action_get_active (action);
2383 modest_msg_edit_window_set_format_state (window, format_state);
2384 g_free (format_state);
2389 modest_ui_actions_on_toggle_bullets (GtkToggleAction *action,
2390 ModestMsgEditWindow *window)
2392 ModestMsgEditFormatState *format_state = NULL;
2394 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2395 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
2397 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2400 format_state = modest_msg_edit_window_get_format_state (window);
2401 g_return_if_fail (format_state != NULL);
2403 format_state->bullet = gtk_toggle_action_get_active (action);
2404 modest_msg_edit_window_set_format_state (window, format_state);
2405 g_free (format_state);
2410 modest_ui_actions_on_change_justify (GtkRadioAction *action,
2411 GtkRadioAction *selected,
2412 ModestMsgEditWindow *window)
2414 ModestMsgEditFormatState *format_state = NULL;
2415 GtkJustification value;
2417 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2419 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2422 value = gtk_radio_action_get_current_value (selected);
2424 format_state = modest_msg_edit_window_get_format_state (window);
2425 g_return_if_fail (format_state != NULL);
2427 format_state->justification = value;
2428 modest_msg_edit_window_set_format_state (window, format_state);
2429 g_free (format_state);
2433 modest_ui_actions_on_select_editor_color (GtkAction *action,
2434 ModestMsgEditWindow *window)
2436 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2437 g_return_if_fail (GTK_IS_ACTION (action));
2439 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2442 modest_msg_edit_window_select_color (window);
2446 modest_ui_actions_on_select_editor_background_color (GtkAction *action,
2447 ModestMsgEditWindow *window)
2449 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2450 g_return_if_fail (GTK_IS_ACTION (action));
2452 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2455 modest_msg_edit_window_select_background_color (window);
2459 modest_ui_actions_on_insert_image (GtkAction *action,
2460 ModestMsgEditWindow *window)
2462 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2463 g_return_if_fail (GTK_IS_ACTION (action));
2465 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2468 modest_msg_edit_window_insert_image (window);
2472 modest_ui_actions_on_attach_file (GtkAction *action,
2473 ModestMsgEditWindow *window)
2475 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2476 g_return_if_fail (GTK_IS_ACTION (action));
2478 modest_msg_edit_window_offer_attach_file (window);
2482 modest_ui_actions_on_remove_attachments (GtkAction *action,
2483 ModestMsgEditWindow *window)
2485 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2486 g_return_if_fail (GTK_IS_ACTION (action));
2488 modest_msg_edit_window_remove_attachments (window, NULL);
2492 modest_ui_actions_new_folder_error_handler (ModestMailOperation *mail_op,
2495 ModestMainWindow *window = MODEST_MAIN_WINDOW (user_data);
2496 const GError *error = modest_mail_operation_get_error (mail_op);
2499 modest_platform_information_banner (GTK_WIDGET (window), NULL,
2500 _("mail_in_ui_folder_create_error"));
2505 modest_ui_actions_create_folder(GtkWidget *parent_window,
2506 GtkWidget *folder_view)
2508 TnyFolderStore *parent_folder;
2510 parent_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
2512 if (parent_folder) {
2513 gboolean finished = FALSE;
2515 gchar *folder_name = NULL, *suggested_name = NULL;
2516 const gchar *proto_str = NULL;
2517 TnyAccount *account;
2519 if (TNY_IS_ACCOUNT (parent_folder))
2520 account = g_object_ref (parent_folder);
2522 account = tny_folder_get_account (TNY_FOLDER (parent_folder));
2523 proto_str = tny_account_get_proto (TNY_ACCOUNT (account));
2525 if (proto_str && modest_protocol_info_get_transport_store_protocol (proto_str) ==
2526 MODEST_PROTOCOL_STORE_POP) {
2528 hildon_banner_show_information (NULL, NULL, _("mail_in_ui_folder_create_error"));
2530 g_object_unref (account);
2532 /* Run the new folder dialog */
2534 result = modest_platform_run_new_folder_dialog (GTK_WINDOW (parent_window),
2539 g_free (suggested_name);
2540 suggested_name = NULL;
2542 if (result == GTK_RESPONSE_ACCEPT) {
2543 ModestMailOperation *mail_op;
2544 TnyFolder *new_folder = NULL;
2546 mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT(parent_window),
2547 modest_ui_actions_new_folder_error_handler,
2548 parent_window, NULL);
2550 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
2552 new_folder = modest_mail_operation_create_folder (mail_op,
2554 (const gchar *) folder_name);
2556 modest_folder_view_select_folder (MODEST_FOLDER_VIEW(folder_view),
2559 g_object_unref (new_folder);
2562 g_object_unref (mail_op);
2567 suggested_name = folder_name;
2571 g_object_unref (parent_folder);
2576 modest_ui_actions_on_new_folder (GtkAction *action, ModestMainWindow *main_window)
2578 GtkWidget *folder_view;
2580 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2582 folder_view = modest_main_window_get_child_widget (main_window,
2583 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2587 modest_ui_actions_create_folder (GTK_WIDGET (main_window), folder_view);
2591 modest_ui_actions_rename_folder_error_handler (ModestMailOperation *mail_op,
2594 ModestMainWindow *window = MODEST_MAIN_WINDOW (user_data);
2595 const GError *error = NULL;
2596 const gchar *message = NULL;
2598 /* Get error message */
2599 error = modest_mail_operation_get_error (mail_op);
2601 g_return_if_reached ();
2603 switch (error->code) {
2604 case MODEST_MAIL_OPERATION_ERROR_FOLDER_EXISTS:
2605 message = _CS("ckdg_ib_folder_already_exists");
2608 g_warning ("%s: BUG: unexpected error:[%d]: %s", __FUNCTION__,
2609 error->code, error->message);
2613 modest_platform_information_banner (GTK_WIDGET (window), NULL, message);
2617 modest_ui_actions_on_rename_folder (GtkAction *action,
2618 ModestMainWindow *main_window)
2620 TnyFolderStore *folder;
2621 GtkWidget *folder_view;
2622 GtkWidget *header_view;
2624 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2626 folder_view = modest_main_window_get_child_widget (main_window,
2627 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2631 header_view = modest_main_window_get_child_widget (main_window,
2632 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2637 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
2642 if (TNY_IS_FOLDER (folder)) {
2645 const gchar *current_name;
2646 TnyFolderStore *parent;
2647 gboolean do_rename = TRUE;
2649 current_name = tny_folder_get_name (TNY_FOLDER (folder));
2650 parent = tny_folder_get_folder_store (TNY_FOLDER (folder));
2651 response = modest_platform_run_rename_folder_dialog (GTK_WINDOW (main_window),
2652 parent, current_name,
2654 g_object_unref (parent);
2656 if (response != GTK_RESPONSE_ACCEPT || strlen (folder_name) == 0) {
2658 } else if (modest_platform_is_network_folderstore(folder) &&
2659 !tny_device_is_online (modest_runtime_get_device())) {
2660 TnyAccount *account = tny_folder_get_account(TNY_FOLDER(folder));
2661 do_rename = modest_platform_connect_and_wait(GTK_WINDOW(main_window), account);
2662 g_object_unref(account);
2666 ModestMailOperation *mail_op;
2667 GtkTreeSelection *sel = NULL;
2670 modest_mail_operation_new_with_error_handling (G_OBJECT(main_window),
2671 modest_ui_actions_rename_folder_error_handler,
2674 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
2677 /* Clear the headers view */
2678 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_view));
2679 gtk_tree_selection_unselect_all (sel);
2681 /* Select *after* the changes */
2682 modest_folder_view_select_folder (MODEST_FOLDER_VIEW(folder_view),
2683 TNY_FOLDER(folder), TRUE);
2685 /* Actually rename the folder */
2686 modest_mail_operation_rename_folder (mail_op,
2687 TNY_FOLDER (folder),
2688 (const gchar *) folder_name);
2690 g_object_unref (mail_op);
2691 g_free (folder_name);
2694 g_object_unref (folder);
2698 modest_ui_actions_delete_folder_error_handler (ModestMailOperation *mail_op,
2701 GObject *win = modest_mail_operation_get_source (mail_op);
2703 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
2704 _("mail_in_ui_folder_delete_error"));
2705 g_object_unref (win);
2709 delete_folder (ModestMainWindow *main_window, gboolean move_to_trash)
2711 TnyFolderStore *folder;
2712 GtkWidget *folder_view;
2715 gboolean do_delete = TRUE;
2717 g_return_val_if_fail (MODEST_IS_MAIN_WINDOW (main_window), FALSE);
2719 folder_view = modest_main_window_get_child_widget (main_window,
2720 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2724 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
2726 /* Show an error if it's an account */
2727 if (!TNY_IS_FOLDER (folder)) {
2728 modest_platform_run_information_dialog (GTK_WINDOW (main_window),
2729 _("mail_in_ui_folder_delete_error"));
2730 g_object_unref (G_OBJECT (folder));
2735 message = g_strdup_printf (_("mcen_nc_delete_folder_text"),
2736 tny_folder_get_name (TNY_FOLDER (folder)));
2737 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (main_window),
2738 (const gchar *) message);
2741 if (response != GTK_RESPONSE_OK) {
2743 } else if (modest_platform_is_network_folderstore(folder) &&
2744 !tny_device_is_online (modest_runtime_get_device())) {
2745 TnyAccount *account = tny_folder_get_account(TNY_FOLDER(folder));
2746 do_delete = modest_platform_connect_and_wait(GTK_WINDOW(main_window), account);
2747 g_object_unref(account);
2751 ModestMailOperation *mail_op;
2752 GtkTreeSelection *sel;
2754 /* Unselect the folder before deleting it to free the headers */
2755 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_view));
2756 gtk_tree_selection_unselect_all (sel);
2758 /* Create the mail operation */
2760 modest_mail_operation_new_with_error_handling (G_OBJECT(main_window),
2761 modest_ui_actions_delete_folder_error_handler,
2764 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
2766 modest_mail_operation_remove_folder (mail_op, TNY_FOLDER (folder), move_to_trash);
2767 g_object_unref (G_OBJECT (mail_op));
2770 g_object_unref (G_OBJECT (folder));
2776 modest_ui_actions_on_delete_folder (GtkAction *action,
2777 ModestMainWindow *main_window)
2779 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2781 if (delete_folder (main_window, FALSE)) {
2782 GtkWidget *folder_view;
2784 folder_view = modest_main_window_get_child_widget (main_window,
2785 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2786 modest_folder_view_select_first_inbox_or_local (MODEST_FOLDER_VIEW (folder_view));
2791 modest_ui_actions_on_move_folder_to_trash_folder (GtkAction *action, ModestMainWindow *main_window)
2793 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2795 delete_folder (main_window, TRUE);
2800 show_error (GtkWidget *parent_widget, const gchar* text)
2802 hildon_banner_show_information(parent_widget, NULL, text);
2805 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_window, text)); */
2807 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
2814 gtk_dialog_run (dialog);
2815 gtk_widget_destroy (GTK_WIDGET (dialog));
2820 modest_ui_actions_on_password_requested (TnyAccountStore *account_store,
2821 const gchar* server_account_name,
2826 ModestMainWindow *main_window)
2828 g_return_if_fail(server_account_name);
2830 /* Initalize output parameters: */
2837 #ifdef MODEST_PLATFORM_MAEMO
2838 /* Maemo uses a different (awkward) button order,
2839 * It should probably just use gtk_alternative_dialog_button_order ().
2841 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
2844 _("mcen_bd_dialog_ok"),
2845 GTK_RESPONSE_ACCEPT,
2846 _("mcen_bd_dialog_cancel"),
2847 GTK_RESPONSE_REJECT,
2850 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
2854 GTK_RESPONSE_REJECT,
2856 GTK_RESPONSE_ACCEPT,
2858 #endif /* MODEST_PLATFORM_MAEMO */
2860 gtk_window_set_transient_for (GTK_WINDOW(dialog), GTK_WINDOW(main_window));
2862 gchar *server_name = modest_account_mgr_get_server_account_hostname (
2863 modest_runtime_get_account_mgr(), server_account_name);
2864 if (!server_name) {/* This happened once, though I don't know why. murrayc. */
2865 g_warning("%s: Could not get server name for server account '%s'", __FUNCTION__, server_account_name);
2871 /* This causes a warning because the logical ID has no %s in it,
2872 * though the translation does, but there is not much we can do about that: */
2873 gchar *txt = g_strdup_printf (_("mail_ia_password_info"), server_name);
2874 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), gtk_label_new(txt),
2877 g_free (server_name);
2881 gchar *initial_username = modest_account_mgr_get_server_account_username (
2882 modest_runtime_get_account_mgr(), server_account_name);
2884 GtkWidget *entry_username = gtk_entry_new ();
2885 if (initial_username)
2886 gtk_entry_set_text (GTK_ENTRY (entry_username), initial_username);
2887 /* Dim this if a connection has ever succeeded with this username,
2888 * as per the UI spec: */
2889 const gboolean username_known =
2890 modest_account_mgr_get_server_account_username_has_succeeded(
2891 modest_runtime_get_account_mgr(), server_account_name);
2892 gtk_widget_set_sensitive (entry_username, !username_known);
2894 #ifdef MODEST_PLATFORM_MAEMO
2895 /* Auto-capitalization is the default, so let's turn it off: */
2896 hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_username), HILDON_GTK_INPUT_MODE_FULL);
2898 /* Create a size group to be used by all captions.
2899 * Note that HildonCaption does not create a default size group if we do not specify one.
2900 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
2901 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
2903 GtkWidget *caption = hildon_caption_new (sizegroup,
2904 _("mail_fi_username"), entry_username, NULL, HILDON_CAPTION_MANDATORY);
2905 gtk_widget_show (entry_username);
2906 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
2907 FALSE, FALSE, MODEST_MARGIN_HALF);
2908 gtk_widget_show (caption);
2910 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry_username,
2912 #endif /* MODEST_PLATFORM_MAEMO */
2915 GtkWidget *entry_password = gtk_entry_new ();
2916 gtk_entry_set_visibility (GTK_ENTRY(entry_password), FALSE);
2917 /* gtk_entry_set_invisible_char (GTK_ENTRY(entry_password), "*"); */
2919 #ifdef MODEST_PLATFORM_MAEMO
2920 /* Auto-capitalization is the default, so let's turn it off: */
2921 hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_password),
2922 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
2924 caption = hildon_caption_new (sizegroup,
2925 _("mail_fi_password"), entry_password, NULL, HILDON_CAPTION_MANDATORY);
2926 gtk_widget_show (entry_password);
2927 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
2928 FALSE, FALSE, MODEST_MARGIN_HALF);
2929 gtk_widget_show (caption);
2930 g_object_unref (sizegroup);
2932 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry_password,
2934 #endif /* MODEST_PLATFORM_MAEMO */
2936 if (initial_username != NULL)
2937 gtk_widget_grab_focus (GTK_WIDGET (entry_password));
2939 /* This is not in the Maemo UI spec:
2940 remember_pass_check = gtk_check_button_new_with_label (_("Remember password"));
2941 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), remember_pass_check,
2945 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
2947 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
2949 *username = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_username)));
2951 modest_account_mgr_set_server_account_username (
2952 modest_runtime_get_account_mgr(), server_account_name,
2955 const gboolean username_was_changed =
2956 (strcmp (*username, initial_username) != 0);
2957 if (username_was_changed) {
2958 g_warning ("%s: tinymail does not yet support changing the "
2959 "username in the get_password() callback.\n", __FUNCTION__);
2964 *password = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_password)));
2966 /* We do not save the password in the configuration,
2967 * because this function is only called for passwords that should
2968 * not be remembered:
2969 modest_server_account_set_password (
2970 modest_runtime_get_account_mgr(), server_account_name,
2979 show_error(GTK_WIDGET (main_window), _("mail_ib_login_cancelled"));
2991 /* This is not in the Maemo UI spec:
2992 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (remember_pass_check)))
2998 gtk_widget_destroy (dialog);
3000 /* printf ("DEBUG: %s: cancel=%d\n", __FUNCTION__, *cancel); */
3004 modest_ui_actions_on_cut (GtkAction *action,
3005 ModestWindow *window)
3007 GtkWidget *focused_widget;
3008 GtkClipboard *clipboard;
3010 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
3011 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
3012 if (GTK_IS_EDITABLE (focused_widget)) {
3013 gtk_editable_cut_clipboard (GTK_EDITABLE(focused_widget));
3014 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3015 gtk_clipboard_store (clipboard);
3016 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
3017 GtkTextBuffer *buffer;
3019 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
3020 gtk_text_buffer_cut_clipboard (buffer, clipboard, TRUE);
3021 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3022 gtk_clipboard_store (clipboard);
3023 } else if (MODEST_IS_HEADER_VIEW (focused_widget)) {
3024 TnyList *header_list = modest_header_view_get_selected_headers (
3025 MODEST_HEADER_VIEW (focused_widget));
3026 gboolean continue_download = FALSE;
3027 gint num_of_unc_msgs;
3029 num_of_unc_msgs = header_list_count_uncached_msgs(header_list);
3031 if (num_of_unc_msgs) {
3032 TnyAccount *account = get_account_from_header_list (header_list);
3033 continue_download = connect_to_get_msg (window, num_of_unc_msgs, account);
3034 g_object_unref (account);
3037 if (num_of_unc_msgs == 0 || continue_download) {
3038 /* modest_platform_information_banner (
3039 NULL, NULL, _CS("mcen_ib_getting_items"));*/
3040 modest_header_view_cut_selection (
3041 MODEST_HEADER_VIEW (focused_widget));
3044 g_object_unref (header_list);
3045 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
3046 modest_folder_view_cut_selection (MODEST_FOLDER_VIEW (focused_widget));
3051 modest_ui_actions_on_copy (GtkAction *action,
3052 ModestWindow *window)
3054 GtkClipboard *clipboard;
3055 GtkWidget *focused_widget;
3056 gboolean copied = TRUE;
3058 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
3059 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
3061 if (GTK_IS_LABEL (focused_widget)) {
3062 gtk_clipboard_set_text (clipboard, gtk_label_get_text (GTK_LABEL (focused_widget)), -1);
3063 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3064 gtk_clipboard_store (clipboard);
3065 } else if (GTK_IS_EDITABLE (focused_widget)) {
3066 gtk_editable_copy_clipboard (GTK_EDITABLE(focused_widget));
3067 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3068 gtk_clipboard_store (clipboard);
3069 } else if (GTK_IS_HTML (focused_widget)) {
3070 gtk_html_copy (GTK_HTML (focused_widget));
3071 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3072 gtk_clipboard_store (clipboard);
3073 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
3074 GtkTextBuffer *buffer;
3075 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
3076 gtk_text_buffer_copy_clipboard (buffer, clipboard);
3077 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3078 gtk_clipboard_store (clipboard);
3079 } else if (MODEST_IS_HEADER_VIEW (focused_widget)) {
3080 TnyList *header_list = modest_header_view_get_selected_headers (
3081 MODEST_HEADER_VIEW (focused_widget));
3082 gboolean continue_download = FALSE;
3083 gint num_of_unc_msgs;
3085 num_of_unc_msgs = header_list_count_uncached_msgs(header_list);
3087 if (num_of_unc_msgs) {
3088 TnyAccount *account = get_account_from_header_list (header_list);
3089 continue_download = connect_to_get_msg (window, num_of_unc_msgs, account);
3090 g_object_unref (account);
3093 if (num_of_unc_msgs == 0 || continue_download) {
3094 modest_platform_information_banner (
3095 NULL, NULL, _CS("mcen_ib_getting_items"));
3096 modest_header_view_copy_selection (
3097 MODEST_HEADER_VIEW (focused_widget));
3101 g_object_unref (header_list);
3103 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
3104 modest_folder_view_copy_selection (MODEST_FOLDER_VIEW (focused_widget));
3107 /* Show information banner if there was a copy to clipboard */
3109 modest_platform_information_banner (
3110 NULL, NULL, _CS("ecoc_ib_edwin_copied"));
3114 modest_ui_actions_on_undo (GtkAction *action,
3115 ModestWindow *window)
3117 ModestEmailClipboard *clipboard = NULL;
3119 if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
3120 modest_msg_edit_window_undo (MODEST_MSG_EDIT_WINDOW (window));
3121 } else if (MODEST_IS_MAIN_WINDOW (window)) {
3122 /* Clear clipboard source */
3123 clipboard = modest_runtime_get_email_clipboard ();
3124 modest_email_clipboard_clear (clipboard);
3127 g_return_if_reached ();
3132 modest_ui_actions_on_redo (GtkAction *action,
3133 ModestWindow *window)
3135 if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
3136 modest_msg_edit_window_redo (MODEST_MSG_EDIT_WINDOW (window));
3139 g_return_if_reached ();
3145 destroy_information_note (ModestMailOperation *mail_op, gpointer user_data)
3147 /* destroy information note */
3148 gtk_widget_destroy (GTK_WIDGET(user_data));
3153 paste_as_attachment_free (gpointer data)
3155 PasteAsAttachmentHelper *helper = (PasteAsAttachmentHelper *) data;
3157 gtk_widget_destroy (helper->banner);
3158 g_object_unref (helper->banner);
3163 paste_msg_as_attachment_cb (ModestMailOperation *mail_op,
3168 PasteAsAttachmentHelper *helper = (PasteAsAttachmentHelper *) userdata;
3169 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (helper->window));
3174 modest_msg_edit_window_add_part (MODEST_MSG_EDIT_WINDOW (helper->window), TNY_MIME_PART (msg));
3179 modest_ui_actions_on_paste (GtkAction *action,
3180 ModestWindow *window)
3182 GtkWidget *focused_widget = NULL;
3183 GtkWidget *inf_note = NULL;
3184 ModestMailOperation *mail_op = NULL;
3186 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
3187 if (GTK_IS_EDITABLE (focused_widget)) {
3188 gtk_editable_paste_clipboard (GTK_EDITABLE(focused_widget));
3189 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
3190 ModestEmailClipboard *e_clipboard = NULL;
3191 e_clipboard = modest_runtime_get_email_clipboard ();
3192 if (modest_email_clipboard_cleared (e_clipboard)) {
3193 GtkTextBuffer *buffer;
3194 GtkClipboard *clipboard;
3196 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
3197 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
3198 gtk_text_buffer_paste_clipboard (buffer, clipboard, NULL, TRUE);
3199 } else if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
3200 ModestMailOperation *mail_op;
3201 TnyFolder *src_folder;
3204 PasteAsAttachmentHelper *helper = g_new0 (PasteAsAttachmentHelper, 1);
3205 helper->window = MODEST_MSG_EDIT_WINDOW (window);
3206 helper->banner = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
3207 _CS("ckct_nw_pasting"));
3208 modest_email_clipboard_get_data (e_clipboard, &src_folder, &data, &delete);
3209 mail_op = modest_mail_operation_new (G_OBJECT (window));
3210 if (helper->banner != NULL) {
3211 g_object_ref (G_OBJECT (helper->banner));
3212 gtk_window_set_modal (GTK_WINDOW (helper->banner), FALSE);
3213 gtk_widget_show (GTK_WIDGET (helper->banner));
3217 modest_mail_operation_get_msgs_full (mail_op,
3219 (GetMsgAsyncUserCallback) paste_msg_as_attachment_cb,
3221 paste_as_attachment_free);
3224 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
3225 ModestEmailClipboard *clipboard = NULL;
3226 TnyFolder *src_folder = NULL;
3227 TnyFolderStore *folder_store = NULL;
3228 TnyList *data = NULL;
3229 gboolean delete = FALSE;
3231 /* Check clipboard source */
3232 clipboard = modest_runtime_get_email_clipboard ();
3233 if (modest_email_clipboard_cleared (clipboard))
3236 /* Get elements to paste */
3237 modest_email_clipboard_get_data (clipboard, &src_folder, &data, &delete);
3239 /* Create a new mail operation */
3240 mail_op = modest_mail_operation_new (G_OBJECT(window));
3242 /* Get destination folder */
3243 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (focused_widget));
3245 /* transfer messages */
3249 /* Ask for user confirmation */
3251 modest_ui_actions_msgs_move_to_confirmation (window,
3252 TNY_FOLDER (folder_store),
3256 if (response == GTK_RESPONSE_OK) {
3257 /* Launch notification */
3258 inf_note = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
3259 _CS("ckct_nw_pasting"));
3260 if (inf_note != NULL) {
3261 gtk_window_set_modal (GTK_WINDOW(inf_note), FALSE);
3262 gtk_widget_show (GTK_WIDGET(inf_note));
3265 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
3266 modest_mail_operation_xfer_msgs (mail_op,
3268 TNY_FOLDER (folder_store),
3270 destroy_information_note,
3273 g_object_unref (mail_op);
3276 } else if (src_folder != NULL) {
3277 /* Launch notification */
3278 inf_note = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
3279 _CS("ckct_nw_pasting"));
3280 if (inf_note != NULL) {
3281 gtk_window_set_modal (GTK_WINDOW(inf_note), FALSE);
3282 gtk_widget_show (GTK_WIDGET(inf_note));
3285 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
3286 modest_mail_operation_xfer_folder (mail_op,
3290 destroy_information_note,
3296 g_object_unref (data);
3297 if (src_folder != NULL)
3298 g_object_unref (src_folder);
3299 if (folder_store != NULL)
3300 g_object_unref (folder_store);
3306 modest_ui_actions_on_select_all (GtkAction *action,
3307 ModestWindow *window)
3309 GtkWidget *focused_widget;
3311 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
3312 if (MODEST_IS_ATTACHMENTS_VIEW (focused_widget)) {
3313 modest_attachments_view_select_all (MODEST_ATTACHMENTS_VIEW (focused_widget));
3314 } else if (GTK_IS_LABEL (focused_widget)) {
3315 gtk_label_select_region (GTK_LABEL (focused_widget), 0, -1);
3316 } else if (GTK_IS_EDITABLE (focused_widget)) {
3317 gtk_editable_select_region (GTK_EDITABLE(focused_widget), 0, -1);
3318 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
3319 GtkTextBuffer *buffer;
3320 GtkTextIter start, end;
3322 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
3323 gtk_text_buffer_get_start_iter (buffer, &start);
3324 gtk_text_buffer_get_end_iter (buffer, &end);
3325 gtk_text_buffer_select_range (buffer, &start, &end);
3326 } else if (GTK_IS_HTML (focused_widget)) {
3327 gtk_html_select_all (GTK_HTML (focused_widget));
3328 } else if (MODEST_IS_MAIN_WINDOW (window)) {
3329 GtkWidget *header_view = focused_widget;
3330 GtkTreeSelection *selection = NULL;
3332 if (!(MODEST_IS_HEADER_VIEW (focused_widget))) {
3333 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (window),
3334 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
3337 /* Disable window dimming management */
3338 modest_window_disable_dimming (MODEST_WINDOW(window));
3340 /* Select all messages */
3341 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(header_view));
3342 gtk_tree_selection_select_all (selection);
3344 /* Set focuse on header view */
3345 gtk_widget_grab_focus (header_view);
3348 /* Enable window dimming management */
3349 modest_window_enable_dimming (MODEST_WINDOW(window));
3350 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (window));
3356 modest_ui_actions_on_mark_as_read (GtkAction *action,
3357 ModestWindow *window)
3359 g_return_if_fail (MODEST_IS_WINDOW(window));
3361 /* Mark each header as read */
3362 do_headers_action (window, headers_action_mark_as_read, NULL);
3366 modest_ui_actions_on_mark_as_unread (GtkAction *action,
3367 ModestWindow *window)
3369 g_return_if_fail (MODEST_IS_WINDOW(window));
3371 /* Mark each header as read */
3372 do_headers_action (window, headers_action_mark_as_unread, NULL);
3376 modest_ui_actions_on_change_zoom (GtkRadioAction *action,
3377 GtkRadioAction *selected,
3378 ModestWindow *window)
3382 value = gtk_radio_action_get_current_value (selected);
3383 if (MODEST_IS_WINDOW (window)) {
3384 modest_window_set_zoom (MODEST_WINDOW (window), ((gdouble)value)/100);
3389 modest_ui_actions_msg_edit_on_change_priority (GtkRadioAction *action,
3390 GtkRadioAction *selected,
3391 ModestWindow *window)
3393 TnyHeaderFlags flags;
3394 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3396 flags = gtk_radio_action_get_current_value (selected);
3397 modest_msg_edit_window_set_priority_flags (MODEST_MSG_EDIT_WINDOW (window), flags);
3401 modest_ui_actions_msg_edit_on_change_file_format (GtkRadioAction *action,
3402 GtkRadioAction *selected,
3403 ModestWindow *window)
3407 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3409 file_format = gtk_radio_action_get_current_value (selected);
3410 modest_msg_edit_window_set_file_format (MODEST_MSG_EDIT_WINDOW (window), file_format);
3415 modest_ui_actions_on_zoom_plus (GtkAction *action,
3416 ModestWindow *window)
3418 g_return_if_fail (MODEST_IS_WINDOW (window));
3420 modest_window_zoom_plus (MODEST_WINDOW (window));
3424 modest_ui_actions_on_zoom_minus (GtkAction *action,
3425 ModestWindow *window)
3427 g_return_if_fail (MODEST_IS_WINDOW (window));
3429 modest_window_zoom_minus (MODEST_WINDOW (window));
3433 modest_ui_actions_on_toggle_fullscreen (GtkToggleAction *toggle,
3434 ModestWindow *window)
3436 ModestWindowMgr *mgr;
3437 gboolean fullscreen, active;
3438 g_return_if_fail (MODEST_IS_WINDOW (window));
3440 mgr = modest_runtime_get_window_mgr ();
3442 active = (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle)))?1:0;
3443 fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
3445 if (active != fullscreen) {
3446 modest_window_mgr_set_fullscreen_mode (mgr, active);
3447 gtk_window_present (GTK_WINDOW (window));
3452 modest_ui_actions_on_change_fullscreen (GtkAction *action,
3453 ModestWindow *window)
3455 ModestWindowMgr *mgr;
3456 gboolean fullscreen;
3458 g_return_if_fail (MODEST_IS_WINDOW (window));
3460 mgr = modest_runtime_get_window_mgr ();
3461 fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
3462 modest_window_mgr_set_fullscreen_mode (mgr, !fullscreen);
3464 gtk_window_present (GTK_WINDOW (window));
3468 * Used by modest_ui_actions_on_details to call do_headers_action
3471 headers_action_show_details (TnyHeader *header,
3472 ModestWindow *window,
3479 dialog = modest_details_dialog_new_with_header (GTK_WINDOW (window), header);
3482 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
3483 gtk_widget_show_all (dialog);
3484 gtk_dialog_run (GTK_DIALOG (dialog));
3486 gtk_widget_destroy (dialog);
3490 * Show the folder details in a ModestDetailsDialog widget
3493 show_folder_details (TnyFolder *folder,
3499 dialog = modest_details_dialog_new_with_folder (window, folder);
3502 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
3503 gtk_widget_show_all (dialog);
3504 gtk_dialog_run (GTK_DIALOG (dialog));
3506 gtk_widget_destroy (dialog);
3510 * Show the header details in a ModestDetailsDialog widget
3513 modest_ui_actions_on_details (GtkAction *action,
3516 TnyList * headers_list;
3520 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
3523 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW (win));
3526 g_object_unref (msg);
3528 headers_list = get_selected_headers (win);
3532 iter = tny_list_create_iterator (headers_list);
3534 header = TNY_HEADER (tny_iterator_get_current (iter));
3536 headers_action_show_details (header, win, NULL);
3537 g_object_unref (header);
3540 g_object_unref (iter);
3541 g_object_unref (headers_list);
3543 } else if (MODEST_IS_MAIN_WINDOW (win)) {
3544 GtkWidget *folder_view, *header_view;
3546 /* Check which widget has the focus */
3547 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
3548 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3549 if (gtk_widget_is_focus (folder_view)) {
3550 TnyFolderStore *folder_store
3551 = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
3552 if (!folder_store) {
3553 g_warning ("%s: No item was selected.\n", __FUNCTION__);
3556 /* Show only when it's a folder */
3557 /* This function should not be called for account items,
3558 * because we dim the menu item for them. */
3559 if (TNY_IS_FOLDER (folder_store)) {
3560 show_folder_details (TNY_FOLDER (folder_store), GTK_WINDOW (win));
3563 g_object_unref (folder_store);
3566 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
3567 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
3568 /* Show details of each header */
3569 do_headers_action (win, headers_action_show_details, header_view);
3575 modest_ui_actions_on_toggle_show_cc (GtkToggleAction *toggle,
3576 ModestMsgEditWindow *window)
3578 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3580 modest_msg_edit_window_show_cc (window, gtk_toggle_action_get_active (toggle));
3584 modest_ui_actions_on_toggle_show_bcc (GtkToggleAction *toggle,
3585 ModestMsgEditWindow *window)
3587 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3589 modest_msg_edit_window_show_bcc (window, gtk_toggle_action_get_active (toggle));
3593 modest_ui_actions_toggle_folders_view (GtkAction *action,
3594 ModestMainWindow *main_window)
3596 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
3598 if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)))
3599 modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SPLIT);
3601 modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SIMPLE);
3605 modest_ui_actions_on_toggle_toolbar (GtkToggleAction *toggle,
3606 ModestWindow *window)
3608 gboolean active, fullscreen = FALSE;
3609 ModestWindowMgr *mgr;
3611 active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle));
3613 /* Check if we want to toggle the toolbar vuew in fullscreen
3615 if (!strcmp (gtk_action_get_name (GTK_ACTION (toggle)),
3616 "ViewShowToolbarFullScreen")) {
3620 /* Toggle toolbar */
3621 mgr = modest_runtime_get_window_mgr ();
3622 modest_window_mgr_show_toolbars (mgr, G_TYPE_FROM_INSTANCE (window), active, fullscreen);
3626 modest_ui_actions_msg_edit_on_select_font (GtkAction *action,
3627 ModestMsgEditWindow *window)
3629 modest_msg_edit_window_select_font (window);
3633 modest_ui_actions_on_folder_display_name_changed (ModestFolderView *folder_view,
3634 const gchar *display_name,
3637 /* Do not change the application name if the widget has not
3638 the focus. This callback could be called even if the folder
3639 view has not the focus, because the handled signal could be
3640 emitted when the folder view is redrawn */
3641 if (gtk_widget_is_focus (GTK_WIDGET (folder_view))) {
3643 gtk_window_set_title (window, display_name);
3645 gtk_window_set_title (window, " ");
3650 modest_ui_actions_on_select_contacts (GtkAction *action, ModestMsgEditWindow *window)
3652 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3653 modest_msg_edit_window_select_contacts (window);
3657 modest_ui_actions_on_check_names (GtkAction *action, ModestMsgEditWindow *window)
3659 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3660 modest_msg_edit_window_check_names (window, FALSE);
3664 create_move_to_dialog_on_new_folder(GtkWidget *button, gpointer user_data)
3666 modest_ui_actions_create_folder (gtk_widget_get_toplevel (button),
3667 GTK_WIDGET (user_data));
3671 * This function is used to track changes in the selection of the
3672 * folder view that is inside the "move to" dialog to enable/disable
3673 * the OK button because we do not want the user to select a disallowed
3674 * destination for a folder.
3675 * The user also not desired to be able to use NEW button on items where
3676 * folder creation is not possibel.
3679 on_move_to_dialog_folder_selection_changed (ModestFolderView* self,
3680 TnyFolderStore *folder_store,
3684 GtkWidget *dialog = NULL;
3685 GtkWidget *ok_button = NULL, *new_button = NULL;
3686 GList *children = NULL;
3687 gboolean ok_sensitive = TRUE, new_sensitive = TRUE;
3688 gboolean moving_folder = FALSE;
3689 gboolean is_local_account = TRUE;
3690 GtkWidget *folder_view = NULL;
3691 ModestTnyFolderRules rules;
3696 /* Get the OK button */
3697 dialog = gtk_widget_get_ancestor (GTK_WIDGET (self), GTK_TYPE_DIALOG);
3701 children = gtk_container_get_children (GTK_CONTAINER (GTK_DIALOG (dialog)->action_area));
3702 ok_button = GTK_WIDGET (children->next->next->data);
3703 new_button = GTK_WIDGET (children->next->data);
3704 g_list_free (children);
3706 /* check if folder_store is an remote account */
3707 if (TNY_IS_ACCOUNT (folder_store)) {
3708 TnyAccount *local_account = NULL;
3709 TnyAccount *mmc_account = NULL;
3710 ModestTnyAccountStore *account_store = NULL;
3712 account_store = modest_runtime_get_account_store ();
3713 local_account = modest_tny_account_store_get_local_folders_account (account_store);
3714 mmc_account = modest_tny_account_store_get_mmc_folders_account (account_store);
3716 if ((gpointer) local_account != (gpointer) folder_store &&
3717 (gpointer) mmc_account != (gpointer) folder_store) {
3718 is_local_account = FALSE;
3719 /* New button should be dimmed on remote
3721 new_sensitive = FALSE;
3723 g_object_unref (local_account);
3726 /* Check the target folder rules */
3727 if (TNY_IS_FOLDER (folder_store)) {
3728 rules = modest_tny_folder_get_rules (TNY_FOLDER (folder_store));
3729 if (rules & MODEST_FOLDER_RULES_FOLDER_NON_WRITEABLE) {
3730 ok_sensitive = FALSE;
3731 new_sensitive = FALSE;
3736 /* Check if we're moving a folder */
3737 if (MODEST_IS_MAIN_WINDOW (user_data)) {
3738 /* Get the widgets */
3739 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (user_data),
3740 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3741 if (gtk_widget_is_focus (folder_view))
3742 moving_folder = TRUE;
3745 if (moving_folder) {
3746 TnyFolderStore *moved_folder = NULL, *parent = NULL;
3748 /* Get the folder to move */
3749 moved_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
3751 /* Check that we're not moving to the same folder */
3752 if (TNY_IS_FOLDER (moved_folder)) {
3753 parent = tny_folder_get_folder_store (TNY_FOLDER (moved_folder));
3754 if (parent == folder_store)
3755 ok_sensitive = FALSE;
3756 g_object_unref (parent);
3759 if (ok_sensitive && TNY_IS_ACCOUNT (folder_store)) {
3760 /* Do not allow to move to an account unless it's the
3761 local folders account */
3762 if (!is_local_account)
3763 ok_sensitive = FALSE;
3766 if (ok_sensitive && (moved_folder == folder_store)) {
3767 /* Do not allow to move to itself */
3768 ok_sensitive = FALSE;
3770 g_object_unref (moved_folder);
3772 TnyHeader *header = NULL;
3773 TnyFolder *src_folder = NULL;
3775 /* Moving a message */
3776 if (MODEST_IS_MSG_VIEW_WINDOW (user_data)) {
3777 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (user_data));
3778 src_folder = tny_header_get_folder (header);
3779 g_object_unref (header);
3782 TNY_FOLDER (modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view)));
3785 /* Do not allow to move the msg to the same folder */
3786 /* Do not allow to move the msg to an account */
3787 if ((gpointer) src_folder == (gpointer) folder_store ||
3788 TNY_IS_ACCOUNT (folder_store))
3789 ok_sensitive = FALSE;
3790 g_object_unref (src_folder);
3794 /* Set sensitivity of the OK button */
3795 gtk_widget_set_sensitive (ok_button, ok_sensitive);
3796 /* Set sensitivity of the NEW button */
3797 gtk_widget_set_sensitive (new_button, new_sensitive);
3801 create_move_to_dialog (GtkWindow *win,
3802 GtkWidget *folder_view,
3803 GtkWidget **tree_view)
3805 GtkWidget *dialog, *scroll;
3806 GtkWidget *new_button;
3808 dialog = gtk_dialog_new_with_buttons (_("mcen_ti_moveto_folders_title"),
3810 GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR | GTK_DIALOG_DESTROY_WITH_PARENT,
3813 gtk_dialog_add_button (GTK_DIALOG (dialog), _("mcen_bd_dialog_ok"), GTK_RESPONSE_ACCEPT);
3814 /* We do this manually so GTK+ does not associate a response ID for
3816 new_button = gtk_button_new_from_stock (_("mcen_bd_new"));
3817 gtk_box_pack_end (GTK_BOX (GTK_DIALOG (dialog)->action_area), new_button, FALSE, FALSE, 0);
3818 gtk_dialog_add_button (GTK_DIALOG (dialog), _("mcen_bd_dialog_cancel"), GTK_RESPONSE_REJECT);
3820 /* Create scrolled window */
3821 scroll = gtk_scrolled_window_new (NULL, NULL);
3822 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll),
3823 GTK_POLICY_AUTOMATIC,
3824 GTK_POLICY_AUTOMATIC);
3826 /* Create folder view */
3827 *tree_view = modest_platform_create_folder_view (NULL);
3829 /* Track changes in the selection to
3830 * disable the OK button whenever "Move to" is not possible
3831 * disbale NEW button whenever New is not possible */
3832 g_signal_connect (*tree_view,
3833 "folder_selection_changed",
3834 G_CALLBACK (on_move_to_dialog_folder_selection_changed),
3837 /* Listen to clicks on New button */
3838 g_signal_connect (G_OBJECT (new_button),
3840 G_CALLBACK(create_move_to_dialog_on_new_folder),
3843 /* It could happen that we're trying to move a message from a
3844 window (msg window for example) after the main window was
3845 closed, so we can not just get the model of the folder
3847 if (MODEST_IS_FOLDER_VIEW (folder_view)) {
3848 const gchar *visible_id = NULL;
3850 modest_folder_view_set_style (MODEST_FOLDER_VIEW (*tree_view),
3851 MODEST_FOLDER_VIEW_STYLE_SHOW_ALL);
3852 modest_folder_view_copy_model (MODEST_FOLDER_VIEW(folder_view),
3853 MODEST_FOLDER_VIEW(*tree_view));
3856 modest_folder_view_get_account_id_of_visible_server_account (MODEST_FOLDER_VIEW(folder_view));
3858 /* Show the same account than the one that is shown in the main window */
3859 modest_folder_view_set_account_id_of_visible_server_account (MODEST_FOLDER_VIEW(*tree_view),
3862 const gchar *active_account_name = NULL;
3863 ModestAccountMgr *mgr = NULL;
3864 ModestAccountData *acc_data = NULL;
3866 modest_folder_view_set_style (MODEST_FOLDER_VIEW (*tree_view),
3867 MODEST_FOLDER_VIEW_STYLE_SHOW_ALL);
3868 modest_folder_view_update_model (MODEST_FOLDER_VIEW (*tree_view),
3869 TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()));
3871 active_account_name = modest_window_get_active_account (MODEST_WINDOW (win));
3872 mgr = modest_runtime_get_account_mgr ();
3873 acc_data = modest_account_mgr_get_account_data (mgr, active_account_name);
3875 /* Set the new visible & active account */
3876 if (acc_data && acc_data->store_account) {
3877 modest_folder_view_set_account_id_of_visible_server_account (MODEST_FOLDER_VIEW (*tree_view),
3878 acc_data->store_account->account_name);
3879 modest_account_mgr_free_account_data (mgr, acc_data);
3883 /* Hide special folders */
3884 modest_folder_view_show_non_move_folders (MODEST_FOLDER_VIEW (*tree_view), FALSE);
3886 gtk_container_add (GTK_CONTAINER (scroll), *tree_view);
3888 /* Add scroll to dialog */
3889 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
3890 scroll, TRUE, TRUE, 0);
3892 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
3893 gtk_window_set_default_size (GTK_WINDOW (dialog), 300, 300);
3899 * Returns TRUE if at least one of the headers of the list belongs to
3900 * a message that has been fully retrieved.
3902 #if 0 /* no longer in use. delete in 2007.10 */
3904 has_retrieved_msgs (TnyList *list)
3907 gboolean found = FALSE;
3909 iter = tny_list_create_iterator (list);
3910 while (!tny_iterator_is_done (iter) && !found) {
3912 TnyHeaderFlags flags = 0;
3914 header = TNY_HEADER (tny_iterator_get_current (iter));
3916 flags = tny_header_get_flags (header);
3917 if (flags & TNY_HEADER_FLAG_CACHED)
3918 /* if (!(flags & TNY_HEADER_FLAG_PARTIAL)) */
3921 g_object_unref (header);
3925 tny_iterator_next (iter);
3927 g_object_unref (iter);
3935 * Shows a confirmation dialog to the user when we're moving messages
3936 * from a remote server to the local storage. Returns the dialog
3937 * response. If it's other kind of movement then it always returns
3940 * This one is used by the next functions:
3941 * modest_ui_actions_on_paste - commented out
3942 * drag_and_drop_from_header_view (for d&d in modest_folder_view.c)
3945 modest_ui_actions_msgs_move_to_confirmation (ModestWindow *win,
3946 TnyFolder *dest_folder,
3950 gint response = GTK_RESPONSE_OK;
3951 TnyAccount *account = NULL;
3952 TnyFolder *src_folder = NULL;
3953 TnyIterator *iter = NULL;
3954 TnyHeader *header = NULL;
3956 /* return with OK if the destination is a remote folder */
3957 if (modest_tny_folder_is_remote_folder (dest_folder))
3958 return GTK_RESPONSE_OK;
3960 /* Get source folder */
3961 iter = tny_list_create_iterator (headers);
3962 header = TNY_HEADER (tny_iterator_get_current (iter));
3964 src_folder = tny_header_get_folder (header);
3965 g_object_unref (header);
3967 g_object_unref (iter);
3969 /* if no src_folder, message may be an attahcment */
3970 if (src_folder == NULL)
3971 return GTK_RESPONSE_CANCEL;
3973 /* If the source is a local or MMC folder */
3974 if (!modest_tny_folder_is_remote_folder (src_folder)) {
3975 g_object_unref (src_folder);
3976 return GTK_RESPONSE_OK;
3979 /* Get the account */
3980 account = tny_folder_get_account (src_folder);
3982 /* now if offline we ask the user */
3983 if(connect_to_get_msg (win, tny_list_get_length (headers), account))
3984 response = GTK_RESPONSE_OK;
3986 response = GTK_RESPONSE_CANCEL;
3989 g_object_unref (src_folder);
3990 g_object_unref (account);
3998 move_to_cb (ModestMailOperation *mail_op, gpointer user_data)
4000 MoveToHelper *helper = (MoveToHelper *) user_data;
4002 /* Note that the operation could have failed, in that case do
4004 if (modest_mail_operation_get_status (mail_op) ==
4005 MODEST_MAIL_OPERATION_STATUS_SUCCESS) {
4007 GObject *object = modest_mail_operation_get_source (mail_op);
4008 if (MODEST_IS_MSG_VIEW_WINDOW (object)) {
4009 ModestMsgViewWindow *self = MODEST_MSG_VIEW_WINDOW (object);
4011 if (!modest_msg_view_window_select_next_message (self))
4012 if (!modest_msg_view_window_select_previous_message (self))
4013 /* No more messages to view, so close this window */
4014 modest_ui_actions_on_close_window (NULL, MODEST_WINDOW(self));
4015 } else if (MODEST_IS_MAIN_WINDOW (object) && helper->reference != NULL) {
4016 GtkWidget *header_view;
4018 GtkTreeSelection *sel;
4020 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(object),
4021 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
4022 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
4023 path = gtk_tree_row_reference_get_path (helper->reference);
4024 gtk_tree_selection_select_path (sel, path);
4025 gtk_tree_path_free (path);
4027 g_object_unref (object);
4030 /* Close the "Pasting" information banner */
4031 gtk_widget_destroy (GTK_WIDGET(helper->banner));
4032 if (helper->reference != NULL)
4033 gtk_tree_row_reference_free (helper->reference);
4038 modest_ui_actions_move_folder_error_handler (ModestMailOperation *mail_op,
4041 ModestWindow *main_window = NULL;
4042 GObject *win = NULL;
4043 const GError *error = NULL;
4044 const gchar *message = NULL;
4046 /* Get error message */
4047 error = modest_mail_operation_get_error (mail_op);
4048 if (error != NULL && error->message != NULL) {
4049 message = error->message;
4051 message = _("mail_in_ui_folder_move_target_error");
4054 /* Disable next automatic folder selection */
4055 main_window = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (),
4056 FALSE); /* don't create */
4058 GtkWidget *folder_view = NULL;
4060 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (main_window),
4061 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
4062 modest_folder_view_disable_next_folder_selection (MODEST_FOLDER_VIEW(folder_view));
4064 if (user_data && TNY_IS_FOLDER (user_data)) {
4065 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view),
4066 TNY_FOLDER (user_data), FALSE);
4070 /* Show notification dialog */
4071 win = modest_mail_operation_get_source (mail_op);
4072 modest_platform_run_information_dialog ((GtkWindow *) win, message);
4074 g_object_unref (win);
4078 modest_ui_actions_send_receive_error_handler (ModestMailOperation *mail_op,
4081 GObject *win = modest_mail_operation_get_source (mail_op);
4082 const GError *error = modest_mail_operation_get_error (mail_op);
4084 g_return_if_fail (error != NULL);
4085 if (error->message != NULL)
4086 g_printerr ("modest: %s\n", error->message);
4088 g_printerr ("modest: unkonw error on send&receive operation");
4090 /* Show error message */
4091 /* if (modest_mail_operation_get_id (mail_op) == MODEST_MAIL_OPERATION_TYPE_RECEIVE) */
4092 /* modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL, */
4093 /* _CS("sfil_ib_unable_to_receive")); */
4095 /* modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL, */
4096 /* _CS("sfil_ib_unable_to_send")); */
4097 g_object_unref (win);
4101 open_msg_for_purge_cb (ModestMailOperation *mail_op,
4108 gint pending_purges = 0;
4109 gboolean some_purged = FALSE;
4110 ModestWindow *win = MODEST_WINDOW (user_data);
4111 ModestWindowMgr *mgr = modest_runtime_get_window_mgr ();
4113 /* If there was any error */
4114 if (!modest_ui_actions_msg_retrieval_check (mail_op, header, msg)) {
4115 modest_window_mgr_unregister_header (mgr, header);
4119 /* Once the message has been retrieved for purging, we check if
4120 * it's all ok for purging */
4122 parts = tny_simple_list_new ();
4123 tny_mime_part_get_parts (TNY_MIME_PART (msg), parts);
4124 iter = tny_list_create_iterator (parts);
4126 while (!tny_iterator_is_done (iter)) {
4128 part = TNY_MIME_PART (tny_iterator_get_current (iter));
4129 if (part && (tny_mime_part_is_attachment (part) || TNY_IS_MSG (part))) {
4130 if (tny_mime_part_is_purged (part))
4137 g_object_unref (part);
4139 tny_iterator_next (iter);
4141 g_object_unref (iter);
4144 if (pending_purges>0) {
4146 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),_("mcen_nc_purge_file_text_inbox"));
4148 if (response == GTK_RESPONSE_OK) {
4149 modest_platform_information_banner (NULL, NULL, _("mcen_ib_removing_attachment"));
4150 iter = tny_list_create_iterator (parts);
4151 while (!tny_iterator_is_done (iter)) {
4154 part = TNY_MIME_PART (tny_iterator_get_current (iter));
4155 if (part && (tny_mime_part_is_attachment (part) || TNY_IS_MSG (part)))
4156 tny_mime_part_set_purged (part);
4159 g_object_unref (part);
4161 tny_iterator_next (iter);
4164 tny_msg_rewrite_cache (msg);
4167 modest_platform_information_banner (NULL, NULL, _("mail_ib_attachment_already_purged"));
4169 g_object_unref (iter);
4171 modest_window_mgr_unregister_header (mgr, header);
4173 g_object_unref (parts);
4177 modest_ui_actions_on_main_window_remove_attachments (GtkAction *action,
4178 ModestMainWindow *win)
4180 GtkWidget *header_view;
4181 TnyList *header_list;
4184 TnyHeaderFlags flags;
4185 ModestWindow *msg_view_window = NULL;
4188 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win));
4190 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
4191 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
4193 header_list = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW (header_view));
4195 g_warning ("%s: no header selected", __FUNCTION__);
4199 if (tny_list_get_length (header_list) == 1) {
4200 iter = tny_list_create_iterator (header_list);
4201 header = TNY_HEADER (tny_iterator_get_current (iter));
4202 g_object_unref (iter);
4206 if (!header || !TNY_IS_HEADER(header)) {
4207 g_warning ("%s: header is not valid", __FUNCTION__);
4211 found = modest_window_mgr_find_registered_header (modest_runtime_get_window_mgr (),
4212 header, &msg_view_window);
4213 flags = tny_header_get_flags (header);
4214 if (!(flags & TNY_HEADER_FLAG_CACHED))
4217 if (msg_view_window != NULL)
4218 modest_msg_view_window_remove_attachments (MODEST_MSG_VIEW_WINDOW (msg_view_window), TRUE);
4220 /* do nothing; uid was registered before, so window is probably on it's way */
4221 g_warning ("debug: header %p has already been registered", header);
4224 ModestMailOperation *mail_op = NULL;
4225 modest_window_mgr_register_header (modest_runtime_get_window_mgr (), header, NULL);
4226 mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT (win),
4227 modest_ui_actions_get_msgs_full_error_handler,
4229 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
4230 modest_mail_operation_get_msg (mail_op, header, open_msg_for_purge_cb, win);
4232 g_object_unref (mail_op);
4235 g_object_unref (header);
4237 g_object_unref (header_list);
4241 * Utility function that transfer messages from both the main window
4242 * and the msg view window when using the "Move to" dialog
4245 modest_ui_actions_xfer_messages_from_move_to (TnyFolderStore *dst_folder,
4248 TnyList *headers = NULL;
4249 TnyAccount *dst_account = NULL;
4250 const gchar *proto_str = NULL;
4251 gboolean dst_is_pop = FALSE;
4253 if (!TNY_IS_FOLDER (dst_folder)) {
4254 modest_platform_information_banner (GTK_WIDGET (win),
4256 _CS("ckdg_ib_unable_to_move_to_current_location"));
4260 dst_account = tny_folder_get_account (TNY_FOLDER (dst_folder));
4261 proto_str = tny_account_get_proto (dst_account);
4263 /* tinymail will return NULL for local folders it seems */
4264 dst_is_pop = proto_str &&
4265 (modest_protocol_info_get_transport_store_protocol (proto_str) ==
4266 MODEST_PROTOCOL_STORE_POP);
4268 g_object_unref (dst_account);
4270 /* Get selected headers */
4271 headers = get_selected_headers (MODEST_WINDOW (win));
4273 g_warning ("%s: no headers selected", __FUNCTION__);
4279 modest_platform_information_banner (GTK_WIDGET (win),
4281 ngettext("mail_in_ui_folder_move_target_error",
4282 "mail_in_ui_folder_move_targets_error",
4283 tny_list_get_length (headers)));
4284 g_object_unref (headers);
4288 MoveToHelper *helper = g_new0 (MoveToHelper, 1);
4289 helper->banner = modest_platform_animation_banner (GTK_WIDGET (win), NULL,
4290 _CS("ckct_nw_pasting"));
4291 if (helper->banner != NULL) {
4292 gtk_window_set_modal (GTK_WINDOW(helper->banner), FALSE);
4293 gtk_widget_show (GTK_WIDGET(helper->banner));
4296 if (MODEST_IS_MAIN_WINDOW (win)) {
4297 GtkWidget *header_view =
4298 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
4299 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
4300 helper->reference = get_next_after_selected_headers (MODEST_HEADER_VIEW (header_view));
4303 ModestMailOperation *mail_op =
4304 modest_mail_operation_new_with_error_handling (G_OBJECT(win),
4305 modest_ui_actions_move_folder_error_handler,
4307 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
4310 modest_mail_operation_xfer_msgs (mail_op,
4312 TNY_FOLDER (dst_folder),
4317 g_object_unref (G_OBJECT (mail_op));
4318 g_object_unref (headers);
4322 * UI handler for the "Move to" action when invoked from the
4326 modest_ui_actions_on_main_window_move_to (GtkAction *action,
4327 GtkWidget *folder_view,
4328 TnyFolderStore *dst_folder,
4329 ModestMainWindow *win)
4331 ModestHeaderView *header_view = NULL;
4332 ModestMailOperation *mail_op = NULL;
4333 TnyFolderStore *src_folder;
4334 gboolean online = (tny_device_is_online (modest_runtime_get_device()));
4336 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win));
4338 /* Get the source folder */
4339 src_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
4341 /* Get header view */
4342 header_view = MODEST_HEADER_VIEW(modest_main_window_get_child_widget (win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW));
4344 /* Get folder or messages to transfer */
4345 if (gtk_widget_is_focus (folder_view)) {
4346 GtkTreeSelection *sel;
4347 gboolean do_xfer = TRUE;
4349 /* Allow only to transfer folders to the local root folder */
4350 if (TNY_IS_ACCOUNT (dst_folder) &&
4351 !MODEST_IS_TNY_LOCAL_FOLDERS_ACCOUNT (dst_folder)) {
4353 } else if (!TNY_IS_FOLDER (src_folder)) {
4354 g_warning ("%s: src_folder is not a TnyFolder.\n", __FUNCTION__);
4356 } else if (!online && modest_platform_is_network_folderstore(src_folder)) {
4357 guint num_headers = tny_folder_get_all_count(TNY_FOLDER (src_folder));
4358 TnyAccount *account = tny_folder_get_account (TNY_FOLDER (src_folder));
4359 if (!connect_to_get_msg(MODEST_WINDOW (win), num_headers, account))
4361 g_object_unref (account);
4365 MoveToHelper *helper = g_new0 (MoveToHelper, 1);
4366 helper->banner = modest_platform_animation_banner (GTK_WIDGET (win), NULL,
4367 _CS("ckct_nw_pasting"));
4368 if (helper->banner != NULL) {
4369 gtk_window_set_modal (GTK_WINDOW(helper->banner), FALSE);
4370 gtk_widget_show (GTK_WIDGET(helper->banner));
4372 /* Clean folder on header view before moving it */
4373 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_view));
4374 gtk_tree_selection_unselect_all (sel);
4376 /* Let gtk events run. We need that the folder
4377 view frees its reference to the source
4378 folder *before* issuing the mail operation
4379 so we need the signal handler of selection
4380 changed to happen before the mail
4382 while (gtk_events_pending ())
4383 gtk_main_iteration ();
4386 modest_mail_operation_new_with_error_handling (G_OBJECT(win),
4387 modest_ui_actions_move_folder_error_handler,
4389 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
4392 /* Select *after* the changes */
4393 /* TODO: this function hangs UI after transfer */
4394 /* modest_folder_view_select_folder (MODEST_FOLDER_VIEW(folder_view), */
4395 /* TNY_FOLDER (src_folder), TRUE); */
4397 modest_mail_operation_xfer_folder (mail_op,
4398 TNY_FOLDER (src_folder),
4403 /* Unref mail operation */
4404 g_object_unref (G_OBJECT (mail_op));
4406 } else if (gtk_widget_is_focus (GTK_WIDGET(header_view))) {
4407 gboolean do_xfer = TRUE;
4408 /* Ask for confirmation if the source folder is remote and we're not connected */
4409 if (!online && modest_platform_is_network_folderstore(src_folder)) {
4410 TnyList *headers = modest_header_view_get_selected_headers(header_view);
4411 if (!msgs_already_deleted_from_server(headers, src_folder)) {
4412 guint num_headers = tny_list_get_length(headers);
4413 TnyAccount *account = get_account_from_header_list (headers);
4414 if (!connect_to_get_msg(MODEST_WINDOW (win), num_headers, account))
4416 g_object_unref (account);
4418 g_object_unref(headers);
4420 if (do_xfer) /* Transfer messages */
4421 modest_ui_actions_xfer_messages_from_move_to (dst_folder, MODEST_WINDOW (win));
4425 g_object_unref (src_folder);
4430 * UI handler for the "Move to" action when invoked from the
4431 * ModestMsgViewWindow
4434 modest_ui_actions_on_msg_view_window_move_to (GtkAction *action,
4435 TnyFolderStore *dst_folder,
4436 ModestMsgViewWindow *win)
4438 TnyHeader *header = NULL;
4439 TnyFolder *src_folder = NULL;
4440 TnyAccount *account = NULL;
4441 gboolean do_xfer = FALSE;
4443 /* Create header list */
4444 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
4445 src_folder = TNY_FOLDER (tny_header_get_folder(header));
4446 g_object_unref (header);
4448 account = tny_folder_get_account (src_folder);
4449 if (!modest_platform_is_network_folderstore(TNY_FOLDER_STORE(src_folder))) {
4450 /* Transfer if the source folder is local */
4452 } else if (remote_folder_is_pop(TNY_FOLDER_STORE(src_folder))) {
4453 /* Transfer if the source folder is POP (as it means
4454 * that the message is already downloaded) */
4456 } else if (connect_to_get_msg(MODEST_WINDOW(win), 1, account)) {
4457 /* Transfer after asking confirmation */
4462 modest_ui_actions_xfer_messages_from_move_to (dst_folder, MODEST_WINDOW (win));
4464 g_object_unref (account);
4465 g_object_unref (src_folder);
4469 modest_ui_actions_on_move_to (GtkAction *action,
4472 GtkWidget *dialog = NULL, *folder_view = NULL, *tree_view = NULL;
4474 TnyFolderStore *dst_folder = NULL;
4475 ModestMainWindow *main_window;
4477 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win) ||
4478 MODEST_IS_MSG_VIEW_WINDOW (win));
4480 /* Get the main window if exists */
4481 if (MODEST_IS_MAIN_WINDOW (win))
4482 main_window = MODEST_MAIN_WINDOW (win);
4485 MODEST_MAIN_WINDOW (modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (),
4486 FALSE)); /* don't create */
4488 /* Get the folder view widget if exists */
4490 folder_view = modest_main_window_get_child_widget (main_window,
4491 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
4495 /* Create and run the dialog */
4496 dialog = create_move_to_dialog (GTK_WINDOW (win), folder_view, &tree_view);
4497 modest_folder_view_select_first_inbox_or_local (MODEST_FOLDER_VIEW (tree_view));
4498 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
4499 result = gtk_dialog_run (GTK_DIALOG(dialog));
4500 g_object_ref (tree_view);
4501 gtk_widget_destroy (dialog);
4503 if (result != GTK_RESPONSE_ACCEPT)
4506 dst_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (tree_view));
4507 /* Do window specific stuff */
4508 if (MODEST_IS_MAIN_WINDOW (win)) {
4509 modest_ui_actions_on_main_window_move_to (action,
4512 MODEST_MAIN_WINDOW (win));
4514 modest_ui_actions_on_msg_view_window_move_to (action,
4516 MODEST_MSG_VIEW_WINDOW (win));
4520 g_object_unref (dst_folder);
4524 * Calls #HeadersFunc for each header already selected in the main
4525 * window or the message currently being shown in the msg view window
4528 do_headers_action (ModestWindow *win,
4532 TnyList *headers_list = NULL;
4533 TnyIterator *iter = NULL;
4534 TnyHeader *header = NULL;
4535 TnyFolder *folder = NULL;
4538 headers_list = get_selected_headers (win);
4542 /* Get the folder */
4543 iter = tny_list_create_iterator (headers_list);
4544 header = TNY_HEADER (tny_iterator_get_current (iter));
4546 folder = tny_header_get_folder (header);
4547 g_object_unref (header);
4550 /* Call the function for each header */
4551 while (!tny_iterator_is_done (iter)) {
4552 header = TNY_HEADER (tny_iterator_get_current (iter));
4553 func (header, win, user_data);
4554 g_object_unref (header);
4555 tny_iterator_next (iter);
4558 /* Trick: do a poke status in order to speed up the signaling
4560 tny_folder_poke_status (folder);
4563 g_object_unref (folder);
4564 g_object_unref (iter);
4565 g_object_unref (headers_list);
4569 modest_ui_actions_view_attachment (GtkAction *action,
4570 ModestWindow *window)
4572 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
4573 modest_msg_view_window_view_attachment (MODEST_MSG_VIEW_WINDOW (window), NULL);
4575 /* not supported window for this action */
4576 g_return_if_reached ();
4581 modest_ui_actions_save_attachments (GtkAction *action,
4582 ModestWindow *window)
4584 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
4585 modest_msg_view_window_save_attachments (MODEST_MSG_VIEW_WINDOW (window), NULL);
4587 /* not supported window for this action */
4588 g_return_if_reached ();
4593 modest_ui_actions_remove_attachments (GtkAction *action,
4594 ModestWindow *window)
4596 if (MODEST_IS_MAIN_WINDOW (window)) {
4597 modest_ui_actions_on_main_window_remove_attachments (action, MODEST_MAIN_WINDOW (window));
4598 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
4599 modest_msg_view_window_remove_attachments (MODEST_MSG_VIEW_WINDOW (window), FALSE);
4601 /* not supported window for this action */
4602 g_return_if_reached ();
4607 modest_ui_actions_on_settings (GtkAction *action,
4612 dialog = modest_platform_get_global_settings_dialog ();
4613 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (win));
4614 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
4615 gtk_widget_show_all (dialog);
4617 gtk_dialog_run (GTK_DIALOG (dialog));
4619 gtk_widget_destroy (dialog);
4623 modest_ui_actions_on_help (GtkAction *action,
4626 const gchar *help_id;
4628 g_return_if_fail (action);
4629 g_return_if_fail (win && GTK_IS_WINDOW(win));
4631 help_id = modest_window_mgr_get_help_id (modest_runtime_get_window_mgr(), win);
4634 modest_platform_show_help (GTK_WINDOW (win), help_id);
4636 g_warning ("%s: no help for window %p", __FUNCTION__, win);
4640 modest_ui_actions_on_retrieve_msg_contents (GtkAction *action,
4641 ModestWindow *window)
4643 ModestMailOperation *mail_op;
4647 headers = get_selected_headers (window);
4651 /* Create mail operation */
4652 mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT (window),
4653 modest_ui_actions_get_msgs_full_error_handler,
4655 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
4656 modest_mail_operation_get_msgs_full (mail_op, headers, NULL, NULL, NULL);
4659 g_object_unref (headers);
4660 g_object_unref (mail_op);
4664 modest_ui_actions_on_email_menu_activated (GtkAction *action,
4665 ModestWindow *window)
4667 g_return_if_fail (MODEST_IS_WINDOW (window));
4670 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4674 modest_ui_actions_on_edit_menu_activated (GtkAction *action,
4675 ModestWindow *window)
4677 g_return_if_fail (MODEST_IS_WINDOW (window));
4680 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4684 modest_ui_actions_on_view_menu_activated (GtkAction *action,
4685 ModestWindow *window)
4687 g_return_if_fail (MODEST_IS_WINDOW (window));
4690 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4694 modest_ui_actions_on_format_menu_activated (GtkAction *action,
4695 ModestWindow *window)
4697 g_return_if_fail (MODEST_IS_WINDOW (window));
4700 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4704 modest_ui_actions_on_tools_menu_activated (GtkAction *action,
4705 ModestWindow *window)
4707 g_return_if_fail (MODEST_IS_WINDOW (window));
4710 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4714 modest_ui_actions_on_attachment_menu_activated (GtkAction *action,
4715 ModestWindow *window)
4717 g_return_if_fail (MODEST_IS_WINDOW (window));
4720 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4724 modest_ui_actions_on_toolbar_csm_menu_activated (GtkAction *action,
4725 ModestWindow *window)
4727 g_return_if_fail (MODEST_IS_WINDOW (window));
4730 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4734 modest_ui_actions_on_folder_view_csm_menu_activated (GtkAction *action,
4735 ModestWindow *window)
4737 g_return_if_fail (MODEST_IS_WINDOW (window));
4740 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4744 modest_ui_actions_on_header_view_csm_menu_activated (GtkAction *action,
4745 ModestWindow *window)
4747 g_return_if_fail (MODEST_IS_WINDOW (window));
4750 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4754 modest_ui_actions_check_toolbar_dimming_rules (ModestWindow *window)
4756 g_return_if_fail (MODEST_IS_WINDOW (window));
4759 modest_window_check_dimming_rules_group (window, "ModestToolbarDimmingRules");
4763 modest_ui_actions_on_search_messages (GtkAction *action, ModestWindow *window)
4765 g_return_if_fail (MODEST_IS_WINDOW (window));
4767 modest_platform_show_search_messages (GTK_WINDOW (window));
4771 modest_ui_actions_on_open_addressbook (GtkAction *action, ModestWindow *win)
4773 g_return_if_fail (MODEST_IS_WINDOW (win));
4774 modest_platform_show_addressbook (GTK_WINDOW (win));
4779 modest_ui_actions_on_toggle_find_in_page (GtkToggleAction *action,
4780 ModestWindow *window)
4782 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4784 modest_msg_edit_window_toggle_find_toolbar (MODEST_MSG_EDIT_WINDOW (window), gtk_toggle_action_get_active (action));
4788 on_send_receive_finished (ModestMailOperation *mail_op,
4791 GtkWidget *header_view, *folder_view;
4792 TnyFolderStore *folder_store;
4793 ModestMainWindow *main_win = MODEST_MAIN_WINDOW (user_data);
4795 /* Set send/receive operation finished */
4796 modest_main_window_notify_send_receive_completed (main_win);
4798 /* Don't refresh the current folder if there were any errors */
4799 if (modest_mail_operation_get_status (mail_op) !=
4800 MODEST_MAIL_OPERATION_STATUS_SUCCESS)
4803 /* Refresh the current folder if we're viewing a window. We do
4804 this because the user won't be able to see the new mails in
4805 the selected folder after a Send&Receive because it only
4806 performs a poke_status, i.e, only the number of read/unread
4807 messages is updated, but the new headers are not
4809 folder_view = modest_main_window_get_child_widget (main_win,
4810 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
4814 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
4816 /* Do not need to refresh INBOX again because the
4817 update_account does it always automatically */
4818 if (folder_store && TNY_IS_FOLDER (folder_store) &&
4819 tny_folder_get_folder_type (TNY_FOLDER (folder_store)) != TNY_FOLDER_TYPE_INBOX) {
4821 header_view = modest_main_window_get_child_widget (main_win,
4822 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
4824 /* We do not need to set the contents style
4825 because it hasn't changed. We also do not
4826 need to save the widget status. Just force
4828 modest_header_view_set_folder (MODEST_HEADER_VIEW(header_view),
4829 TNY_FOLDER (folder_store),
4830 folder_refreshed_cb,
4835 g_object_unref (folder_store);
4840 modest_ui_actions_on_send_queue_error_happened (TnySendQueue *self,
4846 const gchar* server_name = NULL;
4847 TnyTransportAccount *server_account;
4848 gchar *message = NULL;
4850 /* Don't show anything if the user cancelled something */
4851 if (err->code == TNY_TRANSPORT_ACCOUNT_ERROR_SEND_USER_CANCEL)
4854 /* Get the server name: */
4856 TNY_TRANSPORT_ACCOUNT (tny_camel_send_queue_get_transport_account (TNY_CAMEL_SEND_QUEUE (self)));
4857 if (server_account) {
4858 server_name = tny_account_get_hostname (TNY_ACCOUNT (server_account));
4860 g_object_unref (server_account);
4861 server_account = NULL;
4864 g_return_if_fail (server_name);
4866 /* Show the appropriate message text for the GError: */
4867 switch (err->code) {
4868 case TNY_TRANSPORT_ACCOUNT_ERROR_SEND_HOST_LOOKUP_FAILED:
4869 message = g_strdup_printf (_("emev_ib_ui_smtp_server_invalid"), server_name);
4871 case TNY_TRANSPORT_ACCOUNT_ERROR_SEND_SERVICE_UNAVAILABLE:
4872 message = g_strdup_printf (_("emev_ib_ui_smtp_server_invalid"), server_name);
4874 case TNY_TRANSPORT_ACCOUNT_ERROR_SEND_AUTHENTICATION_NOT_SUPPORTED:
4875 message = g_strdup_printf (_("emev_ni_ui_smtp_authentication_fail_error"), server_name);
4877 case TNY_TRANSPORT_ACCOUNT_ERROR_SEND:
4878 message = g_strdup (_("emev_ib_ui_smtp_send_error"));
4881 g_return_if_reached ();
4884 /* TODO if the username or the password where not defined we
4885 should show the Accounts Settings dialog or the Connection
4886 specific SMTP server window */
4888 modest_platform_run_information_dialog (NULL, message);
4893 modest_ui_actions_on_send_queue_status_changed (ModestTnySendQueue *send_queue,
4898 ModestMainWindow *main_window = NULL;
4899 ModestWindowMgr *mgr = NULL;
4900 GtkWidget *folder_view = NULL, *header_view = NULL;
4901 TnyFolderStore *selected_folder = NULL;
4902 TnyFolderType folder_type;
4904 mgr = modest_runtime_get_window_mgr ();
4905 main_window = MODEST_MAIN_WINDOW (modest_window_mgr_get_main_window (mgr,
4906 FALSE));/* don't create */
4910 /* Check if selected folder is OUTBOX */
4911 folder_view = modest_main_window_get_child_widget (main_window,
4912 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
4913 header_view = modest_main_window_get_child_widget (main_window,
4914 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
4916 selected_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
4917 if (!TNY_IS_FOLDER (selected_folder))
4920 /* gtk_tree_view_column_queue_resize is only available in GTK+ 2.8 */
4921 #if GTK_CHECK_VERSION(2, 8, 0)
4922 folder_type = modest_tny_folder_guess_folder_type (TNY_FOLDER (selected_folder));
4923 if (folder_type == TNY_FOLDER_TYPE_OUTBOX) {
4924 GtkTreeViewColumn *tree_column;
4926 tree_column = gtk_tree_view_get_column (GTK_TREE_VIEW (header_view),
4927 TNY_GTK_HEADER_LIST_MODEL_FROM_COLUMN);
4928 gtk_tree_view_column_queue_resize (tree_column);
4931 gtk_widget_queue_draw (header_view);
4936 if (selected_folder != NULL)
4937 g_object_unref (selected_folder);
4941 modest_ui_actions_on_account_connection_error (GtkWindow *parent_window,
4942 TnyAccount *account)
4944 ModestTransportStoreProtocol proto;
4945 const gchar *proto_name;
4946 gchar *error_note = NULL;
4948 proto_name = tny_account_get_proto (account);
4949 proto = modest_protocol_info_get_transport_store_protocol (proto_name);
4952 case MODEST_PROTOCOL_STORE_POP:
4953 error_note = g_strdup_printf (_("emev_ni_ui_pop3_msg_connect_error"),
4954 tny_account_get_hostname (account));
4956 case MODEST_PROTOCOL_STORE_IMAP:
4957 error_note = g_strdup_printf (_("emev_ni_ui_imap_connect_server_error"),
4958 tny_account_get_hostname (account));
4960 case MODEST_PROTOCOL_STORE_MAILDIR:
4961 case MODEST_PROTOCOL_STORE_MBOX:
4962 error_note = g_strdup (_("emev_nc_mailbox_notavailable"));
4965 g_warning ("%s: This should not be reached", __FUNCTION__);
4969 modest_platform_run_information_dialog (parent_window, error_note);
4970 g_free (error_note);