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 #endif /* MODEST_PLATFORM_MAEMO */
54 #include "widgets/modest-ui-constants.h"
55 #include <widgets/modest-main-window.h>
56 #include <widgets/modest-msg-view-window.h>
57 #include <widgets/modest-account-view-window.h>
58 #include <widgets/modest-details-dialog.h>
59 #include <widgets/modest-attachments-view.h>
60 #include "widgets/modest-folder-view.h"
61 #include "widgets/modest-global-settings-dialog.h"
62 #include "modest-connection-specific-smtp-window.h"
63 #include "modest-account-mgr-helpers.h"
64 #include "modest-mail-operation.h"
65 #include "modest-text-utils.h"
67 #ifdef MODEST_HAVE_EASYSETUP
68 #include "easysetup/modest-easysetup-wizard.h"
69 #endif /* MODEST_HAVE_EASYSETUP */
71 #include <modest-widget-memory.h>
72 #include <tny-error.h>
73 #include <tny-simple-list.h>
74 #include <tny-msg-view.h>
75 #include <tny-device.h>
76 #include <tny-merge-folder.h>
78 #include <gtkhtml/gtkhtml.h>
80 typedef struct _GetMsgAsyncHelper {
82 ModestMailOperation *mail_op;
89 typedef enum _ReplyForwardAction {
95 typedef struct _ReplyForwardHelper {
96 guint reply_forward_type;
97 ReplyForwardAction action;
99 GtkWidget *parent_window;
100 } ReplyForwardHelper;
104 * The do_headers_action uses this kind of functions to perform some
105 * action to each member of a list of headers
107 typedef void (*HeadersFunc) (TnyHeader *header, ModestWindow *win, gpointer user_data);
109 static void do_headers_action (ModestWindow *win,
113 static void open_msg_cb (ModestMailOperation *mail_op,
118 static void reply_forward_cb (ModestMailOperation *mail_op,
123 static void reply_forward (ReplyForwardAction action, ModestWindow *win);
125 static void folder_refreshed_cb (ModestMailOperation *mail_op,
129 static void _on_send_receive_progress_changed (ModestMailOperation *mail_op,
130 ModestMailOperationState *state,
136 run_account_setup_wizard (ModestWindow *win)
138 ModestEasysetupWizardDialog *wizard;
140 g_return_if_fail (MODEST_IS_WINDOW(win));
142 wizard = modest_easysetup_wizard_dialog_new ();
143 gtk_window_set_transient_for (GTK_WINDOW (wizard), GTK_WINDOW (win));
144 gtk_dialog_run (GTK_DIALOG (wizard));
145 gtk_widget_destroy (GTK_WIDGET (wizard));
150 modest_ui_actions_on_about (GtkAction *action, ModestWindow *win)
153 const gchar *authors[] = {
154 "Dirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>",
157 about = gtk_about_dialog_new ();
158 gtk_about_dialog_set_name (GTK_ABOUT_DIALOG(about), PACKAGE_NAME);
159 gtk_about_dialog_set_version (GTK_ABOUT_DIALOG(about),PACKAGE_VERSION);
160 gtk_about_dialog_set_copyright (GTK_ABOUT_DIALOG(about),
161 _("Copyright (c) 2006, Nokia Corporation\n"
162 "All rights reserved."));
163 gtk_about_dialog_set_comments (GTK_ABOUT_DIALOG(about),
164 _("a modest e-mail client\n\n"
165 "design and implementation: Dirk-Jan C. Binnema\n"
166 "contributions from the fine people at KC and Ig\n"
167 "uses the tinymail email framework written by Philip van Hoof"));
168 gtk_about_dialog_set_authors (GTK_ABOUT_DIALOG(about), authors);
169 gtk_about_dialog_set_website (GTK_ABOUT_DIALOG(about), "http://modest.garage.maemo.org");
171 gtk_dialog_run (GTK_DIALOG (about));
172 gtk_widget_destroy(about);
176 * Gets the list of currently selected messages. If the win is the
177 * main window, then it returns a newly allocated list of the headers
178 * selected in the header view. If win is the msg view window, then
179 * the value returned is a list with just a single header.
181 * The caller of this funcion must free the list.
184 get_selected_headers (ModestWindow *win)
186 if (MODEST_IS_MAIN_WINDOW(win)) {
187 GtkWidget *header_view;
189 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
190 MODEST_WIDGET_TYPE_HEADER_VIEW);
191 return modest_header_view_get_selected_headers (MODEST_HEADER_VIEW(header_view));
193 } else if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
194 /* for MsgViewWindows, we simply return a list with one element */
196 TnyList *list = NULL;
198 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
199 if (header != NULL) {
200 list = tny_simple_list_new ();
201 tny_list_prepend (list, G_OBJECT(header));
202 g_object_unref (G_OBJECT(header));
212 headers_action_mark_as_read (TnyHeader *header,
216 TnyHeaderFlags flags;
218 g_return_if_fail (TNY_IS_HEADER(header));
220 flags = tny_header_get_flags (header);
221 if (flags & TNY_HEADER_FLAG_SEEN) return;
222 tny_header_set_flags (header, TNY_HEADER_FLAG_SEEN);
226 headers_action_mark_as_unread (TnyHeader *header,
230 TnyHeaderFlags flags;
232 g_return_if_fail (TNY_IS_HEADER(header));
234 flags = tny_header_get_flags (header);
235 if (flags & TNY_HEADER_FLAG_SEEN) {
236 tny_header_unset_flags (header, TNY_HEADER_FLAG_SEEN);
240 /** A convenience method, because deleting a message is
241 * otherwise complicated, and it's best to change it in one place
244 void modest_do_message_delete (TnyHeader *header, ModestWindow *win)
246 ModestMailOperation *mail_op = NULL;
247 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_DELETE,
248 win ? G_OBJECT(win) : NULL);
249 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
252 /* Always delete. TODO: Move to trash still not supported */
253 modest_mail_operation_remove_msg (mail_op, header, FALSE);
254 g_object_unref (G_OBJECT (mail_op));
258 headers_action_delete (TnyHeader *header,
262 modest_do_message_delete (header, win);
264 /* refilter treemodel to hide marked-as-deleted rows */
265 /* if (MODEST_IS_HEADER_VIEW (user_data)) */
266 /* modest_header_view_refilter (MODEST_HEADER_VIEW (user_data)); */
269 /** After deleing a message that is currently visible in a window,
270 * show the next message from the list, or close the window if there are no more messages.
272 void modest_ui_actions_refresh_message_window_after_delete (ModestMsgViewWindow* win)
274 /* Close msg view window or select next */
275 if (modest_msg_view_window_last_message_selected (win) &&
276 modest_msg_view_window_first_message_selected (win)) {
277 modest_ui_actions_on_close_window (NULL, MODEST_WINDOW (win));
279 modest_msg_view_window_select_next_message (win);
284 modest_ui_actions_on_delete_message (GtkAction *action, ModestWindow *win)
286 TnyList *header_list = NULL;
287 TnyIterator *iter = NULL;
288 TnyHeader *header = NULL;
289 gchar *message = NULL;
292 ModestWindowMgr *mgr;
293 GtkWidget *header_view = NULL;
295 g_return_if_fail (MODEST_IS_WINDOW(win));
297 /* Check first if the header view has the focus */
298 if (MODEST_IS_MAIN_WINDOW (win)) {
300 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
301 MODEST_WIDGET_TYPE_HEADER_VIEW);
302 if (!gtk_widget_is_focus (header_view))
306 header_list = get_selected_headers (win);
307 if (!header_list) return;
309 /* Check if any of the headers are already opened, or in the process of being opened */
310 if (MODEST_IS_MAIN_WINDOW (win)) {
312 iter = tny_list_create_iterator (header_list);
314 mgr = modest_runtime_get_window_mgr ();
315 while (!tny_iterator_is_done (iter) && !found) {
316 header = TNY_HEADER (tny_iterator_get_current (iter));
317 found = modest_window_mgr_find_registered_header (mgr, header, NULL);
318 g_object_unref (header);
319 tny_iterator_next (iter);
321 g_object_unref (iter);
326 num = g_strdup_printf ("%d", tny_list_get_length (header_list));
327 msg = g_strdup_printf (_("mcen_nc_unable_to_delete_n_messages"), num);
329 modest_platform_run_information_dialog (GTK_WINDOW (win), (const gchar *) msg);
333 g_object_unref (header_list);
339 if (tny_list_get_length(header_list) == 1) {
340 iter = tny_list_create_iterator (header_list);
341 header = TNY_HEADER (tny_iterator_get_current (iter));
342 desc = g_strdup_printf ("%s", tny_header_get_subject (header));
343 g_object_unref (header);
344 g_object_unref (iter);
346 message = g_strdup_printf(ngettext("emev_nc_delete_message", "emev_nc_delete_messages",
347 tny_list_get_length(header_list)), desc);
349 /* Confirmation dialog */
350 printf("DEBUG: %s\n", __FUNCTION__);
351 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
355 if (response == GTK_RESPONSE_OK) {
356 ModestWindow *main_window = NULL;
357 ModestWindowMgr *mgr = NULL;
358 GtkTreeModel *model = NULL;
359 GtkTreeSelection *sel = NULL;
360 GList *sel_list = NULL, *tmp = NULL;
361 GtkTreeRowReference *row_reference = NULL;
362 GtkTreePath *next_path = NULL;
364 /* Find last selected row */
365 if (MODEST_IS_MAIN_WINDOW (win)) {
366 model = gtk_tree_view_get_model (GTK_TREE_VIEW (header_view));
367 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
368 sel_list = gtk_tree_selection_get_selected_rows (sel, &model);
369 for (tmp=sel_list; tmp; tmp=tmp->next) {
370 if (tmp->next == NULL) {
371 next_path = gtk_tree_path_copy((GtkTreePath *) tmp->data);
372 gtk_tree_path_next (next_path);
373 row_reference = gtk_tree_row_reference_new (model, next_path);
374 gtk_tree_path_free (next_path);
379 /* Remove each header. If it's a view window header_view == NULL */
380 do_headers_action (win, headers_action_delete, header_view);
382 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
383 modest_ui_actions_refresh_message_window_after_delete (MODEST_MSG_VIEW_WINDOW (win));
385 /* Get main window */
386 mgr = modest_runtime_get_window_mgr ();
387 main_window = modest_window_mgr_get_main_window (mgr);
390 /* Move cursor to next row */
393 /* Select next row */
394 if (gtk_tree_row_reference_valid (row_reference)) {
395 next_path = gtk_tree_row_reference_get_path (row_reference);
396 gtk_tree_selection_select_path (sel, next_path);
397 gtk_tree_path_free (next_path);
399 if (row_reference != NULL)
400 gtk_tree_row_reference_free (row_reference);
403 /* Update toolbar dimming state */
404 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
407 g_list_foreach (sel_list, (GFunc) gtk_tree_path_free, NULL);
408 g_list_free (sel_list);
414 g_object_unref (header_list);
420 /* delete either message or folder, based on where we are */
422 modest_ui_actions_on_delete_message_or_folder (GtkAction *action, ModestWindow *win)
424 g_return_if_fail (MODEST_IS_WINDOW(win));
426 /* Check first if the header view has the focus */
427 if (MODEST_IS_MAIN_WINDOW (win)) {
429 w = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
430 MODEST_WIDGET_TYPE_FOLDER_VIEW);
431 if (gtk_widget_is_focus (w)) {
432 modest_ui_actions_on_delete_folder (action, MODEST_MAIN_WINDOW(win));
436 modest_ui_actions_on_delete_message (action, win);
442 modest_ui_actions_on_quit (GtkAction *action, ModestWindow *win)
444 #ifdef MODEST_PLATFORM_MAEMO
445 modest_osso_save_state();
446 #endif /* MODEST_PLATFORM_MAEMO */
448 g_debug ("closing down, clearing %d item(s) from operation queue",
449 modest_mail_operation_queue_num_elements
450 (modest_runtime_get_mail_operation_queue()));
452 /* cancel all outstanding operations */
453 modest_mail_operation_queue_cancel_all
454 (modest_runtime_get_mail_operation_queue());
456 g_debug ("queue has been cleared");
458 /* note: when modest-tny-account-store is finalized,
459 it will automatically set all network connections
466 modest_ui_actions_on_close_window (GtkAction *action, ModestWindow *win)
469 g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value);
471 /* if (MODEST_IS_MSG_VIEW_WINDOW (win)) { */
472 /* gtk_widget_destroy (GTK_WIDGET (win)); */
473 /* } else if (MODEST_IS_MSG_EDIT_WINDOW (win)) { */
474 /* gboolean ret_value; */
475 /* g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value); */
476 /* } else if (MODEST_IS_WINDOW (win)) { */
477 /* gtk_widget_destroy (GTK_WIDGET (win)); */
479 /* g_return_if_reached (); */
484 modest_ui_actions_on_add_to_contacts (GtkAction *action, ModestWindow *win)
486 GtkClipboard *clipboard = NULL;
487 gchar *selection = NULL;
489 clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
490 selection = gtk_clipboard_wait_for_text (clipboard);
492 /* Question: why is the clipboard being used here?
493 * It doesn't really make a lot of sense. */
497 modest_address_book_add_address (selection);
503 modest_ui_actions_on_accounts (GtkAction *action, ModestWindow *win)
505 /* This is currently only implemented for Maemo */
506 #ifdef MODEST_PLATFORM_MAEMO /* Defined in config.h */
507 if (!modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE)) {
508 run_account_setup_wizard (win);
511 /* Show the list of accounts: */
512 GtkDialog *account_win = GTK_DIALOG(modest_account_view_window_new ());
513 modest_maemo_show_dialog_and_forget (GTK_WINDOW (win), account_win);
516 GtkWidget *dialog, *label;
518 /* Create the widgets */
520 dialog = gtk_dialog_new_with_buttons ("Message",
522 GTK_DIALOG_DESTROY_WITH_PARENT,
526 label = gtk_label_new ("Hello World!");
528 /* Ensure that the dialog box is destroyed when the user responds. */
530 g_signal_connect_swapped (dialog, "response",
531 G_CALLBACK (gtk_widget_destroy),
534 /* Add the label, and show everything we've added to the dialog. */
536 gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox),
538 gtk_widget_show_all (dialog);
539 #endif /* MODEST_PLATFORM_MAEMO */
543 on_smtp_servers_window_hide (GtkWindow* window, gpointer user_data)
545 ModestWindow *main_window = MODEST_WINDOW (user_data);
547 /* Save any changes. */
548 modest_connection_specific_smtp_window_save_server_accounts (
549 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (window),
550 modest_window_get_active_account (main_window));
551 gtk_widget_destroy (GTK_WIDGET (window));
557 modest_ui_actions_on_smtp_servers (GtkAction *action, ModestWindow *win)
559 /* This is currently only implemented for Maemo,
560 * because it requires an API (libconic) to detect different connection
563 #ifdef MODEST_PLATFORM_MAEMO /* Defined in config.h */
565 /* Create the window if necessary: */
566 const gchar *active_account_name = modest_window_get_active_account (win);
568 /* TODO: Dim the menu item (not in the UI spec)? or show a warning,
569 * or show the default account?
570 * If we show the default account then the account name should be shown in
571 * the window when we show it. */
572 if (!active_account_name) {
573 g_warning ("%s: No account is active.", __FUNCTION__);
577 GtkWidget *specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
578 modest_connection_specific_smtp_window_fill_with_connections (
579 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (specific_window),
580 modest_runtime_get_account_mgr(),
581 active_account_name);
583 /* Show the window: */
584 gtk_window_set_transient_for (GTK_WINDOW (specific_window), GTK_WINDOW (win));
585 gtk_window_set_modal (GTK_WINDOW (specific_window), TRUE);
586 gtk_widget_show (specific_window);
588 /* Save changes when the window is hidden: */
589 g_signal_connect (specific_window, "hide",
590 G_CALLBACK (on_smtp_servers_window_hide), win);
591 #endif /* MODEST_PLATFORM_MAEMO */
595 modest_ui_actions_on_new_msg (GtkAction *action, ModestWindow *win)
597 ModestWindow *msg_win = NULL;
599 TnyFolder *folder = NULL;
600 gchar *account_name = NULL;
601 gchar *from_str = NULL;
602 /* GError *err = NULL; */
603 TnyAccount *account = NULL;
604 ModestWindowMgr *mgr;
605 gchar *signature = NULL, *blank_and_signature = NULL;
607 /* if there are no accounts yet, just show the wizard */
608 if (!modest_account_mgr_has_accounts (modest_runtime_get_account_mgr(), TRUE)) {
609 run_account_setup_wizard (win);
613 account_name = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr ());
615 account_name = g_strdup (modest_window_get_active_account (win));
617 g_printerr ("modest: no account found\n");
621 account = modest_tny_account_store_get_server_account (modest_runtime_get_account_store(),
623 TNY_ACCOUNT_TYPE_STORE);
625 g_printerr ("modest: failed to get tnyaccount for '%s'\n", account_name);
629 from_str = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(), account_name);
631 g_printerr ("modest: failed get from string for '%s'\n", account_name);
635 if (modest_account_mgr_get_bool (modest_runtime_get_account_mgr (), account_name,
636 MODEST_ACCOUNT_USE_SIGNATURE, FALSE)) {
637 signature = modest_account_mgr_get_string (modest_runtime_get_account_mgr (), account_name,
638 MODEST_ACCOUNT_SIGNATURE, FALSE);
639 blank_and_signature = g_strconcat ("\n", signature, NULL);
642 blank_and_signature = g_strdup ("");
645 msg = modest_tny_msg_new ("", from_str, "", "", "", blank_and_signature, NULL);
647 g_printerr ("modest: failed to create new msg\n");
651 folder = modest_tny_account_get_special_folder (account, TNY_FOLDER_TYPE_DRAFTS);
653 g_printerr ("modest: failed to find Drafts folder\n");
658 /* Create and register edit window */
659 /* This is destroyed by TOOD. */
660 msg_win = modest_msg_edit_window_new (msg, account_name);
661 mgr = modest_runtime_get_window_mgr ();
662 modest_window_mgr_register_window (mgr, msg_win);
665 gtk_window_set_transient_for (GTK_WINDOW (msg_win),
667 gtk_widget_show_all (GTK_WIDGET (msg_win));
670 g_free (account_name);
672 g_free (blank_and_signature);
674 g_object_unref (msg_win);
676 g_object_unref (G_OBJECT(account));
678 g_object_unref (G_OBJECT(msg));
680 g_object_unref (G_OBJECT(folder));
684 modest_ui_actions_msg_retrieval_check (ModestMailOperation *mail_op,
688 ModestMailOperationStatus status;
690 /* If there is no message or the operation was not successful */
691 status = modest_mail_operation_get_status (mail_op);
692 if (!msg || status != MODEST_MAIL_OPERATION_STATUS_SUCCESS) {
694 /* Remove the header from the preregistered uids */
695 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (),
705 open_msg_cb (ModestMailOperation *mail_op,
710 ModestWindowMgr *mgr = NULL;
711 ModestWindow *parent_win = NULL;
712 ModestWindow *win = NULL;
713 TnyFolderType folder_type = TNY_FOLDER_TYPE_UNKNOWN;
714 gchar *account = NULL;
717 /* Do nothing if there was any problem with the mail
718 operation. The error will be shown by the error_handler of
719 the mail operation */
720 if (!modest_ui_actions_msg_retrieval_check (mail_op, header, msg)) {
724 parent_win = (ModestWindow *) modest_mail_operation_get_source (mail_op);
725 folder = tny_header_get_folder (header);
727 /* Mark header as read */
728 headers_action_mark_as_read (header, MODEST_WINDOW(parent_win), NULL);
731 account = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
733 account = g_strdup (modest_window_get_active_account (MODEST_WINDOW (parent_win)));
735 /* Gets folder type (OUTBOX headers will be opened in edit window */
736 if (modest_tny_folder_is_local_folder (folder))
737 folder_type = modest_tny_folder_get_local_folder_type (folder);
739 /* If the header is in the drafts folder then open the editor,
740 else the message view window */
741 if (folder_type == TNY_FOLDER_TYPE_DRAFTS) {
742 /* we cannot edit without a valid account... */
743 if (!modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE)) {
744 run_account_setup_wizard(parent_win);
747 win = modest_msg_edit_window_new (msg, account);
749 gchar *uid = modest_tny_folder_get_header_unique_id (header);
751 if (MODEST_IS_MAIN_WINDOW (parent_win)) {
752 GtkWidget *header_view;
753 GtkTreeSelection *sel;
754 GList *sel_list = NULL;
757 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(parent_win),
758 MODEST_WIDGET_TYPE_HEADER_VIEW);
760 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
761 sel_list = gtk_tree_selection_get_selected_rows (sel, &model);
763 if (sel_list != NULL) {
764 GtkTreeRowReference *row_reference;
766 row_reference = gtk_tree_row_reference_new (model, (GtkTreePath *) sel_list->data);
767 g_list_foreach (sel_list, (GFunc) gtk_tree_path_free, NULL);
768 g_list_free (sel_list);
770 win = modest_msg_view_window_new_with_header_model (msg,
775 gtk_tree_row_reference_free (row_reference);
777 win = modest_msg_view_window_new (msg, account, (const gchar*) uid);
780 win = modest_msg_view_window_new (msg, account, (const gchar*) uid);
785 /* Register and show new window */
787 mgr = modest_runtime_get_window_mgr ();
788 modest_window_mgr_register_window (mgr, win);
789 g_object_unref (win);
790 gtk_window_set_transient_for (GTK_WINDOW (win), GTK_WINDOW (parent_win));
791 gtk_widget_show_all (GTK_WIDGET(win));
794 /* Update toolbar dimming state */
795 if (MODEST_IS_MAIN_WINDOW (parent_win)) {
796 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (parent_win));
802 g_object_unref (parent_win);
803 g_object_unref (folder);
807 modest_ui_actions_get_msgs_full_error_handler (ModestMailOperation *mail_op,
811 GObject *win = modest_mail_operation_get_source (mail_op);
813 error = modest_mail_operation_get_error (mail_op);
814 printf ("DEBUG: %s: Error: code=%d, text=%s\n", __FUNCTION__, error->code, error->message);
816 if (error->code == MODEST_MAIL_OPERATION_ERROR_MESSAGE_SIZE_LIMIT) {
818 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
821 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
822 _("mail_ni_ui_folder_get_msg_folder_error"));
826 g_object_unref (win);
830 * This function is used by both modest_ui_actions_on_open and
831 * modest_ui_actions_on_header_activated. This way we always do the
832 * same when trying to open messages.
835 _modest_ui_actions_open (TnyList *headers, ModestWindow *win)
837 ModestWindowMgr *mgr = NULL;
838 TnyIterator *iter = NULL;
839 ModestMailOperation *mail_op1 = NULL;
840 ModestMailOperation *mail_op2 = NULL;
841 TnyList *not_opened_headers = NULL;
842 TnyList *not_opened_cached_headers = NULL;
843 TnyHeaderFlags flags;
845 /* Look if we already have a message view for each header. If
846 true, then remove the header from the list of headers to
848 mgr = modest_runtime_get_window_mgr ();
849 iter = tny_list_create_iterator (headers);
850 not_opened_headers = tny_simple_list_new ();
851 not_opened_cached_headers = tny_simple_list_new ();
852 while (!tny_iterator_is_done (iter)) {
854 ModestWindow *window;
858 header = TNY_HEADER (tny_iterator_get_current (iter));
859 flags = tny_header_get_flags (header);
862 found = modest_window_mgr_find_registered_header (mgr, header, &window);
864 /* Do not open again the message and present the
865 window to the user */
868 gtk_window_present (GTK_WINDOW (window));
870 /* the header has been registered already, we don't do
871 * anything but wait for the window to come up*/
872 g_warning ("debug: header %p already registered, waiting for window",
875 if (!(flags & TNY_HEADER_FLAG_CACHED))
876 tny_list_append (not_opened_headers, G_OBJECT (header));
877 /* Check if msg has already been retreived */
879 tny_list_append (not_opened_cached_headers, G_OBJECT (header));
881 g_object_unref (header);
882 tny_iterator_next (iter);
884 g_object_unref (iter);
887 /* If some messages would have to be downloaded, ask the user to
888 * make a connection. It's generally easier to do this here (in the mainloop)
889 * than later in a thread:
891 if (tny_list_get_length (not_opened_cached_headers) > 0) {
892 gboolean connected = modest_platform_connect_and_wait (GTK_WINDOW (win), NULL);
894 /* Don't go further if a connection would be necessary but none is available: */
896 g_object_unref (not_opened_headers);
897 g_object_unref (not_opened_cached_headers);
902 /* Register the headers before actually creating the windows: */
903 TnyIterator *iter_not_opened = tny_list_create_iterator (not_opened_headers);
904 while (!tny_iterator_is_done (iter_not_opened)) {
905 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter_not_opened));
906 modest_window_mgr_register_header (mgr, header);
907 g_object_unref (header);
909 tny_iterator_next (iter_not_opened);
911 g_object_unref (iter_not_opened);
912 iter_not_opened = NULL;
914 TnyIterator *iter_cached = tny_list_create_iterator (not_opened_cached_headers);
915 while (!tny_iterator_is_done (iter_cached)) {
916 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter_cached));
917 modest_window_mgr_register_header (mgr, header);
918 g_object_unref (header);
920 tny_iterator_next (iter_cached);
922 g_object_unref (iter_cached);
926 /* Open each uncached message */
927 if (tny_list_get_length (not_opened_headers) > 0) {
928 mail_op1 = modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE,
930 modest_ui_actions_get_msgs_full_error_handler,
932 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op1);
933 if (tny_list_get_length (not_opened_headers) > 1) {
934 modest_mail_operation_get_msgs_full (mail_op1,
940 TnyIterator *iter = tny_list_create_iterator (not_opened_headers);
941 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter));
942 modest_mail_operation_get_msg (mail_op1, header, open_msg_cb, NULL);
943 g_object_unref (header);
944 g_object_unref (iter);
948 /* Open each cached message */
949 if (tny_list_get_length (not_opened_cached_headers) > 0) {
950 mail_op2 = modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE,
952 modest_ui_actions_get_msgs_full_error_handler,
954 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op2);
955 if (tny_list_get_length (not_opened_cached_headers) > 1) {
956 modest_mail_operation_get_msgs_full (mail_op2,
962 TnyIterator *iter = tny_list_create_iterator (not_opened_cached_headers);
963 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter));
964 modest_mail_operation_get_msg (mail_op2, header, open_msg_cb, NULL);
965 g_object_unref (header);
966 g_object_unref (iter);
971 if (not_opened_headers != NULL)
972 g_object_unref (not_opened_headers);
973 if (not_opened_cached_headers != NULL)
974 g_object_unref (not_opened_cached_headers);
976 g_object_unref (iter);
977 if (mail_op1 != NULL)
978 g_object_unref (mail_op1);
979 if (mail_op2 != NULL)
980 g_object_unref (mail_op2);
984 modest_ui_actions_on_open (GtkAction *action, ModestWindow *win)
989 headers = get_selected_headers (win);
994 _modest_ui_actions_open (headers, win);
996 g_object_unref(headers);
1001 free_reply_forward_helper (gpointer data)
1003 ReplyForwardHelper *helper;
1005 helper = (ReplyForwardHelper *) data;
1006 g_free (helper->account_name);
1007 g_slice_free (ReplyForwardHelper, helper);
1011 reply_forward_cb (ModestMailOperation *mail_op,
1017 ReplyForwardHelper *rf_helper;
1018 ModestWindow *msg_win = NULL;
1019 ModestEditType edit_type;
1021 TnyAccount *account = NULL;
1022 ModestWindowMgr *mgr = NULL;
1023 gchar *signature = NULL;
1025 /* If there was any error. The mail operation could be NULL,
1026 this means that we already have the message downloaded and
1027 that we didn't do a mail operation to retrieve it */
1028 if (mail_op && !modest_ui_actions_msg_retrieval_check (mail_op, header, msg))
1031 g_return_if_fail (user_data != NULL);
1032 rf_helper = (ReplyForwardHelper *) user_data;
1034 from = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(),
1035 rf_helper->account_name);
1036 if (modest_account_mgr_get_bool (modest_runtime_get_account_mgr(),
1037 rf_helper->account_name,
1038 MODEST_ACCOUNT_USE_SIGNATURE, FALSE)) {
1039 signature = modest_account_mgr_get_string (modest_runtime_get_account_mgr (),
1040 rf_helper->account_name,
1041 MODEST_ACCOUNT_SIGNATURE, FALSE);
1044 /* Create reply mail */
1045 switch (rf_helper->action) {
1048 modest_tny_msg_create_reply_msg (msg, from, signature,
1049 rf_helper->reply_forward_type,
1050 MODEST_TNY_MSG_REPLY_MODE_SENDER);
1052 case ACTION_REPLY_TO_ALL:
1054 modest_tny_msg_create_reply_msg (msg, from, signature, rf_helper->reply_forward_type,
1055 MODEST_TNY_MSG_REPLY_MODE_ALL);
1056 edit_type = MODEST_EDIT_TYPE_REPLY;
1058 case ACTION_FORWARD:
1060 modest_tny_msg_create_forward_msg (msg, from, signature, rf_helper->reply_forward_type);
1061 edit_type = MODEST_EDIT_TYPE_FORWARD;
1064 g_return_if_reached ();
1071 g_printerr ("modest: failed to create message\n");
1075 account = modest_tny_account_store_get_server_account (modest_runtime_get_account_store(),
1076 rf_helper->account_name,
1077 TNY_ACCOUNT_TYPE_STORE);
1079 g_printerr ("modest: failed to get tnyaccount for '%s'\n", rf_helper->account_name);
1083 /* Create and register the windows */
1084 msg_win = modest_msg_edit_window_new (new_msg, rf_helper->account_name);
1085 mgr = modest_runtime_get_window_mgr ();
1086 modest_window_mgr_register_window (mgr, msg_win);
1088 if (rf_helper->parent_window != NULL) {
1089 gdouble parent_zoom;
1091 parent_zoom = modest_window_get_zoom (MODEST_WINDOW (rf_helper->parent_window));
1092 modest_window_set_zoom (msg_win, parent_zoom);
1095 /* Show edit window */
1096 gtk_widget_show_all (GTK_WIDGET (msg_win));
1100 g_object_unref (msg_win);
1102 g_object_unref (G_OBJECT (new_msg));
1104 g_object_unref (G_OBJECT (account));
1105 /* g_object_unref (msg); */
1106 g_object_unref (header);
1107 free_reply_forward_helper (rf_helper);
1111 * Checks a list of headers. If any of them are not currently
1112 * downloaded (CACHED) then it asks the user for permission to
1115 * Returns FALSE if the user does not want to download the
1116 * messages. Returns TRUE if the user allowed the download or if all
1117 * of them are currently downloaded
1120 download_uncached_messages (TnyList *header_list, GtkWindow *win,
1125 gint uncached_messages = 0;
1127 iter = tny_list_create_iterator (header_list);
1128 while (!tny_iterator_is_done (iter)) {
1130 TnyHeaderFlags flags;
1132 header = TNY_HEADER (tny_iterator_get_current (iter));
1133 flags = tny_header_get_flags (header);
1134 /* TODO: is this the right flag?, it seems that some
1135 headers that have been previously downloaded do not
1137 if (! (flags & TNY_HEADER_FLAG_CACHED))
1138 uncached_messages ++;
1139 g_object_unref (header);
1140 tny_iterator_next (iter);
1142 g_object_unref (iter);
1144 /* Ask for user permission to download the messages */
1146 if (uncached_messages > 0) {
1147 GtkResponseType response;
1149 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
1150 _("emev_nc_include_original"));
1153 modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
1154 ngettext("mcen_nc_get_msg",
1156 uncached_messages));
1157 if (response == GTK_RESPONSE_CANCEL)
1160 /* If a download will be necessary, make sure that we have a connection: */
1161 retval = modest_platform_connect_and_wait(win, NULL);
1169 * Common code for the reply and forward actions
1172 reply_forward (ReplyForwardAction action, ModestWindow *win)
1174 ModestMailOperation *mail_op = NULL;
1175 TnyList *header_list = NULL;
1176 ReplyForwardHelper *rf_helper = NULL;
1177 guint reply_forward_type;
1178 gboolean continue_download;
1180 g_return_if_fail (MODEST_IS_WINDOW(win));
1182 /* we need an account when editing */
1183 if (!modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE)) {
1184 run_account_setup_wizard (win);
1188 header_list = get_selected_headers (win);
1192 /* Check that the messages have been previously downloaded */
1193 continue_download = download_uncached_messages (header_list, GTK_WINDOW (win), TRUE);
1194 if (!continue_download) {
1195 g_object_unref (header_list);
1199 reply_forward_type =
1200 modest_conf_get_int (modest_runtime_get_conf (),
1201 (action == ACTION_FORWARD) ? MODEST_CONF_FORWARD_TYPE : MODEST_CONF_REPLY_TYPE,
1203 /* We assume that we can only select messages of the
1204 same folder and that we reply all of them from the
1205 same account. In fact the interface currently only
1206 allows single selection */
1209 rf_helper = g_slice_new0 (ReplyForwardHelper);
1210 rf_helper->reply_forward_type = reply_forward_type;
1211 rf_helper->action = action;
1212 rf_helper->account_name = g_strdup (modest_window_get_active_account (win));
1214 if ((win != NULL) && (MODEST_IS_WINDOW (win)))
1215 rf_helper->parent_window = GTK_WIDGET (win);
1216 if (!rf_helper->account_name)
1217 rf_helper->account_name =
1218 modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
1220 if (MODEST_IS_MSG_VIEW_WINDOW(win)) {
1223 /* Get header and message. Do not free them here, the
1224 reply_forward_cb must do it */
1225 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW(win));
1226 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW(win));
1227 if (!msg || !header) {
1229 g_object_unref (msg);
1231 g_object_unref (header);
1232 g_printerr ("modest: no message found\n");
1235 reply_forward_cb (NULL, header, msg, rf_helper);
1241 /* Retrieve messages */
1242 mail_op = modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE,
1244 modest_ui_actions_get_msgs_full_error_handler,
1246 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
1248 /* Only reply/forward to one message */
1249 iter = tny_list_create_iterator (header_list);
1250 header = TNY_HEADER (tny_iterator_get_current (iter));
1251 g_object_unref (iter);
1253 modest_mail_operation_get_msg (mail_op,
1258 /* modest_mail_operation_get_msgs_full (mail_op, */
1260 /* reply_forward_cb, */
1262 /* free_reply_forward_helper); */
1265 g_object_unref(mail_op);
1269 g_object_unref (header_list);
1273 modest_ui_actions_on_reply (GtkAction *action, ModestWindow *win)
1275 g_return_if_fail (MODEST_IS_WINDOW(win));
1277 reply_forward (ACTION_REPLY, win);
1281 modest_ui_actions_on_forward (GtkAction *action, ModestWindow *win)
1283 g_return_if_fail (MODEST_IS_WINDOW(win));
1285 reply_forward (ACTION_FORWARD, win);
1289 modest_ui_actions_on_reply_all (GtkAction *action, ModestWindow *win)
1291 g_return_if_fail (MODEST_IS_WINDOW(win));
1293 reply_forward (ACTION_REPLY_TO_ALL, win);
1297 modest_ui_actions_on_next (GtkAction *action,
1298 ModestWindow *window)
1300 if (MODEST_IS_MAIN_WINDOW (window)) {
1301 GtkWidget *header_view;
1303 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
1304 MODEST_WIDGET_TYPE_HEADER_VIEW);
1308 modest_header_view_select_next (MODEST_HEADER_VIEW(header_view));
1309 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
1310 modest_msg_view_window_select_next_message (MODEST_MSG_VIEW_WINDOW (window));
1312 g_return_if_reached ();
1317 modest_ui_actions_on_prev (GtkAction *action,
1318 ModestWindow *window)
1320 g_return_if_fail (MODEST_IS_WINDOW(window));
1322 if (MODEST_IS_MAIN_WINDOW (window)) {
1323 GtkWidget *header_view;
1324 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
1325 MODEST_WIDGET_TYPE_HEADER_VIEW);
1329 modest_header_view_select_prev (MODEST_HEADER_VIEW(header_view));
1330 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
1331 modest_msg_view_window_select_previous_message (MODEST_MSG_VIEW_WINDOW (window));
1333 g_return_if_reached ();
1338 modest_ui_actions_on_sort (GtkAction *action,
1339 ModestWindow *window)
1341 g_return_if_fail (MODEST_IS_WINDOW(window));
1343 if (MODEST_IS_MAIN_WINDOW (window)) {
1344 GtkWidget *header_view;
1345 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
1346 MODEST_WIDGET_TYPE_HEADER_VIEW);
1350 /* Show sorting dialog */
1351 modest_platform_run_sort_dialog (GTK_WINDOW (window), MODEST_SORT_HEADERS);
1356 new_messages_arrived (ModestMailOperation *self,
1360 if (new_messages == 0)
1363 modest_platform_on_new_msg ();
1367 * This function performs the send & receive required actions. The
1368 * window is used to create the mail operation. Typically it should
1369 * always be the main window, but we pass it as argument in order to
1373 modest_ui_actions_do_send_receive (const gchar *account_name, ModestWindow *win)
1375 gchar *acc_name = NULL;
1376 ModestMailOperation *mail_op;
1378 /* If no account name was provided then get the current account, and if
1379 there is no current account then pick the default one: */
1380 if (!account_name) {
1381 acc_name = g_strdup (modest_window_get_active_account(win));
1383 acc_name = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
1385 g_printerr ("modest: cannot get default account\n");
1389 acc_name = g_strdup (account_name);
1392 /* Set send/receive operation in progress */
1393 modest_main_window_notify_send_receive_initied (MODEST_MAIN_WINDOW(win));
1395 mail_op = modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE,
1397 modest_ui_actions_send_receive_error_handler,
1400 g_signal_connect (G_OBJECT(mail_op), "progress-changed",
1401 G_CALLBACK (_on_send_receive_progress_changed),
1404 /* Send & receive. */
1405 /* TODO: The spec wants us to first do any pending deletions, before receiving. */
1406 /* Receive and then send. The operation is tagged initially as
1407 a receive operation because the account update performs a
1408 receive and then a send. The operation changes its type
1409 internally, so the progress objects will receive the proper
1410 progress information */
1411 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
1412 modest_mail_operation_update_account (mail_op, acc_name, new_messages_arrived, NULL);
1413 g_object_unref (G_OBJECT (mail_op));
1421 modest_ui_actions_do_cancel_send (const gchar *account_name,
1424 TnyTransportAccount *transport_account;
1425 TnySendQueue *send_queue = NULL;
1426 GError *error = NULL;
1428 /* Get transport account */
1430 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
1431 (modest_runtime_get_account_store(),
1433 TNY_ACCOUNT_TYPE_TRANSPORT));
1434 if (!transport_account) {
1435 g_printerr ("modest: no transport account found for '%s'\n", account_name);
1440 send_queue = TNY_SEND_QUEUE (modest_runtime_get_send_queue (transport_account));
1441 if (!TNY_IS_SEND_QUEUE(send_queue)) {
1442 g_set_error (&error, MODEST_MAIL_OPERATION_ERROR,
1443 MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND,
1444 "modest: could not find send queue for account\n");
1446 /* Keeep messages in outbox folder */
1447 tny_send_queue_cancel (send_queue, FALSE, &error);
1451 if (transport_account != NULL)
1452 g_object_unref (G_OBJECT (transport_account));
1456 modest_ui_actions_cancel_send_all (ModestWindow *win)
1458 GSList *account_names, *iter;
1460 account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
1463 iter = account_names;
1465 modest_ui_actions_do_cancel_send ((const char*) iter->data, win);
1466 iter = g_slist_next (iter);
1469 modest_account_mgr_free_account_names (account_names);
1470 account_names = NULL;
1474 modest_ui_actions_cancel_send (GtkAction *action, ModestWindow *win)
1477 /* Check if accounts exist */
1478 gboolean accounts_exist =
1479 modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
1481 /* If not, allow the user to create an account before trying to send/receive. */
1482 if (!accounts_exist)
1483 modest_ui_actions_on_accounts (NULL, win);
1485 /* Cancel all sending operaitons */
1486 modest_ui_actions_cancel_send_all (win);
1490 * Refreshes all accounts. This function will be used by automatic
1494 modest_ui_actions_do_send_receive_all (ModestWindow *win)
1496 GSList *account_names, *iter;
1498 account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
1501 iter = account_names;
1503 modest_ui_actions_do_send_receive ((const char*) iter->data, win);
1504 iter = g_slist_next (iter);
1507 modest_account_mgr_free_account_names (account_names);
1508 account_names = NULL;
1512 * Handler of the click on Send&Receive button in the main toolbar
1515 modest_ui_actions_on_send_receive (GtkAction *action, ModestWindow *win)
1517 /* Check if accounts exist */
1518 gboolean accounts_exist =
1519 modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
1521 /* If not, allow the user to create an account before trying to send/receive. */
1522 if (!accounts_exist)
1523 modest_ui_actions_on_accounts (NULL, win);
1525 /* Refresh currently selected folder. Note that if we only
1526 want to retrive the headers, then the refresh only will
1527 invoke a poke_status over all folders, i.e., only the
1528 total/unread count will be updated */
1529 if (MODEST_IS_MAIN_WINDOW (win)) {
1530 GtkWidget *header_view, *folder_view;
1531 TnyFolderStore *folder_store;
1533 /* Get folder and header view */
1535 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
1536 MODEST_WIDGET_TYPE_FOLDER_VIEW);
1538 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
1540 if (folder_store && TNY_IS_FOLDER (folder_store)) {
1542 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
1543 MODEST_WIDGET_TYPE_HEADER_VIEW);
1545 /* We do not need to set the contents style
1546 because it hasn't changed. We also do not
1547 need to save the widget status. Just force
1549 modest_header_view_set_folder (MODEST_HEADER_VIEW(header_view),
1550 TNY_FOLDER (folder_store),
1551 folder_refreshed_cb,
1552 MODEST_MAIN_WINDOW (win));
1556 g_object_unref (folder_store);
1559 /* Refresh the active account */
1560 modest_ui_actions_do_send_receive (NULL, win);
1565 modest_ui_actions_toggle_header_list_view (GtkAction *action, ModestMainWindow *main_window)
1568 GtkWidget *header_view;
1570 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1572 header_view = modest_main_window_get_child_widget (main_window,
1573 MODEST_WIDGET_TYPE_HEADER_VIEW);
1577 conf = modest_runtime_get_conf ();
1579 /* what is saved/restored is depending on the style; thus; we save with
1580 * old style, then update the style, and restore for this new style
1582 modest_widget_memory_save (conf, G_OBJECT(header_view), MODEST_CONF_HEADER_VIEW_KEY);
1584 if (modest_header_view_get_style
1585 (MODEST_HEADER_VIEW(header_view)) == MODEST_HEADER_VIEW_STYLE_DETAILS)
1586 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
1587 MODEST_HEADER_VIEW_STYLE_TWOLINES);
1589 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
1590 MODEST_HEADER_VIEW_STYLE_DETAILS);
1592 modest_widget_memory_restore (conf, G_OBJECT(header_view),
1593 MODEST_CONF_HEADER_VIEW_KEY);
1598 modest_ui_actions_on_header_selected (ModestHeaderView *header_view,
1600 ModestMainWindow *main_window)
1602 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1603 g_return_if_fail (MODEST_IS_HEADER_VIEW (header_view));
1605 /* If no header has been selected then exit */
1610 if (!gtk_widget_is_focus (GTK_WIDGET(header_view)))
1611 gtk_widget_grab_focus (GTK_WIDGET(header_view));
1613 /* Update Main window title */
1614 if (gtk_widget_is_focus (GTK_WIDGET(header_view))) {
1615 const gchar *subject = tny_header_get_subject (header);
1616 if (subject && strlen(subject) > 0)
1617 gtk_window_set_title (GTK_WINDOW (main_window), subject);
1619 gtk_window_set_title (GTK_WINDOW (main_window), _("mail_va_no_subject"));
1622 /* Update toolbar dimming state */
1623 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
1627 modest_ui_actions_on_header_activated (ModestHeaderView *header_view,
1629 ModestMainWindow *main_window)
1633 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1638 headers = tny_simple_list_new ();
1639 tny_list_prepend (headers, G_OBJECT (header));
1641 _modest_ui_actions_open (headers, MODEST_WINDOW (main_window));
1643 g_object_unref (headers);
1647 set_active_account_from_tny_account (TnyAccount *account,
1648 ModestWindow *window)
1650 const gchar *server_acc_name = tny_account_get_id (account);
1652 /* We need the TnyAccount provided by the
1653 account store because that is the one that
1654 knows the name of the Modest account */
1655 TnyAccount *modest_server_account = modest_server_account =
1656 modest_tny_account_store_get_tny_account_by (modest_runtime_get_account_store (),
1657 MODEST_TNY_ACCOUNT_STORE_QUERY_ID,
1660 const gchar *modest_acc_name =
1661 modest_tny_account_get_parent_modest_account_name_for_server_account (modest_server_account);
1662 modest_window_set_active_account (window, modest_acc_name);
1663 g_object_unref (modest_server_account);
1668 folder_refreshed_cb (ModestMailOperation *mail_op,
1672 ModestMainWindow *win = NULL;
1673 GtkWidget *header_view;
1674 TnyFolder *current_folder;
1676 g_return_if_fail (TNY_IS_FOLDER (folder));
1678 win = MODEST_MAIN_WINDOW (user_data);
1680 modest_main_window_get_child_widget(win, MODEST_WIDGET_TYPE_HEADER_VIEW);
1683 current_folder = modest_header_view_get_folder (MODEST_HEADER_VIEW (header_view));
1684 if (current_folder != NULL && folder != current_folder) {
1689 /* Check if folder is empty and set headers view contents style */
1690 if (tny_folder_get_all_count (folder) == 0) {
1691 printf ("DEBUG: %s: tny_folder_get_all_count() returned 0.\n", __FUNCTION__);
1692 modest_main_window_set_contents_style (win,
1693 MODEST_MAIN_WINDOW_CONTENTS_STYLE_EMPTY);
1695 printf ("DEBUG: %s: tny_folder_get_all_count() returned >0.\n", __FUNCTION__);
1700 modest_ui_actions_on_folder_selection_changed (ModestFolderView *folder_view,
1701 TnyFolderStore *folder_store,
1703 ModestMainWindow *main_window)
1706 GtkWidget *header_view;
1708 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1710 header_view = modest_main_window_get_child_widget(main_window,
1711 MODEST_WIDGET_TYPE_HEADER_VIEW);
1715 conf = modest_runtime_get_conf ();
1717 if (TNY_IS_ACCOUNT (folder_store)) {
1719 /* Update active account */
1720 set_active_account_from_tny_account (TNY_ACCOUNT (folder_store), MODEST_WINDOW (main_window));
1721 /* Show account details */
1722 modest_main_window_set_contents_style (main_window, MODEST_MAIN_WINDOW_CONTENTS_STYLE_DETAILS);
1725 if (TNY_IS_FOLDER (folder_store) && selected) {
1727 /* Update the active account */
1728 TnyAccount *account = modest_tny_folder_get_account (TNY_FOLDER (folder_store));
1730 set_active_account_from_tny_account (account, MODEST_WINDOW (main_window));
1731 g_object_unref (account);
1735 /* Set the header style by default, it could
1736 be changed later by the refresh callback to
1738 modest_main_window_set_contents_style (main_window,
1739 MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS);
1741 /* Set folder on header view. This function
1742 will call tny_folder_refresh_async so we
1743 pass a callback that will be called when
1744 finished. We use that callback to set the
1745 empty view if there are no messages */
1746 modest_header_view_set_folder (MODEST_HEADER_VIEW(header_view),
1747 TNY_FOLDER (folder_store),
1748 folder_refreshed_cb,
1751 /* Restore configuration. We need to do this
1752 *after* the set_folder because the widget
1753 memory asks the header view about its
1755 modest_widget_memory_restore (modest_runtime_get_conf (),
1756 G_OBJECT(header_view),
1757 MODEST_CONF_HEADER_VIEW_KEY);
1759 /* Update the active account */
1760 modest_window_set_active_account (MODEST_WINDOW (main_window), NULL);
1761 /* Save only if we're seeing headers */
1762 if (modest_main_window_get_contents_style (main_window) ==
1763 MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS)
1764 modest_widget_memory_save (conf, G_OBJECT (header_view),
1765 MODEST_CONF_HEADER_VIEW_KEY);
1766 modest_header_view_clear (MODEST_HEADER_VIEW(header_view));
1770 /* Update toolbar dimming state */
1771 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
1775 modest_ui_actions_on_item_not_found (ModestHeaderView *header_view,ModestItemType type,
1782 item = (type == MODEST_ITEM_TYPE_FOLDER) ? "folder" : "message";
1784 online = tny_device_is_online (modest_runtime_get_device());
1787 /* already online -- the item is simply not there... */
1788 dialog = gtk_message_dialog_new (GTK_WINDOW (win),
1790 GTK_MESSAGE_WARNING,
1792 _("The %s you selected cannot be found"),
1794 gtk_dialog_run (GTK_DIALOG(dialog));
1796 dialog = gtk_dialog_new_with_buttons (_("Connection requested"),
1800 GTK_RESPONSE_REJECT,
1802 GTK_RESPONSE_ACCEPT,
1804 txt = g_strdup_printf (_("This %s is not available in offline mode.\n"
1805 "Do you want to get online?"), item);
1806 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
1807 gtk_label_new (txt), FALSE, FALSE, 0);
1808 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
1811 gtk_window_set_default_size (GTK_WINDOW(dialog), 300, 300);
1812 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
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))
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_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);
2440 modest_ui_actions_on_password_requested (TnyAccountStore *account_store,
2441 const gchar* server_account_name,
2446 ModestMainWindow *main_window)
2448 g_return_if_fail(server_account_name);
2449 /* printf("DEBUG: %s: server_account_name=%s\n", __FUNCTION__, server_account_name); */
2451 /* Initalize output parameters: */
2458 #ifdef MODEST_PLATFORM_MAEMO
2459 /* Maemo uses a different (awkward) button order,
2460 * It should probably just use gtk_alternative_dialog_button_order ().
2462 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
2466 GTK_RESPONSE_ACCEPT,
2468 GTK_RESPONSE_REJECT,
2471 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
2475 GTK_RESPONSE_REJECT,
2477 GTK_RESPONSE_ACCEPT,
2479 #endif /* MODEST_PLATFORM_MAEMO */
2481 gtk_window_set_transient_for (GTK_WINDOW(dialog), GTK_WINDOW(main_window));
2483 gchar *server_name = modest_server_account_get_hostname (
2484 modest_runtime_get_account_mgr(), server_account_name);
2485 if (!server_name) {/* This happened once, though I don't know why. murrayc. */
2486 g_warning("%s: Could not get server name for server account '%s'", __FUNCTION__, server_account_name);
2491 /* This causes a warning because the logical ID has no %s in it,
2492 * though the translation does, but there is not much we can do about that: */
2493 gchar *txt = g_strdup_printf (_("mail_ia_password_info"), server_name);
2494 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), gtk_label_new(txt),
2497 g_free (server_name);
2501 gchar *initial_username = modest_server_account_get_username (
2502 modest_runtime_get_account_mgr(), server_account_name);
2504 GtkWidget *entry_username = gtk_entry_new ();
2505 if (initial_username)
2506 gtk_entry_set_text (GTK_ENTRY (entry_username), initial_username);
2507 /* Dim this if a connection has ever succeeded with this username,
2508 * as per the UI spec: */
2509 const gboolean username_known =
2510 modest_server_account_get_username_has_succeeded(
2511 modest_runtime_get_account_mgr(), server_account_name);
2512 gtk_widget_set_sensitive (entry_username, !username_known);
2514 #ifdef MODEST_PLATFORM_MAEMO
2515 /* Auto-capitalization is the default, so let's turn it off: */
2516 hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_username), HILDON_GTK_INPUT_MODE_FULL);
2518 /* Create a size group to be used by all captions.
2519 * Note that HildonCaption does not create a default size group if we do not specify one.
2520 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
2521 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
2523 GtkWidget *caption = hildon_caption_new (sizegroup,
2524 _("mail_fi_username"), entry_username, NULL, HILDON_CAPTION_MANDATORY);
2525 gtk_widget_show (entry_username);
2526 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
2527 FALSE, FALSE, MODEST_MARGIN_HALF);
2528 gtk_widget_show (caption);
2530 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry_username,
2532 #endif /* MODEST_PLATFORM_MAEMO */
2535 GtkWidget *entry_password = gtk_entry_new ();
2536 gtk_entry_set_visibility (GTK_ENTRY(entry_password), FALSE);
2537 /* gtk_entry_set_invisible_char (GTK_ENTRY(entry_password), "*"); */
2539 #ifdef MODEST_PLATFORM_MAEMO
2540 /* Auto-capitalization is the default, so let's turn it off: */
2541 hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_password),
2542 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
2544 caption = hildon_caption_new (sizegroup,
2545 _("mail_fi_password"), entry_password, NULL, HILDON_CAPTION_MANDATORY);
2546 gtk_widget_show (entry_password);
2547 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
2548 FALSE, FALSE, MODEST_MARGIN_HALF);
2549 gtk_widget_show (caption);
2550 g_object_unref (sizegroup);
2552 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry_password,
2554 #endif /* MODEST_PLATFORM_MAEMO */
2556 /* This is not in the Maemo UI spec:
2557 remember_pass_check = gtk_check_button_new_with_label (_("Remember password"));
2558 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), remember_pass_check,
2562 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
2564 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
2566 *username = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_username)));
2568 modest_server_account_set_username (
2569 modest_runtime_get_account_mgr(), server_account_name,
2572 const gboolean username_was_changed =
2573 (strcmp (*username, initial_username) != 0);
2574 if (username_was_changed) {
2575 g_warning ("%s: tinymail does not yet support changing the "
2576 "username in the get_password() callback.\n", __FUNCTION__);
2581 *password = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_password)));
2583 /* We do not save the password in the configuration,
2584 * because this function is only called for passwords that should
2585 * not be remembered:
2586 modest_server_account_set_password (
2587 modest_runtime_get_account_mgr(), server_account_name,
2606 /* This is not in the Maemo UI spec:
2607 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (remember_pass_check)))
2613 gtk_widget_destroy (dialog);
2615 /* printf ("DEBUG: %s: cancel=%d\n", __FUNCTION__, *cancel); */
2619 modest_ui_actions_on_cut (GtkAction *action,
2620 ModestWindow *window)
2622 GtkWidget *focused_widget;
2624 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
2625 if (GTK_IS_EDITABLE (focused_widget)) {
2626 gtk_editable_cut_clipboard (GTK_EDITABLE(focused_widget));
2627 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
2628 GtkTextBuffer *buffer;
2629 GtkClipboard *clipboard;
2631 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
2632 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
2633 gtk_text_buffer_cut_clipboard (buffer, clipboard, TRUE);
2634 gtk_clipboard_set_can_store (clipboard, NULL, 0);
2635 } else if (MODEST_IS_HEADER_VIEW (focused_widget)) {
2636 modest_header_view_cut_selection (MODEST_HEADER_VIEW (focused_widget));
2637 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
2638 modest_folder_view_cut_selection (MODEST_FOLDER_VIEW (focused_widget));
2643 modest_ui_actions_on_copy (GtkAction *action,
2644 ModestWindow *window)
2646 GtkClipboard *clipboard;
2647 GtkWidget *focused_widget;
2649 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
2650 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
2652 if (GTK_IS_LABEL (focused_widget)) {
2653 gtk_clipboard_set_text (clipboard, gtk_label_get_text (GTK_LABEL (focused_widget)), -1);
2654 } else if (GTK_IS_EDITABLE (focused_widget)) {
2655 gtk_editable_copy_clipboard (GTK_EDITABLE(focused_widget));
2656 } else if (GTK_IS_HTML (focused_widget)) {
2657 gtk_html_copy (GTK_HTML (focused_widget));
2658 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
2659 GtkTextBuffer *buffer;
2660 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
2661 gtk_text_buffer_copy_clipboard (buffer, clipboard);
2662 gtk_clipboard_set_can_store (clipboard, NULL, 0);
2663 } else if (MODEST_IS_HEADER_VIEW (focused_widget)) {
2664 TnyList *header_list = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW (focused_widget));
2665 TnyIterator *iter = tny_list_create_iterator (header_list);
2666 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter));
2667 TnyFolder *folder = tny_header_get_folder (header);
2668 TnyAccount *account = tny_folder_get_account (folder);
2669 const gchar *proto_str = tny_account_get_proto (TNY_ACCOUNT (account));
2670 /* If it's POP then ask */
2671 gboolean ask = (modest_protocol_info_get_transport_store_protocol (proto_str) ==
2672 MODEST_PROTOCOL_STORE_POP) ? TRUE : FALSE;
2673 g_object_unref (account);
2674 g_object_unref (folder);
2675 g_object_unref (header);
2676 g_object_unref (iter);
2678 /* Check that the messages have been previously downloaded */
2679 gboolean continue_download = TRUE;
2681 continue_download = download_uncached_messages (header_list, GTK_WINDOW (window), FALSE);
2682 if (continue_download)
2683 modest_header_view_copy_selection (MODEST_HEADER_VIEW (focused_widget));
2684 g_object_unref (header_list);
2685 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
2686 modest_folder_view_copy_selection (MODEST_FOLDER_VIEW (focused_widget));
2689 /* Show information banner */
2690 modest_platform_information_banner (NULL, NULL, _CS("ecoc_ib_edwin_copied"));
2695 modest_ui_actions_on_undo (GtkAction *action,
2696 ModestWindow *window)
2698 ModestEmailClipboard *clipboard = NULL;
2700 if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
2701 modest_msg_edit_window_undo (MODEST_MSG_EDIT_WINDOW (window));
2702 } else if (MODEST_IS_MAIN_WINDOW (window)) {
2703 /* Clear clipboard source */
2704 clipboard = modest_runtime_get_email_clipboard ();
2705 modest_email_clipboard_clear (clipboard);
2708 g_return_if_reached ();
2713 modest_ui_actions_on_redo (GtkAction *action,
2714 ModestWindow *window)
2716 if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
2717 modest_msg_edit_window_redo (MODEST_MSG_EDIT_WINDOW (window));
2720 g_return_if_reached ();
2726 paste_msgs_cb (const GObject *object, gpointer user_data)
2728 g_return_if_fail (MODEST_IS_MAIN_WINDOW (object));
2729 g_return_if_fail (GTK_IS_WIDGET (user_data));
2731 /* destroy information note */
2732 gtk_widget_destroy (GTK_WIDGET(user_data));
2736 modest_ui_actions_on_paste (GtkAction *action,
2737 ModestWindow *window)
2739 GtkWidget *focused_widget = NULL;
2740 GtkWidget *inf_note = NULL;
2741 ModestMailOperation *mail_op = NULL;
2743 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
2744 if (GTK_IS_EDITABLE (focused_widget)) {
2745 gtk_editable_paste_clipboard (GTK_EDITABLE(focused_widget));
2746 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
2747 GtkTextBuffer *buffer;
2748 GtkClipboard *clipboard;
2750 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
2751 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
2752 gtk_text_buffer_paste_clipboard (buffer, clipboard, NULL, TRUE);
2753 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
2754 ModestEmailClipboard *clipboard = NULL;
2755 TnyFolder *src_folder = NULL;
2756 TnyFolderStore *folder_store = NULL;
2757 TnyList *data = NULL;
2758 gboolean delete = FALSE;
2760 /* Check clipboard source */
2761 clipboard = modest_runtime_get_email_clipboard ();
2762 if (modest_email_clipboard_cleared (clipboard))
2765 /* Get elements to paste */
2766 modest_email_clipboard_get_data (clipboard, &src_folder, &data, &delete);
2768 /* Create a new mail operation */
2769 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_RECEIVE, G_OBJECT(window));
2770 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
2773 /* Get destination folder */
2774 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (focused_widget));
2776 /* Launch notification */
2777 inf_note = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
2778 _CS("ckct_nw_pasting"));
2779 if (inf_note != NULL) {
2780 gtk_window_set_modal (GTK_WINDOW(inf_note), FALSE);
2781 gtk_widget_show (GTK_WIDGET(inf_note));
2784 /* transfer messages */
2786 modest_mail_operation_xfer_msgs (mail_op,
2788 TNY_FOLDER (folder_store),
2793 } else if (src_folder != NULL) {
2794 modest_mail_operation_xfer_folder (mail_op,
2804 g_object_unref (data);
2805 if (src_folder != NULL)
2806 g_object_unref (src_folder);
2807 if (folder_store != NULL)
2808 g_object_unref (folder_store);
2814 modest_ui_actions_on_select_all (GtkAction *action,
2815 ModestWindow *window)
2817 GtkWidget *focused_widget;
2819 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
2820 if (MODEST_IS_ATTACHMENTS_VIEW (focused_widget)) {
2821 modest_attachments_view_select_all (MODEST_ATTACHMENTS_VIEW (focused_widget));
2822 } else if (GTK_IS_LABEL (focused_widget)) {
2823 gtk_label_select_region (GTK_LABEL (focused_widget), 0, -1);
2824 } else if (GTK_IS_EDITABLE (focused_widget)) {
2825 gtk_editable_select_region (GTK_EDITABLE(focused_widget), 0, -1);
2826 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
2827 GtkTextBuffer *buffer;
2828 GtkTextIter start, end;
2830 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
2831 gtk_text_buffer_get_start_iter (buffer, &start);
2832 gtk_text_buffer_get_end_iter (buffer, &end);
2833 gtk_text_buffer_select_range (buffer, &start, &end);
2834 } else if (GTK_IS_HTML (focused_widget)) {
2835 gtk_html_select_all (GTK_HTML (focused_widget));
2836 } else if (MODEST_IS_MAIN_WINDOW (window)) {
2837 GtkWidget *header_view = focused_widget;
2838 GtkTreeSelection *selection = NULL;
2840 if (!(MODEST_IS_HEADER_VIEW (focused_widget)))
2841 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (window),
2842 MODEST_WIDGET_TYPE_HEADER_VIEW);
2844 /* Select all messages */
2845 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(header_view));
2846 gtk_tree_selection_select_all (selection);
2848 /* Set focuse on header view */
2849 gtk_widget_grab_focus (header_view);
2855 modest_ui_actions_on_mark_as_read (GtkAction *action,
2856 ModestWindow *window)
2858 g_return_if_fail (MODEST_IS_WINDOW(window));
2860 /* Mark each header as read */
2861 do_headers_action (window, headers_action_mark_as_read, NULL);
2865 modest_ui_actions_on_mark_as_unread (GtkAction *action,
2866 ModestWindow *window)
2868 g_return_if_fail (MODEST_IS_WINDOW(window));
2870 /* Mark each header as read */
2871 do_headers_action (window, headers_action_mark_as_unread, NULL);
2875 modest_ui_actions_on_change_zoom (GtkRadioAction *action,
2876 GtkRadioAction *selected,
2877 ModestWindow *window)
2881 value = gtk_radio_action_get_current_value (selected);
2882 if (MODEST_IS_WINDOW (window)) {
2883 modest_window_set_zoom (MODEST_WINDOW (window), ((gdouble)value)/100);
2887 void modest_ui_actions_msg_edit_on_change_priority (GtkRadioAction *action,
2888 GtkRadioAction *selected,
2889 ModestWindow *window)
2891 TnyHeaderFlags flags;
2892 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2894 flags = gtk_radio_action_get_current_value (selected);
2895 modest_msg_edit_window_set_priority_flags (MODEST_MSG_EDIT_WINDOW (window), flags);
2898 void modest_ui_actions_msg_edit_on_change_file_format (GtkRadioAction *action,
2899 GtkRadioAction *selected,
2900 ModestWindow *window)
2904 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2906 file_format = gtk_radio_action_get_current_value (selected);
2907 modest_msg_edit_window_set_file_format (MODEST_MSG_EDIT_WINDOW (window), file_format);
2912 modest_ui_actions_on_zoom_plus (GtkAction *action,
2913 ModestWindow *window)
2915 g_return_if_fail (MODEST_IS_WINDOW (window));
2917 modest_window_zoom_plus (MODEST_WINDOW (window));
2921 modest_ui_actions_on_zoom_minus (GtkAction *action,
2922 ModestWindow *window)
2924 g_return_if_fail (MODEST_IS_WINDOW (window));
2926 modest_window_zoom_minus (MODEST_WINDOW (window));
2930 modest_ui_actions_on_toggle_fullscreen (GtkToggleAction *toggle,
2931 ModestWindow *window)
2933 ModestWindowMgr *mgr;
2934 gboolean fullscreen, active;
2935 g_return_if_fail (MODEST_IS_WINDOW (window));
2937 mgr = modest_runtime_get_window_mgr ();
2939 active = (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle)))?1:0;
2940 fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
2942 if (active != fullscreen) {
2943 modest_window_mgr_set_fullscreen_mode (mgr, active);
2944 gtk_window_present (GTK_WINDOW (window));
2949 modest_ui_actions_on_change_fullscreen (GtkAction *action,
2950 ModestWindow *window)
2952 ModestWindowMgr *mgr;
2953 gboolean fullscreen;
2955 g_return_if_fail (MODEST_IS_WINDOW (window));
2957 mgr = modest_runtime_get_window_mgr ();
2958 fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
2959 modest_window_mgr_set_fullscreen_mode (mgr, !fullscreen);
2961 gtk_window_present (GTK_WINDOW (window));
2965 * Used by modest_ui_actions_on_details to call do_headers_action
2968 headers_action_show_details (TnyHeader *header,
2969 ModestWindow *window,
2976 dialog = modest_details_dialog_new_with_header (GTK_WINDOW (window), header);
2979 gtk_widget_show_all (dialog);
2980 gtk_dialog_run (GTK_DIALOG (dialog));
2982 gtk_widget_destroy (dialog);
2986 * Show the folder details in a ModestDetailsDialog widget
2989 show_folder_details (TnyFolder *folder,
2995 dialog = modest_details_dialog_new_with_folder (window, folder);
2998 gtk_widget_show_all (dialog);
2999 gtk_dialog_run (GTK_DIALOG (dialog));
3001 gtk_widget_destroy (dialog);
3005 * Show the header details in a ModestDetailsDialog widget
3008 modest_ui_actions_on_details (GtkAction *action,
3011 TnyList * headers_list;
3015 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
3018 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW (win));
3021 g_object_unref (msg);
3023 headers_list = get_selected_headers (win);
3027 iter = tny_list_create_iterator (headers_list);
3029 header = TNY_HEADER (tny_iterator_get_current (iter));
3030 headers_action_show_details (header, win, NULL);
3031 g_object_unref (header);
3033 g_object_unref (iter);
3034 g_object_unref (headers_list);
3036 } else if (MODEST_IS_MAIN_WINDOW (win)) {
3037 GtkWidget *folder_view, *header_view;
3039 /* Check which widget has the focus */
3040 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
3041 MODEST_WIDGET_TYPE_FOLDER_VIEW);
3042 if (gtk_widget_is_focus (folder_view)) {
3043 TnyFolderStore *folder_store
3044 = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
3045 if (!folder_store) {
3046 g_warning ("%s: No item was selected.\n", __FUNCTION__);
3049 /* Show only when it's a folder */
3050 /* This function should not be called for account items,
3051 * because we dim the menu item for them. */
3052 if (TNY_IS_FOLDER (folder_store)) {
3053 show_folder_details (TNY_FOLDER (folder_store), GTK_WINDOW (win));
3056 g_object_unref (folder_store);
3059 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
3060 MODEST_WIDGET_TYPE_HEADER_VIEW);
3061 /* Show details of each header */
3062 do_headers_action (win, headers_action_show_details, header_view);
3068 modest_ui_actions_on_toggle_show_cc (GtkToggleAction *toggle,
3069 ModestMsgEditWindow *window)
3071 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3073 modest_msg_edit_window_show_cc (window, gtk_toggle_action_get_active (toggle));
3077 modest_ui_actions_on_toggle_show_bcc (GtkToggleAction *toggle,
3078 ModestMsgEditWindow *window)
3080 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3082 modest_msg_edit_window_show_bcc (window, gtk_toggle_action_get_active (toggle));
3086 modest_ui_actions_toggle_folders_view (GtkAction *action,
3087 ModestMainWindow *main_window)
3089 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
3091 if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)))
3092 modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SPLIT);
3094 modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SIMPLE);
3098 modest_ui_actions_on_toggle_toolbar (GtkToggleAction *toggle,
3099 ModestWindow *window)
3101 gboolean active, fullscreen = FALSE;
3102 ModestWindowMgr *mgr;
3104 active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle));
3106 /* Check if we want to toggle the toolbar vuew in fullscreen
3108 if (!strcmp (gtk_action_get_name (GTK_ACTION (toggle)),
3109 "ViewShowToolbarFullScreen")) {
3113 /* Toggle toolbar */
3114 mgr = modest_runtime_get_window_mgr ();
3115 modest_window_mgr_show_toolbars (mgr, active, fullscreen);
3119 modest_ui_actions_msg_edit_on_select_font (GtkAction *action,
3120 ModestMsgEditWindow *window)
3122 modest_msg_edit_window_select_font (window);
3126 modest_ui_actions_on_folder_display_name_changed (ModestFolderView *folder_view,
3127 const gchar *display_name,
3130 /* Do not change the application name if the widget has not
3131 the focus. This callback could be called even if the folder
3132 view has not the focus, because the handled signal could be
3133 emitted when the folder view is redrawn */
3134 if (gtk_widget_is_focus (GTK_WIDGET (folder_view))) {
3136 gtk_window_set_title (window, display_name);
3138 gtk_window_set_title (window, " ");
3143 modest_ui_actions_on_select_contacts (GtkAction *action, ModestMsgEditWindow *window)
3145 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3146 modest_msg_edit_window_select_contacts (window);
3150 modest_ui_actions_on_check_names (GtkAction *action, ModestMsgEditWindow *window)
3152 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3153 modest_msg_edit_window_check_names (window);
3157 create_move_to_dialog_on_new_folder(GtkWidget *button, gpointer user_data)
3159 modest_ui_actions_create_folder (gtk_widget_get_toplevel (button),
3160 GTK_WIDGET (user_data));
3164 create_move_to_dialog (GtkWindow *win,
3165 GtkWidget *folder_view,
3166 GtkWidget **tree_view)
3168 GtkWidget *dialog, *scroll;
3169 GtkWidget *new_button;
3171 dialog = gtk_dialog_new_with_buttons (_("mcen_ti_moveto_folders_title"),
3173 GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR | GTK_DIALOG_DESTROY_WITH_PARENT,
3176 gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_OK, GTK_RESPONSE_ACCEPT);
3177 /* We do this manually so GTK+ does not associate a response ID for
3179 new_button = gtk_button_new_from_stock (GTK_STOCK_NEW);
3180 gtk_box_pack_end (GTK_BOX (GTK_DIALOG (dialog)->action_area), new_button, FALSE, FALSE, 0);
3181 gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT);
3183 /* Create scrolled window */
3184 scroll = gtk_scrolled_window_new (NULL, NULL);
3185 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll),
3186 GTK_POLICY_AUTOMATIC,
3187 GTK_POLICY_AUTOMATIC);
3189 /* Create folder view */
3190 *tree_view = modest_platform_create_folder_view (NULL);
3192 g_signal_connect (G_OBJECT (new_button), "clicked", G_CALLBACK(create_move_to_dialog_on_new_folder), *tree_view);
3194 /* It could happen that we're trying to move a message from a
3195 window (msg window for example) after the main window was
3196 closed, so we can not just get the model of the folder
3198 if (MODEST_IS_FOLDER_VIEW (folder_view))
3199 gtk_tree_view_set_model (GTK_TREE_VIEW (*tree_view),
3200 gtk_tree_view_get_model (GTK_TREE_VIEW (folder_view)));
3202 modest_folder_view_update_model (MODEST_FOLDER_VIEW (*tree_view),
3203 TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()));
3205 modest_folder_view_show_non_move_folders (MODEST_FOLDER_VIEW (*tree_view), FALSE);
3207 gtk_container_add (GTK_CONTAINER (scroll), *tree_view);
3209 /* Add scroll to dialog */
3210 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
3211 scroll, TRUE, TRUE, 0);
3213 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
3214 gtk_window_set_default_size (GTK_WINDOW (dialog), 300, 300);
3220 * Returns TRUE if at least one of the headers of the list belongs to
3221 * a message that has been fully retrieved.
3224 has_retrieved_msgs (TnyList *list)
3227 gboolean found = FALSE;
3229 iter = tny_list_create_iterator (list);
3230 while (tny_iterator_is_done (iter) && !found) {
3232 TnyHeaderFlags flags;
3234 header = TNY_HEADER (tny_iterator_get_current (iter));
3235 flags = tny_header_get_flags (header);
3236 if (!(flags & TNY_HEADER_FLAG_PARTIAL))
3240 tny_iterator_next (iter);
3242 g_object_unref (iter);
3248 * Shows a confirmation dialog to the user when we're moving messages
3249 * from a remote server to the local storage. Returns the dialog
3250 * response. If it's other kind of movement the it always returns
3254 msgs_move_to_confirmation (GtkWindow *win,
3255 TnyFolder *dest_folder,
3258 gint response = GTK_RESPONSE_OK;
3260 /* If the destination is a local folder */
3261 if (modest_tny_folder_is_local_folder (dest_folder)) {
3262 TnyFolder *src_folder;
3266 /* Get source folder */
3267 iter = tny_list_create_iterator (headers);
3268 header = TNY_HEADER (tny_iterator_get_current (iter));
3269 src_folder = tny_header_get_folder (header);
3270 g_object_unref (header);
3271 g_object_unref (iter);
3273 /* if no src_folder, message may be an attahcment */
3274 if (src_folder == NULL)
3275 return GTK_RESPONSE_CANCEL;
3277 /* If the source is a remote folder */
3278 if (!modest_tny_folder_is_local_folder (src_folder)) {
3279 const gchar *message;
3281 if (has_retrieved_msgs (headers))
3282 message = ngettext ("mcen_nc_move_retrieve", "mcen_nc_move_retrieves",
3283 tny_list_get_length (headers));
3285 message = ngettext ("mcen_nc_move_header", "mcen_nc_move_headers",
3286 tny_list_get_length (headers));
3288 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
3289 (const gchar *) message);
3291 g_object_unref (src_folder);
3299 transfer_msgs_from_viewer_cb (const GObject *object, gpointer user_data)
3301 ModestMsgViewWindow *self = NULL;
3303 g_return_if_fail (MODEST_IS_MSG_VIEW_WINDOW (object));
3304 self = MODEST_MSG_VIEW_WINDOW (object);
3306 if (!modest_msg_view_window_select_next_message (self))
3307 if (!modest_msg_view_window_select_previous_message (self))
3308 /* No more messages to view, so close this window */
3309 modest_ui_actions_on_close_window (NULL, MODEST_WINDOW(self));
3313 modest_ui_actions_move_folder_error_handler (ModestMailOperation *mail_op,
3316 GObject *win = modest_mail_operation_get_source (mail_op);
3317 const GError *error = NULL;
3318 const gchar *message = NULL;
3320 /* Get error message */
3321 error = modest_mail_operation_get_error (mail_op);
3322 if (error != NULL && error->message != NULL) {
3323 message = error->message;
3325 message = _("mail_in_ui_folder_move_target_error");
3328 /* Show notification dialog */
3329 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL, message);
3330 g_object_unref (win);
3334 modest_ui_actions_send_receive_error_handler (ModestMailOperation *mail_op,
3337 GObject *win = modest_mail_operation_get_source (mail_op);
3338 const GError *error = modest_mail_operation_get_error (mail_op);
3340 g_return_if_fail (error != NULL);
3341 if (error->message != NULL)
3342 g_printerr ("modest: %s\n", error->message);
3344 g_printerr ("modest: unkonw error on send&receive operation");
3346 /* Show error message */
3347 /* if (modest_mail_operation_get_id (mail_op) == MODEST_MAIL_OPERATION_TYPE_RECEIVE) */
3348 /* modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL, */
3349 /* _CS("sfil_ib_unable_to_receive")); */
3351 /* modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL, */
3352 /* _CS("sfil_ib_unable_to_send")); */
3353 g_object_unref (win);
3357 open_msg_for_purge_cb (ModestMailOperation *mail_op,
3364 gint pending_purges = 0;
3365 gboolean some_purged = FALSE;
3366 ModestWindow *win = MODEST_WINDOW (user_data);
3367 ModestWindowMgr *mgr = modest_runtime_get_window_mgr ();
3369 /* If there was any error */
3370 if (!modest_ui_actions_msg_retrieval_check (mail_op, header, msg)) {
3371 modest_window_mgr_unregister_header (mgr, header);
3375 /* Once the message has been retrieved for purging, we check if
3376 * it's all ok for purging */
3378 parts = tny_simple_list_new ();
3379 tny_mime_part_get_parts (TNY_MIME_PART (msg), parts);
3380 iter = tny_list_create_iterator (parts);
3382 while (!tny_iterator_is_done (iter)) {
3384 part = TNY_MIME_PART (tny_iterator_get_current (iter));
3385 if (tny_mime_part_is_attachment (part) || TNY_IS_MSG (part)) {
3386 if (tny_mime_part_is_purged (part))
3391 tny_iterator_next (iter);
3394 if (pending_purges>0) {
3396 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),_("mcen_nc_purge_file_text_inbox"));
3398 if (response == GTK_RESPONSE_OK) {
3399 modest_platform_information_banner (NULL, NULL, _("mcen_ib_removing_attachment"));
3400 tny_iterator_first (iter);
3401 while (!tny_iterator_is_done (iter)) {
3404 part = TNY_MIME_PART (tny_iterator_get_current (iter));
3405 if (tny_mime_part_is_attachment (part) || TNY_IS_MSG (part))
3406 tny_mime_part_set_purged (part);
3407 tny_iterator_next (iter);
3410 tny_msg_rewrite_cache (msg);
3413 modest_platform_information_banner (NULL, NULL, _("mail_ib_attachment_already_purged"));
3416 /* remove attachments */
3417 tny_iterator_first (iter);
3418 while (!tny_iterator_is_done (iter)) {
3421 part = TNY_MIME_PART (tny_iterator_get_current (iter));
3422 g_object_unref (part);
3423 tny_iterator_next (iter);
3425 modest_window_mgr_unregister_header (mgr, header);
3427 g_object_unref (iter);
3428 g_object_unref (parts);
3432 modest_ui_actions_on_main_window_remove_attachments (GtkAction *action,
3433 ModestMainWindow *win)
3435 GtkWidget *header_view;
3436 TnyList *header_list;
3439 TnyHeaderFlags flags;
3440 ModestWindow *msg_view_window = NULL;
3443 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win));
3445 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
3446 MODEST_WIDGET_TYPE_HEADER_VIEW);
3448 header_list = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW (header_view));
3450 if (tny_list_get_length (header_list) == 1) {
3451 iter = tny_list_create_iterator (header_list);
3452 header = TNY_HEADER (tny_iterator_get_current (iter));
3453 g_object_unref (iter);
3458 found = modest_window_mgr_find_registered_header (modest_runtime_get_window_mgr (),
3459 header, &msg_view_window);
3460 flags = tny_header_get_flags (header);
3461 if (!(flags & TNY_HEADER_FLAG_CACHED))
3464 if (msg_view_window != NULL)
3465 modest_msg_view_window_remove_attachments (MODEST_MSG_VIEW_WINDOW (msg_view_window), TRUE);
3467 /* do nothing; uid was registered before, so window is probably on it's way */
3468 g_warning ("debug: header %p has already been registered", header);
3471 ModestMailOperation *mail_op = NULL;
3472 modest_window_mgr_register_header (modest_runtime_get_window_mgr (), header);
3473 mail_op = modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE,
3475 modest_ui_actions_get_msgs_full_error_handler,
3477 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
3478 modest_mail_operation_get_msg (mail_op, header, open_msg_for_purge_cb, win);
3480 g_object_unref (mail_op);
3483 g_object_unref (header);
3485 g_object_unref (header_list);
3489 * Utility function that transfer messages from both the main window
3490 * and the msg view window when using the "Move to" dialog
3493 modest_ui_actions_xfer_messages_from_move_to (TnyFolderStore *dst_folder,
3496 TnyList *headers = NULL;
3499 if (!TNY_IS_FOLDER (dst_folder)) {
3500 modest_platform_information_banner (GTK_WIDGET (win),
3502 _CS("ckdg_ib_unable_to_move_to_current_location"));
3506 /* Get selected headers */
3507 headers = get_selected_headers (MODEST_WINDOW (win));
3509 /* Ask for user confirmation */
3510 response = msgs_move_to_confirmation (GTK_WINDOW (win),
3511 TNY_FOLDER (dst_folder),
3514 /* Transfer messages */
3515 if (response == GTK_RESPONSE_OK) {
3516 ModestMailOperation *mail_op =
3517 modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE,
3519 modest_ui_actions_move_folder_error_handler,
3521 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
3524 modest_mail_operation_xfer_msgs (mail_op,
3526 TNY_FOLDER (dst_folder),
3528 (MODEST_IS_MSG_VIEW_WINDOW (win)) ? transfer_msgs_from_viewer_cb : NULL,
3531 g_object_unref (G_OBJECT (mail_op));
3533 g_object_unref (headers);
3538 * UI handler for the "Move to" action when invoked from the
3542 modest_ui_actions_on_main_window_move_to (GtkAction *action,
3543 GtkWidget *folder_view,
3544 TnyFolderStore *dst_folder,
3545 ModestMainWindow *win)
3547 GtkWidget *header_view = NULL;
3548 ModestMailOperation *mail_op = NULL;
3549 TnyFolderStore *src_folder;
3551 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win));
3553 /* Get the source folder */
3554 src_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
3556 /* Offer the connection dialog if necessary, if the source folder is in a networked account: */
3557 if (!modest_platform_connect_and_wait_if_network_folderstore (GTK_WINDOW (win),
3561 /* Get header view */
3563 modest_main_window_get_child_widget (win, MODEST_WIDGET_TYPE_HEADER_VIEW);
3565 /* Get folder or messages to transfer */
3566 if (gtk_widget_is_focus (folder_view)) {
3568 /* Allow only to transfer folders to the local root folder */
3569 if (TNY_IS_ACCOUNT (dst_folder) &&
3570 !MODEST_IS_TNY_LOCAL_FOLDERS_ACCOUNT (dst_folder))
3573 /* Clean folder on header view before moving it */
3574 modest_header_view_clear (MODEST_HEADER_VIEW (header_view));
3576 if (TNY_IS_FOLDER (src_folder)) {
3578 modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE,
3580 modest_ui_actions_move_folder_error_handler,
3582 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
3585 modest_mail_operation_xfer_folder (mail_op,
3586 TNY_FOLDER (src_folder),
3589 /* Unref mail operation */
3590 g_object_unref (G_OBJECT (mail_op));
3592 g_warning ("%s: src_folder is not a TnyFolder.\n", __FUNCTION__);
3594 } else if (gtk_widget_is_focus (header_view)) {
3595 /* Transfer messages */
3596 modest_ui_actions_xfer_messages_from_move_to (dst_folder, MODEST_WINDOW (win));
3601 g_object_unref (src_folder);
3606 * UI handler for the "Move to" action when invoked from the
3607 * ModestMsgViewWindow
3610 modest_ui_actions_on_msg_view_window_move_to (GtkAction *action,
3611 TnyFolderStore *dst_folder,
3612 ModestMsgViewWindow *win)
3614 TnyHeader *header = NULL;
3615 TnyFolder *src_folder;
3617 /* Create header list */
3618 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
3619 src_folder = tny_header_get_folder(header);
3620 g_object_unref (header);
3622 /* Transfer the message */
3623 if (modest_platform_connect_and_wait_if_network_folderstore (NULL, TNY_FOLDER_STORE (src_folder)))
3624 modest_ui_actions_xfer_messages_from_move_to (dst_folder, MODEST_WINDOW (win));
3626 g_object_unref (src_folder);
3630 modest_ui_actions_on_move_to (GtkAction *action,
3633 GtkWidget *dialog = NULL, *folder_view = NULL, *tree_view = NULL;
3635 TnyFolderStore *dst_folder = NULL;
3636 ModestMainWindow *main_window;
3638 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win) ||
3639 MODEST_IS_MSG_VIEW_WINDOW (win));
3641 /* Get the main window if exists */
3642 if (MODEST_IS_MAIN_WINDOW (win))
3643 main_window = MODEST_MAIN_WINDOW (win);
3646 MODEST_MAIN_WINDOW (modest_window_mgr_get_main_window (modest_runtime_get_window_mgr ()));
3648 /* Get the folder view widget if exists */
3650 folder_view = modest_main_window_get_child_widget (main_window,
3651 MODEST_WIDGET_TYPE_FOLDER_VIEW);
3655 /* Create and run the dialog */
3656 dialog = create_move_to_dialog (GTK_WINDOW (win), folder_view, &tree_view);
3657 modest_folder_view_select_first_inbox_or_local (MODEST_FOLDER_VIEW (tree_view));
3658 result = gtk_dialog_run (GTK_DIALOG(dialog));
3659 g_object_ref (tree_view);
3660 gtk_widget_destroy (dialog);
3662 if (result != GTK_RESPONSE_ACCEPT)
3665 dst_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (tree_view));
3666 /* Offer the connection dialog if necessary: */
3667 if (modest_platform_connect_and_wait_if_network_folderstore (GTK_WINDOW (win),
3670 /* Do window specific stuff */
3671 if (MODEST_IS_MAIN_WINDOW (win))
3672 modest_ui_actions_on_main_window_move_to (action,
3675 MODEST_MAIN_WINDOW (win));
3677 modest_ui_actions_on_msg_view_window_move_to (action,
3679 MODEST_MSG_VIEW_WINDOW (win));
3682 g_object_unref (dst_folder);
3686 * Calls #HeadersFunc for each header already selected in the main
3687 * window or the message currently being shown in the msg view window
3690 do_headers_action (ModestWindow *win,
3694 TnyList *headers_list;
3700 headers_list = get_selected_headers (win);
3704 /* Get the folder */
3705 iter = tny_list_create_iterator (headers_list);
3706 header = TNY_HEADER (tny_iterator_get_current (iter));
3707 folder = tny_header_get_folder (header);
3708 g_object_unref (header);
3710 /* Call the function for each header */
3711 while (!tny_iterator_is_done (iter)) {
3712 header = TNY_HEADER (tny_iterator_get_current (iter));
3713 func (header, win, user_data);
3714 g_object_unref (header);
3715 tny_iterator_next (iter);
3718 /* Trick: do a poke status in order to speed up the signaling
3720 tny_folder_poke_status (folder);
3723 g_object_unref (folder);
3724 g_object_unref (iter);
3725 g_object_unref (headers_list);
3729 modest_ui_actions_view_attachment (GtkAction *action,
3730 ModestWindow *window)
3732 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
3733 modest_msg_view_window_view_attachment (MODEST_MSG_VIEW_WINDOW (window), NULL);
3735 /* not supported window for this action */
3736 g_return_if_reached ();
3741 modest_ui_actions_save_attachments (GtkAction *action,
3742 ModestWindow *window)
3744 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
3745 modest_msg_view_window_save_attachments (MODEST_MSG_VIEW_WINDOW (window), NULL);
3747 /* not supported window for this action */
3748 g_return_if_reached ();
3753 modest_ui_actions_remove_attachments (GtkAction *action,
3754 ModestWindow *window)
3756 if (MODEST_IS_MAIN_WINDOW (window)) {
3757 modest_ui_actions_on_main_window_remove_attachments (action, MODEST_MAIN_WINDOW (window));
3758 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
3759 modest_msg_view_window_remove_attachments (MODEST_MSG_VIEW_WINDOW (window), FALSE);
3761 /* not supported window for this action */
3762 g_return_if_reached ();
3767 modest_ui_actions_on_settings (GtkAction *action,
3772 dialog = modest_platform_get_global_settings_dialog ();
3773 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (win));
3774 gtk_widget_show_all (dialog);
3776 gtk_dialog_run (GTK_DIALOG (dialog));
3778 gtk_widget_destroy (dialog);
3782 modest_ui_actions_on_help (GtkAction *action,
3785 const gchar *help_id = NULL;
3787 if (MODEST_IS_MAIN_WINDOW (win)) {
3788 const gchar *action_name;
3789 action_name = gtk_action_get_name (action);
3791 if (!strcmp (action_name, "FolderViewCSMHelp") ||
3792 !strcmp (action_name, "HeaderViewCSMHelp")) {
3793 GtkWidget *folder_view;
3794 TnyFolderStore *folder_store;
3795 /* Get selected folder */
3796 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
3797 MODEST_WIDGET_TYPE_FOLDER_VIEW);
3798 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
3800 /* Switch help_id */
3801 if (TNY_IS_FOLDER (folder_store)) {
3802 switch (modest_tny_folder_guess_folder_type (TNY_FOLDER (folder_store))) {
3803 case TNY_FOLDER_TYPE_NORMAL:
3804 help_id = "applications_email_managefolders";
3806 case TNY_FOLDER_TYPE_INBOX:
3807 help_id = "applications_email_inbox";
3809 case TNY_FOLDER_TYPE_OUTBOX:
3810 help_id = "applications_email_outbox";
3812 case TNY_FOLDER_TYPE_SENT:
3813 help_id = "applications_email_sent";
3815 case TNY_FOLDER_TYPE_DRAFTS:
3816 help_id = "applications_email_drafts";
3818 case TNY_FOLDER_TYPE_ARCHIVE:
3819 help_id = "applications_email_managefolders";
3822 help_id = "applications_email_managefolders";
3825 help_id = "applications_email_mainview";
3827 g_object_unref (folder_store);
3829 help_id = "applications_email_mainview";
3831 } else if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
3832 help_id = "applications_email_viewer";
3833 } else if (MODEST_IS_MSG_EDIT_WINDOW (win))
3834 help_id = "applications_email_editor";
3836 modest_platform_show_help (GTK_WINDOW (win), help_id);
3840 modest_ui_actions_on_retrieve_msg_contents (GtkAction *action,
3841 ModestWindow *window)
3843 ModestMailOperation *mail_op;
3847 headers = get_selected_headers (window);
3851 /* Create mail operation */
3852 mail_op = modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE,
3854 modest_ui_actions_get_msgs_full_error_handler,
3856 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
3857 modest_mail_operation_get_msgs_full (mail_op, headers, NULL, NULL, NULL);
3860 g_object_unref (headers);
3861 g_object_unref (mail_op);
3865 modest_ui_actions_on_email_menu_activated (GtkAction *action,
3866 ModestWindow *window)
3868 g_return_if_fail (MODEST_IS_WINDOW (window));
3871 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
3875 modest_ui_actions_on_edit_menu_activated (GtkAction *action,
3876 ModestWindow *window)
3878 g_return_if_fail (MODEST_IS_WINDOW (window));
3881 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
3885 modest_ui_actions_on_view_menu_activated (GtkAction *action,
3886 ModestWindow *window)
3888 g_return_if_fail (MODEST_IS_WINDOW (window));
3891 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
3895 modest_ui_actions_on_tools_menu_activated (GtkAction *action,
3896 ModestWindow *window)
3898 g_return_if_fail (MODEST_IS_WINDOW (window));
3901 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
3905 modest_ui_actions_on_attachment_menu_activated (GtkAction *action,
3906 ModestWindow *window)
3908 g_return_if_fail (MODEST_IS_WINDOW (window));
3911 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
3915 modest_ui_actions_on_toolbar_csm_menu_activated (GtkAction *action,
3916 ModestWindow *window)
3918 g_return_if_fail (MODEST_IS_WINDOW (window));
3921 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
3925 modest_ui_actions_on_folder_view_csm_menu_activated (GtkAction *action,
3926 ModestWindow *window)
3928 g_return_if_fail (MODEST_IS_WINDOW (window));
3931 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
3935 modest_ui_actions_on_header_view_csm_menu_activated (GtkAction *action,
3936 ModestWindow *window)
3938 g_return_if_fail (MODEST_IS_WINDOW (window));
3941 modest_window_check_dimming_rules_group (window, "ModestMenuDimmingRules");
3945 modest_ui_actions_check_toolbar_dimming_rules (ModestWindow *window)
3947 g_return_if_fail (MODEST_IS_WINDOW (window));
3950 modest_window_check_dimming_rules_group (window, "ModestToolbarDimmingRules");
3954 modest_ui_actions_on_search_messages (GtkAction *action, ModestWindow *window)
3956 g_return_if_fail (MODEST_IS_WINDOW (window));
3958 modest_platform_show_search_messages (GTK_WINDOW (window));
3962 modest_ui_actions_on_open_addressbook (GtkAction *action, ModestWindow *win)
3964 g_return_if_fail (MODEST_IS_WINDOW (win));
3965 modest_platform_show_addressbook (GTK_WINDOW (win));
3970 modest_ui_actions_on_toggle_find_in_page (GtkToggleAction *action,
3971 ModestWindow *window)
3973 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3975 modest_msg_edit_window_toggle_find_toolbar (MODEST_MSG_EDIT_WINDOW (window), gtk_toggle_action_get_active (action));
3979 _on_send_receive_progress_changed (ModestMailOperation *mail_op,
3980 ModestMailOperationState *state,
3983 g_return_if_fail (MODEST_IS_MAIN_WINDOW(user_data));
3985 /* Set send/receive operation finished */
3986 if (state->status != MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS)
3987 modest_main_window_notify_send_receive_completed (MODEST_MAIN_WINDOW(user_data));