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 #ifdef MODEST_TOOLKIT_HILDON2
54 #include <modest-accounts-window.h>
55 #include <hildon/hildon-pannable-area.h>
56 #include <hildon/hildon-gtk.h>
57 #include <modest-header-window.h>
58 #include <modest-folder-window.h>
59 #include <modest-maemo-utils.h>
62 #ifdef MODEST_PLATFORM_MAEMO
63 #include "maemo/modest-osso-state-saving.h"
64 #endif /* MODEST_PLATFORM_MAEMO */
65 #ifndef MODEST_TOOLKIT_GTK
66 #include "maemo/modest-hildon-includes.h"
67 #include "maemo/modest-connection-specific-smtp-window.h"
68 #endif /* !MODEST_TOOLKIT_GTK */
69 #include <modest-utils.h>
71 #include "widgets/modest-ui-constants.h"
72 #include <widgets/modest-main-window.h>
73 #include <widgets/modest-msg-view-window.h>
74 #include <widgets/modest-account-view-window.h>
75 #include <widgets/modest-details-dialog.h>
76 #include <widgets/modest-attachments-view.h>
77 #include "widgets/modest-folder-view.h"
78 #include "widgets/modest-global-settings-dialog.h"
79 #include "modest-account-mgr-helpers.h"
80 #include "modest-mail-operation.h"
81 #include "modest-text-utils.h"
82 #include <modest-widget-memory.h>
83 #include <tny-error.h>
84 #include <tny-simple-list.h>
85 #include <tny-msg-view.h>
86 #include <tny-device.h>
87 #include <tny-merge-folder.h>
89 #include <gtkhtml/gtkhtml.h>
91 #define MODEST_MOVE_TO_DIALOG_FOLDER_VIEW "move-to-dialog-folder-view"
93 typedef struct _GetMsgAsyncHelper {
95 ModestMailOperation *mail_op;
102 typedef enum _ReplyForwardAction {
106 } ReplyForwardAction;
108 typedef struct _ReplyForwardHelper {
109 guint reply_forward_type;
110 ReplyForwardAction action;
113 GtkWidget *parent_window;
115 } ReplyForwardHelper;
117 typedef struct _MoveToHelper {
118 GtkTreeRowReference *reference;
122 typedef struct _PasteAsAttachmentHelper {
123 ModestMsgEditWindow *window;
125 } PasteAsAttachmentHelper;
133 * The do_headers_action uses this kind of functions to perform some
134 * action to each member of a list of headers
136 typedef void (*HeadersFunc) (TnyHeader *header, ModestWindow *win, gpointer user_data);
138 static void do_headers_action (ModestWindow *win,
142 static void open_msg_cb (ModestMailOperation *mail_op,
149 static void reply_forward_cb (ModestMailOperation *mail_op,
156 static void reply_forward (ReplyForwardAction action, ModestWindow *win);
158 #ifndef MODEST_TOOLKIT_HILDON2
159 static void folder_refreshed_cb (ModestMailOperation *mail_op,
163 static void on_send_receive_finished (ModestMailOperation *mail_op,
167 static gint header_list_count_uncached_msgs (TnyList *header_list);
169 static gboolean connect_to_get_msg (ModestWindow *win,
170 gint num_of_uncached_msgs,
171 TnyAccount *account);
173 static gboolean remote_folder_has_leave_on_server (TnyFolderStore *folder);
175 static void do_create_folder (GtkWindow *window,
176 TnyFolderStore *parent_folder,
177 const gchar *suggested_name);
179 static TnyAccount *get_account_from_folder_store (TnyFolderStore *folder_store);
181 #ifndef MODEST_TOOLKIT_HILDON2
182 static void modest_ui_actions_on_main_window_move_to (GtkAction *action,
183 GtkWidget *folder_view,
184 TnyFolderStore *dst_folder,
185 ModestMainWindow *win);
188 static void modest_ui_actions_on_folder_window_move_to (GtkWidget *folder_view,
189 TnyFolderStore *dst_folder,
194 static void modest_ui_actions_on_window_move_to (GtkAction *action,
195 TnyList *list_to_move,
196 TnyFolderStore *dst_folder,
200 * This function checks whether a TnyFolderStore is a pop account
203 remote_folder_has_leave_on_server (TnyFolderStore *folder)
208 g_return_val_if_fail (TNY_IS_FOLDER_STORE (folder), FALSE);
210 account = get_account_from_folder_store (folder);
211 result = (modest_protocol_registry_protocol_type_has_leave_on_server (modest_runtime_get_protocol_registry (),
212 modest_tny_account_get_protocol_type (account)));
213 g_object_unref (account);
218 /* FIXME: this should be merged with the similar code in modest-account-view-window */
219 /* Show the account creation wizard dialog.
220 * returns: TRUE if an account was created. FALSE if the user cancelled.
223 modest_ui_actions_run_account_setup_wizard (ModestWindow *win)
225 gboolean result = FALSE;
227 gint dialog_response;
229 /* there is no such wizard yet */
230 wizard = GTK_WINDOW (modest_platform_get_account_settings_wizard ());
231 modest_window_mgr_set_modal (modest_runtime_get_window_mgr(), GTK_WINDOW (wizard), (GtkWindow *) win);
233 #ifndef MODEST_TOOLKIT_HILDON2
234 /* always present a main window in the background
235 * we do it here, so we cannot end up with two wizards (as this
236 * function might be called in modest_window_mgr_get_main_window as well */
238 win = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr(),
239 TRUE); /* create if not existent */
243 ModestWindowMgr *mgr;
245 mgr = modest_runtime_get_window_mgr ();
247 window_list = modest_window_mgr_get_window_list (mgr);
248 if (window_list == NULL) {
249 win = MODEST_WINDOW (modest_accounts_window_new ());
250 if (modest_window_mgr_register_window (mgr, win, NULL)) {
251 gtk_widget_show_all (GTK_WIDGET (win));
253 gtk_widget_destroy (GTK_WIDGET (win));
258 g_list_free (window_list);
264 gtk_window_set_transient_for (GTK_WINDOW (wizard), GTK_WINDOW (win));
266 /* make sure the mainwindow is visible. We need to present the
267 wizard again to give it the focus back. show_all are needed
268 in order to get the widgets properly drawn (MainWindow main
269 paned won't be in its right position and the dialog will be
271 #ifndef MODEST_TOOLKIT_HILDON2
272 gtk_widget_show_all (GTK_WIDGET (win));
273 gtk_widget_show_all (GTK_WIDGET (wizard));
274 gtk_window_present (GTK_WINDOW (win));
275 gtk_window_present (GTK_WINDOW (wizard));
278 dialog_response = gtk_dialog_run (GTK_DIALOG (wizard));
279 gtk_widget_destroy (GTK_WIDGET (wizard));
280 if (gtk_events_pending ())
281 gtk_main_iteration ();
283 if (dialog_response == GTK_RESPONSE_CANCEL) {
286 /* Check whether an account was created: */
287 result = modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
294 modest_ui_actions_on_about (GtkAction *action, ModestWindow *win)
297 const gchar *authors[] = {
298 "Dirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>",
301 about = gtk_about_dialog_new ();
302 gtk_about_dialog_set_name (GTK_ABOUT_DIALOG(about), PACKAGE_NAME);
303 gtk_about_dialog_set_version (GTK_ABOUT_DIALOG(about),PACKAGE_VERSION);
304 gtk_about_dialog_set_copyright (GTK_ABOUT_DIALOG(about),
305 _("Copyright (c) 2006, Nokia Corporation\n"
306 "All rights reserved."));
307 gtk_about_dialog_set_comments (GTK_ABOUT_DIALOG(about),
308 _("a modest e-mail client\n\n"
309 "design and implementation: Dirk-Jan C. Binnema\n"
310 "contributions from the fine people at KC and Ig\n"
311 "uses the tinymail email framework written by Philip van Hoof"));
312 gtk_about_dialog_set_authors (GTK_ABOUT_DIALOG(about), authors);
313 gtk_about_dialog_set_website (GTK_ABOUT_DIALOG(about), "http://modest.garage.maemo.org");
314 gtk_window_set_transient_for (GTK_WINDOW (about), GTK_WINDOW (win));
315 gtk_window_set_modal (GTK_WINDOW (about), TRUE);
317 gtk_dialog_run (GTK_DIALOG (about));
318 gtk_widget_destroy(about);
322 * Gets the list of currently selected messages. If the win is the
323 * main window, then it returns a newly allocated list of the headers
324 * selected in the header view. If win is the msg view window, then
325 * the value returned is a list with just a single header.
327 * The caller of this funcion must free the list.
330 get_selected_headers (ModestWindow *win)
332 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
333 /* for MsgViewWindows, we simply return a list with one element */
335 TnyList *list = NULL;
337 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
338 if (header != NULL) {
339 list = tny_simple_list_new ();
340 tny_list_prepend (list, G_OBJECT(header));
341 g_object_unref (G_OBJECT(header));
345 #ifndef MODEST_TOOLKIT_HILDON2
346 } else if (MODEST_IS_MAIN_WINDOW(win)) {
347 GtkWidget *header_view;
349 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
350 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
351 return modest_header_view_get_selected_headers (MODEST_HEADER_VIEW(header_view));
353 } else if (MODEST_IS_HEADER_WINDOW (win)) {
354 GtkWidget *header_view;
356 header_view = GTK_WIDGET (modest_header_window_get_header_view (MODEST_HEADER_WINDOW (win)));
357 return modest_header_view_get_selected_headers (MODEST_HEADER_VIEW(header_view));
364 #ifndef MODEST_TOOLKIT_HILDON2
365 static GtkTreeRowReference *
366 get_next_after_selected_headers (ModestHeaderView *header_view)
368 GtkTreeSelection *sel;
369 GList *selected_rows, *node;
371 GtkTreeRowReference *result;
374 model = gtk_tree_view_get_model (GTK_TREE_VIEW (header_view));
375 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
376 selected_rows = gtk_tree_selection_get_selected_rows (sel, NULL);
378 if (selected_rows == NULL)
381 node = g_list_last (selected_rows);
382 path = gtk_tree_path_copy ((GtkTreePath *) node->data);
383 gtk_tree_path_next (path);
385 result = gtk_tree_row_reference_new (model, path);
387 gtk_tree_path_free (path);
388 g_list_foreach (selected_rows, (GFunc) gtk_tree_path_free, NULL);
389 g_list_free (selected_rows);
396 headers_action_mark_as_read (TnyHeader *header,
400 TnyHeaderFlags flags;
402 g_return_if_fail (TNY_IS_HEADER(header));
404 flags = tny_header_get_flags (header);
405 if (flags & TNY_HEADER_FLAG_SEEN) return;
406 tny_header_set_flag (header, TNY_HEADER_FLAG_SEEN);
410 headers_action_mark_as_unread (TnyHeader *header,
414 TnyHeaderFlags flags;
416 g_return_if_fail (TNY_IS_HEADER(header));
418 flags = tny_header_get_flags (header);
419 if (flags & TNY_HEADER_FLAG_SEEN) {
420 tny_header_unset_flag (header, TNY_HEADER_FLAG_SEEN);
424 /** After deleing a message that is currently visible in a window,
425 * show the next message from the list, or close the window if there are no more messages.
428 modest_ui_actions_refresh_message_window_after_delete (ModestMsgViewWindow* win)
430 /* Close msg view window or select next */
431 if (!modest_msg_view_window_select_next_message (win) &&
432 !modest_msg_view_window_select_previous_message (win)) {
434 g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value);
440 modest_ui_actions_on_delete_message (GtkAction *action, ModestWindow *win)
442 modest_ui_actions_on_edit_mode_delete_message (win);
446 modest_ui_actions_on_edit_mode_delete_message (ModestWindow *win)
448 TnyList *header_list = NULL;
449 TnyIterator *iter = NULL;
450 TnyHeader *header = NULL;
451 gchar *message = NULL;
454 ModestWindowMgr *mgr;
455 gboolean retval = TRUE;
457 g_return_val_if_fail (MODEST_IS_WINDOW(win), FALSE);
459 #ifndef MODEST_TOOLKIT_HILDON2
460 /* Check first if the header view has the focus */
461 if (MODEST_IS_MAIN_WINDOW (win)) {
462 GtkWidget *header_view = NULL;
465 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
466 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
467 if (!gtk_widget_is_focus (header_view))
471 /* Get the headers, either from the header view (if win is the main window),
472 * or from the message view window: */
473 header_list = get_selected_headers (win);
474 if (!header_list) return FALSE;
476 /* Check if any of the headers are already opened, or in the process of being opened */
477 #ifndef MODEST_TOOLKIT_HILDON2
478 if (MODEST_IS_MAIN_WINDOW (win)) {
479 gint opened_headers = 0;
481 iter = tny_list_create_iterator (header_list);
482 mgr = modest_runtime_get_window_mgr ();
483 while (!tny_iterator_is_done (iter)) {
484 header = TNY_HEADER (tny_iterator_get_current (iter));
486 if (modest_window_mgr_find_registered_header (mgr, header, NULL))
488 g_object_unref (header);
490 tny_iterator_next (iter);
492 g_object_unref (iter);
494 if (opened_headers > 0) {
497 msg = g_strdup_printf (_("mcen_nc_unable_to_delete_n_messages"),
500 modest_platform_run_information_dialog (GTK_WINDOW (win), (const gchar *) msg, FALSE);
503 g_object_unref (header_list);
510 if (tny_list_get_length(header_list) == 1) {
511 iter = tny_list_create_iterator (header_list);
512 header = TNY_HEADER (tny_iterator_get_current (iter));
515 subject = tny_header_dup_subject (header);
517 subject = g_strdup (_("mail_va_no_subject"));
518 desc = g_strdup_printf ("%s", subject);
520 g_object_unref (header);
523 g_object_unref (iter);
525 message = g_strdup_printf(ngettext("emev_nc_delete_message", "emev_nc_delete_messages",
526 tny_list_get_length(header_list)), desc);
528 /* Confirmation dialog */
529 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
532 if (response == GTK_RESPONSE_OK) {
533 GtkTreeSelection *sel = NULL;
534 GList *sel_list = NULL;
535 ModestMailOperation *mail_op = NULL;
537 /* Find last selected row */
538 #ifndef MODEST_TOOLKIT_HILDON2
539 if (MODEST_IS_MAIN_WINDOW (win)) {
541 ModestWindowMgr *mgr = NULL;
542 GtkTreeModel *model = NULL;
543 GtkTreeRowReference *next_row_reference = NULL, *prev_row_reference = NULL;
544 GtkTreePath *next_path = NULL, *prev_path = NULL;
546 model = gtk_tree_view_get_model (GTK_TREE_VIEW (header_view));
547 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
548 sel_list = gtk_tree_selection_get_selected_rows (sel, &model);
549 for (tmp=sel_list; tmp; tmp=tmp->next) {
550 if (tmp->next == NULL) {
551 prev_path = gtk_tree_path_copy((GtkTreePath *) tmp->data);
552 next_path = gtk_tree_path_copy((GtkTreePath *) tmp->data);
554 gtk_tree_path_prev (prev_path);
555 gtk_tree_path_next (next_path);
557 prev_row_reference = gtk_tree_row_reference_new (model, prev_path);
558 next_row_reference = gtk_tree_row_reference_new (model, next_path);
564 /* Disable window dimming management */
565 modest_window_disable_dimming (win);
567 /* Remove each header. If it's a view window header_view == NULL */
568 mail_op = modest_mail_operation_new ((GObject *) win);
569 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
571 modest_mail_operation_remove_msgs (mail_op, header_list, FALSE);
572 g_object_unref (mail_op);
574 /* Enable window dimming management */
576 gtk_tree_selection_unselect_all (sel);
578 modest_window_enable_dimming (win);
580 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
581 modest_ui_actions_refresh_message_window_after_delete (MODEST_MSG_VIEW_WINDOW (win));
583 /* Get main window */
584 mgr = modest_runtime_get_window_mgr ();
585 #ifndef MODEST_TOOLKIT_HILDON2
586 } else if (MODEST_IS_MAIN_WINDOW (win)) {
587 /* Select next or previous row */
588 if (gtk_tree_row_reference_valid (next_row_reference)) {
589 gtk_tree_selection_select_path (sel, next_path);
591 else if (gtk_tree_row_reference_valid (prev_row_reference)) {
592 gtk_tree_selection_select_path (sel, prev_path);
596 if (gtk_tree_row_reference_valid (next_row_reference))
597 gtk_tree_row_reference_free (next_row_reference);
598 if (next_path != NULL)
599 gtk_tree_path_free (next_path);
600 if (gtk_tree_row_reference_valid (prev_row_reference))
601 gtk_tree_row_reference_free (prev_row_reference);
602 if (prev_path != NULL)
603 gtk_tree_path_free (prev_path);
607 /* Update toolbar dimming state */
608 modest_ui_actions_check_menu_dimming_rules (win);
609 modest_ui_actions_check_toolbar_dimming_rules (win);
612 g_list_foreach (sel_list, (GFunc) gtk_tree_path_free, NULL);
613 g_list_free (sel_list);
622 g_object_unref (header_list);
630 /* delete either message or folder, based on where we are */
632 modest_ui_actions_on_delete_message_or_folder (GtkAction *action, ModestWindow *win)
634 g_return_if_fail (MODEST_IS_WINDOW(win));
636 /* Check first if the header view has the focus */
637 #ifndef MODEST_TOOLKIT_HILDON2
638 if (MODEST_IS_MAIN_WINDOW (win)) {
640 w = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
641 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
642 if (gtk_widget_is_focus (w)) {
643 modest_ui_actions_on_delete_folder (action, MODEST_WINDOW(win));
648 modest_ui_actions_on_delete_message (action, win);
652 modest_ui_actions_on_quit (GtkAction *action, ModestWindow *win)
654 ModestWindowMgr *mgr = NULL;
656 #ifdef MODEST_PLATFORM_MAEMO
657 modest_osso_save_state();
658 #endif /* MODEST_PLATFORM_MAEMO */
660 g_debug ("closing down, clearing %d item(s) from operation queue",
661 modest_mail_operation_queue_num_elements
662 (modest_runtime_get_mail_operation_queue()));
664 /* cancel all outstanding operations */
665 modest_mail_operation_queue_cancel_all
666 (modest_runtime_get_mail_operation_queue());
668 g_debug ("queue has been cleared");
671 /* Check if there are opened editing windows */
672 mgr = modest_runtime_get_window_mgr ();
673 modest_window_mgr_close_all_windows (mgr);
675 /* note: when modest-tny-account-store is finalized,
676 it will automatically set all network connections
679 /* gtk_main_quit (); */
683 modest_ui_actions_on_close_window (GtkAction *action, ModestWindow *win)
687 g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value);
689 /* if (MODEST_IS_MSG_VIEW_WINDOW (win)) { */
690 /* gtk_widget_destroy (GTK_WIDGET (win)); */
691 /* } else if (MODEST_IS_MSG_EDIT_WINDOW (win)) { */
692 /* gboolean ret_value; */
693 /* g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value); */
694 /* } else if (MODEST_IS_WINDOW (win)) { */
695 /* gtk_widget_destroy (GTK_WIDGET (win)); */
697 /* g_return_if_reached (); */
702 modest_ui_actions_add_to_contacts (GtkAction *action, ModestWindow *win)
704 g_return_if_fail (MODEST_IS_MSG_VIEW_WINDOW (win));
706 modest_msg_view_window_add_to_contacts (MODEST_MSG_VIEW_WINDOW (win));
710 modest_ui_actions_on_add_to_contacts (GtkAction *action, ModestWindow *win)
712 GtkClipboard *clipboard = NULL;
713 gchar *selection = NULL;
715 clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
716 selection = gtk_clipboard_wait_for_text (clipboard);
719 modest_address_book_add_address (selection, (GtkWindow *) win);
725 modest_ui_actions_on_new_account (GtkAction *action,
726 ModestWindow *window)
728 if (!modest_ui_actions_run_account_setup_wizard (window)) {
729 g_debug ("%s: wizard was already running", __FUNCTION__);
734 modest_ui_actions_on_accounts (GtkAction *action,
737 /* This is currently only implemented for Maemo */
738 if (!modest_account_mgr_has_accounts (modest_runtime_get_account_mgr(), TRUE)) {
739 if (!modest_ui_actions_run_account_setup_wizard (win))
740 g_debug ("%s: wizard was already running", __FUNCTION__);
744 /* Show the list of accounts */
745 GtkWindow *account_win = GTK_WINDOW (modest_account_view_window_new ());
747 /* The accounts dialog must be modal */
748 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (account_win), (GtkWindow *) win);
749 modest_utils_show_dialog_and_forget (GTK_WINDOW (win), GTK_DIALOG (account_win));
754 modest_ui_actions_on_smtp_servers (GtkAction *action, ModestWindow *win)
756 /* This is currently only implemented for Maemo,
757 * because it requires an API (libconic) to detect different connection
760 #ifndef MODEST_TOOLKIT_GTK /* Defined in config.h */
762 /* Create the window if necessary: */
763 GtkWidget *specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
764 modest_connection_specific_smtp_window_fill_with_connections (
765 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (specific_window),
766 modest_runtime_get_account_mgr());
768 /* Show the window: */
769 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (),
770 GTK_WINDOW (specific_window), (GtkWindow *) win);
771 gtk_widget_show (specific_window);
772 #endif /* !MODEST_TOOLKIT_GTK */
776 count_part_size (const gchar *part)
778 GnomeVFSURI *vfs_uri;
779 gchar *escaped_filename;
781 GnomeVFSFileInfo *info;
784 /* Estimation of attachment size if we cannot get it from file info */
787 vfs_uri = gnome_vfs_uri_new (part);
789 escaped_filename = g_path_get_basename (gnome_vfs_uri_get_path (vfs_uri));
790 filename = gnome_vfs_unescape_string_for_display (escaped_filename);
791 g_free (escaped_filename);
792 gnome_vfs_uri_unref (vfs_uri);
794 info = gnome_vfs_file_info_new ();
796 if (gnome_vfs_get_file_info (part,
798 GNOME_VFS_FILE_INFO_GET_MIME_TYPE)
800 if (info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_SIZE) {
805 gnome_vfs_file_info_unref (info);
811 count_parts_size (GSList *parts)
816 for (node = parts; node != NULL; node = g_slist_next (node)) {
817 result += count_part_size ((const gchar *) node->data);
824 modest_ui_actions_compose_msg(ModestWindow *win,
827 const gchar *bcc_str,
828 const gchar *subject_str,
829 const gchar *body_str,
831 gboolean set_as_modified)
833 gchar *account_name = NULL;
834 const gchar *mailbox;
836 TnyAccount *account = NULL;
837 TnyFolder *folder = NULL;
838 gchar *from_str = NULL, *signature = NULL, *body = NULL;
839 gchar *recipient = NULL;
840 gboolean use_signature = FALSE;
841 ModestWindow *msg_win = NULL;
842 ModestAccountMgr *mgr = modest_runtime_get_account_mgr();
843 ModestTnyAccountStore *store = modest_runtime_get_account_store();
844 GnomeVFSFileSize total_size, allowed_size;
845 guint64 available_disk, expected_size, parts_size;
848 /* we check for low-mem */
849 if (modest_platform_check_memory_low (win, TRUE))
852 available_disk = modest_utils_get_available_space (NULL);
853 parts_count = g_slist_length (attachments);
854 parts_size = count_parts_size (attachments);
855 expected_size = modest_tny_msg_estimate_size (body, NULL, parts_count, parts_size);
857 /* Double check: disk full condition or message too big */
858 if (available_disk < MODEST_TNY_ACCOUNT_STORE_MIN_FREE_SPACE ||
859 expected_size > available_disk) {
860 gchar *msg = g_strdup_printf (_KR("cerm_device_memory_full"), "");
861 modest_platform_system_banner (NULL, NULL, msg);
867 if (expected_size > MODEST_MAX_ATTACHMENT_SIZE) {
868 modest_platform_run_information_dialog (
870 _("mail_ib_error_attachment_size"),
876 #ifdef MODEST_TOOLKIT_HILDON2
878 account_name = g_strdup (modest_window_get_active_account(win));
881 account_name = modest_account_mgr_get_default_account(mgr);
884 g_printerr ("modest: no account found\n");
889 mailbox = modest_window_get_active_mailbox (win);
892 account = modest_tny_account_store_get_server_account (store, account_name, TNY_ACCOUNT_TYPE_STORE);
894 g_printerr ("modest: failed to get tnyaccount for '%s'\n", account_name);
897 folder = modest_tny_account_get_special_folder (account, TNY_FOLDER_TYPE_DRAFTS);
899 g_printerr ("modest: failed to find Drafts folder\n");
902 from_str = modest_account_mgr_get_from_string (mgr, account_name, mailbox);
904 g_printerr ("modest: failed get from string for '%s'\n", account_name);
908 recipient = modest_text_utils_get_email_address (from_str);
909 signature = modest_account_mgr_get_signature_from_recipient (mgr, recipient, &use_signature);
911 if (body_str != NULL) {
912 body = use_signature ? g_strconcat(body_str, "\n",
913 MODEST_TEXT_UTILS_SIGNATURE_MARKER,
914 "\n", signature, NULL) : g_strdup(body_str);
916 body = use_signature ? g_strconcat("\n", MODEST_TEXT_UTILS_SIGNATURE_MARKER,
917 "\n", signature, NULL) : g_strdup("");
920 msg = modest_tny_msg_new (to_str, from_str, cc_str, bcc_str, subject_str, NULL, NULL, body, NULL, NULL, NULL);
922 g_printerr ("modest: failed to create new msg\n");
926 /* Create and register edit window */
927 /* This is destroyed by TODO. */
929 allowed_size = MODEST_MAX_ATTACHMENT_SIZE;
930 msg_win = modest_msg_edit_window_new (msg, account_name, mailbox, FALSE);
932 if (!modest_window_mgr_register_window (modest_runtime_get_window_mgr(), msg_win, win)) {
933 gtk_widget_destroy (GTK_WIDGET (msg_win));
936 modest_msg_edit_window_set_modified (MODEST_MSG_EDIT_WINDOW (msg_win), set_as_modified);
937 gtk_widget_show_all (GTK_WIDGET (msg_win));
939 while (attachments) {
940 GnomeVFSFileSize att_size;
942 modest_msg_edit_window_attach_file_one((ModestMsgEditWindow *)msg_win,
943 attachments->data, allowed_size);
944 total_size += att_size;
946 if (att_size > allowed_size) {
947 g_debug ("%s: total size: %u",
948 __FUNCTION__, (unsigned int)total_size);
951 allowed_size -= att_size;
953 attachments = g_slist_next(attachments);
960 g_free (account_name);
962 g_object_unref (G_OBJECT(account));
964 g_object_unref (G_OBJECT(folder));
966 g_object_unref (G_OBJECT(msg));
970 modest_ui_actions_on_new_msg (GtkAction *action, ModestWindow *win)
972 /* if there are no accounts yet, just show the wizard */
973 if (!modest_account_mgr_has_accounts (modest_runtime_get_account_mgr(), TRUE))
974 if (!modest_ui_actions_run_account_setup_wizard (win))
977 modest_ui_actions_compose_msg(win, NULL, NULL, NULL, NULL, NULL, NULL, FALSE);
982 modest_ui_actions_msg_retrieval_check (ModestMailOperation *mail_op,
986 ModestMailOperationStatus status;
988 /* If there is no message or the operation was not successful */
989 status = modest_mail_operation_get_status (mail_op);
990 if (!msg || status != MODEST_MAIL_OPERATION_STATUS_SUCCESS) {
993 /* If it's a memory low issue, then show a banner */
994 error = modest_mail_operation_get_error (mail_op);
995 if (error && error->domain == MODEST_MAIL_OPERATION_ERROR &&
996 error->code == MODEST_MAIL_OPERATION_ERROR_LOW_MEMORY) {
997 GObject *source = modest_mail_operation_get_source (mail_op);
998 modest_platform_run_information_dialog (GTK_IS_WINDOW (source) ? GTK_WINDOW (source) : NULL,
999 _KR("memr_ib_operation_disabled"),
1001 g_object_unref (source);
1004 if (error && ((error->code == TNY_SERVICE_ERROR_NO_SUCH_MESSAGE) ||
1005 error->code == TNY_SERVICE_ERROR_MESSAGE_NOT_AVAILABLE)) {
1006 gchar *subject, *msg, *format = NULL;
1007 TnyAccount *account;
1009 subject = (header) ? tny_header_dup_subject (header) : NULL;
1011 subject = g_strdup (_("mail_va_no_subject"));
1013 account = modest_mail_operation_get_account (mail_op);
1015 ModestProtocolType proto = modest_tny_account_get_protocol_type (account);
1016 ModestProtocol *protocol = modest_protocol_registry_get_protocol_by_type (modest_runtime_get_protocol_registry (), proto);
1019 if (tny_account_get_connection_status (account) ==
1020 TNY_CONNECTION_STATUS_CONNECTED) {
1021 format = modest_protocol_get_translation (protocol,
1022 MODEST_PROTOCOL_TRANSLATION_MSG_NOT_AVAILABLE,
1025 format = g_strdup_printf (_("mail_ib_backend_server_invalid"),
1026 tny_account_get_hostname (account));
1029 g_object_unref (account);
1033 format = g_strdup (_("emev_ni_ui_imap_message_not_available_in_server"));
1035 msg = g_strdup_printf (format, subject);
1036 modest_platform_run_information_dialog (NULL, msg, FALSE);
1042 /* Remove the header from the preregistered uids */
1043 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (),
1056 } OpenMsgBannerInfo;
1059 GtkTreeModel *model;
1061 ModestWindow *caller_window;
1062 OpenMsgBannerInfo *banner_info;
1063 GtkTreeRowReference *rowref;
1067 open_msg_banner_idle (gpointer userdata)
1069 OpenMsgBannerInfo *banner_info = (OpenMsgBannerInfo *) userdata;
1071 gdk_threads_enter ();
1072 banner_info->idle_handler = 0;
1073 banner_info->banner = modest_platform_animation_banner (NULL, NULL, banner_info->message);
1074 if (banner_info->banner)
1075 g_object_ref (banner_info->banner);
1077 gdk_threads_leave ();
1083 get_header_view_from_window (ModestWindow *window)
1085 GtkWidget *header_view;
1087 #ifndef MODEST_TOOLKIT_HILDON2
1088 if (MODEST_IS_MAIN_WINDOW (window)) {
1089 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (window),
1090 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1092 if (MODEST_IS_HEADER_WINDOW (window)){
1093 header_view = GTK_WIDGET (modest_header_window_get_header_view (MODEST_HEADER_WINDOW (window)));
1103 get_info_from_header (TnyHeader *header, gboolean *is_draft, gboolean *can_open)
1106 gchar *account = NULL;
1107 TnyFolderType folder_type = TNY_FOLDER_TYPE_UNKNOWN;
1112 folder = tny_header_get_folder (header);
1113 /* Gets folder type (OUTBOX headers will be opened in edit window */
1114 if (modest_tny_folder_is_local_folder (folder)) {
1115 folder_type = modest_tny_folder_get_local_or_mmc_folder_type (folder);
1116 if (folder_type == TNY_FOLDER_TYPE_INVALID)
1117 g_warning ("%s: BUG: TNY_FOLDER_TYPE_INVALID", __FUNCTION__);
1120 if (folder_type == TNY_FOLDER_TYPE_OUTBOX) {
1121 TnyTransportAccount *traccount = NULL;
1122 ModestTnyAccountStore *accstore = modest_runtime_get_account_store();
1123 traccount = modest_tny_account_store_get_transport_account_from_outbox_header(accstore, header);
1125 ModestTnySendQueue *send_queue = NULL;
1126 ModestTnySendQueueStatus status;
1128 account = g_strdup(modest_tny_account_get_parent_modest_account_name_for_server_account(
1129 TNY_ACCOUNT(traccount)));
1130 send_queue = modest_runtime_get_send_queue(traccount, TRUE);
1131 if (TNY_IS_SEND_QUEUE (send_queue)) {
1132 msg_id = modest_tny_send_queue_get_msg_id (header);
1133 status = modest_tny_send_queue_get_msg_status(send_queue, msg_id);
1135 /* Only open messages in outbox with the editor if they are in Failed state */
1136 if (status == MODEST_TNY_SEND_QUEUE_FAILED) {
1139 #ifdef MODEST_TOOLKIT_HILDON2
1141 /* In Fremantle we can not
1142 open any message from
1143 outbox which is not in
1149 g_object_unref(traccount);
1151 g_warning("Cannot get transport account for message in outbox!!");
1153 } else if (folder_type == TNY_FOLDER_TYPE_DRAFTS) {
1154 *is_draft = TRUE; /* Open in editor if the message is in the Drafts folder */
1158 TnyAccount *acc = tny_folder_get_account (folder);
1161 g_strdup (modest_tny_account_get_parent_modest_account_name_for_server_account (acc));
1162 g_object_unref (acc);
1166 g_object_unref (folder);
1172 open_msg_cb (ModestMailOperation *mail_op,
1179 ModestWindowMgr *mgr = NULL;
1180 ModestWindow *parent_win = NULL;
1181 ModestWindow *win = NULL;
1182 gchar *account = NULL;
1183 gboolean open_in_editor = FALSE;
1185 OpenMsgHelper *helper = (OpenMsgHelper *) user_data;
1187 /* Do nothing if there was any problem with the mail
1188 operation. The error will be shown by the error_handler of
1189 the mail operation */
1190 if (!modest_ui_actions_msg_retrieval_check (mail_op, header, msg))
1193 parent_win = (ModestWindow *) modest_mail_operation_get_source (mail_op);
1195 /* Mark header as read */
1196 headers_action_mark_as_read (header, MODEST_WINDOW(parent_win), NULL);
1198 account = get_info_from_header (header, &open_in_editor, &can_open);
1202 account = g_strdup (modest_window_get_active_account (MODEST_WINDOW (parent_win)));
1204 account = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
1206 if (open_in_editor) {
1207 ModestAccountMgr *mgr = modest_runtime_get_account_mgr ();
1208 gchar *from_header = NULL, *acc_name;
1209 gchar *mailbox = NULL;
1211 from_header = tny_header_dup_from (header);
1213 /* we cannot edit without a valid account... */
1214 if (!modest_account_mgr_has_accounts(mgr, TRUE)) {
1215 if (!modest_ui_actions_run_account_setup_wizard(parent_win)) {
1216 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (),
1218 g_free (from_header);
1223 acc_name = modest_utils_get_account_name_from_recipient (from_header, &mailbox);
1224 g_free (from_header);
1230 win = modest_msg_edit_window_new (msg, account, mailbox, TRUE);
1234 gchar *uid = modest_tny_folder_get_header_unique_id (header);
1235 const gchar *mailbox = NULL;
1237 if (parent_win && MODEST_IS_WINDOW (parent_win))
1238 mailbox = modest_window_get_active_mailbox (MODEST_WINDOW (parent_win));
1240 if (helper->rowref && helper->model) {
1241 win = modest_msg_view_window_new_with_header_model (msg, account, mailbox, (const gchar*) uid,
1242 helper->model, helper->rowref);
1244 win = modest_msg_view_window_new_for_attachment (msg, account, mailbox, (const gchar*) uid);
1249 /* Register and show new window */
1251 mgr = modest_runtime_get_window_mgr ();
1252 if (!modest_window_mgr_register_window (mgr, win, NULL)) {
1253 gtk_widget_destroy (GTK_WIDGET (win));
1256 gtk_widget_show_all (GTK_WIDGET(win));
1259 #ifndef MODEST_TOOLKIT_HILDON2
1260 /* Update toolbar dimming state */
1261 if (MODEST_IS_MAIN_WINDOW (parent_win)) {
1262 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (parent_win));
1269 g_object_unref (parent_win);
1273 modest_ui_actions_disk_operations_error_handler (ModestMailOperation *mail_op,
1276 const GError *error;
1277 GObject *win = NULL;
1278 ModestMailOperationStatus status;
1280 win = modest_mail_operation_get_source (mail_op);
1281 error = modest_mail_operation_get_error (mail_op);
1282 status = modest_mail_operation_get_status (mail_op);
1284 /* If the mail op has been cancelled then it's not an error:
1285 don't show any message */
1286 if (status != MODEST_MAIL_OPERATION_STATUS_CANCELED) {
1287 TnyAccount *account = modest_mail_operation_get_account (mail_op);
1288 if (modest_tny_account_store_is_disk_full_error (modest_runtime_get_account_store(),
1289 (GError *) error, account)) {
1290 gchar *msg = g_strdup_printf (_KR("cerm_device_memory_full"), "");
1291 modest_platform_information_banner ((GtkWidget *) win, NULL, msg);
1293 } else if (error->code == TNY_SYSTEM_ERROR_MEMORY) {
1294 modest_platform_information_banner ((GtkWidget *) win,
1295 NULL, _("emev_ui_imap_inbox_select_error"));
1296 } else if (error->domain == MODEST_MAIL_OPERATION_ERROR &&
1297 error->code == MODEST_MAIL_OPERATION_ERROR_FILE_IO) {
1298 modest_platform_information_banner ((GtkWidget *) win,
1299 NULL, _CS ("sfil_ni_unable_to_open_file_not_found"));
1300 } else if (user_data) {
1301 modest_platform_information_banner ((GtkWidget *) win,
1305 g_object_unref (account);
1309 g_object_unref (win);
1313 * Returns the account a list of headers belongs to. It returns a
1314 * *new* reference so don't forget to unref it
1317 get_account_from_header_list (TnyList *headers)
1319 TnyAccount *account = NULL;
1321 if (tny_list_get_length (headers) > 0) {
1322 TnyIterator *iter = tny_list_create_iterator (headers);
1323 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter));
1324 TnyFolder *folder = tny_header_get_folder (header);
1327 g_object_unref (header);
1329 while (!tny_iterator_is_done (iter)) {
1330 header = TNY_HEADER (tny_iterator_get_current (iter));
1331 folder = tny_header_get_folder (header);
1334 g_object_unref (header);
1336 tny_iterator_next (iter);
1341 account = tny_folder_get_account (folder);
1342 g_object_unref (folder);
1346 g_object_unref (header);
1348 g_object_unref (iter);
1354 get_account_from_header (TnyHeader *header)
1356 TnyAccount *account = NULL;
1359 folder = tny_header_get_folder (header);
1362 account = tny_folder_get_account (folder);
1363 g_object_unref (folder);
1369 caller_win_destroyed (OpenMsgHelper *helper, GObject *object)
1371 if (helper->caller_window)
1372 helper->caller_window = NULL;
1376 open_msg_helper_destroyer (gpointer user_data)
1378 OpenMsgHelper *helper = (OpenMsgHelper *) user_data;
1380 if (helper->caller_window) {
1381 g_object_weak_unref ((GObject *) helper->caller_window, (GWeakNotify) caller_win_destroyed, helper);
1382 helper->caller_window = NULL;
1385 if (helper->banner_info) {
1386 g_free (helper->banner_info->message);
1387 if (helper->banner_info->idle_handler > 0) {
1388 g_source_remove (helper->banner_info->idle_handler);
1389 helper->banner_info->idle_handler = 0;
1391 if (helper->banner_info->banner != NULL) {
1392 gtk_widget_destroy (helper->banner_info->banner);
1393 g_object_unref (helper->banner_info->banner);
1394 helper->banner_info->banner = NULL;
1396 g_slice_free (OpenMsgBannerInfo, helper->banner_info);
1397 helper->banner_info = NULL;
1399 g_object_unref (helper->model);
1400 g_object_unref (helper->header);
1401 gtk_tree_row_reference_free (helper->rowref);
1402 g_slice_free (OpenMsgHelper, helper);
1406 open_msg_performer(gboolean canceled,
1408 GtkWindow *parent_window,
1409 TnyAccount *account,
1412 ModestMailOperation *mail_op = NULL;
1413 gchar *error_msg = NULL;
1414 ModestProtocolType proto;
1415 TnyConnectionStatus status;
1416 OpenMsgHelper *helper = NULL;
1417 ModestProtocol *protocol;
1418 ModestProtocolRegistry *protocol_registry;
1421 helper = (OpenMsgHelper *) user_data;
1423 status = tny_account_get_connection_status (account);
1424 if (err || canceled || helper->caller_window == NULL) {
1425 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (), helper->header);
1426 /* Free the helper */
1427 open_msg_helper_destroyer (helper);
1429 /* In disk full conditions we could get this error here */
1430 modest_tny_account_store_check_disk_full_error (modest_runtime_get_account_store(),
1431 (GtkWidget *) parent_window, err,
1437 /* Get the error message depending on the protocol */
1438 proto = modest_tny_account_get_protocol_type (account);
1439 if (proto == MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1440 proto = MODEST_PROTOCOLS_STORE_MAILDIR;
1443 protocol_registry = modest_runtime_get_protocol_registry ();
1444 subject = tny_header_dup_subject (helper->header);
1446 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, proto);
1447 error_msg = modest_protocol_get_translation (protocol, MODEST_PROTOCOL_TRANSLATION_MSG_NOT_AVAILABLE, subject);
1451 if (error_msg == NULL) {
1452 error_msg = g_strdup (_("mail_ni_ui_folder_get_msg_folder_error"));
1455 #ifndef MODEST_TOOLKIT_HILDON2
1456 gboolean show_open_draft = FALSE;
1457 if (modest_protocol_registry_protocol_type_has_tag (protocol_registry,
1459 MODEST_PROTOCOL_REGISTRY_LOCAL_STORE_PROTOCOLS)) {
1461 TnyFolderType folder_type;
1463 folder = tny_header_get_folder (helper->header);
1464 folder_type = modest_tny_folder_get_local_or_mmc_folder_type (folder);
1465 show_open_draft = (folder_type == TNY_FOLDER_TYPE_DRAFTS);
1466 g_object_unref (folder);
1470 #ifdef MODEST_TOOLKIT_HILDON2
1473 gchar *account_name = get_info_from_header (helper->header, &is_draft, &can_open);
1476 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (), helper->header);
1477 g_free (account_name);
1478 open_msg_helper_destroyer (helper);
1483 ModestWindow *window;
1484 GtkWidget *header_view;
1487 header_view = get_header_view_from_window (MODEST_WINDOW (parent_window));
1488 uid = modest_tny_folder_get_header_unique_id (helper->header);
1490 const gchar *mailbox = NULL;
1491 mailbox = modest_window_get_active_mailbox (MODEST_WINDOW (parent_window));
1492 window = modest_msg_view_window_new_from_header_view
1493 (MODEST_HEADER_VIEW (header_view), account_name, mailbox, uid, helper->rowref);
1494 if (window != NULL) {
1495 if (!modest_window_mgr_register_window (modest_runtime_get_window_mgr (),
1497 gtk_widget_destroy (GTK_WIDGET (window));
1499 gtk_widget_show_all (GTK_WIDGET(window));
1503 g_free (account_name);
1505 open_msg_helper_destroyer (helper);
1508 g_free (account_name);
1510 /* Create the mail operation */
1512 modest_mail_operation_new_with_error_handling ((GObject *) parent_window,
1513 modest_ui_actions_disk_operations_error_handler,
1514 g_strdup (error_msg), g_free);
1515 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
1519 #ifndef MODEST_TOOLKIT_HILDON2
1520 if (show_open_draft) {
1521 helper->banner_info = g_slice_new (OpenMsgBannerInfo);
1522 helper->banner_info->message = g_strdup (_("mail_ib_opening_draft_message"));
1523 helper->banner_info->banner = NULL;
1524 helper->banner_info->idle_handler = g_timeout_add (500, open_msg_banner_idle,
1525 helper->banner_info);
1531 headers = TNY_LIST (tny_simple_list_new ());
1532 tny_list_prepend (headers, G_OBJECT (helper->header));
1533 modest_mail_operation_get_msgs_full (mail_op,
1537 open_msg_helper_destroyer);
1538 g_object_unref (headers);
1545 g_object_unref (mail_op);
1546 g_object_unref (account);
1550 * This function is used by both modest_ui_actions_on_open and
1551 * modest_ui_actions_on_header_activated. This way we always do the
1552 * same when trying to open messages.
1555 open_msg_from_header (TnyHeader *header, GtkTreeRowReference *rowref, ModestWindow *win)
1557 ModestWindowMgr *mgr = NULL;
1558 TnyAccount *account;
1559 gboolean cached = FALSE;
1561 GtkWidget *header_view = NULL;
1562 OpenMsgHelper *helper;
1563 ModestWindow *window;
1565 g_return_if_fail (header != NULL && rowref != NULL && gtk_tree_row_reference_valid (rowref));
1567 mgr = modest_runtime_get_window_mgr ();
1570 header_view = get_header_view_from_window (MODEST_WINDOW (win));
1571 if (header_view == NULL)
1574 /* Get the account */
1575 account = get_account_from_header (header);
1580 found = modest_window_mgr_find_registered_header (mgr, header, &window);
1582 /* Do not open again the message and present the
1583 window to the user */
1586 #ifndef MODEST_TOOLKIT_HILDON2
1587 gtk_window_present (GTK_WINDOW (window));
1590 /* the header has been registered already, we don't do
1591 * anything but wait for the window to come up*/
1592 g_debug ("header %p already registered, waiting for window", header);
1597 /* Open each message */
1598 cached = tny_header_get_flags (header) & TNY_HEADER_FLAG_CACHED;
1600 /* Allways download if we are online. */
1601 if (!tny_device_is_online (modest_runtime_get_device ())) {
1604 /* If ask for user permission to download the messages */
1605 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
1606 _("mcen_nc_get_msg"));
1608 /* End if the user does not want to continue */
1609 if (response == GTK_RESPONSE_CANCEL) {
1615 /* We register the window for opening */
1616 modest_window_mgr_register_header (mgr, header, NULL);
1618 /* Create the helper. We need to get a reference to the model
1619 here because it could change while the message is readed
1620 (the user could switch between folders) */
1621 helper = g_slice_new (OpenMsgHelper);
1622 helper->model = g_object_ref (gtk_tree_view_get_model (GTK_TREE_VIEW (header_view)));
1623 helper->caller_window = win;
1624 g_object_weak_ref ((GObject *) helper->caller_window, (GWeakNotify) caller_win_destroyed, helper);
1625 helper->header = g_object_ref (header);
1626 helper->rowref = gtk_tree_row_reference_copy (rowref);
1627 helper->banner_info = NULL;
1629 /* Connect to the account and perform */
1631 modest_platform_connect_and_perform ((GtkWindow *) win, TRUE, g_object_ref (account),
1632 open_msg_performer, helper);
1634 /* Call directly the performer, do not need to connect */
1635 open_msg_performer (FALSE, NULL, (GtkWindow *) win,
1636 g_object_ref (account), helper);
1641 g_object_unref (account);
1645 modest_ui_actions_on_open (GtkAction *action, ModestWindow *win)
1652 /* we check for low-mem; in that case, show a warning, and don't allow
1655 if (modest_platform_check_memory_low (MODEST_WINDOW(win), TRUE))
1659 headers = get_selected_headers (win);
1663 headers_count = tny_list_get_length (headers);
1664 if (headers_count != 1) {
1665 if (headers_count > 1) {
1666 /* Don't allow activation if there are more than one message selected */
1667 modest_platform_information_banner (NULL, NULL, _("mcen_ib_select_one_message"));
1670 g_object_unref (headers);
1674 iter = tny_list_create_iterator (headers);
1675 header = TNY_HEADER (tny_iterator_get_current (iter));
1676 g_object_unref (iter);
1680 open_msg_from_header (header, NULL, win);
1681 g_object_unref (header);
1684 g_object_unref(headers);
1688 rf_helper_window_closed (gpointer data,
1691 ReplyForwardHelper *helper = (ReplyForwardHelper *) data;
1693 helper->parent_window = NULL;
1696 static ReplyForwardHelper*
1697 create_reply_forward_helper (ReplyForwardAction action,
1699 guint reply_forward_type,
1702 ReplyForwardHelper *rf_helper = NULL;
1703 const gchar *active_acc = modest_window_get_active_account (win);
1704 const gchar *active_mailbox = modest_window_get_active_mailbox (win);
1706 rf_helper = g_slice_new0 (ReplyForwardHelper);
1707 rf_helper->reply_forward_type = reply_forward_type;
1708 rf_helper->action = action;
1709 rf_helper->parent_window = (MODEST_IS_WINDOW (win)) ? GTK_WIDGET (win) : NULL;
1710 rf_helper->header = (header) ? g_object_ref (header) : NULL;
1711 rf_helper->account_name = (active_acc) ?
1712 g_strdup (active_acc) :
1713 modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
1714 rf_helper->mailbox = g_strdup (active_mailbox);
1716 /* Note that window could be destroyed just AFTER calling
1717 register_window so we must ensure that this pointer does
1718 not hold invalid references */
1719 if (rf_helper->parent_window)
1720 g_object_weak_ref (G_OBJECT (rf_helper->parent_window),
1721 rf_helper_window_closed, rf_helper);
1727 free_reply_forward_helper (gpointer data)
1729 ReplyForwardHelper *helper;
1731 helper = (ReplyForwardHelper *) data;
1732 g_free (helper->account_name);
1733 g_free (helper->mailbox);
1735 g_object_unref (helper->header);
1736 if (helper->parent_window)
1737 g_object_weak_unref (G_OBJECT (helper->parent_window),
1738 rf_helper_window_closed, helper);
1739 g_slice_free (ReplyForwardHelper, helper);
1743 reply_forward_cb (ModestMailOperation *mail_op,
1750 TnyMsg *new_msg = NULL;
1751 ReplyForwardHelper *rf_helper;
1752 ModestWindow *msg_win = NULL;
1753 ModestEditType edit_type;
1755 TnyAccount *account = NULL;
1756 ModestWindowMgr *mgr = NULL;
1757 gchar *signature = NULL;
1758 gboolean use_signature;
1761 /* If there was any error. The mail operation could be NULL,
1762 this means that we already have the message downloaded and
1763 that we didn't do a mail operation to retrieve it */
1764 rf_helper = (ReplyForwardHelper *) user_data;
1765 if (mail_op && !modest_ui_actions_msg_retrieval_check (mail_op, header, msg))
1768 from = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(),
1769 rf_helper->account_name, rf_helper->mailbox);
1770 recipient = modest_text_utils_get_email_address (from);
1771 signature = modest_account_mgr_get_signature_from_recipient (modest_runtime_get_account_mgr(),
1776 /* Create reply mail */
1777 switch (rf_helper->action) {
1778 /* Use the msg_header to ensure that we have all the
1779 information. The summary can lack some data */
1780 TnyHeader *msg_header;
1782 msg_header = tny_msg_get_header (msg);
1784 modest_tny_msg_create_reply_msg (msg, msg_header, from,
1785 (use_signature) ? signature : NULL,
1786 rf_helper->reply_forward_type,
1787 MODEST_TNY_MSG_REPLY_MODE_SENDER);
1788 g_object_unref (msg_header);
1790 case ACTION_REPLY_TO_ALL:
1791 msg_header = tny_msg_get_header (msg);
1793 modest_tny_msg_create_reply_msg (msg, msg_header, from,
1794 (use_signature) ? signature : NULL,
1795 rf_helper->reply_forward_type,
1796 MODEST_TNY_MSG_REPLY_MODE_ALL);
1797 edit_type = MODEST_EDIT_TYPE_REPLY;
1798 g_object_unref (msg_header);
1800 case ACTION_FORWARD:
1802 modest_tny_msg_create_forward_msg (msg, from, (use_signature) ? signature : NULL,
1803 rf_helper->reply_forward_type);
1804 edit_type = MODEST_EDIT_TYPE_FORWARD;
1807 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (),
1809 g_return_if_reached ();
1817 g_warning ("%s: failed to create message\n", __FUNCTION__);
1821 account = modest_tny_account_store_get_server_account (modest_runtime_get_account_store(),
1822 rf_helper->account_name,
1823 TNY_ACCOUNT_TYPE_STORE);
1825 g_warning ("%s: failed to get tnyaccount for '%s'\n", __FUNCTION__, rf_helper->account_name);
1829 /* Create and register the windows */
1830 msg_win = modest_msg_edit_window_new (new_msg, rf_helper->account_name, rf_helper->mailbox, FALSE);
1831 mgr = modest_runtime_get_window_mgr ();
1832 modest_window_mgr_register_window (mgr, msg_win, (ModestWindow *) rf_helper->parent_window);
1834 /* Note that register_window could have deleted the account */
1835 if (MODEST_IS_WINDOW (rf_helper->parent_window)) {
1836 gdouble parent_zoom;
1838 parent_zoom = modest_window_get_zoom (MODEST_WINDOW (rf_helper->parent_window));
1839 modest_window_set_zoom (msg_win, parent_zoom);
1842 /* Show edit window */
1843 gtk_widget_show_all (GTK_WIDGET (msg_win));
1846 /* We always unregister the header because the message is
1847 forwarded or replied so the original one is no longer
1849 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (),
1852 g_object_unref (G_OBJECT (new_msg));
1854 g_object_unref (G_OBJECT (account));
1855 free_reply_forward_helper (rf_helper);
1858 /* Checks a list of headers. If any of them are not currently
1859 * downloaded (CACHED) then returns TRUE else returns FALSE.
1862 header_list_count_uncached_msgs (TnyList *header_list)
1865 gint uncached_messages = 0;
1867 iter = tny_list_create_iterator (header_list);
1868 while (!tny_iterator_is_done (iter)) {
1871 header = TNY_HEADER (tny_iterator_get_current (iter));
1873 if (!(tny_header_get_flags (header) & TNY_HEADER_FLAG_CACHED))
1874 uncached_messages ++;
1875 g_object_unref (header);
1878 tny_iterator_next (iter);
1880 g_object_unref (iter);
1882 return uncached_messages;
1885 /* Returns FALSE if the user does not want to download the
1886 * messages. Returns TRUE if the user allowed the download.
1889 connect_to_get_msg (ModestWindow *win,
1890 gint num_of_uncached_msgs,
1891 TnyAccount *account)
1893 GtkResponseType response;
1895 /* Allways download if we are online. */
1896 if (tny_device_is_online (modest_runtime_get_device ()))
1899 /* If offline, then ask for user permission to download the messages */
1900 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
1901 ngettext("mcen_nc_get_msg",
1903 num_of_uncached_msgs));
1905 if (response == GTK_RESPONSE_CANCEL)
1908 return modest_platform_connect_and_wait((GtkWindow *) win, account);
1912 reply_forward_performer (gboolean canceled,
1914 GtkWindow *parent_window,
1915 TnyAccount *account,
1918 ReplyForwardHelper *rf_helper = NULL;
1919 ModestMailOperation *mail_op;
1921 rf_helper = (ReplyForwardHelper *) user_data;
1923 if (canceled || err) {
1924 free_reply_forward_helper (rf_helper);
1928 /* Retrieve the message */
1929 modest_window_mgr_register_header (modest_runtime_get_window_mgr (), rf_helper->header, NULL);
1930 mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT (parent_window),
1931 modest_ui_actions_disk_operations_error_handler,
1933 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
1934 modest_mail_operation_get_msg (mail_op, rf_helper->header, TRUE, reply_forward_cb, rf_helper);
1937 g_object_unref(mail_op);
1941 * Common code for the reply and forward actions
1944 reply_forward (ReplyForwardAction action, ModestWindow *win)
1946 ReplyForwardHelper *rf_helper = NULL;
1947 guint reply_forward_type;
1949 g_return_if_fail (win && MODEST_IS_WINDOW(win));
1951 /* we check for low-mem; in that case, show a warning, and don't allow
1952 * reply/forward (because it could potentially require a lot of memory */
1953 if (modest_platform_check_memory_low (MODEST_WINDOW(win), TRUE))
1957 /* we need an account when editing */
1958 if (!modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE)) {
1959 if (!modest_ui_actions_run_account_setup_wizard (win))
1963 reply_forward_type =
1964 modest_conf_get_int (modest_runtime_get_conf (),
1965 (action == ACTION_FORWARD) ?
1966 MODEST_CONF_FORWARD_TYPE :
1967 MODEST_CONF_REPLY_TYPE,
1970 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
1972 TnyHeader *header = NULL;
1973 /* Get header and message. Do not free them here, the
1974 reply_forward_cb must do it */
1975 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW(win));
1976 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
1978 if (msg && header) {
1980 rf_helper = create_reply_forward_helper (action, win,
1981 reply_forward_type, header);
1982 reply_forward_cb (NULL, header, FALSE, msg, NULL, rf_helper);
1984 g_warning("%s: no message or header found in viewer\n", __FUNCTION__);
1988 g_object_unref (msg);
1990 g_object_unref (header);
1992 TnyHeader *header = NULL;
1994 gboolean do_retrieve = TRUE;
1995 TnyList *header_list = NULL;
1997 header_list = get_selected_headers (win);
2000 /* Check that only one message is selected for replying */
2001 if (tny_list_get_length (header_list) != 1) {
2002 modest_platform_information_banner ((win) ? GTK_WIDGET (win) : NULL,
2003 NULL, _("mcen_ib_select_one_message"));
2004 g_object_unref (header_list);
2008 /* Only reply/forward to one message */
2009 iter = tny_list_create_iterator (header_list);
2010 header = TNY_HEADER (tny_iterator_get_current (iter));
2011 g_object_unref (iter);
2013 /* Retrieve messages */
2014 do_retrieve = (action == ACTION_FORWARD) ||
2015 (reply_forward_type != MODEST_TNY_MSG_REPLY_TYPE_CITE);
2018 TnyAccount *account = NULL;
2019 TnyFolder *folder = NULL;
2020 gdouble download = TRUE;
2021 guint uncached_msgs = 0;
2023 folder = tny_header_get_folder (header);
2025 goto do_retrieve_frees;
2026 account = tny_folder_get_account (folder);
2028 goto do_retrieve_frees;
2030 uncached_msgs = header_list_count_uncached_msgs (header_list);
2032 if (uncached_msgs > 0) {
2033 /* Allways download if we are online. */
2034 if (!tny_device_is_online (modest_runtime_get_device ())) {
2037 /* If ask for user permission to download the messages */
2038 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
2039 ngettext("mcen_nc_get_msg",
2043 /* End if the user does not want to continue */
2044 if (response == GTK_RESPONSE_CANCEL)
2051 rf_helper = create_reply_forward_helper (action, win,
2052 reply_forward_type, header);
2053 if (uncached_msgs > 0) {
2054 modest_platform_connect_and_perform (GTK_WINDOW (win),
2056 reply_forward_performer,
2059 reply_forward_performer (FALSE, NULL, GTK_WINDOW (win),
2060 account, rf_helper);
2065 g_object_unref (account);
2067 g_object_unref (folder);
2069 reply_forward_cb (NULL, header, FALSE, NULL, NULL, NULL);
2072 g_object_unref (header_list);
2073 g_object_unref (header);
2078 modest_ui_actions_on_reply (GtkAction *action, ModestWindow *win)
2080 g_return_if_fail (MODEST_IS_WINDOW(win));
2082 reply_forward (ACTION_REPLY, win);
2086 modest_ui_actions_on_forward (GtkAction *action, ModestWindow *win)
2088 g_return_if_fail (MODEST_IS_WINDOW(win));
2090 reply_forward (ACTION_FORWARD, win);
2094 modest_ui_actions_on_reply_all (GtkAction *action, ModestWindow *win)
2096 g_return_if_fail (MODEST_IS_WINDOW(win));
2098 reply_forward (ACTION_REPLY_TO_ALL, win);
2102 modest_ui_actions_on_next (GtkAction *action,
2103 ModestWindow *window)
2105 #ifndef MODEST_TOOLKIT_HILDON2
2106 if (MODEST_IS_MAIN_WINDOW (window)) {
2107 GtkWidget *header_view;
2109 header_view = modest_main_window_get_child_widget (
2110 MODEST_MAIN_WINDOW(window),
2111 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2115 modest_header_view_select_next (
2116 MODEST_HEADER_VIEW(header_view));
2118 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
2119 modest_msg_view_window_select_next_message (
2120 MODEST_MSG_VIEW_WINDOW (window));
2123 g_return_if_reached ();
2128 modest_ui_actions_on_prev (GtkAction *action,
2129 ModestWindow *window)
2131 g_return_if_fail (MODEST_IS_WINDOW(window));
2133 #ifndef MODEST_TOOLKIT_HILDON2
2134 if (MODEST_IS_MAIN_WINDOW (window)) {
2135 GtkWidget *header_view;
2136 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
2137 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2141 modest_header_view_select_prev (MODEST_HEADER_VIEW(header_view));
2143 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
2144 modest_msg_view_window_select_previous_message (MODEST_MSG_VIEW_WINDOW (window));
2147 g_return_if_reached ();
2152 modest_ui_actions_on_sort (GtkAction *action,
2153 ModestWindow *window)
2155 GtkWidget *header_view = NULL;
2157 g_return_if_fail (MODEST_IS_WINDOW(window));
2159 #ifndef MODEST_TOOLKIT_HILDON2
2160 if (MODEST_IS_MAIN_WINDOW (window)) {
2161 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
2162 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2164 if (MODEST_IS_HEADER_WINDOW (window)) {
2165 header_view = GTK_WIDGET (modest_header_window_get_header_view (MODEST_HEADER_WINDOW (window)));
2170 modest_platform_information_banner (NULL, NULL, _CS("ckdg_ib_nothing_to_sort"));
2175 /* Show sorting dialog */
2176 modest_utils_run_sort_dialog (GTK_WINDOW (window), MODEST_SORT_HEADERS);
2180 idle_refresh_folder (gpointer source)
2182 ModestHeaderView *header_view = NULL;
2184 /* If the window still exists */
2185 if (!GTK_IS_WIDGET (source) ||
2186 !GTK_WIDGET_VISIBLE (source))
2189 /* Refresh the current view */
2190 #ifdef MODEST_TOOLKIT_HILDON2
2191 if (MODEST_IS_HEADER_WINDOW (source))
2192 header_view = modest_header_window_get_header_view ((ModestHeaderWindow *) source);
2194 if (MODEST_IS_MAIN_WINDOW (source))
2195 header_view = modest_main_window_get_child_widget ((ModestMainWindow *) source,
2196 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2199 TnyFolder *folder = modest_header_view_get_folder (header_view);
2201 /* We must clear first, because otherwise set_folder will ignore
2202 the change as the folders are the same */
2203 modest_header_view_clear (header_view);
2204 modest_header_view_set_folder (header_view, folder, TRUE,
2205 (ModestWindow *) source, NULL, NULL);
2206 g_object_unref (folder);
2214 update_account_cb (ModestMailOperation *self,
2215 TnyList *new_headers,
2219 gboolean show_visual_notifications;
2221 source = modest_mail_operation_get_source (self);
2222 show_visual_notifications = (source) ? FALSE : TRUE;
2224 /* Notify new messages have been downloaded. If the
2225 send&receive was invoked by the user then do not show any
2226 visual notification, only play a sound and activate the LED
2227 (for the Maemo version) */
2228 if (TNY_IS_LIST(new_headers) && (tny_list_get_length (new_headers)) > 0) {
2230 /* We only notify about really new messages (not seen) we get */
2231 TnyList *actually_new_list;
2232 TnyIterator *iterator;
2233 actually_new_list = TNY_LIST (tny_simple_list_new ());
2234 for (iterator = tny_list_create_iterator (new_headers);
2235 !tny_iterator_is_done (iterator);
2236 tny_iterator_next (iterator)) {
2238 TnyHeaderFlags flags;
2239 header = TNY_HEADER (tny_iterator_get_current (iterator));
2240 flags = tny_header_get_flags (header);
2242 if (!(flags & TNY_HEADER_FLAG_SEEN)) {
2243 /* Messages are ordered from most
2244 recent to oldest. But we want to
2245 show notifications starting from
2246 the oldest message. That's why we
2248 tny_list_prepend (actually_new_list, G_OBJECT (header));
2250 g_object_unref (header);
2252 g_object_unref (iterator);
2254 if (tny_list_get_length (actually_new_list) > 0) {
2255 GList *new_headers_list = NULL;
2257 new_headers_list = modest_utils_create_notification_list_from_header_list (actually_new_list);
2259 /* Send notifications */
2260 if (new_headers_list) {
2261 modest_platform_on_new_headers_received (new_headers_list,
2262 show_visual_notifications);
2264 modest_utils_free_notification_list (new_headers_list);
2267 g_object_unref (actually_new_list);
2271 /* Refresh the current folder in an idle. We do this
2272 in order to avoid refresh cancelations if the
2273 currently viewed folder is the inbox */
2274 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
2275 idle_refresh_folder,
2276 g_object_ref (source),
2278 g_object_unref (source);
2283 TnyAccount *account;
2285 gchar *account_name;
2286 gboolean poke_status;
2287 gboolean interactive;
2288 ModestMailOperation *mail_op;
2292 do_send_receive_performer (gboolean canceled,
2294 GtkWindow *parent_window,
2295 TnyAccount *account,
2298 SendReceiveInfo *info;
2300 info = (SendReceiveInfo *) user_data;
2302 if (err || canceled) {
2303 /* In disk full conditions we could get this error here */
2304 modest_tny_account_store_check_disk_full_error (modest_runtime_get_account_store(),
2305 (GtkWidget *) parent_window, err,
2308 if (info->mail_op) {
2309 modest_mail_operation_queue_remove (modest_runtime_get_mail_operation_queue (),
2315 #ifndef MODEST_TOOLKIT_HILDON2
2316 /* Set send/receive operation in progress */
2317 if (info->win && MODEST_IS_MAIN_WINDOW (info->win)) {
2318 modest_main_window_notify_send_receive_initied (MODEST_MAIN_WINDOW (info->win));
2321 if (info->win && MODEST_IS_MAIN_WINDOW (info->win))
2322 g_signal_connect (G_OBJECT (info->mail_op), "operation-finished",
2323 G_CALLBACK (on_send_receive_finished),
2327 /* Send & receive. */
2328 modest_mail_operation_update_account (info->mail_op, info->account_name,
2329 info->poke_status, info->interactive,
2330 update_account_cb, info->win);
2335 g_object_unref (G_OBJECT (info->mail_op));
2336 if (info->account_name)
2337 g_free (info->account_name);
2339 g_object_unref (info->win);
2341 g_object_unref (info->account);
2342 g_slice_free (SendReceiveInfo, info);
2346 * This function performs the send & receive required actions. The
2347 * window is used to create the mail operation. Typically it should
2348 * always be the main window, but we pass it as argument in order to
2352 modest_ui_actions_do_send_receive (const gchar *account_name,
2353 gboolean force_connection,
2354 gboolean poke_status,
2355 gboolean interactive,
2358 gchar *acc_name = NULL;
2359 SendReceiveInfo *info;
2360 ModestTnyAccountStore *acc_store;
2361 TnyAccount *account;
2363 /* If no account name was provided then get the current account, and if
2364 there is no current account then pick the default one: */
2365 if (!account_name) {
2367 acc_name = g_strdup (modest_window_get_active_account (win));
2369 acc_name = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
2371 modest_platform_information_banner (NULL, NULL, _("emev_ni_internal_error"));
2375 acc_name = g_strdup (account_name);
2378 acc_store = modest_runtime_get_account_store ();
2379 account = modest_tny_account_store_get_server_account (acc_store, acc_name, TNY_ACCOUNT_TYPE_STORE);
2383 modest_platform_information_banner (NULL, NULL, _("emev_ni_internal_error"));
2387 /* Do not automatically refresh accounts that are flagged as
2388 NO_AUTO_UPDATE. This could be useful for accounts that
2389 handle their own update times */
2391 ModestProtocolType proto = modest_tny_account_get_protocol_type (account);
2392 if (proto != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
2393 const gchar *tag = MODEST_PROTOCOL_REGISTRY_NO_AUTO_UPDATE_PROTOCOLS;
2394 ModestProtocolRegistry *registry = modest_runtime_get_protocol_registry ();
2396 if (modest_protocol_registry_protocol_type_has_tag (registry, proto, tag)) {
2397 g_debug ("%s no auto update allowed for account %s", __FUNCTION__, account_name);
2398 g_object_unref (account);
2405 /* Create the info for the connect and perform */
2406 info = g_slice_new (SendReceiveInfo);
2407 info->account_name = acc_name;
2408 info->win = (win) ? g_object_ref (win) : NULL;
2409 info->poke_status = poke_status;
2410 info->interactive = interactive;
2411 info->account = account;
2412 /* We need to create the operation here, because otherwise it
2413 could happen that the queue emits the queue-empty signal
2414 while we're trying to connect the account */
2415 info->mail_op = modest_mail_operation_new_with_error_handling ((info->win) ? G_OBJECT (info->win) : NULL,
2416 modest_ui_actions_disk_operations_error_handler,
2418 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), info->mail_op);
2420 /* Invoke the connect and perform */
2421 modest_platform_connect_and_perform ((win) ? GTK_WINDOW (win) : NULL,
2422 force_connection, info->account,
2423 do_send_receive_performer, info);
2428 modest_ui_actions_do_cancel_send (const gchar *account_name,
2431 TnyTransportAccount *transport_account;
2432 TnySendQueue *send_queue = NULL;
2433 GError *error = NULL;
2435 /* Get transport account */
2437 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
2438 (modest_runtime_get_account_store(),
2440 TNY_ACCOUNT_TYPE_TRANSPORT));
2441 if (!transport_account) {
2442 g_printerr ("modest: no transport account found for '%s'\n", account_name);
2447 send_queue = TNY_SEND_QUEUE (modest_runtime_get_send_queue (transport_account, TRUE));
2448 if (!TNY_IS_SEND_QUEUE(send_queue)) {
2449 g_set_error (&error, MODEST_MAIL_OPERATION_ERROR,
2450 MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND,
2451 "modest: could not find send queue for account\n");
2453 /* Cancel the current send */
2454 tny_account_cancel (TNY_ACCOUNT (transport_account));
2456 /* Suspend all pending messages */
2457 tny_send_queue_cancel (send_queue, TNY_SEND_QUEUE_CANCEL_ACTION_SUSPEND, &error);
2461 if (transport_account != NULL)
2462 g_object_unref (G_OBJECT (transport_account));
2466 modest_ui_actions_cancel_send_all (ModestWindow *win)
2468 GSList *account_names, *iter;
2470 account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
2473 iter = account_names;
2475 modest_ui_actions_do_cancel_send ((const char*) iter->data, win);
2476 iter = g_slist_next (iter);
2479 modest_account_mgr_free_account_names (account_names);
2480 account_names = NULL;
2484 modest_ui_actions_cancel_send (GtkAction *action, ModestWindow *win)
2487 /* Check if accounts exist */
2488 gboolean accounts_exist =
2489 modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
2491 /* If not, allow the user to create an account before trying to send/receive. */
2492 if (!accounts_exist)
2493 modest_ui_actions_on_accounts (NULL, win);
2495 /* Cancel all sending operaitons */
2496 modest_ui_actions_cancel_send_all (win);
2500 * Refreshes all accounts. This function will be used by automatic
2504 modest_ui_actions_do_send_receive_all (ModestWindow *win,
2505 gboolean force_connection,
2506 gboolean poke_status,
2507 gboolean interactive)
2509 GSList *account_names, *iter;
2511 account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
2514 iter = account_names;
2516 modest_ui_actions_do_send_receive ((const char*) iter->data,
2518 poke_status, interactive, win);
2519 iter = g_slist_next (iter);
2522 modest_account_mgr_free_account_names (account_names);
2523 account_names = NULL;
2527 * Handler of the click on Send&Receive button in the main toolbar
2530 modest_ui_actions_on_send_receive (GtkAction *action, ModestWindow *win)
2532 /* Check if accounts exist */
2533 gboolean accounts_exist;
2536 modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
2538 /* If not, allow the user to create an account before trying to send/receive. */
2539 if (!accounts_exist)
2540 modest_ui_actions_on_accounts (NULL, win);
2542 /* Refresh the current folder. The if is always TRUE it's just an extra check */
2543 #ifndef MODEST_TOOLKIT_HILDON2
2544 if (MODEST_IS_MAIN_WINDOW (win)) {
2545 GtkWidget *folder_view;
2546 TnyFolderStore *folder_store;
2549 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
2550 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2554 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
2557 g_object_unref (folder_store);
2558 /* Refresh the active account. Force the connection if needed
2559 and poke the status of all folders */
2560 modest_ui_actions_do_send_receive (NULL, TRUE, TRUE, TRUE, win);
2562 if (MODEST_IS_ACCOUNTS_WINDOW (win)) {
2563 modest_ui_actions_do_send_receive_all (win, TRUE, TRUE, TRUE);
2566 const gchar *active_account;
2567 active_account = modest_window_get_active_account (MODEST_WINDOW (win));
2569 modest_ui_actions_do_send_receive (active_account, TRUE, TRUE, TRUE, win);
2574 #ifndef MODEST_TOOLKIT_HILDON2
2576 modest_ui_actions_toggle_header_list_view (GtkAction *action, ModestMainWindow *main_window)
2579 GtkWidget *header_view;
2581 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2583 header_view = modest_main_window_get_child_widget (main_window,
2584 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2588 conf = modest_runtime_get_conf ();
2590 /* what is saved/restored is depending on the style; thus; we save with
2591 * old style, then update the style, and restore for this new style
2593 modest_widget_memory_save (conf, G_OBJECT(header_view), MODEST_CONF_HEADER_VIEW_KEY);
2595 if (modest_header_view_get_style
2596 (MODEST_HEADER_VIEW(header_view)) == MODEST_HEADER_VIEW_STYLE_DETAILS)
2597 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
2598 MODEST_HEADER_VIEW_STYLE_TWOLINES);
2600 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
2601 MODEST_HEADER_VIEW_STYLE_DETAILS);
2603 modest_widget_memory_restore (conf, G_OBJECT(header_view),
2604 MODEST_CONF_HEADER_VIEW_KEY);
2608 modest_ui_actions_on_header_selected (ModestHeaderView *header_view,
2610 ModestMainWindow *main_window)
2612 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2613 g_return_if_fail (MODEST_IS_HEADER_VIEW (header_view));
2615 /* in the case the folder is empty, show the empty folder message and focus
2617 if (!header && gtk_widget_is_focus (GTK_WIDGET (header_view))) {
2618 if (modest_header_view_is_empty (header_view)) {
2619 TnyFolder *folder = modest_header_view_get_folder (header_view);
2620 GtkWidget *folder_view =
2621 modest_main_window_get_child_widget (main_window,
2622 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2623 if (folder != NULL) {
2624 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view), folder, FALSE);
2625 g_object_unref (folder);
2627 gtk_widget_grab_focus (GTK_WIDGET (folder_view));
2631 /* If no header has been selected then exit */
2636 if (!gtk_widget_is_focus (GTK_WIDGET(header_view)))
2637 gtk_widget_grab_focus (GTK_WIDGET(header_view));
2639 /* Update toolbar dimming state */
2640 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (main_window));
2641 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
2646 modest_ui_actions_on_header_activated (ModestHeaderView *header_view,
2649 ModestWindow *window)
2651 GtkTreeRowReference *rowref;
2653 g_return_if_fail (MODEST_IS_WINDOW(window));
2654 g_return_if_fail (MODEST_IS_HEADER_VIEW (header_view));
2655 g_return_if_fail (TNY_IS_HEADER (header));
2657 if (modest_header_view_count_selected_headers (header_view) > 1) {
2658 /* Don't allow activation if there are more than one message selected */
2659 modest_platform_information_banner (NULL, NULL, _("mcen_ib_select_one_message"));
2663 /* we check for low-mem; in that case, show a warning, and don't allow
2664 * activating headers
2666 if (modest_platform_check_memory_low (MODEST_WINDOW(window), TRUE))
2669 #ifndef MODEST_TOOLKIT_HILDON2
2670 GtkWidget *open_widget;
2671 if (MODEST_IS_MAIN_WINDOW (window)) {
2672 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (window));
2673 open_widget = modest_window_get_action_widget (MODEST_WINDOW (window), "/MenuBar/EmailMenu/EmailOpenMenu");
2674 if (!GTK_WIDGET_IS_SENSITIVE (open_widget))
2679 rowref = gtk_tree_row_reference_new (gtk_tree_view_get_model (GTK_TREE_VIEW (header_view)), path);
2680 open_msg_from_header (header, rowref, MODEST_WINDOW (window));
2681 gtk_tree_row_reference_free (rowref);
2684 #ifndef MODEST_TOOLKIT_HILDON2
2686 set_active_account_from_tny_account (TnyAccount *account,
2687 ModestWindow *window)
2689 const gchar *server_acc_name = tny_account_get_id (account);
2691 /* We need the TnyAccount provided by the
2692 account store because that is the one that
2693 knows the name of the Modest account */
2694 TnyAccount *modest_server_account =
2695 modest_tny_account_store_get_tny_account_by (modest_runtime_get_account_store (),
2696 MODEST_TNY_ACCOUNT_STORE_QUERY_ID,
2698 if (!modest_server_account) {
2699 g_warning ("%s: could not get tny account\n", __FUNCTION__);
2703 /* Update active account, but only if it's not a pseudo-account */
2704 if ((!modest_tny_account_is_virtual_local_folders(modest_server_account)) &&
2705 (!modest_tny_account_is_memory_card_account(modest_server_account))) {
2706 const gchar *modest_acc_name =
2707 modest_tny_account_get_parent_modest_account_name_for_server_account (modest_server_account);
2708 if (modest_acc_name)
2709 modest_window_set_active_account (window, modest_acc_name);
2712 g_object_unref (modest_server_account);
2716 folder_refreshed_cb (ModestMailOperation *mail_op,
2720 ModestMainWindow *win = NULL;
2721 GtkWidget *folder_view, *header_view;
2722 const GError *error;
2724 g_return_if_fail (TNY_IS_FOLDER (folder));
2726 win = MODEST_MAIN_WINDOW (user_data);
2728 /* Check if the operation failed due to memory low conditions */
2729 error = modest_mail_operation_get_error (mail_op);
2730 if (error && error->domain == MODEST_MAIL_OPERATION_ERROR &&
2731 error->code == MODEST_MAIL_OPERATION_ERROR_LOW_MEMORY) {
2732 modest_platform_run_information_dialog (GTK_WINDOW (win),
2733 _KR("memr_ib_operation_disabled"),
2739 modest_main_window_get_child_widget(win, MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2741 modest_main_window_get_child_widget(win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2744 TnyFolderStore *current_folder;
2746 current_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
2747 if (current_folder) {
2748 gboolean different = ((TnyFolderStore *) folder != current_folder);
2749 g_object_unref (current_folder);
2755 /* Check if folder is empty and set headers view contents style */
2756 if ((tny_folder_get_all_count (folder) == 0) ||
2757 modest_header_view_is_empty (MODEST_HEADER_VIEW (header_view)))
2758 modest_main_window_set_contents_style (win,
2759 MODEST_MAIN_WINDOW_CONTENTS_STYLE_EMPTY);
2763 modest_ui_actions_on_folder_selection_changed (ModestFolderView *folder_view,
2764 TnyFolderStore *folder_store,
2766 ModestMainWindow *main_window)
2768 GtkWidget *header_view;
2770 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2772 header_view = modest_main_window_get_child_widget(main_window,
2773 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2778 if (TNY_IS_ACCOUNT (folder_store)) {
2780 set_active_account_from_tny_account (TNY_ACCOUNT (folder_store), MODEST_WINDOW (main_window));
2782 /* Show account details */
2783 modest_main_window_set_contents_style (main_window, MODEST_MAIN_WINDOW_CONTENTS_STYLE_DETAILS);
2786 if (TNY_IS_FOLDER (folder_store) && selected) {
2787 TnyAccount *account;
2789 /* Update the active account */
2790 account = modest_tny_folder_get_account (TNY_FOLDER (folder_store));
2792 set_active_account_from_tny_account (account, MODEST_WINDOW (main_window));
2793 g_object_unref (account);
2797 /* Set the header style by default, it could
2798 be changed later by the refresh callback to
2800 modest_main_window_set_contents_style (main_window,
2801 MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS);
2803 /* Set folder on header view. This function
2804 will call tny_folder_refresh_async so we
2805 pass a callback that will be called when
2806 finished. We use that callback to set the
2807 empty view if there are no messages */
2808 modest_header_view_set_folder (MODEST_HEADER_VIEW(header_view),
2809 TNY_FOLDER (folder_store),
2811 MODEST_WINDOW (main_window),
2812 folder_refreshed_cb,
2815 /* Restore configuration. We need to do this
2816 *after* the set_folder because the widget
2817 memory asks the header view about its
2819 modest_widget_memory_restore (modest_runtime_get_conf (),
2820 G_OBJECT(header_view),
2821 MODEST_CONF_HEADER_VIEW_KEY);
2823 /* No need to save the header view
2824 configuration for Maemo because it only
2825 saves the sorting stuff and that it's
2826 already being done by the sort
2827 dialog. Remove it when the GNOME version
2828 has the same behaviour */
2829 #ifdef MODEST_TOOLKIT_GTK
2830 if (modest_main_window_get_contents_style (main_window) ==
2831 MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS)
2832 modest_widget_memory_save (modest_runtime_get_conf (),
2833 G_OBJECT (header_view),
2834 MODEST_CONF_HEADER_VIEW_KEY);
2836 modest_header_view_clear (MODEST_HEADER_VIEW(header_view));
2840 /* Update dimming state */
2841 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (main_window));
2842 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
2847 modest_ui_actions_on_item_not_found (ModestHeaderView *header_view,ModestItemType type,
2854 item = (type == MODEST_ITEM_TYPE_FOLDER) ? "folder" : "message";
2856 online = tny_device_is_online (modest_runtime_get_device());
2859 /* already online -- the item is simply not there... */
2860 dialog = gtk_message_dialog_new (GTK_WINDOW (win),
2862 GTK_MESSAGE_WARNING,
2864 _("The %s you selected cannot be found"),
2866 gtk_dialog_add_button (GTK_DIALOG (dialog),_("mcen_bd_dialog_ok"), GTK_RESPONSE_ACCEPT);
2867 gtk_dialog_run (GTK_DIALOG(dialog));
2869 dialog = gtk_dialog_new_with_buttons (_("Connection requested"),
2872 _("mcen_bd_dialog_cancel"),
2873 GTK_RESPONSE_REJECT,
2874 _("mcen_bd_dialog_ok"),
2875 GTK_RESPONSE_ACCEPT,
2877 txt = g_strdup_printf (_("This %s is not available in offline mode.\n"
2878 "Do you want to get online?"), item);
2879 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
2880 gtk_label_new (txt), FALSE, FALSE, 0);
2881 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
2884 gtk_window_set_default_size (GTK_WINDOW(dialog), 300, 300);
2885 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
2886 /* TODO: Comment about why is this commented out: */
2887 /* modest_platform_connect_and_wait (); */
2890 gtk_widget_destroy (dialog);
2894 modest_ui_actions_on_msg_link_hover (ModestMsgView *msgview, const gchar* link,
2897 /* g_debug ("%s %s", __FUNCTION__, link); */
2902 modest_ui_actions_on_msg_link_clicked (ModestMsgView *msgview, const gchar* link,
2905 modest_platform_activate_uri (link);
2909 modest_ui_actions_on_msg_link_contextual (ModestMsgView *msgview, const gchar* link,
2912 modest_platform_show_uri_popup (link);
2916 modest_ui_actions_on_msg_attachment_clicked (ModestMsgView *msgview, TnyMimePart *mime_part,
2919 /* we check for low-mem; in that case, show a warning, and don't allow
2920 * viewing attachments
2922 if (modest_platform_check_memory_low (MODEST_WINDOW(win), TRUE))
2925 modest_msg_view_window_view_attachment (MODEST_MSG_VIEW_WINDOW (win), mime_part);
2929 modest_ui_actions_on_msg_recpt_activated (ModestMsgView *msgview,
2930 const gchar *address,
2933 /* g_debug ("%s %s", __FUNCTION__, address); */
2937 on_save_to_drafts_cb (ModestMailOperation *mail_op,
2938 TnyMsg *saved_draft,
2941 ModestMsgEditWindow *edit_window;
2943 /* TODO: in hildon 2 we have to dim and undim the header views while we're saving */
2944 #ifndef MODEST_TOOLKIT_HILDON2
2945 ModestMainWindow *win;
2947 /* FIXME. Make the header view sensitive again. This is a
2948 * temporary hack. See modest_ui_actions_on_save_to_drafts()
2950 win = MODEST_MAIN_WINDOW(modest_window_mgr_get_main_window(
2951 modest_runtime_get_window_mgr(), FALSE));
2953 GtkWidget *hdrview = modest_main_window_get_child_widget(
2954 win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2955 if (hdrview) gtk_widget_set_sensitive(hdrview, TRUE);
2959 edit_window = MODEST_MSG_EDIT_WINDOW (user_data);
2961 /* Set draft is there was no error */
2962 if (!modest_mail_operation_get_error (mail_op))
2963 modest_msg_edit_window_set_draft (edit_window, saved_draft);
2965 g_object_unref(edit_window);
2969 enough_space_for_message (ModestMsgEditWindow *edit_window,
2972 guint64 available_disk, expected_size;
2977 available_disk = modest_utils_get_available_space (NULL);
2978 modest_msg_edit_window_get_parts_size (edit_window, &parts_count, &parts_size);
2979 expected_size = modest_tny_msg_estimate_size (data->plain_body,
2984 /* Double check: disk full condition or message too big */
2985 if (available_disk < MODEST_TNY_ACCOUNT_STORE_MIN_FREE_SPACE ||
2986 expected_size > available_disk) {
2987 gchar *msg = g_strdup_printf (_KR("cerm_device_memory_full"), "");
2988 modest_platform_information_banner (NULL, NULL, msg);
2995 * djcb: if we're in low-memory state, we only allow for
2996 * saving messages smaller than
2997 * MODEST_MAX_LOW_MEMORY_MESSAGE_SIZE (see modest-defs.h) this
2998 * should still allow for sending anything critical...
3000 if ((expected_size > MODEST_MAX_LOW_MEMORY_MESSAGE_SIZE) &&
3001 modest_platform_check_memory_low (MODEST_WINDOW(edit_window), TRUE))
3005 * djcb: we also make sure that the attachments are smaller than the max size
3006 * this is for the case where we'd try to forward a message with attachments
3007 * bigger than our max allowed size, or sending an message from drafts which
3008 * somehow got past our checks when attaching.
3010 if (expected_size > MODEST_MAX_ATTACHMENT_SIZE) {
3011 modest_platform_run_information_dialog (
3012 GTK_WINDOW(edit_window),
3013 _("mail_ib_error_attachment_size"),
3022 modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edit_window)
3024 TnyTransportAccount *transport_account;
3025 ModestMailOperation *mail_operation;
3027 gchar *account_name;
3028 ModestAccountMgr *account_mgr;
3029 gboolean had_error = FALSE;
3031 g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window), FALSE);
3033 data = modest_msg_edit_window_get_msg_data (edit_window);
3036 if (!enough_space_for_message (edit_window, data)) {
3037 modest_msg_edit_window_free_msg_data (edit_window, data);
3041 account_name = g_strdup (data->account_name);
3042 account_mgr = modest_runtime_get_account_mgr();
3044 account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
3046 account_name = modest_account_mgr_get_default_account (account_mgr);
3047 if (!account_name) {
3048 g_printerr ("modest: no account found\n");
3049 modest_msg_edit_window_free_msg_data (edit_window, data);
3053 if (!strcmp (account_name, MODEST_LOCAL_FOLDERS_ACCOUNT_ID)) {
3054 account_name = g_strdup (data->account_name);
3058 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
3059 (modest_runtime_get_account_store (),
3061 TNY_ACCOUNT_TYPE_TRANSPORT));
3062 if (!transport_account) {
3063 g_printerr ("modest: no transport account found for '%s'\n", account_name);
3064 g_free (account_name);
3065 modest_msg_edit_window_free_msg_data (edit_window, data);
3069 /* Create the mail operation */
3070 mail_operation = modest_mail_operation_new_with_error_handling (NULL, modest_ui_actions_disk_operations_error_handler,
3072 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
3074 modest_mail_operation_save_to_drafts (mail_operation,
3086 data->priority_flags,
3089 on_save_to_drafts_cb,
3090 g_object_ref(edit_window));
3092 #ifdef MODEST_TOOLKIT_HILDON2
3093 /* In hildon2 we always show the information banner on saving to drafts.
3094 * It will be a system information banner in this case.
3096 gchar *text = g_strdup_printf (_("mail_va_saved_to_drafts"), _("mcen_me_folder_drafts"));
3097 modest_platform_information_banner (NULL, NULL, text);
3100 ModestMainWindow *win = NULL;
3102 /* Use the main window as the parent of the banner, if the
3103 main window does not exist it won't be shown, if the parent
3104 window exists then it's properly shown. We don't use the
3105 editor window because it could be closed (save to drafts
3106 could happen after closing the window */
3107 win = (ModestMainWindow *)
3108 modest_window_mgr_get_main_window( modest_runtime_get_window_mgr(), FALSE);
3110 gchar *text = g_strdup_printf (_("mail_va_saved_to_drafts"), _("mcen_me_folder_drafts"));
3111 modest_platform_information_banner (GTK_WIDGET (win), NULL, text);
3115 modest_msg_edit_window_set_modified (edit_window, FALSE);
3118 g_free (account_name);
3119 g_object_unref (G_OBJECT (transport_account));
3120 g_object_unref (G_OBJECT (mail_operation));
3122 modest_msg_edit_window_free_msg_data (edit_window, data);
3124 #ifndef MODEST_TOOLKIT_HILDON2
3126 * If the drafts folder is selected then make the header view
3127 * insensitive while the message is being saved to drafts
3128 * (it'll be sensitive again in on_save_to_drafts_cb()). This
3129 * is not very clean but it avoids letting the drafts folder
3130 * in an inconsistent state: the user could edit the message
3131 * being saved and undesirable things would happen.
3132 * In the average case the user won't notice anything at
3133 * all. In the worst case (the user is editing a really big
3134 * file from Drafts) the header view will be insensitive
3135 * during the saving process (10 or 20 seconds, depending on
3136 * the message). Anyway this is just a quick workaround: once
3137 * we find a better solution it should be removed
3138 * See NB#65125 (commend #18) for details.
3140 if (!had_error && win != NULL) {
3141 ModestFolderView *view = MODEST_FOLDER_VIEW(modest_main_window_get_child_widget(
3142 win, MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW));
3144 TnyFolder *folder = TNY_FOLDER(modest_folder_view_get_selected(view));
3146 if (modest_tny_folder_is_local_folder(folder)) {
3147 TnyFolderType folder_type;
3148 folder_type = modest_tny_folder_get_local_or_mmc_folder_type(folder);
3149 if (folder_type == TNY_FOLDER_TYPE_DRAFTS) {
3150 GtkWidget *hdrview = modest_main_window_get_child_widget(
3151 win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
3152 if (hdrview) gtk_widget_set_sensitive(hdrview, FALSE);
3156 if (folder != NULL) g_object_unref(folder);
3164 /* For instance, when clicking the Send toolbar button when editing a message: */
3166 modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
3168 TnyTransportAccount *transport_account = NULL;
3169 gboolean had_error = FALSE;
3171 ModestAccountMgr *account_mgr;
3172 gchar *account_name;
3173 ModestMailOperation *mail_operation;
3176 g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window), TRUE);
3178 if (!modest_msg_edit_window_check_names (edit_window, TRUE))
3181 data = modest_msg_edit_window_get_msg_data (edit_window);
3183 recipients = g_strconcat (data->to?data->to:"",
3184 data->cc?data->cc:"",
3185 data->bcc?data->bcc:"",
3187 if (recipients == NULL || recipients[0] == '\0') {
3188 /* Empty subject -> no send */
3189 g_free (recipients);
3190 modest_msg_edit_window_free_msg_data (edit_window, data);
3193 g_free (recipients);
3196 if (!enough_space_for_message (edit_window, data)) {
3197 modest_msg_edit_window_free_msg_data (edit_window, data);
3201 account_mgr = modest_runtime_get_account_mgr();
3202 account_name = g_strdup (data->account_name);
3204 account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
3207 account_name = modest_account_mgr_get_default_account (account_mgr);
3209 if (!account_name) {
3210 modest_msg_edit_window_free_msg_data (edit_window, data);
3211 /* Run account setup wizard */
3212 if (!modest_ui_actions_run_account_setup_wizard (MODEST_WINDOW(edit_window))) {
3217 /* Get the currently-active transport account for this modest account: */
3218 if (account_name && strcmp (account_name, MODEST_LOCAL_FOLDERS_ACCOUNT_ID) != 0) {
3220 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
3221 (modest_runtime_get_account_store (),
3222 account_name, TNY_ACCOUNT_TYPE_TRANSPORT));
3225 if (!transport_account) {
3226 modest_msg_edit_window_free_msg_data (edit_window, data);
3227 /* Run account setup wizard */
3228 if (!modest_ui_actions_run_account_setup_wizard(MODEST_WINDOW(edit_window)))
3233 /* Create the mail operation */
3234 mail_operation = modest_mail_operation_new_with_error_handling (NULL, modest_ui_actions_disk_operations_error_handler, NULL, NULL);
3235 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
3237 modest_mail_operation_send_new_mail (mail_operation,
3251 data->priority_flags);
3253 if (modest_mail_operation_get_status (mail_operation) == MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS)
3254 modest_platform_information_banner (NULL, NULL, _("mcen_ib_outbox_waiting_to_be_sent"));
3256 if (modest_mail_operation_get_error (mail_operation) != NULL) {
3257 const GError *error = modest_mail_operation_get_error (mail_operation);
3258 if (error->domain == MODEST_MAIL_OPERATION_ERROR &&
3259 error->code == MODEST_MAIL_OPERATION_ERROR_INSTANCE_CREATION_FAILED) {
3260 g_warning ("%s failed: %s\n", __FUNCTION__, (modest_mail_operation_get_error (mail_operation))->message);
3261 modest_platform_information_banner (NULL, NULL, _CS("sfil_ni_not_enough_memory"));
3267 g_free (account_name);
3268 g_object_unref (G_OBJECT (transport_account));
3269 g_object_unref (G_OBJECT (mail_operation));
3271 modest_msg_edit_window_free_msg_data (edit_window, data);
3274 modest_msg_edit_window_set_sent (edit_window, TRUE);
3276 /* Save settings and close the window: */
3277 modest_ui_actions_on_close_window (NULL, MODEST_WINDOW (edit_window));
3284 modest_ui_actions_on_toggle_bold (GtkToggleAction *action,
3285 ModestMsgEditWindow *window)
3287 ModestMsgEditFormatState *format_state = NULL;
3289 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3290 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
3292 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3295 format_state = modest_msg_edit_window_get_format_state (window);
3296 g_return_if_fail (format_state != NULL);
3298 format_state->bold = gtk_toggle_action_get_active (action);
3299 modest_msg_edit_window_set_format_state (window, format_state);
3300 g_free (format_state);
3305 modest_ui_actions_on_toggle_italics (GtkToggleAction *action,
3306 ModestMsgEditWindow *window)
3308 ModestMsgEditFormatState *format_state = NULL;
3310 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3311 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
3313 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3316 format_state = modest_msg_edit_window_get_format_state (window);
3317 g_return_if_fail (format_state != NULL);
3319 format_state->italics = gtk_toggle_action_get_active (action);
3320 modest_msg_edit_window_set_format_state (window, format_state);
3321 g_free (format_state);
3326 modest_ui_actions_on_toggle_bullets (GtkToggleAction *action,
3327 ModestMsgEditWindow *window)
3329 ModestMsgEditFormatState *format_state = NULL;
3331 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3332 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
3334 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3337 format_state = modest_msg_edit_window_get_format_state (window);
3338 g_return_if_fail (format_state != NULL);
3340 format_state->bullet = gtk_toggle_action_get_active (action);
3341 modest_msg_edit_window_set_format_state (window, format_state);
3342 g_free (format_state);
3347 modest_ui_actions_on_change_justify (GtkRadioAction *action,
3348 GtkRadioAction *selected,
3349 ModestMsgEditWindow *window)
3351 ModestMsgEditFormatState *format_state = NULL;
3352 GtkJustification value;
3354 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3356 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3359 value = gtk_radio_action_get_current_value (selected);
3361 format_state = modest_msg_edit_window_get_format_state (window);
3362 g_return_if_fail (format_state != NULL);
3364 format_state->justification = value;
3365 modest_msg_edit_window_set_format_state (window, format_state);
3366 g_free (format_state);
3370 modest_ui_actions_on_select_editor_color (GtkAction *action,
3371 ModestMsgEditWindow *window)
3373 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3374 g_return_if_fail (GTK_IS_ACTION (action));
3376 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3379 modest_msg_edit_window_select_color (window);
3383 modest_ui_actions_on_select_editor_background_color (GtkAction *action,
3384 ModestMsgEditWindow *window)
3386 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3387 g_return_if_fail (GTK_IS_ACTION (action));
3389 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3392 modest_msg_edit_window_select_background_color (window);
3396 modest_ui_actions_on_insert_image (GObject *object,
3397 ModestMsgEditWindow *window)
3399 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3402 if (modest_platform_check_memory_low (MODEST_WINDOW(window), TRUE))
3405 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3408 modest_msg_edit_window_insert_image (window);
3412 modest_ui_actions_on_attach_file (GtkAction *action,
3413 ModestMsgEditWindow *window)
3415 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3416 g_return_if_fail (GTK_IS_ACTION (action));
3418 if (modest_platform_check_memory_low (MODEST_WINDOW(window), TRUE))
3421 modest_msg_edit_window_offer_attach_file (window);
3425 modest_ui_actions_on_remove_attachments (GtkAction *action,
3426 ModestMsgEditWindow *window)
3428 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3430 modest_msg_edit_window_remove_attachments (window, NULL);
3434 do_create_folder_cb (ModestMailOperation *mail_op,
3435 TnyFolderStore *parent_folder,
3436 TnyFolder *new_folder,
3439 gchar *suggested_name = (gchar *) user_data;
3440 GtkWindow *source_win = (GtkWindow *) modest_mail_operation_get_source (mail_op);
3441 const GError *error;
3443 error = modest_mail_operation_get_error (mail_op);
3445 gboolean disk_full = FALSE;
3446 TnyAccount *account;
3447 /* Show an error. If there was some problem writing to
3448 disk, show it, otherwise show the generic folder
3449 create error. We do it here and not in an error
3450 handler because the call to do_create_folder will
3451 stop the main loop in a gtk_dialog_run and then,
3452 the message won't be shown until that dialog is
3454 account = modest_mail_operation_get_account (mail_op);
3457 modest_tny_account_store_check_disk_full_error (modest_runtime_get_account_store(),
3458 (GtkWidget *) source_win,
3461 _("mail_in_ui_folder_create_error_memory"));
3462 g_object_unref (account);
3465 /* Show an error and try again if there is no
3466 full memory condition */
3467 modest_platform_information_banner ((GtkWidget *) source_win, NULL,
3468 _("mail_in_ui_folder_create_error"));
3469 do_create_folder (source_win, parent_folder, (const gchar *) suggested_name);
3473 /* the 'source_win' is either the ModestMainWindow, or the 'Move to folder'-dialog
3474 * FIXME: any other? */
3475 GtkWidget *folder_view;
3477 #ifndef MODEST_TOOLKIT_HILDON2
3478 if (MODEST_IS_MAIN_WINDOW(source_win))
3480 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (source_win),
3481 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3484 folder_view = GTK_WIDGET(g_object_get_data (G_OBJECT (source_win),
3485 MODEST_MOVE_TO_DIALOG_FOLDER_VIEW));
3487 /* Select the newly created folder. It could happen
3488 that the widget is no longer there (i.e. the window
3489 has been destroyed, so we need to check this */
3491 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view),
3493 g_object_unref (new_folder);
3495 /* Free. Note that the first time it'll be NULL so noop */
3496 g_free (suggested_name);
3497 g_object_unref (source_win);
3502 TnyFolderStore *parent;
3503 } CreateFolderConnect;
3506 do_create_folder_performer (gboolean canceled,
3508 GtkWindow *parent_window,
3509 TnyAccount *account,
3512 CreateFolderConnect *helper = (CreateFolderConnect *) user_data;
3513 ModestMailOperation *mail_op;
3515 if (canceled || err) {
3516 /* In disk full conditions we could get this error here */
3517 modest_tny_account_store_check_disk_full_error (modest_runtime_get_account_store(),
3518 (GtkWidget *) parent_window, err,
3519 NULL, _("mail_in_ui_folder_create_error_memory"));
3521 /* This happens if we have selected the outbox folder
3523 if (err && err->code == TNY_SERVICE_ERROR_UNKNOWN &&
3524 TNY_IS_MERGE_FOLDER (helper->parent)) {
3525 /* Show an error and retry */
3526 modest_platform_information_banner ((GtkWidget *) parent_window,
3528 _("mail_in_ui_folder_create_error"));
3530 do_create_folder (parent_window, helper->parent, helper->folder_name);
3536 mail_op = modest_mail_operation_new ((GObject *) parent_window);
3537 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
3539 modest_mail_operation_create_folder (mail_op,
3541 (const gchar *) helper->folder_name,
3542 do_create_folder_cb,
3543 g_strdup (helper->folder_name));
3544 g_object_unref (mail_op);
3548 g_object_unref (helper->parent);
3549 if (helper->folder_name)
3550 g_free (helper->folder_name);
3551 g_slice_free (CreateFolderConnect, helper);
3556 do_create_folder (GtkWindow *parent_window,
3557 TnyFolderStore *suggested_parent,
3558 const gchar *suggested_name)
3561 gchar *folder_name = NULL;
3562 TnyFolderStore *parent_folder = NULL;
3564 result = modest_platform_run_new_folder_dialog (GTK_WINDOW (parent_window),
3566 (gchar *) suggested_name,
3570 if (result == GTK_RESPONSE_ACCEPT && parent_folder) {
3571 CreateFolderConnect *helper = (CreateFolderConnect *) g_slice_new0 (CreateFolderConnect);
3572 helper->folder_name = g_strdup (folder_name);
3573 helper->parent = g_object_ref (parent_folder);
3575 modest_platform_connect_if_remote_and_perform (GTK_WINDOW (parent_window),
3578 do_create_folder_performer,
3583 g_free (folder_name);
3585 g_object_unref (parent_folder);
3589 modest_ui_actions_create_folder(GtkWidget *parent_window,
3590 GtkWidget *folder_view,
3591 TnyFolderStore *parent_folder)
3593 if (!parent_folder) {
3594 #ifdef MODEST_TOOLKIT_HILDON2
3595 ModestTnyAccountStore *acc_store;
3597 acc_store = modest_runtime_get_account_store ();
3599 parent_folder = (TnyFolderStore *)
3600 modest_tny_account_store_get_local_folders_account (acc_store);
3602 parent_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
3606 if (parent_folder) {
3607 do_create_folder (GTK_WINDOW (parent_window), parent_folder, NULL);
3608 g_object_unref (parent_folder);
3613 modest_ui_actions_on_new_folder (GtkAction *action, ModestWindow *window)
3616 g_return_if_fail (MODEST_IS_WINDOW(window));
3618 #ifndef MODEST_TOOLKIT_HILDON2
3619 if (MODEST_IS_MAIN_WINDOW (window)) {
3620 GtkWidget *folder_view;
3622 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (window),
3623 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3627 modest_ui_actions_create_folder (GTK_WIDGET (window), folder_view, NULL);
3629 if (MODEST_IS_FOLDER_WINDOW (window)) {
3630 GtkWidget *folder_view;
3632 folder_view = GTK_WIDGET (modest_folder_window_get_folder_view (MODEST_FOLDER_WINDOW (window)));
3633 modest_ui_actions_create_folder (GTK_WIDGET (window), folder_view, NULL);
3636 g_assert_not_reached ();
3641 modest_ui_actions_rename_folder_error_handler (ModestMailOperation *mail_op,
3644 const GError *error = NULL;
3645 gchar *message = NULL;
3647 TnyAccount *account = modest_mail_operation_get_account (mail_op);
3649 /* Get error message */
3650 error = modest_mail_operation_get_error (mail_op);
3652 g_return_if_reached ();
3654 mem_full = modest_tny_account_store_is_disk_full_error (modest_runtime_get_account_store(),
3655 (GError *) error, account);
3657 message = g_strdup_printf (_KR("cerm_device_memory_full"), "");
3658 } else if (error->domain == MODEST_MAIL_OPERATION_ERROR &&
3659 error->code == MODEST_MAIL_OPERATION_ERROR_FOLDER_EXISTS) {
3660 message = _CS("ckdg_ib_folder_already_exists");
3661 } else if (error->domain == TNY_ERROR_DOMAIN &&
3662 error->code == TNY_SERVICE_ERROR_STATE) {
3663 /* This means that the folder is already in use (a
3664 message is opened for example */
3665 message = _("emev_ni_internal_error");
3667 message = _CS("ckdg_ib_unable_to_rename");
3670 /* We don't set a parent for the dialog because the dialog
3671 will be destroyed so the banner won't appear */
3672 modest_platform_information_banner (NULL, NULL, message);
3675 g_object_unref (account);
3681 TnyFolderStore *folder;
3686 on_rename_folder_cb (ModestMailOperation *mail_op,
3687 TnyFolder *new_folder,
3690 ModestFolderView *folder_view;
3692 /* If the window was closed when renaming a folder, or if
3693 * it's not a main window this will happen */
3694 if (!MODEST_IS_FOLDER_VIEW (user_data))
3697 folder_view = MODEST_FOLDER_VIEW (user_data);
3698 /* Note that if the rename fails new_folder will be NULL */
3700 modest_folder_view_select_folder (folder_view, new_folder, FALSE);
3701 #ifndef MODEST_TOOLKIT_HILDON2
3703 modest_folder_view_select_first_inbox_or_local (folder_view);
3706 gtk_widget_grab_focus (GTK_WIDGET (folder_view));
3710 on_rename_folder_performer (gboolean canceled,
3712 GtkWindow *parent_window,
3713 TnyAccount *account,
3716 ModestMailOperation *mail_op = NULL;
3717 GtkTreeSelection *sel = NULL;
3718 GtkWidget *folder_view = NULL;
3719 RenameFolderInfo *data = (RenameFolderInfo*)user_data;
3721 if (canceled || err) {
3722 /* In disk full conditions we could get this error here */
3723 modest_tny_account_store_check_disk_full_error (modest_runtime_get_account_store(),
3724 (GtkWidget *) parent_window, err,
3729 modest_mail_operation_new_with_error_handling (G_OBJECT(parent_window),
3730 modest_ui_actions_rename_folder_error_handler,
3731 parent_window, NULL);
3733 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
3735 #ifndef MODEST_TOOLKIT_HILDON2
3736 if (MODEST_IS_MAIN_WINDOW(parent_window)) {
3738 folder_view = modest_main_window_get_child_widget (
3739 MODEST_MAIN_WINDOW (parent_window),
3740 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3743 if (MODEST_IS_FOLDER_WINDOW (parent_window)) {
3744 ModestFolderWindow *folder_window = (ModestFolderWindow *) parent_window;
3745 folder_view = GTK_WIDGET (modest_folder_window_get_folder_view (folder_window));
3749 /* Clear the folders view */
3750 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_view));
3751 gtk_tree_selection_unselect_all (sel);
3753 /* Actually rename the folder */
3754 modest_mail_operation_rename_folder (mail_op,
3755 TNY_FOLDER (data->folder),
3756 (const gchar *) (data->new_name),
3757 on_rename_folder_cb,
3759 g_object_unref (mail_op);
3762 g_object_unref (data->folder);
3763 g_free (data->new_name);
3768 modest_ui_actions_on_rename_folder (GtkAction *action,
3769 ModestWindow *window)
3771 modest_ui_actions_on_edit_mode_rename_folder (window);
3775 modest_ui_actions_on_edit_mode_rename_folder (ModestWindow *window)
3777 TnyFolderStore *folder;
3778 GtkWidget *folder_view;
3779 gboolean do_rename = TRUE;
3781 g_return_val_if_fail (MODEST_IS_WINDOW(window), FALSE);
3783 #ifndef MODEST_TOOLKIT_HILDON2
3784 if (MODEST_IS_MAIN_WINDOW (window)) {
3785 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (window),
3786 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3790 if (MODEST_IS_FOLDER_WINDOW (window)) {
3791 folder_view = GTK_WIDGET (modest_folder_window_get_folder_view (MODEST_FOLDER_WINDOW (window)));
3797 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
3802 if (TNY_IS_FOLDER (folder)) {
3803 gchar *folder_name = NULL;
3805 const gchar *current_name;
3806 TnyFolderStore *parent;
3808 current_name = tny_folder_get_name (TNY_FOLDER (folder));
3809 parent = tny_folder_get_folder_store (TNY_FOLDER (folder));
3810 response = modest_platform_run_rename_folder_dialog (GTK_WINDOW (window),
3811 parent, current_name,
3813 g_object_unref (parent);
3815 if (response != GTK_RESPONSE_ACCEPT || strlen (folder_name) == 0) {
3818 RenameFolderInfo *rename_folder_data = g_new0 (RenameFolderInfo, 1);
3819 rename_folder_data->folder = g_object_ref (folder);
3820 rename_folder_data->new_name = folder_name;
3821 modest_platform_connect_if_remote_and_perform (GTK_WINDOW(window), TRUE,
3822 folder, on_rename_folder_performer, rename_folder_data);
3825 g_object_unref (folder);
3830 modest_ui_actions_delete_folder_error_handler (ModestMailOperation *mail_op,
3833 GObject *win = modest_mail_operation_get_source (mail_op);
3835 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
3836 _("mail_in_ui_folder_delete_error"),
3838 g_object_unref (win);
3842 TnyFolderStore *folder;
3843 gboolean move_to_trash;
3847 on_delete_folder_cb (gboolean canceled,
3849 GtkWindow *parent_window,
3850 TnyAccount *account,
3853 DeleteFolderInfo *info = (DeleteFolderInfo*) user_data;
3854 GtkWidget *folder_view;
3855 ModestMailOperation *mail_op;
3856 GtkTreeSelection *sel;
3858 if (!MODEST_IS_WINDOW(parent_window) || canceled || (err!=NULL)) {
3859 /* Note that the connection process can fail due to
3860 memory low conditions as it can not successfully
3861 store the summary */
3862 if (!modest_tny_account_store_check_disk_full_error (modest_runtime_get_account_store(),
3863 (GtkWidget*) parent_window, err,
3865 g_debug ("Error connecting when trying to delete a folder");
3866 g_object_unref (G_OBJECT (info->folder));
3871 #ifndef MODEST_TOOLKIT_HILDON2
3872 if (MODEST_IS_MAIN_WINDOW (parent_window)) {
3873 folder_view = modest_main_window_get_child_widget (
3874 MODEST_MAIN_WINDOW (parent_window),
3875 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3877 if (MODEST_IS_FOLDER_WINDOW (parent_window)) {
3878 folder_view = GTK_WIDGET (modest_folder_window_get_folder_view (MODEST_FOLDER_WINDOW (parent_window)));
3881 g_object_unref (G_OBJECT (info->folder));
3886 /* Unselect the folder before deleting it to free the headers */
3887 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_view));
3888 gtk_tree_selection_unselect_all (sel);
3890 /* Create the mail operation */
3892 modest_mail_operation_new_with_error_handling (G_OBJECT(parent_window),
3893 modest_ui_actions_delete_folder_error_handler,
3896 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
3898 modest_mail_operation_remove_folder (mail_op, TNY_FOLDER (info->folder), info->move_to_trash);
3900 #ifndef MODEST_TOOLKIT_HILDON2
3901 modest_folder_view_select_first_inbox_or_local (MODEST_FOLDER_VIEW (folder_view));
3904 g_object_unref (mail_op);
3905 g_object_unref (info->folder);
3910 delete_folder (ModestWindow *window, gboolean move_to_trash)
3912 TnyFolderStore *folder;
3913 GtkWidget *folder_view;
3917 g_return_val_if_fail (MODEST_IS_WINDOW(window), FALSE);
3919 #ifndef MODEST_TOOLKIT_HILDON2
3920 if (MODEST_IS_MAIN_WINDOW (window)) {
3922 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (window),
3923 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3925 if (MODEST_IS_FOLDER_WINDOW (window)) {
3926 folder_view = GTK_WIDGET (modest_folder_window_get_folder_view (MODEST_FOLDER_WINDOW (window)));
3934 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
3939 /* Show an error if it's an account */
3940 if (!TNY_IS_FOLDER (folder)) {
3941 modest_platform_run_information_dialog (GTK_WINDOW (window),
3942 _("mail_in_ui_folder_delete_error"),
3944 g_object_unref (G_OBJECT (folder));
3949 message = g_strdup_printf (_("mcen_nc_delete_folder_text"),
3950 tny_folder_get_name (TNY_FOLDER (folder)));
3951 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (window),
3952 (const gchar *) message);
3955 if (response == GTK_RESPONSE_OK) {
3956 TnyAccount *account = NULL;
3957 DeleteFolderInfo *info = NULL;
3958 info = g_new0(DeleteFolderInfo, 1);
3959 info->folder = g_object_ref (folder);
3960 info->move_to_trash = move_to_trash;
3962 account = tny_folder_get_account (TNY_FOLDER (folder));
3963 modest_platform_connect_if_remote_and_perform (GTK_WINDOW (window),
3965 TNY_FOLDER_STORE (account),
3966 on_delete_folder_cb, info);
3967 g_object_unref (account);
3968 g_object_unref (folder);
3976 modest_ui_actions_on_delete_folder (GtkAction *action,
3977 ModestWindow *window)
3979 modest_ui_actions_on_edit_mode_delete_folder (window);
3983 modest_ui_actions_on_edit_mode_delete_folder (ModestWindow *window)
3985 g_return_val_if_fail (MODEST_IS_WINDOW(window), TRUE);
3987 return delete_folder (window, FALSE);
3990 #ifndef MODEST_TOOLKIT_HILDON2
3992 modest_ui_actions_on_move_folder_to_trash_folder (GtkAction *action, ModestMainWindow *main_window)
3994 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
3996 delete_folder (MODEST_WINDOW (main_window), TRUE);
4000 typedef struct _PasswordDialogFields {
4001 GtkWidget *username;
4002 GtkWidget *password;
4004 } PasswordDialogFields;
4007 password_dialog_check_field (GtkEditable *editable,
4008 PasswordDialogFields *fields)
4011 gboolean any_value_empty = FALSE;
4013 #ifdef MODEST_TOOLKIT_HILDON2
4014 value = hildon_entry_get_text (HILDON_ENTRY (fields->username));
4016 value = gtk_entry_get_text (GTK_ENTRY (fields->username));
4018 if ((value == NULL) || value[0] == '\0') {
4019 any_value_empty = TRUE;
4021 #ifdef MODEST_TOOLKIT_HILDON2
4022 value = hildon_entry_get_text (HILDON_ENTRY (fields->password));
4024 value = gtk_entry_get_text (GTK_ENTRY (fields->password));
4026 if ((value == NULL) || value[0] == '\0') {
4027 any_value_empty = TRUE;
4029 gtk_dialog_set_response_sensitive (GTK_DIALOG (fields->dialog), GTK_RESPONSE_ACCEPT, !any_value_empty);
4033 modest_ui_actions_on_password_requested (TnyAccountStore *account_store,
4034 const gchar* server_account_name,
4039 ModestMainWindow *main_window)
4041 g_return_if_fail(server_account_name);
4042 gboolean completed = FALSE;
4043 PasswordDialogFields *fields = NULL;
4045 /* Initalize output parameters: */
4052 #ifndef MODEST_TOOLKIT_GTK
4053 /* Maemo uses a different (awkward) button order,
4054 * It should probably just use gtk_alternative_dialog_button_order ().
4056 #ifdef MODEST_TOOLKIT_HILDON2
4058 gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
4061 _HL("wdgt_bd_done"),
4062 GTK_RESPONSE_ACCEPT,
4064 gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox),
4065 HILDON_MARGIN_DOUBLE);
4068 gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
4071 _("mcen_bd_dialog_ok"),
4072 GTK_RESPONSE_ACCEPT,
4073 _("mcen_bd_dialog_cancel"),
4074 GTK_RESPONSE_REJECT,
4076 #endif /* MODEST_TOOLKIT_HILDON2 */
4079 gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
4083 GTK_RESPONSE_REJECT,
4085 GTK_RESPONSE_ACCEPT,
4087 #endif /* MODEST_TOOLKIT_GTK */
4089 modest_window_mgr_set_modal (modest_runtime_get_window_mgr(), GTK_WINDOW (dialog), NULL);
4091 gchar *server_name = modest_account_mgr_get_server_account_hostname (
4092 modest_runtime_get_account_mgr(), server_account_name);
4093 if (!server_name) {/* This happened once, though I don't know why. murrayc. */
4094 g_warning("%s: Could not get server name for server account '%s'", __FUNCTION__, server_account_name);
4097 gtk_widget_destroy (dialog);
4101 gchar *txt = g_strdup_printf (_("mail_ia_password_info"), server_name);
4102 GtkWidget *label = gtk_label_new (txt);
4103 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
4105 g_free (server_name);
4106 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), label,
4111 gchar *initial_username = modest_account_mgr_get_server_account_username (
4112 modest_runtime_get_account_mgr(), server_account_name);
4114 #ifdef MODEST_TOOLKIT_HILDON2
4115 GtkWidget *entry_username = hildon_entry_new (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
4116 if (initial_username)
4117 hildon_entry_set_text (HILDON_ENTRY (entry_username), initial_username);
4119 GtkWidget *entry_username = gtk_entry_new ();
4120 if (initial_username)
4121 gtk_entry_set_text (GTK_ENTRY (entry_username), initial_username);
4123 /* Dim this if a connection has ever succeeded with this username,
4124 * as per the UI spec: */
4125 /* const gboolean username_known = */
4126 /* modest_account_mgr_get_server_account_username_has_succeeded( */
4127 /* modest_runtime_get_account_mgr(), server_account_name); */
4128 /* gtk_widget_set_sensitive (entry_username, !username_known); */
4130 /* We drop the username sensitive code and disallow changing it here
4131 * as tinymail does not support really changing the username in the callback
4133 gtk_widget_set_sensitive (entry_username, FALSE);
4135 #ifndef MODEST_TOOLKIT_GTK
4136 /* Auto-capitalization is the default, so let's turn it off: */
4137 hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_username), HILDON_GTK_INPUT_MODE_FULL);
4139 /* Create a size group to be used by all captions.
4140 * Note that HildonCaption does not create a default size group if we do not specify one.
4141 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
4142 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
4144 #ifdef MODEST_TOOLKIT_HILDON2
4145 GtkWidget *caption = modest_maemo_utils_create_captioned (sizegroup, NULL,
4146 _("mail_fi_username"), FALSE,
4149 GtkWidget *caption = hildon_caption_new (sizegroup,
4150 _("mail_fi_username"), entry_username, NULL, HILDON_CAPTION_MANDATORY);
4152 gtk_widget_show (entry_username);
4153 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
4154 FALSE, FALSE, MODEST_MARGIN_HALF);
4155 gtk_widget_show (caption);
4157 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry_username,
4159 #endif /* !MODEST_TOOLKIT_GTK */
4162 #ifdef MODEST_TOOLKIT_HILDON2
4163 GtkWidget *entry_password = hildon_entry_new (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
4165 GtkWidget *entry_password = gtk_entry_new ();
4167 gtk_entry_set_visibility (GTK_ENTRY(entry_password), FALSE);
4168 /* gtk_entry_set_invisible_char (GTK_ENTRY(entry_password), "*"); */
4170 #ifndef MODEST_TOOLKIT_GTK
4171 /* Auto-capitalization is the default, so let's turn it off: */
4172 hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_password),
4173 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
4175 #ifdef MODEST_TOOLKIT_HILDON2
4176 caption = modest_maemo_utils_create_captioned (sizegroup, NULL,
4177 _("mail_fi_password"), FALSE,
4180 caption = hildon_caption_new (sizegroup,
4181 _("mail_fi_password"), entry_password, NULL, HILDON_CAPTION_MANDATORY);
4183 gtk_widget_show (entry_password);
4184 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
4185 FALSE, FALSE, MODEST_MARGIN_HALF);
4186 gtk_widget_show (caption);
4187 g_object_unref (sizegroup);
4189 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry_password,
4191 #endif /* !MODEST_TOOLKIT_GTK */
4193 if (initial_username != NULL)
4194 gtk_widget_grab_focus (GTK_WIDGET (entry_password));
4196 /* This is not in the Maemo UI spec:
4197 remember_pass_check = gtk_check_button_new_with_label (_("Remember password"));
4198 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), remember_pass_check,
4202 fields = g_slice_new0 (PasswordDialogFields);
4203 fields->username = entry_username;
4204 fields->password = entry_password;
4205 fields->dialog = dialog;
4207 g_signal_connect (entry_username, "changed", G_CALLBACK (password_dialog_check_field), fields);
4208 g_signal_connect (entry_password, "changed", G_CALLBACK (password_dialog_check_field), fields);
4209 password_dialog_check_field (NULL, fields);
4211 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
4213 while (!completed) {
4215 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
4217 #ifdef MODEST_TOOLKIT_HILDON2
4218 *username = g_strdup (hildon_entry_get_text (HILDON_ENTRY(entry_username)));
4220 *username = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_username)));
4223 /* Note that an empty field becomes the "" string */
4224 if (*username && strlen (*username) > 0) {
4225 modest_account_mgr_set_server_account_username (modest_runtime_get_account_mgr(),
4226 server_account_name,
4230 const gboolean username_was_changed =
4231 (strcmp (*username, initial_username) != 0);
4232 if (username_was_changed) {
4233 g_warning ("%s: tinymail does not yet support changing the "
4234 "username in the get_password() callback.\n", __FUNCTION__);
4240 modest_platform_information_banner (GTK_WIDGET (dialog), NULL,
4241 _("mcen_ib_username_pw_incorrect"));
4247 #ifdef MODEST_TOOLKIT_HILDON2
4248 *password = g_strdup (hildon_entry_get_text (HILDON_ENTRY(entry_password)));
4250 *password = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_password)));
4253 /* We do not save the password in the configuration,
4254 * because this function is only called for passwords that should
4255 * not be remembered:
4256 modest_server_account_set_password (
4257 modest_runtime_get_account_mgr(), server_account_name,
4264 #ifndef MODEST_TOOLKIT_HILDON2
4265 /* Set parent to NULL or the banner will disappear with its parent dialog */
4266 modest_platform_information_banner(NULL, NULL, _("mail_ib_login_cancelled"));
4278 /* This is not in the Maemo UI spec:
4279 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (remember_pass_check)))
4285 g_free (initial_username);
4286 gtk_widget_destroy (dialog);
4287 g_slice_free (PasswordDialogFields, fields);
4289 /* printf ("DEBUG: %s: cancel=%d\n", __FUNCTION__, *cancel); */
4293 modest_ui_actions_on_cut (GtkAction *action,
4294 ModestWindow *window)
4296 GtkWidget *focused_widget;
4297 GtkClipboard *clipboard;
4299 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
4300 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
4301 if (GTK_IS_EDITABLE (focused_widget)) {
4302 gtk_editable_cut_clipboard (GTK_EDITABLE(focused_widget));
4303 gtk_clipboard_set_can_store (clipboard, NULL, 0);
4304 gtk_clipboard_store (clipboard);
4305 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
4306 GtkTextBuffer *buffer;
4308 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
4309 if (modest_text_utils_buffer_selection_is_valid (buffer)) {
4310 gtk_text_buffer_cut_clipboard (buffer, clipboard, TRUE);
4311 gtk_clipboard_set_can_store (clipboard, NULL, 0);
4312 gtk_clipboard_store (clipboard);
4314 } else if (MODEST_IS_HEADER_VIEW (focused_widget)) {
4315 TnyList *header_list = modest_header_view_get_selected_headers (
4316 MODEST_HEADER_VIEW (focused_widget));
4317 gboolean continue_download = FALSE;
4318 gint num_of_unc_msgs;
4320 num_of_unc_msgs = header_list_count_uncached_msgs(header_list);
4322 if (num_of_unc_msgs) {
4323 TnyAccount *account = get_account_from_header_list (header_list);
4325 continue_download = connect_to_get_msg (window, num_of_unc_msgs, account);
4326 g_object_unref (account);
4330 if (num_of_unc_msgs == 0 || continue_download) {
4331 /* modest_platform_information_banner (
4332 NULL, NULL, _CS("mcen_ib_getting_items"));*/
4333 modest_header_view_cut_selection (
4334 MODEST_HEADER_VIEW (focused_widget));
4337 g_object_unref (header_list);
4338 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
4339 modest_folder_view_cut_selection (MODEST_FOLDER_VIEW (focused_widget));
4344 modest_ui_actions_on_copy (GtkAction *action,
4345 ModestWindow *window)
4347 GtkClipboard *clipboard;
4348 GtkWidget *focused_widget;
4349 gboolean copied = TRUE;
4351 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
4352 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
4354 if (GTK_IS_LABEL (focused_widget)) {
4356 selection = modest_text_utils_label_get_selection (GTK_LABEL (focused_widget));
4357 gtk_clipboard_set_text (clipboard, selection, -1);
4359 gtk_clipboard_set_can_store (clipboard, NULL, 0);
4360 gtk_clipboard_store (clipboard);
4361 } else if (GTK_IS_EDITABLE (focused_widget)) {
4362 gtk_editable_copy_clipboard (GTK_EDITABLE(focused_widget));
4363 gtk_clipboard_set_can_store (clipboard, NULL, 0);
4364 gtk_clipboard_store (clipboard);
4365 } else if (GTK_IS_HTML (focused_widget)) {
4368 sel = gtk_html_get_selection_html (GTK_HTML (focused_widget), &len);
4369 if ((sel == NULL) || (sel[0] == '\0')) {
4372 gtk_html_copy (GTK_HTML (focused_widget));
4373 gtk_clipboard_set_can_store (clipboard, NULL, 0);
4374 gtk_clipboard_store (clipboard);
4376 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
4377 GtkTextBuffer *buffer;
4378 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
4379 if (modest_text_utils_buffer_selection_is_valid (buffer)) {
4380 gtk_text_buffer_copy_clipboard (buffer, clipboard);
4381 gtk_clipboard_set_can_store (clipboard, NULL, 0);
4382 gtk_clipboard_store (clipboard);
4384 } else if (MODEST_IS_HEADER_VIEW (focused_widget)) {
4385 TnyList *header_list = modest_header_view_get_selected_headers (
4386 MODEST_HEADER_VIEW (focused_widget));
4387 gboolean continue_download = FALSE;
4388 gint num_of_unc_msgs;
4390 num_of_unc_msgs = header_list_count_uncached_msgs(header_list);
4392 if (num_of_unc_msgs) {
4393 TnyAccount *account = get_account_from_header_list (header_list);
4395 continue_download = connect_to_get_msg (window, num_of_unc_msgs, account);
4396 g_object_unref (account);
4400 if (num_of_unc_msgs == 0 || continue_download) {
4401 modest_platform_information_banner (
4402 NULL, NULL, _CS("mcen_ib_getting_items"));
4403 modest_header_view_copy_selection (
4404 MODEST_HEADER_VIEW (focused_widget));
4408 g_object_unref (header_list);
4410 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
4411 modest_folder_view_copy_selection (MODEST_FOLDER_VIEW (focused_widget));
4414 /* Show information banner if there was a copy to clipboard */
4416 modest_platform_information_banner (
4417 NULL, NULL, _CS("ecoc_ib_edwin_copied"));
4421 modest_ui_actions_on_undo (GtkAction *action,
4422 ModestWindow *window)
4424 if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
4425 modest_msg_edit_window_undo (MODEST_MSG_EDIT_WINDOW (window));
4426 #ifndef MODEST_TOOLKIT_HILDON2
4427 } else if (MODEST_IS_MAIN_WINDOW (window)) {
4428 ModestEmailClipboard *clipboard = NULL;
4429 /* Clear clipboard source */
4430 clipboard = modest_runtime_get_email_clipboard ();
4431 modest_email_clipboard_clear (clipboard);
4434 g_return_if_reached ();
4439 modest_ui_actions_on_redo (GtkAction *action,
4440 ModestWindow *window)
4442 if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
4443 modest_msg_edit_window_redo (MODEST_MSG_EDIT_WINDOW (window));
4446 g_return_if_reached ();
4452 destroy_information_note (ModestMailOperation *mail_op,
4455 /* destroy information note */
4456 gtk_widget_destroy (GTK_WIDGET(user_data));
4460 destroy_folder_information_note (ModestMailOperation *mail_op,
4461 TnyFolder *new_folder,
4464 /* destroy information note */
4465 gtk_widget_destroy (GTK_WIDGET(user_data));
4470 paste_as_attachment_free (gpointer data)
4472 PasteAsAttachmentHelper *helper = (PasteAsAttachmentHelper *) data;
4474 if (helper->banner) {
4475 gtk_widget_destroy (helper->banner);
4476 g_object_unref (helper->banner);
4482 paste_msg_as_attachment_cb (ModestMailOperation *mail_op,
4487 PasteAsAttachmentHelper *helper = (PasteAsAttachmentHelper *) userdata;
4488 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (helper->window));
4493 modest_msg_edit_window_add_part (MODEST_MSG_EDIT_WINDOW (helper->window), TNY_MIME_PART (msg));
4498 modest_ui_actions_on_paste (GtkAction *action,
4499 ModestWindow *window)
4501 GtkWidget *focused_widget = NULL;
4502 GtkWidget *inf_note = NULL;
4503 ModestMailOperation *mail_op = NULL;
4505 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
4506 if (GTK_IS_EDITABLE (focused_widget)) {
4507 gtk_editable_paste_clipboard (GTK_EDITABLE(focused_widget));
4508 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
4509 ModestEmailClipboard *e_clipboard = NULL;
4510 e_clipboard = modest_runtime_get_email_clipboard ();
4511 if (modest_email_clipboard_cleared (e_clipboard)) {
4512 GtkTextBuffer *buffer;
4513 GtkClipboard *clipboard;
4515 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
4516 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
4517 gtk_text_buffer_paste_clipboard (buffer, clipboard, NULL, TRUE);
4518 } else if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
4519 ModestMailOperation *mail_op;
4520 TnyFolder *src_folder = NULL;
4521 TnyList *data = NULL;
4523 PasteAsAttachmentHelper *helper = g_new0 (PasteAsAttachmentHelper, 1);
4524 helper->window = MODEST_MSG_EDIT_WINDOW (window);
4525 helper->banner = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
4526 _CS("ckct_nw_pasting"));
4527 modest_email_clipboard_get_data (e_clipboard, &src_folder, &data, &delete);
4528 mail_op = modest_mail_operation_new (G_OBJECT (window));
4529 if (helper->banner != NULL) {
4530 g_object_ref (G_OBJECT (helper->banner));
4531 gtk_widget_show (GTK_WIDGET (helper->banner));
4535 modest_mail_operation_get_msgs_full (mail_op,
4537 (GetMsgAsyncUserCallback) paste_msg_as_attachment_cb,
4539 paste_as_attachment_free);
4543 g_object_unref (data);
4545 g_object_unref (src_folder);
4548 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
4549 ModestEmailClipboard *clipboard = NULL;
4550 TnyFolder *src_folder = NULL;
4551 TnyFolderStore *folder_store = NULL;
4552 TnyList *data = NULL;
4553 gboolean delete = FALSE;
4555 /* Check clipboard source */
4556 clipboard = modest_runtime_get_email_clipboard ();
4557 if (modest_email_clipboard_cleared (clipboard))
4560 /* Get elements to paste */
4561 modest_email_clipboard_get_data (clipboard, &src_folder, &data, &delete);
4563 /* Create a new mail operation */
4564 mail_op = modest_mail_operation_new (G_OBJECT(window));
4566 /* Get destination folder */
4567 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (focused_widget));
4569 /* transfer messages */
4573 /* Ask for user confirmation */
4575 modest_ui_actions_msgs_move_to_confirmation (window,
4576 TNY_FOLDER (folder_store),
4580 if (response == GTK_RESPONSE_OK) {
4581 /* Launch notification */
4582 inf_note = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
4583 _CS("ckct_nw_pasting"));
4584 if (inf_note != NULL) {
4585 gtk_window_set_modal (GTK_WINDOW(inf_note), FALSE);
4586 gtk_widget_show (GTK_WIDGET(inf_note));
4589 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
4590 modest_mail_operation_xfer_msgs (mail_op,
4592 TNY_FOLDER (folder_store),
4594 destroy_information_note,
4597 g_object_unref (mail_op);
4600 } else if (src_folder != NULL) {
4601 /* Launch notification */
4602 inf_note = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
4603 _CS("ckct_nw_pasting"));
4604 if (inf_note != NULL) {
4605 gtk_window_set_modal (GTK_WINDOW(inf_note), FALSE);
4606 gtk_widget_show (GTK_WIDGET(inf_note));
4609 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
4610 modest_mail_operation_xfer_folder (mail_op,
4614 destroy_folder_information_note,
4620 g_object_unref (data);
4621 if (src_folder != NULL)
4622 g_object_unref (src_folder);
4623 if (folder_store != NULL)
4624 g_object_unref (folder_store);
4630 modest_ui_actions_on_select_all (GtkAction *action,
4631 ModestWindow *window)
4633 GtkWidget *focused_widget;
4635 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
4636 if (MODEST_IS_ATTACHMENTS_VIEW (focused_widget)) {
4637 modest_attachments_view_select_all (MODEST_ATTACHMENTS_VIEW (focused_widget));
4638 } else if (GTK_IS_LABEL (focused_widget)) {
4639 gtk_label_select_region (GTK_LABEL (focused_widget), 0, -1);
4640 } else if (GTK_IS_EDITABLE (focused_widget)) {
4641 gtk_editable_select_region (GTK_EDITABLE(focused_widget), 0, -1);
4642 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
4643 GtkTextBuffer *buffer;
4644 GtkTextIter start, end;
4646 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
4647 gtk_text_buffer_get_start_iter (buffer, &start);
4648 gtk_text_buffer_get_end_iter (buffer, &end);
4649 gtk_text_buffer_select_range (buffer, &start, &end);
4650 } else if (GTK_IS_HTML (focused_widget)) {
4651 gtk_html_select_all (GTK_HTML (focused_widget));
4652 #ifndef MODEST_TOOLKIT_HILDON2
4653 } else if (MODEST_IS_MAIN_WINDOW (window)) {
4654 GtkWidget *header_view = focused_widget;
4655 GtkTreeSelection *selection = NULL;
4657 if (!(MODEST_IS_HEADER_VIEW (focused_widget))) {
4658 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (window),
4659 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
4662 /* Disable window dimming management */
4663 modest_window_disable_dimming (MODEST_WINDOW(window));
4665 /* Select all messages */
4666 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(header_view));
4667 gtk_tree_selection_select_all (selection);
4669 /* Set focuse on header view */
4670 gtk_widget_grab_focus (header_view);
4672 /* Enable window dimming management */
4673 modest_window_enable_dimming (MODEST_WINDOW(window));
4674 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (window));
4675 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (window));
4682 modest_ui_actions_on_mark_as_read (GtkAction *action,
4683 ModestWindow *window)
4685 g_return_if_fail (MODEST_IS_WINDOW(window));
4687 /* Mark each header as read */
4688 do_headers_action (window, headers_action_mark_as_read, NULL);
4692 modest_ui_actions_on_mark_as_unread (GtkAction *action,
4693 ModestWindow *window)
4695 g_return_if_fail (MODEST_IS_WINDOW(window));
4697 /* Mark each header as read */
4698 do_headers_action (window, headers_action_mark_as_unread, NULL);
4702 modest_ui_actions_on_change_zoom (GtkRadioAction *action,
4703 GtkRadioAction *selected,
4704 ModestWindow *window)
4708 value = gtk_radio_action_get_current_value (selected);
4709 if (MODEST_IS_WINDOW (window)) {
4710 modest_window_set_zoom (MODEST_WINDOW (window), ((gdouble)value)/100);
4715 modest_ui_actions_msg_edit_on_change_priority (GtkRadioAction *action,
4716 GtkRadioAction *selected,
4717 ModestWindow *window)
4719 TnyHeaderFlags flags;
4720 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4722 flags = gtk_radio_action_get_current_value (selected);
4723 modest_msg_edit_window_set_priority_flags (MODEST_MSG_EDIT_WINDOW (window), flags);
4727 modest_ui_actions_msg_edit_on_change_file_format (GtkRadioAction *action,
4728 GtkRadioAction *selected,
4729 ModestWindow *window)
4733 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4735 file_format = gtk_radio_action_get_current_value (selected);
4736 modest_msg_edit_window_set_file_format (MODEST_MSG_EDIT_WINDOW (window), file_format);
4741 modest_ui_actions_on_zoom_plus (GtkAction *action,
4742 ModestWindow *window)
4744 g_return_if_fail (MODEST_IS_WINDOW (window));
4746 modest_window_zoom_plus (MODEST_WINDOW (window));
4750 modest_ui_actions_on_zoom_minus (GtkAction *action,
4751 ModestWindow *window)
4753 g_return_if_fail (MODEST_IS_WINDOW (window));
4755 modest_window_zoom_minus (MODEST_WINDOW (window));
4759 modest_ui_actions_on_toggle_fullscreen (GtkToggleAction *toggle,
4760 ModestWindow *window)
4762 ModestWindowMgr *mgr;
4763 gboolean fullscreen, active;
4764 g_return_if_fail (MODEST_IS_WINDOW (window));
4766 mgr = modest_runtime_get_window_mgr ();
4768 active = (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle)))?1:0;
4769 fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
4771 if (active != fullscreen) {
4772 modest_window_mgr_set_fullscreen_mode (mgr, active);
4773 #ifndef MODEST_TOOLKIT_HILDON2
4774 gtk_window_present (GTK_WINDOW (window));
4780 modest_ui_actions_on_change_fullscreen (GtkAction *action,
4781 ModestWindow *window)
4783 ModestWindowMgr *mgr;
4784 gboolean fullscreen;
4786 g_return_if_fail (MODEST_IS_WINDOW (window));
4788 mgr = modest_runtime_get_window_mgr ();
4789 fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
4790 modest_window_mgr_set_fullscreen_mode (mgr, !fullscreen);
4792 #ifndef MODEST_TOOLKIT_HILDON2
4793 gtk_window_present (GTK_WINDOW (window));
4798 * Used by modest_ui_actions_on_details to call do_headers_action
4801 headers_action_show_details (TnyHeader *header,
4802 ModestWindow *window,
4806 gboolean async_retrieval;
4809 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
4810 async_retrieval = TRUE;
4811 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW (window));
4813 async_retrieval = FALSE;
4815 modest_platform_run_header_details_dialog (GTK_WINDOW (window), header, async_retrieval, msg);
4817 g_object_unref (msg);
4821 * Show the header details in a ModestDetailsDialog widget
4824 modest_ui_actions_on_details (GtkAction *action,
4827 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
4831 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW (win));
4835 header = tny_msg_get_header (msg);
4837 headers_action_show_details (header, win, NULL);
4838 g_object_unref (header);
4840 g_object_unref (msg);
4841 #ifndef MODEST_TOOLKIT_HILDON2
4842 } else if (MODEST_IS_MAIN_WINDOW (win)) {
4843 GtkWidget *folder_view, *header_view;
4845 /* Check which widget has the focus */
4846 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
4847 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
4848 if (gtk_widget_is_focus (folder_view)) {
4849 TnyFolderStore *folder_store
4850 = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
4851 if (!folder_store) {
4852 g_warning ("%s: No item was selected.\n", __FUNCTION__);
4855 /* Show only when it's a folder */
4856 /* This function should not be called for account items,
4857 * because we dim the menu item for them. */
4858 if (TNY_IS_FOLDER (folder_store)) {
4859 modest_platform_run_folder_details_dialog (GTK_WINDOW (win),
4860 TNY_FOLDER (folder_store));
4863 g_object_unref (folder_store);
4866 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
4867 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
4868 /* Show details of each header */
4869 do_headers_action (win, headers_action_show_details, header_view);
4872 } else if (MODEST_IS_HEADER_WINDOW (win)) {
4874 GtkWidget *header_view;
4876 header_view = GTK_WIDGET (modest_header_window_get_header_view (MODEST_HEADER_WINDOW (win)));
4877 folder = modest_header_view_get_folder (MODEST_HEADER_VIEW (header_view));
4879 modest_platform_run_folder_details_dialog (GTK_WINDOW (win),
4881 g_object_unref (folder);
4888 modest_ui_actions_on_limit_error (GtkAction *action,
4891 g_return_if_fail (MODEST_IS_MSG_VIEW_WINDOW (win));
4893 modest_platform_information_banner ((GtkWidget *) win, NULL, _CS("ckdg_ib_maximum_characters_reached"));
4898 modest_ui_actions_on_toggle_show_cc (GtkToggleAction *toggle,
4899 ModestMsgEditWindow *window)
4901 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4903 modest_msg_edit_window_show_cc (window, gtk_toggle_action_get_active (toggle));
4907 modest_ui_actions_on_toggle_show_bcc (GtkToggleAction *toggle,
4908 ModestMsgEditWindow *window)
4910 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4912 modest_msg_edit_window_show_bcc (window, gtk_toggle_action_get_active (toggle));
4915 #ifndef MODEST_TOOLKIT_HILDON2
4917 modest_ui_actions_toggle_folders_view (GtkAction *action,
4918 ModestMainWindow *main_window)
4920 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
4922 if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)))
4923 modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SPLIT);
4925 modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SIMPLE);
4930 modest_ui_actions_on_toggle_toolbar (GtkToggleAction *toggle,
4931 ModestWindow *window)
4933 gboolean active, fullscreen = FALSE;
4934 ModestWindowMgr *mgr;
4936 active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle));
4938 /* Check if we want to toggle the toolbar view in fullscreen
4940 if (!strcmp (gtk_action_get_name (GTK_ACTION (toggle)),
4941 "ViewShowToolbarFullScreen")) {
4945 /* Toggle toolbar */
4946 mgr = modest_runtime_get_window_mgr ();
4947 modest_window_mgr_show_toolbars (mgr, G_TYPE_FROM_INSTANCE (window), active, fullscreen);
4951 modest_ui_actions_msg_edit_on_select_font (GtkAction *action,
4952 ModestMsgEditWindow *window)
4954 modest_msg_edit_window_select_font (window);
4959 modest_ui_actions_on_folder_display_name_changed (ModestFolderView *folder_view,
4960 const gchar *display_name,
4963 /* don't update the display name if it was already set;
4964 * updating the display name apparently is expensive */
4965 const gchar* old_name = gtk_window_get_title (window);
4967 if (display_name == NULL)
4970 if (old_name && display_name && strcmp (old_name, display_name) == 0)
4971 return; /* don't do anything */
4973 /* This is usually used to change the title of the main window, which
4974 * is the one that holds the folder view. Note that this change can
4975 * happen even when the widget doesn't have the focus. */
4976 gtk_window_set_title (window, display_name);
4981 modest_ui_actions_on_select_contacts (GtkAction *action, ModestMsgEditWindow *window)
4983 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4984 modest_msg_edit_window_select_contacts (window);
4988 modest_ui_actions_on_check_names (GtkAction *action, ModestMsgEditWindow *window)
4990 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4991 modest_msg_edit_window_check_names (window, FALSE);
4994 #ifndef MODEST_TOOLKIT_HILDON2
4996 * This function is used to track changes in the selection of the
4997 * folder view that is inside the "move to" dialog to enable/disable
4998 * the OK button because we do not want the user to select a disallowed
4999 * destination for a folder.
5000 * The user also not desired to be able to use NEW button on items where
5001 * folder creation is not possibel.
5004 on_move_to_dialog_folder_selection_changed (ModestFolderView* self,
5005 TnyFolderStore *folder_store,
5009 GtkWidget *dialog = NULL;
5010 gboolean ok_sensitive = TRUE, new_sensitive = TRUE;
5011 gboolean moving_folder = FALSE;
5012 gboolean is_local_account = TRUE;
5013 GtkWidget *folder_view = NULL;
5014 ModestTnyFolderRules rules;
5016 g_return_if_fail (MODEST_IS_FOLDER_VIEW(self));
5021 dialog = gtk_widget_get_ancestor (GTK_WIDGET (self), GTK_TYPE_DIALOG);
5025 /* check if folder_store is an remote account */
5026 if (TNY_IS_ACCOUNT (folder_store)) {
5027 TnyAccount *local_account = NULL;
5028 TnyAccount *mmc_account = NULL;
5029 ModestTnyAccountStore *account_store = NULL;
5031 account_store = modest_runtime_get_account_store ();
5032 local_account = modest_tny_account_store_get_local_folders_account (account_store);
5033 mmc_account = modest_tny_account_store_get_mmc_folders_account (account_store);
5035 if ((gpointer) local_account != (gpointer) folder_store &&
5036 (gpointer) mmc_account != (gpointer) folder_store) {
5037 ModestProtocolType proto;
5038 proto = modest_tny_account_get_protocol_type (TNY_ACCOUNT (folder_store));
5039 if (proto == MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
5040 proto = MODEST_PROTOCOLS_STORE_MAILDIR;
5042 is_local_account = FALSE;
5043 /* New button should be dimmed on remote
5045 new_sensitive = (modest_protocol_registry_protocol_type_has_tag (modest_runtime_get_protocol_registry (),
5047 MODEST_PROTOCOL_REGISTRY_STORE_HAS_FOLDERS));
5049 g_object_unref (local_account);
5051 /* It could not exist */
5053 g_object_unref (mmc_account);
5056 /* Check the target folder rules */
5057 if (TNY_IS_FOLDER (folder_store)) {
5058 rules = modest_tny_folder_get_rules (TNY_FOLDER (folder_store));
5059 if (rules & MODEST_FOLDER_RULES_FOLDER_NON_WRITEABLE) {
5060 ok_sensitive = FALSE;
5061 new_sensitive = FALSE;
5066 /* Check if we're moving a folder */
5067 if (MODEST_IS_MAIN_WINDOW (user_data)) {
5068 /* Get the widgets */
5069 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (user_data),
5070 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
5071 if (gtk_widget_is_focus (folder_view))
5072 moving_folder = TRUE;
5075 if (moving_folder) {
5076 TnyFolderStore *moved_folder = NULL, *parent = NULL;
5078 /* Get the folder to move */
5079 moved_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
5081 /* Check that we're not moving to the same folder */
5082 if (TNY_IS_FOLDER (moved_folder)) {
5083 parent = tny_folder_get_folder_store (TNY_FOLDER (moved_folder));
5084 if (parent == folder_store)
5085 ok_sensitive = FALSE;
5086 g_object_unref (parent);
5089 if (ok_sensitive && TNY_IS_ACCOUNT (folder_store)) {
5090 /* Do not allow to move to an account unless it's the
5091 local folders account */
5092 if (!is_local_account)
5093 ok_sensitive = FALSE;
5096 if (ok_sensitive && (moved_folder == folder_store)) {
5097 /* Do not allow to move to itself */
5098 ok_sensitive = FALSE;
5100 g_object_unref (moved_folder);
5102 TnyFolder *src_folder = NULL;
5104 /* Moving a message */
5105 if (MODEST_IS_MSG_VIEW_WINDOW (user_data)) {
5107 TnyHeader *header = NULL;
5108 header = modest_msg_view_window_get_header
5109 (MODEST_MSG_VIEW_WINDOW (user_data));
5110 if (!TNY_IS_HEADER(header))
5111 g_warning ("%s: could not get source header", __FUNCTION__);
5113 src_folder = tny_header_get_folder (header);
5116 g_object_unref (header);
5119 TNY_FOLDER (modest_folder_view_get_selected
5120 (MODEST_FOLDER_VIEW (folder_view)));
5123 if (TNY_IS_FOLDER(src_folder)) {
5124 /* Do not allow to move the msg to the same folder */
5125 /* Do not allow to move the msg to an account */
5126 if ((gpointer) src_folder == (gpointer) folder_store ||
5127 TNY_IS_ACCOUNT (folder_store))
5128 ok_sensitive = FALSE;
5129 g_object_unref (src_folder);
5131 g_warning ("%s: could not get source folder", __FUNCTION__);
5135 /* Set sensitivity of the OK and NEW button */
5136 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, ok_sensitive);
5137 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), MODEST_GTK_RESPONSE_NEW_FOLDER, new_sensitive);
5142 on_move_to_dialog_response (GtkDialog *dialog,
5146 GtkWidget *parent_win;
5147 MoveToInfo *helper = NULL;
5148 ModestFolderView *folder_view;
5149 gboolean unset_edit_mode = FALSE;
5151 helper = (MoveToInfo *) user_data;
5153 parent_win = (GtkWidget *) helper->win;
5154 folder_view = MODEST_FOLDER_VIEW (g_object_get_data (G_OBJECT (dialog),
5155 MODEST_MOVE_TO_DIALOG_FOLDER_VIEW));
5157 TnyFolderStore *dst_folder;
5158 TnyFolderStore *selected;
5160 case MODEST_GTK_RESPONSE_NEW_FOLDER:
5161 selected = modest_folder_view_get_selected (folder_view);
5162 modest_ui_actions_create_folder (GTK_WIDGET (dialog), GTK_WIDGET (folder_view), selected);
5163 g_object_unref (selected);
5165 case GTK_RESPONSE_NONE:
5166 case GTK_RESPONSE_CANCEL:
5167 case GTK_RESPONSE_DELETE_EVENT:
5169 case GTK_RESPONSE_OK:
5170 dst_folder = modest_folder_view_get_selected (folder_view);
5172 #ifndef MODEST_TOOLKIT_HILDON2
5173 if (MODEST_IS_MAIN_WINDOW (parent_win)) {
5174 /* Clean list to move used for filtering */
5175 modest_folder_view_set_list_to_move (folder_view, NULL);
5177 modest_ui_actions_on_main_window_move_to (NULL,
5178 GTK_WIDGET (folder_view),
5180 MODEST_MAIN_WINDOW (parent_win));
5182 if (MODEST_IS_FOLDER_WINDOW (parent_win)) {
5183 /* Clean list to move used for filtering */
5184 modest_folder_view_set_list_to_move (folder_view, NULL);
5186 modest_ui_actions_on_folder_window_move_to (GTK_WIDGET (folder_view),
5189 GTK_WINDOW (parent_win));
5192 /* if the user selected a root folder
5193 (account) then do not perform any action */
5194 if (TNY_IS_ACCOUNT (dst_folder)) {
5195 g_signal_stop_emission_by_name (dialog, "response");
5199 /* Clean list to move used for filtering */
5200 modest_folder_view_set_list_to_move (folder_view, NULL);
5202 /* Moving from headers window in edit mode */
5203 modest_ui_actions_on_window_move_to (NULL, helper->list,
5205 MODEST_WINDOW (parent_win));
5209 g_object_unref (dst_folder);
5211 unset_edit_mode = TRUE;
5214 g_warning ("%s unexpected response id %d", __FUNCTION__, response);
5217 /* Free the helper and exit */
5219 g_object_unref (helper->list);
5220 if (unset_edit_mode) {
5221 #ifdef MODEST_TOOLKIT_HILDON2
5222 modest_hildon2_window_unset_edit_mode (MODEST_HILDON2_WINDOW (helper->win));
5225 g_slice_free (MoveToInfo, helper);
5226 gtk_widget_destroy (GTK_WIDGET (dialog));
5230 create_move_to_dialog (GtkWindow *win,
5231 GtkWidget *folder_view,
5232 TnyList *list_to_move)
5234 GtkWidget *dialog, *tree_view = NULL;
5236 dialog = modest_platform_create_move_to_dialog (win, &tree_view);
5238 #ifndef MODEST_TOOLKIT_HILDON2
5239 /* Track changes in the selection to
5240 * disable the OK button whenever "Move to" is not possible
5241 * disbale NEW button whenever New is not possible */
5242 g_signal_connect (tree_view,
5243 "folder_selection_changed",
5244 G_CALLBACK (on_move_to_dialog_folder_selection_changed),
5248 /* It could happen that we're trying to move a message from a
5249 window (msg window for example) after the main window was
5250 closed, so we can not just get the model of the folder
5252 if (MODEST_IS_FOLDER_VIEW (folder_view)) {
5253 const gchar *visible_id = NULL;
5255 modest_folder_view_set_style (MODEST_FOLDER_VIEW (tree_view),
5256 MODEST_FOLDER_VIEW_STYLE_SHOW_ALL);
5257 modest_folder_view_copy_model (MODEST_FOLDER_VIEW(folder_view),
5258 MODEST_FOLDER_VIEW(tree_view));
5261 modest_folder_view_get_account_id_of_visible_server_account (MODEST_FOLDER_VIEW(folder_view));
5263 /* Show the same account than the one that is shown in the main window */
5264 modest_folder_view_set_account_id_of_visible_server_account (MODEST_FOLDER_VIEW(tree_view),
5267 const gchar *active_account_name = NULL;
5268 ModestAccountMgr *mgr = NULL;
5269 ModestAccountSettings *settings = NULL;
5270 ModestServerAccountSettings *store_settings = NULL;
5272 modest_folder_view_set_style (MODEST_FOLDER_VIEW (tree_view),
5273 MODEST_FOLDER_VIEW_STYLE_SHOW_ALL);
5274 /* modest_folder_view_update_model (MODEST_FOLDER_VIEW (tree_view), */
5275 /* TNY_ACCOUNT_STORE (modest_runtime_get_account_store ())); */
5277 active_account_name = modest_window_get_active_account (MODEST_WINDOW (win));
5278 mgr = modest_runtime_get_account_mgr ();
5279 settings = modest_account_mgr_load_account_settings (mgr, active_account_name);
5282 const gchar *store_account_name;
5283 store_settings = modest_account_settings_get_store_settings (settings);
5284 store_account_name = modest_server_account_settings_get_account_name (store_settings);
5286 modest_folder_view_set_account_id_of_visible_server_account (MODEST_FOLDER_VIEW (tree_view),
5287 store_account_name);
5288 g_object_unref (store_settings);
5289 g_object_unref (settings);
5293 /* we keep a pointer to the embedded folder view, so we can
5294 * retrieve it with get_folder_view_from_move_to_dialog (see
5295 * above) later (needed for focus handling)
5297 g_object_set_data (G_OBJECT(dialog), MODEST_MOVE_TO_DIALOG_FOLDER_VIEW, tree_view);
5299 /* Hide special folders */
5300 #ifndef MODEST_TOOLKIT_HILDON2
5301 modest_folder_view_show_non_move_folders (MODEST_FOLDER_VIEW (tree_view), FALSE);
5304 modest_folder_view_set_list_to_move (MODEST_FOLDER_VIEW (tree_view), list_to_move);
5305 #ifndef MODEST_TOOLKIT_HILDON2
5306 modest_folder_view_select_first_inbox_or_local (MODEST_FOLDER_VIEW (tree_view));
5309 gtk_widget_show (GTK_WIDGET (tree_view));
5315 * Shows a confirmation dialog to the user when we're moving messages
5316 * from a remote server to the local storage. Returns the dialog
5317 * response. If it's other kind of movement then it always returns
5320 * This one is used by the next functions:
5321 * modest_ui_actions_on_paste - commented out
5322 * drag_and_drop_from_header_view (for d&d in modest_folder_view.c)
5325 modest_ui_actions_msgs_move_to_confirmation (ModestWindow *win,
5326 TnyFolder *dest_folder,
5330 gint response = GTK_RESPONSE_OK;
5331 TnyAccount *account = NULL;
5332 TnyFolder *src_folder = NULL;
5333 TnyIterator *iter = NULL;
5334 TnyHeader *header = NULL;
5336 /* return with OK if the destination is a remote folder */
5337 if (modest_tny_folder_is_remote_folder (dest_folder))
5338 return GTK_RESPONSE_OK;
5340 /* Get source folder */
5341 iter = tny_list_create_iterator (headers);
5342 header = TNY_HEADER (tny_iterator_get_current (iter));
5344 src_folder = tny_header_get_folder (header);
5345 g_object_unref (header);
5347 g_object_unref (iter);
5349 /* if no src_folder, message may be an attahcment */
5350 if (src_folder == NULL)
5351 return GTK_RESPONSE_CANCEL;
5353 /* If the source is a local or MMC folder */
5354 if (!modest_tny_folder_is_remote_folder (src_folder)) {
5355 g_object_unref (src_folder);
5356 return GTK_RESPONSE_OK;
5359 /* Get the account */
5360 account = tny_folder_get_account (src_folder);
5362 /* now if offline we ask the user */
5363 if(connect_to_get_msg (win, tny_list_get_length (headers), account))
5364 response = GTK_RESPONSE_OK;
5366 response = GTK_RESPONSE_CANCEL;
5369 g_object_unref (src_folder);
5370 g_object_unref (account);
5376 move_to_helper_destroyer (gpointer user_data)
5378 MoveToHelper *helper = (MoveToHelper *) user_data;
5380 /* Close the "Pasting" information banner */
5381 if (helper->banner) {
5382 gtk_widget_destroy (GTK_WIDGET (helper->banner));
5383 g_object_unref (helper->banner);
5385 if (gtk_tree_row_reference_valid (helper->reference)) {
5386 gtk_tree_row_reference_free (helper->reference);
5387 helper->reference = NULL;
5393 move_to_cb (ModestMailOperation *mail_op,
5396 MoveToHelper *helper = (MoveToHelper *) user_data;
5397 GObject *object = modest_mail_operation_get_source (mail_op);
5399 /* Note that the operation could have failed, in that case do
5401 if (modest_mail_operation_get_status (mail_op) !=
5402 MODEST_MAIL_OPERATION_STATUS_SUCCESS)
5405 if (MODEST_IS_MSG_VIEW_WINDOW (object)) {
5406 ModestMsgViewWindow *self = MODEST_MSG_VIEW_WINDOW (object);
5408 if (!modest_msg_view_window_select_next_message (self) &&
5409 !modest_msg_view_window_select_previous_message (self)) {
5410 /* No more messages to view, so close this window */
5411 modest_ui_actions_on_close_window (NULL, MODEST_WINDOW(self));
5413 #ifndef MODEST_TOOLKIT_HILDON2
5414 } else if (MODEST_IS_MAIN_WINDOW (object) &&
5415 gtk_tree_row_reference_valid (helper->reference)) {
5416 GtkWidget *header_view;
5418 GtkTreeSelection *sel;
5420 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(object),
5421 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
5422 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
5423 path = gtk_tree_row_reference_get_path (helper->reference);
5424 /* We need to unselect the previous one
5425 because we could be copying instead of
5427 gtk_tree_selection_unselect_all (sel);
5428 gtk_tree_selection_select_path (sel, path);
5429 gtk_tree_path_free (path);
5432 g_object_unref (object);
5435 /* Destroy the helper */
5436 move_to_helper_destroyer (helper);
5440 folder_move_to_cb (ModestMailOperation *mail_op,
5441 TnyFolder *new_folder,
5446 object = modest_mail_operation_get_source (mail_op);
5447 #ifndef MODEST_TOOLKIT_HILDON2
5448 if (MODEST_IS_MAIN_WINDOW (object)) {
5449 GtkWidget *folder_view;
5450 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(object),
5451 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
5452 g_object_ref (folder_view);
5453 g_object_unref (object);
5454 move_to_cb (mail_op, user_data);
5455 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view), new_folder, FALSE);
5456 g_object_unref (folder_view);
5461 move_to_cb (mail_op, user_data);
5466 msgs_move_to_cb (ModestMailOperation *mail_op,
5469 move_to_cb (mail_op, user_data);
5473 modest_ui_actions_move_folder_error_handler (ModestMailOperation *mail_op,
5476 GObject *win = NULL;
5477 const GError *error;
5478 TnyAccount *account = NULL;
5480 #ifndef MODEST_TOOLKIT_HILDON2
5481 ModestWindow *main_window = NULL;
5483 /* Disable next automatic folder selection */
5484 main_window = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (),
5485 FALSE); /* don't create */
5487 /* Show notification dialog only if the main window exists */
5489 GtkWidget *folder_view = NULL;
5491 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (main_window),
5492 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
5493 modest_folder_view_disable_next_folder_selection (MODEST_FOLDER_VIEW(folder_view));
5495 if (user_data && TNY_IS_FOLDER (user_data)) {
5496 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view),
5497 TNY_FOLDER (user_data), FALSE);
5501 win = modest_mail_operation_get_source (mail_op);
5502 error = modest_mail_operation_get_error (mail_op);
5504 if (TNY_IS_FOLDER (user_data))
5505 account = modest_tny_folder_get_account (TNY_FOLDER (user_data));
5506 else if (TNY_IS_ACCOUNT (user_data))
5507 account = g_object_ref (user_data);
5509 /* If it's not a disk full error then show a generic error */
5510 if (!modest_tny_account_store_check_disk_full_error (modest_runtime_get_account_store(),
5511 (GtkWidget *) win, (GError *) error,
5513 modest_platform_run_information_dialog ((GtkWindow *) win,
5514 _("mail_in_ui_folder_move_target_error"),
5517 g_object_unref (account);
5519 g_object_unref (win);
5522 #ifndef MODEST_TOOLKIT_HILDON2
5524 open_msg_for_purge_cb (ModestMailOperation *mail_op,
5533 gint pending_purges = 0;
5534 gboolean some_purged = FALSE;
5535 ModestWindow *win = MODEST_WINDOW (user_data);
5536 ModestWindowMgr *mgr = modest_runtime_get_window_mgr ();
5538 /* If there was any error */
5539 if (!modest_ui_actions_msg_retrieval_check (mail_op, header, msg)) {
5540 modest_window_mgr_unregister_header (mgr, header);
5544 /* Once the message has been retrieved for purging, we check if
5545 * it's all ok for purging */
5547 parts = tny_simple_list_new ();
5548 tny_mime_part_get_parts (TNY_MIME_PART (msg), parts);
5549 iter = tny_list_create_iterator (parts);
5551 while (!tny_iterator_is_done (iter)) {
5553 part = TNY_MIME_PART (tny_iterator_get_current (iter));
5554 if (part && (tny_mime_part_is_attachment (part) || TNY_IS_MSG (part))) {
5555 if (tny_mime_part_is_purged (part))
5562 g_object_unref (part);
5564 tny_iterator_next (iter);
5566 g_object_unref (iter);
5569 if (pending_purges>0) {
5571 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),_("mcen_nc_purge_file_text_inbox"));
5573 if (response == GTK_RESPONSE_OK) {
5576 modest_platform_animation_banner (GTK_WIDGET (win), NULL, _("mcen_me_inbox_remove_attachments"));
5577 iter = tny_list_create_iterator (parts);
5578 while (!tny_iterator_is_done (iter)) {
5581 part = TNY_MIME_PART (tny_iterator_get_current (iter));
5582 if (part && (tny_mime_part_is_attachment (part) || TNY_IS_MSG (part)))
5583 tny_mime_part_set_purged (part);
5586 g_object_unref (part);
5588 tny_iterator_next (iter);
5590 g_object_unref (iter);
5592 tny_msg_rewrite_cache (msg);
5594 gtk_widget_destroy (info);
5598 modest_window_mgr_unregister_header (mgr, header);
5600 g_object_unref (parts);
5604 modest_ui_actions_on_main_window_remove_attachments (GtkAction *action,
5605 ModestMainWindow *win)
5607 GtkWidget *header_view;
5608 TnyList *header_list;
5610 TnyHeaderFlags flags;
5611 ModestWindow *msg_view_window = NULL;
5614 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win));
5616 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
5617 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
5619 header_list = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW (header_view));
5621 g_warning ("%s: no header selected", __FUNCTION__);
5625 if (tny_list_get_length (header_list) == 1) {
5626 TnyIterator *iter = tny_list_create_iterator (header_list);
5627 header = TNY_HEADER (tny_iterator_get_current (iter));
5628 g_object_unref (iter);
5632 if (!header || !TNY_IS_HEADER(header)) {
5633 g_warning ("%s: header is not valid", __FUNCTION__);
5637 found = modest_window_mgr_find_registered_header (modest_runtime_get_window_mgr (),
5638 header, &msg_view_window);
5639 flags = tny_header_get_flags (header);
5640 if (!(flags & TNY_HEADER_FLAG_CACHED))
5643 if (msg_view_window != NULL)
5644 modest_msg_view_window_remove_attachments (MODEST_MSG_VIEW_WINDOW (msg_view_window), TRUE);
5646 /* do nothing; uid was registered before, so window is probably on it's way */
5647 g_debug ("header %p has already been registered", header);
5650 ModestMailOperation *mail_op = NULL;
5651 modest_window_mgr_register_header (modest_runtime_get_window_mgr (), header, NULL);
5652 mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT (win),
5653 modest_ui_actions_disk_operations_error_handler,
5655 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
5656 modest_mail_operation_get_msg (mail_op, header, FALSE, open_msg_for_purge_cb, win);
5658 g_object_unref (mail_op);
5661 g_object_unref (header);
5663 g_object_unref (header_list);
5668 * Checks if we need a connection to do the transfer and if the user
5669 * wants to connect to complete it
5672 modest_ui_actions_xfer_messages_check (GtkWindow *parent_window,
5673 TnyFolderStore *src_folder,
5675 TnyFolder *dst_folder,
5676 gboolean delete_originals,
5677 gboolean *need_connection,
5680 TnyAccount *src_account;
5681 gint uncached_msgs = 0;
5683 /* We don't need any further check if
5685 * 1- the source folder is local OR
5686 * 2- the device is already online
5688 if (!modest_tny_folder_store_is_remote (src_folder) ||
5689 tny_device_is_online (modest_runtime_get_device())) {
5690 *need_connection = FALSE;
5695 /* We must ask for a connection when
5697 * - the message(s) is not already cached OR
5698 * - the message(s) is cached but the leave_on_server setting
5699 * is FALSE (because we need to sync the source folder to
5700 * delete the message from the server (for IMAP we could do it
5701 * offline, it'll take place the next time we get a
5704 uncached_msgs = header_list_count_uncached_msgs (headers);
5705 src_account = get_account_from_folder_store (src_folder);
5706 if (uncached_msgs > 0) {
5710 *need_connection = TRUE;
5711 num_headers = tny_list_get_length (headers);
5712 msg = ngettext ("mcen_nc_get_msg", "mcen_nc_get_msgs", num_headers);
5714 if (modest_platform_run_confirmation_dialog (parent_window, msg) ==
5715 GTK_RESPONSE_CANCEL) {
5721 /* The transfer is possible and the user wants to */
5724 if (remote_folder_has_leave_on_server (src_folder) && delete_originals) {
5725 const gchar *account_name;
5726 gboolean leave_on_server;
5728 account_name = modest_tny_account_get_parent_modest_account_name_for_server_account (src_account);
5729 leave_on_server = modest_account_mgr_get_leave_on_server (modest_runtime_get_account_mgr (),
5732 if (leave_on_server == TRUE) {
5733 *need_connection = FALSE;
5735 *need_connection = TRUE;
5738 *need_connection = FALSE;
5743 g_object_unref (src_account);
5747 xfer_messages_error_handler (ModestMailOperation *mail_op,
5751 const GError *error;
5752 TnyAccount *account;
5754 win = modest_mail_operation_get_source (mail_op);
5755 error = modest_mail_operation_get_error (mail_op);
5757 /* We cannot get the account from the mail op as that is the
5758 source account and for checking memory full conditions we
5759 need the destination one */
5760 account = TNY_ACCOUNT (user_data);
5763 !modest_tny_account_store_check_disk_full_error (modest_runtime_get_account_store(),
5764 (GtkWidget *) win, (GError*) error,
5765 account, _KR("cerm_memory_card_full"))) {
5766 modest_platform_run_information_dialog ((GtkWindow *) win,
5767 _("mail_in_ui_folder_move_target_error"),
5771 g_object_unref (win);
5775 TnyFolderStore *dst_folder;
5780 * Utility function that transfer messages from both the main window
5781 * and the msg view window when using the "Move to" dialog
5784 xfer_messages_performer (gboolean canceled,
5786 GtkWindow *parent_window,
5787 TnyAccount *account,
5790 ModestWindow *win = MODEST_WINDOW (parent_window);
5791 TnyAccount *dst_account = NULL;
5792 gboolean dst_forbids_message_add = FALSE;
5793 XferMsgsHelper *helper;
5794 MoveToHelper *movehelper;
5795 ModestMailOperation *mail_op;
5797 helper = (XferMsgsHelper *) user_data;
5799 if (canceled || err) {
5800 if (!modest_tny_account_store_check_disk_full_error (modest_runtime_get_account_store(),
5801 (GtkWidget *) parent_window, err,
5803 /* Show the proper error message */
5804 modest_ui_actions_on_account_connection_error (parent_window, account);
5809 dst_account = tny_folder_get_account (TNY_FOLDER (helper->dst_folder));
5811 /* tinymail will return NULL for local folders it seems */
5812 dst_forbids_message_add = modest_protocol_registry_protocol_type_has_tag (modest_runtime_get_protocol_registry (),
5813 modest_tny_account_get_protocol_type (dst_account),
5814 MODEST_PROTOCOL_REGISTRY_STORE_FORBID_INCOMING_XFERS);
5816 if (dst_forbids_message_add) {
5817 modest_platform_information_banner (GTK_WIDGET (win),
5819 ngettext("mail_in_ui_folder_move_target_error",
5820 "mail_in_ui_folder_move_targets_error",
5821 tny_list_get_length (helper->headers)));
5825 movehelper = g_new0 (MoveToHelper, 1);
5827 #ifndef MODEST_TOOLKIT_HILDON2
5828 movehelper->banner = modest_platform_animation_banner (GTK_WIDGET (win), NULL,
5829 _CS("ckct_nw_pasting"));
5830 if (movehelper->banner != NULL) {
5831 g_object_ref (movehelper->banner);
5832 gtk_widget_show (GTK_WIDGET (movehelper->banner));
5835 if (MODEST_IS_MAIN_WINDOW (win)) {
5836 GtkWidget *header_view =
5837 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
5838 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
5839 movehelper->reference = get_next_after_selected_headers (MODEST_HEADER_VIEW (header_view));
5843 /* Perform the mail operation */
5844 mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT(win),
5845 xfer_messages_error_handler,
5846 g_object_ref (dst_account),
5848 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
5851 modest_mail_operation_xfer_msgs (mail_op,
5853 TNY_FOLDER (helper->dst_folder),
5858 g_object_unref (G_OBJECT (mail_op));
5861 g_object_unref (dst_account);
5862 g_object_unref (helper->dst_folder);
5863 g_object_unref (helper->headers);
5864 g_slice_free (XferMsgsHelper, helper);
5868 TnyFolder *src_folder;
5869 TnyFolderStore *dst_folder;
5870 gboolean delete_original;
5871 GtkWidget *folder_view;
5875 on_move_folder_cb (gboolean canceled,
5877 GtkWindow *parent_window,
5878 TnyAccount *account,
5881 MoveFolderInfo *info = (MoveFolderInfo*)user_data;
5882 GtkTreeSelection *sel;
5883 ModestMailOperation *mail_op = NULL;
5885 if (canceled || err || !MODEST_IS_WINDOW (parent_window)) {
5886 /* Note that the connection process can fail due to
5887 memory low conditions as it can not successfully
5888 store the summary */
5889 if (!modest_tny_account_store_check_disk_full_error (modest_runtime_get_account_store(),
5890 (GtkWidget*) parent_window, err,
5892 g_debug ("Error connecting when trying to move a folder");
5894 g_object_unref (G_OBJECT (info->src_folder));
5895 g_object_unref (G_OBJECT (info->dst_folder));
5900 MoveToHelper *helper = g_new0 (MoveToHelper, 1);
5901 #ifndef MODEST_TOOLKIT_HILDON2
5902 helper->banner = modest_platform_animation_banner (GTK_WIDGET (parent_window), NULL,
5903 _CS("ckct_nw_pasting"));
5904 if (helper->banner != NULL) {
5905 g_object_ref (helper->banner);
5906 gtk_widget_show (GTK_WIDGET(helper->banner));
5909 /* Clean folder on header view before moving it */
5910 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (info->folder_view));
5911 gtk_tree_selection_unselect_all (sel);
5913 /* Let gtk events run. We need that the folder
5914 view frees its reference to the source
5915 folder *before* issuing the mail operation
5916 so we need the signal handler of selection
5917 changed to happen before the mail
5919 while (gtk_events_pending ())
5920 gtk_main_iteration (); */
5923 modest_mail_operation_new_with_error_handling (G_OBJECT(parent_window),
5924 modest_ui_actions_move_folder_error_handler,
5925 g_object_ref (info->dst_folder), g_object_unref);
5926 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
5929 #ifndef MODEST_TOOLKIT_HILDON2
5930 if (MODEST_IS_MAIN_WINDOW (parent_window)) {
5931 modest_folder_view_select_folder (MODEST_FOLDER_VIEW(info->folder_view),
5932 TNY_FOLDER (info->dst_folder), TRUE);
5935 modest_mail_operation_xfer_folder (mail_op,
5936 TNY_FOLDER (info->src_folder),
5938 info->delete_original,
5941 g_object_unref (G_OBJECT (info->src_folder));
5943 /* if (modest_mail_operation_get_status (mail_op) == MODEST_MAIL_OPERATION_STATUS_SUCCESS) { */
5946 /* Unref mail operation */
5947 g_object_unref (G_OBJECT (mail_op));
5948 g_object_unref (G_OBJECT (info->dst_folder));
5953 get_account_from_folder_store (TnyFolderStore *folder_store)
5955 if (TNY_IS_ACCOUNT (folder_store))
5956 return g_object_ref (folder_store);
5958 return tny_folder_get_account (TNY_FOLDER (folder_store));
5961 #ifndef MODEST_TOOLKIT_HILDON2
5963 * UI handler for the "Move to" action when invoked from the
5967 modest_ui_actions_on_main_window_move_to (GtkAction *action,
5968 GtkWidget *folder_view,
5969 TnyFolderStore *dst_folder,
5970 ModestMainWindow *win)
5972 ModestHeaderView *header_view = NULL;
5973 TnyFolderStore *src_folder = NULL;
5975 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win));
5977 /* Get the source folder */
5978 src_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
5980 /* Get header view */
5981 header_view = (ModestHeaderView *)
5982 modest_main_window_get_child_widget (win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
5984 /* Get folder or messages to transfer */
5985 if (gtk_widget_is_focus (folder_view)) {
5986 gboolean do_xfer = TRUE;
5988 /* Allow only to transfer folders to the local root folder */
5989 if (TNY_IS_ACCOUNT (dst_folder) &&
5990 !MODEST_IS_TNY_LOCAL_FOLDERS_ACCOUNT (dst_folder) &&
5991 !modest_tny_account_is_memory_card_account (TNY_ACCOUNT (dst_folder))) {
5993 } else if (!TNY_IS_FOLDER (src_folder)) {
5994 g_warning ("%s: src_folder is not a TnyFolder.\n", __FUNCTION__);
5999 MoveFolderInfo *info = g_new0 (MoveFolderInfo, 1);
6000 DoubleConnectionInfo *connect_info = g_slice_new (DoubleConnectionInfo);
6002 info->src_folder = g_object_ref (src_folder);
6003 info->dst_folder = g_object_ref (dst_folder);
6004 info->delete_original = TRUE;
6005 info->folder_view = folder_view;
6007 connect_info->callback = on_move_folder_cb;
6008 connect_info->dst_account = get_account_from_folder_store (TNY_FOLDER_STORE (dst_folder));
6009 connect_info->data = info;
6011 modest_platform_double_connect_and_perform(GTK_WINDOW (win), TRUE,
6012 TNY_FOLDER_STORE (src_folder),
6015 } else if (gtk_widget_is_focus (GTK_WIDGET(header_view))) {
6018 headers = modest_header_view_get_selected_headers(header_view);
6020 /* Transfer the messages */
6021 modest_ui_actions_transfer_messages_helper (GTK_WINDOW (win), TNY_FOLDER (src_folder),
6022 headers, TNY_FOLDER (dst_folder));
6024 g_object_unref (headers);
6028 g_object_unref (src_folder);
6032 #ifdef MODEST_TOOLKIT_HILDON2
6034 * UI handler for the "Move to" action when invoked from the
6035 * ModestFolderWindow
6038 modest_ui_actions_on_folder_window_move_to (GtkWidget *folder_view,
6039 TnyFolderStore *dst_folder,
6043 TnyFolderStore *src_folder = NULL;
6044 TnyIterator *iterator;
6046 if (tny_list_get_length (selection) != 1)
6049 iterator = tny_list_create_iterator (selection);
6050 src_folder = TNY_FOLDER_STORE (tny_iterator_get_current (iterator));
6051 g_object_unref (iterator);
6054 gboolean do_xfer = TRUE;
6056 /* Allow only to transfer folders to the local root folder */
6057 if (TNY_IS_ACCOUNT (dst_folder) &&
6058 !MODEST_IS_TNY_LOCAL_FOLDERS_ACCOUNT (dst_folder) &&
6059 !modest_tny_account_is_memory_card_account (TNY_ACCOUNT (dst_folder))) {
6062 modest_platform_run_information_dialog (win,
6063 _("mail_in_ui_folder_move_target_error"),
6065 } else if (!TNY_IS_FOLDER (src_folder)) {
6066 g_warning ("%s: src_folder is not a TnyFolder.\n", __FUNCTION__);
6071 MoveFolderInfo *info = g_new0 (MoveFolderInfo, 1);
6072 DoubleConnectionInfo *connect_info = g_slice_new (DoubleConnectionInfo);
6074 info->src_folder = g_object_ref (src_folder);
6075 info->dst_folder = g_object_ref (dst_folder);
6076 info->delete_original = TRUE;
6077 info->folder_view = folder_view;
6079 connect_info->callback = on_move_folder_cb;
6080 connect_info->dst_account = get_account_from_folder_store (TNY_FOLDER_STORE (dst_folder));
6081 connect_info->data = info;
6083 modest_platform_double_connect_and_perform(GTK_WINDOW (win), TRUE,
6084 TNY_FOLDER_STORE (src_folder),
6089 g_object_unref (src_folder);
6095 modest_ui_actions_transfer_messages_helper (GtkWindow *win,
6096 TnyFolder *src_folder,
6098 TnyFolder *dst_folder)
6100 gboolean need_connection = TRUE;
6101 gboolean do_xfer = TRUE;
6102 XferMsgsHelper *helper;
6104 g_return_if_fail (TNY_IS_FOLDER (src_folder));
6105 g_return_if_fail (TNY_IS_FOLDER (dst_folder));
6106 g_return_if_fail (TNY_IS_LIST (headers));
6108 modest_ui_actions_xfer_messages_check (win, TNY_FOLDER_STORE (src_folder),
6109 headers, TNY_FOLDER (dst_folder),
6110 TRUE, &need_connection,
6113 /* If we don't want to transfer just return */
6117 /* Create the helper */
6118 helper = g_slice_new (XferMsgsHelper);
6119 helper->dst_folder = g_object_ref (dst_folder);
6120 helper->headers = g_object_ref (headers);
6122 if (need_connection) {
6123 DoubleConnectionInfo *connect_info = g_slice_new (DoubleConnectionInfo);
6124 connect_info->callback = xfer_messages_performer;
6125 connect_info->dst_account = tny_folder_get_account (TNY_FOLDER (dst_folder));
6126 connect_info->data = helper;
6128 modest_platform_double_connect_and_perform(GTK_WINDOW (win), TRUE,
6129 TNY_FOLDER_STORE (src_folder),
6132 TnyAccount *src_account = get_account_from_folder_store (TNY_FOLDER_STORE (src_folder));
6133 xfer_messages_performer (FALSE, NULL, GTK_WINDOW (win),
6134 src_account, helper);
6135 g_object_unref (src_account);
6140 * UI handler for the "Move to" action when invoked from the
6141 * ModestMsgViewWindow
6144 modest_ui_actions_on_window_move_to (GtkAction *action,
6146 TnyFolderStore *dst_folder,
6149 TnyFolder *src_folder = NULL;
6151 g_return_if_fail (TNY_IS_FOLDER (dst_folder));
6154 TnyHeader *header = NULL;
6157 iter = tny_list_create_iterator (headers);
6158 header = (TnyHeader *) tny_iterator_get_current (iter);
6159 src_folder = tny_header_get_folder (header);
6161 /* Transfer the messages */
6162 modest_ui_actions_transfer_messages_helper (GTK_WINDOW (win), src_folder,
6164 TNY_FOLDER (dst_folder));
6167 g_object_unref (header);
6168 g_object_unref (iter);
6169 g_object_unref (src_folder);
6174 modest_ui_actions_on_move_to (GtkAction *action,
6177 modest_ui_actions_on_edit_mode_move_to (win);
6181 modest_ui_actions_on_edit_mode_move_to (ModestWindow *win)
6183 GtkWidget *dialog = NULL;
6184 MoveToInfo *helper = NULL;
6185 TnyList *list_to_move;
6187 g_return_val_if_fail (MODEST_IS_WINDOW (win), FALSE);
6189 #ifndef MODEST_TOOLKIT_HILDON2
6190 /* Get the main window if exists */
6191 ModestMainWindow *main_window;
6192 if (MODEST_IS_MAIN_WINDOW (win))
6193 main_window = MODEST_MAIN_WINDOW (win);
6196 MODEST_MAIN_WINDOW (modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (),
6197 FALSE)); /* don't create */
6200 list_to_move = modest_platform_get_list_to_move (MODEST_WINDOW (win));
6205 if (tny_list_get_length (list_to_move) < 1) {
6206 g_object_unref (list_to_move);
6210 /* Create and run the dialog */
6211 dialog = create_move_to_dialog (GTK_WINDOW (win), NULL, list_to_move);
6212 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (),
6213 GTK_WINDOW (dialog),
6217 helper = g_slice_new0 (MoveToInfo);
6218 helper->list = list_to_move;
6221 /* Listen to response signal */
6222 g_signal_connect (dialog, "response", G_CALLBACK (on_move_to_dialog_response), helper);
6224 /* Show the dialog */
6225 gtk_widget_show (dialog);
6231 * Calls #HeadersFunc for each header already selected in the main
6232 * window or the message currently being shown in the msg view window
6235 do_headers_action (ModestWindow *win,
6239 TnyList *headers_list = NULL;
6240 TnyIterator *iter = NULL;
6241 TnyHeader *header = NULL;
6242 TnyFolder *folder = NULL;
6245 headers_list = get_selected_headers (win);
6249 /* Get the folder */
6250 iter = tny_list_create_iterator (headers_list);
6251 header = TNY_HEADER (tny_iterator_get_current (iter));
6253 folder = tny_header_get_folder (header);
6254 g_object_unref (header);
6257 /* Call the function for each header */
6258 while (!tny_iterator_is_done (iter)) {
6259 header = TNY_HEADER (tny_iterator_get_current (iter));
6260 func (header, win, user_data);
6261 g_object_unref (header);
6262 tny_iterator_next (iter);
6265 /* Trick: do a poke status in order to speed up the signaling
6268 tny_folder_poke_status (folder);
6269 g_object_unref (folder);
6273 g_object_unref (iter);
6274 g_object_unref (headers_list);
6278 modest_ui_actions_view_attachment (GtkAction *action,
6279 ModestWindow *window)
6281 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
6282 modest_msg_view_window_view_attachment (MODEST_MSG_VIEW_WINDOW (window), NULL);
6284 /* not supported window for this action */
6285 g_return_if_reached ();
6290 modest_ui_actions_save_attachments (GtkAction *action,
6291 ModestWindow *window)
6293 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
6295 if (modest_platform_check_memory_low (MODEST_WINDOW(window), TRUE))
6298 modest_msg_view_window_save_attachments (MODEST_MSG_VIEW_WINDOW (window), NULL);
6300 /* not supported window for this action */
6301 g_return_if_reached ();
6306 modest_ui_actions_remove_attachments (GtkAction *action,
6307 ModestWindow *window)
6309 #ifndef MODEST_TOOLKIT_HILDON2
6310 if (MODEST_IS_MAIN_WINDOW (window)) {
6311 modest_ui_actions_on_main_window_remove_attachments (action, MODEST_MAIN_WINDOW (window));
6312 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
6314 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
6316 modest_msg_view_window_remove_attachments (MODEST_MSG_VIEW_WINDOW (window), FALSE);
6318 /* not supported window for this action */
6319 g_return_if_reached ();
6324 modest_ui_actions_on_settings (GtkAction *action,
6329 dialog = modest_platform_get_global_settings_dialog ();
6330 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (win));
6331 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
6332 gtk_widget_show_all (dialog);
6334 gtk_dialog_run (GTK_DIALOG (dialog));
6336 gtk_widget_destroy (dialog);
6340 modest_ui_actions_on_help (GtkAction *action,
6343 /* Help app is not available at all in fremantle */
6344 #ifndef MODEST_TOOLKIT_HILDON2
6345 const gchar *help_id;
6347 g_return_if_fail (win && GTK_IS_WINDOW(win));
6349 help_id = modest_window_mgr_get_help_id (modest_runtime_get_window_mgr(), win);
6352 modest_platform_show_help (GTK_WINDOW (win), help_id);
6357 modest_ui_actions_on_csm_help (GtkAction *action,
6360 /* Help app is not available at all in fremantle */
6361 #ifndef MODEST_TOOLKIT_HILDON2
6363 const gchar* help_id = NULL;
6364 GtkWidget *folder_view;
6365 TnyFolderStore *folder_store;
6367 g_return_if_fail (win && MODEST_IS_MAIN_WINDOW (win));
6369 /* Get selected folder */
6370 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
6371 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
6372 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
6374 /* Switch help_id */
6375 if (folder_store && TNY_IS_FOLDER (folder_store))
6376 help_id = modest_tny_folder_get_help_id (TNY_FOLDER (folder_store));
6379 g_object_unref (folder_store);
6382 modest_platform_show_help (GTK_WINDOW (win), help_id);
6384 modest_ui_actions_on_help (action, win);
6389 retrieve_contents_cb (ModestMailOperation *mail_op,
6396 /* We only need this callback to show an error in case of
6397 memory low condition */
6398 if (!modest_ui_actions_msg_retrieval_check (mail_op, header, msg)) {
6399 g_debug ("%s: message failed to retrieve. Memory low?", __FUNCTION__);
6404 retrieve_msg_contents_performer (gboolean canceled,
6406 GtkWindow *parent_window,
6407 TnyAccount *account,
6410 ModestMailOperation *mail_op;
6411 TnyList *headers = TNY_LIST (user_data);
6413 if (err || canceled) {
6414 modest_tny_account_store_check_disk_full_error (modest_runtime_get_account_store(),
6415 (GtkWidget *) parent_window, err,
6420 /* Create mail operation */
6421 mail_op = modest_mail_operation_new_with_error_handling ((GObject *) parent_window,
6422 modest_ui_actions_disk_operations_error_handler,
6424 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
6425 modest_mail_operation_get_msgs_full (mail_op, headers, retrieve_contents_cb, NULL, NULL);
6428 g_object_unref (mail_op);
6430 g_object_unref (headers);
6431 g_object_unref (account);
6435 modest_ui_actions_on_retrieve_msg_contents (GtkAction *action,
6436 ModestWindow *window)
6438 TnyList *headers = NULL;
6439 TnyAccount *account = NULL;
6440 TnyIterator *iter = NULL;
6441 TnyHeader *header = NULL;
6442 TnyFolder *folder = NULL;
6445 headers = get_selected_headers (window);
6449 /* Pick the account */
6450 iter = tny_list_create_iterator (headers);
6451 header = TNY_HEADER (tny_iterator_get_current (iter));
6452 folder = tny_header_get_folder (header);
6453 account = tny_folder_get_account (folder);
6454 g_object_unref (folder);
6455 g_object_unref (header);
6456 g_object_unref (iter);
6458 /* Connect and perform the message retrieval */
6459 modest_platform_connect_and_perform ((GtkWindow *) window, TRUE,
6460 g_object_ref (account),
6461 retrieve_msg_contents_performer,
6462 g_object_ref (headers));
6465 g_object_unref (account);
6466 g_object_unref (headers);
6470 modest_ui_actions_check_toolbar_dimming_rules (ModestWindow *window)
6472 g_return_if_fail (MODEST_IS_WINDOW (window));
6475 modest_window_check_dimming_rules_group (window, MODEST_DIMMING_RULES_TOOLBAR);
6479 modest_ui_actions_check_menu_dimming_rules (ModestWindow *window)
6481 g_return_if_fail (MODEST_IS_WINDOW (window));
6484 modest_window_check_dimming_rules_group (window, MODEST_DIMMING_RULES_MENU);
6488 modest_ui_actions_on_email_menu_activated (GtkAction *action,
6489 ModestWindow *window)
6491 g_return_if_fail (MODEST_IS_WINDOW (window));
6494 modest_ui_actions_check_menu_dimming_rules (window);
6498 modest_ui_actions_on_edit_menu_activated (GtkAction *action,
6499 ModestWindow *window)
6501 g_return_if_fail (MODEST_IS_WINDOW (window));
6504 modest_ui_actions_check_menu_dimming_rules (window);
6508 modest_ui_actions_on_view_menu_activated (GtkAction *action,
6509 ModestWindow *window)
6511 g_return_if_fail (MODEST_IS_WINDOW (window));
6514 modest_ui_actions_check_menu_dimming_rules (window);
6518 modest_ui_actions_on_format_menu_activated (GtkAction *action,
6519 ModestWindow *window)
6521 g_return_if_fail (MODEST_IS_WINDOW (window));
6524 modest_ui_actions_check_menu_dimming_rules (window);
6528 modest_ui_actions_on_tools_menu_activated (GtkAction *action,
6529 ModestWindow *window)
6531 g_return_if_fail (MODEST_IS_WINDOW (window));
6534 modest_ui_actions_check_menu_dimming_rules (window);
6538 modest_ui_actions_on_attachment_menu_activated (GtkAction *action,
6539 ModestWindow *window)
6541 g_return_if_fail (MODEST_IS_WINDOW (window));
6544 modest_ui_actions_check_menu_dimming_rules (window);
6548 modest_ui_actions_on_toolbar_csm_menu_activated (GtkAction *action,
6549 ModestWindow *window)
6551 g_return_if_fail (MODEST_IS_WINDOW (window));
6554 modest_ui_actions_check_menu_dimming_rules (window);
6558 modest_ui_actions_on_folder_view_csm_menu_activated (GtkAction *action,
6559 ModestWindow *window)
6561 g_return_if_fail (MODEST_IS_WINDOW (window));
6564 modest_ui_actions_check_menu_dimming_rules (window);
6568 modest_ui_actions_on_header_view_csm_menu_activated (GtkAction *action,
6569 ModestWindow *window)
6571 g_return_if_fail (MODEST_IS_WINDOW (window));
6574 modest_ui_actions_check_menu_dimming_rules (window);
6578 modest_ui_actions_on_search_messages (GtkAction *action, ModestWindow *window)
6580 g_return_if_fail (MODEST_IS_WINDOW (window));
6582 /* we check for low-mem; in that case, show a warning, and don't allow
6585 if (modest_platform_check_memory_low (window, TRUE))
6588 modest_platform_show_search_messages (GTK_WINDOW (window));
6592 modest_ui_actions_on_open_addressbook (GtkAction *action, ModestWindow *win)
6594 g_return_if_fail (MODEST_IS_WINDOW (win));
6597 /* we check for low-mem; in that case, show a warning, and don't allow
6598 * for the addressbook
6600 if (modest_platform_check_memory_low (win, TRUE))
6604 modest_platform_show_addressbook (GTK_WINDOW (win));
6609 modest_ui_actions_on_toggle_find_in_page (GtkAction *action,
6610 ModestWindow *window)
6613 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
6615 if (GTK_IS_TOGGLE_ACTION (action))
6616 active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
6620 modest_msg_edit_window_toggle_find_toolbar (MODEST_MSG_EDIT_WINDOW (window),
6624 #ifndef MODEST_TOOLKIT_HILDON2
6626 on_send_receive_finished (ModestMailOperation *mail_op,
6629 GtkWidget *header_view, *folder_view;
6630 TnyFolderStore *folder_store;
6631 ModestMainWindow *main_win = MODEST_MAIN_WINDOW (user_data);
6633 /* Set send/receive operation finished */
6634 modest_main_window_notify_send_receive_completed (main_win);
6636 /* Don't refresh the current folder if there were any errors */
6637 if (modest_mail_operation_get_status (mail_op) !=
6638 MODEST_MAIL_OPERATION_STATUS_SUCCESS)
6641 /* Refresh the current folder if we're viewing a window. We do
6642 this because the user won't be able to see the new mails in
6643 the selected folder after a Send&Receive because it only
6644 performs a poke_status, i.e, only the number of read/unread
6645 messages is updated, but the new headers are not
6647 folder_view = modest_main_window_get_child_widget (main_win,
6648 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
6652 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
6654 /* Do not need to refresh INBOX again because the
6655 update_account does it always automatically */
6656 if (folder_store && TNY_IS_FOLDER (folder_store) &&
6657 tny_folder_get_folder_type (TNY_FOLDER (folder_store)) != TNY_FOLDER_TYPE_INBOX) {
6658 ModestMailOperation *refresh_op;
6660 header_view = modest_main_window_get_child_widget (main_win,
6661 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
6663 /* We do not need to set the contents style
6664 because it hasn't changed. We also do not
6665 need to save the widget status. Just force
6667 refresh_op = modest_mail_operation_new (G_OBJECT (main_win));
6668 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), refresh_op);
6669 modest_mail_operation_refresh_folder (refresh_op, TNY_FOLDER (folder_store),
6670 folder_refreshed_cb, main_win);
6671 g_object_unref (refresh_op);
6675 g_object_unref (folder_store);
6680 modest_ui_actions_on_send_queue_error_happened (TnySendQueue *self,
6686 const gchar* server_name = NULL;
6687 TnyTransportAccount *transport;
6688 gchar *message = NULL;
6689 ModestProtocol *protocol;
6691 /* Don't show anything if the user cancelled something or the
6692 * send receive request is not interactive. Authentication
6693 * errors are managed by the account store so no need to show
6694 * a dialog here again */
6695 if (err->code == TNY_SYSTEM_ERROR_CANCEL ||
6696 err->code == TNY_SERVICE_ERROR_AUTHENTICATE ||
6697 !modest_tny_send_queue_get_requested_send_receive (MODEST_TNY_SEND_QUEUE (self)))
6701 /* Get the server name. Note that we could be using a
6702 connection specific transport account */
6703 transport = (TnyTransportAccount *)
6704 tny_camel_send_queue_get_transport_account (TNY_CAMEL_SEND_QUEUE (self));
6706 ModestTnyAccountStore *acc_store;
6707 const gchar *acc_name;
6708 TnyTransportAccount *conn_specific;
6710 acc_store = modest_runtime_get_account_store();
6711 acc_name = modest_tny_account_get_parent_modest_account_name_for_server_account (TNY_ACCOUNT (transport));
6712 conn_specific = (TnyTransportAccount *)
6713 modest_tny_account_store_get_transport_account_for_open_connection (acc_store, acc_name);
6714 if (conn_specific) {
6715 server_name = tny_account_get_hostname (TNY_ACCOUNT (conn_specific));
6716 g_object_unref (conn_specific);
6718 server_name = tny_account_get_hostname (TNY_ACCOUNT (transport));
6720 g_object_unref (transport);
6724 protocol = modest_protocol_registry_get_protocol_by_name (modest_runtime_get_protocol_registry (),
6725 MODEST_PROTOCOL_REGISTRY_TRANSPORT_STORE_PROTOCOLS,
6726 tny_account_get_proto (TNY_ACCOUNT (transport)));
6728 g_warning ("%s: Account with no proto", __FUNCTION__);
6732 /* Show the appropriate message text for the GError: */
6733 switch (err->code) {
6734 case TNY_SERVICE_ERROR_CONNECT:
6735 message = modest_protocol_get_translation (protocol,
6736 MODEST_PROTOCOL_TRANSLATION_ACCOUNT_CONNECTION_ERROR,
6739 case TNY_SERVICE_ERROR_SEND:
6740 message = g_strdup (_CS("sfil_ib_unable_to_send"));
6742 case TNY_SERVICE_ERROR_UNAVAILABLE:
6743 message = modest_protocol_get_translation (protocol,
6744 MODEST_PROTOCOL_TRANSLATION_CONNECT_ERROR,
6748 g_warning ("%s: unexpected ERROR %d",
6749 __FUNCTION__, err->code);
6750 message = g_strdup (_CS("sfil_ib_unable_to_send"));
6754 modest_platform_run_information_dialog (NULL, message, FALSE);
6759 modest_ui_actions_on_send_queue_status_changed (ModestTnySendQueue *send_queue,
6764 ModestWindow *top_window = NULL;
6765 ModestWindowMgr *mgr = NULL;
6766 GtkWidget *header_view = NULL;
6767 TnyFolder *selected_folder = NULL;
6768 TnyFolderType folder_type;
6770 mgr = modest_runtime_get_window_mgr ();
6771 top_window = modest_window_mgr_get_current_top (mgr);
6776 #ifndef MODEST_TOOLKIT_HILDON2
6777 if (MODEST_IS_MAIN_WINDOW (top_window)) {
6778 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (top_window),
6779 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
6782 if (MODEST_IS_HEADER_WINDOW (top_window)) {
6783 header_view = (GtkWidget *)
6784 modest_header_window_get_header_view (MODEST_HEADER_WINDOW (top_window));
6788 /* Get selected folder */
6790 selected_folder = modest_header_view_get_folder (MODEST_HEADER_VIEW (header_view));
6791 if (!selected_folder)
6794 /* gtk_tree_view_column_queue_resize is only available in GTK+ 2.8 */
6795 #if GTK_CHECK_VERSION(2, 8, 0)
6796 folder_type = modest_tny_folder_guess_folder_type (selected_folder);
6797 if (folder_type == TNY_FOLDER_TYPE_OUTBOX) {
6798 GtkTreeViewColumn *tree_column;
6800 tree_column = gtk_tree_view_get_column (GTK_TREE_VIEW (header_view),
6801 TNY_GTK_HEADER_LIST_MODEL_FROM_COLUMN);
6803 gtk_tree_view_column_queue_resize (tree_column);
6805 #else /* #if GTK_CHECK_VERSION(2, 8, 0) */
6806 gtk_widget_queue_draw (header_view);
6809 #ifndef MODEST_TOOLKIT_HILDON2
6810 /* Rerun dimming rules, because the message could become deletable for example */
6811 modest_window_check_dimming_rules_group (MODEST_WINDOW (top_window),
6812 MODEST_DIMMING_RULES_TOOLBAR);
6813 modest_window_check_dimming_rules_group (MODEST_WINDOW (top_window),
6814 MODEST_DIMMING_RULES_MENU);
6818 g_object_unref (selected_folder);
6822 modest_ui_actions_on_account_connection_error (GtkWindow *parent_window,
6823 TnyAccount *account)
6825 ModestProtocolType protocol_type;
6826 ModestProtocol *protocol;
6827 gchar *error_note = NULL;
6829 protocol_type = modest_tny_account_get_protocol_type (account);
6830 protocol = modest_protocol_registry_get_protocol_by_type (modest_runtime_get_protocol_registry (),
6833 error_note = modest_protocol_get_translation (protocol, MODEST_PROTOCOL_TRANSLATION_ACCOUNT_CONNECTION_ERROR, tny_account_get_hostname (account));
6834 if (error_note == NULL) {
6835 g_warning ("%s: This should not be reached", __FUNCTION__);
6837 modest_platform_run_information_dialog (parent_window, error_note, FALSE);
6838 g_free (error_note);
6843 modest_ui_actions_get_msg_already_deleted_error_msg (ModestWindow *win)
6847 TnyFolderStore *folder = NULL;
6848 TnyAccount *account = NULL;
6849 ModestProtocolType proto;
6850 ModestProtocol *protocol;
6851 TnyHeader *header = NULL;
6853 #ifndef MODEST_TOOLKIT_HILDON2
6854 if (MODEST_IS_MAIN_WINDOW (win)) {
6855 GtkWidget *header_view;
6856 TnyList* headers = NULL;
6858 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
6859 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
6860 headers = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW (header_view));
6861 if (!headers || tny_list_get_length (headers) == 0) {
6863 g_object_unref (headers);
6866 iter = tny_list_create_iterator (headers);
6867 header = TNY_HEADER (tny_iterator_get_current (iter));
6868 folder = TNY_FOLDER_STORE (tny_header_get_folder (header));
6869 g_object_unref (iter);
6870 g_object_unref (headers);
6872 if (MODEST_IS_HEADER_WINDOW (win)) {
6873 GtkWidget *header_view;
6874 TnyList* headers = NULL;
6876 header_view = GTK_WIDGET (modest_header_window_get_header_view (MODEST_HEADER_WINDOW (win)));
6877 headers = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW (header_view));
6878 if (!headers || tny_list_get_length (headers) == 0) {
6880 g_object_unref (headers);
6883 iter = tny_list_create_iterator (headers);
6884 header = TNY_HEADER (tny_iterator_get_current (iter));
6886 folder = TNY_FOLDER_STORE (tny_header_get_folder (header));
6888 g_warning ("List should contain headers");
6890 g_object_unref (iter);
6891 g_object_unref (headers);
6893 } else if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
6894 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
6896 folder = TNY_FOLDER_STORE (tny_header_get_folder (header));
6899 if (!header || !folder)
6902 /* Get the account type */
6903 account = tny_folder_get_account (TNY_FOLDER (folder));
6904 proto = modest_tny_account_get_protocol_type (account);
6905 protocol = modest_protocol_registry_get_protocol_by_type (modest_runtime_get_protocol_registry (),
6908 subject = tny_header_dup_subject (header);
6909 msg = modest_protocol_get_translation (protocol, MODEST_PROTOCOL_TRANSLATION_MSG_NOT_AVAILABLE, subject);
6913 msg = g_strdup_printf (_("mail_ni_ui_folder_get_msg_folder_error"));
6919 g_object_unref (account);
6921 g_object_unref (folder);
6923 g_object_unref (header);
6929 modest_ui_actions_on_delete_account (GtkWindow *parent_window,
6930 const gchar *account_name,
6931 const gchar *account_title)
6933 ModestAccountMgr *account_mgr;
6936 ModestProtocol *protocol;
6937 gboolean removed = FALSE;
6939 g_return_val_if_fail (account_name, FALSE);
6940 g_return_val_if_fail (account_title, FALSE);
6942 account_mgr = modest_runtime_get_account_mgr();
6944 /* The warning text depends on the account type: */
6945 protocol = modest_protocol_registry_get_protocol_by_type (modest_runtime_get_protocol_registry (),
6946 modest_account_mgr_get_store_protocol (account_mgr,
6948 txt = modest_protocol_get_translation (protocol,
6949 MODEST_PROTOCOL_TRANSLATION_DELETE_MAILBOX,
6952 txt = g_strdup_printf (_("emev_nc_delete_mailbox"), account_title);
6954 response = modest_platform_run_confirmation_dialog (parent_window, txt);
6958 if (response == GTK_RESPONSE_OK) {
6959 /* Remove account. If it succeeds then it also removes
6960 the account from the ModestAccountView: */
6961 gboolean is_default = FALSE;
6962 gchar *default_account_name = modest_account_mgr_get_default_account (account_mgr);
6963 if (default_account_name && (strcmp (default_account_name, account_name) == 0))
6965 g_free (default_account_name);
6967 removed = modest_account_mgr_remove_account (account_mgr, account_name);
6969 /* Close all email notifications, we cannot
6970 distinguish if the notification belongs to
6971 this account or not, so for safety reasons
6972 we remove them all */
6973 modest_platform_remove_new_mail_notifications (FALSE);
6975 g_warning ("%s: modest_account_mgr_remove_account() failed.\n", __FUNCTION__);
6982 on_fetch_images_performer (gboolean canceled,
6984 GtkWindow *parent_window,
6985 TnyAccount *account,
6988 if (err || canceled) {
6989 /* Show an unable to retrieve images ??? */
6993 /* Note that the user could have closed the window while connecting */
6994 if (GTK_WIDGET_VISIBLE (parent_window))
6995 modest_msg_view_window_fetch_images ((ModestMsgViewWindow *) parent_window);
6996 g_object_unref ((GObject *) user_data);
7000 modest_ui_actions_on_fetch_images (GtkAction *action,
7001 ModestWindow *window)
7003 g_return_if_fail (MODEST_IS_MSG_VIEW_WINDOW (window));
7005 modest_platform_connect_and_perform ((GtkWindow *) window, TRUE,
7007 on_fetch_images_performer,
7008 g_object_ref (window));
7012 modest_ui_actions_on_reload_message (const gchar *msg_id)
7014 ModestWindow *window = NULL;
7016 g_return_if_fail (msg_id && msg_id[0] != '\0');
7017 if (!modest_window_mgr_find_registered_message_uid (modest_runtime_get_window_mgr (),
7023 if (window == NULL || !MODEST_IS_MSG_VIEW_WINDOW (window))
7026 modest_msg_view_window_reload (MODEST_MSG_VIEW_WINDOW (window));
7029 /** Check whether any connections are active, and cancel them if
7031 * Returns TRUE is there was no problem,
7032 * or if an operation was cancelled so we can continue.
7033 * Returns FALSE if the user chose to cancel his request instead.
7037 modest_ui_actions_check_for_active_account (ModestWindow *self,
7038 const gchar* account_name)
7040 ModestTnySendQueue *send_queue;
7041 ModestTnyAccountStore *acc_store;
7042 ModestMailOperationQueue* queue;
7043 TnyConnectionStatus store_conn_status;
7044 TnyAccount *store_account = NULL, *transport_account = NULL;
7045 gboolean retval = TRUE, sending = FALSE;
7047 acc_store = modest_runtime_get_account_store ();
7048 queue = modest_runtime_get_mail_operation_queue ();
7051 modest_tny_account_store_get_server_account (acc_store,
7053 TNY_ACCOUNT_TYPE_STORE);
7055 /* This could happen if the account was deleted before the
7056 call to this function */
7061 modest_tny_account_store_get_server_account (acc_store,
7063 TNY_ACCOUNT_TYPE_TRANSPORT);
7065 /* This could happen if the account was deleted before the
7066 call to this function */
7067 if (!transport_account) {
7068 g_object_unref (store_account);
7072 /* If the transport account was not used yet, then the send
7073 queue could not exist (it's created on demand) */
7074 send_queue = modest_runtime_get_send_queue (TNY_TRANSPORT_ACCOUNT (transport_account), FALSE);
7075 if (TNY_IS_SEND_QUEUE (send_queue))
7076 sending = modest_tny_send_queue_sending_in_progress (send_queue);
7078 store_conn_status = tny_account_get_connection_status (store_account);
7079 if (store_conn_status == TNY_CONNECTION_STATUS_CONNECTED || sending) {
7082 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (self),
7083 _("emev_nc_disconnect_account"));
7084 if (response == GTK_RESPONSE_OK) {
7093 /* FIXME: We should only cancel those of this account */
7094 modest_mail_operation_queue_cancel_all (queue);
7096 /* Also disconnect the account */
7097 if ((tny_account_get_connection_status (store_account) != TNY_CONNECTION_STATUS_DISCONNECTED) &&
7098 (tny_account_get_connection_status (store_account) != TNY_CONNECTION_STATUS_DISCONNECTED_BROKEN)) {
7099 tny_camel_account_set_online (TNY_CAMEL_ACCOUNT (store_account),
7103 tny_camel_account_set_online (TNY_CAMEL_ACCOUNT (transport_account),
7109 g_object_unref (store_account);
7110 g_object_unref (transport_account);