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"
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 #endif /* MODEST_PLATFORM_MAEMO */
58 #include "widgets/modest-ui-constants.h"
59 #include <widgets/modest-main-window.h>
60 #include <widgets/modest-msg-view-window.h>
61 #include <widgets/modest-account-view-window.h>
62 #include <widgets/modest-details-dialog.h>
63 #include <widgets/modest-attachments-view.h>
64 #include "widgets/modest-folder-view.h"
65 #include "widgets/modest-global-settings-dialog.h"
66 #include "modest-connection-specific-smtp-window.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,
132 static void reply_forward_cb (ModestMailOperation *mail_op,
137 static void reply_forward (ReplyForwardAction action, ModestWindow *win);
139 static void folder_refreshed_cb (ModestMailOperation *mail_op,
143 static void on_send_receive_finished (ModestMailOperation *mail_op,
146 static gint header_list_count_uncached_msgs (TnyList *header_list);
148 static gboolean connect_to_get_msg (ModestWindow *win,
149 gint num_of_uncached_msgs,
150 TnyAccount *account);
152 static gboolean remote_folder_is_pop (const TnyFolderStore *folder);
154 static gboolean msgs_already_deleted_from_server ( TnyList *headers,
155 const TnyFolderStore *src_folder);
159 * This function checks whether a TnyFolderStore is a pop account
162 remote_folder_is_pop (const TnyFolderStore *folder)
164 const gchar *proto = NULL;
165 TnyAccount *account = NULL;
167 g_return_val_if_fail (TNY_IS_FOLDER_STORE(folder), FALSE);
169 if (TNY_IS_ACCOUNT (folder)) {
170 account = TNY_ACCOUNT(folder);
171 g_object_ref(account);
172 } else if (TNY_IS_FOLDER (folder)) {
173 account = tny_folder_get_account(TNY_FOLDER(folder));
176 proto = tny_account_get_proto(account);
177 g_object_unref (account);
180 (modest_protocol_info_get_transport_store_protocol (proto) == MODEST_PROTOCOL_STORE_POP);
184 * This functions checks whether if a list of messages are already
185 * deleted from the server: that is, if the server is a POP account
186 * and all messages are already cached.
189 msgs_already_deleted_from_server (TnyList *headers, const TnyFolderStore *src_folder)
191 g_return_val_if_fail (TNY_IS_FOLDER_STORE(src_folder), FALSE);
192 g_return_val_if_fail (TNY_IS_LIST(headers), FALSE);
194 gboolean src_is_pop = remote_folder_is_pop (src_folder);
195 gint uncached_msgs = header_list_count_uncached_msgs (headers);
197 return (src_is_pop && !uncached_msgs);
201 /* FIXME: this should be merged with the similar code in modest-account-view-window */
202 /* Show the account creation wizard dialog.
203 * returns: TRUE if an account was created. FALSE if the user cancelled.
206 modest_ui_actions_run_account_setup_wizard (ModestWindow *win)
208 gboolean result = FALSE;
209 GtkWindow *dialog, *wizard;
210 gint dialog_response;
212 /* Show the easy-setup wizard: */
213 dialog = modest_window_mgr_get_modal (modest_runtime_get_window_mgr());
214 if (dialog && MODEST_IS_EASYSETUP_WIZARD_DIALOG(dialog)) {
215 /* old wizard is active already;
217 gtk_window_present (GTK_WINDOW(dialog));
222 /* there is no such wizard yet */
223 wizard = GTK_WINDOW (modest_easysetup_wizard_dialog_new ());
224 modest_window_mgr_set_modal (modest_runtime_get_window_mgr(), wizard);
226 /* always present a main window in the background
227 * we do it here, so we cannot end up with two wizards (as this
228 * function might be called in modest_window_mgr_get_main_window as well */
230 win = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr(),
231 TRUE); /* create if not existent */
233 /* make sure the mainwindow is visible */
234 gtk_widget_show_all (GTK_WIDGET(win));
235 gtk_window_present (GTK_WINDOW(win));
237 dialog_response = gtk_dialog_run (GTK_DIALOG (wizard));
238 gtk_widget_destroy (GTK_WIDGET (wizard));
239 if (gtk_events_pending ())
240 gtk_main_iteration ();
242 if (dialog_response == GTK_RESPONSE_CANCEL) {
245 /* Check whether an account was created: */
246 result = modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
254 modest_ui_actions_on_about (GtkAction *action, ModestWindow *win)
257 const gchar *authors[] = {
258 "Dirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>",
261 about = gtk_about_dialog_new ();
262 gtk_about_dialog_set_name (GTK_ABOUT_DIALOG(about), PACKAGE_NAME);
263 gtk_about_dialog_set_version (GTK_ABOUT_DIALOG(about),PACKAGE_VERSION);
264 gtk_about_dialog_set_copyright (GTK_ABOUT_DIALOG(about),
265 _("Copyright (c) 2006, Nokia Corporation\n"
266 "All rights reserved."));
267 gtk_about_dialog_set_comments (GTK_ABOUT_DIALOG(about),
268 _("a modest e-mail client\n\n"
269 "design and implementation: Dirk-Jan C. Binnema\n"
270 "contributions from the fine people at KC and Ig\n"
271 "uses the tinymail email framework written by Philip van Hoof"));
272 gtk_about_dialog_set_authors (GTK_ABOUT_DIALOG(about), authors);
273 gtk_about_dialog_set_website (GTK_ABOUT_DIALOG(about), "http://modest.garage.maemo.org");
274 gtk_window_set_transient_for (GTK_WINDOW (about), GTK_WINDOW (win));
275 gtk_window_set_modal (GTK_WINDOW (about), TRUE);
277 gtk_dialog_run (GTK_DIALOG (about));
278 gtk_widget_destroy(about);
282 * Gets the list of currently selected messages. If the win is the
283 * main window, then it returns a newly allocated list of the headers
284 * selected in the header view. If win is the msg view window, then
285 * the value returned is a list with just a single header.
287 * The caller of this funcion must free the list.
290 get_selected_headers (ModestWindow *win)
292 if (MODEST_IS_MAIN_WINDOW(win)) {
293 GtkWidget *header_view;
295 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
296 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
297 return modest_header_view_get_selected_headers (MODEST_HEADER_VIEW(header_view));
299 } else if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
300 /* for MsgViewWindows, we simply return a list with one element */
302 TnyList *list = NULL;
304 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
305 if (header != NULL) {
306 list = tny_simple_list_new ();
307 tny_list_prepend (list, G_OBJECT(header));
308 g_object_unref (G_OBJECT(header));
317 static GtkTreeRowReference *
318 get_next_after_selected_headers (ModestHeaderView *header_view)
320 GtkTreeSelection *sel;
321 GList *selected_rows, *node;
323 GtkTreeRowReference *result;
326 model = gtk_tree_view_get_model (GTK_TREE_VIEW (header_view));
327 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
328 selected_rows = gtk_tree_selection_get_selected_rows (sel, NULL);
330 if (selected_rows == NULL)
333 node = g_list_last (selected_rows);
334 path = gtk_tree_path_copy ((GtkTreePath *) node->data);
335 gtk_tree_path_next (path);
337 result = gtk_tree_row_reference_new (model, path);
339 gtk_tree_path_free (path);
340 g_list_foreach (selected_rows, (GFunc) gtk_tree_path_free, NULL);
341 g_list_free (selected_rows);
347 headers_action_mark_as_read (TnyHeader *header,
351 TnyHeaderFlags flags;
353 g_return_if_fail (TNY_IS_HEADER(header));
355 flags = tny_header_get_flags (header);
356 if (flags & TNY_HEADER_FLAG_SEEN) return;
357 tny_header_set_flag (header, TNY_HEADER_FLAG_SEEN);
361 headers_action_mark_as_unread (TnyHeader *header,
365 TnyHeaderFlags flags;
367 g_return_if_fail (TNY_IS_HEADER(header));
369 flags = tny_header_get_flags (header);
370 if (flags & TNY_HEADER_FLAG_SEEN) {
371 tny_header_unset_flag (header, TNY_HEADER_FLAG_SEEN);
375 /** After deleing a message that is currently visible in a window,
376 * show the next message from the list, or close the window if there are no more messages.
379 modest_ui_actions_refresh_message_window_after_delete (ModestMsgViewWindow* win)
381 /* Close msg view window or select next */
382 if (modest_msg_view_window_last_message_selected (win) &&
383 modest_msg_view_window_first_message_selected (win)) {
384 modest_ui_actions_on_close_window (NULL, MODEST_WINDOW (win));
385 } else if (!modest_msg_view_window_select_next_message (win)) {
387 g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value);
393 modest_ui_actions_on_delete_message (GtkAction *action, ModestWindow *win)
395 TnyList *header_list = NULL;
396 TnyIterator *iter = NULL;
397 TnyHeader *header = NULL;
398 gchar *message = NULL;
401 ModestWindowMgr *mgr;
402 GtkWidget *header_view = NULL;
404 g_return_if_fail (MODEST_IS_WINDOW(win));
406 /* Check first if the header view has the focus */
407 if (MODEST_IS_MAIN_WINDOW (win)) {
409 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
410 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
411 if (!gtk_widget_is_focus (header_view))
415 /* Get the headers, either from the header view (if win is the main window),
416 * or from the message view window: */
417 header_list = get_selected_headers (win);
418 if (!header_list) return;
420 /* Check if any of the headers are already opened, or in the process of being opened */
421 if (MODEST_IS_MAIN_WINDOW (win)) {
422 gint opened_headers = 0;
424 iter = tny_list_create_iterator (header_list);
425 mgr = modest_runtime_get_window_mgr ();
426 while (!tny_iterator_is_done (iter)) {
427 header = TNY_HEADER (tny_iterator_get_current (iter));
429 if (modest_window_mgr_find_registered_header (mgr, header, NULL))
431 g_object_unref (header);
433 tny_iterator_next (iter);
435 g_object_unref (iter);
437 if (opened_headers > 0) {
440 msg = g_strdup_printf (_("mcen_nc_unable_to_delete_n_messages"),
443 modest_platform_run_information_dialog (GTK_WINDOW (win), (const gchar *) msg);
446 g_object_unref (header_list);
452 if (tny_list_get_length(header_list) == 1) {
453 iter = tny_list_create_iterator (header_list);
454 header = TNY_HEADER (tny_iterator_get_current (iter));
456 desc = g_strdup_printf ("%s", tny_header_get_subject (header));
457 g_object_unref (header);
460 g_object_unref (iter);
462 message = g_strdup_printf(ngettext("emev_nc_delete_message", "emev_nc_delete_messages",
463 tny_list_get_length(header_list)), desc);
465 /* Confirmation dialog */
466 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
470 if (response == GTK_RESPONSE_OK) {
471 ModestWindow *main_window = NULL;
472 ModestWindowMgr *mgr = NULL;
473 GtkTreeModel *model = NULL;
474 GtkTreeSelection *sel = NULL;
475 GList *sel_list = NULL, *tmp = NULL;
476 GtkTreeRowReference *next_row_reference = NULL;
477 GtkTreeRowReference *prev_row_reference = NULL;
478 GtkTreePath *next_path = NULL;
479 GtkTreePath *prev_path = NULL;
480 ModestMailOperation *mail_op = NULL;
482 /* Find last selected row */
483 if (MODEST_IS_MAIN_WINDOW (win)) {
484 model = gtk_tree_view_get_model (GTK_TREE_VIEW (header_view));
485 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
486 sel_list = gtk_tree_selection_get_selected_rows (sel, &model);
487 for (tmp=sel_list; tmp; tmp=tmp->next) {
488 if (tmp->next == NULL) {
489 prev_path = gtk_tree_path_copy((GtkTreePath *) tmp->data);
490 next_path = gtk_tree_path_copy((GtkTreePath *) tmp->data);
492 gtk_tree_path_prev (prev_path);
493 gtk_tree_path_next (next_path);
495 prev_row_reference = gtk_tree_row_reference_new (model, prev_path);
496 next_row_reference = gtk_tree_row_reference_new (model, next_path);
501 /* Disable window dimming management */
502 modest_window_disable_dimming (MODEST_WINDOW(win));
504 /* Remove each header. If it's a view window header_view == NULL */
505 mail_op = modest_mail_operation_new ((GObject *) win);
506 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
508 modest_mail_operation_remove_msgs (mail_op, header_list, FALSE);
509 g_object_unref (mail_op);
511 /* Enable window dimming management */
513 gtk_tree_selection_unselect_all (sel);
515 modest_window_enable_dimming (MODEST_WINDOW(win));
517 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
518 modest_ui_actions_refresh_message_window_after_delete (MODEST_MSG_VIEW_WINDOW (win));
520 /* Get main window */
521 mgr = modest_runtime_get_window_mgr ();
522 main_window = modest_window_mgr_get_main_window (mgr, FALSE); /* don't create */
524 /* Move cursor to next row */
527 /* Select next or previous row */
528 if (gtk_tree_row_reference_valid (next_row_reference)) {
529 /* next_path = gtk_tree_row_reference_get_path (row_reference); */
530 gtk_tree_selection_select_path (sel, next_path);
532 else if (gtk_tree_row_reference_valid (prev_row_reference)) {
533 gtk_tree_selection_select_path (sel, prev_path);
537 if (next_row_reference != NULL)
538 gtk_tree_row_reference_free (next_row_reference);
539 if (next_path != NULL)
540 gtk_tree_path_free (next_path);
541 if (prev_row_reference != NULL)
542 gtk_tree_row_reference_free (prev_row_reference);
543 if (prev_path != NULL)
544 gtk_tree_path_free (prev_path);
547 /* Update toolbar dimming state */
549 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
552 g_list_foreach (sel_list, (GFunc) gtk_tree_path_free, NULL);
553 g_list_free (sel_list);
559 g_object_unref (header_list);
565 /* delete either message or folder, based on where we are */
567 modest_ui_actions_on_delete_message_or_folder (GtkAction *action, ModestWindow *win)
569 g_return_if_fail (MODEST_IS_WINDOW(win));
571 /* Check first if the header view has the focus */
572 if (MODEST_IS_MAIN_WINDOW (win)) {
574 w = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
575 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
576 if (gtk_widget_is_focus (w)) {
577 modest_ui_actions_on_delete_folder (action, MODEST_MAIN_WINDOW(win));
581 modest_ui_actions_on_delete_message (action, win);
587 modest_ui_actions_on_quit (GtkAction *action, ModestWindow *win)
589 ModestWindowMgr *mgr = NULL;
591 #ifdef MODEST_PLATFORM_MAEMO
592 modest_osso_save_state();
593 #endif /* MODEST_PLATFORM_MAEMO */
595 g_debug ("closing down, clearing %d item(s) from operation queue",
596 modest_mail_operation_queue_num_elements
597 (modest_runtime_get_mail_operation_queue()));
599 /* cancel all outstanding operations */
600 modest_mail_operation_queue_cancel_all
601 (modest_runtime_get_mail_operation_queue());
603 g_debug ("queue has been cleared");
606 /* Check if there are opened editing windows */
607 mgr = modest_runtime_get_window_mgr ();
608 modest_window_mgr_close_all_windows (mgr);
610 /* note: when modest-tny-account-store is finalized,
611 it will automatically set all network connections
614 /* gtk_main_quit (); */
618 modest_ui_actions_on_close_window (GtkAction *action, ModestWindow *win)
622 g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value);
624 /* if (MODEST_IS_MSG_VIEW_WINDOW (win)) { */
625 /* gtk_widget_destroy (GTK_WIDGET (win)); */
626 /* } else if (MODEST_IS_MSG_EDIT_WINDOW (win)) { */
627 /* gboolean ret_value; */
628 /* g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value); */
629 /* } else if (MODEST_IS_WINDOW (win)) { */
630 /* gtk_widget_destroy (GTK_WIDGET (win)); */
632 /* g_return_if_reached (); */
637 modest_ui_actions_on_add_to_contacts (GtkAction *action, ModestWindow *win)
639 GtkClipboard *clipboard = NULL;
640 gchar *selection = NULL;
642 clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
643 selection = gtk_clipboard_wait_for_text (clipboard);
645 /* Question: why is the clipboard being used here?
646 * It doesn't really make a lot of sense. */
650 modest_address_book_add_address (selection);
656 modest_ui_actions_on_accounts (GtkAction *action,
659 /* This is currently only implemented for Maemo */
660 #ifdef MODEST_PLATFORM_MAEMO /* Defined in config.h */
661 if (!modest_account_mgr_has_accounts (modest_runtime_get_account_mgr(), TRUE)) {
662 modest_ui_actions_run_account_setup_wizard (win);
665 /* Show the list of accounts */
666 GtkWindow *account_win = GTK_WINDOW (modest_account_view_window_new ());
667 gtk_window_set_transient_for (account_win, GTK_WINDOW (win));
669 /* The accounts dialog must be modal */
670 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), account_win);
671 modest_maemo_show_dialog_and_forget (GTK_WINDOW (win), GTK_DIALOG (account_win));
674 GtkWidget *dialog, *label;
676 /* Create the widgets */
678 dialog = gtk_dialog_new_with_buttons ("Message",
680 GTK_DIALOG_DESTROY_WITH_PARENT,
684 label = gtk_label_new ("Hello World!");
686 /* Ensure that the dialog box is destroyed when the user responds. */
688 g_signal_connect_swapped (dialog, "response",
689 G_CALLBACK (gtk_widget_destroy),
692 /* Add the label, and show everything we've added to the dialog. */
694 gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox),
696 gtk_widget_show_all (dialog);
697 #endif /* MODEST_PLATFORM_MAEMO */
701 on_smtp_servers_window_hide (GtkWindow* window, gpointer user_data)
703 /* Save any changes. */
704 modest_connection_specific_smtp_window_save_server_accounts (
705 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (window));
706 gtk_widget_destroy (GTK_WIDGET (window));
712 modest_ui_actions_on_smtp_servers (GtkAction *action, ModestWindow *win)
714 /* This is currently only implemented for Maemo,
715 * because it requires an API (libconic) to detect different connection
718 #ifdef MODEST_PLATFORM_MAEMO /* Defined in config.h */
720 /* Create the window if necessary: */
721 GtkWidget *specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
722 modest_connection_specific_smtp_window_fill_with_connections (
723 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (specific_window),
724 modest_runtime_get_account_mgr());
726 /* Show the window: */
727 gtk_window_set_transient_for (GTK_WINDOW (specific_window), GTK_WINDOW (win));
728 gtk_window_set_modal (GTK_WINDOW (specific_window), TRUE);
729 gtk_widget_show (specific_window);
731 /* Save changes when the window is hidden: */
732 g_signal_connect (specific_window, "hide",
733 G_CALLBACK (on_smtp_servers_window_hide), win);
734 #endif /* MODEST_PLATFORM_MAEMO */
738 modest_ui_actions_compose_msg(ModestWindow *win,
741 const gchar *bcc_str,
742 const gchar *subject_str,
743 const gchar *body_str,
746 gchar *account_name = NULL;
748 TnyAccount *account = NULL;
749 TnyFolder *folder = NULL;
750 gchar *from_str = NULL, *signature = NULL, *body = NULL;
751 gboolean use_signature = FALSE;
752 ModestWindow *msg_win = NULL;
753 ModestAccountMgr *mgr = modest_runtime_get_account_mgr();
754 ModestTnyAccountStore *store = modest_runtime_get_account_store();
756 if (win) account_name = g_strdup (modest_window_get_active_account (win));
757 if (!account_name) account_name = modest_account_mgr_get_default_account(mgr);
759 g_printerr ("modest: no account found\n");
762 account = modest_tny_account_store_get_server_account (store, account_name, TNY_ACCOUNT_TYPE_STORE);
764 g_printerr ("modest: failed to get tnyaccount for '%s'\n", account_name);
767 folder = modest_tny_account_get_special_folder (account, TNY_FOLDER_TYPE_DRAFTS);
769 g_printerr ("modest: failed to find Drafts folder\n");
772 from_str = modest_account_mgr_get_from_string (mgr, account_name);
774 g_printerr ("modest: failed get from string for '%s'\n", account_name);
778 signature = modest_account_mgr_get_signature (mgr, account_name, &use_signature);
779 if (body_str != NULL) {
780 body = use_signature ? g_strconcat(body_str, "\n", signature, NULL) : g_strdup(body_str);
782 body = use_signature ? g_strconcat("\n", signature, NULL) : g_strdup("");
785 msg = modest_tny_msg_new (to_str, from_str, cc_str, bcc_str, subject_str, body, NULL);
787 g_printerr ("modest: failed to create new msg\n");
791 /* Create and register edit window */
792 /* This is destroyed by TODO. */
793 msg_win = modest_msg_edit_window_new (msg, account_name, FALSE);
794 while (attachments) {
795 modest_msg_edit_window_attach_file_one((ModestMsgEditWindow *)msg_win,
797 attachments = g_slist_next(attachments);
799 modest_window_mgr_register_window (modest_runtime_get_window_mgr(), msg_win);
802 gtk_window_set_transient_for (GTK_WINDOW (msg_win),
805 gtk_widget_show_all (GTK_WIDGET (msg_win));
811 g_free (account_name);
812 if (account) g_object_unref (G_OBJECT(account));
813 if (folder) g_object_unref (G_OBJECT(folder));
814 if (msg_win) g_object_unref (G_OBJECT(msg_win));
815 if (msg) g_object_unref (G_OBJECT(msg));
819 modest_ui_actions_on_new_msg (GtkAction *action, ModestWindow *win)
821 /* if there are no accounts yet, just show the wizard */
822 if (!modest_account_mgr_has_accounts (modest_runtime_get_account_mgr(), TRUE)) {
823 if (!modest_ui_actions_run_account_setup_wizard (win)) return;
826 modest_ui_actions_compose_msg(win, NULL, NULL, NULL, NULL, NULL, NULL);
830 modest_ui_actions_msg_retrieval_check (ModestMailOperation *mail_op,
834 ModestMailOperationStatus status;
836 /* If there is no message or the operation was not successful */
837 status = modest_mail_operation_get_status (mail_op);
838 if (!msg || status != MODEST_MAIL_OPERATION_STATUS_SUCCESS) {
840 /* Remove the header from the preregistered uids */
841 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (),
851 open_msg_cb (ModestMailOperation *mail_op, TnyHeader *header, TnyMsg *msg, gpointer user_data)
853 ModestWindowMgr *mgr = NULL;
854 ModestWindow *parent_win = NULL;
855 ModestWindow *win = NULL;
856 TnyFolderType folder_type = TNY_FOLDER_TYPE_UNKNOWN;
857 gchar *account = NULL;
859 gboolean open_in_editor = FALSE;
861 /* Do nothing if there was any problem with the mail
862 operation. The error will be shown by the error_handler of
863 the mail operation */
864 if (!modest_ui_actions_msg_retrieval_check (mail_op, header, msg))
867 parent_win = (ModestWindow *) modest_mail_operation_get_source (mail_op);
868 folder = tny_header_get_folder (header);
870 /* Mark header as read */
871 headers_action_mark_as_read (header, MODEST_WINDOW(parent_win), NULL);
873 /* Gets folder type (OUTBOX headers will be opened in edit window */
874 if (modest_tny_folder_is_local_folder (folder)) {
875 folder_type = modest_tny_folder_get_local_or_mmc_folder_type (folder);
876 if (folder_type == TNY_FOLDER_TYPE_INVALID)
877 g_warning ("%s: BUG: TNY_FOLDER_TYPE_INVALID", __FUNCTION__);
881 if (folder_type == TNY_FOLDER_TYPE_OUTBOX) {
882 TnyTransportAccount *traccount = NULL;
883 ModestTnyAccountStore *accstore = modest_runtime_get_account_store();
884 traccount = modest_tny_account_store_get_transport_account_from_outbox_header(accstore, header);
886 ModestTnySendQueue *send_queue = NULL;
887 ModestTnySendQueueStatus status;
889 account = g_strdup(modest_tny_account_get_parent_modest_account_name_for_server_account(
890 TNY_ACCOUNT(traccount)));
891 send_queue = modest_runtime_get_send_queue(traccount);
892 msg_id = modest_tny_send_queue_get_msg_id (header);
893 status = modest_tny_send_queue_get_msg_status(send_queue, msg_id);
894 /* Only open messages in outbox with the editor if they are in Failed state */
895 if (status == MODEST_TNY_SEND_QUEUE_FAILED) {
896 open_in_editor = TRUE;
899 g_object_unref(traccount);
901 g_warning("Cannot get transport account for message in outbox!!");
903 } else if (folder_type == TNY_FOLDER_TYPE_DRAFTS) {
904 open_in_editor = TRUE; /* Open in editor if the message is in the Drafts folder */
909 account = g_strdup (modest_window_get_active_account (MODEST_WINDOW (parent_win)));
911 account = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
913 if (open_in_editor) {
914 ModestAccountMgr *mgr = modest_runtime_get_account_mgr ();
915 const gchar *from_header = NULL;
917 from_header = tny_header_get_from (header);
919 /* we cannot edit without a valid account... */
920 if (!modest_account_mgr_has_accounts(mgr, TRUE)) {
921 if (!modest_ui_actions_run_account_setup_wizard(parent_win))
926 GSList *accounts = modest_account_mgr_account_names (mgr, TRUE);
928 for (node = accounts; node != NULL; node = g_slist_next (node)) {
929 gchar *from = modest_account_mgr_get_from_string (mgr, node->data);
931 if (from && (strcmp (from_header, from) == 0)) {
933 account = g_strdup (node->data);
939 g_slist_foreach (accounts, (GFunc) g_free, NULL);
940 g_slist_free (accounts);
943 win = modest_msg_edit_window_new (msg, account, TRUE);
947 modest_platform_information_banner (NULL, NULL, _("mail_ib_opening_draft_message"));
950 gchar *uid = modest_tny_folder_get_header_unique_id (header);
952 if (MODEST_IS_MAIN_WINDOW (parent_win)) {
953 GtkWidget *header_view;
954 GtkTreeSelection *sel;
955 GList *sel_list = NULL;
958 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(parent_win),
959 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
961 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
962 sel_list = gtk_tree_selection_get_selected_rows (sel, &model);
964 if (sel_list != NULL) {
965 GtkTreeRowReference *row_reference;
967 row_reference = gtk_tree_row_reference_new (model, (GtkTreePath *) sel_list->data);
968 g_list_foreach (sel_list, (GFunc) gtk_tree_path_free, NULL);
969 g_list_free (sel_list);
971 win = modest_msg_view_window_new_with_header_model (
972 msg, account, (const gchar*) uid,
973 model, row_reference);
974 gtk_tree_row_reference_free (row_reference);
976 win = modest_msg_view_window_new_for_attachment (msg, account, (const gchar*) uid);
979 win = modest_msg_view_window_new_for_attachment (msg, account, (const gchar*) uid);
984 /* Register and show new window */
986 mgr = modest_runtime_get_window_mgr ();
987 modest_window_mgr_register_window (mgr, win);
988 g_object_unref (win);
989 gtk_widget_show_all (GTK_WIDGET(win));
992 /* Update toolbar dimming state */
993 if (MODEST_IS_MAIN_WINDOW (parent_win)) {
994 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (parent_win));
1000 g_object_unref (parent_win);
1001 g_object_unref (folder);
1006 open_msg_error_handler (ModestMailOperation *mail_op,
1009 /* Show the message error */
1010 GObject *win = modest_mail_operation_get_source (mail_op);
1012 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
1013 (gchar *) user_data);
1015 g_object_unref (win);
1019 modest_ui_actions_get_msgs_full_error_handler (ModestMailOperation *mail_op,
1022 const GError *error;
1023 GObject *win = modest_mail_operation_get_source (mail_op);
1025 error = modest_mail_operation_get_error (mail_op);
1027 if (error->code == MODEST_MAIL_OPERATION_ERROR_MESSAGE_SIZE_LIMIT) {
1029 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
1032 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
1033 _("mail_ni_ui_folder_get_msg_folder_error"));
1037 g_object_unref (win);
1041 * Returns the account a list of headers belongs to. It returns a
1042 * *new* reference so don't forget to unref it
1045 get_account_from_header_list (TnyList *headers)
1047 TnyAccount *account = NULL;
1049 if (tny_list_get_length (headers) > 0) {
1050 TnyIterator *iter = tny_list_create_iterator (headers);
1051 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter));
1052 TnyFolder *folder = tny_header_get_folder (header);
1053 account = tny_folder_get_account (folder);
1054 g_object_unref (folder);
1055 g_object_unref (header);
1056 g_object_unref (iter);
1062 * This function is used by both modest_ui_actions_on_open and
1063 * modest_ui_actions_on_header_activated. This way we always do the
1064 * same when trying to open messages.
1067 _modest_ui_actions_open (TnyList *headers, ModestWindow *win)
1069 ModestWindowMgr *mgr = NULL;
1070 TnyIterator *iter = NULL, *iter_not_opened = NULL;
1071 ModestMailOperation *mail_op = NULL;
1072 TnyList *not_opened_headers = NULL;
1073 TnyHeaderFlags flags = 0;
1074 TnyAccount *account;
1076 g_return_if_fail (headers != NULL);
1078 /* Check that only one message is selected for opening */
1079 if (tny_list_get_length (headers) != 1) {
1080 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
1081 _("mcen_ib_select_one_message"));
1085 mgr = modest_runtime_get_window_mgr ();
1086 iter = tny_list_create_iterator (headers);
1088 /* Get the account */
1089 account = get_account_from_header_list (headers);
1091 /* Look if we already have a message view for each header. If
1092 true, then remove the header from the list of headers to
1094 not_opened_headers = tny_simple_list_new ();
1095 while (!tny_iterator_is_done (iter)) {
1097 ModestWindow *window = NULL;
1098 TnyHeader *header = NULL;
1099 gboolean found = FALSE;
1101 header = TNY_HEADER (tny_iterator_get_current (iter));
1103 flags = tny_header_get_flags (header);
1106 found = modest_window_mgr_find_registered_header (mgr, header, &window);
1108 /* Do not open again the message and present the
1109 window to the user */
1112 gtk_window_present (GTK_WINDOW (window));
1114 /* the header has been registered already, we don't do
1115 * anything but wait for the window to come up*/
1116 g_debug ("header %p already registered, waiting for window", header);
1118 tny_list_append (not_opened_headers, G_OBJECT (header));
1122 g_object_unref (header);
1124 tny_iterator_next (iter);
1126 g_object_unref (iter);
1129 /* Open each message */
1130 if (tny_list_get_length (not_opened_headers) == 0)
1133 /* If some messages would have to be downloaded, ask the user to
1134 * make a connection. It's generally easier to do this here (in the mainloop)
1135 * than later in a thread:
1137 if (tny_list_get_length (not_opened_headers) > 0) {
1139 gboolean found = FALSE;
1141 iter = tny_list_create_iterator (not_opened_headers);
1142 while (!tny_iterator_is_done (iter) && !found) {
1143 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter));
1144 if (!(tny_header_get_flags (header) & TNY_HEADER_FLAG_CACHED))
1147 tny_iterator_next (iter);
1149 g_object_unref (header);
1151 g_object_unref (iter);
1153 /* Ask the user if there are any uncached messages */
1154 if (found && !connect_to_get_msg (win,
1155 header_list_count_uncached_msgs (not_opened_headers),
1160 /* Register the headers before actually creating the windows: */
1161 iter_not_opened = tny_list_create_iterator (not_opened_headers);
1162 while (!tny_iterator_is_done (iter_not_opened)) {
1163 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter_not_opened));
1165 modest_window_mgr_register_header (mgr, header, NULL);
1166 g_object_unref (header);
1168 tny_iterator_next (iter_not_opened);
1170 g_object_unref (iter_not_opened);
1171 iter_not_opened = NULL;
1173 /* Create the mail operation */
1174 if (tny_list_get_length (not_opened_headers) > 1) {
1175 mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT (win),
1176 modest_ui_actions_get_msgs_full_error_handler,
1178 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
1180 modest_mail_operation_get_msgs_full (mail_op,
1186 TnyIterator *iter = tny_list_create_iterator (not_opened_headers);
1187 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter));
1188 const gchar *proto_name;
1190 ModestTransportStoreProtocol proto;
1192 /* Get the error message depending on the protocol */
1193 proto_name = tny_account_get_proto (account);
1194 if (proto_name != NULL) {
1195 proto = modest_protocol_info_get_transport_store_protocol (proto_name);
1197 proto = MODEST_PROTOCOL_STORE_MAILDIR;
1200 if (proto == MODEST_PROTOCOL_STORE_POP) {
1201 error_msg = g_strdup (_("emev_ni_ui_pop3_msg_recv_error"));
1202 } else if (proto == MODEST_PROTOCOL_STORE_IMAP) {
1203 error_msg = g_strdup_printf (_("emev_ni_ui_imap_message_not_available_in_server"),
1204 tny_header_get_subject (header));
1206 error_msg = g_strdup (_("mail_ni_ui_folder_get_msg_folder_error"));
1209 /* Create and call the mail operation */
1210 mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT (win),
1211 open_msg_error_handler,
1214 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
1216 modest_mail_operation_get_msg (mail_op, header, open_msg_cb, NULL);
1218 g_object_unref (header);
1219 g_object_unref (iter);
1221 g_object_unref (mail_op);
1226 g_object_unref (account);
1227 if (not_opened_headers)
1228 g_object_unref (not_opened_headers);
1232 modest_ui_actions_on_open (GtkAction *action, ModestWindow *win)
1237 headers = get_selected_headers (win);
1242 _modest_ui_actions_open (headers, win);
1244 g_object_unref(headers);
1249 free_reply_forward_helper (gpointer data)
1251 ReplyForwardHelper *helper;
1253 helper = (ReplyForwardHelper *) data;
1254 g_free (helper->account_name);
1255 g_slice_free (ReplyForwardHelper, helper);
1259 reply_forward_cb (ModestMailOperation *mail_op, TnyHeader *header, TnyMsg *msg,
1263 ReplyForwardHelper *rf_helper;
1264 ModestWindow *msg_win = NULL;
1265 ModestEditType edit_type;
1267 TnyAccount *account = NULL;
1268 ModestWindowMgr *mgr = NULL;
1269 gchar *signature = NULL;
1270 gboolean use_signature;
1272 /* If there was any error. The mail operation could be NULL,
1273 this means that we already have the message downloaded and
1274 that we didn't do a mail operation to retrieve it */
1275 if (mail_op && !modest_ui_actions_msg_retrieval_check (mail_op, header, msg))
1278 g_return_if_fail (user_data != NULL);
1279 rf_helper = (ReplyForwardHelper *) user_data;
1281 from = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(),
1282 rf_helper->account_name);
1283 signature = modest_account_mgr_get_signature (modest_runtime_get_account_mgr(),
1284 rf_helper->account_name,
1287 /* Create reply mail */
1288 switch (rf_helper->action) {
1291 modest_tny_msg_create_reply_msg (msg, header, from, signature,
1292 rf_helper->reply_forward_type,
1293 MODEST_TNY_MSG_REPLY_MODE_SENDER);
1295 case ACTION_REPLY_TO_ALL:
1297 modest_tny_msg_create_reply_msg (msg, header, from, signature, rf_helper->reply_forward_type,
1298 MODEST_TNY_MSG_REPLY_MODE_ALL);
1299 edit_type = MODEST_EDIT_TYPE_REPLY;
1301 case ACTION_FORWARD:
1303 modest_tny_msg_create_forward_msg (msg, from, signature, rf_helper->reply_forward_type);
1304 edit_type = MODEST_EDIT_TYPE_FORWARD;
1307 g_return_if_reached ();
1314 g_printerr ("modest: failed to create message\n");
1318 account = modest_tny_account_store_get_server_account (modest_runtime_get_account_store(),
1319 rf_helper->account_name,
1320 TNY_ACCOUNT_TYPE_STORE);
1322 g_printerr ("modest: failed to get tnyaccount for '%s'\n", rf_helper->account_name);
1326 /* Create and register the windows */
1327 msg_win = modest_msg_edit_window_new (new_msg, rf_helper->account_name, FALSE);
1328 mgr = modest_runtime_get_window_mgr ();
1329 modest_window_mgr_register_window (mgr, msg_win);
1331 if (rf_helper->parent_window != NULL) {
1332 gdouble parent_zoom;
1334 parent_zoom = modest_window_get_zoom (MODEST_WINDOW (rf_helper->parent_window));
1335 modest_window_set_zoom (msg_win, parent_zoom);
1338 /* Show edit window */
1339 gtk_widget_show_all (GTK_WIDGET (msg_win));
1343 g_object_unref (msg_win);
1345 g_object_unref (G_OBJECT (new_msg));
1347 g_object_unref (G_OBJECT (account));
1348 /* g_object_unref (msg); */
1349 free_reply_forward_helper (rf_helper);
1352 /* Checks a list of headers. If any of them are not currently
1353 * downloaded (CACHED) then returns TRUE else returns FALSE.
1356 header_list_count_uncached_msgs (TnyList *header_list)
1359 gint uncached_messages = 0;
1361 iter = tny_list_create_iterator (header_list);
1362 while (!tny_iterator_is_done (iter)) {
1365 header = TNY_HEADER (tny_iterator_get_current (iter));
1367 if (!(tny_header_get_flags (header) & TNY_HEADER_FLAG_CACHED))
1368 uncached_messages ++;
1369 g_object_unref (header);
1372 tny_iterator_next (iter);
1374 g_object_unref (iter);
1376 return uncached_messages;
1379 /* Returns FALSE if the user does not want to download the
1380 * messages. Returns TRUE if the user allowed the download.
1383 connect_to_get_msg (ModestWindow *win,
1384 gint num_of_uncached_msgs,
1385 TnyAccount *account)
1387 GtkResponseType response;
1389 /* Allways download if we are online. */
1390 if (tny_device_is_online (modest_runtime_get_device ()))
1393 /* If offline, then ask for user permission to download the messages */
1394 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
1395 ngettext("mcen_nc_get_msg",
1397 num_of_uncached_msgs));
1399 if (response == GTK_RESPONSE_CANCEL)
1402 return modest_platform_connect_and_wait((GtkWindow *) win, account);
1406 * Common code for the reply and forward actions
1409 reply_forward (ReplyForwardAction action, ModestWindow *win)
1411 ModestMailOperation *mail_op = NULL;
1412 TnyList *header_list = NULL;
1413 ReplyForwardHelper *rf_helper = NULL;
1414 guint reply_forward_type;
1415 gboolean continue_download = TRUE;
1416 gboolean do_retrieve = TRUE;
1418 g_return_if_fail (MODEST_IS_WINDOW(win));
1420 /* we need an account when editing */
1421 if (!modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE)) {
1422 if (!modest_ui_actions_run_account_setup_wizard (win))
1426 header_list = get_selected_headers (win);
1430 reply_forward_type =
1431 modest_conf_get_int (modest_runtime_get_conf (),
1432 (action == ACTION_FORWARD) ? MODEST_CONF_FORWARD_TYPE : MODEST_CONF_REPLY_TYPE,
1435 /* check if we need to download msg before asking about it */
1436 do_retrieve = (action == ACTION_FORWARD) ||
1437 (reply_forward_type != MODEST_TNY_MSG_REPLY_TYPE_CITE);
1440 gint num_of_unc_msgs;
1442 /* check that the messages have been previously downloaded */
1443 num_of_unc_msgs = header_list_count_uncached_msgs(header_list);
1444 /* If there are any uncached message ask the user
1445 * whether he/she wants to download them. */
1446 if (num_of_unc_msgs) {
1447 TnyAccount *account = get_account_from_header_list (header_list);
1448 continue_download = connect_to_get_msg (win, num_of_unc_msgs, account);
1449 g_object_unref (account);
1453 if (!continue_download) {
1454 g_object_unref (header_list);
1458 /* We assume that we can only select messages of the
1459 same folder and that we reply all of them from the
1460 same account. In fact the interface currently only
1461 allows single selection */
1464 rf_helper = g_slice_new0 (ReplyForwardHelper);
1465 rf_helper->reply_forward_type = reply_forward_type;
1466 rf_helper->action = action;
1467 rf_helper->account_name = g_strdup (modest_window_get_active_account (win));
1469 if ((win != NULL) && (MODEST_IS_WINDOW (win)))
1470 rf_helper->parent_window = GTK_WIDGET (win);
1471 if (!rf_helper->account_name)
1472 rf_helper->account_name =
1473 modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
1475 if (MODEST_IS_MSG_VIEW_WINDOW(win)) {
1478 /* Get header and message. Do not free them here, the
1479 reply_forward_cb must do it */
1480 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW(win));
1481 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW(win));
1482 if (!msg || !header) {
1484 g_object_unref (msg);
1485 g_printerr ("modest: no message found\n");
1488 reply_forward_cb (NULL, header, msg, rf_helper);
1491 g_object_unref (header);
1496 /* Only reply/forward to one message */
1497 iter = tny_list_create_iterator (header_list);
1498 header = TNY_HEADER (tny_iterator_get_current (iter));
1499 g_object_unref (iter);
1502 /* Retrieve messages */
1505 modest_mail_operation_new_with_error_handling (G_OBJECT(win),
1506 modest_ui_actions_get_msgs_full_error_handler,
1508 modest_mail_operation_queue_add (
1509 modest_runtime_get_mail_operation_queue (), mail_op);
1511 modest_mail_operation_get_msg (mail_op,
1516 g_object_unref(mail_op);
1518 /* we put a ref here to prevent double unref as the reply
1519 * forward callback unrefs the header at its end */
1520 reply_forward_cb (NULL, header, NULL, rf_helper);
1524 g_object_unref (header);
1530 g_object_unref (header_list);
1534 modest_ui_actions_on_reply (GtkAction *action, ModestWindow *win)
1536 g_return_if_fail (MODEST_IS_WINDOW(win));
1538 reply_forward (ACTION_REPLY, win);
1542 modest_ui_actions_on_forward (GtkAction *action, ModestWindow *win)
1544 g_return_if_fail (MODEST_IS_WINDOW(win));
1546 reply_forward (ACTION_FORWARD, win);
1550 modest_ui_actions_on_reply_all (GtkAction *action, ModestWindow *win)
1552 g_return_if_fail (MODEST_IS_WINDOW(win));
1554 reply_forward (ACTION_REPLY_TO_ALL, win);
1558 modest_ui_actions_on_next (GtkAction *action,
1559 ModestWindow *window)
1561 if (MODEST_IS_MAIN_WINDOW (window)) {
1562 GtkWidget *header_view;
1564 header_view = modest_main_window_get_child_widget (
1565 MODEST_MAIN_WINDOW(window),
1566 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1570 modest_header_view_select_next (
1571 MODEST_HEADER_VIEW(header_view));
1572 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
1573 modest_msg_view_window_select_next_message (
1574 MODEST_MSG_VIEW_WINDOW (window));
1576 g_return_if_reached ();
1581 modest_ui_actions_on_prev (GtkAction *action,
1582 ModestWindow *window)
1584 g_return_if_fail (MODEST_IS_WINDOW(window));
1586 if (MODEST_IS_MAIN_WINDOW (window)) {
1587 GtkWidget *header_view;
1588 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
1589 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1593 modest_header_view_select_prev (MODEST_HEADER_VIEW(header_view));
1594 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
1595 modest_msg_view_window_select_previous_message (MODEST_MSG_VIEW_WINDOW (window));
1597 g_return_if_reached ();
1602 modest_ui_actions_on_sort (GtkAction *action,
1603 ModestWindow *window)
1605 g_return_if_fail (MODEST_IS_WINDOW(window));
1607 if (MODEST_IS_MAIN_WINDOW (window)) {
1608 GtkWidget *header_view;
1609 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
1610 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1612 modest_platform_information_banner (NULL, NULL, _CS("ckdg_ib_nothing_to_sort"));
1617 /* Show sorting dialog */
1618 modest_platform_run_sort_dialog (GTK_WINDOW (window), MODEST_SORT_HEADERS);
1623 new_messages_arrived (ModestMailOperation *self,
1624 TnyList *new_headers,
1629 source = modest_mail_operation_get_source (self);
1631 /* Notify new messages have been downloaded. Do not notify if
1632 the send&receive was invoked by the user, i.e, if the mail
1633 operation has a source (the main window) */
1634 if ((new_headers != NULL) && (tny_list_get_length (new_headers) > 0) && !source)
1635 modest_platform_on_new_headers_received (new_headers);
1638 g_object_unref (source);
1642 TnyAccount *account;
1644 gchar *account_name;
1648 do_send_receive_performer (gboolean canceled,
1650 GtkWindow *parent_window,
1651 TnyAccount *account,
1654 ModestMailOperation *mail_op;
1655 SendReceiveInfo *info;
1657 info = (SendReceiveInfo *) user_data;
1659 if (err || canceled) {
1664 /* Set send/receive operation in progress */
1665 if (info->win && MODEST_IS_MAIN_WINDOW (info->win))
1666 modest_main_window_notify_send_receive_initied (MODEST_MAIN_WINDOW (info->win));
1668 mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT (info->win),
1669 modest_ui_actions_send_receive_error_handler,
1672 if (info->win && MODEST_IS_MAIN_WINDOW (info->win))
1673 g_signal_connect (G_OBJECT(mail_op), "operation-finished",
1674 G_CALLBACK (on_send_receive_finished),
1677 /* Send & receive. */
1678 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
1679 modest_mail_operation_update_account (mail_op, info->account_name, new_messages_arrived, info->win);
1680 g_object_unref (G_OBJECT (mail_op));
1684 if (info->account_name)
1685 g_free (info->account_name);
1687 g_object_unref (info->win);
1689 g_object_unref (info->account);
1690 g_slice_free (SendReceiveInfo, info);
1694 * This function performs the send & receive required actions. The
1695 * window is used to create the mail operation. Typically it should
1696 * always be the main window, but we pass it as argument in order to
1700 modest_ui_actions_do_send_receive (const gchar *account_name,
1703 gchar *acc_name = NULL;
1704 SendReceiveInfo *info;
1705 ModestTnyAccountStore *acc_store;
1707 /* If no account name was provided then get the current account, and if
1708 there is no current account then pick the default one: */
1709 if (!account_name) {
1711 acc_name = g_strdup (modest_window_get_active_account (win));
1713 acc_name = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
1715 g_printerr ("modest: cannot get default account\n");
1719 acc_name = g_strdup (account_name);
1722 acc_store = modest_runtime_get_account_store ();
1724 /* Create the info for the connect and perform */
1725 info = g_slice_new (SendReceiveInfo);
1726 info->account_name = acc_name;
1727 info->win = (win) ? g_object_ref (win) : NULL;
1728 info->account = modest_tny_account_store_get_server_account (acc_store, acc_name,
1729 TNY_ACCOUNT_TYPE_STORE);
1731 /* Invoke the connect and perform */
1732 modest_platform_connect_and_perform ((win) ? GTK_WINDOW (win) : NULL, info->account,
1733 do_send_receive_performer, info);
1738 modest_ui_actions_do_cancel_send (const gchar *account_name,
1741 TnyTransportAccount *transport_account;
1742 TnySendQueue *send_queue = NULL;
1743 GError *error = NULL;
1745 /* Get transport account */
1747 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
1748 (modest_runtime_get_account_store(),
1750 TNY_ACCOUNT_TYPE_TRANSPORT));
1751 if (!transport_account) {
1752 g_printerr ("modest: no transport account found for '%s'\n", account_name);
1757 send_queue = TNY_SEND_QUEUE (modest_runtime_get_send_queue (transport_account));
1758 if (!TNY_IS_SEND_QUEUE(send_queue)) {
1759 g_set_error (&error, MODEST_MAIL_OPERATION_ERROR,
1760 MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND,
1761 "modest: could not find send queue for account\n");
1763 /* Keeep messages in outbox folder */
1764 tny_send_queue_cancel (send_queue, FALSE, &error);
1768 if (transport_account != NULL)
1769 g_object_unref (G_OBJECT (transport_account));
1773 modest_ui_actions_cancel_send_all (ModestWindow *win)
1775 GSList *account_names, *iter;
1777 account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
1780 iter = account_names;
1782 modest_ui_actions_do_cancel_send ((const char*) iter->data, win);
1783 iter = g_slist_next (iter);
1786 modest_account_mgr_free_account_names (account_names);
1787 account_names = NULL;
1791 modest_ui_actions_cancel_send (GtkAction *action, ModestWindow *win)
1794 /* Check if accounts exist */
1795 gboolean accounts_exist =
1796 modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
1798 /* If not, allow the user to create an account before trying to send/receive. */
1799 if (!accounts_exist)
1800 modest_ui_actions_on_accounts (NULL, win);
1802 /* Cancel all sending operaitons */
1803 modest_ui_actions_cancel_send_all (win);
1807 * Refreshes all accounts. This function will be used by automatic
1811 modest_ui_actions_do_send_receive_all (ModestWindow *win)
1813 GSList *account_names, *iter;
1815 account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
1818 iter = account_names;
1820 modest_ui_actions_do_send_receive ((const char*) iter->data, win);
1821 iter = g_slist_next (iter);
1824 modest_account_mgr_free_account_names (account_names);
1825 account_names = NULL;
1829 refresh_current_folder(ModestWindow *win)
1831 /* Refresh currently selected folder. Note that if we only
1832 want to retreive the headers, then the refresh only will
1833 invoke a poke_status over all folders, i.e., only the
1834 total/unread count will be updated */
1835 if (MODEST_IS_MAIN_WINDOW (win)) {
1836 GtkWidget *header_view, *folder_view;
1837 TnyFolderStore *folder_store;
1839 /* Get folder and header view */
1841 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
1842 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
1846 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
1848 if (folder_store && TNY_IS_FOLDER (folder_store)) {
1850 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
1851 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1853 /* We do not need to set the contents style
1854 because it hasn't changed. We also do not
1855 need to save the widget status. Just force
1857 modest_header_view_set_folder (MODEST_HEADER_VIEW(header_view),
1858 TNY_FOLDER (folder_store),
1859 folder_refreshed_cb,
1860 MODEST_MAIN_WINDOW (win));
1864 g_object_unref (folder_store);
1870 * Handler of the click on Send&Receive button in the main toolbar
1873 modest_ui_actions_on_send_receive (GtkAction *action, ModestWindow *win)
1875 /* Check if accounts exist */
1876 gboolean accounts_exist =
1877 modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
1879 /* If not, allow the user to create an account before trying to send/receive. */
1880 if (!accounts_exist)
1881 modest_ui_actions_on_accounts (NULL, win);
1883 /* Refresh the current folder if we're viewing a window */
1885 refresh_current_folder (win);
1887 /* Refresh the active account */
1888 modest_ui_actions_do_send_receive (NULL, win);
1893 modest_ui_actions_toggle_header_list_view (GtkAction *action, ModestMainWindow *main_window)
1896 GtkWidget *header_view;
1898 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1900 header_view = modest_main_window_get_child_widget (main_window,
1901 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1905 conf = modest_runtime_get_conf ();
1907 /* what is saved/restored is depending on the style; thus; we save with
1908 * old style, then update the style, and restore for this new style
1910 modest_widget_memory_save (conf, G_OBJECT(header_view), MODEST_CONF_HEADER_VIEW_KEY);
1912 if (modest_header_view_get_style
1913 (MODEST_HEADER_VIEW(header_view)) == MODEST_HEADER_VIEW_STYLE_DETAILS)
1914 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
1915 MODEST_HEADER_VIEW_STYLE_TWOLINES);
1917 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
1918 MODEST_HEADER_VIEW_STYLE_DETAILS);
1920 modest_widget_memory_restore (conf, G_OBJECT(header_view),
1921 MODEST_CONF_HEADER_VIEW_KEY);
1926 modest_ui_actions_on_header_selected (ModestHeaderView *header_view,
1928 ModestMainWindow *main_window)
1930 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1931 g_return_if_fail (MODEST_IS_HEADER_VIEW (header_view));
1933 /* in the case the folder is empty, show the empty folder message and focus
1935 if (!header && gtk_widget_is_focus (GTK_WIDGET (header_view))) {
1936 if (modest_header_view_is_empty (header_view)) {
1937 TnyFolder *folder = modest_header_view_get_folder (header_view);
1938 GtkWidget *folder_view =
1939 modest_main_window_get_child_widget (main_window,
1940 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
1942 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view), folder, FALSE);
1943 gtk_widget_grab_focus (GTK_WIDGET (folder_view));
1947 /* If no header has been selected then exit */
1952 if (!gtk_widget_is_focus (GTK_WIDGET(header_view)))
1953 gtk_widget_grab_focus (GTK_WIDGET(header_view));
1955 /* Update toolbar dimming state */
1956 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
1960 modest_ui_actions_on_header_activated (ModestHeaderView *header_view,
1962 ModestMainWindow *main_window)
1966 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1971 if (modest_header_view_count_selected_headers (header_view) > 1) {
1972 hildon_banner_show_information (NULL, NULL, _("mcen_ib_select_one_message"));
1977 /* headers = tny_simple_list_new (); */
1978 /* tny_list_prepend (headers, G_OBJECT (header)); */
1979 headers = modest_header_view_get_selected_headers (header_view);
1981 _modest_ui_actions_open (headers, MODEST_WINDOW (main_window));
1983 g_object_unref (headers);
1987 set_active_account_from_tny_account (TnyAccount *account,
1988 ModestWindow *window)
1990 const gchar *server_acc_name = tny_account_get_id (account);
1992 /* We need the TnyAccount provided by the
1993 account store because that is the one that
1994 knows the name of the Modest account */
1995 TnyAccount *modest_server_account = modest_server_account =
1996 modest_tny_account_store_get_tny_account_by (modest_runtime_get_account_store (),
1997 MODEST_TNY_ACCOUNT_STORE_QUERY_ID,
1999 if (!modest_server_account) {
2000 g_warning ("%s: could not get tny account\n", __FUNCTION__);
2004 /* Update active account, but only if it's not a pseudo-account */
2005 if ((!modest_tny_account_is_virtual_local_folders(modest_server_account)) &&
2006 (!modest_tny_account_is_memory_card_account(modest_server_account))) {
2007 const gchar *modest_acc_name =
2008 modest_tny_account_get_parent_modest_account_name_for_server_account (modest_server_account);
2009 if (modest_acc_name)
2010 modest_window_set_active_account (window, modest_acc_name);
2013 g_object_unref (modest_server_account);
2018 folder_refreshed_cb (ModestMailOperation *mail_op,
2022 ModestMainWindow *win = NULL;
2023 GtkWidget *header_view;
2024 gboolean folder_empty = FALSE;
2025 gboolean all_marked_as_deleted = FALSE;
2027 g_return_if_fail (TNY_IS_FOLDER (folder));
2029 win = MODEST_MAIN_WINDOW (user_data);
2031 modest_main_window_get_child_widget(win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2034 TnyFolder *current_folder;
2036 current_folder = modest_header_view_get_folder (MODEST_HEADER_VIEW (header_view));
2037 if (current_folder != NULL && folder != current_folder) {
2038 g_object_unref (current_folder);
2041 g_object_unref (current_folder);
2044 /* Check if folder is empty and set headers view contents style */
2045 folder_empty = (tny_folder_get_all_count (folder) == 0);
2046 all_marked_as_deleted = modest_header_view_is_empty (MODEST_HEADER_VIEW(header_view));
2047 if (folder_empty || all_marked_as_deleted)
2048 modest_main_window_set_contents_style (win,
2049 MODEST_MAIN_WINDOW_CONTENTS_STYLE_EMPTY);
2053 modest_ui_actions_on_folder_selection_changed (ModestFolderView *folder_view,
2054 TnyFolderStore *folder_store,
2056 ModestMainWindow *main_window)
2059 GtkWidget *header_view;
2061 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2063 header_view = modest_main_window_get_child_widget(main_window,
2064 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2068 conf = modest_runtime_get_conf ();
2070 if (TNY_IS_ACCOUNT (folder_store)) {
2072 set_active_account_from_tny_account (TNY_ACCOUNT (folder_store), MODEST_WINDOW (main_window));
2074 /* Show account details */
2075 modest_main_window_set_contents_style (main_window, MODEST_MAIN_WINDOW_CONTENTS_STYLE_DETAILS);
2078 if (TNY_IS_FOLDER (folder_store) && selected) {
2080 /* Update the active account */
2081 TnyAccount *account = modest_tny_folder_get_account (TNY_FOLDER (folder_store));
2083 set_active_account_from_tny_account (account, MODEST_WINDOW (main_window));
2084 g_object_unref (account);
2088 /* Set the header style by default, it could
2089 be changed later by the refresh callback to
2091 modest_main_window_set_contents_style (main_window,
2092 MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS);
2094 /* Set folder on header view. This function
2095 will call tny_folder_refresh_async so we
2096 pass a callback that will be called when
2097 finished. We use that callback to set the
2098 empty view if there are no messages */
2099 modest_header_view_set_folder (MODEST_HEADER_VIEW(header_view),
2100 TNY_FOLDER (folder_store),
2101 folder_refreshed_cb,
2104 /* Restore configuration. We need to do this
2105 *after* the set_folder because the widget
2106 memory asks the header view about its
2108 modest_widget_memory_restore (modest_runtime_get_conf (),
2109 G_OBJECT(header_view),
2110 MODEST_CONF_HEADER_VIEW_KEY);
2112 /* Update the active account */
2113 //modest_window_set_active_account (MODEST_WINDOW (main_window), NULL);
2114 /* Save only if we're seeing headers */
2115 if (modest_main_window_get_contents_style (main_window) ==
2116 MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS)
2117 modest_widget_memory_save (conf, G_OBJECT (header_view),
2118 MODEST_CONF_HEADER_VIEW_KEY);
2119 modest_header_view_clear (MODEST_HEADER_VIEW(header_view));
2123 /* Update toolbar dimming state */
2124 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
2128 modest_ui_actions_on_item_not_found (ModestHeaderView *header_view,ModestItemType type,
2135 item = (type == MODEST_ITEM_TYPE_FOLDER) ? "folder" : "message";
2137 online = tny_device_is_online (modest_runtime_get_device());
2140 /* already online -- the item is simply not there... */
2141 dialog = gtk_message_dialog_new (GTK_WINDOW (win),
2143 GTK_MESSAGE_WARNING,
2145 _("The %s you selected cannot be found"),
2147 gtk_dialog_add_button (GTK_DIALOG (dialog),_("mcen_bd_dialog_ok"), GTK_RESPONSE_ACCEPT);
2148 gtk_dialog_run (GTK_DIALOG(dialog));
2150 dialog = gtk_dialog_new_with_buttons (_("Connection requested"),
2153 _("mcen_bd_dialog_cancel"),
2154 GTK_RESPONSE_REJECT,
2155 _("mcen_bd_dialog_ok"),
2156 GTK_RESPONSE_ACCEPT,
2158 txt = g_strdup_printf (_("This %s is not available in offline mode.\n"
2159 "Do you want to get online?"), item);
2160 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
2161 gtk_label_new (txt), FALSE, FALSE, 0);
2162 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
2165 gtk_window_set_default_size (GTK_WINDOW(dialog), 300, 300);
2166 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
2167 /* TODO: Comment about why is this commented out: */
2168 /* modest_platform_connect_and_wait (); */
2171 gtk_widget_destroy (dialog);
2175 modest_ui_actions_on_msg_link_hover (ModestMsgView *msgview, const gchar* link,
2178 /* g_message ("%s %s", __FUNCTION__, link); */
2183 modest_ui_actions_on_msg_link_clicked (ModestMsgView *msgview, const gchar* link,
2186 modest_platform_activate_uri (link);
2190 modest_ui_actions_on_msg_link_contextual (ModestMsgView *msgview, const gchar* link,
2193 modest_platform_show_uri_popup (link);
2197 modest_ui_actions_on_msg_attachment_clicked (ModestMsgView *msgview, TnyMimePart *mime_part,
2200 modest_msg_view_window_view_attachment (MODEST_MSG_VIEW_WINDOW (win), mime_part);
2204 modest_ui_actions_on_msg_recpt_activated (ModestMsgView *msgview,
2205 const gchar *address,
2208 /* g_message ("%s %s", __FUNCTION__, address); */
2212 on_save_to_drafts_cb (ModestMailOperation *mail_op,
2213 TnyMsg *saved_draft,
2216 ModestMsgEditWindow *edit_window;
2218 edit_window = MODEST_MSG_EDIT_WINDOW (user_data);
2220 /* If there was any error do nothing */
2221 if (modest_mail_operation_get_error (mail_op) != NULL)
2224 modest_msg_edit_window_set_draft (edit_window, saved_draft);
2228 modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edit_window)
2230 TnyTransportAccount *transport_account;
2231 ModestMailOperation *mail_operation;
2233 gchar *account_name, *from;
2234 ModestAccountMgr *account_mgr;
2235 gchar *info_text = NULL;
2237 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window));
2239 data = modest_msg_edit_window_get_msg_data (edit_window);
2241 account_name = g_strdup (data->account_name);
2242 account_mgr = modest_runtime_get_account_mgr();
2244 account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
2246 account_name = modest_account_mgr_get_default_account (account_mgr);
2247 if (!account_name) {
2248 g_printerr ("modest: no account found\n");
2249 modest_msg_edit_window_free_msg_data (edit_window, data);
2253 if (!strcmp (account_name, MODEST_LOCAL_FOLDERS_ACCOUNT_ID)) {
2254 account_name = g_strdup (data->account_name);
2258 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
2259 (modest_runtime_get_account_store(),
2261 TNY_ACCOUNT_TYPE_TRANSPORT));
2262 if (!transport_account) {
2263 g_printerr ("modest: no transport account found for '%s'\n", account_name);
2264 g_free (account_name);
2265 modest_msg_edit_window_free_msg_data (edit_window, data);
2268 from = modest_account_mgr_get_from_string (account_mgr, account_name);
2270 /* Create the mail operation */
2271 mail_operation = modest_mail_operation_new (G_OBJECT(edit_window));
2272 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
2274 modest_mail_operation_save_to_drafts (mail_operation,
2286 data->priority_flags,
2287 on_save_to_drafts_cb,
2291 g_free (account_name);
2292 g_object_unref (G_OBJECT (transport_account));
2293 g_object_unref (G_OBJECT (mail_operation));
2295 modest_msg_edit_window_free_msg_data (edit_window, data);
2297 info_text = g_strdup_printf (_("mail_va_saved_to_drafts"), _("mcen_me_folder_drafts"));
2298 modest_platform_information_banner (NULL, NULL, info_text);
2299 modest_msg_edit_window_reset_modified (edit_window);
2303 /* For instance, when clicking the Send toolbar button when editing a message: */
2305 modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
2307 TnyTransportAccount *transport_account = NULL;
2309 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window));
2311 if (!modest_msg_edit_window_check_names (edit_window, TRUE))
2314 /* FIXME: Code added just for testing. The final version will
2315 use the send queue provided by tinymail and some
2317 MsgData *data = modest_msg_edit_window_get_msg_data (edit_window);
2319 ModestAccountMgr *account_mgr = modest_runtime_get_account_mgr();
2320 gchar *account_name = g_strdup (data->account_name);
2322 g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
2325 account_name = modest_account_mgr_get_default_account (account_mgr);
2327 if (!account_name) {
2328 modest_msg_edit_window_free_msg_data (edit_window, data);
2329 /* Run account setup wizard */
2330 if (!modest_ui_actions_run_account_setup_wizard (MODEST_WINDOW(edit_window)))
2334 /* Get the currently-active transport account for this modest account: */
2335 /* TnyTransportAccount *transport_account = */
2336 /* TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_transport_account_for_open_connection */
2337 /* (modest_runtime_get_account_store(), */
2338 /* account_name)); */
2339 if (strcmp (account_name, MODEST_LOCAL_FOLDERS_ACCOUNT_ID) != 0) {
2340 transport_account = TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
2341 (modest_runtime_get_account_store(),
2342 account_name, TNY_ACCOUNT_TYPE_TRANSPORT));
2345 if (!transport_account) {
2346 /* Run account setup wizard */
2347 if (!modest_ui_actions_run_account_setup_wizard(MODEST_WINDOW(edit_window)))
2351 gchar *from = modest_account_mgr_get_from_string (account_mgr, account_name);
2353 /* Create the mail operation */
2354 ModestMailOperation *mail_operation = modest_mail_operation_new (G_OBJECT(edit_window));
2355 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
2357 modest_mail_operation_send_new_mail (mail_operation,
2369 data->priority_flags);
2373 g_free (account_name);
2374 g_object_unref (G_OBJECT (transport_account));
2375 g_object_unref (G_OBJECT (mail_operation));
2377 modest_msg_edit_window_free_msg_data (edit_window, data);
2378 modest_msg_edit_window_set_sent (edit_window, TRUE);
2380 /* Save settings and close the window: */
2381 modest_ui_actions_on_close_window (NULL, MODEST_WINDOW (edit_window));
2385 modest_ui_actions_on_toggle_bold (GtkToggleAction *action,
2386 ModestMsgEditWindow *window)
2388 ModestMsgEditFormatState *format_state = NULL;
2390 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2391 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
2393 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2396 format_state = modest_msg_edit_window_get_format_state (window);
2397 g_return_if_fail (format_state != NULL);
2399 format_state->bold = gtk_toggle_action_get_active (action);
2400 modest_msg_edit_window_set_format_state (window, format_state);
2401 g_free (format_state);
2406 modest_ui_actions_on_toggle_italics (GtkToggleAction *action,
2407 ModestMsgEditWindow *window)
2409 ModestMsgEditFormatState *format_state = NULL;
2411 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2412 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
2414 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2417 format_state = modest_msg_edit_window_get_format_state (window);
2418 g_return_if_fail (format_state != NULL);
2420 format_state->italics = gtk_toggle_action_get_active (action);
2421 modest_msg_edit_window_set_format_state (window, format_state);
2422 g_free (format_state);
2427 modest_ui_actions_on_toggle_bullets (GtkToggleAction *action,
2428 ModestMsgEditWindow *window)
2430 ModestMsgEditFormatState *format_state = NULL;
2432 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2433 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
2435 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2438 format_state = modest_msg_edit_window_get_format_state (window);
2439 g_return_if_fail (format_state != NULL);
2441 format_state->bullet = gtk_toggle_action_get_active (action);
2442 modest_msg_edit_window_set_format_state (window, format_state);
2443 g_free (format_state);
2448 modest_ui_actions_on_change_justify (GtkRadioAction *action,
2449 GtkRadioAction *selected,
2450 ModestMsgEditWindow *window)
2452 ModestMsgEditFormatState *format_state = NULL;
2453 GtkJustification value;
2455 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2457 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2460 value = gtk_radio_action_get_current_value (selected);
2462 format_state = modest_msg_edit_window_get_format_state (window);
2463 g_return_if_fail (format_state != NULL);
2465 format_state->justification = value;
2466 modest_msg_edit_window_set_format_state (window, format_state);
2467 g_free (format_state);
2471 modest_ui_actions_on_select_editor_color (GtkAction *action,
2472 ModestMsgEditWindow *window)
2474 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2475 g_return_if_fail (GTK_IS_ACTION (action));
2477 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2480 modest_msg_edit_window_select_color (window);
2484 modest_ui_actions_on_select_editor_background_color (GtkAction *action,
2485 ModestMsgEditWindow *window)
2487 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2488 g_return_if_fail (GTK_IS_ACTION (action));
2490 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2493 modest_msg_edit_window_select_background_color (window);
2497 modest_ui_actions_on_insert_image (GtkAction *action,
2498 ModestMsgEditWindow *window)
2500 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2501 g_return_if_fail (GTK_IS_ACTION (action));
2503 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2506 modest_msg_edit_window_insert_image (window);
2510 modest_ui_actions_on_attach_file (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 modest_msg_edit_window_offer_attach_file (window);
2520 modest_ui_actions_on_remove_attachments (GtkAction *action,
2521 ModestMsgEditWindow *window)
2523 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2524 g_return_if_fail (GTK_IS_ACTION (action));
2526 modest_msg_edit_window_remove_attachments (window, NULL);
2530 modest_ui_actions_new_folder_error_handler (ModestMailOperation *mail_op,
2533 ModestMainWindow *window = MODEST_MAIN_WINDOW (user_data);
2534 const GError *error = modest_mail_operation_get_error (mail_op);
2537 modest_platform_information_banner (GTK_WIDGET (window), NULL,
2538 _("mail_in_ui_folder_create_error"));
2543 modest_ui_actions_create_folder(GtkWidget *parent_window,
2544 GtkWidget *folder_view)
2546 TnyFolderStore *parent_folder;
2548 parent_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
2550 if (parent_folder) {
2551 gboolean finished = FALSE;
2553 gchar *folder_name = NULL, *suggested_name = NULL;
2554 const gchar *proto_str = NULL;
2555 TnyAccount *account;
2557 if (TNY_IS_ACCOUNT (parent_folder))
2558 account = g_object_ref (parent_folder);
2560 account = tny_folder_get_account (TNY_FOLDER (parent_folder));
2561 proto_str = tny_account_get_proto (TNY_ACCOUNT (account));
2563 if (proto_str && modest_protocol_info_get_transport_store_protocol (proto_str) ==
2564 MODEST_PROTOCOL_STORE_POP) {
2566 hildon_banner_show_information (NULL, NULL, _("mail_in_ui_folder_create_error"));
2568 g_object_unref (account);
2570 /* Run the new folder dialog */
2572 result = modest_platform_run_new_folder_dialog (GTK_WINDOW (parent_window),
2577 g_free (suggested_name);
2578 suggested_name = NULL;
2580 if (result == GTK_RESPONSE_ACCEPT) {
2581 ModestMailOperation *mail_op;
2582 TnyFolder *new_folder = NULL;
2584 mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT(parent_window),
2585 modest_ui_actions_new_folder_error_handler,
2586 parent_window, NULL);
2588 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
2590 new_folder = modest_mail_operation_create_folder (mail_op,
2592 (const gchar *) folder_name);
2594 modest_folder_view_select_folder (MODEST_FOLDER_VIEW(folder_view),
2597 g_object_unref (new_folder);
2600 g_object_unref (mail_op);
2605 suggested_name = folder_name;
2609 g_object_unref (parent_folder);
2614 modest_ui_actions_on_new_folder (GtkAction *action, ModestMainWindow *main_window)
2616 GtkWidget *folder_view;
2618 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2620 folder_view = modest_main_window_get_child_widget (main_window,
2621 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2625 modest_ui_actions_create_folder (GTK_WIDGET (main_window), folder_view);
2629 modest_ui_actions_rename_folder_error_handler (ModestMailOperation *mail_op,
2632 ModestMainWindow *window = MODEST_MAIN_WINDOW (user_data);
2633 const GError *error = NULL;
2634 const gchar *message = NULL;
2636 /* Get error message */
2637 error = modest_mail_operation_get_error (mail_op);
2639 g_return_if_reached ();
2641 switch (error->code) {
2642 case MODEST_MAIL_OPERATION_ERROR_FOLDER_EXISTS:
2643 message = _CS("ckdg_ib_folder_already_exists");
2646 g_warning ("%s: BUG: unexpected error:[%d]: %s", __FUNCTION__,
2647 error->code, error->message);
2651 modest_platform_information_banner (GTK_WIDGET (window), NULL, message);
2655 modest_ui_actions_on_rename_folder (GtkAction *action,
2656 ModestMainWindow *main_window)
2658 TnyFolderStore *folder;
2659 GtkWidget *folder_view;
2660 GtkWidget *header_view;
2662 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2664 folder_view = modest_main_window_get_child_widget (main_window,
2665 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2669 header_view = modest_main_window_get_child_widget (main_window,
2670 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2675 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
2680 if (TNY_IS_FOLDER (folder)) {
2683 const gchar *current_name;
2684 TnyFolderStore *parent;
2685 gboolean do_rename = TRUE;
2687 current_name = tny_folder_get_name (TNY_FOLDER (folder));
2688 parent = tny_folder_get_folder_store (TNY_FOLDER (folder));
2689 response = modest_platform_run_rename_folder_dialog (GTK_WINDOW (main_window),
2690 parent, current_name,
2692 g_object_unref (parent);
2694 if (response != GTK_RESPONSE_ACCEPT || strlen (folder_name) == 0) {
2696 } else if (modest_platform_is_network_folderstore(folder) &&
2697 !tny_device_is_online (modest_runtime_get_device())) {
2698 TnyAccount *account = tny_folder_get_account(TNY_FOLDER(folder));
2699 do_rename = modest_platform_connect_and_wait(GTK_WINDOW(main_window), account);
2700 g_object_unref(account);
2704 ModestMailOperation *mail_op;
2705 GtkTreeSelection *sel = NULL;
2708 modest_mail_operation_new_with_error_handling (G_OBJECT(main_window),
2709 modest_ui_actions_rename_folder_error_handler,
2712 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
2715 /* Clear the headers view */
2716 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_view));
2717 gtk_tree_selection_unselect_all (sel);
2719 /* Select *after* the changes */
2720 modest_folder_view_select_folder (MODEST_FOLDER_VIEW(folder_view),
2721 TNY_FOLDER(folder), TRUE);
2723 /* Actually rename the folder */
2724 modest_mail_operation_rename_folder (mail_op,
2725 TNY_FOLDER (folder),
2726 (const gchar *) folder_name);
2728 g_object_unref (mail_op);
2729 g_free (folder_name);
2732 g_object_unref (folder);
2736 modest_ui_actions_delete_folder_error_handler (ModestMailOperation *mail_op,
2739 GObject *win = modest_mail_operation_get_source (mail_op);
2741 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
2742 _("mail_in_ui_folder_delete_error"));
2743 g_object_unref (win);
2747 delete_folder (ModestMainWindow *main_window, gboolean move_to_trash)
2749 TnyFolderStore *folder;
2750 GtkWidget *folder_view;
2753 gboolean do_delete = TRUE;
2755 g_return_val_if_fail (MODEST_IS_MAIN_WINDOW (main_window), FALSE);
2757 folder_view = modest_main_window_get_child_widget (main_window,
2758 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2762 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
2764 /* Show an error if it's an account */
2765 if (!TNY_IS_FOLDER (folder)) {
2766 modest_platform_run_information_dialog (GTK_WINDOW (main_window),
2767 _("mail_in_ui_folder_delete_error"));
2768 g_object_unref (G_OBJECT (folder));
2773 message = g_strdup_printf (_("mcen_nc_delete_folder_text"),
2774 tny_folder_get_name (TNY_FOLDER (folder)));
2775 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (main_window),
2776 (const gchar *) message);
2779 if (response != GTK_RESPONSE_OK) {
2781 } else if (modest_platform_is_network_folderstore(folder) &&
2782 !tny_device_is_online (modest_runtime_get_device())) {
2783 TnyAccount *account = tny_folder_get_account(TNY_FOLDER(folder));
2784 do_delete = modest_platform_connect_and_wait(GTK_WINDOW(main_window), account);
2785 g_object_unref(account);
2789 ModestMailOperation *mail_op;
2790 GtkTreeSelection *sel;
2792 /* Unselect the folder before deleting it to free the headers */
2793 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_view));
2794 gtk_tree_selection_unselect_all (sel);
2796 /* Create the mail operation */
2798 modest_mail_operation_new_with_error_handling (G_OBJECT(main_window),
2799 modest_ui_actions_delete_folder_error_handler,
2802 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
2804 modest_mail_operation_remove_folder (mail_op, TNY_FOLDER (folder), move_to_trash);
2805 g_object_unref (G_OBJECT (mail_op));
2808 g_object_unref (G_OBJECT (folder));
2814 modest_ui_actions_on_delete_folder (GtkAction *action,
2815 ModestMainWindow *main_window)
2817 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2819 delete_folder (main_window, FALSE);
2823 modest_ui_actions_on_move_folder_to_trash_folder (GtkAction *action, ModestMainWindow *main_window)
2825 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2827 delete_folder (main_window, TRUE);
2832 show_error (GtkWidget *parent_widget, const gchar* text)
2834 hildon_banner_show_information(parent_widget, NULL, text);
2837 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_window, text)); */
2839 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
2846 gtk_dialog_run (dialog);
2847 gtk_widget_destroy (GTK_WIDGET (dialog));
2852 modest_ui_actions_on_password_requested (TnyAccountStore *account_store,
2853 const gchar* server_account_name,
2858 ModestMainWindow *main_window)
2860 g_return_if_fail(server_account_name);
2862 /* Initalize output parameters: */
2869 #ifdef MODEST_PLATFORM_MAEMO
2870 /* Maemo uses a different (awkward) button order,
2871 * It should probably just use gtk_alternative_dialog_button_order ().
2873 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
2876 _("mcen_bd_dialog_ok"),
2877 GTK_RESPONSE_ACCEPT,
2878 _("mcen_bd_dialog_cancel"),
2879 GTK_RESPONSE_REJECT,
2882 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
2886 GTK_RESPONSE_REJECT,
2888 GTK_RESPONSE_ACCEPT,
2890 #endif /* MODEST_PLATFORM_MAEMO */
2892 gtk_window_set_transient_for (GTK_WINDOW(dialog), GTK_WINDOW(main_window));
2894 gchar *server_name = modest_account_mgr_get_server_account_hostname (
2895 modest_runtime_get_account_mgr(), server_account_name);
2896 if (!server_name) {/* This happened once, though I don't know why. murrayc. */
2897 g_warning("%s: Could not get server name for server account '%s'", __FUNCTION__, server_account_name);
2903 /* This causes a warning because the logical ID has no %s in it,
2904 * though the translation does, but there is not much we can do about that: */
2905 gchar *txt = g_strdup_printf (_("mail_ia_password_info"), server_name);
2906 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), gtk_label_new(txt),
2909 g_free (server_name);
2913 gchar *initial_username = modest_account_mgr_get_server_account_username (
2914 modest_runtime_get_account_mgr(), server_account_name);
2916 GtkWidget *entry_username = gtk_entry_new ();
2917 if (initial_username)
2918 gtk_entry_set_text (GTK_ENTRY (entry_username), initial_username);
2919 /* Dim this if a connection has ever succeeded with this username,
2920 * as per the UI spec: */
2921 const gboolean username_known =
2922 modest_account_mgr_get_server_account_username_has_succeeded(
2923 modest_runtime_get_account_mgr(), server_account_name);
2924 gtk_widget_set_sensitive (entry_username, !username_known);
2926 #ifdef MODEST_PLATFORM_MAEMO
2927 /* Auto-capitalization is the default, so let's turn it off: */
2928 hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_username), HILDON_GTK_INPUT_MODE_FULL);
2930 /* Create a size group to be used by all captions.
2931 * Note that HildonCaption does not create a default size group if we do not specify one.
2932 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
2933 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
2935 GtkWidget *caption = hildon_caption_new (sizegroup,
2936 _("mail_fi_username"), entry_username, NULL, HILDON_CAPTION_MANDATORY);
2937 gtk_widget_show (entry_username);
2938 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
2939 FALSE, FALSE, MODEST_MARGIN_HALF);
2940 gtk_widget_show (caption);
2942 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry_username,
2944 #endif /* MODEST_PLATFORM_MAEMO */
2947 GtkWidget *entry_password = gtk_entry_new ();
2948 gtk_entry_set_visibility (GTK_ENTRY(entry_password), FALSE);
2949 /* gtk_entry_set_invisible_char (GTK_ENTRY(entry_password), "*"); */
2951 #ifdef MODEST_PLATFORM_MAEMO
2952 /* Auto-capitalization is the default, so let's turn it off: */
2953 hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_password),
2954 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
2956 caption = hildon_caption_new (sizegroup,
2957 _("mail_fi_password"), entry_password, NULL, HILDON_CAPTION_MANDATORY);
2958 gtk_widget_show (entry_password);
2959 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
2960 FALSE, FALSE, MODEST_MARGIN_HALF);
2961 gtk_widget_show (caption);
2962 g_object_unref (sizegroup);
2964 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry_password,
2966 #endif /* MODEST_PLATFORM_MAEMO */
2968 if (initial_username != NULL)
2969 gtk_widget_grab_focus (GTK_WIDGET (entry_password));
2971 /* This is not in the Maemo UI spec:
2972 remember_pass_check = gtk_check_button_new_with_label (_("Remember password"));
2973 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), remember_pass_check,
2977 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
2979 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
2981 *username = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_username)));
2983 modest_account_mgr_set_server_account_username (
2984 modest_runtime_get_account_mgr(), server_account_name,
2987 const gboolean username_was_changed =
2988 (strcmp (*username, initial_username) != 0);
2989 if (username_was_changed) {
2990 g_warning ("%s: tinymail does not yet support changing the "
2991 "username in the get_password() callback.\n", __FUNCTION__);
2996 *password = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_password)));
2998 /* We do not save the password in the configuration,
2999 * because this function is only called for passwords that should
3000 * not be remembered:
3001 modest_server_account_set_password (
3002 modest_runtime_get_account_mgr(), server_account_name,
3011 show_error(GTK_WIDGET (main_window), _("mail_ib_login_cancelled"));
3023 /* This is not in the Maemo UI spec:
3024 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (remember_pass_check)))
3030 gtk_widget_destroy (dialog);
3032 /* printf ("DEBUG: %s: cancel=%d\n", __FUNCTION__, *cancel); */
3036 modest_ui_actions_on_cut (GtkAction *action,
3037 ModestWindow *window)
3039 GtkWidget *focused_widget;
3040 GtkClipboard *clipboard;
3042 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
3043 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
3044 if (GTK_IS_EDITABLE (focused_widget)) {
3045 gtk_editable_cut_clipboard (GTK_EDITABLE(focused_widget));
3046 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3047 gtk_clipboard_store (clipboard);
3048 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
3049 GtkTextBuffer *buffer;
3051 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
3052 gtk_text_buffer_cut_clipboard (buffer, clipboard, TRUE);
3053 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3054 gtk_clipboard_store (clipboard);
3055 } else if (MODEST_IS_HEADER_VIEW (focused_widget)) {
3056 TnyList *header_list = modest_header_view_get_selected_headers (
3057 MODEST_HEADER_VIEW (focused_widget));
3058 gboolean continue_download = FALSE;
3059 gint num_of_unc_msgs;
3061 num_of_unc_msgs = header_list_count_uncached_msgs(header_list);
3063 if (num_of_unc_msgs) {
3064 TnyAccount *account = get_account_from_header_list (header_list);
3065 continue_download = connect_to_get_msg (window, num_of_unc_msgs, account);
3066 g_object_unref (account);
3069 if (num_of_unc_msgs == 0 || continue_download) {
3070 /* modest_platform_information_banner (
3071 NULL, NULL, _CS("mcen_ib_getting_items"));*/
3072 modest_header_view_cut_selection (
3073 MODEST_HEADER_VIEW (focused_widget));
3076 g_object_unref (header_list);
3077 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
3078 modest_folder_view_cut_selection (MODEST_FOLDER_VIEW (focused_widget));
3083 modest_ui_actions_on_copy (GtkAction *action,
3084 ModestWindow *window)
3086 GtkClipboard *clipboard;
3087 GtkWidget *focused_widget;
3088 gboolean copied = TRUE;
3090 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
3091 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
3093 if (GTK_IS_LABEL (focused_widget)) {
3094 gtk_clipboard_set_text (clipboard, gtk_label_get_text (GTK_LABEL (focused_widget)), -1);
3095 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3096 gtk_clipboard_store (clipboard);
3097 } else if (GTK_IS_EDITABLE (focused_widget)) {
3098 gtk_editable_copy_clipboard (GTK_EDITABLE(focused_widget));
3099 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3100 gtk_clipboard_store (clipboard);
3101 } else if (GTK_IS_HTML (focused_widget)) {
3102 gtk_html_copy (GTK_HTML (focused_widget));
3103 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3104 gtk_clipboard_store (clipboard);
3105 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
3106 GtkTextBuffer *buffer;
3107 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
3108 gtk_text_buffer_copy_clipboard (buffer, clipboard);
3109 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3110 gtk_clipboard_store (clipboard);
3111 } else if (MODEST_IS_HEADER_VIEW (focused_widget)) {
3112 TnyList *header_list = modest_header_view_get_selected_headers (
3113 MODEST_HEADER_VIEW (focused_widget));
3114 gboolean continue_download = FALSE;
3115 gint num_of_unc_msgs;
3117 num_of_unc_msgs = header_list_count_uncached_msgs(header_list);
3119 if (num_of_unc_msgs) {
3120 TnyAccount *account = get_account_from_header_list (header_list);
3121 continue_download = connect_to_get_msg (window, num_of_unc_msgs, account);
3122 g_object_unref (account);
3125 if (num_of_unc_msgs == 0 || continue_download) {
3126 modest_platform_information_banner (
3127 NULL, NULL, _CS("mcen_ib_getting_items"));
3128 modest_header_view_copy_selection (
3129 MODEST_HEADER_VIEW (focused_widget));
3133 g_object_unref (header_list);
3135 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
3136 modest_folder_view_copy_selection (MODEST_FOLDER_VIEW (focused_widget));
3139 /* Show information banner if there was a copy to clipboard */
3141 modest_platform_information_banner (
3142 NULL, NULL, _CS("ecoc_ib_edwin_copied"));
3146 modest_ui_actions_on_undo (GtkAction *action,
3147 ModestWindow *window)
3149 ModestEmailClipboard *clipboard = NULL;
3151 if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
3152 modest_msg_edit_window_undo (MODEST_MSG_EDIT_WINDOW (window));
3153 } else if (MODEST_IS_MAIN_WINDOW (window)) {
3154 /* Clear clipboard source */
3155 clipboard = modest_runtime_get_email_clipboard ();
3156 modest_email_clipboard_clear (clipboard);
3159 g_return_if_reached ();
3164 modest_ui_actions_on_redo (GtkAction *action,
3165 ModestWindow *window)
3167 if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
3168 modest_msg_edit_window_redo (MODEST_MSG_EDIT_WINDOW (window));
3171 g_return_if_reached ();
3177 destroy_information_note (ModestMailOperation *mail_op, gpointer user_data)
3179 /* destroy information note */
3180 gtk_widget_destroy (GTK_WIDGET(user_data));
3185 paste_as_attachment_free (gpointer data)
3187 PasteAsAttachmentHelper *helper = (PasteAsAttachmentHelper *) data;
3189 gtk_widget_destroy (helper->banner);
3190 g_object_unref (helper->banner);
3195 paste_msg_as_attachment_cb (ModestMailOperation *mail_op,
3200 PasteAsAttachmentHelper *helper = (PasteAsAttachmentHelper *) userdata;
3201 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (helper->window));
3206 modest_msg_edit_window_add_part (MODEST_MSG_EDIT_WINDOW (helper->window), TNY_MIME_PART (msg));
3211 modest_ui_actions_on_paste (GtkAction *action,
3212 ModestWindow *window)
3214 GtkWidget *focused_widget = NULL;
3215 GtkWidget *inf_note = NULL;
3216 ModestMailOperation *mail_op = NULL;
3218 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
3219 if (GTK_IS_EDITABLE (focused_widget)) {
3220 gtk_editable_paste_clipboard (GTK_EDITABLE(focused_widget));
3221 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
3222 ModestEmailClipboard *e_clipboard = NULL;
3223 e_clipboard = modest_runtime_get_email_clipboard ();
3224 if (modest_email_clipboard_cleared (e_clipboard)) {
3225 GtkTextBuffer *buffer;
3226 GtkClipboard *clipboard;
3228 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
3229 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
3230 gtk_text_buffer_paste_clipboard (buffer, clipboard, NULL, TRUE);
3231 } else if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
3232 ModestMailOperation *mail_op;
3233 TnyFolder *src_folder;
3236 PasteAsAttachmentHelper *helper = g_new0 (PasteAsAttachmentHelper, 1);
3237 helper->window = MODEST_MSG_EDIT_WINDOW (window);
3238 helper->banner = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
3239 _CS("ckct_nw_pasting"));
3240 modest_email_clipboard_get_data (e_clipboard, &src_folder, &data, &delete);
3241 mail_op = modest_mail_operation_new (G_OBJECT (window));
3242 if (helper->banner != NULL) {
3243 g_object_ref (G_OBJECT (helper->banner));
3244 gtk_window_set_modal (GTK_WINDOW (helper->banner), FALSE);
3245 gtk_widget_show (GTK_WIDGET (helper->banner));
3249 modest_mail_operation_get_msgs_full (mail_op,
3251 (GetMsgAsyncUserCallback) paste_msg_as_attachment_cb,
3253 paste_as_attachment_free);
3256 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
3257 ModestEmailClipboard *clipboard = NULL;
3258 TnyFolder *src_folder = NULL;
3259 TnyFolderStore *folder_store = NULL;
3260 TnyList *data = NULL;
3261 gboolean delete = FALSE;
3263 /* Check clipboard source */
3264 clipboard = modest_runtime_get_email_clipboard ();
3265 if (modest_email_clipboard_cleared (clipboard))
3268 /* Get elements to paste */
3269 modest_email_clipboard_get_data (clipboard, &src_folder, &data, &delete);
3271 /* Create a new mail operation */
3272 mail_op = modest_mail_operation_new (G_OBJECT(window));
3274 /* Get destination folder */
3275 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (focused_widget));
3277 /* transfer messages */
3281 /* Ask for user confirmation */
3283 modest_ui_actions_msgs_move_to_confirmation (window,
3284 TNY_FOLDER (folder_store),
3288 if (response == GTK_RESPONSE_OK) {
3289 /* Launch notification */
3290 inf_note = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
3291 _CS("ckct_nw_pasting"));
3292 if (inf_note != NULL) {
3293 gtk_window_set_modal (GTK_WINDOW(inf_note), FALSE);
3294 gtk_widget_show (GTK_WIDGET(inf_note));
3297 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
3298 modest_mail_operation_xfer_msgs (mail_op,
3300 TNY_FOLDER (folder_store),
3302 destroy_information_note,
3305 g_object_unref (mail_op);
3308 } else if (src_folder != NULL) {
3309 /* Launch notification */
3310 inf_note = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
3311 _CS("ckct_nw_pasting"));
3312 if (inf_note != NULL) {
3313 gtk_window_set_modal (GTK_WINDOW(inf_note), FALSE);
3314 gtk_widget_show (GTK_WIDGET(inf_note));
3317 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
3318 modest_mail_operation_xfer_folder (mail_op,
3322 destroy_information_note,
3328 g_object_unref (data);
3329 if (src_folder != NULL)
3330 g_object_unref (src_folder);
3331 if (folder_store != NULL)
3332 g_object_unref (folder_store);
3338 modest_ui_actions_on_select_all (GtkAction *action,
3339 ModestWindow *window)
3341 GtkWidget *focused_widget;
3343 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
3344 if (MODEST_IS_ATTACHMENTS_VIEW (focused_widget)) {
3345 modest_attachments_view_select_all (MODEST_ATTACHMENTS_VIEW (focused_widget));
3346 } else if (GTK_IS_LABEL (focused_widget)) {
3347 gtk_label_select_region (GTK_LABEL (focused_widget), 0, -1);
3348 } else if (GTK_IS_EDITABLE (focused_widget)) {
3349 gtk_editable_select_region (GTK_EDITABLE(focused_widget), 0, -1);
3350 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
3351 GtkTextBuffer *buffer;
3352 GtkTextIter start, end;
3354 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
3355 gtk_text_buffer_get_start_iter (buffer, &start);
3356 gtk_text_buffer_get_end_iter (buffer, &end);
3357 gtk_text_buffer_select_range (buffer, &start, &end);
3358 } else if (GTK_IS_HTML (focused_widget)) {
3359 gtk_html_select_all (GTK_HTML (focused_widget));
3360 } else if (MODEST_IS_MAIN_WINDOW (window)) {
3361 GtkWidget *header_view = focused_widget;
3362 GtkTreeSelection *selection = NULL;
3364 if (!(MODEST_IS_HEADER_VIEW (focused_widget))) {
3365 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (window),
3366 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
3369 /* Disable window dimming management */
3370 modest_window_disable_dimming (MODEST_WINDOW(window));
3372 /* Select all messages */
3373 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(header_view));
3374 gtk_tree_selection_select_all (selection);
3376 /* Set focuse on header view */
3377 gtk_widget_grab_focus (header_view);
3380 /* Enable window dimming management */
3381 modest_window_enable_dimming (MODEST_WINDOW(window));
3382 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (window));
3388 modest_ui_actions_on_mark_as_read (GtkAction *action,
3389 ModestWindow *window)
3391 g_return_if_fail (MODEST_IS_WINDOW(window));
3393 /* Mark each header as read */
3394 do_headers_action (window, headers_action_mark_as_read, NULL);
3398 modest_ui_actions_on_mark_as_unread (GtkAction *action,
3399 ModestWindow *window)
3401 g_return_if_fail (MODEST_IS_WINDOW(window));
3403 /* Mark each header as read */
3404 do_headers_action (window, headers_action_mark_as_unread, NULL);
3408 modest_ui_actions_on_change_zoom (GtkRadioAction *action,
3409 GtkRadioAction *selected,
3410 ModestWindow *window)
3414 value = gtk_radio_action_get_current_value (selected);
3415 if (MODEST_IS_WINDOW (window)) {
3416 modest_window_set_zoom (MODEST_WINDOW (window), ((gdouble)value)/100);
3421 modest_ui_actions_msg_edit_on_change_priority (GtkRadioAction *action,
3422 GtkRadioAction *selected,
3423 ModestWindow *window)
3425 TnyHeaderFlags flags;
3426 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3428 flags = gtk_radio_action_get_current_value (selected);
3429 modest_msg_edit_window_set_priority_flags (MODEST_MSG_EDIT_WINDOW (window), flags);
3433 modest_ui_actions_msg_edit_on_change_file_format (GtkRadioAction *action,
3434 GtkRadioAction *selected,
3435 ModestWindow *window)
3439 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3441 file_format = gtk_radio_action_get_current_value (selected);
3442 modest_msg_edit_window_set_file_format (MODEST_MSG_EDIT_WINDOW (window), file_format);
3447 modest_ui_actions_on_zoom_plus (GtkAction *action,
3448 ModestWindow *window)
3450 g_return_if_fail (MODEST_IS_WINDOW (window));
3452 modest_window_zoom_plus (MODEST_WINDOW (window));
3456 modest_ui_actions_on_zoom_minus (GtkAction *action,
3457 ModestWindow *window)
3459 g_return_if_fail (MODEST_IS_WINDOW (window));
3461 modest_window_zoom_minus (MODEST_WINDOW (window));
3465 modest_ui_actions_on_toggle_fullscreen (GtkToggleAction *toggle,
3466 ModestWindow *window)
3468 ModestWindowMgr *mgr;
3469 gboolean fullscreen, active;
3470 g_return_if_fail (MODEST_IS_WINDOW (window));
3472 mgr = modest_runtime_get_window_mgr ();
3474 active = (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle)))?1:0;
3475 fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
3477 if (active != fullscreen) {
3478 modest_window_mgr_set_fullscreen_mode (mgr, active);
3479 gtk_window_present (GTK_WINDOW (window));
3484 modest_ui_actions_on_change_fullscreen (GtkAction *action,
3485 ModestWindow *window)
3487 ModestWindowMgr *mgr;
3488 gboolean fullscreen;
3490 g_return_if_fail (MODEST_IS_WINDOW (window));
3492 mgr = modest_runtime_get_window_mgr ();
3493 fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
3494 modest_window_mgr_set_fullscreen_mode (mgr, !fullscreen);
3496 gtk_window_present (GTK_WINDOW (window));
3500 * Used by modest_ui_actions_on_details to call do_headers_action
3503 headers_action_show_details (TnyHeader *header,
3504 ModestWindow *window,
3511 dialog = modest_details_dialog_new_with_header (GTK_WINDOW (window), header);
3514 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
3515 gtk_widget_show_all (dialog);
3516 gtk_dialog_run (GTK_DIALOG (dialog));
3518 gtk_widget_destroy (dialog);
3522 * Show the folder details in a ModestDetailsDialog widget
3525 show_folder_details (TnyFolder *folder,
3531 dialog = modest_details_dialog_new_with_folder (window, folder);
3534 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
3535 gtk_widget_show_all (dialog);
3536 gtk_dialog_run (GTK_DIALOG (dialog));
3538 gtk_widget_destroy (dialog);
3542 * Show the header details in a ModestDetailsDialog widget
3545 modest_ui_actions_on_details (GtkAction *action,
3548 TnyList * headers_list;
3552 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
3555 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW (win));
3558 g_object_unref (msg);
3560 headers_list = get_selected_headers (win);
3564 iter = tny_list_create_iterator (headers_list);
3566 header = TNY_HEADER (tny_iterator_get_current (iter));
3568 headers_action_show_details (header, win, NULL);
3569 g_object_unref (header);
3572 g_object_unref (iter);
3573 g_object_unref (headers_list);
3575 } else if (MODEST_IS_MAIN_WINDOW (win)) {
3576 GtkWidget *folder_view, *header_view;
3578 /* Check which widget has the focus */
3579 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
3580 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3581 if (gtk_widget_is_focus (folder_view)) {
3582 TnyFolderStore *folder_store
3583 = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
3584 if (!folder_store) {
3585 g_warning ("%s: No item was selected.\n", __FUNCTION__);
3588 /* Show only when it's a folder */
3589 /* This function should not be called for account items,
3590 * because we dim the menu item for them. */
3591 if (TNY_IS_FOLDER (folder_store)) {
3592 show_folder_details (TNY_FOLDER (folder_store), GTK_WINDOW (win));
3595 g_object_unref (folder_store);
3598 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
3599 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
3600 /* Show details of each header */
3601 do_headers_action (win, headers_action_show_details, header_view);
3607 modest_ui_actions_on_toggle_show_cc (GtkToggleAction *toggle,
3608 ModestMsgEditWindow *window)
3610 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3612 modest_msg_edit_window_show_cc (window, gtk_toggle_action_get_active (toggle));
3616 modest_ui_actions_on_toggle_show_bcc (GtkToggleAction *toggle,
3617 ModestMsgEditWindow *window)
3619 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3621 modest_msg_edit_window_show_bcc (window, gtk_toggle_action_get_active (toggle));
3625 modest_ui_actions_toggle_folders_view (GtkAction *action,
3626 ModestMainWindow *main_window)
3628 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
3630 if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)))
3631 modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SPLIT);
3633 modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SIMPLE);
3637 modest_ui_actions_on_toggle_toolbar (GtkToggleAction *toggle,
3638 ModestWindow *window)
3640 gboolean active, fullscreen = FALSE;
3641 ModestWindowMgr *mgr;
3643 active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle));
3645 /* Check if we want to toggle the toolbar vuew in fullscreen
3647 if (!strcmp (gtk_action_get_name (GTK_ACTION (toggle)),
3648 "ViewShowToolbarFullScreen")) {
3652 /* Toggle toolbar */
3653 mgr = modest_runtime_get_window_mgr ();
3654 modest_window_mgr_show_toolbars (mgr, G_TYPE_FROM_INSTANCE (window), active, fullscreen);
3658 modest_ui_actions_msg_edit_on_select_font (GtkAction *action,
3659 ModestMsgEditWindow *window)
3661 modest_msg_edit_window_select_font (window);
3665 modest_ui_actions_on_folder_display_name_changed (ModestFolderView *folder_view,
3666 const gchar *display_name,
3669 /* Do not change the application name if the widget has not
3670 the focus. This callback could be called even if the folder
3671 view has not the focus, because the handled signal could be
3672 emitted when the folder view is redrawn */
3673 if (gtk_widget_is_focus (GTK_WIDGET (folder_view))) {
3675 gtk_window_set_title (window, display_name);
3677 gtk_window_set_title (window, " ");
3682 modest_ui_actions_on_select_contacts (GtkAction *action, ModestMsgEditWindow *window)
3684 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3685 modest_msg_edit_window_select_contacts (window);
3689 modest_ui_actions_on_check_names (GtkAction *action, ModestMsgEditWindow *window)
3691 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3692 modest_msg_edit_window_check_names (window, FALSE);
3696 create_move_to_dialog_on_new_folder(GtkWidget *button, gpointer user_data)
3698 modest_ui_actions_create_folder (gtk_widget_get_toplevel (button),
3699 GTK_WIDGET (user_data));
3703 * This function is used to track changes in the selection of the
3704 * folder view that is inside the "move to" dialog to enable/disable
3705 * the OK button because we do not want the user to select a disallowed
3706 * destination for a folder.
3707 * The user also not desired to be able to use NEW button on items where
3708 * folder creation is not possibel.
3711 on_move_to_dialog_folder_selection_changed (ModestFolderView* self,
3712 TnyFolderStore *folder_store,
3716 GtkWidget *dialog = NULL;
3717 GtkWidget *ok_button = NULL, *new_button = NULL;
3718 GList *children = NULL;
3719 gboolean ok_sensitive = TRUE, new_sensitive = TRUE;
3720 gboolean moving_folder = FALSE;
3721 gboolean is_local_account = TRUE;
3722 GtkWidget *folder_view = NULL;
3723 ModestTnyFolderRules rules;
3728 /* Get the OK button */
3729 dialog = gtk_widget_get_ancestor (GTK_WIDGET (self), GTK_TYPE_DIALOG);
3733 children = gtk_container_get_children (GTK_CONTAINER (GTK_DIALOG (dialog)->action_area));
3734 ok_button = GTK_WIDGET (children->next->next->data);
3735 new_button = GTK_WIDGET (children->next->data);
3736 g_list_free (children);
3738 /* check if folder_store is an remote account */
3739 if (TNY_IS_ACCOUNT (folder_store)) {
3740 TnyAccount *local_account = NULL;
3741 TnyAccount *mmc_account = NULL;
3742 ModestTnyAccountStore *account_store = NULL;
3744 account_store = modest_runtime_get_account_store ();
3745 local_account = modest_tny_account_store_get_local_folders_account (account_store);
3746 mmc_account = modest_tny_account_store_get_mmc_folders_account (account_store);
3748 if ((gpointer) local_account != (gpointer) folder_store &&
3749 (gpointer) mmc_account != (gpointer) folder_store) {
3750 is_local_account = FALSE;
3751 /* New button should be dimmed on remote
3753 new_sensitive = FALSE;
3755 g_object_unref (local_account);
3758 /* Check the target folder rules */
3759 if (TNY_IS_FOLDER (folder_store)) {
3760 rules = modest_tny_folder_get_rules (TNY_FOLDER (folder_store));
3761 if (rules & MODEST_FOLDER_RULES_FOLDER_NON_WRITEABLE) {
3762 ok_sensitive = FALSE;
3763 new_sensitive = FALSE;
3768 /* Check if we're moving a folder */
3769 if (MODEST_IS_MAIN_WINDOW (user_data)) {
3770 /* Get the widgets */
3771 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (user_data),
3772 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3773 if (gtk_widget_is_focus (folder_view))
3774 moving_folder = TRUE;
3777 if (moving_folder) {
3778 TnyFolderStore *moved_folder = NULL, *parent = NULL;
3780 /* Get the folder to move */
3781 moved_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
3783 /* Check that we're not moving to the same folder */
3784 if (TNY_IS_FOLDER (moved_folder)) {
3785 parent = tny_folder_get_folder_store (TNY_FOLDER (moved_folder));
3786 if (parent == folder_store)
3787 ok_sensitive = FALSE;
3788 g_object_unref (parent);
3791 if (ok_sensitive && TNY_IS_ACCOUNT (folder_store)) {
3792 /* Do not allow to move to an account unless it's the
3793 local folders account */
3794 if (!is_local_account)
3795 ok_sensitive = FALSE;
3798 if (ok_sensitive && (moved_folder == folder_store)) {
3799 /* Do not allow to move to itself */
3800 ok_sensitive = FALSE;
3802 g_object_unref (moved_folder);
3804 TnyHeader *header = NULL;
3805 TnyFolder *src_folder = NULL;
3807 /* Moving a message */
3808 if (MODEST_IS_MSG_VIEW_WINDOW (user_data)) {
3809 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (user_data));
3810 src_folder = tny_header_get_folder (header);
3811 g_object_unref (header);
3814 TNY_FOLDER (modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view)));
3817 /* Do not allow to move the msg to the same folder */
3818 /* Do not allow to move the msg to an account */
3819 if ((gpointer) src_folder == (gpointer) folder_store ||
3820 TNY_IS_ACCOUNT (folder_store))
3821 ok_sensitive = FALSE;
3822 g_object_unref (src_folder);
3826 /* Set sensitivity of the OK button */
3827 gtk_widget_set_sensitive (ok_button, ok_sensitive);
3828 /* Set sensitivity of the NEW button */
3829 gtk_widget_set_sensitive (new_button, new_sensitive);
3833 create_move_to_dialog (GtkWindow *win,
3834 GtkWidget *folder_view,
3835 GtkWidget **tree_view)
3837 GtkWidget *dialog, *scroll;
3838 GtkWidget *new_button;
3840 dialog = gtk_dialog_new_with_buttons (_("mcen_ti_moveto_folders_title"),
3842 GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR | GTK_DIALOG_DESTROY_WITH_PARENT,
3845 gtk_dialog_add_button (GTK_DIALOG (dialog), _("mcen_bd_dialog_ok"), GTK_RESPONSE_ACCEPT);
3846 /* We do this manually so GTK+ does not associate a response ID for
3848 new_button = gtk_button_new_from_stock (_("mcen_bd_new"));
3849 gtk_box_pack_end (GTK_BOX (GTK_DIALOG (dialog)->action_area), new_button, FALSE, FALSE, 0);
3850 gtk_dialog_add_button (GTK_DIALOG (dialog), _("mcen_bd_dialog_cancel"), GTK_RESPONSE_REJECT);
3852 /* Create scrolled window */
3853 scroll = gtk_scrolled_window_new (NULL, NULL);
3854 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll),
3855 GTK_POLICY_AUTOMATIC,
3856 GTK_POLICY_AUTOMATIC);
3858 /* Create folder view */
3859 *tree_view = modest_platform_create_folder_view (NULL);
3861 /* Track changes in the selection to
3862 * disable the OK button whenever "Move to" is not possible
3863 * disbale NEW button whenever New is not possible */
3864 g_signal_connect (*tree_view,
3865 "folder_selection_changed",
3866 G_CALLBACK (on_move_to_dialog_folder_selection_changed),
3869 /* Listen to clicks on New button */
3870 g_signal_connect (G_OBJECT (new_button),
3872 G_CALLBACK(create_move_to_dialog_on_new_folder),
3875 /* It could happen that we're trying to move a message from a
3876 window (msg window for example) after the main window was
3877 closed, so we can not just get the model of the folder
3879 if (MODEST_IS_FOLDER_VIEW (folder_view)) {
3880 const gchar *visible_id = NULL;
3882 modest_folder_view_set_style (MODEST_FOLDER_VIEW (*tree_view),
3883 MODEST_FOLDER_VIEW_STYLE_SHOW_ALL);
3884 modest_folder_view_copy_model (MODEST_FOLDER_VIEW(folder_view),
3885 MODEST_FOLDER_VIEW(*tree_view));
3888 modest_folder_view_get_account_id_of_visible_server_account (MODEST_FOLDER_VIEW(folder_view));
3890 /* Show the same account than the one that is shown in the main window */
3891 modest_folder_view_set_account_id_of_visible_server_account (MODEST_FOLDER_VIEW(*tree_view),
3894 const gchar *active_account_name = NULL;
3895 ModestAccountMgr *mgr = NULL;
3896 ModestAccountData *acc_data = NULL;
3898 modest_folder_view_set_style (MODEST_FOLDER_VIEW (*tree_view),
3899 MODEST_FOLDER_VIEW_STYLE_SHOW_ALL);
3900 modest_folder_view_update_model (MODEST_FOLDER_VIEW (*tree_view),
3901 TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()));
3903 active_account_name = modest_window_get_active_account (MODEST_WINDOW (win));
3904 mgr = modest_runtime_get_account_mgr ();
3905 acc_data = modest_account_mgr_get_account_data (mgr, active_account_name);
3907 /* Set the new visible & active account */
3908 if (acc_data && acc_data->store_account) {
3909 modest_folder_view_set_account_id_of_visible_server_account (MODEST_FOLDER_VIEW (*tree_view),
3910 acc_data->store_account->account_name);
3911 modest_account_mgr_free_account_data (mgr, acc_data);
3915 /* Hide special folders */
3916 modest_folder_view_show_non_move_folders (MODEST_FOLDER_VIEW (*tree_view), FALSE);
3918 gtk_container_add (GTK_CONTAINER (scroll), *tree_view);
3920 /* Add scroll to dialog */
3921 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
3922 scroll, TRUE, TRUE, 0);
3924 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
3925 gtk_window_set_default_size (GTK_WINDOW (dialog), 300, 300);
3931 * Returns TRUE if at least one of the headers of the list belongs to
3932 * a message that has been fully retrieved.
3934 #if 0 /* no longer in use. delete in 2007.10 */
3936 has_retrieved_msgs (TnyList *list)
3939 gboolean found = FALSE;
3941 iter = tny_list_create_iterator (list);
3942 while (!tny_iterator_is_done (iter) && !found) {
3944 TnyHeaderFlags flags = 0;
3946 header = TNY_HEADER (tny_iterator_get_current (iter));
3948 flags = tny_header_get_flags (header);
3949 if (flags & TNY_HEADER_FLAG_CACHED)
3950 /* if (!(flags & TNY_HEADER_FLAG_PARTIAL)) */
3953 g_object_unref (header);
3957 tny_iterator_next (iter);
3959 g_object_unref (iter);
3967 * Shows a confirmation dialog to the user when we're moving messages
3968 * from a remote server to the local storage. Returns the dialog
3969 * response. If it's other kind of movement then it always returns
3972 * This one is used by the next functions:
3973 * modest_ui_actions_on_paste - commented out
3974 * drag_and_drop_from_header_view (for d&d in modest_folder_view.c)
3977 modest_ui_actions_msgs_move_to_confirmation (ModestWindow *win,
3978 TnyFolder *dest_folder,
3982 gint response = GTK_RESPONSE_OK;
3983 TnyAccount *account = NULL;
3984 TnyFolder *src_folder = NULL;
3985 TnyIterator *iter = NULL;
3986 TnyHeader *header = NULL;
3988 /* return with OK if the destination is a remote folder */
3989 if (modest_tny_folder_is_remote_folder (dest_folder))
3990 return GTK_RESPONSE_OK;
3992 /* Get source folder */
3993 iter = tny_list_create_iterator (headers);
3994 header = TNY_HEADER (tny_iterator_get_current (iter));
3996 src_folder = tny_header_get_folder (header);
3997 g_object_unref (header);
3999 g_object_unref (iter);
4001 /* if no src_folder, message may be an attahcment */
4002 if (src_folder == NULL)
4003 return GTK_RESPONSE_CANCEL;
4005 /* If the source is a local or MMC folder */
4006 if (!modest_tny_folder_is_remote_folder (src_folder)) {
4007 g_object_unref (src_folder);
4008 return GTK_RESPONSE_OK;
4011 /* Get the account */
4012 account = tny_folder_get_account (src_folder);
4014 /* now if offline we ask the user */
4015 if(connect_to_get_msg (win, tny_list_get_length (headers), account))
4016 response = GTK_RESPONSE_OK;
4018 response = GTK_RESPONSE_CANCEL;
4021 g_object_unref (src_folder);
4022 g_object_unref (account);
4030 move_to_cb (ModestMailOperation *mail_op, gpointer user_data)
4032 MoveToHelper *helper = (MoveToHelper *) user_data;
4034 /* Note that the operation could have failed, in that case do
4036 if (modest_mail_operation_get_status (mail_op) ==
4037 MODEST_MAIL_OPERATION_STATUS_SUCCESS) {
4039 GObject *object = modest_mail_operation_get_source (mail_op);
4040 if (MODEST_IS_MSG_VIEW_WINDOW (object)) {
4041 ModestMsgViewWindow *self = MODEST_MSG_VIEW_WINDOW (object);
4043 if (!modest_msg_view_window_select_next_message (self))
4044 if (!modest_msg_view_window_select_previous_message (self))
4045 /* No more messages to view, so close this window */
4046 modest_ui_actions_on_close_window (NULL, MODEST_WINDOW(self));
4047 } else if (MODEST_IS_MAIN_WINDOW (object) && helper->reference != NULL) {
4048 GtkWidget *header_view;
4050 GtkTreeSelection *sel;
4052 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(object),
4053 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
4054 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
4055 path = gtk_tree_row_reference_get_path (helper->reference);
4056 gtk_tree_selection_select_path (sel, path);
4057 gtk_tree_path_free (path);
4059 g_object_unref (object);
4062 /* Close the "Pasting" information banner */
4063 gtk_widget_destroy (GTK_WIDGET(helper->banner));
4064 if (helper->reference != NULL)
4065 gtk_tree_row_reference_free (helper->reference);
4070 modest_ui_actions_move_folder_error_handler (ModestMailOperation *mail_op,
4073 ModestWindow *main_window = NULL;
4074 GObject *win = NULL;
4075 const GError *error = NULL;
4076 const gchar *message = NULL;
4078 /* Get error message */
4079 error = modest_mail_operation_get_error (mail_op);
4080 if (error != NULL && error->message != NULL) {
4081 message = error->message;
4083 message = _("mail_in_ui_folder_move_target_error");
4086 /* Disable next automatic folder selection */
4087 main_window = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (),
4088 FALSE); /* don't create */
4090 GtkWidget *folder_view = NULL;
4092 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (main_window),
4093 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
4094 modest_folder_view_disable_next_folder_selection (MODEST_FOLDER_VIEW(folder_view));
4096 if (user_data && TNY_IS_FOLDER (user_data)) {
4097 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view),
4098 TNY_FOLDER (user_data), FALSE);
4102 /* Show notification dialog */
4103 win = modest_mail_operation_get_source (mail_op);
4104 if (G_IS_OBJECT (win)) {
4105 modest_platform_run_information_dialog (GTK_WINDOW (win), message);
4106 g_object_unref (win);
4111 modest_ui_actions_send_receive_error_handler (ModestMailOperation *mail_op,
4114 GObject *win = modest_mail_operation_get_source (mail_op);
4115 const GError *error = modest_mail_operation_get_error (mail_op);
4117 g_return_if_fail (error != NULL);
4118 if (error->message != NULL)
4119 g_printerr ("modest: %s\n", error->message);
4121 g_printerr ("modest: unkonw error on send&receive operation");
4123 /* Show error message */
4124 /* if (modest_mail_operation_get_id (mail_op) == MODEST_MAIL_OPERATION_TYPE_RECEIVE) */
4125 /* modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL, */
4126 /* _CS("sfil_ib_unable_to_receive")); */
4128 /* modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL, */
4129 /* _CS("sfil_ib_unable_to_send")); */
4130 g_object_unref (win);
4134 open_msg_for_purge_cb (ModestMailOperation *mail_op,
4141 gint pending_purges = 0;
4142 gboolean some_purged = FALSE;
4143 ModestWindow *win = MODEST_WINDOW (user_data);
4144 ModestWindowMgr *mgr = modest_runtime_get_window_mgr ();
4146 /* If there was any error */
4147 if (!modest_ui_actions_msg_retrieval_check (mail_op, header, msg)) {
4148 modest_window_mgr_unregister_header (mgr, header);
4152 /* Once the message has been retrieved for purging, we check if
4153 * it's all ok for purging */
4155 parts = tny_simple_list_new ();
4156 tny_mime_part_get_parts (TNY_MIME_PART (msg), parts);
4157 iter = tny_list_create_iterator (parts);
4159 while (!tny_iterator_is_done (iter)) {
4161 part = TNY_MIME_PART (tny_iterator_get_current (iter));
4162 if (part && (tny_mime_part_is_attachment (part) || TNY_IS_MSG (part))) {
4163 if (tny_mime_part_is_purged (part))
4170 g_object_unref (part);
4172 tny_iterator_next (iter);
4174 g_object_unref (iter);
4177 if (pending_purges>0) {
4179 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),_("mcen_nc_purge_file_text_inbox"));
4181 if (response == GTK_RESPONSE_OK) {
4182 modest_platform_information_banner (NULL, NULL, _("mcen_ib_removing_attachment"));
4183 iter = tny_list_create_iterator (parts);
4184 while (!tny_iterator_is_done (iter)) {
4187 part = TNY_MIME_PART (tny_iterator_get_current (iter));
4188 if (part && (tny_mime_part_is_attachment (part) || TNY_IS_MSG (part)))
4189 tny_mime_part_set_purged (part);
4192 g_object_unref (part);
4194 tny_iterator_next (iter);
4197 tny_msg_rewrite_cache (msg);
4200 modest_platform_information_banner (NULL, NULL, _("mail_ib_attachment_already_purged"));
4202 g_object_unref (iter);
4204 modest_window_mgr_unregister_header (mgr, header);
4206 g_object_unref (parts);
4210 modest_ui_actions_on_main_window_remove_attachments (GtkAction *action,
4211 ModestMainWindow *win)
4213 GtkWidget *header_view;
4214 TnyList *header_list;
4217 TnyHeaderFlags flags;
4218 ModestWindow *msg_view_window = NULL;
4221 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win));
4223 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
4224 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
4226 header_list = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW (header_view));
4228 g_warning ("%s: no header selected", __FUNCTION__);
4232 if (tny_list_get_length (header_list) == 1) {
4233 iter = tny_list_create_iterator (header_list);
4234 header = TNY_HEADER (tny_iterator_get_current (iter));
4235 g_object_unref (iter);
4239 if (!header || !TNY_IS_HEADER(header)) {
4240 g_warning ("%s: header is not valid", __FUNCTION__);
4244 found = modest_window_mgr_find_registered_header (modest_runtime_get_window_mgr (),
4245 header, &msg_view_window);
4246 flags = tny_header_get_flags (header);
4247 if (!(flags & TNY_HEADER_FLAG_CACHED))
4250 if (msg_view_window != NULL)
4251 modest_msg_view_window_remove_attachments (MODEST_MSG_VIEW_WINDOW (msg_view_window), TRUE);
4253 /* do nothing; uid was registered before, so window is probably on it's way */
4254 g_warning ("debug: header %p has already been registered", header);
4257 ModestMailOperation *mail_op = NULL;
4258 modest_window_mgr_register_header (modest_runtime_get_window_mgr (), header, NULL);
4259 mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT (win),
4260 modest_ui_actions_get_msgs_full_error_handler,
4262 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
4263 modest_mail_operation_get_msg (mail_op, header, open_msg_for_purge_cb, win);
4265 g_object_unref (mail_op);
4268 g_object_unref (header);
4270 g_object_unref (header_list);
4274 * Utility function that transfer messages from both the main window
4275 * and the msg view window when using the "Move to" dialog
4278 modest_ui_actions_xfer_messages_from_move_to (TnyFolderStore *dst_folder,
4281 TnyList *headers = NULL;
4282 TnyAccount *dst_account = NULL;
4283 const gchar *proto_str = NULL;
4284 gboolean dst_is_pop = FALSE;
4286 if (!TNY_IS_FOLDER (dst_folder)) {
4287 modest_platform_information_banner (GTK_WIDGET (win),
4289 _CS("ckdg_ib_unable_to_move_to_current_location"));
4293 dst_account = tny_folder_get_account (TNY_FOLDER (dst_folder));
4294 proto_str = tny_account_get_proto (dst_account);
4296 /* tinymail will return NULL for local folders it seems */
4297 dst_is_pop = proto_str &&
4298 (modest_protocol_info_get_transport_store_protocol (proto_str) ==
4299 MODEST_PROTOCOL_STORE_POP);
4301 g_object_unref (dst_account);
4303 /* Get selected headers */
4304 headers = get_selected_headers (MODEST_WINDOW (win));
4306 g_warning ("%s: no headers selected", __FUNCTION__);
4312 modest_platform_information_banner (GTK_WIDGET (win),
4314 ngettext("mail_in_ui_folder_move_target_error",
4315 "mail_in_ui_folder_move_targets_error",
4316 tny_list_get_length (headers)));
4317 g_object_unref (headers);
4321 MoveToHelper *helper = g_new0 (MoveToHelper, 1);
4322 helper->banner = modest_platform_animation_banner (GTK_WIDGET (win), NULL,
4323 _CS("ckct_nw_pasting"));
4324 if (helper->banner != NULL) {
4325 gtk_window_set_modal (GTK_WINDOW(helper->banner), FALSE);
4326 gtk_widget_show (GTK_WIDGET(helper->banner));
4329 if (MODEST_IS_MAIN_WINDOW (win)) {
4330 GtkWidget *header_view =
4331 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
4332 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
4333 helper->reference = get_next_after_selected_headers (MODEST_HEADER_VIEW (header_view));
4336 ModestMailOperation *mail_op =
4337 modest_mail_operation_new_with_error_handling (G_OBJECT(win),
4338 modest_ui_actions_move_folder_error_handler,
4340 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
4343 modest_mail_operation_xfer_msgs (mail_op,
4345 TNY_FOLDER (dst_folder),
4350 g_object_unref (G_OBJECT (mail_op));
4351 g_object_unref (headers);
4355 * UI handler for the "Move to" action when invoked from the
4359 modest_ui_actions_on_main_window_move_to (GtkAction *action,
4360 GtkWidget *folder_view,
4361 TnyFolderStore *dst_folder,
4362 ModestMainWindow *win)
4364 ModestHeaderView *header_view = NULL;
4365 ModestMailOperation *mail_op = NULL;
4366 TnyFolderStore *src_folder;
4367 gboolean online = (tny_device_is_online (modest_runtime_get_device()));
4369 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win));
4371 /* Get the source folder */
4372 src_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
4374 /* Get header view */
4375 header_view = MODEST_HEADER_VIEW(modest_main_window_get_child_widget (win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW));
4377 /* Get folder or messages to transfer */
4378 if (gtk_widget_is_focus (folder_view)) {
4379 GtkTreeSelection *sel;
4380 gboolean do_xfer = TRUE;
4382 /* Allow only to transfer folders to the local root folder */
4383 if (TNY_IS_ACCOUNT (dst_folder) &&
4384 !MODEST_IS_TNY_LOCAL_FOLDERS_ACCOUNT (dst_folder)) {
4386 } else if (!TNY_IS_FOLDER (src_folder)) {
4387 g_warning ("%s: src_folder is not a TnyFolder.\n", __FUNCTION__);
4389 } else if (!online && modest_platform_is_network_folderstore(src_folder)) {
4390 guint num_headers = tny_folder_get_all_count(TNY_FOLDER (src_folder));
4391 TnyAccount *account = tny_folder_get_account (TNY_FOLDER (src_folder));
4392 if (!connect_to_get_msg(MODEST_WINDOW (win), num_headers, account))
4394 g_object_unref (account);
4398 MoveToHelper *helper = g_new0 (MoveToHelper, 1);
4399 helper->banner = modest_platform_animation_banner (GTK_WIDGET (win), NULL,
4400 _CS("ckct_nw_pasting"));
4401 if (helper->banner != NULL) {
4402 gtk_window_set_modal (GTK_WINDOW(helper->banner), FALSE);
4403 gtk_widget_show (GTK_WIDGET(helper->banner));
4405 /* Clean folder on header view before moving it */
4406 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_view));
4407 gtk_tree_selection_unselect_all (sel);
4409 /* Let gtk events run. We need that the folder
4410 view frees its reference to the source
4411 folder *before* issuing the mail operation
4412 so we need the signal handler of selection
4413 changed to happen before the mail
4415 while (gtk_events_pending ())
4416 gtk_main_iteration ();
4419 modest_mail_operation_new_with_error_handling (G_OBJECT(win),
4420 modest_ui_actions_move_folder_error_handler,
4422 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
4425 /* Select *after* the changes */
4426 /* TODO: this function hangs UI after transfer */
4427 /* modest_folder_view_select_folder (MODEST_FOLDER_VIEW(folder_view), */
4428 /* TNY_FOLDER (src_folder), TRUE); */
4430 modest_mail_operation_xfer_folder (mail_op,
4431 TNY_FOLDER (src_folder),
4436 /* Unref mail operation */
4437 g_object_unref (G_OBJECT (mail_op));
4439 } else if (gtk_widget_is_focus (GTK_WIDGET(header_view))) {
4440 gboolean do_xfer = TRUE;
4441 /* Ask for confirmation if the source folder is remote and we're not connected */
4442 if (!online && modest_platform_is_network_folderstore(src_folder)) {
4443 TnyList *headers = modest_header_view_get_selected_headers(header_view);
4444 if (!msgs_already_deleted_from_server(headers, src_folder)) {
4445 guint num_headers = tny_list_get_length(headers);
4446 TnyAccount *account = get_account_from_header_list (headers);
4447 if (!connect_to_get_msg(MODEST_WINDOW (win), num_headers, account))
4449 g_object_unref (account);
4451 g_object_unref(headers);
4453 if (do_xfer) /* Transfer messages */
4454 modest_ui_actions_xfer_messages_from_move_to (dst_folder, MODEST_WINDOW (win));
4458 g_object_unref (src_folder);
4463 * UI handler for the "Move to" action when invoked from the
4464 * ModestMsgViewWindow
4467 modest_ui_actions_on_msg_view_window_move_to (GtkAction *action,
4468 TnyFolderStore *dst_folder,
4469 ModestMsgViewWindow *win)
4471 TnyHeader *header = NULL;
4472 TnyFolder *src_folder = NULL;
4473 TnyAccount *account = NULL;
4474 gboolean do_xfer = FALSE;
4476 /* Create header list */
4477 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
4478 src_folder = TNY_FOLDER (tny_header_get_folder(header));
4479 g_object_unref (header);
4481 account = tny_folder_get_account (src_folder);
4482 if (!modest_platform_is_network_folderstore(TNY_FOLDER_STORE(src_folder))) {
4483 /* Transfer if the source folder is local */
4485 } else if (remote_folder_is_pop(TNY_FOLDER_STORE(src_folder))) {
4486 /* Transfer if the source folder is POP (as it means
4487 * that the message is already downloaded) */
4489 } else if (connect_to_get_msg(MODEST_WINDOW(win), 1, account)) {
4490 /* Transfer after asking confirmation */
4495 modest_ui_actions_xfer_messages_from_move_to (dst_folder, MODEST_WINDOW (win));
4497 g_object_unref (account);
4498 g_object_unref (src_folder);
4502 modest_ui_actions_on_move_to (GtkAction *action,
4505 GtkWidget *dialog = NULL, *folder_view = NULL, *tree_view = NULL;
4507 TnyFolderStore *dst_folder = NULL;
4508 ModestMainWindow *main_window;
4510 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win) ||
4511 MODEST_IS_MSG_VIEW_WINDOW (win));
4513 /* Get the main window if exists */
4514 if (MODEST_IS_MAIN_WINDOW (win))
4515 main_window = MODEST_MAIN_WINDOW (win);
4518 MODEST_MAIN_WINDOW (modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (),
4519 FALSE)); /* don't create */
4521 /* Get the folder view widget if exists */
4523 folder_view = modest_main_window_get_child_widget (main_window,
4524 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
4528 /* Create and run the dialog */
4529 dialog = create_move_to_dialog (GTK_WINDOW (win), folder_view, &tree_view);
4530 modest_folder_view_select_first_inbox_or_local (MODEST_FOLDER_VIEW (tree_view));
4531 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
4532 result = gtk_dialog_run (GTK_DIALOG(dialog));
4533 g_object_ref (tree_view);
4534 gtk_widget_destroy (dialog);
4536 if (result != GTK_RESPONSE_ACCEPT)
4539 dst_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (tree_view));
4540 /* Do window specific stuff */
4541 if (MODEST_IS_MAIN_WINDOW (win)) {
4542 modest_ui_actions_on_main_window_move_to (action,
4545 MODEST_MAIN_WINDOW (win));
4547 modest_ui_actions_on_msg_view_window_move_to (action,
4549 MODEST_MSG_VIEW_WINDOW (win));
4553 g_object_unref (dst_folder);
4557 * Calls #HeadersFunc for each header already selected in the main
4558 * window or the message currently being shown in the msg view window
4561 do_headers_action (ModestWindow *win,
4565 TnyList *headers_list = NULL;
4566 TnyIterator *iter = NULL;
4567 TnyHeader *header = NULL;
4568 TnyFolder *folder = NULL;
4571 headers_list = get_selected_headers (win);
4575 /* Get the folder */
4576 iter = tny_list_create_iterator (headers_list);
4577 header = TNY_HEADER (tny_iterator_get_current (iter));
4579 folder = tny_header_get_folder (header);
4580 g_object_unref (header);
4583 /* Call the function for each header */
4584 while (!tny_iterator_is_done (iter)) {
4585 header = TNY_HEADER (tny_iterator_get_current (iter));
4586 func (header, win, user_data);
4587 g_object_unref (header);
4588 tny_iterator_next (iter);
4591 /* Trick: do a poke status in order to speed up the signaling
4593 tny_folder_poke_status (folder);
4596 g_object_unref (folder);
4597 g_object_unref (iter);
4598 g_object_unref (headers_list);
4602 modest_ui_actions_view_attachment (GtkAction *action,
4603 ModestWindow *window)
4605 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
4606 modest_msg_view_window_view_attachment (MODEST_MSG_VIEW_WINDOW (window), NULL);
4608 /* not supported window for this action */
4609 g_return_if_reached ();
4614 modest_ui_actions_save_attachments (GtkAction *action,
4615 ModestWindow *window)
4617 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
4618 modest_msg_view_window_save_attachments (MODEST_MSG_VIEW_WINDOW (window), NULL);
4620 /* not supported window for this action */
4621 g_return_if_reached ();
4626 modest_ui_actions_remove_attachments (GtkAction *action,
4627 ModestWindow *window)
4629 if (MODEST_IS_MAIN_WINDOW (window)) {
4630 modest_ui_actions_on_main_window_remove_attachments (action, MODEST_MAIN_WINDOW (window));
4631 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
4632 modest_msg_view_window_remove_attachments (MODEST_MSG_VIEW_WINDOW (window), FALSE);
4634 /* not supported window for this action */
4635 g_return_if_reached ();
4640 modest_ui_actions_on_settings (GtkAction *action,
4645 dialog = modest_platform_get_global_settings_dialog ();
4646 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (win));
4647 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
4648 gtk_widget_show_all (dialog);
4650 gtk_dialog_run (GTK_DIALOG (dialog));
4652 gtk_widget_destroy (dialog);
4656 modest_ui_actions_on_help (GtkAction *action,
4659 const gchar *help_id;
4661 g_return_if_fail (action);
4662 g_return_if_fail (win && GTK_IS_WINDOW(win));
4664 help_id = modest_window_mgr_get_help_id (modest_runtime_get_window_mgr(), win);
4667 modest_platform_show_help (GTK_WINDOW (win), help_id);
4669 g_warning ("%s: no help for window %p", __FUNCTION__, win);
4673 modest_ui_actions_on_retrieve_msg_contents (GtkAction *action,
4674 ModestWindow *window)
4676 ModestMailOperation *mail_op;
4680 headers = get_selected_headers (window);
4684 /* Create mail operation */
4685 mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT (window),
4686 modest_ui_actions_get_msgs_full_error_handler,
4688 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
4689 modest_mail_operation_get_msgs_full (mail_op, headers, NULL, NULL, NULL);
4692 g_object_unref (headers);
4693 g_object_unref (mail_op);
4697 modest_ui_actions_on_email_menu_activated (GtkAction *action,
4698 ModestWindow *window)
4700 g_return_if_fail (MODEST_IS_WINDOW (window));
4703 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4707 modest_ui_actions_on_edit_menu_activated (GtkAction *action,
4708 ModestWindow *window)
4710 g_return_if_fail (MODEST_IS_WINDOW (window));
4713 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4717 modest_ui_actions_on_view_menu_activated (GtkAction *action,
4718 ModestWindow *window)
4720 g_return_if_fail (MODEST_IS_WINDOW (window));
4723 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4727 modest_ui_actions_on_format_menu_activated (GtkAction *action,
4728 ModestWindow *window)
4730 g_return_if_fail (MODEST_IS_WINDOW (window));
4733 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4737 modest_ui_actions_on_tools_menu_activated (GtkAction *action,
4738 ModestWindow *window)
4740 g_return_if_fail (MODEST_IS_WINDOW (window));
4743 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4747 modest_ui_actions_on_attachment_menu_activated (GtkAction *action,
4748 ModestWindow *window)
4750 g_return_if_fail (MODEST_IS_WINDOW (window));
4753 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4757 modest_ui_actions_on_toolbar_csm_menu_activated (GtkAction *action,
4758 ModestWindow *window)
4760 g_return_if_fail (MODEST_IS_WINDOW (window));
4763 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4767 modest_ui_actions_on_folder_view_csm_menu_activated (GtkAction *action,
4768 ModestWindow *window)
4770 g_return_if_fail (MODEST_IS_WINDOW (window));
4773 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4777 modest_ui_actions_on_header_view_csm_menu_activated (GtkAction *action,
4778 ModestWindow *window)
4780 g_return_if_fail (MODEST_IS_WINDOW (window));
4783 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4787 modest_ui_actions_check_toolbar_dimming_rules (ModestWindow *window)
4789 g_return_if_fail (MODEST_IS_WINDOW (window));
4792 modest_window_check_dimming_rules_group (window, "ModestToolbarDimmingRules");
4796 modest_ui_actions_on_search_messages (GtkAction *action, ModestWindow *window)
4798 g_return_if_fail (MODEST_IS_WINDOW (window));
4800 modest_platform_show_search_messages (GTK_WINDOW (window));
4804 modest_ui_actions_on_open_addressbook (GtkAction *action, ModestWindow *win)
4806 g_return_if_fail (MODEST_IS_WINDOW (win));
4807 modest_platform_show_addressbook (GTK_WINDOW (win));
4812 modest_ui_actions_on_toggle_find_in_page (GtkToggleAction *action,
4813 ModestWindow *window)
4815 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4817 modest_msg_edit_window_toggle_find_toolbar (MODEST_MSG_EDIT_WINDOW (window), gtk_toggle_action_get_active (action));
4821 on_send_receive_finished (ModestMailOperation *mail_op,
4824 /* Set send/receive operation finished */
4825 modest_main_window_notify_send_receive_completed (MODEST_MAIN_WINDOW (user_data));
4830 modest_ui_actions_on_send_queue_error_happened (TnySendQueue *self,
4836 const gchar* server_name = NULL;
4837 TnyTransportAccount *server_account;
4838 gchar *message = NULL;
4840 /* Don't show anything if the user cancelled something */
4841 if (err->code == TNY_TRANSPORT_ACCOUNT_ERROR_SEND_USER_CANCEL)
4844 /* Get the server name: */
4846 TNY_TRANSPORT_ACCOUNT (tny_camel_send_queue_get_transport_account (TNY_CAMEL_SEND_QUEUE (self)));
4847 if (server_account) {
4848 server_name = tny_account_get_hostname (TNY_ACCOUNT (server_account));
4850 g_object_unref (server_account);
4851 server_account = NULL;
4854 g_return_if_fail (server_name);
4856 /* Show the appropriate message text for the GError: */
4857 switch (err->code) {
4858 case TNY_TRANSPORT_ACCOUNT_ERROR_SEND_HOST_LOOKUP_FAILED:
4859 message = g_strdup_printf (_("emev_ib_ui_smtp_server_invalid"), server_name);
4861 case TNY_TRANSPORT_ACCOUNT_ERROR_SEND_SERVICE_UNAVAILABLE:
4862 message = g_strdup_printf (_("emev_ib_ui_smtp_server_invalid"), server_name);
4864 case TNY_TRANSPORT_ACCOUNT_ERROR_SEND_AUTHENTICATION_NOT_SUPPORTED:
4865 message = g_strdup_printf (_("emev_ni_ui_smtp_authentication_fail_error"), server_name);
4867 case TNY_TRANSPORT_ACCOUNT_ERROR_SEND:
4868 message = g_strdup (_("emev_ib_ui_smtp_send_error"));
4871 g_return_if_reached ();
4874 /* TODO if the username or the password where not defined we
4875 should show the Accounts Settings dialog or the Connection
4876 specific SMTP server window */
4878 modest_platform_run_information_dialog (NULL, message);
4883 modest_ui_actions_on_send_queue_status_changed (ModestTnySendQueue *send_queue,
4888 ModestMainWindow *main_window = NULL;
4889 ModestWindowMgr *mgr = NULL;
4890 GtkWidget *folder_view = NULL, *header_view = NULL;
4891 TnyFolderStore *selected_folder = NULL;
4892 TnyFolderType folder_type;
4894 mgr = modest_runtime_get_window_mgr ();
4895 main_window = MODEST_MAIN_WINDOW (modest_window_mgr_get_main_window (mgr,
4896 FALSE));/* don't create */
4900 /* Check if selected folder is OUTBOX */
4901 folder_view = modest_main_window_get_child_widget (main_window,
4902 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
4903 header_view = modest_main_window_get_child_widget (main_window,
4904 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
4906 selected_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
4907 if (!TNY_IS_FOLDER (selected_folder))
4910 /* gtk_tree_view_column_queue_resize is only available in GTK+ 2.8 */
4911 #if GTK_CHECK_VERSION(2, 8, 0)
4912 folder_type = modest_tny_folder_guess_folder_type (TNY_FOLDER (selected_folder));
4913 if (folder_type == TNY_FOLDER_TYPE_OUTBOX) {
4914 GtkTreeViewColumn *tree_column;
4916 tree_column = gtk_tree_view_get_column (GTK_TREE_VIEW (header_view),
4917 TNY_GTK_HEADER_LIST_MODEL_FROM_COLUMN);
4918 gtk_tree_view_column_queue_resize (tree_column);
4921 gtk_widget_queue_draw (header_view);
4926 if (selected_folder != NULL)
4927 g_object_unref (selected_folder);