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 <hildon/hildon-pannable-area.h>
53 #include <modest-header-window.h>
56 #ifdef MODEST_PLATFORM_MAEMO
57 #include "maemo/modest-osso-state-saving.h"
58 #endif /* MODEST_PLATFORM_MAEMO */
59 #ifndef MODEST_TOOLKIT_GTK
60 #include "maemo/modest-hildon-includes.h"
61 #include "maemo/modest-connection-specific-smtp-window.h"
62 #endif /* !MODEST_TOOLKIT_GTK */
63 #include <modest-utils.h>
65 #include "widgets/modest-ui-constants.h"
66 #include <widgets/modest-main-window.h>
67 #include <widgets/modest-msg-view-window.h>
68 #include <widgets/modest-account-view-window.h>
69 #include <widgets/modest-details-dialog.h>
70 #include <widgets/modest-attachments-view.h>
71 #include "widgets/modest-folder-view.h"
72 #include "widgets/modest-global-settings-dialog.h"
73 #include "modest-account-mgr-helpers.h"
74 #include "modest-mail-operation.h"
75 #include "modest-text-utils.h"
77 #ifdef MODEST_HAVE_EASYSETUP
78 #ifdef MODEST_TOOLKIT_HILDON2
79 #include "modest-easysetup-wizard-dialog.h"
81 #include "easysetup/modest-easysetup-wizard-dialog.h"
83 #endif /* MODEST_HAVE_EASYSETUP */
85 #include <modest-widget-memory.h>
86 #include <tny-error.h>
87 #include <tny-simple-list.h>
88 #include <tny-msg-view.h>
89 #include <tny-device.h>
90 #include <tny-merge-folder.h>
92 #include <gtkhtml/gtkhtml.h>
94 #define MIN_FREE_SPACE 5 * 1024 * 1024
95 #define MOVE_FOLDER_OK_BUTTON "ok-button"
96 #define MOVE_FOLDER_NEW_BUTTON "new-button"
98 typedef struct _GetMsgAsyncHelper {
100 ModestMailOperation *mail_op;
107 typedef enum _ReplyForwardAction {
111 } ReplyForwardAction;
113 typedef struct _ReplyForwardHelper {
114 guint reply_forward_type;
115 ReplyForwardAction action;
117 GtkWidget *parent_window;
119 } ReplyForwardHelper;
121 typedef struct _MoveToHelper {
122 GtkTreeRowReference *reference;
126 typedef struct _PasteAsAttachmentHelper {
127 ModestMsgEditWindow *window;
129 } PasteAsAttachmentHelper;
133 * The do_headers_action uses this kind of functions to perform some
134 * action to each member of a list of headers
136 typedef void (*HeadersFunc) (TnyHeader *header, ModestWindow *win, gpointer user_data);
138 static void do_headers_action (ModestWindow *win,
142 static void open_msg_cb (ModestMailOperation *mail_op,
149 static void reply_forward_cb (ModestMailOperation *mail_op,
156 static void reply_forward (ReplyForwardAction action, ModestWindow *win);
158 static void folder_refreshed_cb (ModestMailOperation *mail_op,
162 static void on_send_receive_finished (ModestMailOperation *mail_op,
165 static gint header_list_count_uncached_msgs (TnyList *header_list);
167 static gboolean connect_to_get_msg (ModestWindow *win,
168 gint num_of_uncached_msgs,
169 TnyAccount *account);
171 static gboolean remote_folder_has_leave_on_server (TnyFolderStore *folder);
173 static void do_create_folder (GtkWindow *window,
174 TnyFolderStore *parent_folder,
175 const gchar *suggested_name);
177 static GtkWidget* get_folder_view_from_move_to_dialog (GtkWidget *move_to_dialog);
179 static TnyAccount *get_account_from_folder_store (TnyFolderStore *folder_store);
182 * This function checks whether a TnyFolderStore is a pop account
185 remote_folder_has_leave_on_server (TnyFolderStore *folder)
190 g_return_val_if_fail (TNY_IS_FOLDER_STORE (folder), FALSE);
192 account = get_account_from_folder_store (folder);
193 result = (modest_protocol_registry_protocol_type_has_leave_on_server (modest_runtime_get_protocol_registry (),
194 modest_tny_account_get_protocol_type (account)));
195 g_object_unref (account);
200 /* FIXME: this should be merged with the similar code in modest-account-view-window */
201 /* Show the account creation wizard dialog.
202 * returns: TRUE if an account was created. FALSE if the user cancelled.
205 modest_ui_actions_run_account_setup_wizard (ModestWindow *win)
207 gboolean result = FALSE;
209 gint dialog_response;
211 /* there is no such wizard yet */
212 wizard = GTK_WINDOW (modest_platform_get_account_settings_wizard ());
213 modest_window_mgr_set_modal (modest_runtime_get_window_mgr(), GTK_WINDOW (wizard), (GtkWindow *) win);
215 /* always present a main window in the background
216 * we do it here, so we cannot end up with two wizards (as this
217 * function might be called in modest_window_mgr_get_main_window as well */
219 win = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr(),
220 TRUE); /* create if not existent */
222 gtk_window_set_transient_for (GTK_WINDOW (wizard), GTK_WINDOW (win));
224 /* make sure the mainwindow is visible. We need to present the
225 wizard again to give it the focus back. show_all are needed
226 in order to get the widgets properly drawn (MainWindow main
227 paned won't be in its right position and the dialog will be
229 #ifndef MODEST_TOOLKIT_HILDON2
230 gtk_widget_show_all (GTK_WIDGET (win));
231 gtk_widget_show_all (GTK_WIDGET (wizard));
232 gtk_window_present (GTK_WINDOW (win));
233 gtk_window_present (GTK_WINDOW (wizard));
236 dialog_response = gtk_dialog_run (GTK_DIALOG (wizard));
237 gtk_widget_destroy (GTK_WIDGET (wizard));
238 if (gtk_events_pending ())
239 gtk_main_iteration ();
241 if (dialog_response == GTK_RESPONSE_CANCEL) {
244 /* Check whether an account was created: */
245 result = modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
252 modest_ui_actions_on_about (GtkAction *action, ModestWindow *win)
255 const gchar *authors[] = {
256 "Dirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>",
259 about = gtk_about_dialog_new ();
260 gtk_about_dialog_set_name (GTK_ABOUT_DIALOG(about), PACKAGE_NAME);
261 gtk_about_dialog_set_version (GTK_ABOUT_DIALOG(about),PACKAGE_VERSION);
262 gtk_about_dialog_set_copyright (GTK_ABOUT_DIALOG(about),
263 _("Copyright (c) 2006, Nokia Corporation\n"
264 "All rights reserved."));
265 gtk_about_dialog_set_comments (GTK_ABOUT_DIALOG(about),
266 _("a modest e-mail client\n\n"
267 "design and implementation: Dirk-Jan C. Binnema\n"
268 "contributions from the fine people at KC and Ig\n"
269 "uses the tinymail email framework written by Philip van Hoof"));
270 gtk_about_dialog_set_authors (GTK_ABOUT_DIALOG(about), authors);
271 gtk_about_dialog_set_website (GTK_ABOUT_DIALOG(about), "http://modest.garage.maemo.org");
272 gtk_window_set_transient_for (GTK_WINDOW (about), GTK_WINDOW (win));
273 gtk_window_set_modal (GTK_WINDOW (about), TRUE);
275 gtk_dialog_run (GTK_DIALOG (about));
276 gtk_widget_destroy(about);
280 * Gets the list of currently selected messages. If the win is the
281 * main window, then it returns a newly allocated list of the headers
282 * selected in the header view. If win is the msg view window, then
283 * the value returned is a list with just a single header.
285 * The caller of this funcion must free the list.
288 get_selected_headers (ModestWindow *win)
290 if (MODEST_IS_MAIN_WINDOW(win)) {
291 GtkWidget *header_view;
293 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
294 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
295 return modest_header_view_get_selected_headers (MODEST_HEADER_VIEW(header_view));
297 } else if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
298 /* for MsgViewWindows, we simply return a list with one element */
300 TnyList *list = NULL;
302 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
303 if (header != NULL) {
304 list = tny_simple_list_new ();
305 tny_list_prepend (list, G_OBJECT(header));
306 g_object_unref (G_OBJECT(header));
315 static GtkTreeRowReference *
316 get_next_after_selected_headers (ModestHeaderView *header_view)
318 GtkTreeSelection *sel;
319 GList *selected_rows, *node;
321 GtkTreeRowReference *result;
324 model = gtk_tree_view_get_model (GTK_TREE_VIEW (header_view));
325 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
326 selected_rows = gtk_tree_selection_get_selected_rows (sel, NULL);
328 if (selected_rows == NULL)
331 node = g_list_last (selected_rows);
332 path = gtk_tree_path_copy ((GtkTreePath *) node->data);
333 gtk_tree_path_next (path);
335 result = gtk_tree_row_reference_new (model, path);
337 gtk_tree_path_free (path);
338 g_list_foreach (selected_rows, (GFunc) gtk_tree_path_free, NULL);
339 g_list_free (selected_rows);
345 headers_action_mark_as_read (TnyHeader *header,
349 TnyHeaderFlags flags;
351 g_return_if_fail (TNY_IS_HEADER(header));
353 flags = tny_header_get_flags (header);
354 if (flags & TNY_HEADER_FLAG_SEEN) return;
355 tny_header_set_flag (header, TNY_HEADER_FLAG_SEEN);
359 headers_action_mark_as_unread (TnyHeader *header,
363 TnyHeaderFlags flags;
365 g_return_if_fail (TNY_IS_HEADER(header));
367 flags = tny_header_get_flags (header);
368 if (flags & TNY_HEADER_FLAG_SEEN) {
369 tny_header_unset_flag (header, TNY_HEADER_FLAG_SEEN);
373 /** After deleing a message that is currently visible in a window,
374 * show the next message from the list, or close the window if there are no more messages.
377 modest_ui_actions_refresh_message_window_after_delete (ModestMsgViewWindow* win)
379 /* Close msg view window or select next */
380 if (!modest_msg_view_window_select_next_message (win) &&
381 !modest_msg_view_window_select_previous_message (win)) {
383 g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value);
389 modest_ui_actions_on_delete_message (GtkAction *action, ModestWindow *win)
391 TnyList *header_list = NULL;
392 TnyIterator *iter = NULL;
393 TnyHeader *header = NULL;
394 gchar *message = NULL;
397 ModestWindowMgr *mgr;
398 GtkWidget *header_view = NULL;
400 g_return_if_fail (MODEST_IS_WINDOW(win));
402 /* Check first if the header view has the focus */
403 if (MODEST_IS_MAIN_WINDOW (win)) {
405 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
406 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
407 if (!gtk_widget_is_focus (header_view))
411 /* Get the headers, either from the header view (if win is the main window),
412 * or from the message view window: */
413 header_list = get_selected_headers (win);
414 if (!header_list) return;
416 /* Check if any of the headers are already opened, or in the process of being opened */
417 if (MODEST_IS_MAIN_WINDOW (win)) {
418 gint opened_headers = 0;
420 iter = tny_list_create_iterator (header_list);
421 mgr = modest_runtime_get_window_mgr ();
422 while (!tny_iterator_is_done (iter)) {
423 header = TNY_HEADER (tny_iterator_get_current (iter));
425 if (modest_window_mgr_find_registered_header (mgr, header, NULL))
427 g_object_unref (header);
429 tny_iterator_next (iter);
431 g_object_unref (iter);
433 if (opened_headers > 0) {
436 msg = g_strdup_printf (_("mcen_nc_unable_to_delete_n_messages"),
439 modest_platform_run_information_dialog (GTK_WINDOW (win), (const gchar *) msg, FALSE);
442 g_object_unref (header_list);
448 if (tny_list_get_length(header_list) == 1) {
449 iter = tny_list_create_iterator (header_list);
450 header = TNY_HEADER (tny_iterator_get_current (iter));
453 subject = tny_header_dup_subject (header);
455 subject = g_strdup (_("mail_va_no_subject"));
456 desc = g_strdup_printf ("%s", subject);
458 g_object_unref (header);
461 g_object_unref (iter);
463 message = g_strdup_printf(ngettext("emev_nc_delete_message", "emev_nc_delete_messages",
464 tny_list_get_length(header_list)), desc);
466 /* Confirmation dialog */
467 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
471 if (response == GTK_RESPONSE_OK) {
472 ModestWindow *main_window = NULL;
473 ModestWindowMgr *mgr = NULL;
474 GtkTreeModel *model = NULL;
475 GtkTreeSelection *sel = NULL;
476 GList *sel_list = NULL, *tmp = NULL;
477 GtkTreeRowReference *next_row_reference = NULL;
478 GtkTreeRowReference *prev_row_reference = NULL;
479 GtkTreePath *next_path = NULL;
480 GtkTreePath *prev_path = NULL;
481 ModestMailOperation *mail_op = NULL;
483 /* Find last selected row */
484 if (MODEST_IS_MAIN_WINDOW (win)) {
485 model = gtk_tree_view_get_model (GTK_TREE_VIEW (header_view));
486 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
487 sel_list = gtk_tree_selection_get_selected_rows (sel, &model);
488 for (tmp=sel_list; tmp; tmp=tmp->next) {
489 if (tmp->next == NULL) {
490 prev_path = gtk_tree_path_copy((GtkTreePath *) tmp->data);
491 next_path = gtk_tree_path_copy((GtkTreePath *) tmp->data);
493 gtk_tree_path_prev (prev_path);
494 gtk_tree_path_next (next_path);
496 prev_row_reference = gtk_tree_row_reference_new (model, prev_path);
497 next_row_reference = gtk_tree_row_reference_new (model, next_path);
502 /* Disable window dimming management */
503 modest_window_disable_dimming (MODEST_WINDOW(win));
505 /* Remove each header. If it's a view window header_view == NULL */
506 mail_op = modest_mail_operation_new ((GObject *) win);
507 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
509 modest_mail_operation_remove_msgs (mail_op, header_list, FALSE);
510 g_object_unref (mail_op);
512 /* Enable window dimming management */
514 gtk_tree_selection_unselect_all (sel);
516 modest_window_enable_dimming (MODEST_WINDOW(win));
518 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
519 modest_ui_actions_refresh_message_window_after_delete (MODEST_MSG_VIEW_WINDOW (win));
521 /* Get main window */
522 mgr = modest_runtime_get_window_mgr ();
523 main_window = modest_window_mgr_get_main_window (mgr, FALSE); /* don't create */
525 /* Move cursor to next row */
528 /* Select next or previous row */
529 if (gtk_tree_row_reference_valid (next_row_reference)) {
530 gtk_tree_selection_select_path (sel, next_path);
532 else if (gtk_tree_row_reference_valid (prev_row_reference)) {
533 gtk_tree_selection_select_path (sel, prev_path);
537 if (gtk_tree_row_reference_valid (next_row_reference))
538 gtk_tree_row_reference_free (next_row_reference);
539 if (next_path != NULL)
540 gtk_tree_path_free (next_path);
541 if (gtk_tree_row_reference_valid (prev_row_reference))
542 gtk_tree_row_reference_free (prev_row_reference);
543 if (prev_path != NULL)
544 gtk_tree_path_free (prev_path);
547 /* Update toolbar dimming state */
549 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (main_window));
550 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
554 g_list_foreach (sel_list, (GFunc) gtk_tree_path_free, NULL);
555 g_list_free (sel_list);
561 g_object_unref (header_list);
567 /* delete either message or folder, based on where we are */
569 modest_ui_actions_on_delete_message_or_folder (GtkAction *action, ModestWindow *win)
571 g_return_if_fail (MODEST_IS_WINDOW(win));
573 /* Check first if the header view has the focus */
574 if (MODEST_IS_MAIN_WINDOW (win)) {
576 w = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
577 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
578 if (gtk_widget_is_focus (w)) {
579 modest_ui_actions_on_delete_folder (action, MODEST_MAIN_WINDOW(win));
583 modest_ui_actions_on_delete_message (action, win);
587 modest_ui_actions_on_quit (GtkAction *action, ModestWindow *win)
589 ModestWindowMgr *mgr = NULL;
591 #ifdef MODEST_PLATFORM_MAEMO
592 modest_osso_save_state();
593 #endif /* MODEST_PLATFORM_MAEMO */
595 g_debug ("closing down, clearing %d item(s) from operation queue",
596 modest_mail_operation_queue_num_elements
597 (modest_runtime_get_mail_operation_queue()));
599 /* cancel all outstanding operations */
600 modest_mail_operation_queue_cancel_all
601 (modest_runtime_get_mail_operation_queue());
603 g_debug ("queue has been cleared");
606 /* Check if there are opened editing windows */
607 mgr = modest_runtime_get_window_mgr ();
608 modest_window_mgr_close_all_windows (mgr);
610 /* note: when modest-tny-account-store is finalized,
611 it will automatically set all network connections
614 /* gtk_main_quit (); */
618 modest_ui_actions_on_close_window (GtkAction *action, ModestWindow *win)
622 g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value);
624 /* if (MODEST_IS_MSG_VIEW_WINDOW (win)) { */
625 /* gtk_widget_destroy (GTK_WIDGET (win)); */
626 /* } else if (MODEST_IS_MSG_EDIT_WINDOW (win)) { */
627 /* gboolean ret_value; */
628 /* g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value); */
629 /* } else if (MODEST_IS_WINDOW (win)) { */
630 /* gtk_widget_destroy (GTK_WIDGET (win)); */
632 /* g_return_if_reached (); */
637 modest_ui_actions_on_add_to_contacts (GtkAction *action, ModestWindow *win)
639 GtkClipboard *clipboard = NULL;
640 gchar *selection = NULL;
642 clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
643 selection = gtk_clipboard_wait_for_text (clipboard);
645 /* Question: why is the clipboard being used here?
646 * It doesn't really make a lot of sense. */
650 modest_address_book_add_address (selection);
656 modest_ui_actions_on_accounts (GtkAction *action,
659 /* This is currently only implemented for Maemo */
660 if (!modest_account_mgr_has_accounts (modest_runtime_get_account_mgr(), TRUE)) {
661 if (!modest_ui_actions_run_account_setup_wizard (win))
662 g_debug ("%s: wizard was already running", __FUNCTION__);
666 /* Show the list of accounts */
667 GtkWindow *account_win = GTK_WINDOW (modest_account_view_window_new ());
669 /* The accounts dialog must be modal */
670 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (account_win), (GtkWindow *) win);
671 modest_utils_show_dialog_and_forget (GTK_WINDOW (win), GTK_DIALOG (account_win));
676 modest_ui_actions_on_smtp_servers (GtkAction *action, ModestWindow *win)
678 /* This is currently only implemented for Maemo,
679 * because it requires an API (libconic) to detect different connection
682 #ifndef MODEST_TOOLKIT_GTK /* Defined in config.h */
684 /* Create the window if necessary: */
685 GtkWidget *specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
686 modest_connection_specific_smtp_window_fill_with_connections (
687 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (specific_window),
688 modest_runtime_get_account_mgr());
690 /* Show the window: */
691 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (),
692 GTK_WINDOW (specific_window), (GtkWindow *) win);
693 gtk_widget_show (specific_window);
694 #endif /* !MODEST_TOOLKIT_GTK */
698 modest_ui_actions_compose_msg(ModestWindow *win,
701 const gchar *bcc_str,
702 const gchar *subject_str,
703 const gchar *body_str,
705 gboolean set_as_modified)
707 gchar *account_name = NULL;
709 TnyAccount *account = NULL;
710 TnyFolder *folder = NULL;
711 gchar *from_str = NULL, *signature = NULL, *body = NULL;
712 gboolean use_signature = FALSE;
713 ModestWindow *msg_win = NULL;
714 ModestAccountMgr *mgr = modest_runtime_get_account_mgr();
715 ModestTnyAccountStore *store = modest_runtime_get_account_store();
716 GnomeVFSFileSize total_size, allowed_size;
718 /* we check for low-mem; in that case, show a warning, and don't allow
719 * composing a message with attachments
721 if (attachments && modest_platform_check_memory_low (win, TRUE))
724 #ifdef MODEST_TOOLKIT_HILDON2
725 account_name = g_strdup (modest_window_get_active_account(win));
728 account_name = modest_account_mgr_get_default_account(mgr);
731 g_printerr ("modest: no account found\n");
734 account = modest_tny_account_store_get_server_account (store, account_name, TNY_ACCOUNT_TYPE_STORE);
736 g_printerr ("modest: failed to get tnyaccount for '%s'\n", account_name);
739 folder = modest_tny_account_get_special_folder (account, TNY_FOLDER_TYPE_DRAFTS);
741 g_printerr ("modest: failed to find Drafts folder\n");
744 from_str = modest_account_mgr_get_from_string (mgr, account_name);
746 g_printerr ("modest: failed get from string for '%s'\n", account_name);
750 signature = modest_account_mgr_get_signature (mgr, account_name, &use_signature);
751 if (body_str != NULL) {
752 body = use_signature ? g_strconcat(body_str, "\n--\n", signature, NULL) : g_strdup(body_str);
754 body = use_signature ? g_strconcat("\n--\n", signature, NULL) : g_strdup("");
757 msg = modest_tny_msg_new (to_str, from_str, cc_str, bcc_str, subject_str, body, NULL, NULL, NULL);
759 g_printerr ("modest: failed to create new msg\n");
763 /* Create and register edit window */
764 /* This is destroyed by TODO. */
766 allowed_size = MODEST_MAX_ATTACHMENT_SIZE;
767 msg_win = modest_msg_edit_window_new (msg, account_name, FALSE);
769 if (!modest_window_mgr_register_window (modest_runtime_get_window_mgr(), msg_win, NULL)) {
770 gtk_widget_destroy (GTK_WIDGET (msg_win));
773 modest_msg_edit_window_set_modified (MODEST_MSG_EDIT_WINDOW (msg_win), set_as_modified);
774 gtk_widget_show_all (GTK_WIDGET (msg_win));
776 while (attachments) {
778 modest_msg_edit_window_attach_file_one((ModestMsgEditWindow *)msg_win,
779 attachments->data, allowed_size);
781 if (total_size > allowed_size) {
782 g_warning ("%s: total size: %u",
783 __FUNCTION__, (unsigned int)total_size);
786 allowed_size -= total_size;
788 attachments = g_slist_next(attachments);
795 g_free (account_name);
797 g_object_unref (G_OBJECT(account));
799 g_object_unref (G_OBJECT(folder));
801 g_object_unref (G_OBJECT(msg));
805 modest_ui_actions_on_new_msg (GtkAction *action, ModestWindow *win)
807 /* if there are no accounts yet, just show the wizard */
808 if (!modest_account_mgr_has_accounts (modest_runtime_get_account_mgr(), TRUE))
809 if (!modest_ui_actions_run_account_setup_wizard (win))
812 modest_ui_actions_compose_msg(win, NULL, NULL, NULL, NULL, NULL, NULL, FALSE);
817 modest_ui_actions_msg_retrieval_check (ModestMailOperation *mail_op,
821 ModestMailOperationStatus status;
823 /* If there is no message or the operation was not successful */
824 status = modest_mail_operation_get_status (mail_op);
825 if (!msg || status != MODEST_MAIL_OPERATION_STATUS_SUCCESS) {
828 /* If it's a memory low issue, then show a banner */
829 error = modest_mail_operation_get_error (mail_op);
830 if (error && error->domain == MODEST_MAIL_OPERATION_ERROR &&
831 error->code == MODEST_MAIL_OPERATION_ERROR_LOW_MEMORY) {
832 GObject *source = modest_mail_operation_get_source (mail_op);
833 modest_platform_run_information_dialog (GTK_IS_WINDOW (source) ? GTK_WINDOW (source) : NULL,
834 dgettext("ke-recv","memr_ib_operation_disabled"),
836 g_object_unref (source);
839 if (error && ((error->code == TNY_SERVICE_ERROR_NO_SUCH_MESSAGE) ||
840 error->code == TNY_SERVICE_ERROR_MESSAGE_NOT_AVAILABLE)) {
841 gchar *subject, *msg;
842 subject = tny_header_dup_subject (header);
844 subject = g_strdup (_("mail_va_no_subject"));;
845 msg = g_strdup_printf (_("emev_ni_ui_imap_message_not_available_in_server"),
847 modest_platform_run_information_dialog (NULL, msg, FALSE);
852 /* Remove the header from the preregistered uids */
853 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (),
871 OpenMsgBannerInfo *banner_info;
872 GHashTable *row_refs_per_header;
876 open_msg_banner_idle (gpointer userdata)
878 OpenMsgBannerInfo *banner_info = (OpenMsgBannerInfo *) userdata;
880 gdk_threads_enter ();
881 banner_info->idle_handler = 0;
882 banner_info->banner = modest_platform_animation_banner (NULL, NULL, banner_info->message);
884 g_object_ref (banner_info->banner);
886 gdk_threads_leave ();
893 open_msg_cb (ModestMailOperation *mail_op,
900 ModestWindowMgr *mgr = NULL;
901 ModestWindow *parent_win = NULL;
902 ModestWindow *win = NULL;
903 TnyFolderType folder_type = TNY_FOLDER_TYPE_UNKNOWN;
904 gchar *account = NULL;
906 gboolean open_in_editor = FALSE;
907 OpenMsgHelper *helper = (OpenMsgHelper *) user_data;
909 /* Do nothing if there was any problem with the mail
910 operation. The error will be shown by the error_handler of
911 the mail operation */
912 if (!modest_ui_actions_msg_retrieval_check (mail_op, header, msg))
915 parent_win = (ModestWindow *) modest_mail_operation_get_source (mail_op);
916 folder = tny_header_get_folder (header);
918 /* Mark header as read */
919 headers_action_mark_as_read (header, MODEST_WINDOW(parent_win), NULL);
921 /* Gets folder type (OUTBOX headers will be opened in edit window */
922 if (modest_tny_folder_is_local_folder (folder)) {
923 folder_type = modest_tny_folder_get_local_or_mmc_folder_type (folder);
924 if (folder_type == TNY_FOLDER_TYPE_INVALID)
925 g_warning ("%s: BUG: TNY_FOLDER_TYPE_INVALID", __FUNCTION__);
929 if (folder_type == TNY_FOLDER_TYPE_OUTBOX) {
930 TnyTransportAccount *traccount = NULL;
931 ModestTnyAccountStore *accstore = modest_runtime_get_account_store();
932 traccount = modest_tny_account_store_get_transport_account_from_outbox_header(accstore, header);
934 ModestTnySendQueue *send_queue = NULL;
935 ModestTnySendQueueStatus status;
937 account = g_strdup(modest_tny_account_get_parent_modest_account_name_for_server_account(
938 TNY_ACCOUNT(traccount)));
939 send_queue = modest_runtime_get_send_queue(traccount, TRUE);
940 if (TNY_IS_SEND_QUEUE (send_queue)) {
941 msg_id = modest_tny_send_queue_get_msg_id (header);
942 status = modest_tny_send_queue_get_msg_status(send_queue, msg_id);
943 /* Only open messages in outbox with the editor if they are in Failed state */
944 if (status == MODEST_TNY_SEND_QUEUE_FAILED) {
945 open_in_editor = TRUE;
949 g_object_unref(traccount);
951 g_warning("Cannot get transport account for message in outbox!!");
953 } else if (folder_type == TNY_FOLDER_TYPE_DRAFTS) {
954 open_in_editor = TRUE; /* Open in editor if the message is in the Drafts folder */
959 account = g_strdup (modest_window_get_active_account (MODEST_WINDOW (parent_win)));
961 account = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
963 if (open_in_editor) {
964 ModestAccountMgr *mgr = modest_runtime_get_account_mgr ();
965 gchar *from_header = NULL, *acc_name;
967 from_header = tny_header_dup_from (header);
969 /* we cannot edit without a valid account... */
970 if (!modest_account_mgr_has_accounts(mgr, TRUE)) {
971 if (!modest_ui_actions_run_account_setup_wizard(parent_win)) {
972 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (),
974 g_free (from_header);
979 acc_name = modest_utils_get_account_name_from_recipient (from_header);
980 g_free (from_header);
986 win = modest_msg_edit_window_new (msg, account, TRUE);
988 gchar *uid = modest_tny_folder_get_header_unique_id (header);
989 GtkTreeRowReference *row_reference;
991 row_reference = (GtkTreeRowReference *) g_hash_table_lookup (helper->row_refs_per_header, header);
992 if (row_reference && helper->model) {
993 win = modest_msg_view_window_new_with_header_model (msg, account, (const gchar*) uid,
994 helper->model, row_reference);
996 win = modest_msg_view_window_new_for_attachment (msg, account, (const gchar*) uid);
1001 /* Register and show new window */
1003 mgr = modest_runtime_get_window_mgr ();
1004 if (!modest_window_mgr_register_window (mgr, win, NULL)) {
1005 gtk_widget_destroy (GTK_WIDGET (win));
1008 gtk_widget_show_all (GTK_WIDGET(win));
1011 /* Update toolbar dimming state */
1012 if (MODEST_IS_MAIN_WINDOW (parent_win)) {
1013 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (parent_win));
1019 g_object_unref (parent_win);
1020 g_object_unref (folder);
1024 is_memory_full_error (GError *error)
1026 gboolean enough_free_space = TRUE;
1027 GnomeVFSURI *cache_dir_uri;
1028 const gchar *cache_dir;
1029 GnomeVFSFileSize free_space;
1031 cache_dir = tny_account_store_get_cache_dir (TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()));
1032 cache_dir_uri = gnome_vfs_uri_new (cache_dir);
1033 if (gnome_vfs_get_volume_free_space (cache_dir_uri, &free_space) == GNOME_VFS_OK) {
1034 if (free_space < MIN_FREE_SPACE)
1035 enough_free_space = FALSE;
1037 gnome_vfs_uri_unref (cache_dir_uri);
1039 if ((error->code == TNY_SYSTEM_ERROR_MEMORY ||
1040 /* When asking for a mail and no space left on device
1041 tinymail returns this error */
1042 error->code == TNY_SERVICE_ERROR_MESSAGE_NOT_AVAILABLE ||
1043 /* When the folder summary could not be read or
1045 error->code == TNY_IO_ERROR_WRITE ||
1046 error->code == TNY_IO_ERROR_READ) &&
1047 !enough_free_space) {
1055 check_memory_full_error (GtkWidget *parent_window, GError *err)
1060 if (is_memory_full_error (err))
1061 modest_platform_information_banner (parent_window,
1062 NULL, dgettext("ke-recv",
1063 "cerm_device_memory_full"));
1064 else if (err->code == TNY_SYSTEM_ERROR_MEMORY)
1065 /* If the account was created in memory full
1066 conditions then tinymail won't be able to
1067 connect so it'll return this error code */
1068 modest_platform_information_banner (parent_window,
1069 NULL, _("emev_ui_imap_inbox_select_error"));
1077 modest_ui_actions_disk_operations_error_handler (ModestMailOperation *mail_op,
1080 const GError *error;
1081 GObject *win = NULL;
1082 ModestMailOperationStatus status;
1084 win = modest_mail_operation_get_source (mail_op);
1085 error = modest_mail_operation_get_error (mail_op);
1086 status = modest_mail_operation_get_status (mail_op);
1088 /* If the mail op has been cancelled then it's not an error:
1089 don't show any message */
1090 if (status != MODEST_MAIL_OPERATION_STATUS_CANCELED) {
1091 if (is_memory_full_error ((GError *) error)) {
1092 modest_platform_information_banner ((GtkWidget *) win,
1093 NULL, dgettext("ke-recv",
1094 "cerm_device_memory_full"));
1095 } else if (error->code == TNY_SYSTEM_ERROR_MEMORY) {
1096 modest_platform_information_banner ((GtkWidget *) win,
1097 NULL, _("emev_ui_imap_inbox_select_error"));
1098 } else if (error->domain == MODEST_MAIL_OPERATION_ERROR &&
1099 error->code == MODEST_MAIL_OPERATION_ERROR_FILE_IO) {
1100 modest_platform_information_banner ((GtkWidget *) win,
1101 NULL, dgettext ("hildon-common-strings", "sfil_ni_unable_to_open_file_not_found"));
1102 } else if (user_data) {
1103 modest_platform_information_banner ((GtkWidget *) win,
1109 g_object_unref (win);
1113 * Returns the account a list of headers belongs to. It returns a
1114 * *new* reference so don't forget to unref it
1117 get_account_from_header_list (TnyList *headers)
1119 TnyAccount *account = NULL;
1121 if (tny_list_get_length (headers) > 0) {
1122 TnyIterator *iter = tny_list_create_iterator (headers);
1123 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter));
1124 TnyFolder *folder = tny_header_get_folder (header);
1127 g_object_unref (header);
1129 while (!tny_iterator_is_done (iter)) {
1130 header = TNY_HEADER (tny_iterator_get_current (iter));
1131 folder = tny_header_get_folder (header);
1134 g_object_unref (header);
1136 tny_iterator_next (iter);
1141 account = tny_folder_get_account (folder);
1142 g_object_unref (folder);
1146 g_object_unref (header);
1148 g_object_unref (iter);
1154 foreach_unregister_headers (gpointer data,
1157 ModestWindowMgr *mgr = (ModestWindowMgr *) user_data;
1158 TnyHeader *header = TNY_HEADER (data);
1160 modest_window_mgr_unregister_header (mgr, header);
1164 open_msgs_helper_destroyer (gpointer user_data)
1166 OpenMsgHelper *helper = (OpenMsgHelper *) user_data;
1168 if (helper->banner_info) {
1169 g_free (helper->banner_info->message);
1170 if (helper->banner_info->idle_handler > 0) {
1171 g_source_remove (helper->banner_info->idle_handler);
1172 helper->banner_info->idle_handler = 0;
1174 if (helper->banner_info->banner != NULL) {
1175 gtk_widget_destroy (helper->banner_info->banner);
1176 g_object_unref (helper->banner_info->banner);
1177 helper->banner_info->banner = NULL;
1179 g_slice_free (OpenMsgBannerInfo, helper->banner_info);
1180 helper->banner_info = NULL;
1182 g_object_unref (helper->model);
1183 g_object_unref (helper->headers);
1184 g_hash_table_destroy (helper->row_refs_per_header);
1185 g_slice_free (OpenMsgHelper, helper);
1189 open_msgs_performer(gboolean canceled,
1191 GtkWindow *parent_window,
1192 TnyAccount *account,
1195 ModestMailOperation *mail_op = NULL;
1197 ModestProtocolType proto;
1198 TnyList *not_opened_headers;
1199 TnyConnectionStatus status;
1200 gboolean show_open_draft = FALSE;
1201 OpenMsgHelper *helper = NULL;
1203 helper = (OpenMsgHelper *) user_data;
1204 not_opened_headers = helper->headers;
1206 status = tny_account_get_connection_status (account);
1207 if (err || canceled) {
1208 /* Unregister the already registered headers */
1209 tny_list_foreach (not_opened_headers, foreach_unregister_headers,
1210 modest_runtime_get_window_mgr ());
1211 /* Free the helper */
1212 open_msgs_helper_destroyer (helper);
1214 /* In memory full conditions we could get this error here */
1215 check_memory_full_error ((GtkWidget *) parent_window, err);
1220 /* Get the error message depending on the protocol */
1221 proto = modest_tny_account_get_protocol_type (account);
1222 if (proto == MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
1223 proto = MODEST_PROTOCOLS_STORE_MAILDIR;
1226 /* Create the error messages */
1227 if (tny_list_get_length (not_opened_headers) == 1) {
1228 ModestProtocol *protocol;
1229 ModestProtocolRegistry *protocol_registry;
1234 protocol_registry = modest_runtime_get_protocol_registry ();
1235 iter = tny_list_create_iterator (not_opened_headers);
1236 header = TNY_HEADER (tny_iterator_get_current (iter));
1237 subject = tny_header_dup_subject (header);
1239 protocol = modest_protocol_registry_get_protocol_by_type (protocol_registry, proto);
1240 error_msg = modest_protocol_get_translation (protocol, MODEST_PROTOCOL_TRANSLATION_MSG_NOT_AVAILABLE, subject);
1243 g_object_unref (header);
1244 g_object_unref (iter);
1246 if (error_msg == NULL) {
1247 error_msg = g_strdup (_("mail_ni_ui_folder_get_msg_folder_error"));
1250 if (modest_protocol_registry_protocol_type_has_tag (protocol_registry,
1252 MODEST_PROTOCOL_REGISTRY_LOCAL_STORE_PROTOCOLS)) {
1256 TnyFolderType folder_type;
1258 iter = tny_list_create_iterator (not_opened_headers);
1259 header = TNY_HEADER (tny_iterator_get_current (iter));
1260 folder = tny_header_get_folder (header);
1261 folder_type = modest_tny_folder_get_local_or_mmc_folder_type (folder);
1262 show_open_draft = (folder_type == TNY_FOLDER_TYPE_DRAFTS);
1263 g_object_unref (folder);
1264 g_object_unref (header);
1265 g_object_unref (iter);
1268 error_msg = g_strdup (_("mail_ni_ui_folder_get_msg_folder_error"));
1271 /* Create the mail operation */
1273 modest_mail_operation_new_with_error_handling ((GObject *) parent_window,
1274 modest_ui_actions_disk_operations_error_handler,
1276 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
1279 if (show_open_draft) {
1280 helper->banner_info = g_slice_new (OpenMsgBannerInfo);
1281 helper->banner_info->message = g_strdup (_("mail_ib_opening_draft_message"));
1282 helper->banner_info->banner = NULL;
1283 helper->banner_info->idle_handler = g_timeout_add (500, open_msg_banner_idle,
1284 helper->banner_info);
1287 modest_mail_operation_get_msgs_full (mail_op,
1291 open_msgs_helper_destroyer);
1296 g_object_unref (mail_op);
1297 g_object_unref (account);
1301 * This function is used by both modest_ui_actions_on_open and
1302 * modest_ui_actions_on_header_activated. This way we always do the
1303 * same when trying to open messages.
1306 open_msgs_from_headers (TnyList *headers, GtkTreePath *path, ModestWindow *win)
1308 ModestWindowMgr *mgr = NULL;
1309 TnyIterator *iter = NULL, *iter_not_opened = NULL;
1310 TnyList *not_opened_headers = NULL;
1311 TnyHeaderFlags flags = 0;
1312 TnyAccount *account;
1313 gint uncached_msgs = 0;
1314 GtkWidget *header_view = NULL;
1315 GtkTreeModel *model;
1316 GHashTable *refs_for_headers;
1317 OpenMsgHelper *helper;
1318 GtkTreeSelection *sel;
1319 GList *sel_list = NULL, *sel_list_iter = NULL;
1321 g_return_if_fail (headers != NULL);
1323 /* Check that only one message is selected for opening */
1324 if (tny_list_get_length (headers) != 1) {
1325 modest_platform_information_banner ((win) ? GTK_WIDGET (win) : NULL,
1326 NULL, _("mcen_ib_select_one_message"));
1330 mgr = modest_runtime_get_window_mgr ();
1331 iter = tny_list_create_iterator (headers);
1333 /* Get the account */
1334 account = get_account_from_header_list (headers);
1339 if (!MODEST_IS_MAIN_WINDOW (win) && path == NULL)
1343 if (MODEST_IS_MAIN_WINDOW (win)) {
1344 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
1345 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1346 #ifdef MODEST_TOOLKIT_HILDON2
1347 } else if (MODEST_IS_HEADER_WINDOW (win)){
1349 header_view = GTK_WIDGET (modest_header_window_get_header_view (MODEST_HEADER_WINDOW (win)));
1355 model = gtk_tree_view_get_model (GTK_TREE_VIEW (header_view));
1356 if (path && MODEST_IS_HEADER_WINDOW (win)) {
1357 sel_list = g_list_prepend (NULL, gtk_tree_path_copy (path));
1359 /* Get the selections, we need to get the references to the
1360 rows here because the treeview/model could dissapear (the
1361 user might want to select another folder)*/
1362 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
1363 sel_list = gtk_tree_selection_get_selected_rows (sel, &model);
1365 refs_for_headers = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL,
1366 (GDestroyNotify) gtk_tree_row_reference_free);
1368 /* Look if we already have a message view for each header. If
1369 true, then remove the header from the list of headers to
1371 sel_list_iter = sel_list;
1373 not_opened_headers = tny_simple_list_new ();
1374 while (!tny_iterator_is_done (iter) && sel_list_iter) {
1376 ModestWindow *window = NULL;
1377 TnyHeader *header = NULL;
1378 gboolean found = FALSE;
1380 header = TNY_HEADER (tny_iterator_get_current (iter));
1382 flags = tny_header_get_flags (header);
1385 found = modest_window_mgr_find_registered_header (mgr, header, &window);
1387 /* Do not open again the message and present the
1388 window to the user */
1391 #ifndef MODEST_TOOLKIT_HILDON2
1392 gtk_window_present (GTK_WINDOW (window));
1395 /* the header has been registered already, we don't do
1396 * anything but wait for the window to come up*/
1397 g_debug ("header %p already registered, waiting for window", header);
1400 GtkTreeRowReference *row_reference;
1402 tny_list_append (not_opened_headers, G_OBJECT (header));
1403 /* Create a new row reference and add it to the hash table */
1404 row_reference = gtk_tree_row_reference_new (model, (GtkTreePath *) sel_list_iter->data);
1405 g_hash_table_insert (refs_for_headers, header, row_reference);
1409 g_object_unref (header);
1412 tny_iterator_next (iter);
1413 sel_list_iter = g_list_next (sel_list_iter);
1415 g_object_unref (iter);
1417 g_list_foreach (sel_list, (GFunc) gtk_tree_path_free, NULL);
1418 g_list_free (sel_list);
1420 /* Open each message */
1421 if (tny_list_get_length (not_opened_headers) == 0) {
1422 g_hash_table_destroy (refs_for_headers);
1426 /* If some messages would have to be downloaded, ask the user to
1427 * make a connection. It's generally easier to do this here (in the mainloop)
1428 * than later in a thread:
1430 if (tny_list_get_length (not_opened_headers) > 0) {
1431 uncached_msgs = header_list_count_uncached_msgs (not_opened_headers);
1433 if (uncached_msgs > 0) {
1434 /* Allways download if we are online. */
1435 if (!tny_device_is_online (modest_runtime_get_device ())) {
1438 /* If ask for user permission to download the messages */
1439 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
1440 ngettext("mcen_nc_get_msg",
1444 /* End if the user does not want to continue */
1445 if (response == GTK_RESPONSE_CANCEL) {
1446 g_hash_table_destroy (refs_for_headers);
1453 /* Register the headers before actually creating the windows: */
1454 iter_not_opened = tny_list_create_iterator (not_opened_headers);
1455 while (!tny_iterator_is_done (iter_not_opened)) {
1456 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter_not_opened));
1458 modest_window_mgr_register_header (mgr, header, NULL);
1459 g_object_unref (header);
1461 tny_iterator_next (iter_not_opened);
1463 g_object_unref (iter_not_opened);
1464 iter_not_opened = NULL;
1466 /* Create the helper. We need to get a reference to the model
1467 here because it could change while the message is readed
1468 (the user could switch between folders) */
1469 helper = g_slice_new (OpenMsgHelper);
1470 helper->model = g_object_ref (model);
1471 helper->headers = g_object_ref (not_opened_headers);
1472 helper->row_refs_per_header = refs_for_headers;
1473 helper->banner_info = NULL;
1475 /* Connect to the account and perform */
1476 if (uncached_msgs > 0) {
1477 modest_platform_connect_and_perform ((GtkWindow *) win, TRUE, g_object_ref (account),
1478 open_msgs_performer, helper);
1480 /* Call directly the performer, do not need to connect */
1481 open_msgs_performer (FALSE, NULL, (GtkWindow *) win,
1482 g_object_ref (account), helper);
1487 g_object_unref (account);
1488 if (not_opened_headers)
1489 g_object_unref (not_opened_headers);
1493 modest_ui_actions_on_open (GtkAction *action, ModestWindow *win)
1497 /* we check for low-mem; in that case, show a warning, and don't allow
1500 if (modest_platform_check_memory_low (MODEST_WINDOW(win), TRUE))
1504 headers = get_selected_headers (win);
1509 open_msgs_from_headers (headers, NULL, win);
1511 g_object_unref(headers);
1514 static ReplyForwardHelper*
1515 create_reply_forward_helper (ReplyForwardAction action,
1517 guint reply_forward_type,
1520 ReplyForwardHelper *rf_helper = NULL;
1521 const gchar *active_acc = modest_window_get_active_account (win);
1523 rf_helper = g_slice_new0 (ReplyForwardHelper);
1524 rf_helper->reply_forward_type = reply_forward_type;
1525 rf_helper->action = action;
1526 rf_helper->parent_window = (MODEST_IS_WINDOW (win)) ? GTK_WIDGET (win) : NULL;
1527 rf_helper->header = (header) ? g_object_ref (header) : NULL;
1528 rf_helper->account_name = (active_acc) ?
1529 g_strdup (active_acc) :
1530 modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
1536 free_reply_forward_helper (gpointer data)
1538 ReplyForwardHelper *helper;
1540 helper = (ReplyForwardHelper *) data;
1541 g_free (helper->account_name);
1543 g_object_unref (helper->header);
1544 g_slice_free (ReplyForwardHelper, helper);
1548 reply_forward_cb (ModestMailOperation *mail_op,
1555 TnyMsg *new_msg = NULL;
1556 ReplyForwardHelper *rf_helper;
1557 ModestWindow *msg_win = NULL;
1558 ModestEditType edit_type;
1560 TnyAccount *account = NULL;
1561 ModestWindowMgr *mgr = NULL;
1562 gchar *signature = NULL;
1563 gboolean use_signature;
1565 /* If there was any error. The mail operation could be NULL,
1566 this means that we already have the message downloaded and
1567 that we didn't do a mail operation to retrieve it */
1568 rf_helper = (ReplyForwardHelper *) user_data;
1569 if (mail_op && !modest_ui_actions_msg_retrieval_check (mail_op, header, msg))
1572 from = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(),
1573 rf_helper->account_name);
1574 signature = modest_account_mgr_get_signature (modest_runtime_get_account_mgr(),
1575 rf_helper->account_name,
1578 /* Create reply mail */
1579 switch (rf_helper->action) {
1582 modest_tny_msg_create_reply_msg (msg, header, from,
1583 (use_signature) ? signature : NULL,
1584 rf_helper->reply_forward_type,
1585 MODEST_TNY_MSG_REPLY_MODE_SENDER);
1587 case ACTION_REPLY_TO_ALL:
1589 modest_tny_msg_create_reply_msg (msg, header, from,
1590 (use_signature) ? signature : NULL,
1591 rf_helper->reply_forward_type,
1592 MODEST_TNY_MSG_REPLY_MODE_ALL);
1593 edit_type = MODEST_EDIT_TYPE_REPLY;
1595 case ACTION_FORWARD:
1597 modest_tny_msg_create_forward_msg (msg, from, (use_signature) ? signature : NULL,
1598 rf_helper->reply_forward_type);
1599 edit_type = MODEST_EDIT_TYPE_FORWARD;
1602 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (),
1604 g_return_if_reached ();
1612 g_warning ("%s: failed to create message\n", __FUNCTION__);
1616 account = modest_tny_account_store_get_server_account (modest_runtime_get_account_store(),
1617 rf_helper->account_name,
1618 TNY_ACCOUNT_TYPE_STORE);
1620 g_warning ("%s: failed to get tnyaccount for '%s'\n", __FUNCTION__, rf_helper->account_name);
1624 /* Create and register the windows */
1625 msg_win = modest_msg_edit_window_new (new_msg, rf_helper->account_name, FALSE);
1626 mgr = modest_runtime_get_window_mgr ();
1627 modest_window_mgr_register_window (mgr, msg_win, (ModestWindow *) rf_helper->parent_window);
1629 if (rf_helper->parent_window != NULL) {
1630 gdouble parent_zoom;
1632 parent_zoom = modest_window_get_zoom (MODEST_WINDOW (rf_helper->parent_window));
1633 modest_window_set_zoom (msg_win, parent_zoom);
1636 /* Show edit window */
1637 gtk_widget_show_all (GTK_WIDGET (msg_win));
1640 /* We always unregister the header because the message is
1641 forwarded or replied so the original one is no longer
1643 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (),
1646 g_object_unref (G_OBJECT (new_msg));
1648 g_object_unref (G_OBJECT (account));
1649 free_reply_forward_helper (rf_helper);
1652 /* Checks a list of headers. If any of them are not currently
1653 * downloaded (CACHED) then returns TRUE else returns FALSE.
1656 header_list_count_uncached_msgs (TnyList *header_list)
1659 gint uncached_messages = 0;
1661 iter = tny_list_create_iterator (header_list);
1662 while (!tny_iterator_is_done (iter)) {
1665 header = TNY_HEADER (tny_iterator_get_current (iter));
1667 if (!(tny_header_get_flags (header) & TNY_HEADER_FLAG_CACHED))
1668 uncached_messages ++;
1669 g_object_unref (header);
1672 tny_iterator_next (iter);
1674 g_object_unref (iter);
1676 return uncached_messages;
1679 /* Returns FALSE if the user does not want to download the
1680 * messages. Returns TRUE if the user allowed the download.
1683 connect_to_get_msg (ModestWindow *win,
1684 gint num_of_uncached_msgs,
1685 TnyAccount *account)
1687 GtkResponseType response;
1689 /* Allways download if we are online. */
1690 if (tny_device_is_online (modest_runtime_get_device ()))
1693 /* If offline, then ask for user permission to download the messages */
1694 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
1695 ngettext("mcen_nc_get_msg",
1697 num_of_uncached_msgs));
1699 if (response == GTK_RESPONSE_CANCEL)
1702 return modest_platform_connect_and_wait((GtkWindow *) win, account);
1706 reply_forward_performer (gboolean canceled,
1708 GtkWindow *parent_window,
1709 TnyAccount *account,
1712 ReplyForwardHelper *rf_helper = NULL;
1713 ModestMailOperation *mail_op;
1715 rf_helper = (ReplyForwardHelper *) user_data;
1717 if (canceled || err) {
1718 free_reply_forward_helper (rf_helper);
1722 /* Retrieve the message */
1723 modest_window_mgr_register_header (modest_runtime_get_window_mgr (), rf_helper->header, NULL);
1724 mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT (parent_window),
1725 modest_ui_actions_disk_operations_error_handler,
1727 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
1728 modest_mail_operation_get_msg (mail_op, rf_helper->header, TRUE, reply_forward_cb, rf_helper);
1731 g_object_unref(mail_op);
1735 * Common code for the reply and forward actions
1738 reply_forward (ReplyForwardAction action, ModestWindow *win)
1740 ReplyForwardHelper *rf_helper = NULL;
1741 guint reply_forward_type;
1743 g_return_if_fail (MODEST_IS_WINDOW(win));
1745 /* we check for low-mem; in that case, show a warning, and don't allow
1746 * reply/forward (because it could potentially require a lot of memory */
1747 if (modest_platform_check_memory_low (MODEST_WINDOW(win), TRUE))
1751 /* we need an account when editing */
1752 if (!modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE)) {
1753 if (!modest_ui_actions_run_account_setup_wizard (win))
1757 reply_forward_type =
1758 modest_conf_get_int (modest_runtime_get_conf (),
1759 (action == ACTION_FORWARD) ?
1760 MODEST_CONF_FORWARD_TYPE :
1761 MODEST_CONF_REPLY_TYPE,
1764 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
1766 TnyHeader *header = NULL;
1767 /* Get header and message. Do not free them here, the
1768 reply_forward_cb must do it */
1769 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW(win));
1770 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
1772 if (msg && header) {
1774 rf_helper = create_reply_forward_helper (action, win,
1775 reply_forward_type, header);
1776 reply_forward_cb (NULL, header, FALSE, msg, NULL, rf_helper);
1778 g_warning("%s: no message or header found in viewer\n", __FUNCTION__);
1782 g_object_unref (msg);
1784 g_object_unref (header);
1786 TnyHeader *header = NULL;
1788 gboolean do_retrieve = TRUE;
1789 TnyList *header_list = NULL;
1791 header_list = get_selected_headers (win);
1794 /* Check that only one message is selected for replying */
1795 if (tny_list_get_length (header_list) != 1) {
1796 modest_platform_information_banner ((win) ? GTK_WIDGET (win) : NULL,
1797 NULL, _("mcen_ib_select_one_message"));
1798 g_object_unref (header_list);
1802 /* Only reply/forward to one message */
1803 iter = tny_list_create_iterator (header_list);
1804 header = TNY_HEADER (tny_iterator_get_current (iter));
1805 g_object_unref (iter);
1807 /* Retrieve messages */
1808 do_retrieve = (action == ACTION_FORWARD) ||
1809 (reply_forward_type != MODEST_TNY_MSG_REPLY_TYPE_CITE);
1812 TnyAccount *account = NULL;
1813 TnyFolder *folder = NULL;
1814 gdouble download = TRUE;
1815 guint uncached_msgs = 0;
1817 folder = tny_header_get_folder (header);
1819 goto do_retrieve_frees;
1820 account = tny_folder_get_account (folder);
1822 goto do_retrieve_frees;
1824 uncached_msgs = header_list_count_uncached_msgs (header_list);
1826 if (uncached_msgs > 0) {
1827 /* Allways download if we are online. */
1828 if (!tny_device_is_online (modest_runtime_get_device ())) {
1831 /* If ask for user permission to download the messages */
1832 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
1833 ngettext("mcen_nc_get_msg",
1837 /* End if the user does not want to continue */
1838 if (response == GTK_RESPONSE_CANCEL)
1845 rf_helper = create_reply_forward_helper (action, win,
1846 reply_forward_type, header);
1847 if (uncached_msgs > 0) {
1848 modest_platform_connect_and_perform (GTK_WINDOW (win),
1850 reply_forward_performer,
1853 reply_forward_performer (FALSE, NULL, GTK_WINDOW (win),
1854 account, rf_helper);
1859 g_object_unref (account);
1861 g_object_unref (folder);
1863 reply_forward_cb (NULL, header, FALSE, NULL, NULL, rf_helper);
1866 g_object_unref (header_list);
1867 g_object_unref (header);
1872 modest_ui_actions_on_reply (GtkAction *action, ModestWindow *win)
1874 g_return_if_fail (MODEST_IS_WINDOW(win));
1876 reply_forward (ACTION_REPLY, win);
1880 modest_ui_actions_on_forward (GtkAction *action, ModestWindow *win)
1882 g_return_if_fail (MODEST_IS_WINDOW(win));
1884 reply_forward (ACTION_FORWARD, win);
1888 modest_ui_actions_on_reply_all (GtkAction *action, ModestWindow *win)
1890 g_return_if_fail (MODEST_IS_WINDOW(win));
1892 reply_forward (ACTION_REPLY_TO_ALL, win);
1896 modest_ui_actions_on_next (GtkAction *action,
1897 ModestWindow *window)
1899 if (MODEST_IS_MAIN_WINDOW (window)) {
1900 GtkWidget *header_view;
1902 header_view = modest_main_window_get_child_widget (
1903 MODEST_MAIN_WINDOW(window),
1904 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1908 modest_header_view_select_next (
1909 MODEST_HEADER_VIEW(header_view));
1910 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
1911 modest_msg_view_window_select_next_message (
1912 MODEST_MSG_VIEW_WINDOW (window));
1914 g_return_if_reached ();
1919 modest_ui_actions_on_prev (GtkAction *action,
1920 ModestWindow *window)
1922 g_return_if_fail (MODEST_IS_WINDOW(window));
1924 if (MODEST_IS_MAIN_WINDOW (window)) {
1925 GtkWidget *header_view;
1926 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
1927 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1931 modest_header_view_select_prev (MODEST_HEADER_VIEW(header_view));
1932 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
1933 modest_msg_view_window_select_previous_message (MODEST_MSG_VIEW_WINDOW (window));
1935 g_return_if_reached ();
1940 modest_ui_actions_on_sort (GtkAction *action,
1941 ModestWindow *window)
1943 g_return_if_fail (MODEST_IS_WINDOW(window));
1945 if (MODEST_IS_MAIN_WINDOW (window)) {
1946 GtkWidget *header_view;
1947 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
1948 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1950 modest_platform_information_banner (NULL, NULL, _CS("ckdg_ib_nothing_to_sort"));
1955 /* Show sorting dialog */
1956 modest_utils_run_sort_dialog (GTK_WINDOW (window), MODEST_SORT_HEADERS);
1961 new_messages_arrived (ModestMailOperation *self,
1962 TnyList *new_headers,
1966 gboolean show_visual_notifications;
1968 source = modest_mail_operation_get_source (self);
1969 show_visual_notifications = (source) ? FALSE : TRUE;
1971 g_object_unref (source);
1973 /* Notify new messages have been downloaded. If the
1974 send&receive was invoked by the user then do not show any
1975 visual notification, only play a sound and activate the LED
1976 (for the Maemo version) */
1977 if (TNY_IS_LIST(new_headers) && (tny_list_get_length (new_headers)) > 0)
1978 modest_platform_on_new_headers_received (new_headers,
1979 show_visual_notifications);
1984 retrieve_all_messages_cb (GObject *source,
1986 guint retrieve_limit)
1992 window = GTK_WINDOW (source);
1993 msg = g_strdup_printf (_("mail_nc_msg_count_limit_exceeded"),
1994 num_msgs, retrieve_limit);
1996 /* Ask the user if they want to retrieve all the messages */
1998 modest_platform_run_confirmation_dialog_with_buttons (window, msg,
1999 _("mcen_bd_get_all"),
2000 _("mcen_bd_newest_only"));
2001 /* Free and return */
2003 return (response == GTK_RESPONSE_ACCEPT) ? TRUE : FALSE;
2007 TnyAccount *account;
2009 gchar *account_name;
2010 gboolean poke_status;
2011 gboolean interactive;
2012 ModestMailOperation *mail_op;
2016 do_send_receive_performer (gboolean canceled,
2018 GtkWindow *parent_window,
2019 TnyAccount *account,
2022 SendReceiveInfo *info;
2024 info = (SendReceiveInfo *) user_data;
2026 if (err || canceled) {
2027 /* In memory full conditions we could get this error here */
2028 check_memory_full_error ((GtkWidget *) parent_window, err);
2030 if (info->mail_op) {
2031 modest_mail_operation_queue_remove (modest_runtime_get_mail_operation_queue (),
2037 /* Set send/receive operation in progress */
2038 if (info->win && MODEST_IS_MAIN_WINDOW (info->win)) {
2039 modest_main_window_notify_send_receive_initied (MODEST_MAIN_WINDOW (info->win));
2042 if (info->win && MODEST_IS_MAIN_WINDOW (info->win))
2043 g_signal_connect (G_OBJECT (info->mail_op), "operation-finished",
2044 G_CALLBACK (on_send_receive_finished),
2047 /* Send & receive. */
2048 modest_mail_operation_update_account (info->mail_op, info->account_name, info->poke_status, info->interactive,
2049 (info->win) ? retrieve_all_messages_cb : NULL,
2050 new_messages_arrived, info->win);
2055 g_object_unref (G_OBJECT (info->mail_op));
2056 if (info->account_name)
2057 g_free (info->account_name);
2059 g_object_unref (info->win);
2061 g_object_unref (info->account);
2062 g_slice_free (SendReceiveInfo, info);
2066 * This function performs the send & receive required actions. The
2067 * window is used to create the mail operation. Typically it should
2068 * always be the main window, but we pass it as argument in order to
2072 modest_ui_actions_do_send_receive (const gchar *account_name,
2073 gboolean force_connection,
2074 gboolean poke_status,
2075 gboolean interactive,
2078 gchar *acc_name = NULL;
2079 SendReceiveInfo *info;
2080 ModestTnyAccountStore *acc_store;
2082 /* If no account name was provided then get the current account, and if
2083 there is no current account then pick the default one: */
2084 if (!account_name) {
2086 acc_name = g_strdup (modest_window_get_active_account (win));
2088 acc_name = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
2090 g_printerr ("modest: cannot get default account\n");
2094 acc_name = g_strdup (account_name);
2097 acc_store = modest_runtime_get_account_store ();
2099 /* Create the info for the connect and perform */
2100 info = g_slice_new (SendReceiveInfo);
2101 info->account_name = acc_name;
2102 info->win = (win) ? g_object_ref (win) : NULL;
2103 info->poke_status = poke_status;
2104 info->interactive = interactive;
2105 info->account = modest_tny_account_store_get_server_account (acc_store, acc_name,
2106 TNY_ACCOUNT_TYPE_STORE);
2107 /* We need to create the operation here, because otherwise it
2108 could happen that the queue emits the queue-empty signal
2109 while we're trying to connect the account */
2110 info->mail_op = modest_mail_operation_new_with_error_handling ((info->win) ? G_OBJECT (info->win) : NULL,
2111 modest_ui_actions_disk_operations_error_handler,
2113 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), info->mail_op);
2115 /* Invoke the connect and perform */
2116 modest_platform_connect_and_perform ((win) ? GTK_WINDOW (win) : NULL,
2117 force_connection, info->account,
2118 do_send_receive_performer, info);
2123 modest_ui_actions_do_cancel_send (const gchar *account_name,
2126 TnyTransportAccount *transport_account;
2127 TnySendQueue *send_queue = NULL;
2128 GError *error = NULL;
2130 /* Get transport account */
2132 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
2133 (modest_runtime_get_account_store(),
2135 TNY_ACCOUNT_TYPE_TRANSPORT));
2136 if (!transport_account) {
2137 g_printerr ("modest: no transport account found for '%s'\n", account_name);
2142 send_queue = TNY_SEND_QUEUE (modest_runtime_get_send_queue (transport_account, TRUE));
2143 if (!TNY_IS_SEND_QUEUE(send_queue)) {
2144 g_set_error (&error, MODEST_MAIL_OPERATION_ERROR,
2145 MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND,
2146 "modest: could not find send queue for account\n");
2148 /* Cancel the current send */
2149 tny_account_cancel (TNY_ACCOUNT (transport_account));
2151 /* Suspend all pending messages */
2152 tny_send_queue_cancel (send_queue, TNY_SEND_QUEUE_CANCEL_ACTION_SUSPEND, &error);
2156 if (transport_account != NULL)
2157 g_object_unref (G_OBJECT (transport_account));
2161 modest_ui_actions_cancel_send_all (ModestWindow *win)
2163 GSList *account_names, *iter;
2165 account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
2168 iter = account_names;
2170 modest_ui_actions_do_cancel_send ((const char*) iter->data, win);
2171 iter = g_slist_next (iter);
2174 modest_account_mgr_free_account_names (account_names);
2175 account_names = NULL;
2179 modest_ui_actions_cancel_send (GtkAction *action, ModestWindow *win)
2182 /* Check if accounts exist */
2183 gboolean accounts_exist =
2184 modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
2186 /* If not, allow the user to create an account before trying to send/receive. */
2187 if (!accounts_exist)
2188 modest_ui_actions_on_accounts (NULL, win);
2190 /* Cancel all sending operaitons */
2191 modest_ui_actions_cancel_send_all (win);
2195 * Refreshes all accounts. This function will be used by automatic
2199 modest_ui_actions_do_send_receive_all (ModestWindow *win,
2200 gboolean force_connection,
2201 gboolean poke_status,
2202 gboolean interactive)
2204 GSList *account_names, *iter;
2206 account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
2209 iter = account_names;
2211 modest_ui_actions_do_send_receive ((const char*) iter->data,
2213 poke_status, interactive, win);
2214 iter = g_slist_next (iter);
2217 modest_account_mgr_free_account_names (account_names);
2218 account_names = NULL;
2222 * Handler of the click on Send&Receive button in the main toolbar
2225 modest_ui_actions_on_send_receive (GtkAction *action, ModestWindow *win)
2227 /* Check if accounts exist */
2228 gboolean accounts_exist;
2231 modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
2233 /* If not, allow the user to create an account before trying to send/receive. */
2234 if (!accounts_exist)
2235 modest_ui_actions_on_accounts (NULL, win);
2237 /* Refresh the current folder. The if is always TRUE it's just an extra check */
2238 if (MODEST_IS_MAIN_WINDOW (win)) {
2239 GtkWidget *folder_view;
2240 TnyFolderStore *folder_store;
2243 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
2244 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2248 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
2251 g_object_unref (folder_store);
2254 /* Refresh the active account. Force the connection if needed
2255 and poke the status of all folders */
2256 modest_ui_actions_do_send_receive (NULL, TRUE, TRUE, TRUE, win);
2261 modest_ui_actions_toggle_header_list_view (GtkAction *action, ModestMainWindow *main_window)
2264 GtkWidget *header_view;
2266 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2268 header_view = modest_main_window_get_child_widget (main_window,
2269 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2273 conf = modest_runtime_get_conf ();
2275 /* what is saved/restored is depending on the style; thus; we save with
2276 * old style, then update the style, and restore for this new style
2278 modest_widget_memory_save (conf, G_OBJECT(header_view), MODEST_CONF_HEADER_VIEW_KEY);
2280 if (modest_header_view_get_style
2281 (MODEST_HEADER_VIEW(header_view)) == MODEST_HEADER_VIEW_STYLE_DETAILS)
2282 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
2283 MODEST_HEADER_VIEW_STYLE_TWOLINES);
2285 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
2286 MODEST_HEADER_VIEW_STYLE_DETAILS);
2288 modest_widget_memory_restore (conf, G_OBJECT(header_view),
2289 MODEST_CONF_HEADER_VIEW_KEY);
2294 modest_ui_actions_on_header_selected (ModestHeaderView *header_view,
2296 ModestMainWindow *main_window)
2298 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2299 g_return_if_fail (MODEST_IS_HEADER_VIEW (header_view));
2301 /* in the case the folder is empty, show the empty folder message and focus
2303 if (!header && gtk_widget_is_focus (GTK_WIDGET (header_view))) {
2304 if (modest_header_view_is_empty (header_view)) {
2305 TnyFolder *folder = modest_header_view_get_folder (header_view);
2306 GtkWidget *folder_view =
2307 modest_main_window_get_child_widget (main_window,
2308 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2309 if (folder != NULL) {
2310 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view), folder, FALSE);
2311 g_object_unref (folder);
2313 gtk_widget_grab_focus (GTK_WIDGET (folder_view));
2317 /* If no header has been selected then exit */
2322 if (!gtk_widget_is_focus (GTK_WIDGET(header_view)))
2323 gtk_widget_grab_focus (GTK_WIDGET(header_view));
2325 /* Update toolbar dimming state */
2326 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (main_window));
2327 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
2331 modest_ui_actions_on_header_activated (ModestHeaderView *header_view,
2334 ModestWindow *window)
2337 GtkWidget *open_widget;
2339 g_return_if_fail (MODEST_IS_WINDOW(window));
2344 if (MODEST_IS_MAIN_WINDOW (window) &&
2345 modest_header_view_count_selected_headers (header_view) > 1) {
2346 modest_platform_information_banner (NULL, NULL, _("mcen_ib_select_one_message"));
2350 /* we check for low-mem; in that case, show a warning, and don't allow
2351 * activating headers
2353 if (modest_platform_check_memory_low (MODEST_WINDOW(window), TRUE))
2356 if (MODEST_IS_MAIN_WINDOW (window)) {
2357 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (window));
2358 open_widget = modest_window_get_action_widget (MODEST_WINDOW (window), "/MenuBar/EmailMenu/EmailOpenMenu");
2359 if (!GTK_WIDGET_IS_SENSITIVE (open_widget))
2363 if (MODEST_IS_MAIN_WINDOW (window)) {
2364 headers = modest_header_view_get_selected_headers (header_view);
2366 headers = tny_simple_list_new ();
2367 tny_list_prepend (TNY_LIST (headers), G_OBJECT (header));
2370 open_msgs_from_headers (headers, path, MODEST_WINDOW (window));
2372 g_object_unref (headers);
2376 set_active_account_from_tny_account (TnyAccount *account,
2377 ModestWindow *window)
2379 const gchar *server_acc_name = tny_account_get_id (account);
2381 /* We need the TnyAccount provided by the
2382 account store because that is the one that
2383 knows the name of the Modest account */
2384 TnyAccount *modest_server_account = modest_server_account =
2385 modest_tny_account_store_get_tny_account_by (modest_runtime_get_account_store (),
2386 MODEST_TNY_ACCOUNT_STORE_QUERY_ID,
2388 if (!modest_server_account) {
2389 g_warning ("%s: could not get tny account\n", __FUNCTION__);
2393 /* Update active account, but only if it's not a pseudo-account */
2394 if ((!modest_tny_account_is_virtual_local_folders(modest_server_account)) &&
2395 (!modest_tny_account_is_memory_card_account(modest_server_account))) {
2396 const gchar *modest_acc_name =
2397 modest_tny_account_get_parent_modest_account_name_for_server_account (modest_server_account);
2398 if (modest_acc_name)
2399 modest_window_set_active_account (window, modest_acc_name);
2402 g_object_unref (modest_server_account);
2407 folder_refreshed_cb (ModestMailOperation *mail_op,
2411 ModestMainWindow *win = NULL;
2412 GtkWidget *folder_view;
2413 const GError *error;
2415 g_return_if_fail (TNY_IS_FOLDER (folder));
2417 win = MODEST_MAIN_WINDOW (user_data);
2419 /* Check if the operation failed due to memory low conditions */
2420 error = modest_mail_operation_get_error (mail_op);
2421 if (error && error->domain == MODEST_MAIL_OPERATION_ERROR &&
2422 error->code == MODEST_MAIL_OPERATION_ERROR_LOW_MEMORY) {
2423 modest_platform_run_information_dialog (GTK_WINDOW (win),
2424 dgettext("ke-recv","memr_ib_operation_disabled"),
2430 modest_main_window_get_child_widget(win, MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2433 TnyFolderStore *current_folder;
2435 current_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
2436 if (current_folder) {
2437 gboolean different = ((TnyFolderStore *) folder != current_folder);
2438 g_object_unref (current_folder);
2444 /* Check if folder is empty and set headers view contents style */
2445 if (tny_folder_get_all_count (folder) == 0)
2446 modest_main_window_set_contents_style (win,
2447 MODEST_MAIN_WINDOW_CONTENTS_STYLE_EMPTY);
2452 modest_ui_actions_on_folder_selection_changed (ModestFolderView *folder_view,
2453 TnyFolderStore *folder_store,
2455 ModestMainWindow *main_window)
2458 GtkWidget *header_view;
2460 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2462 header_view = modest_main_window_get_child_widget(main_window,
2463 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2467 conf = modest_runtime_get_conf ();
2469 if (TNY_IS_ACCOUNT (folder_store)) {
2471 set_active_account_from_tny_account (TNY_ACCOUNT (folder_store), MODEST_WINDOW (main_window));
2473 /* Show account details */
2474 modest_main_window_set_contents_style (main_window, MODEST_MAIN_WINDOW_CONTENTS_STYLE_DETAILS);
2477 if (TNY_IS_FOLDER (folder_store) && selected) {
2478 TnyAccount *account;
2479 const gchar *account_name = NULL;
2481 /* Update the active account */
2482 account = modest_tny_folder_get_account (TNY_FOLDER (folder_store));
2484 set_active_account_from_tny_account (account, MODEST_WINDOW (main_window));
2486 modest_tny_account_get_parent_modest_account_name_for_server_account (account);
2487 g_object_unref (account);
2491 /* Set the header style by default, it could
2492 be changed later by the refresh callback to
2494 modest_main_window_set_contents_style (main_window,
2495 MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS);
2497 /* Set folder on header view. This function
2498 will call tny_folder_refresh_async so we
2499 pass a callback that will be called when
2500 finished. We use that callback to set the
2501 empty view if there are no messages */
2502 modest_header_view_set_folder (MODEST_HEADER_VIEW(header_view),
2503 TNY_FOLDER (folder_store),
2505 folder_refreshed_cb,
2508 /* Restore configuration. We need to do this
2509 *after* the set_folder because the widget
2510 memory asks the header view about its
2512 modest_widget_memory_restore (modest_runtime_get_conf (),
2513 G_OBJECT(header_view),
2514 MODEST_CONF_HEADER_VIEW_KEY);
2516 /* No need to save the header view
2517 configuration for Maemo because it only
2518 saves the sorting stuff and that it's
2519 already being done by the sort
2520 dialog. Remove it when the GNOME version
2521 has the same behaviour */
2522 #ifdef MODEST_TOOLKIT_GTK
2523 if (modest_main_window_get_contents_style (main_window) ==
2524 MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS)
2525 modest_widget_memory_save (conf, G_OBJECT (header_view),
2526 MODEST_CONF_HEADER_VIEW_KEY);
2528 modest_header_view_clear (MODEST_HEADER_VIEW(header_view));
2532 /* Update dimming state */
2533 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (main_window));
2534 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
2538 modest_ui_actions_on_item_not_found (ModestHeaderView *header_view,ModestItemType type,
2545 item = (type == MODEST_ITEM_TYPE_FOLDER) ? "folder" : "message";
2547 online = tny_device_is_online (modest_runtime_get_device());
2550 /* already online -- the item is simply not there... */
2551 dialog = gtk_message_dialog_new (GTK_WINDOW (win),
2553 GTK_MESSAGE_WARNING,
2555 _("The %s you selected cannot be found"),
2557 gtk_dialog_add_button (GTK_DIALOG (dialog),_("mcen_bd_dialog_ok"), GTK_RESPONSE_ACCEPT);
2558 gtk_dialog_run (GTK_DIALOG(dialog));
2560 dialog = gtk_dialog_new_with_buttons (_("Connection requested"),
2563 _("mcen_bd_dialog_cancel"),
2564 GTK_RESPONSE_REJECT,
2565 _("mcen_bd_dialog_ok"),
2566 GTK_RESPONSE_ACCEPT,
2568 txt = g_strdup_printf (_("This %s is not available in offline mode.\n"
2569 "Do you want to get online?"), item);
2570 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
2571 gtk_label_new (txt), FALSE, FALSE, 0);
2572 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
2575 gtk_window_set_default_size (GTK_WINDOW(dialog), 300, 300);
2576 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
2577 /* TODO: Comment about why is this commented out: */
2578 /* modest_platform_connect_and_wait (); */
2581 gtk_widget_destroy (dialog);
2585 modest_ui_actions_on_msg_link_hover (ModestMsgView *msgview, const gchar* link,
2588 /* g_message ("%s %s", __FUNCTION__, link); */
2593 modest_ui_actions_on_msg_link_clicked (ModestMsgView *msgview, const gchar* link,
2596 modest_platform_activate_uri (link);
2600 modest_ui_actions_on_msg_link_contextual (ModestMsgView *msgview, const gchar* link,
2603 modest_platform_show_uri_popup (link);
2607 modest_ui_actions_on_msg_attachment_clicked (ModestMsgView *msgview, TnyMimePart *mime_part,
2610 /* we check for low-mem; in that case, show a warning, and don't allow
2611 * viewing attachments
2613 if (modest_platform_check_memory_low (MODEST_WINDOW(win), TRUE))
2616 modest_msg_view_window_view_attachment (MODEST_MSG_VIEW_WINDOW (win), mime_part);
2620 modest_ui_actions_on_msg_recpt_activated (ModestMsgView *msgview,
2621 const gchar *address,
2624 /* g_message ("%s %s", __FUNCTION__, address); */
2628 on_save_to_drafts_cb (ModestMailOperation *mail_op,
2629 TnyMsg *saved_draft,
2632 ModestMsgEditWindow *edit_window;
2633 ModestMainWindow *win;
2635 /* FIXME. Make the header view sensitive again. This is a
2636 * temporary hack. See modest_ui_actions_on_save_to_drafts()
2638 win = MODEST_MAIN_WINDOW(modest_window_mgr_get_main_window(
2639 modest_runtime_get_window_mgr(), FALSE));
2641 GtkWidget *hdrview = modest_main_window_get_child_widget(
2642 win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2643 if (hdrview) gtk_widget_set_sensitive(hdrview, TRUE);
2646 edit_window = MODEST_MSG_EDIT_WINDOW (user_data);
2648 /* Set draft is there was no error */
2649 if (!modest_mail_operation_get_error (mail_op))
2650 modest_msg_edit_window_set_draft (edit_window, saved_draft);
2652 g_object_unref(edit_window);
2656 enough_space_for_message (ModestMsgEditWindow *edit_window,
2659 TnyAccountStore *acc_store;
2660 guint64 available_disk, expected_size;
2665 acc_store = TNY_ACCOUNT_STORE (modest_runtime_get_account_store());
2666 available_disk = modest_utils_get_available_space (NULL);
2667 modest_msg_edit_window_get_parts_size (edit_window, &parts_count, &parts_size);
2668 expected_size = modest_tny_msg_estimate_size (data->plain_body,
2673 /* Double check: memory full condition or message too big */
2674 if (available_disk < MIN_FREE_SPACE ||
2675 expected_size > available_disk) {
2677 modest_platform_information_banner (NULL, NULL,
2679 "cerm_device_memory_full"));
2684 * djcb: if we're in low-memory state, we only allow for
2685 * saving messages smaller than
2686 * MODEST_MAX_LOW_MEMORY_MESSAGE_SIZE (see modest-defs.h) this
2687 * should still allow for sending anything critical...
2689 if ((expected_size > MODEST_MAX_LOW_MEMORY_MESSAGE_SIZE) &&
2690 modest_platform_check_memory_low (MODEST_WINDOW(edit_window), TRUE))
2694 * djcb: we also make sure that the attachments are smaller than the max size
2695 * this is for the case where we'd try to forward a message with attachments
2696 * bigger than our max allowed size, or sending an message from drafts which
2697 * somehow got past our checks when attaching.
2699 if (expected_size > MODEST_MAX_ATTACHMENT_SIZE) {
2700 modest_platform_run_information_dialog (
2701 GTK_WINDOW(edit_window),
2702 dgettext("ke-recv","memr_ib_operation_disabled"),
2711 modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edit_window)
2713 TnyTransportAccount *transport_account;
2714 ModestMailOperation *mail_operation;
2716 gchar *account_name, *from;
2717 ModestAccountMgr *account_mgr;
2718 gboolean had_error = FALSE;
2719 ModestMainWindow *win = NULL;
2721 g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window), FALSE);
2723 data = modest_msg_edit_window_get_msg_data (edit_window);
2726 if (!enough_space_for_message (edit_window, data)) {
2727 modest_msg_edit_window_free_msg_data (edit_window, data);
2731 account_name = g_strdup (data->account_name);
2732 account_mgr = modest_runtime_get_account_mgr();
2734 account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
2736 account_name = modest_account_mgr_get_default_account (account_mgr);
2737 if (!account_name) {
2738 g_printerr ("modest: no account found\n");
2739 modest_msg_edit_window_free_msg_data (edit_window, data);
2743 if (!strcmp (account_name, MODEST_LOCAL_FOLDERS_ACCOUNT_ID)) {
2744 account_name = g_strdup (data->account_name);
2748 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
2749 (modest_runtime_get_account_store (),
2751 TNY_ACCOUNT_TYPE_TRANSPORT));
2752 if (!transport_account) {
2753 g_printerr ("modest: no transport account found for '%s'\n", account_name);
2754 g_free (account_name);
2755 modest_msg_edit_window_free_msg_data (edit_window, data);
2758 from = modest_account_mgr_get_from_string (account_mgr, account_name);
2760 /* Create the mail operation */
2761 mail_operation = modest_mail_operation_new_with_error_handling (NULL, modest_ui_actions_disk_operations_error_handler,
2763 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
2765 modest_mail_operation_save_to_drafts (mail_operation,
2777 data->priority_flags,
2778 on_save_to_drafts_cb,
2779 g_object_ref(edit_window));
2781 #ifdef MODEST_TOOLKIT_HILDON2
2782 /* In hildon2 we always show the information banner on saving to drafts.
2783 * It will be a system information banner in this case.
2785 gchar *text = g_strdup_printf (_("mail_va_saved_to_drafts"), _("mcen_me_folder_drafts"));
2786 modest_platform_information_banner (NULL, NULL, text);
2789 /* Use the main window as the parent of the banner, if the
2790 main window does not exist it won't be shown, if the parent
2791 window exists then it's properly shown. We don't use the
2792 editor window because it could be closed (save to drafts
2793 could happen after closing the window */
2794 win = (ModestMainWindow *)
2795 modest_window_mgr_get_main_window( modest_runtime_get_window_mgr(), FALSE);
2797 gchar *text = g_strdup_printf (_("mail_va_saved_to_drafts"), _("mcen_me_folder_drafts"));
2798 modest_platform_information_banner (GTK_WIDGET (win), NULL, text);
2802 modest_msg_edit_window_set_modified (edit_window, FALSE);
2806 g_free (account_name);
2807 g_object_unref (G_OBJECT (transport_account));
2808 g_object_unref (G_OBJECT (mail_operation));
2810 modest_msg_edit_window_free_msg_data (edit_window, data);
2813 * If the drafts folder is selected then make the header view
2814 * insensitive while the message is being saved to drafts
2815 * (it'll be sensitive again in on_save_to_drafts_cb()). This
2816 * is not very clean but it avoids letting the drafts folder
2817 * in an inconsistent state: the user could edit the message
2818 * being saved and undesirable things would happen.
2819 * In the average case the user won't notice anything at
2820 * all. In the worst case (the user is editing a really big
2821 * file from Drafts) the header view will be insensitive
2822 * during the saving process (10 or 20 seconds, depending on
2823 * the message). Anyway this is just a quick workaround: once
2824 * we find a better solution it should be removed
2825 * See NB#65125 (commend #18) for details.
2827 if (!had_error && win != NULL) {
2828 ModestFolderView *view = MODEST_FOLDER_VIEW(modest_main_window_get_child_widget(
2829 win, MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW));
2831 TnyFolder *folder = TNY_FOLDER(modest_folder_view_get_selected(view));
2833 if (modest_tny_folder_is_local_folder(folder)) {
2834 TnyFolderType folder_type;
2835 folder_type = modest_tny_folder_get_local_or_mmc_folder_type(folder);
2836 if (folder_type == TNY_FOLDER_TYPE_DRAFTS) {
2837 GtkWidget *hdrview = modest_main_window_get_child_widget(
2838 win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2839 if (hdrview) gtk_widget_set_sensitive(hdrview, FALSE);
2843 if (folder != NULL) g_object_unref(folder);
2850 /* For instance, when clicking the Send toolbar button when editing a message: */
2852 modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
2854 TnyTransportAccount *transport_account = NULL;
2855 gboolean had_error = FALSE;
2857 ModestAccountMgr *account_mgr;
2858 gchar *account_name;
2860 ModestMailOperation *mail_operation;
2862 g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window), TRUE);
2864 if (!modest_msg_edit_window_check_names (edit_window, TRUE))
2867 data = modest_msg_edit_window_get_msg_data (edit_window);
2870 if (!enough_space_for_message (edit_window, data)) {
2871 modest_msg_edit_window_free_msg_data (edit_window, data);
2875 account_mgr = modest_runtime_get_account_mgr();
2876 account_name = g_strdup (data->account_name);
2878 account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
2881 account_name = modest_account_mgr_get_default_account (account_mgr);
2883 if (!account_name) {
2884 modest_msg_edit_window_free_msg_data (edit_window, data);
2885 /* Run account setup wizard */
2886 if (!modest_ui_actions_run_account_setup_wizard (MODEST_WINDOW(edit_window))) {
2891 /* Get the currently-active transport account for this modest account: */
2892 if (strcmp (account_name, MODEST_LOCAL_FOLDERS_ACCOUNT_ID) != 0) {
2894 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
2895 (modest_runtime_get_account_store (),
2896 account_name, TNY_ACCOUNT_TYPE_TRANSPORT));
2899 if (!transport_account) {
2900 modest_msg_edit_window_free_msg_data (edit_window, data);
2901 /* Run account setup wizard */
2902 if (!modest_ui_actions_run_account_setup_wizard(MODEST_WINDOW(edit_window)))
2907 /* Create the mail operation */
2908 from = modest_account_mgr_get_from_string (account_mgr, account_name);
2909 mail_operation = modest_mail_operation_new_with_error_handling (NULL, modest_ui_actions_disk_operations_error_handler, NULL, NULL);
2910 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
2912 modest_mail_operation_send_new_mail (mail_operation,
2924 data->priority_flags);
2926 if (modest_mail_operation_get_status (mail_operation) == MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS)
2927 modest_platform_information_banner (NULL, NULL, _("mcen_ib_outbox_waiting_to_be_sent"));
2930 if (modest_mail_operation_get_error (mail_operation) != NULL) {
2931 const GError *error = modest_mail_operation_get_error (mail_operation);
2932 if (error->domain == MODEST_MAIL_OPERATION_ERROR &&
2933 error->code == MODEST_MAIL_OPERATION_ERROR_INSTANCE_CREATION_FAILED) {
2934 g_warning ("%s failed: %s\n", __FUNCTION__, (modest_mail_operation_get_error (mail_operation))->message);
2935 modest_platform_information_banner (NULL, NULL, _CS("sfil_ni_not_enough_memory"));
2942 g_free (account_name);
2943 g_object_unref (G_OBJECT (transport_account));
2944 g_object_unref (G_OBJECT (mail_operation));
2946 modest_msg_edit_window_free_msg_data (edit_window, data);
2949 modest_msg_edit_window_set_sent (edit_window, TRUE);
2951 /* Save settings and close the window: */
2952 modest_ui_actions_on_close_window (NULL, MODEST_WINDOW (edit_window));
2959 modest_ui_actions_on_toggle_bold (GtkToggleAction *action,
2960 ModestMsgEditWindow *window)
2962 ModestMsgEditFormatState *format_state = NULL;
2964 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2965 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
2967 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2970 format_state = modest_msg_edit_window_get_format_state (window);
2971 g_return_if_fail (format_state != NULL);
2973 format_state->bold = gtk_toggle_action_get_active (action);
2974 modest_msg_edit_window_set_format_state (window, format_state);
2975 g_free (format_state);
2980 modest_ui_actions_on_toggle_italics (GtkToggleAction *action,
2981 ModestMsgEditWindow *window)
2983 ModestMsgEditFormatState *format_state = NULL;
2985 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2986 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
2988 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2991 format_state = modest_msg_edit_window_get_format_state (window);
2992 g_return_if_fail (format_state != NULL);
2994 format_state->italics = gtk_toggle_action_get_active (action);
2995 modest_msg_edit_window_set_format_state (window, format_state);
2996 g_free (format_state);
3001 modest_ui_actions_on_toggle_bullets (GtkToggleAction *action,
3002 ModestMsgEditWindow *window)
3004 ModestMsgEditFormatState *format_state = NULL;
3006 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3007 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
3009 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3012 format_state = modest_msg_edit_window_get_format_state (window);
3013 g_return_if_fail (format_state != NULL);
3015 format_state->bullet = gtk_toggle_action_get_active (action);
3016 modest_msg_edit_window_set_format_state (window, format_state);
3017 g_free (format_state);
3022 modest_ui_actions_on_change_justify (GtkRadioAction *action,
3023 GtkRadioAction *selected,
3024 ModestMsgEditWindow *window)
3026 ModestMsgEditFormatState *format_state = NULL;
3027 GtkJustification value;
3029 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3031 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3034 value = gtk_radio_action_get_current_value (selected);
3036 format_state = modest_msg_edit_window_get_format_state (window);
3037 g_return_if_fail (format_state != NULL);
3039 format_state->justification = value;
3040 modest_msg_edit_window_set_format_state (window, format_state);
3041 g_free (format_state);
3045 modest_ui_actions_on_select_editor_color (GtkAction *action,
3046 ModestMsgEditWindow *window)
3048 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3049 g_return_if_fail (GTK_IS_ACTION (action));
3051 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3054 modest_msg_edit_window_select_color (window);
3058 modest_ui_actions_on_select_editor_background_color (GtkAction *action,
3059 ModestMsgEditWindow *window)
3061 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3062 g_return_if_fail (GTK_IS_ACTION (action));
3064 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3067 modest_msg_edit_window_select_background_color (window);
3071 modest_ui_actions_on_insert_image (GtkAction *action,
3072 ModestMsgEditWindow *window)
3074 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3075 g_return_if_fail (GTK_IS_ACTION (action));
3078 if (modest_platform_check_memory_low (MODEST_WINDOW(window), TRUE))
3081 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3084 modest_msg_edit_window_insert_image (window);
3088 modest_ui_actions_on_attach_file (GtkAction *action,
3089 ModestMsgEditWindow *window)
3091 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3092 g_return_if_fail (GTK_IS_ACTION (action));
3094 if (modest_platform_check_memory_low (MODEST_WINDOW(window), TRUE))
3097 modest_msg_edit_window_offer_attach_file (window);
3101 modest_ui_actions_on_remove_attachments (GtkAction *action,
3102 ModestMsgEditWindow *window)
3104 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3105 g_return_if_fail (GTK_IS_ACTION (action));
3107 modest_msg_edit_window_remove_attachments (window, NULL);
3111 #ifndef MODEST_TOOLKIT_GTK
3116 TnyFolderStore *folder;
3117 } CreateFolderHelper;
3120 show_create_folder_in_timeout (gpointer data)
3122 CreateFolderHelper *helper = (CreateFolderHelper *) data;
3124 /* Remove the timeout ASAP, we can not wait until the dialog
3125 is shown because it could take a lot of time and so the
3126 timeout could be called twice or more times */
3127 g_source_remove (helper->handler);
3129 gdk_threads_enter ();
3130 do_create_folder (helper->win, helper->folder, helper->name);
3131 gdk_threads_leave ();
3133 g_object_unref (helper->win);
3134 g_object_unref (helper->folder);
3135 g_free (helper->name);
3136 g_slice_free (CreateFolderHelper, helper);
3143 do_create_folder_cb (ModestMailOperation *mail_op,
3144 TnyFolderStore *parent_folder,
3145 TnyFolder *new_folder,
3148 gchar *suggested_name = (gchar *) user_data;
3149 GtkWindow *source_win = (GtkWindow *) modest_mail_operation_get_source (mail_op);
3151 if (modest_mail_operation_get_error (mail_op)) {
3153 /* Show an error. If there was some problem writing to
3154 disk, show it, otherwise show the generic folder
3155 create error. We do it here and not in an error
3156 handler because the call to do_create_folder will
3157 stop the main loop in a gtk_dialog_run and then,
3158 the message won't be shown until that dialog is
3160 modest_ui_actions_disk_operations_error_handler (mail_op,
3161 _("mail_in_ui_folder_create_error"));
3163 /* Try again. Do *NOT* show any error because the mail
3164 operations system will do it for us because we
3165 created the mail_op with new_with_error_handler */
3166 #ifndef MODEST_TOOLKIT_GTK
3167 CreateFolderHelper *helper;
3168 helper = g_slice_new0 (CreateFolderHelper);
3169 helper->name = g_strdup (suggested_name);
3170 helper->folder = g_object_ref (parent_folder);
3171 helper->win = g_object_ref (source_win);
3173 /* Ugly but neccesary stuff. The problem is that the
3174 dialog when is shown calls a function that destroys
3175 all the temporary windows, so the banner is
3177 helper->handler = g_timeout_add (2000, show_create_folder_in_timeout, helper);
3179 do_create_folder (source_win, parent_folder, (const gchar *) suggested_name);
3182 /* the 'source_win' is either the ModestMainWindow, or the 'Move to folder'-dialog
3183 * FIXME: any other? */
3184 GtkWidget *folder_view;
3186 if (MODEST_IS_MAIN_WINDOW(source_win))
3188 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (source_win),
3189 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3192 get_folder_view_from_move_to_dialog (GTK_WIDGET(source_win));
3194 /* Select the newly created folder. It could happen
3195 that the widget is no longer there (i.e. the window
3196 has been destroyed, so we need to check this */
3198 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view),
3200 g_object_unref (new_folder);
3202 /* Free. Note that the first time it'll be NULL so noop */
3203 g_free (suggested_name);
3204 g_object_unref (source_win);
3208 do_create_folder (GtkWindow *parent_window,
3209 TnyFolderStore *parent_folder,
3210 const gchar *suggested_name)
3213 gchar *folder_name = NULL;
3215 result = modest_platform_run_new_folder_dialog (GTK_WINDOW (parent_window),
3217 (gchar *) suggested_name,
3220 if (result == GTK_RESPONSE_ACCEPT) {
3221 ModestMailOperation *mail_op;
3223 mail_op = modest_mail_operation_new ((GObject *) parent_window);
3224 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
3226 modest_mail_operation_create_folder (mail_op,
3228 (const gchar *) folder_name,
3229 do_create_folder_cb,
3231 g_object_unref (mail_op);
3236 create_folder_performer (gboolean canceled,
3238 GtkWindow *parent_window,
3239 TnyAccount *account,
3242 TnyFolderStore *parent_folder = TNY_FOLDER_STORE (user_data);
3244 if (canceled || err) {
3245 /* In memory full conditions we could get this error here */
3246 check_memory_full_error ((GtkWidget *) parent_window, err);
3250 /* Run the new folder dialog */
3251 do_create_folder (GTK_WINDOW (parent_window), parent_folder, NULL);
3254 g_object_unref (parent_folder);
3258 modest_ui_actions_create_folder(GtkWidget *parent_window,
3259 GtkWidget *folder_view)
3261 TnyFolderStore *parent_folder;
3263 parent_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
3265 if (parent_folder) {
3266 /* The parent folder will be freed in the callback */
3267 modest_platform_connect_if_remote_and_perform (GTK_WINDOW (parent_window),
3270 create_folder_performer,
3276 modest_ui_actions_on_new_folder (GtkAction *action, ModestMainWindow *main_window)
3278 GtkWidget *folder_view;
3280 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
3282 folder_view = modest_main_window_get_child_widget (main_window,
3283 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3287 modest_ui_actions_create_folder (GTK_WIDGET (main_window), folder_view);
3291 modest_ui_actions_rename_folder_error_handler (ModestMailOperation *mail_op,
3294 const GError *error = NULL;
3295 const gchar *message = NULL;
3297 /* Get error message */
3298 error = modest_mail_operation_get_error (mail_op);
3300 g_return_if_reached ();
3302 if (error->domain == MODEST_MAIL_OPERATION_ERROR &&
3303 error->code == MODEST_MAIL_OPERATION_ERROR_FOLDER_EXISTS) {
3304 message = _CS("ckdg_ib_folder_already_exists");
3305 } else if (error->domain == TNY_ERROR_DOMAIN &&
3306 error->code == TNY_SERVICE_ERROR_STATE) {
3307 /* This means that the folder is already in use (a
3308 message is opened for example */
3309 message = _("emev_ni_internal_error");
3311 message = _("emev_ib_ui_imap_unable_to_rename");
3314 /* We don't set a parent for the dialog because the dialog
3315 will be destroyed so the banner won't appear */
3316 modest_platform_information_banner (NULL, NULL, message);
3320 TnyFolderStore *folder;
3325 on_rename_folder_cb (ModestMailOperation *mail_op,
3326 TnyFolder *new_folder,
3329 ModestFolderView *folder_view;
3331 /* If the window was closed when renaming a folder this could
3333 if (!MODEST_IS_FOLDER_VIEW (user_data))
3336 folder_view = MODEST_FOLDER_VIEW (user_data);
3337 /* Note that if the rename fails new_folder will be NULL */
3339 modest_folder_view_select_folder (folder_view, new_folder, FALSE);
3341 modest_folder_view_select_first_inbox_or_local (folder_view);
3343 gtk_widget_grab_focus (GTK_WIDGET (folder_view));
3347 on_rename_folder_performer (gboolean canceled,
3349 GtkWindow *parent_window,
3350 TnyAccount *account,
3353 ModestMailOperation *mail_op = NULL;
3354 GtkTreeSelection *sel = NULL;
3355 GtkWidget *folder_view = NULL;
3356 RenameFolderInfo *data = (RenameFolderInfo*)user_data;
3358 if (canceled || err) {
3359 /* In memory full conditions we could get this error here */
3360 check_memory_full_error ((GtkWidget *) parent_window, err);
3361 } else if (MODEST_IS_MAIN_WINDOW(parent_window)) {
3363 folder_view = modest_main_window_get_child_widget (
3364 MODEST_MAIN_WINDOW (parent_window),
3365 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3368 modest_mail_operation_new_with_error_handling (G_OBJECT(parent_window),
3369 modest_ui_actions_rename_folder_error_handler,
3370 parent_window, NULL);
3372 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
3375 /* Clear the headers view */
3376 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_view));
3377 gtk_tree_selection_unselect_all (sel);
3379 /* Actually rename the folder */
3380 modest_mail_operation_rename_folder (mail_op,
3381 TNY_FOLDER (data->folder),
3382 (const gchar *) (data->new_name),
3383 on_rename_folder_cb,
3385 g_object_unref (data->folder);
3386 g_object_unref (mail_op);
3389 g_free (data->new_name);
3394 modest_ui_actions_on_rename_folder (GtkAction *action,
3395 ModestMainWindow *main_window)
3397 TnyFolderStore *folder;
3398 GtkWidget *folder_view;
3399 GtkWidget *header_view;
3401 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
3403 folder_view = modest_main_window_get_child_widget (main_window,
3404 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3408 header_view = modest_main_window_get_child_widget (main_window,
3409 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
3414 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
3419 if (TNY_IS_FOLDER (folder)) {
3420 gchar *folder_name = NULL;
3422 const gchar *current_name;
3423 TnyFolderStore *parent;
3424 gboolean do_rename = TRUE;
3426 current_name = tny_folder_get_name (TNY_FOLDER (folder));
3427 parent = tny_folder_get_folder_store (TNY_FOLDER (folder));
3428 response = modest_platform_run_rename_folder_dialog (GTK_WINDOW (main_window),
3429 parent, current_name,
3431 g_object_unref (parent);
3433 if (response != GTK_RESPONSE_ACCEPT || strlen (folder_name) == 0) {
3436 RenameFolderInfo *rename_folder_data = g_new0 (RenameFolderInfo, 1);
3437 rename_folder_data->folder = g_object_ref (folder);
3438 rename_folder_data->new_name = folder_name;
3439 modest_platform_connect_if_remote_and_perform (GTK_WINDOW(main_window), TRUE,
3440 folder, on_rename_folder_performer, rename_folder_data);
3443 g_object_unref (folder);
3447 modest_ui_actions_delete_folder_error_handler (ModestMailOperation *mail_op,
3450 GObject *win = modest_mail_operation_get_source (mail_op);
3452 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
3453 _("mail_in_ui_folder_delete_error"),
3455 g_object_unref (win);
3459 TnyFolderStore *folder;
3460 gboolean move_to_trash;
3464 on_delete_folder_cb (gboolean canceled,
3466 GtkWindow *parent_window,
3467 TnyAccount *account,
3470 DeleteFolderInfo *info = (DeleteFolderInfo*) user_data;
3471 GtkWidget *folder_view;
3472 ModestMailOperation *mail_op;
3473 GtkTreeSelection *sel;
3475 if (!MODEST_IS_MAIN_WINDOW(parent_window) || canceled || (err!=NULL)) {
3476 g_object_unref (G_OBJECT (info->folder));
3481 folder_view = modest_main_window_get_child_widget (
3482 MODEST_MAIN_WINDOW (parent_window),
3483 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3485 /* Unselect the folder before deleting it to free the headers */
3486 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_view));
3487 gtk_tree_selection_unselect_all (sel);
3489 /* Create the mail operation */
3491 modest_mail_operation_new_with_error_handling (G_OBJECT(parent_window),
3492 modest_ui_actions_delete_folder_error_handler,
3495 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
3497 modest_mail_operation_remove_folder (mail_op, TNY_FOLDER (info->folder), info->move_to_trash);
3499 modest_folder_view_select_first_inbox_or_local (MODEST_FOLDER_VIEW (folder_view));
3501 g_object_unref (G_OBJECT (mail_op));
3502 g_object_unref (G_OBJECT (info->folder));
3507 delete_folder (ModestMainWindow *main_window, gboolean move_to_trash)
3509 TnyFolderStore *folder;
3510 GtkWidget *folder_view;
3514 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
3516 folder_view = modest_main_window_get_child_widget (main_window,
3517 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3521 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
3523 /* Show an error if it's an account */
3524 if (!TNY_IS_FOLDER (folder)) {
3525 modest_platform_run_information_dialog (GTK_WINDOW (main_window),
3526 _("mail_in_ui_folder_delete_error"),
3528 g_object_unref (G_OBJECT (folder));
3533 message = g_strdup_printf (_("mcen_nc_delete_folder_text"),
3534 tny_folder_get_name (TNY_FOLDER (folder)));
3535 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (main_window),
3536 (const gchar *) message);
3539 if (response == GTK_RESPONSE_OK) {
3540 DeleteFolderInfo *info;
3541 info = g_new0(DeleteFolderInfo, 1);
3542 info->folder = folder;
3543 info->move_to_trash = move_to_trash;
3544 g_object_ref (G_OBJECT (info->folder));
3545 TnyAccount *account = tny_folder_get_account (TNY_FOLDER (folder));
3546 modest_platform_connect_if_remote_and_perform (GTK_WINDOW (main_window),
3548 TNY_FOLDER_STORE (account),
3549 on_delete_folder_cb, info);
3550 g_object_unref (account);
3552 g_object_unref (G_OBJECT (folder));
3556 modest_ui_actions_on_delete_folder (GtkAction *action,
3557 ModestMainWindow *main_window)
3559 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
3561 delete_folder (main_window, FALSE);
3565 modest_ui_actions_on_move_folder_to_trash_folder (GtkAction *action, ModestMainWindow *main_window)
3567 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
3569 delete_folder (main_window, TRUE);
3573 typedef struct _PasswordDialogFields {
3574 GtkWidget *username;
3575 GtkWidget *password;
3577 } PasswordDialogFields;
3580 password_dialog_check_field (GtkEditable *editable,
3581 PasswordDialogFields *fields)
3584 gboolean any_value_empty = FALSE;
3586 value = gtk_entry_get_text (GTK_ENTRY (fields->username));
3587 if ((value == NULL) || value[0] == '\0') {
3588 any_value_empty = TRUE;
3590 value = gtk_entry_get_text (GTK_ENTRY (fields->password));
3591 if ((value == NULL) || value[0] == '\0') {
3592 any_value_empty = TRUE;
3594 gtk_dialog_set_response_sensitive (GTK_DIALOG (fields->dialog), GTK_RESPONSE_ACCEPT, !any_value_empty);
3598 modest_ui_actions_on_password_requested (TnyAccountStore *account_store,
3599 const gchar* server_account_name,
3604 ModestMainWindow *main_window)
3606 g_return_if_fail(server_account_name);
3607 gboolean completed = FALSE;
3608 PasswordDialogFields *fields = NULL;
3610 /* Initalize output parameters: */
3617 #ifndef MODEST_TOOLKIT_GTK
3618 /* Maemo uses a different (awkward) button order,
3619 * It should probably just use gtk_alternative_dialog_button_order ().
3621 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
3624 _("mcen_bd_dialog_ok"),
3625 GTK_RESPONSE_ACCEPT,
3626 _("mcen_bd_dialog_cancel"),
3627 GTK_RESPONSE_REJECT,
3630 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
3634 GTK_RESPONSE_REJECT,
3636 GTK_RESPONSE_ACCEPT,
3638 #endif /* !MODEST_TOOLKIT_GTK */
3640 modest_window_mgr_set_modal (modest_runtime_get_window_mgr(), GTK_WINDOW (dialog), NULL);
3642 gchar *server_name = modest_account_mgr_get_server_account_hostname (
3643 modest_runtime_get_account_mgr(), server_account_name);
3644 if (!server_name) {/* This happened once, though I don't know why. murrayc. */
3645 g_warning("%s: Could not get server name for server account '%s'", __FUNCTION__, server_account_name);
3648 gtk_widget_destroy (dialog);
3652 /* This causes a warning because the logical ID has no %s in it,
3653 * though the translation does, but there is not much we can do about that: */
3654 gchar *txt = g_strdup_printf (_("mail_ia_password_info"), server_name);
3655 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), gtk_label_new(txt),
3658 g_free (server_name);
3662 gchar *initial_username = modest_account_mgr_get_server_account_username (
3663 modest_runtime_get_account_mgr(), server_account_name);
3665 GtkWidget *entry_username = gtk_entry_new ();
3666 if (initial_username)
3667 gtk_entry_set_text (GTK_ENTRY (entry_username), initial_username);
3668 /* Dim this if a connection has ever succeeded with this username,
3669 * as per the UI spec: */
3670 /* const gboolean username_known = */
3671 /* modest_account_mgr_get_server_account_username_has_succeeded( */
3672 /* modest_runtime_get_account_mgr(), server_account_name); */
3673 /* gtk_widget_set_sensitive (entry_username, !username_known); */
3675 /* We drop the username sensitive code and disallow changing it here
3676 * as tinymail does not support really changing the username in the callback
3678 gtk_widget_set_sensitive (entry_username, FALSE);
3680 #ifndef MODEST_TOOLKIT_GTK
3681 /* Auto-capitalization is the default, so let's turn it off: */
3682 hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_username), HILDON_GTK_INPUT_MODE_FULL);
3684 /* Create a size group to be used by all captions.
3685 * Note that HildonCaption does not create a default size group if we do not specify one.
3686 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
3687 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
3689 GtkWidget *caption = hildon_caption_new (sizegroup,
3690 _("mail_fi_username"), entry_username, NULL, HILDON_CAPTION_MANDATORY);
3691 gtk_widget_show (entry_username);
3692 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
3693 FALSE, FALSE, MODEST_MARGIN_HALF);
3694 gtk_widget_show (caption);
3696 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry_username,
3698 #endif /* !MODEST_TOOLKIT_GTK */
3701 GtkWidget *entry_password = gtk_entry_new ();
3702 gtk_entry_set_visibility (GTK_ENTRY(entry_password), FALSE);
3703 /* gtk_entry_set_invisible_char (GTK_ENTRY(entry_password), "*"); */
3705 #ifndef MODEST_TOOLKIT_GTK
3706 /* Auto-capitalization is the default, so let's turn it off: */
3707 hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_password),
3708 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
3710 caption = hildon_caption_new (sizegroup,
3711 _("mail_fi_password"), entry_password, NULL, HILDON_CAPTION_MANDATORY);
3712 gtk_widget_show (entry_password);
3713 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
3714 FALSE, FALSE, MODEST_MARGIN_HALF);
3715 gtk_widget_show (caption);
3716 g_object_unref (sizegroup);
3718 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry_password,
3720 #endif /* !MODEST_TOOLKIT_GTK */
3722 if (initial_username != NULL)
3723 gtk_widget_grab_focus (GTK_WIDGET (entry_password));
3725 /* This is not in the Maemo UI spec:
3726 remember_pass_check = gtk_check_button_new_with_label (_("Remember password"));
3727 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), remember_pass_check,
3731 fields = g_slice_new0 (PasswordDialogFields);
3732 fields->username = entry_username;
3733 fields->password = entry_password;
3734 fields->dialog = dialog;
3736 g_signal_connect (entry_username, "changed", G_CALLBACK (password_dialog_check_field), fields);
3737 g_signal_connect (entry_password, "changed", G_CALLBACK (password_dialog_check_field), fields);
3738 password_dialog_check_field (NULL, fields);
3740 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
3742 while (!completed) {
3744 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
3746 *username = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_username)));
3748 /* Note that an empty field becomes the "" string */
3749 if (*username && strlen (*username) > 0) {
3750 modest_account_mgr_set_server_account_username (modest_runtime_get_account_mgr(),
3751 server_account_name,
3755 const gboolean username_was_changed =
3756 (strcmp (*username, initial_username) != 0);
3757 if (username_was_changed) {
3758 g_warning ("%s: tinymail does not yet support changing the "
3759 "username in the get_password() callback.\n", __FUNCTION__);
3764 modest_platform_information_banner (GTK_WIDGET (dialog), NULL,
3765 _("mcen_ib_username_pw_incorrect"));
3771 *password = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_password)));
3773 /* We do not save the password in the configuration,
3774 * because this function is only called for passwords that should
3775 * not be remembered:
3776 modest_server_account_set_password (
3777 modest_runtime_get_account_mgr(), server_account_name,
3784 /* Set parent to NULL or the banner will disappear with its parent dialog */
3785 modest_platform_information_banner(NULL, NULL, _("mail_ib_login_cancelled"));
3796 /* This is not in the Maemo UI spec:
3797 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (remember_pass_check)))
3803 g_free (initial_username);
3804 gtk_widget_destroy (dialog);
3805 g_slice_free (PasswordDialogFields, fields);
3807 /* printf ("DEBUG: %s: cancel=%d\n", __FUNCTION__, *cancel); */
3811 modest_ui_actions_on_cut (GtkAction *action,
3812 ModestWindow *window)
3814 GtkWidget *focused_widget;
3815 GtkClipboard *clipboard;
3817 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
3818 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
3819 if (GTK_IS_EDITABLE (focused_widget)) {
3820 gtk_editable_cut_clipboard (GTK_EDITABLE(focused_widget));
3821 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3822 gtk_clipboard_store (clipboard);
3823 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
3824 GtkTextBuffer *buffer;
3826 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
3827 if (modest_text_utils_buffer_selection_is_valid (buffer)) {
3828 gtk_text_buffer_cut_clipboard (buffer, clipboard, TRUE);
3829 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3830 gtk_clipboard_store (clipboard);
3832 } else if (MODEST_IS_HEADER_VIEW (focused_widget)) {
3833 TnyList *header_list = modest_header_view_get_selected_headers (
3834 MODEST_HEADER_VIEW (focused_widget));
3835 gboolean continue_download = FALSE;
3836 gint num_of_unc_msgs;
3838 num_of_unc_msgs = header_list_count_uncached_msgs(header_list);
3840 if (num_of_unc_msgs) {
3841 TnyAccount *account = get_account_from_header_list (header_list);
3843 continue_download = connect_to_get_msg (window, num_of_unc_msgs, account);
3844 g_object_unref (account);
3848 if (num_of_unc_msgs == 0 || continue_download) {
3849 /* modest_platform_information_banner (
3850 NULL, NULL, _CS("mcen_ib_getting_items"));*/
3851 modest_header_view_cut_selection (
3852 MODEST_HEADER_VIEW (focused_widget));
3855 g_object_unref (header_list);
3856 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
3857 modest_folder_view_cut_selection (MODEST_FOLDER_VIEW (focused_widget));
3862 modest_ui_actions_on_copy (GtkAction *action,
3863 ModestWindow *window)
3865 GtkClipboard *clipboard;
3866 GtkWidget *focused_widget;
3867 gboolean copied = TRUE;
3869 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
3870 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
3872 if (GTK_IS_LABEL (focused_widget)) {
3874 selection = modest_text_utils_label_get_selection (GTK_LABEL (focused_widget));
3875 gtk_clipboard_set_text (clipboard, selection, -1);
3877 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3878 gtk_clipboard_store (clipboard);
3879 } else if (GTK_IS_EDITABLE (focused_widget)) {
3880 gtk_editable_copy_clipboard (GTK_EDITABLE(focused_widget));
3881 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3882 gtk_clipboard_store (clipboard);
3883 } else if (GTK_IS_HTML (focused_widget)) {
3886 sel = gtk_html_get_selection_html (GTK_HTML (focused_widget), &len);
3887 if ((sel == NULL) || (sel[0] == '\0')) {
3890 gtk_html_copy (GTK_HTML (focused_widget));
3891 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3892 gtk_clipboard_store (clipboard);
3894 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
3895 GtkTextBuffer *buffer;
3896 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
3897 if (modest_text_utils_buffer_selection_is_valid (buffer)) {
3898 gtk_text_buffer_copy_clipboard (buffer, clipboard);
3899 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3900 gtk_clipboard_store (clipboard);
3902 } else if (MODEST_IS_HEADER_VIEW (focused_widget)) {
3903 TnyList *header_list = modest_header_view_get_selected_headers (
3904 MODEST_HEADER_VIEW (focused_widget));
3905 gboolean continue_download = FALSE;
3906 gint num_of_unc_msgs;
3908 num_of_unc_msgs = header_list_count_uncached_msgs(header_list);
3910 if (num_of_unc_msgs) {
3911 TnyAccount *account = get_account_from_header_list (header_list);
3913 continue_download = connect_to_get_msg (window, num_of_unc_msgs, account);
3914 g_object_unref (account);
3918 if (num_of_unc_msgs == 0 || continue_download) {
3919 modest_platform_information_banner (
3920 NULL, NULL, _CS("mcen_ib_getting_items"));
3921 modest_header_view_copy_selection (
3922 MODEST_HEADER_VIEW (focused_widget));
3926 g_object_unref (header_list);
3928 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
3929 modest_folder_view_copy_selection (MODEST_FOLDER_VIEW (focused_widget));
3932 /* Show information banner if there was a copy to clipboard */
3934 modest_platform_information_banner (
3935 NULL, NULL, _CS("ecoc_ib_edwin_copied"));
3939 modest_ui_actions_on_undo (GtkAction *action,
3940 ModestWindow *window)
3942 ModestEmailClipboard *clipboard = NULL;
3944 if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
3945 modest_msg_edit_window_undo (MODEST_MSG_EDIT_WINDOW (window));
3946 } else if (MODEST_IS_MAIN_WINDOW (window)) {
3947 /* Clear clipboard source */
3948 clipboard = modest_runtime_get_email_clipboard ();
3949 modest_email_clipboard_clear (clipboard);
3952 g_return_if_reached ();
3957 modest_ui_actions_on_redo (GtkAction *action,
3958 ModestWindow *window)
3960 if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
3961 modest_msg_edit_window_redo (MODEST_MSG_EDIT_WINDOW (window));
3964 g_return_if_reached ();
3970 destroy_information_note (ModestMailOperation *mail_op,
3973 /* destroy information note */
3974 gtk_widget_destroy (GTK_WIDGET(user_data));
3978 destroy_folder_information_note (ModestMailOperation *mail_op,
3979 TnyFolder *new_folder,
3982 /* destroy information note */
3983 gtk_widget_destroy (GTK_WIDGET(user_data));
3988 paste_as_attachment_free (gpointer data)
3990 PasteAsAttachmentHelper *helper = (PasteAsAttachmentHelper *) data;
3992 if (helper->banner) {
3993 gtk_widget_destroy (helper->banner);
3994 g_object_unref (helper->banner);
4000 paste_msg_as_attachment_cb (ModestMailOperation *mail_op,
4005 PasteAsAttachmentHelper *helper = (PasteAsAttachmentHelper *) userdata;
4006 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (helper->window));
4011 modest_msg_edit_window_add_part (MODEST_MSG_EDIT_WINDOW (helper->window), TNY_MIME_PART (msg));
4016 modest_ui_actions_on_paste (GtkAction *action,
4017 ModestWindow *window)
4019 GtkWidget *focused_widget = NULL;
4020 GtkWidget *inf_note = NULL;
4021 ModestMailOperation *mail_op = NULL;
4023 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
4024 if (GTK_IS_EDITABLE (focused_widget)) {
4025 gtk_editable_paste_clipboard (GTK_EDITABLE(focused_widget));
4026 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
4027 ModestEmailClipboard *e_clipboard = NULL;
4028 e_clipboard = modest_runtime_get_email_clipboard ();
4029 if (modest_email_clipboard_cleared (e_clipboard)) {
4030 GtkTextBuffer *buffer;
4031 GtkClipboard *clipboard;
4033 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
4034 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
4035 gtk_text_buffer_paste_clipboard (buffer, clipboard, NULL, TRUE);
4036 } else if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
4037 ModestMailOperation *mail_op;
4038 TnyFolder *src_folder = NULL;
4039 TnyList *data = NULL;
4041 PasteAsAttachmentHelper *helper = g_new0 (PasteAsAttachmentHelper, 1);
4042 helper->window = MODEST_MSG_EDIT_WINDOW (window);
4043 helper->banner = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
4044 _CS("ckct_nw_pasting"));
4045 modest_email_clipboard_get_data (e_clipboard, &src_folder, &data, &delete);
4046 mail_op = modest_mail_operation_new (G_OBJECT (window));
4047 if (helper->banner != NULL) {
4048 g_object_ref (G_OBJECT (helper->banner));
4049 gtk_widget_show (GTK_WIDGET (helper->banner));
4053 modest_mail_operation_get_msgs_full (mail_op,
4055 (GetMsgAsyncUserCallback) paste_msg_as_attachment_cb,
4057 paste_as_attachment_free);
4061 g_object_unref (data);
4063 g_object_unref (src_folder);
4066 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
4067 ModestEmailClipboard *clipboard = NULL;
4068 TnyFolder *src_folder = NULL;
4069 TnyFolderStore *folder_store = NULL;
4070 TnyList *data = NULL;
4071 gboolean delete = FALSE;
4073 /* Check clipboard source */
4074 clipboard = modest_runtime_get_email_clipboard ();
4075 if (modest_email_clipboard_cleared (clipboard))
4078 /* Get elements to paste */
4079 modest_email_clipboard_get_data (clipboard, &src_folder, &data, &delete);
4081 /* Create a new mail operation */
4082 mail_op = modest_mail_operation_new (G_OBJECT(window));
4084 /* Get destination folder */
4085 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (focused_widget));
4087 /* transfer messages */
4091 /* Ask for user confirmation */
4093 modest_ui_actions_msgs_move_to_confirmation (window,
4094 TNY_FOLDER (folder_store),
4098 if (response == GTK_RESPONSE_OK) {
4099 /* Launch notification */
4100 inf_note = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
4101 _CS("ckct_nw_pasting"));
4102 if (inf_note != NULL) {
4103 gtk_window_set_modal (GTK_WINDOW(inf_note), FALSE);
4104 gtk_widget_show (GTK_WIDGET(inf_note));
4107 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
4108 modest_mail_operation_xfer_msgs (mail_op,
4110 TNY_FOLDER (folder_store),
4112 destroy_information_note,
4115 g_object_unref (mail_op);
4118 } else if (src_folder != NULL) {
4119 /* Launch notification */
4120 inf_note = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
4121 _CS("ckct_nw_pasting"));
4122 if (inf_note != NULL) {
4123 gtk_window_set_modal (GTK_WINDOW(inf_note), FALSE);
4124 gtk_widget_show (GTK_WIDGET(inf_note));
4127 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
4128 modest_mail_operation_xfer_folder (mail_op,
4132 destroy_folder_information_note,
4138 g_object_unref (data);
4139 if (src_folder != NULL)
4140 g_object_unref (src_folder);
4141 if (folder_store != NULL)
4142 g_object_unref (folder_store);
4148 modest_ui_actions_on_select_all (GtkAction *action,
4149 ModestWindow *window)
4151 GtkWidget *focused_widget;
4153 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
4154 if (MODEST_IS_ATTACHMENTS_VIEW (focused_widget)) {
4155 modest_attachments_view_select_all (MODEST_ATTACHMENTS_VIEW (focused_widget));
4156 } else if (GTK_IS_LABEL (focused_widget)) {
4157 gtk_label_select_region (GTK_LABEL (focused_widget), 0, -1);
4158 } else if (GTK_IS_EDITABLE (focused_widget)) {
4159 gtk_editable_select_region (GTK_EDITABLE(focused_widget), 0, -1);
4160 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
4161 GtkTextBuffer *buffer;
4162 GtkTextIter start, end;
4164 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
4165 gtk_text_buffer_get_start_iter (buffer, &start);
4166 gtk_text_buffer_get_end_iter (buffer, &end);
4167 gtk_text_buffer_select_range (buffer, &start, &end);
4168 } else if (GTK_IS_HTML (focused_widget)) {
4169 gtk_html_select_all (GTK_HTML (focused_widget));
4170 } else if (MODEST_IS_MAIN_WINDOW (window)) {
4171 GtkWidget *header_view = focused_widget;
4172 GtkTreeSelection *selection = NULL;
4174 if (!(MODEST_IS_HEADER_VIEW (focused_widget))) {
4175 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (window),
4176 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
4179 /* Disable window dimming management */
4180 modest_window_disable_dimming (MODEST_WINDOW(window));
4182 /* Select all messages */
4183 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(header_view));
4184 gtk_tree_selection_select_all (selection);
4186 /* Set focuse on header view */
4187 gtk_widget_grab_focus (header_view);
4189 /* Enable window dimming management */
4190 modest_window_enable_dimming (MODEST_WINDOW(window));
4191 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (window));
4192 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (window));
4198 modest_ui_actions_on_mark_as_read (GtkAction *action,
4199 ModestWindow *window)
4201 g_return_if_fail (MODEST_IS_WINDOW(window));
4203 /* Mark each header as read */
4204 do_headers_action (window, headers_action_mark_as_read, NULL);
4208 modest_ui_actions_on_mark_as_unread (GtkAction *action,
4209 ModestWindow *window)
4211 g_return_if_fail (MODEST_IS_WINDOW(window));
4213 /* Mark each header as read */
4214 do_headers_action (window, headers_action_mark_as_unread, NULL);
4218 modest_ui_actions_on_change_zoom (GtkRadioAction *action,
4219 GtkRadioAction *selected,
4220 ModestWindow *window)
4224 value = gtk_radio_action_get_current_value (selected);
4225 if (MODEST_IS_WINDOW (window)) {
4226 modest_window_set_zoom (MODEST_WINDOW (window), ((gdouble)value)/100);
4231 modest_ui_actions_msg_edit_on_change_priority (GtkRadioAction *action,
4232 GtkRadioAction *selected,
4233 ModestWindow *window)
4235 TnyHeaderFlags flags;
4236 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4238 flags = gtk_radio_action_get_current_value (selected);
4239 modest_msg_edit_window_set_priority_flags (MODEST_MSG_EDIT_WINDOW (window), flags);
4243 modest_ui_actions_msg_edit_on_change_file_format (GtkRadioAction *action,
4244 GtkRadioAction *selected,
4245 ModestWindow *window)
4249 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4251 file_format = gtk_radio_action_get_current_value (selected);
4252 modest_msg_edit_window_set_file_format (MODEST_MSG_EDIT_WINDOW (window), file_format);
4257 modest_ui_actions_on_zoom_plus (GtkAction *action,
4258 ModestWindow *window)
4260 g_return_if_fail (MODEST_IS_WINDOW (window));
4262 modest_window_zoom_plus (MODEST_WINDOW (window));
4266 modest_ui_actions_on_zoom_minus (GtkAction *action,
4267 ModestWindow *window)
4269 g_return_if_fail (MODEST_IS_WINDOW (window));
4271 modest_window_zoom_minus (MODEST_WINDOW (window));
4275 modest_ui_actions_on_toggle_fullscreen (GtkToggleAction *toggle,
4276 ModestWindow *window)
4278 ModestWindowMgr *mgr;
4279 gboolean fullscreen, active;
4280 g_return_if_fail (MODEST_IS_WINDOW (window));
4282 mgr = modest_runtime_get_window_mgr ();
4284 active = (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle)))?1:0;
4285 fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
4287 if (active != fullscreen) {
4288 modest_window_mgr_set_fullscreen_mode (mgr, active);
4289 #ifndef MODEST_TOOLKIT_HILDON2
4290 gtk_window_present (GTK_WINDOW (window));
4296 modest_ui_actions_on_change_fullscreen (GtkAction *action,
4297 ModestWindow *window)
4299 ModestWindowMgr *mgr;
4300 gboolean fullscreen;
4302 g_return_if_fail (MODEST_IS_WINDOW (window));
4304 mgr = modest_runtime_get_window_mgr ();
4305 fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
4306 modest_window_mgr_set_fullscreen_mode (mgr, !fullscreen);
4308 #ifndef MODEST_TOOLKIT_HILDON2
4309 gtk_window_present (GTK_WINDOW (window));
4314 * Used by modest_ui_actions_on_details to call do_headers_action
4317 headers_action_show_details (TnyHeader *header,
4318 ModestWindow *window,
4322 modest_platform_run_header_details_dialog (GTK_WINDOW (window), header);
4326 * Show the header details in a ModestDetailsDialog widget
4329 modest_ui_actions_on_details (GtkAction *action,
4332 TnyList * headers_list;
4336 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
4339 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW (win));
4342 g_object_unref (msg);
4344 headers_list = get_selected_headers (win);
4348 iter = tny_list_create_iterator (headers_list);
4350 header = TNY_HEADER (tny_iterator_get_current (iter));
4352 headers_action_show_details (header, win, NULL);
4353 g_object_unref (header);
4356 g_object_unref (iter);
4357 g_object_unref (headers_list);
4359 } else if (MODEST_IS_MAIN_WINDOW (win)) {
4360 GtkWidget *folder_view, *header_view;
4362 /* Check which widget has the focus */
4363 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
4364 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
4365 if (gtk_widget_is_focus (folder_view)) {
4366 TnyFolderStore *folder_store
4367 = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
4368 if (!folder_store) {
4369 g_warning ("%s: No item was selected.\n", __FUNCTION__);
4372 /* Show only when it's a folder */
4373 /* This function should not be called for account items,
4374 * because we dim the menu item for them. */
4375 if (TNY_IS_FOLDER (folder_store)) {
4376 modest_platform_run_folder_details_dialog (GTK_WINDOW (win),
4377 TNY_FOLDER (folder_store));
4380 g_object_unref (folder_store);
4383 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
4384 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
4385 /* Show details of each header */
4386 do_headers_action (win, headers_action_show_details, header_view);
4392 modest_ui_actions_on_toggle_show_cc (GtkToggleAction *toggle,
4393 ModestMsgEditWindow *window)
4395 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4397 modest_msg_edit_window_show_cc (window, gtk_toggle_action_get_active (toggle));
4401 modest_ui_actions_on_toggle_show_bcc (GtkToggleAction *toggle,
4402 ModestMsgEditWindow *window)
4404 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4406 modest_msg_edit_window_show_bcc (window, gtk_toggle_action_get_active (toggle));
4410 modest_ui_actions_toggle_folders_view (GtkAction *action,
4411 ModestMainWindow *main_window)
4413 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
4415 if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)))
4416 modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SPLIT);
4418 modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SIMPLE);
4422 modest_ui_actions_on_toggle_toolbar (GtkToggleAction *toggle,
4423 ModestWindow *window)
4425 gboolean active, fullscreen = FALSE;
4426 ModestWindowMgr *mgr;
4428 active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle));
4430 /* Check if we want to toggle the toolbar view in fullscreen
4432 if (!strcmp (gtk_action_get_name (GTK_ACTION (toggle)),
4433 "ViewShowToolbarFullScreen")) {
4437 /* Toggle toolbar */
4438 mgr = modest_runtime_get_window_mgr ();
4439 modest_window_mgr_show_toolbars (mgr, G_TYPE_FROM_INSTANCE (window), active, fullscreen);
4443 modest_ui_actions_msg_edit_on_select_font (GtkAction *action,
4444 ModestMsgEditWindow *window)
4446 modest_msg_edit_window_select_font (window);
4451 modest_ui_actions_on_folder_display_name_changed (ModestFolderView *folder_view,
4452 const gchar *display_name,
4455 /* don't update the display name if it was already set;
4456 * updating the display name apparently is expensive */
4457 const gchar* old_name = gtk_window_get_title (window);
4459 if (display_name == NULL)
4462 if (old_name && display_name && strcmp (old_name, display_name) == 0)
4463 return; /* don't do anything */
4465 /* This is usually used to change the title of the main window, which
4466 * is the one that holds the folder view. Note that this change can
4467 * happen even when the widget doesn't have the focus. */
4468 gtk_window_set_title (window, display_name);
4473 modest_ui_actions_on_select_contacts (GtkAction *action, ModestMsgEditWindow *window)
4475 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4476 modest_msg_edit_window_select_contacts (window);
4480 modest_ui_actions_on_check_names (GtkAction *action, ModestMsgEditWindow *window)
4482 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4483 modest_msg_edit_window_check_names (window, FALSE);
4487 create_move_to_dialog_on_new_folder(GtkWidget *button, gpointer user_data)
4489 modest_ui_actions_create_folder (gtk_widget_get_toplevel (button),
4490 GTK_WIDGET (user_data));
4494 * This function is used to track changes in the selection of the
4495 * folder view that is inside the "move to" dialog to enable/disable
4496 * the OK button because we do not want the user to select a disallowed
4497 * destination for a folder.
4498 * The user also not desired to be able to use NEW button on items where
4499 * folder creation is not possibel.
4502 on_move_to_dialog_folder_selection_changed (ModestFolderView* self,
4503 TnyFolderStore *folder_store,
4507 GtkWidget *dialog = NULL;
4508 GtkWidget *ok_button = NULL, *new_button = NULL;
4509 gboolean ok_sensitive = TRUE, new_sensitive = TRUE;
4510 gboolean moving_folder = FALSE;
4511 gboolean is_local_account = TRUE;
4512 GtkWidget *folder_view = NULL;
4513 ModestTnyFolderRules rules;
4515 g_return_if_fail (MODEST_IS_FOLDER_VIEW(self));
4520 /* Get the OK button */
4521 dialog = gtk_widget_get_ancestor (GTK_WIDGET (self), GTK_TYPE_DIALOG);
4525 ok_button = g_object_get_data (G_OBJECT (dialog), MOVE_FOLDER_OK_BUTTON);
4526 new_button = g_object_get_data (G_OBJECT (dialog), MOVE_FOLDER_NEW_BUTTON);
4528 /* check if folder_store is an remote account */
4529 if (TNY_IS_ACCOUNT (folder_store)) {
4530 TnyAccount *local_account = NULL;
4531 TnyAccount *mmc_account = NULL;
4532 ModestTnyAccountStore *account_store = NULL;
4534 account_store = modest_runtime_get_account_store ();
4535 local_account = modest_tny_account_store_get_local_folders_account (account_store);
4536 mmc_account = modest_tny_account_store_get_mmc_folders_account (account_store);
4538 if ((gpointer) local_account != (gpointer) folder_store &&
4539 (gpointer) mmc_account != (gpointer) folder_store) {
4540 ModestProtocolType proto;
4541 proto = modest_tny_account_get_protocol_type (TNY_ACCOUNT (folder_store));
4542 if (proto == MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
4543 proto = MODEST_PROTOCOLS_STORE_MAILDIR;
4545 is_local_account = FALSE;
4546 /* New button should be dimmed on remote
4548 new_sensitive = (modest_protocol_registry_protocol_type_has_tag (modest_runtime_get_protocol_registry (),
4550 MODEST_PROTOCOL_REGISTRY_STORE_HAS_FOLDERS));
4552 g_object_unref (local_account);
4554 /* It could not exist */
4556 g_object_unref (mmc_account);
4559 /* Check the target folder rules */
4560 if (TNY_IS_FOLDER (folder_store)) {
4561 rules = modest_tny_folder_get_rules (TNY_FOLDER (folder_store));
4562 if (rules & MODEST_FOLDER_RULES_FOLDER_NON_WRITEABLE) {
4563 ok_sensitive = FALSE;
4564 new_sensitive = FALSE;
4569 /* Check if we're moving a folder */
4570 if (MODEST_IS_MAIN_WINDOW (user_data)) {
4571 /* Get the widgets */
4572 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (user_data),
4573 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
4574 if (gtk_widget_is_focus (folder_view))
4575 moving_folder = TRUE;
4578 if (moving_folder) {
4579 TnyFolderStore *moved_folder = NULL, *parent = NULL;
4581 /* Get the folder to move */
4582 moved_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
4584 /* Check that we're not moving to the same folder */
4585 if (TNY_IS_FOLDER (moved_folder)) {
4586 parent = tny_folder_get_folder_store (TNY_FOLDER (moved_folder));
4587 if (parent == folder_store)
4588 ok_sensitive = FALSE;
4589 g_object_unref (parent);
4592 if (ok_sensitive && TNY_IS_ACCOUNT (folder_store)) {
4593 /* Do not allow to move to an account unless it's the
4594 local folders account */
4595 if (!is_local_account)
4596 ok_sensitive = FALSE;
4599 if (ok_sensitive && (moved_folder == folder_store)) {
4600 /* Do not allow to move to itself */
4601 ok_sensitive = FALSE;
4603 g_object_unref (moved_folder);
4605 TnyFolder *src_folder = NULL;
4607 /* Moving a message */
4608 if (MODEST_IS_MSG_VIEW_WINDOW (user_data)) {
4610 TnyHeader *header = NULL;
4611 header = modest_msg_view_window_get_header
4612 (MODEST_MSG_VIEW_WINDOW (user_data));
4613 if (!TNY_IS_HEADER(header))
4614 g_warning ("%s: could not get source header", __FUNCTION__);
4616 src_folder = tny_header_get_folder (header);
4619 g_object_unref (header);
4622 TNY_FOLDER (modest_folder_view_get_selected
4623 (MODEST_FOLDER_VIEW (folder_view)));
4626 if (TNY_IS_FOLDER(src_folder)) {
4627 /* Do not allow to move the msg to the same folder */
4628 /* Do not allow to move the msg to an account */
4629 if ((gpointer) src_folder == (gpointer) folder_store ||
4630 TNY_IS_ACCOUNT (folder_store))
4631 ok_sensitive = FALSE;
4632 g_object_unref (src_folder);
4634 g_warning ("%s: could not get source folder", __FUNCTION__);
4638 /* Set sensitivity of the OK button */
4639 gtk_widget_set_sensitive (ok_button, ok_sensitive);
4640 /* Set sensitivity of the NEW button */
4641 gtk_widget_set_sensitive (new_button, new_sensitive);
4645 #define MODEST_MOVE_TO_DIALOG_FOLDER_VIEW "move-to-dialog-folder-view"
4648 get_folder_view_from_move_to_dialog (GtkWidget *move_to_dialog)
4650 return GTK_WIDGET(g_object_get_data (G_OBJECT(move_to_dialog),
4651 MODEST_MOVE_TO_DIALOG_FOLDER_VIEW));
4655 create_move_to_dialog (GtkWindow *win,
4656 GtkWidget *folder_view,
4657 GtkWidget **tree_view)
4660 #ifdef MODEST_TOOLKIT_HILDON2
4661 GtkWidget *pannable;
4665 GtkWidget *new_button, *ok_button;
4667 dialog = gtk_dialog_new_with_buttons (_("mcen_ti_moveto_folders_title"),
4669 GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR | GTK_DIALOG_DESTROY_WITH_PARENT,
4672 #ifndef MODEST_TOOLKIT_GTK
4673 ok_button = gtk_dialog_add_button (GTK_DIALOG (dialog), _("mcen_bd_dialog_ok"), GTK_RESPONSE_ACCEPT);
4674 /* We do this manually so GTK+ does not associate a response ID for
4676 new_button = gtk_button_new_from_stock (_("mcen_bd_new"));
4677 gtk_box_pack_end (GTK_BOX (GTK_DIALOG (dialog)->action_area), new_button, FALSE, FALSE, 0);
4678 gtk_widget_show (new_button);
4679 #ifndef MODEST_TOOLKIT_HILDON2
4680 gtk_dialog_add_button (GTK_DIALOG (dialog), _("mcen_bd_dialog_cancel"), GTK_RESPONSE_REJECT);
4683 /* We do this manually so GTK+ does not associate a response ID for
4685 new_button = gtk_button_new_with_label (_("mcen_ti_new_folder"));
4686 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area), new_button, FALSE, FALSE, 0);
4687 gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (GTK_DIALOG (dialog)->action_area), new_button, TRUE);
4688 gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT);
4689 ok_button = gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_OK, GTK_RESPONSE_ACCEPT);
4690 gtk_container_set_border_width (GTK_CONTAINER (dialog), 12);
4691 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 24);
4693 g_object_set_data (G_OBJECT (dialog), MOVE_FOLDER_OK_BUTTON, ok_button);
4694 g_object_set_data (G_OBJECT (dialog), MOVE_FOLDER_NEW_BUTTON, new_button);
4696 /* Create scrolled window */
4697 #ifdef MODEST_TOOLKIT_HILDON2
4698 pannable = hildon_pannable_area_new ();
4700 scroll = gtk_scrolled_window_new (NULL, NULL);
4701 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll),
4702 GTK_POLICY_AUTOMATIC,
4703 GTK_POLICY_AUTOMATIC);
4706 #ifdef MODEST_TOOLKIT_GTK
4707 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scroll), GTK_SHADOW_IN);
4710 /* Create folder view */
4711 *tree_view = modest_platform_create_folder_view (NULL);
4713 /* Track changes in the selection to
4714 * disable the OK button whenever "Move to" is not possible
4715 * disbale NEW button whenever New is not possible */
4716 g_signal_connect (*tree_view,
4717 "folder_selection_changed",
4718 G_CALLBACK (on_move_to_dialog_folder_selection_changed),
4721 /* Listen to clicks on New button */
4722 g_signal_connect (G_OBJECT (new_button),
4724 G_CALLBACK(create_move_to_dialog_on_new_folder),
4727 /* It could happen that we're trying to move a message from a
4728 window (msg window for example) after the main window was
4729 closed, so we can not just get the model of the folder
4731 if (MODEST_IS_FOLDER_VIEW (folder_view)) {
4732 const gchar *visible_id = NULL;
4734 modest_folder_view_set_style (MODEST_FOLDER_VIEW (*tree_view),
4735 MODEST_FOLDER_VIEW_STYLE_SHOW_ALL);
4736 modest_folder_view_copy_model (MODEST_FOLDER_VIEW(folder_view),
4737 MODEST_FOLDER_VIEW(*tree_view));
4740 modest_folder_view_get_account_id_of_visible_server_account (MODEST_FOLDER_VIEW(folder_view));
4742 /* Show the same account than the one that is shown in the main window */
4743 modest_folder_view_set_account_id_of_visible_server_account (MODEST_FOLDER_VIEW(*tree_view),
4746 const gchar *active_account_name = NULL;
4747 ModestAccountMgr *mgr = NULL;
4748 ModestAccountSettings *settings = NULL;
4749 ModestServerAccountSettings *store_settings = NULL;
4751 modest_folder_view_set_style (MODEST_FOLDER_VIEW (*tree_view),
4752 MODEST_FOLDER_VIEW_STYLE_SHOW_ALL);
4753 modest_folder_view_update_model (MODEST_FOLDER_VIEW (*tree_view),
4754 TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()));
4756 active_account_name = modest_window_get_active_account (MODEST_WINDOW (win));
4757 mgr = modest_runtime_get_account_mgr ();
4758 settings = modest_account_mgr_load_account_settings (mgr, active_account_name);
4761 const gchar *store_account_name;
4762 store_settings = modest_account_settings_get_store_settings (settings);
4763 store_account_name = modest_server_account_settings_get_account_name (store_settings);
4765 modest_folder_view_set_account_id_of_visible_server_account (MODEST_FOLDER_VIEW (*tree_view),
4766 store_account_name);
4767 g_object_unref (store_settings);
4768 g_object_unref (settings);
4772 /* we keep a pointer to the embedded folder view, so we can retrieve it with
4773 * get_folder_view_from_move_to_dialog
4774 * (see above) later (needed for focus handling)
4776 g_object_set_data (G_OBJECT(dialog), MODEST_MOVE_TO_DIALOG_FOLDER_VIEW, *tree_view);
4779 /* Hide special folders */
4780 modest_folder_view_show_non_move_folders (MODEST_FOLDER_VIEW (*tree_view), FALSE);
4782 #ifdef MODEST_TOOLKIT_HILDON2
4783 gtk_container_add (GTK_CONTAINER (pannable), *tree_view);
4784 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
4785 pannable, TRUE, TRUE, 0);
4787 gtk_container_add (GTK_CONTAINER (scroll), *tree_view);
4788 /* Add scroll to dialog */
4789 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
4790 scroll, TRUE, TRUE, 0);
4794 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
4795 #ifndef MODEST_TOOLKIT_GTK
4796 gtk_window_set_default_size (GTK_WINDOW (dialog), 300, 300);
4798 gtk_window_set_default_size (GTK_WINDOW (dialog), 600, 400);
4807 * Shows a confirmation dialog to the user when we're moving messages
4808 * from a remote server to the local storage. Returns the dialog
4809 * response. If it's other kind of movement then it always returns
4812 * This one is used by the next functions:
4813 * modest_ui_actions_on_paste - commented out
4814 * drag_and_drop_from_header_view (for d&d in modest_folder_view.c)
4817 modest_ui_actions_msgs_move_to_confirmation (ModestWindow *win,
4818 TnyFolder *dest_folder,
4822 gint response = GTK_RESPONSE_OK;
4823 TnyAccount *account = NULL;
4824 TnyFolder *src_folder = NULL;
4825 TnyIterator *iter = NULL;
4826 TnyHeader *header = NULL;
4828 /* return with OK if the destination is a remote folder */
4829 if (modest_tny_folder_is_remote_folder (dest_folder))
4830 return GTK_RESPONSE_OK;
4832 /* Get source folder */
4833 iter = tny_list_create_iterator (headers);
4834 header = TNY_HEADER (tny_iterator_get_current (iter));
4836 src_folder = tny_header_get_folder (header);
4837 g_object_unref (header);
4839 g_object_unref (iter);
4841 /* if no src_folder, message may be an attahcment */
4842 if (src_folder == NULL)
4843 return GTK_RESPONSE_CANCEL;
4845 /* If the source is a local or MMC folder */
4846 if (!modest_tny_folder_is_remote_folder (src_folder)) {
4847 g_object_unref (src_folder);
4848 return GTK_RESPONSE_OK;
4851 /* Get the account */
4852 account = tny_folder_get_account (src_folder);
4854 /* now if offline we ask the user */
4855 if(connect_to_get_msg (win, tny_list_get_length (headers), account))
4856 response = GTK_RESPONSE_OK;
4858 response = GTK_RESPONSE_CANCEL;
4861 g_object_unref (src_folder);
4862 g_object_unref (account);
4868 move_to_helper_destroyer (gpointer user_data)
4870 MoveToHelper *helper = (MoveToHelper *) user_data;
4872 /* Close the "Pasting" information banner */
4873 if (helper->banner) {
4874 gtk_widget_destroy (GTK_WIDGET (helper->banner));
4875 g_object_unref (helper->banner);
4877 if (gtk_tree_row_reference_valid (helper->reference)) {
4878 gtk_tree_row_reference_free (helper->reference);
4879 helper->reference = NULL;
4885 move_to_cb (ModestMailOperation *mail_op,
4888 MoveToHelper *helper = (MoveToHelper *) user_data;
4890 /* Note that the operation could have failed, in that case do
4892 if (modest_mail_operation_get_status (mail_op) ==
4893 MODEST_MAIL_OPERATION_STATUS_SUCCESS) {
4895 GObject *object = modest_mail_operation_get_source (mail_op);
4896 if (MODEST_IS_MSG_VIEW_WINDOW (object)) {
4897 ModestMsgViewWindow *self = MODEST_MSG_VIEW_WINDOW (object);
4899 if (!modest_msg_view_window_select_next_message (self) &&
4900 !modest_msg_view_window_select_previous_message (self)) {
4901 /* No more messages to view, so close this window */
4902 modest_ui_actions_on_close_window (NULL, MODEST_WINDOW(self));
4904 } else if (MODEST_IS_MAIN_WINDOW (object) &&
4905 gtk_tree_row_reference_valid (helper->reference)) {
4906 GtkWidget *header_view;
4908 GtkTreeSelection *sel;
4910 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(object),
4911 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
4912 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
4913 path = gtk_tree_row_reference_get_path (helper->reference);
4914 /* We need to unselect the previous one
4915 because we could be copying instead of
4917 gtk_tree_selection_unselect_all (sel);
4918 gtk_tree_selection_select_path (sel, path);
4919 gtk_tree_path_free (path);
4921 g_object_unref (object);
4923 /* Destroy the helper */
4924 move_to_helper_destroyer (helper);
4928 folder_move_to_cb (ModestMailOperation *mail_op,
4929 TnyFolder *new_folder,
4932 GtkWidget *folder_view;
4935 object = modest_mail_operation_get_source (mail_op);
4936 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(object),
4937 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
4938 g_object_ref (folder_view);
4939 g_object_unref (object);
4940 move_to_cb (mail_op, user_data);
4941 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view), new_folder, FALSE);
4942 g_object_unref (folder_view);
4946 msgs_move_to_cb (ModestMailOperation *mail_op,
4949 move_to_cb (mail_op, user_data);
4953 modest_ui_actions_move_folder_error_handler (ModestMailOperation *mail_op,
4956 ModestWindow *main_window = NULL;
4958 /* Disable next automatic folder selection */
4959 main_window = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (),
4960 FALSE); /* don't create */
4962 GObject *win = NULL;
4963 GtkWidget *folder_view = NULL;
4965 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (main_window),
4966 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
4967 modest_folder_view_disable_next_folder_selection (MODEST_FOLDER_VIEW(folder_view));
4969 if (user_data && TNY_IS_FOLDER (user_data)) {
4970 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view),
4971 TNY_FOLDER (user_data), FALSE);
4974 /* Show notification dialog only if the main window exists */
4975 win = modest_mail_operation_get_source (mail_op);
4976 modest_platform_run_information_dialog ((GtkWindow *) win,
4977 _("mail_in_ui_folder_move_target_error"),
4980 g_object_unref (win);
4985 open_msg_for_purge_cb (ModestMailOperation *mail_op,
4994 gint pending_purges = 0;
4995 gboolean some_purged = FALSE;
4996 ModestWindow *win = MODEST_WINDOW (user_data);
4997 ModestWindowMgr *mgr = modest_runtime_get_window_mgr ();
4999 /* If there was any error */
5000 if (!modest_ui_actions_msg_retrieval_check (mail_op, header, msg)) {
5001 modest_window_mgr_unregister_header (mgr, header);
5005 /* Once the message has been retrieved for purging, we check if
5006 * it's all ok for purging */
5008 parts = tny_simple_list_new ();
5009 tny_mime_part_get_parts (TNY_MIME_PART (msg), parts);
5010 iter = tny_list_create_iterator (parts);
5012 while (!tny_iterator_is_done (iter)) {
5014 part = TNY_MIME_PART (tny_iterator_get_current (iter));
5015 if (part && (tny_mime_part_is_attachment (part) || TNY_IS_MSG (part))) {
5016 if (tny_mime_part_is_purged (part))
5023 g_object_unref (part);
5025 tny_iterator_next (iter);
5027 g_object_unref (iter);
5030 if (pending_purges>0) {
5032 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),_("mcen_nc_purge_file_text_inbox"));
5034 if (response == GTK_RESPONSE_OK) {
5037 modest_platform_animation_banner (GTK_WIDGET (win), NULL, _("mcen_ib_removing_attachment"));
5038 iter = tny_list_create_iterator (parts);
5039 while (!tny_iterator_is_done (iter)) {
5042 part = TNY_MIME_PART (tny_iterator_get_current (iter));
5043 if (part && (tny_mime_part_is_attachment (part) || TNY_IS_MSG (part)))
5044 tny_mime_part_set_purged (part);
5047 g_object_unref (part);
5049 tny_iterator_next (iter);
5051 g_object_unref (iter);
5053 tny_msg_rewrite_cache (msg);
5055 gtk_widget_destroy (info);
5059 modest_window_mgr_unregister_header (mgr, header);
5061 g_object_unref (parts);
5065 modest_ui_actions_on_main_window_remove_attachments (GtkAction *action,
5066 ModestMainWindow *win)
5068 GtkWidget *header_view;
5069 TnyList *header_list;
5071 TnyHeaderFlags flags;
5072 ModestWindow *msg_view_window = NULL;
5075 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win));
5077 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
5078 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
5080 header_list = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW (header_view));
5082 g_warning ("%s: no header selected", __FUNCTION__);
5086 if (tny_list_get_length (header_list) == 1) {
5087 TnyIterator *iter = tny_list_create_iterator (header_list);
5088 header = TNY_HEADER (tny_iterator_get_current (iter));
5089 g_object_unref (iter);
5093 if (!header || !TNY_IS_HEADER(header)) {
5094 g_warning ("%s: header is not valid", __FUNCTION__);
5098 found = modest_window_mgr_find_registered_header (modest_runtime_get_window_mgr (),
5099 header, &msg_view_window);
5100 flags = tny_header_get_flags (header);
5101 if (!(flags & TNY_HEADER_FLAG_CACHED))
5104 if (msg_view_window != NULL)
5105 modest_msg_view_window_remove_attachments (MODEST_MSG_VIEW_WINDOW (msg_view_window), TRUE);
5107 /* do nothing; uid was registered before, so window is probably on it's way */
5108 g_warning ("debug: header %p has already been registered", header);
5111 ModestMailOperation *mail_op = NULL;
5112 modest_window_mgr_register_header (modest_runtime_get_window_mgr (), header, NULL);
5113 mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT (win),
5114 modest_ui_actions_disk_operations_error_handler,
5116 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
5117 modest_mail_operation_get_msg (mail_op, header, FALSE, open_msg_for_purge_cb, win);
5119 g_object_unref (mail_op);
5122 g_object_unref (header);
5124 g_object_unref (header_list);
5128 * Checks if we need a connection to do the transfer and if the user
5129 * wants to connect to complete it
5132 modest_ui_actions_xfer_messages_check (GtkWindow *parent_window,
5133 TnyFolderStore *src_folder,
5135 TnyFolder *dst_folder,
5136 gboolean delete_originals,
5137 gboolean *need_connection,
5140 TnyAccount *src_account;
5141 gint uncached_msgs = 0;
5143 uncached_msgs = header_list_count_uncached_msgs (headers);
5145 /* We don't need any further check if
5147 * 1- the source folder is local OR
5148 * 2- the device is already online
5150 if (!modest_tny_folder_store_is_remote (src_folder) ||
5151 tny_device_is_online (modest_runtime_get_device())) {
5152 *need_connection = FALSE;
5157 /* We must ask for a connection when
5159 * - the message(s) is not already cached OR
5160 * - the message(s) is cached but the leave_on_server setting
5161 * is FALSE (because we need to sync the source folder to
5162 * delete the message from the server (for IMAP we could do it
5163 * offline, it'll take place the next time we get a
5166 src_account = get_account_from_folder_store (src_folder);
5167 if (uncached_msgs > 0) {
5171 *need_connection = TRUE;
5172 num_headers = tny_list_get_length (headers);
5173 msg = ngettext ("mcen_nc_get_msg", "mcen_nc_get_msgs", num_headers);
5175 if (modest_platform_run_confirmation_dialog (parent_window, msg) ==
5176 GTK_RESPONSE_CANCEL) {
5182 /* The transfer is possible and the user wants to */
5185 if (remote_folder_has_leave_on_server (src_folder) && delete_originals) {
5186 const gchar *account_name;
5187 gboolean leave_on_server;
5189 account_name = modest_tny_account_get_parent_modest_account_name_for_server_account (src_account);
5190 leave_on_server = modest_account_mgr_get_leave_on_server (modest_runtime_get_account_mgr (),
5193 if (leave_on_server == TRUE) {
5194 *need_connection = FALSE;
5196 *need_connection = TRUE;
5199 *need_connection = FALSE;
5204 g_object_unref (src_account);
5208 xfer_messages_error_handler (ModestMailOperation *mail_op,
5211 ModestWindow *main_window = NULL;
5213 /* Disable next automatic folder selection */
5214 main_window = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (),
5215 FALSE); /* don't create */
5217 GObject *win = modest_mail_operation_get_source (mail_op);
5218 modest_platform_run_information_dialog ((GtkWindow *) win,
5219 _("mail_in_ui_folder_move_target_error"),
5222 g_object_unref (win);
5224 move_to_helper_destroyer (user_data);
5228 TnyFolderStore *dst_folder;
5233 * Utility function that transfer messages from both the main window
5234 * and the msg view window when using the "Move to" dialog
5237 xfer_messages_performer (gboolean canceled,
5239 GtkWindow *parent_window,
5240 TnyAccount *account,
5243 ModestWindow *win = MODEST_WINDOW (parent_window);
5244 TnyAccount *dst_account = NULL;
5245 gboolean dst_forbids_message_add = FALSE;
5246 XferMsgsHelper *helper;
5247 MoveToHelper *movehelper;
5248 ModestMailOperation *mail_op;
5250 helper = (XferMsgsHelper *) user_data;
5252 if (canceled || err) {
5253 if (!check_memory_full_error ((GtkWidget *) parent_window, err)) {
5254 /* Show the proper error message */
5255 modest_ui_actions_on_account_connection_error (parent_window, account);
5260 dst_account = tny_folder_get_account (TNY_FOLDER (helper->dst_folder));
5262 /* tinymail will return NULL for local folders it seems */
5263 dst_forbids_message_add = modest_protocol_registry_protocol_type_has_tag (modest_runtime_get_protocol_registry (),
5264 modest_tny_account_get_protocol_type (dst_account),
5265 MODEST_PROTOCOL_REGISTRY_STORE_FORBID_MESSAGE_ADD);
5266 g_object_unref (dst_account);
5268 if (dst_forbids_message_add) {
5269 modest_platform_information_banner (GTK_WIDGET (win),
5271 ngettext("mail_in_ui_folder_move_target_error",
5272 "mail_in_ui_folder_move_targets_error",
5273 tny_list_get_length (helper->headers)));
5277 movehelper = g_new0 (MoveToHelper, 1);
5278 movehelper->banner = modest_platform_animation_banner (GTK_WIDGET (win), NULL,
5279 _CS("ckct_nw_pasting"));
5280 if (movehelper->banner != NULL) {
5281 g_object_ref (movehelper->banner);
5282 gtk_widget_show (GTK_WIDGET (movehelper->banner));
5285 if (MODEST_IS_MAIN_WINDOW (win)) {
5286 GtkWidget *header_view =
5287 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
5288 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
5289 movehelper->reference = get_next_after_selected_headers (MODEST_HEADER_VIEW (header_view));
5292 /* Perform the mail operation */
5293 mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT(win),
5294 xfer_messages_error_handler,
5296 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
5299 modest_mail_operation_xfer_msgs (mail_op,
5301 TNY_FOLDER (helper->dst_folder),
5306 g_object_unref (G_OBJECT (mail_op));
5308 g_object_unref (helper->dst_folder);
5309 g_object_unref (helper->headers);
5310 g_slice_free (XferMsgsHelper, helper);
5314 TnyFolder *src_folder;
5315 TnyFolderStore *dst_folder;
5316 gboolean delete_original;
5317 GtkWidget *folder_view;
5321 on_move_folder_cb (gboolean canceled, GError *err, GtkWindow *parent_window,
5322 TnyAccount *account, gpointer user_data)
5324 MoveFolderInfo *info = (MoveFolderInfo*)user_data;
5325 GtkTreeSelection *sel;
5326 ModestMailOperation *mail_op = NULL;
5328 if (canceled || err || !MODEST_IS_MAIN_WINDOW (parent_window)) {
5329 g_object_unref (G_OBJECT (info->src_folder));
5330 g_object_unref (G_OBJECT (info->dst_folder));
5335 MoveToHelper *helper = g_new0 (MoveToHelper, 1);
5336 helper->banner = modest_platform_animation_banner (GTK_WIDGET (parent_window), NULL,
5337 _CS("ckct_nw_pasting"));
5338 if (helper->banner != NULL) {
5339 g_object_ref (helper->banner);
5340 gtk_widget_show (GTK_WIDGET(helper->banner));
5342 /* Clean folder on header view before moving it */
5343 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (info->folder_view));
5344 gtk_tree_selection_unselect_all (sel);
5346 /* Let gtk events run. We need that the folder
5347 view frees its reference to the source
5348 folder *before* issuing the mail operation
5349 so we need the signal handler of selection
5350 changed to happen before the mail
5352 while (gtk_events_pending ())
5353 gtk_main_iteration (); */
5356 modest_mail_operation_new_with_error_handling (G_OBJECT(parent_window),
5357 modest_ui_actions_move_folder_error_handler,
5358 info->src_folder, NULL);
5359 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
5362 /* Select *after* the changes */
5363 /* TODO: this function hangs UI after transfer */
5364 /* modest_folder_view_select_folder (MODEST_FOLDER_VIEW(folder_view), */
5365 /* TNY_FOLDER (src_folder), TRUE); */
5367 modest_folder_view_select_folder (MODEST_FOLDER_VIEW(info->folder_view),
5368 TNY_FOLDER (info->dst_folder), TRUE);
5369 modest_mail_operation_xfer_folder (mail_op,
5370 TNY_FOLDER (info->src_folder),
5372 info->delete_original,
5375 g_object_unref (G_OBJECT (info->src_folder));
5377 /* if (modest_mail_operation_get_status (mail_op) == MODEST_MAIL_OPERATION_STATUS_SUCCESS) { */
5380 /* Unref mail operation */
5381 g_object_unref (G_OBJECT (mail_op));
5382 g_object_unref (G_OBJECT (info->dst_folder));
5387 get_account_from_folder_store (TnyFolderStore *folder_store)
5389 if (TNY_IS_ACCOUNT (folder_store))
5390 return g_object_ref (folder_store);
5392 return tny_folder_get_account (TNY_FOLDER (folder_store));
5396 * UI handler for the "Move to" action when invoked from the
5400 modest_ui_actions_on_main_window_move_to (GtkAction *action,
5401 GtkWidget *folder_view,
5402 TnyFolderStore *dst_folder,
5403 ModestMainWindow *win)
5405 ModestHeaderView *header_view = NULL;
5406 TnyFolderStore *src_folder = NULL;
5408 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win));
5410 /* Get the source folder */
5411 src_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
5413 /* Get header view */
5414 header_view = MODEST_HEADER_VIEW(modest_main_window_get_child_widget (win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW));
5416 /* Get folder or messages to transfer */
5417 if (gtk_widget_is_focus (folder_view)) {
5418 gboolean do_xfer = TRUE;
5420 /* Allow only to transfer folders to the local root folder */
5421 if (TNY_IS_ACCOUNT (dst_folder) &&
5422 !MODEST_IS_TNY_LOCAL_FOLDERS_ACCOUNT (dst_folder) &&
5423 !modest_tny_account_is_memory_card_account (TNY_ACCOUNT (dst_folder))) {
5425 } else if (!TNY_IS_FOLDER (src_folder)) {
5426 g_warning ("%s: src_folder is not a TnyFolder.\n", __FUNCTION__);
5431 MoveFolderInfo *info = g_new0 (MoveFolderInfo, 1);
5432 DoubleConnectionInfo *connect_info = g_slice_new (DoubleConnectionInfo);
5434 info->src_folder = g_object_ref (src_folder);
5435 info->dst_folder = g_object_ref (dst_folder);
5436 info->delete_original = TRUE;
5437 info->folder_view = folder_view;
5439 connect_info->callback = on_move_folder_cb;
5440 connect_info->dst_account = get_account_from_folder_store (TNY_FOLDER_STORE (dst_folder));
5441 connect_info->data = info;
5443 modest_platform_double_connect_and_perform(GTK_WINDOW (win), TRUE,
5444 TNY_FOLDER_STORE (src_folder),
5447 } else if (gtk_widget_is_focus (GTK_WIDGET(header_view))) {
5450 headers = modest_header_view_get_selected_headers(header_view);
5452 /* Transfer the messages */
5453 modest_ui_actions_transfer_messages_helper (GTK_WINDOW (win), TNY_FOLDER (src_folder),
5454 headers, TNY_FOLDER (dst_folder));
5456 g_object_unref (headers);
5460 g_object_unref (src_folder);
5465 modest_ui_actions_transfer_messages_helper (GtkWindow *win,
5466 TnyFolder *src_folder,
5468 TnyFolder *dst_folder)
5470 gboolean need_connection = TRUE;
5471 gboolean do_xfer = TRUE;
5472 XferMsgsHelper *helper;
5474 g_return_if_fail (TNY_IS_FOLDER (src_folder));
5475 g_return_if_fail (TNY_IS_FOLDER (dst_folder));
5476 g_return_if_fail (TNY_IS_LIST (headers));
5478 modest_ui_actions_xfer_messages_check (win, TNY_FOLDER_STORE (src_folder),
5479 headers, TNY_FOLDER (dst_folder),
5480 TRUE, &need_connection,
5483 /* If we don't want to transfer just return */
5487 /* Create the helper */
5488 helper = g_slice_new (XferMsgsHelper);
5489 helper->dst_folder = g_object_ref (dst_folder);
5490 helper->headers = g_object_ref (headers);
5492 if (need_connection) {
5493 DoubleConnectionInfo *connect_info = g_slice_new (DoubleConnectionInfo);
5494 connect_info->callback = xfer_messages_performer;
5495 connect_info->dst_account = tny_folder_get_account (TNY_FOLDER (dst_folder));
5496 connect_info->data = helper;
5498 modest_platform_double_connect_and_perform(GTK_WINDOW (win), TRUE,
5499 TNY_FOLDER_STORE (src_folder),
5502 TnyAccount *src_account = get_account_from_folder_store (TNY_FOLDER_STORE (src_folder));
5503 xfer_messages_performer (FALSE, NULL, GTK_WINDOW (win),
5504 src_account, helper);
5505 g_object_unref (src_account);
5510 * UI handler for the "Move to" action when invoked from the
5511 * ModestMsgViewWindow
5514 modest_ui_actions_on_msg_view_window_move_to (GtkAction *action,
5515 TnyFolderStore *dst_folder,
5516 ModestMsgViewWindow *win)
5518 TnyList *headers = NULL;
5519 TnyHeader *header = NULL;
5520 TnyFolder *src_folder = NULL;
5522 g_return_if_fail (TNY_IS_FOLDER (dst_folder));
5524 /* Create header list */
5525 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
5526 src_folder = TNY_FOLDER (tny_header_get_folder(header));
5527 headers = tny_simple_list_new ();
5528 tny_list_append (headers, G_OBJECT (header));
5530 /* Transfer the messages */
5531 modest_ui_actions_transfer_messages_helper (GTK_WINDOW (win), src_folder, headers,
5532 TNY_FOLDER (dst_folder));
5535 g_object_unref (src_folder);
5536 g_object_unref (header);
5537 g_object_unref (headers);
5541 modest_ui_actions_on_move_to (GtkAction *action,
5544 GtkWidget *dialog = NULL, *folder_view = NULL, *tree_view = NULL;
5546 TnyFolderStore *dst_folder = NULL;
5547 ModestMainWindow *main_window;
5549 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win) ||
5550 MODEST_IS_MSG_VIEW_WINDOW (win));
5552 /* Get the main window if exists */
5553 if (MODEST_IS_MAIN_WINDOW (win))
5554 main_window = MODEST_MAIN_WINDOW (win);
5557 MODEST_MAIN_WINDOW (modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (),
5558 FALSE)); /* don't create */
5560 /* Get the folder view widget if exists */
5562 folder_view = modest_main_window_get_child_widget (main_window,
5563 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
5567 /* Create and run the dialog */
5568 dialog = create_move_to_dialog (GTK_WINDOW (win), folder_view, &tree_view);
5569 modest_folder_view_select_first_inbox_or_local (MODEST_FOLDER_VIEW (tree_view));
5570 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), GTK_WINDOW (dialog), (GtkWindow *) win);
5571 result = gtk_dialog_run (GTK_DIALOG(dialog));
5572 g_object_ref (tree_view);
5573 gtk_widget_destroy (dialog);
5575 if (result != GTK_RESPONSE_ACCEPT)
5578 dst_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (tree_view));
5579 /* Do window specific stuff */
5580 if (MODEST_IS_MAIN_WINDOW (win)) {
5581 modest_ui_actions_on_main_window_move_to (action,
5584 MODEST_MAIN_WINDOW (win));
5586 modest_ui_actions_on_msg_view_window_move_to (action,
5588 MODEST_MSG_VIEW_WINDOW (win));
5592 g_object_unref (dst_folder);
5596 * Calls #HeadersFunc for each header already selected in the main
5597 * window or the message currently being shown in the msg view window
5600 do_headers_action (ModestWindow *win,
5604 TnyList *headers_list = NULL;
5605 TnyIterator *iter = NULL;
5606 TnyHeader *header = NULL;
5607 TnyFolder *folder = NULL;
5610 headers_list = get_selected_headers (win);
5614 /* Get the folder */
5615 iter = tny_list_create_iterator (headers_list);
5616 header = TNY_HEADER (tny_iterator_get_current (iter));
5618 folder = tny_header_get_folder (header);
5619 g_object_unref (header);
5622 /* Call the function for each header */
5623 while (!tny_iterator_is_done (iter)) {
5624 header = TNY_HEADER (tny_iterator_get_current (iter));
5625 func (header, win, user_data);
5626 g_object_unref (header);
5627 tny_iterator_next (iter);
5630 /* Trick: do a poke status in order to speed up the signaling
5632 tny_folder_poke_status (folder);
5635 g_object_unref (folder);
5636 g_object_unref (iter);
5637 g_object_unref (headers_list);
5641 modest_ui_actions_view_attachment (GtkAction *action,
5642 ModestWindow *window)
5644 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
5645 modest_msg_view_window_view_attachment (MODEST_MSG_VIEW_WINDOW (window), NULL);
5647 /* not supported window for this action */
5648 g_return_if_reached ();
5653 modest_ui_actions_save_attachments (GtkAction *action,
5654 ModestWindow *window)
5656 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
5658 if (modest_platform_check_memory_low (MODEST_WINDOW(window), TRUE))
5661 modest_msg_view_window_save_attachments (MODEST_MSG_VIEW_WINDOW (window), NULL);
5663 /* not supported window for this action */
5664 g_return_if_reached ();
5669 modest_ui_actions_remove_attachments (GtkAction *action,
5670 ModestWindow *window)
5672 if (MODEST_IS_MAIN_WINDOW (window)) {
5673 modest_ui_actions_on_main_window_remove_attachments (action, MODEST_MAIN_WINDOW (window));
5674 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
5675 modest_msg_view_window_remove_attachments (MODEST_MSG_VIEW_WINDOW (window), FALSE);
5677 /* not supported window for this action */
5678 g_return_if_reached ();
5683 modest_ui_actions_on_settings (GtkAction *action,
5688 dialog = modest_platform_get_global_settings_dialog ();
5689 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (win));
5690 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
5691 gtk_widget_show_all (dialog);
5693 gtk_dialog_run (GTK_DIALOG (dialog));
5695 gtk_widget_destroy (dialog);
5699 modest_ui_actions_on_help (GtkAction *action,
5702 const gchar *help_id;
5704 g_return_if_fail (win && GTK_IS_WINDOW(win));
5706 help_id = modest_window_mgr_get_help_id (modest_runtime_get_window_mgr(), win);
5709 modest_platform_show_help (GTK_WINDOW (win), help_id);
5713 modest_ui_actions_on_csm_help (GtkAction *action,
5716 const gchar* help_id = NULL;
5717 GtkWidget *folder_view;
5718 TnyFolderStore *folder_store;
5720 g_return_if_fail (win && MODEST_IS_MAIN_WINDOW (win));
5722 /* Get selected folder */
5723 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
5724 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
5725 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
5727 /* Switch help_id */
5728 if (folder_store && TNY_IS_FOLDER (folder_store))
5729 help_id = modest_tny_folder_get_help_id (TNY_FOLDER (folder_store));
5732 g_object_unref (folder_store);
5735 modest_platform_show_help (GTK_WINDOW (win), help_id);
5737 modest_ui_actions_on_help (action, win);
5741 retrieve_contents_cb (ModestMailOperation *mail_op,
5748 /* We only need this callback to show an error in case of
5749 memory low condition */
5750 modest_ui_actions_msg_retrieval_check (mail_op, header, msg);
5754 retrieve_msg_contents_performer (gboolean canceled,
5756 GtkWindow *parent_window,
5757 TnyAccount *account,
5760 ModestMailOperation *mail_op;
5761 TnyList *headers = TNY_LIST (user_data);
5763 if (err || canceled) {
5764 check_memory_full_error ((GtkWidget *) parent_window, err);
5768 /* Create mail operation */
5769 mail_op = modest_mail_operation_new_with_error_handling ((GObject *) parent_window,
5770 modest_ui_actions_disk_operations_error_handler,
5772 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
5773 modest_mail_operation_get_msgs_full (mail_op, headers, retrieve_contents_cb, NULL, NULL);
5776 g_object_unref (mail_op);
5778 g_object_unref (headers);
5779 g_object_unref (account);
5783 modest_ui_actions_on_retrieve_msg_contents (GtkAction *action,
5784 ModestWindow *window)
5786 TnyList *headers = NULL;
5787 TnyAccount *account = NULL;
5788 TnyIterator *iter = NULL;
5789 TnyHeader *header = NULL;
5790 TnyFolder *folder = NULL;
5793 headers = get_selected_headers (window);
5797 /* Pick the account */
5798 iter = tny_list_create_iterator (headers);
5799 header = TNY_HEADER (tny_iterator_get_current (iter));
5800 folder = tny_header_get_folder (header);
5801 account = tny_folder_get_account (folder);
5802 g_object_unref (folder);
5803 g_object_unref (header);
5804 g_object_unref (iter);
5806 /* Connect and perform the message retrieval */
5807 modest_platform_connect_and_perform ((GtkWindow *) window, TRUE,
5808 g_object_ref (account),
5809 retrieve_msg_contents_performer,
5810 g_object_ref (headers));
5813 g_object_unref (account);
5814 g_object_unref (headers);
5818 modest_ui_actions_check_toolbar_dimming_rules (ModestWindow *window)
5820 g_return_if_fail (MODEST_IS_WINDOW (window));
5823 modest_window_check_dimming_rules_group (window, MODEST_DIMMING_RULES_TOOLBAR);
5827 modest_ui_actions_check_menu_dimming_rules (ModestWindow *window)
5829 g_return_if_fail (MODEST_IS_WINDOW (window));
5832 modest_window_check_dimming_rules_group (window, MODEST_DIMMING_RULES_MENU);
5836 modest_ui_actions_on_email_menu_activated (GtkAction *action,
5837 ModestWindow *window)
5839 g_return_if_fail (MODEST_IS_WINDOW (window));
5842 modest_ui_actions_check_menu_dimming_rules (window);
5846 modest_ui_actions_on_edit_menu_activated (GtkAction *action,
5847 ModestWindow *window)
5849 g_return_if_fail (MODEST_IS_WINDOW (window));
5852 modest_ui_actions_check_menu_dimming_rules (window);
5856 modest_ui_actions_on_view_menu_activated (GtkAction *action,
5857 ModestWindow *window)
5859 g_return_if_fail (MODEST_IS_WINDOW (window));
5862 modest_ui_actions_check_menu_dimming_rules (window);
5866 modest_ui_actions_on_format_menu_activated (GtkAction *action,
5867 ModestWindow *window)
5869 g_return_if_fail (MODEST_IS_WINDOW (window));
5872 modest_ui_actions_check_menu_dimming_rules (window);
5876 modest_ui_actions_on_tools_menu_activated (GtkAction *action,
5877 ModestWindow *window)
5879 g_return_if_fail (MODEST_IS_WINDOW (window));
5882 modest_ui_actions_check_menu_dimming_rules (window);
5886 modest_ui_actions_on_attachment_menu_activated (GtkAction *action,
5887 ModestWindow *window)
5889 g_return_if_fail (MODEST_IS_WINDOW (window));
5892 modest_ui_actions_check_menu_dimming_rules (window);
5896 modest_ui_actions_on_toolbar_csm_menu_activated (GtkAction *action,
5897 ModestWindow *window)
5899 g_return_if_fail (MODEST_IS_WINDOW (window));
5902 modest_ui_actions_check_menu_dimming_rules (window);
5906 modest_ui_actions_on_folder_view_csm_menu_activated (GtkAction *action,
5907 ModestWindow *window)
5909 g_return_if_fail (MODEST_IS_WINDOW (window));
5912 modest_ui_actions_check_menu_dimming_rules (window);
5916 modest_ui_actions_on_header_view_csm_menu_activated (GtkAction *action,
5917 ModestWindow *window)
5919 g_return_if_fail (MODEST_IS_WINDOW (window));
5922 modest_ui_actions_check_menu_dimming_rules (window);
5926 modest_ui_actions_on_search_messages (GtkAction *action, ModestWindow *window)
5928 g_return_if_fail (MODEST_IS_WINDOW (window));
5930 /* we check for low-mem; in that case, show a warning, and don't allow
5933 if (modest_platform_check_memory_low (window, TRUE))
5936 modest_platform_show_search_messages (GTK_WINDOW (window));
5940 modest_ui_actions_on_open_addressbook (GtkAction *action, ModestWindow *win)
5942 g_return_if_fail (MODEST_IS_WINDOW (win));
5945 /* we check for low-mem; in that case, show a warning, and don't allow
5946 * for the addressbook
5948 if (modest_platform_check_memory_low (win, TRUE))
5952 modest_platform_show_addressbook (GTK_WINDOW (win));
5957 modest_ui_actions_on_toggle_find_in_page (GtkToggleAction *action,
5958 ModestWindow *window)
5960 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
5962 modest_msg_edit_window_toggle_find_toolbar (MODEST_MSG_EDIT_WINDOW (window), gtk_toggle_action_get_active (action));
5966 on_send_receive_finished (ModestMailOperation *mail_op,
5969 GtkWidget *header_view, *folder_view;
5970 TnyFolderStore *folder_store;
5971 ModestMainWindow *main_win = MODEST_MAIN_WINDOW (user_data);
5973 /* Set send/receive operation finished */
5974 modest_main_window_notify_send_receive_completed (main_win);
5976 /* Don't refresh the current folder if there were any errors */
5977 if (modest_mail_operation_get_status (mail_op) !=
5978 MODEST_MAIL_OPERATION_STATUS_SUCCESS)
5981 /* Refresh the current folder if we're viewing a window. We do
5982 this because the user won't be able to see the new mails in
5983 the selected folder after a Send&Receive because it only
5984 performs a poke_status, i.e, only the number of read/unread
5985 messages is updated, but the new headers are not
5987 folder_view = modest_main_window_get_child_widget (main_win,
5988 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
5992 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
5994 /* Do not need to refresh INBOX again because the
5995 update_account does it always automatically */
5996 if (folder_store && TNY_IS_FOLDER (folder_store) &&
5997 tny_folder_get_folder_type (TNY_FOLDER (folder_store)) != TNY_FOLDER_TYPE_INBOX) {
5998 ModestMailOperation *refresh_op;
6000 header_view = modest_main_window_get_child_widget (main_win,
6001 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
6003 /* We do not need to set the contents style
6004 because it hasn't changed. We also do not
6005 need to save the widget status. Just force
6007 refresh_op = modest_mail_operation_new (G_OBJECT (main_win));
6008 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), refresh_op);
6009 modest_mail_operation_refresh_folder (refresh_op, TNY_FOLDER (folder_store),
6010 folder_refreshed_cb, main_win);
6011 g_object_unref (refresh_op);
6015 g_object_unref (folder_store);
6020 modest_ui_actions_on_send_queue_error_happened (TnySendQueue *self,
6026 const gchar* server_name = NULL;
6027 TnyTransportAccount *server_account;
6028 gchar *message = NULL;
6030 /* Don't show anything if the user cancelled something or the
6031 * send receive request is not interactive. Authentication
6032 * errors are managed by the account store so no need to show
6033 * a dialog here again */
6034 if (err->code == TNY_SYSTEM_ERROR_CANCEL ||
6035 err->code == TNY_SERVICE_ERROR_AUTHENTICATE ||
6036 !modest_tny_send_queue_get_requested_send_receive (MODEST_TNY_SEND_QUEUE (self)))
6040 /* Get the server name: */
6042 TNY_TRANSPORT_ACCOUNT (tny_camel_send_queue_get_transport_account (TNY_CAMEL_SEND_QUEUE (self)));
6044 server_name = tny_account_get_hostname (TNY_ACCOUNT (server_account));
6046 g_return_if_reached ();
6048 /* Show the appropriate message text for the GError: */
6049 switch (err->code) {
6050 case TNY_SERVICE_ERROR_CONNECT:
6051 message = g_strdup_printf (_("emev_ib_ui_smtp_server_invalid"), server_name);
6053 case TNY_SERVICE_ERROR_SEND:
6054 message = g_strdup (dgettext("hildon-common-strings", "sfil_ib_unable_to_send"));
6056 case TNY_SERVICE_ERROR_UNAVAILABLE:
6057 message = g_strdup_printf (_("emev_ib_ui_smtp_server_invalid"), server_name);
6060 g_warning ("%s: unexpected ERROR %d",
6061 __FUNCTION__, err->code);
6062 message = g_strdup (dgettext("hildon-common-strings", "sfil_ib_unable_to_send"));
6066 modest_platform_run_information_dialog (NULL, message, FALSE);
6068 g_object_unref (server_account);
6072 modest_ui_actions_on_send_queue_status_changed (ModestTnySendQueue *send_queue,
6077 ModestMainWindow *main_window = NULL;
6078 ModestWindowMgr *mgr = NULL;
6079 GtkWidget *folder_view = NULL, *header_view = NULL;
6080 TnyFolderStore *selected_folder = NULL;
6081 TnyFolderType folder_type;
6083 mgr = modest_runtime_get_window_mgr ();
6084 main_window = MODEST_MAIN_WINDOW (modest_window_mgr_get_main_window (mgr,
6085 FALSE));/* don't create */
6089 /* Check if selected folder is OUTBOX */
6090 folder_view = modest_main_window_get_child_widget (main_window,
6091 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
6092 header_view = modest_main_window_get_child_widget (main_window,
6093 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
6095 selected_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
6096 if (!TNY_IS_FOLDER (selected_folder))
6099 /* gtk_tree_view_column_queue_resize is only available in GTK+ 2.8 */
6100 #if GTK_CHECK_VERSION(2, 8, 0)
6101 folder_type = modest_tny_folder_guess_folder_type (TNY_FOLDER (selected_folder));
6102 if (folder_type == TNY_FOLDER_TYPE_OUTBOX) {
6103 GtkTreeViewColumn *tree_column;
6105 tree_column = gtk_tree_view_get_column (GTK_TREE_VIEW (header_view),
6106 TNY_GTK_HEADER_LIST_MODEL_FROM_COLUMN);
6108 gtk_tree_view_column_queue_resize (tree_column);
6111 gtk_widget_queue_draw (header_view);
6114 /* Rerun dimming rules, because the message could become deletable for example */
6115 modest_window_check_dimming_rules_group (MODEST_WINDOW (main_window),
6116 MODEST_DIMMING_RULES_TOOLBAR);
6117 modest_window_check_dimming_rules_group (MODEST_WINDOW (main_window),
6118 MODEST_DIMMING_RULES_MENU);
6122 if (selected_folder != NULL)
6123 g_object_unref (selected_folder);
6127 modest_ui_actions_on_account_connection_error (GtkWindow *parent_window,
6128 TnyAccount *account)
6130 ModestProtocolType protocol_type;
6131 ModestProtocol *protocol;
6132 gchar *error_note = NULL;
6134 protocol_type = modest_tny_account_get_protocol_type (account);
6135 protocol = modest_protocol_registry_get_protocol_by_type (modest_runtime_get_protocol_registry (),
6138 error_note = modest_protocol_get_translation (protocol, MODEST_PROTOCOL_TRANSLATION_ACCOUNT_CONNECTION_ERROR, tny_account_get_hostname (account));
6139 if (error_note == NULL) {
6140 g_warning ("%s: This should not be reached", __FUNCTION__);
6142 modest_platform_run_information_dialog (parent_window, error_note, FALSE);
6143 g_free (error_note);
6148 modest_ui_actions_get_msg_already_deleted_error_msg (ModestWindow *win)
6152 TnyFolderStore *folder = NULL;
6153 TnyAccount *account = NULL;
6154 ModestProtocolType proto;
6155 ModestProtocol *protocol;
6156 TnyHeader *header = NULL;
6158 if (MODEST_IS_MAIN_WINDOW (win)) {
6159 GtkWidget *header_view;
6160 TnyList* headers = NULL;
6162 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
6163 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
6164 headers = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW (header_view));
6165 if (!headers || tny_list_get_length (headers) == 0) {
6167 g_object_unref (headers);
6170 iter = tny_list_create_iterator (headers);
6171 header = TNY_HEADER (tny_iterator_get_current (iter));
6172 folder = TNY_FOLDER_STORE (tny_header_get_folder (header));
6173 g_object_unref (iter);
6174 g_object_unref (headers);
6175 } else if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
6176 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
6177 folder = TNY_FOLDER_STORE (tny_header_get_folder (header));
6180 /* Get the account type */
6181 account = tny_folder_get_account (TNY_FOLDER (folder));
6182 proto = modest_tny_account_get_protocol_type (account);
6183 protocol = modest_protocol_registry_get_protocol_by_type (modest_runtime_get_protocol_registry (),
6186 subject = tny_header_dup_subject (header);
6187 msg = modest_protocol_get_translation (protocol, MODEST_PROTOCOL_TRANSLATION_MSG_NOT_AVAILABLE, subject);
6191 msg = g_strdup_printf (_("mail_ni_ui_folder_get_msg_folder_error"));
6195 g_object_unref (account);
6196 g_object_unref (folder);
6197 g_object_unref (header);