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-defs.h>
39 #include <modest-tny-folder.h>
40 #include <modest-tny-msg.h>
41 #include <modest-tny-account.h>
42 #include <modest-address-book.h>
43 #include "modest-error.h"
44 #include "modest-ui-actions.h"
45 #include "modest-tny-platform-factory.h"
46 #include "modest-platform.h"
47 #include "modest-debug.h"
48 #include <tny-mime-part.h>
49 #include <tny-error.h>
50 #include <tny-camel-folder.h>
51 #include <tny-camel-imap-folder.h>
52 #include <tny-camel-pop-folder.h>
53 #include <widgets/modest-header-window.h>
54 #include <widgets/modest-folder-window.h>
55 #ifdef MODEST_TOOLKIT_HILDON2
56 #include <modest-accounts-window.h>
57 #include <hildon/hildon-gtk.h>
58 #include <modest-maemo-utils.h>
60 #include "modest-utils.h"
61 #include "widgets/modest-connection-specific-smtp-window.h"
62 #include "widgets/modest-ui-constants.h"
63 #include <widgets/modest-main-window.h>
64 #include <widgets/modest-msg-view-window.h>
65 #include <widgets/modest-account-view-window.h>
66 #include <widgets/modest-details-dialog.h>
67 #include <widgets/modest-attachments-view.h>
68 #include "widgets/modest-folder-view.h"
69 #include "widgets/modest-global-settings-dialog.h"
70 #include "modest-account-mgr-helpers.h"
71 #include "modest-mail-operation.h"
72 #include "modest-text-utils.h"
73 #include <modest-widget-memory.h>
74 #include <tny-error.h>
75 #include <tny-simple-list.h>
76 #include <tny-msg-view.h>
77 #include <tny-device.h>
78 #include <tny-merge-folder.h>
79 #include <widgets/modest-toolkit-utils.h>
81 #include <gtkhtml/gtkhtml.h>
83 #define MODEST_MOVE_TO_DIALOG_FOLDER_VIEW "move-to-dialog-folder-view"
85 typedef struct _GetMsgAsyncHelper {
87 ModestMailOperation *mail_op;
94 typedef enum _ReplyForwardAction {
100 typedef struct _ReplyForwardHelper {
101 guint reply_forward_type;
102 ReplyForwardAction action;
105 GtkWidget *parent_window;
107 } ReplyForwardHelper;
109 typedef struct _MoveToHelper {
110 GtkTreeRowReference *reference;
114 typedef struct _PasteAsAttachmentHelper {
115 ModestMsgEditWindow *window;
117 } PasteAsAttachmentHelper;
125 * The do_headers_action uses this kind of functions to perform some
126 * action to each member of a list of headers
128 typedef void (*HeadersFunc) (TnyHeader *header, ModestWindow *win, gpointer user_data);
130 static void do_headers_action (ModestWindow *win,
134 static void open_msg_cb (ModestMailOperation *mail_op,
141 static void reply_forward_cb (ModestMailOperation *mail_op,
148 static void reply_forward (ReplyForwardAction action, ModestWindow *win);
150 #ifndef MODEST_TOOLKIT_HILDON2
151 static void folder_refreshed_cb (ModestMailOperation *mail_op,
155 static void on_send_receive_finished (ModestMailOperation *mail_op,
159 static gint header_list_count_uncached_msgs (TnyList *header_list);
161 static gboolean connect_to_get_msg (ModestWindow *win,
162 gint num_of_uncached_msgs,
163 TnyAccount *account);
165 static gboolean remote_folder_has_leave_on_server (TnyFolderStore *folder);
167 static void do_create_folder (GtkWindow *window,
168 TnyFolderStore *parent_folder,
169 const gchar *suggested_name);
171 static TnyAccount *get_account_from_folder_store (TnyFolderStore *folder_store);
173 #ifndef MODEST_TOOLKIT_HILDON2
174 static void modest_ui_actions_on_main_window_move_to (GtkAction *action,
175 GtkWidget *folder_view,
176 TnyFolderStore *dst_folder,
177 ModestMainWindow *win);
180 static void modest_ui_actions_on_folder_window_move_to (GtkWidget *folder_view,
181 TnyFolderStore *dst_folder,
186 static void modest_ui_actions_on_window_move_to (GtkAction *action,
187 TnyList *list_to_move,
188 TnyFolderStore *dst_folder,
192 * This function checks whether a TnyFolderStore is a pop account
195 remote_folder_has_leave_on_server (TnyFolderStore *folder)
200 g_return_val_if_fail (TNY_IS_FOLDER_STORE (folder), FALSE);
202 account = get_account_from_folder_store (folder);
203 result = (modest_protocol_registry_protocol_type_has_leave_on_server (modest_runtime_get_protocol_registry (),
204 modest_tny_account_get_protocol_type (account)));
205 g_object_unref (account);
210 /* FIXME: this should be merged with the similar code in modest-account-view-window */
211 /* Show the account creation wizard dialog.
212 * returns: TRUE if an account was created. FALSE if the user cancelled.
215 modest_ui_actions_run_account_setup_wizard (ModestWindow *win)
217 gboolean result = FALSE;
219 gint dialog_response;
221 /* there is no such wizard yet */
222 wizard = GTK_WINDOW (modest_platform_get_account_settings_wizard ());
223 modest_window_mgr_set_modal (modest_runtime_get_window_mgr(), GTK_WINDOW (wizard), (GtkWindow *) win);
225 #ifndef MODEST_TOOLKIT_HILDON2
226 /* always present a main window in the background
227 * we do it here, so we cannot end up with two wizards (as this
228 * function might be called in modest_window_mgr_get_main_window as well */
230 win = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr(),
231 TRUE); /* create if not existent */
235 ModestWindowMgr *mgr;
237 mgr = modest_runtime_get_window_mgr ();
239 window_list = modest_window_mgr_get_window_list (mgr);
240 if (window_list == NULL) {
241 win = MODEST_WINDOW (modest_accounts_window_new ());
242 if (modest_window_mgr_register_window (mgr, win, NULL)) {
243 gtk_widget_show_all (GTK_WIDGET (win));
245 gtk_widget_destroy (GTK_WIDGET (win));
250 g_list_free (window_list);
256 gtk_window_set_transient_for (GTK_WINDOW (wizard), GTK_WINDOW (win));
258 /* make sure the mainwindow is visible. We need to present the
259 wizard again to give it the focus back. show_all are needed
260 in order to get the widgets properly drawn (MainWindow main
261 paned won't be in its right position and the dialog will be
263 #ifndef MODEST_TOOLKIT_HILDON2
264 gtk_widget_show_all (GTK_WIDGET (win));
265 gtk_widget_show_all (GTK_WIDGET (wizard));
266 gtk_window_present (GTK_WINDOW (win));
267 gtk_window_present (GTK_WINDOW (wizard));
270 dialog_response = gtk_dialog_run (GTK_DIALOG (wizard));
271 gtk_widget_destroy (GTK_WIDGET (wizard));
272 if (gtk_events_pending ())
273 gtk_main_iteration ();
275 if (dialog_response == GTK_RESPONSE_CANCEL) {
278 /* Check whether an account was created: */
279 result = modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
286 modest_ui_actions_on_about (GtkAction *action, ModestWindow *win)
289 const gchar *authors[] = {
290 "Dirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>",
293 about = gtk_about_dialog_new ();
294 gtk_about_dialog_set_name (GTK_ABOUT_DIALOG(about), PACKAGE_NAME);
295 gtk_about_dialog_set_version (GTK_ABOUT_DIALOG(about),PACKAGE_VERSION);
296 gtk_about_dialog_set_copyright (GTK_ABOUT_DIALOG(about),
297 _("Copyright (c) 2006, Nokia Corporation\n"
298 "All rights reserved."));
299 gtk_about_dialog_set_comments (GTK_ABOUT_DIALOG(about),
300 _("a modest e-mail client\n\n"
301 "design and implementation: Dirk-Jan C. Binnema\n"
302 "contributions from the fine people at KC and Ig\n"
303 "uses the tinymail email framework written by Philip van Hoof"));
304 gtk_about_dialog_set_authors (GTK_ABOUT_DIALOG(about), authors);
305 gtk_about_dialog_set_website (GTK_ABOUT_DIALOG(about), "http://modest.garage.maemo.org");
306 gtk_window_set_transient_for (GTK_WINDOW (about), GTK_WINDOW (win));
307 gtk_window_set_modal (GTK_WINDOW (about), TRUE);
309 gtk_dialog_run (GTK_DIALOG (about));
310 gtk_widget_destroy(about);
314 * Gets the list of currently selected messages. If the win is the
315 * main window, then it returns a newly allocated list of the headers
316 * selected in the header view. If win is the msg view window, then
317 * the value returned is a list with just a single header.
319 * The caller of this funcion must free the list.
322 get_selected_headers (ModestWindow *win)
324 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
325 /* for MsgViewWindows, we simply return a list with one element */
327 TnyList *list = NULL;
329 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
330 if (header != NULL) {
331 list = tny_simple_list_new ();
332 tny_list_prepend (list, G_OBJECT(header));
333 g_object_unref (G_OBJECT(header));
337 #ifndef MODEST_TOOLKIT_HILDON2
338 } else if (MODEST_IS_MAIN_WINDOW(win)) {
339 GtkWidget *header_view;
341 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
342 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
343 return modest_header_view_get_selected_headers (MODEST_HEADER_VIEW(header_view));
345 } else if (MODEST_IS_HEADER_WINDOW (win)) {
346 GtkWidget *header_view;
348 header_view = GTK_WIDGET (modest_header_window_get_header_view (MODEST_HEADER_WINDOW (win)));
349 return modest_header_view_get_selected_headers (MODEST_HEADER_VIEW(header_view));
356 #ifndef MODEST_TOOLKIT_HILDON2
357 static GtkTreeRowReference *
358 get_next_after_selected_headers (ModestHeaderView *header_view)
360 GtkTreeSelection *sel;
361 GList *selected_rows, *node;
363 GtkTreeRowReference *result;
366 model = gtk_tree_view_get_model (GTK_TREE_VIEW (header_view));
367 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
368 selected_rows = gtk_tree_selection_get_selected_rows (sel, NULL);
370 if (selected_rows == NULL)
373 node = g_list_last (selected_rows);
374 path = gtk_tree_path_copy ((GtkTreePath *) node->data);
375 gtk_tree_path_next (path);
377 result = gtk_tree_row_reference_new (model, path);
379 gtk_tree_path_free (path);
380 g_list_foreach (selected_rows, (GFunc) gtk_tree_path_free, NULL);
381 g_list_free (selected_rows);
388 headers_action_mark_as_read (TnyHeader *header,
392 TnyHeaderFlags flags;
394 g_return_if_fail (TNY_IS_HEADER(header));
396 flags = tny_header_get_flags (header);
397 if (flags & TNY_HEADER_FLAG_SEEN) return;
398 tny_header_set_flag (header, TNY_HEADER_FLAG_SEEN);
402 headers_action_mark_as_unread (TnyHeader *header,
406 TnyHeaderFlags flags;
408 g_return_if_fail (TNY_IS_HEADER(header));
410 flags = tny_header_get_flags (header);
411 if (flags & TNY_HEADER_FLAG_SEEN) {
412 tny_header_unset_flag (header, TNY_HEADER_FLAG_SEEN);
416 /** After deleing a message that is currently visible in a window,
417 * show the next message from the list, or close the window if there are no more messages.
420 modest_ui_actions_refresh_message_window_after_delete (ModestMsgViewWindow* win)
422 /* Close msg view window or select next */
423 if (!modest_msg_view_window_select_next_message (win) &&
424 !modest_msg_view_window_select_previous_message (win)) {
426 g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value);
432 modest_ui_actions_on_delete_message (GtkAction *action, ModestWindow *win)
434 modest_ui_actions_on_edit_mode_delete_message (win);
438 modest_ui_actions_on_edit_mode_delete_message (ModestWindow *win)
440 TnyList *header_list = NULL;
441 TnyIterator *iter = NULL;
442 TnyHeader *header = NULL;
443 gchar *message = NULL;
446 ModestWindowMgr *mgr;
447 gboolean retval = TRUE;
449 g_return_val_if_fail (MODEST_IS_WINDOW(win), FALSE);
451 /* Get the headers, either from the header view (if win is the main window),
452 * or from the message view window: */
453 header_list = get_selected_headers (win);
454 if (!header_list) return FALSE;
456 /* Check if any of the headers are already opened, or in the process of being opened */
459 if (tny_list_get_length(header_list) == 1) {
460 iter = tny_list_create_iterator (header_list);
461 header = TNY_HEADER (tny_iterator_get_current (iter));
464 subject = tny_header_dup_subject (header);
466 subject = g_strdup (_("mail_va_no_subject"));
467 desc = g_strdup_printf ("%s", subject);
469 g_object_unref (header);
472 g_object_unref (iter);
474 message = g_strdup_printf(ngettext("emev_nc_delete_message", "emev_nc_delete_messages",
475 tny_list_get_length(header_list)), desc);
477 /* Confirmation dialog */
478 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
481 if (response == GTK_RESPONSE_OK) {
482 GtkTreeSelection *sel = NULL;
483 GList *sel_list = NULL;
484 ModestMailOperation *mail_op = NULL;
486 /* Find last selected row */
488 /* Disable window dimming management */
489 modest_window_disable_dimming (win);
491 /* Remove each header. If it's a view window header_view == NULL */
492 mail_op = modest_mail_operation_new ((GObject *) win);
493 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
495 modest_mail_operation_remove_msgs (mail_op, header_list, FALSE);
496 g_object_unref (mail_op);
498 /* Enable window dimming management */
500 gtk_tree_selection_unselect_all (sel);
502 modest_window_enable_dimming (win);
504 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
505 modest_ui_actions_refresh_message_window_after_delete (MODEST_MSG_VIEW_WINDOW (win));
507 /* Get main window */
508 mgr = modest_runtime_get_window_mgr ();
511 /* Update toolbar dimming state */
512 modest_ui_actions_check_menu_dimming_rules (win);
513 modest_ui_actions_check_toolbar_dimming_rules (win);
516 g_list_foreach (sel_list, (GFunc) gtk_tree_path_free, NULL);
517 g_list_free (sel_list);
526 g_object_unref (header_list);
534 /* delete either message or folder, based on where we are */
536 modest_ui_actions_on_delete_message_or_folder (GtkAction *action, ModestWindow *win)
538 g_return_if_fail (MODEST_IS_WINDOW(win));
540 /* Check first if the header view has the focus */
541 #ifndef MODEST_TOOLKIT_HILDON2
542 if (MODEST_IS_MAIN_WINDOW (win)) {
544 w = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
545 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
546 if (gtk_widget_is_focus (w)) {
547 modest_ui_actions_on_delete_folder (action, MODEST_WINDOW(win));
552 modest_ui_actions_on_delete_message (action, win);
556 modest_ui_actions_on_quit (GtkAction *action, ModestWindow *win)
558 ModestWindowMgr *mgr = NULL;
560 #ifdef MODEST_PLATFORM_MAEMO
561 modest_window_mgr_save_state_for_all_windows (modest_runtime_get_window_mgr ());
562 #endif /* MODEST_PLATFORM_MAEMO */
564 g_debug ("closing down, clearing %d item(s) from operation queue",
565 modest_mail_operation_queue_num_elements
566 (modest_runtime_get_mail_operation_queue()));
568 /* cancel all outstanding operations */
569 modest_mail_operation_queue_cancel_all
570 (modest_runtime_get_mail_operation_queue());
572 g_debug ("queue has been cleared");
575 /* Check if there are opened editing windows */
576 mgr = modest_runtime_get_window_mgr ();
577 modest_window_mgr_close_all_windows (mgr);
579 /* note: when modest-tny-account-store is finalized,
580 it will automatically set all network connections
583 /* gtk_main_quit (); */
587 modest_ui_actions_on_close_window (GtkAction *action, ModestWindow *win)
591 g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value);
593 /* if (MODEST_IS_MSG_VIEW_WINDOW (win)) { */
594 /* gtk_widget_destroy (GTK_WIDGET (win)); */
595 /* } else if (MODEST_IS_MSG_EDIT_WINDOW (win)) { */
596 /* gboolean ret_value; */
597 /* g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value); */
598 /* } else if (MODEST_IS_WINDOW (win)) { */
599 /* gtk_widget_destroy (GTK_WIDGET (win)); */
601 /* g_return_if_reached (); */
606 modest_ui_actions_add_to_contacts (GtkAction *action, ModestWindow *win)
608 if (MODEST_IS_MSG_VIEW_WINDOW (win))
609 modest_msg_view_window_add_to_contacts (MODEST_MSG_VIEW_WINDOW (win));
610 else if (MODEST_IS_MSG_EDIT_WINDOW (win))
611 modest_msg_edit_window_add_to_contacts (MODEST_MSG_EDIT_WINDOW (win));
615 modest_ui_actions_on_add_to_contacts (GtkAction *action, ModestWindow *win)
617 GtkClipboard *clipboard = NULL;
618 gchar *selection = NULL;
620 clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
621 selection = gtk_clipboard_wait_for_text (clipboard);
624 modest_address_book_add_address (selection, (GtkWindow *) win);
630 modest_ui_actions_on_new_account (GtkAction *action,
631 ModestWindow *window)
633 if (!modest_ui_actions_run_account_setup_wizard (window)) {
634 g_debug ("%s: wizard was already running", __FUNCTION__);
639 modest_ui_actions_on_accounts (GtkAction *action,
642 /* This is currently only implemented for Maemo */
643 if (!modest_account_mgr_has_accounts (modest_runtime_get_account_mgr(), TRUE)) {
644 if (!modest_ui_actions_run_account_setup_wizard (win))
645 g_debug ("%s: wizard was already running", __FUNCTION__);
649 /* Show the list of accounts */
650 GtkWindow *account_win = GTK_WINDOW (modest_account_view_window_new ());
652 /* The accounts dialog must be modal */
653 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (account_win), (GtkWindow *) win);
654 modest_utils_show_dialog_and_forget (GTK_WINDOW (win), GTK_DIALOG (account_win));
659 modest_ui_actions_on_smtp_servers (GtkAction *action, ModestWindow *win)
661 /* This is currently only implemented for Maemo,
662 * because it requires an API (libconic) to detect different connection
665 #ifndef MODEST_TOOLKIT_GTK /* Defined in config.h */
667 /* Create the window if necessary: */
668 GtkWidget *specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
669 modest_connection_specific_smtp_window_fill_with_connections (
670 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (specific_window),
671 modest_runtime_get_account_mgr());
673 /* Show the window: */
674 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (),
675 GTK_WINDOW (specific_window), (GtkWindow *) win);
676 gtk_widget_show (specific_window);
677 #endif /* !MODEST_TOOLKIT_GTK */
681 count_part_size (const gchar *part)
683 GnomeVFSURI *vfs_uri;
684 gchar *escaped_filename;
686 GnomeVFSFileInfo *info;
689 /* Estimation of attachment size if we cannot get it from file info */
692 vfs_uri = gnome_vfs_uri_new (part);
694 escaped_filename = g_path_get_basename (gnome_vfs_uri_get_path (vfs_uri));
695 filename = gnome_vfs_unescape_string_for_display (escaped_filename);
696 g_free (escaped_filename);
697 gnome_vfs_uri_unref (vfs_uri);
699 info = gnome_vfs_file_info_new ();
701 if (gnome_vfs_get_file_info (part,
703 GNOME_VFS_FILE_INFO_GET_MIME_TYPE)
705 if (info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_SIZE) {
710 gnome_vfs_file_info_unref (info);
716 count_parts_size (GSList *parts)
721 for (node = parts; node != NULL; node = g_slist_next (node)) {
722 result += count_part_size ((const gchar *) node->data);
729 modest_ui_actions_compose_msg(ModestWindow *win,
732 const gchar *bcc_str,
733 const gchar *subject_str,
734 const gchar *body_str,
736 gboolean set_as_modified)
738 gchar *account_name = NULL;
739 const gchar *mailbox;
741 TnyAccount *account = NULL;
742 TnyFolder *folder = NULL;
743 gchar *from_str = NULL, *signature = NULL, *body = NULL;
744 gchar *recipient = NULL;
745 gboolean use_signature = FALSE;
746 ModestWindow *msg_win = NULL;
747 ModestAccountMgr *mgr = modest_runtime_get_account_mgr();
748 ModestTnyAccountStore *store = modest_runtime_get_account_store();
749 GnomeVFSFileSize total_size, allowed_size;
750 guint64 available_disk, expected_size, parts_size;
753 /* we check for low-mem */
754 if (modest_platform_check_memory_low (win, TRUE))
757 available_disk = modest_utils_get_available_space (NULL);
758 parts_count = g_slist_length (attachments);
759 parts_size = count_parts_size (attachments);
760 expected_size = modest_tny_msg_estimate_size (body, NULL, parts_count, parts_size);
762 /* Double check: disk full condition or message too big */
763 if (available_disk < MODEST_TNY_ACCOUNT_STORE_MIN_FREE_SPACE ||
764 expected_size > available_disk) {
765 gchar *msg = g_strdup_printf (_KR("cerm_device_memory_full"), "");
766 modest_platform_system_banner (NULL, NULL, msg);
772 if (expected_size > MODEST_MAX_ATTACHMENT_SIZE) {
773 modest_platform_run_information_dialog (
775 _("mail_ib_error_attachment_size"),
781 #ifdef MODEST_TOOLKIT_HILDON2
783 account_name = g_strdup (modest_window_get_active_account(win));
786 account_name = modest_account_mgr_get_default_account(mgr);
789 g_printerr ("modest: no account found\n");
794 mailbox = modest_window_get_active_mailbox (win);
797 account = modest_tny_account_store_get_server_account (store, account_name, TNY_ACCOUNT_TYPE_STORE);
799 g_printerr ("modest: failed to get tnyaccount for '%s'\n", account_name);
802 folder = modest_tny_account_get_special_folder (account, TNY_FOLDER_TYPE_DRAFTS);
804 g_printerr ("modest: failed to find Drafts folder\n");
807 from_str = modest_account_mgr_get_from_string (mgr, account_name, mailbox);
809 g_printerr ("modest: failed get from string for '%s'\n", account_name);
813 recipient = modest_text_utils_get_email_address (from_str);
814 signature = modest_account_mgr_get_signature_from_recipient (mgr, recipient, &use_signature);
816 if (body_str != NULL) {
817 body = use_signature ? g_strconcat(body_str, "\n",
818 MODEST_TEXT_UTILS_SIGNATURE_MARKER,
819 "\n", signature, NULL) : g_strdup(body_str);
821 body = use_signature ? g_strconcat("\n", MODEST_TEXT_UTILS_SIGNATURE_MARKER,
822 "\n", signature, NULL) : g_strdup("");
825 msg = modest_tny_msg_new (to_str, from_str, cc_str, bcc_str, subject_str, NULL, NULL, body, NULL, NULL, NULL);
827 g_printerr ("modest: failed to create new msg\n");
831 /* Create and register edit window */
832 /* This is destroyed by TODO. */
834 allowed_size = MODEST_MAX_ATTACHMENT_SIZE;
835 msg_win = modest_msg_edit_window_new (msg, account_name, mailbox, FALSE);
837 if (!modest_window_mgr_register_window (modest_runtime_get_window_mgr(), msg_win, win)) {
838 gtk_widget_destroy (GTK_WIDGET (msg_win));
841 modest_msg_edit_window_set_modified (MODEST_MSG_EDIT_WINDOW (msg_win), set_as_modified);
842 gtk_widget_show_all (GTK_WIDGET (msg_win));
844 while (attachments) {
845 GnomeVFSFileSize att_size;
847 modest_msg_edit_window_attach_file_one((ModestMsgEditWindow *)msg_win,
848 attachments->data, allowed_size);
849 total_size += att_size;
851 if (att_size > allowed_size) {
852 g_debug ("%s: total size: %u",
853 __FUNCTION__, (unsigned int)total_size);
856 allowed_size -= att_size;
858 attachments = g_slist_next(attachments);
865 g_free (account_name);
867 g_object_unref (G_OBJECT(account));
869 g_object_unref (G_OBJECT(folder));
871 g_object_unref (G_OBJECT(msg));
875 modest_ui_actions_on_new_msg (GtkAction *action, ModestWindow *win)
877 /* if there are no accounts yet, just show the wizard */
878 if (!modest_account_mgr_has_accounts (modest_runtime_get_account_mgr(), TRUE))
879 if (!modest_ui_actions_run_account_setup_wizard (win))
882 modest_ui_actions_compose_msg(win, NULL, NULL, NULL, NULL, NULL, NULL, FALSE);
887 modest_ui_actions_msg_retrieval_check (ModestMailOperation *mail_op,
891 ModestMailOperationStatus status;
893 /* If there is no message or the operation was not successful */
894 status = modest_mail_operation_get_status (mail_op);
895 if (!msg || status != MODEST_MAIL_OPERATION_STATUS_SUCCESS) {
898 /* If it's a memory low issue, then show a banner */
899 error = modest_mail_operation_get_error (mail_op);
900 if (error && error->domain == MODEST_MAIL_OPERATION_ERROR &&
901 error->code == MODEST_MAIL_OPERATION_ERROR_LOW_MEMORY) {
902 GObject *source = modest_mail_operation_get_source (mail_op);
903 modest_platform_run_information_dialog (GTK_IS_WINDOW (source) ? GTK_WINDOW (source) : NULL,
904 _KR("memr_ib_operation_disabled"),
906 g_object_unref (source);
909 if (error && ((error->code == TNY_SERVICE_ERROR_NO_SUCH_MESSAGE) ||
910 error->code == TNY_SERVICE_ERROR_MESSAGE_NOT_AVAILABLE)) {
911 gchar *subject, *msg, *format = NULL;
914 subject = (header) ? tny_header_dup_subject (header) : NULL;
916 subject = g_strdup (_("mail_va_no_subject"));
918 account = modest_mail_operation_get_account (mail_op);
920 ModestProtocolType proto = modest_tny_account_get_protocol_type (account);
921 ModestProtocol *protocol = modest_protocol_registry_get_protocol_by_type (modest_runtime_get_protocol_registry (), proto);
924 if (tny_account_get_connection_status (account) ==
925 TNY_CONNECTION_STATUS_CONNECTED) {
927 format = modest_protocol_get_translation (protocol,
928 MODEST_PROTOCOL_TRANSLATION_MSG_NOT_AVAILABLE,
931 format = modest_protocol_get_translation (protocol,
932 MODEST_PROTOCOL_TRANSLATION_MSG_NOT_AVAILABLE_LOST_HEADER);
935 format = g_strdup_printf (_("mail_ib_backend_server_invalid"),
936 tny_account_get_hostname (account));
939 g_object_unref (account);
944 format = g_strdup (_("emev_ni_ui_imap_message_not_available_in_server"));
946 format = g_strdup (_("emev_ni_ui_pop3_msg_recv_error"));
950 msg = g_strdup_printf (format, subject);
951 modest_platform_run_information_dialog (NULL, msg, FALSE);
957 /* Remove the header from the preregistered uids */
958 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (),
976 ModestWindow *caller_window;
977 OpenMsgBannerInfo *banner_info;
978 GtkTreeRowReference *rowref;
982 open_msg_banner_idle (gpointer userdata)
984 OpenMsgBannerInfo *banner_info = (OpenMsgBannerInfo *) userdata;
986 gdk_threads_enter ();
987 banner_info->idle_handler = 0;
988 banner_info->banner = modest_platform_animation_banner (NULL, NULL, banner_info->message);
989 if (banner_info->banner)
990 g_object_ref (banner_info->banner);
992 gdk_threads_leave ();
998 get_header_view_from_window (ModestWindow *window)
1000 GtkWidget *header_view;
1002 #ifndef MODEST_TOOLKIT_HILDON2
1003 if (MODEST_IS_MAIN_WINDOW (window)) {
1004 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (window),
1005 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1007 if (MODEST_IS_HEADER_WINDOW (window)){
1008 header_view = GTK_WIDGET (modest_header_window_get_header_view (MODEST_HEADER_WINDOW (window)));
1018 get_info_from_header (TnyHeader *header, gboolean *is_draft, gboolean *can_open)
1021 gchar *account = NULL;
1022 TnyFolderType folder_type = TNY_FOLDER_TYPE_UNKNOWN;
1027 folder = tny_header_get_folder (header);
1028 /* Gets folder type (OUTBOX headers will be opened in edit window */
1029 if (modest_tny_folder_is_local_folder (folder)) {
1030 folder_type = modest_tny_folder_get_local_or_mmc_folder_type (folder);
1031 if (folder_type == TNY_FOLDER_TYPE_INVALID)
1032 g_warning ("%s: BUG: TNY_FOLDER_TYPE_INVALID", __FUNCTION__);
1035 if (folder_type == TNY_FOLDER_TYPE_OUTBOX) {
1036 TnyTransportAccount *traccount = NULL;
1037 ModestTnyAccountStore *accstore = modest_runtime_get_account_store();
1038 traccount = modest_tny_account_store_get_transport_account_from_outbox_header(accstore, header);
1040 ModestTnySendQueue *send_queue = NULL;
1041 ModestTnySendQueueStatus status;
1043 account = g_strdup(modest_tny_account_get_parent_modest_account_name_for_server_account(
1044 TNY_ACCOUNT(traccount)));
1045 send_queue = modest_runtime_get_send_queue(traccount, TRUE);
1046 if (TNY_IS_SEND_QUEUE (send_queue)) {
1047 msg_id = modest_tny_send_queue_get_msg_id (header);
1048 status = modest_tny_send_queue_get_msg_status(send_queue, msg_id);
1050 /* Only open messages in outbox with the editor if they are in Failed state */
1051 if (status == MODEST_TNY_SEND_QUEUE_FAILED) {
1054 #ifdef MODEST_TOOLKIT_HILDON2
1056 /* In Fremantle we can not
1057 open any message from
1058 outbox which is not in
1064 g_object_unref(traccount);
1066 g_warning("Cannot get transport account for message in outbox!!");
1068 } else if (folder_type == TNY_FOLDER_TYPE_DRAFTS) {
1069 *is_draft = TRUE; /* Open in editor if the message is in the Drafts folder */
1073 TnyAccount *acc = tny_folder_get_account (folder);
1076 g_strdup (modest_tny_account_get_parent_modest_account_name_for_server_account (acc));
1077 g_object_unref (acc);
1081 g_object_unref (folder);
1087 open_msg_cb (ModestMailOperation *mail_op,
1094 ModestWindowMgr *mgr = NULL;
1095 ModestWindow *parent_win = NULL;
1096 ModestWindow *win = NULL;
1097 gchar *account = NULL;
1098 gboolean open_in_editor = FALSE;
1100 OpenMsgHelper *helper = (OpenMsgHelper *) user_data;
1102 /* Do nothing if there was any problem with the mail
1103 operation. The error will be shown by the error_handler of
1104 the mail operation */
1105 if (!modest_ui_actions_msg_retrieval_check (mail_op, header, msg))
1108 parent_win = (ModestWindow *) modest_mail_operation_get_source (mail_op);
1110 /* Mark header as read */
1111 headers_action_mark_as_read (header, MODEST_WINDOW(parent_win), NULL);
1113 account = get_info_from_header (header, &open_in_editor, &can_open);
1117 account = g_strdup (modest_window_get_active_account (MODEST_WINDOW (parent_win)));
1119 account = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
1121 if (open_in_editor) {
1122 ModestAccountMgr *mgr = modest_runtime_get_account_mgr ();
1123 gchar *from_header = NULL, *acc_name;
1124 gchar *mailbox = NULL;
1126 from_header = tny_header_dup_from (header);
1128 /* we cannot edit without a valid account... */
1129 if (!modest_account_mgr_has_accounts(mgr, TRUE)) {
1130 if (!modest_ui_actions_run_account_setup_wizard(parent_win)) {
1131 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (),
1133 g_free (from_header);
1138 acc_name = modest_utils_get_account_name_from_recipient (from_header, &mailbox);
1139 g_free (from_header);
1145 win = modest_msg_edit_window_new (msg, account, mailbox, TRUE);
1149 gchar *uid = modest_tny_folder_get_header_unique_id (header);
1150 const gchar *mailbox = NULL;
1152 if (parent_win && MODEST_IS_WINDOW (parent_win))
1153 mailbox = modest_window_get_active_mailbox (MODEST_WINDOW (parent_win));
1155 if (helper->rowref && helper->model) {
1156 win = modest_msg_view_window_new_with_header_model (msg, account, mailbox, (const gchar*) uid,
1157 helper->model, helper->rowref);
1159 win = modest_msg_view_window_new_for_attachment (msg, account, mailbox, (const gchar*) uid);
1164 /* Register and show new window */
1166 mgr = modest_runtime_get_window_mgr ();
1167 if (!modest_window_mgr_register_window (mgr, win, NULL)) {
1168 gtk_widget_destroy (GTK_WIDGET (win));
1171 gtk_widget_show_all (GTK_WIDGET(win));
1174 #ifndef MODEST_TOOLKIT_HILDON2
1175 /* Update toolbar dimming state */
1176 if (MODEST_IS_MAIN_WINDOW (parent_win)) {
1177 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (parent_win));
1184 g_object_unref (parent_win);
1188 modest_ui_actions_disk_operations_error_handler (ModestMailOperation *mail_op,
1191 const GError *error;
1192 GObject *win = NULL;
1193 ModestMailOperationStatus status;
1195 win = modest_mail_operation_get_source (mail_op);
1196 error = modest_mail_operation_get_error (mail_op);
1197 status = modest_mail_operation_get_status (mail_op);
1199 /* If the mail op has been cancelled then it's not an error:
1200 don't show any message */
1201 if (status != MODEST_MAIL_OPERATION_STATUS_CANCELED) {
1202 TnyAccount *account = modest_mail_operation_get_account (mail_op);
1203 if (modest_tny_account_store_is_disk_full_error (modest_runtime_get_account_store(),
1204 (GError *) error, account)) {
1205 gchar *msg = g_strdup_printf (_KR("cerm_device_memory_full"), "");
1206 modest_platform_information_banner ((GtkWidget *) win, NULL, msg);
1208 } else if (error->code == TNY_SYSTEM_ERROR_MEMORY) {
1209 modest_platform_information_banner ((GtkWidget *) win,
1210 NULL, _("emev_ui_imap_inbox_select_error"));
1211 } else if (error->domain == MODEST_MAIL_OPERATION_ERROR &&
1212 error->code == MODEST_MAIL_OPERATION_ERROR_FILE_IO) {
1213 modest_platform_information_banner ((GtkWidget *) win,
1214 NULL, _CS ("sfil_ni_unable_to_open_file_not_found"));
1215 } else if (user_data) {
1216 modest_platform_information_banner ((GtkWidget *) win,
1220 g_object_unref (account);
1224 g_object_unref (win);
1228 * Returns the account a list of headers belongs to. It returns a
1229 * *new* reference so don't forget to unref it
1232 get_account_from_header_list (TnyList *headers)
1234 TnyAccount *account = NULL;
1236 if (tny_list_get_length (headers) > 0) {
1237 TnyIterator *iter = tny_list_create_iterator (headers);
1238 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter));
1239 TnyFolder *folder = tny_header_get_folder (header);
1242 g_object_unref (header);
1244 while (!tny_iterator_is_done (iter)) {
1245 header = TNY_HEADER (tny_iterator_get_current (iter));
1246 folder = tny_header_get_folder (header);
1249 g_object_unref (header);
1251 tny_iterator_next (iter);
1256 account = tny_folder_get_account (folder);
1257 g_object_unref (folder);
1261 g_object_unref (header);
1263 g_object_unref (iter);
1269 get_account_from_header (TnyHeader *header)
1271 TnyAccount *account = NULL;
1274 folder = tny_header_get_folder (header);
1277 account = tny_folder_get_account (folder);
1278 g_object_unref (folder);
1284 caller_win_destroyed (OpenMsgHelper *helper, GObject *object)
1286 if (helper->caller_window)
1287 helper->caller_window = NULL;
1291 open_msg_helper_destroyer (gpointer user_data)
1293 OpenMsgHelper *helper = (OpenMsgHelper *) user_data;
1295 if (helper->caller_window) {
1296 g_object_weak_unref ((GObject *) helper->caller_window, (GWeakNotify) caller_win_destroyed, helper);
1297 helper->caller_window = NULL;
1300 if (helper->banner_info) {
1301 g_free (helper->banner_info->message);
1302 if (helper->banner_info->idle_handler > 0) {
1303 g_source_remove (helper->banner_info->idle_handler);
1304 helper->banner_info->idle_handler = 0;
1306 if (helper->banner_info->banner != NULL) {
1307 gtk_widget_destroy (helper->banner_info->banner);
1308 g_object_unref (helper->banner_info->banner);
1309 helper->banner_info->banner = NULL;
1311 g_slice_free (OpenMsgBannerInfo, helper->banner_info);
1312 helper->banner_info = NULL;
1314 g_object_unref (helper->model);
1315 g_object_unref (helper->header);
1316 gtk_tree_row_reference_free (helper->rowref);
1317 g_slice_free (OpenMsgHelper, helper);
1321 open_msg_performer(gboolean canceled,
1323 GtkWindow *parent_window,
1324 TnyAccount *account,
1327 ModestMailOperation *mail_op = NULL;
1328 gchar *error_msg = NULL;
1329 ModestProtocolType proto;
1330 TnyConnectionStatus status;
1331 OpenMsgHelper *helper = NULL;
1332 ModestProtocol *protocol;
1333 ModestProtocolRegistry *protocol_registry;
1336 helper = (OpenMsgHelper *) user_data;
1338 status = tny_account_get_connection_status (account);
1339 if (err || canceled || helper->caller_window == NULL) {
1340 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (), helper->header);
1341 /* Free the helper */
1342 open_msg_helper_destroyer (helper);
1344 /* In disk full conditions we could get this error here */
1345 modest_tny_account_store_check_disk_full_error (modest_runtime_get_account_store(),
1346 (GtkWidget *) parent_window, err,
1352 /* Get the error message depending on the protocol */
1353 proto = modest_tny_account_get_protocol_type (account);
1354 if (proto == MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1355 proto = MODEST_PROTOCOLS_STORE_MAILDIR;
1358 protocol_registry = modest_runtime_get_protocol_registry ();
1359 subject = tny_header_dup_subject (helper->header);
1361 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, proto);
1362 error_msg = modest_protocol_get_translation (protocol, MODEST_PROTOCOL_TRANSLATION_MSG_NOT_AVAILABLE, subject);
1366 if (error_msg == NULL) {
1367 error_msg = g_strdup (_("mail_ni_ui_folder_get_msg_folder_error"));
1370 #ifndef MODEST_TOOLKIT_HILDON2
1371 gboolean show_open_draft = FALSE;
1372 if (modest_protocol_registry_protocol_type_has_tag (protocol_registry,
1374 MODEST_PROTOCOL_REGISTRY_LOCAL_STORE_PROTOCOLS)) {
1376 TnyFolderType folder_type;
1378 folder = tny_header_get_folder (helper->header);
1379 folder_type = modest_tny_folder_get_local_or_mmc_folder_type (folder);
1380 show_open_draft = (folder_type == TNY_FOLDER_TYPE_DRAFTS);
1381 g_object_unref (folder);
1385 #ifdef MODEST_TOOLKIT_HILDON2
1388 gchar *account_name = get_info_from_header (helper->header, &is_draft, &can_open);
1391 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (), helper->header);
1392 g_free (account_name);
1393 open_msg_helper_destroyer (helper);
1398 ModestWindow *window;
1399 GtkWidget *header_view;
1402 header_view = get_header_view_from_window (MODEST_WINDOW (parent_window));
1403 uid = modest_tny_folder_get_header_unique_id (helper->header);
1405 const gchar *mailbox = NULL;
1406 mailbox = modest_window_get_active_mailbox (MODEST_WINDOW (parent_window));
1407 window = modest_msg_view_window_new_from_header_view
1408 (MODEST_HEADER_VIEW (header_view), account_name, mailbox, uid, helper->rowref);
1409 if (window != NULL) {
1410 if (!modest_window_mgr_register_window (modest_runtime_get_window_mgr (),
1412 gtk_widget_destroy (GTK_WIDGET (window));
1414 gtk_widget_show_all (GTK_WIDGET(window));
1418 g_free (account_name);
1420 open_msg_helper_destroyer (helper);
1423 g_free (account_name);
1425 /* Create the mail operation */
1427 modest_mail_operation_new_with_error_handling ((GObject *) parent_window,
1428 modest_ui_actions_disk_operations_error_handler,
1429 g_strdup (error_msg), g_free);
1430 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
1434 #ifndef MODEST_TOOLKIT_HILDON2
1435 if (show_open_draft) {
1436 helper->banner_info = g_slice_new (OpenMsgBannerInfo);
1437 helper->banner_info->message = g_strdup (_("mail_ib_opening_draft_message"));
1438 helper->banner_info->banner = NULL;
1439 helper->banner_info->idle_handler = g_timeout_add (500, open_msg_banner_idle,
1440 helper->banner_info);
1446 headers = TNY_LIST (tny_simple_list_new ());
1447 tny_list_prepend (headers, G_OBJECT (helper->header));
1448 modest_mail_operation_get_msgs_full (mail_op,
1452 open_msg_helper_destroyer);
1453 g_object_unref (headers);
1460 g_object_unref (mail_op);
1461 g_object_unref (account);
1465 * This function is used by both modest_ui_actions_on_open and
1466 * modest_ui_actions_on_header_activated. This way we always do the
1467 * same when trying to open messages.
1470 open_msg_from_header (TnyHeader *header, GtkTreeRowReference *rowref, ModestWindow *win)
1472 ModestWindowMgr *mgr = NULL;
1473 TnyAccount *account;
1474 gboolean cached = FALSE;
1476 GtkWidget *header_view = NULL;
1477 OpenMsgHelper *helper;
1478 ModestWindow *window;
1480 g_return_if_fail (header != NULL && rowref != NULL && gtk_tree_row_reference_valid (rowref));
1482 mgr = modest_runtime_get_window_mgr ();
1485 header_view = get_header_view_from_window (MODEST_WINDOW (win));
1486 if (header_view == NULL)
1489 /* Get the account */
1490 account = get_account_from_header (header);
1495 found = modest_window_mgr_find_registered_header (mgr, header, &window);
1497 /* Do not open again the message and present the
1498 window to the user */
1501 #ifndef MODEST_TOOLKIT_HILDON2
1502 gtk_window_present (GTK_WINDOW (window));
1505 /* the header has been registered already, we don't do
1506 * anything but wait for the window to come up*/
1507 g_debug ("header %p already registered, waiting for window", header);
1512 /* Open each message */
1513 cached = tny_header_get_flags (header) & TNY_HEADER_FLAG_CACHED;
1515 /* Allways download if we are online. */
1516 if (!tny_device_is_online (modest_runtime_get_device ())) {
1519 /* If ask for user permission to download the messages */
1520 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
1521 _("mcen_nc_get_msg"));
1523 /* End if the user does not want to continue */
1524 if (response == GTK_RESPONSE_CANCEL) {
1530 /* We register the window for opening */
1531 modest_window_mgr_register_header (mgr, header, NULL);
1533 /* Create the helper. We need to get a reference to the model
1534 here because it could change while the message is readed
1535 (the user could switch between folders) */
1536 helper = g_slice_new (OpenMsgHelper);
1537 helper->model = g_object_ref (gtk_tree_view_get_model (GTK_TREE_VIEW (header_view)));
1538 helper->caller_window = win;
1539 g_object_weak_ref ((GObject *) helper->caller_window, (GWeakNotify) caller_win_destroyed, helper);
1540 helper->header = g_object_ref (header);
1541 helper->rowref = gtk_tree_row_reference_copy (rowref);
1542 helper->banner_info = NULL;
1544 /* Connect to the account and perform */
1546 modest_platform_connect_and_perform ((GtkWindow *) win, TRUE, g_object_ref (account),
1547 open_msg_performer, helper);
1549 /* Call directly the performer, do not need to connect */
1550 open_msg_performer (FALSE, NULL, (GtkWindow *) win,
1551 g_object_ref (account), helper);
1556 g_object_unref (account);
1560 modest_ui_actions_on_open (GtkAction *action, ModestWindow *win)
1567 /* we check for low-mem; in that case, show a warning, and don't allow
1570 if (modest_platform_check_memory_low (MODEST_WINDOW(win), TRUE))
1574 headers = get_selected_headers (win);
1578 headers_count = tny_list_get_length (headers);
1579 if (headers_count != 1) {
1580 if (headers_count > 1) {
1581 /* Don't allow activation if there are more than one message selected */
1582 modest_platform_information_banner (NULL, NULL, _("mcen_ib_select_one_message"));
1585 g_object_unref (headers);
1589 iter = tny_list_create_iterator (headers);
1590 header = TNY_HEADER (tny_iterator_get_current (iter));
1591 g_object_unref (iter);
1595 open_msg_from_header (header, NULL, win);
1596 g_object_unref (header);
1599 g_object_unref(headers);
1603 rf_helper_window_closed (gpointer data,
1606 ReplyForwardHelper *helper = (ReplyForwardHelper *) data;
1608 helper->parent_window = NULL;
1611 static ReplyForwardHelper*
1612 create_reply_forward_helper (ReplyForwardAction action,
1614 guint reply_forward_type,
1617 ReplyForwardHelper *rf_helper = NULL;
1618 const gchar *active_acc = modest_window_get_active_account (win);
1619 const gchar *active_mailbox = modest_window_get_active_mailbox (win);
1621 rf_helper = g_slice_new0 (ReplyForwardHelper);
1622 rf_helper->reply_forward_type = reply_forward_type;
1623 rf_helper->action = action;
1624 rf_helper->parent_window = (MODEST_IS_WINDOW (win)) ? GTK_WIDGET (win) : NULL;
1625 rf_helper->header = (header) ? g_object_ref (header) : NULL;
1626 rf_helper->account_name = (active_acc) ?
1627 g_strdup (active_acc) :
1628 modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
1629 rf_helper->mailbox = g_strdup (active_mailbox);
1631 /* Note that window could be destroyed just AFTER calling
1632 register_window so we must ensure that this pointer does
1633 not hold invalid references */
1634 if (rf_helper->parent_window)
1635 g_object_weak_ref (G_OBJECT (rf_helper->parent_window),
1636 rf_helper_window_closed, rf_helper);
1642 free_reply_forward_helper (gpointer data)
1644 ReplyForwardHelper *helper;
1646 helper = (ReplyForwardHelper *) data;
1647 g_free (helper->account_name);
1648 g_free (helper->mailbox);
1650 g_object_unref (helper->header);
1651 if (helper->parent_window)
1652 g_object_weak_unref (G_OBJECT (helper->parent_window),
1653 rf_helper_window_closed, helper);
1654 g_slice_free (ReplyForwardHelper, helper);
1658 reply_forward_cb (ModestMailOperation *mail_op,
1665 TnyMsg *new_msg = NULL;
1666 ReplyForwardHelper *rf_helper;
1667 ModestWindow *msg_win = NULL;
1668 ModestEditType edit_type;
1670 TnyAccount *account = NULL;
1671 ModestWindowMgr *mgr = NULL;
1672 gchar *signature = NULL;
1673 gboolean use_signature;
1676 /* If there was any error. The mail operation could be NULL,
1677 this means that we already have the message downloaded and
1678 that we didn't do a mail operation to retrieve it */
1679 rf_helper = (ReplyForwardHelper *) user_data;
1680 if (mail_op && !modest_ui_actions_msg_retrieval_check (mail_op, header, msg))
1683 from = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(),
1684 rf_helper->account_name, rf_helper->mailbox);
1685 recipient = modest_text_utils_get_email_address (from);
1686 signature = modest_account_mgr_get_signature_from_recipient (modest_runtime_get_account_mgr(),
1691 /* Create reply mail */
1692 switch (rf_helper->action) {
1693 /* Use the msg_header to ensure that we have all the
1694 information. The summary can lack some data */
1695 TnyHeader *msg_header;
1697 msg_header = tny_msg_get_header (msg);
1699 modest_tny_msg_create_reply_msg (msg, msg_header, from,
1700 (use_signature) ? signature : NULL,
1701 rf_helper->reply_forward_type,
1702 MODEST_TNY_MSG_REPLY_MODE_SENDER);
1703 g_object_unref (msg_header);
1705 case ACTION_REPLY_TO_ALL:
1706 msg_header = tny_msg_get_header (msg);
1708 modest_tny_msg_create_reply_msg (msg, msg_header, from,
1709 (use_signature) ? signature : NULL,
1710 rf_helper->reply_forward_type,
1711 MODEST_TNY_MSG_REPLY_MODE_ALL);
1712 edit_type = MODEST_EDIT_TYPE_REPLY;
1713 g_object_unref (msg_header);
1715 case ACTION_FORWARD:
1717 modest_tny_msg_create_forward_msg (msg, from, (use_signature) ? signature : NULL,
1718 rf_helper->reply_forward_type);
1719 edit_type = MODEST_EDIT_TYPE_FORWARD;
1722 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (),
1724 g_return_if_reached ();
1732 g_warning ("%s: failed to create message\n", __FUNCTION__);
1736 account = modest_tny_account_store_get_server_account (modest_runtime_get_account_store(),
1737 rf_helper->account_name,
1738 TNY_ACCOUNT_TYPE_STORE);
1740 g_warning ("%s: failed to get tnyaccount for '%s'\n", __FUNCTION__, rf_helper->account_name);
1744 /* Create and register the windows */
1745 msg_win = modest_msg_edit_window_new (new_msg, rf_helper->account_name, rf_helper->mailbox, FALSE);
1746 mgr = modest_runtime_get_window_mgr ();
1747 modest_window_mgr_register_window (mgr, msg_win, (ModestWindow *) rf_helper->parent_window);
1749 /* Note that register_window could have deleted the account */
1750 if (MODEST_IS_WINDOW (rf_helper->parent_window)) {
1751 gdouble parent_zoom;
1753 parent_zoom = modest_window_get_zoom (MODEST_WINDOW (rf_helper->parent_window));
1754 modest_window_set_zoom (msg_win, parent_zoom);
1757 /* Show edit window */
1758 gtk_widget_show_all (GTK_WIDGET (msg_win));
1761 /* We always unregister the header because the message is
1762 forwarded or replied so the original one is no longer
1764 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (),
1767 g_object_unref (G_OBJECT (new_msg));
1769 g_object_unref (G_OBJECT (account));
1770 free_reply_forward_helper (rf_helper);
1773 /* Checks a list of headers. If any of them are not currently
1774 * downloaded (CACHED) then returns TRUE else returns FALSE.
1777 header_list_count_uncached_msgs (TnyList *header_list)
1780 gint uncached_messages = 0;
1782 iter = tny_list_create_iterator (header_list);
1783 while (!tny_iterator_is_done (iter)) {
1786 header = TNY_HEADER (tny_iterator_get_current (iter));
1788 if (!(tny_header_get_flags (header) & TNY_HEADER_FLAG_CACHED))
1789 uncached_messages ++;
1790 g_object_unref (header);
1793 tny_iterator_next (iter);
1795 g_object_unref (iter);
1797 return uncached_messages;
1800 /* Returns FALSE if the user does not want to download the
1801 * messages. Returns TRUE if the user allowed the download.
1804 connect_to_get_msg (ModestWindow *win,
1805 gint num_of_uncached_msgs,
1806 TnyAccount *account)
1808 GtkResponseType response;
1810 /* Allways download if we are online. */
1811 if (tny_device_is_online (modest_runtime_get_device ()))
1814 /* If offline, then ask for user permission to download the messages */
1815 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
1816 ngettext("mcen_nc_get_msg",
1818 num_of_uncached_msgs));
1820 if (response == GTK_RESPONSE_CANCEL)
1823 return modest_platform_connect_and_wait((GtkWindow *) win, account);
1827 reply_forward_performer (gboolean canceled,
1829 GtkWindow *parent_window,
1830 TnyAccount *account,
1833 ReplyForwardHelper *rf_helper = NULL;
1834 ModestMailOperation *mail_op;
1836 rf_helper = (ReplyForwardHelper *) user_data;
1838 if (canceled || err) {
1839 free_reply_forward_helper (rf_helper);
1843 /* Retrieve the message */
1844 modest_window_mgr_register_header (modest_runtime_get_window_mgr (), rf_helper->header, NULL);
1845 mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT (parent_window),
1846 modest_ui_actions_disk_operations_error_handler,
1848 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
1849 modest_mail_operation_get_msg (mail_op, rf_helper->header, TRUE, reply_forward_cb, rf_helper);
1852 g_object_unref(mail_op);
1856 * Common code for the reply and forward actions
1859 reply_forward (ReplyForwardAction action, ModestWindow *win)
1861 ReplyForwardHelper *rf_helper = NULL;
1862 guint reply_forward_type;
1864 g_return_if_fail (win && MODEST_IS_WINDOW(win));
1866 /* we check for low-mem; in that case, show a warning, and don't allow
1867 * reply/forward (because it could potentially require a lot of memory */
1868 if (modest_platform_check_memory_low (MODEST_WINDOW(win), TRUE))
1872 /* we need an account when editing */
1873 if (!modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE)) {
1874 if (!modest_ui_actions_run_account_setup_wizard (win))
1878 reply_forward_type =
1879 modest_conf_get_int (modest_runtime_get_conf (),
1880 (action == ACTION_FORWARD) ?
1881 MODEST_CONF_FORWARD_TYPE :
1882 MODEST_CONF_REPLY_TYPE,
1885 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
1887 TnyHeader *header = NULL;
1888 /* Get header and message. Do not free them here, the
1889 reply_forward_cb must do it */
1890 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW(win));
1891 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
1893 if (msg && header) {
1895 rf_helper = create_reply_forward_helper (action, win,
1896 reply_forward_type, header);
1897 reply_forward_cb (NULL, header, FALSE, msg, NULL, rf_helper);
1899 g_warning("%s: no message or header found in viewer\n", __FUNCTION__);
1903 g_object_unref (msg);
1905 g_object_unref (header);
1907 TnyHeader *header = NULL;
1909 gboolean do_retrieve = TRUE;
1910 TnyList *header_list = NULL;
1912 header_list = get_selected_headers (win);
1915 /* Check that only one message is selected for replying */
1916 if (tny_list_get_length (header_list) != 1) {
1917 modest_platform_information_banner ((win) ? GTK_WIDGET (win) : NULL,
1918 NULL, _("mcen_ib_select_one_message"));
1919 g_object_unref (header_list);
1923 /* Only reply/forward to one message */
1924 iter = tny_list_create_iterator (header_list);
1925 header = TNY_HEADER (tny_iterator_get_current (iter));
1926 g_object_unref (iter);
1928 /* Retrieve messages */
1929 do_retrieve = (action == ACTION_FORWARD) ||
1930 (reply_forward_type != MODEST_TNY_MSG_REPLY_TYPE_CITE);
1933 TnyAccount *account = NULL;
1934 TnyFolder *folder = NULL;
1935 gdouble download = TRUE;
1936 guint uncached_msgs = 0;
1938 folder = tny_header_get_folder (header);
1940 goto do_retrieve_frees;
1941 account = tny_folder_get_account (folder);
1943 goto do_retrieve_frees;
1945 uncached_msgs = header_list_count_uncached_msgs (header_list);
1947 if (uncached_msgs > 0) {
1948 /* Allways download if we are online. */
1949 if (!tny_device_is_online (modest_runtime_get_device ())) {
1952 /* If ask for user permission to download the messages */
1953 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
1954 ngettext("mcen_nc_get_msg",
1958 /* End if the user does not want to continue */
1959 if (response == GTK_RESPONSE_CANCEL)
1966 rf_helper = create_reply_forward_helper (action, win,
1967 reply_forward_type, header);
1968 if (uncached_msgs > 0) {
1969 modest_platform_connect_and_perform (GTK_WINDOW (win),
1971 reply_forward_performer,
1974 reply_forward_performer (FALSE, NULL, GTK_WINDOW (win),
1975 account, rf_helper);
1980 g_object_unref (account);
1982 g_object_unref (folder);
1984 reply_forward_cb (NULL, header, FALSE, NULL, NULL, NULL);
1987 g_object_unref (header_list);
1988 g_object_unref (header);
1993 modest_ui_actions_on_reply (GtkAction *action, ModestWindow *win)
1995 g_return_if_fail (MODEST_IS_WINDOW(win));
1997 reply_forward (ACTION_REPLY, win);
2001 modest_ui_actions_on_forward (GtkAction *action, ModestWindow *win)
2003 g_return_if_fail (MODEST_IS_WINDOW(win));
2005 reply_forward (ACTION_FORWARD, win);
2009 modest_ui_actions_on_reply_all (GtkAction *action, ModestWindow *win)
2011 g_return_if_fail (MODEST_IS_WINDOW(win));
2013 reply_forward (ACTION_REPLY_TO_ALL, win);
2017 modest_ui_actions_on_next (GtkAction *action,
2018 ModestWindow *window)
2020 #ifndef MODEST_TOOLKIT_HILDON2
2021 if (MODEST_IS_MAIN_WINDOW (window)) {
2022 GtkWidget *header_view;
2024 header_view = modest_main_window_get_child_widget (
2025 MODEST_MAIN_WINDOW(window),
2026 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2030 modest_header_view_select_next (
2031 MODEST_HEADER_VIEW(header_view));
2033 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
2034 modest_msg_view_window_select_next_message (
2035 MODEST_MSG_VIEW_WINDOW (window));
2038 g_return_if_reached ();
2043 modest_ui_actions_on_prev (GtkAction *action,
2044 ModestWindow *window)
2046 g_return_if_fail (MODEST_IS_WINDOW(window));
2048 #ifndef MODEST_TOOLKIT_HILDON2
2049 if (MODEST_IS_MAIN_WINDOW (window)) {
2050 GtkWidget *header_view;
2051 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
2052 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2056 modest_header_view_select_prev (MODEST_HEADER_VIEW(header_view));
2058 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
2059 modest_msg_view_window_select_previous_message (MODEST_MSG_VIEW_WINDOW (window));
2062 g_return_if_reached ();
2067 modest_ui_actions_on_sort (GtkAction *action,
2068 ModestWindow *window)
2070 GtkWidget *header_view = NULL;
2072 g_return_if_fail (MODEST_IS_WINDOW(window));
2074 #ifndef MODEST_TOOLKIT_HILDON2
2075 if (MODEST_IS_MAIN_WINDOW (window)) {
2076 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
2077 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2079 if (MODEST_IS_HEADER_WINDOW (window)) {
2080 header_view = GTK_WIDGET (modest_header_window_get_header_view (MODEST_HEADER_WINDOW (window)));
2085 modest_platform_information_banner (NULL, NULL, _CS("ckdg_ib_nothing_to_sort"));
2090 /* Show sorting dialog */
2091 modest_utils_run_sort_dialog (GTK_WINDOW (window), MODEST_SORT_HEADERS);
2095 sync_folder_cb (ModestMailOperation *mail_op,
2099 ModestHeaderView *header_view = (ModestHeaderView *) user_data;
2101 if (modest_mail_operation_get_status (mail_op) == MODEST_MAIL_OPERATION_STATUS_SUCCESS) {
2102 ModestWindow *parent = (ModestWindow *) modest_mail_operation_get_source (mail_op);
2104 /* We must clear first, because otherwise set_folder will ignore */
2105 /* the change as the folders are the same */
2106 modest_header_view_clear (header_view);
2107 modest_header_view_set_folder (header_view, folder, TRUE, parent, NULL, NULL);
2109 g_object_unref (parent);
2112 g_object_unref (header_view);
2116 idle_refresh_folder (gpointer source)
2118 ModestHeaderView *header_view = NULL;
2120 /* If the window still exists */
2121 if (!GTK_IS_WIDGET (source) ||
2122 !GTK_WIDGET_VISIBLE (source))
2125 /* Refresh the current view */
2126 #ifdef MODEST_TOOLKIT_HILDON2
2127 if (MODEST_IS_HEADER_WINDOW (source))
2128 header_view = modest_header_window_get_header_view ((ModestHeaderWindow *) source);
2130 if (MODEST_IS_MAIN_WINDOW (source))
2131 header_view = MODEST_HEADER_VIEW (modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (source),
2132 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW));
2135 TnyFolder *folder = modest_header_view_get_folder (header_view);
2137 /* Sync the folder status */
2138 ModestMailOperation *mail_op = modest_mail_operation_new (source);
2139 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
2140 modest_mail_operation_sync_folder (mail_op, folder, FALSE, sync_folder_cb, g_object_ref (header_view));
2141 g_object_unref (folder);
2142 g_object_unref (mail_op);
2150 update_account_cb (ModestMailOperation *self,
2151 TnyList *new_headers,
2155 gboolean show_visual_notifications;
2157 top = modest_window_mgr_get_current_top (modest_runtime_get_window_mgr ());
2158 show_visual_notifications = (top) ? FALSE : TRUE;
2160 /* Notify new messages have been downloaded. If the
2161 send&receive was invoked by the user then do not show any
2162 visual notification, only play a sound and activate the LED
2163 (for the Maemo version) */
2164 if (TNY_IS_LIST(new_headers) && (tny_list_get_length (new_headers)) > 0) {
2166 /* We only notify about really new messages (not seen) we get */
2167 TnyList *actually_new_list;
2168 TnyIterator *iterator;
2169 actually_new_list = TNY_LIST (tny_simple_list_new ());
2170 for (iterator = tny_list_create_iterator (new_headers);
2171 !tny_iterator_is_done (iterator);
2172 tny_iterator_next (iterator)) {
2174 TnyHeaderFlags flags;
2175 header = TNY_HEADER (tny_iterator_get_current (iterator));
2176 flags = tny_header_get_flags (header);
2178 if (!(flags & TNY_HEADER_FLAG_SEEN)) {
2179 /* Messages are ordered from most
2180 recent to oldest. But we want to
2181 show notifications starting from
2182 the oldest message. That's why we
2184 tny_list_prepend (actually_new_list, G_OBJECT (header));
2186 g_object_unref (header);
2188 g_object_unref (iterator);
2190 if (tny_list_get_length (actually_new_list) > 0) {
2191 GList *new_headers_list = NULL;
2193 new_headers_list = modest_utils_create_notification_list_from_header_list (actually_new_list);
2195 /* Send notifications */
2196 if (new_headers_list) {
2197 modest_platform_on_new_headers_received (new_headers_list,
2198 show_visual_notifications);
2200 modest_utils_free_notification_list (new_headers_list);
2203 g_object_unref (actually_new_list);
2207 /* Refresh the current folder in an idle. We do this
2208 in order to avoid refresh cancelations if the
2209 currently viewed folder is the inbox */
2210 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
2211 idle_refresh_folder,
2218 TnyAccount *account;
2220 gchar *account_name;
2221 gboolean poke_status;
2222 gboolean interactive;
2223 ModestMailOperation *mail_op;
2227 do_send_receive_performer (gboolean canceled,
2229 GtkWindow *parent_window,
2230 TnyAccount *account,
2233 SendReceiveInfo *info;
2235 info = (SendReceiveInfo *) user_data;
2237 if (err || canceled) {
2238 /* In disk full conditions we could get this error here */
2239 modest_tny_account_store_check_disk_full_error (modest_runtime_get_account_store(),
2240 (GtkWidget *) parent_window, err,
2243 if (info->mail_op) {
2244 modest_mail_operation_queue_remove (modest_runtime_get_mail_operation_queue (),
2250 #ifndef MODEST_TOOLKIT_HILDON2
2251 /* Set send/receive operation in progress */
2252 if (info->win && MODEST_IS_MAIN_WINDOW (info->win)) {
2253 modest_main_window_notify_send_receive_initied (MODEST_MAIN_WINDOW (info->win));
2256 if (info->win && MODEST_IS_MAIN_WINDOW (info->win))
2257 g_signal_connect (G_OBJECT (info->mail_op), "operation-finished",
2258 G_CALLBACK (on_send_receive_finished),
2262 /* Send & receive. */
2263 modest_mail_operation_update_account (info->mail_op, info->account_name,
2264 info->poke_status, info->interactive,
2265 update_account_cb, info->win);
2270 g_object_unref (G_OBJECT (info->mail_op));
2271 if (info->account_name)
2272 g_free (info->account_name);
2274 g_object_unref (info->win);
2276 g_object_unref (info->account);
2277 g_slice_free (SendReceiveInfo, info);
2281 * This function performs the send & receive required actions. The
2282 * window is used to create the mail operation. Typically it should
2283 * always be the main window, but we pass it as argument in order to
2287 modest_ui_actions_do_send_receive (const gchar *account_name,
2288 gboolean force_connection,
2289 gboolean poke_status,
2290 gboolean interactive,
2293 gchar *acc_name = NULL;
2294 SendReceiveInfo *info;
2295 ModestTnyAccountStore *acc_store;
2296 TnyAccount *account;
2298 /* If no account name was provided then get the current account, and if
2299 there is no current account then pick the default one: */
2300 if (!account_name) {
2302 acc_name = g_strdup (modest_window_get_active_account (win));
2304 acc_name = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
2306 modest_platform_information_banner (NULL, NULL, _("emev_ni_internal_error"));
2310 acc_name = g_strdup (account_name);
2313 acc_store = modest_runtime_get_account_store ();
2314 account = modest_tny_account_store_get_server_account (acc_store, acc_name, TNY_ACCOUNT_TYPE_STORE);
2318 modest_platform_information_banner (NULL, NULL, _("emev_ni_internal_error"));
2322 /* Do not automatically refresh accounts that are flagged as
2323 NO_AUTO_UPDATE. This could be useful for accounts that
2324 handle their own update times */
2326 ModestProtocolType proto = modest_tny_account_get_protocol_type (account);
2327 if (proto != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
2328 const gchar *tag = MODEST_PROTOCOL_REGISTRY_NO_AUTO_UPDATE_PROTOCOLS;
2329 ModestProtocolRegistry *registry = modest_runtime_get_protocol_registry ();
2331 if (modest_protocol_registry_protocol_type_has_tag (registry, proto, tag)) {
2332 g_debug ("%s no auto update allowed for account %s", __FUNCTION__, account_name);
2333 g_object_unref (account);
2340 /* Create the info for the connect and perform */
2341 info = g_slice_new (SendReceiveInfo);
2342 info->account_name = acc_name;
2343 info->win = (win) ? g_object_ref (win) : NULL;
2344 info->poke_status = poke_status;
2345 info->interactive = interactive;
2346 info->account = account;
2347 /* We need to create the operation here, because otherwise it
2348 could happen that the queue emits the queue-empty signal
2349 while we're trying to connect the account */
2350 info->mail_op = modest_mail_operation_new_with_error_handling ((info->win) ? G_OBJECT (info->win) : NULL,
2351 modest_ui_actions_disk_operations_error_handler,
2353 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), info->mail_op);
2355 /* Invoke the connect and perform */
2356 modest_platform_connect_and_perform ((win) ? GTK_WINDOW (win) : NULL,
2357 force_connection, info->account,
2358 do_send_receive_performer, info);
2363 modest_ui_actions_do_cancel_send (const gchar *account_name,
2366 TnyTransportAccount *transport_account;
2367 TnySendQueue *send_queue = NULL;
2368 GError *error = NULL;
2370 /* Get transport account */
2372 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
2373 (modest_runtime_get_account_store(),
2375 TNY_ACCOUNT_TYPE_TRANSPORT));
2376 if (!transport_account) {
2377 g_printerr ("modest: no transport account found for '%s'\n", account_name);
2382 send_queue = TNY_SEND_QUEUE (modest_runtime_get_send_queue (transport_account, TRUE));
2383 if (!TNY_IS_SEND_QUEUE(send_queue)) {
2384 g_set_error (&error, MODEST_MAIL_OPERATION_ERROR,
2385 MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND,
2386 "modest: could not find send queue for account\n");
2388 /* Cancel the current send */
2389 tny_account_cancel (TNY_ACCOUNT (transport_account));
2391 /* Suspend all pending messages */
2392 tny_send_queue_cancel (send_queue, TNY_SEND_QUEUE_CANCEL_ACTION_SUSPEND, &error);
2396 if (transport_account != NULL)
2397 g_object_unref (G_OBJECT (transport_account));
2401 modest_ui_actions_cancel_send_all (ModestWindow *win)
2403 GSList *account_names, *iter;
2405 account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
2408 iter = account_names;
2410 modest_ui_actions_do_cancel_send ((const char*) iter->data, win);
2411 iter = g_slist_next (iter);
2414 modest_account_mgr_free_account_names (account_names);
2415 account_names = NULL;
2419 modest_ui_actions_cancel_send (GtkAction *action, ModestWindow *win)
2422 /* Check if accounts exist */
2423 gboolean accounts_exist =
2424 modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
2426 /* If not, allow the user to create an account before trying to send/receive. */
2427 if (!accounts_exist)
2428 modest_ui_actions_on_accounts (NULL, win);
2430 /* Cancel all sending operaitons */
2431 modest_ui_actions_cancel_send_all (win);
2435 * Refreshes all accounts. This function will be used by automatic
2439 modest_ui_actions_do_send_receive_all (ModestWindow *win,
2440 gboolean force_connection,
2441 gboolean poke_status,
2442 gboolean interactive)
2444 GSList *account_names, *iter;
2446 account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
2449 iter = account_names;
2451 modest_ui_actions_do_send_receive ((const char*) iter->data,
2453 poke_status, interactive, win);
2454 iter = g_slist_next (iter);
2457 modest_account_mgr_free_account_names (account_names);
2458 account_names = NULL;
2462 * Handler of the click on Send&Receive button in the main toolbar
2465 modest_ui_actions_on_send_receive (GtkAction *action, ModestWindow *win)
2467 /* Check if accounts exist */
2468 gboolean accounts_exist;
2471 modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
2473 /* If not, allow the user to create an account before trying to send/receive. */
2474 if (!accounts_exist)
2475 modest_ui_actions_on_accounts (NULL, win);
2477 /* Refresh the current folder. The if is always TRUE it's just an extra check */
2478 #ifndef MODEST_TOOLKIT_HILDON2
2479 if (MODEST_IS_MAIN_WINDOW (win)) {
2480 GtkWidget *folder_view;
2481 TnyFolderStore *folder_store;
2484 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
2485 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2489 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
2492 g_object_unref (folder_store);
2493 /* Refresh the active account. Force the connection if needed
2494 and poke the status of all folders */
2495 modest_ui_actions_do_send_receive (NULL, TRUE, TRUE, TRUE, win);
2497 if (MODEST_IS_ACCOUNTS_WINDOW (win)) {
2498 modest_ui_actions_do_send_receive_all (win, TRUE, TRUE, TRUE);
2501 const gchar *active_account;
2502 active_account = modest_window_get_active_account (MODEST_WINDOW (win));
2504 modest_ui_actions_do_send_receive (active_account, TRUE, TRUE, TRUE, win);
2509 #ifndef MODEST_TOOLKIT_HILDON2
2511 modest_ui_actions_toggle_header_list_view (GtkAction *action, ModestMainWindow *main_window)
2514 GtkWidget *header_view;
2516 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2518 header_view = modest_main_window_get_child_widget (main_window,
2519 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2523 conf = modest_runtime_get_conf ();
2525 /* what is saved/restored is depending on the style; thus; we save with
2526 * old style, then update the style, and restore for this new style
2528 modest_widget_memory_save (conf, G_OBJECT(header_view), MODEST_CONF_HEADER_VIEW_KEY);
2530 if (modest_header_view_get_style
2531 (MODEST_HEADER_VIEW(header_view)) == MODEST_HEADER_VIEW_STYLE_DETAILS)
2532 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
2533 MODEST_HEADER_VIEW_STYLE_TWOLINES);
2535 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
2536 MODEST_HEADER_VIEW_STYLE_DETAILS);
2538 modest_widget_memory_restore (conf, G_OBJECT(header_view),
2539 MODEST_CONF_HEADER_VIEW_KEY);
2543 modest_ui_actions_on_header_selected (ModestHeaderView *header_view,
2545 ModestMainWindow *main_window)
2547 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2548 g_return_if_fail (MODEST_IS_HEADER_VIEW (header_view));
2550 /* in the case the folder is empty, show the empty folder message and focus
2552 if (!header && gtk_widget_is_focus (GTK_WIDGET (header_view))) {
2553 if (modest_header_view_is_empty (header_view)) {
2554 TnyFolder *folder = modest_header_view_get_folder (header_view);
2555 GtkWidget *folder_view =
2556 modest_main_window_get_child_widget (main_window,
2557 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2558 if (folder != NULL) {
2559 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view), folder, FALSE);
2560 g_object_unref (folder);
2562 gtk_widget_grab_focus (GTK_WIDGET (folder_view));
2566 /* If no header has been selected then exit */
2571 if (!gtk_widget_is_focus (GTK_WIDGET(header_view)))
2572 gtk_widget_grab_focus (GTK_WIDGET(header_view));
2574 /* Update toolbar dimming state */
2575 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (main_window));
2576 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
2581 modest_ui_actions_on_header_activated (ModestHeaderView *header_view,
2584 ModestWindow *window)
2586 GtkTreeRowReference *rowref;
2588 g_return_if_fail (MODEST_IS_WINDOW(window));
2589 g_return_if_fail (MODEST_IS_HEADER_VIEW (header_view));
2590 g_return_if_fail (TNY_IS_HEADER (header));
2592 if (modest_header_view_count_selected_headers (header_view) > 1) {
2593 /* Don't allow activation if there are more than one message selected */
2594 modest_platform_information_banner (NULL, NULL, _("mcen_ib_select_one_message"));
2598 /* we check for low-mem; in that case, show a warning, and don't allow
2599 * activating headers
2601 if (modest_platform_check_memory_low (MODEST_WINDOW(window), TRUE))
2604 #ifndef MODEST_TOOLKIT_HILDON2
2605 GtkWidget *open_widget;
2606 if (MODEST_IS_MAIN_WINDOW (window)) {
2607 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (window));
2608 open_widget = modest_window_get_action_widget (MODEST_WINDOW (window), "/MenuBar/EmailMenu/EmailOpenMenu");
2609 if (!GTK_WIDGET_IS_SENSITIVE (open_widget))
2614 rowref = gtk_tree_row_reference_new (gtk_tree_view_get_model (GTK_TREE_VIEW (header_view)), path);
2615 open_msg_from_header (header, rowref, MODEST_WINDOW (window));
2616 gtk_tree_row_reference_free (rowref);
2619 #ifndef MODEST_TOOLKIT_HILDON2
2621 set_active_account_from_tny_account (TnyAccount *account,
2622 ModestWindow *window)
2624 const gchar *server_acc_name = tny_account_get_id (account);
2626 /* We need the TnyAccount provided by the
2627 account store because that is the one that
2628 knows the name of the Modest account */
2629 TnyAccount *modest_server_account =
2630 modest_tny_account_store_get_tny_account_by (modest_runtime_get_account_store (),
2631 MODEST_TNY_ACCOUNT_STORE_QUERY_ID,
2633 if (!modest_server_account) {
2634 g_warning ("%s: could not get tny account\n", __FUNCTION__);
2638 /* Update active account, but only if it's not a pseudo-account */
2639 if ((!modest_tny_account_is_virtual_local_folders(modest_server_account)) &&
2640 (!modest_tny_account_is_memory_card_account(modest_server_account))) {
2641 const gchar *modest_acc_name =
2642 modest_tny_account_get_parent_modest_account_name_for_server_account (modest_server_account);
2643 if (modest_acc_name)
2644 modest_window_set_active_account (window, modest_acc_name);
2647 g_object_unref (modest_server_account);
2651 folder_refreshed_cb (ModestMailOperation *mail_op,
2655 ModestMainWindow *win = NULL;
2656 GtkWidget *folder_view, *header_view;
2657 const GError *error;
2659 g_return_if_fail (TNY_IS_FOLDER (folder));
2661 win = MODEST_MAIN_WINDOW (user_data);
2663 /* Check if the operation failed due to memory low conditions */
2664 error = modest_mail_operation_get_error (mail_op);
2665 if (error && error->domain == MODEST_MAIL_OPERATION_ERROR &&
2666 error->code == MODEST_MAIL_OPERATION_ERROR_LOW_MEMORY) {
2667 modest_platform_run_information_dialog (GTK_WINDOW (win),
2668 _KR("memr_ib_operation_disabled"),
2674 modest_main_window_get_child_widget(win, MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2676 modest_main_window_get_child_widget(win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2679 TnyFolderStore *current_folder;
2681 current_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
2682 if (current_folder) {
2683 gboolean different = ((TnyFolderStore *) folder != current_folder);
2684 g_object_unref (current_folder);
2690 /* Check if folder is empty and set headers view contents style */
2691 if ((tny_folder_get_all_count (folder) == 0) ||
2692 modest_header_view_is_empty (MODEST_HEADER_VIEW (header_view)))
2693 modest_main_window_set_contents_style (win,
2694 MODEST_MAIN_WINDOW_CONTENTS_STYLE_EMPTY);
2698 modest_ui_actions_on_folder_selection_changed (ModestFolderView *folder_view,
2699 TnyFolderStore *folder_store,
2701 ModestMainWindow *main_window)
2703 GtkWidget *header_view;
2705 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2707 header_view = modest_main_window_get_child_widget(main_window,
2708 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2713 if (TNY_IS_ACCOUNT (folder_store)) {
2715 set_active_account_from_tny_account (TNY_ACCOUNT (folder_store), MODEST_WINDOW (main_window));
2717 /* Show account details */
2718 modest_main_window_set_contents_style (main_window, MODEST_MAIN_WINDOW_CONTENTS_STYLE_DETAILS);
2721 if (TNY_IS_FOLDER (folder_store) && selected) {
2722 TnyAccount *account;
2724 /* Update the active account */
2725 account = modest_tny_folder_get_account (TNY_FOLDER (folder_store));
2727 set_active_account_from_tny_account (account, MODEST_WINDOW (main_window));
2728 g_object_unref (account);
2732 /* Set the header style by default, it could
2733 be changed later by the refresh callback to
2735 modest_main_window_set_contents_style (main_window,
2736 MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS);
2738 /* Set folder on header view. This function
2739 will call tny_folder_refresh_async so we
2740 pass a callback that will be called when
2741 finished. We use that callback to set the
2742 empty view if there are no messages */
2743 modest_header_view_set_folder (MODEST_HEADER_VIEW(header_view),
2744 TNY_FOLDER (folder_store),
2746 MODEST_WINDOW (main_window),
2747 folder_refreshed_cb,
2750 /* Restore configuration. We need to do this
2751 *after* the set_folder because the widget
2752 memory asks the header view about its
2754 modest_widget_memory_restore (modest_runtime_get_conf (),
2755 G_OBJECT(header_view),
2756 MODEST_CONF_HEADER_VIEW_KEY);
2758 /* No need to save the header view
2759 configuration for Maemo because it only
2760 saves the sorting stuff and that it's
2761 already being done by the sort
2762 dialog. Remove it when the GNOME version
2763 has the same behaviour */
2764 #ifdef MODEST_TOOLKIT_GTK
2765 if (modest_main_window_get_contents_style (main_window) ==
2766 MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS)
2767 modest_widget_memory_save (modest_runtime_get_conf (),
2768 G_OBJECT (header_view),
2769 MODEST_CONF_HEADER_VIEW_KEY);
2771 modest_header_view_clear (MODEST_HEADER_VIEW(header_view));
2775 /* Update dimming state */
2776 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (main_window));
2777 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
2782 modest_ui_actions_on_item_not_found (ModestHeaderView *header_view,ModestItemType type,
2789 item = (type == MODEST_ITEM_TYPE_FOLDER) ? "folder" : "message";
2791 online = tny_device_is_online (modest_runtime_get_device());
2794 /* already online -- the item is simply not there... */
2795 dialog = gtk_message_dialog_new (GTK_WINDOW (win),
2797 GTK_MESSAGE_WARNING,
2799 _("The %s you selected cannot be found"),
2801 gtk_dialog_add_button (GTK_DIALOG (dialog),_("mcen_bd_dialog_ok"), GTK_RESPONSE_ACCEPT);
2802 gtk_dialog_run (GTK_DIALOG(dialog));
2804 dialog = gtk_dialog_new_with_buttons (_("Connection requested"),
2807 _("mcen_bd_dialog_cancel"),
2808 GTK_RESPONSE_REJECT,
2809 _("mcen_bd_dialog_ok"),
2810 GTK_RESPONSE_ACCEPT,
2812 txt = g_strdup_printf (_("This %s is not available in offline mode.\n"
2813 "Do you want to get online?"), item);
2814 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
2815 gtk_label_new (txt), FALSE, FALSE, 0);
2816 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
2819 gtk_window_set_default_size (GTK_WINDOW(dialog), 300, 300);
2820 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
2821 /* TODO: Comment about why is this commented out: */
2822 /* modest_platform_connect_and_wait (); */
2825 gtk_widget_destroy (dialog);
2829 modest_ui_actions_on_msg_link_hover (ModestMsgView *msgview, const gchar* link,
2832 /* g_debug ("%s %s", __FUNCTION__, link); */
2837 modest_ui_actions_on_msg_link_clicked (ModestMsgView *msgview, const gchar* link,
2840 modest_platform_activate_uri (link);
2844 modest_ui_actions_on_msg_link_contextual (ModestMsgView *msgview, const gchar* link,
2847 modest_platform_show_uri_popup (link);
2851 modest_ui_actions_on_msg_attachment_clicked (ModestMsgView *msgview, TnyMimePart *mime_part,
2854 /* we check for low-mem; in that case, show a warning, and don't allow
2855 * viewing attachments
2857 if (modest_platform_check_memory_low (MODEST_WINDOW(win), TRUE))
2860 modest_msg_view_window_view_attachment (MODEST_MSG_VIEW_WINDOW (win), mime_part);
2864 modest_ui_actions_on_msg_recpt_activated (ModestMsgView *msgview,
2865 const gchar *address,
2868 /* g_debug ("%s %s", __FUNCTION__, address); */
2872 on_save_to_drafts_cb (ModestMailOperation *mail_op,
2873 TnyMsg *saved_draft,
2876 ModestMsgEditWindow *edit_window;
2878 /* TODO: in hildon 2 we have to dim and undim the header views while we're saving */
2879 #ifndef MODEST_TOOLKIT_HILDON2
2880 ModestMainWindow *win;
2882 /* FIXME. Make the header view sensitive again. This is a
2883 * temporary hack. See modest_ui_actions_on_save_to_drafts()
2885 win = MODEST_MAIN_WINDOW(modest_window_mgr_get_main_window(
2886 modest_runtime_get_window_mgr(), FALSE));
2888 GtkWidget *hdrview = modest_main_window_get_child_widget(
2889 win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2890 if (hdrview) gtk_widget_set_sensitive(hdrview, TRUE);
2894 edit_window = MODEST_MSG_EDIT_WINDOW (user_data);
2896 /* Set draft is there was no error */
2897 if (!modest_mail_operation_get_error (mail_op))
2898 modest_msg_edit_window_set_draft (edit_window, saved_draft);
2900 g_object_unref(edit_window);
2904 enough_space_for_message (ModestMsgEditWindow *edit_window,
2907 guint64 available_disk, expected_size;
2912 available_disk = modest_utils_get_available_space (NULL);
2913 modest_msg_edit_window_get_parts_size (edit_window, &parts_count, &parts_size);
2914 expected_size = modest_tny_msg_estimate_size (data->plain_body,
2919 /* Double check: disk full condition or message too big */
2920 if (available_disk < MODEST_TNY_ACCOUNT_STORE_MIN_FREE_SPACE ||
2921 expected_size > available_disk) {
2922 gchar *msg = g_strdup_printf (_KR("cerm_device_memory_full"), "");
2923 modest_platform_information_banner (NULL, NULL, msg);
2930 * djcb: if we're in low-memory state, we only allow for
2931 * saving messages smaller than
2932 * MODEST_MAX_LOW_MEMORY_MESSAGE_SIZE (see modest-defs.h) this
2933 * should still allow for sending anything critical...
2935 if ((expected_size > MODEST_MAX_LOW_MEMORY_MESSAGE_SIZE) &&
2936 modest_platform_check_memory_low (MODEST_WINDOW(edit_window), TRUE))
2940 * djcb: we also make sure that the attachments are smaller than the max size
2941 * this is for the case where we'd try to forward a message with attachments
2942 * bigger than our max allowed size, or sending an message from drafts which
2943 * somehow got past our checks when attaching.
2945 if (expected_size > MODEST_MAX_ATTACHMENT_SIZE) {
2946 modest_platform_run_information_dialog (
2947 GTK_WINDOW(edit_window),
2948 _("mail_ib_error_attachment_size"),
2957 modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edit_window)
2959 TnyTransportAccount *transport_account;
2960 ModestMailOperation *mail_operation;
2962 gchar *account_name;
2963 ModestAccountMgr *account_mgr;
2964 gboolean had_error = FALSE;
2966 g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window), FALSE);
2968 data = modest_msg_edit_window_get_msg_data (edit_window);
2971 if (!enough_space_for_message (edit_window, data)) {
2972 modest_msg_edit_window_free_msg_data (edit_window, data);
2976 account_name = g_strdup (data->account_name);
2977 account_mgr = modest_runtime_get_account_mgr();
2979 account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
2981 account_name = modest_account_mgr_get_default_account (account_mgr);
2982 if (!account_name) {
2983 g_printerr ("modest: no account found\n");
2984 modest_msg_edit_window_free_msg_data (edit_window, data);
2988 if (!strcmp (account_name, MODEST_LOCAL_FOLDERS_ACCOUNT_ID)) {
2989 account_name = g_strdup (data->account_name);
2993 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
2994 (modest_runtime_get_account_store (),
2996 TNY_ACCOUNT_TYPE_TRANSPORT));
2997 if (!transport_account) {
2998 g_printerr ("modest: no transport account found for '%s'\n", account_name);
2999 g_free (account_name);
3000 modest_msg_edit_window_free_msg_data (edit_window, data);
3004 /* Create the mail operation */
3005 mail_operation = modest_mail_operation_new_with_error_handling (NULL, modest_ui_actions_disk_operations_error_handler,
3007 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
3009 modest_mail_operation_save_to_drafts (mail_operation,
3021 data->priority_flags,
3024 on_save_to_drafts_cb,
3025 g_object_ref(edit_window));
3027 #ifdef MODEST_TOOLKIT_HILDON2
3028 /* In hildon2 we always show the information banner on saving to drafts.
3029 * It will be a system information banner in this case.
3031 gchar *text = g_strdup_printf (_("mail_va_saved_to_drafts"), _("mcen_me_folder_drafts"));
3032 modest_platform_information_banner (NULL, NULL, text);
3035 ModestMainWindow *win = NULL;
3037 /* Use the main window as the parent of the banner, if the
3038 main window does not exist it won't be shown, if the parent
3039 window exists then it's properly shown. We don't use the
3040 editor window because it could be closed (save to drafts
3041 could happen after closing the window */
3042 win = (ModestMainWindow *)
3043 modest_window_mgr_get_main_window( modest_runtime_get_window_mgr(), FALSE);
3045 gchar *text = g_strdup_printf (_("mail_va_saved_to_drafts"), _("mcen_me_folder_drafts"));
3046 modest_platform_information_banner (GTK_WIDGET (win), NULL, text);
3050 modest_msg_edit_window_set_modified (edit_window, FALSE);
3053 g_free (account_name);
3054 g_object_unref (G_OBJECT (transport_account));
3055 g_object_unref (G_OBJECT (mail_operation));
3057 modest_msg_edit_window_free_msg_data (edit_window, data);
3059 #ifndef MODEST_TOOLKIT_HILDON2
3061 * If the drafts folder is selected then make the header view
3062 * insensitive while the message is being saved to drafts
3063 * (it'll be sensitive again in on_save_to_drafts_cb()). This
3064 * is not very clean but it avoids letting the drafts folder
3065 * in an inconsistent state: the user could edit the message
3066 * being saved and undesirable things would happen.
3067 * In the average case the user won't notice anything at
3068 * all. In the worst case (the user is editing a really big
3069 * file from Drafts) the header view will be insensitive
3070 * during the saving process (10 or 20 seconds, depending on
3071 * the message). Anyway this is just a quick workaround: once
3072 * we find a better solution it should be removed
3073 * See NB#65125 (commend #18) for details.
3075 if (!had_error && win != NULL) {
3076 ModestFolderView *view = MODEST_FOLDER_VIEW(modest_main_window_get_child_widget(
3077 win, MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW));
3079 TnyFolder *folder = TNY_FOLDER(modest_folder_view_get_selected(view));
3081 if (modest_tny_folder_is_local_folder(folder)) {
3082 TnyFolderType folder_type;
3083 folder_type = modest_tny_folder_get_local_or_mmc_folder_type(folder);
3084 if (folder_type == TNY_FOLDER_TYPE_DRAFTS) {
3085 GtkWidget *hdrview = modest_main_window_get_child_widget(
3086 win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
3087 if (hdrview) gtk_widget_set_sensitive(hdrview, FALSE);
3091 if (folder != NULL) g_object_unref(folder);
3099 /* For instance, when clicking the Send toolbar button when editing a message: */
3101 modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
3103 TnyTransportAccount *transport_account = NULL;
3104 gboolean had_error = FALSE;
3106 ModestAccountMgr *account_mgr;
3107 gchar *account_name;
3108 ModestMailOperation *mail_operation;
3111 g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window), TRUE);
3113 /* Check names but do not automatically add them to addressbook */
3114 if (!modest_msg_edit_window_check_names (edit_window, FALSE))
3117 data = modest_msg_edit_window_get_msg_data (edit_window);
3119 recipients = g_strconcat (data->to?data->to:"",
3120 data->cc?data->cc:"",
3121 data->bcc?data->bcc:"",
3123 if (recipients == NULL || recipients[0] == '\0') {
3124 /* Empty subject -> no send */
3125 g_free (recipients);
3126 modest_msg_edit_window_free_msg_data (edit_window, data);
3129 g_free (recipients);
3132 if (!enough_space_for_message (edit_window, data)) {
3133 modest_msg_edit_window_free_msg_data (edit_window, data);
3137 account_mgr = modest_runtime_get_account_mgr();
3138 account_name = g_strdup (data->account_name);
3140 account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
3143 account_name = modest_account_mgr_get_default_account (account_mgr);
3145 if (!account_name) {
3146 modest_msg_edit_window_free_msg_data (edit_window, data);
3147 /* Run account setup wizard */
3148 if (!modest_ui_actions_run_account_setup_wizard (MODEST_WINDOW(edit_window))) {
3153 /* Get the currently-active transport account for this modest account: */
3154 if (account_name && strcmp (account_name, MODEST_LOCAL_FOLDERS_ACCOUNT_ID) != 0) {
3156 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
3157 (modest_runtime_get_account_store (),
3158 account_name, TNY_ACCOUNT_TYPE_TRANSPORT));
3161 if (!transport_account) {
3162 modest_msg_edit_window_free_msg_data (edit_window, data);
3163 /* Run account setup wizard */
3164 if (!modest_ui_actions_run_account_setup_wizard(MODEST_WINDOW(edit_window)))
3169 /* Create the mail operation */
3170 mail_operation = modest_mail_operation_new_with_error_handling (NULL, modest_ui_actions_disk_operations_error_handler, NULL, NULL);
3171 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
3173 modest_mail_operation_send_new_mail (mail_operation,
3187 data->priority_flags);
3189 if (modest_mail_operation_get_status (mail_operation) == MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS)
3190 modest_platform_information_banner (NULL, NULL, _("mcen_ib_outbox_waiting_to_be_sent"));
3192 if (modest_mail_operation_get_error (mail_operation) != NULL) {
3193 const GError *error = modest_mail_operation_get_error (mail_operation);
3194 if (error->domain == MODEST_MAIL_OPERATION_ERROR &&
3195 error->code == MODEST_MAIL_OPERATION_ERROR_INSTANCE_CREATION_FAILED) {
3196 g_warning ("%s failed: %s\n", __FUNCTION__, (modest_mail_operation_get_error (mail_operation))->message);
3197 modest_platform_information_banner (NULL, NULL, _CS("sfil_ni_not_enough_memory"));
3203 g_free (account_name);
3204 g_object_unref (G_OBJECT (transport_account));
3205 g_object_unref (G_OBJECT (mail_operation));
3207 modest_msg_edit_window_free_msg_data (edit_window, data);
3210 modest_msg_edit_window_set_sent (edit_window, TRUE);
3212 /* Save settings and close the window: */
3213 modest_ui_actions_on_close_window (NULL, MODEST_WINDOW (edit_window));
3220 modest_ui_actions_on_toggle_bold (GtkToggleAction *action,
3221 ModestMsgEditWindow *window)
3223 ModestMsgEditFormatState *format_state = NULL;
3225 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3226 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
3228 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3231 format_state = modest_msg_edit_window_get_format_state (window);
3232 g_return_if_fail (format_state != NULL);
3234 format_state->bold = gtk_toggle_action_get_active (action);
3235 modest_msg_edit_window_set_format_state (window, format_state);
3236 g_free (format_state);
3241 modest_ui_actions_on_toggle_italics (GtkToggleAction *action,
3242 ModestMsgEditWindow *window)
3244 ModestMsgEditFormatState *format_state = NULL;
3246 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3247 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
3249 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3252 format_state = modest_msg_edit_window_get_format_state (window);
3253 g_return_if_fail (format_state != NULL);
3255 format_state->italics = gtk_toggle_action_get_active (action);
3256 modest_msg_edit_window_set_format_state (window, format_state);
3257 g_free (format_state);
3262 modest_ui_actions_on_toggle_bullets (GtkToggleAction *action,
3263 ModestMsgEditWindow *window)
3265 ModestMsgEditFormatState *format_state = NULL;
3267 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3268 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
3270 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3273 format_state = modest_msg_edit_window_get_format_state (window);
3274 g_return_if_fail (format_state != NULL);
3276 format_state->bullet = gtk_toggle_action_get_active (action);
3277 modest_msg_edit_window_set_format_state (window, format_state);
3278 g_free (format_state);
3283 modest_ui_actions_on_change_justify (GtkRadioAction *action,
3284 GtkRadioAction *selected,
3285 ModestMsgEditWindow *window)
3287 ModestMsgEditFormatState *format_state = NULL;
3288 GtkJustification value;
3290 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3292 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3295 value = gtk_radio_action_get_current_value (selected);
3297 format_state = modest_msg_edit_window_get_format_state (window);
3298 g_return_if_fail (format_state != NULL);
3300 format_state->justification = value;
3301 modest_msg_edit_window_set_format_state (window, format_state);
3302 g_free (format_state);
3306 modest_ui_actions_on_select_editor_color (GtkAction *action,
3307 ModestMsgEditWindow *window)
3309 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3310 g_return_if_fail (GTK_IS_ACTION (action));
3312 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3315 modest_msg_edit_window_select_color (window);
3319 modest_ui_actions_on_select_editor_background_color (GtkAction *action,
3320 ModestMsgEditWindow *window)
3322 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3323 g_return_if_fail (GTK_IS_ACTION (action));
3325 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3328 modest_msg_edit_window_select_background_color (window);
3332 modest_ui_actions_on_insert_image (GObject *object,
3333 ModestMsgEditWindow *window)
3335 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3338 if (modest_platform_check_memory_low (MODEST_WINDOW(window), TRUE))
3341 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3344 modest_msg_edit_window_insert_image (window);
3348 modest_ui_actions_on_attach_file (GtkAction *action,
3349 ModestMsgEditWindow *window)
3351 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3352 g_return_if_fail (GTK_IS_ACTION (action));
3354 if (modest_platform_check_memory_low (MODEST_WINDOW(window), TRUE))
3357 modest_msg_edit_window_offer_attach_file (window);
3361 modest_ui_actions_on_remove_attachments (GtkAction *action,
3362 ModestMsgEditWindow *window)
3364 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3366 modest_msg_edit_window_remove_attachments (window, NULL);
3370 do_create_folder_cb (ModestMailOperation *mail_op,
3371 TnyFolderStore *parent_folder,
3372 TnyFolder *new_folder,
3375 gchar *suggested_name = (gchar *) user_data;
3376 GtkWindow *source_win = (GtkWindow *) modest_mail_operation_get_source (mail_op);
3377 const GError *error;
3379 error = modest_mail_operation_get_error (mail_op);
3381 gboolean disk_full = FALSE;
3382 TnyAccount *account;
3383 /* Show an error. If there was some problem writing to
3384 disk, show it, otherwise show the generic folder
3385 create error. We do it here and not in an error
3386 handler because the call to do_create_folder will
3387 stop the main loop in a gtk_dialog_run and then,
3388 the message won't be shown until that dialog is
3390 account = modest_mail_operation_get_account (mail_op);
3393 modest_tny_account_store_check_disk_full_error (modest_runtime_get_account_store(),
3394 (GtkWidget *) source_win,
3397 _("mail_in_ui_folder_create_error_memory"));
3398 g_object_unref (account);
3401 /* Show an error and try again if there is no
3402 full memory condition */
3403 modest_platform_information_banner ((GtkWidget *) source_win, NULL,
3404 _("mail_in_ui_folder_create_error"));
3405 do_create_folder (source_win, parent_folder, (const gchar *) suggested_name);
3409 /* the 'source_win' is either the ModestMainWindow, or the 'Move to folder'-dialog
3410 * FIXME: any other? */
3411 GtkWidget *folder_view;
3413 #ifndef MODEST_TOOLKIT_HILDON2
3414 if (MODEST_IS_MAIN_WINDOW(source_win))
3416 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (source_win),
3417 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3420 folder_view = GTK_WIDGET(g_object_get_data (G_OBJECT (source_win),
3421 MODEST_MOVE_TO_DIALOG_FOLDER_VIEW));
3423 /* Select the newly created folder. It could happen
3424 that the widget is no longer there (i.e. the window
3425 has been destroyed, so we need to check this */
3427 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view),
3429 g_object_unref (new_folder);
3431 /* Free. Note that the first time it'll be NULL so noop */
3432 g_free (suggested_name);
3433 g_object_unref (source_win);
3438 TnyFolderStore *parent;
3439 } CreateFolderConnect;
3442 do_create_folder_performer (gboolean canceled,
3444 GtkWindow *parent_window,
3445 TnyAccount *account,
3448 CreateFolderConnect *helper = (CreateFolderConnect *) user_data;
3449 ModestMailOperation *mail_op;
3451 if (canceled || err) {
3452 /* In disk full conditions we could get this error here */
3453 modest_tny_account_store_check_disk_full_error (modest_runtime_get_account_store(),
3454 (GtkWidget *) parent_window, err,
3455 NULL, _("mail_in_ui_folder_create_error_memory"));
3457 /* This happens if we have selected the outbox folder
3459 if (err && err->code == TNY_SERVICE_ERROR_UNKNOWN &&
3460 TNY_IS_MERGE_FOLDER (helper->parent)) {
3461 /* Show an error and retry */
3462 modest_platform_information_banner ((GtkWidget *) parent_window,
3464 _("mail_in_ui_folder_create_error"));
3466 do_create_folder (parent_window, helper->parent, helper->folder_name);
3472 mail_op = modest_mail_operation_new ((GObject *) parent_window);
3473 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
3475 modest_mail_operation_create_folder (mail_op,
3477 (const gchar *) helper->folder_name,
3478 do_create_folder_cb,
3479 g_strdup (helper->folder_name));
3480 g_object_unref (mail_op);
3484 g_object_unref (helper->parent);
3485 if (helper->folder_name)
3486 g_free (helper->folder_name);
3487 g_slice_free (CreateFolderConnect, helper);
3492 do_create_folder (GtkWindow *parent_window,
3493 TnyFolderStore *suggested_parent,
3494 const gchar *suggested_name)
3497 gchar *folder_name = NULL;
3498 TnyFolderStore *parent_folder = NULL;
3500 result = modest_platform_run_new_folder_dialog (GTK_WINDOW (parent_window),
3502 (gchar *) suggested_name,
3506 if (result == GTK_RESPONSE_ACCEPT && parent_folder) {
3507 CreateFolderConnect *helper = (CreateFolderConnect *) g_slice_new0 (CreateFolderConnect);
3508 helper->folder_name = g_strdup (folder_name);
3509 helper->parent = g_object_ref (parent_folder);
3511 modest_platform_connect_if_remote_and_perform (GTK_WINDOW (parent_window),
3514 do_create_folder_performer,
3519 g_free (folder_name);
3521 g_object_unref (parent_folder);
3525 modest_ui_actions_create_folder(GtkWidget *parent_window,
3526 GtkWidget *folder_view,
3527 TnyFolderStore *parent_folder)
3529 if (!parent_folder) {
3530 #ifdef MODEST_TOOLKIT_HILDON2
3531 ModestTnyAccountStore *acc_store;
3533 acc_store = modest_runtime_get_account_store ();
3535 parent_folder = (TnyFolderStore *)
3536 modest_tny_account_store_get_local_folders_account (acc_store);
3538 parent_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
3542 if (parent_folder) {
3543 do_create_folder (GTK_WINDOW (parent_window), parent_folder, NULL);
3544 g_object_unref (parent_folder);
3549 modest_ui_actions_on_new_folder (GtkAction *action, ModestWindow *window)
3552 g_return_if_fail (MODEST_IS_WINDOW(window));
3554 #ifndef MODEST_TOOLKIT_HILDON2
3555 if (MODEST_IS_MAIN_WINDOW (window)) {
3556 GtkWidget *folder_view;
3558 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (window),
3559 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3563 modest_ui_actions_create_folder (GTK_WIDGET (window), folder_view, NULL);
3565 if (MODEST_IS_FOLDER_WINDOW (window)) {
3566 GtkWidget *folder_view;
3568 folder_view = GTK_WIDGET (modest_folder_window_get_folder_view (MODEST_FOLDER_WINDOW (window)));
3569 modest_ui_actions_create_folder (GTK_WIDGET (window), folder_view, NULL);
3572 g_assert_not_reached ();
3577 modest_ui_actions_rename_folder_error_handler (ModestMailOperation *mail_op,
3580 const GError *error = NULL;
3581 gchar *message = NULL;
3583 TnyAccount *account = modest_mail_operation_get_account (mail_op);
3585 /* Get error message */
3586 error = modest_mail_operation_get_error (mail_op);
3588 g_return_if_reached ();
3590 mem_full = modest_tny_account_store_is_disk_full_error (modest_runtime_get_account_store(),
3591 (GError *) error, account);
3593 message = g_strdup_printf (_KR("cerm_device_memory_full"), "");
3594 } else if (error->domain == MODEST_MAIL_OPERATION_ERROR &&
3595 error->code == MODEST_MAIL_OPERATION_ERROR_FOLDER_EXISTS) {
3596 message = _CS("ckdg_ib_folder_already_exists");
3597 } else if (error->domain == TNY_ERROR_DOMAIN &&
3598 error->code == TNY_SERVICE_ERROR_STATE) {
3599 /* This means that the folder is already in use (a
3600 message is opened for example */
3601 message = _("emev_ni_internal_error");
3603 message = _CS("ckdg_ib_unable_to_rename");
3606 /* We don't set a parent for the dialog because the dialog
3607 will be destroyed so the banner won't appear */
3608 modest_platform_information_banner (NULL, NULL, message);
3611 g_object_unref (account);
3617 TnyFolderStore *folder;
3622 on_rename_folder_cb (ModestMailOperation *mail_op,
3623 TnyFolder *new_folder,
3626 ModestFolderView *folder_view;
3628 /* If the window was closed when renaming a folder, or if
3629 * it's not a main window this will happen */
3630 if (!MODEST_IS_FOLDER_VIEW (user_data))
3633 folder_view = MODEST_FOLDER_VIEW (user_data);
3634 /* Note that if the rename fails new_folder will be NULL */
3636 modest_folder_view_select_folder (folder_view, new_folder, FALSE);
3637 #ifndef MODEST_TOOLKIT_HILDON2
3639 modest_folder_view_select_first_inbox_or_local (folder_view);
3642 gtk_widget_grab_focus (GTK_WIDGET (folder_view));
3646 on_rename_folder_performer (gboolean canceled,
3648 GtkWindow *parent_window,
3649 TnyAccount *account,
3652 ModestMailOperation *mail_op = NULL;
3653 GtkTreeSelection *sel = NULL;
3654 GtkWidget *folder_view = NULL;
3655 RenameFolderInfo *data = (RenameFolderInfo*)user_data;
3657 if (canceled || err) {
3658 /* In disk full conditions we could get this error here */
3659 modest_tny_account_store_check_disk_full_error (modest_runtime_get_account_store(),
3660 (GtkWidget *) parent_window, err,
3665 modest_mail_operation_new_with_error_handling (G_OBJECT(parent_window),
3666 modest_ui_actions_rename_folder_error_handler,
3667 parent_window, NULL);
3669 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
3671 #ifndef MODEST_TOOLKIT_HILDON2
3672 if (MODEST_IS_MAIN_WINDOW(parent_window)) {
3674 folder_view = modest_main_window_get_child_widget (
3675 MODEST_MAIN_WINDOW (parent_window),
3676 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3679 if (MODEST_IS_FOLDER_WINDOW (parent_window)) {
3680 ModestFolderWindow *folder_window = (ModestFolderWindow *) parent_window;
3681 folder_view = GTK_WIDGET (modest_folder_window_get_folder_view (folder_window));
3685 /* Clear the folders view */
3686 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_view));
3687 gtk_tree_selection_unselect_all (sel);
3689 /* Actually rename the folder */
3690 modest_mail_operation_rename_folder (mail_op,
3691 TNY_FOLDER (data->folder),
3692 (const gchar *) (data->new_name),
3693 on_rename_folder_cb,
3695 g_object_unref (mail_op);
3698 g_object_unref (data->folder);
3699 g_free (data->new_name);
3704 modest_ui_actions_on_rename_folder (GtkAction *action,
3705 ModestWindow *window)
3707 modest_ui_actions_on_edit_mode_rename_folder (window);
3711 modest_ui_actions_on_edit_mode_rename_folder (ModestWindow *window)
3713 TnyFolderStore *folder;
3714 GtkWidget *folder_view;
3715 gboolean do_rename = TRUE;
3717 g_return_val_if_fail (MODEST_IS_WINDOW(window), FALSE);
3719 #ifndef MODEST_TOOLKIT_HILDON2
3720 if (MODEST_IS_MAIN_WINDOW (window)) {
3721 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (window),
3722 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3726 if (MODEST_IS_FOLDER_WINDOW (window)) {
3727 folder_view = GTK_WIDGET (modest_folder_window_get_folder_view (MODEST_FOLDER_WINDOW (window)));
3733 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
3738 if (TNY_IS_FOLDER (folder)) {
3739 gchar *folder_name = NULL;
3741 const gchar *current_name;
3742 TnyFolderStore *parent;
3744 current_name = tny_folder_get_name (TNY_FOLDER (folder));
3745 parent = tny_folder_get_folder_store (TNY_FOLDER (folder));
3746 response = modest_platform_run_rename_folder_dialog (GTK_WINDOW (window),
3747 parent, current_name,
3749 g_object_unref (parent);
3751 if (response != GTK_RESPONSE_ACCEPT || strlen (folder_name) == 0) {
3754 RenameFolderInfo *rename_folder_data = g_new0 (RenameFolderInfo, 1);
3755 rename_folder_data->folder = g_object_ref (folder);
3756 rename_folder_data->new_name = folder_name;
3757 modest_platform_connect_if_remote_and_perform (GTK_WINDOW(window), TRUE,
3758 folder, on_rename_folder_performer, rename_folder_data);
3761 g_object_unref (folder);
3766 modest_ui_actions_delete_folder_error_handler (ModestMailOperation *mail_op,
3769 GObject *win = modest_mail_operation_get_source (mail_op);
3771 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
3772 _("mail_in_ui_folder_delete_error"),
3774 g_object_unref (win);
3778 TnyFolderStore *folder;
3779 gboolean move_to_trash;
3783 on_delete_folder_cb (gboolean canceled,
3785 GtkWindow *parent_window,
3786 TnyAccount *account,
3789 DeleteFolderInfo *info = (DeleteFolderInfo*) user_data;
3790 GtkWidget *folder_view;
3791 ModestMailOperation *mail_op;
3792 GtkTreeSelection *sel;
3794 if (!MODEST_IS_WINDOW(parent_window) || canceled || (err!=NULL)) {
3795 /* Note that the connection process can fail due to
3796 memory low conditions as it can not successfully
3797 store the summary */
3798 if (!modest_tny_account_store_check_disk_full_error (modest_runtime_get_account_store(),
3799 (GtkWidget*) parent_window, err,
3801 g_debug ("Error connecting when trying to delete a folder");
3802 g_object_unref (G_OBJECT (info->folder));
3807 #ifndef MODEST_TOOLKIT_HILDON2
3808 if (MODEST_IS_MAIN_WINDOW (parent_window)) {
3809 folder_view = modest_main_window_get_child_widget (
3810 MODEST_MAIN_WINDOW (parent_window),
3811 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3813 if (MODEST_IS_FOLDER_WINDOW (parent_window)) {
3814 folder_view = GTK_WIDGET (modest_folder_window_get_folder_view (MODEST_FOLDER_WINDOW (parent_window)));
3817 g_object_unref (G_OBJECT (info->folder));
3822 /* Unselect the folder before deleting it to free the headers */
3823 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_view));
3824 gtk_tree_selection_unselect_all (sel);
3826 /* Create the mail operation */
3828 modest_mail_operation_new_with_error_handling (G_OBJECT(parent_window),
3829 modest_ui_actions_delete_folder_error_handler,
3832 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
3834 modest_mail_operation_remove_folder (mail_op, TNY_FOLDER (info->folder), info->move_to_trash);
3836 #ifndef MODEST_TOOLKIT_HILDON2
3837 modest_folder_view_select_first_inbox_or_local (MODEST_FOLDER_VIEW (folder_view));
3840 g_object_unref (mail_op);
3841 g_object_unref (info->folder);
3846 delete_folder (ModestWindow *window, gboolean move_to_trash)
3848 TnyFolderStore *folder;
3849 GtkWidget *folder_view;
3853 g_return_val_if_fail (MODEST_IS_WINDOW(window), FALSE);
3855 #ifndef MODEST_TOOLKIT_HILDON2
3856 if (MODEST_IS_MAIN_WINDOW (window)) {
3858 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (window),
3859 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3861 if (MODEST_IS_FOLDER_WINDOW (window)) {
3862 folder_view = GTK_WIDGET (modest_folder_window_get_folder_view (MODEST_FOLDER_WINDOW (window)));
3870 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
3875 /* Show an error if it's an account */
3876 if (!TNY_IS_FOLDER (folder)) {
3877 modest_platform_run_information_dialog (GTK_WINDOW (window),
3878 _("mail_in_ui_folder_delete_error"),
3880 g_object_unref (G_OBJECT (folder));
3885 message = g_strdup_printf (_("mcen_nc_delete_folder_text"),
3886 tny_folder_get_name (TNY_FOLDER (folder)));
3887 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (window),
3888 (const gchar *) message);
3891 if (response == GTK_RESPONSE_OK) {
3892 TnyAccount *account = NULL;
3893 DeleteFolderInfo *info = NULL;
3894 info = g_new0(DeleteFolderInfo, 1);
3895 info->folder = g_object_ref (folder);
3896 info->move_to_trash = move_to_trash;
3898 account = tny_folder_get_account (TNY_FOLDER (folder));
3899 modest_platform_connect_if_remote_and_perform (GTK_WINDOW (window),
3901 TNY_FOLDER_STORE (account),
3902 on_delete_folder_cb, info);
3903 g_object_unref (account);
3904 g_object_unref (folder);
3912 modest_ui_actions_on_delete_folder (GtkAction *action,
3913 ModestWindow *window)
3915 modest_ui_actions_on_edit_mode_delete_folder (window);
3919 modest_ui_actions_on_edit_mode_delete_folder (ModestWindow *window)
3921 g_return_val_if_fail (MODEST_IS_WINDOW(window), TRUE);
3923 return delete_folder (window, FALSE);
3926 #ifndef MODEST_TOOLKIT_HILDON2
3928 modest_ui_actions_on_move_folder_to_trash_folder (GtkAction *action, ModestMainWindow *main_window)
3930 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
3932 delete_folder (MODEST_WINDOW (main_window), TRUE);
3936 typedef struct _PasswordDialogFields {
3937 GtkWidget *username;
3938 GtkWidget *password;
3940 } PasswordDialogFields;
3943 password_dialog_check_field (GtkEditable *editable,
3944 PasswordDialogFields *fields)
3947 gboolean any_value_empty = FALSE;
3949 value = modest_entry_get_text (fields->username);
3950 if ((value == NULL) || value[0] == '\0') {
3951 any_value_empty = TRUE;
3953 value = modest_entry_get_text (fields->password);
3954 if ((value == NULL) || value[0] == '\0') {
3955 any_value_empty = TRUE;
3957 gtk_dialog_set_response_sensitive (GTK_DIALOG (fields->dialog), GTK_RESPONSE_ACCEPT, !any_value_empty);
3961 modest_ui_actions_on_password_requested (TnyAccountStore *account_store,
3962 const gchar* server_account_name,
3967 ModestMainWindow *main_window)
3969 g_return_if_fail(server_account_name);
3970 gboolean completed = FALSE;
3971 PasswordDialogFields *fields = NULL;
3973 /* Initalize output parameters: */
3980 #ifndef MODEST_TOOLKIT_GTK
3981 /* Maemo uses a different (awkward) button order,
3982 * It should probably just use gtk_alternative_dialog_button_order ().
3984 #ifdef MODEST_TOOLKIT_HILDON2
3986 gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
3989 _HL("wdgt_bd_done"),
3990 GTK_RESPONSE_ACCEPT,
3992 gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox),
3993 HILDON_MARGIN_DOUBLE);
3996 gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
3999 _("mcen_bd_dialog_ok"),
4000 GTK_RESPONSE_ACCEPT,
4001 _("mcen_bd_dialog_cancel"),
4002 GTK_RESPONSE_REJECT,
4004 #endif /* MODEST_TOOLKIT_HILDON2 */
4007 gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
4011 GTK_RESPONSE_REJECT,
4013 GTK_RESPONSE_ACCEPT,
4015 #endif /* MODEST_TOOLKIT_GTK */
4017 modest_window_mgr_set_modal (modest_runtime_get_window_mgr(), GTK_WINDOW (dialog), NULL);
4019 gchar *server_name = modest_account_mgr_get_server_account_hostname (
4020 modest_runtime_get_account_mgr(), server_account_name);
4021 if (!server_name) {/* This happened once, though I don't know why. murrayc. */
4022 g_warning("%s: Could not get server name for server account '%s'", __FUNCTION__, server_account_name);
4025 gtk_widget_destroy (dialog);
4029 gchar *txt = g_strdup_printf (_("mail_ia_password_info"), server_name);
4030 GtkWidget *label = gtk_label_new (txt);
4031 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
4033 g_free (server_name);
4034 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), label,
4039 gchar *initial_username = modest_account_mgr_get_server_account_username (
4040 modest_runtime_get_account_mgr(), server_account_name);
4042 GtkWidget *entry_username = modest_toolkit_factory_create_entry (modest_runtime_get_toolkit_factory ());
4043 if (initial_username)
4044 modest_entry_set_text (entry_username, initial_username);
4046 /* Dim this if a connection has ever succeeded with this username,
4047 * as per the UI spec: */
4048 /* const gboolean username_known = */
4049 /* modest_account_mgr_get_server_account_username_has_succeeded( */
4050 /* modest_runtime_get_account_mgr(), server_account_name); */
4051 /* gtk_widget_set_sensitive (entry_username, !username_known); */
4053 /* We drop the username sensitive code and disallow changing it here
4054 * as tinymail does not support really changing the username in the callback
4056 gtk_widget_set_sensitive (entry_username, FALSE);
4058 /* Auto-capitalization is the default, so let's turn it off: */
4059 #ifdef MAEMO_CHANGES
4060 hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_username), HILDON_GTK_INPUT_MODE_FULL);
4063 /* Create a size group to be used by all captions.
4064 * Note that HildonCaption does not create a default size group if we do not specify one.
4065 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
4066 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
4068 GtkWidget *caption = modest_toolkit_utils_create_captioned (sizegroup, NULL,
4069 _("mail_fi_username"), FALSE,
4071 gtk_widget_show (entry_username);
4072 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
4073 FALSE, FALSE, MODEST_MARGIN_HALF);
4074 gtk_widget_show (caption);
4077 GtkWidget *entry_password = modest_toolkit_factory_create_entry (modest_runtime_get_toolkit_factory ());
4078 gtk_entry_set_visibility (GTK_ENTRY(entry_password), FALSE);
4079 /* gtk_entry_set_invisible_char (GTK_ENTRY(entry_password), "*"); */
4081 /* Auto-capitalization is the default, so let's turn it off: */
4082 #ifdef MAEMO_CHANGES
4083 hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_password),
4084 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
4087 caption = modest_toolkit_utils_create_captioned (sizegroup, NULL,
4088 _("mail_fi_password"), FALSE,
4090 gtk_widget_show (entry_password);
4091 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
4092 FALSE, FALSE, MODEST_MARGIN_HALF);
4093 gtk_widget_show (caption);
4094 g_object_unref (sizegroup);
4096 if (initial_username != NULL)
4097 gtk_widget_grab_focus (GTK_WIDGET (entry_password));
4099 /* This is not in the Maemo UI spec:
4100 remember_pass_check = gtk_check_button_new_with_label (_("Remember password"));
4101 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), remember_pass_check,
4105 fields = g_slice_new0 (PasswordDialogFields);
4106 fields->username = entry_username;
4107 fields->password = entry_password;
4108 fields->dialog = dialog;
4110 g_signal_connect (entry_username, "changed", G_CALLBACK (password_dialog_check_field), fields);
4111 g_signal_connect (entry_password, "changed", G_CALLBACK (password_dialog_check_field), fields);
4112 password_dialog_check_field (NULL, fields);
4114 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
4116 while (!completed) {
4118 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
4120 *username = g_strdup (modest_entry_get_text (entry_username));
4122 /* Note that an empty field becomes the "" string */
4123 if (*username && strlen (*username) > 0) {
4124 modest_account_mgr_set_server_account_username (modest_runtime_get_account_mgr(),
4125 server_account_name,
4129 const gboolean username_was_changed =
4130 (strcmp (*username, initial_username) != 0);
4131 if (username_was_changed) {
4132 g_warning ("%s: tinymail does not yet support changing the "
4133 "username in the get_password() callback.\n", __FUNCTION__);
4139 modest_platform_information_banner (GTK_WIDGET (dialog), NULL,
4140 _("mcen_ib_username_pw_incorrect"));
4146 *password = g_strdup (modest_entry_get_text (entry_password));
4148 /* We do not save the password in the configuration,
4149 * because this function is only called for passwords that should
4150 * not be remembered:
4151 modest_server_account_set_password (
4152 modest_runtime_get_account_mgr(), server_account_name,
4159 #ifndef MODEST_TOOLKIT_HILDON2
4160 /* Set parent to NULL or the banner will disappear with its parent dialog */
4161 modest_platform_information_banner(NULL, NULL, _("mail_ib_login_cancelled"));
4173 /* This is not in the Maemo UI spec:
4174 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (remember_pass_check)))
4180 g_free (initial_username);
4181 gtk_widget_destroy (dialog);
4182 g_slice_free (PasswordDialogFields, fields);
4184 /* printf ("DEBUG: %s: cancel=%d\n", __FUNCTION__, *cancel); */
4188 modest_ui_actions_on_cut (GtkAction *action,
4189 ModestWindow *window)
4191 GtkWidget *focused_widget;
4192 GtkClipboard *clipboard;
4194 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
4195 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
4196 if (GTK_IS_EDITABLE (focused_widget)) {
4197 gtk_editable_cut_clipboard (GTK_EDITABLE(focused_widget));
4198 gtk_clipboard_set_can_store (clipboard, NULL, 0);
4199 gtk_clipboard_store (clipboard);
4200 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
4201 GtkTextBuffer *buffer;
4203 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
4204 if (modest_text_utils_buffer_selection_is_valid (buffer)) {
4205 gtk_text_buffer_cut_clipboard (buffer, clipboard, TRUE);
4206 gtk_clipboard_set_can_store (clipboard, NULL, 0);
4207 gtk_clipboard_store (clipboard);
4209 } else if (MODEST_IS_HEADER_VIEW (focused_widget)) {
4210 TnyList *header_list = modest_header_view_get_selected_headers (
4211 MODEST_HEADER_VIEW (focused_widget));
4212 gboolean continue_download = FALSE;
4213 gint num_of_unc_msgs;
4215 num_of_unc_msgs = header_list_count_uncached_msgs(header_list);
4217 if (num_of_unc_msgs) {
4218 TnyAccount *account = get_account_from_header_list (header_list);
4220 continue_download = connect_to_get_msg (window, num_of_unc_msgs, account);
4221 g_object_unref (account);
4225 if (num_of_unc_msgs == 0 || continue_download) {
4226 /* modest_platform_information_banner (
4227 NULL, NULL, _CS("mcen_ib_getting_items"));*/
4228 modest_header_view_cut_selection (
4229 MODEST_HEADER_VIEW (focused_widget));
4232 g_object_unref (header_list);
4233 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
4234 modest_folder_view_cut_selection (MODEST_FOLDER_VIEW (focused_widget));
4239 modest_ui_actions_on_copy (GtkAction *action,
4240 ModestWindow *window)
4242 GtkClipboard *clipboard;
4243 GtkWidget *focused_widget;
4244 gboolean copied = TRUE;
4246 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
4247 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
4249 if (GTK_IS_LABEL (focused_widget)) {
4251 selection = modest_text_utils_label_get_selection (GTK_LABEL (focused_widget));
4252 gtk_clipboard_set_text (clipboard, selection, -1);
4254 gtk_clipboard_set_can_store (clipboard, NULL, 0);
4255 gtk_clipboard_store (clipboard);
4256 } else if (GTK_IS_EDITABLE (focused_widget)) {
4257 gtk_editable_copy_clipboard (GTK_EDITABLE(focused_widget));
4258 gtk_clipboard_set_can_store (clipboard, NULL, 0);
4259 gtk_clipboard_store (clipboard);
4260 } else if (GTK_IS_HTML (focused_widget)) {
4263 sel = gtk_html_get_selection_html (GTK_HTML (focused_widget), &len);
4264 if ((sel == NULL) || (sel[0] == '\0')) {
4267 gtk_html_copy (GTK_HTML (focused_widget));
4268 gtk_clipboard_set_can_store (clipboard, NULL, 0);
4269 gtk_clipboard_store (clipboard);
4271 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
4272 GtkTextBuffer *buffer;
4273 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
4274 if (modest_text_utils_buffer_selection_is_valid (buffer)) {
4275 gtk_text_buffer_copy_clipboard (buffer, clipboard);
4276 gtk_clipboard_set_can_store (clipboard, NULL, 0);
4277 gtk_clipboard_store (clipboard);
4279 } else if (MODEST_IS_HEADER_VIEW (focused_widget)) {
4280 TnyList *header_list = modest_header_view_get_selected_headers (
4281 MODEST_HEADER_VIEW (focused_widget));
4282 gboolean continue_download = FALSE;
4283 gint num_of_unc_msgs;
4285 num_of_unc_msgs = header_list_count_uncached_msgs(header_list);
4287 if (num_of_unc_msgs) {
4288 TnyAccount *account = get_account_from_header_list (header_list);
4290 continue_download = connect_to_get_msg (window, num_of_unc_msgs, account);
4291 g_object_unref (account);
4295 if (num_of_unc_msgs == 0 || continue_download) {
4296 modest_platform_information_banner (
4297 NULL, NULL, _CS("mcen_ib_getting_items"));
4298 modest_header_view_copy_selection (
4299 MODEST_HEADER_VIEW (focused_widget));
4303 g_object_unref (header_list);
4305 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
4306 modest_folder_view_copy_selection (MODEST_FOLDER_VIEW (focused_widget));
4309 /* Show information banner if there was a copy to clipboard */
4311 modest_platform_information_banner (
4312 NULL, NULL, _CS("ecoc_ib_edwin_copied"));
4316 modest_ui_actions_on_undo (GtkAction *action,
4317 ModestWindow *window)
4319 if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
4320 modest_msg_edit_window_undo (MODEST_MSG_EDIT_WINDOW (window));
4321 #ifndef MODEST_TOOLKIT_HILDON2
4322 } else if (MODEST_IS_MAIN_WINDOW (window)) {
4323 ModestEmailClipboard *clipboard = NULL;
4324 /* Clear clipboard source */
4325 clipboard = modest_runtime_get_email_clipboard ();
4326 modest_email_clipboard_clear (clipboard);
4329 g_return_if_reached ();
4334 modest_ui_actions_on_redo (GtkAction *action,
4335 ModestWindow *window)
4337 if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
4338 modest_msg_edit_window_redo (MODEST_MSG_EDIT_WINDOW (window));
4341 g_return_if_reached ();
4347 destroy_information_note (ModestMailOperation *mail_op,
4350 /* destroy information note */
4351 gtk_widget_destroy (GTK_WIDGET(user_data));
4355 destroy_folder_information_note (ModestMailOperation *mail_op,
4356 TnyFolder *new_folder,
4359 /* destroy information note */
4360 gtk_widget_destroy (GTK_WIDGET(user_data));
4365 paste_as_attachment_free (gpointer data)
4367 PasteAsAttachmentHelper *helper = (PasteAsAttachmentHelper *) data;
4369 if (helper->banner) {
4370 gtk_widget_destroy (helper->banner);
4371 g_object_unref (helper->banner);
4377 paste_msg_as_attachment_cb (ModestMailOperation *mail_op,
4382 PasteAsAttachmentHelper *helper = (PasteAsAttachmentHelper *) userdata;
4383 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (helper->window));
4388 modest_msg_edit_window_add_part (MODEST_MSG_EDIT_WINDOW (helper->window), TNY_MIME_PART (msg));
4393 modest_ui_actions_on_paste (GtkAction *action,
4394 ModestWindow *window)
4396 GtkWidget *focused_widget = NULL;
4397 GtkWidget *inf_note = NULL;
4398 ModestMailOperation *mail_op = NULL;
4400 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
4401 if (GTK_IS_EDITABLE (focused_widget)) {
4402 gtk_editable_paste_clipboard (GTK_EDITABLE(focused_widget));
4403 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
4404 ModestEmailClipboard *e_clipboard = NULL;
4405 e_clipboard = modest_runtime_get_email_clipboard ();
4406 if (modest_email_clipboard_cleared (e_clipboard)) {
4407 GtkTextBuffer *buffer;
4408 GtkClipboard *clipboard;
4410 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
4411 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
4412 gtk_text_buffer_paste_clipboard (buffer, clipboard, NULL, TRUE);
4413 } else if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
4414 ModestMailOperation *mail_op;
4415 TnyFolder *src_folder = NULL;
4416 TnyList *data = NULL;
4418 PasteAsAttachmentHelper *helper = g_new0 (PasteAsAttachmentHelper, 1);
4419 helper->window = MODEST_MSG_EDIT_WINDOW (window);
4420 helper->banner = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
4421 _CS("ckct_nw_pasting"));
4422 modest_email_clipboard_get_data (e_clipboard, &src_folder, &data, &delete);
4423 mail_op = modest_mail_operation_new (G_OBJECT (window));
4424 if (helper->banner != NULL) {
4425 g_object_ref (G_OBJECT (helper->banner));
4426 gtk_widget_show (GTK_WIDGET (helper->banner));
4430 modest_mail_operation_get_msgs_full (mail_op,
4432 (GetMsgAsyncUserCallback) paste_msg_as_attachment_cb,
4434 paste_as_attachment_free);
4438 g_object_unref (data);
4440 g_object_unref (src_folder);
4443 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
4444 ModestEmailClipboard *clipboard = NULL;
4445 TnyFolder *src_folder = NULL;
4446 TnyFolderStore *folder_store = NULL;
4447 TnyList *data = NULL;
4448 gboolean delete = FALSE;
4450 /* Check clipboard source */
4451 clipboard = modest_runtime_get_email_clipboard ();
4452 if (modest_email_clipboard_cleared (clipboard))
4455 /* Get elements to paste */
4456 modest_email_clipboard_get_data (clipboard, &src_folder, &data, &delete);
4458 /* Create a new mail operation */
4459 mail_op = modest_mail_operation_new (G_OBJECT(window));
4461 /* Get destination folder */
4462 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (focused_widget));
4464 /* transfer messages */
4468 /* Ask for user confirmation */
4470 modest_ui_actions_msgs_move_to_confirmation (window,
4471 TNY_FOLDER (folder_store),
4475 if (response == GTK_RESPONSE_OK) {
4476 /* Launch notification */
4477 inf_note = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
4478 _CS("ckct_nw_pasting"));
4479 if (inf_note != NULL) {
4480 gtk_window_set_modal (GTK_WINDOW(inf_note), FALSE);
4481 gtk_widget_show (GTK_WIDGET(inf_note));
4484 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
4485 modest_mail_operation_xfer_msgs (mail_op,
4487 TNY_FOLDER (folder_store),
4489 destroy_information_note,
4492 g_object_unref (mail_op);
4495 } else if (src_folder != NULL) {
4496 /* Launch notification */
4497 inf_note = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
4498 _CS("ckct_nw_pasting"));
4499 if (inf_note != NULL) {
4500 gtk_window_set_modal (GTK_WINDOW(inf_note), FALSE);
4501 gtk_widget_show (GTK_WIDGET(inf_note));
4504 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
4505 modest_mail_operation_xfer_folder (mail_op,
4509 destroy_folder_information_note,
4515 g_object_unref (data);
4516 if (src_folder != NULL)
4517 g_object_unref (src_folder);
4518 if (folder_store != NULL)
4519 g_object_unref (folder_store);
4525 modest_ui_actions_on_select_all (GtkAction *action,
4526 ModestWindow *window)
4528 GtkWidget *focused_widget;
4530 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
4531 if (MODEST_IS_ATTACHMENTS_VIEW (focused_widget)) {
4532 modest_attachments_view_select_all (MODEST_ATTACHMENTS_VIEW (focused_widget));
4533 } else if (GTK_IS_LABEL (focused_widget)) {
4534 gtk_label_select_region (GTK_LABEL (focused_widget), 0, -1);
4535 } else if (GTK_IS_EDITABLE (focused_widget)) {
4536 gtk_editable_select_region (GTK_EDITABLE(focused_widget), 0, -1);
4537 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
4538 GtkTextBuffer *buffer;
4539 GtkTextIter start, end;
4541 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
4542 gtk_text_buffer_get_start_iter (buffer, &start);
4543 gtk_text_buffer_get_end_iter (buffer, &end);
4544 gtk_text_buffer_select_range (buffer, &start, &end);
4545 } else if (GTK_IS_HTML (focused_widget)) {
4546 gtk_html_select_all (GTK_HTML (focused_widget));
4547 #ifndef MODEST_TOOLKIT_HILDON2
4548 } else if (MODEST_IS_MAIN_WINDOW (window)) {
4549 GtkWidget *header_view = focused_widget;
4550 GtkTreeSelection *selection = NULL;
4552 if (!(MODEST_IS_HEADER_VIEW (focused_widget))) {
4553 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (window),
4554 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
4557 /* Disable window dimming management */
4558 modest_window_disable_dimming (MODEST_WINDOW(window));
4560 /* Select all messages */
4561 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(header_view));
4562 gtk_tree_selection_select_all (selection);
4564 /* Set focuse on header view */
4565 gtk_widget_grab_focus (header_view);
4567 /* Enable window dimming management */
4568 modest_window_enable_dimming (MODEST_WINDOW(window));
4569 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (window));
4570 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (window));
4577 modest_ui_actions_on_mark_as_read (GtkAction *action,
4578 ModestWindow *window)
4580 g_return_if_fail (MODEST_IS_WINDOW(window));
4582 /* Mark each header as read */
4583 do_headers_action (window, headers_action_mark_as_read, NULL);
4587 modest_ui_actions_on_mark_as_unread (GtkAction *action,
4588 ModestWindow *window)
4590 g_return_if_fail (MODEST_IS_WINDOW(window));
4592 /* Mark each header as read */
4593 do_headers_action (window, headers_action_mark_as_unread, NULL);
4597 modest_ui_actions_on_change_zoom (GtkRadioAction *action,
4598 GtkRadioAction *selected,
4599 ModestWindow *window)
4603 value = gtk_radio_action_get_current_value (selected);
4604 if (MODEST_IS_WINDOW (window)) {
4605 modest_window_set_zoom (MODEST_WINDOW (window), ((gdouble)value)/100);
4610 modest_ui_actions_msg_edit_on_change_priority (GtkRadioAction *action,
4611 GtkRadioAction *selected,
4612 ModestWindow *window)
4614 TnyHeaderFlags flags;
4615 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4617 flags = gtk_radio_action_get_current_value (selected);
4618 modest_msg_edit_window_set_priority_flags (MODEST_MSG_EDIT_WINDOW (window), flags);
4622 modest_ui_actions_msg_edit_on_change_file_format (GtkRadioAction *action,
4623 GtkRadioAction *selected,
4624 ModestWindow *window)
4628 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4630 file_format = gtk_radio_action_get_current_value (selected);
4631 modest_msg_edit_window_set_file_format (MODEST_MSG_EDIT_WINDOW (window), file_format);
4636 modest_ui_actions_on_zoom_plus (GtkAction *action,
4637 ModestWindow *window)
4639 g_return_if_fail (MODEST_IS_WINDOW (window));
4641 modest_window_zoom_plus (MODEST_WINDOW (window));
4645 modest_ui_actions_on_zoom_minus (GtkAction *action,
4646 ModestWindow *window)
4648 g_return_if_fail (MODEST_IS_WINDOW (window));
4650 modest_window_zoom_minus (MODEST_WINDOW (window));
4654 modest_ui_actions_on_toggle_fullscreen (GtkToggleAction *toggle,
4655 ModestWindow *window)
4657 ModestWindowMgr *mgr;
4658 gboolean fullscreen, active;
4659 g_return_if_fail (MODEST_IS_WINDOW (window));
4661 mgr = modest_runtime_get_window_mgr ();
4663 active = (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle)))?1:0;
4664 fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
4666 if (active != fullscreen) {
4667 modest_window_mgr_set_fullscreen_mode (mgr, active);
4668 #ifndef MODEST_TOOLKIT_HILDON2
4669 gtk_window_present (GTK_WINDOW (window));
4675 modest_ui_actions_on_change_fullscreen (GtkAction *action,
4676 ModestWindow *window)
4678 ModestWindowMgr *mgr;
4679 gboolean fullscreen;
4681 g_return_if_fail (MODEST_IS_WINDOW (window));
4683 mgr = modest_runtime_get_window_mgr ();
4684 fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
4685 modest_window_mgr_set_fullscreen_mode (mgr, !fullscreen);
4687 #ifndef MODEST_TOOLKIT_HILDON2
4688 gtk_window_present (GTK_WINDOW (window));
4693 * Used by modest_ui_actions_on_details to call do_headers_action
4696 headers_action_show_details (TnyHeader *header,
4697 ModestWindow *window,
4701 gboolean async_retrieval;
4704 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
4705 async_retrieval = TRUE;
4706 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW (window));
4708 async_retrieval = FALSE;
4710 modest_platform_run_header_details_dialog (GTK_WINDOW (window), header, async_retrieval, msg);
4712 g_object_unref (msg);
4716 * Show the header details in a ModestDetailsDialog widget
4719 modest_ui_actions_on_details (GtkAction *action,
4722 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
4726 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW (win));
4730 header = tny_msg_get_header (msg);
4732 headers_action_show_details (header, win, NULL);
4733 g_object_unref (header);
4735 g_object_unref (msg);
4736 #ifndef MODEST_TOOLKIT_HILDON2
4737 } else if (MODEST_IS_MAIN_WINDOW (win)) {
4738 GtkWidget *folder_view, *header_view;
4740 /* Check which widget has the focus */
4741 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
4742 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
4743 if (gtk_widget_is_focus (folder_view)) {
4744 TnyFolderStore *folder_store
4745 = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
4746 if (!folder_store) {
4747 g_warning ("%s: No item was selected.\n", __FUNCTION__);
4750 /* Show only when it's a folder */
4751 /* This function should not be called for account items,
4752 * because we dim the menu item for them. */
4753 if (TNY_IS_FOLDER (folder_store)) {
4754 modest_platform_run_folder_details_dialog (GTK_WINDOW (win),
4755 TNY_FOLDER (folder_store));
4758 g_object_unref (folder_store);
4761 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
4762 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
4763 /* Show details of each header */
4764 do_headers_action (win, headers_action_show_details, header_view);
4767 } else if (MODEST_IS_HEADER_WINDOW (win)) {
4769 GtkWidget *header_view;
4771 header_view = GTK_WIDGET (modest_header_window_get_header_view (MODEST_HEADER_WINDOW (win)));
4772 folder = modest_header_view_get_folder (MODEST_HEADER_VIEW (header_view));
4774 modest_platform_run_folder_details_dialog (GTK_WINDOW (win),
4776 g_object_unref (folder);
4783 modest_ui_actions_on_limit_error (GtkAction *action,
4786 g_return_if_fail (MODEST_IS_MSG_VIEW_WINDOW (win));
4788 modest_platform_information_banner ((GtkWidget *) win, NULL, _CS("ckdg_ib_maximum_characters_reached"));
4793 modest_ui_actions_on_toggle_show_cc (GtkToggleAction *toggle,
4794 ModestMsgEditWindow *window)
4796 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4798 modest_msg_edit_window_show_cc (window, gtk_toggle_action_get_active (toggle));
4802 modest_ui_actions_on_toggle_show_bcc (GtkToggleAction *toggle,
4803 ModestMsgEditWindow *window)
4805 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4807 modest_msg_edit_window_show_bcc (window, gtk_toggle_action_get_active (toggle));
4810 #ifndef MODEST_TOOLKIT_HILDON2
4812 modest_ui_actions_toggle_folders_view (GtkAction *action,
4813 ModestMainWindow *main_window)
4815 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
4817 if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)))
4818 modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SPLIT);
4820 modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SIMPLE);
4825 modest_ui_actions_on_toggle_toolbar (GtkToggleAction *toggle,
4826 ModestWindow *window)
4828 gboolean active, fullscreen = FALSE;
4829 ModestWindowMgr *mgr;
4831 active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle));
4833 /* Check if we want to toggle the toolbar view in fullscreen
4835 if (!strcmp (gtk_action_get_name (GTK_ACTION (toggle)),
4836 "ViewShowToolbarFullScreen")) {
4840 /* Toggle toolbar */
4841 mgr = modest_runtime_get_window_mgr ();
4842 modest_window_mgr_show_toolbars (mgr, G_TYPE_FROM_INSTANCE (window), active, fullscreen);
4846 modest_ui_actions_msg_edit_on_select_font (GtkAction *action,
4847 ModestMsgEditWindow *window)
4849 modest_msg_edit_window_select_font (window);
4854 modest_ui_actions_on_folder_display_name_changed (ModestFolderView *folder_view,
4855 const gchar *display_name,
4858 /* don't update the display name if it was already set;
4859 * updating the display name apparently is expensive */
4860 const gchar* old_name = gtk_window_get_title (window);
4862 if (display_name == NULL)
4865 if (old_name && display_name && strcmp (old_name, display_name) == 0)
4866 return; /* don't do anything */
4868 /* This is usually used to change the title of the main window, which
4869 * is the one that holds the folder view. Note that this change can
4870 * happen even when the widget doesn't have the focus. */
4871 gtk_window_set_title (window, display_name);
4876 modest_ui_actions_on_select_contacts (GtkAction *action, ModestMsgEditWindow *window)
4878 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4879 modest_msg_edit_window_select_contacts (window);
4883 modest_ui_actions_on_check_names (GtkAction *action, ModestMsgEditWindow *window)
4885 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4886 modest_msg_edit_window_check_names (window, FALSE);
4889 #ifndef MODEST_TOOLKIT_HILDON2
4891 * This function is used to track changes in the selection of the
4892 * folder view that is inside the "move to" dialog to enable/disable
4893 * the OK button because we do not want the user to select a disallowed
4894 * destination for a folder.
4895 * The user also not desired to be able to use NEW button on items where
4896 * folder creation is not possibel.
4899 on_move_to_dialog_folder_selection_changed (ModestFolderView* self,
4900 TnyFolderStore *folder_store,
4904 GtkWidget *dialog = NULL;
4905 gboolean ok_sensitive = TRUE, new_sensitive = TRUE;
4906 gboolean moving_folder = FALSE;
4907 gboolean is_local_account = TRUE;
4908 GtkWidget *folder_view = NULL;
4909 ModestTnyFolderRules rules;
4911 g_return_if_fail (MODEST_IS_FOLDER_VIEW(self));
4916 dialog = gtk_widget_get_ancestor (GTK_WIDGET (self), GTK_TYPE_DIALOG);
4920 /* check if folder_store is an remote account */
4921 if (TNY_IS_ACCOUNT (folder_store)) {
4922 TnyAccount *local_account = NULL;
4923 TnyAccount *mmc_account = NULL;
4924 ModestTnyAccountStore *account_store = NULL;
4926 account_store = modest_runtime_get_account_store ();
4927 local_account = modest_tny_account_store_get_local_folders_account (account_store);
4928 mmc_account = modest_tny_account_store_get_mmc_folders_account (account_store);
4930 if ((gpointer) local_account != (gpointer) folder_store &&
4931 (gpointer) mmc_account != (gpointer) folder_store) {
4932 ModestProtocolType proto;
4933 proto = modest_tny_account_get_protocol_type (TNY_ACCOUNT (folder_store));
4934 if (proto == MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
4935 proto = MODEST_PROTOCOLS_STORE_MAILDIR;
4937 is_local_account = FALSE;
4938 /* New button should be dimmed on remote
4940 new_sensitive = (modest_protocol_registry_protocol_type_has_tag (modest_runtime_get_protocol_registry (),
4942 MODEST_PROTOCOL_REGISTRY_STORE_HAS_FOLDERS));
4944 g_object_unref (local_account);
4946 /* It could not exist */
4948 g_object_unref (mmc_account);
4951 /* Check the target folder rules */
4952 if (TNY_IS_FOLDER (folder_store)) {
4953 rules = modest_tny_folder_get_rules (TNY_FOLDER (folder_store));
4954 if (rules & MODEST_FOLDER_RULES_FOLDER_NON_WRITEABLE) {
4955 ok_sensitive = FALSE;
4956 new_sensitive = FALSE;
4961 /* Check if we're moving a folder */
4962 if (MODEST_IS_MAIN_WINDOW (user_data)) {
4963 /* Get the widgets */
4964 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (user_data),
4965 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
4966 if (gtk_widget_is_focus (folder_view))
4967 moving_folder = TRUE;
4970 if (moving_folder) {
4971 TnyFolderStore *moved_folder = NULL, *parent = NULL;
4973 /* Get the folder to move */
4974 moved_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
4976 /* Check that we're not moving to the same folder */
4977 if (TNY_IS_FOLDER (moved_folder)) {
4978 parent = tny_folder_get_folder_store (TNY_FOLDER (moved_folder));
4979 if (parent == folder_store)
4980 ok_sensitive = FALSE;
4981 g_object_unref (parent);
4984 if (ok_sensitive && TNY_IS_ACCOUNT (folder_store)) {
4985 /* Do not allow to move to an account unless it's the
4986 local folders account */
4987 if (!is_local_account)
4988 ok_sensitive = FALSE;
4991 if (ok_sensitive && (moved_folder == folder_store)) {
4992 /* Do not allow to move to itself */
4993 ok_sensitive = FALSE;
4995 g_object_unref (moved_folder);
4997 TnyFolder *src_folder = NULL;
4999 /* Moving a message */
5000 if (MODEST_IS_MSG_VIEW_WINDOW (user_data)) {
5002 TnyHeader *header = NULL;
5003 header = modest_msg_view_window_get_header
5004 (MODEST_MSG_VIEW_WINDOW (user_data));
5005 if (!TNY_IS_HEADER(header))
5006 g_warning ("%s: could not get source header", __FUNCTION__);
5008 src_folder = tny_header_get_folder (header);
5011 g_object_unref (header);
5014 TNY_FOLDER (modest_folder_view_get_selected
5015 (MODEST_FOLDER_VIEW (folder_view)));
5018 if (TNY_IS_FOLDER(src_folder)) {
5019 /* Do not allow to move the msg to the same folder */
5020 /* Do not allow to move the msg to an account */
5021 if ((gpointer) src_folder == (gpointer) folder_store ||
5022 TNY_IS_ACCOUNT (folder_store))
5023 ok_sensitive = FALSE;
5024 g_object_unref (src_folder);
5026 g_warning ("%s: could not get source folder", __FUNCTION__);
5030 /* Set sensitivity of the OK and NEW button */
5031 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, ok_sensitive);
5032 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), MODEST_GTK_RESPONSE_NEW_FOLDER, new_sensitive);
5037 on_move_to_dialog_response (GtkDialog *dialog,
5041 GtkWidget *parent_win;
5042 MoveToInfo *helper = NULL;
5043 ModestFolderView *folder_view;
5044 gboolean unset_edit_mode = FALSE;
5046 helper = (MoveToInfo *) user_data;
5048 parent_win = (GtkWidget *) helper->win;
5049 folder_view = MODEST_FOLDER_VIEW (g_object_get_data (G_OBJECT (dialog),
5050 MODEST_MOVE_TO_DIALOG_FOLDER_VIEW));
5052 TnyFolderStore *dst_folder;
5053 TnyFolderStore *selected;
5055 case MODEST_GTK_RESPONSE_NEW_FOLDER:
5056 selected = modest_folder_view_get_selected (folder_view);
5057 modest_ui_actions_create_folder (GTK_WIDGET (dialog), GTK_WIDGET (folder_view), selected);
5058 g_object_unref (selected);
5060 case GTK_RESPONSE_NONE:
5061 case GTK_RESPONSE_CANCEL:
5062 case GTK_RESPONSE_DELETE_EVENT:
5064 case GTK_RESPONSE_OK:
5065 dst_folder = modest_folder_view_get_selected (folder_view);
5067 #ifndef MODEST_TOOLKIT_HILDON2
5068 if (MODEST_IS_MAIN_WINDOW (parent_win)) {
5069 /* Clean list to move used for filtering */
5070 modest_folder_view_set_list_to_move (folder_view, NULL);
5072 modest_ui_actions_on_main_window_move_to (NULL,
5073 GTK_WIDGET (folder_view),
5075 MODEST_MAIN_WINDOW (parent_win));
5077 if (MODEST_IS_FOLDER_WINDOW (parent_win)) {
5078 /* Clean list to move used for filtering */
5079 modest_folder_view_set_list_to_move (folder_view, NULL);
5081 modest_ui_actions_on_folder_window_move_to (GTK_WIDGET (folder_view),
5084 GTK_WINDOW (parent_win));
5087 /* if the user selected a root folder
5088 (account) then do not perform any action */
5089 if (TNY_IS_ACCOUNT (dst_folder)) {
5090 g_signal_stop_emission_by_name (dialog, "response");
5094 /* Clean list to move used for filtering */
5095 modest_folder_view_set_list_to_move (folder_view, NULL);
5097 /* Moving from headers window in edit mode */
5098 modest_ui_actions_on_window_move_to (NULL, helper->list,
5100 MODEST_WINDOW (parent_win));
5104 g_object_unref (dst_folder);
5106 unset_edit_mode = TRUE;
5109 g_warning ("%s unexpected response id %d", __FUNCTION__, response);
5112 /* Free the helper and exit */
5114 g_object_unref (helper->list);
5115 if (unset_edit_mode) {
5116 #ifdef MODEST_TOOLKIT_HILDON2
5117 modest_hildon2_window_unset_edit_mode (MODEST_HILDON2_WINDOW (helper->win));
5120 g_slice_free (MoveToInfo, helper);
5121 gtk_widget_destroy (GTK_WIDGET (dialog));
5125 create_move_to_dialog (GtkWindow *win,
5126 GtkWidget *folder_view,
5127 TnyList *list_to_move)
5129 GtkWidget *dialog, *tree_view = NULL;
5131 dialog = modest_platform_create_move_to_dialog (win, &tree_view);
5133 #ifndef MODEST_TOOLKIT_HILDON2
5134 /* Track changes in the selection to
5135 * disable the OK button whenever "Move to" is not possible
5136 * disbale NEW button whenever New is not possible */
5137 g_signal_connect (tree_view,
5138 "folder_selection_changed",
5139 G_CALLBACK (on_move_to_dialog_folder_selection_changed),
5143 /* It could happen that we're trying to move a message from a
5144 window (msg window for example) after the main window was
5145 closed, so we can not just get the model of the folder
5147 if (MODEST_IS_FOLDER_VIEW (folder_view)) {
5148 const gchar *visible_id = NULL;
5150 modest_folder_view_set_style (MODEST_FOLDER_VIEW (tree_view),
5151 MODEST_FOLDER_VIEW_STYLE_SHOW_ALL);
5152 modest_folder_view_copy_model (MODEST_FOLDER_VIEW(folder_view),
5153 MODEST_FOLDER_VIEW(tree_view));
5156 modest_folder_view_get_account_id_of_visible_server_account (MODEST_FOLDER_VIEW(folder_view));
5158 /* Show the same account than the one that is shown in the main window */
5159 modest_folder_view_set_account_id_of_visible_server_account (MODEST_FOLDER_VIEW(tree_view),
5162 const gchar *active_account_name = NULL;
5163 ModestAccountMgr *mgr = NULL;
5164 ModestAccountSettings *settings = NULL;
5165 ModestServerAccountSettings *store_settings = NULL;
5167 modest_folder_view_set_style (MODEST_FOLDER_VIEW (tree_view),
5168 MODEST_FOLDER_VIEW_STYLE_SHOW_ALL);
5169 /* modest_folder_view_update_model (MODEST_FOLDER_VIEW (tree_view), */
5170 /* TNY_ACCOUNT_STORE (modest_runtime_get_account_store ())); */
5172 active_account_name = modest_window_get_active_account (MODEST_WINDOW (win));
5173 mgr = modest_runtime_get_account_mgr ();
5174 settings = modest_account_mgr_load_account_settings (mgr, active_account_name);
5177 const gchar *store_account_name;
5178 store_settings = modest_account_settings_get_store_settings (settings);
5179 store_account_name = modest_server_account_settings_get_account_name (store_settings);
5181 modest_folder_view_set_account_id_of_visible_server_account (MODEST_FOLDER_VIEW (tree_view),
5182 store_account_name);
5183 g_object_unref (store_settings);
5184 g_object_unref (settings);
5188 /* we keep a pointer to the embedded folder view, so we can
5189 * retrieve it with get_folder_view_from_move_to_dialog (see
5190 * above) later (needed for focus handling)
5192 g_object_set_data (G_OBJECT(dialog), MODEST_MOVE_TO_DIALOG_FOLDER_VIEW, tree_view);
5194 /* Hide special folders */
5195 #ifndef MODEST_TOOLKIT_HILDON2
5196 modest_folder_view_show_non_move_folders (MODEST_FOLDER_VIEW (tree_view), FALSE);
5199 modest_folder_view_set_list_to_move (MODEST_FOLDER_VIEW (tree_view), list_to_move);
5200 #ifndef MODEST_TOOLKIT_HILDON2
5201 modest_folder_view_select_first_inbox_or_local (MODEST_FOLDER_VIEW (tree_view));
5204 gtk_widget_show (GTK_WIDGET (tree_view));
5210 * Shows a confirmation dialog to the user when we're moving messages
5211 * from a remote server to the local storage. Returns the dialog
5212 * response. If it's other kind of movement then it always returns
5215 * This one is used by the next functions:
5216 * modest_ui_actions_on_paste - commented out
5217 * drag_and_drop_from_header_view (for d&d in modest_folder_view.c)
5220 modest_ui_actions_msgs_move_to_confirmation (ModestWindow *win,
5221 TnyFolder *dest_folder,
5225 gint response = GTK_RESPONSE_OK;
5226 TnyAccount *account = NULL;
5227 TnyFolder *src_folder = NULL;
5228 TnyIterator *iter = NULL;
5229 TnyHeader *header = NULL;
5231 /* return with OK if the destination is a remote folder */
5232 if (modest_tny_folder_is_remote_folder (dest_folder))
5233 return GTK_RESPONSE_OK;
5235 /* Get source folder */
5236 iter = tny_list_create_iterator (headers);
5237 header = TNY_HEADER (tny_iterator_get_current (iter));
5239 src_folder = tny_header_get_folder (header);
5240 g_object_unref (header);
5242 g_object_unref (iter);
5244 /* if no src_folder, message may be an attahcment */
5245 if (src_folder == NULL)
5246 return GTK_RESPONSE_CANCEL;
5248 /* If the source is a local or MMC folder */
5249 if (!modest_tny_folder_is_remote_folder (src_folder)) {
5250 g_object_unref (src_folder);
5251 return GTK_RESPONSE_OK;
5254 /* Get the account */
5255 account = tny_folder_get_account (src_folder);
5257 /* now if offline we ask the user */
5258 if(connect_to_get_msg (win, tny_list_get_length (headers), account))
5259 response = GTK_RESPONSE_OK;
5261 response = GTK_RESPONSE_CANCEL;
5264 g_object_unref (src_folder);
5265 g_object_unref (account);
5271 move_to_helper_destroyer (gpointer user_data)
5273 MoveToHelper *helper = (MoveToHelper *) user_data;
5275 /* Close the "Pasting" information banner */
5276 if (helper->banner) {
5277 gtk_widget_destroy (GTK_WIDGET (helper->banner));
5278 g_object_unref (helper->banner);
5280 if (gtk_tree_row_reference_valid (helper->reference)) {
5281 gtk_tree_row_reference_free (helper->reference);
5282 helper->reference = NULL;
5288 move_to_cb (ModestMailOperation *mail_op,
5291 MoveToHelper *helper = (MoveToHelper *) user_data;
5292 GObject *object = modest_mail_operation_get_source (mail_op);
5294 /* Note that the operation could have failed, in that case do
5296 if (modest_mail_operation_get_status (mail_op) !=
5297 MODEST_MAIL_OPERATION_STATUS_SUCCESS)
5300 if (MODEST_IS_MSG_VIEW_WINDOW (object)) {
5301 ModestMsgViewWindow *self = MODEST_MSG_VIEW_WINDOW (object);
5303 if (!modest_msg_view_window_select_next_message (self) &&
5304 !modest_msg_view_window_select_previous_message (self)) {
5305 /* No more messages to view, so close this window */
5306 modest_ui_actions_on_close_window (NULL, MODEST_WINDOW(self));
5308 #ifndef MODEST_TOOLKIT_HILDON2
5309 } else if (MODEST_IS_MAIN_WINDOW (object) &&
5310 gtk_tree_row_reference_valid (helper->reference)) {
5311 GtkWidget *header_view;
5313 GtkTreeSelection *sel;
5315 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(object),
5316 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
5317 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
5318 path = gtk_tree_row_reference_get_path (helper->reference);
5319 /* We need to unselect the previous one
5320 because we could be copying instead of
5322 gtk_tree_selection_unselect_all (sel);
5323 gtk_tree_selection_select_path (sel, path);
5324 gtk_tree_path_free (path);
5327 g_object_unref (object);
5330 /* Destroy the helper */
5331 move_to_helper_destroyer (helper);
5335 folder_move_to_cb (ModestMailOperation *mail_op,
5336 TnyFolder *new_folder,
5341 object = modest_mail_operation_get_source (mail_op);
5342 #ifndef MODEST_TOOLKIT_HILDON2
5343 if (MODEST_IS_MAIN_WINDOW (object)) {
5344 GtkWidget *folder_view;
5345 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(object),
5346 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
5347 g_object_ref (folder_view);
5348 g_object_unref (object);
5349 move_to_cb (mail_op, user_data);
5350 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view), new_folder, FALSE);
5351 g_object_unref (folder_view);
5356 move_to_cb (mail_op, user_data);
5361 msgs_move_to_cb (ModestMailOperation *mail_op,
5364 move_to_cb (mail_op, user_data);
5368 modest_ui_actions_move_folder_error_handler (ModestMailOperation *mail_op,
5371 GObject *win = NULL;
5372 const GError *error;
5373 TnyAccount *account = NULL;
5375 #ifndef MODEST_TOOLKIT_HILDON2
5376 ModestWindow *main_window = NULL;
5378 /* Disable next automatic folder selection */
5379 main_window = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (),
5380 FALSE); /* don't create */
5382 /* Show notification dialog only if the main window exists */
5384 GtkWidget *folder_view = NULL;
5386 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (main_window),
5387 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
5388 modest_folder_view_disable_next_folder_selection (MODEST_FOLDER_VIEW(folder_view));
5390 if (user_data && TNY_IS_FOLDER (user_data)) {
5391 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view),
5392 TNY_FOLDER (user_data), FALSE);
5396 win = modest_mail_operation_get_source (mail_op);
5397 error = modest_mail_operation_get_error (mail_op);
5399 if (TNY_IS_FOLDER (user_data))
5400 account = modest_tny_folder_get_account (TNY_FOLDER (user_data));
5401 else if (TNY_IS_ACCOUNT (user_data))
5402 account = g_object_ref (user_data);
5404 /* If it's not a disk full error then show a generic error */
5405 if (!modest_tny_account_store_check_disk_full_error (modest_runtime_get_account_store(),
5406 (GtkWidget *) win, (GError *) error,
5408 modest_platform_run_information_dialog ((GtkWindow *) win,
5409 _("mail_in_ui_folder_move_target_error"),
5412 g_object_unref (account);
5414 g_object_unref (win);
5417 #ifndef MODEST_TOOLKIT_HILDON2
5419 open_msg_for_purge_cb (ModestMailOperation *mail_op,
5428 gint pending_purges = 0;
5429 gboolean some_purged = FALSE;
5430 ModestWindow *win = MODEST_WINDOW (user_data);
5431 ModestWindowMgr *mgr = modest_runtime_get_window_mgr ();
5433 /* If there was any error */
5434 if (!modest_ui_actions_msg_retrieval_check (mail_op, header, msg)) {
5435 modest_window_mgr_unregister_header (mgr, header);
5439 /* Once the message has been retrieved for purging, we check if
5440 * it's all ok for purging */
5442 parts = tny_simple_list_new ();
5443 tny_mime_part_get_parts (TNY_MIME_PART (msg), parts);
5444 iter = tny_list_create_iterator (parts);
5446 while (!tny_iterator_is_done (iter)) {
5448 part = TNY_MIME_PART (tny_iterator_get_current (iter));
5449 if (part && (tny_mime_part_is_attachment (part) || TNY_IS_MSG (part))) {
5450 if (tny_mime_part_is_purged (part))
5457 g_object_unref (part);
5459 tny_iterator_next (iter);
5461 g_object_unref (iter);
5464 if (pending_purges>0) {
5466 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),_("mcen_nc_purge_file_text_inbox"));
5468 if (response == GTK_RESPONSE_OK) {
5471 modest_platform_animation_banner (GTK_WIDGET (win), NULL, _("mcen_me_inbox_remove_attachments"));
5472 iter = tny_list_create_iterator (parts);
5473 while (!tny_iterator_is_done (iter)) {
5476 part = TNY_MIME_PART (tny_iterator_get_current (iter));
5477 if (part && (tny_mime_part_is_attachment (part) || TNY_IS_MSG (part)))
5478 tny_mime_part_set_purged (part);
5481 g_object_unref (part);
5483 tny_iterator_next (iter);
5485 g_object_unref (iter);
5487 tny_msg_rewrite_cache (msg);
5489 gtk_widget_destroy (info);
5493 modest_window_mgr_unregister_header (mgr, header);
5495 g_object_unref (parts);
5499 modest_ui_actions_on_main_window_remove_attachments (GtkAction *action,
5500 ModestMainWindow *win)
5502 GtkWidget *header_view;
5503 TnyList *header_list;
5505 TnyHeaderFlags flags;
5506 ModestWindow *msg_view_window = NULL;
5509 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win));
5511 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
5512 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
5514 header_list = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW (header_view));
5516 g_warning ("%s: no header selected", __FUNCTION__);
5520 if (tny_list_get_length (header_list) == 1) {
5521 TnyIterator *iter = tny_list_create_iterator (header_list);
5522 header = TNY_HEADER (tny_iterator_get_current (iter));
5523 g_object_unref (iter);
5527 if (!header || !TNY_IS_HEADER(header)) {
5528 g_warning ("%s: header is not valid", __FUNCTION__);
5532 found = modest_window_mgr_find_registered_header (modest_runtime_get_window_mgr (),
5533 header, &msg_view_window);
5534 flags = tny_header_get_flags (header);
5535 if (!(flags & TNY_HEADER_FLAG_CACHED))
5538 if (msg_view_window != NULL)
5539 modest_msg_view_window_remove_attachments (MODEST_MSG_VIEW_WINDOW (msg_view_window), TRUE);
5541 /* do nothing; uid was registered before, so window is probably on it's way */
5542 g_debug ("header %p has already been registered", header);
5545 ModestMailOperation *mail_op = NULL;
5546 modest_window_mgr_register_header (modest_runtime_get_window_mgr (), header, NULL);
5547 mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT (win),
5548 modest_ui_actions_disk_operations_error_handler,
5550 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
5551 modest_mail_operation_get_msg (mail_op, header, FALSE, open_msg_for_purge_cb, win);
5553 g_object_unref (mail_op);
5556 g_object_unref (header);
5558 g_object_unref (header_list);
5563 * Checks if we need a connection to do the transfer and if the user
5564 * wants to connect to complete it
5567 modest_ui_actions_xfer_messages_check (GtkWindow *parent_window,
5568 TnyFolderStore *src_folder,
5570 TnyFolder *dst_folder,
5571 gboolean delete_originals,
5572 gboolean *need_connection,
5575 TnyAccount *src_account;
5576 gint uncached_msgs = 0;
5578 /* We don't need any further check if
5580 * 1- the source folder is local OR
5581 * 2- the device is already online
5583 if (!modest_tny_folder_store_is_remote (src_folder) ||
5584 tny_device_is_online (modest_runtime_get_device())) {
5585 *need_connection = FALSE;
5590 /* We must ask for a connection when
5592 * - the message(s) is not already cached OR
5593 * - the message(s) is cached but the leave_on_server setting
5594 * is FALSE (because we need to sync the source folder to
5595 * delete the message from the server (for IMAP we could do it
5596 * offline, it'll take place the next time we get a
5599 uncached_msgs = header_list_count_uncached_msgs (headers);
5600 src_account = get_account_from_folder_store (src_folder);
5601 if (uncached_msgs > 0) {
5605 *need_connection = TRUE;
5606 num_headers = tny_list_get_length (headers);
5607 msg = ngettext ("mcen_nc_get_msg", "mcen_nc_get_msgs", num_headers);
5609 if (modest_platform_run_confirmation_dialog (parent_window, msg) ==
5610 GTK_RESPONSE_CANCEL) {
5616 /* The transfer is possible and the user wants to */
5619 if (remote_folder_has_leave_on_server (src_folder) && delete_originals) {
5620 const gchar *account_name;
5621 gboolean leave_on_server;
5623 account_name = modest_tny_account_get_parent_modest_account_name_for_server_account (src_account);
5624 leave_on_server = modest_account_mgr_get_leave_on_server (modest_runtime_get_account_mgr (),
5627 if (leave_on_server == TRUE) {
5628 *need_connection = FALSE;
5630 *need_connection = TRUE;
5633 *need_connection = FALSE;
5638 g_object_unref (src_account);
5642 xfer_messages_error_handler (ModestMailOperation *mail_op,
5646 const GError *error;
5647 TnyAccount *account;
5649 win = modest_mail_operation_get_source (mail_op);
5650 error = modest_mail_operation_get_error (mail_op);
5652 /* We cannot get the account from the mail op as that is the
5653 source account and for checking memory full conditions we
5654 need the destination one */
5655 account = TNY_ACCOUNT (user_data);
5658 !modest_tny_account_store_check_disk_full_error (modest_runtime_get_account_store(),
5659 (GtkWidget *) win, (GError*) error,
5660 account, _KR("cerm_memory_card_full"))) {
5661 modest_platform_run_information_dialog ((GtkWindow *) win,
5662 _("mail_in_ui_folder_move_target_error"),
5666 g_object_unref (win);
5670 TnyFolderStore *dst_folder;
5675 * Utility function that transfer messages from both the main window
5676 * and the msg view window when using the "Move to" dialog
5679 xfer_messages_performer (gboolean canceled,
5681 GtkWindow *parent_window,
5682 TnyAccount *account,
5685 ModestWindow *win = MODEST_WINDOW (parent_window);
5686 TnyAccount *dst_account = NULL;
5687 gboolean dst_forbids_message_add = FALSE;
5688 XferMsgsHelper *helper;
5689 MoveToHelper *movehelper;
5690 ModestMailOperation *mail_op;
5692 helper = (XferMsgsHelper *) user_data;
5694 if (canceled || err) {
5695 if (!modest_tny_account_store_check_disk_full_error (modest_runtime_get_account_store(),
5696 (GtkWidget *) parent_window, err,
5698 /* Show the proper error message */
5699 modest_ui_actions_on_account_connection_error (parent_window, account);
5704 dst_account = tny_folder_get_account (TNY_FOLDER (helper->dst_folder));
5706 /* tinymail will return NULL for local folders it seems */
5707 dst_forbids_message_add = modest_protocol_registry_protocol_type_has_tag (modest_runtime_get_protocol_registry (),
5708 modest_tny_account_get_protocol_type (dst_account),
5709 MODEST_PROTOCOL_REGISTRY_STORE_FORBID_INCOMING_XFERS);
5711 if (dst_forbids_message_add) {
5712 modest_platform_information_banner (GTK_WIDGET (win),
5714 ngettext("mail_in_ui_folder_move_target_error",
5715 "mail_in_ui_folder_move_targets_error",
5716 tny_list_get_length (helper->headers)));
5720 movehelper = g_new0 (MoveToHelper, 1);
5722 #ifndef MODEST_TOOLKIT_HILDON2
5723 movehelper->banner = modest_platform_animation_banner (GTK_WIDGET (win), NULL,
5724 _CS("ckct_nw_pasting"));
5725 if (movehelper->banner != NULL) {
5726 g_object_ref (movehelper->banner);
5727 gtk_widget_show (GTK_WIDGET (movehelper->banner));
5730 if (MODEST_IS_MAIN_WINDOW (win)) {
5731 GtkWidget *header_view =
5732 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
5733 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
5734 movehelper->reference = get_next_after_selected_headers (MODEST_HEADER_VIEW (header_view));
5738 /* Perform the mail operation */
5739 mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT(win),
5740 xfer_messages_error_handler,
5741 g_object_ref (dst_account),
5743 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
5746 modest_mail_operation_xfer_msgs (mail_op,
5748 TNY_FOLDER (helper->dst_folder),
5753 g_object_unref (G_OBJECT (mail_op));
5756 g_object_unref (dst_account);
5757 g_object_unref (helper->dst_folder);
5758 g_object_unref (helper->headers);
5759 g_slice_free (XferMsgsHelper, helper);
5763 TnyFolder *src_folder;
5764 TnyFolderStore *dst_folder;
5765 gboolean delete_original;
5766 GtkWidget *folder_view;
5770 on_move_folder_cb (gboolean canceled,
5772 GtkWindow *parent_window,
5773 TnyAccount *account,
5776 MoveFolderInfo *info = (MoveFolderInfo*)user_data;
5777 GtkTreeSelection *sel;
5778 ModestMailOperation *mail_op = NULL;
5780 if (canceled || err || !MODEST_IS_WINDOW (parent_window)) {
5781 /* Note that the connection process can fail due to
5782 memory low conditions as it can not successfully
5783 store the summary */
5784 if (!modest_tny_account_store_check_disk_full_error (modest_runtime_get_account_store(),
5785 (GtkWidget*) parent_window, err,
5787 g_debug ("Error connecting when trying to move a folder");
5789 g_object_unref (G_OBJECT (info->src_folder));
5790 g_object_unref (G_OBJECT (info->dst_folder));
5795 MoveToHelper *helper = g_new0 (MoveToHelper, 1);
5796 #ifndef MODEST_TOOLKIT_HILDON2
5797 helper->banner = modest_platform_animation_banner (GTK_WIDGET (parent_window), NULL,
5798 _CS("ckct_nw_pasting"));
5799 if (helper->banner != NULL) {
5800 g_object_ref (helper->banner);
5801 gtk_widget_show (GTK_WIDGET(helper->banner));
5804 /* Clean folder on header view before moving it */
5805 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (info->folder_view));
5806 gtk_tree_selection_unselect_all (sel);
5808 /* Let gtk events run. We need that the folder
5809 view frees its reference to the source
5810 folder *before* issuing the mail operation
5811 so we need the signal handler of selection
5812 changed to happen before the mail
5814 while (gtk_events_pending ())
5815 gtk_main_iteration (); */
5818 modest_mail_operation_new_with_error_handling (G_OBJECT(parent_window),
5819 modest_ui_actions_move_folder_error_handler,
5820 g_object_ref (info->dst_folder), g_object_unref);
5821 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
5824 #ifndef MODEST_TOOLKIT_HILDON2
5825 if (MODEST_IS_MAIN_WINDOW (parent_window)) {
5826 modest_folder_view_select_folder (MODEST_FOLDER_VIEW(info->folder_view),
5827 TNY_FOLDER (info->dst_folder), TRUE);
5830 modest_mail_operation_xfer_folder (mail_op,
5831 TNY_FOLDER (info->src_folder),
5833 info->delete_original,
5836 g_object_unref (G_OBJECT (info->src_folder));
5838 /* if (modest_mail_operation_get_status (mail_op) == MODEST_MAIL_OPERATION_STATUS_SUCCESS) { */
5841 /* Unref mail operation */
5842 g_object_unref (G_OBJECT (mail_op));
5843 g_object_unref (G_OBJECT (info->dst_folder));
5848 get_account_from_folder_store (TnyFolderStore *folder_store)
5850 if (TNY_IS_ACCOUNT (folder_store))
5851 return g_object_ref (folder_store);
5853 return tny_folder_get_account (TNY_FOLDER (folder_store));
5856 #ifndef MODEST_TOOLKIT_HILDON2
5858 * UI handler for the "Move to" action when invoked from the
5862 modest_ui_actions_on_main_window_move_to (GtkAction *action,
5863 GtkWidget *folder_view,
5864 TnyFolderStore *dst_folder,
5865 ModestMainWindow *win)
5867 ModestHeaderView *header_view = NULL;
5868 TnyFolderStore *src_folder = NULL;
5870 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win));
5872 /* Get the source folder */
5873 src_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
5875 /* Get header view */
5876 header_view = (ModestHeaderView *)
5877 modest_main_window_get_child_widget (win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
5879 /* Get folder or messages to transfer */
5880 if (gtk_widget_is_focus (folder_view)) {
5881 gboolean do_xfer = TRUE;
5883 /* Allow only to transfer folders to the local root folder */
5884 if (TNY_IS_ACCOUNT (dst_folder) &&
5885 !MODEST_IS_TNY_LOCAL_FOLDERS_ACCOUNT (dst_folder) &&
5886 !modest_tny_account_is_memory_card_account (TNY_ACCOUNT (dst_folder))) {
5888 } else if (!TNY_IS_FOLDER (src_folder)) {
5889 g_warning ("%s: src_folder is not a TnyFolder.\n", __FUNCTION__);
5894 MoveFolderInfo *info = g_new0 (MoveFolderInfo, 1);
5895 DoubleConnectionInfo *connect_info = g_slice_new (DoubleConnectionInfo);
5897 info->src_folder = g_object_ref (src_folder);
5898 info->dst_folder = g_object_ref (dst_folder);
5899 info->delete_original = TRUE;
5900 info->folder_view = folder_view;
5902 connect_info->callback = on_move_folder_cb;
5903 connect_info->dst_account = get_account_from_folder_store (TNY_FOLDER_STORE (dst_folder));
5904 connect_info->data = info;
5906 modest_platform_double_connect_and_perform(GTK_WINDOW (win), TRUE,
5907 TNY_FOLDER_STORE (src_folder),
5910 } else if (gtk_widget_is_focus (GTK_WIDGET(header_view))) {
5913 headers = modest_header_view_get_selected_headers(header_view);
5915 /* Transfer the messages */
5916 modest_ui_actions_transfer_messages_helper (GTK_WINDOW (win), TNY_FOLDER (src_folder),
5917 headers, TNY_FOLDER (dst_folder));
5919 g_object_unref (headers);
5923 g_object_unref (src_folder);
5927 #ifdef MODEST_TOOLKIT_HILDON2
5929 * UI handler for the "Move to" action when invoked from the
5930 * ModestFolderWindow
5933 modest_ui_actions_on_folder_window_move_to (GtkWidget *folder_view,
5934 TnyFolderStore *dst_folder,
5938 TnyFolderStore *src_folder = NULL;
5939 TnyIterator *iterator;
5941 if (tny_list_get_length (selection) != 1)
5944 iterator = tny_list_create_iterator (selection);
5945 src_folder = TNY_FOLDER_STORE (tny_iterator_get_current (iterator));
5946 g_object_unref (iterator);
5949 gboolean do_xfer = TRUE;
5951 /* Allow only to transfer folders to the local root folder */
5952 if (TNY_IS_ACCOUNT (dst_folder) &&
5953 !MODEST_IS_TNY_LOCAL_FOLDERS_ACCOUNT (dst_folder) &&
5954 !modest_tny_account_is_memory_card_account (TNY_ACCOUNT (dst_folder))) {
5957 modest_platform_run_information_dialog (win,
5958 _("mail_in_ui_folder_move_target_error"),
5960 } else if (!TNY_IS_FOLDER (src_folder)) {
5961 g_warning ("%s: src_folder is not a TnyFolder.\n", __FUNCTION__);
5966 MoveFolderInfo *info = g_new0 (MoveFolderInfo, 1);
5967 DoubleConnectionInfo *connect_info = g_slice_new (DoubleConnectionInfo);
5969 info->src_folder = g_object_ref (src_folder);
5970 info->dst_folder = g_object_ref (dst_folder);
5971 info->delete_original = TRUE;
5972 info->folder_view = folder_view;
5974 connect_info->callback = on_move_folder_cb;
5975 connect_info->dst_account = get_account_from_folder_store (TNY_FOLDER_STORE (dst_folder));
5976 connect_info->data = info;
5978 modest_platform_double_connect_and_perform(GTK_WINDOW (win), TRUE,
5979 TNY_FOLDER_STORE (src_folder),
5984 g_object_unref (src_folder);
5990 modest_ui_actions_transfer_messages_helper (GtkWindow *win,
5991 TnyFolder *src_folder,
5993 TnyFolder *dst_folder)
5995 gboolean need_connection = TRUE;
5996 gboolean do_xfer = TRUE;
5997 XferMsgsHelper *helper;
5999 g_return_if_fail (TNY_IS_FOLDER (src_folder));
6000 g_return_if_fail (TNY_IS_FOLDER (dst_folder));
6001 g_return_if_fail (TNY_IS_LIST (headers));
6003 modest_ui_actions_xfer_messages_check (win, TNY_FOLDER_STORE (src_folder),
6004 headers, TNY_FOLDER (dst_folder),
6005 TRUE, &need_connection,
6008 /* If we don't want to transfer just return */
6012 /* Create the helper */
6013 helper = g_slice_new (XferMsgsHelper);
6014 helper->dst_folder = g_object_ref (dst_folder);
6015 helper->headers = g_object_ref (headers);
6017 if (need_connection) {
6018 DoubleConnectionInfo *connect_info = g_slice_new (DoubleConnectionInfo);
6019 connect_info->callback = xfer_messages_performer;
6020 connect_info->dst_account = tny_folder_get_account (TNY_FOLDER (dst_folder));
6021 connect_info->data = helper;
6023 modest_platform_double_connect_and_perform(GTK_WINDOW (win), TRUE,
6024 TNY_FOLDER_STORE (src_folder),
6027 TnyAccount *src_account = get_account_from_folder_store (TNY_FOLDER_STORE (src_folder));
6028 xfer_messages_performer (FALSE, NULL, GTK_WINDOW (win),
6029 src_account, helper);
6030 g_object_unref (src_account);
6035 * UI handler for the "Move to" action when invoked from the
6036 * ModestMsgViewWindow
6039 modest_ui_actions_on_window_move_to (GtkAction *action,
6041 TnyFolderStore *dst_folder,
6044 TnyFolder *src_folder = NULL;
6046 g_return_if_fail (TNY_IS_FOLDER (dst_folder));
6049 TnyHeader *header = NULL;
6052 iter = tny_list_create_iterator (headers);
6053 header = (TnyHeader *) tny_iterator_get_current (iter);
6054 src_folder = tny_header_get_folder (header);
6056 /* Transfer the messages */
6057 modest_ui_actions_transfer_messages_helper (GTK_WINDOW (win), src_folder,
6059 TNY_FOLDER (dst_folder));
6062 g_object_unref (header);
6063 g_object_unref (iter);
6064 g_object_unref (src_folder);
6069 modest_ui_actions_on_move_to (GtkAction *action,
6072 modest_ui_actions_on_edit_mode_move_to (win);
6076 modest_ui_actions_on_edit_mode_move_to (ModestWindow *win)
6078 GtkWidget *dialog = NULL;
6079 MoveToInfo *helper = NULL;
6080 TnyList *list_to_move;
6082 g_return_val_if_fail (MODEST_IS_WINDOW (win), FALSE);
6084 #ifndef MODEST_TOOLKIT_HILDON2
6085 /* Get the main window if exists */
6086 ModestMainWindow *main_window;
6087 if (MODEST_IS_MAIN_WINDOW (win))
6088 main_window = MODEST_MAIN_WINDOW (win);
6091 MODEST_MAIN_WINDOW (modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (),
6092 FALSE)); /* don't create */
6095 list_to_move = modest_platform_get_list_to_move (MODEST_WINDOW (win));
6100 if (tny_list_get_length (list_to_move) < 1) {
6101 g_object_unref (list_to_move);
6105 /* Create and run the dialog */
6106 dialog = create_move_to_dialog (GTK_WINDOW (win), NULL, list_to_move);
6107 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (),
6108 GTK_WINDOW (dialog),
6112 helper = g_slice_new0 (MoveToInfo);
6113 helper->list = list_to_move;
6116 /* Listen to response signal */
6117 g_signal_connect (dialog, "response", G_CALLBACK (on_move_to_dialog_response), helper);
6119 /* Show the dialog */
6120 gtk_widget_show (dialog);
6126 * Calls #HeadersFunc for each header already selected in the main
6127 * window or the message currently being shown in the msg view window
6130 do_headers_action (ModestWindow *win,
6134 TnyList *headers_list = NULL;
6135 TnyIterator *iter = NULL;
6136 TnyHeader *header = NULL;
6137 TnyFolder *folder = NULL;
6140 headers_list = get_selected_headers (win);
6144 /* Get the folder */
6145 iter = tny_list_create_iterator (headers_list);
6146 header = TNY_HEADER (tny_iterator_get_current (iter));
6148 folder = tny_header_get_folder (header);
6149 g_object_unref (header);
6152 /* Call the function for each header */
6153 while (!tny_iterator_is_done (iter)) {
6154 header = TNY_HEADER (tny_iterator_get_current (iter));
6155 func (header, win, user_data);
6156 g_object_unref (header);
6157 tny_iterator_next (iter);
6160 /* Trick: do a poke status in order to speed up the signaling
6163 tny_folder_poke_status (folder);
6164 g_object_unref (folder);
6168 g_object_unref (iter);
6169 g_object_unref (headers_list);
6173 modest_ui_actions_view_attachment (GtkAction *action,
6174 ModestWindow *window)
6176 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
6177 modest_msg_view_window_view_attachment (MODEST_MSG_VIEW_WINDOW (window), NULL);
6179 /* not supported window for this action */
6180 g_return_if_reached ();
6185 modest_ui_actions_save_attachments (GtkAction *action,
6186 ModestWindow *window)
6188 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
6190 if (modest_platform_check_memory_low (MODEST_WINDOW(window), TRUE))
6193 modest_msg_view_window_save_attachments (MODEST_MSG_VIEW_WINDOW (window), NULL);
6195 /* not supported window for this action */
6196 g_return_if_reached ();
6201 modest_ui_actions_remove_attachments (GtkAction *action,
6202 ModestWindow *window)
6204 #ifndef MODEST_TOOLKIT_HILDON2
6205 if (MODEST_IS_MAIN_WINDOW (window)) {
6206 modest_ui_actions_on_main_window_remove_attachments (action, MODEST_MAIN_WINDOW (window));
6207 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
6209 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
6211 modest_msg_view_window_remove_attachments (MODEST_MSG_VIEW_WINDOW (window), FALSE);
6213 /* not supported window for this action */
6214 g_return_if_reached ();
6219 modest_ui_actions_on_settings (GtkAction *action,
6224 dialog = modest_platform_get_global_settings_dialog ();
6225 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (win));
6226 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
6227 gtk_widget_show_all (dialog);
6229 gtk_dialog_run (GTK_DIALOG (dialog));
6231 gtk_widget_destroy (dialog);
6235 modest_ui_actions_on_help (GtkAction *action,
6238 /* Help app is not available at all in fremantle */
6239 #ifndef MODEST_TOOLKIT_HILDON2
6240 const gchar *help_id;
6242 g_return_if_fail (win && GTK_IS_WINDOW(win));
6244 help_id = modest_window_mgr_get_help_id (modest_runtime_get_window_mgr(), win);
6247 modest_platform_show_help (GTK_WINDOW (win), help_id);
6252 modest_ui_actions_on_csm_help (GtkAction *action,
6255 /* Help app is not available at all in fremantle */
6256 #ifndef MODEST_TOOLKIT_HILDON2
6258 const gchar* help_id = NULL;
6259 GtkWidget *folder_view;
6260 TnyFolderStore *folder_store;
6262 g_return_if_fail (win && MODEST_IS_MAIN_WINDOW (win));
6264 /* Get selected folder */
6265 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
6266 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
6267 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
6269 /* Switch help_id */
6270 if (folder_store && TNY_IS_FOLDER (folder_store))
6271 help_id = modest_tny_folder_get_help_id (TNY_FOLDER (folder_store));
6274 g_object_unref (folder_store);
6277 modest_platform_show_help (GTK_WINDOW (win), help_id);
6279 modest_ui_actions_on_help (action, win);
6284 retrieve_contents_cb (ModestMailOperation *mail_op,
6291 /* We only need this callback to show an error in case of
6292 memory low condition */
6293 if (!modest_ui_actions_msg_retrieval_check (mail_op, header, msg)) {
6294 g_debug ("%s: message failed to retrieve. Memory low?", __FUNCTION__);
6299 retrieve_msg_contents_performer (gboolean canceled,
6301 GtkWindow *parent_window,
6302 TnyAccount *account,
6305 ModestMailOperation *mail_op;
6306 TnyList *headers = TNY_LIST (user_data);
6308 if (err || canceled) {
6309 modest_tny_account_store_check_disk_full_error (modest_runtime_get_account_store(),
6310 (GtkWidget *) parent_window, err,
6315 /* Create mail operation */
6316 mail_op = modest_mail_operation_new_with_error_handling ((GObject *) parent_window,
6317 modest_ui_actions_disk_operations_error_handler,
6319 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
6320 modest_mail_operation_get_msgs_full (mail_op, headers, retrieve_contents_cb, NULL, NULL);
6323 g_object_unref (mail_op);
6325 g_object_unref (headers);
6326 g_object_unref (account);
6330 modest_ui_actions_on_retrieve_msg_contents (GtkAction *action,
6331 ModestWindow *window)
6333 TnyList *headers = NULL;
6334 TnyAccount *account = NULL;
6335 TnyIterator *iter = NULL;
6336 TnyHeader *header = NULL;
6337 TnyFolder *folder = NULL;
6340 headers = get_selected_headers (window);
6344 /* Pick the account */
6345 iter = tny_list_create_iterator (headers);
6346 header = TNY_HEADER (tny_iterator_get_current (iter));
6347 folder = tny_header_get_folder (header);
6348 account = tny_folder_get_account (folder);
6349 g_object_unref (folder);
6350 g_object_unref (header);
6351 g_object_unref (iter);
6353 /* Connect and perform the message retrieval */
6354 modest_platform_connect_and_perform ((GtkWindow *) window, TRUE,
6355 g_object_ref (account),
6356 retrieve_msg_contents_performer,
6357 g_object_ref (headers));
6360 g_object_unref (account);
6361 g_object_unref (headers);
6365 modest_ui_actions_check_toolbar_dimming_rules (ModestWindow *window)
6367 g_return_if_fail (MODEST_IS_WINDOW (window));
6370 modest_window_check_dimming_rules_group (window, MODEST_DIMMING_RULES_TOOLBAR);
6374 modest_ui_actions_check_menu_dimming_rules (ModestWindow *window)
6376 g_return_if_fail (MODEST_IS_WINDOW (window));
6379 modest_window_check_dimming_rules_group (window, MODEST_DIMMING_RULES_MENU);
6383 modest_ui_actions_on_email_menu_activated (GtkAction *action,
6384 ModestWindow *window)
6386 g_return_if_fail (MODEST_IS_WINDOW (window));
6389 modest_ui_actions_check_menu_dimming_rules (window);
6393 modest_ui_actions_on_edit_menu_activated (GtkAction *action,
6394 ModestWindow *window)
6396 g_return_if_fail (MODEST_IS_WINDOW (window));
6399 modest_ui_actions_check_menu_dimming_rules (window);
6403 modest_ui_actions_on_view_menu_activated (GtkAction *action,
6404 ModestWindow *window)
6406 g_return_if_fail (MODEST_IS_WINDOW (window));
6409 modest_ui_actions_check_menu_dimming_rules (window);
6413 modest_ui_actions_on_format_menu_activated (GtkAction *action,
6414 ModestWindow *window)
6416 g_return_if_fail (MODEST_IS_WINDOW (window));
6419 modest_ui_actions_check_menu_dimming_rules (window);
6423 modest_ui_actions_on_tools_menu_activated (GtkAction *action,
6424 ModestWindow *window)
6426 g_return_if_fail (MODEST_IS_WINDOW (window));
6429 modest_ui_actions_check_menu_dimming_rules (window);
6433 modest_ui_actions_on_attachment_menu_activated (GtkAction *action,
6434 ModestWindow *window)
6436 g_return_if_fail (MODEST_IS_WINDOW (window));
6439 modest_ui_actions_check_menu_dimming_rules (window);
6443 modest_ui_actions_on_toolbar_csm_menu_activated (GtkAction *action,
6444 ModestWindow *window)
6446 g_return_if_fail (MODEST_IS_WINDOW (window));
6449 modest_ui_actions_check_menu_dimming_rules (window);
6453 modest_ui_actions_on_folder_view_csm_menu_activated (GtkAction *action,
6454 ModestWindow *window)
6456 g_return_if_fail (MODEST_IS_WINDOW (window));
6459 modest_ui_actions_check_menu_dimming_rules (window);
6463 modest_ui_actions_on_header_view_csm_menu_activated (GtkAction *action,
6464 ModestWindow *window)
6466 g_return_if_fail (MODEST_IS_WINDOW (window));
6469 modest_ui_actions_check_menu_dimming_rules (window);
6473 modest_ui_actions_on_search_messages (GtkAction *action, ModestWindow *window)
6475 g_return_if_fail (MODEST_IS_WINDOW (window));
6477 /* we check for low-mem; in that case, show a warning, and don't allow
6480 if (modest_platform_check_memory_low (window, TRUE))
6483 modest_platform_show_search_messages (GTK_WINDOW (window));
6487 modest_ui_actions_on_open_addressbook (GtkAction *action, ModestWindow *win)
6489 g_return_if_fail (MODEST_IS_WINDOW (win));
6492 /* we check for low-mem; in that case, show a warning, and don't allow
6493 * for the addressbook
6495 if (modest_platform_check_memory_low (win, TRUE))
6499 modest_platform_show_addressbook (GTK_WINDOW (win));
6504 modest_ui_actions_on_toggle_find_in_page (GtkAction *action,
6505 ModestWindow *window)
6508 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
6510 if (GTK_IS_TOGGLE_ACTION (action))
6511 active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
6515 modest_msg_edit_window_toggle_isearch_toolbar (MODEST_MSG_EDIT_WINDOW (window),
6519 #ifndef MODEST_TOOLKIT_HILDON2
6521 on_send_receive_finished (ModestMailOperation *mail_op,
6524 GtkWidget *header_view, *folder_view;
6525 TnyFolderStore *folder_store;
6526 ModestMainWindow *main_win = MODEST_MAIN_WINDOW (user_data);
6528 /* Set send/receive operation finished */
6529 modest_main_window_notify_send_receive_completed (main_win);
6531 /* Don't refresh the current folder if there were any errors */
6532 if (modest_mail_operation_get_status (mail_op) !=
6533 MODEST_MAIL_OPERATION_STATUS_SUCCESS)
6536 /* Refresh the current folder if we're viewing a window. We do
6537 this because the user won't be able to see the new mails in
6538 the selected folder after a Send&Receive because it only
6539 performs a poke_status, i.e, only the number of read/unread
6540 messages is updated, but the new headers are not
6542 folder_view = modest_main_window_get_child_widget (main_win,
6543 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
6547 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
6549 /* Do not need to refresh INBOX again because the
6550 update_account does it always automatically */
6551 if (folder_store && TNY_IS_FOLDER (folder_store) &&
6552 tny_folder_get_folder_type (TNY_FOLDER (folder_store)) != TNY_FOLDER_TYPE_INBOX) {
6553 ModestMailOperation *refresh_op;
6555 header_view = modest_main_window_get_child_widget (main_win,
6556 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
6558 /* We do not need to set the contents style
6559 because it hasn't changed. We also do not
6560 need to save the widget status. Just force
6562 refresh_op = modest_mail_operation_new (G_OBJECT (main_win));
6563 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), refresh_op);
6564 modest_mail_operation_refresh_folder (refresh_op, TNY_FOLDER (folder_store),
6565 folder_refreshed_cb, main_win);
6566 g_object_unref (refresh_op);
6570 g_object_unref (folder_store);
6575 modest_ui_actions_on_send_queue_error_happened (TnySendQueue *self,
6581 const gchar* server_name = NULL;
6582 TnyTransportAccount *transport;
6583 gchar *message = NULL;
6584 ModestProtocol *protocol;
6586 /* Don't show anything if the user cancelled something or the
6587 * send receive request is not interactive. Authentication
6588 * errors are managed by the account store so no need to show
6589 * a dialog here again */
6590 if (err->code == TNY_SYSTEM_ERROR_CANCEL ||
6591 err->code == TNY_SERVICE_ERROR_AUTHENTICATE ||
6592 !modest_tny_send_queue_get_requested_send_receive (MODEST_TNY_SEND_QUEUE (self)))
6596 /* Get the server name. Note that we could be using a
6597 connection specific transport account */
6598 transport = (TnyTransportAccount *)
6599 tny_camel_send_queue_get_transport_account (TNY_CAMEL_SEND_QUEUE (self));
6601 ModestTnyAccountStore *acc_store;
6602 const gchar *acc_name;
6603 TnyTransportAccount *conn_specific;
6605 acc_store = modest_runtime_get_account_store();
6606 acc_name = modest_tny_account_get_parent_modest_account_name_for_server_account (TNY_ACCOUNT (transport));
6607 conn_specific = (TnyTransportAccount *)
6608 modest_tny_account_store_get_transport_account_for_open_connection (acc_store, acc_name);
6609 if (conn_specific) {
6610 server_name = tny_account_get_hostname (TNY_ACCOUNT (conn_specific));
6611 g_object_unref (conn_specific);
6613 server_name = tny_account_get_hostname (TNY_ACCOUNT (transport));
6615 g_object_unref (transport);
6619 protocol = modest_protocol_registry_get_protocol_by_name (modest_runtime_get_protocol_registry (),
6620 MODEST_PROTOCOL_REGISTRY_TRANSPORT_STORE_PROTOCOLS,
6621 tny_account_get_proto (TNY_ACCOUNT (transport)));
6623 g_warning ("%s: Account with no proto", __FUNCTION__);
6627 /* Show the appropriate message text for the GError: */
6628 switch (err->code) {
6629 case TNY_SERVICE_ERROR_CONNECT:
6630 message = modest_protocol_get_translation (protocol,
6631 MODEST_PROTOCOL_TRANSLATION_ACCOUNT_CONNECTION_ERROR,
6634 case TNY_SERVICE_ERROR_SEND:
6635 message = g_strdup (_CS("sfil_ib_unable_to_send"));
6637 case TNY_SERVICE_ERROR_UNAVAILABLE:
6638 message = modest_protocol_get_translation (protocol,
6639 MODEST_PROTOCOL_TRANSLATION_CONNECT_ERROR,
6643 g_warning ("%s: unexpected ERROR %d",
6644 __FUNCTION__, err->code);
6645 message = g_strdup (_CS("sfil_ib_unable_to_send"));
6649 modest_platform_run_information_dialog (NULL, message, FALSE);
6654 modest_ui_actions_on_send_queue_status_changed (ModestTnySendQueue *send_queue,
6659 ModestWindow *top_window = NULL;
6660 ModestWindowMgr *mgr = NULL;
6661 GtkWidget *header_view = NULL;
6662 TnyFolder *selected_folder = NULL;
6663 TnyFolderType folder_type;
6665 mgr = modest_runtime_get_window_mgr ();
6666 top_window = modest_window_mgr_get_current_top (mgr);
6671 #ifndef MODEST_TOOLKIT_HILDON2
6672 if (MODEST_IS_MAIN_WINDOW (top_window)) {
6673 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (top_window),
6674 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
6677 if (MODEST_IS_HEADER_WINDOW (top_window)) {
6678 header_view = (GtkWidget *)
6679 modest_header_window_get_header_view (MODEST_HEADER_WINDOW (top_window));
6683 /* Get selected folder */
6685 selected_folder = modest_header_view_get_folder (MODEST_HEADER_VIEW (header_view));
6686 if (!selected_folder)
6689 /* gtk_tree_view_column_queue_resize is only available in GTK+ 2.8 */
6690 #if GTK_CHECK_VERSION(2, 8, 0)
6691 folder_type = modest_tny_folder_guess_folder_type (selected_folder);
6692 if (folder_type == TNY_FOLDER_TYPE_OUTBOX) {
6693 GtkTreeViewColumn *tree_column;
6695 tree_column = gtk_tree_view_get_column (GTK_TREE_VIEW (header_view),
6696 TNY_GTK_HEADER_LIST_MODEL_FROM_COLUMN);
6698 gtk_tree_view_column_queue_resize (tree_column);
6700 #else /* #if GTK_CHECK_VERSION(2, 8, 0) */
6701 gtk_widget_queue_draw (header_view);
6704 #ifndef MODEST_TOOLKIT_HILDON2
6705 /* Rerun dimming rules, because the message could become deletable for example */
6706 modest_window_check_dimming_rules_group (MODEST_WINDOW (top_window),
6707 MODEST_DIMMING_RULES_TOOLBAR);
6708 modest_window_check_dimming_rules_group (MODEST_WINDOW (top_window),
6709 MODEST_DIMMING_RULES_MENU);
6713 g_object_unref (selected_folder);
6717 modest_ui_actions_on_account_connection_error (GtkWindow *parent_window,
6718 TnyAccount *account)
6720 ModestProtocolType protocol_type;
6721 ModestProtocol *protocol;
6722 gchar *error_note = NULL;
6724 protocol_type = modest_tny_account_get_protocol_type (account);
6725 protocol = modest_protocol_registry_get_protocol_by_type (modest_runtime_get_protocol_registry (),
6728 error_note = modest_protocol_get_translation (protocol, MODEST_PROTOCOL_TRANSLATION_ACCOUNT_CONNECTION_ERROR, tny_account_get_hostname (account));
6729 if (error_note == NULL) {
6730 g_warning ("%s: This should not be reached", __FUNCTION__);
6732 modest_platform_run_information_dialog (parent_window, error_note, FALSE);
6733 g_free (error_note);
6738 modest_ui_actions_get_msg_already_deleted_error_msg (ModestWindow *win)
6742 TnyFolderStore *folder = NULL;
6743 TnyAccount *account = NULL;
6744 ModestProtocolType proto;
6745 ModestProtocol *protocol;
6746 TnyHeader *header = NULL;
6748 #ifndef MODEST_TOOLKIT_HILDON2
6749 if (MODEST_IS_MAIN_WINDOW (win)) {
6750 GtkWidget *header_view;
6751 TnyList* headers = NULL;
6753 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
6754 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
6755 headers = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW (header_view));
6756 if (!headers || tny_list_get_length (headers) == 0) {
6758 g_object_unref (headers);
6761 iter = tny_list_create_iterator (headers);
6762 header = TNY_HEADER (tny_iterator_get_current (iter));
6763 folder = TNY_FOLDER_STORE (tny_header_get_folder (header));
6764 g_object_unref (iter);
6765 g_object_unref (headers);
6767 if (MODEST_IS_HEADER_WINDOW (win)) {
6768 GtkWidget *header_view;
6769 TnyList* headers = NULL;
6771 header_view = GTK_WIDGET (modest_header_window_get_header_view (MODEST_HEADER_WINDOW (win)));
6772 headers = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW (header_view));
6773 if (!headers || tny_list_get_length (headers) == 0) {
6775 g_object_unref (headers);
6778 iter = tny_list_create_iterator (headers);
6779 header = TNY_HEADER (tny_iterator_get_current (iter));
6781 folder = TNY_FOLDER_STORE (tny_header_get_folder (header));
6783 g_warning ("List should contain headers");
6785 g_object_unref (iter);
6786 g_object_unref (headers);
6788 } else if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
6789 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
6791 folder = TNY_FOLDER_STORE (tny_header_get_folder (header));
6794 if (!header || !folder)
6797 /* Get the account type */
6798 account = tny_folder_get_account (TNY_FOLDER (folder));
6799 proto = modest_tny_account_get_protocol_type (account);
6800 protocol = modest_protocol_registry_get_protocol_by_type (modest_runtime_get_protocol_registry (),
6803 subject = tny_header_dup_subject (header);
6804 msg = modest_protocol_get_translation (protocol, MODEST_PROTOCOL_TRANSLATION_MSG_NOT_AVAILABLE, subject);
6808 msg = g_strdup_printf (_("mail_ni_ui_folder_get_msg_folder_error"));
6814 g_object_unref (account);
6816 g_object_unref (folder);
6818 g_object_unref (header);
6824 modest_ui_actions_on_delete_account (GtkWindow *parent_window,
6825 const gchar *account_name,
6826 const gchar *account_title)
6828 ModestAccountMgr *account_mgr;
6831 ModestProtocol *protocol;
6832 gboolean removed = FALSE;
6834 g_return_val_if_fail (account_name, FALSE);
6835 g_return_val_if_fail (account_title, FALSE);
6837 account_mgr = modest_runtime_get_account_mgr();
6839 /* The warning text depends on the account type: */
6840 protocol = modest_protocol_registry_get_protocol_by_type (modest_runtime_get_protocol_registry (),
6841 modest_account_mgr_get_store_protocol (account_mgr,
6843 txt = modest_protocol_get_translation (protocol,
6844 MODEST_PROTOCOL_TRANSLATION_DELETE_MAILBOX,
6847 txt = g_strdup_printf (_("emev_nc_delete_mailbox"), account_title);
6849 response = modest_platform_run_confirmation_dialog (parent_window, txt);
6853 if (response == GTK_RESPONSE_OK) {
6854 /* Remove account. If it succeeds then it also removes
6855 the account from the ModestAccountView: */
6856 gboolean is_default = FALSE;
6857 gchar *default_account_name = modest_account_mgr_get_default_account (account_mgr);
6858 if (default_account_name && (strcmp (default_account_name, account_name) == 0))
6860 g_free (default_account_name);
6862 removed = modest_account_mgr_remove_account (account_mgr, account_name);
6864 /* Close all email notifications, we cannot
6865 distinguish if the notification belongs to
6866 this account or not, so for safety reasons
6867 we remove them all */
6868 modest_platform_remove_new_mail_notifications (FALSE);
6870 g_warning ("%s: modest_account_mgr_remove_account() failed.\n", __FUNCTION__);
6877 on_fetch_images_performer (gboolean canceled,
6879 GtkWindow *parent_window,
6880 TnyAccount *account,
6883 if (err || canceled) {
6884 /* Show an unable to retrieve images ??? */
6888 /* Note that the user could have closed the window while connecting */
6889 if (GTK_WIDGET_VISIBLE (parent_window))
6890 modest_msg_view_window_fetch_images ((ModestMsgViewWindow *) parent_window);
6891 g_object_unref ((GObject *) user_data);
6895 modest_ui_actions_on_fetch_images (GtkAction *action,
6896 ModestWindow *window)
6898 g_return_if_fail (MODEST_IS_MSG_VIEW_WINDOW (window));
6900 modest_platform_connect_and_perform ((GtkWindow *) window, TRUE,
6902 on_fetch_images_performer,
6903 g_object_ref (window));
6907 modest_ui_actions_on_reload_message (const gchar *msg_id)
6909 ModestWindow *window = NULL;
6911 g_return_if_fail (msg_id && msg_id[0] != '\0');
6912 if (!modest_window_mgr_find_registered_message_uid (modest_runtime_get_window_mgr (),
6918 if (window == NULL || !MODEST_IS_MSG_VIEW_WINDOW (window))
6921 modest_msg_view_window_reload (MODEST_MSG_VIEW_WINDOW (window));
6924 /** Check whether any connections are active, and cancel them if
6926 * Returns TRUE is there was no problem,
6927 * or if an operation was cancelled so we can continue.
6928 * Returns FALSE if the user chose to cancel his request instead.
6932 modest_ui_actions_check_for_active_account (ModestWindow *self,
6933 const gchar* account_name)
6935 ModestTnySendQueue *send_queue;
6936 ModestTnyAccountStore *acc_store;
6937 ModestMailOperationQueue* queue;
6938 TnyConnectionStatus store_conn_status;
6939 TnyAccount *store_account = NULL, *transport_account = NULL;
6940 gboolean retval = TRUE, sending = FALSE;
6942 acc_store = modest_runtime_get_account_store ();
6943 queue = modest_runtime_get_mail_operation_queue ();
6946 modest_tny_account_store_get_server_account (acc_store,
6948 TNY_ACCOUNT_TYPE_STORE);
6950 /* This could happen if the account was deleted before the
6951 call to this function */
6956 modest_tny_account_store_get_server_account (acc_store,
6958 TNY_ACCOUNT_TYPE_TRANSPORT);
6960 /* This could happen if the account was deleted before the
6961 call to this function */
6962 if (!transport_account) {
6963 g_object_unref (store_account);
6967 /* If the transport account was not used yet, then the send
6968 queue could not exist (it's created on demand) */
6969 send_queue = modest_runtime_get_send_queue (TNY_TRANSPORT_ACCOUNT (transport_account), FALSE);
6970 if (TNY_IS_SEND_QUEUE (send_queue))
6971 sending = modest_tny_send_queue_sending_in_progress (send_queue);
6973 store_conn_status = tny_account_get_connection_status (store_account);
6974 if (store_conn_status == TNY_CONNECTION_STATUS_CONNECTED || sending) {
6977 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (self),
6978 _("emev_nc_disconnect_account"));
6979 if (response == GTK_RESPONSE_OK) {
6988 /* FIXME: We should only cancel those of this account */
6989 modest_mail_operation_queue_cancel_all (queue);
6991 /* Also disconnect the account */
6992 if ((tny_account_get_connection_status (store_account) != TNY_CONNECTION_STATUS_DISCONNECTED) &&
6993 (tny_account_get_connection_status (store_account) != TNY_CONNECTION_STATUS_DISCONNECTED_BROKEN)) {
6994 tny_camel_account_set_online (TNY_CAMEL_ACCOUNT (store_account),
6998 tny_camel_account_set_online (TNY_CAMEL_ACCOUNT (transport_account),
7004 g_object_unref (store_account);
7005 g_object_unref (transport_account);