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 dgettext("ke-recv","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)
958 gchar *account = NULL;
959 TnyFolderType folder_type = TNY_FOLDER_TYPE_UNKNOWN;
963 folder = tny_header_get_folder (header);
964 /* Gets folder type (OUTBOX headers will be opened in edit window */
965 if (modest_tny_folder_is_local_folder (folder)) {
966 folder_type = modest_tny_folder_get_local_or_mmc_folder_type (folder);
967 if (folder_type == TNY_FOLDER_TYPE_INVALID)
968 g_warning ("%s: BUG: TNY_FOLDER_TYPE_INVALID", __FUNCTION__);
971 if (folder_type == TNY_FOLDER_TYPE_OUTBOX) {
972 TnyTransportAccount *traccount = NULL;
973 ModestTnyAccountStore *accstore = modest_runtime_get_account_store();
974 traccount = modest_tny_account_store_get_transport_account_from_outbox_header(accstore, header);
976 ModestTnySendQueue *send_queue = NULL;
977 ModestTnySendQueueStatus status;
979 account = g_strdup(modest_tny_account_get_parent_modest_account_name_for_server_account(
980 TNY_ACCOUNT(traccount)));
981 send_queue = modest_runtime_get_send_queue(traccount, TRUE);
982 if (TNY_IS_SEND_QUEUE (send_queue)) {
983 msg_id = modest_tny_send_queue_get_msg_id (header);
984 status = modest_tny_send_queue_get_msg_status(send_queue, msg_id);
986 /* Only open messages in outbox with the editor if they are in Failed state */
987 if (status == MODEST_TNY_SEND_QUEUE_FAILED) {
990 #ifdef MODEST_TOOLKIT_HILDON2
992 /* In Fremantle we can not
993 open any message from
994 outbox which is not in
996 g_object_unref(traccount);
1000 g_object_unref(traccount);
1002 g_warning("Cannot get transport account for message in outbox!!");
1004 } else if (folder_type == TNY_FOLDER_TYPE_DRAFTS) {
1005 *is_draft = TRUE; /* Open in editor if the message is in the Drafts folder */
1008 g_object_unref (folder);
1014 open_msg_cb (ModestMailOperation *mail_op,
1021 ModestWindowMgr *mgr = NULL;
1022 ModestWindow *parent_win = NULL;
1023 ModestWindow *win = NULL;
1024 gchar *account = NULL;
1025 gboolean open_in_editor = FALSE;
1026 OpenMsgHelper *helper = (OpenMsgHelper *) user_data;
1028 /* Do nothing if there was any problem with the mail
1029 operation. The error will be shown by the error_handler of
1030 the mail operation */
1031 if (!modest_ui_actions_msg_retrieval_check (mail_op, header, msg))
1034 parent_win = (ModestWindow *) modest_mail_operation_get_source (mail_op);
1036 /* Mark header as read */
1037 headers_action_mark_as_read (header, MODEST_WINDOW(parent_win), NULL);
1039 account = get_info_from_header (header, &open_in_editor);
1043 account = g_strdup (modest_window_get_active_account (MODEST_WINDOW (parent_win)));
1045 account = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
1047 if (open_in_editor) {
1048 ModestAccountMgr *mgr = modest_runtime_get_account_mgr ();
1049 gchar *from_header = NULL, *acc_name;
1051 from_header = tny_header_dup_from (header);
1053 /* we cannot edit without a valid account... */
1054 if (!modest_account_mgr_has_accounts(mgr, TRUE)) {
1055 if (!modest_ui_actions_run_account_setup_wizard(parent_win)) {
1056 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (),
1058 g_free (from_header);
1063 acc_name = modest_utils_get_account_name_from_recipient (from_header);
1064 g_free (from_header);
1070 win = modest_msg_edit_window_new (msg, account, TRUE);
1072 gchar *uid = modest_tny_folder_get_header_unique_id (header);
1074 if (helper->rowref && helper->model) {
1075 win = modest_msg_view_window_new_with_header_model (msg, account, (const gchar*) uid,
1076 helper->model, helper->rowref);
1078 win = modest_msg_view_window_new_for_attachment (msg, account, (const gchar*) uid);
1083 /* Register and show new window */
1085 mgr = modest_runtime_get_window_mgr ();
1086 if (!modest_window_mgr_register_window (mgr, win, NULL)) {
1087 gtk_widget_destroy (GTK_WIDGET (win));
1090 gtk_widget_show_all (GTK_WIDGET(win));
1093 /* Update toolbar dimming state */
1094 if (MODEST_IS_MAIN_WINDOW (parent_win)) {
1095 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (parent_win));
1101 g_object_unref (parent_win);
1105 is_memory_full_error (GError *error)
1107 gboolean enough_free_space = TRUE;
1108 GnomeVFSURI *cache_dir_uri;
1109 const gchar *cache_dir;
1110 GnomeVFSFileSize free_space;
1112 cache_dir = tny_account_store_get_cache_dir (TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()));
1113 cache_dir_uri = gnome_vfs_uri_new (cache_dir);
1114 if (gnome_vfs_get_volume_free_space (cache_dir_uri, &free_space) == GNOME_VFS_OK) {
1115 if (free_space < MIN_FREE_SPACE)
1116 enough_free_space = FALSE;
1118 gnome_vfs_uri_unref (cache_dir_uri);
1120 if ((error->code == TNY_SYSTEM_ERROR_MEMORY ||
1121 /* When asking for a mail and no space left on device
1122 tinymail returns this error */
1123 error->code == TNY_SERVICE_ERROR_MESSAGE_NOT_AVAILABLE ||
1124 /* When the folder summary could not be read or
1126 error->code == TNY_IO_ERROR_WRITE ||
1127 error->code == TNY_IO_ERROR_READ) &&
1128 !enough_free_space) {
1136 check_memory_full_error (GtkWidget *parent_window, GError *err)
1141 if (is_memory_full_error (err))
1142 modest_platform_information_banner (parent_window,
1143 NULL, dgettext("ke-recv",
1144 "cerm_device_memory_full"));
1145 else if (err->code == TNY_SYSTEM_ERROR_MEMORY)
1146 /* If the account was created in memory full
1147 conditions then tinymail won't be able to
1148 connect so it'll return this error code */
1149 modest_platform_information_banner (parent_window,
1150 NULL, _("emev_ui_imap_inbox_select_error"));
1158 modest_ui_actions_disk_operations_error_handler (ModestMailOperation *mail_op,
1161 const GError *error;
1162 GObject *win = NULL;
1163 ModestMailOperationStatus status;
1165 win = modest_mail_operation_get_source (mail_op);
1166 error = modest_mail_operation_get_error (mail_op);
1167 status = modest_mail_operation_get_status (mail_op);
1169 /* If the mail op has been cancelled then it's not an error:
1170 don't show any message */
1171 if (status != MODEST_MAIL_OPERATION_STATUS_CANCELED) {
1172 if (is_memory_full_error ((GError *) error)) {
1173 modest_platform_information_banner ((GtkWidget *) win,
1174 NULL, dgettext("ke-recv",
1175 "cerm_device_memory_full"));
1176 } else if (error->code == TNY_SYSTEM_ERROR_MEMORY) {
1177 modest_platform_information_banner ((GtkWidget *) win,
1178 NULL, _("emev_ui_imap_inbox_select_error"));
1179 } else if (error->domain == MODEST_MAIL_OPERATION_ERROR &&
1180 error->code == MODEST_MAIL_OPERATION_ERROR_FILE_IO) {
1181 modest_platform_information_banner ((GtkWidget *) win,
1182 NULL, dgettext ("hildon-common-strings", "sfil_ni_unable_to_open_file_not_found"));
1183 } else if (user_data) {
1184 modest_platform_information_banner ((GtkWidget *) win,
1190 g_object_unref (win);
1194 * Returns the account a list of headers belongs to. It returns a
1195 * *new* reference so don't forget to unref it
1198 get_account_from_header_list (TnyList *headers)
1200 TnyAccount *account = NULL;
1202 if (tny_list_get_length (headers) > 0) {
1203 TnyIterator *iter = tny_list_create_iterator (headers);
1204 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter));
1205 TnyFolder *folder = tny_header_get_folder (header);
1208 g_object_unref (header);
1210 while (!tny_iterator_is_done (iter)) {
1211 header = TNY_HEADER (tny_iterator_get_current (iter));
1212 folder = tny_header_get_folder (header);
1215 g_object_unref (header);
1217 tny_iterator_next (iter);
1222 account = tny_folder_get_account (folder);
1223 g_object_unref (folder);
1227 g_object_unref (header);
1229 g_object_unref (iter);
1235 get_account_from_header (TnyHeader *header)
1237 TnyAccount *account = NULL;
1240 folder = tny_header_get_folder (header);
1243 account = tny_folder_get_account (folder);
1244 g_object_unref (folder);
1251 open_msg_helper_destroyer (gpointer user_data)
1253 OpenMsgHelper *helper = (OpenMsgHelper *) user_data;
1255 if (helper->banner_info) {
1256 g_free (helper->banner_info->message);
1257 if (helper->banner_info->idle_handler > 0) {
1258 g_source_remove (helper->banner_info->idle_handler);
1259 helper->banner_info->idle_handler = 0;
1261 if (helper->banner_info->banner != NULL) {
1262 gtk_widget_destroy (helper->banner_info->banner);
1263 g_object_unref (helper->banner_info->banner);
1264 helper->banner_info->banner = NULL;
1266 g_slice_free (OpenMsgBannerInfo, helper->banner_info);
1267 helper->banner_info = NULL;
1269 g_object_unref (helper->model);
1270 g_object_unref (helper->header);
1271 gtk_tree_row_reference_free (helper->rowref);
1272 g_slice_free (OpenMsgHelper, helper);
1276 open_msg_performer(gboolean canceled,
1278 GtkWindow *parent_window,
1279 TnyAccount *account,
1282 ModestMailOperation *mail_op = NULL;
1284 ModestProtocolType proto;
1285 TnyConnectionStatus status;
1286 gboolean show_open_draft = FALSE;
1287 OpenMsgHelper *helper = NULL;
1289 helper = (OpenMsgHelper *) user_data;
1291 status = tny_account_get_connection_status (account);
1292 if (err || canceled) {
1293 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (), helper->header);
1294 /* Free the helper */
1295 open_msg_helper_destroyer (helper);
1297 /* In memory full conditions we could get this error here */
1298 check_memory_full_error ((GtkWidget *) parent_window, err);
1303 /* Get the error message depending on the protocol */
1304 proto = modest_tny_account_get_protocol_type (account);
1305 if (proto == MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1306 proto = MODEST_PROTOCOLS_STORE_MAILDIR;
1309 ModestProtocol *protocol;
1310 ModestProtocolRegistry *protocol_registry;
1313 protocol_registry = modest_runtime_get_protocol_registry ();
1314 subject = tny_header_dup_subject (helper->header);
1316 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, proto);
1317 error_msg = modest_protocol_get_translation (protocol, MODEST_PROTOCOL_TRANSLATION_MSG_NOT_AVAILABLE, subject);
1321 if (error_msg == NULL) {
1322 error_msg = g_strdup (_("mail_ni_ui_folder_get_msg_folder_error"));
1325 if (modest_protocol_registry_protocol_type_has_tag (protocol_registry,
1327 MODEST_PROTOCOL_REGISTRY_LOCAL_STORE_PROTOCOLS)) {
1329 TnyFolderType folder_type;
1331 folder = tny_header_get_folder (helper->header);
1332 folder_type = modest_tny_folder_get_local_or_mmc_folder_type (folder);
1333 show_open_draft = (folder_type == TNY_FOLDER_TYPE_DRAFTS);
1334 g_object_unref (folder);
1337 #ifdef MODEST_TOOLKIT_HILDON2
1339 gchar *account_name = get_info_from_header (helper->header, &is_draft);
1342 ModestWindow *window;
1343 GtkWidget *header_view;
1346 header_view = get_header_view_from_window (MODEST_WINDOW (parent_window));
1347 uid = modest_tny_folder_get_header_unique_id (helper->header);
1349 window = modest_msg_view_window_new_from_header_view
1350 (MODEST_HEADER_VIEW (header_view), account_name, uid, helper->rowref);
1351 if (window != NULL) {
1352 if (!modest_window_mgr_register_window (modest_runtime_get_window_mgr (),
1354 gtk_widget_destroy (GTK_WIDGET (window));
1356 gtk_widget_show_all (GTK_WIDGET(window));
1360 g_free (account_name);
1362 open_msg_helper_destroyer (helper);
1365 g_free (account_name);
1367 /* Create the mail operation */
1369 modest_mail_operation_new_with_error_handling ((GObject *) parent_window,
1370 modest_ui_actions_disk_operations_error_handler,
1372 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
1375 if (show_open_draft) {
1376 helper->banner_info = g_slice_new (OpenMsgBannerInfo);
1377 #ifdef MODEST_TOOLKIT_HILDON2
1378 helper->banner_info->message = g_strdup (_("mail_me_opening"));
1380 helper->banner_info->message = g_strdup (_("mail_ib_opening_draft_message"));
1382 helper->banner_info->banner = NULL;
1383 helper->banner_info->idle_handler = g_timeout_add (500, open_msg_banner_idle,
1384 helper->banner_info);
1388 headers = TNY_LIST (tny_simple_list_new ());
1389 tny_list_prepend (headers, G_OBJECT (helper->header));
1390 modest_mail_operation_get_msgs_full (mail_op,
1394 open_msg_helper_destroyer);
1395 g_object_unref (headers);
1400 g_object_unref (mail_op);
1401 g_object_unref (account);
1405 * This function is used by both modest_ui_actions_on_open and
1406 * modest_ui_actions_on_header_activated. This way we always do the
1407 * same when trying to open messages.
1410 open_msg_from_header (TnyHeader *header, GtkTreeRowReference *rowref, ModestWindow *win)
1412 ModestWindowMgr *mgr = NULL;
1413 TnyAccount *account;
1414 gboolean cached = FALSE;
1416 GtkWidget *header_view = NULL;
1417 OpenMsgHelper *helper;
1418 ModestWindow *window;
1420 g_return_if_fail (header != NULL && rowref != NULL);
1422 mgr = modest_runtime_get_window_mgr ();
1425 header_view = get_header_view_from_window (MODEST_WINDOW (win));
1426 if (header_view == NULL)
1429 /* Get the account */
1430 account = get_account_from_header (header);
1435 found = modest_window_mgr_find_registered_header (mgr, header, &window);
1437 /* Do not open again the message and present the
1438 window to the user */
1441 #ifndef MODEST_TOOLKIT_HILDON2
1442 gtk_window_present (GTK_WINDOW (window));
1445 /* the header has been registered already, we don't do
1446 * anything but wait for the window to come up*/
1447 g_debug ("header %p already registered, waiting for window", header);
1452 /* Open each message */
1453 cached = tny_header_get_flags (header) & TNY_HEADER_FLAG_CACHED;
1455 /* Allways download if we are online. */
1456 if (!tny_device_is_online (modest_runtime_get_device ())) {
1459 /* If ask for user permission to download the messages */
1460 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
1461 _("mcen_nc_get_msg"));
1463 /* End if the user does not want to continue */
1464 if (response == GTK_RESPONSE_CANCEL) {
1470 /* We register the window for opening */
1471 modest_window_mgr_register_header (mgr, header, NULL);
1473 /* Create the helper. We need to get a reference to the model
1474 here because it could change while the message is readed
1475 (the user could switch between folders) */
1476 helper = g_slice_new (OpenMsgHelper);
1477 helper->model = g_object_ref (gtk_tree_view_get_model (GTK_TREE_VIEW (header_view)));
1478 helper->header = g_object_ref (header);
1479 helper->rowref = gtk_tree_row_reference_copy (rowref);
1480 helper->banner_info = NULL;
1482 /* Connect to the account and perform */
1484 modest_platform_connect_and_perform ((GtkWindow *) win, TRUE, g_object_ref (account),
1485 open_msg_performer, helper);
1487 /* Call directly the performer, do not need to connect */
1488 open_msg_performer (FALSE, NULL, (GtkWindow *) win,
1489 g_object_ref (account), helper);
1494 g_object_unref (account);
1498 modest_ui_actions_on_open (GtkAction *action, ModestWindow *win)
1505 /* we check for low-mem; in that case, show a warning, and don't allow
1508 if (modest_platform_check_memory_low (MODEST_WINDOW(win), TRUE))
1512 headers = get_selected_headers (win);
1516 headers_count = tny_list_get_length (headers);
1517 if (headers_count != 1) {
1518 if (headers_count > 1) {
1519 /* Don't allow activation if there are more than one message selected */
1520 modest_platform_information_banner (NULL, NULL, _("mcen_ib_select_one_message"));
1523 g_object_unref (headers);
1527 iter = tny_list_create_iterator (headers);
1528 header = TNY_HEADER (tny_iterator_get_current (iter));
1529 g_object_unref (iter);
1533 open_msg_from_header (header, NULL, win);
1534 g_object_unref (header);
1537 g_object_unref(headers);
1541 rf_helper_window_closed (gpointer data,
1544 ReplyForwardHelper *helper = (ReplyForwardHelper *) data;
1546 helper->parent_window = NULL;
1549 static ReplyForwardHelper*
1550 create_reply_forward_helper (ReplyForwardAction action,
1552 guint reply_forward_type,
1555 ReplyForwardHelper *rf_helper = NULL;
1556 const gchar *active_acc = modest_window_get_active_account (win);
1558 rf_helper = g_slice_new0 (ReplyForwardHelper);
1559 rf_helper->reply_forward_type = reply_forward_type;
1560 rf_helper->action = action;
1561 rf_helper->parent_window = (MODEST_IS_WINDOW (win)) ? GTK_WIDGET (win) : NULL;
1562 rf_helper->header = (header) ? g_object_ref (header) : NULL;
1563 rf_helper->account_name = (active_acc) ?
1564 g_strdup (active_acc) :
1565 modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
1567 /* Note that window could be destroyed just AFTER calling
1568 register_window so we must ensure that this pointer does
1569 not hold invalid references */
1570 if (rf_helper->parent_window)
1571 g_object_weak_ref (G_OBJECT (rf_helper->parent_window),
1572 rf_helper_window_closed, rf_helper);
1578 free_reply_forward_helper (gpointer data)
1580 ReplyForwardHelper *helper;
1582 helper = (ReplyForwardHelper *) data;
1583 g_free (helper->account_name);
1585 g_object_unref (helper->header);
1586 if (helper->parent_window)
1587 g_object_weak_unref (G_OBJECT (helper->parent_window),
1588 rf_helper_window_closed, helper);
1589 g_slice_free (ReplyForwardHelper, helper);
1593 reply_forward_cb (ModestMailOperation *mail_op,
1600 TnyMsg *new_msg = NULL;
1601 ReplyForwardHelper *rf_helper;
1602 ModestWindow *msg_win = NULL;
1603 ModestEditType edit_type;
1605 TnyAccount *account = NULL;
1606 ModestWindowMgr *mgr = NULL;
1607 gchar *signature = NULL;
1608 gboolean use_signature;
1610 /* If there was any error. The mail operation could be NULL,
1611 this means that we already have the message downloaded and
1612 that we didn't do a mail operation to retrieve it */
1613 rf_helper = (ReplyForwardHelper *) user_data;
1614 if (mail_op && !modest_ui_actions_msg_retrieval_check (mail_op, header, msg))
1617 from = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(),
1618 rf_helper->account_name);
1619 signature = modest_account_mgr_get_signature (modest_runtime_get_account_mgr(),
1620 rf_helper->account_name,
1623 /* Create reply mail */
1624 switch (rf_helper->action) {
1627 modest_tny_msg_create_reply_msg (msg, header, from,
1628 (use_signature) ? signature : NULL,
1629 rf_helper->reply_forward_type,
1630 MODEST_TNY_MSG_REPLY_MODE_SENDER);
1632 case ACTION_REPLY_TO_ALL:
1634 modest_tny_msg_create_reply_msg (msg, header, from,
1635 (use_signature) ? signature : NULL,
1636 rf_helper->reply_forward_type,
1637 MODEST_TNY_MSG_REPLY_MODE_ALL);
1638 edit_type = MODEST_EDIT_TYPE_REPLY;
1640 case ACTION_FORWARD:
1642 modest_tny_msg_create_forward_msg (msg, from, (use_signature) ? signature : NULL,
1643 rf_helper->reply_forward_type);
1644 edit_type = MODEST_EDIT_TYPE_FORWARD;
1647 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (),
1649 g_return_if_reached ();
1657 g_warning ("%s: failed to create message\n", __FUNCTION__);
1661 account = modest_tny_account_store_get_server_account (modest_runtime_get_account_store(),
1662 rf_helper->account_name,
1663 TNY_ACCOUNT_TYPE_STORE);
1665 g_warning ("%s: failed to get tnyaccount for '%s'\n", __FUNCTION__, rf_helper->account_name);
1669 /* Create and register the windows */
1670 msg_win = modest_msg_edit_window_new (new_msg, rf_helper->account_name, FALSE);
1671 mgr = modest_runtime_get_window_mgr ();
1672 modest_window_mgr_register_window (mgr, msg_win, (ModestWindow *) rf_helper->parent_window);
1674 /* Note that register_window could have deleted the account */
1675 if (MODEST_IS_WINDOW (rf_helper->parent_window)) {
1676 gdouble parent_zoom;
1678 parent_zoom = modest_window_get_zoom (MODEST_WINDOW (rf_helper->parent_window));
1679 modest_window_set_zoom (msg_win, parent_zoom);
1682 /* Show edit window */
1683 gtk_widget_show_all (GTK_WIDGET (msg_win));
1686 /* We always unregister the header because the message is
1687 forwarded or replied so the original one is no longer
1689 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (),
1692 g_object_unref (G_OBJECT (new_msg));
1694 g_object_unref (G_OBJECT (account));
1695 free_reply_forward_helper (rf_helper);
1698 /* Checks a list of headers. If any of them are not currently
1699 * downloaded (CACHED) then returns TRUE else returns FALSE.
1702 header_list_count_uncached_msgs (TnyList *header_list)
1705 gint uncached_messages = 0;
1707 iter = tny_list_create_iterator (header_list);
1708 while (!tny_iterator_is_done (iter)) {
1711 header = TNY_HEADER (tny_iterator_get_current (iter));
1713 if (!(tny_header_get_flags (header) & TNY_HEADER_FLAG_CACHED))
1714 uncached_messages ++;
1715 g_object_unref (header);
1718 tny_iterator_next (iter);
1720 g_object_unref (iter);
1722 return uncached_messages;
1725 /* Returns FALSE if the user does not want to download the
1726 * messages. Returns TRUE if the user allowed the download.
1729 connect_to_get_msg (ModestWindow *win,
1730 gint num_of_uncached_msgs,
1731 TnyAccount *account)
1733 GtkResponseType response;
1735 /* Allways download if we are online. */
1736 if (tny_device_is_online (modest_runtime_get_device ()))
1739 /* If offline, then ask for user permission to download the messages */
1740 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
1741 ngettext("mcen_nc_get_msg",
1743 num_of_uncached_msgs));
1745 if (response == GTK_RESPONSE_CANCEL)
1748 return modest_platform_connect_and_wait((GtkWindow *) win, account);
1752 reply_forward_performer (gboolean canceled,
1754 GtkWindow *parent_window,
1755 TnyAccount *account,
1758 ReplyForwardHelper *rf_helper = NULL;
1759 ModestMailOperation *mail_op;
1761 rf_helper = (ReplyForwardHelper *) user_data;
1763 if (canceled || err) {
1764 free_reply_forward_helper (rf_helper);
1768 /* Retrieve the message */
1769 modest_window_mgr_register_header (modest_runtime_get_window_mgr (), rf_helper->header, NULL);
1770 mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT (parent_window),
1771 modest_ui_actions_disk_operations_error_handler,
1773 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
1774 modest_mail_operation_get_msg (mail_op, rf_helper->header, TRUE, reply_forward_cb, rf_helper);
1777 g_object_unref(mail_op);
1781 * Common code for the reply and forward actions
1784 reply_forward (ReplyForwardAction action, ModestWindow *win)
1786 ReplyForwardHelper *rf_helper = NULL;
1787 guint reply_forward_type;
1789 g_return_if_fail (MODEST_IS_WINDOW(win));
1791 /* we check for low-mem; in that case, show a warning, and don't allow
1792 * reply/forward (because it could potentially require a lot of memory */
1793 if (modest_platform_check_memory_low (MODEST_WINDOW(win), TRUE))
1797 /* we need an account when editing */
1798 if (!modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE)) {
1799 if (!modest_ui_actions_run_account_setup_wizard (win))
1803 reply_forward_type =
1804 modest_conf_get_int (modest_runtime_get_conf (),
1805 (action == ACTION_FORWARD) ?
1806 MODEST_CONF_FORWARD_TYPE :
1807 MODEST_CONF_REPLY_TYPE,
1810 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
1812 TnyHeader *header = NULL;
1813 /* Get header and message. Do not free them here, the
1814 reply_forward_cb must do it */
1815 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW(win));
1816 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
1818 if (msg && header) {
1820 rf_helper = create_reply_forward_helper (action, win,
1821 reply_forward_type, header);
1822 reply_forward_cb (NULL, header, FALSE, msg, NULL, rf_helper);
1824 g_warning("%s: no message or header found in viewer\n", __FUNCTION__);
1828 g_object_unref (msg);
1830 g_object_unref (header);
1832 TnyHeader *header = NULL;
1834 gboolean do_retrieve = TRUE;
1835 TnyList *header_list = NULL;
1837 header_list = get_selected_headers (win);
1840 /* Check that only one message is selected for replying */
1841 if (tny_list_get_length (header_list) != 1) {
1842 modest_platform_information_banner ((win) ? GTK_WIDGET (win) : NULL,
1843 NULL, _("mcen_ib_select_one_message"));
1844 g_object_unref (header_list);
1848 /* Only reply/forward to one message */
1849 iter = tny_list_create_iterator (header_list);
1850 header = TNY_HEADER (tny_iterator_get_current (iter));
1851 g_object_unref (iter);
1853 /* Retrieve messages */
1854 do_retrieve = (action == ACTION_FORWARD) ||
1855 (reply_forward_type != MODEST_TNY_MSG_REPLY_TYPE_CITE);
1858 TnyAccount *account = NULL;
1859 TnyFolder *folder = NULL;
1860 gdouble download = TRUE;
1861 guint uncached_msgs = 0;
1863 folder = tny_header_get_folder (header);
1865 goto do_retrieve_frees;
1866 account = tny_folder_get_account (folder);
1868 goto do_retrieve_frees;
1870 uncached_msgs = header_list_count_uncached_msgs (header_list);
1872 if (uncached_msgs > 0) {
1873 /* Allways download if we are online. */
1874 if (!tny_device_is_online (modest_runtime_get_device ())) {
1877 /* If ask for user permission to download the messages */
1878 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
1879 ngettext("mcen_nc_get_msg",
1883 /* End if the user does not want to continue */
1884 if (response == GTK_RESPONSE_CANCEL)
1891 rf_helper = create_reply_forward_helper (action, win,
1892 reply_forward_type, header);
1893 if (uncached_msgs > 0) {
1894 modest_platform_connect_and_perform (GTK_WINDOW (win),
1896 reply_forward_performer,
1899 reply_forward_performer (FALSE, NULL, GTK_WINDOW (win),
1900 account, rf_helper);
1905 g_object_unref (account);
1907 g_object_unref (folder);
1909 reply_forward_cb (NULL, header, FALSE, NULL, NULL, rf_helper);
1912 g_object_unref (header_list);
1913 g_object_unref (header);
1918 modest_ui_actions_on_reply (GtkAction *action, ModestWindow *win)
1920 g_return_if_fail (MODEST_IS_WINDOW(win));
1922 reply_forward (ACTION_REPLY, win);
1926 modest_ui_actions_on_forward (GtkAction *action, ModestWindow *win)
1928 g_return_if_fail (MODEST_IS_WINDOW(win));
1930 reply_forward (ACTION_FORWARD, win);
1934 modest_ui_actions_on_reply_all (GtkAction *action, ModestWindow *win)
1936 g_return_if_fail (MODEST_IS_WINDOW(win));
1938 reply_forward (ACTION_REPLY_TO_ALL, win);
1942 modest_ui_actions_on_next (GtkAction *action,
1943 ModestWindow *window)
1945 if (MODEST_IS_MAIN_WINDOW (window)) {
1946 GtkWidget *header_view;
1948 header_view = modest_main_window_get_child_widget (
1949 MODEST_MAIN_WINDOW(window),
1950 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1954 modest_header_view_select_next (
1955 MODEST_HEADER_VIEW(header_view));
1956 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
1957 modest_msg_view_window_select_next_message (
1958 MODEST_MSG_VIEW_WINDOW (window));
1960 g_return_if_reached ();
1965 modest_ui_actions_on_prev (GtkAction *action,
1966 ModestWindow *window)
1968 g_return_if_fail (MODEST_IS_WINDOW(window));
1970 if (MODEST_IS_MAIN_WINDOW (window)) {
1971 GtkWidget *header_view;
1972 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
1973 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1977 modest_header_view_select_prev (MODEST_HEADER_VIEW(header_view));
1978 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
1979 modest_msg_view_window_select_previous_message (MODEST_MSG_VIEW_WINDOW (window));
1981 g_return_if_reached ();
1986 modest_ui_actions_on_sort (GtkAction *action,
1987 ModestWindow *window)
1989 GtkWidget *header_view = NULL;
1991 g_return_if_fail (MODEST_IS_WINDOW(window));
1993 if (MODEST_IS_MAIN_WINDOW (window)) {
1994 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
1995 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1996 #ifdef MODEST_TOOLKIT_HILDON2
1997 } else if (MODEST_IS_HEADER_WINDOW (window)) {
1998 header_view = GTK_WIDGET (modest_header_window_get_header_view (MODEST_HEADER_WINDOW (window)));
2003 modest_platform_information_banner (NULL, NULL, _CS("ckdg_ib_nothing_to_sort"));
2008 /* Show sorting dialog */
2009 modest_utils_run_sort_dialog (GTK_WINDOW (window), MODEST_SORT_HEADERS);
2013 new_messages_arrived (ModestMailOperation *self,
2014 TnyList *new_headers,
2018 gboolean show_visual_notifications;
2020 source = modest_mail_operation_get_source (self);
2021 show_visual_notifications = (source) ? FALSE : TRUE;
2023 g_object_unref (source);
2025 /* Notify new messages have been downloaded. If the
2026 send&receive was invoked by the user then do not show any
2027 visual notification, only play a sound and activate the LED
2028 (for the Maemo version) */
2029 if (TNY_IS_LIST(new_headers) && (tny_list_get_length (new_headers)) > 0)
2030 modest_platform_on_new_headers_received (new_headers,
2031 show_visual_notifications);
2036 retrieve_all_messages_cb (GObject *source,
2038 guint retrieve_limit)
2044 window = GTK_WINDOW (source);
2045 msg = g_strdup_printf (_("mail_nc_msg_count_limit_exceeded"),
2046 num_msgs, retrieve_limit);
2048 /* Ask the user if they want to retrieve all the messages */
2050 modest_platform_run_confirmation_dialog_with_buttons (window, msg,
2051 _("mcen_bd_get_all"),
2052 _("mcen_bd_newest_only"));
2053 /* Free and return */
2055 return (response == GTK_RESPONSE_ACCEPT) ? TRUE : FALSE;
2059 TnyAccount *account;
2061 gchar *account_name;
2062 gboolean poke_status;
2063 gboolean interactive;
2064 ModestMailOperation *mail_op;
2068 do_send_receive_performer (gboolean canceled,
2070 GtkWindow *parent_window,
2071 TnyAccount *account,
2074 SendReceiveInfo *info;
2076 info = (SendReceiveInfo *) user_data;
2078 if (err || canceled) {
2079 /* In memory full conditions we could get this error here */
2080 check_memory_full_error ((GtkWidget *) parent_window, err);
2082 if (info->mail_op) {
2083 modest_mail_operation_queue_remove (modest_runtime_get_mail_operation_queue (),
2089 /* Set send/receive operation in progress */
2090 if (info->win && MODEST_IS_MAIN_WINDOW (info->win)) {
2091 modest_main_window_notify_send_receive_initied (MODEST_MAIN_WINDOW (info->win));
2094 if (info->win && MODEST_IS_MAIN_WINDOW (info->win))
2095 g_signal_connect (G_OBJECT (info->mail_op), "operation-finished",
2096 G_CALLBACK (on_send_receive_finished),
2099 /* Send & receive. */
2100 modest_mail_operation_update_account (info->mail_op, info->account_name, info->poke_status, info->interactive,
2101 (info->win) ? retrieve_all_messages_cb : NULL,
2102 new_messages_arrived, info->win);
2107 g_object_unref (G_OBJECT (info->mail_op));
2108 if (info->account_name)
2109 g_free (info->account_name);
2111 g_object_unref (info->win);
2113 g_object_unref (info->account);
2114 g_slice_free (SendReceiveInfo, info);
2118 * This function performs the send & receive required actions. The
2119 * window is used to create the mail operation. Typically it should
2120 * always be the main window, but we pass it as argument in order to
2124 modest_ui_actions_do_send_receive (const gchar *account_name,
2125 gboolean force_connection,
2126 gboolean poke_status,
2127 gboolean interactive,
2130 gchar *acc_name = NULL;
2131 SendReceiveInfo *info;
2132 ModestTnyAccountStore *acc_store;
2134 /* If no account name was provided then get the current account, and if
2135 there is no current account then pick the default one: */
2136 if (!account_name) {
2138 acc_name = g_strdup (modest_window_get_active_account (win));
2140 acc_name = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
2142 g_printerr ("modest: cannot get default account\n");
2146 acc_name = g_strdup (account_name);
2149 acc_store = modest_runtime_get_account_store ();
2151 /* Create the info for the connect and perform */
2152 info = g_slice_new (SendReceiveInfo);
2153 info->account_name = acc_name;
2154 info->win = (win) ? g_object_ref (win) : NULL;
2155 info->poke_status = poke_status;
2156 info->interactive = interactive;
2157 info->account = modest_tny_account_store_get_server_account (acc_store, acc_name,
2158 TNY_ACCOUNT_TYPE_STORE);
2159 /* We need to create the operation here, because otherwise it
2160 could happen that the queue emits the queue-empty signal
2161 while we're trying to connect the account */
2162 info->mail_op = modest_mail_operation_new_with_error_handling ((info->win) ? G_OBJECT (info->win) : NULL,
2163 modest_ui_actions_disk_operations_error_handler,
2165 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), info->mail_op);
2167 /* Invoke the connect and perform */
2168 modest_platform_connect_and_perform ((win) ? GTK_WINDOW (win) : NULL,
2169 force_connection, info->account,
2170 do_send_receive_performer, info);
2175 modest_ui_actions_do_cancel_send (const gchar *account_name,
2178 TnyTransportAccount *transport_account;
2179 TnySendQueue *send_queue = NULL;
2180 GError *error = NULL;
2182 /* Get transport account */
2184 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
2185 (modest_runtime_get_account_store(),
2187 TNY_ACCOUNT_TYPE_TRANSPORT));
2188 if (!transport_account) {
2189 g_printerr ("modest: no transport account found for '%s'\n", account_name);
2194 send_queue = TNY_SEND_QUEUE (modest_runtime_get_send_queue (transport_account, TRUE));
2195 if (!TNY_IS_SEND_QUEUE(send_queue)) {
2196 g_set_error (&error, MODEST_MAIL_OPERATION_ERROR,
2197 MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND,
2198 "modest: could not find send queue for account\n");
2200 /* Cancel the current send */
2201 tny_account_cancel (TNY_ACCOUNT (transport_account));
2203 /* Suspend all pending messages */
2204 tny_send_queue_cancel (send_queue, TNY_SEND_QUEUE_CANCEL_ACTION_SUSPEND, &error);
2208 if (transport_account != NULL)
2209 g_object_unref (G_OBJECT (transport_account));
2213 modest_ui_actions_cancel_send_all (ModestWindow *win)
2215 GSList *account_names, *iter;
2217 account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
2220 iter = account_names;
2222 modest_ui_actions_do_cancel_send ((const char*) iter->data, win);
2223 iter = g_slist_next (iter);
2226 modest_account_mgr_free_account_names (account_names);
2227 account_names = NULL;
2231 modest_ui_actions_cancel_send (GtkAction *action, ModestWindow *win)
2234 /* Check if accounts exist */
2235 gboolean accounts_exist =
2236 modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
2238 /* If not, allow the user to create an account before trying to send/receive. */
2239 if (!accounts_exist)
2240 modest_ui_actions_on_accounts (NULL, win);
2242 /* Cancel all sending operaitons */
2243 modest_ui_actions_cancel_send_all (win);
2247 * Refreshes all accounts. This function will be used by automatic
2251 modest_ui_actions_do_send_receive_all (ModestWindow *win,
2252 gboolean force_connection,
2253 gboolean poke_status,
2254 gboolean interactive)
2256 GSList *account_names, *iter;
2258 account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
2261 iter = account_names;
2263 modest_ui_actions_do_send_receive ((const char*) iter->data,
2265 poke_status, interactive, win);
2266 iter = g_slist_next (iter);
2269 modest_account_mgr_free_account_names (account_names);
2270 account_names = NULL;
2274 * Handler of the click on Send&Receive button in the main toolbar
2277 modest_ui_actions_on_send_receive (GtkAction *action, ModestWindow *win)
2279 /* Check if accounts exist */
2280 gboolean accounts_exist;
2283 modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
2285 /* If not, allow the user to create an account before trying to send/receive. */
2286 if (!accounts_exist)
2287 modest_ui_actions_on_accounts (NULL, win);
2289 /* Refresh the current folder. The if is always TRUE it's just an extra check */
2290 if (MODEST_IS_MAIN_WINDOW (win)) {
2291 GtkWidget *folder_view;
2292 TnyFolderStore *folder_store;
2295 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
2296 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2300 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
2303 g_object_unref (folder_store);
2304 /* Refresh the active account. Force the connection if needed
2305 and poke the status of all folders */
2306 modest_ui_actions_do_send_receive (NULL, TRUE, TRUE, TRUE, win);
2307 #ifdef MODEST_TOOLKIT_HILDON2
2308 } else if (MODEST_IS_ACCOUNTS_WINDOW (win)) {
2309 modest_ui_actions_do_send_receive_all (win, TRUE, TRUE, TRUE);
2312 const gchar *active_account;
2313 active_account = modest_window_get_active_account (MODEST_WINDOW (win));
2315 modest_ui_actions_do_send_receive (active_account, TRUE, TRUE, TRUE, win);
2322 modest_ui_actions_toggle_header_list_view (GtkAction *action, ModestMainWindow *main_window)
2325 GtkWidget *header_view;
2327 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2329 header_view = modest_main_window_get_child_widget (main_window,
2330 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2334 conf = modest_runtime_get_conf ();
2336 /* what is saved/restored is depending on the style; thus; we save with
2337 * old style, then update the style, and restore for this new style
2339 modest_widget_memory_save (conf, G_OBJECT(header_view), MODEST_CONF_HEADER_VIEW_KEY);
2341 if (modest_header_view_get_style
2342 (MODEST_HEADER_VIEW(header_view)) == MODEST_HEADER_VIEW_STYLE_DETAILS)
2343 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
2344 MODEST_HEADER_VIEW_STYLE_TWOLINES);
2346 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
2347 MODEST_HEADER_VIEW_STYLE_DETAILS);
2349 modest_widget_memory_restore (conf, G_OBJECT(header_view),
2350 MODEST_CONF_HEADER_VIEW_KEY);
2355 modest_ui_actions_on_header_selected (ModestHeaderView *header_view,
2357 ModestMainWindow *main_window)
2359 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2360 g_return_if_fail (MODEST_IS_HEADER_VIEW (header_view));
2362 /* in the case the folder is empty, show the empty folder message and focus
2364 if (!header && gtk_widget_is_focus (GTK_WIDGET (header_view))) {
2365 if (modest_header_view_is_empty (header_view)) {
2366 TnyFolder *folder = modest_header_view_get_folder (header_view);
2367 GtkWidget *folder_view =
2368 modest_main_window_get_child_widget (main_window,
2369 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2370 if (folder != NULL) {
2371 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view), folder, FALSE);
2372 g_object_unref (folder);
2374 gtk_widget_grab_focus (GTK_WIDGET (folder_view));
2378 /* If no header has been selected then exit */
2383 if (!gtk_widget_is_focus (GTK_WIDGET(header_view)))
2384 gtk_widget_grab_focus (GTK_WIDGET(header_view));
2386 /* Update toolbar dimming state */
2387 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (main_window));
2388 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
2392 modest_ui_actions_on_header_activated (ModestHeaderView *header_view,
2395 ModestWindow *window)
2397 GtkWidget *open_widget;
2398 GtkTreeRowReference *rowref;
2400 g_return_if_fail (MODEST_IS_WINDOW(window));
2401 g_return_if_fail (MODEST_IS_HEADER_VIEW (header_view));
2402 g_return_if_fail (TNY_IS_HEADER (header));
2404 if (modest_header_view_count_selected_headers (header_view) > 1) {
2405 /* Don't allow activation if there are more than one message selected */
2406 modest_platform_information_banner (NULL, NULL, _("mcen_ib_select_one_message"));
2410 /* we check for low-mem; in that case, show a warning, and don't allow
2411 * activating headers
2413 if (modest_platform_check_memory_low (MODEST_WINDOW(window), TRUE))
2416 if (MODEST_IS_MAIN_WINDOW (window)) {
2417 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (window));
2418 open_widget = modest_window_get_action_widget (MODEST_WINDOW (window), "/MenuBar/EmailMenu/EmailOpenMenu");
2419 if (!GTK_WIDGET_IS_SENSITIVE (open_widget))
2423 rowref = gtk_tree_row_reference_new (gtk_tree_view_get_model (GTK_TREE_VIEW (header_view)), path);
2424 open_msg_from_header (header, rowref, MODEST_WINDOW (window));
2425 gtk_tree_row_reference_free (rowref);
2429 set_active_account_from_tny_account (TnyAccount *account,
2430 ModestWindow *window)
2432 const gchar *server_acc_name = tny_account_get_id (account);
2434 /* We need the TnyAccount provided by the
2435 account store because that is the one that
2436 knows the name of the Modest account */
2437 TnyAccount *modest_server_account = modest_server_account =
2438 modest_tny_account_store_get_tny_account_by (modest_runtime_get_account_store (),
2439 MODEST_TNY_ACCOUNT_STORE_QUERY_ID,
2441 if (!modest_server_account) {
2442 g_warning ("%s: could not get tny account\n", __FUNCTION__);
2446 /* Update active account, but only if it's not a pseudo-account */
2447 if ((!modest_tny_account_is_virtual_local_folders(modest_server_account)) &&
2448 (!modest_tny_account_is_memory_card_account(modest_server_account))) {
2449 const gchar *modest_acc_name =
2450 modest_tny_account_get_parent_modest_account_name_for_server_account (modest_server_account);
2451 if (modest_acc_name)
2452 modest_window_set_active_account (window, modest_acc_name);
2455 g_object_unref (modest_server_account);
2460 folder_refreshed_cb (ModestMailOperation *mail_op,
2464 ModestMainWindow *win = NULL;
2465 GtkWidget *folder_view;
2466 const GError *error;
2468 g_return_if_fail (TNY_IS_FOLDER (folder));
2470 win = MODEST_MAIN_WINDOW (user_data);
2472 /* Check if the operation failed due to memory low conditions */
2473 error = modest_mail_operation_get_error (mail_op);
2474 if (error && error->domain == MODEST_MAIL_OPERATION_ERROR &&
2475 error->code == MODEST_MAIL_OPERATION_ERROR_LOW_MEMORY) {
2476 modest_platform_run_information_dialog (GTK_WINDOW (win),
2477 dgettext("ke-recv","memr_ib_operation_disabled"),
2483 modest_main_window_get_child_widget(win, MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2486 TnyFolderStore *current_folder;
2488 current_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
2489 if (current_folder) {
2490 gboolean different = ((TnyFolderStore *) folder != current_folder);
2491 g_object_unref (current_folder);
2497 /* Check if folder is empty and set headers view contents style */
2498 if (tny_folder_get_all_count (folder) == 0)
2499 modest_main_window_set_contents_style (win,
2500 MODEST_MAIN_WINDOW_CONTENTS_STYLE_EMPTY);
2505 modest_ui_actions_on_folder_selection_changed (ModestFolderView *folder_view,
2506 TnyFolderStore *folder_store,
2508 ModestMainWindow *main_window)
2511 GtkWidget *header_view;
2513 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2515 header_view = modest_main_window_get_child_widget(main_window,
2516 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2520 conf = modest_runtime_get_conf ();
2522 if (TNY_IS_ACCOUNT (folder_store)) {
2524 set_active_account_from_tny_account (TNY_ACCOUNT (folder_store), MODEST_WINDOW (main_window));
2526 /* Show account details */
2527 modest_main_window_set_contents_style (main_window, MODEST_MAIN_WINDOW_CONTENTS_STYLE_DETAILS);
2530 if (TNY_IS_FOLDER (folder_store) && selected) {
2531 TnyAccount *account;
2532 const gchar *account_name = NULL;
2534 /* Update the active account */
2535 account = modest_tny_folder_get_account (TNY_FOLDER (folder_store));
2537 set_active_account_from_tny_account (account, MODEST_WINDOW (main_window));
2539 modest_tny_account_get_parent_modest_account_name_for_server_account (account);
2540 g_object_unref (account);
2544 /* Set the header style by default, it could
2545 be changed later by the refresh callback to
2547 modest_main_window_set_contents_style (main_window,
2548 MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS);
2550 /* Set folder on header view. This function
2551 will call tny_folder_refresh_async so we
2552 pass a callback that will be called when
2553 finished. We use that callback to set the
2554 empty view if there are no messages */
2555 modest_header_view_set_folder (MODEST_HEADER_VIEW(header_view),
2556 TNY_FOLDER (folder_store),
2558 MODEST_WINDOW (main_window),
2559 folder_refreshed_cb,
2562 /* Restore configuration. We need to do this
2563 *after* the set_folder because the widget
2564 memory asks the header view about its
2566 modest_widget_memory_restore (modest_runtime_get_conf (),
2567 G_OBJECT(header_view),
2568 MODEST_CONF_HEADER_VIEW_KEY);
2570 /* No need to save the header view
2571 configuration for Maemo because it only
2572 saves the sorting stuff and that it's
2573 already being done by the sort
2574 dialog. Remove it when the GNOME version
2575 has the same behaviour */
2576 #ifdef MODEST_TOOLKIT_GTK
2577 if (modest_main_window_get_contents_style (main_window) ==
2578 MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS)
2579 modest_widget_memory_save (conf, G_OBJECT (header_view),
2580 MODEST_CONF_HEADER_VIEW_KEY);
2582 modest_header_view_clear (MODEST_HEADER_VIEW(header_view));
2586 /* Update dimming state */
2587 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (main_window));
2588 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
2592 modest_ui_actions_on_item_not_found (ModestHeaderView *header_view,ModestItemType type,
2599 item = (type == MODEST_ITEM_TYPE_FOLDER) ? "folder" : "message";
2601 online = tny_device_is_online (modest_runtime_get_device());
2604 /* already online -- the item is simply not there... */
2605 dialog = gtk_message_dialog_new (GTK_WINDOW (win),
2607 GTK_MESSAGE_WARNING,
2609 _("The %s you selected cannot be found"),
2611 gtk_dialog_add_button (GTK_DIALOG (dialog),_("mcen_bd_dialog_ok"), GTK_RESPONSE_ACCEPT);
2612 gtk_dialog_run (GTK_DIALOG(dialog));
2614 dialog = gtk_dialog_new_with_buttons (_("Connection requested"),
2617 _("mcen_bd_dialog_cancel"),
2618 GTK_RESPONSE_REJECT,
2619 _("mcen_bd_dialog_ok"),
2620 GTK_RESPONSE_ACCEPT,
2622 txt = g_strdup_printf (_("This %s is not available in offline mode.\n"
2623 "Do you want to get online?"), item);
2624 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
2625 gtk_label_new (txt), FALSE, FALSE, 0);
2626 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
2629 gtk_window_set_default_size (GTK_WINDOW(dialog), 300, 300);
2630 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
2631 /* TODO: Comment about why is this commented out: */
2632 /* modest_platform_connect_and_wait (); */
2635 gtk_widget_destroy (dialog);
2639 modest_ui_actions_on_msg_link_hover (ModestMsgView *msgview, const gchar* link,
2642 /* g_message ("%s %s", __FUNCTION__, link); */
2647 modest_ui_actions_on_msg_link_clicked (ModestMsgView *msgview, const gchar* link,
2650 modest_platform_activate_uri (link);
2654 modest_ui_actions_on_msg_link_contextual (ModestMsgView *msgview, const gchar* link,
2657 modest_platform_show_uri_popup (link);
2661 modest_ui_actions_on_msg_attachment_clicked (ModestMsgView *msgview, TnyMimePart *mime_part,
2664 /* we check for low-mem; in that case, show a warning, and don't allow
2665 * viewing attachments
2667 if (modest_platform_check_memory_low (MODEST_WINDOW(win), TRUE))
2670 modest_msg_view_window_view_attachment (MODEST_MSG_VIEW_WINDOW (win), mime_part);
2674 modest_ui_actions_on_msg_recpt_activated (ModestMsgView *msgview,
2675 const gchar *address,
2678 /* g_message ("%s %s", __FUNCTION__, address); */
2682 on_save_to_drafts_cb (ModestMailOperation *mail_op,
2683 TnyMsg *saved_draft,
2686 ModestMsgEditWindow *edit_window;
2688 /* TODO: in hildon 2 we have to dim and undim the header views while we're saving */
2689 #ifndef MODEST_TOOLKIT_HILDON2
2690 ModestMainWindow *win;
2692 /* FIXME. Make the header view sensitive again. This is a
2693 * temporary hack. See modest_ui_actions_on_save_to_drafts()
2695 win = MODEST_MAIN_WINDOW(modest_window_mgr_get_main_window(
2696 modest_runtime_get_window_mgr(), FALSE));
2698 GtkWidget *hdrview = modest_main_window_get_child_widget(
2699 win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2700 if (hdrview) gtk_widget_set_sensitive(hdrview, TRUE);
2704 edit_window = MODEST_MSG_EDIT_WINDOW (user_data);
2706 /* Set draft is there was no error */
2707 if (!modest_mail_operation_get_error (mail_op))
2708 modest_msg_edit_window_set_draft (edit_window, saved_draft);
2710 g_object_unref(edit_window);
2714 enough_space_for_message (ModestMsgEditWindow *edit_window,
2717 TnyAccountStore *acc_store;
2718 guint64 available_disk, expected_size;
2723 acc_store = TNY_ACCOUNT_STORE (modest_runtime_get_account_store());
2724 available_disk = modest_utils_get_available_space (NULL);
2725 modest_msg_edit_window_get_parts_size (edit_window, &parts_count, &parts_size);
2726 expected_size = modest_tny_msg_estimate_size (data->plain_body,
2731 /* Double check: memory full condition or message too big */
2732 if (available_disk < MIN_FREE_SPACE ||
2733 expected_size > available_disk) {
2735 modest_platform_information_banner (NULL, NULL,
2737 "cerm_device_memory_full"));
2742 * djcb: if we're in low-memory state, we only allow for
2743 * saving messages smaller than
2744 * MODEST_MAX_LOW_MEMORY_MESSAGE_SIZE (see modest-defs.h) this
2745 * should still allow for sending anything critical...
2747 if ((expected_size > MODEST_MAX_LOW_MEMORY_MESSAGE_SIZE) &&
2748 modest_platform_check_memory_low (MODEST_WINDOW(edit_window), TRUE))
2752 * djcb: we also make sure that the attachments are smaller than the max size
2753 * this is for the case where we'd try to forward a message with attachments
2754 * bigger than our max allowed size, or sending an message from drafts which
2755 * somehow got past our checks when attaching.
2757 if (expected_size > MODEST_MAX_ATTACHMENT_SIZE) {
2758 modest_platform_run_information_dialog (
2759 GTK_WINDOW(edit_window),
2760 dgettext("ke-recv","memr_ib_operation_disabled"),
2769 modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edit_window)
2771 TnyTransportAccount *transport_account;
2772 ModestMailOperation *mail_operation;
2774 gchar *account_name, *from;
2775 ModestAccountMgr *account_mgr;
2776 gboolean had_error = FALSE;
2777 ModestMainWindow *win = NULL;
2779 g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window), FALSE);
2781 data = modest_msg_edit_window_get_msg_data (edit_window);
2784 if (!enough_space_for_message (edit_window, data)) {
2785 modest_msg_edit_window_free_msg_data (edit_window, data);
2789 account_name = g_strdup (data->account_name);
2790 account_mgr = modest_runtime_get_account_mgr();
2792 account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
2794 account_name = modest_account_mgr_get_default_account (account_mgr);
2795 if (!account_name) {
2796 g_printerr ("modest: no account found\n");
2797 modest_msg_edit_window_free_msg_data (edit_window, data);
2801 if (!strcmp (account_name, MODEST_LOCAL_FOLDERS_ACCOUNT_ID)) {
2802 account_name = g_strdup (data->account_name);
2806 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
2807 (modest_runtime_get_account_store (),
2809 TNY_ACCOUNT_TYPE_TRANSPORT));
2810 if (!transport_account) {
2811 g_printerr ("modest: no transport account found for '%s'\n", account_name);
2812 g_free (account_name);
2813 modest_msg_edit_window_free_msg_data (edit_window, data);
2816 from = modest_account_mgr_get_from_string (account_mgr, account_name);
2818 /* Create the mail operation */
2819 mail_operation = modest_mail_operation_new_with_error_handling (NULL, modest_ui_actions_disk_operations_error_handler,
2821 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
2823 modest_mail_operation_save_to_drafts (mail_operation,
2835 data->priority_flags,
2836 on_save_to_drafts_cb,
2837 g_object_ref(edit_window));
2839 #ifdef MODEST_TOOLKIT_HILDON2
2840 /* In hildon2 we always show the information banner on saving to drafts.
2841 * It will be a system information banner in this case.
2843 gchar *text = g_strdup_printf (_("mail_va_saved_to_drafts"), _("mcen_me_folder_drafts"));
2844 modest_platform_information_banner (NULL, NULL, text);
2847 /* Use the main window as the parent of the banner, if the
2848 main window does not exist it won't be shown, if the parent
2849 window exists then it's properly shown. We don't use the
2850 editor window because it could be closed (save to drafts
2851 could happen after closing the window */
2852 win = (ModestMainWindow *)
2853 modest_window_mgr_get_main_window( modest_runtime_get_window_mgr(), FALSE);
2855 gchar *text = g_strdup_printf (_("mail_va_saved_to_drafts"), _("mcen_me_folder_drafts"));
2856 modest_platform_information_banner (GTK_WIDGET (win), NULL, text);
2860 modest_msg_edit_window_set_modified (edit_window, FALSE);
2864 g_free (account_name);
2865 g_object_unref (G_OBJECT (transport_account));
2866 g_object_unref (G_OBJECT (mail_operation));
2868 modest_msg_edit_window_free_msg_data (edit_window, data);
2871 * If the drafts folder is selected then make the header view
2872 * insensitive while the message is being saved to drafts
2873 * (it'll be sensitive again in on_save_to_drafts_cb()). This
2874 * is not very clean but it avoids letting the drafts folder
2875 * in an inconsistent state: the user could edit the message
2876 * being saved and undesirable things would happen.
2877 * In the average case the user won't notice anything at
2878 * all. In the worst case (the user is editing a really big
2879 * file from Drafts) the header view will be insensitive
2880 * during the saving process (10 or 20 seconds, depending on
2881 * the message). Anyway this is just a quick workaround: once
2882 * we find a better solution it should be removed
2883 * See NB#65125 (commend #18) for details.
2885 if (!had_error && win != NULL) {
2886 ModestFolderView *view = MODEST_FOLDER_VIEW(modest_main_window_get_child_widget(
2887 win, MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW));
2889 TnyFolder *folder = TNY_FOLDER(modest_folder_view_get_selected(view));
2891 if (modest_tny_folder_is_local_folder(folder)) {
2892 TnyFolderType folder_type;
2893 folder_type = modest_tny_folder_get_local_or_mmc_folder_type(folder);
2894 if (folder_type == TNY_FOLDER_TYPE_DRAFTS) {
2895 GtkWidget *hdrview = modest_main_window_get_child_widget(
2896 win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2897 if (hdrview) gtk_widget_set_sensitive(hdrview, FALSE);
2901 if (folder != NULL) g_object_unref(folder);
2908 /* For instance, when clicking the Send toolbar button when editing a message: */
2910 modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
2912 TnyTransportAccount *transport_account = NULL;
2913 gboolean had_error = FALSE;
2915 ModestAccountMgr *account_mgr;
2916 gchar *account_name;
2918 ModestMailOperation *mail_operation;
2920 g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window), TRUE);
2922 if (!modest_msg_edit_window_check_names (edit_window, TRUE))
2925 data = modest_msg_edit_window_get_msg_data (edit_window);
2928 if (!enough_space_for_message (edit_window, data)) {
2929 modest_msg_edit_window_free_msg_data (edit_window, data);
2933 account_mgr = modest_runtime_get_account_mgr();
2934 account_name = g_strdup (data->account_name);
2936 account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
2939 account_name = modest_account_mgr_get_default_account (account_mgr);
2941 if (!account_name) {
2942 modest_msg_edit_window_free_msg_data (edit_window, data);
2943 /* Run account setup wizard */
2944 if (!modest_ui_actions_run_account_setup_wizard (MODEST_WINDOW(edit_window))) {
2949 /* Get the currently-active transport account for this modest account: */
2950 if (strcmp (account_name, MODEST_LOCAL_FOLDERS_ACCOUNT_ID) != 0) {
2952 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
2953 (modest_runtime_get_account_store (),
2954 account_name, TNY_ACCOUNT_TYPE_TRANSPORT));
2957 if (!transport_account) {
2958 modest_msg_edit_window_free_msg_data (edit_window, data);
2959 /* Run account setup wizard */
2960 if (!modest_ui_actions_run_account_setup_wizard(MODEST_WINDOW(edit_window)))
2965 /* Create the mail operation */
2966 from = modest_account_mgr_get_from_string (account_mgr, account_name);
2967 mail_operation = modest_mail_operation_new_with_error_handling (NULL, modest_ui_actions_disk_operations_error_handler, NULL, NULL);
2968 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
2970 modest_mail_operation_send_new_mail (mail_operation,
2982 data->priority_flags);
2984 if (modest_mail_operation_get_status (mail_operation) == MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS)
2985 modest_platform_information_banner (NULL, NULL, _("mcen_ib_outbox_waiting_to_be_sent"));
2988 if (modest_mail_operation_get_error (mail_operation) != NULL) {
2989 const GError *error = modest_mail_operation_get_error (mail_operation);
2990 if (error->domain == MODEST_MAIL_OPERATION_ERROR &&
2991 error->code == MODEST_MAIL_OPERATION_ERROR_INSTANCE_CREATION_FAILED) {
2992 g_warning ("%s failed: %s\n", __FUNCTION__, (modest_mail_operation_get_error (mail_operation))->message);
2993 modest_platform_information_banner (NULL, NULL, _CS("sfil_ni_not_enough_memory"));
3000 g_free (account_name);
3001 g_object_unref (G_OBJECT (transport_account));
3002 g_object_unref (G_OBJECT (mail_operation));
3004 modest_msg_edit_window_free_msg_data (edit_window, data);
3007 modest_msg_edit_window_set_sent (edit_window, TRUE);
3009 /* Save settings and close the window: */
3010 modest_ui_actions_on_close_window (NULL, MODEST_WINDOW (edit_window));
3017 modest_ui_actions_on_toggle_bold (GtkToggleAction *action,
3018 ModestMsgEditWindow *window)
3020 ModestMsgEditFormatState *format_state = NULL;
3022 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3023 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
3025 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3028 format_state = modest_msg_edit_window_get_format_state (window);
3029 g_return_if_fail (format_state != NULL);
3031 format_state->bold = gtk_toggle_action_get_active (action);
3032 modest_msg_edit_window_set_format_state (window, format_state);
3033 g_free (format_state);
3038 modest_ui_actions_on_toggle_italics (GtkToggleAction *action,
3039 ModestMsgEditWindow *window)
3041 ModestMsgEditFormatState *format_state = NULL;
3043 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3044 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
3046 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3049 format_state = modest_msg_edit_window_get_format_state (window);
3050 g_return_if_fail (format_state != NULL);
3052 format_state->italics = gtk_toggle_action_get_active (action);
3053 modest_msg_edit_window_set_format_state (window, format_state);
3054 g_free (format_state);
3059 modest_ui_actions_on_toggle_bullets (GtkToggleAction *action,
3060 ModestMsgEditWindow *window)
3062 ModestMsgEditFormatState *format_state = NULL;
3064 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3065 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
3067 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3070 format_state = modest_msg_edit_window_get_format_state (window);
3071 g_return_if_fail (format_state != NULL);
3073 format_state->bullet = gtk_toggle_action_get_active (action);
3074 modest_msg_edit_window_set_format_state (window, format_state);
3075 g_free (format_state);
3080 modest_ui_actions_on_change_justify (GtkRadioAction *action,
3081 GtkRadioAction *selected,
3082 ModestMsgEditWindow *window)
3084 ModestMsgEditFormatState *format_state = NULL;
3085 GtkJustification value;
3087 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3089 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3092 value = gtk_radio_action_get_current_value (selected);
3094 format_state = modest_msg_edit_window_get_format_state (window);
3095 g_return_if_fail (format_state != NULL);
3097 format_state->justification = value;
3098 modest_msg_edit_window_set_format_state (window, format_state);
3099 g_free (format_state);
3103 modest_ui_actions_on_select_editor_color (GtkAction *action,
3104 ModestMsgEditWindow *window)
3106 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3107 g_return_if_fail (GTK_IS_ACTION (action));
3109 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3112 modest_msg_edit_window_select_color (window);
3116 modest_ui_actions_on_select_editor_background_color (GtkAction *action,
3117 ModestMsgEditWindow *window)
3119 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3120 g_return_if_fail (GTK_IS_ACTION (action));
3122 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3125 modest_msg_edit_window_select_background_color (window);
3129 modest_ui_actions_on_insert_image (GtkAction *action,
3130 ModestMsgEditWindow *window)
3132 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3133 g_return_if_fail (GTK_IS_ACTION (action));
3136 if (modest_platform_check_memory_low (MODEST_WINDOW(window), TRUE))
3139 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3142 modest_msg_edit_window_insert_image (window);
3146 modest_ui_actions_on_attach_file (GtkAction *action,
3147 ModestMsgEditWindow *window)
3149 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3150 g_return_if_fail (GTK_IS_ACTION (action));
3152 if (modest_platform_check_memory_low (MODEST_WINDOW(window), TRUE))
3155 modest_msg_edit_window_offer_attach_file (window);
3159 modest_ui_actions_on_remove_attachments (GtkAction *action,
3160 ModestMsgEditWindow *window)
3162 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3164 modest_msg_edit_window_remove_attachments (window, NULL);
3168 #ifndef MODEST_TOOLKIT_GTK
3173 TnyFolderStore *folder;
3174 } CreateFolderHelper;
3177 show_create_folder_in_timeout (gpointer data)
3179 CreateFolderHelper *helper = (CreateFolderHelper *) data;
3181 /* Remove the timeout ASAP, we can not wait until the dialog
3182 is shown because it could take a lot of time and so the
3183 timeout could be called twice or more times */
3184 g_source_remove (helper->handler);
3186 gdk_threads_enter ();
3187 do_create_folder (helper->win, helper->folder, helper->name);
3188 gdk_threads_leave ();
3190 g_object_unref (helper->win);
3191 g_object_unref (helper->folder);
3192 g_free (helper->name);
3193 g_slice_free (CreateFolderHelper, helper);
3200 do_create_folder_cb (ModestMailOperation *mail_op,
3201 TnyFolderStore *parent_folder,
3202 TnyFolder *new_folder,
3205 gchar *suggested_name = (gchar *) user_data;
3206 GtkWindow *source_win = (GtkWindow *) modest_mail_operation_get_source (mail_op);
3208 if (modest_mail_operation_get_error (mail_op)) {
3210 /* Show an error. If there was some problem writing to
3211 disk, show it, otherwise show the generic folder
3212 create error. We do it here and not in an error
3213 handler because the call to do_create_folder will
3214 stop the main loop in a gtk_dialog_run and then,
3215 the message won't be shown until that dialog is
3217 modest_ui_actions_disk_operations_error_handler (mail_op,
3218 _("mail_in_ui_folder_create_error"));
3220 /* Try again. Do *NOT* show any error because the mail
3221 operations system will do it for us because we
3222 created the mail_op with new_with_error_handler */
3223 #ifndef MODEST_TOOLKIT_GTK
3224 CreateFolderHelper *helper;
3225 helper = g_slice_new0 (CreateFolderHelper);
3226 helper->name = g_strdup (suggested_name);
3227 helper->folder = g_object_ref (parent_folder);
3228 helper->win = g_object_ref (source_win);
3230 /* Ugly but neccesary stuff. The problem is that the
3231 dialog when is shown calls a function that destroys
3232 all the temporary windows, so the banner is
3234 helper->handler = g_timeout_add (2000, show_create_folder_in_timeout, helper);
3236 do_create_folder (source_win, parent_folder, (const gchar *) suggested_name);
3239 /* the 'source_win' is either the ModestMainWindow, or the 'Move to folder'-dialog
3240 * FIXME: any other? */
3241 GtkWidget *folder_view;
3243 if (MODEST_IS_MAIN_WINDOW(source_win))
3245 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (source_win),
3246 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3248 folder_view = GTK_WIDGET(g_object_get_data (G_OBJECT (source_win),
3249 MODEST_MOVE_TO_DIALOG_FOLDER_VIEW));
3251 /* Select the newly created folder. It could happen
3252 that the widget is no longer there (i.e. the window
3253 has been destroyed, so we need to check this */
3255 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view),
3257 g_object_unref (new_folder);
3259 /* Free. Note that the first time it'll be NULL so noop */
3260 g_free (suggested_name);
3261 g_object_unref (source_win);
3265 do_create_folder (GtkWindow *parent_window,
3266 TnyFolderStore *suggested_parent,
3267 const gchar *suggested_name)
3270 gchar *folder_name = NULL;
3271 TnyFolderStore *parent_folder;
3273 result = modest_platform_run_new_folder_dialog (GTK_WINDOW (parent_window),
3275 (gchar *) suggested_name,
3279 if (result == GTK_RESPONSE_ACCEPT && parent_folder) {
3280 ModestMailOperation *mail_op;
3282 mail_op = modest_mail_operation_new ((GObject *) parent_window);
3283 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
3285 modest_mail_operation_create_folder (mail_op,
3287 (const gchar *) folder_name,
3288 do_create_folder_cb,
3290 g_object_unref (mail_op);
3292 g_object_unref (parent_folder);
3296 create_folder_performer (gboolean canceled,
3298 GtkWindow *parent_window,
3299 TnyAccount *account,
3302 TnyFolderStore *parent_folder = TNY_FOLDER_STORE (user_data);
3304 if (canceled || err) {
3305 /* In memory full conditions we could get this error here */
3306 check_memory_full_error ((GtkWidget *) parent_window, err);
3310 /* Run the new folder dialog */
3311 do_create_folder (GTK_WINDOW (parent_window), parent_folder, NULL);
3314 g_object_unref (parent_folder);
3318 modest_ui_actions_create_folder(GtkWidget *parent_window,
3319 GtkWidget *folder_view)
3321 TnyFolderStore *parent_folder;
3323 #ifdef MODEST_TOOLKIT_HILDON2
3324 const gchar *active_account;
3325 TnyAccount *account;
3327 /* In hildon 2.2 we use the current account as default parent */
3328 active_account = modest_window_get_active_account (MODEST_WINDOW (parent_window));
3329 account = modest_tny_account_store_get_server_account (modest_runtime_get_account_store (),
3331 TNY_ACCOUNT_TYPE_STORE);
3332 parent_folder = TNY_FOLDER_STORE (account);
3334 parent_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
3337 if (parent_folder) {
3338 /* The parent folder will be freed in the callback */
3339 modest_platform_connect_if_remote_and_perform (GTK_WINDOW (parent_window),
3342 create_folder_performer,
3348 modest_ui_actions_on_new_folder (GtkAction *action, ModestWindow *window)
3351 g_return_if_fail (MODEST_IS_WINDOW(window));
3353 if (MODEST_IS_MAIN_WINDOW (window)) {
3354 GtkWidget *folder_view;
3356 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (window),
3357 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3361 modest_ui_actions_create_folder (GTK_WIDGET (window), folder_view);
3362 #ifdef MODEST_TOOLKIT_HILDON2
3363 } else if (MODEST_IS_FOLDER_WINDOW (window)) {
3364 GtkWidget *folder_view;
3366 folder_view = GTK_WIDGET (modest_folder_window_get_folder_view (MODEST_FOLDER_WINDOW (window)));
3367 modest_ui_actions_create_folder (GTK_WIDGET (window), folder_view);
3370 g_assert_not_reached ();
3375 modest_ui_actions_rename_folder_error_handler (ModestMailOperation *mail_op,
3378 const GError *error = NULL;
3379 const gchar *message = NULL;
3381 /* Get error message */
3382 error = modest_mail_operation_get_error (mail_op);
3384 g_return_if_reached ();
3386 if (error->domain == MODEST_MAIL_OPERATION_ERROR &&
3387 error->code == MODEST_MAIL_OPERATION_ERROR_FOLDER_EXISTS) {
3388 message = _CS("ckdg_ib_folder_already_exists");
3389 } else if (error->domain == TNY_ERROR_DOMAIN &&
3390 error->code == TNY_SERVICE_ERROR_STATE) {
3391 /* This means that the folder is already in use (a
3392 message is opened for example */
3393 message = _("emev_ni_internal_error");
3395 message = _("emev_ib_ui_imap_unable_to_rename");
3398 /* We don't set a parent for the dialog because the dialog
3399 will be destroyed so the banner won't appear */
3400 modest_platform_information_banner (NULL, NULL, message);
3404 TnyFolderStore *folder;
3409 on_rename_folder_cb (ModestMailOperation *mail_op,
3410 TnyFolder *new_folder,
3413 ModestFolderView *folder_view;
3415 /* If the window was closed when renaming a folder, or if
3416 * it's not a main window this will happen */
3417 if (!MODEST_IS_FOLDER_VIEW (user_data))
3420 folder_view = MODEST_FOLDER_VIEW (user_data);
3421 /* Note that if the rename fails new_folder will be NULL */
3423 modest_folder_view_select_folder (folder_view, new_folder, FALSE);
3425 modest_folder_view_select_first_inbox_or_local (folder_view);
3427 gtk_widget_grab_focus (GTK_WIDGET (folder_view));
3431 on_rename_folder_performer (gboolean canceled,
3433 GtkWindow *parent_window,
3434 TnyAccount *account,
3437 ModestMailOperation *mail_op = NULL;
3438 GtkTreeSelection *sel = NULL;
3439 GtkWidget *folder_view = NULL;
3440 RenameFolderInfo *data = (RenameFolderInfo*)user_data;
3442 if (canceled || err) {
3443 /* In memory full conditions we could get this error here */
3444 check_memory_full_error ((GtkWidget *) parent_window, err);
3448 modest_mail_operation_new_with_error_handling (G_OBJECT(parent_window),
3449 modest_ui_actions_rename_folder_error_handler,
3450 parent_window, NULL);
3452 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
3455 if (MODEST_IS_MAIN_WINDOW(parent_window)) {
3457 folder_view = modest_main_window_get_child_widget (
3458 MODEST_MAIN_WINDOW (parent_window),
3459 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3461 /* Clear the headers view */
3462 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_view));
3463 gtk_tree_selection_unselect_all (sel);
3468 /* Actually rename the folder */
3469 modest_mail_operation_rename_folder (mail_op,
3470 TNY_FOLDER (data->folder),
3471 (const gchar *) (data->new_name),
3472 on_rename_folder_cb,
3474 g_object_unref (data->folder);
3475 g_object_unref (mail_op);
3478 g_free (data->new_name);
3483 modest_ui_actions_on_rename_folder (GtkAction *action,
3484 ModestWindow *window)
3486 modest_ui_actions_on_edit_mode_rename_folder (window);
3490 modest_ui_actions_on_edit_mode_rename_folder (ModestWindow *window)
3492 TnyFolderStore *folder;
3493 GtkWidget *folder_view;
3494 gboolean do_rename = TRUE;
3496 g_return_val_if_fail (MODEST_IS_WINDOW(window), FALSE);
3498 if (MODEST_IS_MAIN_WINDOW (window)) {
3499 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (window),
3500 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3504 #ifdef MODEST_TOOLKIT_HILDON2
3505 } else if (MODEST_IS_FOLDER_WINDOW (window)) {
3506 folder_view = GTK_WIDGET (modest_folder_window_get_folder_view (MODEST_FOLDER_WINDOW (window)));
3512 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
3517 if (TNY_IS_FOLDER (folder)) {
3518 gchar *folder_name = NULL;
3520 const gchar *current_name;
3521 TnyFolderStore *parent;
3523 current_name = tny_folder_get_name (TNY_FOLDER (folder));
3524 parent = tny_folder_get_folder_store (TNY_FOLDER (folder));
3525 response = modest_platform_run_rename_folder_dialog (GTK_WINDOW (window),
3526 parent, current_name,
3528 g_object_unref (parent);
3530 if (response != GTK_RESPONSE_ACCEPT || strlen (folder_name) == 0) {
3533 RenameFolderInfo *rename_folder_data = g_new0 (RenameFolderInfo, 1);
3534 rename_folder_data->folder = g_object_ref (folder);
3535 rename_folder_data->new_name = folder_name;
3536 modest_platform_connect_if_remote_and_perform (GTK_WINDOW(window), TRUE,
3537 folder, on_rename_folder_performer, rename_folder_data);
3540 g_object_unref (folder);
3545 modest_ui_actions_delete_folder_error_handler (ModestMailOperation *mail_op,
3548 GObject *win = modest_mail_operation_get_source (mail_op);
3550 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
3551 _("mail_in_ui_folder_delete_error"),
3553 g_object_unref (win);
3557 TnyFolderStore *folder;
3558 gboolean move_to_trash;
3562 on_delete_folder_cb (gboolean canceled,
3564 GtkWindow *parent_window,
3565 TnyAccount *account,
3568 DeleteFolderInfo *info = (DeleteFolderInfo*) user_data;
3569 GtkWidget *folder_view;
3570 ModestMailOperation *mail_op;
3571 GtkTreeSelection *sel;
3573 if (!MODEST_IS_WINDOW(parent_window) || canceled || (err!=NULL)) {
3574 g_object_unref (G_OBJECT (info->folder));
3579 if (MODEST_IS_MAIN_WINDOW (parent_window)) {
3580 folder_view = modest_main_window_get_child_widget (
3581 MODEST_MAIN_WINDOW (parent_window),
3582 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3583 #ifdef MODEST_TOOLKIT_HILDON2
3584 } else if (MODEST_IS_FOLDER_WINDOW (parent_window)) {
3585 folder_view = GTK_WIDGET (modest_folder_window_get_folder_view (MODEST_FOLDER_WINDOW (parent_window)));
3588 g_object_unref (G_OBJECT (info->folder));
3593 /* Unselect the folder before deleting it to free the headers */
3594 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_view));
3595 gtk_tree_selection_unselect_all (sel);
3597 /* Create the mail operation */
3599 modest_mail_operation_new_with_error_handling (G_OBJECT(parent_window),
3600 modest_ui_actions_delete_folder_error_handler,
3603 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
3605 modest_mail_operation_remove_folder (mail_op, TNY_FOLDER (info->folder), info->move_to_trash);
3607 modest_folder_view_select_first_inbox_or_local (MODEST_FOLDER_VIEW (folder_view));
3609 g_object_unref (G_OBJECT (mail_op));
3610 g_object_unref (G_OBJECT (info->folder));
3615 delete_folder (ModestWindow *window, gboolean move_to_trash)
3617 TnyFolderStore *folder;
3618 GtkWidget *folder_view;
3622 g_return_val_if_fail (MODEST_IS_WINDOW(window), FALSE);
3624 if (MODEST_IS_MAIN_WINDOW (window)) {
3626 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (window),
3627 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3628 #ifdef MODEST_TOOLKIT_HILDON2
3629 } else if (MODEST_IS_FOLDER_WINDOW (window)) {
3630 folder_view = GTK_WIDGET (modest_folder_window_get_folder_view (MODEST_FOLDER_WINDOW (window)));
3638 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
3640 /* Show an error if it's an account */
3641 if (!TNY_IS_FOLDER (folder)) {
3642 modest_platform_run_information_dialog (GTK_WINDOW (window),
3643 _("mail_in_ui_folder_delete_error"),
3645 g_object_unref (G_OBJECT (folder));
3650 message = g_strdup_printf (_("mcen_nc_delete_folder_text"),
3651 tny_folder_get_name (TNY_FOLDER (folder)));
3652 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (window),
3653 (const gchar *) message);
3656 if (response == GTK_RESPONSE_OK) {
3657 DeleteFolderInfo *info;
3658 info = g_new0(DeleteFolderInfo, 1);
3659 info->folder = folder;
3660 info->move_to_trash = move_to_trash;
3661 g_object_ref (G_OBJECT (info->folder));
3662 TnyAccount *account = tny_folder_get_account (TNY_FOLDER (folder));
3663 modest_platform_connect_if_remote_and_perform (GTK_WINDOW (window),
3665 TNY_FOLDER_STORE (account),
3666 on_delete_folder_cb, info);
3667 g_object_unref (account);
3672 g_object_unref (G_OBJECT (folder));
3676 modest_ui_actions_on_delete_folder (GtkAction *action,
3677 ModestWindow *window)
3679 modest_ui_actions_on_edit_mode_delete_folder (window);
3683 modest_ui_actions_on_edit_mode_delete_folder (ModestWindow *window)
3685 g_return_val_if_fail (MODEST_IS_WINDOW(window), TRUE);
3687 return delete_folder (window, FALSE);
3691 modest_ui_actions_on_move_folder_to_trash_folder (GtkAction *action, ModestMainWindow *main_window)
3693 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
3695 delete_folder (MODEST_WINDOW (main_window), TRUE);
3699 typedef struct _PasswordDialogFields {
3700 GtkWidget *username;
3701 GtkWidget *password;
3703 } PasswordDialogFields;
3706 password_dialog_check_field (GtkEditable *editable,
3707 PasswordDialogFields *fields)
3710 gboolean any_value_empty = FALSE;
3712 value = gtk_entry_get_text (GTK_ENTRY (fields->username));
3713 if ((value == NULL) || value[0] == '\0') {
3714 any_value_empty = TRUE;
3716 value = gtk_entry_get_text (GTK_ENTRY (fields->password));
3717 if ((value == NULL) || value[0] == '\0') {
3718 any_value_empty = TRUE;
3720 gtk_dialog_set_response_sensitive (GTK_DIALOG (fields->dialog), GTK_RESPONSE_ACCEPT, !any_value_empty);
3724 modest_ui_actions_on_password_requested (TnyAccountStore *account_store,
3725 const gchar* server_account_name,
3730 ModestMainWindow *main_window)
3732 g_return_if_fail(server_account_name);
3733 gboolean completed = FALSE;
3734 PasswordDialogFields *fields = NULL;
3736 /* Initalize output parameters: */
3743 #ifndef MODEST_TOOLKIT_GTK
3744 /* Maemo uses a different (awkward) button order,
3745 * It should probably just use gtk_alternative_dialog_button_order ().
3747 #ifdef MODEST_TOOLKIT_HILDON2
3749 gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
3752 _HL("wdgt_bd_done"),
3753 GTK_RESPONSE_ACCEPT,
3757 gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
3760 _("mcen_bd_dialog_ok"),
3761 GTK_RESPONSE_ACCEPT,
3762 _("mcen_bd_dialog_cancel"),
3763 GTK_RESPONSE_REJECT,
3765 #endif /* MODEST_TOOLKIT_HILDON2 */
3768 gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
3772 GTK_RESPONSE_REJECT,
3774 GTK_RESPONSE_ACCEPT,
3776 #endif /* MODEST_TOOLKIT_GTK */
3778 modest_window_mgr_set_modal (modest_runtime_get_window_mgr(), GTK_WINDOW (dialog), NULL);
3780 gchar *server_name = modest_account_mgr_get_server_account_hostname (
3781 modest_runtime_get_account_mgr(), server_account_name);
3782 if (!server_name) {/* This happened once, though I don't know why. murrayc. */
3783 g_warning("%s: Could not get server name for server account '%s'", __FUNCTION__, server_account_name);
3786 gtk_widget_destroy (dialog);
3790 gchar *txt = g_strdup_printf (_("mail_ia_password_info"), server_name);
3791 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), gtk_label_new(txt),
3794 g_free (server_name);
3798 gchar *initial_username = modest_account_mgr_get_server_account_username (
3799 modest_runtime_get_account_mgr(), server_account_name);
3801 GtkWidget *entry_username = gtk_entry_new ();
3802 if (initial_username)
3803 gtk_entry_set_text (GTK_ENTRY (entry_username), initial_username);
3804 /* Dim this if a connection has ever succeeded with this username,
3805 * as per the UI spec: */
3806 /* const gboolean username_known = */
3807 /* modest_account_mgr_get_server_account_username_has_succeeded( */
3808 /* modest_runtime_get_account_mgr(), server_account_name); */
3809 /* gtk_widget_set_sensitive (entry_username, !username_known); */
3811 /* We drop the username sensitive code and disallow changing it here
3812 * as tinymail does not support really changing the username in the callback
3814 gtk_widget_set_sensitive (entry_username, FALSE);
3816 #ifndef MODEST_TOOLKIT_GTK
3817 /* Auto-capitalization is the default, so let's turn it off: */
3818 hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_username), HILDON_GTK_INPUT_MODE_FULL);
3820 /* Create a size group to be used by all captions.
3821 * Note that HildonCaption does not create a default size group if we do not specify one.
3822 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
3823 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
3825 GtkWidget *caption = hildon_caption_new (sizegroup,
3826 _("mail_fi_username"), entry_username, NULL, HILDON_CAPTION_MANDATORY);
3827 gtk_widget_show (entry_username);
3828 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
3829 FALSE, FALSE, MODEST_MARGIN_HALF);
3830 gtk_widget_show (caption);
3832 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry_username,
3834 #endif /* !MODEST_TOOLKIT_GTK */
3837 GtkWidget *entry_password = gtk_entry_new ();
3838 gtk_entry_set_visibility (GTK_ENTRY(entry_password), FALSE);
3839 /* gtk_entry_set_invisible_char (GTK_ENTRY(entry_password), "*"); */
3841 #ifndef MODEST_TOOLKIT_GTK
3842 /* Auto-capitalization is the default, so let's turn it off: */
3843 hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_password),
3844 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
3846 caption = hildon_caption_new (sizegroup,
3847 _("mail_fi_password"), entry_password, NULL, HILDON_CAPTION_MANDATORY);
3848 gtk_widget_show (entry_password);
3849 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
3850 FALSE, FALSE, MODEST_MARGIN_HALF);
3851 gtk_widget_show (caption);
3852 g_object_unref (sizegroup);
3854 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry_password,
3856 #endif /* !MODEST_TOOLKIT_GTK */
3858 if (initial_username != NULL)
3859 gtk_widget_grab_focus (GTK_WIDGET (entry_password));
3861 /* This is not in the Maemo UI spec:
3862 remember_pass_check = gtk_check_button_new_with_label (_("Remember password"));
3863 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), remember_pass_check,
3867 fields = g_slice_new0 (PasswordDialogFields);
3868 fields->username = entry_username;
3869 fields->password = entry_password;
3870 fields->dialog = dialog;
3872 g_signal_connect (entry_username, "changed", G_CALLBACK (password_dialog_check_field), fields);
3873 g_signal_connect (entry_password, "changed", G_CALLBACK (password_dialog_check_field), fields);
3874 password_dialog_check_field (NULL, fields);
3876 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
3878 while (!completed) {
3880 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
3882 *username = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_username)));
3884 /* Note that an empty field becomes the "" string */
3885 if (*username && strlen (*username) > 0) {
3886 modest_account_mgr_set_server_account_username (modest_runtime_get_account_mgr(),
3887 server_account_name,
3891 const gboolean username_was_changed =
3892 (strcmp (*username, initial_username) != 0);
3893 if (username_was_changed) {
3894 g_warning ("%s: tinymail does not yet support changing the "
3895 "username in the get_password() callback.\n", __FUNCTION__);
3901 modest_platform_information_banner (GTK_WIDGET (dialog), NULL,
3902 _("mcen_ib_username_pw_incorrect"));
3908 *password = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_password)));
3910 /* We do not save the password in the configuration,
3911 * because this function is only called for passwords that should
3912 * not be remembered:
3913 modest_server_account_set_password (
3914 modest_runtime_get_account_mgr(), server_account_name,
3921 #ifndef MODEST_TOOLKIT_HILDON2
3922 /* Set parent to NULL or the banner will disappear with its parent dialog */
3923 modest_platform_information_banner(NULL, NULL, _("mail_ib_login_cancelled"));
3935 /* This is not in the Maemo UI spec:
3936 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (remember_pass_check)))
3942 g_free (initial_username);
3943 gtk_widget_destroy (dialog);
3944 g_slice_free (PasswordDialogFields, fields);
3946 /* printf ("DEBUG: %s: cancel=%d\n", __FUNCTION__, *cancel); */
3950 modest_ui_actions_on_cut (GtkAction *action,
3951 ModestWindow *window)
3953 GtkWidget *focused_widget;
3954 GtkClipboard *clipboard;
3956 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
3957 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
3958 if (GTK_IS_EDITABLE (focused_widget)) {
3959 gtk_editable_cut_clipboard (GTK_EDITABLE(focused_widget));
3960 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3961 gtk_clipboard_store (clipboard);
3962 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
3963 GtkTextBuffer *buffer;
3965 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
3966 if (modest_text_utils_buffer_selection_is_valid (buffer)) {
3967 gtk_text_buffer_cut_clipboard (buffer, clipboard, TRUE);
3968 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3969 gtk_clipboard_store (clipboard);
3971 } else if (MODEST_IS_HEADER_VIEW (focused_widget)) {
3972 TnyList *header_list = modest_header_view_get_selected_headers (
3973 MODEST_HEADER_VIEW (focused_widget));
3974 gboolean continue_download = FALSE;
3975 gint num_of_unc_msgs;
3977 num_of_unc_msgs = header_list_count_uncached_msgs(header_list);
3979 if (num_of_unc_msgs) {
3980 TnyAccount *account = get_account_from_header_list (header_list);
3982 continue_download = connect_to_get_msg (window, num_of_unc_msgs, account);
3983 g_object_unref (account);
3987 if (num_of_unc_msgs == 0 || continue_download) {
3988 /* modest_platform_information_banner (
3989 NULL, NULL, _CS("mcen_ib_getting_items"));*/
3990 modest_header_view_cut_selection (
3991 MODEST_HEADER_VIEW (focused_widget));
3994 g_object_unref (header_list);
3995 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
3996 modest_folder_view_cut_selection (MODEST_FOLDER_VIEW (focused_widget));
4001 modest_ui_actions_on_copy (GtkAction *action,
4002 ModestWindow *window)
4004 GtkClipboard *clipboard;
4005 GtkWidget *focused_widget;
4006 gboolean copied = TRUE;
4008 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
4009 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
4011 if (GTK_IS_LABEL (focused_widget)) {
4013 selection = modest_text_utils_label_get_selection (GTK_LABEL (focused_widget));
4014 gtk_clipboard_set_text (clipboard, selection, -1);
4016 gtk_clipboard_set_can_store (clipboard, NULL, 0);
4017 gtk_clipboard_store (clipboard);
4018 } else if (GTK_IS_EDITABLE (focused_widget)) {
4019 gtk_editable_copy_clipboard (GTK_EDITABLE(focused_widget));
4020 gtk_clipboard_set_can_store (clipboard, NULL, 0);
4021 gtk_clipboard_store (clipboard);
4022 } else if (GTK_IS_HTML (focused_widget)) {
4025 sel = gtk_html_get_selection_html (GTK_HTML (focused_widget), &len);
4026 if ((sel == NULL) || (sel[0] == '\0')) {
4029 gtk_html_copy (GTK_HTML (focused_widget));
4030 gtk_clipboard_set_can_store (clipboard, NULL, 0);
4031 gtk_clipboard_store (clipboard);
4033 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
4034 GtkTextBuffer *buffer;
4035 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
4036 if (modest_text_utils_buffer_selection_is_valid (buffer)) {
4037 gtk_text_buffer_copy_clipboard (buffer, clipboard);
4038 gtk_clipboard_set_can_store (clipboard, NULL, 0);
4039 gtk_clipboard_store (clipboard);
4041 } else if (MODEST_IS_HEADER_VIEW (focused_widget)) {
4042 TnyList *header_list = modest_header_view_get_selected_headers (
4043 MODEST_HEADER_VIEW (focused_widget));
4044 gboolean continue_download = FALSE;
4045 gint num_of_unc_msgs;
4047 num_of_unc_msgs = header_list_count_uncached_msgs(header_list);
4049 if (num_of_unc_msgs) {
4050 TnyAccount *account = get_account_from_header_list (header_list);
4052 continue_download = connect_to_get_msg (window, num_of_unc_msgs, account);
4053 g_object_unref (account);
4057 if (num_of_unc_msgs == 0 || continue_download) {
4058 modest_platform_information_banner (
4059 NULL, NULL, _CS("mcen_ib_getting_items"));
4060 modest_header_view_copy_selection (
4061 MODEST_HEADER_VIEW (focused_widget));
4065 g_object_unref (header_list);
4067 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
4068 modest_folder_view_copy_selection (MODEST_FOLDER_VIEW (focused_widget));
4071 /* Show information banner if there was a copy to clipboard */
4073 modest_platform_information_banner (
4074 NULL, NULL, _CS("ecoc_ib_edwin_copied"));
4078 modest_ui_actions_on_undo (GtkAction *action,
4079 ModestWindow *window)
4081 ModestEmailClipboard *clipboard = NULL;
4083 if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
4084 modest_msg_edit_window_undo (MODEST_MSG_EDIT_WINDOW (window));
4085 } else if (MODEST_IS_MAIN_WINDOW (window)) {
4086 /* Clear clipboard source */
4087 clipboard = modest_runtime_get_email_clipboard ();
4088 modest_email_clipboard_clear (clipboard);
4091 g_return_if_reached ();
4096 modest_ui_actions_on_redo (GtkAction *action,
4097 ModestWindow *window)
4099 if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
4100 modest_msg_edit_window_redo (MODEST_MSG_EDIT_WINDOW (window));
4103 g_return_if_reached ();
4109 destroy_information_note (ModestMailOperation *mail_op,
4112 /* destroy information note */
4113 gtk_widget_destroy (GTK_WIDGET(user_data));
4117 destroy_folder_information_note (ModestMailOperation *mail_op,
4118 TnyFolder *new_folder,
4121 /* destroy information note */
4122 gtk_widget_destroy (GTK_WIDGET(user_data));
4127 paste_as_attachment_free (gpointer data)
4129 PasteAsAttachmentHelper *helper = (PasteAsAttachmentHelper *) data;
4131 if (helper->banner) {
4132 gtk_widget_destroy (helper->banner);
4133 g_object_unref (helper->banner);
4139 paste_msg_as_attachment_cb (ModestMailOperation *mail_op,
4144 PasteAsAttachmentHelper *helper = (PasteAsAttachmentHelper *) userdata;
4145 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (helper->window));
4150 modest_msg_edit_window_add_part (MODEST_MSG_EDIT_WINDOW (helper->window), TNY_MIME_PART (msg));
4155 modest_ui_actions_on_paste (GtkAction *action,
4156 ModestWindow *window)
4158 GtkWidget *focused_widget = NULL;
4159 GtkWidget *inf_note = NULL;
4160 ModestMailOperation *mail_op = NULL;
4162 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
4163 if (GTK_IS_EDITABLE (focused_widget)) {
4164 gtk_editable_paste_clipboard (GTK_EDITABLE(focused_widget));
4165 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
4166 ModestEmailClipboard *e_clipboard = NULL;
4167 e_clipboard = modest_runtime_get_email_clipboard ();
4168 if (modest_email_clipboard_cleared (e_clipboard)) {
4169 GtkTextBuffer *buffer;
4170 GtkClipboard *clipboard;
4172 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
4173 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
4174 gtk_text_buffer_paste_clipboard (buffer, clipboard, NULL, TRUE);
4175 } else if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
4176 ModestMailOperation *mail_op;
4177 TnyFolder *src_folder = NULL;
4178 TnyList *data = NULL;
4180 PasteAsAttachmentHelper *helper = g_new0 (PasteAsAttachmentHelper, 1);
4181 helper->window = MODEST_MSG_EDIT_WINDOW (window);
4182 helper->banner = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
4183 _CS("ckct_nw_pasting"));
4184 modest_email_clipboard_get_data (e_clipboard, &src_folder, &data, &delete);
4185 mail_op = modest_mail_operation_new (G_OBJECT (window));
4186 if (helper->banner != NULL) {
4187 g_object_ref (G_OBJECT (helper->banner));
4188 gtk_widget_show (GTK_WIDGET (helper->banner));
4192 modest_mail_operation_get_msgs_full (mail_op,
4194 (GetMsgAsyncUserCallback) paste_msg_as_attachment_cb,
4196 paste_as_attachment_free);
4200 g_object_unref (data);
4202 g_object_unref (src_folder);
4205 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
4206 ModestEmailClipboard *clipboard = NULL;
4207 TnyFolder *src_folder = NULL;
4208 TnyFolderStore *folder_store = NULL;
4209 TnyList *data = NULL;
4210 gboolean delete = FALSE;
4212 /* Check clipboard source */
4213 clipboard = modest_runtime_get_email_clipboard ();
4214 if (modest_email_clipboard_cleared (clipboard))
4217 /* Get elements to paste */
4218 modest_email_clipboard_get_data (clipboard, &src_folder, &data, &delete);
4220 /* Create a new mail operation */
4221 mail_op = modest_mail_operation_new (G_OBJECT(window));
4223 /* Get destination folder */
4224 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (focused_widget));
4226 /* transfer messages */
4230 /* Ask for user confirmation */
4232 modest_ui_actions_msgs_move_to_confirmation (window,
4233 TNY_FOLDER (folder_store),
4237 if (response == GTK_RESPONSE_OK) {
4238 /* Launch notification */
4239 inf_note = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
4240 _CS("ckct_nw_pasting"));
4241 if (inf_note != NULL) {
4242 gtk_window_set_modal (GTK_WINDOW(inf_note), FALSE);
4243 gtk_widget_show (GTK_WIDGET(inf_note));
4246 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
4247 modest_mail_operation_xfer_msgs (mail_op,
4249 TNY_FOLDER (folder_store),
4251 destroy_information_note,
4254 g_object_unref (mail_op);
4257 } else if (src_folder != NULL) {
4258 /* Launch notification */
4259 inf_note = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
4260 _CS("ckct_nw_pasting"));
4261 if (inf_note != NULL) {
4262 gtk_window_set_modal (GTK_WINDOW(inf_note), FALSE);
4263 gtk_widget_show (GTK_WIDGET(inf_note));
4266 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
4267 modest_mail_operation_xfer_folder (mail_op,
4271 destroy_folder_information_note,
4277 g_object_unref (data);
4278 if (src_folder != NULL)
4279 g_object_unref (src_folder);
4280 if (folder_store != NULL)
4281 g_object_unref (folder_store);
4287 modest_ui_actions_on_select_all (GtkAction *action,
4288 ModestWindow *window)
4290 GtkWidget *focused_widget;
4292 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
4293 if (MODEST_IS_ATTACHMENTS_VIEW (focused_widget)) {
4294 modest_attachments_view_select_all (MODEST_ATTACHMENTS_VIEW (focused_widget));
4295 } else if (GTK_IS_LABEL (focused_widget)) {
4296 gtk_label_select_region (GTK_LABEL (focused_widget), 0, -1);
4297 } else if (GTK_IS_EDITABLE (focused_widget)) {
4298 gtk_editable_select_region (GTK_EDITABLE(focused_widget), 0, -1);
4299 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
4300 GtkTextBuffer *buffer;
4301 GtkTextIter start, end;
4303 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
4304 gtk_text_buffer_get_start_iter (buffer, &start);
4305 gtk_text_buffer_get_end_iter (buffer, &end);
4306 gtk_text_buffer_select_range (buffer, &start, &end);
4307 } else if (GTK_IS_HTML (focused_widget)) {
4308 gtk_html_select_all (GTK_HTML (focused_widget));
4309 } else if (MODEST_IS_MAIN_WINDOW (window)) {
4310 GtkWidget *header_view = focused_widget;
4311 GtkTreeSelection *selection = NULL;
4313 if (!(MODEST_IS_HEADER_VIEW (focused_widget))) {
4314 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (window),
4315 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
4318 /* Disable window dimming management */
4319 modest_window_disable_dimming (MODEST_WINDOW(window));
4321 /* Select all messages */
4322 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(header_view));
4323 gtk_tree_selection_select_all (selection);
4325 /* Set focuse on header view */
4326 gtk_widget_grab_focus (header_view);
4328 /* Enable window dimming management */
4329 modest_window_enable_dimming (MODEST_WINDOW(window));
4330 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (window));
4331 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (window));
4337 modest_ui_actions_on_mark_as_read (GtkAction *action,
4338 ModestWindow *window)
4340 g_return_if_fail (MODEST_IS_WINDOW(window));
4342 /* Mark each header as read */
4343 do_headers_action (window, headers_action_mark_as_read, NULL);
4347 modest_ui_actions_on_mark_as_unread (GtkAction *action,
4348 ModestWindow *window)
4350 g_return_if_fail (MODEST_IS_WINDOW(window));
4352 /* Mark each header as read */
4353 do_headers_action (window, headers_action_mark_as_unread, NULL);
4357 modest_ui_actions_on_change_zoom (GtkRadioAction *action,
4358 GtkRadioAction *selected,
4359 ModestWindow *window)
4363 value = gtk_radio_action_get_current_value (selected);
4364 if (MODEST_IS_WINDOW (window)) {
4365 modest_window_set_zoom (MODEST_WINDOW (window), ((gdouble)value)/100);
4370 modest_ui_actions_msg_edit_on_change_priority (GtkRadioAction *action,
4371 GtkRadioAction *selected,
4372 ModestWindow *window)
4374 TnyHeaderFlags flags;
4375 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4377 flags = gtk_radio_action_get_current_value (selected);
4378 modest_msg_edit_window_set_priority_flags (MODEST_MSG_EDIT_WINDOW (window), flags);
4382 modest_ui_actions_msg_edit_on_change_file_format (GtkRadioAction *action,
4383 GtkRadioAction *selected,
4384 ModestWindow *window)
4388 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4390 file_format = gtk_radio_action_get_current_value (selected);
4391 modest_msg_edit_window_set_file_format (MODEST_MSG_EDIT_WINDOW (window), file_format);
4396 modest_ui_actions_on_zoom_plus (GtkAction *action,
4397 ModestWindow *window)
4399 g_return_if_fail (MODEST_IS_WINDOW (window));
4401 modest_window_zoom_plus (MODEST_WINDOW (window));
4405 modest_ui_actions_on_zoom_minus (GtkAction *action,
4406 ModestWindow *window)
4408 g_return_if_fail (MODEST_IS_WINDOW (window));
4410 modest_window_zoom_minus (MODEST_WINDOW (window));
4414 modest_ui_actions_on_toggle_fullscreen (GtkToggleAction *toggle,
4415 ModestWindow *window)
4417 ModestWindowMgr *mgr;
4418 gboolean fullscreen, active;
4419 g_return_if_fail (MODEST_IS_WINDOW (window));
4421 mgr = modest_runtime_get_window_mgr ();
4423 active = (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle)))?1:0;
4424 fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
4426 if (active != fullscreen) {
4427 modest_window_mgr_set_fullscreen_mode (mgr, active);
4428 #ifndef MODEST_TOOLKIT_HILDON2
4429 gtk_window_present (GTK_WINDOW (window));
4435 modest_ui_actions_on_change_fullscreen (GtkAction *action,
4436 ModestWindow *window)
4438 ModestWindowMgr *mgr;
4439 gboolean fullscreen;
4441 g_return_if_fail (MODEST_IS_WINDOW (window));
4443 mgr = modest_runtime_get_window_mgr ();
4444 fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
4445 modest_window_mgr_set_fullscreen_mode (mgr, !fullscreen);
4447 #ifndef MODEST_TOOLKIT_HILDON2
4448 gtk_window_present (GTK_WINDOW (window));
4453 * Used by modest_ui_actions_on_details to call do_headers_action
4456 headers_action_show_details (TnyHeader *header,
4457 ModestWindow *window,
4461 modest_platform_run_header_details_dialog (GTK_WINDOW (window), header);
4465 * Show the header details in a ModestDetailsDialog widget
4468 modest_ui_actions_on_details (GtkAction *action,
4471 TnyList * headers_list;
4475 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
4478 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW (win));
4481 g_object_unref (msg);
4483 headers_list = get_selected_headers (win);
4487 iter = tny_list_create_iterator (headers_list);
4489 header = TNY_HEADER (tny_iterator_get_current (iter));
4491 headers_action_show_details (header, win, NULL);
4492 g_object_unref (header);
4495 g_object_unref (iter);
4496 g_object_unref (headers_list);
4498 } else if (MODEST_IS_MAIN_WINDOW (win)) {
4499 GtkWidget *folder_view, *header_view;
4501 /* Check which widget has the focus */
4502 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
4503 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
4504 if (gtk_widget_is_focus (folder_view)) {
4505 TnyFolderStore *folder_store
4506 = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
4507 if (!folder_store) {
4508 g_warning ("%s: No item was selected.\n", __FUNCTION__);
4511 /* Show only when it's a folder */
4512 /* This function should not be called for account items,
4513 * because we dim the menu item for them. */
4514 if (TNY_IS_FOLDER (folder_store)) {
4515 modest_platform_run_folder_details_dialog (GTK_WINDOW (win),
4516 TNY_FOLDER (folder_store));
4519 g_object_unref (folder_store);
4522 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
4523 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
4524 /* Show details of each header */
4525 do_headers_action (win, headers_action_show_details, header_view);
4527 #ifdef MODEST_TOOLKIT_HILDON2
4528 } else if (MODEST_IS_HEADER_WINDOW (win)) {
4530 GtkWidget *header_view;
4532 header_view = GTK_WIDGET (modest_header_window_get_header_view (MODEST_HEADER_WINDOW (win)));
4533 folder = modest_header_view_get_folder (MODEST_HEADER_VIEW (header_view));
4535 modest_platform_run_folder_details_dialog (GTK_WINDOW (win),
4537 g_object_unref (folder);
4544 modest_ui_actions_on_toggle_show_cc (GtkToggleAction *toggle,
4545 ModestMsgEditWindow *window)
4547 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4549 modest_msg_edit_window_show_cc (window, gtk_toggle_action_get_active (toggle));
4553 modest_ui_actions_on_toggle_show_bcc (GtkToggleAction *toggle,
4554 ModestMsgEditWindow *window)
4556 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4558 modest_msg_edit_window_show_bcc (window, gtk_toggle_action_get_active (toggle));
4562 modest_ui_actions_toggle_folders_view (GtkAction *action,
4563 ModestMainWindow *main_window)
4565 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
4567 if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)))
4568 modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SPLIT);
4570 modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SIMPLE);
4574 modest_ui_actions_on_toggle_toolbar (GtkToggleAction *toggle,
4575 ModestWindow *window)
4577 gboolean active, fullscreen = FALSE;
4578 ModestWindowMgr *mgr;
4580 active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle));
4582 /* Check if we want to toggle the toolbar view in fullscreen
4584 if (!strcmp (gtk_action_get_name (GTK_ACTION (toggle)),
4585 "ViewShowToolbarFullScreen")) {
4589 /* Toggle toolbar */
4590 mgr = modest_runtime_get_window_mgr ();
4591 modest_window_mgr_show_toolbars (mgr, G_TYPE_FROM_INSTANCE (window), active, fullscreen);
4595 modest_ui_actions_msg_edit_on_select_font (GtkAction *action,
4596 ModestMsgEditWindow *window)
4598 modest_msg_edit_window_select_font (window);
4603 modest_ui_actions_on_folder_display_name_changed (ModestFolderView *folder_view,
4604 const gchar *display_name,
4607 /* don't update the display name if it was already set;
4608 * updating the display name apparently is expensive */
4609 const gchar* old_name = gtk_window_get_title (window);
4611 if (display_name == NULL)
4614 if (old_name && display_name && strcmp (old_name, display_name) == 0)
4615 return; /* don't do anything */
4617 /* This is usually used to change the title of the main window, which
4618 * is the one that holds the folder view. Note that this change can
4619 * happen even when the widget doesn't have the focus. */
4620 gtk_window_set_title (window, display_name);
4625 modest_ui_actions_on_select_contacts (GtkAction *action, ModestMsgEditWindow *window)
4627 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4628 modest_msg_edit_window_select_contacts (window);
4632 modest_ui_actions_on_check_names (GtkAction *action, ModestMsgEditWindow *window)
4634 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4635 modest_msg_edit_window_check_names (window, FALSE);
4638 #ifndef MODEST_TOOLKIT_HILDON2
4640 * This function is used to track changes in the selection of the
4641 * folder view that is inside the "move to" dialog to enable/disable
4642 * the OK button because we do not want the user to select a disallowed
4643 * destination for a folder.
4644 * The user also not desired to be able to use NEW button on items where
4645 * folder creation is not possibel.
4648 on_move_to_dialog_folder_selection_changed (ModestFolderView* self,
4649 TnyFolderStore *folder_store,
4653 GtkWidget *dialog = NULL;
4654 gboolean ok_sensitive = TRUE, new_sensitive = TRUE;
4655 gboolean moving_folder = FALSE;
4656 gboolean is_local_account = TRUE;
4657 GtkWidget *folder_view = NULL;
4658 ModestTnyFolderRules rules;
4660 g_return_if_fail (MODEST_IS_FOLDER_VIEW(self));
4665 dialog = gtk_widget_get_ancestor (GTK_WIDGET (self), GTK_TYPE_DIALOG);
4669 /* check if folder_store is an remote account */
4670 if (TNY_IS_ACCOUNT (folder_store)) {
4671 TnyAccount *local_account = NULL;
4672 TnyAccount *mmc_account = NULL;
4673 ModestTnyAccountStore *account_store = NULL;
4675 account_store = modest_runtime_get_account_store ();
4676 local_account = modest_tny_account_store_get_local_folders_account (account_store);
4677 mmc_account = modest_tny_account_store_get_mmc_folders_account (account_store);
4679 if ((gpointer) local_account != (gpointer) folder_store &&
4680 (gpointer) mmc_account != (gpointer) folder_store) {
4681 ModestProtocolType proto;
4682 proto = modest_tny_account_get_protocol_type (TNY_ACCOUNT (folder_store));
4683 if (proto == MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
4684 proto = MODEST_PROTOCOLS_STORE_MAILDIR;
4686 is_local_account = FALSE;
4687 /* New button should be dimmed on remote
4689 new_sensitive = (modest_protocol_registry_protocol_type_has_tag (modest_runtime_get_protocol_registry (),
4691 MODEST_PROTOCOL_REGISTRY_STORE_HAS_FOLDERS));
4693 g_object_unref (local_account);
4695 /* It could not exist */
4697 g_object_unref (mmc_account);
4700 /* Check the target folder rules */
4701 if (TNY_IS_FOLDER (folder_store)) {
4702 rules = modest_tny_folder_get_rules (TNY_FOLDER (folder_store));
4703 if (rules & MODEST_FOLDER_RULES_FOLDER_NON_WRITEABLE) {
4704 ok_sensitive = FALSE;
4705 new_sensitive = FALSE;
4710 /* Check if we're moving a folder */
4711 if (MODEST_IS_MAIN_WINDOW (user_data)) {
4712 /* Get the widgets */
4713 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (user_data),
4714 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
4715 if (gtk_widget_is_focus (folder_view))
4716 moving_folder = TRUE;
4719 if (moving_folder) {
4720 TnyFolderStore *moved_folder = NULL, *parent = NULL;
4722 /* Get the folder to move */
4723 moved_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
4725 /* Check that we're not moving to the same folder */
4726 if (TNY_IS_FOLDER (moved_folder)) {
4727 parent = tny_folder_get_folder_store (TNY_FOLDER (moved_folder));
4728 if (parent == folder_store)
4729 ok_sensitive = FALSE;
4730 g_object_unref (parent);
4733 if (ok_sensitive && TNY_IS_ACCOUNT (folder_store)) {
4734 /* Do not allow to move to an account unless it's the
4735 local folders account */
4736 if (!is_local_account)
4737 ok_sensitive = FALSE;
4740 if (ok_sensitive && (moved_folder == folder_store)) {
4741 /* Do not allow to move to itself */
4742 ok_sensitive = FALSE;
4744 g_object_unref (moved_folder);
4746 TnyFolder *src_folder = NULL;
4748 /* Moving a message */
4749 if (MODEST_IS_MSG_VIEW_WINDOW (user_data)) {
4751 TnyHeader *header = NULL;
4752 header = modest_msg_view_window_get_header
4753 (MODEST_MSG_VIEW_WINDOW (user_data));
4754 if (!TNY_IS_HEADER(header))
4755 g_warning ("%s: could not get source header", __FUNCTION__);
4757 src_folder = tny_header_get_folder (header);
4760 g_object_unref (header);
4763 TNY_FOLDER (modest_folder_view_get_selected
4764 (MODEST_FOLDER_VIEW (folder_view)));
4767 if (TNY_IS_FOLDER(src_folder)) {
4768 /* Do not allow to move the msg to the same folder */
4769 /* Do not allow to move the msg to an account */
4770 if ((gpointer) src_folder == (gpointer) folder_store ||
4771 TNY_IS_ACCOUNT (folder_store))
4772 ok_sensitive = FALSE;
4773 g_object_unref (src_folder);
4775 g_warning ("%s: could not get source folder", __FUNCTION__);
4779 /* Set sensitivity of the OK and NEW button */
4780 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, ok_sensitive);
4781 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), MODEST_GTK_RESPONSE_NEW_FOLDER, new_sensitive);
4786 on_move_to_dialog_response (GtkDialog *dialog,
4790 GtkWidget *parent_win, *folder_view;
4791 MoveToInfo *helper = NULL;
4793 helper = (MoveToInfo *) user_data;
4795 parent_win = (GtkWidget *) helper->win;
4796 folder_view = GTK_WIDGET (g_object_get_data (G_OBJECT (dialog),
4797 MODEST_MOVE_TO_DIALOG_FOLDER_VIEW));
4800 TnyFolderStore *dst_folder;
4802 case MODEST_GTK_RESPONSE_NEW_FOLDER:
4803 modest_ui_actions_create_folder (GTK_WIDGET (parent_win), folder_view);
4805 case GTK_RESPONSE_NONE:
4806 case GTK_RESPONSE_CANCEL:
4807 case GTK_RESPONSE_DELETE_EVENT:
4809 case GTK_RESPONSE_OK:
4810 dst_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
4811 /* Do window specific stuff */
4812 if (MODEST_IS_MAIN_WINDOW (parent_win)) {
4813 modest_ui_actions_on_main_window_move_to (NULL,
4816 MODEST_MAIN_WINDOW (parent_win));
4817 #ifdef MODEST_TOOLKIT_HILDON2
4818 } else if (MODEST_IS_FOLDER_WINDOW (parent_win)) {
4819 modest_ui_actions_on_folder_window_move_to (folder_view,
4822 GTK_WINDOW (parent_win));
4825 /* Moving from headers window in edit mode */
4826 modest_ui_actions_on_window_move_to (NULL, helper->list,
4828 MODEST_WINDOW (parent_win));
4832 g_object_unref (dst_folder);
4836 g_warning ("%s unexpected response id %d", __FUNCTION__, response);
4839 /* Free the helper and exit */
4840 g_object_unref (helper->list);
4841 g_slice_free (MoveToInfo, helper);
4842 gtk_widget_destroy (GTK_WIDGET (dialog));
4846 create_move_to_dialog (GtkWindow *win,
4847 GtkWidget *folder_view)
4849 GtkWidget *dialog, *tree_view = NULL;
4851 dialog = modest_platform_create_move_to_dialog (win, &tree_view);
4853 #ifndef MODEST_TOOLKIT_HILDON2
4854 /* Track changes in the selection to
4855 * disable the OK button whenever "Move to" is not possible
4856 * disbale NEW button whenever New is not possible */
4857 g_signal_connect (tree_view,
4858 "folder_selection_changed",
4859 G_CALLBACK (on_move_to_dialog_folder_selection_changed),
4863 /* It could happen that we're trying to move a message from a
4864 window (msg window for example) after the main window was
4865 closed, so we can not just get the model of the folder
4867 if (MODEST_IS_FOLDER_VIEW (folder_view)) {
4868 const gchar *visible_id = NULL;
4870 modest_folder_view_set_style (MODEST_FOLDER_VIEW (tree_view),
4871 MODEST_FOLDER_VIEW_STYLE_SHOW_ALL);
4872 modest_folder_view_copy_model (MODEST_FOLDER_VIEW(folder_view),
4873 MODEST_FOLDER_VIEW(tree_view));
4876 modest_folder_view_get_account_id_of_visible_server_account (MODEST_FOLDER_VIEW(folder_view));
4878 /* Show the same account than the one that is shown in the main window */
4879 modest_folder_view_set_account_id_of_visible_server_account (MODEST_FOLDER_VIEW(tree_view),
4882 const gchar *active_account_name = NULL;
4883 ModestAccountMgr *mgr = NULL;
4884 ModestAccountSettings *settings = NULL;
4885 ModestServerAccountSettings *store_settings = NULL;
4887 modest_folder_view_set_style (MODEST_FOLDER_VIEW (tree_view),
4888 MODEST_FOLDER_VIEW_STYLE_SHOW_ALL);
4889 modest_folder_view_update_model (MODEST_FOLDER_VIEW (tree_view),
4890 TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()));
4892 active_account_name = modest_window_get_active_account (MODEST_WINDOW (win));
4893 mgr = modest_runtime_get_account_mgr ();
4894 settings = modest_account_mgr_load_account_settings (mgr, active_account_name);
4897 const gchar *store_account_name;
4898 store_settings = modest_account_settings_get_store_settings (settings);
4899 store_account_name = modest_server_account_settings_get_account_name (store_settings);
4901 modest_folder_view_set_account_id_of_visible_server_account (MODEST_FOLDER_VIEW (tree_view),
4902 store_account_name);
4903 g_object_unref (store_settings);
4904 g_object_unref (settings);
4908 /* we keep a pointer to the embedded folder view, so we can
4909 * retrieve it with get_folder_view_from_move_to_dialog (see
4910 * above) later (needed for focus handling)
4912 g_object_set_data (G_OBJECT(dialog), MODEST_MOVE_TO_DIALOG_FOLDER_VIEW, tree_view);
4914 /* Hide special folders */
4915 modest_folder_view_show_non_move_folders (MODEST_FOLDER_VIEW (tree_view), FALSE);
4916 #ifndef MODEST_TOOLKIT_HILDON2
4917 modest_folder_view_select_first_inbox_or_local (MODEST_FOLDER_VIEW (tree_view));
4920 gtk_widget_show (GTK_WIDGET (tree_view));
4926 * Shows a confirmation dialog to the user when we're moving messages
4927 * from a remote server to the local storage. Returns the dialog
4928 * response. If it's other kind of movement then it always returns
4931 * This one is used by the next functions:
4932 * modest_ui_actions_on_paste - commented out
4933 * drag_and_drop_from_header_view (for d&d in modest_folder_view.c)
4936 modest_ui_actions_msgs_move_to_confirmation (ModestWindow *win,
4937 TnyFolder *dest_folder,
4941 gint response = GTK_RESPONSE_OK;
4942 TnyAccount *account = NULL;
4943 TnyFolder *src_folder = NULL;
4944 TnyIterator *iter = NULL;
4945 TnyHeader *header = NULL;
4947 /* return with OK if the destination is a remote folder */
4948 if (modest_tny_folder_is_remote_folder (dest_folder))
4949 return GTK_RESPONSE_OK;
4951 /* Get source folder */
4952 iter = tny_list_create_iterator (headers);
4953 header = TNY_HEADER (tny_iterator_get_current (iter));
4955 src_folder = tny_header_get_folder (header);
4956 g_object_unref (header);
4958 g_object_unref (iter);
4960 /* if no src_folder, message may be an attahcment */
4961 if (src_folder == NULL)
4962 return GTK_RESPONSE_CANCEL;
4964 /* If the source is a local or MMC folder */
4965 if (!modest_tny_folder_is_remote_folder (src_folder)) {
4966 g_object_unref (src_folder);
4967 return GTK_RESPONSE_OK;
4970 /* Get the account */
4971 account = tny_folder_get_account (src_folder);
4973 /* now if offline we ask the user */
4974 if(connect_to_get_msg (win, tny_list_get_length (headers), account))
4975 response = GTK_RESPONSE_OK;
4977 response = GTK_RESPONSE_CANCEL;
4980 g_object_unref (src_folder);
4981 g_object_unref (account);
4987 move_to_helper_destroyer (gpointer user_data)
4989 MoveToHelper *helper = (MoveToHelper *) user_data;
4991 /* Close the "Pasting" information banner */
4992 if (helper->banner) {
4993 gtk_widget_destroy (GTK_WIDGET (helper->banner));
4994 g_object_unref (helper->banner);
4996 if (gtk_tree_row_reference_valid (helper->reference)) {
4997 gtk_tree_row_reference_free (helper->reference);
4998 helper->reference = NULL;
5004 move_to_cb (ModestMailOperation *mail_op,
5007 MoveToHelper *helper = (MoveToHelper *) user_data;
5009 /* Note that the operation could have failed, in that case do
5011 if (modest_mail_operation_get_status (mail_op) ==
5012 MODEST_MAIL_OPERATION_STATUS_SUCCESS) {
5014 GObject *object = modest_mail_operation_get_source (mail_op);
5015 if (MODEST_IS_MSG_VIEW_WINDOW (object)) {
5016 ModestMsgViewWindow *self = MODEST_MSG_VIEW_WINDOW (object);
5018 if (!modest_msg_view_window_select_next_message (self) &&
5019 !modest_msg_view_window_select_previous_message (self)) {
5020 /* No more messages to view, so close this window */
5021 modest_ui_actions_on_close_window (NULL, MODEST_WINDOW(self));
5023 } else if (MODEST_IS_MAIN_WINDOW (object) &&
5024 gtk_tree_row_reference_valid (helper->reference)) {
5025 GtkWidget *header_view;
5027 GtkTreeSelection *sel;
5029 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(object),
5030 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
5031 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
5032 path = gtk_tree_row_reference_get_path (helper->reference);
5033 /* We need to unselect the previous one
5034 because we could be copying instead of
5036 gtk_tree_selection_unselect_all (sel);
5037 gtk_tree_selection_select_path (sel, path);
5038 gtk_tree_path_free (path);
5040 g_object_unref (object);
5042 /* Destroy the helper */
5043 move_to_helper_destroyer (helper);
5047 folder_move_to_cb (ModestMailOperation *mail_op,
5048 TnyFolder *new_folder,
5051 GtkWidget *folder_view;
5054 object = modest_mail_operation_get_source (mail_op);
5055 if (MODEST_IS_MAIN_WINDOW (object)) {
5056 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(object),
5057 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
5058 g_object_ref (folder_view);
5059 g_object_unref (object);
5060 move_to_cb (mail_op, user_data);
5061 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view), new_folder, FALSE);
5062 g_object_unref (folder_view);
5064 move_to_cb (mail_op, user_data);
5069 msgs_move_to_cb (ModestMailOperation *mail_op,
5072 move_to_cb (mail_op, user_data);
5076 modest_ui_actions_move_folder_error_handler (ModestMailOperation *mail_op,
5079 ModestWindow *main_window = NULL;
5081 /* Disable next automatic folder selection */
5082 main_window = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (),
5083 FALSE); /* don't create */
5085 GObject *win = NULL;
5086 GtkWidget *folder_view = NULL;
5088 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (main_window),
5089 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
5090 modest_folder_view_disable_next_folder_selection (MODEST_FOLDER_VIEW(folder_view));
5092 if (user_data && TNY_IS_FOLDER (user_data)) {
5093 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view),
5094 TNY_FOLDER (user_data), FALSE);
5097 /* Show notification dialog only if the main window exists */
5098 win = modest_mail_operation_get_source (mail_op);
5099 modest_platform_run_information_dialog ((GtkWindow *) win,
5100 _("mail_in_ui_folder_move_target_error"),
5103 g_object_unref (win);
5108 open_msg_for_purge_cb (ModestMailOperation *mail_op,
5117 gint pending_purges = 0;
5118 gboolean some_purged = FALSE;
5119 ModestWindow *win = MODEST_WINDOW (user_data);
5120 ModestWindowMgr *mgr = modest_runtime_get_window_mgr ();
5122 /* If there was any error */
5123 if (!modest_ui_actions_msg_retrieval_check (mail_op, header, msg)) {
5124 modest_window_mgr_unregister_header (mgr, header);
5128 /* Once the message has been retrieved for purging, we check if
5129 * it's all ok for purging */
5131 parts = tny_simple_list_new ();
5132 tny_mime_part_get_parts (TNY_MIME_PART (msg), parts);
5133 iter = tny_list_create_iterator (parts);
5135 while (!tny_iterator_is_done (iter)) {
5137 part = TNY_MIME_PART (tny_iterator_get_current (iter));
5138 if (part && (tny_mime_part_is_attachment (part) || TNY_IS_MSG (part))) {
5139 if (tny_mime_part_is_purged (part))
5146 g_object_unref (part);
5148 tny_iterator_next (iter);
5150 g_object_unref (iter);
5153 if (pending_purges>0) {
5155 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),_("mcen_nc_purge_file_text_inbox"));
5157 if (response == GTK_RESPONSE_OK) {
5160 modest_platform_animation_banner (GTK_WIDGET (win), NULL, _("mcen_me_inbox_remove_attachments"));
5161 iter = tny_list_create_iterator (parts);
5162 while (!tny_iterator_is_done (iter)) {
5165 part = TNY_MIME_PART (tny_iterator_get_current (iter));
5166 if (part && (tny_mime_part_is_attachment (part) || TNY_IS_MSG (part)))
5167 tny_mime_part_set_purged (part);
5170 g_object_unref (part);
5172 tny_iterator_next (iter);
5174 g_object_unref (iter);
5176 tny_msg_rewrite_cache (msg);
5178 gtk_widget_destroy (info);
5182 modest_window_mgr_unregister_header (mgr, header);
5184 g_object_unref (parts);
5188 modest_ui_actions_on_main_window_remove_attachments (GtkAction *action,
5189 ModestMainWindow *win)
5191 GtkWidget *header_view;
5192 TnyList *header_list;
5194 TnyHeaderFlags flags;
5195 ModestWindow *msg_view_window = NULL;
5198 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win));
5200 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
5201 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
5203 header_list = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW (header_view));
5205 g_warning ("%s: no header selected", __FUNCTION__);
5209 if (tny_list_get_length (header_list) == 1) {
5210 TnyIterator *iter = tny_list_create_iterator (header_list);
5211 header = TNY_HEADER (tny_iterator_get_current (iter));
5212 g_object_unref (iter);
5216 if (!header || !TNY_IS_HEADER(header)) {
5217 g_warning ("%s: header is not valid", __FUNCTION__);
5221 found = modest_window_mgr_find_registered_header (modest_runtime_get_window_mgr (),
5222 header, &msg_view_window);
5223 flags = tny_header_get_flags (header);
5224 if (!(flags & TNY_HEADER_FLAG_CACHED))
5227 if (msg_view_window != NULL)
5228 modest_msg_view_window_remove_attachments (MODEST_MSG_VIEW_WINDOW (msg_view_window), TRUE);
5230 /* do nothing; uid was registered before, so window is probably on it's way */
5231 g_warning ("debug: header %p has already been registered", header);
5234 ModestMailOperation *mail_op = NULL;
5235 modest_window_mgr_register_header (modest_runtime_get_window_mgr (), header, NULL);
5236 mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT (win),
5237 modest_ui_actions_disk_operations_error_handler,
5239 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
5240 modest_mail_operation_get_msg (mail_op, header, FALSE, open_msg_for_purge_cb, win);
5242 g_object_unref (mail_op);
5245 g_object_unref (header);
5247 g_object_unref (header_list);
5251 * Checks if we need a connection to do the transfer and if the user
5252 * wants to connect to complete it
5255 modest_ui_actions_xfer_messages_check (GtkWindow *parent_window,
5256 TnyFolderStore *src_folder,
5258 TnyFolder *dst_folder,
5259 gboolean delete_originals,
5260 gboolean *need_connection,
5263 TnyAccount *src_account;
5264 gint uncached_msgs = 0;
5266 uncached_msgs = header_list_count_uncached_msgs (headers);
5268 /* We don't need any further check if
5270 * 1- the source folder is local OR
5271 * 2- the device is already online
5273 if (!modest_tny_folder_store_is_remote (src_folder) ||
5274 tny_device_is_online (modest_runtime_get_device())) {
5275 *need_connection = FALSE;
5280 /* We must ask for a connection when
5282 * - the message(s) is not already cached OR
5283 * - the message(s) is cached but the leave_on_server setting
5284 * is FALSE (because we need to sync the source folder to
5285 * delete the message from the server (for IMAP we could do it
5286 * offline, it'll take place the next time we get a
5289 src_account = get_account_from_folder_store (src_folder);
5290 if (uncached_msgs > 0) {
5294 *need_connection = TRUE;
5295 num_headers = tny_list_get_length (headers);
5296 msg = ngettext ("mcen_nc_get_msg", "mcen_nc_get_msgs", num_headers);
5298 if (modest_platform_run_confirmation_dialog (parent_window, msg) ==
5299 GTK_RESPONSE_CANCEL) {
5305 /* The transfer is possible and the user wants to */
5308 if (remote_folder_has_leave_on_server (src_folder) && delete_originals) {
5309 const gchar *account_name;
5310 gboolean leave_on_server;
5312 account_name = modest_tny_account_get_parent_modest_account_name_for_server_account (src_account);
5313 leave_on_server = modest_account_mgr_get_leave_on_server (modest_runtime_get_account_mgr (),
5316 if (leave_on_server == TRUE) {
5317 *need_connection = FALSE;
5319 *need_connection = TRUE;
5322 *need_connection = FALSE;
5327 g_object_unref (src_account);
5331 xfer_messages_error_handler (ModestMailOperation *mail_op,
5334 ModestWindow *main_window = NULL;
5336 /* Disable next automatic folder selection */
5337 main_window = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (),
5338 FALSE); /* don't create */
5340 GObject *win = modest_mail_operation_get_source (mail_op);
5341 modest_platform_run_information_dialog ((GtkWindow *) win,
5342 _("mail_in_ui_folder_move_target_error"),
5345 g_object_unref (win);
5347 move_to_helper_destroyer (user_data);
5351 TnyFolderStore *dst_folder;
5356 * Utility function that transfer messages from both the main window
5357 * and the msg view window when using the "Move to" dialog
5360 xfer_messages_performer (gboolean canceled,
5362 GtkWindow *parent_window,
5363 TnyAccount *account,
5366 ModestWindow *win = MODEST_WINDOW (parent_window);
5367 TnyAccount *dst_account = NULL;
5368 gboolean dst_forbids_message_add = FALSE;
5369 XferMsgsHelper *helper;
5370 MoveToHelper *movehelper;
5371 ModestMailOperation *mail_op;
5373 helper = (XferMsgsHelper *) user_data;
5375 if (canceled || err) {
5376 if (!check_memory_full_error ((GtkWidget *) parent_window, err)) {
5377 /* Show the proper error message */
5378 modest_ui_actions_on_account_connection_error (parent_window, account);
5383 dst_account = tny_folder_get_account (TNY_FOLDER (helper->dst_folder));
5385 /* tinymail will return NULL for local folders it seems */
5386 dst_forbids_message_add = modest_protocol_registry_protocol_type_has_tag (modest_runtime_get_protocol_registry (),
5387 modest_tny_account_get_protocol_type (dst_account),
5388 MODEST_PROTOCOL_REGISTRY_STORE_FORBID_MESSAGE_ADD);
5389 g_object_unref (dst_account);
5391 if (dst_forbids_message_add) {
5392 modest_platform_information_banner (GTK_WIDGET (win),
5394 ngettext("mail_in_ui_folder_move_target_error",
5395 "mail_in_ui_folder_move_targets_error",
5396 tny_list_get_length (helper->headers)));
5400 movehelper = g_new0 (MoveToHelper, 1);
5401 movehelper->banner = modest_platform_animation_banner (GTK_WIDGET (win), NULL,
5402 _CS("ckct_nw_pasting"));
5403 if (movehelper->banner != NULL) {
5404 g_object_ref (movehelper->banner);
5405 gtk_widget_show (GTK_WIDGET (movehelper->banner));
5408 if (MODEST_IS_MAIN_WINDOW (win)) {
5409 GtkWidget *header_view =
5410 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
5411 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
5412 movehelper->reference = get_next_after_selected_headers (MODEST_HEADER_VIEW (header_view));
5415 /* Perform the mail operation */
5416 mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT(win),
5417 xfer_messages_error_handler,
5419 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
5422 modest_mail_operation_xfer_msgs (mail_op,
5424 TNY_FOLDER (helper->dst_folder),
5429 g_object_unref (G_OBJECT (mail_op));
5431 g_object_unref (helper->dst_folder);
5432 g_object_unref (helper->headers);
5433 g_slice_free (XferMsgsHelper, helper);
5437 TnyFolder *src_folder;
5438 TnyFolderStore *dst_folder;
5439 gboolean delete_original;
5440 GtkWidget *folder_view;
5444 on_move_folder_cb (gboolean canceled, GError *err, GtkWindow *parent_window,
5445 TnyAccount *account, gpointer user_data)
5447 MoveFolderInfo *info = (MoveFolderInfo*)user_data;
5448 GtkTreeSelection *sel;
5449 ModestMailOperation *mail_op = NULL;
5451 if (canceled || err || !MODEST_IS_WINDOW (parent_window)) {
5452 g_object_unref (G_OBJECT (info->src_folder));
5453 g_object_unref (G_OBJECT (info->dst_folder));
5458 MoveToHelper *helper = g_new0 (MoveToHelper, 1);
5459 helper->banner = modest_platform_animation_banner (GTK_WIDGET (parent_window), NULL,
5460 _CS("ckct_nw_pasting"));
5461 if (helper->banner != NULL) {
5462 g_object_ref (helper->banner);
5463 gtk_widget_show (GTK_WIDGET(helper->banner));
5465 /* Clean folder on header view before moving it */
5466 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (info->folder_view));
5467 gtk_tree_selection_unselect_all (sel);
5469 /* Let gtk events run. We need that the folder
5470 view frees its reference to the source
5471 folder *before* issuing the mail operation
5472 so we need the signal handler of selection
5473 changed to happen before the mail
5475 while (gtk_events_pending ())
5476 gtk_main_iteration (); */
5479 modest_mail_operation_new_with_error_handling (G_OBJECT(parent_window),
5480 modest_ui_actions_move_folder_error_handler,
5481 info->src_folder, NULL);
5482 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
5485 /* Select *after* the changes */
5486 /* TODO: this function hangs UI after transfer */
5487 /* modest_folder_view_select_folder (MODEST_FOLDER_VIEW(folder_view), */
5488 /* TNY_FOLDER (src_folder), TRUE); */
5490 if (MODEST_IS_MAIN_WINDOW (parent_window)) {
5491 modest_folder_view_select_folder (MODEST_FOLDER_VIEW(info->folder_view),
5492 TNY_FOLDER (info->dst_folder), TRUE);
5494 modest_mail_operation_xfer_folder (mail_op,
5495 TNY_FOLDER (info->src_folder),
5497 info->delete_original,
5500 g_object_unref (G_OBJECT (info->src_folder));
5502 /* if (modest_mail_operation_get_status (mail_op) == MODEST_MAIL_OPERATION_STATUS_SUCCESS) { */
5505 /* Unref mail operation */
5506 g_object_unref (G_OBJECT (mail_op));
5507 g_object_unref (G_OBJECT (info->dst_folder));
5512 get_account_from_folder_store (TnyFolderStore *folder_store)
5514 if (TNY_IS_ACCOUNT (folder_store))
5515 return g_object_ref (folder_store);
5517 return tny_folder_get_account (TNY_FOLDER (folder_store));
5521 * UI handler for the "Move to" action when invoked from the
5525 modest_ui_actions_on_main_window_move_to (GtkAction *action,
5526 GtkWidget *folder_view,
5527 TnyFolderStore *dst_folder,
5528 ModestMainWindow *win)
5530 ModestHeaderView *header_view = NULL;
5531 TnyFolderStore *src_folder = NULL;
5533 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win));
5535 /* Get the source folder */
5536 src_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
5538 /* Get header view */
5539 header_view = (ModestHeaderView *)
5540 modest_main_window_get_child_widget (win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
5542 /* Get folder or messages to transfer */
5543 if (gtk_widget_is_focus (folder_view)) {
5544 gboolean do_xfer = TRUE;
5546 /* Allow only to transfer folders to the local root folder */
5547 if (TNY_IS_ACCOUNT (dst_folder) &&
5548 !MODEST_IS_TNY_LOCAL_FOLDERS_ACCOUNT (dst_folder) &&
5549 !modest_tny_account_is_memory_card_account (TNY_ACCOUNT (dst_folder))) {
5551 } else if (!TNY_IS_FOLDER (src_folder)) {
5552 g_warning ("%s: src_folder is not a TnyFolder.\n", __FUNCTION__);
5557 MoveFolderInfo *info = g_new0 (MoveFolderInfo, 1);
5558 DoubleConnectionInfo *connect_info = g_slice_new (DoubleConnectionInfo);
5560 info->src_folder = g_object_ref (src_folder);
5561 info->dst_folder = g_object_ref (dst_folder);
5562 info->delete_original = TRUE;
5563 info->folder_view = folder_view;
5565 connect_info->callback = on_move_folder_cb;
5566 connect_info->dst_account = get_account_from_folder_store (TNY_FOLDER_STORE (dst_folder));
5567 connect_info->data = info;
5569 modest_platform_double_connect_and_perform(GTK_WINDOW (win), TRUE,
5570 TNY_FOLDER_STORE (src_folder),
5573 } else if (gtk_widget_is_focus (GTK_WIDGET(header_view))) {
5576 headers = modest_header_view_get_selected_headers(header_view);
5578 /* Transfer the messages */
5579 modest_ui_actions_transfer_messages_helper (GTK_WINDOW (win), TNY_FOLDER (src_folder),
5580 headers, TNY_FOLDER (dst_folder));
5582 g_object_unref (headers);
5586 g_object_unref (src_folder);
5589 #ifdef MODEST_TOOLKIT_HILDON2
5591 * UI handler for the "Move to" action when invoked from the
5592 * ModestFolderWindow
5595 modest_ui_actions_on_folder_window_move_to (GtkWidget *folder_view,
5596 TnyFolderStore *dst_folder,
5600 TnyFolderStore *src_folder = NULL;
5601 TnyIterator *iterator;
5603 if (tny_list_get_length (selection) != 1)
5606 iterator = tny_list_create_iterator (selection);
5607 src_folder = TNY_FOLDER_STORE (tny_iterator_get_current (iterator));
5608 g_object_unref (iterator);
5611 gboolean do_xfer = TRUE;
5613 /* Allow only to transfer folders to the local root folder */
5614 if (TNY_IS_ACCOUNT (dst_folder) &&
5615 !MODEST_IS_TNY_LOCAL_FOLDERS_ACCOUNT (dst_folder) &&
5616 !modest_tny_account_is_memory_card_account (TNY_ACCOUNT (dst_folder))) {
5618 } else if (!TNY_IS_FOLDER (src_folder)) {
5619 g_warning ("%s: src_folder is not a TnyFolder.\n", __FUNCTION__);
5624 MoveFolderInfo *info = g_new0 (MoveFolderInfo, 1);
5625 DoubleConnectionInfo *connect_info = g_slice_new (DoubleConnectionInfo);
5627 info->src_folder = g_object_ref (src_folder);
5628 info->dst_folder = g_object_ref (dst_folder);
5629 info->delete_original = TRUE;
5630 info->folder_view = folder_view;
5632 connect_info->callback = on_move_folder_cb;
5633 connect_info->dst_account = get_account_from_folder_store (TNY_FOLDER_STORE (dst_folder));
5634 connect_info->data = info;
5636 modest_platform_double_connect_and_perform(GTK_WINDOW (win), TRUE,
5637 TNY_FOLDER_STORE (src_folder),
5641 g_object_unref (src_folder);
5647 modest_ui_actions_transfer_messages_helper (GtkWindow *win,
5648 TnyFolder *src_folder,
5650 TnyFolder *dst_folder)
5652 gboolean need_connection = TRUE;
5653 gboolean do_xfer = TRUE;
5654 XferMsgsHelper *helper;
5656 g_return_if_fail (TNY_IS_FOLDER (src_folder));
5657 g_return_if_fail (TNY_IS_FOLDER (dst_folder));
5658 g_return_if_fail (TNY_IS_LIST (headers));
5660 modest_ui_actions_xfer_messages_check (win, TNY_FOLDER_STORE (src_folder),
5661 headers, TNY_FOLDER (dst_folder),
5662 TRUE, &need_connection,
5665 /* If we don't want to transfer just return */
5669 /* Create the helper */
5670 helper = g_slice_new (XferMsgsHelper);
5671 helper->dst_folder = g_object_ref (dst_folder);
5672 helper->headers = g_object_ref (headers);
5674 if (need_connection) {
5675 DoubleConnectionInfo *connect_info = g_slice_new (DoubleConnectionInfo);
5676 connect_info->callback = xfer_messages_performer;
5677 connect_info->dst_account = tny_folder_get_account (TNY_FOLDER (dst_folder));
5678 connect_info->data = helper;
5680 modest_platform_double_connect_and_perform(GTK_WINDOW (win), TRUE,
5681 TNY_FOLDER_STORE (src_folder),
5684 TnyAccount *src_account = get_account_from_folder_store (TNY_FOLDER_STORE (src_folder));
5685 xfer_messages_performer (FALSE, NULL, GTK_WINDOW (win),
5686 src_account, helper);
5687 g_object_unref (src_account);
5692 * UI handler for the "Move to" action when invoked from the
5693 * ModestMsgViewWindow
5696 modest_ui_actions_on_window_move_to (GtkAction *action,
5698 TnyFolderStore *dst_folder,
5701 TnyFolder *src_folder = NULL;
5703 g_return_if_fail (TNY_IS_FOLDER (dst_folder));
5706 TnyHeader *header = NULL;
5709 iter = tny_list_create_iterator (headers);
5710 header = (TnyHeader *) tny_iterator_get_current (iter);
5711 src_folder = tny_header_get_folder (header);
5713 /* Transfer the messages */
5714 modest_ui_actions_transfer_messages_helper (GTK_WINDOW (win), src_folder,
5716 TNY_FOLDER (dst_folder));
5719 g_object_unref (header);
5720 g_object_unref (iter);
5721 g_object_unref (src_folder);
5726 modest_ui_actions_on_move_to (GtkAction *action,
5729 modest_ui_actions_on_edit_mode_move_to (win);
5733 modest_ui_actions_on_edit_mode_move_to (ModestWindow *win)
5735 GtkWidget *dialog = NULL, *folder_view = NULL;
5736 ModestMainWindow *main_window;
5737 MoveToInfo *helper = NULL;
5739 g_return_val_if_fail (MODEST_IS_WINDOW (win), FALSE);
5741 /* Get the main window if exists */
5742 if (MODEST_IS_MAIN_WINDOW (win))
5743 main_window = MODEST_MAIN_WINDOW (win);
5746 MODEST_MAIN_WINDOW (modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (),
5747 FALSE)); /* don't create */
5749 /* Get the folder view widget if exists */
5751 folder_view = modest_main_window_get_child_widget (main_window,
5752 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
5756 /* Create and run the dialog */
5757 dialog = create_move_to_dialog (GTK_WINDOW (win), folder_view);
5758 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (),
5759 GTK_WINDOW (dialog),
5763 helper = g_slice_new0 (MoveToInfo);
5764 helper->list = modest_platform_get_list_to_move (MODEST_WINDOW (win));
5767 /* Listen to response signal */
5768 g_signal_connect (dialog, "response", G_CALLBACK (on_move_to_dialog_response), helper);
5770 /* Show the dialog */
5771 gtk_widget_show (dialog);
5777 * Calls #HeadersFunc for each header already selected in the main
5778 * window or the message currently being shown in the msg view window
5781 do_headers_action (ModestWindow *win,
5785 TnyList *headers_list = NULL;
5786 TnyIterator *iter = NULL;
5787 TnyHeader *header = NULL;
5788 TnyFolder *folder = NULL;
5791 headers_list = get_selected_headers (win);
5795 /* Get the folder */
5796 iter = tny_list_create_iterator (headers_list);
5797 header = TNY_HEADER (tny_iterator_get_current (iter));
5799 folder = tny_header_get_folder (header);
5800 g_object_unref (header);
5803 /* Call the function for each header */
5804 while (!tny_iterator_is_done (iter)) {
5805 header = TNY_HEADER (tny_iterator_get_current (iter));
5806 func (header, win, user_data);
5807 g_object_unref (header);
5808 tny_iterator_next (iter);
5811 /* Trick: do a poke status in order to speed up the signaling
5813 tny_folder_poke_status (folder);
5816 g_object_unref (folder);
5817 g_object_unref (iter);
5818 g_object_unref (headers_list);
5822 modest_ui_actions_view_attachment (GtkAction *action,
5823 ModestWindow *window)
5825 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
5826 modest_msg_view_window_view_attachment (MODEST_MSG_VIEW_WINDOW (window), NULL);
5828 /* not supported window for this action */
5829 g_return_if_reached ();
5834 modest_ui_actions_save_attachments (GtkAction *action,
5835 ModestWindow *window)
5837 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
5839 if (modest_platform_check_memory_low (MODEST_WINDOW(window), TRUE))
5842 modest_msg_view_window_save_attachments (MODEST_MSG_VIEW_WINDOW (window), NULL);
5844 /* not supported window for this action */
5845 g_return_if_reached ();
5850 modest_ui_actions_remove_attachments (GtkAction *action,
5851 ModestWindow *window)
5853 if (MODEST_IS_MAIN_WINDOW (window)) {
5854 modest_ui_actions_on_main_window_remove_attachments (action, MODEST_MAIN_WINDOW (window));
5855 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
5856 modest_msg_view_window_remove_attachments (MODEST_MSG_VIEW_WINDOW (window), FALSE);
5858 /* not supported window for this action */
5859 g_return_if_reached ();
5864 modest_ui_actions_on_settings (GtkAction *action,
5869 dialog = modest_platform_get_global_settings_dialog ();
5870 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (win));
5871 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
5872 gtk_widget_show_all (dialog);
5874 gtk_dialog_run (GTK_DIALOG (dialog));
5876 gtk_widget_destroy (dialog);
5880 modest_ui_actions_on_help (GtkAction *action,
5883 /* Help app is not available at all in fremantle */
5884 #ifndef MODEST_TOOLKIT_HILDON2
5885 const gchar *help_id;
5887 g_return_if_fail (win && GTK_IS_WINDOW(win));
5889 help_id = modest_window_mgr_get_help_id (modest_runtime_get_window_mgr(), win);
5892 modest_platform_show_help (GTK_WINDOW (win), help_id);
5897 modest_ui_actions_on_csm_help (GtkAction *action,
5900 /* Help app is not available at all in fremantle */
5901 #ifndef MODEST_TOOLKIT_HILDON2
5903 const gchar* help_id = NULL;
5904 GtkWidget *folder_view;
5905 TnyFolderStore *folder_store;
5907 g_return_if_fail (win && MODEST_IS_MAIN_WINDOW (win));
5909 /* Get selected folder */
5910 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
5911 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
5912 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
5914 /* Switch help_id */
5915 if (folder_store && TNY_IS_FOLDER (folder_store))
5916 help_id = modest_tny_folder_get_help_id (TNY_FOLDER (folder_store));
5919 g_object_unref (folder_store);
5922 modest_platform_show_help (GTK_WINDOW (win), help_id);
5924 modest_ui_actions_on_help (action, win);
5929 retrieve_contents_cb (ModestMailOperation *mail_op,
5936 /* We only need this callback to show an error in case of
5937 memory low condition */
5938 modest_ui_actions_msg_retrieval_check (mail_op, header, msg);
5942 retrieve_msg_contents_performer (gboolean canceled,
5944 GtkWindow *parent_window,
5945 TnyAccount *account,
5948 ModestMailOperation *mail_op;
5949 TnyList *headers = TNY_LIST (user_data);
5951 if (err || canceled) {
5952 check_memory_full_error ((GtkWidget *) parent_window, err);
5956 /* Create mail operation */
5957 mail_op = modest_mail_operation_new_with_error_handling ((GObject *) parent_window,
5958 modest_ui_actions_disk_operations_error_handler,
5960 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
5961 modest_mail_operation_get_msgs_full (mail_op, headers, retrieve_contents_cb, NULL, NULL);
5964 g_object_unref (mail_op);
5966 g_object_unref (headers);
5967 g_object_unref (account);
5971 modest_ui_actions_on_retrieve_msg_contents (GtkAction *action,
5972 ModestWindow *window)
5974 TnyList *headers = NULL;
5975 TnyAccount *account = NULL;
5976 TnyIterator *iter = NULL;
5977 TnyHeader *header = NULL;
5978 TnyFolder *folder = NULL;
5981 headers = get_selected_headers (window);
5985 /* Pick the account */
5986 iter = tny_list_create_iterator (headers);
5987 header = TNY_HEADER (tny_iterator_get_current (iter));
5988 folder = tny_header_get_folder (header);
5989 account = tny_folder_get_account (folder);
5990 g_object_unref (folder);
5991 g_object_unref (header);
5992 g_object_unref (iter);
5994 /* Connect and perform the message retrieval */
5995 modest_platform_connect_and_perform ((GtkWindow *) window, TRUE,
5996 g_object_ref (account),
5997 retrieve_msg_contents_performer,
5998 g_object_ref (headers));
6001 g_object_unref (account);
6002 g_object_unref (headers);
6006 modest_ui_actions_check_toolbar_dimming_rules (ModestWindow *window)
6008 g_return_if_fail (MODEST_IS_WINDOW (window));
6011 modest_window_check_dimming_rules_group (window, MODEST_DIMMING_RULES_TOOLBAR);
6015 modest_ui_actions_check_menu_dimming_rules (ModestWindow *window)
6017 g_return_if_fail (MODEST_IS_WINDOW (window));
6020 modest_window_check_dimming_rules_group (window, MODEST_DIMMING_RULES_MENU);
6024 modest_ui_actions_on_email_menu_activated (GtkAction *action,
6025 ModestWindow *window)
6027 g_return_if_fail (MODEST_IS_WINDOW (window));
6030 modest_ui_actions_check_menu_dimming_rules (window);
6034 modest_ui_actions_on_edit_menu_activated (GtkAction *action,
6035 ModestWindow *window)
6037 g_return_if_fail (MODEST_IS_WINDOW (window));
6040 modest_ui_actions_check_menu_dimming_rules (window);
6044 modest_ui_actions_on_view_menu_activated (GtkAction *action,
6045 ModestWindow *window)
6047 g_return_if_fail (MODEST_IS_WINDOW (window));
6050 modest_ui_actions_check_menu_dimming_rules (window);
6054 modest_ui_actions_on_format_menu_activated (GtkAction *action,
6055 ModestWindow *window)
6057 g_return_if_fail (MODEST_IS_WINDOW (window));
6060 modest_ui_actions_check_menu_dimming_rules (window);
6064 modest_ui_actions_on_tools_menu_activated (GtkAction *action,
6065 ModestWindow *window)
6067 g_return_if_fail (MODEST_IS_WINDOW (window));
6070 modest_ui_actions_check_menu_dimming_rules (window);
6074 modest_ui_actions_on_attachment_menu_activated (GtkAction *action,
6075 ModestWindow *window)
6077 g_return_if_fail (MODEST_IS_WINDOW (window));
6080 modest_ui_actions_check_menu_dimming_rules (window);
6084 modest_ui_actions_on_toolbar_csm_menu_activated (GtkAction *action,
6085 ModestWindow *window)
6087 g_return_if_fail (MODEST_IS_WINDOW (window));
6090 modest_ui_actions_check_menu_dimming_rules (window);
6094 modest_ui_actions_on_folder_view_csm_menu_activated (GtkAction *action,
6095 ModestWindow *window)
6097 g_return_if_fail (MODEST_IS_WINDOW (window));
6100 modest_ui_actions_check_menu_dimming_rules (window);
6104 modest_ui_actions_on_header_view_csm_menu_activated (GtkAction *action,
6105 ModestWindow *window)
6107 g_return_if_fail (MODEST_IS_WINDOW (window));
6110 modest_ui_actions_check_menu_dimming_rules (window);
6114 modest_ui_actions_on_search_messages (GtkAction *action, ModestWindow *window)
6116 g_return_if_fail (MODEST_IS_WINDOW (window));
6118 /* we check for low-mem; in that case, show a warning, and don't allow
6121 if (modest_platform_check_memory_low (window, TRUE))
6124 modest_platform_show_search_messages (GTK_WINDOW (window));
6128 modest_ui_actions_on_open_addressbook (GtkAction *action, ModestWindow *win)
6130 g_return_if_fail (MODEST_IS_WINDOW (win));
6133 /* we check for low-mem; in that case, show a warning, and don't allow
6134 * for the addressbook
6136 if (modest_platform_check_memory_low (win, TRUE))
6140 modest_platform_show_addressbook (GTK_WINDOW (win));
6145 modest_ui_actions_on_toggle_find_in_page (GtkToggleAction *action,
6146 ModestWindow *window)
6148 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
6150 modest_msg_edit_window_toggle_find_toolbar (MODEST_MSG_EDIT_WINDOW (window), gtk_toggle_action_get_active (action));
6154 on_send_receive_finished (ModestMailOperation *mail_op,
6157 GtkWidget *header_view, *folder_view;
6158 TnyFolderStore *folder_store;
6159 ModestMainWindow *main_win = MODEST_MAIN_WINDOW (user_data);
6161 /* Set send/receive operation finished */
6162 modest_main_window_notify_send_receive_completed (main_win);
6164 /* Don't refresh the current folder if there were any errors */
6165 if (modest_mail_operation_get_status (mail_op) !=
6166 MODEST_MAIL_OPERATION_STATUS_SUCCESS)
6169 /* Refresh the current folder if we're viewing a window. We do
6170 this because the user won't be able to see the new mails in
6171 the selected folder after a Send&Receive because it only
6172 performs a poke_status, i.e, only the number of read/unread
6173 messages is updated, but the new headers are not
6175 folder_view = modest_main_window_get_child_widget (main_win,
6176 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
6180 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
6182 /* Do not need to refresh INBOX again because the
6183 update_account does it always automatically */
6184 if (folder_store && TNY_IS_FOLDER (folder_store) &&
6185 tny_folder_get_folder_type (TNY_FOLDER (folder_store)) != TNY_FOLDER_TYPE_INBOX) {
6186 ModestMailOperation *refresh_op;
6188 header_view = modest_main_window_get_child_widget (main_win,
6189 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
6191 /* We do not need to set the contents style
6192 because it hasn't changed. We also do not
6193 need to save the widget status. Just force
6195 refresh_op = modest_mail_operation_new (G_OBJECT (main_win));
6196 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), refresh_op);
6197 modest_mail_operation_refresh_folder (refresh_op, TNY_FOLDER (folder_store),
6198 folder_refreshed_cb, main_win);
6199 g_object_unref (refresh_op);
6203 g_object_unref (folder_store);
6208 modest_ui_actions_on_send_queue_error_happened (TnySendQueue *self,
6214 const gchar* server_name = NULL;
6215 TnyTransportAccount *server_account;
6216 gchar *message = NULL;
6218 /* Don't show anything if the user cancelled something or the
6219 * send receive request is not interactive. Authentication
6220 * errors are managed by the account store so no need to show
6221 * a dialog here again */
6222 if (err->code == TNY_SYSTEM_ERROR_CANCEL ||
6223 err->code == TNY_SERVICE_ERROR_AUTHENTICATE ||
6224 !modest_tny_send_queue_get_requested_send_receive (MODEST_TNY_SEND_QUEUE (self)))
6228 /* Get the server name: */
6230 TNY_TRANSPORT_ACCOUNT (tny_camel_send_queue_get_transport_account (TNY_CAMEL_SEND_QUEUE (self)));
6232 server_name = tny_account_get_hostname (TNY_ACCOUNT (server_account));
6234 g_return_if_reached ();
6236 /* Show the appropriate message text for the GError: */
6237 switch (err->code) {
6238 case TNY_SERVICE_ERROR_CONNECT:
6239 message = g_strdup_printf (_("emev_ib_ui_smtp_server_invalid"), server_name);
6241 case TNY_SERVICE_ERROR_SEND:
6242 message = g_strdup (dgettext("hildon-common-strings", "sfil_ib_unable_to_send"));
6244 case TNY_SERVICE_ERROR_UNAVAILABLE:
6245 message = g_strdup_printf (_("emev_ib_ui_smtp_server_invalid"), server_name);
6248 g_warning ("%s: unexpected ERROR %d",
6249 __FUNCTION__, err->code);
6250 message = g_strdup (dgettext("hildon-common-strings", "sfil_ib_unable_to_send"));
6254 modest_platform_run_information_dialog (NULL, message, FALSE);
6256 g_object_unref (server_account);
6260 modest_ui_actions_on_send_queue_status_changed (ModestTnySendQueue *send_queue,
6265 ModestMainWindow *main_window = NULL;
6266 ModestWindowMgr *mgr = NULL;
6267 GtkWidget *folder_view = NULL, *header_view = NULL;
6268 TnyFolderStore *selected_folder = NULL;
6269 TnyFolderType folder_type;
6271 mgr = modest_runtime_get_window_mgr ();
6272 main_window = MODEST_MAIN_WINDOW (modest_window_mgr_get_main_window (mgr,
6273 FALSE));/* don't create */
6277 /* Check if selected folder is OUTBOX */
6278 folder_view = modest_main_window_get_child_widget (main_window,
6279 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
6280 header_view = modest_main_window_get_child_widget (main_window,
6281 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
6283 selected_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
6284 if (!TNY_IS_FOLDER (selected_folder))
6287 /* gtk_tree_view_column_queue_resize is only available in GTK+ 2.8 */
6288 #if GTK_CHECK_VERSION(2, 8, 0)
6289 folder_type = modest_tny_folder_guess_folder_type (TNY_FOLDER (selected_folder));
6290 if (folder_type == TNY_FOLDER_TYPE_OUTBOX) {
6291 GtkTreeViewColumn *tree_column;
6293 tree_column = gtk_tree_view_get_column (GTK_TREE_VIEW (header_view),
6294 TNY_GTK_HEADER_LIST_MODEL_FROM_COLUMN);
6296 gtk_tree_view_column_queue_resize (tree_column);
6299 gtk_widget_queue_draw (header_view);
6302 /* Rerun dimming rules, because the message could become deletable for example */
6303 modest_window_check_dimming_rules_group (MODEST_WINDOW (main_window),
6304 MODEST_DIMMING_RULES_TOOLBAR);
6305 modest_window_check_dimming_rules_group (MODEST_WINDOW (main_window),
6306 MODEST_DIMMING_RULES_MENU);
6310 if (selected_folder != NULL)
6311 g_object_unref (selected_folder);
6315 modest_ui_actions_on_account_connection_error (GtkWindow *parent_window,
6316 TnyAccount *account)
6318 ModestProtocolType protocol_type;
6319 ModestProtocol *protocol;
6320 gchar *error_note = NULL;
6322 protocol_type = modest_tny_account_get_protocol_type (account);
6323 protocol = modest_protocol_registry_get_protocol_by_type (modest_runtime_get_protocol_registry (),
6326 error_note = modest_protocol_get_translation (protocol, MODEST_PROTOCOL_TRANSLATION_ACCOUNT_CONNECTION_ERROR, tny_account_get_hostname (account));
6327 if (error_note == NULL) {
6328 g_warning ("%s: This should not be reached", __FUNCTION__);
6330 modest_platform_run_information_dialog (parent_window, error_note, FALSE);
6331 g_free (error_note);
6336 modest_ui_actions_get_msg_already_deleted_error_msg (ModestWindow *win)
6340 TnyFolderStore *folder = NULL;
6341 TnyAccount *account = NULL;
6342 ModestProtocolType proto;
6343 ModestProtocol *protocol;
6344 TnyHeader *header = NULL;
6346 if (MODEST_IS_MAIN_WINDOW (win)) {
6347 GtkWidget *header_view;
6348 TnyList* headers = NULL;
6350 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
6351 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
6352 headers = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW (header_view));
6353 if (!headers || tny_list_get_length (headers) == 0) {
6355 g_object_unref (headers);
6358 iter = tny_list_create_iterator (headers);
6359 header = TNY_HEADER (tny_iterator_get_current (iter));
6360 folder = TNY_FOLDER_STORE (tny_header_get_folder (header));
6361 g_object_unref (iter);
6362 g_object_unref (headers);
6363 #ifdef MODEST_TOOLKIT_HILDON2
6364 } else if (MODEST_IS_HEADER_WINDOW (win)) {
6365 GtkWidget *header_view;
6366 TnyList* headers = NULL;
6368 header_view = GTK_WIDGET (modest_header_window_get_header_view (MODEST_HEADER_WINDOW (win)));
6369 headers = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW (header_view));
6370 if (!headers || tny_list_get_length (headers) == 0) {
6372 g_object_unref (headers);
6375 iter = tny_list_create_iterator (headers);
6376 header = TNY_HEADER (tny_iterator_get_current (iter));
6377 folder = TNY_FOLDER_STORE (tny_header_get_folder (header));
6378 g_object_unref (iter);
6379 g_object_unref (headers);
6381 } else if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
6382 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
6383 folder = TNY_FOLDER_STORE (tny_header_get_folder (header));
6386 /* Get the account type */
6387 account = tny_folder_get_account (TNY_FOLDER (folder));
6388 proto = modest_tny_account_get_protocol_type (account);
6389 protocol = modest_protocol_registry_get_protocol_by_type (modest_runtime_get_protocol_registry (),
6392 subject = tny_header_dup_subject (header);
6393 msg = modest_protocol_get_translation (protocol, MODEST_PROTOCOL_TRANSLATION_MSG_NOT_AVAILABLE, subject);
6397 msg = g_strdup_printf (_("mail_ni_ui_folder_get_msg_folder_error"));
6401 g_object_unref (account);
6402 g_object_unref (folder);
6403 g_object_unref (header);
6409 modest_ui_actions_on_delete_account (GtkWindow *parent_window,
6410 const gchar *account_name,
6411 const gchar *account_title)
6413 ModestAccountMgr *account_mgr;
6416 ModestProtocol *protocol;
6417 gboolean removed = FALSE;
6419 g_return_val_if_fail (account_name, FALSE);
6420 g_return_val_if_fail (account_title, FALSE);
6422 account_mgr = modest_runtime_get_account_mgr();
6424 /* The warning text depends on the account type: */
6425 protocol = modest_protocol_registry_get_protocol_by_type (modest_runtime_get_protocol_registry (),
6426 modest_account_mgr_get_store_protocol (account_mgr,
6428 txt = modest_protocol_get_translation (protocol,
6429 MODEST_PROTOCOL_TRANSLATION_DELETE_MAILBOX,
6432 txt = g_strdup_printf (_("emev_nc_delete_mailbox"), account_title);
6434 response = modest_platform_run_confirmation_dialog (parent_window, txt);
6438 if (response == GTK_RESPONSE_OK) {
6439 /* Remove account. If it succeeds then it also removes
6440 the account from the ModestAccountView: */
6441 gboolean is_default = FALSE;
6442 gchar *default_account_name = modest_account_mgr_get_default_account (account_mgr);
6443 if (default_account_name && (strcmp (default_account_name, account_name) == 0))
6445 g_free (default_account_name);
6447 removed = modest_account_mgr_remove_account (account_mgr, account_name);
6449 g_warning ("%s: modest_account_mgr_remove_account() failed.\n", __FUNCTION__);