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>
49 #ifdef MODEST_PLATFORM_MAEMO
50 #include "maemo/modest-osso-state-saving.h"
51 #include "maemo/modest-maemo-utils.h"
52 #include "maemo/modest-hildon-includes.h"
53 #endif /* MODEST_PLATFORM_MAEMO */
55 #include "widgets/modest-ui-constants.h"
56 #include <widgets/modest-main-window.h>
57 #include <widgets/modest-msg-view-window.h>
58 #include <widgets/modest-account-view-window.h>
59 #include <widgets/modest-details-dialog.h>
60 #include <widgets/modest-attachments-view.h>
61 #include "widgets/modest-folder-view.h"
62 #include "widgets/modest-global-settings-dialog.h"
63 #include "modest-connection-specific-smtp-window.h"
64 #include "modest-account-mgr-helpers.h"
65 #include "modest-mail-operation.h"
66 #include "modest-text-utils.h"
68 #ifdef MODEST_HAVE_EASYSETUP
69 #include "easysetup/modest-easysetup-wizard.h"
70 #endif /* MODEST_HAVE_EASYSETUP */
72 #include <modest-widget-memory.h>
73 #include <tny-error.h>
74 #include <tny-simple-list.h>
75 #include <tny-msg-view.h>
76 #include <tny-device.h>
77 #include <tny-merge-folder.h>
79 #include <gtkhtml/gtkhtml.h>
81 typedef struct _GetMsgAsyncHelper {
83 ModestMailOperation *mail_op;
90 typedef enum _ReplyForwardAction {
96 typedef struct _ReplyForwardHelper {
97 guint reply_forward_type;
98 ReplyForwardAction action;
100 GtkWidget *parent_window;
101 } ReplyForwardHelper;
103 typedef struct _PasteAsAttachmentHelper {
104 ModestMsgEditWindow *window;
106 } PasteAsAttachmentHelper;
110 * The do_headers_action uses this kind of functions to perform some
111 * action to each member of a list of headers
113 typedef void (*HeadersFunc) (TnyHeader *header, ModestWindow *win, gpointer user_data);
115 static void do_headers_action (ModestWindow *win,
119 static void open_msg_cb (ModestMailOperation *mail_op,
124 static void reply_forward_cb (ModestMailOperation *mail_op,
129 static void reply_forward (ReplyForwardAction action, ModestWindow *win);
131 static void folder_refreshed_cb (ModestMailOperation *mail_op,
135 static void _on_send_receive_progress_changed (ModestMailOperation *mail_op,
136 ModestMailOperationState *state,
140 download_uncached_messages (TnyList *header_list, GtkWindow *win,
145 run_account_setup_wizard (ModestWindow *win)
147 ModestEasysetupWizardDialog *wizard;
149 g_return_if_fail (MODEST_IS_WINDOW(win));
151 wizard = modest_easysetup_wizard_dialog_new ();
152 gtk_window_set_transient_for (GTK_WINDOW (wizard), GTK_WINDOW (win));
153 gtk_dialog_run (GTK_DIALOG (wizard));
154 gtk_widget_destroy (GTK_WIDGET (wizard));
159 modest_ui_actions_on_about (GtkAction *action, ModestWindow *win)
162 const gchar *authors[] = {
163 "Dirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>",
166 about = gtk_about_dialog_new ();
167 gtk_about_dialog_set_name (GTK_ABOUT_DIALOG(about), PACKAGE_NAME);
168 gtk_about_dialog_set_version (GTK_ABOUT_DIALOG(about),PACKAGE_VERSION);
169 gtk_about_dialog_set_copyright (GTK_ABOUT_DIALOG(about),
170 _("Copyright (c) 2006, Nokia Corporation\n"
171 "All rights reserved."));
172 gtk_about_dialog_set_comments (GTK_ABOUT_DIALOG(about),
173 _("a modest e-mail client\n\n"
174 "design and implementation: Dirk-Jan C. Binnema\n"
175 "contributions from the fine people at KC and Ig\n"
176 "uses the tinymail email framework written by Philip van Hoof"));
177 gtk_about_dialog_set_authors (GTK_ABOUT_DIALOG(about), authors);
178 gtk_about_dialog_set_website (GTK_ABOUT_DIALOG(about), "http://modest.garage.maemo.org");
180 gtk_dialog_run (GTK_DIALOG (about));
181 gtk_widget_destroy(about);
185 * Gets the list of currently selected messages. If the win is the
186 * main window, then it returns a newly allocated list of the headers
187 * selected in the header view. If win is the msg view window, then
188 * the value returned is a list with just a single header.
190 * The caller of this funcion must free the list.
193 get_selected_headers (ModestWindow *win)
195 if (MODEST_IS_MAIN_WINDOW(win)) {
196 GtkWidget *header_view;
198 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
199 MODEST_WIDGET_TYPE_HEADER_VIEW);
200 return modest_header_view_get_selected_headers (MODEST_HEADER_VIEW(header_view));
202 } else if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
203 /* for MsgViewWindows, we simply return a list with one element */
205 TnyList *list = NULL;
207 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
208 if (header != NULL) {
209 list = tny_simple_list_new ();
210 tny_list_prepend (list, G_OBJECT(header));
211 g_object_unref (G_OBJECT(header));
221 headers_action_mark_as_read (TnyHeader *header,
225 TnyHeaderFlags flags;
227 g_return_if_fail (TNY_IS_HEADER(header));
229 flags = tny_header_get_flags (header);
230 if (flags & TNY_HEADER_FLAG_SEEN) return;
231 tny_header_set_flags (header, TNY_HEADER_FLAG_SEEN);
235 headers_action_mark_as_unread (TnyHeader *header,
239 TnyHeaderFlags flags;
241 g_return_if_fail (TNY_IS_HEADER(header));
243 flags = tny_header_get_flags (header);
244 if (flags & TNY_HEADER_FLAG_SEEN) {
245 tny_header_unset_flags (header, TNY_HEADER_FLAG_SEEN);
249 /** A convenience method, because deleting a message is
250 * otherwise complicated, and it's best to change it in one place
253 void modest_do_message_delete (TnyHeader *header, ModestWindow *win)
255 ModestMailOperation *mail_op = NULL;
256 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_DELETE,
257 win ? G_OBJECT(win) : NULL);
258 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
261 /* Always delete. TODO: Move to trash still not supported */
262 modest_mail_operation_remove_msg (mail_op, header, FALSE);
263 g_object_unref (G_OBJECT (mail_op));
267 headers_action_delete (TnyHeader *header,
271 modest_do_message_delete (header, win);
273 /* refilter treemodel to hide marked-as-deleted rows */
274 /* if (MODEST_IS_HEADER_VIEW (user_data)) */
275 /* modest_header_view_refilter (MODEST_HEADER_VIEW (user_data)); */
278 /** After deleing a message that is currently visible in a window,
279 * show the next message from the list, or close the window if there are no more messages.
281 void modest_ui_actions_refresh_message_window_after_delete (ModestMsgViewWindow* win)
283 /* Close msg view window or select next */
284 if (modest_msg_view_window_last_message_selected (win) &&
285 modest_msg_view_window_first_message_selected (win)) {
286 modest_ui_actions_on_close_window (NULL, MODEST_WINDOW (win));
288 modest_msg_view_window_select_next_message (win);
293 modest_ui_actions_on_delete_message (GtkAction *action, ModestWindow *win)
295 TnyList *header_list = NULL;
296 TnyIterator *iter = NULL;
297 TnyHeader *header = NULL;
298 gchar *message = NULL;
301 ModestWindowMgr *mgr;
302 GtkWidget *header_view = NULL;
304 g_return_if_fail (MODEST_IS_WINDOW(win));
306 /* Check first if the header view has the focus */
307 if (MODEST_IS_MAIN_WINDOW (win)) {
309 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
310 MODEST_WIDGET_TYPE_HEADER_VIEW);
311 if (!gtk_widget_is_focus (header_view))
315 header_list = get_selected_headers (win);
316 if (!header_list) return;
318 /* Check if any of the headers are already opened, or in the process of being opened */
319 if (MODEST_IS_MAIN_WINDOW (win)) {
321 iter = tny_list_create_iterator (header_list);
323 mgr = modest_runtime_get_window_mgr ();
324 while (!tny_iterator_is_done (iter) && !found) {
325 header = TNY_HEADER (tny_iterator_get_current (iter));
327 found = modest_window_mgr_find_registered_header (mgr, header, NULL);
328 g_object_unref (header);
331 tny_iterator_next (iter);
333 g_object_unref (iter);
338 num = g_strdup_printf ("%d", tny_list_get_length (header_list));
339 msg = g_strdup_printf (_("mcen_nc_unable_to_delete_n_messages"), num);
341 modest_platform_run_information_dialog (GTK_WINDOW (win), (const gchar *) msg);
345 g_object_unref (header_list);
351 if (tny_list_get_length(header_list) == 1) {
352 iter = tny_list_create_iterator (header_list);
353 header = TNY_HEADER (tny_iterator_get_current (iter));
355 desc = g_strdup_printf ("%s", tny_header_get_subject (header));
356 g_object_unref (header);
359 g_object_unref (iter);
361 message = g_strdup_printf(ngettext("emev_nc_delete_message", "emev_nc_delete_messages",
362 tny_list_get_length(header_list)), desc);
364 /* Confirmation dialog */
365 printf("DEBUG: %s\n", __FUNCTION__);
366 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
370 if (response == GTK_RESPONSE_OK) {
371 ModestWindow *main_window = NULL;
372 ModestWindowMgr *mgr = NULL;
373 GtkTreeModel *model = NULL;
374 GtkTreeSelection *sel = NULL;
375 GList *sel_list = NULL, *tmp = NULL;
376 GtkTreeRowReference *row_reference = NULL;
377 GtkTreePath *next_path = NULL;
379 /* Find last selected row */
380 if (MODEST_IS_MAIN_WINDOW (win)) {
381 model = gtk_tree_view_get_model (GTK_TREE_VIEW (header_view));
382 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
383 sel_list = gtk_tree_selection_get_selected_rows (sel, &model);
384 for (tmp=sel_list; tmp; tmp=tmp->next) {
385 if (tmp->next == NULL) {
386 next_path = gtk_tree_path_copy((GtkTreePath *) tmp->data);
387 gtk_tree_path_next (next_path);
388 row_reference = gtk_tree_row_reference_new (model, next_path);
389 gtk_tree_path_free (next_path);
394 /* Remove each header. If it's a view window header_view == NULL */
395 do_headers_action (win, headers_action_delete, header_view);
397 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
398 modest_ui_actions_refresh_message_window_after_delete (MODEST_MSG_VIEW_WINDOW (win));
400 /* Get main window */
401 mgr = modest_runtime_get_window_mgr ();
402 main_window = modest_window_mgr_get_main_window (mgr);
405 /* Move cursor to next row */
408 /* Select next row */
409 if (gtk_tree_row_reference_valid (row_reference)) {
410 next_path = gtk_tree_row_reference_get_path (row_reference);
411 gtk_tree_selection_select_path (sel, next_path);
412 gtk_tree_path_free (next_path);
414 if (row_reference != NULL)
415 gtk_tree_row_reference_free (row_reference);
418 /* Update toolbar dimming state */
419 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
422 g_list_foreach (sel_list, (GFunc) gtk_tree_path_free, NULL);
423 g_list_free (sel_list);
429 g_object_unref (header_list);
435 /* delete either message or folder, based on where we are */
437 modest_ui_actions_on_delete_message_or_folder (GtkAction *action, ModestWindow *win)
439 g_return_if_fail (MODEST_IS_WINDOW(win));
441 /* Check first if the header view has the focus */
442 if (MODEST_IS_MAIN_WINDOW (win)) {
444 w = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
445 MODEST_WIDGET_TYPE_FOLDER_VIEW);
446 if (gtk_widget_is_focus (w)) {
447 modest_ui_actions_on_delete_folder (action, MODEST_MAIN_WINDOW(win));
451 modest_ui_actions_on_delete_message (action, win);
457 modest_ui_actions_on_quit (GtkAction *action, ModestWindow *win)
459 #ifdef MODEST_PLATFORM_MAEMO
460 modest_osso_save_state();
461 #endif /* MODEST_PLATFORM_MAEMO */
463 g_debug ("closing down, clearing %d item(s) from operation queue",
464 modest_mail_operation_queue_num_elements
465 (modest_runtime_get_mail_operation_queue()));
467 /* cancel all outstanding operations */
468 modest_mail_operation_queue_cancel_all
469 (modest_runtime_get_mail_operation_queue());
471 g_debug ("queue has been cleared");
473 /* note: when modest-tny-account-store is finalized,
474 it will automatically set all network connections
481 modest_ui_actions_on_close_window (GtkAction *action, ModestWindow *win)
485 g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value);
487 /* if (MODEST_IS_MSG_VIEW_WINDOW (win)) { */
488 /* gtk_widget_destroy (GTK_WIDGET (win)); */
489 /* } else if (MODEST_IS_MSG_EDIT_WINDOW (win)) { */
490 /* gboolean ret_value; */
491 /* g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value); */
492 /* } else if (MODEST_IS_WINDOW (win)) { */
493 /* gtk_widget_destroy (GTK_WIDGET (win)); */
495 /* g_return_if_reached (); */
500 modest_ui_actions_on_add_to_contacts (GtkAction *action, ModestWindow *win)
502 GtkClipboard *clipboard = NULL;
503 gchar *selection = NULL;
505 clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
506 selection = gtk_clipboard_wait_for_text (clipboard);
508 /* Question: why is the clipboard being used here?
509 * It doesn't really make a lot of sense. */
513 modest_address_book_add_address (selection);
519 modest_ui_actions_on_accounts (GtkAction *action, ModestWindow *win)
521 /* This is currently only implemented for Maemo */
522 #ifdef MODEST_PLATFORM_MAEMO /* Defined in config.h */
523 if (!modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE)) {
524 run_account_setup_wizard (win);
527 /* Show the list of accounts: */
528 GtkDialog *account_win = GTK_DIALOG(modest_account_view_window_new ());
529 modest_maemo_show_dialog_and_forget (GTK_WINDOW (win), account_win);
532 GtkWidget *dialog, *label;
534 /* Create the widgets */
536 dialog = gtk_dialog_new_with_buttons ("Message",
538 GTK_DIALOG_DESTROY_WITH_PARENT,
542 label = gtk_label_new ("Hello World!");
544 /* Ensure that the dialog box is destroyed when the user responds. */
546 g_signal_connect_swapped (dialog, "response",
547 G_CALLBACK (gtk_widget_destroy),
550 /* Add the label, and show everything we've added to the dialog. */
552 gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox),
554 gtk_widget_show_all (dialog);
555 #endif /* MODEST_PLATFORM_MAEMO */
559 on_smtp_servers_window_hide (GtkWindow* window, gpointer user_data)
561 ModestWindow *main_window = MODEST_WINDOW (user_data);
563 /* Save any changes. */
564 modest_connection_specific_smtp_window_save_server_accounts (
565 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (window),
566 modest_window_get_active_account (main_window));
567 gtk_widget_destroy (GTK_WIDGET (window));
573 modest_ui_actions_on_smtp_servers (GtkAction *action, ModestWindow *win)
575 /* This is currently only implemented for Maemo,
576 * because it requires an API (libconic) to detect different connection
579 #ifdef MODEST_PLATFORM_MAEMO /* Defined in config.h */
581 /* Create the window if necessary: */
582 const gchar *active_account_name = modest_window_get_active_account (win);
584 /* TODO: Dim the menu item (not in the UI spec)? or show a warning,
585 * or show the default account?
586 * If we show the default account then the account name should be shown in
587 * the window when we show it. */
588 if (!active_account_name) {
589 g_warning ("%s: No account is active.", __FUNCTION__);
593 GtkWidget *specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
594 modest_connection_specific_smtp_window_fill_with_connections (
595 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (specific_window),
596 modest_runtime_get_account_mgr(),
597 active_account_name);
599 /* Show the window: */
600 gtk_window_set_transient_for (GTK_WINDOW (specific_window), GTK_WINDOW (win));
601 gtk_window_set_modal (GTK_WINDOW (specific_window), TRUE);
602 gtk_widget_show (specific_window);
604 /* Save changes when the window is hidden: */
605 g_signal_connect (specific_window, "hide",
606 G_CALLBACK (on_smtp_servers_window_hide), win);
607 #endif /* MODEST_PLATFORM_MAEMO */
611 modest_ui_actions_on_new_msg (GtkAction *action, ModestWindow *win)
613 ModestWindow *msg_win = NULL;
615 TnyFolder *folder = NULL;
616 gchar *account_name = NULL;
617 gchar *from_str = NULL;
618 /* GError *err = NULL; */
619 TnyAccount *account = NULL;
620 ModestWindowMgr *mgr;
621 gchar *signature = NULL, *blank_and_signature = NULL;
623 /* if there are no accounts yet, just show the wizard */
624 if (!modest_account_mgr_has_accounts (modest_runtime_get_account_mgr(), TRUE)) {
625 run_account_setup_wizard (win);
629 account_name = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr ());
631 account_name = g_strdup (modest_window_get_active_account (win));
633 g_printerr ("modest: no account found\n");
637 account = modest_tny_account_store_get_server_account (modest_runtime_get_account_store(),
639 TNY_ACCOUNT_TYPE_STORE);
641 g_printerr ("modest: failed to get tnyaccount for '%s'\n", account_name);
645 from_str = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(), account_name);
647 g_printerr ("modest: failed get from string for '%s'\n", account_name);
651 if (modest_account_mgr_get_bool (modest_runtime_get_account_mgr (), account_name,
652 MODEST_ACCOUNT_USE_SIGNATURE, FALSE)) {
653 signature = modest_account_mgr_get_string (modest_runtime_get_account_mgr (), account_name,
654 MODEST_ACCOUNT_SIGNATURE, FALSE);
655 blank_and_signature = g_strconcat ("\n", signature, NULL);
658 blank_and_signature = g_strdup ("");
661 msg = modest_tny_msg_new ("", from_str, "", "", "", blank_and_signature, NULL);
663 g_printerr ("modest: failed to create new msg\n");
667 folder = modest_tny_account_get_special_folder (account, TNY_FOLDER_TYPE_DRAFTS);
669 g_printerr ("modest: failed to find Drafts folder\n");
674 /* Create and register edit window */
675 /* This is destroyed by TOOD. */
676 msg_win = modest_msg_edit_window_new (msg, account_name);
677 mgr = modest_runtime_get_window_mgr ();
678 modest_window_mgr_register_window (mgr, msg_win);
681 gtk_window_set_transient_for (GTK_WINDOW (msg_win),
683 gtk_widget_show_all (GTK_WIDGET (msg_win));
686 g_free (account_name);
688 g_free (blank_and_signature);
690 g_object_unref (msg_win);
692 g_object_unref (G_OBJECT(account));
694 g_object_unref (G_OBJECT(msg));
696 g_object_unref (G_OBJECT(folder));
700 modest_ui_actions_msg_retrieval_check (ModestMailOperation *mail_op,
704 ModestMailOperationStatus status;
706 /* If there is no message or the operation was not successful */
707 status = modest_mail_operation_get_status (mail_op);
708 if (!msg || status != MODEST_MAIL_OPERATION_STATUS_SUCCESS) {
710 /* Remove the header from the preregistered uids */
711 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (),
721 open_msg_cb (ModestMailOperation *mail_op,
726 ModestWindowMgr *mgr = NULL;
727 ModestWindow *parent_win = NULL;
728 ModestWindow *win = NULL;
729 TnyFolderType folder_type = TNY_FOLDER_TYPE_UNKNOWN;
730 gchar *account = NULL;
733 /* Do nothing if there was any problem with the mail
734 operation. The error will be shown by the error_handler of
735 the mail operation */
736 if (!modest_ui_actions_msg_retrieval_check (mail_op, header, msg)) {
740 parent_win = (ModestWindow *) modest_mail_operation_get_source (mail_op);
741 folder = tny_header_get_folder (header);
743 /* Mark header as read */
744 headers_action_mark_as_read (header, MODEST_WINDOW(parent_win), NULL);
747 account = g_strdup (modest_window_get_active_account (MODEST_WINDOW (parent_win)));
749 account = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
751 /* Gets folder type (OUTBOX headers will be opened in edit window */
752 if (modest_tny_folder_is_local_folder (folder))
753 folder_type = modest_tny_folder_get_local_or_mmc_folder_type (folder);
755 /* If the header is in the drafts folder then open the editor,
756 else the message view window */
757 if ((folder_type == TNY_FOLDER_TYPE_DRAFTS) ||
758 (folder_type == TNY_FOLDER_TYPE_OUTBOX)) {
759 /* we cannot edit without a valid account... */
760 if (!modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE)) {
761 run_account_setup_wizard(parent_win);
764 win = modest_msg_edit_window_new (msg, account);
766 gchar *uid = modest_tny_folder_get_header_unique_id (header);
768 if (MODEST_IS_MAIN_WINDOW (parent_win)) {
769 GtkWidget *header_view;
770 GtkTreeSelection *sel;
771 GList *sel_list = NULL;
774 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(parent_win),
775 MODEST_WIDGET_TYPE_HEADER_VIEW);
777 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
778 sel_list = gtk_tree_selection_get_selected_rows (sel, &model);
780 if (sel_list != NULL) {
781 GtkTreeRowReference *row_reference;
783 row_reference = gtk_tree_row_reference_new (model, (GtkTreePath *) sel_list->data);
784 g_list_foreach (sel_list, (GFunc) gtk_tree_path_free, NULL);
785 g_list_free (sel_list);
787 win = modest_msg_view_window_new_with_header_model (msg,
792 gtk_tree_row_reference_free (row_reference);
794 win = modest_msg_view_window_new (msg, account, (const gchar*) uid);
797 win = modest_msg_view_window_new (msg, account, (const gchar*) uid);
802 /* Register and show new window */
804 mgr = modest_runtime_get_window_mgr ();
805 modest_window_mgr_register_window (mgr, win);
806 g_object_unref (win);
807 gtk_window_set_transient_for (GTK_WINDOW (win), GTK_WINDOW (parent_win));
808 gtk_widget_show_all (GTK_WIDGET(win));
811 /* Update toolbar dimming state */
812 if (MODEST_IS_MAIN_WINDOW (parent_win)) {
813 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (parent_win));
819 g_object_unref (parent_win);
820 g_object_unref (folder);
824 modest_ui_actions_get_msgs_full_error_handler (ModestMailOperation *mail_op,
828 GObject *win = modest_mail_operation_get_source (mail_op);
830 error = modest_mail_operation_get_error (mail_op);
831 printf ("DEBUG: %s: Error: code=%d, text=%s\n", __FUNCTION__, error->code, error->message);
833 if (error->code == MODEST_MAIL_OPERATION_ERROR_MESSAGE_SIZE_LIMIT) {
835 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
838 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
839 _("mail_ni_ui_folder_get_msg_folder_error"));
843 g_object_unref (win);
847 * This function is used by both modest_ui_actions_on_open and
848 * modest_ui_actions_on_header_activated. This way we always do the
849 * same when trying to open messages.
852 _modest_ui_actions_open (TnyList *headers, ModestWindow *win)
854 ModestWindowMgr *mgr = NULL;
855 TnyIterator *iter = NULL;
856 ModestMailOperation *mail_op = NULL;
857 TnyList *not_opened_headers = NULL;
858 TnyHeaderFlags flags = 0;
860 /* Look if we already have a message view for each header. If
861 true, then remove the header from the list of headers to
863 mgr = modest_runtime_get_window_mgr ();
864 iter = tny_list_create_iterator (headers);
865 not_opened_headers = tny_simple_list_new ();
867 while (!tny_iterator_is_done (iter)) {
869 ModestWindow *window = NULL;
870 TnyHeader *header = NULL;
871 gboolean found = FALSE;
873 header = TNY_HEADER (tny_iterator_get_current (iter));
875 flags = tny_header_get_flags (header);
878 found = modest_window_mgr_find_registered_header (mgr, header, &window);
880 /* Do not open again the message and present the
881 window to the user */
884 gtk_window_present (GTK_WINDOW (window));
886 /* the header has been registered already, we don't do
887 * anything but wait for the window to come up*/
888 g_debug ("header %p already registered, waiting for window", header);
890 tny_list_append (not_opened_headers, G_OBJECT (header));
894 g_object_unref (header);
896 tny_iterator_next (iter);
898 g_object_unref (iter);
901 /* If some messages would have to be downloaded, ask the user to
902 * make a connection. It's generally easier to do this here (in the mainloop)
903 * than later in a thread:
905 if (tny_list_get_length (not_opened_headers) > 0) {
907 gboolean found = FALSE;
909 iter = tny_list_create_iterator (not_opened_headers);
910 while (!tny_iterator_is_done (iter) && !found) {
911 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter));
912 if (!(tny_header_get_flags (header) & TNY_HEADER_FLAG_CACHED))
915 tny_iterator_next (iter);
917 g_object_unref (header);
919 g_object_unref (iter);
921 if (found && !modest_platform_connect_and_wait (GTK_WINDOW (win), NULL)) {
922 g_object_unref (not_opened_headers);
927 /* Register the headers before actually creating the windows: */
928 TnyIterator *iter_not_opened = tny_list_create_iterator (not_opened_headers);
929 while (!tny_iterator_is_done (iter_not_opened)) {
930 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter_not_opened));
932 modest_window_mgr_register_header (mgr, header);
933 g_object_unref (header);
936 tny_iterator_next (iter_not_opened);
938 g_object_unref (iter_not_opened);
939 iter_not_opened = NULL;
941 /* Open each message */
942 if (tny_list_get_length (not_opened_headers) > 0) {
943 mail_op = modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE,
945 modest_ui_actions_get_msgs_full_error_handler,
947 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
948 if (tny_list_get_length (not_opened_headers) > 1) {
949 modest_mail_operation_get_msgs_full (mail_op,
955 TnyIterator *iter = tny_list_create_iterator (not_opened_headers);
956 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter));
957 modest_mail_operation_get_msg (mail_op, header, open_msg_cb, NULL);
958 g_object_unref (header);
959 g_object_unref (iter);
961 g_object_unref (mail_op);
965 if (not_opened_headers != NULL)
966 g_object_unref (not_opened_headers);
970 modest_ui_actions_on_open (GtkAction *action, ModestWindow *win)
975 headers = get_selected_headers (win);
980 _modest_ui_actions_open (headers, win);
982 g_object_unref(headers);
987 free_reply_forward_helper (gpointer data)
989 ReplyForwardHelper *helper;
991 helper = (ReplyForwardHelper *) data;
992 g_free (helper->account_name);
993 g_slice_free (ReplyForwardHelper, helper);
997 reply_forward_cb (ModestMailOperation *mail_op,
1003 ReplyForwardHelper *rf_helper;
1004 ModestWindow *msg_win = NULL;
1005 ModestEditType edit_type;
1007 TnyAccount *account = NULL;
1008 ModestWindowMgr *mgr = NULL;
1009 gchar *signature = NULL;
1011 /* If there was any error. The mail operation could be NULL,
1012 this means that we already have the message downloaded and
1013 that we didn't do a mail operation to retrieve it */
1014 if (mail_op && !modest_ui_actions_msg_retrieval_check (mail_op, header, msg))
1017 g_return_if_fail (user_data != NULL);
1018 rf_helper = (ReplyForwardHelper *) user_data;
1020 from = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(),
1021 rf_helper->account_name);
1022 if (modest_account_mgr_get_bool (modest_runtime_get_account_mgr(),
1023 rf_helper->account_name,
1024 MODEST_ACCOUNT_USE_SIGNATURE, FALSE)) {
1025 signature = modest_account_mgr_get_string (modest_runtime_get_account_mgr (),
1026 rf_helper->account_name,
1027 MODEST_ACCOUNT_SIGNATURE, FALSE);
1030 /* Create reply mail */
1031 switch (rf_helper->action) {
1034 modest_tny_msg_create_reply_msg (msg, from, signature,
1035 rf_helper->reply_forward_type,
1036 MODEST_TNY_MSG_REPLY_MODE_SENDER);
1038 case ACTION_REPLY_TO_ALL:
1040 modest_tny_msg_create_reply_msg (msg, from, signature, rf_helper->reply_forward_type,
1041 MODEST_TNY_MSG_REPLY_MODE_ALL);
1042 edit_type = MODEST_EDIT_TYPE_REPLY;
1044 case ACTION_FORWARD:
1046 modest_tny_msg_create_forward_msg (msg, from, signature, rf_helper->reply_forward_type);
1047 edit_type = MODEST_EDIT_TYPE_FORWARD;
1050 g_return_if_reached ();
1057 g_printerr ("modest: failed to create message\n");
1061 account = modest_tny_account_store_get_server_account (modest_runtime_get_account_store(),
1062 rf_helper->account_name,
1063 TNY_ACCOUNT_TYPE_STORE);
1065 g_printerr ("modest: failed to get tnyaccount for '%s'\n", rf_helper->account_name);
1069 /* Create and register the windows */
1070 msg_win = modest_msg_edit_window_new (new_msg, rf_helper->account_name);
1071 mgr = modest_runtime_get_window_mgr ();
1072 modest_window_mgr_register_window (mgr, msg_win);
1074 if (rf_helper->parent_window != NULL) {
1075 gdouble parent_zoom;
1077 parent_zoom = modest_window_get_zoom (MODEST_WINDOW (rf_helper->parent_window));
1078 modest_window_set_zoom (msg_win, parent_zoom);
1081 /* Show edit window */
1082 gtk_widget_show_all (GTK_WIDGET (msg_win));
1086 g_object_unref (msg_win);
1088 g_object_unref (G_OBJECT (new_msg));
1090 g_object_unref (G_OBJECT (account));
1091 /* g_object_unref (msg); */
1092 g_object_unref (header);
1093 free_reply_forward_helper (rf_helper);
1097 * Checks a list of headers. If any of them are not currently
1098 * downloaded (CACHED) then it asks the user for permission to
1101 * Returns FALSE if the user does not want to download the
1102 * messages. Returns TRUE if the user allowed the download or if all
1103 * of them are currently downloaded
1106 download_uncached_messages (TnyList *header_list,
1112 gint uncached_messages = 0;
1114 iter = tny_list_create_iterator (header_list);
1115 while (!tny_iterator_is_done (iter)) {
1118 header = TNY_HEADER (tny_iterator_get_current (iter));
1120 if (!(tny_header_get_flags (header) & TNY_HEADER_FLAG_CACHED))
1121 uncached_messages ++;
1122 g_object_unref (header);
1125 tny_iterator_next (iter);
1127 g_object_unref (iter);
1129 /* Ask for user permission to download the messages */
1131 if (uncached_messages > 0) {
1132 GtkResponseType response;
1134 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
1135 _("emev_nc_include_original"));
1138 modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
1139 ngettext("mcen_nc_get_msg",
1141 uncached_messages));
1142 if (response == GTK_RESPONSE_CANCEL)
1145 /* If a download will be necessary, make sure that we have a connection: */
1146 retval = modest_platform_connect_and_wait(win, NULL);
1154 * Common code for the reply and forward actions
1157 reply_forward (ReplyForwardAction action, ModestWindow *win)
1159 ModestMailOperation *mail_op = NULL;
1160 TnyList *header_list = NULL;
1161 ReplyForwardHelper *rf_helper = NULL;
1162 guint reply_forward_type;
1163 gboolean continue_download;
1165 g_return_if_fail (MODEST_IS_WINDOW(win));
1167 /* we need an account when editing */
1168 if (!modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE)) {
1169 run_account_setup_wizard (win);
1173 header_list = get_selected_headers (win);
1177 /* Check that the messages have been previously downloaded */
1178 continue_download = download_uncached_messages (header_list, GTK_WINDOW (win), TRUE);
1179 if (!continue_download) {
1180 g_object_unref (header_list);
1184 reply_forward_type =
1185 modest_conf_get_int (modest_runtime_get_conf (),
1186 (action == ACTION_FORWARD) ? MODEST_CONF_FORWARD_TYPE : MODEST_CONF_REPLY_TYPE,
1188 /* We assume that we can only select messages of the
1189 same folder and that we reply all of them from the
1190 same account. In fact the interface currently only
1191 allows single selection */
1194 rf_helper = g_slice_new0 (ReplyForwardHelper);
1195 rf_helper->reply_forward_type = reply_forward_type;
1196 rf_helper->action = action;
1197 rf_helper->account_name = g_strdup (modest_window_get_active_account (win));
1199 if ((win != NULL) && (MODEST_IS_WINDOW (win)))
1200 rf_helper->parent_window = GTK_WIDGET (win);
1201 if (!rf_helper->account_name)
1202 rf_helper->account_name =
1203 modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
1205 if (MODEST_IS_MSG_VIEW_WINDOW(win)) {
1208 /* Get header and message. Do not free them here, the
1209 reply_forward_cb must do it */
1210 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW(win));
1211 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW(win));
1212 if (!msg || !header) {
1214 g_object_unref (msg);
1216 g_object_unref (header);
1217 g_printerr ("modest: no message found\n");
1220 reply_forward_cb (NULL, header, msg, rf_helper);
1226 /* Retrieve messages */
1227 mail_op = modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE,
1229 modest_ui_actions_get_msgs_full_error_handler,
1231 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
1233 /* Only reply/forward to one message */
1234 iter = tny_list_create_iterator (header_list);
1235 header = TNY_HEADER (tny_iterator_get_current (iter));
1236 g_object_unref (iter);
1239 modest_mail_operation_get_msg (mail_op,
1244 /* modest_mail_operation_get_msgs_full (mail_op, */
1246 /* reply_forward_cb, */
1248 /* free_reply_forward_helper); */
1250 g_object_unref (header);
1254 g_object_unref(mail_op);
1258 g_object_unref (header_list);
1262 modest_ui_actions_on_reply (GtkAction *action, ModestWindow *win)
1264 g_return_if_fail (MODEST_IS_WINDOW(win));
1266 reply_forward (ACTION_REPLY, win);
1270 modest_ui_actions_on_forward (GtkAction *action, ModestWindow *win)
1272 g_return_if_fail (MODEST_IS_WINDOW(win));
1274 reply_forward (ACTION_FORWARD, win);
1278 modest_ui_actions_on_reply_all (GtkAction *action, ModestWindow *win)
1280 g_return_if_fail (MODEST_IS_WINDOW(win));
1282 reply_forward (ACTION_REPLY_TO_ALL, win);
1286 modest_ui_actions_on_next (GtkAction *action,
1287 ModestWindow *window)
1289 if (MODEST_IS_MAIN_WINDOW (window)) {
1290 GtkWidget *header_view;
1292 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
1293 MODEST_WIDGET_TYPE_HEADER_VIEW);
1297 modest_header_view_select_next (MODEST_HEADER_VIEW(header_view));
1298 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
1299 modest_msg_view_window_select_next_message (MODEST_MSG_VIEW_WINDOW (window));
1301 g_return_if_reached ();
1306 modest_ui_actions_on_prev (GtkAction *action,
1307 ModestWindow *window)
1309 g_return_if_fail (MODEST_IS_WINDOW(window));
1311 if (MODEST_IS_MAIN_WINDOW (window)) {
1312 GtkWidget *header_view;
1313 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
1314 MODEST_WIDGET_TYPE_HEADER_VIEW);
1318 modest_header_view_select_prev (MODEST_HEADER_VIEW(header_view));
1319 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
1320 modest_msg_view_window_select_previous_message (MODEST_MSG_VIEW_WINDOW (window));
1322 g_return_if_reached ();
1327 modest_ui_actions_on_sort (GtkAction *action,
1328 ModestWindow *window)
1330 g_return_if_fail (MODEST_IS_WINDOW(window));
1332 if (MODEST_IS_MAIN_WINDOW (window)) {
1333 GtkWidget *header_view;
1334 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
1335 MODEST_WIDGET_TYPE_HEADER_VIEW);
1337 modest_platform_information_banner (NULL, NULL, _CS("ckdg_ib_nothing_to_sort"));
1342 /* Show sorting dialog */
1343 modest_platform_run_sort_dialog (GTK_WINDOW (window), MODEST_SORT_HEADERS);
1348 new_messages_arrived (ModestMailOperation *self,
1352 if (new_messages == 0)
1355 modest_platform_on_new_msg ();
1359 * This function performs the send & receive required actions. The
1360 * window is used to create the mail operation. Typically it should
1361 * always be the main window, but we pass it as argument in order to
1365 modest_ui_actions_do_send_receive (const gchar *account_name, ModestWindow *win)
1367 gchar *acc_name = NULL;
1368 ModestMailOperation *mail_op;
1370 /* If no account name was provided then get the current account, and if
1371 there is no current account then pick the default one: */
1372 if (!account_name) {
1373 acc_name = g_strdup (modest_window_get_active_account(win));
1375 acc_name = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
1377 g_printerr ("modest: cannot get default account\n");
1381 acc_name = g_strdup (account_name);
1384 /* Set send/receive operation in progress */
1385 modest_main_window_notify_send_receive_initied (MODEST_MAIN_WINDOW(win));
1387 mail_op = modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE,
1389 modest_ui_actions_send_receive_error_handler,
1392 g_signal_connect (G_OBJECT(mail_op), "progress-changed",
1393 G_CALLBACK (_on_send_receive_progress_changed),
1396 /* Send & receive. */
1397 /* TODO: The spec wants us to first do any pending deletions, before receiving. */
1398 /* Receive and then send. The operation is tagged initially as
1399 a receive operation because the account update performs a
1400 receive and then a send. The operation changes its type
1401 internally, so the progress objects will receive the proper
1402 progress information */
1403 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
1404 modest_mail_operation_update_account (mail_op, acc_name, new_messages_arrived, NULL);
1405 g_object_unref (G_OBJECT (mail_op));
1413 modest_ui_actions_do_cancel_send (const gchar *account_name,
1416 TnyTransportAccount *transport_account;
1417 TnySendQueue *send_queue = NULL;
1418 GError *error = NULL;
1420 /* Get transport account */
1422 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
1423 (modest_runtime_get_account_store(),
1425 TNY_ACCOUNT_TYPE_TRANSPORT));
1426 if (!transport_account) {
1427 g_printerr ("modest: no transport account found for '%s'\n", account_name);
1432 send_queue = TNY_SEND_QUEUE (modest_runtime_get_send_queue (transport_account));
1433 if (!TNY_IS_SEND_QUEUE(send_queue)) {
1434 g_set_error (&error, MODEST_MAIL_OPERATION_ERROR,
1435 MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND,
1436 "modest: could not find send queue for account\n");
1438 /* Keeep messages in outbox folder */
1439 tny_send_queue_cancel (send_queue, FALSE, &error);
1443 if (transport_account != NULL)
1444 g_object_unref (G_OBJECT (transport_account));
1448 modest_ui_actions_cancel_send_all (ModestWindow *win)
1450 GSList *account_names, *iter;
1452 account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
1455 iter = account_names;
1457 modest_ui_actions_do_cancel_send ((const char*) iter->data, win);
1458 iter = g_slist_next (iter);
1461 modest_account_mgr_free_account_names (account_names);
1462 account_names = NULL;
1466 modest_ui_actions_cancel_send (GtkAction *action, ModestWindow *win)
1469 /* Check if accounts exist */
1470 gboolean accounts_exist =
1471 modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
1473 /* If not, allow the user to create an account before trying to send/receive. */
1474 if (!accounts_exist)
1475 modest_ui_actions_on_accounts (NULL, win);
1477 /* Cancel all sending operaitons */
1478 modest_ui_actions_cancel_send_all (win);
1482 * Refreshes all accounts. This function will be used by automatic
1486 modest_ui_actions_do_send_receive_all (ModestWindow *win)
1488 GSList *account_names, *iter;
1490 account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
1493 iter = account_names;
1495 modest_ui_actions_do_send_receive ((const char*) iter->data, win);
1496 iter = g_slist_next (iter);
1499 modest_account_mgr_free_account_names (account_names);
1500 account_names = NULL;
1504 modest_do_refresh_current_folder(ModestWindow *win)
1506 /* Refresh currently selected folder. Note that if we only
1507 want to retreive the headers, then the refresh only will
1508 invoke a poke_status over all folders, i.e., only the
1509 total/unread count will be updated */
1510 if (MODEST_IS_MAIN_WINDOW (win)) {
1511 GtkWidget *header_view, *folder_view;
1512 TnyFolderStore *folder_store;
1514 /* Get folder and header view */
1516 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
1517 MODEST_WIDGET_TYPE_FOLDER_VIEW);
1519 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
1521 if (folder_store && TNY_IS_FOLDER (folder_store)) {
1523 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
1524 MODEST_WIDGET_TYPE_HEADER_VIEW);
1526 /* We do not need to set the contents style
1527 because it hasn't changed. We also do not
1528 need to save the widget status. Just force
1530 modest_header_view_set_folder (MODEST_HEADER_VIEW(header_view),
1531 TNY_FOLDER (folder_store),
1532 folder_refreshed_cb,
1533 MODEST_MAIN_WINDOW (win));
1537 g_object_unref (folder_store);
1543 * Handler of the click on Send&Receive button in the main toolbar
1546 modest_ui_actions_on_send_receive (GtkAction *action, ModestWindow *win)
1548 /* Check if accounts exist */
1549 gboolean accounts_exist =
1550 modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
1552 /* If not, allow the user to create an account before trying to send/receive. */
1553 if (!accounts_exist)
1554 modest_ui_actions_on_accounts (NULL, win);
1556 modest_do_refresh_current_folder (win);
1558 /* Refresh the active account */
1559 modest_ui_actions_do_send_receive (NULL, win);
1564 modest_ui_actions_toggle_header_list_view (GtkAction *action, ModestMainWindow *main_window)
1567 GtkWidget *header_view;
1569 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1571 header_view = modest_main_window_get_child_widget (main_window,
1572 MODEST_WIDGET_TYPE_HEADER_VIEW);
1576 conf = modest_runtime_get_conf ();
1578 /* what is saved/restored is depending on the style; thus; we save with
1579 * old style, then update the style, and restore for this new style
1581 modest_widget_memory_save (conf, G_OBJECT(header_view), MODEST_CONF_HEADER_VIEW_KEY);
1583 if (modest_header_view_get_style
1584 (MODEST_HEADER_VIEW(header_view)) == MODEST_HEADER_VIEW_STYLE_DETAILS)
1585 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
1586 MODEST_HEADER_VIEW_STYLE_TWOLINES);
1588 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
1589 MODEST_HEADER_VIEW_STYLE_DETAILS);
1591 modest_widget_memory_restore (conf, G_OBJECT(header_view),
1592 MODEST_CONF_HEADER_VIEW_KEY);
1597 modest_ui_actions_on_header_selected (ModestHeaderView *header_view,
1599 ModestMainWindow *main_window)
1601 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1602 g_return_if_fail (MODEST_IS_HEADER_VIEW (header_view));
1604 /* If no header has been selected then exit */
1609 if (!gtk_widget_is_focus (GTK_WIDGET(header_view)))
1610 gtk_widget_grab_focus (GTK_WIDGET(header_view));
1612 /* Update Main window title */
1613 if (gtk_widget_is_focus (GTK_WIDGET(header_view))) {
1614 const gchar *subject = tny_header_get_subject (header);
1615 if (subject && strlen(subject) > 0)
1616 gtk_window_set_title (GTK_WINDOW (main_window), subject);
1618 gtk_window_set_title (GTK_WINDOW (main_window), _("mail_va_no_subject"));
1621 /* Update toolbar dimming state */
1622 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
1626 modest_ui_actions_on_header_activated (ModestHeaderView *header_view,
1628 ModestMainWindow *main_window)
1632 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1637 headers = tny_simple_list_new ();
1638 tny_list_prepend (headers, G_OBJECT (header));
1640 _modest_ui_actions_open (headers, MODEST_WINDOW (main_window));
1642 g_object_unref (headers);
1646 set_active_account_from_tny_account (TnyAccount *account,
1647 ModestWindow *window)
1649 const gchar *server_acc_name = tny_account_get_id (account);
1651 /* We need the TnyAccount provided by the
1652 account store because that is the one that
1653 knows the name of the Modest account */
1654 TnyAccount *modest_server_account = modest_server_account =
1655 modest_tny_account_store_get_tny_account_by (modest_runtime_get_account_store (),
1656 MODEST_TNY_ACCOUNT_STORE_QUERY_ID,
1659 const gchar *modest_acc_name =
1660 modest_tny_account_get_parent_modest_account_name_for_server_account (modest_server_account);
1661 modest_window_set_active_account (window, modest_acc_name);
1662 g_object_unref (modest_server_account);
1667 folder_refreshed_cb (ModestMailOperation *mail_op,
1671 ModestMainWindow *win = NULL;
1672 GtkWidget *header_view;
1673 TnyFolder *current_folder;
1675 g_return_if_fail (TNY_IS_FOLDER (folder));
1677 win = MODEST_MAIN_WINDOW (user_data);
1679 modest_main_window_get_child_widget(win, MODEST_WIDGET_TYPE_HEADER_VIEW);
1682 current_folder = modest_header_view_get_folder (MODEST_HEADER_VIEW (header_view));
1683 if (current_folder != NULL && folder != current_folder) {
1688 /* Check if folder is empty and set headers view contents style */
1689 if (tny_folder_get_all_count (folder) == 0) {
1690 printf ("DEBUG: %s: tny_folder_get_all_count() returned 0.\n", __FUNCTION__);
1691 modest_main_window_set_contents_style (win,
1692 MODEST_MAIN_WINDOW_CONTENTS_STYLE_EMPTY);
1694 printf ("DEBUG: %s: tny_folder_get_all_count() returned >0.\n", __FUNCTION__);
1699 modest_ui_actions_on_folder_selection_changed (ModestFolderView *folder_view,
1700 TnyFolderStore *folder_store,
1702 ModestMainWindow *main_window)
1705 GtkWidget *header_view;
1707 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1709 header_view = modest_main_window_get_child_widget(main_window,
1710 MODEST_WIDGET_TYPE_HEADER_VIEW);
1714 conf = modest_runtime_get_conf ();
1716 if (TNY_IS_ACCOUNT (folder_store)) {
1718 /* Update active account */
1719 set_active_account_from_tny_account (TNY_ACCOUNT (folder_store), MODEST_WINDOW (main_window));
1720 /* Show account details */
1721 modest_main_window_set_contents_style (main_window, MODEST_MAIN_WINDOW_CONTENTS_STYLE_DETAILS);
1724 if (TNY_IS_FOLDER (folder_store) && selected) {
1726 /* Update the active account */
1727 TnyAccount *account = modest_tny_folder_get_account (TNY_FOLDER (folder_store));
1729 set_active_account_from_tny_account (account, MODEST_WINDOW (main_window));
1730 g_object_unref (account);
1734 /* Set the header style by default, it could
1735 be changed later by the refresh callback to
1737 modest_main_window_set_contents_style (main_window,
1738 MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS);
1740 /* Set folder on header view. This function
1741 will call tny_folder_refresh_async so we
1742 pass a callback that will be called when
1743 finished. We use that callback to set the
1744 empty view if there are no messages */
1745 modest_header_view_set_folder (MODEST_HEADER_VIEW(header_view),
1746 TNY_FOLDER (folder_store),
1747 folder_refreshed_cb,
1750 /* Restore configuration. We need to do this
1751 *after* the set_folder because the widget
1752 memory asks the header view about its
1754 modest_widget_memory_restore (modest_runtime_get_conf (),
1755 G_OBJECT(header_view),
1756 MODEST_CONF_HEADER_VIEW_KEY);
1758 /* Update the active account */
1759 modest_window_set_active_account (MODEST_WINDOW (main_window), NULL);
1760 /* Save only if we're seeing headers */
1761 if (modest_main_window_get_contents_style (main_window) ==
1762 MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS)
1763 modest_widget_memory_save (conf, G_OBJECT (header_view),
1764 MODEST_CONF_HEADER_VIEW_KEY);
1765 modest_header_view_clear (MODEST_HEADER_VIEW(header_view));
1769 /* Update toolbar dimming state */
1770 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
1774 modest_ui_actions_on_item_not_found (ModestHeaderView *header_view,ModestItemType type,
1781 item = (type == MODEST_ITEM_TYPE_FOLDER) ? "folder" : "message";
1783 online = tny_device_is_online (modest_runtime_get_device());
1786 /* already online -- the item is simply not there... */
1787 dialog = gtk_message_dialog_new (GTK_WINDOW (win),
1789 GTK_MESSAGE_WARNING,
1791 _("The %s you selected cannot be found"),
1793 gtk_dialog_run (GTK_DIALOG(dialog));
1795 dialog = gtk_dialog_new_with_buttons (_("Connection requested"),
1799 GTK_RESPONSE_REJECT,
1801 GTK_RESPONSE_ACCEPT,
1803 txt = g_strdup_printf (_("This %s is not available in offline mode.\n"
1804 "Do you want to get online?"), item);
1805 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
1806 gtk_label_new (txt), FALSE, FALSE, 0);
1807 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
1810 gtk_window_set_default_size (GTK_WINDOW(dialog), 300, 300);
1811 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
1812 /* TODO: Comment about why is this commented out: */
1813 /* modest_platform_connect_and_wait (); */
1816 gtk_widget_destroy (dialog);
1820 modest_ui_actions_on_msg_link_hover (ModestMsgView *msgview, const gchar* link,
1823 /* g_message ("%s %s", __FUNCTION__, link); */
1828 modest_ui_actions_on_msg_link_clicked (ModestMsgView *msgview, const gchar* link,
1831 modest_platform_activate_uri (link);
1835 modest_ui_actions_on_msg_link_contextual (ModestMsgView *msgview, const gchar* link,
1838 modest_platform_show_uri_popup (link);
1842 modest_ui_actions_on_msg_attachment_clicked (ModestMsgView *msgview, TnyMimePart *mime_part,
1845 modest_msg_view_window_view_attachment (MODEST_MSG_VIEW_WINDOW (win), mime_part);
1849 modest_ui_actions_on_msg_recpt_activated (ModestMsgView *msgview,
1850 const gchar *address,
1853 /* g_message ("%s %s", __FUNCTION__, address); */
1857 modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edit_window)
1859 TnyTransportAccount *transport_account;
1860 ModestMailOperation *mail_operation;
1862 gchar *account_name, *from;
1863 ModestAccountMgr *account_mgr;
1864 gchar *info_text = NULL;
1866 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window));
1868 data = modest_msg_edit_window_get_msg_data (edit_window);
1870 account_mgr = modest_runtime_get_account_mgr();
1871 account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
1873 account_name = modest_account_mgr_get_default_account (account_mgr);
1874 if (!account_name) {
1875 g_printerr ("modest: no account found\n");
1876 modest_msg_edit_window_free_msg_data (edit_window, data);
1880 if (!strcmp (account_name, MODEST_LOCAL_FOLDERS_ACCOUNT_ID)) {
1881 account_name = g_strdup (data->account_name);
1885 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
1886 (modest_runtime_get_account_store(),
1888 TNY_ACCOUNT_TYPE_TRANSPORT));
1889 if (!transport_account) {
1890 g_printerr ("modest: no transport account found for '%s'\n", account_name);
1891 g_free (account_name);
1892 modest_msg_edit_window_free_msg_data (edit_window, data);
1895 from = modest_account_mgr_get_from_string (account_mgr, account_name);
1897 /* Create the mail operation */
1898 mail_operation = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_INFO, G_OBJECT(edit_window));
1899 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
1901 modest_mail_operation_save_to_drafts (mail_operation,
1913 data->priority_flags);
1916 g_free (account_name);
1917 g_object_unref (G_OBJECT (transport_account));
1918 g_object_unref (G_OBJECT (mail_operation));
1920 modest_msg_edit_window_free_msg_data (edit_window, data);
1922 info_text = g_strdup_printf (_("mail_va_saved_to_drafts"), _("mcen_me_folder_drafts"));
1923 modest_platform_information_banner (NULL, NULL, info_text);
1927 /* For instance, when clicking the Send toolbar button when editing a message: */
1929 modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
1931 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window));
1933 if (!modest_msg_edit_window_check_names (edit_window, TRUE))
1936 /* Offer the connection dialog, if necessary: */
1937 if (!modest_platform_connect_and_wait (GTK_WINDOW (edit_window), NULL))
1940 /* FIXME: Code added just for testing. The final version will
1941 use the send queue provided by tinymail and some
1943 ModestAccountMgr *account_mgr = modest_runtime_get_account_mgr();
1944 gchar *account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
1946 account_name = modest_account_mgr_get_default_account (account_mgr);
1948 if (!account_name) {
1949 g_printerr ("modest: no account found\n");
1953 MsgData *data = modest_msg_edit_window_get_msg_data (edit_window);
1955 if (!strcmp (account_name, MODEST_LOCAL_FOLDERS_ACCOUNT_ID)) {
1956 account_name = g_strdup (data->account_name);
1959 /* Get the currently-active transport account for this modest account: */
1960 TnyTransportAccount *transport_account =
1961 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_transport_account_for_open_connection
1962 (modest_runtime_get_account_store(),
1964 if (!transport_account) {
1965 g_printerr ("modest: no transport account found for '%s'\n", account_name);
1966 g_free (account_name);
1967 modest_msg_edit_window_free_msg_data (edit_window, data);
1971 gchar *from = modest_account_mgr_get_from_string (account_mgr, account_name);
1973 /* mail content checks and dialogs */
1974 if (data->subject == NULL || data->subject[0] == '\0') {
1975 GtkResponseType response;
1976 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (edit_window),
1977 _("mcen_nc_subject_is_empty_send"));
1978 if (response == GTK_RESPONSE_CANCEL) {
1979 g_free (account_name);
1984 if (data->plain_body == NULL || data->plain_body[0] == '\0') {
1985 GtkResponseType response;
1986 gchar *note_message;
1987 gchar *note_subject = data->subject;
1988 if (note_subject == NULL || note_subject[0] == '\0')
1989 note_subject = _("mail_va_no_subject");
1990 note_message = g_strdup_printf (_("emev_ni_ui_smtp_message_null"), note_subject);
1991 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (edit_window),
1993 g_free (note_message);
1994 if (response == GTK_RESPONSE_CANCEL) {
1995 g_free (account_name);
2000 modest_platform_information_banner (NULL, NULL, _("mcen_ib_outbox_waiting_to_be_sent"));
2002 /* Create the mail operation */
2003 ModestMailOperation *mail_operation = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_SEND, G_OBJECT(edit_window));
2004 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
2006 modest_mail_operation_send_new_mail (mail_operation,
2017 data->priority_flags);
2021 g_free (account_name);
2022 g_object_unref (G_OBJECT (transport_account));
2023 g_object_unref (G_OBJECT (mail_operation));
2025 modest_msg_edit_window_free_msg_data (edit_window, data);
2026 modest_msg_edit_window_set_sent (edit_window, TRUE);
2028 /* Save settings and close the window: */
2029 modest_ui_actions_on_close_window (NULL, MODEST_WINDOW (edit_window));
2033 modest_ui_actions_on_toggle_bold (GtkToggleAction *action,
2034 ModestMsgEditWindow *window)
2036 ModestMsgEditFormatState *format_state = NULL;
2038 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2039 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
2041 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2044 format_state = modest_msg_edit_window_get_format_state (window);
2045 g_return_if_fail (format_state != NULL);
2047 format_state->bold = gtk_toggle_action_get_active (action);
2048 modest_msg_edit_window_set_format_state (window, format_state);
2049 g_free (format_state);
2054 modest_ui_actions_on_toggle_italics (GtkToggleAction *action,
2055 ModestMsgEditWindow *window)
2057 ModestMsgEditFormatState *format_state = NULL;
2059 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2060 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
2062 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2065 format_state = modest_msg_edit_window_get_format_state (window);
2066 g_return_if_fail (format_state != NULL);
2068 format_state->italics = gtk_toggle_action_get_active (action);
2069 modest_msg_edit_window_set_format_state (window, format_state);
2070 g_free (format_state);
2075 modest_ui_actions_on_toggle_bullets (GtkToggleAction *action,
2076 ModestMsgEditWindow *window)
2078 ModestMsgEditFormatState *format_state = NULL;
2080 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2081 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
2083 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2086 format_state = modest_msg_edit_window_get_format_state (window);
2087 g_return_if_fail (format_state != NULL);
2089 format_state->bullet = gtk_toggle_action_get_active (action);
2090 modest_msg_edit_window_set_format_state (window, format_state);
2091 g_free (format_state);
2096 modest_ui_actions_on_change_justify (GtkRadioAction *action,
2097 GtkRadioAction *selected,
2098 ModestMsgEditWindow *window)
2100 ModestMsgEditFormatState *format_state = NULL;
2101 GtkJustification value;
2103 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2105 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2108 value = gtk_radio_action_get_current_value (selected);
2110 format_state = modest_msg_edit_window_get_format_state (window);
2111 g_return_if_fail (format_state != NULL);
2113 format_state->justification = value;
2114 modest_msg_edit_window_set_format_state (window, format_state);
2115 g_free (format_state);
2119 modest_ui_actions_on_select_editor_color (GtkAction *action,
2120 ModestMsgEditWindow *window)
2122 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2123 g_return_if_fail (GTK_IS_ACTION (action));
2125 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2128 modest_msg_edit_window_select_color (window);
2132 modest_ui_actions_on_select_editor_background_color (GtkAction *action,
2133 ModestMsgEditWindow *window)
2135 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2136 g_return_if_fail (GTK_IS_ACTION (action));
2138 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2141 modest_msg_edit_window_select_background_color (window);
2145 modest_ui_actions_on_insert_image (GtkAction *action,
2146 ModestMsgEditWindow *window)
2148 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2149 g_return_if_fail (GTK_IS_ACTION (action));
2151 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2154 modest_msg_edit_window_insert_image (window);
2158 modest_ui_actions_on_attach_file (GtkAction *action,
2159 ModestMsgEditWindow *window)
2161 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2162 g_return_if_fail (GTK_IS_ACTION (action));
2164 modest_msg_edit_window_offer_attach_file (window);
2168 modest_ui_actions_on_remove_attachments (GtkAction *action,
2169 ModestMsgEditWindow *window)
2171 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2172 g_return_if_fail (GTK_IS_ACTION (action));
2174 modest_msg_edit_window_remove_attachments (window, NULL);
2178 modest_ui_actions_new_folder_error_handler (ModestMailOperation *mail_op,
2181 ModestMainWindow *window = MODEST_MAIN_WINDOW (user_data);
2182 const GError *error = modest_mail_operation_get_error (mail_op);
2186 modest_platform_information_banner (GTK_WIDGET (window), NULL,
2187 modest_mail_operation_get_error (mail_op)->message);
2192 modest_ui_actions_create_folder(GtkWidget *parent_window,
2193 GtkWidget *folder_view)
2195 TnyFolderStore *parent_folder;
2197 parent_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
2199 if (parent_folder) {
2200 gboolean finished = FALSE;
2202 gchar *folder_name = NULL, *suggested_name = NULL;
2204 /* Run the new folder dialog */
2206 result = modest_platform_run_new_folder_dialog (GTK_WINDOW (parent_window),
2211 g_free (suggested_name);
2212 suggested_name = NULL;
2214 if (result == GTK_RESPONSE_REJECT) {
2217 ModestMailOperation *mail_op;
2218 TnyFolder *new_folder = NULL;
2220 mail_op = modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_INFO,
2221 G_OBJECT(parent_window),
2222 modest_ui_actions_new_folder_error_handler,
2225 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
2227 new_folder = modest_mail_operation_create_folder (mail_op,
2229 (const gchar *) folder_name);
2231 modest_folder_view_select_folder (MODEST_FOLDER_VIEW(folder_view),
2234 g_object_unref (new_folder);
2237 g_object_unref (mail_op);
2240 suggested_name = folder_name;
2244 g_object_unref (parent_folder);
2249 modest_ui_actions_on_new_folder (GtkAction *action, ModestMainWindow *main_window)
2251 GtkWidget *folder_view;
2253 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2255 folder_view = modest_main_window_get_child_widget (main_window,
2256 MODEST_WIDGET_TYPE_FOLDER_VIEW);
2260 modest_ui_actions_create_folder (GTK_WIDGET (main_window), folder_view);
2264 modest_ui_actions_rename_folder_error_handler (ModestMailOperation *mail_op,
2267 GObject *win = modest_mail_operation_get_source (mail_op);
2268 const GError *error = NULL;
2269 const gchar *message = NULL;
2271 /* Get error message */
2272 error = modest_mail_operation_get_error (mail_op);
2273 if (error != NULL && error->message != NULL) {
2274 message = error->message;
2276 message = _("!!! FIXME: Unable to rename");
2279 /* Show notification dialog */
2280 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL, message);
2281 g_object_unref (win);
2285 modest_ui_actions_on_rename_folder (GtkAction *action,
2286 ModestMainWindow *main_window)
2288 TnyFolderStore *folder;
2289 GtkWidget *folder_view;
2290 GtkWidget *header_view;
2292 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2294 folder_view = modest_main_window_get_child_widget (main_window,
2295 MODEST_WIDGET_TYPE_FOLDER_VIEW);
2299 header_view = modest_main_window_get_child_widget (main_window,
2300 MODEST_WIDGET_TYPE_HEADER_VIEW);
2305 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
2309 /* Offer the connection dialog if necessary: */
2310 if (!modest_platform_connect_and_wait_if_network_folderstore (NULL, folder)) {
2311 g_object_unref (G_OBJECT (folder));
2316 if (TNY_IS_FOLDER (folder)) {
2319 const gchar *current_name;
2321 current_name = tny_folder_get_name (TNY_FOLDER (folder));
2322 response = modest_platform_run_rename_folder_dialog (GTK_WINDOW (main_window), NULL,
2323 current_name, &folder_name);
2325 if (response == GTK_RESPONSE_ACCEPT && strlen (folder_name) > 0) {
2326 ModestMailOperation *mail_op;
2329 modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_INFO,
2330 G_OBJECT(main_window),
2331 modest_ui_actions_rename_folder_error_handler,
2335 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
2338 modest_header_view_clear (MODEST_HEADER_VIEW (header_view));
2340 modest_folder_view_select_folder (MODEST_FOLDER_VIEW(folder_view),
2341 TNY_FOLDER(folder), TRUE);
2344 modest_header_view_clear ((ModestHeaderView *) header_view);
2346 modest_mail_operation_rename_folder (mail_op,
2347 TNY_FOLDER (folder),
2348 (const gchar *) folder_name);
2350 g_object_unref (mail_op);
2351 g_free (folder_name);
2354 g_object_unref (folder);
2358 modest_ui_actions_delete_folder_error_handler (ModestMailOperation *mail_op,
2361 GObject *win = modest_mail_operation_get_source (mail_op);
2363 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
2364 _("mail_in_ui_folder_delete_error"));
2365 g_object_unref (win);
2369 delete_folder (ModestMainWindow *main_window, gboolean move_to_trash)
2371 TnyFolderStore *folder;
2372 GtkWidget *folder_view;
2376 g_return_if_fail (MODEST_IS_MAIN_WINDOW (main_window));
2378 folder_view = modest_main_window_get_child_widget (main_window,
2379 MODEST_WIDGET_TYPE_FOLDER_VIEW);
2383 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
2385 /* Show an error if it's an account */
2386 if (!TNY_IS_FOLDER (folder)) {
2387 modest_platform_run_information_dialog (GTK_WINDOW (main_window),
2388 _("mail_in_ui_folder_delete_error"));
2389 g_object_unref (G_OBJECT (folder));
2393 /* Offer the connection dialog if necessary: */
2394 if (!modest_platform_connect_and_wait_if_network_folderstore (NULL, folder)) {
2395 g_object_unref (G_OBJECT (folder));
2400 message = g_strdup_printf (_("mcen_nc_delete_folder_text"),
2401 tny_folder_get_name (TNY_FOLDER (folder)));
2402 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (main_window),
2403 (const gchar *) message);
2406 if (response == GTK_RESPONSE_OK) {
2407 ModestMailOperation *mail_op =
2408 modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_DELETE,
2409 G_OBJECT(main_window),
2410 modest_ui_actions_delete_folder_error_handler,
2413 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
2415 modest_mail_operation_remove_folder (mail_op, TNY_FOLDER (folder), move_to_trash);
2416 g_object_unref (G_OBJECT (mail_op));
2419 g_object_unref (G_OBJECT (folder));
2423 modest_ui_actions_on_delete_folder (GtkAction *action,
2424 ModestMainWindow *main_window)
2426 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2428 delete_folder (main_window, FALSE);
2432 modest_ui_actions_on_move_folder_to_trash_folder (GtkAction *action, ModestMainWindow *main_window)
2434 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2436 delete_folder (main_window, TRUE);
2441 show_error (GtkWidget *parent_widget, const gchar* text)
2443 hildon_banner_show_information(parent_widget, NULL, text);
2446 GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_window, text)); */
2448 GtkDialog *dialog = GTK_DIALOG (gtk_message_dialog_new (parent_window,
2455 gtk_dialog_run (dialog);
2456 gtk_widget_destroy (GTK_WIDGET (dialog));
2461 modest_ui_actions_on_password_requested (TnyAccountStore *account_store,
2462 const gchar* server_account_name,
2467 ModestMainWindow *main_window)
2469 g_return_if_fail(server_account_name);
2470 /* printf("DEBUG: %s: server_account_name=%s\n", __FUNCTION__, server_account_name); */
2472 /* Initalize output parameters: */
2479 #ifdef MODEST_PLATFORM_MAEMO
2480 /* Maemo uses a different (awkward) button order,
2481 * It should probably just use gtk_alternative_dialog_button_order ().
2483 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
2487 GTK_RESPONSE_ACCEPT,
2489 GTK_RESPONSE_REJECT,
2492 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
2496 GTK_RESPONSE_REJECT,
2498 GTK_RESPONSE_ACCEPT,
2500 #endif /* MODEST_PLATFORM_MAEMO */
2502 gtk_window_set_transient_for (GTK_WINDOW(dialog), GTK_WINDOW(main_window));
2504 gchar *server_name = modest_server_account_get_hostname (
2505 modest_runtime_get_account_mgr(), server_account_name);
2506 if (!server_name) {/* This happened once, though I don't know why. murrayc. */
2507 g_warning("%s: Could not get server name for server account '%s'", __FUNCTION__, server_account_name);
2512 /* This causes a warning because the logical ID has no %s in it,
2513 * though the translation does, but there is not much we can do about that: */
2514 gchar *txt = g_strdup_printf (_("mail_ia_password_info"), server_name);
2515 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), gtk_label_new(txt),
2518 g_free (server_name);
2522 gchar *initial_username = modest_server_account_get_username (
2523 modest_runtime_get_account_mgr(), server_account_name);
2525 GtkWidget *entry_username = gtk_entry_new ();
2526 if (initial_username)
2527 gtk_entry_set_text (GTK_ENTRY (entry_username), initial_username);
2528 /* Dim this if a connection has ever succeeded with this username,
2529 * as per the UI spec: */
2530 const gboolean username_known =
2531 modest_server_account_get_username_has_succeeded(
2532 modest_runtime_get_account_mgr(), server_account_name);
2533 gtk_widget_set_sensitive (entry_username, !username_known);
2535 #ifdef MODEST_PLATFORM_MAEMO
2536 /* Auto-capitalization is the default, so let's turn it off: */
2537 hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_username), HILDON_GTK_INPUT_MODE_FULL);
2539 /* Create a size group to be used by all captions.
2540 * Note that HildonCaption does not create a default size group if we do not specify one.
2541 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
2542 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
2544 GtkWidget *caption = hildon_caption_new (sizegroup,
2545 _("mail_fi_username"), entry_username, NULL, HILDON_CAPTION_MANDATORY);
2546 gtk_widget_show (entry_username);
2547 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
2548 FALSE, FALSE, MODEST_MARGIN_HALF);
2549 gtk_widget_show (caption);
2551 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry_username,
2553 #endif /* MODEST_PLATFORM_MAEMO */
2556 GtkWidget *entry_password = gtk_entry_new ();
2557 gtk_entry_set_visibility (GTK_ENTRY(entry_password), FALSE);
2558 /* gtk_entry_set_invisible_char (GTK_ENTRY(entry_password), "*"); */
2560 #ifdef MODEST_PLATFORM_MAEMO
2561 /* Auto-capitalization is the default, so let's turn it off: */
2562 hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_password),
2563 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
2565 caption = hildon_caption_new (sizegroup,
2566 _("mail_fi_password"), entry_password, NULL, HILDON_CAPTION_MANDATORY);
2567 gtk_widget_show (entry_password);
2568 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
2569 FALSE, FALSE, MODEST_MARGIN_HALF);
2570 gtk_widget_show (caption);
2571 g_object_unref (sizegroup);
2573 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry_password,
2575 #endif /* MODEST_PLATFORM_MAEMO */
2577 /* This is not in the Maemo UI spec:
2578 remember_pass_check = gtk_check_button_new_with_label (_("Remember password"));
2579 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), remember_pass_check,
2583 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
2585 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
2587 *username = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_username)));
2589 modest_server_account_set_username (
2590 modest_runtime_get_account_mgr(), server_account_name,
2593 const gboolean username_was_changed =
2594 (strcmp (*username, initial_username) != 0);
2595 if (username_was_changed) {
2596 g_warning ("%s: tinymail does not yet support changing the "
2597 "username in the get_password() callback.\n", __FUNCTION__);
2602 *password = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_password)));
2604 /* We do not save the password in the configuration,
2605 * because this function is only called for passwords that should
2606 * not be remembered:
2607 modest_server_account_set_password (
2608 modest_runtime_get_account_mgr(), server_account_name,
2617 show_error(GTK_WIDGET (main_window), _("mail_ib_login_cancelled"));
2629 /* This is not in the Maemo UI spec:
2630 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (remember_pass_check)))
2636 gtk_widget_destroy (dialog);
2638 /* printf ("DEBUG: %s: cancel=%d\n", __FUNCTION__, *cancel); */
2642 modest_ui_actions_on_cut (GtkAction *action,
2643 ModestWindow *window)
2645 GtkWidget *focused_widget;
2646 GtkClipboard *clipboard;
2648 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
2649 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
2650 if (GTK_IS_EDITABLE (focused_widget)) {
2651 gtk_editable_cut_clipboard (GTK_EDITABLE(focused_widget));
2652 gtk_clipboard_set_can_store (clipboard, NULL, 0);
2653 gtk_clipboard_store (clipboard);
2654 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
2655 GtkTextBuffer *buffer;
2657 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
2658 gtk_text_buffer_cut_clipboard (buffer, clipboard, TRUE);
2659 gtk_clipboard_set_can_store (clipboard, NULL, 0);
2660 gtk_clipboard_store (clipboard);
2661 } else if (MODEST_IS_HEADER_VIEW (focused_widget)) {
2662 modest_header_view_cut_selection (MODEST_HEADER_VIEW (focused_widget));
2663 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
2664 modest_folder_view_cut_selection (MODEST_FOLDER_VIEW (focused_widget));
2669 modest_ui_actions_on_copy (GtkAction *action,
2670 ModestWindow *window)
2672 GtkClipboard *clipboard;
2673 GtkWidget *focused_widget;
2675 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
2676 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
2678 if (GTK_IS_LABEL (focused_widget)) {
2679 gtk_clipboard_set_text (clipboard, gtk_label_get_text (GTK_LABEL (focused_widget)), -1);
2680 gtk_clipboard_set_can_store (clipboard, NULL, 0);
2681 gtk_clipboard_store (clipboard);
2682 } else if (GTK_IS_EDITABLE (focused_widget)) {
2683 gtk_editable_copy_clipboard (GTK_EDITABLE(focused_widget));
2684 gtk_clipboard_set_can_store (clipboard, NULL, 0);
2685 gtk_clipboard_store (clipboard);
2686 } else if (GTK_IS_HTML (focused_widget)) {
2687 gtk_html_copy (GTK_HTML (focused_widget));
2688 gtk_clipboard_set_can_store (clipboard, NULL, 0);
2689 gtk_clipboard_store (clipboard);
2690 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
2691 GtkTextBuffer *buffer;
2692 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
2693 gtk_text_buffer_copy_clipboard (buffer, clipboard);
2694 gtk_clipboard_set_can_store (clipboard, NULL, 0);
2695 gtk_clipboard_store (clipboard);
2696 } else if (MODEST_IS_HEADER_VIEW (focused_widget)) {
2697 TnyList *header_list = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW (focused_widget));
2698 TnyIterator *iter = tny_list_create_iterator (header_list);
2699 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter));
2701 gboolean ask = FALSE;
2703 TnyFolder *folder = tny_header_get_folder (header);
2704 TnyAccount *account = tny_folder_get_account (folder);
2705 const gchar *proto_str = tny_account_get_proto (TNY_ACCOUNT (account));
2706 /* If it's POP then ask */
2707 ask = (modest_protocol_info_get_transport_store_protocol (proto_str) ==
2708 MODEST_PROTOCOL_STORE_POP) ? TRUE : FALSE;
2709 g_object_unref (account);
2710 g_object_unref (folder);
2711 g_object_unref (header);
2714 g_object_unref (iter);
2716 /* Check that the messages have been previously downloaded */
2717 gboolean continue_download = TRUE;
2719 continue_download = download_uncached_messages (header_list, GTK_WINDOW (window), FALSE);
2720 if (continue_download)
2721 modest_header_view_copy_selection (MODEST_HEADER_VIEW (focused_widget));
2722 g_object_unref (header_list);
2723 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
2724 modest_folder_view_copy_selection (MODEST_FOLDER_VIEW (focused_widget));
2727 /* Show information banner */
2728 modest_platform_information_banner (NULL, NULL, _CS("ecoc_ib_edwin_copied"));
2733 modest_ui_actions_on_undo (GtkAction *action,
2734 ModestWindow *window)
2736 ModestEmailClipboard *clipboard = NULL;
2738 if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
2739 modest_msg_edit_window_undo (MODEST_MSG_EDIT_WINDOW (window));
2740 } else if (MODEST_IS_MAIN_WINDOW (window)) {
2741 /* Clear clipboard source */
2742 clipboard = modest_runtime_get_email_clipboard ();
2743 modest_email_clipboard_clear (clipboard);
2746 g_return_if_reached ();
2751 modest_ui_actions_on_redo (GtkAction *action,
2752 ModestWindow *window)
2754 if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
2755 modest_msg_edit_window_redo (MODEST_MSG_EDIT_WINDOW (window));
2758 g_return_if_reached ();
2764 paste_msgs_cb (const GObject *object, gpointer user_data)
2766 g_return_if_fail (MODEST_IS_MAIN_WINDOW (object));
2767 g_return_if_fail (GTK_IS_WIDGET (user_data));
2769 /* destroy information note */
2770 gtk_widget_destroy (GTK_WIDGET(user_data));
2774 paste_as_attachment_free (gpointer data)
2776 PasteAsAttachmentHelper *helper = (PasteAsAttachmentHelper *) data;
2778 gtk_widget_destroy (helper->banner);
2779 g_object_unref (helper->banner);
2784 paste_msg_as_attachment_cb (ModestMailOperation *mail_op,
2789 PasteAsAttachmentHelper *helper = (PasteAsAttachmentHelper *) userdata;
2790 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (helper->window));
2795 modest_msg_edit_window_add_part (MODEST_MSG_EDIT_WINDOW (helper->window), TNY_MIME_PART (msg));
2800 modest_ui_actions_on_paste (GtkAction *action,
2801 ModestWindow *window)
2803 GtkWidget *focused_widget = NULL;
2804 GtkWidget *inf_note = NULL;
2805 ModestMailOperation *mail_op = NULL;
2807 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
2808 if (GTK_IS_EDITABLE (focused_widget)) {
2809 gtk_editable_paste_clipboard (GTK_EDITABLE(focused_widget));
2810 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
2811 ModestEmailClipboard *e_clipboard = NULL;
2812 e_clipboard = modest_runtime_get_email_clipboard ();
2813 if (modest_email_clipboard_cleared (e_clipboard)) {
2814 GtkTextBuffer *buffer;
2815 GtkClipboard *clipboard;
2817 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
2818 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
2819 gtk_text_buffer_paste_clipboard (buffer, clipboard, NULL, TRUE);
2820 } else if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
2821 ModestMailOperation *mail_op;
2822 TnyFolder *src_folder;
2825 PasteAsAttachmentHelper *helper = g_new0 (PasteAsAttachmentHelper, 1);
2826 helper->window = MODEST_MSG_EDIT_WINDOW (window);
2827 helper->banner = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
2828 _CS("ckct_nw_pasting"));
2829 modest_email_clipboard_get_data (e_clipboard, &src_folder, &data, &delete);
2830 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_RECEIVE,
2832 if (helper->banner != NULL) {
2833 g_object_ref (G_OBJECT (helper->banner));
2834 gtk_window_set_modal (GTK_WINDOW (helper->banner), FALSE);
2835 gtk_widget_show (GTK_WIDGET (helper->banner));
2839 modest_mail_operation_get_msgs_full (mail_op,
2841 (GetMsgAsyncUserCallback) paste_msg_as_attachment_cb,
2843 paste_as_attachment_free);
2846 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
2847 ModestEmailClipboard *clipboard = NULL;
2848 TnyFolder *src_folder = NULL;
2849 TnyFolderStore *folder_store = NULL;
2850 TnyList *data = NULL;
2851 gboolean delete = FALSE;
2853 /* Check clipboard source */
2854 clipboard = modest_runtime_get_email_clipboard ();
2855 if (modest_email_clipboard_cleared (clipboard))
2858 /* Get elements to paste */
2859 modest_email_clipboard_get_data (clipboard, &src_folder, &data, &delete);
2861 /* Create a new mail operation */
2862 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_RECEIVE, G_OBJECT(window));
2863 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
2866 /* Get destination folder */
2867 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (focused_widget));
2869 /* Launch notification */
2870 inf_note = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
2871 _CS("ckct_nw_pasting"));
2872 if (inf_note != NULL) {
2873 gtk_window_set_modal (GTK_WINDOW(inf_note), FALSE);
2874 gtk_widget_show (GTK_WIDGET(inf_note));
2877 /* transfer messages */
2879 modest_mail_operation_xfer_msgs (mail_op,
2881 TNY_FOLDER (folder_store),
2886 } else if (src_folder != NULL) {
2887 modest_mail_operation_xfer_folder (mail_op,
2897 g_object_unref (data);
2898 if (src_folder != NULL)
2899 g_object_unref (src_folder);
2900 if (folder_store != NULL)
2901 g_object_unref (folder_store);
2907 modest_ui_actions_on_select_all (GtkAction *action,
2908 ModestWindow *window)
2910 GtkWidget *focused_widget;
2912 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
2913 if (MODEST_IS_ATTACHMENTS_VIEW (focused_widget)) {
2914 modest_attachments_view_select_all (MODEST_ATTACHMENTS_VIEW (focused_widget));
2915 } else if (GTK_IS_LABEL (focused_widget)) {
2916 gtk_label_select_region (GTK_LABEL (focused_widget), 0, -1);
2917 } else if (GTK_IS_EDITABLE (focused_widget)) {
2918 gtk_editable_select_region (GTK_EDITABLE(focused_widget), 0, -1);
2919 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
2920 GtkTextBuffer *buffer;
2921 GtkTextIter start, end;
2923 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
2924 gtk_text_buffer_get_start_iter (buffer, &start);
2925 gtk_text_buffer_get_end_iter (buffer, &end);
2926 gtk_text_buffer_select_range (buffer, &start, &end);
2927 } else if (GTK_IS_HTML (focused_widget)) {
2928 gtk_html_select_all (GTK_HTML (focused_widget));
2929 } else if (MODEST_IS_MAIN_WINDOW (window)) {
2930 GtkWidget *header_view = focused_widget;
2931 GtkTreeSelection *selection = NULL;
2933 if (!(MODEST_IS_HEADER_VIEW (focused_widget)))
2934 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (window),
2935 MODEST_WIDGET_TYPE_HEADER_VIEW);
2937 /* Select all messages */
2938 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(header_view));
2939 gtk_tree_selection_select_all (selection);
2941 /* Set focuse on header view */
2942 gtk_widget_grab_focus (header_view);
2948 modest_ui_actions_on_mark_as_read (GtkAction *action,
2949 ModestWindow *window)
2951 g_return_if_fail (MODEST_IS_WINDOW(window));
2953 /* Mark each header as read */
2954 do_headers_action (window, headers_action_mark_as_read, NULL);
2958 modest_ui_actions_on_mark_as_unread (GtkAction *action,
2959 ModestWindow *window)
2961 g_return_if_fail (MODEST_IS_WINDOW(window));
2963 /* Mark each header as read */
2964 do_headers_action (window, headers_action_mark_as_unread, NULL);
2968 modest_ui_actions_on_change_zoom (GtkRadioAction *action,
2969 GtkRadioAction *selected,
2970 ModestWindow *window)
2974 value = gtk_radio_action_get_current_value (selected);
2975 if (MODEST_IS_WINDOW (window)) {
2976 modest_window_set_zoom (MODEST_WINDOW (window), ((gdouble)value)/100);
2980 void modest_ui_actions_msg_edit_on_change_priority (GtkRadioAction *action,
2981 GtkRadioAction *selected,
2982 ModestWindow *window)
2984 TnyHeaderFlags flags;
2985 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2987 flags = gtk_radio_action_get_current_value (selected);
2988 modest_msg_edit_window_set_priority_flags (MODEST_MSG_EDIT_WINDOW (window), flags);
2991 void modest_ui_actions_msg_edit_on_change_file_format (GtkRadioAction *action,
2992 GtkRadioAction *selected,
2993 ModestWindow *window)
2997 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2999 file_format = gtk_radio_action_get_current_value (selected);
3000 modest_msg_edit_window_set_file_format (MODEST_MSG_EDIT_WINDOW (window), file_format);
3005 modest_ui_actions_on_zoom_plus (GtkAction *action,
3006 ModestWindow *window)
3008 g_return_if_fail (MODEST_IS_WINDOW (window));
3010 modest_window_zoom_plus (MODEST_WINDOW (window));
3014 modest_ui_actions_on_zoom_minus (GtkAction *action,
3015 ModestWindow *window)
3017 g_return_if_fail (MODEST_IS_WINDOW (window));
3019 modest_window_zoom_minus (MODEST_WINDOW (window));
3023 modest_ui_actions_on_toggle_fullscreen (GtkToggleAction *toggle,
3024 ModestWindow *window)
3026 ModestWindowMgr *mgr;
3027 gboolean fullscreen, active;
3028 g_return_if_fail (MODEST_IS_WINDOW (window));
3030 mgr = modest_runtime_get_window_mgr ();
3032 active = (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle)))?1:0;
3033 fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
3035 if (active != fullscreen) {
3036 modest_window_mgr_set_fullscreen_mode (mgr, active);
3037 gtk_window_present (GTK_WINDOW (window));
3042 modest_ui_actions_on_change_fullscreen (GtkAction *action,
3043 ModestWindow *window)
3045 ModestWindowMgr *mgr;
3046 gboolean fullscreen;
3048 g_return_if_fail (MODEST_IS_WINDOW (window));
3050 mgr = modest_runtime_get_window_mgr ();
3051 fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
3052 modest_window_mgr_set_fullscreen_mode (mgr, !fullscreen);
3054 gtk_window_present (GTK_WINDOW (window));
3058 * Used by modest_ui_actions_on_details to call do_headers_action
3061 headers_action_show_details (TnyHeader *header,
3062 ModestWindow *window,
3069 dialog = modest_details_dialog_new_with_header (GTK_WINDOW (window), header);
3072 gtk_widget_show_all (dialog);
3073 gtk_dialog_run (GTK_DIALOG (dialog));
3075 gtk_widget_destroy (dialog);
3079 * Show the folder details in a ModestDetailsDialog widget
3082 show_folder_details (TnyFolder *folder,
3088 dialog = modest_details_dialog_new_with_folder (window, folder);
3091 gtk_widget_show_all (dialog);
3092 gtk_dialog_run (GTK_DIALOG (dialog));
3094 gtk_widget_destroy (dialog);
3098 * Show the header details in a ModestDetailsDialog widget
3101 modest_ui_actions_on_details (GtkAction *action,
3104 TnyList * headers_list;
3108 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
3111 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW (win));
3114 g_object_unref (msg);
3116 headers_list = get_selected_headers (win);
3120 iter = tny_list_create_iterator (headers_list);
3122 header = TNY_HEADER (tny_iterator_get_current (iter));
3124 headers_action_show_details (header, win, NULL);
3125 g_object_unref (header);
3128 g_object_unref (iter);
3129 g_object_unref (headers_list);
3131 } else if (MODEST_IS_MAIN_WINDOW (win)) {
3132 GtkWidget *folder_view, *header_view;
3134 /* Check which widget has the focus */
3135 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
3136 MODEST_WIDGET_TYPE_FOLDER_VIEW);
3137 if (gtk_widget_is_focus (folder_view)) {
3138 TnyFolderStore *folder_store
3139 = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
3140 if (!folder_store) {
3141 g_warning ("%s: No item was selected.\n", __FUNCTION__);
3144 /* Show only when it's a folder */
3145 /* This function should not be called for account items,
3146 * because we dim the menu item for them. */
3147 if (TNY_IS_FOLDER (folder_store)) {
3148 show_folder_details (TNY_FOLDER (folder_store), GTK_WINDOW (win));
3151 g_object_unref (folder_store);
3154 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
3155 MODEST_WIDGET_TYPE_HEADER_VIEW);
3156 /* Show details of each header */
3157 do_headers_action (win, headers_action_show_details, header_view);
3163 modest_ui_actions_on_toggle_show_cc (GtkToggleAction *toggle,
3164 ModestMsgEditWindow *window)
3166 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3168 modest_msg_edit_window_show_cc (window, gtk_toggle_action_get_active (toggle));
3172 modest_ui_actions_on_toggle_show_bcc (GtkToggleAction *toggle,
3173 ModestMsgEditWindow *window)
3175 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3177 modest_msg_edit_window_show_bcc (window, gtk_toggle_action_get_active (toggle));
3181 modest_ui_actions_toggle_folders_view (GtkAction *action,
3182 ModestMainWindow *main_window)
3184 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
3186 if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)))
3187 modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SPLIT);
3189 modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SIMPLE);
3193 modest_ui_actions_on_toggle_toolbar (GtkToggleAction *toggle,
3194 ModestWindow *window)
3196 gboolean active, fullscreen = FALSE;
3197 ModestWindowMgr *mgr;
3199 active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle));
3201 /* Check if we want to toggle the toolbar vuew in fullscreen
3203 if (!strcmp (gtk_action_get_name (GTK_ACTION (toggle)),
3204 "ViewShowToolbarFullScreen")) {
3208 /* Toggle toolbar */
3209 mgr = modest_runtime_get_window_mgr ();
3210 modest_window_mgr_show_toolbars (mgr, active, fullscreen);
3214 modest_ui_actions_msg_edit_on_select_font (GtkAction *action,
3215 ModestMsgEditWindow *window)
3217 modest_msg_edit_window_select_font (window);
3221 modest_ui_actions_on_folder_display_name_changed (ModestFolderView *folder_view,
3222 const gchar *display_name,
3225 /* Do not change the application name if the widget has not
3226 the focus. This callback could be called even if the folder
3227 view has not the focus, because the handled signal could be
3228 emitted when the folder view is redrawn */
3229 if (gtk_widget_is_focus (GTK_WIDGET (folder_view))) {
3231 gtk_window_set_title (window, display_name);
3233 gtk_window_set_title (window, " ");
3238 modest_ui_actions_on_select_contacts (GtkAction *action, ModestMsgEditWindow *window)
3240 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3241 modest_msg_edit_window_select_contacts (window);
3245 modest_ui_actions_on_check_names (GtkAction *action, ModestMsgEditWindow *window)
3247 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3248 modest_msg_edit_window_check_names (window, FALSE);
3252 create_move_to_dialog_on_new_folder(GtkWidget *button, gpointer user_data)
3254 modest_ui_actions_create_folder (gtk_widget_get_toplevel (button),
3255 GTK_WIDGET (user_data));
3259 create_move_to_dialog (GtkWindow *win,
3260 GtkWidget *folder_view,
3261 GtkWidget **tree_view)
3263 GtkWidget *dialog, *scroll;
3264 GtkWidget *new_button;
3266 dialog = gtk_dialog_new_with_buttons (_("mcen_ti_moveto_folders_title"),
3268 GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR | GTK_DIALOG_DESTROY_WITH_PARENT,
3271 gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_OK, GTK_RESPONSE_ACCEPT);
3272 /* We do this manually so GTK+ does not associate a response ID for
3274 new_button = gtk_button_new_from_stock (GTK_STOCK_NEW);
3275 gtk_box_pack_end (GTK_BOX (GTK_DIALOG (dialog)->action_area), new_button, FALSE, FALSE, 0);
3276 gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT);
3278 /* Create scrolled window */
3279 scroll = gtk_scrolled_window_new (NULL, NULL);
3280 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll),
3281 GTK_POLICY_AUTOMATIC,
3282 GTK_POLICY_AUTOMATIC);
3284 /* Create folder view */
3285 *tree_view = modest_platform_create_folder_view (NULL);
3287 g_signal_connect (G_OBJECT (new_button), "clicked", G_CALLBACK(create_move_to_dialog_on_new_folder), *tree_view);
3289 /* It could happen that we're trying to move a message from a
3290 window (msg window for example) after the main window was
3291 closed, so we can not just get the model of the folder
3293 if (MODEST_IS_FOLDER_VIEW (folder_view))
3294 gtk_tree_view_set_model (GTK_TREE_VIEW (*tree_view),
3295 gtk_tree_view_get_model (GTK_TREE_VIEW (folder_view)));
3297 modest_folder_view_update_model (MODEST_FOLDER_VIEW (*tree_view),
3298 TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()));
3300 modest_folder_view_show_non_move_folders (MODEST_FOLDER_VIEW (*tree_view), FALSE);
3302 gtk_container_add (GTK_CONTAINER (scroll), *tree_view);
3304 /* Add scroll to dialog */
3305 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
3306 scroll, TRUE, TRUE, 0);
3308 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
3309 gtk_window_set_default_size (GTK_WINDOW (dialog), 300, 300);
3315 * Returns TRUE if at least one of the headers of the list belongs to
3316 * a message that has been fully retrieved.
3319 has_retrieved_msgs (TnyList *list)
3322 gboolean found = FALSE;
3324 iter = tny_list_create_iterator (list);
3325 while (tny_iterator_is_done (iter) && !found) {
3327 TnyHeaderFlags flags = 0;
3329 header = TNY_HEADER (tny_iterator_get_current (iter));
3331 flags = tny_header_get_flags (header);
3332 if (!(flags & TNY_HEADER_FLAG_PARTIAL))
3335 g_object_unref (header);
3339 tny_iterator_next (iter);
3341 g_object_unref (iter);
3347 * Shows a confirmation dialog to the user when we're moving messages
3348 * from a remote server to the local storage. Returns the dialog
3349 * response. If it's other kind of movement the it always returns
3353 msgs_move_to_confirmation (GtkWindow *win,
3354 TnyFolder *dest_folder,
3357 gint response = GTK_RESPONSE_OK;
3359 /* If the destination is a local folder */
3360 if (modest_tny_folder_is_local_folder (dest_folder)) {
3361 TnyFolder *src_folder = NULL;
3362 TnyIterator *iter = NULL;
3363 TnyHeader *header = NULL;
3365 /* Get source folder */
3366 iter = tny_list_create_iterator (headers);
3367 header = TNY_HEADER (tny_iterator_get_current (iter));
3369 src_folder = tny_header_get_folder (header);
3370 g_object_unref (header);
3373 g_object_unref (iter);
3375 /* if no src_folder, message may be an attahcment */
3376 if (src_folder == NULL)
3377 return GTK_RESPONSE_CANCEL;
3379 /* If the source is a remote folder */
3380 if (!modest_tny_folder_is_local_folder (src_folder)) {
3381 const gchar *message;
3383 if (has_retrieved_msgs (headers))
3384 message = ngettext ("mcen_nc_move_retrieve", "mcen_nc_move_retrieves",
3385 tny_list_get_length (headers));
3387 message = ngettext ("mcen_nc_move_header", "mcen_nc_move_headers",
3388 tny_list_get_length (headers));
3390 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
3391 (const gchar *) message);
3394 g_object_unref (src_folder);
3403 transfer_msgs_from_viewer_cb (const GObject *object, gpointer user_data)
3405 ModestMsgViewWindow *self = NULL;
3407 g_return_if_fail (MODEST_IS_MSG_VIEW_WINDOW (object));
3408 self = MODEST_MSG_VIEW_WINDOW (object);
3410 if (!modest_msg_view_window_select_next_message (self))
3411 if (!modest_msg_view_window_select_previous_message (self))
3412 /* No more messages to view, so close this window */
3413 modest_ui_actions_on_close_window (NULL, MODEST_WINDOW(self));
3417 modest_ui_actions_move_folder_error_handler (ModestMailOperation *mail_op,
3420 GObject *win = modest_mail_operation_get_source (mail_op);
3421 const GError *error = NULL;
3422 const gchar *message = NULL;
3424 /* Get error message */
3425 error = modest_mail_operation_get_error (mail_op);
3426 if (error != NULL && error->message != NULL) {
3427 message = error->message;
3429 message = _("mail_in_ui_folder_move_target_error");
3432 /* Show notification dialog */
3433 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL, message);
3434 g_object_unref (win);
3438 modest_ui_actions_send_receive_error_handler (ModestMailOperation *mail_op,
3441 GObject *win = modest_mail_operation_get_source (mail_op);
3442 const GError *error = modest_mail_operation_get_error (mail_op);
3444 g_return_if_fail (error != NULL);
3445 if (error->message != NULL)
3446 g_printerr ("modest: %s\n", error->message);
3448 g_printerr ("modest: unkonw error on send&receive operation");
3450 /* Show error message */
3451 /* if (modest_mail_operation_get_id (mail_op) == MODEST_MAIL_OPERATION_TYPE_RECEIVE) */
3452 /* modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL, */
3453 /* _CS("sfil_ib_unable_to_receive")); */
3455 /* modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL, */
3456 /* _CS("sfil_ib_unable_to_send")); */
3457 g_object_unref (win);
3461 open_msg_for_purge_cb (ModestMailOperation *mail_op,
3468 gint pending_purges = 0;
3469 gboolean some_purged = FALSE;
3470 ModestWindow *win = MODEST_WINDOW (user_data);
3471 ModestWindowMgr *mgr = modest_runtime_get_window_mgr ();
3473 /* If there was any error */
3474 if (!modest_ui_actions_msg_retrieval_check (mail_op, header, msg)) {
3475 modest_window_mgr_unregister_header (mgr, header);
3479 /* Once the message has been retrieved for purging, we check if
3480 * it's all ok for purging */
3482 parts = tny_simple_list_new ();
3483 tny_mime_part_get_parts (TNY_MIME_PART (msg), parts);
3484 iter = tny_list_create_iterator (parts);
3486 while (!tny_iterator_is_done (iter)) {
3488 part = TNY_MIME_PART (tny_iterator_get_current (iter));
3489 if (part && (tny_mime_part_is_attachment (part) || TNY_IS_MSG (part))) {
3490 if (tny_mime_part_is_purged (part))
3497 g_object_unref (part);
3499 tny_iterator_next (iter);
3502 if (pending_purges>0) {
3504 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),_("mcen_nc_purge_file_text_inbox"));
3506 if (response == GTK_RESPONSE_OK) {
3507 modest_platform_information_banner (NULL, NULL, _("mcen_ib_removing_attachment"));
3508 tny_iterator_first (iter);
3509 while (!tny_iterator_is_done (iter)) {
3512 part = TNY_MIME_PART (tny_iterator_get_current (iter));
3513 if (part && (tny_mime_part_is_attachment (part) || TNY_IS_MSG (part)))
3514 tny_mime_part_set_purged (part);
3517 g_object_unref (part);
3519 tny_iterator_next (iter);
3522 tny_msg_rewrite_cache (msg);
3525 modest_platform_information_banner (NULL, NULL, _("mail_ib_attachment_already_purged"));
3528 /* remove attachments */
3529 tny_iterator_first (iter);
3530 while (!tny_iterator_is_done (iter)) {
3533 part = TNY_MIME_PART (tny_iterator_get_current (iter));
3535 /* One for the reference given by tny_iterator_get_current(): */
3536 g_object_unref (part);
3538 /* TODO: Is this meant to remove the attachment by doing another unref()?
3539 * Otherwise, this seems useless. */
3542 tny_iterator_next (iter);
3544 modest_window_mgr_unregister_header (mgr, header);
3546 g_object_unref (iter);
3547 g_object_unref (parts);
3551 modest_ui_actions_on_main_window_remove_attachments (GtkAction *action,
3552 ModestMainWindow *win)
3554 GtkWidget *header_view;
3555 TnyList *header_list;
3558 TnyHeaderFlags flags;
3559 ModestWindow *msg_view_window = NULL;
3562 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win));
3564 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
3565 MODEST_WIDGET_TYPE_HEADER_VIEW);
3567 header_list = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW (header_view));
3569 if (tny_list_get_length (header_list) == 1) {
3570 iter = tny_list_create_iterator (header_list);
3571 header = TNY_HEADER (tny_iterator_get_current (iter));
3572 g_object_unref (iter);
3577 found = modest_window_mgr_find_registered_header (modest_runtime_get_window_mgr (),
3578 header, &msg_view_window);
3579 flags = tny_header_get_flags (header);
3580 if (!(flags & TNY_HEADER_FLAG_CACHED))
3583 if (msg_view_window != NULL)
3584 modest_msg_view_window_remove_attachments (MODEST_MSG_VIEW_WINDOW (msg_view_window), TRUE);
3586 /* do nothing; uid was registered before, so window is probably on it's way */
3587 g_warning ("debug: header %p has already been registered", header);
3590 ModestMailOperation *mail_op = NULL;
3591 modest_window_mgr_register_header (modest_runtime_get_window_mgr (), header);
3592 mail_op = modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE,
3594 modest_ui_actions_get_msgs_full_error_handler,
3596 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
3597 modest_mail_operation_get_msg (mail_op, header, open_msg_for_purge_cb, win);
3599 g_object_unref (mail_op);
3602 g_object_unref (header);
3604 g_object_unref (header_list);
3608 * Utility function that transfer messages from both the main window
3609 * and the msg view window when using the "Move to" dialog
3612 modest_ui_actions_xfer_messages_from_move_to (TnyFolderStore *dst_folder,
3615 TnyList *headers = NULL;
3618 if (!TNY_IS_FOLDER (dst_folder)) {
3619 modest_platform_information_banner (GTK_WIDGET (win),
3621 _CS("ckdg_ib_unable_to_move_to_current_location"));
3625 /* Get selected headers */
3626 headers = get_selected_headers (MODEST_WINDOW (win));
3628 /* Ask for user confirmation */
3629 response = msgs_move_to_confirmation (GTK_WINDOW (win),
3630 TNY_FOLDER (dst_folder),
3633 /* Transfer messages */
3634 if (response == GTK_RESPONSE_OK) {
3635 ModestMailOperation *mail_op =
3636 modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE,
3638 modest_ui_actions_move_folder_error_handler,
3640 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
3643 modest_mail_operation_xfer_msgs (mail_op,
3645 TNY_FOLDER (dst_folder),
3647 (MODEST_IS_MSG_VIEW_WINDOW (win)) ? transfer_msgs_from_viewer_cb : NULL,
3650 g_object_unref (G_OBJECT (mail_op));
3652 g_object_unref (headers);
3657 * UI handler for the "Move to" action when invoked from the
3661 modest_ui_actions_on_main_window_move_to (GtkAction *action,
3662 GtkWidget *folder_view,
3663 TnyFolderStore *dst_folder,
3664 ModestMainWindow *win)
3666 GtkWidget *header_view = NULL;
3667 ModestMailOperation *mail_op = NULL;
3668 TnyFolderStore *src_folder;
3670 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win));
3672 /* Get the source folder */
3673 src_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
3675 /* Offer the connection dialog if necessary, if the source folder is in a networked account: */
3676 if (!modest_platform_connect_and_wait_if_network_folderstore (GTK_WINDOW (win),
3680 /* Get header view */
3682 modest_main_window_get_child_widget (win, MODEST_WIDGET_TYPE_HEADER_VIEW);
3684 /* Get folder or messages to transfer */
3685 if (gtk_widget_is_focus (folder_view)) {
3687 /* Allow only to transfer folders to the local root folder */
3688 if (TNY_IS_ACCOUNT (dst_folder) &&
3689 !MODEST_IS_TNY_LOCAL_FOLDERS_ACCOUNT (dst_folder))
3692 /* Clean folder on header view before moving it */
3693 modest_header_view_clear (MODEST_HEADER_VIEW (header_view));
3695 if (TNY_IS_FOLDER (src_folder)) {
3697 modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE,
3699 modest_ui_actions_move_folder_error_handler,
3701 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
3704 modest_mail_operation_xfer_folder (mail_op,
3705 TNY_FOLDER (src_folder),
3708 /* Unref mail operation */
3709 g_object_unref (G_OBJECT (mail_op));
3711 g_warning ("%s: src_folder is not a TnyFolder.\n", __FUNCTION__);
3713 } else if (gtk_widget_is_focus (header_view)) {
3714 /* Transfer messages */
3715 modest_ui_actions_xfer_messages_from_move_to (dst_folder, MODEST_WINDOW (win));
3720 g_object_unref (src_folder);
3725 * UI handler for the "Move to" action when invoked from the
3726 * ModestMsgViewWindow
3729 modest_ui_actions_on_msg_view_window_move_to (GtkAction *action,
3730 TnyFolderStore *dst_folder,
3731 ModestMsgViewWindow *win)
3733 TnyHeader *header = NULL;
3734 TnyFolder *src_folder;
3736 /* Create header list */
3737 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
3738 src_folder = tny_header_get_folder(header);
3739 g_object_unref (header);
3741 /* Transfer the message */
3742 if (modest_platform_connect_and_wait_if_network_folderstore (NULL, TNY_FOLDER_STORE (src_folder)))
3743 modest_ui_actions_xfer_messages_from_move_to (dst_folder, MODEST_WINDOW (win));
3745 g_object_unref (src_folder);
3749 modest_ui_actions_on_move_to (GtkAction *action,
3752 GtkWidget *dialog = NULL, *folder_view = NULL, *tree_view = NULL;
3754 TnyFolderStore *dst_folder = NULL;
3755 ModestMainWindow *main_window;
3757 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win) ||
3758 MODEST_IS_MSG_VIEW_WINDOW (win));
3760 /* Get the main window if exists */
3761 if (MODEST_IS_MAIN_WINDOW (win))
3762 main_window = MODEST_MAIN_WINDOW (win);
3765 MODEST_MAIN_WINDOW (modest_window_mgr_get_main_window (modest_runtime_get_window_mgr ()));
3767 /* Get the folder view widget if exists */
3769 folder_view = modest_main_window_get_child_widget (main_window,
3770 MODEST_WIDGET_TYPE_FOLDER_VIEW);
3774 /* Create and run the dialog */
3775 dialog = create_move_to_dialog (GTK_WINDOW (win), folder_view, &tree_view);
3776 modest_folder_view_select_first_inbox_or_local (MODEST_FOLDER_VIEW (tree_view));
3777 result = gtk_dialog_run (GTK_DIALOG(dialog));
3778 g_object_ref (tree_view);
3779 gtk_widget_destroy (dialog);
3781 if (result != GTK_RESPONSE_ACCEPT)
3784 dst_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (tree_view));
3785 /* Offer the connection dialog if necessary: */
3786 if (modest_platform_connect_and_wait_if_network_folderstore (GTK_WINDOW (win),
3789 /* Do window specific stuff */
3790 if (MODEST_IS_MAIN_WINDOW (win))
3791 modest_ui_actions_on_main_window_move_to (action,
3794 MODEST_MAIN_WINDOW (win));
3796 modest_ui_actions_on_msg_view_window_move_to (action,
3798 MODEST_MSG_VIEW_WINDOW (win));
3801 g_object_unref (dst_folder);
3805 * Calls #HeadersFunc for each header already selected in the main
3806 * window or the message currently being shown in the msg view window
3809 do_headers_action (ModestWindow *win,
3813 TnyList *headers_list = NULL;
3814 TnyIterator *iter = NULL;
3815 TnyHeader *header = NULL;
3816 TnyFolder *folder = NULL;
3819 headers_list = get_selected_headers (win);
3823 /* Get the folder */
3824 iter = tny_list_create_iterator (headers_list);
3825 header = TNY_HEADER (tny_iterator_get_current (iter));
3827 folder = tny_header_get_folder (header);
3828 g_object_unref (header);
3831 /* Call the function for each header */
3832 while (!tny_iterator_is_done (iter)) {
3833 header = TNY_HEADER (tny_iterator_get_current (iter));
3834 func (header, win, user_data);
3835 g_object_unref (header);
3836 tny_iterator_next (iter);
3839 /* Trick: do a poke status in order to speed up the signaling
3841 tny_folder_poke_status (folder);
3844 g_object_unref (folder);
3845 g_object_unref (iter);
3846 g_object_unref (headers_list);
3850 modest_ui_actions_view_attachment (GtkAction *action,
3851 ModestWindow *window)
3853 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
3854 modest_msg_view_window_view_attachment (MODEST_MSG_VIEW_WINDOW (window), NULL);
3856 /* not supported window for this action */
3857 g_return_if_reached ();
3862 modest_ui_actions_save_attachments (GtkAction *action,
3863 ModestWindow *window)
3865 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
3866 modest_msg_view_window_save_attachments (MODEST_MSG_VIEW_WINDOW (window), NULL);
3868 /* not supported window for this action */
3869 g_return_if_reached ();
3874 modest_ui_actions_remove_attachments (GtkAction *action,
3875 ModestWindow *window)
3877 if (MODEST_IS_MAIN_WINDOW (window)) {
3878 modest_ui_actions_on_main_window_remove_attachments (action, MODEST_MAIN_WINDOW (window));
3879 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
3880 modest_msg_view_window_remove_attachments (MODEST_MSG_VIEW_WINDOW (window), FALSE);
3882 /* not supported window for this action */
3883 g_return_if_reached ();
3888 modest_ui_actions_on_settings (GtkAction *action,
3893 dialog = modest_platform_get_global_settings_dialog ();
3894 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (win));
3895 gtk_widget_show_all (dialog);
3897 gtk_dialog_run (GTK_DIALOG (dialog));
3899 gtk_widget_destroy (dialog);
3903 modest_ui_actions_on_help (GtkAction *action,
3906 const gchar *help_id = NULL;
3908 if (MODEST_IS_MAIN_WINDOW (win)) {
3909 const gchar *action_name;
3910 action_name = gtk_action_get_name (action);
3912 if (!strcmp (action_name, "FolderViewCSMHelp") ||
3913 !strcmp (action_name, "HeaderViewCSMHelp")) {
3914 GtkWidget *folder_view;
3915 TnyFolderStore *folder_store;
3916 /* Get selected folder */
3917 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
3918 MODEST_WIDGET_TYPE_FOLDER_VIEW);
3919 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
3921 /* Switch help_id */
3922 if (TNY_IS_FOLDER (folder_store)) {
3923 switch (modest_tny_folder_guess_folder_type (TNY_FOLDER (folder_store))) {
3924 case TNY_FOLDER_TYPE_NORMAL:
3925 help_id = "applications_email_managefolders";
3927 case TNY_FOLDER_TYPE_INBOX:
3928 help_id = "applications_email_inbox";
3930 case TNY_FOLDER_TYPE_OUTBOX:
3931 help_id = "applications_email_outbox";
3933 case TNY_FOLDER_TYPE_SENT:
3934 help_id = "applications_email_sent";
3936 case TNY_FOLDER_TYPE_DRAFTS:
3937 help_id = "applications_email_drafts";
3939 case TNY_FOLDER_TYPE_ARCHIVE:
3940 help_id = "applications_email_managefolders";
3943 help_id = "applications_email_managefolders";
3946 help_id = "applications_email_mainview";
3948 g_object_unref (folder_store);
3950 help_id = "applications_email_mainview";
3952 } else if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
3953 help_id = "applications_email_viewer";
3954 } else if (MODEST_IS_MSG_EDIT_WINDOW (win))
3955 help_id = "applications_email_editor";
3957 modest_platform_show_help (GTK_WINDOW (win), help_id);
3961 modest_ui_actions_on_retrieve_msg_contents (GtkAction *action,
3962 ModestWindow *window)
3964 ModestMailOperation *mail_op;
3968 headers = get_selected_headers (window);
3972 /* Create mail operation */
3973 mail_op = modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE,
3975 modest_ui_actions_get_msgs_full_error_handler,
3977 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
3978 modest_mail_operation_get_msgs_full (mail_op, headers, NULL, NULL, NULL);
3981 g_object_unref (headers);
3982 g_object_unref (mail_op);
3986 modest_ui_actions_on_email_menu_activated (GtkAction *action,
3987 ModestWindow *window)
3989 g_return_if_fail (MODEST_IS_WINDOW (window));
3992 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
3996 modest_ui_actions_on_edit_menu_activated (GtkAction *action,
3997 ModestWindow *window)
3999 g_return_if_fail (MODEST_IS_WINDOW (window));
4002 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4006 modest_ui_actions_on_view_menu_activated (GtkAction *action,
4007 ModestWindow *window)
4009 g_return_if_fail (MODEST_IS_WINDOW (window));
4012 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4016 modest_ui_actions_on_tools_menu_activated (GtkAction *action,
4017 ModestWindow *window)
4019 g_return_if_fail (MODEST_IS_WINDOW (window));
4022 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4026 modest_ui_actions_on_attachment_menu_activated (GtkAction *action,
4027 ModestWindow *window)
4029 g_return_if_fail (MODEST_IS_WINDOW (window));
4032 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4036 modest_ui_actions_on_toolbar_csm_menu_activated (GtkAction *action,
4037 ModestWindow *window)
4039 g_return_if_fail (MODEST_IS_WINDOW (window));
4042 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4046 modest_ui_actions_on_folder_view_csm_menu_activated (GtkAction *action,
4047 ModestWindow *window)
4049 g_return_if_fail (MODEST_IS_WINDOW (window));
4052 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4056 modest_ui_actions_on_header_view_csm_menu_activated (GtkAction *action,
4057 ModestWindow *window)
4059 g_return_if_fail (MODEST_IS_WINDOW (window));
4062 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
4066 modest_ui_actions_check_toolbar_dimming_rules (ModestWindow *window)
4068 g_return_if_fail (MODEST_IS_WINDOW (window));
4071 modest_window_check_dimming_rules_group (window, "ModestToolbarDimmingRules");
4075 modest_ui_actions_on_search_messages (GtkAction *action, ModestWindow *window)
4077 g_return_if_fail (MODEST_IS_WINDOW (window));
4079 modest_platform_show_search_messages (GTK_WINDOW (window));
4083 modest_ui_actions_on_open_addressbook (GtkAction *action, ModestWindow *win)
4085 g_return_if_fail (MODEST_IS_WINDOW (win));
4086 modest_platform_show_addressbook (GTK_WINDOW (win));
4091 modest_ui_actions_on_toggle_find_in_page (GtkToggleAction *action,
4092 ModestWindow *window)
4094 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4096 modest_msg_edit_window_toggle_find_toolbar (MODEST_MSG_EDIT_WINDOW (window), gtk_toggle_action_get_active (action));
4100 _on_send_receive_progress_changed (ModestMailOperation *mail_op,
4101 ModestMailOperationState *state,
4104 g_return_if_fail (MODEST_IS_MAIN_WINDOW(user_data));
4106 /* Set send/receive operation finished */
4107 if (state->status != MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS)
4108 modest_main_window_notify_send_receive_completed (MODEST_MAIN_WINDOW(user_data));