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>
57 #include <modest-maemo-utils.h>
60 #ifdef MODEST_PLATFORM_MAEMO
61 #include "maemo/modest-osso-state-saving.h"
62 #endif /* MODEST_PLATFORM_MAEMO */
63 #ifndef MODEST_TOOLKIT_GTK
64 #include "maemo/modest-hildon-includes.h"
65 #include "maemo/modest-connection-specific-smtp-window.h"
66 #endif /* !MODEST_TOOLKIT_GTK */
67 #include <modest-utils.h>
69 #include "widgets/modest-ui-constants.h"
70 #include <widgets/modest-main-window.h>
71 #include <widgets/modest-msg-view-window.h>
72 #include <widgets/modest-account-view-window.h>
73 #include <widgets/modest-details-dialog.h>
74 #include <widgets/modest-attachments-view.h>
75 #include "widgets/modest-folder-view.h"
76 #include "widgets/modest-global-settings-dialog.h"
77 #include "modest-account-mgr-helpers.h"
78 #include "modest-mail-operation.h"
79 #include "modest-text-utils.h"
80 #include <modest-widget-memory.h>
81 #include <tny-error.h>
82 #include <tny-simple-list.h>
83 #include <tny-msg-view.h>
84 #include <tny-device.h>
85 #include <tny-merge-folder.h>
87 #include <gtkhtml/gtkhtml.h>
89 #define MIN_FREE_SPACE 5 * 1024 * 1024
90 #define MODEST_MOVE_TO_DIALOG_FOLDER_VIEW "move-to-dialog-folder-view"
92 typedef struct _GetMsgAsyncHelper {
94 ModestMailOperation *mail_op;
101 typedef enum _ReplyForwardAction {
105 } ReplyForwardAction;
107 typedef struct _ReplyForwardHelper {
108 guint reply_forward_type;
109 ReplyForwardAction action;
111 GtkWidget *parent_window;
113 } ReplyForwardHelper;
115 typedef struct _MoveToHelper {
116 GtkTreeRowReference *reference;
120 typedef struct _PasteAsAttachmentHelper {
121 ModestMsgEditWindow *window;
123 } PasteAsAttachmentHelper;
131 * The do_headers_action uses this kind of functions to perform some
132 * action to each member of a list of headers
134 typedef void (*HeadersFunc) (TnyHeader *header, ModestWindow *win, gpointer user_data);
136 static void do_headers_action (ModestWindow *win,
140 static void open_msg_cb (ModestMailOperation *mail_op,
147 static void reply_forward_cb (ModestMailOperation *mail_op,
154 static void reply_forward (ReplyForwardAction action, ModestWindow *win);
156 static void folder_refreshed_cb (ModestMailOperation *mail_op,
160 static void on_send_receive_finished (ModestMailOperation *mail_op,
163 static gint header_list_count_uncached_msgs (TnyList *header_list);
165 static gboolean connect_to_get_msg (ModestWindow *win,
166 gint num_of_uncached_msgs,
167 TnyAccount *account);
169 static gboolean remote_folder_has_leave_on_server (TnyFolderStore *folder);
171 static void do_create_folder (GtkWindow *window,
172 TnyFolderStore *parent_folder,
173 const gchar *suggested_name);
175 static TnyAccount *get_account_from_folder_store (TnyFolderStore *folder_store);
177 static void modest_ui_actions_on_main_window_move_to (GtkAction *action,
178 GtkWidget *folder_view,
179 TnyFolderStore *dst_folder,
180 ModestMainWindow *win);
181 #ifdef MODEST_TOOLKIT_HILDON2
182 static void modest_ui_actions_on_folder_window_move_to (GtkWidget *folder_view,
183 TnyFolderStore *dst_folder,
188 static void modest_ui_actions_on_window_move_to (GtkAction *action,
189 TnyList *list_to_move,
190 TnyFolderStore *dst_folder,
194 * This function checks whether a TnyFolderStore is a pop account
197 remote_folder_has_leave_on_server (TnyFolderStore *folder)
202 g_return_val_if_fail (TNY_IS_FOLDER_STORE (folder), FALSE);
204 account = get_account_from_folder_store (folder);
205 result = (modest_protocol_registry_protocol_type_has_leave_on_server (modest_runtime_get_protocol_registry (),
206 modest_tny_account_get_protocol_type (account)));
207 g_object_unref (account);
212 /* FIXME: this should be merged with the similar code in modest-account-view-window */
213 /* Show the account creation wizard dialog.
214 * returns: TRUE if an account was created. FALSE if the user cancelled.
217 modest_ui_actions_run_account_setup_wizard (ModestWindow *win)
219 gboolean result = FALSE;
221 gint dialog_response;
223 /* there is no such wizard yet */
224 wizard = GTK_WINDOW (modest_platform_get_account_settings_wizard ());
225 modest_window_mgr_set_modal (modest_runtime_get_window_mgr(), GTK_WINDOW (wizard), (GtkWindow *) win);
227 #ifndef MODEST_TOOLKIT_HILDON2
228 /* always present a main window in the background
229 * we do it here, so we cannot end up with two wizards (as this
230 * function might be called in modest_window_mgr_get_main_window as well */
232 win = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr(),
233 TRUE); /* create if not existent */
237 ModestWindowMgr *mgr;
239 mgr = modest_runtime_get_window_mgr ();
241 window_list = modest_window_mgr_get_window_list (mgr);
242 if (window_list == NULL) {
243 ModestWindow *old_win;
244 win = MODEST_WINDOW (modest_accounts_window_new ());
245 if (modest_window_mgr_register_window (mgr, win, NULL)) {
246 gtk_widget_show_all (GTK_WIDGET (win));
248 gtk_widget_destroy (GTK_WIDGET (win));
253 win = MODEST_WINDOW (modest_folder_window_new (NULL));
254 if (modest_window_mgr_register_window (mgr, win, NULL)) {
255 gtk_widget_show_all (GTK_WIDGET (win));
257 gtk_widget_destroy (GTK_WIDGET (win));
261 g_list_free (window_list);
267 gtk_window_set_transient_for (GTK_WINDOW (wizard), GTK_WINDOW (win));
269 /* make sure the mainwindow is visible. We need to present the
270 wizard again to give it the focus back. show_all are needed
271 in order to get the widgets properly drawn (MainWindow main
272 paned won't be in its right position and the dialog will be
274 #ifndef MODEST_TOOLKIT_HILDON2
275 gtk_widget_show_all (GTK_WIDGET (win));
276 gtk_widget_show_all (GTK_WIDGET (wizard));
277 gtk_window_present (GTK_WINDOW (win));
278 gtk_window_present (GTK_WINDOW (wizard));
281 dialog_response = gtk_dialog_run (GTK_DIALOG (wizard));
282 gtk_widget_destroy (GTK_WIDGET (wizard));
283 if (gtk_events_pending ())
284 gtk_main_iteration ();
286 if (dialog_response == GTK_RESPONSE_CANCEL) {
289 /* Check whether an account was created: */
290 result = modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
297 modest_ui_actions_on_about (GtkAction *action, ModestWindow *win)
300 const gchar *authors[] = {
301 "Dirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>",
304 about = gtk_about_dialog_new ();
305 gtk_about_dialog_set_name (GTK_ABOUT_DIALOG(about), PACKAGE_NAME);
306 gtk_about_dialog_set_version (GTK_ABOUT_DIALOG(about),PACKAGE_VERSION);
307 gtk_about_dialog_set_copyright (GTK_ABOUT_DIALOG(about),
308 _("Copyright (c) 2006, Nokia Corporation\n"
309 "All rights reserved."));
310 gtk_about_dialog_set_comments (GTK_ABOUT_DIALOG(about),
311 _("a modest e-mail client\n\n"
312 "design and implementation: Dirk-Jan C. Binnema\n"
313 "contributions from the fine people at KC and Ig\n"
314 "uses the tinymail email framework written by Philip van Hoof"));
315 gtk_about_dialog_set_authors (GTK_ABOUT_DIALOG(about), authors);
316 gtk_about_dialog_set_website (GTK_ABOUT_DIALOG(about), "http://modest.garage.maemo.org");
317 gtk_window_set_transient_for (GTK_WINDOW (about), GTK_WINDOW (win));
318 gtk_window_set_modal (GTK_WINDOW (about), TRUE);
320 gtk_dialog_run (GTK_DIALOG (about));
321 gtk_widget_destroy(about);
325 * Gets the list of currently selected messages. If the win is the
326 * main window, then it returns a newly allocated list of the headers
327 * selected in the header view. If win is the msg view window, then
328 * the value returned is a list with just a single header.
330 * The caller of this funcion must free the list.
333 get_selected_headers (ModestWindow *win)
335 if (MODEST_IS_MAIN_WINDOW(win)) {
336 GtkWidget *header_view;
338 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
339 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
340 return modest_header_view_get_selected_headers (MODEST_HEADER_VIEW(header_view));
342 } else if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
343 /* for MsgViewWindows, we simply return a list with one element */
345 TnyList *list = NULL;
347 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
348 if (header != NULL) {
349 list = tny_simple_list_new ();
350 tny_list_prepend (list, G_OBJECT(header));
351 g_object_unref (G_OBJECT(header));
356 #ifdef MODEST_TOOLKIT_HILDON2
357 } else if (MODEST_IS_HEADER_WINDOW (win)) {
358 GtkWidget *header_view;
360 header_view = GTK_WIDGET (modest_header_window_get_header_view (MODEST_HEADER_WINDOW (win)));
361 return modest_header_view_get_selected_headers (MODEST_HEADER_VIEW(header_view));
367 static GtkTreeRowReference *
368 get_next_after_selected_headers (ModestHeaderView *header_view)
370 GtkTreeSelection *sel;
371 GList *selected_rows, *node;
373 GtkTreeRowReference *result;
376 model = gtk_tree_view_get_model (GTK_TREE_VIEW (header_view));
377 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
378 selected_rows = gtk_tree_selection_get_selected_rows (sel, NULL);
380 if (selected_rows == NULL)
383 node = g_list_last (selected_rows);
384 path = gtk_tree_path_copy ((GtkTreePath *) node->data);
385 gtk_tree_path_next (path);
387 result = gtk_tree_row_reference_new (model, path);
389 gtk_tree_path_free (path);
390 g_list_foreach (selected_rows, (GFunc) gtk_tree_path_free, NULL);
391 g_list_free (selected_rows);
397 headers_action_mark_as_read (TnyHeader *header,
401 TnyHeaderFlags flags;
403 g_return_if_fail (TNY_IS_HEADER(header));
405 flags = tny_header_get_flags (header);
406 if (flags & TNY_HEADER_FLAG_SEEN) return;
407 tny_header_set_flag (header, TNY_HEADER_FLAG_SEEN);
411 headers_action_mark_as_unread (TnyHeader *header,
415 TnyHeaderFlags flags;
417 g_return_if_fail (TNY_IS_HEADER(header));
419 flags = tny_header_get_flags (header);
420 if (flags & TNY_HEADER_FLAG_SEEN) {
421 tny_header_unset_flag (header, TNY_HEADER_FLAG_SEEN);
425 /** After deleing a message that is currently visible in a window,
426 * show the next message from the list, or close the window if there are no more messages.
429 modest_ui_actions_refresh_message_window_after_delete (ModestMsgViewWindow* win)
431 /* Close msg view window or select next */
432 if (!modest_msg_view_window_select_next_message (win) &&
433 !modest_msg_view_window_select_previous_message (win)) {
435 g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value);
441 modest_ui_actions_on_delete_message (GtkAction *action, ModestWindow *win)
443 modest_ui_actions_on_edit_mode_delete_message (win);
447 modest_ui_actions_on_edit_mode_delete_message (ModestWindow *win)
449 TnyList *header_list = NULL;
450 TnyIterator *iter = NULL;
451 TnyHeader *header = NULL;
452 gchar *message = NULL;
455 ModestWindowMgr *mgr;
456 GtkWidget *header_view = NULL;
457 gboolean retval = TRUE;
459 g_return_val_if_fail (MODEST_IS_WINDOW(win), FALSE);
461 /* Check first if the header view has the focus */
462 if (MODEST_IS_MAIN_WINDOW (win)) {
464 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
465 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
466 if (!gtk_widget_is_focus (header_view))
470 /* Get the headers, either from the header view (if win is the main window),
471 * or from the message view window: */
472 header_list = get_selected_headers (win);
473 if (!header_list) return FALSE;
475 /* Check if any of the headers are already opened, or in the process of being opened */
476 if (MODEST_IS_MAIN_WINDOW (win)) {
477 gint opened_headers = 0;
479 iter = tny_list_create_iterator (header_list);
480 mgr = modest_runtime_get_window_mgr ();
481 while (!tny_iterator_is_done (iter)) {
482 header = TNY_HEADER (tny_iterator_get_current (iter));
484 if (modest_window_mgr_find_registered_header (mgr, header, NULL))
486 g_object_unref (header);
488 tny_iterator_next (iter);
490 g_object_unref (iter);
492 if (opened_headers > 0) {
495 msg = g_strdup_printf (_("mcen_nc_unable_to_delete_n_messages"),
498 modest_platform_run_information_dialog (GTK_WINDOW (win), (const gchar *) msg, FALSE);
501 g_object_unref (header_list);
507 if (tny_list_get_length(header_list) == 1) {
508 iter = tny_list_create_iterator (header_list);
509 header = TNY_HEADER (tny_iterator_get_current (iter));
512 subject = tny_header_dup_subject (header);
514 subject = g_strdup (_("mail_va_no_subject"));
515 desc = g_strdup_printf ("%s", subject);
517 g_object_unref (header);
520 g_object_unref (iter);
522 message = g_strdup_printf(ngettext("emev_nc_delete_message", "emev_nc_delete_messages",
523 tny_list_get_length(header_list)), desc);
525 /* Confirmation dialog */
526 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
530 if (response == GTK_RESPONSE_OK) {
531 ModestWindow *main_window = NULL;
532 ModestWindowMgr *mgr = NULL;
533 GtkTreeModel *model = NULL;
534 GtkTreeSelection *sel = NULL;
535 GList *sel_list = NULL, *tmp = NULL;
536 GtkTreeRowReference *next_row_reference = NULL;
537 GtkTreeRowReference *prev_row_reference = NULL;
538 GtkTreePath *next_path = NULL;
539 GtkTreePath *prev_path = NULL;
540 ModestMailOperation *mail_op = NULL;
542 /* Find last selected row */
543 if (MODEST_IS_MAIN_WINDOW (win)) {
544 model = gtk_tree_view_get_model (GTK_TREE_VIEW (header_view));
545 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
546 sel_list = gtk_tree_selection_get_selected_rows (sel, &model);
547 for (tmp=sel_list; tmp; tmp=tmp->next) {
548 if (tmp->next == NULL) {
549 prev_path = gtk_tree_path_copy((GtkTreePath *) tmp->data);
550 next_path = gtk_tree_path_copy((GtkTreePath *) tmp->data);
552 gtk_tree_path_prev (prev_path);
553 gtk_tree_path_next (next_path);
555 prev_row_reference = gtk_tree_row_reference_new (model, prev_path);
556 next_row_reference = gtk_tree_row_reference_new (model, next_path);
561 /* Disable window dimming management */
562 modest_window_disable_dimming (MODEST_WINDOW(win));
564 /* Remove each header. If it's a view window header_view == NULL */
565 mail_op = modest_mail_operation_new ((GObject *) win);
566 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
568 modest_mail_operation_remove_msgs (mail_op, header_list, FALSE);
569 g_object_unref (mail_op);
571 /* Enable window dimming management */
573 gtk_tree_selection_unselect_all (sel);
575 modest_window_enable_dimming (MODEST_WINDOW(win));
577 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
578 modest_ui_actions_refresh_message_window_after_delete (MODEST_MSG_VIEW_WINDOW (win));
580 /* Get main window */
581 mgr = modest_runtime_get_window_mgr ();
582 main_window = modest_window_mgr_get_main_window (mgr, FALSE); /* don't create */
583 } else if (MODEST_IS_MAIN_WINDOW (win)) {
584 /* Move cursor to next row */
587 /* Select next or previous row */
588 if (gtk_tree_row_reference_valid (next_row_reference)) {
589 gtk_tree_selection_select_path (sel, next_path);
591 else if (gtk_tree_row_reference_valid (prev_row_reference)) {
592 gtk_tree_selection_select_path (sel, prev_path);
596 if (gtk_tree_row_reference_valid (next_row_reference))
597 gtk_tree_row_reference_free (next_row_reference);
598 if (next_path != NULL)
599 gtk_tree_path_free (next_path);
600 if (gtk_tree_row_reference_valid (prev_row_reference))
601 gtk_tree_row_reference_free (prev_row_reference);
602 if (prev_path != NULL)
603 gtk_tree_path_free (prev_path);
606 /* Update toolbar dimming state */
608 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (main_window));
609 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
613 g_list_foreach (sel_list, (GFunc) gtk_tree_path_free, NULL);
614 g_list_free (sel_list);
623 g_object_unref (header_list);
631 /* delete either message or folder, based on where we are */
633 modest_ui_actions_on_delete_message_or_folder (GtkAction *action, ModestWindow *win)
635 g_return_if_fail (MODEST_IS_WINDOW(win));
637 /* Check first if the header view has the focus */
638 if (MODEST_IS_MAIN_WINDOW (win)) {
640 w = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
641 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
642 if (gtk_widget_is_focus (w)) {
643 modest_ui_actions_on_delete_folder (action, MODEST_WINDOW(win));
647 modest_ui_actions_on_delete_message (action, win);
651 modest_ui_actions_on_quit (GtkAction *action, ModestWindow *win)
653 ModestWindowMgr *mgr = NULL;
655 #ifdef MODEST_PLATFORM_MAEMO
656 modest_osso_save_state();
657 #endif /* MODEST_PLATFORM_MAEMO */
659 g_debug ("closing down, clearing %d item(s) from operation queue",
660 modest_mail_operation_queue_num_elements
661 (modest_runtime_get_mail_operation_queue()));
663 /* cancel all outstanding operations */
664 modest_mail_operation_queue_cancel_all
665 (modest_runtime_get_mail_operation_queue());
667 g_debug ("queue has been cleared");
670 /* Check if there are opened editing windows */
671 mgr = modest_runtime_get_window_mgr ();
672 modest_window_mgr_close_all_windows (mgr);
674 /* note: when modest-tny-account-store is finalized,
675 it will automatically set all network connections
678 /* gtk_main_quit (); */
682 modest_ui_actions_on_close_window (GtkAction *action, ModestWindow *win)
686 g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value);
688 /* if (MODEST_IS_MSG_VIEW_WINDOW (win)) { */
689 /* gtk_widget_destroy (GTK_WIDGET (win)); */
690 /* } else if (MODEST_IS_MSG_EDIT_WINDOW (win)) { */
691 /* gboolean ret_value; */
692 /* g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value); */
693 /* } else if (MODEST_IS_WINDOW (win)) { */
694 /* gtk_widget_destroy (GTK_WIDGET (win)); */
696 /* g_return_if_reached (); */
701 modest_ui_actions_add_to_contacts (GtkAction *action, ModestWindow *win)
703 g_return_if_fail (MODEST_IS_MSG_VIEW_WINDOW (win));
705 modest_msg_view_window_add_to_contacts (MODEST_MSG_VIEW_WINDOW (win));
709 modest_ui_actions_on_add_to_contacts (GtkAction *action, ModestWindow *win)
711 GtkClipboard *clipboard = NULL;
712 gchar *selection = NULL;
714 clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
715 selection = gtk_clipboard_wait_for_text (clipboard);
717 /* Question: why is the clipboard being used here?
718 * It doesn't really make a lot of sense. */
722 modest_address_book_add_address (selection);
728 modest_ui_actions_on_new_account (GtkAction *action,
729 ModestWindow *window)
731 modest_ui_actions_run_account_setup_wizard (window);
735 modest_ui_actions_on_accounts (GtkAction *action,
738 /* This is currently only implemented for Maemo */
739 if (!modest_account_mgr_has_accounts (modest_runtime_get_account_mgr(), TRUE)) {
740 if (!modest_ui_actions_run_account_setup_wizard (win))
741 g_debug ("%s: wizard was already running", __FUNCTION__);
745 /* Show the list of accounts */
746 GtkWindow *account_win = GTK_WINDOW (modest_account_view_window_new ());
748 /* The accounts dialog must be modal */
749 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (account_win), (GtkWindow *) win);
750 modest_utils_show_dialog_and_forget (GTK_WINDOW (win), GTK_DIALOG (account_win));
755 modest_ui_actions_on_smtp_servers (GtkAction *action, ModestWindow *win)
757 /* This is currently only implemented for Maemo,
758 * because it requires an API (libconic) to detect different connection
761 #ifndef MODEST_TOOLKIT_GTK /* Defined in config.h */
763 /* Create the window if necessary: */
764 GtkWidget *specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
765 modest_connection_specific_smtp_window_fill_with_connections (
766 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (specific_window),
767 modest_runtime_get_account_mgr());
769 /* Show the window: */
770 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (),
771 GTK_WINDOW (specific_window), (GtkWindow *) win);
772 gtk_widget_show (specific_window);
773 #endif /* !MODEST_TOOLKIT_GTK */
777 modest_ui_actions_compose_msg(ModestWindow *win,
780 const gchar *bcc_str,
781 const gchar *subject_str,
782 const gchar *body_str,
784 gboolean set_as_modified)
786 gchar *account_name = NULL;
788 TnyAccount *account = NULL;
789 TnyFolder *folder = NULL;
790 gchar *from_str = NULL, *signature = NULL, *body = NULL;
791 gboolean use_signature = FALSE;
792 ModestWindow *msg_win = NULL;
793 ModestAccountMgr *mgr = modest_runtime_get_account_mgr();
794 ModestTnyAccountStore *store = modest_runtime_get_account_store();
795 GnomeVFSFileSize total_size, allowed_size;
797 /* we check for low-mem */
798 if (modest_platform_check_memory_low (win, TRUE))
801 #ifdef MODEST_TOOLKIT_HILDON2
802 account_name = g_strdup (modest_window_get_active_account(win));
805 account_name = modest_account_mgr_get_default_account(mgr);
808 g_printerr ("modest: no account found\n");
811 account = modest_tny_account_store_get_server_account (store, account_name, TNY_ACCOUNT_TYPE_STORE);
813 g_printerr ("modest: failed to get tnyaccount for '%s'\n", account_name);
816 folder = modest_tny_account_get_special_folder (account, TNY_FOLDER_TYPE_DRAFTS);
818 g_printerr ("modest: failed to find Drafts folder\n");
821 from_str = modest_account_mgr_get_from_string (mgr, account_name);
823 g_printerr ("modest: failed get from string for '%s'\n", account_name);
827 signature = modest_account_mgr_get_signature (mgr, account_name, &use_signature);
828 if (body_str != NULL) {
829 body = use_signature ? g_strconcat(body_str, "\n--\n", signature, NULL) : g_strdup(body_str);
831 body = use_signature ? g_strconcat("\n--\n", signature, NULL) : g_strdup("");
834 msg = modest_tny_msg_new (to_str, from_str, cc_str, bcc_str, subject_str, body, NULL, NULL, NULL);
836 g_printerr ("modest: failed to create new msg\n");
840 /* Create and register edit window */
841 /* This is destroyed by TODO. */
843 allowed_size = MODEST_MAX_ATTACHMENT_SIZE;
844 msg_win = modest_msg_edit_window_new (msg, account_name, FALSE);
846 if (!modest_window_mgr_register_window (modest_runtime_get_window_mgr(), msg_win, win)) {
847 gtk_widget_destroy (GTK_WIDGET (msg_win));
850 modest_msg_edit_window_set_modified (MODEST_MSG_EDIT_WINDOW (msg_win), set_as_modified);
851 gtk_widget_show_all (GTK_WIDGET (msg_win));
853 while (attachments) {
855 modest_msg_edit_window_attach_file_one((ModestMsgEditWindow *)msg_win,
856 attachments->data, allowed_size);
858 if (total_size > allowed_size) {
859 g_warning ("%s: total size: %u",
860 __FUNCTION__, (unsigned int)total_size);
863 allowed_size -= total_size;
865 attachments = g_slist_next(attachments);
872 g_free (account_name);
874 g_object_unref (G_OBJECT(account));
876 g_object_unref (G_OBJECT(folder));
878 g_object_unref (G_OBJECT(msg));
882 modest_ui_actions_on_new_msg (GtkAction *action, ModestWindow *win)
884 /* if there are no accounts yet, just show the wizard */
885 if (!modest_account_mgr_has_accounts (modest_runtime_get_account_mgr(), TRUE))
886 if (!modest_ui_actions_run_account_setup_wizard (win))
889 modest_ui_actions_compose_msg(win, NULL, NULL, NULL, NULL, NULL, NULL, FALSE);
894 modest_ui_actions_msg_retrieval_check (ModestMailOperation *mail_op,
898 ModestMailOperationStatus status;
900 /* If there is no message or the operation was not successful */
901 status = modest_mail_operation_get_status (mail_op);
902 if (!msg || status != MODEST_MAIL_OPERATION_STATUS_SUCCESS) {
905 /* If it's a memory low issue, then show a banner */
906 error = modest_mail_operation_get_error (mail_op);
907 if (error && error->domain == MODEST_MAIL_OPERATION_ERROR &&
908 error->code == MODEST_MAIL_OPERATION_ERROR_LOW_MEMORY) {
909 GObject *source = modest_mail_operation_get_source (mail_op);
910 modest_platform_run_information_dialog (GTK_IS_WINDOW (source) ? GTK_WINDOW (source) : NULL,
911 _KR("memr_ib_operation_disabled"),
913 g_object_unref (source);
916 if (error && ((error->code == TNY_SERVICE_ERROR_NO_SUCH_MESSAGE) ||
917 error->code == TNY_SERVICE_ERROR_MESSAGE_NOT_AVAILABLE)) {
918 gchar *subject, *msg, *format = NULL;
920 subject = tny_header_dup_subject (header);
922 subject = g_strdup (_("mail_va_no_subject"));
924 account = modest_mail_operation_get_account (mail_op);
926 ModestProtocol *protocol;
927 ModestProtocolType proto;
928 proto = modest_tny_account_get_protocol_type (account);
929 protocol = modest_protocol_registry_get_protocol_by_type (modest_runtime_get_protocol_registry (), proto);
931 format = modest_protocol_get_translation (protocol, MODEST_PROTOCOL_TRANSLATION_MSG_NOT_AVAILABLE, subject);
932 g_object_unref (account);
936 format = g_strdup (_("emev_ni_ui_imap_message_not_available_in_server"));
938 msg = g_strdup_printf (format, subject);
939 modest_platform_run_information_dialog (NULL, msg, FALSE);
945 /* Remove the header from the preregistered uids */
946 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (),
964 OpenMsgBannerInfo *banner_info;
965 GtkTreeRowReference *rowref;
969 open_msg_banner_idle (gpointer userdata)
971 OpenMsgBannerInfo *banner_info = (OpenMsgBannerInfo *) userdata;
973 gdk_threads_enter ();
974 banner_info->idle_handler = 0;
975 banner_info->banner = modest_platform_animation_banner (NULL, NULL, banner_info->message);
977 g_object_ref (banner_info->banner);
979 gdk_threads_leave ();
986 get_header_view_from_window (ModestWindow *window)
988 GtkWidget *header_view;
990 if (MODEST_IS_MAIN_WINDOW (window)) {
991 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (window),
992 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
993 #ifdef MODEST_TOOLKIT_HILDON2
994 } else if (MODEST_IS_HEADER_WINDOW (window)){
995 header_view = GTK_WIDGET (modest_header_window_get_header_view (MODEST_HEADER_WINDOW (window)));
1005 get_info_from_header (TnyHeader *header, gboolean *is_draft, gboolean *can_open)
1008 gchar *account = NULL;
1009 TnyFolderType folder_type = TNY_FOLDER_TYPE_UNKNOWN;
1014 folder = tny_header_get_folder (header);
1015 /* Gets folder type (OUTBOX headers will be opened in edit window */
1016 if (modest_tny_folder_is_local_folder (folder)) {
1017 folder_type = modest_tny_folder_get_local_or_mmc_folder_type (folder);
1018 if (folder_type == TNY_FOLDER_TYPE_INVALID)
1019 g_warning ("%s: BUG: TNY_FOLDER_TYPE_INVALID", __FUNCTION__);
1022 if (folder_type == TNY_FOLDER_TYPE_OUTBOX) {
1023 TnyTransportAccount *traccount = NULL;
1024 ModestTnyAccountStore *accstore = modest_runtime_get_account_store();
1025 traccount = modest_tny_account_store_get_transport_account_from_outbox_header(accstore, header);
1027 ModestTnySendQueue *send_queue = NULL;
1028 ModestTnySendQueueStatus status;
1030 account = g_strdup(modest_tny_account_get_parent_modest_account_name_for_server_account(
1031 TNY_ACCOUNT(traccount)));
1032 send_queue = modest_runtime_get_send_queue(traccount, TRUE);
1033 if (TNY_IS_SEND_QUEUE (send_queue)) {
1034 msg_id = modest_tny_send_queue_get_msg_id (header);
1035 status = modest_tny_send_queue_get_msg_status(send_queue, msg_id);
1037 /* Only open messages in outbox with the editor if they are in Failed state */
1038 if (status == MODEST_TNY_SEND_QUEUE_FAILED) {
1041 #ifdef MODEST_TOOLKIT_HILDON2
1043 /* In Fremantle we can not
1044 open any message from
1045 outbox which is not in
1051 g_object_unref(traccount);
1053 g_warning("Cannot get transport account for message in outbox!!");
1055 } else if (folder_type == TNY_FOLDER_TYPE_DRAFTS) {
1056 *is_draft = TRUE; /* Open in editor if the message is in the Drafts folder */
1060 TnyAccount *acc = tny_folder_get_account (folder);
1063 g_strdup (modest_tny_account_get_parent_modest_account_name_for_server_account (acc));
1064 g_object_unref (acc);
1068 g_object_unref (folder);
1074 open_msg_cb (ModestMailOperation *mail_op,
1081 ModestWindowMgr *mgr = NULL;
1082 ModestWindow *parent_win = NULL;
1083 ModestWindow *win = NULL;
1084 gchar *account = NULL;
1085 gboolean open_in_editor = FALSE;
1087 OpenMsgHelper *helper = (OpenMsgHelper *) user_data;
1089 /* Do nothing if there was any problem with the mail
1090 operation. The error will be shown by the error_handler of
1091 the mail operation */
1092 if (!modest_ui_actions_msg_retrieval_check (mail_op, header, msg))
1095 parent_win = (ModestWindow *) modest_mail_operation_get_source (mail_op);
1097 /* Mark header as read */
1098 headers_action_mark_as_read (header, MODEST_WINDOW(parent_win), NULL);
1100 account = get_info_from_header (header, &open_in_editor, &can_open);
1104 account = g_strdup (modest_window_get_active_account (MODEST_WINDOW (parent_win)));
1106 account = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
1108 if (open_in_editor) {
1109 ModestAccountMgr *mgr = modest_runtime_get_account_mgr ();
1110 gchar *from_header = NULL, *acc_name;
1112 from_header = tny_header_dup_from (header);
1114 /* we cannot edit without a valid account... */
1115 if (!modest_account_mgr_has_accounts(mgr, TRUE)) {
1116 if (!modest_ui_actions_run_account_setup_wizard(parent_win)) {
1117 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (),
1119 g_free (from_header);
1124 acc_name = modest_utils_get_account_name_from_recipient (from_header);
1125 g_free (from_header);
1131 win = modest_msg_edit_window_new (msg, account, TRUE);
1133 gchar *uid = modest_tny_folder_get_header_unique_id (header);
1135 if (helper->rowref && helper->model) {
1136 win = modest_msg_view_window_new_with_header_model (msg, account, (const gchar*) uid,
1137 helper->model, helper->rowref);
1139 win = modest_msg_view_window_new_for_attachment (msg, account, (const gchar*) uid);
1144 /* Register and show new window */
1146 mgr = modest_runtime_get_window_mgr ();
1147 if (!modest_window_mgr_register_window (mgr, win, NULL)) {
1148 gtk_widget_destroy (GTK_WIDGET (win));
1151 gtk_widget_show_all (GTK_WIDGET(win));
1154 /* Update toolbar dimming state */
1155 if (MODEST_IS_MAIN_WINDOW (parent_win)) {
1156 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (parent_win));
1162 g_object_unref (parent_win);
1166 is_memory_full_error (GError *error)
1168 gboolean enough_free_space = TRUE;
1169 GnomeVFSURI *cache_dir_uri;
1170 const gchar *cache_dir;
1171 GnomeVFSFileSize free_space;
1173 cache_dir = tny_account_store_get_cache_dir (TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()));
1174 cache_dir_uri = gnome_vfs_uri_new (cache_dir);
1175 if (gnome_vfs_get_volume_free_space (cache_dir_uri, &free_space) == GNOME_VFS_OK) {
1176 if (free_space < MIN_FREE_SPACE)
1177 enough_free_space = FALSE;
1179 gnome_vfs_uri_unref (cache_dir_uri);
1181 if ((error->code == TNY_SYSTEM_ERROR_MEMORY ||
1182 /* When asking for a mail and no space left on device
1183 tinymail returns this error */
1184 error->code == TNY_SERVICE_ERROR_MESSAGE_NOT_AVAILABLE ||
1185 /* When the folder summary could not be read or
1187 error->code == TNY_IO_ERROR_WRITE ||
1188 error->code == TNY_IO_ERROR_READ) &&
1189 !enough_free_space) {
1197 check_memory_full_error (GtkWidget *parent_window, GError *err)
1202 if (is_memory_full_error (err))
1203 modest_platform_information_banner (parent_window,
1204 NULL, _KR("cerm_device_memory_full"));
1205 else if (err->code == TNY_SYSTEM_ERROR_MEMORY)
1206 /* If the account was created in memory full
1207 conditions then tinymail won't be able to
1208 connect so it'll return this error code */
1209 modest_platform_information_banner (parent_window,
1210 NULL, _("emev_ui_imap_inbox_select_error"));
1218 modest_ui_actions_disk_operations_error_handler (ModestMailOperation *mail_op,
1221 const GError *error;
1222 GObject *win = NULL;
1223 ModestMailOperationStatus status;
1225 win = modest_mail_operation_get_source (mail_op);
1226 error = modest_mail_operation_get_error (mail_op);
1227 status = modest_mail_operation_get_status (mail_op);
1229 /* If the mail op has been cancelled then it's not an error:
1230 don't show any message */
1231 if (status != MODEST_MAIL_OPERATION_STATUS_CANCELED) {
1232 if (is_memory_full_error ((GError *) error)) {
1233 modest_platform_information_banner ((GtkWidget *) win,
1234 NULL, _KR("cerm_device_memory_full"));
1235 } else if (error->code == TNY_SYSTEM_ERROR_MEMORY) {
1236 modest_platform_information_banner ((GtkWidget *) win,
1237 NULL, _("emev_ui_imap_inbox_select_error"));
1238 } else if (error->domain == MODEST_MAIL_OPERATION_ERROR &&
1239 error->code == MODEST_MAIL_OPERATION_ERROR_FILE_IO) {
1240 modest_platform_information_banner ((GtkWidget *) win,
1241 NULL, _CS ("sfil_ni_unable_to_open_file_not_found"));
1242 } else if (user_data) {
1243 modest_platform_information_banner ((GtkWidget *) win,
1249 g_object_unref (win);
1253 * Returns the account a list of headers belongs to. It returns a
1254 * *new* reference so don't forget to unref it
1257 get_account_from_header_list (TnyList *headers)
1259 TnyAccount *account = NULL;
1261 if (tny_list_get_length (headers) > 0) {
1262 TnyIterator *iter = tny_list_create_iterator (headers);
1263 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter));
1264 TnyFolder *folder = tny_header_get_folder (header);
1267 g_object_unref (header);
1269 while (!tny_iterator_is_done (iter)) {
1270 header = TNY_HEADER (tny_iterator_get_current (iter));
1271 folder = tny_header_get_folder (header);
1274 g_object_unref (header);
1276 tny_iterator_next (iter);
1281 account = tny_folder_get_account (folder);
1282 g_object_unref (folder);
1286 g_object_unref (header);
1288 g_object_unref (iter);
1294 get_account_from_header (TnyHeader *header)
1296 TnyAccount *account = NULL;
1299 folder = tny_header_get_folder (header);
1302 account = tny_folder_get_account (folder);
1303 g_object_unref (folder);
1309 open_msg_helper_destroyer (gpointer user_data)
1311 OpenMsgHelper *helper = (OpenMsgHelper *) user_data;
1313 if (helper->banner_info) {
1314 g_free (helper->banner_info->message);
1315 if (helper->banner_info->idle_handler > 0) {
1316 g_source_remove (helper->banner_info->idle_handler);
1317 helper->banner_info->idle_handler = 0;
1319 if (helper->banner_info->banner != NULL) {
1320 gtk_widget_destroy (helper->banner_info->banner);
1321 g_object_unref (helper->banner_info->banner);
1322 helper->banner_info->banner = NULL;
1324 g_slice_free (OpenMsgBannerInfo, helper->banner_info);
1325 helper->banner_info = NULL;
1327 g_object_unref (helper->model);
1328 g_object_unref (helper->header);
1329 gtk_tree_row_reference_free (helper->rowref);
1330 g_slice_free (OpenMsgHelper, helper);
1334 open_msg_performer(gboolean canceled,
1336 GtkWindow *parent_window,
1337 TnyAccount *account,
1340 ModestMailOperation *mail_op = NULL;
1342 ModestProtocolType proto;
1343 TnyConnectionStatus status;
1344 OpenMsgHelper *helper = NULL;
1345 ModestProtocol *protocol;
1346 ModestProtocolRegistry *protocol_registry;
1349 helper = (OpenMsgHelper *) user_data;
1351 status = tny_account_get_connection_status (account);
1352 if (err || canceled) {
1353 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (), helper->header);
1354 /* Free the helper */
1355 open_msg_helper_destroyer (helper);
1357 /* In memory full conditions we could get this error here */
1358 check_memory_full_error ((GtkWidget *) parent_window, err);
1363 /* Get the error message depending on the protocol */
1364 proto = modest_tny_account_get_protocol_type (account);
1365 if (proto == MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1366 proto = MODEST_PROTOCOLS_STORE_MAILDIR;
1369 protocol_registry = modest_runtime_get_protocol_registry ();
1370 subject = tny_header_dup_subject (helper->header);
1372 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, proto);
1373 error_msg = modest_protocol_get_translation (protocol, MODEST_PROTOCOL_TRANSLATION_MSG_NOT_AVAILABLE, subject);
1377 if (error_msg == NULL) {
1378 error_msg = g_strdup (_("mail_ni_ui_folder_get_msg_folder_error"));
1381 #ifndef MODEST_TOOLKIT_HILDON2
1382 gboolean show_open_draft = FALSE;
1383 if (modest_protocol_registry_protocol_type_has_tag (protocol_registry,
1385 MODEST_PROTOCOL_REGISTRY_LOCAL_STORE_PROTOCOLS)) {
1387 TnyFolderType folder_type;
1389 folder = tny_header_get_folder (helper->header);
1390 folder_type = modest_tny_folder_get_local_or_mmc_folder_type (folder);
1391 show_open_draft = (folder_type == TNY_FOLDER_TYPE_DRAFTS);
1392 g_object_unref (folder);
1396 #ifdef MODEST_TOOLKIT_HILDON2
1399 gchar *account_name = get_info_from_header (helper->header, &is_draft, &can_open);
1402 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (), helper->header);
1403 g_free (account_name);
1404 open_msg_helper_destroyer (helper);
1409 ModestWindow *window;
1410 GtkWidget *header_view;
1413 header_view = get_header_view_from_window (MODEST_WINDOW (parent_window));
1414 uid = modest_tny_folder_get_header_unique_id (helper->header);
1416 window = modest_msg_view_window_new_from_header_view
1417 (MODEST_HEADER_VIEW (header_view), account_name, uid, helper->rowref);
1418 if (window != NULL) {
1419 if (!modest_window_mgr_register_window (modest_runtime_get_window_mgr (),
1421 gtk_widget_destroy (GTK_WIDGET (window));
1423 gtk_widget_show_all (GTK_WIDGET(window));
1427 g_free (account_name);
1429 open_msg_helper_destroyer (helper);
1432 g_free (account_name);
1434 /* Create the mail operation */
1436 modest_mail_operation_new_with_error_handling ((GObject *) parent_window,
1437 modest_ui_actions_disk_operations_error_handler,
1439 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
1443 #ifndef MODEST_TOOLKIT_HILDON2
1444 if (show_open_draft) {
1445 helper->banner_info = g_slice_new (OpenMsgBannerInfo);
1446 helper->banner_info->message = g_strdup (_("mail_ib_opening_draft_message"));
1447 helper->banner_info->banner = NULL;
1448 helper->banner_info->idle_handler = g_timeout_add (500, open_msg_banner_idle,
1449 helper->banner_info);
1455 headers = TNY_LIST (tny_simple_list_new ());
1456 tny_list_prepend (headers, G_OBJECT (helper->header));
1457 modest_mail_operation_get_msgs_full (mail_op,
1461 open_msg_helper_destroyer);
1462 g_object_unref (headers);
1467 g_object_unref (mail_op);
1468 g_object_unref (account);
1472 * This function is used by both modest_ui_actions_on_open and
1473 * modest_ui_actions_on_header_activated. This way we always do the
1474 * same when trying to open messages.
1477 open_msg_from_header (TnyHeader *header, GtkTreeRowReference *rowref, ModestWindow *win)
1479 ModestWindowMgr *mgr = NULL;
1480 TnyAccount *account;
1481 gboolean cached = FALSE;
1483 GtkWidget *header_view = NULL;
1484 OpenMsgHelper *helper;
1485 ModestWindow *window;
1487 g_return_if_fail (header != NULL && rowref != NULL);
1489 mgr = modest_runtime_get_window_mgr ();
1492 header_view = get_header_view_from_window (MODEST_WINDOW (win));
1493 if (header_view == NULL)
1496 /* Get the account */
1497 account = get_account_from_header (header);
1502 found = modest_window_mgr_find_registered_header (mgr, header, &window);
1504 /* Do not open again the message and present the
1505 window to the user */
1508 #ifndef MODEST_TOOLKIT_HILDON2
1509 gtk_window_present (GTK_WINDOW (window));
1512 /* the header has been registered already, we don't do
1513 * anything but wait for the window to come up*/
1514 g_debug ("header %p already registered, waiting for window", header);
1519 /* Open each message */
1520 cached = tny_header_get_flags (header) & TNY_HEADER_FLAG_CACHED;
1522 /* Allways download if we are online. */
1523 if (!tny_device_is_online (modest_runtime_get_device ())) {
1526 /* If ask for user permission to download the messages */
1527 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
1528 _("mcen_nc_get_msg"));
1530 /* End if the user does not want to continue */
1531 if (response == GTK_RESPONSE_CANCEL) {
1537 /* We register the window for opening */
1538 modest_window_mgr_register_header (mgr, header, NULL);
1540 /* Create the helper. We need to get a reference to the model
1541 here because it could change while the message is readed
1542 (the user could switch between folders) */
1543 helper = g_slice_new (OpenMsgHelper);
1544 helper->model = g_object_ref (gtk_tree_view_get_model (GTK_TREE_VIEW (header_view)));
1545 helper->header = g_object_ref (header);
1546 helper->rowref = gtk_tree_row_reference_copy (rowref);
1547 helper->banner_info = NULL;
1549 /* Connect to the account and perform */
1551 modest_platform_connect_and_perform ((GtkWindow *) win, TRUE, g_object_ref (account),
1552 open_msg_performer, helper);
1554 /* Call directly the performer, do not need to connect */
1555 open_msg_performer (FALSE, NULL, (GtkWindow *) win,
1556 g_object_ref (account), helper);
1561 g_object_unref (account);
1565 modest_ui_actions_on_open (GtkAction *action, ModestWindow *win)
1572 /* we check for low-mem; in that case, show a warning, and don't allow
1575 if (modest_platform_check_memory_low (MODEST_WINDOW(win), TRUE))
1579 headers = get_selected_headers (win);
1583 headers_count = tny_list_get_length (headers);
1584 if (headers_count != 1) {
1585 if (headers_count > 1) {
1586 /* Don't allow activation if there are more than one message selected */
1587 modest_platform_information_banner (NULL, NULL, _("mcen_ib_select_one_message"));
1590 g_object_unref (headers);
1594 iter = tny_list_create_iterator (headers);
1595 header = TNY_HEADER (tny_iterator_get_current (iter));
1596 g_object_unref (iter);
1600 open_msg_from_header (header, NULL, win);
1601 g_object_unref (header);
1604 g_object_unref(headers);
1608 rf_helper_window_closed (gpointer data,
1611 ReplyForwardHelper *helper = (ReplyForwardHelper *) data;
1613 helper->parent_window = NULL;
1616 static ReplyForwardHelper*
1617 create_reply_forward_helper (ReplyForwardAction action,
1619 guint reply_forward_type,
1622 ReplyForwardHelper *rf_helper = NULL;
1623 const gchar *active_acc = modest_window_get_active_account (win);
1625 rf_helper = g_slice_new0 (ReplyForwardHelper);
1626 rf_helper->reply_forward_type = reply_forward_type;
1627 rf_helper->action = action;
1628 rf_helper->parent_window = (MODEST_IS_WINDOW (win)) ? GTK_WIDGET (win) : NULL;
1629 rf_helper->header = (header) ? g_object_ref (header) : NULL;
1630 rf_helper->account_name = (active_acc) ?
1631 g_strdup (active_acc) :
1632 modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
1634 /* Note that window could be destroyed just AFTER calling
1635 register_window so we must ensure that this pointer does
1636 not hold invalid references */
1637 if (rf_helper->parent_window)
1638 g_object_weak_ref (G_OBJECT (rf_helper->parent_window),
1639 rf_helper_window_closed, rf_helper);
1645 free_reply_forward_helper (gpointer data)
1647 ReplyForwardHelper *helper;
1649 helper = (ReplyForwardHelper *) data;
1650 g_free (helper->account_name);
1652 g_object_unref (helper->header);
1653 if (helper->parent_window)
1654 g_object_weak_unref (G_OBJECT (helper->parent_window),
1655 rf_helper_window_closed, helper);
1656 g_slice_free (ReplyForwardHelper, helper);
1660 reply_forward_cb (ModestMailOperation *mail_op,
1667 TnyMsg *new_msg = NULL;
1668 ReplyForwardHelper *rf_helper;
1669 ModestWindow *msg_win = NULL;
1670 ModestEditType edit_type;
1672 TnyAccount *account = NULL;
1673 ModestWindowMgr *mgr = NULL;
1674 gchar *signature = NULL;
1675 gboolean use_signature;
1677 /* If there was any error. The mail operation could be NULL,
1678 this means that we already have the message downloaded and
1679 that we didn't do a mail operation to retrieve it */
1680 rf_helper = (ReplyForwardHelper *) user_data;
1681 if (mail_op && !modest_ui_actions_msg_retrieval_check (mail_op, header, msg))
1684 from = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(),
1685 rf_helper->account_name);
1686 signature = modest_account_mgr_get_signature (modest_runtime_get_account_mgr(),
1687 rf_helper->account_name,
1690 /* Create reply mail */
1691 switch (rf_helper->action) {
1694 modest_tny_msg_create_reply_msg (msg, header, from,
1695 (use_signature) ? signature : NULL,
1696 rf_helper->reply_forward_type,
1697 MODEST_TNY_MSG_REPLY_MODE_SENDER);
1699 case ACTION_REPLY_TO_ALL:
1701 modest_tny_msg_create_reply_msg (msg, header, from,
1702 (use_signature) ? signature : NULL,
1703 rf_helper->reply_forward_type,
1704 MODEST_TNY_MSG_REPLY_MODE_ALL);
1705 edit_type = MODEST_EDIT_TYPE_REPLY;
1707 case ACTION_FORWARD:
1709 modest_tny_msg_create_forward_msg (msg, from, (use_signature) ? signature : NULL,
1710 rf_helper->reply_forward_type);
1711 edit_type = MODEST_EDIT_TYPE_FORWARD;
1714 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (),
1716 g_return_if_reached ();
1724 g_warning ("%s: failed to create message\n", __FUNCTION__);
1728 account = modest_tny_account_store_get_server_account (modest_runtime_get_account_store(),
1729 rf_helper->account_name,
1730 TNY_ACCOUNT_TYPE_STORE);
1732 g_warning ("%s: failed to get tnyaccount for '%s'\n", __FUNCTION__, rf_helper->account_name);
1736 /* Create and register the windows */
1737 msg_win = modest_msg_edit_window_new (new_msg, rf_helper->account_name, FALSE);
1738 mgr = modest_runtime_get_window_mgr ();
1739 modest_window_mgr_register_window (mgr, msg_win, (ModestWindow *) rf_helper->parent_window);
1741 /* Note that register_window could have deleted the account */
1742 if (MODEST_IS_WINDOW (rf_helper->parent_window)) {
1743 gdouble parent_zoom;
1745 parent_zoom = modest_window_get_zoom (MODEST_WINDOW (rf_helper->parent_window));
1746 modest_window_set_zoom (msg_win, parent_zoom);
1749 /* Show edit window */
1750 gtk_widget_show_all (GTK_WIDGET (msg_win));
1753 /* We always unregister the header because the message is
1754 forwarded or replied so the original one is no longer
1756 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (),
1759 g_object_unref (G_OBJECT (new_msg));
1761 g_object_unref (G_OBJECT (account));
1762 free_reply_forward_helper (rf_helper);
1765 /* Checks a list of headers. If any of them are not currently
1766 * downloaded (CACHED) then returns TRUE else returns FALSE.
1769 header_list_count_uncached_msgs (TnyList *header_list)
1772 gint uncached_messages = 0;
1774 iter = tny_list_create_iterator (header_list);
1775 while (!tny_iterator_is_done (iter)) {
1778 header = TNY_HEADER (tny_iterator_get_current (iter));
1780 if (!(tny_header_get_flags (header) & TNY_HEADER_FLAG_CACHED))
1781 uncached_messages ++;
1782 g_object_unref (header);
1785 tny_iterator_next (iter);
1787 g_object_unref (iter);
1789 return uncached_messages;
1792 /* Returns FALSE if the user does not want to download the
1793 * messages. Returns TRUE if the user allowed the download.
1796 connect_to_get_msg (ModestWindow *win,
1797 gint num_of_uncached_msgs,
1798 TnyAccount *account)
1800 GtkResponseType response;
1802 /* Allways download if we are online. */
1803 if (tny_device_is_online (modest_runtime_get_device ()))
1806 /* If offline, then ask for user permission to download the messages */
1807 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
1808 ngettext("mcen_nc_get_msg",
1810 num_of_uncached_msgs));
1812 if (response == GTK_RESPONSE_CANCEL)
1815 return modest_platform_connect_and_wait((GtkWindow *) win, account);
1819 reply_forward_performer (gboolean canceled,
1821 GtkWindow *parent_window,
1822 TnyAccount *account,
1825 ReplyForwardHelper *rf_helper = NULL;
1826 ModestMailOperation *mail_op;
1828 rf_helper = (ReplyForwardHelper *) user_data;
1830 if (canceled || err) {
1831 free_reply_forward_helper (rf_helper);
1835 /* Retrieve the message */
1836 modest_window_mgr_register_header (modest_runtime_get_window_mgr (), rf_helper->header, NULL);
1837 mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT (parent_window),
1838 modest_ui_actions_disk_operations_error_handler,
1840 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
1841 modest_mail_operation_get_msg (mail_op, rf_helper->header, TRUE, reply_forward_cb, rf_helper);
1844 g_object_unref(mail_op);
1848 * Common code for the reply and forward actions
1851 reply_forward (ReplyForwardAction action, ModestWindow *win)
1853 ReplyForwardHelper *rf_helper = NULL;
1854 guint reply_forward_type;
1856 g_return_if_fail (MODEST_IS_WINDOW(win));
1858 /* we check for low-mem; in that case, show a warning, and don't allow
1859 * reply/forward (because it could potentially require a lot of memory */
1860 if (modest_platform_check_memory_low (MODEST_WINDOW(win), TRUE))
1864 /* we need an account when editing */
1865 if (!modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE)) {
1866 if (!modest_ui_actions_run_account_setup_wizard (win))
1870 reply_forward_type =
1871 modest_conf_get_int (modest_runtime_get_conf (),
1872 (action == ACTION_FORWARD) ?
1873 MODEST_CONF_FORWARD_TYPE :
1874 MODEST_CONF_REPLY_TYPE,
1877 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
1879 TnyHeader *header = NULL;
1880 /* Get header and message. Do not free them here, the
1881 reply_forward_cb must do it */
1882 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW(win));
1883 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
1885 if (msg && header) {
1887 rf_helper = create_reply_forward_helper (action, win,
1888 reply_forward_type, header);
1889 reply_forward_cb (NULL, header, FALSE, msg, NULL, rf_helper);
1891 g_warning("%s: no message or header found in viewer\n", __FUNCTION__);
1895 g_object_unref (msg);
1897 g_object_unref (header);
1899 TnyHeader *header = NULL;
1901 gboolean do_retrieve = TRUE;
1902 TnyList *header_list = NULL;
1904 header_list = get_selected_headers (win);
1907 /* Check that only one message is selected for replying */
1908 if (tny_list_get_length (header_list) != 1) {
1909 modest_platform_information_banner ((win) ? GTK_WIDGET (win) : NULL,
1910 NULL, _("mcen_ib_select_one_message"));
1911 g_object_unref (header_list);
1915 /* Only reply/forward to one message */
1916 iter = tny_list_create_iterator (header_list);
1917 header = TNY_HEADER (tny_iterator_get_current (iter));
1918 g_object_unref (iter);
1920 /* Retrieve messages */
1921 do_retrieve = (action == ACTION_FORWARD) ||
1922 (reply_forward_type != MODEST_TNY_MSG_REPLY_TYPE_CITE);
1925 TnyAccount *account = NULL;
1926 TnyFolder *folder = NULL;
1927 gdouble download = TRUE;
1928 guint uncached_msgs = 0;
1930 folder = tny_header_get_folder (header);
1932 goto do_retrieve_frees;
1933 account = tny_folder_get_account (folder);
1935 goto do_retrieve_frees;
1937 uncached_msgs = header_list_count_uncached_msgs (header_list);
1939 if (uncached_msgs > 0) {
1940 /* Allways download if we are online. */
1941 if (!tny_device_is_online (modest_runtime_get_device ())) {
1944 /* If ask for user permission to download the messages */
1945 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
1946 ngettext("mcen_nc_get_msg",
1950 /* End if the user does not want to continue */
1951 if (response == GTK_RESPONSE_CANCEL)
1958 rf_helper = create_reply_forward_helper (action, win,
1959 reply_forward_type, header);
1960 if (uncached_msgs > 0) {
1961 modest_platform_connect_and_perform (GTK_WINDOW (win),
1963 reply_forward_performer,
1966 reply_forward_performer (FALSE, NULL, GTK_WINDOW (win),
1967 account, rf_helper);
1972 g_object_unref (account);
1974 g_object_unref (folder);
1976 reply_forward_cb (NULL, header, FALSE, NULL, NULL, rf_helper);
1979 g_object_unref (header_list);
1980 g_object_unref (header);
1985 modest_ui_actions_on_reply (GtkAction *action, ModestWindow *win)
1987 g_return_if_fail (MODEST_IS_WINDOW(win));
1989 reply_forward (ACTION_REPLY, win);
1993 modest_ui_actions_on_forward (GtkAction *action, ModestWindow *win)
1995 g_return_if_fail (MODEST_IS_WINDOW(win));
1997 reply_forward (ACTION_FORWARD, win);
2001 modest_ui_actions_on_reply_all (GtkAction *action, ModestWindow *win)
2003 g_return_if_fail (MODEST_IS_WINDOW(win));
2005 reply_forward (ACTION_REPLY_TO_ALL, win);
2009 modest_ui_actions_on_next (GtkAction *action,
2010 ModestWindow *window)
2012 if (MODEST_IS_MAIN_WINDOW (window)) {
2013 GtkWidget *header_view;
2015 header_view = modest_main_window_get_child_widget (
2016 MODEST_MAIN_WINDOW(window),
2017 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2021 modest_header_view_select_next (
2022 MODEST_HEADER_VIEW(header_view));
2023 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
2024 modest_msg_view_window_select_next_message (
2025 MODEST_MSG_VIEW_WINDOW (window));
2027 g_return_if_reached ();
2032 modest_ui_actions_on_prev (GtkAction *action,
2033 ModestWindow *window)
2035 g_return_if_fail (MODEST_IS_WINDOW(window));
2037 if (MODEST_IS_MAIN_WINDOW (window)) {
2038 GtkWidget *header_view;
2039 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
2040 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2044 modest_header_view_select_prev (MODEST_HEADER_VIEW(header_view));
2045 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
2046 modest_msg_view_window_select_previous_message (MODEST_MSG_VIEW_WINDOW (window));
2048 g_return_if_reached ();
2053 modest_ui_actions_on_sort (GtkAction *action,
2054 ModestWindow *window)
2056 GtkWidget *header_view = NULL;
2058 g_return_if_fail (MODEST_IS_WINDOW(window));
2060 if (MODEST_IS_MAIN_WINDOW (window)) {
2061 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
2062 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2063 #ifdef MODEST_TOOLKIT_HILDON2
2064 } else if (MODEST_IS_HEADER_WINDOW (window)) {
2065 header_view = GTK_WIDGET (modest_header_window_get_header_view (MODEST_HEADER_WINDOW (window)));
2070 modest_platform_information_banner (NULL, NULL, _CS("ckdg_ib_nothing_to_sort"));
2075 /* Show sorting dialog */
2076 modest_utils_run_sort_dialog (GTK_WINDOW (window), MODEST_SORT_HEADERS);
2080 new_messages_arrived (ModestMailOperation *self,
2081 TnyList *new_headers,
2085 gboolean show_visual_notifications;
2087 source = modest_mail_operation_get_source (self);
2088 show_visual_notifications = (source) ? FALSE : TRUE;
2090 g_object_unref (source);
2092 /* Notify new messages have been downloaded. If the
2093 send&receive was invoked by the user then do not show any
2094 visual notification, only play a sound and activate the LED
2095 (for the Maemo version) */
2096 if (TNY_IS_LIST(new_headers) && (tny_list_get_length (new_headers)) > 0)
2097 modest_platform_on_new_headers_received (new_headers,
2098 show_visual_notifications);
2103 retrieve_all_messages_cb (GObject *source,
2105 guint retrieve_limit)
2111 window = GTK_WINDOW (source);
2112 msg = g_strdup_printf (_("mail_nc_msg_count_limit_exceeded"),
2113 num_msgs, retrieve_limit);
2115 /* Ask the user if they want to retrieve all the messages */
2117 modest_platform_run_confirmation_dialog_with_buttons (window, msg,
2118 _("mcen_bd_get_all"),
2119 _("mcen_bd_newest_only"));
2120 /* Free and return */
2122 return (response == GTK_RESPONSE_ACCEPT) ? TRUE : FALSE;
2126 TnyAccount *account;
2128 gchar *account_name;
2129 gboolean poke_status;
2130 gboolean interactive;
2131 ModestMailOperation *mail_op;
2135 do_send_receive_performer (gboolean canceled,
2137 GtkWindow *parent_window,
2138 TnyAccount *account,
2141 SendReceiveInfo *info;
2143 info = (SendReceiveInfo *) user_data;
2145 if (err || canceled) {
2146 /* In memory full conditions we could get this error here */
2147 check_memory_full_error ((GtkWidget *) parent_window, err);
2149 if (info->mail_op) {
2150 modest_mail_operation_queue_remove (modest_runtime_get_mail_operation_queue (),
2156 /* Set send/receive operation in progress */
2157 if (info->win && MODEST_IS_MAIN_WINDOW (info->win)) {
2158 modest_main_window_notify_send_receive_initied (MODEST_MAIN_WINDOW (info->win));
2161 if (info->win && MODEST_IS_MAIN_WINDOW (info->win))
2162 g_signal_connect (G_OBJECT (info->mail_op), "operation-finished",
2163 G_CALLBACK (on_send_receive_finished),
2166 /* Send & receive. */
2167 modest_mail_operation_update_account (info->mail_op, info->account_name, info->poke_status, info->interactive,
2168 (info->win) ? retrieve_all_messages_cb : NULL,
2169 new_messages_arrived, info->win);
2174 g_object_unref (G_OBJECT (info->mail_op));
2175 if (info->account_name)
2176 g_free (info->account_name);
2178 g_object_unref (info->win);
2180 g_object_unref (info->account);
2181 g_slice_free (SendReceiveInfo, info);
2185 * This function performs the send & receive required actions. The
2186 * window is used to create the mail operation. Typically it should
2187 * always be the main window, but we pass it as argument in order to
2191 modest_ui_actions_do_send_receive (const gchar *account_name,
2192 gboolean force_connection,
2193 gboolean poke_status,
2194 gboolean interactive,
2197 gchar *acc_name = NULL;
2198 SendReceiveInfo *info;
2199 ModestTnyAccountStore *acc_store;
2201 /* If no account name was provided then get the current account, and if
2202 there is no current account then pick the default one: */
2203 if (!account_name) {
2205 acc_name = g_strdup (modest_window_get_active_account (win));
2207 acc_name = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
2209 g_printerr ("modest: cannot get default account\n");
2213 acc_name = g_strdup (account_name);
2216 acc_store = modest_runtime_get_account_store ();
2218 /* Create the info for the connect and perform */
2219 info = g_slice_new (SendReceiveInfo);
2220 info->account_name = acc_name;
2221 info->win = (win) ? g_object_ref (win) : NULL;
2222 info->poke_status = poke_status;
2223 info->interactive = interactive;
2224 info->account = modest_tny_account_store_get_server_account (acc_store, acc_name,
2225 TNY_ACCOUNT_TYPE_STORE);
2226 /* We need to create the operation here, because otherwise it
2227 could happen that the queue emits the queue-empty signal
2228 while we're trying to connect the account */
2229 info->mail_op = modest_mail_operation_new_with_error_handling ((info->win) ? G_OBJECT (info->win) : NULL,
2230 modest_ui_actions_disk_operations_error_handler,
2232 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), info->mail_op);
2234 /* Invoke the connect and perform */
2235 modest_platform_connect_and_perform ((win) ? GTK_WINDOW (win) : NULL,
2236 force_connection, info->account,
2237 do_send_receive_performer, info);
2242 modest_ui_actions_do_cancel_send (const gchar *account_name,
2245 TnyTransportAccount *transport_account;
2246 TnySendQueue *send_queue = NULL;
2247 GError *error = NULL;
2249 /* Get transport account */
2251 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
2252 (modest_runtime_get_account_store(),
2254 TNY_ACCOUNT_TYPE_TRANSPORT));
2255 if (!transport_account) {
2256 g_printerr ("modest: no transport account found for '%s'\n", account_name);
2261 send_queue = TNY_SEND_QUEUE (modest_runtime_get_send_queue (transport_account, TRUE));
2262 if (!TNY_IS_SEND_QUEUE(send_queue)) {
2263 g_set_error (&error, MODEST_MAIL_OPERATION_ERROR,
2264 MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND,
2265 "modest: could not find send queue for account\n");
2267 /* Cancel the current send */
2268 tny_account_cancel (TNY_ACCOUNT (transport_account));
2270 /* Suspend all pending messages */
2271 tny_send_queue_cancel (send_queue, TNY_SEND_QUEUE_CANCEL_ACTION_SUSPEND, &error);
2275 if (transport_account != NULL)
2276 g_object_unref (G_OBJECT (transport_account));
2280 modest_ui_actions_cancel_send_all (ModestWindow *win)
2282 GSList *account_names, *iter;
2284 account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
2287 iter = account_names;
2289 modest_ui_actions_do_cancel_send ((const char*) iter->data, win);
2290 iter = g_slist_next (iter);
2293 modest_account_mgr_free_account_names (account_names);
2294 account_names = NULL;
2298 modest_ui_actions_cancel_send (GtkAction *action, ModestWindow *win)
2301 /* Check if accounts exist */
2302 gboolean accounts_exist =
2303 modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
2305 /* If not, allow the user to create an account before trying to send/receive. */
2306 if (!accounts_exist)
2307 modest_ui_actions_on_accounts (NULL, win);
2309 /* Cancel all sending operaitons */
2310 modest_ui_actions_cancel_send_all (win);
2314 * Refreshes all accounts. This function will be used by automatic
2318 modest_ui_actions_do_send_receive_all (ModestWindow *win,
2319 gboolean force_connection,
2320 gboolean poke_status,
2321 gboolean interactive)
2323 GSList *account_names, *iter;
2325 account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
2328 iter = account_names;
2330 modest_ui_actions_do_send_receive ((const char*) iter->data,
2332 poke_status, interactive, win);
2333 iter = g_slist_next (iter);
2336 modest_account_mgr_free_account_names (account_names);
2337 account_names = NULL;
2341 * Handler of the click on Send&Receive button in the main toolbar
2344 modest_ui_actions_on_send_receive (GtkAction *action, ModestWindow *win)
2346 /* Check if accounts exist */
2347 gboolean accounts_exist;
2350 modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
2352 /* If not, allow the user to create an account before trying to send/receive. */
2353 if (!accounts_exist)
2354 modest_ui_actions_on_accounts (NULL, win);
2356 /* Refresh the current folder. The if is always TRUE it's just an extra check */
2357 if (MODEST_IS_MAIN_WINDOW (win)) {
2358 GtkWidget *folder_view;
2359 TnyFolderStore *folder_store;
2362 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
2363 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2367 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
2370 g_object_unref (folder_store);
2371 /* Refresh the active account. Force the connection if needed
2372 and poke the status of all folders */
2373 modest_ui_actions_do_send_receive (NULL, TRUE, TRUE, TRUE, win);
2374 #ifdef MODEST_TOOLKIT_HILDON2
2375 } else if (MODEST_IS_ACCOUNTS_WINDOW (win)) {
2376 modest_ui_actions_do_send_receive_all (win, TRUE, TRUE, TRUE);
2379 const gchar *active_account;
2380 active_account = modest_window_get_active_account (MODEST_WINDOW (win));
2382 modest_ui_actions_do_send_receive (active_account, TRUE, TRUE, TRUE, win);
2389 modest_ui_actions_toggle_header_list_view (GtkAction *action, ModestMainWindow *main_window)
2392 GtkWidget *header_view;
2394 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2396 header_view = modest_main_window_get_child_widget (main_window,
2397 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2401 conf = modest_runtime_get_conf ();
2403 /* what is saved/restored is depending on the style; thus; we save with
2404 * old style, then update the style, and restore for this new style
2406 modest_widget_memory_save (conf, G_OBJECT(header_view), MODEST_CONF_HEADER_VIEW_KEY);
2408 if (modest_header_view_get_style
2409 (MODEST_HEADER_VIEW(header_view)) == MODEST_HEADER_VIEW_STYLE_DETAILS)
2410 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
2411 MODEST_HEADER_VIEW_STYLE_TWOLINES);
2413 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
2414 MODEST_HEADER_VIEW_STYLE_DETAILS);
2416 modest_widget_memory_restore (conf, G_OBJECT(header_view),
2417 MODEST_CONF_HEADER_VIEW_KEY);
2422 modest_ui_actions_on_header_selected (ModestHeaderView *header_view,
2424 ModestMainWindow *main_window)
2426 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2427 g_return_if_fail (MODEST_IS_HEADER_VIEW (header_view));
2429 /* in the case the folder is empty, show the empty folder message and focus
2431 if (!header && gtk_widget_is_focus (GTK_WIDGET (header_view))) {
2432 if (modest_header_view_is_empty (header_view)) {
2433 TnyFolder *folder = modest_header_view_get_folder (header_view);
2434 GtkWidget *folder_view =
2435 modest_main_window_get_child_widget (main_window,
2436 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2437 if (folder != NULL) {
2438 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view), folder, FALSE);
2439 g_object_unref (folder);
2441 gtk_widget_grab_focus (GTK_WIDGET (folder_view));
2445 /* If no header has been selected then exit */
2450 if (!gtk_widget_is_focus (GTK_WIDGET(header_view)))
2451 gtk_widget_grab_focus (GTK_WIDGET(header_view));
2453 /* Update toolbar dimming state */
2454 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (main_window));
2455 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
2459 modest_ui_actions_on_header_activated (ModestHeaderView *header_view,
2462 ModestWindow *window)
2464 GtkWidget *open_widget;
2465 GtkTreeRowReference *rowref;
2467 g_return_if_fail (MODEST_IS_WINDOW(window));
2468 g_return_if_fail (MODEST_IS_HEADER_VIEW (header_view));
2469 g_return_if_fail (TNY_IS_HEADER (header));
2471 if (modest_header_view_count_selected_headers (header_view) > 1) {
2472 /* Don't allow activation if there are more than one message selected */
2473 modest_platform_information_banner (NULL, NULL, _("mcen_ib_select_one_message"));
2477 /* we check for low-mem; in that case, show a warning, and don't allow
2478 * activating headers
2480 if (modest_platform_check_memory_low (MODEST_WINDOW(window), TRUE))
2483 if (MODEST_IS_MAIN_WINDOW (window)) {
2484 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (window));
2485 open_widget = modest_window_get_action_widget (MODEST_WINDOW (window), "/MenuBar/EmailMenu/EmailOpenMenu");
2486 if (!GTK_WIDGET_IS_SENSITIVE (open_widget))
2490 rowref = gtk_tree_row_reference_new (gtk_tree_view_get_model (GTK_TREE_VIEW (header_view)), path);
2491 open_msg_from_header (header, rowref, MODEST_WINDOW (window));
2492 gtk_tree_row_reference_free (rowref);
2496 set_active_account_from_tny_account (TnyAccount *account,
2497 ModestWindow *window)
2499 const gchar *server_acc_name = tny_account_get_id (account);
2501 /* We need the TnyAccount provided by the
2502 account store because that is the one that
2503 knows the name of the Modest account */
2504 TnyAccount *modest_server_account = modest_server_account =
2505 modest_tny_account_store_get_tny_account_by (modest_runtime_get_account_store (),
2506 MODEST_TNY_ACCOUNT_STORE_QUERY_ID,
2508 if (!modest_server_account) {
2509 g_warning ("%s: could not get tny account\n", __FUNCTION__);
2513 /* Update active account, but only if it's not a pseudo-account */
2514 if ((!modest_tny_account_is_virtual_local_folders(modest_server_account)) &&
2515 (!modest_tny_account_is_memory_card_account(modest_server_account))) {
2516 const gchar *modest_acc_name =
2517 modest_tny_account_get_parent_modest_account_name_for_server_account (modest_server_account);
2518 if (modest_acc_name)
2519 modest_window_set_active_account (window, modest_acc_name);
2522 g_object_unref (modest_server_account);
2527 folder_refreshed_cb (ModestMailOperation *mail_op,
2531 ModestMainWindow *win = NULL;
2532 GtkWidget *folder_view;
2533 const GError *error;
2535 g_return_if_fail (TNY_IS_FOLDER (folder));
2537 win = MODEST_MAIN_WINDOW (user_data);
2539 /* Check if the operation failed due to memory low conditions */
2540 error = modest_mail_operation_get_error (mail_op);
2541 if (error && error->domain == MODEST_MAIL_OPERATION_ERROR &&
2542 error->code == MODEST_MAIL_OPERATION_ERROR_LOW_MEMORY) {
2543 modest_platform_run_information_dialog (GTK_WINDOW (win),
2544 _KR("memr_ib_operation_disabled"),
2550 modest_main_window_get_child_widget(win, MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2553 TnyFolderStore *current_folder;
2555 current_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
2556 if (current_folder) {
2557 gboolean different = ((TnyFolderStore *) folder != current_folder);
2558 g_object_unref (current_folder);
2564 /* Check if folder is empty and set headers view contents style */
2565 if (tny_folder_get_all_count (folder) == 0)
2566 modest_main_window_set_contents_style (win,
2567 MODEST_MAIN_WINDOW_CONTENTS_STYLE_EMPTY);
2572 modest_ui_actions_on_folder_selection_changed (ModestFolderView *folder_view,
2573 TnyFolderStore *folder_store,
2575 ModestMainWindow *main_window)
2578 GtkWidget *header_view;
2580 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2582 header_view = modest_main_window_get_child_widget(main_window,
2583 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2587 conf = modest_runtime_get_conf ();
2589 if (TNY_IS_ACCOUNT (folder_store)) {
2591 set_active_account_from_tny_account (TNY_ACCOUNT (folder_store), MODEST_WINDOW (main_window));
2593 /* Show account details */
2594 modest_main_window_set_contents_style (main_window, MODEST_MAIN_WINDOW_CONTENTS_STYLE_DETAILS);
2597 if (TNY_IS_FOLDER (folder_store) && selected) {
2598 TnyAccount *account;
2599 const gchar *account_name = NULL;
2601 /* Update the active account */
2602 account = modest_tny_folder_get_account (TNY_FOLDER (folder_store));
2604 set_active_account_from_tny_account (account, MODEST_WINDOW (main_window));
2606 modest_tny_account_get_parent_modest_account_name_for_server_account (account);
2607 g_object_unref (account);
2611 /* Set the header style by default, it could
2612 be changed later by the refresh callback to
2614 modest_main_window_set_contents_style (main_window,
2615 MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS);
2617 /* Set folder on header view. This function
2618 will call tny_folder_refresh_async so we
2619 pass a callback that will be called when
2620 finished. We use that callback to set the
2621 empty view if there are no messages */
2622 modest_header_view_set_folder (MODEST_HEADER_VIEW(header_view),
2623 TNY_FOLDER (folder_store),
2625 MODEST_WINDOW (main_window),
2626 folder_refreshed_cb,
2629 /* Restore configuration. We need to do this
2630 *after* the set_folder because the widget
2631 memory asks the header view about its
2633 modest_widget_memory_restore (modest_runtime_get_conf (),
2634 G_OBJECT(header_view),
2635 MODEST_CONF_HEADER_VIEW_KEY);
2637 /* No need to save the header view
2638 configuration for Maemo because it only
2639 saves the sorting stuff and that it's
2640 already being done by the sort
2641 dialog. Remove it when the GNOME version
2642 has the same behaviour */
2643 #ifdef MODEST_TOOLKIT_GTK
2644 if (modest_main_window_get_contents_style (main_window) ==
2645 MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS)
2646 modest_widget_memory_save (conf, G_OBJECT (header_view),
2647 MODEST_CONF_HEADER_VIEW_KEY);
2649 modest_header_view_clear (MODEST_HEADER_VIEW(header_view));
2653 /* Update dimming state */
2654 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (main_window));
2655 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
2659 modest_ui_actions_on_item_not_found (ModestHeaderView *header_view,ModestItemType type,
2666 item = (type == MODEST_ITEM_TYPE_FOLDER) ? "folder" : "message";
2668 online = tny_device_is_online (modest_runtime_get_device());
2671 /* already online -- the item is simply not there... */
2672 dialog = gtk_message_dialog_new (GTK_WINDOW (win),
2674 GTK_MESSAGE_WARNING,
2676 _("The %s you selected cannot be found"),
2678 gtk_dialog_add_button (GTK_DIALOG (dialog),_("mcen_bd_dialog_ok"), GTK_RESPONSE_ACCEPT);
2679 gtk_dialog_run (GTK_DIALOG(dialog));
2681 dialog = gtk_dialog_new_with_buttons (_("Connection requested"),
2684 _("mcen_bd_dialog_cancel"),
2685 GTK_RESPONSE_REJECT,
2686 _("mcen_bd_dialog_ok"),
2687 GTK_RESPONSE_ACCEPT,
2689 txt = g_strdup_printf (_("This %s is not available in offline mode.\n"
2690 "Do you want to get online?"), item);
2691 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
2692 gtk_label_new (txt), FALSE, FALSE, 0);
2693 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
2696 gtk_window_set_default_size (GTK_WINDOW(dialog), 300, 300);
2697 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
2698 /* TODO: Comment about why is this commented out: */
2699 /* modest_platform_connect_and_wait (); */
2702 gtk_widget_destroy (dialog);
2706 modest_ui_actions_on_msg_link_hover (ModestMsgView *msgview, const gchar* link,
2709 /* g_message ("%s %s", __FUNCTION__, link); */
2714 modest_ui_actions_on_msg_link_clicked (ModestMsgView *msgview, const gchar* link,
2717 modest_platform_activate_uri (link);
2721 modest_ui_actions_on_msg_link_contextual (ModestMsgView *msgview, const gchar* link,
2724 modest_platform_show_uri_popup (link);
2728 modest_ui_actions_on_msg_attachment_clicked (ModestMsgView *msgview, TnyMimePart *mime_part,
2731 /* we check for low-mem; in that case, show a warning, and don't allow
2732 * viewing attachments
2734 if (modest_platform_check_memory_low (MODEST_WINDOW(win), TRUE))
2737 modest_msg_view_window_view_attachment (MODEST_MSG_VIEW_WINDOW (win), mime_part);
2741 modest_ui_actions_on_msg_recpt_activated (ModestMsgView *msgview,
2742 const gchar *address,
2745 /* g_message ("%s %s", __FUNCTION__, address); */
2749 on_save_to_drafts_cb (ModestMailOperation *mail_op,
2750 TnyMsg *saved_draft,
2753 ModestMsgEditWindow *edit_window;
2755 /* TODO: in hildon 2 we have to dim and undim the header views while we're saving */
2756 #ifndef MODEST_TOOLKIT_HILDON2
2757 ModestMainWindow *win;
2759 /* FIXME. Make the header view sensitive again. This is a
2760 * temporary hack. See modest_ui_actions_on_save_to_drafts()
2762 win = MODEST_MAIN_WINDOW(modest_window_mgr_get_main_window(
2763 modest_runtime_get_window_mgr(), FALSE));
2765 GtkWidget *hdrview = modest_main_window_get_child_widget(
2766 win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2767 if (hdrview) gtk_widget_set_sensitive(hdrview, TRUE);
2771 edit_window = MODEST_MSG_EDIT_WINDOW (user_data);
2773 /* Set draft is there was no error */
2774 if (!modest_mail_operation_get_error (mail_op))
2775 modest_msg_edit_window_set_draft (edit_window, saved_draft);
2777 g_object_unref(edit_window);
2781 enough_space_for_message (ModestMsgEditWindow *edit_window,
2784 TnyAccountStore *acc_store;
2785 guint64 available_disk, expected_size;
2790 acc_store = TNY_ACCOUNT_STORE (modest_runtime_get_account_store());
2791 available_disk = modest_utils_get_available_space (NULL);
2792 modest_msg_edit_window_get_parts_size (edit_window, &parts_count, &parts_size);
2793 expected_size = modest_tny_msg_estimate_size (data->plain_body,
2798 /* Double check: memory full condition or message too big */
2799 if (available_disk < MIN_FREE_SPACE ||
2800 expected_size > available_disk) {
2802 modest_platform_information_banner (NULL, NULL,
2803 _KR("cerm_device_memory_full"));
2808 * djcb: if we're in low-memory state, we only allow for
2809 * saving messages smaller than
2810 * MODEST_MAX_LOW_MEMORY_MESSAGE_SIZE (see modest-defs.h) this
2811 * should still allow for sending anything critical...
2813 if ((expected_size > MODEST_MAX_LOW_MEMORY_MESSAGE_SIZE) &&
2814 modest_platform_check_memory_low (MODEST_WINDOW(edit_window), TRUE))
2818 * djcb: we also make sure that the attachments are smaller than the max size
2819 * this is for the case where we'd try to forward a message with attachments
2820 * bigger than our max allowed size, or sending an message from drafts which
2821 * somehow got past our checks when attaching.
2823 if (expected_size > MODEST_MAX_ATTACHMENT_SIZE) {
2824 modest_platform_run_information_dialog (
2825 GTK_WINDOW(edit_window),
2826 _KR("memr_ib_operation_disabled"),
2835 modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edit_window)
2837 TnyTransportAccount *transport_account;
2838 ModestMailOperation *mail_operation;
2840 gchar *account_name, *from;
2841 ModestAccountMgr *account_mgr;
2842 gboolean had_error = FALSE;
2843 ModestMainWindow *win = NULL;
2845 g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window), FALSE);
2847 data = modest_msg_edit_window_get_msg_data (edit_window);
2850 if (!enough_space_for_message (edit_window, data)) {
2851 modest_msg_edit_window_free_msg_data (edit_window, data);
2855 account_name = g_strdup (data->account_name);
2856 account_mgr = modest_runtime_get_account_mgr();
2858 account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
2860 account_name = modest_account_mgr_get_default_account (account_mgr);
2861 if (!account_name) {
2862 g_printerr ("modest: no account found\n");
2863 modest_msg_edit_window_free_msg_data (edit_window, data);
2867 if (!strcmp (account_name, MODEST_LOCAL_FOLDERS_ACCOUNT_ID)) {
2868 account_name = g_strdup (data->account_name);
2872 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
2873 (modest_runtime_get_account_store (),
2875 TNY_ACCOUNT_TYPE_TRANSPORT));
2876 if (!transport_account) {
2877 g_printerr ("modest: no transport account found for '%s'\n", account_name);
2878 g_free (account_name);
2879 modest_msg_edit_window_free_msg_data (edit_window, data);
2882 from = modest_account_mgr_get_from_string (account_mgr, account_name);
2884 /* Create the mail operation */
2885 mail_operation = modest_mail_operation_new_with_error_handling (NULL, modest_ui_actions_disk_operations_error_handler,
2887 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
2889 modest_mail_operation_save_to_drafts (mail_operation,
2901 data->priority_flags,
2902 on_save_to_drafts_cb,
2903 g_object_ref(edit_window));
2905 #ifdef MODEST_TOOLKIT_HILDON2
2906 /* In hildon2 we always show the information banner on saving to drafts.
2907 * It will be a system information banner in this case.
2909 gchar *text = g_strdup_printf (_("mail_va_saved_to_drafts"), _("mcen_me_folder_drafts"));
2910 modest_platform_information_banner (NULL, NULL, text);
2913 /* Use the main window as the parent of the banner, if the
2914 main window does not exist it won't be shown, if the parent
2915 window exists then it's properly shown. We don't use the
2916 editor window because it could be closed (save to drafts
2917 could happen after closing the window */
2918 win = (ModestMainWindow *)
2919 modest_window_mgr_get_main_window( modest_runtime_get_window_mgr(), FALSE);
2921 gchar *text = g_strdup_printf (_("mail_va_saved_to_drafts"), _("mcen_me_folder_drafts"));
2922 modest_platform_information_banner (GTK_WIDGET (win), NULL, text);
2926 modest_msg_edit_window_set_modified (edit_window, FALSE);
2930 g_free (account_name);
2931 g_object_unref (G_OBJECT (transport_account));
2932 g_object_unref (G_OBJECT (mail_operation));
2934 modest_msg_edit_window_free_msg_data (edit_window, data);
2937 * If the drafts folder is selected then make the header view
2938 * insensitive while the message is being saved to drafts
2939 * (it'll be sensitive again in on_save_to_drafts_cb()). This
2940 * is not very clean but it avoids letting the drafts folder
2941 * in an inconsistent state: the user could edit the message
2942 * being saved and undesirable things would happen.
2943 * In the average case the user won't notice anything at
2944 * all. In the worst case (the user is editing a really big
2945 * file from Drafts) the header view will be insensitive
2946 * during the saving process (10 or 20 seconds, depending on
2947 * the message). Anyway this is just a quick workaround: once
2948 * we find a better solution it should be removed
2949 * See NB#65125 (commend #18) for details.
2951 if (!had_error && win != NULL) {
2952 ModestFolderView *view = MODEST_FOLDER_VIEW(modest_main_window_get_child_widget(
2953 win, MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW));
2955 TnyFolder *folder = TNY_FOLDER(modest_folder_view_get_selected(view));
2957 if (modest_tny_folder_is_local_folder(folder)) {
2958 TnyFolderType folder_type;
2959 folder_type = modest_tny_folder_get_local_or_mmc_folder_type(folder);
2960 if (folder_type == TNY_FOLDER_TYPE_DRAFTS) {
2961 GtkWidget *hdrview = modest_main_window_get_child_widget(
2962 win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2963 if (hdrview) gtk_widget_set_sensitive(hdrview, FALSE);
2967 if (folder != NULL) g_object_unref(folder);
2974 /* For instance, when clicking the Send toolbar button when editing a message: */
2976 modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
2978 TnyTransportAccount *transport_account = NULL;
2979 gboolean had_error = FALSE;
2981 ModestAccountMgr *account_mgr;
2982 gchar *account_name;
2984 ModestMailOperation *mail_operation;
2986 g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window), TRUE);
2988 if (!modest_msg_edit_window_check_names (edit_window, TRUE))
2991 data = modest_msg_edit_window_get_msg_data (edit_window);
2994 if (!enough_space_for_message (edit_window, data)) {
2995 modest_msg_edit_window_free_msg_data (edit_window, data);
2999 account_mgr = modest_runtime_get_account_mgr();
3000 account_name = g_strdup (data->account_name);
3002 account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
3005 account_name = modest_account_mgr_get_default_account (account_mgr);
3007 if (!account_name) {
3008 modest_msg_edit_window_free_msg_data (edit_window, data);
3009 /* Run account setup wizard */
3010 if (!modest_ui_actions_run_account_setup_wizard (MODEST_WINDOW(edit_window))) {
3015 /* Get the currently-active transport account for this modest account: */
3016 if (strcmp (account_name, MODEST_LOCAL_FOLDERS_ACCOUNT_ID) != 0) {
3018 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
3019 (modest_runtime_get_account_store (),
3020 account_name, TNY_ACCOUNT_TYPE_TRANSPORT));
3023 if (!transport_account) {
3024 modest_msg_edit_window_free_msg_data (edit_window, data);
3025 /* Run account setup wizard */
3026 if (!modest_ui_actions_run_account_setup_wizard(MODEST_WINDOW(edit_window)))
3031 /* Create the mail operation */
3032 from = modest_account_mgr_get_from_string (account_mgr, account_name);
3033 mail_operation = modest_mail_operation_new_with_error_handling (NULL, modest_ui_actions_disk_operations_error_handler, NULL, NULL);
3034 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
3036 modest_mail_operation_send_new_mail (mail_operation,
3048 data->priority_flags);
3050 if (modest_mail_operation_get_status (mail_operation) == MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS)
3051 modest_platform_information_banner (NULL, NULL, _("mcen_ib_outbox_waiting_to_be_sent"));
3054 if (modest_mail_operation_get_error (mail_operation) != NULL) {
3055 const GError *error = modest_mail_operation_get_error (mail_operation);
3056 if (error->domain == MODEST_MAIL_OPERATION_ERROR &&
3057 error->code == MODEST_MAIL_OPERATION_ERROR_INSTANCE_CREATION_FAILED) {
3058 g_warning ("%s failed: %s\n", __FUNCTION__, (modest_mail_operation_get_error (mail_operation))->message);
3059 modest_platform_information_banner (NULL, NULL, _CS("sfil_ni_not_enough_memory"));
3066 g_free (account_name);
3067 g_object_unref (G_OBJECT (transport_account));
3068 g_object_unref (G_OBJECT (mail_operation));
3070 modest_msg_edit_window_free_msg_data (edit_window, data);
3073 modest_msg_edit_window_set_sent (edit_window, TRUE);
3075 /* Save settings and close the window: */
3076 modest_ui_actions_on_close_window (NULL, MODEST_WINDOW (edit_window));
3083 modest_ui_actions_on_toggle_bold (GtkToggleAction *action,
3084 ModestMsgEditWindow *window)
3086 ModestMsgEditFormatState *format_state = NULL;
3088 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3089 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
3091 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3094 format_state = modest_msg_edit_window_get_format_state (window);
3095 g_return_if_fail (format_state != NULL);
3097 format_state->bold = gtk_toggle_action_get_active (action);
3098 modest_msg_edit_window_set_format_state (window, format_state);
3099 g_free (format_state);
3104 modest_ui_actions_on_toggle_italics (GtkToggleAction *action,
3105 ModestMsgEditWindow *window)
3107 ModestMsgEditFormatState *format_state = NULL;
3109 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3110 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
3112 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3115 format_state = modest_msg_edit_window_get_format_state (window);
3116 g_return_if_fail (format_state != NULL);
3118 format_state->italics = gtk_toggle_action_get_active (action);
3119 modest_msg_edit_window_set_format_state (window, format_state);
3120 g_free (format_state);
3125 modest_ui_actions_on_toggle_bullets (GtkToggleAction *action,
3126 ModestMsgEditWindow *window)
3128 ModestMsgEditFormatState *format_state = NULL;
3130 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3131 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
3133 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3136 format_state = modest_msg_edit_window_get_format_state (window);
3137 g_return_if_fail (format_state != NULL);
3139 format_state->bullet = gtk_toggle_action_get_active (action);
3140 modest_msg_edit_window_set_format_state (window, format_state);
3141 g_free (format_state);
3146 modest_ui_actions_on_change_justify (GtkRadioAction *action,
3147 GtkRadioAction *selected,
3148 ModestMsgEditWindow *window)
3150 ModestMsgEditFormatState *format_state = NULL;
3151 GtkJustification value;
3153 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3155 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3158 value = gtk_radio_action_get_current_value (selected);
3160 format_state = modest_msg_edit_window_get_format_state (window);
3161 g_return_if_fail (format_state != NULL);
3163 format_state->justification = value;
3164 modest_msg_edit_window_set_format_state (window, format_state);
3165 g_free (format_state);
3169 modest_ui_actions_on_select_editor_color (GtkAction *action,
3170 ModestMsgEditWindow *window)
3172 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3173 g_return_if_fail (GTK_IS_ACTION (action));
3175 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3178 modest_msg_edit_window_select_color (window);
3182 modest_ui_actions_on_select_editor_background_color (GtkAction *action,
3183 ModestMsgEditWindow *window)
3185 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3186 g_return_if_fail (GTK_IS_ACTION (action));
3188 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3191 modest_msg_edit_window_select_background_color (window);
3195 modest_ui_actions_on_insert_image (GObject *object,
3196 ModestMsgEditWindow *window)
3198 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3201 if (modest_platform_check_memory_low (MODEST_WINDOW(window), TRUE))
3204 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3207 modest_msg_edit_window_insert_image (window);
3211 modest_ui_actions_on_attach_file (GtkAction *action,
3212 ModestMsgEditWindow *window)
3214 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3215 g_return_if_fail (GTK_IS_ACTION (action));
3217 if (modest_platform_check_memory_low (MODEST_WINDOW(window), TRUE))
3220 modest_msg_edit_window_offer_attach_file (window);
3224 modest_ui_actions_on_remove_attachments (GtkAction *action,
3225 ModestMsgEditWindow *window)
3227 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3229 modest_msg_edit_window_remove_attachments (window, NULL);
3233 #ifndef MODEST_TOOLKIT_GTK
3238 TnyFolderStore *folder;
3239 } CreateFolderHelper;
3242 show_create_folder_in_timeout (gpointer data)
3244 CreateFolderHelper *helper = (CreateFolderHelper *) data;
3246 /* Remove the timeout ASAP, we can not wait until the dialog
3247 is shown because it could take a lot of time and so the
3248 timeout could be called twice or more times */
3249 g_source_remove (helper->handler);
3251 gdk_threads_enter ();
3252 do_create_folder (helper->win, helper->folder, helper->name);
3253 gdk_threads_leave ();
3255 g_object_unref (helper->win);
3256 g_object_unref (helper->folder);
3257 g_free (helper->name);
3258 g_slice_free (CreateFolderHelper, helper);
3265 do_create_folder_cb (ModestMailOperation *mail_op,
3266 TnyFolderStore *parent_folder,
3267 TnyFolder *new_folder,
3270 gchar *suggested_name = (gchar *) user_data;
3271 GtkWindow *source_win = (GtkWindow *) modest_mail_operation_get_source (mail_op);
3273 if (modest_mail_operation_get_error (mail_op)) {
3275 /* Show an error. If there was some problem writing to
3276 disk, show it, otherwise show the generic folder
3277 create error. We do it here and not in an error
3278 handler because the call to do_create_folder will
3279 stop the main loop in a gtk_dialog_run and then,
3280 the message won't be shown until that dialog is
3282 modest_ui_actions_disk_operations_error_handler (mail_op,
3283 _("mail_in_ui_folder_create_error"));
3285 /* Try again. Do *NOT* show any error because the mail
3286 operations system will do it for us because we
3287 created the mail_op with new_with_error_handler */
3288 #ifndef MODEST_TOOLKIT_GTK
3289 CreateFolderHelper *helper;
3290 helper = g_slice_new0 (CreateFolderHelper);
3291 helper->name = g_strdup (suggested_name);
3292 helper->folder = g_object_ref (parent_folder);
3293 helper->win = g_object_ref (source_win);
3295 /* Ugly but neccesary stuff. The problem is that the
3296 dialog when is shown calls a function that destroys
3297 all the temporary windows, so the banner is
3299 helper->handler = g_timeout_add (2000, show_create_folder_in_timeout, helper);
3301 do_create_folder (source_win, parent_folder, (const gchar *) suggested_name);
3304 /* the 'source_win' is either the ModestMainWindow, or the 'Move to folder'-dialog
3305 * FIXME: any other? */
3306 GtkWidget *folder_view;
3308 if (MODEST_IS_MAIN_WINDOW(source_win))
3310 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (source_win),
3311 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3313 folder_view = GTK_WIDGET(g_object_get_data (G_OBJECT (source_win),
3314 MODEST_MOVE_TO_DIALOG_FOLDER_VIEW));
3316 /* Select the newly created folder. It could happen
3317 that the widget is no longer there (i.e. the window
3318 has been destroyed, so we need to check this */
3320 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view),
3322 g_object_unref (new_folder);
3324 /* Free. Note that the first time it'll be NULL so noop */
3325 g_free (suggested_name);
3326 g_object_unref (source_win);
3331 TnyFolderStore *parent;
3332 } CreateFolderConnect;
3335 do_create_folder_performer (gboolean canceled,
3337 GtkWindow *parent_window,
3338 TnyAccount *account,
3341 CreateFolderConnect *helper = (CreateFolderConnect *) user_data;
3342 ModestMailOperation *mail_op;
3344 if (canceled || err) {
3345 /* In memory full conditions we could get this error here */
3346 check_memory_full_error ((GtkWidget *) parent_window, err);
3350 mail_op = modest_mail_operation_new ((GObject *) parent_window);
3351 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
3353 modest_mail_operation_create_folder (mail_op,
3355 (const gchar *) helper->folder_name,
3356 do_create_folder_cb,
3357 g_strdup (helper->folder_name));
3358 g_object_unref (mail_op);
3362 g_object_unref (helper->parent);
3363 if (helper->folder_name)
3364 g_free (helper->folder_name);
3365 g_slice_free (CreateFolderConnect, helper);
3370 do_create_folder (GtkWindow *parent_window,
3371 TnyFolderStore *suggested_parent,
3372 const gchar *suggested_name)
3375 gchar *folder_name = NULL;
3376 TnyFolderStore *parent_folder = NULL;
3378 result = modest_platform_run_new_folder_dialog (GTK_WINDOW (parent_window),
3380 (gchar *) suggested_name,
3384 if (result == GTK_RESPONSE_ACCEPT && parent_folder) {
3385 CreateFolderConnect *helper = (CreateFolderConnect *) g_slice_new0 (CreateFolderHelper);
3386 helper->folder_name = g_strdup (folder_name);
3387 helper->parent = g_object_ref (parent_folder);
3389 modest_platform_connect_if_remote_and_perform (GTK_WINDOW (parent_window),
3392 do_create_folder_performer,
3397 g_free (folder_name);
3399 g_object_unref (parent_folder);
3403 modest_ui_actions_create_folder(GtkWidget *parent_window,
3404 GtkWidget *folder_view)
3406 TnyFolderStore *parent_folder;
3408 #ifdef MODEST_TOOLKIT_HILDON2
3409 ModestTnyAccountStore *acc_store;
3411 acc_store = modest_runtime_get_account_store ();
3413 parent_folder = (TnyFolderStore *)
3414 modest_tny_account_store_get_local_folders_account (acc_store);
3416 parent_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
3420 do_create_folder (GTK_WINDOW (parent_window), parent_folder, NULL);
3424 modest_ui_actions_on_new_folder (GtkAction *action, ModestWindow *window)
3427 g_return_if_fail (MODEST_IS_WINDOW(window));
3429 if (MODEST_IS_MAIN_WINDOW (window)) {
3430 GtkWidget *folder_view;
3432 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (window),
3433 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3437 modest_ui_actions_create_folder (GTK_WIDGET (window), folder_view);
3438 #ifdef MODEST_TOOLKIT_HILDON2
3439 } else if (MODEST_IS_FOLDER_WINDOW (window)) {
3440 GtkWidget *folder_view;
3442 folder_view = GTK_WIDGET (modest_folder_window_get_folder_view (MODEST_FOLDER_WINDOW (window)));
3443 modest_ui_actions_create_folder (GTK_WIDGET (window), folder_view);
3446 g_assert_not_reached ();
3451 modest_ui_actions_rename_folder_error_handler (ModestMailOperation *mail_op,
3454 const GError *error = NULL;
3455 const gchar *message = NULL;
3457 /* Get error message */
3458 error = modest_mail_operation_get_error (mail_op);
3460 g_return_if_reached ();
3462 if (error->domain == MODEST_MAIL_OPERATION_ERROR &&
3463 error->code == MODEST_MAIL_OPERATION_ERROR_FOLDER_EXISTS) {
3464 message = _CS("ckdg_ib_folder_already_exists");
3465 } else if (error->domain == TNY_ERROR_DOMAIN &&
3466 error->code == TNY_SERVICE_ERROR_STATE) {
3467 /* This means that the folder is already in use (a
3468 message is opened for example */
3469 message = _("emev_ni_internal_error");
3471 message = _CS("ckdg_ib_unable_to_rename");
3474 /* We don't set a parent for the dialog because the dialog
3475 will be destroyed so the banner won't appear */
3476 modest_platform_information_banner (NULL, NULL, message);
3480 TnyFolderStore *folder;
3485 on_rename_folder_cb (ModestMailOperation *mail_op,
3486 TnyFolder *new_folder,
3489 ModestFolderView *folder_view;
3491 /* If the window was closed when renaming a folder, or if
3492 * it's not a main window this will happen */
3493 if (!MODEST_IS_FOLDER_VIEW (user_data))
3496 folder_view = MODEST_FOLDER_VIEW (user_data);
3497 /* Note that if the rename fails new_folder will be NULL */
3499 modest_folder_view_select_folder (folder_view, new_folder, FALSE);
3501 modest_folder_view_select_first_inbox_or_local (folder_view);
3503 gtk_widget_grab_focus (GTK_WIDGET (folder_view));
3507 on_rename_folder_performer (gboolean canceled,
3509 GtkWindow *parent_window,
3510 TnyAccount *account,
3513 ModestMailOperation *mail_op = NULL;
3514 GtkTreeSelection *sel = NULL;
3515 GtkWidget *folder_view = NULL;
3516 RenameFolderInfo *data = (RenameFolderInfo*)user_data;
3518 if (canceled || err) {
3519 /* In memory full conditions we could get this error here */
3520 check_memory_full_error ((GtkWidget *) parent_window, err);
3524 modest_mail_operation_new_with_error_handling (G_OBJECT(parent_window),
3525 modest_ui_actions_rename_folder_error_handler,
3526 parent_window, NULL);
3528 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
3531 if (MODEST_IS_MAIN_WINDOW(parent_window)) {
3533 folder_view = modest_main_window_get_child_widget (
3534 MODEST_MAIN_WINDOW (parent_window),
3535 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3537 #ifdef MODEST_TOOLKIT_HILDON2
3538 else if (MODEST_IS_FOLDER_WINDOW (parent_window)) {
3539 ModestFolderWindow *folder_window = (ModestFolderWindow *) parent_window;
3540 folder_view = GTK_WIDGET (modest_folder_window_get_folder_view (folder_window));
3544 /* Clear the folders view */
3545 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_view));
3546 gtk_tree_selection_unselect_all (sel);
3548 /* Actually rename the folder */
3549 modest_mail_operation_rename_folder (mail_op,
3550 TNY_FOLDER (data->folder),
3551 (const gchar *) (data->new_name),
3552 on_rename_folder_cb,
3554 g_object_unref (mail_op);
3557 g_object_unref (data->folder);
3558 g_free (data->new_name);
3563 modest_ui_actions_on_rename_folder (GtkAction *action,
3564 ModestWindow *window)
3566 modest_ui_actions_on_edit_mode_rename_folder (window);
3570 modest_ui_actions_on_edit_mode_rename_folder (ModestWindow *window)
3572 TnyFolderStore *folder;
3573 GtkWidget *folder_view;
3574 gboolean do_rename = TRUE;
3576 g_return_val_if_fail (MODEST_IS_WINDOW(window), FALSE);
3578 if (MODEST_IS_MAIN_WINDOW (window)) {
3579 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (window),
3580 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3584 #ifdef MODEST_TOOLKIT_HILDON2
3585 } else if (MODEST_IS_FOLDER_WINDOW (window)) {
3586 folder_view = GTK_WIDGET (modest_folder_window_get_folder_view (MODEST_FOLDER_WINDOW (window)));
3592 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
3597 if (TNY_IS_FOLDER (folder)) {
3598 gchar *folder_name = NULL;
3600 const gchar *current_name;
3601 TnyFolderStore *parent;
3603 current_name = tny_folder_get_name (TNY_FOLDER (folder));
3604 parent = tny_folder_get_folder_store (TNY_FOLDER (folder));
3605 response = modest_platform_run_rename_folder_dialog (GTK_WINDOW (window),
3606 parent, current_name,
3608 g_object_unref (parent);
3610 if (response != GTK_RESPONSE_ACCEPT || strlen (folder_name) == 0) {
3613 RenameFolderInfo *rename_folder_data = g_new0 (RenameFolderInfo, 1);
3614 rename_folder_data->folder = g_object_ref (folder);
3615 rename_folder_data->new_name = folder_name;
3616 modest_platform_connect_if_remote_and_perform (GTK_WINDOW(window), TRUE,
3617 folder, on_rename_folder_performer, rename_folder_data);
3620 g_object_unref (folder);
3625 modest_ui_actions_delete_folder_error_handler (ModestMailOperation *mail_op,
3628 GObject *win = modest_mail_operation_get_source (mail_op);
3630 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
3631 _("mail_in_ui_folder_delete_error"),
3633 g_object_unref (win);
3637 TnyFolderStore *folder;
3638 gboolean move_to_trash;
3642 on_delete_folder_cb (gboolean canceled,
3644 GtkWindow *parent_window,
3645 TnyAccount *account,
3648 DeleteFolderInfo *info = (DeleteFolderInfo*) user_data;
3649 GtkWidget *folder_view;
3650 ModestMailOperation *mail_op;
3651 GtkTreeSelection *sel;
3653 if (!MODEST_IS_WINDOW(parent_window) || canceled || (err!=NULL)) {
3654 g_object_unref (G_OBJECT (info->folder));
3659 if (MODEST_IS_MAIN_WINDOW (parent_window)) {
3660 folder_view = modest_main_window_get_child_widget (
3661 MODEST_MAIN_WINDOW (parent_window),
3662 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3663 #ifdef MODEST_TOOLKIT_HILDON2
3664 } else if (MODEST_IS_FOLDER_WINDOW (parent_window)) {
3665 folder_view = GTK_WIDGET (modest_folder_window_get_folder_view (MODEST_FOLDER_WINDOW (parent_window)));
3668 g_object_unref (G_OBJECT (info->folder));
3673 /* Unselect the folder before deleting it to free the headers */
3674 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_view));
3675 gtk_tree_selection_unselect_all (sel);
3677 /* Create the mail operation */
3679 modest_mail_operation_new_with_error_handling (G_OBJECT(parent_window),
3680 modest_ui_actions_delete_folder_error_handler,
3683 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
3685 modest_mail_operation_remove_folder (mail_op, TNY_FOLDER (info->folder), info->move_to_trash);
3687 modest_folder_view_select_first_inbox_or_local (MODEST_FOLDER_VIEW (folder_view));
3689 g_object_unref (G_OBJECT (mail_op));
3690 g_object_unref (G_OBJECT (info->folder));
3695 delete_folder (ModestWindow *window, gboolean move_to_trash)
3697 TnyFolderStore *folder;
3698 GtkWidget *folder_view;
3702 g_return_val_if_fail (MODEST_IS_WINDOW(window), FALSE);
3704 if (MODEST_IS_MAIN_WINDOW (window)) {
3706 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (window),
3707 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3708 #ifdef MODEST_TOOLKIT_HILDON2
3709 } else if (MODEST_IS_FOLDER_WINDOW (window)) {
3710 folder_view = GTK_WIDGET (modest_folder_window_get_folder_view (MODEST_FOLDER_WINDOW (window)));
3718 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
3723 /* Show an error if it's an account */
3724 if (!TNY_IS_FOLDER (folder)) {
3725 modest_platform_run_information_dialog (GTK_WINDOW (window),
3726 _("mail_in_ui_folder_delete_error"),
3728 g_object_unref (G_OBJECT (folder));
3733 message = g_strdup_printf (_("mcen_nc_delete_folder_text"),
3734 tny_folder_get_name (TNY_FOLDER (folder)));
3735 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (window),
3736 (const gchar *) message);
3739 if (response == GTK_RESPONSE_OK) {
3740 DeleteFolderInfo *info;
3741 info = g_new0(DeleteFolderInfo, 1);
3742 info->folder = folder;
3743 info->move_to_trash = move_to_trash;
3744 g_object_ref (G_OBJECT (info->folder));
3745 TnyAccount *account = tny_folder_get_account (TNY_FOLDER (folder));
3746 modest_platform_connect_if_remote_and_perform (GTK_WINDOW (window),
3748 TNY_FOLDER_STORE (account),
3749 on_delete_folder_cb, info);
3750 g_object_unref (account);
3755 g_object_unref (G_OBJECT (folder));
3759 modest_ui_actions_on_delete_folder (GtkAction *action,
3760 ModestWindow *window)
3762 modest_ui_actions_on_edit_mode_delete_folder (window);
3766 modest_ui_actions_on_edit_mode_delete_folder (ModestWindow *window)
3768 g_return_val_if_fail (MODEST_IS_WINDOW(window), TRUE);
3770 return delete_folder (window, FALSE);
3774 modest_ui_actions_on_move_folder_to_trash_folder (GtkAction *action, ModestMainWindow *main_window)
3776 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
3778 delete_folder (MODEST_WINDOW (main_window), TRUE);
3782 typedef struct _PasswordDialogFields {
3783 GtkWidget *username;
3784 GtkWidget *password;
3786 } PasswordDialogFields;
3789 password_dialog_check_field (GtkEditable *editable,
3790 PasswordDialogFields *fields)
3793 gboolean any_value_empty = FALSE;
3795 #ifdef MODEST_TOOLKIT_HILDON2
3796 value = hildon_entry_get_text (HILDON_ENTRY (fields->username));
3798 value = gtk_entry_get_text (GTK_ENTRY (fields->username));
3800 if ((value == NULL) || value[0] == '\0') {
3801 any_value_empty = TRUE;
3803 #ifdef MODEST_TOOLKIT_HILDON2
3804 value = hildon_entry_get_text (HILDON_ENTRY (fields->password));
3806 value = gtk_entry_get_text (GTK_ENTRY (fields->password));
3808 if ((value == NULL) || value[0] == '\0') {
3809 any_value_empty = TRUE;
3811 gtk_dialog_set_response_sensitive (GTK_DIALOG (fields->dialog), GTK_RESPONSE_ACCEPT, !any_value_empty);
3815 modest_ui_actions_on_password_requested (TnyAccountStore *account_store,
3816 const gchar* server_account_name,
3821 ModestMainWindow *main_window)
3823 g_return_if_fail(server_account_name);
3824 gboolean completed = FALSE;
3825 PasswordDialogFields *fields = NULL;
3827 /* Initalize output parameters: */
3834 #ifndef MODEST_TOOLKIT_GTK
3835 /* Maemo uses a different (awkward) button order,
3836 * It should probably just use gtk_alternative_dialog_button_order ().
3838 #ifdef MODEST_TOOLKIT_HILDON2
3840 gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
3843 _HL("wdgt_bd_done"),
3844 GTK_RESPONSE_ACCEPT,
3848 gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
3851 _("mcen_bd_dialog_ok"),
3852 GTK_RESPONSE_ACCEPT,
3853 _("mcen_bd_dialog_cancel"),
3854 GTK_RESPONSE_REJECT,
3856 #endif /* MODEST_TOOLKIT_HILDON2 */
3859 gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
3863 GTK_RESPONSE_REJECT,
3865 GTK_RESPONSE_ACCEPT,
3867 #endif /* MODEST_TOOLKIT_GTK */
3869 modest_window_mgr_set_modal (modest_runtime_get_window_mgr(), GTK_WINDOW (dialog), NULL);
3871 gchar *server_name = modest_account_mgr_get_server_account_hostname (
3872 modest_runtime_get_account_mgr(), server_account_name);
3873 if (!server_name) {/* This happened once, though I don't know why. murrayc. */
3874 g_warning("%s: Could not get server name for server account '%s'", __FUNCTION__, server_account_name);
3877 gtk_widget_destroy (dialog);
3881 gchar *txt = g_strdup_printf (_("mail_ia_password_info"), server_name);
3882 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), gtk_label_new(txt),
3885 g_free (server_name);
3889 gchar *initial_username = modest_account_mgr_get_server_account_username (
3890 modest_runtime_get_account_mgr(), server_account_name);
3892 #ifdef MODEST_TOOLKIT_HILDON2
3893 GtkWidget *entry_username = hildon_entry_new (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
3894 if (initial_username)
3895 hildon_entry_set_text (HILDON_ENTRY (entry_username), initial_username);
3897 GtkWidget *entry_username = gtk_entry_new ();
3898 if (initial_username)
3899 gtk_entry_set_text (GTK_ENTRY (entry_username), initial_username);
3901 /* Dim this if a connection has ever succeeded with this username,
3902 * as per the UI spec: */
3903 /* const gboolean username_known = */
3904 /* modest_account_mgr_get_server_account_username_has_succeeded( */
3905 /* modest_runtime_get_account_mgr(), server_account_name); */
3906 /* gtk_widget_set_sensitive (entry_username, !username_known); */
3908 /* We drop the username sensitive code and disallow changing it here
3909 * as tinymail does not support really changing the username in the callback
3911 gtk_widget_set_sensitive (entry_username, FALSE);
3913 #ifndef MODEST_TOOLKIT_GTK
3914 /* Auto-capitalization is the default, so let's turn it off: */
3915 hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_username), HILDON_GTK_INPUT_MODE_FULL);
3917 /* Create a size group to be used by all captions.
3918 * Note that HildonCaption does not create a default size group if we do not specify one.
3919 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
3920 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
3922 #ifdef MODEST_TOOLKIT_HILDON2
3923 GtkWidget *caption = modest_maemo_utils_create_captioned (sizegroup, NULL,
3924 _("mail_fi_username"), FALSE,
3927 GtkWidget *caption = hildon_caption_new (sizegroup,
3928 _("mail_fi_username"), entry_username, NULL, HILDON_CAPTION_MANDATORY);
3930 gtk_widget_show (entry_username);
3931 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
3932 FALSE, FALSE, MODEST_MARGIN_HALF);
3933 gtk_widget_show (caption);
3935 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry_username,
3937 #endif /* !MODEST_TOOLKIT_GTK */
3940 #ifdef MODEST_TOOLKIT_HILDON2
3941 GtkWidget *entry_password = hildon_entry_new (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
3943 GtkWidget *entry_password = gtk_entry_new ();
3945 gtk_entry_set_visibility (GTK_ENTRY(entry_password), FALSE);
3946 /* gtk_entry_set_invisible_char (GTK_ENTRY(entry_password), "*"); */
3948 #ifndef MODEST_TOOLKIT_GTK
3949 /* Auto-capitalization is the default, so let's turn it off: */
3950 hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_password),
3951 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
3953 #ifdef MODEST_TOOLKIT_HILDON2
3954 caption = modest_maemo_utils_create_captioned (sizegroup, NULL,
3955 _("mail_fi_password"), FALSE,
3958 caption = hildon_caption_new (sizegroup,
3959 _("mail_fi_password"), entry_password, NULL, HILDON_CAPTION_MANDATORY);
3961 gtk_widget_show (entry_password);
3962 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
3963 FALSE, FALSE, MODEST_MARGIN_HALF);
3964 gtk_widget_show (caption);
3965 g_object_unref (sizegroup);
3967 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry_password,
3969 #endif /* !MODEST_TOOLKIT_GTK */
3971 if (initial_username != NULL)
3972 gtk_widget_grab_focus (GTK_WIDGET (entry_password));
3974 /* This is not in the Maemo UI spec:
3975 remember_pass_check = gtk_check_button_new_with_label (_("Remember password"));
3976 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), remember_pass_check,
3980 fields = g_slice_new0 (PasswordDialogFields);
3981 fields->username = entry_username;
3982 fields->password = entry_password;
3983 fields->dialog = dialog;
3985 g_signal_connect (entry_username, "changed", G_CALLBACK (password_dialog_check_field), fields);
3986 g_signal_connect (entry_password, "changed", G_CALLBACK (password_dialog_check_field), fields);
3987 password_dialog_check_field (NULL, fields);
3989 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
3991 while (!completed) {
3993 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
3995 #ifdef MODEST_TOOLKIT_HILDON2
3996 *username = g_strdup (hildon_entry_get_text (HILDON_ENTRY(entry_username)));
3998 *username = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_username)));
4001 /* Note that an empty field becomes the "" string */
4002 if (*username && strlen (*username) > 0) {
4003 modest_account_mgr_set_server_account_username (modest_runtime_get_account_mgr(),
4004 server_account_name,
4008 const gboolean username_was_changed =
4009 (strcmp (*username, initial_username) != 0);
4010 if (username_was_changed) {
4011 g_warning ("%s: tinymail does not yet support changing the "
4012 "username in the get_password() callback.\n", __FUNCTION__);
4018 modest_platform_information_banner (GTK_WIDGET (dialog), NULL,
4019 _("mcen_ib_username_pw_incorrect"));
4025 #ifdef MODEST_TOOLKIT_HILDON2
4026 *password = g_strdup (hildon_entry_get_text (HILDON_ENTRY(entry_password)));
4028 *password = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_password)));
4031 /* We do not save the password in the configuration,
4032 * because this function is only called for passwords that should
4033 * not be remembered:
4034 modest_server_account_set_password (
4035 modest_runtime_get_account_mgr(), server_account_name,
4042 #ifndef MODEST_TOOLKIT_HILDON2
4043 /* Set parent to NULL or the banner will disappear with its parent dialog */
4044 modest_platform_information_banner(NULL, NULL, _("mail_ib_login_cancelled"));
4056 /* This is not in the Maemo UI spec:
4057 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (remember_pass_check)))
4063 g_free (initial_username);
4064 gtk_widget_destroy (dialog);
4065 g_slice_free (PasswordDialogFields, fields);
4067 /* printf ("DEBUG: %s: cancel=%d\n", __FUNCTION__, *cancel); */
4071 modest_ui_actions_on_cut (GtkAction *action,
4072 ModestWindow *window)
4074 GtkWidget *focused_widget;
4075 GtkClipboard *clipboard;
4077 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
4078 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
4079 if (GTK_IS_EDITABLE (focused_widget)) {
4080 gtk_editable_cut_clipboard (GTK_EDITABLE(focused_widget));
4081 gtk_clipboard_set_can_store (clipboard, NULL, 0);
4082 gtk_clipboard_store (clipboard);
4083 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
4084 GtkTextBuffer *buffer;
4086 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
4087 if (modest_text_utils_buffer_selection_is_valid (buffer)) {
4088 gtk_text_buffer_cut_clipboard (buffer, clipboard, TRUE);
4089 gtk_clipboard_set_can_store (clipboard, NULL, 0);
4090 gtk_clipboard_store (clipboard);
4092 } else if (MODEST_IS_HEADER_VIEW (focused_widget)) {
4093 TnyList *header_list = modest_header_view_get_selected_headers (
4094 MODEST_HEADER_VIEW (focused_widget));
4095 gboolean continue_download = FALSE;
4096 gint num_of_unc_msgs;
4098 num_of_unc_msgs = header_list_count_uncached_msgs(header_list);
4100 if (num_of_unc_msgs) {
4101 TnyAccount *account = get_account_from_header_list (header_list);
4103 continue_download = connect_to_get_msg (window, num_of_unc_msgs, account);
4104 g_object_unref (account);
4108 if (num_of_unc_msgs == 0 || continue_download) {
4109 /* modest_platform_information_banner (
4110 NULL, NULL, _CS("mcen_ib_getting_items"));*/
4111 modest_header_view_cut_selection (
4112 MODEST_HEADER_VIEW (focused_widget));
4115 g_object_unref (header_list);
4116 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
4117 modest_folder_view_cut_selection (MODEST_FOLDER_VIEW (focused_widget));
4122 modest_ui_actions_on_copy (GtkAction *action,
4123 ModestWindow *window)
4125 GtkClipboard *clipboard;
4126 GtkWidget *focused_widget;
4127 gboolean copied = TRUE;
4129 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
4130 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
4132 if (GTK_IS_LABEL (focused_widget)) {
4134 selection = modest_text_utils_label_get_selection (GTK_LABEL (focused_widget));
4135 gtk_clipboard_set_text (clipboard, selection, -1);
4137 gtk_clipboard_set_can_store (clipboard, NULL, 0);
4138 gtk_clipboard_store (clipboard);
4139 } else if (GTK_IS_EDITABLE (focused_widget)) {
4140 gtk_editable_copy_clipboard (GTK_EDITABLE(focused_widget));
4141 gtk_clipboard_set_can_store (clipboard, NULL, 0);
4142 gtk_clipboard_store (clipboard);
4143 } else if (GTK_IS_HTML (focused_widget)) {
4146 sel = gtk_html_get_selection_html (GTK_HTML (focused_widget), &len);
4147 if ((sel == NULL) || (sel[0] == '\0')) {
4150 gtk_html_copy (GTK_HTML (focused_widget));
4151 gtk_clipboard_set_can_store (clipboard, NULL, 0);
4152 gtk_clipboard_store (clipboard);
4154 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
4155 GtkTextBuffer *buffer;
4156 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
4157 if (modest_text_utils_buffer_selection_is_valid (buffer)) {
4158 gtk_text_buffer_copy_clipboard (buffer, clipboard);
4159 gtk_clipboard_set_can_store (clipboard, NULL, 0);
4160 gtk_clipboard_store (clipboard);
4162 } else if (MODEST_IS_HEADER_VIEW (focused_widget)) {
4163 TnyList *header_list = modest_header_view_get_selected_headers (
4164 MODEST_HEADER_VIEW (focused_widget));
4165 gboolean continue_download = FALSE;
4166 gint num_of_unc_msgs;
4168 num_of_unc_msgs = header_list_count_uncached_msgs(header_list);
4170 if (num_of_unc_msgs) {
4171 TnyAccount *account = get_account_from_header_list (header_list);
4173 continue_download = connect_to_get_msg (window, num_of_unc_msgs, account);
4174 g_object_unref (account);
4178 if (num_of_unc_msgs == 0 || continue_download) {
4179 modest_platform_information_banner (
4180 NULL, NULL, _CS("mcen_ib_getting_items"));
4181 modest_header_view_copy_selection (
4182 MODEST_HEADER_VIEW (focused_widget));
4186 g_object_unref (header_list);
4188 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
4189 modest_folder_view_copy_selection (MODEST_FOLDER_VIEW (focused_widget));
4192 /* Show information banner if there was a copy to clipboard */
4194 modest_platform_information_banner (
4195 NULL, NULL, _CS("ecoc_ib_edwin_copied"));
4199 modest_ui_actions_on_undo (GtkAction *action,
4200 ModestWindow *window)
4202 ModestEmailClipboard *clipboard = NULL;
4204 if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
4205 modest_msg_edit_window_undo (MODEST_MSG_EDIT_WINDOW (window));
4206 } else if (MODEST_IS_MAIN_WINDOW (window)) {
4207 /* Clear clipboard source */
4208 clipboard = modest_runtime_get_email_clipboard ();
4209 modest_email_clipboard_clear (clipboard);
4212 g_return_if_reached ();
4217 modest_ui_actions_on_redo (GtkAction *action,
4218 ModestWindow *window)
4220 if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
4221 modest_msg_edit_window_redo (MODEST_MSG_EDIT_WINDOW (window));
4224 g_return_if_reached ();
4230 destroy_information_note (ModestMailOperation *mail_op,
4233 /* destroy information note */
4234 gtk_widget_destroy (GTK_WIDGET(user_data));
4238 destroy_folder_information_note (ModestMailOperation *mail_op,
4239 TnyFolder *new_folder,
4242 /* destroy information note */
4243 gtk_widget_destroy (GTK_WIDGET(user_data));
4248 paste_as_attachment_free (gpointer data)
4250 PasteAsAttachmentHelper *helper = (PasteAsAttachmentHelper *) data;
4252 if (helper->banner) {
4253 gtk_widget_destroy (helper->banner);
4254 g_object_unref (helper->banner);
4260 paste_msg_as_attachment_cb (ModestMailOperation *mail_op,
4265 PasteAsAttachmentHelper *helper = (PasteAsAttachmentHelper *) userdata;
4266 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (helper->window));
4271 modest_msg_edit_window_add_part (MODEST_MSG_EDIT_WINDOW (helper->window), TNY_MIME_PART (msg));
4276 modest_ui_actions_on_paste (GtkAction *action,
4277 ModestWindow *window)
4279 GtkWidget *focused_widget = NULL;
4280 GtkWidget *inf_note = NULL;
4281 ModestMailOperation *mail_op = NULL;
4283 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
4284 if (GTK_IS_EDITABLE (focused_widget)) {
4285 gtk_editable_paste_clipboard (GTK_EDITABLE(focused_widget));
4286 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
4287 ModestEmailClipboard *e_clipboard = NULL;
4288 e_clipboard = modest_runtime_get_email_clipboard ();
4289 if (modest_email_clipboard_cleared (e_clipboard)) {
4290 GtkTextBuffer *buffer;
4291 GtkClipboard *clipboard;
4293 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
4294 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
4295 gtk_text_buffer_paste_clipboard (buffer, clipboard, NULL, TRUE);
4296 } else if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
4297 ModestMailOperation *mail_op;
4298 TnyFolder *src_folder = NULL;
4299 TnyList *data = NULL;
4301 PasteAsAttachmentHelper *helper = g_new0 (PasteAsAttachmentHelper, 1);
4302 helper->window = MODEST_MSG_EDIT_WINDOW (window);
4303 helper->banner = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
4304 _CS("ckct_nw_pasting"));
4305 modest_email_clipboard_get_data (e_clipboard, &src_folder, &data, &delete);
4306 mail_op = modest_mail_operation_new (G_OBJECT (window));
4307 if (helper->banner != NULL) {
4308 g_object_ref (G_OBJECT (helper->banner));
4309 gtk_widget_show (GTK_WIDGET (helper->banner));
4313 modest_mail_operation_get_msgs_full (mail_op,
4315 (GetMsgAsyncUserCallback) paste_msg_as_attachment_cb,
4317 paste_as_attachment_free);
4321 g_object_unref (data);
4323 g_object_unref (src_folder);
4326 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
4327 ModestEmailClipboard *clipboard = NULL;
4328 TnyFolder *src_folder = NULL;
4329 TnyFolderStore *folder_store = NULL;
4330 TnyList *data = NULL;
4331 gboolean delete = FALSE;
4333 /* Check clipboard source */
4334 clipboard = modest_runtime_get_email_clipboard ();
4335 if (modest_email_clipboard_cleared (clipboard))
4338 /* Get elements to paste */
4339 modest_email_clipboard_get_data (clipboard, &src_folder, &data, &delete);
4341 /* Create a new mail operation */
4342 mail_op = modest_mail_operation_new (G_OBJECT(window));
4344 /* Get destination folder */
4345 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (focused_widget));
4347 /* transfer messages */
4351 /* Ask for user confirmation */
4353 modest_ui_actions_msgs_move_to_confirmation (window,
4354 TNY_FOLDER (folder_store),
4358 if (response == GTK_RESPONSE_OK) {
4359 /* Launch notification */
4360 inf_note = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
4361 _CS("ckct_nw_pasting"));
4362 if (inf_note != NULL) {
4363 gtk_window_set_modal (GTK_WINDOW(inf_note), FALSE);
4364 gtk_widget_show (GTK_WIDGET(inf_note));
4367 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
4368 modest_mail_operation_xfer_msgs (mail_op,
4370 TNY_FOLDER (folder_store),
4372 destroy_information_note,
4375 g_object_unref (mail_op);
4378 } else if (src_folder != NULL) {
4379 /* Launch notification */
4380 inf_note = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
4381 _CS("ckct_nw_pasting"));
4382 if (inf_note != NULL) {
4383 gtk_window_set_modal (GTK_WINDOW(inf_note), FALSE);
4384 gtk_widget_show (GTK_WIDGET(inf_note));
4387 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
4388 modest_mail_operation_xfer_folder (mail_op,
4392 destroy_folder_information_note,
4398 g_object_unref (data);
4399 if (src_folder != NULL)
4400 g_object_unref (src_folder);
4401 if (folder_store != NULL)
4402 g_object_unref (folder_store);
4408 modest_ui_actions_on_select_all (GtkAction *action,
4409 ModestWindow *window)
4411 GtkWidget *focused_widget;
4413 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
4414 if (MODEST_IS_ATTACHMENTS_VIEW (focused_widget)) {
4415 modest_attachments_view_select_all (MODEST_ATTACHMENTS_VIEW (focused_widget));
4416 } else if (GTK_IS_LABEL (focused_widget)) {
4417 gtk_label_select_region (GTK_LABEL (focused_widget), 0, -1);
4418 } else if (GTK_IS_EDITABLE (focused_widget)) {
4419 gtk_editable_select_region (GTK_EDITABLE(focused_widget), 0, -1);
4420 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
4421 GtkTextBuffer *buffer;
4422 GtkTextIter start, end;
4424 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
4425 gtk_text_buffer_get_start_iter (buffer, &start);
4426 gtk_text_buffer_get_end_iter (buffer, &end);
4427 gtk_text_buffer_select_range (buffer, &start, &end);
4428 } else if (GTK_IS_HTML (focused_widget)) {
4429 gtk_html_select_all (GTK_HTML (focused_widget));
4430 } else if (MODEST_IS_MAIN_WINDOW (window)) {
4431 GtkWidget *header_view = focused_widget;
4432 GtkTreeSelection *selection = NULL;
4434 if (!(MODEST_IS_HEADER_VIEW (focused_widget))) {
4435 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (window),
4436 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
4439 /* Disable window dimming management */
4440 modest_window_disable_dimming (MODEST_WINDOW(window));
4442 /* Select all messages */
4443 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(header_view));
4444 gtk_tree_selection_select_all (selection);
4446 /* Set focuse on header view */
4447 gtk_widget_grab_focus (header_view);
4449 /* Enable window dimming management */
4450 modest_window_enable_dimming (MODEST_WINDOW(window));
4451 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (window));
4452 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (window));
4458 modest_ui_actions_on_mark_as_read (GtkAction *action,
4459 ModestWindow *window)
4461 g_return_if_fail (MODEST_IS_WINDOW(window));
4463 /* Mark each header as read */
4464 do_headers_action (window, headers_action_mark_as_read, NULL);
4468 modest_ui_actions_on_mark_as_unread (GtkAction *action,
4469 ModestWindow *window)
4471 g_return_if_fail (MODEST_IS_WINDOW(window));
4473 /* Mark each header as read */
4474 do_headers_action (window, headers_action_mark_as_unread, NULL);
4478 modest_ui_actions_on_change_zoom (GtkRadioAction *action,
4479 GtkRadioAction *selected,
4480 ModestWindow *window)
4484 value = gtk_radio_action_get_current_value (selected);
4485 if (MODEST_IS_WINDOW (window)) {
4486 modest_window_set_zoom (MODEST_WINDOW (window), ((gdouble)value)/100);
4491 modest_ui_actions_msg_edit_on_change_priority (GtkRadioAction *action,
4492 GtkRadioAction *selected,
4493 ModestWindow *window)
4495 TnyHeaderFlags flags;
4496 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4498 flags = gtk_radio_action_get_current_value (selected);
4499 modest_msg_edit_window_set_priority_flags (MODEST_MSG_EDIT_WINDOW (window), flags);
4503 modest_ui_actions_msg_edit_on_change_file_format (GtkRadioAction *action,
4504 GtkRadioAction *selected,
4505 ModestWindow *window)
4509 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4511 file_format = gtk_radio_action_get_current_value (selected);
4512 modest_msg_edit_window_set_file_format (MODEST_MSG_EDIT_WINDOW (window), file_format);
4517 modest_ui_actions_on_zoom_plus (GtkAction *action,
4518 ModestWindow *window)
4520 g_return_if_fail (MODEST_IS_WINDOW (window));
4522 modest_window_zoom_plus (MODEST_WINDOW (window));
4526 modest_ui_actions_on_zoom_minus (GtkAction *action,
4527 ModestWindow *window)
4529 g_return_if_fail (MODEST_IS_WINDOW (window));
4531 modest_window_zoom_minus (MODEST_WINDOW (window));
4535 modest_ui_actions_on_toggle_fullscreen (GtkToggleAction *toggle,
4536 ModestWindow *window)
4538 ModestWindowMgr *mgr;
4539 gboolean fullscreen, active;
4540 g_return_if_fail (MODEST_IS_WINDOW (window));
4542 mgr = modest_runtime_get_window_mgr ();
4544 active = (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle)))?1:0;
4545 fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
4547 if (active != fullscreen) {
4548 modest_window_mgr_set_fullscreen_mode (mgr, active);
4549 #ifndef MODEST_TOOLKIT_HILDON2
4550 gtk_window_present (GTK_WINDOW (window));
4556 modest_ui_actions_on_change_fullscreen (GtkAction *action,
4557 ModestWindow *window)
4559 ModestWindowMgr *mgr;
4560 gboolean fullscreen;
4562 g_return_if_fail (MODEST_IS_WINDOW (window));
4564 mgr = modest_runtime_get_window_mgr ();
4565 fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
4566 modest_window_mgr_set_fullscreen_mode (mgr, !fullscreen);
4568 #ifndef MODEST_TOOLKIT_HILDON2
4569 gtk_window_present (GTK_WINDOW (window));
4574 * Used by modest_ui_actions_on_details to call do_headers_action
4577 headers_action_show_details (TnyHeader *header,
4578 ModestWindow *window,
4582 modest_platform_run_header_details_dialog (GTK_WINDOW (window), header);
4586 * Show the header details in a ModestDetailsDialog widget
4589 modest_ui_actions_on_details (GtkAction *action,
4592 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
4596 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW (win));
4600 header = tny_msg_get_header (msg);
4602 headers_action_show_details (header, win, NULL);
4603 g_object_unref (header);
4605 g_object_unref (msg);
4607 } else if (MODEST_IS_MAIN_WINDOW (win)) {
4608 GtkWidget *folder_view, *header_view;
4610 /* Check which widget has the focus */
4611 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
4612 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
4613 if (gtk_widget_is_focus (folder_view)) {
4614 TnyFolderStore *folder_store
4615 = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
4616 if (!folder_store) {
4617 g_warning ("%s: No item was selected.\n", __FUNCTION__);
4620 /* Show only when it's a folder */
4621 /* This function should not be called for account items,
4622 * because we dim the menu item for them. */
4623 if (TNY_IS_FOLDER (folder_store)) {
4624 modest_platform_run_folder_details_dialog (GTK_WINDOW (win),
4625 TNY_FOLDER (folder_store));
4628 g_object_unref (folder_store);
4631 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
4632 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
4633 /* Show details of each header */
4634 do_headers_action (win, headers_action_show_details, header_view);
4636 #ifdef MODEST_TOOLKIT_HILDON2
4637 } else if (MODEST_IS_HEADER_WINDOW (win)) {
4639 GtkWidget *header_view;
4641 header_view = GTK_WIDGET (modest_header_window_get_header_view (MODEST_HEADER_WINDOW (win)));
4642 folder = modest_header_view_get_folder (MODEST_HEADER_VIEW (header_view));
4644 modest_platform_run_folder_details_dialog (GTK_WINDOW (win),
4646 g_object_unref (folder);
4653 modest_ui_actions_on_toggle_show_cc (GtkToggleAction *toggle,
4654 ModestMsgEditWindow *window)
4656 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4658 modest_msg_edit_window_show_cc (window, gtk_toggle_action_get_active (toggle));
4662 modest_ui_actions_on_toggle_show_bcc (GtkToggleAction *toggle,
4663 ModestMsgEditWindow *window)
4665 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4667 modest_msg_edit_window_show_bcc (window, gtk_toggle_action_get_active (toggle));
4671 modest_ui_actions_toggle_folders_view (GtkAction *action,
4672 ModestMainWindow *main_window)
4674 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
4676 if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)))
4677 modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SPLIT);
4679 modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SIMPLE);
4683 modest_ui_actions_on_toggle_toolbar (GtkToggleAction *toggle,
4684 ModestWindow *window)
4686 gboolean active, fullscreen = FALSE;
4687 ModestWindowMgr *mgr;
4689 active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle));
4691 /* Check if we want to toggle the toolbar view in fullscreen
4693 if (!strcmp (gtk_action_get_name (GTK_ACTION (toggle)),
4694 "ViewShowToolbarFullScreen")) {
4698 /* Toggle toolbar */
4699 mgr = modest_runtime_get_window_mgr ();
4700 modest_window_mgr_show_toolbars (mgr, G_TYPE_FROM_INSTANCE (window), active, fullscreen);
4704 modest_ui_actions_msg_edit_on_select_font (GtkAction *action,
4705 ModestMsgEditWindow *window)
4707 modest_msg_edit_window_select_font (window);
4712 modest_ui_actions_on_folder_display_name_changed (ModestFolderView *folder_view,
4713 const gchar *display_name,
4716 /* don't update the display name if it was already set;
4717 * updating the display name apparently is expensive */
4718 const gchar* old_name = gtk_window_get_title (window);
4720 if (display_name == NULL)
4723 if (old_name && display_name && strcmp (old_name, display_name) == 0)
4724 return; /* don't do anything */
4726 /* This is usually used to change the title of the main window, which
4727 * is the one that holds the folder view. Note that this change can
4728 * happen even when the widget doesn't have the focus. */
4729 gtk_window_set_title (window, display_name);
4734 modest_ui_actions_on_select_contacts (GtkAction *action, ModestMsgEditWindow *window)
4736 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4737 modest_msg_edit_window_select_contacts (window);
4741 modest_ui_actions_on_check_names (GtkAction *action, ModestMsgEditWindow *window)
4743 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4744 modest_msg_edit_window_check_names (window, FALSE);
4747 #ifndef MODEST_TOOLKIT_HILDON2
4749 * This function is used to track changes in the selection of the
4750 * folder view that is inside the "move to" dialog to enable/disable
4751 * the OK button because we do not want the user to select a disallowed
4752 * destination for a folder.
4753 * The user also not desired to be able to use NEW button on items where
4754 * folder creation is not possibel.
4757 on_move_to_dialog_folder_selection_changed (ModestFolderView* self,
4758 TnyFolderStore *folder_store,
4762 GtkWidget *dialog = NULL;
4763 gboolean ok_sensitive = TRUE, new_sensitive = TRUE;
4764 gboolean moving_folder = FALSE;
4765 gboolean is_local_account = TRUE;
4766 GtkWidget *folder_view = NULL;
4767 ModestTnyFolderRules rules;
4769 g_return_if_fail (MODEST_IS_FOLDER_VIEW(self));
4774 dialog = gtk_widget_get_ancestor (GTK_WIDGET (self), GTK_TYPE_DIALOG);
4778 /* check if folder_store is an remote account */
4779 if (TNY_IS_ACCOUNT (folder_store)) {
4780 TnyAccount *local_account = NULL;
4781 TnyAccount *mmc_account = NULL;
4782 ModestTnyAccountStore *account_store = NULL;
4784 account_store = modest_runtime_get_account_store ();
4785 local_account = modest_tny_account_store_get_local_folders_account (account_store);
4786 mmc_account = modest_tny_account_store_get_mmc_folders_account (account_store);
4788 if ((gpointer) local_account != (gpointer) folder_store &&
4789 (gpointer) mmc_account != (gpointer) folder_store) {
4790 ModestProtocolType proto;
4791 proto = modest_tny_account_get_protocol_type (TNY_ACCOUNT (folder_store));
4792 if (proto == MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
4793 proto = MODEST_PROTOCOLS_STORE_MAILDIR;
4795 is_local_account = FALSE;
4796 /* New button should be dimmed on remote
4798 new_sensitive = (modest_protocol_registry_protocol_type_has_tag (modest_runtime_get_protocol_registry (),
4800 MODEST_PROTOCOL_REGISTRY_STORE_HAS_FOLDERS));
4802 g_object_unref (local_account);
4804 /* It could not exist */
4806 g_object_unref (mmc_account);
4809 /* Check the target folder rules */
4810 if (TNY_IS_FOLDER (folder_store)) {
4811 rules = modest_tny_folder_get_rules (TNY_FOLDER (folder_store));
4812 if (rules & MODEST_FOLDER_RULES_FOLDER_NON_WRITEABLE) {
4813 ok_sensitive = FALSE;
4814 new_sensitive = FALSE;
4819 /* Check if we're moving a folder */
4820 if (MODEST_IS_MAIN_WINDOW (user_data)) {
4821 /* Get the widgets */
4822 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (user_data),
4823 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
4824 if (gtk_widget_is_focus (folder_view))
4825 moving_folder = TRUE;
4828 if (moving_folder) {
4829 TnyFolderStore *moved_folder = NULL, *parent = NULL;
4831 /* Get the folder to move */
4832 moved_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
4834 /* Check that we're not moving to the same folder */
4835 if (TNY_IS_FOLDER (moved_folder)) {
4836 parent = tny_folder_get_folder_store (TNY_FOLDER (moved_folder));
4837 if (parent == folder_store)
4838 ok_sensitive = FALSE;
4839 g_object_unref (parent);
4842 if (ok_sensitive && TNY_IS_ACCOUNT (folder_store)) {
4843 /* Do not allow to move to an account unless it's the
4844 local folders account */
4845 if (!is_local_account)
4846 ok_sensitive = FALSE;
4849 if (ok_sensitive && (moved_folder == folder_store)) {
4850 /* Do not allow to move to itself */
4851 ok_sensitive = FALSE;
4853 g_object_unref (moved_folder);
4855 TnyFolder *src_folder = NULL;
4857 /* Moving a message */
4858 if (MODEST_IS_MSG_VIEW_WINDOW (user_data)) {
4860 TnyHeader *header = NULL;
4861 header = modest_msg_view_window_get_header
4862 (MODEST_MSG_VIEW_WINDOW (user_data));
4863 if (!TNY_IS_HEADER(header))
4864 g_warning ("%s: could not get source header", __FUNCTION__);
4866 src_folder = tny_header_get_folder (header);
4869 g_object_unref (header);
4872 TNY_FOLDER (modest_folder_view_get_selected
4873 (MODEST_FOLDER_VIEW (folder_view)));
4876 if (TNY_IS_FOLDER(src_folder)) {
4877 /* Do not allow to move the msg to the same folder */
4878 /* Do not allow to move the msg to an account */
4879 if ((gpointer) src_folder == (gpointer) folder_store ||
4880 TNY_IS_ACCOUNT (folder_store))
4881 ok_sensitive = FALSE;
4882 g_object_unref (src_folder);
4884 g_warning ("%s: could not get source folder", __FUNCTION__);
4888 /* Set sensitivity of the OK and NEW button */
4889 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, ok_sensitive);
4890 gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), MODEST_GTK_RESPONSE_NEW_FOLDER, new_sensitive);
4895 on_move_to_dialog_response (GtkDialog *dialog,
4899 GtkWidget *parent_win, *folder_view;
4900 MoveToInfo *helper = NULL;
4902 helper = (MoveToInfo *) user_data;
4904 parent_win = (GtkWidget *) helper->win;
4905 folder_view = GTK_WIDGET (g_object_get_data (G_OBJECT (dialog),
4906 MODEST_MOVE_TO_DIALOG_FOLDER_VIEW));
4909 TnyFolderStore *dst_folder;
4911 case MODEST_GTK_RESPONSE_NEW_FOLDER:
4912 modest_ui_actions_create_folder (GTK_WIDGET (dialog), folder_view);
4914 case GTK_RESPONSE_NONE:
4915 case GTK_RESPONSE_CANCEL:
4916 case GTK_RESPONSE_DELETE_EVENT:
4918 case GTK_RESPONSE_OK:
4919 dst_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
4920 /* Do window specific stuff */
4921 if (MODEST_IS_MAIN_WINDOW (parent_win)) {
4922 modest_ui_actions_on_main_window_move_to (NULL,
4925 MODEST_MAIN_WINDOW (parent_win));
4926 #ifdef MODEST_TOOLKIT_HILDON2
4927 } else if (MODEST_IS_FOLDER_WINDOW (parent_win)) {
4928 modest_ui_actions_on_folder_window_move_to (folder_view,
4931 GTK_WINDOW (parent_win));
4934 /* Moving from headers window in edit mode */
4935 modest_ui_actions_on_window_move_to (NULL, helper->list,
4937 MODEST_WINDOW (parent_win));
4941 g_object_unref (dst_folder);
4945 g_warning ("%s unexpected response id %d", __FUNCTION__, response);
4948 /* Free the helper and exit */
4950 g_object_unref (helper->list);
4951 g_slice_free (MoveToInfo, helper);
4952 gtk_widget_destroy (GTK_WIDGET (dialog));
4956 create_move_to_dialog (GtkWindow *win,
4957 GtkWidget *folder_view)
4959 GtkWidget *dialog, *tree_view = NULL;
4961 dialog = modest_platform_create_move_to_dialog (win, &tree_view);
4963 #ifndef MODEST_TOOLKIT_HILDON2
4964 /* Track changes in the selection to
4965 * disable the OK button whenever "Move to" is not possible
4966 * disbale NEW button whenever New is not possible */
4967 g_signal_connect (tree_view,
4968 "folder_selection_changed",
4969 G_CALLBACK (on_move_to_dialog_folder_selection_changed),
4973 /* It could happen that we're trying to move a message from a
4974 window (msg window for example) after the main window was
4975 closed, so we can not just get the model of the folder
4977 if (MODEST_IS_FOLDER_VIEW (folder_view)) {
4978 const gchar *visible_id = NULL;
4980 modest_folder_view_set_style (MODEST_FOLDER_VIEW (tree_view),
4981 MODEST_FOLDER_VIEW_STYLE_SHOW_ALL);
4982 modest_folder_view_copy_model (MODEST_FOLDER_VIEW(folder_view),
4983 MODEST_FOLDER_VIEW(tree_view));
4986 modest_folder_view_get_account_id_of_visible_server_account (MODEST_FOLDER_VIEW(folder_view));
4988 /* Show the same account than the one that is shown in the main window */
4989 modest_folder_view_set_account_id_of_visible_server_account (MODEST_FOLDER_VIEW(tree_view),
4992 const gchar *active_account_name = NULL;
4993 ModestAccountMgr *mgr = NULL;
4994 ModestAccountSettings *settings = NULL;
4995 ModestServerAccountSettings *store_settings = NULL;
4997 modest_folder_view_set_style (MODEST_FOLDER_VIEW (tree_view),
4998 MODEST_FOLDER_VIEW_STYLE_SHOW_ALL);
4999 modest_folder_view_update_model (MODEST_FOLDER_VIEW (tree_view),
5000 TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()));
5002 active_account_name = modest_window_get_active_account (MODEST_WINDOW (win));
5003 mgr = modest_runtime_get_account_mgr ();
5004 settings = modest_account_mgr_load_account_settings (mgr, active_account_name);
5007 const gchar *store_account_name;
5008 store_settings = modest_account_settings_get_store_settings (settings);
5009 store_account_name = modest_server_account_settings_get_account_name (store_settings);
5011 modest_folder_view_set_account_id_of_visible_server_account (MODEST_FOLDER_VIEW (tree_view),
5012 store_account_name);
5013 g_object_unref (store_settings);
5014 g_object_unref (settings);
5018 /* we keep a pointer to the embedded folder view, so we can
5019 * retrieve it with get_folder_view_from_move_to_dialog (see
5020 * above) later (needed for focus handling)
5022 g_object_set_data (G_OBJECT(dialog), MODEST_MOVE_TO_DIALOG_FOLDER_VIEW, tree_view);
5024 /* Hide special folders */
5025 modest_folder_view_show_non_move_folders (MODEST_FOLDER_VIEW (tree_view), FALSE);
5026 #ifndef MODEST_TOOLKIT_HILDON2
5027 modest_folder_view_select_first_inbox_or_local (MODEST_FOLDER_VIEW (tree_view));
5030 gtk_widget_show (GTK_WIDGET (tree_view));
5036 * Shows a confirmation dialog to the user when we're moving messages
5037 * from a remote server to the local storage. Returns the dialog
5038 * response. If it's other kind of movement then it always returns
5041 * This one is used by the next functions:
5042 * modest_ui_actions_on_paste - commented out
5043 * drag_and_drop_from_header_view (for d&d in modest_folder_view.c)
5046 modest_ui_actions_msgs_move_to_confirmation (ModestWindow *win,
5047 TnyFolder *dest_folder,
5051 gint response = GTK_RESPONSE_OK;
5052 TnyAccount *account = NULL;
5053 TnyFolder *src_folder = NULL;
5054 TnyIterator *iter = NULL;
5055 TnyHeader *header = NULL;
5057 /* return with OK if the destination is a remote folder */
5058 if (modest_tny_folder_is_remote_folder (dest_folder))
5059 return GTK_RESPONSE_OK;
5061 /* Get source folder */
5062 iter = tny_list_create_iterator (headers);
5063 header = TNY_HEADER (tny_iterator_get_current (iter));
5065 src_folder = tny_header_get_folder (header);
5066 g_object_unref (header);
5068 g_object_unref (iter);
5070 /* if no src_folder, message may be an attahcment */
5071 if (src_folder == NULL)
5072 return GTK_RESPONSE_CANCEL;
5074 /* If the source is a local or MMC folder */
5075 if (!modest_tny_folder_is_remote_folder (src_folder)) {
5076 g_object_unref (src_folder);
5077 return GTK_RESPONSE_OK;
5080 /* Get the account */
5081 account = tny_folder_get_account (src_folder);
5083 /* now if offline we ask the user */
5084 if(connect_to_get_msg (win, tny_list_get_length (headers), account))
5085 response = GTK_RESPONSE_OK;
5087 response = GTK_RESPONSE_CANCEL;
5090 g_object_unref (src_folder);
5091 g_object_unref (account);
5097 move_to_helper_destroyer (gpointer user_data)
5099 MoveToHelper *helper = (MoveToHelper *) user_data;
5101 /* Close the "Pasting" information banner */
5102 if (helper->banner) {
5103 gtk_widget_destroy (GTK_WIDGET (helper->banner));
5104 g_object_unref (helper->banner);
5106 if (gtk_tree_row_reference_valid (helper->reference)) {
5107 gtk_tree_row_reference_free (helper->reference);
5108 helper->reference = NULL;
5114 move_to_cb (ModestMailOperation *mail_op,
5117 MoveToHelper *helper = (MoveToHelper *) user_data;
5118 GObject *object = modest_mail_operation_get_source (mail_op);
5120 /* Note that the operation could have failed, in that case do
5122 if (modest_mail_operation_get_status (mail_op) !=
5123 MODEST_MAIL_OPERATION_STATUS_SUCCESS)
5126 if (MODEST_IS_MSG_VIEW_WINDOW (object)) {
5127 ModestMsgViewWindow *self = MODEST_MSG_VIEW_WINDOW (object);
5129 if (!modest_msg_view_window_select_next_message (self) &&
5130 !modest_msg_view_window_select_previous_message (self)) {
5131 /* No more messages to view, so close this window */
5132 modest_ui_actions_on_close_window (NULL, MODEST_WINDOW(self));
5134 } else if (MODEST_IS_MAIN_WINDOW (object) &&
5135 gtk_tree_row_reference_valid (helper->reference)) {
5136 GtkWidget *header_view;
5138 GtkTreeSelection *sel;
5140 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(object),
5141 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
5142 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
5143 path = gtk_tree_row_reference_get_path (helper->reference);
5144 /* We need to unselect the previous one
5145 because we could be copying instead of
5147 gtk_tree_selection_unselect_all (sel);
5148 gtk_tree_selection_select_path (sel, path);
5149 gtk_tree_path_free (path);
5151 g_object_unref (object);
5154 /* Destroy the helper */
5155 move_to_helper_destroyer (helper);
5159 folder_move_to_cb (ModestMailOperation *mail_op,
5160 TnyFolder *new_folder,
5163 GtkWidget *folder_view;
5166 object = modest_mail_operation_get_source (mail_op);
5167 if (MODEST_IS_MAIN_WINDOW (object)) {
5168 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(object),
5169 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
5170 g_object_ref (folder_view);
5171 g_object_unref (object);
5172 move_to_cb (mail_op, user_data);
5173 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view), new_folder, FALSE);
5174 g_object_unref (folder_view);
5176 move_to_cb (mail_op, user_data);
5181 msgs_move_to_cb (ModestMailOperation *mail_op,
5184 move_to_cb (mail_op, user_data);
5188 modest_ui_actions_move_folder_error_handler (ModestMailOperation *mail_op,
5191 GObject *win = NULL;
5193 #ifndef MODEST_TOOLKIT_HILDON2
5194 ModestWindow *main_window = NULL;
5196 /* Disable next automatic folder selection */
5197 main_window = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (),
5198 FALSE); /* don't create */
5200 GtkWidget *folder_view = NULL;
5202 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (main_window),
5203 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
5204 modest_folder_view_disable_next_folder_selection (MODEST_FOLDER_VIEW(folder_view));
5206 if (user_data && TNY_IS_FOLDER (user_data)) {
5207 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view),
5208 TNY_FOLDER (user_data), FALSE);
5212 /* Show notification dialog only if the main window exists */
5213 win = modest_mail_operation_get_source (mail_op);
5214 modest_platform_run_information_dialog ((GtkWindow *) win,
5215 _("mail_in_ui_folder_move_target_error"),
5218 g_object_unref (win);
5222 open_msg_for_purge_cb (ModestMailOperation *mail_op,
5231 gint pending_purges = 0;
5232 gboolean some_purged = FALSE;
5233 ModestWindow *win = MODEST_WINDOW (user_data);
5234 ModestWindowMgr *mgr = modest_runtime_get_window_mgr ();
5236 /* If there was any error */
5237 if (!modest_ui_actions_msg_retrieval_check (mail_op, header, msg)) {
5238 modest_window_mgr_unregister_header (mgr, header);
5242 /* Once the message has been retrieved for purging, we check if
5243 * it's all ok for purging */
5245 parts = tny_simple_list_new ();
5246 tny_mime_part_get_parts (TNY_MIME_PART (msg), parts);
5247 iter = tny_list_create_iterator (parts);
5249 while (!tny_iterator_is_done (iter)) {
5251 part = TNY_MIME_PART (tny_iterator_get_current (iter));
5252 if (part && (tny_mime_part_is_attachment (part) || TNY_IS_MSG (part))) {
5253 if (tny_mime_part_is_purged (part))
5260 g_object_unref (part);
5262 tny_iterator_next (iter);
5264 g_object_unref (iter);
5267 if (pending_purges>0) {
5269 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),_("mcen_nc_purge_file_text_inbox"));
5271 if (response == GTK_RESPONSE_OK) {
5274 modest_platform_animation_banner (GTK_WIDGET (win), NULL, _("mcen_me_inbox_remove_attachments"));
5275 iter = tny_list_create_iterator (parts);
5276 while (!tny_iterator_is_done (iter)) {
5279 part = TNY_MIME_PART (tny_iterator_get_current (iter));
5280 if (part && (tny_mime_part_is_attachment (part) || TNY_IS_MSG (part)))
5281 tny_mime_part_set_purged (part);
5284 g_object_unref (part);
5286 tny_iterator_next (iter);
5288 g_object_unref (iter);
5290 tny_msg_rewrite_cache (msg);
5292 gtk_widget_destroy (info);
5296 modest_window_mgr_unregister_header (mgr, header);
5298 g_object_unref (parts);
5302 modest_ui_actions_on_main_window_remove_attachments (GtkAction *action,
5303 ModestMainWindow *win)
5305 GtkWidget *header_view;
5306 TnyList *header_list;
5308 TnyHeaderFlags flags;
5309 ModestWindow *msg_view_window = NULL;
5312 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win));
5314 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
5315 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
5317 header_list = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW (header_view));
5319 g_warning ("%s: no header selected", __FUNCTION__);
5323 if (tny_list_get_length (header_list) == 1) {
5324 TnyIterator *iter = tny_list_create_iterator (header_list);
5325 header = TNY_HEADER (tny_iterator_get_current (iter));
5326 g_object_unref (iter);
5330 if (!header || !TNY_IS_HEADER(header)) {
5331 g_warning ("%s: header is not valid", __FUNCTION__);
5335 found = modest_window_mgr_find_registered_header (modest_runtime_get_window_mgr (),
5336 header, &msg_view_window);
5337 flags = tny_header_get_flags (header);
5338 if (!(flags & TNY_HEADER_FLAG_CACHED))
5341 if (msg_view_window != NULL)
5342 modest_msg_view_window_remove_attachments (MODEST_MSG_VIEW_WINDOW (msg_view_window), TRUE);
5344 /* do nothing; uid was registered before, so window is probably on it's way */
5345 g_warning ("debug: header %p has already been registered", header);
5348 ModestMailOperation *mail_op = NULL;
5349 modest_window_mgr_register_header (modest_runtime_get_window_mgr (), header, NULL);
5350 mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT (win),
5351 modest_ui_actions_disk_operations_error_handler,
5353 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
5354 modest_mail_operation_get_msg (mail_op, header, FALSE, open_msg_for_purge_cb, win);
5356 g_object_unref (mail_op);
5359 g_object_unref (header);
5361 g_object_unref (header_list);
5365 * Checks if we need a connection to do the transfer and if the user
5366 * wants to connect to complete it
5369 modest_ui_actions_xfer_messages_check (GtkWindow *parent_window,
5370 TnyFolderStore *src_folder,
5372 TnyFolder *dst_folder,
5373 gboolean delete_originals,
5374 gboolean *need_connection,
5377 TnyAccount *src_account;
5378 gint uncached_msgs = 0;
5380 /* We don't need any further check if
5382 * 1- the source folder is local OR
5383 * 2- the device is already online
5385 if (!modest_tny_folder_store_is_remote (src_folder) ||
5386 tny_device_is_online (modest_runtime_get_device())) {
5387 *need_connection = FALSE;
5392 /* We must ask for a connection when
5394 * - the message(s) is not already cached OR
5395 * - the message(s) is cached but the leave_on_server setting
5396 * is FALSE (because we need to sync the source folder to
5397 * delete the message from the server (for IMAP we could do it
5398 * offline, it'll take place the next time we get a
5401 uncached_msgs = header_list_count_uncached_msgs (headers);
5402 src_account = get_account_from_folder_store (src_folder);
5403 if (uncached_msgs > 0) {
5407 *need_connection = TRUE;
5408 num_headers = tny_list_get_length (headers);
5409 msg = ngettext ("mcen_nc_get_msg", "mcen_nc_get_msgs", num_headers);
5411 if (modest_platform_run_confirmation_dialog (parent_window, msg) ==
5412 GTK_RESPONSE_CANCEL) {
5418 /* The transfer is possible and the user wants to */
5421 if (remote_folder_has_leave_on_server (src_folder) && delete_originals) {
5422 const gchar *account_name;
5423 gboolean leave_on_server;
5425 account_name = modest_tny_account_get_parent_modest_account_name_for_server_account (src_account);
5426 leave_on_server = modest_account_mgr_get_leave_on_server (modest_runtime_get_account_mgr (),
5429 if (leave_on_server == TRUE) {
5430 *need_connection = FALSE;
5432 *need_connection = TRUE;
5435 *need_connection = FALSE;
5440 g_object_unref (src_account);
5444 xfer_messages_error_handler (ModestMailOperation *mail_op,
5448 const GError *error;
5450 win = modest_mail_operation_get_source (mail_op);
5451 error = modest_mail_operation_get_error (mail_op);
5453 if (error && is_memory_full_error ((GError *) error))
5454 modest_platform_information_banner ((GtkWidget *) win,
5455 NULL, _KR("cerm_device_memory_full"));
5457 modest_platform_run_information_dialog ((GtkWindow *) win,
5458 _("mail_in_ui_folder_move_target_error"),
5461 g_object_unref (win);
5465 TnyFolderStore *dst_folder;
5470 * Utility function that transfer messages from both the main window
5471 * and the msg view window when using the "Move to" dialog
5474 xfer_messages_performer (gboolean canceled,
5476 GtkWindow *parent_window,
5477 TnyAccount *account,
5480 ModestWindow *win = MODEST_WINDOW (parent_window);
5481 TnyAccount *dst_account = NULL;
5482 gboolean dst_forbids_message_add = FALSE;
5483 XferMsgsHelper *helper;
5484 MoveToHelper *movehelper;
5485 ModestMailOperation *mail_op;
5487 helper = (XferMsgsHelper *) user_data;
5489 if (canceled || err) {
5490 if (!check_memory_full_error ((GtkWidget *) parent_window, err)) {
5491 /* Show the proper error message */
5492 modest_ui_actions_on_account_connection_error (parent_window, account);
5497 dst_account = tny_folder_get_account (TNY_FOLDER (helper->dst_folder));
5499 /* tinymail will return NULL for local folders it seems */
5500 dst_forbids_message_add = modest_protocol_registry_protocol_type_has_tag (modest_runtime_get_protocol_registry (),
5501 modest_tny_account_get_protocol_type (dst_account),
5502 MODEST_PROTOCOL_REGISTRY_STORE_FORBID_MESSAGE_ADD);
5503 g_object_unref (dst_account);
5505 if (dst_forbids_message_add) {
5506 modest_platform_information_banner (GTK_WIDGET (win),
5508 ngettext("mail_in_ui_folder_move_target_error",
5509 "mail_in_ui_folder_move_targets_error",
5510 tny_list_get_length (helper->headers)));
5514 movehelper = g_new0 (MoveToHelper, 1);
5516 #ifndef MODEST_TOOLKIT_HILDON2
5517 movehelper->banner = modest_platform_animation_banner (GTK_WIDGET (win), NULL,
5518 _CS("ckct_nw_pasting"));
5519 if (movehelper->banner != NULL) {
5520 g_object_ref (movehelper->banner);
5521 gtk_widget_show (GTK_WIDGET (movehelper->banner));
5525 if (MODEST_IS_MAIN_WINDOW (win)) {
5526 GtkWidget *header_view =
5527 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
5528 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
5529 movehelper->reference = get_next_after_selected_headers (MODEST_HEADER_VIEW (header_view));
5532 /* Perform the mail operation */
5533 mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT(win),
5534 xfer_messages_error_handler,
5536 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
5539 modest_mail_operation_xfer_msgs (mail_op,
5541 TNY_FOLDER (helper->dst_folder),
5546 g_object_unref (G_OBJECT (mail_op));
5548 g_object_unref (helper->dst_folder);
5549 g_object_unref (helper->headers);
5550 g_slice_free (XferMsgsHelper, helper);
5554 TnyFolder *src_folder;
5555 TnyFolderStore *dst_folder;
5556 gboolean delete_original;
5557 GtkWidget *folder_view;
5561 on_move_folder_cb (gboolean canceled, GError *err, GtkWindow *parent_window,
5562 TnyAccount *account, gpointer user_data)
5564 MoveFolderInfo *info = (MoveFolderInfo*)user_data;
5565 GtkTreeSelection *sel;
5566 ModestMailOperation *mail_op = NULL;
5568 if (canceled || err || !MODEST_IS_WINDOW (parent_window)) {
5569 g_object_unref (G_OBJECT (info->src_folder));
5570 g_object_unref (G_OBJECT (info->dst_folder));
5575 MoveToHelper *helper = g_new0 (MoveToHelper, 1);
5576 #ifndef MODEST_TOOLKIT_HILDON2
5577 helper->banner = modest_platform_animation_banner (GTK_WIDGET (parent_window), NULL,
5578 _CS("ckct_nw_pasting"));
5579 if (helper->banner != NULL) {
5580 g_object_ref (helper->banner);
5581 gtk_widget_show (GTK_WIDGET(helper->banner));
5584 /* Clean folder on header view before moving it */
5585 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (info->folder_view));
5586 gtk_tree_selection_unselect_all (sel);
5588 /* Let gtk events run. We need that the folder
5589 view frees its reference to the source
5590 folder *before* issuing the mail operation
5591 so we need the signal handler of selection
5592 changed to happen before the mail
5594 while (gtk_events_pending ())
5595 gtk_main_iteration (); */
5598 modest_mail_operation_new_with_error_handling (G_OBJECT(parent_window),
5599 modest_ui_actions_move_folder_error_handler,
5600 info->src_folder, NULL);
5601 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
5604 /* Select *after* the changes */
5605 /* TODO: this function hangs UI after transfer */
5606 /* modest_folder_view_select_folder (MODEST_FOLDER_VIEW(folder_view), */
5607 /* TNY_FOLDER (src_folder), TRUE); */
5609 if (MODEST_IS_MAIN_WINDOW (parent_window)) {
5610 modest_folder_view_select_folder (MODEST_FOLDER_VIEW(info->folder_view),
5611 TNY_FOLDER (info->dst_folder), TRUE);
5613 modest_mail_operation_xfer_folder (mail_op,
5614 TNY_FOLDER (info->src_folder),
5616 info->delete_original,
5619 g_object_unref (G_OBJECT (info->src_folder));
5621 /* if (modest_mail_operation_get_status (mail_op) == MODEST_MAIL_OPERATION_STATUS_SUCCESS) { */
5624 /* Unref mail operation */
5625 g_object_unref (G_OBJECT (mail_op));
5626 g_object_unref (G_OBJECT (info->dst_folder));
5631 get_account_from_folder_store (TnyFolderStore *folder_store)
5633 if (TNY_IS_ACCOUNT (folder_store))
5634 return g_object_ref (folder_store);
5636 return tny_folder_get_account (TNY_FOLDER (folder_store));
5640 * UI handler for the "Move to" action when invoked from the
5644 modest_ui_actions_on_main_window_move_to (GtkAction *action,
5645 GtkWidget *folder_view,
5646 TnyFolderStore *dst_folder,
5647 ModestMainWindow *win)
5649 ModestHeaderView *header_view = NULL;
5650 TnyFolderStore *src_folder = NULL;
5652 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win));
5654 /* Get the source folder */
5655 src_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
5657 /* Get header view */
5658 header_view = (ModestHeaderView *)
5659 modest_main_window_get_child_widget (win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
5661 /* Get folder or messages to transfer */
5662 if (gtk_widget_is_focus (folder_view)) {
5663 gboolean do_xfer = TRUE;
5665 /* Allow only to transfer folders to the local root folder */
5666 if (TNY_IS_ACCOUNT (dst_folder) &&
5667 !MODEST_IS_TNY_LOCAL_FOLDERS_ACCOUNT (dst_folder) &&
5668 !modest_tny_account_is_memory_card_account (TNY_ACCOUNT (dst_folder))) {
5670 } else if (!TNY_IS_FOLDER (src_folder)) {
5671 g_warning ("%s: src_folder is not a TnyFolder.\n", __FUNCTION__);
5676 MoveFolderInfo *info = g_new0 (MoveFolderInfo, 1);
5677 DoubleConnectionInfo *connect_info = g_slice_new (DoubleConnectionInfo);
5679 info->src_folder = g_object_ref (src_folder);
5680 info->dst_folder = g_object_ref (dst_folder);
5681 info->delete_original = TRUE;
5682 info->folder_view = folder_view;
5684 connect_info->callback = on_move_folder_cb;
5685 connect_info->dst_account = get_account_from_folder_store (TNY_FOLDER_STORE (dst_folder));
5686 connect_info->data = info;
5688 modest_platform_double_connect_and_perform(GTK_WINDOW (win), TRUE,
5689 TNY_FOLDER_STORE (src_folder),
5692 } else if (gtk_widget_is_focus (GTK_WIDGET(header_view))) {
5695 headers = modest_header_view_get_selected_headers(header_view);
5697 /* Transfer the messages */
5698 modest_ui_actions_transfer_messages_helper (GTK_WINDOW (win), TNY_FOLDER (src_folder),
5699 headers, TNY_FOLDER (dst_folder));
5701 g_object_unref (headers);
5705 g_object_unref (src_folder);
5708 #ifdef MODEST_TOOLKIT_HILDON2
5710 * UI handler for the "Move to" action when invoked from the
5711 * ModestFolderWindow
5714 modest_ui_actions_on_folder_window_move_to (GtkWidget *folder_view,
5715 TnyFolderStore *dst_folder,
5719 TnyFolderStore *src_folder = NULL;
5720 TnyIterator *iterator;
5722 if (tny_list_get_length (selection) != 1)
5725 iterator = tny_list_create_iterator (selection);
5726 src_folder = TNY_FOLDER_STORE (tny_iterator_get_current (iterator));
5727 g_object_unref (iterator);
5730 gboolean do_xfer = TRUE;
5732 /* Allow only to transfer folders to the local root folder */
5733 if (TNY_IS_ACCOUNT (dst_folder) &&
5734 !MODEST_IS_TNY_LOCAL_FOLDERS_ACCOUNT (dst_folder) &&
5735 !modest_tny_account_is_memory_card_account (TNY_ACCOUNT (dst_folder))) {
5738 modest_platform_run_information_dialog (win,
5739 _("mail_in_ui_folder_move_target_error"),
5741 } else if (!TNY_IS_FOLDER (src_folder)) {
5742 g_warning ("%s: src_folder is not a TnyFolder.\n", __FUNCTION__);
5747 MoveFolderInfo *info = g_new0 (MoveFolderInfo, 1);
5748 DoubleConnectionInfo *connect_info = g_slice_new (DoubleConnectionInfo);
5750 info->src_folder = g_object_ref (src_folder);
5751 info->dst_folder = g_object_ref (dst_folder);
5752 info->delete_original = TRUE;
5753 info->folder_view = folder_view;
5755 connect_info->callback = on_move_folder_cb;
5756 connect_info->dst_account = get_account_from_folder_store (TNY_FOLDER_STORE (dst_folder));
5757 connect_info->data = info;
5759 modest_platform_double_connect_and_perform(GTK_WINDOW (win), TRUE,
5760 TNY_FOLDER_STORE (src_folder),
5765 g_object_unref (src_folder);
5771 modest_ui_actions_transfer_messages_helper (GtkWindow *win,
5772 TnyFolder *src_folder,
5774 TnyFolder *dst_folder)
5776 gboolean need_connection = TRUE;
5777 gboolean do_xfer = TRUE;
5778 XferMsgsHelper *helper;
5780 g_return_if_fail (TNY_IS_FOLDER (src_folder));
5781 g_return_if_fail (TNY_IS_FOLDER (dst_folder));
5782 g_return_if_fail (TNY_IS_LIST (headers));
5784 modest_ui_actions_xfer_messages_check (win, TNY_FOLDER_STORE (src_folder),
5785 headers, TNY_FOLDER (dst_folder),
5786 TRUE, &need_connection,
5789 /* If we don't want to transfer just return */
5793 /* Create the helper */
5794 helper = g_slice_new (XferMsgsHelper);
5795 helper->dst_folder = g_object_ref (dst_folder);
5796 helper->headers = g_object_ref (headers);
5798 if (need_connection) {
5799 DoubleConnectionInfo *connect_info = g_slice_new (DoubleConnectionInfo);
5800 connect_info->callback = xfer_messages_performer;
5801 connect_info->dst_account = tny_folder_get_account (TNY_FOLDER (dst_folder));
5802 connect_info->data = helper;
5804 modest_platform_double_connect_and_perform(GTK_WINDOW (win), TRUE,
5805 TNY_FOLDER_STORE (src_folder),
5808 TnyAccount *src_account = get_account_from_folder_store (TNY_FOLDER_STORE (src_folder));
5809 xfer_messages_performer (FALSE, NULL, GTK_WINDOW (win),
5810 src_account, helper);
5811 g_object_unref (src_account);
5816 * UI handler for the "Move to" action when invoked from the
5817 * ModestMsgViewWindow
5820 modest_ui_actions_on_window_move_to (GtkAction *action,
5822 TnyFolderStore *dst_folder,
5825 TnyFolder *src_folder = NULL;
5827 g_return_if_fail (TNY_IS_FOLDER (dst_folder));
5830 TnyHeader *header = NULL;
5833 iter = tny_list_create_iterator (headers);
5834 header = (TnyHeader *) tny_iterator_get_current (iter);
5835 src_folder = tny_header_get_folder (header);
5837 /* Transfer the messages */
5838 modest_ui_actions_transfer_messages_helper (GTK_WINDOW (win), src_folder,
5840 TNY_FOLDER (dst_folder));
5843 g_object_unref (header);
5844 g_object_unref (iter);
5845 g_object_unref (src_folder);
5850 modest_ui_actions_on_move_to (GtkAction *action,
5853 modest_ui_actions_on_edit_mode_move_to (win);
5857 modest_ui_actions_on_edit_mode_move_to (ModestWindow *win)
5859 GtkWidget *dialog = NULL;
5860 MoveToInfo *helper = NULL;
5861 TnyList *list_to_move;
5863 g_return_val_if_fail (MODEST_IS_WINDOW (win), FALSE);
5865 #ifndef MODEST_TOOLKIT_HILDON2
5866 /* Get the main window if exists */
5867 ModestMainWindow *main_window;
5868 if (MODEST_IS_MAIN_WINDOW (win))
5869 main_window = MODEST_MAIN_WINDOW (win);
5872 MODEST_MAIN_WINDOW (modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (),
5873 FALSE)); /* don't create */
5876 list_to_move = modest_platform_get_list_to_move (MODEST_WINDOW (win));
5881 if (tny_list_get_length (list_to_move) < 1) {
5882 g_object_unref (list_to_move);
5886 /* Create and run the dialog */
5887 dialog = create_move_to_dialog (GTK_WINDOW (win), NULL);
5888 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (),
5889 GTK_WINDOW (dialog),
5893 helper = g_slice_new0 (MoveToInfo);
5894 helper->list = list_to_move;
5897 /* Listen to response signal */
5898 g_signal_connect (dialog, "response", G_CALLBACK (on_move_to_dialog_response), helper);
5900 /* Show the dialog */
5901 gtk_widget_show (dialog);
5907 * Calls #HeadersFunc for each header already selected in the main
5908 * window or the message currently being shown in the msg view window
5911 do_headers_action (ModestWindow *win,
5915 TnyList *headers_list = NULL;
5916 TnyIterator *iter = NULL;
5917 TnyHeader *header = NULL;
5918 TnyFolder *folder = NULL;
5921 headers_list = get_selected_headers (win);
5925 /* Get the folder */
5926 iter = tny_list_create_iterator (headers_list);
5927 header = TNY_HEADER (tny_iterator_get_current (iter));
5929 folder = tny_header_get_folder (header);
5930 g_object_unref (header);
5933 /* Call the function for each header */
5934 while (!tny_iterator_is_done (iter)) {
5935 header = TNY_HEADER (tny_iterator_get_current (iter));
5936 func (header, win, user_data);
5937 g_object_unref (header);
5938 tny_iterator_next (iter);
5941 /* Trick: do a poke status in order to speed up the signaling
5944 tny_folder_poke_status (folder);
5945 g_object_unref (folder);
5949 g_object_unref (iter);
5950 g_object_unref (headers_list);
5954 modest_ui_actions_view_attachment (GtkAction *action,
5955 ModestWindow *window)
5957 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
5958 modest_msg_view_window_view_attachment (MODEST_MSG_VIEW_WINDOW (window), NULL);
5960 /* not supported window for this action */
5961 g_return_if_reached ();
5966 modest_ui_actions_save_attachments (GtkAction *action,
5967 ModestWindow *window)
5969 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
5971 if (modest_platform_check_memory_low (MODEST_WINDOW(window), TRUE))
5974 modest_msg_view_window_save_attachments (MODEST_MSG_VIEW_WINDOW (window), NULL);
5976 /* not supported window for this action */
5977 g_return_if_reached ();
5982 modest_ui_actions_remove_attachments (GtkAction *action,
5983 ModestWindow *window)
5985 if (MODEST_IS_MAIN_WINDOW (window)) {
5986 modest_ui_actions_on_main_window_remove_attachments (action, MODEST_MAIN_WINDOW (window));
5987 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
5988 modest_msg_view_window_remove_attachments (MODEST_MSG_VIEW_WINDOW (window), FALSE);
5990 /* not supported window for this action */
5991 g_return_if_reached ();
5996 modest_ui_actions_on_settings (GtkAction *action,
6001 dialog = modest_platform_get_global_settings_dialog ();
6002 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (win));
6003 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
6004 gtk_widget_show_all (dialog);
6006 gtk_dialog_run (GTK_DIALOG (dialog));
6008 gtk_widget_destroy (dialog);
6012 modest_ui_actions_on_help (GtkAction *action,
6015 /* Help app is not available at all in fremantle */
6016 #ifndef MODEST_TOOLKIT_HILDON2
6017 const gchar *help_id;
6019 g_return_if_fail (win && GTK_IS_WINDOW(win));
6021 help_id = modest_window_mgr_get_help_id (modest_runtime_get_window_mgr(), win);
6024 modest_platform_show_help (GTK_WINDOW (win), help_id);
6029 modest_ui_actions_on_csm_help (GtkAction *action,
6032 /* Help app is not available at all in fremantle */
6033 #ifndef MODEST_TOOLKIT_HILDON2
6035 const gchar* help_id = NULL;
6036 GtkWidget *folder_view;
6037 TnyFolderStore *folder_store;
6039 g_return_if_fail (win && MODEST_IS_MAIN_WINDOW (win));
6041 /* Get selected folder */
6042 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
6043 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
6044 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
6046 /* Switch help_id */
6047 if (folder_store && TNY_IS_FOLDER (folder_store))
6048 help_id = modest_tny_folder_get_help_id (TNY_FOLDER (folder_store));
6051 g_object_unref (folder_store);
6054 modest_platform_show_help (GTK_WINDOW (win), help_id);
6056 modest_ui_actions_on_help (action, win);
6061 retrieve_contents_cb (ModestMailOperation *mail_op,
6068 /* We only need this callback to show an error in case of
6069 memory low condition */
6070 modest_ui_actions_msg_retrieval_check (mail_op, header, msg);
6074 retrieve_msg_contents_performer (gboolean canceled,
6076 GtkWindow *parent_window,
6077 TnyAccount *account,
6080 ModestMailOperation *mail_op;
6081 TnyList *headers = TNY_LIST (user_data);
6083 if (err || canceled) {
6084 check_memory_full_error ((GtkWidget *) parent_window, err);
6088 /* Create mail operation */
6089 mail_op = modest_mail_operation_new_with_error_handling ((GObject *) parent_window,
6090 modest_ui_actions_disk_operations_error_handler,
6092 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
6093 modest_mail_operation_get_msgs_full (mail_op, headers, retrieve_contents_cb, NULL, NULL);
6096 g_object_unref (mail_op);
6098 g_object_unref (headers);
6099 g_object_unref (account);
6103 modest_ui_actions_on_retrieve_msg_contents (GtkAction *action,
6104 ModestWindow *window)
6106 TnyList *headers = NULL;
6107 TnyAccount *account = NULL;
6108 TnyIterator *iter = NULL;
6109 TnyHeader *header = NULL;
6110 TnyFolder *folder = NULL;
6113 headers = get_selected_headers (window);
6117 /* Pick the account */
6118 iter = tny_list_create_iterator (headers);
6119 header = TNY_HEADER (tny_iterator_get_current (iter));
6120 folder = tny_header_get_folder (header);
6121 account = tny_folder_get_account (folder);
6122 g_object_unref (folder);
6123 g_object_unref (header);
6124 g_object_unref (iter);
6126 /* Connect and perform the message retrieval */
6127 modest_platform_connect_and_perform ((GtkWindow *) window, TRUE,
6128 g_object_ref (account),
6129 retrieve_msg_contents_performer,
6130 g_object_ref (headers));
6133 g_object_unref (account);
6134 g_object_unref (headers);
6138 modest_ui_actions_check_toolbar_dimming_rules (ModestWindow *window)
6140 g_return_if_fail (MODEST_IS_WINDOW (window));
6143 modest_window_check_dimming_rules_group (window, MODEST_DIMMING_RULES_TOOLBAR);
6147 modest_ui_actions_check_menu_dimming_rules (ModestWindow *window)
6149 g_return_if_fail (MODEST_IS_WINDOW (window));
6152 modest_window_check_dimming_rules_group (window, MODEST_DIMMING_RULES_MENU);
6156 modest_ui_actions_on_email_menu_activated (GtkAction *action,
6157 ModestWindow *window)
6159 g_return_if_fail (MODEST_IS_WINDOW (window));
6162 modest_ui_actions_check_menu_dimming_rules (window);
6166 modest_ui_actions_on_edit_menu_activated (GtkAction *action,
6167 ModestWindow *window)
6169 g_return_if_fail (MODEST_IS_WINDOW (window));
6172 modest_ui_actions_check_menu_dimming_rules (window);
6176 modest_ui_actions_on_view_menu_activated (GtkAction *action,
6177 ModestWindow *window)
6179 g_return_if_fail (MODEST_IS_WINDOW (window));
6182 modest_ui_actions_check_menu_dimming_rules (window);
6186 modest_ui_actions_on_format_menu_activated (GtkAction *action,
6187 ModestWindow *window)
6189 g_return_if_fail (MODEST_IS_WINDOW (window));
6192 modest_ui_actions_check_menu_dimming_rules (window);
6196 modest_ui_actions_on_tools_menu_activated (GtkAction *action,
6197 ModestWindow *window)
6199 g_return_if_fail (MODEST_IS_WINDOW (window));
6202 modest_ui_actions_check_menu_dimming_rules (window);
6206 modest_ui_actions_on_attachment_menu_activated (GtkAction *action,
6207 ModestWindow *window)
6209 g_return_if_fail (MODEST_IS_WINDOW (window));
6212 modest_ui_actions_check_menu_dimming_rules (window);
6216 modest_ui_actions_on_toolbar_csm_menu_activated (GtkAction *action,
6217 ModestWindow *window)
6219 g_return_if_fail (MODEST_IS_WINDOW (window));
6222 modest_ui_actions_check_menu_dimming_rules (window);
6226 modest_ui_actions_on_folder_view_csm_menu_activated (GtkAction *action,
6227 ModestWindow *window)
6229 g_return_if_fail (MODEST_IS_WINDOW (window));
6232 modest_ui_actions_check_menu_dimming_rules (window);
6236 modest_ui_actions_on_header_view_csm_menu_activated (GtkAction *action,
6237 ModestWindow *window)
6239 g_return_if_fail (MODEST_IS_WINDOW (window));
6242 modest_ui_actions_check_menu_dimming_rules (window);
6246 modest_ui_actions_on_search_messages (GtkAction *action, ModestWindow *window)
6248 g_return_if_fail (MODEST_IS_WINDOW (window));
6250 /* we check for low-mem; in that case, show a warning, and don't allow
6253 if (modest_platform_check_memory_low (window, TRUE))
6256 modest_platform_show_search_messages (GTK_WINDOW (window));
6260 modest_ui_actions_on_open_addressbook (GtkAction *action, ModestWindow *win)
6262 g_return_if_fail (MODEST_IS_WINDOW (win));
6265 /* we check for low-mem; in that case, show a warning, and don't allow
6266 * for the addressbook
6268 if (modest_platform_check_memory_low (win, TRUE))
6272 modest_platform_show_addressbook (GTK_WINDOW (win));
6277 modest_ui_actions_on_toggle_find_in_page (GtkAction *action,
6278 ModestWindow *window)
6281 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
6283 if (GTK_IS_TOGGLE_ACTION (action))
6284 active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
6288 modest_msg_edit_window_toggle_find_toolbar (MODEST_MSG_EDIT_WINDOW (window),
6293 on_send_receive_finished (ModestMailOperation *mail_op,
6296 GtkWidget *header_view, *folder_view;
6297 TnyFolderStore *folder_store;
6298 ModestMainWindow *main_win = MODEST_MAIN_WINDOW (user_data);
6300 /* Set send/receive operation finished */
6301 modest_main_window_notify_send_receive_completed (main_win);
6303 /* Don't refresh the current folder if there were any errors */
6304 if (modest_mail_operation_get_status (mail_op) !=
6305 MODEST_MAIL_OPERATION_STATUS_SUCCESS)
6308 /* Refresh the current folder if we're viewing a window. We do
6309 this because the user won't be able to see the new mails in
6310 the selected folder after a Send&Receive because it only
6311 performs a poke_status, i.e, only the number of read/unread
6312 messages is updated, but the new headers are not
6314 folder_view = modest_main_window_get_child_widget (main_win,
6315 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
6319 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
6321 /* Do not need to refresh INBOX again because the
6322 update_account does it always automatically */
6323 if (folder_store && TNY_IS_FOLDER (folder_store) &&
6324 tny_folder_get_folder_type (TNY_FOLDER (folder_store)) != TNY_FOLDER_TYPE_INBOX) {
6325 ModestMailOperation *refresh_op;
6327 header_view = modest_main_window_get_child_widget (main_win,
6328 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
6330 /* We do not need to set the contents style
6331 because it hasn't changed. We also do not
6332 need to save the widget status. Just force
6334 refresh_op = modest_mail_operation_new (G_OBJECT (main_win));
6335 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), refresh_op);
6336 modest_mail_operation_refresh_folder (refresh_op, TNY_FOLDER (folder_store),
6337 folder_refreshed_cb, main_win);
6338 g_object_unref (refresh_op);
6342 g_object_unref (folder_store);
6347 modest_ui_actions_on_send_queue_error_happened (TnySendQueue *self,
6353 const gchar* server_name = NULL;
6354 TnyTransportAccount *server_account;
6355 gchar *message = NULL;
6357 /* Don't show anything if the user cancelled something or the
6358 * send receive request is not interactive. Authentication
6359 * errors are managed by the account store so no need to show
6360 * a dialog here again */
6361 if (err->code == TNY_SYSTEM_ERROR_CANCEL ||
6362 err->code == TNY_SERVICE_ERROR_AUTHENTICATE ||
6363 !modest_tny_send_queue_get_requested_send_receive (MODEST_TNY_SEND_QUEUE (self)))
6367 /* Get the server name: */
6369 TNY_TRANSPORT_ACCOUNT (tny_camel_send_queue_get_transport_account (TNY_CAMEL_SEND_QUEUE (self)));
6371 server_name = tny_account_get_hostname (TNY_ACCOUNT (server_account));
6373 g_return_if_reached ();
6375 /* Show the appropriate message text for the GError: */
6376 switch (err->code) {
6377 case TNY_SERVICE_ERROR_CONNECT:
6378 message = g_strdup_printf (_("emev_ib_ui_smtp_server_invalid"), server_name);
6380 case TNY_SERVICE_ERROR_SEND:
6381 message = g_strdup (_CS("sfil_ib_unable_to_send"));
6383 case TNY_SERVICE_ERROR_UNAVAILABLE:
6384 message = g_strdup_printf (_("emev_ib_ui_smtp_server_invalid"), server_name);
6387 g_warning ("%s: unexpected ERROR %d",
6388 __FUNCTION__, err->code);
6389 message = g_strdup (_CS("sfil_ib_unable_to_send"));
6393 modest_platform_run_information_dialog (NULL, message, FALSE);
6395 g_object_unref (server_account);
6399 modest_ui_actions_on_send_queue_status_changed (ModestTnySendQueue *send_queue,
6404 ModestWindow *top_window = NULL;
6405 ModestWindowMgr *mgr = NULL;
6406 GtkWidget *header_view = NULL;
6407 TnyFolder *selected_folder = NULL;
6408 TnyFolderType folder_type;
6410 mgr = modest_runtime_get_window_mgr ();
6411 top_window = modest_window_mgr_get_current_top (mgr);
6416 #ifndef MODEST_TOOLKIT_HILDON2
6417 if (MODEST_IS_MAIN_WINDOW (top_window)) {
6418 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (top_window),
6419 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
6422 if (MODEST_IS_HEADER_WINDOW (top_window)) {
6423 header_view = (GtkWidget *)
6424 modest_header_window_get_header_view (MODEST_HEADER_WINDOW (top_window));
6428 /* Get selected folder */
6429 selected_folder = modest_header_view_get_folder (MODEST_HEADER_VIEW (header_view));
6430 if (!selected_folder)
6433 /* gtk_tree_view_column_queue_resize is only available in GTK+ 2.8 */
6434 #if GTK_CHECK_VERSION(2, 8, 0)
6435 folder_type = modest_tny_folder_guess_folder_type (selected_folder);
6436 if (folder_type == TNY_FOLDER_TYPE_OUTBOX) {
6437 GtkTreeViewColumn *tree_column;
6439 tree_column = gtk_tree_view_get_column (GTK_TREE_VIEW (header_view),
6440 TNY_GTK_HEADER_LIST_MODEL_FROM_COLUMN);
6442 gtk_tree_view_column_queue_resize (tree_column);
6444 #else /* #if GTK_CHECK_VERSION(2, 8, 0) */
6445 gtk_widget_queue_draw (header_view);
6448 #ifndef MODEST_TOOLKIT_HILDON2
6449 /* Rerun dimming rules, because the message could become deletable for example */
6450 modest_window_check_dimming_rules_group (MODEST_WINDOW (top_window),
6451 MODEST_DIMMING_RULES_TOOLBAR);
6452 modest_window_check_dimming_rules_group (MODEST_WINDOW (top_window),
6453 MODEST_DIMMING_RULES_MENU);
6457 g_object_unref (selected_folder);
6461 modest_ui_actions_on_account_connection_error (GtkWindow *parent_window,
6462 TnyAccount *account)
6464 ModestProtocolType protocol_type;
6465 ModestProtocol *protocol;
6466 gchar *error_note = NULL;
6468 protocol_type = modest_tny_account_get_protocol_type (account);
6469 protocol = modest_protocol_registry_get_protocol_by_type (modest_runtime_get_protocol_registry (),
6472 error_note = modest_protocol_get_translation (protocol, MODEST_PROTOCOL_TRANSLATION_ACCOUNT_CONNECTION_ERROR, tny_account_get_hostname (account));
6473 if (error_note == NULL) {
6474 g_warning ("%s: This should not be reached", __FUNCTION__);
6476 modest_platform_run_information_dialog (parent_window, error_note, FALSE);
6477 g_free (error_note);
6482 modest_ui_actions_get_msg_already_deleted_error_msg (ModestWindow *win)
6486 TnyFolderStore *folder = NULL;
6487 TnyAccount *account = NULL;
6488 ModestProtocolType proto;
6489 ModestProtocol *protocol;
6490 TnyHeader *header = NULL;
6492 if (MODEST_IS_MAIN_WINDOW (win)) {
6493 GtkWidget *header_view;
6494 TnyList* headers = NULL;
6496 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
6497 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
6498 headers = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW (header_view));
6499 if (!headers || tny_list_get_length (headers) == 0) {
6501 g_object_unref (headers);
6504 iter = tny_list_create_iterator (headers);
6505 header = TNY_HEADER (tny_iterator_get_current (iter));
6506 folder = TNY_FOLDER_STORE (tny_header_get_folder (header));
6507 g_object_unref (iter);
6508 g_object_unref (headers);
6509 #ifdef MODEST_TOOLKIT_HILDON2
6510 } else if (MODEST_IS_HEADER_WINDOW (win)) {
6511 GtkWidget *header_view;
6512 TnyList* headers = NULL;
6514 header_view = GTK_WIDGET (modest_header_window_get_header_view (MODEST_HEADER_WINDOW (win)));
6515 headers = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW (header_view));
6516 if (!headers || tny_list_get_length (headers) == 0) {
6518 g_object_unref (headers);
6521 iter = tny_list_create_iterator (headers);
6522 header = TNY_HEADER (tny_iterator_get_current (iter));
6523 folder = TNY_FOLDER_STORE (tny_header_get_folder (header));
6524 g_object_unref (iter);
6525 g_object_unref (headers);
6527 } else if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
6528 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
6529 folder = TNY_FOLDER_STORE (tny_header_get_folder (header));
6532 /* Get the account type */
6533 account = tny_folder_get_account (TNY_FOLDER (folder));
6534 proto = modest_tny_account_get_protocol_type (account);
6535 protocol = modest_protocol_registry_get_protocol_by_type (modest_runtime_get_protocol_registry (),
6538 subject = tny_header_dup_subject (header);
6539 msg = modest_protocol_get_translation (protocol, MODEST_PROTOCOL_TRANSLATION_MSG_NOT_AVAILABLE, subject);
6543 msg = g_strdup_printf (_("mail_ni_ui_folder_get_msg_folder_error"));
6547 g_object_unref (account);
6548 g_object_unref (folder);
6549 g_object_unref (header);
6555 modest_ui_actions_on_delete_account (GtkWindow *parent_window,
6556 const gchar *account_name,
6557 const gchar *account_title)
6559 ModestAccountMgr *account_mgr;
6562 ModestProtocol *protocol;
6563 gboolean removed = FALSE;
6565 g_return_val_if_fail (account_name, FALSE);
6566 g_return_val_if_fail (account_title, FALSE);
6568 account_mgr = modest_runtime_get_account_mgr();
6570 /* The warning text depends on the account type: */
6571 protocol = modest_protocol_registry_get_protocol_by_type (modest_runtime_get_protocol_registry (),
6572 modest_account_mgr_get_store_protocol (account_mgr,
6574 txt = modest_protocol_get_translation (protocol,
6575 MODEST_PROTOCOL_TRANSLATION_DELETE_MAILBOX,
6578 txt = g_strdup_printf (_("emev_nc_delete_mailbox"), account_title);
6580 response = modest_platform_run_confirmation_dialog (parent_window, txt);
6584 if (response == GTK_RESPONSE_OK) {
6585 /* Remove account. If it succeeds then it also removes
6586 the account from the ModestAccountView: */
6587 gboolean is_default = FALSE;
6588 gchar *default_account_name = modest_account_mgr_get_default_account (account_mgr);
6589 if (default_account_name && (strcmp (default_account_name, account_name) == 0))
6591 g_free (default_account_name);
6593 removed = modest_account_mgr_remove_account (account_mgr, account_name);
6595 g_warning ("%s: modest_account_mgr_remove_account() failed.\n", __FUNCTION__);