1 /* Copyright (c) 2006, Nokia Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of the Nokia Corporation nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #endif /*HAVE_CONFIG_H*/
34 #include <glib/gi18n.h>
35 #include <glib/gprintf.h>
37 #include <modest-runtime.h>
38 #include <modest-tny-folder.h>
39 #include <modest-tny-msg.h>
40 #include <modest-tny-account.h>
41 #include <modest-address-book.h>
42 #include "modest-error.h"
43 #include "modest-ui-actions.h"
44 #include "modest-protocol-info.h"
45 #include "modest-tny-platform-factory.h"
46 #include "modest-platform.h"
47 #include "modest-debug.h"
48 #include <tny-mime-part.h>
49 #include <tny-camel-folder.h>
50 #include <tny-camel-imap-folder.h>
51 #include <tny-camel-pop-folder.h>
53 #ifdef MODEST_PLATFORM_MAEMO
54 #include "maemo/modest-osso-state-saving.h"
55 #include "maemo/modest-hildon-includes.h"
56 #include "maemo/modest-connection-specific-smtp-window.h"
57 #endif /* MODEST_PLATFORM_MAEMO */
58 #include <modest-utils.h>
60 #include "widgets/modest-ui-constants.h"
61 #include <widgets/modest-main-window.h>
62 #include <widgets/modest-msg-view-window.h>
63 #include <widgets/modest-account-view-window.h>
64 #include <widgets/modest-details-dialog.h>
65 #include <widgets/modest-attachments-view.h>
66 #include "widgets/modest-folder-view.h"
67 #include "widgets/modest-global-settings-dialog.h"
68 #include "modest-account-mgr-helpers.h"
69 #include "modest-mail-operation.h"
70 #include "modest-text-utils.h"
72 #ifdef MODEST_HAVE_EASYSETUP
73 #include "easysetup/modest-easysetup-wizard.h"
74 #endif /* MODEST_HAVE_EASYSETUP */
76 #include <modest-widget-memory.h>
77 #include <tny-error.h>
78 #include <tny-simple-list.h>
79 #include <tny-msg-view.h>
80 #include <tny-device.h>
81 #include <tny-merge-folder.h>
83 #include <gtkhtml/gtkhtml.h>
85 typedef struct _GetMsgAsyncHelper {
87 ModestMailOperation *mail_op;
94 typedef enum _ReplyForwardAction {
100 typedef struct _ReplyForwardHelper {
101 guint reply_forward_type;
102 ReplyForwardAction action;
104 GtkWidget *parent_window;
105 } ReplyForwardHelper;
107 typedef struct _MoveToHelper {
108 GtkTreeRowReference *reference;
112 typedef struct _PasteAsAttachmentHelper {
113 ModestMsgEditWindow *window;
115 } PasteAsAttachmentHelper;
119 * The do_headers_action uses this kind of functions to perform some
120 * action to each member of a list of headers
122 typedef void (*HeadersFunc) (TnyHeader *header, ModestWindow *win, gpointer user_data);
124 static void do_headers_action (ModestWindow *win,
128 static void open_msg_cb (ModestMailOperation *mail_op,
135 static void reply_forward_cb (ModestMailOperation *mail_op,
142 static void reply_forward (ReplyForwardAction action, ModestWindow *win);
144 static void folder_refreshed_cb (ModestMailOperation *mail_op,
148 static void on_send_receive_finished (ModestMailOperation *mail_op,
151 static gint header_list_count_uncached_msgs (TnyList *header_list);
153 static gboolean connect_to_get_msg (ModestWindow *win,
154 gint num_of_uncached_msgs,
155 TnyAccount *account);
157 static gboolean remote_folder_is_pop (const TnyFolderStore *folder);
159 static gboolean msgs_already_deleted_from_server ( TnyList *headers,
160 const TnyFolderStore *src_folder);
162 static void do_create_folder (GtkWindow *window,
163 TnyFolderStore *parent_folder,
164 const gchar *suggested_name);
166 static GtkWidget* get_folder_view_from_move_to_dialog (GtkWidget *move_to_dialog);
170 * This function checks whether a TnyFolderStore is a pop account
173 remote_folder_is_pop (const TnyFolderStore *folder)
175 const gchar *proto = NULL;
176 TnyAccount *account = NULL;
178 g_return_val_if_fail (TNY_IS_FOLDER_STORE(folder), FALSE);
180 if (TNY_IS_ACCOUNT (folder)) {
181 account = TNY_ACCOUNT(folder);
182 g_object_ref(account);
183 } else if (TNY_IS_FOLDER (folder)) {
184 account = tny_folder_get_account(TNY_FOLDER(folder));
187 if (!account && !TNY_IS_ACCOUNT(account)) {
188 g_warning ("%s: could not get account", __FUNCTION__);
192 proto = tny_account_get_proto(account);
193 g_object_unref (account);
196 (modest_protocol_info_get_transport_store_protocol (proto) == MODEST_PROTOCOL_STORE_POP);
200 * This functions checks whether if a list of messages are already
201 * deleted from the server: that is, if the server is a POP account
202 * and all messages are already cached.
205 msgs_already_deleted_from_server (TnyList *headers, const TnyFolderStore *src_folder)
207 g_return_val_if_fail (TNY_IS_FOLDER_STORE(src_folder), FALSE);
208 g_return_val_if_fail (TNY_IS_LIST(headers), FALSE);
210 gboolean src_is_pop = remote_folder_is_pop (src_folder);
211 gint uncached_msgs = header_list_count_uncached_msgs (headers);
213 return (src_is_pop && !uncached_msgs);
217 /* FIXME: this should be merged with the similar code in modest-account-view-window */
218 /* Show the account creation wizard dialog.
219 * returns: TRUE if an account was created. FALSE if the user cancelled.
222 modest_ui_actions_run_account_setup_wizard (ModestWindow *win)
224 gboolean result = FALSE;
225 GtkWindow *dialog, *wizard;
226 gint dialog_response;
228 /* Show the easy-setup wizard: */
229 dialog = modest_window_mgr_get_modal (modest_runtime_get_window_mgr());
231 /* old wizard is active already;
233 gtk_window_present (GTK_WINDOW(dialog));
238 /* there is no such wizard yet */
239 wizard = GTK_WINDOW (modest_platform_get_account_settings_wizard ());
240 modest_window_mgr_set_modal (modest_runtime_get_window_mgr(), wizard);
242 /* always present a main window in the background
243 * we do it here, so we cannot end up with two wizards (as this
244 * function might be called in modest_window_mgr_get_main_window as well */
246 win = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr(),
247 TRUE); /* create if not existent */
249 /* make sure the mainwindow is visible */
250 gtk_window_set_transient_for (GTK_WINDOW (wizard), GTK_WINDOW (win));
251 gtk_widget_show_all (GTK_WIDGET(win));
252 gtk_window_present (GTK_WINDOW(win));
254 dialog_response = gtk_dialog_run (GTK_DIALOG (wizard));
255 gtk_widget_destroy (GTK_WIDGET (wizard));
256 if (gtk_events_pending ())
257 gtk_main_iteration ();
259 if (dialog_response == GTK_RESPONSE_CANCEL) {
262 /* Check whether an account was created: */
263 result = modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
270 modest_ui_actions_on_about (GtkAction *action, ModestWindow *win)
273 const gchar *authors[] = {
274 "Dirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>",
277 about = gtk_about_dialog_new ();
278 gtk_about_dialog_set_name (GTK_ABOUT_DIALOG(about), PACKAGE_NAME);
279 gtk_about_dialog_set_version (GTK_ABOUT_DIALOG(about),PACKAGE_VERSION);
280 gtk_about_dialog_set_copyright (GTK_ABOUT_DIALOG(about),
281 _("Copyright (c) 2006, Nokia Corporation\n"
282 "All rights reserved."));
283 gtk_about_dialog_set_comments (GTK_ABOUT_DIALOG(about),
284 _("a modest e-mail client\n\n"
285 "design and implementation: Dirk-Jan C. Binnema\n"
286 "contributions from the fine people at KC and Ig\n"
287 "uses the tinymail email framework written by Philip van Hoof"));
288 gtk_about_dialog_set_authors (GTK_ABOUT_DIALOG(about), authors);
289 gtk_about_dialog_set_website (GTK_ABOUT_DIALOG(about), "http://modest.garage.maemo.org");
290 gtk_window_set_transient_for (GTK_WINDOW (about), GTK_WINDOW (win));
291 gtk_window_set_modal (GTK_WINDOW (about), TRUE);
293 gtk_dialog_run (GTK_DIALOG (about));
294 gtk_widget_destroy(about);
298 * Gets the list of currently selected messages. If the win is the
299 * main window, then it returns a newly allocated list of the headers
300 * selected in the header view. If win is the msg view window, then
301 * the value returned is a list with just a single header.
303 * The caller of this funcion must free the list.
306 get_selected_headers (ModestWindow *win)
308 if (MODEST_IS_MAIN_WINDOW(win)) {
309 GtkWidget *header_view;
311 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
312 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
313 return modest_header_view_get_selected_headers (MODEST_HEADER_VIEW(header_view));
315 } else if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
316 /* for MsgViewWindows, we simply return a list with one element */
318 TnyList *list = NULL;
320 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
321 if (header != NULL) {
322 list = tny_simple_list_new ();
323 tny_list_prepend (list, G_OBJECT(header));
324 g_object_unref (G_OBJECT(header));
333 static GtkTreeRowReference *
334 get_next_after_selected_headers (ModestHeaderView *header_view)
336 GtkTreeSelection *sel;
337 GList *selected_rows, *node;
339 GtkTreeRowReference *result;
342 model = gtk_tree_view_get_model (GTK_TREE_VIEW (header_view));
343 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
344 selected_rows = gtk_tree_selection_get_selected_rows (sel, NULL);
346 if (selected_rows == NULL)
349 node = g_list_last (selected_rows);
350 path = gtk_tree_path_copy ((GtkTreePath *) node->data);
351 gtk_tree_path_next (path);
353 result = gtk_tree_row_reference_new (model, path);
355 gtk_tree_path_free (path);
356 g_list_foreach (selected_rows, (GFunc) gtk_tree_path_free, NULL);
357 g_list_free (selected_rows);
363 headers_action_mark_as_read (TnyHeader *header,
367 TnyHeaderFlags flags;
369 g_return_if_fail (TNY_IS_HEADER(header));
371 flags = tny_header_get_flags (header);
372 if (flags & TNY_HEADER_FLAG_SEEN) return;
373 tny_header_set_flag (header, TNY_HEADER_FLAG_SEEN);
377 headers_action_mark_as_unread (TnyHeader *header,
381 TnyHeaderFlags flags;
383 g_return_if_fail (TNY_IS_HEADER(header));
385 flags = tny_header_get_flags (header);
386 if (flags & TNY_HEADER_FLAG_SEEN) {
387 tny_header_unset_flag (header, TNY_HEADER_FLAG_SEEN);
391 /** After deleing a message that is currently visible in a window,
392 * show the next message from the list, or close the window if there are no more messages.
395 modest_ui_actions_refresh_message_window_after_delete (ModestMsgViewWindow* win)
397 /* Close msg view window or select next */
398 if (modest_msg_view_window_last_message_selected (win) &&
399 modest_msg_view_window_first_message_selected (win)) {
400 modest_ui_actions_on_close_window (NULL, MODEST_WINDOW (win));
401 } else if (!modest_msg_view_window_select_next_message (win)) {
403 g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value);
409 modest_ui_actions_on_delete_message (GtkAction *action, ModestWindow *win)
411 TnyList *header_list = NULL;
412 TnyIterator *iter = NULL;
413 TnyHeader *header = NULL;
414 gchar *message = NULL;
417 ModestWindowMgr *mgr;
418 GtkWidget *header_view = NULL;
420 g_return_if_fail (MODEST_IS_WINDOW(win));
422 /* Check first if the header view has the focus */
423 if (MODEST_IS_MAIN_WINDOW (win)) {
425 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
426 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
427 if (!gtk_widget_is_focus (header_view))
431 /* Get the headers, either from the header view (if win is the main window),
432 * or from the message view window: */
433 header_list = get_selected_headers (win);
434 if (!header_list) return;
436 /* Check if any of the headers are already opened, or in the process of being opened */
437 if (MODEST_IS_MAIN_WINDOW (win)) {
438 gint opened_headers = 0;
440 iter = tny_list_create_iterator (header_list);
441 mgr = modest_runtime_get_window_mgr ();
442 while (!tny_iterator_is_done (iter)) {
443 header = TNY_HEADER (tny_iterator_get_current (iter));
445 if (modest_window_mgr_find_registered_header (mgr, header, NULL))
447 g_object_unref (header);
449 tny_iterator_next (iter);
451 g_object_unref (iter);
453 if (opened_headers > 0) {
456 msg = g_strdup_printf (_("mcen_nc_unable_to_delete_n_messages"),
459 modest_platform_run_information_dialog (GTK_WINDOW (win), (const gchar *) msg);
462 g_object_unref (header_list);
468 if (tny_list_get_length(header_list) == 1) {
469 iter = tny_list_create_iterator (header_list);
470 header = TNY_HEADER (tny_iterator_get_current (iter));
472 desc = g_strdup_printf ("%s", tny_header_get_subject (header));
473 g_object_unref (header);
476 g_object_unref (iter);
478 message = g_strdup_printf(ngettext("emev_nc_delete_message", "emev_nc_delete_messages",
479 tny_list_get_length(header_list)), desc);
481 /* Confirmation dialog */
482 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
486 if (response == GTK_RESPONSE_OK) {
487 ModestWindow *main_window = NULL;
488 ModestWindowMgr *mgr = NULL;
489 GtkTreeModel *model = NULL;
490 GtkTreeSelection *sel = NULL;
491 GList *sel_list = NULL, *tmp = NULL;
492 GtkTreeRowReference *next_row_reference = NULL;
493 GtkTreeRowReference *prev_row_reference = NULL;
494 GtkTreePath *next_path = NULL;
495 GtkTreePath *prev_path = NULL;
496 ModestMailOperation *mail_op = NULL;
498 /* Find last selected row */
499 if (MODEST_IS_MAIN_WINDOW (win)) {
500 model = gtk_tree_view_get_model (GTK_TREE_VIEW (header_view));
501 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
502 sel_list = gtk_tree_selection_get_selected_rows (sel, &model);
503 for (tmp=sel_list; tmp; tmp=tmp->next) {
504 if (tmp->next == NULL) {
505 prev_path = gtk_tree_path_copy((GtkTreePath *) tmp->data);
506 next_path = gtk_tree_path_copy((GtkTreePath *) tmp->data);
508 gtk_tree_path_prev (prev_path);
509 gtk_tree_path_next (next_path);
511 prev_row_reference = gtk_tree_row_reference_new (model, prev_path);
512 next_row_reference = gtk_tree_row_reference_new (model, next_path);
517 /* Disable window dimming management */
518 modest_window_disable_dimming (MODEST_WINDOW(win));
520 /* Remove each header. If it's a view window header_view == NULL */
521 mail_op = modest_mail_operation_new ((GObject *) win);
522 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
524 modest_mail_operation_remove_msgs (mail_op, header_list, FALSE);
525 g_object_unref (mail_op);
527 /* Enable window dimming management */
529 gtk_tree_selection_unselect_all (sel);
531 modest_window_enable_dimming (MODEST_WINDOW(win));
533 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
534 modest_ui_actions_refresh_message_window_after_delete (MODEST_MSG_VIEW_WINDOW (win));
536 /* Get main window */
537 mgr = modest_runtime_get_window_mgr ();
538 main_window = modest_window_mgr_get_main_window (mgr, FALSE); /* don't create */
540 /* Move cursor to next row */
543 /* Select next or previous row */
544 if (gtk_tree_row_reference_valid (next_row_reference)) {
545 /* next_path = gtk_tree_row_reference_get_path (row_reference); */
546 gtk_tree_selection_select_path (sel, next_path);
548 else if (gtk_tree_row_reference_valid (prev_row_reference)) {
549 gtk_tree_selection_select_path (sel, prev_path);
553 if (next_row_reference != NULL)
554 gtk_tree_row_reference_free (next_row_reference);
555 if (next_path != NULL)
556 gtk_tree_path_free (next_path);
557 if (prev_row_reference != NULL)
558 gtk_tree_row_reference_free (prev_row_reference);
559 if (prev_path != NULL)
560 gtk_tree_path_free (prev_path);
563 /* Update toolbar dimming state */
565 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
568 g_list_foreach (sel_list, (GFunc) gtk_tree_path_free, NULL);
569 g_list_free (sel_list);
575 g_object_unref (header_list);
581 /* delete either message or folder, based on where we are */
583 modest_ui_actions_on_delete_message_or_folder (GtkAction *action, ModestWindow *win)
585 g_return_if_fail (MODEST_IS_WINDOW(win));
587 /* Check first if the header view has the focus */
588 if (MODEST_IS_MAIN_WINDOW (win)) {
590 w = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
591 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
592 if (gtk_widget_is_focus (w)) {
593 modest_ui_actions_on_delete_folder (action, MODEST_MAIN_WINDOW(win));
597 modest_ui_actions_on_delete_message (action, win);
603 modest_ui_actions_on_quit (GtkAction *action, ModestWindow *win)
605 ModestWindowMgr *mgr = NULL;
607 #ifdef MODEST_PLATFORM_MAEMO
608 modest_osso_save_state();
609 #endif /* MODEST_PLATFORM_MAEMO */
611 g_debug ("closing down, clearing %d item(s) from operation queue",
612 modest_mail_operation_queue_num_elements
613 (modest_runtime_get_mail_operation_queue()));
615 /* cancel all outstanding operations */
616 modest_mail_operation_queue_cancel_all
617 (modest_runtime_get_mail_operation_queue());
619 g_debug ("queue has been cleared");
622 /* Check if there are opened editing windows */
623 mgr = modest_runtime_get_window_mgr ();
624 modest_window_mgr_close_all_windows (mgr);
626 /* note: when modest-tny-account-store is finalized,
627 it will automatically set all network connections
630 /* gtk_main_quit (); */
634 modest_ui_actions_on_close_window (GtkAction *action, ModestWindow *win)
638 g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value);
640 /* if (MODEST_IS_MSG_VIEW_WINDOW (win)) { */
641 /* gtk_widget_destroy (GTK_WIDGET (win)); */
642 /* } else if (MODEST_IS_MSG_EDIT_WINDOW (win)) { */
643 /* gboolean ret_value; */
644 /* g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value); */
645 /* } else if (MODEST_IS_WINDOW (win)) { */
646 /* gtk_widget_destroy (GTK_WIDGET (win)); */
648 /* g_return_if_reached (); */
653 modest_ui_actions_on_add_to_contacts (GtkAction *action, ModestWindow *win)
655 GtkClipboard *clipboard = NULL;
656 gchar *selection = NULL;
658 clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
659 selection = gtk_clipboard_wait_for_text (clipboard);
661 /* Question: why is the clipboard being used here?
662 * It doesn't really make a lot of sense. */
666 modest_address_book_add_address (selection);
672 modest_ui_actions_on_accounts (GtkAction *action,
675 /* This is currently only implemented for Maemo */
676 if (!modest_account_mgr_has_accounts (modest_runtime_get_account_mgr(), TRUE)) {
677 if (!modest_ui_actions_run_account_setup_wizard (win))
678 g_debug ("%s: wizard was already running", __FUNCTION__);
682 /* Show the list of accounts */
683 GtkWindow *account_win = GTK_WINDOW (modest_account_view_window_new ());
684 gtk_window_set_transient_for (account_win, GTK_WINDOW (win));
686 /* The accounts dialog must be modal */
687 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), account_win);
688 modest_utils_show_dialog_and_forget (GTK_WINDOW (win), GTK_DIALOG (account_win));
692 #ifdef MODEST_PLATFORM_MAEMO
694 on_smtp_servers_window_hide (GtkWindow* window, gpointer user_data)
696 /* Save any changes. */
697 modest_connection_specific_smtp_window_save_server_accounts (
698 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (window));
699 gtk_widget_destroy (GTK_WIDGET (window));
705 modest_ui_actions_on_smtp_servers (GtkAction *action, ModestWindow *win)
707 /* This is currently only implemented for Maemo,
708 * because it requires an API (libconic) to detect different connection
711 #ifdef MODEST_PLATFORM_MAEMO /* Defined in config.h */
713 /* Create the window if necessary: */
714 GtkWidget *specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
715 modest_connection_specific_smtp_window_fill_with_connections (
716 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (specific_window),
717 modest_runtime_get_account_mgr());
719 /* Show the window: */
720 gtk_window_set_transient_for (GTK_WINDOW (specific_window), GTK_WINDOW (win));
721 gtk_window_set_modal (GTK_WINDOW (specific_window), TRUE);
722 gtk_widget_show (specific_window);
724 /* Save changes when the window is hidden: */
725 g_signal_connect (specific_window, "hide",
726 G_CALLBACK (on_smtp_servers_window_hide), win);
727 #endif /* MODEST_PLATFORM_MAEMO */
731 modest_ui_actions_compose_msg(ModestWindow *win,
734 const gchar *bcc_str,
735 const gchar *subject_str,
736 const gchar *body_str,
739 gchar *account_name = NULL;
741 TnyAccount *account = NULL;
742 TnyFolder *folder = NULL;
743 gchar *from_str = NULL, *signature = NULL, *body = NULL;
744 gboolean use_signature = FALSE;
745 ModestWindow *msg_win = NULL;
746 ModestAccountMgr *mgr = modest_runtime_get_account_mgr();
747 ModestTnyAccountStore *store = modest_runtime_get_account_store();
749 account_name = modest_account_mgr_get_default_account(mgr);
751 g_printerr ("modest: no account found\n");
754 account = modest_tny_account_store_get_server_account (store, account_name, TNY_ACCOUNT_TYPE_STORE);
756 g_printerr ("modest: failed to get tnyaccount for '%s'\n", account_name);
759 folder = modest_tny_account_get_special_folder (account, TNY_FOLDER_TYPE_DRAFTS);
761 g_printerr ("modest: failed to find Drafts folder\n");
764 from_str = modest_account_mgr_get_from_string (mgr, account_name);
766 g_printerr ("modest: failed get from string for '%s'\n", account_name);
770 signature = modest_account_mgr_get_signature (mgr, account_name, &use_signature);
771 if (body_str != NULL) {
772 body = use_signature ? g_strconcat(body_str, "\n", signature, NULL) : g_strdup(body_str);
774 body = use_signature ? g_strconcat("\n", signature, NULL) : g_strdup("");
777 msg = modest_tny_msg_new (to_str, from_str, cc_str, bcc_str, subject_str, body, NULL);
779 g_printerr ("modest: failed to create new msg\n");
783 /* Create and register edit window */
784 /* This is destroyed by TODO. */
785 msg_win = modest_msg_edit_window_new (msg, account_name, FALSE);
786 while (attachments) {
787 modest_msg_edit_window_attach_file_one((ModestMsgEditWindow *)msg_win,
789 attachments = g_slist_next(attachments);
791 modest_window_mgr_register_window (modest_runtime_get_window_mgr(), msg_win);
792 gtk_widget_show_all (GTK_WIDGET (msg_win));
798 g_free (account_name);
799 if (account) g_object_unref (G_OBJECT(account));
800 if (folder) g_object_unref (G_OBJECT(folder));
801 if (msg_win) g_object_unref (G_OBJECT(msg_win));
802 if (msg) g_object_unref (G_OBJECT(msg));
806 modest_ui_actions_on_new_msg (GtkAction *action, ModestWindow *win)
808 /* if there are no accounts yet, just show the wizard */
809 if (!modest_account_mgr_has_accounts (modest_runtime_get_account_mgr(), TRUE))
810 if (!modest_ui_actions_run_account_setup_wizard (win))
813 modest_ui_actions_compose_msg(win, NULL, NULL, NULL, NULL, NULL, NULL);
817 modest_ui_actions_on_new_msg_or_folder (GtkAction *action, ModestWindow *win)
819 g_return_if_fail (MODEST_IS_WINDOW (win));
821 /* Check first if the folder view has the focus */
822 if (MODEST_IS_MAIN_WINDOW (win)) {
824 w = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
825 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
826 if (gtk_widget_is_focus (w)) {
827 modest_ui_actions_on_new_folder (action, MODEST_MAIN_WINDOW(win));
832 modest_ui_actions_on_new_msg (action, win);
837 modest_ui_actions_msg_retrieval_check (ModestMailOperation *mail_op,
841 ModestMailOperationStatus status;
843 /* If there is no message or the operation was not successful */
844 status = modest_mail_operation_get_status (mail_op);
845 if (!msg || status != MODEST_MAIL_OPERATION_STATUS_SUCCESS) {
847 /* Remove the header from the preregistered uids */
848 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (),
858 open_msg_cb (ModestMailOperation *mail_op,
865 ModestWindowMgr *mgr = NULL;
866 ModestWindow *parent_win = NULL;
867 ModestWindow *win = NULL;
868 TnyFolderType folder_type = TNY_FOLDER_TYPE_UNKNOWN;
869 gchar *account = NULL;
871 gboolean open_in_editor = FALSE;
873 /* Do nothing if there was any problem with the mail
874 operation. The error will be shown by the error_handler of
875 the mail operation */
876 if (!modest_ui_actions_msg_retrieval_check (mail_op, header, msg))
879 parent_win = (ModestWindow *) modest_mail_operation_get_source (mail_op);
880 folder = tny_header_get_folder (header);
882 /* Mark header as read */
883 headers_action_mark_as_read (header, MODEST_WINDOW(parent_win), NULL);
885 /* Gets folder type (OUTBOX headers will be opened in edit window */
886 if (modest_tny_folder_is_local_folder (folder)) {
887 folder_type = modest_tny_folder_get_local_or_mmc_folder_type (folder);
888 if (folder_type == TNY_FOLDER_TYPE_INVALID)
889 g_warning ("%s: BUG: TNY_FOLDER_TYPE_INVALID", __FUNCTION__);
893 if (folder_type == TNY_FOLDER_TYPE_OUTBOX) {
894 TnyTransportAccount *traccount = NULL;
895 ModestTnyAccountStore *accstore = modest_runtime_get_account_store();
896 traccount = modest_tny_account_store_get_transport_account_from_outbox_header(accstore, header);
898 ModestTnySendQueue *send_queue = NULL;
899 ModestTnySendQueueStatus status;
901 account = g_strdup(modest_tny_account_get_parent_modest_account_name_for_server_account(
902 TNY_ACCOUNT(traccount)));
903 send_queue = modest_runtime_get_send_queue(traccount);
904 msg_id = modest_tny_send_queue_get_msg_id (header);
905 status = modest_tny_send_queue_get_msg_status(send_queue, msg_id);
906 /* Only open messages in outbox with the editor if they are in Failed state */
907 if (status == MODEST_TNY_SEND_QUEUE_FAILED) {
908 open_in_editor = TRUE;
911 g_object_unref(traccount);
913 g_warning("Cannot get transport account for message in outbox!!");
915 } else if (folder_type == TNY_FOLDER_TYPE_DRAFTS) {
916 open_in_editor = TRUE; /* Open in editor if the message is in the Drafts folder */
921 account = g_strdup (modest_window_get_active_account (MODEST_WINDOW (parent_win)));
923 account = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
925 if (open_in_editor) {
926 ModestAccountMgr *mgr = modest_runtime_get_account_mgr ();
927 const gchar *from_header = NULL;
929 from_header = tny_header_get_from (header);
931 /* we cannot edit without a valid account... */
932 if (!modest_account_mgr_has_accounts(mgr, TRUE)) {
933 if (!modest_ui_actions_run_account_setup_wizard(parent_win))
938 GSList *accounts = modest_account_mgr_account_names (mgr, TRUE);
940 for (node = accounts; node != NULL; node = g_slist_next (node)) {
941 gchar *from = modest_account_mgr_get_from_string (mgr, node->data);
943 if (from && (strcmp (from_header, from) == 0)) {
945 account = g_strdup (node->data);
951 g_slist_foreach (accounts, (GFunc) g_free, NULL);
952 g_slist_free (accounts);
955 win = modest_msg_edit_window_new (msg, account, TRUE);
959 modest_platform_information_banner_with_timeout
960 (NULL, NULL, _("mail_ib_opening_draft_message"), 1200);
963 gchar *uid = modest_tny_folder_get_header_unique_id (header);
965 if (MODEST_IS_MAIN_WINDOW (parent_win)) {
966 GtkWidget *header_view;
967 GtkTreeSelection *sel;
968 GList *sel_list = NULL;
971 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(parent_win),
972 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
974 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
975 sel_list = gtk_tree_selection_get_selected_rows (sel, &model);
977 if (sel_list != NULL) {
978 GtkTreeRowReference *row_reference;
980 row_reference = gtk_tree_row_reference_new (model, (GtkTreePath *) sel_list->data);
981 g_list_foreach (sel_list, (GFunc) gtk_tree_path_free, NULL);
982 g_list_free (sel_list);
984 win = modest_msg_view_window_new_with_header_model (
985 msg, account, (const gchar*) uid,
986 model, row_reference);
987 gtk_tree_row_reference_free (row_reference);
989 win = modest_msg_view_window_new_for_attachment (msg, account, (const gchar*) uid);
992 win = modest_msg_view_window_new_for_attachment (msg, account, (const gchar*) uid);
997 /* Register and show new window */
999 mgr = modest_runtime_get_window_mgr ();
1000 modest_window_mgr_register_window (mgr, win);
1001 g_object_unref (win);
1002 gtk_widget_show_all (GTK_WIDGET(win));
1005 /* Update toolbar dimming state */
1006 if (MODEST_IS_MAIN_WINDOW (parent_win)) {
1007 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (parent_win));
1013 g_object_unref (parent_win);
1014 g_object_unref (folder);
1018 modest_ui_actions_get_msgs_full_error_handler (ModestMailOperation *mail_op,
1021 const GError *error;
1022 GObject *win = NULL;
1023 const gchar *err_msg;
1025 win = modest_mail_operation_get_source (mail_op);
1026 error = modest_mail_operation_get_error (mail_op);
1028 /* Select error message */
1029 if (error->code == MODEST_MAIL_OPERATION_ERROR_MESSAGE_SIZE_LIMIT)
1030 err_msg = _("emev_ni_ui_imap_msg_size_exceed_error");
1032 err_msg = (const gchar *) user_data;
1035 modest_platform_run_information_dialog ((GtkWindow *) win, err_msg);
1038 g_object_unref (win);
1042 * Returns the account a list of headers belongs to. It returns a
1043 * *new* reference so don't forget to unref it
1046 get_account_from_header_list (TnyList *headers)
1048 TnyAccount *account = NULL;
1050 if (tny_list_get_length (headers) > 0) {
1051 TnyIterator *iter = tny_list_create_iterator (headers);
1052 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter));
1053 TnyFolder *folder = tny_header_get_folder (header);
1054 account = tny_folder_get_account (folder);
1055 g_object_unref (folder);
1056 g_object_unref (header);
1057 g_object_unref (iter);
1063 open_msgs_performer(gboolean canceled,
1065 GtkWindow *parent_window,
1066 TnyAccount *account,
1069 ModestMailOperation *mail_op = NULL;
1070 const gchar *proto_name;
1072 ModestTransportStoreProtocol proto;
1073 TnyList *not_opened_headers;
1074 TnyConnectionStatus status;
1076 not_opened_headers = TNY_LIST (user_data);
1078 status = tny_account_get_connection_status (account);
1079 if (err || canceled) {
1083 /* Get the error message depending on the protocol */
1084 proto_name = tny_account_get_proto (account);
1085 if (proto_name != NULL) {
1086 proto = modest_protocol_info_get_transport_store_protocol (proto_name);
1088 proto = MODEST_PROTOCOL_STORE_MAILDIR;
1091 /* Create the error messages */
1092 if (tny_list_get_length (not_opened_headers) == 1) {
1093 if (proto == MODEST_PROTOCOL_STORE_POP) {
1094 error_msg = g_strdup (_("emev_ni_ui_pop3_msg_recv_error"));
1095 } else if (proto == MODEST_PROTOCOL_STORE_IMAP) {
1096 TnyIterator *iter = tny_list_create_iterator (not_opened_headers);
1097 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter));
1098 error_msg = g_strdup_printf (_("emev_ni_ui_imap_message_not_available_in_server"),
1099 tny_header_get_subject (header));
1100 g_object_unref (header);
1101 g_object_unref (iter);
1103 error_msg = g_strdup (_("mail_ni_ui_folder_get_msg_folder_error"));
1106 error_msg = g_strdup (_("mail_ni_ui_folder_get_msg_folder_error"));
1109 /* Create the mail operation */
1111 modest_mail_operation_new_with_error_handling ((GObject *) parent_window,
1112 modest_ui_actions_get_msgs_full_error_handler,
1114 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
1117 modest_mail_operation_get_msgs_full (mail_op,
1126 g_object_unref (mail_op);
1127 g_object_unref (not_opened_headers);
1128 g_object_unref (account);
1132 * This function is used by both modest_ui_actions_on_open and
1133 * modest_ui_actions_on_header_activated. This way we always do the
1134 * same when trying to open messages.
1137 open_msgs_from_headers (TnyList *headers, ModestWindow *win)
1139 ModestWindowMgr *mgr = NULL;
1140 TnyIterator *iter = NULL, *iter_not_opened = NULL;
1141 TnyList *not_opened_headers = NULL;
1142 TnyHeaderFlags flags = 0;
1143 TnyAccount *account;
1144 gint uncached_msgs = 0;
1146 g_return_if_fail (headers != NULL);
1148 /* Check that only one message is selected for opening */
1149 if (tny_list_get_length (headers) != 1) {
1150 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
1151 _("mcen_ib_select_one_message"));
1155 mgr = modest_runtime_get_window_mgr ();
1156 iter = tny_list_create_iterator (headers);
1158 /* Get the account */
1159 account = get_account_from_header_list (headers);
1161 /* Look if we already have a message view for each header. If
1162 true, then remove the header from the list of headers to
1164 not_opened_headers = tny_simple_list_new ();
1165 while (!tny_iterator_is_done (iter)) {
1167 ModestWindow *window = NULL;
1168 TnyHeader *header = NULL;
1169 gboolean found = FALSE;
1171 header = TNY_HEADER (tny_iterator_get_current (iter));
1173 flags = tny_header_get_flags (header);
1176 found = modest_window_mgr_find_registered_header (mgr, header, &window);
1178 /* Do not open again the message and present the
1179 window to the user */
1182 gtk_window_present (GTK_WINDOW (window));
1184 /* the header has been registered already, we don't do
1185 * anything but wait for the window to come up*/
1186 g_debug ("header %p already registered, waiting for window", header);
1188 tny_list_append (not_opened_headers, G_OBJECT (header));
1192 g_object_unref (header);
1194 tny_iterator_next (iter);
1196 g_object_unref (iter);
1199 /* Open each message */
1200 if (tny_list_get_length (not_opened_headers) == 0)
1203 /* If some messages would have to be downloaded, ask the user to
1204 * make a connection. It's generally easier to do this here (in the mainloop)
1205 * than later in a thread:
1207 if (tny_list_get_length (not_opened_headers) > 0) {
1208 uncached_msgs = header_list_count_uncached_msgs (not_opened_headers);
1210 if (uncached_msgs > 0) {
1211 /* Allways download if we are online. */
1212 if (!tny_device_is_online (modest_runtime_get_device ())) {
1215 /* If ask for user permission to download the messages */
1216 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
1217 ngettext("mcen_nc_get_msg",
1221 /* End if the user does not want to continue */
1222 if (response == GTK_RESPONSE_CANCEL)
1228 /* Register the headers before actually creating the windows: */
1229 iter_not_opened = tny_list_create_iterator (not_opened_headers);
1230 while (!tny_iterator_is_done (iter_not_opened)) {
1231 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter_not_opened));
1233 modest_window_mgr_register_header (mgr, header, NULL);
1234 g_object_unref (header);
1236 tny_iterator_next (iter_not_opened);
1238 g_object_unref (iter_not_opened);
1239 iter_not_opened = NULL;
1241 /* Connect to the account and perform */
1242 if (uncached_msgs > 0) {
1243 modest_platform_connect_and_perform ((GtkWindow *) win, TRUE, g_object_ref (account),
1244 open_msgs_performer, g_object_ref (not_opened_headers));
1246 /* Call directly the performer, do not need to connect */
1247 open_msgs_performer (FALSE, NULL, (GtkWindow *) win, g_object_ref (account),
1248 g_object_ref (not_opened_headers));
1253 g_object_unref (account);
1254 if (not_opened_headers)
1255 g_object_unref (not_opened_headers);
1259 modest_ui_actions_on_open (GtkAction *action, ModestWindow *win)
1264 headers = get_selected_headers (win);
1269 open_msgs_from_headers (headers, win);
1271 g_object_unref(headers);
1276 free_reply_forward_helper (gpointer data)
1278 ReplyForwardHelper *helper;
1280 helper = (ReplyForwardHelper *) data;
1281 g_free (helper->account_name);
1282 g_slice_free (ReplyForwardHelper, helper);
1286 reply_forward_cb (ModestMailOperation *mail_op,
1294 ReplyForwardHelper *rf_helper;
1295 ModestWindow *msg_win = NULL;
1296 ModestEditType edit_type;
1298 TnyAccount *account = NULL;
1299 ModestWindowMgr *mgr = NULL;
1300 gchar *signature = NULL;
1301 gboolean use_signature;
1303 /* If there was any error. The mail operation could be NULL,
1304 this means that we already have the message downloaded and
1305 that we didn't do a mail operation to retrieve it */
1306 if (mail_op && !modest_ui_actions_msg_retrieval_check (mail_op, header, msg))
1309 g_return_if_fail (user_data != NULL);
1310 rf_helper = (ReplyForwardHelper *) user_data;
1312 from = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(),
1313 rf_helper->account_name);
1314 signature = modest_account_mgr_get_signature (modest_runtime_get_account_mgr(),
1315 rf_helper->account_name,
1318 /* Create reply mail */
1319 switch (rf_helper->action) {
1322 modest_tny_msg_create_reply_msg (msg, header, from, signature,
1323 rf_helper->reply_forward_type,
1324 MODEST_TNY_MSG_REPLY_MODE_SENDER);
1326 case ACTION_REPLY_TO_ALL:
1328 modest_tny_msg_create_reply_msg (msg, header, from, signature, rf_helper->reply_forward_type,
1329 MODEST_TNY_MSG_REPLY_MODE_ALL);
1330 edit_type = MODEST_EDIT_TYPE_REPLY;
1332 case ACTION_FORWARD:
1334 modest_tny_msg_create_forward_msg (msg, from, signature, rf_helper->reply_forward_type);
1335 edit_type = MODEST_EDIT_TYPE_FORWARD;
1338 g_return_if_reached ();
1345 g_printerr ("modest: failed to create message\n");
1349 account = modest_tny_account_store_get_server_account (modest_runtime_get_account_store(),
1350 rf_helper->account_name,
1351 TNY_ACCOUNT_TYPE_STORE);
1353 g_printerr ("modest: failed to get tnyaccount for '%s'\n", rf_helper->account_name);
1357 /* Create and register the windows */
1358 msg_win = modest_msg_edit_window_new (new_msg, rf_helper->account_name, FALSE);
1359 mgr = modest_runtime_get_window_mgr ();
1360 modest_window_mgr_register_window (mgr, msg_win);
1362 if (rf_helper->parent_window != NULL) {
1363 gdouble parent_zoom;
1365 parent_zoom = modest_window_get_zoom (MODEST_WINDOW (rf_helper->parent_window));
1366 modest_window_set_zoom (msg_win, parent_zoom);
1369 /* Show edit window */
1370 gtk_widget_show_all (GTK_WIDGET (msg_win));
1374 g_object_unref (msg_win);
1376 g_object_unref (G_OBJECT (new_msg));
1378 g_object_unref (G_OBJECT (account));
1379 /* g_object_unref (msg); */
1380 free_reply_forward_helper (rf_helper);
1383 /* Checks a list of headers. If any of them are not currently
1384 * downloaded (CACHED) then returns TRUE else returns FALSE.
1387 header_list_count_uncached_msgs (TnyList *header_list)
1390 gint uncached_messages = 0;
1392 iter = tny_list_create_iterator (header_list);
1393 while (!tny_iterator_is_done (iter)) {
1396 header = TNY_HEADER (tny_iterator_get_current (iter));
1398 if (!(tny_header_get_flags (header) & TNY_HEADER_FLAG_CACHED))
1399 uncached_messages ++;
1400 g_object_unref (header);
1403 tny_iterator_next (iter);
1405 g_object_unref (iter);
1407 return uncached_messages;
1410 /* Returns FALSE if the user does not want to download the
1411 * messages. Returns TRUE if the user allowed the download.
1414 connect_to_get_msg (ModestWindow *win,
1415 gint num_of_uncached_msgs,
1416 TnyAccount *account)
1418 GtkResponseType response;
1420 /* Allways download if we are online. */
1421 if (tny_device_is_online (modest_runtime_get_device ()))
1424 /* If offline, then ask for user permission to download the messages */
1425 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
1426 ngettext("mcen_nc_get_msg",
1428 num_of_uncached_msgs));
1430 if (response == GTK_RESPONSE_CANCEL)
1433 return modest_platform_connect_and_wait((GtkWindow *) win, account);
1437 * Common code for the reply and forward actions
1440 reply_forward (ReplyForwardAction action, ModestWindow *win)
1442 ModestMailOperation *mail_op = NULL;
1443 TnyList *header_list = NULL;
1444 ReplyForwardHelper *rf_helper = NULL;
1445 guint reply_forward_type;
1446 gboolean continue_download = TRUE;
1447 gboolean do_retrieve = TRUE;
1449 g_return_if_fail (MODEST_IS_WINDOW(win));
1451 /* we need an account when editing */
1452 if (!modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE)) {
1453 if (!modest_ui_actions_run_account_setup_wizard (win))
1457 header_list = get_selected_headers (win);
1461 reply_forward_type =
1462 modest_conf_get_int (modest_runtime_get_conf (),
1463 (action == ACTION_FORWARD) ? MODEST_CONF_FORWARD_TYPE : MODEST_CONF_REPLY_TYPE,
1466 /* check if we need to download msg before asking about it */
1467 do_retrieve = (action == ACTION_FORWARD) ||
1468 (reply_forward_type != MODEST_TNY_MSG_REPLY_TYPE_CITE);
1471 gint num_of_unc_msgs;
1473 /* check that the messages have been previously downloaded */
1474 num_of_unc_msgs = header_list_count_uncached_msgs(header_list);
1475 /* If there are any uncached message ask the user
1476 * whether he/she wants to download them. */
1477 if (num_of_unc_msgs) {
1478 TnyAccount *account = get_account_from_header_list (header_list);
1479 continue_download = connect_to_get_msg (win, num_of_unc_msgs, account);
1480 g_object_unref (account);
1484 if (!continue_download) {
1485 g_object_unref (header_list);
1489 /* We assume that we can only select messages of the
1490 same folder and that we reply all of them from the
1491 same account. In fact the interface currently only
1492 allows single selection */
1495 rf_helper = g_slice_new0 (ReplyForwardHelper);
1496 rf_helper->reply_forward_type = reply_forward_type;
1497 rf_helper->action = action;
1498 rf_helper->account_name = g_strdup (modest_window_get_active_account (win));
1500 if ((win != NULL) && (MODEST_IS_WINDOW (win)))
1501 rf_helper->parent_window = GTK_WIDGET (win);
1502 if (!rf_helper->account_name)
1503 rf_helper->account_name =
1504 modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
1506 if (MODEST_IS_MSG_VIEW_WINDOW(win)) {
1509 /* Get header and message. Do not free them here, the
1510 reply_forward_cb must do it */
1511 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW(win));
1512 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW(win));
1513 if (!msg || !header) {
1515 g_object_unref (msg);
1516 g_printerr ("modest: no message found\n");
1519 reply_forward_cb (NULL, header, FALSE, msg, NULL, rf_helper);
1522 g_object_unref (header);
1527 /* Only reply/forward to one message */
1528 iter = tny_list_create_iterator (header_list);
1529 header = TNY_HEADER (tny_iterator_get_current (iter));
1530 g_object_unref (iter);
1533 /* Retrieve messages */
1536 modest_mail_operation_new_with_error_handling (G_OBJECT(win),
1537 modest_ui_actions_get_msgs_full_error_handler,
1539 modest_mail_operation_queue_add (
1540 modest_runtime_get_mail_operation_queue (), mail_op);
1542 modest_mail_operation_get_msg (mail_op,
1547 g_object_unref(mail_op);
1549 /* we put a ref here to prevent double unref as the reply
1550 * forward callback unrefs the header at its end */
1551 reply_forward_cb (NULL, header, FALSE, NULL, NULL, rf_helper);
1555 g_object_unref (header);
1561 g_object_unref (header_list);
1565 modest_ui_actions_on_reply (GtkAction *action, ModestWindow *win)
1567 g_return_if_fail (MODEST_IS_WINDOW(win));
1569 reply_forward (ACTION_REPLY, win);
1573 modest_ui_actions_on_forward (GtkAction *action, ModestWindow *win)
1575 g_return_if_fail (MODEST_IS_WINDOW(win));
1577 reply_forward (ACTION_FORWARD, win);
1581 modest_ui_actions_on_reply_all (GtkAction *action, ModestWindow *win)
1583 g_return_if_fail (MODEST_IS_WINDOW(win));
1585 reply_forward (ACTION_REPLY_TO_ALL, win);
1589 modest_ui_actions_on_next (GtkAction *action,
1590 ModestWindow *window)
1592 if (MODEST_IS_MAIN_WINDOW (window)) {
1593 GtkWidget *header_view;
1595 header_view = modest_main_window_get_child_widget (
1596 MODEST_MAIN_WINDOW(window),
1597 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1601 modest_header_view_select_next (
1602 MODEST_HEADER_VIEW(header_view));
1603 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
1604 modest_msg_view_window_select_next_message (
1605 MODEST_MSG_VIEW_WINDOW (window));
1607 g_return_if_reached ();
1612 modest_ui_actions_on_prev (GtkAction *action,
1613 ModestWindow *window)
1615 g_return_if_fail (MODEST_IS_WINDOW(window));
1617 if (MODEST_IS_MAIN_WINDOW (window)) {
1618 GtkWidget *header_view;
1619 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
1620 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1624 modest_header_view_select_prev (MODEST_HEADER_VIEW(header_view));
1625 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
1626 modest_msg_view_window_select_previous_message (MODEST_MSG_VIEW_WINDOW (window));
1628 g_return_if_reached ();
1633 modest_ui_actions_on_sort (GtkAction *action,
1634 ModestWindow *window)
1636 g_return_if_fail (MODEST_IS_WINDOW(window));
1638 if (MODEST_IS_MAIN_WINDOW (window)) {
1639 GtkWidget *header_view;
1640 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
1641 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1643 modest_platform_information_banner (NULL, NULL, _CS("ckdg_ib_nothing_to_sort"));
1648 /* Show sorting dialog */
1649 modest_platform_run_sort_dialog (GTK_WINDOW (window), MODEST_SORT_HEADERS);
1654 new_messages_arrived (ModestMailOperation *self,
1655 TnyList *new_headers,
1659 gboolean show_visual_notifications;
1661 source = modest_mail_operation_get_source (self);
1662 show_visual_notifications = (source) ? FALSE : TRUE;
1664 g_object_unref (source);
1666 /* Notify new messages have been downloaded. If the
1667 send&receive was invoked by the user then do not show any
1668 visual notification, only play a sound and activate the LED
1669 (for the Maemo version) */
1670 if ((new_headers != NULL) && (tny_list_get_length (new_headers) > 0))
1671 modest_platform_on_new_headers_received (new_headers,
1672 show_visual_notifications);
1677 retrieve_all_messages_cb (GObject *source,
1679 guint retrieve_limit)
1685 window = GTK_WINDOW (source);
1686 msg = g_strdup_printf (_("mail_nc_msg_count_limit_exceeded"),
1687 num_msgs, retrieve_limit);
1689 /* Ask the user if they want to retrieve all the messages */
1691 modest_platform_run_confirmation_dialog_with_buttons (window, msg,
1692 _("mcen_bd_get_all"),
1693 _("mcen_bd_newest_only"));
1694 /* Free and return */
1696 return (response == GTK_RESPONSE_ACCEPT) ? TRUE : FALSE;
1700 TnyAccount *account;
1702 gchar *account_name;
1706 do_send_receive_performer (gboolean canceled,
1708 GtkWindow *parent_window,
1709 TnyAccount *account,
1712 ModestMailOperation *mail_op;
1713 SendReceiveInfo *info;
1715 info = (SendReceiveInfo *) user_data;
1717 if (err || canceled) {
1721 /* Set send/receive operation in progress */
1722 if (info->win && MODEST_IS_MAIN_WINDOW (info->win)) {
1723 modest_main_window_notify_send_receive_initied (MODEST_MAIN_WINDOW (info->win));
1726 mail_op = modest_mail_operation_new_with_error_handling ((info->win) ? G_OBJECT (info->win) : NULL,
1727 modest_ui_actions_send_receive_error_handler,
1730 if (info->win && MODEST_IS_MAIN_WINDOW (info->win))
1731 g_signal_connect (G_OBJECT(mail_op), "operation-finished",
1732 G_CALLBACK (on_send_receive_finished),
1735 /* Send & receive. */
1736 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
1737 modest_mail_operation_update_account (mail_op, info->account_name, (info->win) ? FALSE : TRUE,
1738 (info->win) ? retrieve_all_messages_cb : NULL,
1739 new_messages_arrived, info->win);
1740 g_object_unref (G_OBJECT (mail_op));
1744 if (info->account_name)
1745 g_free (info->account_name);
1747 g_object_unref (info->win);
1749 g_object_unref (info->account);
1750 g_slice_free (SendReceiveInfo, info);
1754 * This function performs the send & receive required actions. The
1755 * window is used to create the mail operation. Typically it should
1756 * always be the main window, but we pass it as argument in order to
1760 modest_ui_actions_do_send_receive (const gchar *account_name,
1761 gboolean force_connection,
1764 gchar *acc_name = NULL;
1765 SendReceiveInfo *info;
1766 ModestTnyAccountStore *acc_store;
1768 /* If no account name was provided then get the current account, and if
1769 there is no current account then pick the default one: */
1770 if (!account_name) {
1772 acc_name = g_strdup (modest_window_get_active_account (win));
1774 acc_name = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
1776 g_printerr ("modest: cannot get default account\n");
1780 acc_name = g_strdup (account_name);
1783 acc_store = modest_runtime_get_account_store ();
1785 /* Create the info for the connect and perform */
1786 info = g_slice_new (SendReceiveInfo);
1787 info->account_name = acc_name;
1788 info->win = (win) ? g_object_ref (win) : NULL;
1789 info->account = modest_tny_account_store_get_server_account (acc_store, acc_name,
1790 TNY_ACCOUNT_TYPE_STORE);
1792 /* Invoke the connect and perform */
1793 modest_platform_connect_and_perform ((win) ? GTK_WINDOW (win) : NULL,
1794 force_connection, info->account,
1795 do_send_receive_performer, info);
1800 modest_ui_actions_do_cancel_send (const gchar *account_name,
1803 TnyTransportAccount *transport_account;
1804 TnySendQueue *send_queue = NULL;
1805 GError *error = NULL;
1807 /* Get transport account */
1809 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
1810 (modest_runtime_get_account_store(),
1812 TNY_ACCOUNT_TYPE_TRANSPORT));
1813 if (!transport_account) {
1814 g_printerr ("modest: no transport account found for '%s'\n", account_name);
1819 send_queue = TNY_SEND_QUEUE (modest_runtime_get_send_queue (transport_account));
1820 if (!TNY_IS_SEND_QUEUE(send_queue)) {
1821 g_set_error (&error, MODEST_MAIL_OPERATION_ERROR,
1822 MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND,
1823 "modest: could not find send queue for account\n");
1825 /* Keeep messages in outbox folder */
1826 tny_send_queue_cancel (send_queue, FALSE, &error);
1830 if (transport_account != NULL)
1831 g_object_unref (G_OBJECT (transport_account));
1835 modest_ui_actions_cancel_send_all (ModestWindow *win)
1837 GSList *account_names, *iter;
1839 account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
1842 iter = account_names;
1844 modest_ui_actions_do_cancel_send ((const char*) iter->data, win);
1845 iter = g_slist_next (iter);
1848 modest_account_mgr_free_account_names (account_names);
1849 account_names = NULL;
1853 modest_ui_actions_cancel_send (GtkAction *action, ModestWindow *win)
1856 /* Check if accounts exist */
1857 gboolean accounts_exist =
1858 modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
1860 /* If not, allow the user to create an account before trying to send/receive. */
1861 if (!accounts_exist)
1862 modest_ui_actions_on_accounts (NULL, win);
1864 /* Cancel all sending operaitons */
1865 modest_ui_actions_cancel_send_all (win);
1869 * Refreshes all accounts. This function will be used by automatic
1873 modest_ui_actions_do_send_receive_all (ModestWindow *win,
1874 gboolean force_connection)
1876 GSList *account_names, *iter;
1878 account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
1881 iter = account_names;
1883 modest_ui_actions_do_send_receive ((const char*) iter->data, force_connection, win);
1884 iter = g_slist_next (iter);
1887 modest_account_mgr_free_account_names (account_names);
1888 account_names = NULL;
1892 * Handler of the click on Send&Receive button in the main toolbar
1895 modest_ui_actions_on_send_receive (GtkAction *action, ModestWindow *win)
1897 /* Check if accounts exist */
1898 gboolean accounts_exist;
1901 modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
1903 /* If not, allow the user to create an account before trying to send/receive. */
1904 if (!accounts_exist)
1905 modest_ui_actions_on_accounts (NULL, win);
1907 /* Refresh the current folder. The if is always TRUE it's just an extra check */
1908 if (MODEST_IS_MAIN_WINDOW (win)) {
1909 GtkWidget *folder_view;
1910 TnyFolderStore *folder_store;
1913 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
1914 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
1918 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
1921 g_object_unref (folder_store);
1924 /* Refresh the active account. Force the connection if needed */
1925 modest_ui_actions_do_send_receive (NULL, TRUE, win);
1930 modest_ui_actions_toggle_header_list_view (GtkAction *action, ModestMainWindow *main_window)
1933 GtkWidget *header_view;
1935 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1937 header_view = modest_main_window_get_child_widget (main_window,
1938 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1942 conf = modest_runtime_get_conf ();
1944 /* what is saved/restored is depending on the style; thus; we save with
1945 * old style, then update the style, and restore for this new style
1947 modest_widget_memory_save (conf, G_OBJECT(header_view), MODEST_CONF_HEADER_VIEW_KEY);
1949 if (modest_header_view_get_style
1950 (MODEST_HEADER_VIEW(header_view)) == MODEST_HEADER_VIEW_STYLE_DETAILS)
1951 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
1952 MODEST_HEADER_VIEW_STYLE_TWOLINES);
1954 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
1955 MODEST_HEADER_VIEW_STYLE_DETAILS);
1957 modest_widget_memory_restore (conf, G_OBJECT(header_view),
1958 MODEST_CONF_HEADER_VIEW_KEY);
1963 modest_ui_actions_on_header_selected (ModestHeaderView *header_view,
1965 ModestMainWindow *main_window)
1967 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1968 g_return_if_fail (MODEST_IS_HEADER_VIEW (header_view));
1970 /* in the case the folder is empty, show the empty folder message and focus
1972 if (!header && gtk_widget_is_focus (GTK_WIDGET (header_view))) {
1973 if (modest_header_view_is_empty (header_view)) {
1974 TnyFolder *folder = modest_header_view_get_folder (header_view);
1975 GtkWidget *folder_view =
1976 modest_main_window_get_child_widget (main_window,
1977 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
1979 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view), folder, FALSE);
1980 gtk_widget_grab_focus (GTK_WIDGET (folder_view));
1984 /* If no header has been selected then exit */
1989 if (!gtk_widget_is_focus (GTK_WIDGET(header_view)))
1990 gtk_widget_grab_focus (GTK_WIDGET(header_view));
1992 /* Update toolbar dimming state */
1993 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
1997 modest_ui_actions_on_header_activated (ModestHeaderView *header_view,
1999 ModestMainWindow *main_window)
2003 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2008 if (modest_header_view_count_selected_headers (header_view) > 1) {
2009 modest_platform_information_banner (NULL, NULL, _("mcen_ib_select_one_message"));
2014 /* headers = tny_simple_list_new (); */
2015 /* tny_list_prepend (headers, G_OBJECT (header)); */
2016 headers = modest_header_view_get_selected_headers (header_view);
2018 open_msgs_from_headers (headers, MODEST_WINDOW (main_window));
2020 g_object_unref (headers);
2024 set_active_account_from_tny_account (TnyAccount *account,
2025 ModestWindow *window)
2027 const gchar *server_acc_name = tny_account_get_id (account);
2029 /* We need the TnyAccount provided by the
2030 account store because that is the one that
2031 knows the name of the Modest account */
2032 TnyAccount *modest_server_account = modest_server_account =
2033 modest_tny_account_store_get_tny_account_by (modest_runtime_get_account_store (),
2034 MODEST_TNY_ACCOUNT_STORE_QUERY_ID,
2036 if (!modest_server_account) {
2037 g_warning ("%s: could not get tny account\n", __FUNCTION__);
2041 /* Update active account, but only if it's not a pseudo-account */
2042 if ((!modest_tny_account_is_virtual_local_folders(modest_server_account)) &&
2043 (!modest_tny_account_is_memory_card_account(modest_server_account))) {
2044 const gchar *modest_acc_name =
2045 modest_tny_account_get_parent_modest_account_name_for_server_account (modest_server_account);
2046 if (modest_acc_name)
2047 modest_window_set_active_account (window, modest_acc_name);
2050 g_object_unref (modest_server_account);
2055 folder_refreshed_cb (ModestMailOperation *mail_op,
2059 ModestMainWindow *win = NULL;
2060 GtkWidget *header_view;
2062 g_return_if_fail (TNY_IS_FOLDER (folder));
2064 win = MODEST_MAIN_WINDOW (user_data);
2066 modest_main_window_get_child_widget(win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2069 TnyFolder *current_folder;
2071 current_folder = modest_header_view_get_folder (MODEST_HEADER_VIEW (header_view));
2072 if (current_folder != NULL && folder != current_folder) {
2073 g_object_unref (current_folder);
2075 } else if (current_folder)
2076 g_object_unref (current_folder);
2079 /* Check if folder is empty and set headers view contents style */
2080 if (tny_folder_get_all_count (folder) == 0)
2081 modest_main_window_set_contents_style (win,
2082 MODEST_MAIN_WINDOW_CONTENTS_STYLE_EMPTY);
2086 modest_ui_actions_on_folder_selection_changed (ModestFolderView *folder_view,
2087 TnyFolderStore *folder_store,
2089 ModestMainWindow *main_window)
2092 GtkWidget *header_view;
2094 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2096 header_view = modest_main_window_get_child_widget(main_window,
2097 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2101 conf = modest_runtime_get_conf ();
2103 if (TNY_IS_ACCOUNT (folder_store)) {
2105 set_active_account_from_tny_account (TNY_ACCOUNT (folder_store), MODEST_WINDOW (main_window));
2107 /* Show account details */
2108 modest_main_window_set_contents_style (main_window, MODEST_MAIN_WINDOW_CONTENTS_STYLE_DETAILS);
2111 if (TNY_IS_FOLDER (folder_store) && selected) {
2113 /* Update the active account */
2114 TnyAccount *account = modest_tny_folder_get_account (TNY_FOLDER (folder_store));
2116 set_active_account_from_tny_account (account, MODEST_WINDOW (main_window));
2117 g_object_unref (account);
2121 /* Set the header style by default, it could
2122 be changed later by the refresh callback to
2124 modest_main_window_set_contents_style (main_window,
2125 MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS);
2127 /* Set folder on header view. This function
2128 will call tny_folder_refresh_async so we
2129 pass a callback that will be called when
2130 finished. We use that callback to set the
2131 empty view if there are no messages */
2132 modest_header_view_set_folder (MODEST_HEADER_VIEW(header_view),
2133 TNY_FOLDER (folder_store),
2134 folder_refreshed_cb,
2137 /* Restore configuration. We need to do this
2138 *after* the set_folder because the widget
2139 memory asks the header view about its
2141 modest_widget_memory_restore (modest_runtime_get_conf (),
2142 G_OBJECT(header_view),
2143 MODEST_CONF_HEADER_VIEW_KEY);
2145 /* Update the active account */
2146 //modest_window_set_active_account (MODEST_WINDOW (main_window), NULL);
2147 /* Save only if we're seeing headers */
2148 if (modest_main_window_get_contents_style (main_window) ==
2149 MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS)
2150 modest_widget_memory_save (conf, G_OBJECT (header_view),
2151 MODEST_CONF_HEADER_VIEW_KEY);
2152 modest_header_view_clear (MODEST_HEADER_VIEW(header_view));
2156 /* Update toolbar dimming state */
2157 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
2161 modest_ui_actions_on_item_not_found (ModestHeaderView *header_view,ModestItemType type,
2168 item = (type == MODEST_ITEM_TYPE_FOLDER) ? "folder" : "message";
2170 online = tny_device_is_online (modest_runtime_get_device());
2173 /* already online -- the item is simply not there... */
2174 dialog = gtk_message_dialog_new (GTK_WINDOW (win),
2176 GTK_MESSAGE_WARNING,
2178 _("The %s you selected cannot be found"),
2180 gtk_dialog_add_button (GTK_DIALOG (dialog),_("mcen_bd_dialog_ok"), GTK_RESPONSE_ACCEPT);
2181 gtk_dialog_run (GTK_DIALOG(dialog));
2183 dialog = gtk_dialog_new_with_buttons (_("Connection requested"),
2186 _("mcen_bd_dialog_cancel"),
2187 GTK_RESPONSE_REJECT,
2188 _("mcen_bd_dialog_ok"),
2189 GTK_RESPONSE_ACCEPT,
2191 txt = g_strdup_printf (_("This %s is not available in offline mode.\n"
2192 "Do you want to get online?"), item);
2193 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
2194 gtk_label_new (txt), FALSE, FALSE, 0);
2195 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
2198 gtk_window_set_default_size (GTK_WINDOW(dialog), 300, 300);
2199 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
2200 /* TODO: Comment about why is this commented out: */
2201 /* modest_platform_connect_and_wait (); */
2204 gtk_widget_destroy (dialog);
2208 modest_ui_actions_on_msg_link_hover (ModestMsgView *msgview, const gchar* link,
2211 /* g_message ("%s %s", __FUNCTION__, link); */
2216 modest_ui_actions_on_msg_link_clicked (ModestMsgView *msgview, const gchar* link,
2219 modest_platform_activate_uri (link);
2223 modest_ui_actions_on_msg_link_contextual (ModestMsgView *msgview, const gchar* link,
2226 modest_platform_show_uri_popup (link);
2230 modest_ui_actions_on_msg_attachment_clicked (ModestMsgView *msgview, TnyMimePart *mime_part,
2233 modest_msg_view_window_view_attachment (MODEST_MSG_VIEW_WINDOW (win), mime_part);
2237 modest_ui_actions_on_msg_recpt_activated (ModestMsgView *msgview,
2238 const gchar *address,
2241 /* g_message ("%s %s", __FUNCTION__, address); */
2245 on_save_to_drafts_cb (ModestMailOperation *mail_op,
2246 TnyMsg *saved_draft,
2249 ModestMsgEditWindow *edit_window;
2250 ModestMainWindow *win;
2252 /* FIXME. Make the header view sensitive again. This is a
2253 * temporary hack. See modest_ui_actions_on_save_to_drafts()
2255 win = MODEST_MAIN_WINDOW(modest_window_mgr_get_main_window(
2256 modest_runtime_get_window_mgr(), FALSE));
2258 GtkWidget *hdrview = modest_main_window_get_child_widget(
2259 win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2260 if (hdrview) gtk_widget_set_sensitive(hdrview, TRUE);
2263 edit_window = MODEST_MSG_EDIT_WINDOW (user_data);
2265 /* It might not be a good idea to do nothing if there was an error,
2266 * so let's at least show a generic error banner. */
2267 /* TODO error while saving attachment, show "Saving draft failed" banner */
2268 if (modest_mail_operation_get_error (mail_op) != NULL) {
2269 g_warning ("%s failed: %s\n", __FUNCTION__, (modest_mail_operation_get_error (mail_op))->message);
2270 modest_platform_information_banner (NULL, NULL, _("mail_ib_file_operation_failed"));
2274 modest_msg_edit_window_set_draft (edit_window, saved_draft);
2278 modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edit_window)
2280 TnyTransportAccount *transport_account;
2281 ModestMailOperation *mail_operation;
2283 gchar *account_name, *from;
2284 ModestAccountMgr *account_mgr;
2287 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window));
2289 data = modest_msg_edit_window_get_msg_data (edit_window);
2291 account_name = g_strdup (data->account_name);
2292 account_mgr = modest_runtime_get_account_mgr();
2294 account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
2296 account_name = modest_account_mgr_get_default_account (account_mgr);
2297 if (!account_name) {
2298 g_printerr ("modest: no account found\n");
2299 modest_msg_edit_window_free_msg_data (edit_window, data);
2303 if (!strcmp (account_name, MODEST_LOCAL_FOLDERS_ACCOUNT_ID)) {
2304 account_name = g_strdup (data->account_name);
2308 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
2309 (modest_runtime_get_account_store(),
2311 TNY_ACCOUNT_TYPE_TRANSPORT));
2312 if (!transport_account) {
2313 g_printerr ("modest: no transport account found for '%s'\n", account_name);
2314 g_free (account_name);
2315 modest_msg_edit_window_free_msg_data (edit_window, data);
2318 from = modest_account_mgr_get_from_string (account_mgr, account_name);
2320 /* Create the mail operation */
2321 mail_operation = modest_mail_operation_new (NULL);
2322 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
2324 modest_mail_operation_save_to_drafts (mail_operation,
2336 data->priority_flags,
2337 on_save_to_drafts_cb,
2339 info_text = g_strdup_printf (_("mail_va_saved_to_drafts"), _("mcen_me_folder_drafts"));
2340 modest_platform_information_banner (NULL, NULL, info_text);
2345 g_free (account_name);
2346 g_object_unref (G_OBJECT (transport_account));
2347 g_object_unref (G_OBJECT (mail_operation));
2349 modest_msg_edit_window_free_msg_data (edit_window, data);
2350 modest_msg_edit_window_reset_modified (edit_window);
2353 * If the drafts folder is selected then make the header view
2354 * insensitive while the message is being saved to drafts
2355 * (it'll be sensitive again in on_save_to_drafts_cb()). This
2356 * is not very clean but it avoids letting the drafts folder
2357 * in an inconsistent state: the user could edit the message
2358 * being saved and undesirable things would happen.
2359 * In the average case the user won't notice anything at
2360 * all. In the worst case (the user is editing a really big
2361 * file from Drafts) the header view will be insensitive
2362 * during the saving process (10 or 20 seconds, depending on
2363 * the message). Anyway this is just a quick workaround: once
2364 * we find a better solution it should be removed
2365 * See NB#65125 (commend #18) for details.
2367 ModestMainWindow *win = MODEST_MAIN_WINDOW(modest_window_mgr_get_main_window(
2368 modest_runtime_get_window_mgr(), FALSE));
2370 ModestFolderView *view = MODEST_FOLDER_VIEW(modest_main_window_get_child_widget(
2371 win, MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW));
2373 TnyFolder *folder = TNY_FOLDER(modest_folder_view_get_selected(view));
2375 if (modest_tny_folder_is_local_folder(folder)) {
2376 TnyFolderType folder_type;
2377 folder_type = modest_tny_folder_get_local_or_mmc_folder_type(folder);
2378 if (folder_type == TNY_FOLDER_TYPE_DRAFTS) {
2379 GtkWidget *hdrview = modest_main_window_get_child_widget(
2380 win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2381 if (hdrview) gtk_widget_set_sensitive(hdrview, FALSE);
2385 if (folder != NULL) g_object_unref(folder);
2390 /* For instance, when clicking the Send toolbar button when editing a message: */
2392 modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
2394 TnyTransportAccount *transport_account = NULL;
2396 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window));
2398 if (!modest_msg_edit_window_check_names (edit_window, TRUE))
2401 /* FIXME: Code added just for testing. The final version will
2402 use the send queue provided by tinymail and some
2404 MsgData *data = modest_msg_edit_window_get_msg_data (edit_window);
2406 ModestAccountMgr *account_mgr = modest_runtime_get_account_mgr();
2407 gchar *account_name = g_strdup (data->account_name);
2409 account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
2412 account_name = modest_account_mgr_get_default_account (account_mgr);
2414 if (!account_name) {
2415 modest_msg_edit_window_free_msg_data (edit_window, data);
2416 /* Run account setup wizard */
2417 if (!modest_ui_actions_run_account_setup_wizard (MODEST_WINDOW(edit_window))) {
2422 /* Get the currently-active transport account for this modest account: */
2423 if (strcmp (account_name, MODEST_LOCAL_FOLDERS_ACCOUNT_ID) != 0) {
2424 transport_account = TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
2425 (modest_runtime_get_account_store(),
2426 account_name, TNY_ACCOUNT_TYPE_TRANSPORT));
2429 if (!transport_account) {
2430 modest_msg_edit_window_free_msg_data (edit_window, data);
2431 /* Run account setup wizard */
2432 if (!modest_ui_actions_run_account_setup_wizard(MODEST_WINDOW(edit_window)))
2436 gchar *from = modest_account_mgr_get_from_string (account_mgr, account_name);
2438 /* Create the mail operation */
2439 ModestMailOperation *mail_operation = modest_mail_operation_new (NULL);
2440 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
2442 modest_mail_operation_send_new_mail (mail_operation,
2454 data->priority_flags);
2456 if (modest_mail_operation_get_status (mail_operation) == MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS)
2457 modest_platform_information_banner (NULL, NULL, _("mcen_ib_outbox_waiting_to_be_sent"));
2462 g_free (account_name);
2463 g_object_unref (G_OBJECT (transport_account));
2464 g_object_unref (G_OBJECT (mail_operation));
2466 modest_msg_edit_window_free_msg_data (edit_window, data);
2467 modest_msg_edit_window_set_sent (edit_window, TRUE);
2469 /* Save settings and close the window: */
2470 modest_ui_actions_on_close_window (NULL, MODEST_WINDOW (edit_window));
2474 modest_ui_actions_on_toggle_bold (GtkToggleAction *action,
2475 ModestMsgEditWindow *window)
2477 ModestMsgEditFormatState *format_state = NULL;
2479 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2480 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
2482 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2485 format_state = modest_msg_edit_window_get_format_state (window);
2486 g_return_if_fail (format_state != NULL);
2488 format_state->bold = gtk_toggle_action_get_active (action);
2489 modest_msg_edit_window_set_format_state (window, format_state);
2490 g_free (format_state);
2495 modest_ui_actions_on_toggle_italics (GtkToggleAction *action,
2496 ModestMsgEditWindow *window)
2498 ModestMsgEditFormatState *format_state = NULL;
2500 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2501 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
2503 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2506 format_state = modest_msg_edit_window_get_format_state (window);
2507 g_return_if_fail (format_state != NULL);
2509 format_state->italics = gtk_toggle_action_get_active (action);
2510 modest_msg_edit_window_set_format_state (window, format_state);
2511 g_free (format_state);
2516 modest_ui_actions_on_toggle_bullets (GtkToggleAction *action,
2517 ModestMsgEditWindow *window)
2519 ModestMsgEditFormatState *format_state = NULL;
2521 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2522 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
2524 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2527 format_state = modest_msg_edit_window_get_format_state (window);
2528 g_return_if_fail (format_state != NULL);
2530 format_state->bullet = gtk_toggle_action_get_active (action);
2531 modest_msg_edit_window_set_format_state (window, format_state);
2532 g_free (format_state);
2537 modest_ui_actions_on_change_justify (GtkRadioAction *action,
2538 GtkRadioAction *selected,
2539 ModestMsgEditWindow *window)
2541 ModestMsgEditFormatState *format_state = NULL;
2542 GtkJustification value;
2544 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2546 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2549 value = gtk_radio_action_get_current_value (selected);
2551 format_state = modest_msg_edit_window_get_format_state (window);
2552 g_return_if_fail (format_state != NULL);
2554 format_state->justification = value;
2555 modest_msg_edit_window_set_format_state (window, format_state);
2556 g_free (format_state);
2560 modest_ui_actions_on_select_editor_color (GtkAction *action,
2561 ModestMsgEditWindow *window)
2563 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2564 g_return_if_fail (GTK_IS_ACTION (action));
2566 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2569 modest_msg_edit_window_select_color (window);
2573 modest_ui_actions_on_select_editor_background_color (GtkAction *action,
2574 ModestMsgEditWindow *window)
2576 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2577 g_return_if_fail (GTK_IS_ACTION (action));
2579 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2582 modest_msg_edit_window_select_background_color (window);
2586 modest_ui_actions_on_insert_image (GtkAction *action,
2587 ModestMsgEditWindow *window)
2589 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2590 g_return_if_fail (GTK_IS_ACTION (action));
2592 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2595 modest_msg_edit_window_insert_image (window);
2599 modest_ui_actions_on_attach_file (GtkAction *action,
2600 ModestMsgEditWindow *window)
2602 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2603 g_return_if_fail (GTK_IS_ACTION (action));
2605 modest_msg_edit_window_offer_attach_file (window);
2609 modest_ui_actions_on_remove_attachments (GtkAction *action,
2610 ModestMsgEditWindow *window)
2612 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2613 g_return_if_fail (GTK_IS_ACTION (action));
2615 modest_msg_edit_window_remove_attachments (window, NULL);
2619 do_create_folder_cb (ModestMailOperation *mail_op,
2620 TnyFolderStore *parent_folder,
2621 TnyFolder *new_folder,
2624 gchar *suggested_name = (gchar *) user_data;
2625 GtkWindow *source_win = (GtkWindow *) modest_mail_operation_get_source (mail_op);
2627 if (modest_mail_operation_get_error (mail_op)) {
2629 modest_platform_information_banner (GTK_WIDGET (source_win), NULL,
2630 _("mail_in_ui_folder_create_error"));
2633 do_create_folder (source_win, parent_folder, (const gchar *) suggested_name);
2635 /* the 'source_win' is either the ModestMainWindow, or the 'Move to folder'-dialog
2636 * FIXME: any other? */
2637 GtkWidget *folder_view;
2639 if (MODEST_IS_MAIN_WINDOW(source_win))
2641 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (source_win),
2642 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2645 get_folder_view_from_move_to_dialog (GTK_WIDGET(source_win));
2647 /* Select the newly created folder */
2648 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view),
2650 g_object_unref (new_folder);
2652 /* Free. Note that the first time it'll be NULL so noop */
2653 g_free (suggested_name);
2654 g_object_unref (source_win);
2658 do_create_folder (GtkWindow *parent_window,
2659 TnyFolderStore *parent_folder,
2660 const gchar *suggested_name)
2663 gchar *folder_name = NULL;
2665 result = modest_platform_run_new_folder_dialog (GTK_WINDOW (parent_window),
2667 (gchar *) suggested_name,
2670 if (result == GTK_RESPONSE_ACCEPT) {
2671 ModestMailOperation *mail_op;
2673 mail_op = modest_mail_operation_new (G_OBJECT(parent_window));
2675 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
2677 modest_mail_operation_create_folder (mail_op,
2679 (const gchar *) folder_name,
2680 do_create_folder_cb,
2682 g_object_unref (mail_op);
2687 create_folder_performer (gboolean canceled,
2689 GtkWindow *parent_window,
2690 TnyAccount *account,
2693 TnyFolderStore *parent_folder = TNY_FOLDER_STORE (user_data);
2695 if (canceled || err) {
2699 /* Run the new folder dialog */
2700 do_create_folder (GTK_WINDOW (parent_window), parent_folder, NULL);
2703 g_object_unref (parent_folder);
2707 modest_ui_actions_create_folder(GtkWidget *parent_window,
2708 GtkWidget *folder_view)
2710 TnyFolderStore *parent_folder;
2712 parent_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
2714 if (parent_folder) {
2715 /* The parent folder will be freed in the callback */
2716 modest_platform_connect_if_remote_and_perform (GTK_WINDOW (parent_window),
2719 create_folder_performer,
2725 modest_ui_actions_on_new_folder (GtkAction *action, ModestMainWindow *main_window)
2727 GtkWidget *folder_view;
2729 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2731 folder_view = modest_main_window_get_child_widget (main_window,
2732 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2736 modest_ui_actions_create_folder (GTK_WIDGET (main_window), folder_view);
2740 modest_ui_actions_rename_folder_error_handler (ModestMailOperation *mail_op,
2743 ModestMainWindow *window = MODEST_MAIN_WINDOW (user_data);
2744 const GError *error = NULL;
2745 const gchar *message = NULL;
2747 /* Get error message */
2748 error = modest_mail_operation_get_error (mail_op);
2750 g_return_if_reached ();
2752 switch (error->code) {
2753 case MODEST_MAIL_OPERATION_ERROR_FOLDER_EXISTS:
2754 message = _CS("ckdg_ib_folder_already_exists");
2757 g_warning ("%s: BUG: unexpected error:[%d]: %s", __FUNCTION__,
2758 error->code, error->message);
2762 modest_platform_information_banner (GTK_WIDGET (window), NULL, message);
2766 TnyFolderStore *folder;
2771 on_rename_folder_cb (ModestMailOperation *mail_op,
2772 TnyFolder *new_folder,
2776 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (user_data),
2781 on_rename_folder_performer (gboolean canceled,
2783 GtkWindow *parent_window,
2784 TnyAccount *account,
2787 ModestMailOperation *mail_op = NULL;
2788 GtkTreeSelection *sel = NULL;
2789 GtkWidget *folder_view = NULL;
2790 RenameFolderInfo *data = (RenameFolderInfo*)user_data;
2792 if (!canceled && (err == NULL) && MODEST_IS_MAIN_WINDOW(parent_window)) {
2794 folder_view = modest_main_window_get_child_widget (
2795 MODEST_MAIN_WINDOW (parent_window),
2796 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2799 modest_mail_operation_new_with_error_handling (G_OBJECT(parent_window),
2800 modest_ui_actions_rename_folder_error_handler,
2801 parent_window, NULL);
2803 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
2806 /* Clear the headers view */
2807 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_view));
2808 gtk_tree_selection_unselect_all (sel);
2810 /* Actually rename the folder */
2811 modest_mail_operation_rename_folder (mail_op,
2812 TNY_FOLDER (data->folder),
2813 (const gchar *) (data->new_name),
2814 on_rename_folder_cb,
2818 g_object_unref (mail_op);
2819 g_free (data->new_name);
2824 modest_ui_actions_on_rename_folder (GtkAction *action,
2825 ModestMainWindow *main_window)
2827 TnyFolderStore *folder;
2828 GtkWidget *folder_view;
2829 GtkWidget *header_view;
2831 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2833 folder_view = modest_main_window_get_child_widget (main_window,
2834 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2838 header_view = modest_main_window_get_child_widget (main_window,
2839 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2844 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
2849 if (TNY_IS_FOLDER (folder)) {
2852 const gchar *current_name;
2853 TnyFolderStore *parent;
2854 gboolean do_rename = TRUE;
2856 current_name = tny_folder_get_name (TNY_FOLDER (folder));
2857 parent = tny_folder_get_folder_store (TNY_FOLDER (folder));
2858 response = modest_platform_run_rename_folder_dialog (GTK_WINDOW (main_window),
2859 parent, current_name,
2861 g_object_unref (parent);
2863 if (response != GTK_RESPONSE_ACCEPT || strlen (folder_name) == 0) {
2866 RenameFolderInfo *rename_folder_data = g_new0 (RenameFolderInfo, 1);
2867 rename_folder_data->folder = folder;
2868 rename_folder_data->new_name = folder_name;
2869 modest_platform_connect_if_remote_and_perform (GTK_WINDOW(main_window), TRUE,
2870 folder, on_rename_folder_performer, rename_folder_data);
2873 g_object_unref (folder);
2877 modest_ui_actions_delete_folder_error_handler (ModestMailOperation *mail_op,
2880 GObject *win = modest_mail_operation_get_source (mail_op);
2882 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
2883 _("mail_in_ui_folder_delete_error"));
2884 g_object_unref (win);
2888 TnyFolderStore *folder;
2889 gboolean move_to_trash;
2893 on_delete_folder_cb (gboolean canceled,
2895 GtkWindow *parent_window,
2896 TnyAccount *account,
2899 DeleteFolderInfo *info = (DeleteFolderInfo*) user_data;
2900 GtkWidget *folder_view;
2901 ModestMailOperation *mail_op;
2902 GtkTreeSelection *sel;
2904 if (!MODEST_IS_MAIN_WINDOW(parent_window) || canceled || (err!=NULL)) {
2905 g_object_unref (G_OBJECT (info->folder));
2909 folder_view = modest_main_window_get_child_widget (
2910 MODEST_MAIN_WINDOW (parent_window),
2911 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2913 /* Unselect the folder before deleting it to free the headers */
2914 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_view));
2915 gtk_tree_selection_unselect_all (sel);
2917 /* Create the mail operation */
2919 modest_mail_operation_new_with_error_handling (G_OBJECT(parent_window),
2920 modest_ui_actions_delete_folder_error_handler,
2923 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
2925 modest_mail_operation_remove_folder (mail_op, TNY_FOLDER (info->folder), info->move_to_trash);
2927 modest_folder_view_select_first_inbox_or_local (MODEST_FOLDER_VIEW (folder_view));
2929 g_object_unref (G_OBJECT (mail_op));
2930 g_object_unref (G_OBJECT (info->folder));
2935 delete_folder (ModestMainWindow *main_window, gboolean move_to_trash)
2937 TnyFolderStore *folder;
2938 GtkWidget *folder_view;
2942 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2944 folder_view = modest_main_window_get_child_widget (main_window,
2945 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2949 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
2951 /* Show an error if it's an account */
2952 if (!TNY_IS_FOLDER (folder)) {
2953 modest_platform_run_information_dialog (GTK_WINDOW (main_window),
2954 _("mail_in_ui_folder_delete_error"));
2955 g_object_unref (G_OBJECT (folder));
2960 message = g_strdup_printf (_("mcen_nc_delete_folder_text"),
2961 tny_folder_get_name (TNY_FOLDER (folder)));
2962 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (main_window),
2963 (const gchar *) message);
2966 if (response == GTK_RESPONSE_OK) {
2967 DeleteFolderInfo *info;
2968 info = g_new0(DeleteFolderInfo, 1);
2969 info->folder = folder;
2970 info->move_to_trash = move_to_trash;
2971 g_object_ref (G_OBJECT (info->folder));
2972 TnyAccount *account = tny_folder_get_account (TNY_FOLDER (folder));
2973 modest_platform_connect_if_remote_and_perform (GTK_WINDOW (main_window),
2975 TNY_FOLDER_STORE (account),
2976 on_delete_folder_cb, info);
2977 g_object_unref (account);
2979 g_object_unref (G_OBJECT (folder));
2983 modest_ui_actions_on_delete_folder (GtkAction *action,
2984 ModestMainWindow *main_window)
2986 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2988 delete_folder (main_window, FALSE);
2992 modest_ui_actions_on_move_folder_to_trash_folder (GtkAction *action, ModestMainWindow *main_window)
2994 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2996 delete_folder (main_window, TRUE);
3001 show_error (GtkWidget *parent_widget, const gchar* text)
3003 modest_platform_information_banner(parent_widget, NULL, text);
3006 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_window, text)); */
3008 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
3015 gtk_dialog_run (dialog);
3016 gtk_widget_destroy (GTK_WIDGET (dialog));
3021 modest_ui_actions_on_password_requested (TnyAccountStore *account_store,
3022 const gchar* server_account_name,
3027 ModestMainWindow *main_window)
3029 g_return_if_fail(server_account_name);
3031 /* Initalize output parameters: */
3038 #ifdef MODEST_PLATFORM_MAEMO
3039 /* Maemo uses a different (awkward) button order,
3040 * It should probably just use gtk_alternative_dialog_button_order ().
3042 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
3045 _("mcen_bd_dialog_ok"),
3046 GTK_RESPONSE_ACCEPT,
3047 _("mcen_bd_dialog_cancel"),
3048 GTK_RESPONSE_REJECT,
3051 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
3055 GTK_RESPONSE_REJECT,
3057 GTK_RESPONSE_ACCEPT,
3059 #endif /* MODEST_PLATFORM_MAEMO */
3061 modest_window_mgr_set_modal (modest_runtime_get_window_mgr(), GTK_WINDOW (dialog));
3063 gchar *server_name = modest_account_mgr_get_server_account_hostname (
3064 modest_runtime_get_account_mgr(), server_account_name);
3065 if (!server_name) {/* This happened once, though I don't know why. murrayc. */
3066 g_warning("%s: Could not get server name for server account '%s'", __FUNCTION__, server_account_name);
3072 /* This causes a warning because the logical ID has no %s in it,
3073 * though the translation does, but there is not much we can do about that: */
3074 gchar *txt = g_strdup_printf (_("mail_ia_password_info"), server_name);
3075 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), gtk_label_new(txt),
3078 g_free (server_name);
3082 gchar *initial_username = modest_account_mgr_get_server_account_username (
3083 modest_runtime_get_account_mgr(), server_account_name);
3085 GtkWidget *entry_username = gtk_entry_new ();
3086 if (initial_username)
3087 gtk_entry_set_text (GTK_ENTRY (entry_username), initial_username);
3088 /* Dim this if a connection has ever succeeded with this username,
3089 * as per the UI spec: */
3090 const gboolean username_known =
3091 modest_account_mgr_get_server_account_username_has_succeeded(
3092 modest_runtime_get_account_mgr(), server_account_name);
3093 gtk_widget_set_sensitive (entry_username, !username_known);
3095 #ifdef MODEST_PLATFORM_MAEMO
3096 /* Auto-capitalization is the default, so let's turn it off: */
3097 hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_username), HILDON_GTK_INPUT_MODE_FULL);
3099 /* Create a size group to be used by all captions.
3100 * Note that HildonCaption does not create a default size group if we do not specify one.
3101 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
3102 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
3104 GtkWidget *caption = hildon_caption_new (sizegroup,
3105 _("mail_fi_username"), entry_username, NULL, HILDON_CAPTION_MANDATORY);
3106 gtk_widget_show (entry_username);
3107 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
3108 FALSE, FALSE, MODEST_MARGIN_HALF);
3109 gtk_widget_show (caption);
3111 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry_username,
3113 #endif /* MODEST_PLATFORM_MAEMO */
3116 GtkWidget *entry_password = gtk_entry_new ();
3117 gtk_entry_set_visibility (GTK_ENTRY(entry_password), FALSE);
3118 /* gtk_entry_set_invisible_char (GTK_ENTRY(entry_password), "*"); */
3120 #ifdef MODEST_PLATFORM_MAEMO
3121 /* Auto-capitalization is the default, so let's turn it off: */
3122 hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_password),
3123 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
3125 caption = hildon_caption_new (sizegroup,
3126 _("mail_fi_password"), entry_password, NULL, HILDON_CAPTION_MANDATORY);
3127 gtk_widget_show (entry_password);
3128 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
3129 FALSE, FALSE, MODEST_MARGIN_HALF);
3130 gtk_widget_show (caption);
3131 g_object_unref (sizegroup);
3133 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry_password,
3135 #endif /* MODEST_PLATFORM_MAEMO */
3137 if (initial_username != NULL)
3138 gtk_widget_grab_focus (GTK_WIDGET (entry_password));
3140 /* This is not in the Maemo UI spec:
3141 remember_pass_check = gtk_check_button_new_with_label (_("Remember password"));
3142 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), remember_pass_check,
3146 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
3148 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
3150 *username = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_username)));
3152 modest_account_mgr_set_server_account_username (
3153 modest_runtime_get_account_mgr(), server_account_name,
3156 const gboolean username_was_changed =
3157 (strcmp (*username, initial_username) != 0);
3158 if (username_was_changed) {
3159 g_warning ("%s: tinymail does not yet support changing the "
3160 "username in the get_password() callback.\n", __FUNCTION__);
3165 *password = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_password)));
3167 /* We do not save the password in the configuration,
3168 * because this function is only called for passwords that should
3169 * not be remembered:
3170 modest_server_account_set_password (
3171 modest_runtime_get_account_mgr(), server_account_name,
3180 show_error(GTK_WIDGET (main_window), _("mail_ib_login_cancelled"));
3192 /* This is not in the Maemo UI spec:
3193 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (remember_pass_check)))
3199 gtk_widget_destroy (dialog);
3201 /* printf ("DEBUG: %s: cancel=%d\n", __FUNCTION__, *cancel); */
3205 modest_ui_actions_on_cut (GtkAction *action,
3206 ModestWindow *window)
3208 GtkWidget *focused_widget;
3209 GtkClipboard *clipboard;
3211 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
3212 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
3213 if (GTK_IS_EDITABLE (focused_widget)) {
3214 gtk_editable_cut_clipboard (GTK_EDITABLE(focused_widget));
3215 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3216 gtk_clipboard_store (clipboard);
3217 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
3218 GtkTextBuffer *buffer;
3220 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
3221 gtk_text_buffer_cut_clipboard (buffer, clipboard, TRUE);
3222 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3223 gtk_clipboard_store (clipboard);
3224 } else if (MODEST_IS_HEADER_VIEW (focused_widget)) {
3225 TnyList *header_list = modest_header_view_get_selected_headers (
3226 MODEST_HEADER_VIEW (focused_widget));
3227 gboolean continue_download = FALSE;
3228 gint num_of_unc_msgs;
3230 num_of_unc_msgs = header_list_count_uncached_msgs(header_list);
3232 if (num_of_unc_msgs) {
3233 TnyAccount *account = get_account_from_header_list (header_list);
3234 continue_download = connect_to_get_msg (window, num_of_unc_msgs, account);
3235 g_object_unref (account);
3238 if (num_of_unc_msgs == 0 || continue_download) {
3239 /* modest_platform_information_banner (
3240 NULL, NULL, _CS("mcen_ib_getting_items"));*/
3241 modest_header_view_cut_selection (
3242 MODEST_HEADER_VIEW (focused_widget));
3245 g_object_unref (header_list);
3246 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
3247 modest_folder_view_cut_selection (MODEST_FOLDER_VIEW (focused_widget));
3252 modest_ui_actions_on_copy (GtkAction *action,
3253 ModestWindow *window)
3255 GtkClipboard *clipboard;
3256 GtkWidget *focused_widget;
3257 gboolean copied = TRUE;
3259 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
3260 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
3262 if (GTK_IS_LABEL (focused_widget)) {
3263 gtk_clipboard_set_text (clipboard, gtk_label_get_text (GTK_LABEL (focused_widget)), -1);
3264 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3265 gtk_clipboard_store (clipboard);
3266 } else if (GTK_IS_EDITABLE (focused_widget)) {
3267 gtk_editable_copy_clipboard (GTK_EDITABLE(focused_widget));
3268 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3269 gtk_clipboard_store (clipboard);
3270 } else if (GTK_IS_HTML (focused_widget)) {
3271 gtk_html_copy (GTK_HTML (focused_widget));
3272 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3273 gtk_clipboard_store (clipboard);
3274 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
3275 GtkTextBuffer *buffer;
3276 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
3277 gtk_text_buffer_copy_clipboard (buffer, clipboard);
3278 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3279 gtk_clipboard_store (clipboard);
3280 } else if (MODEST_IS_HEADER_VIEW (focused_widget)) {
3281 TnyList *header_list = modest_header_view_get_selected_headers (
3282 MODEST_HEADER_VIEW (focused_widget));
3283 gboolean continue_download = FALSE;
3284 gint num_of_unc_msgs;
3286 num_of_unc_msgs = header_list_count_uncached_msgs(header_list);
3288 if (num_of_unc_msgs) {
3289 TnyAccount *account = get_account_from_header_list (header_list);
3290 continue_download = connect_to_get_msg (window, num_of_unc_msgs, account);
3291 g_object_unref (account);
3294 if (num_of_unc_msgs == 0 || continue_download) {
3295 modest_platform_information_banner (
3296 NULL, NULL, _CS("mcen_ib_getting_items"));
3297 modest_header_view_copy_selection (
3298 MODEST_HEADER_VIEW (focused_widget));
3302 g_object_unref (header_list);
3304 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
3305 modest_folder_view_copy_selection (MODEST_FOLDER_VIEW (focused_widget));
3308 /* Show information banner if there was a copy to clipboard */
3310 modest_platform_information_banner (
3311 NULL, NULL, _CS("ecoc_ib_edwin_copied"));
3315 modest_ui_actions_on_undo (GtkAction *action,
3316 ModestWindow *window)
3318 ModestEmailClipboard *clipboard = NULL;
3320 if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
3321 modest_msg_edit_window_undo (MODEST_MSG_EDIT_WINDOW (window));
3322 } else if (MODEST_IS_MAIN_WINDOW (window)) {
3323 /* Clear clipboard source */
3324 clipboard = modest_runtime_get_email_clipboard ();
3325 modest_email_clipboard_clear (clipboard);
3328 g_return_if_reached ();
3333 modest_ui_actions_on_redo (GtkAction *action,
3334 ModestWindow *window)
3336 if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
3337 modest_msg_edit_window_redo (MODEST_MSG_EDIT_WINDOW (window));
3340 g_return_if_reached ();
3346 destroy_information_note (ModestMailOperation *mail_op,
3349 /* destroy information note */
3350 gtk_widget_destroy (GTK_WIDGET(user_data));
3354 destroy_folder_information_note (ModestMailOperation *mail_op,
3355 TnyFolder *new_folder,
3358 /* destroy information note */
3359 gtk_widget_destroy (GTK_WIDGET(user_data));
3364 paste_as_attachment_free (gpointer data)
3366 PasteAsAttachmentHelper *helper = (PasteAsAttachmentHelper *) data;
3368 gtk_widget_destroy (helper->banner);
3369 g_object_unref (helper->banner);
3374 paste_msg_as_attachment_cb (ModestMailOperation *mail_op,
3379 PasteAsAttachmentHelper *helper = (PasteAsAttachmentHelper *) userdata;
3380 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (helper->window));
3385 modest_msg_edit_window_add_part (MODEST_MSG_EDIT_WINDOW (helper->window), TNY_MIME_PART (msg));
3390 modest_ui_actions_on_paste (GtkAction *action,
3391 ModestWindow *window)
3393 GtkWidget *focused_widget = NULL;
3394 GtkWidget *inf_note = NULL;
3395 ModestMailOperation *mail_op = NULL;
3397 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
3398 if (GTK_IS_EDITABLE (focused_widget)) {
3399 gtk_editable_paste_clipboard (GTK_EDITABLE(focused_widget));
3400 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
3401 ModestEmailClipboard *e_clipboard = NULL;
3402 e_clipboard = modest_runtime_get_email_clipboard ();
3403 if (modest_email_clipboard_cleared (e_clipboard)) {
3404 GtkTextBuffer *buffer;
3405 GtkClipboard *clipboard;
3407 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
3408 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
3409 gtk_text_buffer_paste_clipboard (buffer, clipboard, NULL, TRUE);
3410 } else if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
3411 ModestMailOperation *mail_op;
3412 TnyFolder *src_folder;
3415 PasteAsAttachmentHelper *helper = g_new0 (PasteAsAttachmentHelper, 1);
3416 helper->window = MODEST_MSG_EDIT_WINDOW (window);
3417 helper->banner = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
3418 _CS("ckct_nw_pasting"));
3419 modest_email_clipboard_get_data (e_clipboard, &src_folder, &data, &delete);
3420 mail_op = modest_mail_operation_new (G_OBJECT (window));
3421 if (helper->banner != NULL) {
3422 g_object_ref (G_OBJECT (helper->banner));
3423 gtk_window_set_modal (GTK_WINDOW (helper->banner), FALSE);
3424 gtk_widget_show (GTK_WIDGET (helper->banner));
3428 modest_mail_operation_get_msgs_full (mail_op,
3430 (GetMsgAsyncUserCallback) paste_msg_as_attachment_cb,
3432 paste_as_attachment_free);
3435 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
3436 ModestEmailClipboard *clipboard = NULL;
3437 TnyFolder *src_folder = NULL;
3438 TnyFolderStore *folder_store = NULL;
3439 TnyList *data = NULL;
3440 gboolean delete = FALSE;
3442 /* Check clipboard source */
3443 clipboard = modest_runtime_get_email_clipboard ();
3444 if (modest_email_clipboard_cleared (clipboard))
3447 /* Get elements to paste */
3448 modest_email_clipboard_get_data (clipboard, &src_folder, &data, &delete);
3450 /* Create a new mail operation */
3451 mail_op = modest_mail_operation_new (G_OBJECT(window));
3453 /* Get destination folder */
3454 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (focused_widget));
3456 /* transfer messages */
3460 /* Ask for user confirmation */
3462 modest_ui_actions_msgs_move_to_confirmation (window,
3463 TNY_FOLDER (folder_store),
3467 if (response == GTK_RESPONSE_OK) {
3468 /* Launch notification */
3469 inf_note = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
3470 _CS("ckct_nw_pasting"));
3471 if (inf_note != NULL) {
3472 gtk_window_set_modal (GTK_WINDOW(inf_note), FALSE);
3473 gtk_widget_show (GTK_WIDGET(inf_note));
3476 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
3477 modest_mail_operation_xfer_msgs (mail_op,
3479 TNY_FOLDER (folder_store),
3481 destroy_information_note,
3484 g_object_unref (mail_op);
3487 } else if (src_folder != NULL) {
3488 /* Launch notification */
3489 inf_note = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
3490 _CS("ckct_nw_pasting"));
3491 if (inf_note != NULL) {
3492 gtk_window_set_modal (GTK_WINDOW(inf_note), FALSE);
3493 gtk_widget_show (GTK_WIDGET(inf_note));
3496 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
3497 modest_mail_operation_xfer_folder (mail_op,
3501 destroy_folder_information_note,
3507 g_object_unref (data);
3508 if (src_folder != NULL)
3509 g_object_unref (src_folder);
3510 if (folder_store != NULL)
3511 g_object_unref (folder_store);
3517 modest_ui_actions_on_select_all (GtkAction *action,
3518 ModestWindow *window)
3520 GtkWidget *focused_widget;
3522 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
3523 if (MODEST_IS_ATTACHMENTS_VIEW (focused_widget)) {
3524 modest_attachments_view_select_all (MODEST_ATTACHMENTS_VIEW (focused_widget));
3525 } else if (GTK_IS_LABEL (focused_widget)) {
3526 gtk_label_select_region (GTK_LABEL (focused_widget), 0, -1);
3527 } else if (GTK_IS_EDITABLE (focused_widget)) {
3528 gtk_editable_select_region (GTK_EDITABLE(focused_widget), 0, -1);
3529 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
3530 GtkTextBuffer *buffer;
3531 GtkTextIter start, end;
3533 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
3534 gtk_text_buffer_get_start_iter (buffer, &start);
3535 gtk_text_buffer_get_end_iter (buffer, &end);
3536 gtk_text_buffer_select_range (buffer, &start, &end);
3537 } else if (GTK_IS_HTML (focused_widget)) {
3538 gtk_html_select_all (GTK_HTML (focused_widget));
3539 } else if (MODEST_IS_MAIN_WINDOW (window)) {
3540 GtkWidget *header_view = focused_widget;
3541 GtkTreeSelection *selection = NULL;
3543 if (!(MODEST_IS_HEADER_VIEW (focused_widget))) {
3544 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (window),
3545 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
3548 /* Disable window dimming management */
3549 modest_window_disable_dimming (MODEST_WINDOW(window));
3551 /* Select all messages */
3552 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(header_view));
3553 gtk_tree_selection_select_all (selection);
3555 /* Set focuse on header view */
3556 gtk_widget_grab_focus (header_view);
3559 /* Enable window dimming management */
3560 modest_window_enable_dimming (MODEST_WINDOW(window));
3561 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (window));
3567 modest_ui_actions_on_mark_as_read (GtkAction *action,
3568 ModestWindow *window)
3570 g_return_if_fail (MODEST_IS_WINDOW(window));
3572 /* Mark each header as read */
3573 do_headers_action (window, headers_action_mark_as_read, NULL);
3577 modest_ui_actions_on_mark_as_unread (GtkAction *action,
3578 ModestWindow *window)
3580 g_return_if_fail (MODEST_IS_WINDOW(window));
3582 /* Mark each header as read */
3583 do_headers_action (window, headers_action_mark_as_unread, NULL);
3587 modest_ui_actions_on_change_zoom (GtkRadioAction *action,
3588 GtkRadioAction *selected,
3589 ModestWindow *window)
3593 value = gtk_radio_action_get_current_value (selected);
3594 if (MODEST_IS_WINDOW (window)) {
3595 modest_window_set_zoom (MODEST_WINDOW (window), ((gdouble)value)/100);
3600 modest_ui_actions_msg_edit_on_change_priority (GtkRadioAction *action,
3601 GtkRadioAction *selected,
3602 ModestWindow *window)
3604 TnyHeaderFlags flags;
3605 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3607 flags = gtk_radio_action_get_current_value (selected);
3608 modest_msg_edit_window_set_priority_flags (MODEST_MSG_EDIT_WINDOW (window), flags);
3612 modest_ui_actions_msg_edit_on_change_file_format (GtkRadioAction *action,
3613 GtkRadioAction *selected,
3614 ModestWindow *window)
3618 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3620 file_format = gtk_radio_action_get_current_value (selected);
3621 modest_msg_edit_window_set_file_format (MODEST_MSG_EDIT_WINDOW (window), file_format);
3626 modest_ui_actions_on_zoom_plus (GtkAction *action,
3627 ModestWindow *window)
3629 g_return_if_fail (MODEST_IS_WINDOW (window));
3631 modest_window_zoom_plus (MODEST_WINDOW (window));
3635 modest_ui_actions_on_zoom_minus (GtkAction *action,
3636 ModestWindow *window)
3638 g_return_if_fail (MODEST_IS_WINDOW (window));
3640 modest_window_zoom_minus (MODEST_WINDOW (window));
3644 modest_ui_actions_on_toggle_fullscreen (GtkToggleAction *toggle,
3645 ModestWindow *window)
3647 ModestWindowMgr *mgr;
3648 gboolean fullscreen, active;
3649 g_return_if_fail (MODEST_IS_WINDOW (window));
3651 mgr = modest_runtime_get_window_mgr ();
3653 active = (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle)))?1:0;
3654 fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
3656 if (active != fullscreen) {
3657 modest_window_mgr_set_fullscreen_mode (mgr, active);
3658 gtk_window_present (GTK_WINDOW (window));
3663 modest_ui_actions_on_change_fullscreen (GtkAction *action,
3664 ModestWindow *window)
3666 ModestWindowMgr *mgr;
3667 gboolean fullscreen;
3669 g_return_if_fail (MODEST_IS_WINDOW (window));
3671 mgr = modest_runtime_get_window_mgr ();
3672 fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
3673 modest_window_mgr_set_fullscreen_mode (mgr, !fullscreen);
3675 gtk_window_present (GTK_WINDOW (window));
3679 * Used by modest_ui_actions_on_details to call do_headers_action
3682 headers_action_show_details (TnyHeader *header,
3683 ModestWindow *window,
3690 dialog = modest_details_dialog_new_with_header (GTK_WINDOW (window), header);
3693 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
3694 gtk_widget_show_all (dialog);
3695 gtk_dialog_run (GTK_DIALOG (dialog));
3697 gtk_widget_destroy (dialog);
3701 * Show the folder details in a ModestDetailsDialog widget
3704 show_folder_details (TnyFolder *folder,
3710 dialog = modest_details_dialog_new_with_folder (window, folder);
3713 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
3714 gtk_widget_show_all (dialog);
3715 gtk_dialog_run (GTK_DIALOG (dialog));
3717 gtk_widget_destroy (dialog);
3721 * Show the header details in a ModestDetailsDialog widget
3724 modest_ui_actions_on_details (GtkAction *action,
3727 TnyList * headers_list;
3731 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
3734 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW (win));
3737 g_object_unref (msg);
3739 headers_list = get_selected_headers (win);
3743 iter = tny_list_create_iterator (headers_list);
3745 header = TNY_HEADER (tny_iterator_get_current (iter));
3747 headers_action_show_details (header, win, NULL);
3748 g_object_unref (header);
3751 g_object_unref (iter);
3752 g_object_unref (headers_list);
3754 } else if (MODEST_IS_MAIN_WINDOW (win)) {
3755 GtkWidget *folder_view, *header_view;
3757 /* Check which widget has the focus */
3758 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
3759 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3760 if (gtk_widget_is_focus (folder_view)) {
3761 TnyFolderStore *folder_store
3762 = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
3763 if (!folder_store) {
3764 g_warning ("%s: No item was selected.\n", __FUNCTION__);
3767 /* Show only when it's a folder */
3768 /* This function should not be called for account items,
3769 * because we dim the menu item for them. */
3770 if (TNY_IS_FOLDER (folder_store)) {
3771 show_folder_details (TNY_FOLDER (folder_store), GTK_WINDOW (win));
3774 g_object_unref (folder_store);
3777 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
3778 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
3779 /* Show details of each header */
3780 do_headers_action (win, headers_action_show_details, header_view);
3786 modest_ui_actions_on_toggle_show_cc (GtkToggleAction *toggle,
3787 ModestMsgEditWindow *window)
3789 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3791 modest_msg_edit_window_show_cc (window, gtk_toggle_action_get_active (toggle));
3795 modest_ui_actions_on_toggle_show_bcc (GtkToggleAction *toggle,
3796 ModestMsgEditWindow *window)
3798 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3800 modest_msg_edit_window_show_bcc (window, gtk_toggle_action_get_active (toggle));
3804 modest_ui_actions_toggle_folders_view (GtkAction *action,
3805 ModestMainWindow *main_window)
3807 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
3809 if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)))
3810 modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SPLIT);
3812 modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SIMPLE);
3816 modest_ui_actions_on_toggle_toolbar (GtkToggleAction *toggle,
3817 ModestWindow *window)
3819 gboolean active, fullscreen = FALSE;
3820 ModestWindowMgr *mgr;
3822 active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle));
3824 /* Check if we want to toggle the toolbar vuew in fullscreen
3826 if (!strcmp (gtk_action_get_name (GTK_ACTION (toggle)),
3827 "ViewShowToolbarFullScreen")) {
3831 /* Toggle toolbar */
3832 mgr = modest_runtime_get_window_mgr ();
3833 modest_window_mgr_show_toolbars (mgr, G_TYPE_FROM_INSTANCE (window), active, fullscreen);
3837 modest_ui_actions_msg_edit_on_select_font (GtkAction *action,
3838 ModestMsgEditWindow *window)
3840 modest_msg_edit_window_select_font (window);
3845 modest_ui_actions_on_folder_display_name_changed (ModestFolderView *folder_view,
3846 const gchar *display_name,
3849 /* don't update the display name if it was already set;
3850 * updating the display name apparently is expensive */
3851 const gchar* old_name = gtk_window_get_title (window);
3853 if (display_name == NULL)
3856 if (old_name && display_name && strcmp (old_name, display_name) == 0)
3857 return; /* don't do anything */
3859 /* This is usually used to change the title of the main window, which
3860 * is the one that holds the folder view. Note that this change can
3861 * happen even when the widget doesn't have the focus. */
3862 gtk_window_set_title (window, display_name);
3867 modest_ui_actions_on_select_contacts (GtkAction *action, ModestMsgEditWindow *window)
3869 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3870 modest_msg_edit_window_select_contacts (window);
3874 modest_ui_actions_on_check_names (GtkAction *action, ModestMsgEditWindow *window)
3876 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3877 modest_msg_edit_window_check_names (window, FALSE);
3881 create_move_to_dialog_on_new_folder(GtkWidget *button, gpointer user_data)
3883 modest_ui_actions_create_folder (gtk_widget_get_toplevel (button),
3884 GTK_WIDGET (user_data));
3888 * This function is used to track changes in the selection of the
3889 * folder view that is inside the "move to" dialog to enable/disable
3890 * the OK button because we do not want the user to select a disallowed
3891 * destination for a folder.
3892 * The user also not desired to be able to use NEW button on items where
3893 * folder creation is not possibel.
3896 on_move_to_dialog_folder_selection_changed (ModestFolderView* self,
3897 TnyFolderStore *folder_store,
3901 GtkWidget *dialog = NULL;
3902 GtkWidget *ok_button = NULL, *new_button = NULL;
3903 GList *children = NULL;
3904 gboolean ok_sensitive = TRUE, new_sensitive = TRUE;
3905 gboolean moving_folder = FALSE;
3906 gboolean is_local_account = TRUE;
3907 GtkWidget *folder_view = NULL;
3908 ModestTnyFolderRules rules;
3913 /* Get the OK button */
3914 dialog = gtk_widget_get_ancestor (GTK_WIDGET (self), GTK_TYPE_DIALOG);
3918 children = gtk_container_get_children (GTK_CONTAINER (GTK_DIALOG (dialog)->action_area));
3919 ok_button = GTK_WIDGET (children->next->next->data);
3920 new_button = GTK_WIDGET (children->next->data);
3921 g_list_free (children);
3923 /* check if folder_store is an remote account */
3924 if (TNY_IS_ACCOUNT (folder_store)) {
3925 TnyAccount *local_account = NULL;
3926 TnyAccount *mmc_account = NULL;
3927 ModestTnyAccountStore *account_store = NULL;
3929 account_store = modest_runtime_get_account_store ();
3930 local_account = modest_tny_account_store_get_local_folders_account (account_store);
3931 mmc_account = modest_tny_account_store_get_mmc_folders_account (account_store);
3933 if ((gpointer) local_account != (gpointer) folder_store &&
3934 (gpointer) mmc_account != (gpointer) folder_store) {
3935 is_local_account = FALSE;
3936 /* New button should be dimmed on remote
3938 new_sensitive = FALSE;
3940 g_object_unref (local_account);
3943 /* Check the target folder rules */
3944 if (TNY_IS_FOLDER (folder_store)) {
3945 rules = modest_tny_folder_get_rules (TNY_FOLDER (folder_store));
3946 if (rules & MODEST_FOLDER_RULES_FOLDER_NON_WRITEABLE) {
3947 ok_sensitive = FALSE;
3948 new_sensitive = FALSE;
3953 /* Check if we're moving a folder */
3954 if (MODEST_IS_MAIN_WINDOW (user_data)) {
3955 /* Get the widgets */
3956 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (user_data),
3957 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3958 if (gtk_widget_is_focus (folder_view))
3959 moving_folder = TRUE;
3962 if (moving_folder) {
3963 TnyFolderStore *moved_folder = NULL, *parent = NULL;
3965 /* Get the folder to move */
3966 moved_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
3968 /* Check that we're not moving to the same folder */
3969 if (TNY_IS_FOLDER (moved_folder)) {
3970 parent = tny_folder_get_folder_store (TNY_FOLDER (moved_folder));
3971 if (parent == folder_store)
3972 ok_sensitive = FALSE;
3973 g_object_unref (parent);
3976 if (ok_sensitive && TNY_IS_ACCOUNT (folder_store)) {
3977 /* Do not allow to move to an account unless it's the
3978 local folders account */
3979 if (!is_local_account)
3980 ok_sensitive = FALSE;
3983 if (ok_sensitive && (moved_folder == folder_store)) {
3984 /* Do not allow to move to itself */
3985 ok_sensitive = FALSE;
3987 g_object_unref (moved_folder);
3989 TnyHeader *header = NULL;
3990 TnyFolder *src_folder = NULL;
3992 /* Moving a message */
3993 if (MODEST_IS_MSG_VIEW_WINDOW (user_data)) {
3994 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (user_data));
3995 src_folder = tny_header_get_folder (header);
3996 g_object_unref (header);
3999 TNY_FOLDER (modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view)));
4002 /* Do not allow to move the msg to the same folder */
4003 /* Do not allow to move the msg to an account */
4004 if ((gpointer) src_folder == (gpointer) folder_store ||
4005 TNY_IS_ACCOUNT (folder_store))
4006 ok_sensitive = FALSE;
4007 g_object_unref (src_folder);
4011 /* Set sensitivity of the OK button */
4012 gtk_widget_set_sensitive (ok_button, ok_sensitive);
4013 /* Set sensitivity of the NEW button */
4014 gtk_widget_set_sensitive (new_button, new_sensitive);
4018 #define MODEST_MOVE_TO_DIALOG_FOLDER_VIEW "move-to-dialog-folder-view"
4021 get_folder_view_from_move_to_dialog (GtkWidget *move_to_dialog)
4023 return GTK_WIDGET(g_object_get_data (G_OBJECT(move_to_dialog),
4024 MODEST_MOVE_TO_DIALOG_FOLDER_VIEW));
4028 create_move_to_dialog (GtkWindow *win,
4029 GtkWidget *folder_view,
4030 GtkWidget **tree_view)
4032 GtkWidget *dialog, *scroll;
4033 GtkWidget *new_button;
4035 dialog = gtk_dialog_new_with_buttons (_("mcen_ti_moveto_folders_title"),
4037 GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR | GTK_DIALOG_DESTROY_WITH_PARENT,
4040 gtk_dialog_add_button (GTK_DIALOG (dialog), _("mcen_bd_dialog_ok"), GTK_RESPONSE_ACCEPT);
4041 /* We do this manually so GTK+ does not associate a response ID for
4043 new_button = gtk_button_new_from_stock (_("mcen_bd_new"));
4044 gtk_box_pack_end (GTK_BOX (GTK_DIALOG (dialog)->action_area), new_button, FALSE, FALSE, 0);
4045 gtk_dialog_add_button (GTK_DIALOG (dialog), _("mcen_bd_dialog_cancel"), GTK_RESPONSE_REJECT);
4047 /* Create scrolled window */
4048 scroll = gtk_scrolled_window_new (NULL, NULL);
4049 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll),
4050 GTK_POLICY_AUTOMATIC,
4051 GTK_POLICY_AUTOMATIC);
4053 /* Create folder view */
4054 *tree_view = modest_platform_create_folder_view (NULL);
4056 /* Track changes in the selection to
4057 * disable the OK button whenever "Move to" is not possible
4058 * disbale NEW button whenever New is not possible */
4059 g_signal_connect (*tree_view,
4060 "folder_selection_changed",
4061 G_CALLBACK (on_move_to_dialog_folder_selection_changed),
4064 /* Listen to clicks on New button */
4065 g_signal_connect (G_OBJECT (new_button),
4067 G_CALLBACK(create_move_to_dialog_on_new_folder),
4070 /* It could happen that we're trying to move a message from a
4071 window (msg window for example) after the main window was
4072 closed, so we can not just get the model of the folder
4074 if (MODEST_IS_FOLDER_VIEW (folder_view)) {
4075 const gchar *visible_id = NULL;
4077 modest_folder_view_set_style (MODEST_FOLDER_VIEW (*tree_view),
4078 MODEST_FOLDER_VIEW_STYLE_SHOW_ALL);
4079 modest_folder_view_copy_model (MODEST_FOLDER_VIEW(folder_view),
4080 MODEST_FOLDER_VIEW(*tree_view));
4083 modest_folder_view_get_account_id_of_visible_server_account (MODEST_FOLDER_VIEW(folder_view));
4085 /* Show the same account than the one that is shown in the main window */
4086 modest_folder_view_set_account_id_of_visible_server_account (MODEST_FOLDER_VIEW(*tree_view),
4089 const gchar *active_account_name = NULL;
4090 ModestAccountMgr *mgr = NULL;
4091 ModestAccountSettings *settings = NULL;
4092 ModestServerAccountSettings *store_settings = NULL;
4094 modest_folder_view_set_style (MODEST_FOLDER_VIEW (*tree_view),
4095 MODEST_FOLDER_VIEW_STYLE_SHOW_ALL);
4096 modest_folder_view_update_model (MODEST_FOLDER_VIEW (*tree_view),
4097 TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()));
4099 active_account_name = modest_window_get_active_account (MODEST_WINDOW (win));
4100 mgr = modest_runtime_get_account_mgr ();
4101 settings = modest_account_mgr_load_account_settings (mgr, active_account_name);
4104 const gchar *store_account_name;
4105 store_settings = modest_account_settings_get_store_settings (settings);
4106 store_account_name = modest_server_account_settings_get_account_name (store_settings);
4108 modest_folder_view_set_account_id_of_visible_server_account (MODEST_FOLDER_VIEW (*tree_view),
4109 store_account_name);
4110 g_object_unref (store_settings);
4111 g_object_unref (settings);
4115 /* we keep a pointer to the embedded folder view, so we can retrieve it with
4116 * get_folder_view_from_move_to_dialog
4117 * (see above) later (needed for focus handling)
4119 g_object_set_data (G_OBJECT(dialog), MODEST_MOVE_TO_DIALOG_FOLDER_VIEW, *tree_view);
4122 /* Hide special folders */
4123 modest_folder_view_show_non_move_folders (MODEST_FOLDER_VIEW (*tree_view), FALSE);
4125 gtk_container_add (GTK_CONTAINER (scroll), *tree_view);
4127 /* Add scroll to dialog */
4128 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
4129 scroll, TRUE, TRUE, 0);
4131 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
4132 gtk_window_set_default_size (GTK_WINDOW (dialog), 300, 300);
4138 * Returns TRUE if at least one of the headers of the list belongs to
4139 * a message that has been fully retrieved.
4141 #if 0 /* no longer in use. delete in 2007.10 */
4143 has_retrieved_msgs (TnyList *list)
4146 gboolean found = FALSE;
4148 iter = tny_list_create_iterator (list);
4149 while (!tny_iterator_is_done (iter) && !found) {
4151 TnyHeaderFlags flags = 0;
4153 header = TNY_HEADER (tny_iterator_get_current (iter));
4155 flags = tny_header_get_flags (header);
4156 if (flags & TNY_HEADER_FLAG_CACHED)
4157 /* if (!(flags & TNY_HEADER_FLAG_PARTIAL)) */
4160 g_object_unref (header);
4164 tny_iterator_next (iter);
4166 g_object_unref (iter);
4174 * Shows a confirmation dialog to the user when we're moving messages
4175 * from a remote server to the local storage. Returns the dialog
4176 * response. If it's other kind of movement then it always returns
4179 * This one is used by the next functions:
4180 * modest_ui_actions_on_paste - commented out
4181 * drag_and_drop_from_header_view (for d&d in modest_folder_view.c)
4184 modest_ui_actions_msgs_move_to_confirmation (ModestWindow *win,
4185 TnyFolder *dest_folder,
4189 gint response = GTK_RESPONSE_OK;
4190 TnyAccount *account = NULL;
4191 TnyFolder *src_folder = NULL;
4192 TnyIterator *iter = NULL;
4193 TnyHeader *header = NULL;
4195 /* return with OK if the destination is a remote folder */
4196 if (modest_tny_folder_is_remote_folder (dest_folder))
4197 return GTK_RESPONSE_OK;
4199 /* Get source folder */
4200 iter = tny_list_create_iterator (headers);
4201 header = TNY_HEADER (tny_iterator_get_current (iter));
4203 src_folder = tny_header_get_folder (header);
4204 g_object_unref (header);
4206 g_object_unref (iter);
4208 /* if no src_folder, message may be an attahcment */
4209 if (src_folder == NULL)
4210 return GTK_RESPONSE_CANCEL;
4212 /* If the source is a local or MMC folder */
4213 if (!modest_tny_folder_is_remote_folder (src_folder)) {
4214 g_object_unref (src_folder);
4215 return GTK_RESPONSE_OK;
4218 /* Get the account */
4219 account = tny_folder_get_account (src_folder);
4221 /* now if offline we ask the user */
4222 if(connect_to_get_msg (win, tny_list_get_length (headers), account))
4223 response = GTK_RESPONSE_OK;
4225 response = GTK_RESPONSE_CANCEL;
4228 g_object_unref (src_folder);
4229 g_object_unref (account);
4235 move_to_cb (ModestMailOperation *mail_op,
4238 MoveToHelper *helper = (MoveToHelper *) user_data;
4240 /* Note that the operation could have failed, in that case do
4242 if (modest_mail_operation_get_status (mail_op) ==
4243 MODEST_MAIL_OPERATION_STATUS_SUCCESS) {
4245 GObject *object = modest_mail_operation_get_source (mail_op);
4246 if (MODEST_IS_MSG_VIEW_WINDOW (object)) {
4247 ModestMsgViewWindow *self = MODEST_MSG_VIEW_WINDOW (object);
4249 if (!modest_msg_view_window_select_next_message (self))
4250 if (!modest_msg_view_window_select_previous_message (self))
4251 /* No more messages to view, so close this window */
4252 modest_ui_actions_on_close_window (NULL, MODEST_WINDOW(self));
4253 } else if (MODEST_IS_MAIN_WINDOW (object) && helper->reference != NULL) {
4254 GtkWidget *header_view;
4256 GtkTreeSelection *sel;
4258 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(object),
4259 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
4260 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
4261 path = gtk_tree_row_reference_get_path (helper->reference);
4262 gtk_tree_selection_select_path (sel, path);
4263 gtk_tree_path_free (path);
4265 g_object_unref (object);
4268 /* Close the "Pasting" information banner */
4269 gtk_widget_destroy (GTK_WIDGET(helper->banner));
4270 if (helper->reference != NULL)
4271 gtk_tree_row_reference_free (helper->reference);
4276 folder_move_to_cb (ModestMailOperation *mail_op,
4277 TnyFolder *new_folder,
4280 move_to_cb (mail_op, user_data);
4284 msgs_move_to_cb (ModestMailOperation *mail_op,
4287 move_to_cb (mail_op, user_data);
4291 modest_ui_actions_move_folder_error_handler (ModestMailOperation *mail_op,
4294 ModestWindow *main_window = NULL;
4295 GObject *win = NULL;
4297 /* Disable next automatic folder selection */
4298 main_window = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (),
4299 FALSE); /* don't create */
4301 GtkWidget *folder_view = NULL;
4303 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (main_window),
4304 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
4305 modest_folder_view_disable_next_folder_selection (MODEST_FOLDER_VIEW(folder_view));
4307 if (user_data && TNY_IS_FOLDER (user_data)) {
4308 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view),
4309 TNY_FOLDER (user_data), FALSE);
4313 /* Show notification dialog */
4314 win = modest_mail_operation_get_source (mail_op);
4315 modest_platform_run_information_dialog ((GtkWindow *) win, _("mail_in_ui_folder_move_target_error"));
4317 g_object_unref (win);
4321 modest_ui_actions_send_receive_error_handler (ModestMailOperation *mail_op,
4324 GObject *win = modest_mail_operation_get_source (mail_op);
4325 const GError *error = modest_mail_operation_get_error (mail_op);
4327 g_return_if_fail (error != NULL);
4328 if (error->message != NULL)
4329 g_printerr ("modest: %s\n", error->message);
4331 g_printerr ("modest: unkonw error on send&receive operation");
4333 /* Show error message */
4334 /* if (modest_mail_operation_get_id (mail_op) == MODEST_MAIL_OPERATION_TYPE_RECEIVE) */
4335 /* modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL, */
4336 /* _CS("sfil_ib_unable_to_receive")); */
4338 /* modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL, */
4339 /* _CS("sfil_ib_unable_to_send")); */
4340 g_object_unref (win);
4344 open_msg_for_purge_cb (ModestMailOperation *mail_op,
4353 gint pending_purges = 0;
4354 gboolean some_purged = FALSE;
4355 ModestWindow *win = MODEST_WINDOW (user_data);
4356 ModestWindowMgr *mgr = modest_runtime_get_window_mgr ();
4358 /* If there was any error */
4359 if (!modest_ui_actions_msg_retrieval_check (mail_op, header, msg)) {
4360 modest_window_mgr_unregister_header (mgr, header);
4364 /* Once the message has been retrieved for purging, we check if
4365 * it's all ok for purging */
4367 parts = tny_simple_list_new ();
4368 tny_mime_part_get_parts (TNY_MIME_PART (msg), parts);
4369 iter = tny_list_create_iterator (parts);
4371 while (!tny_iterator_is_done (iter)) {
4373 part = TNY_MIME_PART (tny_iterator_get_current (iter));
4374 if (part && (tny_mime_part_is_attachment (part) || TNY_IS_MSG (part))) {
4375 if (tny_mime_part_is_purged (part))
4382 g_object_unref (part);
4384 tny_iterator_next (iter);
4386 g_object_unref (iter);
4389 if (pending_purges>0) {
4391 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),_("mcen_nc_purge_file_text_inbox"));
4393 if (response == GTK_RESPONSE_OK) {
4394 modest_platform_information_banner (NULL, NULL, _("mcen_ib_removing_attachment"));
4395 iter = tny_list_create_iterator (parts);
4396 while (!tny_iterator_is_done (iter)) {
4399 part = TNY_MIME_PART (tny_iterator_get_current (iter));
4400 if (part && (tny_mime_part_is_attachment (part) || TNY_IS_MSG (part)))
4401 tny_mime_part_set_purged (part);
4404 g_object_unref (part);
4406 tny_iterator_next (iter);
4409 tny_msg_rewrite_cache (msg);
4412 /* This string no longer exists, refer to NB#75415 for more info */
4413 /* modest_platform_information_banner (NULL, NULL, _("mail_ib_attachment_already_purged")); */
4415 g_object_unref (iter);
4417 modest_window_mgr_unregister_header (mgr, header);
4419 g_object_unref (parts);
4423 modest_ui_actions_on_main_window_remove_attachments (GtkAction *action,
4424 ModestMainWindow *win)
4426 GtkWidget *header_view;
4427 TnyList *header_list;
4430 TnyHeaderFlags flags;
4431 ModestWindow *msg_view_window = NULL;
4434 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win));
4436 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
4437 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
4439 header_list = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW (header_view));
4441 g_warning ("%s: no header selected", __FUNCTION__);
4445 if (tny_list_get_length (header_list) == 1) {
4446 iter = tny_list_create_iterator (header_list);
4447 header = TNY_HEADER (tny_iterator_get_current (iter));
4448 g_object_unref (iter);
4452 if (!header || !TNY_IS_HEADER(header)) {
4453 g_warning ("%s: header is not valid", __FUNCTION__);
4457 found = modest_window_mgr_find_registered_header (modest_runtime_get_window_mgr (),
4458 header, &msg_view_window);
4459 flags = tny_header_get_flags (header);
4460 if (!(flags & TNY_HEADER_FLAG_CACHED))
4463 if (msg_view_window != NULL)
4464 modest_msg_view_window_remove_attachments (MODEST_MSG_VIEW_WINDOW (msg_view_window), TRUE);
4466 /* do nothing; uid was registered before, so window is probably on it's way */
4467 g_warning ("debug: header %p has already been registered", header);
4470 ModestMailOperation *mail_op = NULL;
4471 modest_window_mgr_register_header (modest_runtime_get_window_mgr (), header, NULL);
4472 mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT (win),
4473 modest_ui_actions_get_msgs_full_error_handler,
4475 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
4476 modest_mail_operation_get_msg (mail_op, header, open_msg_for_purge_cb, win);
4478 g_object_unref (mail_op);
4481 g_object_unref (header);
4483 g_object_unref (header_list);
4487 * Utility function that transfer messages from both the main window
4488 * and the msg view window when using the "Move to" dialog
4491 xfer_messages_from_move_to_cb (gboolean canceled, GError *err,
4492 GtkWindow *parent_window,
4493 TnyAccount *account, gpointer user_data)
4495 TnyFolderStore *dst_folder = TNY_FOLDER_STORE (user_data);
4496 ModestWindow *win = MODEST_WINDOW (parent_window);
4497 TnyList *headers = NULL;
4498 TnyAccount *dst_account = NULL;
4499 const gchar *proto_str = NULL;
4500 gboolean dst_is_pop = FALSE;
4502 if (canceled || err) {
4503 g_object_unref (dst_folder);
4507 if (!TNY_IS_FOLDER (dst_folder)) {
4508 modest_platform_information_banner (GTK_WIDGET (win),
4510 _CS("ckdg_ib_unable_to_move_to_current_location"));
4514 dst_account = tny_folder_get_account (TNY_FOLDER (dst_folder));
4515 proto_str = tny_account_get_proto (dst_account);
4517 /* tinymail will return NULL for local folders it seems */
4518 dst_is_pop = proto_str &&
4519 (modest_protocol_info_get_transport_store_protocol (proto_str) ==
4520 MODEST_PROTOCOL_STORE_POP);
4522 g_object_unref (dst_account);
4524 /* Get selected headers */
4525 headers = get_selected_headers (MODEST_WINDOW (win));
4527 g_warning ("%s: no headers selected", __FUNCTION__);
4533 modest_platform_information_banner (GTK_WIDGET (win),
4535 ngettext("mail_in_ui_folder_move_target_error",
4536 "mail_in_ui_folder_move_targets_error",
4537 tny_list_get_length (headers)));
4538 g_object_unref (headers);
4542 MoveToHelper *helper = g_new0 (MoveToHelper, 1);
4543 helper->banner = modest_platform_animation_banner (GTK_WIDGET (win), NULL,
4544 _CS("ckct_nw_pasting"));
4545 if (helper->banner != NULL) {
4546 gtk_window_set_modal (GTK_WINDOW(helper->banner), FALSE);
4547 gtk_widget_show (GTK_WIDGET(helper->banner));
4550 if (MODEST_IS_MAIN_WINDOW (win)) {
4551 GtkWidget *header_view =
4552 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
4553 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
4554 helper->reference = get_next_after_selected_headers (MODEST_HEADER_VIEW (header_view));
4557 ModestMailOperation *mail_op =
4558 modest_mail_operation_new_with_error_handling (G_OBJECT(win),
4559 modest_ui_actions_move_folder_error_handler,
4561 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
4564 modest_mail_operation_xfer_msgs (mail_op,
4566 TNY_FOLDER (dst_folder),
4571 g_object_unref (G_OBJECT (mail_op));
4572 g_object_unref (headers);
4573 g_object_unref (dst_folder);
4577 TnyFolder *src_folder;
4578 TnyFolderStore *dst_folder;
4579 gboolean delete_original;
4580 GtkWidget *folder_view;
4584 on_move_folder_cb (gboolean canceled, GError *err, GtkWindow *parent_window,
4585 TnyAccount *account, gpointer user_data)
4587 MoveFolderInfo *info = (MoveFolderInfo*)user_data;
4588 GtkTreeSelection *sel;
4589 ModestMailOperation *mail_op = NULL;
4591 if (canceled || err || !MODEST_IS_MAIN_WINDOW (parent_window)) {
4592 g_object_unref (G_OBJECT (info->src_folder));
4593 g_object_unref (G_OBJECT (info->dst_folder));
4598 MoveToHelper *helper = g_new0 (MoveToHelper, 1);
4599 helper->banner = modest_platform_animation_banner (GTK_WIDGET (parent_window), NULL,
4600 _CS("ckct_nw_pasting"));
4601 if (helper->banner != NULL) {
4602 gtk_window_set_modal (GTK_WINDOW(helper->banner), FALSE);
4603 gtk_widget_show (GTK_WIDGET(helper->banner));
4605 /* Clean folder on header view before moving it */
4606 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (info->folder_view));
4607 gtk_tree_selection_unselect_all (sel);
4609 /* Let gtk events run. We need that the folder
4610 view frees its reference to the source
4611 folder *before* issuing the mail operation
4612 so we need the signal handler of selection
4613 changed to happen before the mail
4615 while (gtk_events_pending ())
4616 gtk_main_iteration (); */
4619 modest_mail_operation_new_with_error_handling (G_OBJECT(parent_window),
4620 modest_ui_actions_move_folder_error_handler,
4621 info->src_folder, NULL);
4622 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
4625 /* Select *after* the changes */
4626 /* TODO: this function hangs UI after transfer */
4627 /* modest_folder_view_select_folder (MODEST_FOLDER_VIEW(folder_view), */
4628 /* TNY_FOLDER (src_folder), TRUE); */
4630 modest_mail_operation_xfer_folder (mail_op,
4631 TNY_FOLDER (info->src_folder),
4633 info->delete_original,
4637 if (modest_mail_operation_get_status (mail_op) == MODEST_MAIL_OPERATION_STATUS_SUCCESS) {
4638 modest_folder_view_select_folder (MODEST_FOLDER_VIEW(info->folder_view),
4639 TNY_FOLDER (info->dst_folder), TRUE);
4642 /* Unref mail operation */
4643 g_object_unref (G_OBJECT (mail_op));
4644 g_object_unref (G_OBJECT (info->src_folder));
4645 g_object_unref (G_OBJECT (info->dst_folder));
4650 * UI handler for the "Move to" action when invoked from the
4654 modest_ui_actions_on_main_window_move_to (GtkAction *action,
4655 GtkWidget *folder_view,
4656 TnyFolderStore *dst_folder,
4657 ModestMainWindow *win)
4659 ModestHeaderView *header_view = NULL;
4660 TnyFolderStore *src_folder;
4661 gboolean online = (tny_device_is_online (modest_runtime_get_device()));
4663 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win));
4665 /* Get the source folder */
4666 src_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
4668 /* Get header view */
4669 header_view = MODEST_HEADER_VIEW(modest_main_window_get_child_widget (win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW));
4671 /* Get folder or messages to transfer */
4672 if (gtk_widget_is_focus (folder_view)) {
4673 gboolean do_xfer = TRUE;
4675 /* Allow only to transfer folders to the local root folder */
4676 if (TNY_IS_ACCOUNT (dst_folder) &&
4677 !MODEST_IS_TNY_LOCAL_FOLDERS_ACCOUNT (dst_folder)) {
4679 } else if (!TNY_IS_FOLDER (src_folder)) {
4680 g_warning ("%s: src_folder is not a TnyFolder.\n", __FUNCTION__);
4682 } /* else if (!online && modest_tny_folder_store_is_remote(src_folder)) {
4683 guint num_headers = tny_folder_get_all_count(TNY_FOLDER (src_folder));
4684 TnyAccount *account = tny_folder_get_account (TNY_FOLDER (src_folder));
4685 if (!connect_to_get_msg(MODEST_WINDOW (win), num_headers, account))
4687 g_object_unref (account);
4691 MoveFolderInfo *info = g_new0 (MoveFolderInfo, 1);
4692 info->src_folder = TNY_FOLDER (src_folder);
4693 info->dst_folder = dst_folder;
4694 info->delete_original = TRUE;
4695 info->folder_view = folder_view;
4696 g_object_ref (G_OBJECT (info->src_folder));
4697 g_object_ref (G_OBJECT (info->dst_folder));
4698 modest_platform_connect_if_remote_and_perform(GTK_WINDOW (win), TRUE,
4699 TNY_FOLDER_STORE (dst_folder), on_move_folder_cb, info);
4701 } else if (gtk_widget_is_focus (GTK_WIDGET(header_view))) {
4702 gboolean do_xfer = TRUE;
4703 /* Ask for confirmation if the source folder is remote and we're not connected */
4704 if (!online && modest_tny_folder_store_is_remote(src_folder)) {
4705 TnyList *headers = modest_header_view_get_selected_headers(header_view);
4706 if (!msgs_already_deleted_from_server(headers, src_folder)) {
4707 guint num_headers = tny_list_get_length(headers);
4708 TnyAccount *account = get_account_from_header_list (headers);
4709 if (!connect_to_get_msg(MODEST_WINDOW (win), num_headers, account))
4711 g_object_unref (account);
4713 g_object_unref(headers);
4715 if (do_xfer) /* Transfer messages */ {
4716 g_object_ref (dst_folder);
4717 modest_platform_connect_if_remote_and_perform(GTK_WINDOW (win), TRUE,
4718 TNY_FOLDER_STORE (dst_folder), xfer_messages_from_move_to_cb, dst_folder);
4723 g_object_unref (src_folder);
4728 * UI handler for the "Move to" action when invoked from the
4729 * ModestMsgViewWindow
4732 modest_ui_actions_on_msg_view_window_move_to (GtkAction *action,
4733 TnyFolderStore *dst_folder,
4734 ModestMsgViewWindow *win)
4736 TnyHeader *header = NULL;
4737 TnyFolder *src_folder = NULL;
4738 TnyAccount *account = NULL;
4739 gboolean do_xfer = FALSE;
4741 /* Create header list */
4742 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
4743 src_folder = TNY_FOLDER (tny_header_get_folder(header));
4744 g_object_unref (header);
4746 account = tny_folder_get_account (src_folder);
4747 if (!modest_tny_folder_store_is_remote(TNY_FOLDER_STORE(src_folder))) {
4748 /* Transfer if the source folder is local */
4750 } else if (remote_folder_is_pop(TNY_FOLDER_STORE(src_folder))) {
4751 /* Transfer if the source folder is POP (as it means
4752 * that the message is already downloaded) */
4754 } else if (connect_to_get_msg(MODEST_WINDOW(win), 1, account)) {
4755 /* Transfer after asking confirmation */
4760 g_object_ref (dst_folder);
4761 modest_platform_connect_if_remote_and_perform(GTK_WINDOW (win), TRUE,
4762 TNY_FOLDER_STORE (dst_folder), xfer_messages_from_move_to_cb, dst_folder);
4764 g_object_unref (account);
4765 g_object_unref (src_folder);
4769 modest_ui_actions_on_move_to (GtkAction *action,
4772 GtkWidget *dialog = NULL, *folder_view = NULL, *tree_view = NULL;
4774 TnyFolderStore *dst_folder = NULL;
4775 ModestMainWindow *main_window;
4777 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win) ||
4778 MODEST_IS_MSG_VIEW_WINDOW (win));
4780 /* Get the main window if exists */
4781 if (MODEST_IS_MAIN_WINDOW (win))
4782 main_window = MODEST_MAIN_WINDOW (win);
4785 MODEST_MAIN_WINDOW (modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (),
4786 FALSE)); /* don't create */
4788 /* Get the folder view widget if exists */
4790 folder_view = modest_main_window_get_child_widget (main_window,
4791 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
4795 /* Create and run the dialog */
4796 dialog = create_move_to_dialog (GTK_WINDOW (win), folder_view, &tree_view);
4797 modest_folder_view_select_first_inbox_or_local (MODEST_FOLDER_VIEW (tree_view));
4798 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
4799 result = gtk_dialog_run (GTK_DIALOG(dialog));
4800 g_object_ref (tree_view);
4801 gtk_widget_destroy (dialog);
4803 if (result != GTK_RESPONSE_ACCEPT)
4806 dst_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (tree_view));
4807 /* Do window specific stuff */
4808 if (MODEST_IS_MAIN_WINDOW (win)) {
4809 modest_ui_actions_on_main_window_move_to (action,
4812 MODEST_MAIN_WINDOW (win));
4814 modest_ui_actions_on_msg_view_window_move_to (action,
4816 MODEST_MSG_VIEW_WINDOW (win));
4820 g_object_unref (dst_folder);
4824 * Calls #HeadersFunc for each header already selected in the main
4825 * window or the message currently being shown in the msg view window
4828 do_headers_action (ModestWindow *win,
4832 TnyList *headers_list = NULL;
4833 TnyIterator *iter = NULL;
4834 TnyHeader *header = NULL;
4835 TnyFolder *folder = NULL;
4838 headers_list = get_selected_headers (win);
4842 /* Get the folder */
4843 iter = tny_list_create_iterator (headers_list);
4844 header = TNY_HEADER (tny_iterator_get_current (iter));
4846 folder = tny_header_get_folder (header);
4847 g_object_unref (header);
4850 /* Call the function for each header */
4851 while (!tny_iterator_is_done (iter)) {
4852 header = TNY_HEADER (tny_iterator_get_current (iter));
4853 func (header, win, user_data);
4854 g_object_unref (header);
4855 tny_iterator_next (iter);
4858 /* Trick: do a poke status in order to speed up the signaling
4860 tny_folder_poke_status (folder);
4863 g_object_unref (folder);
4864 g_object_unref (iter);
4865 g_object_unref (headers_list);
4869 modest_ui_actions_view_attachment (GtkAction *action,
4870 ModestWindow *window)
4872 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
4873 modest_msg_view_window_view_attachment (MODEST_MSG_VIEW_WINDOW (window), NULL);
4875 /* not supported window for this action */
4876 g_return_if_reached ();
4881 modest_ui_actions_save_attachments (GtkAction *action,
4882 ModestWindow *window)
4884 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
4885 modest_msg_view_window_save_attachments (MODEST_MSG_VIEW_WINDOW (window), NULL);
4887 /* not supported window for this action */
4888 g_return_if_reached ();
4893 modest_ui_actions_remove_attachments (GtkAction *action,
4894 ModestWindow *window)
4896 if (MODEST_IS_MAIN_WINDOW (window)) {
4897 modest_ui_actions_on_main_window_remove_attachments (action, MODEST_MAIN_WINDOW (window));
4898 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
4899 modest_msg_view_window_remove_attachments (MODEST_MSG_VIEW_WINDOW (window), FALSE);
4901 /* not supported window for this action */
4902 g_return_if_reached ();
4907 modest_ui_actions_on_settings (GtkAction *action,
4912 dialog = modest_platform_get_global_settings_dialog ();
4913 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (win));
4914 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
4915 gtk_widget_show_all (dialog);
4917 gtk_dialog_run (GTK_DIALOG (dialog));
4919 gtk_widget_destroy (dialog);
4923 modest_ui_actions_on_help (GtkAction *action,
4926 const gchar *help_id;
4928 g_return_if_fail (action);
4929 g_return_if_fail (win && GTK_IS_WINDOW(win));
4931 help_id = modest_window_mgr_get_help_id (modest_runtime_get_window_mgr(), win);
4934 modest_platform_show_help (GTK_WINDOW (win), help_id);
4936 g_warning ("%s: no help for window %p", __FUNCTION__, win);
4940 retrieve_msg_contents_performer (gboolean canceled,
4942 GtkWindow *parent_window,
4943 TnyAccount *account,
4946 ModestMailOperation *mail_op;
4947 TnyList *headers = TNY_LIST (user_data);
4949 if (err || canceled) {
4953 /* Create mail operation */
4954 mail_op = modest_mail_operation_new_with_error_handling ((GObject *) parent_window,
4955 modest_ui_actions_get_msgs_full_error_handler,
4957 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
4958 modest_mail_operation_get_msgs_full (mail_op, headers, NULL, NULL, NULL);
4961 g_object_unref (mail_op);
4963 g_object_unref (headers);
4964 g_object_unref (account);
4968 modest_ui_actions_on_retrieve_msg_contents (GtkAction *action,
4969 ModestWindow *window)
4971 TnyList *headers = NULL;
4972 TnyAccount *account = NULL;
4973 TnyIterator *iter = NULL;
4974 TnyHeader *header = NULL;
4975 TnyFolder *folder = NULL;
4978 headers = get_selected_headers (window);
4982 /* Pick the account */
4983 iter = tny_list_create_iterator (headers);
4984 header = TNY_HEADER (tny_iterator_get_current (iter));
4985 folder = tny_header_get_folder (header);
4986 account = tny_folder_get_account (folder);
4987 g_object_unref (folder);
4988 g_object_unref (header);
4989 g_object_unref (iter);
4991 /* Connect and perform the message retrieval */
4992 modest_platform_connect_and_perform ((GtkWindow *) window, TRUE,
4993 g_object_ref (account),
4994 retrieve_msg_contents_performer,
4995 g_object_ref (headers));
4998 g_object_unref (account);
4999 g_object_unref (headers);
5003 modest_ui_actions_check_toolbar_dimming_rules (ModestWindow *window)
5005 g_return_if_fail (MODEST_IS_WINDOW (window));
5008 modest_window_check_dimming_rules_group (window, MODEST_DIMMING_RULES_TOOLBAR);
5012 modest_ui_actions_check_menu_dimming_rules (ModestWindow *window)
5014 g_return_if_fail (MODEST_IS_WINDOW (window));
5017 modest_window_check_dimming_rules_group (window, MODEST_DIMMING_RULES_MENU);
5021 modest_ui_actions_on_email_menu_activated (GtkAction *action,
5022 ModestWindow *window)
5024 g_return_if_fail (MODEST_IS_WINDOW (window));
5027 modest_ui_actions_check_menu_dimming_rules (window);
5031 modest_ui_actions_on_edit_menu_activated (GtkAction *action,
5032 ModestWindow *window)
5034 g_return_if_fail (MODEST_IS_WINDOW (window));
5037 modest_ui_actions_check_menu_dimming_rules (window);
5041 modest_ui_actions_on_view_menu_activated (GtkAction *action,
5042 ModestWindow *window)
5044 g_return_if_fail (MODEST_IS_WINDOW (window));
5047 modest_ui_actions_check_menu_dimming_rules (window);
5051 modest_ui_actions_on_format_menu_activated (GtkAction *action,
5052 ModestWindow *window)
5054 g_return_if_fail (MODEST_IS_WINDOW (window));
5057 modest_ui_actions_check_menu_dimming_rules (window);
5061 modest_ui_actions_on_tools_menu_activated (GtkAction *action,
5062 ModestWindow *window)
5064 g_return_if_fail (MODEST_IS_WINDOW (window));
5067 modest_ui_actions_check_menu_dimming_rules (window);
5071 modest_ui_actions_on_attachment_menu_activated (GtkAction *action,
5072 ModestWindow *window)
5074 g_return_if_fail (MODEST_IS_WINDOW (window));
5077 modest_ui_actions_check_menu_dimming_rules (window);
5081 modest_ui_actions_on_toolbar_csm_menu_activated (GtkAction *action,
5082 ModestWindow *window)
5084 g_return_if_fail (MODEST_IS_WINDOW (window));
5087 modest_ui_actions_check_menu_dimming_rules (window);
5091 modest_ui_actions_on_folder_view_csm_menu_activated (GtkAction *action,
5092 ModestWindow *window)
5094 g_return_if_fail (MODEST_IS_WINDOW (window));
5097 modest_ui_actions_check_menu_dimming_rules (window);
5101 modest_ui_actions_on_header_view_csm_menu_activated (GtkAction *action,
5102 ModestWindow *window)
5104 g_return_if_fail (MODEST_IS_WINDOW (window));
5107 modest_ui_actions_check_menu_dimming_rules (window);
5111 modest_ui_actions_on_search_messages (GtkAction *action, ModestWindow *window)
5113 g_return_if_fail (MODEST_IS_WINDOW (window));
5115 modest_platform_show_search_messages (GTK_WINDOW (window));
5119 modest_ui_actions_on_open_addressbook (GtkAction *action, ModestWindow *win)
5121 g_return_if_fail (MODEST_IS_WINDOW (win));
5122 modest_platform_show_addressbook (GTK_WINDOW (win));
5127 modest_ui_actions_on_toggle_find_in_page (GtkToggleAction *action,
5128 ModestWindow *window)
5130 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
5132 modest_msg_edit_window_toggle_find_toolbar (MODEST_MSG_EDIT_WINDOW (window), gtk_toggle_action_get_active (action));
5136 on_send_receive_finished (ModestMailOperation *mail_op,
5139 GtkWidget *header_view, *folder_view;
5140 TnyFolderStore *folder_store;
5141 ModestMainWindow *main_win = MODEST_MAIN_WINDOW (user_data);
5143 /* Set send/receive operation finished */
5144 modest_main_window_notify_send_receive_completed (main_win);
5146 /* Don't refresh the current folder if there were any errors */
5147 if (modest_mail_operation_get_status (mail_op) !=
5148 MODEST_MAIL_OPERATION_STATUS_SUCCESS)
5151 /* Refresh the current folder if we're viewing a window. We do
5152 this because the user won't be able to see the new mails in
5153 the selected folder after a Send&Receive because it only
5154 performs a poke_status, i.e, only the number of read/unread
5155 messages is updated, but the new headers are not
5157 folder_view = modest_main_window_get_child_widget (main_win,
5158 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
5162 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
5164 /* Do not need to refresh INBOX again because the
5165 update_account does it always automatically */
5166 if (folder_store && TNY_IS_FOLDER (folder_store) &&
5167 tny_folder_get_folder_type (TNY_FOLDER (folder_store)) != TNY_FOLDER_TYPE_INBOX) {
5168 ModestMailOperation *refresh_op;
5170 header_view = modest_main_window_get_child_widget (main_win,
5171 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
5173 /* We do not need to set the contents style
5174 because it hasn't changed. We also do not
5175 need to save the widget status. Just force
5177 refresh_op = modest_mail_operation_new (G_OBJECT (main_win));
5178 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), refresh_op);
5179 modest_mail_operation_refresh_folder (refresh_op, TNY_FOLDER (folder_store),
5180 folder_refreshed_cb, main_win);
5181 g_object_unref (refresh_op);
5185 g_object_unref (folder_store);
5190 modest_ui_actions_on_send_queue_error_happened (TnySendQueue *self,
5196 const gchar* server_name = NULL;
5197 TnyTransportAccount *server_account;
5198 gchar *message = NULL;
5200 /* Don't show anything if the user cancelled something */
5201 if (err->code == TNY_TRANSPORT_ACCOUNT_ERROR_SEND_USER_CANCEL)
5204 /* Get the server name: */
5206 TNY_TRANSPORT_ACCOUNT (tny_camel_send_queue_get_transport_account (TNY_CAMEL_SEND_QUEUE (self)));
5207 if (server_account) {
5208 server_name = tny_account_get_hostname (TNY_ACCOUNT (server_account));
5210 g_object_unref (server_account);
5211 server_account = NULL;
5214 g_return_if_fail (server_name);
5216 /* Show the appropriate message text for the GError: */
5217 switch (err->code) {
5218 case TNY_TRANSPORT_ACCOUNT_ERROR_SEND_HOST_LOOKUP_FAILED:
5219 message = g_strdup_printf (_("emev_ib_ui_smtp_server_invalid"), server_name);
5221 case TNY_TRANSPORT_ACCOUNT_ERROR_SEND_SERVICE_UNAVAILABLE:
5222 message = g_strdup_printf (_("emev_ib_ui_smtp_server_invalid"), server_name);
5224 case TNY_TRANSPORT_ACCOUNT_ERROR_SEND_AUTHENTICATION_NOT_SUPPORTED:
5225 message = g_strdup_printf (_("emev_ni_ui_smtp_authentication_fail_error"), server_name);
5227 case TNY_TRANSPORT_ACCOUNT_ERROR_SEND:
5228 message = g_strdup (_("emev_ib_ui_smtp_send_error"));
5231 g_warning ("%s: unexpected TNY_TRANSPORT_ACCOUNT_ERROR %d",
5232 __FUNCTION__, err->code);
5233 message = g_strdup (_("emev_ib_ui_smtp_send_error"));
5237 /* TODO if the username or the password where not defined we
5238 should show the Accounts Settings dialog or the Connection
5239 specific SMTP server window */
5241 modest_platform_run_information_dialog (NULL, message);
5246 modest_ui_actions_on_send_queue_status_changed (ModestTnySendQueue *send_queue,
5251 ModestMainWindow *main_window = NULL;
5252 ModestWindowMgr *mgr = NULL;
5253 GtkWidget *folder_view = NULL, *header_view = NULL;
5254 TnyFolderStore *selected_folder = NULL;
5255 TnyFolderType folder_type;
5257 mgr = modest_runtime_get_window_mgr ();
5258 main_window = MODEST_MAIN_WINDOW (modest_window_mgr_get_main_window (mgr,
5259 FALSE));/* don't create */
5263 /* Check if selected folder is OUTBOX */
5264 folder_view = modest_main_window_get_child_widget (main_window,
5265 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
5266 header_view = modest_main_window_get_child_widget (main_window,
5267 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
5269 selected_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
5270 if (!TNY_IS_FOLDER (selected_folder))
5273 /* gtk_tree_view_column_queue_resize is only available in GTK+ 2.8 */
5274 #if GTK_CHECK_VERSION(2, 8, 0)
5275 folder_type = modest_tny_folder_guess_folder_type (TNY_FOLDER (selected_folder));
5276 if (folder_type == TNY_FOLDER_TYPE_OUTBOX) {
5277 GtkTreeViewColumn *tree_column;
5279 tree_column = gtk_tree_view_get_column (GTK_TREE_VIEW (header_view),
5280 TNY_GTK_HEADER_LIST_MODEL_FROM_COLUMN);
5281 gtk_tree_view_column_queue_resize (tree_column);
5284 gtk_widget_queue_draw (header_view);
5289 if (selected_folder != NULL)
5290 g_object_unref (selected_folder);
5294 modest_ui_actions_on_account_connection_error (GtkWindow *parent_window,
5295 TnyAccount *account)
5297 ModestTransportStoreProtocol proto;
5298 const gchar *proto_name;
5299 gchar *error_note = NULL;
5301 proto_name = tny_account_get_proto (account);
5302 proto = modest_protocol_info_get_transport_store_protocol (proto_name);
5305 case MODEST_PROTOCOL_STORE_POP:
5306 error_note = g_strdup_printf (_("emev_ni_ui_pop3_msg_connect_error"),
5307 tny_account_get_hostname (account));
5309 case MODEST_PROTOCOL_STORE_IMAP:
5310 error_note = g_strdup_printf (_("emev_ni_ui_imap_connect_server_error"),
5311 tny_account_get_hostname (account));
5313 case MODEST_PROTOCOL_STORE_MAILDIR:
5314 case MODEST_PROTOCOL_STORE_MBOX:
5315 error_note = g_strdup (_("emev_nc_mailbox_notavailable"));
5318 g_warning ("%s: This should not be reached", __FUNCTION__);
5322 modest_platform_run_information_dialog (parent_window, error_note);
5323 g_free (error_note);