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-tny-platform-factory.h"
45 #include "modest-platform.h"
46 #include "modest-debug.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>
51 #ifdef MODEST_TOOLKIT_HILDON2
52 #include <hildon/hildon-pannable-area.h>
55 #ifdef MODEST_PLATFORM_MAEMO
56 #include "maemo/modest-osso-state-saving.h"
57 #endif /* MODEST_PLATFORM_MAEMO */
58 #ifndef MODEST_TOOLKIT_GTK
59 #include "maemo/modest-hildon-includes.h"
60 #include "maemo/modest-connection-specific-smtp-window.h"
61 #endif /* !MODEST_TOOLKIT_GTK */
62 #include <modest-utils.h>
64 #include "widgets/modest-ui-constants.h"
65 #include <widgets/modest-main-window.h>
66 #include <widgets/modest-msg-view-window.h>
67 #include <widgets/modest-account-view-window.h>
68 #include <widgets/modest-details-dialog.h>
69 #include <widgets/modest-attachments-view.h>
70 #include "widgets/modest-folder-view.h"
71 #include "widgets/modest-global-settings-dialog.h"
72 #include "modest-account-mgr-helpers.h"
73 #include "modest-mail-operation.h"
74 #include "modest-text-utils.h"
76 #ifdef MODEST_HAVE_EASYSETUP
77 #ifdef MODEST_TOOLKIT_HILDON2
78 #include "modest-easysetup-wizard-dialog.h"
80 #include "easysetup/modest-easysetup-wizard-dialog.h"
82 #endif /* MODEST_HAVE_EASYSETUP */
84 #include <modest-widget-memory.h>
85 #include <tny-error.h>
86 #include <tny-simple-list.h>
87 #include <tny-msg-view.h>
88 #include <tny-device.h>
89 #include <tny-merge-folder.h>
91 #include <gtkhtml/gtkhtml.h>
93 #define MIN_FREE_SPACE 5 * 1024 * 1024
94 #define MOVE_FOLDER_OK_BUTTON "ok-button"
95 #define MOVE_FOLDER_NEW_BUTTON "new-button"
97 typedef struct _GetMsgAsyncHelper {
99 ModestMailOperation *mail_op;
106 typedef enum _ReplyForwardAction {
110 } ReplyForwardAction;
112 typedef struct _ReplyForwardHelper {
113 guint reply_forward_type;
114 ReplyForwardAction action;
116 GtkWidget *parent_window;
118 } ReplyForwardHelper;
120 typedef struct _MoveToHelper {
121 GtkTreeRowReference *reference;
125 typedef struct _PasteAsAttachmentHelper {
126 ModestMsgEditWindow *window;
128 } PasteAsAttachmentHelper;
132 * The do_headers_action uses this kind of functions to perform some
133 * action to each member of a list of headers
135 typedef void (*HeadersFunc) (TnyHeader *header, ModestWindow *win, gpointer user_data);
137 static void do_headers_action (ModestWindow *win,
141 static void open_msg_cb (ModestMailOperation *mail_op,
148 static void reply_forward_cb (ModestMailOperation *mail_op,
155 static void reply_forward (ReplyForwardAction action, ModestWindow *win);
157 static void folder_refreshed_cb (ModestMailOperation *mail_op,
161 static void on_send_receive_finished (ModestMailOperation *mail_op,
164 static gint header_list_count_uncached_msgs (TnyList *header_list);
166 static gboolean connect_to_get_msg (ModestWindow *win,
167 gint num_of_uncached_msgs,
168 TnyAccount *account);
170 static gboolean remote_folder_has_leave_on_server (TnyFolderStore *folder);
172 static void do_create_folder (GtkWindow *window,
173 TnyFolderStore *parent_folder,
174 const gchar *suggested_name);
176 static GtkWidget* get_folder_view_from_move_to_dialog (GtkWidget *move_to_dialog);
178 static TnyAccount *get_account_from_folder_store (TnyFolderStore *folder_store);
181 * This function checks whether a TnyFolderStore is a pop account
184 remote_folder_has_leave_on_server (TnyFolderStore *folder)
189 g_return_val_if_fail (TNY_IS_FOLDER_STORE (folder), FALSE);
191 account = get_account_from_folder_store (folder);
192 result = (modest_protocol_registry_protocol_type_has_leave_on_server (modest_runtime_get_protocol_registry (),
193 modest_tny_account_get_protocol_type (account)));
194 g_object_unref (account);
199 /* FIXME: this should be merged with the similar code in modest-account-view-window */
200 /* Show the account creation wizard dialog.
201 * returns: TRUE if an account was created. FALSE if the user cancelled.
204 modest_ui_actions_run_account_setup_wizard (ModestWindow *win)
206 gboolean result = FALSE;
208 gint dialog_response;
210 /* there is no such wizard yet */
211 wizard = GTK_WINDOW (modest_platform_get_account_settings_wizard ());
212 modest_window_mgr_set_modal (modest_runtime_get_window_mgr(), GTK_WINDOW (wizard), (GtkWindow *) win);
214 /* always present a main window in the background
215 * we do it here, so we cannot end up with two wizards (as this
216 * function might be called in modest_window_mgr_get_main_window as well */
218 win = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr(),
219 TRUE); /* create if not existent */
221 gtk_window_set_transient_for (GTK_WINDOW (wizard), GTK_WINDOW (win));
223 /* make sure the mainwindow is visible. We need to present the
224 wizard again to give it the focus back. show_all are needed
225 in order to get the widgets properly drawn (MainWindow main
226 paned won't be in its right position and the dialog will be
228 #ifndef MODEST_TOOLKIT_HILDON2
229 gtk_widget_show_all (GTK_WIDGET (win));
230 gtk_widget_show_all (GTK_WIDGET (wizard));
231 gtk_window_present (GTK_WINDOW (win));
232 gtk_window_present (GTK_WINDOW (wizard));
235 dialog_response = gtk_dialog_run (GTK_DIALOG (wizard));
236 gtk_widget_destroy (GTK_WIDGET (wizard));
237 if (gtk_events_pending ())
238 gtk_main_iteration ();
240 if (dialog_response == GTK_RESPONSE_CANCEL) {
243 /* Check whether an account was created: */
244 result = modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
251 modest_ui_actions_on_about (GtkAction *action, ModestWindow *win)
254 const gchar *authors[] = {
255 "Dirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>",
258 about = gtk_about_dialog_new ();
259 gtk_about_dialog_set_name (GTK_ABOUT_DIALOG(about), PACKAGE_NAME);
260 gtk_about_dialog_set_version (GTK_ABOUT_DIALOG(about),PACKAGE_VERSION);
261 gtk_about_dialog_set_copyright (GTK_ABOUT_DIALOG(about),
262 _("Copyright (c) 2006, Nokia Corporation\n"
263 "All rights reserved."));
264 gtk_about_dialog_set_comments (GTK_ABOUT_DIALOG(about),
265 _("a modest e-mail client\n\n"
266 "design and implementation: Dirk-Jan C. Binnema\n"
267 "contributions from the fine people at KC and Ig\n"
268 "uses the tinymail email framework written by Philip van Hoof"));
269 gtk_about_dialog_set_authors (GTK_ABOUT_DIALOG(about), authors);
270 gtk_about_dialog_set_website (GTK_ABOUT_DIALOG(about), "http://modest.garage.maemo.org");
271 gtk_window_set_transient_for (GTK_WINDOW (about), GTK_WINDOW (win));
272 gtk_window_set_modal (GTK_WINDOW (about), TRUE);
274 gtk_dialog_run (GTK_DIALOG (about));
275 gtk_widget_destroy(about);
279 * Gets the list of currently selected messages. If the win is the
280 * main window, then it returns a newly allocated list of the headers
281 * selected in the header view. If win is the msg view window, then
282 * the value returned is a list with just a single header.
284 * The caller of this funcion must free the list.
287 get_selected_headers (ModestWindow *win)
289 if (MODEST_IS_MAIN_WINDOW(win)) {
290 GtkWidget *header_view;
292 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
293 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
294 return modest_header_view_get_selected_headers (MODEST_HEADER_VIEW(header_view));
296 } else if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
297 /* for MsgViewWindows, we simply return a list with one element */
299 TnyList *list = NULL;
301 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
302 if (header != NULL) {
303 list = tny_simple_list_new ();
304 tny_list_prepend (list, G_OBJECT(header));
305 g_object_unref (G_OBJECT(header));
314 static GtkTreeRowReference *
315 get_next_after_selected_headers (ModestHeaderView *header_view)
317 GtkTreeSelection *sel;
318 GList *selected_rows, *node;
320 GtkTreeRowReference *result;
323 model = gtk_tree_view_get_model (GTK_TREE_VIEW (header_view));
324 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
325 selected_rows = gtk_tree_selection_get_selected_rows (sel, NULL);
327 if (selected_rows == NULL)
330 node = g_list_last (selected_rows);
331 path = gtk_tree_path_copy ((GtkTreePath *) node->data);
332 gtk_tree_path_next (path);
334 result = gtk_tree_row_reference_new (model, path);
336 gtk_tree_path_free (path);
337 g_list_foreach (selected_rows, (GFunc) gtk_tree_path_free, NULL);
338 g_list_free (selected_rows);
344 headers_action_mark_as_read (TnyHeader *header,
348 TnyHeaderFlags flags;
350 g_return_if_fail (TNY_IS_HEADER(header));
352 flags = tny_header_get_flags (header);
353 if (flags & TNY_HEADER_FLAG_SEEN) return;
354 tny_header_set_flag (header, TNY_HEADER_FLAG_SEEN);
358 headers_action_mark_as_unread (TnyHeader *header,
362 TnyHeaderFlags flags;
364 g_return_if_fail (TNY_IS_HEADER(header));
366 flags = tny_header_get_flags (header);
367 if (flags & TNY_HEADER_FLAG_SEEN) {
368 tny_header_unset_flag (header, TNY_HEADER_FLAG_SEEN);
372 /** After deleing a message that is currently visible in a window,
373 * show the next message from the list, or close the window if there are no more messages.
376 modest_ui_actions_refresh_message_window_after_delete (ModestMsgViewWindow* win)
378 /* Close msg view window or select next */
379 if (!modest_msg_view_window_select_next_message (win) &&
380 !modest_msg_view_window_select_previous_message (win)) {
382 g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value);
388 modest_ui_actions_on_delete_message (GtkAction *action, ModestWindow *win)
390 TnyList *header_list = NULL;
391 TnyIterator *iter = NULL;
392 TnyHeader *header = NULL;
393 gchar *message = NULL;
396 ModestWindowMgr *mgr;
397 GtkWidget *header_view = NULL;
399 g_return_if_fail (MODEST_IS_WINDOW(win));
401 /* Check first if the header view has the focus */
402 if (MODEST_IS_MAIN_WINDOW (win)) {
404 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
405 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
406 if (!gtk_widget_is_focus (header_view))
410 /* Get the headers, either from the header view (if win is the main window),
411 * or from the message view window: */
412 header_list = get_selected_headers (win);
413 if (!header_list) return;
415 /* Check if any of the headers are already opened, or in the process of being opened */
416 if (MODEST_IS_MAIN_WINDOW (win)) {
417 gint opened_headers = 0;
419 iter = tny_list_create_iterator (header_list);
420 mgr = modest_runtime_get_window_mgr ();
421 while (!tny_iterator_is_done (iter)) {
422 header = TNY_HEADER (tny_iterator_get_current (iter));
424 if (modest_window_mgr_find_registered_header (mgr, header, NULL))
426 g_object_unref (header);
428 tny_iterator_next (iter);
430 g_object_unref (iter);
432 if (opened_headers > 0) {
435 msg = g_strdup_printf (_("mcen_nc_unable_to_delete_n_messages"),
438 modest_platform_run_information_dialog (GTK_WINDOW (win), (const gchar *) msg, FALSE);
441 g_object_unref (header_list);
447 if (tny_list_get_length(header_list) == 1) {
448 iter = tny_list_create_iterator (header_list);
449 header = TNY_HEADER (tny_iterator_get_current (iter));
452 subject = tny_header_dup_subject (header);
454 subject = g_strdup (_("mail_va_no_subject"));
455 desc = g_strdup_printf ("%s", subject);
457 g_object_unref (header);
460 g_object_unref (iter);
462 message = g_strdup_printf(ngettext("emev_nc_delete_message", "emev_nc_delete_messages",
463 tny_list_get_length(header_list)), desc);
465 /* Confirmation dialog */
466 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
470 if (response == GTK_RESPONSE_OK) {
471 ModestWindow *main_window = NULL;
472 ModestWindowMgr *mgr = NULL;
473 GtkTreeModel *model = NULL;
474 GtkTreeSelection *sel = NULL;
475 GList *sel_list = NULL, *tmp = NULL;
476 GtkTreeRowReference *next_row_reference = NULL;
477 GtkTreeRowReference *prev_row_reference = NULL;
478 GtkTreePath *next_path = NULL;
479 GtkTreePath *prev_path = NULL;
480 ModestMailOperation *mail_op = NULL;
482 /* Find last selected row */
483 if (MODEST_IS_MAIN_WINDOW (win)) {
484 model = gtk_tree_view_get_model (GTK_TREE_VIEW (header_view));
485 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
486 sel_list = gtk_tree_selection_get_selected_rows (sel, &model);
487 for (tmp=sel_list; tmp; tmp=tmp->next) {
488 if (tmp->next == NULL) {
489 prev_path = gtk_tree_path_copy((GtkTreePath *) tmp->data);
490 next_path = gtk_tree_path_copy((GtkTreePath *) tmp->data);
492 gtk_tree_path_prev (prev_path);
493 gtk_tree_path_next (next_path);
495 prev_row_reference = gtk_tree_row_reference_new (model, prev_path);
496 next_row_reference = gtk_tree_row_reference_new (model, next_path);
501 /* Disable window dimming management */
502 modest_window_disable_dimming (MODEST_WINDOW(win));
504 /* Remove each header. If it's a view window header_view == NULL */
505 mail_op = modest_mail_operation_new ((GObject *) win);
506 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
508 modest_mail_operation_remove_msgs (mail_op, header_list, FALSE);
509 g_object_unref (mail_op);
511 /* Enable window dimming management */
513 gtk_tree_selection_unselect_all (sel);
515 modest_window_enable_dimming (MODEST_WINDOW(win));
517 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
518 modest_ui_actions_refresh_message_window_after_delete (MODEST_MSG_VIEW_WINDOW (win));
520 /* Get main window */
521 mgr = modest_runtime_get_window_mgr ();
522 main_window = modest_window_mgr_get_main_window (mgr, FALSE); /* don't create */
524 /* Move cursor to next row */
527 /* Select next or previous row */
528 if (gtk_tree_row_reference_valid (next_row_reference)) {
529 gtk_tree_selection_select_path (sel, next_path);
531 else if (gtk_tree_row_reference_valid (prev_row_reference)) {
532 gtk_tree_selection_select_path (sel, prev_path);
536 if (gtk_tree_row_reference_valid (next_row_reference))
537 gtk_tree_row_reference_free (next_row_reference);
538 if (next_path != NULL)
539 gtk_tree_path_free (next_path);
540 if (gtk_tree_row_reference_valid (prev_row_reference))
541 gtk_tree_row_reference_free (prev_row_reference);
542 if (prev_path != NULL)
543 gtk_tree_path_free (prev_path);
546 /* Update toolbar dimming state */
548 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (main_window));
549 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
553 g_list_foreach (sel_list, (GFunc) gtk_tree_path_free, NULL);
554 g_list_free (sel_list);
560 g_object_unref (header_list);
566 /* delete either message or folder, based on where we are */
568 modest_ui_actions_on_delete_message_or_folder (GtkAction *action, ModestWindow *win)
570 g_return_if_fail (MODEST_IS_WINDOW(win));
572 /* Check first if the header view has the focus */
573 if (MODEST_IS_MAIN_WINDOW (win)) {
575 w = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
576 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
577 if (gtk_widget_is_focus (w)) {
578 modest_ui_actions_on_delete_folder (action, MODEST_MAIN_WINDOW(win));
582 modest_ui_actions_on_delete_message (action, win);
586 modest_ui_actions_on_quit (GtkAction *action, ModestWindow *win)
588 ModestWindowMgr *mgr = NULL;
590 #ifdef MODEST_PLATFORM_MAEMO
591 modest_osso_save_state();
592 #endif /* MODEST_PLATFORM_MAEMO */
594 g_debug ("closing down, clearing %d item(s) from operation queue",
595 modest_mail_operation_queue_num_elements
596 (modest_runtime_get_mail_operation_queue()));
598 /* cancel all outstanding operations */
599 modest_mail_operation_queue_cancel_all
600 (modest_runtime_get_mail_operation_queue());
602 g_debug ("queue has been cleared");
605 /* Check if there are opened editing windows */
606 mgr = modest_runtime_get_window_mgr ();
607 modest_window_mgr_close_all_windows (mgr);
609 /* note: when modest-tny-account-store is finalized,
610 it will automatically set all network connections
613 /* gtk_main_quit (); */
617 modest_ui_actions_on_close_window (GtkAction *action, ModestWindow *win)
621 g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value);
623 /* if (MODEST_IS_MSG_VIEW_WINDOW (win)) { */
624 /* gtk_widget_destroy (GTK_WIDGET (win)); */
625 /* } else if (MODEST_IS_MSG_EDIT_WINDOW (win)) { */
626 /* gboolean ret_value; */
627 /* g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value); */
628 /* } else if (MODEST_IS_WINDOW (win)) { */
629 /* gtk_widget_destroy (GTK_WIDGET (win)); */
631 /* g_return_if_reached (); */
636 modest_ui_actions_on_add_to_contacts (GtkAction *action, ModestWindow *win)
638 GtkClipboard *clipboard = NULL;
639 gchar *selection = NULL;
641 clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
642 selection = gtk_clipboard_wait_for_text (clipboard);
644 /* Question: why is the clipboard being used here?
645 * It doesn't really make a lot of sense. */
649 modest_address_book_add_address (selection);
655 modest_ui_actions_on_accounts (GtkAction *action,
658 /* This is currently only implemented for Maemo */
659 if (!modest_account_mgr_has_accounts (modest_runtime_get_account_mgr(), TRUE)) {
660 if (!modest_ui_actions_run_account_setup_wizard (win))
661 g_debug ("%s: wizard was already running", __FUNCTION__);
665 /* Show the list of accounts */
666 GtkWindow *account_win = GTK_WINDOW (modest_account_view_window_new ());
668 /* The accounts dialog must be modal */
669 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (account_win), (GtkWindow *) win);
670 modest_utils_show_dialog_and_forget (GTK_WINDOW (win), GTK_DIALOG (account_win));
675 modest_ui_actions_on_smtp_servers (GtkAction *action, ModestWindow *win)
677 /* This is currently only implemented for Maemo,
678 * because it requires an API (libconic) to detect different connection
681 #ifndef MODEST_TOOLKIT_GTK /* Defined in config.h */
683 /* Create the window if necessary: */
684 GtkWidget *specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
685 modest_connection_specific_smtp_window_fill_with_connections (
686 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (specific_window),
687 modest_runtime_get_account_mgr());
689 /* Show the window: */
690 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (),
691 GTK_WINDOW (specific_window), (GtkWindow *) win);
692 gtk_widget_show (specific_window);
693 #endif /* !MODEST_TOOLKIT_GTK */
697 modest_ui_actions_compose_msg(ModestWindow *win,
700 const gchar *bcc_str,
701 const gchar *subject_str,
702 const gchar *body_str,
704 gboolean set_as_modified)
706 gchar *account_name = NULL;
708 TnyAccount *account = NULL;
709 TnyFolder *folder = NULL;
710 gchar *from_str = NULL, *signature = NULL, *body = NULL;
711 gboolean use_signature = FALSE;
712 ModestWindow *msg_win = NULL;
713 ModestAccountMgr *mgr = modest_runtime_get_account_mgr();
714 ModestTnyAccountStore *store = modest_runtime_get_account_store();
715 GnomeVFSFileSize total_size, allowed_size;
717 /* we check for low-mem */
718 if (modest_platform_check_memory_low (win, TRUE))
721 #ifdef MODEST_TOOLKIT_HILDON2
722 account_name = g_strdup (modest_window_get_active_account(win));
725 account_name = modest_account_mgr_get_default_account(mgr);
728 g_printerr ("modest: no account found\n");
731 account = modest_tny_account_store_get_server_account (store, account_name, TNY_ACCOUNT_TYPE_STORE);
733 g_printerr ("modest: failed to get tnyaccount for '%s'\n", account_name);
736 folder = modest_tny_account_get_special_folder (account, TNY_FOLDER_TYPE_DRAFTS);
738 g_printerr ("modest: failed to find Drafts folder\n");
741 from_str = modest_account_mgr_get_from_string (mgr, account_name);
743 g_printerr ("modest: failed get from string for '%s'\n", account_name);
747 signature = modest_account_mgr_get_signature (mgr, account_name, &use_signature);
748 if (body_str != NULL) {
749 body = use_signature ? g_strconcat(body_str, "\n--\n", signature, NULL) : g_strdup(body_str);
751 body = use_signature ? g_strconcat("\n--\n", signature, NULL) : g_strdup("");
754 msg = modest_tny_msg_new (to_str, from_str, cc_str, bcc_str, subject_str, body, NULL, NULL, NULL);
756 g_printerr ("modest: failed to create new msg\n");
760 /* Create and register edit window */
761 /* This is destroyed by TODO. */
763 allowed_size = MODEST_MAX_ATTACHMENT_SIZE;
764 msg_win = modest_msg_edit_window_new (msg, account_name, FALSE);
766 if (!modest_window_mgr_register_window (modest_runtime_get_window_mgr(), msg_win, NULL)) {
767 gtk_widget_destroy (GTK_WIDGET (msg_win));
770 modest_msg_edit_window_set_modified (MODEST_MSG_EDIT_WINDOW (msg_win), set_as_modified);
771 gtk_widget_show_all (GTK_WIDGET (msg_win));
773 while (attachments) {
775 modest_msg_edit_window_attach_file_one((ModestMsgEditWindow *)msg_win,
776 attachments->data, allowed_size);
778 if (total_size > allowed_size) {
779 g_warning ("%s: total size: %u",
780 __FUNCTION__, (unsigned int)total_size);
783 allowed_size -= total_size;
785 attachments = g_slist_next(attachments);
792 g_free (account_name);
794 g_object_unref (G_OBJECT(account));
796 g_object_unref (G_OBJECT(folder));
798 g_object_unref (G_OBJECT(msg));
802 modest_ui_actions_on_new_msg (GtkAction *action, ModestWindow *win)
804 /* if there are no accounts yet, just show the wizard */
805 if (!modest_account_mgr_has_accounts (modest_runtime_get_account_mgr(), TRUE))
806 if (!modest_ui_actions_run_account_setup_wizard (win))
809 modest_ui_actions_compose_msg(win, NULL, NULL, NULL, NULL, NULL, NULL, FALSE);
814 modest_ui_actions_msg_retrieval_check (ModestMailOperation *mail_op,
818 ModestMailOperationStatus status;
820 /* If there is no message or the operation was not successful */
821 status = modest_mail_operation_get_status (mail_op);
822 if (!msg || status != MODEST_MAIL_OPERATION_STATUS_SUCCESS) {
825 /* If it's a memory low issue, then show a banner */
826 error = modest_mail_operation_get_error (mail_op);
827 if (error && error->domain == MODEST_MAIL_OPERATION_ERROR &&
828 error->code == MODEST_MAIL_OPERATION_ERROR_LOW_MEMORY) {
829 GObject *source = modest_mail_operation_get_source (mail_op);
830 modest_platform_run_information_dialog (GTK_IS_WINDOW (source) ? GTK_WINDOW (source) : NULL,
831 dgettext("ke-recv","memr_ib_operation_disabled"),
833 g_object_unref (source);
836 if (error && ((error->code == TNY_SERVICE_ERROR_NO_SUCH_MESSAGE) ||
837 error->code == TNY_SERVICE_ERROR_MESSAGE_NOT_AVAILABLE)) {
838 gchar *subject, *msg;
839 subject = tny_header_dup_subject (header);
841 subject = g_strdup (_("mail_va_no_subject"));;
842 msg = g_strdup_printf (_("emev_ni_ui_imap_message_not_available_in_server"),
844 modest_platform_run_information_dialog (NULL, msg, FALSE);
849 /* Remove the header from the preregistered uids */
850 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (),
868 OpenMsgBannerInfo *banner_info;
869 GHashTable *row_refs_per_header;
873 open_msg_banner_idle (gpointer userdata)
875 OpenMsgBannerInfo *banner_info = (OpenMsgBannerInfo *) userdata;
877 gdk_threads_enter ();
878 banner_info->idle_handler = 0;
879 banner_info->banner = modest_platform_animation_banner (NULL, NULL, banner_info->message);
881 g_object_ref (banner_info->banner);
883 gdk_threads_leave ();
890 open_msg_cb (ModestMailOperation *mail_op,
897 ModestWindowMgr *mgr = NULL;
898 ModestWindow *parent_win = NULL;
899 ModestWindow *win = NULL;
900 TnyFolderType folder_type = TNY_FOLDER_TYPE_UNKNOWN;
901 gchar *account = NULL;
903 gboolean open_in_editor = FALSE;
904 OpenMsgHelper *helper = (OpenMsgHelper *) user_data;
906 /* Do nothing if there was any problem with the mail
907 operation. The error will be shown by the error_handler of
908 the mail operation */
909 if (!modest_ui_actions_msg_retrieval_check (mail_op, header, msg))
912 parent_win = (ModestWindow *) modest_mail_operation_get_source (mail_op);
913 folder = tny_header_get_folder (header);
915 /* Mark header as read */
916 headers_action_mark_as_read (header, MODEST_WINDOW(parent_win), NULL);
918 /* Gets folder type (OUTBOX headers will be opened in edit window */
919 if (modest_tny_folder_is_local_folder (folder)) {
920 folder_type = modest_tny_folder_get_local_or_mmc_folder_type (folder);
921 if (folder_type == TNY_FOLDER_TYPE_INVALID)
922 g_warning ("%s: BUG: TNY_FOLDER_TYPE_INVALID", __FUNCTION__);
926 if (folder_type == TNY_FOLDER_TYPE_OUTBOX) {
927 TnyTransportAccount *traccount = NULL;
928 ModestTnyAccountStore *accstore = modest_runtime_get_account_store();
929 traccount = modest_tny_account_store_get_transport_account_from_outbox_header(accstore, header);
931 ModestTnySendQueue *send_queue = NULL;
932 ModestTnySendQueueStatus status;
934 account = g_strdup(modest_tny_account_get_parent_modest_account_name_for_server_account(
935 TNY_ACCOUNT(traccount)));
936 send_queue = modest_runtime_get_send_queue(traccount, TRUE);
937 if (TNY_IS_SEND_QUEUE (send_queue)) {
938 msg_id = modest_tny_send_queue_get_msg_id (header);
939 status = modest_tny_send_queue_get_msg_status(send_queue, msg_id);
940 /* Only open messages in outbox with the editor if they are in Failed state */
941 if (status == MODEST_TNY_SEND_QUEUE_FAILED) {
942 open_in_editor = TRUE;
946 g_object_unref(traccount);
948 g_warning("Cannot get transport account for message in outbox!!");
950 } else if (folder_type == TNY_FOLDER_TYPE_DRAFTS) {
951 open_in_editor = TRUE; /* Open in editor if the message is in the Drafts folder */
956 account = g_strdup (modest_window_get_active_account (MODEST_WINDOW (parent_win)));
958 account = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
960 if (open_in_editor) {
961 ModestAccountMgr *mgr = modest_runtime_get_account_mgr ();
962 gchar *from_header = NULL, *acc_name;
964 from_header = tny_header_dup_from (header);
966 /* we cannot edit without a valid account... */
967 if (!modest_account_mgr_has_accounts(mgr, TRUE)) {
968 if (!modest_ui_actions_run_account_setup_wizard(parent_win)) {
969 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (),
971 g_free (from_header);
976 acc_name = modest_utils_get_account_name_from_recipient (from_header);
977 g_free (from_header);
983 win = modest_msg_edit_window_new (msg, account, TRUE);
985 gchar *uid = modest_tny_folder_get_header_unique_id (header);
987 if (MODEST_IS_MAIN_WINDOW (parent_win)) {
988 GtkTreeRowReference *row_reference;
990 row_reference = (GtkTreeRowReference *) g_hash_table_lookup (helper->row_refs_per_header, header);
992 win = modest_msg_view_window_new_with_header_model (msg, account, (const gchar*) uid,
993 helper->model, row_reference);
995 win = modest_msg_view_window_new_for_attachment (msg, account, (const gchar*) uid);
1000 /* Register and show new window */
1002 mgr = modest_runtime_get_window_mgr ();
1003 if (!modest_window_mgr_register_window (mgr, win, NULL)) {
1004 gtk_widget_destroy (GTK_WIDGET (win));
1007 gtk_widget_show_all (GTK_WIDGET(win));
1010 /* Update toolbar dimming state */
1011 if (MODEST_IS_MAIN_WINDOW (parent_win)) {
1012 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (parent_win));
1018 g_object_unref (parent_win);
1019 g_object_unref (folder);
1023 is_memory_full_error (GError *error)
1025 gboolean enough_free_space = TRUE;
1026 GnomeVFSURI *cache_dir_uri;
1027 const gchar *cache_dir;
1028 GnomeVFSFileSize free_space;
1030 cache_dir = tny_account_store_get_cache_dir (TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()));
1031 cache_dir_uri = gnome_vfs_uri_new (cache_dir);
1032 if (gnome_vfs_get_volume_free_space (cache_dir_uri, &free_space) == GNOME_VFS_OK) {
1033 if (free_space < MIN_FREE_SPACE)
1034 enough_free_space = FALSE;
1036 gnome_vfs_uri_unref (cache_dir_uri);
1038 if ((error->code == TNY_SYSTEM_ERROR_MEMORY ||
1039 /* When asking for a mail and no space left on device
1040 tinymail returns this error */
1041 error->code == TNY_SERVICE_ERROR_MESSAGE_NOT_AVAILABLE ||
1042 /* When the folder summary could not be read or
1044 error->code == TNY_IO_ERROR_WRITE ||
1045 error->code == TNY_IO_ERROR_READ) &&
1046 !enough_free_space) {
1054 check_memory_full_error (GtkWidget *parent_window, GError *err)
1059 if (is_memory_full_error (err))
1060 modest_platform_information_banner (parent_window,
1061 NULL, dgettext("ke-recv",
1062 "cerm_device_memory_full"));
1063 else if (err->code == TNY_SYSTEM_ERROR_MEMORY)
1064 /* If the account was created in memory full
1065 conditions then tinymail won't be able to
1066 connect so it'll return this error code */
1067 modest_platform_information_banner (parent_window,
1068 NULL, _("emev_ui_imap_inbox_select_error"));
1076 modest_ui_actions_disk_operations_error_handler (ModestMailOperation *mail_op,
1079 const GError *error;
1080 GObject *win = NULL;
1081 ModestMailOperationStatus status;
1083 win = modest_mail_operation_get_source (mail_op);
1084 error = modest_mail_operation_get_error (mail_op);
1085 status = modest_mail_operation_get_status (mail_op);
1087 /* If the mail op has been cancelled then it's not an error:
1088 don't show any message */
1089 if (status != MODEST_MAIL_OPERATION_STATUS_CANCELED) {
1090 if (is_memory_full_error ((GError *) error)) {
1091 modest_platform_information_banner ((GtkWidget *) win,
1092 NULL, dgettext("ke-recv",
1093 "cerm_device_memory_full"));
1094 } else if (error->code == TNY_SYSTEM_ERROR_MEMORY) {
1095 modest_platform_information_banner ((GtkWidget *) win,
1096 NULL, _("emev_ui_imap_inbox_select_error"));
1097 } else if (error->domain == MODEST_MAIL_OPERATION_ERROR &&
1098 error->code == MODEST_MAIL_OPERATION_ERROR_FILE_IO) {
1099 modest_platform_information_banner ((GtkWidget *) win,
1100 NULL, dgettext ("hildon-common-strings", "sfil_ni_unable_to_open_file_not_found"));
1101 } else if (user_data) {
1102 modest_platform_information_banner ((GtkWidget *) win,
1108 g_object_unref (win);
1112 * Returns the account a list of headers belongs to. It returns a
1113 * *new* reference so don't forget to unref it
1116 get_account_from_header_list (TnyList *headers)
1118 TnyAccount *account = NULL;
1120 if (tny_list_get_length (headers) > 0) {
1121 TnyIterator *iter = tny_list_create_iterator (headers);
1122 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter));
1123 TnyFolder *folder = tny_header_get_folder (header);
1126 g_object_unref (header);
1128 while (!tny_iterator_is_done (iter)) {
1129 header = TNY_HEADER (tny_iterator_get_current (iter));
1130 folder = tny_header_get_folder (header);
1133 g_object_unref (header);
1135 tny_iterator_next (iter);
1140 account = tny_folder_get_account (folder);
1141 g_object_unref (folder);
1145 g_object_unref (header);
1147 g_object_unref (iter);
1153 foreach_unregister_headers (gpointer data,
1156 ModestWindowMgr *mgr = (ModestWindowMgr *) user_data;
1157 TnyHeader *header = TNY_HEADER (data);
1159 modest_window_mgr_unregister_header (mgr, header);
1163 open_msgs_helper_destroyer (gpointer user_data)
1165 OpenMsgHelper *helper = (OpenMsgHelper *) user_data;
1167 if (helper->banner_info) {
1168 g_free (helper->banner_info->message);
1169 if (helper->banner_info->idle_handler > 0) {
1170 g_source_remove (helper->banner_info->idle_handler);
1171 helper->banner_info->idle_handler = 0;
1173 if (helper->banner_info->banner != NULL) {
1174 gtk_widget_destroy (helper->banner_info->banner);
1175 g_object_unref (helper->banner_info->banner);
1176 helper->banner_info->banner = NULL;
1178 g_slice_free (OpenMsgBannerInfo, helper->banner_info);
1179 helper->banner_info = NULL;
1181 g_object_unref (helper->model);
1182 g_object_unref (helper->headers);
1183 g_hash_table_destroy (helper->row_refs_per_header);
1184 g_slice_free (OpenMsgHelper, helper);
1188 open_msgs_performer(gboolean canceled,
1190 GtkWindow *parent_window,
1191 TnyAccount *account,
1194 ModestMailOperation *mail_op = NULL;
1196 ModestProtocolType proto;
1197 TnyList *not_opened_headers;
1198 TnyConnectionStatus status;
1199 gboolean show_open_draft = FALSE;
1200 OpenMsgHelper *helper = NULL;
1202 helper = (OpenMsgHelper *) user_data;
1203 not_opened_headers = helper->headers;
1205 status = tny_account_get_connection_status (account);
1206 if (err || canceled) {
1207 /* Unregister the already registered headers */
1208 tny_list_foreach (not_opened_headers, foreach_unregister_headers,
1209 modest_runtime_get_window_mgr ());
1210 /* Free the helper */
1211 open_msgs_helper_destroyer (helper);
1213 /* In memory full conditions we could get this error here */
1214 check_memory_full_error ((GtkWidget *) parent_window, err);
1219 /* Get the error message depending on the protocol */
1220 proto = modest_tny_account_get_protocol_type (account);
1221 if (proto == MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1222 proto = MODEST_PROTOCOLS_STORE_MAILDIR;
1225 /* Create the error messages */
1226 if (tny_list_get_length (not_opened_headers) == 1) {
1227 ModestProtocol *protocol;
1228 ModestProtocolRegistry *protocol_registry;
1233 protocol_registry = modest_runtime_get_protocol_registry ();
1234 iter = tny_list_create_iterator (not_opened_headers);
1235 header = TNY_HEADER (tny_iterator_get_current (iter));
1236 subject = tny_header_dup_subject (header);
1238 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, proto);
1239 error_msg = modest_protocol_get_translation (protocol, MODEST_PROTOCOL_TRANSLATION_MSG_NOT_AVAILABLE, subject);
1242 g_object_unref (header);
1243 g_object_unref (iter);
1245 if (error_msg == NULL) {
1246 error_msg = g_strdup (_("mail_ni_ui_folder_get_msg_folder_error"));
1249 if (modest_protocol_registry_protocol_type_has_tag (protocol_registry,
1251 MODEST_PROTOCOL_REGISTRY_LOCAL_STORE_PROTOCOLS)) {
1255 TnyFolderType folder_type;
1257 iter = tny_list_create_iterator (not_opened_headers);
1258 header = TNY_HEADER (tny_iterator_get_current (iter));
1259 folder = tny_header_get_folder (header);
1260 folder_type = modest_tny_folder_get_local_or_mmc_folder_type (folder);
1261 show_open_draft = (folder_type == TNY_FOLDER_TYPE_DRAFTS);
1262 g_object_unref (folder);
1263 g_object_unref (header);
1264 g_object_unref (iter);
1267 error_msg = g_strdup (_("mail_ni_ui_folder_get_msg_folder_error"));
1270 /* Create the mail operation */
1272 modest_mail_operation_new_with_error_handling ((GObject *) parent_window,
1273 modest_ui_actions_disk_operations_error_handler,
1275 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
1278 if (show_open_draft) {
1279 helper->banner_info = g_slice_new (OpenMsgBannerInfo);
1280 helper->banner_info->message = g_strdup (_("mail_ib_opening_draft_message"));
1281 helper->banner_info->banner = NULL;
1282 helper->banner_info->idle_handler = g_timeout_add (500, open_msg_banner_idle,
1283 helper->banner_info);
1286 modest_mail_operation_get_msgs_full (mail_op,
1290 open_msgs_helper_destroyer);
1295 g_object_unref (mail_op);
1296 g_object_unref (account);
1300 * This function is used by both modest_ui_actions_on_open and
1301 * modest_ui_actions_on_header_activated. This way we always do the
1302 * same when trying to open messages.
1305 open_msgs_from_headers (TnyList *headers, ModestWindow *win)
1307 ModestWindowMgr *mgr = NULL;
1308 TnyIterator *iter = NULL, *iter_not_opened = NULL;
1309 TnyList *not_opened_headers = NULL;
1310 TnyHeaderFlags flags = 0;
1311 TnyAccount *account;
1312 gint uncached_msgs = 0;
1313 GtkWidget *header_view;
1314 GtkTreeModel *model;
1315 GHashTable *refs_for_headers;
1316 OpenMsgHelper *helper;
1317 GtkTreeSelection *sel;
1318 GList *sel_list = NULL, *sel_list_iter = NULL;
1320 g_return_if_fail (headers != NULL);
1322 /* Check that only one message is selected for opening */
1323 if (tny_list_get_length (headers) != 1) {
1324 modest_platform_information_banner ((win) ? GTK_WIDGET (win) : NULL,
1325 NULL, _("mcen_ib_select_one_message"));
1329 mgr = modest_runtime_get_window_mgr ();
1330 iter = tny_list_create_iterator (headers);
1332 /* Get the account */
1333 account = get_account_from_header_list (headers);
1338 /* Get the selections, we need to get the references to the
1339 rows here because the treeview/model could dissapear (the
1340 user might want to select another folder)*/
1341 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
1342 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1343 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
1344 model = gtk_tree_view_get_model (GTK_TREE_VIEW (header_view));
1345 sel_list = gtk_tree_selection_get_selected_rows (sel, &model);
1346 refs_for_headers = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL,
1347 (GDestroyNotify) gtk_tree_row_reference_free);
1349 /* Look if we already have a message view for each header. If
1350 true, then remove the header from the list of headers to
1352 sel_list_iter = sel_list;
1353 not_opened_headers = tny_simple_list_new ();
1354 while (!tny_iterator_is_done (iter) && sel_list_iter) {
1356 ModestWindow *window = NULL;
1357 TnyHeader *header = NULL;
1358 gboolean found = FALSE;
1360 header = TNY_HEADER (tny_iterator_get_current (iter));
1362 flags = tny_header_get_flags (header);
1365 found = modest_window_mgr_find_registered_header (mgr, header, &window);
1367 /* Do not open again the message and present the
1368 window to the user */
1371 #ifndef MODEST_TOOLKIT_HILDON2
1372 gtk_window_present (GTK_WINDOW (window));
1375 /* the header has been registered already, we don't do
1376 * anything but wait for the window to come up*/
1377 g_debug ("header %p already registered, waiting for window", header);
1380 GtkTreeRowReference *row_reference;
1382 tny_list_append (not_opened_headers, G_OBJECT (header));
1383 /* Create a new row reference and add it to the hash table */
1384 row_reference = gtk_tree_row_reference_new (model, (GtkTreePath *) sel_list_iter->data);
1385 g_hash_table_insert (refs_for_headers, header, row_reference);
1389 g_object_unref (header);
1392 tny_iterator_next (iter);
1393 sel_list_iter = g_list_next (sel_list_iter);
1395 g_object_unref (iter);
1397 g_list_foreach (sel_list, (GFunc) gtk_tree_path_free, NULL);
1398 g_list_free (sel_list);
1400 /* Open each message */
1401 if (tny_list_get_length (not_opened_headers) == 0) {
1402 g_hash_table_destroy (refs_for_headers);
1406 /* If some messages would have to be downloaded, ask the user to
1407 * make a connection. It's generally easier to do this here (in the mainloop)
1408 * than later in a thread:
1410 if (tny_list_get_length (not_opened_headers) > 0) {
1411 uncached_msgs = header_list_count_uncached_msgs (not_opened_headers);
1413 if (uncached_msgs > 0) {
1414 /* Allways download if we are online. */
1415 if (!tny_device_is_online (modest_runtime_get_device ())) {
1418 /* If ask for user permission to download the messages */
1419 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
1420 ngettext("mcen_nc_get_msg",
1424 /* End if the user does not want to continue */
1425 if (response == GTK_RESPONSE_CANCEL) {
1426 g_hash_table_destroy (refs_for_headers);
1433 /* Register the headers before actually creating the windows: */
1434 iter_not_opened = tny_list_create_iterator (not_opened_headers);
1435 while (!tny_iterator_is_done (iter_not_opened)) {
1436 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter_not_opened));
1438 modest_window_mgr_register_header (mgr, header, NULL);
1439 g_object_unref (header);
1441 tny_iterator_next (iter_not_opened);
1443 g_object_unref (iter_not_opened);
1444 iter_not_opened = NULL;
1446 /* Create the helper. We need to get a reference to the model
1447 here because it could change while the message is readed
1448 (the user could switch between folders) */
1449 helper = g_slice_new (OpenMsgHelper);
1450 helper->model = g_object_ref (model);
1451 helper->headers = g_object_ref (not_opened_headers);
1452 helper->row_refs_per_header = refs_for_headers;
1453 helper->banner_info = NULL;
1455 /* Connect to the account and perform */
1456 if (uncached_msgs > 0) {
1457 modest_platform_connect_and_perform ((GtkWindow *) win, TRUE, g_object_ref (account),
1458 open_msgs_performer, helper);
1460 /* Call directly the performer, do not need to connect */
1461 open_msgs_performer (FALSE, NULL, (GtkWindow *) win,
1462 g_object_ref (account), helper);
1467 g_object_unref (account);
1468 if (not_opened_headers)
1469 g_object_unref (not_opened_headers);
1473 modest_ui_actions_on_open (GtkAction *action, ModestWindow *win)
1477 /* we check for low-mem; in that case, show a warning, and don't allow
1480 if (modest_platform_check_memory_low (MODEST_WINDOW(win), TRUE))
1484 headers = get_selected_headers (win);
1489 open_msgs_from_headers (headers, win);
1491 g_object_unref(headers);
1494 static ReplyForwardHelper*
1495 create_reply_forward_helper (ReplyForwardAction action,
1497 guint reply_forward_type,
1500 ReplyForwardHelper *rf_helper = NULL;
1501 const gchar *active_acc = modest_window_get_active_account (win);
1503 rf_helper = g_slice_new0 (ReplyForwardHelper);
1504 rf_helper->reply_forward_type = reply_forward_type;
1505 rf_helper->action = action;
1506 rf_helper->parent_window = (MODEST_IS_WINDOW (win)) ? GTK_WIDGET (win) : NULL;
1507 rf_helper->header = (header) ? g_object_ref (header) : NULL;
1508 rf_helper->account_name = (active_acc) ?
1509 g_strdup (active_acc) :
1510 modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
1516 free_reply_forward_helper (gpointer data)
1518 ReplyForwardHelper *helper;
1520 helper = (ReplyForwardHelper *) data;
1521 g_free (helper->account_name);
1523 g_object_unref (helper->header);
1524 g_slice_free (ReplyForwardHelper, helper);
1528 reply_forward_cb (ModestMailOperation *mail_op,
1535 TnyMsg *new_msg = NULL;
1536 ReplyForwardHelper *rf_helper;
1537 ModestWindow *msg_win = NULL;
1538 ModestEditType edit_type;
1540 TnyAccount *account = NULL;
1541 ModestWindowMgr *mgr = NULL;
1542 gchar *signature = NULL;
1543 gboolean use_signature;
1545 /* If there was any error. The mail operation could be NULL,
1546 this means that we already have the message downloaded and
1547 that we didn't do a mail operation to retrieve it */
1548 rf_helper = (ReplyForwardHelper *) user_data;
1549 if (mail_op && !modest_ui_actions_msg_retrieval_check (mail_op, header, msg))
1552 from = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(),
1553 rf_helper->account_name);
1554 signature = modest_account_mgr_get_signature (modest_runtime_get_account_mgr(),
1555 rf_helper->account_name,
1558 /* Create reply mail */
1559 switch (rf_helper->action) {
1562 modest_tny_msg_create_reply_msg (msg, header, from,
1563 (use_signature) ? signature : NULL,
1564 rf_helper->reply_forward_type,
1565 MODEST_TNY_MSG_REPLY_MODE_SENDER);
1567 case ACTION_REPLY_TO_ALL:
1569 modest_tny_msg_create_reply_msg (msg, header, from,
1570 (use_signature) ? signature : NULL,
1571 rf_helper->reply_forward_type,
1572 MODEST_TNY_MSG_REPLY_MODE_ALL);
1573 edit_type = MODEST_EDIT_TYPE_REPLY;
1575 case ACTION_FORWARD:
1577 modest_tny_msg_create_forward_msg (msg, from, (use_signature) ? signature : NULL,
1578 rf_helper->reply_forward_type);
1579 edit_type = MODEST_EDIT_TYPE_FORWARD;
1582 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (),
1584 g_return_if_reached ();
1592 g_warning ("%s: failed to create message\n", __FUNCTION__);
1596 account = modest_tny_account_store_get_server_account (modest_runtime_get_account_store(),
1597 rf_helper->account_name,
1598 TNY_ACCOUNT_TYPE_STORE);
1600 g_warning ("%s: failed to get tnyaccount for '%s'\n", __FUNCTION__, rf_helper->account_name);
1604 /* Create and register the windows */
1605 msg_win = modest_msg_edit_window_new (new_msg, rf_helper->account_name, FALSE);
1606 mgr = modest_runtime_get_window_mgr ();
1607 modest_window_mgr_register_window (mgr, msg_win, (ModestWindow *) rf_helper->parent_window);
1609 if (rf_helper->parent_window != NULL) {
1610 gdouble parent_zoom;
1612 parent_zoom = modest_window_get_zoom (MODEST_WINDOW (rf_helper->parent_window));
1613 modest_window_set_zoom (msg_win, parent_zoom);
1616 /* Show edit window */
1617 gtk_widget_show_all (GTK_WIDGET (msg_win));
1620 /* We always unregister the header because the message is
1621 forwarded or replied so the original one is no longer
1623 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (),
1626 g_object_unref (G_OBJECT (new_msg));
1628 g_object_unref (G_OBJECT (account));
1629 free_reply_forward_helper (rf_helper);
1632 /* Checks a list of headers. If any of them are not currently
1633 * downloaded (CACHED) then returns TRUE else returns FALSE.
1636 header_list_count_uncached_msgs (TnyList *header_list)
1639 gint uncached_messages = 0;
1641 iter = tny_list_create_iterator (header_list);
1642 while (!tny_iterator_is_done (iter)) {
1645 header = TNY_HEADER (tny_iterator_get_current (iter));
1647 if (!(tny_header_get_flags (header) & TNY_HEADER_FLAG_CACHED))
1648 uncached_messages ++;
1649 g_object_unref (header);
1652 tny_iterator_next (iter);
1654 g_object_unref (iter);
1656 return uncached_messages;
1659 /* Returns FALSE if the user does not want to download the
1660 * messages. Returns TRUE if the user allowed the download.
1663 connect_to_get_msg (ModestWindow *win,
1664 gint num_of_uncached_msgs,
1665 TnyAccount *account)
1667 GtkResponseType response;
1669 /* Allways download if we are online. */
1670 if (tny_device_is_online (modest_runtime_get_device ()))
1673 /* If offline, then ask for user permission to download the messages */
1674 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
1675 ngettext("mcen_nc_get_msg",
1677 num_of_uncached_msgs));
1679 if (response == GTK_RESPONSE_CANCEL)
1682 return modest_platform_connect_and_wait((GtkWindow *) win, account);
1686 reply_forward_performer (gboolean canceled,
1688 GtkWindow *parent_window,
1689 TnyAccount *account,
1692 ReplyForwardHelper *rf_helper = NULL;
1693 ModestMailOperation *mail_op;
1695 rf_helper = (ReplyForwardHelper *) user_data;
1697 if (canceled || err) {
1698 free_reply_forward_helper (rf_helper);
1702 /* Retrieve the message */
1703 modest_window_mgr_register_header (modest_runtime_get_window_mgr (), rf_helper->header, NULL);
1704 mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT (parent_window),
1705 modest_ui_actions_disk_operations_error_handler,
1707 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
1708 modest_mail_operation_get_msg (mail_op, rf_helper->header, TRUE, reply_forward_cb, rf_helper);
1711 g_object_unref(mail_op);
1715 * Common code for the reply and forward actions
1718 reply_forward (ReplyForwardAction action, ModestWindow *win)
1720 ReplyForwardHelper *rf_helper = NULL;
1721 guint reply_forward_type;
1723 g_return_if_fail (MODEST_IS_WINDOW(win));
1725 /* we check for low-mem; in that case, show a warning, and don't allow
1726 * reply/forward (because it could potentially require a lot of memory */
1727 if (modest_platform_check_memory_low (MODEST_WINDOW(win), TRUE))
1731 /* we need an account when editing */
1732 if (!modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE)) {
1733 if (!modest_ui_actions_run_account_setup_wizard (win))
1737 reply_forward_type =
1738 modest_conf_get_int (modest_runtime_get_conf (),
1739 (action == ACTION_FORWARD) ?
1740 MODEST_CONF_FORWARD_TYPE :
1741 MODEST_CONF_REPLY_TYPE,
1744 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
1746 TnyHeader *header = NULL;
1747 /* Get header and message. Do not free them here, the
1748 reply_forward_cb must do it */
1749 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW(win));
1750 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
1752 if (msg && header) {
1754 rf_helper = create_reply_forward_helper (action, win,
1755 reply_forward_type, header);
1756 reply_forward_cb (NULL, header, FALSE, msg, NULL, rf_helper);
1758 g_warning("%s: no message or header found in viewer\n", __FUNCTION__);
1762 g_object_unref (msg);
1764 g_object_unref (header);
1766 TnyHeader *header = NULL;
1768 gboolean do_retrieve = TRUE;
1769 TnyList *header_list = NULL;
1771 header_list = get_selected_headers (win);
1774 /* Check that only one message is selected for replying */
1775 if (tny_list_get_length (header_list) != 1) {
1776 modest_platform_information_banner ((win) ? GTK_WIDGET (win) : NULL,
1777 NULL, _("mcen_ib_select_one_message"));
1778 g_object_unref (header_list);
1782 /* Only reply/forward to one message */
1783 iter = tny_list_create_iterator (header_list);
1784 header = TNY_HEADER (tny_iterator_get_current (iter));
1785 g_object_unref (iter);
1787 /* Retrieve messages */
1788 do_retrieve = (action == ACTION_FORWARD) ||
1789 (reply_forward_type != MODEST_TNY_MSG_REPLY_TYPE_CITE);
1792 TnyAccount *account = NULL;
1793 TnyFolder *folder = NULL;
1794 gdouble download = TRUE;
1795 guint uncached_msgs = 0;
1797 folder = tny_header_get_folder (header);
1799 goto do_retrieve_frees;
1800 account = tny_folder_get_account (folder);
1802 goto do_retrieve_frees;
1804 uncached_msgs = header_list_count_uncached_msgs (header_list);
1806 if (uncached_msgs > 0) {
1807 /* Allways download if we are online. */
1808 if (!tny_device_is_online (modest_runtime_get_device ())) {
1811 /* If ask for user permission to download the messages */
1812 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
1813 ngettext("mcen_nc_get_msg",
1817 /* End if the user does not want to continue */
1818 if (response == GTK_RESPONSE_CANCEL)
1825 rf_helper = create_reply_forward_helper (action, win,
1826 reply_forward_type, header);
1827 if (uncached_msgs > 0) {
1828 modest_platform_connect_and_perform (GTK_WINDOW (win),
1830 reply_forward_performer,
1833 reply_forward_performer (FALSE, NULL, GTK_WINDOW (win),
1834 account, rf_helper);
1839 g_object_unref (account);
1841 g_object_unref (folder);
1843 reply_forward_cb (NULL, header, FALSE, NULL, NULL, rf_helper);
1846 g_object_unref (header_list);
1847 g_object_unref (header);
1852 modest_ui_actions_on_reply (GtkAction *action, ModestWindow *win)
1854 g_return_if_fail (MODEST_IS_WINDOW(win));
1856 reply_forward (ACTION_REPLY, win);
1860 modest_ui_actions_on_forward (GtkAction *action, ModestWindow *win)
1862 g_return_if_fail (MODEST_IS_WINDOW(win));
1864 reply_forward (ACTION_FORWARD, win);
1868 modest_ui_actions_on_reply_all (GtkAction *action, ModestWindow *win)
1870 g_return_if_fail (MODEST_IS_WINDOW(win));
1872 reply_forward (ACTION_REPLY_TO_ALL, win);
1876 modest_ui_actions_on_next (GtkAction *action,
1877 ModestWindow *window)
1879 if (MODEST_IS_MAIN_WINDOW (window)) {
1880 GtkWidget *header_view;
1882 header_view = modest_main_window_get_child_widget (
1883 MODEST_MAIN_WINDOW(window),
1884 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1888 modest_header_view_select_next (
1889 MODEST_HEADER_VIEW(header_view));
1890 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
1891 modest_msg_view_window_select_next_message (
1892 MODEST_MSG_VIEW_WINDOW (window));
1894 g_return_if_reached ();
1899 modest_ui_actions_on_prev (GtkAction *action,
1900 ModestWindow *window)
1902 g_return_if_fail (MODEST_IS_WINDOW(window));
1904 if (MODEST_IS_MAIN_WINDOW (window)) {
1905 GtkWidget *header_view;
1906 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
1907 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1911 modest_header_view_select_prev (MODEST_HEADER_VIEW(header_view));
1912 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
1913 modest_msg_view_window_select_previous_message (MODEST_MSG_VIEW_WINDOW (window));
1915 g_return_if_reached ();
1920 modest_ui_actions_on_sort (GtkAction *action,
1921 ModestWindow *window)
1923 g_return_if_fail (MODEST_IS_WINDOW(window));
1925 if (MODEST_IS_MAIN_WINDOW (window)) {
1926 GtkWidget *header_view;
1927 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
1928 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1930 modest_platform_information_banner (NULL, NULL, _CS("ckdg_ib_nothing_to_sort"));
1935 /* Show sorting dialog */
1936 modest_utils_run_sort_dialog (GTK_WINDOW (window), MODEST_SORT_HEADERS);
1941 new_messages_arrived (ModestMailOperation *self,
1942 TnyList *new_headers,
1946 gboolean show_visual_notifications;
1948 source = modest_mail_operation_get_source (self);
1949 show_visual_notifications = (source) ? FALSE : TRUE;
1951 g_object_unref (source);
1953 /* Notify new messages have been downloaded. If the
1954 send&receive was invoked by the user then do not show any
1955 visual notification, only play a sound and activate the LED
1956 (for the Maemo version) */
1957 if (TNY_IS_LIST(new_headers) && (tny_list_get_length (new_headers)) > 0)
1958 modest_platform_on_new_headers_received (new_headers,
1959 show_visual_notifications);
1964 retrieve_all_messages_cb (GObject *source,
1966 guint retrieve_limit)
1972 window = GTK_WINDOW (source);
1973 msg = g_strdup_printf (_("mail_nc_msg_count_limit_exceeded"),
1974 num_msgs, retrieve_limit);
1976 /* Ask the user if they want to retrieve all the messages */
1978 modest_platform_run_confirmation_dialog_with_buttons (window, msg,
1979 _("mcen_bd_get_all"),
1980 _("mcen_bd_newest_only"));
1981 /* Free and return */
1983 return (response == GTK_RESPONSE_ACCEPT) ? TRUE : FALSE;
1987 TnyAccount *account;
1989 gchar *account_name;
1990 gboolean poke_status;
1991 gboolean interactive;
1992 ModestMailOperation *mail_op;
1996 do_send_receive_performer (gboolean canceled,
1998 GtkWindow *parent_window,
1999 TnyAccount *account,
2002 SendReceiveInfo *info;
2004 info = (SendReceiveInfo *) user_data;
2006 if (err || canceled) {
2007 /* In memory full conditions we could get this error here */
2008 check_memory_full_error ((GtkWidget *) parent_window, err);
2010 if (info->mail_op) {
2011 modest_mail_operation_queue_remove (modest_runtime_get_mail_operation_queue (),
2017 /* Set send/receive operation in progress */
2018 if (info->win && MODEST_IS_MAIN_WINDOW (info->win)) {
2019 modest_main_window_notify_send_receive_initied (MODEST_MAIN_WINDOW (info->win));
2022 if (info->win && MODEST_IS_MAIN_WINDOW (info->win))
2023 g_signal_connect (G_OBJECT (info->mail_op), "operation-finished",
2024 G_CALLBACK (on_send_receive_finished),
2027 /* Send & receive. */
2028 modest_mail_operation_update_account (info->mail_op, info->account_name, info->poke_status, info->interactive,
2029 (info->win) ? retrieve_all_messages_cb : NULL,
2030 new_messages_arrived, info->win);
2035 g_object_unref (G_OBJECT (info->mail_op));
2036 if (info->account_name)
2037 g_free (info->account_name);
2039 g_object_unref (info->win);
2041 g_object_unref (info->account);
2042 g_slice_free (SendReceiveInfo, info);
2046 * This function performs the send & receive required actions. The
2047 * window is used to create the mail operation. Typically it should
2048 * always be the main window, but we pass it as argument in order to
2052 modest_ui_actions_do_send_receive (const gchar *account_name,
2053 gboolean force_connection,
2054 gboolean poke_status,
2055 gboolean interactive,
2058 gchar *acc_name = NULL;
2059 SendReceiveInfo *info;
2060 ModestTnyAccountStore *acc_store;
2062 /* If no account name was provided then get the current account, and if
2063 there is no current account then pick the default one: */
2064 if (!account_name) {
2066 acc_name = g_strdup (modest_window_get_active_account (win));
2068 acc_name = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
2070 g_printerr ("modest: cannot get default account\n");
2074 acc_name = g_strdup (account_name);
2077 acc_store = modest_runtime_get_account_store ();
2079 /* Create the info for the connect and perform */
2080 info = g_slice_new (SendReceiveInfo);
2081 info->account_name = acc_name;
2082 info->win = (win) ? g_object_ref (win) : NULL;
2083 info->poke_status = poke_status;
2084 info->interactive = interactive;
2085 info->account = modest_tny_account_store_get_server_account (acc_store, acc_name,
2086 TNY_ACCOUNT_TYPE_STORE);
2087 /* We need to create the operation here, because otherwise it
2088 could happen that the queue emits the queue-empty signal
2089 while we're trying to connect the account */
2090 info->mail_op = modest_mail_operation_new_with_error_handling ((info->win) ? G_OBJECT (info->win) : NULL,
2091 modest_ui_actions_disk_operations_error_handler,
2093 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), info->mail_op);
2095 /* Invoke the connect and perform */
2096 modest_platform_connect_and_perform ((win) ? GTK_WINDOW (win) : NULL,
2097 force_connection, info->account,
2098 do_send_receive_performer, info);
2103 modest_ui_actions_do_cancel_send (const gchar *account_name,
2106 TnyTransportAccount *transport_account;
2107 TnySendQueue *send_queue = NULL;
2108 GError *error = NULL;
2110 /* Get transport account */
2112 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
2113 (modest_runtime_get_account_store(),
2115 TNY_ACCOUNT_TYPE_TRANSPORT));
2116 if (!transport_account) {
2117 g_printerr ("modest: no transport account found for '%s'\n", account_name);
2122 send_queue = TNY_SEND_QUEUE (modest_runtime_get_send_queue (transport_account, TRUE));
2123 if (!TNY_IS_SEND_QUEUE(send_queue)) {
2124 g_set_error (&error, MODEST_MAIL_OPERATION_ERROR,
2125 MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND,
2126 "modest: could not find send queue for account\n");
2128 /* Cancel the current send */
2129 tny_account_cancel (TNY_ACCOUNT (transport_account));
2131 /* Suspend all pending messages */
2132 tny_send_queue_cancel (send_queue, TNY_SEND_QUEUE_CANCEL_ACTION_SUSPEND, &error);
2136 if (transport_account != NULL)
2137 g_object_unref (G_OBJECT (transport_account));
2141 modest_ui_actions_cancel_send_all (ModestWindow *win)
2143 GSList *account_names, *iter;
2145 account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
2148 iter = account_names;
2150 modest_ui_actions_do_cancel_send ((const char*) iter->data, win);
2151 iter = g_slist_next (iter);
2154 modest_account_mgr_free_account_names (account_names);
2155 account_names = NULL;
2159 modest_ui_actions_cancel_send (GtkAction *action, ModestWindow *win)
2162 /* Check if accounts exist */
2163 gboolean accounts_exist =
2164 modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
2166 /* If not, allow the user to create an account before trying to send/receive. */
2167 if (!accounts_exist)
2168 modest_ui_actions_on_accounts (NULL, win);
2170 /* Cancel all sending operaitons */
2171 modest_ui_actions_cancel_send_all (win);
2175 * Refreshes all accounts. This function will be used by automatic
2179 modest_ui_actions_do_send_receive_all (ModestWindow *win,
2180 gboolean force_connection,
2181 gboolean poke_status,
2182 gboolean interactive)
2184 GSList *account_names, *iter;
2186 account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
2189 iter = account_names;
2191 modest_ui_actions_do_send_receive ((const char*) iter->data,
2193 poke_status, interactive, win);
2194 iter = g_slist_next (iter);
2197 modest_account_mgr_free_account_names (account_names);
2198 account_names = NULL;
2202 * Handler of the click on Send&Receive button in the main toolbar
2205 modest_ui_actions_on_send_receive (GtkAction *action, ModestWindow *win)
2207 /* Check if accounts exist */
2208 gboolean accounts_exist;
2211 modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
2213 /* If not, allow the user to create an account before trying to send/receive. */
2214 if (!accounts_exist)
2215 modest_ui_actions_on_accounts (NULL, win);
2217 /* Refresh the current folder. The if is always TRUE it's just an extra check */
2218 if (MODEST_IS_MAIN_WINDOW (win)) {
2219 GtkWidget *folder_view;
2220 TnyFolderStore *folder_store;
2223 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
2224 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2228 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
2231 g_object_unref (folder_store);
2234 /* Refresh the active account. Force the connection if needed
2235 and poke the status of all folders */
2236 modest_ui_actions_do_send_receive (NULL, TRUE, TRUE, TRUE, win);
2241 modest_ui_actions_toggle_header_list_view (GtkAction *action, ModestMainWindow *main_window)
2244 GtkWidget *header_view;
2246 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2248 header_view = modest_main_window_get_child_widget (main_window,
2249 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2253 conf = modest_runtime_get_conf ();
2255 /* what is saved/restored is depending on the style; thus; we save with
2256 * old style, then update the style, and restore for this new style
2258 modest_widget_memory_save (conf, G_OBJECT(header_view), MODEST_CONF_HEADER_VIEW_KEY);
2260 if (modest_header_view_get_style
2261 (MODEST_HEADER_VIEW(header_view)) == MODEST_HEADER_VIEW_STYLE_DETAILS)
2262 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
2263 MODEST_HEADER_VIEW_STYLE_TWOLINES);
2265 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
2266 MODEST_HEADER_VIEW_STYLE_DETAILS);
2268 modest_widget_memory_restore (conf, G_OBJECT(header_view),
2269 MODEST_CONF_HEADER_VIEW_KEY);
2274 modest_ui_actions_on_header_selected (ModestHeaderView *header_view,
2276 ModestMainWindow *main_window)
2278 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2279 g_return_if_fail (MODEST_IS_HEADER_VIEW (header_view));
2281 /* in the case the folder is empty, show the empty folder message and focus
2283 if (!header && gtk_widget_is_focus (GTK_WIDGET (header_view))) {
2284 if (modest_header_view_is_empty (header_view)) {
2285 TnyFolder *folder = modest_header_view_get_folder (header_view);
2286 GtkWidget *folder_view =
2287 modest_main_window_get_child_widget (main_window,
2288 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2289 if (folder != NULL) {
2290 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view), folder, FALSE);
2291 g_object_unref (folder);
2293 gtk_widget_grab_focus (GTK_WIDGET (folder_view));
2297 /* If no header has been selected then exit */
2302 if (!gtk_widget_is_focus (GTK_WIDGET(header_view)))
2303 gtk_widget_grab_focus (GTK_WIDGET(header_view));
2305 /* Update toolbar dimming state */
2306 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (main_window));
2307 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
2311 modest_ui_actions_on_header_activated (ModestHeaderView *header_view,
2313 ModestMainWindow *main_window)
2316 GtkWidget *open_widget;
2318 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2323 if (modest_header_view_count_selected_headers (header_view) > 1) {
2324 modest_platform_information_banner (NULL, NULL, _("mcen_ib_select_one_message"));
2328 /* we check for low-mem; in that case, show a warning, and don't allow
2329 * activating headers
2331 if (modest_platform_check_memory_low (MODEST_WINDOW(main_window), TRUE))
2334 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (main_window));
2335 open_widget = modest_window_get_action_widget (MODEST_WINDOW (main_window), "/MenuBar/EmailMenu/EmailOpenMenu");
2336 if (!GTK_WIDGET_IS_SENSITIVE (open_widget))
2339 headers = modest_header_view_get_selected_headers (header_view);
2341 open_msgs_from_headers (headers, MODEST_WINDOW (main_window));
2343 g_object_unref (headers);
2347 set_active_account_from_tny_account (TnyAccount *account,
2348 ModestWindow *window)
2350 const gchar *server_acc_name = tny_account_get_id (account);
2352 /* We need the TnyAccount provided by the
2353 account store because that is the one that
2354 knows the name of the Modest account */
2355 TnyAccount *modest_server_account = modest_server_account =
2356 modest_tny_account_store_get_tny_account_by (modest_runtime_get_account_store (),
2357 MODEST_TNY_ACCOUNT_STORE_QUERY_ID,
2359 if (!modest_server_account) {
2360 g_warning ("%s: could not get tny account\n", __FUNCTION__);
2364 /* Update active account, but only if it's not a pseudo-account */
2365 if ((!modest_tny_account_is_virtual_local_folders(modest_server_account)) &&
2366 (!modest_tny_account_is_memory_card_account(modest_server_account))) {
2367 const gchar *modest_acc_name =
2368 modest_tny_account_get_parent_modest_account_name_for_server_account (modest_server_account);
2369 if (modest_acc_name)
2370 modest_window_set_active_account (window, modest_acc_name);
2373 g_object_unref (modest_server_account);
2378 folder_refreshed_cb (ModestMailOperation *mail_op,
2382 ModestMainWindow *win = NULL;
2383 GtkWidget *folder_view;
2384 const GError *error;
2386 g_return_if_fail (TNY_IS_FOLDER (folder));
2388 win = MODEST_MAIN_WINDOW (user_data);
2390 /* Check if the operation failed due to memory low conditions */
2391 error = modest_mail_operation_get_error (mail_op);
2392 if (error && error->domain == MODEST_MAIL_OPERATION_ERROR &&
2393 error->code == MODEST_MAIL_OPERATION_ERROR_LOW_MEMORY) {
2394 modest_platform_run_information_dialog (GTK_WINDOW (win),
2395 dgettext("ke-recv","memr_ib_operation_disabled"),
2401 modest_main_window_get_child_widget(win, MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2404 TnyFolderStore *current_folder;
2406 current_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
2407 if (current_folder) {
2408 gboolean different = ((TnyFolderStore *) folder != current_folder);
2409 g_object_unref (current_folder);
2415 /* Check if folder is empty and set headers view contents style */
2416 if (tny_folder_get_all_count (folder) == 0)
2417 modest_main_window_set_contents_style (win,
2418 MODEST_MAIN_WINDOW_CONTENTS_STYLE_EMPTY);
2423 modest_ui_actions_on_folder_selection_changed (ModestFolderView *folder_view,
2424 TnyFolderStore *folder_store,
2426 ModestMainWindow *main_window)
2429 GtkWidget *header_view;
2431 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2433 header_view = modest_main_window_get_child_widget(main_window,
2434 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2438 conf = modest_runtime_get_conf ();
2440 if (TNY_IS_ACCOUNT (folder_store)) {
2442 set_active_account_from_tny_account (TNY_ACCOUNT (folder_store), MODEST_WINDOW (main_window));
2444 /* Show account details */
2445 modest_main_window_set_contents_style (main_window, MODEST_MAIN_WINDOW_CONTENTS_STYLE_DETAILS);
2448 if (TNY_IS_FOLDER (folder_store) && selected) {
2449 TnyAccount *account;
2450 const gchar *account_name = NULL;
2452 /* Update the active account */
2453 account = modest_tny_folder_get_account (TNY_FOLDER (folder_store));
2455 set_active_account_from_tny_account (account, MODEST_WINDOW (main_window));
2457 modest_tny_account_get_parent_modest_account_name_for_server_account (account);
2458 g_object_unref (account);
2462 /* Set the header style by default, it could
2463 be changed later by the refresh callback to
2465 modest_main_window_set_contents_style (main_window,
2466 MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS);
2468 /* Set folder on header view. This function
2469 will call tny_folder_refresh_async so we
2470 pass a callback that will be called when
2471 finished. We use that callback to set the
2472 empty view if there are no messages */
2473 modest_header_view_set_folder (MODEST_HEADER_VIEW(header_view),
2474 TNY_FOLDER (folder_store),
2476 folder_refreshed_cb,
2479 /* Restore configuration. We need to do this
2480 *after* the set_folder because the widget
2481 memory asks the header view about its
2483 modest_widget_memory_restore (modest_runtime_get_conf (),
2484 G_OBJECT(header_view),
2485 MODEST_CONF_HEADER_VIEW_KEY);
2487 /* No need to save the header view
2488 configuration for Maemo because it only
2489 saves the sorting stuff and that it's
2490 already being done by the sort
2491 dialog. Remove it when the GNOME version
2492 has the same behaviour */
2493 #ifdef MODEST_TOOLKIT_GTK
2494 if (modest_main_window_get_contents_style (main_window) ==
2495 MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS)
2496 modest_widget_memory_save (conf, G_OBJECT (header_view),
2497 MODEST_CONF_HEADER_VIEW_KEY);
2499 modest_header_view_clear (MODEST_HEADER_VIEW(header_view));
2503 /* Update dimming state */
2504 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (main_window));
2505 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
2509 modest_ui_actions_on_item_not_found (ModestHeaderView *header_view,ModestItemType type,
2516 item = (type == MODEST_ITEM_TYPE_FOLDER) ? "folder" : "message";
2518 online = tny_device_is_online (modest_runtime_get_device());
2521 /* already online -- the item is simply not there... */
2522 dialog = gtk_message_dialog_new (GTK_WINDOW (win),
2524 GTK_MESSAGE_WARNING,
2526 _("The %s you selected cannot be found"),
2528 gtk_dialog_add_button (GTK_DIALOG (dialog),_("mcen_bd_dialog_ok"), GTK_RESPONSE_ACCEPT);
2529 gtk_dialog_run (GTK_DIALOG(dialog));
2531 dialog = gtk_dialog_new_with_buttons (_("Connection requested"),
2534 _("mcen_bd_dialog_cancel"),
2535 GTK_RESPONSE_REJECT,
2536 _("mcen_bd_dialog_ok"),
2537 GTK_RESPONSE_ACCEPT,
2539 txt = g_strdup_printf (_("This %s is not available in offline mode.\n"
2540 "Do you want to get online?"), item);
2541 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
2542 gtk_label_new (txt), FALSE, FALSE, 0);
2543 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
2546 gtk_window_set_default_size (GTK_WINDOW(dialog), 300, 300);
2547 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
2548 /* TODO: Comment about why is this commented out: */
2549 /* modest_platform_connect_and_wait (); */
2552 gtk_widget_destroy (dialog);
2556 modest_ui_actions_on_msg_link_hover (ModestMsgView *msgview, const gchar* link,
2559 /* g_message ("%s %s", __FUNCTION__, link); */
2564 modest_ui_actions_on_msg_link_clicked (ModestMsgView *msgview, const gchar* link,
2567 modest_platform_activate_uri (link);
2571 modest_ui_actions_on_msg_link_contextual (ModestMsgView *msgview, const gchar* link,
2574 modest_platform_show_uri_popup (link);
2578 modest_ui_actions_on_msg_attachment_clicked (ModestMsgView *msgview, TnyMimePart *mime_part,
2581 /* we check for low-mem; in that case, show a warning, and don't allow
2582 * viewing attachments
2584 if (modest_platform_check_memory_low (MODEST_WINDOW(win), TRUE))
2587 modest_msg_view_window_view_attachment (MODEST_MSG_VIEW_WINDOW (win), mime_part);
2591 modest_ui_actions_on_msg_recpt_activated (ModestMsgView *msgview,
2592 const gchar *address,
2595 /* g_message ("%s %s", __FUNCTION__, address); */
2599 on_save_to_drafts_cb (ModestMailOperation *mail_op,
2600 TnyMsg *saved_draft,
2603 ModestMsgEditWindow *edit_window;
2604 ModestMainWindow *win;
2606 /* FIXME. Make the header view sensitive again. This is a
2607 * temporary hack. See modest_ui_actions_on_save_to_drafts()
2609 win = MODEST_MAIN_WINDOW(modest_window_mgr_get_main_window(
2610 modest_runtime_get_window_mgr(), FALSE));
2612 GtkWidget *hdrview = modest_main_window_get_child_widget(
2613 win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2614 if (hdrview) gtk_widget_set_sensitive(hdrview, TRUE);
2617 edit_window = MODEST_MSG_EDIT_WINDOW (user_data);
2619 /* Set draft is there was no error */
2620 if (!modest_mail_operation_get_error (mail_op))
2621 modest_msg_edit_window_set_draft (edit_window, saved_draft);
2623 g_object_unref(edit_window);
2627 enough_space_for_message (ModestMsgEditWindow *edit_window,
2630 TnyAccountStore *acc_store;
2631 guint64 available_disk, expected_size;
2636 acc_store = TNY_ACCOUNT_STORE (modest_runtime_get_account_store());
2637 available_disk = modest_utils_get_available_space (NULL);
2638 modest_msg_edit_window_get_parts_size (edit_window, &parts_count, &parts_size);
2639 expected_size = modest_tny_msg_estimate_size (data->plain_body,
2644 /* Double check: memory full condition or message too big */
2645 if (available_disk < MIN_FREE_SPACE ||
2646 expected_size > available_disk) {
2648 modest_platform_information_banner (NULL, NULL,
2650 "cerm_device_memory_full"));
2655 * djcb: if we're in low-memory state, we only allow for
2656 * saving messages smaller than
2657 * MODEST_MAX_LOW_MEMORY_MESSAGE_SIZE (see modest-defs.h) this
2658 * should still allow for sending anything critical...
2660 if ((expected_size > MODEST_MAX_LOW_MEMORY_MESSAGE_SIZE) &&
2661 modest_platform_check_memory_low (MODEST_WINDOW(edit_window), TRUE))
2665 * djcb: we also make sure that the attachments are smaller than the max size
2666 * this is for the case where we'd try to forward a message with attachments
2667 * bigger than our max allowed size, or sending an message from drafts which
2668 * somehow got past our checks when attaching.
2670 if (expected_size > MODEST_MAX_ATTACHMENT_SIZE) {
2671 modest_platform_run_information_dialog (
2672 GTK_WINDOW(edit_window),
2673 dgettext("ke-recv","memr_ib_operation_disabled"),
2682 modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edit_window)
2684 TnyTransportAccount *transport_account;
2685 ModestMailOperation *mail_operation;
2687 gchar *account_name, *from;
2688 ModestAccountMgr *account_mgr;
2689 gboolean had_error = FALSE;
2690 ModestMainWindow *win = NULL;
2692 g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window), FALSE);
2694 data = modest_msg_edit_window_get_msg_data (edit_window);
2697 if (!enough_space_for_message (edit_window, data)) {
2698 modest_msg_edit_window_free_msg_data (edit_window, data);
2702 account_name = g_strdup (data->account_name);
2703 account_mgr = modest_runtime_get_account_mgr();
2705 account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
2707 account_name = modest_account_mgr_get_default_account (account_mgr);
2708 if (!account_name) {
2709 g_printerr ("modest: no account found\n");
2710 modest_msg_edit_window_free_msg_data (edit_window, data);
2714 if (!strcmp (account_name, MODEST_LOCAL_FOLDERS_ACCOUNT_ID)) {
2715 account_name = g_strdup (data->account_name);
2719 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
2720 (modest_runtime_get_account_store (),
2722 TNY_ACCOUNT_TYPE_TRANSPORT));
2723 if (!transport_account) {
2724 g_printerr ("modest: no transport account found for '%s'\n", account_name);
2725 g_free (account_name);
2726 modest_msg_edit_window_free_msg_data (edit_window, data);
2729 from = modest_account_mgr_get_from_string (account_mgr, account_name);
2731 /* Create the mail operation */
2732 mail_operation = modest_mail_operation_new_with_error_handling (NULL, modest_ui_actions_disk_operations_error_handler,
2734 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
2736 modest_mail_operation_save_to_drafts (mail_operation,
2748 data->priority_flags,
2749 on_save_to_drafts_cb,
2750 g_object_ref(edit_window));
2752 #ifdef MODEST_TOOLKIT_HILDON2
2753 /* In hildon2 we always show the information banner on saving to drafts.
2754 * It will be a system information banner in this case.
2756 gchar *text = g_strdup_printf (_("mail_va_saved_to_drafts"), _("mcen_me_folder_drafts"));
2757 modest_platform_information_banner (NULL, NULL, text);
2760 /* Use the main window as the parent of the banner, if the
2761 main window does not exist it won't be shown, if the parent
2762 window exists then it's properly shown. We don't use the
2763 editor window because it could be closed (save to drafts
2764 could happen after closing the window */
2765 win = (ModestMainWindow *)
2766 modest_window_mgr_get_main_window( modest_runtime_get_window_mgr(), FALSE);
2768 gchar *text = g_strdup_printf (_("mail_va_saved_to_drafts"), _("mcen_me_folder_drafts"));
2769 modest_platform_information_banner (GTK_WIDGET (win), NULL, text);
2773 modest_msg_edit_window_set_modified (edit_window, FALSE);
2777 g_free (account_name);
2778 g_object_unref (G_OBJECT (transport_account));
2779 g_object_unref (G_OBJECT (mail_operation));
2781 modest_msg_edit_window_free_msg_data (edit_window, data);
2784 * If the drafts folder is selected then make the header view
2785 * insensitive while the message is being saved to drafts
2786 * (it'll be sensitive again in on_save_to_drafts_cb()). This
2787 * is not very clean but it avoids letting the drafts folder
2788 * in an inconsistent state: the user could edit the message
2789 * being saved and undesirable things would happen.
2790 * In the average case the user won't notice anything at
2791 * all. In the worst case (the user is editing a really big
2792 * file from Drafts) the header view will be insensitive
2793 * during the saving process (10 or 20 seconds, depending on
2794 * the message). Anyway this is just a quick workaround: once
2795 * we find a better solution it should be removed
2796 * See NB#65125 (commend #18) for details.
2798 if (!had_error && win != NULL) {
2799 ModestFolderView *view = MODEST_FOLDER_VIEW(modest_main_window_get_child_widget(
2800 win, MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW));
2802 TnyFolder *folder = TNY_FOLDER(modest_folder_view_get_selected(view));
2804 if (modest_tny_folder_is_local_folder(folder)) {
2805 TnyFolderType folder_type;
2806 folder_type = modest_tny_folder_get_local_or_mmc_folder_type(folder);
2807 if (folder_type == TNY_FOLDER_TYPE_DRAFTS) {
2808 GtkWidget *hdrview = modest_main_window_get_child_widget(
2809 win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2810 if (hdrview) gtk_widget_set_sensitive(hdrview, FALSE);
2814 if (folder != NULL) g_object_unref(folder);
2821 /* For instance, when clicking the Send toolbar button when editing a message: */
2823 modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
2825 TnyTransportAccount *transport_account = NULL;
2826 gboolean had_error = FALSE;
2828 ModestAccountMgr *account_mgr;
2829 gchar *account_name;
2831 ModestMailOperation *mail_operation;
2833 g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window), TRUE);
2835 if (!modest_msg_edit_window_check_names (edit_window, TRUE))
2838 data = modest_msg_edit_window_get_msg_data (edit_window);
2841 if (!enough_space_for_message (edit_window, data)) {
2842 modest_msg_edit_window_free_msg_data (edit_window, data);
2846 account_mgr = modest_runtime_get_account_mgr();
2847 account_name = g_strdup (data->account_name);
2849 account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
2852 account_name = modest_account_mgr_get_default_account (account_mgr);
2854 if (!account_name) {
2855 modest_msg_edit_window_free_msg_data (edit_window, data);
2856 /* Run account setup wizard */
2857 if (!modest_ui_actions_run_account_setup_wizard (MODEST_WINDOW(edit_window))) {
2862 /* Get the currently-active transport account for this modest account: */
2863 if (strcmp (account_name, MODEST_LOCAL_FOLDERS_ACCOUNT_ID) != 0) {
2865 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
2866 (modest_runtime_get_account_store (),
2867 account_name, TNY_ACCOUNT_TYPE_TRANSPORT));
2870 if (!transport_account) {
2871 modest_msg_edit_window_free_msg_data (edit_window, data);
2872 /* Run account setup wizard */
2873 if (!modest_ui_actions_run_account_setup_wizard(MODEST_WINDOW(edit_window)))
2878 /* Create the mail operation */
2879 from = modest_account_mgr_get_from_string (account_mgr, account_name);
2880 mail_operation = modest_mail_operation_new_with_error_handling (NULL, modest_ui_actions_disk_operations_error_handler, NULL, NULL);
2881 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
2883 modest_mail_operation_send_new_mail (mail_operation,
2895 data->priority_flags);
2897 if (modest_mail_operation_get_status (mail_operation) == MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS)
2898 modest_platform_information_banner (NULL, NULL, _("mcen_ib_outbox_waiting_to_be_sent"));
2901 if (modest_mail_operation_get_error (mail_operation) != NULL) {
2902 const GError *error = modest_mail_operation_get_error (mail_operation);
2903 if (error->domain == MODEST_MAIL_OPERATION_ERROR &&
2904 error->code == MODEST_MAIL_OPERATION_ERROR_INSTANCE_CREATION_FAILED) {
2905 g_warning ("%s failed: %s\n", __FUNCTION__, (modest_mail_operation_get_error (mail_operation))->message);
2906 modest_platform_information_banner (NULL, NULL, _CS("sfil_ni_not_enough_memory"));
2913 g_free (account_name);
2914 g_object_unref (G_OBJECT (transport_account));
2915 g_object_unref (G_OBJECT (mail_operation));
2917 modest_msg_edit_window_free_msg_data (edit_window, data);
2920 modest_msg_edit_window_set_sent (edit_window, TRUE);
2922 /* Save settings and close the window: */
2923 modest_ui_actions_on_close_window (NULL, MODEST_WINDOW (edit_window));
2930 modest_ui_actions_on_toggle_bold (GtkToggleAction *action,
2931 ModestMsgEditWindow *window)
2933 ModestMsgEditFormatState *format_state = NULL;
2935 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2936 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
2938 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2941 format_state = modest_msg_edit_window_get_format_state (window);
2942 g_return_if_fail (format_state != NULL);
2944 format_state->bold = gtk_toggle_action_get_active (action);
2945 modest_msg_edit_window_set_format_state (window, format_state);
2946 g_free (format_state);
2951 modest_ui_actions_on_toggle_italics (GtkToggleAction *action,
2952 ModestMsgEditWindow *window)
2954 ModestMsgEditFormatState *format_state = NULL;
2956 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2957 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
2959 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2962 format_state = modest_msg_edit_window_get_format_state (window);
2963 g_return_if_fail (format_state != NULL);
2965 format_state->italics = gtk_toggle_action_get_active (action);
2966 modest_msg_edit_window_set_format_state (window, format_state);
2967 g_free (format_state);
2972 modest_ui_actions_on_toggle_bullets (GtkToggleAction *action,
2973 ModestMsgEditWindow *window)
2975 ModestMsgEditFormatState *format_state = NULL;
2977 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2978 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
2980 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2983 format_state = modest_msg_edit_window_get_format_state (window);
2984 g_return_if_fail (format_state != NULL);
2986 format_state->bullet = gtk_toggle_action_get_active (action);
2987 modest_msg_edit_window_set_format_state (window, format_state);
2988 g_free (format_state);
2993 modest_ui_actions_on_change_justify (GtkRadioAction *action,
2994 GtkRadioAction *selected,
2995 ModestMsgEditWindow *window)
2997 ModestMsgEditFormatState *format_state = NULL;
2998 GtkJustification value;
3000 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3002 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3005 value = gtk_radio_action_get_current_value (selected);
3007 format_state = modest_msg_edit_window_get_format_state (window);
3008 g_return_if_fail (format_state != NULL);
3010 format_state->justification = value;
3011 modest_msg_edit_window_set_format_state (window, format_state);
3012 g_free (format_state);
3016 modest_ui_actions_on_select_editor_color (GtkAction *action,
3017 ModestMsgEditWindow *window)
3019 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3020 g_return_if_fail (GTK_IS_ACTION (action));
3022 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3025 modest_msg_edit_window_select_color (window);
3029 modest_ui_actions_on_select_editor_background_color (GtkAction *action,
3030 ModestMsgEditWindow *window)
3032 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3033 g_return_if_fail (GTK_IS_ACTION (action));
3035 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3038 modest_msg_edit_window_select_background_color (window);
3042 modest_ui_actions_on_insert_image (GtkAction *action,
3043 ModestMsgEditWindow *window)
3045 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3046 g_return_if_fail (GTK_IS_ACTION (action));
3049 if (modest_platform_check_memory_low (MODEST_WINDOW(window), TRUE))
3052 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3055 modest_msg_edit_window_insert_image (window);
3059 modest_ui_actions_on_attach_file (GtkAction *action,
3060 ModestMsgEditWindow *window)
3062 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3063 g_return_if_fail (GTK_IS_ACTION (action));
3065 if (modest_platform_check_memory_low (MODEST_WINDOW(window), TRUE))
3068 modest_msg_edit_window_offer_attach_file (window);
3072 modest_ui_actions_on_remove_attachments (GtkAction *action,
3073 ModestMsgEditWindow *window)
3075 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3076 g_return_if_fail (GTK_IS_ACTION (action));
3078 modest_msg_edit_window_remove_attachments (window, NULL);
3082 #ifndef MODEST_TOOLKIT_GTK
3087 TnyFolderStore *folder;
3088 } CreateFolderHelper;
3091 show_create_folder_in_timeout (gpointer data)
3093 CreateFolderHelper *helper = (CreateFolderHelper *) data;
3095 /* Remove the timeout ASAP, we can not wait until the dialog
3096 is shown because it could take a lot of time and so the
3097 timeout could be called twice or more times */
3098 g_source_remove (helper->handler);
3100 gdk_threads_enter ();
3101 do_create_folder (helper->win, helper->folder, helper->name);
3102 gdk_threads_leave ();
3104 g_object_unref (helper->win);
3105 g_object_unref (helper->folder);
3106 g_free (helper->name);
3107 g_slice_free (CreateFolderHelper, helper);
3114 do_create_folder_cb (ModestMailOperation *mail_op,
3115 TnyFolderStore *parent_folder,
3116 TnyFolder *new_folder,
3119 gchar *suggested_name = (gchar *) user_data;
3120 GtkWindow *source_win = (GtkWindow *) modest_mail_operation_get_source (mail_op);
3122 if (modest_mail_operation_get_error (mail_op)) {
3124 /* Show an error. If there was some problem writing to
3125 disk, show it, otherwise show the generic folder
3126 create error. We do it here and not in an error
3127 handler because the call to do_create_folder will
3128 stop the main loop in a gtk_dialog_run and then,
3129 the message won't be shown until that dialog is
3131 modest_ui_actions_disk_operations_error_handler (mail_op,
3132 _("mail_in_ui_folder_create_error"));
3134 /* Try again. Do *NOT* show any error because the mail
3135 operations system will do it for us because we
3136 created the mail_op with new_with_error_handler */
3137 #ifndef MODEST_TOOLKIT_GTK
3138 CreateFolderHelper *helper;
3139 helper = g_slice_new0 (CreateFolderHelper);
3140 helper->name = g_strdup (suggested_name);
3141 helper->folder = g_object_ref (parent_folder);
3142 helper->win = g_object_ref (source_win);
3144 /* Ugly but neccesary stuff. The problem is that the
3145 dialog when is shown calls a function that destroys
3146 all the temporary windows, so the banner is
3148 helper->handler = g_timeout_add (2000, show_create_folder_in_timeout, helper);
3150 do_create_folder (source_win, parent_folder, (const gchar *) suggested_name);
3153 /* the 'source_win' is either the ModestMainWindow, or the 'Move to folder'-dialog
3154 * FIXME: any other? */
3155 GtkWidget *folder_view;
3157 if (MODEST_IS_MAIN_WINDOW(source_win))
3159 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (source_win),
3160 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3163 get_folder_view_from_move_to_dialog (GTK_WIDGET(source_win));
3165 /* Select the newly created folder. It could happen
3166 that the widget is no longer there (i.e. the window
3167 has been destroyed, so we need to check this */
3169 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view),
3171 g_object_unref (new_folder);
3173 /* Free. Note that the first time it'll be NULL so noop */
3174 g_free (suggested_name);
3175 g_object_unref (source_win);
3179 do_create_folder (GtkWindow *parent_window,
3180 TnyFolderStore *parent_folder,
3181 const gchar *suggested_name)
3184 gchar *folder_name = NULL;
3186 result = modest_platform_run_new_folder_dialog (GTK_WINDOW (parent_window),
3188 (gchar *) suggested_name,
3191 if (result == GTK_RESPONSE_ACCEPT) {
3192 ModestMailOperation *mail_op;
3194 mail_op = modest_mail_operation_new ((GObject *) parent_window);
3195 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
3197 modest_mail_operation_create_folder (mail_op,
3199 (const gchar *) folder_name,
3200 do_create_folder_cb,
3202 g_object_unref (mail_op);
3207 create_folder_performer (gboolean canceled,
3209 GtkWindow *parent_window,
3210 TnyAccount *account,
3213 TnyFolderStore *parent_folder = TNY_FOLDER_STORE (user_data);
3215 if (canceled || err) {
3216 /* In memory full conditions we could get this error here */
3217 check_memory_full_error ((GtkWidget *) parent_window, err);
3221 /* Run the new folder dialog */
3222 do_create_folder (GTK_WINDOW (parent_window), parent_folder, NULL);
3225 g_object_unref (parent_folder);
3229 modest_ui_actions_create_folder(GtkWidget *parent_window,
3230 GtkWidget *folder_view)
3232 TnyFolderStore *parent_folder;
3234 parent_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
3236 if (parent_folder) {
3237 /* The parent folder will be freed in the callback */
3238 modest_platform_connect_if_remote_and_perform (GTK_WINDOW (parent_window),
3241 create_folder_performer,
3247 modest_ui_actions_on_new_folder (GtkAction *action, ModestMainWindow *main_window)
3249 GtkWidget *folder_view;
3251 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
3253 folder_view = modest_main_window_get_child_widget (main_window,
3254 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3258 modest_ui_actions_create_folder (GTK_WIDGET (main_window), folder_view);
3262 modest_ui_actions_rename_folder_error_handler (ModestMailOperation *mail_op,
3265 const GError *error = NULL;
3266 const gchar *message = NULL;
3268 /* Get error message */
3269 error = modest_mail_operation_get_error (mail_op);
3271 g_return_if_reached ();
3273 if (error->domain == MODEST_MAIL_OPERATION_ERROR &&
3274 error->code == MODEST_MAIL_OPERATION_ERROR_FOLDER_EXISTS) {
3275 message = _CS("ckdg_ib_folder_already_exists");
3276 } else if (error->domain == TNY_ERROR_DOMAIN &&
3277 error->code == TNY_SERVICE_ERROR_STATE) {
3278 /* This means that the folder is already in use (a
3279 message is opened for example */
3280 message = _("emev_ni_internal_error");
3282 message = _("emev_ib_ui_imap_unable_to_rename");
3285 /* We don't set a parent for the dialog because the dialog
3286 will be destroyed so the banner won't appear */
3287 modest_platform_information_banner (NULL, NULL, message);
3291 TnyFolderStore *folder;
3296 on_rename_folder_cb (ModestMailOperation *mail_op,
3297 TnyFolder *new_folder,
3300 ModestFolderView *folder_view;
3302 /* If the window was closed when renaming a folder this could
3304 if (!MODEST_IS_FOLDER_VIEW (user_data))
3307 folder_view = MODEST_FOLDER_VIEW (user_data);
3308 /* Note that if the rename fails new_folder will be NULL */
3310 modest_folder_view_select_folder (folder_view, new_folder, FALSE);
3312 modest_folder_view_select_first_inbox_or_local (folder_view);
3314 gtk_widget_grab_focus (GTK_WIDGET (folder_view));
3318 on_rename_folder_performer (gboolean canceled,
3320 GtkWindow *parent_window,
3321 TnyAccount *account,
3324 ModestMailOperation *mail_op = NULL;
3325 GtkTreeSelection *sel = NULL;
3326 GtkWidget *folder_view = NULL;
3327 RenameFolderInfo *data = (RenameFolderInfo*)user_data;
3329 if (canceled || err) {
3330 /* In memory full conditions we could get this error here */
3331 check_memory_full_error ((GtkWidget *) parent_window, err);
3332 } else if (MODEST_IS_MAIN_WINDOW(parent_window)) {
3334 folder_view = modest_main_window_get_child_widget (
3335 MODEST_MAIN_WINDOW (parent_window),
3336 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3339 modest_mail_operation_new_with_error_handling (G_OBJECT(parent_window),
3340 modest_ui_actions_rename_folder_error_handler,
3341 parent_window, NULL);
3343 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
3346 /* Clear the headers view */
3347 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_view));
3348 gtk_tree_selection_unselect_all (sel);
3350 /* Actually rename the folder */
3351 modest_mail_operation_rename_folder (mail_op,
3352 TNY_FOLDER (data->folder),
3353 (const gchar *) (data->new_name),
3354 on_rename_folder_cb,
3356 g_object_unref (data->folder);
3357 g_object_unref (mail_op);
3360 g_free (data->new_name);
3365 modest_ui_actions_on_rename_folder (GtkAction *action,
3366 ModestMainWindow *main_window)
3368 TnyFolderStore *folder;
3369 GtkWidget *folder_view;
3370 GtkWidget *header_view;
3372 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
3374 folder_view = modest_main_window_get_child_widget (main_window,
3375 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3379 header_view = modest_main_window_get_child_widget (main_window,
3380 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
3385 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
3390 if (TNY_IS_FOLDER (folder)) {
3391 gchar *folder_name = NULL;
3393 const gchar *current_name;
3394 TnyFolderStore *parent;
3395 gboolean do_rename = TRUE;
3397 current_name = tny_folder_get_name (TNY_FOLDER (folder));
3398 parent = tny_folder_get_folder_store (TNY_FOLDER (folder));
3399 response = modest_platform_run_rename_folder_dialog (GTK_WINDOW (main_window),
3400 parent, current_name,
3402 g_object_unref (parent);
3404 if (response != GTK_RESPONSE_ACCEPT || strlen (folder_name) == 0) {
3407 RenameFolderInfo *rename_folder_data = g_new0 (RenameFolderInfo, 1);
3408 rename_folder_data->folder = g_object_ref (folder);
3409 rename_folder_data->new_name = folder_name;
3410 modest_platform_connect_if_remote_and_perform (GTK_WINDOW(main_window), TRUE,
3411 folder, on_rename_folder_performer, rename_folder_data);
3414 g_object_unref (folder);
3418 modest_ui_actions_delete_folder_error_handler (ModestMailOperation *mail_op,
3421 GObject *win = modest_mail_operation_get_source (mail_op);
3423 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
3424 _("mail_in_ui_folder_delete_error"),
3426 g_object_unref (win);
3430 TnyFolderStore *folder;
3431 gboolean move_to_trash;
3435 on_delete_folder_cb (gboolean canceled,
3437 GtkWindow *parent_window,
3438 TnyAccount *account,
3441 DeleteFolderInfo *info = (DeleteFolderInfo*) user_data;
3442 GtkWidget *folder_view;
3443 ModestMailOperation *mail_op;
3444 GtkTreeSelection *sel;
3446 if (!MODEST_IS_MAIN_WINDOW(parent_window) || canceled || (err!=NULL)) {
3447 g_object_unref (G_OBJECT (info->folder));
3452 folder_view = modest_main_window_get_child_widget (
3453 MODEST_MAIN_WINDOW (parent_window),
3454 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3456 /* Unselect the folder before deleting it to free the headers */
3457 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_view));
3458 gtk_tree_selection_unselect_all (sel);
3460 /* Create the mail operation */
3462 modest_mail_operation_new_with_error_handling (G_OBJECT(parent_window),
3463 modest_ui_actions_delete_folder_error_handler,
3466 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
3468 modest_mail_operation_remove_folder (mail_op, TNY_FOLDER (info->folder), info->move_to_trash);
3470 modest_folder_view_select_first_inbox_or_local (MODEST_FOLDER_VIEW (folder_view));
3472 g_object_unref (G_OBJECT (mail_op));
3473 g_object_unref (G_OBJECT (info->folder));
3478 delete_folder (ModestMainWindow *main_window, gboolean move_to_trash)
3480 TnyFolderStore *folder;
3481 GtkWidget *folder_view;
3485 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
3487 folder_view = modest_main_window_get_child_widget (main_window,
3488 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3492 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
3494 /* Show an error if it's an account */
3495 if (!TNY_IS_FOLDER (folder)) {
3496 modest_platform_run_information_dialog (GTK_WINDOW (main_window),
3497 _("mail_in_ui_folder_delete_error"),
3499 g_object_unref (G_OBJECT (folder));
3504 message = g_strdup_printf (_("mcen_nc_delete_folder_text"),
3505 tny_folder_get_name (TNY_FOLDER (folder)));
3506 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (main_window),
3507 (const gchar *) message);
3510 if (response == GTK_RESPONSE_OK) {
3511 DeleteFolderInfo *info;
3512 info = g_new0(DeleteFolderInfo, 1);
3513 info->folder = folder;
3514 info->move_to_trash = move_to_trash;
3515 g_object_ref (G_OBJECT (info->folder));
3516 TnyAccount *account = tny_folder_get_account (TNY_FOLDER (folder));
3517 modest_platform_connect_if_remote_and_perform (GTK_WINDOW (main_window),
3519 TNY_FOLDER_STORE (account),
3520 on_delete_folder_cb, info);
3521 g_object_unref (account);
3523 g_object_unref (G_OBJECT (folder));
3527 modest_ui_actions_on_delete_folder (GtkAction *action,
3528 ModestMainWindow *main_window)
3530 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
3532 delete_folder (main_window, FALSE);
3536 modest_ui_actions_on_move_folder_to_trash_folder (GtkAction *action, ModestMainWindow *main_window)
3538 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
3540 delete_folder (main_window, TRUE);
3544 typedef struct _PasswordDialogFields {
3545 GtkWidget *username;
3546 GtkWidget *password;
3548 } PasswordDialogFields;
3551 password_dialog_check_field (GtkEditable *editable,
3552 PasswordDialogFields *fields)
3555 gboolean any_value_empty = FALSE;
3557 value = gtk_entry_get_text (GTK_ENTRY (fields->username));
3558 if ((value == NULL) || value[0] == '\0') {
3559 any_value_empty = TRUE;
3561 value = gtk_entry_get_text (GTK_ENTRY (fields->password));
3562 if ((value == NULL) || value[0] == '\0') {
3563 any_value_empty = TRUE;
3565 gtk_dialog_set_response_sensitive (GTK_DIALOG (fields->dialog), GTK_RESPONSE_ACCEPT, !any_value_empty);
3569 modest_ui_actions_on_password_requested (TnyAccountStore *account_store,
3570 const gchar* server_account_name,
3575 ModestMainWindow *main_window)
3577 g_return_if_fail(server_account_name);
3578 gboolean completed = FALSE;
3579 PasswordDialogFields *fields = NULL;
3581 /* Initalize output parameters: */
3588 #ifndef MODEST_TOOLKIT_GTK
3589 /* Maemo uses a different (awkward) button order,
3590 * It should probably just use gtk_alternative_dialog_button_order ().
3592 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
3595 _("mcen_bd_dialog_ok"),
3596 GTK_RESPONSE_ACCEPT,
3597 _("mcen_bd_dialog_cancel"),
3598 GTK_RESPONSE_REJECT,
3601 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
3605 GTK_RESPONSE_REJECT,
3607 GTK_RESPONSE_ACCEPT,
3609 #endif /* !MODEST_TOOLKIT_GTK */
3611 modest_window_mgr_set_modal (modest_runtime_get_window_mgr(), GTK_WINDOW (dialog), NULL);
3613 gchar *server_name = modest_account_mgr_get_server_account_hostname (
3614 modest_runtime_get_account_mgr(), server_account_name);
3615 if (!server_name) {/* This happened once, though I don't know why. murrayc. */
3616 g_warning("%s: Could not get server name for server account '%s'", __FUNCTION__, server_account_name);
3619 gtk_widget_destroy (dialog);
3623 /* This causes a warning because the logical ID has no %s in it,
3624 * though the translation does, but there is not much we can do about that: */
3625 gchar *txt = g_strdup_printf (_("mail_ia_password_info"), server_name);
3626 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), gtk_label_new(txt),
3629 g_free (server_name);
3633 gchar *initial_username = modest_account_mgr_get_server_account_username (
3634 modest_runtime_get_account_mgr(), server_account_name);
3636 GtkWidget *entry_username = gtk_entry_new ();
3637 if (initial_username)
3638 gtk_entry_set_text (GTK_ENTRY (entry_username), initial_username);
3639 /* Dim this if a connection has ever succeeded with this username,
3640 * as per the UI spec: */
3641 /* const gboolean username_known = */
3642 /* modest_account_mgr_get_server_account_username_has_succeeded( */
3643 /* modest_runtime_get_account_mgr(), server_account_name); */
3644 /* gtk_widget_set_sensitive (entry_username, !username_known); */
3646 /* We drop the username sensitive code and disallow changing it here
3647 * as tinymail does not support really changing the username in the callback
3649 gtk_widget_set_sensitive (entry_username, FALSE);
3651 #ifndef MODEST_TOOLKIT_GTK
3652 /* Auto-capitalization is the default, so let's turn it off: */
3653 hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_username), HILDON_GTK_INPUT_MODE_FULL);
3655 /* Create a size group to be used by all captions.
3656 * Note that HildonCaption does not create a default size group if we do not specify one.
3657 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
3658 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
3660 GtkWidget *caption = hildon_caption_new (sizegroup,
3661 _("mail_fi_username"), entry_username, NULL, HILDON_CAPTION_MANDATORY);
3662 gtk_widget_show (entry_username);
3663 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
3664 FALSE, FALSE, MODEST_MARGIN_HALF);
3665 gtk_widget_show (caption);
3667 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry_username,
3669 #endif /* !MODEST_TOOLKIT_GTK */
3672 GtkWidget *entry_password = gtk_entry_new ();
3673 gtk_entry_set_visibility (GTK_ENTRY(entry_password), FALSE);
3674 /* gtk_entry_set_invisible_char (GTK_ENTRY(entry_password), "*"); */
3676 #ifndef MODEST_TOOLKIT_GTK
3677 /* Auto-capitalization is the default, so let's turn it off: */
3678 hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_password),
3679 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
3681 caption = hildon_caption_new (sizegroup,
3682 _("mail_fi_password"), entry_password, NULL, HILDON_CAPTION_MANDATORY);
3683 gtk_widget_show (entry_password);
3684 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
3685 FALSE, FALSE, MODEST_MARGIN_HALF);
3686 gtk_widget_show (caption);
3687 g_object_unref (sizegroup);
3689 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry_password,
3691 #endif /* !MODEST_TOOLKIT_GTK */
3693 if (initial_username != NULL)
3694 gtk_widget_grab_focus (GTK_WIDGET (entry_password));
3696 /* This is not in the Maemo UI spec:
3697 remember_pass_check = gtk_check_button_new_with_label (_("Remember password"));
3698 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), remember_pass_check,
3702 fields = g_slice_new0 (PasswordDialogFields);
3703 fields->username = entry_username;
3704 fields->password = entry_password;
3705 fields->dialog = dialog;
3707 g_signal_connect (entry_username, "changed", G_CALLBACK (password_dialog_check_field), fields);
3708 g_signal_connect (entry_password, "changed", G_CALLBACK (password_dialog_check_field), fields);
3709 password_dialog_check_field (NULL, fields);
3711 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
3713 while (!completed) {
3715 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
3717 *username = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_username)));
3719 /* Note that an empty field becomes the "" string */
3720 if (*username && strlen (*username) > 0) {
3721 modest_account_mgr_set_server_account_username (modest_runtime_get_account_mgr(),
3722 server_account_name,
3726 const gboolean username_was_changed =
3727 (strcmp (*username, initial_username) != 0);
3728 if (username_was_changed) {
3729 g_warning ("%s: tinymail does not yet support changing the "
3730 "username in the get_password() callback.\n", __FUNCTION__);
3736 modest_platform_information_banner (GTK_WIDGET (dialog), NULL,
3737 _("mcen_ib_username_pw_incorrect"));
3743 *password = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_password)));
3745 /* We do not save the password in the configuration,
3746 * because this function is only called for passwords that should
3747 * not be remembered:
3748 modest_server_account_set_password (
3749 modest_runtime_get_account_mgr(), server_account_name,
3756 /* Set parent to NULL or the banner will disappear with its parent dialog */
3757 modest_platform_information_banner(NULL, NULL, _("mail_ib_login_cancelled"));
3768 /* This is not in the Maemo UI spec:
3769 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (remember_pass_check)))
3775 g_free (initial_username);
3776 gtk_widget_destroy (dialog);
3777 g_slice_free (PasswordDialogFields, fields);
3779 /* printf ("DEBUG: %s: cancel=%d\n", __FUNCTION__, *cancel); */
3783 modest_ui_actions_on_cut (GtkAction *action,
3784 ModestWindow *window)
3786 GtkWidget *focused_widget;
3787 GtkClipboard *clipboard;
3789 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
3790 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
3791 if (GTK_IS_EDITABLE (focused_widget)) {
3792 gtk_editable_cut_clipboard (GTK_EDITABLE(focused_widget));
3793 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3794 gtk_clipboard_store (clipboard);
3795 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
3796 GtkTextBuffer *buffer;
3798 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
3799 if (modest_text_utils_buffer_selection_is_valid (buffer)) {
3800 gtk_text_buffer_cut_clipboard (buffer, clipboard, TRUE);
3801 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3802 gtk_clipboard_store (clipboard);
3804 } else if (MODEST_IS_HEADER_VIEW (focused_widget)) {
3805 TnyList *header_list = modest_header_view_get_selected_headers (
3806 MODEST_HEADER_VIEW (focused_widget));
3807 gboolean continue_download = FALSE;
3808 gint num_of_unc_msgs;
3810 num_of_unc_msgs = header_list_count_uncached_msgs(header_list);
3812 if (num_of_unc_msgs) {
3813 TnyAccount *account = get_account_from_header_list (header_list);
3815 continue_download = connect_to_get_msg (window, num_of_unc_msgs, account);
3816 g_object_unref (account);
3820 if (num_of_unc_msgs == 0 || continue_download) {
3821 /* modest_platform_information_banner (
3822 NULL, NULL, _CS("mcen_ib_getting_items"));*/
3823 modest_header_view_cut_selection (
3824 MODEST_HEADER_VIEW (focused_widget));
3827 g_object_unref (header_list);
3828 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
3829 modest_folder_view_cut_selection (MODEST_FOLDER_VIEW (focused_widget));
3834 modest_ui_actions_on_copy (GtkAction *action,
3835 ModestWindow *window)
3837 GtkClipboard *clipboard;
3838 GtkWidget *focused_widget;
3839 gboolean copied = TRUE;
3841 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
3842 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
3844 if (GTK_IS_LABEL (focused_widget)) {
3846 selection = modest_text_utils_label_get_selection (GTK_LABEL (focused_widget));
3847 gtk_clipboard_set_text (clipboard, selection, -1);
3849 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3850 gtk_clipboard_store (clipboard);
3851 } else if (GTK_IS_EDITABLE (focused_widget)) {
3852 gtk_editable_copy_clipboard (GTK_EDITABLE(focused_widget));
3853 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3854 gtk_clipboard_store (clipboard);
3855 } else if (GTK_IS_HTML (focused_widget)) {
3858 sel = gtk_html_get_selection_html (GTK_HTML (focused_widget), &len);
3859 if ((sel == NULL) || (sel[0] == '\0')) {
3862 gtk_html_copy (GTK_HTML (focused_widget));
3863 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3864 gtk_clipboard_store (clipboard);
3866 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
3867 GtkTextBuffer *buffer;
3868 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
3869 if (modest_text_utils_buffer_selection_is_valid (buffer)) {
3870 gtk_text_buffer_copy_clipboard (buffer, clipboard);
3871 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3872 gtk_clipboard_store (clipboard);
3874 } else if (MODEST_IS_HEADER_VIEW (focused_widget)) {
3875 TnyList *header_list = modest_header_view_get_selected_headers (
3876 MODEST_HEADER_VIEW (focused_widget));
3877 gboolean continue_download = FALSE;
3878 gint num_of_unc_msgs;
3880 num_of_unc_msgs = header_list_count_uncached_msgs(header_list);
3882 if (num_of_unc_msgs) {
3883 TnyAccount *account = get_account_from_header_list (header_list);
3885 continue_download = connect_to_get_msg (window, num_of_unc_msgs, account);
3886 g_object_unref (account);
3890 if (num_of_unc_msgs == 0 || continue_download) {
3891 modest_platform_information_banner (
3892 NULL, NULL, _CS("mcen_ib_getting_items"));
3893 modest_header_view_copy_selection (
3894 MODEST_HEADER_VIEW (focused_widget));
3898 g_object_unref (header_list);
3900 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
3901 modest_folder_view_copy_selection (MODEST_FOLDER_VIEW (focused_widget));
3904 /* Show information banner if there was a copy to clipboard */
3906 modest_platform_information_banner (
3907 NULL, NULL, _CS("ecoc_ib_edwin_copied"));
3911 modest_ui_actions_on_undo (GtkAction *action,
3912 ModestWindow *window)
3914 ModestEmailClipboard *clipboard = NULL;
3916 if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
3917 modest_msg_edit_window_undo (MODEST_MSG_EDIT_WINDOW (window));
3918 } else if (MODEST_IS_MAIN_WINDOW (window)) {
3919 /* Clear clipboard source */
3920 clipboard = modest_runtime_get_email_clipboard ();
3921 modest_email_clipboard_clear (clipboard);
3924 g_return_if_reached ();
3929 modest_ui_actions_on_redo (GtkAction *action,
3930 ModestWindow *window)
3932 if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
3933 modest_msg_edit_window_redo (MODEST_MSG_EDIT_WINDOW (window));
3936 g_return_if_reached ();
3942 destroy_information_note (ModestMailOperation *mail_op,
3945 /* destroy information note */
3946 gtk_widget_destroy (GTK_WIDGET(user_data));
3950 destroy_folder_information_note (ModestMailOperation *mail_op,
3951 TnyFolder *new_folder,
3954 /* destroy information note */
3955 gtk_widget_destroy (GTK_WIDGET(user_data));
3960 paste_as_attachment_free (gpointer data)
3962 PasteAsAttachmentHelper *helper = (PasteAsAttachmentHelper *) data;
3964 if (helper->banner) {
3965 gtk_widget_destroy (helper->banner);
3966 g_object_unref (helper->banner);
3972 paste_msg_as_attachment_cb (ModestMailOperation *mail_op,
3977 PasteAsAttachmentHelper *helper = (PasteAsAttachmentHelper *) userdata;
3978 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (helper->window));
3983 modest_msg_edit_window_add_part (MODEST_MSG_EDIT_WINDOW (helper->window), TNY_MIME_PART (msg));
3988 modest_ui_actions_on_paste (GtkAction *action,
3989 ModestWindow *window)
3991 GtkWidget *focused_widget = NULL;
3992 GtkWidget *inf_note = NULL;
3993 ModestMailOperation *mail_op = NULL;
3995 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
3996 if (GTK_IS_EDITABLE (focused_widget)) {
3997 gtk_editable_paste_clipboard (GTK_EDITABLE(focused_widget));
3998 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
3999 ModestEmailClipboard *e_clipboard = NULL;
4000 e_clipboard = modest_runtime_get_email_clipboard ();
4001 if (modest_email_clipboard_cleared (e_clipboard)) {
4002 GtkTextBuffer *buffer;
4003 GtkClipboard *clipboard;
4005 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
4006 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
4007 gtk_text_buffer_paste_clipboard (buffer, clipboard, NULL, TRUE);
4008 } else if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
4009 ModestMailOperation *mail_op;
4010 TnyFolder *src_folder = NULL;
4011 TnyList *data = NULL;
4013 PasteAsAttachmentHelper *helper = g_new0 (PasteAsAttachmentHelper, 1);
4014 helper->window = MODEST_MSG_EDIT_WINDOW (window);
4015 helper->banner = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
4016 _CS("ckct_nw_pasting"));
4017 modest_email_clipboard_get_data (e_clipboard, &src_folder, &data, &delete);
4018 mail_op = modest_mail_operation_new (G_OBJECT (window));
4019 if (helper->banner != NULL) {
4020 g_object_ref (G_OBJECT (helper->banner));
4021 gtk_widget_show (GTK_WIDGET (helper->banner));
4025 modest_mail_operation_get_msgs_full (mail_op,
4027 (GetMsgAsyncUserCallback) paste_msg_as_attachment_cb,
4029 paste_as_attachment_free);
4033 g_object_unref (data);
4035 g_object_unref (src_folder);
4038 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
4039 ModestEmailClipboard *clipboard = NULL;
4040 TnyFolder *src_folder = NULL;
4041 TnyFolderStore *folder_store = NULL;
4042 TnyList *data = NULL;
4043 gboolean delete = FALSE;
4045 /* Check clipboard source */
4046 clipboard = modest_runtime_get_email_clipboard ();
4047 if (modest_email_clipboard_cleared (clipboard))
4050 /* Get elements to paste */
4051 modest_email_clipboard_get_data (clipboard, &src_folder, &data, &delete);
4053 /* Create a new mail operation */
4054 mail_op = modest_mail_operation_new (G_OBJECT(window));
4056 /* Get destination folder */
4057 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (focused_widget));
4059 /* transfer messages */
4063 /* Ask for user confirmation */
4065 modest_ui_actions_msgs_move_to_confirmation (window,
4066 TNY_FOLDER (folder_store),
4070 if (response == GTK_RESPONSE_OK) {
4071 /* Launch notification */
4072 inf_note = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
4073 _CS("ckct_nw_pasting"));
4074 if (inf_note != NULL) {
4075 gtk_window_set_modal (GTK_WINDOW(inf_note), FALSE);
4076 gtk_widget_show (GTK_WIDGET(inf_note));
4079 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
4080 modest_mail_operation_xfer_msgs (mail_op,
4082 TNY_FOLDER (folder_store),
4084 destroy_information_note,
4087 g_object_unref (mail_op);
4090 } else if (src_folder != NULL) {
4091 /* Launch notification */
4092 inf_note = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
4093 _CS("ckct_nw_pasting"));
4094 if (inf_note != NULL) {
4095 gtk_window_set_modal (GTK_WINDOW(inf_note), FALSE);
4096 gtk_widget_show (GTK_WIDGET(inf_note));
4099 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
4100 modest_mail_operation_xfer_folder (mail_op,
4104 destroy_folder_information_note,
4110 g_object_unref (data);
4111 if (src_folder != NULL)
4112 g_object_unref (src_folder);
4113 if (folder_store != NULL)
4114 g_object_unref (folder_store);
4120 modest_ui_actions_on_select_all (GtkAction *action,
4121 ModestWindow *window)
4123 GtkWidget *focused_widget;
4125 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
4126 if (MODEST_IS_ATTACHMENTS_VIEW (focused_widget)) {
4127 modest_attachments_view_select_all (MODEST_ATTACHMENTS_VIEW (focused_widget));
4128 } else if (GTK_IS_LABEL (focused_widget)) {
4129 gtk_label_select_region (GTK_LABEL (focused_widget), 0, -1);
4130 } else if (GTK_IS_EDITABLE (focused_widget)) {
4131 gtk_editable_select_region (GTK_EDITABLE(focused_widget), 0, -1);
4132 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
4133 GtkTextBuffer *buffer;
4134 GtkTextIter start, end;
4136 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
4137 gtk_text_buffer_get_start_iter (buffer, &start);
4138 gtk_text_buffer_get_end_iter (buffer, &end);
4139 gtk_text_buffer_select_range (buffer, &start, &end);
4140 } else if (GTK_IS_HTML (focused_widget)) {
4141 gtk_html_select_all (GTK_HTML (focused_widget));
4142 } else if (MODEST_IS_MAIN_WINDOW (window)) {
4143 GtkWidget *header_view = focused_widget;
4144 GtkTreeSelection *selection = NULL;
4146 if (!(MODEST_IS_HEADER_VIEW (focused_widget))) {
4147 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (window),
4148 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
4151 /* Disable window dimming management */
4152 modest_window_disable_dimming (MODEST_WINDOW(window));
4154 /* Select all messages */
4155 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(header_view));
4156 gtk_tree_selection_select_all (selection);
4158 /* Set focuse on header view */
4159 gtk_widget_grab_focus (header_view);
4161 /* Enable window dimming management */
4162 modest_window_enable_dimming (MODEST_WINDOW(window));
4163 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (window));
4164 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (window));
4170 modest_ui_actions_on_mark_as_read (GtkAction *action,
4171 ModestWindow *window)
4173 g_return_if_fail (MODEST_IS_WINDOW(window));
4175 /* Mark each header as read */
4176 do_headers_action (window, headers_action_mark_as_read, NULL);
4180 modest_ui_actions_on_mark_as_unread (GtkAction *action,
4181 ModestWindow *window)
4183 g_return_if_fail (MODEST_IS_WINDOW(window));
4185 /* Mark each header as read */
4186 do_headers_action (window, headers_action_mark_as_unread, NULL);
4190 modest_ui_actions_on_change_zoom (GtkRadioAction *action,
4191 GtkRadioAction *selected,
4192 ModestWindow *window)
4196 value = gtk_radio_action_get_current_value (selected);
4197 if (MODEST_IS_WINDOW (window)) {
4198 modest_window_set_zoom (MODEST_WINDOW (window), ((gdouble)value)/100);
4203 modest_ui_actions_msg_edit_on_change_priority (GtkRadioAction *action,
4204 GtkRadioAction *selected,
4205 ModestWindow *window)
4207 TnyHeaderFlags flags;
4208 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4210 flags = gtk_radio_action_get_current_value (selected);
4211 modest_msg_edit_window_set_priority_flags (MODEST_MSG_EDIT_WINDOW (window), flags);
4215 modest_ui_actions_msg_edit_on_change_file_format (GtkRadioAction *action,
4216 GtkRadioAction *selected,
4217 ModestWindow *window)
4221 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4223 file_format = gtk_radio_action_get_current_value (selected);
4224 modest_msg_edit_window_set_file_format (MODEST_MSG_EDIT_WINDOW (window), file_format);
4229 modest_ui_actions_on_zoom_plus (GtkAction *action,
4230 ModestWindow *window)
4232 g_return_if_fail (MODEST_IS_WINDOW (window));
4234 modest_window_zoom_plus (MODEST_WINDOW (window));
4238 modest_ui_actions_on_zoom_minus (GtkAction *action,
4239 ModestWindow *window)
4241 g_return_if_fail (MODEST_IS_WINDOW (window));
4243 modest_window_zoom_minus (MODEST_WINDOW (window));
4247 modest_ui_actions_on_toggle_fullscreen (GtkToggleAction *toggle,
4248 ModestWindow *window)
4250 ModestWindowMgr *mgr;
4251 gboolean fullscreen, active;
4252 g_return_if_fail (MODEST_IS_WINDOW (window));
4254 mgr = modest_runtime_get_window_mgr ();
4256 active = (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle)))?1:0;
4257 fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
4259 if (active != fullscreen) {
4260 modest_window_mgr_set_fullscreen_mode (mgr, active);
4261 #ifndef MODEST_TOOLKIT_HILDON2
4262 gtk_window_present (GTK_WINDOW (window));
4268 modest_ui_actions_on_change_fullscreen (GtkAction *action,
4269 ModestWindow *window)
4271 ModestWindowMgr *mgr;
4272 gboolean fullscreen;
4274 g_return_if_fail (MODEST_IS_WINDOW (window));
4276 mgr = modest_runtime_get_window_mgr ();
4277 fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
4278 modest_window_mgr_set_fullscreen_mode (mgr, !fullscreen);
4280 #ifndef MODEST_TOOLKIT_HILDON2
4281 gtk_window_present (GTK_WINDOW (window));
4286 * Used by modest_ui_actions_on_details to call do_headers_action
4289 headers_action_show_details (TnyHeader *header,
4290 ModestWindow *window,
4294 modest_platform_run_header_details_dialog (GTK_WINDOW (window), header);
4298 * Show the header details in a ModestDetailsDialog widget
4301 modest_ui_actions_on_details (GtkAction *action,
4304 TnyList * headers_list;
4308 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
4311 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW (win));
4314 g_object_unref (msg);
4316 headers_list = get_selected_headers (win);
4320 iter = tny_list_create_iterator (headers_list);
4322 header = TNY_HEADER (tny_iterator_get_current (iter));
4324 headers_action_show_details (header, win, NULL);
4325 g_object_unref (header);
4328 g_object_unref (iter);
4329 g_object_unref (headers_list);
4331 } else if (MODEST_IS_MAIN_WINDOW (win)) {
4332 GtkWidget *folder_view, *header_view;
4334 /* Check which widget has the focus */
4335 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
4336 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
4337 if (gtk_widget_is_focus (folder_view)) {
4338 TnyFolderStore *folder_store
4339 = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
4340 if (!folder_store) {
4341 g_warning ("%s: No item was selected.\n", __FUNCTION__);
4344 /* Show only when it's a folder */
4345 /* This function should not be called for account items,
4346 * because we dim the menu item for them. */
4347 if (TNY_IS_FOLDER (folder_store)) {
4348 modest_platform_run_folder_details_dialog (GTK_WINDOW (win),
4349 TNY_FOLDER (folder_store));
4352 g_object_unref (folder_store);
4355 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
4356 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
4357 /* Show details of each header */
4358 do_headers_action (win, headers_action_show_details, header_view);
4364 modest_ui_actions_on_toggle_show_cc (GtkToggleAction *toggle,
4365 ModestMsgEditWindow *window)
4367 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4369 modest_msg_edit_window_show_cc (window, gtk_toggle_action_get_active (toggle));
4373 modest_ui_actions_on_toggle_show_bcc (GtkToggleAction *toggle,
4374 ModestMsgEditWindow *window)
4376 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4378 modest_msg_edit_window_show_bcc (window, gtk_toggle_action_get_active (toggle));
4382 modest_ui_actions_toggle_folders_view (GtkAction *action,
4383 ModestMainWindow *main_window)
4385 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
4387 if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)))
4388 modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SPLIT);
4390 modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SIMPLE);
4394 modest_ui_actions_on_toggle_toolbar (GtkToggleAction *toggle,
4395 ModestWindow *window)
4397 gboolean active, fullscreen = FALSE;
4398 ModestWindowMgr *mgr;
4400 active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle));
4402 /* Check if we want to toggle the toolbar view in fullscreen
4404 if (!strcmp (gtk_action_get_name (GTK_ACTION (toggle)),
4405 "ViewShowToolbarFullScreen")) {
4409 /* Toggle toolbar */
4410 mgr = modest_runtime_get_window_mgr ();
4411 modest_window_mgr_show_toolbars (mgr, G_TYPE_FROM_INSTANCE (window), active, fullscreen);
4415 modest_ui_actions_msg_edit_on_select_font (GtkAction *action,
4416 ModestMsgEditWindow *window)
4418 modest_msg_edit_window_select_font (window);
4423 modest_ui_actions_on_folder_display_name_changed (ModestFolderView *folder_view,
4424 const gchar *display_name,
4427 /* don't update the display name if it was already set;
4428 * updating the display name apparently is expensive */
4429 const gchar* old_name = gtk_window_get_title (window);
4431 if (display_name == NULL)
4434 if (old_name && display_name && strcmp (old_name, display_name) == 0)
4435 return; /* don't do anything */
4437 /* This is usually used to change the title of the main window, which
4438 * is the one that holds the folder view. Note that this change can
4439 * happen even when the widget doesn't have the focus. */
4440 gtk_window_set_title (window, display_name);
4445 modest_ui_actions_on_select_contacts (GtkAction *action, ModestMsgEditWindow *window)
4447 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4448 modest_msg_edit_window_select_contacts (window);
4452 modest_ui_actions_on_check_names (GtkAction *action, ModestMsgEditWindow *window)
4454 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4455 modest_msg_edit_window_check_names (window, FALSE);
4459 create_move_to_dialog_on_new_folder(GtkWidget *button, gpointer user_data)
4461 modest_ui_actions_create_folder (gtk_widget_get_toplevel (button),
4462 GTK_WIDGET (user_data));
4466 * This function is used to track changes in the selection of the
4467 * folder view that is inside the "move to" dialog to enable/disable
4468 * the OK button because we do not want the user to select a disallowed
4469 * destination for a folder.
4470 * The user also not desired to be able to use NEW button on items where
4471 * folder creation is not possibel.
4474 on_move_to_dialog_folder_selection_changed (ModestFolderView* self,
4475 TnyFolderStore *folder_store,
4479 GtkWidget *dialog = NULL;
4480 GtkWidget *ok_button = NULL, *new_button = NULL;
4481 gboolean ok_sensitive = TRUE, new_sensitive = TRUE;
4482 gboolean moving_folder = FALSE;
4483 gboolean is_local_account = TRUE;
4484 GtkWidget *folder_view = NULL;
4485 ModestTnyFolderRules rules;
4487 g_return_if_fail (MODEST_IS_FOLDER_VIEW(self));
4492 /* Get the OK button */
4493 dialog = gtk_widget_get_ancestor (GTK_WIDGET (self), GTK_TYPE_DIALOG);
4497 ok_button = g_object_get_data (G_OBJECT (dialog), MOVE_FOLDER_OK_BUTTON);
4498 new_button = g_object_get_data (G_OBJECT (dialog), MOVE_FOLDER_NEW_BUTTON);
4500 /* check if folder_store is an remote account */
4501 if (TNY_IS_ACCOUNT (folder_store)) {
4502 TnyAccount *local_account = NULL;
4503 TnyAccount *mmc_account = NULL;
4504 ModestTnyAccountStore *account_store = NULL;
4506 account_store = modest_runtime_get_account_store ();
4507 local_account = modest_tny_account_store_get_local_folders_account (account_store);
4508 mmc_account = modest_tny_account_store_get_mmc_folders_account (account_store);
4510 if ((gpointer) local_account != (gpointer) folder_store &&
4511 (gpointer) mmc_account != (gpointer) folder_store) {
4512 ModestProtocolType proto;
4513 proto = modest_tny_account_get_protocol_type (TNY_ACCOUNT (folder_store));
4514 if (proto == MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
4515 proto = MODEST_PROTOCOLS_STORE_MAILDIR;
4517 is_local_account = FALSE;
4518 /* New button should be dimmed on remote
4520 new_sensitive = (modest_protocol_registry_protocol_type_has_tag (modest_runtime_get_protocol_registry (),
4522 MODEST_PROTOCOL_REGISTRY_STORE_HAS_FOLDERS));
4524 g_object_unref (local_account);
4526 /* It could not exist */
4528 g_object_unref (mmc_account);
4531 /* Check the target folder rules */
4532 if (TNY_IS_FOLDER (folder_store)) {
4533 rules = modest_tny_folder_get_rules (TNY_FOLDER (folder_store));
4534 if (rules & MODEST_FOLDER_RULES_FOLDER_NON_WRITEABLE) {
4535 ok_sensitive = FALSE;
4536 new_sensitive = FALSE;
4541 /* Check if we're moving a folder */
4542 if (MODEST_IS_MAIN_WINDOW (user_data)) {
4543 /* Get the widgets */
4544 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (user_data),
4545 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
4546 if (gtk_widget_is_focus (folder_view))
4547 moving_folder = TRUE;
4550 if (moving_folder) {
4551 TnyFolderStore *moved_folder = NULL, *parent = NULL;
4553 /* Get the folder to move */
4554 moved_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
4556 /* Check that we're not moving to the same folder */
4557 if (TNY_IS_FOLDER (moved_folder)) {
4558 parent = tny_folder_get_folder_store (TNY_FOLDER (moved_folder));
4559 if (parent == folder_store)
4560 ok_sensitive = FALSE;
4561 g_object_unref (parent);
4564 if (ok_sensitive && TNY_IS_ACCOUNT (folder_store)) {
4565 /* Do not allow to move to an account unless it's the
4566 local folders account */
4567 if (!is_local_account)
4568 ok_sensitive = FALSE;
4571 if (ok_sensitive && (moved_folder == folder_store)) {
4572 /* Do not allow to move to itself */
4573 ok_sensitive = FALSE;
4575 g_object_unref (moved_folder);
4577 TnyFolder *src_folder = NULL;
4579 /* Moving a message */
4580 if (MODEST_IS_MSG_VIEW_WINDOW (user_data)) {
4582 TnyHeader *header = NULL;
4583 header = modest_msg_view_window_get_header
4584 (MODEST_MSG_VIEW_WINDOW (user_data));
4585 if (!TNY_IS_HEADER(header))
4586 g_warning ("%s: could not get source header", __FUNCTION__);
4588 src_folder = tny_header_get_folder (header);
4591 g_object_unref (header);
4594 TNY_FOLDER (modest_folder_view_get_selected
4595 (MODEST_FOLDER_VIEW (folder_view)));
4598 if (TNY_IS_FOLDER(src_folder)) {
4599 /* Do not allow to move the msg to the same folder */
4600 /* Do not allow to move the msg to an account */
4601 if ((gpointer) src_folder == (gpointer) folder_store ||
4602 TNY_IS_ACCOUNT (folder_store))
4603 ok_sensitive = FALSE;
4604 g_object_unref (src_folder);
4606 g_warning ("%s: could not get source folder", __FUNCTION__);
4610 /* Set sensitivity of the OK button */
4611 gtk_widget_set_sensitive (ok_button, ok_sensitive);
4612 /* Set sensitivity of the NEW button */
4613 gtk_widget_set_sensitive (new_button, new_sensitive);
4617 #define MODEST_MOVE_TO_DIALOG_FOLDER_VIEW "move-to-dialog-folder-view"
4620 get_folder_view_from_move_to_dialog (GtkWidget *move_to_dialog)
4622 return GTK_WIDGET(g_object_get_data (G_OBJECT(move_to_dialog),
4623 MODEST_MOVE_TO_DIALOG_FOLDER_VIEW));
4627 create_move_to_dialog (GtkWindow *win,
4628 GtkWidget *folder_view,
4629 GtkWidget **tree_view)
4632 #ifdef MODEST_TOOLKIT_HILDON2
4633 GtkWidget *pannable;
4637 GtkWidget *new_button, *ok_button;
4639 dialog = gtk_dialog_new_with_buttons (_("mcen_ti_moveto_folders_title"),
4641 GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR | GTK_DIALOG_DESTROY_WITH_PARENT,
4644 #ifndef MODEST_TOOLKIT_GTK
4645 ok_button = gtk_dialog_add_button (GTK_DIALOG (dialog), _("mcen_bd_dialog_ok"), GTK_RESPONSE_ACCEPT);
4646 /* We do this manually so GTK+ does not associate a response ID for
4648 new_button = gtk_button_new_from_stock (_("mcen_bd_new"));
4649 gtk_box_pack_end (GTK_BOX (GTK_DIALOG (dialog)->action_area), new_button, FALSE, FALSE, 0);
4650 gtk_widget_show (new_button);
4651 #ifndef MODEST_TOOLKIT_HILDON2
4652 gtk_dialog_add_button (GTK_DIALOG (dialog), _("mcen_bd_dialog_cancel"), GTK_RESPONSE_REJECT);
4655 /* We do this manually so GTK+ does not associate a response ID for
4657 new_button = gtk_button_new_with_label (_("mcen_ti_new_folder"));
4658 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area), new_button, FALSE, FALSE, 0);
4659 gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (GTK_DIALOG (dialog)->action_area), new_button, TRUE);
4660 gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT);
4661 ok_button = gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_OK, GTK_RESPONSE_ACCEPT);
4662 gtk_container_set_border_width (GTK_CONTAINER (dialog), 12);
4663 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 24);
4665 g_object_set_data (G_OBJECT (dialog), MOVE_FOLDER_OK_BUTTON, ok_button);
4666 g_object_set_data (G_OBJECT (dialog), MOVE_FOLDER_NEW_BUTTON, new_button);
4668 /* Create scrolled window */
4669 #ifdef MODEST_TOOLKIT_HILDON2
4670 pannable = hildon_pannable_area_new ();
4672 scroll = gtk_scrolled_window_new (NULL, NULL);
4673 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll),
4674 GTK_POLICY_AUTOMATIC,
4675 GTK_POLICY_AUTOMATIC);
4678 #ifdef MODEST_TOOLKIT_GTK
4679 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scroll), GTK_SHADOW_IN);
4682 /* Create folder view */
4683 *tree_view = modest_platform_create_folder_view (NULL);
4685 /* Track changes in the selection to
4686 * disable the OK button whenever "Move to" is not possible
4687 * disbale NEW button whenever New is not possible */
4688 g_signal_connect (*tree_view,
4689 "folder_selection_changed",
4690 G_CALLBACK (on_move_to_dialog_folder_selection_changed),
4693 /* Listen to clicks on New button */
4694 g_signal_connect (G_OBJECT (new_button),
4696 G_CALLBACK(create_move_to_dialog_on_new_folder),
4699 /* It could happen that we're trying to move a message from a
4700 window (msg window for example) after the main window was
4701 closed, so we can not just get the model of the folder
4703 if (MODEST_IS_FOLDER_VIEW (folder_view)) {
4704 const gchar *visible_id = NULL;
4706 modest_folder_view_set_style (MODEST_FOLDER_VIEW (*tree_view),
4707 MODEST_FOLDER_VIEW_STYLE_SHOW_ALL);
4708 modest_folder_view_copy_model (MODEST_FOLDER_VIEW(folder_view),
4709 MODEST_FOLDER_VIEW(*tree_view));
4712 modest_folder_view_get_account_id_of_visible_server_account (MODEST_FOLDER_VIEW(folder_view));
4714 /* Show the same account than the one that is shown in the main window */
4715 modest_folder_view_set_account_id_of_visible_server_account (MODEST_FOLDER_VIEW(*tree_view),
4718 const gchar *active_account_name = NULL;
4719 ModestAccountMgr *mgr = NULL;
4720 ModestAccountSettings *settings = NULL;
4721 ModestServerAccountSettings *store_settings = NULL;
4723 modest_folder_view_set_style (MODEST_FOLDER_VIEW (*tree_view),
4724 MODEST_FOLDER_VIEW_STYLE_SHOW_ALL);
4725 modest_folder_view_update_model (MODEST_FOLDER_VIEW (*tree_view),
4726 TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()));
4728 active_account_name = modest_window_get_active_account (MODEST_WINDOW (win));
4729 mgr = modest_runtime_get_account_mgr ();
4730 settings = modest_account_mgr_load_account_settings (mgr, active_account_name);
4733 const gchar *store_account_name;
4734 store_settings = modest_account_settings_get_store_settings (settings);
4735 store_account_name = modest_server_account_settings_get_account_name (store_settings);
4737 modest_folder_view_set_account_id_of_visible_server_account (MODEST_FOLDER_VIEW (*tree_view),
4738 store_account_name);
4739 g_object_unref (store_settings);
4740 g_object_unref (settings);
4744 /* we keep a pointer to the embedded folder view, so we can retrieve it with
4745 * get_folder_view_from_move_to_dialog
4746 * (see above) later (needed for focus handling)
4748 g_object_set_data (G_OBJECT(dialog), MODEST_MOVE_TO_DIALOG_FOLDER_VIEW, *tree_view);
4751 /* Hide special folders */
4752 modest_folder_view_show_non_move_folders (MODEST_FOLDER_VIEW (*tree_view), FALSE);
4754 #ifdef MODEST_TOOLKIT_HILDON2
4755 gtk_container_add (GTK_CONTAINER (pannable), *tree_view);
4756 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
4757 pannable, TRUE, TRUE, 0);
4759 gtk_container_add (GTK_CONTAINER (scroll), *tree_view);
4760 /* Add scroll to dialog */
4761 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
4762 scroll, TRUE, TRUE, 0);
4766 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
4767 #ifndef MODEST_TOOLKIT_GTK
4768 gtk_window_set_default_size (GTK_WINDOW (dialog), 300, 300);
4770 gtk_window_set_default_size (GTK_WINDOW (dialog), 600, 400);
4779 * Shows a confirmation dialog to the user when we're moving messages
4780 * from a remote server to the local storage. Returns the dialog
4781 * response. If it's other kind of movement then it always returns
4784 * This one is used by the next functions:
4785 * modest_ui_actions_on_paste - commented out
4786 * drag_and_drop_from_header_view (for d&d in modest_folder_view.c)
4789 modest_ui_actions_msgs_move_to_confirmation (ModestWindow *win,
4790 TnyFolder *dest_folder,
4794 gint response = GTK_RESPONSE_OK;
4795 TnyAccount *account = NULL;
4796 TnyFolder *src_folder = NULL;
4797 TnyIterator *iter = NULL;
4798 TnyHeader *header = NULL;
4800 /* return with OK if the destination is a remote folder */
4801 if (modest_tny_folder_is_remote_folder (dest_folder))
4802 return GTK_RESPONSE_OK;
4804 /* Get source folder */
4805 iter = tny_list_create_iterator (headers);
4806 header = TNY_HEADER (tny_iterator_get_current (iter));
4808 src_folder = tny_header_get_folder (header);
4809 g_object_unref (header);
4811 g_object_unref (iter);
4813 /* if no src_folder, message may be an attahcment */
4814 if (src_folder == NULL)
4815 return GTK_RESPONSE_CANCEL;
4817 /* If the source is a local or MMC folder */
4818 if (!modest_tny_folder_is_remote_folder (src_folder)) {
4819 g_object_unref (src_folder);
4820 return GTK_RESPONSE_OK;
4823 /* Get the account */
4824 account = tny_folder_get_account (src_folder);
4826 /* now if offline we ask the user */
4827 if(connect_to_get_msg (win, tny_list_get_length (headers), account))
4828 response = GTK_RESPONSE_OK;
4830 response = GTK_RESPONSE_CANCEL;
4833 g_object_unref (src_folder);
4834 g_object_unref (account);
4840 move_to_helper_destroyer (gpointer user_data)
4842 MoveToHelper *helper = (MoveToHelper *) user_data;
4844 /* Close the "Pasting" information banner */
4845 if (helper->banner) {
4846 gtk_widget_destroy (GTK_WIDGET (helper->banner));
4847 g_object_unref (helper->banner);
4849 if (gtk_tree_row_reference_valid (helper->reference)) {
4850 gtk_tree_row_reference_free (helper->reference);
4851 helper->reference = NULL;
4857 move_to_cb (ModestMailOperation *mail_op,
4860 MoveToHelper *helper = (MoveToHelper *) user_data;
4862 /* Note that the operation could have failed, in that case do
4864 if (modest_mail_operation_get_status (mail_op) ==
4865 MODEST_MAIL_OPERATION_STATUS_SUCCESS) {
4867 GObject *object = modest_mail_operation_get_source (mail_op);
4868 if (MODEST_IS_MSG_VIEW_WINDOW (object)) {
4869 ModestMsgViewWindow *self = MODEST_MSG_VIEW_WINDOW (object);
4871 if (!modest_msg_view_window_select_next_message (self) &&
4872 !modest_msg_view_window_select_previous_message (self)) {
4873 /* No more messages to view, so close this window */
4874 modest_ui_actions_on_close_window (NULL, MODEST_WINDOW(self));
4876 } else if (MODEST_IS_MAIN_WINDOW (object) &&
4877 gtk_tree_row_reference_valid (helper->reference)) {
4878 GtkWidget *header_view;
4880 GtkTreeSelection *sel;
4882 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(object),
4883 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
4884 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
4885 path = gtk_tree_row_reference_get_path (helper->reference);
4886 /* We need to unselect the previous one
4887 because we could be copying instead of
4889 gtk_tree_selection_unselect_all (sel);
4890 gtk_tree_selection_select_path (sel, path);
4891 gtk_tree_path_free (path);
4893 g_object_unref (object);
4895 /* Destroy the helper */
4896 move_to_helper_destroyer (helper);
4900 folder_move_to_cb (ModestMailOperation *mail_op,
4901 TnyFolder *new_folder,
4904 GtkWidget *folder_view;
4907 object = modest_mail_operation_get_source (mail_op);
4908 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(object),
4909 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
4910 g_object_ref (folder_view);
4911 g_object_unref (object);
4912 move_to_cb (mail_op, user_data);
4913 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view), new_folder, FALSE);
4914 g_object_unref (folder_view);
4918 msgs_move_to_cb (ModestMailOperation *mail_op,
4921 move_to_cb (mail_op, user_data);
4925 modest_ui_actions_move_folder_error_handler (ModestMailOperation *mail_op,
4928 ModestWindow *main_window = NULL;
4930 /* Disable next automatic folder selection */
4931 main_window = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (),
4932 FALSE); /* don't create */
4934 GObject *win = NULL;
4935 GtkWidget *folder_view = NULL;
4937 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (main_window),
4938 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
4939 modest_folder_view_disable_next_folder_selection (MODEST_FOLDER_VIEW(folder_view));
4941 if (user_data && TNY_IS_FOLDER (user_data)) {
4942 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view),
4943 TNY_FOLDER (user_data), FALSE);
4946 /* Show notification dialog only if the main window exists */
4947 win = modest_mail_operation_get_source (mail_op);
4948 modest_platform_run_information_dialog ((GtkWindow *) win,
4949 _("mail_in_ui_folder_move_target_error"),
4952 g_object_unref (win);
4957 open_msg_for_purge_cb (ModestMailOperation *mail_op,
4966 gint pending_purges = 0;
4967 gboolean some_purged = FALSE;
4968 ModestWindow *win = MODEST_WINDOW (user_data);
4969 ModestWindowMgr *mgr = modest_runtime_get_window_mgr ();
4971 /* If there was any error */
4972 if (!modest_ui_actions_msg_retrieval_check (mail_op, header, msg)) {
4973 modest_window_mgr_unregister_header (mgr, header);
4977 /* Once the message has been retrieved for purging, we check if
4978 * it's all ok for purging */
4980 parts = tny_simple_list_new ();
4981 tny_mime_part_get_parts (TNY_MIME_PART (msg), parts);
4982 iter = tny_list_create_iterator (parts);
4984 while (!tny_iterator_is_done (iter)) {
4986 part = TNY_MIME_PART (tny_iterator_get_current (iter));
4987 if (part && (tny_mime_part_is_attachment (part) || TNY_IS_MSG (part))) {
4988 if (tny_mime_part_is_purged (part))
4995 g_object_unref (part);
4997 tny_iterator_next (iter);
4999 g_object_unref (iter);
5002 if (pending_purges>0) {
5004 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),_("mcen_nc_purge_file_text_inbox"));
5006 if (response == GTK_RESPONSE_OK) {
5009 modest_platform_animation_banner (GTK_WIDGET (win), NULL, _("mcen_ib_removing_attachment"));
5010 iter = tny_list_create_iterator (parts);
5011 while (!tny_iterator_is_done (iter)) {
5014 part = TNY_MIME_PART (tny_iterator_get_current (iter));
5015 if (part && (tny_mime_part_is_attachment (part) || TNY_IS_MSG (part)))
5016 tny_mime_part_set_purged (part);
5019 g_object_unref (part);
5021 tny_iterator_next (iter);
5023 g_object_unref (iter);
5025 tny_msg_rewrite_cache (msg);
5027 gtk_widget_destroy (info);
5031 modest_window_mgr_unregister_header (mgr, header);
5033 g_object_unref (parts);
5037 modest_ui_actions_on_main_window_remove_attachments (GtkAction *action,
5038 ModestMainWindow *win)
5040 GtkWidget *header_view;
5041 TnyList *header_list;
5043 TnyHeaderFlags flags;
5044 ModestWindow *msg_view_window = NULL;
5047 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win));
5049 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
5050 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
5052 header_list = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW (header_view));
5054 g_warning ("%s: no header selected", __FUNCTION__);
5058 if (tny_list_get_length (header_list) == 1) {
5059 TnyIterator *iter = tny_list_create_iterator (header_list);
5060 header = TNY_HEADER (tny_iterator_get_current (iter));
5061 g_object_unref (iter);
5065 if (!header || !TNY_IS_HEADER(header)) {
5066 g_warning ("%s: header is not valid", __FUNCTION__);
5070 found = modest_window_mgr_find_registered_header (modest_runtime_get_window_mgr (),
5071 header, &msg_view_window);
5072 flags = tny_header_get_flags (header);
5073 if (!(flags & TNY_HEADER_FLAG_CACHED))
5076 if (msg_view_window != NULL)
5077 modest_msg_view_window_remove_attachments (MODEST_MSG_VIEW_WINDOW (msg_view_window), TRUE);
5079 /* do nothing; uid was registered before, so window is probably on it's way */
5080 g_warning ("debug: header %p has already been registered", header);
5083 ModestMailOperation *mail_op = NULL;
5084 modest_window_mgr_register_header (modest_runtime_get_window_mgr (), header, NULL);
5085 mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT (win),
5086 modest_ui_actions_disk_operations_error_handler,
5088 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
5089 modest_mail_operation_get_msg (mail_op, header, FALSE, open_msg_for_purge_cb, win);
5091 g_object_unref (mail_op);
5094 g_object_unref (header);
5096 g_object_unref (header_list);
5100 * Checks if we need a connection to do the transfer and if the user
5101 * wants to connect to complete it
5104 modest_ui_actions_xfer_messages_check (GtkWindow *parent_window,
5105 TnyFolderStore *src_folder,
5107 TnyFolder *dst_folder,
5108 gboolean delete_originals,
5109 gboolean *need_connection,
5112 TnyAccount *src_account;
5113 gint uncached_msgs = 0;
5115 uncached_msgs = header_list_count_uncached_msgs (headers);
5117 /* We don't need any further check if
5119 * 1- the source folder is local OR
5120 * 2- the device is already online
5122 if (!modest_tny_folder_store_is_remote (src_folder) ||
5123 tny_device_is_online (modest_runtime_get_device())) {
5124 *need_connection = FALSE;
5129 /* We must ask for a connection when
5131 * - the message(s) is not already cached OR
5132 * - the message(s) is cached but the leave_on_server setting
5133 * is FALSE (because we need to sync the source folder to
5134 * delete the message from the server (for IMAP we could do it
5135 * offline, it'll take place the next time we get a
5138 src_account = get_account_from_folder_store (src_folder);
5139 if (uncached_msgs > 0) {
5143 *need_connection = TRUE;
5144 num_headers = tny_list_get_length (headers);
5145 msg = ngettext ("mcen_nc_get_msg", "mcen_nc_get_msgs", num_headers);
5147 if (modest_platform_run_confirmation_dialog (parent_window, msg) ==
5148 GTK_RESPONSE_CANCEL) {
5154 /* The transfer is possible and the user wants to */
5157 if (remote_folder_has_leave_on_server (src_folder) && delete_originals) {
5158 const gchar *account_name;
5159 gboolean leave_on_server;
5161 account_name = modest_tny_account_get_parent_modest_account_name_for_server_account (src_account);
5162 leave_on_server = modest_account_mgr_get_leave_on_server (modest_runtime_get_account_mgr (),
5165 if (leave_on_server == TRUE) {
5166 *need_connection = FALSE;
5168 *need_connection = TRUE;
5171 *need_connection = FALSE;
5176 g_object_unref (src_account);
5180 xfer_messages_error_handler (ModestMailOperation *mail_op,
5183 ModestWindow *main_window = NULL;
5185 /* Disable next automatic folder selection */
5186 main_window = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (),
5187 FALSE); /* don't create */
5189 GObject *win = modest_mail_operation_get_source (mail_op);
5190 modest_platform_run_information_dialog ((GtkWindow *) win,
5191 _("mail_in_ui_folder_move_target_error"),
5194 g_object_unref (win);
5196 move_to_helper_destroyer (user_data);
5200 TnyFolderStore *dst_folder;
5205 * Utility function that transfer messages from both the main window
5206 * and the msg view window when using the "Move to" dialog
5209 xfer_messages_performer (gboolean canceled,
5211 GtkWindow *parent_window,
5212 TnyAccount *account,
5215 ModestWindow *win = MODEST_WINDOW (parent_window);
5216 TnyAccount *dst_account = NULL;
5217 gboolean dst_forbids_message_add = FALSE;
5218 XferMsgsHelper *helper;
5219 MoveToHelper *movehelper;
5220 ModestMailOperation *mail_op;
5222 helper = (XferMsgsHelper *) user_data;
5224 if (canceled || err) {
5225 if (!check_memory_full_error ((GtkWidget *) parent_window, err)) {
5226 /* Show the proper error message */
5227 modest_ui_actions_on_account_connection_error (parent_window, account);
5232 dst_account = tny_folder_get_account (TNY_FOLDER (helper->dst_folder));
5234 /* tinymail will return NULL for local folders it seems */
5235 dst_forbids_message_add = modest_protocol_registry_protocol_type_has_tag (modest_runtime_get_protocol_registry (),
5236 modest_tny_account_get_protocol_type (dst_account),
5237 MODEST_PROTOCOL_REGISTRY_STORE_FORBID_MESSAGE_ADD);
5238 g_object_unref (dst_account);
5240 if (dst_forbids_message_add) {
5241 modest_platform_information_banner (GTK_WIDGET (win),
5243 ngettext("mail_in_ui_folder_move_target_error",
5244 "mail_in_ui_folder_move_targets_error",
5245 tny_list_get_length (helper->headers)));
5249 movehelper = g_new0 (MoveToHelper, 1);
5250 movehelper->banner = modest_platform_animation_banner (GTK_WIDGET (win), NULL,
5251 _CS("ckct_nw_pasting"));
5252 if (movehelper->banner != NULL) {
5253 g_object_ref (movehelper->banner);
5254 gtk_widget_show (GTK_WIDGET (movehelper->banner));
5257 if (MODEST_IS_MAIN_WINDOW (win)) {
5258 GtkWidget *header_view =
5259 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
5260 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
5261 movehelper->reference = get_next_after_selected_headers (MODEST_HEADER_VIEW (header_view));
5264 /* Perform the mail operation */
5265 mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT(win),
5266 xfer_messages_error_handler,
5268 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
5271 modest_mail_operation_xfer_msgs (mail_op,
5273 TNY_FOLDER (helper->dst_folder),
5278 g_object_unref (G_OBJECT (mail_op));
5280 g_object_unref (helper->dst_folder);
5281 g_object_unref (helper->headers);
5282 g_slice_free (XferMsgsHelper, helper);
5286 TnyFolder *src_folder;
5287 TnyFolderStore *dst_folder;
5288 gboolean delete_original;
5289 GtkWidget *folder_view;
5293 on_move_folder_cb (gboolean canceled, GError *err, GtkWindow *parent_window,
5294 TnyAccount *account, gpointer user_data)
5296 MoveFolderInfo *info = (MoveFolderInfo*)user_data;
5297 GtkTreeSelection *sel;
5298 ModestMailOperation *mail_op = NULL;
5300 if (canceled || err || !MODEST_IS_MAIN_WINDOW (parent_window)) {
5301 g_object_unref (G_OBJECT (info->src_folder));
5302 g_object_unref (G_OBJECT (info->dst_folder));
5307 MoveToHelper *helper = g_new0 (MoveToHelper, 1);
5308 helper->banner = modest_platform_animation_banner (GTK_WIDGET (parent_window), NULL,
5309 _CS("ckct_nw_pasting"));
5310 if (helper->banner != NULL) {
5311 g_object_ref (helper->banner);
5312 gtk_widget_show (GTK_WIDGET(helper->banner));
5314 /* Clean folder on header view before moving it */
5315 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (info->folder_view));
5316 gtk_tree_selection_unselect_all (sel);
5318 /* Let gtk events run. We need that the folder
5319 view frees its reference to the source
5320 folder *before* issuing the mail operation
5321 so we need the signal handler of selection
5322 changed to happen before the mail
5324 while (gtk_events_pending ())
5325 gtk_main_iteration (); */
5328 modest_mail_operation_new_with_error_handling (G_OBJECT(parent_window),
5329 modest_ui_actions_move_folder_error_handler,
5330 info->src_folder, NULL);
5331 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
5334 /* Select *after* the changes */
5335 /* TODO: this function hangs UI after transfer */
5336 /* modest_folder_view_select_folder (MODEST_FOLDER_VIEW(folder_view), */
5337 /* TNY_FOLDER (src_folder), TRUE); */
5339 modest_folder_view_select_folder (MODEST_FOLDER_VIEW(info->folder_view),
5340 TNY_FOLDER (info->dst_folder), TRUE);
5341 modest_mail_operation_xfer_folder (mail_op,
5342 TNY_FOLDER (info->src_folder),
5344 info->delete_original,
5347 g_object_unref (G_OBJECT (info->src_folder));
5349 /* if (modest_mail_operation_get_status (mail_op) == MODEST_MAIL_OPERATION_STATUS_SUCCESS) { */
5352 /* Unref mail operation */
5353 g_object_unref (G_OBJECT (mail_op));
5354 g_object_unref (G_OBJECT (info->dst_folder));
5359 get_account_from_folder_store (TnyFolderStore *folder_store)
5361 if (TNY_IS_ACCOUNT (folder_store))
5362 return g_object_ref (folder_store);
5364 return tny_folder_get_account (TNY_FOLDER (folder_store));
5368 * UI handler for the "Move to" action when invoked from the
5372 modest_ui_actions_on_main_window_move_to (GtkAction *action,
5373 GtkWidget *folder_view,
5374 TnyFolderStore *dst_folder,
5375 ModestMainWindow *win)
5377 ModestHeaderView *header_view = NULL;
5378 TnyFolderStore *src_folder = NULL;
5380 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win));
5382 /* Get the source folder */
5383 src_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
5385 /* Get header view */
5386 header_view = MODEST_HEADER_VIEW(modest_main_window_get_child_widget (win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW));
5388 /* Get folder or messages to transfer */
5389 if (gtk_widget_is_focus (folder_view)) {
5390 gboolean do_xfer = TRUE;
5392 /* Allow only to transfer folders to the local root folder */
5393 if (TNY_IS_ACCOUNT (dst_folder) &&
5394 !MODEST_IS_TNY_LOCAL_FOLDERS_ACCOUNT (dst_folder) &&
5395 !modest_tny_account_is_memory_card_account (TNY_ACCOUNT (dst_folder))) {
5397 } else if (!TNY_IS_FOLDER (src_folder)) {
5398 g_warning ("%s: src_folder is not a TnyFolder.\n", __FUNCTION__);
5403 MoveFolderInfo *info = g_new0 (MoveFolderInfo, 1);
5404 DoubleConnectionInfo *connect_info = g_slice_new (DoubleConnectionInfo);
5406 info->src_folder = g_object_ref (src_folder);
5407 info->dst_folder = g_object_ref (dst_folder);
5408 info->delete_original = TRUE;
5409 info->folder_view = folder_view;
5411 connect_info->callback = on_move_folder_cb;
5412 connect_info->dst_account = get_account_from_folder_store (TNY_FOLDER_STORE (dst_folder));
5413 connect_info->data = info;
5415 modest_platform_double_connect_and_perform(GTK_WINDOW (win), TRUE,
5416 TNY_FOLDER_STORE (src_folder),
5419 } else if (gtk_widget_is_focus (GTK_WIDGET(header_view))) {
5422 headers = modest_header_view_get_selected_headers(header_view);
5424 /* Transfer the messages */
5425 modest_ui_actions_transfer_messages_helper (GTK_WINDOW (win), TNY_FOLDER (src_folder),
5426 headers, TNY_FOLDER (dst_folder));
5428 g_object_unref (headers);
5432 g_object_unref (src_folder);
5437 modest_ui_actions_transfer_messages_helper (GtkWindow *win,
5438 TnyFolder *src_folder,
5440 TnyFolder *dst_folder)
5442 gboolean need_connection = TRUE;
5443 gboolean do_xfer = TRUE;
5444 XferMsgsHelper *helper;
5446 g_return_if_fail (TNY_IS_FOLDER (src_folder));
5447 g_return_if_fail (TNY_IS_FOLDER (dst_folder));
5448 g_return_if_fail (TNY_IS_LIST (headers));
5450 modest_ui_actions_xfer_messages_check (win, TNY_FOLDER_STORE (src_folder),
5451 headers, TNY_FOLDER (dst_folder),
5452 TRUE, &need_connection,
5455 /* If we don't want to transfer just return */
5459 /* Create the helper */
5460 helper = g_slice_new (XferMsgsHelper);
5461 helper->dst_folder = g_object_ref (dst_folder);
5462 helper->headers = g_object_ref (headers);
5464 if (need_connection) {
5465 DoubleConnectionInfo *connect_info = g_slice_new (DoubleConnectionInfo);
5466 connect_info->callback = xfer_messages_performer;
5467 connect_info->dst_account = tny_folder_get_account (TNY_FOLDER (dst_folder));
5468 connect_info->data = helper;
5470 modest_platform_double_connect_and_perform(GTK_WINDOW (win), TRUE,
5471 TNY_FOLDER_STORE (src_folder),
5474 TnyAccount *src_account = get_account_from_folder_store (TNY_FOLDER_STORE (src_folder));
5475 xfer_messages_performer (FALSE, NULL, GTK_WINDOW (win),
5476 src_account, helper);
5477 g_object_unref (src_account);
5482 * UI handler for the "Move to" action when invoked from the
5483 * ModestMsgViewWindow
5486 modest_ui_actions_on_msg_view_window_move_to (GtkAction *action,
5487 TnyFolderStore *dst_folder,
5488 ModestMsgViewWindow *win)
5490 TnyList *headers = NULL;
5491 TnyHeader *header = NULL;
5492 TnyFolder *src_folder = NULL;
5494 g_return_if_fail (TNY_IS_FOLDER (dst_folder));
5496 /* Create header list */
5497 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
5498 src_folder = TNY_FOLDER (tny_header_get_folder(header));
5499 headers = tny_simple_list_new ();
5500 tny_list_append (headers, G_OBJECT (header));
5502 /* Transfer the messages */
5503 modest_ui_actions_transfer_messages_helper (GTK_WINDOW (win), src_folder, headers,
5504 TNY_FOLDER (dst_folder));
5507 g_object_unref (src_folder);
5508 g_object_unref (header);
5509 g_object_unref (headers);
5513 modest_ui_actions_on_move_to (GtkAction *action,
5516 GtkWidget *dialog = NULL, *folder_view = NULL, *tree_view = NULL;
5518 TnyFolderStore *dst_folder = NULL;
5519 ModestMainWindow *main_window;
5521 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win) ||
5522 MODEST_IS_MSG_VIEW_WINDOW (win));
5524 /* Get the main window if exists */
5525 if (MODEST_IS_MAIN_WINDOW (win))
5526 main_window = MODEST_MAIN_WINDOW (win);
5529 MODEST_MAIN_WINDOW (modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (),
5530 FALSE)); /* don't create */
5532 /* Get the folder view widget if exists */
5534 folder_view = modest_main_window_get_child_widget (main_window,
5535 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
5539 /* Create and run the dialog */
5540 dialog = create_move_to_dialog (GTK_WINDOW (win), folder_view, &tree_view);
5541 modest_folder_view_select_first_inbox_or_local (MODEST_FOLDER_VIEW (tree_view));
5542 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (dialog), (GtkWindow *) win);
5543 result = gtk_dialog_run (GTK_DIALOG(dialog));
5544 g_object_ref (tree_view);
5545 gtk_widget_destroy (dialog);
5547 if (result != GTK_RESPONSE_ACCEPT)
5550 dst_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (tree_view));
5551 /* Do window specific stuff */
5552 if (MODEST_IS_MAIN_WINDOW (win)) {
5553 modest_ui_actions_on_main_window_move_to (action,
5556 MODEST_MAIN_WINDOW (win));
5558 modest_ui_actions_on_msg_view_window_move_to (action,
5560 MODEST_MSG_VIEW_WINDOW (win));
5564 g_object_unref (dst_folder);
5568 * Calls #HeadersFunc for each header already selected in the main
5569 * window or the message currently being shown in the msg view window
5572 do_headers_action (ModestWindow *win,
5576 TnyList *headers_list = NULL;
5577 TnyIterator *iter = NULL;
5578 TnyHeader *header = NULL;
5579 TnyFolder *folder = NULL;
5582 headers_list = get_selected_headers (win);
5586 /* Get the folder */
5587 iter = tny_list_create_iterator (headers_list);
5588 header = TNY_HEADER (tny_iterator_get_current (iter));
5590 folder = tny_header_get_folder (header);
5591 g_object_unref (header);
5594 /* Call the function for each header */
5595 while (!tny_iterator_is_done (iter)) {
5596 header = TNY_HEADER (tny_iterator_get_current (iter));
5597 func (header, win, user_data);
5598 g_object_unref (header);
5599 tny_iterator_next (iter);
5602 /* Trick: do a poke status in order to speed up the signaling
5604 tny_folder_poke_status (folder);
5607 g_object_unref (folder);
5608 g_object_unref (iter);
5609 g_object_unref (headers_list);
5613 modest_ui_actions_view_attachment (GtkAction *action,
5614 ModestWindow *window)
5616 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
5617 modest_msg_view_window_view_attachment (MODEST_MSG_VIEW_WINDOW (window), NULL);
5619 /* not supported window for this action */
5620 g_return_if_reached ();
5625 modest_ui_actions_save_attachments (GtkAction *action,
5626 ModestWindow *window)
5628 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
5630 if (modest_platform_check_memory_low (MODEST_WINDOW(window), TRUE))
5633 modest_msg_view_window_save_attachments (MODEST_MSG_VIEW_WINDOW (window), NULL);
5635 /* not supported window for this action */
5636 g_return_if_reached ();
5641 modest_ui_actions_remove_attachments (GtkAction *action,
5642 ModestWindow *window)
5644 if (MODEST_IS_MAIN_WINDOW (window)) {
5645 modest_ui_actions_on_main_window_remove_attachments (action, MODEST_MAIN_WINDOW (window));
5646 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
5647 modest_msg_view_window_remove_attachments (MODEST_MSG_VIEW_WINDOW (window), FALSE);
5649 /* not supported window for this action */
5650 g_return_if_reached ();
5655 modest_ui_actions_on_settings (GtkAction *action,
5660 dialog = modest_platform_get_global_settings_dialog ();
5661 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (win));
5662 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
5663 gtk_widget_show_all (dialog);
5665 gtk_dialog_run (GTK_DIALOG (dialog));
5667 gtk_widget_destroy (dialog);
5671 modest_ui_actions_on_help (GtkAction *action,
5674 const gchar *help_id;
5676 g_return_if_fail (win && GTK_IS_WINDOW(win));
5678 help_id = modest_window_mgr_get_help_id (modest_runtime_get_window_mgr(), win);
5681 modest_platform_show_help (GTK_WINDOW (win), help_id);
5685 modest_ui_actions_on_csm_help (GtkAction *action,
5688 const gchar* help_id = NULL;
5689 GtkWidget *folder_view;
5690 TnyFolderStore *folder_store;
5692 g_return_if_fail (win && MODEST_IS_MAIN_WINDOW (win));
5694 /* Get selected folder */
5695 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
5696 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
5697 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
5699 /* Switch help_id */
5700 if (folder_store && TNY_IS_FOLDER (folder_store))
5701 help_id = modest_tny_folder_get_help_id (TNY_FOLDER (folder_store));
5704 g_object_unref (folder_store);
5707 modest_platform_show_help (GTK_WINDOW (win), help_id);
5709 modest_ui_actions_on_help (action, win);
5713 retrieve_contents_cb (ModestMailOperation *mail_op,
5720 /* We only need this callback to show an error in case of
5721 memory low condition */
5722 modest_ui_actions_msg_retrieval_check (mail_op, header, msg);
5726 retrieve_msg_contents_performer (gboolean canceled,
5728 GtkWindow *parent_window,
5729 TnyAccount *account,
5732 ModestMailOperation *mail_op;
5733 TnyList *headers = TNY_LIST (user_data);
5735 if (err || canceled) {
5736 check_memory_full_error ((GtkWidget *) parent_window, err);
5740 /* Create mail operation */
5741 mail_op = modest_mail_operation_new_with_error_handling ((GObject *) parent_window,
5742 modest_ui_actions_disk_operations_error_handler,
5744 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
5745 modest_mail_operation_get_msgs_full (mail_op, headers, retrieve_contents_cb, NULL, NULL);
5748 g_object_unref (mail_op);
5750 g_object_unref (headers);
5751 g_object_unref (account);
5755 modest_ui_actions_on_retrieve_msg_contents (GtkAction *action,
5756 ModestWindow *window)
5758 TnyList *headers = NULL;
5759 TnyAccount *account = NULL;
5760 TnyIterator *iter = NULL;
5761 TnyHeader *header = NULL;
5762 TnyFolder *folder = NULL;
5765 headers = get_selected_headers (window);
5769 /* Pick the account */
5770 iter = tny_list_create_iterator (headers);
5771 header = TNY_HEADER (tny_iterator_get_current (iter));
5772 folder = tny_header_get_folder (header);
5773 account = tny_folder_get_account (folder);
5774 g_object_unref (folder);
5775 g_object_unref (header);
5776 g_object_unref (iter);
5778 /* Connect and perform the message retrieval */
5779 modest_platform_connect_and_perform ((GtkWindow *) window, TRUE,
5780 g_object_ref (account),
5781 retrieve_msg_contents_performer,
5782 g_object_ref (headers));
5785 g_object_unref (account);
5786 g_object_unref (headers);
5790 modest_ui_actions_check_toolbar_dimming_rules (ModestWindow *window)
5792 g_return_if_fail (MODEST_IS_WINDOW (window));
5795 modest_window_check_dimming_rules_group (window, MODEST_DIMMING_RULES_TOOLBAR);
5799 modest_ui_actions_check_menu_dimming_rules (ModestWindow *window)
5801 g_return_if_fail (MODEST_IS_WINDOW (window));
5804 modest_window_check_dimming_rules_group (window, MODEST_DIMMING_RULES_MENU);
5808 modest_ui_actions_on_email_menu_activated (GtkAction *action,
5809 ModestWindow *window)
5811 g_return_if_fail (MODEST_IS_WINDOW (window));
5814 modest_ui_actions_check_menu_dimming_rules (window);
5818 modest_ui_actions_on_edit_menu_activated (GtkAction *action,
5819 ModestWindow *window)
5821 g_return_if_fail (MODEST_IS_WINDOW (window));
5824 modest_ui_actions_check_menu_dimming_rules (window);
5828 modest_ui_actions_on_view_menu_activated (GtkAction *action,
5829 ModestWindow *window)
5831 g_return_if_fail (MODEST_IS_WINDOW (window));
5834 modest_ui_actions_check_menu_dimming_rules (window);
5838 modest_ui_actions_on_format_menu_activated (GtkAction *action,
5839 ModestWindow *window)
5841 g_return_if_fail (MODEST_IS_WINDOW (window));
5844 modest_ui_actions_check_menu_dimming_rules (window);
5848 modest_ui_actions_on_tools_menu_activated (GtkAction *action,
5849 ModestWindow *window)
5851 g_return_if_fail (MODEST_IS_WINDOW (window));
5854 modest_ui_actions_check_menu_dimming_rules (window);
5858 modest_ui_actions_on_attachment_menu_activated (GtkAction *action,
5859 ModestWindow *window)
5861 g_return_if_fail (MODEST_IS_WINDOW (window));
5864 modest_ui_actions_check_menu_dimming_rules (window);
5868 modest_ui_actions_on_toolbar_csm_menu_activated (GtkAction *action,
5869 ModestWindow *window)
5871 g_return_if_fail (MODEST_IS_WINDOW (window));
5874 modest_ui_actions_check_menu_dimming_rules (window);
5878 modest_ui_actions_on_folder_view_csm_menu_activated (GtkAction *action,
5879 ModestWindow *window)
5881 g_return_if_fail (MODEST_IS_WINDOW (window));
5884 modest_ui_actions_check_menu_dimming_rules (window);
5888 modest_ui_actions_on_header_view_csm_menu_activated (GtkAction *action,
5889 ModestWindow *window)
5891 g_return_if_fail (MODEST_IS_WINDOW (window));
5894 modest_ui_actions_check_menu_dimming_rules (window);
5898 modest_ui_actions_on_search_messages (GtkAction *action, ModestWindow *window)
5900 g_return_if_fail (MODEST_IS_WINDOW (window));
5902 /* we check for low-mem; in that case, show a warning, and don't allow
5905 if (modest_platform_check_memory_low (window, TRUE))
5908 modest_platform_show_search_messages (GTK_WINDOW (window));
5912 modest_ui_actions_on_open_addressbook (GtkAction *action, ModestWindow *win)
5914 g_return_if_fail (MODEST_IS_WINDOW (win));
5917 /* we check for low-mem; in that case, show a warning, and don't allow
5918 * for the addressbook
5920 if (modest_platform_check_memory_low (win, TRUE))
5924 modest_platform_show_addressbook (GTK_WINDOW (win));
5929 modest_ui_actions_on_toggle_find_in_page (GtkToggleAction *action,
5930 ModestWindow *window)
5932 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
5934 modest_msg_edit_window_toggle_find_toolbar (MODEST_MSG_EDIT_WINDOW (window), gtk_toggle_action_get_active (action));
5938 on_send_receive_finished (ModestMailOperation *mail_op,
5941 GtkWidget *header_view, *folder_view;
5942 TnyFolderStore *folder_store;
5943 ModestMainWindow *main_win = MODEST_MAIN_WINDOW (user_data);
5945 /* Set send/receive operation finished */
5946 modest_main_window_notify_send_receive_completed (main_win);
5948 /* Don't refresh the current folder if there were any errors */
5949 if (modest_mail_operation_get_status (mail_op) !=
5950 MODEST_MAIL_OPERATION_STATUS_SUCCESS)
5953 /* Refresh the current folder if we're viewing a window. We do
5954 this because the user won't be able to see the new mails in
5955 the selected folder after a Send&Receive because it only
5956 performs a poke_status, i.e, only the number of read/unread
5957 messages is updated, but the new headers are not
5959 folder_view = modest_main_window_get_child_widget (main_win,
5960 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
5964 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
5966 /* Do not need to refresh INBOX again because the
5967 update_account does it always automatically */
5968 if (folder_store && TNY_IS_FOLDER (folder_store) &&
5969 tny_folder_get_folder_type (TNY_FOLDER (folder_store)) != TNY_FOLDER_TYPE_INBOX) {
5970 ModestMailOperation *refresh_op;
5972 header_view = modest_main_window_get_child_widget (main_win,
5973 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
5975 /* We do not need to set the contents style
5976 because it hasn't changed. We also do not
5977 need to save the widget status. Just force
5979 refresh_op = modest_mail_operation_new (G_OBJECT (main_win));
5980 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), refresh_op);
5981 modest_mail_operation_refresh_folder (refresh_op, TNY_FOLDER (folder_store),
5982 folder_refreshed_cb, main_win);
5983 g_object_unref (refresh_op);
5987 g_object_unref (folder_store);
5992 modest_ui_actions_on_send_queue_error_happened (TnySendQueue *self,
5998 const gchar* server_name = NULL;
5999 TnyTransportAccount *server_account;
6000 gchar *message = NULL;
6002 /* Don't show anything if the user cancelled something or the
6003 * send receive request is not interactive. Authentication
6004 * errors are managed by the account store so no need to show
6005 * a dialog here again */
6006 if (err->code == TNY_SYSTEM_ERROR_CANCEL ||
6007 err->code == TNY_SERVICE_ERROR_AUTHENTICATE ||
6008 !modest_tny_send_queue_get_requested_send_receive (MODEST_TNY_SEND_QUEUE (self)))
6012 /* Get the server name: */
6014 TNY_TRANSPORT_ACCOUNT (tny_camel_send_queue_get_transport_account (TNY_CAMEL_SEND_QUEUE (self)));
6016 server_name = tny_account_get_hostname (TNY_ACCOUNT (server_account));
6018 g_return_if_reached ();
6020 /* Show the appropriate message text for the GError: */
6021 switch (err->code) {
6022 case TNY_SERVICE_ERROR_CONNECT:
6023 message = g_strdup_printf (_("emev_ib_ui_smtp_server_invalid"), server_name);
6025 case TNY_SERVICE_ERROR_SEND:
6026 message = g_strdup (dgettext("hildon-common-strings", "sfil_ib_unable_to_send"));
6028 case TNY_SERVICE_ERROR_UNAVAILABLE:
6029 message = g_strdup_printf (_("emev_ib_ui_smtp_server_invalid"), server_name);
6032 g_warning ("%s: unexpected ERROR %d",
6033 __FUNCTION__, err->code);
6034 message = g_strdup (dgettext("hildon-common-strings", "sfil_ib_unable_to_send"));
6038 modest_platform_run_information_dialog (NULL, message, FALSE);
6040 g_object_unref (server_account);
6044 modest_ui_actions_on_send_queue_status_changed (ModestTnySendQueue *send_queue,
6049 ModestMainWindow *main_window = NULL;
6050 ModestWindowMgr *mgr = NULL;
6051 GtkWidget *folder_view = NULL, *header_view = NULL;
6052 TnyFolderStore *selected_folder = NULL;
6053 TnyFolderType folder_type;
6055 mgr = modest_runtime_get_window_mgr ();
6056 main_window = MODEST_MAIN_WINDOW (modest_window_mgr_get_main_window (mgr,
6057 FALSE));/* don't create */
6061 /* Check if selected folder is OUTBOX */
6062 folder_view = modest_main_window_get_child_widget (main_window,
6063 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
6064 header_view = modest_main_window_get_child_widget (main_window,
6065 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
6067 selected_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
6068 if (!TNY_IS_FOLDER (selected_folder))
6071 /* gtk_tree_view_column_queue_resize is only available in GTK+ 2.8 */
6072 #if GTK_CHECK_VERSION(2, 8, 0)
6073 folder_type = modest_tny_folder_guess_folder_type (TNY_FOLDER (selected_folder));
6074 if (folder_type == TNY_FOLDER_TYPE_OUTBOX) {
6075 GtkTreeViewColumn *tree_column;
6077 tree_column = gtk_tree_view_get_column (GTK_TREE_VIEW (header_view),
6078 TNY_GTK_HEADER_LIST_MODEL_FROM_COLUMN);
6080 gtk_tree_view_column_queue_resize (tree_column);
6083 gtk_widget_queue_draw (header_view);
6086 /* Rerun dimming rules, because the message could become deletable for example */
6087 modest_window_check_dimming_rules_group (MODEST_WINDOW (main_window),
6088 MODEST_DIMMING_RULES_TOOLBAR);
6089 modest_window_check_dimming_rules_group (MODEST_WINDOW (main_window),
6090 MODEST_DIMMING_RULES_MENU);
6094 if (selected_folder != NULL)
6095 g_object_unref (selected_folder);
6099 modest_ui_actions_on_account_connection_error (GtkWindow *parent_window,
6100 TnyAccount *account)
6102 ModestProtocolType protocol_type;
6103 ModestProtocol *protocol;
6104 gchar *error_note = NULL;
6106 protocol_type = modest_tny_account_get_protocol_type (account);
6107 protocol = modest_protocol_registry_get_protocol_by_type (modest_runtime_get_protocol_registry (),
6110 error_note = modest_protocol_get_translation (protocol, MODEST_PROTOCOL_TRANSLATION_ACCOUNT_CONNECTION_ERROR, tny_account_get_hostname (account));
6111 if (error_note == NULL) {
6112 g_warning ("%s: This should not be reached", __FUNCTION__);
6114 modest_platform_run_information_dialog (parent_window, error_note, FALSE);
6115 g_free (error_note);
6120 modest_ui_actions_get_msg_already_deleted_error_msg (ModestWindow *win)
6124 TnyFolderStore *folder = NULL;
6125 TnyAccount *account = NULL;
6126 ModestProtocolType proto;
6127 ModestProtocol *protocol;
6128 TnyHeader *header = NULL;
6130 if (MODEST_IS_MAIN_WINDOW (win)) {
6131 GtkWidget *header_view;
6132 TnyList* headers = NULL;
6134 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
6135 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
6136 headers = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW (header_view));
6137 if (!headers || tny_list_get_length (headers) == 0) {
6139 g_object_unref (headers);
6142 iter = tny_list_create_iterator (headers);
6143 header = TNY_HEADER (tny_iterator_get_current (iter));
6144 folder = TNY_FOLDER_STORE (tny_header_get_folder (header));
6145 g_object_unref (iter);
6146 g_object_unref (headers);
6147 } else if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
6148 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
6149 folder = TNY_FOLDER_STORE (tny_header_get_folder (header));
6152 /* Get the account type */
6153 account = tny_folder_get_account (TNY_FOLDER (folder));
6154 proto = modest_tny_account_get_protocol_type (account);
6155 protocol = modest_protocol_registry_get_protocol_by_type (modest_runtime_get_protocol_registry (),
6158 subject = tny_header_dup_subject (header);
6159 msg = modest_protocol_get_translation (protocol, MODEST_PROTOCOL_TRANSLATION_MSG_NOT_AVAILABLE, subject);
6163 msg = g_strdup_printf (_("mail_ni_ui_folder_get_msg_folder_error"));
6167 g_object_unref (account);
6168 g_object_unref (folder);
6169 g_object_unref (header);
6175 modest_ui_actions_on_delete_account (GtkWindow *parent_window,
6176 const gchar *account_name,
6177 const gchar *account_title)
6179 ModestAccountMgr *account_mgr;
6182 ModestProtocol *protocol;
6183 gboolean removed = FALSE;
6185 g_return_val_if_fail (account_name, FALSE);
6186 g_return_val_if_fail (account_title, FALSE);
6188 account_mgr = modest_runtime_get_account_mgr();
6190 /* The warning text depends on the account type: */
6191 protocol = modest_protocol_registry_get_protocol_by_type (modest_runtime_get_protocol_registry (),
6192 modest_account_mgr_get_store_protocol (account_mgr,
6194 txt = modest_protocol_get_translation (protocol,
6195 MODEST_PROTOCOL_TRANSLATION_DELETE_MAILBOX,
6198 txt = g_strdup_printf (_("emev_nc_delete_mailbox"), account_title);
6200 response = modest_platform_run_confirmation_dialog (parent_window, txt);
6204 if (response == GTK_RESPONSE_OK) {
6205 /* Remove account. If it succeeds then it also removes
6206 the account from the ModestAccountView: */
6207 gboolean is_default = FALSE;
6208 gchar *default_account_name = modest_account_mgr_get_default_account (account_mgr);
6209 if (default_account_name && (strcmp (default_account_name, account_name) == 0))
6211 g_free (default_account_name);
6213 removed = modest_account_mgr_remove_account (account_mgr, account_name);
6215 g_warning ("%s: modest_account_mgr_remove_account() failed.\n", __FUNCTION__);