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>
52 #ifdef MODEST_PLATFORM_MAEMO
53 #include "maemo/modest-osso-state-saving.h"
54 #endif /* MODEST_PLATFORM_MAEMO */
55 #ifndef MODEST_TOOLKIT_GTK
56 #include "maemo/modest-hildon-includes.h"
57 #include "maemo/modest-connection-specific-smtp-window.h"
58 #endif /* !MODEST_TOOLKIT_GTK */
59 #include <modest-utils.h>
61 #include "widgets/modest-ui-constants.h"
62 #include <widgets/modest-main-window.h>
63 #include <widgets/modest-msg-view-window.h>
64 #include <widgets/modest-account-view-window.h>
65 #include <widgets/modest-details-dialog.h>
66 #include <widgets/modest-attachments-view.h>
67 #include "widgets/modest-folder-view.h"
68 #include "widgets/modest-global-settings-dialog.h"
69 #include "modest-account-mgr-helpers.h"
70 #include "modest-mail-operation.h"
71 #include "modest-text-utils.h"
73 #ifdef MODEST_HAVE_EASYSETUP
74 #ifdef MODEST_TOOLKIT_HILDON2
75 #include "modest-easysetup-wizard-dialog.h"
77 #include "easysetup/modest-easysetup-wizard-dialog.h"
79 #endif /* MODEST_HAVE_EASYSETUP */
81 #include <modest-widget-memory.h>
82 #include <tny-error.h>
83 #include <tny-simple-list.h>
84 #include <tny-msg-view.h>
85 #include <tny-device.h>
86 #include <tny-merge-folder.h>
88 #include <gtkhtml/gtkhtml.h>
90 #define MIN_FREE_SPACE 5 * 1024 * 1024
91 #define MOVE_FOLDER_OK_BUTTON "ok-button"
92 #define MOVE_FOLDER_NEW_BUTTON "new-button"
94 typedef struct _GetMsgAsyncHelper {
96 ModestMailOperation *mail_op;
103 typedef enum _ReplyForwardAction {
107 } ReplyForwardAction;
109 typedef struct _ReplyForwardHelper {
110 guint reply_forward_type;
111 ReplyForwardAction action;
113 GtkWidget *parent_window;
115 } ReplyForwardHelper;
117 typedef struct _MoveToHelper {
118 GtkTreeRowReference *reference;
122 typedef struct _PasteAsAttachmentHelper {
123 ModestMsgEditWindow *window;
125 } PasteAsAttachmentHelper;
129 * The do_headers_action uses this kind of functions to perform some
130 * action to each member of a list of headers
132 typedef void (*HeadersFunc) (TnyHeader *header, ModestWindow *win, gpointer user_data);
134 static void do_headers_action (ModestWindow *win,
138 static void open_msg_cb (ModestMailOperation *mail_op,
145 static void reply_forward_cb (ModestMailOperation *mail_op,
152 static void reply_forward (ReplyForwardAction action, ModestWindow *win);
154 static void folder_refreshed_cb (ModestMailOperation *mail_op,
158 static void on_send_receive_finished (ModestMailOperation *mail_op,
161 static gint header_list_count_uncached_msgs (TnyList *header_list);
163 static gboolean connect_to_get_msg (ModestWindow *win,
164 gint num_of_uncached_msgs,
165 TnyAccount *account);
167 static gboolean remote_folder_has_leave_on_server (TnyFolderStore *folder);
169 static void do_create_folder (GtkWindow *window,
170 TnyFolderStore *parent_folder,
171 const gchar *suggested_name);
173 static GtkWidget* get_folder_view_from_move_to_dialog (GtkWidget *move_to_dialog);
175 static TnyAccount *get_account_from_folder_store (TnyFolderStore *folder_store);
178 * This function checks whether a TnyFolderStore is a pop account
181 remote_folder_has_leave_on_server (TnyFolderStore *folder)
186 g_return_val_if_fail (TNY_IS_FOLDER_STORE (folder), FALSE);
188 account = get_account_from_folder_store (folder);
189 result = (modest_protocol_registry_protocol_type_has_leave_on_server (modest_runtime_get_protocol_registry (),
190 modest_tny_account_get_protocol_type (account)));
191 g_object_unref (account);
196 /* FIXME: this should be merged with the similar code in modest-account-view-window */
197 /* Show the account creation wizard dialog.
198 * returns: TRUE if an account was created. FALSE if the user cancelled.
201 modest_ui_actions_run_account_setup_wizard (ModestWindow *win)
203 gboolean result = FALSE;
205 gint dialog_response;
207 /* there is no such wizard yet */
208 wizard = GTK_WINDOW (modest_platform_get_account_settings_wizard ());
209 modest_window_mgr_set_modal (modest_runtime_get_window_mgr(), GTK_WINDOW (wizard), (GtkWindow *) win);
211 /* always present a main window in the background
212 * we do it here, so we cannot end up with two wizards (as this
213 * function might be called in modest_window_mgr_get_main_window as well */
215 win = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr(),
216 TRUE); /* create if not existent */
218 gtk_window_set_transient_for (GTK_WINDOW (wizard), GTK_WINDOW (win));
220 /* make sure the mainwindow is visible. We need to present the
221 wizard again to give it the focus back. show_all are needed
222 in order to get the widgets properly drawn (MainWindow main
223 paned won't be in its right position and the dialog will be
225 #ifndef MODEST_TOOLKIT_HILDON2
226 gtk_widget_show_all (GTK_WIDGET (win));
227 gtk_widget_show_all (GTK_WIDGET (wizard));
228 gtk_window_present (GTK_WINDOW (win));
229 gtk_window_present (GTK_WINDOW (wizard));
232 dialog_response = gtk_dialog_run (GTK_DIALOG (wizard));
233 gtk_widget_destroy (GTK_WIDGET (wizard));
234 if (gtk_events_pending ())
235 gtk_main_iteration ();
237 if (dialog_response == GTK_RESPONSE_CANCEL) {
240 /* Check whether an account was created: */
241 result = modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
248 modest_ui_actions_on_about (GtkAction *action, ModestWindow *win)
251 const gchar *authors[] = {
252 "Dirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>",
255 about = gtk_about_dialog_new ();
256 gtk_about_dialog_set_name (GTK_ABOUT_DIALOG(about), PACKAGE_NAME);
257 gtk_about_dialog_set_version (GTK_ABOUT_DIALOG(about),PACKAGE_VERSION);
258 gtk_about_dialog_set_copyright (GTK_ABOUT_DIALOG(about),
259 _("Copyright (c) 2006, Nokia Corporation\n"
260 "All rights reserved."));
261 gtk_about_dialog_set_comments (GTK_ABOUT_DIALOG(about),
262 _("a modest e-mail client\n\n"
263 "design and implementation: Dirk-Jan C. Binnema\n"
264 "contributions from the fine people at KC and Ig\n"
265 "uses the tinymail email framework written by Philip van Hoof"));
266 gtk_about_dialog_set_authors (GTK_ABOUT_DIALOG(about), authors);
267 gtk_about_dialog_set_website (GTK_ABOUT_DIALOG(about), "http://modest.garage.maemo.org");
268 gtk_window_set_transient_for (GTK_WINDOW (about), GTK_WINDOW (win));
269 gtk_window_set_modal (GTK_WINDOW (about), TRUE);
271 gtk_dialog_run (GTK_DIALOG (about));
272 gtk_widget_destroy(about);
276 * Gets the list of currently selected messages. If the win is the
277 * main window, then it returns a newly allocated list of the headers
278 * selected in the header view. If win is the msg view window, then
279 * the value returned is a list with just a single header.
281 * The caller of this funcion must free the list.
284 get_selected_headers (ModestWindow *win)
286 if (MODEST_IS_MAIN_WINDOW(win)) {
287 GtkWidget *header_view;
289 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
290 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
291 return modest_header_view_get_selected_headers (MODEST_HEADER_VIEW(header_view));
293 } else if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
294 /* for MsgViewWindows, we simply return a list with one element */
296 TnyList *list = NULL;
298 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
299 if (header != NULL) {
300 list = tny_simple_list_new ();
301 tny_list_prepend (list, G_OBJECT(header));
302 g_object_unref (G_OBJECT(header));
311 static GtkTreeRowReference *
312 get_next_after_selected_headers (ModestHeaderView *header_view)
314 GtkTreeSelection *sel;
315 GList *selected_rows, *node;
317 GtkTreeRowReference *result;
320 model = gtk_tree_view_get_model (GTK_TREE_VIEW (header_view));
321 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
322 selected_rows = gtk_tree_selection_get_selected_rows (sel, NULL);
324 if (selected_rows == NULL)
327 node = g_list_last (selected_rows);
328 path = gtk_tree_path_copy ((GtkTreePath *) node->data);
329 gtk_tree_path_next (path);
331 result = gtk_tree_row_reference_new (model, path);
333 gtk_tree_path_free (path);
334 g_list_foreach (selected_rows, (GFunc) gtk_tree_path_free, NULL);
335 g_list_free (selected_rows);
341 headers_action_mark_as_read (TnyHeader *header,
345 TnyHeaderFlags flags;
347 g_return_if_fail (TNY_IS_HEADER(header));
349 flags = tny_header_get_flags (header);
350 if (flags & TNY_HEADER_FLAG_SEEN) return;
351 tny_header_set_flag (header, TNY_HEADER_FLAG_SEEN);
355 headers_action_mark_as_unread (TnyHeader *header,
359 TnyHeaderFlags flags;
361 g_return_if_fail (TNY_IS_HEADER(header));
363 flags = tny_header_get_flags (header);
364 if (flags & TNY_HEADER_FLAG_SEEN) {
365 tny_header_unset_flag (header, TNY_HEADER_FLAG_SEEN);
369 /** After deleing a message that is currently visible in a window,
370 * show the next message from the list, or close the window if there are no more messages.
373 modest_ui_actions_refresh_message_window_after_delete (ModestMsgViewWindow* win)
375 /* Close msg view window or select next */
376 if (!modest_msg_view_window_select_next_message (win) &&
377 !modest_msg_view_window_select_previous_message (win)) {
379 g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value);
385 modest_ui_actions_on_delete_message (GtkAction *action, ModestWindow *win)
387 TnyList *header_list = NULL;
388 TnyIterator *iter = NULL;
389 TnyHeader *header = NULL;
390 gchar *message = NULL;
393 ModestWindowMgr *mgr;
394 GtkWidget *header_view = NULL;
396 g_return_if_fail (MODEST_IS_WINDOW(win));
398 /* Check first if the header view has the focus */
399 if (MODEST_IS_MAIN_WINDOW (win)) {
401 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
402 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
403 if (!gtk_widget_is_focus (header_view))
407 /* Get the headers, either from the header view (if win is the main window),
408 * or from the message view window: */
409 header_list = get_selected_headers (win);
410 if (!header_list) return;
412 /* Check if any of the headers are already opened, or in the process of being opened */
413 if (MODEST_IS_MAIN_WINDOW (win)) {
414 gint opened_headers = 0;
416 iter = tny_list_create_iterator (header_list);
417 mgr = modest_runtime_get_window_mgr ();
418 while (!tny_iterator_is_done (iter)) {
419 header = TNY_HEADER (tny_iterator_get_current (iter));
421 if (modest_window_mgr_find_registered_header (mgr, header, NULL))
423 g_object_unref (header);
425 tny_iterator_next (iter);
427 g_object_unref (iter);
429 if (opened_headers > 0) {
432 msg = g_strdup_printf (_("mcen_nc_unable_to_delete_n_messages"),
435 modest_platform_run_information_dialog (GTK_WINDOW (win), (const gchar *) msg, FALSE);
438 g_object_unref (header_list);
444 if (tny_list_get_length(header_list) == 1) {
445 iter = tny_list_create_iterator (header_list);
446 header = TNY_HEADER (tny_iterator_get_current (iter));
449 subject = tny_header_dup_subject (header);
450 desc = g_strdup_printf ("%s", subject);
452 g_object_unref (header);
455 g_object_unref (iter);
457 message = g_strdup_printf(ngettext("emev_nc_delete_message", "emev_nc_delete_messages",
458 tny_list_get_length(header_list)), desc);
460 /* Confirmation dialog */
461 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
465 if (response == GTK_RESPONSE_OK) {
466 ModestWindow *main_window = NULL;
467 ModestWindowMgr *mgr = NULL;
468 GtkTreeModel *model = NULL;
469 GtkTreeSelection *sel = NULL;
470 GList *sel_list = NULL, *tmp = NULL;
471 GtkTreeRowReference *next_row_reference = NULL;
472 GtkTreeRowReference *prev_row_reference = NULL;
473 GtkTreePath *next_path = NULL;
474 GtkTreePath *prev_path = NULL;
475 ModestMailOperation *mail_op = NULL;
477 /* Find last selected row */
478 if (MODEST_IS_MAIN_WINDOW (win)) {
479 model = gtk_tree_view_get_model (GTK_TREE_VIEW (header_view));
480 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
481 sel_list = gtk_tree_selection_get_selected_rows (sel, &model);
482 for (tmp=sel_list; tmp; tmp=tmp->next) {
483 if (tmp->next == NULL) {
484 prev_path = gtk_tree_path_copy((GtkTreePath *) tmp->data);
485 next_path = gtk_tree_path_copy((GtkTreePath *) tmp->data);
487 gtk_tree_path_prev (prev_path);
488 gtk_tree_path_next (next_path);
490 prev_row_reference = gtk_tree_row_reference_new (model, prev_path);
491 next_row_reference = gtk_tree_row_reference_new (model, next_path);
496 /* Disable window dimming management */
497 modest_window_disable_dimming (MODEST_WINDOW(win));
499 /* Remove each header. If it's a view window header_view == NULL */
500 mail_op = modest_mail_operation_new ((GObject *) win);
501 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
503 modest_mail_operation_remove_msgs (mail_op, header_list, FALSE);
504 g_object_unref (mail_op);
506 /* Enable window dimming management */
508 gtk_tree_selection_unselect_all (sel);
510 modest_window_enable_dimming (MODEST_WINDOW(win));
512 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
513 modest_ui_actions_refresh_message_window_after_delete (MODEST_MSG_VIEW_WINDOW (win));
515 /* Get main window */
516 mgr = modest_runtime_get_window_mgr ();
517 main_window = modest_window_mgr_get_main_window (mgr, FALSE); /* don't create */
519 /* Move cursor to next row */
522 /* Select next or previous row */
523 if (gtk_tree_row_reference_valid (next_row_reference)) {
524 gtk_tree_selection_select_path (sel, next_path);
526 else if (gtk_tree_row_reference_valid (prev_row_reference)) {
527 gtk_tree_selection_select_path (sel, prev_path);
531 if (next_row_reference != NULL)
532 gtk_tree_row_reference_free (next_row_reference);
533 if (next_path != NULL)
534 gtk_tree_path_free (next_path);
535 if (prev_row_reference != NULL)
536 gtk_tree_row_reference_free (prev_row_reference);
537 if (prev_path != NULL)
538 gtk_tree_path_free (prev_path);
541 /* Update toolbar dimming state */
543 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (main_window));
544 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
548 g_list_foreach (sel_list, (GFunc) gtk_tree_path_free, NULL);
549 g_list_free (sel_list);
555 g_object_unref (header_list);
561 /* delete either message or folder, based on where we are */
563 modest_ui_actions_on_delete_message_or_folder (GtkAction *action, ModestWindow *win)
565 g_return_if_fail (MODEST_IS_WINDOW(win));
567 /* Check first if the header view has the focus */
568 if (MODEST_IS_MAIN_WINDOW (win)) {
570 w = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
571 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
572 if (gtk_widget_is_focus (w)) {
573 modest_ui_actions_on_delete_folder (action, MODEST_MAIN_WINDOW(win));
577 modest_ui_actions_on_delete_message (action, win);
581 modest_ui_actions_on_quit (GtkAction *action, ModestWindow *win)
583 ModestWindowMgr *mgr = NULL;
585 #ifdef MODEST_PLATFORM_MAEMO
586 modest_osso_save_state();
587 #endif /* MODEST_PLATFORM_MAEMO */
589 g_debug ("closing down, clearing %d item(s) from operation queue",
590 modest_mail_operation_queue_num_elements
591 (modest_runtime_get_mail_operation_queue()));
593 /* cancel all outstanding operations */
594 modest_mail_operation_queue_cancel_all
595 (modest_runtime_get_mail_operation_queue());
597 g_debug ("queue has been cleared");
600 /* Check if there are opened editing windows */
601 mgr = modest_runtime_get_window_mgr ();
602 modest_window_mgr_close_all_windows (mgr);
604 /* note: when modest-tny-account-store is finalized,
605 it will automatically set all network connections
608 /* gtk_main_quit (); */
612 modest_ui_actions_on_close_window (GtkAction *action, ModestWindow *win)
616 g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value);
618 /* if (MODEST_IS_MSG_VIEW_WINDOW (win)) { */
619 /* gtk_widget_destroy (GTK_WIDGET (win)); */
620 /* } else if (MODEST_IS_MSG_EDIT_WINDOW (win)) { */
621 /* gboolean ret_value; */
622 /* g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value); */
623 /* } else if (MODEST_IS_WINDOW (win)) { */
624 /* gtk_widget_destroy (GTK_WIDGET (win)); */
626 /* g_return_if_reached (); */
631 modest_ui_actions_on_add_to_contacts (GtkAction *action, ModestWindow *win)
633 GtkClipboard *clipboard = NULL;
634 gchar *selection = NULL;
636 clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
637 selection = gtk_clipboard_wait_for_text (clipboard);
639 /* Question: why is the clipboard being used here?
640 * It doesn't really make a lot of sense. */
644 modest_address_book_add_address (selection);
650 modest_ui_actions_on_accounts (GtkAction *action,
653 /* This is currently only implemented for Maemo */
654 if (!modest_account_mgr_has_accounts (modest_runtime_get_account_mgr(), TRUE)) {
655 if (!modest_ui_actions_run_account_setup_wizard (win))
656 g_debug ("%s: wizard was already running", __FUNCTION__);
660 /* Show the list of accounts */
661 GtkWindow *account_win = GTK_WINDOW (modest_account_view_window_new ());
663 /* The accounts dialog must be modal */
664 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (account_win), (GtkWindow *) win);
665 modest_utils_show_dialog_and_forget (GTK_WINDOW (win), GTK_DIALOG (account_win));
670 modest_ui_actions_on_smtp_servers (GtkAction *action, ModestWindow *win)
672 /* This is currently only implemented for Maemo,
673 * because it requires an API (libconic) to detect different connection
676 #ifndef MODEST_TOOLKIT_GTK /* Defined in config.h */
678 /* Create the window if necessary: */
679 GtkWidget *specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
680 modest_connection_specific_smtp_window_fill_with_connections (
681 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (specific_window),
682 modest_runtime_get_account_mgr());
684 /* Show the window: */
685 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (),
686 GTK_WINDOW (specific_window), (GtkWindow *) win);
687 gtk_widget_show (specific_window);
688 #endif /* !MODEST_TOOLKIT_GTK */
692 modest_ui_actions_compose_msg(ModestWindow *win,
695 const gchar *bcc_str,
696 const gchar *subject_str,
697 const gchar *body_str,
699 gboolean set_as_modified)
701 gchar *account_name = NULL;
703 TnyAccount *account = NULL;
704 TnyFolder *folder = NULL;
705 gchar *from_str = NULL, *signature = NULL, *body = NULL;
706 gboolean use_signature = FALSE;
707 ModestWindow *msg_win = NULL;
708 ModestAccountMgr *mgr = modest_runtime_get_account_mgr();
709 ModestTnyAccountStore *store = modest_runtime_get_account_store();
710 GnomeVFSFileSize total_size, allowed_size;
712 /* we check for low-mem; in that case, show a warning, and don't allow
713 * composing a message with attachments
715 if (attachments && modest_platform_check_memory_low (win, TRUE))
718 #ifdef MODEST_TOOLKIT_HILDON2
719 account_name = g_strdup (modest_window_get_active_account(win));
722 account_name = modest_account_mgr_get_default_account(mgr);
725 g_printerr ("modest: no account found\n");
728 account = modest_tny_account_store_get_server_account (store, account_name, TNY_ACCOUNT_TYPE_STORE);
730 g_printerr ("modest: failed to get tnyaccount for '%s'\n", account_name);
733 folder = modest_tny_account_get_special_folder (account, TNY_FOLDER_TYPE_DRAFTS);
735 g_printerr ("modest: failed to find Drafts folder\n");
738 from_str = modest_account_mgr_get_from_string (mgr, account_name);
740 g_printerr ("modest: failed get from string for '%s'\n", account_name);
744 signature = modest_account_mgr_get_signature (mgr, account_name, &use_signature);
745 if (body_str != NULL) {
746 body = use_signature ? g_strconcat(body_str, "\n--\n", signature, NULL) : g_strdup(body_str);
748 body = use_signature ? g_strconcat("\n--\n", signature, NULL) : g_strdup("");
751 msg = modest_tny_msg_new (to_str, from_str, cc_str, bcc_str, subject_str, body, NULL, NULL, NULL);
753 g_printerr ("modest: failed to create new msg\n");
757 /* Create and register edit window */
758 /* This is destroyed by TODO. */
760 allowed_size = MODEST_MAX_ATTACHMENT_SIZE;
761 msg_win = modest_msg_edit_window_new (msg, account_name, FALSE);
763 if (!modest_window_mgr_register_window (modest_runtime_get_window_mgr(), msg_win, NULL)) {
764 gtk_widget_destroy (GTK_WIDGET (msg_win));
767 modest_msg_edit_window_set_modified (MODEST_MSG_EDIT_WINDOW (msg_win), set_as_modified);
768 gtk_widget_show_all (GTK_WIDGET (msg_win));
770 while (attachments) {
772 modest_msg_edit_window_attach_file_one((ModestMsgEditWindow *)msg_win,
773 attachments->data, allowed_size);
775 if (total_size > allowed_size) {
776 g_warning ("%s: total size: %u",
777 __FUNCTION__, (unsigned int)total_size);
780 allowed_size -= total_size;
782 attachments = g_slist_next(attachments);
789 g_free (account_name);
791 g_object_unref (G_OBJECT(account));
793 g_object_unref (G_OBJECT(folder));
795 g_object_unref (G_OBJECT(msg));
799 modest_ui_actions_on_new_msg (GtkAction *action, ModestWindow *win)
801 /* if there are no accounts yet, just show the wizard */
802 if (!modest_account_mgr_has_accounts (modest_runtime_get_account_mgr(), TRUE))
803 if (!modest_ui_actions_run_account_setup_wizard (win))
806 modest_ui_actions_compose_msg(win, NULL, NULL, NULL, NULL, NULL, NULL, FALSE);
811 modest_ui_actions_msg_retrieval_check (ModestMailOperation *mail_op,
815 ModestMailOperationStatus status;
817 /* If there is no message or the operation was not successful */
818 status = modest_mail_operation_get_status (mail_op);
819 if (!msg || status != MODEST_MAIL_OPERATION_STATUS_SUCCESS) {
822 /* If it's a memory low issue, then show a banner */
823 error = modest_mail_operation_get_error (mail_op);
824 if (error && error->domain == MODEST_MAIL_OPERATION_ERROR &&
825 error->code == MODEST_MAIL_OPERATION_ERROR_LOW_MEMORY) {
826 GObject *source = modest_mail_operation_get_source (mail_op);
827 modest_platform_run_information_dialog (GTK_IS_WINDOW (source) ? GTK_WINDOW (source) : NULL,
828 dgettext("ke-recv","memr_ib_operation_disabled"),
830 g_object_unref (source);
833 if (error && ((error->code == TNY_SERVICE_ERROR_NO_SUCH_MESSAGE) ||
834 error->code == TNY_SERVICE_ERROR_MESSAGE_NOT_AVAILABLE)) {
835 gchar *subject, *msg;
836 subject = tny_header_dup_subject (header);
837 msg = g_strdup_printf (_("emev_ni_ui_imap_message_not_available_in_server"),
839 modest_platform_run_information_dialog (NULL, msg, FALSE);
844 /* Remove the header from the preregistered uids */
845 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (),
863 OpenMsgBannerInfo *banner_info;
864 GHashTable *row_refs_per_header;
868 open_msg_banner_idle (gpointer userdata)
870 OpenMsgBannerInfo *banner_info = (OpenMsgBannerInfo *) userdata;
872 gdk_threads_enter ();
873 banner_info->idle_handler = 0;
874 banner_info->banner = modest_platform_animation_banner (NULL, NULL, banner_info->message);
876 g_object_ref (banner_info->banner);
878 gdk_threads_leave ();
885 open_msg_cb (ModestMailOperation *mail_op,
892 ModestWindowMgr *mgr = NULL;
893 ModestWindow *parent_win = NULL;
894 ModestWindow *win = NULL;
895 TnyFolderType folder_type = TNY_FOLDER_TYPE_UNKNOWN;
896 gchar *account = NULL;
898 gboolean open_in_editor = FALSE;
899 OpenMsgHelper *helper = (OpenMsgHelper *) user_data;
901 /* Do nothing if there was any problem with the mail
902 operation. The error will be shown by the error_handler of
903 the mail operation */
904 if (!modest_ui_actions_msg_retrieval_check (mail_op, header, msg))
907 parent_win = (ModestWindow *) modest_mail_operation_get_source (mail_op);
908 folder = tny_header_get_folder (header);
910 /* Mark header as read */
911 headers_action_mark_as_read (header, MODEST_WINDOW(parent_win), NULL);
913 /* Gets folder type (OUTBOX headers will be opened in edit window */
914 if (modest_tny_folder_is_local_folder (folder)) {
915 folder_type = modest_tny_folder_get_local_or_mmc_folder_type (folder);
916 if (folder_type == TNY_FOLDER_TYPE_INVALID)
917 g_warning ("%s: BUG: TNY_FOLDER_TYPE_INVALID", __FUNCTION__);
921 if (folder_type == TNY_FOLDER_TYPE_OUTBOX) {
922 TnyTransportAccount *traccount = NULL;
923 ModestTnyAccountStore *accstore = modest_runtime_get_account_store();
924 traccount = modest_tny_account_store_get_transport_account_from_outbox_header(accstore, header);
926 ModestTnySendQueue *send_queue = NULL;
927 ModestTnySendQueueStatus status;
929 account = g_strdup(modest_tny_account_get_parent_modest_account_name_for_server_account(
930 TNY_ACCOUNT(traccount)));
931 send_queue = modest_runtime_get_send_queue(traccount, TRUE);
932 if (TNY_IS_SEND_QUEUE (send_queue)) {
933 msg_id = modest_tny_send_queue_get_msg_id (header);
934 status = modest_tny_send_queue_get_msg_status(send_queue, msg_id);
935 /* Only open messages in outbox with the editor if they are in Failed state */
936 if (status == MODEST_TNY_SEND_QUEUE_FAILED) {
937 open_in_editor = TRUE;
941 g_object_unref(traccount);
943 g_warning("Cannot get transport account for message in outbox!!");
945 } else if (folder_type == TNY_FOLDER_TYPE_DRAFTS) {
946 open_in_editor = TRUE; /* Open in editor if the message is in the Drafts folder */
951 account = g_strdup (modest_window_get_active_account (MODEST_WINDOW (parent_win)));
953 account = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
955 if (open_in_editor) {
956 ModestAccountMgr *mgr = modest_runtime_get_account_mgr ();
957 gchar *from_header = NULL, *acc_name;
959 from_header = tny_header_dup_from (header);
961 /* we cannot edit without a valid account... */
962 if (!modest_account_mgr_has_accounts(mgr, TRUE)) {
963 if (!modest_ui_actions_run_account_setup_wizard(parent_win)) {
964 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (),
966 g_free (from_header);
971 acc_name = modest_utils_get_account_name_from_recipient (from_header);
972 g_free (from_header);
978 win = modest_msg_edit_window_new (msg, account, TRUE);
980 gchar *uid = modest_tny_folder_get_header_unique_id (header);
982 if (MODEST_IS_MAIN_WINDOW (parent_win)) {
983 GtkTreeRowReference *row_reference;
985 row_reference = (GtkTreeRowReference *) g_hash_table_lookup (helper->row_refs_per_header, header);
987 win = modest_msg_view_window_new_with_header_model (msg, account, (const gchar*) uid,
988 helper->model, row_reference);
990 win = modest_msg_view_window_new_for_attachment (msg, account, (const gchar*) uid);
995 /* Register and show new window */
997 mgr = modest_runtime_get_window_mgr ();
998 if (!modest_window_mgr_register_window (mgr, win, NULL)) {
999 gtk_widget_destroy (GTK_WIDGET (win));
1002 gtk_widget_show_all (GTK_WIDGET(win));
1005 /* Update toolbar dimming state */
1006 if (MODEST_IS_MAIN_WINDOW (parent_win)) {
1007 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (parent_win));
1013 g_object_unref (parent_win);
1014 g_object_unref (folder);
1018 is_memory_full_error (GError *error)
1020 gboolean enough_free_space = TRUE;
1021 GnomeVFSURI *cache_dir_uri;
1022 const gchar *cache_dir;
1023 GnomeVFSFileSize free_space;
1025 cache_dir = tny_account_store_get_cache_dir (TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()));
1026 cache_dir_uri = gnome_vfs_uri_new (cache_dir);
1027 if (gnome_vfs_get_volume_free_space (cache_dir_uri, &free_space) == GNOME_VFS_OK) {
1028 if (free_space < MIN_FREE_SPACE)
1029 enough_free_space = FALSE;
1031 gnome_vfs_uri_unref (cache_dir_uri);
1033 if ((error->code == TNY_SYSTEM_ERROR_MEMORY ||
1034 /* When asking for a mail and no space left on device
1035 tinymail returns this error */
1036 error->code == TNY_SERVICE_ERROR_MESSAGE_NOT_AVAILABLE ||
1037 /* When the folder summary could not be read or
1039 error->code == TNY_IO_ERROR_WRITE ||
1040 error->code == TNY_IO_ERROR_READ) &&
1041 !enough_free_space) {
1049 check_memory_full_error (GtkWidget *parent_window, GError *err)
1054 if (is_memory_full_error (err))
1055 modest_platform_information_banner (parent_window,
1056 NULL, dgettext("ke-recv",
1057 "cerm_device_memory_full"));
1058 else if (err->code == TNY_SYSTEM_ERROR_MEMORY)
1059 /* If the account was created in memory full
1060 conditions then tinymail won't be able to
1061 connect so it'll return this error code */
1062 modest_platform_information_banner (parent_window,
1063 NULL, _("emev_ui_imap_inbox_select_error"));
1071 modest_ui_actions_disk_operations_error_handler (ModestMailOperation *mail_op,
1074 const GError *error;
1075 GObject *win = NULL;
1076 ModestMailOperationStatus status;
1078 win = modest_mail_operation_get_source (mail_op);
1079 error = modest_mail_operation_get_error (mail_op);
1080 status = modest_mail_operation_get_status (mail_op);
1082 /* If the mail op has been cancelled then it's not an error:
1083 don't show any message */
1084 if (status != MODEST_MAIL_OPERATION_STATUS_CANCELED) {
1085 if (is_memory_full_error ((GError *) error)) {
1086 modest_platform_information_banner ((GtkWidget *) win,
1087 NULL, dgettext("ke-recv",
1088 "cerm_device_memory_full"));
1089 } else if (error->code == TNY_SYSTEM_ERROR_MEMORY) {
1090 modest_platform_information_banner ((GtkWidget *) win,
1091 NULL, _("emev_ui_imap_inbox_select_error"));
1092 } else if (error->domain == MODEST_MAIL_OPERATION_ERROR &&
1093 error->code == MODEST_MAIL_OPERATION_ERROR_FILE_IO) {
1094 modest_platform_information_banner ((GtkWidget *) win,
1095 NULL, dgettext ("hildon-common-strings", "sfil_ni_unable_to_open_file_not_found"));
1096 } else if (user_data) {
1097 modest_platform_information_banner ((GtkWidget *) win,
1103 g_object_unref (win);
1107 * Returns the account a list of headers belongs to. It returns a
1108 * *new* reference so don't forget to unref it
1111 get_account_from_header_list (TnyList *headers)
1113 TnyAccount *account = NULL;
1115 if (tny_list_get_length (headers) > 0) {
1116 TnyIterator *iter = tny_list_create_iterator (headers);
1117 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter));
1118 TnyFolder *folder = tny_header_get_folder (header);
1121 g_object_unref (header);
1123 while (!tny_iterator_is_done (iter)) {
1124 header = TNY_HEADER (tny_iterator_get_current (iter));
1125 folder = tny_header_get_folder (header);
1128 g_object_unref (header);
1130 tny_iterator_next (iter);
1135 account = tny_folder_get_account (folder);
1136 g_object_unref (folder);
1140 g_object_unref (header);
1142 g_object_unref (iter);
1148 foreach_unregister_headers (gpointer data,
1151 ModestWindowMgr *mgr = (ModestWindowMgr *) user_data;
1152 TnyHeader *header = TNY_HEADER (data);
1154 modest_window_mgr_unregister_header (mgr, header);
1158 open_msgs_helper_destroyer (gpointer user_data)
1160 OpenMsgHelper *helper = (OpenMsgHelper *) user_data;
1162 if (helper->banner_info) {
1163 g_free (helper->banner_info->message);
1164 if (helper->banner_info->idle_handler > 0) {
1165 g_source_remove (helper->banner_info->idle_handler);
1166 helper->banner_info->idle_handler = 0;
1168 if (helper->banner_info->banner != NULL) {
1169 gtk_widget_destroy (helper->banner_info->banner);
1170 g_object_unref (helper->banner_info->banner);
1171 helper->banner_info->banner = NULL;
1173 g_slice_free (OpenMsgBannerInfo, helper->banner_info);
1174 helper->banner_info = NULL;
1176 g_object_unref (helper->model);
1177 g_object_unref (helper->headers);
1178 g_hash_table_destroy (helper->row_refs_per_header);
1179 g_slice_free (OpenMsgHelper, helper);
1183 open_msgs_performer(gboolean canceled,
1185 GtkWindow *parent_window,
1186 TnyAccount *account,
1189 ModestMailOperation *mail_op = NULL;
1191 ModestProtocolType proto;
1192 TnyList *not_opened_headers;
1193 TnyConnectionStatus status;
1194 gboolean show_open_draft = FALSE;
1195 OpenMsgHelper *helper = NULL;
1197 helper = (OpenMsgHelper *) user_data;
1198 not_opened_headers = helper->headers;
1200 status = tny_account_get_connection_status (account);
1201 if (err || canceled) {
1202 /* Unregister the already registered headers */
1203 tny_list_foreach (not_opened_headers, foreach_unregister_headers,
1204 modest_runtime_get_window_mgr ());
1205 /* Free the helper */
1206 open_msgs_helper_destroyer (helper);
1208 /* In memory full conditions we could get this error here */
1209 check_memory_full_error ((GtkWidget *) parent_window, err);
1214 /* Get the error message depending on the protocol */
1215 proto = modest_tny_account_get_protocol_type (account);
1216 if (proto == MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1217 proto = MODEST_PROTOCOLS_STORE_MAILDIR;
1220 /* Create the error messages */
1221 if (tny_list_get_length (not_opened_headers) == 1) {
1222 ModestProtocol *protocol;
1223 ModestProtocolRegistry *protocol_registry;
1228 protocol_registry = modest_runtime_get_protocol_registry ();
1229 iter = tny_list_create_iterator (not_opened_headers);
1230 header = TNY_HEADER (tny_iterator_get_current (iter));
1231 subject = tny_header_dup_subject (header);
1233 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, proto);
1234 error_msg = modest_protocol_get_translation (protocol, MODEST_PROTOCOL_TRANSLATION_MSG_NOT_AVAILABLE, subject);
1236 g_object_unref (header);
1237 g_object_unref (iter);
1239 if (error_msg == NULL) {
1240 error_msg = g_strdup (_("mail_ni_ui_folder_get_msg_folder_error"));
1243 if (modest_protocol_registry_protocol_type_has_tag (protocol_registry,
1245 MODEST_PROTOCOL_REGISTRY_LOCAL_STORE_PROTOCOLS)) {
1249 TnyFolderType folder_type;
1251 iter = tny_list_create_iterator (not_opened_headers);
1252 header = TNY_HEADER (tny_iterator_get_current (iter));
1253 folder = tny_header_get_folder (header);
1254 folder_type = modest_tny_folder_get_local_or_mmc_folder_type (folder);
1255 show_open_draft = (folder_type == TNY_FOLDER_TYPE_DRAFTS);
1256 g_object_unref (folder);
1257 g_object_unref (header);
1258 g_object_unref (iter);
1261 error_msg = g_strdup (_("mail_ni_ui_folder_get_msg_folder_error"));
1264 /* Create the mail operation */
1266 modest_mail_operation_new_with_error_handling ((GObject *) parent_window,
1267 modest_ui_actions_disk_operations_error_handler,
1269 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
1272 if (show_open_draft) {
1273 helper->banner_info = g_slice_new (OpenMsgBannerInfo);
1274 helper->banner_info->message = g_strdup (_("mail_ib_opening_draft_message"));
1275 helper->banner_info->banner = NULL;
1276 helper->banner_info->idle_handler = g_timeout_add (500, open_msg_banner_idle,
1277 helper->banner_info);
1280 modest_mail_operation_get_msgs_full (mail_op,
1284 open_msgs_helper_destroyer);
1289 g_object_unref (mail_op);
1290 g_object_unref (account);
1294 * This function is used by both modest_ui_actions_on_open and
1295 * modest_ui_actions_on_header_activated. This way we always do the
1296 * same when trying to open messages.
1299 open_msgs_from_headers (TnyList *headers, ModestWindow *win)
1301 ModestWindowMgr *mgr = NULL;
1302 TnyIterator *iter = NULL, *iter_not_opened = NULL;
1303 TnyList *not_opened_headers = NULL;
1304 TnyHeaderFlags flags = 0;
1305 TnyAccount *account;
1306 gint uncached_msgs = 0;
1307 GtkWidget *header_view;
1308 GtkTreeModel *model;
1309 GHashTable *refs_for_headers;
1310 OpenMsgHelper *helper;
1311 GtkTreeSelection *sel;
1312 GList *sel_list = NULL, *sel_list_iter = NULL;
1314 g_return_if_fail (headers != NULL);
1316 /* Check that only one message is selected for opening */
1317 if (tny_list_get_length (headers) != 1) {
1318 modest_platform_information_banner ((win) ? GTK_WIDGET (win) : NULL,
1319 NULL, _("mcen_ib_select_one_message"));
1323 mgr = modest_runtime_get_window_mgr ();
1324 iter = tny_list_create_iterator (headers);
1326 /* Get the account */
1327 account = get_account_from_header_list (headers);
1332 /* Get the selections, we need to get the references to the
1333 rows here because the treeview/model could dissapear (the
1334 user might want to select another folder)*/
1335 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
1336 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1337 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
1338 model = gtk_tree_view_get_model (GTK_TREE_VIEW (header_view));
1339 sel_list = gtk_tree_selection_get_selected_rows (sel, &model);
1340 refs_for_headers = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL,
1341 (GDestroyNotify) gtk_tree_row_reference_free);
1343 /* Look if we already have a message view for each header. If
1344 true, then remove the header from the list of headers to
1346 sel_list_iter = sel_list;
1347 not_opened_headers = tny_simple_list_new ();
1348 while (!tny_iterator_is_done (iter) && sel_list_iter) {
1350 ModestWindow *window = NULL;
1351 TnyHeader *header = NULL;
1352 gboolean found = FALSE;
1354 header = TNY_HEADER (tny_iterator_get_current (iter));
1356 flags = tny_header_get_flags (header);
1359 found = modest_window_mgr_find_registered_header (mgr, header, &window);
1361 /* Do not open again the message and present the
1362 window to the user */
1365 #ifndef MODEST_TOOLKIT_HILDON2
1366 gtk_window_present (GTK_WINDOW (window));
1369 /* the header has been registered already, we don't do
1370 * anything but wait for the window to come up*/
1371 g_debug ("header %p already registered, waiting for window", header);
1374 GtkTreeRowReference *row_reference;
1376 tny_list_append (not_opened_headers, G_OBJECT (header));
1377 /* Create a new row reference and add it to the hash table */
1378 row_reference = gtk_tree_row_reference_new (model, (GtkTreePath *) sel_list_iter->data);
1379 g_hash_table_insert (refs_for_headers, header, row_reference);
1383 g_object_unref (header);
1386 tny_iterator_next (iter);
1387 sel_list_iter = g_list_next (sel_list_iter);
1389 g_object_unref (iter);
1391 g_list_foreach (sel_list, (GFunc) gtk_tree_path_free, NULL);
1392 g_list_free (sel_list);
1394 /* Open each message */
1395 if (tny_list_get_length (not_opened_headers) == 0) {
1396 g_hash_table_destroy (refs_for_headers);
1400 /* If some messages would have to be downloaded, ask the user to
1401 * make a connection. It's generally easier to do this here (in the mainloop)
1402 * than later in a thread:
1404 if (tny_list_get_length (not_opened_headers) > 0) {
1405 uncached_msgs = header_list_count_uncached_msgs (not_opened_headers);
1407 if (uncached_msgs > 0) {
1408 /* Allways download if we are online. */
1409 if (!tny_device_is_online (modest_runtime_get_device ())) {
1412 /* If ask for user permission to download the messages */
1413 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
1414 ngettext("mcen_nc_get_msg",
1418 /* End if the user does not want to continue */
1419 if (response == GTK_RESPONSE_CANCEL) {
1420 g_hash_table_destroy (refs_for_headers);
1427 /* Register the headers before actually creating the windows: */
1428 iter_not_opened = tny_list_create_iterator (not_opened_headers);
1429 while (!tny_iterator_is_done (iter_not_opened)) {
1430 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter_not_opened));
1432 modest_window_mgr_register_header (mgr, header, NULL);
1433 g_object_unref (header);
1435 tny_iterator_next (iter_not_opened);
1437 g_object_unref (iter_not_opened);
1438 iter_not_opened = NULL;
1440 /* Create the helper. We need to get a reference to the model
1441 here because it could change while the message is readed
1442 (the user could switch between folders) */
1443 helper = g_slice_new (OpenMsgHelper);
1444 helper->model = g_object_ref (model);
1445 helper->headers = g_object_ref (not_opened_headers);
1446 helper->row_refs_per_header = refs_for_headers;
1447 helper->banner_info = NULL;
1449 /* Connect to the account and perform */
1450 if (uncached_msgs > 0) {
1451 modest_platform_connect_and_perform ((GtkWindow *) win, TRUE, g_object_ref (account),
1452 open_msgs_performer, helper);
1454 /* Call directly the performer, do not need to connect */
1455 open_msgs_performer (FALSE, NULL, (GtkWindow *) win,
1456 g_object_ref (account), helper);
1461 g_object_unref (account);
1462 if (not_opened_headers)
1463 g_object_unref (not_opened_headers);
1467 modest_ui_actions_on_open (GtkAction *action, ModestWindow *win)
1471 /* we check for low-mem; in that case, show a warning, and don't allow
1474 if (modest_platform_check_memory_low (MODEST_WINDOW(win), TRUE))
1478 headers = get_selected_headers (win);
1483 open_msgs_from_headers (headers, win);
1485 g_object_unref(headers);
1488 static ReplyForwardHelper*
1489 create_reply_forward_helper (ReplyForwardAction action,
1491 guint reply_forward_type,
1494 ReplyForwardHelper *rf_helper = NULL;
1495 const gchar *active_acc = modest_window_get_active_account (win);
1497 rf_helper = g_slice_new0 (ReplyForwardHelper);
1498 rf_helper->reply_forward_type = reply_forward_type;
1499 rf_helper->action = action;
1500 rf_helper->parent_window = (MODEST_IS_WINDOW (win)) ? GTK_WIDGET (win) : NULL;
1501 rf_helper->header = (header) ? g_object_ref (header) : NULL;
1502 rf_helper->account_name = (active_acc) ?
1503 g_strdup (active_acc) :
1504 modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
1510 free_reply_forward_helper (gpointer data)
1512 ReplyForwardHelper *helper;
1514 helper = (ReplyForwardHelper *) data;
1515 g_free (helper->account_name);
1517 g_object_unref (helper->header);
1518 g_slice_free (ReplyForwardHelper, helper);
1522 reply_forward_cb (ModestMailOperation *mail_op,
1529 TnyMsg *new_msg = NULL;
1530 ReplyForwardHelper *rf_helper;
1531 ModestWindow *msg_win = NULL;
1532 ModestEditType edit_type;
1534 TnyAccount *account = NULL;
1535 ModestWindowMgr *mgr = NULL;
1536 gchar *signature = NULL;
1537 gboolean use_signature;
1539 /* If there was any error. The mail operation could be NULL,
1540 this means that we already have the message downloaded and
1541 that we didn't do a mail operation to retrieve it */
1542 rf_helper = (ReplyForwardHelper *) user_data;
1543 if (mail_op && !modest_ui_actions_msg_retrieval_check (mail_op, header, msg))
1546 from = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(),
1547 rf_helper->account_name);
1548 signature = modest_account_mgr_get_signature (modest_runtime_get_account_mgr(),
1549 rf_helper->account_name,
1552 /* Create reply mail */
1553 switch (rf_helper->action) {
1556 modest_tny_msg_create_reply_msg (msg, header, from,
1557 (use_signature) ? signature : NULL,
1558 rf_helper->reply_forward_type,
1559 MODEST_TNY_MSG_REPLY_MODE_SENDER);
1561 case ACTION_REPLY_TO_ALL:
1563 modest_tny_msg_create_reply_msg (msg, header, from,
1564 (use_signature) ? signature : NULL,
1565 rf_helper->reply_forward_type,
1566 MODEST_TNY_MSG_REPLY_MODE_ALL);
1567 edit_type = MODEST_EDIT_TYPE_REPLY;
1569 case ACTION_FORWARD:
1571 modest_tny_msg_create_forward_msg (msg, from, (use_signature) ? signature : NULL,
1572 rf_helper->reply_forward_type);
1573 edit_type = MODEST_EDIT_TYPE_FORWARD;
1576 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (),
1578 g_return_if_reached ();
1586 g_warning ("%s: failed to create message\n", __FUNCTION__);
1590 account = modest_tny_account_store_get_server_account (modest_runtime_get_account_store(),
1591 rf_helper->account_name,
1592 TNY_ACCOUNT_TYPE_STORE);
1594 g_warning ("%s: failed to get tnyaccount for '%s'\n", __FUNCTION__, rf_helper->account_name);
1598 /* Create and register the windows */
1599 msg_win = modest_msg_edit_window_new (new_msg, rf_helper->account_name, FALSE);
1600 mgr = modest_runtime_get_window_mgr ();
1601 modest_window_mgr_register_window (mgr, msg_win, (ModestWindow *) rf_helper->parent_window);
1603 if (rf_helper->parent_window != NULL) {
1604 gdouble parent_zoom;
1606 parent_zoom = modest_window_get_zoom (MODEST_WINDOW (rf_helper->parent_window));
1607 modest_window_set_zoom (msg_win, parent_zoom);
1610 /* Show edit window */
1611 gtk_widget_show_all (GTK_WIDGET (msg_win));
1614 /* We always unregister the header because the message is
1615 forwarded or replied so the original one is no longer
1617 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (),
1620 g_object_unref (G_OBJECT (new_msg));
1622 g_object_unref (G_OBJECT (account));
1623 free_reply_forward_helper (rf_helper);
1626 /* Checks a list of headers. If any of them are not currently
1627 * downloaded (CACHED) then returns TRUE else returns FALSE.
1630 header_list_count_uncached_msgs (TnyList *header_list)
1633 gint uncached_messages = 0;
1635 iter = tny_list_create_iterator (header_list);
1636 while (!tny_iterator_is_done (iter)) {
1639 header = TNY_HEADER (tny_iterator_get_current (iter));
1641 if (!(tny_header_get_flags (header) & TNY_HEADER_FLAG_CACHED))
1642 uncached_messages ++;
1643 g_object_unref (header);
1646 tny_iterator_next (iter);
1648 g_object_unref (iter);
1650 return uncached_messages;
1653 /* Returns FALSE if the user does not want to download the
1654 * messages. Returns TRUE if the user allowed the download.
1657 connect_to_get_msg (ModestWindow *win,
1658 gint num_of_uncached_msgs,
1659 TnyAccount *account)
1661 GtkResponseType response;
1663 /* Allways download if we are online. */
1664 if (tny_device_is_online (modest_runtime_get_device ()))
1667 /* If offline, then ask for user permission to download the messages */
1668 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
1669 ngettext("mcen_nc_get_msg",
1671 num_of_uncached_msgs));
1673 if (response == GTK_RESPONSE_CANCEL)
1676 return modest_platform_connect_and_wait((GtkWindow *) win, account);
1680 reply_forward_performer (gboolean canceled,
1682 GtkWindow *parent_window,
1683 TnyAccount *account,
1686 ReplyForwardHelper *rf_helper = NULL;
1687 ModestMailOperation *mail_op;
1689 rf_helper = (ReplyForwardHelper *) user_data;
1691 if (canceled || err) {
1692 free_reply_forward_helper (rf_helper);
1696 /* Retrieve the message */
1697 modest_window_mgr_register_header (modest_runtime_get_window_mgr (), rf_helper->header, NULL);
1698 mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT (parent_window),
1699 modest_ui_actions_disk_operations_error_handler,
1701 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
1702 modest_mail_operation_get_msg (mail_op, rf_helper->header, TRUE, reply_forward_cb, rf_helper);
1705 g_object_unref(mail_op);
1709 * Common code for the reply and forward actions
1712 reply_forward (ReplyForwardAction action, ModestWindow *win)
1714 ReplyForwardHelper *rf_helper = NULL;
1715 guint reply_forward_type;
1717 g_return_if_fail (MODEST_IS_WINDOW(win));
1719 /* we check for low-mem; in that case, show a warning, and don't allow
1720 * reply/forward (because it could potentially require a lot of memory */
1721 if (modest_platform_check_memory_low (MODEST_WINDOW(win), TRUE))
1725 /* we need an account when editing */
1726 if (!modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE)) {
1727 if (!modest_ui_actions_run_account_setup_wizard (win))
1731 reply_forward_type =
1732 modest_conf_get_int (modest_runtime_get_conf (),
1733 (action == ACTION_FORWARD) ?
1734 MODEST_CONF_FORWARD_TYPE :
1735 MODEST_CONF_REPLY_TYPE,
1738 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
1740 TnyHeader *header = NULL;
1741 /* Get header and message. Do not free them here, the
1742 reply_forward_cb must do it */
1743 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW(win));
1744 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
1746 if (msg && header) {
1748 rf_helper = create_reply_forward_helper (action, win,
1749 reply_forward_type, header);
1750 reply_forward_cb (NULL, header, FALSE, msg, NULL, rf_helper);
1752 g_warning("%s: no message or header found in viewer\n", __FUNCTION__);
1756 g_object_unref (msg);
1758 g_object_unref (header);
1760 TnyHeader *header = NULL;
1762 gboolean do_retrieve = TRUE;
1763 TnyList *header_list = NULL;
1765 header_list = get_selected_headers (win);
1768 /* Check that only one message is selected for replying */
1769 if (tny_list_get_length (header_list) != 1) {
1770 modest_platform_information_banner ((win) ? GTK_WIDGET (win) : NULL,
1771 NULL, _("mcen_ib_select_one_message"));
1772 g_object_unref (header_list);
1776 /* Only reply/forward to one message */
1777 iter = tny_list_create_iterator (header_list);
1778 header = TNY_HEADER (tny_iterator_get_current (iter));
1779 g_object_unref (iter);
1781 /* Retrieve messages */
1782 do_retrieve = (action == ACTION_FORWARD) ||
1783 (reply_forward_type != MODEST_TNY_MSG_REPLY_TYPE_CITE);
1786 TnyAccount *account = NULL;
1787 TnyFolder *folder = NULL;
1788 gdouble download = TRUE;
1789 guint uncached_msgs = 0;
1791 folder = tny_header_get_folder (header);
1793 goto do_retrieve_frees;
1794 account = tny_folder_get_account (folder);
1796 goto do_retrieve_frees;
1798 uncached_msgs = header_list_count_uncached_msgs (header_list);
1800 if (uncached_msgs > 0) {
1801 /* Allways download if we are online. */
1802 if (!tny_device_is_online (modest_runtime_get_device ())) {
1805 /* If ask for user permission to download the messages */
1806 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
1807 ngettext("mcen_nc_get_msg",
1811 /* End if the user does not want to continue */
1812 if (response == GTK_RESPONSE_CANCEL)
1819 rf_helper = create_reply_forward_helper (action, win,
1820 reply_forward_type, header);
1821 if (uncached_msgs > 0) {
1822 modest_platform_connect_and_perform (GTK_WINDOW (win),
1824 reply_forward_performer,
1827 reply_forward_performer (FALSE, NULL, GTK_WINDOW (win),
1828 account, rf_helper);
1833 g_object_unref (account);
1835 g_object_unref (folder);
1837 reply_forward_cb (NULL, header, FALSE, NULL, NULL, rf_helper);
1840 g_object_unref (header_list);
1841 g_object_unref (header);
1846 modest_ui_actions_on_reply (GtkAction *action, ModestWindow *win)
1848 g_return_if_fail (MODEST_IS_WINDOW(win));
1850 reply_forward (ACTION_REPLY, win);
1854 modest_ui_actions_on_forward (GtkAction *action, ModestWindow *win)
1856 g_return_if_fail (MODEST_IS_WINDOW(win));
1858 reply_forward (ACTION_FORWARD, win);
1862 modest_ui_actions_on_reply_all (GtkAction *action, ModestWindow *win)
1864 g_return_if_fail (MODEST_IS_WINDOW(win));
1866 reply_forward (ACTION_REPLY_TO_ALL, win);
1870 modest_ui_actions_on_next (GtkAction *action,
1871 ModestWindow *window)
1873 if (MODEST_IS_MAIN_WINDOW (window)) {
1874 GtkWidget *header_view;
1876 header_view = modest_main_window_get_child_widget (
1877 MODEST_MAIN_WINDOW(window),
1878 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1882 modest_header_view_select_next (
1883 MODEST_HEADER_VIEW(header_view));
1884 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
1885 modest_msg_view_window_select_next_message (
1886 MODEST_MSG_VIEW_WINDOW (window));
1888 g_return_if_reached ();
1893 modest_ui_actions_on_prev (GtkAction *action,
1894 ModestWindow *window)
1896 g_return_if_fail (MODEST_IS_WINDOW(window));
1898 if (MODEST_IS_MAIN_WINDOW (window)) {
1899 GtkWidget *header_view;
1900 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
1901 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1905 modest_header_view_select_prev (MODEST_HEADER_VIEW(header_view));
1906 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
1907 modest_msg_view_window_select_previous_message (MODEST_MSG_VIEW_WINDOW (window));
1909 g_return_if_reached ();
1914 modest_ui_actions_on_sort (GtkAction *action,
1915 ModestWindow *window)
1917 g_return_if_fail (MODEST_IS_WINDOW(window));
1919 if (MODEST_IS_MAIN_WINDOW (window)) {
1920 GtkWidget *header_view;
1921 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
1922 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1924 modest_platform_information_banner (NULL, NULL, _CS("ckdg_ib_nothing_to_sort"));
1929 /* Show sorting dialog */
1930 modest_utils_run_sort_dialog (GTK_WINDOW (window), MODEST_SORT_HEADERS);
1935 new_messages_arrived (ModestMailOperation *self,
1936 TnyList *new_headers,
1940 gboolean show_visual_notifications;
1942 source = modest_mail_operation_get_source (self);
1943 show_visual_notifications = (source) ? FALSE : TRUE;
1945 g_object_unref (source);
1947 /* Notify new messages have been downloaded. If the
1948 send&receive was invoked by the user then do not show any
1949 visual notification, only play a sound and activate the LED
1950 (for the Maemo version) */
1951 if (TNY_IS_LIST(new_headers) && (tny_list_get_length (new_headers)) > 0)
1952 modest_platform_on_new_headers_received (new_headers,
1953 show_visual_notifications);
1958 retrieve_all_messages_cb (GObject *source,
1960 guint retrieve_limit)
1966 window = GTK_WINDOW (source);
1967 msg = g_strdup_printf (_("mail_nc_msg_count_limit_exceeded"),
1968 num_msgs, retrieve_limit);
1970 /* Ask the user if they want to retrieve all the messages */
1972 modest_platform_run_confirmation_dialog_with_buttons (window, msg,
1973 _("mcen_bd_get_all"),
1974 _("mcen_bd_newest_only"));
1975 /* Free and return */
1977 return (response == GTK_RESPONSE_ACCEPT) ? TRUE : FALSE;
1981 TnyAccount *account;
1983 gchar *account_name;
1984 gboolean poke_status;
1985 gboolean interactive;
1986 ModestMailOperation *mail_op;
1990 do_send_receive_performer (gboolean canceled,
1992 GtkWindow *parent_window,
1993 TnyAccount *account,
1996 SendReceiveInfo *info;
1998 info = (SendReceiveInfo *) user_data;
2000 if (err || canceled) {
2001 /* In memory full conditions we could get this error here */
2002 check_memory_full_error ((GtkWidget *) parent_window, err);
2004 if (info->mail_op) {
2005 modest_mail_operation_queue_remove (modest_runtime_get_mail_operation_queue (),
2011 /* Set send/receive operation in progress */
2012 if (info->win && MODEST_IS_MAIN_WINDOW (info->win)) {
2013 modest_main_window_notify_send_receive_initied (MODEST_MAIN_WINDOW (info->win));
2016 if (info->win && MODEST_IS_MAIN_WINDOW (info->win))
2017 g_signal_connect (G_OBJECT (info->mail_op), "operation-finished",
2018 G_CALLBACK (on_send_receive_finished),
2021 /* Send & receive. */
2022 modest_mail_operation_update_account (info->mail_op, info->account_name, info->poke_status, info->interactive,
2023 (info->win) ? retrieve_all_messages_cb : NULL,
2024 new_messages_arrived, info->win);
2029 g_object_unref (G_OBJECT (info->mail_op));
2030 if (info->account_name)
2031 g_free (info->account_name);
2033 g_object_unref (info->win);
2035 g_object_unref (info->account);
2036 g_slice_free (SendReceiveInfo, info);
2040 * This function performs the send & receive required actions. The
2041 * window is used to create the mail operation. Typically it should
2042 * always be the main window, but we pass it as argument in order to
2046 modest_ui_actions_do_send_receive (const gchar *account_name,
2047 gboolean force_connection,
2048 gboolean poke_status,
2049 gboolean interactive,
2052 gchar *acc_name = NULL;
2053 SendReceiveInfo *info;
2054 ModestTnyAccountStore *acc_store;
2056 /* If no account name was provided then get the current account, and if
2057 there is no current account then pick the default one: */
2058 if (!account_name) {
2060 acc_name = g_strdup (modest_window_get_active_account (win));
2062 acc_name = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
2064 g_printerr ("modest: cannot get default account\n");
2068 acc_name = g_strdup (account_name);
2071 acc_store = modest_runtime_get_account_store ();
2073 /* Create the info for the connect and perform */
2074 info = g_slice_new (SendReceiveInfo);
2075 info->account_name = acc_name;
2076 info->win = (win) ? g_object_ref (win) : NULL;
2077 info->poke_status = poke_status;
2078 info->interactive = interactive;
2079 info->account = modest_tny_account_store_get_server_account (acc_store, acc_name,
2080 TNY_ACCOUNT_TYPE_STORE);
2081 /* We need to create the operation here, because otherwise it
2082 could happen that the queue emits the queue-empty signal
2083 while we're trying to connect the account */
2084 info->mail_op = modest_mail_operation_new_with_error_handling ((info->win) ? G_OBJECT (info->win) : NULL,
2085 modest_ui_actions_disk_operations_error_handler,
2087 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), info->mail_op);
2089 /* Invoke the connect and perform */
2090 modest_platform_connect_and_perform ((win) ? GTK_WINDOW (win) : NULL,
2091 force_connection, info->account,
2092 do_send_receive_performer, info);
2097 modest_ui_actions_do_cancel_send (const gchar *account_name,
2100 TnyTransportAccount *transport_account;
2101 TnySendQueue *send_queue = NULL;
2102 GError *error = NULL;
2104 /* Get transport account */
2106 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
2107 (modest_runtime_get_account_store(),
2109 TNY_ACCOUNT_TYPE_TRANSPORT));
2110 if (!transport_account) {
2111 g_printerr ("modest: no transport account found for '%s'\n", account_name);
2116 send_queue = TNY_SEND_QUEUE (modest_runtime_get_send_queue (transport_account, TRUE));
2117 if (!TNY_IS_SEND_QUEUE(send_queue)) {
2118 g_set_error (&error, MODEST_MAIL_OPERATION_ERROR,
2119 MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND,
2120 "modest: could not find send queue for account\n");
2122 /* Cancel the current send */
2123 tny_account_cancel (TNY_ACCOUNT (transport_account));
2125 /* Suspend all pending messages */
2126 tny_send_queue_cancel (send_queue, TNY_SEND_QUEUE_CANCEL_ACTION_SUSPEND, &error);
2130 if (transport_account != NULL)
2131 g_object_unref (G_OBJECT (transport_account));
2135 modest_ui_actions_cancel_send_all (ModestWindow *win)
2137 GSList *account_names, *iter;
2139 account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
2142 iter = account_names;
2144 modest_ui_actions_do_cancel_send ((const char*) iter->data, win);
2145 iter = g_slist_next (iter);
2148 modest_account_mgr_free_account_names (account_names);
2149 account_names = NULL;
2153 modest_ui_actions_cancel_send (GtkAction *action, ModestWindow *win)
2156 /* Check if accounts exist */
2157 gboolean accounts_exist =
2158 modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
2160 /* If not, allow the user to create an account before trying to send/receive. */
2161 if (!accounts_exist)
2162 modest_ui_actions_on_accounts (NULL, win);
2164 /* Cancel all sending operaitons */
2165 modest_ui_actions_cancel_send_all (win);
2169 * Refreshes all accounts. This function will be used by automatic
2173 modest_ui_actions_do_send_receive_all (ModestWindow *win,
2174 gboolean force_connection,
2175 gboolean poke_status,
2176 gboolean interactive)
2178 GSList *account_names, *iter;
2180 account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
2183 iter = account_names;
2185 modest_ui_actions_do_send_receive ((const char*) iter->data,
2187 poke_status, interactive, win);
2188 iter = g_slist_next (iter);
2191 modest_account_mgr_free_account_names (account_names);
2192 account_names = NULL;
2196 * Handler of the click on Send&Receive button in the main toolbar
2199 modest_ui_actions_on_send_receive (GtkAction *action, ModestWindow *win)
2201 /* Check if accounts exist */
2202 gboolean accounts_exist;
2205 modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
2207 /* If not, allow the user to create an account before trying to send/receive. */
2208 if (!accounts_exist)
2209 modest_ui_actions_on_accounts (NULL, win);
2211 /* Refresh the current folder. The if is always TRUE it's just an extra check */
2212 if (MODEST_IS_MAIN_WINDOW (win)) {
2213 GtkWidget *folder_view;
2214 TnyFolderStore *folder_store;
2217 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
2218 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2222 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
2225 g_object_unref (folder_store);
2228 /* Refresh the active account. Force the connection if needed
2229 and poke the status of all folders */
2230 modest_ui_actions_do_send_receive (NULL, TRUE, TRUE, TRUE, win);
2235 modest_ui_actions_toggle_header_list_view (GtkAction *action, ModestMainWindow *main_window)
2238 GtkWidget *header_view;
2240 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2242 header_view = modest_main_window_get_child_widget (main_window,
2243 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2247 conf = modest_runtime_get_conf ();
2249 /* what is saved/restored is depending on the style; thus; we save with
2250 * old style, then update the style, and restore for this new style
2252 modest_widget_memory_save (conf, G_OBJECT(header_view), MODEST_CONF_HEADER_VIEW_KEY);
2254 if (modest_header_view_get_style
2255 (MODEST_HEADER_VIEW(header_view)) == MODEST_HEADER_VIEW_STYLE_DETAILS)
2256 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
2257 MODEST_HEADER_VIEW_STYLE_TWOLINES);
2259 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
2260 MODEST_HEADER_VIEW_STYLE_DETAILS);
2262 modest_widget_memory_restore (conf, G_OBJECT(header_view),
2263 MODEST_CONF_HEADER_VIEW_KEY);
2268 modest_ui_actions_on_header_selected (ModestHeaderView *header_view,
2270 ModestMainWindow *main_window)
2272 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2273 g_return_if_fail (MODEST_IS_HEADER_VIEW (header_view));
2275 /* in the case the folder is empty, show the empty folder message and focus
2277 if (!header && gtk_widget_is_focus (GTK_WIDGET (header_view))) {
2278 if (modest_header_view_is_empty (header_view)) {
2279 TnyFolder *folder = modest_header_view_get_folder (header_view);
2280 GtkWidget *folder_view =
2281 modest_main_window_get_child_widget (main_window,
2282 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2283 if (folder != NULL) {
2284 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view), folder, FALSE);
2285 g_object_unref (folder);
2287 gtk_widget_grab_focus (GTK_WIDGET (folder_view));
2291 /* If no header has been selected then exit */
2296 if (!gtk_widget_is_focus (GTK_WIDGET(header_view)))
2297 gtk_widget_grab_focus (GTK_WIDGET(header_view));
2299 /* Update toolbar dimming state */
2300 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (main_window));
2301 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
2305 modest_ui_actions_on_header_activated (ModestHeaderView *header_view,
2307 ModestMainWindow *main_window)
2310 GtkWidget *open_widget;
2312 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2317 if (modest_header_view_count_selected_headers (header_view) > 1) {
2318 modest_platform_information_banner (NULL, NULL, _("mcen_ib_select_one_message"));
2322 /* we check for low-mem; in that case, show a warning, and don't allow
2323 * activating headers
2325 if (modest_platform_check_memory_low (MODEST_WINDOW(main_window), TRUE))
2328 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (main_window));
2329 open_widget = modest_window_get_action_widget (MODEST_WINDOW (main_window), "/MenuBar/EmailMenu/EmailOpenMenu");
2330 if (!GTK_WIDGET_IS_SENSITIVE (open_widget))
2333 headers = modest_header_view_get_selected_headers (header_view);
2335 open_msgs_from_headers (headers, MODEST_WINDOW (main_window));
2337 g_object_unref (headers);
2341 set_active_account_from_tny_account (TnyAccount *account,
2342 ModestWindow *window)
2344 const gchar *server_acc_name = tny_account_get_id (account);
2346 /* We need the TnyAccount provided by the
2347 account store because that is the one that
2348 knows the name of the Modest account */
2349 TnyAccount *modest_server_account = modest_server_account =
2350 modest_tny_account_store_get_tny_account_by (modest_runtime_get_account_store (),
2351 MODEST_TNY_ACCOUNT_STORE_QUERY_ID,
2353 if (!modest_server_account) {
2354 g_warning ("%s: could not get tny account\n", __FUNCTION__);
2358 /* Update active account, but only if it's not a pseudo-account */
2359 if ((!modest_tny_account_is_virtual_local_folders(modest_server_account)) &&
2360 (!modest_tny_account_is_memory_card_account(modest_server_account))) {
2361 const gchar *modest_acc_name =
2362 modest_tny_account_get_parent_modest_account_name_for_server_account (modest_server_account);
2363 if (modest_acc_name)
2364 modest_window_set_active_account (window, modest_acc_name);
2367 g_object_unref (modest_server_account);
2372 folder_refreshed_cb (ModestMailOperation *mail_op,
2376 ModestMainWindow *win = NULL;
2377 GtkWidget *folder_view;
2378 const GError *error;
2380 g_return_if_fail (TNY_IS_FOLDER (folder));
2382 win = MODEST_MAIN_WINDOW (user_data);
2384 /* Check if the operation failed due to memory low conditions */
2385 error = modest_mail_operation_get_error (mail_op);
2386 if (error && error->domain == MODEST_MAIL_OPERATION_ERROR &&
2387 error->code == MODEST_MAIL_OPERATION_ERROR_LOW_MEMORY) {
2388 modest_platform_run_information_dialog (GTK_WINDOW (win),
2389 dgettext("ke-recv","memr_ib_operation_disabled"),
2395 modest_main_window_get_child_widget(win, MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2398 TnyFolderStore *current_folder;
2400 current_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
2401 if (current_folder) {
2402 gboolean different = ((TnyFolderStore *) folder != current_folder);
2403 g_object_unref (current_folder);
2409 /* Check if folder is empty and set headers view contents style */
2410 if (tny_folder_get_all_count (folder) == 0)
2411 modest_main_window_set_contents_style (win,
2412 MODEST_MAIN_WINDOW_CONTENTS_STYLE_EMPTY);
2417 modest_ui_actions_on_folder_selection_changed (ModestFolderView *folder_view,
2418 TnyFolderStore *folder_store,
2420 ModestMainWindow *main_window)
2423 GtkWidget *header_view;
2425 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2427 header_view = modest_main_window_get_child_widget(main_window,
2428 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2432 conf = modest_runtime_get_conf ();
2434 if (TNY_IS_ACCOUNT (folder_store)) {
2436 set_active_account_from_tny_account (TNY_ACCOUNT (folder_store), MODEST_WINDOW (main_window));
2438 /* Show account details */
2439 modest_main_window_set_contents_style (main_window, MODEST_MAIN_WINDOW_CONTENTS_STYLE_DETAILS);
2442 if (TNY_IS_FOLDER (folder_store) && selected) {
2443 TnyAccount *account;
2444 const gchar *account_name = NULL;
2446 /* Update the active account */
2447 account = modest_tny_folder_get_account (TNY_FOLDER (folder_store));
2449 set_active_account_from_tny_account (account, MODEST_WINDOW (main_window));
2451 modest_tny_account_get_parent_modest_account_name_for_server_account (account);
2452 g_object_unref (account);
2456 /* Set the header style by default, it could
2457 be changed later by the refresh callback to
2459 modest_main_window_set_contents_style (main_window,
2460 MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS);
2462 /* Set folder on header view. This function
2463 will call tny_folder_refresh_async so we
2464 pass a callback that will be called when
2465 finished. We use that callback to set the
2466 empty view if there are no messages */
2467 modest_header_view_set_folder (MODEST_HEADER_VIEW(header_view),
2468 TNY_FOLDER (folder_store),
2470 folder_refreshed_cb,
2473 /* Restore configuration. We need to do this
2474 *after* the set_folder because the widget
2475 memory asks the header view about its
2477 modest_widget_memory_restore (modest_runtime_get_conf (),
2478 G_OBJECT(header_view),
2479 MODEST_CONF_HEADER_VIEW_KEY);
2481 /* No need to save the header view
2482 configuration for Maemo because it only
2483 saves the sorting stuff and that it's
2484 already being done by the sort
2485 dialog. Remove it when the GNOME version
2486 has the same behaviour */
2487 #ifdef MODEST_TOOLKIT_GTK
2488 if (modest_main_window_get_contents_style (main_window) ==
2489 MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS)
2490 modest_widget_memory_save (conf, G_OBJECT (header_view),
2491 MODEST_CONF_HEADER_VIEW_KEY);
2493 modest_header_view_clear (MODEST_HEADER_VIEW(header_view));
2497 /* Update dimming state */
2498 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (main_window));
2499 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
2503 modest_ui_actions_on_item_not_found (ModestHeaderView *header_view,ModestItemType type,
2510 item = (type == MODEST_ITEM_TYPE_FOLDER) ? "folder" : "message";
2512 online = tny_device_is_online (modest_runtime_get_device());
2515 /* already online -- the item is simply not there... */
2516 dialog = gtk_message_dialog_new (GTK_WINDOW (win),
2518 GTK_MESSAGE_WARNING,
2520 _("The %s you selected cannot be found"),
2522 gtk_dialog_add_button (GTK_DIALOG (dialog),_("mcen_bd_dialog_ok"), GTK_RESPONSE_ACCEPT);
2523 gtk_dialog_run (GTK_DIALOG(dialog));
2525 dialog = gtk_dialog_new_with_buttons (_("Connection requested"),
2528 _("mcen_bd_dialog_cancel"),
2529 GTK_RESPONSE_REJECT,
2530 _("mcen_bd_dialog_ok"),
2531 GTK_RESPONSE_ACCEPT,
2533 txt = g_strdup_printf (_("This %s is not available in offline mode.\n"
2534 "Do you want to get online?"), item);
2535 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
2536 gtk_label_new (txt), FALSE, FALSE, 0);
2537 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
2540 gtk_window_set_default_size (GTK_WINDOW(dialog), 300, 300);
2541 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
2542 /* TODO: Comment about why is this commented out: */
2543 /* modest_platform_connect_and_wait (); */
2546 gtk_widget_destroy (dialog);
2550 modest_ui_actions_on_msg_link_hover (ModestMsgView *msgview, const gchar* link,
2553 /* g_message ("%s %s", __FUNCTION__, link); */
2558 modest_ui_actions_on_msg_link_clicked (ModestMsgView *msgview, const gchar* link,
2561 modest_platform_activate_uri (link);
2565 modest_ui_actions_on_msg_link_contextual (ModestMsgView *msgview, const gchar* link,
2568 modest_platform_show_uri_popup (link);
2572 modest_ui_actions_on_msg_attachment_clicked (ModestMsgView *msgview, TnyMimePart *mime_part,
2575 /* we check for low-mem; in that case, show a warning, and don't allow
2576 * viewing attachments
2578 if (modest_platform_check_memory_low (MODEST_WINDOW(win), TRUE))
2581 modest_msg_view_window_view_attachment (MODEST_MSG_VIEW_WINDOW (win), mime_part);
2585 modest_ui_actions_on_msg_recpt_activated (ModestMsgView *msgview,
2586 const gchar *address,
2589 /* g_message ("%s %s", __FUNCTION__, address); */
2593 on_save_to_drafts_cb (ModestMailOperation *mail_op,
2594 TnyMsg *saved_draft,
2597 ModestMsgEditWindow *edit_window;
2598 ModestMainWindow *win;
2600 /* FIXME. Make the header view sensitive again. This is a
2601 * temporary hack. See modest_ui_actions_on_save_to_drafts()
2603 win = MODEST_MAIN_WINDOW(modest_window_mgr_get_main_window(
2604 modest_runtime_get_window_mgr(), FALSE));
2606 GtkWidget *hdrview = modest_main_window_get_child_widget(
2607 win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2608 if (hdrview) gtk_widget_set_sensitive(hdrview, TRUE);
2611 edit_window = MODEST_MSG_EDIT_WINDOW (user_data);
2613 /* Set draft is there was no error */
2614 if (!modest_mail_operation_get_error (mail_op))
2615 modest_msg_edit_window_set_draft (edit_window, saved_draft);
2617 g_object_unref(edit_window);
2621 enough_space_for_message (ModestMsgEditWindow *edit_window,
2624 TnyAccountStore *acc_store;
2625 guint64 available_disk, expected_size;
2630 acc_store = TNY_ACCOUNT_STORE (modest_runtime_get_account_store());
2631 available_disk = modest_utils_get_available_space (NULL);
2632 modest_msg_edit_window_get_parts_size (edit_window, &parts_count, &parts_size);
2633 expected_size = modest_tny_msg_estimate_size (data->plain_body,
2638 /* Double check: memory full condition or message too big */
2639 if (available_disk < MIN_FREE_SPACE ||
2640 expected_size > available_disk) {
2642 modest_platform_information_banner (NULL, NULL,
2644 "cerm_device_memory_full"));
2649 * djcb: if we're in low-memory state, we only allow for
2650 * saving messages smaller than
2651 * MODEST_MAX_LOW_MEMORY_MESSAGE_SIZE (see modest-defs.h) this
2652 * should still allow for sending anything critical...
2654 if ((expected_size > MODEST_MAX_LOW_MEMORY_MESSAGE_SIZE) &&
2655 modest_platform_check_memory_low (MODEST_WINDOW(edit_window), TRUE))
2659 * djcb: we also make sure that the attachments are smaller than the max size
2660 * this is for the case where we'd try to forward a message with attachments
2661 * bigger than our max allowed size, or sending an message from drafts which
2662 * somehow got past our checks when attaching.
2664 if (expected_size > MODEST_MAX_ATTACHMENT_SIZE) {
2665 modest_platform_run_information_dialog (
2666 GTK_WINDOW(edit_window),
2667 dgettext("ke-recv","memr_ib_operation_disabled"),
2676 modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edit_window)
2678 TnyTransportAccount *transport_account;
2679 ModestMailOperation *mail_operation;
2681 gchar *account_name, *from;
2682 ModestAccountMgr *account_mgr;
2683 gboolean had_error = FALSE;
2684 ModestMainWindow *win;
2686 g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window), FALSE);
2688 data = modest_msg_edit_window_get_msg_data (edit_window);
2691 if (!enough_space_for_message (edit_window, data)) {
2692 modest_msg_edit_window_free_msg_data (edit_window, data);
2696 account_name = g_strdup (data->account_name);
2697 account_mgr = modest_runtime_get_account_mgr();
2699 account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
2701 account_name = modest_account_mgr_get_default_account (account_mgr);
2702 if (!account_name) {
2703 g_printerr ("modest: no account found\n");
2704 modest_msg_edit_window_free_msg_data (edit_window, data);
2708 if (!strcmp (account_name, MODEST_LOCAL_FOLDERS_ACCOUNT_ID)) {
2709 account_name = g_strdup (data->account_name);
2713 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
2714 (modest_runtime_get_account_store (),
2716 TNY_ACCOUNT_TYPE_TRANSPORT));
2717 if (!transport_account) {
2718 g_printerr ("modest: no transport account found for '%s'\n", account_name);
2719 g_free (account_name);
2720 modest_msg_edit_window_free_msg_data (edit_window, data);
2723 from = modest_account_mgr_get_from_string (account_mgr, account_name);
2725 /* Create the mail operation */
2726 mail_operation = modest_mail_operation_new_with_error_handling (NULL, modest_ui_actions_disk_operations_error_handler,
2728 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
2730 modest_mail_operation_save_to_drafts (mail_operation,
2742 data->priority_flags,
2743 on_save_to_drafts_cb,
2744 g_object_ref(edit_window));
2746 #ifdef MODEST_TOOLKIT_HILDON2
2747 /* In hildon2 we always show the information banner on saving to drafts.
2748 * It will be a system information banner in this case.
2750 gchar *text = g_strdup_printf (_("mail_va_saved_to_drafts"), _("mcen_me_folder_drafts"));
2751 modest_platform_information_banner (NULL, NULL, text);
2754 /* Use the main window as the parent of the banner, if the
2755 main window does not exist it won't be shown, if the parent
2756 window exists then it's properly shown. We don't use the
2757 editor window because it could be closed (save to drafts
2758 could happen after closing the window */
2759 win = (ModestMainWindow *)
2760 modest_window_mgr_get_main_window( modest_runtime_get_window_mgr(), FALSE);
2762 gchar *text = g_strdup_printf (_("mail_va_saved_to_drafts"), _("mcen_me_folder_drafts"));
2763 modest_platform_information_banner (GTK_WIDGET (win), NULL, text);
2767 modest_msg_edit_window_set_modified (edit_window, FALSE);
2771 g_free (account_name);
2772 g_object_unref (G_OBJECT (transport_account));
2773 g_object_unref (G_OBJECT (mail_operation));
2775 modest_msg_edit_window_free_msg_data (edit_window, data);
2778 * If the drafts folder is selected then make the header view
2779 * insensitive while the message is being saved to drafts
2780 * (it'll be sensitive again in on_save_to_drafts_cb()). This
2781 * is not very clean but it avoids letting the drafts folder
2782 * in an inconsistent state: the user could edit the message
2783 * being saved and undesirable things would happen.
2784 * In the average case the user won't notice anything at
2785 * all. In the worst case (the user is editing a really big
2786 * file from Drafts) the header view will be insensitive
2787 * during the saving process (10 or 20 seconds, depending on
2788 * the message). Anyway this is just a quick workaround: once
2789 * we find a better solution it should be removed
2790 * See NB#65125 (commend #18) for details.
2792 if (!had_error && win != NULL) {
2793 ModestFolderView *view = MODEST_FOLDER_VIEW(modest_main_window_get_child_widget(
2794 win, MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW));
2796 TnyFolder *folder = TNY_FOLDER(modest_folder_view_get_selected(view));
2798 if (modest_tny_folder_is_local_folder(folder)) {
2799 TnyFolderType folder_type;
2800 folder_type = modest_tny_folder_get_local_or_mmc_folder_type(folder);
2801 if (folder_type == TNY_FOLDER_TYPE_DRAFTS) {
2802 GtkWidget *hdrview = modest_main_window_get_child_widget(
2803 win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2804 if (hdrview) gtk_widget_set_sensitive(hdrview, FALSE);
2808 if (folder != NULL) g_object_unref(folder);
2815 /* For instance, when clicking the Send toolbar button when editing a message: */
2817 modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
2819 TnyTransportAccount *transport_account = NULL;
2820 gboolean had_error = FALSE;
2822 ModestAccountMgr *account_mgr;
2823 gchar *account_name;
2825 ModestMailOperation *mail_operation;
2827 g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window), TRUE);
2829 if (!modest_msg_edit_window_check_names (edit_window, TRUE))
2832 data = modest_msg_edit_window_get_msg_data (edit_window);
2835 if (!enough_space_for_message (edit_window, data)) {
2836 modest_msg_edit_window_free_msg_data (edit_window, data);
2840 account_mgr = modest_runtime_get_account_mgr();
2841 account_name = g_strdup (data->account_name);
2843 account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
2846 account_name = modest_account_mgr_get_default_account (account_mgr);
2848 if (!account_name) {
2849 modest_msg_edit_window_free_msg_data (edit_window, data);
2850 /* Run account setup wizard */
2851 if (!modest_ui_actions_run_account_setup_wizard (MODEST_WINDOW(edit_window))) {
2856 /* Get the currently-active transport account for this modest account: */
2857 if (strcmp (account_name, MODEST_LOCAL_FOLDERS_ACCOUNT_ID) != 0) {
2859 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
2860 (modest_runtime_get_account_store (),
2861 account_name, TNY_ACCOUNT_TYPE_TRANSPORT));
2864 if (!transport_account) {
2865 modest_msg_edit_window_free_msg_data (edit_window, data);
2866 /* Run account setup wizard */
2867 if (!modest_ui_actions_run_account_setup_wizard(MODEST_WINDOW(edit_window)))
2872 /* Create the mail operation */
2873 from = modest_account_mgr_get_from_string (account_mgr, account_name);
2874 mail_operation = modest_mail_operation_new_with_error_handling (NULL, modest_ui_actions_disk_operations_error_handler, NULL, NULL);
2875 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
2877 modest_mail_operation_send_new_mail (mail_operation,
2889 data->priority_flags);
2891 if (modest_mail_operation_get_status (mail_operation) == MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS)
2892 modest_platform_information_banner (NULL, NULL, _("mcen_ib_outbox_waiting_to_be_sent"));
2895 if (modest_mail_operation_get_error (mail_operation) != NULL) {
2896 const GError *error = modest_mail_operation_get_error (mail_operation);
2897 if (error->domain == MODEST_MAIL_OPERATION_ERROR &&
2898 error->code == MODEST_MAIL_OPERATION_ERROR_INSTANCE_CREATION_FAILED) {
2899 g_warning ("%s failed: %s\n", __FUNCTION__, (modest_mail_operation_get_error (mail_operation))->message);
2900 modest_platform_information_banner (NULL, NULL, _CS("sfil_ni_not_enough_memory"));
2907 g_free (account_name);
2908 g_object_unref (G_OBJECT (transport_account));
2909 g_object_unref (G_OBJECT (mail_operation));
2911 modest_msg_edit_window_free_msg_data (edit_window, data);
2914 modest_msg_edit_window_set_sent (edit_window, TRUE);
2916 /* Save settings and close the window: */
2917 modest_ui_actions_on_close_window (NULL, MODEST_WINDOW (edit_window));
2924 modest_ui_actions_on_toggle_bold (GtkToggleAction *action,
2925 ModestMsgEditWindow *window)
2927 ModestMsgEditFormatState *format_state = NULL;
2929 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2930 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
2932 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2935 format_state = modest_msg_edit_window_get_format_state (window);
2936 g_return_if_fail (format_state != NULL);
2938 format_state->bold = gtk_toggle_action_get_active (action);
2939 modest_msg_edit_window_set_format_state (window, format_state);
2940 g_free (format_state);
2945 modest_ui_actions_on_toggle_italics (GtkToggleAction *action,
2946 ModestMsgEditWindow *window)
2948 ModestMsgEditFormatState *format_state = NULL;
2950 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2951 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
2953 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2956 format_state = modest_msg_edit_window_get_format_state (window);
2957 g_return_if_fail (format_state != NULL);
2959 format_state->italics = gtk_toggle_action_get_active (action);
2960 modest_msg_edit_window_set_format_state (window, format_state);
2961 g_free (format_state);
2966 modest_ui_actions_on_toggle_bullets (GtkToggleAction *action,
2967 ModestMsgEditWindow *window)
2969 ModestMsgEditFormatState *format_state = NULL;
2971 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2972 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
2974 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2977 format_state = modest_msg_edit_window_get_format_state (window);
2978 g_return_if_fail (format_state != NULL);
2980 format_state->bullet = gtk_toggle_action_get_active (action);
2981 modest_msg_edit_window_set_format_state (window, format_state);
2982 g_free (format_state);
2987 modest_ui_actions_on_change_justify (GtkRadioAction *action,
2988 GtkRadioAction *selected,
2989 ModestMsgEditWindow *window)
2991 ModestMsgEditFormatState *format_state = NULL;
2992 GtkJustification value;
2994 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2996 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2999 value = gtk_radio_action_get_current_value (selected);
3001 format_state = modest_msg_edit_window_get_format_state (window);
3002 g_return_if_fail (format_state != NULL);
3004 format_state->justification = value;
3005 modest_msg_edit_window_set_format_state (window, format_state);
3006 g_free (format_state);
3010 modest_ui_actions_on_select_editor_color (GtkAction *action,
3011 ModestMsgEditWindow *window)
3013 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3014 g_return_if_fail (GTK_IS_ACTION (action));
3016 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3019 modest_msg_edit_window_select_color (window);
3023 modest_ui_actions_on_select_editor_background_color (GtkAction *action,
3024 ModestMsgEditWindow *window)
3026 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3027 g_return_if_fail (GTK_IS_ACTION (action));
3029 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3032 modest_msg_edit_window_select_background_color (window);
3036 modest_ui_actions_on_insert_image (GtkAction *action,
3037 ModestMsgEditWindow *window)
3039 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3040 g_return_if_fail (GTK_IS_ACTION (action));
3043 if (modest_platform_check_memory_low (MODEST_WINDOW(window), TRUE))
3046 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3049 modest_msg_edit_window_insert_image (window);
3053 modest_ui_actions_on_attach_file (GtkAction *action,
3054 ModestMsgEditWindow *window)
3056 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3057 g_return_if_fail (GTK_IS_ACTION (action));
3059 if (modest_platform_check_memory_low (MODEST_WINDOW(window), TRUE))
3062 modest_msg_edit_window_offer_attach_file (window);
3066 modest_ui_actions_on_remove_attachments (GtkAction *action,
3067 ModestMsgEditWindow *window)
3069 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3070 g_return_if_fail (GTK_IS_ACTION (action));
3072 modest_msg_edit_window_remove_attachments (window, NULL);
3076 #ifndef MODEST_TOOLKIT_GTK
3081 TnyFolderStore *folder;
3082 } CreateFolderHelper;
3085 show_create_folder_in_timeout (gpointer data)
3087 CreateFolderHelper *helper = (CreateFolderHelper *) data;
3089 /* Remove the timeout ASAP, we can not wait until the dialog
3090 is shown because it could take a lot of time and so the
3091 timeout could be called twice or more times */
3092 g_source_remove (helper->handler);
3094 gdk_threads_enter ();
3095 do_create_folder (helper->win, helper->folder, helper->name);
3096 gdk_threads_leave ();
3098 g_object_unref (helper->win);
3099 g_object_unref (helper->folder);
3100 g_free (helper->name);
3101 g_slice_free (CreateFolderHelper, helper);
3108 do_create_folder_cb (ModestMailOperation *mail_op,
3109 TnyFolderStore *parent_folder,
3110 TnyFolder *new_folder,
3113 gchar *suggested_name = (gchar *) user_data;
3114 GtkWindow *source_win = (GtkWindow *) modest_mail_operation_get_source (mail_op);
3116 if (modest_mail_operation_get_error (mail_op)) {
3118 /* Show an error. If there was some problem writing to
3119 disk, show it, otherwise show the generic folder
3120 create error. We do it here and not in an error
3121 handler because the call to do_create_folder will
3122 stop the main loop in a gtk_dialog_run and then,
3123 the message won't be shown until that dialog is
3125 modest_ui_actions_disk_operations_error_handler (mail_op,
3126 _("mail_in_ui_folder_create_error"));
3128 /* Try again. Do *NOT* show any error because the mail
3129 operations system will do it for us because we
3130 created the mail_op with new_with_error_handler */
3131 #ifndef MODEST_TOOLKIT_GTK
3132 CreateFolderHelper *helper;
3133 helper = g_slice_new0 (CreateFolderHelper);
3134 helper->name = g_strdup (suggested_name);
3135 helper->folder = g_object_ref (parent_folder);
3136 helper->win = g_object_ref (source_win);
3138 /* Ugly but neccesary stuff. The problem is that the
3139 dialog when is shown calls a function that destroys
3140 all the temporary windows, so the banner is
3142 helper->handler = g_timeout_add (2000, show_create_folder_in_timeout, helper);
3144 do_create_folder (source_win, parent_folder, (const gchar *) suggested_name);
3147 /* the 'source_win' is either the ModestMainWindow, or the 'Move to folder'-dialog
3148 * FIXME: any other? */
3149 GtkWidget *folder_view;
3151 if (MODEST_IS_MAIN_WINDOW(source_win))
3153 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (source_win),
3154 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3157 get_folder_view_from_move_to_dialog (GTK_WIDGET(source_win));
3159 /* Select the newly created folder. It could happen
3160 that the widget is no longer there (i.e. the window
3161 has been destroyed, so we need to check this */
3163 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view),
3165 g_object_unref (new_folder);
3167 /* Free. Note that the first time it'll be NULL so noop */
3168 g_free (suggested_name);
3169 g_object_unref (source_win);
3173 do_create_folder (GtkWindow *parent_window,
3174 TnyFolderStore *parent_folder,
3175 const gchar *suggested_name)
3178 gchar *folder_name = NULL;
3180 result = modest_platform_run_new_folder_dialog (GTK_WINDOW (parent_window),
3182 (gchar *) suggested_name,
3185 if (result == GTK_RESPONSE_ACCEPT) {
3186 ModestMailOperation *mail_op;
3188 mail_op = modest_mail_operation_new ((GObject *) parent_window);
3189 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
3191 modest_mail_operation_create_folder (mail_op,
3193 (const gchar *) folder_name,
3194 do_create_folder_cb,
3196 g_object_unref (mail_op);
3201 create_folder_performer (gboolean canceled,
3203 GtkWindow *parent_window,
3204 TnyAccount *account,
3207 TnyFolderStore *parent_folder = TNY_FOLDER_STORE (user_data);
3209 if (canceled || err) {
3210 /* In memory full conditions we could get this error here */
3211 check_memory_full_error ((GtkWidget *) parent_window, err);
3215 /* Run the new folder dialog */
3216 do_create_folder (GTK_WINDOW (parent_window), parent_folder, NULL);
3219 g_object_unref (parent_folder);
3223 modest_ui_actions_create_folder(GtkWidget *parent_window,
3224 GtkWidget *folder_view)
3226 TnyFolderStore *parent_folder;
3228 parent_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
3230 if (parent_folder) {
3231 /* The parent folder will be freed in the callback */
3232 modest_platform_connect_if_remote_and_perform (GTK_WINDOW (parent_window),
3235 create_folder_performer,
3241 modest_ui_actions_on_new_folder (GtkAction *action, ModestMainWindow *main_window)
3243 GtkWidget *folder_view;
3245 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
3247 folder_view = modest_main_window_get_child_widget (main_window,
3248 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3252 modest_ui_actions_create_folder (GTK_WIDGET (main_window), folder_view);
3256 modest_ui_actions_rename_folder_error_handler (ModestMailOperation *mail_op,
3259 const GError *error = NULL;
3260 const gchar *message = NULL;
3262 /* Get error message */
3263 error = modest_mail_operation_get_error (mail_op);
3265 g_return_if_reached ();
3267 if (error->domain == MODEST_MAIL_OPERATION_ERROR &&
3268 error->code == MODEST_MAIL_OPERATION_ERROR_FOLDER_EXISTS) {
3269 message = _CS("ckdg_ib_folder_already_exists");
3270 } else if (error->domain == TNY_ERROR_DOMAIN &&
3271 error->code == TNY_SERVICE_ERROR_STATE) {
3272 /* This means that the folder is already in use (a
3273 message is opened for example */
3274 message = _("emev_ni_internal_error");
3276 message = _("emev_ib_ui_imap_unable_to_rename");
3279 /* We don't set a parent for the dialog because the dialog
3280 will be destroyed so the banner won't appear */
3281 modest_platform_information_banner (NULL, NULL, message);
3285 TnyFolderStore *folder;
3290 on_rename_folder_cb (ModestMailOperation *mail_op,
3291 TnyFolder *new_folder,
3294 ModestFolderView *folder_view;
3296 /* If the window was closed when renaming a folder this could
3298 if (!MODEST_IS_FOLDER_VIEW (user_data))
3301 folder_view = MODEST_FOLDER_VIEW (user_data);
3302 /* Note that if the rename fails new_folder will be NULL */
3304 modest_folder_view_select_folder (folder_view, new_folder, FALSE);
3306 modest_folder_view_select_first_inbox_or_local (folder_view);
3308 gtk_widget_grab_focus (GTK_WIDGET (folder_view));
3312 on_rename_folder_performer (gboolean canceled,
3314 GtkWindow *parent_window,
3315 TnyAccount *account,
3318 ModestMailOperation *mail_op = NULL;
3319 GtkTreeSelection *sel = NULL;
3320 GtkWidget *folder_view = NULL;
3321 RenameFolderInfo *data = (RenameFolderInfo*)user_data;
3323 if (canceled || err) {
3324 /* In memory full conditions we could get this error here */
3325 check_memory_full_error ((GtkWidget *) parent_window, err);
3326 } else if (MODEST_IS_MAIN_WINDOW(parent_window)) {
3328 folder_view = modest_main_window_get_child_widget (
3329 MODEST_MAIN_WINDOW (parent_window),
3330 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3333 modest_mail_operation_new_with_error_handling (G_OBJECT(parent_window),
3334 modest_ui_actions_rename_folder_error_handler,
3335 parent_window, NULL);
3337 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
3340 /* Clear the headers view */
3341 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_view));
3342 gtk_tree_selection_unselect_all (sel);
3344 /* Actually rename the folder */
3345 modest_mail_operation_rename_folder (mail_op,
3346 TNY_FOLDER (data->folder),
3347 (const gchar *) (data->new_name),
3348 on_rename_folder_cb,
3350 g_object_unref (data->folder);
3351 g_object_unref (mail_op);
3354 g_free (data->new_name);
3359 modest_ui_actions_on_rename_folder (GtkAction *action,
3360 ModestMainWindow *main_window)
3362 TnyFolderStore *folder;
3363 GtkWidget *folder_view;
3364 GtkWidget *header_view;
3366 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
3368 folder_view = modest_main_window_get_child_widget (main_window,
3369 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3373 header_view = modest_main_window_get_child_widget (main_window,
3374 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
3379 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
3384 if (TNY_IS_FOLDER (folder)) {
3387 const gchar *current_name;
3388 TnyFolderStore *parent;
3389 gboolean do_rename = TRUE;
3391 current_name = tny_folder_get_name (TNY_FOLDER (folder));
3392 parent = tny_folder_get_folder_store (TNY_FOLDER (folder));
3393 response = modest_platform_run_rename_folder_dialog (GTK_WINDOW (main_window),
3394 parent, current_name,
3396 g_object_unref (parent);
3398 if (response != GTK_RESPONSE_ACCEPT || strlen (folder_name) == 0) {
3401 RenameFolderInfo *rename_folder_data = g_new0 (RenameFolderInfo, 1);
3402 rename_folder_data->folder = g_object_ref (folder);
3403 rename_folder_data->new_name = folder_name;
3404 modest_platform_connect_if_remote_and_perform (GTK_WINDOW(main_window), TRUE,
3405 folder, on_rename_folder_performer, rename_folder_data);
3408 g_object_unref (folder);
3412 modest_ui_actions_delete_folder_error_handler (ModestMailOperation *mail_op,
3415 GObject *win = modest_mail_operation_get_source (mail_op);
3417 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
3418 _("mail_in_ui_folder_delete_error"),
3420 g_object_unref (win);
3424 TnyFolderStore *folder;
3425 gboolean move_to_trash;
3429 on_delete_folder_cb (gboolean canceled,
3431 GtkWindow *parent_window,
3432 TnyAccount *account,
3435 DeleteFolderInfo *info = (DeleteFolderInfo*) user_data;
3436 GtkWidget *folder_view;
3437 ModestMailOperation *mail_op;
3438 GtkTreeSelection *sel;
3440 if (!MODEST_IS_MAIN_WINDOW(parent_window) || canceled || (err!=NULL)) {
3441 g_object_unref (G_OBJECT (info->folder));
3446 folder_view = modest_main_window_get_child_widget (
3447 MODEST_MAIN_WINDOW (parent_window),
3448 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3450 /* Unselect the folder before deleting it to free the headers */
3451 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_view));
3452 gtk_tree_selection_unselect_all (sel);
3454 /* Create the mail operation */
3456 modest_mail_operation_new_with_error_handling (G_OBJECT(parent_window),
3457 modest_ui_actions_delete_folder_error_handler,
3460 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
3462 modest_mail_operation_remove_folder (mail_op, TNY_FOLDER (info->folder), info->move_to_trash);
3464 modest_folder_view_select_first_inbox_or_local (MODEST_FOLDER_VIEW (folder_view));
3466 g_object_unref (G_OBJECT (mail_op));
3467 g_object_unref (G_OBJECT (info->folder));
3472 delete_folder (ModestMainWindow *main_window, gboolean move_to_trash)
3474 TnyFolderStore *folder;
3475 GtkWidget *folder_view;
3479 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
3481 folder_view = modest_main_window_get_child_widget (main_window,
3482 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3486 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
3488 /* Show an error if it's an account */
3489 if (!TNY_IS_FOLDER (folder)) {
3490 modest_platform_run_information_dialog (GTK_WINDOW (main_window),
3491 _("mail_in_ui_folder_delete_error"),
3493 g_object_unref (G_OBJECT (folder));
3498 message = g_strdup_printf (_("mcen_nc_delete_folder_text"),
3499 tny_folder_get_name (TNY_FOLDER (folder)));
3500 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (main_window),
3501 (const gchar *) message);
3504 if (response == GTK_RESPONSE_OK) {
3505 DeleteFolderInfo *info;
3506 info = g_new0(DeleteFolderInfo, 1);
3507 info->folder = folder;
3508 info->move_to_trash = move_to_trash;
3509 g_object_ref (G_OBJECT (info->folder));
3510 TnyAccount *account = tny_folder_get_account (TNY_FOLDER (folder));
3511 modest_platform_connect_if_remote_and_perform (GTK_WINDOW (main_window),
3513 TNY_FOLDER_STORE (account),
3514 on_delete_folder_cb, info);
3515 g_object_unref (account);
3517 g_object_unref (G_OBJECT (folder));
3521 modest_ui_actions_on_delete_folder (GtkAction *action,
3522 ModestMainWindow *main_window)
3524 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
3526 delete_folder (main_window, FALSE);
3530 modest_ui_actions_on_move_folder_to_trash_folder (GtkAction *action, ModestMainWindow *main_window)
3532 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
3534 delete_folder (main_window, TRUE);
3538 typedef struct _PasswordDialogFields {
3539 GtkWidget *username;
3540 GtkWidget *password;
3542 } PasswordDialogFields;
3545 password_dialog_check_field (GtkEditable *editable,
3546 PasswordDialogFields *fields)
3549 gboolean any_value_empty = FALSE;
3551 value = gtk_entry_get_text (GTK_ENTRY (fields->username));
3552 if ((value == NULL) || value[0] == '\0') {
3553 any_value_empty = TRUE;
3555 value = gtk_entry_get_text (GTK_ENTRY (fields->password));
3556 if ((value == NULL) || value[0] == '\0') {
3557 any_value_empty = TRUE;
3559 gtk_dialog_set_response_sensitive (GTK_DIALOG (fields->dialog), GTK_RESPONSE_ACCEPT, !any_value_empty);
3563 modest_ui_actions_on_password_requested (TnyAccountStore *account_store,
3564 const gchar* server_account_name,
3569 ModestMainWindow *main_window)
3571 g_return_if_fail(server_account_name);
3572 gboolean completed = FALSE;
3573 PasswordDialogFields *fields = NULL;
3575 /* Initalize output parameters: */
3582 #ifndef MODEST_TOOLKIT_GTK
3583 /* Maemo uses a different (awkward) button order,
3584 * It should probably just use gtk_alternative_dialog_button_order ().
3586 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
3589 _("mcen_bd_dialog_ok"),
3590 GTK_RESPONSE_ACCEPT,
3591 _("mcen_bd_dialog_cancel"),
3592 GTK_RESPONSE_REJECT,
3595 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
3599 GTK_RESPONSE_REJECT,
3601 GTK_RESPONSE_ACCEPT,
3603 #endif /* !MODEST_TOOLKIT_GTK */
3605 modest_window_mgr_set_modal (modest_runtime_get_window_mgr(), GTK_WINDOW (dialog), NULL);
3607 gchar *server_name = modest_account_mgr_get_server_account_hostname (
3608 modest_runtime_get_account_mgr(), server_account_name);
3609 if (!server_name) {/* This happened once, though I don't know why. murrayc. */
3610 g_warning("%s: Could not get server name for server account '%s'", __FUNCTION__, server_account_name);
3616 /* This causes a warning because the logical ID has no %s in it,
3617 * though the translation does, but there is not much we can do about that: */
3618 gchar *txt = g_strdup_printf (_("mail_ia_password_info"), server_name);
3619 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), gtk_label_new(txt),
3622 g_free (server_name);
3626 gchar *initial_username = modest_account_mgr_get_server_account_username (
3627 modest_runtime_get_account_mgr(), server_account_name);
3629 GtkWidget *entry_username = gtk_entry_new ();
3630 if (initial_username)
3631 gtk_entry_set_text (GTK_ENTRY (entry_username), initial_username);
3632 /* Dim this if a connection has ever succeeded with this username,
3633 * as per the UI spec: */
3634 /* const gboolean username_known = */
3635 /* modest_account_mgr_get_server_account_username_has_succeeded( */
3636 /* modest_runtime_get_account_mgr(), server_account_name); */
3637 /* gtk_widget_set_sensitive (entry_username, !username_known); */
3639 /* We drop the username sensitive code and disallow changing it here
3640 * as tinymail does not support really changing the username in the callback
3642 gtk_widget_set_sensitive (entry_username, FALSE);
3644 #ifndef MODEST_TOOLKIT_GTK
3645 /* Auto-capitalization is the default, so let's turn it off: */
3646 hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_username), HILDON_GTK_INPUT_MODE_FULL);
3648 /* Create a size group to be used by all captions.
3649 * Note that HildonCaption does not create a default size group if we do not specify one.
3650 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
3651 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
3653 GtkWidget *caption = hildon_caption_new (sizegroup,
3654 _("mail_fi_username"), entry_username, NULL, HILDON_CAPTION_MANDATORY);
3655 gtk_widget_show (entry_username);
3656 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
3657 FALSE, FALSE, MODEST_MARGIN_HALF);
3658 gtk_widget_show (caption);
3660 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry_username,
3662 #endif /* !MODEST_TOOLKIT_GTK */
3665 GtkWidget *entry_password = gtk_entry_new ();
3666 gtk_entry_set_visibility (GTK_ENTRY(entry_password), FALSE);
3667 /* gtk_entry_set_invisible_char (GTK_ENTRY(entry_password), "*"); */
3669 #ifndef MODEST_TOOLKIT_GTK
3670 /* Auto-capitalization is the default, so let's turn it off: */
3671 hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_password),
3672 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
3674 caption = hildon_caption_new (sizegroup,
3675 _("mail_fi_password"), entry_password, NULL, HILDON_CAPTION_MANDATORY);
3676 gtk_widget_show (entry_password);
3677 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
3678 FALSE, FALSE, MODEST_MARGIN_HALF);
3679 gtk_widget_show (caption);
3680 g_object_unref (sizegroup);
3682 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry_password,
3684 #endif /* !MODEST_TOOLKIT_GTK */
3686 if (initial_username != NULL)
3687 gtk_widget_grab_focus (GTK_WIDGET (entry_password));
3689 /* This is not in the Maemo UI spec:
3690 remember_pass_check = gtk_check_button_new_with_label (_("Remember password"));
3691 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), remember_pass_check,
3695 fields = g_slice_new0 (PasswordDialogFields);
3696 fields->username = entry_username;
3697 fields->password = entry_password;
3698 fields->dialog = dialog;
3700 g_signal_connect (entry_username, "changed", G_CALLBACK (password_dialog_check_field), fields);
3701 g_signal_connect (entry_password, "changed", G_CALLBACK (password_dialog_check_field), fields);
3702 password_dialog_check_field (NULL, fields);
3704 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
3706 while (!completed) {
3708 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
3710 *username = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_username)));
3712 /* Note that an empty field becomes the "" string */
3713 if (*username && strlen (*username) > 0) {
3714 modest_account_mgr_set_server_account_username (modest_runtime_get_account_mgr(),
3715 server_account_name,
3719 const gboolean username_was_changed =
3720 (strcmp (*username, initial_username) != 0);
3721 if (username_was_changed) {
3722 g_warning ("%s: tinymail does not yet support changing the "
3723 "username in the get_password() callback.\n", __FUNCTION__);
3727 modest_platform_information_banner (GTK_WIDGET (dialog), NULL,
3728 _("mcen_ib_username_pw_incorrect"));
3734 *password = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_password)));
3736 /* We do not save the password in the configuration,
3737 * because this function is only called for passwords that should
3738 * not be remembered:
3739 modest_server_account_set_password (
3740 modest_runtime_get_account_mgr(), server_account_name,
3747 /* Set parent to NULL or the banner will disappear with its parent dialog */
3748 modest_platform_information_banner(NULL, NULL, _("mail_ib_login_cancelled"));
3759 /* This is not in the Maemo UI spec:
3760 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (remember_pass_check)))
3766 gtk_widget_destroy (dialog);
3767 g_slice_free (PasswordDialogFields, fields);
3769 /* printf ("DEBUG: %s: cancel=%d\n", __FUNCTION__, *cancel); */
3773 modest_ui_actions_on_cut (GtkAction *action,
3774 ModestWindow *window)
3776 GtkWidget *focused_widget;
3777 GtkClipboard *clipboard;
3779 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
3780 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
3781 if (GTK_IS_EDITABLE (focused_widget)) {
3782 gtk_editable_cut_clipboard (GTK_EDITABLE(focused_widget));
3783 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3784 gtk_clipboard_store (clipboard);
3785 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
3786 GtkTextBuffer *buffer;
3788 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
3789 if (modest_text_utils_buffer_selection_is_valid (buffer)) {
3790 gtk_text_buffer_cut_clipboard (buffer, clipboard, TRUE);
3791 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3792 gtk_clipboard_store (clipboard);
3794 } else if (MODEST_IS_HEADER_VIEW (focused_widget)) {
3795 TnyList *header_list = modest_header_view_get_selected_headers (
3796 MODEST_HEADER_VIEW (focused_widget));
3797 gboolean continue_download = FALSE;
3798 gint num_of_unc_msgs;
3800 num_of_unc_msgs = header_list_count_uncached_msgs(header_list);
3802 if (num_of_unc_msgs) {
3803 TnyAccount *account = get_account_from_header_list (header_list);
3805 continue_download = connect_to_get_msg (window, num_of_unc_msgs, account);
3806 g_object_unref (account);
3810 if (num_of_unc_msgs == 0 || continue_download) {
3811 /* modest_platform_information_banner (
3812 NULL, NULL, _CS("mcen_ib_getting_items"));*/
3813 modest_header_view_cut_selection (
3814 MODEST_HEADER_VIEW (focused_widget));
3817 g_object_unref (header_list);
3818 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
3819 modest_folder_view_cut_selection (MODEST_FOLDER_VIEW (focused_widget));
3824 modest_ui_actions_on_copy (GtkAction *action,
3825 ModestWindow *window)
3827 GtkClipboard *clipboard;
3828 GtkWidget *focused_widget;
3829 gboolean copied = TRUE;
3831 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
3832 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
3834 if (GTK_IS_LABEL (focused_widget)) {
3836 selection = modest_text_utils_label_get_selection (GTK_LABEL (focused_widget));
3837 gtk_clipboard_set_text (clipboard, selection, -1);
3839 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3840 gtk_clipboard_store (clipboard);
3841 } else if (GTK_IS_EDITABLE (focused_widget)) {
3842 gtk_editable_copy_clipboard (GTK_EDITABLE(focused_widget));
3843 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3844 gtk_clipboard_store (clipboard);
3845 } else if (GTK_IS_HTML (focused_widget)) {
3848 sel = gtk_html_get_selection_html (GTK_HTML (focused_widget), &len);
3849 if ((sel == NULL) || (sel[0] == '\0')) {
3852 gtk_html_copy (GTK_HTML (focused_widget));
3853 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3854 gtk_clipboard_store (clipboard);
3856 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
3857 GtkTextBuffer *buffer;
3858 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
3859 if (modest_text_utils_buffer_selection_is_valid (buffer)) {
3860 gtk_text_buffer_copy_clipboard (buffer, clipboard);
3861 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3862 gtk_clipboard_store (clipboard);
3864 } else if (MODEST_IS_HEADER_VIEW (focused_widget)) {
3865 TnyList *header_list = modest_header_view_get_selected_headers (
3866 MODEST_HEADER_VIEW (focused_widget));
3867 gboolean continue_download = FALSE;
3868 gint num_of_unc_msgs;
3870 num_of_unc_msgs = header_list_count_uncached_msgs(header_list);
3872 if (num_of_unc_msgs) {
3873 TnyAccount *account = get_account_from_header_list (header_list);
3875 continue_download = connect_to_get_msg (window, num_of_unc_msgs, account);
3876 g_object_unref (account);
3880 if (num_of_unc_msgs == 0 || continue_download) {
3881 modest_platform_information_banner (
3882 NULL, NULL, _CS("mcen_ib_getting_items"));
3883 modest_header_view_copy_selection (
3884 MODEST_HEADER_VIEW (focused_widget));
3888 g_object_unref (header_list);
3890 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
3891 modest_folder_view_copy_selection (MODEST_FOLDER_VIEW (focused_widget));
3894 /* Show information banner if there was a copy to clipboard */
3896 modest_platform_information_banner (
3897 NULL, NULL, _CS("ecoc_ib_edwin_copied"));
3901 modest_ui_actions_on_undo (GtkAction *action,
3902 ModestWindow *window)
3904 ModestEmailClipboard *clipboard = NULL;
3906 if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
3907 modest_msg_edit_window_undo (MODEST_MSG_EDIT_WINDOW (window));
3908 } else if (MODEST_IS_MAIN_WINDOW (window)) {
3909 /* Clear clipboard source */
3910 clipboard = modest_runtime_get_email_clipboard ();
3911 modest_email_clipboard_clear (clipboard);
3914 g_return_if_reached ();
3919 modest_ui_actions_on_redo (GtkAction *action,
3920 ModestWindow *window)
3922 if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
3923 modest_msg_edit_window_redo (MODEST_MSG_EDIT_WINDOW (window));
3926 g_return_if_reached ();
3932 destroy_information_note (ModestMailOperation *mail_op,
3935 /* destroy information note */
3936 gtk_widget_destroy (GTK_WIDGET(user_data));
3940 destroy_folder_information_note (ModestMailOperation *mail_op,
3941 TnyFolder *new_folder,
3944 /* destroy information note */
3945 gtk_widget_destroy (GTK_WIDGET(user_data));
3950 paste_as_attachment_free (gpointer data)
3952 PasteAsAttachmentHelper *helper = (PasteAsAttachmentHelper *) data;
3954 if (helper->banner) {
3955 gtk_widget_destroy (helper->banner);
3956 g_object_unref (helper->banner);
3962 paste_msg_as_attachment_cb (ModestMailOperation *mail_op,
3967 PasteAsAttachmentHelper *helper = (PasteAsAttachmentHelper *) userdata;
3968 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (helper->window));
3973 modest_msg_edit_window_add_part (MODEST_MSG_EDIT_WINDOW (helper->window), TNY_MIME_PART (msg));
3978 modest_ui_actions_on_paste (GtkAction *action,
3979 ModestWindow *window)
3981 GtkWidget *focused_widget = NULL;
3982 GtkWidget *inf_note = NULL;
3983 ModestMailOperation *mail_op = NULL;
3985 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
3986 if (GTK_IS_EDITABLE (focused_widget)) {
3987 gtk_editable_paste_clipboard (GTK_EDITABLE(focused_widget));
3988 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
3989 ModestEmailClipboard *e_clipboard = NULL;
3990 e_clipboard = modest_runtime_get_email_clipboard ();
3991 if (modest_email_clipboard_cleared (e_clipboard)) {
3992 GtkTextBuffer *buffer;
3993 GtkClipboard *clipboard;
3995 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
3996 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
3997 gtk_text_buffer_paste_clipboard (buffer, clipboard, NULL, TRUE);
3998 } else if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
3999 ModestMailOperation *mail_op;
4000 TnyFolder *src_folder;
4003 PasteAsAttachmentHelper *helper = g_new0 (PasteAsAttachmentHelper, 1);
4004 helper->window = MODEST_MSG_EDIT_WINDOW (window);
4005 helper->banner = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
4006 _CS("ckct_nw_pasting"));
4007 modest_email_clipboard_get_data (e_clipboard, &src_folder, &data, &delete);
4008 mail_op = modest_mail_operation_new (G_OBJECT (window));
4009 if (helper->banner != NULL) {
4010 g_object_ref (G_OBJECT (helper->banner));
4011 gtk_widget_show (GTK_WIDGET (helper->banner));
4015 modest_mail_operation_get_msgs_full (mail_op,
4017 (GetMsgAsyncUserCallback) paste_msg_as_attachment_cb,
4019 paste_as_attachment_free);
4022 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
4023 ModestEmailClipboard *clipboard = NULL;
4024 TnyFolder *src_folder = NULL;
4025 TnyFolderStore *folder_store = NULL;
4026 TnyList *data = NULL;
4027 gboolean delete = FALSE;
4029 /* Check clipboard source */
4030 clipboard = modest_runtime_get_email_clipboard ();
4031 if (modest_email_clipboard_cleared (clipboard))
4034 /* Get elements to paste */
4035 modest_email_clipboard_get_data (clipboard, &src_folder, &data, &delete);
4037 /* Create a new mail operation */
4038 mail_op = modest_mail_operation_new (G_OBJECT(window));
4040 /* Get destination folder */
4041 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (focused_widget));
4043 /* transfer messages */
4047 /* Ask for user confirmation */
4049 modest_ui_actions_msgs_move_to_confirmation (window,
4050 TNY_FOLDER (folder_store),
4054 if (response == GTK_RESPONSE_OK) {
4055 /* Launch notification */
4056 inf_note = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
4057 _CS("ckct_nw_pasting"));
4058 if (inf_note != NULL) {
4059 gtk_window_set_modal (GTK_WINDOW(inf_note), FALSE);
4060 gtk_widget_show (GTK_WIDGET(inf_note));
4063 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
4064 modest_mail_operation_xfer_msgs (mail_op,
4066 TNY_FOLDER (folder_store),
4068 destroy_information_note,
4071 g_object_unref (mail_op);
4074 } else if (src_folder != NULL) {
4075 /* Launch notification */
4076 inf_note = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
4077 _CS("ckct_nw_pasting"));
4078 if (inf_note != NULL) {
4079 gtk_window_set_modal (GTK_WINDOW(inf_note), FALSE);
4080 gtk_widget_show (GTK_WIDGET(inf_note));
4083 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
4084 modest_mail_operation_xfer_folder (mail_op,
4088 destroy_folder_information_note,
4094 g_object_unref (data);
4095 if (src_folder != NULL)
4096 g_object_unref (src_folder);
4097 if (folder_store != NULL)
4098 g_object_unref (folder_store);
4104 modest_ui_actions_on_select_all (GtkAction *action,
4105 ModestWindow *window)
4107 GtkWidget *focused_widget;
4109 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
4110 if (MODEST_IS_ATTACHMENTS_VIEW (focused_widget)) {
4111 modest_attachments_view_select_all (MODEST_ATTACHMENTS_VIEW (focused_widget));
4112 } else if (GTK_IS_LABEL (focused_widget)) {
4113 gtk_label_select_region (GTK_LABEL (focused_widget), 0, -1);
4114 } else if (GTK_IS_EDITABLE (focused_widget)) {
4115 gtk_editable_select_region (GTK_EDITABLE(focused_widget), 0, -1);
4116 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
4117 GtkTextBuffer *buffer;
4118 GtkTextIter start, end;
4120 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
4121 gtk_text_buffer_get_start_iter (buffer, &start);
4122 gtk_text_buffer_get_end_iter (buffer, &end);
4123 gtk_text_buffer_select_range (buffer, &start, &end);
4124 } else if (GTK_IS_HTML (focused_widget)) {
4125 gtk_html_select_all (GTK_HTML (focused_widget));
4126 } else if (MODEST_IS_MAIN_WINDOW (window)) {
4127 GtkWidget *header_view = focused_widget;
4128 GtkTreeSelection *selection = NULL;
4130 if (!(MODEST_IS_HEADER_VIEW (focused_widget))) {
4131 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (window),
4132 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
4135 /* Disable window dimming management */
4136 modest_window_disable_dimming (MODEST_WINDOW(window));
4138 /* Select all messages */
4139 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(header_view));
4140 gtk_tree_selection_select_all (selection);
4142 /* Set focuse on header view */
4143 gtk_widget_grab_focus (header_view);
4145 /* Enable window dimming management */
4146 modest_window_enable_dimming (MODEST_WINDOW(window));
4147 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (window));
4148 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (window));
4154 modest_ui_actions_on_mark_as_read (GtkAction *action,
4155 ModestWindow *window)
4157 g_return_if_fail (MODEST_IS_WINDOW(window));
4159 /* Mark each header as read */
4160 do_headers_action (window, headers_action_mark_as_read, NULL);
4164 modest_ui_actions_on_mark_as_unread (GtkAction *action,
4165 ModestWindow *window)
4167 g_return_if_fail (MODEST_IS_WINDOW(window));
4169 /* Mark each header as read */
4170 do_headers_action (window, headers_action_mark_as_unread, NULL);
4174 modest_ui_actions_on_change_zoom (GtkRadioAction *action,
4175 GtkRadioAction *selected,
4176 ModestWindow *window)
4180 value = gtk_radio_action_get_current_value (selected);
4181 if (MODEST_IS_WINDOW (window)) {
4182 modest_window_set_zoom (MODEST_WINDOW (window), ((gdouble)value)/100);
4187 modest_ui_actions_msg_edit_on_change_priority (GtkRadioAction *action,
4188 GtkRadioAction *selected,
4189 ModestWindow *window)
4191 TnyHeaderFlags flags;
4192 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4194 flags = gtk_radio_action_get_current_value (selected);
4195 modest_msg_edit_window_set_priority_flags (MODEST_MSG_EDIT_WINDOW (window), flags);
4199 modest_ui_actions_msg_edit_on_change_file_format (GtkRadioAction *action,
4200 GtkRadioAction *selected,
4201 ModestWindow *window)
4205 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4207 file_format = gtk_radio_action_get_current_value (selected);
4208 modest_msg_edit_window_set_file_format (MODEST_MSG_EDIT_WINDOW (window), file_format);
4213 modest_ui_actions_on_zoom_plus (GtkAction *action,
4214 ModestWindow *window)
4216 g_return_if_fail (MODEST_IS_WINDOW (window));
4218 modest_window_zoom_plus (MODEST_WINDOW (window));
4222 modest_ui_actions_on_zoom_minus (GtkAction *action,
4223 ModestWindow *window)
4225 g_return_if_fail (MODEST_IS_WINDOW (window));
4227 modest_window_zoom_minus (MODEST_WINDOW (window));
4231 modest_ui_actions_on_toggle_fullscreen (GtkToggleAction *toggle,
4232 ModestWindow *window)
4234 ModestWindowMgr *mgr;
4235 gboolean fullscreen, active;
4236 g_return_if_fail (MODEST_IS_WINDOW (window));
4238 mgr = modest_runtime_get_window_mgr ();
4240 active = (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle)))?1:0;
4241 fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
4243 if (active != fullscreen) {
4244 modest_window_mgr_set_fullscreen_mode (mgr, active);
4245 #ifndef MODEST_TOOLKIT_HILDON2
4246 gtk_window_present (GTK_WINDOW (window));
4252 modest_ui_actions_on_change_fullscreen (GtkAction *action,
4253 ModestWindow *window)
4255 ModestWindowMgr *mgr;
4256 gboolean fullscreen;
4258 g_return_if_fail (MODEST_IS_WINDOW (window));
4260 mgr = modest_runtime_get_window_mgr ();
4261 fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
4262 modest_window_mgr_set_fullscreen_mode (mgr, !fullscreen);
4264 #ifndef MODEST_TOOLKIT_HILDON2
4265 gtk_window_present (GTK_WINDOW (window));
4270 * Used by modest_ui_actions_on_details to call do_headers_action
4273 headers_action_show_details (TnyHeader *header,
4274 ModestWindow *window,
4281 dialog = modest_details_dialog_new_with_header (GTK_WINDOW (window), header);
4284 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (dialog), (GtkWindow *) window);
4285 gtk_widget_show_all (dialog);
4287 g_signal_connect_swapped (dialog, "response",
4288 G_CALLBACK (gtk_widget_destroy),
4293 * Show the folder details in a ModestDetailsDialog widget
4296 show_folder_details (TnyFolder *folder,
4302 dialog = modest_details_dialog_new_with_folder (window, folder);
4305 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
4306 gtk_widget_show_all (dialog);
4307 gtk_dialog_run (GTK_DIALOG (dialog));
4309 gtk_widget_destroy (dialog);
4313 * Show the header details in a ModestDetailsDialog widget
4316 modest_ui_actions_on_details (GtkAction *action,
4319 TnyList * headers_list;
4323 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
4326 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW (win));
4329 g_object_unref (msg);
4331 headers_list = get_selected_headers (win);
4335 iter = tny_list_create_iterator (headers_list);
4337 header = TNY_HEADER (tny_iterator_get_current (iter));
4339 headers_action_show_details (header, win, NULL);
4340 g_object_unref (header);
4343 g_object_unref (iter);
4344 g_object_unref (headers_list);
4346 } else if (MODEST_IS_MAIN_WINDOW (win)) {
4347 GtkWidget *folder_view, *header_view;
4349 /* Check which widget has the focus */
4350 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
4351 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
4352 if (gtk_widget_is_focus (folder_view)) {
4353 TnyFolderStore *folder_store
4354 = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
4355 if (!folder_store) {
4356 g_warning ("%s: No item was selected.\n", __FUNCTION__);
4359 /* Show only when it's a folder */
4360 /* This function should not be called for account items,
4361 * because we dim the menu item for them. */
4362 if (TNY_IS_FOLDER (folder_store)) {
4363 show_folder_details (TNY_FOLDER (folder_store), GTK_WINDOW (win));
4366 g_object_unref (folder_store);
4369 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
4370 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
4371 /* Show details of each header */
4372 do_headers_action (win, headers_action_show_details, header_view);
4378 modest_ui_actions_on_toggle_show_cc (GtkToggleAction *toggle,
4379 ModestMsgEditWindow *window)
4381 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4383 modest_msg_edit_window_show_cc (window, gtk_toggle_action_get_active (toggle));
4387 modest_ui_actions_on_toggle_show_bcc (GtkToggleAction *toggle,
4388 ModestMsgEditWindow *window)
4390 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4392 modest_msg_edit_window_show_bcc (window, gtk_toggle_action_get_active (toggle));
4396 modest_ui_actions_toggle_folders_view (GtkAction *action,
4397 ModestMainWindow *main_window)
4399 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
4401 if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)))
4402 modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SPLIT);
4404 modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SIMPLE);
4408 modest_ui_actions_on_toggle_toolbar (GtkToggleAction *toggle,
4409 ModestWindow *window)
4411 gboolean active, fullscreen = FALSE;
4412 ModestWindowMgr *mgr;
4414 active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle));
4416 /* Check if we want to toggle the toolbar vuew in fullscreen
4418 if (!strcmp (gtk_action_get_name (GTK_ACTION (toggle)),
4419 "ViewShowToolbarFullScreen")) {
4423 /* Toggle toolbar */
4424 mgr = modest_runtime_get_window_mgr ();
4425 modest_window_mgr_show_toolbars (mgr, G_TYPE_FROM_INSTANCE (window), active, fullscreen);
4429 modest_ui_actions_msg_edit_on_select_font (GtkAction *action,
4430 ModestMsgEditWindow *window)
4432 modest_msg_edit_window_select_font (window);
4437 modest_ui_actions_on_folder_display_name_changed (ModestFolderView *folder_view,
4438 const gchar *display_name,
4441 /* don't update the display name if it was already set;
4442 * updating the display name apparently is expensive */
4443 const gchar* old_name = gtk_window_get_title (window);
4445 if (display_name == NULL)
4448 if (old_name && display_name && strcmp (old_name, display_name) == 0)
4449 return; /* don't do anything */
4451 /* This is usually used to change the title of the main window, which
4452 * is the one that holds the folder view. Note that this change can
4453 * happen even when the widget doesn't have the focus. */
4454 gtk_window_set_title (window, display_name);
4459 modest_ui_actions_on_select_contacts (GtkAction *action, ModestMsgEditWindow *window)
4461 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4462 modest_msg_edit_window_select_contacts (window);
4466 modest_ui_actions_on_check_names (GtkAction *action, ModestMsgEditWindow *window)
4468 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4469 modest_msg_edit_window_check_names (window, FALSE);
4473 create_move_to_dialog_on_new_folder(GtkWidget *button, gpointer user_data)
4475 modest_ui_actions_create_folder (gtk_widget_get_toplevel (button),
4476 GTK_WIDGET (user_data));
4480 * This function is used to track changes in the selection of the
4481 * folder view that is inside the "move to" dialog to enable/disable
4482 * the OK button because we do not want the user to select a disallowed
4483 * destination for a folder.
4484 * The user also not desired to be able to use NEW button on items where
4485 * folder creation is not possibel.
4488 on_move_to_dialog_folder_selection_changed (ModestFolderView* self,
4489 TnyFolderStore *folder_store,
4493 GtkWidget *dialog = NULL;
4494 GtkWidget *ok_button = NULL, *new_button = NULL;
4495 gboolean ok_sensitive = TRUE, new_sensitive = TRUE;
4496 gboolean moving_folder = FALSE;
4497 gboolean is_local_account = TRUE;
4498 GtkWidget *folder_view = NULL;
4499 ModestTnyFolderRules rules;
4501 g_return_if_fail (MODEST_IS_FOLDER_VIEW(self));
4506 /* Get the OK button */
4507 dialog = gtk_widget_get_ancestor (GTK_WIDGET (self), GTK_TYPE_DIALOG);
4511 ok_button = g_object_get_data (G_OBJECT (dialog), MOVE_FOLDER_OK_BUTTON);
4512 new_button = g_object_get_data (G_OBJECT (dialog), MOVE_FOLDER_NEW_BUTTON);
4514 /* check if folder_store is an remote account */
4515 if (TNY_IS_ACCOUNT (folder_store)) {
4516 TnyAccount *local_account = NULL;
4517 TnyAccount *mmc_account = NULL;
4518 ModestTnyAccountStore *account_store = NULL;
4520 account_store = modest_runtime_get_account_store ();
4521 local_account = modest_tny_account_store_get_local_folders_account (account_store);
4522 mmc_account = modest_tny_account_store_get_mmc_folders_account (account_store);
4524 if ((gpointer) local_account != (gpointer) folder_store &&
4525 (gpointer) mmc_account != (gpointer) folder_store) {
4526 ModestProtocolType proto;
4527 proto = modest_tny_account_get_protocol_type (TNY_ACCOUNT (folder_store));
4528 if (proto == MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
4529 proto = MODEST_PROTOCOLS_STORE_MAILDIR;
4531 is_local_account = FALSE;
4532 /* New button should be dimmed on remote
4534 new_sensitive = (modest_protocol_registry_protocol_type_has_tag (modest_runtime_get_protocol_registry (),
4536 MODEST_PROTOCOL_REGISTRY_STORE_HAS_FOLDERS));
4538 g_object_unref (local_account);
4539 g_object_unref (mmc_account);
4542 /* Check the target folder rules */
4543 if (TNY_IS_FOLDER (folder_store)) {
4544 rules = modest_tny_folder_get_rules (TNY_FOLDER (folder_store));
4545 if (rules & MODEST_FOLDER_RULES_FOLDER_NON_WRITEABLE) {
4546 ok_sensitive = FALSE;
4547 new_sensitive = FALSE;
4552 /* Check if we're moving a folder */
4553 if (MODEST_IS_MAIN_WINDOW (user_data)) {
4554 /* Get the widgets */
4555 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (user_data),
4556 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
4557 if (gtk_widget_is_focus (folder_view))
4558 moving_folder = TRUE;
4561 if (moving_folder) {
4562 TnyFolderStore *moved_folder = NULL, *parent = NULL;
4564 /* Get the folder to move */
4565 moved_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
4567 /* Check that we're not moving to the same folder */
4568 if (TNY_IS_FOLDER (moved_folder)) {
4569 parent = tny_folder_get_folder_store (TNY_FOLDER (moved_folder));
4570 if (parent == folder_store)
4571 ok_sensitive = FALSE;
4572 g_object_unref (parent);
4575 if (ok_sensitive && TNY_IS_ACCOUNT (folder_store)) {
4576 /* Do not allow to move to an account unless it's the
4577 local folders account */
4578 if (!is_local_account)
4579 ok_sensitive = FALSE;
4582 if (ok_sensitive && (moved_folder == folder_store)) {
4583 /* Do not allow to move to itself */
4584 ok_sensitive = FALSE;
4586 g_object_unref (moved_folder);
4588 TnyFolder *src_folder = NULL;
4590 /* Moving a message */
4591 if (MODEST_IS_MSG_VIEW_WINDOW (user_data)) {
4593 TnyHeader *header = NULL;
4594 header = modest_msg_view_window_get_header
4595 (MODEST_MSG_VIEW_WINDOW (user_data));
4596 if (!TNY_IS_HEADER(header))
4597 g_warning ("%s: could not get source header", __FUNCTION__);
4599 src_folder = tny_header_get_folder (header);
4602 g_object_unref (header);
4605 TNY_FOLDER (modest_folder_view_get_selected
4606 (MODEST_FOLDER_VIEW (folder_view)));
4609 if (TNY_IS_FOLDER(src_folder)) {
4610 /* Do not allow to move the msg to the same folder */
4611 /* Do not allow to move the msg to an account */
4612 if ((gpointer) src_folder == (gpointer) folder_store ||
4613 TNY_IS_ACCOUNT (folder_store))
4614 ok_sensitive = FALSE;
4615 g_object_unref (src_folder);
4617 g_warning ("%s: could not get source folder", __FUNCTION__);
4621 /* Set sensitivity of the OK button */
4622 gtk_widget_set_sensitive (ok_button, ok_sensitive);
4623 /* Set sensitivity of the NEW button */
4624 gtk_widget_set_sensitive (new_button, new_sensitive);
4628 #define MODEST_MOVE_TO_DIALOG_FOLDER_VIEW "move-to-dialog-folder-view"
4631 get_folder_view_from_move_to_dialog (GtkWidget *move_to_dialog)
4633 return GTK_WIDGET(g_object_get_data (G_OBJECT(move_to_dialog),
4634 MODEST_MOVE_TO_DIALOG_FOLDER_VIEW));
4638 create_move_to_dialog (GtkWindow *win,
4639 GtkWidget *folder_view,
4640 GtkWidget **tree_view)
4642 GtkWidget *dialog, *scroll;
4643 GtkWidget *new_button, *ok_button;
4645 dialog = gtk_dialog_new_with_buttons (_("mcen_ti_moveto_folders_title"),
4647 GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR | GTK_DIALOG_DESTROY_WITH_PARENT,
4650 #ifndef MODEST_TOOLKIT_GTK
4651 ok_button = gtk_dialog_add_button (GTK_DIALOG (dialog), _("mcen_bd_dialog_ok"), GTK_RESPONSE_ACCEPT);
4652 /* We do this manually so GTK+ does not associate a response ID for
4654 new_button = gtk_button_new_from_stock (_("mcen_bd_new"));
4655 gtk_box_pack_end (GTK_BOX (GTK_DIALOG (dialog)->action_area), new_button, FALSE, FALSE, 0);
4656 gtk_widget_show (new_button);
4657 #ifndef MODEST_TOOLKIT_HILDON2
4658 gtk_dialog_add_button (GTK_DIALOG (dialog), _("mcen_bd_dialog_cancel"), GTK_RESPONSE_REJECT);
4661 /* We do this manually so GTK+ does not associate a response ID for
4663 new_button = gtk_button_new_with_label (_("mcen_ti_new_folder"));
4664 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area), new_button, FALSE, FALSE, 0);
4665 gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (GTK_DIALOG (dialog)->action_area), new_button, TRUE);
4666 gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT);
4667 ok_button = gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_OK, GTK_RESPONSE_ACCEPT);
4668 gtk_container_set_border_width (GTK_CONTAINER (dialog), 12);
4669 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 24);
4671 g_object_set_data (G_OBJECT (dialog), MOVE_FOLDER_OK_BUTTON, ok_button);
4672 g_object_set_data (G_OBJECT (dialog), MOVE_FOLDER_NEW_BUTTON, new_button);
4674 /* Create scrolled window */
4675 scroll = gtk_scrolled_window_new (NULL, NULL);
4676 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll),
4677 GTK_POLICY_AUTOMATIC,
4678 GTK_POLICY_AUTOMATIC);
4680 #ifdef MODEST_TOOLKIT_GTK
4681 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scroll), GTK_SHADOW_IN);
4684 /* Create folder view */
4685 *tree_view = modest_platform_create_folder_view (NULL);
4687 /* Track changes in the selection to
4688 * disable the OK button whenever "Move to" is not possible
4689 * disbale NEW button whenever New is not possible */
4690 g_signal_connect (*tree_view,
4691 "folder_selection_changed",
4692 G_CALLBACK (on_move_to_dialog_folder_selection_changed),
4695 /* Listen to clicks on New button */
4696 g_signal_connect (G_OBJECT (new_button),
4698 G_CALLBACK(create_move_to_dialog_on_new_folder),
4701 /* It could happen that we're trying to move a message from a
4702 window (msg window for example) after the main window was
4703 closed, so we can not just get the model of the folder
4705 if (MODEST_IS_FOLDER_VIEW (folder_view)) {
4706 const gchar *visible_id = NULL;
4708 modest_folder_view_set_style (MODEST_FOLDER_VIEW (*tree_view),
4709 MODEST_FOLDER_VIEW_STYLE_SHOW_ALL);
4710 modest_folder_view_copy_model (MODEST_FOLDER_VIEW(folder_view),
4711 MODEST_FOLDER_VIEW(*tree_view));
4714 modest_folder_view_get_account_id_of_visible_server_account (MODEST_FOLDER_VIEW(folder_view));
4716 /* Show the same account than the one that is shown in the main window */
4717 modest_folder_view_set_account_id_of_visible_server_account (MODEST_FOLDER_VIEW(*tree_view),
4720 const gchar *active_account_name = NULL;
4721 ModestAccountMgr *mgr = NULL;
4722 ModestAccountSettings *settings = NULL;
4723 ModestServerAccountSettings *store_settings = NULL;
4725 modest_folder_view_set_style (MODEST_FOLDER_VIEW (*tree_view),
4726 MODEST_FOLDER_VIEW_STYLE_SHOW_ALL);
4727 modest_folder_view_update_model (MODEST_FOLDER_VIEW (*tree_view),
4728 TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()));
4730 active_account_name = modest_window_get_active_account (MODEST_WINDOW (win));
4731 mgr = modest_runtime_get_account_mgr ();
4732 settings = modest_account_mgr_load_account_settings (mgr, active_account_name);
4735 const gchar *store_account_name;
4736 store_settings = modest_account_settings_get_store_settings (settings);
4737 store_account_name = modest_server_account_settings_get_account_name (store_settings);
4739 modest_folder_view_set_account_id_of_visible_server_account (MODEST_FOLDER_VIEW (*tree_view),
4740 store_account_name);
4741 g_object_unref (store_settings);
4742 g_object_unref (settings);
4746 /* we keep a pointer to the embedded folder view, so we can retrieve it with
4747 * get_folder_view_from_move_to_dialog
4748 * (see above) later (needed for focus handling)
4750 g_object_set_data (G_OBJECT(dialog), MODEST_MOVE_TO_DIALOG_FOLDER_VIEW, *tree_view);
4753 /* Hide special folders */
4754 modest_folder_view_show_non_move_folders (MODEST_FOLDER_VIEW (*tree_view), FALSE);
4756 gtk_container_add (GTK_CONTAINER (scroll), *tree_view);
4758 /* Add scroll to dialog */
4759 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
4760 scroll, TRUE, TRUE, 0);
4762 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
4763 #ifndef MODEST_TOOLKIT_GTK
4764 gtk_window_set_default_size (GTK_WINDOW (dialog), 300, 300);
4766 gtk_window_set_default_size (GTK_WINDOW (dialog), 600, 400);
4775 * Shows a confirmation dialog to the user when we're moving messages
4776 * from a remote server to the local storage. Returns the dialog
4777 * response. If it's other kind of movement then it always returns
4780 * This one is used by the next functions:
4781 * modest_ui_actions_on_paste - commented out
4782 * drag_and_drop_from_header_view (for d&d in modest_folder_view.c)
4785 modest_ui_actions_msgs_move_to_confirmation (ModestWindow *win,
4786 TnyFolder *dest_folder,
4790 gint response = GTK_RESPONSE_OK;
4791 TnyAccount *account = NULL;
4792 TnyFolder *src_folder = NULL;
4793 TnyIterator *iter = NULL;
4794 TnyHeader *header = NULL;
4796 /* return with OK if the destination is a remote folder */
4797 if (modest_tny_folder_is_remote_folder (dest_folder))
4798 return GTK_RESPONSE_OK;
4800 /* Get source folder */
4801 iter = tny_list_create_iterator (headers);
4802 header = TNY_HEADER (tny_iterator_get_current (iter));
4804 src_folder = tny_header_get_folder (header);
4805 g_object_unref (header);
4807 g_object_unref (iter);
4809 /* if no src_folder, message may be an attahcment */
4810 if (src_folder == NULL)
4811 return GTK_RESPONSE_CANCEL;
4813 /* If the source is a local or MMC folder */
4814 if (!modest_tny_folder_is_remote_folder (src_folder)) {
4815 g_object_unref (src_folder);
4816 return GTK_RESPONSE_OK;
4819 /* Get the account */
4820 account = tny_folder_get_account (src_folder);
4822 /* now if offline we ask the user */
4823 if(connect_to_get_msg (win, tny_list_get_length (headers), account))
4824 response = GTK_RESPONSE_OK;
4826 response = GTK_RESPONSE_CANCEL;
4829 g_object_unref (src_folder);
4830 g_object_unref (account);
4836 move_to_helper_destroyer (gpointer user_data)
4838 MoveToHelper *helper = (MoveToHelper *) user_data;
4840 /* Close the "Pasting" information banner */
4841 if (helper->banner) {
4842 gtk_widget_destroy (GTK_WIDGET (helper->banner));
4843 g_object_unref (helper->banner);
4845 if (helper->reference != NULL)
4846 gtk_tree_row_reference_free (helper->reference);
4851 move_to_cb (ModestMailOperation *mail_op,
4854 MoveToHelper *helper = (MoveToHelper *) user_data;
4856 /* Note that the operation could have failed, in that case do
4858 if (modest_mail_operation_get_status (mail_op) ==
4859 MODEST_MAIL_OPERATION_STATUS_SUCCESS) {
4861 GObject *object = modest_mail_operation_get_source (mail_op);
4862 if (MODEST_IS_MSG_VIEW_WINDOW (object)) {
4863 ModestMsgViewWindow *self = MODEST_MSG_VIEW_WINDOW (object);
4865 if (!modest_msg_view_window_select_next_message (self) &&
4866 !modest_msg_view_window_select_previous_message (self)) {
4867 /* No more messages to view, so close this window */
4868 modest_ui_actions_on_close_window (NULL, MODEST_WINDOW(self));
4870 } else if (MODEST_IS_MAIN_WINDOW (object) && helper->reference != NULL) {
4871 GtkWidget *header_view;
4873 GtkTreeSelection *sel;
4875 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(object),
4876 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
4877 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
4878 path = gtk_tree_row_reference_get_path (helper->reference);
4879 /* We need to unselect the previous one
4880 because we could be copying instead of
4882 gtk_tree_selection_unselect_all (sel);
4883 gtk_tree_selection_select_path (sel, path);
4884 gtk_tree_path_free (path);
4886 g_object_unref (object);
4888 /* Destroy the helper */
4889 move_to_helper_destroyer (helper);
4893 folder_move_to_cb (ModestMailOperation *mail_op,
4894 TnyFolder *new_folder,
4897 GtkWidget *folder_view;
4900 object = modest_mail_operation_get_source (mail_op);
4901 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(object),
4902 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
4903 g_object_ref (folder_view);
4904 g_object_unref (object);
4905 move_to_cb (mail_op, user_data);
4906 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view), new_folder, FALSE);
4907 g_object_unref (folder_view);
4911 msgs_move_to_cb (ModestMailOperation *mail_op,
4914 move_to_cb (mail_op, user_data);
4918 modest_ui_actions_move_folder_error_handler (ModestMailOperation *mail_op,
4921 ModestWindow *main_window = NULL;
4923 /* Disable next automatic folder selection */
4924 main_window = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (),
4925 FALSE); /* don't create */
4927 GObject *win = NULL;
4928 GtkWidget *folder_view = NULL;
4930 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (main_window),
4931 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
4932 modest_folder_view_disable_next_folder_selection (MODEST_FOLDER_VIEW(folder_view));
4934 if (user_data && TNY_IS_FOLDER (user_data)) {
4935 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view),
4936 TNY_FOLDER (user_data), FALSE);
4939 /* Show notification dialog only if the main window exists */
4940 win = modest_mail_operation_get_source (mail_op);
4941 modest_platform_run_information_dialog ((GtkWindow *) win,
4942 _("mail_in_ui_folder_move_target_error"),
4945 g_object_unref (win);
4950 open_msg_for_purge_cb (ModestMailOperation *mail_op,
4959 gint pending_purges = 0;
4960 gboolean some_purged = FALSE;
4961 ModestWindow *win = MODEST_WINDOW (user_data);
4962 ModestWindowMgr *mgr = modest_runtime_get_window_mgr ();
4964 /* If there was any error */
4965 if (!modest_ui_actions_msg_retrieval_check (mail_op, header, msg)) {
4966 modest_window_mgr_unregister_header (mgr, header);
4970 /* Once the message has been retrieved for purging, we check if
4971 * it's all ok for purging */
4973 parts = tny_simple_list_new ();
4974 tny_mime_part_get_parts (TNY_MIME_PART (msg), parts);
4975 iter = tny_list_create_iterator (parts);
4977 while (!tny_iterator_is_done (iter)) {
4979 part = TNY_MIME_PART (tny_iterator_get_current (iter));
4980 if (part && (tny_mime_part_is_attachment (part) || TNY_IS_MSG (part))) {
4981 if (tny_mime_part_is_purged (part))
4988 g_object_unref (part);
4990 tny_iterator_next (iter);
4992 g_object_unref (iter);
4995 if (pending_purges>0) {
4997 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),_("mcen_nc_purge_file_text_inbox"));
4999 if (response == GTK_RESPONSE_OK) {
5002 modest_platform_animation_banner (GTK_WIDGET (win), NULL, _("mcen_ib_removing_attachment"));
5003 iter = tny_list_create_iterator (parts);
5004 while (!tny_iterator_is_done (iter)) {
5007 part = TNY_MIME_PART (tny_iterator_get_current (iter));
5008 if (part && (tny_mime_part_is_attachment (part) || TNY_IS_MSG (part)))
5009 tny_mime_part_set_purged (part);
5012 g_object_unref (part);
5014 tny_iterator_next (iter);
5016 g_object_unref (iter);
5018 tny_msg_rewrite_cache (msg);
5020 gtk_widget_destroy (info);
5024 modest_window_mgr_unregister_header (mgr, header);
5026 g_object_unref (parts);
5030 modest_ui_actions_on_main_window_remove_attachments (GtkAction *action,
5031 ModestMainWindow *win)
5033 GtkWidget *header_view;
5034 TnyList *header_list;
5036 TnyHeaderFlags flags;
5037 ModestWindow *msg_view_window = NULL;
5040 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win));
5042 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
5043 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
5045 header_list = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW (header_view));
5047 g_warning ("%s: no header selected", __FUNCTION__);
5051 if (tny_list_get_length (header_list) == 1) {
5052 TnyIterator *iter = tny_list_create_iterator (header_list);
5053 header = TNY_HEADER (tny_iterator_get_current (iter));
5054 g_object_unref (iter);
5058 if (!header || !TNY_IS_HEADER(header)) {
5059 g_warning ("%s: header is not valid", __FUNCTION__);
5063 found = modest_window_mgr_find_registered_header (modest_runtime_get_window_mgr (),
5064 header, &msg_view_window);
5065 flags = tny_header_get_flags (header);
5066 if (!(flags & TNY_HEADER_FLAG_CACHED))
5069 if (msg_view_window != NULL)
5070 modest_msg_view_window_remove_attachments (MODEST_MSG_VIEW_WINDOW (msg_view_window), TRUE);
5072 /* do nothing; uid was registered before, so window is probably on it's way */
5073 g_warning ("debug: header %p has already been registered", header);
5076 ModestMailOperation *mail_op = NULL;
5077 modest_window_mgr_register_header (modest_runtime_get_window_mgr (), header, NULL);
5078 mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT (win),
5079 modest_ui_actions_disk_operations_error_handler,
5081 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
5082 modest_mail_operation_get_msg (mail_op, header, FALSE, open_msg_for_purge_cb, win);
5084 g_object_unref (mail_op);
5087 g_object_unref (header);
5089 g_object_unref (header_list);
5093 * Checks if we need a connection to do the transfer and if the user
5094 * wants to connect to complete it
5097 modest_ui_actions_xfer_messages_check (GtkWindow *parent_window,
5098 TnyFolderStore *src_folder,
5100 TnyFolder *dst_folder,
5101 gboolean delete_originals,
5102 gboolean *need_connection,
5105 TnyAccount *src_account;
5106 gint uncached_msgs = 0;
5108 uncached_msgs = header_list_count_uncached_msgs (headers);
5110 /* We don't need any further check if
5112 * 1- the source folder is local OR
5113 * 2- the device is already online
5115 if (!modest_tny_folder_store_is_remote (src_folder) ||
5116 tny_device_is_online (modest_runtime_get_device())) {
5117 *need_connection = FALSE;
5122 /* We must ask for a connection when
5124 * - the message(s) is not already cached OR
5125 * - the message(s) is cached but the leave_on_server setting
5126 * is FALSE (because we need to sync the source folder to
5127 * delete the message from the server (for IMAP we could do it
5128 * offline, it'll take place the next time we get a
5131 src_account = get_account_from_folder_store (src_folder);
5132 if (uncached_msgs > 0) {
5136 *need_connection = TRUE;
5137 num_headers = tny_list_get_length (headers);
5138 msg = ngettext ("mcen_nc_get_msg", "mcen_nc_get_msgs", num_headers);
5140 if (modest_platform_run_confirmation_dialog (parent_window, msg) ==
5141 GTK_RESPONSE_CANCEL) {
5147 /* The transfer is possible and the user wants to */
5150 if (remote_folder_has_leave_on_server (src_folder) && delete_originals) {
5151 const gchar *account_name;
5152 gboolean leave_on_server;
5154 account_name = modest_tny_account_get_parent_modest_account_name_for_server_account (src_account);
5155 leave_on_server = modest_account_mgr_get_leave_on_server (modest_runtime_get_account_mgr (),
5158 if (leave_on_server == TRUE) {
5159 *need_connection = FALSE;
5161 *need_connection = TRUE;
5164 *need_connection = FALSE;
5169 g_object_unref (src_account);
5173 xfer_messages_error_handler (ModestMailOperation *mail_op,
5176 ModestWindow *main_window = NULL;
5178 /* Disable next automatic folder selection */
5179 main_window = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (),
5180 FALSE); /* don't create */
5182 GObject *win = modest_mail_operation_get_source (mail_op);
5183 modest_platform_run_information_dialog ((GtkWindow *) win,
5184 _("mail_in_ui_folder_move_target_error"),
5187 g_object_unref (win);
5189 move_to_helper_destroyer (user_data);
5193 TnyFolderStore *dst_folder;
5198 * Utility function that transfer messages from both the main window
5199 * and the msg view window when using the "Move to" dialog
5202 xfer_messages_performer (gboolean canceled,
5204 GtkWindow *parent_window,
5205 TnyAccount *account,
5208 ModestWindow *win = MODEST_WINDOW (parent_window);
5209 TnyAccount *dst_account = NULL;
5210 gboolean dst_forbids_message_add = FALSE;
5211 XferMsgsHelper *helper;
5212 MoveToHelper *movehelper;
5213 ModestMailOperation *mail_op;
5215 helper = (XferMsgsHelper *) user_data;
5217 if (canceled || err) {
5218 if (!check_memory_full_error ((GtkWidget *) parent_window, err)) {
5219 /* Show the proper error message */
5220 modest_ui_actions_on_account_connection_error (parent_window, account);
5225 dst_account = tny_folder_get_account (TNY_FOLDER (helper->dst_folder));
5227 /* tinymail will return NULL for local folders it seems */
5228 dst_forbids_message_add = modest_protocol_registry_protocol_type_has_tag (modest_runtime_get_protocol_registry (),
5229 modest_tny_account_get_protocol_type (dst_account),
5230 MODEST_PROTOCOL_REGISTRY_STORE_FORBID_MESSAGE_ADD);
5231 g_object_unref (dst_account);
5233 if (dst_forbids_message_add) {
5234 modest_platform_information_banner (GTK_WIDGET (win),
5236 ngettext("mail_in_ui_folder_move_target_error",
5237 "mail_in_ui_folder_move_targets_error",
5238 tny_list_get_length (helper->headers)));
5242 movehelper = g_new0 (MoveToHelper, 1);
5243 movehelper->banner = modest_platform_animation_banner (GTK_WIDGET (win), NULL,
5244 _CS("ckct_nw_pasting"));
5245 if (movehelper->banner != NULL) {
5246 g_object_ref (movehelper->banner);
5247 gtk_widget_show (GTK_WIDGET (movehelper->banner));
5250 if (MODEST_IS_MAIN_WINDOW (win)) {
5251 GtkWidget *header_view =
5252 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
5253 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
5254 movehelper->reference = get_next_after_selected_headers (MODEST_HEADER_VIEW (header_view));
5257 /* Perform the mail operation */
5258 mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT(win),
5259 xfer_messages_error_handler,
5261 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
5264 modest_mail_operation_xfer_msgs (mail_op,
5266 TNY_FOLDER (helper->dst_folder),
5271 g_object_unref (G_OBJECT (mail_op));
5273 g_object_unref (helper->dst_folder);
5274 g_object_unref (helper->headers);
5275 g_slice_free (XferMsgsHelper, helper);
5279 TnyFolder *src_folder;
5280 TnyFolderStore *dst_folder;
5281 gboolean delete_original;
5282 GtkWidget *folder_view;
5286 on_move_folder_cb (gboolean canceled, GError *err, GtkWindow *parent_window,
5287 TnyAccount *account, gpointer user_data)
5289 MoveFolderInfo *info = (MoveFolderInfo*)user_data;
5290 GtkTreeSelection *sel;
5291 ModestMailOperation *mail_op = NULL;
5293 if (canceled || err || !MODEST_IS_MAIN_WINDOW (parent_window)) {
5294 g_object_unref (G_OBJECT (info->src_folder));
5295 g_object_unref (G_OBJECT (info->dst_folder));
5300 MoveToHelper *helper = g_new0 (MoveToHelper, 1);
5301 helper->banner = modest_platform_animation_banner (GTK_WIDGET (parent_window), NULL,
5302 _CS("ckct_nw_pasting"));
5303 if (helper->banner != NULL) {
5304 g_object_ref (helper->banner);
5305 gtk_widget_show (GTK_WIDGET(helper->banner));
5307 /* Clean folder on header view before moving it */
5308 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (info->folder_view));
5309 gtk_tree_selection_unselect_all (sel);
5311 /* Let gtk events run. We need that the folder
5312 view frees its reference to the source
5313 folder *before* issuing the mail operation
5314 so we need the signal handler of selection
5315 changed to happen before the mail
5317 while (gtk_events_pending ())
5318 gtk_main_iteration (); */
5321 modest_mail_operation_new_with_error_handling (G_OBJECT(parent_window),
5322 modest_ui_actions_move_folder_error_handler,
5323 info->src_folder, NULL);
5324 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
5327 /* Select *after* the changes */
5328 /* TODO: this function hangs UI after transfer */
5329 /* modest_folder_view_select_folder (MODEST_FOLDER_VIEW(folder_view), */
5330 /* TNY_FOLDER (src_folder), TRUE); */
5332 modest_folder_view_select_folder (MODEST_FOLDER_VIEW(info->folder_view),
5333 TNY_FOLDER (info->dst_folder), TRUE);
5334 modest_mail_operation_xfer_folder (mail_op,
5335 TNY_FOLDER (info->src_folder),
5337 info->delete_original,
5340 g_object_unref (G_OBJECT (info->src_folder));
5342 /* if (modest_mail_operation_get_status (mail_op) == MODEST_MAIL_OPERATION_STATUS_SUCCESS) { */
5345 /* Unref mail operation */
5346 g_object_unref (G_OBJECT (mail_op));
5347 g_object_unref (G_OBJECT (info->dst_folder));
5352 get_account_from_folder_store (TnyFolderStore *folder_store)
5354 if (TNY_IS_ACCOUNT (folder_store))
5355 return g_object_ref (folder_store);
5357 return tny_folder_get_account (TNY_FOLDER (folder_store));
5361 * UI handler for the "Move to" action when invoked from the
5365 modest_ui_actions_on_main_window_move_to (GtkAction *action,
5366 GtkWidget *folder_view,
5367 TnyFolderStore *dst_folder,
5368 ModestMainWindow *win)
5370 ModestHeaderView *header_view = NULL;
5371 TnyFolderStore *src_folder = NULL;
5373 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win));
5375 /* Get the source folder */
5376 src_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
5378 /* Get header view */
5379 header_view = MODEST_HEADER_VIEW(modest_main_window_get_child_widget (win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW));
5381 /* Get folder or messages to transfer */
5382 if (gtk_widget_is_focus (folder_view)) {
5383 gboolean do_xfer = TRUE;
5385 /* Allow only to transfer folders to the local root folder */
5386 if (TNY_IS_ACCOUNT (dst_folder) &&
5387 !MODEST_IS_TNY_LOCAL_FOLDERS_ACCOUNT (dst_folder) &&
5388 !modest_tny_account_is_memory_card_account (TNY_ACCOUNT (dst_folder))) {
5390 } else if (!TNY_IS_FOLDER (src_folder)) {
5391 g_warning ("%s: src_folder is not a TnyFolder.\n", __FUNCTION__);
5396 MoveFolderInfo *info = g_new0 (MoveFolderInfo, 1);
5397 DoubleConnectionInfo *connect_info = g_slice_new (DoubleConnectionInfo);
5399 info->src_folder = g_object_ref (src_folder);
5400 info->dst_folder = g_object_ref (dst_folder);
5401 info->delete_original = TRUE;
5402 info->folder_view = folder_view;
5404 connect_info->callback = on_move_folder_cb;
5405 connect_info->dst_account = get_account_from_folder_store (TNY_FOLDER_STORE (dst_folder));
5406 connect_info->data = info;
5408 modest_platform_double_connect_and_perform(GTK_WINDOW (win), TRUE,
5409 TNY_FOLDER_STORE (src_folder),
5412 } else if (gtk_widget_is_focus (GTK_WIDGET(header_view))) {
5415 headers = modest_header_view_get_selected_headers(header_view);
5417 /* Transfer the messages */
5418 modest_ui_actions_transfer_messages_helper (GTK_WINDOW (win), TNY_FOLDER (src_folder),
5419 headers, TNY_FOLDER (dst_folder));
5421 g_object_unref (headers);
5425 g_object_unref (src_folder);
5430 modest_ui_actions_transfer_messages_helper (GtkWindow *win,
5431 TnyFolder *src_folder,
5433 TnyFolder *dst_folder)
5435 gboolean need_connection = TRUE;
5436 gboolean do_xfer = TRUE;
5437 XferMsgsHelper *helper;
5439 g_return_if_fail (TNY_IS_FOLDER (src_folder));
5440 g_return_if_fail (TNY_IS_FOLDER (dst_folder));
5441 g_return_if_fail (TNY_IS_LIST (headers));
5443 modest_ui_actions_xfer_messages_check (win, TNY_FOLDER_STORE (src_folder),
5444 headers, TNY_FOLDER (dst_folder),
5445 TRUE, &need_connection,
5448 /* If we don't want to transfer just return */
5452 /* Create the helper */
5453 helper = g_slice_new (XferMsgsHelper);
5454 helper->dst_folder = g_object_ref (dst_folder);
5455 helper->headers = g_object_ref (headers);
5457 if (need_connection) {
5458 DoubleConnectionInfo *connect_info = g_slice_new (DoubleConnectionInfo);
5459 connect_info->callback = xfer_messages_performer;
5460 connect_info->dst_account = tny_folder_get_account (TNY_FOLDER (dst_folder));
5461 connect_info->data = helper;
5463 modest_platform_double_connect_and_perform(GTK_WINDOW (win), TRUE,
5464 TNY_FOLDER_STORE (src_folder),
5467 TnyAccount *src_account = get_account_from_folder_store (TNY_FOLDER_STORE (src_folder));
5468 xfer_messages_performer (FALSE, NULL, GTK_WINDOW (win),
5469 src_account, helper);
5470 g_object_unref (src_account);
5475 * UI handler for the "Move to" action when invoked from the
5476 * ModestMsgViewWindow
5479 modest_ui_actions_on_msg_view_window_move_to (GtkAction *action,
5480 TnyFolderStore *dst_folder,
5481 ModestMsgViewWindow *win)
5483 TnyList *headers = NULL;
5484 TnyHeader *header = NULL;
5485 TnyFolder *src_folder = NULL;
5487 g_return_if_fail (TNY_IS_FOLDER (dst_folder));
5489 /* Create header list */
5490 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
5491 src_folder = TNY_FOLDER (tny_header_get_folder(header));
5492 headers = tny_simple_list_new ();
5493 tny_list_append (headers, G_OBJECT (header));
5495 /* Transfer the messages */
5496 modest_ui_actions_transfer_messages_helper (GTK_WINDOW (win), src_folder, headers,
5497 TNY_FOLDER (dst_folder));
5500 g_object_unref (src_folder);
5501 g_object_unref (header);
5502 g_object_unref (headers);
5506 modest_ui_actions_on_move_to (GtkAction *action,
5509 GtkWidget *dialog = NULL, *folder_view = NULL, *tree_view = NULL;
5511 TnyFolderStore *dst_folder = NULL;
5512 ModestMainWindow *main_window;
5514 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win) ||
5515 MODEST_IS_MSG_VIEW_WINDOW (win));
5517 /* Get the main window if exists */
5518 if (MODEST_IS_MAIN_WINDOW (win))
5519 main_window = MODEST_MAIN_WINDOW (win);
5522 MODEST_MAIN_WINDOW (modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (),
5523 FALSE)); /* don't create */
5525 /* Get the folder view widget if exists */
5527 folder_view = modest_main_window_get_child_widget (main_window,
5528 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
5532 /* Create and run the dialog */
5533 dialog = create_move_to_dialog (GTK_WINDOW (win), folder_view, &tree_view);
5534 modest_folder_view_select_first_inbox_or_local (MODEST_FOLDER_VIEW (tree_view));
5535 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (dialog), (GtkWindow *) win);
5536 result = gtk_dialog_run (GTK_DIALOG(dialog));
5537 g_object_ref (tree_view);
5538 gtk_widget_destroy (dialog);
5540 if (result != GTK_RESPONSE_ACCEPT)
5543 dst_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (tree_view));
5544 /* Do window specific stuff */
5545 if (MODEST_IS_MAIN_WINDOW (win)) {
5546 modest_ui_actions_on_main_window_move_to (action,
5549 MODEST_MAIN_WINDOW (win));
5551 modest_ui_actions_on_msg_view_window_move_to (action,
5553 MODEST_MSG_VIEW_WINDOW (win));
5557 g_object_unref (dst_folder);
5561 * Calls #HeadersFunc for each header already selected in the main
5562 * window or the message currently being shown in the msg view window
5565 do_headers_action (ModestWindow *win,
5569 TnyList *headers_list = NULL;
5570 TnyIterator *iter = NULL;
5571 TnyHeader *header = NULL;
5572 TnyFolder *folder = NULL;
5575 headers_list = get_selected_headers (win);
5579 /* Get the folder */
5580 iter = tny_list_create_iterator (headers_list);
5581 header = TNY_HEADER (tny_iterator_get_current (iter));
5583 folder = tny_header_get_folder (header);
5584 g_object_unref (header);
5587 /* Call the function for each header */
5588 while (!tny_iterator_is_done (iter)) {
5589 header = TNY_HEADER (tny_iterator_get_current (iter));
5590 func (header, win, user_data);
5591 g_object_unref (header);
5592 tny_iterator_next (iter);
5595 /* Trick: do a poke status in order to speed up the signaling
5597 tny_folder_poke_status (folder);
5600 g_object_unref (folder);
5601 g_object_unref (iter);
5602 g_object_unref (headers_list);
5606 modest_ui_actions_view_attachment (GtkAction *action,
5607 ModestWindow *window)
5609 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
5610 modest_msg_view_window_view_attachment (MODEST_MSG_VIEW_WINDOW (window), NULL);
5612 /* not supported window for this action */
5613 g_return_if_reached ();
5618 modest_ui_actions_save_attachments (GtkAction *action,
5619 ModestWindow *window)
5621 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
5623 if (modest_platform_check_memory_low (MODEST_WINDOW(window), TRUE))
5626 modest_msg_view_window_save_attachments (MODEST_MSG_VIEW_WINDOW (window), NULL);
5628 /* not supported window for this action */
5629 g_return_if_reached ();
5634 modest_ui_actions_remove_attachments (GtkAction *action,
5635 ModestWindow *window)
5637 if (MODEST_IS_MAIN_WINDOW (window)) {
5638 modest_ui_actions_on_main_window_remove_attachments (action, MODEST_MAIN_WINDOW (window));
5639 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
5640 modest_msg_view_window_remove_attachments (MODEST_MSG_VIEW_WINDOW (window), FALSE);
5642 /* not supported window for this action */
5643 g_return_if_reached ();
5648 modest_ui_actions_on_settings (GtkAction *action,
5653 dialog = modest_platform_get_global_settings_dialog ();
5654 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (win));
5655 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
5656 gtk_widget_show_all (dialog);
5658 gtk_dialog_run (GTK_DIALOG (dialog));
5660 gtk_widget_destroy (dialog);
5664 modest_ui_actions_on_help (GtkAction *action,
5667 const gchar *help_id;
5669 g_return_if_fail (win && GTK_IS_WINDOW(win));
5671 help_id = modest_window_mgr_get_help_id (modest_runtime_get_window_mgr(), win);
5674 modest_platform_show_help (GTK_WINDOW (win), help_id);
5678 modest_ui_actions_on_csm_help (GtkAction *action,
5681 const gchar* help_id = NULL;
5682 GtkWidget *folder_view;
5683 TnyFolderStore *folder_store;
5685 g_return_if_fail (win && MODEST_IS_MAIN_WINDOW (win));
5687 /* Get selected folder */
5688 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
5689 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
5690 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
5692 /* Switch help_id */
5693 if (folder_store && TNY_IS_FOLDER (folder_store))
5694 help_id = modest_tny_folder_get_help_id (TNY_FOLDER (folder_store));
5697 g_object_unref (folder_store);
5700 modest_platform_show_help (GTK_WINDOW (win), help_id);
5702 modest_ui_actions_on_help (action, win);
5706 retrieve_contents_cb (ModestMailOperation *mail_op,
5713 /* We only need this callback to show an error in case of
5714 memory low condition */
5715 modest_ui_actions_msg_retrieval_check (mail_op, header, msg);
5719 retrieve_msg_contents_performer (gboolean canceled,
5721 GtkWindow *parent_window,
5722 TnyAccount *account,
5725 ModestMailOperation *mail_op;
5726 TnyList *headers = TNY_LIST (user_data);
5728 if (err || canceled) {
5729 check_memory_full_error ((GtkWidget *) parent_window, err);
5733 /* Create mail operation */
5734 mail_op = modest_mail_operation_new_with_error_handling ((GObject *) parent_window,
5735 modest_ui_actions_disk_operations_error_handler,
5737 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
5738 modest_mail_operation_get_msgs_full (mail_op, headers, retrieve_contents_cb, NULL, NULL);
5741 g_object_unref (mail_op);
5743 g_object_unref (headers);
5744 g_object_unref (account);
5748 modest_ui_actions_on_retrieve_msg_contents (GtkAction *action,
5749 ModestWindow *window)
5751 TnyList *headers = NULL;
5752 TnyAccount *account = NULL;
5753 TnyIterator *iter = NULL;
5754 TnyHeader *header = NULL;
5755 TnyFolder *folder = NULL;
5758 headers = get_selected_headers (window);
5762 /* Pick the account */
5763 iter = tny_list_create_iterator (headers);
5764 header = TNY_HEADER (tny_iterator_get_current (iter));
5765 folder = tny_header_get_folder (header);
5766 account = tny_folder_get_account (folder);
5767 g_object_unref (folder);
5768 g_object_unref (header);
5769 g_object_unref (iter);
5771 /* Connect and perform the message retrieval */
5772 modest_platform_connect_and_perform ((GtkWindow *) window, TRUE,
5773 g_object_ref (account),
5774 retrieve_msg_contents_performer,
5775 g_object_ref (headers));
5778 g_object_unref (account);
5779 g_object_unref (headers);
5783 modest_ui_actions_check_toolbar_dimming_rules (ModestWindow *window)
5785 g_return_if_fail (MODEST_IS_WINDOW (window));
5788 modest_window_check_dimming_rules_group (window, MODEST_DIMMING_RULES_TOOLBAR);
5792 modest_ui_actions_check_menu_dimming_rules (ModestWindow *window)
5794 g_return_if_fail (MODEST_IS_WINDOW (window));
5797 modest_window_check_dimming_rules_group (window, MODEST_DIMMING_RULES_MENU);
5801 modest_ui_actions_on_email_menu_activated (GtkAction *action,
5802 ModestWindow *window)
5804 g_return_if_fail (MODEST_IS_WINDOW (window));
5807 modest_ui_actions_check_menu_dimming_rules (window);
5811 modest_ui_actions_on_edit_menu_activated (GtkAction *action,
5812 ModestWindow *window)
5814 g_return_if_fail (MODEST_IS_WINDOW (window));
5817 modest_ui_actions_check_menu_dimming_rules (window);
5821 modest_ui_actions_on_view_menu_activated (GtkAction *action,
5822 ModestWindow *window)
5824 g_return_if_fail (MODEST_IS_WINDOW (window));
5827 modest_ui_actions_check_menu_dimming_rules (window);
5831 modest_ui_actions_on_format_menu_activated (GtkAction *action,
5832 ModestWindow *window)
5834 g_return_if_fail (MODEST_IS_WINDOW (window));
5837 modest_ui_actions_check_menu_dimming_rules (window);
5841 modest_ui_actions_on_tools_menu_activated (GtkAction *action,
5842 ModestWindow *window)
5844 g_return_if_fail (MODEST_IS_WINDOW (window));
5847 modest_ui_actions_check_menu_dimming_rules (window);
5851 modest_ui_actions_on_attachment_menu_activated (GtkAction *action,
5852 ModestWindow *window)
5854 g_return_if_fail (MODEST_IS_WINDOW (window));
5857 modest_ui_actions_check_menu_dimming_rules (window);
5861 modest_ui_actions_on_toolbar_csm_menu_activated (GtkAction *action,
5862 ModestWindow *window)
5864 g_return_if_fail (MODEST_IS_WINDOW (window));
5867 modest_ui_actions_check_menu_dimming_rules (window);
5871 modest_ui_actions_on_folder_view_csm_menu_activated (GtkAction *action,
5872 ModestWindow *window)
5874 g_return_if_fail (MODEST_IS_WINDOW (window));
5877 modest_ui_actions_check_menu_dimming_rules (window);
5881 modest_ui_actions_on_header_view_csm_menu_activated (GtkAction *action,
5882 ModestWindow *window)
5884 g_return_if_fail (MODEST_IS_WINDOW (window));
5887 modest_ui_actions_check_menu_dimming_rules (window);
5891 modest_ui_actions_on_search_messages (GtkAction *action, ModestWindow *window)
5893 g_return_if_fail (MODEST_IS_WINDOW (window));
5895 /* we check for low-mem; in that case, show a warning, and don't allow
5898 if (modest_platform_check_memory_low (window, TRUE))
5901 modest_platform_show_search_messages (GTK_WINDOW (window));
5905 modest_ui_actions_on_open_addressbook (GtkAction *action, ModestWindow *win)
5907 g_return_if_fail (MODEST_IS_WINDOW (win));
5910 /* we check for low-mem; in that case, show a warning, and don't allow
5911 * for the addressbook
5913 if (modest_platform_check_memory_low (win, TRUE))
5917 modest_platform_show_addressbook (GTK_WINDOW (win));
5922 modest_ui_actions_on_toggle_find_in_page (GtkToggleAction *action,
5923 ModestWindow *window)
5925 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
5927 modest_msg_edit_window_toggle_find_toolbar (MODEST_MSG_EDIT_WINDOW (window), gtk_toggle_action_get_active (action));
5931 on_send_receive_finished (ModestMailOperation *mail_op,
5934 GtkWidget *header_view, *folder_view;
5935 TnyFolderStore *folder_store;
5936 ModestMainWindow *main_win = MODEST_MAIN_WINDOW (user_data);
5938 /* Set send/receive operation finished */
5939 modest_main_window_notify_send_receive_completed (main_win);
5941 /* Don't refresh the current folder if there were any errors */
5942 if (modest_mail_operation_get_status (mail_op) !=
5943 MODEST_MAIL_OPERATION_STATUS_SUCCESS)
5946 /* Refresh the current folder if we're viewing a window. We do
5947 this because the user won't be able to see the new mails in
5948 the selected folder after a Send&Receive because it only
5949 performs a poke_status, i.e, only the number of read/unread
5950 messages is updated, but the new headers are not
5952 folder_view = modest_main_window_get_child_widget (main_win,
5953 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
5957 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
5959 /* Do not need to refresh INBOX again because the
5960 update_account does it always automatically */
5961 if (folder_store && TNY_IS_FOLDER (folder_store) &&
5962 tny_folder_get_folder_type (TNY_FOLDER (folder_store)) != TNY_FOLDER_TYPE_INBOX) {
5963 ModestMailOperation *refresh_op;
5965 header_view = modest_main_window_get_child_widget (main_win,
5966 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
5968 /* We do not need to set the contents style
5969 because it hasn't changed. We also do not
5970 need to save the widget status. Just force
5972 refresh_op = modest_mail_operation_new (G_OBJECT (main_win));
5973 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), refresh_op);
5974 modest_mail_operation_refresh_folder (refresh_op, TNY_FOLDER (folder_store),
5975 folder_refreshed_cb, main_win);
5976 g_object_unref (refresh_op);
5980 g_object_unref (folder_store);
5985 modest_ui_actions_on_send_queue_error_happened (TnySendQueue *self,
5991 const gchar* server_name = NULL;
5992 TnyTransportAccount *server_account;
5993 gchar *message = NULL;
5995 /* Don't show anything if the user cancelled something or the
5996 * send receive request is not interactive. Authentication
5997 * errors are managed by the account store so no need to show
5998 * a dialog here again */
5999 if (err->code == TNY_SYSTEM_ERROR_CANCEL ||
6000 err->code == TNY_SERVICE_ERROR_AUTHENTICATE ||
6001 !modest_tny_send_queue_get_requested_send_receive (MODEST_TNY_SEND_QUEUE (self)))
6005 /* Get the server name: */
6007 TNY_TRANSPORT_ACCOUNT (tny_camel_send_queue_get_transport_account (TNY_CAMEL_SEND_QUEUE (self)));
6009 server_name = tny_account_get_hostname (TNY_ACCOUNT (server_account));
6011 g_return_if_reached ();
6013 /* Show the appropriate message text for the GError: */
6014 switch (err->code) {
6015 case TNY_SERVICE_ERROR_CONNECT:
6016 message = g_strdup_printf (_("emev_ib_ui_smtp_server_invalid"), server_name);
6018 case TNY_SERVICE_ERROR_SEND:
6019 message = g_strdup (dgettext("hildon-common-strings", "sfil_ib_unable_to_send"));
6021 case TNY_SERVICE_ERROR_UNAVAILABLE:
6022 message = g_strdup_printf (_("emev_ib_ui_smtp_server_invalid"), server_name);
6025 g_warning ("%s: unexpected ERROR %d",
6026 __FUNCTION__, err->code);
6027 message = g_strdup (dgettext("hildon-common-strings", "sfil_ib_unable_to_send"));
6031 modest_platform_run_information_dialog (NULL, message, FALSE);
6033 g_object_unref (server_account);
6037 modest_ui_actions_on_send_queue_status_changed (ModestTnySendQueue *send_queue,
6042 ModestMainWindow *main_window = NULL;
6043 ModestWindowMgr *mgr = NULL;
6044 GtkWidget *folder_view = NULL, *header_view = NULL;
6045 TnyFolderStore *selected_folder = NULL;
6046 TnyFolderType folder_type;
6048 mgr = modest_runtime_get_window_mgr ();
6049 main_window = MODEST_MAIN_WINDOW (modest_window_mgr_get_main_window (mgr,
6050 FALSE));/* don't create */
6054 /* Check if selected folder is OUTBOX */
6055 folder_view = modest_main_window_get_child_widget (main_window,
6056 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
6057 header_view = modest_main_window_get_child_widget (main_window,
6058 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
6060 selected_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
6061 if (!TNY_IS_FOLDER (selected_folder))
6064 /* gtk_tree_view_column_queue_resize is only available in GTK+ 2.8 */
6065 #if GTK_CHECK_VERSION(2, 8, 0)
6066 folder_type = modest_tny_folder_guess_folder_type (TNY_FOLDER (selected_folder));
6067 if (folder_type == TNY_FOLDER_TYPE_OUTBOX) {
6068 GtkTreeViewColumn *tree_column;
6070 tree_column = gtk_tree_view_get_column (GTK_TREE_VIEW (header_view),
6071 TNY_GTK_HEADER_LIST_MODEL_FROM_COLUMN);
6073 gtk_tree_view_column_queue_resize (tree_column);
6076 gtk_widget_queue_draw (header_view);
6079 /* Rerun dimming rules, because the message could become deletable for example */
6080 modest_window_check_dimming_rules_group (MODEST_WINDOW (main_window),
6081 MODEST_DIMMING_RULES_TOOLBAR);
6082 modest_window_check_dimming_rules_group (MODEST_WINDOW (main_window),
6083 MODEST_DIMMING_RULES_MENU);
6087 if (selected_folder != NULL)
6088 g_object_unref (selected_folder);
6092 modest_ui_actions_on_account_connection_error (GtkWindow *parent_window,
6093 TnyAccount *account)
6095 ModestProtocolType protocol_type;
6096 ModestProtocol *protocol;
6097 gchar *error_note = NULL;
6099 protocol_type = modest_tny_account_get_protocol_type (account);
6100 protocol = modest_protocol_registry_get_protocol_by_type (modest_runtime_get_protocol_registry (),
6103 error_note = modest_protocol_get_translation (protocol, MODEST_PROTOCOL_TRANSLATION_ACCOUNT_CONNECTION_ERROR, tny_account_get_hostname (account));
6104 if (error_note == NULL) {
6105 g_warning ("%s: This should not be reached", __FUNCTION__);
6107 modest_platform_run_information_dialog (parent_window, error_note, FALSE);
6108 g_free (error_note);
6113 modest_ui_actions_get_msg_already_deleted_error_msg (ModestWindow *win)
6117 TnyFolderStore *folder = NULL;
6118 TnyAccount *account = NULL;
6119 ModestProtocolType proto;
6120 ModestProtocol *protocol;
6121 TnyHeader *header = NULL;
6123 if (MODEST_IS_MAIN_WINDOW (win)) {
6124 GtkWidget *header_view;
6125 TnyList* headers = NULL;
6127 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
6128 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
6129 headers = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW (header_view));
6130 if (!headers || tny_list_get_length (headers) == 0) {
6132 g_object_unref (headers);
6135 iter = tny_list_create_iterator (headers);
6136 header = TNY_HEADER (tny_iterator_get_current (iter));
6137 folder = TNY_FOLDER_STORE (tny_header_get_folder (header));
6138 g_object_unref (iter);
6139 g_object_unref (headers);
6140 } else if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
6141 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
6142 folder = TNY_FOLDER_STORE (tny_header_get_folder (header));
6145 /* Get the account type */
6146 account = tny_folder_get_account (TNY_FOLDER (folder));
6147 proto = modest_tny_account_get_protocol_type (account);
6148 protocol = modest_protocol_registry_get_protocol_by_type (modest_runtime_get_protocol_registry (),
6151 subject = tny_header_dup_subject (header);
6152 msg = modest_protocol_get_translation (protocol, MODEST_PROTOCOL_TRANSLATION_MSG_NOT_AVAILABLE, subject);
6155 msg = g_strdup_printf (_("mail_ni_ui_folder_get_msg_folder_error"));
6159 g_object_unref (account);
6160 g_object_unref (folder);
6161 g_object_unref (header);