1 /* Copyright (c) 2006, Nokia Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of the Nokia Corporation nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #endif /*HAVE_CONFIG_H*/
34 #include <glib/gi18n.h>
35 #include <glib/gprintf.h>
37 #include <modest-runtime.h>
38 #include <modest-tny-folder.h>
39 #include <modest-tny-msg.h>
40 #include <modest-tny-account.h>
41 #include <modest-address-book.h>
42 #include "modest-error.h"
43 #include "modest-ui-actions.h"
44 #include "modest-tny-platform-factory.h"
45 #include "modest-platform.h"
46 #include "modest-debug.h"
47 #include <tny-mime-part.h>
48 #include <tny-camel-folder.h>
49 #include <tny-camel-imap-folder.h>
50 #include <tny-camel-pop-folder.h>
51 #ifdef MODEST_TOOLKIT_HILDON2
52 #include <modest-accounts-window.h>
53 #include <hildon/hildon-pannable-area.h>
54 #include <hildon/hildon-gtk.h>
55 #include <modest-header-window.h>
56 #include <modest-folder-window.h>
59 #ifdef MODEST_PLATFORM_MAEMO
60 #include "maemo/modest-osso-state-saving.h"
61 #endif /* MODEST_PLATFORM_MAEMO */
62 #ifndef MODEST_TOOLKIT_GTK
63 #include "maemo/modest-hildon-includes.h"
64 #include "maemo/modest-connection-specific-smtp-window.h"
65 #endif /* !MODEST_TOOLKIT_GTK */
66 #include <modest-utils.h>
68 #include "widgets/modest-ui-constants.h"
69 #include <widgets/modest-main-window.h>
70 #include <widgets/modest-msg-view-window.h>
71 #include <widgets/modest-account-view-window.h>
72 #include <widgets/modest-details-dialog.h>
73 #include <widgets/modest-attachments-view.h>
74 #include "widgets/modest-folder-view.h"
75 #include "widgets/modest-global-settings-dialog.h"
76 #include "modest-account-mgr-helpers.h"
77 #include "modest-mail-operation.h"
78 #include "modest-text-utils.h"
79 #include <modest-widget-memory.h>
80 #include <tny-error.h>
81 #include <tny-simple-list.h>
82 #include <tny-msg-view.h>
83 #include <tny-device.h>
84 #include <tny-merge-folder.h>
86 #include <gtkhtml/gtkhtml.h>
88 #define MIN_FREE_SPACE 5 * 1024 * 1024
89 #define MODEST_MOVE_TO_DIALOG_FOLDER_VIEW "move-to-dialog-folder-view"
91 typedef struct _GetMsgAsyncHelper {
93 ModestMailOperation *mail_op;
100 typedef enum _ReplyForwardAction {
104 } ReplyForwardAction;
106 typedef struct _ReplyForwardHelper {
107 guint reply_forward_type;
108 ReplyForwardAction action;
110 GtkWidget *parent_window;
112 } ReplyForwardHelper;
114 typedef struct _MoveToHelper {
115 GtkTreeRowReference *reference;
119 typedef struct _PasteAsAttachmentHelper {
120 ModestMsgEditWindow *window;
122 } PasteAsAttachmentHelper;
130 * The do_headers_action uses this kind of functions to perform some
131 * action to each member of a list of headers
133 typedef void (*HeadersFunc) (TnyHeader *header, ModestWindow *win, gpointer user_data);
135 static void do_headers_action (ModestWindow *win,
139 static void open_msg_cb (ModestMailOperation *mail_op,
146 static void reply_forward_cb (ModestMailOperation *mail_op,
153 static void reply_forward (ReplyForwardAction action, ModestWindow *win);
155 static void folder_refreshed_cb (ModestMailOperation *mail_op,
159 static void on_send_receive_finished (ModestMailOperation *mail_op,
162 static gint header_list_count_uncached_msgs (TnyList *header_list);
164 static gboolean connect_to_get_msg (ModestWindow *win,
165 gint num_of_uncached_msgs,
166 TnyAccount *account);
168 static gboolean remote_folder_has_leave_on_server (TnyFolderStore *folder);
170 static void do_create_folder (GtkWindow *window,
171 TnyFolderStore *parent_folder,
172 const gchar *suggested_name);
174 static TnyAccount *get_account_from_folder_store (TnyFolderStore *folder_store);
176 static void modest_ui_actions_on_main_window_move_to (GtkAction *action,
177 GtkWidget *folder_view,
178 TnyFolderStore *dst_folder,
179 ModestMainWindow *win);
180 #ifdef MODEST_TOOLKIT_HILDON2
181 static void modest_ui_actions_on_folder_window_move_to (GtkWidget *folder_view,
182 TnyFolderStore *dst_folder,
187 static void modest_ui_actions_on_window_move_to (GtkAction *action,
188 TnyList *list_to_move,
189 TnyFolderStore *dst_folder,
193 * This function checks whether a TnyFolderStore is a pop account
196 remote_folder_has_leave_on_server (TnyFolderStore *folder)
201 g_return_val_if_fail (TNY_IS_FOLDER_STORE (folder), FALSE);
203 account = get_account_from_folder_store (folder);
204 result = (modest_protocol_registry_protocol_type_has_leave_on_server (modest_runtime_get_protocol_registry (),
205 modest_tny_account_get_protocol_type (account)));
206 g_object_unref (account);
211 /* FIXME: this should be merged with the similar code in modest-account-view-window */
212 /* Show the account creation wizard dialog.
213 * returns: TRUE if an account was created. FALSE if the user cancelled.
216 modest_ui_actions_run_account_setup_wizard (ModestWindow *win)
218 gboolean result = FALSE;
220 gint dialog_response;
222 /* there is no such wizard yet */
223 wizard = GTK_WINDOW (modest_platform_get_account_settings_wizard ());
224 modest_window_mgr_set_modal (modest_runtime_get_window_mgr(), GTK_WINDOW (wizard), (GtkWindow *) win);
226 /* always present a main window in the background
227 * we do it here, so we cannot end up with two wizards (as this
228 * function might be called in modest_window_mgr_get_main_window as well */
230 win = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr(),
231 TRUE); /* create if not existent */
233 gtk_window_set_transient_for (GTK_WINDOW (wizard), GTK_WINDOW (win));
235 /* make sure the mainwindow is visible. We need to present the
236 wizard again to give it the focus back. show_all are needed
237 in order to get the widgets properly drawn (MainWindow main
238 paned won't be in its right position and the dialog will be
240 #ifndef MODEST_TOOLKIT_HILDON2
241 gtk_widget_show_all (GTK_WIDGET (win));
242 gtk_widget_show_all (GTK_WIDGET (wizard));
243 gtk_window_present (GTK_WINDOW (win));
244 gtk_window_present (GTK_WINDOW (wizard));
247 dialog_response = gtk_dialog_run (GTK_DIALOG (wizard));
248 gtk_widget_destroy (GTK_WIDGET (wizard));
249 if (gtk_events_pending ())
250 gtk_main_iteration ();
252 if (dialog_response == GTK_RESPONSE_CANCEL) {
255 /* Check whether an account was created: */
256 result = modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
263 modest_ui_actions_on_about (GtkAction *action, ModestWindow *win)
266 const gchar *authors[] = {
267 "Dirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>",
270 about = gtk_about_dialog_new ();
271 gtk_about_dialog_set_name (GTK_ABOUT_DIALOG(about), PACKAGE_NAME);
272 gtk_about_dialog_set_version (GTK_ABOUT_DIALOG(about),PACKAGE_VERSION);
273 gtk_about_dialog_set_copyright (GTK_ABOUT_DIALOG(about),
274 _("Copyright (c) 2006, Nokia Corporation\n"
275 "All rights reserved."));
276 gtk_about_dialog_set_comments (GTK_ABOUT_DIALOG(about),
277 _("a modest e-mail client\n\n"
278 "design and implementation: Dirk-Jan C. Binnema\n"
279 "contributions from the fine people at KC and Ig\n"
280 "uses the tinymail email framework written by Philip van Hoof"));
281 gtk_about_dialog_set_authors (GTK_ABOUT_DIALOG(about), authors);
282 gtk_about_dialog_set_website (GTK_ABOUT_DIALOG(about), "http://modest.garage.maemo.org");
283 gtk_window_set_transient_for (GTK_WINDOW (about), GTK_WINDOW (win));
284 gtk_window_set_modal (GTK_WINDOW (about), TRUE);
286 gtk_dialog_run (GTK_DIALOG (about));
287 gtk_widget_destroy(about);
291 * Gets the list of currently selected messages. If the win is the
292 * main window, then it returns a newly allocated list of the headers
293 * selected in the header view. If win is the msg view window, then
294 * the value returned is a list with just a single header.
296 * The caller of this funcion must free the list.
299 get_selected_headers (ModestWindow *win)
301 if (MODEST_IS_MAIN_WINDOW(win)) {
302 GtkWidget *header_view;
304 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
305 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
306 return modest_header_view_get_selected_headers (MODEST_HEADER_VIEW(header_view));
308 } else if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
309 /* for MsgViewWindows, we simply return a list with one element */
311 TnyList *list = NULL;
313 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
314 if (header != NULL) {
315 list = tny_simple_list_new ();
316 tny_list_prepend (list, G_OBJECT(header));
317 g_object_unref (G_OBJECT(header));
322 #ifdef MODEST_TOOLKIT_HILDON2
323 } else if (MODEST_IS_HEADER_WINDOW (win)) {
324 GtkWidget *header_view;
326 header_view = GTK_WIDGET (modest_header_window_get_header_view (MODEST_HEADER_WINDOW (win)));
327 return modest_header_view_get_selected_headers (MODEST_HEADER_VIEW(header_view));
333 static GtkTreeRowReference *
334 get_next_after_selected_headers (ModestHeaderView *header_view)
336 GtkTreeSelection *sel;
337 GList *selected_rows, *node;
339 GtkTreeRowReference *result;
342 model = gtk_tree_view_get_model (GTK_TREE_VIEW (header_view));
343 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
344 selected_rows = gtk_tree_selection_get_selected_rows (sel, NULL);
346 if (selected_rows == NULL)
349 node = g_list_last (selected_rows);
350 path = gtk_tree_path_copy ((GtkTreePath *) node->data);
351 gtk_tree_path_next (path);
353 result = gtk_tree_row_reference_new (model, path);
355 gtk_tree_path_free (path);
356 g_list_foreach (selected_rows, (GFunc) gtk_tree_path_free, NULL);
357 g_list_free (selected_rows);
363 headers_action_mark_as_read (TnyHeader *header,
367 TnyHeaderFlags flags;
369 g_return_if_fail (TNY_IS_HEADER(header));
371 flags = tny_header_get_flags (header);
372 if (flags & TNY_HEADER_FLAG_SEEN) return;
373 tny_header_set_flag (header, TNY_HEADER_FLAG_SEEN);
377 headers_action_mark_as_unread (TnyHeader *header,
381 TnyHeaderFlags flags;
383 g_return_if_fail (TNY_IS_HEADER(header));
385 flags = tny_header_get_flags (header);
386 if (flags & TNY_HEADER_FLAG_SEEN) {
387 tny_header_unset_flag (header, TNY_HEADER_FLAG_SEEN);
391 /** After deleing a message that is currently visible in a window,
392 * show the next message from the list, or close the window if there are no more messages.
395 modest_ui_actions_refresh_message_window_after_delete (ModestMsgViewWindow* win)
397 /* Close msg view window or select next */
398 if (!modest_msg_view_window_select_next_message (win) &&
399 !modest_msg_view_window_select_previous_message (win)) {
401 g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value);
407 modest_ui_actions_on_delete_message (GtkAction *action, ModestWindow *win)
409 modest_ui_actions_on_edit_mode_delete_message (win);
413 modest_ui_actions_on_edit_mode_delete_message (ModestWindow *win)
415 TnyList *header_list = NULL;
416 TnyIterator *iter = NULL;
417 TnyHeader *header = NULL;
418 gchar *message = NULL;
421 ModestWindowMgr *mgr;
422 GtkWidget *header_view = NULL;
423 gboolean retval = TRUE;
425 g_return_val_if_fail (MODEST_IS_WINDOW(win), FALSE);
427 /* Check first if the header view has the focus */
428 if (MODEST_IS_MAIN_WINDOW (win)) {
430 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
431 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
432 if (!gtk_widget_is_focus (header_view))
436 /* Get the headers, either from the header view (if win is the main window),
437 * or from the message view window: */
438 header_list = get_selected_headers (win);
439 if (!header_list) return FALSE;
441 /* Check if any of the headers are already opened, or in the process of being opened */
442 if (MODEST_IS_MAIN_WINDOW (win)) {
443 gint opened_headers = 0;
445 iter = tny_list_create_iterator (header_list);
446 mgr = modest_runtime_get_window_mgr ();
447 while (!tny_iterator_is_done (iter)) {
448 header = TNY_HEADER (tny_iterator_get_current (iter));
450 if (modest_window_mgr_find_registered_header (mgr, header, NULL))
452 g_object_unref (header);
454 tny_iterator_next (iter);
456 g_object_unref (iter);
458 if (opened_headers > 0) {
461 msg = g_strdup_printf (_("mcen_nc_unable_to_delete_n_messages"),
464 modest_platform_run_information_dialog (GTK_WINDOW (win), (const gchar *) msg, FALSE);
467 g_object_unref (header_list);
473 if (tny_list_get_length(header_list) == 1) {
474 iter = tny_list_create_iterator (header_list);
475 header = TNY_HEADER (tny_iterator_get_current (iter));
478 subject = tny_header_dup_subject (header);
480 subject = g_strdup (_("mail_va_no_subject"));
481 desc = g_strdup_printf ("%s", subject);
483 g_object_unref (header);
486 g_object_unref (iter);
488 message = g_strdup_printf(ngettext("emev_nc_delete_message", "emev_nc_delete_messages",
489 tny_list_get_length(header_list)), desc);
491 /* Confirmation dialog */
492 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
496 if (response == GTK_RESPONSE_OK) {
497 ModestWindow *main_window = NULL;
498 ModestWindowMgr *mgr = NULL;
499 GtkTreeModel *model = NULL;
500 GtkTreeSelection *sel = NULL;
501 GList *sel_list = NULL, *tmp = NULL;
502 GtkTreeRowReference *next_row_reference = NULL;
503 GtkTreeRowReference *prev_row_reference = NULL;
504 GtkTreePath *next_path = NULL;
505 GtkTreePath *prev_path = NULL;
506 ModestMailOperation *mail_op = NULL;
508 /* Find last selected row */
509 if (MODEST_IS_MAIN_WINDOW (win)) {
510 model = gtk_tree_view_get_model (GTK_TREE_VIEW (header_view));
511 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
512 sel_list = gtk_tree_selection_get_selected_rows (sel, &model);
513 for (tmp=sel_list; tmp; tmp=tmp->next) {
514 if (tmp->next == NULL) {
515 prev_path = gtk_tree_path_copy((GtkTreePath *) tmp->data);
516 next_path = gtk_tree_path_copy((GtkTreePath *) tmp->data);
518 gtk_tree_path_prev (prev_path);
519 gtk_tree_path_next (next_path);
521 prev_row_reference = gtk_tree_row_reference_new (model, prev_path);
522 next_row_reference = gtk_tree_row_reference_new (model, next_path);
527 /* Disable window dimming management */
528 modest_window_disable_dimming (MODEST_WINDOW(win));
530 /* Remove each header. If it's a view window header_view == NULL */
531 mail_op = modest_mail_operation_new ((GObject *) win);
532 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
534 modest_mail_operation_remove_msgs (mail_op, header_list, FALSE);
535 g_object_unref (mail_op);
537 /* Enable window dimming management */
539 gtk_tree_selection_unselect_all (sel);
541 modest_window_enable_dimming (MODEST_WINDOW(win));
543 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
544 modest_ui_actions_refresh_message_window_after_delete (MODEST_MSG_VIEW_WINDOW (win));
546 /* Get main window */
547 mgr = modest_runtime_get_window_mgr ();
548 main_window = modest_window_mgr_get_main_window (mgr, FALSE); /* don't create */
549 } else if (MODEST_IS_MAIN_WINDOW (win)) {
550 /* Move cursor to next row */
553 /* Select next or previous row */
554 if (gtk_tree_row_reference_valid (next_row_reference)) {
555 gtk_tree_selection_select_path (sel, next_path);
557 else if (gtk_tree_row_reference_valid (prev_row_reference)) {
558 gtk_tree_selection_select_path (sel, prev_path);
562 if (gtk_tree_row_reference_valid (next_row_reference))
563 gtk_tree_row_reference_free (next_row_reference);
564 if (next_path != NULL)
565 gtk_tree_path_free (next_path);
566 if (gtk_tree_row_reference_valid (prev_row_reference))
567 gtk_tree_row_reference_free (prev_row_reference);
568 if (prev_path != NULL)
569 gtk_tree_path_free (prev_path);
572 /* Update toolbar dimming state */
574 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (main_window));
575 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
579 g_list_foreach (sel_list, (GFunc) gtk_tree_path_free, NULL);
580 g_list_free (sel_list);
589 g_object_unref (header_list);
597 /* delete either message or folder, based on where we are */
599 modest_ui_actions_on_delete_message_or_folder (GtkAction *action, ModestWindow *win)
601 g_return_if_fail (MODEST_IS_WINDOW(win));
603 /* Check first if the header view has the focus */
604 if (MODEST_IS_MAIN_WINDOW (win)) {
606 w = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
607 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
608 if (gtk_widget_is_focus (w)) {
609 modest_ui_actions_on_delete_folder (action, MODEST_WINDOW(win));
613 modest_ui_actions_on_delete_message (action, win);
617 modest_ui_actions_on_quit (GtkAction *action, ModestWindow *win)
619 ModestWindowMgr *mgr = NULL;
621 #ifdef MODEST_PLATFORM_MAEMO
622 modest_osso_save_state();
623 #endif /* MODEST_PLATFORM_MAEMO */
625 g_debug ("closing down, clearing %d item(s) from operation queue",
626 modest_mail_operation_queue_num_elements
627 (modest_runtime_get_mail_operation_queue()));
629 /* cancel all outstanding operations */
630 modest_mail_operation_queue_cancel_all
631 (modest_runtime_get_mail_operation_queue());
633 g_debug ("queue has been cleared");
636 /* Check if there are opened editing windows */
637 mgr = modest_runtime_get_window_mgr ();
638 modest_window_mgr_close_all_windows (mgr);
640 /* note: when modest-tny-account-store is finalized,
641 it will automatically set all network connections
644 /* gtk_main_quit (); */
648 modest_ui_actions_on_close_window (GtkAction *action, ModestWindow *win)
652 g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value);
654 /* if (MODEST_IS_MSG_VIEW_WINDOW (win)) { */
655 /* gtk_widget_destroy (GTK_WIDGET (win)); */
656 /* } else if (MODEST_IS_MSG_EDIT_WINDOW (win)) { */
657 /* gboolean ret_value; */
658 /* g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value); */
659 /* } else if (MODEST_IS_WINDOW (win)) { */
660 /* gtk_widget_destroy (GTK_WIDGET (win)); */
662 /* g_return_if_reached (); */
667 modest_ui_actions_add_to_contacts (GtkAction *action, ModestWindow *win)
669 g_return_if_fail (MODEST_IS_MSG_VIEW_WINDOW (win));
671 modest_msg_view_window_add_to_contacts (MODEST_MSG_VIEW_WINDOW (win));
675 modest_ui_actions_on_add_to_contacts (GtkAction *action, ModestWindow *win)
677 GtkClipboard *clipboard = NULL;
678 gchar *selection = NULL;
680 clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
681 selection = gtk_clipboard_wait_for_text (clipboard);
683 /* Question: why is the clipboard being used here?
684 * It doesn't really make a lot of sense. */
688 modest_address_book_add_address (selection);
694 modest_ui_actions_on_new_account (GtkAction *action,
695 ModestWindow *window)
697 modest_ui_actions_run_account_setup_wizard (window);
701 modest_ui_actions_on_accounts (GtkAction *action,
704 /* This is currently only implemented for Maemo */
705 if (!modest_account_mgr_has_accounts (modest_runtime_get_account_mgr(), TRUE)) {
706 if (!modest_ui_actions_run_account_setup_wizard (win))
707 g_debug ("%s: wizard was already running", __FUNCTION__);
711 /* Show the list of accounts */
712 GtkWindow *account_win = GTK_WINDOW (modest_account_view_window_new ());
714 /* The accounts dialog must be modal */
715 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (account_win), (GtkWindow *) win);
716 modest_utils_show_dialog_and_forget (GTK_WINDOW (win), GTK_DIALOG (account_win));
721 modest_ui_actions_on_smtp_servers (GtkAction *action, ModestWindow *win)
723 /* This is currently only implemented for Maemo,
724 * because it requires an API (libconic) to detect different connection
727 #ifndef MODEST_TOOLKIT_GTK /* Defined in config.h */
729 /* Create the window if necessary: */
730 GtkWidget *specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
731 modest_connection_specific_smtp_window_fill_with_connections (
732 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (specific_window),
733 modest_runtime_get_account_mgr());
735 /* Show the window: */
736 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (),
737 GTK_WINDOW (specific_window), (GtkWindow *) win);
738 gtk_widget_show (specific_window);
739 #endif /* !MODEST_TOOLKIT_GTK */
743 modest_ui_actions_compose_msg(ModestWindow *win,
746 const gchar *bcc_str,
747 const gchar *subject_str,
748 const gchar *body_str,
750 gboolean set_as_modified)
752 gchar *account_name = NULL;
754 TnyAccount *account = NULL;
755 TnyFolder *folder = NULL;
756 gchar *from_str = NULL, *signature = NULL, *body = NULL;
757 gboolean use_signature = FALSE;
758 ModestWindow *msg_win = NULL;
759 ModestAccountMgr *mgr = modest_runtime_get_account_mgr();
760 ModestTnyAccountStore *store = modest_runtime_get_account_store();
761 GnomeVFSFileSize total_size, allowed_size;
763 /* we check for low-mem */
764 if (modest_platform_check_memory_low (win, TRUE))
767 #ifdef MODEST_TOOLKIT_HILDON2
768 account_name = g_strdup (modest_window_get_active_account(win));
771 account_name = modest_account_mgr_get_default_account(mgr);
774 g_printerr ("modest: no account found\n");
777 account = modest_tny_account_store_get_server_account (store, account_name, TNY_ACCOUNT_TYPE_STORE);
779 g_printerr ("modest: failed to get tnyaccount for '%s'\n", account_name);
782 folder = modest_tny_account_get_special_folder (account, TNY_FOLDER_TYPE_DRAFTS);
784 g_printerr ("modest: failed to find Drafts folder\n");
787 from_str = modest_account_mgr_get_from_string (mgr, account_name);
789 g_printerr ("modest: failed get from string for '%s'\n", account_name);
793 signature = modest_account_mgr_get_signature (mgr, account_name, &use_signature);
794 if (body_str != NULL) {
795 body = use_signature ? g_strconcat(body_str, "\n--\n", signature, NULL) : g_strdup(body_str);
797 body = use_signature ? g_strconcat("\n--\n", signature, NULL) : g_strdup("");
800 msg = modest_tny_msg_new (to_str, from_str, cc_str, bcc_str, subject_str, body, NULL, NULL, NULL);
802 g_printerr ("modest: failed to create new msg\n");
806 /* Create and register edit window */
807 /* This is destroyed by TODO. */
809 allowed_size = MODEST_MAX_ATTACHMENT_SIZE;
810 msg_win = modest_msg_edit_window_new (msg, account_name, FALSE);
812 if (!modest_window_mgr_register_window (modest_runtime_get_window_mgr(), msg_win, win)) {
813 gtk_widget_destroy (GTK_WIDGET (msg_win));
816 modest_msg_edit_window_set_modified (MODEST_MSG_EDIT_WINDOW (msg_win), set_as_modified);
817 gtk_widget_show_all (GTK_WIDGET (msg_win));
819 while (attachments) {
821 modest_msg_edit_window_attach_file_one((ModestMsgEditWindow *)msg_win,
822 attachments->data, allowed_size);
824 if (total_size > allowed_size) {
825 g_warning ("%s: total size: %u",
826 __FUNCTION__, (unsigned int)total_size);
829 allowed_size -= total_size;
831 attachments = g_slist_next(attachments);
838 g_free (account_name);
840 g_object_unref (G_OBJECT(account));
842 g_object_unref (G_OBJECT(folder));
844 g_object_unref (G_OBJECT(msg));
848 modest_ui_actions_on_new_msg (GtkAction *action, ModestWindow *win)
850 /* if there are no accounts yet, just show the wizard */
851 if (!modest_account_mgr_has_accounts (modest_runtime_get_account_mgr(), TRUE))
852 if (!modest_ui_actions_run_account_setup_wizard (win))
855 modest_ui_actions_compose_msg(win, NULL, NULL, NULL, NULL, NULL, NULL, FALSE);
860 modest_ui_actions_msg_retrieval_check (ModestMailOperation *mail_op,
864 ModestMailOperationStatus status;
866 /* If there is no message or the operation was not successful */
867 status = modest_mail_operation_get_status (mail_op);
868 if (!msg || status != MODEST_MAIL_OPERATION_STATUS_SUCCESS) {
871 /* If it's a memory low issue, then show a banner */
872 error = modest_mail_operation_get_error (mail_op);
873 if (error && error->domain == MODEST_MAIL_OPERATION_ERROR &&
874 error->code == MODEST_MAIL_OPERATION_ERROR_LOW_MEMORY) {
875 GObject *source = modest_mail_operation_get_source (mail_op);
876 modest_platform_run_information_dialog (GTK_IS_WINDOW (source) ? GTK_WINDOW (source) : NULL,
877 _KR("memr_ib_operation_disabled"),
879 g_object_unref (source);
882 if (error && ((error->code == TNY_SERVICE_ERROR_NO_SUCH_MESSAGE) ||
883 error->code == TNY_SERVICE_ERROR_MESSAGE_NOT_AVAILABLE)) {
884 gchar *subject, *msg;
885 subject = tny_header_dup_subject (header);
887 subject = g_strdup (_("mail_va_no_subject"));;
888 msg = g_strdup_printf (_("emev_ni_ui_imap_message_not_available_in_server"),
890 modest_platform_run_information_dialog (NULL, msg, FALSE);
895 /* Remove the header from the preregistered uids */
896 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (),
914 OpenMsgBannerInfo *banner_info;
915 GtkTreeRowReference *rowref;
919 open_msg_banner_idle (gpointer userdata)
921 OpenMsgBannerInfo *banner_info = (OpenMsgBannerInfo *) userdata;
923 gdk_threads_enter ();
924 banner_info->idle_handler = 0;
925 banner_info->banner = modest_platform_animation_banner (NULL, NULL, banner_info->message);
927 g_object_ref (banner_info->banner);
929 gdk_threads_leave ();
936 get_header_view_from_window (ModestWindow *window)
938 GtkWidget *header_view;
940 if (MODEST_IS_MAIN_WINDOW (window)) {
941 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (window),
942 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
943 #ifdef MODEST_TOOLKIT_HILDON2
944 } else if (MODEST_IS_HEADER_WINDOW (window)){
945 header_view = GTK_WIDGET (modest_header_window_get_header_view (MODEST_HEADER_WINDOW (window)));
955 get_info_from_header (TnyHeader *header, gboolean *is_draft, gboolean *can_open)
958 gchar *account = NULL;
959 TnyFolderType folder_type = TNY_FOLDER_TYPE_UNKNOWN;
964 folder = tny_header_get_folder (header);
965 /* Gets folder type (OUTBOX headers will be opened in edit window */
966 if (modest_tny_folder_is_local_folder (folder)) {
967 folder_type = modest_tny_folder_get_local_or_mmc_folder_type (folder);
968 if (folder_type == TNY_FOLDER_TYPE_INVALID)
969 g_warning ("%s: BUG: TNY_FOLDER_TYPE_INVALID", __FUNCTION__);
972 if (folder_type == TNY_FOLDER_TYPE_OUTBOX) {
973 TnyTransportAccount *traccount = NULL;
974 ModestTnyAccountStore *accstore = modest_runtime_get_account_store();
975 traccount = modest_tny_account_store_get_transport_account_from_outbox_header(accstore, header);
977 ModestTnySendQueue *send_queue = NULL;
978 ModestTnySendQueueStatus status;
980 account = g_strdup(modest_tny_account_get_parent_modest_account_name_for_server_account(
981 TNY_ACCOUNT(traccount)));
982 send_queue = modest_runtime_get_send_queue(traccount, TRUE);
983 if (TNY_IS_SEND_QUEUE (send_queue)) {
984 msg_id = modest_tny_send_queue_get_msg_id (header);
985 status = modest_tny_send_queue_get_msg_status(send_queue, msg_id);
987 /* Only open messages in outbox with the editor if they are in Failed state */
988 if (status == MODEST_TNY_SEND_QUEUE_FAILED) {
991 #ifdef MODEST_TOOLKIT_HILDON2
993 /* In Fremantle we can not
994 open any message from
995 outbox which is not in
998 g_object_unref(traccount);
1002 g_object_unref(traccount);
1004 g_warning("Cannot get transport account for message in outbox!!");
1006 } else if (folder_type == TNY_FOLDER_TYPE_DRAFTS) {
1007 *is_draft = TRUE; /* Open in editor if the message is in the Drafts folder */
1011 TnyAccount *acc = tny_folder_get_account (folder);
1014 g_strdup (modest_tny_account_get_parent_modest_account_name_for_server_account (acc));
1015 g_object_unref (acc);
1019 g_object_unref (folder);
1025 open_msg_cb (ModestMailOperation *mail_op,
1032 ModestWindowMgr *mgr = NULL;
1033 ModestWindow *parent_win = NULL;
1034 ModestWindow *win = NULL;
1035 gchar *account = NULL;
1036 gboolean open_in_editor = FALSE;
1038 OpenMsgHelper *helper = (OpenMsgHelper *) user_data;
1040 /* Do nothing if there was any problem with the mail
1041 operation. The error will be shown by the error_handler of
1042 the mail operation */
1043 if (!modest_ui_actions_msg_retrieval_check (mail_op, header, msg))
1046 parent_win = (ModestWindow *) modest_mail_operation_get_source (mail_op);
1048 /* Mark header as read */
1049 headers_action_mark_as_read (header, MODEST_WINDOW(parent_win), NULL);
1051 account = get_info_from_header (header, &open_in_editor, &can_open);
1055 account = g_strdup (modest_window_get_active_account (MODEST_WINDOW (parent_win)));
1057 account = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
1059 if (open_in_editor) {
1060 ModestAccountMgr *mgr = modest_runtime_get_account_mgr ();
1061 gchar *from_header = NULL, *acc_name;
1063 from_header = tny_header_dup_from (header);
1065 /* we cannot edit without a valid account... */
1066 if (!modest_account_mgr_has_accounts(mgr, TRUE)) {
1067 if (!modest_ui_actions_run_account_setup_wizard(parent_win)) {
1068 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (),
1070 g_free (from_header);
1075 acc_name = modest_utils_get_account_name_from_recipient (from_header);
1076 g_free (from_header);
1082 win = modest_msg_edit_window_new (msg, account, TRUE);
1084 gchar *uid = modest_tny_folder_get_header_unique_id (header);
1086 if (helper->rowref && helper->model) {
1087 win = modest_msg_view_window_new_with_header_model (msg, account, (const gchar*) uid,
1088 helper->model, helper->rowref);
1090 win = modest_msg_view_window_new_for_attachment (msg, account, (const gchar*) uid);
1095 /* Register and show new window */
1097 mgr = modest_runtime_get_window_mgr ();
1098 if (!modest_window_mgr_register_window (mgr, win, NULL)) {
1099 gtk_widget_destroy (GTK_WIDGET (win));
1102 gtk_widget_show_all (GTK_WIDGET(win));
1105 /* Update toolbar dimming state */
1106 if (MODEST_IS_MAIN_WINDOW (parent_win)) {
1107 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (parent_win));
1113 g_object_unref (parent_win);
1117 is_memory_full_error (GError *error)
1119 gboolean enough_free_space = TRUE;
1120 GnomeVFSURI *cache_dir_uri;
1121 const gchar *cache_dir;
1122 GnomeVFSFileSize free_space;
1124 cache_dir = tny_account_store_get_cache_dir (TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()));
1125 cache_dir_uri = gnome_vfs_uri_new (cache_dir);
1126 if (gnome_vfs_get_volume_free_space (cache_dir_uri, &free_space) == GNOME_VFS_OK) {
1127 if (free_space < MIN_FREE_SPACE)
1128 enough_free_space = FALSE;
1130 gnome_vfs_uri_unref (cache_dir_uri);
1132 if ((error->code == TNY_SYSTEM_ERROR_MEMORY ||
1133 /* When asking for a mail and no space left on device
1134 tinymail returns this error */
1135 error->code == TNY_SERVICE_ERROR_MESSAGE_NOT_AVAILABLE ||
1136 /* When the folder summary could not be read or
1138 error->code == TNY_IO_ERROR_WRITE ||
1139 error->code == TNY_IO_ERROR_READ) &&
1140 !enough_free_space) {
1148 check_memory_full_error (GtkWidget *parent_window, GError *err)
1153 if (is_memory_full_error (err))
1154 modest_platform_information_banner (parent_window,
1155 NULL, _KR("cerm_device_memory_full"));
1156 else if (err->code == TNY_SYSTEM_ERROR_MEMORY)
1157 /* If the account was created in memory full
1158 conditions then tinymail won't be able to
1159 connect so it'll return this error code */
1160 modest_platform_information_banner (parent_window,
1161 NULL, _("emev_ui_imap_inbox_select_error"));
1169 modest_ui_actions_disk_operations_error_handler (ModestMailOperation *mail_op,
1172 const GError *error;
1173 GObject *win = NULL;
1174 ModestMailOperationStatus status;
1176 win = modest_mail_operation_get_source (mail_op);
1177 error = modest_mail_operation_get_error (mail_op);
1178 status = modest_mail_operation_get_status (mail_op);
1180 /* If the mail op has been cancelled then it's not an error:
1181 don't show any message */
1182 if (status != MODEST_MAIL_OPERATION_STATUS_CANCELED) {
1183 if (is_memory_full_error ((GError *) error)) {
1184 modest_platform_information_banner ((GtkWidget *) win,
1185 NULL, _KR("cerm_device_memory_full"));
1186 } else if (error->code == TNY_SYSTEM_ERROR_MEMORY) {
1187 modest_platform_information_banner ((GtkWidget *) win,
1188 NULL, _("emev_ui_imap_inbox_select_error"));
1189 } else if (error->domain == MODEST_MAIL_OPERATION_ERROR &&
1190 error->code == MODEST_MAIL_OPERATION_ERROR_FILE_IO) {
1191 modest_platform_information_banner ((GtkWidget *) win,
1192 NULL, _CS ("sfil_ni_unable_to_open_file_not_found"));
1193 } else if (user_data) {
1194 modest_platform_information_banner ((GtkWidget *) win,
1200 g_object_unref (win);
1204 * Returns the account a list of headers belongs to. It returns a
1205 * *new* reference so don't forget to unref it
1208 get_account_from_header_list (TnyList *headers)
1210 TnyAccount *account = NULL;
1212 if (tny_list_get_length (headers) > 0) {
1213 TnyIterator *iter = tny_list_create_iterator (headers);
1214 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter));
1215 TnyFolder *folder = tny_header_get_folder (header);
1218 g_object_unref (header);
1220 while (!tny_iterator_is_done (iter)) {
1221 header = TNY_HEADER (tny_iterator_get_current (iter));
1222 folder = tny_header_get_folder (header);
1225 g_object_unref (header);
1227 tny_iterator_next (iter);
1232 account = tny_folder_get_account (folder);
1233 g_object_unref (folder);
1237 g_object_unref (header);
1239 g_object_unref (iter);
1245 get_account_from_header (TnyHeader *header)
1247 TnyAccount *account = NULL;
1250 folder = tny_header_get_folder (header);
1253 account = tny_folder_get_account (folder);
1254 g_object_unref (folder);
1260 open_msg_helper_destroyer (gpointer user_data)
1262 OpenMsgHelper *helper = (OpenMsgHelper *) user_data;
1264 if (helper->banner_info) {
1265 g_free (helper->banner_info->message);
1266 if (helper->banner_info->idle_handler > 0) {
1267 g_source_remove (helper->banner_info->idle_handler);
1268 helper->banner_info->idle_handler = 0;
1270 if (helper->banner_info->banner != NULL) {
1271 gtk_widget_destroy (helper->banner_info->banner);
1272 g_object_unref (helper->banner_info->banner);
1273 helper->banner_info->banner = NULL;
1275 g_slice_free (OpenMsgBannerInfo, helper->banner_info);
1276 helper->banner_info = NULL;
1278 g_object_unref (helper->model);
1279 g_object_unref (helper->header);
1280 gtk_tree_row_reference_free (helper->rowref);
1281 g_slice_free (OpenMsgHelper, helper);
1285 open_msg_performer(gboolean canceled,
1287 GtkWindow *parent_window,
1288 TnyAccount *account,
1291 ModestMailOperation *mail_op = NULL;
1293 ModestProtocolType proto;
1294 TnyConnectionStatus status;
1295 OpenMsgHelper *helper = NULL;
1296 ModestProtocol *protocol;
1297 ModestProtocolRegistry *protocol_registry;
1300 helper = (OpenMsgHelper *) user_data;
1302 status = tny_account_get_connection_status (account);
1303 if (err || canceled) {
1304 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (), helper->header);
1305 /* Free the helper */
1306 open_msg_helper_destroyer (helper);
1308 /* In memory full conditions we could get this error here */
1309 check_memory_full_error ((GtkWidget *) parent_window, err);
1314 /* Get the error message depending on the protocol */
1315 proto = modest_tny_account_get_protocol_type (account);
1316 if (proto == MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1317 proto = MODEST_PROTOCOLS_STORE_MAILDIR;
1320 protocol_registry = modest_runtime_get_protocol_registry ();
1321 subject = tny_header_dup_subject (helper->header);
1323 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, proto);
1324 error_msg = modest_protocol_get_translation (protocol, MODEST_PROTOCOL_TRANSLATION_MSG_NOT_AVAILABLE, subject);
1328 if (error_msg == NULL) {
1329 error_msg = g_strdup (_("mail_ni_ui_folder_get_msg_folder_error"));
1332 #ifndef MODEST_TOOLKIT_HILDON2
1333 gboolean show_open_draft = FALSE;
1334 if (modest_protocol_registry_protocol_type_has_tag (protocol_registry,
1336 MODEST_PROTOCOL_REGISTRY_LOCAL_STORE_PROTOCOLS)) {
1338 TnyFolderType folder_type;
1340 folder = tny_header_get_folder (helper->header);
1341 folder_type = modest_tny_folder_get_local_or_mmc_folder_type (folder);
1342 show_open_draft = (folder_type == TNY_FOLDER_TYPE_DRAFTS);
1343 g_object_unref (folder);
1347 #ifdef MODEST_TOOLKIT_HILDON2
1350 gchar *account_name = get_info_from_header (helper->header, &is_draft, &can_open);
1353 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (), helper->header);
1354 g_free (account_name);
1355 open_msg_helper_destroyer (helper);
1360 ModestWindow *window;
1361 GtkWidget *header_view;
1364 header_view = get_header_view_from_window (MODEST_WINDOW (parent_window));
1365 uid = modest_tny_folder_get_header_unique_id (helper->header);
1367 window = modest_msg_view_window_new_from_header_view
1368 (MODEST_HEADER_VIEW (header_view), account_name, uid, helper->rowref);
1369 if (window != NULL) {
1370 if (!modest_window_mgr_register_window (modest_runtime_get_window_mgr (),
1372 gtk_widget_destroy (GTK_WIDGET (window));
1374 gtk_widget_show_all (GTK_WIDGET(window));
1378 g_free (account_name);
1380 open_msg_helper_destroyer (helper);
1383 g_free (account_name);
1385 /* Create the mail operation */
1387 modest_mail_operation_new_with_error_handling ((GObject *) parent_window,
1388 modest_ui_actions_disk_operations_error_handler,
1390 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
1394 #ifndef MODEST_TOOLKIT_HILDON2
1395 if (show_open_draft) {
1396 helper->banner_info = g_slice_new (OpenMsgBannerInfo);
1397 helper->banner_info->message = g_strdup (_("mail_ib_opening_draft_message"));
1398 helper->banner_info->banner = NULL;
1399 helper->banner_info->idle_handler = g_timeout_add (500, open_msg_banner_idle,
1400 helper->banner_info);
1406 headers = TNY_LIST (tny_simple_list_new ());
1407 tny_list_prepend (headers, G_OBJECT (helper->header));
1408 modest_mail_operation_get_msgs_full (mail_op,
1412 open_msg_helper_destroyer);
1413 g_object_unref (headers);
1418 g_object_unref (mail_op);
1419 g_object_unref (account);
1423 * This function is used by both modest_ui_actions_on_open and
1424 * modest_ui_actions_on_header_activated. This way we always do the
1425 * same when trying to open messages.
1428 open_msg_from_header (TnyHeader *header, GtkTreeRowReference *rowref, ModestWindow *win)
1430 ModestWindowMgr *mgr = NULL;
1431 TnyAccount *account;
1432 gboolean cached = FALSE;
1434 GtkWidget *header_view = NULL;
1435 OpenMsgHelper *helper;
1436 ModestWindow *window;
1438 g_return_if_fail (header != NULL && rowref != NULL);
1440 mgr = modest_runtime_get_window_mgr ();
1443 header_view = get_header_view_from_window (MODEST_WINDOW (win));
1444 if (header_view == NULL)
1447 /* Get the account */
1448 account = get_account_from_header (header);
1453 found = modest_window_mgr_find_registered_header (mgr, header, &window);
1455 /* Do not open again the message and present the
1456 window to the user */
1459 #ifndef MODEST_TOOLKIT_HILDON2
1460 gtk_window_present (GTK_WINDOW (window));
1463 /* the header has been registered already, we don't do
1464 * anything but wait for the window to come up*/
1465 g_debug ("header %p already registered, waiting for window", header);
1470 /* Open each message */
1471 cached = tny_header_get_flags (header) & TNY_HEADER_FLAG_CACHED;
1473 /* Allways download if we are online. */
1474 if (!tny_device_is_online (modest_runtime_get_device ())) {
1477 /* If ask for user permission to download the messages */
1478 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
1479 _("mcen_nc_get_msg"));
1481 /* End if the user does not want to continue */
1482 if (response == GTK_RESPONSE_CANCEL) {
1488 /* We register the window for opening */
1489 modest_window_mgr_register_header (mgr, header, NULL);
1491 /* Create the helper. We need to get a reference to the model
1492 here because it could change while the message is readed
1493 (the user could switch between folders) */
1494 helper = g_slice_new (OpenMsgHelper);
1495 helper->model = g_object_ref (gtk_tree_view_get_model (GTK_TREE_VIEW (header_view)));
1496 helper->header = g_object_ref (header);
1497 helper->rowref = gtk_tree_row_reference_copy (rowref);
1498 helper->banner_info = NULL;
1500 /* Connect to the account and perform */
1502 modest_platform_connect_and_perform ((GtkWindow *) win, TRUE, g_object_ref (account),
1503 open_msg_performer, helper);
1505 /* Call directly the performer, do not need to connect */
1506 open_msg_performer (FALSE, NULL, (GtkWindow *) win,
1507 g_object_ref (account), helper);
1512 g_object_unref (account);
1516 modest_ui_actions_on_open (GtkAction *action, ModestWindow *win)
1523 /* we check for low-mem; in that case, show a warning, and don't allow
1526 if (modest_platform_check_memory_low (MODEST_WINDOW(win), TRUE))
1530 headers = get_selected_headers (win);
1534 headers_count = tny_list_get_length (headers);
1535 if (headers_count != 1) {
1536 if (headers_count > 1) {
1537 /* Don't allow activation if there are more than one message selected */
1538 modest_platform_information_banner (NULL, NULL, _("mcen_ib_select_one_message"));
1541 g_object_unref (headers);
1545 iter = tny_list_create_iterator (headers);
1546 header = TNY_HEADER (tny_iterator_get_current (iter));
1547 g_object_unref (iter);
1551 open_msg_from_header (header, NULL, win);
1552 g_object_unref (header);
1555 g_object_unref(headers);
1559 rf_helper_window_closed (gpointer data,
1562 ReplyForwardHelper *helper = (ReplyForwardHelper *) data;
1564 helper->parent_window = NULL;
1567 static ReplyForwardHelper*
1568 create_reply_forward_helper (ReplyForwardAction action,
1570 guint reply_forward_type,
1573 ReplyForwardHelper *rf_helper = NULL;
1574 const gchar *active_acc = modest_window_get_active_account (win);
1576 rf_helper = g_slice_new0 (ReplyForwardHelper);
1577 rf_helper->reply_forward_type = reply_forward_type;
1578 rf_helper->action = action;
1579 rf_helper->parent_window = (MODEST_IS_WINDOW (win)) ? GTK_WIDGET (win) : NULL;
1580 rf_helper->header = (header) ? g_object_ref (header) : NULL;
1581 rf_helper->account_name = (active_acc) ?
1582 g_strdup (active_acc) :
1583 modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
1585 /* Note that window could be destroyed just AFTER calling
1586 register_window so we must ensure that this pointer does
1587 not hold invalid references */
1588 if (rf_helper->parent_window)
1589 g_object_weak_ref (G_OBJECT (rf_helper->parent_window),
1590 rf_helper_window_closed, rf_helper);
1596 free_reply_forward_helper (gpointer data)
1598 ReplyForwardHelper *helper;
1600 helper = (ReplyForwardHelper *) data;
1601 g_free (helper->account_name);
1603 g_object_unref (helper->header);
1604 if (helper->parent_window)
1605 g_object_weak_unref (G_OBJECT (helper->parent_window),
1606 rf_helper_window_closed, helper);
1607 g_slice_free (ReplyForwardHelper, helper);
1611 reply_forward_cb (ModestMailOperation *mail_op,
1618 TnyMsg *new_msg = NULL;
1619 ReplyForwardHelper *rf_helper;
1620 ModestWindow *msg_win = NULL;
1621 ModestEditType edit_type;
1623 TnyAccount *account = NULL;
1624 ModestWindowMgr *mgr = NULL;
1625 gchar *signature = NULL;
1626 gboolean use_signature;
1628 /* If there was any error. The mail operation could be NULL,
1629 this means that we already have the message downloaded and
1630 that we didn't do a mail operation to retrieve it */
1631 rf_helper = (ReplyForwardHelper *) user_data;
1632 if (mail_op && !modest_ui_actions_msg_retrieval_check (mail_op, header, msg))
1635 from = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(),
1636 rf_helper->account_name);
1637 signature = modest_account_mgr_get_signature (modest_runtime_get_account_mgr(),
1638 rf_helper->account_name,
1641 /* Create reply mail */
1642 switch (rf_helper->action) {
1645 modest_tny_msg_create_reply_msg (msg, header, from,
1646 (use_signature) ? signature : NULL,
1647 rf_helper->reply_forward_type,
1648 MODEST_TNY_MSG_REPLY_MODE_SENDER);
1650 case ACTION_REPLY_TO_ALL:
1652 modest_tny_msg_create_reply_msg (msg, header, from,
1653 (use_signature) ? signature : NULL,
1654 rf_helper->reply_forward_type,
1655 MODEST_TNY_MSG_REPLY_MODE_ALL);
1656 edit_type = MODEST_EDIT_TYPE_REPLY;
1658 case ACTION_FORWARD:
1660 modest_tny_msg_create_forward_msg (msg, from, (use_signature) ? signature : NULL,
1661 rf_helper->reply_forward_type);
1662 edit_type = MODEST_EDIT_TYPE_FORWARD;
1665 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (),
1667 g_return_if_reached ();
1675 g_warning ("%s: failed to create message\n", __FUNCTION__);
1679 account = modest_tny_account_store_get_server_account (modest_runtime_get_account_store(),
1680 rf_helper->account_name,
1681 TNY_ACCOUNT_TYPE_STORE);
1683 g_warning ("%s: failed to get tnyaccount for '%s'\n", __FUNCTION__, rf_helper->account_name);
1687 /* Create and register the windows */
1688 msg_win = modest_msg_edit_window_new (new_msg, rf_helper->account_name, FALSE);
1689 mgr = modest_runtime_get_window_mgr ();
1690 modest_window_mgr_register_window (mgr, msg_win, (ModestWindow *) rf_helper->parent_window);
1692 /* Note that register_window could have deleted the account */
1693 if (MODEST_IS_WINDOW (rf_helper->parent_window)) {
1694 gdouble parent_zoom;
1696 parent_zoom = modest_window_get_zoom (MODEST_WINDOW (rf_helper->parent_window));
1697 modest_window_set_zoom (msg_win, parent_zoom);
1700 /* Show edit window */
1701 gtk_widget_show_all (GTK_WIDGET (msg_win));
1704 /* We always unregister the header because the message is
1705 forwarded or replied so the original one is no longer
1707 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (),
1710 g_object_unref (G_OBJECT (new_msg));
1712 g_object_unref (G_OBJECT (account));
1713 free_reply_forward_helper (rf_helper);
1716 /* Checks a list of headers. If any of them are not currently
1717 * downloaded (CACHED) then returns TRUE else returns FALSE.
1720 header_list_count_uncached_msgs (TnyList *header_list)
1723 gint uncached_messages = 0;
1725 iter = tny_list_create_iterator (header_list);
1726 while (!tny_iterator_is_done (iter)) {
1729 header = TNY_HEADER (tny_iterator_get_current (iter));
1731 if (!(tny_header_get_flags (header) & TNY_HEADER_FLAG_CACHED))
1732 uncached_messages ++;
1733 g_object_unref (header);
1736 tny_iterator_next (iter);
1738 g_object_unref (iter);
1740 return uncached_messages;
1743 /* Returns FALSE if the user does not want to download the
1744 * messages. Returns TRUE if the user allowed the download.
1747 connect_to_get_msg (ModestWindow *win,
1748 gint num_of_uncached_msgs,
1749 TnyAccount *account)
1751 GtkResponseType response;
1753 /* Allways download if we are online. */
1754 if (tny_device_is_online (modest_runtime_get_device ()))
1757 /* If offline, then ask for user permission to download the messages */
1758 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
1759 ngettext("mcen_nc_get_msg",
1761 num_of_uncached_msgs));
1763 if (response == GTK_RESPONSE_CANCEL)
1766 return modest_platform_connect_and_wait((GtkWindow *) win, account);
1770 reply_forward_performer (gboolean canceled,
1772 GtkWindow *parent_window,
1773 TnyAccount *account,
1776 ReplyForwardHelper *rf_helper = NULL;
1777 ModestMailOperation *mail_op;
1779 rf_helper = (ReplyForwardHelper *) user_data;
1781 if (canceled || err) {
1782 free_reply_forward_helper (rf_helper);
1786 /* Retrieve the message */
1787 modest_window_mgr_register_header (modest_runtime_get_window_mgr (), rf_helper->header, NULL);
1788 mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT (parent_window),
1789 modest_ui_actions_disk_operations_error_handler,
1791 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
1792 modest_mail_operation_get_msg (mail_op, rf_helper->header, TRUE, reply_forward_cb, rf_helper);
1795 g_object_unref(mail_op);
1799 * Common code for the reply and forward actions
1802 reply_forward (ReplyForwardAction action, ModestWindow *win)
1804 ReplyForwardHelper *rf_helper = NULL;
1805 guint reply_forward_type;
1807 g_return_if_fail (MODEST_IS_WINDOW(win));
1809 /* we check for low-mem; in that case, show a warning, and don't allow
1810 * reply/forward (because it could potentially require a lot of memory */
1811 if (modest_platform_check_memory_low (MODEST_WINDOW(win), TRUE))
1815 /* we need an account when editing */
1816 if (!modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE)) {
1817 if (!modest_ui_actions_run_account_setup_wizard (win))
1821 reply_forward_type =
1822 modest_conf_get_int (modest_runtime_get_conf (),
1823 (action == ACTION_FORWARD) ?
1824 MODEST_CONF_FORWARD_TYPE :
1825 MODEST_CONF_REPLY_TYPE,
1828 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
1830 TnyHeader *header = NULL;
1831 /* Get header and message. Do not free them here, the
1832 reply_forward_cb must do it */
1833 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW(win));
1834 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
1836 if (msg && header) {
1838 rf_helper = create_reply_forward_helper (action, win,
1839 reply_forward_type, header);
1840 reply_forward_cb (NULL, header, FALSE, msg, NULL, rf_helper);
1842 g_warning("%s: no message or header found in viewer\n", __FUNCTION__);
1846 g_object_unref (msg);
1848 g_object_unref (header);
1850 TnyHeader *header = NULL;
1852 gboolean do_retrieve = TRUE;
1853 TnyList *header_list = NULL;
1855 header_list = get_selected_headers (win);
1858 /* Check that only one message is selected for replying */
1859 if (tny_list_get_length (header_list) != 1) {
1860 modest_platform_information_banner ((win) ? GTK_WIDGET (win) : NULL,
1861 NULL, _("mcen_ib_select_one_message"));
1862 g_object_unref (header_list);
1866 /* Only reply/forward to one message */
1867 iter = tny_list_create_iterator (header_list);
1868 header = TNY_HEADER (tny_iterator_get_current (iter));
1869 g_object_unref (iter);
1871 /* Retrieve messages */
1872 do_retrieve = (action == ACTION_FORWARD) ||
1873 (reply_forward_type != MODEST_TNY_MSG_REPLY_TYPE_CITE);
1876 TnyAccount *account = NULL;
1877 TnyFolder *folder = NULL;
1878 gdouble download = TRUE;
1879 guint uncached_msgs = 0;
1881 folder = tny_header_get_folder (header);
1883 goto do_retrieve_frees;
1884 account = tny_folder_get_account (folder);
1886 goto do_retrieve_frees;
1888 uncached_msgs = header_list_count_uncached_msgs (header_list);
1890 if (uncached_msgs > 0) {
1891 /* Allways download if we are online. */
1892 if (!tny_device_is_online (modest_runtime_get_device ())) {
1895 /* If ask for user permission to download the messages */
1896 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
1897 ngettext("mcen_nc_get_msg",
1901 /* End if the user does not want to continue */
1902 if (response == GTK_RESPONSE_CANCEL)
1909 rf_helper = create_reply_forward_helper (action, win,
1910 reply_forward_type, header);
1911 if (uncached_msgs > 0) {
1912 modest_platform_connect_and_perform (GTK_WINDOW (win),
1914 reply_forward_performer,
1917 reply_forward_performer (FALSE, NULL, GTK_WINDOW (win),
1918 account, rf_helper);
1923 g_object_unref (account);
1925 g_object_unref (folder);
1927 reply_forward_cb (NULL, header, FALSE, NULL, NULL, rf_helper);
1930 g_object_unref (header_list);
1931 g_object_unref (header);
1936 modest_ui_actions_on_reply (GtkAction *action, ModestWindow *win)
1938 g_return_if_fail (MODEST_IS_WINDOW(win));
1940 reply_forward (ACTION_REPLY, win);
1944 modest_ui_actions_on_forward (GtkAction *action, ModestWindow *win)
1946 g_return_if_fail (MODEST_IS_WINDOW(win));
1948 reply_forward (ACTION_FORWARD, win);
1952 modest_ui_actions_on_reply_all (GtkAction *action, ModestWindow *win)
1954 g_return_if_fail (MODEST_IS_WINDOW(win));
1956 reply_forward (ACTION_REPLY_TO_ALL, win);
1960 modest_ui_actions_on_next (GtkAction *action,
1961 ModestWindow *window)
1963 if (MODEST_IS_MAIN_WINDOW (window)) {
1964 GtkWidget *header_view;
1966 header_view = modest_main_window_get_child_widget (
1967 MODEST_MAIN_WINDOW(window),
1968 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1972 modest_header_view_select_next (
1973 MODEST_HEADER_VIEW(header_view));
1974 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
1975 modest_msg_view_window_select_next_message (
1976 MODEST_MSG_VIEW_WINDOW (window));
1978 g_return_if_reached ();
1983 modest_ui_actions_on_prev (GtkAction *action,
1984 ModestWindow *window)
1986 g_return_if_fail (MODEST_IS_WINDOW(window));
1988 if (MODEST_IS_MAIN_WINDOW (window)) {
1989 GtkWidget *header_view;
1990 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
1991 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1995 modest_header_view_select_prev (MODEST_HEADER_VIEW(header_view));
1996 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
1997 modest_msg_view_window_select_previous_message (MODEST_MSG_VIEW_WINDOW (window));
1999 g_return_if_reached ();
2004 modest_ui_actions_on_sort (GtkAction *action,
2005 ModestWindow *window)
2007 GtkWidget *header_view = NULL;
2009 g_return_if_fail (MODEST_IS_WINDOW(window));
2011 if (MODEST_IS_MAIN_WINDOW (window)) {
2012 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
2013 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2014 #ifdef MODEST_TOOLKIT_HILDON2
2015 } else if (MODEST_IS_HEADER_WINDOW (window)) {
2016 header_view = GTK_WIDGET (modest_header_window_get_header_view (MODEST_HEADER_WINDOW (window)));
2021 modest_platform_information_banner (NULL, NULL, _CS("ckdg_ib_nothing_to_sort"));
2026 /* Show sorting dialog */
2027 modest_utils_run_sort_dialog (GTK_WINDOW (window), MODEST_SORT_HEADERS);
2031 new_messages_arrived (ModestMailOperation *self,
2032 TnyList *new_headers,
2036 gboolean show_visual_notifications;
2038 source = modest_mail_operation_get_source (self);
2039 show_visual_notifications = (source) ? FALSE : TRUE;
2041 g_object_unref (source);
2043 /* Notify new messages have been downloaded. If the
2044 send&receive was invoked by the user then do not show any
2045 visual notification, only play a sound and activate the LED
2046 (for the Maemo version) */
2047 if (TNY_IS_LIST(new_headers) && (tny_list_get_length (new_headers)) > 0)
2048 modest_platform_on_new_headers_received (new_headers,
2049 show_visual_notifications);
2054 retrieve_all_messages_cb (GObject *source,
2056 guint retrieve_limit)
2062 window = GTK_WINDOW (source);
2063 msg = g_strdup_printf (_("mail_nc_msg_count_limit_exceeded"),
2064 num_msgs, retrieve_limit);
2066 /* Ask the user if they want to retrieve all the messages */
2068 modest_platform_run_confirmation_dialog_with_buttons (window, msg,
2069 _("mcen_bd_get_all"),
2070 _("mcen_bd_newest_only"));
2071 /* Free and return */
2073 return (response == GTK_RESPONSE_ACCEPT) ? TRUE : FALSE;
2077 TnyAccount *account;
2079 gchar *account_name;
2080 gboolean poke_status;
2081 gboolean interactive;
2082 ModestMailOperation *mail_op;
2086 do_send_receive_performer (gboolean canceled,
2088 GtkWindow *parent_window,
2089 TnyAccount *account,
2092 SendReceiveInfo *info;
2094 info = (SendReceiveInfo *) user_data;
2096 if (err || canceled) {
2097 /* In memory full conditions we could get this error here */
2098 check_memory_full_error ((GtkWidget *) parent_window, err);
2100 if (info->mail_op) {
2101 modest_mail_operation_queue_remove (modest_runtime_get_mail_operation_queue (),
2107 /* Set send/receive operation in progress */
2108 if (info->win && MODEST_IS_MAIN_WINDOW (info->win)) {
2109 modest_main_window_notify_send_receive_initied (MODEST_MAIN_WINDOW (info->win));
2112 if (info->win && MODEST_IS_MAIN_WINDOW (info->win))
2113 g_signal_connect (G_OBJECT (info->mail_op), "operation-finished",
2114 G_CALLBACK (on_send_receive_finished),
2117 /* Send & receive. */
2118 modest_mail_operation_update_account (info->mail_op, info->account_name, info->poke_status, info->interactive,
2119 (info->win) ? retrieve_all_messages_cb : NULL,
2120 new_messages_arrived, info->win);
2125 g_object_unref (G_OBJECT (info->mail_op));
2126 if (info->account_name)
2127 g_free (info->account_name);
2129 g_object_unref (info->win);
2131 g_object_unref (info->account);
2132 g_slice_free (SendReceiveInfo, info);
2136 * This function performs the send & receive required actions. The
2137 * window is used to create the mail operation. Typically it should
2138 * always be the main window, but we pass it as argument in order to
2142 modest_ui_actions_do_send_receive (const gchar *account_name,
2143 gboolean force_connection,
2144 gboolean poke_status,
2145 gboolean interactive,
2148 gchar *acc_name = NULL;
2149 SendReceiveInfo *info;
2150 ModestTnyAccountStore *acc_store;
2152 /* If no account name was provided then get the current account, and if
2153 there is no current account then pick the default one: */
2154 if (!account_name) {
2156 acc_name = g_strdup (modest_window_get_active_account (win));
2158 acc_name = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
2160 g_printerr ("modest: cannot get default account\n");
2164 acc_name = g_strdup (account_name);
2167 acc_store = modest_runtime_get_account_store ();
2169 /* Create the info for the connect and perform */
2170 info = g_slice_new (SendReceiveInfo);
2171 info->account_name = acc_name;
2172 info->win = (win) ? g_object_ref (win) : NULL;
2173 info->poke_status = poke_status;
2174 info->interactive = interactive;
2175 info->account = modest_tny_account_store_get_server_account (acc_store, acc_name,
2176 TNY_ACCOUNT_TYPE_STORE);
2177 /* We need to create the operation here, because otherwise it
2178 could happen that the queue emits the queue-empty signal
2179 while we're trying to connect the account */
2180 info->mail_op = modest_mail_operation_new_with_error_handling ((info->win) ? G_OBJECT (info->win) : NULL,
2181 modest_ui_actions_disk_operations_error_handler,
2183 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), info->mail_op);
2185 /* Invoke the connect and perform */
2186 modest_platform_connect_and_perform ((win) ? GTK_WINDOW (win) : NULL,
2187 force_connection, info->account,
2188 do_send_receive_performer, info);
2193 modest_ui_actions_do_cancel_send (const gchar *account_name,
2196 TnyTransportAccount *transport_account;
2197 TnySendQueue *send_queue = NULL;
2198 GError *error = NULL;
2200 /* Get transport account */
2202 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
2203 (modest_runtime_get_account_store(),
2205 TNY_ACCOUNT_TYPE_TRANSPORT));
2206 if (!transport_account) {
2207 g_printerr ("modest: no transport account found for '%s'\n", account_name);
2212 send_queue = TNY_SEND_QUEUE (modest_runtime_get_send_queue (transport_account, TRUE));
2213 if (!TNY_IS_SEND_QUEUE(send_queue)) {
2214 g_set_error (&error, MODEST_MAIL_OPERATION_ERROR,
2215 MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND,
2216 "modest: could not find send queue for account\n");
2218 /* Cancel the current send */
2219 tny_account_cancel (TNY_ACCOUNT (transport_account));
2221 /* Suspend all pending messages */
2222 tny_send_queue_cancel (send_queue, TNY_SEND_QUEUE_CANCEL_ACTION_SUSPEND, &error);
2226 if (transport_account != NULL)
2227 g_object_unref (G_OBJECT (transport_account));
2231 modest_ui_actions_cancel_send_all (ModestWindow *win)
2233 GSList *account_names, *iter;
2235 account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
2238 iter = account_names;
2240 modest_ui_actions_do_cancel_send ((const char*) iter->data, win);
2241 iter = g_slist_next (iter);
2244 modest_account_mgr_free_account_names (account_names);
2245 account_names = NULL;
2249 modest_ui_actions_cancel_send (GtkAction *action, ModestWindow *win)
2252 /* Check if accounts exist */
2253 gboolean accounts_exist =
2254 modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
2256 /* If not, allow the user to create an account before trying to send/receive. */
2257 if (!accounts_exist)
2258 modest_ui_actions_on_accounts (NULL, win);
2260 /* Cancel all sending operaitons */
2261 modest_ui_actions_cancel_send_all (win);
2265 * Refreshes all accounts. This function will be used by automatic
2269 modest_ui_actions_do_send_receive_all (ModestWindow *win,
2270 gboolean force_connection,
2271 gboolean poke_status,
2272 gboolean interactive)
2274 GSList *account_names, *iter;
2276 account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
2279 iter = account_names;
2281 modest_ui_actions_do_send_receive ((const char*) iter->data,
2283 poke_status, interactive, win);
2284 iter = g_slist_next (iter);
2287 modest_account_mgr_free_account_names (account_names);
2288 account_names = NULL;
2292 * Handler of the click on Send&Receive button in the main toolbar
2295 modest_ui_actions_on_send_receive (GtkAction *action, ModestWindow *win)
2297 /* Check if accounts exist */
2298 gboolean accounts_exist;
2301 modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
2303 /* If not, allow the user to create an account before trying to send/receive. */
2304 if (!accounts_exist)
2305 modest_ui_actions_on_accounts (NULL, win);
2307 /* Refresh the current folder. The if is always TRUE it's just an extra check */
2308 if (MODEST_IS_MAIN_WINDOW (win)) {
2309 GtkWidget *folder_view;
2310 TnyFolderStore *folder_store;
2313 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
2314 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2318 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
2321 g_object_unref (folder_store);
2322 /* Refresh the active account. Force the connection if needed
2323 and poke the status of all folders */
2324 modest_ui_actions_do_send_receive (NULL, TRUE, TRUE, TRUE, win);
2325 #ifdef MODEST_TOOLKIT_HILDON2
2326 } else if (MODEST_IS_ACCOUNTS_WINDOW (win)) {
2327 modest_ui_actions_do_send_receive_all (win, TRUE, TRUE, TRUE);
2330 const gchar *active_account;
2331 active_account = modest_window_get_active_account (MODEST_WINDOW (win));
2333 modest_ui_actions_do_send_receive (active_account, TRUE, TRUE, TRUE, win);
2340 modest_ui_actions_toggle_header_list_view (GtkAction *action, ModestMainWindow *main_window)
2343 GtkWidget *header_view;
2345 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2347 header_view = modest_main_window_get_child_widget (main_window,
2348 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2352 conf = modest_runtime_get_conf ();
2354 /* what is saved/restored is depending on the style; thus; we save with
2355 * old style, then update the style, and restore for this new style
2357 modest_widget_memory_save (conf, G_OBJECT(header_view), MODEST_CONF_HEADER_VIEW_KEY);
2359 if (modest_header_view_get_style
2360 (MODEST_HEADER_VIEW(header_view)) == MODEST_HEADER_VIEW_STYLE_DETAILS)
2361 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
2362 MODEST_HEADER_VIEW_STYLE_TWOLINES);
2364 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
2365 MODEST_HEADER_VIEW_STYLE_DETAILS);
2367 modest_widget_memory_restore (conf, G_OBJECT(header_view),
2368 MODEST_CONF_HEADER_VIEW_KEY);
2373 modest_ui_actions_on_header_selected (ModestHeaderView *header_view,
2375 ModestMainWindow *main_window)
2377 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2378 g_return_if_fail (MODEST_IS_HEADER_VIEW (header_view));
2380 /* in the case the folder is empty, show the empty folder message and focus
2382 if (!header && gtk_widget_is_focus (GTK_WIDGET (header_view))) {
2383 if (modest_header_view_is_empty (header_view)) {
2384 TnyFolder *folder = modest_header_view_get_folder (header_view);
2385 GtkWidget *folder_view =
2386 modest_main_window_get_child_widget (main_window,
2387 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2388 if (folder != NULL) {
2389 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view), folder, FALSE);
2390 g_object_unref (folder);
2392 gtk_widget_grab_focus (GTK_WIDGET (folder_view));
2396 /* If no header has been selected then exit */
2401 if (!gtk_widget_is_focus (GTK_WIDGET(header_view)))
2402 gtk_widget_grab_focus (GTK_WIDGET(header_view));
2404 /* Update toolbar dimming state */
2405 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (main_window));
2406 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
2410 modest_ui_actions_on_header_activated (ModestHeaderView *header_view,
2413 ModestWindow *window)
2415 GtkWidget *open_widget;
2416 GtkTreeRowReference *rowref;
2418 g_return_if_fail (MODEST_IS_WINDOW(window));
2419 g_return_if_fail (MODEST_IS_HEADER_VIEW (header_view));
2420 g_return_if_fail (TNY_IS_HEADER (header));
2422 if (modest_header_view_count_selected_headers (header_view) > 1) {
2423 /* Don't allow activation if there are more than one message selected */
2424 modest_platform_information_banner (NULL, NULL, _("mcen_ib_select_one_message"));
2428 /* we check for low-mem; in that case, show a warning, and don't allow
2429 * activating headers
2431 if (modest_platform_check_memory_low (MODEST_WINDOW(window), TRUE))
2434 if (MODEST_IS_MAIN_WINDOW (window)) {
2435 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (window));
2436 open_widget = modest_window_get_action_widget (MODEST_WINDOW (window), "/MenuBar/EmailMenu/EmailOpenMenu");
2437 if (!GTK_WIDGET_IS_SENSITIVE (open_widget))
2441 rowref = gtk_tree_row_reference_new (gtk_tree_view_get_model (GTK_TREE_VIEW (header_view)), path);
2442 open_msg_from_header (header, rowref, MODEST_WINDOW (window));
2443 gtk_tree_row_reference_free (rowref);
2447 set_active_account_from_tny_account (TnyAccount *account,
2448 ModestWindow *window)
2450 const gchar *server_acc_name = tny_account_get_id (account);
2452 /* We need the TnyAccount provided by the
2453 account store because that is the one that
2454 knows the name of the Modest account */
2455 TnyAccount *modest_server_account = modest_server_account =
2456 modest_tny_account_store_get_tny_account_by (modest_runtime_get_account_store (),
2457 MODEST_TNY_ACCOUNT_STORE_QUERY_ID,
2459 if (!modest_server_account) {
2460 g_warning ("%s: could not get tny account\n", __FUNCTION__);
2464 /* Update active account, but only if it's not a pseudo-account */
2465 if ((!modest_tny_account_is_virtual_local_folders(modest_server_account)) &&
2466 (!modest_tny_account_is_memory_card_account(modest_server_account))) {
2467 const gchar *modest_acc_name =
2468 modest_tny_account_get_parent_modest_account_name_for_server_account (modest_server_account);
2469 if (modest_acc_name)
2470 modest_window_set_active_account (window, modest_acc_name);
2473 g_object_unref (modest_server_account);
2478 folder_refreshed_cb (ModestMailOperation *mail_op,
2482 ModestMainWindow *win = NULL;
2483 GtkWidget *folder_view;
2484 const GError *error;
2486 g_return_if_fail (TNY_IS_FOLDER (folder));
2488 win = MODEST_MAIN_WINDOW (user_data);
2490 /* Check if the operation failed due to memory low conditions */
2491 error = modest_mail_operation_get_error (mail_op);
2492 if (error && error->domain == MODEST_MAIL_OPERATION_ERROR &&
2493 error->code == MODEST_MAIL_OPERATION_ERROR_LOW_MEMORY) {
2494 modest_platform_run_information_dialog (GTK_WINDOW (win),
2495 _KR("memr_ib_operation_disabled"),
2501 modest_main_window_get_child_widget(win, MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2504 TnyFolderStore *current_folder;
2506 current_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
2507 if (current_folder) {
2508 gboolean different = ((TnyFolderStore *) folder != current_folder);
2509 g_object_unref (current_folder);
2515 /* Check if folder is empty and set headers view contents style */
2516 if (tny_folder_get_all_count (folder) == 0)
2517 modest_main_window_set_contents_style (win,
2518 MODEST_MAIN_WINDOW_CONTENTS_STYLE_EMPTY);
2523 modest_ui_actions_on_folder_selection_changed (ModestFolderView *folder_view,
2524 TnyFolderStore *folder_store,
2526 ModestMainWindow *main_window)
2529 GtkWidget *header_view;
2531 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2533 header_view = modest_main_window_get_child_widget(main_window,
2534 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2538 conf = modest_runtime_get_conf ();
2540 if (TNY_IS_ACCOUNT (folder_store)) {
2542 set_active_account_from_tny_account (TNY_ACCOUNT (folder_store), MODEST_WINDOW (main_window));
2544 /* Show account details */
2545 modest_main_window_set_contents_style (main_window, MODEST_MAIN_WINDOW_CONTENTS_STYLE_DETAILS);
2548 if (TNY_IS_FOLDER (folder_store) && selected) {
2549 TnyAccount *account;
2550 const gchar *account_name = NULL;
2552 /* Update the active account */
2553 account = modest_tny_folder_get_account (TNY_FOLDER (folder_store));
2555 set_active_account_from_tny_account (account, MODEST_WINDOW (main_window));
2557 modest_tny_account_get_parent_modest_account_name_for_server_account (account);
2558 g_object_unref (account);
2562 /* Set the header style by default, it could
2563 be changed later by the refresh callback to
2565 modest_main_window_set_contents_style (main_window,
2566 MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS);
2568 /* Set folder on header view. This function
2569 will call tny_folder_refresh_async so we
2570 pass a callback that will be called when
2571 finished. We use that callback to set the
2572 empty view if there are no messages */
2573 modest_header_view_set_folder (MODEST_HEADER_VIEW(header_view),
2574 TNY_FOLDER (folder_store),
2576 MODEST_WINDOW (main_window),
2577 folder_refreshed_cb,
2580 /* Restore configuration. We need to do this
2581 *after* the set_folder because the widget
2582 memory asks the header view about its
2584 modest_widget_memory_restore (modest_runtime_get_conf (),
2585 G_OBJECT(header_view),
2586 MODEST_CONF_HEADER_VIEW_KEY);
2588 /* No need to save the header view
2589 configuration for Maemo because it only
2590 saves the sorting stuff and that it's
2591 already being done by the sort
2592 dialog. Remove it when the GNOME version
2593 has the same behaviour */
2594 #ifdef MODEST_TOOLKIT_GTK
2595 if (modest_main_window_get_contents_style (main_window) ==
2596 MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS)
2597 modest_widget_memory_save (conf, G_OBJECT (header_view),
2598 MODEST_CONF_HEADER_VIEW_KEY);
2600 modest_header_view_clear (MODEST_HEADER_VIEW(header_view));
2604 /* Update dimming state */
2605 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (main_window));
2606 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
2610 modest_ui_actions_on_item_not_found (ModestHeaderView *header_view,ModestItemType type,
2617 item = (type == MODEST_ITEM_TYPE_FOLDER) ? "folder" : "message";
2619 online = tny_device_is_online (modest_runtime_get_device());
2622 /* already online -- the item is simply not there... */
2623 dialog = gtk_message_dialog_new (GTK_WINDOW (win),
2625 GTK_MESSAGE_WARNING,
2627 _("The %s you selected cannot be found"),
2629 gtk_dialog_add_button (GTK_DIALOG (dialog),_("mcen_bd_dialog_ok"), GTK_RESPONSE_ACCEPT);
2630 gtk_dialog_run (GTK_DIALOG(dialog));
2632 dialog = gtk_dialog_new_with_buttons (_("Connection requested"),
2635 _("mcen_bd_dialog_cancel"),
2636 GTK_RESPONSE_REJECT,
2637 _("mcen_bd_dialog_ok"),
2638 GTK_RESPONSE_ACCEPT,
2640 txt = g_strdup_printf (_("This %s is not available in offline mode.\n"
2641 "Do you want to get online?"), item);
2642 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
2643 gtk_label_new (txt), FALSE, FALSE, 0);
2644 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
2647 gtk_window_set_default_size (GTK_WINDOW(dialog), 300, 300);
2648 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
2649 /* TODO: Comment about why is this commented out: */
2650 /* modest_platform_connect_and_wait (); */
2653 gtk_widget_destroy (dialog);
2657 modest_ui_actions_on_msg_link_hover (ModestMsgView *msgview, const gchar* link,
2660 /* g_message ("%s %s", __FUNCTION__, link); */
2665 modest_ui_actions_on_msg_link_clicked (ModestMsgView *msgview, const gchar* link,
2668 modest_platform_activate_uri (link);
2672 modest_ui_actions_on_msg_link_contextual (ModestMsgView *msgview, const gchar* link,
2675 modest_platform_show_uri_popup (link);
2679 modest_ui_actions_on_msg_attachment_clicked (ModestMsgView *msgview, TnyMimePart *mime_part,
2682 /* we check for low-mem; in that case, show a warning, and don't allow
2683 * viewing attachments
2685 if (modest_platform_check_memory_low (MODEST_WINDOW(win), TRUE))
2688 modest_msg_view_window_view_attachment (MODEST_MSG_VIEW_WINDOW (win), mime_part);
2692 modest_ui_actions_on_msg_recpt_activated (ModestMsgView *msgview,
2693 const gchar *address,
2696 /* g_message ("%s %s", __FUNCTION__, address); */
2700 on_save_to_drafts_cb (ModestMailOperation *mail_op,
2701 TnyMsg *saved_draft,
2704 ModestMsgEditWindow *edit_window;
2706 /* TODO: in hildon 2 we have to dim and undim the header views while we're saving */
2707 #ifndef MODEST_TOOLKIT_HILDON2
2708 ModestMainWindow *win;
2710 /* FIXME. Make the header view sensitive again. This is a
2711 * temporary hack. See modest_ui_actions_on_save_to_drafts()
2713 win = MODEST_MAIN_WINDOW(modest_window_mgr_get_main_window(
2714 modest_runtime_get_window_mgr(), FALSE));
2716 GtkWidget *hdrview = modest_main_window_get_child_widget(
2717 win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2718 if (hdrview) gtk_widget_set_sensitive(hdrview, TRUE);
2722 edit_window = MODEST_MSG_EDIT_WINDOW (user_data);
2724 /* Set draft is there was no error */
2725 if (!modest_mail_operation_get_error (mail_op))
2726 modest_msg_edit_window_set_draft (edit_window, saved_draft);
2728 g_object_unref(edit_window);
2732 enough_space_for_message (ModestMsgEditWindow *edit_window,
2735 TnyAccountStore *acc_store;
2736 guint64 available_disk, expected_size;
2741 acc_store = TNY_ACCOUNT_STORE (modest_runtime_get_account_store());
2742 available_disk = modest_utils_get_available_space (NULL);
2743 modest_msg_edit_window_get_parts_size (edit_window, &parts_count, &parts_size);
2744 expected_size = modest_tny_msg_estimate_size (data->plain_body,
2749 /* Double check: memory full condition or message too big */
2750 if (available_disk < MIN_FREE_SPACE ||
2751 expected_size > available_disk) {
2753 modest_platform_information_banner (NULL, NULL,
2754 _KR("cerm_device_memory_full"));
2759 * djcb: if we're in low-memory state, we only allow for
2760 * saving messages smaller than
2761 * MODEST_MAX_LOW_MEMORY_MESSAGE_SIZE (see modest-defs.h) this
2762 * should still allow for sending anything critical...
2764 if ((expected_size > MODEST_MAX_LOW_MEMORY_MESSAGE_SIZE) &&
2765 modest_platform_check_memory_low (MODEST_WINDOW(edit_window), TRUE))
2769 * djcb: we also make sure that the attachments are smaller than the max size
2770 * this is for the case where we'd try to forward a message with attachments
2771 * bigger than our max allowed size, or sending an message from drafts which
2772 * somehow got past our checks when attaching.
2774 if (expected_size > MODEST_MAX_ATTACHMENT_SIZE) {
2775 modest_platform_run_information_dialog (
2776 GTK_WINDOW(edit_window),
2777 _KR("memr_ib_operation_disabled"),
2786 modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edit_window)
2788 TnyTransportAccount *transport_account;
2789 ModestMailOperation *mail_operation;
2791 gchar *account_name, *from;
2792 ModestAccountMgr *account_mgr;
2793 gboolean had_error = FALSE;
2794 ModestMainWindow *win = NULL;
2796 g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window), FALSE);
2798 data = modest_msg_edit_window_get_msg_data (edit_window);
2801 if (!enough_space_for_message (edit_window, data)) {
2802 modest_msg_edit_window_free_msg_data (edit_window, data);
2806 account_name = g_strdup (data->account_name);
2807 account_mgr = modest_runtime_get_account_mgr();
2809 account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
2811 account_name = modest_account_mgr_get_default_account (account_mgr);
2812 if (!account_name) {
2813 g_printerr ("modest: no account found\n");
2814 modest_msg_edit_window_free_msg_data (edit_window, data);
2818 if (!strcmp (account_name, MODEST_LOCAL_FOLDERS_ACCOUNT_ID)) {
2819 account_name = g_strdup (data->account_name);
2823 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
2824 (modest_runtime_get_account_store (),
2826 TNY_ACCOUNT_TYPE_TRANSPORT));
2827 if (!transport_account) {
2828 g_printerr ("modest: no transport account found for '%s'\n", account_name);
2829 g_free (account_name);
2830 modest_msg_edit_window_free_msg_data (edit_window, data);
2833 from = modest_account_mgr_get_from_string (account_mgr, account_name);
2835 /* Create the mail operation */
2836 mail_operation = modest_mail_operation_new_with_error_handling (NULL, modest_ui_actions_disk_operations_error_handler,
2838 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
2840 modest_mail_operation_save_to_drafts (mail_operation,
2852 data->priority_flags,
2853 on_save_to_drafts_cb,
2854 g_object_ref(edit_window));
2856 #ifdef MODEST_TOOLKIT_HILDON2
2857 /* In hildon2 we always show the information banner on saving to drafts.
2858 * It will be a system information banner in this case.
2860 gchar *text = g_strdup_printf (_("mail_va_saved_to_drafts"), _("mcen_me_folder_drafts"));
2861 modest_platform_information_banner (NULL, NULL, text);
2864 /* Use the main window as the parent of the banner, if the
2865 main window does not exist it won't be shown, if the parent
2866 window exists then it's properly shown. We don't use the
2867 editor window because it could be closed (save to drafts
2868 could happen after closing the window */
2869 win = (ModestMainWindow *)
2870 modest_window_mgr_get_main_window( modest_runtime_get_window_mgr(), FALSE);
2872 gchar *text = g_strdup_printf (_("mail_va_saved_to_drafts"), _("mcen_me_folder_drafts"));
2873 modest_platform_information_banner (GTK_WIDGET (win), NULL, text);
2877 modest_msg_edit_window_set_modified (edit_window, FALSE);
2881 g_free (account_name);
2882 g_object_unref (G_OBJECT (transport_account));
2883 g_object_unref (G_OBJECT (mail_operation));
2885 modest_msg_edit_window_free_msg_data (edit_window, data);
2888 * If the drafts folder is selected then make the header view
2889 * insensitive while the message is being saved to drafts
2890 * (it'll be sensitive again in on_save_to_drafts_cb()). This
2891 * is not very clean but it avoids letting the drafts folder
2892 * in an inconsistent state: the user could edit the message
2893 * being saved and undesirable things would happen.
2894 * In the average case the user won't notice anything at
2895 * all. In the worst case (the user is editing a really big
2896 * file from Drafts) the header view will be insensitive
2897 * during the saving process (10 or 20 seconds, depending on
2898 * the message). Anyway this is just a quick workaround: once
2899 * we find a better solution it should be removed
2900 * See NB#65125 (commend #18) for details.
2902 if (!had_error && win != NULL) {
2903 ModestFolderView *view = MODEST_FOLDER_VIEW(modest_main_window_get_child_widget(
2904 win, MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW));
2906 TnyFolder *folder = TNY_FOLDER(modest_folder_view_get_selected(view));
2908 if (modest_tny_folder_is_local_folder(folder)) {
2909 TnyFolderType folder_type;
2910 folder_type = modest_tny_folder_get_local_or_mmc_folder_type(folder);
2911 if (folder_type == TNY_FOLDER_TYPE_DRAFTS) {
2912 GtkWidget *hdrview = modest_main_window_get_child_widget(
2913 win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2914 if (hdrview) gtk_widget_set_sensitive(hdrview, FALSE);
2918 if (folder != NULL) g_object_unref(folder);
2925 /* For instance, when clicking the Send toolbar button when editing a message: */
2927 modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
2929 TnyTransportAccount *transport_account = NULL;
2930 gboolean had_error = FALSE;
2932 ModestAccountMgr *account_mgr;
2933 gchar *account_name;
2935 ModestMailOperation *mail_operation;
2937 g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window), TRUE);
2939 if (!modest_msg_edit_window_check_names (edit_window, TRUE))
2942 data = modest_msg_edit_window_get_msg_data (edit_window);
2945 if (!enough_space_for_message (edit_window, data)) {
2946 modest_msg_edit_window_free_msg_data (edit_window, data);
2950 account_mgr = modest_runtime_get_account_mgr();
2951 account_name = g_strdup (data->account_name);
2953 account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
2956 account_name = modest_account_mgr_get_default_account (account_mgr);
2958 if (!account_name) {
2959 modest_msg_edit_window_free_msg_data (edit_window, data);
2960 /* Run account setup wizard */
2961 if (!modest_ui_actions_run_account_setup_wizard (MODEST_WINDOW(edit_window))) {
2966 /* Get the currently-active transport account for this modest account: */
2967 if (strcmp (account_name, MODEST_LOCAL_FOLDERS_ACCOUNT_ID) != 0) {
2969 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
2970 (modest_runtime_get_account_store (),
2971 account_name, TNY_ACCOUNT_TYPE_TRANSPORT));
2974 if (!transport_account) {
2975 modest_msg_edit_window_free_msg_data (edit_window, data);
2976 /* Run account setup wizard */
2977 if (!modest_ui_actions_run_account_setup_wizard(MODEST_WINDOW(edit_window)))
2982 /* Create the mail operation */
2983 from = modest_account_mgr_get_from_string (account_mgr, account_name);
2984 mail_operation = modest_mail_operation_new_with_error_handling (NULL, modest_ui_actions_disk_operations_error_handler, NULL, NULL);
2985 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
2987 modest_mail_operation_send_new_mail (mail_operation,
2999 data->priority_flags);
3001 if (modest_mail_operation_get_status (mail_operation) == MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS)
3002 modest_platform_information_banner (NULL, NULL, _("mcen_ib_outbox_waiting_to_be_sent"));
3005 if (modest_mail_operation_get_error (mail_operation) != NULL) {
3006 const GError *error = modest_mail_operation_get_error (mail_operation);
3007 if (error->domain == MODEST_MAIL_OPERATION_ERROR &&
3008 error->code == MODEST_MAIL_OPERATION_ERROR_INSTANCE_CREATION_FAILED) {
3009 g_warning ("%s failed: %s\n", __FUNCTION__, (modest_mail_operation_get_error (mail_operation))->message);
3010 modest_platform_information_banner (NULL, NULL, _CS("sfil_ni_not_enough_memory"));
3017 g_free (account_name);
3018 g_object_unref (G_OBJECT (transport_account));
3019 g_object_unref (G_OBJECT (mail_operation));
3021 modest_msg_edit_window_free_msg_data (edit_window, data);
3024 modest_msg_edit_window_set_sent (edit_window, TRUE);
3026 /* Save settings and close the window: */
3027 modest_ui_actions_on_close_window (NULL, MODEST_WINDOW (edit_window));
3034 modest_ui_actions_on_toggle_bold (GtkToggleAction *action,
3035 ModestMsgEditWindow *window)
3037 ModestMsgEditFormatState *format_state = NULL;
3039 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3040 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
3042 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3045 format_state = modest_msg_edit_window_get_format_state (window);
3046 g_return_if_fail (format_state != NULL);
3048 format_state->bold = gtk_toggle_action_get_active (action);
3049 modest_msg_edit_window_set_format_state (window, format_state);
3050 g_free (format_state);
3055 modest_ui_actions_on_toggle_italics (GtkToggleAction *action,
3056 ModestMsgEditWindow *window)
3058 ModestMsgEditFormatState *format_state = NULL;
3060 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3061 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
3063 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3066 format_state = modest_msg_edit_window_get_format_state (window);
3067 g_return_if_fail (format_state != NULL);
3069 format_state->italics = gtk_toggle_action_get_active (action);
3070 modest_msg_edit_window_set_format_state (window, format_state);
3071 g_free (format_state);
3076 modest_ui_actions_on_toggle_bullets (GtkToggleAction *action,
3077 ModestMsgEditWindow *window)
3079 ModestMsgEditFormatState *format_state = NULL;
3081 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3082 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
3084 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3087 format_state = modest_msg_edit_window_get_format_state (window);
3088 g_return_if_fail (format_state != NULL);
3090 format_state->bullet = gtk_toggle_action_get_active (action);
3091 modest_msg_edit_window_set_format_state (window, format_state);
3092 g_free (format_state);
3097 modest_ui_actions_on_change_justify (GtkRadioAction *action,
3098 GtkRadioAction *selected,
3099 ModestMsgEditWindow *window)
3101 ModestMsgEditFormatState *format_state = NULL;
3102 GtkJustification value;
3104 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3106 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3109 value = gtk_radio_action_get_current_value (selected);
3111 format_state = modest_msg_edit_window_get_format_state (window);
3112 g_return_if_fail (format_state != NULL);
3114 format_state->justification = value;
3115 modest_msg_edit_window_set_format_state (window, format_state);
3116 g_free (format_state);
3120 modest_ui_actions_on_select_editor_color (GtkAction *action,
3121 ModestMsgEditWindow *window)
3123 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3124 g_return_if_fail (GTK_IS_ACTION (action));
3126 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3129 modest_msg_edit_window_select_color (window);
3133 modest_ui_actions_on_select_editor_background_color (GtkAction *action,
3134 ModestMsgEditWindow *window)
3136 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3137 g_return_if_fail (GTK_IS_ACTION (action));
3139 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3142 modest_msg_edit_window_select_background_color (window);
3146 modest_ui_actions_on_insert_image (GObject *object,
3147 ModestMsgEditWindow *window)
3149 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3152 if (modest_platform_check_memory_low (MODEST_WINDOW(window), TRUE))
3155 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3158 modest_msg_edit_window_insert_image (window);
3162 modest_ui_actions_on_attach_file (GtkAction *action,
3163 ModestMsgEditWindow *window)
3165 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3166 g_return_if_fail (GTK_IS_ACTION (action));
3168 if (modest_platform_check_memory_low (MODEST_WINDOW(window), TRUE))
3171 modest_msg_edit_window_offer_attach_file (window);
3175 modest_ui_actions_on_remove_attachments (GtkAction *action,
3176 ModestMsgEditWindow *window)
3178 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3180 modest_msg_edit_window_remove_attachments (window, NULL);
3184 #ifndef MODEST_TOOLKIT_GTK
3189 TnyFolderStore *folder;
3190 } CreateFolderHelper;
3193 show_create_folder_in_timeout (gpointer data)
3195 CreateFolderHelper *helper = (CreateFolderHelper *) data;
3197 /* Remove the timeout ASAP, we can not wait until the dialog
3198 is shown because it could take a lot of time and so the
3199 timeout could be called twice or more times */
3200 g_source_remove (helper->handler);
3202 gdk_threads_enter ();
3203 do_create_folder (helper->win, helper->folder, helper->name);
3204 gdk_threads_leave ();
3206 g_object_unref (helper->win);
3207 g_object_unref (helper->folder);
3208 g_free (helper->name);
3209 g_slice_free (CreateFolderHelper, helper);
3216 do_create_folder_cb (ModestMailOperation *mail_op,
3217 TnyFolderStore *parent_folder,
3218 TnyFolder *new_folder,
3221 gchar *suggested_name = (gchar *) user_data;
3222 GtkWindow *source_win = (GtkWindow *) modest_mail_operation_get_source (mail_op);
3224 if (modest_mail_operation_get_error (mail_op)) {
3226 /* Show an error. If there was some problem writing to
3227 disk, show it, otherwise show the generic folder
3228 create error. We do it here and not in an error
3229 handler because the call to do_create_folder will
3230 stop the main loop in a gtk_dialog_run and then,
3231 the message won't be shown until that dialog is
3233 modest_ui_actions_disk_operations_error_handler (mail_op,
3234 _("mail_in_ui_folder_create_error"));
3236 /* Try again. Do *NOT* show any error because the mail
3237 operations system will do it for us because we
3238 created the mail_op with new_with_error_handler */
3239 #ifndef MODEST_TOOLKIT_GTK
3240 CreateFolderHelper *helper;
3241 helper = g_slice_new0 (CreateFolderHelper);
3242 helper->name = g_strdup (suggested_name);
3243 helper->folder = g_object_ref (parent_folder);
3244 helper->win = g_object_ref (source_win);
3246 /* Ugly but neccesary stuff. The problem is that the
3247 dialog when is shown calls a function that destroys
3248 all the temporary windows, so the banner is
3250 helper->handler = g_timeout_add (2000, show_create_folder_in_timeout, helper);