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 <tny-mime-part.h>
48 #include <tny-camel-folder.h>
49 #include <tny-camel-imap-folder.h>
50 #include <tny-camel-pop-folder.h>
52 #ifdef MODEST_PLATFORM_MAEMO
53 #include "maemo/modest-osso-state-saving.h"
54 #include "maemo/modest-maemo-utils.h"
55 #include "maemo/modest-hildon-includes.h"
56 #include "maemo/modest-connection-specific-smtp-window.h"
57 #endif /* MODEST_PLATFORM_MAEMO */
59 #include "widgets/modest-ui-constants.h"
60 #include <widgets/modest-main-window.h>
61 #include <widgets/modest-msg-view-window.h>
62 #include <widgets/modest-account-view-window.h>
63 #include <widgets/modest-details-dialog.h>
64 #include <widgets/modest-attachments-view.h>
65 #include "widgets/modest-folder-view.h"
66 #include "widgets/modest-global-settings-dialog.h"
67 #include "modest-account-mgr-helpers.h"
68 #include "modest-mail-operation.h"
69 #include "modest-text-utils.h"
71 #ifdef MODEST_HAVE_EASYSETUP
72 #include "easysetup/modest-easysetup-wizard.h"
73 #endif /* MODEST_HAVE_EASYSETUP */
75 #include <modest-widget-memory.h>
76 #include <tny-error.h>
77 #include <tny-simple-list.h>
78 #include <tny-msg-view.h>
79 #include <tny-device.h>
80 #include <tny-merge-folder.h>
82 #include <gtkhtml/gtkhtml.h>
84 typedef struct _GetMsgAsyncHelper {
86 ModestMailOperation *mail_op;
93 typedef enum _ReplyForwardAction {
99 typedef struct _ReplyForwardHelper {
100 guint reply_forward_type;
101 ReplyForwardAction action;
103 GtkWidget *parent_window;
104 } ReplyForwardHelper;
106 typedef struct _MoveToHelper {
107 GtkTreeRowReference *reference;
111 typedef struct _PasteAsAttachmentHelper {
112 ModestMsgEditWindow *window;
114 } PasteAsAttachmentHelper;
118 * The do_headers_action uses this kind of functions to perform some
119 * action to each member of a list of headers
121 typedef void (*HeadersFunc) (TnyHeader *header, ModestWindow *win, gpointer user_data);
123 static void do_headers_action (ModestWindow *win,
127 static void open_msg_cb (ModestMailOperation *mail_op,
134 static void reply_forward_cb (ModestMailOperation *mail_op,
141 static void reply_forward (ReplyForwardAction action, ModestWindow *win);
143 static void folder_refreshed_cb (ModestMailOperation *mail_op,
147 static void on_send_receive_finished (ModestMailOperation *mail_op,
150 static gint header_list_count_uncached_msgs (TnyList *header_list);
152 static gboolean connect_to_get_msg (ModestWindow *win,
153 gint num_of_uncached_msgs,
154 TnyAccount *account);
156 static gboolean remote_folder_is_pop (const TnyFolderStore *folder);
158 static gboolean msgs_already_deleted_from_server ( TnyList *headers,
159 const TnyFolderStore *src_folder);
163 * This function checks whether a TnyFolderStore is a pop account
166 remote_folder_is_pop (const TnyFolderStore *folder)
168 const gchar *proto = NULL;
169 TnyAccount *account = NULL;
171 g_return_val_if_fail (TNY_IS_FOLDER_STORE(folder), FALSE);
173 if (TNY_IS_ACCOUNT (folder)) {
174 account = TNY_ACCOUNT(folder);
175 g_object_ref(account);
176 } else if (TNY_IS_FOLDER (folder)) {
177 account = tny_folder_get_account(TNY_FOLDER(folder));
180 if (!account && !TNY_IS_ACCOUNT(account)) {
181 g_warning ("%s: could not get account", __FUNCTION__);
185 proto = tny_account_get_proto(account);
186 g_object_unref (account);
189 (modest_protocol_info_get_transport_store_protocol (proto) == MODEST_PROTOCOL_STORE_POP);
193 * This functions checks whether if a list of messages are already
194 * deleted from the server: that is, if the server is a POP account
195 * and all messages are already cached.
198 msgs_already_deleted_from_server (TnyList *headers, const TnyFolderStore *src_folder)
200 g_return_val_if_fail (TNY_IS_FOLDER_STORE(src_folder), FALSE);
201 g_return_val_if_fail (TNY_IS_LIST(headers), FALSE);
203 gboolean src_is_pop = remote_folder_is_pop (src_folder);
204 gint uncached_msgs = header_list_count_uncached_msgs (headers);
206 return (src_is_pop && !uncached_msgs);
210 /* FIXME: this should be merged with the similar code in modest-account-view-window */
211 /* Show the account creation wizard dialog.
212 * returns: TRUE if an account was created. FALSE if the user cancelled.
215 modest_ui_actions_run_account_setup_wizard (ModestWindow *win)
217 gboolean result = FALSE;
218 #ifdef MODEST_PLATFORM_MAEMO
219 GtkWindow *dialog, *wizard;
220 gint dialog_response;
222 /* Show the easy-setup wizard: */
223 dialog = modest_window_mgr_get_modal (modest_runtime_get_window_mgr());
224 if (dialog && MODEST_IS_EASYSETUP_WIZARD_DIALOG(dialog)) {
225 /* old wizard is active already;
227 gtk_window_present (GTK_WINDOW(dialog));
232 /* there is no such wizard yet */
233 wizard = GTK_WINDOW (modest_easysetup_wizard_dialog_new ());
234 modest_window_mgr_set_modal (modest_runtime_get_window_mgr(), wizard);
236 /* always present a main window in the background
237 * we do it here, so we cannot end up with two wizards (as this
238 * function might be called in modest_window_mgr_get_main_window as well */
240 win = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr(),
241 TRUE); /* create if not existent */
243 /* make sure the mainwindow is visible */
244 gtk_window_set_transient_for (GTK_WINDOW (wizard), GTK_WINDOW (win));
245 gtk_widget_show_all (GTK_WIDGET(win));
246 gtk_window_present (GTK_WINDOW(win));
248 dialog_response = gtk_dialog_run (GTK_DIALOG (wizard));
249 gtk_widget_destroy (GTK_WIDGET (wizard));
250 if (gtk_events_pending ())
251 gtk_main_iteration ();
253 if (dialog_response == GTK_RESPONSE_CANCEL) {
256 /* Check whether an account was created: */
257 result = modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
265 modest_ui_actions_on_about (GtkAction *action, ModestWindow *win)
268 const gchar *authors[] = {
269 "Dirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>",
272 about = gtk_about_dialog_new ();
273 gtk_about_dialog_set_name (GTK_ABOUT_DIALOG(about), PACKAGE_NAME);
274 gtk_about_dialog_set_version (GTK_ABOUT_DIALOG(about),PACKAGE_VERSION);
275 gtk_about_dialog_set_copyright (GTK_ABOUT_DIALOG(about),
276 _("Copyright (c) 2006, Nokia Corporation\n"
277 "All rights reserved."));
278 gtk_about_dialog_set_comments (GTK_ABOUT_DIALOG(about),
279 _("a modest e-mail client\n\n"
280 "design and implementation: Dirk-Jan C. Binnema\n"
281 "contributions from the fine people at KC and Ig\n"
282 "uses the tinymail email framework written by Philip van Hoof"));
283 gtk_about_dialog_set_authors (GTK_ABOUT_DIALOG(about), authors);
284 gtk_about_dialog_set_website (GTK_ABOUT_DIALOG(about), "http://modest.garage.maemo.org");
285 gtk_window_set_transient_for (GTK_WINDOW (about), GTK_WINDOW (win));
286 gtk_window_set_modal (GTK_WINDOW (about), TRUE);
288 gtk_dialog_run (GTK_DIALOG (about));
289 gtk_widget_destroy(about);
293 * Gets the list of currently selected messages. If the win is the
294 * main window, then it returns a newly allocated list of the headers
295 * selected in the header view. If win is the msg view window, then
296 * the value returned is a list with just a single header.
298 * The caller of this funcion must free the list.
301 get_selected_headers (ModestWindow *win)
303 if (MODEST_IS_MAIN_WINDOW(win)) {
304 GtkWidget *header_view;
306 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
307 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
308 return modest_header_view_get_selected_headers (MODEST_HEADER_VIEW(header_view));
310 } else if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
311 /* for MsgViewWindows, we simply return a list with one element */
313 TnyList *list = NULL;
315 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
316 if (header != NULL) {
317 list = tny_simple_list_new ();
318 tny_list_prepend (list, G_OBJECT(header));
319 g_object_unref (G_OBJECT(header));
328 static GtkTreeRowReference *
329 get_next_after_selected_headers (ModestHeaderView *header_view)
331 GtkTreeSelection *sel;
332 GList *selected_rows, *node;
334 GtkTreeRowReference *result;
337 model = gtk_tree_view_get_model (GTK_TREE_VIEW (header_view));
338 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
339 selected_rows = gtk_tree_selection_get_selected_rows (sel, NULL);
341 if (selected_rows == NULL)
344 node = g_list_last (selected_rows);
345 path = gtk_tree_path_copy ((GtkTreePath *) node->data);
346 gtk_tree_path_next (path);
348 result = gtk_tree_row_reference_new (model, path);
350 gtk_tree_path_free (path);
351 g_list_foreach (selected_rows, (GFunc) gtk_tree_path_free, NULL);
352 g_list_free (selected_rows);
358 headers_action_mark_as_read (TnyHeader *header,
362 TnyHeaderFlags flags;
364 g_return_if_fail (TNY_IS_HEADER(header));
366 flags = tny_header_get_flags (header);
367 if (flags & TNY_HEADER_FLAG_SEEN) return;
368 tny_header_set_flag (header, TNY_HEADER_FLAG_SEEN);
372 headers_action_mark_as_unread (TnyHeader *header,
376 TnyHeaderFlags flags;
378 g_return_if_fail (TNY_IS_HEADER(header));
380 flags = tny_header_get_flags (header);
381 if (flags & TNY_HEADER_FLAG_SEEN) {
382 tny_header_unset_flag (header, TNY_HEADER_FLAG_SEEN);
386 /** After deleing a message that is currently visible in a window,
387 * show the next message from the list, or close the window if there are no more messages.
390 modest_ui_actions_refresh_message_window_after_delete (ModestMsgViewWindow* win)
392 /* Close msg view window or select next */
393 if (modest_msg_view_window_last_message_selected (win) &&
394 modest_msg_view_window_first_message_selected (win)) {
395 modest_ui_actions_on_close_window (NULL, MODEST_WINDOW (win));
396 } else if (!modest_msg_view_window_select_next_message (win)) {
398 g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value);
404 modest_ui_actions_on_delete_message (GtkAction *action, ModestWindow *win)
406 TnyList *header_list = NULL;
407 TnyIterator *iter = NULL;
408 TnyHeader *header = NULL;
409 gchar *message = NULL;
412 ModestWindowMgr *mgr;
413 GtkWidget *header_view = NULL;
415 g_return_if_fail (MODEST_IS_WINDOW(win));
417 /* Check first if the header view has the focus */
418 if (MODEST_IS_MAIN_WINDOW (win)) {
420 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
421 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
422 if (!gtk_widget_is_focus (header_view))
426 /* Get the headers, either from the header view (if win is the main window),
427 * or from the message view window: */
428 header_list = get_selected_headers (win);
429 if (!header_list) return;
431 /* Check if any of the headers are already opened, or in the process of being opened */
432 if (MODEST_IS_MAIN_WINDOW (win)) {
433 gint opened_headers = 0;
435 iter = tny_list_create_iterator (header_list);
436 mgr = modest_runtime_get_window_mgr ();
437 while (!tny_iterator_is_done (iter)) {
438 header = TNY_HEADER (tny_iterator_get_current (iter));
440 if (modest_window_mgr_find_registered_header (mgr, header, NULL))
442 g_object_unref (header);
444 tny_iterator_next (iter);
446 g_object_unref (iter);
448 if (opened_headers > 0) {
451 msg = g_strdup_printf (_("mcen_nc_unable_to_delete_n_messages"),
454 modest_platform_run_information_dialog (GTK_WINDOW (win), (const gchar *) msg);
457 g_object_unref (header_list);
463 if (tny_list_get_length(header_list) == 1) {
464 iter = tny_list_create_iterator (header_list);
465 header = TNY_HEADER (tny_iterator_get_current (iter));
467 desc = g_strdup_printf ("%s", tny_header_get_subject (header));
468 g_object_unref (header);
471 g_object_unref (iter);
473 message = g_strdup_printf(ngettext("emev_nc_delete_message", "emev_nc_delete_messages",
474 tny_list_get_length(header_list)), desc);
476 /* Confirmation dialog */
477 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
481 if (response == GTK_RESPONSE_OK) {
482 ModestWindow *main_window = NULL;
483 ModestWindowMgr *mgr = NULL;
484 GtkTreeModel *model = NULL;
485 GtkTreeSelection *sel = NULL;
486 GList *sel_list = NULL, *tmp = NULL;
487 GtkTreeRowReference *next_row_reference = NULL;
488 GtkTreeRowReference *prev_row_reference = NULL;
489 GtkTreePath *next_path = NULL;
490 GtkTreePath *prev_path = NULL;
491 ModestMailOperation *mail_op = NULL;
493 /* Find last selected row */
494 if (MODEST_IS_MAIN_WINDOW (win)) {
495 model = gtk_tree_view_get_model (GTK_TREE_VIEW (header_view));
496 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
497 sel_list = gtk_tree_selection_get_selected_rows (sel, &model);
498 for (tmp=sel_list; tmp; tmp=tmp->next) {
499 if (tmp->next == NULL) {
500 prev_path = gtk_tree_path_copy((GtkTreePath *) tmp->data);
501 next_path = gtk_tree_path_copy((GtkTreePath *) tmp->data);
503 gtk_tree_path_prev (prev_path);
504 gtk_tree_path_next (next_path);
506 prev_row_reference = gtk_tree_row_reference_new (model, prev_path);
507 next_row_reference = gtk_tree_row_reference_new (model, next_path);
512 /* Disable window dimming management */
513 modest_window_disable_dimming (MODEST_WINDOW(win));
515 /* Remove each header. If it's a view window header_view == NULL */
516 mail_op = modest_mail_operation_new ((GObject *) win);
517 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
519 modest_mail_operation_remove_msgs (mail_op, header_list, FALSE);
520 g_object_unref (mail_op);
522 /* Enable window dimming management */
524 gtk_tree_selection_unselect_all (sel);
526 modest_window_enable_dimming (MODEST_WINDOW(win));
528 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
529 modest_ui_actions_refresh_message_window_after_delete (MODEST_MSG_VIEW_WINDOW (win));
531 /* Get main window */
532 mgr = modest_runtime_get_window_mgr ();
533 main_window = modest_window_mgr_get_main_window (mgr, FALSE); /* don't create */
535 /* Move cursor to next row */
538 /* Select next or previous row */
539 if (gtk_tree_row_reference_valid (next_row_reference)) {
540 /* next_path = gtk_tree_row_reference_get_path (row_reference); */
541 gtk_tree_selection_select_path (sel, next_path);
543 else if (gtk_tree_row_reference_valid (prev_row_reference)) {
544 gtk_tree_selection_select_path (sel, prev_path);
548 if (next_row_reference != NULL)
549 gtk_tree_row_reference_free (next_row_reference);
550 if (next_path != NULL)
551 gtk_tree_path_free (next_path);
552 if (prev_row_reference != NULL)
553 gtk_tree_row_reference_free (prev_row_reference);
554 if (prev_path != NULL)
555 gtk_tree_path_free (prev_path);
558 /* Update toolbar dimming state */
560 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
563 g_list_foreach (sel_list, (GFunc) gtk_tree_path_free, NULL);
564 g_list_free (sel_list);
570 g_object_unref (header_list);
576 /* delete either message or folder, based on where we are */
578 modest_ui_actions_on_delete_message_or_folder (GtkAction *action, ModestWindow *win)
580 g_return_if_fail (MODEST_IS_WINDOW(win));
582 /* Check first if the header view has the focus */
583 if (MODEST_IS_MAIN_WINDOW (win)) {
585 w = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
586 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
587 if (gtk_widget_is_focus (w)) {
588 modest_ui_actions_on_delete_folder (action, MODEST_MAIN_WINDOW(win));
592 modest_ui_actions_on_delete_message (action, win);
598 modest_ui_actions_on_quit (GtkAction *action, ModestWindow *win)
600 ModestWindowMgr *mgr = NULL;
602 #ifdef MODEST_PLATFORM_MAEMO
603 modest_osso_save_state();
604 #endif /* MODEST_PLATFORM_MAEMO */
606 g_debug ("closing down, clearing %d item(s) from operation queue",
607 modest_mail_operation_queue_num_elements
608 (modest_runtime_get_mail_operation_queue()));
610 /* cancel all outstanding operations */
611 modest_mail_operation_queue_cancel_all
612 (modest_runtime_get_mail_operation_queue());
614 g_debug ("queue has been cleared");
617 /* Check if there are opened editing windows */
618 mgr = modest_runtime_get_window_mgr ();
619 modest_window_mgr_close_all_windows (mgr);
621 /* note: when modest-tny-account-store is finalized,
622 it will automatically set all network connections
625 /* gtk_main_quit (); */
629 modest_ui_actions_on_close_window (GtkAction *action, ModestWindow *win)
633 g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value);
635 /* if (MODEST_IS_MSG_VIEW_WINDOW (win)) { */
636 /* gtk_widget_destroy (GTK_WIDGET (win)); */
637 /* } else if (MODEST_IS_MSG_EDIT_WINDOW (win)) { */
638 /* gboolean ret_value; */
639 /* g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value); */
640 /* } else if (MODEST_IS_WINDOW (win)) { */
641 /* gtk_widget_destroy (GTK_WIDGET (win)); */
643 /* g_return_if_reached (); */
648 modest_ui_actions_on_add_to_contacts (GtkAction *action, ModestWindow *win)
650 GtkClipboard *clipboard = NULL;
651 gchar *selection = NULL;
653 clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
654 selection = gtk_clipboard_wait_for_text (clipboard);
656 /* Question: why is the clipboard being used here?
657 * It doesn't really make a lot of sense. */
661 modest_address_book_add_address (selection);
667 modest_ui_actions_on_accounts (GtkAction *action,
670 /* This is currently only implemented for Maemo */
671 #ifdef MODEST_PLATFORM_MAEMO /* Defined in config.h */
672 if (!modest_account_mgr_has_accounts (modest_runtime_get_account_mgr(), TRUE)) {
673 if (!modest_ui_actions_run_account_setup_wizard (win))
674 g_debug ("%s: wizard was already running", __FUNCTION__);
678 /* Show the list of accounts */
679 GtkWindow *account_win = GTK_WINDOW (modest_account_view_window_new ());
680 gtk_window_set_transient_for (account_win, GTK_WINDOW (win));
682 /* The accounts dialog must be modal */
683 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), account_win);
684 modest_maemo_show_dialog_and_forget (GTK_WINDOW (win), GTK_DIALOG (account_win));
687 GtkWidget *dialog, *label;
689 /* Create the widgets */
691 dialog = gtk_dialog_new_with_buttons ("Message",
693 GTK_DIALOG_DESTROY_WITH_PARENT,
697 label = gtk_label_new ("Hello World!");
699 /* Ensure that the dialog box is destroyed when the user responds. */
701 g_signal_connect_swapped (dialog, "response",
702 G_CALLBACK (gtk_widget_destroy),
705 /* Add the label, and show everything we've added to the dialog. */
707 gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox),
709 gtk_widget_show_all (dialog);
710 #endif /* MODEST_PLATFORM_MAEMO */
713 #ifdef MODEST_PLATFORM_MAEMO
715 on_smtp_servers_window_hide (GtkWindow* window, gpointer user_data)
717 /* Save any changes. */
718 modest_connection_specific_smtp_window_save_server_accounts (
719 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (window));
720 gtk_widget_destroy (GTK_WIDGET (window));
726 modest_ui_actions_on_smtp_servers (GtkAction *action, ModestWindow *win)
728 /* This is currently only implemented for Maemo,
729 * because it requires an API (libconic) to detect different connection
732 #ifdef MODEST_PLATFORM_MAEMO /* Defined in config.h */
734 /* Create the window if necessary: */
735 GtkWidget *specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
736 modest_connection_specific_smtp_window_fill_with_connections (
737 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (specific_window),
738 modest_runtime_get_account_mgr());
740 /* Show the window: */
741 gtk_window_set_transient_for (GTK_WINDOW (specific_window), GTK_WINDOW (win));
742 gtk_window_set_modal (GTK_WINDOW (specific_window), TRUE);
743 gtk_widget_show (specific_window);
745 /* Save changes when the window is hidden: */
746 g_signal_connect (specific_window, "hide",
747 G_CALLBACK (on_smtp_servers_window_hide), win);
748 #endif /* MODEST_PLATFORM_MAEMO */
752 modest_ui_actions_compose_msg(ModestWindow *win,
755 const gchar *bcc_str,
756 const gchar *subject_str,
757 const gchar *body_str,
760 gchar *account_name = NULL;
762 TnyAccount *account = NULL;
763 TnyFolder *folder = NULL;
764 gchar *from_str = NULL, *signature = NULL, *body = NULL;
765 gboolean use_signature = FALSE;
766 ModestWindow *msg_win = NULL;
767 ModestAccountMgr *mgr = modest_runtime_get_account_mgr();
768 ModestTnyAccountStore *store = modest_runtime_get_account_store();
770 if (win) account_name = g_strdup (modest_window_get_active_account (win));
771 if (!account_name) account_name = modest_account_mgr_get_default_account(mgr);
773 g_printerr ("modest: no account found\n");
776 account = modest_tny_account_store_get_server_account (store, account_name, TNY_ACCOUNT_TYPE_STORE);
778 g_printerr ("modest: failed to get tnyaccount for '%s'\n", account_name);
781 folder = modest_tny_account_get_special_folder (account, TNY_FOLDER_TYPE_DRAFTS);
783 g_printerr ("modest: failed to find Drafts folder\n");
786 from_str = modest_account_mgr_get_from_string (mgr, account_name);
788 g_printerr ("modest: failed get from string for '%s'\n", account_name);
792 signature = modest_account_mgr_get_signature (mgr, account_name, &use_signature);
793 if (body_str != NULL) {
794 body = use_signature ? g_strconcat(body_str, "\n", signature, NULL) : g_strdup(body_str);
796 body = use_signature ? g_strconcat("\n", signature, NULL) : g_strdup("");
799 msg = modest_tny_msg_new (to_str, from_str, cc_str, bcc_str, subject_str, body, NULL);
801 g_printerr ("modest: failed to create new msg\n");
805 /* Create and register edit window */
806 /* This is destroyed by TODO. */
807 msg_win = modest_msg_edit_window_new (msg, account_name, FALSE);
808 while (attachments) {
809 modest_msg_edit_window_attach_file_one((ModestMsgEditWindow *)msg_win,
811 attachments = g_slist_next(attachments);
813 modest_window_mgr_register_window (modest_runtime_get_window_mgr(), msg_win);
816 gtk_window_set_transient_for (GTK_WINDOW (msg_win),
819 gtk_widget_show_all (GTK_WIDGET (msg_win));
825 g_free (account_name);
826 if (account) g_object_unref (G_OBJECT(account));
827 if (folder) g_object_unref (G_OBJECT(folder));
828 if (msg_win) g_object_unref (G_OBJECT(msg_win));
829 if (msg) g_object_unref (G_OBJECT(msg));
833 modest_ui_actions_on_new_msg (GtkAction *action, ModestWindow *win)
835 /* if there are no accounts yet, just show the wizard */
836 if (!modest_account_mgr_has_accounts (modest_runtime_get_account_mgr(), TRUE))
837 if (!modest_ui_actions_run_account_setup_wizard (win))
840 modest_ui_actions_compose_msg(win, NULL, NULL, NULL, NULL, NULL, NULL);
844 modest_ui_actions_msg_retrieval_check (ModestMailOperation *mail_op,
848 ModestMailOperationStatus status;
850 /* If there is no message or the operation was not successful */
851 status = modest_mail_operation_get_status (mail_op);
852 if (!msg || status != MODEST_MAIL_OPERATION_STATUS_SUCCESS) {
854 /* Remove the header from the preregistered uids */
855 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (),
865 open_msg_cb (ModestMailOperation *mail_op,
872 ModestWindowMgr *mgr = NULL;
873 ModestWindow *parent_win = NULL;
874 ModestWindow *win = NULL;
875 TnyFolderType folder_type = TNY_FOLDER_TYPE_UNKNOWN;
876 gchar *account = NULL;
878 gboolean open_in_editor = FALSE;
880 /* Do nothing if there was any problem with the mail
881 operation. The error will be shown by the error_handler of
882 the mail operation */
883 if (!modest_ui_actions_msg_retrieval_check (mail_op, header, msg))
886 parent_win = (ModestWindow *) modest_mail_operation_get_source (mail_op);
887 folder = tny_header_get_folder (header);
889 /* Mark header as read */
890 headers_action_mark_as_read (header, MODEST_WINDOW(parent_win), NULL);
892 /* Gets folder type (OUTBOX headers will be opened in edit window */
893 if (modest_tny_folder_is_local_folder (folder)) {
894 folder_type = modest_tny_folder_get_local_or_mmc_folder_type (folder);
895 if (folder_type == TNY_FOLDER_TYPE_INVALID)
896 g_warning ("%s: BUG: TNY_FOLDER_TYPE_INVALID", __FUNCTION__);
900 if (folder_type == TNY_FOLDER_TYPE_OUTBOX) {
901 TnyTransportAccount *traccount = NULL;
902 ModestTnyAccountStore *accstore = modest_runtime_get_account_store();
903 traccount = modest_tny_account_store_get_transport_account_from_outbox_header(accstore, header);
905 ModestTnySendQueue *send_queue = NULL;
906 ModestTnySendQueueStatus status;
908 account = g_strdup(modest_tny_account_get_parent_modest_account_name_for_server_account(
909 TNY_ACCOUNT(traccount)));
910 send_queue = modest_runtime_get_send_queue(traccount);
911 msg_id = modest_tny_send_queue_get_msg_id (header);
912 status = modest_tny_send_queue_get_msg_status(send_queue, msg_id);
913 /* Only open messages in outbox with the editor if they are in Failed state */
914 if (status == MODEST_TNY_SEND_QUEUE_FAILED) {
915 open_in_editor = TRUE;
918 g_object_unref(traccount);
920 g_warning("Cannot get transport account for message in outbox!!");
922 } else if (folder_type == TNY_FOLDER_TYPE_DRAFTS) {
923 open_in_editor = TRUE; /* Open in editor if the message is in the Drafts folder */
928 account = g_strdup (modest_window_get_active_account (MODEST_WINDOW (parent_win)));
930 account = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
932 if (open_in_editor) {
933 ModestAccountMgr *mgr = modest_runtime_get_account_mgr ();
934 const gchar *from_header = NULL;
936 from_header = tny_header_get_from (header);
938 /* we cannot edit without a valid account... */
939 if (!modest_account_mgr_has_accounts(mgr, TRUE)) {
940 if (!modest_ui_actions_run_account_setup_wizard(parent_win))
945 GSList *accounts = modest_account_mgr_account_names (mgr, TRUE);
947 for (node = accounts; node != NULL; node = g_slist_next (node)) {
948 gchar *from = modest_account_mgr_get_from_string (mgr, node->data);
950 if (from && (strcmp (from_header, from) == 0)) {
952 account = g_strdup (node->data);
958 g_slist_foreach (accounts, (GFunc) g_free, NULL);
959 g_slist_free (accounts);
962 win = modest_msg_edit_window_new (msg, account, TRUE);
966 modest_platform_information_banner (NULL, NULL, _("mail_ib_opening_draft_message"));
969 gchar *uid = modest_tny_folder_get_header_unique_id (header);
971 if (MODEST_IS_MAIN_WINDOW (parent_win)) {
972 GtkWidget *header_view;
973 GtkTreeSelection *sel;
974 GList *sel_list = NULL;
977 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(parent_win),
978 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
980 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
981 sel_list = gtk_tree_selection_get_selected_rows (sel, &model);
983 if (sel_list != NULL) {
984 GtkTreeRowReference *row_reference;
986 row_reference = gtk_tree_row_reference_new (model, (GtkTreePath *) sel_list->data);
987 g_list_foreach (sel_list, (GFunc) gtk_tree_path_free, NULL);
988 g_list_free (sel_list);
990 win = modest_msg_view_window_new_with_header_model (
991 msg, account, (const gchar*) uid,
992 model, row_reference);
993 gtk_tree_row_reference_free (row_reference);
995 win = modest_msg_view_window_new_for_attachment (msg, account, (const gchar*) uid);
998 win = modest_msg_view_window_new_for_attachment (msg, account, (const gchar*) uid);
1003 /* Register and show new window */
1005 mgr = modest_runtime_get_window_mgr ();
1006 modest_window_mgr_register_window (mgr, win);
1007 g_object_unref (win);
1008 gtk_widget_show_all (GTK_WIDGET(win));
1011 /* Update toolbar dimming state */
1012 if (MODEST_IS_MAIN_WINDOW (parent_win)) {
1013 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (parent_win));
1019 g_object_unref (parent_win);
1020 g_object_unref (folder);
1024 modest_ui_actions_get_msgs_full_error_handler (ModestMailOperation *mail_op,
1027 const GError *error;
1028 GObject *win = NULL;
1029 const gchar *err_msg;
1031 win = modest_mail_operation_get_source (mail_op);
1032 error = modest_mail_operation_get_error (mail_op);
1034 /* Select error message */
1035 if (error->code == MODEST_MAIL_OPERATION_ERROR_MESSAGE_SIZE_LIMIT)
1036 err_msg = _("emev_ni_ui_imap_msg_size_exceed_error");
1038 err_msg = (const gchar *) user_data;
1041 modest_platform_run_information_dialog ((GtkWindow *) win, err_msg);
1044 g_object_unref (win);
1048 * Returns the account a list of headers belongs to. It returns a
1049 * *new* reference so don't forget to unref it
1052 get_account_from_header_list (TnyList *headers)
1054 TnyAccount *account = NULL;
1056 if (tny_list_get_length (headers) > 0) {
1057 TnyIterator *iter = tny_list_create_iterator (headers);
1058 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter));
1059 TnyFolder *folder = tny_header_get_folder (header);
1060 account = tny_folder_get_account (folder);
1061 g_object_unref (folder);
1062 g_object_unref (header);
1063 g_object_unref (iter);
1069 open_msgs_performer(gboolean canceled,
1071 GtkWindow *parent_window,
1072 TnyAccount *account,
1075 ModestMailOperation *mail_op;
1076 const gchar *proto_name;
1078 ModestTransportStoreProtocol proto;
1079 TnyList *not_opened_headers;
1081 not_opened_headers = TNY_LIST (user_data);
1083 /* Get the error message depending on the protocol */
1084 proto_name = tny_account_get_proto (account);
1085 if (proto_name != NULL) {
1086 proto = modest_protocol_info_get_transport_store_protocol (proto_name);
1088 proto = MODEST_PROTOCOL_STORE_MAILDIR;
1091 /* Create the error messages */
1092 if (tny_list_get_length (not_opened_headers) == 1) {
1093 if (proto == MODEST_PROTOCOL_STORE_POP) {
1094 error_msg = g_strdup (_("emev_ni_ui_pop3_msg_recv_error"));
1095 } else if (proto == MODEST_PROTOCOL_STORE_IMAP) {
1096 TnyIterator *iter = tny_list_create_iterator (not_opened_headers);
1097 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter));
1098 error_msg = g_strdup_printf (_("emev_ni_ui_imap_message_not_available_in_server"),
1099 tny_header_get_subject (header));
1100 g_object_unref (header);
1101 g_object_unref (iter);
1103 error_msg = g_strdup (_("mail_ni_ui_folder_get_msg_folder_error"));
1106 error_msg = g_strdup (_("mail_ni_ui_folder_get_msg_folder_error"));
1109 /* Create the mail operation */
1111 modest_mail_operation_new_with_error_handling ((GObject *) parent_window,
1112 modest_ui_actions_get_msgs_full_error_handler,
1114 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
1117 modest_mail_operation_get_msgs_full (mail_op,
1124 g_object_unref (mail_op);
1125 g_object_unref (not_opened_headers);
1126 g_object_unref (account);
1130 * This function is used by both modest_ui_actions_on_open and
1131 * modest_ui_actions_on_header_activated. This way we always do the
1132 * same when trying to open messages.
1135 open_msgs_from_headers (TnyList *headers, ModestWindow *win)
1137 ModestWindowMgr *mgr = NULL;
1138 TnyIterator *iter = NULL, *iter_not_opened = NULL;
1139 TnyList *not_opened_headers = NULL;
1140 TnyHeaderFlags flags = 0;
1141 TnyAccount *account;
1142 gint uncached_msgs = 0;
1144 g_return_if_fail (headers != NULL);
1146 /* Check that only one message is selected for opening */
1147 if (tny_list_get_length (headers) != 1) {
1148 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
1149 _("mcen_ib_select_one_message"));
1153 mgr = modest_runtime_get_window_mgr ();
1154 iter = tny_list_create_iterator (headers);
1156 /* Get the account */
1157 account = get_account_from_header_list (headers);
1159 /* Look if we already have a message view for each header. If
1160 true, then remove the header from the list of headers to
1162 not_opened_headers = tny_simple_list_new ();
1163 while (!tny_iterator_is_done (iter)) {
1165 ModestWindow *window = NULL;
1166 TnyHeader *header = NULL;
1167 gboolean found = FALSE;
1169 header = TNY_HEADER (tny_iterator_get_current (iter));
1171 flags = tny_header_get_flags (header);
1174 found = modest_window_mgr_find_registered_header (mgr, header, &window);
1176 /* Do not open again the message and present the
1177 window to the user */
1180 gtk_window_present (GTK_WINDOW (window));
1182 /* the header has been registered already, we don't do
1183 * anything but wait for the window to come up*/
1184 g_debug ("header %p already registered, waiting for window", header);
1186 tny_list_append (not_opened_headers, G_OBJECT (header));
1190 g_object_unref (header);
1192 tny_iterator_next (iter);
1194 g_object_unref (iter);
1197 /* Open each message */
1198 if (tny_list_get_length (not_opened_headers) == 0)
1201 /* If some messages would have to be downloaded, ask the user to
1202 * make a connection. It's generally easier to do this here (in the mainloop)
1203 * than later in a thread:
1205 if (tny_list_get_length (not_opened_headers) > 0) {
1206 uncached_msgs = header_list_count_uncached_msgs (not_opened_headers);
1208 if (uncached_msgs > 0) {
1209 /* Allways download if we are online. */
1210 if (!tny_device_is_online (modest_runtime_get_device ())) {
1213 /* If ask for user permission to download the messages */
1214 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
1215 ngettext("mcen_nc_get_msg",
1219 /* End if the user does not want to continue */
1220 if (response == GTK_RESPONSE_CANCEL)
1226 /* Register the headers before actually creating the windows: */
1227 iter_not_opened = tny_list_create_iterator (not_opened_headers);
1228 while (!tny_iterator_is_done (iter_not_opened)) {
1229 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter_not_opened));
1231 modest_window_mgr_register_header (mgr, header, NULL);
1232 g_object_unref (header);
1234 tny_iterator_next (iter_not_opened);
1236 g_object_unref (iter_not_opened);
1237 iter_not_opened = NULL;
1239 /* Connect to the account and perform */
1240 if (uncached_msgs > 0) {
1241 modest_platform_connect_and_perform ((GtkWindow *) win, g_object_ref (account),
1242 open_msgs_performer, g_object_ref (not_opened_headers));
1244 /* Call directly the performer, do not need to connect */
1245 open_msgs_performer (FALSE, NULL, (GtkWindow *) win, g_object_ref (account),
1246 g_object_ref (not_opened_headers));
1251 g_object_unref (account);
1252 if (not_opened_headers)
1253 g_object_unref (not_opened_headers);
1257 modest_ui_actions_on_open (GtkAction *action, ModestWindow *win)
1262 headers = get_selected_headers (win);
1267 open_msgs_from_headers (headers, win);
1269 g_object_unref(headers);
1274 free_reply_forward_helper (gpointer data)
1276 ReplyForwardHelper *helper;
1278 helper = (ReplyForwardHelper *) data;
1279 g_free (helper->account_name);
1280 g_slice_free (ReplyForwardHelper, helper);
1284 reply_forward_cb (ModestMailOperation *mail_op,
1292 ReplyForwardHelper *rf_helper;
1293 ModestWindow *msg_win = NULL;
1294 ModestEditType edit_type;
1296 TnyAccount *account = NULL;
1297 ModestWindowMgr *mgr = NULL;
1298 gchar *signature = NULL;
1299 gboolean use_signature;
1301 /* If there was any error. The mail operation could be NULL,
1302 this means that we already have the message downloaded and
1303 that we didn't do a mail operation to retrieve it */
1304 if (mail_op && !modest_ui_actions_msg_retrieval_check (mail_op, header, msg))
1307 g_return_if_fail (user_data != NULL);
1308 rf_helper = (ReplyForwardHelper *) user_data;
1310 from = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(),
1311 rf_helper->account_name);
1312 signature = modest_account_mgr_get_signature (modest_runtime_get_account_mgr(),
1313 rf_helper->account_name,
1316 /* Create reply mail */
1317 switch (rf_helper->action) {
1320 modest_tny_msg_create_reply_msg (msg, header, from, signature,
1321 rf_helper->reply_forward_type,
1322 MODEST_TNY_MSG_REPLY_MODE_SENDER);
1324 case ACTION_REPLY_TO_ALL:
1326 modest_tny_msg_create_reply_msg (msg, header, from, signature, rf_helper->reply_forward_type,
1327 MODEST_TNY_MSG_REPLY_MODE_ALL);
1328 edit_type = MODEST_EDIT_TYPE_REPLY;
1330 case ACTION_FORWARD:
1332 modest_tny_msg_create_forward_msg (msg, from, signature, rf_helper->reply_forward_type);
1333 edit_type = MODEST_EDIT_TYPE_FORWARD;
1336 g_return_if_reached ();
1343 g_printerr ("modest: failed to create message\n");
1347 account = modest_tny_account_store_get_server_account (modest_runtime_get_account_store(),
1348 rf_helper->account_name,
1349 TNY_ACCOUNT_TYPE_STORE);
1351 g_printerr ("modest: failed to get tnyaccount for '%s'\n", rf_helper->account_name);
1355 /* Create and register the windows */
1356 msg_win = modest_msg_edit_window_new (new_msg, rf_helper->account_name, FALSE);
1357 mgr = modest_runtime_get_window_mgr ();
1358 modest_window_mgr_register_window (mgr, msg_win);
1360 if (rf_helper->parent_window != NULL) {
1361 gdouble parent_zoom;
1363 parent_zoom = modest_window_get_zoom (MODEST_WINDOW (rf_helper->parent_window));
1364 modest_window_set_zoom (msg_win, parent_zoom);
1367 /* Show edit window */
1368 gtk_widget_show_all (GTK_WIDGET (msg_win));
1372 g_object_unref (msg_win);
1374 g_object_unref (G_OBJECT (new_msg));
1376 g_object_unref (G_OBJECT (account));
1377 /* g_object_unref (msg); */
1378 free_reply_forward_helper (rf_helper);
1381 /* Checks a list of headers. If any of them are not currently
1382 * downloaded (CACHED) then returns TRUE else returns FALSE.
1385 header_list_count_uncached_msgs (TnyList *header_list)
1388 gint uncached_messages = 0;
1390 iter = tny_list_create_iterator (header_list);
1391 while (!tny_iterator_is_done (iter)) {
1394 header = TNY_HEADER (tny_iterator_get_current (iter));
1396 if (!(tny_header_get_flags (header) & TNY_HEADER_FLAG_CACHED))
1397 uncached_messages ++;
1398 g_object_unref (header);
1401 tny_iterator_next (iter);
1403 g_object_unref (iter);
1405 return uncached_messages;
1408 /* Returns FALSE if the user does not want to download the
1409 * messages. Returns TRUE if the user allowed the download.
1412 connect_to_get_msg (ModestWindow *win,
1413 gint num_of_uncached_msgs,
1414 TnyAccount *account)
1416 GtkResponseType response;
1418 /* Allways download if we are online. */
1419 if (tny_device_is_online (modest_runtime_get_device ()))
1422 /* If offline, then ask for user permission to download the messages */
1423 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
1424 ngettext("mcen_nc_get_msg",
1426 num_of_uncached_msgs));
1428 if (response == GTK_RESPONSE_CANCEL)
1431 return modest_platform_connect_and_wait((GtkWindow *) win, account);
1435 * Common code for the reply and forward actions
1438 reply_forward (ReplyForwardAction action, ModestWindow *win)
1440 ModestMailOperation *mail_op = NULL;
1441 TnyList *header_list = NULL;
1442 ReplyForwardHelper *rf_helper = NULL;
1443 guint reply_forward_type;
1444 gboolean continue_download = TRUE;
1445 gboolean do_retrieve = TRUE;
1447 g_return_if_fail (MODEST_IS_WINDOW(win));
1449 /* we need an account when editing */
1450 if (!modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE)) {
1451 if (!modest_ui_actions_run_account_setup_wizard (win))
1455 header_list = get_selected_headers (win);
1459 reply_forward_type =
1460 modest_conf_get_int (modest_runtime_get_conf (),
1461 (action == ACTION_FORWARD) ? MODEST_CONF_FORWARD_TYPE : MODEST_CONF_REPLY_TYPE,
1464 /* check if we need to download msg before asking about it */
1465 do_retrieve = (action == ACTION_FORWARD) ||
1466 (reply_forward_type != MODEST_TNY_MSG_REPLY_TYPE_CITE);
1469 gint num_of_unc_msgs;
1471 /* check that the messages have been previously downloaded */
1472 num_of_unc_msgs = header_list_count_uncached_msgs(header_list);
1473 /* If there are any uncached message ask the user
1474 * whether he/she wants to download them. */
1475 if (num_of_unc_msgs) {
1476 TnyAccount *account = get_account_from_header_list (header_list);
1477 continue_download = connect_to_get_msg (win, num_of_unc_msgs, account);
1478 g_object_unref (account);
1482 if (!continue_download) {
1483 g_object_unref (header_list);
1487 /* We assume that we can only select messages of the
1488 same folder and that we reply all of them from the
1489 same account. In fact the interface currently only
1490 allows single selection */
1493 rf_helper = g_slice_new0 (ReplyForwardHelper);
1494 rf_helper->reply_forward_type = reply_forward_type;
1495 rf_helper->action = action;
1496 rf_helper->account_name = g_strdup (modest_window_get_active_account (win));
1498 if ((win != NULL) && (MODEST_IS_WINDOW (win)))
1499 rf_helper->parent_window = GTK_WIDGET (win);
1500 if (!rf_helper->account_name)
1501 rf_helper->account_name =
1502 modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
1504 if (MODEST_IS_MSG_VIEW_WINDOW(win)) {
1507 /* Get header and message. Do not free them here, the
1508 reply_forward_cb must do it */
1509 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW(win));
1510 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW(win));
1511 if (!msg || !header) {
1513 g_object_unref (msg);
1514 g_printerr ("modest: no message found\n");
1517 reply_forward_cb (NULL, header, FALSE, msg, NULL, rf_helper);
1520 g_object_unref (header);
1525 /* Only reply/forward to one message */
1526 iter = tny_list_create_iterator (header_list);
1527 header = TNY_HEADER (tny_iterator_get_current (iter));
1528 g_object_unref (iter);
1531 /* Retrieve messages */
1534 modest_mail_operation_new_with_error_handling (G_OBJECT(win),
1535 modest_ui_actions_get_msgs_full_error_handler,
1537 modest_mail_operation_queue_add (
1538 modest_runtime_get_mail_operation_queue (), mail_op);
1540 modest_mail_operation_get_msg (mail_op,
1545 g_object_unref(mail_op);
1547 /* we put a ref here to prevent double unref as the reply
1548 * forward callback unrefs the header at its end */
1549 reply_forward_cb (NULL, header, FALSE, NULL, NULL, rf_helper);
1553 g_object_unref (header);
1559 g_object_unref (header_list);
1563 modest_ui_actions_on_reply (GtkAction *action, ModestWindow *win)
1565 g_return_if_fail (MODEST_IS_WINDOW(win));
1567 reply_forward (ACTION_REPLY, win);
1571 modest_ui_actions_on_forward (GtkAction *action, ModestWindow *win)
1573 g_return_if_fail (MODEST_IS_WINDOW(win));
1575 reply_forward (ACTION_FORWARD, win);
1579 modest_ui_actions_on_reply_all (GtkAction *action, ModestWindow *win)
1581 g_return_if_fail (MODEST_IS_WINDOW(win));
1583 reply_forward (ACTION_REPLY_TO_ALL, win);
1587 modest_ui_actions_on_next (GtkAction *action,
1588 ModestWindow *window)
1590 if (MODEST_IS_MAIN_WINDOW (window)) {
1591 GtkWidget *header_view;
1593 header_view = modest_main_window_get_child_widget (
1594 MODEST_MAIN_WINDOW(window),
1595 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1599 modest_header_view_select_next (
1600 MODEST_HEADER_VIEW(header_view));
1601 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
1602 modest_msg_view_window_select_next_message (
1603 MODEST_MSG_VIEW_WINDOW (window));
1605 g_return_if_reached ();
1610 modest_ui_actions_on_prev (GtkAction *action,
1611 ModestWindow *window)
1613 g_return_if_fail (MODEST_IS_WINDOW(window));
1615 if (MODEST_IS_MAIN_WINDOW (window)) {
1616 GtkWidget *header_view;
1617 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
1618 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1622 modest_header_view_select_prev (MODEST_HEADER_VIEW(header_view));
1623 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
1624 modest_msg_view_window_select_previous_message (MODEST_MSG_VIEW_WINDOW (window));
1626 g_return_if_reached ();
1631 modest_ui_actions_on_sort (GtkAction *action,
1632 ModestWindow *window)
1634 g_return_if_fail (MODEST_IS_WINDOW(window));
1636 if (MODEST_IS_MAIN_WINDOW (window)) {
1637 GtkWidget *header_view;
1638 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
1639 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1641 modest_platform_information_banner (NULL, NULL, _CS("ckdg_ib_nothing_to_sort"));
1646 /* Show sorting dialog */
1647 modest_platform_run_sort_dialog (GTK_WINDOW (window), MODEST_SORT_HEADERS);
1652 new_messages_arrived (ModestMailOperation *self,
1653 TnyList *new_headers,
1658 source = modest_mail_operation_get_source (self);
1660 /* Notify new messages have been downloaded. Do not notify if
1661 the send&receive was invoked by the user, i.e, if the mail
1662 operation has a source (the main window) */
1663 if ((new_headers != NULL) && (tny_list_get_length (new_headers) > 0) && !source)
1664 modest_platform_on_new_headers_received (new_headers);
1667 g_object_unref (source);
1671 TnyAccount *account;
1673 gchar *account_name;
1677 do_send_receive_performer (gboolean canceled,
1679 GtkWindow *parent_window,
1680 TnyAccount *account,
1683 ModestMailOperation *mail_op;
1684 SendReceiveInfo *info;
1686 info = (SendReceiveInfo *) user_data;
1688 if (err || canceled) {
1693 /* Set send/receive operation in progress */
1694 if (info->win && MODEST_IS_MAIN_WINDOW (info->win)) {
1695 modest_main_window_notify_send_receive_initied (MODEST_MAIN_WINDOW (info->win));
1698 mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT (info->win),
1699 modest_ui_actions_send_receive_error_handler,
1702 if (info->win && MODEST_IS_MAIN_WINDOW (info->win))
1703 g_signal_connect (G_OBJECT(mail_op), "operation-finished",
1704 G_CALLBACK (on_send_receive_finished),
1707 /* Send & receive. */
1708 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
1709 modest_mail_operation_update_account (mail_op, info->account_name, (info->win) ? FALSE : TRUE,
1710 new_messages_arrived, info->win);
1711 g_object_unref (G_OBJECT (mail_op));
1715 if (info->account_name)
1716 g_free (info->account_name);
1718 g_object_unref (info->win);
1720 g_object_unref (info->account);
1721 g_slice_free (SendReceiveInfo, info);
1725 * This function performs the send & receive required actions. The
1726 * window is used to create the mail operation. Typically it should
1727 * always be the main window, but we pass it as argument in order to
1731 modest_ui_actions_do_send_receive (const gchar *account_name,
1734 gchar *acc_name = NULL;
1735 SendReceiveInfo *info;
1736 ModestTnyAccountStore *acc_store;
1738 /* If no account name was provided then get the current account, and if
1739 there is no current account then pick the default one: */
1740 if (!account_name) {
1742 acc_name = g_strdup (modest_window_get_active_account (win));
1744 acc_name = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
1746 g_printerr ("modest: cannot get default account\n");
1750 acc_name = g_strdup (account_name);
1753 acc_store = modest_runtime_get_account_store ();
1755 /* Create the info for the connect and perform */
1756 info = g_slice_new (SendReceiveInfo);
1757 info->account_name = acc_name;
1758 info->win = (win) ? g_object_ref (win) : NULL;
1759 info->account = modest_tny_account_store_get_server_account (acc_store, acc_name,
1760 TNY_ACCOUNT_TYPE_STORE);
1762 /* Invoke the connect and perform */
1763 modest_platform_connect_and_perform ((win) ? GTK_WINDOW (win) : NULL, info->account,
1764 do_send_receive_performer, info);
1769 modest_ui_actions_do_cancel_send (const gchar *account_name,
1772 TnyTransportAccount *transport_account;
1773 TnySendQueue *send_queue = NULL;
1774 GError *error = NULL;
1776 /* Get transport account */
1778 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
1779 (modest_runtime_get_account_store(),
1781 TNY_ACCOUNT_TYPE_TRANSPORT));
1782 if (!transport_account) {
1783 g_printerr ("modest: no transport account found for '%s'\n", account_name);
1788 send_queue = TNY_SEND_QUEUE (modest_runtime_get_send_queue (transport_account));
1789 if (!TNY_IS_SEND_QUEUE(send_queue)) {
1790 g_set_error (&error, MODEST_MAIL_OPERATION_ERROR,
1791 MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND,
1792 "modest: could not find send queue for account\n");
1794 /* Keeep messages in outbox folder */
1795 tny_send_queue_cancel (send_queue, FALSE, &error);
1799 if (transport_account != NULL)
1800 g_object_unref (G_OBJECT (transport_account));
1804 modest_ui_actions_cancel_send_all (ModestWindow *win)
1806 GSList *account_names, *iter;
1808 account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
1811 iter = account_names;
1813 modest_ui_actions_do_cancel_send ((const char*) iter->data, win);
1814 iter = g_slist_next (iter);
1817 modest_account_mgr_free_account_names (account_names);
1818 account_names = NULL;
1822 modest_ui_actions_cancel_send (GtkAction *action, ModestWindow *win)
1825 /* Check if accounts exist */
1826 gboolean accounts_exist =
1827 modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
1829 /* If not, allow the user to create an account before trying to send/receive. */
1830 if (!accounts_exist)
1831 modest_ui_actions_on_accounts (NULL, win);
1833 /* Cancel all sending operaitons */
1834 modest_ui_actions_cancel_send_all (win);
1838 * Refreshes all accounts. This function will be used by automatic
1842 modest_ui_actions_do_send_receive_all (ModestWindow *win)
1844 GSList *account_names, *iter;
1846 account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
1849 iter = account_names;
1851 modest_ui_actions_do_send_receive ((const char*) iter->data, win);
1852 iter = g_slist_next (iter);
1855 modest_account_mgr_free_account_names (account_names);
1856 account_names = NULL;
1860 * Handler of the click on Send&Receive button in the main toolbar
1863 modest_ui_actions_on_send_receive (GtkAction *action, ModestWindow *win)
1865 /* Check if accounts exist */
1866 gboolean accounts_exist =
1867 modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
1869 /* If not, allow the user to create an account before trying to send/receive. */
1870 if (!accounts_exist)
1871 modest_ui_actions_on_accounts (NULL, win);
1873 /* Refresh the active account */
1874 modest_ui_actions_do_send_receive (NULL, win);
1879 modest_ui_actions_toggle_header_list_view (GtkAction *action, ModestMainWindow *main_window)
1882 GtkWidget *header_view;
1884 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1886 header_view = modest_main_window_get_child_widget (main_window,
1887 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1891 conf = modest_runtime_get_conf ();
1893 /* what is saved/restored is depending on the style; thus; we save with
1894 * old style, then update the style, and restore for this new style
1896 modest_widget_memory_save (conf, G_OBJECT(header_view), MODEST_CONF_HEADER_VIEW_KEY);
1898 if (modest_header_view_get_style
1899 (MODEST_HEADER_VIEW(header_view)) == MODEST_HEADER_VIEW_STYLE_DETAILS)
1900 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
1901 MODEST_HEADER_VIEW_STYLE_TWOLINES);
1903 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
1904 MODEST_HEADER_VIEW_STYLE_DETAILS);
1906 modest_widget_memory_restore (conf, G_OBJECT(header_view),
1907 MODEST_CONF_HEADER_VIEW_KEY);
1912 modest_ui_actions_on_header_selected (ModestHeaderView *header_view,
1914 ModestMainWindow *main_window)
1916 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1917 g_return_if_fail (MODEST_IS_HEADER_VIEW (header_view));
1919 /* in the case the folder is empty, show the empty folder message and focus
1921 if (!header && gtk_widget_is_focus (GTK_WIDGET (header_view))) {
1922 if (modest_header_view_is_empty (header_view)) {
1923 TnyFolder *folder = modest_header_view_get_folder (header_view);
1924 GtkWidget *folder_view =
1925 modest_main_window_get_child_widget (main_window,
1926 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
1928 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view), folder, FALSE);
1929 gtk_widget_grab_focus (GTK_WIDGET (folder_view));
1933 /* If no header has been selected then exit */
1938 if (!gtk_widget_is_focus (GTK_WIDGET(header_view)))
1939 gtk_widget_grab_focus (GTK_WIDGET(header_view));
1941 /* Update toolbar dimming state */
1942 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
1946 modest_ui_actions_on_header_activated (ModestHeaderView *header_view,
1948 ModestMainWindow *main_window)
1952 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1957 if (modest_header_view_count_selected_headers (header_view) > 1) {
1958 modest_platform_information_banner (NULL, NULL, _("mcen_ib_select_one_message"));
1963 /* headers = tny_simple_list_new (); */
1964 /* tny_list_prepend (headers, G_OBJECT (header)); */
1965 headers = modest_header_view_get_selected_headers (header_view);
1967 open_msgs_from_headers (headers, MODEST_WINDOW (main_window));
1969 g_object_unref (headers);
1973 set_active_account_from_tny_account (TnyAccount *account,
1974 ModestWindow *window)
1976 const gchar *server_acc_name = tny_account_get_id (account);
1978 /* We need the TnyAccount provided by the
1979 account store because that is the one that
1980 knows the name of the Modest account */
1981 TnyAccount *modest_server_account = modest_server_account =
1982 modest_tny_account_store_get_tny_account_by (modest_runtime_get_account_store (),
1983 MODEST_TNY_ACCOUNT_STORE_QUERY_ID,
1985 if (!modest_server_account) {
1986 g_warning ("%s: could not get tny account\n", __FUNCTION__);
1990 /* Update active account, but only if it's not a pseudo-account */
1991 if ((!modest_tny_account_is_virtual_local_folders(modest_server_account)) &&
1992 (!modest_tny_account_is_memory_card_account(modest_server_account))) {
1993 const gchar *modest_acc_name =
1994 modest_tny_account_get_parent_modest_account_name_for_server_account (modest_server_account);
1995 if (modest_acc_name)
1996 modest_window_set_active_account (window, modest_acc_name);
1999 g_object_unref (modest_server_account);
2004 folder_refreshed_cb (ModestMailOperation *mail_op,
2008 ModestMainWindow *win = NULL;
2009 GtkWidget *header_view;
2010 gboolean folder_empty = FALSE;
2011 gboolean all_marked_as_deleted = FALSE;
2013 g_return_if_fail (TNY_IS_FOLDER (folder));
2015 win = MODEST_MAIN_WINDOW (user_data);
2017 modest_main_window_get_child_widget(win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2020 TnyFolder *current_folder;
2022 current_folder = modest_header_view_get_folder (MODEST_HEADER_VIEW (header_view));
2023 if (current_folder != NULL && folder != current_folder) {
2024 g_object_unref (current_folder);
2027 g_object_unref (current_folder);
2030 /* Check if folder is empty and set headers view contents style */
2031 folder_empty = (tny_folder_get_all_count (folder) == 0);
2032 all_marked_as_deleted = modest_header_view_is_empty (MODEST_HEADER_VIEW(header_view));
2033 if (folder_empty || all_marked_as_deleted)
2034 modest_main_window_set_contents_style (win,
2035 MODEST_MAIN_WINDOW_CONTENTS_STYLE_EMPTY);
2039 modest_ui_actions_on_folder_selection_changed (ModestFolderView *folder_view,
2040 TnyFolderStore *folder_store,
2042 ModestMainWindow *main_window)
2045 GtkWidget *header_view;
2047 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2049 header_view = modest_main_window_get_child_widget(main_window,
2050 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2054 conf = modest_runtime_get_conf ();
2056 if (TNY_IS_ACCOUNT (folder_store)) {
2058 set_active_account_from_tny_account (TNY_ACCOUNT (folder_store), MODEST_WINDOW (main_window));
2060 /* Show account details */
2061 modest_main_window_set_contents_style (main_window, MODEST_MAIN_WINDOW_CONTENTS_STYLE_DETAILS);
2064 if (TNY_IS_FOLDER (folder_store) && selected) {
2066 /* Update the active account */
2067 TnyAccount *account = modest_tny_folder_get_account (TNY_FOLDER (folder_store));
2069 set_active_account_from_tny_account (account, MODEST_WINDOW (main_window));
2070 g_object_unref (account);
2074 /* Set the header style by default, it could
2075 be changed later by the refresh callback to
2077 modest_main_window_set_contents_style (main_window,
2078 MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS);
2080 /* Set folder on header view. This function
2081 will call tny_folder_refresh_async so we
2082 pass a callback that will be called when
2083 finished. We use that callback to set the
2084 empty view if there are no messages */
2085 modest_header_view_set_folder (MODEST_HEADER_VIEW(header_view),
2086 TNY_FOLDER (folder_store),
2087 folder_refreshed_cb,
2090 /* Restore configuration. We need to do this
2091 *after* the set_folder because the widget
2092 memory asks the header view about its
2094 modest_widget_memory_restore (modest_runtime_get_conf (),
2095 G_OBJECT(header_view),
2096 MODEST_CONF_HEADER_VIEW_KEY);
2098 /* Update the active account */
2099 //modest_window_set_active_account (MODEST_WINDOW (main_window), NULL);
2100 /* Save only if we're seeing headers */
2101 if (modest_main_window_get_contents_style (main_window) ==
2102 MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS)
2103 modest_widget_memory_save (conf, G_OBJECT (header_view),
2104 MODEST_CONF_HEADER_VIEW_KEY);
2105 modest_header_view_clear (MODEST_HEADER_VIEW(header_view));
2109 /* Update toolbar dimming state */
2110 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
2114 modest_ui_actions_on_item_not_found (ModestHeaderView *header_view,ModestItemType type,
2121 item = (type == MODEST_ITEM_TYPE_FOLDER) ? "folder" : "message";
2123 online = tny_device_is_online (modest_runtime_get_device());
2126 /* already online -- the item is simply not there... */
2127 dialog = gtk_message_dialog_new (GTK_WINDOW (win),
2129 GTK_MESSAGE_WARNING,
2131 _("The %s you selected cannot be found"),
2133 gtk_dialog_add_button (GTK_DIALOG (dialog),_("mcen_bd_dialog_ok"), GTK_RESPONSE_ACCEPT);
2134 gtk_dialog_run (GTK_DIALOG(dialog));
2136 dialog = gtk_dialog_new_with_buttons (_("Connection requested"),
2139 _("mcen_bd_dialog_cancel"),
2140 GTK_RESPONSE_REJECT,
2141 _("mcen_bd_dialog_ok"),
2142 GTK_RESPONSE_ACCEPT,
2144 txt = g_strdup_printf (_("This %s is not available in offline mode.\n"
2145 "Do you want to get online?"), item);
2146 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
2147 gtk_label_new (txt), FALSE, FALSE, 0);
2148 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
2151 gtk_window_set_default_size (GTK_WINDOW(dialog), 300, 300);
2152 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
2153 /* TODO: Comment about why is this commented out: */
2154 /* modest_platform_connect_and_wait (); */
2157 gtk_widget_destroy (dialog);
2161 modest_ui_actions_on_msg_link_hover (ModestMsgView *msgview, const gchar* link,
2164 /* g_message ("%s %s", __FUNCTION__, link); */
2169 modest_ui_actions_on_msg_link_clicked (ModestMsgView *msgview, const gchar* link,
2172 modest_platform_activate_uri (link);
2176 modest_ui_actions_on_msg_link_contextual (ModestMsgView *msgview, const gchar* link,
2179 modest_platform_show_uri_popup (link);
2183 modest_ui_actions_on_msg_attachment_clicked (ModestMsgView *msgview, TnyMimePart *mime_part,
2186 modest_msg_view_window_view_attachment (MODEST_MSG_VIEW_WINDOW (win), mime_part);
2190 modest_ui_actions_on_msg_recpt_activated (ModestMsgView *msgview,
2191 const gchar *address,
2194 /* g_message ("%s %s", __FUNCTION__, address); */
2198 on_save_to_drafts_cb (ModestMailOperation *mail_op,
2199 TnyMsg *saved_draft,
2202 ModestMsgEditWindow *edit_window;
2203 ModestMainWindow *win;
2205 /* FIXME. Make the header view sensitive again. This is a
2206 * temporary hack. See modest_ui_actions_on_save_to_drafts()
2208 win = MODEST_MAIN_WINDOW(modest_window_mgr_get_main_window(
2209 modest_runtime_get_window_mgr(), FALSE));
2211 GtkWidget *hdrview = modest_main_window_get_child_widget(
2212 win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2213 if (hdrview) gtk_widget_set_sensitive(hdrview, TRUE);
2216 edit_window = MODEST_MSG_EDIT_WINDOW (user_data);
2218 /* If there was any error do nothing */
2219 if (modest_mail_operation_get_error (mail_op) != NULL)
2222 modest_msg_edit_window_set_draft (edit_window, saved_draft);
2226 modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edit_window)
2228 TnyTransportAccount *transport_account;
2229 ModestMailOperation *mail_operation;
2231 gchar *account_name, *from;
2232 ModestAccountMgr *account_mgr;
2235 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window));
2237 data = modest_msg_edit_window_get_msg_data (edit_window);
2239 account_name = g_strdup (data->account_name);
2240 account_mgr = modest_runtime_get_account_mgr();
2242 account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
2244 account_name = modest_account_mgr_get_default_account (account_mgr);
2245 if (!account_name) {
2246 g_printerr ("modest: no account found\n");
2247 modest_msg_edit_window_free_msg_data (edit_window, data);
2251 if (!strcmp (account_name, MODEST_LOCAL_FOLDERS_ACCOUNT_ID)) {
2252 account_name = g_strdup (data->account_name);
2256 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
2257 (modest_runtime_get_account_store(),
2259 TNY_ACCOUNT_TYPE_TRANSPORT));
2260 if (!transport_account) {
2261 g_printerr ("modest: no transport account found for '%s'\n", account_name);
2262 g_free (account_name);
2263 modest_msg_edit_window_free_msg_data (edit_window, data);
2266 from = modest_account_mgr_get_from_string (account_mgr, account_name);
2268 /* Create the mail operation */
2269 mail_operation = modest_mail_operation_new (G_OBJECT(edit_window));
2270 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
2272 modest_mail_operation_save_to_drafts (mail_operation,
2284 data->priority_flags,
2285 on_save_to_drafts_cb,
2287 info_text = g_strdup_printf (_("mail_va_saved_to_drafts"), _("mcen_me_folder_drafts"));
2288 modest_platform_information_banner (NULL, NULL, info_text);
2293 g_free (account_name);
2294 g_object_unref (G_OBJECT (transport_account));
2295 g_object_unref (G_OBJECT (mail_operation));
2297 modest_msg_edit_window_free_msg_data (edit_window, data);
2298 modest_msg_edit_window_reset_modified (edit_window);
2301 * If the drafts folder is selected then make the header view
2302 * insensitive while the message is being saved to drafts
2303 * (it'll be sensitive again in on_save_to_drafts_cb()). This
2304 * is not very clean but it avoids letting the drafts folder
2305 * in an inconsistent state: the user could edit the message
2306 * being saved and undesirable things would happen.
2307 * In the average case the user won't notice anything at
2308 * all. In the worst case (the user is editing a really big
2309 * file from Drafts) the header view will be insensitive
2310 * during the saving process (10 or 20 seconds, depending on
2311 * the message). Anyway this is just a quick workaround: once
2312 * we find a better solution it should be removed
2313 * See NB#65125 (commend #18) for details.
2315 ModestMainWindow *win = MODEST_MAIN_WINDOW(modest_window_mgr_get_main_window(
2316 modest_runtime_get_window_mgr(), FALSE));
2318 ModestFolderView *view = MODEST_FOLDER_VIEW(modest_main_window_get_child_widget(
2319 win, MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW));
2321 TnyFolder *folder = TNY_FOLDER(modest_folder_view_get_selected(view));
2323 if (modest_tny_folder_is_local_folder(folder)) {
2324 TnyFolderType folder_type;
2325 folder_type = modest_tny_folder_get_local_or_mmc_folder_type(folder);
2326 if (folder_type == TNY_FOLDER_TYPE_DRAFTS) {
2327 GtkWidget *hdrview = modest_main_window_get_child_widget(
2328 win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2329 if (hdrview) gtk_widget_set_sensitive(hdrview, FALSE);
2333 if (folder != NULL) g_object_unref(folder);
2338 /* For instance, when clicking the Send toolbar button when editing a message: */
2340 modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
2342 TnyTransportAccount *transport_account = NULL;
2344 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window));
2346 if (!modest_msg_edit_window_check_names (edit_window, TRUE))
2349 /* FIXME: Code added just for testing. The final version will
2350 use the send queue provided by tinymail and some
2352 MsgData *data = modest_msg_edit_window_get_msg_data (edit_window);
2354 ModestAccountMgr *account_mgr = modest_runtime_get_account_mgr();
2355 gchar *account_name = g_strdup (data->account_name);
2357 g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
2360 account_name = modest_account_mgr_get_default_account (account_mgr);
2362 if (!account_name) {
2363 modest_msg_edit_window_free_msg_data (edit_window, data);
2364 /* Run account setup wizard */
2365 if (!modest_ui_actions_run_account_setup_wizard (MODEST_WINDOW(edit_window)))
2369 /* Get the currently-active transport account for this modest account: */
2370 /* TnyTransportAccount *transport_account = */
2371 /* TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_transport_account_for_open_connection */
2372 /* (modest_runtime_get_account_store(), */
2373 /* account_name)); */
2374 if (strcmp (account_name, MODEST_LOCAL_FOLDERS_ACCOUNT_ID) != 0) {
2375 transport_account = TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
2376 (modest_runtime_get_account_store(),
2377 account_name, TNY_ACCOUNT_TYPE_TRANSPORT));
2380 if (!transport_account) {
2381 /* Run account setup wizard */
2382 if (!modest_ui_actions_run_account_setup_wizard(MODEST_WINDOW(edit_window)))
2386 gchar *from = modest_account_mgr_get_from_string (account_mgr, account_name);
2388 /* Create the mail operation */
2389 ModestMailOperation *mail_operation = modest_mail_operation_new (G_OBJECT(edit_window));
2390 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
2392 modest_mail_operation_send_new_mail (mail_operation,
2404 data->priority_flags);
2406 if (modest_mail_operation_get_status (mail_operation) == MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS)
2407 modest_platform_information_banner (NULL, NULL, _("mcen_ib_outbox_waiting_to_be_sent"));
2412 g_free (account_name);
2413 g_object_unref (G_OBJECT (transport_account));
2414 g_object_unref (G_OBJECT (mail_operation));
2416 modest_msg_edit_window_free_msg_data (edit_window, data);
2417 modest_msg_edit_window_set_sent (edit_window, TRUE);
2419 /* Save settings and close the window: */
2420 modest_ui_actions_on_close_window (NULL, MODEST_WINDOW (edit_window));
2424 modest_ui_actions_on_toggle_bold (GtkToggleAction *action,
2425 ModestMsgEditWindow *window)
2427 ModestMsgEditFormatState *format_state = NULL;
2429 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2430 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
2432 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2435 format_state = modest_msg_edit_window_get_format_state (window);
2436 g_return_if_fail (format_state != NULL);
2438 format_state->bold = gtk_toggle_action_get_active (action);
2439 modest_msg_edit_window_set_format_state (window, format_state);
2440 g_free (format_state);
2445 modest_ui_actions_on_toggle_italics (GtkToggleAction *action,
2446 ModestMsgEditWindow *window)
2448 ModestMsgEditFormatState *format_state = NULL;
2450 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2451 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
2453 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2456 format_state = modest_msg_edit_window_get_format_state (window);
2457 g_return_if_fail (format_state != NULL);
2459 format_state->italics = gtk_toggle_action_get_active (action);
2460 modest_msg_edit_window_set_format_state (window, format_state);
2461 g_free (format_state);
2466 modest_ui_actions_on_toggle_bullets (GtkToggleAction *action,
2467 ModestMsgEditWindow *window)
2469 ModestMsgEditFormatState *format_state = NULL;
2471 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2472 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
2474 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2477 format_state = modest_msg_edit_window_get_format_state (window);
2478 g_return_if_fail (format_state != NULL);
2480 format_state->bullet = gtk_toggle_action_get_active (action);
2481 modest_msg_edit_window_set_format_state (window, format_state);
2482 g_free (format_state);
2487 modest_ui_actions_on_change_justify (GtkRadioAction *action,
2488 GtkRadioAction *selected,
2489 ModestMsgEditWindow *window)
2491 ModestMsgEditFormatState *format_state = NULL;
2492 GtkJustification value;
2494 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2496 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2499 value = gtk_radio_action_get_current_value (selected);
2501 format_state = modest_msg_edit_window_get_format_state (window);
2502 g_return_if_fail (format_state != NULL);
2504 format_state->justification = value;
2505 modest_msg_edit_window_set_format_state (window, format_state);
2506 g_free (format_state);
2510 modest_ui_actions_on_select_editor_color (GtkAction *action,
2511 ModestMsgEditWindow *window)
2513 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2514 g_return_if_fail (GTK_IS_ACTION (action));
2516 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2519 modest_msg_edit_window_select_color (window);
2523 modest_ui_actions_on_select_editor_background_color (GtkAction *action,
2524 ModestMsgEditWindow *window)
2526 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2527 g_return_if_fail (GTK_IS_ACTION (action));
2529 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2532 modest_msg_edit_window_select_background_color (window);
2536 modest_ui_actions_on_insert_image (GtkAction *action,
2537 ModestMsgEditWindow *window)
2539 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2540 g_return_if_fail (GTK_IS_ACTION (action));
2542 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2545 modest_msg_edit_window_insert_image (window);
2549 modest_ui_actions_on_attach_file (GtkAction *action,
2550 ModestMsgEditWindow *window)
2552 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2553 g_return_if_fail (GTK_IS_ACTION (action));
2555 modest_msg_edit_window_offer_attach_file (window);
2559 modest_ui_actions_on_remove_attachments (GtkAction *action,
2560 ModestMsgEditWindow *window)
2562 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2563 g_return_if_fail (GTK_IS_ACTION (action));
2565 modest_msg_edit_window_remove_attachments (window, NULL);
2569 modest_ui_actions_new_folder_error_handler (ModestMailOperation *mail_op,
2572 ModestMainWindow *window = MODEST_MAIN_WINDOW (user_data);
2573 const GError *error = modest_mail_operation_get_error (mail_op);
2576 modest_platform_information_banner (GTK_WIDGET (window), NULL,
2577 _("mail_in_ui_folder_create_error"));
2582 modest_ui_actions_create_folder(GtkWidget *parent_window,
2583 GtkWidget *folder_view)
2585 TnyFolderStore *parent_folder;
2587 parent_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
2589 if (parent_folder) {
2590 gboolean finished = FALSE;
2592 gchar *folder_name = NULL, *suggested_name = NULL;
2593 const gchar *proto_str = NULL;
2594 TnyAccount *account;
2596 if (TNY_IS_ACCOUNT (parent_folder))
2597 account = g_object_ref (parent_folder);
2599 account = tny_folder_get_account (TNY_FOLDER (parent_folder));
2600 proto_str = tny_account_get_proto (TNY_ACCOUNT (account));
2602 if (proto_str && modest_protocol_info_get_transport_store_protocol (proto_str) ==
2603 MODEST_PROTOCOL_STORE_POP) {
2605 modest_platform_information_banner (NULL, NULL, _("mail_in_ui_folder_create_error"));
2607 g_object_unref (account);
2609 /* Run the new folder dialog */
2611 result = modest_platform_run_new_folder_dialog (GTK_WINDOW (parent_window),
2616 g_free (suggested_name);
2617 suggested_name = NULL;
2619 if (result == GTK_RESPONSE_ACCEPT) {
2620 ModestMailOperation *mail_op;
2621 TnyFolder *new_folder = NULL;
2623 mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT(parent_window),
2624 modest_ui_actions_new_folder_error_handler,
2625 parent_window, NULL);
2627 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
2629 new_folder = modest_mail_operation_create_folder (mail_op,
2631 (const gchar *) folder_name);
2633 modest_folder_view_select_folder (MODEST_FOLDER_VIEW(folder_view),
2636 g_object_unref (new_folder);
2639 g_object_unref (mail_op);
2644 suggested_name = folder_name;
2648 g_object_unref (parent_folder);
2653 modest_ui_actions_on_new_folder (GtkAction *action, ModestMainWindow *main_window)
2655 GtkWidget *folder_view;
2657 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2659 folder_view = modest_main_window_get_child_widget (main_window,
2660 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2664 modest_ui_actions_create_folder (GTK_WIDGET (main_window), folder_view);
2668 modest_ui_actions_rename_folder_error_handler (ModestMailOperation *mail_op,
2671 ModestMainWindow *window = MODEST_MAIN_WINDOW (user_data);
2672 const GError *error = NULL;
2673 const gchar *message = NULL;
2675 /* Get error message */
2676 error = modest_mail_operation_get_error (mail_op);
2678 g_return_if_reached ();
2680 switch (error->code) {
2681 case MODEST_MAIL_OPERATION_ERROR_FOLDER_EXISTS:
2682 message = _CS("ckdg_ib_folder_already_exists");
2685 g_warning ("%s: BUG: unexpected error:[%d]: %s", __FUNCTION__,
2686 error->code, error->message);
2690 modest_platform_information_banner (GTK_WIDGET (window), NULL, message);
2694 modest_ui_actions_on_rename_folder (GtkAction *action,
2695 ModestMainWindow *main_window)
2697 TnyFolderStore *folder;
2698 GtkWidget *folder_view;
2699 GtkWidget *header_view;
2701 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2703 folder_view = modest_main_window_get_child_widget (main_window,
2704 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2708 header_view = modest_main_window_get_child_widget (main_window,
2709 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2714 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
2719 if (TNY_IS_FOLDER (folder)) {
2722 const gchar *current_name;
2723 TnyFolderStore *parent;
2724 gboolean do_rename = TRUE;
2726 current_name = tny_folder_get_name (TNY_FOLDER (folder));
2727 parent = tny_folder_get_folder_store (TNY_FOLDER (folder));
2728 response = modest_platform_run_rename_folder_dialog (GTK_WINDOW (main_window),
2729 parent, current_name,
2731 g_object_unref (parent);
2733 if (response != GTK_RESPONSE_ACCEPT || strlen (folder_name) == 0) {
2735 } else if (modest_tny_folder_store_is_remote(folder) &&
2736 !tny_device_is_online (modest_runtime_get_device())) {
2737 TnyAccount *account = tny_folder_get_account(TNY_FOLDER(folder));
2738 do_rename = modest_platform_connect_and_wait(GTK_WINDOW(main_window), account);
2739 g_object_unref(account);
2743 ModestMailOperation *mail_op;
2744 GtkTreeSelection *sel = NULL;
2747 modest_mail_operation_new_with_error_handling (G_OBJECT(main_window),
2748 modest_ui_actions_rename_folder_error_handler,
2751 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
2754 /* Clear the headers view */
2755 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_view));
2756 gtk_tree_selection_unselect_all (sel);
2758 /* Select *after* the changes */
2759 modest_folder_view_select_folder (MODEST_FOLDER_VIEW(folder_view),
2760 TNY_FOLDER(folder), TRUE);
2762 /* Actually rename the folder */
2763 modest_mail_operation_rename_folder (mail_op,
2764 TNY_FOLDER (folder),
2765 (const gchar *) folder_name);
2767 g_object_unref (mail_op);
2768 g_free (folder_name);
2771 g_object_unref (folder);
2775 modest_ui_actions_delete_folder_error_handler (ModestMailOperation *mail_op,
2778 GObject *win = modest_mail_operation_get_source (mail_op);
2780 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
2781 _("mail_in_ui_folder_delete_error"));
2782 g_object_unref (win);
2786 delete_folder (ModestMainWindow *main_window, gboolean move_to_trash)
2788 TnyFolderStore *folder;
2789 GtkWidget *folder_view;
2792 gboolean do_delete = TRUE;
2794 g_return_val_if_fail (MODEST_IS_MAIN_WINDOW (main_window), FALSE);
2796 folder_view = modest_main_window_get_child_widget (main_window,
2797 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2801 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
2803 /* Show an error if it's an account */
2804 if (!TNY_IS_FOLDER (folder)) {
2805 modest_platform_run_information_dialog (GTK_WINDOW (main_window),
2806 _("mail_in_ui_folder_delete_error"));
2807 g_object_unref (G_OBJECT (folder));
2812 message = g_strdup_printf (_("mcen_nc_delete_folder_text"),
2813 tny_folder_get_name (TNY_FOLDER (folder)));
2814 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (main_window),
2815 (const gchar *) message);
2818 if (response != GTK_RESPONSE_OK) {
2820 } else if (modest_tny_folder_store_is_remote(folder) &&
2821 !tny_device_is_online (modest_runtime_get_device())) {
2822 TnyAccount *account = tny_folder_get_account(TNY_FOLDER(folder));
2823 do_delete = modest_platform_connect_and_wait(GTK_WINDOW(main_window), account);
2824 g_object_unref(account);
2828 ModestMailOperation *mail_op;
2829 GtkTreeSelection *sel;
2831 /* Unselect the folder before deleting it to free the headers */
2832 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_view));
2833 gtk_tree_selection_unselect_all (sel);
2835 /* Create the mail operation */
2837 modest_mail_operation_new_with_error_handling (G_OBJECT(main_window),
2838 modest_ui_actions_delete_folder_error_handler,
2841 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
2843 modest_mail_operation_remove_folder (mail_op, TNY_FOLDER (folder), move_to_trash);
2844 g_object_unref (G_OBJECT (mail_op));
2847 g_object_unref (G_OBJECT (folder));
2853 modest_ui_actions_on_delete_folder (GtkAction *action,
2854 ModestMainWindow *main_window)
2856 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2858 if (delete_folder (main_window, FALSE)) {
2859 GtkWidget *folder_view;
2861 folder_view = modest_main_window_get_child_widget (main_window,
2862 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2863 modest_folder_view_select_first_inbox_or_local (MODEST_FOLDER_VIEW (folder_view));
2868 modest_ui_actions_on_move_folder_to_trash_folder (GtkAction *action, ModestMainWindow *main_window)
2870 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2872 delete_folder (main_window, TRUE);
2877 show_error (GtkWidget *parent_widget, const gchar* text)
2879 modest_platform_information_banner(parent_widget, NULL, text);
2882 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_window, text)); */
2884 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
2891 gtk_dialog_run (dialog);
2892 gtk_widget_destroy (GTK_WIDGET (dialog));
2897 modest_ui_actions_on_password_requested (TnyAccountStore *account_store,
2898 const gchar* server_account_name,
2903 ModestMainWindow *main_window)
2905 g_return_if_fail(server_account_name);
2907 /* Initalize output parameters: */
2914 #ifdef MODEST_PLATFORM_MAEMO
2915 /* Maemo uses a different (awkward) button order,
2916 * It should probably just use gtk_alternative_dialog_button_order ().
2918 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
2921 _("mcen_bd_dialog_ok"),
2922 GTK_RESPONSE_ACCEPT,
2923 _("mcen_bd_dialog_cancel"),
2924 GTK_RESPONSE_REJECT,
2927 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
2931 GTK_RESPONSE_REJECT,
2933 GTK_RESPONSE_ACCEPT,
2935 #endif /* MODEST_PLATFORM_MAEMO */
2937 gtk_window_set_transient_for (GTK_WINDOW(dialog), GTK_WINDOW(main_window));
2939 gchar *server_name = modest_account_mgr_get_server_account_hostname (
2940 modest_runtime_get_account_mgr(), server_account_name);
2941 if (!server_name) {/* This happened once, though I don't know why. murrayc. */
2942 g_warning("%s: Could not get server name for server account '%s'", __FUNCTION__, server_account_name);
2948 /* This causes a warning because the logical ID has no %s in it,
2949 * though the translation does, but there is not much we can do about that: */
2950 gchar *txt = g_strdup_printf (_("mail_ia_password_info"), server_name);
2951 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), gtk_label_new(txt),
2954 g_free (server_name);
2958 gchar *initial_username = modest_account_mgr_get_server_account_username (
2959 modest_runtime_get_account_mgr(), server_account_name);
2961 GtkWidget *entry_username = gtk_entry_new ();
2962 if (initial_username)
2963 gtk_entry_set_text (GTK_ENTRY (entry_username), initial_username);
2964 /* Dim this if a connection has ever succeeded with this username,
2965 * as per the UI spec: */
2966 const gboolean username_known =
2967 modest_account_mgr_get_server_account_username_has_succeeded(
2968 modest_runtime_get_account_mgr(), server_account_name);
2969 gtk_widget_set_sensitive (entry_username, !username_known);
2971 #ifdef MODEST_PLATFORM_MAEMO
2972 /* Auto-capitalization is the default, so let's turn it off: */
2973 hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_username), HILDON_GTK_INPUT_MODE_FULL);
2975 /* Create a size group to be used by all captions.
2976 * Note that HildonCaption does not create a default size group if we do not specify one.
2977 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
2978 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
2980 GtkWidget *caption = hildon_caption_new (sizegroup,
2981 _("mail_fi_username"), entry_username, NULL, HILDON_CAPTION_MANDATORY);
2982 gtk_widget_show (entry_username);
2983 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
2984 FALSE, FALSE, MODEST_MARGIN_HALF);
2985 gtk_widget_show (caption);
2987 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry_username,
2989 #endif /* MODEST_PLATFORM_MAEMO */
2992 GtkWidget *entry_password = gtk_entry_new ();
2993 gtk_entry_set_visibility (GTK_ENTRY(entry_password), FALSE);
2994 /* gtk_entry_set_invisible_char (GTK_ENTRY(entry_password), "*"); */
2996 #ifdef MODEST_PLATFORM_MAEMO
2997 /* Auto-capitalization is the default, so let's turn it off: */
2998 hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_password),
2999 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
3001 caption = hildon_caption_new (sizegroup,
3002 _("mail_fi_password"), entry_password, NULL, HILDON_CAPTION_MANDATORY);
3003 gtk_widget_show (entry_password);
3004 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
3005 FALSE, FALSE, MODEST_MARGIN_HALF);
3006 gtk_widget_show (caption);
3007 g_object_unref (sizegroup);
3009 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry_password,
3011 #endif /* MODEST_PLATFORM_MAEMO */
3013 if (initial_username != NULL)
3014 gtk_widget_grab_focus (GTK_WIDGET (entry_password));
3016 /* This is not in the Maemo UI spec:
3017 remember_pass_check = gtk_check_button_new_with_label (_("Remember password"));
3018 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), remember_pass_check,
3022 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
3024 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
3026 *username = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_username)));
3028 modest_account_mgr_set_server_account_username (
3029 modest_runtime_get_account_mgr(), server_account_name,
3032 const gboolean username_was_changed =
3033 (strcmp (*username, initial_username) != 0);
3034 if (username_was_changed) {
3035 g_warning ("%s: tinymail does not yet support changing the "
3036 "username in the get_password() callback.\n", __FUNCTION__);
3041 *password = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_password)));
3043 /* We do not save the password in the configuration,
3044 * because this function is only called for passwords that should
3045 * not be remembered:
3046 modest_server_account_set_password (
3047 modest_runtime_get_account_mgr(), server_account_name,
3056 show_error(GTK_WIDGET (main_window), _("mail_ib_login_cancelled"));
3068 /* This is not in the Maemo UI spec:
3069 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (remember_pass_check)))
3075 gtk_widget_destroy (dialog);
3077 /* printf ("DEBUG: %s: cancel=%d\n", __FUNCTION__, *cancel); */
3081 modest_ui_actions_on_cut (GtkAction *action,
3082 ModestWindow *window)
3084 GtkWidget *focused_widget;
3085 GtkClipboard *clipboard;
3087 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
3088 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
3089 if (GTK_IS_EDITABLE (focused_widget)) {
3090 gtk_editable_cut_clipboard (GTK_EDITABLE(focused_widget));
3091 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3092 gtk_clipboard_store (clipboard);
3093 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
3094 GtkTextBuffer *buffer;
3096 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
3097 gtk_text_buffer_cut_clipboard (buffer, clipboard, TRUE);
3098 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3099 gtk_clipboard_store (clipboard);
3100 } else if (MODEST_IS_HEADER_VIEW (focused_widget)) {
3101 TnyList *header_list = modest_header_view_get_selected_headers (
3102 MODEST_HEADER_VIEW (focused_widget));
3103 gboolean continue_download = FALSE;
3104 gint num_of_unc_msgs;
3106 num_of_unc_msgs = header_list_count_uncached_msgs(header_list);
3108 if (num_of_unc_msgs) {
3109 TnyAccount *account = get_account_from_header_list (header_list);
3110 continue_download = connect_to_get_msg (window, num_of_unc_msgs, account);
3111 g_object_unref (account);
3114 if (num_of_unc_msgs == 0 || continue_download) {
3115 /* modest_platform_information_banner (
3116 NULL, NULL, _CS("mcen_ib_getting_items"));*/
3117 modest_header_view_cut_selection (
3118 MODEST_HEADER_VIEW (focused_widget));
3121 g_object_unref (header_list);
3122 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
3123 modest_folder_view_cut_selection (MODEST_FOLDER_VIEW (focused_widget));
3128 modest_ui_actions_on_copy (GtkAction *action,
3129 ModestWindow *window)
3131 GtkClipboard *clipboard;
3132 GtkWidget *focused_widget;
3133 gboolean copied = TRUE;
3135 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
3136 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
3138 if (GTK_IS_LABEL (focused_widget)) {
3139 gtk_clipboard_set_text (clipboard, gtk_label_get_text (GTK_LABEL (focused_widget)), -1);
3140 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3141 gtk_clipboard_store (clipboard);
3142 } else if (GTK_IS_EDITABLE (focused_widget)) {
3143 gtk_editable_copy_clipboard (GTK_EDITABLE(focused_widget));
3144 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3145 gtk_clipboard_store (clipboard);
3146 } else if (GTK_IS_HTML (focused_widget)) {
3147 gtk_html_copy (GTK_HTML (focused_widget));
3148 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3149 gtk_clipboard_store (clipboard);
3150 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
3151 GtkTextBuffer *buffer;
3152 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
3153 gtk_text_buffer_copy_clipboard (buffer, clipboard);
3154 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3155 gtk_clipboard_store (clipboard);
3156 } else if (MODEST_IS_HEADER_VIEW (focused_widget)) {
3157 TnyList *header_list = modest_header_view_get_selected_headers (
3158 MODEST_HEADER_VIEW (focused_widget));
3159 gboolean continue_download = FALSE;
3160 gint num_of_unc_msgs;
3162 num_of_unc_msgs = header_list_count_uncached_msgs(header_list);
3164 if (num_of_unc_msgs) {
3165 TnyAccount *account = get_account_from_header_list (header_list);
3166 continue_download = connect_to_get_msg (window, num_of_unc_msgs, account);
3167 g_object_unref (account);
3170 if (num_of_unc_msgs == 0 || continue_download) {
3171 modest_platform_information_banner (
3172 NULL, NULL, _CS("mcen_ib_getting_items"));
3173 modest_header_view_copy_selection (
3174 MODEST_HEADER_VIEW (focused_widget));
3178 g_object_unref (header_list);
3180 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
3181 modest_folder_view_copy_selection (MODEST_FOLDER_VIEW (focused_widget));
3184 /* Show information banner if there was a copy to clipboard */
3186 modest_platform_information_banner (
3187 NULL, NULL, _CS("ecoc_ib_edwin_copied"));
3191 modest_ui_actions_on_undo (GtkAction *action,
3192 ModestWindow *window)
3194 ModestEmailClipboard *clipboard = NULL;
3196 if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
3197 modest_msg_edit_window_undo (MODEST_MSG_EDIT_WINDOW (window));
3198 } else if (MODEST_IS_MAIN_WINDOW (window)) {
3199 /* Clear clipboard source */
3200 clipboard = modest_runtime_get_email_clipboard ();
3201 modest_email_clipboard_clear (clipboard);
3204 g_return_if_reached ();
3209 modest_ui_actions_on_redo (GtkAction *action,
3210 ModestWindow *window)
3212 if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
3213 modest_msg_edit_window_redo (MODEST_MSG_EDIT_WINDOW (window));
3216 g_return_if_reached ();
3222 destroy_information_note (ModestMailOperation *mail_op, gpointer user_data)
3224 /* destroy information note */
3225 gtk_widget_destroy (GTK_WIDGET(user_data));
3230 paste_as_attachment_free (gpointer data)
3232 PasteAsAttachmentHelper *helper = (PasteAsAttachmentHelper *) data;
3234 gtk_widget_destroy (helper->banner);
3235 g_object_unref (helper->banner);
3240 paste_msg_as_attachment_cb (ModestMailOperation *mail_op,
3245 PasteAsAttachmentHelper *helper = (PasteAsAttachmentHelper *) userdata;
3246 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (helper->window));
3251 modest_msg_edit_window_add_part (MODEST_MSG_EDIT_WINDOW (helper->window), TNY_MIME_PART (msg));
3256 modest_ui_actions_on_paste (GtkAction *action,
3257 ModestWindow *window)
3259 GtkWidget *focused_widget = NULL;
3260 GtkWidget *inf_note = NULL;
3261 ModestMailOperation *mail_op = NULL;
3263 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
3264 if (GTK_IS_EDITABLE (focused_widget)) {
3265 gtk_editable_paste_clipboard (GTK_EDITABLE(focused_widget));
3266 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
3267 ModestEmailClipboard *e_clipboard = NULL;
3268 e_clipboard = modest_runtime_get_email_clipboard ();
3269 if (modest_email_clipboard_cleared (e_clipboard)) {
3270 GtkTextBuffer *buffer;
3271 GtkClipboard *clipboard;
3273 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
3274 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
3275 gtk_text_buffer_paste_clipboard (buffer, clipboard, NULL, TRUE);
3276 } else if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
3277 ModestMailOperation *mail_op;
3278 TnyFolder *src_folder;
3281 PasteAsAttachmentHelper *helper = g_new0 (PasteAsAttachmentHelper, 1);
3282 helper->window = MODEST_MSG_EDIT_WINDOW (window);
3283 helper->banner = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
3284 _CS("ckct_nw_pasting"));
3285 modest_email_clipboard_get_data (e_clipboard, &src_folder, &data, &delete);
3286 mail_op = modest_mail_operation_new (G_OBJECT (window));
3287 if (helper->banner != NULL) {
3288 g_object_ref (G_OBJECT (helper->banner));
3289 gtk_window_set_modal (GTK_WINDOW (helper->banner), FALSE);
3290 gtk_widget_show (GTK_WIDGET (helper->banner));
3294 modest_mail_operation_get_msgs_full (mail_op,
3296 (GetMsgAsyncUserCallback) paste_msg_as_attachment_cb,
3298 paste_as_attachment_free);
3301 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
3302 ModestEmailClipboard *clipboard = NULL;
3303 TnyFolder *src_folder = NULL;
3304 TnyFolderStore *folder_store = NULL;
3305 TnyList *data = NULL;
3306 gboolean delete = FALSE;
3308 /* Check clipboard source */
3309 clipboard = modest_runtime_get_email_clipboard ();
3310 if (modest_email_clipboard_cleared (clipboard))
3313 /* Get elements to paste */
3314 modest_email_clipboard_get_data (clipboard, &src_folder, &data, &delete);
3316 /* Create a new mail operation */
3317 mail_op = modest_mail_operation_new (G_OBJECT(window));
3319 /* Get destination folder */
3320 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (focused_widget));
3322 /* transfer messages */
3326 /* Ask for user confirmation */
3328 modest_ui_actions_msgs_move_to_confirmation (window,
3329 TNY_FOLDER (folder_store),
3333 if (response == GTK_RESPONSE_OK) {
3334 /* Launch notification */
3335 inf_note = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
3336 _CS("ckct_nw_pasting"));
3337 if (inf_note != NULL) {
3338 gtk_window_set_modal (GTK_WINDOW(inf_note), FALSE);
3339 gtk_widget_show (GTK_WIDGET(inf_note));
3342 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
3343 modest_mail_operation_xfer_msgs (mail_op,
3345 TNY_FOLDER (folder_store),
3347 destroy_information_note,
3350 g_object_unref (mail_op);
3353 } else if (src_folder != NULL) {
3354 /* Launch notification */
3355 inf_note = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
3356 _CS("ckct_nw_pasting"));
3357 if (inf_note != NULL) {
3358 gtk_window_set_modal (GTK_WINDOW(inf_note), FALSE);
3359 gtk_widget_show (GTK_WIDGET(inf_note));
3362 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
3363 modest_mail_operation_xfer_folder (mail_op,
3367 destroy_information_note,
3373 g_object_unref (data);
3374 if (src_folder != NULL)
3375 g_object_unref (src_folder);
3376 if (folder_store != NULL)
3377 g_object_unref (folder_store);
3383 modest_ui_actions_on_select_all (GtkAction *action,
3384 ModestWindow *window)
3386 GtkWidget *focused_widget;
3388 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
3389 if (MODEST_IS_ATTACHMENTS_VIEW (focused_widget)) {
3390 modest_attachments_view_select_all (MODEST_ATTACHMENTS_VIEW (focused_widget));
3391 } else if (GTK_IS_LABEL (focused_widget)) {
3392 gtk_label_select_region (GTK_LABEL (focused_widget), 0, -1);
3393 } else if (GTK_IS_EDITABLE (focused_widget)) {
3394 gtk_editable_select_region (GTK_EDITABLE(focused_widget), 0, -1);
3395 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
3396 GtkTextBuffer *buffer;
3397 GtkTextIter start, end;
3399 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
3400 gtk_text_buffer_get_start_iter (buffer, &start);
3401 gtk_text_buffer_get_end_iter (buffer, &end);
3402 gtk_text_buffer_select_range (buffer, &start, &end);
3403 } else if (GTK_IS_HTML (focused_widget)) {
3404 gtk_html_select_all (GTK_HTML (focused_widget));
3405 } else if (MODEST_IS_MAIN_WINDOW (window)) {
3406 GtkWidget *header_view = focused_widget;
3407 GtkTreeSelection *selection = NULL;
3409 if (!(MODEST_IS_HEADER_VIEW (focused_widget))) {
3410 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (window),
3411 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
3414 /* Disable window dimming management */
3415 modest_window_disable_dimming (MODEST_WINDOW(window));
3417 /* Select all messages */
3418 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(header_view));
3419 gtk_tree_selection_select_all (selection);
3421 /* Set focuse on header view */
3422 gtk_widget_grab_focus (header_view);
3425 /* Enable window dimming management */
3426 modest_window_enable_dimming (MODEST_WINDOW(window));
3427 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (window));
3433 modest_ui_actions_on_mark_as_read (GtkAction *action,
3434 ModestWindow *window)
3436 g_return_if_fail (MODEST_IS_WINDOW(window));
3438 /* Mark each header as read */
3439 do_headers_action (window, headers_action_mark_as_read, NULL);
3443 modest_ui_actions_on_mark_as_unread (GtkAction *action,
3444 ModestWindow *window)
3446 g_return_if_fail (MODEST_IS_WINDOW(window));
3448 /* Mark each header as read */
3449 do_headers_action (window, headers_action_mark_as_unread, NULL);
3453 modest_ui_actions_on_change_zoom (GtkRadioAction *action,
3454 GtkRadioAction *selected,
3455 ModestWindow *window)
3459 value = gtk_radio_action_get_current_value (selected);
3460 if (MODEST_IS_WINDOW (window)) {
3461 modest_window_set_zoom (MODEST_WINDOW (window), ((gdouble)value)/100);
3466 modest_ui_actions_msg_edit_on_change_priority (GtkRadioAction *action,
3467 GtkRadioAction *selected,
3468 ModestWindow *window)
3470 TnyHeaderFlags flags;
3471 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3473 flags = gtk_radio_action_get_current_value (selected);
3474 modest_msg_edit_window_set_priority_flags (MODEST_MSG_EDIT_WINDOW (window), flags);
3478 modest_ui_actions_msg_edit_on_change_file_format (GtkRadioAction *action,
3479 GtkRadioAction *selected,
3480 ModestWindow *window)
3484 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3486 file_format = gtk_radio_action_get_current_value (selected);
3487 modest_msg_edit_window_set_file_format (MODEST_MSG_EDIT_WINDOW (window), file_format);
3492 modest_ui_actions_on_zoom_plus (GtkAction *action,
3493 ModestWindow *window)
3495 g_return_if_fail (MODEST_IS_WINDOW (window));
3497 modest_window_zoom_plus (MODEST_WINDOW (window));
3501 modest_ui_actions_on_zoom_minus (GtkAction *action,
3502 ModestWindow *window)
3504 g_return_if_fail (MODEST_IS_WINDOW (window));
3506 modest_window_zoom_minus (MODEST_WINDOW (window));
3510 modest_ui_actions_on_toggle_fullscreen (GtkToggleAction *toggle,
3511 ModestWindow *window)
3513 ModestWindowMgr *mgr;
3514 gboolean fullscreen, active;
3515 g_return_if_fail (MODEST_IS_WINDOW (window));
3517 mgr = modest_runtime_get_window_mgr ();
3519 active = (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle)))?1:0;
3520 fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
3522 if (active != fullscreen) {
3523 modest_window_mgr_set_fullscreen_mode (mgr, active);
3524 gtk_window_present (GTK_WINDOW (window));
3529 modest_ui_actions_on_change_fullscreen (GtkAction *action,
3530 ModestWindow *window)
3532 ModestWindowMgr *mgr;
3533 gboolean fullscreen;
3535 g_return_if_fail (MODEST_IS_WINDOW (window));
3537 mgr = modest_runtime_get_window_mgr ();
3538 fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
3539 modest_window_mgr_set_fullscreen_mode (mgr, !fullscreen);
3541 gtk_window_present (GTK_WINDOW (window));
3545 * Used by modest_ui_actions_on_details to call do_headers_action
3548 headers_action_show_details (TnyHeader *header,
3549 ModestWindow *window,
3556 dialog = modest_details_dialog_new_with_header (GTK_WINDOW (window), header);
3559 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
3560 gtk_widget_show_all (dialog);
3561 gtk_dialog_run (GTK_DIALOG (dialog));
3563 gtk_widget_destroy (dialog);
3567 * Show the folder details in a ModestDetailsDialog widget
3570 show_folder_details (TnyFolder *folder,
3576 dialog = modest_details_dialog_new_with_folder (window, folder);
3579 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
3580 gtk_widget_show_all (dialog);
3581 gtk_dialog_run (GTK_DIALOG (dialog));
3583 gtk_widget_destroy (dialog);
3587 * Show the header details in a ModestDetailsDialog widget
3590 modest_ui_actions_on_details (GtkAction *action,
3593 TnyList * headers_list;
3597 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
3600 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW (win));
3603 g_object_unref (msg);
3605 headers_list = get_selected_headers (win);
3609 iter = tny_list_create_iterator (headers_list);
3611 header = TNY_HEADER (tny_iterator_get_current (iter));
3613 headers_action_show_details (header, win, NULL);
3614 g_object_unref (header);
3617 g_object_unref (iter);
3618 g_object_unref (headers_list);
3620 } else if (MODEST_IS_MAIN_WINDOW (win)) {
3621 GtkWidget *folder_view, *header_view;
3623 /* Check which widget has the focus */
3624 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
3625 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3626 if (gtk_widget_is_focus (folder_view)) {
3627 TnyFolderStore *folder_store
3628 = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
3629 if (!folder_store) {
3630 g_warning ("%s: No item was selected.\n", __FUNCTION__);
3633 /* Show only when it's a folder */
3634 /* This function should not be called for account items,
3635 * because we dim the menu item for them. */
3636 if (TNY_IS_FOLDER (folder_store)) {
3637 show_folder_details (TNY_FOLDER (folder_store), GTK_WINDOW (win));
3640 g_object_unref (folder_store);
3643 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
3644 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
3645 /* Show details of each header */
3646 do_headers_action (win, headers_action_show_details, header_view);
3652 modest_ui_actions_on_toggle_show_cc (GtkToggleAction *toggle,
3653 ModestMsgEditWindow *window)
3655 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3657 modest_msg_edit_window_show_cc (window, gtk_toggle_action_get_active (toggle));
3661 modest_ui_actions_on_toggle_show_bcc (GtkToggleAction *toggle,
3662 ModestMsgEditWindow *window)
3664 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3666 modest_msg_edit_window_show_bcc (window, gtk_toggle_action_get_active (toggle));
3670 modest_ui_actions_toggle_folders_view (GtkAction *action,
3671 ModestMainWindow *main_window)
3673 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
3675 if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)))
3676 modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SPLIT);
3678 modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SIMPLE);
3682 modest_ui_actions_on_toggle_toolbar (GtkToggleAction *toggle,
3683 ModestWindow *window)
3685 gboolean active, fullscreen = FALSE;
3686 ModestWindowMgr *mgr;
3688 active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle));
3690 /* Check if we want to toggle the toolbar vuew in fullscreen
3692 if (!strcmp (gtk_action_get_name (GTK_ACTION (toggle)),
3693 "ViewShowToolbarFullScreen")) {
3697 /* Toggle toolbar */
3698 mgr = modest_runtime_get_window_mgr ();
3699 modest_window_mgr_show_toolbars (mgr, G_TYPE_FROM_INSTANCE (window), active, fullscreen);
3703 modest_ui_actions_msg_edit_on_select_font (GtkAction *action,
3704 ModestMsgEditWindow *window)
3706 modest_msg_edit_window_select_font (window);
3710 modest_ui_actions_on_folder_display_name_changed (ModestFolderView *folder_view,
3711 const gchar *display_name,
3714 /* This is usually used to change the title of the main window, which
3715 * is the one that holds the folder view. Note that this change can
3716 * happen even when the widget doesn't have the focus. */
3718 gtk_window_set_title (window, display_name);
3720 gtk_window_set_title (window, " ");
3724 modest_ui_actions_on_select_contacts (GtkAction *action, ModestMsgEditWindow *window)
3726 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3727 modest_msg_edit_window_select_contacts (window);
3731 modest_ui_actions_on_check_names (GtkAction *action, ModestMsgEditWindow *window)
3733 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3734 modest_msg_edit_window_check_names (window, FALSE);
3738 create_move_to_dialog_on_new_folder(GtkWidget *button, gpointer user_data)
3740 modest_ui_actions_create_folder (gtk_widget_get_toplevel (button),
3741 GTK_WIDGET (user_data));
3745 * This function is used to track changes in the selection of the
3746 * folder view that is inside the "move to" dialog to enable/disable
3747 * the OK button because we do not want the user to select a disallowed
3748 * destination for a folder.
3749 * The user also not desired to be able to use NEW button on items where
3750 * folder creation is not possibel.
3753 on_move_to_dialog_folder_selection_changed (ModestFolderView* self,
3754 TnyFolderStore *folder_store,
3758 GtkWidget *dialog = NULL;
3759 GtkWidget *ok_button = NULL, *new_button = NULL;
3760 GList *children = NULL;
3761 gboolean ok_sensitive = TRUE, new_sensitive = TRUE;
3762 gboolean moving_folder = FALSE;
3763 gboolean is_local_account = TRUE;
3764 GtkWidget *folder_view = NULL;
3765 ModestTnyFolderRules rules;
3770 /* Get the OK button */
3771 dialog = gtk_widget_get_ancestor (GTK_WIDGET (self), GTK_TYPE_DIALOG);
3775 children = gtk_container_get_children (GTK_CONTAINER (GTK_DIALOG (dialog)->action_area));
3776 ok_button = GTK_WIDGET (children->next->next->data);
3777 new_button = GTK_WIDGET (children->next->data);
3778 g_list_free (children);
3780 /* check if folder_store is an remote account */
3781 if (TNY_IS_ACCOUNT (folder_store)) {
3782 TnyAccount *local_account = NULL;
3783 TnyAccount *mmc_account = NULL;
3784 ModestTnyAccountStore *account_store = NULL;
3786 account_store = modest_runtime_get_account_store ();
3787 local_account = modest_tny_account_store_get_local_folders_account (account_store);
3788 mmc_account = modest_tny_account_store_get_mmc_folders_account (account_store);
3790 if ((gpointer) local_account != (gpointer) folder_store &&
3791 (gpointer) mmc_account != (gpointer) folder_store) {
3792 is_local_account = FALSE;
3793 /* New button should be dimmed on remote
3795 new_sensitive = FALSE;
3797 g_object_unref (local_account);
3800 /* Check the target folder rules */
3801 if (TNY_IS_FOLDER (folder_store)) {
3802 rules = modest_tny_folder_get_rules (TNY_FOLDER (folder_store));
3803 if (rules & MODEST_FOLDER_RULES_FOLDER_NON_WRITEABLE) {
3804 ok_sensitive = FALSE;
3805 new_sensitive = FALSE;
3810 /* Check if we're moving a folder */
3811 if (MODEST_IS_MAIN_WINDOW (user_data)) {
3812 /* Get the widgets */
3813 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (user_data),
3814 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3815 if (gtk_widget_is_focus (folder_view))
3816 moving_folder = TRUE;
3819 if (moving_folder) {
3820 TnyFolderStore *moved_folder = NULL, *parent = NULL;
3822 /* Get the folder to move */
3823 moved_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
3825 /* Check that we're not moving to the same folder */
3826 if (TNY_IS_FOLDER (moved_folder)) {
3827 parent = tny_folder_get_folder_store (TNY_FOLDER (moved_folder));
3828 if (parent == folder_store)
3829 ok_sensitive = FALSE;
3830 g_object_unref (parent);
3833 if (ok_sensitive && TNY_IS_ACCOUNT (folder_store)) {
3834 /* Do not allow to move to an account unless it's the
3835 local folders account */
3836 if (!is_local_account)
3837 ok_sensitive = FALSE;
3840 if (ok_sensitive && (moved_folder == folder_store)) {
3841 /* Do not allow to move to itself */
3842 ok_sensitive = FALSE;
3844 g_object_unref (moved_folder);
3846 TnyHeader *header = NULL;
3847 TnyFolder *src_folder = NULL;
3849 /* Moving a message */
3850 if (MODEST_IS_MSG_VIEW_WINDOW (user_data)) {
3851 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (user_data));
3852 src_folder = tny_header_get_folder (header);
3853 g_object_unref (header);
3856 TNY_FOLDER (modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view)));
3859 /* Do not allow to move the msg to the same folder */
3860 /* Do not allow to move the msg to an account */
3861 if ((gpointer) src_folder == (gpointer) folder_store ||
3862 TNY_IS_ACCOUNT (folder_store))
3863 ok_sensitive = FALSE;
3864 g_object_unref (src_folder);
3868 /* Set sensitivity of the OK button */
3869 gtk_widget_set_sensitive (ok_button, ok_sensitive);
3870 /* Set sensitivity of the NEW button */
3871 gtk_widget_set_sensitive (new_button, new_sensitive);
3875 create_move_to_dialog (GtkWindow *win,
3876 GtkWidget *folder_view,
3877 GtkWidget **tree_view)
3879 GtkWidget *dialog, *scroll;
3880 GtkWidget *new_button;
3882 dialog = gtk_dialog_new_with_buttons (_("mcen_ti_moveto_folders_title"),
3884 GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR | GTK_DIALOG_DESTROY_WITH_PARENT,
3887 gtk_dialog_add_button (GTK_DIALOG (dialog), _("mcen_bd_dialog_ok"), GTK_RESPONSE_ACCEPT);
3888 /* We do this manually so GTK+ does not associate a response ID for
3890 new_button = gtk_button_new_from_stock (_("mcen_bd_new"));
3891 gtk_box_pack_end (GTK_BOX (GTK_DIALOG (dialog)->action_area), new_button, FALSE, FALSE, 0);
3892 gtk_dialog_add_button (GTK_DIALOG (dialog), _("mcen_bd_dialog_cancel"), GTK_RESPONSE_REJECT);
3894 /* Create scrolled window */
3895 scroll = gtk_scrolled_window_new (NULL, NULL);
3896 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll),
3897 GTK_POLICY_AUTOMATIC,
3898 GTK_POLICY_AUTOMATIC);
3900 /* Create folder view */
3901 *tree_view = modest_platform_create_folder_view (NULL);
3903 /* Track changes in the selection to
3904 * disable the OK button whenever "Move to" is not possible
3905 * disbale NEW button whenever New is not possible */
3906 g_signal_connect (*tree_view,
3907 "folder_selection_changed",
3908 G_CALLBACK (on_move_to_dialog_folder_selection_changed),
3911 /* Listen to clicks on New button */
3912 g_signal_connect (G_OBJECT (new_button),
3914 G_CALLBACK(create_move_to_dialog_on_new_folder),
3917 /* It could happen that we're trying to move a message from a
3918 window (msg window for example) after the main window was
3919 closed, so we can not just get the model of the folder
3921 if (MODEST_IS_FOLDER_VIEW (folder_view)) {
3922 const gchar *visible_id = NULL;
3924 modest_folder_view_set_style (MODEST_FOLDER_VIEW (*tree_view),
3925 MODEST_FOLDER_VIEW_STYLE_SHOW_ALL);
3926 modest_folder_view_copy_model (MODEST_FOLDER_VIEW(folder_view),
3927 MODEST_FOLDER_VIEW(*tree_view));
3930 modest_folder_view_get_account_id_of_visible_server_account (MODEST_FOLDER_VIEW(folder_view));
3932 /* Show the same account than the one that is shown in the main window */
3933 modest_folder_view_set_account_id_of_visible_server_account (MODEST_FOLDER_VIEW(*tree_view),
3936 const gchar *active_account_name = NULL;
3937 ModestAccountMgr *mgr = NULL;
3938 ModestAccountData *acc_data = NULL;
3940 modest_folder_view_set_style (MODEST_FOLDER_VIEW (*tree_view),
3941 MODEST_FOLDER_VIEW_STYLE_SHOW_ALL);
3942 modest_folder_view_update_model (MODEST_FOLDER_VIEW (*tree_view),
3943 TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()));
3945 active_account_name = modest_window_get_active_account (MODEST_WINDOW (win));
3946 mgr = modest_runtime_get_account_mgr ();
3947 acc_data = modest_account_mgr_get_account_data (mgr, active_account_name);
3949 /* Set the new visible & active account */
3950 if (acc_data && acc_data->store_account) {
3951 modest_folder_view_set_account_id_of_visible_server_account (MODEST_FOLDER_VIEW (*tree_view),
3952 acc_data->store_account->account_name);
3953 modest_account_mgr_free_account_data (mgr, acc_data);
3957 /* Hide special folders */
3958 modest_folder_view_show_non_move_folders (MODEST_FOLDER_VIEW (*tree_view), FALSE);
3960 gtk_container_add (GTK_CONTAINER (scroll), *tree_view);
3962 /* Add scroll to dialog */
3963 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
3964 scroll, TRUE, TRUE, 0);
3966 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
3967 gtk_window_set_default_size (GTK_WINDOW (dialog), 300, 300);
3973 * Returns TRUE if at least one of the headers of the list belongs to
3974 * a message that has been fully retrieved.
3976 #if 0 /* no longer in use. delete in 2007.10 */
3978 has_retrieved_msgs (TnyList *list)
3981 gboolean found = FALSE;
3983 iter = tny_list_create_iterator (list);
3984 while (!tny_iterator_is_done (iter) && !found) {
3986 TnyHeaderFlags flags = 0;
3988 header = TNY_HEADER (tny_iterator_get_current (iter));
3990 flags = tny_header_get_flags (header);
3991 if (flags & TNY_HEADER_FLAG_CACHED)
3992 /* if (!(flags & TNY_HEADER_FLAG_PARTIAL)) */
3995 g_object_unref (header);
3999 tny_iterator_next (iter);
4001 g_object_unref (iter);
4009 * Shows a confirmation dialog to the user when we're moving messages
4010 * from a remote server to the local storage. Returns the dialog
4011 * response. If it's other kind of movement then it always returns
4014 * This one is used by the next functions:
4015 * modest_ui_actions_on_paste - commented out
4016 * drag_and_drop_from_header_view (for d&d in modest_folder_view.c)
4019 modest_ui_actions_msgs_move_to_confirmation (ModestWindow *win,
4020 TnyFolder *dest_folder,
4024 gint response = GTK_RESPONSE_OK;
4025 TnyAccount *account = NULL;
4026 TnyFolder *src_folder = NULL;
4027 TnyIterator *iter = NULL;
4028 TnyHeader *header = NULL;
4030 /* return with OK if the destination is a remote folder */
4031 if (modest_tny_folder_is_remote_folder (dest_folder))
4032 return GTK_RESPONSE_OK;
4034 /* Get source folder */
4035 iter = tny_list_create_iterator (headers);
4036 header = TNY_HEADER (tny_iterator_get_current (iter));
4038 src_folder = tny_header_get_folder (header);
4039 g_object_unref (header);
4041 g_object_unref (iter);
4043 /* if no src_folder, message may be an attahcment */
4044 if (src_folder == NULL)
4045 return GTK_RESPONSE_CANCEL;
4047 /* If the source is a local or MMC folder */
4048 if (!modest_tny_folder_is_remote_folder (src_folder)) {
4049 g_object_unref (src_folder);
4050 return GTK_RESPONSE_OK;
4053 /* Get the account */
4054 account = tny_folder_get_account (src_folder);
4056 /* now if offline we ask the user */
4057 if(connect_to_get_msg (win, tny_list_get_length (headers), account))
4058 response = GTK_RESPONSE_OK;
4060 response = GTK_RESPONSE_CANCEL;
4063 g_object_unref (src_folder);
4064 g_object_unref (account);
4072 move_to_cb (ModestMailOperation *mail_op, gpointer user_data)
4074 MoveToHelper *helper = (MoveToHelper *) user_data;
4076 /* Note that the operation could have failed, in that case do
4078 if (modest_mail_operation_get_status (mail_op) ==
4079 MODEST_MAIL_OPERATION_STATUS_SUCCESS) {
4081 GObject *object = modest_mail_operation_get_source (mail_op);
4082 if (MODEST_IS_MSG_VIEW_WINDOW (object)) {
4083 ModestMsgViewWindow *self = MODEST_MSG_VIEW_WINDOW (object);
4085 if (!modest_msg_view_window_select_next_message (self))
4086 if (!modest_msg_view_window_select_previous_message (self))
4087 /* No more messages to view, so close this window */
4088 modest_ui_actions_on_close_window (NULL, MODEST_WINDOW(self));
4089 } else if (MODEST_IS_MAIN_WINDOW (object) && helper->reference != NULL) {
4090 GtkWidget *header_view;
4092 GtkTreeSelection *sel;
4094 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(object),
4095 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
4096 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
4097 path = gtk_tree_row_reference_get_path (helper->reference);
4098 gtk_tree_selection_select_path (sel, path);
4099 gtk_tree_path_free (path);
4101 g_object_unref (object);
4104 /* Close the "Pasting" information banner */
4105 gtk_widget_destroy (GTK_WIDGET(helper->banner));
4106 if (helper->reference != NULL)
4107 gtk_tree_row_reference_free (helper->reference);
4112 modest_ui_actions_move_folder_error_handler (ModestMailOperation *mail_op,
4115 ModestWindow *main_window = NULL;
4116 GObject *win = NULL;
4117 const GError *error = NULL;
4118 const gchar *message = NULL;
4120 /* Get error message */
4121 error = modest_mail_operation_get_error (mail_op);
4122 if (error != NULL && error->message != NULL) {
4123 message = error->message;
4125 message = _("mail_in_ui_folder_move_target_error");
4128 /* Disable next automatic folder selection */
4129 main_window = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (),
4130 FALSE); /* don't create */
4132 GtkWidget *folder_view = NULL;
4134 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (main_window),
4135 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
4136 modest_folder_view_disable_next_folder_selection (MODEST_FOLDER_VIEW(folder_view));
4138 if (user_data && TNY_IS_FOLDER (user_data)) {
4139 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view),
4140 TNY_FOLDER (user_data), FALSE);
4144 /* Show notification dialog */
4145 win = modest_mail_operation_get_source (mail_op);
4146 modest_platform_run_information_dialog ((GtkWindow *) win, message);
4148 g_object_unref (win);
4152 modest_ui_actions_send_receive_error_handler (ModestMailOperation *mail_op,
4155 GObject *win = modest_mail_operation_get_source (mail_op);
4156 const GError *error = modest_mail_operation_get_error (mail_op);
4158 g_return_if_fail (error != NULL);
4159 if (error->message != NULL)
4160 g_printerr ("modest: %s\n", error->message);
4162 g_printerr ("modest: unkonw error on send&receive operation");
4164 /* Show error message */
4165 /* if (modest_mail_operation_get_id (mail_op) == MODEST_MAIL_OPERATION_TYPE_RECEIVE) */
4166 /* modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL, */
4167 /* _CS("sfil_ib_unable_to_receive")); */
4169 /* modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL, */
4170 /* _CS("sfil_ib_unable_to_send")); */
4171 g_object_unref (win);
4175 open_msg_for_purge_cb (ModestMailOperation *mail_op,
4184 gint pending_purges = 0;
4185 gboolean some_purged = FALSE;
4186 ModestWindow *win = MODEST_WINDOW (user_data);
4187 ModestWindowMgr *mgr = modest_runtime_get_window_mgr ();
4189 /* If there was any error */
4190 if (!modest_ui_actions_msg_retrieval_check (mail_op, header, msg)) {
4191 modest_window_mgr_unregister_header (mgr, header);
4195 /* Once the message has been retrieved for purging, we check if
4196 * it's all ok for purging */
4198 parts = tny_simple_list_new ();
4199 tny_mime_part_get_parts (TNY_MIME_PART (msg), parts);
4200 iter = tny_list_create_iterator (parts);
4202 while (!tny_iterator_is_done (iter)) {
4204 part = TNY_MIME_PART (tny_iterator_get_current (iter));
4205 if (part && (tny_mime_part_is_attachment (part) || TNY_IS_MSG (part))) {
4206 if (tny_mime_part_is_purged (part))
4213 g_object_unref (part);
4215 tny_iterator_next (iter);
4217 g_object_unref (iter);
4220 if (pending_purges>0) {
4222 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),_("mcen_nc_purge_file_text_inbox"));
4224 if (response == GTK_RESPONSE_OK) {
4225 modest_platform_information_banner (NULL, NULL, _("mcen_ib_removing_attachment"));
4226 iter = tny_list_create_iterator (parts);
4227 while (!tny_iterator_is_done (iter)) {
4230 part = TNY_MIME_PART (tny_iterator_get_current (iter));
4231 if (part && (tny_mime_part_is_attachment (part) || TNY_IS_MSG (part)))
4232 tny_mime_part_set_purged (part);
4235 g_object_unref (part);
4237 tny_iterator_next (iter);
4240 tny_msg_rewrite_cache (msg);
4243 /* This string no longer exists, refer to NB#75415 for more info */
4244 /* modest_platform_information_banner (NULL, NULL, _("mail_ib_attachment_already_purged")); */
4246 g_object_unref (iter);
4248 modest_window_mgr_unregister_header (mgr, header);
4250 g_object_unref (parts);
4254 modest_ui_actions_on_main_window_remove_attachments (GtkAction *action,
4255 ModestMainWindow *win)
4257 GtkWidget *header_view;
4258 TnyList *header_list;
4261 TnyHeaderFlags flags;
4262 ModestWindow *msg_view_window = NULL;
4265 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win));
4267 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
4268 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
4270 header_list = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW (header_view));
4272 g_warning ("%s: no header selected", __FUNCTION__);
4276 if (tny_list_get_length (header_list) == 1) {
4277 iter = tny_list_create_iterator (header_list);
4278 header = TNY_HEADER (tny_iterator_get_current (iter));
4279 g_object_unref (iter);
4283 if (!header || !TNY_IS_HEADER(header)) {
4284 g_warning ("%s: header is not valid", __FUNCTION__);
4288 found = modest_window_mgr_find_registered_header (modest_runtime_get_window_mgr (),
4289 header, &msg_view_window);
4290 flags = tny_header_get_flags (header);
4291 if (!(flags & TNY_HEADER_FLAG_CACHED))
4294 if (msg_view_window != NULL)
4295 modest_msg_view_window_remove_attachments (MODEST_MSG_VIEW_WINDOW (msg_view_window), TRUE);
4297 /* do nothing; uid was registered before, so window is probably on it's way */
4298 g_warning ("debug: header %p has already been registered", header);
4301 ModestMailOperation *mail_op = NULL;
4302 modest_window_mgr_register_header (modest_runtime_get_window_mgr (), header, NULL);
4303 mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT (win),
4304 modest_ui_actions_get_msgs_full_error_handler,
4306 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
4307 modest_mail_operation_get_msg (mail_op, header, open_msg_for_purge_cb, win);
4309 g_object_unref (mail_op);
4312 g_object_unref (header);
4314 g_object_unref (header_list);
4318 * Utility function that transfer messages from both the main window
4319 * and the msg view window when using the "Move to" dialog
4322 modest_ui_actions_xfer_messages_from_move_to (TnyFolderStore *dst_folder,
4325 TnyList *headers = NULL;
4326 TnyAccount *dst_account = NULL;
4327 const gchar *proto_str = NULL;
4328 gboolean dst_is_pop = FALSE;
4330 if (!TNY_IS_FOLDER (dst_folder)) {
4331 modest_platform_information_banner (GTK_WIDGET (win),
4333 _CS("ckdg_ib_unable_to_move_to_current_location"));
4337 dst_account = tny_folder_get_account (TNY_FOLDER (dst_folder));
4338 proto_str = tny_account_get_proto (dst_account);
4340 /* tinymail will return NULL for local folders it seems */
4341 dst_is_pop = proto_str &&
4342 (modest_protocol_info_get_transport_store_protocol (proto_str) ==
4343 MODEST_PROTOCOL_STORE_POP);
4345 g_object_unref (dst_account);
4347 /* Get selected headers */
4348 headers = get_selected_headers (MODEST_WINDOW (win));
4350 g_warning ("%s: no headers selected", __FUNCTION__);
4356 modest_platform_information_banner (GTK_WIDGET (win),
4358 ngettext("mail_in_ui_folder_move_target_error",
4359 "mail_in_ui_folder_move_targets_error",
4360 tny_list_get_length (headers)));
4361 g_object_unref (headers);
4365 MoveToHelper *helper = g_new0 (MoveToHelper, 1);
4366 helper->banner = modest_platform_animation_banner (GTK_WIDGET (win), NULL,
4367 _CS("ckct_nw_pasting"));
4368 if (helper->banner != NULL) {
4369 gtk_window_set_modal (GTK_WINDOW(helper->banner), FALSE);
4370 gtk_widget_show (GTK_WIDGET(helper->banner));
4373 if (MODEST_IS_MAIN_WINDOW (win)) {
4374 GtkWidget *header_view =
4375 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
4376 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
4377 helper->reference = get_next_after_selected_headers (MODEST_HEADER_VIEW (header_view));
4380 ModestMailOperation *mail_op =
4381 modest_mail_operation_new_with_error_handling (G_OBJECT(win),
4382 modest_ui_actions_move_folder_error_handler,
4384 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
4387 modest_mail_operation_xfer_msgs (mail_op,
4389 TNY_FOLDER (dst_folder),
4394 g_object_unref (G_OBJECT (mail_op));
4395 g_object_unref (headers);
4399 * UI handler for the "Move to" action when invoked from the
4403 modest_ui_actions_on_main_window_move_to (GtkAction *action,
4404 GtkWidget *folder_view,
4405 TnyFolderStore *dst_folder,
4406 ModestMainWindow *win)
4408 ModestHeaderView *header_view = NULL;
4409 ModestMailOperation *mail_op = NULL;
4410 TnyFolderStore *src_folder;
4411 gboolean online = (tny_device_is_online (modest_runtime_get_device()));
4413 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win));
4415 /* Get the source folder */
4416 src_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
4418 /* Get header view */
4419 header_view = MODEST_HEADER_VIEW(modest_main_window_get_child_widget (win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW));
4421 /* Get folder or messages to transfer */
4422 if (gtk_widget_is_focus (folder_view)) {
4423 GtkTreeSelection *sel;
4424 gboolean do_xfer = TRUE;
4426 /* Allow only to transfer folders to the local root folder */
4427 if (TNY_IS_ACCOUNT (dst_folder) &&
4428 !MODEST_IS_TNY_LOCAL_FOLDERS_ACCOUNT (dst_folder)) {
4430 } else if (!TNY_IS_FOLDER (src_folder)) {
4431 g_warning ("%s: src_folder is not a TnyFolder.\n", __FUNCTION__);
4433 } else if (!online && modest_tny_folder_store_is_remote(src_folder)) {
4434 guint num_headers = tny_folder_get_all_count(TNY_FOLDER (src_folder));
4435 TnyAccount *account = tny_folder_get_account (TNY_FOLDER (src_folder));
4436 if (!connect_to_get_msg(MODEST_WINDOW (win), num_headers, account))
4438 g_object_unref (account);
4442 MoveToHelper *helper = g_new0 (MoveToHelper, 1);
4443 helper->banner = modest_platform_animation_banner (GTK_WIDGET (win), NULL,
4444 _CS("ckct_nw_pasting"));
4445 if (helper->banner != NULL) {
4446 gtk_window_set_modal (GTK_WINDOW(helper->banner), FALSE);
4447 gtk_widget_show (GTK_WIDGET(helper->banner));
4449 /* Clean folder on header view before moving it */
4450 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_view));
4451 gtk_tree_selection_unselect_all (sel);
4453 /* Let gtk events run. We need that the folder
4454 view frees its reference to the source
4455 folder *before* issuing the mail operation
4456 so we need the signal handler of selection
4457 changed to happen before the mail
4459 while (gtk_events_pending ())
4460 gtk_main_iteration ();
4463 modest_mail_operation_new_with_error_handling (G_OBJECT(win),
4464 modest_ui_actions_move_folder_error_handler,
4466 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
4469 /* Select *after* the changes */
4470 /* TODO: this function hangs UI after transfer */
4471 /* modest_folder_view_select_folder (MODEST_FOLDER_VIEW(folder_view), */
4472 /* TNY_FOLDER (src_folder), TRUE); */
4474 modest_mail_operation_xfer_folder (mail_op,
4475 TNY_FOLDER (src_folder),
4480 /* Unref mail operation */
4481 g_object_unref (G_OBJECT (mail_op));
4483 } else if (gtk_widget_is_focus (GTK_WIDGET(header_view))) {
4484 gboolean do_xfer = TRUE;
4485 /* Ask for confirmation if the source folder is remote and we're not connected */
4486 if (!online && modest_tny_folder_store_is_remote(src_folder)) {
4487 TnyList *headers = modest_header_view_get_selected_headers(header_view);
4488 if (!msgs_already_deleted_from_server(headers, src_folder)) {
4489 guint num_headers = tny_list_get_length(headers);
4490 TnyAccount *account = get_account_from_header_list (headers);
4491 if (!connect_to_get_msg(MODEST_WINDOW (win), num_headers, account))
4493 g_object_unref (account);
4495 g_object_unref(headers);
4497 if (do_xfer) /* Transfer messages */
4498 modest_ui_actions_xfer_messages_from_move_to (dst_folder, MODEST_WINDOW (win));
4502 g_object_unref (src_folder);
4507 * UI handler for the "Move to" action when invoked from the
4508 * ModestMsgViewWindow
4511 modest_ui_actions_on_msg_view_window_move_to (GtkAction *action,
4512 TnyFolderStore *dst_folder,
4513 ModestMsgViewWindow *win)
4515 TnyHeader *header = NULL;
4516 TnyFolder *src_folder = NULL;
4517 TnyAccount *account = NULL;
4518 gboolean do_xfer = FALSE;
4520 /* Create header list */
4521 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
4522 src_folder = TNY_FOLDER (tny_header_get_folder(header));
4523 g_object_unref (header);
4525 account = tny_folder_get_account (src_folder);
4526 if (!modest_tny_folder_store_is_remote(TNY_FOLDER_STORE(src_folder))) {
4527 /* Transfer if the source folder is local */
4529 } else if (remote_folder_is_pop(TNY_FOLDER_STORE(src_folder))) {
4530 /* Transfer if the source folder is POP (as it means
4531 * that the message is already downloaded) */
4533 } else if (connect_to_get_msg(MODEST_WINDOW(win), 1, account)) {
4534 /* Transfer after asking confirmation */
4539 modest_ui_actions_xfer_messages_from_move_to (dst_folder, MODEST_WINDOW (win));
4541 g_object_unref (account);
4542 g_object_unref (src_folder);
4546 modest_ui_actions_on_move_to (GtkAction *action,
4549 GtkWidget *dialog = NULL, *folder_view = NULL, *tree_view = NULL;
4551 TnyFolderStore *dst_folder = NULL;
4552 ModestMainWindow *main_window;
4554 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win) ||
4555 MODEST_IS_MSG_VIEW_WINDOW (win));
4557 /* Get the main window if exists */
4558 if (MODEST_IS_MAIN_WINDOW (win))
4559 main_window = MODEST_MAIN_WINDOW (win);
4562 MODEST_MAIN_WINDOW (modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (),
4563 FALSE)); /* don't create */
4565 /* Get the folder view widget if exists */
4567 folder_view = modest_main_window_get_child_widget (main_window,
4568 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
4572 /* Create and run the dialog */
4573 dialog = create_move_to_dialog (GTK_WINDOW (win), folder_view, &tree_view);
4574 modest_folder_view_select_first_inbox_or_local (MODEST_FOLDER_VIEW (tree_view));
4575 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
4576 result = gtk_dialog_run (GTK_DIALOG(dialog));
4577 g_object_ref (tree_view);
4578 gtk_widget_destroy (dialog);
4580 if (result != GTK_RESPONSE_ACCEPT)
4583 dst_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (tree_view));
4584 /* Do window specific stuff */
4585 if (MODEST_IS_MAIN_WINDOW (win)) {
4586 modest_ui_actions_on_main_window_move_to (action,
4589 MODEST_MAIN_WINDOW (win));
4591 modest_ui_actions_on_msg_view_window_move_to (action,
4593 MODEST_MSG_VIEW_WINDOW (win));
4597 g_object_unref (dst_folder);
4601 * Calls #HeadersFunc for each header already selected in the main
4602 * window or the message currently being shown in the msg view window
4605 do_headers_action (ModestWindow *win,
4609 TnyList *headers_list = NULL;
4610 TnyIterator *iter = NULL;
4611 TnyHeader *header = NULL;
4612 TnyFolder *folder = NULL;
4615 headers_list = get_selected_headers (win);
4619 /* Get the folder */
4620 iter = tny_list_create_iterator (headers_list);
4621 header = TNY_HEADER (tny_iterator_get_current (iter));
4623 folder = tny_header_get_folder (header);
4624 g_object_unref (header);
4627 /* Call the function for each header */
4628 while (!tny_iterator_is_done (iter)) {
4629 header = TNY_HEADER (tny_iterator_get_current (iter));
4630 func (header, win, user_data);
4631 g_object_unref (header);
4632 tny_iterator_next (iter);
4635 /* Trick: do a poke status in order to speed up the signaling
4637 tny_folder_poke_status (folder);
4640 g_object_unref (folder);
4641 g_object_unref (iter);
4642 g_object_unref (headers_list);
4646 modest_ui_actions_view_attachment (GtkAction *action,
4647 ModestWindow *window)
4649 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
4650 modest_msg_view_window_view_attachment (MODEST_MSG_VIEW_WINDOW (window), NULL);
4652 /* not supported window for this action */
4653 g_return_if_reached ();
4658 modest_ui_actions_save_attachments (GtkAction *action,
4659 ModestWindow *window)
4661 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
4662 modest_msg_view_window_save_attachments (MODEST_MSG_VIEW_WINDOW (window), NULL);
4664 /* not supported window for this action */
4665 g_return_if_reached ();
4670 modest_ui_actions_remove_attachments (GtkAction *action,
4671 ModestWindow *window)
4673 if (MODEST_IS_MAIN_WINDOW (window)) {
4674 modest_ui_actions_on_main_window_remove_attachments (action, MODEST_MAIN_WINDOW (window));
4675 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
4676 modest_msg_view_window_remove_attachments (MODEST_MSG_VIEW_WINDOW (window), FALSE);
4678 /* not supported window for this action */
4679 g_return_if_reached ();
4684 modest_ui_actions_on_settings (GtkAction *action,
4689 dialog = modest_platform_get_global_settings_dialog ();
4690 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (win));
4691 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
4692 gtk_widget_show_all (dialog);
4694 gtk_dialog_run (GTK_DIALOG (dialog));
4696 gtk_widget_destroy (dialog);
4700 modest_ui_actions_on_help (GtkAction *action,
4703 const gchar *help_id;
4705 g_return_if_fail (action);
4706 g_return_if_fail (win && GTK_IS_WINDOW(win));
4708 help_id = modest_window_mgr_get_help_id (modest_runtime_get_window_mgr(), win);
4711 modest_platform_show_help (GTK_WINDOW (win), help_id);
4713 g_warning ("%s: no help for window %p", __FUNCTION__, win);
4717 retrieve_msg_contents_performer (gboolean canceled,
4719 GtkWindow *parent_window,
4720 TnyAccount *account,
4723 ModestMailOperation *mail_op;
4724 TnyList *headers = TNY_LIST (user_data);
4726 if (err || canceled) {
4727 /* Show an error ? */
4731 /* Create mail operation */
4732 mail_op = modest_mail_operation_new_with_error_handling ((GObject *) parent_window,
4733 modest_ui_actions_get_msgs_full_error_handler,
4735 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
4736 modest_mail_operation_get_msgs_full (mail_op, headers, NULL, NULL, NULL);
4739 g_object_unref (mail_op);
4741 g_object_unref (headers);
4742 g_object_unref (account);
4746 modest_ui_actions_on_retrieve_msg_contents (GtkAction *action,
4747 ModestWindow *window)
4749 TnyList *headers = NULL;
4750 TnyAccount *account = NULL;
4751 TnyIterator *iter = NULL;
4752 TnyHeader *header = NULL;
4753 TnyFolder *folder = NULL;
4756 headers = get_selected_headers (window);
4760 /* Pick the account */
4761 iter = tny_list_create_iterator (headers);
4762 header = TNY_HEADER (tny_iterator_get_current (iter));
4763 folder = tny_header_get_folder (header);
4764 account = tny_folder_get_account (folder);
4765 g_object_unref (folder);
4766 g_object_unref (header);
4767 g_object_unref (iter);
4769 /* Connect and perform the message retrieval */
4770 modest_platform_connect_and_perform ((GtkWindow *) window,
4771 g_object_ref (account),
4772 retrieve_msg_contents_performer,
4773 g_object_ref (headers));
4776 g_object_unref (account);
4777 g_object_unref (headers);
4781 modest_ui_actions_on_email_menu_activated (GtkAction *action,
4782 ModestWindow *window)
4784 g_return_if_fail (MODEST_IS_WINDOW (window));
4787 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4791 modest_ui_actions_on_edit_menu_activated (GtkAction *action,
4792 ModestWindow *window)
4794 g_return_if_fail (MODEST_IS_WINDOW (window));
4797 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4801 modest_ui_actions_on_view_menu_activated (GtkAction *action,
4802 ModestWindow *window)
4804 g_return_if_fail (MODEST_IS_WINDOW (window));
4807 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4811 modest_ui_actions_on_format_menu_activated (GtkAction *action,
4812 ModestWindow *window)
4814 g_return_if_fail (MODEST_IS_WINDOW (window));
4817 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4821 modest_ui_actions_on_tools_menu_activated (GtkAction *action,
4822 ModestWindow *window)
4824 g_return_if_fail (MODEST_IS_WINDOW (window));
4827 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4831 modest_ui_actions_on_attachment_menu_activated (GtkAction *action,
4832 ModestWindow *window)
4834 g_return_if_fail (MODEST_IS_WINDOW (window));
4837 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4841 modest_ui_actions_on_toolbar_csm_menu_activated (GtkAction *action,
4842 ModestWindow *window)
4844 g_return_if_fail (MODEST_IS_WINDOW (window));
4847 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4851 modest_ui_actions_on_folder_view_csm_menu_activated (GtkAction *action,
4852 ModestWindow *window)
4854 g_return_if_fail (MODEST_IS_WINDOW (window));
4857 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4861 modest_ui_actions_on_header_view_csm_menu_activated (GtkAction *action,
4862 ModestWindow *window)
4864 g_return_if_fail (MODEST_IS_WINDOW (window));
4867 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4871 modest_ui_actions_check_toolbar_dimming_rules (ModestWindow *window)
4873 g_return_if_fail (MODEST_IS_WINDOW (window));
4876 modest_window_check_dimming_rules_group (window, "ModestToolbarDimmingRules");
4880 modest_ui_actions_on_search_messages (GtkAction *action, ModestWindow *window)
4882 g_return_if_fail (MODEST_IS_WINDOW (window));
4884 modest_platform_show_search_messages (GTK_WINDOW (window));
4888 modest_ui_actions_on_open_addressbook (GtkAction *action, ModestWindow *win)
4890 g_return_if_fail (MODEST_IS_WINDOW (win));
4891 modest_platform_show_addressbook (GTK_WINDOW (win));
4896 modest_ui_actions_on_toggle_find_in_page (GtkToggleAction *action,
4897 ModestWindow *window)
4899 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4901 modest_msg_edit_window_toggle_find_toolbar (MODEST_MSG_EDIT_WINDOW (window), gtk_toggle_action_get_active (action));
4905 on_send_receive_finished (ModestMailOperation *mail_op,
4908 GtkWidget *header_view, *folder_view;
4909 TnyFolderStore *folder_store;
4910 ModestMainWindow *main_win = MODEST_MAIN_WINDOW (user_data);
4912 /* Set send/receive operation finished */
4913 modest_main_window_notify_send_receive_completed (main_win);
4915 /* Don't refresh the current folder if there were any errors */
4916 if (modest_mail_operation_get_status (mail_op) !=
4917 MODEST_MAIL_OPERATION_STATUS_SUCCESS)
4920 /* Refresh the current folder if we're viewing a window. We do
4921 this because the user won't be able to see the new mails in
4922 the selected folder after a Send&Receive because it only
4923 performs a poke_status, i.e, only the number of read/unread
4924 messages is updated, but the new headers are not
4926 folder_view = modest_main_window_get_child_widget (main_win,
4927 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
4931 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
4933 /* Do not need to refresh INBOX again because the
4934 update_account does it always automatically */
4935 if (folder_store && TNY_IS_FOLDER (folder_store) &&
4936 tny_folder_get_folder_type (TNY_FOLDER (folder_store)) != TNY_FOLDER_TYPE_INBOX) {
4938 header_view = modest_main_window_get_child_widget (main_win,
4939 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
4941 /* We do not need to set the contents style
4942 because it hasn't changed. We also do not
4943 need to save the widget status. Just force
4945 modest_header_view_set_folder (MODEST_HEADER_VIEW(header_view),
4946 TNY_FOLDER (folder_store),
4947 folder_refreshed_cb,
4952 g_object_unref (folder_store);
4957 modest_ui_actions_on_send_queue_error_happened (TnySendQueue *self,
4963 const gchar* server_name = NULL;
4964 TnyTransportAccount *server_account;
4965 gchar *message = NULL;
4967 /* Don't show anything if the user cancelled something */
4968 if (err->code == TNY_TRANSPORT_ACCOUNT_ERROR_SEND_USER_CANCEL)
4971 /* Get the server name: */
4973 TNY_TRANSPORT_ACCOUNT (tny_camel_send_queue_get_transport_account (TNY_CAMEL_SEND_QUEUE (self)));
4974 if (server_account) {
4975 server_name = tny_account_get_hostname (TNY_ACCOUNT (server_account));
4977 g_object_unref (server_account);
4978 server_account = NULL;
4981 g_return_if_fail (server_name);
4983 /* Show the appropriate message text for the GError: */
4984 switch (err->code) {
4985 case TNY_TRANSPORT_ACCOUNT_ERROR_SEND_HOST_LOOKUP_FAILED:
4986 message = g_strdup_printf (_("emev_ib_ui_smtp_server_invalid"), server_name);
4988 case TNY_TRANSPORT_ACCOUNT_ERROR_SEND_SERVICE_UNAVAILABLE:
4989 message = g_strdup_printf (_("emev_ib_ui_smtp_server_invalid"), server_name);
4991 case TNY_TRANSPORT_ACCOUNT_ERROR_SEND_AUTHENTICATION_NOT_SUPPORTED:
4992 message = g_strdup_printf (_("emev_ni_ui_smtp_authentication_fail_error"), server_name);
4994 case TNY_TRANSPORT_ACCOUNT_ERROR_SEND:
4995 message = g_strdup (_("emev_ib_ui_smtp_send_error"));
4998 g_return_if_reached ();
5001 /* TODO if the username or the password where not defined we
5002 should show the Accounts Settings dialog or the Connection
5003 specific SMTP server window */
5005 modest_platform_run_information_dialog (NULL, message);
5010 modest_ui_actions_on_send_queue_status_changed (ModestTnySendQueue *send_queue,
5015 ModestMainWindow *main_window = NULL;
5016 ModestWindowMgr *mgr = NULL;
5017 GtkWidget *folder_view = NULL, *header_view = NULL;
5018 TnyFolderStore *selected_folder = NULL;
5019 TnyFolderType folder_type;
5021 mgr = modest_runtime_get_window_mgr ();
5022 main_window = MODEST_MAIN_WINDOW (modest_window_mgr_get_main_window (mgr,
5023 FALSE));/* don't create */
5027 /* Check if selected folder is OUTBOX */
5028 folder_view = modest_main_window_get_child_widget (main_window,
5029 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
5030 header_view = modest_main_window_get_child_widget (main_window,
5031 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
5033 selected_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
5034 if (!TNY_IS_FOLDER (selected_folder))
5037 /* gtk_tree_view_column_queue_resize is only available in GTK+ 2.8 */
5038 #if GTK_CHECK_VERSION(2, 8, 0)
5039 folder_type = modest_tny_folder_guess_folder_type (TNY_FOLDER (selected_folder));
5040 if (folder_type == TNY_FOLDER_TYPE_OUTBOX) {
5041 GtkTreeViewColumn *tree_column;
5043 tree_column = gtk_tree_view_get_column (GTK_TREE_VIEW (header_view),
5044 TNY_GTK_HEADER_LIST_MODEL_FROM_COLUMN);
5045 gtk_tree_view_column_queue_resize (tree_column);
5048 gtk_widget_queue_draw (header_view);
5053 if (selected_folder != NULL)
5054 g_object_unref (selected_folder);
5058 modest_ui_actions_on_account_connection_error (GtkWindow *parent_window,
5059 TnyAccount *account)
5061 ModestTransportStoreProtocol proto;
5062 const gchar *proto_name;
5063 gchar *error_note = NULL;
5065 proto_name = tny_account_get_proto (account);
5066 proto = modest_protocol_info_get_transport_store_protocol (proto_name);
5069 case MODEST_PROTOCOL_STORE_POP:
5070 error_note = g_strdup_printf (_("emev_ni_ui_pop3_msg_connect_error"),
5071 tny_account_get_hostname (account));
5073 case MODEST_PROTOCOL_STORE_IMAP:
5074 error_note = g_strdup_printf (_("emev_ni_ui_imap_connect_server_error"),
5075 tny_account_get_hostname (account));
5077 case MODEST_PROTOCOL_STORE_MAILDIR:
5078 case MODEST_PROTOCOL_STORE_MBOX:
5079 error_note = g_strdup (_("emev_nc_mailbox_notavailable"));
5082 g_warning ("%s: This should not be reached", __FUNCTION__);
5086 modest_platform_run_information_dialog (parent_window, error_note);
5087 g_free (error_note);