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>
53 #include <hildon/hildon-gtk.h>
54 #include <modest-header-window.h>
57 #ifdef MODEST_PLATFORM_MAEMO
58 #include "maemo/modest-osso-state-saving.h"
59 #endif /* MODEST_PLATFORM_MAEMO */
60 #ifndef MODEST_TOOLKIT_GTK
61 #include "maemo/modest-hildon-includes.h"
62 #include "maemo/modest-connection-specific-smtp-window.h"
63 #endif /* !MODEST_TOOLKIT_GTK */
64 #include <modest-utils.h>
66 #include "widgets/modest-ui-constants.h"
67 #include <widgets/modest-main-window.h>
68 #include <widgets/modest-msg-view-window.h>
69 #include <widgets/modest-account-view-window.h>
70 #include <widgets/modest-details-dialog.h>
71 #include <widgets/modest-attachments-view.h>
72 #include "widgets/modest-folder-view.h"
73 #include "widgets/modest-global-settings-dialog.h"
74 #include "modest-account-mgr-helpers.h"
75 #include "modest-mail-operation.h"
76 #include "modest-text-utils.h"
77 #include <modest-widget-memory.h>
78 #include <tny-error.h>
79 #include <tny-simple-list.h>
80 #include <tny-msg-view.h>
81 #include <tny-device.h>
82 #include <tny-merge-folder.h>
84 #include <gtkhtml/gtkhtml.h>
86 #define MIN_FREE_SPACE 5 * 1024 * 1024
87 #define MODEST_MOVE_TO_DIALOG_FOLDER_VIEW "move-to-dialog-folder-view"
89 typedef struct _GetMsgAsyncHelper {
91 ModestMailOperation *mail_op;
98 typedef enum _ReplyForwardAction {
102 } ReplyForwardAction;
104 typedef struct _ReplyForwardHelper {
105 guint reply_forward_type;
106 ReplyForwardAction action;
108 GtkWidget *parent_window;
110 } ReplyForwardHelper;
112 typedef struct _MoveToHelper {
113 GtkTreeRowReference *reference;
117 typedef struct _PasteAsAttachmentHelper {
118 ModestMsgEditWindow *window;
120 } PasteAsAttachmentHelper;
124 * The do_headers_action uses this kind of functions to perform some
125 * action to each member of a list of headers
127 typedef void (*HeadersFunc) (TnyHeader *header, ModestWindow *win, gpointer user_data);
129 static void do_headers_action (ModestWindow *win,
133 static void open_msg_cb (ModestMailOperation *mail_op,
140 static void reply_forward_cb (ModestMailOperation *mail_op,
147 static void reply_forward (ReplyForwardAction action, ModestWindow *win);
149 static void folder_refreshed_cb (ModestMailOperation *mail_op,
153 static void on_send_receive_finished (ModestMailOperation *mail_op,
156 static gint header_list_count_uncached_msgs (TnyList *header_list);
158 static gboolean connect_to_get_msg (ModestWindow *win,
159 gint num_of_uncached_msgs,
160 TnyAccount *account);
162 static gboolean remote_folder_has_leave_on_server (TnyFolderStore *folder);
164 static void do_create_folder (GtkWindow *window,
165 TnyFolderStore *parent_folder,
166 const gchar *suggested_name);
168 static TnyAccount *get_account_from_folder_store (TnyFolderStore *folder_store);
170 static void modest_ui_actions_on_main_window_move_to (GtkAction *action,
171 GtkWidget *folder_view,
172 TnyFolderStore *dst_folder,
173 ModestMainWindow *win);
175 static void modest_ui_actions_on_msg_view_window_move_to (GtkAction *action,
176 TnyFolderStore *dst_folder,
177 ModestMsgViewWindow *win);
180 * This function checks whether a TnyFolderStore is a pop account
183 remote_folder_has_leave_on_server (TnyFolderStore *folder)
188 g_return_val_if_fail (TNY_IS_FOLDER_STORE (folder), FALSE);
190 account = get_account_from_folder_store (folder);
191 result = (modest_protocol_registry_protocol_type_has_leave_on_server (modest_runtime_get_protocol_registry (),
192 modest_tny_account_get_protocol_type (account)));
193 g_object_unref (account);
198 /* FIXME: this should be merged with the similar code in modest-account-view-window */
199 /* Show the account creation wizard dialog.
200 * returns: TRUE if an account was created. FALSE if the user cancelled.
203 modest_ui_actions_run_account_setup_wizard (ModestWindow *win)
205 gboolean result = FALSE;
207 gint dialog_response;
209 /* there is no such wizard yet */
210 wizard = GTK_WINDOW (modest_platform_get_account_settings_wizard ());
211 modest_window_mgr_set_modal (modest_runtime_get_window_mgr(), GTK_WINDOW (wizard), (GtkWindow *) win);
213 /* always present a main window in the background
214 * we do it here, so we cannot end up with two wizards (as this
215 * function might be called in modest_window_mgr_get_main_window as well */
217 win = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr(),
218 TRUE); /* create if not existent */
220 gtk_window_set_transient_for (GTK_WINDOW (wizard), GTK_WINDOW (win));
222 /* make sure the mainwindow is visible. We need to present the
223 wizard again to give it the focus back. show_all are needed
224 in order to get the widgets properly drawn (MainWindow main
225 paned won't be in its right position and the dialog will be
227 #ifndef MODEST_TOOLKIT_HILDON2
228 gtk_widget_show_all (GTK_WIDGET (win));
229 gtk_widget_show_all (GTK_WIDGET (wizard));
230 gtk_window_present (GTK_WINDOW (win));
231 gtk_window_present (GTK_WINDOW (wizard));
234 dialog_response = gtk_dialog_run (GTK_DIALOG (wizard));
235 gtk_widget_destroy (GTK_WIDGET (wizard));
236 if (gtk_events_pending ())
237 gtk_main_iteration ();
239 if (dialog_response == GTK_RESPONSE_CANCEL) {
242 /* Check whether an account was created: */
243 result = modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
250 modest_ui_actions_on_about (GtkAction *action, ModestWindow *win)
253 const gchar *authors[] = {
254 "Dirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>",
257 about = gtk_about_dialog_new ();
258 gtk_about_dialog_set_name (GTK_ABOUT_DIALOG(about), PACKAGE_NAME);
259 gtk_about_dialog_set_version (GTK_ABOUT_DIALOG(about),PACKAGE_VERSION);
260 gtk_about_dialog_set_copyright (GTK_ABOUT_DIALOG(about),
261 _("Copyright (c) 2006, Nokia Corporation\n"
262 "All rights reserved."));
263 gtk_about_dialog_set_comments (GTK_ABOUT_DIALOG(about),
264 _("a modest e-mail client\n\n"
265 "design and implementation: Dirk-Jan C. Binnema\n"
266 "contributions from the fine people at KC and Ig\n"
267 "uses the tinymail email framework written by Philip van Hoof"));
268 gtk_about_dialog_set_authors (GTK_ABOUT_DIALOG(about), authors);
269 gtk_about_dialog_set_website (GTK_ABOUT_DIALOG(about), "http://modest.garage.maemo.org");
270 gtk_window_set_transient_for (GTK_WINDOW (about), GTK_WINDOW (win));
271 gtk_window_set_modal (GTK_WINDOW (about), TRUE);
273 gtk_dialog_run (GTK_DIALOG (about));
274 gtk_widget_destroy(about);
278 * Gets the list of currently selected messages. If the win is the
279 * main window, then it returns a newly allocated list of the headers
280 * selected in the header view. If win is the msg view window, then
281 * the value returned is a list with just a single header.
283 * The caller of this funcion must free the list.
286 get_selected_headers (ModestWindow *win)
288 if (MODEST_IS_MAIN_WINDOW(win)) {
289 GtkWidget *header_view;
291 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
292 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
293 return modest_header_view_get_selected_headers (MODEST_HEADER_VIEW(header_view));
295 } else if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
296 /* for MsgViewWindows, we simply return a list with one element */
298 TnyList *list = NULL;
300 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
301 if (header != NULL) {
302 list = tny_simple_list_new ();
303 tny_list_prepend (list, G_OBJECT(header));
304 g_object_unref (G_OBJECT(header));
309 #ifdef MODEST_TOOLKIT_HILDON2
310 } else if (MODEST_IS_HEADER_WINDOW (win)) {
311 GtkWidget *header_view;
313 header_view = GTK_WIDGET (modest_header_window_get_header_view (MODEST_HEADER_WINDOW (win)));
314 return modest_header_view_get_selected_headers (MODEST_HEADER_VIEW(header_view));
320 static GtkTreeRowReference *
321 get_next_after_selected_headers (ModestHeaderView *header_view)
323 GtkTreeSelection *sel;
324 GList *selected_rows, *node;
326 GtkTreeRowReference *result;
329 model = gtk_tree_view_get_model (GTK_TREE_VIEW (header_view));
330 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
331 selected_rows = gtk_tree_selection_get_selected_rows (sel, NULL);
333 if (selected_rows == NULL)
336 node = g_list_last (selected_rows);
337 path = gtk_tree_path_copy ((GtkTreePath *) node->data);
338 gtk_tree_path_next (path);
340 result = gtk_tree_row_reference_new (model, path);
342 gtk_tree_path_free (path);
343 g_list_foreach (selected_rows, (GFunc) gtk_tree_path_free, NULL);
344 g_list_free (selected_rows);
350 headers_action_mark_as_read (TnyHeader *header,
354 TnyHeaderFlags flags;
356 g_return_if_fail (TNY_IS_HEADER(header));
358 flags = tny_header_get_flags (header);
359 if (flags & TNY_HEADER_FLAG_SEEN) return;
360 tny_header_set_flag (header, TNY_HEADER_FLAG_SEEN);
364 headers_action_mark_as_unread (TnyHeader *header,
368 TnyHeaderFlags flags;
370 g_return_if_fail (TNY_IS_HEADER(header));
372 flags = tny_header_get_flags (header);
373 if (flags & TNY_HEADER_FLAG_SEEN) {
374 tny_header_unset_flag (header, TNY_HEADER_FLAG_SEEN);
378 /** After deleing a message that is currently visible in a window,
379 * show the next message from the list, or close the window if there are no more messages.
382 modest_ui_actions_refresh_message_window_after_delete (ModestMsgViewWindow* win)
384 /* Close msg view window or select next */
385 if (!modest_msg_view_window_select_next_message (win) &&
386 !modest_msg_view_window_select_previous_message (win)) {
388 g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value);
394 modest_ui_actions_on_delete_message (GtkAction *action, ModestWindow *win)
396 modest_ui_actions_on_edit_mode_delete_message (win);
400 modest_ui_actions_on_edit_mode_delete_message (ModestWindow *win)
402 TnyList *header_list = NULL;
403 TnyIterator *iter = NULL;
404 TnyHeader *header = NULL;
405 gchar *message = NULL;
408 ModestWindowMgr *mgr;
409 GtkWidget *header_view = NULL;
410 gboolean retval = TRUE;
412 g_return_val_if_fail (MODEST_IS_WINDOW(win), FALSE);
414 /* Check first if the header view has the focus */
415 if (MODEST_IS_MAIN_WINDOW (win)) {
417 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
418 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
419 if (!gtk_widget_is_focus (header_view))
423 /* Get the headers, either from the header view (if win is the main window),
424 * or from the message view window: */
425 header_list = get_selected_headers (win);
426 if (!header_list) return FALSE;
428 /* Check if any of the headers are already opened, or in the process of being opened */
429 if (MODEST_IS_MAIN_WINDOW (win)) {
430 gint opened_headers = 0;
432 iter = tny_list_create_iterator (header_list);
433 mgr = modest_runtime_get_window_mgr ();
434 while (!tny_iterator_is_done (iter)) {
435 header = TNY_HEADER (tny_iterator_get_current (iter));
437 if (modest_window_mgr_find_registered_header (mgr, header, NULL))
439 g_object_unref (header);
441 tny_iterator_next (iter);
443 g_object_unref (iter);
445 if (opened_headers > 0) {
448 msg = g_strdup_printf (_("mcen_nc_unable_to_delete_n_messages"),
451 modest_platform_run_information_dialog (GTK_WINDOW (win), (const gchar *) msg, FALSE);
454 g_object_unref (header_list);
460 if (tny_list_get_length(header_list) == 1) {
461 iter = tny_list_create_iterator (header_list);
462 header = TNY_HEADER (tny_iterator_get_current (iter));
465 subject = tny_header_dup_subject (header);
467 subject = g_strdup (_("mail_va_no_subject"));
468 desc = g_strdup_printf ("%s", subject);
470 g_object_unref (header);
473 g_object_unref (iter);
475 message = g_strdup_printf(ngettext("emev_nc_delete_message", "emev_nc_delete_messages",
476 tny_list_get_length(header_list)), desc);
478 /* Confirmation dialog */
479 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
483 if (response == GTK_RESPONSE_OK) {
484 ModestWindow *main_window = NULL;
485 ModestWindowMgr *mgr = NULL;
486 GtkTreeModel *model = NULL;
487 GtkTreeSelection *sel = NULL;
488 GList *sel_list = NULL, *tmp = NULL;
489 GtkTreeRowReference *next_row_reference = NULL;
490 GtkTreeRowReference *prev_row_reference = NULL;
491 GtkTreePath *next_path = NULL;
492 GtkTreePath *prev_path = NULL;
493 ModestMailOperation *mail_op = NULL;
495 /* Find last selected row */
496 if (MODEST_IS_MAIN_WINDOW (win)) {
497 model = gtk_tree_view_get_model (GTK_TREE_VIEW (header_view));
498 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
499 sel_list = gtk_tree_selection_get_selected_rows (sel, &model);
500 for (tmp=sel_list; tmp; tmp=tmp->next) {
501 if (tmp->next == NULL) {
502 prev_path = gtk_tree_path_copy((GtkTreePath *) tmp->data);
503 next_path = gtk_tree_path_copy((GtkTreePath *) tmp->data);
505 gtk_tree_path_prev (prev_path);
506 gtk_tree_path_next (next_path);
508 prev_row_reference = gtk_tree_row_reference_new (model, prev_path);
509 next_row_reference = gtk_tree_row_reference_new (model, next_path);
514 /* Disable window dimming management */
515 modest_window_disable_dimming (MODEST_WINDOW(win));
517 /* Remove each header. If it's a view window header_view == NULL */
518 mail_op = modest_mail_operation_new ((GObject *) win);
519 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
521 modest_mail_operation_remove_msgs (mail_op, header_list, FALSE);
522 g_object_unref (mail_op);
524 /* Enable window dimming management */
526 gtk_tree_selection_unselect_all (sel);
528 modest_window_enable_dimming (MODEST_WINDOW(win));
530 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
531 modest_ui_actions_refresh_message_window_after_delete (MODEST_MSG_VIEW_WINDOW (win));
533 /* Get main window */
534 mgr = modest_runtime_get_window_mgr ();
535 main_window = modest_window_mgr_get_main_window (mgr, FALSE); /* don't create */
536 } else if (MODEST_IS_MAIN_WINDOW (win)) {
537 /* Move cursor to next row */
540 /* Select next or previous row */
541 if (gtk_tree_row_reference_valid (next_row_reference)) {
542 gtk_tree_selection_select_path (sel, next_path);
544 else if (gtk_tree_row_reference_valid (prev_row_reference)) {
545 gtk_tree_selection_select_path (sel, prev_path);
549 if (gtk_tree_row_reference_valid (next_row_reference))
550 gtk_tree_row_reference_free (next_row_reference);
551 if (next_path != NULL)
552 gtk_tree_path_free (next_path);
553 if (gtk_tree_row_reference_valid (prev_row_reference))
554 gtk_tree_row_reference_free (prev_row_reference);
555 if (prev_path != NULL)
556 gtk_tree_path_free (prev_path);
559 /* Update toolbar dimming state */
561 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (main_window));
562 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
566 g_list_foreach (sel_list, (GFunc) gtk_tree_path_free, NULL);
567 g_list_free (sel_list);
576 g_object_unref (header_list);
584 /* delete either message or folder, based on where we are */
586 modest_ui_actions_on_delete_message_or_folder (GtkAction *action, ModestWindow *win)
588 g_return_if_fail (MODEST_IS_WINDOW(win));
590 /* Check first if the header view has the focus */
591 if (MODEST_IS_MAIN_WINDOW (win)) {
593 w = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
594 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
595 if (gtk_widget_is_focus (w)) {
596 modest_ui_actions_on_delete_folder (action, MODEST_MAIN_WINDOW(win));
600 modest_ui_actions_on_delete_message (action, win);
604 modest_ui_actions_on_quit (GtkAction *action, ModestWindow *win)
606 ModestWindowMgr *mgr = NULL;
608 #ifdef MODEST_PLATFORM_MAEMO
609 modest_osso_save_state();
610 #endif /* MODEST_PLATFORM_MAEMO */
612 g_debug ("closing down, clearing %d item(s) from operation queue",
613 modest_mail_operation_queue_num_elements
614 (modest_runtime_get_mail_operation_queue()));
616 /* cancel all outstanding operations */
617 modest_mail_operation_queue_cancel_all
618 (modest_runtime_get_mail_operation_queue());
620 g_debug ("queue has been cleared");
623 /* Check if there are opened editing windows */
624 mgr = modest_runtime_get_window_mgr ();
625 modest_window_mgr_close_all_windows (mgr);
627 /* note: when modest-tny-account-store is finalized,
628 it will automatically set all network connections
631 /* gtk_main_quit (); */
635 modest_ui_actions_on_close_window (GtkAction *action, ModestWindow *win)
639 g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value);
641 /* if (MODEST_IS_MSG_VIEW_WINDOW (win)) { */
642 /* gtk_widget_destroy (GTK_WIDGET (win)); */
643 /* } else if (MODEST_IS_MSG_EDIT_WINDOW (win)) { */
644 /* gboolean ret_value; */
645 /* g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value); */
646 /* } else if (MODEST_IS_WINDOW (win)) { */
647 /* gtk_widget_destroy (GTK_WIDGET (win)); */
649 /* g_return_if_reached (); */
654 modest_ui_actions_add_to_contacts (GtkAction *action, ModestWindow *win)
656 g_return_if_fail (MODEST_IS_MSG_VIEW_WINDOW (win));
658 modest_msg_view_window_add_to_contacts (MODEST_MSG_VIEW_WINDOW (win));
662 modest_ui_actions_on_add_to_contacts (GtkAction *action, ModestWindow *win)
664 GtkClipboard *clipboard = NULL;
665 gchar *selection = NULL;
667 clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
668 selection = gtk_clipboard_wait_for_text (clipboard);
670 /* Question: why is the clipboard being used here?
671 * It doesn't really make a lot of sense. */
675 modest_address_book_add_address (selection);
681 modest_ui_actions_on_accounts (GtkAction *action,
684 /* This is currently only implemented for Maemo */
685 if (!modest_account_mgr_has_accounts (modest_runtime_get_account_mgr(), TRUE)) {
686 if (!modest_ui_actions_run_account_setup_wizard (win))
687 g_debug ("%s: wizard was already running", __FUNCTION__);
691 /* Show the list of accounts */
692 GtkWindow *account_win = GTK_WINDOW (modest_account_view_window_new ());
694 /* The accounts dialog must be modal */
695 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (account_win), (GtkWindow *) win);
696 modest_utils_show_dialog_and_forget (GTK_WINDOW (win), GTK_DIALOG (account_win));
701 modest_ui_actions_on_smtp_servers (GtkAction *action, ModestWindow *win)
703 /* This is currently only implemented for Maemo,
704 * because it requires an API (libconic) to detect different connection
707 #ifndef MODEST_TOOLKIT_GTK /* Defined in config.h */
709 /* Create the window if necessary: */
710 GtkWidget *specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
711 modest_connection_specific_smtp_window_fill_with_connections (
712 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (specific_window),
713 modest_runtime_get_account_mgr());
715 /* Show the window: */
716 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (),
717 GTK_WINDOW (specific_window), (GtkWindow *) win);
718 gtk_widget_show (specific_window);
719 #endif /* !MODEST_TOOLKIT_GTK */
723 modest_ui_actions_compose_msg(ModestWindow *win,
726 const gchar *bcc_str,
727 const gchar *subject_str,
728 const gchar *body_str,
730 gboolean set_as_modified)
732 gchar *account_name = NULL;
734 TnyAccount *account = NULL;
735 TnyFolder *folder = NULL;
736 gchar *from_str = NULL, *signature = NULL, *body = NULL;
737 gboolean use_signature = FALSE;
738 ModestWindow *msg_win = NULL;
739 ModestAccountMgr *mgr = modest_runtime_get_account_mgr();
740 ModestTnyAccountStore *store = modest_runtime_get_account_store();
741 GnomeVFSFileSize total_size, allowed_size;
743 /* we check for low-mem */
744 if (modest_platform_check_memory_low (win, TRUE))
747 #ifdef MODEST_TOOLKIT_HILDON2
748 account_name = g_strdup (modest_window_get_active_account(win));
751 account_name = modest_account_mgr_get_default_account(mgr);
754 g_printerr ("modest: no account found\n");
757 account = modest_tny_account_store_get_server_account (store, account_name, TNY_ACCOUNT_TYPE_STORE);
759 g_printerr ("modest: failed to get tnyaccount for '%s'\n", account_name);
762 folder = modest_tny_account_get_special_folder (account, TNY_FOLDER_TYPE_DRAFTS);
764 g_printerr ("modest: failed to find Drafts folder\n");
767 from_str = modest_account_mgr_get_from_string (mgr, account_name);
769 g_printerr ("modest: failed get from string for '%s'\n", account_name);
773 signature = modest_account_mgr_get_signature (mgr, account_name, &use_signature);
774 if (body_str != NULL) {
775 body = use_signature ? g_strconcat(body_str, "\n--\n", signature, NULL) : g_strdup(body_str);
777 body = use_signature ? g_strconcat("\n--\n", signature, NULL) : g_strdup("");
780 msg = modest_tny_msg_new (to_str, from_str, cc_str, bcc_str, subject_str, body, NULL, NULL, NULL);
782 g_printerr ("modest: failed to create new msg\n");
786 /* Create and register edit window */
787 /* This is destroyed by TODO. */
789 allowed_size = MODEST_MAX_ATTACHMENT_SIZE;
790 msg_win = modest_msg_edit_window_new (msg, account_name, FALSE);
792 if (!modest_window_mgr_register_window (modest_runtime_get_window_mgr(), msg_win, NULL)) {
793 gtk_widget_destroy (GTK_WIDGET (msg_win));
796 modest_msg_edit_window_set_modified (MODEST_MSG_EDIT_WINDOW (msg_win), set_as_modified);
797 gtk_widget_show_all (GTK_WIDGET (msg_win));
799 while (attachments) {
801 modest_msg_edit_window_attach_file_one((ModestMsgEditWindow *)msg_win,
802 attachments->data, allowed_size);
804 if (total_size > allowed_size) {
805 g_warning ("%s: total size: %u",
806 __FUNCTION__, (unsigned int)total_size);
809 allowed_size -= total_size;
811 attachments = g_slist_next(attachments);
818 g_free (account_name);
820 g_object_unref (G_OBJECT(account));
822 g_object_unref (G_OBJECT(folder));
824 g_object_unref (G_OBJECT(msg));
828 modest_ui_actions_on_new_msg (GtkAction *action, ModestWindow *win)
830 /* if there are no accounts yet, just show the wizard */
831 if (!modest_account_mgr_has_accounts (modest_runtime_get_account_mgr(), TRUE))
832 if (!modest_ui_actions_run_account_setup_wizard (win))
835 modest_ui_actions_compose_msg(win, NULL, NULL, NULL, NULL, NULL, NULL, FALSE);
840 modest_ui_actions_msg_retrieval_check (ModestMailOperation *mail_op,
844 ModestMailOperationStatus status;
846 /* If there is no message or the operation was not successful */
847 status = modest_mail_operation_get_status (mail_op);
848 if (!msg || status != MODEST_MAIL_OPERATION_STATUS_SUCCESS) {
851 /* If it's a memory low issue, then show a banner */
852 error = modest_mail_operation_get_error (mail_op);
853 if (error && error->domain == MODEST_MAIL_OPERATION_ERROR &&
854 error->code == MODEST_MAIL_OPERATION_ERROR_LOW_MEMORY) {
855 GObject *source = modest_mail_operation_get_source (mail_op);
856 modest_platform_run_information_dialog (GTK_IS_WINDOW (source) ? GTK_WINDOW (source) : NULL,
857 dgettext("ke-recv","memr_ib_operation_disabled"),
859 g_object_unref (source);
862 if (error && ((error->code == TNY_SERVICE_ERROR_NO_SUCH_MESSAGE) ||
863 error->code == TNY_SERVICE_ERROR_MESSAGE_NOT_AVAILABLE)) {
864 gchar *subject, *msg;
865 subject = tny_header_dup_subject (header);
867 subject = g_strdup (_("mail_va_no_subject"));;
868 msg = g_strdup_printf (_("emev_ni_ui_imap_message_not_available_in_server"),
870 modest_platform_run_information_dialog (NULL, msg, FALSE);
875 /* Remove the header from the preregistered uids */
876 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (),
894 OpenMsgBannerInfo *banner_info;
895 GtkTreeRowReference *rowref;
899 open_msg_banner_idle (gpointer userdata)
901 OpenMsgBannerInfo *banner_info = (OpenMsgBannerInfo *) userdata;
903 gdk_threads_enter ();
904 banner_info->idle_handler = 0;
905 banner_info->banner = modest_platform_animation_banner (NULL, NULL, banner_info->message);
907 g_object_ref (banner_info->banner);
909 gdk_threads_leave ();
916 get_header_view_from_window (ModestWindow *window)
918 GtkWidget *header_view;
920 if (MODEST_IS_MAIN_WINDOW (window)) {
921 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (window),
922 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
923 #ifdef MODEST_TOOLKIT_HILDON2
924 } else if (MODEST_IS_HEADER_WINDOW (window)){
925 header_view = GTK_WIDGET (modest_header_window_get_header_view (MODEST_HEADER_WINDOW (window)));
935 get_info_from_header (TnyHeader *header, gboolean *is_draft)
938 gchar *account = NULL;
939 TnyFolderType folder_type = TNY_FOLDER_TYPE_UNKNOWN;
943 folder = tny_header_get_folder (header);
944 /* Gets folder type (OUTBOX headers will be opened in edit window */
945 if (modest_tny_folder_is_local_folder (folder)) {
946 folder_type = modest_tny_folder_get_local_or_mmc_folder_type (folder);
947 if (folder_type == TNY_FOLDER_TYPE_INVALID)
948 g_warning ("%s: BUG: TNY_FOLDER_TYPE_INVALID", __FUNCTION__);
951 if (folder_type == TNY_FOLDER_TYPE_OUTBOX) {
952 TnyTransportAccount *traccount = NULL;
953 ModestTnyAccountStore *accstore = modest_runtime_get_account_store();
954 traccount = modest_tny_account_store_get_transport_account_from_outbox_header(accstore, header);
956 ModestTnySendQueue *send_queue = NULL;
957 ModestTnySendQueueStatus status;
959 account = g_strdup(modest_tny_account_get_parent_modest_account_name_for_server_account(
960 TNY_ACCOUNT(traccount)));
961 send_queue = modest_runtime_get_send_queue(traccount, TRUE);
962 if (TNY_IS_SEND_QUEUE (send_queue)) {
963 msg_id = modest_tny_send_queue_get_msg_id (header);
964 status = modest_tny_send_queue_get_msg_status(send_queue, msg_id);
966 /* Only open messages in outbox with the editor if they are in Failed state */
967 if (status == MODEST_TNY_SEND_QUEUE_FAILED) {
970 #ifdef MODEST_TOOLKIT_HILDON2
972 /* In Fremantle we can not
973 open any message from
974 outbox which is not in
976 g_object_unref(traccount);
980 g_object_unref(traccount);
982 g_warning("Cannot get transport account for message in outbox!!");
984 } else if (folder_type == TNY_FOLDER_TYPE_DRAFTS) {
985 *is_draft = TRUE; /* Open in editor if the message is in the Drafts folder */
988 g_object_unref (folder);
994 open_msg_cb (ModestMailOperation *mail_op,
1001 ModestWindowMgr *mgr = NULL;
1002 ModestWindow *parent_win = NULL;
1003 ModestWindow *win = NULL;
1004 gchar *account = NULL;
1005 gboolean open_in_editor = FALSE;
1006 OpenMsgHelper *helper = (OpenMsgHelper *) user_data;
1008 /* Do nothing if there was any problem with the mail
1009 operation. The error will be shown by the error_handler of
1010 the mail operation */
1011 if (!modest_ui_actions_msg_retrieval_check (mail_op, header, msg))
1014 parent_win = (ModestWindow *) modest_mail_operation_get_source (mail_op);
1016 /* Mark header as read */
1017 headers_action_mark_as_read (header, MODEST_WINDOW(parent_win), NULL);
1019 account = get_info_from_header (header, &open_in_editor);
1023 account = g_strdup (modest_window_get_active_account (MODEST_WINDOW (parent_win)));
1025 account = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
1027 if (open_in_editor) {
1028 ModestAccountMgr *mgr = modest_runtime_get_account_mgr ();
1029 gchar *from_header = NULL, *acc_name;
1031 from_header = tny_header_dup_from (header);
1033 /* we cannot edit without a valid account... */
1034 if (!modest_account_mgr_has_accounts(mgr, TRUE)) {
1035 if (!modest_ui_actions_run_account_setup_wizard(parent_win)) {
1036 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (),
1038 g_free (from_header);
1043 acc_name = modest_utils_get_account_name_from_recipient (from_header);
1044 g_free (from_header);
1050 win = modest_msg_edit_window_new (msg, account, TRUE);
1052 gchar *uid = modest_tny_folder_get_header_unique_id (header);
1054 if (helper->rowref && helper->model) {
1055 win = modest_msg_view_window_new_with_header_model (msg, account, (const gchar*) uid,
1056 helper->model, helper->rowref);
1058 win = modest_msg_view_window_new_for_attachment (msg, account, (const gchar*) uid);
1063 /* Register and show new window */
1065 mgr = modest_runtime_get_window_mgr ();
1066 if (!modest_window_mgr_register_window (mgr, win, NULL)) {
1067 gtk_widget_destroy (GTK_WIDGET (win));
1070 gtk_widget_show_all (GTK_WIDGET(win));
1073 /* Update toolbar dimming state */
1074 if (MODEST_IS_MAIN_WINDOW (parent_win)) {
1075 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (parent_win));
1081 g_object_unref (parent_win);
1085 is_memory_full_error (GError *error)
1087 gboolean enough_free_space = TRUE;
1088 GnomeVFSURI *cache_dir_uri;
1089 const gchar *cache_dir;
1090 GnomeVFSFileSize free_space;
1092 cache_dir = tny_account_store_get_cache_dir (TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()));
1093 cache_dir_uri = gnome_vfs_uri_new (cache_dir);
1094 if (gnome_vfs_get_volume_free_space (cache_dir_uri, &free_space) == GNOME_VFS_OK) {
1095 if (free_space < MIN_FREE_SPACE)
1096 enough_free_space = FALSE;
1098 gnome_vfs_uri_unref (cache_dir_uri);
1100 if ((error->code == TNY_SYSTEM_ERROR_MEMORY ||
1101 /* When asking for a mail and no space left on device
1102 tinymail returns this error */
1103 error->code == TNY_SERVICE_ERROR_MESSAGE_NOT_AVAILABLE ||
1104 /* When the folder summary could not be read or
1106 error->code == TNY_IO_ERROR_WRITE ||
1107 error->code == TNY_IO_ERROR_READ) &&
1108 !enough_free_space) {
1116 check_memory_full_error (GtkWidget *parent_window, GError *err)
1121 if (is_memory_full_error (err))
1122 modest_platform_information_banner (parent_window,
1123 NULL, dgettext("ke-recv",
1124 "cerm_device_memory_full"));
1125 else if (err->code == TNY_SYSTEM_ERROR_MEMORY)
1126 /* If the account was created in memory full
1127 conditions then tinymail won't be able to
1128 connect so it'll return this error code */
1129 modest_platform_information_banner (parent_window,
1130 NULL, _("emev_ui_imap_inbox_select_error"));
1138 modest_ui_actions_disk_operations_error_handler (ModestMailOperation *mail_op,
1141 const GError *error;
1142 GObject *win = NULL;
1143 ModestMailOperationStatus status;
1145 win = modest_mail_operation_get_source (mail_op);
1146 error = modest_mail_operation_get_error (mail_op);
1147 status = modest_mail_operation_get_status (mail_op);
1149 /* If the mail op has been cancelled then it's not an error:
1150 don't show any message */
1151 if (status != MODEST_MAIL_OPERATION_STATUS_CANCELED) {
1152 if (is_memory_full_error ((GError *) error)) {
1153 modest_platform_information_banner ((GtkWidget *) win,
1154 NULL, dgettext("ke-recv",
1155 "cerm_device_memory_full"));
1156 } else if (error->code == TNY_SYSTEM_ERROR_MEMORY) {
1157 modest_platform_information_banner ((GtkWidget *) win,
1158 NULL, _("emev_ui_imap_inbox_select_error"));
1159 } else if (error->domain == MODEST_MAIL_OPERATION_ERROR &&
1160 error->code == MODEST_MAIL_OPERATION_ERROR_FILE_IO) {
1161 modest_platform_information_banner ((GtkWidget *) win,
1162 NULL, dgettext ("hildon-common-strings", "sfil_ni_unable_to_open_file_not_found"));
1163 } else if (user_data) {
1164 modest_platform_information_banner ((GtkWidget *) win,
1170 g_object_unref (win);
1174 * Returns the account a list of headers belongs to. It returns a
1175 * *new* reference so don't forget to unref it
1178 get_account_from_header_list (TnyList *headers)
1180 TnyAccount *account = NULL;
1182 if (tny_list_get_length (headers) > 0) {
1183 TnyIterator *iter = tny_list_create_iterator (headers);
1184 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter));
1185 TnyFolder *folder = tny_header_get_folder (header);
1188 g_object_unref (header);
1190 while (!tny_iterator_is_done (iter)) {
1191 header = TNY_HEADER (tny_iterator_get_current (iter));
1192 folder = tny_header_get_folder (header);
1195 g_object_unref (header);
1197 tny_iterator_next (iter);
1202 account = tny_folder_get_account (folder);
1203 g_object_unref (folder);
1207 g_object_unref (header);
1209 g_object_unref (iter);
1215 get_account_from_header (TnyHeader *header)
1217 TnyAccount *account = NULL;
1220 folder = tny_header_get_folder (header);
1223 account = tny_folder_get_account (folder);
1224 g_object_unref (folder);
1231 open_msg_helper_destroyer (gpointer user_data)
1233 OpenMsgHelper *helper = (OpenMsgHelper *) user_data;
1235 if (helper->banner_info) {
1236 g_free (helper->banner_info->message);
1237 if (helper->banner_info->idle_handler > 0) {
1238 g_source_remove (helper->banner_info->idle_handler);
1239 helper->banner_info->idle_handler = 0;
1241 if (helper->banner_info->banner != NULL) {
1242 gtk_widget_destroy (helper->banner_info->banner);
1243 g_object_unref (helper->banner_info->banner);
1244 helper->banner_info->banner = NULL;
1246 g_slice_free (OpenMsgBannerInfo, helper->banner_info);
1247 helper->banner_info = NULL;
1249 g_object_unref (helper->model);
1250 g_object_unref (helper->header);
1251 gtk_tree_row_reference_free (helper->rowref);
1252 g_slice_free (OpenMsgHelper, helper);
1256 open_msg_performer(gboolean canceled,
1258 GtkWindow *parent_window,
1259 TnyAccount *account,
1262 ModestMailOperation *mail_op = NULL;
1264 ModestProtocolType proto;
1265 TnyConnectionStatus status;
1266 gboolean show_open_draft = FALSE;
1267 OpenMsgHelper *helper = NULL;
1269 helper = (OpenMsgHelper *) user_data;
1271 status = tny_account_get_connection_status (account);
1272 if (err || canceled) {
1273 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (), helper->header);
1274 /* Free the helper */
1275 open_msg_helper_destroyer (helper);
1277 /* In memory full conditions we could get this error here */
1278 check_memory_full_error ((GtkWidget *) parent_window, err);
1283 /* Get the error message depending on the protocol */
1284 proto = modest_tny_account_get_protocol_type (account);
1285 if (proto == MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1286 proto = MODEST_PROTOCOLS_STORE_MAILDIR;
1289 ModestProtocol *protocol;
1290 ModestProtocolRegistry *protocol_registry;
1293 protocol_registry = modest_runtime_get_protocol_registry ();
1294 subject = tny_header_dup_subject (helper->header);
1296 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, proto);
1297 error_msg = modest_protocol_get_translation (protocol, MODEST_PROTOCOL_TRANSLATION_MSG_NOT_AVAILABLE, subject);
1301 if (error_msg == NULL) {
1302 error_msg = g_strdup (_("mail_ni_ui_folder_get_msg_folder_error"));
1305 if (modest_protocol_registry_protocol_type_has_tag (protocol_registry,
1307 MODEST_PROTOCOL_REGISTRY_LOCAL_STORE_PROTOCOLS)) {
1309 TnyFolderType folder_type;
1311 folder = tny_header_get_folder (helper->header);
1312 folder_type = modest_tny_folder_get_local_or_mmc_folder_type (folder);
1313 show_open_draft = (folder_type == TNY_FOLDER_TYPE_DRAFTS);
1314 g_object_unref (folder);
1317 #ifdef MODEST_TOOLKIT_HILDON2
1319 gchar *account_name = get_info_from_header (helper->header, &is_draft);
1322 ModestWindow *window;
1323 GtkWidget *header_view;
1326 header_view = get_header_view_from_window (MODEST_WINDOW (parent_window));
1327 uid = modest_tny_folder_get_header_unique_id (helper->header);
1329 window = modest_msg_view_window_new_from_header_view
1330 (MODEST_HEADER_VIEW (header_view), account_name, uid, helper->rowref);
1331 if (window != NULL) {
1332 if (!modest_window_mgr_register_window (modest_runtime_get_window_mgr (),
1334 gtk_widget_destroy (GTK_WIDGET (window));
1336 gtk_widget_show_all (GTK_WIDGET(window));
1340 g_free (account_name);
1342 open_msg_helper_destroyer (helper);
1345 g_free (account_name);
1347 /* Create the mail operation */
1349 modest_mail_operation_new_with_error_handling ((GObject *) parent_window,
1350 modest_ui_actions_disk_operations_error_handler,
1352 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
1355 if (show_open_draft) {
1356 helper->banner_info = g_slice_new (OpenMsgBannerInfo);
1357 #ifdef MODEST_TOOLKIT_HILDON2
1358 helper->banner_info->message = g_strdup (_("mail_me_opening"));
1360 helper->banner_info->message = g_strdup (_("mail_ib_opening_draft_message"));
1362 helper->banner_info->banner = NULL;
1363 helper->banner_info->idle_handler = g_timeout_add (500, open_msg_banner_idle,
1364 helper->banner_info);
1368 headers = TNY_LIST (tny_simple_list_new ());
1369 tny_list_prepend (headers, G_OBJECT (helper->header));
1370 modest_mail_operation_get_msgs_full (mail_op,
1374 open_msg_helper_destroyer);
1375 g_object_unref (headers);
1380 g_object_unref (mail_op);
1381 g_object_unref (account);
1385 * This function is used by both modest_ui_actions_on_open and
1386 * modest_ui_actions_on_header_activated. This way we always do the
1387 * same when trying to open messages.
1390 open_msg_from_header (TnyHeader *header, GtkTreeRowReference *rowref, ModestWindow *win)
1392 ModestWindowMgr *mgr = NULL;
1393 TnyAccount *account;
1394 gboolean cached = FALSE;
1396 GtkWidget *header_view = NULL;
1397 OpenMsgHelper *helper;
1398 ModestWindow *window;
1400 g_return_if_fail (header != NULL && rowref != NULL);
1402 mgr = modest_runtime_get_window_mgr ();
1405 header_view = get_header_view_from_window (MODEST_WINDOW (win));
1406 if (header_view == NULL)
1409 /* Get the account */
1410 account = get_account_from_header (header);
1415 found = modest_window_mgr_find_registered_header (mgr, header, &window);
1417 /* Do not open again the message and present the
1418 window to the user */
1421 #ifndef MODEST_TOOLKIT_HILDON2
1422 gtk_window_present (GTK_WINDOW (window));
1425 /* the header has been registered already, we don't do
1426 * anything but wait for the window to come up*/
1427 g_debug ("header %p already registered, waiting for window", header);
1432 /* Open each message */
1433 cached = tny_header_get_flags (header) & TNY_HEADER_FLAG_CACHED;
1435 /* Allways download if we are online. */
1436 if (!tny_device_is_online (modest_runtime_get_device ())) {
1439 /* If ask for user permission to download the messages */
1440 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
1441 _("mcen_nc_get_msg"));
1443 /* End if the user does not want to continue */
1444 if (response == GTK_RESPONSE_CANCEL) {
1450 /* We register the window for opening */
1451 modest_window_mgr_register_header (mgr, header, NULL);
1453 /* Create the helper. We need to get a reference to the model
1454 here because it could change while the message is readed
1455 (the user could switch between folders) */
1456 helper = g_slice_new (OpenMsgHelper);
1457 helper->model = g_object_ref (gtk_tree_view_get_model (GTK_TREE_VIEW (header_view)));
1458 helper->header = g_object_ref (header);
1459 helper->rowref = gtk_tree_row_reference_copy (rowref);
1460 helper->banner_info = NULL;
1462 /* Connect to the account and perform */
1464 modest_platform_connect_and_perform ((GtkWindow *) win, TRUE, g_object_ref (account),
1465 open_msg_performer, helper);
1467 /* Call directly the performer, do not need to connect */
1468 open_msg_performer (FALSE, NULL, (GtkWindow *) win,
1469 g_object_ref (account), helper);
1474 g_object_unref (account);
1478 modest_ui_actions_on_open (GtkAction *action, ModestWindow *win)
1485 /* we check for low-mem; in that case, show a warning, and don't allow
1488 if (modest_platform_check_memory_low (MODEST_WINDOW(win), TRUE))
1492 headers = get_selected_headers (win);
1496 headers_count = tny_list_get_length (headers);
1497 if (headers_count != 1) {
1498 if (headers_count > 1) {
1499 /* Don't allow activation if there are more than one message selected */
1500 modest_platform_information_banner (NULL, NULL, _("mcen_ib_select_one_message"));
1503 g_object_unref (headers);
1507 iter = tny_list_create_iterator (headers);
1508 header = TNY_HEADER (tny_iterator_get_current (iter));
1509 g_object_unref (iter);
1513 open_msg_from_header (header, NULL, win);
1514 g_object_unref (header);
1517 g_object_unref(headers);
1520 static ReplyForwardHelper*
1521 create_reply_forward_helper (ReplyForwardAction action,
1523 guint reply_forward_type,
1526 ReplyForwardHelper *rf_helper = NULL;
1527 const gchar *active_acc = modest_window_get_active_account (win);
1529 rf_helper = g_slice_new0 (ReplyForwardHelper);
1530 rf_helper->reply_forward_type = reply_forward_type;
1531 rf_helper->action = action;
1532 rf_helper->parent_window = (MODEST_IS_WINDOW (win)) ? GTK_WIDGET (win) : NULL;
1533 rf_helper->header = (header) ? g_object_ref (header) : NULL;
1534 rf_helper->account_name = (active_acc) ?
1535 g_strdup (active_acc) :
1536 modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
1542 free_reply_forward_helper (gpointer data)
1544 ReplyForwardHelper *helper;
1546 helper = (ReplyForwardHelper *) data;
1547 g_free (helper->account_name);
1549 g_object_unref (helper->header);
1550 g_slice_free (ReplyForwardHelper, helper);
1554 reply_forward_cb (ModestMailOperation *mail_op,
1561 TnyMsg *new_msg = NULL;
1562 ReplyForwardHelper *rf_helper;
1563 ModestWindow *msg_win = NULL;
1564 ModestEditType edit_type;
1566 TnyAccount *account = NULL;
1567 ModestWindowMgr *mgr = NULL;
1568 gchar *signature = NULL;
1569 gboolean use_signature;
1571 /* If there was any error. The mail operation could be NULL,
1572 this means that we already have the message downloaded and
1573 that we didn't do a mail operation to retrieve it */
1574 rf_helper = (ReplyForwardHelper *) user_data;
1575 if (mail_op && !modest_ui_actions_msg_retrieval_check (mail_op, header, msg))
1578 from = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(),
1579 rf_helper->account_name);
1580 signature = modest_account_mgr_get_signature (modest_runtime_get_account_mgr(),
1581 rf_helper->account_name,
1584 /* Create reply mail */
1585 switch (rf_helper->action) {
1588 modest_tny_msg_create_reply_msg (msg, header, from,
1589 (use_signature) ? signature : NULL,
1590 rf_helper->reply_forward_type,
1591 MODEST_TNY_MSG_REPLY_MODE_SENDER);
1593 case ACTION_REPLY_TO_ALL:
1595 modest_tny_msg_create_reply_msg (msg, header, from,
1596 (use_signature) ? signature : NULL,
1597 rf_helper->reply_forward_type,
1598 MODEST_TNY_MSG_REPLY_MODE_ALL);
1599 edit_type = MODEST_EDIT_TYPE_REPLY;
1601 case ACTION_FORWARD:
1603 modest_tny_msg_create_forward_msg (msg, from, (use_signature) ? signature : NULL,
1604 rf_helper->reply_forward_type);
1605 edit_type = MODEST_EDIT_TYPE_FORWARD;
1608 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (),
1610 g_return_if_reached ();
1618 g_warning ("%s: failed to create message\n", __FUNCTION__);
1622 account = modest_tny_account_store_get_server_account (modest_runtime_get_account_store(),
1623 rf_helper->account_name,
1624 TNY_ACCOUNT_TYPE_STORE);
1626 g_warning ("%s: failed to get tnyaccount for '%s'\n", __FUNCTION__, rf_helper->account_name);
1630 /* Create and register the windows */
1631 msg_win = modest_msg_edit_window_new (new_msg, rf_helper->account_name, FALSE);
1632 mgr = modest_runtime_get_window_mgr ();
1633 modest_window_mgr_register_window (mgr, msg_win, (ModestWindow *) rf_helper->parent_window);
1635 if (rf_helper->parent_window != NULL) {
1636 gdouble parent_zoom;
1638 parent_zoom = modest_window_get_zoom (MODEST_WINDOW (rf_helper->parent_window));
1639 modest_window_set_zoom (msg_win, parent_zoom);
1642 /* Show edit window */
1643 gtk_widget_show_all (GTK_WIDGET (msg_win));
1646 /* We always unregister the header because the message is
1647 forwarded or replied so the original one is no longer
1649 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (),
1652 g_object_unref (G_OBJECT (new_msg));
1654 g_object_unref (G_OBJECT (account));
1655 free_reply_forward_helper (rf_helper);
1658 /* Checks a list of headers. If any of them are not currently
1659 * downloaded (CACHED) then returns TRUE else returns FALSE.
1662 header_list_count_uncached_msgs (TnyList *header_list)
1665 gint uncached_messages = 0;
1667 iter = tny_list_create_iterator (header_list);
1668 while (!tny_iterator_is_done (iter)) {
1671 header = TNY_HEADER (tny_iterator_get_current (iter));
1673 if (!(tny_header_get_flags (header) & TNY_HEADER_FLAG_CACHED))
1674 uncached_messages ++;
1675 g_object_unref (header);
1678 tny_iterator_next (iter);
1680 g_object_unref (iter);
1682 return uncached_messages;
1685 /* Returns FALSE if the user does not want to download the
1686 * messages. Returns TRUE if the user allowed the download.
1689 connect_to_get_msg (ModestWindow *win,
1690 gint num_of_uncached_msgs,
1691 TnyAccount *account)
1693 GtkResponseType response;
1695 /* Allways download if we are online. */
1696 if (tny_device_is_online (modest_runtime_get_device ()))
1699 /* If offline, then ask for user permission to download the messages */
1700 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
1701 ngettext("mcen_nc_get_msg",
1703 num_of_uncached_msgs));
1705 if (response == GTK_RESPONSE_CANCEL)
1708 return modest_platform_connect_and_wait((GtkWindow *) win, account);
1712 reply_forward_performer (gboolean canceled,
1714 GtkWindow *parent_window,
1715 TnyAccount *account,
1718 ReplyForwardHelper *rf_helper = NULL;
1719 ModestMailOperation *mail_op;
1721 rf_helper = (ReplyForwardHelper *) user_data;
1723 if (canceled || err) {
1724 free_reply_forward_helper (rf_helper);
1728 /* Retrieve the message */
1729 modest_window_mgr_register_header (modest_runtime_get_window_mgr (), rf_helper->header, NULL);
1730 mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT (parent_window),
1731 modest_ui_actions_disk_operations_error_handler,
1733 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
1734 modest_mail_operation_get_msg (mail_op, rf_helper->header, TRUE, reply_forward_cb, rf_helper);
1737 g_object_unref(mail_op);
1741 * Common code for the reply and forward actions
1744 reply_forward (ReplyForwardAction action, ModestWindow *win)
1746 ReplyForwardHelper *rf_helper = NULL;
1747 guint reply_forward_type;
1749 g_return_if_fail (MODEST_IS_WINDOW(win));
1751 /* we check for low-mem; in that case, show a warning, and don't allow
1752 * reply/forward (because it could potentially require a lot of memory */
1753 if (modest_platform_check_memory_low (MODEST_WINDOW(win), TRUE))
1757 /* we need an account when editing */
1758 if (!modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE)) {
1759 if (!modest_ui_actions_run_account_setup_wizard (win))
1763 reply_forward_type =
1764 modest_conf_get_int (modest_runtime_get_conf (),
1765 (action == ACTION_FORWARD) ?
1766 MODEST_CONF_FORWARD_TYPE :
1767 MODEST_CONF_REPLY_TYPE,
1770 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
1772 TnyHeader *header = NULL;
1773 /* Get header and message. Do not free them here, the
1774 reply_forward_cb must do it */
1775 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW(win));
1776 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
1778 if (msg && header) {
1780 rf_helper = create_reply_forward_helper (action, win,
1781 reply_forward_type, header);
1782 reply_forward_cb (NULL, header, FALSE, msg, NULL, rf_helper);
1784 g_warning("%s: no message or header found in viewer\n", __FUNCTION__);
1788 g_object_unref (msg);
1790 g_object_unref (header);
1792 TnyHeader *header = NULL;
1794 gboolean do_retrieve = TRUE;
1795 TnyList *header_list = NULL;
1797 header_list = get_selected_headers (win);
1800 /* Check that only one message is selected for replying */
1801 if (tny_list_get_length (header_list) != 1) {
1802 modest_platform_information_banner ((win) ? GTK_WIDGET (win) : NULL,
1803 NULL, _("mcen_ib_select_one_message"));
1804 g_object_unref (header_list);
1808 /* Only reply/forward to one message */
1809 iter = tny_list_create_iterator (header_list);
1810 header = TNY_HEADER (tny_iterator_get_current (iter));
1811 g_object_unref (iter);
1813 /* Retrieve messages */
1814 do_retrieve = (action == ACTION_FORWARD) ||
1815 (reply_forward_type != MODEST_TNY_MSG_REPLY_TYPE_CITE);
1818 TnyAccount *account = NULL;
1819 TnyFolder *folder = NULL;
1820 gdouble download = TRUE;
1821 guint uncached_msgs = 0;
1823 folder = tny_header_get_folder (header);
1825 goto do_retrieve_frees;
1826 account = tny_folder_get_account (folder);
1828 goto do_retrieve_frees;
1830 uncached_msgs = header_list_count_uncached_msgs (header_list);
1832 if (uncached_msgs > 0) {
1833 /* Allways download if we are online. */
1834 if (!tny_device_is_online (modest_runtime_get_device ())) {
1837 /* If ask for user permission to download the messages */
1838 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
1839 ngettext("mcen_nc_get_msg",
1843 /* End if the user does not want to continue */
1844 if (response == GTK_RESPONSE_CANCEL)
1851 rf_helper = create_reply_forward_helper (action, win,
1852 reply_forward_type, header);
1853 if (uncached_msgs > 0) {
1854 modest_platform_connect_and_perform (GTK_WINDOW (win),
1856 reply_forward_performer,
1859 reply_forward_performer (FALSE, NULL, GTK_WINDOW (win),
1860 account, rf_helper);
1865 g_object_unref (account);
1867 g_object_unref (folder);
1869 reply_forward_cb (NULL, header, FALSE, NULL, NULL, rf_helper);
1872 g_object_unref (header_list);
1873 g_object_unref (header);
1878 modest_ui_actions_on_reply (GtkAction *action, ModestWindow *win)
1880 g_return_if_fail (MODEST_IS_WINDOW(win));
1882 reply_forward (ACTION_REPLY, win);
1886 modest_ui_actions_on_forward (GtkAction *action, ModestWindow *win)
1888 g_return_if_fail (MODEST_IS_WINDOW(win));
1890 reply_forward (ACTION_FORWARD, win);
1894 modest_ui_actions_on_reply_all (GtkAction *action, ModestWindow *win)
1896 g_return_if_fail (MODEST_IS_WINDOW(win));
1898 reply_forward (ACTION_REPLY_TO_ALL, win);
1902 modest_ui_actions_on_next (GtkAction *action,
1903 ModestWindow *window)
1905 if (MODEST_IS_MAIN_WINDOW (window)) {
1906 GtkWidget *header_view;
1908 header_view = modest_main_window_get_child_widget (
1909 MODEST_MAIN_WINDOW(window),
1910 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1914 modest_header_view_select_next (
1915 MODEST_HEADER_VIEW(header_view));
1916 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
1917 modest_msg_view_window_select_next_message (
1918 MODEST_MSG_VIEW_WINDOW (window));
1920 g_return_if_reached ();
1925 modest_ui_actions_on_prev (GtkAction *action,
1926 ModestWindow *window)
1928 g_return_if_fail (MODEST_IS_WINDOW(window));
1930 if (MODEST_IS_MAIN_WINDOW (window)) {
1931 GtkWidget *header_view;
1932 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
1933 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1937 modest_header_view_select_prev (MODEST_HEADER_VIEW(header_view));
1938 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
1939 modest_msg_view_window_select_previous_message (MODEST_MSG_VIEW_WINDOW (window));
1941 g_return_if_reached ();
1946 modest_ui_actions_on_sort (GtkAction *action,
1947 ModestWindow *window)
1949 GtkWidget *header_view = NULL;
1951 g_return_if_fail (MODEST_IS_WINDOW(window));
1953 if (MODEST_IS_MAIN_WINDOW (window)) {
1954 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
1955 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1956 #ifdef MODEST_TOOLKIT_HILDON2
1957 } else if (MODEST_IS_HEADER_WINDOW (window)) {
1958 header_view = GTK_WIDGET (modest_header_window_get_header_view (MODEST_HEADER_WINDOW (window)));
1963 modest_platform_information_banner (NULL, NULL, _CS("ckdg_ib_nothing_to_sort"));
1968 /* Show sorting dialog */
1969 modest_utils_run_sort_dialog (GTK_WINDOW (window), MODEST_SORT_HEADERS);
1973 new_messages_arrived (ModestMailOperation *self,
1974 TnyList *new_headers,
1978 gboolean show_visual_notifications;
1980 source = modest_mail_operation_get_source (self);
1981 show_visual_notifications = (source) ? FALSE : TRUE;
1983 g_object_unref (source);
1985 /* Notify new messages have been downloaded. If the
1986 send&receive was invoked by the user then do not show any
1987 visual notification, only play a sound and activate the LED
1988 (for the Maemo version) */
1989 if (TNY_IS_LIST(new_headers) && (tny_list_get_length (new_headers)) > 0)
1990 modest_platform_on_new_headers_received (new_headers,
1991 show_visual_notifications);
1996 retrieve_all_messages_cb (GObject *source,
1998 guint retrieve_limit)
2004 window = GTK_WINDOW (source);
2005 msg = g_strdup_printf (_("mail_nc_msg_count_limit_exceeded"),
2006 num_msgs, retrieve_limit);
2008 /* Ask the user if they want to retrieve all the messages */
2010 modest_platform_run_confirmation_dialog_with_buttons (window, msg,
2011 _("mcen_bd_get_all"),
2012 _("mcen_bd_newest_only"));
2013 /* Free and return */
2015 return (response == GTK_RESPONSE_ACCEPT) ? TRUE : FALSE;
2019 TnyAccount *account;
2021 gchar *account_name;
2022 gboolean poke_status;
2023 gboolean interactive;
2024 ModestMailOperation *mail_op;
2028 do_send_receive_performer (gboolean canceled,
2030 GtkWindow *parent_window,
2031 TnyAccount *account,
2034 SendReceiveInfo *info;
2036 info = (SendReceiveInfo *) user_data;
2038 if (err || canceled) {
2039 /* In memory full conditions we could get this error here */
2040 check_memory_full_error ((GtkWidget *) parent_window, err);
2042 if (info->mail_op) {
2043 modest_mail_operation_queue_remove (modest_runtime_get_mail_operation_queue (),
2049 /* Set send/receive operation in progress */
2050 if (info->win && MODEST_IS_MAIN_WINDOW (info->win)) {
2051 modest_main_window_notify_send_receive_initied (MODEST_MAIN_WINDOW (info->win));
2054 if (info->win && MODEST_IS_MAIN_WINDOW (info->win))
2055 g_signal_connect (G_OBJECT (info->mail_op), "operation-finished",
2056 G_CALLBACK (on_send_receive_finished),
2059 /* Send & receive. */
2060 modest_mail_operation_update_account (info->mail_op, info->account_name, info->poke_status, info->interactive,
2061 (info->win) ? retrieve_all_messages_cb : NULL,
2062 new_messages_arrived, info->win);
2067 g_object_unref (G_OBJECT (info->mail_op));
2068 if (info->account_name)
2069 g_free (info->account_name);
2071 g_object_unref (info->win);
2073 g_object_unref (info->account);
2074 g_slice_free (SendReceiveInfo, info);
2078 * This function performs the send & receive required actions. The
2079 * window is used to create the mail operation. Typically it should
2080 * always be the main window, but we pass it as argument in order to
2084 modest_ui_actions_do_send_receive (const gchar *account_name,
2085 gboolean force_connection,
2086 gboolean poke_status,
2087 gboolean interactive,
2090 gchar *acc_name = NULL;
2091 SendReceiveInfo *info;
2092 ModestTnyAccountStore *acc_store;
2094 /* If no account name was provided then get the current account, and if
2095 there is no current account then pick the default one: */
2096 if (!account_name) {
2098 acc_name = g_strdup (modest_window_get_active_account (win));
2100 acc_name = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
2102 g_printerr ("modest: cannot get default account\n");
2106 acc_name = g_strdup (account_name);
2109 acc_store = modest_runtime_get_account_store ();
2111 /* Create the info for the connect and perform */
2112 info = g_slice_new (SendReceiveInfo);
2113 info->account_name = acc_name;
2114 info->win = (win) ? g_object_ref (win) : NULL;
2115 info->poke_status = poke_status;
2116 info->interactive = interactive;
2117 info->account = modest_tny_account_store_get_server_account (acc_store, acc_name,
2118 TNY_ACCOUNT_TYPE_STORE);
2119 /* We need to create the operation here, because otherwise it
2120 could happen that the queue emits the queue-empty signal
2121 while we're trying to connect the account */
2122 info->mail_op = modest_mail_operation_new_with_error_handling ((info->win) ? G_OBJECT (info->win) : NULL,
2123 modest_ui_actions_disk_operations_error_handler,
2125 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), info->mail_op);
2127 /* Invoke the connect and perform */
2128 modest_platform_connect_and_perform ((win) ? GTK_WINDOW (win) : NULL,
2129 force_connection, info->account,
2130 do_send_receive_performer, info);
2135 modest_ui_actions_do_cancel_send (const gchar *account_name,
2138 TnyTransportAccount *transport_account;
2139 TnySendQueue *send_queue = NULL;
2140 GError *error = NULL;
2142 /* Get transport account */
2144 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
2145 (modest_runtime_get_account_store(),
2147 TNY_ACCOUNT_TYPE_TRANSPORT));
2148 if (!transport_account) {
2149 g_printerr ("modest: no transport account found for '%s'\n", account_name);
2154 send_queue = TNY_SEND_QUEUE (modest_runtime_get_send_queue (transport_account, TRUE));
2155 if (!TNY_IS_SEND_QUEUE(send_queue)) {
2156 g_set_error (&error, MODEST_MAIL_OPERATION_ERROR,
2157 MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND,
2158 "modest: could not find send queue for account\n");
2160 /* Cancel the current send */
2161 tny_account_cancel (TNY_ACCOUNT (transport_account));
2163 /* Suspend all pending messages */
2164 tny_send_queue_cancel (send_queue, TNY_SEND_QUEUE_CANCEL_ACTION_SUSPEND, &error);
2168 if (transport_account != NULL)
2169 g_object_unref (G_OBJECT (transport_account));
2173 modest_ui_actions_cancel_send_all (ModestWindow *win)
2175 GSList *account_names, *iter;
2177 account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
2180 iter = account_names;
2182 modest_ui_actions_do_cancel_send ((const char*) iter->data, win);
2183 iter = g_slist_next (iter);
2186 modest_account_mgr_free_account_names (account_names);
2187 account_names = NULL;
2191 modest_ui_actions_cancel_send (GtkAction *action, ModestWindow *win)
2194 /* Check if accounts exist */
2195 gboolean accounts_exist =
2196 modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
2198 /* If not, allow the user to create an account before trying to send/receive. */
2199 if (!accounts_exist)
2200 modest_ui_actions_on_accounts (NULL, win);
2202 /* Cancel all sending operaitons */
2203 modest_ui_actions_cancel_send_all (win);
2207 * Refreshes all accounts. This function will be used by automatic
2211 modest_ui_actions_do_send_receive_all (ModestWindow *win,
2212 gboolean force_connection,
2213 gboolean poke_status,
2214 gboolean interactive)
2216 GSList *account_names, *iter;
2218 account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
2221 iter = account_names;
2223 modest_ui_actions_do_send_receive ((const char*) iter->data,
2225 poke_status, interactive, win);
2226 iter = g_slist_next (iter);
2229 modest_account_mgr_free_account_names (account_names);
2230 account_names = NULL;
2234 * Handler of the click on Send&Receive button in the main toolbar
2237 modest_ui_actions_on_send_receive (GtkAction *action, ModestWindow *win)
2239 /* Check if accounts exist */
2240 gboolean accounts_exist;
2243 modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
2245 /* If not, allow the user to create an account before trying to send/receive. */
2246 if (!accounts_exist)
2247 modest_ui_actions_on_accounts (NULL, win);
2249 /* Refresh the current folder. The if is always TRUE it's just an extra check */
2250 if (MODEST_IS_MAIN_WINDOW (win)) {
2251 GtkWidget *folder_view;
2252 TnyFolderStore *folder_store;
2255 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
2256 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2260 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
2263 g_object_unref (folder_store);
2264 /* Refresh the active account. Force the connection if needed
2265 and poke the status of all folders */
2266 modest_ui_actions_do_send_receive (NULL, TRUE, TRUE, TRUE, win);
2268 const gchar *active_account;
2269 active_account = modest_window_get_active_account (MODEST_WINDOW (win));
2271 modest_ui_actions_do_send_receive (active_account, TRUE, TRUE, TRUE, win);
2278 modest_ui_actions_toggle_header_list_view (GtkAction *action, ModestMainWindow *main_window)
2281 GtkWidget *header_view;
2283 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2285 header_view = modest_main_window_get_child_widget (main_window,
2286 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2290 conf = modest_runtime_get_conf ();
2292 /* what is saved/restored is depending on the style; thus; we save with
2293 * old style, then update the style, and restore for this new style
2295 modest_widget_memory_save (conf, G_OBJECT(header_view), MODEST_CONF_HEADER_VIEW_KEY);
2297 if (modest_header_view_get_style
2298 (MODEST_HEADER_VIEW(header_view)) == MODEST_HEADER_VIEW_STYLE_DETAILS)
2299 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
2300 MODEST_HEADER_VIEW_STYLE_TWOLINES);
2302 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
2303 MODEST_HEADER_VIEW_STYLE_DETAILS);
2305 modest_widget_memory_restore (conf, G_OBJECT(header_view),
2306 MODEST_CONF_HEADER_VIEW_KEY);
2311 modest_ui_actions_on_header_selected (ModestHeaderView *header_view,
2313 ModestMainWindow *main_window)
2315 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2316 g_return_if_fail (MODEST_IS_HEADER_VIEW (header_view));
2318 /* in the case the folder is empty, show the empty folder message and focus
2320 if (!header && gtk_widget_is_focus (GTK_WIDGET (header_view))) {
2321 if (modest_header_view_is_empty (header_view)) {
2322 TnyFolder *folder = modest_header_view_get_folder (header_view);
2323 GtkWidget *folder_view =
2324 modest_main_window_get_child_widget (main_window,
2325 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2326 if (folder != NULL) {
2327 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view), folder, FALSE);
2328 g_object_unref (folder);
2330 gtk_widget_grab_focus (GTK_WIDGET (folder_view));
2334 /* If no header has been selected then exit */
2339 if (!gtk_widget_is_focus (GTK_WIDGET(header_view)))
2340 gtk_widget_grab_focus (GTK_WIDGET(header_view));
2342 /* Update toolbar dimming state */
2343 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (main_window));
2344 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
2348 modest_ui_actions_on_header_activated (ModestHeaderView *header_view,
2351 ModestWindow *window)
2353 GtkWidget *open_widget;
2354 GtkTreeRowReference *rowref;
2356 g_return_if_fail (MODEST_IS_WINDOW(window));
2357 g_return_if_fail (MODEST_IS_HEADER_VIEW (header_view));
2358 g_return_if_fail (TNY_IS_HEADER (header));
2360 if (modest_header_view_count_selected_headers (header_view) > 1) {
2361 /* Don't allow activation if there are more than one message selected */
2362 modest_platform_information_banner (NULL, NULL, _("mcen_ib_select_one_message"));
2366 /* we check for low-mem; in that case, show a warning, and don't allow
2367 * activating headers
2369 if (modest_platform_check_memory_low (MODEST_WINDOW(window), TRUE))
2372 if (MODEST_IS_MAIN_WINDOW (window)) {
2373 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (window));
2374 open_widget = modest_window_get_action_widget (MODEST_WINDOW (window), "/MenuBar/EmailMenu/EmailOpenMenu");
2375 if (!GTK_WIDGET_IS_SENSITIVE (open_widget))
2379 rowref = gtk_tree_row_reference_new (gtk_tree_view_get_model (GTK_TREE_VIEW (header_view)), path);
2380 open_msg_from_header (header, rowref, MODEST_WINDOW (window));
2381 gtk_tree_row_reference_free (rowref);
2385 set_active_account_from_tny_account (TnyAccount *account,
2386 ModestWindow *window)
2388 const gchar *server_acc_name = tny_account_get_id (account);
2390 /* We need the TnyAccount provided by the
2391 account store because that is the one that
2392 knows the name of the Modest account */
2393 TnyAccount *modest_server_account = modest_server_account =
2394 modest_tny_account_store_get_tny_account_by (modest_runtime_get_account_store (),
2395 MODEST_TNY_ACCOUNT_STORE_QUERY_ID,
2397 if (!modest_server_account) {
2398 g_warning ("%s: could not get tny account\n", __FUNCTION__);
2402 /* Update active account, but only if it's not a pseudo-account */
2403 if ((!modest_tny_account_is_virtual_local_folders(modest_server_account)) &&
2404 (!modest_tny_account_is_memory_card_account(modest_server_account))) {
2405 const gchar *modest_acc_name =
2406 modest_tny_account_get_parent_modest_account_name_for_server_account (modest_server_account);
2407 if (modest_acc_name)
2408 modest_window_set_active_account (window, modest_acc_name);
2411 g_object_unref (modest_server_account);
2416 folder_refreshed_cb (ModestMailOperation *mail_op,
2420 ModestMainWindow *win = NULL;
2421 GtkWidget *folder_view;
2422 const GError *error;
2424 g_return_if_fail (TNY_IS_FOLDER (folder));
2426 win = MODEST_MAIN_WINDOW (user_data);
2428 /* Check if the operation failed due to memory low conditions */
2429 error = modest_mail_operation_get_error (mail_op);
2430 if (error && error->domain == MODEST_MAIL_OPERATION_ERROR &&
2431 error->code == MODEST_MAIL_OPERATION_ERROR_LOW_MEMORY) {
2432 modest_platform_run_information_dialog (GTK_WINDOW (win),
2433 dgettext("ke-recv","memr_ib_operation_disabled"),
2439 modest_main_window_get_child_widget(win, MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2442 TnyFolderStore *current_folder;
2444 current_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
2445 if (current_folder) {
2446 gboolean different = ((TnyFolderStore *) folder != current_folder);
2447 g_object_unref (current_folder);
2453 /* Check if folder is empty and set headers view contents style */
2454 if (tny_folder_get_all_count (folder) == 0)
2455 modest_main_window_set_contents_style (win,
2456 MODEST_MAIN_WINDOW_CONTENTS_STYLE_EMPTY);
2461 modest_ui_actions_on_folder_selection_changed (ModestFolderView *folder_view,
2462 TnyFolderStore *folder_store,
2464 ModestMainWindow *main_window)
2467 GtkWidget *header_view;
2469 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2471 header_view = modest_main_window_get_child_widget(main_window,
2472 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2476 conf = modest_runtime_get_conf ();
2478 if (TNY_IS_ACCOUNT (folder_store)) {
2480 set_active_account_from_tny_account (TNY_ACCOUNT (folder_store), MODEST_WINDOW (main_window));
2482 /* Show account details */
2483 modest_main_window_set_contents_style (main_window, MODEST_MAIN_WINDOW_CONTENTS_STYLE_DETAILS);
2486 if (TNY_IS_FOLDER (folder_store) && selected) {
2487 TnyAccount *account;
2488 const gchar *account_name = NULL;
2490 /* Update the active account */
2491 account = modest_tny_folder_get_account (TNY_FOLDER (folder_store));
2493 set_active_account_from_tny_account (account, MODEST_WINDOW (main_window));
2495 modest_tny_account_get_parent_modest_account_name_for_server_account (account);
2496 g_object_unref (account);
2500 /* Set the header style by default, it could
2501 be changed later by the refresh callback to
2503 modest_main_window_set_contents_style (main_window,
2504 MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS);
2506 /* Set folder on header view. This function
2507 will call tny_folder_refresh_async so we
2508 pass a callback that will be called when
2509 finished. We use that callback to set the
2510 empty view if there are no messages */
2511 modest_header_view_set_folder (MODEST_HEADER_VIEW(header_view),
2512 TNY_FOLDER (folder_store),
2514 MODEST_WINDOW (main_window),
2515 folder_refreshed_cb,
2518 /* Restore configuration. We need to do this
2519 *after* the set_folder because the widget
2520 memory asks the header view about its
2522 modest_widget_memory_restore (modest_runtime_get_conf (),
2523 G_OBJECT(header_view),
2524 MODEST_CONF_HEADER_VIEW_KEY);
2526 /* No need to save the header view
2527 configuration for Maemo because it only
2528 saves the sorting stuff and that it's
2529 already being done by the sort
2530 dialog. Remove it when the GNOME version
2531 has the same behaviour */
2532 #ifdef MODEST_TOOLKIT_GTK
2533 if (modest_main_window_get_contents_style (main_window) ==
2534 MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS)
2535 modest_widget_memory_save (conf, G_OBJECT (header_view),
2536 MODEST_CONF_HEADER_VIEW_KEY);
2538 modest_header_view_clear (MODEST_HEADER_VIEW(header_view));
2542 /* Update dimming state */
2543 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (main_window));
2544 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
2548 modest_ui_actions_on_item_not_found (ModestHeaderView *header_view,ModestItemType type,
2555 item = (type == MODEST_ITEM_TYPE_FOLDER) ? "folder" : "message";
2557 online = tny_device_is_online (modest_runtime_get_device());
2560 /* already online -- the item is simply not there... */
2561 dialog = gtk_message_dialog_new (GTK_WINDOW (win),
2563 GTK_MESSAGE_WARNING,
2565 _("The %s you selected cannot be found"),
2567 gtk_dialog_add_button (GTK_DIALOG (dialog),_("mcen_bd_dialog_ok"), GTK_RESPONSE_ACCEPT);
2568 gtk_dialog_run (GTK_DIALOG(dialog));
2570 dialog = gtk_dialog_new_with_buttons (_("Connection requested"),
2573 _("mcen_bd_dialog_cancel"),
2574 GTK_RESPONSE_REJECT,
2575 _("mcen_bd_dialog_ok"),
2576 GTK_RESPONSE_ACCEPT,
2578 txt = g_strdup_printf (_("This %s is not available in offline mode.\n"
2579 "Do you want to get online?"), item);
2580 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
2581 gtk_label_new (txt), FALSE, FALSE, 0);
2582 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
2585 gtk_window_set_default_size (GTK_WINDOW(dialog), 300, 300);
2586 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
2587 /* TODO: Comment about why is this commented out: */
2588 /* modest_platform_connect_and_wait (); */
2591 gtk_widget_destroy (dialog);
2595 modest_ui_actions_on_msg_link_hover (ModestMsgView *msgview, const gchar* link,
2598 /* g_message ("%s %s", __FUNCTION__, link); */
2603 modest_ui_actions_on_msg_link_clicked (ModestMsgView *msgview, const gchar* link,
2606 modest_platform_activate_uri (link);
2610 modest_ui_actions_on_msg_link_contextual (ModestMsgView *msgview, const gchar* link,
2613 modest_platform_show_uri_popup (link);
2617 modest_ui_actions_on_msg_attachment_clicked (ModestMsgView *msgview, TnyMimePart *mime_part,
2620 /* we check for low-mem; in that case, show a warning, and don't allow
2621 * viewing attachments
2623 if (modest_platform_check_memory_low (MODEST_WINDOW(win), TRUE))
2626 modest_msg_view_window_view_attachment (MODEST_MSG_VIEW_WINDOW (win), mime_part);
2630 modest_ui_actions_on_msg_recpt_activated (ModestMsgView *msgview,
2631 const gchar *address,
2634 /* g_message ("%s %s", __FUNCTION__, address); */
2638 on_save_to_drafts_cb (ModestMailOperation *mail_op,
2639 TnyMsg *saved_draft,
2642 ModestMsgEditWindow *edit_window;
2644 /* TODO: in hildon 2 we have to dim and undim the header views while we're saving */
2645 #ifndef MODEST_TOOLKIT_HILDON2
2646 ModestMainWindow *win;
2648 /* FIXME. Make the header view sensitive again. This is a
2649 * temporary hack. See modest_ui_actions_on_save_to_drafts()
2651 win = MODEST_MAIN_WINDOW(modest_window_mgr_get_main_window(
2652 modest_runtime_get_window_mgr(), FALSE));
2654 GtkWidget *hdrview = modest_main_window_get_child_widget(
2655 win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2656 if (hdrview) gtk_widget_set_sensitive(hdrview, TRUE);
2660 edit_window = MODEST_MSG_EDIT_WINDOW (user_data);
2662 /* Set draft is there was no error */
2663 if (!modest_mail_operation_get_error (mail_op))
2664 modest_msg_edit_window_set_draft (edit_window, saved_draft);
2666 g_object_unref(edit_window);
2670 enough_space_for_message (ModestMsgEditWindow *edit_window,
2673 TnyAccountStore *acc_store;
2674 guint64 available_disk, expected_size;
2679 acc_store = TNY_ACCOUNT_STORE (modest_runtime_get_account_store());
2680 available_disk = modest_utils_get_available_space (NULL);
2681 modest_msg_edit_window_get_parts_size (edit_window, &parts_count, &parts_size);
2682 expected_size = modest_tny_msg_estimate_size (data->plain_body,
2687 /* Double check: memory full condition or message too big */
2688 if (available_disk < MIN_FREE_SPACE ||
2689 expected_size > available_disk) {
2691 modest_platform_information_banner (NULL, NULL,
2693 "cerm_device_memory_full"));
2698 * djcb: if we're in low-memory state, we only allow for
2699 * saving messages smaller than
2700 * MODEST_MAX_LOW_MEMORY_MESSAGE_SIZE (see modest-defs.h) this
2701 * should still allow for sending anything critical...
2703 if ((expected_size > MODEST_MAX_LOW_MEMORY_MESSAGE_SIZE) &&
2704 modest_platform_check_memory_low (MODEST_WINDOW(edit_window), TRUE))
2708 * djcb: we also make sure that the attachments are smaller than the max size
2709 * this is for the case where we'd try to forward a message with attachments
2710 * bigger than our max allowed size, or sending an message from drafts which
2711 * somehow got past our checks when attaching.
2713 if (expected_size > MODEST_MAX_ATTACHMENT_SIZE) {
2714 modest_platform_run_information_dialog (
2715 GTK_WINDOW(edit_window),
2716 dgettext("ke-recv","memr_ib_operation_disabled"),
2725 modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edit_window)
2727 TnyTransportAccount *transport_account;
2728 ModestMailOperation *mail_operation;
2730 gchar *account_name, *from;
2731 ModestAccountMgr *account_mgr;
2732 gboolean had_error = FALSE;
2733 ModestMainWindow *win = NULL;
2735 g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window), FALSE);
2737 data = modest_msg_edit_window_get_msg_data (edit_window);
2740 if (!enough_space_for_message (edit_window, data)) {
2741 modest_msg_edit_window_free_msg_data (edit_window, data);
2745 account_name = g_strdup (data->account_name);
2746 account_mgr = modest_runtime_get_account_mgr();
2748 account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
2750 account_name = modest_account_mgr_get_default_account (account_mgr);
2751 if (!account_name) {
2752 g_printerr ("modest: no account found\n");
2753 modest_msg_edit_window_free_msg_data (edit_window, data);
2757 if (!strcmp (account_name, MODEST_LOCAL_FOLDERS_ACCOUNT_ID)) {
2758 account_name = g_strdup (data->account_name);
2762 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
2763 (modest_runtime_get_account_store (),
2765 TNY_ACCOUNT_TYPE_TRANSPORT));
2766 if (!transport_account) {
2767 g_printerr ("modest: no transport account found for '%s'\n", account_name);
2768 g_free (account_name);
2769 modest_msg_edit_window_free_msg_data (edit_window, data);
2772 from = modest_account_mgr_get_from_string (account_mgr, account_name);
2774 /* Create the mail operation */
2775 mail_operation = modest_mail_operation_new_with_error_handling (NULL, modest_ui_actions_disk_operations_error_handler,
2777 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
2779 modest_mail_operation_save_to_drafts (mail_operation,
2791 data->priority_flags,
2792 on_save_to_drafts_cb,
2793 g_object_ref(edit_window));
2795 #ifdef MODEST_TOOLKIT_HILDON2
2796 /* In hildon2 we always show the information banner on saving to drafts.
2797 * It will be a system information banner in this case.
2799 gchar *text = g_strdup_printf (_("mail_va_saved_to_drafts"), _("mcen_me_folder_drafts"));
2800 modest_platform_information_banner (NULL, NULL, text);
2803 /* Use the main window as the parent of the banner, if the
2804 main window does not exist it won't be shown, if the parent
2805 window exists then it's properly shown. We don't use the
2806 editor window because it could be closed (save to drafts
2807 could happen after closing the window */
2808 win = (ModestMainWindow *)
2809 modest_window_mgr_get_main_window( modest_runtime_get_window_mgr(), FALSE);
2811 gchar *text = g_strdup_printf (_("mail_va_saved_to_drafts"), _("mcen_me_folder_drafts"));
2812 modest_platform_information_banner (GTK_WIDGET (win), NULL, text);
2816 modest_msg_edit_window_set_modified (edit_window, FALSE);
2820 g_free (account_name);
2821 g_object_unref (G_OBJECT (transport_account));
2822 g_object_unref (G_OBJECT (mail_operation));
2824 modest_msg_edit_window_free_msg_data (edit_window, data);
2827 * If the drafts folder is selected then make the header view
2828 * insensitive while the message is being saved to drafts
2829 * (it'll be sensitive again in on_save_to_drafts_cb()). This
2830 * is not very clean but it avoids letting the drafts folder
2831 * in an inconsistent state: the user could edit the message
2832 * being saved and undesirable things would happen.
2833 * In the average case the user won't notice anything at
2834 * all. In the worst case (the user is editing a really big
2835 * file from Drafts) the header view will be insensitive
2836 * during the saving process (10 or 20 seconds, depending on
2837 * the message). Anyway this is just a quick workaround: once
2838 * we find a better solution it should be removed
2839 * See NB#65125 (commend #18) for details.
2841 if (!had_error && win != NULL) {
2842 ModestFolderView *view = MODEST_FOLDER_VIEW(modest_main_window_get_child_widget(
2843 win, MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW));
2845 TnyFolder *folder = TNY_FOLDER(modest_folder_view_get_selected(view));
2847 if (modest_tny_folder_is_local_folder(folder)) {
2848 TnyFolderType folder_type;
2849 folder_type = modest_tny_folder_get_local_or_mmc_folder_type(folder);
2850 if (folder_type == TNY_FOLDER_TYPE_DRAFTS) {
2851 GtkWidget *hdrview = modest_main_window_get_child_widget(
2852 win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2853 if (hdrview) gtk_widget_set_sensitive(hdrview, FALSE);
2857 if (folder != NULL) g_object_unref(folder);
2864 /* For instance, when clicking the Send toolbar button when editing a message: */
2866 modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
2868 TnyTransportAccount *transport_account = NULL;
2869 gboolean had_error = FALSE;
2871 ModestAccountMgr *account_mgr;
2872 gchar *account_name;
2874 ModestMailOperation *mail_operation;
2876 g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window), TRUE);
2878 if (!modest_msg_edit_window_check_names (edit_window, TRUE))
2881 data = modest_msg_edit_window_get_msg_data (edit_window);
2884 if (!enough_space_for_message (edit_window, data)) {
2885 modest_msg_edit_window_free_msg_data (edit_window, data);
2889 account_mgr = modest_runtime_get_account_mgr();
2890 account_name = g_strdup (data->account_name);
2892 account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
2895 account_name = modest_account_mgr_get_default_account (account_mgr);
2897 if (!account_name) {
2898 modest_msg_edit_window_free_msg_data (edit_window, data);
2899 /* Run account setup wizard */
2900 if (!modest_ui_actions_run_account_setup_wizard (MODEST_WINDOW(edit_window))) {
2905 /* Get the currently-active transport account for this modest account: */
2906 if (strcmp (account_name, MODEST_LOCAL_FOLDERS_ACCOUNT_ID) != 0) {
2908 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
2909 (modest_runtime_get_account_store (),
2910 account_name, TNY_ACCOUNT_TYPE_TRANSPORT));
2913 if (!transport_account) {
2914 modest_msg_edit_window_free_msg_data (edit_window, data);
2915 /* Run account setup wizard */
2916 if (!modest_ui_actions_run_account_setup_wizard(MODEST_WINDOW(edit_window)))
2921 /* Create the mail operation */
2922 from = modest_account_mgr_get_from_string (account_mgr, account_name);
2923 mail_operation = modest_mail_operation_new_with_error_handling (NULL, modest_ui_actions_disk_operations_error_handler, NULL, NULL);
2924 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
2926 modest_mail_operation_send_new_mail (mail_operation,
2938 data->priority_flags);
2940 if (modest_mail_operation_get_status (mail_operation) == MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS)
2941 modest_platform_information_banner (NULL, NULL, _("mcen_ib_outbox_waiting_to_be_sent"));
2944 if (modest_mail_operation_get_error (mail_operation) != NULL) {
2945 const GError *error = modest_mail_operation_get_error (mail_operation);
2946 if (error->domain == MODEST_MAIL_OPERATION_ERROR &&
2947 error->code == MODEST_MAIL_OPERATION_ERROR_INSTANCE_CREATION_FAILED) {
2948 g_warning ("%s failed: %s\n", __FUNCTION__, (modest_mail_operation_get_error (mail_operation))->message);
2949 modest_platform_information_banner (NULL, NULL, _CS("sfil_ni_not_enough_memory"));
2956 g_free (account_name);
2957 g_object_unref (G_OBJECT (transport_account));
2958 g_object_unref (G_OBJECT (mail_operation));
2960 modest_msg_edit_window_free_msg_data (edit_window, data);
2963 modest_msg_edit_window_set_sent (edit_window, TRUE);
2965 /* Save settings and close the window: */
2966 modest_ui_actions_on_close_window (NULL, MODEST_WINDOW (edit_window));
2973 modest_ui_actions_on_toggle_bold (GtkToggleAction *action,
2974 ModestMsgEditWindow *window)
2976 ModestMsgEditFormatState *format_state = NULL;
2978 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2979 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
2981 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2984 format_state = modest_msg_edit_window_get_format_state (window);
2985 g_return_if_fail (format_state != NULL);
2987 format_state->bold = gtk_toggle_action_get_active (action);
2988 modest_msg_edit_window_set_format_state (window, format_state);
2989 g_free (format_state);
2994 modest_ui_actions_on_toggle_italics (GtkToggleAction *action,
2995 ModestMsgEditWindow *window)
2997 ModestMsgEditFormatState *format_state = NULL;
2999 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3000 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
3002 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3005 format_state = modest_msg_edit_window_get_format_state (window);
3006 g_return_if_fail (format_state != NULL);
3008 format_state->italics = gtk_toggle_action_get_active (action);
3009 modest_msg_edit_window_set_format_state (window, format_state);
3010 g_free (format_state);
3015 modest_ui_actions_on_toggle_bullets (GtkToggleAction *action,
3016 ModestMsgEditWindow *window)
3018 ModestMsgEditFormatState *format_state = NULL;
3020 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3021 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
3023 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3026 format_state = modest_msg_edit_window_get_format_state (window);
3027 g_return_if_fail (format_state != NULL);
3029 format_state->bullet = gtk_toggle_action_get_active (action);
3030 modest_msg_edit_window_set_format_state (window, format_state);
3031 g_free (format_state);
3036 modest_ui_actions_on_change_justify (GtkRadioAction *action,
3037 GtkRadioAction *selected,
3038 ModestMsgEditWindow *window)
3040 ModestMsgEditFormatState *format_state = NULL;
3041 GtkJustification value;
3043 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3045 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3048 value = gtk_radio_action_get_current_value (selected);
3050 format_state = modest_msg_edit_window_get_format_state (window);
3051 g_return_if_fail (format_state != NULL);
3053 format_state->justification = value;
3054 modest_msg_edit_window_set_format_state (window, format_state);
3055 g_free (format_state);
3059 modest_ui_actions_on_select_editor_color (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_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3068 modest_msg_edit_window_select_color (window);
3072 modest_ui_actions_on_select_editor_background_color (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 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3081 modest_msg_edit_window_select_background_color (window);
3085 modest_ui_actions_on_insert_image (GtkAction *action,
3086 ModestMsgEditWindow *window)
3088 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3089 g_return_if_fail (GTK_IS_ACTION (action));
3092 if (modest_platform_check_memory_low (MODEST_WINDOW(window), TRUE))
3095 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3098 modest_msg_edit_window_insert_image (window);
3102 modest_ui_actions_on_attach_file (GtkAction *action,
3103 ModestMsgEditWindow *window)
3105 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3106 g_return_if_fail (GTK_IS_ACTION (action));
3108 if (modest_platform_check_memory_low (MODEST_WINDOW(window), TRUE))
3111 modest_msg_edit_window_offer_attach_file (window);
3115 modest_ui_actions_on_remove_attachments (GtkAction *action,
3116 ModestMsgEditWindow *window)
3118 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3119 g_return_if_fail (GTK_IS_ACTION (action));
3121 modest_msg_edit_window_remove_attachments (window, NULL);
3125 #ifndef MODEST_TOOLKIT_GTK
3130 TnyFolderStore *folder;
3131 } CreateFolderHelper;
3134 show_create_folder_in_timeout (gpointer data)
3136 CreateFolderHelper *helper = (CreateFolderHelper *) data;
3138 /* Remove the timeout ASAP, we can not wait until the dialog
3139 is shown because it could take a lot of time and so the
3140 timeout could be called twice or more times */
3141 g_source_remove (helper->handler);
3143 gdk_threads_enter ();
3144 do_create_folder (helper->win, helper->folder, helper->name);
3145 gdk_threads_leave ();
3147 g_object_unref (helper->win);
3148 g_object_unref (helper->folder);
3149 g_free (helper->name);
3150 g_slice_free (CreateFolderHelper, helper);
3157 do_create_folder_cb (ModestMailOperation *mail_op,
3158 TnyFolderStore *parent_folder,
3159 TnyFolder *new_folder,
3162 gchar *suggested_name = (gchar *) user_data;
3163 GtkWindow *source_win = (GtkWindow *) modest_mail_operation_get_source (mail_op);
3165 if (modest_mail_operation_get_error (mail_op)) {
3167 /* Show an error. If there was some problem writing to
3168 disk, show it, otherwise show the generic folder
3169 create error. We do it here and not in an error
3170 handler because the call to do_create_folder will
3171 stop the main loop in a gtk_dialog_run and then,
3172 the message won't be shown until that dialog is
3174 modest_ui_actions_disk_operations_error_handler (mail_op,
3175 _("mail_in_ui_folder_create_error"));
3177 /* Try again. Do *NOT* show any error because the mail
3178 operations system will do it for us because we
3179 created the mail_op with new_with_error_handler */
3180 #ifndef MODEST_TOOLKIT_GTK
3181 CreateFolderHelper *helper;
3182 helper = g_slice_new0 (CreateFolderHelper);
3183 helper->name = g_strdup (suggested_name);
3184 helper->folder = g_object_ref (parent_folder);
3185 helper->win = g_object_ref (source_win);
3187 /* Ugly but neccesary stuff. The problem is that the
3188 dialog when is shown calls a function that destroys
3189 all the temporary windows, so the banner is
3191 helper->handler = g_timeout_add (2000, show_create_folder_in_timeout, helper);
3193 do_create_folder (source_win, parent_folder, (const gchar *) suggested_name);
3196 /* the 'source_win' is either the ModestMainWindow, or the 'Move to folder'-dialog
3197 * FIXME: any other? */
3198 GtkWidget *folder_view;
3200 if (MODEST_IS_MAIN_WINDOW(source_win))
3202 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (source_win),
3203 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3205 folder_view = GTK_WIDGET(g_object_get_data (G_OBJECT (source_win),
3206 MODEST_MOVE_TO_DIALOG_FOLDER_VIEW));
3208 /* Select the newly created folder. It could happen
3209 that the widget is no longer there (i.e. the window
3210 has been destroyed, so we need to check this */
3212 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view),
3214 g_object_unref (new_folder);
3216 /* Free. Note that the first time it'll be NULL so noop */
3217 g_free (suggested_name);
3218 g_object_unref (source_win);
3222 do_create_folder (GtkWindow *parent_window,
3223 TnyFolderStore *parent_folder,
3224 const gchar *suggested_name)
3227 gchar *folder_name = NULL;
3229 result = modest_platform_run_new_folder_dialog (GTK_WINDOW (parent_window),
3231 (gchar *) suggested_name,
3234 if (result == GTK_RESPONSE_ACCEPT) {
3235 ModestMailOperation *mail_op;
3237 mail_op = modest_mail_operation_new ((GObject *) parent_window);
3238 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
3240 modest_mail_operation_create_folder (mail_op,
3242 (const gchar *) folder_name,
3243 do_create_folder_cb,
3245 g_object_unref (mail_op);
3250 create_folder_performer (gboolean canceled,
3252 GtkWindow *parent_window,
3253 TnyAccount *account,
3256 TnyFolderStore *parent_folder = TNY_FOLDER_STORE (user_data);
3258 if (canceled || err) {
3259 /* In memory full conditions we could get this error here */
3260 check_memory_full_error ((GtkWidget *) parent_window, err);
3264 /* Run the new folder dialog */
3265 do_create_folder (GTK_WINDOW (parent_window), parent_folder, NULL);
3268 g_object_unref (parent_folder);
3272 modest_ui_actions_create_folder(GtkWidget *parent_window,
3273 GtkWidget *folder_view)
3275 TnyFolderStore *parent_folder;
3277 parent_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
3279 if (parent_folder) {
3280 /* The parent folder will be freed in the callback */
3281 modest_platform_connect_if_remote_and_perform (GTK_WINDOW (parent_window),
3284 create_folder_performer,
3290 modest_ui_actions_on_new_folder (GtkAction *action, ModestMainWindow *main_window)
3292 GtkWidget *folder_view;
3294 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
3296 folder_view = modest_main_window_get_child_widget (main_window,
3297 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3301 modest_ui_actions_create_folder (GTK_WIDGET (main_window), folder_view);
3305 modest_ui_actions_rename_folder_error_handler (ModestMailOperation *mail_op,
3308 const GError *error = NULL;
3309 const gchar *message = NULL;
3311 /* Get error message */
3312 error = modest_mail_operation_get_error (mail_op);
3314 g_return_if_reached ();
3316 if (error->domain == MODEST_MAIL_OPERATION_ERROR &&
3317 error->code == MODEST_MAIL_OPERATION_ERROR_FOLDER_EXISTS) {
3318 message = _CS("ckdg_ib_folder_already_exists");
3319 } else if (error->domain == TNY_ERROR_DOMAIN &&
3320 error->code == TNY_SERVICE_ERROR_STATE) {
3321 /* This means that the folder is already in use (a
3322 message is opened for example */
3323 message = _("emev_ni_internal_error");
3325 message = _("emev_ib_ui_imap_unable_to_rename");
3328 /* We don't set a parent for the dialog because the dialog
3329 will be destroyed so the banner won't appear */
3330 modest_platform_information_banner (NULL, NULL, message);
3334 TnyFolderStore *folder;
3339 on_rename_folder_cb (ModestMailOperation *mail_op,
3340 TnyFolder *new_folder,
3343 ModestFolderView *folder_view;
3345 /* If the window was closed when renaming a folder this could
3347 if (!MODEST_IS_FOLDER_VIEW (user_data))
3350 folder_view = MODEST_FOLDER_VIEW (user_data);
3351 /* Note that if the rename fails new_folder will be NULL */
3353 modest_folder_view_select_folder (folder_view, new_folder, FALSE);
3355 modest_folder_view_select_first_inbox_or_local (folder_view);
3357 gtk_widget_grab_focus (GTK_WIDGET (folder_view));
3361 on_rename_folder_performer (gboolean canceled,
3363 GtkWindow *parent_window,
3364 TnyAccount *account,
3367 ModestMailOperation *mail_op = NULL;
3368 GtkTreeSelection *sel = NULL;
3369 GtkWidget *folder_view = NULL;
3370 RenameFolderInfo *data = (RenameFolderInfo*)user_data;
3372 if (canceled || err) {
3373 /* In memory full conditions we could get this error here */
3374 check_memory_full_error ((GtkWidget *) parent_window, err);
3375 } else if (MODEST_IS_MAIN_WINDOW(parent_window)) {
3377 folder_view = modest_main_window_get_child_widget (
3378 MODEST_MAIN_WINDOW (parent_window),
3379 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3382 modest_mail_operation_new_with_error_handling (G_OBJECT(parent_window),
3383 modest_ui_actions_rename_folder_error_handler,
3384 parent_window, NULL);
3386 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
3389 /* Clear the headers view */
3390 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_view));
3391 gtk_tree_selection_unselect_all (sel);
3393 /* Actually rename the folder */
3394 modest_mail_operation_rename_folder (mail_op,
3395 TNY_FOLDER (data->folder),
3396 (const gchar *) (data->new_name),
3397 on_rename_folder_cb,
3399 g_object_unref (data->folder);
3400 g_object_unref (mail_op);
3403 g_free (data->new_name);
3408 modest_ui_actions_on_rename_folder (GtkAction *action,
3409 ModestMainWindow *main_window)
3411 TnyFolderStore *folder;
3412 GtkWidget *folder_view;
3413 GtkWidget *header_view;
3415 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
3417 folder_view = modest_main_window_get_child_widget (main_window,
3418 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3422 header_view = modest_main_window_get_child_widget (main_window,
3423 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
3428 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
3433 if (TNY_IS_FOLDER (folder)) {
3434 gchar *folder_name = NULL;
3436 const gchar *current_name;
3437 TnyFolderStore *parent;
3438 gboolean do_rename = TRUE;
3440 current_name = tny_folder_get_name (TNY_FOLDER (folder));
3441 parent = tny_folder_get_folder_store (TNY_FOLDER (folder));
3442 response = modest_platform_run_rename_folder_dialog (GTK_WINDOW (main_window),
3443 parent, current_name,
3445 g_object_unref (parent);
3447 if (response != GTK_RESPONSE_ACCEPT || strlen (folder_name) == 0) {
3450 RenameFolderInfo *rename_folder_data = g_new0 (RenameFolderInfo, 1);
3451 rename_folder_data->folder = g_object_ref (folder);
3452 rename_folder_data->new_name = folder_name;
3453 modest_platform_connect_if_remote_and_perform (GTK_WINDOW(main_window), TRUE,
3454 folder, on_rename_folder_performer, rename_folder_data);
3457 g_object_unref (folder);
3461 modest_ui_actions_delete_folder_error_handler (ModestMailOperation *mail_op,
3464 GObject *win = modest_mail_operation_get_source (mail_op);
3466 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
3467 _("mail_in_ui_folder_delete_error"),
3469 g_object_unref (win);
3473 TnyFolderStore *folder;
3474 gboolean move_to_trash;
3478 on_delete_folder_cb (gboolean canceled,
3480 GtkWindow *parent_window,
3481 TnyAccount *account,
3484 DeleteFolderInfo *info = (DeleteFolderInfo*) user_data;
3485 GtkWidget *folder_view;
3486 ModestMailOperation *mail_op;
3487 GtkTreeSelection *sel;
3489 if (!MODEST_IS_MAIN_WINDOW(parent_window) || canceled || (err!=NULL)) {
3490 g_object_unref (G_OBJECT (info->folder));
3495 folder_view = modest_main_window_get_child_widget (
3496 MODEST_MAIN_WINDOW (parent_window),
3497 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3499 /* Unselect the folder before deleting it to free the headers */
3500 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_view));
3501 gtk_tree_selection_unselect_all (sel);
3503 /* Create the mail operation */
3505 modest_mail_operation_new_with_error_handling (G_OBJECT(parent_window),
3506 modest_ui_actions_delete_folder_error_handler,
3509 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
3511 modest_mail_operation_remove_folder (mail_op, TNY_FOLDER (info->folder), info->move_to_trash);
3513 modest_folder_view_select_first_inbox_or_local (MODEST_FOLDER_VIEW (folder_view));
3515 g_object_unref (G_OBJECT (mail_op));
3516 g_object_unref (G_OBJECT (info->folder));
3521 delete_folder (ModestMainWindow *main_window, gboolean move_to_trash)
3523 TnyFolderStore *folder;
3524 GtkWidget *folder_view;
3528 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
3530 folder_view = modest_main_window_get_child_widget (main_window,
3531 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3535 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
3537 /* Show an error if it's an account */
3538 if (!TNY_IS_FOLDER (folder)) {
3539 modest_platform_run_information_dialog (GTK_WINDOW (main_window),
3540 _("mail_in_ui_folder_delete_error"),
3542 g_object_unref (G_OBJECT (folder));
3547 message = g_strdup_printf (_("mcen_nc_delete_folder_text"),
3548 tny_folder_get_name (TNY_FOLDER (folder)));
3549 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (main_window),
3550 (const gchar *) message);
3553 if (response == GTK_RESPONSE_OK) {
3554 DeleteFolderInfo *info;
3555 info = g_new0(DeleteFolderInfo, 1);
3556 info->folder = folder;
3557 info->move_to_trash = move_to_trash;
3558 g_object_ref (G_OBJECT (info->folder));
3559 TnyAccount *account = tny_folder_get_account (TNY_FOLDER (folder));
3560 modest_platform_connect_if_remote_and_perform (GTK_WINDOW (main_window),
3562 TNY_FOLDER_STORE (account),
3563 on_delete_folder_cb, info);
3564 g_object_unref (account);
3566 g_object_unref (G_OBJECT (folder));
3570 modest_ui_actions_on_delete_folder (GtkAction *action,
3571 ModestMainWindow *main_window)
3573 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
3575 delete_folder (main_window, FALSE);
3579 modest_ui_actions_on_move_folder_to_trash_folder (GtkAction *action, ModestMainWindow *main_window)
3581 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
3583 delete_folder (main_window, TRUE);
3587 typedef struct _PasswordDialogFields {
3588 GtkWidget *username;
3589 GtkWidget *password;
3591 } PasswordDialogFields;
3594 password_dialog_check_field (GtkEditable *editable,
3595 PasswordDialogFields *fields)
3598 gboolean any_value_empty = FALSE;
3600 value = gtk_entry_get_text (GTK_ENTRY (fields->username));
3601 if ((value == NULL) || value[0] == '\0') {
3602 any_value_empty = TRUE;
3604 value = gtk_entry_get_text (GTK_ENTRY (fields->password));
3605 if ((value == NULL) || value[0] == '\0') {
3606 any_value_empty = TRUE;
3608 gtk_dialog_set_response_sensitive (GTK_DIALOG (fields->dialog), GTK_RESPONSE_ACCEPT, !any_value_empty);
3612 modest_ui_actions_on_password_requested (TnyAccountStore *account_store,
3613 const gchar* server_account_name,
3618 ModestMainWindow *main_window)
3620 g_return_if_fail(server_account_name);
3621 gboolean completed = FALSE;
3622 PasswordDialogFields *fields = NULL;
3624 /* Initalize output parameters: */
3631 #ifndef MODEST_TOOLKIT_GTK
3632 /* Maemo uses a different (awkward) button order,
3633 * It should probably just use gtk_alternative_dialog_button_order ().
3635 #ifdef MODEST_TOOLKIT_HILDON2
3637 gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
3640 _HL("wdgt_bd_done"),
3641 GTK_RESPONSE_ACCEPT,
3645 gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
3648 _("mcen_bd_dialog_ok"),
3649 GTK_RESPONSE_ACCEPT,
3650 _("mcen_bd_dialog_cancel"),
3651 GTK_RESPONSE_REJECT,
3653 #endif /* MODEST_TOOLKIT_HILDON2 */
3656 gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
3660 GTK_RESPONSE_REJECT,
3662 GTK_RESPONSE_ACCEPT,
3664 #endif /* MODEST_TOOLKIT_GTK */
3666 modest_window_mgr_set_modal (modest_runtime_get_window_mgr(), GTK_WINDOW (dialog), NULL);
3668 gchar *server_name = modest_account_mgr_get_server_account_hostname (
3669 modest_runtime_get_account_mgr(), server_account_name);
3670 if (!server_name) {/* This happened once, though I don't know why. murrayc. */
3671 g_warning("%s: Could not get server name for server account '%s'", __FUNCTION__, server_account_name);
3674 gtk_widget_destroy (dialog);
3678 gchar *txt = g_strdup_printf (_("mail_ia_password_info"), server_name);
3679 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), gtk_label_new(txt),
3682 g_free (server_name);
3686 gchar *initial_username = modest_account_mgr_get_server_account_username (
3687 modest_runtime_get_account_mgr(), server_account_name);
3689 GtkWidget *entry_username = gtk_entry_new ();
3690 if (initial_username)
3691 gtk_entry_set_text (GTK_ENTRY (entry_username), initial_username);
3692 /* Dim this if a connection has ever succeeded with this username,
3693 * as per the UI spec: */
3694 /* const gboolean username_known = */
3695 /* modest_account_mgr_get_server_account_username_has_succeeded( */
3696 /* modest_runtime_get_account_mgr(), server_account_name); */
3697 /* gtk_widget_set_sensitive (entry_username, !username_known); */
3699 /* We drop the username sensitive code and disallow changing it here
3700 * as tinymail does not support really changing the username in the callback
3702 gtk_widget_set_sensitive (entry_username, FALSE);
3704 #ifndef MODEST_TOOLKIT_GTK
3705 /* Auto-capitalization is the default, so let's turn it off: */
3706 hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_username), HILDON_GTK_INPUT_MODE_FULL);
3708 /* Create a size group to be used by all captions.
3709 * Note that HildonCaption does not create a default size group if we do not specify one.
3710 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
3711 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
3713 GtkWidget *caption = hildon_caption_new (sizegroup,
3714 _("mail_fi_username"), entry_username, NULL, HILDON_CAPTION_MANDATORY);
3715 gtk_widget_show (entry_username);
3716 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
3717 FALSE, FALSE, MODEST_MARGIN_HALF);
3718 gtk_widget_show (caption);
3720 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry_username,
3722 #endif /* !MODEST_TOOLKIT_GTK */
3725 GtkWidget *entry_password = gtk_entry_new ();
3726 gtk_entry_set_visibility (GTK_ENTRY(entry_password), FALSE);
3727 /* gtk_entry_set_invisible_char (GTK_ENTRY(entry_password), "*"); */
3729 #ifndef MODEST_TOOLKIT_GTK
3730 /* Auto-capitalization is the default, so let's turn it off: */
3731 hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_password),
3732 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
3734 caption = hildon_caption_new (sizegroup,
3735 _("mail_fi_password"), entry_password, NULL, HILDON_CAPTION_MANDATORY);
3736 gtk_widget_show (entry_password);
3737 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
3738 FALSE, FALSE, MODEST_MARGIN_HALF);
3739 gtk_widget_show (caption);
3740 g_object_unref (sizegroup);
3742 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry_password,
3744 #endif /* !MODEST_TOOLKIT_GTK */
3746 if (initial_username != NULL)
3747 gtk_widget_grab_focus (GTK_WIDGET (entry_password));
3749 /* This is not in the Maemo UI spec:
3750 remember_pass_check = gtk_check_button_new_with_label (_("Remember password"));
3751 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), remember_pass_check,
3755 fields = g_slice_new0 (PasswordDialogFields);
3756 fields->username = entry_username;
3757 fields->password = entry_password;
3758 fields->dialog = dialog;
3760 g_signal_connect (entry_username, "changed", G_CALLBACK (password_dialog_check_field), fields);
3761 g_signal_connect (entry_password, "changed", G_CALLBACK (password_dialog_check_field), fields);
3762 password_dialog_check_field (NULL, fields);
3764 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
3766 while (!completed) {
3768 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
3770 *username = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_username)));
3772 /* Note that an empty field becomes the "" string */
3773 if (*username && strlen (*username) > 0) {
3774 modest_account_mgr_set_server_account_username (modest_runtime_get_account_mgr(),
3775 server_account_name,
3779 const gboolean username_was_changed =
3780 (strcmp (*username, initial_username) != 0);
3781 if (username_was_changed) {
3782 g_warning ("%s: tinymail does not yet support changing the "
3783 "username in the get_password() callback.\n", __FUNCTION__);
3789 modest_platform_information_banner (GTK_WIDGET (dialog), NULL,
3790 _("mcen_ib_username_pw_incorrect"));
3796 *password = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_password)));
3798 /* We do not save the password in the configuration,
3799 * because this function is only called for passwords that should
3800 * not be remembered:
3801 modest_server_account_set_password (
3802 modest_runtime_get_account_mgr(), server_account_name,
3809 #ifndef MODEST_TOOLKIT_HILDON2
3810 /* Set parent to NULL or the banner will disappear with its parent dialog */
3811 modest_platform_information_banner(NULL, NULL, _("mail_ib_login_cancelled"));
3823 /* This is not in the Maemo UI spec:
3824 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (remember_pass_check)))
3830 g_free (initial_username);
3831 gtk_widget_destroy (dialog);
3832 g_slice_free (PasswordDialogFields, fields);
3834 /* printf ("DEBUG: %s: cancel=%d\n", __FUNCTION__, *cancel); */
3838 modest_ui_actions_on_cut (GtkAction *action,
3839 ModestWindow *window)
3841 GtkWidget *focused_widget;
3842 GtkClipboard *clipboard;
3844 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
3845 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
3846 if (GTK_IS_EDITABLE (focused_widget)) {
3847 gtk_editable_cut_clipboard (GTK_EDITABLE(focused_widget));
3848 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3849 gtk_clipboard_store (clipboard);
3850 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
3851 GtkTextBuffer *buffer;
3853 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
3854 if (modest_text_utils_buffer_selection_is_valid (buffer)) {
3855 gtk_text_buffer_cut_clipboard (buffer, clipboard, TRUE);
3856 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3857 gtk_clipboard_store (clipboard);
3859 } else if (MODEST_IS_HEADER_VIEW (focused_widget)) {
3860 TnyList *header_list = modest_header_view_get_selected_headers (
3861 MODEST_HEADER_VIEW (focused_widget));
3862 gboolean continue_download = FALSE;
3863 gint num_of_unc_msgs;
3865 num_of_unc_msgs = header_list_count_uncached_msgs(header_list);
3867 if (num_of_unc_msgs) {
3868 TnyAccount *account = get_account_from_header_list (header_list);
3870 continue_download = connect_to_get_msg (window, num_of_unc_msgs, account);
3871 g_object_unref (account);
3875 if (num_of_unc_msgs == 0 || continue_download) {
3876 /* modest_platform_information_banner (
3877 NULL, NULL, _CS("mcen_ib_getting_items"));*/
3878 modest_header_view_cut_selection (
3879 MODEST_HEADER_VIEW (focused_widget));
3882 g_object_unref (header_list);
3883 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
3884 modest_folder_view_cut_selection (MODEST_FOLDER_VIEW (focused_widget));
3889 modest_ui_actions_on_copy (GtkAction *action,
3890 ModestWindow *window)
3892 GtkClipboard *clipboard;
3893 GtkWidget *focused_widget;
3894 gboolean copied = TRUE;
3896 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
3897 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
3899 if (GTK_IS_LABEL (focused_widget)) {
3901 selection = modest_text_utils_label_get_selection (GTK_LABEL (focused_widget));
3902 gtk_clipboard_set_text (clipboard, selection, -1);
3904 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3905 gtk_clipboard_store (clipboard);
3906 } else if (GTK_IS_EDITABLE (focused_widget)) {
3907 gtk_editable_copy_clipboard (GTK_EDITABLE(focused_widget));
3908 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3909 gtk_clipboard_store (clipboard);
3910 } else if (GTK_IS_HTML (focused_widget)) {
3913 sel = gtk_html_get_selection_html (GTK_HTML (focused_widget), &len);
3914 if ((sel == NULL) || (sel[0] == '\0')) {
3917 gtk_html_copy (GTK_HTML (focused_widget));
3918 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3919 gtk_clipboard_store (clipboard);
3921 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
3922 GtkTextBuffer *buffer;
3923 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
3924 if (modest_text_utils_buffer_selection_is_valid (buffer)) {
3925 gtk_text_buffer_copy_clipboard (buffer, clipboard);
3926 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3927 gtk_clipboard_store (clipboard);
3929 } else if (MODEST_IS_HEADER_VIEW (focused_widget)) {
3930 TnyList *header_list = modest_header_view_get_selected_headers (
3931 MODEST_HEADER_VIEW (focused_widget));
3932 gboolean continue_download = FALSE;
3933 gint num_of_unc_msgs;
3935 num_of_unc_msgs = header_list_count_uncached_msgs(header_list);
3937 if (num_of_unc_msgs) {
3938 TnyAccount *account = get_account_from_header_list (header_list);
3940 continue_download = connect_to_get_msg (window, num_of_unc_msgs, account);
3941 g_object_unref (account);
3945 if (num_of_unc_msgs == 0 || continue_download) {
3946 modest_platform_information_banner (
3947 NULL, NULL, _CS("mcen_ib_getting_items"));
3948 modest_header_view_copy_selection (
3949 MODEST_HEADER_VIEW (focused_widget));
3953 g_object_unref (header_list);
3955 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
3956 modest_folder_view_copy_selection (MODEST_FOLDER_VIEW (focused_widget));
3959 /* Show information banner if there was a copy to clipboard */
3961 modest_platform_information_banner (
3962 NULL, NULL, _CS("ecoc_ib_edwin_copied"));
3966 modest_ui_actions_on_undo (GtkAction *action,
3967 ModestWindow *window)
3969 ModestEmailClipboard *clipboard = NULL;
3971 if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
3972 modest_msg_edit_window_undo (MODEST_MSG_EDIT_WINDOW (window));
3973 } else if (MODEST_IS_MAIN_WINDOW (window)) {
3974 /* Clear clipboard source */
3975 clipboard = modest_runtime_get_email_clipboard ();
3976 modest_email_clipboard_clear (clipboard);
3979 g_return_if_reached ();
3984 modest_ui_actions_on_redo (GtkAction *action,
3985 ModestWindow *window)
3987 if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
3988 modest_msg_edit_window_redo (MODEST_MSG_EDIT_WINDOW (window));
3991 g_return_if_reached ();
3997 destroy_information_note (ModestMailOperation *mail_op,
4000 /* destroy information note */
4001 gtk_widget_destroy (GTK_WIDGET(user_data));
4005 destroy_folder_information_note (ModestMailOperation *mail_op,
4006 TnyFolder *new_folder,
4009 /* destroy information note */
4010 gtk_widget_destroy (GTK_WIDGET(user_data));
4015 paste_as_attachment_free (gpointer data)
4017 PasteAsAttachmentHelper *helper = (PasteAsAttachmentHelper *) data;
4019 if (helper->banner) {
4020 gtk_widget_destroy (helper->banner);
4021 g_object_unref (helper->banner);
4027 paste_msg_as_attachment_cb (ModestMailOperation *mail_op,
4032 PasteAsAttachmentHelper *helper = (PasteAsAttachmentHelper *) userdata;
4033 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (helper->window));
4038 modest_msg_edit_window_add_part (MODEST_MSG_EDIT_WINDOW (helper->window), TNY_MIME_PART (msg));
4043 modest_ui_actions_on_paste (GtkAction *action,
4044 ModestWindow *window)
4046 GtkWidget *focused_widget = NULL;
4047 GtkWidget *inf_note = NULL;
4048 ModestMailOperation *mail_op = NULL;
4050 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
4051 if (GTK_IS_EDITABLE (focused_widget)) {
4052 gtk_editable_paste_clipboard (GTK_EDITABLE(focused_widget));
4053 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
4054 ModestEmailClipboard *e_clipboard = NULL;
4055 e_clipboard = modest_runtime_get_email_clipboard ();
4056 if (modest_email_clipboard_cleared (e_clipboard)) {
4057 GtkTextBuffer *buffer;
4058 GtkClipboard *clipboard;
4060 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
4061 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
4062 gtk_text_buffer_paste_clipboard (buffer, clipboard, NULL, TRUE);
4063 } else if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
4064 ModestMailOperation *mail_op;
4065 TnyFolder *src_folder = NULL;
4066 TnyList *data = NULL;
4068 PasteAsAttachmentHelper *helper = g_new0 (PasteAsAttachmentHelper, 1);
4069 helper->window = MODEST_MSG_EDIT_WINDOW (window);
4070 helper->banner = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
4071 _CS("ckct_nw_pasting"));
4072 modest_email_clipboard_get_data (e_clipboard, &src_folder, &data, &delete);
4073 mail_op = modest_mail_operation_new (G_OBJECT (window));
4074 if (helper->banner != NULL) {
4075 g_object_ref (G_OBJECT (helper->banner));
4076 gtk_widget_show (GTK_WIDGET (helper->banner));
4080 modest_mail_operation_get_msgs_full (mail_op,
4082 (GetMsgAsyncUserCallback) paste_msg_as_attachment_cb,
4084 paste_as_attachment_free);
4088 g_object_unref (data);
4090 g_object_unref (src_folder);
4093 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
4094 ModestEmailClipboard *clipboard = NULL;
4095 TnyFolder *src_folder = NULL;
4096 TnyFolderStore *folder_store = NULL;
4097 TnyList *data = NULL;
4098 gboolean delete = FALSE;
4100 /* Check clipboard source */
4101 clipboard = modest_runtime_get_email_clipboard ();
4102 if (modest_email_clipboard_cleared (clipboard))
4105 /* Get elements to paste */
4106 modest_email_clipboard_get_data (clipboard, &src_folder, &data, &delete);
4108 /* Create a new mail operation */
4109 mail_op = modest_mail_operation_new (G_OBJECT(window));
4111 /* Get destination folder */
4112 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (focused_widget));
4114 /* transfer messages */
4118 /* Ask for user confirmation */
4120 modest_ui_actions_msgs_move_to_confirmation (window,
4121 TNY_FOLDER (folder_store),
4125 if (response == GTK_RESPONSE_OK) {
4126 /* Launch notification */
4127 inf_note = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
4128 _CS("ckct_nw_pasting"));
4129 if (inf_note != NULL) {
4130 gtk_window_set_modal (GTK_WINDOW(inf_note), FALSE);
4131 gtk_widget_show (GTK_WIDGET(inf_note));
4134 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
4135 modest_mail_operation_xfer_msgs (mail_op,
4137 TNY_FOLDER (folder_store),
4139 destroy_information_note,
4142 g_object_unref (mail_op);
4145 } else if (src_folder != NULL) {
4146 /* Launch notification */
4147 inf_note = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
4148 _CS("ckct_nw_pasting"));
4149 if (inf_note != NULL) {
4150 gtk_window_set_modal (GTK_WINDOW(inf_note), FALSE);
4151 gtk_widget_show (GTK_WIDGET(inf_note));
4154 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
4155 modest_mail_operation_xfer_folder (mail_op,
4159 destroy_folder_information_note,
4165 g_object_unref (data);
4166 if (src_folder != NULL)
4167 g_object_unref (src_folder);
4168 if (folder_store != NULL)
4169 g_object_unref (folder_store);
4175 modest_ui_actions_on_select_all (GtkAction *action,
4176 ModestWindow *window)
4178 GtkWidget *focused_widget;
4180 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
4181 if (MODEST_IS_ATTACHMENTS_VIEW (focused_widget)) {
4182 modest_attachments_view_select_all (MODEST_ATTACHMENTS_VIEW (focused_widget));
4183 } else if (GTK_IS_LABEL (focused_widget)) {
4184 gtk_label_select_region (GTK_LABEL (focused_widget), 0, -1);
4185 } else if (GTK_IS_EDITABLE (focused_widget)) {
4186 gtk_editable_select_region (GTK_EDITABLE(focused_widget), 0, -1);
4187 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
4188 GtkTextBuffer *buffer;
4189 GtkTextIter start, end;
4191 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
4192 gtk_text_buffer_get_start_iter (buffer, &start);
4193 gtk_text_buffer_get_end_iter (buffer, &end);
4194 gtk_text_buffer_select_range (buffer, &start, &end);
4195 } else if (GTK_IS_HTML (focused_widget)) {
4196 gtk_html_select_all (GTK_HTML (focused_widget));
4197 } else if (MODEST_IS_MAIN_WINDOW (window)) {
4198 GtkWidget *header_view = focused_widget;
4199 GtkTreeSelection *selection = NULL;
4201 if (!(MODEST_IS_HEADER_VIEW (focused_widget))) {
4202 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (window),
4203 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
4206 /* Disable window dimming management */
4207 modest_window_disable_dimming (MODEST_WINDOW(window));
4209 /* Select all messages */
4210 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(header_view));
4211 gtk_tree_selection_select_all (selection);
4213 /* Set focuse on header view */
4214 gtk_widget_grab_focus (header_view);
4216 /* Enable window dimming management */
4217 modest_window_enable_dimming (MODEST_WINDOW(window));
4218 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (window));
4219 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (window));
4225 modest_ui_actions_on_mark_as_read (GtkAction *action,
4226 ModestWindow *window)
4228 g_return_if_fail (MODEST_IS_WINDOW(window));
4230 /* Mark each header as read */
4231 do_headers_action (window, headers_action_mark_as_read, NULL);
4235 modest_ui_actions_on_mark_as_unread (GtkAction *action,
4236 ModestWindow *window)
4238 g_return_if_fail (MODEST_IS_WINDOW(window));
4240 /* Mark each header as read */
4241 do_headers_action (window, headers_action_mark_as_unread, NULL);
4245 modest_ui_actions_on_change_zoom (GtkRadioAction *action,
4246 GtkRadioAction *selected,
4247 ModestWindow *window)
4251 value = gtk_radio_action_get_current_value (selected);
4252 if (MODEST_IS_WINDOW (window)) {
4253 modest_window_set_zoom (MODEST_WINDOW (window), ((gdouble)value)/100);
4258 modest_ui_actions_msg_edit_on_change_priority (GtkRadioAction *action,
4259 GtkRadioAction *selected,
4260 ModestWindow *window)
4262 TnyHeaderFlags flags;
4263 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4265 flags = gtk_radio_action_get_current_value (selected);
4266 modest_msg_edit_window_set_priority_flags (MODEST_MSG_EDIT_WINDOW (window), flags);
4270 modest_ui_actions_msg_edit_on_change_file_format (GtkRadioAction *action,
4271 GtkRadioAction *selected,
4272 ModestWindow *window)
4276 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4278 file_format = gtk_radio_action_get_current_value (selected);
4279 modest_msg_edit_window_set_file_format (MODEST_MSG_EDIT_WINDOW (window), file_format);
4284 modest_ui_actions_on_zoom_plus (GtkAction *action,
4285 ModestWindow *window)
4287 g_return_if_fail (MODEST_IS_WINDOW (window));
4289 modest_window_zoom_plus (MODEST_WINDOW (window));
4293 modest_ui_actions_on_zoom_minus (GtkAction *action,
4294 ModestWindow *window)
4296 g_return_if_fail (MODEST_IS_WINDOW (window));
4298 modest_window_zoom_minus (MODEST_WINDOW (window));
4302 modest_ui_actions_on_toggle_fullscreen (GtkToggleAction *toggle,
4303 ModestWindow *window)
4305 ModestWindowMgr *mgr;
4306 gboolean fullscreen, active;
4307 g_return_if_fail (MODEST_IS_WINDOW (window));
4309 mgr = modest_runtime_get_window_mgr ();
4311 active = (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle)))?1:0;
4312 fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
4314 if (active != fullscreen) {
4315 modest_window_mgr_set_fullscreen_mode (mgr, active);
4316 #ifndef MODEST_TOOLKIT_HILDON2
4317 gtk_window_present (GTK_WINDOW (window));
4323 modest_ui_actions_on_change_fullscreen (GtkAction *action,
4324 ModestWindow *window)
4326 ModestWindowMgr *mgr;
4327 gboolean fullscreen;
4329 g_return_if_fail (MODEST_IS_WINDOW (window));
4331 mgr = modest_runtime_get_window_mgr ();
4332 fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
4333 modest_window_mgr_set_fullscreen_mode (mgr, !fullscreen);
4335 #ifndef MODEST_TOOLKIT_HILDON2
4336 gtk_window_present (GTK_WINDOW (window));
4341 * Used by modest_ui_actions_on_details to call do_headers_action
4344 headers_action_show_details (TnyHeader *header,
4345 ModestWindow *window,
4349 modest_platform_run_header_details_dialog (GTK_WINDOW (window), header);
4353 * Show the header details in a ModestDetailsDialog widget
4356 modest_ui_actions_on_details (GtkAction *action,
4359 TnyList * headers_list;
4363 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
4366 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW (win));
4369 g_object_unref (msg);
4371 headers_list = get_selected_headers (win);
4375 iter = tny_list_create_iterator (headers_list);
4377 header = TNY_HEADER (tny_iterator_get_current (iter));
4379 headers_action_show_details (header, win, NULL);
4380 g_object_unref (header);
4383 g_object_unref (iter);
4384 g_object_unref (headers_list);
4386 } else if (MODEST_IS_MAIN_WINDOW (win)) {
4387 GtkWidget *folder_view, *header_view;
4389 /* Check which widget has the focus */
4390 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
4391 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
4392 if (gtk_widget_is_focus (folder_view)) {
4393 TnyFolderStore *folder_store
4394 = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
4395 if (!folder_store) {
4396 g_warning ("%s: No item was selected.\n", __FUNCTION__);
4399 /* Show only when it's a folder */
4400 /* This function should not be called for account items,
4401 * because we dim the menu item for them. */
4402 if (TNY_IS_FOLDER (folder_store)) {
4403 modest_platform_run_folder_details_dialog (GTK_WINDOW (win),
4404 TNY_FOLDER (folder_store));
4407 g_object_unref (folder_store);
4410 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
4411 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
4412 /* Show details of each header */
4413 do_headers_action (win, headers_action_show_details, header_view);
4415 #ifdef MODEST_TOOLKIT_HILDON2
4416 } else if (MODEST_IS_HEADER_WINDOW (win)) {
4418 GtkWidget *header_view;
4420 header_view = GTK_WIDGET (modest_header_window_get_header_view (MODEST_HEADER_WINDOW (win)));
4421 folder = modest_header_view_get_folder (MODEST_HEADER_VIEW (header_view));
4423 modest_platform_run_folder_details_dialog (GTK_WINDOW (win),
4425 g_object_unref (folder);
4432 modest_ui_actions_on_toggle_show_cc (GtkToggleAction *toggle,
4433 ModestMsgEditWindow *window)
4435 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4437 modest_msg_edit_window_show_cc (window, gtk_toggle_action_get_active (toggle));
4441 modest_ui_actions_on_toggle_show_bcc (GtkToggleAction *toggle,
4442 ModestMsgEditWindow *window)
4444 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4446 modest_msg_edit_window_show_bcc (window, gtk_toggle_action_get_active (toggle));
4450 modest_ui_actions_toggle_folders_view (GtkAction *action,
4451 ModestMainWindow *main_window)
4453 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
4455 if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)))
4456 modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SPLIT);
4458 modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SIMPLE);
4462 modest_ui_actions_on_toggle_toolbar (GtkToggleAction *toggle,
4463 ModestWindow *window)
4465 gboolean active, fullscreen = FALSE;
4466 ModestWindowMgr *mgr;
4468 active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle));
4470 /* Check if we want to toggle the toolbar view in fullscreen
4472 if (!strcmp (gtk_action_get_name (GTK_ACTION (toggle)),
4473 "ViewShowToolbarFullScreen")) {
4477 /* Toggle toolbar */
4478 mgr = modest_runtime_get_window_mgr ();
4479 modest_window_mgr_show_toolbars (mgr, G_TYPE_FROM_INSTANCE (window), active, fullscreen);
4483 modest_ui_actions_msg_edit_on_select_font (GtkAction *action,
4484 ModestMsgEditWindow *window)
4486 modest_msg_edit_window_select_font (window);
4491 modest_ui_actions_on_folder_display_name_changed (ModestFolderView *folder_view,
4492 const gchar *display_name,
4495 /* don't update the display name if it was already set;
4496 * updating the display name apparently is expensive */
4497 const gchar* old_name = gtk_window_get_title (window);
4499 if (display_name == NULL)
4502 if (old_name && display_name && strcmp (old_name, display_name) == 0)
4503 return; /* don't do anything */
4505 /* This is usually used to change the title of the main window, which
4506 * is the one that holds the folder view. Note that this change can
4507 * happen even when the widget doesn't have the focus. */
4508 gtk_window_set_title (window, display_name);
4513 modest_ui_actions_on_select_contacts (GtkAction *action, ModestMsgEditWindow *window)
4515 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4516 modest_msg_edit_window_select_contacts (window);
4520 modest_ui_actions_on_check_names (GtkAction *action, ModestMsgEditWindow *window)
4522 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4523 modest_msg_edit_window_check_names (window, FALSE);
4526 #ifndef MODEST_TOOLKIT_HILDON2
4528 * This function is used to track changes in the selection of the
4529 * folder view that is inside the "move to" dialog to enable/disable
4530 * the OK button because we do not want the user to select a disallowed
4531 * destination for a folder.
4532 * The user also not desired to be able to use NEW button on items where
4533 * folder creation is not possibel.
4536 on_move_to_dialog_folder_selection_changed (ModestFolderView* self,
4537 TnyFolderStore *folder_store,
4541 GtkWidget *dialog = NULL;
4542 gboolean ok_sensitive = TRUE, new_sensitive = TRUE;
4543 gboolean moving_folder = FALSE;
4544 gboolean is_local_account = TRUE;
4545 GtkWidget *folder_view = NULL;
4546 ModestTnyFolderRules rules;
4548 g_return_if_fail (MODEST_IS_FOLDER_VIEW(self));
4553 dialog = gtk_widget_get_ancestor (GTK_WIDGET (self), GTK_TYPE_DIALOG);
4557 /* check if folder_store is an remote account */
4558 if (TNY_IS_ACCOUNT (folder_store)) {
4559 TnyAccount *local_account = NULL;
4560 TnyAccount *mmc_account = NULL;
4561 ModestTnyAccountStore *account_store = NULL;
4563 account_store = modest_runtime_get_account_store ();
4564 local_account = modest_tny_account_store_get_local_folders_account (account_store);
4565 mmc_account = modest_tny_account_store_get_mmc_folders_account (account_store);
4567 if ((gpointer) local_account != (gpointer) folder_store &&
4568 (gpointer) mmc_account != (gpointer) folder_store) {
4569 ModestProtocolType proto;
4570 proto = modest_tny_account_get_protocol_type (TNY_ACCOUNT (folder_store));
4571 if (proto == MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
4572 proto = MODEST_PROTOCOLS_STORE_MAILDIR;
4574 is_local_account = FALSE;
4575 /* New button should be dimmed on remote
4577 new_sensitive = (modest_protocol_registry_protocol_type_has_tag (modest_runtime_get_protocol_registry (),
4579 MODEST_PROTOCOL_REGISTRY_STORE_HAS_FOLDERS));
4581 g_object_unref (local_account);
4583 /* It could not exist */
4585 g_object_unref (mmc_account);
4588 /* Check the target folder rules */
4589 if (TNY_IS_FOLDER (folder_store)) {
4590 rules = modest_tny_folder_get_rules (TNY_FOLDER (folder_store));
4591 if (rules & MODEST_FOLDER_RULES_FOLDER_NON_WRITEABLE) {
4592 ok_sensitive = FALSE;
4593 new_sensitive = FALSE;
4598 /* Check if we're moving a folder */
4599 if (MODEST_IS_MAIN_WINDOW (user_data)) {
4600 /* Get the widgets */
4601 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (user_data),
4602 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
4603 if (gtk_widget_is_focus (folder_view))
4604 moving_folder = TRUE;
4607 if (moving_folder) {
4608 TnyFolderStore *moved_folder = NULL, *parent = NULL;
4610 /* Get the folder to move */
4611 moved_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
4613 /* Check that we're not moving to the same folder */
4614 if (TNY_IS_FOLDER (moved_folder)) {
4615 parent = tny_folder_get_folder_store (TNY_FOLDER (moved_folder));
4616 if (parent == folder_store)
4617 ok_sensitive = FALSE;
4618 g_object_unref (parent);
4621 if (ok_sensitive && TNY_IS_ACCOUNT (folder_store)) {
4622 /* Do not allow to move to an account unless it's the
4623 local folders account */
4624 if (!is_local_account)
4625 ok_sensitive = FALSE;
4628 if (ok_sensitive && (moved_folder == folder_store)) {
4629 /* Do not allow to move to itself */
4630 ok_sensitive = FALSE;
4632 g_object_unref (moved_folder);
4634 TnyFolder *src_folder = NULL;
4636 /* Moving a message */
4637 if (MODEST_IS_MSG_VIEW_WINDOW (user_data)) {
4639 TnyHeader *header = NULL;
4640 header = modest_msg_view_window_get_header
4641 (MODEST_MSG_VIEW_WINDOW (user_data));
4642 if (!TNY_IS_HEADER(header))
4643 g_warning ("%s: could not get source header", __FUNCTION__);
4645 src_folder = tny_header_get_folder (header);
4648 g_object_unref (header);
4651 TNY_FOLDER (modest_folder_view_get_selected
4652 (MODEST_FOLDER_VIEW (folder_view)));
4655 if (TNY_IS_FOLDER(src_folder)) {
4656 /* Do not allow to move the msg to the same folder */
4657 /* Do not allow to move the msg to an account */
4658 if ((gpointer) src_folder == (gpointer) folder_store ||
4659 TNY_IS_ACCOUNT (folder_store))
4660 ok_sensitive = FALSE;
4661 g_object_unref (src_folder);
4663 g_warning ("%s: could not get source folder", __FUNCTION__);
4667 /* Set sensitivity of the OK and NEW button */
4668 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, ok_sensitive);
4669 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), MODEST_GTK_RESPONSE_NEW_FOLDER, new_sensitive);
4674 on_move_to_dialog_response (GtkDialog *dialog,
4678 GtkWidget *parent_win, *folder_view;
4680 parent_win = (GtkWidget *) user_data;
4681 folder_view = GTK_WIDGET (g_object_get_data (G_OBJECT (dialog),
4682 MODEST_MOVE_TO_DIALOG_FOLDER_VIEW));
4685 TnyFolderStore *dst_folder;
4687 case MODEST_GTK_RESPONSE_NEW_FOLDER:
4688 modest_ui_actions_create_folder (GTK_WIDGET (dialog), folder_view);
4690 case GTK_RESPONSE_NONE:
4691 case GTK_RESPONSE_CANCEL:
4692 case GTK_RESPONSE_DELETE_EVENT:
4693 gtk_widget_destroy (GTK_WIDGET (dialog));
4695 case GTK_RESPONSE_OK:
4696 dst_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
4697 /* Do window specific stuff */
4698 if (MODEST_IS_MAIN_WINDOW (parent_win)) {
4699 modest_ui_actions_on_main_window_move_to (NULL,
4702 MODEST_MAIN_WINDOW (parent_win));
4704 modest_ui_actions_on_msg_view_window_move_to (NULL,
4706 MODEST_MSG_VIEW_WINDOW (parent_win));
4709 g_object_unref (dst_folder);
4710 gtk_widget_destroy (GTK_WIDGET (dialog));
4713 g_warning ("%s unexpected response id %d", __FUNCTION__, response);
4718 create_move_to_dialog (GtkWindow *win,
4719 GtkWidget *folder_view)
4721 GtkWidget *dialog, *tree_view = NULL;
4723 dialog = modest_platform_create_move_to_dialog (win, &tree_view);
4725 #ifndef MODEST_TOOLKIT_HILDON2
4726 /* Track changes in the selection to
4727 * disable the OK button whenever "Move to" is not possible
4728 * disbale NEW button whenever New is not possible */
4729 g_signal_connect (tree_view,
4730 "folder_selection_changed",
4731 G_CALLBACK (on_move_to_dialog_folder_selection_changed),
4735 /* It could happen that we're trying to move a message from a
4736 window (msg window for example) after the main window was
4737 closed, so we can not just get the model of the folder
4739 if (MODEST_IS_FOLDER_VIEW (folder_view)) {
4740 const gchar *visible_id = NULL;
4742 modest_folder_view_set_style (MODEST_FOLDER_VIEW (tree_view),
4743 MODEST_FOLDER_VIEW_STYLE_SHOW_ALL);
4744 modest_folder_view_copy_model (MODEST_FOLDER_VIEW(folder_view),
4745 MODEST_FOLDER_VIEW(tree_view));
4748 modest_folder_view_get_account_id_of_visible_server_account (MODEST_FOLDER_VIEW(folder_view));
4750 /* Show the same account than the one that is shown in the main window */
4751 modest_folder_view_set_account_id_of_visible_server_account (MODEST_FOLDER_VIEW(tree_view),
4754 const gchar *active_account_name = NULL;
4755 ModestAccountMgr *mgr = NULL;
4756 ModestAccountSettings *settings = NULL;
4757 ModestServerAccountSettings *store_settings = NULL;
4759 modest_folder_view_set_style (MODEST_FOLDER_VIEW (tree_view),
4760 MODEST_FOLDER_VIEW_STYLE_SHOW_ALL);
4761 modest_folder_view_update_model (MODEST_FOLDER_VIEW (tree_view),
4762 TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()));
4764 active_account_name = modest_window_get_active_account (MODEST_WINDOW (win));
4765 mgr = modest_runtime_get_account_mgr ();
4766 settings = modest_account_mgr_load_account_settings (mgr, active_account_name);
4769 const gchar *store_account_name;
4770 store_settings = modest_account_settings_get_store_settings (settings);
4771 store_account_name = modest_server_account_settings_get_account_name (store_settings);
4773 modest_folder_view_set_account_id_of_visible_server_account (MODEST_FOLDER_VIEW (tree_view),
4774 store_account_name);
4775 g_object_unref (store_settings);
4776 g_object_unref (settings);
4780 /* we keep a pointer to the embedded folder view, so we can
4781 * retrieve it with get_folder_view_from_move_to_dialog (see
4782 * above) later (needed for focus handling)
4784 g_object_set_data (G_OBJECT(dialog), MODEST_MOVE_TO_DIALOG_FOLDER_VIEW, tree_view);
4786 /* Hide special folders */
4787 modest_folder_view_show_non_move_folders (MODEST_FOLDER_VIEW (tree_view), FALSE);
4788 #ifndef MODEST_TOOLKIT_HILDON2
4789 modest_folder_view_select_first_inbox_or_local (MODEST_FOLDER_VIEW (tree_view));
4792 gtk_widget_show (GTK_WIDGET (tree_view));
4798 * Shows a confirmation dialog to the user when we're moving messages
4799 * from a remote server to the local storage. Returns the dialog
4800 * response. If it's other kind of movement then it always returns
4803 * This one is used by the next functions:
4804 * modest_ui_actions_on_paste - commented out
4805 * drag_and_drop_from_header_view (for d&d in modest_folder_view.c)
4808 modest_ui_actions_msgs_move_to_confirmation (ModestWindow *win,
4809 TnyFolder *dest_folder,
4813 gint response = GTK_RESPONSE_OK;
4814 TnyAccount *account = NULL;
4815 TnyFolder *src_folder = NULL;
4816 TnyIterator *iter = NULL;
4817 TnyHeader *header = NULL;
4819 /* return with OK if the destination is a remote folder */
4820 if (modest_tny_folder_is_remote_folder (dest_folder))
4821 return GTK_RESPONSE_OK;
4823 /* Get source folder */
4824 iter = tny_list_create_iterator (headers);
4825 header = TNY_HEADER (tny_iterator_get_current (iter));
4827 src_folder = tny_header_get_folder (header);
4828 g_object_unref (header);
4830 g_object_unref (iter);
4832 /* if no src_folder, message may be an attahcment */
4833 if (src_folder == NULL)
4834 return GTK_RESPONSE_CANCEL;
4836 /* If the source is a local or MMC folder */
4837 if (!modest_tny_folder_is_remote_folder (src_folder)) {
4838 g_object_unref (src_folder);
4839 return GTK_RESPONSE_OK;
4842 /* Get the account */
4843 account = tny_folder_get_account (src_folder);
4845 /* now if offline we ask the user */
4846 if(connect_to_get_msg (win, tny_list_get_length (headers), account))
4847 response = GTK_RESPONSE_OK;
4849 response = GTK_RESPONSE_CANCEL;
4852 g_object_unref (src_folder);
4853 g_object_unref (account);
4859 move_to_helper_destroyer (gpointer user_data)
4861 MoveToHelper *helper = (MoveToHelper *) user_data;
4863 /* Close the "Pasting" information banner */
4864 if (helper->banner) {
4865 gtk_widget_destroy (GTK_WIDGET (helper->banner));
4866 g_object_unref (helper->banner);
4868 if (gtk_tree_row_reference_valid (helper->reference)) {
4869 gtk_tree_row_reference_free (helper->reference);
4870 helper->reference = NULL;
4876 move_to_cb (ModestMailOperation *mail_op,
4879 MoveToHelper *helper = (MoveToHelper *) user_data;
4881 /* Note that the operation could have failed, in that case do
4883 if (modest_mail_operation_get_status (mail_op) ==
4884 MODEST_MAIL_OPERATION_STATUS_SUCCESS) {
4886 GObject *object = modest_mail_operation_get_source (mail_op);
4887 if (MODEST_IS_MSG_VIEW_WINDOW (object)) {
4888 ModestMsgViewWindow *self = MODEST_MSG_VIEW_WINDOW (object);
4890 if (!modest_msg_view_window_select_next_message (self) &&
4891 !modest_msg_view_window_select_previous_message (self)) {
4892 /* No more messages to view, so close this window */
4893 modest_ui_actions_on_close_window (NULL, MODEST_WINDOW(self));
4895 } else if (MODEST_IS_MAIN_WINDOW (object) &&
4896 gtk_tree_row_reference_valid (helper->reference)) {
4897 GtkWidget *header_view;
4899 GtkTreeSelection *sel;
4901 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(object),
4902 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
4903 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
4904 path = gtk_tree_row_reference_get_path (helper->reference);
4905 /* We need to unselect the previous one
4906 because we could be copying instead of
4908 gtk_tree_selection_unselect_all (sel);
4909 gtk_tree_selection_select_path (sel, path);
4910 gtk_tree_path_free (path);
4912 g_object_unref (object);
4914 /* Destroy the helper */
4915 move_to_helper_destroyer (helper);
4919 folder_move_to_cb (ModestMailOperation *mail_op,
4920 TnyFolder *new_folder,
4923 GtkWidget *folder_view;
4926 object = modest_mail_operation_get_source (mail_op);
4927 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(object),
4928 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
4929 g_object_ref (folder_view);
4930 g_object_unref (object);
4931 move_to_cb (mail_op, user_data);
4932 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view), new_folder, FALSE);
4933 g_object_unref (folder_view);
4937 msgs_move_to_cb (ModestMailOperation *mail_op,
4940 move_to_cb (mail_op, user_data);
4944 modest_ui_actions_move_folder_error_handler (ModestMailOperation *mail_op,
4947 ModestWindow *main_window = NULL;
4949 /* Disable next automatic folder selection */
4950 main_window = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (),
4951 FALSE); /* don't create */
4953 GObject *win = NULL;
4954 GtkWidget *folder_view = NULL;
4956 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (main_window),
4957 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
4958 modest_folder_view_disable_next_folder_selection (MODEST_FOLDER_VIEW(folder_view));
4960 if (user_data && TNY_IS_FOLDER (user_data)) {
4961 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view),
4962 TNY_FOLDER (user_data), FALSE);
4965 /* Show notification dialog only if the main window exists */
4966 win = modest_mail_operation_get_source (mail_op);
4967 modest_platform_run_information_dialog ((GtkWindow *) win,
4968 _("mail_in_ui_folder_move_target_error"),
4971 g_object_unref (win);
4976 open_msg_for_purge_cb (ModestMailOperation *mail_op,
4985 gint pending_purges = 0;
4986 gboolean some_purged = FALSE;
4987 ModestWindow *win = MODEST_WINDOW (user_data);
4988 ModestWindowMgr *mgr = modest_runtime_get_window_mgr ();
4990 /* If there was any error */
4991 if (!modest_ui_actions_msg_retrieval_check (mail_op, header, msg)) {
4992 modest_window_mgr_unregister_header (mgr, header);
4996 /* Once the message has been retrieved for purging, we check if
4997 * it's all ok for purging */
4999 parts = tny_simple_list_new ();
5000 tny_mime_part_get_parts (TNY_MIME_PART (msg), parts);
5001 iter = tny_list_create_iterator (parts);
5003 while (!tny_iterator_is_done (iter)) {
5005 part = TNY_MIME_PART (tny_iterator_get_current (iter));
5006 if (part && (tny_mime_part_is_attachment (part) || TNY_IS_MSG (part))) {
5007 if (tny_mime_part_is_purged (part))
5014 g_object_unref (part);
5016 tny_iterator_next (iter);
5018 g_object_unref (iter);
5021 if (pending_purges>0) {
5023 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),_("mcen_nc_purge_file_text_inbox"));
5025 if (response == GTK_RESPONSE_OK) {
5028 modest_platform_animation_banner (GTK_WIDGET (win), NULL, _("mcen_me_inbox_remove_attachments"));
5029 iter = tny_list_create_iterator (parts);
5030 while (!tny_iterator_is_done (iter)) {
5033 part = TNY_MIME_PART (tny_iterator_get_current (iter));
5034 if (part && (tny_mime_part_is_attachment (part) || TNY_IS_MSG (part)))
5035 tny_mime_part_set_purged (part);
5038 g_object_unref (part);
5040 tny_iterator_next (iter);
5042 g_object_unref (iter);
5044 tny_msg_rewrite_cache (msg);
5046 gtk_widget_destroy (info);
5050 modest_window_mgr_unregister_header (mgr, header);
5052 g_object_unref (parts);
5056 modest_ui_actions_on_main_window_remove_attachments (GtkAction *action,
5057 ModestMainWindow *win)
5059 GtkWidget *header_view;
5060 TnyList *header_list;
5062 TnyHeaderFlags flags;
5063 ModestWindow *msg_view_window = NULL;
5066 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win));
5068 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
5069 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
5071 header_list = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW (header_view));
5073 g_warning ("%s: no header selected", __FUNCTION__);
5077 if (tny_list_get_length (header_list) == 1) {
5078 TnyIterator *iter = tny_list_create_iterator (header_list);
5079 header = TNY_HEADER (tny_iterator_get_current (iter));
5080 g_object_unref (iter);
5084 if (!header || !TNY_IS_HEADER(header)) {
5085 g_warning ("%s: header is not valid", __FUNCTION__);
5089 found = modest_window_mgr_find_registered_header (modest_runtime_get_window_mgr (),
5090 header, &msg_view_window);
5091 flags = tny_header_get_flags (header);
5092 if (!(flags & TNY_HEADER_FLAG_CACHED))
5095 if (msg_view_window != NULL)
5096 modest_msg_view_window_remove_attachments (MODEST_MSG_VIEW_WINDOW (msg_view_window), TRUE);
5098 /* do nothing; uid was registered before, so window is probably on it's way */
5099 g_warning ("debug: header %p has already been registered", header);
5102 ModestMailOperation *mail_op = NULL;
5103 modest_window_mgr_register_header (modest_runtime_get_window_mgr (), header, NULL);
5104 mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT (win),
5105 modest_ui_actions_disk_operations_error_handler,
5107 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
5108 modest_mail_operation_get_msg (mail_op, header, FALSE, open_msg_for_purge_cb, win);
5110 g_object_unref (mail_op);
5113 g_object_unref (header);
5115 g_object_unref (header_list);
5119 * Checks if we need a connection to do the transfer and if the user
5120 * wants to connect to complete it
5123 modest_ui_actions_xfer_messages_check (GtkWindow *parent_window,
5124 TnyFolderStore *src_folder,
5126 TnyFolder *dst_folder,
5127 gboolean delete_originals,
5128 gboolean *need_connection,
5131 TnyAccount *src_account;
5132 gint uncached_msgs = 0;
5134 uncached_msgs = header_list_count_uncached_msgs (headers);
5136 /* We don't need any further check if
5138 * 1- the source folder is local OR
5139 * 2- the device is already online
5141 if (!modest_tny_folder_store_is_remote (src_folder) ||
5142 tny_device_is_online (modest_runtime_get_device())) {
5143 *need_connection = FALSE;
5148 /* We must ask for a connection when
5150 * - the message(s) is not already cached OR
5151 * - the message(s) is cached but the leave_on_server setting
5152 * is FALSE (because we need to sync the source folder to
5153 * delete the message from the server (for IMAP we could do it
5154 * offline, it'll take place the next time we get a
5157 src_account = get_account_from_folder_store (src_folder);
5158 if (uncached_msgs > 0) {
5162 *need_connection = TRUE;
5163 num_headers = tny_list_get_length (headers);
5164 msg = ngettext ("mcen_nc_get_msg", "mcen_nc_get_msgs", num_headers);
5166 if (modest_platform_run_confirmation_dialog (parent_window, msg) ==
5167 GTK_RESPONSE_CANCEL) {
5173 /* The transfer is possible and the user wants to */
5176 if (remote_folder_has_leave_on_server (src_folder) && delete_originals) {
5177 const gchar *account_name;
5178 gboolean leave_on_server;
5180 account_name = modest_tny_account_get_parent_modest_account_name_for_server_account (src_account);
5181 leave_on_server = modest_account_mgr_get_leave_on_server (modest_runtime_get_account_mgr (),
5184 if (leave_on_server == TRUE) {
5185 *need_connection = FALSE;
5187 *need_connection = TRUE;
5190 *need_connection = FALSE;
5195 g_object_unref (src_account);
5199 xfer_messages_error_handler (ModestMailOperation *mail_op,
5202 ModestWindow *main_window = NULL;
5204 /* Disable next automatic folder selection */
5205 main_window = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (),
5206 FALSE); /* don't create */
5208 GObject *win = modest_mail_operation_get_source (mail_op);
5209 modest_platform_run_information_dialog ((GtkWindow *) win,
5210 _("mail_in_ui_folder_move_target_error"),
5213 g_object_unref (win);
5215 move_to_helper_destroyer (user_data);
5219 TnyFolderStore *dst_folder;
5224 * Utility function that transfer messages from both the main window
5225 * and the msg view window when using the "Move to" dialog
5228 xfer_messages_performer (gboolean canceled,
5230 GtkWindow *parent_window,
5231 TnyAccount *account,
5234 ModestWindow *win = MODEST_WINDOW (parent_window);
5235 TnyAccount *dst_account = NULL;
5236 gboolean dst_forbids_message_add = FALSE;
5237 XferMsgsHelper *helper;
5238 MoveToHelper *movehelper;
5239 ModestMailOperation *mail_op;
5241 helper = (XferMsgsHelper *) user_data;
5243 if (canceled || err) {
5244 if (!check_memory_full_error ((GtkWidget *) parent_window, err)) {
5245 /* Show the proper error message */
5246 modest_ui_actions_on_account_connection_error (parent_window, account);
5251 dst_account = tny_folder_get_account (TNY_FOLDER (helper->dst_folder));
5253 /* tinymail will return NULL for local folders it seems */
5254 dst_forbids_message_add = modest_protocol_registry_protocol_type_has_tag (modest_runtime_get_protocol_registry (),
5255 modest_tny_account_get_protocol_type (dst_account),
5256 MODEST_PROTOCOL_REGISTRY_STORE_FORBID_MESSAGE_ADD);
5257 g_object_unref (dst_account);
5259 if (dst_forbids_message_add) {
5260 modest_platform_information_banner (GTK_WIDGET (win),
5262 ngettext("mail_in_ui_folder_move_target_error",
5263 "mail_in_ui_folder_move_targets_error",
5264 tny_list_get_length (helper->headers)));
5268 movehelper = g_new0 (MoveToHelper, 1);
5269 movehelper->banner = modest_platform_animation_banner (GTK_WIDGET (win), NULL,
5270 _CS("ckct_nw_pasting"));
5271 if (movehelper->banner != NULL) {
5272 g_object_ref (movehelper->banner);
5273 gtk_widget_show (GTK_WIDGET (movehelper->banner));
5276 if (MODEST_IS_MAIN_WINDOW (win)) {
5277 GtkWidget *header_view =
5278 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
5279 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
5280 movehelper->reference = get_next_after_selected_headers (MODEST_HEADER_VIEW (header_view));
5283 /* Perform the mail operation */
5284 mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT(win),
5285 xfer_messages_error_handler,
5287 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
5290 modest_mail_operation_xfer_msgs (mail_op,
5292 TNY_FOLDER (helper->dst_folder),
5297 g_object_unref (G_OBJECT (mail_op));
5299 g_object_unref (helper->dst_folder);
5300 g_object_unref (helper->headers);
5301 g_slice_free (XferMsgsHelper, helper);
5305 TnyFolder *src_folder;
5306 TnyFolderStore *dst_folder;
5307 gboolean delete_original;
5308 GtkWidget *folder_view;
5312 on_move_folder_cb (gboolean canceled, GError *err, GtkWindow *parent_window,
5313 TnyAccount *account, gpointer user_data)
5315 MoveFolderInfo *info = (MoveFolderInfo*)user_data;
5316 GtkTreeSelection *sel;
5317 ModestMailOperation *mail_op = NULL;
5319 if (canceled || err || !MODEST_IS_MAIN_WINDOW (parent_window)) {
5320 g_object_unref (G_OBJECT (info->src_folder));
5321 g_object_unref (G_OBJECT (info->dst_folder));
5326 MoveToHelper *helper = g_new0 (MoveToHelper, 1);
5327 helper->banner = modest_platform_animation_banner (GTK_WIDGET (parent_window), NULL,
5328 _CS("ckct_nw_pasting"));
5329 if (helper->banner != NULL) {
5330 g_object_ref (helper->banner);
5331 gtk_widget_show (GTK_WIDGET(helper->banner));
5333 /* Clean folder on header view before moving it */
5334 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (info->folder_view));
5335 gtk_tree_selection_unselect_all (sel);
5337 /* Let gtk events run. We need that the folder
5338 view frees its reference to the source
5339 folder *before* issuing the mail operation
5340 so we need the signal handler of selection
5341 changed to happen before the mail
5343 while (gtk_events_pending ())
5344 gtk_main_iteration (); */
5347 modest_mail_operation_new_with_error_handling (G_OBJECT(parent_window),
5348 modest_ui_actions_move_folder_error_handler,
5349 info->src_folder, NULL);
5350 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
5353 /* Select *after* the changes */
5354 /* TODO: this function hangs UI after transfer */
5355 /* modest_folder_view_select_folder (MODEST_FOLDER_VIEW(folder_view), */
5356 /* TNY_FOLDER (src_folder), TRUE); */
5358 modest_folder_view_select_folder (MODEST_FOLDER_VIEW(info->folder_view),
5359 TNY_FOLDER (info->dst_folder), TRUE);
5360 modest_mail_operation_xfer_folder (mail_op,
5361 TNY_FOLDER (info->src_folder),
5363 info->delete_original,
5366 g_object_unref (G_OBJECT (info->src_folder));
5368 /* if (modest_mail_operation_get_status (mail_op) == MODEST_MAIL_OPERATION_STATUS_SUCCESS) { */
5371 /* Unref mail operation */
5372 g_object_unref (G_OBJECT (mail_op));
5373 g_object_unref (G_OBJECT (info->dst_folder));
5378 get_account_from_folder_store (TnyFolderStore *folder_store)
5380 if (TNY_IS_ACCOUNT (folder_store))
5381 return g_object_ref (folder_store);
5383 return tny_folder_get_account (TNY_FOLDER (folder_store));
5387 * UI handler for the "Move to" action when invoked from the
5391 modest_ui_actions_on_main_window_move_to (GtkAction *action,
5392 GtkWidget *folder_view,
5393 TnyFolderStore *dst_folder,
5394 ModestMainWindow *win)
5396 ModestHeaderView *header_view = NULL;
5397 TnyFolderStore *src_folder = NULL;
5399 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win));
5401 /* Get the source folder */
5402 src_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
5404 /* Get header view */
5405 header_view = MODEST_HEADER_VIEW(modest_main_window_get_child_widget (win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW));
5407 /* Get folder or messages to transfer */
5408 if (gtk_widget_is_focus (folder_view)) {
5409 gboolean do_xfer = TRUE;
5411 /* Allow only to transfer folders to the local root folder */
5412 if (TNY_IS_ACCOUNT (dst_folder) &&
5413 !MODEST_IS_TNY_LOCAL_FOLDERS_ACCOUNT (dst_folder) &&
5414 !modest_tny_account_is_memory_card_account (TNY_ACCOUNT (dst_folder))) {
5416 } else if (!TNY_IS_FOLDER (src_folder)) {
5417 g_warning ("%s: src_folder is not a TnyFolder.\n", __FUNCTION__);
5422 MoveFolderInfo *info = g_new0 (MoveFolderInfo, 1);
5423 DoubleConnectionInfo *connect_info = g_slice_new (DoubleConnectionInfo);
5425 info->src_folder = g_object_ref (src_folder);
5426 info->dst_folder = g_object_ref (dst_folder);
5427 info->delete_original = TRUE;
5428 info->folder_view = folder_view;
5430 connect_info->callback = on_move_folder_cb;
5431 connect_info->dst_account = get_account_from_folder_store (TNY_FOLDER_STORE (dst_folder));
5432 connect_info->data = info;
5434 modest_platform_double_connect_and_perform(GTK_WINDOW (win), TRUE,
5435 TNY_FOLDER_STORE (src_folder),
5438 } else if (gtk_widget_is_focus (GTK_WIDGET(header_view))) {
5441 headers = modest_header_view_get_selected_headers(header_view);
5443 /* Transfer the messages */
5444 modest_ui_actions_transfer_messages_helper (GTK_WINDOW (win), TNY_FOLDER (src_folder),
5445 headers, TNY_FOLDER (dst_folder));
5447 g_object_unref (headers);
5451 g_object_unref (src_folder);
5456 modest_ui_actions_transfer_messages_helper (GtkWindow *win,
5457 TnyFolder *src_folder,
5459 TnyFolder *dst_folder)
5461 gboolean need_connection = TRUE;
5462 gboolean do_xfer = TRUE;
5463 XferMsgsHelper *helper;
5465 g_return_if_fail (TNY_IS_FOLDER (src_folder));
5466 g_return_if_fail (TNY_IS_FOLDER (dst_folder));
5467 g_return_if_fail (TNY_IS_LIST (headers));
5469 modest_ui_actions_xfer_messages_check (win, TNY_FOLDER_STORE (src_folder),
5470 headers, TNY_FOLDER (dst_folder),
5471 TRUE, &need_connection,
5474 /* If we don't want to transfer just return */
5478 /* Create the helper */
5479 helper = g_slice_new (XferMsgsHelper);
5480 helper->dst_folder = g_object_ref (dst_folder);
5481 helper->headers = g_object_ref (headers);
5483 if (need_connection) {
5484 DoubleConnectionInfo *connect_info = g_slice_new (DoubleConnectionInfo);
5485 connect_info->callback = xfer_messages_performer;
5486 connect_info->dst_account = tny_folder_get_account (TNY_FOLDER (dst_folder));
5487 connect_info->data = helper;
5489 modest_platform_double_connect_and_perform(GTK_WINDOW (win), TRUE,
5490 TNY_FOLDER_STORE (src_folder),
5493 TnyAccount *src_account = get_account_from_folder_store (TNY_FOLDER_STORE (src_folder));
5494 xfer_messages_performer (FALSE, NULL, GTK_WINDOW (win),
5495 src_account, helper);
5496 g_object_unref (src_account);
5501 * UI handler for the "Move to" action when invoked from the
5502 * ModestMsgViewWindow
5505 modest_ui_actions_on_msg_view_window_move_to (GtkAction *action,
5506 TnyFolderStore *dst_folder,
5507 ModestMsgViewWindow *win)
5509 TnyList *headers = NULL;
5510 TnyHeader *header = NULL;
5511 TnyFolder *src_folder = NULL;
5513 g_return_if_fail (TNY_IS_FOLDER (dst_folder));
5515 /* Create header list */
5516 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
5517 src_folder = TNY_FOLDER (tny_header_get_folder(header));
5518 headers = tny_simple_list_new ();
5519 tny_list_append (headers, G_OBJECT (header));
5521 /* Transfer the messages */
5522 modest_ui_actions_transfer_messages_helper (GTK_WINDOW (win), src_folder, headers,
5523 TNY_FOLDER (dst_folder));
5526 g_object_unref (src_folder);
5527 g_object_unref (header);
5528 g_object_unref (headers);
5532 modest_ui_actions_on_move_to (GtkAction *action,
5535 GtkWidget *dialog = NULL, *folder_view = NULL;
5536 ModestMainWindow *main_window;
5538 g_return_if_fail (MODEST_IS_WINDOW (win));
5540 /* Get the main window if exists */
5541 if (MODEST_IS_MAIN_WINDOW (win))
5542 main_window = MODEST_MAIN_WINDOW (win);
5545 MODEST_MAIN_WINDOW (modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (),
5546 FALSE)); /* don't create */
5548 /* Get the folder view widget if exists */
5550 folder_view = modest_main_window_get_child_widget (main_window,
5551 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
5555 /* Create and run the dialog */
5556 dialog = create_move_to_dialog (GTK_WINDOW (win), folder_view);
5557 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (),
5558 GTK_WINDOW (dialog),
5561 /* Listen to response signal */
5562 g_signal_connect (dialog,
5564 G_CALLBACK (on_move_to_dialog_response),
5567 gtk_widget_show (dialog);
5571 * Calls #HeadersFunc for each header already selected in the main
5572 * window or the message currently being shown in the msg view window
5575 do_headers_action (ModestWindow *win,
5579 TnyList *headers_list = NULL;
5580 TnyIterator *iter = NULL;
5581 TnyHeader *header = NULL;
5582 TnyFolder *folder = NULL;
5585 headers_list = get_selected_headers (win);
5589 /* Get the folder */
5590 iter = tny_list_create_iterator (headers_list);
5591 header = TNY_HEADER (tny_iterator_get_current (iter));
5593 folder = tny_header_get_folder (header);
5594 g_object_unref (header);
5597 /* Call the function for each header */
5598 while (!tny_iterator_is_done (iter)) {
5599 header = TNY_HEADER (tny_iterator_get_current (iter));
5600 func (header, win, user_data);
5601 g_object_unref (header);
5602 tny_iterator_next (iter);
5605 /* Trick: do a poke status in order to speed up the signaling
5607 tny_folder_poke_status (folder);
5610 g_object_unref (folder);
5611 g_object_unref (iter);
5612 g_object_unref (headers_list);
5616 modest_ui_actions_view_attachment (GtkAction *action,
5617 ModestWindow *window)
5619 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
5620 modest_msg_view_window_view_attachment (MODEST_MSG_VIEW_WINDOW (window), NULL);
5622 /* not supported window for this action */
5623 g_return_if_reached ();
5628 modest_ui_actions_save_attachments (GtkAction *action,
5629 ModestWindow *window)
5631 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
5633 if (modest_platform_check_memory_low (MODEST_WINDOW(window), TRUE))
5636 modest_msg_view_window_save_attachments (MODEST_MSG_VIEW_WINDOW (window), NULL);
5638 /* not supported window for this action */
5639 g_return_if_reached ();
5644 modest_ui_actions_remove_attachments (GtkAction *action,
5645 ModestWindow *window)
5647 if (MODEST_IS_MAIN_WINDOW (window)) {
5648 modest_ui_actions_on_main_window_remove_attachments (action, MODEST_MAIN_WINDOW (window));
5649 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
5650 modest_msg_view_window_remove_attachments (MODEST_MSG_VIEW_WINDOW (window), FALSE);
5652 /* not supported window for this action */
5653 g_return_if_reached ();
5658 modest_ui_actions_on_settings (GtkAction *action,
5663 dialog = modest_platform_get_global_settings_dialog ();
5664 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (win));
5665 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
5666 gtk_widget_show_all (dialog);
5668 gtk_dialog_run (GTK_DIALOG (dialog));
5670 gtk_widget_destroy (dialog);
5674 modest_ui_actions_on_help (GtkAction *action,
5677 /* Help app is not available at all in fremantle */
5678 #ifndef MODEST_TOOLKIT_HILDON2
5679 const gchar *help_id;
5681 g_return_if_fail (win && GTK_IS_WINDOW(win));
5683 help_id = modest_window_mgr_get_help_id (modest_runtime_get_window_mgr(), win);
5686 modest_platform_show_help (GTK_WINDOW (win), help_id);
5691 modest_ui_actions_on_csm_help (GtkAction *action,
5694 /* Help app is not available at all in fremantle */
5695 #ifndef MODEST_TOOLKIT_HILDON2
5697 const gchar* help_id = NULL;
5698 GtkWidget *folder_view;
5699 TnyFolderStore *folder_store;
5701 g_return_if_fail (win && MODEST_IS_MAIN_WINDOW (win));
5703 /* Get selected folder */
5704 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
5705 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
5706 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
5708 /* Switch help_id */
5709 if (folder_store && TNY_IS_FOLDER (folder_store))
5710 help_id = modest_tny_folder_get_help_id (TNY_FOLDER (folder_store));
5713 g_object_unref (folder_store);
5716 modest_platform_show_help (GTK_WINDOW (win), help_id);
5718 modest_ui_actions_on_help (action, win);
5723 retrieve_contents_cb (ModestMailOperation *mail_op,
5730 /* We only need this callback to show an error in case of
5731 memory low condition */
5732 modest_ui_actions_msg_retrieval_check (mail_op, header, msg);
5736 retrieve_msg_contents_performer (gboolean canceled,
5738 GtkWindow *parent_window,
5739 TnyAccount *account,
5742 ModestMailOperation *mail_op;
5743 TnyList *headers = TNY_LIST (user_data);
5745 if (err || canceled) {
5746 check_memory_full_error ((GtkWidget *) parent_window, err);
5750 /* Create mail operation */
5751 mail_op = modest_mail_operation_new_with_error_handling ((GObject *) parent_window,
5752 modest_ui_actions_disk_operations_error_handler,
5754 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
5755 modest_mail_operation_get_msgs_full (mail_op, headers, retrieve_contents_cb, NULL, NULL);
5758 g_object_unref (mail_op);
5760 g_object_unref (headers);
5761 g_object_unref (account);
5765 modest_ui_actions_on_retrieve_msg_contents (GtkAction *action,
5766 ModestWindow *window)
5768 TnyList *headers = NULL;
5769 TnyAccount *account = NULL;
5770 TnyIterator *iter = NULL;
5771 TnyHeader *header = NULL;
5772 TnyFolder *folder = NULL;
5775 headers = get_selected_headers (window);
5779 /* Pick the account */
5780 iter = tny_list_create_iterator (headers);
5781 header = TNY_HEADER (tny_iterator_get_current (iter));
5782 folder = tny_header_get_folder (header);
5783 account = tny_folder_get_account (folder);
5784 g_object_unref (folder);
5785 g_object_unref (header);
5786 g_object_unref (iter);
5788 /* Connect and perform the message retrieval */
5789 modest_platform_connect_and_perform ((GtkWindow *) window, TRUE,
5790 g_object_ref (account),
5791 retrieve_msg_contents_performer,
5792 g_object_ref (headers));
5795 g_object_unref (account);
5796 g_object_unref (headers);
5800 modest_ui_actions_check_toolbar_dimming_rules (ModestWindow *window)
5802 g_return_if_fail (MODEST_IS_WINDOW (window));
5805 modest_window_check_dimming_rules_group (window, MODEST_DIMMING_RULES_TOOLBAR);
5809 modest_ui_actions_check_menu_dimming_rules (ModestWindow *window)
5811 g_return_if_fail (MODEST_IS_WINDOW (window));
5814 modest_window_check_dimming_rules_group (window, MODEST_DIMMING_RULES_MENU);
5818 modest_ui_actions_on_email_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_edit_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_view_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_format_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_tools_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_attachment_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_toolbar_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_folder_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_header_view_csm_menu_activated (GtkAction *action,
5899 ModestWindow *window)
5901 g_return_if_fail (MODEST_IS_WINDOW (window));
5904 modest_ui_actions_check_menu_dimming_rules (window);
5908 modest_ui_actions_on_search_messages (GtkAction *action, ModestWindow *window)
5910 g_return_if_fail (MODEST_IS_WINDOW (window));
5912 /* we check for low-mem; in that case, show a warning, and don't allow
5915 if (modest_platform_check_memory_low (window, TRUE))
5918 modest_platform_show_search_messages (GTK_WINDOW (window));
5922 modest_ui_actions_on_open_addressbook (GtkAction *action, ModestWindow *win)
5924 g_return_if_fail (MODEST_IS_WINDOW (win));
5927 /* we check for low-mem; in that case, show a warning, and don't allow
5928 * for the addressbook
5930 if (modest_platform_check_memory_low (win, TRUE))
5934 modest_platform_show_addressbook (GTK_WINDOW (win));
5939 modest_ui_actions_on_toggle_find_in_page (GtkToggleAction *action,
5940 ModestWindow *window)
5942 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
5944 modest_msg_edit_window_toggle_find_toolbar (MODEST_MSG_EDIT_WINDOW (window), gtk_toggle_action_get_active (action));
5948 on_send_receive_finished (ModestMailOperation *mail_op,
5951 GtkWidget *header_view, *folder_view;
5952 TnyFolderStore *folder_store;
5953 ModestMainWindow *main_win = MODEST_MAIN_WINDOW (user_data);
5955 /* Set send/receive operation finished */
5956 modest_main_window_notify_send_receive_completed (main_win);
5958 /* Don't refresh the current folder if there were any errors */
5959 if (modest_mail_operation_get_status (mail_op) !=
5960 MODEST_MAIL_OPERATION_STATUS_SUCCESS)
5963 /* Refresh the current folder if we're viewing a window. We do
5964 this because the user won't be able to see the new mails in
5965 the selected folder after a Send&Receive because it only
5966 performs a poke_status, i.e, only the number of read/unread
5967 messages is updated, but the new headers are not
5969 folder_view = modest_main_window_get_child_widget (main_win,
5970 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
5974 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
5976 /* Do not need to refresh INBOX again because the
5977 update_account does it always automatically */
5978 if (folder_store && TNY_IS_FOLDER (folder_store) &&
5979 tny_folder_get_folder_type (TNY_FOLDER (folder_store)) != TNY_FOLDER_TYPE_INBOX) {
5980 ModestMailOperation *refresh_op;
5982 header_view = modest_main_window_get_child_widget (main_win,
5983 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
5985 /* We do not need to set the contents style
5986 because it hasn't changed. We also do not
5987 need to save the widget status. Just force
5989 refresh_op = modest_mail_operation_new (G_OBJECT (main_win));
5990 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), refresh_op);
5991 modest_mail_operation_refresh_folder (refresh_op, TNY_FOLDER (folder_store),
5992 folder_refreshed_cb, main_win);
5993 g_object_unref (refresh_op);
5997 g_object_unref (folder_store);
6002 modest_ui_actions_on_send_queue_error_happened (TnySendQueue *self,
6008 const gchar* server_name = NULL;
6009 TnyTransportAccount *server_account;
6010 gchar *message = NULL;
6012 /* Don't show anything if the user cancelled something or the
6013 * send receive request is not interactive. Authentication
6014 * errors are managed by the account store so no need to show
6015 * a dialog here again */
6016 if (err->code == TNY_SYSTEM_ERROR_CANCEL ||
6017 err->code == TNY_SERVICE_ERROR_AUTHENTICATE ||
6018 !modest_tny_send_queue_get_requested_send_receive (MODEST_TNY_SEND_QUEUE (self)))
6022 /* Get the server name: */
6024 TNY_TRANSPORT_ACCOUNT (tny_camel_send_queue_get_transport_account (TNY_CAMEL_SEND_QUEUE (self)));
6026 server_name = tny_account_get_hostname (TNY_ACCOUNT (server_account));
6028 g_return_if_reached ();
6030 /* Show the appropriate message text for the GError: */
6031 switch (err->code) {
6032 case TNY_SERVICE_ERROR_CONNECT:
6033 message = g_strdup_printf (_("emev_ib_ui_smtp_server_invalid"), server_name);
6035 case TNY_SERVICE_ERROR_SEND:
6036 message = g_strdup (dgettext("hildon-common-strings", "sfil_ib_unable_to_send"));
6038 case TNY_SERVICE_ERROR_UNAVAILABLE:
6039 message = g_strdup_printf (_("emev_ib_ui_smtp_server_invalid"), server_name);
6042 g_warning ("%s: unexpected ERROR %d",
6043 __FUNCTION__, err->code);
6044 message = g_strdup (dgettext("hildon-common-strings", "sfil_ib_unable_to_send"));
6048 modest_platform_run_information_dialog (NULL, message, FALSE);
6050 g_object_unref (server_account);
6054 modest_ui_actions_on_send_queue_status_changed (ModestTnySendQueue *send_queue,
6059 ModestMainWindow *main_window = NULL;
6060 ModestWindowMgr *mgr = NULL;
6061 GtkWidget *folder_view = NULL, *header_view = NULL;
6062 TnyFolderStore *selected_folder = NULL;
6063 TnyFolderType folder_type;
6065 mgr = modest_runtime_get_window_mgr ();
6066 main_window = MODEST_MAIN_WINDOW (modest_window_mgr_get_main_window (mgr,
6067 FALSE));/* don't create */
6071 /* Check if selected folder is OUTBOX */
6072 folder_view = modest_main_window_get_child_widget (main_window,
6073 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
6074 header_view = modest_main_window_get_child_widget (main_window,
6075 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
6077 selected_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
6078 if (!TNY_IS_FOLDER (selected_folder))
6081 /* gtk_tree_view_column_queue_resize is only available in GTK+ 2.8 */
6082 #if GTK_CHECK_VERSION(2, 8, 0)
6083 folder_type = modest_tny_folder_guess_folder_type (TNY_FOLDER (selected_folder));
6084 if (folder_type == TNY_FOLDER_TYPE_OUTBOX) {
6085 GtkTreeViewColumn *tree_column;
6087 tree_column = gtk_tree_view_get_column (GTK_TREE_VIEW (header_view),
6088 TNY_GTK_HEADER_LIST_MODEL_FROM_COLUMN);
6090 gtk_tree_view_column_queue_resize (tree_column);
6093 gtk_widget_queue_draw (header_view);
6096 /* Rerun dimming rules, because the message could become deletable for example */
6097 modest_window_check_dimming_rules_group (MODEST_WINDOW (main_window),
6098 MODEST_DIMMING_RULES_TOOLBAR);
6099 modest_window_check_dimming_rules_group (MODEST_WINDOW (main_window),
6100 MODEST_DIMMING_RULES_MENU);
6104 if (selected_folder != NULL)
6105 g_object_unref (selected_folder);
6109 modest_ui_actions_on_account_connection_error (GtkWindow *parent_window,
6110 TnyAccount *account)
6112 ModestProtocolType protocol_type;
6113 ModestProtocol *protocol;
6114 gchar *error_note = NULL;
6116 protocol_type = modest_tny_account_get_protocol_type (account);
6117 protocol = modest_protocol_registry_get_protocol_by_type (modest_runtime_get_protocol_registry (),
6120 error_note = modest_protocol_get_translation (protocol, MODEST_PROTOCOL_TRANSLATION_ACCOUNT_CONNECTION_ERROR, tny_account_get_hostname (account));
6121 if (error_note == NULL) {
6122 g_warning ("%s: This should not be reached", __FUNCTION__);
6124 modest_platform_run_information_dialog (parent_window, error_note, FALSE);
6125 g_free (error_note);
6130 modest_ui_actions_get_msg_already_deleted_error_msg (ModestWindow *win)
6134 TnyFolderStore *folder = NULL;
6135 TnyAccount *account = NULL;
6136 ModestProtocolType proto;
6137 ModestProtocol *protocol;
6138 TnyHeader *header = NULL;
6140 if (MODEST_IS_MAIN_WINDOW (win)) {
6141 GtkWidget *header_view;
6142 TnyList* headers = NULL;
6144 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
6145 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
6146 headers = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW (header_view));
6147 if (!headers || tny_list_get_length (headers) == 0) {
6149 g_object_unref (headers);
6152 iter = tny_list_create_iterator (headers);
6153 header = TNY_HEADER (tny_iterator_get_current (iter));
6154 folder = TNY_FOLDER_STORE (tny_header_get_folder (header));
6155 g_object_unref (iter);
6156 g_object_unref (headers);
6157 #ifdef MODEST_TOOLKIT_HILDON2
6158 } else if (MODEST_IS_HEADER_WINDOW (win)) {
6159 GtkWidget *header_view;
6160 TnyList* headers = NULL;
6162 header_view = GTK_WIDGET (modest_header_window_get_header_view (MODEST_HEADER_WINDOW (win)));
6163 headers = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW (header_view));
6164 if (!headers || tny_list_get_length (headers) == 0) {
6166 g_object_unref (headers);
6169 iter = tny_list_create_iterator (headers);
6170 header = TNY_HEADER (tny_iterator_get_current (iter));
6171 folder = TNY_FOLDER_STORE (tny_header_get_folder (header));
6172 g_object_unref (iter);
6173 g_object_unref (headers);
6175 } else if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
6176 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
6177 folder = TNY_FOLDER_STORE (tny_header_get_folder (header));
6180 /* Get the account type */
6181 account = tny_folder_get_account (TNY_FOLDER (folder));
6182 proto = modest_tny_account_get_protocol_type (account);
6183 protocol = modest_protocol_registry_get_protocol_by_type (modest_runtime_get_protocol_registry (),
6186 subject = tny_header_dup_subject (header);
6187 msg = modest_protocol_get_translation (protocol, MODEST_PROTOCOL_TRANSLATION_MSG_NOT_AVAILABLE, subject);
6191 msg = g_strdup_printf (_("mail_ni_ui_folder_get_msg_folder_error"));
6195 g_object_unref (account);
6196 g_object_unref (folder);
6197 g_object_unref (header);
6203 modest_ui_actions_on_delete_account (GtkWindow *parent_window,
6204 const gchar *account_name,
6205 const gchar *account_title)
6207 ModestAccountMgr *account_mgr;
6210 ModestProtocol *protocol;
6211 gboolean removed = FALSE;
6213 g_return_val_if_fail (account_name, FALSE);
6214 g_return_val_if_fail (account_title, FALSE);
6216 account_mgr = modest_runtime_get_account_mgr();
6218 /* The warning text depends on the account type: */
6219 protocol = modest_protocol_registry_get_protocol_by_type (modest_runtime_get_protocol_registry (),
6220 modest_account_mgr_get_store_protocol (account_mgr,
6222 txt = modest_protocol_get_translation (protocol,
6223 MODEST_PROTOCOL_TRANSLATION_DELETE_MAILBOX,
6226 txt = g_strdup_printf (_("emev_nc_delete_mailbox"), account_title);
6228 response = modest_platform_run_confirmation_dialog (parent_window, txt);
6232 if (response == GTK_RESPONSE_OK) {
6233 /* Remove account. If it succeeds then it also removes
6234 the account from the ModestAccountView: */
6235 gboolean is_default = FALSE;
6236 gchar *default_account_name = modest_account_mgr_get_default_account (account_mgr);
6237 if (default_account_name && (strcmp (default_account_name, account_name) == 0))
6239 g_free (default_account_name);
6241 removed = modest_account_mgr_remove_account (account_mgr, account_name);
6243 g_warning ("%s: modest_account_mgr_remove_account() failed.\n", __FUNCTION__);