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);
167 * This function checks whether a TnyFolderStore is a pop account
170 remote_folder_is_pop (const TnyFolderStore *folder)
172 const gchar *proto = NULL;
173 TnyAccount *account = NULL;
175 g_return_val_if_fail (TNY_IS_FOLDER_STORE(folder), FALSE);
177 if (TNY_IS_ACCOUNT (folder)) {
178 account = TNY_ACCOUNT(folder);
179 g_object_ref(account);
180 } else if (TNY_IS_FOLDER (folder)) {
181 account = tny_folder_get_account(TNY_FOLDER(folder));
184 if (!account && !TNY_IS_ACCOUNT(account)) {
185 g_warning ("%s: could not get account", __FUNCTION__);
189 proto = tny_account_get_proto(account);
190 g_object_unref (account);
193 (modest_protocol_info_get_transport_store_protocol (proto) == MODEST_PROTOCOL_STORE_POP);
197 * This functions checks whether if a list of messages are already
198 * deleted from the server: that is, if the server is a POP account
199 * and all messages are already cached.
202 msgs_already_deleted_from_server (TnyList *headers, const TnyFolderStore *src_folder)
204 g_return_val_if_fail (TNY_IS_FOLDER_STORE(src_folder), FALSE);
205 g_return_val_if_fail (TNY_IS_LIST(headers), FALSE);
207 gboolean src_is_pop = remote_folder_is_pop (src_folder);
208 gint uncached_msgs = header_list_count_uncached_msgs (headers);
210 return (src_is_pop && !uncached_msgs);
214 /* FIXME: this should be merged with the similar code in modest-account-view-window */
215 /* Show the account creation wizard dialog.
216 * returns: TRUE if an account was created. FALSE if the user cancelled.
219 modest_ui_actions_run_account_setup_wizard (ModestWindow *win)
221 gboolean result = FALSE;
222 GtkWindow *dialog, *wizard;
223 gint dialog_response;
225 /* Show the easy-setup wizard: */
226 dialog = modest_window_mgr_get_modal (modest_runtime_get_window_mgr());
228 /* old wizard is active already;
230 gtk_window_present (GTK_WINDOW(dialog));
235 /* there is no such wizard yet */
236 wizard = GTK_WINDOW (modest_platform_get_account_settings_wizard ());
237 modest_window_mgr_set_modal (modest_runtime_get_window_mgr(), wizard);
239 /* always present a main window in the background
240 * we do it here, so we cannot end up with two wizards (as this
241 * function might be called in modest_window_mgr_get_main_window as well */
243 win = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr(),
244 TRUE); /* create if not existent */
246 /* make sure the mainwindow is visible */
247 gtk_window_set_transient_for (GTK_WINDOW (wizard), GTK_WINDOW (win));
248 gtk_widget_show_all (GTK_WIDGET(win));
249 gtk_window_present (GTK_WINDOW(win));
251 dialog_response = gtk_dialog_run (GTK_DIALOG (wizard));
252 gtk_widget_destroy (GTK_WIDGET (wizard));
253 if (gtk_events_pending ())
254 gtk_main_iteration ();
256 if (dialog_response == GTK_RESPONSE_CANCEL) {
259 /* Check whether an account was created: */
260 result = modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
267 modest_ui_actions_on_about (GtkAction *action, ModestWindow *win)
270 const gchar *authors[] = {
271 "Dirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>",
274 about = gtk_about_dialog_new ();
275 gtk_about_dialog_set_name (GTK_ABOUT_DIALOG(about), PACKAGE_NAME);
276 gtk_about_dialog_set_version (GTK_ABOUT_DIALOG(about),PACKAGE_VERSION);
277 gtk_about_dialog_set_copyright (GTK_ABOUT_DIALOG(about),
278 _("Copyright (c) 2006, Nokia Corporation\n"
279 "All rights reserved."));
280 gtk_about_dialog_set_comments (GTK_ABOUT_DIALOG(about),
281 _("a modest e-mail client\n\n"
282 "design and implementation: Dirk-Jan C. Binnema\n"
283 "contributions from the fine people at KC and Ig\n"
284 "uses the tinymail email framework written by Philip van Hoof"));
285 gtk_about_dialog_set_authors (GTK_ABOUT_DIALOG(about), authors);
286 gtk_about_dialog_set_website (GTK_ABOUT_DIALOG(about), "http://modest.garage.maemo.org");
287 gtk_window_set_transient_for (GTK_WINDOW (about), GTK_WINDOW (win));
288 gtk_window_set_modal (GTK_WINDOW (about), TRUE);
290 gtk_dialog_run (GTK_DIALOG (about));
291 gtk_widget_destroy(about);
295 * Gets the list of currently selected messages. If the win is the
296 * main window, then it returns a newly allocated list of the headers
297 * selected in the header view. If win is the msg view window, then
298 * the value returned is a list with just a single header.
300 * The caller of this funcion must free the list.
303 get_selected_headers (ModestWindow *win)
305 if (MODEST_IS_MAIN_WINDOW(win)) {
306 GtkWidget *header_view;
308 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
309 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
310 return modest_header_view_get_selected_headers (MODEST_HEADER_VIEW(header_view));
312 } else if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
313 /* for MsgViewWindows, we simply return a list with one element */
315 TnyList *list = NULL;
317 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
318 if (header != NULL) {
319 list = tny_simple_list_new ();
320 tny_list_prepend (list, G_OBJECT(header));
321 g_object_unref (G_OBJECT(header));
330 static GtkTreeRowReference *
331 get_next_after_selected_headers (ModestHeaderView *header_view)
333 GtkTreeSelection *sel;
334 GList *selected_rows, *node;
336 GtkTreeRowReference *result;
339 model = gtk_tree_view_get_model (GTK_TREE_VIEW (header_view));
340 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
341 selected_rows = gtk_tree_selection_get_selected_rows (sel, NULL);
343 if (selected_rows == NULL)
346 node = g_list_last (selected_rows);
347 path = gtk_tree_path_copy ((GtkTreePath *) node->data);
348 gtk_tree_path_next (path);
350 result = gtk_tree_row_reference_new (model, path);
352 gtk_tree_path_free (path);
353 g_list_foreach (selected_rows, (GFunc) gtk_tree_path_free, NULL);
354 g_list_free (selected_rows);
360 headers_action_mark_as_read (TnyHeader *header,
364 TnyHeaderFlags flags;
366 g_return_if_fail (TNY_IS_HEADER(header));
368 flags = tny_header_get_flags (header);
369 if (flags & TNY_HEADER_FLAG_SEEN) return;
370 tny_header_set_flag (header, TNY_HEADER_FLAG_SEEN);
374 headers_action_mark_as_unread (TnyHeader *header,
378 TnyHeaderFlags flags;
380 g_return_if_fail (TNY_IS_HEADER(header));
382 flags = tny_header_get_flags (header);
383 if (flags & TNY_HEADER_FLAG_SEEN) {
384 tny_header_unset_flag (header, TNY_HEADER_FLAG_SEEN);
388 /** After deleing a message that is currently visible in a window,
389 * show the next message from the list, or close the window if there are no more messages.
392 modest_ui_actions_refresh_message_window_after_delete (ModestMsgViewWindow* win)
394 /* Close msg view window or select next */
395 if (modest_msg_view_window_last_message_selected (win) &&
396 modest_msg_view_window_first_message_selected (win)) {
397 modest_ui_actions_on_close_window (NULL, MODEST_WINDOW (win));
398 } else if (!modest_msg_view_window_select_next_message (win)) {
400 g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value);
406 modest_ui_actions_on_delete_message (GtkAction *action, ModestWindow *win)
408 TnyList *header_list = NULL;
409 TnyIterator *iter = NULL;
410 TnyHeader *header = NULL;
411 gchar *message = NULL;
414 ModestWindowMgr *mgr;
415 GtkWidget *header_view = NULL;
417 g_return_if_fail (MODEST_IS_WINDOW(win));
419 /* Check first if the header view has the focus */
420 if (MODEST_IS_MAIN_WINDOW (win)) {
422 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
423 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
424 if (!gtk_widget_is_focus (header_view))
428 /* Get the headers, either from the header view (if win is the main window),
429 * or from the message view window: */
430 header_list = get_selected_headers (win);
431 if (!header_list) return;
433 /* Check if any of the headers are already opened, or in the process of being opened */
434 if (MODEST_IS_MAIN_WINDOW (win)) {
435 gint opened_headers = 0;
437 iter = tny_list_create_iterator (header_list);
438 mgr = modest_runtime_get_window_mgr ();
439 while (!tny_iterator_is_done (iter)) {
440 header = TNY_HEADER (tny_iterator_get_current (iter));
442 if (modest_window_mgr_find_registered_header (mgr, header, NULL))
444 g_object_unref (header);
446 tny_iterator_next (iter);
448 g_object_unref (iter);
450 if (opened_headers > 0) {
453 msg = g_strdup_printf (_("mcen_nc_unable_to_delete_n_messages"),
456 modest_platform_run_information_dialog (GTK_WINDOW (win), (const gchar *) msg);
459 g_object_unref (header_list);
465 if (tny_list_get_length(header_list) == 1) {
466 iter = tny_list_create_iterator (header_list);
467 header = TNY_HEADER (tny_iterator_get_current (iter));
469 desc = g_strdup_printf ("%s", tny_header_get_subject (header));
470 g_object_unref (header);
473 g_object_unref (iter);
475 message = g_strdup_printf(ngettext("emev_nc_delete_message", "emev_nc_delete_messages",
476 tny_list_get_length(header_list)), desc);
478 /* Confirmation dialog */
479 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
483 if (response == GTK_RESPONSE_OK) {
484 ModestWindow *main_window = NULL;
485 ModestWindowMgr *mgr = NULL;
486 GtkTreeModel *model = NULL;
487 GtkTreeSelection *sel = NULL;
488 GList *sel_list = NULL, *tmp = NULL;
489 GtkTreeRowReference *next_row_reference = NULL;
490 GtkTreeRowReference *prev_row_reference = NULL;
491 GtkTreePath *next_path = NULL;
492 GtkTreePath *prev_path = NULL;
493 ModestMailOperation *mail_op = NULL;
495 /* Find last selected row */
496 if (MODEST_IS_MAIN_WINDOW (win)) {
497 model = gtk_tree_view_get_model (GTK_TREE_VIEW (header_view));
498 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
499 sel_list = gtk_tree_selection_get_selected_rows (sel, &model);
500 for (tmp=sel_list; tmp; tmp=tmp->next) {
501 if (tmp->next == NULL) {
502 prev_path = gtk_tree_path_copy((GtkTreePath *) tmp->data);
503 next_path = gtk_tree_path_copy((GtkTreePath *) tmp->data);
505 gtk_tree_path_prev (prev_path);
506 gtk_tree_path_next (next_path);
508 prev_row_reference = gtk_tree_row_reference_new (model, prev_path);
509 next_row_reference = gtk_tree_row_reference_new (model, next_path);
514 /* Disable window dimming management */
515 modest_window_disable_dimming (MODEST_WINDOW(win));
517 /* Remove each header. If it's a view window header_view == NULL */
518 mail_op = modest_mail_operation_new ((GObject *) win);
519 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
521 modest_mail_operation_remove_msgs (mail_op, header_list, FALSE);
522 g_object_unref (mail_op);
524 /* Enable window dimming management */
526 gtk_tree_selection_unselect_all (sel);
528 modest_window_enable_dimming (MODEST_WINDOW(win));
530 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
531 modest_ui_actions_refresh_message_window_after_delete (MODEST_MSG_VIEW_WINDOW (win));
533 /* Get main window */
534 mgr = modest_runtime_get_window_mgr ();
535 main_window = modest_window_mgr_get_main_window (mgr, FALSE); /* don't create */
537 /* Move cursor to next row */
540 /* Select next or previous row */
541 if (gtk_tree_row_reference_valid (next_row_reference)) {
542 /* next_path = gtk_tree_row_reference_get_path (row_reference); */
543 gtk_tree_selection_select_path (sel, next_path);
545 else if (gtk_tree_row_reference_valid (prev_row_reference)) {
546 gtk_tree_selection_select_path (sel, prev_path);
550 if (next_row_reference != NULL)
551 gtk_tree_row_reference_free (next_row_reference);
552 if (next_path != NULL)
553 gtk_tree_path_free (next_path);
554 if (prev_row_reference != NULL)
555 gtk_tree_row_reference_free (prev_row_reference);
556 if (prev_path != NULL)
557 gtk_tree_path_free (prev_path);
560 /* Update toolbar dimming state */
562 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
565 g_list_foreach (sel_list, (GFunc) gtk_tree_path_free, NULL);
566 g_list_free (sel_list);
572 g_object_unref (header_list);
578 /* delete either message or folder, based on where we are */
580 modest_ui_actions_on_delete_message_or_folder (GtkAction *action, ModestWindow *win)
582 g_return_if_fail (MODEST_IS_WINDOW(win));
584 /* Check first if the header view has the focus */
585 if (MODEST_IS_MAIN_WINDOW (win)) {
587 w = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
588 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
589 if (gtk_widget_is_focus (w)) {
590 modest_ui_actions_on_delete_folder (action, MODEST_MAIN_WINDOW(win));
594 modest_ui_actions_on_delete_message (action, win);
600 modest_ui_actions_on_quit (GtkAction *action, ModestWindow *win)
602 ModestWindowMgr *mgr = NULL;
604 #ifdef MODEST_PLATFORM_MAEMO
605 modest_osso_save_state();
606 #endif /* MODEST_PLATFORM_MAEMO */
608 g_debug ("closing down, clearing %d item(s) from operation queue",
609 modest_mail_operation_queue_num_elements
610 (modest_runtime_get_mail_operation_queue()));
612 /* cancel all outstanding operations */
613 modest_mail_operation_queue_cancel_all
614 (modest_runtime_get_mail_operation_queue());
616 g_debug ("queue has been cleared");
619 /* Check if there are opened editing windows */
620 mgr = modest_runtime_get_window_mgr ();
621 modest_window_mgr_close_all_windows (mgr);
623 /* note: when modest-tny-account-store is finalized,
624 it will automatically set all network connections
627 /* gtk_main_quit (); */
631 modest_ui_actions_on_close_window (GtkAction *action, ModestWindow *win)
635 g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value);
637 /* if (MODEST_IS_MSG_VIEW_WINDOW (win)) { */
638 /* gtk_widget_destroy (GTK_WIDGET (win)); */
639 /* } else if (MODEST_IS_MSG_EDIT_WINDOW (win)) { */
640 /* gboolean ret_value; */
641 /* g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value); */
642 /* } else if (MODEST_IS_WINDOW (win)) { */
643 /* gtk_widget_destroy (GTK_WIDGET (win)); */
645 /* g_return_if_reached (); */
650 modest_ui_actions_on_add_to_contacts (GtkAction *action, ModestWindow *win)
652 GtkClipboard *clipboard = NULL;
653 gchar *selection = NULL;
655 clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
656 selection = gtk_clipboard_wait_for_text (clipboard);
658 /* Question: why is the clipboard being used here?
659 * It doesn't really make a lot of sense. */
663 modest_address_book_add_address (selection);
669 modest_ui_actions_on_accounts (GtkAction *action,
672 /* This is currently only implemented for Maemo */
673 if (!modest_account_mgr_has_accounts (modest_runtime_get_account_mgr(), TRUE)) {
674 if (!modest_ui_actions_run_account_setup_wizard (win))
675 g_debug ("%s: wizard was already running", __FUNCTION__);
679 /* Show the list of accounts */
680 GtkWindow *account_win = GTK_WINDOW (modest_account_view_window_new ());
681 gtk_window_set_transient_for (account_win, GTK_WINDOW (win));
683 /* The accounts dialog must be modal */
684 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), account_win);
685 modest_utils_show_dialog_and_forget (GTK_WINDOW (win), GTK_DIALOG (account_win));
689 #ifdef MODEST_PLATFORM_MAEMO
691 on_smtp_servers_window_hide (GtkWindow* window, gpointer user_data)
693 /* Save any changes. */
694 modest_connection_specific_smtp_window_save_server_accounts (
695 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (window));
696 gtk_widget_destroy (GTK_WIDGET (window));
702 modest_ui_actions_on_smtp_servers (GtkAction *action, ModestWindow *win)
704 /* This is currently only implemented for Maemo,
705 * because it requires an API (libconic) to detect different connection
708 #ifdef MODEST_PLATFORM_MAEMO /* Defined in config.h */
710 /* Create the window if necessary: */
711 GtkWidget *specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
712 modest_connection_specific_smtp_window_fill_with_connections (
713 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (specific_window),
714 modest_runtime_get_account_mgr());
716 /* Show the window: */
717 gtk_window_set_transient_for (GTK_WINDOW (specific_window), GTK_WINDOW (win));
718 gtk_window_set_modal (GTK_WINDOW (specific_window), TRUE);
719 gtk_widget_show (specific_window);
721 /* Save changes when the window is hidden: */
722 g_signal_connect (specific_window, "hide",
723 G_CALLBACK (on_smtp_servers_window_hide), win);
724 #endif /* MODEST_PLATFORM_MAEMO */
728 modest_ui_actions_compose_msg(ModestWindow *win,
731 const gchar *bcc_str,
732 const gchar *subject_str,
733 const gchar *body_str,
736 gchar *account_name = NULL;
738 TnyAccount *account = NULL;
739 TnyFolder *folder = NULL;
740 gchar *from_str = NULL, *signature = NULL, *body = NULL;
741 gboolean use_signature = FALSE;
742 ModestWindow *msg_win = NULL;
743 ModestAccountMgr *mgr = modest_runtime_get_account_mgr();
744 ModestTnyAccountStore *store = modest_runtime_get_account_store();
746 if (win) account_name = g_strdup (modest_window_get_active_account (win));
747 if (!account_name) account_name = modest_account_mgr_get_default_account(mgr);
749 g_printerr ("modest: no account found\n");
752 account = modest_tny_account_store_get_server_account (store, account_name, TNY_ACCOUNT_TYPE_STORE);
754 g_printerr ("modest: failed to get tnyaccount for '%s'\n", account_name);
757 folder = modest_tny_account_get_special_folder (account, TNY_FOLDER_TYPE_DRAFTS);
759 g_printerr ("modest: failed to find Drafts folder\n");
762 from_str = modest_account_mgr_get_from_string (mgr, account_name);
764 g_printerr ("modest: failed get from string for '%s'\n", account_name);
768 signature = modest_account_mgr_get_signature (mgr, account_name, &use_signature);
769 if (body_str != NULL) {
770 body = use_signature ? g_strconcat(body_str, "\n", signature, NULL) : g_strdup(body_str);
772 body = use_signature ? g_strconcat("\n", signature, NULL) : g_strdup("");
775 msg = modest_tny_msg_new (to_str, from_str, cc_str, bcc_str, subject_str, body, NULL);
777 g_printerr ("modest: failed to create new msg\n");
781 /* Create and register edit window */
782 /* This is destroyed by TODO. */
783 msg_win = modest_msg_edit_window_new (msg, account_name, FALSE);
784 while (attachments) {
785 modest_msg_edit_window_attach_file_one((ModestMsgEditWindow *)msg_win,
787 attachments = g_slist_next(attachments);
789 modest_window_mgr_register_window (modest_runtime_get_window_mgr(), msg_win);
792 gtk_window_set_transient_for (GTK_WINDOW (msg_win),
795 gtk_widget_show_all (GTK_WIDGET (msg_win));
801 g_free (account_name);
802 if (account) g_object_unref (G_OBJECT(account));
803 if (folder) g_object_unref (G_OBJECT(folder));
804 if (msg_win) g_object_unref (G_OBJECT(msg_win));
805 if (msg) g_object_unref (G_OBJECT(msg));
809 modest_ui_actions_on_new_msg (GtkAction *action, ModestWindow *win)
811 /* if there are no accounts yet, just show the wizard */
812 if (!modest_account_mgr_has_accounts (modest_runtime_get_account_mgr(), TRUE))
813 if (!modest_ui_actions_run_account_setup_wizard (win))
816 modest_ui_actions_compose_msg(win, NULL, NULL, NULL, NULL, NULL, NULL);
820 modest_ui_actions_msg_retrieval_check (ModestMailOperation *mail_op,
824 ModestMailOperationStatus status;
826 /* If there is no message or the operation was not successful */
827 status = modest_mail_operation_get_status (mail_op);
828 if (!msg || status != MODEST_MAIL_OPERATION_STATUS_SUCCESS) {
830 /* Remove the header from the preregistered uids */
831 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (),
841 open_msg_cb (ModestMailOperation *mail_op,
848 ModestWindowMgr *mgr = NULL;
849 ModestWindow *parent_win = NULL;
850 ModestWindow *win = NULL;
851 TnyFolderType folder_type = TNY_FOLDER_TYPE_UNKNOWN;
852 gchar *account = NULL;
854 gboolean open_in_editor = FALSE;
856 /* Do nothing if there was any problem with the mail
857 operation. The error will be shown by the error_handler of
858 the mail operation */
859 if (!modest_ui_actions_msg_retrieval_check (mail_op, header, msg))
862 parent_win = (ModestWindow *) modest_mail_operation_get_source (mail_op);
863 folder = tny_header_get_folder (header);
865 /* Mark header as read */
866 headers_action_mark_as_read (header, MODEST_WINDOW(parent_win), NULL);
868 /* Gets folder type (OUTBOX headers will be opened in edit window */
869 if (modest_tny_folder_is_local_folder (folder)) {
870 folder_type = modest_tny_folder_get_local_or_mmc_folder_type (folder);
871 if (folder_type == TNY_FOLDER_TYPE_INVALID)
872 g_warning ("%s: BUG: TNY_FOLDER_TYPE_INVALID", __FUNCTION__);
876 if (folder_type == TNY_FOLDER_TYPE_OUTBOX) {
877 TnyTransportAccount *traccount = NULL;
878 ModestTnyAccountStore *accstore = modest_runtime_get_account_store();
879 traccount = modest_tny_account_store_get_transport_account_from_outbox_header(accstore, header);
881 ModestTnySendQueue *send_queue = NULL;
882 ModestTnySendQueueStatus status;
884 account = g_strdup(modest_tny_account_get_parent_modest_account_name_for_server_account(
885 TNY_ACCOUNT(traccount)));
886 send_queue = modest_runtime_get_send_queue(traccount);
887 msg_id = modest_tny_send_queue_get_msg_id (header);
888 status = modest_tny_send_queue_get_msg_status(send_queue, msg_id);
889 /* Only open messages in outbox with the editor if they are in Failed state */
890 if (status == MODEST_TNY_SEND_QUEUE_FAILED) {
891 open_in_editor = TRUE;
894 g_object_unref(traccount);
896 g_warning("Cannot get transport account for message in outbox!!");
898 } else if (folder_type == TNY_FOLDER_TYPE_DRAFTS) {
899 open_in_editor = TRUE; /* Open in editor if the message is in the Drafts folder */
904 account = g_strdup (modest_window_get_active_account (MODEST_WINDOW (parent_win)));
906 account = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
908 if (open_in_editor) {
909 ModestAccountMgr *mgr = modest_runtime_get_account_mgr ();
910 const gchar *from_header = NULL;
912 from_header = tny_header_get_from (header);
914 /* we cannot edit without a valid account... */
915 if (!modest_account_mgr_has_accounts(mgr, TRUE)) {
916 if (!modest_ui_actions_run_account_setup_wizard(parent_win))
921 GSList *accounts = modest_account_mgr_account_names (mgr, TRUE);
923 for (node = accounts; node != NULL; node = g_slist_next (node)) {
924 gchar *from = modest_account_mgr_get_from_string (mgr, node->data);
926 if (from && (strcmp (from_header, from) == 0)) {
928 account = g_strdup (node->data);
934 g_slist_foreach (accounts, (GFunc) g_free, NULL);
935 g_slist_free (accounts);
938 win = modest_msg_edit_window_new (msg, account, TRUE);
942 modest_platform_information_banner_with_timeout
943 (NULL, NULL, _("mail_ib_opening_draft_message"), 1200);
946 gchar *uid = modest_tny_folder_get_header_unique_id (header);
948 if (MODEST_IS_MAIN_WINDOW (parent_win)) {
949 GtkWidget *header_view;
950 GtkTreeSelection *sel;
951 GList *sel_list = NULL;
954 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(parent_win),
955 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
957 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
958 sel_list = gtk_tree_selection_get_selected_rows (sel, &model);
960 if (sel_list != NULL) {
961 GtkTreeRowReference *row_reference;
963 row_reference = gtk_tree_row_reference_new (model, (GtkTreePath *) sel_list->data);
964 g_list_foreach (sel_list, (GFunc) gtk_tree_path_free, NULL);
965 g_list_free (sel_list);
967 win = modest_msg_view_window_new_with_header_model (
968 msg, account, (const gchar*) uid,
969 model, row_reference);
970 gtk_tree_row_reference_free (row_reference);
972 win = modest_msg_view_window_new_for_attachment (msg, account, (const gchar*) uid);
975 win = modest_msg_view_window_new_for_attachment (msg, account, (const gchar*) uid);
980 /* Register and show new window */
982 mgr = modest_runtime_get_window_mgr ();
983 modest_window_mgr_register_window (mgr, win);
984 g_object_unref (win);
985 gtk_widget_show_all (GTK_WIDGET(win));
988 /* Update toolbar dimming state */
989 if (MODEST_IS_MAIN_WINDOW (parent_win)) {
990 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (parent_win));
996 g_object_unref (parent_win);
997 g_object_unref (folder);
1001 modest_ui_actions_get_msgs_full_error_handler (ModestMailOperation *mail_op,
1004 const GError *error;
1005 GObject *win = NULL;
1006 const gchar *err_msg;
1008 win = modest_mail_operation_get_source (mail_op);
1009 error = modest_mail_operation_get_error (mail_op);
1011 /* Select error message */
1012 if (error->code == MODEST_MAIL_OPERATION_ERROR_MESSAGE_SIZE_LIMIT)
1013 err_msg = _("emev_ni_ui_imap_msg_size_exceed_error");
1015 err_msg = (const gchar *) user_data;
1018 modest_platform_run_information_dialog ((GtkWindow *) win, err_msg);
1021 g_object_unref (win);
1025 * Returns the account a list of headers belongs to. It returns a
1026 * *new* reference so don't forget to unref it
1029 get_account_from_header_list (TnyList *headers)
1031 TnyAccount *account = NULL;
1033 if (tny_list_get_length (headers) > 0) {
1034 TnyIterator *iter = tny_list_create_iterator (headers);
1035 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter));
1036 TnyFolder *folder = tny_header_get_folder (header);
1037 account = tny_folder_get_account (folder);
1038 g_object_unref (folder);
1039 g_object_unref (header);
1040 g_object_unref (iter);
1046 open_msgs_performer(gboolean canceled,
1048 GtkWindow *parent_window,
1049 TnyAccount *account,
1052 ModestMailOperation *mail_op = NULL;
1053 const gchar *proto_name;
1055 ModestTransportStoreProtocol proto;
1056 TnyList *not_opened_headers;
1057 TnyConnectionStatus status;
1059 not_opened_headers = TNY_LIST (user_data);
1061 status = tny_account_get_connection_status (account);
1062 if (err || canceled) {
1063 /* TODO: Show an error ? */
1067 /* Get the error message depending on the protocol */
1068 proto_name = tny_account_get_proto (account);
1069 if (proto_name != NULL) {
1070 proto = modest_protocol_info_get_transport_store_protocol (proto_name);
1072 proto = MODEST_PROTOCOL_STORE_MAILDIR;
1075 /* Create the error messages */
1076 if (tny_list_get_length (not_opened_headers) == 1) {
1077 if (proto == MODEST_PROTOCOL_STORE_POP) {
1078 error_msg = g_strdup (_("emev_ni_ui_pop3_msg_recv_error"));
1079 } else if (proto == MODEST_PROTOCOL_STORE_IMAP) {
1080 TnyIterator *iter = tny_list_create_iterator (not_opened_headers);
1081 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter));
1082 error_msg = g_strdup_printf (_("emev_ni_ui_imap_message_not_available_in_server"),
1083 tny_header_get_subject (header));
1084 g_object_unref (header);
1085 g_object_unref (iter);
1087 error_msg = g_strdup (_("mail_ni_ui_folder_get_msg_folder_error"));
1090 error_msg = g_strdup (_("mail_ni_ui_folder_get_msg_folder_error"));
1093 /* Create the mail operation */
1095 modest_mail_operation_new_with_error_handling ((GObject *) parent_window,
1096 modest_ui_actions_get_msgs_full_error_handler,
1098 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
1101 modest_mail_operation_get_msgs_full (mail_op,
1110 g_object_unref (mail_op);
1111 g_object_unref (not_opened_headers);
1112 g_object_unref (account);
1116 * This function is used by both modest_ui_actions_on_open and
1117 * modest_ui_actions_on_header_activated. This way we always do the
1118 * same when trying to open messages.
1121 open_msgs_from_headers (TnyList *headers, ModestWindow *win)
1123 ModestWindowMgr *mgr = NULL;
1124 TnyIterator *iter = NULL, *iter_not_opened = NULL;
1125 TnyList *not_opened_headers = NULL;
1126 TnyHeaderFlags flags = 0;
1127 TnyAccount *account;
1128 gint uncached_msgs = 0;
1130 g_return_if_fail (headers != NULL);
1132 /* Check that only one message is selected for opening */
1133 if (tny_list_get_length (headers) != 1) {
1134 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
1135 _("mcen_ib_select_one_message"));
1139 mgr = modest_runtime_get_window_mgr ();
1140 iter = tny_list_create_iterator (headers);
1142 /* Get the account */
1143 account = get_account_from_header_list (headers);
1145 /* Look if we already have a message view for each header. If
1146 true, then remove the header from the list of headers to
1148 not_opened_headers = tny_simple_list_new ();
1149 while (!tny_iterator_is_done (iter)) {
1151 ModestWindow *window = NULL;
1152 TnyHeader *header = NULL;
1153 gboolean found = FALSE;
1155 header = TNY_HEADER (tny_iterator_get_current (iter));
1157 flags = tny_header_get_flags (header);
1160 found = modest_window_mgr_find_registered_header (mgr, header, &window);
1162 /* Do not open again the message and present the
1163 window to the user */
1166 gtk_window_present (GTK_WINDOW (window));
1168 /* the header has been registered already, we don't do
1169 * anything but wait for the window to come up*/
1170 g_debug ("header %p already registered, waiting for window", header);
1172 tny_list_append (not_opened_headers, G_OBJECT (header));
1176 g_object_unref (header);
1178 tny_iterator_next (iter);
1180 g_object_unref (iter);
1183 /* Open each message */
1184 if (tny_list_get_length (not_opened_headers) == 0)
1187 /* If some messages would have to be downloaded, ask the user to
1188 * make a connection. It's generally easier to do this here (in the mainloop)
1189 * than later in a thread:
1191 if (tny_list_get_length (not_opened_headers) > 0) {
1192 uncached_msgs = header_list_count_uncached_msgs (not_opened_headers);
1194 if (uncached_msgs > 0) {
1195 /* Allways download if we are online. */
1196 if (!tny_device_is_online (modest_runtime_get_device ())) {
1199 /* If ask for user permission to download the messages */
1200 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
1201 ngettext("mcen_nc_get_msg",
1205 /* End if the user does not want to continue */
1206 if (response == GTK_RESPONSE_CANCEL)
1212 /* Register the headers before actually creating the windows: */
1213 iter_not_opened = tny_list_create_iterator (not_opened_headers);
1214 while (!tny_iterator_is_done (iter_not_opened)) {
1215 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter_not_opened));
1217 modest_window_mgr_register_header (mgr, header, NULL);
1218 g_object_unref (header);
1220 tny_iterator_next (iter_not_opened);
1222 g_object_unref (iter_not_opened);
1223 iter_not_opened = NULL;
1225 /* Connect to the account and perform */
1226 if (uncached_msgs > 0) {
1227 modest_platform_connect_and_perform ((GtkWindow *) win, g_object_ref (account),
1228 open_msgs_performer, g_object_ref (not_opened_headers));
1230 /* Call directly the performer, do not need to connect */
1231 open_msgs_performer (FALSE, NULL, (GtkWindow *) win, g_object_ref (account),
1232 g_object_ref (not_opened_headers));
1237 g_object_unref (account);
1238 if (not_opened_headers)
1239 g_object_unref (not_opened_headers);
1243 modest_ui_actions_on_open (GtkAction *action, ModestWindow *win)
1248 headers = get_selected_headers (win);
1253 open_msgs_from_headers (headers, win);
1255 g_object_unref(headers);
1260 free_reply_forward_helper (gpointer data)
1262 ReplyForwardHelper *helper;
1264 helper = (ReplyForwardHelper *) data;
1265 g_free (helper->account_name);
1266 g_slice_free (ReplyForwardHelper, helper);
1270 reply_forward_cb (ModestMailOperation *mail_op,
1278 ReplyForwardHelper *rf_helper;
1279 ModestWindow *msg_win = NULL;
1280 ModestEditType edit_type;
1282 TnyAccount *account = NULL;
1283 ModestWindowMgr *mgr = NULL;
1284 gchar *signature = NULL;
1285 gboolean use_signature;
1287 /* If there was any error. The mail operation could be NULL,
1288 this means that we already have the message downloaded and
1289 that we didn't do a mail operation to retrieve it */
1290 if (mail_op && !modest_ui_actions_msg_retrieval_check (mail_op, header, msg))
1293 g_return_if_fail (user_data != NULL);
1294 rf_helper = (ReplyForwardHelper *) user_data;
1296 from = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(),
1297 rf_helper->account_name);
1298 signature = modest_account_mgr_get_signature (modest_runtime_get_account_mgr(),
1299 rf_helper->account_name,
1302 /* Create reply mail */
1303 switch (rf_helper->action) {
1306 modest_tny_msg_create_reply_msg (msg, header, from, signature,
1307 rf_helper->reply_forward_type,
1308 MODEST_TNY_MSG_REPLY_MODE_SENDER);
1310 case ACTION_REPLY_TO_ALL:
1312 modest_tny_msg_create_reply_msg (msg, header, from, signature, rf_helper->reply_forward_type,
1313 MODEST_TNY_MSG_REPLY_MODE_ALL);
1314 edit_type = MODEST_EDIT_TYPE_REPLY;
1316 case ACTION_FORWARD:
1318 modest_tny_msg_create_forward_msg (msg, from, signature, rf_helper->reply_forward_type);
1319 edit_type = MODEST_EDIT_TYPE_FORWARD;
1322 g_return_if_reached ();
1329 g_printerr ("modest: failed to create message\n");
1333 account = modest_tny_account_store_get_server_account (modest_runtime_get_account_store(),
1334 rf_helper->account_name,
1335 TNY_ACCOUNT_TYPE_STORE);
1337 g_printerr ("modest: failed to get tnyaccount for '%s'\n", rf_helper->account_name);
1341 /* Create and register the windows */
1342 msg_win = modest_msg_edit_window_new (new_msg, rf_helper->account_name, FALSE);
1343 mgr = modest_runtime_get_window_mgr ();
1344 modest_window_mgr_register_window (mgr, msg_win);
1346 if (rf_helper->parent_window != NULL) {
1347 gdouble parent_zoom;
1349 parent_zoom = modest_window_get_zoom (MODEST_WINDOW (rf_helper->parent_window));
1350 modest_window_set_zoom (msg_win, parent_zoom);
1353 /* Show edit window */
1354 gtk_widget_show_all (GTK_WIDGET (msg_win));
1358 g_object_unref (msg_win);
1360 g_object_unref (G_OBJECT (new_msg));
1362 g_object_unref (G_OBJECT (account));
1363 /* g_object_unref (msg); */
1364 free_reply_forward_helper (rf_helper);
1367 /* Checks a list of headers. If any of them are not currently
1368 * downloaded (CACHED) then returns TRUE else returns FALSE.
1371 header_list_count_uncached_msgs (TnyList *header_list)
1374 gint uncached_messages = 0;
1376 iter = tny_list_create_iterator (header_list);
1377 while (!tny_iterator_is_done (iter)) {
1380 header = TNY_HEADER (tny_iterator_get_current (iter));
1382 if (!(tny_header_get_flags (header) & TNY_HEADER_FLAG_CACHED))
1383 uncached_messages ++;
1384 g_object_unref (header);
1387 tny_iterator_next (iter);
1389 g_object_unref (iter);
1391 return uncached_messages;
1394 /* Returns FALSE if the user does not want to download the
1395 * messages. Returns TRUE if the user allowed the download.
1398 connect_to_get_msg (ModestWindow *win,
1399 gint num_of_uncached_msgs,
1400 TnyAccount *account)
1402 GtkResponseType response;
1404 /* Allways download if we are online. */
1405 if (tny_device_is_online (modest_runtime_get_device ()))
1408 /* If offline, then ask for user permission to download the messages */
1409 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
1410 ngettext("mcen_nc_get_msg",
1412 num_of_uncached_msgs));
1414 if (response == GTK_RESPONSE_CANCEL)
1417 return modest_platform_connect_and_wait((GtkWindow *) win, account);
1421 * Common code for the reply and forward actions
1424 reply_forward (ReplyForwardAction action, ModestWindow *win)
1426 ModestMailOperation *mail_op = NULL;
1427 TnyList *header_list = NULL;
1428 ReplyForwardHelper *rf_helper = NULL;
1429 guint reply_forward_type;
1430 gboolean continue_download = TRUE;
1431 gboolean do_retrieve = TRUE;
1433 g_return_if_fail (MODEST_IS_WINDOW(win));
1435 /* we need an account when editing */
1436 if (!modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE)) {
1437 if (!modest_ui_actions_run_account_setup_wizard (win))
1441 header_list = get_selected_headers (win);
1445 reply_forward_type =
1446 modest_conf_get_int (modest_runtime_get_conf (),
1447 (action == ACTION_FORWARD) ? MODEST_CONF_FORWARD_TYPE : MODEST_CONF_REPLY_TYPE,
1450 /* check if we need to download msg before asking about it */
1451 do_retrieve = (action == ACTION_FORWARD) ||
1452 (reply_forward_type != MODEST_TNY_MSG_REPLY_TYPE_CITE);
1455 gint num_of_unc_msgs;
1457 /* check that the messages have been previously downloaded */
1458 num_of_unc_msgs = header_list_count_uncached_msgs(header_list);
1459 /* If there are any uncached message ask the user
1460 * whether he/she wants to download them. */
1461 if (num_of_unc_msgs) {
1462 TnyAccount *account = get_account_from_header_list (header_list);
1463 continue_download = connect_to_get_msg (win, num_of_unc_msgs, account);
1464 g_object_unref (account);
1468 if (!continue_download) {
1469 g_object_unref (header_list);
1473 /* We assume that we can only select messages of the
1474 same folder and that we reply all of them from the
1475 same account. In fact the interface currently only
1476 allows single selection */
1479 rf_helper = g_slice_new0 (ReplyForwardHelper);
1480 rf_helper->reply_forward_type = reply_forward_type;
1481 rf_helper->action = action;
1482 rf_helper->account_name = g_strdup (modest_window_get_active_account (win));
1484 if ((win != NULL) && (MODEST_IS_WINDOW (win)))
1485 rf_helper->parent_window = GTK_WIDGET (win);
1486 if (!rf_helper->account_name)
1487 rf_helper->account_name =
1488 modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
1490 if (MODEST_IS_MSG_VIEW_WINDOW(win)) {
1493 /* Get header and message. Do not free them here, the
1494 reply_forward_cb must do it */
1495 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW(win));
1496 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW(win));
1497 if (!msg || !header) {
1499 g_object_unref (msg);
1500 g_printerr ("modest: no message found\n");
1503 reply_forward_cb (NULL, header, FALSE, msg, NULL, rf_helper);
1506 g_object_unref (header);
1511 /* Only reply/forward to one message */
1512 iter = tny_list_create_iterator (header_list);
1513 header = TNY_HEADER (tny_iterator_get_current (iter));
1514 g_object_unref (iter);
1517 /* Retrieve messages */
1520 modest_mail_operation_new_with_error_handling (G_OBJECT(win),
1521 modest_ui_actions_get_msgs_full_error_handler,
1523 modest_mail_operation_queue_add (
1524 modest_runtime_get_mail_operation_queue (), mail_op);
1526 modest_mail_operation_get_msg (mail_op,
1531 g_object_unref(mail_op);
1533 /* we put a ref here to prevent double unref as the reply
1534 * forward callback unrefs the header at its end */
1535 reply_forward_cb (NULL, header, FALSE, NULL, NULL, rf_helper);
1539 g_object_unref (header);
1545 g_object_unref (header_list);
1549 modest_ui_actions_on_reply (GtkAction *action, ModestWindow *win)
1551 g_return_if_fail (MODEST_IS_WINDOW(win));
1553 reply_forward (ACTION_REPLY, win);
1557 modest_ui_actions_on_forward (GtkAction *action, ModestWindow *win)
1559 g_return_if_fail (MODEST_IS_WINDOW(win));
1561 reply_forward (ACTION_FORWARD, win);
1565 modest_ui_actions_on_reply_all (GtkAction *action, ModestWindow *win)
1567 g_return_if_fail (MODEST_IS_WINDOW(win));
1569 reply_forward (ACTION_REPLY_TO_ALL, win);
1573 modest_ui_actions_on_next (GtkAction *action,
1574 ModestWindow *window)
1576 if (MODEST_IS_MAIN_WINDOW (window)) {
1577 GtkWidget *header_view;
1579 header_view = modest_main_window_get_child_widget (
1580 MODEST_MAIN_WINDOW(window),
1581 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1585 modest_header_view_select_next (
1586 MODEST_HEADER_VIEW(header_view));
1587 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
1588 modest_msg_view_window_select_next_message (
1589 MODEST_MSG_VIEW_WINDOW (window));
1591 g_return_if_reached ();
1596 modest_ui_actions_on_prev (GtkAction *action,
1597 ModestWindow *window)
1599 g_return_if_fail (MODEST_IS_WINDOW(window));
1601 if (MODEST_IS_MAIN_WINDOW (window)) {
1602 GtkWidget *header_view;
1603 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
1604 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1608 modest_header_view_select_prev (MODEST_HEADER_VIEW(header_view));
1609 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
1610 modest_msg_view_window_select_previous_message (MODEST_MSG_VIEW_WINDOW (window));
1612 g_return_if_reached ();
1617 modest_ui_actions_on_sort (GtkAction *action,
1618 ModestWindow *window)
1620 g_return_if_fail (MODEST_IS_WINDOW(window));
1622 if (MODEST_IS_MAIN_WINDOW (window)) {
1623 GtkWidget *header_view;
1624 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
1625 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1627 modest_platform_information_banner (NULL, NULL, _CS("ckdg_ib_nothing_to_sort"));
1632 /* Show sorting dialog */
1633 modest_platform_run_sort_dialog (GTK_WINDOW (window), MODEST_SORT_HEADERS);
1638 new_messages_arrived (ModestMailOperation *self,
1639 TnyList *new_headers,
1644 source = modest_mail_operation_get_source (self);
1646 /* Notify new messages have been downloaded. Do not notify if
1647 the send&receive was invoked by the user, i.e, if the mail
1648 operation has a source (the main window) */
1649 if ((new_headers != NULL) && (tny_list_get_length (new_headers) > 0) && !source)
1650 modest_platform_on_new_headers_received (new_headers);
1653 g_object_unref (source);
1657 retrieve_all_messages_cb (GObject *source,
1659 guint retrieve_limit)
1665 window = GTK_WINDOW (source);
1666 msg = g_strdup_printf (_("mail_nc_msg_count_limit_exceeded"),
1667 num_msgs, retrieve_limit);
1669 /* Ask the user if they want to retrieve all the messages */
1671 modest_platform_run_confirmation_dialog_with_buttons (window, msg,
1672 _("mcen_bd_get_all"),
1673 _("mcen_bd_newest_only"));
1674 /* Free and return */
1676 return (response == GTK_RESPONSE_ACCEPT) ? TRUE : FALSE;
1680 TnyAccount *account;
1682 gchar *account_name;
1686 do_send_receive_performer (gboolean canceled,
1688 GtkWindow *parent_window,
1689 TnyAccount *account,
1692 ModestMailOperation *mail_op;
1693 SendReceiveInfo *info;
1695 info = (SendReceiveInfo *) user_data;
1697 if (err || canceled) {
1702 /* Set send/receive operation in progress */
1703 if (info->win && MODEST_IS_MAIN_WINDOW (info->win)) {
1704 modest_main_window_notify_send_receive_initied (MODEST_MAIN_WINDOW (info->win));
1707 mail_op = modest_mail_operation_new_with_error_handling ((info->win) ? G_OBJECT (info->win) : NULL,
1708 modest_ui_actions_send_receive_error_handler,
1711 if (info->win && MODEST_IS_MAIN_WINDOW (info->win))
1712 g_signal_connect (G_OBJECT(mail_op), "operation-finished",
1713 G_CALLBACK (on_send_receive_finished),
1716 /* Send & receive. */
1717 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
1718 modest_mail_operation_update_account (mail_op, info->account_name, (info->win) ? FALSE : TRUE,
1719 (info->win) ? retrieve_all_messages_cb : NULL,
1720 new_messages_arrived, info->win);
1721 g_object_unref (G_OBJECT (mail_op));
1725 if (info->account_name)
1726 g_free (info->account_name);
1728 g_object_unref (info->win);
1730 g_object_unref (info->account);
1731 g_slice_free (SendReceiveInfo, info);
1735 * This function performs the send & receive required actions. The
1736 * window is used to create the mail operation. Typically it should
1737 * always be the main window, but we pass it as argument in order to
1741 modest_ui_actions_do_send_receive (const gchar *account_name,
1744 gchar *acc_name = NULL;
1745 SendReceiveInfo *info;
1746 ModestTnyAccountStore *acc_store;
1748 /* If no account name was provided then get the current account, and if
1749 there is no current account then pick the default one: */
1750 if (!account_name) {
1752 acc_name = g_strdup (modest_window_get_active_account (win));
1754 acc_name = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
1756 g_printerr ("modest: cannot get default account\n");
1760 acc_name = g_strdup (account_name);
1763 acc_store = modest_runtime_get_account_store ();
1765 /* Create the info for the connect and perform */
1766 info = g_slice_new (SendReceiveInfo);
1767 info->account_name = acc_name;
1768 info->win = (win) ? g_object_ref (win) : NULL;
1769 info->account = modest_tny_account_store_get_server_account (acc_store, acc_name,
1770 TNY_ACCOUNT_TYPE_STORE);
1772 /* Invoke the connect and perform */
1773 modest_platform_connect_and_perform ((win) ? GTK_WINDOW (win) : NULL, info->account,
1774 do_send_receive_performer, info);
1779 modest_ui_actions_do_cancel_send (const gchar *account_name,
1782 TnyTransportAccount *transport_account;
1783 TnySendQueue *send_queue = NULL;
1784 GError *error = NULL;
1786 /* Get transport account */
1788 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
1789 (modest_runtime_get_account_store(),
1791 TNY_ACCOUNT_TYPE_TRANSPORT));
1792 if (!transport_account) {
1793 g_printerr ("modest: no transport account found for '%s'\n", account_name);
1798 send_queue = TNY_SEND_QUEUE (modest_runtime_get_send_queue (transport_account));
1799 if (!TNY_IS_SEND_QUEUE(send_queue)) {
1800 g_set_error (&error, MODEST_MAIL_OPERATION_ERROR,
1801 MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND,
1802 "modest: could not find send queue for account\n");
1804 /* Keeep messages in outbox folder */
1805 tny_send_queue_cancel (send_queue, FALSE, &error);
1809 if (transport_account != NULL)
1810 g_object_unref (G_OBJECT (transport_account));
1814 modest_ui_actions_cancel_send_all (ModestWindow *win)
1816 GSList *account_names, *iter;
1818 account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
1821 iter = account_names;
1823 modest_ui_actions_do_cancel_send ((const char*) iter->data, win);
1824 iter = g_slist_next (iter);
1827 modest_account_mgr_free_account_names (account_names);
1828 account_names = NULL;
1832 modest_ui_actions_cancel_send (GtkAction *action, ModestWindow *win)
1835 /* Check if accounts exist */
1836 gboolean accounts_exist =
1837 modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
1839 /* If not, allow the user to create an account before trying to send/receive. */
1840 if (!accounts_exist)
1841 modest_ui_actions_on_accounts (NULL, win);
1843 /* Cancel all sending operaitons */
1844 modest_ui_actions_cancel_send_all (win);
1848 * Refreshes all accounts. This function will be used by automatic
1852 modest_ui_actions_do_send_receive_all (ModestWindow *win)
1854 GSList *account_names, *iter;
1856 account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
1859 iter = account_names;
1861 modest_ui_actions_do_send_receive ((const char*) iter->data, win);
1862 iter = g_slist_next (iter);
1865 modest_account_mgr_free_account_names (account_names);
1866 account_names = NULL;
1870 * Handler of the click on Send&Receive button in the main toolbar
1873 modest_ui_actions_on_send_receive (GtkAction *action, ModestWindow *win)
1875 /* Check if accounts exist */
1876 gboolean accounts_exist;
1879 modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
1881 /* If not, allow the user to create an account before trying to send/receive. */
1882 if (!accounts_exist)
1883 modest_ui_actions_on_accounts (NULL, win);
1885 /* Refresh the current folder. The if is always TRUE it's just an extra check */
1886 if (MODEST_IS_MAIN_WINDOW (win)) {
1887 GtkWidget *folder_view;
1888 TnyFolderStore *folder_store;
1891 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
1892 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
1896 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
1899 g_object_unref (folder_store);
1902 /* Refresh the active account */
1903 modest_ui_actions_do_send_receive (NULL, win);
1908 modest_ui_actions_toggle_header_list_view (GtkAction *action, ModestMainWindow *main_window)
1911 GtkWidget *header_view;
1913 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1915 header_view = modest_main_window_get_child_widget (main_window,
1916 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1920 conf = modest_runtime_get_conf ();
1922 /* what is saved/restored is depending on the style; thus; we save with
1923 * old style, then update the style, and restore for this new style
1925 modest_widget_memory_save (conf, G_OBJECT(header_view), MODEST_CONF_HEADER_VIEW_KEY);
1927 if (modest_header_view_get_style
1928 (MODEST_HEADER_VIEW(header_view)) == MODEST_HEADER_VIEW_STYLE_DETAILS)
1929 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
1930 MODEST_HEADER_VIEW_STYLE_TWOLINES);
1932 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
1933 MODEST_HEADER_VIEW_STYLE_DETAILS);
1935 modest_widget_memory_restore (conf, G_OBJECT(header_view),
1936 MODEST_CONF_HEADER_VIEW_KEY);
1941 modest_ui_actions_on_header_selected (ModestHeaderView *header_view,
1943 ModestMainWindow *main_window)
1945 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1946 g_return_if_fail (MODEST_IS_HEADER_VIEW (header_view));
1948 /* in the case the folder is empty, show the empty folder message and focus
1950 if (!header && gtk_widget_is_focus (GTK_WIDGET (header_view))) {
1951 if (modest_header_view_is_empty (header_view)) {
1952 TnyFolder *folder = modest_header_view_get_folder (header_view);
1953 GtkWidget *folder_view =
1954 modest_main_window_get_child_widget (main_window,
1955 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
1957 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view), folder, FALSE);
1958 gtk_widget_grab_focus (GTK_WIDGET (folder_view));
1962 /* If no header has been selected then exit */
1967 if (!gtk_widget_is_focus (GTK_WIDGET(header_view)))
1968 gtk_widget_grab_focus (GTK_WIDGET(header_view));
1970 /* Update toolbar dimming state */
1971 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
1975 modest_ui_actions_on_header_activated (ModestHeaderView *header_view,
1977 ModestMainWindow *main_window)
1981 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1986 if (modest_header_view_count_selected_headers (header_view) > 1) {
1987 modest_platform_information_banner (NULL, NULL, _("mcen_ib_select_one_message"));
1992 /* headers = tny_simple_list_new (); */
1993 /* tny_list_prepend (headers, G_OBJECT (header)); */
1994 headers = modest_header_view_get_selected_headers (header_view);
1996 open_msgs_from_headers (headers, MODEST_WINDOW (main_window));
1998 g_object_unref (headers);
2002 set_active_account_from_tny_account (TnyAccount *account,
2003 ModestWindow *window)
2005 const gchar *server_acc_name = tny_account_get_id (account);
2007 /* We need the TnyAccount provided by the
2008 account store because that is the one that
2009 knows the name of the Modest account */
2010 TnyAccount *modest_server_account = modest_server_account =
2011 modest_tny_account_store_get_tny_account_by (modest_runtime_get_account_store (),
2012 MODEST_TNY_ACCOUNT_STORE_QUERY_ID,
2014 if (!modest_server_account) {
2015 g_warning ("%s: could not get tny account\n", __FUNCTION__);
2019 /* Update active account, but only if it's not a pseudo-account */
2020 if ((!modest_tny_account_is_virtual_local_folders(modest_server_account)) &&
2021 (!modest_tny_account_is_memory_card_account(modest_server_account))) {
2022 const gchar *modest_acc_name =
2023 modest_tny_account_get_parent_modest_account_name_for_server_account (modest_server_account);
2024 if (modest_acc_name)
2025 modest_window_set_active_account (window, modest_acc_name);
2028 g_object_unref (modest_server_account);
2033 folder_refreshed_cb (ModestMailOperation *mail_op,
2037 ModestMainWindow *win = NULL;
2038 GtkWidget *header_view;
2039 gboolean folder_empty = FALSE;
2040 gboolean all_marked_as_deleted = FALSE;
2042 g_return_if_fail (TNY_IS_FOLDER (folder));
2044 win = MODEST_MAIN_WINDOW (user_data);
2046 modest_main_window_get_child_widget(win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2049 TnyFolder *current_folder;
2051 current_folder = modest_header_view_get_folder (MODEST_HEADER_VIEW (header_view));
2052 if (current_folder != NULL && folder != current_folder) {
2053 g_object_unref (current_folder);
2056 g_object_unref (current_folder);
2059 /* Check if folder is empty and set headers view contents style */
2060 folder_empty = (tny_folder_get_all_count (folder) == 0);
2061 all_marked_as_deleted = modest_header_view_is_empty (MODEST_HEADER_VIEW(header_view));
2062 if (folder_empty || all_marked_as_deleted)
2063 modest_main_window_set_contents_style (win,
2064 MODEST_MAIN_WINDOW_CONTENTS_STYLE_EMPTY);
2068 modest_ui_actions_on_folder_selection_changed (ModestFolderView *folder_view,
2069 TnyFolderStore *folder_store,
2071 ModestMainWindow *main_window)
2074 GtkWidget *header_view;
2076 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2078 header_view = modest_main_window_get_child_widget(main_window,
2079 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2083 conf = modest_runtime_get_conf ();
2085 if (TNY_IS_ACCOUNT (folder_store)) {
2087 set_active_account_from_tny_account (TNY_ACCOUNT (folder_store), MODEST_WINDOW (main_window));
2089 /* Show account details */
2090 modest_main_window_set_contents_style (main_window, MODEST_MAIN_WINDOW_CONTENTS_STYLE_DETAILS);
2093 if (TNY_IS_FOLDER (folder_store) && selected) {
2095 /* Update the active account */
2096 TnyAccount *account = modest_tny_folder_get_account (TNY_FOLDER (folder_store));
2098 set_active_account_from_tny_account (account, MODEST_WINDOW (main_window));
2099 g_object_unref (account);
2103 /* Set the header style by default, it could
2104 be changed later by the refresh callback to
2106 modest_main_window_set_contents_style (main_window,
2107 MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS);
2109 /* Set folder on header view. This function
2110 will call tny_folder_refresh_async so we
2111 pass a callback that will be called when
2112 finished. We use that callback to set the
2113 empty view if there are no messages */
2114 modest_header_view_set_folder (MODEST_HEADER_VIEW(header_view),
2115 TNY_FOLDER (folder_store),
2116 folder_refreshed_cb,
2119 /* Restore configuration. We need to do this
2120 *after* the set_folder because the widget
2121 memory asks the header view about its
2123 modest_widget_memory_restore (modest_runtime_get_conf (),
2124 G_OBJECT(header_view),
2125 MODEST_CONF_HEADER_VIEW_KEY);
2127 /* Update the active account */
2128 //modest_window_set_active_account (MODEST_WINDOW (main_window), NULL);
2129 /* Save only if we're seeing headers */
2130 if (modest_main_window_get_contents_style (main_window) ==
2131 MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS)
2132 modest_widget_memory_save (conf, G_OBJECT (header_view),
2133 MODEST_CONF_HEADER_VIEW_KEY);
2134 modest_header_view_clear (MODEST_HEADER_VIEW(header_view));
2138 /* Update toolbar dimming state */
2139 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
2143 modest_ui_actions_on_item_not_found (ModestHeaderView *header_view,ModestItemType type,
2150 item = (type == MODEST_ITEM_TYPE_FOLDER) ? "folder" : "message";
2152 online = tny_device_is_online (modest_runtime_get_device());
2155 /* already online -- the item is simply not there... */
2156 dialog = gtk_message_dialog_new (GTK_WINDOW (win),
2158 GTK_MESSAGE_WARNING,
2160 _("The %s you selected cannot be found"),
2162 gtk_dialog_add_button (GTK_DIALOG (dialog),_("mcen_bd_dialog_ok"), GTK_RESPONSE_ACCEPT);
2163 gtk_dialog_run (GTK_DIALOG(dialog));
2165 dialog = gtk_dialog_new_with_buttons (_("Connection requested"),
2168 _("mcen_bd_dialog_cancel"),
2169 GTK_RESPONSE_REJECT,
2170 _("mcen_bd_dialog_ok"),
2171 GTK_RESPONSE_ACCEPT,
2173 txt = g_strdup_printf (_("This %s is not available in offline mode.\n"
2174 "Do you want to get online?"), item);
2175 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
2176 gtk_label_new (txt), FALSE, FALSE, 0);
2177 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
2180 gtk_window_set_default_size (GTK_WINDOW(dialog), 300, 300);
2181 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
2182 /* TODO: Comment about why is this commented out: */
2183 /* modest_platform_connect_and_wait (); */
2186 gtk_widget_destroy (dialog);
2190 modest_ui_actions_on_msg_link_hover (ModestMsgView *msgview, const gchar* link,
2193 /* g_message ("%s %s", __FUNCTION__, link); */
2198 modest_ui_actions_on_msg_link_clicked (ModestMsgView *msgview, const gchar* link,
2201 modest_platform_activate_uri (link);
2205 modest_ui_actions_on_msg_link_contextual (ModestMsgView *msgview, const gchar* link,
2208 modest_platform_show_uri_popup (link);
2212 modest_ui_actions_on_msg_attachment_clicked (ModestMsgView *msgview, TnyMimePart *mime_part,
2215 modest_msg_view_window_view_attachment (MODEST_MSG_VIEW_WINDOW (win), mime_part);
2219 modest_ui_actions_on_msg_recpt_activated (ModestMsgView *msgview,
2220 const gchar *address,
2223 /* g_message ("%s %s", __FUNCTION__, address); */
2227 on_save_to_drafts_cb (ModestMailOperation *mail_op,
2228 TnyMsg *saved_draft,
2231 ModestMsgEditWindow *edit_window;
2232 ModestMainWindow *win;
2234 /* FIXME. Make the header view sensitive again. This is a
2235 * temporary hack. See modest_ui_actions_on_save_to_drafts()
2237 win = MODEST_MAIN_WINDOW(modest_window_mgr_get_main_window(
2238 modest_runtime_get_window_mgr(), FALSE));
2240 GtkWidget *hdrview = modest_main_window_get_child_widget(
2241 win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2242 if (hdrview) gtk_widget_set_sensitive(hdrview, TRUE);
2245 edit_window = MODEST_MSG_EDIT_WINDOW (user_data);
2247 /* If there was any error do nothing */
2248 if (modest_mail_operation_get_error (mail_op) != NULL)
2251 modest_msg_edit_window_set_draft (edit_window, saved_draft);
2255 modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edit_window)
2257 TnyTransportAccount *transport_account;
2258 ModestMailOperation *mail_operation;
2260 gchar *account_name, *from;
2261 ModestAccountMgr *account_mgr;
2264 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window));
2266 data = modest_msg_edit_window_get_msg_data (edit_window);
2268 account_name = g_strdup (data->account_name);
2269 account_mgr = modest_runtime_get_account_mgr();
2271 account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
2273 account_name = modest_account_mgr_get_default_account (account_mgr);
2274 if (!account_name) {
2275 g_printerr ("modest: no account found\n");
2276 modest_msg_edit_window_free_msg_data (edit_window, data);
2280 if (!strcmp (account_name, MODEST_LOCAL_FOLDERS_ACCOUNT_ID)) {
2281 account_name = g_strdup (data->account_name);
2285 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
2286 (modest_runtime_get_account_store(),
2288 TNY_ACCOUNT_TYPE_TRANSPORT));
2289 if (!transport_account) {
2290 g_printerr ("modest: no transport account found for '%s'\n", account_name);
2291 g_free (account_name);
2292 modest_msg_edit_window_free_msg_data (edit_window, data);
2295 from = modest_account_mgr_get_from_string (account_mgr, account_name);
2297 /* Create the mail operation */
2298 mail_operation = modest_mail_operation_new (G_OBJECT(edit_window));
2299 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
2301 modest_mail_operation_save_to_drafts (mail_operation,
2313 data->priority_flags,
2314 on_save_to_drafts_cb,
2316 info_text = g_strdup_printf (_("mail_va_saved_to_drafts"), _("mcen_me_folder_drafts"));
2317 modest_platform_information_banner (NULL, NULL, info_text);
2322 g_free (account_name);
2323 g_object_unref (G_OBJECT (transport_account));
2324 g_object_unref (G_OBJECT (mail_operation));
2326 modest_msg_edit_window_free_msg_data (edit_window, data);
2327 modest_msg_edit_window_reset_modified (edit_window);
2330 * If the drafts folder is selected then make the header view
2331 * insensitive while the message is being saved to drafts
2332 * (it'll be sensitive again in on_save_to_drafts_cb()). This
2333 * is not very clean but it avoids letting the drafts folder
2334 * in an inconsistent state: the user could edit the message
2335 * being saved and undesirable things would happen.
2336 * In the average case the user won't notice anything at
2337 * all. In the worst case (the user is editing a really big
2338 * file from Drafts) the header view will be insensitive
2339 * during the saving process (10 or 20 seconds, depending on
2340 * the message). Anyway this is just a quick workaround: once
2341 * we find a better solution it should be removed
2342 * See NB#65125 (commend #18) for details.
2344 ModestMainWindow *win = MODEST_MAIN_WINDOW(modest_window_mgr_get_main_window(
2345 modest_runtime_get_window_mgr(), FALSE));
2347 ModestFolderView *view = MODEST_FOLDER_VIEW(modest_main_window_get_child_widget(
2348 win, MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW));
2350 TnyFolder *folder = TNY_FOLDER(modest_folder_view_get_selected(view));
2352 if (modest_tny_folder_is_local_folder(folder)) {
2353 TnyFolderType folder_type;
2354 folder_type = modest_tny_folder_get_local_or_mmc_folder_type(folder);
2355 if (folder_type == TNY_FOLDER_TYPE_DRAFTS) {
2356 GtkWidget *hdrview = modest_main_window_get_child_widget(
2357 win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2358 if (hdrview) gtk_widget_set_sensitive(hdrview, FALSE);
2362 if (folder != NULL) g_object_unref(folder);
2367 /* For instance, when clicking the Send toolbar button when editing a message: */
2369 modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
2371 TnyTransportAccount *transport_account = NULL;
2373 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window));
2375 if (!modest_msg_edit_window_check_names (edit_window, TRUE))
2378 /* FIXME: Code added just for testing. The final version will
2379 use the send queue provided by tinymail and some
2381 MsgData *data = modest_msg_edit_window_get_msg_data (edit_window);
2383 ModestAccountMgr *account_mgr = modest_runtime_get_account_mgr();
2384 gchar *account_name = g_strdup (data->account_name);
2386 g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
2389 account_name = modest_account_mgr_get_default_account (account_mgr);
2391 if (!account_name) {
2392 modest_msg_edit_window_free_msg_data (edit_window, data);
2393 /* Run account setup wizard */
2394 if (!modest_ui_actions_run_account_setup_wizard (MODEST_WINDOW(edit_window)))
2398 /* Get the currently-active transport account for this modest account: */
2399 if (strcmp (account_name, MODEST_LOCAL_FOLDERS_ACCOUNT_ID) != 0) {
2400 transport_account = TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
2401 (modest_runtime_get_account_store(),
2402 account_name, TNY_ACCOUNT_TYPE_TRANSPORT));
2405 if (!transport_account) {
2406 /* Run account setup wizard */
2407 if (!modest_ui_actions_run_account_setup_wizard(MODEST_WINDOW(edit_window)))
2411 gchar *from = modest_account_mgr_get_from_string (account_mgr, account_name);
2413 /* Create the mail operation */
2414 ModestMailOperation *mail_operation = modest_mail_operation_new (G_OBJECT(edit_window));
2415 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
2417 modest_mail_operation_send_new_mail (mail_operation,
2429 data->priority_flags);
2431 if (modest_mail_operation_get_status (mail_operation) == MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS)
2432 modest_platform_information_banner (NULL, NULL, _("mcen_ib_outbox_waiting_to_be_sent"));
2437 g_free (account_name);
2438 g_object_unref (G_OBJECT (transport_account));
2439 g_object_unref (G_OBJECT (mail_operation));
2441 modest_msg_edit_window_free_msg_data (edit_window, data);
2442 modest_msg_edit_window_set_sent (edit_window, TRUE);
2444 /* Save settings and close the window: */
2445 modest_ui_actions_on_close_window (NULL, MODEST_WINDOW (edit_window));
2449 modest_ui_actions_on_toggle_bold (GtkToggleAction *action,
2450 ModestMsgEditWindow *window)
2452 ModestMsgEditFormatState *format_state = NULL;
2454 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2455 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
2457 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2460 format_state = modest_msg_edit_window_get_format_state (window);
2461 g_return_if_fail (format_state != NULL);
2463 format_state->bold = gtk_toggle_action_get_active (action);
2464 modest_msg_edit_window_set_format_state (window, format_state);
2465 g_free (format_state);
2470 modest_ui_actions_on_toggle_italics (GtkToggleAction *action,
2471 ModestMsgEditWindow *window)
2473 ModestMsgEditFormatState *format_state = NULL;
2475 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2476 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
2478 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2481 format_state = modest_msg_edit_window_get_format_state (window);
2482 g_return_if_fail (format_state != NULL);
2484 format_state->italics = gtk_toggle_action_get_active (action);
2485 modest_msg_edit_window_set_format_state (window, format_state);
2486 g_free (format_state);
2491 modest_ui_actions_on_toggle_bullets (GtkToggleAction *action,
2492 ModestMsgEditWindow *window)
2494 ModestMsgEditFormatState *format_state = NULL;
2496 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2497 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
2499 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2502 format_state = modest_msg_edit_window_get_format_state (window);
2503 g_return_if_fail (format_state != NULL);
2505 format_state->bullet = gtk_toggle_action_get_active (action);
2506 modest_msg_edit_window_set_format_state (window, format_state);
2507 g_free (format_state);
2512 modest_ui_actions_on_change_justify (GtkRadioAction *action,
2513 GtkRadioAction *selected,
2514 ModestMsgEditWindow *window)
2516 ModestMsgEditFormatState *format_state = NULL;
2517 GtkJustification value;
2519 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2521 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2524 value = gtk_radio_action_get_current_value (selected);
2526 format_state = modest_msg_edit_window_get_format_state (window);
2527 g_return_if_fail (format_state != NULL);
2529 format_state->justification = value;
2530 modest_msg_edit_window_set_format_state (window, format_state);
2531 g_free (format_state);
2535 modest_ui_actions_on_select_editor_color (GtkAction *action,
2536 ModestMsgEditWindow *window)
2538 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2539 g_return_if_fail (GTK_IS_ACTION (action));
2541 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2544 modest_msg_edit_window_select_color (window);
2548 modest_ui_actions_on_select_editor_background_color (GtkAction *action,
2549 ModestMsgEditWindow *window)
2551 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2552 g_return_if_fail (GTK_IS_ACTION (action));
2554 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2557 modest_msg_edit_window_select_background_color (window);
2561 modest_ui_actions_on_insert_image (GtkAction *action,
2562 ModestMsgEditWindow *window)
2564 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2565 g_return_if_fail (GTK_IS_ACTION (action));
2567 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2570 modest_msg_edit_window_insert_image (window);
2574 modest_ui_actions_on_attach_file (GtkAction *action,
2575 ModestMsgEditWindow *window)
2577 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2578 g_return_if_fail (GTK_IS_ACTION (action));
2580 modest_msg_edit_window_offer_attach_file (window);
2584 modest_ui_actions_on_remove_attachments (GtkAction *action,
2585 ModestMsgEditWindow *window)
2587 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2588 g_return_if_fail (GTK_IS_ACTION (action));
2590 modest_msg_edit_window_remove_attachments (window, NULL);
2594 do_create_folder_cb (ModestMailOperation *mail_op,
2595 TnyFolderStore *parent_folder,
2596 TnyFolder *new_folder,
2599 gchar *suggested_name = (gchar *) user_data;
2600 GtkWindow *main_window = (GtkWindow *) modest_mail_operation_get_source (mail_op);
2602 if (modest_mail_operation_get_error (mail_op)) {
2604 modest_platform_information_banner (GTK_WIDGET (main_window), NULL,
2605 _("mail_in_ui_folder_create_error"));
2608 do_create_folder (main_window, parent_folder, (const gchar *) suggested_name);
2610 GtkWidget *folder_view;
2613 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (main_window),
2614 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2616 /* Select the newly created folder */
2617 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view),
2619 g_object_unref (new_folder);
2621 /* Free. Note that the first time it'll be NULL so noop */
2622 g_free (suggested_name);
2623 g_object_unref (main_window);
2627 do_create_folder (GtkWindow *parent_window,
2628 TnyFolderStore *parent_folder,
2629 const gchar *suggested_name)
2632 gchar *folder_name = NULL;
2634 result = modest_platform_run_new_folder_dialog (GTK_WINDOW (parent_window),
2636 (gchar *) suggested_name,
2639 if (result == GTK_RESPONSE_ACCEPT) {
2640 ModestMailOperation *mail_op;
2642 mail_op = modest_mail_operation_new (G_OBJECT(parent_window));
2644 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
2646 modest_mail_operation_create_folder (mail_op,
2648 (const gchar *) folder_name,
2649 do_create_folder_cb,
2651 g_object_unref (mail_op);
2657 modest_ui_actions_create_folder(GtkWidget *parent_window,
2658 GtkWidget *folder_view)
2660 TnyFolderStore *parent_folder;
2662 parent_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
2664 if (parent_folder) {
2666 /* Run the new folder dialog */
2667 do_create_folder (GTK_WINDOW (parent_window), parent_folder, NULL);
2669 g_object_unref (parent_folder);
2674 modest_ui_actions_on_new_folder (GtkAction *action, ModestMainWindow *main_window)
2676 GtkWidget *folder_view;
2678 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2680 folder_view = modest_main_window_get_child_widget (main_window,
2681 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2685 modest_ui_actions_create_folder (GTK_WIDGET (main_window), folder_view);
2689 modest_ui_actions_rename_folder_error_handler (ModestMailOperation *mail_op,
2692 ModestMainWindow *window = MODEST_MAIN_WINDOW (user_data);
2693 const GError *error = NULL;
2694 const gchar *message = NULL;
2696 /* Get error message */
2697 error = modest_mail_operation_get_error (mail_op);
2699 g_return_if_reached ();
2701 switch (error->code) {
2702 case MODEST_MAIL_OPERATION_ERROR_FOLDER_EXISTS:
2703 message = _CS("ckdg_ib_folder_already_exists");
2706 g_warning ("%s: BUG: unexpected error:[%d]: %s", __FUNCTION__,
2707 error->code, error->message);
2711 modest_platform_information_banner (GTK_WIDGET (window), NULL, message);
2715 TnyFolderStore *folder;
2720 on_rename_folder_cb (gboolean canceled, GError *err, GtkWindow *parent_window,
2721 TnyAccount *account, gpointer user_data)
2723 ModestMailOperation *mail_op = NULL;
2724 GtkTreeSelection *sel = NULL;
2725 GtkWidget *folder_view = NULL;
2726 RenameFolderInfo *data = (RenameFolderInfo*)user_data;
2728 if (!canceled && (err == NULL) && MODEST_IS_MAIN_WINDOW(parent_window)) {
2730 folder_view = modest_main_window_get_child_widget (
2731 MODEST_MAIN_WINDOW (parent_window),
2732 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2735 modest_mail_operation_new_with_error_handling (G_OBJECT(parent_window),
2736 modest_ui_actions_rename_folder_error_handler,
2737 parent_window, NULL);
2739 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
2742 /* Clear the headers view */
2743 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_view));
2744 gtk_tree_selection_unselect_all (sel);
2746 /* Select *after* the changes */
2747 modest_folder_view_select_folder (MODEST_FOLDER_VIEW(folder_view),
2748 TNY_FOLDER(data->folder), TRUE);
2750 /* Actually rename the folder */
2751 modest_mail_operation_rename_folder (mail_op,
2752 TNY_FOLDER (data->folder),
2753 (const gchar *) (data->new_name));
2755 /* TODO folder view filter refilter */
2757 GtkTreeModel *tree_model = gtk_tree_view_get_model (GTK_TREE_VIEW (folder_view));
2758 if (GTK_IS_TREE_MODEL_FILTER (tree_model))
2759 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (tree_model)); */
2762 g_object_unref (mail_op);
2763 g_free (data->new_name);
2768 modest_ui_actions_on_rename_folder (GtkAction *action,
2769 ModestMainWindow *main_window)
2771 TnyFolderStore *folder;
2772 GtkWidget *folder_view;
2773 GtkWidget *header_view;
2775 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2777 folder_view = modest_main_window_get_child_widget (main_window,
2778 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2782 header_view = modest_main_window_get_child_widget (main_window,
2783 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2788 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
2793 if (TNY_IS_FOLDER (folder)) {
2796 const gchar *current_name;
2797 TnyFolderStore *parent;
2798 gboolean do_rename = TRUE;
2800 current_name = tny_folder_get_name (TNY_FOLDER (folder));
2801 parent = tny_folder_get_folder_store (TNY_FOLDER (folder));
2802 response = modest_platform_run_rename_folder_dialog (GTK_WINDOW (main_window),
2803 parent, current_name,
2805 g_object_unref (parent);
2807 if (response != GTK_RESPONSE_ACCEPT || strlen (folder_name) == 0) {
2810 RenameFolderInfo *rename_folder_data = g_new0 (RenameFolderInfo, 1);
2811 rename_folder_data->folder = folder;
2812 rename_folder_data->new_name = folder_name;
2813 modest_platform_connect_if_remote_and_perform (GTK_WINDOW(main_window),
2814 folder, on_rename_folder_cb, rename_folder_data);
2817 g_object_unref (folder);
2821 modest_ui_actions_delete_folder_error_handler (ModestMailOperation *mail_op,
2824 GObject *win = modest_mail_operation_get_source (mail_op);
2826 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
2827 _("mail_in_ui_folder_delete_error"));
2828 g_object_unref (win);
2832 TnyFolderStore *folder;
2833 gboolean move_to_trash;
2837 on_delete_folder_cb (gboolean canceled,
2839 GtkWindow *parent_window,
2840 TnyAccount *account,
2843 DeleteFolderInfo *info = (DeleteFolderInfo*) user_data;
2844 GtkWidget *folder_view;
2845 ModestMailOperation *mail_op;
2846 GtkTreeSelection *sel;
2848 if (!MODEST_IS_MAIN_WINDOW(parent_window) || canceled || (err!=NULL)) {
2849 g_object_unref (G_OBJECT (info->folder));
2853 folder_view = modest_main_window_get_child_widget (
2854 MODEST_MAIN_WINDOW (parent_window),
2855 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2857 /* Unselect the folder before deleting it to free the headers */
2858 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_view));
2859 gtk_tree_selection_unselect_all (sel);
2861 /* Create the mail operation */
2863 modest_mail_operation_new_with_error_handling (G_OBJECT(parent_window),
2864 modest_ui_actions_delete_folder_error_handler,
2867 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
2869 modest_mail_operation_remove_folder (mail_op, TNY_FOLDER (info->folder), info->move_to_trash);
2871 modest_folder_view_select_first_inbox_or_local (MODEST_FOLDER_VIEW (folder_view));
2873 g_object_unref (G_OBJECT (mail_op));
2874 g_object_unref (G_OBJECT (info->folder));
2879 delete_folder (ModestMainWindow *main_window, gboolean move_to_trash)
2881 TnyFolderStore *folder;
2882 GtkWidget *folder_view;
2886 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2888 folder_view = modest_main_window_get_child_widget (main_window,
2889 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2893 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
2895 /* Show an error if it's an account */
2896 if (!TNY_IS_FOLDER (folder)) {
2897 modest_platform_run_information_dialog (GTK_WINDOW (main_window),
2898 _("mail_in_ui_folder_delete_error"));
2899 g_object_unref (G_OBJECT (folder));
2904 message = g_strdup_printf (_("mcen_nc_delete_folder_text"),
2905 tny_folder_get_name (TNY_FOLDER (folder)));
2906 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (main_window),
2907 (const gchar *) message);
2910 if (response == GTK_RESPONSE_OK) {
2911 DeleteFolderInfo *info;
2912 info = g_new0(DeleteFolderInfo, 1);
2913 info->folder = folder;
2914 info->move_to_trash = move_to_trash;
2915 g_object_ref (G_OBJECT (info->folder));
2916 TnyAccount *account = tny_folder_get_account(TNY_FOLDER(folder));
2917 modest_platform_connect_and_perform (GTK_WINDOW (main_window),
2918 account, on_delete_folder_cb, info);
2919 g_object_unref (account);
2921 g_object_unref (G_OBJECT (folder));
2925 modest_ui_actions_on_delete_folder (GtkAction *action,
2926 ModestMainWindow *main_window)
2928 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2930 delete_folder (main_window, FALSE);
2934 modest_ui_actions_on_move_folder_to_trash_folder (GtkAction *action, ModestMainWindow *main_window)
2936 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2938 delete_folder (main_window, TRUE);
2943 show_error (GtkWidget *parent_widget, const gchar* text)
2945 modest_platform_information_banner(parent_widget, NULL, text);
2948 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_window, text)); */
2950 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
2957 gtk_dialog_run (dialog);
2958 gtk_widget_destroy (GTK_WIDGET (dialog));
2963 modest_ui_actions_on_password_requested (TnyAccountStore *account_store,
2964 const gchar* server_account_name,
2969 ModestMainWindow *main_window)
2971 g_return_if_fail(server_account_name);
2973 /* Initalize output parameters: */
2980 #ifdef MODEST_PLATFORM_MAEMO
2981 /* Maemo uses a different (awkward) button order,
2982 * It should probably just use gtk_alternative_dialog_button_order ().
2984 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
2987 _("mcen_bd_dialog_ok"),
2988 GTK_RESPONSE_ACCEPT,
2989 _("mcen_bd_dialog_cancel"),
2990 GTK_RESPONSE_REJECT,
2993 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
2997 GTK_RESPONSE_REJECT,
2999 GTK_RESPONSE_ACCEPT,
3001 #endif /* MODEST_PLATFORM_MAEMO */
3003 modest_window_mgr_set_modal (modest_runtime_get_window_mgr(), GTK_WINDOW (dialog));
3005 gchar *server_name = modest_account_mgr_get_server_account_hostname (
3006 modest_runtime_get_account_mgr(), server_account_name);
3007 if (!server_name) {/* This happened once, though I don't know why. murrayc. */
3008 g_warning("%s: Could not get server name for server account '%s'", __FUNCTION__, server_account_name);
3014 /* This causes a warning because the logical ID has no %s in it,
3015 * though the translation does, but there is not much we can do about that: */
3016 gchar *txt = g_strdup_printf (_("mail_ia_password_info"), server_name);
3017 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), gtk_label_new(txt),
3020 g_free (server_name);
3024 gchar *initial_username = modest_account_mgr_get_server_account_username (
3025 modest_runtime_get_account_mgr(), server_account_name);
3027 GtkWidget *entry_username = gtk_entry_new ();
3028 if (initial_username)
3029 gtk_entry_set_text (GTK_ENTRY (entry_username), initial_username);
3030 /* Dim this if a connection has ever succeeded with this username,
3031 * as per the UI spec: */
3032 const gboolean username_known =
3033 modest_account_mgr_get_server_account_username_has_succeeded(
3034 modest_runtime_get_account_mgr(), server_account_name);
3035 gtk_widget_set_sensitive (entry_username, !username_known);
3037 #ifdef MODEST_PLATFORM_MAEMO
3038 /* Auto-capitalization is the default, so let's turn it off: */
3039 hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_username), HILDON_GTK_INPUT_MODE_FULL);
3041 /* Create a size group to be used by all captions.
3042 * Note that HildonCaption does not create a default size group if we do not specify one.
3043 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
3044 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
3046 GtkWidget *caption = hildon_caption_new (sizegroup,
3047 _("mail_fi_username"), entry_username, NULL, HILDON_CAPTION_MANDATORY);
3048 gtk_widget_show (entry_username);
3049 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
3050 FALSE, FALSE, MODEST_MARGIN_HALF);
3051 gtk_widget_show (caption);
3053 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry_username,
3055 #endif /* MODEST_PLATFORM_MAEMO */
3058 GtkWidget *entry_password = gtk_entry_new ();
3059 gtk_entry_set_visibility (GTK_ENTRY(entry_password), FALSE);
3060 /* gtk_entry_set_invisible_char (GTK_ENTRY(entry_password), "*"); */
3062 #ifdef MODEST_PLATFORM_MAEMO
3063 /* Auto-capitalization is the default, so let's turn it off: */
3064 hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_password),
3065 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
3067 caption = hildon_caption_new (sizegroup,
3068 _("mail_fi_password"), entry_password, NULL, HILDON_CAPTION_MANDATORY);
3069 gtk_widget_show (entry_password);
3070 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
3071 FALSE, FALSE, MODEST_MARGIN_HALF);
3072 gtk_widget_show (caption);
3073 g_object_unref (sizegroup);
3075 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry_password,
3077 #endif /* MODEST_PLATFORM_MAEMO */
3079 if (initial_username != NULL)
3080 gtk_widget_grab_focus (GTK_WIDGET (entry_password));
3082 /* This is not in the Maemo UI spec:
3083 remember_pass_check = gtk_check_button_new_with_label (_("Remember password"));
3084 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), remember_pass_check,
3088 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
3090 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
3092 *username = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_username)));
3094 modest_account_mgr_set_server_account_username (
3095 modest_runtime_get_account_mgr(), server_account_name,
3098 const gboolean username_was_changed =
3099 (strcmp (*username, initial_username) != 0);
3100 if (username_was_changed) {
3101 g_warning ("%s: tinymail does not yet support changing the "
3102 "username in the get_password() callback.\n", __FUNCTION__);
3107 *password = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_password)));
3109 /* We do not save the password in the configuration,
3110 * because this function is only called for passwords that should
3111 * not be remembered:
3112 modest_server_account_set_password (
3113 modest_runtime_get_account_mgr(), server_account_name,
3122 show_error(GTK_WIDGET (main_window), _("mail_ib_login_cancelled"));
3134 /* This is not in the Maemo UI spec:
3135 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (remember_pass_check)))
3141 gtk_widget_destroy (dialog);
3143 /* printf ("DEBUG: %s: cancel=%d\n", __FUNCTION__, *cancel); */
3147 modest_ui_actions_on_cut (GtkAction *action,
3148 ModestWindow *window)
3150 GtkWidget *focused_widget;
3151 GtkClipboard *clipboard;
3153 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
3154 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
3155 if (GTK_IS_EDITABLE (focused_widget)) {
3156 gtk_editable_cut_clipboard (GTK_EDITABLE(focused_widget));
3157 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3158 gtk_clipboard_store (clipboard);
3159 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
3160 GtkTextBuffer *buffer;
3162 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
3163 gtk_text_buffer_cut_clipboard (buffer, clipboard, TRUE);
3164 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3165 gtk_clipboard_store (clipboard);
3166 } else if (MODEST_IS_HEADER_VIEW (focused_widget)) {
3167 TnyList *header_list = modest_header_view_get_selected_headers (
3168 MODEST_HEADER_VIEW (focused_widget));
3169 gboolean continue_download = FALSE;
3170 gint num_of_unc_msgs;
3172 num_of_unc_msgs = header_list_count_uncached_msgs(header_list);
3174 if (num_of_unc_msgs) {
3175 TnyAccount *account = get_account_from_header_list (header_list);
3176 continue_download = connect_to_get_msg (window, num_of_unc_msgs, account);
3177 g_object_unref (account);
3180 if (num_of_unc_msgs == 0 || continue_download) {
3181 /* modest_platform_information_banner (
3182 NULL, NULL, _CS("mcen_ib_getting_items"));*/
3183 modest_header_view_cut_selection (
3184 MODEST_HEADER_VIEW (focused_widget));
3187 g_object_unref (header_list);
3188 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
3189 modest_folder_view_cut_selection (MODEST_FOLDER_VIEW (focused_widget));
3194 modest_ui_actions_on_copy (GtkAction *action,
3195 ModestWindow *window)
3197 GtkClipboard *clipboard;
3198 GtkWidget *focused_widget;
3199 gboolean copied = TRUE;
3201 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
3202 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
3204 if (GTK_IS_LABEL (focused_widget)) {
3205 gtk_clipboard_set_text (clipboard, gtk_label_get_text (GTK_LABEL (focused_widget)), -1);
3206 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3207 gtk_clipboard_store (clipboard);
3208 } else if (GTK_IS_EDITABLE (focused_widget)) {
3209 gtk_editable_copy_clipboard (GTK_EDITABLE(focused_widget));
3210 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3211 gtk_clipboard_store (clipboard);
3212 } else if (GTK_IS_HTML (focused_widget)) {
3213 gtk_html_copy (GTK_HTML (focused_widget));
3214 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3215 gtk_clipboard_store (clipboard);
3216 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
3217 GtkTextBuffer *buffer;
3218 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
3219 gtk_text_buffer_copy_clipboard (buffer, clipboard);
3220 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3221 gtk_clipboard_store (clipboard);
3222 } else if (MODEST_IS_HEADER_VIEW (focused_widget)) {
3223 TnyList *header_list = modest_header_view_get_selected_headers (
3224 MODEST_HEADER_VIEW (focused_widget));
3225 gboolean continue_download = FALSE;
3226 gint num_of_unc_msgs;
3228 num_of_unc_msgs = header_list_count_uncached_msgs(header_list);
3230 if (num_of_unc_msgs) {
3231 TnyAccount *account = get_account_from_header_list (header_list);
3232 continue_download = connect_to_get_msg (window, num_of_unc_msgs, account);
3233 g_object_unref (account);
3236 if (num_of_unc_msgs == 0 || continue_download) {
3237 modest_platform_information_banner (
3238 NULL, NULL, _CS("mcen_ib_getting_items"));
3239 modest_header_view_copy_selection (
3240 MODEST_HEADER_VIEW (focused_widget));
3244 g_object_unref (header_list);
3246 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
3247 modest_folder_view_copy_selection (MODEST_FOLDER_VIEW (focused_widget));
3250 /* Show information banner if there was a copy to clipboard */
3252 modest_platform_information_banner (
3253 NULL, NULL, _CS("ecoc_ib_edwin_copied"));
3257 modest_ui_actions_on_undo (GtkAction *action,
3258 ModestWindow *window)
3260 ModestEmailClipboard *clipboard = NULL;
3262 if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
3263 modest_msg_edit_window_undo (MODEST_MSG_EDIT_WINDOW (window));
3264 } else if (MODEST_IS_MAIN_WINDOW (window)) {
3265 /* Clear clipboard source */
3266 clipboard = modest_runtime_get_email_clipboard ();
3267 modest_email_clipboard_clear (clipboard);
3270 g_return_if_reached ();
3275 modest_ui_actions_on_redo (GtkAction *action,
3276 ModestWindow *window)
3278 if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
3279 modest_msg_edit_window_redo (MODEST_MSG_EDIT_WINDOW (window));
3282 g_return_if_reached ();
3288 destroy_information_note (ModestMailOperation *mail_op, gpointer user_data)
3290 /* destroy information note */
3291 gtk_widget_destroy (GTK_WIDGET(user_data));
3296 paste_as_attachment_free (gpointer data)
3298 PasteAsAttachmentHelper *helper = (PasteAsAttachmentHelper *) data;
3300 gtk_widget_destroy (helper->banner);
3301 g_object_unref (helper->banner);
3306 paste_msg_as_attachment_cb (ModestMailOperation *mail_op,
3311 PasteAsAttachmentHelper *helper = (PasteAsAttachmentHelper *) userdata;
3312 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (helper->window));
3317 modest_msg_edit_window_add_part (MODEST_MSG_EDIT_WINDOW (helper->window), TNY_MIME_PART (msg));
3322 modest_ui_actions_on_paste (GtkAction *action,
3323 ModestWindow *window)
3325 GtkWidget *focused_widget = NULL;
3326 GtkWidget *inf_note = NULL;
3327 ModestMailOperation *mail_op = NULL;
3329 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
3330 if (GTK_IS_EDITABLE (focused_widget)) {
3331 gtk_editable_paste_clipboard (GTK_EDITABLE(focused_widget));
3332 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
3333 ModestEmailClipboard *e_clipboard = NULL;
3334 e_clipboard = modest_runtime_get_email_clipboard ();
3335 if (modest_email_clipboard_cleared (e_clipboard)) {
3336 GtkTextBuffer *buffer;
3337 GtkClipboard *clipboard;
3339 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
3340 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
3341 gtk_text_buffer_paste_clipboard (buffer, clipboard, NULL, TRUE);
3342 } else if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
3343 ModestMailOperation *mail_op;
3344 TnyFolder *src_folder;
3347 PasteAsAttachmentHelper *helper = g_new0 (PasteAsAttachmentHelper, 1);
3348 helper->window = MODEST_MSG_EDIT_WINDOW (window);
3349 helper->banner = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
3350 _CS("ckct_nw_pasting"));
3351 modest_email_clipboard_get_data (e_clipboard, &src_folder, &data, &delete);
3352 mail_op = modest_mail_operation_new (G_OBJECT (window));
3353 if (helper->banner != NULL) {
3354 g_object_ref (G_OBJECT (helper->banner));
3355 gtk_window_set_modal (GTK_WINDOW (helper->banner), FALSE);
3356 gtk_widget_show (GTK_WIDGET (helper->banner));
3360 modest_mail_operation_get_msgs_full (mail_op,
3362 (GetMsgAsyncUserCallback) paste_msg_as_attachment_cb,
3364 paste_as_attachment_free);
3367 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
3368 ModestEmailClipboard *clipboard = NULL;
3369 TnyFolder *src_folder = NULL;
3370 TnyFolderStore *folder_store = NULL;
3371 TnyList *data = NULL;
3372 gboolean delete = FALSE;
3374 /* Check clipboard source */
3375 clipboard = modest_runtime_get_email_clipboard ();
3376 if (modest_email_clipboard_cleared (clipboard))
3379 /* Get elements to paste */
3380 modest_email_clipboard_get_data (clipboard, &src_folder, &data, &delete);
3382 /* Create a new mail operation */
3383 mail_op = modest_mail_operation_new (G_OBJECT(window));
3385 /* Get destination folder */
3386 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (focused_widget));
3388 /* transfer messages */
3392 /* Ask for user confirmation */
3394 modest_ui_actions_msgs_move_to_confirmation (window,
3395 TNY_FOLDER (folder_store),
3399 if (response == GTK_RESPONSE_OK) {
3400 /* Launch notification */
3401 inf_note = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
3402 _CS("ckct_nw_pasting"));
3403 if (inf_note != NULL) {
3404 gtk_window_set_modal (GTK_WINDOW(inf_note), FALSE);
3405 gtk_widget_show (GTK_WIDGET(inf_note));
3408 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
3409 modest_mail_operation_xfer_msgs (mail_op,
3411 TNY_FOLDER (folder_store),
3413 destroy_information_note,
3416 g_object_unref (mail_op);
3419 } else if (src_folder != NULL) {
3420 /* Launch notification */
3421 inf_note = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
3422 _CS("ckct_nw_pasting"));
3423 if (inf_note != NULL) {
3424 gtk_window_set_modal (GTK_WINDOW(inf_note), FALSE);
3425 gtk_widget_show (GTK_WIDGET(inf_note));
3428 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
3429 modest_mail_operation_xfer_folder (mail_op,
3433 destroy_information_note,
3439 g_object_unref (data);
3440 if (src_folder != NULL)
3441 g_object_unref (src_folder);
3442 if (folder_store != NULL)
3443 g_object_unref (folder_store);
3449 modest_ui_actions_on_select_all (GtkAction *action,
3450 ModestWindow *window)
3452 GtkWidget *focused_widget;
3454 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
3455 if (MODEST_IS_ATTACHMENTS_VIEW (focused_widget)) {
3456 modest_attachments_view_select_all (MODEST_ATTACHMENTS_VIEW (focused_widget));
3457 } else if (GTK_IS_LABEL (focused_widget)) {
3458 gtk_label_select_region (GTK_LABEL (focused_widget), 0, -1);
3459 } else if (GTK_IS_EDITABLE (focused_widget)) {
3460 gtk_editable_select_region (GTK_EDITABLE(focused_widget), 0, -1);
3461 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
3462 GtkTextBuffer *buffer;
3463 GtkTextIter start, end;
3465 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
3466 gtk_text_buffer_get_start_iter (buffer, &start);
3467 gtk_text_buffer_get_end_iter (buffer, &end);
3468 gtk_text_buffer_select_range (buffer, &start, &end);
3469 } else if (GTK_IS_HTML (focused_widget)) {
3470 gtk_html_select_all (GTK_HTML (focused_widget));
3471 } else if (MODEST_IS_MAIN_WINDOW (window)) {
3472 GtkWidget *header_view = focused_widget;
3473 GtkTreeSelection *selection = NULL;
3475 if (!(MODEST_IS_HEADER_VIEW (focused_widget))) {
3476 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (window),
3477 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
3480 /* Disable window dimming management */
3481 modest_window_disable_dimming (MODEST_WINDOW(window));
3483 /* Select all messages */
3484 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(header_view));
3485 gtk_tree_selection_select_all (selection);
3487 /* Set focuse on header view */
3488 gtk_widget_grab_focus (header_view);
3491 /* Enable window dimming management */
3492 modest_window_enable_dimming (MODEST_WINDOW(window));
3493 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (window));
3499 modest_ui_actions_on_mark_as_read (GtkAction *action,
3500 ModestWindow *window)
3502 g_return_if_fail (MODEST_IS_WINDOW(window));
3504 /* Mark each header as read */
3505 do_headers_action (window, headers_action_mark_as_read, NULL);
3509 modest_ui_actions_on_mark_as_unread (GtkAction *action,
3510 ModestWindow *window)
3512 g_return_if_fail (MODEST_IS_WINDOW(window));
3514 /* Mark each header as read */
3515 do_headers_action (window, headers_action_mark_as_unread, NULL);
3519 modest_ui_actions_on_change_zoom (GtkRadioAction *action,
3520 GtkRadioAction *selected,
3521 ModestWindow *window)
3525 value = gtk_radio_action_get_current_value (selected);
3526 if (MODEST_IS_WINDOW (window)) {
3527 modest_window_set_zoom (MODEST_WINDOW (window), ((gdouble)value)/100);
3532 modest_ui_actions_msg_edit_on_change_priority (GtkRadioAction *action,
3533 GtkRadioAction *selected,
3534 ModestWindow *window)
3536 TnyHeaderFlags flags;
3537 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3539 flags = gtk_radio_action_get_current_value (selected);
3540 modest_msg_edit_window_set_priority_flags (MODEST_MSG_EDIT_WINDOW (window), flags);
3544 modest_ui_actions_msg_edit_on_change_file_format (GtkRadioAction *action,
3545 GtkRadioAction *selected,
3546 ModestWindow *window)
3550 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3552 file_format = gtk_radio_action_get_current_value (selected);
3553 modest_msg_edit_window_set_file_format (MODEST_MSG_EDIT_WINDOW (window), file_format);
3558 modest_ui_actions_on_zoom_plus (GtkAction *action,
3559 ModestWindow *window)
3561 g_return_if_fail (MODEST_IS_WINDOW (window));
3563 modest_window_zoom_plus (MODEST_WINDOW (window));
3567 modest_ui_actions_on_zoom_minus (GtkAction *action,
3568 ModestWindow *window)
3570 g_return_if_fail (MODEST_IS_WINDOW (window));
3572 modest_window_zoom_minus (MODEST_WINDOW (window));
3576 modest_ui_actions_on_toggle_fullscreen (GtkToggleAction *toggle,
3577 ModestWindow *window)
3579 ModestWindowMgr *mgr;
3580 gboolean fullscreen, active;
3581 g_return_if_fail (MODEST_IS_WINDOW (window));
3583 mgr = modest_runtime_get_window_mgr ();
3585 active = (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle)))?1:0;
3586 fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
3588 if (active != fullscreen) {
3589 modest_window_mgr_set_fullscreen_mode (mgr, active);
3590 gtk_window_present (GTK_WINDOW (window));
3595 modest_ui_actions_on_change_fullscreen (GtkAction *action,
3596 ModestWindow *window)
3598 ModestWindowMgr *mgr;
3599 gboolean fullscreen;
3601 g_return_if_fail (MODEST_IS_WINDOW (window));
3603 mgr = modest_runtime_get_window_mgr ();
3604 fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
3605 modest_window_mgr_set_fullscreen_mode (mgr, !fullscreen);
3607 gtk_window_present (GTK_WINDOW (window));
3611 * Used by modest_ui_actions_on_details to call do_headers_action
3614 headers_action_show_details (TnyHeader *header,
3615 ModestWindow *window,
3622 dialog = modest_details_dialog_new_with_header (GTK_WINDOW (window), header);
3625 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
3626 gtk_widget_show_all (dialog);
3627 gtk_dialog_run (GTK_DIALOG (dialog));
3629 gtk_widget_destroy (dialog);
3633 * Show the folder details in a ModestDetailsDialog widget
3636 show_folder_details (TnyFolder *folder,
3642 dialog = modest_details_dialog_new_with_folder (window, folder);
3645 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
3646 gtk_widget_show_all (dialog);
3647 gtk_dialog_run (GTK_DIALOG (dialog));
3649 gtk_widget_destroy (dialog);
3653 * Show the header details in a ModestDetailsDialog widget
3656 modest_ui_actions_on_details (GtkAction *action,
3659 TnyList * headers_list;
3663 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
3666 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW (win));
3669 g_object_unref (msg);
3671 headers_list = get_selected_headers (win);
3675 iter = tny_list_create_iterator (headers_list);
3677 header = TNY_HEADER (tny_iterator_get_current (iter));
3679 headers_action_show_details (header, win, NULL);
3680 g_object_unref (header);
3683 g_object_unref (iter);
3684 g_object_unref (headers_list);
3686 } else if (MODEST_IS_MAIN_WINDOW (win)) {
3687 GtkWidget *folder_view, *header_view;
3689 /* Check which widget has the focus */
3690 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
3691 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3692 if (gtk_widget_is_focus (folder_view)) {
3693 TnyFolderStore *folder_store
3694 = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
3695 if (!folder_store) {
3696 g_warning ("%s: No item was selected.\n", __FUNCTION__);
3699 /* Show only when it's a folder */
3700 /* This function should not be called for account items,
3701 * because we dim the menu item for them. */
3702 if (TNY_IS_FOLDER (folder_store)) {
3703 show_folder_details (TNY_FOLDER (folder_store), GTK_WINDOW (win));
3706 g_object_unref (folder_store);
3709 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
3710 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
3711 /* Show details of each header */
3712 do_headers_action (win, headers_action_show_details, header_view);
3718 modest_ui_actions_on_toggle_show_cc (GtkToggleAction *toggle,
3719 ModestMsgEditWindow *window)
3721 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3723 modest_msg_edit_window_show_cc (window, gtk_toggle_action_get_active (toggle));
3727 modest_ui_actions_on_toggle_show_bcc (GtkToggleAction *toggle,
3728 ModestMsgEditWindow *window)
3730 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3732 modest_msg_edit_window_show_bcc (window, gtk_toggle_action_get_active (toggle));
3736 modest_ui_actions_toggle_folders_view (GtkAction *action,
3737 ModestMainWindow *main_window)
3739 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
3741 if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)))
3742 modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SPLIT);
3744 modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SIMPLE);
3748 modest_ui_actions_on_toggle_toolbar (GtkToggleAction *toggle,
3749 ModestWindow *window)
3751 gboolean active, fullscreen = FALSE;
3752 ModestWindowMgr *mgr;
3754 active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle));
3756 /* Check if we want to toggle the toolbar vuew in fullscreen
3758 if (!strcmp (gtk_action_get_name (GTK_ACTION (toggle)),
3759 "ViewShowToolbarFullScreen")) {
3763 /* Toggle toolbar */
3764 mgr = modest_runtime_get_window_mgr ();
3765 modest_window_mgr_show_toolbars (mgr, G_TYPE_FROM_INSTANCE (window), active, fullscreen);
3769 modest_ui_actions_msg_edit_on_select_font (GtkAction *action,
3770 ModestMsgEditWindow *window)
3772 modest_msg_edit_window_select_font (window);
3776 modest_ui_actions_on_folder_display_name_changed (ModestFolderView *folder_view,
3777 const gchar *display_name,
3780 /* This is usually used to change the title of the main window, which
3781 * is the one that holds the folder view. Note that this change can
3782 * happen even when the widget doesn't have the focus. */
3784 gtk_window_set_title (window, display_name);
3786 gtk_window_set_title (window, " ");
3790 modest_ui_actions_on_select_contacts (GtkAction *action, ModestMsgEditWindow *window)
3792 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3793 modest_msg_edit_window_select_contacts (window);
3797 modest_ui_actions_on_check_names (GtkAction *action, ModestMsgEditWindow *window)
3799 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3800 modest_msg_edit_window_check_names (window, FALSE);
3804 create_move_to_dialog_on_new_folder(GtkWidget *button, gpointer user_data)
3806 modest_ui_actions_create_folder (gtk_widget_get_toplevel (button),
3807 GTK_WIDGET (user_data));
3811 * This function is used to track changes in the selection of the
3812 * folder view that is inside the "move to" dialog to enable/disable
3813 * the OK button because we do not want the user to select a disallowed
3814 * destination for a folder.
3815 * The user also not desired to be able to use NEW button on items where
3816 * folder creation is not possibel.
3819 on_move_to_dialog_folder_selection_changed (ModestFolderView* self,
3820 TnyFolderStore *folder_store,
3824 GtkWidget *dialog = NULL;
3825 GtkWidget *ok_button = NULL, *new_button = NULL;
3826 GList *children = NULL;
3827 gboolean ok_sensitive = TRUE, new_sensitive = TRUE;
3828 gboolean moving_folder = FALSE;
3829 gboolean is_local_account = TRUE;
3830 GtkWidget *folder_view = NULL;
3831 ModestTnyFolderRules rules;
3836 /* Get the OK button */
3837 dialog = gtk_widget_get_ancestor (GTK_WIDGET (self), GTK_TYPE_DIALOG);
3841 children = gtk_container_get_children (GTK_CONTAINER (GTK_DIALOG (dialog)->action_area));
3842 ok_button = GTK_WIDGET (children->next->next->data);
3843 new_button = GTK_WIDGET (children->next->data);
3844 g_list_free (children);
3846 /* check if folder_store is an remote account */
3847 if (TNY_IS_ACCOUNT (folder_store)) {
3848 TnyAccount *local_account = NULL;
3849 TnyAccount *mmc_account = NULL;
3850 ModestTnyAccountStore *account_store = NULL;
3852 account_store = modest_runtime_get_account_store ();
3853 local_account = modest_tny_account_store_get_local_folders_account (account_store);
3854 mmc_account = modest_tny_account_store_get_mmc_folders_account (account_store);
3856 if ((gpointer) local_account != (gpointer) folder_store &&
3857 (gpointer) mmc_account != (gpointer) folder_store) {
3858 is_local_account = FALSE;
3859 /* New button should be dimmed on remote
3861 new_sensitive = FALSE;
3863 g_object_unref (local_account);
3866 /* Check the target folder rules */
3867 if (TNY_IS_FOLDER (folder_store)) {
3868 rules = modest_tny_folder_get_rules (TNY_FOLDER (folder_store));
3869 if (rules & MODEST_FOLDER_RULES_FOLDER_NON_WRITEABLE) {
3870 ok_sensitive = FALSE;
3871 new_sensitive = FALSE;
3876 /* Check if we're moving a folder */
3877 if (MODEST_IS_MAIN_WINDOW (user_data)) {
3878 /* Get the widgets */
3879 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (user_data),
3880 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3881 if (gtk_widget_is_focus (folder_view))
3882 moving_folder = TRUE;
3885 if (moving_folder) {
3886 TnyFolderStore *moved_folder = NULL, *parent = NULL;
3888 /* Get the folder to move */
3889 moved_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
3891 /* Check that we're not moving to the same folder */
3892 if (TNY_IS_FOLDER (moved_folder)) {
3893 parent = tny_folder_get_folder_store (TNY_FOLDER (moved_folder));
3894 if (parent == folder_store)
3895 ok_sensitive = FALSE;
3896 g_object_unref (parent);
3899 if (ok_sensitive && TNY_IS_ACCOUNT (folder_store)) {
3900 /* Do not allow to move to an account unless it's the
3901 local folders account */
3902 if (!is_local_account)
3903 ok_sensitive = FALSE;
3906 if (ok_sensitive && (moved_folder == folder_store)) {
3907 /* Do not allow to move to itself */
3908 ok_sensitive = FALSE;
3910 g_object_unref (moved_folder);
3912 TnyHeader *header = NULL;
3913 TnyFolder *src_folder = NULL;
3915 /* Moving a message */
3916 if (MODEST_IS_MSG_VIEW_WINDOW (user_data)) {
3917 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (user_data));
3918 src_folder = tny_header_get_folder (header);
3919 g_object_unref (header);
3922 TNY_FOLDER (modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view)));
3925 /* Do not allow to move the msg to the same folder */
3926 /* Do not allow to move the msg to an account */
3927 if ((gpointer) src_folder == (gpointer) folder_store ||
3928 TNY_IS_ACCOUNT (folder_store))
3929 ok_sensitive = FALSE;
3930 g_object_unref (src_folder);
3934 /* Set sensitivity of the OK button */
3935 gtk_widget_set_sensitive (ok_button, ok_sensitive);
3936 /* Set sensitivity of the NEW button */
3937 gtk_widget_set_sensitive (new_button, new_sensitive);
3941 create_move_to_dialog (GtkWindow *win,
3942 GtkWidget *folder_view,
3943 GtkWidget **tree_view)
3945 GtkWidget *dialog, *scroll;
3946 GtkWidget *new_button;
3948 dialog = gtk_dialog_new_with_buttons (_("mcen_ti_moveto_folders_title"),
3950 GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR | GTK_DIALOG_DESTROY_WITH_PARENT,
3953 gtk_dialog_add_button (GTK_DIALOG (dialog), _("mcen_bd_dialog_ok"), GTK_RESPONSE_ACCEPT);
3954 /* We do this manually so GTK+ does not associate a response ID for
3956 new_button = gtk_button_new_from_stock (_("mcen_bd_new"));
3957 gtk_box_pack_end (GTK_BOX (GTK_DIALOG (dialog)->action_area), new_button, FALSE, FALSE, 0);
3958 gtk_dialog_add_button (GTK_DIALOG (dialog), _("mcen_bd_dialog_cancel"), GTK_RESPONSE_REJECT);
3960 /* Create scrolled window */
3961 scroll = gtk_scrolled_window_new (NULL, NULL);
3962 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll),
3963 GTK_POLICY_AUTOMATIC,
3964 GTK_POLICY_AUTOMATIC);
3966 /* Create folder view */
3967 *tree_view = modest_platform_create_folder_view (NULL);
3969 /* Track changes in the selection to
3970 * disable the OK button whenever "Move to" is not possible
3971 * disbale NEW button whenever New is not possible */
3972 g_signal_connect (*tree_view,
3973 "folder_selection_changed",
3974 G_CALLBACK (on_move_to_dialog_folder_selection_changed),
3977 /* Listen to clicks on New button */
3978 g_signal_connect (G_OBJECT (new_button),
3980 G_CALLBACK(create_move_to_dialog_on_new_folder),
3983 /* It could happen that we're trying to move a message from a
3984 window (msg window for example) after the main window was
3985 closed, so we can not just get the model of the folder
3987 if (MODEST_IS_FOLDER_VIEW (folder_view)) {
3988 const gchar *visible_id = NULL;
3990 modest_folder_view_set_style (MODEST_FOLDER_VIEW (*tree_view),
3991 MODEST_FOLDER_VIEW_STYLE_SHOW_ALL);
3992 modest_folder_view_copy_model (MODEST_FOLDER_VIEW(folder_view),
3993 MODEST_FOLDER_VIEW(*tree_view));
3996 modest_folder_view_get_account_id_of_visible_server_account (MODEST_FOLDER_VIEW(folder_view));
3998 /* Show the same account than the one that is shown in the main window */
3999 modest_folder_view_set_account_id_of_visible_server_account (MODEST_FOLDER_VIEW(*tree_view),
4002 const gchar *active_account_name = NULL;
4003 ModestAccountMgr *mgr = NULL;
4004 ModestAccountSettings *settings = NULL;
4005 ModestServerAccountSettings *store_settings = NULL;
4007 modest_folder_view_set_style (MODEST_FOLDER_VIEW (*tree_view),
4008 MODEST_FOLDER_VIEW_STYLE_SHOW_ALL);
4009 modest_folder_view_update_model (MODEST_FOLDER_VIEW (*tree_view),
4010 TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()));
4012 active_account_name = modest_window_get_active_account (MODEST_WINDOW (win));
4013 mgr = modest_runtime_get_account_mgr ();
4014 settings = modest_account_mgr_load_account_settings (mgr, active_account_name);
4017 const gchar *store_account_name;
4018 store_settings = modest_account_settings_get_store_settings (settings);
4019 store_account_name = modest_server_account_settings_get_account_name (store_settings);
4021 modest_folder_view_set_account_id_of_visible_server_account (MODEST_FOLDER_VIEW (*tree_view),
4022 store_account_name);
4023 g_object_unref (store_settings);
4024 g_object_unref (settings);
4028 /* Hide special folders */
4029 modest_folder_view_show_non_move_folders (MODEST_FOLDER_VIEW (*tree_view), FALSE);
4031 gtk_container_add (GTK_CONTAINER (scroll), *tree_view);
4033 /* Add scroll to dialog */
4034 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
4035 scroll, TRUE, TRUE, 0);
4037 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
4038 gtk_window_set_default_size (GTK_WINDOW (dialog), 300, 300);
4044 * Returns TRUE if at least one of the headers of the list belongs to
4045 * a message that has been fully retrieved.
4047 #if 0 /* no longer in use. delete in 2007.10 */
4049 has_retrieved_msgs (TnyList *list)
4052 gboolean found = FALSE;
4054 iter = tny_list_create_iterator (list);
4055 while (!tny_iterator_is_done (iter) && !found) {
4057 TnyHeaderFlags flags = 0;
4059 header = TNY_HEADER (tny_iterator_get_current (iter));
4061 flags = tny_header_get_flags (header);
4062 if (flags & TNY_HEADER_FLAG_CACHED)
4063 /* if (!(flags & TNY_HEADER_FLAG_PARTIAL)) */
4066 g_object_unref (header);
4070 tny_iterator_next (iter);
4072 g_object_unref (iter);
4080 * Shows a confirmation dialog to the user when we're moving messages
4081 * from a remote server to the local storage. Returns the dialog
4082 * response. If it's other kind of movement then it always returns
4085 * This one is used by the next functions:
4086 * modest_ui_actions_on_paste - commented out
4087 * drag_and_drop_from_header_view (for d&d in modest_folder_view.c)
4090 modest_ui_actions_msgs_move_to_confirmation (ModestWindow *win,
4091 TnyFolder *dest_folder,
4095 gint response = GTK_RESPONSE_OK;
4096 TnyAccount *account = NULL;
4097 TnyFolder *src_folder = NULL;
4098 TnyIterator *iter = NULL;
4099 TnyHeader *header = NULL;
4101 /* return with OK if the destination is a remote folder */
4102 if (modest_tny_folder_is_remote_folder (dest_folder))
4103 return GTK_RESPONSE_OK;
4105 /* Get source folder */
4106 iter = tny_list_create_iterator (headers);
4107 header = TNY_HEADER (tny_iterator_get_current (iter));
4109 src_folder = tny_header_get_folder (header);
4110 g_object_unref (header);
4112 g_object_unref (iter);
4114 /* if no src_folder, message may be an attahcment */
4115 if (src_folder == NULL)
4116 return GTK_RESPONSE_CANCEL;
4118 /* If the source is a local or MMC folder */
4119 if (!modest_tny_folder_is_remote_folder (src_folder)) {
4120 g_object_unref (src_folder);
4121 return GTK_RESPONSE_OK;
4124 /* Get the account */
4125 account = tny_folder_get_account (src_folder);
4127 /* now if offline we ask the user */
4128 if(connect_to_get_msg (win, tny_list_get_length (headers), account))
4129 response = GTK_RESPONSE_OK;
4131 response = GTK_RESPONSE_CANCEL;
4134 g_object_unref (src_folder);
4135 g_object_unref (account);
4143 move_to_cb (ModestMailOperation *mail_op, gpointer user_data)
4145 MoveToHelper *helper = (MoveToHelper *) user_data;
4147 /* Note that the operation could have failed, in that case do
4149 if (modest_mail_operation_get_status (mail_op) ==
4150 MODEST_MAIL_OPERATION_STATUS_SUCCESS) {
4152 GObject *object = modest_mail_operation_get_source (mail_op);
4153 if (MODEST_IS_MSG_VIEW_WINDOW (object)) {
4154 ModestMsgViewWindow *self = MODEST_MSG_VIEW_WINDOW (object);
4156 if (!modest_msg_view_window_select_next_message (self))
4157 if (!modest_msg_view_window_select_previous_message (self))
4158 /* No more messages to view, so close this window */
4159 modest_ui_actions_on_close_window (NULL, MODEST_WINDOW(self));
4160 } else if (MODEST_IS_MAIN_WINDOW (object) && helper->reference != NULL) {
4161 GtkWidget *header_view;
4163 GtkTreeSelection *sel;
4165 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(object),
4166 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
4167 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
4168 path = gtk_tree_row_reference_get_path (helper->reference);
4169 gtk_tree_selection_select_path (sel, path);
4170 gtk_tree_path_free (path);
4172 g_object_unref (object);
4175 /* Close the "Pasting" information banner */
4176 gtk_widget_destroy (GTK_WIDGET(helper->banner));
4177 if (helper->reference != NULL)
4178 gtk_tree_row_reference_free (helper->reference);
4183 modest_ui_actions_move_folder_error_handler (ModestMailOperation *mail_op,
4186 ModestWindow *main_window = NULL;
4187 GObject *win = NULL;
4189 /* Disable next automatic folder selection */
4190 main_window = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (),
4191 FALSE); /* don't create */
4193 GtkWidget *folder_view = NULL;
4195 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (main_window),
4196 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
4197 modest_folder_view_disable_next_folder_selection (MODEST_FOLDER_VIEW(folder_view));
4199 if (user_data && TNY_IS_FOLDER (user_data)) {
4200 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view),
4201 TNY_FOLDER (user_data), FALSE);
4205 /* Show notification dialog */
4206 win = modest_mail_operation_get_source (mail_op);
4207 modest_platform_run_information_dialog ((GtkWindow *) win, _("mail_in_ui_folder_move_target_error"));
4209 g_object_unref (win);
4213 modest_ui_actions_send_receive_error_handler (ModestMailOperation *mail_op,
4216 GObject *win = modest_mail_operation_get_source (mail_op);
4217 const GError *error = modest_mail_operation_get_error (mail_op);
4219 g_return_if_fail (error != NULL);
4220 if (error->message != NULL)
4221 g_printerr ("modest: %s\n", error->message);
4223 g_printerr ("modest: unkonw error on send&receive operation");
4225 /* Show error message */
4226 /* if (modest_mail_operation_get_id (mail_op) == MODEST_MAIL_OPERATION_TYPE_RECEIVE) */
4227 /* modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL, */
4228 /* _CS("sfil_ib_unable_to_receive")); */
4230 /* modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL, */
4231 /* _CS("sfil_ib_unable_to_send")); */
4232 g_object_unref (win);
4236 open_msg_for_purge_cb (ModestMailOperation *mail_op,
4245 gint pending_purges = 0;
4246 gboolean some_purged = FALSE;
4247 ModestWindow *win = MODEST_WINDOW (user_data);
4248 ModestWindowMgr *mgr = modest_runtime_get_window_mgr ();
4250 /* If there was any error */
4251 if (!modest_ui_actions_msg_retrieval_check (mail_op, header, msg)) {
4252 modest_window_mgr_unregister_header (mgr, header);
4256 /* Once the message has been retrieved for purging, we check if
4257 * it's all ok for purging */
4259 parts = tny_simple_list_new ();
4260 tny_mime_part_get_parts (TNY_MIME_PART (msg), parts);
4261 iter = tny_list_create_iterator (parts);
4263 while (!tny_iterator_is_done (iter)) {
4265 part = TNY_MIME_PART (tny_iterator_get_current (iter));
4266 if (part && (tny_mime_part_is_attachment (part) || TNY_IS_MSG (part))) {
4267 if (tny_mime_part_is_purged (part))
4274 g_object_unref (part);
4276 tny_iterator_next (iter);
4278 g_object_unref (iter);
4281 if (pending_purges>0) {
4283 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),_("mcen_nc_purge_file_text_inbox"));
4285 if (response == GTK_RESPONSE_OK) {
4286 modest_platform_information_banner (NULL, NULL, _("mcen_ib_removing_attachment"));
4287 iter = tny_list_create_iterator (parts);
4288 while (!tny_iterator_is_done (iter)) {
4291 part = TNY_MIME_PART (tny_iterator_get_current (iter));
4292 if (part && (tny_mime_part_is_attachment (part) || TNY_IS_MSG (part)))
4293 tny_mime_part_set_purged (part);
4296 g_object_unref (part);
4298 tny_iterator_next (iter);
4301 tny_msg_rewrite_cache (msg);
4304 /* This string no longer exists, refer to NB#75415 for more info */
4305 /* modest_platform_information_banner (NULL, NULL, _("mail_ib_attachment_already_purged")); */
4307 g_object_unref (iter);
4309 modest_window_mgr_unregister_header (mgr, header);
4311 g_object_unref (parts);
4315 modest_ui_actions_on_main_window_remove_attachments (GtkAction *action,
4316 ModestMainWindow *win)
4318 GtkWidget *header_view;
4319 TnyList *header_list;
4322 TnyHeaderFlags flags;
4323 ModestWindow *msg_view_window = NULL;
4326 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win));
4328 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
4329 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
4331 header_list = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW (header_view));
4333 g_warning ("%s: no header selected", __FUNCTION__);
4337 if (tny_list_get_length (header_list) == 1) {
4338 iter = tny_list_create_iterator (header_list);
4339 header = TNY_HEADER (tny_iterator_get_current (iter));
4340 g_object_unref (iter);
4344 if (!header || !TNY_IS_HEADER(header)) {
4345 g_warning ("%s: header is not valid", __FUNCTION__);
4349 found = modest_window_mgr_find_registered_header (modest_runtime_get_window_mgr (),
4350 header, &msg_view_window);
4351 flags = tny_header_get_flags (header);
4352 if (!(flags & TNY_HEADER_FLAG_CACHED))
4355 if (msg_view_window != NULL)
4356 modest_msg_view_window_remove_attachments (MODEST_MSG_VIEW_WINDOW (msg_view_window), TRUE);
4358 /* do nothing; uid was registered before, so window is probably on it's way */
4359 g_warning ("debug: header %p has already been registered", header);
4362 ModestMailOperation *mail_op = NULL;
4363 modest_window_mgr_register_header (modest_runtime_get_window_mgr (), header, NULL);
4364 mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT (win),
4365 modest_ui_actions_get_msgs_full_error_handler,
4367 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
4368 modest_mail_operation_get_msg (mail_op, header, open_msg_for_purge_cb, win);
4370 g_object_unref (mail_op);
4373 g_object_unref (header);
4375 g_object_unref (header_list);
4379 * Utility function that transfer messages from both the main window
4380 * and the msg view window when using the "Move to" dialog
4383 xfer_messages_from_move_to_cb (gboolean canceled, GError *err,
4384 GtkWindow *parent_window,
4385 TnyAccount *account, gpointer user_data)
4387 TnyFolderStore *dst_folder = TNY_FOLDER_STORE (user_data);
4388 ModestWindow *win = MODEST_WINDOW (parent_window);
4389 TnyList *headers = NULL;
4390 TnyAccount *dst_account = NULL;
4391 const gchar *proto_str = NULL;
4392 gboolean dst_is_pop = FALSE;
4394 if (canceled || err) {
4395 g_object_unref (dst_folder);
4399 if (!TNY_IS_FOLDER (dst_folder)) {
4400 modest_platform_information_banner (GTK_WIDGET (win),
4402 _CS("ckdg_ib_unable_to_move_to_current_location"));
4406 dst_account = tny_folder_get_account (TNY_FOLDER (dst_folder));
4407 proto_str = tny_account_get_proto (dst_account);
4409 /* tinymail will return NULL for local folders it seems */
4410 dst_is_pop = proto_str &&
4411 (modest_protocol_info_get_transport_store_protocol (proto_str) ==
4412 MODEST_PROTOCOL_STORE_POP);
4414 g_object_unref (dst_account);
4416 /* Get selected headers */
4417 headers = get_selected_headers (MODEST_WINDOW (win));
4419 g_warning ("%s: no headers selected", __FUNCTION__);
4425 modest_platform_information_banner (GTK_WIDGET (win),
4427 ngettext("mail_in_ui_folder_move_target_error",
4428 "mail_in_ui_folder_move_targets_error",
4429 tny_list_get_length (headers)));
4430 g_object_unref (headers);
4434 MoveToHelper *helper = g_new0 (MoveToHelper, 1);
4435 helper->banner = modest_platform_animation_banner (GTK_WIDGET (win), NULL,
4436 _CS("ckct_nw_pasting"));
4437 if (helper->banner != NULL) {
4438 gtk_window_set_modal (GTK_WINDOW(helper->banner), FALSE);
4439 gtk_widget_show (GTK_WIDGET(helper->banner));
4442 if (MODEST_IS_MAIN_WINDOW (win)) {
4443 GtkWidget *header_view =
4444 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
4445 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
4446 helper->reference = get_next_after_selected_headers (MODEST_HEADER_VIEW (header_view));
4449 ModestMailOperation *mail_op =
4450 modest_mail_operation_new_with_error_handling (G_OBJECT(win),
4451 modest_ui_actions_move_folder_error_handler,
4453 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
4456 modest_mail_operation_xfer_msgs (mail_op,
4458 TNY_FOLDER (dst_folder),
4463 g_object_unref (G_OBJECT (mail_op));
4464 g_object_unref (headers);
4465 g_object_unref (dst_folder);
4469 TnyFolder *src_folder;
4470 TnyFolderStore *dst_folder;
4471 gboolean delete_original;
4472 GtkWidget *folder_view;
4476 on_move_folder_cb (gboolean canceled, GError *err, GtkWindow *parent_window,
4477 TnyAccount *account, gpointer user_data)
4479 MoveFolderInfo *info = (MoveFolderInfo*)user_data;
4480 GtkTreeSelection *sel;
4481 ModestMailOperation *mail_op = NULL;
4483 if (canceled || err || !MODEST_IS_MAIN_WINDOW (parent_window)) {
4484 g_object_unref (G_OBJECT (info->src_folder));
4485 g_object_unref (G_OBJECT (info->dst_folder));
4490 MoveToHelper *helper = g_new0 (MoveToHelper, 1);
4491 helper->banner = modest_platform_animation_banner (GTK_WIDGET (parent_window), NULL,
4492 _CS("ckct_nw_pasting"));
4493 if (helper->banner != NULL) {
4494 gtk_window_set_modal (GTK_WINDOW(helper->banner), FALSE);
4495 gtk_widget_show (GTK_WIDGET(helper->banner));
4497 /* Clean folder on header view before moving it */
4498 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (info->folder_view));
4499 gtk_tree_selection_unselect_all (sel);
4501 /* Let gtk events run. We need that the folder
4502 view frees its reference to the source
4503 folder *before* issuing the mail operation
4504 so we need the signal handler of selection
4505 changed to happen before the mail
4507 while (gtk_events_pending ())
4508 gtk_main_iteration (); */
4511 modest_mail_operation_new_with_error_handling (G_OBJECT(parent_window),
4512 modest_ui_actions_move_folder_error_handler,
4513 info->src_folder, NULL);
4514 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
4517 /* Select *after* the changes */
4518 /* TODO: this function hangs UI after transfer */
4519 /* modest_folder_view_select_folder (MODEST_FOLDER_VIEW(folder_view), */
4520 /* TNY_FOLDER (src_folder), TRUE); */
4522 modest_mail_operation_xfer_folder (mail_op,
4523 TNY_FOLDER (info->src_folder),
4525 info->delete_original,
4529 modest_folder_view_select_folder (MODEST_FOLDER_VIEW(info->folder_view),
4530 TNY_FOLDER (info->dst_folder), TRUE);
4532 /* Unref mail operation */
4533 g_object_unref (G_OBJECT (mail_op));
4534 g_object_unref (G_OBJECT (info->src_folder));
4535 g_object_unref (G_OBJECT (info->dst_folder));
4540 * UI handler for the "Move to" action when invoked from the
4544 modest_ui_actions_on_main_window_move_to (GtkAction *action,
4545 GtkWidget *folder_view,
4546 TnyFolderStore *dst_folder,
4547 ModestMainWindow *win)
4549 ModestHeaderView *header_view = NULL;
4550 TnyFolderStore *src_folder;
4551 gboolean online = (tny_device_is_online (modest_runtime_get_device()));
4553 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win));
4555 /* Get the source folder */
4556 src_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
4558 /* Get header view */
4559 header_view = MODEST_HEADER_VIEW(modest_main_window_get_child_widget (win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW));
4561 /* Get folder or messages to transfer */
4562 if (gtk_widget_is_focus (folder_view)) {
4563 gboolean do_xfer = TRUE;
4565 /* Allow only to transfer folders to the local root folder */
4566 if (TNY_IS_ACCOUNT (dst_folder) &&
4567 !MODEST_IS_TNY_LOCAL_FOLDERS_ACCOUNT (dst_folder)) {
4569 } else if (!TNY_IS_FOLDER (src_folder)) {
4570 g_warning ("%s: src_folder is not a TnyFolder.\n", __FUNCTION__);
4572 } /* else if (!online && modest_tny_folder_store_is_remote(src_folder)) {
4573 guint num_headers = tny_folder_get_all_count(TNY_FOLDER (src_folder));
4574 TnyAccount *account = tny_folder_get_account (TNY_FOLDER (src_folder));
4575 if (!connect_to_get_msg(MODEST_WINDOW (win), num_headers, account))
4577 g_object_unref (account);
4581 MoveFolderInfo *info = g_new0 (MoveFolderInfo, 1);
4582 info->src_folder = TNY_FOLDER (src_folder);
4583 info->dst_folder = dst_folder;
4584 info->delete_original = TRUE;
4585 info->folder_view = folder_view;
4586 g_object_ref (G_OBJECT (info->src_folder));
4587 g_object_ref (G_OBJECT (info->dst_folder));
4588 modest_platform_connect_if_remote_and_perform(GTK_WINDOW (win),
4589 TNY_FOLDER_STORE (dst_folder), on_move_folder_cb, info);
4591 } else if (gtk_widget_is_focus (GTK_WIDGET(header_view))) {
4592 gboolean do_xfer = TRUE;
4593 /* Ask for confirmation if the source folder is remote and we're not connected */
4594 if (!online && modest_tny_folder_store_is_remote(src_folder)) {
4595 TnyList *headers = modest_header_view_get_selected_headers(header_view);
4596 if (!msgs_already_deleted_from_server(headers, src_folder)) {
4597 guint num_headers = tny_list_get_length(headers);
4598 TnyAccount *account = get_account_from_header_list (headers);
4599 if (!connect_to_get_msg(MODEST_WINDOW (win), num_headers, account))
4601 g_object_unref (account);
4603 g_object_unref(headers);
4605 if (do_xfer) /* Transfer messages */ {
4606 g_object_ref (dst_folder);
4607 modest_platform_connect_if_remote_and_perform(GTK_WINDOW (win),
4608 TNY_FOLDER_STORE (dst_folder), xfer_messages_from_move_to_cb, dst_folder);
4613 g_object_unref (src_folder);
4618 * UI handler for the "Move to" action when invoked from the
4619 * ModestMsgViewWindow
4622 modest_ui_actions_on_msg_view_window_move_to (GtkAction *action,
4623 TnyFolderStore *dst_folder,
4624 ModestMsgViewWindow *win)
4626 TnyHeader *header = NULL;
4627 TnyFolder *src_folder = NULL;
4628 TnyAccount *account = NULL;
4629 gboolean do_xfer = FALSE;
4631 /* Create header list */
4632 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
4633 src_folder = TNY_FOLDER (tny_header_get_folder(header));
4634 g_object_unref (header);
4636 account = tny_folder_get_account (src_folder);
4637 if (!modest_tny_folder_store_is_remote(TNY_FOLDER_STORE(src_folder))) {
4638 /* Transfer if the source folder is local */
4640 } else if (remote_folder_is_pop(TNY_FOLDER_STORE(src_folder))) {
4641 /* Transfer if the source folder is POP (as it means
4642 * that the message is already downloaded) */
4644 } else if (connect_to_get_msg(MODEST_WINDOW(win), 1, account)) {
4645 /* Transfer after asking confirmation */
4650 g_object_ref (dst_folder);
4651 modest_platform_connect_if_remote_and_perform(GTK_WINDOW (win),
4652 TNY_FOLDER_STORE (dst_folder), xfer_messages_from_move_to_cb, dst_folder);
4654 g_object_unref (account);
4655 g_object_unref (src_folder);
4659 modest_ui_actions_on_move_to (GtkAction *action,
4662 GtkWidget *dialog = NULL, *folder_view = NULL, *tree_view = NULL;
4664 TnyFolderStore *dst_folder = NULL;
4665 ModestMainWindow *main_window;
4667 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win) ||
4668 MODEST_IS_MSG_VIEW_WINDOW (win));
4670 /* Get the main window if exists */
4671 if (MODEST_IS_MAIN_WINDOW (win))
4672 main_window = MODEST_MAIN_WINDOW (win);
4675 MODEST_MAIN_WINDOW (modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (),
4676 FALSE)); /* don't create */
4678 /* Get the folder view widget if exists */
4680 folder_view = modest_main_window_get_child_widget (main_window,
4681 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
4685 /* Create and run the dialog */
4686 dialog = create_move_to_dialog (GTK_WINDOW (win), folder_view, &tree_view);
4687 modest_folder_view_select_first_inbox_or_local (MODEST_FOLDER_VIEW (tree_view));
4688 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
4689 result = gtk_dialog_run (GTK_DIALOG(dialog));
4690 g_object_ref (tree_view);
4691 gtk_widget_destroy (dialog);
4693 if (result != GTK_RESPONSE_ACCEPT)
4696 dst_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (tree_view));
4697 /* Do window specific stuff */
4698 if (MODEST_IS_MAIN_WINDOW (win)) {
4699 modest_ui_actions_on_main_window_move_to (action,
4702 MODEST_MAIN_WINDOW (win));
4704 modest_ui_actions_on_msg_view_window_move_to (action,
4706 MODEST_MSG_VIEW_WINDOW (win));
4710 g_object_unref (dst_folder);
4714 * Calls #HeadersFunc for each header already selected in the main
4715 * window or the message currently being shown in the msg view window
4718 do_headers_action (ModestWindow *win,
4722 TnyList *headers_list = NULL;
4723 TnyIterator *iter = NULL;
4724 TnyHeader *header = NULL;
4725 TnyFolder *folder = NULL;
4728 headers_list = get_selected_headers (win);
4732 /* Get the folder */
4733 iter = tny_list_create_iterator (headers_list);
4734 header = TNY_HEADER (tny_iterator_get_current (iter));
4736 folder = tny_header_get_folder (header);
4737 g_object_unref (header);
4740 /* Call the function for each header */
4741 while (!tny_iterator_is_done (iter)) {
4742 header = TNY_HEADER (tny_iterator_get_current (iter));
4743 func (header, win, user_data);
4744 g_object_unref (header);
4745 tny_iterator_next (iter);
4748 /* Trick: do a poke status in order to speed up the signaling
4750 tny_folder_poke_status (folder);
4753 g_object_unref (folder);
4754 g_object_unref (iter);
4755 g_object_unref (headers_list);
4759 modest_ui_actions_view_attachment (GtkAction *action,
4760 ModestWindow *window)
4762 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
4763 modest_msg_view_window_view_attachment (MODEST_MSG_VIEW_WINDOW (window), NULL);
4765 /* not supported window for this action */
4766 g_return_if_reached ();
4771 modest_ui_actions_save_attachments (GtkAction *action,
4772 ModestWindow *window)
4774 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
4775 modest_msg_view_window_save_attachments (MODEST_MSG_VIEW_WINDOW (window), NULL);
4777 /* not supported window for this action */
4778 g_return_if_reached ();
4783 modest_ui_actions_remove_attachments (GtkAction *action,
4784 ModestWindow *window)
4786 if (MODEST_IS_MAIN_WINDOW (window)) {
4787 modest_ui_actions_on_main_window_remove_attachments (action, MODEST_MAIN_WINDOW (window));
4788 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
4789 modest_msg_view_window_remove_attachments (MODEST_MSG_VIEW_WINDOW (window), FALSE);
4791 /* not supported window for this action */
4792 g_return_if_reached ();
4797 modest_ui_actions_on_settings (GtkAction *action,
4802 dialog = modest_platform_get_global_settings_dialog ();
4803 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (win));
4804 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
4805 gtk_widget_show_all (dialog);
4807 gtk_dialog_run (GTK_DIALOG (dialog));
4809 gtk_widget_destroy (dialog);
4813 modest_ui_actions_on_help (GtkAction *action,
4816 const gchar *help_id;
4818 g_return_if_fail (action);
4819 g_return_if_fail (win && GTK_IS_WINDOW(win));
4821 help_id = modest_window_mgr_get_help_id (modest_runtime_get_window_mgr(), win);
4824 modest_platform_show_help (GTK_WINDOW (win), help_id);
4826 g_warning ("%s: no help for window %p", __FUNCTION__, win);
4830 retrieve_msg_contents_performer (gboolean canceled,
4832 GtkWindow *parent_window,
4833 TnyAccount *account,
4836 ModestMailOperation *mail_op;
4837 TnyList *headers = TNY_LIST (user_data);
4839 if (err || canceled) {
4840 /* Show an error ? */
4844 /* Create mail operation */
4845 mail_op = modest_mail_operation_new_with_error_handling ((GObject *) parent_window,
4846 modest_ui_actions_get_msgs_full_error_handler,
4848 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
4849 modest_mail_operation_get_msgs_full (mail_op, headers, NULL, NULL, NULL);
4852 g_object_unref (mail_op);
4854 g_object_unref (headers);
4855 g_object_unref (account);
4859 modest_ui_actions_on_retrieve_msg_contents (GtkAction *action,
4860 ModestWindow *window)
4862 TnyList *headers = NULL;
4863 TnyAccount *account = NULL;
4864 TnyIterator *iter = NULL;
4865 TnyHeader *header = NULL;
4866 TnyFolder *folder = NULL;
4869 headers = get_selected_headers (window);
4873 /* Pick the account */
4874 iter = tny_list_create_iterator (headers);
4875 header = TNY_HEADER (tny_iterator_get_current (iter));
4876 folder = tny_header_get_folder (header);
4877 account = tny_folder_get_account (folder);
4878 g_object_unref (folder);
4879 g_object_unref (header);
4880 g_object_unref (iter);
4882 /* Connect and perform the message retrieval */
4883 modest_platform_connect_and_perform ((GtkWindow *) window,
4884 g_object_ref (account),
4885 retrieve_msg_contents_performer,
4886 g_object_ref (headers));
4889 g_object_unref (account);
4890 g_object_unref (headers);
4894 modest_ui_actions_on_email_menu_activated (GtkAction *action,
4895 ModestWindow *window)
4897 g_return_if_fail (MODEST_IS_WINDOW (window));
4900 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4904 modest_ui_actions_on_edit_menu_activated (GtkAction *action,
4905 ModestWindow *window)
4907 g_return_if_fail (MODEST_IS_WINDOW (window));
4910 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4914 modest_ui_actions_on_view_menu_activated (GtkAction *action,
4915 ModestWindow *window)
4917 g_return_if_fail (MODEST_IS_WINDOW (window));
4920 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4924 modest_ui_actions_on_format_menu_activated (GtkAction *action,
4925 ModestWindow *window)
4927 g_return_if_fail (MODEST_IS_WINDOW (window));
4930 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4934 modest_ui_actions_on_tools_menu_activated (GtkAction *action,
4935 ModestWindow *window)
4937 g_return_if_fail (MODEST_IS_WINDOW (window));
4940 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4944 modest_ui_actions_on_attachment_menu_activated (GtkAction *action,
4945 ModestWindow *window)
4947 g_return_if_fail (MODEST_IS_WINDOW (window));
4950 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4954 modest_ui_actions_on_toolbar_csm_menu_activated (GtkAction *action,
4955 ModestWindow *window)
4957 g_return_if_fail (MODEST_IS_WINDOW (window));
4960 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4964 modest_ui_actions_on_folder_view_csm_menu_activated (GtkAction *action,
4965 ModestWindow *window)
4967 g_return_if_fail (MODEST_IS_WINDOW (window));
4970 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4974 modest_ui_actions_on_header_view_csm_menu_activated (GtkAction *action,
4975 ModestWindow *window)
4977 g_return_if_fail (MODEST_IS_WINDOW (window));
4980 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4984 modest_ui_actions_check_toolbar_dimming_rules (ModestWindow *window)
4986 g_return_if_fail (MODEST_IS_WINDOW (window));
4989 modest_window_check_dimming_rules_group (window, "ModestToolbarDimmingRules");
4993 modest_ui_actions_on_search_messages (GtkAction *action, ModestWindow *window)
4995 g_return_if_fail (MODEST_IS_WINDOW (window));
4997 modest_platform_show_search_messages (GTK_WINDOW (window));
5001 modest_ui_actions_on_open_addressbook (GtkAction *action, ModestWindow *win)
5003 g_return_if_fail (MODEST_IS_WINDOW (win));
5004 modest_platform_show_addressbook (GTK_WINDOW (win));
5009 modest_ui_actions_on_toggle_find_in_page (GtkToggleAction *action,
5010 ModestWindow *window)
5012 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
5014 modest_msg_edit_window_toggle_find_toolbar (MODEST_MSG_EDIT_WINDOW (window), gtk_toggle_action_get_active (action));
5018 on_send_receive_finished (ModestMailOperation *mail_op,
5021 GtkWidget *header_view, *folder_view;
5022 TnyFolderStore *folder_store;
5023 ModestMainWindow *main_win = MODEST_MAIN_WINDOW (user_data);
5025 /* Set send/receive operation finished */
5026 modest_main_window_notify_send_receive_completed (main_win);
5028 /* Don't refresh the current folder if there were any errors */
5029 if (modest_mail_operation_get_status (mail_op) !=
5030 MODEST_MAIL_OPERATION_STATUS_SUCCESS)
5033 /* Refresh the current folder if we're viewing a window. We do
5034 this because the user won't be able to see the new mails in
5035 the selected folder after a Send&Receive because it only
5036 performs a poke_status, i.e, only the number of read/unread
5037 messages is updated, but the new headers are not
5039 folder_view = modest_main_window_get_child_widget (main_win,
5040 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
5044 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
5046 /* Do not need to refresh INBOX again because the
5047 update_account does it always automatically */
5048 if (folder_store && TNY_IS_FOLDER (folder_store) &&
5049 tny_folder_get_folder_type (TNY_FOLDER (folder_store)) != TNY_FOLDER_TYPE_INBOX) {
5050 ModestMailOperation *refresh_op;
5052 header_view = modest_main_window_get_child_widget (main_win,
5053 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
5055 /* We do not need to set the contents style
5056 because it hasn't changed. We also do not
5057 need to save the widget status. Just force
5059 refresh_op = modest_mail_operation_new (G_OBJECT (main_win));
5060 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), refresh_op);
5061 modest_mail_operation_refresh_folder (refresh_op, TNY_FOLDER (folder_store),
5062 folder_refreshed_cb, main_win);
5063 g_object_unref (refresh_op);
5067 g_object_unref (folder_store);
5072 modest_ui_actions_on_send_queue_error_happened (TnySendQueue *self,
5078 const gchar* server_name = NULL;
5079 TnyTransportAccount *server_account;
5080 gchar *message = NULL;
5082 /* Don't show anything if the user cancelled something */
5083 if (err->code == TNY_TRANSPORT_ACCOUNT_ERROR_SEND_USER_CANCEL)
5086 /* Get the server name: */
5088 TNY_TRANSPORT_ACCOUNT (tny_camel_send_queue_get_transport_account (TNY_CAMEL_SEND_QUEUE (self)));
5089 if (server_account) {
5090 server_name = tny_account_get_hostname (TNY_ACCOUNT (server_account));
5092 g_object_unref (server_account);
5093 server_account = NULL;
5096 g_return_if_fail (server_name);
5098 /* Show the appropriate message text for the GError: */
5099 switch (err->code) {
5100 case TNY_TRANSPORT_ACCOUNT_ERROR_SEND_HOST_LOOKUP_FAILED:
5101 message = g_strdup_printf (_("emev_ib_ui_smtp_server_invalid"), server_name);
5103 case TNY_TRANSPORT_ACCOUNT_ERROR_SEND_SERVICE_UNAVAILABLE:
5104 message = g_strdup_printf (_("emev_ib_ui_smtp_server_invalid"), server_name);
5106 case TNY_TRANSPORT_ACCOUNT_ERROR_SEND_AUTHENTICATION_NOT_SUPPORTED:
5107 message = g_strdup_printf (_("emev_ni_ui_smtp_authentication_fail_error"), server_name);
5109 case TNY_TRANSPORT_ACCOUNT_ERROR_SEND:
5110 message = g_strdup (_("emev_ib_ui_smtp_send_error"));
5113 g_return_if_reached ();
5116 /* TODO if the username or the password where not defined we
5117 should show the Accounts Settings dialog or the Connection
5118 specific SMTP server window */
5120 modest_platform_run_information_dialog (NULL, message);
5125 modest_ui_actions_on_send_queue_status_changed (ModestTnySendQueue *send_queue,
5130 ModestMainWindow *main_window = NULL;
5131 ModestWindowMgr *mgr = NULL;
5132 GtkWidget *folder_view = NULL, *header_view = NULL;
5133 TnyFolderStore *selected_folder = NULL;
5134 TnyFolderType folder_type;
5136 mgr = modest_runtime_get_window_mgr ();
5137 main_window = MODEST_MAIN_WINDOW (modest_window_mgr_get_main_window (mgr,
5138 FALSE));/* don't create */
5142 /* Check if selected folder is OUTBOX */
5143 folder_view = modest_main_window_get_child_widget (main_window,
5144 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
5145 header_view = modest_main_window_get_child_widget (main_window,
5146 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
5148 selected_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
5149 if (!TNY_IS_FOLDER (selected_folder))
5152 /* gtk_tree_view_column_queue_resize is only available in GTK+ 2.8 */
5153 #if GTK_CHECK_VERSION(2, 8, 0)
5154 folder_type = modest_tny_folder_guess_folder_type (TNY_FOLDER (selected_folder));
5155 if (folder_type == TNY_FOLDER_TYPE_OUTBOX) {
5156 GtkTreeViewColumn *tree_column;
5158 tree_column = gtk_tree_view_get_column (GTK_TREE_VIEW (header_view),
5159 TNY_GTK_HEADER_LIST_MODEL_FROM_COLUMN);
5160 gtk_tree_view_column_queue_resize (tree_column);
5163 gtk_widget_queue_draw (header_view);
5168 if (selected_folder != NULL)
5169 g_object_unref (selected_folder);
5173 modest_ui_actions_on_account_connection_error (GtkWindow *parent_window,
5174 TnyAccount *account)
5176 ModestTransportStoreProtocol proto;
5177 const gchar *proto_name;
5178 gchar *error_note = NULL;
5180 proto_name = tny_account_get_proto (account);
5181 proto = modest_protocol_info_get_transport_store_protocol (proto_name);
5184 case MODEST_PROTOCOL_STORE_POP:
5185 error_note = g_strdup_printf (_("emev_ni_ui_pop3_msg_connect_error"),
5186 tny_account_get_hostname (account));
5188 case MODEST_PROTOCOL_STORE_IMAP:
5189 error_note = g_strdup_printf (_("emev_ni_ui_imap_connect_server_error"),
5190 tny_account_get_hostname (account));
5192 case MODEST_PROTOCOL_STORE_MAILDIR:
5193 case MODEST_PROTOCOL_STORE_MBOX:
5194 error_note = g_strdup (_("emev_nc_mailbox_notavailable"));
5197 g_warning ("%s: This should not be reached", __FUNCTION__);
5201 modest_platform_run_information_dialog (parent_window, error_note);
5202 g_free (error_note);