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 static void modest_ui_actions_on_folder_window_move_to (GtkWidget *folder_view,
181 TnyFolderStore *dst_folder,
185 static void modest_ui_actions_on_window_move_to (GtkAction *action,
186 TnyList *list_to_move,
187 TnyFolderStore *dst_folder,
191 * This function checks whether a TnyFolderStore is a pop account
194 remote_folder_has_leave_on_server (TnyFolderStore *folder)
199 g_return_val_if_fail (TNY_IS_FOLDER_STORE (folder), FALSE);
201 account = get_account_from_folder_store (folder);
202 result = (modest_protocol_registry_protocol_type_has_leave_on_server (modest_runtime_get_protocol_registry (),
203 modest_tny_account_get_protocol_type (account)));
204 g_object_unref (account);
209 /* FIXME: this should be merged with the similar code in modest-account-view-window */
210 /* Show the account creation wizard dialog.
211 * returns: TRUE if an account was created. FALSE if the user cancelled.
214 modest_ui_actions_run_account_setup_wizard (ModestWindow *win)
216 gboolean result = FALSE;
218 gint dialog_response;
220 /* there is no such wizard yet */
221 wizard = GTK_WINDOW (modest_platform_get_account_settings_wizard ());
222 modest_window_mgr_set_modal (modest_runtime_get_window_mgr(), GTK_WINDOW (wizard), (GtkWindow *) win);
224 /* always present a main window in the background
225 * we do it here, so we cannot end up with two wizards (as this
226 * function might be called in modest_window_mgr_get_main_window as well */
228 win = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr(),
229 TRUE); /* create if not existent */
231 gtk_window_set_transient_for (GTK_WINDOW (wizard), GTK_WINDOW (win));
233 /* make sure the mainwindow is visible. We need to present the
234 wizard again to give it the focus back. show_all are needed
235 in order to get the widgets properly drawn (MainWindow main
236 paned won't be in its right position and the dialog will be
238 #ifndef MODEST_TOOLKIT_HILDON2
239 gtk_widget_show_all (GTK_WIDGET (win));
240 gtk_widget_show_all (GTK_WIDGET (wizard));
241 gtk_window_present (GTK_WINDOW (win));
242 gtk_window_present (GTK_WINDOW (wizard));
245 dialog_response = gtk_dialog_run (GTK_DIALOG (wizard));
246 gtk_widget_destroy (GTK_WIDGET (wizard));
247 if (gtk_events_pending ())
248 gtk_main_iteration ();
250 if (dialog_response == GTK_RESPONSE_CANCEL) {
253 /* Check whether an account was created: */
254 result = modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
261 modest_ui_actions_on_about (GtkAction *action, ModestWindow *win)
264 const gchar *authors[] = {
265 "Dirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>",
268 about = gtk_about_dialog_new ();
269 gtk_about_dialog_set_name (GTK_ABOUT_DIALOG(about), PACKAGE_NAME);
270 gtk_about_dialog_set_version (GTK_ABOUT_DIALOG(about),PACKAGE_VERSION);
271 gtk_about_dialog_set_copyright (GTK_ABOUT_DIALOG(about),
272 _("Copyright (c) 2006, Nokia Corporation\n"
273 "All rights reserved."));
274 gtk_about_dialog_set_comments (GTK_ABOUT_DIALOG(about),
275 _("a modest e-mail client\n\n"
276 "design and implementation: Dirk-Jan C. Binnema\n"
277 "contributions from the fine people at KC and Ig\n"
278 "uses the tinymail email framework written by Philip van Hoof"));
279 gtk_about_dialog_set_authors (GTK_ABOUT_DIALOG(about), authors);
280 gtk_about_dialog_set_website (GTK_ABOUT_DIALOG(about), "http://modest.garage.maemo.org");
281 gtk_window_set_transient_for (GTK_WINDOW (about), GTK_WINDOW (win));
282 gtk_window_set_modal (GTK_WINDOW (about), TRUE);
284 gtk_dialog_run (GTK_DIALOG (about));
285 gtk_widget_destroy(about);
289 * Gets the list of currently selected messages. If the win is the
290 * main window, then it returns a newly allocated list of the headers
291 * selected in the header view. If win is the msg view window, then
292 * the value returned is a list with just a single header.
294 * The caller of this funcion must free the list.
297 get_selected_headers (ModestWindow *win)
299 if (MODEST_IS_MAIN_WINDOW(win)) {
300 GtkWidget *header_view;
302 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
303 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
304 return modest_header_view_get_selected_headers (MODEST_HEADER_VIEW(header_view));
306 } else if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
307 /* for MsgViewWindows, we simply return a list with one element */
309 TnyList *list = NULL;
311 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
312 if (header != NULL) {
313 list = tny_simple_list_new ();
314 tny_list_prepend (list, G_OBJECT(header));
315 g_object_unref (G_OBJECT(header));
320 #ifdef MODEST_TOOLKIT_HILDON2
321 } else if (MODEST_IS_HEADER_WINDOW (win)) {
322 GtkWidget *header_view;
324 header_view = GTK_WIDGET (modest_header_window_get_header_view (MODEST_HEADER_WINDOW (win)));
325 return modest_header_view_get_selected_headers (MODEST_HEADER_VIEW(header_view));
331 static GtkTreeRowReference *
332 get_next_after_selected_headers (ModestHeaderView *header_view)
334 GtkTreeSelection *sel;
335 GList *selected_rows, *node;
337 GtkTreeRowReference *result;
340 model = gtk_tree_view_get_model (GTK_TREE_VIEW (header_view));
341 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
342 selected_rows = gtk_tree_selection_get_selected_rows (sel, NULL);
344 if (selected_rows == NULL)
347 node = g_list_last (selected_rows);
348 path = gtk_tree_path_copy ((GtkTreePath *) node->data);
349 gtk_tree_path_next (path);
351 result = gtk_tree_row_reference_new (model, path);
353 gtk_tree_path_free (path);
354 g_list_foreach (selected_rows, (GFunc) gtk_tree_path_free, NULL);
355 g_list_free (selected_rows);
361 headers_action_mark_as_read (TnyHeader *header,
365 TnyHeaderFlags flags;
367 g_return_if_fail (TNY_IS_HEADER(header));
369 flags = tny_header_get_flags (header);
370 if (flags & TNY_HEADER_FLAG_SEEN) return;
371 tny_header_set_flag (header, TNY_HEADER_FLAG_SEEN);
375 headers_action_mark_as_unread (TnyHeader *header,
379 TnyHeaderFlags flags;
381 g_return_if_fail (TNY_IS_HEADER(header));
383 flags = tny_header_get_flags (header);
384 if (flags & TNY_HEADER_FLAG_SEEN) {
385 tny_header_unset_flag (header, TNY_HEADER_FLAG_SEEN);
389 /** After deleing a message that is currently visible in a window,
390 * show the next message from the list, or close the window if there are no more messages.
393 modest_ui_actions_refresh_message_window_after_delete (ModestMsgViewWindow* win)
395 /* Close msg view window or select next */
396 if (!modest_msg_view_window_select_next_message (win) &&
397 !modest_msg_view_window_select_previous_message (win)) {
399 g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value);
405 modest_ui_actions_on_delete_message (GtkAction *action, ModestWindow *win)
407 modest_ui_actions_on_edit_mode_delete_message (win);
411 modest_ui_actions_on_edit_mode_delete_message (ModestWindow *win)
413 TnyList *header_list = NULL;
414 TnyIterator *iter = NULL;
415 TnyHeader *header = NULL;
416 gchar *message = NULL;
419 ModestWindowMgr *mgr;
420 GtkWidget *header_view = NULL;
421 gboolean retval = TRUE;
423 g_return_val_if_fail (MODEST_IS_WINDOW(win), FALSE);
425 /* Check first if the header view has the focus */
426 if (MODEST_IS_MAIN_WINDOW (win)) {
428 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
429 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
430 if (!gtk_widget_is_focus (header_view))
434 /* Get the headers, either from the header view (if win is the main window),
435 * or from the message view window: */
436 header_list = get_selected_headers (win);
437 if (!header_list) return FALSE;
439 /* Check if any of the headers are already opened, or in the process of being opened */
440 if (MODEST_IS_MAIN_WINDOW (win)) {
441 gint opened_headers = 0;
443 iter = tny_list_create_iterator (header_list);
444 mgr = modest_runtime_get_window_mgr ();
445 while (!tny_iterator_is_done (iter)) {
446 header = TNY_HEADER (tny_iterator_get_current (iter));
448 if (modest_window_mgr_find_registered_header (mgr, header, NULL))
450 g_object_unref (header);
452 tny_iterator_next (iter);
454 g_object_unref (iter);
456 if (opened_headers > 0) {
459 msg = g_strdup_printf (_("mcen_nc_unable_to_delete_n_messages"),
462 modest_platform_run_information_dialog (GTK_WINDOW (win), (const gchar *) msg, FALSE);
465 g_object_unref (header_list);
471 if (tny_list_get_length(header_list) == 1) {
472 iter = tny_list_create_iterator (header_list);
473 header = TNY_HEADER (tny_iterator_get_current (iter));
476 subject = tny_header_dup_subject (header);
478 subject = g_strdup (_("mail_va_no_subject"));
479 desc = g_strdup_printf ("%s", subject);
481 g_object_unref (header);
484 g_object_unref (iter);
486 message = g_strdup_printf(ngettext("emev_nc_delete_message", "emev_nc_delete_messages",
487 tny_list_get_length(header_list)), desc);
489 /* Confirmation dialog */
490 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
494 if (response == GTK_RESPONSE_OK) {
495 ModestWindow *main_window = NULL;
496 ModestWindowMgr *mgr = NULL;
497 GtkTreeModel *model = NULL;
498 GtkTreeSelection *sel = NULL;
499 GList *sel_list = NULL, *tmp = NULL;
500 GtkTreeRowReference *next_row_reference = NULL;
501 GtkTreeRowReference *prev_row_reference = NULL;
502 GtkTreePath *next_path = NULL;
503 GtkTreePath *prev_path = NULL;
504 ModestMailOperation *mail_op = NULL;
506 /* Find last selected row */
507 if (MODEST_IS_MAIN_WINDOW (win)) {
508 model = gtk_tree_view_get_model (GTK_TREE_VIEW (header_view));
509 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
510 sel_list = gtk_tree_selection_get_selected_rows (sel, &model);
511 for (tmp=sel_list; tmp; tmp=tmp->next) {
512 if (tmp->next == NULL) {
513 prev_path = gtk_tree_path_copy((GtkTreePath *) tmp->data);
514 next_path = gtk_tree_path_copy((GtkTreePath *) tmp->data);
516 gtk_tree_path_prev (prev_path);
517 gtk_tree_path_next (next_path);
519 prev_row_reference = gtk_tree_row_reference_new (model, prev_path);
520 next_row_reference = gtk_tree_row_reference_new (model, next_path);
525 /* Disable window dimming management */
526 modest_window_disable_dimming (MODEST_WINDOW(win));
528 /* Remove each header. If it's a view window header_view == NULL */
529 mail_op = modest_mail_operation_new ((GObject *) win);
530 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
532 modest_mail_operation_remove_msgs (mail_op, header_list, FALSE);
533 g_object_unref (mail_op);
535 /* Enable window dimming management */
537 gtk_tree_selection_unselect_all (sel);
539 modest_window_enable_dimming (MODEST_WINDOW(win));
541 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
542 modest_ui_actions_refresh_message_window_after_delete (MODEST_MSG_VIEW_WINDOW (win));
544 /* Get main window */
545 mgr = modest_runtime_get_window_mgr ();
546 main_window = modest_window_mgr_get_main_window (mgr, FALSE); /* don't create */
547 } else if (MODEST_IS_MAIN_WINDOW (win)) {
548 /* Move cursor to next row */
551 /* Select next or previous row */
552 if (gtk_tree_row_reference_valid (next_row_reference)) {
553 gtk_tree_selection_select_path (sel, next_path);
555 else if (gtk_tree_row_reference_valid (prev_row_reference)) {
556 gtk_tree_selection_select_path (sel, prev_path);
560 if (gtk_tree_row_reference_valid (next_row_reference))
561 gtk_tree_row_reference_free (next_row_reference);
562 if (next_path != NULL)
563 gtk_tree_path_free (next_path);
564 if (gtk_tree_row_reference_valid (prev_row_reference))
565 gtk_tree_row_reference_free (prev_row_reference);
566 if (prev_path != NULL)
567 gtk_tree_path_free (prev_path);
570 /* Update toolbar dimming state */
572 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (main_window));
573 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
577 g_list_foreach (sel_list, (GFunc) gtk_tree_path_free, NULL);
578 g_list_free (sel_list);
587 g_object_unref (header_list);
595 /* delete either message or folder, based on where we are */
597 modest_ui_actions_on_delete_message_or_folder (GtkAction *action, ModestWindow *win)
599 g_return_if_fail (MODEST_IS_WINDOW(win));
601 /* Check first if the header view has the focus */
602 if (MODEST_IS_MAIN_WINDOW (win)) {
604 w = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
605 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
606 if (gtk_widget_is_focus (w)) {
607 modest_ui_actions_on_delete_folder (action, MODEST_WINDOW(win));
611 modest_ui_actions_on_delete_message (action, win);
615 modest_ui_actions_on_quit (GtkAction *action, ModestWindow *win)
617 ModestWindowMgr *mgr = NULL;
619 #ifdef MODEST_PLATFORM_MAEMO
620 modest_osso_save_state();
621 #endif /* MODEST_PLATFORM_MAEMO */
623 g_debug ("closing down, clearing %d item(s) from operation queue",
624 modest_mail_operation_queue_num_elements
625 (modest_runtime_get_mail_operation_queue()));
627 /* cancel all outstanding operations */
628 modest_mail_operation_queue_cancel_all
629 (modest_runtime_get_mail_operation_queue());
631 g_debug ("queue has been cleared");
634 /* Check if there are opened editing windows */
635 mgr = modest_runtime_get_window_mgr ();
636 modest_window_mgr_close_all_windows (mgr);
638 /* note: when modest-tny-account-store is finalized,
639 it will automatically set all network connections
642 /* gtk_main_quit (); */
646 modest_ui_actions_on_close_window (GtkAction *action, ModestWindow *win)
650 g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value);
652 /* if (MODEST_IS_MSG_VIEW_WINDOW (win)) { */
653 /* gtk_widget_destroy (GTK_WIDGET (win)); */
654 /* } else if (MODEST_IS_MSG_EDIT_WINDOW (win)) { */
655 /* gboolean ret_value; */
656 /* g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value); */
657 /* } else if (MODEST_IS_WINDOW (win)) { */
658 /* gtk_widget_destroy (GTK_WIDGET (win)); */
660 /* g_return_if_reached (); */
665 modest_ui_actions_add_to_contacts (GtkAction *action, ModestWindow *win)
667 g_return_if_fail (MODEST_IS_MSG_VIEW_WINDOW (win));
669 modest_msg_view_window_add_to_contacts (MODEST_MSG_VIEW_WINDOW (win));
673 modest_ui_actions_on_add_to_contacts (GtkAction *action, ModestWindow *win)
675 GtkClipboard *clipboard = NULL;
676 gchar *selection = NULL;
678 clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
679 selection = gtk_clipboard_wait_for_text (clipboard);
681 /* Question: why is the clipboard being used here?
682 * It doesn't really make a lot of sense. */
686 modest_address_book_add_address (selection);
692 modest_ui_actions_on_new_account (GtkAction *action,
693 ModestWindow *window)
695 modest_ui_actions_run_account_setup_wizard (window);
699 modest_ui_actions_on_accounts (GtkAction *action,
702 /* This is currently only implemented for Maemo */
703 if (!modest_account_mgr_has_accounts (modest_runtime_get_account_mgr(), TRUE)) {
704 if (!modest_ui_actions_run_account_setup_wizard (win))
705 g_debug ("%s: wizard was already running", __FUNCTION__);
709 /* Show the list of accounts */
710 GtkWindow *account_win = GTK_WINDOW (modest_account_view_window_new ());
712 /* The accounts dialog must be modal */
713 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (account_win), (GtkWindow *) win);
714 modest_utils_show_dialog_and_forget (GTK_WINDOW (win), GTK_DIALOG (account_win));
719 modest_ui_actions_on_smtp_servers (GtkAction *action, ModestWindow *win)
721 /* This is currently only implemented for Maemo,
722 * because it requires an API (libconic) to detect different connection
725 #ifndef MODEST_TOOLKIT_GTK /* Defined in config.h */
727 /* Create the window if necessary: */
728 GtkWidget *specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
729 modest_connection_specific_smtp_window_fill_with_connections (
730 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (specific_window),
731 modest_runtime_get_account_mgr());
733 /* Show the window: */
734 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (),
735 GTK_WINDOW (specific_window), (GtkWindow *) win);
736 gtk_widget_show (specific_window);
737 #endif /* !MODEST_TOOLKIT_GTK */
741 modest_ui_actions_compose_msg(ModestWindow *win,
744 const gchar *bcc_str,
745 const gchar *subject_str,
746 const gchar *body_str,
748 gboolean set_as_modified)
750 gchar *account_name = NULL;
752 TnyAccount *account = NULL;
753 TnyFolder *folder = NULL;
754 gchar *from_str = NULL, *signature = NULL, *body = NULL;
755 gboolean use_signature = FALSE;
756 ModestWindow *msg_win = NULL;
757 ModestAccountMgr *mgr = modest_runtime_get_account_mgr();
758 ModestTnyAccountStore *store = modest_runtime_get_account_store();
759 GnomeVFSFileSize total_size, allowed_size;
761 /* we check for low-mem */
762 if (modest_platform_check_memory_low (win, TRUE))
765 #ifdef MODEST_TOOLKIT_HILDON2
766 account_name = g_strdup (modest_window_get_active_account(win));
769 account_name = modest_account_mgr_get_default_account(mgr);
772 g_printerr ("modest: no account found\n");
775 account = modest_tny_account_store_get_server_account (store, account_name, TNY_ACCOUNT_TYPE_STORE);
777 g_printerr ("modest: failed to get tnyaccount for '%s'\n", account_name);
780 folder = modest_tny_account_get_special_folder (account, TNY_FOLDER_TYPE_DRAFTS);
782 g_printerr ("modest: failed to find Drafts folder\n");
785 from_str = modest_account_mgr_get_from_string (mgr, account_name);
787 g_printerr ("modest: failed get from string for '%s'\n", account_name);
791 signature = modest_account_mgr_get_signature (mgr, account_name, &use_signature);
792 if (body_str != NULL) {
793 body = use_signature ? g_strconcat(body_str, "\n--\n", signature, NULL) : g_strdup(body_str);
795 body = use_signature ? g_strconcat("\n--\n", signature, NULL) : g_strdup("");
798 msg = modest_tny_msg_new (to_str, from_str, cc_str, bcc_str, subject_str, body, NULL, NULL, NULL);
800 g_printerr ("modest: failed to create new msg\n");
804 /* Create and register edit window */
805 /* This is destroyed by TODO. */
807 allowed_size = MODEST_MAX_ATTACHMENT_SIZE;
808 msg_win = modest_msg_edit_window_new (msg, account_name, FALSE);
810 if (!modest_window_mgr_register_window (modest_runtime_get_window_mgr(), msg_win, win)) {
811 gtk_widget_destroy (GTK_WIDGET (msg_win));
814 modest_msg_edit_window_set_modified (MODEST_MSG_EDIT_WINDOW (msg_win), set_as_modified);
815 gtk_widget_show_all (GTK_WIDGET (msg_win));
817 while (attachments) {
819 modest_msg_edit_window_attach_file_one((ModestMsgEditWindow *)msg_win,
820 attachments->data, allowed_size);
822 if (total_size > allowed_size) {
823 g_warning ("%s: total size: %u",
824 __FUNCTION__, (unsigned int)total_size);
827 allowed_size -= total_size;
829 attachments = g_slist_next(attachments);
836 g_free (account_name);
838 g_object_unref (G_OBJECT(account));
840 g_object_unref (G_OBJECT(folder));
842 g_object_unref (G_OBJECT(msg));
846 modest_ui_actions_on_new_msg (GtkAction *action, ModestWindow *win)
848 /* if there are no accounts yet, just show the wizard */
849 if (!modest_account_mgr_has_accounts (modest_runtime_get_account_mgr(), TRUE))
850 if (!modest_ui_actions_run_account_setup_wizard (win))
853 modest_ui_actions_compose_msg(win, NULL, NULL, NULL, NULL, NULL, NULL, FALSE);
858 modest_ui_actions_msg_retrieval_check (ModestMailOperation *mail_op,
862 ModestMailOperationStatus status;
864 /* If there is no message or the operation was not successful */
865 status = modest_mail_operation_get_status (mail_op);
866 if (!msg || status != MODEST_MAIL_OPERATION_STATUS_SUCCESS) {
869 /* If it's a memory low issue, then show a banner */
870 error = modest_mail_operation_get_error (mail_op);
871 if (error && error->domain == MODEST_MAIL_OPERATION_ERROR &&
872 error->code == MODEST_MAIL_OPERATION_ERROR_LOW_MEMORY) {
873 GObject *source = modest_mail_operation_get_source (mail_op);
874 modest_platform_run_information_dialog (GTK_IS_WINDOW (source) ? GTK_WINDOW (source) : NULL,
875 dgettext("ke-recv","memr_ib_operation_disabled"),
877 g_object_unref (source);
880 if (error && ((error->code == TNY_SERVICE_ERROR_NO_SUCH_MESSAGE) ||
881 error->code == TNY_SERVICE_ERROR_MESSAGE_NOT_AVAILABLE)) {
882 gchar *subject, *msg;
883 subject = tny_header_dup_subject (header);
885 subject = g_strdup (_("mail_va_no_subject"));;
886 msg = g_strdup_printf (_("emev_ni_ui_imap_message_not_available_in_server"),
888 modest_platform_run_information_dialog (NULL, msg, FALSE);
893 /* Remove the header from the preregistered uids */
894 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (),
912 OpenMsgBannerInfo *banner_info;
913 GtkTreeRowReference *rowref;
917 open_msg_banner_idle (gpointer userdata)
919 OpenMsgBannerInfo *banner_info = (OpenMsgBannerInfo *) userdata;
921 gdk_threads_enter ();
922 banner_info->idle_handler = 0;
923 banner_info->banner = modest_platform_animation_banner (NULL, NULL, banner_info->message);
925 g_object_ref (banner_info->banner);
927 gdk_threads_leave ();
934 get_header_view_from_window (ModestWindow *window)
936 GtkWidget *header_view;
938 if (MODEST_IS_MAIN_WINDOW (window)) {
939 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (window),
940 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
941 #ifdef MODEST_TOOLKIT_HILDON2
942 } else if (MODEST_IS_HEADER_WINDOW (window)){
943 header_view = GTK_WIDGET (modest_header_window_get_header_view (MODEST_HEADER_WINDOW (window)));
953 get_info_from_header (TnyHeader *header, gboolean *is_draft)
956 gchar *account = NULL;
957 TnyFolderType folder_type = TNY_FOLDER_TYPE_UNKNOWN;
961 folder = tny_header_get_folder (header);
962 /* Gets folder type (OUTBOX headers will be opened in edit window */
963 if (modest_tny_folder_is_local_folder (folder)) {
964 folder_type = modest_tny_folder_get_local_or_mmc_folder_type (folder);
965 if (folder_type == TNY_FOLDER_TYPE_INVALID)
966 g_warning ("%s: BUG: TNY_FOLDER_TYPE_INVALID", __FUNCTION__);
969 if (folder_type == TNY_FOLDER_TYPE_OUTBOX) {
970 TnyTransportAccount *traccount = NULL;
971 ModestTnyAccountStore *accstore = modest_runtime_get_account_store();
972 traccount = modest_tny_account_store_get_transport_account_from_outbox_header(accstore, header);
974 ModestTnySendQueue *send_queue = NULL;
975 ModestTnySendQueueStatus status;
977 account = g_strdup(modest_tny_account_get_parent_modest_account_name_for_server_account(
978 TNY_ACCOUNT(traccount)));
979 send_queue = modest_runtime_get_send_queue(traccount, TRUE);
980 if (TNY_IS_SEND_QUEUE (send_queue)) {
981 msg_id = modest_tny_send_queue_get_msg_id (header);
982 status = modest_tny_send_queue_get_msg_status(send_queue, msg_id);
984 /* Only open messages in outbox with the editor if they are in Failed state */
985 if (status == MODEST_TNY_SEND_QUEUE_FAILED) {
988 #ifdef MODEST_TOOLKIT_HILDON2
990 /* In Fremantle we can not
991 open any message from
992 outbox which is not in
994 g_object_unref(traccount);
998 g_object_unref(traccount);
1000 g_warning("Cannot get transport account for message in outbox!!");
1002 } else if (folder_type == TNY_FOLDER_TYPE_DRAFTS) {
1003 *is_draft = TRUE; /* Open in editor if the message is in the Drafts folder */
1006 g_object_unref (folder);
1012 open_msg_cb (ModestMailOperation *mail_op,
1019 ModestWindowMgr *mgr = NULL;
1020 ModestWindow *parent_win = NULL;
1021 ModestWindow *win = NULL;
1022 gchar *account = NULL;
1023 gboolean open_in_editor = FALSE;
1024 OpenMsgHelper *helper = (OpenMsgHelper *) user_data;
1026 /* Do nothing if there was any problem with the mail
1027 operation. The error will be shown by the error_handler of
1028 the mail operation */
1029 if (!modest_ui_actions_msg_retrieval_check (mail_op, header, msg))
1032 parent_win = (ModestWindow *) modest_mail_operation_get_source (mail_op);
1034 /* Mark header as read */
1035 headers_action_mark_as_read (header, MODEST_WINDOW(parent_win), NULL);
1037 account = get_info_from_header (header, &open_in_editor);
1041 account = g_strdup (modest_window_get_active_account (MODEST_WINDOW (parent_win)));
1043 account = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
1045 if (open_in_editor) {
1046 ModestAccountMgr *mgr = modest_runtime_get_account_mgr ();
1047 gchar *from_header = NULL, *acc_name;
1049 from_header = tny_header_dup_from (header);
1051 /* we cannot edit without a valid account... */
1052 if (!modest_account_mgr_has_accounts(mgr, TRUE)) {
1053 if (!modest_ui_actions_run_account_setup_wizard(parent_win)) {
1054 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (),
1056 g_free (from_header);
1061 acc_name = modest_utils_get_account_name_from_recipient (from_header);
1062 g_free (from_header);
1068 win = modest_msg_edit_window_new (msg, account, TRUE);
1070 gchar *uid = modest_tny_folder_get_header_unique_id (header);
1072 if (helper->rowref && helper->model) {
1073 win = modest_msg_view_window_new_with_header_model (msg, account, (const gchar*) uid,
1074 helper->model, helper->rowref);
1076 win = modest_msg_view_window_new_for_attachment (msg, account, (const gchar*) uid);
1081 /* Register and show new window */
1083 mgr = modest_runtime_get_window_mgr ();
1084 if (!modest_window_mgr_register_window (mgr, win, NULL)) {
1085 gtk_widget_destroy (GTK_WIDGET (win));
1088 gtk_widget_show_all (GTK_WIDGET(win));
1091 /* Update toolbar dimming state */
1092 if (MODEST_IS_MAIN_WINDOW (parent_win)) {
1093 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (parent_win));
1099 g_object_unref (parent_win);
1103 is_memory_full_error (GError *error)
1105 gboolean enough_free_space = TRUE;
1106 GnomeVFSURI *cache_dir_uri;
1107 const gchar *cache_dir;
1108 GnomeVFSFileSize free_space;
1110 cache_dir = tny_account_store_get_cache_dir (TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()));
1111 cache_dir_uri = gnome_vfs_uri_new (cache_dir);
1112 if (gnome_vfs_get_volume_free_space (cache_dir_uri, &free_space) == GNOME_VFS_OK) {
1113 if (free_space < MIN_FREE_SPACE)
1114 enough_free_space = FALSE;
1116 gnome_vfs_uri_unref (cache_dir_uri);
1118 if ((error->code == TNY_SYSTEM_ERROR_MEMORY ||
1119 /* When asking for a mail and no space left on device
1120 tinymail returns this error */
1121 error->code == TNY_SERVICE_ERROR_MESSAGE_NOT_AVAILABLE ||
1122 /* When the folder summary could not be read or
1124 error->code == TNY_IO_ERROR_WRITE ||
1125 error->code == TNY_IO_ERROR_READ) &&
1126 !enough_free_space) {
1134 check_memory_full_error (GtkWidget *parent_window, GError *err)
1139 if (is_memory_full_error (err))
1140 modest_platform_information_banner (parent_window,
1141 NULL, dgettext("ke-recv",
1142 "cerm_device_memory_full"));
1143 else if (err->code == TNY_SYSTEM_ERROR_MEMORY)
1144 /* If the account was created in memory full
1145 conditions then tinymail won't be able to
1146 connect so it'll return this error code */
1147 modest_platform_information_banner (parent_window,
1148 NULL, _("emev_ui_imap_inbox_select_error"));
1156 modest_ui_actions_disk_operations_error_handler (ModestMailOperation *mail_op,
1159 const GError *error;
1160 GObject *win = NULL;
1161 ModestMailOperationStatus status;
1163 win = modest_mail_operation_get_source (mail_op);
1164 error = modest_mail_operation_get_error (mail_op);
1165 status = modest_mail_operation_get_status (mail_op);
1167 /* If the mail op has been cancelled then it's not an error:
1168 don't show any message */
1169 if (status != MODEST_MAIL_OPERATION_STATUS_CANCELED) {
1170 if (is_memory_full_error ((GError *) error)) {
1171 modest_platform_information_banner ((GtkWidget *) win,
1172 NULL, dgettext("ke-recv",
1173 "cerm_device_memory_full"));
1174 } else if (error->code == TNY_SYSTEM_ERROR_MEMORY) {
1175 modest_platform_information_banner ((GtkWidget *) win,
1176 NULL, _("emev_ui_imap_inbox_select_error"));
1177 } else if (error->domain == MODEST_MAIL_OPERATION_ERROR &&
1178 error->code == MODEST_MAIL_OPERATION_ERROR_FILE_IO) {
1179 modest_platform_information_banner ((GtkWidget *) win,
1180 NULL, dgettext ("hildon-common-strings", "sfil_ni_unable_to_open_file_not_found"));
1181 } else if (user_data) {
1182 modest_platform_information_banner ((GtkWidget *) win,
1188 g_object_unref (win);
1192 * Returns the account a list of headers belongs to. It returns a
1193 * *new* reference so don't forget to unref it
1196 get_account_from_header_list (TnyList *headers)
1198 TnyAccount *account = NULL;
1200 if (tny_list_get_length (headers) > 0) {
1201 TnyIterator *iter = tny_list_create_iterator (headers);
1202 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter));
1203 TnyFolder *folder = tny_header_get_folder (header);
1206 g_object_unref (header);
1208 while (!tny_iterator_is_done (iter)) {
1209 header = TNY_HEADER (tny_iterator_get_current (iter));
1210 folder = tny_header_get_folder (header);
1213 g_object_unref (header);
1215 tny_iterator_next (iter);
1220 account = tny_folder_get_account (folder);
1221 g_object_unref (folder);
1225 g_object_unref (header);
1227 g_object_unref (iter);
1233 get_account_from_header (TnyHeader *header)
1235 TnyAccount *account = NULL;
1238 folder = tny_header_get_folder (header);
1241 account = tny_folder_get_account (folder);
1242 g_object_unref (folder);
1249 open_msg_helper_destroyer (gpointer user_data)
1251 OpenMsgHelper *helper = (OpenMsgHelper *) user_data;
1253 if (helper->banner_info) {
1254 g_free (helper->banner_info->message);
1255 if (helper->banner_info->idle_handler > 0) {
1256 g_source_remove (helper->banner_info->idle_handler);
1257 helper->banner_info->idle_handler = 0;
1259 if (helper->banner_info->banner != NULL) {
1260 gtk_widget_destroy (helper->banner_info->banner);
1261 g_object_unref (helper->banner_info->banner);
1262 helper->banner_info->banner = NULL;
1264 g_slice_free (OpenMsgBannerInfo, helper->banner_info);
1265 helper->banner_info = NULL;
1267 g_object_unref (helper->model);
1268 g_object_unref (helper->header);
1269 gtk_tree_row_reference_free (helper->rowref);
1270 g_slice_free (OpenMsgHelper, helper);
1274 open_msg_performer(gboolean canceled,
1276 GtkWindow *parent_window,
1277 TnyAccount *account,
1280 ModestMailOperation *mail_op = NULL;
1282 ModestProtocolType proto;
1283 TnyConnectionStatus status;
1284 gboolean show_open_draft = FALSE;
1285 OpenMsgHelper *helper = NULL;
1287 helper = (OpenMsgHelper *) user_data;
1289 status = tny_account_get_connection_status (account);
1290 if (err || canceled) {
1291 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (), helper->header);
1292 /* Free the helper */
1293 open_msg_helper_destroyer (helper);
1295 /* In memory full conditions we could get this error here */
1296 check_memory_full_error ((GtkWidget *) parent_window, err);
1301 /* Get the error message depending on the protocol */
1302 proto = modest_tny_account_get_protocol_type (account);
1303 if (proto == MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1304 proto = MODEST_PROTOCOLS_STORE_MAILDIR;
1307 ModestProtocol *protocol;
1308 ModestProtocolRegistry *protocol_registry;
1311 protocol_registry = modest_runtime_get_protocol_registry ();
1312 subject = tny_header_dup_subject (helper->header);
1314 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, proto);
1315 error_msg = modest_protocol_get_translation (protocol, MODEST_PROTOCOL_TRANSLATION_MSG_NOT_AVAILABLE, subject);
1319 if (error_msg == NULL) {
1320 error_msg = g_strdup (_("mail_ni_ui_folder_get_msg_folder_error"));
1323 if (modest_protocol_registry_protocol_type_has_tag (protocol_registry,
1325 MODEST_PROTOCOL_REGISTRY_LOCAL_STORE_PROTOCOLS)) {
1327 TnyFolderType folder_type;
1329 folder = tny_header_get_folder (helper->header);
1330 folder_type = modest_tny_folder_get_local_or_mmc_folder_type (folder);
1331 show_open_draft = (folder_type == TNY_FOLDER_TYPE_DRAFTS);
1332 g_object_unref (folder);
1335 #ifdef MODEST_TOOLKIT_HILDON2
1337 gchar *account_name = get_info_from_header (helper->header, &is_draft);
1340 ModestWindow *window;
1341 GtkWidget *header_view;
1344 header_view = get_header_view_from_window (MODEST_WINDOW (parent_window));
1345 uid = modest_tny_folder_get_header_unique_id (helper->header);
1347 window = modest_msg_view_window_new_from_header_view
1348 (MODEST_HEADER_VIEW (header_view), account_name, uid, helper->rowref);
1349 if (window != NULL) {
1350 if (!modest_window_mgr_register_window (modest_runtime_get_window_mgr (),
1352 gtk_widget_destroy (GTK_WIDGET (window));
1354 gtk_widget_show_all (GTK_WIDGET(window));
1358 g_free (account_name);
1360 open_msg_helper_destroyer (helper);
1363 g_free (account_name);
1365 /* Create the mail operation */
1367 modest_mail_operation_new_with_error_handling ((GObject *) parent_window,
1368 modest_ui_actions_disk_operations_error_handler,
1370 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
1373 if (show_open_draft) {
1374 helper->banner_info = g_slice_new (OpenMsgBannerInfo);
1375 #ifdef MODEST_TOOLKIT_HILDON2
1376 helper->banner_info->message = g_strdup (_("mail_me_opening"));
1378 helper->banner_info->message = g_strdup (_("mail_ib_opening_draft_message"));
1380 helper->banner_info->banner = NULL;
1381 helper->banner_info->idle_handler = g_timeout_add (500, open_msg_banner_idle,
1382 helper->banner_info);
1386 headers = TNY_LIST (tny_simple_list_new ());
1387 tny_list_prepend (headers, G_OBJECT (helper->header));
1388 modest_mail_operation_get_msgs_full (mail_op,
1392 open_msg_helper_destroyer);
1393 g_object_unref (headers);
1398 g_object_unref (mail_op);
1399 g_object_unref (account);
1403 * This function is used by both modest_ui_actions_on_open and
1404 * modest_ui_actions_on_header_activated. This way we always do the
1405 * same when trying to open messages.
1408 open_msg_from_header (TnyHeader *header, GtkTreeRowReference *rowref, ModestWindow *win)
1410 ModestWindowMgr *mgr = NULL;
1411 TnyAccount *account;
1412 gboolean cached = FALSE;
1414 GtkWidget *header_view = NULL;
1415 OpenMsgHelper *helper;
1416 ModestWindow *window;
1418 g_return_if_fail (header != NULL && rowref != NULL);
1420 mgr = modest_runtime_get_window_mgr ();
1423 header_view = get_header_view_from_window (MODEST_WINDOW (win));
1424 if (header_view == NULL)
1427 /* Get the account */
1428 account = get_account_from_header (header);
1433 found = modest_window_mgr_find_registered_header (mgr, header, &window);
1435 /* Do not open again the message and present the
1436 window to the user */
1439 #ifndef MODEST_TOOLKIT_HILDON2
1440 gtk_window_present (GTK_WINDOW (window));
1443 /* the header has been registered already, we don't do
1444 * anything but wait for the window to come up*/
1445 g_debug ("header %p already registered, waiting for window", header);
1450 /* Open each message */
1451 cached = tny_header_get_flags (header) & TNY_HEADER_FLAG_CACHED;
1453 /* Allways download if we are online. */
1454 if (!tny_device_is_online (modest_runtime_get_device ())) {
1457 /* If ask for user permission to download the messages */
1458 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
1459 _("mcen_nc_get_msg"));
1461 /* End if the user does not want to continue */
1462 if (response == GTK_RESPONSE_CANCEL) {
1468 /* We register the window for opening */
1469 modest_window_mgr_register_header (mgr, header, NULL);
1471 /* Create the helper. We need to get a reference to the model
1472 here because it could change while the message is readed
1473 (the user could switch between folders) */
1474 helper = g_slice_new (OpenMsgHelper);
1475 helper->model = g_object_ref (gtk_tree_view_get_model (GTK_TREE_VIEW (header_view)));
1476 helper->header = g_object_ref (header);
1477 helper->rowref = gtk_tree_row_reference_copy (rowref);
1478 helper->banner_info = NULL;
1480 /* Connect to the account and perform */
1482 modest_platform_connect_and_perform ((GtkWindow *) win, TRUE, g_object_ref (account),
1483 open_msg_performer, helper);
1485 /* Call directly the performer, do not need to connect */
1486 open_msg_performer (FALSE, NULL, (GtkWindow *) win,
1487 g_object_ref (account), helper);
1492 g_object_unref (account);
1496 modest_ui_actions_on_open (GtkAction *action, ModestWindow *win)
1503 /* we check for low-mem; in that case, show a warning, and don't allow
1506 if (modest_platform_check_memory_low (MODEST_WINDOW(win), TRUE))
1510 headers = get_selected_headers (win);
1514 headers_count = tny_list_get_length (headers);
1515 if (headers_count != 1) {
1516 if (headers_count > 1) {
1517 /* Don't allow activation if there are more than one message selected */
1518 modest_platform_information_banner (NULL, NULL, _("mcen_ib_select_one_message"));
1521 g_object_unref (headers);
1525 iter = tny_list_create_iterator (headers);
1526 header = TNY_HEADER (tny_iterator_get_current (iter));
1527 g_object_unref (iter);
1531 open_msg_from_header (header, NULL, win);
1532 g_object_unref (header);
1535 g_object_unref(headers);
1539 rf_helper_window_closed (gpointer data,
1542 ReplyForwardHelper *helper = (ReplyForwardHelper *) data;
1544 helper->parent_window = NULL;
1547 static ReplyForwardHelper*
1548 create_reply_forward_helper (ReplyForwardAction action,
1550 guint reply_forward_type,
1553 ReplyForwardHelper *rf_helper = NULL;
1554 const gchar *active_acc = modest_window_get_active_account (win);
1556 rf_helper = g_slice_new0 (ReplyForwardHelper);
1557 rf_helper->reply_forward_type = reply_forward_type;
1558 rf_helper->action = action;
1559 rf_helper->parent_window = (MODEST_IS_WINDOW (win)) ? GTK_WIDGET (win) : NULL;
1560 rf_helper->header = (header) ? g_object_ref (header) : NULL;
1561 rf_helper->account_name = (active_acc) ?
1562 g_strdup (active_acc) :
1563 modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
1565 /* Note that window could be destroyed just AFTER calling
1566 register_window so we must ensure that this pointer does
1567 not hold invalid references */
1568 if (rf_helper->parent_window)
1569 g_object_weak_ref (G_OBJECT (rf_helper->parent_window),
1570 rf_helper_window_closed, rf_helper);
1576 free_reply_forward_helper (gpointer data)
1578 ReplyForwardHelper *helper;
1580 helper = (ReplyForwardHelper *) data;
1581 g_free (helper->account_name);
1583 g_object_unref (helper->header);
1584 if (helper->parent_window)
1585 g_object_weak_unref (G_OBJECT (helper->parent_window),
1586 rf_helper_window_closed, helper);
1587 g_slice_free (ReplyForwardHelper, helper);
1591 reply_forward_cb (ModestMailOperation *mail_op,
1598 TnyMsg *new_msg = NULL;
1599 ReplyForwardHelper *rf_helper;
1600 ModestWindow *msg_win = NULL;
1601 ModestEditType edit_type;
1603 TnyAccount *account = NULL;
1604 ModestWindowMgr *mgr = NULL;
1605 gchar *signature = NULL;
1606 gboolean use_signature;
1608 /* If there was any error. The mail operation could be NULL,
1609 this means that we already have the message downloaded and
1610 that we didn't do a mail operation to retrieve it */
1611 rf_helper = (ReplyForwardHelper *) user_data;
1612 if (mail_op && !modest_ui_actions_msg_retrieval_check (mail_op, header, msg))
1615 from = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(),
1616 rf_helper->account_name);
1617 signature = modest_account_mgr_get_signature (modest_runtime_get_account_mgr(),
1618 rf_helper->account_name,
1621 /* Create reply mail */
1622 switch (rf_helper->action) {
1625 modest_tny_msg_create_reply_msg (msg, header, from,
1626 (use_signature) ? signature : NULL,
1627 rf_helper->reply_forward_type,
1628 MODEST_TNY_MSG_REPLY_MODE_SENDER);
1630 case ACTION_REPLY_TO_ALL:
1632 modest_tny_msg_create_reply_msg (msg, header, from,
1633 (use_signature) ? signature : NULL,
1634 rf_helper->reply_forward_type,
1635 MODEST_TNY_MSG_REPLY_MODE_ALL);
1636 edit_type = MODEST_EDIT_TYPE_REPLY;
1638 case ACTION_FORWARD:
1640 modest_tny_msg_create_forward_msg (msg, from, (use_signature) ? signature : NULL,
1641 rf_helper->reply_forward_type);
1642 edit_type = MODEST_EDIT_TYPE_FORWARD;
1645 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (),
1647 g_return_if_reached ();
1655 g_warning ("%s: failed to create message\n", __FUNCTION__);
1659 account = modest_tny_account_store_get_server_account (modest_runtime_get_account_store(),
1660 rf_helper->account_name,
1661 TNY_ACCOUNT_TYPE_STORE);
1663 g_warning ("%s: failed to get tnyaccount for '%s'\n", __FUNCTION__, rf_helper->account_name);
1667 /* Create and register the windows */
1668 msg_win = modest_msg_edit_window_new (new_msg, rf_helper->account_name, FALSE);
1669 mgr = modest_runtime_get_window_mgr ();
1670 modest_window_mgr_register_window (mgr, msg_win, (ModestWindow *) rf_helper->parent_window);
1672 /* Note that register_window could have deleted the account */
1673 if (MODEST_IS_WINDOW (rf_helper->parent_window)) {
1674 gdouble parent_zoom;
1676 parent_zoom = modest_window_get_zoom (MODEST_WINDOW (rf_helper->parent_window));
1677 modest_window_set_zoom (msg_win, parent_zoom);
1680 /* Show edit window */
1681 gtk_widget_show_all (GTK_WIDGET (msg_win));
1684 /* We always unregister the header because the message is
1685 forwarded or replied so the original one is no longer
1687 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (),
1690 g_object_unref (G_OBJECT (new_msg));
1692 g_object_unref (G_OBJECT (account));
1693 free_reply_forward_helper (rf_helper);
1696 /* Checks a list of headers. If any of them are not currently
1697 * downloaded (CACHED) then returns TRUE else returns FALSE.
1700 header_list_count_uncached_msgs (TnyList *header_list)
1703 gint uncached_messages = 0;
1705 iter = tny_list_create_iterator (header_list);
1706 while (!tny_iterator_is_done (iter)) {
1709 header = TNY_HEADER (tny_iterator_get_current (iter));
1711 if (!(tny_header_get_flags (header) & TNY_HEADER_FLAG_CACHED))
1712 uncached_messages ++;
1713 g_object_unref (header);
1716 tny_iterator_next (iter);
1718 g_object_unref (iter);
1720 return uncached_messages;
1723 /* Returns FALSE if the user does not want to download the
1724 * messages. Returns TRUE if the user allowed the download.
1727 connect_to_get_msg (ModestWindow *win,
1728 gint num_of_uncached_msgs,
1729 TnyAccount *account)
1731 GtkResponseType response;
1733 /* Allways download if we are online. */
1734 if (tny_device_is_online (modest_runtime_get_device ()))
1737 /* If offline, then ask for user permission to download the messages */
1738 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
1739 ngettext("mcen_nc_get_msg",
1741 num_of_uncached_msgs));
1743 if (response == GTK_RESPONSE_CANCEL)
1746 return modest_platform_connect_and_wait((GtkWindow *) win, account);
1750 reply_forward_performer (gboolean canceled,
1752 GtkWindow *parent_window,
1753 TnyAccount *account,
1756 ReplyForwardHelper *rf_helper = NULL;
1757 ModestMailOperation *mail_op;
1759 rf_helper = (ReplyForwardHelper *) user_data;
1761 if (canceled || err) {
1762 free_reply_forward_helper (rf_helper);
1766 /* Retrieve the message */
1767 modest_window_mgr_register_header (modest_runtime_get_window_mgr (), rf_helper->header, NULL);
1768 mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT (parent_window),
1769 modest_ui_actions_disk_operations_error_handler,
1771 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
1772 modest_mail_operation_get_msg (mail_op, rf_helper->header, TRUE, reply_forward_cb, rf_helper);
1775 g_object_unref(mail_op);
1779 * Common code for the reply and forward actions
1782 reply_forward (ReplyForwardAction action, ModestWindow *win)
1784 ReplyForwardHelper *rf_helper = NULL;
1785 guint reply_forward_type;
1787 g_return_if_fail (MODEST_IS_WINDOW(win));
1789 /* we check for low-mem; in that case, show a warning, and don't allow
1790 * reply/forward (because it could potentially require a lot of memory */
1791 if (modest_platform_check_memory_low (MODEST_WINDOW(win), TRUE))
1795 /* we need an account when editing */
1796 if (!modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE)) {
1797 if (!modest_ui_actions_run_account_setup_wizard (win))
1801 reply_forward_type =
1802 modest_conf_get_int (modest_runtime_get_conf (),
1803 (action == ACTION_FORWARD) ?
1804 MODEST_CONF_FORWARD_TYPE :
1805 MODEST_CONF_REPLY_TYPE,
1808 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
1810 TnyHeader *header = NULL;
1811 /* Get header and message. Do not free them here, the
1812 reply_forward_cb must do it */
1813 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW(win));
1814 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
1816 if (msg && header) {
1818 rf_helper = create_reply_forward_helper (action, win,
1819 reply_forward_type, header);
1820 reply_forward_cb (NULL, header, FALSE, msg, NULL, rf_helper);
1822 g_warning("%s: no message or header found in viewer\n", __FUNCTION__);
1826 g_object_unref (msg);
1828 g_object_unref (header);
1830 TnyHeader *header = NULL;
1832 gboolean do_retrieve = TRUE;
1833 TnyList *header_list = NULL;
1835 header_list = get_selected_headers (win);
1838 /* Check that only one message is selected for replying */
1839 if (tny_list_get_length (header_list) != 1) {
1840 modest_platform_information_banner ((win) ? GTK_WIDGET (win) : NULL,
1841 NULL, _("mcen_ib_select_one_message"));
1842 g_object_unref (header_list);
1846 /* Only reply/forward to one message */
1847 iter = tny_list_create_iterator (header_list);
1848 header = TNY_HEADER (tny_iterator_get_current (iter));
1849 g_object_unref (iter);
1851 /* Retrieve messages */
1852 do_retrieve = (action == ACTION_FORWARD) ||
1853 (reply_forward_type != MODEST_TNY_MSG_REPLY_TYPE_CITE);
1856 TnyAccount *account = NULL;
1857 TnyFolder *folder = NULL;
1858 gdouble download = TRUE;
1859 guint uncached_msgs = 0;
1861 folder = tny_header_get_folder (header);
1863 goto do_retrieve_frees;
1864 account = tny_folder_get_account (folder);
1866 goto do_retrieve_frees;
1868 uncached_msgs = header_list_count_uncached_msgs (header_list);
1870 if (uncached_msgs > 0) {
1871 /* Allways download if we are online. */
1872 if (!tny_device_is_online (modest_runtime_get_device ())) {
1875 /* If ask for user permission to download the messages */
1876 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
1877 ngettext("mcen_nc_get_msg",
1881 /* End if the user does not want to continue */
1882 if (response == GTK_RESPONSE_CANCEL)
1889 rf_helper = create_reply_forward_helper (action, win,
1890 reply_forward_type, header);
1891 if (uncached_msgs > 0) {
1892 modest_platform_connect_and_perform (GTK_WINDOW (win),
1894 reply_forward_performer,
1897 reply_forward_performer (FALSE, NULL, GTK_WINDOW (win),
1898 account, rf_helper);
1903 g_object_unref (account);
1905 g_object_unref (folder);
1907 reply_forward_cb (NULL, header, FALSE, NULL, NULL, rf_helper);
1910 g_object_unref (header_list);
1911 g_object_unref (header);
1916 modest_ui_actions_on_reply (GtkAction *action, ModestWindow *win)
1918 g_return_if_fail (MODEST_IS_WINDOW(win));
1920 reply_forward (ACTION_REPLY, win);
1924 modest_ui_actions_on_forward (GtkAction *action, ModestWindow *win)
1926 g_return_if_fail (MODEST_IS_WINDOW(win));
1928 reply_forward (ACTION_FORWARD, win);
1932 modest_ui_actions_on_reply_all (GtkAction *action, ModestWindow *win)
1934 g_return_if_fail (MODEST_IS_WINDOW(win));
1936 reply_forward (ACTION_REPLY_TO_ALL, win);
1940 modest_ui_actions_on_next (GtkAction *action,
1941 ModestWindow *window)
1943 if (MODEST_IS_MAIN_WINDOW (window)) {
1944 GtkWidget *header_view;
1946 header_view = modest_main_window_get_child_widget (
1947 MODEST_MAIN_WINDOW(window),
1948 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1952 modest_header_view_select_next (
1953 MODEST_HEADER_VIEW(header_view));
1954 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
1955 modest_msg_view_window_select_next_message (
1956 MODEST_MSG_VIEW_WINDOW (window));
1958 g_return_if_reached ();
1963 modest_ui_actions_on_prev (GtkAction *action,
1964 ModestWindow *window)
1966 g_return_if_fail (MODEST_IS_WINDOW(window));
1968 if (MODEST_IS_MAIN_WINDOW (window)) {
1969 GtkWidget *header_view;
1970 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
1971 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1975 modest_header_view_select_prev (MODEST_HEADER_VIEW(header_view));
1976 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
1977 modest_msg_view_window_select_previous_message (MODEST_MSG_VIEW_WINDOW (window));
1979 g_return_if_reached ();
1984 modest_ui_actions_on_sort (GtkAction *action,
1985 ModestWindow *window)
1987 GtkWidget *header_view = NULL;
1989 g_return_if_fail (MODEST_IS_WINDOW(window));
1991 if (MODEST_IS_MAIN_WINDOW (window)) {
1992 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
1993 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1994 #ifdef MODEST_TOOLKIT_HILDON2
1995 } else if (MODEST_IS_HEADER_WINDOW (window)) {
1996 header_view = GTK_WIDGET (modest_header_window_get_header_view (MODEST_HEADER_WINDOW (window)));
2001 modest_platform_information_banner (NULL, NULL, _CS("ckdg_ib_nothing_to_sort"));
2006 /* Show sorting dialog */
2007 modest_utils_run_sort_dialog (GTK_WINDOW (window), MODEST_SORT_HEADERS);
2011 new_messages_arrived (ModestMailOperation *self,
2012 TnyList *new_headers,
2016 gboolean show_visual_notifications;
2018 source = modest_mail_operation_get_source (self);
2019 show_visual_notifications = (source) ? FALSE : TRUE;
2021 g_object_unref (source);
2023 /* Notify new messages have been downloaded. If the
2024 send&receive was invoked by the user then do not show any
2025 visual notification, only play a sound and activate the LED
2026 (for the Maemo version) */
2027 if (TNY_IS_LIST(new_headers) && (tny_list_get_length (new_headers)) > 0)
2028 modest_platform_on_new_headers_received (new_headers,
2029 show_visual_notifications);
2034 retrieve_all_messages_cb (GObject *source,
2036 guint retrieve_limit)
2042 window = GTK_WINDOW (source);
2043 msg = g_strdup_printf (_("mail_nc_msg_count_limit_exceeded"),
2044 num_msgs, retrieve_limit);
2046 /* Ask the user if they want to retrieve all the messages */
2048 modest_platform_run_confirmation_dialog_with_buttons (window, msg,
2049 _("mcen_bd_get_all"),
2050 _("mcen_bd_newest_only"));
2051 /* Free and return */
2053 return (response == GTK_RESPONSE_ACCEPT) ? TRUE : FALSE;
2057 TnyAccount *account;
2059 gchar *account_name;
2060 gboolean poke_status;
2061 gboolean interactive;
2062 ModestMailOperation *mail_op;
2066 do_send_receive_performer (gboolean canceled,
2068 GtkWindow *parent_window,
2069 TnyAccount *account,
2072 SendReceiveInfo *info;
2074 info = (SendReceiveInfo *) user_data;
2076 if (err || canceled) {
2077 /* In memory full conditions we could get this error here */
2078 check_memory_full_error ((GtkWidget *) parent_window, err);
2080 if (info->mail_op) {
2081 modest_mail_operation_queue_remove (modest_runtime_get_mail_operation_queue (),
2087 /* Set send/receive operation in progress */
2088 if (info->win && MODEST_IS_MAIN_WINDOW (info->win)) {
2089 modest_main_window_notify_send_receive_initied (MODEST_MAIN_WINDOW (info->win));
2092 if (info->win && MODEST_IS_MAIN_WINDOW (info->win))
2093 g_signal_connect (G_OBJECT (info->mail_op), "operation-finished",
2094 G_CALLBACK (on_send_receive_finished),
2097 /* Send & receive. */
2098 modest_mail_operation_update_account (info->mail_op, info->account_name, info->poke_status, info->interactive,
2099 (info->win) ? retrieve_all_messages_cb : NULL,
2100 new_messages_arrived, info->win);
2105 g_object_unref (G_OBJECT (info->mail_op));
2106 if (info->account_name)
2107 g_free (info->account_name);
2109 g_object_unref (info->win);
2111 g_object_unref (info->account);
2112 g_slice_free (SendReceiveInfo, info);
2116 * This function performs the send & receive required actions. The
2117 * window is used to create the mail operation. Typically it should
2118 * always be the main window, but we pass it as argument in order to
2122 modest_ui_actions_do_send_receive (const gchar *account_name,
2123 gboolean force_connection,
2124 gboolean poke_status,
2125 gboolean interactive,
2128 gchar *acc_name = NULL;
2129 SendReceiveInfo *info;
2130 ModestTnyAccountStore *acc_store;
2132 /* If no account name was provided then get the current account, and if
2133 there is no current account then pick the default one: */
2134 if (!account_name) {
2136 acc_name = g_strdup (modest_window_get_active_account (win));
2138 acc_name = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
2140 g_printerr ("modest: cannot get default account\n");
2144 acc_name = g_strdup (account_name);
2147 acc_store = modest_runtime_get_account_store ();
2149 /* Create the info for the connect and perform */
2150 info = g_slice_new (SendReceiveInfo);
2151 info->account_name = acc_name;
2152 info->win = (win) ? g_object_ref (win) : NULL;
2153 info->poke_status = poke_status;
2154 info->interactive = interactive;
2155 info->account = modest_tny_account_store_get_server_account (acc_store, acc_name,
2156 TNY_ACCOUNT_TYPE_STORE);
2157 /* We need to create the operation here, because otherwise it
2158 could happen that the queue emits the queue-empty signal
2159 while we're trying to connect the account */
2160 info->mail_op = modest_mail_operation_new_with_error_handling ((info->win) ? G_OBJECT (info->win) : NULL,
2161 modest_ui_actions_disk_operations_error_handler,
2163 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), info->mail_op);
2165 /* Invoke the connect and perform */
2166 modest_platform_connect_and_perform ((win) ? GTK_WINDOW (win) : NULL,
2167 force_connection, info->account,
2168 do_send_receive_performer, info);
2173 modest_ui_actions_do_cancel_send (const gchar *account_name,
2176 TnyTransportAccount *transport_account;
2177 TnySendQueue *send_queue = NULL;
2178 GError *error = NULL;
2180 /* Get transport account */
2182 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
2183 (modest_runtime_get_account_store(),
2185 TNY_ACCOUNT_TYPE_TRANSPORT));
2186 if (!transport_account) {
2187 g_printerr ("modest: no transport account found for '%s'\n", account_name);
2192 send_queue = TNY_SEND_QUEUE (modest_runtime_get_send_queue (transport_account, TRUE));
2193 if (!TNY_IS_SEND_QUEUE(send_queue)) {
2194 g_set_error (&error, MODEST_MAIL_OPERATION_ERROR,
2195 MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND,
2196 "modest: could not find send queue for account\n");
2198 /* Cancel the current send */
2199 tny_account_cancel (TNY_ACCOUNT (transport_account));
2201 /* Suspend all pending messages */
2202 tny_send_queue_cancel (send_queue, TNY_SEND_QUEUE_CANCEL_ACTION_SUSPEND, &error);
2206 if (transport_account != NULL)
2207 g_object_unref (G_OBJECT (transport_account));
2211 modest_ui_actions_cancel_send_all (ModestWindow *win)
2213 GSList *account_names, *iter;
2215 account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
2218 iter = account_names;
2220 modest_ui_actions_do_cancel_send ((const char*) iter->data, win);
2221 iter = g_slist_next (iter);
2224 modest_account_mgr_free_account_names (account_names);
2225 account_names = NULL;
2229 modest_ui_actions_cancel_send (GtkAction *action, ModestWindow *win)
2232 /* Check if accounts exist */
2233 gboolean accounts_exist =
2234 modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
2236 /* If not, allow the user to create an account before trying to send/receive. */
2237 if (!accounts_exist)
2238 modest_ui_actions_on_accounts (NULL, win);
2240 /* Cancel all sending operaitons */
2241 modest_ui_actions_cancel_send_all (win);
2245 * Refreshes all accounts. This function will be used by automatic
2249 modest_ui_actions_do_send_receive_all (ModestWindow *win,
2250 gboolean force_connection,
2251 gboolean poke_status,
2252 gboolean interactive)
2254 GSList *account_names, *iter;
2256 account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
2259 iter = account_names;
2261 modest_ui_actions_do_send_receive ((const char*) iter->data,
2263 poke_status, interactive, win);
2264 iter = g_slist_next (iter);
2267 modest_account_mgr_free_account_names (account_names);
2268 account_names = NULL;
2272 * Handler of the click on Send&Receive button in the main toolbar
2275 modest_ui_actions_on_send_receive (GtkAction *action, ModestWindow *win)
2277 /* Check if accounts exist */
2278 gboolean accounts_exist;
2281 modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
2283 /* If not, allow the user to create an account before trying to send/receive. */
2284 if (!accounts_exist)
2285 modest_ui_actions_on_accounts (NULL, win);
2287 /* Refresh the current folder. The if is always TRUE it's just an extra check */
2288 if (MODEST_IS_MAIN_WINDOW (win)) {
2289 GtkWidget *folder_view;
2290 TnyFolderStore *folder_store;
2293 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
2294 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2298 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
2301 g_object_unref (folder_store);
2302 /* Refresh the active account. Force the connection if needed
2303 and poke the status of all folders */
2304 modest_ui_actions_do_send_receive (NULL, TRUE, TRUE, TRUE, win);
2305 #ifdef MODEST_TOOLKIT_HILDON2
2306 } else if (MODEST_IS_ACCOUNTS_WINDOW (win)) {
2307 modest_ui_actions_do_send_receive_all (win, TRUE, TRUE, TRUE);
2310 const gchar *active_account;
2311 active_account = modest_window_get_active_account (MODEST_WINDOW (win));
2313 modest_ui_actions_do_send_receive (active_account, TRUE, TRUE, TRUE, win);
2320 modest_ui_actions_toggle_header_list_view (GtkAction *action, ModestMainWindow *main_window)
2323 GtkWidget *header_view;
2325 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2327 header_view = modest_main_window_get_child_widget (main_window,
2328 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2332 conf = modest_runtime_get_conf ();
2334 /* what is saved/restored is depending on the style; thus; we save with
2335 * old style, then update the style, and restore for this new style
2337 modest_widget_memory_save (conf, G_OBJECT(header_view), MODEST_CONF_HEADER_VIEW_KEY);
2339 if (modest_header_view_get_style
2340 (MODEST_HEADER_VIEW(header_view)) == MODEST_HEADER_VIEW_STYLE_DETAILS)
2341 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
2342 MODEST_HEADER_VIEW_STYLE_TWOLINES);
2344 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
2345 MODEST_HEADER_VIEW_STYLE_DETAILS);
2347 modest_widget_memory_restore (conf, G_OBJECT(header_view),
2348 MODEST_CONF_HEADER_VIEW_KEY);
2353 modest_ui_actions_on_header_selected (ModestHeaderView *header_view,
2355 ModestMainWindow *main_window)
2357 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2358 g_return_if_fail (MODEST_IS_HEADER_VIEW (header_view));
2360 /* in the case the folder is empty, show the empty folder message and focus
2362 if (!header && gtk_widget_is_focus (GTK_WIDGET (header_view))) {
2363 if (modest_header_view_is_empty (header_view)) {
2364 TnyFolder *folder = modest_header_view_get_folder (header_view);
2365 GtkWidget *folder_view =
2366 modest_main_window_get_child_widget (main_window,
2367 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2368 if (folder != NULL) {
2369 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view), folder, FALSE);
2370 g_object_unref (folder);
2372 gtk_widget_grab_focus (GTK_WIDGET (folder_view));
2376 /* If no header has been selected then exit */
2381 if (!gtk_widget_is_focus (GTK_WIDGET(header_view)))
2382 gtk_widget_grab_focus (GTK_WIDGET(header_view));
2384 /* Update toolbar dimming state */
2385 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (main_window));
2386 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
2390 modest_ui_actions_on_header_activated (ModestHeaderView *header_view,
2393 ModestWindow *window)
2395 GtkWidget *open_widget;
2396 GtkTreeRowReference *rowref;
2398 g_return_if_fail (MODEST_IS_WINDOW(window));
2399 g_return_if_fail (MODEST_IS_HEADER_VIEW (header_view));
2400 g_return_if_fail (TNY_IS_HEADER (header));
2402 if (modest_header_view_count_selected_headers (header_view) > 1) {
2403 /* Don't allow activation if there are more than one message selected */
2404 modest_platform_information_banner (NULL, NULL, _("mcen_ib_select_one_message"));
2408 /* we check for low-mem; in that case, show a warning, and don't allow
2409 * activating headers
2411 if (modest_platform_check_memory_low (MODEST_WINDOW(window), TRUE))
2414 if (MODEST_IS_MAIN_WINDOW (window)) {
2415 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (window));
2416 open_widget = modest_window_get_action_widget (MODEST_WINDOW (window), "/MenuBar/EmailMenu/EmailOpenMenu");
2417 if (!GTK_WIDGET_IS_SENSITIVE (open_widget))
2421 rowref = gtk_tree_row_reference_new (gtk_tree_view_get_model (GTK_TREE_VIEW (header_view)), path);
2422 open_msg_from_header (header, rowref, MODEST_WINDOW (window));
2423 gtk_tree_row_reference_free (rowref);
2427 set_active_account_from_tny_account (TnyAccount *account,
2428 ModestWindow *window)
2430 const gchar *server_acc_name = tny_account_get_id (account);
2432 /* We need the TnyAccount provided by the
2433 account store because that is the one that
2434 knows the name of the Modest account */
2435 TnyAccount *modest_server_account = modest_server_account =
2436 modest_tny_account_store_get_tny_account_by (modest_runtime_get_account_store (),
2437 MODEST_TNY_ACCOUNT_STORE_QUERY_ID,
2439 if (!modest_server_account) {
2440 g_warning ("%s: could not get tny account\n", __FUNCTION__);
2444 /* Update active account, but only if it's not a pseudo-account */
2445 if ((!modest_tny_account_is_virtual_local_folders(modest_server_account)) &&
2446 (!modest_tny_account_is_memory_card_account(modest_server_account))) {
2447 const gchar *modest_acc_name =
2448 modest_tny_account_get_parent_modest_account_name_for_server_account (modest_server_account);
2449 if (modest_acc_name)
2450 modest_window_set_active_account (window, modest_acc_name);
2453 g_object_unref (modest_server_account);
2458 folder_refreshed_cb (ModestMailOperation *mail_op,
2462 ModestMainWindow *win = NULL;
2463 GtkWidget *folder_view;
2464 const GError *error;
2466 g_return_if_fail (TNY_IS_FOLDER (folder));
2468 win = MODEST_MAIN_WINDOW (user_data);
2470 /* Check if the operation failed due to memory low conditions */
2471 error = modest_mail_operation_get_error (mail_op);
2472 if (error && error->domain == MODEST_MAIL_OPERATION_ERROR &&
2473 error->code == MODEST_MAIL_OPERATION_ERROR_LOW_MEMORY) {
2474 modest_platform_run_information_dialog (GTK_WINDOW (win),
2475 dgettext("ke-recv","memr_ib_operation_disabled"),
2481 modest_main_window_get_child_widget(win, MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2484 TnyFolderStore *current_folder;
2486 current_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
2487 if (current_folder) {
2488 gboolean different = ((TnyFolderStore *) folder != current_folder);
2489 g_object_unref (current_folder);
2495 /* Check if folder is empty and set headers view contents style */
2496 if (tny_folder_get_all_count (folder) == 0)
2497 modest_main_window_set_contents_style (win,
2498 MODEST_MAIN_WINDOW_CONTENTS_STYLE_EMPTY);
2503 modest_ui_actions_on_folder_selection_changed (ModestFolderView *folder_view,
2504 TnyFolderStore *folder_store,
2506 ModestMainWindow *main_window)
2509 GtkWidget *header_view;
2511 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2513 header_view = modest_main_window_get_child_widget(main_window,
2514 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2518 conf = modest_runtime_get_conf ();
2520 if (TNY_IS_ACCOUNT (folder_store)) {
2522 set_active_account_from_tny_account (TNY_ACCOUNT (folder_store), MODEST_WINDOW (main_window));
2524 /* Show account details */
2525 modest_main_window_set_contents_style (main_window, MODEST_MAIN_WINDOW_CONTENTS_STYLE_DETAILS);
2528 if (TNY_IS_FOLDER (folder_store) && selected) {
2529 TnyAccount *account;
2530 const gchar *account_name = NULL;
2532 /* Update the active account */
2533 account = modest_tny_folder_get_account (TNY_FOLDER (folder_store));
2535 set_active_account_from_tny_account (account, MODEST_WINDOW (main_window));
2537 modest_tny_account_get_parent_modest_account_name_for_server_account (account);
2538 g_object_unref (account);
2542 /* Set the header style by default, it could
2543 be changed later by the refresh callback to
2545 modest_main_window_set_contents_style (main_window,
2546 MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS);
2548 /* Set folder on header view. This function
2549 will call tny_folder_refresh_async so we
2550 pass a callback that will be called when
2551 finished. We use that callback to set the
2552 empty view if there are no messages */
2553 modest_header_view_set_folder (MODEST_HEADER_VIEW(header_view),
2554 TNY_FOLDER (folder_store),
2556 MODEST_WINDOW (main_window),
2557 folder_refreshed_cb,
2560 /* Restore configuration. We need to do this
2561 *after* the set_folder because the widget
2562 memory asks the header view about its
2564 modest_widget_memory_restore (modest_runtime_get_conf (),
2565 G_OBJECT(header_view),
2566 MODEST_CONF_HEADER_VIEW_KEY);
2568 /* No need to save the header view
2569 configuration for Maemo because it only
2570 saves the sorting stuff and that it's
2571 already being done by the sort
2572 dialog. Remove it when the GNOME version
2573 has the same behaviour */
2574 #ifdef MODEST_TOOLKIT_GTK
2575 if (modest_main_window_get_contents_style (main_window) ==
2576 MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS)
2577 modest_widget_memory_save (conf, G_OBJECT (header_view),
2578 MODEST_CONF_HEADER_VIEW_KEY);
2580 modest_header_view_clear (MODEST_HEADER_VIEW(header_view));
2584 /* Update dimming state */
2585 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (main_window));
2586 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
2590 modest_ui_actions_on_item_not_found (ModestHeaderView *header_view,ModestItemType type,
2597 item = (type == MODEST_ITEM_TYPE_FOLDER) ? "folder" : "message";
2599 online = tny_device_is_online (modest_runtime_get_device());
2602 /* already online -- the item is simply not there... */
2603 dialog = gtk_message_dialog_new (GTK_WINDOW (win),
2605 GTK_MESSAGE_WARNING,
2607 _("The %s you selected cannot be found"),
2609 gtk_dialog_add_button (GTK_DIALOG (dialog),_("mcen_bd_dialog_ok"), GTK_RESPONSE_ACCEPT);
2610 gtk_dialog_run (GTK_DIALOG(dialog));
2612 dialog = gtk_dialog_new_with_buttons (_("Connection requested"),
2615 _("mcen_bd_dialog_cancel"),
2616 GTK_RESPONSE_REJECT,
2617 _("mcen_bd_dialog_ok"),
2618 GTK_RESPONSE_ACCEPT,
2620 txt = g_strdup_printf (_("This %s is not available in offline mode.\n"
2621 "Do you want to get online?"), item);
2622 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
2623 gtk_label_new (txt), FALSE, FALSE, 0);
2624 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
2627 gtk_window_set_default_size (GTK_WINDOW(dialog), 300, 300);
2628 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
2629 /* TODO: Comment about why is this commented out: */
2630 /* modest_platform_connect_and_wait (); */
2633 gtk_widget_destroy (dialog);
2637 modest_ui_actions_on_msg_link_hover (ModestMsgView *msgview, const gchar* link,
2640 /* g_message ("%s %s", __FUNCTION__, link); */
2645 modest_ui_actions_on_msg_link_clicked (ModestMsgView *msgview, const gchar* link,
2648 modest_platform_activate_uri (link);
2652 modest_ui_actions_on_msg_link_contextual (ModestMsgView *msgview, const gchar* link,
2655 modest_platform_show_uri_popup (link);
2659 modest_ui_actions_on_msg_attachment_clicked (ModestMsgView *msgview, TnyMimePart *mime_part,
2662 /* we check for low-mem; in that case, show a warning, and don't allow
2663 * viewing attachments
2665 if (modest_platform_check_memory_low (MODEST_WINDOW(win), TRUE))
2668 modest_msg_view_window_view_attachment (MODEST_MSG_VIEW_WINDOW (win), mime_part);
2672 modest_ui_actions_on_msg_recpt_activated (ModestMsgView *msgview,
2673 const gchar *address,
2676 /* g_message ("%s %s", __FUNCTION__, address); */
2680 on_save_to_drafts_cb (ModestMailOperation *mail_op,
2681 TnyMsg *saved_draft,
2684 ModestMsgEditWindow *edit_window;
2686 /* TODO: in hildon 2 we have to dim and undim the header views while we're saving */
2687 #ifndef MODEST_TOOLKIT_HILDON2
2688 ModestMainWindow *win;
2690 /* FIXME. Make the header view sensitive again. This is a
2691 * temporary hack. See modest_ui_actions_on_save_to_drafts()
2693 win = MODEST_MAIN_WINDOW(modest_window_mgr_get_main_window(
2694 modest_runtime_get_window_mgr(), FALSE));
2696 GtkWidget *hdrview = modest_main_window_get_child_widget(
2697 win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2698 if (hdrview) gtk_widget_set_sensitive(hdrview, TRUE);
2702 edit_window = MODEST_MSG_EDIT_WINDOW (user_data);
2704 /* Set draft is there was no error */
2705 if (!modest_mail_operation_get_error (mail_op))
2706 modest_msg_edit_window_set_draft (edit_window, saved_draft);
2708 g_object_unref(edit_window);
2712 enough_space_for_message (ModestMsgEditWindow *edit_window,
2715 TnyAccountStore *acc_store;
2716 guint64 available_disk, expected_size;
2721 acc_store = TNY_ACCOUNT_STORE (modest_runtime_get_account_store());
2722 available_disk = modest_utils_get_available_space (NULL);
2723 modest_msg_edit_window_get_parts_size (edit_window, &parts_count, &parts_size);
2724 expected_size = modest_tny_msg_estimate_size (data->plain_body,
2729 /* Double check: memory full condition or message too big */
2730 if (available_disk < MIN_FREE_SPACE ||
2731 expected_size > available_disk) {
2733 modest_platform_information_banner (NULL, NULL,
2735 "cerm_device_memory_full"));
2740 * djcb: if we're in low-memory state, we only allow for
2741 * saving messages smaller than
2742 * MODEST_MAX_LOW_MEMORY_MESSAGE_SIZE (see modest-defs.h) this
2743 * should still allow for sending anything critical...
2745 if ((expected_size > MODEST_MAX_LOW_MEMORY_MESSAGE_SIZE) &&
2746 modest_platform_check_memory_low (MODEST_WINDOW(edit_window), TRUE))
2750 * djcb: we also make sure that the attachments are smaller than the max size
2751 * this is for the case where we'd try to forward a message with attachments
2752 * bigger than our max allowed size, or sending an message from drafts which
2753 * somehow got past our checks when attaching.
2755 if (expected_size > MODEST_MAX_ATTACHMENT_SIZE) {
2756 modest_platform_run_information_dialog (
2757 GTK_WINDOW(edit_window),
2758 dgettext("ke-recv","memr_ib_operation_disabled"),
2767 modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edit_window)
2769 TnyTransportAccount *transport_account;
2770 ModestMailOperation *mail_operation;
2772 gchar *account_name, *from;
2773 ModestAccountMgr *account_mgr;
2774 gboolean had_error = FALSE;
2775 ModestMainWindow *win = NULL;
2777 g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window), FALSE);
2779 data = modest_msg_edit_window_get_msg_data (edit_window);
2782 if (!enough_space_for_message (edit_window, data)) {
2783 modest_msg_edit_window_free_msg_data (edit_window, data);
2787 account_name = g_strdup (data->account_name);
2788 account_mgr = modest_runtime_get_account_mgr();
2790 account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
2792 account_name = modest_account_mgr_get_default_account (account_mgr);
2793 if (!account_name) {
2794 g_printerr ("modest: no account found\n");
2795 modest_msg_edit_window_free_msg_data (edit_window, data);
2799 if (!strcmp (account_name, MODEST_LOCAL_FOLDERS_ACCOUNT_ID)) {
2800 account_name = g_strdup (data->account_name);
2804 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
2805 (modest_runtime_get_account_store (),
2807 TNY_ACCOUNT_TYPE_TRANSPORT));
2808 if (!transport_account) {
2809 g_printerr ("modest: no transport account found for '%s'\n", account_name);
2810 g_free (account_name);
2811 modest_msg_edit_window_free_msg_data (edit_window, data);
2814 from = modest_account_mgr_get_from_string (account_mgr, account_name);
2816 /* Create the mail operation */
2817 mail_operation = modest_mail_operation_new_with_error_handling (NULL, modest_ui_actions_disk_operations_error_handler,
2819 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
2821 modest_mail_operation_save_to_drafts (mail_operation,
2833 data->priority_flags,
2834 on_save_to_drafts_cb,
2835 g_object_ref(edit_window));
2837 #ifdef MODEST_TOOLKIT_HILDON2
2838 /* In hildon2 we always show the information banner on saving to drafts.
2839 * It will be a system information banner in this case.
2841 gchar *text = g_strdup_printf (_("mail_va_saved_to_drafts"), _("mcen_me_folder_drafts"));
2842 modest_platform_information_banner (NULL, NULL, text);
2845 /* Use the main window as the parent of the banner, if the
2846 main window does not exist it won't be shown, if the parent
2847 window exists then it's properly shown. We don't use the
2848 editor window because it could be closed (save to drafts
2849 could happen after closing the window */
2850 win = (ModestMainWindow *)
2851 modest_window_mgr_get_main_window( modest_runtime_get_window_mgr(), FALSE);
2853 gchar *text = g_strdup_printf (_("mail_va_saved_to_drafts"), _("mcen_me_folder_drafts"));
2854 modest_platform_information_banner (GTK_WIDGET (win), NULL, text);
2858 modest_msg_edit_window_set_modified (edit_window, FALSE);
2862 g_free (account_name);
2863 g_object_unref (G_OBJECT (transport_account));
2864 g_object_unref (G_OBJECT (mail_operation));
2866 modest_msg_edit_window_free_msg_data (edit_window, data);
2869 * If the drafts folder is selected then make the header view
2870 * insensitive while the message is being saved to drafts
2871 * (it'll be sensitive again in on_save_to_drafts_cb()). This
2872 * is not very clean but it avoids letting the drafts folder
2873 * in an inconsistent state: the user could edit the message
2874 * being saved and undesirable things would happen.
2875 * In the average case the user won't notice anything at
2876 * all. In the worst case (the user is editing a really big
2877 * file from Drafts) the header view will be insensitive
2878 * during the saving process (10 or 20 seconds, depending on
2879 * the message). Anyway this is just a quick workaround: once
2880 * we find a better solution it should be removed
2881 * See NB#65125 (commend #18) for details.
2883 if (!had_error && win != NULL) {
2884 ModestFolderView *view = MODEST_FOLDER_VIEW(modest_main_window_get_child_widget(
2885 win, MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW));
2887 TnyFolder *folder = TNY_FOLDER(modest_folder_view_get_selected(view));
2889 if (modest_tny_folder_is_local_folder(folder)) {
2890 TnyFolderType folder_type;
2891 folder_type = modest_tny_folder_get_local_or_mmc_folder_type(folder);
2892 if (folder_type == TNY_FOLDER_TYPE_DRAFTS) {
2893 GtkWidget *hdrview = modest_main_window_get_child_widget(
2894 win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2895 if (hdrview) gtk_widget_set_sensitive(hdrview, FALSE);
2899 if (folder != NULL) g_object_unref(folder);
2906 /* For instance, when clicking the Send toolbar button when editing a message: */
2908 modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
2910 TnyTransportAccount *transport_account = NULL;
2911 gboolean had_error = FALSE;
2913 ModestAccountMgr *account_mgr;
2914 gchar *account_name;
2916 ModestMailOperation *mail_operation;
2918 g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window), TRUE);
2920 if (!modest_msg_edit_window_check_names (edit_window, TRUE))
2923 data = modest_msg_edit_window_get_msg_data (edit_window);
2926 if (!enough_space_for_message (edit_window, data)) {
2927 modest_msg_edit_window_free_msg_data (edit_window, data);
2931 account_mgr = modest_runtime_get_account_mgr();
2932 account_name = g_strdup (data->account_name);
2934 account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
2937 account_name = modest_account_mgr_get_default_account (account_mgr);
2939 if (!account_name) {
2940 modest_msg_edit_window_free_msg_data (edit_window, data);
2941 /* Run account setup wizard */
2942 if (!modest_ui_actions_run_account_setup_wizard (MODEST_WINDOW(edit_window))) {
2947 /* Get the currently-active transport account for this modest account: */
2948 if (strcmp (account_name, MODEST_LOCAL_FOLDERS_ACCOUNT_ID) != 0) {
2950 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
2951 (modest_runtime_get_account_store (),
2952 account_name, TNY_ACCOUNT_TYPE_TRANSPORT));
2955 if (!transport_account) {
2956 modest_msg_edit_window_free_msg_data (edit_window, data);
2957 /* Run account setup wizard */
2958 if (!modest_ui_actions_run_account_setup_wizard(MODEST_WINDOW(edit_window)))
2963 /* Create the mail operation */
2964 from = modest_account_mgr_get_from_string (account_mgr, account_name);
2965 mail_operation = modest_mail_operation_new_with_error_handling (NULL, modest_ui_actions_disk_operations_error_handler, NULL, NULL);
2966 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
2968 modest_mail_operation_send_new_mail (mail_operation,
2980 data->priority_flags);
2982 if (modest_mail_operation_get_status (mail_operation) == MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS)
2983 modest_platform_information_banner (NULL, NULL, _("mcen_ib_outbox_waiting_to_be_sent"));
2986 if (modest_mail_operation_get_error (mail_operation) != NULL) {
2987 const GError *error = modest_mail_operation_get_error (mail_operation);
2988 if (error->domain == MODEST_MAIL_OPERATION_ERROR &&
2989 error->code == MODEST_MAIL_OPERATION_ERROR_INSTANCE_CREATION_FAILED) {
2990 g_warning ("%s failed: %s\n", __FUNCTION__, (modest_mail_operation_get_error (mail_operation))->message);
2991 modest_platform_information_banner (NULL, NULL, _CS("sfil_ni_not_enough_memory"));
2998 g_free (account_name);
2999 g_object_unref (G_OBJECT (transport_account));
3000 g_object_unref (G_OBJECT (mail_operation));
3002 modest_msg_edit_window_free_msg_data (edit_window, data);
3005 modest_msg_edit_window_set_sent (edit_window, TRUE);
3007 /* Save settings and close the window: */
3008 modest_ui_actions_on_close_window (NULL, MODEST_WINDOW (edit_window));
3015 modest_ui_actions_on_toggle_bold (GtkToggleAction *action,
3016 ModestMsgEditWindow *window)
3018 ModestMsgEditFormatState *format_state = NULL;
3020 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3021 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
3023 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3026 format_state = modest_msg_edit_window_get_format_state (window);
3027 g_return_if_fail (format_state != NULL);
3029 format_state->bold = gtk_toggle_action_get_active (action);
3030 modest_msg_edit_window_set_format_state (window, format_state);
3031 g_free (format_state);
3036 modest_ui_actions_on_toggle_italics (GtkToggleAction *action,
3037 ModestMsgEditWindow *window)
3039 ModestMsgEditFormatState *format_state = NULL;
3041 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3042 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
3044 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3047 format_state = modest_msg_edit_window_get_format_state (window);
3048 g_return_if_fail (format_state != NULL);
3050 format_state->italics = gtk_toggle_action_get_active (action);
3051 modest_msg_edit_window_set_format_state (window, format_state);
3052 g_free (format_state);
3057 modest_ui_actions_on_toggle_bullets (GtkToggleAction *action,
3058 ModestMsgEditWindow *window)
3060 ModestMsgEditFormatState *format_state = NULL;
3062 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3063 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
3065 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3068 format_state = modest_msg_edit_window_get_format_state (window);
3069 g_return_if_fail (format_state != NULL);
3071 format_state->bullet = gtk_toggle_action_get_active (action);
3072 modest_msg_edit_window_set_format_state (window, format_state);
3073 g_free (format_state);
3078 modest_ui_actions_on_change_justify (GtkRadioAction *action,
3079 GtkRadioAction *selected,
3080 ModestMsgEditWindow *window)
3082 ModestMsgEditFormatState *format_state = NULL;
3083 GtkJustification value;
3085 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3087 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3090 value = gtk_radio_action_get_current_value (selected);
3092 format_state = modest_msg_edit_window_get_format_state (window);
3093 g_return_if_fail (format_state != NULL);
3095 format_state->justification = value;
3096 modest_msg_edit_window_set_format_state (window, format_state);
3097 g_free (format_state);
3101 modest_ui_actions_on_select_editor_color (GtkAction *action,
3102 ModestMsgEditWindow *window)
3104 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3105 g_return_if_fail (GTK_IS_ACTION (action));
3107 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3110 modest_msg_edit_window_select_color (window);
3114 modest_ui_actions_on_select_editor_background_color (GtkAction *action,
3115 ModestMsgEditWindow *window)
3117 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3118 g_return_if_fail (GTK_IS_ACTION (action));
3120 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3123 modest_msg_edit_window_select_background_color (window);
3127 modest_ui_actions_on_insert_image (GtkAction *action,
3128 ModestMsgEditWindow *window)
3130 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3131 g_return_if_fail (GTK_IS_ACTION (action));
3134 if (modest_platform_check_memory_low (MODEST_WINDOW(window), TRUE))
3137 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3140 modest_msg_edit_window_insert_image (window);
3144 modest_ui_actions_on_attach_file (GtkAction *action,
3145 ModestMsgEditWindow *window)
3147 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3148 g_return_if_fail (GTK_IS_ACTION (action));
3150 if (modest_platform_check_memory_low (MODEST_WINDOW(window), TRUE))
3153 modest_msg_edit_window_offer_attach_file (window);
3157 modest_ui_actions_on_remove_attachments (GtkAction *action,
3158 ModestMsgEditWindow *window)
3160 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3161 g_return_if_fail (GTK_IS_ACTION (action));
3163 modest_msg_edit_window_remove_attachments (window, NULL);
3167 #ifndef MODEST_TOOLKIT_GTK
3172 TnyFolderStore *folder;
3173 } CreateFolderHelper;
3176 show_create_folder_in_timeout (gpointer data)
3178 CreateFolderHelper *helper = (CreateFolderHelper *) data;
3180 /* Remove the timeout ASAP, we can not wait until the dialog
3181 is shown because it could take a lot of time and so the
3182 timeout could be called twice or more times */
3183 g_source_remove (helper->handler);
3185 gdk_threads_enter ();
3186 do_create_folder (helper->win, helper->folder, helper->name);
3187 gdk_threads_leave ();
3189 g_object_unref (helper->win);
3190 g_object_unref (helper->folder);
3191 g_free (helper->name);
3192 g_slice_free (CreateFolderHelper, helper);
3199 do_create_folder_cb (ModestMailOperation *mail_op,
3200 TnyFolderStore *parent_folder,
3201 TnyFolder *new_folder,
3204 gchar *suggested_name = (gchar *) user_data;
3205 GtkWindow *source_win = (GtkWindow *) modest_mail_operation_get_source (mail_op);
3207 if (modest_mail_operation_get_error (mail_op)) {
3209 /* Show an error. If there was some problem writing to
3210 disk, show it, otherwise show the generic folder
3211 create error. We do it here and not in an error
3212 handler because the call to do_create_folder will
3213 stop the main loop in a gtk_dialog_run and then,
3214 the message won't be shown until that dialog is
3216 modest_ui_actions_disk_operations_error_handler (mail_op,
3217 _("mail_in_ui_folder_create_error"));
3219 /* Try again. Do *NOT* show any error because the mail
3220 operations system will do it for us because we
3221 created the mail_op with new_with_error_handler */
3222 #ifndef MODEST_TOOLKIT_GTK
3223 CreateFolderHelper *helper;
3224 helper = g_slice_new0 (CreateFolderHelper);
3225 helper->name = g_strdup (suggested_name);
3226 helper->folder = g_object_ref (parent_folder);
3227 helper->win = g_object_ref (source_win);
3229 /* Ugly but neccesary stuff. The problem is that the
3230 dialog when is shown calls a function that destroys
3231 all the temporary windows, so the banner is
3233 helper->handler = g_timeout_add (2000, show_create_folder_in_timeout, helper);
3235 do_create_folder (source_win, parent_folder, (const gchar *) suggested_name);
3238 /* the 'source_win' is either the ModestMainWindow, or the 'Move to folder'-dialog
3239 * FIXME: any other? */
3240 GtkWidget *folder_view;
3242 if (MODEST_IS_MAIN_WINDOW(source_win))
3244 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (source_win),
3245 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3247 folder_view = GTK_WIDGET(g_object_get_data (G_OBJECT (source_win),
3248 MODEST_MOVE_TO_DIALOG_FOLDER_VIEW));
3250 /* Select the newly created folder. It could happen
3251 that the widget is no longer there (i.e. the window
3252 has been destroyed, so we need to check this */
3254 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view),
3256 g_object_unref (new_folder);
3258 /* Free. Note that the first time it'll be NULL so noop */
3259 g_free (suggested_name);
3260 g_object_unref (source_win);
3264 do_create_folder (GtkWindow *parent_window,
3265 TnyFolderStore *parent_folder,
3266 const gchar *suggested_name)
3269 gchar *folder_name = NULL;
3271 result = modest_platform_run_new_folder_dialog (GTK_WINDOW (parent_window),
3273 (gchar *) suggested_name,
3276 if (result == GTK_RESPONSE_ACCEPT) {
3277 ModestMailOperation *mail_op;
3279 mail_op = modest_mail_operation_new ((GObject *) parent_window);
3280 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
3282 modest_mail_operation_create_folder (mail_op,
3284 (const gchar *) folder_name,
3285 do_create_folder_cb,
3287 g_object_unref (mail_op);
3292 create_folder_performer (gboolean canceled,
3294 GtkWindow *parent_window,
3295 TnyAccount *account,
3298 TnyFolderStore *parent_folder = TNY_FOLDER_STORE (user_data);
3300 if (canceled || err) {
3301 /* In memory full conditions we could get this error here */
3302 check_memory_full_error ((GtkWidget *) parent_window, err);
3306 /* Run the new folder dialog */
3307 do_create_folder (GTK_WINDOW (parent_window), parent_folder, NULL);
3310 g_object_unref (parent_folder);
3314 modest_ui_actions_create_folder(GtkWidget *parent_window,
3315 GtkWidget *folder_view)
3317 TnyFolderStore *parent_folder;
3319 #ifdef MODEST_TOOLKIT_HILDON2
3320 const gchar *active_account;
3321 TnyAccount *account;
3323 /* In hildon 2.2 we use the current account as default parent */
3324 active_account = modest_window_get_active_account (MODEST_WINDOW (parent_window));
3325 account = modest_tny_account_store_get_server_account (modest_runtime_get_account_store (),
3327 TNY_ACCOUNT_TYPE_STORE);
3328 parent_folder = TNY_FOLDER_STORE (account);
3330 parent_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
3333 if (parent_folder) {
3334 /* The parent folder will be freed in the callback */
3335 modest_platform_connect_if_remote_and_perform (GTK_WINDOW (parent_window),
3338 create_folder_performer,
3341 #ifdef MODEST_TOOLKIT_HILDON2
3342 g_object_unref (parent_folder);
3347 modest_ui_actions_on_new_folder (GtkAction *action, ModestWindow *window)
3350 g_return_if_fail (MODEST_IS_WINDOW(window));
3352 if (MODEST_IS_MAIN_WINDOW (window)) {
3353 GtkWidget *folder_view;
3355 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (window),
3356 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3360 modest_ui_actions_create_folder (GTK_WIDGET (window), folder_view);
3361 #ifdef MODEST_TOOLKIT_HILDON2
3362 } else if (MODEST_IS_FOLDER_WINDOW (window)) {
3363 GtkWidget *folder_view;
3365 folder_view = GTK_WIDGET (modest_folder_window_get_folder_view (MODEST_FOLDER_WINDOW (window)));
3366 modest_ui_actions_create_folder (GTK_WIDGET (window), folder_view);
3369 g_assert_not_reached ();
3374 modest_ui_actions_rename_folder_error_handler (ModestMailOperation *mail_op,
3377 const GError *error = NULL;
3378 const gchar *message = NULL;
3380 /* Get error message */
3381 error = modest_mail_operation_get_error (mail_op);
3383 g_return_if_reached ();
3385 if (error->domain == MODEST_MAIL_OPERATION_ERROR &&
3386 error->code == MODEST_MAIL_OPERATION_ERROR_FOLDER_EXISTS) {
3387 message = _CS("ckdg_ib_folder_already_exists");
3388 } else if (error->domain == TNY_ERROR_DOMAIN &&
3389 error->code == TNY_SERVICE_ERROR_STATE) {
3390 /* This means that the folder is already in use (a
3391 message is opened for example */
3392 message = _("emev_ni_internal_error");
3394 message = _("emev_ib_ui_imap_unable_to_rename");
3397 /* We don't set a parent for the dialog because the dialog
3398 will be destroyed so the banner won't appear */
3399 modest_platform_information_banner (NULL, NULL, message);
3403 TnyFolderStore *folder;
3408 on_rename_folder_cb (ModestMailOperation *mail_op,
3409 TnyFolder *new_folder,
3412 ModestFolderView *folder_view;
3414 /* If the window was closed when renaming a folder, or if
3415 * it's not a main window this will happen */
3416 if (!MODEST_IS_FOLDER_VIEW (user_data))
3419 folder_view = MODEST_FOLDER_VIEW (user_data);
3420 /* Note that if the rename fails new_folder will be NULL */
3422 modest_folder_view_select_folder (folder_view, new_folder, FALSE);
3424 modest_folder_view_select_first_inbox_or_local (folder_view);
3426 gtk_widget_grab_focus (GTK_WIDGET (folder_view));
3430 on_rename_folder_performer (gboolean canceled,
3432 GtkWindow *parent_window,
3433 TnyAccount *account,
3436 ModestMailOperation *mail_op = NULL;
3437 GtkTreeSelection *sel = NULL;
3438 GtkWidget *folder_view = NULL;
3439 RenameFolderInfo *data = (RenameFolderInfo*)user_data;
3441 if (canceled || err) {
3442 /* In memory full conditions we could get this error here */
3443 check_memory_full_error ((GtkWidget *) parent_window, err);
3447 modest_mail_operation_new_with_error_handling (G_OBJECT(parent_window),
3448 modest_ui_actions_rename_folder_error_handler,
3449 parent_window, NULL);
3451 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
3454 if (MODEST_IS_MAIN_WINDOW(parent_window)) {
3456 folder_view = modest_main_window_get_child_widget (
3457 MODEST_MAIN_WINDOW (parent_window),
3458 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3460 /* Clear the headers view */
3461 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_view));
3462 gtk_tree_selection_unselect_all (sel);
3467 /* Actually rename the folder */
3468 modest_mail_operation_rename_folder (mail_op,
3469 TNY_FOLDER (data->folder),
3470 (const gchar *) (data->new_name),
3471 on_rename_folder_cb,
3473 g_object_unref (data->folder);
3474 g_object_unref (mail_op);
3477 g_free (data->new_name);
3482 modest_ui_actions_on_rename_folder (GtkAction *action,
3483 ModestWindow *window)
3485 modest_ui_actions_on_edit_mode_rename_folder (window);
3489 modest_ui_actions_on_edit_mode_rename_folder (ModestWindow *window)
3491 TnyFolderStore *folder;
3492 GtkWidget *folder_view;
3493 gboolean do_rename = TRUE;
3495 g_return_val_if_fail (MODEST_IS_WINDOW(window), FALSE);
3497 if (MODEST_IS_MAIN_WINDOW (window)) {
3498 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (window),
3499 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3503 #ifdef MODEST_TOOLKIT_HILDON2
3504 } else if (MODEST_IS_FOLDER_WINDOW (window)) {
3505 folder_view = GTK_WIDGET (modest_folder_window_get_folder_view (MODEST_FOLDER_WINDOW (window)));
3509 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
3514 if (TNY_IS_FOLDER (folder)) {
3515 gchar *folder_name = NULL;
3517 const gchar *current_name;
3518 TnyFolderStore *parent;
3520 current_name = tny_folder_get_name (TNY_FOLDER (folder));
3521 parent = tny_folder_get_folder_store (TNY_FOLDER (folder));
3522 response = modest_platform_run_rename_folder_dialog (GTK_WINDOW (window),
3523 parent, current_name,
3525 g_object_unref (parent);
3527 if (response != GTK_RESPONSE_ACCEPT || strlen (folder_name) == 0) {
3530 RenameFolderInfo *rename_folder_data = g_new0 (RenameFolderInfo, 1);
3531 rename_folder_data->folder = g_object_ref (folder);
3532 rename_folder_data->new_name = folder_name;
3533 modest_platform_connect_if_remote_and_perform (GTK_WINDOW(window), TRUE,
3534 folder, on_rename_folder_performer, rename_folder_data);
3537 g_object_unref (folder);
3542 modest_ui_actions_delete_folder_error_handler (ModestMailOperation *mail_op,
3545 GObject *win = modest_mail_operation_get_source (mail_op);
3547 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
3548 _("mail_in_ui_folder_delete_error"),
3550 g_object_unref (win);
3554 TnyFolderStore *folder;
3555 gboolean move_to_trash;
3559 on_delete_folder_cb (gboolean canceled,
3561 GtkWindow *parent_window,
3562 TnyAccount *account,
3565 DeleteFolderInfo *info = (DeleteFolderInfo*) user_data;
3566 GtkWidget *folder_view;
3567 ModestMailOperation *mail_op;
3568 GtkTreeSelection *sel;
3570 if (!MODEST_IS_WINDOW(parent_window) || canceled || (err!=NULL)) {
3571 g_object_unref (G_OBJECT (info->folder));
3576 if (MODEST_IS_MAIN_WINDOW (parent_window)) {
3577 folder_view = modest_main_window_get_child_widget (
3578 MODEST_MAIN_WINDOW (parent_window),
3579 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3580 #ifdef MODEST_TOOLKIT_HILDON2
3581 } else if (MODEST_IS_FOLDER_WINDOW (parent_window)) {
3582 folder_view = GTK_WIDGET (modest_folder_window_get_folder_view (MODEST_FOLDER_WINDOW (parent_window)));
3586 /* Unselect the folder before deleting it to free the headers */
3587 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_view));
3588 gtk_tree_selection_unselect_all (sel);
3590 /* Create the mail operation */
3592 modest_mail_operation_new_with_error_handling (G_OBJECT(parent_window),
3593 modest_ui_actions_delete_folder_error_handler,
3596 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
3598 modest_mail_operation_remove_folder (mail_op, TNY_FOLDER (info->folder), info->move_to_trash);
3600 modest_folder_view_select_first_inbox_or_local (MODEST_FOLDER_VIEW (folder_view));
3602 g_object_unref (G_OBJECT (mail_op));
3603 g_object_unref (G_OBJECT (info->folder));
3608 delete_folder (ModestWindow *window, gboolean move_to_trash)
3610 TnyFolderStore *folder;
3611 GtkWidget *folder_view;
3615 g_return_val_if_fail (MODEST_IS_WINDOW(window), FALSE);
3617 if (MODEST_IS_MAIN_WINDOW (window)) {
3619 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (window),
3620 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3621 #ifdef MODEST_TOOLKIT_HILDON2
3622 } else if (MODEST_IS_FOLDER_WINDOW (window)) {
3623 folder_view = GTK_WIDGET (modest_folder_window_get_folder_view (MODEST_FOLDER_WINDOW (window)));
3629 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
3631 /* Show an error if it's an account */
3632 if (!TNY_IS_FOLDER (folder)) {
3633 modest_platform_run_information_dialog (GTK_WINDOW (window),
3634 _("mail_in_ui_folder_delete_error"),
3636 g_object_unref (G_OBJECT (folder));
3641 message = g_strdup_printf (_("mcen_nc_delete_folder_text"),
3642 tny_folder_get_name (TNY_FOLDER (folder)));
3643 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (window),
3644 (const gchar *) message);
3647 if (response == GTK_RESPONSE_OK) {
3648 DeleteFolderInfo *info;
3649 info = g_new0(DeleteFolderInfo, 1);
3650 info->folder = folder;
3651 info->move_to_trash = move_to_trash;
3652 g_object_ref (G_OBJECT (info->folder));
3653 TnyAccount *account = tny_folder_get_account (TNY_FOLDER (folder));
3654 modest_platform_connect_if_remote_and_perform (GTK_WINDOW (window),
3656 TNY_FOLDER_STORE (account),
3657 on_delete_folder_cb, info);
3658 g_object_unref (account);
3663 g_object_unref (G_OBJECT (folder));
3667 modest_ui_actions_on_delete_folder (GtkAction *action,
3668 ModestWindow *window)
3670 modest_ui_actions_on_edit_mode_delete_folder (window);
3674 modest_ui_actions_on_edit_mode_delete_folder (ModestWindow *window)
3676 g_return_val_if_fail (MODEST_IS_WINDOW(window), TRUE);
3678 return delete_folder (window, FALSE);
3682 modest_ui_actions_on_move_folder_to_trash_folder (GtkAction *action, ModestMainWindow *main_window)
3684 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
3686 delete_folder (MODEST_WINDOW (main_window), TRUE);
3690 typedef struct _PasswordDialogFields {
3691 GtkWidget *username;
3692 GtkWidget *password;
3694 } PasswordDialogFields;
3697 password_dialog_check_field (GtkEditable *editable,
3698 PasswordDialogFields *fields)
3701 gboolean any_value_empty = FALSE;
3703 value = gtk_entry_get_text (GTK_ENTRY (fields->username));
3704 if ((value == NULL) || value[0] == '\0') {
3705 any_value_empty = TRUE;
3707 value = gtk_entry_get_text (GTK_ENTRY (fields->password));
3708 if ((value == NULL) || value[0] == '\0') {
3709 any_value_empty = TRUE;
3711 gtk_dialog_set_response_sensitive (GTK_DIALOG (fields->dialog), GTK_RESPONSE_ACCEPT, !any_value_empty);
3715 modest_ui_actions_on_password_requested (TnyAccountStore *account_store,
3716 const gchar* server_account_name,
3721 ModestMainWindow *main_window)
3723 g_return_if_fail(server_account_name);
3724 gboolean completed = FALSE;
3725 PasswordDialogFields *fields = NULL;
3727 /* Initalize output parameters: */
3734 #ifndef MODEST_TOOLKIT_GTK
3735 /* Maemo uses a different (awkward) button order,
3736 * It should probably just use gtk_alternative_dialog_button_order ().
3738 #ifdef MODEST_TOOLKIT_HILDON2
3740 gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
3743 _HL("wdgt_bd_done"),
3744 GTK_RESPONSE_ACCEPT,
3748 gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
3751 _("mcen_bd_dialog_ok"),
3752 GTK_RESPONSE_ACCEPT,
3753 _("mcen_bd_dialog_cancel"),
3754 GTK_RESPONSE_REJECT,
3756 #endif /* MODEST_TOOLKIT_HILDON2 */
3759 gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
3763 GTK_RESPONSE_REJECT,
3765 GTK_RESPONSE_ACCEPT,
3767 #endif /* MODEST_TOOLKIT_GTK */
3769 modest_window_mgr_set_modal (modest_runtime_get_window_mgr(), GTK_WINDOW (dialog), NULL);
3771 gchar *server_name = modest_account_mgr_get_server_account_hostname (
3772 modest_runtime_get_account_mgr(), server_account_name);
3773 if (!server_name) {/* This happened once, though I don't know why. murrayc. */
3774 g_warning("%s: Could not get server name for server account '%s'", __FUNCTION__, server_account_name);
3777 gtk_widget_destroy (dialog);
3781 gchar *txt = g_strdup_printf (_("mail_ia_password_info"), server_name);
3782 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), gtk_label_new(txt),
3785 g_free (server_name);
3789 gchar *initial_username = modest_account_mgr_get_server_account_username (
3790 modest_runtime_get_account_mgr(), server_account_name);
3792 GtkWidget *entry_username = gtk_entry_new ();
3793 if (initial_username)
3794 gtk_entry_set_text (GTK_ENTRY (entry_username), initial_username);
3795 /* Dim this if a connection has ever succeeded with this username,
3796 * as per the UI spec: */
3797 /* const gboolean username_known = */
3798 /* modest_account_mgr_get_server_account_username_has_succeeded( */
3799 /* modest_runtime_get_account_mgr(), server_account_name); */
3800 /* gtk_widget_set_sensitive (entry_username, !username_known); */
3802 /* We drop the username sensitive code and disallow changing it here
3803 * as tinymail does not support really changing the username in the callback
3805 gtk_widget_set_sensitive (entry_username, FALSE);
3807 #ifndef MODEST_TOOLKIT_GTK
3808 /* Auto-capitalization is the default, so let's turn it off: */
3809 hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_username), HILDON_GTK_INPUT_MODE_FULL);
3811 /* Create a size group to be used by all captions.
3812 * Note that HildonCaption does not create a default size group if we do not specify one.
3813 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
3814 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
3816 GtkWidget *caption = hildon_caption_new (sizegroup,
3817 _("mail_fi_username"), entry_username, NULL, HILDON_CAPTION_MANDATORY);
3818 gtk_widget_show (entry_username);
3819 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
3820 FALSE, FALSE, MODEST_MARGIN_HALF);
3821 gtk_widget_show (caption);
3823 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry_username,
3825 #endif /* !MODEST_TOOLKIT_GTK */
3828 GtkWidget *entry_password = gtk_entry_new ();
3829 gtk_entry_set_visibility (GTK_ENTRY(entry_password), FALSE);
3830 /* gtk_entry_set_invisible_char (GTK_ENTRY(entry_password), "*"); */
3832 #ifndef MODEST_TOOLKIT_GTK
3833 /* Auto-capitalization is the default, so let's turn it off: */
3834 hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_password),
3835 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
3837 caption = hildon_caption_new (sizegroup,
3838 _("mail_fi_password"), entry_password, NULL, HILDON_CAPTION_MANDATORY);
3839 gtk_widget_show (entry_password);
3840 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
3841 FALSE, FALSE, MODEST_MARGIN_HALF);
3842 gtk_widget_show (caption);
3843 g_object_unref (sizegroup);
3845 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry_password,
3847 #endif /* !MODEST_TOOLKIT_GTK */
3849 if (initial_username != NULL)
3850 gtk_widget_grab_focus (GTK_WIDGET (entry_password));
3852 /* This is not in the Maemo UI spec:
3853 remember_pass_check = gtk_check_button_new_with_label (_("Remember password"));
3854 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), remember_pass_check,
3858 fields = g_slice_new0 (PasswordDialogFields);
3859 fields->username = entry_username;
3860 fields->password = entry_password;
3861 fields->dialog = dialog;
3863 g_signal_connect (entry_username, "changed", G_CALLBACK (password_dialog_check_field), fields);
3864 g_signal_connect (entry_password, "changed", G_CALLBACK (password_dialog_check_field), fields);
3865 password_dialog_check_field (NULL, fields);
3867 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
3869 while (!completed) {
3871 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
3873 *username = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_username)));
3875 /* Note that an empty field becomes the "" string */
3876 if (*username && strlen (*username) > 0) {
3877 modest_account_mgr_set_server_account_username (modest_runtime_get_account_mgr(),
3878 server_account_name,
3882 const gboolean username_was_changed =
3883 (strcmp (*username, initial_username) != 0);
3884 if (username_was_changed) {
3885 g_warning ("%s: tinymail does not yet support changing the "
3886 "username in the get_password() callback.\n", __FUNCTION__);
3892 modest_platform_information_banner (GTK_WIDGET (dialog), NULL,
3893 _("mcen_ib_username_pw_incorrect"));
3899 *password = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_password)));
3901 /* We do not save the password in the configuration,
3902 * because this function is only called for passwords that should
3903 * not be remembered:
3904 modest_server_account_set_password (
3905 modest_runtime_get_account_mgr(), server_account_name,
3912 #ifndef MODEST_TOOLKIT_HILDON2
3913 /* Set parent to NULL or the banner will disappear with its parent dialog */
3914 modest_platform_information_banner(NULL, NULL, _("mail_ib_login_cancelled"));
3926 /* This is not in the Maemo UI spec:
3927 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (remember_pass_check)))
3933 g_free (initial_username);
3934 gtk_widget_destroy (dialog);
3935 g_slice_free (PasswordDialogFields, fields);
3937 /* printf ("DEBUG: %s: cancel=%d\n", __FUNCTION__, *cancel); */
3941 modest_ui_actions_on_cut (GtkAction *action,
3942 ModestWindow *window)
3944 GtkWidget *focused_widget;
3945 GtkClipboard *clipboard;
3947 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
3948 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
3949 if (GTK_IS_EDITABLE (focused_widget)) {
3950 gtk_editable_cut_clipboard (GTK_EDITABLE(focused_widget));
3951 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3952 gtk_clipboard_store (clipboard);
3953 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
3954 GtkTextBuffer *buffer;
3956 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
3957 if (modest_text_utils_buffer_selection_is_valid (buffer)) {
3958 gtk_text_buffer_cut_clipboard (buffer, clipboard, TRUE);
3959 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3960 gtk_clipboard_store (clipboard);
3962 } else if (MODEST_IS_HEADER_VIEW (focused_widget)) {
3963 TnyList *header_list = modest_header_view_get_selected_headers (
3964 MODEST_HEADER_VIEW (focused_widget));
3965 gboolean continue_download = FALSE;
3966 gint num_of_unc_msgs;
3968 num_of_unc_msgs = header_list_count_uncached_msgs(header_list);
3970 if (num_of_unc_msgs) {
3971 TnyAccount *account = get_account_from_header_list (header_list);
3973 continue_download = connect_to_get_msg (window, num_of_unc_msgs, account);
3974 g_object_unref (account);
3978 if (num_of_unc_msgs == 0 || continue_download) {
3979 /* modest_platform_information_banner (
3980 NULL, NULL, _CS("mcen_ib_getting_items"));*/
3981 modest_header_view_cut_selection (
3982 MODEST_HEADER_VIEW (focused_widget));
3985 g_object_unref (header_list);
3986 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
3987 modest_folder_view_cut_selection (MODEST_FOLDER_VIEW (focused_widget));
3992 modest_ui_actions_on_copy (GtkAction *action,
3993 ModestWindow *window)
3995 GtkClipboard *clipboard;
3996 GtkWidget *focused_widget;
3997 gboolean copied = TRUE;
3999 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
4000 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
4002 if (GTK_IS_LABEL (focused_widget)) {
4004 selection = modest_text_utils_label_get_selection (GTK_LABEL (focused_widget));
4005 gtk_clipboard_set_text (clipboard, selection, -1);
4007 gtk_clipboard_set_can_store (clipboard, NULL, 0);
4008 gtk_clipboard_store (clipboard);
4009 } else if (GTK_IS_EDITABLE (focused_widget)) {
4010 gtk_editable_copy_clipboard (GTK_EDITABLE(focused_widget));
4011 gtk_clipboard_set_can_store (clipboard, NULL, 0);
4012 gtk_clipboard_store (clipboard);
4013 } else if (GTK_IS_HTML (focused_widget)) {
4016 sel = gtk_html_get_selection_html (GTK_HTML (focused_widget), &len);
4017 if ((sel == NULL) || (sel[0] == '\0')) {
4020 gtk_html_copy (GTK_HTML (focused_widget));
4021 gtk_clipboard_set_can_store (clipboard, NULL, 0);
4022 gtk_clipboard_store (clipboard);
4024 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
4025 GtkTextBuffer *buffer;
4026 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
4027 if (modest_text_utils_buffer_selection_is_valid (buffer)) {
4028 gtk_text_buffer_copy_clipboard (buffer, clipboard);
4029 gtk_clipboard_set_can_store (clipboard, NULL, 0);
4030 gtk_clipboard_store (clipboard);
4032 } else if (MODEST_IS_HEADER_VIEW (focused_widget)) {
4033 TnyList *header_list = modest_header_view_get_selected_headers (
4034 MODEST_HEADER_VIEW (focused_widget));
4035 gboolean continue_download = FALSE;
4036 gint num_of_unc_msgs;
4038 num_of_unc_msgs = header_list_count_uncached_msgs(header_list);
4040 if (num_of_unc_msgs) {
4041 TnyAccount *account = get_account_from_header_list (header_list);
4043 continue_download = connect_to_get_msg (window, num_of_unc_msgs, account);
4044 g_object_unref (account);
4048 if (num_of_unc_msgs == 0 || continue_download) {
4049 modest_platform_information_banner (
4050 NULL, NULL, _CS("mcen_ib_getting_items"));
4051 modest_header_view_copy_selection (
4052 MODEST_HEADER_VIEW (focused_widget));
4056 g_object_unref (header_list);
4058 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
4059 modest_folder_view_copy_selection (MODEST_FOLDER_VIEW (focused_widget));
4062 /* Show information banner if there was a copy to clipboard */
4064 modest_platform_information_banner (
4065 NULL, NULL, _CS("ecoc_ib_edwin_copied"));
4069 modest_ui_actions_on_undo (GtkAction *action,
4070 ModestWindow *window)
4072 ModestEmailClipboard *clipboard = NULL;
4074 if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
4075 modest_msg_edit_window_undo (MODEST_MSG_EDIT_WINDOW (window));
4076 } else if (MODEST_IS_MAIN_WINDOW (window)) {
4077 /* Clear clipboard source */
4078 clipboard = modest_runtime_get_email_clipboard ();
4079 modest_email_clipboard_clear (clipboard);
4082 g_return_if_reached ();
4087 modest_ui_actions_on_redo (GtkAction *action,
4088 ModestWindow *window)
4090 if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
4091 modest_msg_edit_window_redo (MODEST_MSG_EDIT_WINDOW (window));
4094 g_return_if_reached ();
4100 destroy_information_note (ModestMailOperation *mail_op,
4103 /* destroy information note */
4104 gtk_widget_destroy (GTK_WIDGET(user_data));
4108 destroy_folder_information_note (ModestMailOperation *mail_op,
4109 TnyFolder *new_folder,
4112 /* destroy information note */
4113 gtk_widget_destroy (GTK_WIDGET(user_data));
4118 paste_as_attachment_free (gpointer data)
4120 PasteAsAttachmentHelper *helper = (PasteAsAttachmentHelper *) data;
4122 if (helper->banner) {
4123 gtk_widget_destroy (helper->banner);
4124 g_object_unref (helper->banner);
4130 paste_msg_as_attachment_cb (ModestMailOperation *mail_op,
4135 PasteAsAttachmentHelper *helper = (PasteAsAttachmentHelper *) userdata;
4136 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (helper->window));
4141 modest_msg_edit_window_add_part (MODEST_MSG_EDIT_WINDOW (helper->window), TNY_MIME_PART (msg));
4146 modest_ui_actions_on_paste (GtkAction *action,
4147 ModestWindow *window)
4149 GtkWidget *focused_widget = NULL;
4150 GtkWidget *inf_note = NULL;
4151 ModestMailOperation *mail_op = NULL;
4153 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
4154 if (GTK_IS_EDITABLE (focused_widget)) {
4155 gtk_editable_paste_clipboard (GTK_EDITABLE(focused_widget));
4156 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
4157 ModestEmailClipboard *e_clipboard = NULL;
4158 e_clipboard = modest_runtime_get_email_clipboard ();
4159 if (modest_email_clipboard_cleared (e_clipboard)) {
4160 GtkTextBuffer *buffer;
4161 GtkClipboard *clipboard;
4163 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
4164 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
4165 gtk_text_buffer_paste_clipboard (buffer, clipboard, NULL, TRUE);
4166 } else if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
4167 ModestMailOperation *mail_op;
4168 TnyFolder *src_folder = NULL;
4169 TnyList *data = NULL;
4171 PasteAsAttachmentHelper *helper = g_new0 (PasteAsAttachmentHelper, 1);
4172 helper->window = MODEST_MSG_EDIT_WINDOW (window);
4173 helper->banner = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
4174 _CS("ckct_nw_pasting"));
4175 modest_email_clipboard_get_data (e_clipboard, &src_folder, &data, &delete);
4176 mail_op = modest_mail_operation_new (G_OBJECT (window));
4177 if (helper->banner != NULL) {
4178 g_object_ref (G_OBJECT (helper->banner));
4179 gtk_widget_show (GTK_WIDGET (helper->banner));
4183 modest_mail_operation_get_msgs_full (mail_op,
4185 (GetMsgAsyncUserCallback) paste_msg_as_attachment_cb,
4187 paste_as_attachment_free);
4191 g_object_unref (data);
4193 g_object_unref (src_folder);
4196 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
4197 ModestEmailClipboard *clipboard = NULL;
4198 TnyFolder *src_folder = NULL;
4199 TnyFolderStore *folder_store = NULL;
4200 TnyList *data = NULL;
4201 gboolean delete = FALSE;
4203 /* Check clipboard source */
4204 clipboard = modest_runtime_get_email_clipboard ();
4205 if (modest_email_clipboard_cleared (clipboard))
4208 /* Get elements to paste */
4209 modest_email_clipboard_get_data (clipboard, &src_folder, &data, &delete);
4211 /* Create a new mail operation */
4212 mail_op = modest_mail_operation_new (G_OBJECT(window));
4214 /* Get destination folder */
4215 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (focused_widget));
4217 /* transfer messages */
4221 /* Ask for user confirmation */
4223 modest_ui_actions_msgs_move_to_confirmation (window,
4224 TNY_FOLDER (folder_store),
4228 if (response == GTK_RESPONSE_OK) {
4229 /* Launch notification */
4230 inf_note = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
4231 _CS("ckct_nw_pasting"));
4232 if (inf_note != NULL) {
4233 gtk_window_set_modal (GTK_WINDOW(inf_note), FALSE);
4234 gtk_widget_show (GTK_WIDGET(inf_note));
4237 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
4238 modest_mail_operation_xfer_msgs (mail_op,
4240 TNY_FOLDER (folder_store),
4242 destroy_information_note,
4245 g_object_unref (mail_op);
4248 } else if (src_folder != NULL) {
4249 /* Launch notification */
4250 inf_note = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
4251 _CS("ckct_nw_pasting"));
4252 if (inf_note != NULL) {
4253 gtk_window_set_modal (GTK_WINDOW(inf_note), FALSE);
4254 gtk_widget_show (GTK_WIDGET(inf_note));
4257 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
4258 modest_mail_operation_xfer_folder (mail_op,
4262 destroy_folder_information_note,
4268 g_object_unref (data);
4269 if (src_folder != NULL)
4270 g_object_unref (src_folder);
4271 if (folder_store != NULL)
4272 g_object_unref (folder_store);
4278 modest_ui_actions_on_select_all (GtkAction *action,
4279 ModestWindow *window)
4281 GtkWidget *focused_widget;
4283 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
4284 if (MODEST_IS_ATTACHMENTS_VIEW (focused_widget)) {
4285 modest_attachments_view_select_all (MODEST_ATTACHMENTS_VIEW (focused_widget));
4286 } else if (GTK_IS_LABEL (focused_widget)) {
4287 gtk_label_select_region (GTK_LABEL (focused_widget), 0, -1);
4288 } else if (GTK_IS_EDITABLE (focused_widget)) {
4289 gtk_editable_select_region (GTK_EDITABLE(focused_widget), 0, -1);
4290 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
4291 GtkTextBuffer *buffer;
4292 GtkTextIter start, end;
4294 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
4295 gtk_text_buffer_get_start_iter (buffer, &start);
4296 gtk_text_buffer_get_end_iter (buffer, &end);
4297 gtk_text_buffer_select_range (buffer, &start, &end);
4298 } else if (GTK_IS_HTML (focused_widget)) {
4299 gtk_html_select_all (GTK_HTML (focused_widget));
4300 } else if (MODEST_IS_MAIN_WINDOW (window)) {
4301 GtkWidget *header_view = focused_widget;
4302 GtkTreeSelection *selection = NULL;
4304 if (!(MODEST_IS_HEADER_VIEW (focused_widget))) {
4305 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (window),
4306 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
4309 /* Disable window dimming management */
4310 modest_window_disable_dimming (MODEST_WINDOW(window));
4312 /* Select all messages */
4313 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(header_view));
4314 gtk_tree_selection_select_all (selection);
4316 /* Set focuse on header view */
4317 gtk_widget_grab_focus (header_view);
4319 /* Enable window dimming management */
4320 modest_window_enable_dimming (MODEST_WINDOW(window));
4321 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (window));
4322 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (window));
4328 modest_ui_actions_on_mark_as_read (GtkAction *action,
4329 ModestWindow *window)
4331 g_return_if_fail (MODEST_IS_WINDOW(window));
4333 /* Mark each header as read */
4334 do_headers_action (window, headers_action_mark_as_read, NULL);
4338 modest_ui_actions_on_mark_as_unread (GtkAction *action,
4339 ModestWindow *window)
4341 g_return_if_fail (MODEST_IS_WINDOW(window));
4343 /* Mark each header as read */
4344 do_headers_action (window, headers_action_mark_as_unread, NULL);
4348 modest_ui_actions_on_change_zoom (GtkRadioAction *action,
4349 GtkRadioAction *selected,
4350 ModestWindow *window)
4354 value = gtk_radio_action_get_current_value (selected);
4355 if (MODEST_IS_WINDOW (window)) {
4356 modest_window_set_zoom (MODEST_WINDOW (window), ((gdouble)value)/100);
4361 modest_ui_actions_msg_edit_on_change_priority (GtkRadioAction *action,
4362 GtkRadioAction *selected,
4363 ModestWindow *window)
4365 TnyHeaderFlags flags;
4366 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4368 flags = gtk_radio_action_get_current_value (selected);
4369 modest_msg_edit_window_set_priority_flags (MODEST_MSG_EDIT_WINDOW (window), flags);
4373 modest_ui_actions_msg_edit_on_change_file_format (GtkRadioAction *action,
4374 GtkRadioAction *selected,
4375 ModestWindow *window)
4379 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4381 file_format = gtk_radio_action_get_current_value (selected);
4382 modest_msg_edit_window_set_file_format (MODEST_MSG_EDIT_WINDOW (window), file_format);
4387 modest_ui_actions_on_zoom_plus (GtkAction *action,
4388 ModestWindow *window)
4390 g_return_if_fail (MODEST_IS_WINDOW (window));
4392 modest_window_zoom_plus (MODEST_WINDOW (window));
4396 modest_ui_actions_on_zoom_minus (GtkAction *action,
4397 ModestWindow *window)
4399 g_return_if_fail (MODEST_IS_WINDOW (window));
4401 modest_window_zoom_minus (MODEST_WINDOW (window));
4405 modest_ui_actions_on_toggle_fullscreen (GtkToggleAction *toggle,
4406 ModestWindow *window)
4408 ModestWindowMgr *mgr;
4409 gboolean fullscreen, active;
4410 g_return_if_fail (MODEST_IS_WINDOW (window));
4412 mgr = modest_runtime_get_window_mgr ();
4414 active = (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle)))?1:0;
4415 fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
4417 if (active != fullscreen) {
4418 modest_window_mgr_set_fullscreen_mode (mgr, active);
4419 #ifndef MODEST_TOOLKIT_HILDON2
4420 gtk_window_present (GTK_WINDOW (window));
4426 modest_ui_actions_on_change_fullscreen (GtkAction *action,
4427 ModestWindow *window)
4429 ModestWindowMgr *mgr;
4430 gboolean fullscreen;
4432 g_return_if_fail (MODEST_IS_WINDOW (window));
4434 mgr = modest_runtime_get_window_mgr ();
4435 fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
4436 modest_window_mgr_set_fullscreen_mode (mgr, !fullscreen);
4438 #ifndef MODEST_TOOLKIT_HILDON2
4439 gtk_window_present (GTK_WINDOW (window));
4444 * Used by modest_ui_actions_on_details to call do_headers_action
4447 headers_action_show_details (TnyHeader *header,
4448 ModestWindow *window,
4452 modest_platform_run_header_details_dialog (GTK_WINDOW (window), header);
4456 * Show the header details in a ModestDetailsDialog widget
4459 modest_ui_actions_on_details (GtkAction *action,
4462 TnyList * headers_list;
4466 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
4469 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW (win));
4472 g_object_unref (msg);
4474 headers_list = get_selected_headers (win);
4478 iter = tny_list_create_iterator (headers_list);
4480 header = TNY_HEADER (tny_iterator_get_current (iter));
4482 headers_action_show_details (header, win, NULL);
4483 g_object_unref (header);
4486 g_object_unref (iter);
4487 g_object_unref (headers_list);
4489 } else if (MODEST_IS_MAIN_WINDOW (win)) {
4490 GtkWidget *folder_view, *header_view;
4492 /* Check which widget has the focus */
4493 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
4494 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
4495 if (gtk_widget_is_focus (folder_view)) {
4496 TnyFolderStore *folder_store
4497 = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
4498 if (!folder_store) {
4499 g_warning ("%s: No item was selected.\n", __FUNCTION__);
4502 /* Show only when it's a folder */
4503 /* This function should not be called for account items,
4504 * because we dim the menu item for them. */
4505 if (TNY_IS_FOLDER (folder_store)) {
4506 modest_platform_run_folder_details_dialog (GTK_WINDOW (win),
4507 TNY_FOLDER (folder_store));
4510 g_object_unref (folder_store);
4513 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
4514 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
4515 /* Show details of each header */
4516 do_headers_action (win, headers_action_show_details, header_view);
4518 #ifdef MODEST_TOOLKIT_HILDON2
4519 } else if (MODEST_IS_HEADER_WINDOW (win)) {
4521 GtkWidget *header_view;
4523 header_view = GTK_WIDGET (modest_header_window_get_header_view (MODEST_HEADER_WINDOW (win)));
4524 folder = modest_header_view_get_folder (MODEST_HEADER_VIEW (header_view));
4526 modest_platform_run_folder_details_dialog (GTK_WINDOW (win),
4528 g_object_unref (folder);
4535 modest_ui_actions_on_toggle_show_cc (GtkToggleAction *toggle,
4536 ModestMsgEditWindow *window)
4538 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4540 modest_msg_edit_window_show_cc (window, gtk_toggle_action_get_active (toggle));
4544 modest_ui_actions_on_toggle_show_bcc (GtkToggleAction *toggle,
4545 ModestMsgEditWindow *window)
4547 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4549 modest_msg_edit_window_show_bcc (window, gtk_toggle_action_get_active (toggle));
4553 modest_ui_actions_toggle_folders_view (GtkAction *action,
4554 ModestMainWindow *main_window)
4556 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
4558 if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)))
4559 modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SPLIT);
4561 modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SIMPLE);
4565 modest_ui_actions_on_toggle_toolbar (GtkToggleAction *toggle,
4566 ModestWindow *window)
4568 gboolean active, fullscreen = FALSE;
4569 ModestWindowMgr *mgr;
4571 active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle));
4573 /* Check if we want to toggle the toolbar view in fullscreen
4575 if (!strcmp (gtk_action_get_name (GTK_ACTION (toggle)),
4576 "ViewShowToolbarFullScreen")) {
4580 /* Toggle toolbar */
4581 mgr = modest_runtime_get_window_mgr ();
4582 modest_window_mgr_show_toolbars (mgr, G_TYPE_FROM_INSTANCE (window), active, fullscreen);
4586 modest_ui_actions_msg_edit_on_select_font (GtkAction *action,
4587 ModestMsgEditWindow *window)
4589 modest_msg_edit_window_select_font (window);
4594 modest_ui_actions_on_folder_display_name_changed (ModestFolderView *folder_view,
4595 const gchar *display_name,
4598 /* don't update the display name if it was already set;
4599 * updating the display name apparently is expensive */
4600 const gchar* old_name = gtk_window_get_title (window);
4602 if (display_name == NULL)
4605 if (old_name && display_name && strcmp (old_name, display_name) == 0)
4606 return; /* don't do anything */
4608 /* This is usually used to change the title of the main window, which
4609 * is the one that holds the folder view. Note that this change can
4610 * happen even when the widget doesn't have the focus. */
4611 gtk_window_set_title (window, display_name);
4616 modest_ui_actions_on_select_contacts (GtkAction *action, ModestMsgEditWindow *window)
4618 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4619 modest_msg_edit_window_select_contacts (window);
4623 modest_ui_actions_on_check_names (GtkAction *action, ModestMsgEditWindow *window)
4625 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4626 modest_msg_edit_window_check_names (window, FALSE);
4629 #ifndef MODEST_TOOLKIT_HILDON2
4631 * This function is used to track changes in the selection of the
4632 * folder view that is inside the "move to" dialog to enable/disable
4633 * the OK button because we do not want the user to select a disallowed
4634 * destination for a folder.
4635 * The user also not desired to be able to use NEW button on items where
4636 * folder creation is not possibel.
4639 on_move_to_dialog_folder_selection_changed (ModestFolderView* self,
4640 TnyFolderStore *folder_store,
4644 GtkWidget *dialog = NULL;
4645 gboolean ok_sensitive = TRUE, new_sensitive = TRUE;
4646 gboolean moving_folder = FALSE;
4647 gboolean is_local_account = TRUE;
4648 GtkWidget *folder_view = NULL;
4649 ModestTnyFolderRules rules;
4651 g_return_if_fail (MODEST_IS_FOLDER_VIEW(self));
4656 dialog = gtk_widget_get_ancestor (GTK_WIDGET (self), GTK_TYPE_DIALOG);
4660 /* check if folder_store is an remote account */
4661 if (TNY_IS_ACCOUNT (folder_store)) {
4662 TnyAccount *local_account = NULL;
4663 TnyAccount *mmc_account = NULL;
4664 ModestTnyAccountStore *account_store = NULL;
4666 account_store = modest_runtime_get_account_store ();
4667 local_account = modest_tny_account_store_get_local_folders_account (account_store);
4668 mmc_account = modest_tny_account_store_get_mmc_folders_account (account_store);
4670 if ((gpointer) local_account != (gpointer) folder_store &&
4671 (gpointer) mmc_account != (gpointer) folder_store) {
4672 ModestProtocolType proto;
4673 proto = modest_tny_account_get_protocol_type (TNY_ACCOUNT (folder_store));
4674 if (proto == MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
4675 proto = MODEST_PROTOCOLS_STORE_MAILDIR;
4677 is_local_account = FALSE;
4678 /* New button should be dimmed on remote
4680 new_sensitive = (modest_protocol_registry_protocol_type_has_tag (modest_runtime_get_protocol_registry (),
4682 MODEST_PROTOCOL_REGISTRY_STORE_HAS_FOLDERS));
4684 g_object_unref (local_account);
4686 /* It could not exist */
4688 g_object_unref (mmc_account);
4691 /* Check the target folder rules */
4692 if (TNY_IS_FOLDER (folder_store)) {
4693 rules = modest_tny_folder_get_rules (TNY_FOLDER (folder_store));
4694 if (rules & MODEST_FOLDER_RULES_FOLDER_NON_WRITEABLE) {
4695 ok_sensitive = FALSE;
4696 new_sensitive = FALSE;
4701 /* Check if we're moving a folder */
4702 if (MODEST_IS_MAIN_WINDOW (user_data)) {
4703 /* Get the widgets */
4704 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (user_data),
4705 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
4706 if (gtk_widget_is_focus (folder_view))
4707 moving_folder = TRUE;
4710 if (moving_folder) {
4711 TnyFolderStore *moved_folder = NULL, *parent = NULL;
4713 /* Get the folder to move */
4714 moved_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
4716 /* Check that we're not moving to the same folder */
4717 if (TNY_IS_FOLDER (moved_folder)) {
4718 parent = tny_folder_get_folder_store (TNY_FOLDER (moved_folder));
4719 if (parent == folder_store)
4720 ok_sensitive = FALSE;
4721 g_object_unref (parent);
4724 if (ok_sensitive && TNY_IS_ACCOUNT (folder_store)) {
4725 /* Do not allow to move to an account unless it's the
4726 local folders account */
4727 if (!is_local_account)
4728 ok_sensitive = FALSE;
4731 if (ok_sensitive && (moved_folder == folder_store)) {
4732 /* Do not allow to move to itself */
4733 ok_sensitive = FALSE;
4735 g_object_unref (moved_folder);
4737 TnyFolder *src_folder = NULL;
4739 /* Moving a message */
4740 if (MODEST_IS_MSG_VIEW_WINDOW (user_data)) {
4742 TnyHeader *header = NULL;
4743 header = modest_msg_view_window_get_header
4744 (MODEST_MSG_VIEW_WINDOW (user_data));
4745 if (!TNY_IS_HEADER(header))
4746 g_warning ("%s: could not get source header", __FUNCTION__);
4748 src_folder = tny_header_get_folder (header);
4751 g_object_unref (header);
4754 TNY_FOLDER (modest_folder_view_get_selected
4755 (MODEST_FOLDER_VIEW (folder_view)));
4758 if (TNY_IS_FOLDER(src_folder)) {
4759 /* Do not allow to move the msg to the same folder */
4760 /* Do not allow to move the msg to an account */
4761 if ((gpointer) src_folder == (gpointer) folder_store ||
4762 TNY_IS_ACCOUNT (folder_store))
4763 ok_sensitive = FALSE;
4764 g_object_unref (src_folder);
4766 g_warning ("%s: could not get source folder", __FUNCTION__);
4770 /* Set sensitivity of the OK and NEW button */
4771 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, ok_sensitive);
4772 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), MODEST_GTK_RESPONSE_NEW_FOLDER, new_sensitive);
4777 on_move_to_dialog_response (GtkDialog *dialog,
4781 GtkWidget *parent_win, *folder_view;
4782 MoveToInfo *helper = NULL;
4784 helper = (MoveToInfo *) user_data;
4786 parent_win = (GtkWidget *) helper->win;
4787 folder_view = GTK_WIDGET (g_object_get_data (G_OBJECT (dialog),
4788 MODEST_MOVE_TO_DIALOG_FOLDER_VIEW));
4791 TnyFolderStore *dst_folder;
4793 case MODEST_GTK_RESPONSE_NEW_FOLDER:
4794 modest_ui_actions_create_folder (GTK_WIDGET (dialog), folder_view);
4796 case GTK_RESPONSE_NONE:
4797 case GTK_RESPONSE_CANCEL:
4798 case GTK_RESPONSE_DELETE_EVENT:
4800 case GTK_RESPONSE_OK:
4801 dst_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
4802 /* Do window specific stuff */
4803 if (MODEST_IS_MAIN_WINDOW (parent_win)) {
4804 modest_ui_actions_on_main_window_move_to (NULL,
4807 MODEST_MAIN_WINDOW (parent_win));
4808 #ifdef MODEST_TOOLKIT_HILDON2
4809 } else if (MODEST_IS_FOLDER_WINDOW (parent_win)) {
4810 modest_ui_actions_on_folder_window_move_to (folder_view,
4813 GTK_WINDOW (parent_win));
4816 /* Moving from headers window in edit mode */
4817 modest_ui_actions_on_window_move_to (NULL, helper->list,
4819 MODEST_WINDOW (parent_win));
4823 g_object_unref (dst_folder);
4827 g_warning ("%s unexpected response id %d", __FUNCTION__, response);
4830 /* Free the helper and exit */
4831 g_object_unref (helper->list);
4832 g_slice_free (MoveToInfo, helper);
4833 gtk_widget_destroy (GTK_WIDGET (dialog));
4837 create_move_to_dialog (GtkWindow *win,
4838 GtkWidget *folder_view)
4840 GtkWidget *dialog, *tree_view = NULL;
4842 dialog = modest_platform_create_move_to_dialog (win, &tree_view);
4844 #ifndef MODEST_TOOLKIT_HILDON2
4845 /* Track changes in the selection to
4846 * disable the OK button whenever "Move to" is not possible
4847 * disbale NEW button whenever New is not possible */
4848 g_signal_connect (tree_view,
4849 "folder_selection_changed",
4850 G_CALLBACK (on_move_to_dialog_folder_selection_changed),
4854 /* It could happen that we're trying to move a message from a
4855 window (msg window for example) after the main window was
4856 closed, so we can not just get the model of the folder
4858 if (MODEST_IS_FOLDER_VIEW (folder_view)) {
4859 const gchar *visible_id = NULL;
4861 modest_folder_view_set_style (MODEST_FOLDER_VIEW (tree_view),
4862 MODEST_FOLDER_VIEW_STYLE_SHOW_ALL);
4863 modest_folder_view_copy_model (MODEST_FOLDER_VIEW(folder_view),
4864 MODEST_FOLDER_VIEW(tree_view));
4867 modest_folder_view_get_account_id_of_visible_server_account (MODEST_FOLDER_VIEW(folder_view));
4869 /* Show the same account than the one that is shown in the main window */
4870 modest_folder_view_set_account_id_of_visible_server_account (MODEST_FOLDER_VIEW(tree_view),
4873 const gchar *active_account_name = NULL;
4874 ModestAccountMgr *mgr = NULL;
4875 ModestAccountSettings *settings = NULL;
4876 ModestServerAccountSettings *store_settings = NULL;
4878 modest_folder_view_set_style (MODEST_FOLDER_VIEW (tree_view),
4879 MODEST_FOLDER_VIEW_STYLE_SHOW_ALL);
4880 modest_folder_view_update_model (MODEST_FOLDER_VIEW (tree_view),
4881 TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()));
4883 active_account_name = modest_window_get_active_account (MODEST_WINDOW (win));
4884 mgr = modest_runtime_get_account_mgr ();
4885 settings = modest_account_mgr_load_account_settings (mgr, active_account_name);
4888 const gchar *store_account_name;
4889 store_settings = modest_account_settings_get_store_settings (settings);
4890 store_account_name = modest_server_account_settings_get_account_name (store_settings);
4892 modest_folder_view_set_account_id_of_visible_server_account (MODEST_FOLDER_VIEW (tree_view),
4893 store_account_name);
4894 g_object_unref (store_settings);
4895 g_object_unref (settings);
4899 /* we keep a pointer to the embedded folder view, so we can
4900 * retrieve it with get_folder_view_from_move_to_dialog (see
4901 * above) later (needed for focus handling)
4903 g_object_set_data (G_OBJECT(dialog), MODEST_MOVE_TO_DIALOG_FOLDER_VIEW, tree_view);
4905 /* Hide special folders */
4906 modest_folder_view_show_non_move_folders (MODEST_FOLDER_VIEW (tree_view), FALSE);
4907 #ifndef MODEST_TOOLKIT_HILDON2
4908 modest_folder_view_select_first_inbox_or_local (MODEST_FOLDER_VIEW (tree_view));
4911 gtk_widget_show (GTK_WIDGET (tree_view));
4917 * Shows a confirmation dialog to the user when we're moving messages
4918 * from a remote server to the local storage. Returns the dialog
4919 * response. If it's other kind of movement then it always returns
4922 * This one is used by the next functions:
4923 * modest_ui_actions_on_paste - commented out
4924 * drag_and_drop_from_header_view (for d&d in modest_folder_view.c)
4927 modest_ui_actions_msgs_move_to_confirmation (ModestWindow *win,
4928 TnyFolder *dest_folder,
4932 gint response = GTK_RESPONSE_OK;
4933 TnyAccount *account = NULL;
4934 TnyFolder *src_folder = NULL;
4935 TnyIterator *iter = NULL;
4936 TnyHeader *header = NULL;
4938 /* return with OK if the destination is a remote folder */
4939 if (modest_tny_folder_is_remote_folder (dest_folder))
4940 return GTK_RESPONSE_OK;
4942 /* Get source folder */
4943 iter = tny_list_create_iterator (headers);
4944 header = TNY_HEADER (tny_iterator_get_current (iter));
4946 src_folder = tny_header_get_folder (header);
4947 g_object_unref (header);
4949 g_object_unref (iter);
4951 /* if no src_folder, message may be an attahcment */
4952 if (src_folder == NULL)
4953 return GTK_RESPONSE_CANCEL;
4955 /* If the source is a local or MMC folder */
4956 if (!modest_tny_folder_is_remote_folder (src_folder)) {
4957 g_object_unref (src_folder);
4958 return GTK_RESPONSE_OK;
4961 /* Get the account */
4962 account = tny_folder_get_account (src_folder);
4964 /* now if offline we ask the user */
4965 if(connect_to_get_msg (win, tny_list_get_length (headers), account))
4966 response = GTK_RESPONSE_OK;
4968 response = GTK_RESPONSE_CANCEL;
4971 g_object_unref (src_folder);
4972 g_object_unref (account);
4978 move_to_helper_destroyer (gpointer user_data)
4980 MoveToHelper *helper = (MoveToHelper *) user_data;
4982 /* Close the "Pasting" information banner */
4983 if (helper->banner) {
4984 gtk_widget_destroy (GTK_WIDGET (helper->banner));
4985 g_object_unref (helper->banner);
4987 if (gtk_tree_row_reference_valid (helper->reference)) {
4988 gtk_tree_row_reference_free (helper->reference);
4989 helper->reference = NULL;
4995 move_to_cb (ModestMailOperation *mail_op,
4998 MoveToHelper *helper = (MoveToHelper *) user_data;
5000 /* Note that the operation could have failed, in that case do
5002 if (modest_mail_operation_get_status (mail_op) ==
5003 MODEST_MAIL_OPERATION_STATUS_SUCCESS) {
5005 GObject *object = modest_mail_operation_get_source (mail_op);
5006 if (MODEST_IS_MSG_VIEW_WINDOW (object)) {
5007 ModestMsgViewWindow *self = MODEST_MSG_VIEW_WINDOW (object);
5009 if (!modest_msg_view_window_select_next_message (self) &&
5010 !modest_msg_view_window_select_previous_message (self)) {
5011 /* No more messages to view, so close this window */
5012 modest_ui_actions_on_close_window (NULL, MODEST_WINDOW(self));
5014 } else if (MODEST_IS_MAIN_WINDOW (object) &&
5015 gtk_tree_row_reference_valid (helper->reference)) {
5016 GtkWidget *header_view;
5018 GtkTreeSelection *sel;
5020 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(object),
5021 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
5022 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
5023 path = gtk_tree_row_reference_get_path (helper->reference);
5024 /* We need to unselect the previous one
5025 because we could be copying instead of
5027 gtk_tree_selection_unselect_all (sel);
5028 gtk_tree_selection_select_path (sel, path);
5029 gtk_tree_path_free (path);
5031 g_object_unref (object);
5033 /* Destroy the helper */
5034 move_to_helper_destroyer (helper);
5038 folder_move_to_cb (ModestMailOperation *mail_op,
5039 TnyFolder *new_folder,
5042 GtkWidget *folder_view;
5045 object = modest_mail_operation_get_source (mail_op);
5046 if (MODEST_IS_MAIN_WINDOW (object)) {
5047 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(object),
5048 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
5049 g_object_ref (folder_view);
5050 g_object_unref (object);
5051 move_to_cb (mail_op, user_data);
5052 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view), new_folder, FALSE);
5053 g_object_unref (folder_view);
5055 move_to_cb (mail_op, user_data);
5060 msgs_move_to_cb (ModestMailOperation *mail_op,
5063 move_to_cb (mail_op, user_data);
5067 modest_ui_actions_move_folder_error_handler (ModestMailOperation *mail_op,
5070 ModestWindow *main_window = NULL;
5072 /* Disable next automatic folder selection */
5073 main_window = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (),
5074 FALSE); /* don't create */
5076 GObject *win = NULL;
5077 GtkWidget *folder_view = NULL;
5079 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (main_window),
5080 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
5081 modest_folder_view_disable_next_folder_selection (MODEST_FOLDER_VIEW(folder_view));
5083 if (user_data && TNY_IS_FOLDER (user_data)) {
5084 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view),
5085 TNY_FOLDER (user_data), FALSE);
5088 /* Show notification dialog only if the main window exists */
5089 win = modest_mail_operation_get_source (mail_op);
5090 modest_platform_run_information_dialog ((GtkWindow *) win,
5091 _("mail_in_ui_folder_move_target_error"),
5094 g_object_unref (win);
5099 open_msg_for_purge_cb (ModestMailOperation *mail_op,
5108 gint pending_purges = 0;
5109 gboolean some_purged = FALSE;
5110 ModestWindow *win = MODEST_WINDOW (user_data);
5111 ModestWindowMgr *mgr = modest_runtime_get_window_mgr ();
5113 /* If there was any error */
5114 if (!modest_ui_actions_msg_retrieval_check (mail_op, header, msg)) {
5115 modest_window_mgr_unregister_header (mgr, header);
5119 /* Once the message has been retrieved for purging, we check if
5120 * it's all ok for purging */
5122 parts = tny_simple_list_new ();
5123 tny_mime_part_get_parts (TNY_MIME_PART (msg), parts);
5124 iter = tny_list_create_iterator (parts);
5126 while (!tny_iterator_is_done (iter)) {
5128 part = TNY_MIME_PART (tny_iterator_get_current (iter));
5129 if (part && (tny_mime_part_is_attachment (part) || TNY_IS_MSG (part))) {
5130 if (tny_mime_part_is_purged (part))
5137 g_object_unref (part);
5139 tny_iterator_next (iter);
5141 g_object_unref (iter);
5144 if (pending_purges>0) {
5146 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),_("mcen_nc_purge_file_text_inbox"));
5148 if (response == GTK_RESPONSE_OK) {
5151 modest_platform_animation_banner (GTK_WIDGET (win), NULL, _("mcen_me_inbox_remove_attachments"));
5152 iter = tny_list_create_iterator (parts);
5153 while (!tny_iterator_is_done (iter)) {
5156 part = TNY_MIME_PART (tny_iterator_get_current (iter));
5157 if (part && (tny_mime_part_is_attachment (part) || TNY_IS_MSG (part)))
5158 tny_mime_part_set_purged (part);
5161 g_object_unref (part);
5163 tny_iterator_next (iter);
5165 g_object_unref (iter);
5167 tny_msg_rewrite_cache (msg);
5169 gtk_widget_destroy (info);
5173 modest_window_mgr_unregister_header (mgr, header);
5175 g_object_unref (parts);
5179 modest_ui_actions_on_main_window_remove_attachments (GtkAction *action,
5180 ModestMainWindow *win)
5182 GtkWidget *header_view;
5183 TnyList *header_list;
5185 TnyHeaderFlags flags;
5186 ModestWindow *msg_view_window = NULL;
5189 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win));
5191 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
5192 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
5194 header_list = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW (header_view));
5196 g_warning ("%s: no header selected", __FUNCTION__);
5200 if (tny_list_get_length (header_list) == 1) {
5201 TnyIterator *iter = tny_list_create_iterator (header_list);
5202 header = TNY_HEADER (tny_iterator_get_current (iter));
5203 g_object_unref (iter);
5207 if (!header || !TNY_IS_HEADER(header)) {
5208 g_warning ("%s: header is not valid", __FUNCTION__);
5212 found = modest_window_mgr_find_registered_header (modest_runtime_get_window_mgr (),
5213 header, &msg_view_window);
5214 flags = tny_header_get_flags (header);
5215 if (!(flags & TNY_HEADER_FLAG_CACHED))
5218 if (msg_view_window != NULL)
5219 modest_msg_view_window_remove_attachments (MODEST_MSG_VIEW_WINDOW (msg_view_window), TRUE);
5221 /* do nothing; uid was registered before, so window is probably on it's way */
5222 g_warning ("debug: header %p has already been registered", header);
5225 ModestMailOperation *mail_op = NULL;
5226 modest_window_mgr_register_header (modest_runtime_get_window_mgr (), header, NULL);
5227 mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT (win),
5228 modest_ui_actions_disk_operations_error_handler,
5230 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
5231 modest_mail_operation_get_msg (mail_op, header, FALSE, open_msg_for_purge_cb, win);
5233 g_object_unref (mail_op);
5236 g_object_unref (header);
5238 g_object_unref (header_list);
5242 * Checks if we need a connection to do the transfer and if the user
5243 * wants to connect to complete it
5246 modest_ui_actions_xfer_messages_check (GtkWindow *parent_window,
5247 TnyFolderStore *src_folder,
5249 TnyFolder *dst_folder,
5250 gboolean delete_originals,
5251 gboolean *need_connection,
5254 TnyAccount *src_account;
5255 gint uncached_msgs = 0;
5257 uncached_msgs = header_list_count_uncached_msgs (headers);
5259 /* We don't need any further check if
5261 * 1- the source folder is local OR
5262 * 2- the device is already online
5264 if (!modest_tny_folder_store_is_remote (src_folder) ||
5265 tny_device_is_online (modest_runtime_get_device())) {
5266 *need_connection = FALSE;
5271 /* We must ask for a connection when
5273 * - the message(s) is not already cached OR
5274 * - the message(s) is cached but the leave_on_server setting
5275 * is FALSE (because we need to sync the source folder to
5276 * delete the message from the server (for IMAP we could do it
5277 * offline, it'll take place the next time we get a
5280 src_account = get_account_from_folder_store (src_folder);
5281 if (uncached_msgs > 0) {
5285 *need_connection = TRUE;
5286 num_headers = tny_list_get_length (headers);
5287 msg = ngettext ("mcen_nc_get_msg", "mcen_nc_get_msgs", num_headers);
5289 if (modest_platform_run_confirmation_dialog (parent_window, msg) ==
5290 GTK_RESPONSE_CANCEL) {
5296 /* The transfer is possible and the user wants to */
5299 if (remote_folder_has_leave_on_server (src_folder) && delete_originals) {
5300 const gchar *account_name;
5301 gboolean leave_on_server;
5303 account_name = modest_tny_account_get_parent_modest_account_name_for_server_account (src_account);
5304 leave_on_server = modest_account_mgr_get_leave_on_server (modest_runtime_get_account_mgr (),
5307 if (leave_on_server == TRUE) {
5308 *need_connection = FALSE;
5310 *need_connection = TRUE;
5313 *need_connection = FALSE;
5318 g_object_unref (src_account);
5322 xfer_messages_error_handler (ModestMailOperation *mail_op,
5325 ModestWindow *main_window = NULL;
5327 /* Disable next automatic folder selection */
5328 main_window = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (),
5329 FALSE); /* don't create */
5331 GObject *win = modest_mail_operation_get_source (mail_op);
5332 modest_platform_run_information_dialog ((GtkWindow *) win,
5333 _("mail_in_ui_folder_move_target_error"),
5336 g_object_unref (win);
5338 move_to_helper_destroyer (user_data);
5342 TnyFolderStore *dst_folder;
5347 * Utility function that transfer messages from both the main window
5348 * and the msg view window when using the "Move to" dialog
5351 xfer_messages_performer (gboolean canceled,
5353 GtkWindow *parent_window,
5354 TnyAccount *account,
5357 ModestWindow *win = MODEST_WINDOW (parent_window);
5358 TnyAccount *dst_account = NULL;
5359 gboolean dst_forbids_message_add = FALSE;
5360 XferMsgsHelper *helper;
5361 MoveToHelper *movehelper;
5362 ModestMailOperation *mail_op;
5364 helper = (XferMsgsHelper *) user_data;
5366 if (canceled || err) {
5367 if (!check_memory_full_error ((GtkWidget *) parent_window, err)) {
5368 /* Show the proper error message */
5369 modest_ui_actions_on_account_connection_error (parent_window, account);
5374 dst_account = tny_folder_get_account (TNY_FOLDER (helper->dst_folder));
5376 /* tinymail will return NULL for local folders it seems */
5377 dst_forbids_message_add = modest_protocol_registry_protocol_type_has_tag (modest_runtime_get_protocol_registry (),
5378 modest_tny_account_get_protocol_type (dst_account),
5379 MODEST_PROTOCOL_REGISTRY_STORE_FORBID_MESSAGE_ADD);
5380 g_object_unref (dst_account);
5382 if (dst_forbids_message_add) {
5383 modest_platform_information_banner (GTK_WIDGET (win),
5385 ngettext("mail_in_ui_folder_move_target_error",
5386 "mail_in_ui_folder_move_targets_error",
5387 tny_list_get_length (helper->headers)));
5391 movehelper = g_new0 (MoveToHelper, 1);
5392 movehelper->banner = modest_platform_animation_banner (GTK_WIDGET (win), NULL,
5393 _CS("ckct_nw_pasting"));
5394 if (movehelper->banner != NULL) {
5395 g_object_ref (movehelper->banner);
5396 gtk_widget_show (GTK_WIDGET (movehelper->banner));
5399 if (MODEST_IS_MAIN_WINDOW (win)) {
5400 GtkWidget *header_view =
5401 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
5402 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
5403 movehelper->reference = get_next_after_selected_headers (MODEST_HEADER_VIEW (header_view));
5406 /* Perform the mail operation */
5407 mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT(win),
5408 xfer_messages_error_handler,
5410 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
5413 modest_mail_operation_xfer_msgs (mail_op,
5415 TNY_FOLDER (helper->dst_folder),
5420 g_object_unref (G_OBJECT (mail_op));
5422 g_object_unref (helper->dst_folder);
5423 g_object_unref (helper->headers);
5424 g_slice_free (XferMsgsHelper, helper);
5428 TnyFolder *src_folder;
5429 TnyFolderStore *dst_folder;
5430 gboolean delete_original;
5431 GtkWidget *folder_view;
5435 on_move_folder_cb (gboolean canceled, GError *err, GtkWindow *parent_window,
5436 TnyAccount *account, gpointer user_data)
5438 MoveFolderInfo *info = (MoveFolderInfo*)user_data;
5439 GtkTreeSelection *sel;
5440 ModestMailOperation *mail_op = NULL;
5442 if (canceled || err || !MODEST_IS_WINDOW (parent_window)) {
5443 g_object_unref (G_OBJECT (info->src_folder));
5444 g_object_unref (G_OBJECT (info->dst_folder));
5449 MoveToHelper *helper = g_new0 (MoveToHelper, 1);
5450 helper->banner = modest_platform_animation_banner (GTK_WIDGET (parent_window), NULL,
5451 _CS("ckct_nw_pasting"));
5452 if (helper->banner != NULL) {
5453 g_object_ref (helper->banner);
5454 gtk_widget_show (GTK_WIDGET(helper->banner));
5456 /* Clean folder on header view before moving it */
5457 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (info->folder_view));
5458 gtk_tree_selection_unselect_all (sel);
5460 /* Let gtk events run. We need that the folder
5461 view frees its reference to the source
5462 folder *before* issuing the mail operation
5463 so we need the signal handler of selection
5464 changed to happen before the mail
5466 while (gtk_events_pending ())
5467 gtk_main_iteration (); */
5470 modest_mail_operation_new_with_error_handling (G_OBJECT(parent_window),
5471 modest_ui_actions_move_folder_error_handler,
5472 info->src_folder, NULL);
5473 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
5476 /* Select *after* the changes */
5477 /* TODO: this function hangs UI after transfer */
5478 /* modest_folder_view_select_folder (MODEST_FOLDER_VIEW(folder_view), */
5479 /* TNY_FOLDER (src_folder), TRUE); */
5481 if (MODEST_IS_MAIN_WINDOW (parent_window)) {
5482 modest_folder_view_select_folder (MODEST_FOLDER_VIEW(info->folder_view),
5483 TNY_FOLDER (info->dst_folder), TRUE);
5485 modest_mail_operation_xfer_folder (mail_op,
5486 TNY_FOLDER (info->src_folder),
5488 info->delete_original,
5491 g_object_unref (G_OBJECT (info->src_folder));
5493 /* if (modest_mail_operation_get_status (mail_op) == MODEST_MAIL_OPERATION_STATUS_SUCCESS) { */
5496 /* Unref mail operation */
5497 g_object_unref (G_OBJECT (mail_op));
5498 g_object_unref (G_OBJECT (info->dst_folder));
5503 get_account_from_folder_store (TnyFolderStore *folder_store)
5505 if (TNY_IS_ACCOUNT (folder_store))
5506 return g_object_ref (folder_store);
5508 return tny_folder_get_account (TNY_FOLDER (folder_store));
5512 * UI handler for the "Move to" action when invoked from the
5516 modest_ui_actions_on_main_window_move_to (GtkAction *action,
5517 GtkWidget *folder_view,
5518 TnyFolderStore *dst_folder,
5519 ModestMainWindow *win)
5521 ModestHeaderView *header_view = NULL;
5522 TnyFolderStore *src_folder = NULL;
5524 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win));
5526 /* Get the source folder */
5527 src_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
5529 /* Get header view */
5530 header_view = (ModestHeaderView *)
5531 modest_main_window_get_child_widget (win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
5533 /* Get folder or messages to transfer */
5534 if (gtk_widget_is_focus (folder_view)) {
5535 gboolean do_xfer = TRUE;
5537 /* Allow only to transfer folders to the local root folder */
5538 if (TNY_IS_ACCOUNT (dst_folder) &&
5539 !MODEST_IS_TNY_LOCAL_FOLDERS_ACCOUNT (dst_folder) &&
5540 !modest_tny_account_is_memory_card_account (TNY_ACCOUNT (dst_folder))) {
5542 } else if (!TNY_IS_FOLDER (src_folder)) {
5543 g_warning ("%s: src_folder is not a TnyFolder.\n", __FUNCTION__);
5548 MoveFolderInfo *info = g_new0 (MoveFolderInfo, 1);
5549 DoubleConnectionInfo *connect_info = g_slice_new (DoubleConnectionInfo);
5551 info->src_folder = g_object_ref (src_folder);
5552 info->dst_folder = g_object_ref (dst_folder);
5553 info->delete_original = TRUE;
5554 info->folder_view = folder_view;
5556 connect_info->callback = on_move_folder_cb;
5557 connect_info->dst_account = get_account_from_folder_store (TNY_FOLDER_STORE (dst_folder));
5558 connect_info->data = info;
5560 modest_platform_double_connect_and_perform(GTK_WINDOW (win), TRUE,
5561 TNY_FOLDER_STORE (src_folder),
5564 } else if (gtk_widget_is_focus (GTK_WIDGET(header_view))) {
5567 headers = modest_header_view_get_selected_headers(header_view);
5569 /* Transfer the messages */
5570 modest_ui_actions_transfer_messages_helper (GTK_WINDOW (win), TNY_FOLDER (src_folder),
5571 headers, TNY_FOLDER (dst_folder));
5573 g_object_unref (headers);
5577 g_object_unref (src_folder);
5580 #ifdef MODEST_TOOLKIT_HILDON2
5582 * UI handler for the "Move to" action when invoked from the
5583 * ModestFolderWindow
5586 modest_ui_actions_on_folder_window_move_to (GtkWidget *folder_view,
5587 TnyFolderStore *dst_folder,
5591 TnyFolderStore *src_folder = NULL;
5592 TnyIterator *iterator;
5594 if (tny_list_get_length (selection) != 1)
5597 iterator = tny_list_create_iterator (selection);
5598 src_folder = TNY_FOLDER_STORE (tny_iterator_get_current (iterator));
5599 g_object_unref (iterator);
5602 gboolean do_xfer = TRUE;
5604 /* Allow only to transfer folders to the local root folder */
5605 if (TNY_IS_ACCOUNT (dst_folder) &&
5606 !MODEST_IS_TNY_LOCAL_FOLDERS_ACCOUNT (dst_folder) &&
5607 !modest_tny_account_is_memory_card_account (TNY_ACCOUNT (dst_folder))) {
5609 } else if (!TNY_IS_FOLDER (src_folder)) {
5610 g_warning ("%s: src_folder is not a TnyFolder.\n", __FUNCTION__);
5615 MoveFolderInfo *info = g_new0 (MoveFolderInfo, 1);
5616 DoubleConnectionInfo *connect_info = g_slice_new (DoubleConnectionInfo);
5618 info->src_folder = g_object_ref (src_folder);
5619 info->dst_folder = g_object_ref (dst_folder);
5620 info->delete_original = TRUE;
5621 info->folder_view = folder_view;
5623 connect_info->callback = on_move_folder_cb;
5624 connect_info->dst_account = get_account_from_folder_store (TNY_FOLDER_STORE (dst_folder));
5625 connect_info->data = info;
5627 modest_platform_double_connect_and_perform(GTK_WINDOW (win), TRUE,
5628 TNY_FOLDER_STORE (src_folder),
5632 g_object_unref (src_folder);
5638 modest_ui_actions_transfer_messages_helper (GtkWindow *win,
5639 TnyFolder *src_folder,
5641 TnyFolder *dst_folder)
5643 gboolean need_connection = TRUE;
5644 gboolean do_xfer = TRUE;
5645 XferMsgsHelper *helper;
5647 g_return_if_fail (TNY_IS_FOLDER (src_folder));
5648 g_return_if_fail (TNY_IS_FOLDER (dst_folder));
5649 g_return_if_fail (TNY_IS_LIST (headers));
5651 modest_ui_actions_xfer_messages_check (win, TNY_FOLDER_STORE (src_folder),
5652 headers, TNY_FOLDER (dst_folder),
5653 TRUE, &need_connection,
5656 /* If we don't want to transfer just return */
5660 /* Create the helper */
5661 helper = g_slice_new (XferMsgsHelper);
5662 helper->dst_folder = g_object_ref (dst_folder);
5663 helper->headers = g_object_ref (headers);
5665 if (need_connection) {
5666 DoubleConnectionInfo *connect_info = g_slice_new (DoubleConnectionInfo);
5667 connect_info->callback = xfer_messages_performer;
5668 connect_info->dst_account = tny_folder_get_account (TNY_FOLDER (dst_folder));
5669 connect_info->data = helper;
5671 modest_platform_double_connect_and_perform(GTK_WINDOW (win), TRUE,
5672 TNY_FOLDER_STORE (src_folder),
5675 TnyAccount *src_account = get_account_from_folder_store (TNY_FOLDER_STORE (src_folder));
5676 xfer_messages_performer (FALSE, NULL, GTK_WINDOW (win),
5677 src_account, helper);
5678 g_object_unref (src_account);
5683 * UI handler for the "Move to" action when invoked from the
5684 * ModestMsgViewWindow
5687 modest_ui_actions_on_window_move_to (GtkAction *action,
5689 TnyFolderStore *dst_folder,
5692 TnyFolder *src_folder = NULL;
5694 g_return_if_fail (TNY_IS_FOLDER (dst_folder));
5697 TnyHeader *header = NULL;
5700 iter = tny_list_create_iterator (headers);
5701 header = (TnyHeader *) tny_iterator_get_current (iter);
5702 src_folder = tny_header_get_folder (header);
5704 /* Transfer the messages */
5705 modest_ui_actions_transfer_messages_helper (GTK_WINDOW (win), src_folder,
5707 TNY_FOLDER (dst_folder));
5710 g_object_unref (header);
5711 g_object_unref (iter);
5712 g_object_unref (src_folder);
5717 modest_ui_actions_on_move_to (GtkAction *action,
5720 modest_ui_actions_on_edit_mode_move_to (win);
5724 modest_ui_actions_on_edit_mode_move_to (ModestWindow *win)
5726 GtkWidget *dialog = NULL, *folder_view = NULL;
5727 ModestMainWindow *main_window;
5728 MoveToInfo *helper = NULL;
5730 g_return_val_if_fail (MODEST_IS_WINDOW (win), FALSE);
5732 /* Get the main window if exists */
5733 if (MODEST_IS_MAIN_WINDOW (win))
5734 main_window = MODEST_MAIN_WINDOW (win);
5737 MODEST_MAIN_WINDOW (modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (),
5738 FALSE)); /* don't create */
5740 /* Get the folder view widget if exists */
5742 folder_view = modest_main_window_get_child_widget (main_window,
5743 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
5747 /* Create and run the dialog */
5748 dialog = create_move_to_dialog (GTK_WINDOW (win), folder_view);
5749 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (),
5750 GTK_WINDOW (dialog),
5754 helper = g_slice_new0 (MoveToInfo);
5755 helper->list = modest_platform_get_list_to_move (MODEST_WINDOW (win));
5758 /* Listen to response signal */
5759 g_signal_connect (dialog, "response", G_CALLBACK (on_move_to_dialog_response), helper);
5761 /* Show the dialog */
5762 gtk_widget_show (dialog);
5768 * Calls #HeadersFunc for each header already selected in the main
5769 * window or the message currently being shown in the msg view window
5772 do_headers_action (ModestWindow *win,
5776 TnyList *headers_list = NULL;
5777 TnyIterator *iter = NULL;
5778 TnyHeader *header = NULL;
5779 TnyFolder *folder = NULL;
5782 headers_list = get_selected_headers (win);
5786 /* Get the folder */
5787 iter = tny_list_create_iterator (headers_list);
5788 header = TNY_HEADER (tny_iterator_get_current (iter));
5790 folder = tny_header_get_folder (header);
5791 g_object_unref (header);
5794 /* Call the function for each header */
5795 while (!tny_iterator_is_done (iter)) {
5796 header = TNY_HEADER (tny_iterator_get_current (iter));
5797 func (header, win, user_data);
5798 g_object_unref (header);
5799 tny_iterator_next (iter);
5802 /* Trick: do a poke status in order to speed up the signaling
5804 tny_folder_poke_status (folder);
5807 g_object_unref (folder);
5808 g_object_unref (iter);
5809 g_object_unref (headers_list);
5813 modest_ui_actions_view_attachment (GtkAction *action,
5814 ModestWindow *window)
5816 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
5817 modest_msg_view_window_view_attachment (MODEST_MSG_VIEW_WINDOW (window), NULL);
5819 /* not supported window for this action */
5820 g_return_if_reached ();
5825 modest_ui_actions_save_attachments (GtkAction *action,
5826 ModestWindow *window)
5828 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
5830 if (modest_platform_check_memory_low (MODEST_WINDOW(window), TRUE))
5833 modest_msg_view_window_save_attachments (MODEST_MSG_VIEW_WINDOW (window), NULL);
5835 /* not supported window for this action */
5836 g_return_if_reached ();
5841 modest_ui_actions_remove_attachments (GtkAction *action,
5842 ModestWindow *window)
5844 if (MODEST_IS_MAIN_WINDOW (window)) {
5845 modest_ui_actions_on_main_window_remove_attachments (action, MODEST_MAIN_WINDOW (window));
5846 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
5847 modest_msg_view_window_remove_attachments (MODEST_MSG_VIEW_WINDOW (window), FALSE);
5849 /* not supported window for this action */
5850 g_return_if_reached ();
5855 modest_ui_actions_on_settings (GtkAction *action,
5860 dialog = modest_platform_get_global_settings_dialog ();
5861 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (win));
5862 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
5863 gtk_widget_show_all (dialog);
5865 gtk_dialog_run (GTK_DIALOG (dialog));
5867 gtk_widget_destroy (dialog);
5871 modest_ui_actions_on_help (GtkAction *action,
5874 /* Help app is not available at all in fremantle */
5875 #ifndef MODEST_TOOLKIT_HILDON2
5876 const gchar *help_id;
5878 g_return_if_fail (win && GTK_IS_WINDOW(win));
5880 help_id = modest_window_mgr_get_help_id (modest_runtime_get_window_mgr(), win);
5883 modest_platform_show_help (GTK_WINDOW (win), help_id);
5888 modest_ui_actions_on_csm_help (GtkAction *action,
5891 /* Help app is not available at all in fremantle */
5892 #ifndef MODEST_TOOLKIT_HILDON2
5894 const gchar* help_id = NULL;
5895 GtkWidget *folder_view;
5896 TnyFolderStore *folder_store;
5898 g_return_if_fail (win && MODEST_IS_MAIN_WINDOW (win));
5900 /* Get selected folder */
5901 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
5902 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
5903 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
5905 /* Switch help_id */
5906 if (folder_store && TNY_IS_FOLDER (folder_store))
5907 help_id = modest_tny_folder_get_help_id (TNY_FOLDER (folder_store));
5910 g_object_unref (folder_store);
5913 modest_platform_show_help (GTK_WINDOW (win), help_id);
5915 modest_ui_actions_on_help (action, win);
5920 retrieve_contents_cb (ModestMailOperation *mail_op,
5927 /* We only need this callback to show an error in case of
5928 memory low condition */
5929 modest_ui_actions_msg_retrieval_check (mail_op, header, msg);
5933 retrieve_msg_contents_performer (gboolean canceled,
5935 GtkWindow *parent_window,
5936 TnyAccount *account,
5939 ModestMailOperation *mail_op;
5940 TnyList *headers = TNY_LIST (user_data);
5942 if (err || canceled) {
5943 check_memory_full_error ((GtkWidget *) parent_window, err);
5947 /* Create mail operation */
5948 mail_op = modest_mail_operation_new_with_error_handling ((GObject *) parent_window,
5949 modest_ui_actions_disk_operations_error_handler,
5951 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
5952 modest_mail_operation_get_msgs_full (mail_op, headers, retrieve_contents_cb, NULL, NULL);
5955 g_object_unref (mail_op);
5957 g_object_unref (headers);
5958 g_object_unref (account);
5962 modest_ui_actions_on_retrieve_msg_contents (GtkAction *action,
5963 ModestWindow *window)
5965 TnyList *headers = NULL;
5966 TnyAccount *account = NULL;
5967 TnyIterator *iter = NULL;
5968 TnyHeader *header = NULL;
5969 TnyFolder *folder = NULL;
5972 headers = get_selected_headers (window);
5976 /* Pick the account */
5977 iter = tny_list_create_iterator (headers);
5978 header = TNY_HEADER (tny_iterator_get_current (iter));
5979 folder = tny_header_get_folder (header);
5980 account = tny_folder_get_account (folder);
5981 g_object_unref (folder);
5982 g_object_unref (header);
5983 g_object_unref (iter);
5985 /* Connect and perform the message retrieval */
5986 modest_platform_connect_and_perform ((GtkWindow *) window, TRUE,
5987 g_object_ref (account),
5988 retrieve_msg_contents_performer,
5989 g_object_ref (headers));
5992 g_object_unref (account);
5993 g_object_unref (headers);
5997 modest_ui_actions_check_toolbar_dimming_rules (ModestWindow *window)
5999 g_return_if_fail (MODEST_IS_WINDOW (window));
6002 modest_window_check_dimming_rules_group (window, MODEST_DIMMING_RULES_TOOLBAR);
6006 modest_ui_actions_check_menu_dimming_rules (ModestWindow *window)
6008 g_return_if_fail (MODEST_IS_WINDOW (window));
6011 modest_window_check_dimming_rules_group (window, MODEST_DIMMING_RULES_MENU);
6015 modest_ui_actions_on_email_menu_activated (GtkAction *action,
6016 ModestWindow *window)
6018 g_return_if_fail (MODEST_IS_WINDOW (window));
6021 modest_ui_actions_check_menu_dimming_rules (window);
6025 modest_ui_actions_on_edit_menu_activated (GtkAction *action,
6026 ModestWindow *window)
6028 g_return_if_fail (MODEST_IS_WINDOW (window));
6031 modest_ui_actions_check_menu_dimming_rules (window);
6035 modest_ui_actions_on_view_menu_activated (GtkAction *action,
6036 ModestWindow *window)
6038 g_return_if_fail (MODEST_IS_WINDOW (window));
6041 modest_ui_actions_check_menu_dimming_rules (window);
6045 modest_ui_actions_on_format_menu_activated (GtkAction *action,
6046 ModestWindow *window)
6048 g_return_if_fail (MODEST_IS_WINDOW (window));
6051 modest_ui_actions_check_menu_dimming_rules (window);
6055 modest_ui_actions_on_tools_menu_activated (GtkAction *action,
6056 ModestWindow *window)
6058 g_return_if_fail (MODEST_IS_WINDOW (window));
6061 modest_ui_actions_check_menu_dimming_rules (window);
6065 modest_ui_actions_on_attachment_menu_activated (GtkAction *action,
6066 ModestWindow *window)
6068 g_return_if_fail (MODEST_IS_WINDOW (window));
6071 modest_ui_actions_check_menu_dimming_rules (window);
6075 modest_ui_actions_on_toolbar_csm_menu_activated (GtkAction *action,
6076 ModestWindow *window)
6078 g_return_if_fail (MODEST_IS_WINDOW (window));
6081 modest_ui_actions_check_menu_dimming_rules (window);
6085 modest_ui_actions_on_folder_view_csm_menu_activated (GtkAction *action,
6086 ModestWindow *window)
6088 g_return_if_fail (MODEST_IS_WINDOW (window));
6091 modest_ui_actions_check_menu_dimming_rules (window);
6095 modest_ui_actions_on_header_view_csm_menu_activated (GtkAction *action,
6096 ModestWindow *window)
6098 g_return_if_fail (MODEST_IS_WINDOW (window));
6101 modest_ui_actions_check_menu_dimming_rules (window);
6105 modest_ui_actions_on_search_messages (GtkAction *action, ModestWindow *window)
6107 g_return_if_fail (MODEST_IS_WINDOW (window));
6109 /* we check for low-mem; in that case, show a warning, and don't allow
6112 if (modest_platform_check_memory_low (window, TRUE))
6115 modest_platform_show_search_messages (GTK_WINDOW (window));
6119 modest_ui_actions_on_open_addressbook (GtkAction *action, ModestWindow *win)
6121 g_return_if_fail (MODEST_IS_WINDOW (win));
6124 /* we check for low-mem; in that case, show a warning, and don't allow
6125 * for the addressbook
6127 if (modest_platform_check_memory_low (win, TRUE))
6131 modest_platform_show_addressbook (GTK_WINDOW (win));
6136 modest_ui_actions_on_toggle_find_in_page (GtkToggleAction *action,
6137 ModestWindow *window)
6139 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
6141 modest_msg_edit_window_toggle_find_toolbar (MODEST_MSG_EDIT_WINDOW (window), gtk_toggle_action_get_active (action));
6145 on_send_receive_finished (ModestMailOperation *mail_op,
6148 GtkWidget *header_view, *folder_view;
6149 TnyFolderStore *folder_store;
6150 ModestMainWindow *main_win = MODEST_MAIN_WINDOW (user_data);
6152 /* Set send/receive operation finished */
6153 modest_main_window_notify_send_receive_completed (main_win);
6155 /* Don't refresh the current folder if there were any errors */
6156 if (modest_mail_operation_get_status (mail_op) !=
6157 MODEST_MAIL_OPERATION_STATUS_SUCCESS)
6160 /* Refresh the current folder if we're viewing a window. We do
6161 this because the user won't be able to see the new mails in
6162 the selected folder after a Send&Receive because it only
6163 performs a poke_status, i.e, only the number of read/unread
6164 messages is updated, but the new headers are not
6166 folder_view = modest_main_window_get_child_widget (main_win,
6167 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
6171 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
6173 /* Do not need to refresh INBOX again because the
6174 update_account does it always automatically */
6175 if (folder_store && TNY_IS_FOLDER (folder_store) &&
6176 tny_folder_get_folder_type (TNY_FOLDER (folder_store)) != TNY_FOLDER_TYPE_INBOX) {
6177 ModestMailOperation *refresh_op;
6179 header_view = modest_main_window_get_child_widget (main_win,
6180 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
6182 /* We do not need to set the contents style
6183 because it hasn't changed. We also do not
6184 need to save the widget status. Just force
6186 refresh_op = modest_mail_operation_new (G_OBJECT (main_win));
6187 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), refresh_op);
6188 modest_mail_operation_refresh_folder (refresh_op, TNY_FOLDER (folder_store),
6189 folder_refreshed_cb, main_win);
6190 g_object_unref (refresh_op);
6194 g_object_unref (folder_store);
6199 modest_ui_actions_on_send_queue_error_happened (TnySendQueue *self,
6205 const gchar* server_name = NULL;
6206 TnyTransportAccount *server_account;
6207 gchar *message = NULL;
6209 /* Don't show anything if the user cancelled something or the
6210 * send receive request is not interactive. Authentication
6211 * errors are managed by the account store so no need to show
6212 * a dialog here again */
6213 if (err->code == TNY_SYSTEM_ERROR_CANCEL ||
6214 err->code == TNY_SERVICE_ERROR_AUTHENTICATE ||
6215 !modest_tny_send_queue_get_requested_send_receive (MODEST_TNY_SEND_QUEUE (self)))
6219 /* Get the server name: */
6221 TNY_TRANSPORT_ACCOUNT (tny_camel_send_queue_get_transport_account (TNY_CAMEL_SEND_QUEUE (self)));
6223 server_name = tny_account_get_hostname (TNY_ACCOUNT (server_account));
6225 g_return_if_reached ();
6227 /* Show the appropriate message text for the GError: */
6228 switch (err->code) {
6229 case TNY_SERVICE_ERROR_CONNECT:
6230 message = g_strdup_printf (_("emev_ib_ui_smtp_server_invalid"), server_name);
6232 case TNY_SERVICE_ERROR_SEND:
6233 message = g_strdup (dgettext("hildon-common-strings", "sfil_ib_unable_to_send"));
6235 case TNY_SERVICE_ERROR_UNAVAILABLE:
6236 message = g_strdup_printf (_("emev_ib_ui_smtp_server_invalid"), server_name);
6239 g_warning ("%s: unexpected ERROR %d",
6240 __FUNCTION__, err->code);
6241 message = g_strdup (dgettext("hildon-common-strings", "sfil_ib_unable_to_send"));
6245 modest_platform_run_information_dialog (NULL, message, FALSE);
6247 g_object_unref (server_account);
6251 modest_ui_actions_on_send_queue_status_changed (ModestTnySendQueue *send_queue,
6256 ModestMainWindow *main_window = NULL;
6257 ModestWindowMgr *mgr = NULL;
6258 GtkWidget *folder_view = NULL, *header_view = NULL;
6259 TnyFolderStore *selected_folder = NULL;
6260 TnyFolderType folder_type;
6262 mgr = modest_runtime_get_window_mgr ();
6263 main_window = MODEST_MAIN_WINDOW (modest_window_mgr_get_main_window (mgr,
6264 FALSE));/* don't create */
6268 /* Check if selected folder is OUTBOX */
6269 folder_view = modest_main_window_get_child_widget (main_window,
6270 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
6271 header_view = modest_main_window_get_child_widget (main_window,
6272 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
6274 selected_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
6275 if (!TNY_IS_FOLDER (selected_folder))
6278 /* gtk_tree_view_column_queue_resize is only available in GTK+ 2.8 */
6279 #if GTK_CHECK_VERSION(2, 8, 0)
6280 folder_type = modest_tny_folder_guess_folder_type (TNY_FOLDER (selected_folder));
6281 if (folder_type == TNY_FOLDER_TYPE_OUTBOX) {
6282 GtkTreeViewColumn *tree_column;
6284 tree_column = gtk_tree_view_get_column (GTK_TREE_VIEW (header_view),
6285 TNY_GTK_HEADER_LIST_MODEL_FROM_COLUMN);
6287 gtk_tree_view_column_queue_resize (tree_column);
6290 gtk_widget_queue_draw (header_view);
6293 /* Rerun dimming rules, because the message could become deletable for example */
6294 modest_window_check_dimming_rules_group (MODEST_WINDOW (main_window),
6295 MODEST_DIMMING_RULES_TOOLBAR);
6296 modest_window_check_dimming_rules_group (MODEST_WINDOW (main_window),
6297 MODEST_DIMMING_RULES_MENU);
6301 if (selected_folder != NULL)
6302 g_object_unref (selected_folder);
6306 modest_ui_actions_on_account_connection_error (GtkWindow *parent_window,
6307 TnyAccount *account)
6309 ModestProtocolType protocol_type;
6310 ModestProtocol *protocol;
6311 gchar *error_note = NULL;
6313 protocol_type = modest_tny_account_get_protocol_type (account);
6314 protocol = modest_protocol_registry_get_protocol_by_type (modest_runtime_get_protocol_registry (),
6317 error_note = modest_protocol_get_translation (protocol, MODEST_PROTOCOL_TRANSLATION_ACCOUNT_CONNECTION_ERROR, tny_account_get_hostname (account));
6318 if (error_note == NULL) {
6319 g_warning ("%s: This should not be reached", __FUNCTION__);
6321 modest_platform_run_information_dialog (parent_window, error_note, FALSE);
6322 g_free (error_note);
6327 modest_ui_actions_get_msg_already_deleted_error_msg (ModestWindow *win)
6331 TnyFolderStore *folder = NULL;
6332 TnyAccount *account = NULL;
6333 ModestProtocolType proto;
6334 ModestProtocol *protocol;
6335 TnyHeader *header = NULL;
6337 if (MODEST_IS_MAIN_WINDOW (win)) {
6338 GtkWidget *header_view;
6339 TnyList* headers = NULL;
6341 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
6342 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
6343 headers = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW (header_view));
6344 if (!headers || tny_list_get_length (headers) == 0) {
6346 g_object_unref (headers);
6349 iter = tny_list_create_iterator (headers);
6350 header = TNY_HEADER (tny_iterator_get_current (iter));
6351 folder = TNY_FOLDER_STORE (tny_header_get_folder (header));
6352 g_object_unref (iter);
6353 g_object_unref (headers);
6354 #ifdef MODEST_TOOLKIT_HILDON2
6355 } else if (MODEST_IS_HEADER_WINDOW (win)) {
6356 GtkWidget *header_view;
6357 TnyList* headers = NULL;
6359 header_view = GTK_WIDGET (modest_header_window_get_header_view (MODEST_HEADER_WINDOW (win)));
6360 headers = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW (header_view));
6361 if (!headers || tny_list_get_length (headers) == 0) {
6363 g_object_unref (headers);
6366 iter = tny_list_create_iterator (headers);
6367 header = TNY_HEADER (tny_iterator_get_current (iter));
6368 folder = TNY_FOLDER_STORE (tny_header_get_folder (header));
6369 g_object_unref (iter);
6370 g_object_unref (headers);
6372 } else if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
6373 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
6374 folder = TNY_FOLDER_STORE (tny_header_get_folder (header));
6377 /* Get the account type */
6378 account = tny_folder_get_account (TNY_FOLDER (folder));
6379 proto = modest_tny_account_get_protocol_type (account);
6380 protocol = modest_protocol_registry_get_protocol_by_type (modest_runtime_get_protocol_registry (),
6383 subject = tny_header_dup_subject (header);
6384 msg = modest_protocol_get_translation (protocol, MODEST_PROTOCOL_TRANSLATION_MSG_NOT_AVAILABLE, subject);
6388 msg = g_strdup_printf (_("mail_ni_ui_folder_get_msg_folder_error"));
6392 g_object_unref (account);
6393 g_object_unref (folder);
6394 g_object_unref (header);
6400 modest_ui_actions_on_delete_account (GtkWindow *parent_window,
6401 const gchar *account_name,
6402 const gchar *account_title)
6404 ModestAccountMgr *account_mgr;
6407 ModestProtocol *protocol;
6408 gboolean removed = FALSE;
6410 g_return_val_if_fail (account_name, FALSE);
6411 g_return_val_if_fail (account_title, FALSE);
6413 account_mgr = modest_runtime_get_account_mgr();
6415 /* The warning text depends on the account type: */
6416 protocol = modest_protocol_registry_get_protocol_by_type (modest_runtime_get_protocol_registry (),
6417 modest_account_mgr_get_store_protocol (account_mgr,
6419 txt = modest_protocol_get_translation (protocol,
6420 MODEST_PROTOCOL_TRANSLATION_DELETE_MAILBOX,
6423 txt = g_strdup_printf (_("emev_nc_delete_mailbox"), account_title);
6425 response = modest_platform_run_confirmation_dialog (parent_window, txt);
6429 if (response == GTK_RESPONSE_OK) {
6430 /* Remove account. If it succeeds then it also removes
6431 the account from the ModestAccountView: */
6432 gboolean is_default = FALSE;
6433 gchar *default_account_name = modest_account_mgr_get_default_account (account_mgr);
6434 if (default_account_name && (strcmp (default_account_name, account_name) == 0))
6436 g_free (default_account_name);
6438 removed = modest_account_mgr_remove_account (account_mgr, account_name);
6440 g_warning ("%s: modest_account_mgr_remove_account() failed.\n", __FUNCTION__);