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-protocol-info.h"
45 #include "modest-tny-platform-factory.h"
46 #include "modest-platform.h"
47 #include "modest-debug.h"
48 #include <tny-mime-part.h>
49 #include <tny-camel-folder.h>
50 #include <tny-camel-imap-folder.h>
51 #include <tny-camel-pop-folder.h>
53 #ifdef MODEST_PLATFORM_MAEMO
54 #include "maemo/modest-osso-state-saving.h"
55 #include "maemo/modest-hildon-includes.h"
56 #include "maemo/modest-connection-specific-smtp-window.h"
57 #endif /* MODEST_PLATFORM_MAEMO */
58 #include <modest-utils.h>
60 #include "widgets/modest-ui-constants.h"
61 #include <widgets/modest-main-window.h>
62 #include <widgets/modest-msg-view-window.h>
63 #include <widgets/modest-account-view-window.h>
64 #include <widgets/modest-details-dialog.h>
65 #include <widgets/modest-attachments-view.h>
66 #include "widgets/modest-folder-view.h"
67 #include "widgets/modest-global-settings-dialog.h"
68 #include "modest-account-mgr-helpers.h"
69 #include "modest-mail-operation.h"
70 #include "modest-text-utils.h"
72 #ifdef MODEST_HAVE_EASYSETUP
73 #include "easysetup/modest-easysetup-wizard.h"
74 #endif /* MODEST_HAVE_EASYSETUP */
76 #include <modest-widget-memory.h>
77 #include <tny-error.h>
78 #include <tny-simple-list.h>
79 #include <tny-msg-view.h>
80 #include <tny-device.h>
81 #include <tny-merge-folder.h>
83 #include <gtkhtml/gtkhtml.h>
85 typedef struct _GetMsgAsyncHelper {
87 ModestMailOperation *mail_op;
94 typedef enum _ReplyForwardAction {
100 typedef struct _ReplyForwardHelper {
101 guint reply_forward_type;
102 ReplyForwardAction action;
104 GtkWidget *parent_window;
105 } ReplyForwardHelper;
107 typedef struct _MoveToHelper {
108 GtkTreeRowReference *reference;
112 typedef struct _PasteAsAttachmentHelper {
113 ModestMsgEditWindow *window;
115 } PasteAsAttachmentHelper;
119 * The do_headers_action uses this kind of functions to perform some
120 * action to each member of a list of headers
122 typedef void (*HeadersFunc) (TnyHeader *header, ModestWindow *win, gpointer user_data);
124 static void do_headers_action (ModestWindow *win,
128 static void open_msg_cb (ModestMailOperation *mail_op,
135 static void reply_forward_cb (ModestMailOperation *mail_op,
142 static void reply_forward (ReplyForwardAction action, ModestWindow *win);
144 static void folder_refreshed_cb (ModestMailOperation *mail_op,
148 static void on_send_receive_finished (ModestMailOperation *mail_op,
151 static gint header_list_count_uncached_msgs (TnyList *header_list);
153 static gboolean connect_to_get_msg (ModestWindow *win,
154 gint num_of_uncached_msgs,
155 TnyAccount *account);
157 static gboolean remote_folder_is_pop (const TnyFolderStore *folder);
159 static gboolean msgs_already_deleted_from_server ( TnyList *headers,
160 const TnyFolderStore *src_folder);
162 static void do_create_folder (GtkWindow *window,
163 TnyFolderStore *parent_folder,
164 const gchar *suggested_name);
166 static GtkWidget* get_folder_view_from_move_to_dialog (GtkWidget *move_to_dialog);
170 * This function checks whether a TnyFolderStore is a pop account
173 remote_folder_is_pop (const TnyFolderStore *folder)
175 const gchar *proto = NULL;
176 TnyAccount *account = NULL;
178 g_return_val_if_fail (TNY_IS_FOLDER_STORE(folder), FALSE);
180 if (TNY_IS_ACCOUNT (folder)) {
181 account = TNY_ACCOUNT(folder);
182 g_object_ref(account);
183 } else if (TNY_IS_FOLDER (folder)) {
184 account = tny_folder_get_account(TNY_FOLDER(folder));
187 if (!account && !TNY_IS_ACCOUNT(account)) {
188 g_warning ("%s: could not get account", __FUNCTION__);
192 proto = tny_account_get_proto(account);
193 g_object_unref (account);
196 (modest_protocol_info_get_transport_store_protocol (proto) == MODEST_PROTOCOL_STORE_POP);
200 * This functions checks whether if a list of messages are already
201 * deleted from the server: that is, if the server is a POP account
202 * and all messages are already cached.
205 msgs_already_deleted_from_server (TnyList *headers, const TnyFolderStore *src_folder)
207 g_return_val_if_fail (TNY_IS_FOLDER_STORE(src_folder), FALSE);
208 g_return_val_if_fail (TNY_IS_LIST(headers), FALSE);
210 gboolean src_is_pop = remote_folder_is_pop (src_folder);
211 gint uncached_msgs = header_list_count_uncached_msgs (headers);
213 return (src_is_pop && !uncached_msgs);
217 /* FIXME: this should be merged with the similar code in modest-account-view-window */
218 /* Show the account creation wizard dialog.
219 * returns: TRUE if an account was created. FALSE if the user cancelled.
222 modest_ui_actions_run_account_setup_wizard (ModestWindow *win)
224 gboolean result = FALSE;
225 GtkWindow *dialog, *wizard;
226 gint dialog_response;
228 /* Show the easy-setup wizard: */
229 dialog = modest_window_mgr_get_modal (modest_runtime_get_window_mgr());
231 /* old wizard is active already;
233 gtk_window_present (GTK_WINDOW(dialog));
238 /* there is no such wizard yet */
239 wizard = GTK_WINDOW (modest_platform_get_account_settings_wizard ());
240 modest_window_mgr_set_modal (modest_runtime_get_window_mgr(), wizard);
242 /* always present a main window in the background
243 * we do it here, so we cannot end up with two wizards (as this
244 * function might be called in modest_window_mgr_get_main_window as well */
246 win = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr(),
247 TRUE); /* create if not existent */
249 /* make sure the mainwindow is visible */
250 gtk_window_set_transient_for (GTK_WINDOW (wizard), GTK_WINDOW (win));
251 gtk_widget_show_all (GTK_WIDGET(win));
252 gtk_window_present (GTK_WINDOW(win));
254 dialog_response = gtk_dialog_run (GTK_DIALOG (wizard));
255 gtk_widget_destroy (GTK_WIDGET (wizard));
256 if (gtk_events_pending ())
257 gtk_main_iteration ();
259 if (dialog_response == GTK_RESPONSE_CANCEL) {
262 /* Check whether an account was created: */
263 result = modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
270 modest_ui_actions_on_about (GtkAction *action, ModestWindow *win)
273 const gchar *authors[] = {
274 "Dirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>",
277 about = gtk_about_dialog_new ();
278 gtk_about_dialog_set_name (GTK_ABOUT_DIALOG(about), PACKAGE_NAME);
279 gtk_about_dialog_set_version (GTK_ABOUT_DIALOG(about),PACKAGE_VERSION);
280 gtk_about_dialog_set_copyright (GTK_ABOUT_DIALOG(about),
281 _("Copyright (c) 2006, Nokia Corporation\n"
282 "All rights reserved."));
283 gtk_about_dialog_set_comments (GTK_ABOUT_DIALOG(about),
284 _("a modest e-mail client\n\n"
285 "design and implementation: Dirk-Jan C. Binnema\n"
286 "contributions from the fine people at KC and Ig\n"
287 "uses the tinymail email framework written by Philip van Hoof"));
288 gtk_about_dialog_set_authors (GTK_ABOUT_DIALOG(about), authors);
289 gtk_about_dialog_set_website (GTK_ABOUT_DIALOG(about), "http://modest.garage.maemo.org");
290 gtk_window_set_transient_for (GTK_WINDOW (about), GTK_WINDOW (win));
291 gtk_window_set_modal (GTK_WINDOW (about), TRUE);
293 gtk_dialog_run (GTK_DIALOG (about));
294 gtk_widget_destroy(about);
298 * Gets the list of currently selected messages. If the win is the
299 * main window, then it returns a newly allocated list of the headers
300 * selected in the header view. If win is the msg view window, then
301 * the value returned is a list with just a single header.
303 * The caller of this funcion must free the list.
306 get_selected_headers (ModestWindow *win)
308 if (MODEST_IS_MAIN_WINDOW(win)) {
309 GtkWidget *header_view;
311 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
312 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
313 return modest_header_view_get_selected_headers (MODEST_HEADER_VIEW(header_view));
315 } else if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
316 /* for MsgViewWindows, we simply return a list with one element */
318 TnyList *list = NULL;
320 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
321 if (header != NULL) {
322 list = tny_simple_list_new ();
323 tny_list_prepend (list, G_OBJECT(header));
324 g_object_unref (G_OBJECT(header));
333 static GtkTreeRowReference *
334 get_next_after_selected_headers (ModestHeaderView *header_view)
336 GtkTreeSelection *sel;
337 GList *selected_rows, *node;
339 GtkTreeRowReference *result;
342 model = gtk_tree_view_get_model (GTK_TREE_VIEW (header_view));
343 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
344 selected_rows = gtk_tree_selection_get_selected_rows (sel, NULL);
346 if (selected_rows == NULL)
349 node = g_list_last (selected_rows);
350 path = gtk_tree_path_copy ((GtkTreePath *) node->data);
351 gtk_tree_path_next (path);
353 result = gtk_tree_row_reference_new (model, path);
355 gtk_tree_path_free (path);
356 g_list_foreach (selected_rows, (GFunc) gtk_tree_path_free, NULL);
357 g_list_free (selected_rows);
363 headers_action_mark_as_read (TnyHeader *header,
367 TnyHeaderFlags flags;
369 g_return_if_fail (TNY_IS_HEADER(header));
371 flags = tny_header_get_flags (header);
372 if (flags & TNY_HEADER_FLAG_SEEN) return;
373 tny_header_set_flag (header, TNY_HEADER_FLAG_SEEN);
377 headers_action_mark_as_unread (TnyHeader *header,
381 TnyHeaderFlags flags;
383 g_return_if_fail (TNY_IS_HEADER(header));
385 flags = tny_header_get_flags (header);
386 if (flags & TNY_HEADER_FLAG_SEEN) {
387 tny_header_unset_flag (header, TNY_HEADER_FLAG_SEEN);
391 /** After deleing a message that is currently visible in a window,
392 * show the next message from the list, or close the window if there are no more messages.
395 modest_ui_actions_refresh_message_window_after_delete (ModestMsgViewWindow* win)
397 /* Close msg view window or select next */
398 if (modest_msg_view_window_last_message_selected (win) &&
399 modest_msg_view_window_first_message_selected (win)) {
400 modest_ui_actions_on_close_window (NULL, MODEST_WINDOW (win));
401 } else if (!modest_msg_view_window_select_next_message (win) &&
402 !modest_msg_view_window_select_previous_message (win)) {
404 g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value);
410 modest_ui_actions_on_delete_message (GtkAction *action, ModestWindow *win)
412 TnyList *header_list = NULL;
413 TnyIterator *iter = NULL;
414 TnyHeader *header = NULL;
415 gchar *message = NULL;
418 ModestWindowMgr *mgr;
419 GtkWidget *header_view = NULL;
421 g_return_if_fail (MODEST_IS_WINDOW(win));
423 /* Check first if the header view has the focus */
424 if (MODEST_IS_MAIN_WINDOW (win)) {
426 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
427 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
428 if (!gtk_widget_is_focus (header_view))
432 /* Get the headers, either from the header view (if win is the main window),
433 * or from the message view window: */
434 header_list = get_selected_headers (win);
435 if (!header_list) return;
437 /* Check if any of the headers are already opened, or in the process of being opened */
438 if (MODEST_IS_MAIN_WINDOW (win)) {
439 gint opened_headers = 0;
441 iter = tny_list_create_iterator (header_list);
442 mgr = modest_runtime_get_window_mgr ();
443 while (!tny_iterator_is_done (iter)) {
444 header = TNY_HEADER (tny_iterator_get_current (iter));
446 if (modest_window_mgr_find_registered_header (mgr, header, NULL))
448 g_object_unref (header);
450 tny_iterator_next (iter);
452 g_object_unref (iter);
454 if (opened_headers > 0) {
457 msg = g_strdup_printf (_("mcen_nc_unable_to_delete_n_messages"),
460 modest_platform_run_information_dialog (GTK_WINDOW (win), (const gchar *) msg);
463 g_object_unref (header_list);
469 if (tny_list_get_length(header_list) == 1) {
470 iter = tny_list_create_iterator (header_list);
471 header = TNY_HEADER (tny_iterator_get_current (iter));
473 desc = g_strdup_printf ("%s", tny_header_get_subject (header));
474 g_object_unref (header);
477 g_object_unref (iter);
479 message = g_strdup_printf(ngettext("emev_nc_delete_message", "emev_nc_delete_messages",
480 tny_list_get_length(header_list)), desc);
482 /* Confirmation dialog */
483 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
487 if (response == GTK_RESPONSE_OK) {
488 ModestWindow *main_window = NULL;
489 ModestWindowMgr *mgr = NULL;
490 GtkTreeModel *model = NULL;
491 GtkTreeSelection *sel = NULL;
492 GList *sel_list = NULL, *tmp = NULL;
493 GtkTreeRowReference *next_row_reference = NULL;
494 GtkTreeRowReference *prev_row_reference = NULL;
495 GtkTreePath *next_path = NULL;
496 GtkTreePath *prev_path = NULL;
497 ModestMailOperation *mail_op = NULL;
499 /* Find last selected row */
500 if (MODEST_IS_MAIN_WINDOW (win)) {
501 model = gtk_tree_view_get_model (GTK_TREE_VIEW (header_view));
502 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
503 sel_list = gtk_tree_selection_get_selected_rows (sel, &model);
504 for (tmp=sel_list; tmp; tmp=tmp->next) {
505 if (tmp->next == NULL) {
506 prev_path = gtk_tree_path_copy((GtkTreePath *) tmp->data);
507 next_path = gtk_tree_path_copy((GtkTreePath *) tmp->data);
509 gtk_tree_path_prev (prev_path);
510 gtk_tree_path_next (next_path);
512 prev_row_reference = gtk_tree_row_reference_new (model, prev_path);
513 next_row_reference = gtk_tree_row_reference_new (model, next_path);
518 /* Disable window dimming management */
519 modest_window_disable_dimming (MODEST_WINDOW(win));
521 /* Remove each header. If it's a view window header_view == NULL */
522 mail_op = modest_mail_operation_new ((GObject *) win);
523 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
525 modest_mail_operation_remove_msgs (mail_op, header_list, FALSE);
526 g_object_unref (mail_op);
528 /* Enable window dimming management */
530 gtk_tree_selection_unselect_all (sel);
532 modest_window_enable_dimming (MODEST_WINDOW(win));
534 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
535 modest_ui_actions_refresh_message_window_after_delete (MODEST_MSG_VIEW_WINDOW (win));
537 /* Get main window */
538 mgr = modest_runtime_get_window_mgr ();
539 main_window = modest_window_mgr_get_main_window (mgr, FALSE); /* don't create */
541 /* Move cursor to next row */
544 /* Select next or previous row */
545 if (gtk_tree_row_reference_valid (next_row_reference)) {
546 /* next_path = gtk_tree_row_reference_get_path (row_reference); */
547 gtk_tree_selection_select_path (sel, next_path);
549 else if (gtk_tree_row_reference_valid (prev_row_reference)) {
550 gtk_tree_selection_select_path (sel, prev_path);
554 if (next_row_reference != NULL)
555 gtk_tree_row_reference_free (next_row_reference);
556 if (next_path != NULL)
557 gtk_tree_path_free (next_path);
558 if (prev_row_reference != NULL)
559 gtk_tree_row_reference_free (prev_row_reference);
560 if (prev_path != NULL)
561 gtk_tree_path_free (prev_path);
564 /* Update toolbar dimming state */
566 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
569 g_list_foreach (sel_list, (GFunc) gtk_tree_path_free, NULL);
570 g_list_free (sel_list);
576 g_object_unref (header_list);
582 /* delete either message or folder, based on where we are */
584 modest_ui_actions_on_delete_message_or_folder (GtkAction *action, ModestWindow *win)
586 g_return_if_fail (MODEST_IS_WINDOW(win));
588 /* Check first if the header view has the focus */
589 if (MODEST_IS_MAIN_WINDOW (win)) {
591 w = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
592 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
593 if (gtk_widget_is_focus (w)) {
594 modest_ui_actions_on_delete_folder (action, MODEST_MAIN_WINDOW(win));
598 modest_ui_actions_on_delete_message (action, win);
604 modest_ui_actions_on_quit (GtkAction *action, ModestWindow *win)
606 ModestWindowMgr *mgr = NULL;
608 #ifdef MODEST_PLATFORM_MAEMO
609 modest_osso_save_state();
610 #endif /* MODEST_PLATFORM_MAEMO */
612 g_debug ("closing down, clearing %d item(s) from operation queue",
613 modest_mail_operation_queue_num_elements
614 (modest_runtime_get_mail_operation_queue()));
616 /* cancel all outstanding operations */
617 modest_mail_operation_queue_cancel_all
618 (modest_runtime_get_mail_operation_queue());
620 g_debug ("queue has been cleared");
623 /* Check if there are opened editing windows */
624 mgr = modest_runtime_get_window_mgr ();
625 modest_window_mgr_close_all_windows (mgr);
627 /* note: when modest-tny-account-store is finalized,
628 it will automatically set all network connections
631 /* gtk_main_quit (); */
635 modest_ui_actions_on_close_window (GtkAction *action, ModestWindow *win)
639 g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value);
641 /* if (MODEST_IS_MSG_VIEW_WINDOW (win)) { */
642 /* gtk_widget_destroy (GTK_WIDGET (win)); */
643 /* } else if (MODEST_IS_MSG_EDIT_WINDOW (win)) { */
644 /* gboolean ret_value; */
645 /* g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value); */
646 /* } else if (MODEST_IS_WINDOW (win)) { */
647 /* gtk_widget_destroy (GTK_WIDGET (win)); */
649 /* g_return_if_reached (); */
654 modest_ui_actions_on_add_to_contacts (GtkAction *action, ModestWindow *win)
656 GtkClipboard *clipboard = NULL;
657 gchar *selection = NULL;
659 clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
660 selection = gtk_clipboard_wait_for_text (clipboard);
662 /* Question: why is the clipboard being used here?
663 * It doesn't really make a lot of sense. */
667 modest_address_book_add_address (selection);
673 modest_ui_actions_on_accounts (GtkAction *action,
676 /* This is currently only implemented for Maemo */
677 if (!modest_account_mgr_has_accounts (modest_runtime_get_account_mgr(), TRUE)) {
678 if (!modest_ui_actions_run_account_setup_wizard (win))
679 g_debug ("%s: wizard was already running", __FUNCTION__);
683 /* Show the list of accounts */
684 GtkWindow *account_win = GTK_WINDOW (modest_account_view_window_new ());
685 gtk_window_set_transient_for (account_win, GTK_WINDOW (win));
687 /* The accounts dialog must be modal */
688 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), account_win);
689 modest_utils_show_dialog_and_forget (GTK_WINDOW (win), GTK_DIALOG (account_win));
693 #ifdef MODEST_PLATFORM_MAEMO
695 on_smtp_servers_window_hide (GtkWindow* window, gpointer user_data)
697 /* Save any changes. */
698 modest_connection_specific_smtp_window_save_server_accounts (
699 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (window));
700 gtk_widget_destroy (GTK_WIDGET (window));
706 modest_ui_actions_on_smtp_servers (GtkAction *action, ModestWindow *win)
708 /* This is currently only implemented for Maemo,
709 * because it requires an API (libconic) to detect different connection
712 #ifdef MODEST_PLATFORM_MAEMO /* Defined in config.h */
714 /* Create the window if necessary: */
715 GtkWidget *specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
716 modest_connection_specific_smtp_window_fill_with_connections (
717 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (specific_window),
718 modest_runtime_get_account_mgr());
720 /* Show the window: */
721 gtk_window_set_transient_for (GTK_WINDOW (specific_window), GTK_WINDOW (win));
722 gtk_window_set_modal (GTK_WINDOW (specific_window), TRUE);
723 gtk_widget_show (specific_window);
725 /* Save changes when the window is hidden: */
726 g_signal_connect (specific_window, "hide",
727 G_CALLBACK (on_smtp_servers_window_hide), win);
728 #endif /* MODEST_PLATFORM_MAEMO */
732 modest_ui_actions_compose_msg(ModestWindow *win,
735 const gchar *bcc_str,
736 const gchar *subject_str,
737 const gchar *body_str,
740 gchar *account_name = NULL;
742 TnyAccount *account = NULL;
743 TnyFolder *folder = NULL;
744 gchar *from_str = NULL, *signature = NULL, *body = NULL;
745 gboolean use_signature = FALSE;
746 ModestWindow *msg_win = NULL;
747 ModestAccountMgr *mgr = modest_runtime_get_account_mgr();
748 ModestTnyAccountStore *store = modest_runtime_get_account_store();
750 account_name = modest_account_mgr_get_default_account(mgr);
752 g_printerr ("modest: no account found\n");
755 account = modest_tny_account_store_get_server_account (store, account_name, TNY_ACCOUNT_TYPE_STORE);
757 g_printerr ("modest: failed to get tnyaccount for '%s'\n", account_name);
760 folder = modest_tny_account_get_special_folder (account, TNY_FOLDER_TYPE_DRAFTS);
762 g_printerr ("modest: failed to find Drafts folder\n");
765 from_str = modest_account_mgr_get_from_string (mgr, account_name);
767 g_printerr ("modest: failed get from string for '%s'\n", account_name);
771 signature = modest_account_mgr_get_signature (mgr, account_name, &use_signature);
772 if (body_str != NULL) {
773 body = use_signature ? g_strconcat(body_str, "\n", signature, NULL) : g_strdup(body_str);
775 body = use_signature ? g_strconcat("\n", signature, NULL) : g_strdup("");
778 msg = modest_tny_msg_new (to_str, from_str, cc_str, bcc_str, subject_str, body, NULL);
780 g_printerr ("modest: failed to create new msg\n");
784 /* Create and register edit window */
785 /* This is destroyed by TODO. */
786 msg_win = modest_msg_edit_window_new (msg, account_name, FALSE);
787 while (attachments) {
788 modest_msg_edit_window_attach_file_one((ModestMsgEditWindow *)msg_win,
790 attachments = g_slist_next(attachments);
792 modest_window_mgr_register_window (modest_runtime_get_window_mgr(), msg_win);
793 gtk_widget_show_all (GTK_WIDGET (msg_win));
799 g_free (account_name);
800 if (account) g_object_unref (G_OBJECT(account));
801 if (folder) g_object_unref (G_OBJECT(folder));
802 if (msg_win) g_object_unref (G_OBJECT(msg_win));
803 if (msg) g_object_unref (G_OBJECT(msg));
807 modest_ui_actions_on_new_msg (GtkAction *action, ModestWindow *win)
809 /* if there are no accounts yet, just show the wizard */
810 if (!modest_account_mgr_has_accounts (modest_runtime_get_account_mgr(), TRUE))
811 if (!modest_ui_actions_run_account_setup_wizard (win))
814 modest_ui_actions_compose_msg(win, NULL, NULL, NULL, NULL, NULL, NULL);
818 modest_ui_actions_on_new_msg_or_folder (GtkAction *action, ModestWindow *win)
820 g_return_if_fail (MODEST_IS_WINDOW (win));
822 /* Check first if the folder view has the focus */
823 if (MODEST_IS_MAIN_WINDOW (win)) {
825 w = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
826 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
827 if (gtk_widget_is_focus (w)) {
828 modest_ui_actions_on_new_folder (action, MODEST_MAIN_WINDOW(win));
833 modest_ui_actions_on_new_msg (action, win);
838 modest_ui_actions_msg_retrieval_check (ModestMailOperation *mail_op,
842 ModestMailOperationStatus status;
844 /* If there is no message or the operation was not successful */
845 status = modest_mail_operation_get_status (mail_op);
846 if (!msg || status != MODEST_MAIL_OPERATION_STATUS_SUCCESS) {
848 /* Remove the header from the preregistered uids */
849 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (),
859 open_msg_cb (ModestMailOperation *mail_op,
866 ModestWindowMgr *mgr = NULL;
867 ModestWindow *parent_win = NULL;
868 ModestWindow *win = NULL;
869 TnyFolderType folder_type = TNY_FOLDER_TYPE_UNKNOWN;
870 gchar *account = NULL;
872 gboolean open_in_editor = FALSE;
874 /* Do nothing if there was any problem with the mail
875 operation. The error will be shown by the error_handler of
876 the mail operation */
877 if (!modest_ui_actions_msg_retrieval_check (mail_op, header, msg))
880 parent_win = (ModestWindow *) modest_mail_operation_get_source (mail_op);
881 folder = tny_header_get_folder (header);
883 /* Mark header as read */
884 headers_action_mark_as_read (header, MODEST_WINDOW(parent_win), NULL);
886 /* Gets folder type (OUTBOX headers will be opened in edit window */
887 if (modest_tny_folder_is_local_folder (folder)) {
888 folder_type = modest_tny_folder_get_local_or_mmc_folder_type (folder);
889 if (folder_type == TNY_FOLDER_TYPE_INVALID)
890 g_warning ("%s: BUG: TNY_FOLDER_TYPE_INVALID", __FUNCTION__);
894 if (folder_type == TNY_FOLDER_TYPE_OUTBOX) {
895 TnyTransportAccount *traccount = NULL;
896 ModestTnyAccountStore *accstore = modest_runtime_get_account_store();
897 traccount = modest_tny_account_store_get_transport_account_from_outbox_header(accstore, header);
899 ModestTnySendQueue *send_queue = NULL;
900 ModestTnySendQueueStatus status;
902 account = g_strdup(modest_tny_account_get_parent_modest_account_name_for_server_account(
903 TNY_ACCOUNT(traccount)));
904 send_queue = modest_runtime_get_send_queue(traccount);
905 msg_id = modest_tny_send_queue_get_msg_id (header);
906 status = modest_tny_send_queue_get_msg_status(send_queue, msg_id);
907 /* Only open messages in outbox with the editor if they are in Failed state */
908 if (status == MODEST_TNY_SEND_QUEUE_FAILED) {
909 open_in_editor = TRUE;
912 g_object_unref(traccount);
914 g_warning("Cannot get transport account for message in outbox!!");
916 } else if (folder_type == TNY_FOLDER_TYPE_DRAFTS) {
917 open_in_editor = TRUE; /* Open in editor if the message is in the Drafts folder */
922 account = g_strdup (modest_window_get_active_account (MODEST_WINDOW (parent_win)));
924 account = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
926 if (open_in_editor) {
927 ModestAccountMgr *mgr = modest_runtime_get_account_mgr ();
928 const gchar *from_header = NULL;
930 from_header = tny_header_get_from (header);
932 /* we cannot edit without a valid account... */
933 if (!modest_account_mgr_has_accounts(mgr, TRUE)) {
934 if (!modest_ui_actions_run_account_setup_wizard(parent_win))
939 GSList *accounts = modest_account_mgr_account_names (mgr, TRUE);
941 for (node = accounts; node != NULL; node = g_slist_next (node)) {
942 gchar *from = modest_account_mgr_get_from_string (mgr, node->data);
944 if (from && (strcmp (from_header, from) == 0)) {
946 account = g_strdup (node->data);
952 g_slist_foreach (accounts, (GFunc) g_free, NULL);
953 g_slist_free (accounts);
956 win = modest_msg_edit_window_new (msg, account, TRUE);
960 modest_platform_information_banner_with_timeout
961 (NULL, NULL, _("mail_ib_opening_draft_message"), 1200);
964 gchar *uid = modest_tny_folder_get_header_unique_id (header);
966 if (MODEST_IS_MAIN_WINDOW (parent_win)) {
967 GtkWidget *header_view;
968 GtkTreeSelection *sel;
969 GList *sel_list = NULL;
972 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(parent_win),
973 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
975 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
976 sel_list = gtk_tree_selection_get_selected_rows (sel, &model);
978 if (sel_list != NULL) {
979 GtkTreeRowReference *row_reference;
981 row_reference = gtk_tree_row_reference_new (model, (GtkTreePath *) sel_list->data);
982 g_list_foreach (sel_list, (GFunc) gtk_tree_path_free, NULL);
983 g_list_free (sel_list);
985 win = modest_msg_view_window_new_with_header_model (
986 msg, account, (const gchar*) uid,
987 model, row_reference);
988 gtk_tree_row_reference_free (row_reference);
990 win = modest_msg_view_window_new_for_attachment (msg, account, (const gchar*) uid);
993 win = modest_msg_view_window_new_for_attachment (msg, account, (const gchar*) uid);
998 /* Register and show new window */
1000 mgr = modest_runtime_get_window_mgr ();
1001 modest_window_mgr_register_window (mgr, win);
1002 g_object_unref (win);
1003 gtk_widget_show_all (GTK_WIDGET(win));
1006 /* Update toolbar dimming state */
1007 if (MODEST_IS_MAIN_WINDOW (parent_win)) {
1008 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (parent_win));
1014 g_object_unref (parent_win);
1015 g_object_unref (folder);
1019 modest_ui_actions_get_msgs_full_error_handler (ModestMailOperation *mail_op,
1022 const GError *error;
1023 GObject *win = NULL;
1024 const gchar *err_msg = (const gchar *) user_data;
1026 win = modest_mail_operation_get_source (mail_op);
1027 error = modest_mail_operation_get_error (mail_op);
1030 modest_platform_run_information_dialog ((GtkWindow *) win, err_msg);
1033 g_object_unref (win);
1037 * Returns the account a list of headers belongs to. It returns a
1038 * *new* reference so don't forget to unref it
1041 get_account_from_header_list (TnyList *headers)
1043 TnyAccount *account = NULL;
1045 if (tny_list_get_length (headers) > 0) {
1046 TnyIterator *iter = tny_list_create_iterator (headers);
1047 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter));
1048 TnyFolder *folder = tny_header_get_folder (header);
1049 account = tny_folder_get_account (folder);
1050 g_object_unref (folder);
1051 g_object_unref (header);
1052 g_object_unref (iter);
1058 foreach_unregister_headers (gpointer data,
1061 ModestWindowMgr *mgr = (ModestWindowMgr *) user_data;
1062 TnyHeader *header = TNY_HEADER (data);
1064 modest_window_mgr_unregister_header (mgr, header);
1068 open_msgs_performer(gboolean canceled,
1070 GtkWindow *parent_window,
1071 TnyAccount *account,
1074 ModestMailOperation *mail_op = NULL;
1075 const gchar *proto_name;
1077 ModestTransportStoreProtocol proto;
1078 TnyList *not_opened_headers;
1079 TnyConnectionStatus status;
1081 not_opened_headers = TNY_LIST (user_data);
1083 status = tny_account_get_connection_status (account);
1084 if (err || canceled) {
1085 /* Unregister the already registered headers */
1086 tny_list_foreach (not_opened_headers, foreach_unregister_headers,
1087 modest_runtime_get_window_mgr ());
1091 /* Get the error message depending on the protocol */
1092 proto_name = tny_account_get_proto (account);
1093 if (proto_name != NULL) {
1094 proto = modest_protocol_info_get_transport_store_protocol (proto_name);
1096 proto = MODEST_PROTOCOL_STORE_MAILDIR;
1099 /* Create the error messages */
1100 if (tny_list_get_length (not_opened_headers) == 1) {
1101 if (proto == MODEST_PROTOCOL_STORE_POP) {
1102 error_msg = g_strdup (_("emev_ni_ui_pop3_msg_recv_error"));
1103 } else if (proto == MODEST_PROTOCOL_STORE_IMAP) {
1104 TnyIterator *iter = tny_list_create_iterator (not_opened_headers);
1105 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter));
1106 error_msg = g_strdup_printf (_("emev_ni_ui_imap_message_not_available_in_server"),
1107 tny_header_get_subject (header));
1108 g_object_unref (header);
1109 g_object_unref (iter);
1111 error_msg = g_strdup (_("mail_ni_ui_folder_get_msg_folder_error"));
1114 error_msg = g_strdup (_("mail_ni_ui_folder_get_msg_folder_error"));
1117 /* Create the mail operation */
1119 modest_mail_operation_new_with_error_handling ((GObject *) parent_window,
1120 modest_ui_actions_get_msgs_full_error_handler,
1122 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
1125 modest_mail_operation_get_msgs_full (mail_op,
1134 g_object_unref (mail_op);
1135 g_object_unref (not_opened_headers);
1136 g_object_unref (account);
1140 * This function is used by both modest_ui_actions_on_open and
1141 * modest_ui_actions_on_header_activated. This way we always do the
1142 * same when trying to open messages.
1145 open_msgs_from_headers (TnyList *headers, ModestWindow *win)
1147 ModestWindowMgr *mgr = NULL;
1148 TnyIterator *iter = NULL, *iter_not_opened = NULL;
1149 TnyList *not_opened_headers = NULL;
1150 TnyHeaderFlags flags = 0;
1151 TnyAccount *account;
1152 gint uncached_msgs = 0;
1154 g_return_if_fail (headers != NULL);
1156 /* Check that only one message is selected for opening */
1157 if (tny_list_get_length (headers) != 1) {
1158 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
1159 _("mcen_ib_select_one_message"));
1163 mgr = modest_runtime_get_window_mgr ();
1164 iter = tny_list_create_iterator (headers);
1166 /* Get the account */
1167 account = get_account_from_header_list (headers);
1169 /* Look if we already have a message view for each header. If
1170 true, then remove the header from the list of headers to
1172 not_opened_headers = tny_simple_list_new ();
1173 while (!tny_iterator_is_done (iter)) {
1175 ModestWindow *window = NULL;
1176 TnyHeader *header = NULL;
1177 gboolean found = FALSE;
1179 header = TNY_HEADER (tny_iterator_get_current (iter));
1181 flags = tny_header_get_flags (header);
1184 found = modest_window_mgr_find_registered_header (mgr, header, &window);
1186 /* Do not open again the message and present the
1187 window to the user */
1190 gtk_window_present (GTK_WINDOW (window));
1192 /* the header has been registered already, we don't do
1193 * anything but wait for the window to come up*/
1194 g_debug ("header %p already registered, waiting for window", header);
1196 tny_list_append (not_opened_headers, G_OBJECT (header));
1200 g_object_unref (header);
1202 tny_iterator_next (iter);
1204 g_object_unref (iter);
1207 /* Open each message */
1208 if (tny_list_get_length (not_opened_headers) == 0)
1211 /* If some messages would have to be downloaded, ask the user to
1212 * make a connection. It's generally easier to do this here (in the mainloop)
1213 * than later in a thread:
1215 if (tny_list_get_length (not_opened_headers) > 0) {
1216 uncached_msgs = header_list_count_uncached_msgs (not_opened_headers);
1218 if (uncached_msgs > 0) {
1219 /* Allways download if we are online. */
1220 if (!tny_device_is_online (modest_runtime_get_device ())) {
1223 /* If ask for user permission to download the messages */
1224 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
1225 ngettext("mcen_nc_get_msg",
1229 /* End if the user does not want to continue */
1230 if (response == GTK_RESPONSE_CANCEL)
1236 /* Register the headers before actually creating the windows: */
1237 iter_not_opened = tny_list_create_iterator (not_opened_headers);
1238 while (!tny_iterator_is_done (iter_not_opened)) {
1239 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter_not_opened));
1241 modest_window_mgr_register_header (mgr, header, NULL);
1242 g_object_unref (header);
1244 tny_iterator_next (iter_not_opened);
1246 g_object_unref (iter_not_opened);
1247 iter_not_opened = NULL;
1249 /* Connect to the account and perform */
1250 if (uncached_msgs > 0) {
1251 modest_platform_connect_and_perform ((GtkWindow *) win, TRUE, g_object_ref (account),
1252 open_msgs_performer, g_object_ref (not_opened_headers));
1254 /* Call directly the performer, do not need to connect */
1255 open_msgs_performer (FALSE, NULL, (GtkWindow *) win, g_object_ref (account),
1256 g_object_ref (not_opened_headers));
1261 g_object_unref (account);
1262 if (not_opened_headers)
1263 g_object_unref (not_opened_headers);
1267 modest_ui_actions_on_open (GtkAction *action, ModestWindow *win)
1272 headers = get_selected_headers (win);
1277 open_msgs_from_headers (headers, win);
1279 g_object_unref(headers);
1284 free_reply_forward_helper (gpointer data)
1286 ReplyForwardHelper *helper;
1288 helper = (ReplyForwardHelper *) data;
1289 g_free (helper->account_name);
1290 g_slice_free (ReplyForwardHelper, helper);
1294 reply_forward_cb (ModestMailOperation *mail_op,
1302 ReplyForwardHelper *rf_helper;
1303 ModestWindow *msg_win = NULL;
1304 ModestEditType edit_type;
1306 TnyAccount *account = NULL;
1307 ModestWindowMgr *mgr = NULL;
1308 gchar *signature = NULL;
1309 gboolean use_signature;
1311 /* If there was any error. The mail operation could be NULL,
1312 this means that we already have the message downloaded and
1313 that we didn't do a mail operation to retrieve it */
1314 if (mail_op && !modest_ui_actions_msg_retrieval_check (mail_op, header, msg))
1317 g_return_if_fail (user_data != NULL);
1318 rf_helper = (ReplyForwardHelper *) user_data;
1320 from = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(),
1321 rf_helper->account_name);
1322 signature = modest_account_mgr_get_signature (modest_runtime_get_account_mgr(),
1323 rf_helper->account_name,
1326 /* Create reply mail */
1327 switch (rf_helper->action) {
1330 modest_tny_msg_create_reply_msg (msg, header, from, signature,
1331 rf_helper->reply_forward_type,
1332 MODEST_TNY_MSG_REPLY_MODE_SENDER);
1334 case ACTION_REPLY_TO_ALL:
1336 modest_tny_msg_create_reply_msg (msg, header, from, signature, rf_helper->reply_forward_type,
1337 MODEST_TNY_MSG_REPLY_MODE_ALL);
1338 edit_type = MODEST_EDIT_TYPE_REPLY;
1340 case ACTION_FORWARD:
1342 modest_tny_msg_create_forward_msg (msg, from, signature, rf_helper->reply_forward_type);
1343 edit_type = MODEST_EDIT_TYPE_FORWARD;
1346 g_return_if_reached ();
1353 g_printerr ("modest: failed to create message\n");
1357 account = modest_tny_account_store_get_server_account (modest_runtime_get_account_store(),
1358 rf_helper->account_name,
1359 TNY_ACCOUNT_TYPE_STORE);
1361 g_printerr ("modest: failed to get tnyaccount for '%s'\n", rf_helper->account_name);
1365 /* Create and register the windows */
1366 msg_win = modest_msg_edit_window_new (new_msg, rf_helper->account_name, FALSE);
1367 mgr = modest_runtime_get_window_mgr ();
1368 modest_window_mgr_register_window (mgr, msg_win);
1370 if (rf_helper->parent_window != NULL) {
1371 gdouble parent_zoom;
1373 parent_zoom = modest_window_get_zoom (MODEST_WINDOW (rf_helper->parent_window));
1374 modest_window_set_zoom (msg_win, parent_zoom);
1377 /* Show edit window */
1378 gtk_widget_show_all (GTK_WIDGET (msg_win));
1382 g_object_unref (msg_win);
1384 g_object_unref (G_OBJECT (new_msg));
1386 g_object_unref (G_OBJECT (account));
1387 /* g_object_unref (msg); */
1388 free_reply_forward_helper (rf_helper);
1391 /* Checks a list of headers. If any of them are not currently
1392 * downloaded (CACHED) then returns TRUE else returns FALSE.
1395 header_list_count_uncached_msgs (TnyList *header_list)
1398 gint uncached_messages = 0;
1400 iter = tny_list_create_iterator (header_list);
1401 while (!tny_iterator_is_done (iter)) {
1404 header = TNY_HEADER (tny_iterator_get_current (iter));
1406 if (!(tny_header_get_flags (header) & TNY_HEADER_FLAG_CACHED))
1407 uncached_messages ++;
1408 g_object_unref (header);
1411 tny_iterator_next (iter);
1413 g_object_unref (iter);
1415 return uncached_messages;
1418 /* Returns FALSE if the user does not want to download the
1419 * messages. Returns TRUE if the user allowed the download.
1422 connect_to_get_msg (ModestWindow *win,
1423 gint num_of_uncached_msgs,
1424 TnyAccount *account)
1426 GtkResponseType response;
1428 /* Allways download if we are online. */
1429 if (tny_device_is_online (modest_runtime_get_device ()))
1432 /* If offline, then ask for user permission to download the messages */
1433 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
1434 ngettext("mcen_nc_get_msg",
1436 num_of_uncached_msgs));
1438 if (response == GTK_RESPONSE_CANCEL)
1441 return modest_platform_connect_and_wait((GtkWindow *) win, account);
1445 * Common code for the reply and forward actions
1448 reply_forward (ReplyForwardAction action, ModestWindow *win)
1450 ModestMailOperation *mail_op = NULL;
1451 TnyList *header_list = NULL;
1452 ReplyForwardHelper *rf_helper = NULL;
1453 guint reply_forward_type;
1454 gboolean continue_download = TRUE;
1455 gboolean do_retrieve = TRUE;
1457 g_return_if_fail (MODEST_IS_WINDOW(win));
1459 /* we need an account when editing */
1460 if (!modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE)) {
1461 if (!modest_ui_actions_run_account_setup_wizard (win))
1465 header_list = get_selected_headers (win);
1469 reply_forward_type =
1470 modest_conf_get_int (modest_runtime_get_conf (),
1471 (action == ACTION_FORWARD) ? MODEST_CONF_FORWARD_TYPE : MODEST_CONF_REPLY_TYPE,
1474 /* check if we need to download msg before asking about it */
1475 do_retrieve = (action == ACTION_FORWARD) ||
1476 (reply_forward_type != MODEST_TNY_MSG_REPLY_TYPE_CITE);
1479 gint num_of_unc_msgs;
1481 /* check that the messages have been previously downloaded */
1482 num_of_unc_msgs = header_list_count_uncached_msgs(header_list);
1483 /* If there are any uncached message ask the user
1484 * whether he/she wants to download them. */
1485 if (num_of_unc_msgs) {
1486 TnyAccount *account = get_account_from_header_list (header_list);
1487 continue_download = connect_to_get_msg (win, num_of_unc_msgs, account);
1488 g_object_unref (account);
1492 if (!continue_download) {
1493 g_object_unref (header_list);
1497 /* We assume that we can only select messages of the
1498 same folder and that we reply all of them from the
1499 same account. In fact the interface currently only
1500 allows single selection */
1503 rf_helper = g_slice_new0 (ReplyForwardHelper);
1504 rf_helper->reply_forward_type = reply_forward_type;
1505 rf_helper->action = action;
1506 rf_helper->account_name = g_strdup (modest_window_get_active_account (win));
1508 if ((win != NULL) && (MODEST_IS_WINDOW (win)))
1509 rf_helper->parent_window = GTK_WIDGET (win);
1510 if (!rf_helper->account_name)
1511 rf_helper->account_name =
1512 modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
1514 if (MODEST_IS_MSG_VIEW_WINDOW(win)) {
1517 /* Get header and message. Do not free them here, the
1518 reply_forward_cb must do it */
1519 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW(win));
1520 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW(win));
1521 if (!msg || !header) {
1523 g_object_unref (msg);
1524 g_printerr ("modest: no message found\n");
1527 reply_forward_cb (NULL, header, FALSE, msg, NULL, rf_helper);
1530 g_object_unref (header);
1535 /* Only reply/forward to one message */
1536 iter = tny_list_create_iterator (header_list);
1537 header = TNY_HEADER (tny_iterator_get_current (iter));
1538 g_object_unref (iter);
1541 /* Retrieve messages */
1544 modest_mail_operation_new_with_error_handling (G_OBJECT(win),
1545 modest_ui_actions_get_msgs_full_error_handler,
1547 modest_mail_operation_queue_add (
1548 modest_runtime_get_mail_operation_queue (), mail_op);
1550 modest_mail_operation_get_msg (mail_op,
1555 g_object_unref(mail_op);
1557 /* we put a ref here to prevent double unref as the reply
1558 * forward callback unrefs the header at its end */
1559 reply_forward_cb (NULL, header, FALSE, NULL, NULL, rf_helper);
1563 g_object_unref (header);
1569 g_object_unref (header_list);
1573 modest_ui_actions_on_reply (GtkAction *action, ModestWindow *win)
1575 g_return_if_fail (MODEST_IS_WINDOW(win));
1577 reply_forward (ACTION_REPLY, win);
1581 modest_ui_actions_on_forward (GtkAction *action, ModestWindow *win)
1583 g_return_if_fail (MODEST_IS_WINDOW(win));
1585 reply_forward (ACTION_FORWARD, win);
1589 modest_ui_actions_on_reply_all (GtkAction *action, ModestWindow *win)
1591 g_return_if_fail (MODEST_IS_WINDOW(win));
1593 reply_forward (ACTION_REPLY_TO_ALL, win);
1597 modest_ui_actions_on_next (GtkAction *action,
1598 ModestWindow *window)
1600 if (MODEST_IS_MAIN_WINDOW (window)) {
1601 GtkWidget *header_view;
1603 header_view = modest_main_window_get_child_widget (
1604 MODEST_MAIN_WINDOW(window),
1605 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1609 modest_header_view_select_next (
1610 MODEST_HEADER_VIEW(header_view));
1611 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
1612 modest_msg_view_window_select_next_message (
1613 MODEST_MSG_VIEW_WINDOW (window));
1615 g_return_if_reached ();
1620 modest_ui_actions_on_prev (GtkAction *action,
1621 ModestWindow *window)
1623 g_return_if_fail (MODEST_IS_WINDOW(window));
1625 if (MODEST_IS_MAIN_WINDOW (window)) {
1626 GtkWidget *header_view;
1627 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
1628 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1632 modest_header_view_select_prev (MODEST_HEADER_VIEW(header_view));
1633 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
1634 modest_msg_view_window_select_previous_message (MODEST_MSG_VIEW_WINDOW (window));
1636 g_return_if_reached ();
1641 modest_ui_actions_on_sort (GtkAction *action,
1642 ModestWindow *window)
1644 g_return_if_fail (MODEST_IS_WINDOW(window));
1646 if (MODEST_IS_MAIN_WINDOW (window)) {
1647 GtkWidget *header_view;
1648 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
1649 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1651 modest_platform_information_banner (NULL, NULL, _CS("ckdg_ib_nothing_to_sort"));
1656 /* Show sorting dialog */
1657 modest_platform_run_sort_dialog (GTK_WINDOW (window), MODEST_SORT_HEADERS);
1662 new_messages_arrived (ModestMailOperation *self,
1663 TnyList *new_headers,
1667 gboolean show_visual_notifications;
1669 source = modest_mail_operation_get_source (self);
1670 show_visual_notifications = (source) ? FALSE : TRUE;
1672 g_object_unref (source);
1674 /* Notify new messages have been downloaded. If the
1675 send&receive was invoked by the user then do not show any
1676 visual notification, only play a sound and activate the LED
1677 (for the Maemo version) */
1678 if (TNY_IS_LIST(new_headers) && (tny_list_get_length (new_headers)) > 0)
1679 modest_platform_on_new_headers_received (new_headers,
1680 show_visual_notifications);
1685 retrieve_all_messages_cb (GObject *source,
1687 guint retrieve_limit)
1693 window = GTK_WINDOW (source);
1694 msg = g_strdup_printf (_("mail_nc_msg_count_limit_exceeded"),
1695 num_msgs, retrieve_limit);
1697 /* Ask the user if they want to retrieve all the messages */
1699 modest_platform_run_confirmation_dialog_with_buttons (window, msg,
1700 _("mcen_bd_get_all"),
1701 _("mcen_bd_newest_only"));
1702 /* Free and return */
1704 return (response == GTK_RESPONSE_ACCEPT) ? TRUE : FALSE;
1708 TnyAccount *account;
1710 gchar *account_name;
1714 do_send_receive_performer (gboolean canceled,
1716 GtkWindow *parent_window,
1717 TnyAccount *account,
1720 ModestMailOperation *mail_op;
1721 SendReceiveInfo *info;
1723 info = (SendReceiveInfo *) user_data;
1725 if (err || canceled) {
1729 /* Set send/receive operation in progress */
1730 if (info->win && MODEST_IS_MAIN_WINDOW (info->win)) {
1731 modest_main_window_notify_send_receive_initied (MODEST_MAIN_WINDOW (info->win));
1734 mail_op = modest_mail_operation_new_with_error_handling ((info->win) ? G_OBJECT (info->win) : NULL,
1735 modest_ui_actions_send_receive_error_handler,
1738 if (info->win && MODEST_IS_MAIN_WINDOW (info->win))
1739 g_signal_connect (G_OBJECT(mail_op), "operation-finished",
1740 G_CALLBACK (on_send_receive_finished),
1743 /* Send & receive. */
1744 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
1745 modest_mail_operation_update_account (mail_op, info->account_name, (info->win) ? FALSE : TRUE,
1746 (info->win) ? retrieve_all_messages_cb : NULL,
1747 new_messages_arrived, info->win);
1748 g_object_unref (G_OBJECT (mail_op));
1752 if (info->account_name)
1753 g_free (info->account_name);
1755 g_object_unref (info->win);
1757 g_object_unref (info->account);
1758 g_slice_free (SendReceiveInfo, info);
1762 * This function performs the send & receive required actions. The
1763 * window is used to create the mail operation. Typically it should
1764 * always be the main window, but we pass it as argument in order to
1768 modest_ui_actions_do_send_receive (const gchar *account_name,
1769 gboolean force_connection,
1772 gchar *acc_name = NULL;
1773 SendReceiveInfo *info;
1774 ModestTnyAccountStore *acc_store;
1776 /* If no account name was provided then get the current account, and if
1777 there is no current account then pick the default one: */
1778 if (!account_name) {
1780 acc_name = g_strdup (modest_window_get_active_account (win));
1782 acc_name = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
1784 g_printerr ("modest: cannot get default account\n");
1788 acc_name = g_strdup (account_name);
1791 acc_store = modest_runtime_get_account_store ();
1793 /* Create the info for the connect and perform */
1794 info = g_slice_new (SendReceiveInfo);
1795 info->account_name = acc_name;
1796 info->win = (win) ? g_object_ref (win) : NULL;
1797 info->account = modest_tny_account_store_get_server_account (acc_store, acc_name,
1798 TNY_ACCOUNT_TYPE_STORE);
1800 /* Invoke the connect and perform */
1801 modest_platform_connect_and_perform ((win) ? GTK_WINDOW (win) : NULL,
1802 force_connection, info->account,
1803 do_send_receive_performer, info);
1808 modest_ui_actions_do_cancel_send (const gchar *account_name,
1811 TnyTransportAccount *transport_account;
1812 TnySendQueue *send_queue = NULL;
1813 GError *error = NULL;
1815 /* Get transport account */
1817 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
1818 (modest_runtime_get_account_store(),
1820 TNY_ACCOUNT_TYPE_TRANSPORT));
1821 if (!transport_account) {
1822 g_printerr ("modest: no transport account found for '%s'\n", account_name);
1827 send_queue = TNY_SEND_QUEUE (modest_runtime_get_send_queue (transport_account));
1828 if (!TNY_IS_SEND_QUEUE(send_queue)) {
1829 g_set_error (&error, MODEST_MAIL_OPERATION_ERROR,
1830 MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND,
1831 "modest: could not find send queue for account\n");
1833 /* Cancel the current send */
1834 tny_account_cancel (TNY_ACCOUNT (transport_account));
1836 /* Suspend all pending messages */
1837 tny_send_queue_cancel (send_queue, TNY_SEND_QUEUE_CANCEL_ACTION_SUSPEND, &error);
1841 if (transport_account != NULL)
1842 g_object_unref (G_OBJECT (transport_account));
1846 modest_ui_actions_cancel_send_all (ModestWindow *win)
1848 GSList *account_names, *iter;
1850 account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
1853 iter = account_names;
1855 modest_ui_actions_do_cancel_send ((const char*) iter->data, win);
1856 iter = g_slist_next (iter);
1859 modest_account_mgr_free_account_names (account_names);
1860 account_names = NULL;
1864 modest_ui_actions_cancel_send (GtkAction *action, ModestWindow *win)
1867 /* Check if accounts exist */
1868 gboolean accounts_exist =
1869 modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
1871 /* If not, allow the user to create an account before trying to send/receive. */
1872 if (!accounts_exist)
1873 modest_ui_actions_on_accounts (NULL, win);
1875 /* Cancel all sending operaitons */
1876 modest_ui_actions_cancel_send_all (win);
1880 * Refreshes all accounts. This function will be used by automatic
1884 modest_ui_actions_do_send_receive_all (ModestWindow *win,
1885 gboolean force_connection)
1887 GSList *account_names, *iter;
1889 account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
1892 iter = account_names;
1894 modest_ui_actions_do_send_receive ((const char*) iter->data, force_connection, win);
1895 iter = g_slist_next (iter);
1898 modest_account_mgr_free_account_names (account_names);
1899 account_names = NULL;
1903 * Handler of the click on Send&Receive button in the main toolbar
1906 modest_ui_actions_on_send_receive (GtkAction *action, ModestWindow *win)
1908 /* Check if accounts exist */
1909 gboolean accounts_exist;
1912 modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
1914 /* If not, allow the user to create an account before trying to send/receive. */
1915 if (!accounts_exist)
1916 modest_ui_actions_on_accounts (NULL, win);
1918 /* Refresh the current folder. The if is always TRUE it's just an extra check */
1919 if (MODEST_IS_MAIN_WINDOW (win)) {
1920 GtkWidget *folder_view;
1921 TnyFolderStore *folder_store;
1924 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
1925 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
1929 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
1932 g_object_unref (folder_store);
1935 /* Refresh the active account. Force the connection if needed */
1936 modest_ui_actions_do_send_receive (NULL, TRUE, win);
1941 modest_ui_actions_toggle_header_list_view (GtkAction *action, ModestMainWindow *main_window)
1944 GtkWidget *header_view;
1946 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1948 header_view = modest_main_window_get_child_widget (main_window,
1949 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1953 conf = modest_runtime_get_conf ();
1955 /* what is saved/restored is depending on the style; thus; we save with
1956 * old style, then update the style, and restore for this new style
1958 modest_widget_memory_save (conf, G_OBJECT(header_view), MODEST_CONF_HEADER_VIEW_KEY);
1960 if (modest_header_view_get_style
1961 (MODEST_HEADER_VIEW(header_view)) == MODEST_HEADER_VIEW_STYLE_DETAILS)
1962 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
1963 MODEST_HEADER_VIEW_STYLE_TWOLINES);
1965 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
1966 MODEST_HEADER_VIEW_STYLE_DETAILS);
1968 modest_widget_memory_restore (conf, G_OBJECT(header_view),
1969 MODEST_CONF_HEADER_VIEW_KEY);
1974 modest_ui_actions_on_header_selected (ModestHeaderView *header_view,
1976 ModestMainWindow *main_window)
1978 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1979 g_return_if_fail (MODEST_IS_HEADER_VIEW (header_view));
1981 /* in the case the folder is empty, show the empty folder message and focus
1983 if (!header && gtk_widget_is_focus (GTK_WIDGET (header_view))) {
1984 if (modest_header_view_is_empty (header_view)) {
1985 TnyFolder *folder = modest_header_view_get_folder (header_view);
1986 GtkWidget *folder_view =
1987 modest_main_window_get_child_widget (main_window,
1988 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
1990 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view), folder, FALSE);
1991 gtk_widget_grab_focus (GTK_WIDGET (folder_view));
1995 /* If no header has been selected then exit */
2000 if (!gtk_widget_is_focus (GTK_WIDGET(header_view)))
2001 gtk_widget_grab_focus (GTK_WIDGET(header_view));
2003 /* Update toolbar dimming state */
2004 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
2008 modest_ui_actions_on_header_activated (ModestHeaderView *header_view,
2010 ModestMainWindow *main_window)
2014 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2019 if (modest_header_view_count_selected_headers (header_view) > 1) {
2020 modest_platform_information_banner (NULL, NULL, _("mcen_ib_select_one_message"));
2025 /* headers = tny_simple_list_new (); */
2026 /* tny_list_prepend (headers, G_OBJECT (header)); */
2027 headers = modest_header_view_get_selected_headers (header_view);
2029 open_msgs_from_headers (headers, MODEST_WINDOW (main_window));
2031 g_object_unref (headers);
2035 set_active_account_from_tny_account (TnyAccount *account,
2036 ModestWindow *window)
2038 const gchar *server_acc_name = tny_account_get_id (account);
2040 /* We need the TnyAccount provided by the
2041 account store because that is the one that
2042 knows the name of the Modest account */
2043 TnyAccount *modest_server_account = modest_server_account =
2044 modest_tny_account_store_get_tny_account_by (modest_runtime_get_account_store (),
2045 MODEST_TNY_ACCOUNT_STORE_QUERY_ID,
2047 if (!modest_server_account) {
2048 g_warning ("%s: could not get tny account\n", __FUNCTION__);
2052 /* Update active account, but only if it's not a pseudo-account */
2053 if ((!modest_tny_account_is_virtual_local_folders(modest_server_account)) &&
2054 (!modest_tny_account_is_memory_card_account(modest_server_account))) {
2055 const gchar *modest_acc_name =
2056 modest_tny_account_get_parent_modest_account_name_for_server_account (modest_server_account);
2057 if (modest_acc_name)
2058 modest_window_set_active_account (window, modest_acc_name);
2061 g_object_unref (modest_server_account);
2066 folder_refreshed_cb (ModestMailOperation *mail_op,
2070 ModestMainWindow *win = NULL;
2071 GtkWidget *header_view;
2073 g_return_if_fail (TNY_IS_FOLDER (folder));
2075 win = MODEST_MAIN_WINDOW (user_data);
2077 modest_main_window_get_child_widget(win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2080 TnyFolder *current_folder;
2082 current_folder = modest_header_view_get_folder (MODEST_HEADER_VIEW (header_view));
2083 if (current_folder != NULL && folder != current_folder) {
2084 g_object_unref (current_folder);
2086 } else if (current_folder)
2087 g_object_unref (current_folder);
2090 /* Check if folder is empty and set headers view contents style */
2091 if (tny_folder_get_all_count (folder) == 0)
2092 modest_main_window_set_contents_style (win,
2093 MODEST_MAIN_WINDOW_CONTENTS_STYLE_EMPTY);
2097 modest_ui_actions_on_folder_selection_changed (ModestFolderView *folder_view,
2098 TnyFolderStore *folder_store,
2100 ModestMainWindow *main_window)
2103 GtkWidget *header_view;
2105 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2107 header_view = modest_main_window_get_child_widget(main_window,
2108 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2112 conf = modest_runtime_get_conf ();
2114 if (TNY_IS_ACCOUNT (folder_store)) {
2116 set_active_account_from_tny_account (TNY_ACCOUNT (folder_store), MODEST_WINDOW (main_window));
2118 /* Show account details */
2119 modest_main_window_set_contents_style (main_window, MODEST_MAIN_WINDOW_CONTENTS_STYLE_DETAILS);
2122 if (TNY_IS_FOLDER (folder_store) && selected) {
2124 /* Update the active account */
2125 TnyAccount *account = modest_tny_folder_get_account (TNY_FOLDER (folder_store));
2127 set_active_account_from_tny_account (account, MODEST_WINDOW (main_window));
2128 g_object_unref (account);
2132 /* Set the header style by default, it could
2133 be changed later by the refresh callback to
2135 modest_main_window_set_contents_style (main_window,
2136 MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS);
2138 /* Set folder on header view. This function
2139 will call tny_folder_refresh_async so we
2140 pass a callback that will be called when
2141 finished. We use that callback to set the
2142 empty view if there are no messages */
2143 modest_header_view_set_folder (MODEST_HEADER_VIEW(header_view),
2144 TNY_FOLDER (folder_store),
2145 folder_refreshed_cb,
2148 /* Restore configuration. We need to do this
2149 *after* the set_folder because the widget
2150 memory asks the header view about its
2152 modest_widget_memory_restore (modest_runtime_get_conf (),
2153 G_OBJECT(header_view),
2154 MODEST_CONF_HEADER_VIEW_KEY);
2156 /* Update the active account */
2157 //modest_window_set_active_account (MODEST_WINDOW (main_window), NULL);
2158 /* Save only if we're seeing headers */
2159 if (modest_main_window_get_contents_style (main_window) ==
2160 MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS)
2161 modest_widget_memory_save (conf, G_OBJECT (header_view),
2162 MODEST_CONF_HEADER_VIEW_KEY);
2163 modest_header_view_clear (MODEST_HEADER_VIEW(header_view));
2167 /* Update toolbar dimming state */
2168 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
2172 modest_ui_actions_on_item_not_found (ModestHeaderView *header_view,ModestItemType type,
2179 item = (type == MODEST_ITEM_TYPE_FOLDER) ? "folder" : "message";
2181 online = tny_device_is_online (modest_runtime_get_device());
2184 /* already online -- the item is simply not there... */
2185 dialog = gtk_message_dialog_new (GTK_WINDOW (win),
2187 GTK_MESSAGE_WARNING,
2189 _("The %s you selected cannot be found"),
2191 gtk_dialog_add_button (GTK_DIALOG (dialog),_("mcen_bd_dialog_ok"), GTK_RESPONSE_ACCEPT);
2192 gtk_dialog_run (GTK_DIALOG(dialog));
2194 dialog = gtk_dialog_new_with_buttons (_("Connection requested"),
2197 _("mcen_bd_dialog_cancel"),
2198 GTK_RESPONSE_REJECT,
2199 _("mcen_bd_dialog_ok"),
2200 GTK_RESPONSE_ACCEPT,
2202 txt = g_strdup_printf (_("This %s is not available in offline mode.\n"
2203 "Do you want to get online?"), item);
2204 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
2205 gtk_label_new (txt), FALSE, FALSE, 0);
2206 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
2209 gtk_window_set_default_size (GTK_WINDOW(dialog), 300, 300);
2210 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
2211 /* TODO: Comment about why is this commented out: */
2212 /* modest_platform_connect_and_wait (); */
2215 gtk_widget_destroy (dialog);
2219 modest_ui_actions_on_msg_link_hover (ModestMsgView *msgview, const gchar* link,
2222 /* g_message ("%s %s", __FUNCTION__, link); */
2227 modest_ui_actions_on_msg_link_clicked (ModestMsgView *msgview, const gchar* link,
2230 modest_platform_activate_uri (link);
2234 modest_ui_actions_on_msg_link_contextual (ModestMsgView *msgview, const gchar* link,
2237 modest_platform_show_uri_popup (link);
2241 modest_ui_actions_on_msg_attachment_clicked (ModestMsgView *msgview, TnyMimePart *mime_part,
2244 modest_msg_view_window_view_attachment (MODEST_MSG_VIEW_WINDOW (win), mime_part);
2248 modest_ui_actions_on_msg_recpt_activated (ModestMsgView *msgview,
2249 const gchar *address,
2252 /* g_message ("%s %s", __FUNCTION__, address); */
2256 on_save_to_drafts_cb (ModestMailOperation *mail_op,
2257 TnyMsg *saved_draft,
2260 ModestMsgEditWindow *edit_window;
2261 ModestMainWindow *win;
2263 /* FIXME. Make the header view sensitive again. This is a
2264 * temporary hack. See modest_ui_actions_on_save_to_drafts()
2266 win = MODEST_MAIN_WINDOW(modest_window_mgr_get_main_window(
2267 modest_runtime_get_window_mgr(), FALSE));
2269 GtkWidget *hdrview = modest_main_window_get_child_widget(
2270 win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2271 if (hdrview) gtk_widget_set_sensitive(hdrview, TRUE);
2274 edit_window = MODEST_MSG_EDIT_WINDOW (user_data);
2276 /* It might not be a good idea to do nothing if there was an error,
2277 * so let's at least show a generic error banner. */
2278 /* TODO error while saving attachment, show "Saving draft failed" banner */
2279 if (modest_mail_operation_get_error (mail_op) != NULL) {
2280 g_warning ("%s failed: %s\n", __FUNCTION__, (modest_mail_operation_get_error (mail_op))->message);
2281 modest_platform_information_banner (NULL, NULL, _("mail_ib_file_operation_failed"));
2283 modest_msg_edit_window_set_draft (edit_window, saved_draft);
2285 g_object_unref(edit_window);
2289 modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edit_window)
2291 TnyTransportAccount *transport_account;
2292 ModestMailOperation *mail_operation;
2294 gchar *account_name, *from;
2295 ModestAccountMgr *account_mgr;
2297 gboolean had_error = FALSE;
2298 guint64 available_disk, expected_size;
2302 g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window), FALSE);
2304 data = modest_msg_edit_window_get_msg_data (edit_window);
2307 available_disk = modest_folder_available_space (NULL);
2308 modest_msg_edit_window_get_parts_size (edit_window, &parts_count, &parts_size);
2309 expected_size = modest_tny_msg_estimate_size (data->plain_body,
2314 if ((available_disk != -1) && expected_size > available_disk) {
2315 modest_msg_edit_window_free_msg_data (edit_window, data);
2317 modest_platform_information_banner (NULL, NULL, dgettext("ke-recv", "cerm_device_memory_full"));
2321 account_name = g_strdup (data->account_name);
2322 account_mgr = modest_runtime_get_account_mgr();
2324 account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
2326 account_name = modest_account_mgr_get_default_account (account_mgr);
2327 if (!account_name) {
2328 g_printerr ("modest: no account found\n");
2329 modest_msg_edit_window_free_msg_data (edit_window, data);
2333 if (!strcmp (account_name, MODEST_LOCAL_FOLDERS_ACCOUNT_ID)) {
2334 account_name = g_strdup (data->account_name);
2338 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
2339 (modest_runtime_get_account_store(),
2341 TNY_ACCOUNT_TYPE_TRANSPORT));
2342 if (!transport_account) {
2343 g_printerr ("modest: no transport account found for '%s'\n", account_name);
2344 g_free (account_name);
2345 modest_msg_edit_window_free_msg_data (edit_window, data);
2348 from = modest_account_mgr_get_from_string (account_mgr, account_name);
2350 /* Create the mail operation */
2351 mail_operation = modest_mail_operation_new (NULL);
2352 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
2354 modest_mail_operation_save_to_drafts (mail_operation,
2366 data->priority_flags,
2367 on_save_to_drafts_cb,
2368 g_object_ref(edit_window));
2370 info_text = g_strdup_printf (_("mail_va_saved_to_drafts"), _("mcen_me_folder_drafts"));
2371 modest_platform_information_banner (NULL, NULL, info_text);
2373 modest_msg_edit_window_reset_modified (edit_window);
2377 g_free (account_name);
2378 g_object_unref (G_OBJECT (transport_account));
2379 g_object_unref (G_OBJECT (mail_operation));
2381 modest_msg_edit_window_free_msg_data (edit_window, data);
2384 * If the drafts folder is selected then make the header view
2385 * insensitive while the message is being saved to drafts
2386 * (it'll be sensitive again in on_save_to_drafts_cb()). This
2387 * is not very clean but it avoids letting the drafts folder
2388 * in an inconsistent state: the user could edit the message
2389 * being saved and undesirable things would happen.
2390 * In the average case the user won't notice anything at
2391 * all. In the worst case (the user is editing a really big
2392 * file from Drafts) the header view will be insensitive
2393 * during the saving process (10 or 20 seconds, depending on
2394 * the message). Anyway this is just a quick workaround: once
2395 * we find a better solution it should be removed
2396 * See NB#65125 (commend #18) for details.
2398 ModestMainWindow *win = MODEST_MAIN_WINDOW(modest_window_mgr_get_main_window(
2399 modest_runtime_get_window_mgr(), FALSE));
2400 if (!had_error && win != NULL) {
2401 ModestFolderView *view = MODEST_FOLDER_VIEW(modest_main_window_get_child_widget(
2402 win, MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW));
2404 TnyFolder *folder = TNY_FOLDER(modest_folder_view_get_selected(view));
2406 if (modest_tny_folder_is_local_folder(folder)) {
2407 TnyFolderType folder_type;
2408 folder_type = modest_tny_folder_get_local_or_mmc_folder_type(folder);
2409 if (folder_type == TNY_FOLDER_TYPE_DRAFTS) {
2410 GtkWidget *hdrview = modest_main_window_get_child_widget(
2411 win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2412 if (hdrview) gtk_widget_set_sensitive(hdrview, FALSE);
2416 if (folder != NULL) g_object_unref(folder);
2423 /* For instance, when clicking the Send toolbar button when editing a message: */
2425 modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
2427 TnyTransportAccount *transport_account = NULL;
2428 gboolean had_error = FALSE;
2429 guint64 available_disk, expected_size;
2433 g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window), TRUE);
2435 if (!modest_msg_edit_window_check_names (edit_window, TRUE))
2438 /* FIXME: Code added just for testing. The final version will
2439 use the send queue provided by tinymail and some
2441 MsgData *data = modest_msg_edit_window_get_msg_data (edit_window);
2444 available_disk = modest_folder_available_space (NULL);
2445 modest_msg_edit_window_get_parts_size (edit_window, &parts_count, &parts_size);
2446 expected_size = modest_tny_msg_estimate_size (data->plain_body,
2451 if ((available_disk != -1) && expected_size > available_disk) {
2452 modest_msg_edit_window_free_msg_data (edit_window, data);
2454 modest_platform_information_banner (NULL, NULL, dgettext("ke-recv", "cerm_device_memory_full"));
2458 ModestAccountMgr *account_mgr = modest_runtime_get_account_mgr();
2459 gchar *account_name = g_strdup (data->account_name);
2461 account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
2464 account_name = modest_account_mgr_get_default_account (account_mgr);
2466 if (!account_name) {
2467 modest_msg_edit_window_free_msg_data (edit_window, data);
2468 /* Run account setup wizard */
2469 if (!modest_ui_actions_run_account_setup_wizard (MODEST_WINDOW(edit_window))) {
2474 /* Get the currently-active transport account for this modest account: */
2475 if (strcmp (account_name, MODEST_LOCAL_FOLDERS_ACCOUNT_ID) != 0) {
2476 transport_account = TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
2477 (modest_runtime_get_account_store(),
2478 account_name, TNY_ACCOUNT_TYPE_TRANSPORT));
2481 if (!transport_account) {
2482 modest_msg_edit_window_free_msg_data (edit_window, data);
2483 /* Run account setup wizard */
2484 if (!modest_ui_actions_run_account_setup_wizard(MODEST_WINDOW(edit_window)))
2488 gchar *from = modest_account_mgr_get_from_string (account_mgr, account_name);
2490 /* Create the mail operation */
2491 ModestMailOperation *mail_operation = modest_mail_operation_new (NULL);
2492 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
2494 modest_mail_operation_send_new_mail (mail_operation,
2506 data->priority_flags);
2508 if (modest_mail_operation_get_status (mail_operation) == MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS)
2509 modest_platform_information_banner (NULL, NULL, _("mcen_ib_outbox_waiting_to_be_sent"));
2512 if (modest_mail_operation_get_error (mail_operation) != NULL) {
2513 const GError *error = modest_mail_operation_get_error (mail_operation);
2514 if (error->code == MODEST_MAIL_OPERATION_ERROR_INSTANCE_CREATION_FAILED) {
2515 g_warning ("%s failed: %s\n", __FUNCTION__, (modest_mail_operation_get_error (mail_operation))->message);
2516 modest_platform_information_banner (NULL, NULL, _CS("sfil_ni_not_enough_memory"));
2523 g_free (account_name);
2524 g_object_unref (G_OBJECT (transport_account));
2525 g_object_unref (G_OBJECT (mail_operation));
2527 modest_msg_edit_window_free_msg_data (edit_window, data);
2530 modest_msg_edit_window_set_sent (edit_window, TRUE);
2532 /* Save settings and close the window: */
2533 modest_ui_actions_on_close_window (NULL, MODEST_WINDOW (edit_window));
2540 modest_ui_actions_on_toggle_bold (GtkToggleAction *action,
2541 ModestMsgEditWindow *window)
2543 ModestMsgEditFormatState *format_state = NULL;
2545 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2546 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
2548 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2551 format_state = modest_msg_edit_window_get_format_state (window);
2552 g_return_if_fail (format_state != NULL);
2554 format_state->bold = gtk_toggle_action_get_active (action);
2555 modest_msg_edit_window_set_format_state (window, format_state);
2556 g_free (format_state);
2561 modest_ui_actions_on_toggle_italics (GtkToggleAction *action,
2562 ModestMsgEditWindow *window)
2564 ModestMsgEditFormatState *format_state = NULL;
2566 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2567 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
2569 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2572 format_state = modest_msg_edit_window_get_format_state (window);
2573 g_return_if_fail (format_state != NULL);
2575 format_state->italics = gtk_toggle_action_get_active (action);
2576 modest_msg_edit_window_set_format_state (window, format_state);
2577 g_free (format_state);
2582 modest_ui_actions_on_toggle_bullets (GtkToggleAction *action,
2583 ModestMsgEditWindow *window)
2585 ModestMsgEditFormatState *format_state = NULL;
2587 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2588 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
2590 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2593 format_state = modest_msg_edit_window_get_format_state (window);
2594 g_return_if_fail (format_state != NULL);
2596 format_state->bullet = gtk_toggle_action_get_active (action);
2597 modest_msg_edit_window_set_format_state (window, format_state);
2598 g_free (format_state);
2603 modest_ui_actions_on_change_justify (GtkRadioAction *action,
2604 GtkRadioAction *selected,
2605 ModestMsgEditWindow *window)
2607 ModestMsgEditFormatState *format_state = NULL;
2608 GtkJustification value;
2610 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2612 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2615 value = gtk_radio_action_get_current_value (selected);
2617 format_state = modest_msg_edit_window_get_format_state (window);
2618 g_return_if_fail (format_state != NULL);
2620 format_state->justification = value;
2621 modest_msg_edit_window_set_format_state (window, format_state);
2622 g_free (format_state);
2626 modest_ui_actions_on_select_editor_color (GtkAction *action,
2627 ModestMsgEditWindow *window)
2629 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2630 g_return_if_fail (GTK_IS_ACTION (action));
2632 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2635 modest_msg_edit_window_select_color (window);
2639 modest_ui_actions_on_select_editor_background_color (GtkAction *action,
2640 ModestMsgEditWindow *window)
2642 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2643 g_return_if_fail (GTK_IS_ACTION (action));
2645 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2648 modest_msg_edit_window_select_background_color (window);
2652 modest_ui_actions_on_insert_image (GtkAction *action,
2653 ModestMsgEditWindow *window)
2655 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2656 g_return_if_fail (GTK_IS_ACTION (action));
2658 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2661 modest_msg_edit_window_insert_image (window);
2665 modest_ui_actions_on_attach_file (GtkAction *action,
2666 ModestMsgEditWindow *window)
2668 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2669 g_return_if_fail (GTK_IS_ACTION (action));
2671 modest_msg_edit_window_offer_attach_file (window);
2675 modest_ui_actions_on_remove_attachments (GtkAction *action,
2676 ModestMsgEditWindow *window)
2678 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2679 g_return_if_fail (GTK_IS_ACTION (action));
2681 modest_msg_edit_window_remove_attachments (window, NULL);
2685 do_create_folder_cb (ModestMailOperation *mail_op,
2686 TnyFolderStore *parent_folder,
2687 TnyFolder *new_folder,
2690 gchar *suggested_name = (gchar *) user_data;
2691 GtkWindow *source_win = (GtkWindow *) modest_mail_operation_get_source (mail_op);
2693 if (modest_mail_operation_get_error (mail_op)) {
2695 modest_platform_information_banner (GTK_WIDGET (source_win), NULL,
2696 _("mail_in_ui_folder_create_error"));
2699 do_create_folder (source_win, parent_folder, (const gchar *) suggested_name);
2701 /* the 'source_win' is either the ModestMainWindow, or the 'Move to folder'-dialog
2702 * FIXME: any other? */
2703 GtkWidget *folder_view;
2705 if (MODEST_IS_MAIN_WINDOW(source_win))
2707 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (source_win),
2708 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2711 get_folder_view_from_move_to_dialog (GTK_WIDGET(source_win));
2713 /* Select the newly created folder */
2714 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view),
2716 g_object_unref (new_folder);
2718 /* Free. Note that the first time it'll be NULL so noop */
2719 g_free (suggested_name);
2720 g_object_unref (source_win);
2724 do_create_folder (GtkWindow *parent_window,
2725 TnyFolderStore *parent_folder,
2726 const gchar *suggested_name)
2729 gchar *folder_name = NULL;
2731 result = modest_platform_run_new_folder_dialog (GTK_WINDOW (parent_window),
2733 (gchar *) suggested_name,
2736 if (result == GTK_RESPONSE_ACCEPT) {
2737 ModestMailOperation *mail_op;
2739 mail_op = modest_mail_operation_new (G_OBJECT(parent_window));
2741 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
2743 modest_mail_operation_create_folder (mail_op,
2745 (const gchar *) folder_name,
2746 do_create_folder_cb,
2748 g_object_unref (mail_op);
2753 create_folder_performer (gboolean canceled,
2755 GtkWindow *parent_window,
2756 TnyAccount *account,
2759 TnyFolderStore *parent_folder = TNY_FOLDER_STORE (user_data);
2761 if (canceled || err) {
2765 /* Run the new folder dialog */
2766 do_create_folder (GTK_WINDOW (parent_window), parent_folder, NULL);
2769 g_object_unref (parent_folder);
2773 modest_ui_actions_create_folder(GtkWidget *parent_window,
2774 GtkWidget *folder_view)
2776 TnyFolderStore *parent_folder;
2778 parent_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
2780 if (parent_folder) {
2781 /* The parent folder will be freed in the callback */
2782 modest_platform_connect_if_remote_and_perform (GTK_WINDOW (parent_window),
2785 create_folder_performer,
2791 modest_ui_actions_on_new_folder (GtkAction *action, ModestMainWindow *main_window)
2793 GtkWidget *folder_view;
2795 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2797 folder_view = modest_main_window_get_child_widget (main_window,
2798 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2802 modest_ui_actions_create_folder (GTK_WIDGET (main_window), folder_view);
2806 modest_ui_actions_rename_folder_error_handler (ModestMailOperation *mail_op,
2809 ModestMainWindow *window = MODEST_MAIN_WINDOW (user_data);
2810 const GError *error = NULL;
2811 const gchar *message = NULL;
2813 /* Get error message */
2814 error = modest_mail_operation_get_error (mail_op);
2816 g_return_if_reached ();
2818 switch (error->code) {
2819 case MODEST_MAIL_OPERATION_ERROR_FOLDER_EXISTS:
2820 message = _CS("ckdg_ib_folder_already_exists");
2823 g_warning ("%s: BUG: unexpected error:[%d]: %s", __FUNCTION__,
2824 error->code, error->message);
2828 modest_platform_information_banner (GTK_WIDGET (window), NULL, message);
2832 TnyFolderStore *folder;
2837 on_rename_folder_cb (ModestMailOperation *mail_op,
2838 TnyFolder *new_folder,
2842 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (user_data),
2847 on_rename_folder_performer (gboolean canceled,
2849 GtkWindow *parent_window,
2850 TnyAccount *account,
2853 ModestMailOperation *mail_op = NULL;
2854 GtkTreeSelection *sel = NULL;
2855 GtkWidget *folder_view = NULL;
2856 RenameFolderInfo *data = (RenameFolderInfo*)user_data;
2858 if (!canceled && (err == NULL) && MODEST_IS_MAIN_WINDOW(parent_window)) {
2860 folder_view = modest_main_window_get_child_widget (
2861 MODEST_MAIN_WINDOW (parent_window),
2862 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2865 modest_mail_operation_new_with_error_handling (G_OBJECT(parent_window),
2866 modest_ui_actions_rename_folder_error_handler,
2867 parent_window, NULL);
2869 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
2872 /* Clear the headers view */
2873 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_view));
2874 gtk_tree_selection_unselect_all (sel);
2876 /* Actually rename the folder */
2877 modest_mail_operation_rename_folder (mail_op,
2878 TNY_FOLDER (data->folder),
2879 (const gchar *) (data->new_name),
2880 on_rename_folder_cb,
2884 g_object_unref (mail_op);
2885 g_free (data->new_name);
2890 modest_ui_actions_on_rename_folder (GtkAction *action,
2891 ModestMainWindow *main_window)
2893 TnyFolderStore *folder;
2894 GtkWidget *folder_view;
2895 GtkWidget *header_view;
2897 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2899 folder_view = modest_main_window_get_child_widget (main_window,
2900 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2904 header_view = modest_main_window_get_child_widget (main_window,
2905 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2910 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
2915 if (TNY_IS_FOLDER (folder)) {
2918 const gchar *current_name;
2919 TnyFolderStore *parent;
2920 gboolean do_rename = TRUE;
2922 current_name = tny_folder_get_name (TNY_FOLDER (folder));
2923 parent = tny_folder_get_folder_store (TNY_FOLDER (folder));
2924 response = modest_platform_run_rename_folder_dialog (GTK_WINDOW (main_window),
2925 parent, current_name,
2927 g_object_unref (parent);
2929 if (response != GTK_RESPONSE_ACCEPT || strlen (folder_name) == 0) {
2932 RenameFolderInfo *rename_folder_data = g_new0 (RenameFolderInfo, 1);
2933 rename_folder_data->folder = folder;
2934 rename_folder_data->new_name = folder_name;
2935 modest_platform_connect_if_remote_and_perform (GTK_WINDOW(main_window), TRUE,
2936 folder, on_rename_folder_performer, rename_folder_data);
2939 g_object_unref (folder);
2943 modest_ui_actions_delete_folder_error_handler (ModestMailOperation *mail_op,
2946 GObject *win = modest_mail_operation_get_source (mail_op);
2948 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
2949 _("mail_in_ui_folder_delete_error"));
2950 g_object_unref (win);
2954 TnyFolderStore *folder;
2955 gboolean move_to_trash;
2959 on_delete_folder_cb (gboolean canceled,
2961 GtkWindow *parent_window,
2962 TnyAccount *account,
2965 DeleteFolderInfo *info = (DeleteFolderInfo*) user_data;
2966 GtkWidget *folder_view;
2967 ModestMailOperation *mail_op;
2968 GtkTreeSelection *sel;
2970 if (!MODEST_IS_MAIN_WINDOW(parent_window) || canceled || (err!=NULL)) {
2971 g_object_unref (G_OBJECT (info->folder));
2975 folder_view = modest_main_window_get_child_widget (
2976 MODEST_MAIN_WINDOW (parent_window),
2977 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2979 /* Unselect the folder before deleting it to free the headers */
2980 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_view));
2981 gtk_tree_selection_unselect_all (sel);
2983 /* Create the mail operation */
2985 modest_mail_operation_new_with_error_handling (G_OBJECT(parent_window),
2986 modest_ui_actions_delete_folder_error_handler,
2989 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
2991 modest_mail_operation_remove_folder (mail_op, TNY_FOLDER (info->folder), info->move_to_trash);
2993 modest_folder_view_select_first_inbox_or_local (MODEST_FOLDER_VIEW (folder_view));
2995 g_object_unref (G_OBJECT (mail_op));
2996 g_object_unref (G_OBJECT (info->folder));
3001 delete_folder (ModestMainWindow *main_window, gboolean move_to_trash)
3003 TnyFolderStore *folder;
3004 GtkWidget *folder_view;
3008 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
3010 folder_view = modest_main_window_get_child_widget (main_window,
3011 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3015 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
3017 /* Show an error if it's an account */
3018 if (!TNY_IS_FOLDER (folder)) {
3019 modest_platform_run_information_dialog (GTK_WINDOW (main_window),
3020 _("mail_in_ui_folder_delete_error"));
3021 g_object_unref (G_OBJECT (folder));
3026 message = g_strdup_printf (_("mcen_nc_delete_folder_text"),
3027 tny_folder_get_name (TNY_FOLDER (folder)));
3028 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (main_window),
3029 (const gchar *) message);
3032 if (response == GTK_RESPONSE_OK) {
3033 DeleteFolderInfo *info;
3034 info = g_new0(DeleteFolderInfo, 1);
3035 info->folder = folder;
3036 info->move_to_trash = move_to_trash;
3037 g_object_ref (G_OBJECT (info->folder));
3038 TnyAccount *account = tny_folder_get_account (TNY_FOLDER (folder));
3039 modest_platform_connect_if_remote_and_perform (GTK_WINDOW (main_window),
3041 TNY_FOLDER_STORE (account),
3042 on_delete_folder_cb, info);
3043 g_object_unref (account);
3045 g_object_unref (G_OBJECT (folder));
3049 modest_ui_actions_on_delete_folder (GtkAction *action,
3050 ModestMainWindow *main_window)
3052 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
3054 delete_folder (main_window, FALSE);
3058 modest_ui_actions_on_move_folder_to_trash_folder (GtkAction *action, ModestMainWindow *main_window)
3060 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
3062 delete_folder (main_window, TRUE);
3067 show_error (GtkWidget *parent_widget, const gchar* text)
3069 modest_platform_information_banner(parent_widget, NULL, text);
3072 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_window, text)); */
3074 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
3081 gtk_dialog_run (dialog);
3082 gtk_widget_destroy (GTK_WIDGET (dialog));
3087 modest_ui_actions_on_password_requested (TnyAccountStore *account_store,
3088 const gchar* server_account_name,
3093 ModestMainWindow *main_window)
3095 g_return_if_fail(server_account_name);
3097 /* Initalize output parameters: */
3104 #ifdef MODEST_PLATFORM_MAEMO
3105 /* Maemo uses a different (awkward) button order,
3106 * It should probably just use gtk_alternative_dialog_button_order ().
3108 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
3111 _("mcen_bd_dialog_ok"),
3112 GTK_RESPONSE_ACCEPT,
3113 _("mcen_bd_dialog_cancel"),
3114 GTK_RESPONSE_REJECT,
3117 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
3121 GTK_RESPONSE_REJECT,
3123 GTK_RESPONSE_ACCEPT,
3125 #endif /* MODEST_PLATFORM_MAEMO */
3127 modest_window_mgr_set_modal (modest_runtime_get_window_mgr(), GTK_WINDOW (dialog));
3129 gchar *server_name = modest_account_mgr_get_server_account_hostname (
3130 modest_runtime_get_account_mgr(), server_account_name);
3131 if (!server_name) {/* This happened once, though I don't know why. murrayc. */
3132 g_warning("%s: Could not get server name for server account '%s'", __FUNCTION__, server_account_name);
3138 /* This causes a warning because the logical ID has no %s in it,
3139 * though the translation does, but there is not much we can do about that: */
3140 gchar *txt = g_strdup_printf (_("mail_ia_password_info"), server_name);
3141 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), gtk_label_new(txt),
3144 g_free (server_name);
3148 gchar *initial_username = modest_account_mgr_get_server_account_username (
3149 modest_runtime_get_account_mgr(), server_account_name);
3151 GtkWidget *entry_username = gtk_entry_new ();
3152 if (initial_username)
3153 gtk_entry_set_text (GTK_ENTRY (entry_username), initial_username);
3154 /* Dim this if a connection has ever succeeded with this username,
3155 * as per the UI spec: */
3156 const gboolean username_known =
3157 modest_account_mgr_get_server_account_username_has_succeeded(
3158 modest_runtime_get_account_mgr(), server_account_name);
3159 gtk_widget_set_sensitive (entry_username, !username_known);
3161 #ifdef MODEST_PLATFORM_MAEMO
3162 /* Auto-capitalization is the default, so let's turn it off: */
3163 hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_username), HILDON_GTK_INPUT_MODE_FULL);
3165 /* Create a size group to be used by all captions.
3166 * Note that HildonCaption does not create a default size group if we do not specify one.
3167 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
3168 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
3170 GtkWidget *caption = hildon_caption_new (sizegroup,
3171 _("mail_fi_username"), entry_username, NULL, HILDON_CAPTION_MANDATORY);
3172 gtk_widget_show (entry_username);
3173 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
3174 FALSE, FALSE, MODEST_MARGIN_HALF);
3175 gtk_widget_show (caption);
3177 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry_username,
3179 #endif /* MODEST_PLATFORM_MAEMO */
3182 GtkWidget *entry_password = gtk_entry_new ();
3183 gtk_entry_set_visibility (GTK_ENTRY(entry_password), FALSE);
3184 /* gtk_entry_set_invisible_char (GTK_ENTRY(entry_password), "*"); */
3186 #ifdef MODEST_PLATFORM_MAEMO
3187 /* Auto-capitalization is the default, so let's turn it off: */
3188 hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_password),
3189 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
3191 caption = hildon_caption_new (sizegroup,
3192 _("mail_fi_password"), entry_password, NULL, HILDON_CAPTION_MANDATORY);
3193 gtk_widget_show (entry_password);
3194 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
3195 FALSE, FALSE, MODEST_MARGIN_HALF);
3196 gtk_widget_show (caption);
3197 g_object_unref (sizegroup);
3199 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry_password,
3201 #endif /* MODEST_PLATFORM_MAEMO */
3203 if (initial_username != NULL)
3204 gtk_widget_grab_focus (GTK_WIDGET (entry_password));
3206 /* This is not in the Maemo UI spec:
3207 remember_pass_check = gtk_check_button_new_with_label (_("Remember password"));
3208 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), remember_pass_check,
3212 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
3214 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
3216 *username = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_username)));
3218 modest_account_mgr_set_server_account_username (
3219 modest_runtime_get_account_mgr(), server_account_name,
3222 const gboolean username_was_changed =
3223 (strcmp (*username, initial_username) != 0);
3224 if (username_was_changed) {
3225 g_warning ("%s: tinymail does not yet support changing the "
3226 "username in the get_password() callback.\n", __FUNCTION__);
3231 *password = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_password)));
3233 /* We do not save the password in the configuration,
3234 * because this function is only called for passwords that should
3235 * not be remembered:
3236 modest_server_account_set_password (
3237 modest_runtime_get_account_mgr(), server_account_name,
3246 show_error(GTK_WIDGET (main_window), _("mail_ib_login_cancelled"));
3258 /* This is not in the Maemo UI spec:
3259 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (remember_pass_check)))
3265 gtk_widget_destroy (dialog);
3267 /* printf ("DEBUG: %s: cancel=%d\n", __FUNCTION__, *cancel); */
3271 modest_ui_actions_on_cut (GtkAction *action,
3272 ModestWindow *window)
3274 GtkWidget *focused_widget;
3275 GtkClipboard *clipboard;
3277 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
3278 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
3279 if (GTK_IS_EDITABLE (focused_widget)) {
3280 gtk_editable_cut_clipboard (GTK_EDITABLE(focused_widget));
3281 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3282 gtk_clipboard_store (clipboard);
3283 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
3284 GtkTextBuffer *buffer;
3286 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
3287 gtk_text_buffer_cut_clipboard (buffer, clipboard, TRUE);
3288 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3289 gtk_clipboard_store (clipboard);
3290 } else if (MODEST_IS_HEADER_VIEW (focused_widget)) {
3291 TnyList *header_list = modest_header_view_get_selected_headers (
3292 MODEST_HEADER_VIEW (focused_widget));
3293 gboolean continue_download = FALSE;
3294 gint num_of_unc_msgs;
3296 num_of_unc_msgs = header_list_count_uncached_msgs(header_list);
3298 if (num_of_unc_msgs) {
3299 TnyAccount *account = get_account_from_header_list (header_list);
3300 continue_download = connect_to_get_msg (window, num_of_unc_msgs, account);
3301 g_object_unref (account);
3304 if (num_of_unc_msgs == 0 || continue_download) {
3305 /* modest_platform_information_banner (
3306 NULL, NULL, _CS("mcen_ib_getting_items"));*/
3307 modest_header_view_cut_selection (
3308 MODEST_HEADER_VIEW (focused_widget));
3311 g_object_unref (header_list);
3312 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
3313 modest_folder_view_cut_selection (MODEST_FOLDER_VIEW (focused_widget));
3318 modest_ui_actions_on_copy (GtkAction *action,
3319 ModestWindow *window)
3321 GtkClipboard *clipboard;
3322 GtkWidget *focused_widget;
3323 gboolean copied = TRUE;
3325 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
3326 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
3328 if (GTK_IS_LABEL (focused_widget)) {
3329 gtk_clipboard_set_text (clipboard, gtk_label_get_text (GTK_LABEL (focused_widget)), -1);
3330 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3331 gtk_clipboard_store (clipboard);
3332 } else if (GTK_IS_EDITABLE (focused_widget)) {
3333 gtk_editable_copy_clipboard (GTK_EDITABLE(focused_widget));
3334 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3335 gtk_clipboard_store (clipboard);
3336 } else if (GTK_IS_HTML (focused_widget)) {
3337 gtk_html_copy (GTK_HTML (focused_widget));
3338 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3339 gtk_clipboard_store (clipboard);
3340 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
3341 GtkTextBuffer *buffer;
3342 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
3343 gtk_text_buffer_copy_clipboard (buffer, clipboard);
3344 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3345 gtk_clipboard_store (clipboard);
3346 } else if (MODEST_IS_HEADER_VIEW (focused_widget)) {
3347 TnyList *header_list = modest_header_view_get_selected_headers (
3348 MODEST_HEADER_VIEW (focused_widget));
3349 gboolean continue_download = FALSE;
3350 gint num_of_unc_msgs;
3352 num_of_unc_msgs = header_list_count_uncached_msgs(header_list);
3354 if (num_of_unc_msgs) {
3355 TnyAccount *account = get_account_from_header_list (header_list);
3356 continue_download = connect_to_get_msg (window, num_of_unc_msgs, account);
3357 g_object_unref (account);
3360 if (num_of_unc_msgs == 0 || continue_download) {
3361 modest_platform_information_banner (
3362 NULL, NULL, _CS("mcen_ib_getting_items"));
3363 modest_header_view_copy_selection (
3364 MODEST_HEADER_VIEW (focused_widget));
3368 g_object_unref (header_list);
3370 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
3371 modest_folder_view_copy_selection (MODEST_FOLDER_VIEW (focused_widget));
3374 /* Show information banner if there was a copy to clipboard */
3376 modest_platform_information_banner (
3377 NULL, NULL, _CS("ecoc_ib_edwin_copied"));
3381 modest_ui_actions_on_undo (GtkAction *action,
3382 ModestWindow *window)
3384 ModestEmailClipboard *clipboard = NULL;
3386 if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
3387 modest_msg_edit_window_undo (MODEST_MSG_EDIT_WINDOW (window));
3388 } else if (MODEST_IS_MAIN_WINDOW (window)) {
3389 /* Clear clipboard source */
3390 clipboard = modest_runtime_get_email_clipboard ();
3391 modest_email_clipboard_clear (clipboard);
3394 g_return_if_reached ();
3399 modest_ui_actions_on_redo (GtkAction *action,
3400 ModestWindow *window)
3402 if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
3403 modest_msg_edit_window_redo (MODEST_MSG_EDIT_WINDOW (window));
3406 g_return_if_reached ();
3412 destroy_information_note (ModestMailOperation *mail_op,
3415 /* destroy information note */
3416 gtk_widget_destroy (GTK_WIDGET(user_data));
3420 destroy_folder_information_note (ModestMailOperation *mail_op,
3421 TnyFolder *new_folder,
3424 /* destroy information note */
3425 gtk_widget_destroy (GTK_WIDGET(user_data));
3430 paste_as_attachment_free (gpointer data)
3432 PasteAsAttachmentHelper *helper = (PasteAsAttachmentHelper *) data;
3434 gtk_widget_destroy (helper->banner);
3435 g_object_unref (helper->banner);
3440 paste_msg_as_attachment_cb (ModestMailOperation *mail_op,
3445 PasteAsAttachmentHelper *helper = (PasteAsAttachmentHelper *) userdata;
3446 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (helper->window));
3451 modest_msg_edit_window_add_part (MODEST_MSG_EDIT_WINDOW (helper->window), TNY_MIME_PART (msg));
3456 modest_ui_actions_on_paste (GtkAction *action,
3457 ModestWindow *window)
3459 GtkWidget *focused_widget = NULL;
3460 GtkWidget *inf_note = NULL;
3461 ModestMailOperation *mail_op = NULL;
3463 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
3464 if (GTK_IS_EDITABLE (focused_widget)) {
3465 gtk_editable_paste_clipboard (GTK_EDITABLE(focused_widget));
3466 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
3467 ModestEmailClipboard *e_clipboard = NULL;
3468 e_clipboard = modest_runtime_get_email_clipboard ();
3469 if (modest_email_clipboard_cleared (e_clipboard)) {
3470 GtkTextBuffer *buffer;
3471 GtkClipboard *clipboard;
3473 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
3474 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
3475 gtk_text_buffer_paste_clipboard (buffer, clipboard, NULL, TRUE);
3476 } else if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
3477 ModestMailOperation *mail_op;
3478 TnyFolder *src_folder;
3481 PasteAsAttachmentHelper *helper = g_new0 (PasteAsAttachmentHelper, 1);
3482 helper->window = MODEST_MSG_EDIT_WINDOW (window);
3483 helper->banner = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
3484 _CS("ckct_nw_pasting"));
3485 modest_email_clipboard_get_data (e_clipboard, &src_folder, &data, &delete);
3486 mail_op = modest_mail_operation_new (G_OBJECT (window));
3487 if (helper->banner != NULL) {
3488 g_object_ref (G_OBJECT (helper->banner));
3489 gtk_window_set_modal (GTK_WINDOW (helper->banner), FALSE);
3490 gtk_widget_show (GTK_WIDGET (helper->banner));
3494 modest_mail_operation_get_msgs_full (mail_op,
3496 (GetMsgAsyncUserCallback) paste_msg_as_attachment_cb,
3498 paste_as_attachment_free);
3501 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
3502 ModestEmailClipboard *clipboard = NULL;
3503 TnyFolder *src_folder = NULL;
3504 TnyFolderStore *folder_store = NULL;
3505 TnyList *data = NULL;
3506 gboolean delete = FALSE;
3508 /* Check clipboard source */
3509 clipboard = modest_runtime_get_email_clipboard ();
3510 if (modest_email_clipboard_cleared (clipboard))
3513 /* Get elements to paste */
3514 modest_email_clipboard_get_data (clipboard, &src_folder, &data, &delete);
3516 /* Create a new mail operation */
3517 mail_op = modest_mail_operation_new (G_OBJECT(window));
3519 /* Get destination folder */
3520 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (focused_widget));
3522 /* transfer messages */
3526 /* Ask for user confirmation */
3528 modest_ui_actions_msgs_move_to_confirmation (window,
3529 TNY_FOLDER (folder_store),
3533 if (response == GTK_RESPONSE_OK) {
3534 /* Launch notification */
3535 inf_note = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
3536 _CS("ckct_nw_pasting"));
3537 if (inf_note != NULL) {
3538 gtk_window_set_modal (GTK_WINDOW(inf_note), FALSE);
3539 gtk_widget_show (GTK_WIDGET(inf_note));
3542 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
3543 modest_mail_operation_xfer_msgs (mail_op,
3545 TNY_FOLDER (folder_store),
3547 destroy_information_note,
3550 g_object_unref (mail_op);
3553 } else if (src_folder != NULL) {
3554 /* Launch notification */
3555 inf_note = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
3556 _CS("ckct_nw_pasting"));
3557 if (inf_note != NULL) {
3558 gtk_window_set_modal (GTK_WINDOW(inf_note), FALSE);
3559 gtk_widget_show (GTK_WIDGET(inf_note));
3562 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
3563 modest_mail_operation_xfer_folder (mail_op,
3567 destroy_folder_information_note,
3573 g_object_unref (data);
3574 if (src_folder != NULL)
3575 g_object_unref (src_folder);
3576 if (folder_store != NULL)
3577 g_object_unref (folder_store);
3583 modest_ui_actions_on_select_all (GtkAction *action,
3584 ModestWindow *window)
3586 GtkWidget *focused_widget;
3588 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
3589 if (MODEST_IS_ATTACHMENTS_VIEW (focused_widget)) {
3590 modest_attachments_view_select_all (MODEST_ATTACHMENTS_VIEW (focused_widget));
3591 } else if (GTK_IS_LABEL (focused_widget)) {
3592 gtk_label_select_region (GTK_LABEL (focused_widget), 0, -1);
3593 } else if (GTK_IS_EDITABLE (focused_widget)) {
3594 gtk_editable_select_region (GTK_EDITABLE(focused_widget), 0, -1);
3595 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
3596 GtkTextBuffer *buffer;
3597 GtkTextIter start, end;
3599 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
3600 gtk_text_buffer_get_start_iter (buffer, &start);
3601 gtk_text_buffer_get_end_iter (buffer, &end);
3602 gtk_text_buffer_select_range (buffer, &start, &end);
3603 } else if (GTK_IS_HTML (focused_widget)) {
3604 gtk_html_select_all (GTK_HTML (focused_widget));
3605 } else if (MODEST_IS_MAIN_WINDOW (window)) {
3606 GtkWidget *header_view = focused_widget;
3607 GtkTreeSelection *selection = NULL;
3609 if (!(MODEST_IS_HEADER_VIEW (focused_widget))) {
3610 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (window),
3611 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
3614 /* Disable window dimming management */
3615 modest_window_disable_dimming (MODEST_WINDOW(window));
3617 /* Select all messages */
3618 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(header_view));
3619 gtk_tree_selection_select_all (selection);
3621 /* Set focuse on header view */
3622 gtk_widget_grab_focus (header_view);
3625 /* Enable window dimming management */
3626 modest_window_enable_dimming (MODEST_WINDOW(window));
3627 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (window));
3633 modest_ui_actions_on_mark_as_read (GtkAction *action,
3634 ModestWindow *window)
3636 g_return_if_fail (MODEST_IS_WINDOW(window));
3638 /* Mark each header as read */
3639 do_headers_action (window, headers_action_mark_as_read, NULL);
3643 modest_ui_actions_on_mark_as_unread (GtkAction *action,
3644 ModestWindow *window)
3646 g_return_if_fail (MODEST_IS_WINDOW(window));
3648 /* Mark each header as read */
3649 do_headers_action (window, headers_action_mark_as_unread, NULL);
3653 modest_ui_actions_on_change_zoom (GtkRadioAction *action,
3654 GtkRadioAction *selected,
3655 ModestWindow *window)
3659 value = gtk_radio_action_get_current_value (selected);
3660 if (MODEST_IS_WINDOW (window)) {
3661 modest_window_set_zoom (MODEST_WINDOW (window), ((gdouble)value)/100);
3666 modest_ui_actions_msg_edit_on_change_priority (GtkRadioAction *action,
3667 GtkRadioAction *selected,
3668 ModestWindow *window)
3670 TnyHeaderFlags flags;
3671 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3673 flags = gtk_radio_action_get_current_value (selected);
3674 modest_msg_edit_window_set_priority_flags (MODEST_MSG_EDIT_WINDOW (window), flags);
3678 modest_ui_actions_msg_edit_on_change_file_format (GtkRadioAction *action,
3679 GtkRadioAction *selected,
3680 ModestWindow *window)
3684 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3686 file_format = gtk_radio_action_get_current_value (selected);
3687 modest_msg_edit_window_set_file_format (MODEST_MSG_EDIT_WINDOW (window), file_format);
3692 modest_ui_actions_on_zoom_plus (GtkAction *action,
3693 ModestWindow *window)
3695 g_return_if_fail (MODEST_IS_WINDOW (window));
3697 modest_window_zoom_plus (MODEST_WINDOW (window));
3701 modest_ui_actions_on_zoom_minus (GtkAction *action,
3702 ModestWindow *window)
3704 g_return_if_fail (MODEST_IS_WINDOW (window));
3706 modest_window_zoom_minus (MODEST_WINDOW (window));
3710 modest_ui_actions_on_toggle_fullscreen (GtkToggleAction *toggle,
3711 ModestWindow *window)
3713 ModestWindowMgr *mgr;
3714 gboolean fullscreen, active;
3715 g_return_if_fail (MODEST_IS_WINDOW (window));
3717 mgr = modest_runtime_get_window_mgr ();
3719 active = (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle)))?1:0;
3720 fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
3722 if (active != fullscreen) {
3723 modest_window_mgr_set_fullscreen_mode (mgr, active);
3724 gtk_window_present (GTK_WINDOW (window));
3729 modest_ui_actions_on_change_fullscreen (GtkAction *action,
3730 ModestWindow *window)
3732 ModestWindowMgr *mgr;
3733 gboolean fullscreen;
3735 g_return_if_fail (MODEST_IS_WINDOW (window));
3737 mgr = modest_runtime_get_window_mgr ();
3738 fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
3739 modest_window_mgr_set_fullscreen_mode (mgr, !fullscreen);
3741 gtk_window_present (GTK_WINDOW (window));
3745 * Used by modest_ui_actions_on_details to call do_headers_action
3748 headers_action_show_details (TnyHeader *header,
3749 ModestWindow *window,
3756 dialog = modest_details_dialog_new_with_header (GTK_WINDOW (window), header);
3759 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
3760 gtk_widget_show_all (dialog);
3761 gtk_dialog_run (GTK_DIALOG (dialog));
3763 gtk_widget_destroy (dialog);
3767 * Show the folder details in a ModestDetailsDialog widget
3770 show_folder_details (TnyFolder *folder,
3776 dialog = modest_details_dialog_new_with_folder (window, folder);
3779 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
3780 gtk_widget_show_all (dialog);
3781 gtk_dialog_run (GTK_DIALOG (dialog));
3783 gtk_widget_destroy (dialog);
3787 * Show the header details in a ModestDetailsDialog widget
3790 modest_ui_actions_on_details (GtkAction *action,
3793 TnyList * headers_list;
3797 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
3800 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW (win));
3803 g_object_unref (msg);
3805 headers_list = get_selected_headers (win);
3809 iter = tny_list_create_iterator (headers_list);
3811 header = TNY_HEADER (tny_iterator_get_current (iter));
3813 headers_action_show_details (header, win, NULL);
3814 g_object_unref (header);
3817 g_object_unref (iter);
3818 g_object_unref (headers_list);
3820 } else if (MODEST_IS_MAIN_WINDOW (win)) {
3821 GtkWidget *folder_view, *header_view;
3823 /* Check which widget has the focus */
3824 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
3825 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3826 if (gtk_widget_is_focus (folder_view)) {
3827 TnyFolderStore *folder_store
3828 = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
3829 if (!folder_store) {
3830 g_warning ("%s: No item was selected.\n", __FUNCTION__);
3833 /* Show only when it's a folder */
3834 /* This function should not be called for account items,
3835 * because we dim the menu item for them. */
3836 if (TNY_IS_FOLDER (folder_store)) {
3837 show_folder_details (TNY_FOLDER (folder_store), GTK_WINDOW (win));
3840 g_object_unref (folder_store);
3843 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
3844 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
3845 /* Show details of each header */
3846 do_headers_action (win, headers_action_show_details, header_view);
3852 modest_ui_actions_on_toggle_show_cc (GtkToggleAction *toggle,
3853 ModestMsgEditWindow *window)
3855 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3857 modest_msg_edit_window_show_cc (window, gtk_toggle_action_get_active (toggle));
3861 modest_ui_actions_on_toggle_show_bcc (GtkToggleAction *toggle,
3862 ModestMsgEditWindow *window)
3864 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3866 modest_msg_edit_window_show_bcc (window, gtk_toggle_action_get_active (toggle));
3870 modest_ui_actions_toggle_folders_view (GtkAction *action,
3871 ModestMainWindow *main_window)
3873 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
3875 if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)))
3876 modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SPLIT);
3878 modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SIMPLE);
3882 modest_ui_actions_on_toggle_toolbar (GtkToggleAction *toggle,
3883 ModestWindow *window)
3885 gboolean active, fullscreen = FALSE;
3886 ModestWindowMgr *mgr;
3888 active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle));
3890 /* Check if we want to toggle the toolbar vuew in fullscreen
3892 if (!strcmp (gtk_action_get_name (GTK_ACTION (toggle)),
3893 "ViewShowToolbarFullScreen")) {
3897 /* Toggle toolbar */
3898 mgr = modest_runtime_get_window_mgr ();
3899 modest_window_mgr_show_toolbars (mgr, G_TYPE_FROM_INSTANCE (window), active, fullscreen);
3903 modest_ui_actions_msg_edit_on_select_font (GtkAction *action,
3904 ModestMsgEditWindow *window)
3906 modest_msg_edit_window_select_font (window);
3911 modest_ui_actions_on_folder_display_name_changed (ModestFolderView *folder_view,
3912 const gchar *display_name,
3915 /* don't update the display name if it was already set;
3916 * updating the display name apparently is expensive */
3917 const gchar* old_name = gtk_window_get_title (window);
3919 if (display_name == NULL)
3922 if (old_name && display_name && strcmp (old_name, display_name) == 0)
3923 return; /* don't do anything */
3925 /* This is usually used to change the title of the main window, which
3926 * is the one that holds the folder view. Note that this change can
3927 * happen even when the widget doesn't have the focus. */
3928 gtk_window_set_title (window, display_name);
3933 modest_ui_actions_on_select_contacts (GtkAction *action, ModestMsgEditWindow *window)
3935 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3936 modest_msg_edit_window_select_contacts (window);
3940 modest_ui_actions_on_check_names (GtkAction *action, ModestMsgEditWindow *window)
3942 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3943 modest_msg_edit_window_check_names (window, FALSE);
3947 create_move_to_dialog_on_new_folder(GtkWidget *button, gpointer user_data)
3949 modest_ui_actions_create_folder (gtk_widget_get_toplevel (button),
3950 GTK_WIDGET (user_data));
3954 * This function is used to track changes in the selection of the
3955 * folder view that is inside the "move to" dialog to enable/disable
3956 * the OK button because we do not want the user to select a disallowed
3957 * destination for a folder.
3958 * The user also not desired to be able to use NEW button on items where
3959 * folder creation is not possibel.
3962 on_move_to_dialog_folder_selection_changed (ModestFolderView* self,
3963 TnyFolderStore *folder_store,
3967 GtkWidget *dialog = NULL;
3968 GtkWidget *ok_button = NULL, *new_button = NULL;
3969 GList *children = NULL;
3970 gboolean ok_sensitive = TRUE, new_sensitive = TRUE;
3971 gboolean moving_folder = FALSE;
3972 gboolean is_local_account = TRUE;
3973 GtkWidget *folder_view = NULL;
3974 ModestTnyFolderRules rules;
3979 /* Get the OK button */
3980 dialog = gtk_widget_get_ancestor (GTK_WIDGET (self), GTK_TYPE_DIALOG);
3984 children = gtk_container_get_children (GTK_CONTAINER (GTK_DIALOG (dialog)->action_area));
3985 ok_button = GTK_WIDGET (children->next->next->data);
3986 new_button = GTK_WIDGET (children->next->data);
3987 g_list_free (children);
3989 /* check if folder_store is an remote account */
3990 if (TNY_IS_ACCOUNT (folder_store)) {
3991 TnyAccount *local_account = NULL;
3992 TnyAccount *mmc_account = NULL;
3993 ModestTnyAccountStore *account_store = NULL;
3995 account_store = modest_runtime_get_account_store ();
3996 local_account = modest_tny_account_store_get_local_folders_account (account_store);
3997 mmc_account = modest_tny_account_store_get_mmc_folders_account (account_store);
3999 if ((gpointer) local_account != (gpointer) folder_store &&
4000 (gpointer) mmc_account != (gpointer) folder_store) {
4001 const char *proto_name = tny_account_get_proto (TNY_ACCOUNT (folder_store));
4002 ModestTransportStoreProtocol proto = MODEST_PROTOCOL_STORE_MAILDIR;
4003 if (proto_name != NULL) {
4004 proto = modest_protocol_info_get_transport_store_protocol (proto_name);
4006 is_local_account = FALSE;
4007 /* New button should be dimmed on remote
4009 new_sensitive = (proto != MODEST_PROTOCOL_STORE_POP);
4011 g_object_unref (local_account);
4014 /* Check the target folder rules */
4015 if (TNY_IS_FOLDER (folder_store)) {
4016 rules = modest_tny_folder_get_rules (TNY_FOLDER (folder_store));
4017 if (rules & MODEST_FOLDER_RULES_FOLDER_NON_WRITEABLE) {
4018 ok_sensitive = FALSE;
4019 new_sensitive = FALSE;
4024 /* Check if we're moving a folder */
4025 if (MODEST_IS_MAIN_WINDOW (user_data)) {
4026 /* Get the widgets */
4027 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (user_data),
4028 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
4029 if (gtk_widget_is_focus (folder_view))
4030 moving_folder = TRUE;
4033 if (moving_folder) {
4034 TnyFolderStore *moved_folder = NULL, *parent = NULL;
4036 /* Get the folder to move */
4037 moved_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
4039 /* Check that we're not moving to the same folder */
4040 if (TNY_IS_FOLDER (moved_folder)) {
4041 parent = tny_folder_get_folder_store (TNY_FOLDER (moved_folder));
4042 if (parent == folder_store)
4043 ok_sensitive = FALSE;
4044 g_object_unref (parent);
4047 if (ok_sensitive && TNY_IS_ACCOUNT (folder_store)) {
4048 /* Do not allow to move to an account unless it's the
4049 local folders account */
4050 if (!is_local_account)
4051 ok_sensitive = FALSE;
4054 if (ok_sensitive && (moved_folder == folder_store)) {
4055 /* Do not allow to move to itself */
4056 ok_sensitive = FALSE;
4058 g_object_unref (moved_folder);
4060 TnyHeader *header = NULL;
4061 TnyFolder *src_folder = NULL;
4063 /* Moving a message */
4064 if (MODEST_IS_MSG_VIEW_WINDOW (user_data)) {
4065 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (user_data));
4066 src_folder = tny_header_get_folder (header);
4067 g_object_unref (header);
4070 TNY_FOLDER (modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view)));
4073 /* Do not allow to move the msg to the same folder */
4074 /* Do not allow to move the msg to an account */
4075 if ((gpointer) src_folder == (gpointer) folder_store ||
4076 TNY_IS_ACCOUNT (folder_store))
4077 ok_sensitive = FALSE;
4078 g_object_unref (src_folder);
4082 /* Set sensitivity of the OK button */
4083 gtk_widget_set_sensitive (ok_button, ok_sensitive);
4084 /* Set sensitivity of the NEW button */
4085 gtk_widget_set_sensitive (new_button, new_sensitive);
4089 #define MODEST_MOVE_TO_DIALOG_FOLDER_VIEW "move-to-dialog-folder-view"
4092 get_folder_view_from_move_to_dialog (GtkWidget *move_to_dialog)
4094 return GTK_WIDGET(g_object_get_data (G_OBJECT(move_to_dialog),
4095 MODEST_MOVE_TO_DIALOG_FOLDER_VIEW));
4099 create_move_to_dialog (GtkWindow *win,
4100 GtkWidget *folder_view,
4101 GtkWidget **tree_view)
4103 GtkWidget *dialog, *scroll;
4104 GtkWidget *new_button;
4106 dialog = gtk_dialog_new_with_buttons (_("mcen_ti_moveto_folders_title"),
4108 GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR | GTK_DIALOG_DESTROY_WITH_PARENT,
4111 gtk_dialog_add_button (GTK_DIALOG (dialog), _("mcen_bd_dialog_ok"), GTK_RESPONSE_ACCEPT);
4112 /* We do this manually so GTK+ does not associate a response ID for
4114 new_button = gtk_button_new_from_stock (_("mcen_bd_new"));
4115 gtk_box_pack_end (GTK_BOX (GTK_DIALOG (dialog)->action_area), new_button, FALSE, FALSE, 0);
4116 gtk_dialog_add_button (GTK_DIALOG (dialog), _("mcen_bd_dialog_cancel"), GTK_RESPONSE_REJECT);
4118 /* Create scrolled window */
4119 scroll = gtk_scrolled_window_new (NULL, NULL);
4120 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll),
4121 GTK_POLICY_AUTOMATIC,
4122 GTK_POLICY_AUTOMATIC);
4124 /* Create folder view */
4125 *tree_view = modest_platform_create_folder_view (NULL);
4127 /* Track changes in the selection to
4128 * disable the OK button whenever "Move to" is not possible
4129 * disbale NEW button whenever New is not possible */
4130 g_signal_connect (*tree_view,
4131 "folder_selection_changed",
4132 G_CALLBACK (on_move_to_dialog_folder_selection_changed),
4135 /* Listen to clicks on New button */
4136 g_signal_connect (G_OBJECT (new_button),
4138 G_CALLBACK(create_move_to_dialog_on_new_folder),
4141 /* It could happen that we're trying to move a message from a
4142 window (msg window for example) after the main window was
4143 closed, so we can not just get the model of the folder
4145 if (MODEST_IS_FOLDER_VIEW (folder_view)) {
4146 const gchar *visible_id = NULL;
4148 modest_folder_view_set_style (MODEST_FOLDER_VIEW (*tree_view),
4149 MODEST_FOLDER_VIEW_STYLE_SHOW_ALL);
4150 modest_folder_view_copy_model (MODEST_FOLDER_VIEW(folder_view),
4151 MODEST_FOLDER_VIEW(*tree_view));
4154 modest_folder_view_get_account_id_of_visible_server_account (MODEST_FOLDER_VIEW(folder_view));
4156 /* Show the same account than the one that is shown in the main window */
4157 modest_folder_view_set_account_id_of_visible_server_account (MODEST_FOLDER_VIEW(*tree_view),
4160 const gchar *active_account_name = NULL;
4161 ModestAccountMgr *mgr = NULL;
4162 ModestAccountSettings *settings = NULL;
4163 ModestServerAccountSettings *store_settings = NULL;
4165 modest_folder_view_set_style (MODEST_FOLDER_VIEW (*tree_view),
4166 MODEST_FOLDER_VIEW_STYLE_SHOW_ALL);
4167 modest_folder_view_update_model (MODEST_FOLDER_VIEW (*tree_view),
4168 TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()));
4170 active_account_name = modest_window_get_active_account (MODEST_WINDOW (win));
4171 mgr = modest_runtime_get_account_mgr ();
4172 settings = modest_account_mgr_load_account_settings (mgr, active_account_name);
4175 const gchar *store_account_name;
4176 store_settings = modest_account_settings_get_store_settings (settings);
4177 store_account_name = modest_server_account_settings_get_account_name (store_settings);
4179 modest_folder_view_set_account_id_of_visible_server_account (MODEST_FOLDER_VIEW (*tree_view),
4180 store_account_name);
4181 g_object_unref (store_settings);
4182 g_object_unref (settings);
4186 /* we keep a pointer to the embedded folder view, so we can retrieve it with
4187 * get_folder_view_from_move_to_dialog
4188 * (see above) later (needed for focus handling)
4190 g_object_set_data (G_OBJECT(dialog), MODEST_MOVE_TO_DIALOG_FOLDER_VIEW, *tree_view);
4193 /* Hide special folders */
4194 modest_folder_view_show_non_move_folders (MODEST_FOLDER_VIEW (*tree_view), FALSE);
4196 gtk_container_add (GTK_CONTAINER (scroll), *tree_view);
4198 /* Add scroll to dialog */
4199 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
4200 scroll, TRUE, TRUE, 0);
4202 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
4203 gtk_window_set_default_size (GTK_WINDOW (dialog), 300, 300);
4209 * Returns TRUE if at least one of the headers of the list belongs to
4210 * a message that has been fully retrieved.
4212 #if 0 /* no longer in use. delete in 2007.10 */
4214 has_retrieved_msgs (TnyList *list)
4217 gboolean found = FALSE;
4219 iter = tny_list_create_iterator (list);
4220 while (!tny_iterator_is_done (iter) && !found) {
4222 TnyHeaderFlags flags = 0;
4224 header = TNY_HEADER (tny_iterator_get_current (iter));
4226 flags = tny_header_get_flags (header);
4227 if (flags & TNY_HEADER_FLAG_CACHED)
4228 /* if (!(flags & TNY_HEADER_FLAG_PARTIAL)) */
4231 g_object_unref (header);
4235 tny_iterator_next (iter);
4237 g_object_unref (iter);
4245 * Shows a confirmation dialog to the user when we're moving messages
4246 * from a remote server to the local storage. Returns the dialog
4247 * response. If it's other kind of movement then it always returns
4250 * This one is used by the next functions:
4251 * modest_ui_actions_on_paste - commented out
4252 * drag_and_drop_from_header_view (for d&d in modest_folder_view.c)
4255 modest_ui_actions_msgs_move_to_confirmation (ModestWindow *win,
4256 TnyFolder *dest_folder,
4260 gint response = GTK_RESPONSE_OK;
4261 TnyAccount *account = NULL;
4262 TnyFolder *src_folder = NULL;
4263 TnyIterator *iter = NULL;
4264 TnyHeader *header = NULL;
4266 /* return with OK if the destination is a remote folder */
4267 if (modest_tny_folder_is_remote_folder (dest_folder))
4268 return GTK_RESPONSE_OK;
4270 /* Get source folder */
4271 iter = tny_list_create_iterator (headers);
4272 header = TNY_HEADER (tny_iterator_get_current (iter));
4274 src_folder = tny_header_get_folder (header);
4275 g_object_unref (header);
4277 g_object_unref (iter);
4279 /* if no src_folder, message may be an attahcment */
4280 if (src_folder == NULL)
4281 return GTK_RESPONSE_CANCEL;
4283 /* If the source is a local or MMC folder */
4284 if (!modest_tny_folder_is_remote_folder (src_folder)) {
4285 g_object_unref (src_folder);
4286 return GTK_RESPONSE_OK;
4289 /* Get the account */
4290 account = tny_folder_get_account (src_folder);
4292 /* now if offline we ask the user */
4293 if(connect_to_get_msg (win, tny_list_get_length (headers), account))
4294 response = GTK_RESPONSE_OK;
4296 response = GTK_RESPONSE_CANCEL;
4299 g_object_unref (src_folder);
4300 g_object_unref (account);
4306 move_to_cb (ModestMailOperation *mail_op,
4309 MoveToHelper *helper = (MoveToHelper *) user_data;
4311 /* Note that the operation could have failed, in that case do
4313 if (modest_mail_operation_get_status (mail_op) ==
4314 MODEST_MAIL_OPERATION_STATUS_SUCCESS) {
4316 GObject *object = modest_mail_operation_get_source (mail_op);
4317 if (MODEST_IS_MSG_VIEW_WINDOW (object)) {
4318 ModestMsgViewWindow *self = MODEST_MSG_VIEW_WINDOW (object);
4320 if (modest_msg_view_window_last_message_selected (self) &&
4321 modest_msg_view_window_first_message_selected (self)) {
4322 modest_ui_actions_on_close_window (NULL, MODEST_WINDOW (self));
4323 } else if (!modest_msg_view_window_select_next_message (self) &&
4324 !modest_msg_view_window_select_previous_message (self)) {
4325 /* No more messages to view, so close this window */
4326 modest_ui_actions_on_close_window (NULL, MODEST_WINDOW(self));
4328 } else if (MODEST_IS_MAIN_WINDOW (object) && helper->reference != NULL) {
4329 GtkWidget *header_view;
4331 GtkTreeSelection *sel;
4333 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(object),
4334 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
4335 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
4336 path = gtk_tree_row_reference_get_path (helper->reference);
4337 gtk_tree_selection_select_path (sel, path);
4338 gtk_tree_path_free (path);
4340 g_object_unref (object);
4343 /* Close the "Pasting" information banner */
4344 gtk_widget_destroy (GTK_WIDGET(helper->banner));
4345 if (helper->reference != NULL)
4346 gtk_tree_row_reference_free (helper->reference);
4351 folder_move_to_cb (ModestMailOperation *mail_op,
4352 TnyFolder *new_folder,
4355 move_to_cb (mail_op, user_data);
4359 msgs_move_to_cb (ModestMailOperation *mail_op,
4362 move_to_cb (mail_op, user_data);
4366 modest_ui_actions_move_folder_error_handler (ModestMailOperation *mail_op,
4369 ModestWindow *main_window = NULL;
4370 GObject *win = NULL;
4372 /* Disable next automatic folder selection */
4373 main_window = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (),
4374 FALSE); /* don't create */
4376 GtkWidget *folder_view = NULL;
4378 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (main_window),
4379 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
4380 modest_folder_view_disable_next_folder_selection (MODEST_FOLDER_VIEW(folder_view));
4382 if (user_data && TNY_IS_FOLDER (user_data)) {
4383 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view),
4384 TNY_FOLDER (user_data), FALSE);
4388 /* Show notification dialog */
4389 win = modest_mail_operation_get_source (mail_op);
4390 modest_platform_run_information_dialog ((GtkWindow *) win, _("mail_in_ui_folder_move_target_error"));
4392 g_object_unref (win);
4396 modest_ui_actions_send_receive_error_handler (ModestMailOperation *mail_op,
4399 GObject *win = modest_mail_operation_get_source (mail_op);
4400 const GError *error = modest_mail_operation_get_error (mail_op);
4402 g_return_if_fail (error != NULL);
4403 if (error->message != NULL)
4404 g_printerr ("modest: %s\n", error->message);
4406 g_printerr ("modest: unkonw error on send&receive operation");
4408 /* Show error message */
4409 /* if (modest_mail_operation_get_id (mail_op) == MODEST_MAIL_OPERATION_TYPE_RECEIVE) */
4410 /* modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL, */
4411 /* _CS("sfil_ib_unable_to_receive")); */
4413 /* modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL, */
4414 /* _CS("sfil_ib_unable_to_send")); */
4415 g_object_unref (win);
4419 open_msg_for_purge_cb (ModestMailOperation *mail_op,
4428 gint pending_purges = 0;
4429 gboolean some_purged = FALSE;
4430 ModestWindow *win = MODEST_WINDOW (user_data);
4431 ModestWindowMgr *mgr = modest_runtime_get_window_mgr ();
4433 /* If there was any error */
4434 if (!modest_ui_actions_msg_retrieval_check (mail_op, header, msg)) {
4435 modest_window_mgr_unregister_header (mgr, header);
4439 /* Once the message has been retrieved for purging, we check if
4440 * it's all ok for purging */
4442 parts = tny_simple_list_new ();
4443 tny_mime_part_get_parts (TNY_MIME_PART (msg), parts);
4444 iter = tny_list_create_iterator (parts);
4446 while (!tny_iterator_is_done (iter)) {
4448 part = TNY_MIME_PART (tny_iterator_get_current (iter));
4449 if (part && (tny_mime_part_is_attachment (part) || TNY_IS_MSG (part))) {
4450 if (tny_mime_part_is_purged (part))
4457 g_object_unref (part);
4459 tny_iterator_next (iter);
4461 g_object_unref (iter);
4464 if (pending_purges>0) {
4466 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),_("mcen_nc_purge_file_text_inbox"));
4468 if (response == GTK_RESPONSE_OK) {
4469 modest_platform_information_banner (NULL, NULL, _("mcen_ib_removing_attachment"));
4470 iter = tny_list_create_iterator (parts);
4471 while (!tny_iterator_is_done (iter)) {
4474 part = TNY_MIME_PART (tny_iterator_get_current (iter));
4475 if (part && (tny_mime_part_is_attachment (part) || TNY_IS_MSG (part)))
4476 tny_mime_part_set_purged (part);
4479 g_object_unref (part);
4481 tny_iterator_next (iter);
4484 tny_msg_rewrite_cache (msg);
4487 /* This string no longer exists, refer to NB#75415 for more info */
4488 /* modest_platform_information_banner (NULL, NULL, _("mail_ib_attachment_already_purged")); */
4490 g_object_unref (iter);
4492 modest_window_mgr_unregister_header (mgr, header);
4494 g_object_unref (parts);
4498 modest_ui_actions_on_main_window_remove_attachments (GtkAction *action,
4499 ModestMainWindow *win)
4501 GtkWidget *header_view;
4502 TnyList *header_list;
4505 TnyHeaderFlags flags;
4506 ModestWindow *msg_view_window = NULL;
4509 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win));
4511 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
4512 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
4514 header_list = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW (header_view));
4516 g_warning ("%s: no header selected", __FUNCTION__);
4520 if (tny_list_get_length (header_list) == 1) {
4521 iter = tny_list_create_iterator (header_list);
4522 header = TNY_HEADER (tny_iterator_get_current (iter));
4523 g_object_unref (iter);
4527 if (!header || !TNY_IS_HEADER(header)) {
4528 g_warning ("%s: header is not valid", __FUNCTION__);
4532 found = modest_window_mgr_find_registered_header (modest_runtime_get_window_mgr (),
4533 header, &msg_view_window);
4534 flags = tny_header_get_flags (header);
4535 if (!(flags & TNY_HEADER_FLAG_CACHED))
4538 if (msg_view_window != NULL)
4539 modest_msg_view_window_remove_attachments (MODEST_MSG_VIEW_WINDOW (msg_view_window), TRUE);
4541 /* do nothing; uid was registered before, so window is probably on it's way */
4542 g_warning ("debug: header %p has already been registered", header);
4545 ModestMailOperation *mail_op = NULL;
4546 modest_window_mgr_register_header (modest_runtime_get_window_mgr (), header, NULL);
4547 mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT (win),
4548 modest_ui_actions_get_msgs_full_error_handler,
4550 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
4551 modest_mail_operation_get_msg (mail_op, header, open_msg_for_purge_cb, win);
4553 g_object_unref (mail_op);
4556 g_object_unref (header);
4558 g_object_unref (header_list);
4562 * Utility function that transfer messages from both the main window
4563 * and the msg view window when using the "Move to" dialog
4566 xfer_messages_from_move_to_cb (gboolean canceled, GError *err,
4567 GtkWindow *parent_window,
4568 TnyAccount *account, gpointer user_data)
4570 TnyFolderStore *dst_folder = TNY_FOLDER_STORE (user_data);
4571 ModestWindow *win = MODEST_WINDOW (parent_window);
4572 TnyList *headers = NULL;
4573 TnyAccount *dst_account = NULL;
4574 const gchar *proto_str = NULL;
4575 gboolean dst_is_pop = FALSE;
4577 if (canceled || err) {
4578 g_object_unref (dst_folder);
4582 dst_account = tny_folder_get_account (TNY_FOLDER (dst_folder));
4583 proto_str = tny_account_get_proto (dst_account);
4585 /* tinymail will return NULL for local folders it seems */
4586 dst_is_pop = proto_str &&
4587 (modest_protocol_info_get_transport_store_protocol (proto_str) ==
4588 MODEST_PROTOCOL_STORE_POP);
4590 g_object_unref (dst_account);
4592 /* Get selected headers */
4593 headers = get_selected_headers (MODEST_WINDOW (win));
4595 g_warning ("%s: no headers selected", __FUNCTION__);
4601 modest_platform_information_banner (GTK_WIDGET (win),
4603 ngettext("mail_in_ui_folder_move_target_error",
4604 "mail_in_ui_folder_move_targets_error",
4605 tny_list_get_length (headers)));
4606 g_object_unref (headers);
4610 MoveToHelper *helper = g_new0 (MoveToHelper, 1);
4611 helper->banner = modest_platform_animation_banner (GTK_WIDGET (win), NULL,
4612 _CS("ckct_nw_pasting"));
4613 if (helper->banner != NULL) {
4614 gtk_window_set_modal (GTK_WINDOW(helper->banner), FALSE);
4615 gtk_widget_show (GTK_WIDGET(helper->banner));
4618 if (MODEST_IS_MAIN_WINDOW (win)) {
4619 GtkWidget *header_view =
4620 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
4621 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
4622 helper->reference = get_next_after_selected_headers (MODEST_HEADER_VIEW (header_view));
4625 ModestMailOperation *mail_op =
4626 modest_mail_operation_new_with_error_handling (G_OBJECT(win),
4627 modest_ui_actions_move_folder_error_handler,
4629 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
4632 modest_mail_operation_xfer_msgs (mail_op,
4634 TNY_FOLDER (dst_folder),
4639 g_object_unref (G_OBJECT (mail_op));
4640 g_object_unref (headers);
4641 g_object_unref (dst_folder);
4645 TnyAccount *dst_account;
4646 ModestConnectedPerformer callback;
4648 } DoubleConnectionInfo;
4651 src_account_connect_performer (gboolean canceled,
4653 GtkWindow *parent_window,
4654 TnyAccount *src_account,
4657 DoubleConnectionInfo *info = (DoubleConnectionInfo *) user_data;
4659 if (canceled || err) {
4660 /* If there was any error call the user callback */
4661 info->callback (canceled, err, parent_window, src_account, info->data);
4663 /* Connect the destination account */
4664 modest_platform_connect_if_remote_and_perform (parent_window, TRUE,
4665 TNY_FOLDER_STORE (info->dst_account),
4666 info->callback, info->data);
4669 /* Free the info object */
4670 g_object_unref (info->dst_account);
4671 g_slice_free (DoubleConnectionInfo, info);
4675 TnyFolder *src_folder;
4676 TnyFolderStore *dst_folder;
4677 gboolean delete_original;
4678 GtkWidget *folder_view;
4682 on_move_folder_cb (gboolean canceled, GError *err, GtkWindow *parent_window,
4683 TnyAccount *account, gpointer user_data)
4685 MoveFolderInfo *info = (MoveFolderInfo*)user_data;
4686 GtkTreeSelection *sel;
4687 ModestMailOperation *mail_op = NULL;
4689 if (canceled || err || !MODEST_IS_MAIN_WINDOW (parent_window)) {
4690 g_object_unref (G_OBJECT (info->src_folder));
4691 g_object_unref (G_OBJECT (info->dst_folder));
4696 MoveToHelper *helper = g_new0 (MoveToHelper, 1);
4697 helper->banner = modest_platform_animation_banner (GTK_WIDGET (parent_window), NULL,
4698 _CS("ckct_nw_pasting"));
4699 if (helper->banner != NULL) {
4700 gtk_window_set_modal (GTK_WINDOW(helper->banner), FALSE);
4701 gtk_widget_show (GTK_WIDGET(helper->banner));
4703 /* Clean folder on header view before moving it */
4704 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (info->folder_view));
4705 gtk_tree_selection_unselect_all (sel);
4707 /* Let gtk events run. We need that the folder
4708 view frees its reference to the source
4709 folder *before* issuing the mail operation
4710 so we need the signal handler of selection
4711 changed to happen before the mail
4713 while (gtk_events_pending ())
4714 gtk_main_iteration (); */
4717 modest_mail_operation_new_with_error_handling (G_OBJECT(parent_window),
4718 modest_ui_actions_move_folder_error_handler,
4719 info->src_folder, NULL);
4720 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
4723 /* Select *after* the changes */
4724 /* TODO: this function hangs UI after transfer */
4725 /* modest_folder_view_select_folder (MODEST_FOLDER_VIEW(folder_view), */
4726 /* TNY_FOLDER (src_folder), TRUE); */
4728 modest_mail_operation_xfer_folder (mail_op,
4729 TNY_FOLDER (info->src_folder),
4731 info->delete_original,
4735 if (modest_mail_operation_get_status (mail_op) == MODEST_MAIL_OPERATION_STATUS_SUCCESS) {
4736 modest_folder_view_select_folder (MODEST_FOLDER_VIEW(info->folder_view),
4737 TNY_FOLDER (info->dst_folder), TRUE);
4740 /* Unref mail operation */
4741 g_object_unref (G_OBJECT (mail_op));
4742 g_object_unref (G_OBJECT (info->src_folder));
4743 g_object_unref (G_OBJECT (info->dst_folder));
4748 * UI handler for the "Move to" action when invoked from the
4752 modest_ui_actions_on_main_window_move_to (GtkAction *action,
4753 GtkWidget *folder_view,
4754 TnyFolderStore *dst_folder,
4755 ModestMainWindow *win)
4757 ModestHeaderView *header_view = NULL;
4758 TnyFolderStore *src_folder;
4759 gboolean online = (tny_device_is_online (modest_runtime_get_device()));
4761 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win));
4763 /* Get the source folder */
4764 src_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
4766 /* Get header view */
4767 header_view = MODEST_HEADER_VIEW(modest_main_window_get_child_widget (win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW));
4769 /* Get folder or messages to transfer */
4770 if (gtk_widget_is_focus (folder_view)) {
4771 gboolean do_xfer = TRUE;
4773 /* Allow only to transfer folders to the local root folder */
4774 if (TNY_IS_ACCOUNT (dst_folder) &&
4775 !MODEST_IS_TNY_LOCAL_FOLDERS_ACCOUNT (dst_folder)) {
4777 } else if (!TNY_IS_FOLDER (src_folder)) {
4778 g_warning ("%s: src_folder is not a TnyFolder.\n", __FUNCTION__);
4780 } /* else if (!online && modest_tny_folder_store_is_remote(src_folder)) {
4781 guint num_headers = tny_folder_get_all_count(TNY_FOLDER (src_folder));
4782 TnyAccount *account = tny_folder_get_account (TNY_FOLDER (src_folder));
4783 if (!connect_to_get_msg(MODEST_WINDOW (win), num_headers, account))
4785 g_object_unref (account);
4789 MoveFolderInfo *info = g_new0 (MoveFolderInfo, 1);
4790 info->src_folder = TNY_FOLDER (src_folder);
4791 info->dst_folder = dst_folder;
4792 info->delete_original = TRUE;
4793 info->folder_view = folder_view;
4794 g_object_ref (G_OBJECT (info->src_folder));
4795 g_object_ref (G_OBJECT (info->dst_folder));
4796 modest_platform_connect_if_remote_and_perform(GTK_WINDOW (win), TRUE,
4797 TNY_FOLDER_STORE (dst_folder), on_move_folder_cb, info);
4799 } else if (gtk_widget_is_focus (GTK_WIDGET(header_view))) {
4800 gboolean do_xfer = TRUE;
4802 /* Show an error when trying to move msgs to an account */
4803 if (!TNY_IS_FOLDER (dst_folder)) {
4804 modest_platform_information_banner (GTK_WIDGET (win),
4806 _CS("ckdg_ib_unable_to_move_to_current_location"));
4810 /* Ask for confirmation if the source folder is remote and we're not connected */
4811 if (!online && modest_tny_folder_store_is_remote(src_folder)) {
4812 TnyList *headers = modest_header_view_get_selected_headers(header_view);
4813 if (!msgs_already_deleted_from_server(headers, src_folder)) {
4814 guint num_headers = tny_list_get_length(headers);
4815 TnyAccount *account = get_account_from_header_list (headers);
4816 GtkResponseType response;
4818 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
4819 ngettext("mcen_nc_get_msg",
4822 if (response == GTK_RESPONSE_CANCEL)
4825 g_object_unref (account);
4827 g_object_unref(headers);
4829 if (do_xfer) /* Transfer messages */ {
4830 DoubleConnectionInfo *info = g_slice_new (DoubleConnectionInfo);
4831 info->callback = xfer_messages_from_move_to_cb;
4832 info->dst_account = tny_folder_get_account (TNY_FOLDER (dst_folder));
4833 info->data = g_object_ref (dst_folder);
4835 modest_platform_connect_if_remote_and_perform(GTK_WINDOW (win), TRUE,
4836 TNY_FOLDER_STORE (src_folder),
4837 src_account_connect_performer,
4844 g_object_unref (src_folder);
4849 * UI handler for the "Move to" action when invoked from the
4850 * ModestMsgViewWindow
4853 modest_ui_actions_on_msg_view_window_move_to (GtkAction *action,
4854 TnyFolderStore *dst_folder,
4855 ModestMsgViewWindow *win)
4857 TnyHeader *header = NULL;
4858 TnyFolder *src_folder = NULL;
4859 TnyAccount *account = NULL;
4860 gboolean do_xfer = FALSE;
4862 /* Create header list */
4863 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
4864 src_folder = TNY_FOLDER (tny_header_get_folder(header));
4865 g_object_unref (header);
4867 account = tny_folder_get_account (src_folder);
4868 if (!modest_tny_folder_store_is_remote(TNY_FOLDER_STORE(src_folder))) {
4869 /* Transfer if the source folder is local */
4871 } else if (remote_folder_is_pop(TNY_FOLDER_STORE(src_folder))) {
4872 /* Transfer if the source folder is POP (as it means
4873 * that the message is already downloaded) */
4875 } else if (connect_to_get_msg(MODEST_WINDOW(win), 1, account)) {
4876 /* Transfer after asking confirmation */
4881 g_object_ref (dst_folder);
4882 modest_platform_connect_if_remote_and_perform(GTK_WINDOW (win), TRUE,
4883 TNY_FOLDER_STORE (dst_folder), xfer_messages_from_move_to_cb, dst_folder);
4885 g_object_unref (account);
4886 g_object_unref (src_folder);
4890 modest_ui_actions_on_move_to (GtkAction *action,
4893 GtkWidget *dialog = NULL, *folder_view = NULL, *tree_view = NULL;
4895 TnyFolderStore *dst_folder = NULL;
4896 ModestMainWindow *main_window;
4898 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win) ||
4899 MODEST_IS_MSG_VIEW_WINDOW (win));
4901 /* Get the main window if exists */
4902 if (MODEST_IS_MAIN_WINDOW (win))
4903 main_window = MODEST_MAIN_WINDOW (win);
4906 MODEST_MAIN_WINDOW (modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (),
4907 FALSE)); /* don't create */
4909 /* Get the folder view widget if exists */
4911 folder_view = modest_main_window_get_child_widget (main_window,
4912 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
4916 /* Create and run the dialog */
4917 dialog = create_move_to_dialog (GTK_WINDOW (win), folder_view, &tree_view);
4918 modest_folder_view_select_first_inbox_or_local (MODEST_FOLDER_VIEW (tree_view));
4919 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
4920 result = gtk_dialog_run (GTK_DIALOG(dialog));
4921 g_object_ref (tree_view);
4922 gtk_widget_destroy (dialog);
4924 if (result != GTK_RESPONSE_ACCEPT)
4927 dst_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (tree_view));
4928 /* Do window specific stuff */
4929 if (MODEST_IS_MAIN_WINDOW (win)) {
4930 modest_ui_actions_on_main_window_move_to (action,
4933 MODEST_MAIN_WINDOW (win));
4935 modest_ui_actions_on_msg_view_window_move_to (action,
4937 MODEST_MSG_VIEW_WINDOW (win));
4941 g_object_unref (dst_folder);
4945 * Calls #HeadersFunc for each header already selected in the main
4946 * window or the message currently being shown in the msg view window
4949 do_headers_action (ModestWindow *win,
4953 TnyList *headers_list = NULL;
4954 TnyIterator *iter = NULL;
4955 TnyHeader *header = NULL;
4956 TnyFolder *folder = NULL;
4959 headers_list = get_selected_headers (win);
4963 /* Get the folder */
4964 iter = tny_list_create_iterator (headers_list);
4965 header = TNY_HEADER (tny_iterator_get_current (iter));
4967 folder = tny_header_get_folder (header);
4968 g_object_unref (header);
4971 /* Call the function for each header */
4972 while (!tny_iterator_is_done (iter)) {
4973 header = TNY_HEADER (tny_iterator_get_current (iter));
4974 func (header, win, user_data);
4975 g_object_unref (header);
4976 tny_iterator_next (iter);
4979 /* Trick: do a poke status in order to speed up the signaling
4981 tny_folder_poke_status (folder);
4984 g_object_unref (folder);
4985 g_object_unref (iter);
4986 g_object_unref (headers_list);
4990 modest_ui_actions_view_attachment (GtkAction *action,
4991 ModestWindow *window)
4993 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
4994 modest_msg_view_window_view_attachment (MODEST_MSG_VIEW_WINDOW (window), NULL);
4996 /* not supported window for this action */
4997 g_return_if_reached ();
5002 modest_ui_actions_save_attachments (GtkAction *action,
5003 ModestWindow *window)
5005 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
5006 modest_msg_view_window_save_attachments (MODEST_MSG_VIEW_WINDOW (window), NULL);
5008 /* not supported window for this action */
5009 g_return_if_reached ();
5014 modest_ui_actions_remove_attachments (GtkAction *action,
5015 ModestWindow *window)
5017 if (MODEST_IS_MAIN_WINDOW (window)) {
5018 modest_ui_actions_on_main_window_remove_attachments (action, MODEST_MAIN_WINDOW (window));
5019 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
5020 modest_msg_view_window_remove_attachments (MODEST_MSG_VIEW_WINDOW (window), FALSE);
5022 /* not supported window for this action */
5023 g_return_if_reached ();
5028 modest_ui_actions_on_settings (GtkAction *action,
5033 dialog = modest_platform_get_global_settings_dialog ();
5034 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (win));
5035 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
5036 gtk_widget_show_all (dialog);
5038 gtk_dialog_run (GTK_DIALOG (dialog));
5040 gtk_widget_destroy (dialog);
5044 modest_ui_actions_on_help (GtkAction *action,
5047 const gchar *help_id;
5049 g_return_if_fail (action);
5050 g_return_if_fail (win && GTK_IS_WINDOW(win));
5052 help_id = modest_window_mgr_get_help_id (modest_runtime_get_window_mgr(), win);
5055 modest_platform_show_help (GTK_WINDOW (win), help_id);
5057 g_warning ("%s: no help for window %p", __FUNCTION__, win);
5061 retrieve_msg_contents_performer (gboolean canceled,
5063 GtkWindow *parent_window,
5064 TnyAccount *account,
5067 ModestMailOperation *mail_op;
5068 TnyList *headers = TNY_LIST (user_data);
5070 if (err || canceled) {
5074 /* Create mail operation */
5075 mail_op = modest_mail_operation_new_with_error_handling ((GObject *) parent_window,
5076 modest_ui_actions_get_msgs_full_error_handler,
5078 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
5079 modest_mail_operation_get_msgs_full (mail_op, headers, NULL, NULL, NULL);
5082 g_object_unref (mail_op);
5084 g_object_unref (headers);
5085 g_object_unref (account);
5089 modest_ui_actions_on_retrieve_msg_contents (GtkAction *action,
5090 ModestWindow *window)
5092 TnyList *headers = NULL;
5093 TnyAccount *account = NULL;
5094 TnyIterator *iter = NULL;
5095 TnyHeader *header = NULL;
5096 TnyFolder *folder = NULL;
5099 headers = get_selected_headers (window);
5103 /* Pick the account */
5104 iter = tny_list_create_iterator (headers);
5105 header = TNY_HEADER (tny_iterator_get_current (iter));
5106 folder = tny_header_get_folder (header);
5107 account = tny_folder_get_account (folder);
5108 g_object_unref (folder);
5109 g_object_unref (header);
5110 g_object_unref (iter);
5112 /* Connect and perform the message retrieval */
5113 modest_platform_connect_and_perform ((GtkWindow *) window, TRUE,
5114 g_object_ref (account),
5115 retrieve_msg_contents_performer,
5116 g_object_ref (headers));
5119 g_object_unref (account);
5120 g_object_unref (headers);
5124 modest_ui_actions_check_toolbar_dimming_rules (ModestWindow *window)
5126 g_return_if_fail (MODEST_IS_WINDOW (window));
5129 modest_window_check_dimming_rules_group (window, MODEST_DIMMING_RULES_TOOLBAR);
5133 modest_ui_actions_check_menu_dimming_rules (ModestWindow *window)
5135 g_return_if_fail (MODEST_IS_WINDOW (window));
5138 modest_window_check_dimming_rules_group (window, MODEST_DIMMING_RULES_MENU);
5142 modest_ui_actions_on_email_menu_activated (GtkAction *action,
5143 ModestWindow *window)
5145 g_return_if_fail (MODEST_IS_WINDOW (window));
5148 modest_ui_actions_check_menu_dimming_rules (window);
5152 modest_ui_actions_on_edit_menu_activated (GtkAction *action,
5153 ModestWindow *window)
5155 g_return_if_fail (MODEST_IS_WINDOW (window));
5158 modest_ui_actions_check_menu_dimming_rules (window);
5162 modest_ui_actions_on_view_menu_activated (GtkAction *action,
5163 ModestWindow *window)
5165 g_return_if_fail (MODEST_IS_WINDOW (window));
5168 modest_ui_actions_check_menu_dimming_rules (window);
5172 modest_ui_actions_on_format_menu_activated (GtkAction *action,
5173 ModestWindow *window)
5175 g_return_if_fail (MODEST_IS_WINDOW (window));
5178 modest_ui_actions_check_menu_dimming_rules (window);
5182 modest_ui_actions_on_tools_menu_activated (GtkAction *action,
5183 ModestWindow *window)
5185 g_return_if_fail (MODEST_IS_WINDOW (window));
5188 modest_ui_actions_check_menu_dimming_rules (window);
5192 modest_ui_actions_on_attachment_menu_activated (GtkAction *action,
5193 ModestWindow *window)
5195 g_return_if_fail (MODEST_IS_WINDOW (window));
5198 modest_ui_actions_check_menu_dimming_rules (window);
5202 modest_ui_actions_on_toolbar_csm_menu_activated (GtkAction *action,
5203 ModestWindow *window)
5205 g_return_if_fail (MODEST_IS_WINDOW (window));
5208 modest_ui_actions_check_menu_dimming_rules (window);
5212 modest_ui_actions_on_folder_view_csm_menu_activated (GtkAction *action,
5213 ModestWindow *window)
5215 g_return_if_fail (MODEST_IS_WINDOW (window));
5218 modest_ui_actions_check_menu_dimming_rules (window);
5222 modest_ui_actions_on_header_view_csm_menu_activated (GtkAction *action,
5223 ModestWindow *window)
5225 g_return_if_fail (MODEST_IS_WINDOW (window));
5228 modest_ui_actions_check_menu_dimming_rules (window);
5232 modest_ui_actions_on_search_messages (GtkAction *action, ModestWindow *window)
5234 g_return_if_fail (MODEST_IS_WINDOW (window));
5236 modest_platform_show_search_messages (GTK_WINDOW (window));
5240 modest_ui_actions_on_open_addressbook (GtkAction *action, ModestWindow *win)
5242 g_return_if_fail (MODEST_IS_WINDOW (win));
5243 modest_platform_show_addressbook (GTK_WINDOW (win));
5248 modest_ui_actions_on_toggle_find_in_page (GtkToggleAction *action,
5249 ModestWindow *window)
5251 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
5253 modest_msg_edit_window_toggle_find_toolbar (MODEST_MSG_EDIT_WINDOW (window), gtk_toggle_action_get_active (action));
5257 on_send_receive_finished (ModestMailOperation *mail_op,
5260 GtkWidget *header_view, *folder_view;
5261 TnyFolderStore *folder_store;
5262 ModestMainWindow *main_win = MODEST_MAIN_WINDOW (user_data);
5264 /* Set send/receive operation finished */
5265 modest_main_window_notify_send_receive_completed (main_win);
5267 /* Don't refresh the current folder if there were any errors */
5268 if (modest_mail_operation_get_status (mail_op) !=
5269 MODEST_MAIL_OPERATION_STATUS_SUCCESS)
5272 /* Refresh the current folder if we're viewing a window. We do
5273 this because the user won't be able to see the new mails in
5274 the selected folder after a Send&Receive because it only
5275 performs a poke_status, i.e, only the number of read/unread
5276 messages is updated, but the new headers are not
5278 folder_view = modest_main_window_get_child_widget (main_win,
5279 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
5283 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
5285 /* Do not need to refresh INBOX again because the
5286 update_account does it always automatically */
5287 if (folder_store && TNY_IS_FOLDER (folder_store) &&
5288 tny_folder_get_folder_type (TNY_FOLDER (folder_store)) != TNY_FOLDER_TYPE_INBOX) {
5289 ModestMailOperation *refresh_op;
5291 header_view = modest_main_window_get_child_widget (main_win,
5292 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
5294 /* We do not need to set the contents style
5295 because it hasn't changed. We also do not
5296 need to save the widget status. Just force
5298 refresh_op = modest_mail_operation_new (G_OBJECT (main_win));
5299 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), refresh_op);
5300 modest_mail_operation_refresh_folder (refresh_op, TNY_FOLDER (folder_store),
5301 folder_refreshed_cb, main_win);
5302 g_object_unref (refresh_op);
5306 g_object_unref (folder_store);
5311 modest_ui_actions_on_send_queue_error_happened (TnySendQueue *self,
5317 const gchar* server_name = NULL;
5318 TnyTransportAccount *server_account;
5319 gchar *message = NULL;
5321 /* Don't show anything if the user cancelled something */
5322 if (err->code == TNY_SYSTEM_ERROR_CANCEL)
5325 /* Get the server name: */
5327 TNY_TRANSPORT_ACCOUNT (tny_camel_send_queue_get_transport_account (TNY_CAMEL_SEND_QUEUE (self)));
5328 if (server_account) {
5329 server_name = tny_account_get_hostname (TNY_ACCOUNT (server_account));
5331 g_object_unref (server_account);
5332 server_account = NULL;
5335 g_return_if_fail (server_name);
5337 /* Show the appropriate message text for the GError: */
5338 switch (err->code) {
5339 case TNY_SERVICE_ERROR_CONNECT:
5340 message = g_strdup_printf (_("emev_ib_ui_smtp_server_invalid"), server_name);
5342 case TNY_SERVICE_ERROR_AUTHENTICATE:
5343 message = g_strdup_printf (_("emev_ni_ui_smtp_authentication_fail_error"), server_name);
5345 case TNY_SERVICE_ERROR_SEND:
5346 message = g_strdup (_("emev_ib_ui_smtp_send_error"));
5349 g_warning ("%s: unexpected ERROR %d",
5350 __FUNCTION__, err->code);
5351 message = g_strdup (_("emev_ib_ui_smtp_send_error"));
5355 /* TODO if the username or the password where not defined we
5356 should show the Accounts Settings dialog or the Connection
5357 specific SMTP server window */
5359 modest_platform_run_information_dialog (NULL, message);
5364 modest_ui_actions_on_send_queue_status_changed (ModestTnySendQueue *send_queue,
5369 ModestMainWindow *main_window = NULL;
5370 ModestWindowMgr *mgr = NULL;
5371 GtkWidget *folder_view = NULL, *header_view = NULL;
5372 TnyFolderStore *selected_folder = NULL;
5373 TnyFolderType folder_type;
5375 mgr = modest_runtime_get_window_mgr ();
5376 main_window = MODEST_MAIN_WINDOW (modest_window_mgr_get_main_window (mgr,
5377 FALSE));/* don't create */
5381 /* Check if selected folder is OUTBOX */
5382 folder_view = modest_main_window_get_child_widget (main_window,
5383 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
5384 header_view = modest_main_window_get_child_widget (main_window,
5385 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
5387 selected_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
5388 if (!TNY_IS_FOLDER (selected_folder))
5391 /* gtk_tree_view_column_queue_resize is only available in GTK+ 2.8 */
5392 #if GTK_CHECK_VERSION(2, 8, 0)
5393 folder_type = modest_tny_folder_guess_folder_type (TNY_FOLDER (selected_folder));
5394 if (folder_type == TNY_FOLDER_TYPE_OUTBOX) {
5395 GtkTreeViewColumn *tree_column;
5397 tree_column = gtk_tree_view_get_column (GTK_TREE_VIEW (header_view),
5398 TNY_GTK_HEADER_LIST_MODEL_FROM_COLUMN);
5399 gtk_tree_view_column_queue_resize (tree_column);
5402 gtk_widget_queue_draw (header_view);
5405 /* Rerun dimming rules, because the message could become deletable for example */
5406 modest_window_check_dimming_rules_group (MODEST_WINDOW (main_window),
5407 MODEST_DIMMING_RULES_TOOLBAR);
5411 if (selected_folder != NULL)
5412 g_object_unref (selected_folder);
5416 modest_ui_actions_on_account_connection_error (GtkWindow *parent_window,
5417 TnyAccount *account)
5419 ModestTransportStoreProtocol proto;
5420 const gchar *proto_name;
5421 gchar *error_note = NULL;
5423 proto_name = tny_account_get_proto (account);
5424 proto = modest_protocol_info_get_transport_store_protocol (proto_name);
5427 case MODEST_PROTOCOL_STORE_POP:
5428 error_note = g_strdup_printf (_("emev_ni_ui_pop3_msg_connect_error"),
5429 tny_account_get_hostname (account));
5431 case MODEST_PROTOCOL_STORE_IMAP:
5432 error_note = g_strdup_printf (_("emev_ni_ui_imap_connect_server_error"),
5433 tny_account_get_hostname (account));
5435 case MODEST_PROTOCOL_STORE_MAILDIR:
5436 case MODEST_PROTOCOL_STORE_MBOX:
5437 error_note = g_strdup (_("emev_nc_mailbox_notavailable"));
5440 g_warning ("%s: This should not be reached", __FUNCTION__);
5444 modest_platform_run_information_dialog (parent_window, error_note);
5445 g_free (error_note);