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 foreach_unregister_headers (gpointer data,
1066 ModestWindowMgr *mgr = (ModestWindowMgr *) user_data;
1067 TnyHeader *header = TNY_HEADER (data);
1069 modest_window_mgr_unregister_header (mgr, header);
1073 open_msgs_performer(gboolean canceled,
1075 GtkWindow *parent_window,
1076 TnyAccount *account,
1079 ModestMailOperation *mail_op = NULL;
1080 const gchar *proto_name;
1082 ModestTransportStoreProtocol proto;
1083 TnyList *not_opened_headers;
1084 TnyConnectionStatus status;
1086 not_opened_headers = TNY_LIST (user_data);
1088 status = tny_account_get_connection_status (account);
1089 if (err || canceled) {
1090 /* Unregister the already registered headers */
1091 tny_list_foreach (not_opened_headers, foreach_unregister_headers,
1092 modest_runtime_get_window_mgr ());
1096 /* Get the error message depending on the protocol */
1097 proto_name = tny_account_get_proto (account);
1098 if (proto_name != NULL) {
1099 proto = modest_protocol_info_get_transport_store_protocol (proto_name);
1101 proto = MODEST_PROTOCOL_STORE_MAILDIR;
1104 /* Create the error messages */
1105 if (tny_list_get_length (not_opened_headers) == 1) {
1106 if (proto == MODEST_PROTOCOL_STORE_POP) {
1107 error_msg = g_strdup (_("emev_ni_ui_pop3_msg_recv_error"));
1108 } else if (proto == MODEST_PROTOCOL_STORE_IMAP) {
1109 TnyIterator *iter = tny_list_create_iterator (not_opened_headers);
1110 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter));
1111 error_msg = g_strdup_printf (_("emev_ni_ui_imap_message_not_available_in_server"),
1112 tny_header_get_subject (header));
1113 g_object_unref (header);
1114 g_object_unref (iter);
1116 error_msg = g_strdup (_("mail_ni_ui_folder_get_msg_folder_error"));
1119 error_msg = g_strdup (_("mail_ni_ui_folder_get_msg_folder_error"));
1122 /* Create the mail operation */
1124 modest_mail_operation_new_with_error_handling ((GObject *) parent_window,
1125 modest_ui_actions_get_msgs_full_error_handler,
1127 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
1130 modest_mail_operation_get_msgs_full (mail_op,
1139 g_object_unref (mail_op);
1140 g_object_unref (not_opened_headers);
1141 g_object_unref (account);
1145 * This function is used by both modest_ui_actions_on_open and
1146 * modest_ui_actions_on_header_activated. This way we always do the
1147 * same when trying to open messages.
1150 open_msgs_from_headers (TnyList *headers, ModestWindow *win)
1152 ModestWindowMgr *mgr = NULL;
1153 TnyIterator *iter = NULL, *iter_not_opened = NULL;
1154 TnyList *not_opened_headers = NULL;
1155 TnyHeaderFlags flags = 0;
1156 TnyAccount *account;
1157 gint uncached_msgs = 0;
1159 g_return_if_fail (headers != NULL);
1161 /* Check that only one message is selected for opening */
1162 if (tny_list_get_length (headers) != 1) {
1163 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
1164 _("mcen_ib_select_one_message"));
1168 mgr = modest_runtime_get_window_mgr ();
1169 iter = tny_list_create_iterator (headers);
1171 /* Get the account */
1172 account = get_account_from_header_list (headers);
1174 /* Look if we already have a message view for each header. If
1175 true, then remove the header from the list of headers to
1177 not_opened_headers = tny_simple_list_new ();
1178 while (!tny_iterator_is_done (iter)) {
1180 ModestWindow *window = NULL;
1181 TnyHeader *header = NULL;
1182 gboolean found = FALSE;
1184 header = TNY_HEADER (tny_iterator_get_current (iter));
1186 flags = tny_header_get_flags (header);
1189 found = modest_window_mgr_find_registered_header (mgr, header, &window);
1191 /* Do not open again the message and present the
1192 window to the user */
1195 gtk_window_present (GTK_WINDOW (window));
1197 /* the header has been registered already, we don't do
1198 * anything but wait for the window to come up*/
1199 g_debug ("header %p already registered, waiting for window", header);
1201 tny_list_append (not_opened_headers, G_OBJECT (header));
1205 g_object_unref (header);
1207 tny_iterator_next (iter);
1209 g_object_unref (iter);
1212 /* Open each message */
1213 if (tny_list_get_length (not_opened_headers) == 0)
1216 /* If some messages would have to be downloaded, ask the user to
1217 * make a connection. It's generally easier to do this here (in the mainloop)
1218 * than later in a thread:
1220 if (tny_list_get_length (not_opened_headers) > 0) {
1221 uncached_msgs = header_list_count_uncached_msgs (not_opened_headers);
1223 if (uncached_msgs > 0) {
1224 /* Allways download if we are online. */
1225 if (!tny_device_is_online (modest_runtime_get_device ())) {
1228 /* If ask for user permission to download the messages */
1229 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
1230 ngettext("mcen_nc_get_msg",
1234 /* End if the user does not want to continue */
1235 if (response == GTK_RESPONSE_CANCEL)
1241 /* Register the headers before actually creating the windows: */
1242 iter_not_opened = tny_list_create_iterator (not_opened_headers);
1243 while (!tny_iterator_is_done (iter_not_opened)) {
1244 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter_not_opened));
1246 modest_window_mgr_register_header (mgr, header, NULL);
1247 g_object_unref (header);
1249 tny_iterator_next (iter_not_opened);
1251 g_object_unref (iter_not_opened);
1252 iter_not_opened = NULL;
1254 /* Connect to the account and perform */
1255 if (uncached_msgs > 0) {
1256 modest_platform_connect_and_perform ((GtkWindow *) win, TRUE, g_object_ref (account),
1257 open_msgs_performer, g_object_ref (not_opened_headers));
1259 /* Call directly the performer, do not need to connect */
1260 open_msgs_performer (FALSE, NULL, (GtkWindow *) win, g_object_ref (account),
1261 g_object_ref (not_opened_headers));
1266 g_object_unref (account);
1267 if (not_opened_headers)
1268 g_object_unref (not_opened_headers);
1272 modest_ui_actions_on_open (GtkAction *action, ModestWindow *win)
1277 headers = get_selected_headers (win);
1282 open_msgs_from_headers (headers, win);
1284 g_object_unref(headers);
1289 free_reply_forward_helper (gpointer data)
1291 ReplyForwardHelper *helper;
1293 helper = (ReplyForwardHelper *) data;
1294 g_free (helper->account_name);
1295 g_slice_free (ReplyForwardHelper, helper);
1299 reply_forward_cb (ModestMailOperation *mail_op,
1307 ReplyForwardHelper *rf_helper;
1308 ModestWindow *msg_win = NULL;
1309 ModestEditType edit_type;
1311 TnyAccount *account = NULL;
1312 ModestWindowMgr *mgr = NULL;
1313 gchar *signature = NULL;
1314 gboolean use_signature;
1316 /* If there was any error. The mail operation could be NULL,
1317 this means that we already have the message downloaded and
1318 that we didn't do a mail operation to retrieve it */
1319 if (mail_op && !modest_ui_actions_msg_retrieval_check (mail_op, header, msg))
1322 g_return_if_fail (user_data != NULL);
1323 rf_helper = (ReplyForwardHelper *) user_data;
1325 from = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(),
1326 rf_helper->account_name);
1327 signature = modest_account_mgr_get_signature (modest_runtime_get_account_mgr(),
1328 rf_helper->account_name,
1331 /* Create reply mail */
1332 switch (rf_helper->action) {
1335 modest_tny_msg_create_reply_msg (msg, header, from, signature,
1336 rf_helper->reply_forward_type,
1337 MODEST_TNY_MSG_REPLY_MODE_SENDER);
1339 case ACTION_REPLY_TO_ALL:
1341 modest_tny_msg_create_reply_msg (msg, header, from, signature, rf_helper->reply_forward_type,
1342 MODEST_TNY_MSG_REPLY_MODE_ALL);
1343 edit_type = MODEST_EDIT_TYPE_REPLY;
1345 case ACTION_FORWARD:
1347 modest_tny_msg_create_forward_msg (msg, from, signature, rf_helper->reply_forward_type);
1348 edit_type = MODEST_EDIT_TYPE_FORWARD;
1351 g_return_if_reached ();
1358 g_printerr ("modest: failed to create message\n");
1362 account = modest_tny_account_store_get_server_account (modest_runtime_get_account_store(),
1363 rf_helper->account_name,
1364 TNY_ACCOUNT_TYPE_STORE);
1366 g_printerr ("modest: failed to get tnyaccount for '%s'\n", rf_helper->account_name);
1370 /* Create and register the windows */
1371 msg_win = modest_msg_edit_window_new (new_msg, rf_helper->account_name, FALSE);
1372 mgr = modest_runtime_get_window_mgr ();
1373 modest_window_mgr_register_window (mgr, msg_win);
1375 if (rf_helper->parent_window != NULL) {
1376 gdouble parent_zoom;
1378 parent_zoom = modest_window_get_zoom (MODEST_WINDOW (rf_helper->parent_window));
1379 modest_window_set_zoom (msg_win, parent_zoom);
1382 /* Show edit window */
1383 gtk_widget_show_all (GTK_WIDGET (msg_win));
1387 g_object_unref (msg_win);
1389 g_object_unref (G_OBJECT (new_msg));
1391 g_object_unref (G_OBJECT (account));
1392 /* g_object_unref (msg); */
1393 free_reply_forward_helper (rf_helper);
1396 /* Checks a list of headers. If any of them are not currently
1397 * downloaded (CACHED) then returns TRUE else returns FALSE.
1400 header_list_count_uncached_msgs (TnyList *header_list)
1403 gint uncached_messages = 0;
1405 iter = tny_list_create_iterator (header_list);
1406 while (!tny_iterator_is_done (iter)) {
1409 header = TNY_HEADER (tny_iterator_get_current (iter));
1411 if (!(tny_header_get_flags (header) & TNY_HEADER_FLAG_CACHED))
1412 uncached_messages ++;
1413 g_object_unref (header);
1416 tny_iterator_next (iter);
1418 g_object_unref (iter);
1420 return uncached_messages;
1423 /* Returns FALSE if the user does not want to download the
1424 * messages. Returns TRUE if the user allowed the download.
1427 connect_to_get_msg (ModestWindow *win,
1428 gint num_of_uncached_msgs,
1429 TnyAccount *account)
1431 GtkResponseType response;
1433 /* Allways download if we are online. */
1434 if (tny_device_is_online (modest_runtime_get_device ()))
1437 /* If offline, then ask for user permission to download the messages */
1438 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
1439 ngettext("mcen_nc_get_msg",
1441 num_of_uncached_msgs));
1443 if (response == GTK_RESPONSE_CANCEL)
1446 return modest_platform_connect_and_wait((GtkWindow *) win, account);
1450 * Common code for the reply and forward actions
1453 reply_forward (ReplyForwardAction action, ModestWindow *win)
1455 ModestMailOperation *mail_op = NULL;
1456 TnyList *header_list = NULL;
1457 ReplyForwardHelper *rf_helper = NULL;
1458 guint reply_forward_type;
1459 gboolean continue_download = TRUE;
1460 gboolean do_retrieve = TRUE;
1462 g_return_if_fail (MODEST_IS_WINDOW(win));
1464 /* we need an account when editing */
1465 if (!modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE)) {
1466 if (!modest_ui_actions_run_account_setup_wizard (win))
1470 header_list = get_selected_headers (win);
1474 reply_forward_type =
1475 modest_conf_get_int (modest_runtime_get_conf (),
1476 (action == ACTION_FORWARD) ? MODEST_CONF_FORWARD_TYPE : MODEST_CONF_REPLY_TYPE,
1479 /* check if we need to download msg before asking about it */
1480 do_retrieve = (action == ACTION_FORWARD) ||
1481 (reply_forward_type != MODEST_TNY_MSG_REPLY_TYPE_CITE);
1484 gint num_of_unc_msgs;
1486 /* check that the messages have been previously downloaded */
1487 num_of_unc_msgs = header_list_count_uncached_msgs(header_list);
1488 /* If there are any uncached message ask the user
1489 * whether he/she wants to download them. */
1490 if (num_of_unc_msgs) {
1491 TnyAccount *account = get_account_from_header_list (header_list);
1492 continue_download = connect_to_get_msg (win, num_of_unc_msgs, account);
1493 g_object_unref (account);
1497 if (!continue_download) {
1498 g_object_unref (header_list);
1502 /* We assume that we can only select messages of the
1503 same folder and that we reply all of them from the
1504 same account. In fact the interface currently only
1505 allows single selection */
1508 rf_helper = g_slice_new0 (ReplyForwardHelper);
1509 rf_helper->reply_forward_type = reply_forward_type;
1510 rf_helper->action = action;
1511 rf_helper->account_name = g_strdup (modest_window_get_active_account (win));
1513 if ((win != NULL) && (MODEST_IS_WINDOW (win)))
1514 rf_helper->parent_window = GTK_WIDGET (win);
1515 if (!rf_helper->account_name)
1516 rf_helper->account_name =
1517 modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
1519 if (MODEST_IS_MSG_VIEW_WINDOW(win)) {
1522 /* Get header and message. Do not free them here, the
1523 reply_forward_cb must do it */
1524 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW(win));
1525 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW(win));
1526 if (!msg || !header) {
1528 g_object_unref (msg);
1529 g_printerr ("modest: no message found\n");
1532 reply_forward_cb (NULL, header, FALSE, msg, NULL, rf_helper);
1535 g_object_unref (header);
1540 /* Only reply/forward to one message */
1541 iter = tny_list_create_iterator (header_list);
1542 header = TNY_HEADER (tny_iterator_get_current (iter));
1543 g_object_unref (iter);
1546 /* Retrieve messages */
1549 modest_mail_operation_new_with_error_handling (G_OBJECT(win),
1550 modest_ui_actions_get_msgs_full_error_handler,
1552 modest_mail_operation_queue_add (
1553 modest_runtime_get_mail_operation_queue (), mail_op);
1555 modest_mail_operation_get_msg (mail_op,
1560 g_object_unref(mail_op);
1562 /* we put a ref here to prevent double unref as the reply
1563 * forward callback unrefs the header at its end */
1564 reply_forward_cb (NULL, header, FALSE, NULL, NULL, rf_helper);
1568 g_object_unref (header);
1574 g_object_unref (header_list);
1578 modest_ui_actions_on_reply (GtkAction *action, ModestWindow *win)
1580 g_return_if_fail (MODEST_IS_WINDOW(win));
1582 reply_forward (ACTION_REPLY, win);
1586 modest_ui_actions_on_forward (GtkAction *action, ModestWindow *win)
1588 g_return_if_fail (MODEST_IS_WINDOW(win));
1590 reply_forward (ACTION_FORWARD, win);
1594 modest_ui_actions_on_reply_all (GtkAction *action, ModestWindow *win)
1596 g_return_if_fail (MODEST_IS_WINDOW(win));
1598 reply_forward (ACTION_REPLY_TO_ALL, win);
1602 modest_ui_actions_on_next (GtkAction *action,
1603 ModestWindow *window)
1605 if (MODEST_IS_MAIN_WINDOW (window)) {
1606 GtkWidget *header_view;
1608 header_view = modest_main_window_get_child_widget (
1609 MODEST_MAIN_WINDOW(window),
1610 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1614 modest_header_view_select_next (
1615 MODEST_HEADER_VIEW(header_view));
1616 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
1617 modest_msg_view_window_select_next_message (
1618 MODEST_MSG_VIEW_WINDOW (window));
1620 g_return_if_reached ();
1625 modest_ui_actions_on_prev (GtkAction *action,
1626 ModestWindow *window)
1628 g_return_if_fail (MODEST_IS_WINDOW(window));
1630 if (MODEST_IS_MAIN_WINDOW (window)) {
1631 GtkWidget *header_view;
1632 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
1633 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1637 modest_header_view_select_prev (MODEST_HEADER_VIEW(header_view));
1638 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
1639 modest_msg_view_window_select_previous_message (MODEST_MSG_VIEW_WINDOW (window));
1641 g_return_if_reached ();
1646 modest_ui_actions_on_sort (GtkAction *action,
1647 ModestWindow *window)
1649 g_return_if_fail (MODEST_IS_WINDOW(window));
1651 if (MODEST_IS_MAIN_WINDOW (window)) {
1652 GtkWidget *header_view;
1653 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
1654 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1656 modest_platform_information_banner (NULL, NULL, _CS("ckdg_ib_nothing_to_sort"));
1661 /* Show sorting dialog */
1662 modest_platform_run_sort_dialog (GTK_WINDOW (window), MODEST_SORT_HEADERS);
1667 new_messages_arrived (ModestMailOperation *self,
1668 TnyList *new_headers,
1672 gboolean show_visual_notifications;
1674 source = modest_mail_operation_get_source (self);
1675 show_visual_notifications = (source) ? FALSE : TRUE;
1677 g_object_unref (source);
1679 /* Notify new messages have been downloaded. If the
1680 send&receive was invoked by the user then do not show any
1681 visual notification, only play a sound and activate the LED
1682 (for the Maemo version) */
1683 if ((new_headers != NULL) && (tny_list_get_length (new_headers) > 0))
1684 modest_platform_on_new_headers_received (new_headers,
1685 show_visual_notifications);
1690 retrieve_all_messages_cb (GObject *source,
1692 guint retrieve_limit)
1698 window = GTK_WINDOW (source);
1699 msg = g_strdup_printf (_("mail_nc_msg_count_limit_exceeded"),
1700 num_msgs, retrieve_limit);
1702 /* Ask the user if they want to retrieve all the messages */
1704 modest_platform_run_confirmation_dialog_with_buttons (window, msg,
1705 _("mcen_bd_get_all"),
1706 _("mcen_bd_newest_only"));
1707 /* Free and return */
1709 return (response == GTK_RESPONSE_ACCEPT) ? TRUE : FALSE;
1713 TnyAccount *account;
1715 gchar *account_name;
1719 do_send_receive_performer (gboolean canceled,
1721 GtkWindow *parent_window,
1722 TnyAccount *account,
1725 ModestMailOperation *mail_op;
1726 SendReceiveInfo *info;
1728 info = (SendReceiveInfo *) user_data;
1730 if (err || canceled) {
1734 /* Set send/receive operation in progress */
1735 if (info->win && MODEST_IS_MAIN_WINDOW (info->win)) {
1736 modest_main_window_notify_send_receive_initied (MODEST_MAIN_WINDOW (info->win));
1739 mail_op = modest_mail_operation_new_with_error_handling ((info->win) ? G_OBJECT (info->win) : NULL,
1740 modest_ui_actions_send_receive_error_handler,
1743 if (info->win && MODEST_IS_MAIN_WINDOW (info->win))
1744 g_signal_connect (G_OBJECT(mail_op), "operation-finished",
1745 G_CALLBACK (on_send_receive_finished),
1748 /* Send & receive. */
1749 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
1750 modest_mail_operation_update_account (mail_op, info->account_name, (info->win) ? FALSE : TRUE,
1751 (info->win) ? retrieve_all_messages_cb : NULL,
1752 new_messages_arrived, info->win);
1753 g_object_unref (G_OBJECT (mail_op));
1757 if (info->account_name)
1758 g_free (info->account_name);
1760 g_object_unref (info->win);
1762 g_object_unref (info->account);
1763 g_slice_free (SendReceiveInfo, info);
1767 * This function performs the send & receive required actions. The
1768 * window is used to create the mail operation. Typically it should
1769 * always be the main window, but we pass it as argument in order to
1773 modest_ui_actions_do_send_receive (const gchar *account_name,
1774 gboolean force_connection,
1777 gchar *acc_name = NULL;
1778 SendReceiveInfo *info;
1779 ModestTnyAccountStore *acc_store;
1781 /* If no account name was provided then get the current account, and if
1782 there is no current account then pick the default one: */
1783 if (!account_name) {
1785 acc_name = g_strdup (modest_window_get_active_account (win));
1787 acc_name = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
1789 g_printerr ("modest: cannot get default account\n");
1793 acc_name = g_strdup (account_name);
1796 acc_store = modest_runtime_get_account_store ();
1798 /* Create the info for the connect and perform */
1799 info = g_slice_new (SendReceiveInfo);
1800 info->account_name = acc_name;
1801 info->win = (win) ? g_object_ref (win) : NULL;
1802 info->account = modest_tny_account_store_get_server_account (acc_store, acc_name,
1803 TNY_ACCOUNT_TYPE_STORE);
1805 /* Invoke the connect and perform */
1806 modest_platform_connect_and_perform ((win) ? GTK_WINDOW (win) : NULL,
1807 force_connection, info->account,
1808 do_send_receive_performer, info);
1813 modest_ui_actions_do_cancel_send (const gchar *account_name,
1816 TnyTransportAccount *transport_account;
1817 TnySendQueue *send_queue = NULL;
1818 GError *error = NULL;
1820 /* Get transport account */
1822 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
1823 (modest_runtime_get_account_store(),
1825 TNY_ACCOUNT_TYPE_TRANSPORT));
1826 if (!transport_account) {
1827 g_printerr ("modest: no transport account found for '%s'\n", account_name);
1832 send_queue = TNY_SEND_QUEUE (modest_runtime_get_send_queue (transport_account));
1833 if (!TNY_IS_SEND_QUEUE(send_queue)) {
1834 g_set_error (&error, MODEST_MAIL_OPERATION_ERROR,
1835 MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND,
1836 "modest: could not find send queue for account\n");
1838 /* Keeep messages in outbox folder */
1839 tny_send_queue_cancel (send_queue, FALSE, &error);
1843 if (transport_account != NULL)
1844 g_object_unref (G_OBJECT (transport_account));
1848 modest_ui_actions_cancel_send_all (ModestWindow *win)
1850 GSList *account_names, *iter;
1852 account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
1855 iter = account_names;
1857 modest_ui_actions_do_cancel_send ((const char*) iter->data, win);
1858 iter = g_slist_next (iter);
1861 modest_account_mgr_free_account_names (account_names);
1862 account_names = NULL;
1866 modest_ui_actions_cancel_send (GtkAction *action, ModestWindow *win)
1869 /* Check if accounts exist */
1870 gboolean accounts_exist =
1871 modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
1873 /* If not, allow the user to create an account before trying to send/receive. */
1874 if (!accounts_exist)
1875 modest_ui_actions_on_accounts (NULL, win);
1877 /* Cancel all sending operaitons */
1878 modest_ui_actions_cancel_send_all (win);
1882 * Refreshes all accounts. This function will be used by automatic
1886 modest_ui_actions_do_send_receive_all (ModestWindow *win,
1887 gboolean force_connection)
1889 GSList *account_names, *iter;
1891 account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
1894 iter = account_names;
1896 modest_ui_actions_do_send_receive ((const char*) iter->data, force_connection, win);
1897 iter = g_slist_next (iter);
1900 modest_account_mgr_free_account_names (account_names);
1901 account_names = NULL;
1905 * Handler of the click on Send&Receive button in the main toolbar
1908 modest_ui_actions_on_send_receive (GtkAction *action, ModestWindow *win)
1910 /* Check if accounts exist */
1911 gboolean accounts_exist;
1914 modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
1916 /* If not, allow the user to create an account before trying to send/receive. */
1917 if (!accounts_exist)
1918 modest_ui_actions_on_accounts (NULL, win);
1920 /* Refresh the current folder. The if is always TRUE it's just an extra check */
1921 if (MODEST_IS_MAIN_WINDOW (win)) {
1922 GtkWidget *folder_view;
1923 TnyFolderStore *folder_store;
1926 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
1927 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
1931 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
1934 g_object_unref (folder_store);
1937 /* Refresh the active account. Force the connection if needed */
1938 modest_ui_actions_do_send_receive (NULL, TRUE, win);
1943 modest_ui_actions_toggle_header_list_view (GtkAction *action, ModestMainWindow *main_window)
1946 GtkWidget *header_view;
1948 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1950 header_view = modest_main_window_get_child_widget (main_window,
1951 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1955 conf = modest_runtime_get_conf ();
1957 /* what is saved/restored is depending on the style; thus; we save with
1958 * old style, then update the style, and restore for this new style
1960 modest_widget_memory_save (conf, G_OBJECT(header_view), MODEST_CONF_HEADER_VIEW_KEY);
1962 if (modest_header_view_get_style
1963 (MODEST_HEADER_VIEW(header_view)) == MODEST_HEADER_VIEW_STYLE_DETAILS)
1964 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
1965 MODEST_HEADER_VIEW_STYLE_TWOLINES);
1967 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
1968 MODEST_HEADER_VIEW_STYLE_DETAILS);
1970 modest_widget_memory_restore (conf, G_OBJECT(header_view),
1971 MODEST_CONF_HEADER_VIEW_KEY);
1976 modest_ui_actions_on_header_selected (ModestHeaderView *header_view,
1978 ModestMainWindow *main_window)
1980 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1981 g_return_if_fail (MODEST_IS_HEADER_VIEW (header_view));
1983 /* in the case the folder is empty, show the empty folder message and focus
1985 if (!header && gtk_widget_is_focus (GTK_WIDGET (header_view))) {
1986 if (modest_header_view_is_empty (header_view)) {
1987 TnyFolder *folder = modest_header_view_get_folder (header_view);
1988 GtkWidget *folder_view =
1989 modest_main_window_get_child_widget (main_window,
1990 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
1992 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view), folder, FALSE);
1993 gtk_widget_grab_focus (GTK_WIDGET (folder_view));
1997 /* If no header has been selected then exit */
2002 if (!gtk_widget_is_focus (GTK_WIDGET(header_view)))
2003 gtk_widget_grab_focus (GTK_WIDGET(header_view));
2005 /* Update toolbar dimming state */
2006 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
2010 modest_ui_actions_on_header_activated (ModestHeaderView *header_view,
2012 ModestMainWindow *main_window)
2016 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2021 if (modest_header_view_count_selected_headers (header_view) > 1) {
2022 modest_platform_information_banner (NULL, NULL, _("mcen_ib_select_one_message"));
2027 /* headers = tny_simple_list_new (); */
2028 /* tny_list_prepend (headers, G_OBJECT (header)); */
2029 headers = modest_header_view_get_selected_headers (header_view);
2031 open_msgs_from_headers (headers, MODEST_WINDOW (main_window));
2033 g_object_unref (headers);
2037 set_active_account_from_tny_account (TnyAccount *account,
2038 ModestWindow *window)
2040 const gchar *server_acc_name = tny_account_get_id (account);
2042 /* We need the TnyAccount provided by the
2043 account store because that is the one that
2044 knows the name of the Modest account */
2045 TnyAccount *modest_server_account = modest_server_account =
2046 modest_tny_account_store_get_tny_account_by (modest_runtime_get_account_store (),
2047 MODEST_TNY_ACCOUNT_STORE_QUERY_ID,
2049 if (!modest_server_account) {
2050 g_warning ("%s: could not get tny account\n", __FUNCTION__);
2054 /* Update active account, but only if it's not a pseudo-account */
2055 if ((!modest_tny_account_is_virtual_local_folders(modest_server_account)) &&
2056 (!modest_tny_account_is_memory_card_account(modest_server_account))) {
2057 const gchar *modest_acc_name =
2058 modest_tny_account_get_parent_modest_account_name_for_server_account (modest_server_account);
2059 if (modest_acc_name)
2060 modest_window_set_active_account (window, modest_acc_name);
2063 g_object_unref (modest_server_account);
2068 folder_refreshed_cb (ModestMailOperation *mail_op,
2072 ModestMainWindow *win = NULL;
2073 GtkWidget *header_view;
2075 g_return_if_fail (TNY_IS_FOLDER (folder));
2077 win = MODEST_MAIN_WINDOW (user_data);
2079 modest_main_window_get_child_widget(win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2082 TnyFolder *current_folder;
2084 current_folder = modest_header_view_get_folder (MODEST_HEADER_VIEW (header_view));
2085 if (current_folder != NULL && folder != current_folder) {
2086 g_object_unref (current_folder);
2088 } else if (current_folder)
2089 g_object_unref (current_folder);
2092 /* Check if folder is empty and set headers view contents style */
2093 if (tny_folder_get_all_count (folder) == 0)
2094 modest_main_window_set_contents_style (win,
2095 MODEST_MAIN_WINDOW_CONTENTS_STYLE_EMPTY);
2099 modest_ui_actions_on_folder_selection_changed (ModestFolderView *folder_view,
2100 TnyFolderStore *folder_store,
2102 ModestMainWindow *main_window)
2105 GtkWidget *header_view;
2107 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2109 header_view = modest_main_window_get_child_widget(main_window,
2110 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2114 conf = modest_runtime_get_conf ();
2116 if (TNY_IS_ACCOUNT (folder_store)) {
2118 set_active_account_from_tny_account (TNY_ACCOUNT (folder_store), MODEST_WINDOW (main_window));
2120 /* Show account details */
2121 modest_main_window_set_contents_style (main_window, MODEST_MAIN_WINDOW_CONTENTS_STYLE_DETAILS);
2124 if (TNY_IS_FOLDER (folder_store) && selected) {
2126 /* Update the active account */
2127 TnyAccount *account = modest_tny_folder_get_account (TNY_FOLDER (folder_store));
2129 set_active_account_from_tny_account (account, MODEST_WINDOW (main_window));
2130 g_object_unref (account);
2134 /* Set the header style by default, it could
2135 be changed later by the refresh callback to
2137 modest_main_window_set_contents_style (main_window,
2138 MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS);
2140 /* Set folder on header view. This function
2141 will call tny_folder_refresh_async so we
2142 pass a callback that will be called when
2143 finished. We use that callback to set the
2144 empty view if there are no messages */
2145 modest_header_view_set_folder (MODEST_HEADER_VIEW(header_view),
2146 TNY_FOLDER (folder_store),
2147 folder_refreshed_cb,
2150 /* Restore configuration. We need to do this
2151 *after* the set_folder because the widget
2152 memory asks the header view about its
2154 modest_widget_memory_restore (modest_runtime_get_conf (),
2155 G_OBJECT(header_view),
2156 MODEST_CONF_HEADER_VIEW_KEY);
2158 /* Update the active account */
2159 //modest_window_set_active_account (MODEST_WINDOW (main_window), NULL);
2160 /* Save only if we're seeing headers */
2161 if (modest_main_window_get_contents_style (main_window) ==
2162 MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS)
2163 modest_widget_memory_save (conf, G_OBJECT (header_view),
2164 MODEST_CONF_HEADER_VIEW_KEY);
2165 modest_header_view_clear (MODEST_HEADER_VIEW(header_view));
2169 /* Update toolbar dimming state */
2170 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
2174 modest_ui_actions_on_item_not_found (ModestHeaderView *header_view,ModestItemType type,
2181 item = (type == MODEST_ITEM_TYPE_FOLDER) ? "folder" : "message";
2183 online = tny_device_is_online (modest_runtime_get_device());
2186 /* already online -- the item is simply not there... */
2187 dialog = gtk_message_dialog_new (GTK_WINDOW (win),
2189 GTK_MESSAGE_WARNING,
2191 _("The %s you selected cannot be found"),
2193 gtk_dialog_add_button (GTK_DIALOG (dialog),_("mcen_bd_dialog_ok"), GTK_RESPONSE_ACCEPT);
2194 gtk_dialog_run (GTK_DIALOG(dialog));
2196 dialog = gtk_dialog_new_with_buttons (_("Connection requested"),
2199 _("mcen_bd_dialog_cancel"),
2200 GTK_RESPONSE_REJECT,
2201 _("mcen_bd_dialog_ok"),
2202 GTK_RESPONSE_ACCEPT,
2204 txt = g_strdup_printf (_("This %s is not available in offline mode.\n"
2205 "Do you want to get online?"), item);
2206 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
2207 gtk_label_new (txt), FALSE, FALSE, 0);
2208 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
2211 gtk_window_set_default_size (GTK_WINDOW(dialog), 300, 300);
2212 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
2213 /* TODO: Comment about why is this commented out: */
2214 /* modest_platform_connect_and_wait (); */
2217 gtk_widget_destroy (dialog);
2221 modest_ui_actions_on_msg_link_hover (ModestMsgView *msgview, const gchar* link,
2224 /* g_message ("%s %s", __FUNCTION__, link); */
2229 modest_ui_actions_on_msg_link_clicked (ModestMsgView *msgview, const gchar* link,
2232 modest_platform_activate_uri (link);
2236 modest_ui_actions_on_msg_link_contextual (ModestMsgView *msgview, const gchar* link,
2239 modest_platform_show_uri_popup (link);
2243 modest_ui_actions_on_msg_attachment_clicked (ModestMsgView *msgview, TnyMimePart *mime_part,
2246 modest_msg_view_window_view_attachment (MODEST_MSG_VIEW_WINDOW (win), mime_part);
2250 modest_ui_actions_on_msg_recpt_activated (ModestMsgView *msgview,
2251 const gchar *address,
2254 /* g_message ("%s %s", __FUNCTION__, address); */
2258 on_save_to_drafts_cb (ModestMailOperation *mail_op,
2259 TnyMsg *saved_draft,
2262 ModestMsgEditWindow *edit_window;
2263 ModestMainWindow *win;
2265 /* FIXME. Make the header view sensitive again. This is a
2266 * temporary hack. See modest_ui_actions_on_save_to_drafts()
2268 win = MODEST_MAIN_WINDOW(modest_window_mgr_get_main_window(
2269 modest_runtime_get_window_mgr(), FALSE));
2271 GtkWidget *hdrview = modest_main_window_get_child_widget(
2272 win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2273 if (hdrview) gtk_widget_set_sensitive(hdrview, TRUE);
2276 edit_window = MODEST_MSG_EDIT_WINDOW (user_data);
2278 /* It might not be a good idea to do nothing if there was an error,
2279 * so let's at least show a generic error banner. */
2280 /* TODO error while saving attachment, show "Saving draft failed" banner */
2281 if (modest_mail_operation_get_error (mail_op) != NULL) {
2282 g_warning ("%s failed: %s\n", __FUNCTION__, (modest_mail_operation_get_error (mail_op))->message);
2283 modest_platform_information_banner (NULL, NULL, _("mail_ib_file_operation_failed"));
2285 modest_msg_edit_window_set_draft (edit_window, saved_draft);
2287 g_object_unref(edit_window);
2291 modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edit_window)
2293 TnyTransportAccount *transport_account;
2294 ModestMailOperation *mail_operation;
2296 gchar *account_name, *from;
2297 ModestAccountMgr *account_mgr;
2300 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window));
2302 data = modest_msg_edit_window_get_msg_data (edit_window);
2304 account_name = g_strdup (data->account_name);
2305 account_mgr = modest_runtime_get_account_mgr();
2307 account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
2309 account_name = modest_account_mgr_get_default_account (account_mgr);
2310 if (!account_name) {
2311 g_printerr ("modest: no account found\n");
2312 modest_msg_edit_window_free_msg_data (edit_window, data);
2316 if (!strcmp (account_name, MODEST_LOCAL_FOLDERS_ACCOUNT_ID)) {
2317 account_name = g_strdup (data->account_name);
2321 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
2322 (modest_runtime_get_account_store(),
2324 TNY_ACCOUNT_TYPE_TRANSPORT));
2325 if (!transport_account) {
2326 g_printerr ("modest: no transport account found for '%s'\n", account_name);
2327 g_free (account_name);
2328 modest_msg_edit_window_free_msg_data (edit_window, data);
2331 from = modest_account_mgr_get_from_string (account_mgr, account_name);
2333 /* Create the mail operation */
2334 mail_operation = modest_mail_operation_new (NULL);
2335 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
2337 modest_mail_operation_save_to_drafts (mail_operation,
2349 data->priority_flags,
2350 on_save_to_drafts_cb,
2351 g_object_ref(edit_window));
2352 info_text = g_strdup_printf (_("mail_va_saved_to_drafts"), _("mcen_me_folder_drafts"));
2353 modest_platform_information_banner (NULL, NULL, info_text);
2358 g_free (account_name);
2359 g_object_unref (G_OBJECT (transport_account));
2360 g_object_unref (G_OBJECT (mail_operation));
2362 modest_msg_edit_window_free_msg_data (edit_window, data);
2363 modest_msg_edit_window_reset_modified (edit_window);
2366 * If the drafts folder is selected then make the header view
2367 * insensitive while the message is being saved to drafts
2368 * (it'll be sensitive again in on_save_to_drafts_cb()). This
2369 * is not very clean but it avoids letting the drafts folder
2370 * in an inconsistent state: the user could edit the message
2371 * being saved and undesirable things would happen.
2372 * In the average case the user won't notice anything at
2373 * all. In the worst case (the user is editing a really big
2374 * file from Drafts) the header view will be insensitive
2375 * during the saving process (10 or 20 seconds, depending on
2376 * the message). Anyway this is just a quick workaround: once
2377 * we find a better solution it should be removed
2378 * See NB#65125 (commend #18) for details.
2380 ModestMainWindow *win = MODEST_MAIN_WINDOW(modest_window_mgr_get_main_window(
2381 modest_runtime_get_window_mgr(), FALSE));
2383 ModestFolderView *view = MODEST_FOLDER_VIEW(modest_main_window_get_child_widget(
2384 win, MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW));
2386 TnyFolder *folder = TNY_FOLDER(modest_folder_view_get_selected(view));
2388 if (modest_tny_folder_is_local_folder(folder)) {
2389 TnyFolderType folder_type;
2390 folder_type = modest_tny_folder_get_local_or_mmc_folder_type(folder);
2391 if (folder_type == TNY_FOLDER_TYPE_DRAFTS) {
2392 GtkWidget *hdrview = modest_main_window_get_child_widget(
2393 win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2394 if (hdrview) gtk_widget_set_sensitive(hdrview, FALSE);
2398 if (folder != NULL) g_object_unref(folder);
2403 /* For instance, when clicking the Send toolbar button when editing a message: */
2405 modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
2407 TnyTransportAccount *transport_account = NULL;
2409 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window));
2411 if (!modest_msg_edit_window_check_names (edit_window, TRUE))
2414 /* FIXME: Code added just for testing. The final version will
2415 use the send queue provided by tinymail and some
2417 MsgData *data = modest_msg_edit_window_get_msg_data (edit_window);
2419 ModestAccountMgr *account_mgr = modest_runtime_get_account_mgr();
2420 gchar *account_name = g_strdup (data->account_name);
2422 account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
2425 account_name = modest_account_mgr_get_default_account (account_mgr);
2427 if (!account_name) {
2428 modest_msg_edit_window_free_msg_data (edit_window, data);
2429 /* Run account setup wizard */
2430 if (!modest_ui_actions_run_account_setup_wizard (MODEST_WINDOW(edit_window))) {
2435 /* Get the currently-active transport account for this modest account: */
2436 if (strcmp (account_name, MODEST_LOCAL_FOLDERS_ACCOUNT_ID) != 0) {
2437 transport_account = TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
2438 (modest_runtime_get_account_store(),
2439 account_name, TNY_ACCOUNT_TYPE_TRANSPORT));
2442 if (!transport_account) {
2443 modest_msg_edit_window_free_msg_data (edit_window, data);
2444 /* Run account setup wizard */
2445 if (!modest_ui_actions_run_account_setup_wizard(MODEST_WINDOW(edit_window)))
2449 gchar *from = modest_account_mgr_get_from_string (account_mgr, account_name);
2451 /* Create the mail operation */
2452 ModestMailOperation *mail_operation = modest_mail_operation_new (NULL);
2453 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
2455 modest_mail_operation_send_new_mail (mail_operation,
2467 data->priority_flags);
2469 if (modest_mail_operation_get_status (mail_operation) == MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS)
2470 modest_platform_information_banner (NULL, NULL, _("mcen_ib_outbox_waiting_to_be_sent"));
2475 g_free (account_name);
2476 g_object_unref (G_OBJECT (transport_account));
2477 g_object_unref (G_OBJECT (mail_operation));
2479 modest_msg_edit_window_free_msg_data (edit_window, data);
2480 modest_msg_edit_window_set_sent (edit_window, TRUE);
2482 /* Save settings and close the window: */
2483 modest_ui_actions_on_close_window (NULL, MODEST_WINDOW (edit_window));
2487 modest_ui_actions_on_toggle_bold (GtkToggleAction *action,
2488 ModestMsgEditWindow *window)
2490 ModestMsgEditFormatState *format_state = NULL;
2492 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2493 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
2495 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2498 format_state = modest_msg_edit_window_get_format_state (window);
2499 g_return_if_fail (format_state != NULL);
2501 format_state->bold = gtk_toggle_action_get_active (action);
2502 modest_msg_edit_window_set_format_state (window, format_state);
2503 g_free (format_state);
2508 modest_ui_actions_on_toggle_italics (GtkToggleAction *action,
2509 ModestMsgEditWindow *window)
2511 ModestMsgEditFormatState *format_state = NULL;
2513 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2514 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
2516 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2519 format_state = modest_msg_edit_window_get_format_state (window);
2520 g_return_if_fail (format_state != NULL);
2522 format_state->italics = gtk_toggle_action_get_active (action);
2523 modest_msg_edit_window_set_format_state (window, format_state);
2524 g_free (format_state);
2529 modest_ui_actions_on_toggle_bullets (GtkToggleAction *action,
2530 ModestMsgEditWindow *window)
2532 ModestMsgEditFormatState *format_state = NULL;
2534 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2535 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
2537 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2540 format_state = modest_msg_edit_window_get_format_state (window);
2541 g_return_if_fail (format_state != NULL);
2543 format_state->bullet = gtk_toggle_action_get_active (action);
2544 modest_msg_edit_window_set_format_state (window, format_state);
2545 g_free (format_state);
2550 modest_ui_actions_on_change_justify (GtkRadioAction *action,
2551 GtkRadioAction *selected,
2552 ModestMsgEditWindow *window)
2554 ModestMsgEditFormatState *format_state = NULL;
2555 GtkJustification value;
2557 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2559 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2562 value = gtk_radio_action_get_current_value (selected);
2564 format_state = modest_msg_edit_window_get_format_state (window);
2565 g_return_if_fail (format_state != NULL);
2567 format_state->justification = value;
2568 modest_msg_edit_window_set_format_state (window, format_state);
2569 g_free (format_state);
2573 modest_ui_actions_on_select_editor_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_color (window);
2586 modest_ui_actions_on_select_editor_background_color (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_select_background_color (window);
2599 modest_ui_actions_on_insert_image (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 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2608 modest_msg_edit_window_insert_image (window);
2612 modest_ui_actions_on_attach_file (GtkAction *action,
2613 ModestMsgEditWindow *window)
2615 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2616 g_return_if_fail (GTK_IS_ACTION (action));
2618 modest_msg_edit_window_offer_attach_file (window);
2622 modest_ui_actions_on_remove_attachments (GtkAction *action,
2623 ModestMsgEditWindow *window)
2625 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2626 g_return_if_fail (GTK_IS_ACTION (action));
2628 modest_msg_edit_window_remove_attachments (window, NULL);
2632 do_create_folder_cb (ModestMailOperation *mail_op,
2633 TnyFolderStore *parent_folder,
2634 TnyFolder *new_folder,
2637 gchar *suggested_name = (gchar *) user_data;
2638 GtkWindow *source_win = (GtkWindow *) modest_mail_operation_get_source (mail_op);
2640 if (modest_mail_operation_get_error (mail_op)) {
2642 modest_platform_information_banner (GTK_WIDGET (source_win), NULL,
2643 _("mail_in_ui_folder_create_error"));
2646 do_create_folder (source_win, parent_folder, (const gchar *) suggested_name);
2648 /* the 'source_win' is either the ModestMainWindow, or the 'Move to folder'-dialog
2649 * FIXME: any other? */
2650 GtkWidget *folder_view;
2652 if (MODEST_IS_MAIN_WINDOW(source_win))
2654 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (source_win),
2655 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2658 get_folder_view_from_move_to_dialog (GTK_WIDGET(source_win));
2660 /* Select the newly created folder */
2661 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view),
2663 g_object_unref (new_folder);
2665 /* Free. Note that the first time it'll be NULL so noop */
2666 g_free (suggested_name);
2667 g_object_unref (source_win);
2671 do_create_folder (GtkWindow *parent_window,
2672 TnyFolderStore *parent_folder,
2673 const gchar *suggested_name)
2676 gchar *folder_name = NULL;
2678 result = modest_platform_run_new_folder_dialog (GTK_WINDOW (parent_window),
2680 (gchar *) suggested_name,
2683 if (result == GTK_RESPONSE_ACCEPT) {
2684 ModestMailOperation *mail_op;
2686 mail_op = modest_mail_operation_new (G_OBJECT(parent_window));
2688 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
2690 modest_mail_operation_create_folder (mail_op,
2692 (const gchar *) folder_name,
2693 do_create_folder_cb,
2695 g_object_unref (mail_op);
2700 create_folder_performer (gboolean canceled,
2702 GtkWindow *parent_window,
2703 TnyAccount *account,
2706 TnyFolderStore *parent_folder = TNY_FOLDER_STORE (user_data);
2708 if (canceled || err) {
2712 /* Run the new folder dialog */
2713 do_create_folder (GTK_WINDOW (parent_window), parent_folder, NULL);
2716 g_object_unref (parent_folder);
2720 modest_ui_actions_create_folder(GtkWidget *parent_window,
2721 GtkWidget *folder_view)
2723 TnyFolderStore *parent_folder;
2725 parent_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
2727 if (parent_folder) {
2728 /* The parent folder will be freed in the callback */
2729 modest_platform_connect_if_remote_and_perform (GTK_WINDOW (parent_window),
2732 create_folder_performer,
2738 modest_ui_actions_on_new_folder (GtkAction *action, ModestMainWindow *main_window)
2740 GtkWidget *folder_view;
2742 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2744 folder_view = modest_main_window_get_child_widget (main_window,
2745 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2749 modest_ui_actions_create_folder (GTK_WIDGET (main_window), folder_view);
2753 modest_ui_actions_rename_folder_error_handler (ModestMailOperation *mail_op,
2756 ModestMainWindow *window = MODEST_MAIN_WINDOW (user_data);
2757 const GError *error = NULL;
2758 const gchar *message = NULL;
2760 /* Get error message */
2761 error = modest_mail_operation_get_error (mail_op);
2763 g_return_if_reached ();
2765 switch (error->code) {
2766 case MODEST_MAIL_OPERATION_ERROR_FOLDER_EXISTS:
2767 message = _CS("ckdg_ib_folder_already_exists");
2770 g_warning ("%s: BUG: unexpected error:[%d]: %s", __FUNCTION__,
2771 error->code, error->message);
2775 modest_platform_information_banner (GTK_WIDGET (window), NULL, message);
2779 TnyFolderStore *folder;
2784 on_rename_folder_cb (ModestMailOperation *mail_op,
2785 TnyFolder *new_folder,
2789 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (user_data),
2794 on_rename_folder_performer (gboolean canceled,
2796 GtkWindow *parent_window,
2797 TnyAccount *account,
2800 ModestMailOperation *mail_op = NULL;
2801 GtkTreeSelection *sel = NULL;
2802 GtkWidget *folder_view = NULL;
2803 RenameFolderInfo *data = (RenameFolderInfo*)user_data;
2805 if (!canceled && (err == NULL) && MODEST_IS_MAIN_WINDOW(parent_window)) {
2807 folder_view = modest_main_window_get_child_widget (
2808 MODEST_MAIN_WINDOW (parent_window),
2809 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2812 modest_mail_operation_new_with_error_handling (G_OBJECT(parent_window),
2813 modest_ui_actions_rename_folder_error_handler,
2814 parent_window, NULL);
2816 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
2819 /* Clear the headers view */
2820 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_view));
2821 gtk_tree_selection_unselect_all (sel);
2823 /* Actually rename the folder */
2824 modest_mail_operation_rename_folder (mail_op,
2825 TNY_FOLDER (data->folder),
2826 (const gchar *) (data->new_name),
2827 on_rename_folder_cb,
2831 g_object_unref (mail_op);
2832 g_free (data->new_name);
2837 modest_ui_actions_on_rename_folder (GtkAction *action,
2838 ModestMainWindow *main_window)
2840 TnyFolderStore *folder;
2841 GtkWidget *folder_view;
2842 GtkWidget *header_view;
2844 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2846 folder_view = modest_main_window_get_child_widget (main_window,
2847 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2851 header_view = modest_main_window_get_child_widget (main_window,
2852 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2857 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
2862 if (TNY_IS_FOLDER (folder)) {
2865 const gchar *current_name;
2866 TnyFolderStore *parent;
2867 gboolean do_rename = TRUE;
2869 current_name = tny_folder_get_name (TNY_FOLDER (folder));
2870 parent = tny_folder_get_folder_store (TNY_FOLDER (folder));
2871 response = modest_platform_run_rename_folder_dialog (GTK_WINDOW (main_window),
2872 parent, current_name,
2874 g_object_unref (parent);
2876 if (response != GTK_RESPONSE_ACCEPT || strlen (folder_name) == 0) {
2879 RenameFolderInfo *rename_folder_data = g_new0 (RenameFolderInfo, 1);
2880 rename_folder_data->folder = folder;
2881 rename_folder_data->new_name = folder_name;
2882 modest_platform_connect_if_remote_and_perform (GTK_WINDOW(main_window), TRUE,
2883 folder, on_rename_folder_performer, rename_folder_data);
2886 g_object_unref (folder);
2890 modest_ui_actions_delete_folder_error_handler (ModestMailOperation *mail_op,
2893 GObject *win = modest_mail_operation_get_source (mail_op);
2895 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
2896 _("mail_in_ui_folder_delete_error"));
2897 g_object_unref (win);
2901 TnyFolderStore *folder;
2902 gboolean move_to_trash;
2906 on_delete_folder_cb (gboolean canceled,
2908 GtkWindow *parent_window,
2909 TnyAccount *account,
2912 DeleteFolderInfo *info = (DeleteFolderInfo*) user_data;
2913 GtkWidget *folder_view;
2914 ModestMailOperation *mail_op;
2915 GtkTreeSelection *sel;
2917 if (!MODEST_IS_MAIN_WINDOW(parent_window) || canceled || (err!=NULL)) {
2918 g_object_unref (G_OBJECT (info->folder));
2922 folder_view = modest_main_window_get_child_widget (
2923 MODEST_MAIN_WINDOW (parent_window),
2924 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2926 /* Unselect the folder before deleting it to free the headers */
2927 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_view));
2928 gtk_tree_selection_unselect_all (sel);
2930 /* Create the mail operation */
2932 modest_mail_operation_new_with_error_handling (G_OBJECT(parent_window),
2933 modest_ui_actions_delete_folder_error_handler,
2936 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
2938 modest_mail_operation_remove_folder (mail_op, TNY_FOLDER (info->folder), info->move_to_trash);
2940 modest_folder_view_select_first_inbox_or_local (MODEST_FOLDER_VIEW (folder_view));
2942 g_object_unref (G_OBJECT (mail_op));
2943 g_object_unref (G_OBJECT (info->folder));
2948 delete_folder (ModestMainWindow *main_window, gboolean move_to_trash)
2950 TnyFolderStore *folder;
2951 GtkWidget *folder_view;
2955 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2957 folder_view = modest_main_window_get_child_widget (main_window,
2958 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2962 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
2964 /* Show an error if it's an account */
2965 if (!TNY_IS_FOLDER (folder)) {
2966 modest_platform_run_information_dialog (GTK_WINDOW (main_window),
2967 _("mail_in_ui_folder_delete_error"));
2968 g_object_unref (G_OBJECT (folder));
2973 message = g_strdup_printf (_("mcen_nc_delete_folder_text"),
2974 tny_folder_get_name (TNY_FOLDER (folder)));
2975 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (main_window),
2976 (const gchar *) message);
2979 if (response == GTK_RESPONSE_OK) {
2980 DeleteFolderInfo *info;
2981 info = g_new0(DeleteFolderInfo, 1);
2982 info->folder = folder;
2983 info->move_to_trash = move_to_trash;
2984 g_object_ref (G_OBJECT (info->folder));
2985 TnyAccount *account = tny_folder_get_account (TNY_FOLDER (folder));
2986 modest_platform_connect_if_remote_and_perform (GTK_WINDOW (main_window),
2988 TNY_FOLDER_STORE (account),
2989 on_delete_folder_cb, info);
2990 g_object_unref (account);
2992 g_object_unref (G_OBJECT (folder));
2996 modest_ui_actions_on_delete_folder (GtkAction *action,
2997 ModestMainWindow *main_window)
2999 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
3001 delete_folder (main_window, FALSE);
3005 modest_ui_actions_on_move_folder_to_trash_folder (GtkAction *action, ModestMainWindow *main_window)
3007 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
3009 delete_folder (main_window, TRUE);
3014 show_error (GtkWidget *parent_widget, const gchar* text)
3016 modest_platform_information_banner(parent_widget, NULL, text);
3019 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_window, text)); */
3021 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
3028 gtk_dialog_run (dialog);
3029 gtk_widget_destroy (GTK_WIDGET (dialog));
3034 modest_ui_actions_on_password_requested (TnyAccountStore *account_store,
3035 const gchar* server_account_name,
3040 ModestMainWindow *main_window)
3042 g_return_if_fail(server_account_name);
3044 /* Initalize output parameters: */
3051 #ifdef MODEST_PLATFORM_MAEMO
3052 /* Maemo uses a different (awkward) button order,
3053 * It should probably just use gtk_alternative_dialog_button_order ().
3055 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
3058 _("mcen_bd_dialog_ok"),
3059 GTK_RESPONSE_ACCEPT,
3060 _("mcen_bd_dialog_cancel"),
3061 GTK_RESPONSE_REJECT,
3064 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
3068 GTK_RESPONSE_REJECT,
3070 GTK_RESPONSE_ACCEPT,
3072 #endif /* MODEST_PLATFORM_MAEMO */
3074 modest_window_mgr_set_modal (modest_runtime_get_window_mgr(), GTK_WINDOW (dialog));
3076 gchar *server_name = modest_account_mgr_get_server_account_hostname (
3077 modest_runtime_get_account_mgr(), server_account_name);
3078 if (!server_name) {/* This happened once, though I don't know why. murrayc. */
3079 g_warning("%s: Could not get server name for server account '%s'", __FUNCTION__, server_account_name);
3085 /* This causes a warning because the logical ID has no %s in it,
3086 * though the translation does, but there is not much we can do about that: */
3087 gchar *txt = g_strdup_printf (_("mail_ia_password_info"), server_name);
3088 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), gtk_label_new(txt),
3091 g_free (server_name);
3095 gchar *initial_username = modest_account_mgr_get_server_account_username (
3096 modest_runtime_get_account_mgr(), server_account_name);
3098 GtkWidget *entry_username = gtk_entry_new ();
3099 if (initial_username)
3100 gtk_entry_set_text (GTK_ENTRY (entry_username), initial_username);
3101 /* Dim this if a connection has ever succeeded with this username,
3102 * as per the UI spec: */
3103 const gboolean username_known =
3104 modest_account_mgr_get_server_account_username_has_succeeded(
3105 modest_runtime_get_account_mgr(), server_account_name);
3106 gtk_widget_set_sensitive (entry_username, !username_known);
3108 #ifdef MODEST_PLATFORM_MAEMO
3109 /* Auto-capitalization is the default, so let's turn it off: */
3110 hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_username), HILDON_GTK_INPUT_MODE_FULL);
3112 /* Create a size group to be used by all captions.
3113 * Note that HildonCaption does not create a default size group if we do not specify one.
3114 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
3115 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
3117 GtkWidget *caption = hildon_caption_new (sizegroup,
3118 _("mail_fi_username"), entry_username, NULL, HILDON_CAPTION_MANDATORY);
3119 gtk_widget_show (entry_username);
3120 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
3121 FALSE, FALSE, MODEST_MARGIN_HALF);
3122 gtk_widget_show (caption);
3124 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry_username,
3126 #endif /* MODEST_PLATFORM_MAEMO */
3129 GtkWidget *entry_password = gtk_entry_new ();
3130 gtk_entry_set_visibility (GTK_ENTRY(entry_password), FALSE);
3131 /* gtk_entry_set_invisible_char (GTK_ENTRY(entry_password), "*"); */
3133 #ifdef MODEST_PLATFORM_MAEMO
3134 /* Auto-capitalization is the default, so let's turn it off: */
3135 hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_password),
3136 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
3138 caption = hildon_caption_new (sizegroup,
3139 _("mail_fi_password"), entry_password, NULL, HILDON_CAPTION_MANDATORY);
3140 gtk_widget_show (entry_password);
3141 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
3142 FALSE, FALSE, MODEST_MARGIN_HALF);
3143 gtk_widget_show (caption);
3144 g_object_unref (sizegroup);
3146 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry_password,
3148 #endif /* MODEST_PLATFORM_MAEMO */
3150 if (initial_username != NULL)
3151 gtk_widget_grab_focus (GTK_WIDGET (entry_password));
3153 /* This is not in the Maemo UI spec:
3154 remember_pass_check = gtk_check_button_new_with_label (_("Remember password"));
3155 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), remember_pass_check,
3159 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
3161 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
3163 *username = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_username)));
3165 modest_account_mgr_set_server_account_username (
3166 modest_runtime_get_account_mgr(), server_account_name,
3169 const gboolean username_was_changed =
3170 (strcmp (*username, initial_username) != 0);
3171 if (username_was_changed) {
3172 g_warning ("%s: tinymail does not yet support changing the "
3173 "username in the get_password() callback.\n", __FUNCTION__);
3178 *password = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_password)));
3180 /* We do not save the password in the configuration,
3181 * because this function is only called for passwords that should
3182 * not be remembered:
3183 modest_server_account_set_password (
3184 modest_runtime_get_account_mgr(), server_account_name,
3193 show_error(GTK_WIDGET (main_window), _("mail_ib_login_cancelled"));
3205 /* This is not in the Maemo UI spec:
3206 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (remember_pass_check)))
3212 gtk_widget_destroy (dialog);
3214 /* printf ("DEBUG: %s: cancel=%d\n", __FUNCTION__, *cancel); */
3218 modest_ui_actions_on_cut (GtkAction *action,
3219 ModestWindow *window)
3221 GtkWidget *focused_widget;
3222 GtkClipboard *clipboard;
3224 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
3225 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
3226 if (GTK_IS_EDITABLE (focused_widget)) {
3227 gtk_editable_cut_clipboard (GTK_EDITABLE(focused_widget));
3228 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3229 gtk_clipboard_store (clipboard);
3230 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
3231 GtkTextBuffer *buffer;
3233 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
3234 gtk_text_buffer_cut_clipboard (buffer, clipboard, TRUE);
3235 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3236 gtk_clipboard_store (clipboard);
3237 } else if (MODEST_IS_HEADER_VIEW (focused_widget)) {
3238 TnyList *header_list = modest_header_view_get_selected_headers (
3239 MODEST_HEADER_VIEW (focused_widget));
3240 gboolean continue_download = FALSE;
3241 gint num_of_unc_msgs;
3243 num_of_unc_msgs = header_list_count_uncached_msgs(header_list);
3245 if (num_of_unc_msgs) {
3246 TnyAccount *account = get_account_from_header_list (header_list);
3247 continue_download = connect_to_get_msg (window, num_of_unc_msgs, account);
3248 g_object_unref (account);
3251 if (num_of_unc_msgs == 0 || continue_download) {
3252 /* modest_platform_information_banner (
3253 NULL, NULL, _CS("mcen_ib_getting_items"));*/
3254 modest_header_view_cut_selection (
3255 MODEST_HEADER_VIEW (focused_widget));
3258 g_object_unref (header_list);
3259 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
3260 modest_folder_view_cut_selection (MODEST_FOLDER_VIEW (focused_widget));
3265 modest_ui_actions_on_copy (GtkAction *action,
3266 ModestWindow *window)
3268 GtkClipboard *clipboard;
3269 GtkWidget *focused_widget;
3270 gboolean copied = TRUE;
3272 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
3273 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
3275 if (GTK_IS_LABEL (focused_widget)) {
3276 gtk_clipboard_set_text (clipboard, gtk_label_get_text (GTK_LABEL (focused_widget)), -1);
3277 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3278 gtk_clipboard_store (clipboard);
3279 } else if (GTK_IS_EDITABLE (focused_widget)) {
3280 gtk_editable_copy_clipboard (GTK_EDITABLE(focused_widget));
3281 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3282 gtk_clipboard_store (clipboard);
3283 } else if (GTK_IS_HTML (focused_widget)) {
3284 gtk_html_copy (GTK_HTML (focused_widget));
3285 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3286 gtk_clipboard_store (clipboard);
3287 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
3288 GtkTextBuffer *buffer;
3289 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
3290 gtk_text_buffer_copy_clipboard (buffer, clipboard);
3291 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3292 gtk_clipboard_store (clipboard);
3293 } else if (MODEST_IS_HEADER_VIEW (focused_widget)) {
3294 TnyList *header_list = modest_header_view_get_selected_headers (
3295 MODEST_HEADER_VIEW (focused_widget));
3296 gboolean continue_download = FALSE;
3297 gint num_of_unc_msgs;
3299 num_of_unc_msgs = header_list_count_uncached_msgs(header_list);
3301 if (num_of_unc_msgs) {
3302 TnyAccount *account = get_account_from_header_list (header_list);
3303 continue_download = connect_to_get_msg (window, num_of_unc_msgs, account);
3304 g_object_unref (account);
3307 if (num_of_unc_msgs == 0 || continue_download) {
3308 modest_platform_information_banner (
3309 NULL, NULL, _CS("mcen_ib_getting_items"));
3310 modest_header_view_copy_selection (
3311 MODEST_HEADER_VIEW (focused_widget));
3315 g_object_unref (header_list);
3317 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
3318 modest_folder_view_copy_selection (MODEST_FOLDER_VIEW (focused_widget));
3321 /* Show information banner if there was a copy to clipboard */
3323 modest_platform_information_banner (
3324 NULL, NULL, _CS("ecoc_ib_edwin_copied"));
3328 modest_ui_actions_on_undo (GtkAction *action,
3329 ModestWindow *window)
3331 ModestEmailClipboard *clipboard = NULL;
3333 if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
3334 modest_msg_edit_window_undo (MODEST_MSG_EDIT_WINDOW (window));
3335 } else if (MODEST_IS_MAIN_WINDOW (window)) {
3336 /* Clear clipboard source */
3337 clipboard = modest_runtime_get_email_clipboard ();
3338 modest_email_clipboard_clear (clipboard);
3341 g_return_if_reached ();
3346 modest_ui_actions_on_redo (GtkAction *action,
3347 ModestWindow *window)
3349 if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
3350 modest_msg_edit_window_redo (MODEST_MSG_EDIT_WINDOW (window));
3353 g_return_if_reached ();
3359 destroy_information_note (ModestMailOperation *mail_op,
3362 /* destroy information note */
3363 gtk_widget_destroy (GTK_WIDGET(user_data));
3367 destroy_folder_information_note (ModestMailOperation *mail_op,
3368 TnyFolder *new_folder,
3371 /* destroy information note */
3372 gtk_widget_destroy (GTK_WIDGET(user_data));
3377 paste_as_attachment_free (gpointer data)
3379 PasteAsAttachmentHelper *helper = (PasteAsAttachmentHelper *) data;
3381 gtk_widget_destroy (helper->banner);
3382 g_object_unref (helper->banner);
3387 paste_msg_as_attachment_cb (ModestMailOperation *mail_op,
3392 PasteAsAttachmentHelper *helper = (PasteAsAttachmentHelper *) userdata;
3393 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (helper->window));
3398 modest_msg_edit_window_add_part (MODEST_MSG_EDIT_WINDOW (helper->window), TNY_MIME_PART (msg));
3403 modest_ui_actions_on_paste (GtkAction *action,
3404 ModestWindow *window)
3406 GtkWidget *focused_widget = NULL;
3407 GtkWidget *inf_note = NULL;
3408 ModestMailOperation *mail_op = NULL;
3410 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
3411 if (GTK_IS_EDITABLE (focused_widget)) {
3412 gtk_editable_paste_clipboard (GTK_EDITABLE(focused_widget));
3413 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
3414 ModestEmailClipboard *e_clipboard = NULL;
3415 e_clipboard = modest_runtime_get_email_clipboard ();
3416 if (modest_email_clipboard_cleared (e_clipboard)) {
3417 GtkTextBuffer *buffer;
3418 GtkClipboard *clipboard;
3420 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
3421 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
3422 gtk_text_buffer_paste_clipboard (buffer, clipboard, NULL, TRUE);
3423 } else if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
3424 ModestMailOperation *mail_op;
3425 TnyFolder *src_folder;
3428 PasteAsAttachmentHelper *helper = g_new0 (PasteAsAttachmentHelper, 1);
3429 helper->window = MODEST_MSG_EDIT_WINDOW (window);
3430 helper->banner = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
3431 _CS("ckct_nw_pasting"));
3432 modest_email_clipboard_get_data (e_clipboard, &src_folder, &data, &delete);
3433 mail_op = modest_mail_operation_new (G_OBJECT (window));
3434 if (helper->banner != NULL) {
3435 g_object_ref (G_OBJECT (helper->banner));
3436 gtk_window_set_modal (GTK_WINDOW (helper->banner), FALSE);
3437 gtk_widget_show (GTK_WIDGET (helper->banner));
3441 modest_mail_operation_get_msgs_full (mail_op,
3443 (GetMsgAsyncUserCallback) paste_msg_as_attachment_cb,
3445 paste_as_attachment_free);
3448 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
3449 ModestEmailClipboard *clipboard = NULL;
3450 TnyFolder *src_folder = NULL;
3451 TnyFolderStore *folder_store = NULL;
3452 TnyList *data = NULL;
3453 gboolean delete = FALSE;
3455 /* Check clipboard source */
3456 clipboard = modest_runtime_get_email_clipboard ();
3457 if (modest_email_clipboard_cleared (clipboard))
3460 /* Get elements to paste */
3461 modest_email_clipboard_get_data (clipboard, &src_folder, &data, &delete);
3463 /* Create a new mail operation */
3464 mail_op = modest_mail_operation_new (G_OBJECT(window));
3466 /* Get destination folder */
3467 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (focused_widget));
3469 /* transfer messages */
3473 /* Ask for user confirmation */
3475 modest_ui_actions_msgs_move_to_confirmation (window,
3476 TNY_FOLDER (folder_store),
3480 if (response == GTK_RESPONSE_OK) {
3481 /* Launch notification */
3482 inf_note = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
3483 _CS("ckct_nw_pasting"));
3484 if (inf_note != NULL) {
3485 gtk_window_set_modal (GTK_WINDOW(inf_note), FALSE);
3486 gtk_widget_show (GTK_WIDGET(inf_note));
3489 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
3490 modest_mail_operation_xfer_msgs (mail_op,
3492 TNY_FOLDER (folder_store),
3494 destroy_information_note,
3497 g_object_unref (mail_op);
3500 } else if (src_folder != NULL) {
3501 /* Launch notification */
3502 inf_note = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
3503 _CS("ckct_nw_pasting"));
3504 if (inf_note != NULL) {
3505 gtk_window_set_modal (GTK_WINDOW(inf_note), FALSE);
3506 gtk_widget_show (GTK_WIDGET(inf_note));
3509 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
3510 modest_mail_operation_xfer_folder (mail_op,
3514 destroy_folder_information_note,
3520 g_object_unref (data);
3521 if (src_folder != NULL)
3522 g_object_unref (src_folder);
3523 if (folder_store != NULL)
3524 g_object_unref (folder_store);
3530 modest_ui_actions_on_select_all (GtkAction *action,
3531 ModestWindow *window)
3533 GtkWidget *focused_widget;
3535 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
3536 if (MODEST_IS_ATTACHMENTS_VIEW (focused_widget)) {
3537 modest_attachments_view_select_all (MODEST_ATTACHMENTS_VIEW (focused_widget));
3538 } else if (GTK_IS_LABEL (focused_widget)) {
3539 gtk_label_select_region (GTK_LABEL (focused_widget), 0, -1);
3540 } else if (GTK_IS_EDITABLE (focused_widget)) {
3541 gtk_editable_select_region (GTK_EDITABLE(focused_widget), 0, -1);
3542 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
3543 GtkTextBuffer *buffer;
3544 GtkTextIter start, end;
3546 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
3547 gtk_text_buffer_get_start_iter (buffer, &start);
3548 gtk_text_buffer_get_end_iter (buffer, &end);
3549 gtk_text_buffer_select_range (buffer, &start, &end);
3550 } else if (GTK_IS_HTML (focused_widget)) {
3551 gtk_html_select_all (GTK_HTML (focused_widget));
3552 } else if (MODEST_IS_MAIN_WINDOW (window)) {
3553 GtkWidget *header_view = focused_widget;
3554 GtkTreeSelection *selection = NULL;
3556 if (!(MODEST_IS_HEADER_VIEW (focused_widget))) {
3557 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (window),
3558 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
3561 /* Disable window dimming management */
3562 modest_window_disable_dimming (MODEST_WINDOW(window));
3564 /* Select all messages */
3565 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(header_view));
3566 gtk_tree_selection_select_all (selection);
3568 /* Set focuse on header view */
3569 gtk_widget_grab_focus (header_view);
3572 /* Enable window dimming management */
3573 modest_window_enable_dimming (MODEST_WINDOW(window));
3574 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (window));
3580 modest_ui_actions_on_mark_as_read (GtkAction *action,
3581 ModestWindow *window)
3583 g_return_if_fail (MODEST_IS_WINDOW(window));
3585 /* Mark each header as read */
3586 do_headers_action (window, headers_action_mark_as_read, NULL);
3590 modest_ui_actions_on_mark_as_unread (GtkAction *action,
3591 ModestWindow *window)
3593 g_return_if_fail (MODEST_IS_WINDOW(window));
3595 /* Mark each header as read */
3596 do_headers_action (window, headers_action_mark_as_unread, NULL);
3600 modest_ui_actions_on_change_zoom (GtkRadioAction *action,
3601 GtkRadioAction *selected,
3602 ModestWindow *window)
3606 value = gtk_radio_action_get_current_value (selected);
3607 if (MODEST_IS_WINDOW (window)) {
3608 modest_window_set_zoom (MODEST_WINDOW (window), ((gdouble)value)/100);
3613 modest_ui_actions_msg_edit_on_change_priority (GtkRadioAction *action,
3614 GtkRadioAction *selected,
3615 ModestWindow *window)
3617 TnyHeaderFlags flags;
3618 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3620 flags = gtk_radio_action_get_current_value (selected);
3621 modest_msg_edit_window_set_priority_flags (MODEST_MSG_EDIT_WINDOW (window), flags);
3625 modest_ui_actions_msg_edit_on_change_file_format (GtkRadioAction *action,
3626 GtkRadioAction *selected,
3627 ModestWindow *window)
3631 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3633 file_format = gtk_radio_action_get_current_value (selected);
3634 modest_msg_edit_window_set_file_format (MODEST_MSG_EDIT_WINDOW (window), file_format);
3639 modest_ui_actions_on_zoom_plus (GtkAction *action,
3640 ModestWindow *window)
3642 g_return_if_fail (MODEST_IS_WINDOW (window));
3644 modest_window_zoom_plus (MODEST_WINDOW (window));
3648 modest_ui_actions_on_zoom_minus (GtkAction *action,
3649 ModestWindow *window)
3651 g_return_if_fail (MODEST_IS_WINDOW (window));
3653 modest_window_zoom_minus (MODEST_WINDOW (window));
3657 modest_ui_actions_on_toggle_fullscreen (GtkToggleAction *toggle,
3658 ModestWindow *window)
3660 ModestWindowMgr *mgr;
3661 gboolean fullscreen, active;
3662 g_return_if_fail (MODEST_IS_WINDOW (window));
3664 mgr = modest_runtime_get_window_mgr ();
3666 active = (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle)))?1:0;
3667 fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
3669 if (active != fullscreen) {
3670 modest_window_mgr_set_fullscreen_mode (mgr, active);
3671 gtk_window_present (GTK_WINDOW (window));
3676 modest_ui_actions_on_change_fullscreen (GtkAction *action,
3677 ModestWindow *window)
3679 ModestWindowMgr *mgr;
3680 gboolean fullscreen;
3682 g_return_if_fail (MODEST_IS_WINDOW (window));
3684 mgr = modest_runtime_get_window_mgr ();
3685 fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
3686 modest_window_mgr_set_fullscreen_mode (mgr, !fullscreen);
3688 gtk_window_present (GTK_WINDOW (window));
3692 * Used by modest_ui_actions_on_details to call do_headers_action
3695 headers_action_show_details (TnyHeader *header,
3696 ModestWindow *window,
3703 dialog = modest_details_dialog_new_with_header (GTK_WINDOW (window), header);
3706 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
3707 gtk_widget_show_all (dialog);
3708 gtk_dialog_run (GTK_DIALOG (dialog));
3710 gtk_widget_destroy (dialog);
3714 * Show the folder details in a ModestDetailsDialog widget
3717 show_folder_details (TnyFolder *folder,
3723 dialog = modest_details_dialog_new_with_folder (window, folder);
3726 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
3727 gtk_widget_show_all (dialog);
3728 gtk_dialog_run (GTK_DIALOG (dialog));
3730 gtk_widget_destroy (dialog);
3734 * Show the header details in a ModestDetailsDialog widget
3737 modest_ui_actions_on_details (GtkAction *action,
3740 TnyList * headers_list;
3744 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
3747 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW (win));
3750 g_object_unref (msg);
3752 headers_list = get_selected_headers (win);
3756 iter = tny_list_create_iterator (headers_list);
3758 header = TNY_HEADER (tny_iterator_get_current (iter));
3760 headers_action_show_details (header, win, NULL);
3761 g_object_unref (header);
3764 g_object_unref (iter);
3765 g_object_unref (headers_list);
3767 } else if (MODEST_IS_MAIN_WINDOW (win)) {
3768 GtkWidget *folder_view, *header_view;
3770 /* Check which widget has the focus */
3771 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
3772 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3773 if (gtk_widget_is_focus (folder_view)) {
3774 TnyFolderStore *folder_store
3775 = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
3776 if (!folder_store) {
3777 g_warning ("%s: No item was selected.\n", __FUNCTION__);
3780 /* Show only when it's a folder */
3781 /* This function should not be called for account items,
3782 * because we dim the menu item for them. */
3783 if (TNY_IS_FOLDER (folder_store)) {
3784 show_folder_details (TNY_FOLDER (folder_store), GTK_WINDOW (win));
3787 g_object_unref (folder_store);
3790 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
3791 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
3792 /* Show details of each header */
3793 do_headers_action (win, headers_action_show_details, header_view);
3799 modest_ui_actions_on_toggle_show_cc (GtkToggleAction *toggle,
3800 ModestMsgEditWindow *window)
3802 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3804 modest_msg_edit_window_show_cc (window, gtk_toggle_action_get_active (toggle));
3808 modest_ui_actions_on_toggle_show_bcc (GtkToggleAction *toggle,
3809 ModestMsgEditWindow *window)
3811 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3813 modest_msg_edit_window_show_bcc (window, gtk_toggle_action_get_active (toggle));
3817 modest_ui_actions_toggle_folders_view (GtkAction *action,
3818 ModestMainWindow *main_window)
3820 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
3822 if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)))
3823 modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SPLIT);
3825 modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SIMPLE);
3829 modest_ui_actions_on_toggle_toolbar (GtkToggleAction *toggle,
3830 ModestWindow *window)
3832 gboolean active, fullscreen = FALSE;
3833 ModestWindowMgr *mgr;
3835 active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle));
3837 /* Check if we want to toggle the toolbar vuew in fullscreen
3839 if (!strcmp (gtk_action_get_name (GTK_ACTION (toggle)),
3840 "ViewShowToolbarFullScreen")) {
3844 /* Toggle toolbar */
3845 mgr = modest_runtime_get_window_mgr ();
3846 modest_window_mgr_show_toolbars (mgr, G_TYPE_FROM_INSTANCE (window), active, fullscreen);
3850 modest_ui_actions_msg_edit_on_select_font (GtkAction *action,
3851 ModestMsgEditWindow *window)
3853 modest_msg_edit_window_select_font (window);
3858 modest_ui_actions_on_folder_display_name_changed (ModestFolderView *folder_view,
3859 const gchar *display_name,
3862 /* don't update the display name if it was already set;
3863 * updating the display name apparently is expensive */
3864 const gchar* old_name = gtk_window_get_title (window);
3866 if (display_name == NULL)
3869 if (old_name && display_name && strcmp (old_name, display_name) == 0)
3870 return; /* don't do anything */
3872 /* This is usually used to change the title of the main window, which
3873 * is the one that holds the folder view. Note that this change can
3874 * happen even when the widget doesn't have the focus. */
3875 gtk_window_set_title (window, display_name);
3880 modest_ui_actions_on_select_contacts (GtkAction *action, ModestMsgEditWindow *window)
3882 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3883 modest_msg_edit_window_select_contacts (window);
3887 modest_ui_actions_on_check_names (GtkAction *action, ModestMsgEditWindow *window)
3889 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3890 modest_msg_edit_window_check_names (window, FALSE);
3894 create_move_to_dialog_on_new_folder(GtkWidget *button, gpointer user_data)
3896 modest_ui_actions_create_folder (gtk_widget_get_toplevel (button),
3897 GTK_WIDGET (user_data));
3901 * This function is used to track changes in the selection of the
3902 * folder view that is inside the "move to" dialog to enable/disable
3903 * the OK button because we do not want the user to select a disallowed
3904 * destination for a folder.
3905 * The user also not desired to be able to use NEW button on items where
3906 * folder creation is not possibel.
3909 on_move_to_dialog_folder_selection_changed (ModestFolderView* self,
3910 TnyFolderStore *folder_store,
3914 GtkWidget *dialog = NULL;
3915 GtkWidget *ok_button = NULL, *new_button = NULL;
3916 GList *children = NULL;
3917 gboolean ok_sensitive = TRUE, new_sensitive = TRUE;
3918 gboolean moving_folder = FALSE;
3919 gboolean is_local_account = TRUE;
3920 GtkWidget *folder_view = NULL;
3921 ModestTnyFolderRules rules;
3926 /* Get the OK button */
3927 dialog = gtk_widget_get_ancestor (GTK_WIDGET (self), GTK_TYPE_DIALOG);
3931 children = gtk_container_get_children (GTK_CONTAINER (GTK_DIALOG (dialog)->action_area));
3932 ok_button = GTK_WIDGET (children->next->next->data);
3933 new_button = GTK_WIDGET (children->next->data);
3934 g_list_free (children);
3936 /* check if folder_store is an remote account */
3937 if (TNY_IS_ACCOUNT (folder_store)) {
3938 TnyAccount *local_account = NULL;
3939 TnyAccount *mmc_account = NULL;
3940 ModestTnyAccountStore *account_store = NULL;
3942 account_store = modest_runtime_get_account_store ();
3943 local_account = modest_tny_account_store_get_local_folders_account (account_store);
3944 mmc_account = modest_tny_account_store_get_mmc_folders_account (account_store);
3946 if ((gpointer) local_account != (gpointer) folder_store &&
3947 (gpointer) mmc_account != (gpointer) folder_store) {
3948 is_local_account = FALSE;
3949 /* New button should be dimmed on remote
3951 new_sensitive = FALSE;
3953 g_object_unref (local_account);
3956 /* Check the target folder rules */
3957 if (TNY_IS_FOLDER (folder_store)) {
3958 rules = modest_tny_folder_get_rules (TNY_FOLDER (folder_store));
3959 if (rules & MODEST_FOLDER_RULES_FOLDER_NON_WRITEABLE) {
3960 ok_sensitive = FALSE;
3961 new_sensitive = FALSE;
3966 /* Check if we're moving a folder */
3967 if (MODEST_IS_MAIN_WINDOW (user_data)) {
3968 /* Get the widgets */
3969 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (user_data),
3970 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3971 if (gtk_widget_is_focus (folder_view))
3972 moving_folder = TRUE;
3975 if (moving_folder) {
3976 TnyFolderStore *moved_folder = NULL, *parent = NULL;
3978 /* Get the folder to move */
3979 moved_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
3981 /* Check that we're not moving to the same folder */
3982 if (TNY_IS_FOLDER (moved_folder)) {
3983 parent = tny_folder_get_folder_store (TNY_FOLDER (moved_folder));
3984 if (parent == folder_store)
3985 ok_sensitive = FALSE;
3986 g_object_unref (parent);
3989 if (ok_sensitive && TNY_IS_ACCOUNT (folder_store)) {
3990 /* Do not allow to move to an account unless it's the
3991 local folders account */
3992 if (!is_local_account)
3993 ok_sensitive = FALSE;
3996 if (ok_sensitive && (moved_folder == folder_store)) {
3997 /* Do not allow to move to itself */
3998 ok_sensitive = FALSE;
4000 g_object_unref (moved_folder);
4002 TnyHeader *header = NULL;
4003 TnyFolder *src_folder = NULL;
4005 /* Moving a message */
4006 if (MODEST_IS_MSG_VIEW_WINDOW (user_data)) {
4007 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (user_data));
4008 src_folder = tny_header_get_folder (header);
4009 g_object_unref (header);
4012 TNY_FOLDER (modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view)));
4015 /* Do not allow to move the msg to the same folder */
4016 /* Do not allow to move the msg to an account */
4017 if ((gpointer) src_folder == (gpointer) folder_store ||
4018 TNY_IS_ACCOUNT (folder_store))
4019 ok_sensitive = FALSE;
4020 g_object_unref (src_folder);
4024 /* Set sensitivity of the OK button */
4025 gtk_widget_set_sensitive (ok_button, ok_sensitive);
4026 /* Set sensitivity of the NEW button */
4027 gtk_widget_set_sensitive (new_button, new_sensitive);
4031 #define MODEST_MOVE_TO_DIALOG_FOLDER_VIEW "move-to-dialog-folder-view"
4034 get_folder_view_from_move_to_dialog (GtkWidget *move_to_dialog)
4036 return GTK_WIDGET(g_object_get_data (G_OBJECT(move_to_dialog),
4037 MODEST_MOVE_TO_DIALOG_FOLDER_VIEW));
4041 create_move_to_dialog (GtkWindow *win,
4042 GtkWidget *folder_view,
4043 GtkWidget **tree_view)
4045 GtkWidget *dialog, *scroll;
4046 GtkWidget *new_button;
4048 dialog = gtk_dialog_new_with_buttons (_("mcen_ti_moveto_folders_title"),
4050 GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR | GTK_DIALOG_DESTROY_WITH_PARENT,
4053 gtk_dialog_add_button (GTK_DIALOG (dialog), _("mcen_bd_dialog_ok"), GTK_RESPONSE_ACCEPT);
4054 /* We do this manually so GTK+ does not associate a response ID for
4056 new_button = gtk_button_new_from_stock (_("mcen_bd_new"));
4057 gtk_box_pack_end (GTK_BOX (GTK_DIALOG (dialog)->action_area), new_button, FALSE, FALSE, 0);
4058 gtk_dialog_add_button (GTK_DIALOG (dialog), _("mcen_bd_dialog_cancel"), GTK_RESPONSE_REJECT);
4060 /* Create scrolled window */
4061 scroll = gtk_scrolled_window_new (NULL, NULL);
4062 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll),
4063 GTK_POLICY_AUTOMATIC,
4064 GTK_POLICY_AUTOMATIC);
4066 /* Create folder view */
4067 *tree_view = modest_platform_create_folder_view (NULL);
4069 /* Track changes in the selection to
4070 * disable the OK button whenever "Move to" is not possible
4071 * disbale NEW button whenever New is not possible */
4072 g_signal_connect (*tree_view,
4073 "folder_selection_changed",
4074 G_CALLBACK (on_move_to_dialog_folder_selection_changed),
4077 /* Listen to clicks on New button */
4078 g_signal_connect (G_OBJECT (new_button),
4080 G_CALLBACK(create_move_to_dialog_on_new_folder),
4083 /* It could happen that we're trying to move a message from a
4084 window (msg window for example) after the main window was
4085 closed, so we can not just get the model of the folder
4087 if (MODEST_IS_FOLDER_VIEW (folder_view)) {
4088 const gchar *visible_id = NULL;
4090 modest_folder_view_set_style (MODEST_FOLDER_VIEW (*tree_view),
4091 MODEST_FOLDER_VIEW_STYLE_SHOW_ALL);
4092 modest_folder_view_copy_model (MODEST_FOLDER_VIEW(folder_view),
4093 MODEST_FOLDER_VIEW(*tree_view));
4096 modest_folder_view_get_account_id_of_visible_server_account (MODEST_FOLDER_VIEW(folder_view));
4098 /* Show the same account than the one that is shown in the main window */
4099 modest_folder_view_set_account_id_of_visible_server_account (MODEST_FOLDER_VIEW(*tree_view),
4102 const gchar *active_account_name = NULL;
4103 ModestAccountMgr *mgr = NULL;
4104 ModestAccountSettings *settings = NULL;
4105 ModestServerAccountSettings *store_settings = NULL;
4107 modest_folder_view_set_style (MODEST_FOLDER_VIEW (*tree_view),
4108 MODEST_FOLDER_VIEW_STYLE_SHOW_ALL);
4109 modest_folder_view_update_model (MODEST_FOLDER_VIEW (*tree_view),
4110 TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()));
4112 active_account_name = modest_window_get_active_account (MODEST_WINDOW (win));
4113 mgr = modest_runtime_get_account_mgr ();
4114 settings = modest_account_mgr_load_account_settings (mgr, active_account_name);
4117 const gchar *store_account_name;
4118 store_settings = modest_account_settings_get_store_settings (settings);
4119 store_account_name = modest_server_account_settings_get_account_name (store_settings);
4121 modest_folder_view_set_account_id_of_visible_server_account (MODEST_FOLDER_VIEW (*tree_view),
4122 store_account_name);
4123 g_object_unref (store_settings);
4124 g_object_unref (settings);
4128 /* we keep a pointer to the embedded folder view, so we can retrieve it with
4129 * get_folder_view_from_move_to_dialog
4130 * (see above) later (needed for focus handling)
4132 g_object_set_data (G_OBJECT(dialog), MODEST_MOVE_TO_DIALOG_FOLDER_VIEW, *tree_view);
4135 /* Hide special folders */
4136 modest_folder_view_show_non_move_folders (MODEST_FOLDER_VIEW (*tree_view), FALSE);
4138 gtk_container_add (GTK_CONTAINER (scroll), *tree_view);
4140 /* Add scroll to dialog */
4141 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
4142 scroll, TRUE, TRUE, 0);
4144 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
4145 gtk_window_set_default_size (GTK_WINDOW (dialog), 300, 300);
4151 * Returns TRUE if at least one of the headers of the list belongs to
4152 * a message that has been fully retrieved.
4154 #if 0 /* no longer in use. delete in 2007.10 */
4156 has_retrieved_msgs (TnyList *list)
4159 gboolean found = FALSE;
4161 iter = tny_list_create_iterator (list);
4162 while (!tny_iterator_is_done (iter) && !found) {
4164 TnyHeaderFlags flags = 0;
4166 header = TNY_HEADER (tny_iterator_get_current (iter));
4168 flags = tny_header_get_flags (header);
4169 if (flags & TNY_HEADER_FLAG_CACHED)
4170 /* if (!(flags & TNY_HEADER_FLAG_PARTIAL)) */
4173 g_object_unref (header);
4177 tny_iterator_next (iter);
4179 g_object_unref (iter);
4187 * Shows a confirmation dialog to the user when we're moving messages
4188 * from a remote server to the local storage. Returns the dialog
4189 * response. If it's other kind of movement then it always returns
4192 * This one is used by the next functions:
4193 * modest_ui_actions_on_paste - commented out
4194 * drag_and_drop_from_header_view (for d&d in modest_folder_view.c)
4197 modest_ui_actions_msgs_move_to_confirmation (ModestWindow *win,
4198 TnyFolder *dest_folder,
4202 gint response = GTK_RESPONSE_OK;
4203 TnyAccount *account = NULL;
4204 TnyFolder *src_folder = NULL;
4205 TnyIterator *iter = NULL;
4206 TnyHeader *header = NULL;
4208 /* return with OK if the destination is a remote folder */
4209 if (modest_tny_folder_is_remote_folder (dest_folder))
4210 return GTK_RESPONSE_OK;
4212 /* Get source folder */
4213 iter = tny_list_create_iterator (headers);
4214 header = TNY_HEADER (tny_iterator_get_current (iter));
4216 src_folder = tny_header_get_folder (header);
4217 g_object_unref (header);
4219 g_object_unref (iter);
4221 /* if no src_folder, message may be an attahcment */
4222 if (src_folder == NULL)
4223 return GTK_RESPONSE_CANCEL;
4225 /* If the source is a local or MMC folder */
4226 if (!modest_tny_folder_is_remote_folder (src_folder)) {
4227 g_object_unref (src_folder);
4228 return GTK_RESPONSE_OK;
4231 /* Get the account */
4232 account = tny_folder_get_account (src_folder);
4234 /* now if offline we ask the user */
4235 if(connect_to_get_msg (win, tny_list_get_length (headers), account))
4236 response = GTK_RESPONSE_OK;
4238 response = GTK_RESPONSE_CANCEL;
4241 g_object_unref (src_folder);
4242 g_object_unref (account);
4248 move_to_cb (ModestMailOperation *mail_op,
4251 MoveToHelper *helper = (MoveToHelper *) user_data;
4253 /* Note that the operation could have failed, in that case do
4255 if (modest_mail_operation_get_status (mail_op) ==
4256 MODEST_MAIL_OPERATION_STATUS_SUCCESS) {
4258 GObject *object = modest_mail_operation_get_source (mail_op);
4259 if (MODEST_IS_MSG_VIEW_WINDOW (object)) {
4260 ModestMsgViewWindow *self = MODEST_MSG_VIEW_WINDOW (object);
4262 if (!modest_msg_view_window_select_next_message (self))
4263 if (!modest_msg_view_window_select_previous_message (self))
4264 /* No more messages to view, so close this window */
4265 modest_ui_actions_on_close_window (NULL, MODEST_WINDOW(self));
4266 } else if (MODEST_IS_MAIN_WINDOW (object) && helper->reference != NULL) {
4267 GtkWidget *header_view;
4269 GtkTreeSelection *sel;
4271 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(object),
4272 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
4273 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
4274 path = gtk_tree_row_reference_get_path (helper->reference);
4275 gtk_tree_selection_select_path (sel, path);
4276 gtk_tree_path_free (path);
4278 g_object_unref (object);
4281 /* Close the "Pasting" information banner */
4282 gtk_widget_destroy (GTK_WIDGET(helper->banner));
4283 if (helper->reference != NULL)
4284 gtk_tree_row_reference_free (helper->reference);
4289 folder_move_to_cb (ModestMailOperation *mail_op,
4290 TnyFolder *new_folder,
4293 move_to_cb (mail_op, user_data);
4297 msgs_move_to_cb (ModestMailOperation *mail_op,
4300 move_to_cb (mail_op, user_data);
4304 modest_ui_actions_move_folder_error_handler (ModestMailOperation *mail_op,
4307 ModestWindow *main_window = NULL;
4308 GObject *win = NULL;
4310 /* Disable next automatic folder selection */
4311 main_window = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (),
4312 FALSE); /* don't create */
4314 GtkWidget *folder_view = NULL;
4316 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (main_window),
4317 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
4318 modest_folder_view_disable_next_folder_selection (MODEST_FOLDER_VIEW(folder_view));
4320 if (user_data && TNY_IS_FOLDER (user_data)) {
4321 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view),
4322 TNY_FOLDER (user_data), FALSE);
4326 /* Show notification dialog */
4327 win = modest_mail_operation_get_source (mail_op);
4328 modest_platform_run_information_dialog ((GtkWindow *) win, _("mail_in_ui_folder_move_target_error"));
4330 g_object_unref (win);
4334 modest_ui_actions_send_receive_error_handler (ModestMailOperation *mail_op,
4337 GObject *win = modest_mail_operation_get_source (mail_op);
4338 const GError *error = modest_mail_operation_get_error (mail_op);
4340 g_return_if_fail (error != NULL);
4341 if (error->message != NULL)
4342 g_printerr ("modest: %s\n", error->message);
4344 g_printerr ("modest: unkonw error on send&receive operation");
4346 /* Show error message */
4347 /* if (modest_mail_operation_get_id (mail_op) == MODEST_MAIL_OPERATION_TYPE_RECEIVE) */
4348 /* modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL, */
4349 /* _CS("sfil_ib_unable_to_receive")); */
4351 /* modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL, */
4352 /* _CS("sfil_ib_unable_to_send")); */
4353 g_object_unref (win);
4357 open_msg_for_purge_cb (ModestMailOperation *mail_op,
4366 gint pending_purges = 0;
4367 gboolean some_purged = FALSE;
4368 ModestWindow *win = MODEST_WINDOW (user_data);
4369 ModestWindowMgr *mgr = modest_runtime_get_window_mgr ();
4371 /* If there was any error */
4372 if (!modest_ui_actions_msg_retrieval_check (mail_op, header, msg)) {
4373 modest_window_mgr_unregister_header (mgr, header);
4377 /* Once the message has been retrieved for purging, we check if
4378 * it's all ok for purging */
4380 parts = tny_simple_list_new ();
4381 tny_mime_part_get_parts (TNY_MIME_PART (msg), parts);
4382 iter = tny_list_create_iterator (parts);
4384 while (!tny_iterator_is_done (iter)) {
4386 part = TNY_MIME_PART (tny_iterator_get_current (iter));
4387 if (part && (tny_mime_part_is_attachment (part) || TNY_IS_MSG (part))) {
4388 if (tny_mime_part_is_purged (part))
4395 g_object_unref (part);
4397 tny_iterator_next (iter);
4399 g_object_unref (iter);
4402 if (pending_purges>0) {
4404 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),_("mcen_nc_purge_file_text_inbox"));
4406 if (response == GTK_RESPONSE_OK) {
4407 modest_platform_information_banner (NULL, NULL, _("mcen_ib_removing_attachment"));
4408 iter = tny_list_create_iterator (parts);
4409 while (!tny_iterator_is_done (iter)) {
4412 part = TNY_MIME_PART (tny_iterator_get_current (iter));
4413 if (part && (tny_mime_part_is_attachment (part) || TNY_IS_MSG (part)))
4414 tny_mime_part_set_purged (part);
4417 g_object_unref (part);
4419 tny_iterator_next (iter);
4422 tny_msg_rewrite_cache (msg);
4425 /* This string no longer exists, refer to NB#75415 for more info */
4426 /* modest_platform_information_banner (NULL, NULL, _("mail_ib_attachment_already_purged")); */
4428 g_object_unref (iter);
4430 modest_window_mgr_unregister_header (mgr, header);
4432 g_object_unref (parts);
4436 modest_ui_actions_on_main_window_remove_attachments (GtkAction *action,
4437 ModestMainWindow *win)
4439 GtkWidget *header_view;
4440 TnyList *header_list;
4443 TnyHeaderFlags flags;
4444 ModestWindow *msg_view_window = NULL;
4447 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win));
4449 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
4450 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
4452 header_list = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW (header_view));
4454 g_warning ("%s: no header selected", __FUNCTION__);
4458 if (tny_list_get_length (header_list) == 1) {
4459 iter = tny_list_create_iterator (header_list);
4460 header = TNY_HEADER (tny_iterator_get_current (iter));
4461 g_object_unref (iter);
4465 if (!header || !TNY_IS_HEADER(header)) {
4466 g_warning ("%s: header is not valid", __FUNCTION__);
4470 found = modest_window_mgr_find_registered_header (modest_runtime_get_window_mgr (),
4471 header, &msg_view_window);
4472 flags = tny_header_get_flags (header);
4473 if (!(flags & TNY_HEADER_FLAG_CACHED))
4476 if (msg_view_window != NULL)
4477 modest_msg_view_window_remove_attachments (MODEST_MSG_VIEW_WINDOW (msg_view_window), TRUE);
4479 /* do nothing; uid was registered before, so window is probably on it's way */
4480 g_warning ("debug: header %p has already been registered", header);
4483 ModestMailOperation *mail_op = NULL;
4484 modest_window_mgr_register_header (modest_runtime_get_window_mgr (), header, NULL);
4485 mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT (win),
4486 modest_ui_actions_get_msgs_full_error_handler,
4488 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
4489 modest_mail_operation_get_msg (mail_op, header, open_msg_for_purge_cb, win);
4491 g_object_unref (mail_op);
4494 g_object_unref (header);
4496 g_object_unref (header_list);
4500 * Utility function that transfer messages from both the main window
4501 * and the msg view window when using the "Move to" dialog
4504 xfer_messages_from_move_to_cb (gboolean canceled, GError *err,
4505 GtkWindow *parent_window,
4506 TnyAccount *account, gpointer user_data)
4508 TnyFolderStore *dst_folder = TNY_FOLDER_STORE (user_data);
4509 ModestWindow *win = MODEST_WINDOW (parent_window);
4510 TnyList *headers = NULL;
4511 TnyAccount *dst_account = NULL;
4512 const gchar *proto_str = NULL;
4513 gboolean dst_is_pop = FALSE;
4515 if (canceled || err) {
4516 g_object_unref (dst_folder);
4520 dst_account = tny_folder_get_account (TNY_FOLDER (dst_folder));
4521 proto_str = tny_account_get_proto (dst_account);
4523 /* tinymail will return NULL for local folders it seems */
4524 dst_is_pop = proto_str &&
4525 (modest_protocol_info_get_transport_store_protocol (proto_str) ==
4526 MODEST_PROTOCOL_STORE_POP);
4528 g_object_unref (dst_account);
4530 /* Get selected headers */
4531 headers = get_selected_headers (MODEST_WINDOW (win));
4533 g_warning ("%s: no headers selected", __FUNCTION__);
4539 modest_platform_information_banner (GTK_WIDGET (win),
4541 ngettext("mail_in_ui_folder_move_target_error",
4542 "mail_in_ui_folder_move_targets_error",
4543 tny_list_get_length (headers)));
4544 g_object_unref (headers);
4548 MoveToHelper *helper = g_new0 (MoveToHelper, 1);
4549 helper->banner = modest_platform_animation_banner (GTK_WIDGET (win), NULL,
4550 _CS("ckct_nw_pasting"));
4551 if (helper->banner != NULL) {
4552 gtk_window_set_modal (GTK_WINDOW(helper->banner), FALSE);
4553 gtk_widget_show (GTK_WIDGET(helper->banner));
4556 if (MODEST_IS_MAIN_WINDOW (win)) {
4557 GtkWidget *header_view =
4558 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
4559 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
4560 helper->reference = get_next_after_selected_headers (MODEST_HEADER_VIEW (header_view));
4563 ModestMailOperation *mail_op =
4564 modest_mail_operation_new_with_error_handling (G_OBJECT(win),
4565 modest_ui_actions_move_folder_error_handler,
4567 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
4570 modest_mail_operation_xfer_msgs (mail_op,
4572 TNY_FOLDER (dst_folder),
4577 g_object_unref (G_OBJECT (mail_op));
4578 g_object_unref (headers);
4579 g_object_unref (dst_folder);
4583 TnyAccount *dst_account;
4584 ModestConnectedPerformer callback;
4586 } DoubleConnectionInfo;
4589 src_account_connect_performer (gboolean canceled,
4591 GtkWindow *parent_window,
4592 TnyAccount *src_account,
4595 DoubleConnectionInfo *info = (DoubleConnectionInfo *) user_data;
4597 if (canceled || err) {
4598 /* If there was any error call the user callback */
4599 info->callback (canceled, err, parent_window, src_account, info->data);
4601 /* Connect the destination account */
4602 modest_platform_connect_if_remote_and_perform (parent_window, TRUE,
4603 TNY_FOLDER_STORE (info->dst_account),
4604 info->callback, info->data);
4607 /* Free the info object */
4608 g_object_unref (info->dst_account);
4609 g_slice_free (DoubleConnectionInfo, info);
4613 TnyFolder *src_folder;
4614 TnyFolderStore *dst_folder;
4615 gboolean delete_original;
4616 GtkWidget *folder_view;
4620 on_move_folder_cb (gboolean canceled, GError *err, GtkWindow *parent_window,
4621 TnyAccount *account, gpointer user_data)
4623 MoveFolderInfo *info = (MoveFolderInfo*)user_data;
4624 GtkTreeSelection *sel;
4625 ModestMailOperation *mail_op = NULL;
4627 if (canceled || err || !MODEST_IS_MAIN_WINDOW (parent_window)) {
4628 g_object_unref (G_OBJECT (info->src_folder));
4629 g_object_unref (G_OBJECT (info->dst_folder));
4634 MoveToHelper *helper = g_new0 (MoveToHelper, 1);
4635 helper->banner = modest_platform_animation_banner (GTK_WIDGET (parent_window), NULL,
4636 _CS("ckct_nw_pasting"));
4637 if (helper->banner != NULL) {
4638 gtk_window_set_modal (GTK_WINDOW(helper->banner), FALSE);
4639 gtk_widget_show (GTK_WIDGET(helper->banner));
4641 /* Clean folder on header view before moving it */
4642 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (info->folder_view));
4643 gtk_tree_selection_unselect_all (sel);
4645 /* Let gtk events run. We need that the folder
4646 view frees its reference to the source
4647 folder *before* issuing the mail operation
4648 so we need the signal handler of selection
4649 changed to happen before the mail
4651 while (gtk_events_pending ())
4652 gtk_main_iteration (); */
4655 modest_mail_operation_new_with_error_handling (G_OBJECT(parent_window),
4656 modest_ui_actions_move_folder_error_handler,
4657 info->src_folder, NULL);
4658 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
4661 /* Select *after* the changes */
4662 /* TODO: this function hangs UI after transfer */
4663 /* modest_folder_view_select_folder (MODEST_FOLDER_VIEW(folder_view), */
4664 /* TNY_FOLDER (src_folder), TRUE); */
4666 modest_mail_operation_xfer_folder (mail_op,
4667 TNY_FOLDER (info->src_folder),
4669 info->delete_original,
4673 if (modest_mail_operation_get_status (mail_op) == MODEST_MAIL_OPERATION_STATUS_SUCCESS) {
4674 modest_folder_view_select_folder (MODEST_FOLDER_VIEW(info->folder_view),
4675 TNY_FOLDER (info->dst_folder), TRUE);
4678 /* Unref mail operation */
4679 g_object_unref (G_OBJECT (mail_op));
4680 g_object_unref (G_OBJECT (info->src_folder));
4681 g_object_unref (G_OBJECT (info->dst_folder));
4686 * UI handler for the "Move to" action when invoked from the
4690 modest_ui_actions_on_main_window_move_to (GtkAction *action,
4691 GtkWidget *folder_view,
4692 TnyFolderStore *dst_folder,
4693 ModestMainWindow *win)
4695 ModestHeaderView *header_view = NULL;
4696 TnyFolderStore *src_folder;
4697 gboolean online = (tny_device_is_online (modest_runtime_get_device()));
4699 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win));
4701 /* Get the source folder */
4702 src_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
4704 /* Get header view */
4705 header_view = MODEST_HEADER_VIEW(modest_main_window_get_child_widget (win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW));
4707 /* Get folder or messages to transfer */
4708 if (gtk_widget_is_focus (folder_view)) {
4709 gboolean do_xfer = TRUE;
4711 /* Allow only to transfer folders to the local root folder */
4712 if (TNY_IS_ACCOUNT (dst_folder) &&
4713 !MODEST_IS_TNY_LOCAL_FOLDERS_ACCOUNT (dst_folder)) {
4715 } else if (!TNY_IS_FOLDER (src_folder)) {
4716 g_warning ("%s: src_folder is not a TnyFolder.\n", __FUNCTION__);
4718 } /* else if (!online && modest_tny_folder_store_is_remote(src_folder)) {
4719 guint num_headers = tny_folder_get_all_count(TNY_FOLDER (src_folder));
4720 TnyAccount *account = tny_folder_get_account (TNY_FOLDER (src_folder));
4721 if (!connect_to_get_msg(MODEST_WINDOW (win), num_headers, account))
4723 g_object_unref (account);
4727 MoveFolderInfo *info = g_new0 (MoveFolderInfo, 1);
4728 info->src_folder = TNY_FOLDER (src_folder);
4729 info->dst_folder = dst_folder;
4730 info->delete_original = TRUE;
4731 info->folder_view = folder_view;
4732 g_object_ref (G_OBJECT (info->src_folder));
4733 g_object_ref (G_OBJECT (info->dst_folder));
4734 modest_platform_connect_if_remote_and_perform(GTK_WINDOW (win), TRUE,
4735 TNY_FOLDER_STORE (dst_folder), on_move_folder_cb, info);
4737 } else if (gtk_widget_is_focus (GTK_WIDGET(header_view))) {
4738 gboolean do_xfer = TRUE;
4740 /* Show an error when trying to move msgs to an account */
4741 if (!TNY_IS_FOLDER (dst_folder)) {
4742 modest_platform_information_banner (GTK_WIDGET (win),
4744 _CS("ckdg_ib_unable_to_move_to_current_location"));
4748 /* Ask for confirmation if the source folder is remote and we're not connected */
4749 if (!online && modest_tny_folder_store_is_remote(src_folder)) {
4750 TnyList *headers = modest_header_view_get_selected_headers(header_view);
4751 if (!msgs_already_deleted_from_server(headers, src_folder)) {
4752 guint num_headers = tny_list_get_length(headers);
4753 TnyAccount *account = get_account_from_header_list (headers);
4754 GtkResponseType response;
4756 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
4757 ngettext("mcen_nc_get_msg",
4760 if (response == GTK_RESPONSE_CANCEL)
4763 g_object_unref (account);
4765 g_object_unref(headers);
4767 if (do_xfer) /* Transfer messages */ {
4768 DoubleConnectionInfo *info = g_slice_new (DoubleConnectionInfo);
4769 info->callback = xfer_messages_from_move_to_cb;
4770 info->dst_account = tny_folder_get_account (TNY_FOLDER (dst_folder));
4771 info->data = g_object_ref (dst_folder);
4773 modest_platform_connect_if_remote_and_perform(GTK_WINDOW (win), TRUE,
4774 TNY_FOLDER_STORE (src_folder),
4775 src_account_connect_performer,
4782 g_object_unref (src_folder);
4787 * UI handler for the "Move to" action when invoked from the
4788 * ModestMsgViewWindow
4791 modest_ui_actions_on_msg_view_window_move_to (GtkAction *action,
4792 TnyFolderStore *dst_folder,
4793 ModestMsgViewWindow *win)
4795 TnyHeader *header = NULL;
4796 TnyFolder *src_folder = NULL;
4797 TnyAccount *account = NULL;
4798 gboolean do_xfer = FALSE;
4800 /* Create header list */
4801 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
4802 src_folder = TNY_FOLDER (tny_header_get_folder(header));
4803 g_object_unref (header);
4805 account = tny_folder_get_account (src_folder);
4806 if (!modest_tny_folder_store_is_remote(TNY_FOLDER_STORE(src_folder))) {
4807 /* Transfer if the source folder is local */
4809 } else if (remote_folder_is_pop(TNY_FOLDER_STORE(src_folder))) {
4810 /* Transfer if the source folder is POP (as it means
4811 * that the message is already downloaded) */
4813 } else if (connect_to_get_msg(MODEST_WINDOW(win), 1, account)) {
4814 /* Transfer after asking confirmation */
4819 g_object_ref (dst_folder);
4820 modest_platform_connect_if_remote_and_perform(GTK_WINDOW (win), TRUE,
4821 TNY_FOLDER_STORE (dst_folder), xfer_messages_from_move_to_cb, dst_folder);
4823 g_object_unref (account);
4824 g_object_unref (src_folder);
4828 modest_ui_actions_on_move_to (GtkAction *action,
4831 GtkWidget *dialog = NULL, *folder_view = NULL, *tree_view = NULL;
4833 TnyFolderStore *dst_folder = NULL;
4834 ModestMainWindow *main_window;
4836 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win) ||
4837 MODEST_IS_MSG_VIEW_WINDOW (win));
4839 /* Get the main window if exists */
4840 if (MODEST_IS_MAIN_WINDOW (win))
4841 main_window = MODEST_MAIN_WINDOW (win);
4844 MODEST_MAIN_WINDOW (modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (),
4845 FALSE)); /* don't create */
4847 /* Get the folder view widget if exists */
4849 folder_view = modest_main_window_get_child_widget (main_window,
4850 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
4854 /* Create and run the dialog */
4855 dialog = create_move_to_dialog (GTK_WINDOW (win), folder_view, &tree_view);
4856 modest_folder_view_select_first_inbox_or_local (MODEST_FOLDER_VIEW (tree_view));
4857 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
4858 result = gtk_dialog_run (GTK_DIALOG(dialog));
4859 g_object_ref (tree_view);
4860 gtk_widget_destroy (dialog);
4862 if (result != GTK_RESPONSE_ACCEPT)
4865 dst_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (tree_view));
4866 /* Do window specific stuff */
4867 if (MODEST_IS_MAIN_WINDOW (win)) {
4868 modest_ui_actions_on_main_window_move_to (action,
4871 MODEST_MAIN_WINDOW (win));
4873 modest_ui_actions_on_msg_view_window_move_to (action,
4875 MODEST_MSG_VIEW_WINDOW (win));
4879 g_object_unref (dst_folder);
4883 * Calls #HeadersFunc for each header already selected in the main
4884 * window or the message currently being shown in the msg view window
4887 do_headers_action (ModestWindow *win,
4891 TnyList *headers_list = NULL;
4892 TnyIterator *iter = NULL;
4893 TnyHeader *header = NULL;
4894 TnyFolder *folder = NULL;
4897 headers_list = get_selected_headers (win);
4901 /* Get the folder */
4902 iter = tny_list_create_iterator (headers_list);
4903 header = TNY_HEADER (tny_iterator_get_current (iter));
4905 folder = tny_header_get_folder (header);
4906 g_object_unref (header);
4909 /* Call the function for each header */
4910 while (!tny_iterator_is_done (iter)) {
4911 header = TNY_HEADER (tny_iterator_get_current (iter));
4912 func (header, win, user_data);
4913 g_object_unref (header);
4914 tny_iterator_next (iter);
4917 /* Trick: do a poke status in order to speed up the signaling
4919 tny_folder_poke_status (folder);
4922 g_object_unref (folder);
4923 g_object_unref (iter);
4924 g_object_unref (headers_list);
4928 modest_ui_actions_view_attachment (GtkAction *action,
4929 ModestWindow *window)
4931 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
4932 modest_msg_view_window_view_attachment (MODEST_MSG_VIEW_WINDOW (window), NULL);
4934 /* not supported window for this action */
4935 g_return_if_reached ();
4940 modest_ui_actions_save_attachments (GtkAction *action,
4941 ModestWindow *window)
4943 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
4944 modest_msg_view_window_save_attachments (MODEST_MSG_VIEW_WINDOW (window), NULL);
4946 /* not supported window for this action */
4947 g_return_if_reached ();
4952 modest_ui_actions_remove_attachments (GtkAction *action,
4953 ModestWindow *window)
4955 if (MODEST_IS_MAIN_WINDOW (window)) {
4956 modest_ui_actions_on_main_window_remove_attachments (action, MODEST_MAIN_WINDOW (window));
4957 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
4958 modest_msg_view_window_remove_attachments (MODEST_MSG_VIEW_WINDOW (window), FALSE);
4960 /* not supported window for this action */
4961 g_return_if_reached ();
4966 modest_ui_actions_on_settings (GtkAction *action,
4971 dialog = modest_platform_get_global_settings_dialog ();
4972 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (win));
4973 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
4974 gtk_widget_show_all (dialog);
4976 gtk_dialog_run (GTK_DIALOG (dialog));
4978 gtk_widget_destroy (dialog);
4982 modest_ui_actions_on_help (GtkAction *action,
4985 const gchar *help_id;
4987 g_return_if_fail (action);
4988 g_return_if_fail (win && GTK_IS_WINDOW(win));
4990 help_id = modest_window_mgr_get_help_id (modest_runtime_get_window_mgr(), win);
4993 modest_platform_show_help (GTK_WINDOW (win), help_id);
4995 g_warning ("%s: no help for window %p", __FUNCTION__, win);
4999 retrieve_msg_contents_performer (gboolean canceled,
5001 GtkWindow *parent_window,
5002 TnyAccount *account,
5005 ModestMailOperation *mail_op;
5006 TnyList *headers = TNY_LIST (user_data);
5008 if (err || canceled) {
5012 /* Create mail operation */
5013 mail_op = modest_mail_operation_new_with_error_handling ((GObject *) parent_window,
5014 modest_ui_actions_get_msgs_full_error_handler,
5016 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
5017 modest_mail_operation_get_msgs_full (mail_op, headers, NULL, NULL, NULL);
5020 g_object_unref (mail_op);
5022 g_object_unref (headers);
5023 g_object_unref (account);
5027 modest_ui_actions_on_retrieve_msg_contents (GtkAction *action,
5028 ModestWindow *window)
5030 TnyList *headers = NULL;
5031 TnyAccount *account = NULL;
5032 TnyIterator *iter = NULL;
5033 TnyHeader *header = NULL;
5034 TnyFolder *folder = NULL;
5037 headers = get_selected_headers (window);
5041 /* Pick the account */
5042 iter = tny_list_create_iterator (headers);
5043 header = TNY_HEADER (tny_iterator_get_current (iter));
5044 folder = tny_header_get_folder (header);
5045 account = tny_folder_get_account (folder);
5046 g_object_unref (folder);
5047 g_object_unref (header);
5048 g_object_unref (iter);
5050 /* Connect and perform the message retrieval */
5051 modest_platform_connect_and_perform ((GtkWindow *) window, TRUE,
5052 g_object_ref (account),
5053 retrieve_msg_contents_performer,
5054 g_object_ref (headers));
5057 g_object_unref (account);
5058 g_object_unref (headers);
5062 modest_ui_actions_check_toolbar_dimming_rules (ModestWindow *window)
5064 g_return_if_fail (MODEST_IS_WINDOW (window));
5067 modest_window_check_dimming_rules_group (window, MODEST_DIMMING_RULES_TOOLBAR);
5071 modest_ui_actions_check_menu_dimming_rules (ModestWindow *window)
5073 g_return_if_fail (MODEST_IS_WINDOW (window));
5076 modest_window_check_dimming_rules_group (window, MODEST_DIMMING_RULES_MENU);
5080 modest_ui_actions_on_email_menu_activated (GtkAction *action,
5081 ModestWindow *window)
5083 g_return_if_fail (MODEST_IS_WINDOW (window));
5086 modest_ui_actions_check_menu_dimming_rules (window);
5090 modest_ui_actions_on_edit_menu_activated (GtkAction *action,
5091 ModestWindow *window)
5093 g_return_if_fail (MODEST_IS_WINDOW (window));
5096 modest_ui_actions_check_menu_dimming_rules (window);
5100 modest_ui_actions_on_view_menu_activated (GtkAction *action,
5101 ModestWindow *window)
5103 g_return_if_fail (MODEST_IS_WINDOW (window));
5106 modest_ui_actions_check_menu_dimming_rules (window);
5110 modest_ui_actions_on_format_menu_activated (GtkAction *action,
5111 ModestWindow *window)
5113 g_return_if_fail (MODEST_IS_WINDOW (window));
5116 modest_ui_actions_check_menu_dimming_rules (window);
5120 modest_ui_actions_on_tools_menu_activated (GtkAction *action,
5121 ModestWindow *window)
5123 g_return_if_fail (MODEST_IS_WINDOW (window));
5126 modest_ui_actions_check_menu_dimming_rules (window);
5130 modest_ui_actions_on_attachment_menu_activated (GtkAction *action,
5131 ModestWindow *window)
5133 g_return_if_fail (MODEST_IS_WINDOW (window));
5136 modest_ui_actions_check_menu_dimming_rules (window);
5140 modest_ui_actions_on_toolbar_csm_menu_activated (GtkAction *action,
5141 ModestWindow *window)
5143 g_return_if_fail (MODEST_IS_WINDOW (window));
5146 modest_ui_actions_check_menu_dimming_rules (window);
5150 modest_ui_actions_on_folder_view_csm_menu_activated (GtkAction *action,
5151 ModestWindow *window)
5153 g_return_if_fail (MODEST_IS_WINDOW (window));
5156 modest_ui_actions_check_menu_dimming_rules (window);
5160 modest_ui_actions_on_header_view_csm_menu_activated (GtkAction *action,
5161 ModestWindow *window)
5163 g_return_if_fail (MODEST_IS_WINDOW (window));
5166 modest_ui_actions_check_menu_dimming_rules (window);
5170 modest_ui_actions_on_search_messages (GtkAction *action, ModestWindow *window)
5172 g_return_if_fail (MODEST_IS_WINDOW (window));
5174 modest_platform_show_search_messages (GTK_WINDOW (window));
5178 modest_ui_actions_on_open_addressbook (GtkAction *action, ModestWindow *win)
5180 g_return_if_fail (MODEST_IS_WINDOW (win));
5181 modest_platform_show_addressbook (GTK_WINDOW (win));
5186 modest_ui_actions_on_toggle_find_in_page (GtkToggleAction *action,
5187 ModestWindow *window)
5189 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
5191 modest_msg_edit_window_toggle_find_toolbar (MODEST_MSG_EDIT_WINDOW (window), gtk_toggle_action_get_active (action));
5195 on_send_receive_finished (ModestMailOperation *mail_op,
5198 GtkWidget *header_view, *folder_view;
5199 TnyFolderStore *folder_store;
5200 ModestMainWindow *main_win = MODEST_MAIN_WINDOW (user_data);
5202 /* Set send/receive operation finished */
5203 modest_main_window_notify_send_receive_completed (main_win);
5205 /* Don't refresh the current folder if there were any errors */
5206 if (modest_mail_operation_get_status (mail_op) !=
5207 MODEST_MAIL_OPERATION_STATUS_SUCCESS)
5210 /* Refresh the current folder if we're viewing a window. We do
5211 this because the user won't be able to see the new mails in
5212 the selected folder after a Send&Receive because it only
5213 performs a poke_status, i.e, only the number of read/unread
5214 messages is updated, but the new headers are not
5216 folder_view = modest_main_window_get_child_widget (main_win,
5217 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
5221 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
5223 /* Do not need to refresh INBOX again because the
5224 update_account does it always automatically */
5225 if (folder_store && TNY_IS_FOLDER (folder_store) &&
5226 tny_folder_get_folder_type (TNY_FOLDER (folder_store)) != TNY_FOLDER_TYPE_INBOX) {
5227 ModestMailOperation *refresh_op;
5229 header_view = modest_main_window_get_child_widget (main_win,
5230 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
5232 /* We do not need to set the contents style
5233 because it hasn't changed. We also do not
5234 need to save the widget status. Just force
5236 refresh_op = modest_mail_operation_new (G_OBJECT (main_win));
5237 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), refresh_op);
5238 modest_mail_operation_refresh_folder (refresh_op, TNY_FOLDER (folder_store),
5239 folder_refreshed_cb, main_win);
5240 g_object_unref (refresh_op);
5244 g_object_unref (folder_store);
5249 modest_ui_actions_on_send_queue_error_happened (TnySendQueue *self,
5255 const gchar* server_name = NULL;
5256 TnyTransportAccount *server_account;
5257 gchar *message = NULL;
5259 /* Don't show anything if the user cancelled something */
5260 if (err->code == TNY_TRANSPORT_ACCOUNT_ERROR_SEND_USER_CANCEL)
5263 /* Get the server name: */
5265 TNY_TRANSPORT_ACCOUNT (tny_camel_send_queue_get_transport_account (TNY_CAMEL_SEND_QUEUE (self)));
5266 if (server_account) {
5267 server_name = tny_account_get_hostname (TNY_ACCOUNT (server_account));
5269 g_object_unref (server_account);
5270 server_account = NULL;
5273 g_return_if_fail (server_name);
5275 /* Show the appropriate message text for the GError: */
5276 switch (err->code) {
5277 case TNY_TRANSPORT_ACCOUNT_ERROR_SEND_HOST_LOOKUP_FAILED:
5278 message = g_strdup_printf (_("emev_ib_ui_smtp_server_invalid"), server_name);
5280 case TNY_TRANSPORT_ACCOUNT_ERROR_SEND_SERVICE_UNAVAILABLE:
5281 message = g_strdup_printf (_("emev_ib_ui_smtp_server_invalid"), server_name);
5283 case TNY_TRANSPORT_ACCOUNT_ERROR_SEND_AUTHENTICATION_NOT_SUPPORTED:
5284 message = g_strdup_printf (_("emev_ni_ui_smtp_authentication_fail_error"), server_name);
5286 case TNY_TRANSPORT_ACCOUNT_ERROR_SEND:
5287 message = g_strdup (_("emev_ib_ui_smtp_send_error"));
5290 g_warning ("%s: unexpected TNY_TRANSPORT_ACCOUNT_ERROR %d",
5291 __FUNCTION__, err->code);
5292 message = g_strdup (_("emev_ib_ui_smtp_send_error"));
5296 /* TODO if the username or the password where not defined we
5297 should show the Accounts Settings dialog or the Connection
5298 specific SMTP server window */
5300 modest_platform_run_information_dialog (NULL, message);
5305 modest_ui_actions_on_send_queue_status_changed (ModestTnySendQueue *send_queue,
5310 ModestMainWindow *main_window = NULL;
5311 ModestWindowMgr *mgr = NULL;
5312 GtkWidget *folder_view = NULL, *header_view = NULL;
5313 TnyFolderStore *selected_folder = NULL;
5314 TnyFolderType folder_type;
5316 mgr = modest_runtime_get_window_mgr ();
5317 main_window = MODEST_MAIN_WINDOW (modest_window_mgr_get_main_window (mgr,
5318 FALSE));/* don't create */
5322 /* Check if selected folder is OUTBOX */
5323 folder_view = modest_main_window_get_child_widget (main_window,
5324 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
5325 header_view = modest_main_window_get_child_widget (main_window,
5326 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
5328 selected_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
5329 if (!TNY_IS_FOLDER (selected_folder))
5332 /* gtk_tree_view_column_queue_resize is only available in GTK+ 2.8 */
5333 #if GTK_CHECK_VERSION(2, 8, 0)
5334 folder_type = modest_tny_folder_guess_folder_type (TNY_FOLDER (selected_folder));
5335 if (folder_type == TNY_FOLDER_TYPE_OUTBOX) {
5336 GtkTreeViewColumn *tree_column;
5338 tree_column = gtk_tree_view_get_column (GTK_TREE_VIEW (header_view),
5339 TNY_GTK_HEADER_LIST_MODEL_FROM_COLUMN);
5340 gtk_tree_view_column_queue_resize (tree_column);
5343 gtk_widget_queue_draw (header_view);
5348 if (selected_folder != NULL)
5349 g_object_unref (selected_folder);
5353 modest_ui_actions_on_account_connection_error (GtkWindow *parent_window,
5354 TnyAccount *account)
5356 ModestTransportStoreProtocol proto;
5357 const gchar *proto_name;
5358 gchar *error_note = NULL;
5360 proto_name = tny_account_get_proto (account);
5361 proto = modest_protocol_info_get_transport_store_protocol (proto_name);
5364 case MODEST_PROTOCOL_STORE_POP:
5365 error_note = g_strdup_printf (_("emev_ni_ui_pop3_msg_connect_error"),
5366 tny_account_get_hostname (account));
5368 case MODEST_PROTOCOL_STORE_IMAP:
5369 error_note = g_strdup_printf (_("emev_ni_ui_imap_connect_server_error"),
5370 tny_account_get_hostname (account));
5372 case MODEST_PROTOCOL_STORE_MAILDIR:
5373 case MODEST_PROTOCOL_STORE_MBOX:
5374 error_note = g_strdup (_("emev_nc_mailbox_notavailable"));
5377 g_warning ("%s: This should not be reached", __FUNCTION__);
5381 modest_platform_run_information_dialog (parent_window, error_note);
5382 g_free (error_note);