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>
36 #include <modest-runtime.h>
37 #include <modest-tny-folder.h>
38 #include <modest-tny-msg.h>
39 #include <modest-tny-account.h>
40 #include <modest-address-book.h>
42 #include "modest-ui-actions.h"
44 #include "modest-tny-platform-factory.h"
45 #include "modest-platform.h"
47 #include <widgets/modest-main-window.h>
48 #include <widgets/modest-msg-view-window.h>
49 #include <widgets/modest-account-view-window.h>
50 #include <widgets/modest-details-dialog.h>
52 #include "modest-account-mgr-helpers.h"
53 #include "modest-mail-operation.h"
54 #include "modest-text-utils.h"
56 #ifdef MODEST_HAVE_EASYSETUP
57 #include "easysetup/modest-easysetup-wizard.h"
58 #endif /*MODEST_HAVE_EASYSETUP*/
60 #include <modest-widget-memory.h>
61 #include <tny-error.h>
62 #include <tny-simple-list.h>
63 #include <tny-msg-view.h>
64 #include <tny-device.h>
66 typedef struct _GetMsgAsyncHelper {
68 ModestMailOperation *mail_op;
74 typedef enum _ReplyForwardAction {
80 typedef struct _ReplyForwardHelper {
81 guint reply_forward_type;
82 ReplyForwardAction action;
87 static void reply_forward_func (gpointer data, gpointer user_data);
88 static void read_msg_func (gpointer data, gpointer user_data);
89 static void get_msg_cb (TnyFolder *folder, TnyMsg *msg, GError **err,
91 static void reply_forward (ReplyForwardAction action, ModestWindow *win);
93 static gchar* ask_for_folder_name (GtkWindow *parent_window, const gchar *title);
97 modest_ui_actions_on_about (GtkAction *action, ModestWindow *win)
100 const gchar *authors[] = {
101 "Dirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>",
104 about = gtk_about_dialog_new ();
105 gtk_about_dialog_set_name (GTK_ABOUT_DIALOG(about), PACKAGE_NAME);
106 gtk_about_dialog_set_version (GTK_ABOUT_DIALOG(about),PACKAGE_VERSION);
107 gtk_about_dialog_set_copyright (GTK_ABOUT_DIALOG(about),
108 _("Copyright (c) 2006, Nokia Corporation\n"
109 "All rights reserved."));
110 gtk_about_dialog_set_comments (GTK_ABOUT_DIALOG(about),
111 _("a modest e-mail client\n\n"
112 "design and implementation: Dirk-Jan C. Binnema\n"
113 "contributions from the fine people at KC and Ig\n"
114 "uses the tinymail email framework written by Philip van Hoof"));
115 gtk_about_dialog_set_authors (GTK_ABOUT_DIALOG(about), authors);
116 gtk_about_dialog_set_website (GTK_ABOUT_DIALOG(about), "http://modest.garage.maemo.org");
118 gtk_dialog_run (GTK_DIALOG (about));
119 gtk_widget_destroy(about);
124 get_selected_headers (ModestWindow *win)
126 if (MODEST_IS_MAIN_WINDOW(win)) {
127 GtkWidget *header_view;
129 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
130 MODEST_WIDGET_TYPE_HEADER_VIEW);
131 return modest_header_view_get_selected_headers (MODEST_HEADER_VIEW(header_view));
133 } else if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
134 /* for MsgViewWindows, we simply return a list with one element */
137 TnyList *list = NULL;
139 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW(win));
141 header = tny_msg_get_header (msg);
142 list = tny_simple_list_new ();
143 tny_list_prepend (list, G_OBJECT(header));
144 g_object_unref (G_OBJECT(header));
153 modest_ui_actions_on_delete (GtkAction *action, ModestWindow *win)
155 TnyList *header_list;
158 g_return_if_fail (MODEST_IS_WINDOW(win));
160 if (MODEST_IS_MSG_EDIT_WINDOW (win)) {
162 g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value);
166 header_list = get_selected_headers (win);
169 iter = tny_list_create_iterator (header_list);
172 ModestMailOperation *mail_op;
174 header = TNY_HEADER (tny_iterator_get_current (iter));
175 /* TODO: thick grain mail operation involving
176 a list of objects. Composite pattern ??? */
177 /* TODO: add confirmation dialog */
178 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_DELETE);
179 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
182 /* Always delete. TODO: Move to trash still not supported */
183 modest_mail_operation_remove_msg (mail_op, header, FALSE);
186 g_object_unref (G_OBJECT (mail_op));
187 g_object_unref (G_OBJECT (header));
189 tny_iterator_next (iter);
191 } while (!tny_iterator_is_done (iter));
194 g_object_unref (G_OBJECT (iter));
197 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
198 gtk_widget_destroy (GTK_WIDGET(win));
204 modest_ui_actions_on_quit (GtkAction *action, ModestWindow *win)
210 modest_ui_actions_on_close_window (GtkAction *action, ModestWindow *win)
212 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
213 gtk_widget_destroy (GTK_WIDGET (win));
214 } else if (MODEST_IS_MSG_EDIT_WINDOW (win)) {
216 g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value);
217 } else if (MODEST_IS_WINDOW (win)) {
218 gtk_widget_destroy (GTK_WIDGET (win));
220 g_return_if_reached ();
225 modest_ui_actions_on_add_to_contacts (GtkAction *action, ModestWindow *win)
227 GtkClipboard *clipboard = NULL;
228 gchar *selection = NULL;
230 clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
231 selection = gtk_clipboard_wait_for_text (clipboard);
233 modest_address_book_add_address (selection);
238 modest_ui_actions_on_accounts (GtkAction *action, ModestWindow *win)
241 /* This is currently only implemented for Maemo,
242 * because it requires a providers preset file which is not publically available.
244 #ifdef MODEST_PLATFORM_MAEMO /* Defined in config.h */
245 GSList *account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
246 TRUE /* enabled accounts only */);
247 gboolean accounts_exist = account_names != NULL;
248 g_slist_free (account_names);
250 if (!accounts_exist) {
251 /* If there are no accounts yet, just show the easy-setup wizard, as per the UI spec: */
252 ModestEasysetupWizardDialog *wizard = modest_easysetup_wizard_dialog_new ();
253 gtk_window_set_transient_for (GTK_WINDOW (wizard), GTK_WINDOW (win));
254 gtk_dialog_run (GTK_DIALOG (wizard));
255 gtk_widget_destroy (GTK_WIDGET (wizard));
257 /* Show the list of accounts: */
258 GtkDialog *account_win = GTK_DIALOG(modest_account_view_window_new ());
259 gtk_window_set_transient_for (GTK_WINDOW (account_win), GTK_WINDOW(win));
260 gtk_dialog_run (account_win);
261 gtk_widget_destroy (GTK_WIDGET(account_win));
264 GtkWidget *dialog, *label;
266 /* Create the widgets */
268 dialog = gtk_dialog_new_with_buttons ("Message",
270 GTK_DIALOG_DESTROY_WITH_PARENT,
274 label = gtk_label_new ("Hello World!");
276 /* Ensure that the dialog box is destroyed when the user responds. */
278 g_signal_connect_swapped (dialog, "response",
279 G_CALLBACK (gtk_widget_destroy),
282 /* Add the label, and show everything we've added to the dialog. */
284 gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox),
286 gtk_widget_show_all (dialog);
287 #endif /* MODEST_PLATFORM_MAEMO */
291 modest_ui_actions_on_new_msg (GtkAction *action, ModestWindow *win)
293 ModestWindow *msg_win;
295 TnyFolder *folder = NULL;
296 gchar *account_name = NULL;
297 gchar *from_str = NULL;
298 /* GError *err = NULL; */
299 TnyAccount *account = NULL;
300 ModestWindowMgr *mgr;
301 gchar *signature = NULL;
303 account_name = g_strdup(modest_window_get_active_account (win));
305 account_name = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
307 g_printerr ("modest: no account found\n");
311 account = modest_tny_account_store_get_tny_account_by_account (modest_runtime_get_account_store(),
313 TNY_ACCOUNT_TYPE_STORE);
315 g_printerr ("modest: failed to get tnyaccount for '%s'\n", account_name);
319 from_str = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(), account_name);
321 g_printerr ("modest: failed get from string for '%s'\n", account_name);
325 if (modest_account_mgr_get_bool (modest_runtime_get_account_mgr (), account_name,
326 MODEST_ACCOUNT_USE_SIGNATURE, FALSE)) {
327 signature = modest_account_mgr_get_string (modest_runtime_get_account_mgr (), account_name,
328 MODEST_ACCOUNT_SIGNATURE, FALSE);
330 signature = g_strdup ("");
333 msg = modest_tny_msg_new ("", from_str, "", "", "", signature, NULL);
335 g_printerr ("modest: failed to create new msg\n");
339 folder = modest_tny_account_get_special_folder (account, TNY_FOLDER_TYPE_DRAFTS);
341 g_printerr ("modest: failed to find Drafts folder\n");
345 /* tny_folder_add_msg (folder, msg, &err); */
347 /* g_printerr ("modest: error adding msg to Drafts folder: %s", */
349 /* g_error_free (err); */
353 /* Create and register edit window */
354 msg_win = modest_msg_edit_window_new (msg, account_name);
355 mgr = modest_runtime_get_window_mgr ();
356 modest_window_mgr_register_window (mgr, msg_win);
359 gtk_window_set_transient_for (GTK_WINDOW (msg_win),
361 gtk_widget_show_all (GTK_WIDGET (msg_win));
364 g_free (account_name);
368 g_object_unref (G_OBJECT(account));
370 g_object_unref (G_OBJECT(msg));
372 g_object_unref (G_OBJECT(folder));
377 modest_ui_actions_on_open (GtkAction *action, ModestWindow *win)
379 modest_runtime_not_implemented (GTK_WINDOW(win)); /* FIXME */
385 reply_forward_func (gpointer data, gpointer user_data)
387 TnyMsg *msg, *new_msg;
388 GetMsgAsyncHelper *helper;
389 ReplyForwardHelper *rf_helper;
390 ModestWindow *msg_win;
391 ModestEditType edit_type;
394 TnyFolder *folder = NULL;
395 TnyAccount *account = NULL;
396 ModestWindowMgr *mgr;
397 gchar *signature = NULL;
399 msg = TNY_MSG (data);
400 helper = (GetMsgAsyncHelper *) user_data;
401 rf_helper = (ReplyForwardHelper *) helper->user_data;
403 from = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(),
404 rf_helper->account_name);
405 if (modest_account_mgr_get_bool (modest_runtime_get_account_mgr(),
406 rf_helper->account_name,
407 MODEST_ACCOUNT_USE_SIGNATURE, FALSE)) {
408 signature = modest_account_mgr_get_string (modest_runtime_get_account_mgr (),
409 rf_helper->account_name,
410 MODEST_ACCOUNT_SIGNATURE, FALSE);
412 /* Create reply mail */
413 switch (rf_helper->action) {
416 modest_tny_msg_create_reply_msg (msg, from, signature,
417 rf_helper->reply_forward_type,
418 MODEST_TNY_MSG_REPLY_MODE_SENDER);
420 case ACTION_REPLY_TO_ALL:
422 modest_tny_msg_create_reply_msg (msg, from, signature, rf_helper->reply_forward_type,
423 MODEST_TNY_MSG_REPLY_MODE_ALL);
424 edit_type = MODEST_EDIT_TYPE_REPLY;
428 modest_tny_msg_create_forward_msg (msg, from, signature, rf_helper->reply_forward_type);
429 edit_type = MODEST_EDIT_TYPE_FORWARD;
432 g_return_if_reached ();
439 g_printerr ("modest: failed to create message\n");
443 account = modest_tny_account_store_get_tny_account_by_account (modest_runtime_get_account_store(),
444 rf_helper->account_name,
445 TNY_ACCOUNT_TYPE_STORE);
447 g_printerr ("modest: failed to get tnyaccount for '%s'\n", rf_helper->account_name);
451 folder = modest_tny_account_get_special_folder (account, TNY_FOLDER_TYPE_DRAFTS);
453 g_printerr ("modest: failed to find Drafts folder\n");
457 tny_folder_add_msg (folder, msg, &err);
459 g_printerr ("modest: error adding msg to Drafts folder: %s",
465 /* Create and register the windows */
466 msg_win = modest_msg_edit_window_new (new_msg, rf_helper->account_name);
467 mgr = modest_runtime_get_window_mgr ();
468 modest_window_mgr_register_window (mgr, msg_win);
470 /* Show edit window */
471 gtk_widget_show_all (GTK_WIDGET (msg_win));
475 g_object_unref (G_OBJECT (new_msg));
477 g_object_unref (G_OBJECT (folder));
479 g_object_unref (G_OBJECT (account));
481 g_free (rf_helper->account_name);
482 g_slice_free (ReplyForwardHelper, rf_helper);
485 * Common code for the reply and forward actions
488 reply_forward (ReplyForwardAction action, ModestWindow *win)
490 TnyList *header_list;
491 guint reply_forward_type;
493 /* TnyFolder *folder; */
494 GetMsgAsyncHelper *helper;
495 ReplyForwardHelper *rf_helper;
497 g_return_if_fail (MODEST_IS_WINDOW(win));
499 header_list = get_selected_headers (win);
503 reply_forward_type = modest_conf_get_int (modest_runtime_get_conf (),
504 (action == ACTION_FORWARD) ? MODEST_CONF_FORWARD_TYPE : MODEST_CONF_REPLY_TYPE,
506 /* We assume that we can only select messages of the
507 same folder and that we reply all of them from the
508 same account. In fact the interface currently only
509 allows single selection */
512 rf_helper = g_slice_new0 (ReplyForwardHelper);
513 rf_helper->reply_forward_type = reply_forward_type;
514 rf_helper->action = action;
516 rf_helper->account_name = g_strdup (modest_window_get_active_account (win));
517 if (!rf_helper->account_name)
518 rf_helper->account_name =
519 modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
521 helper = g_slice_new0 (GetMsgAsyncHelper);
522 helper->window = win;
523 helper->func = reply_forward_func;
524 helper->iter = tny_list_create_iterator (header_list);
525 helper->user_data = rf_helper;
527 if (MODEST_IS_MSG_VIEW_WINDOW(win)) {
529 msg = modest_msg_view_window_get_message(MODEST_MSG_VIEW_WINDOW(win));
531 g_printerr ("modest: no message found\n");
534 reply_forward_func (msg, helper);
536 header = TNY_HEADER (tny_iterator_get_current (helper->iter));
538 /* folder = tny_header_get_folder (header); */
540 /* /\* The callback will call it per each header *\/ */
541 /* tny_folder_get_msg_async (folder, header, get_msg_cb, NULL, helper); */
542 /* g_object_unref (G_OBJECT (folder)); */
544 /* g_printerr ("modest: no folder for header\n"); */
546 helper->mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE);
547 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), helper->mail_op);
548 modest_mail_operation_process_msg (helper->mail_op, header, get_msg_cb, helper);
551 g_object_unref (G_OBJECT (header));
557 modest_ui_actions_on_reply (GtkAction *action, ModestWindow *win)
559 g_return_if_fail (MODEST_IS_WINDOW(win));
561 reply_forward (ACTION_REPLY, win);
565 modest_ui_actions_on_forward (GtkAction *action, ModestWindow *win)
567 g_return_if_fail (MODEST_IS_WINDOW(win));
569 reply_forward (ACTION_FORWARD, win);
573 modest_ui_actions_on_reply_all (GtkAction *action, ModestWindow *win)
575 g_return_if_fail (MODEST_IS_WINDOW(win));
577 reply_forward (ACTION_REPLY_TO_ALL, win);
581 modest_ui_actions_on_next (GtkAction *action,
582 ModestWindow *window)
584 if (MODEST_IS_MAIN_WINDOW (window)) {
585 GtkWidget *header_view;
587 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
588 MODEST_WIDGET_TYPE_HEADER_VIEW);
592 modest_header_view_select_next (MODEST_HEADER_VIEW(header_view));
593 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
594 modest_msg_view_window_select_next_message (MODEST_MSG_VIEW_WINDOW (window));
596 g_return_if_reached ();
601 modest_ui_actions_on_prev (GtkAction *action,
602 ModestWindow *window)
604 g_return_if_fail (MODEST_IS_WINDOW(window));
606 if (MODEST_IS_MAIN_WINDOW (window)) {
607 GtkWidget *header_view;
608 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
609 MODEST_WIDGET_TYPE_HEADER_VIEW);
613 modest_header_view_select_prev (MODEST_HEADER_VIEW(header_view));
614 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
615 modest_msg_view_window_select_previous_message (MODEST_MSG_VIEW_WINDOW (window));
617 g_return_if_reached ();
622 modest_ui_actions_on_sort (GtkAction *action,
623 ModestWindow *window)
625 g_return_if_fail (MODEST_IS_WINDOW(window));
627 if (MODEST_IS_MAIN_WINDOW (window)) {
628 GtkWidget *header_view;
629 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
630 MODEST_WIDGET_TYPE_HEADER_VIEW);
634 /* Show sorting dialog */
635 modest_platform_run_sort_dialog (GTK_WINDOW (window), MODEST_SORT_HEADERS);
641 action_send (const gchar* account_name)
643 TnyAccount *tny_account;
644 ModestTnySendQueue *send_queue;
646 g_return_val_if_fail (account_name, FALSE);
648 /* Get the transport account according to the open connection,
649 * because the account might specify connection-specific SMTP servers.
652 modest_tny_account_store_get_transport_account_for_open_connection (modest_runtime_get_account_store(),
655 g_printerr ("modest: cannot get tny transport account for %s\n", account_name);
659 send_queue = modest_tny_send_queue_new (TNY_CAMEL_TRANSPORT_ACCOUNT(tny_account));
661 g_object_unref (G_OBJECT(tny_account));
662 g_printerr ("modest: cannot get send queue for %s\n", account_name);
666 //modest_tny_send_queue_flush (send_queue);
668 g_object_unref (G_OBJECT(send_queue));
669 g_object_unref (G_OBJECT(tny_account));
676 action_receive (const gchar* account_name)
678 TnyAccount *tny_account;
679 ModestMailOperation *mail_op;
681 g_return_val_if_fail (account_name, FALSE);
684 modest_tny_account_store_get_tny_account_by_account (modest_runtime_get_account_store(),
686 TNY_ACCOUNT_TYPE_STORE);
688 g_printerr ("modest: cannot get tny store account for %s\n", account_name);
692 /* Create the mail operation */
693 /* TODO: The spec wants us to first do any pending deletions, before receiving. */
694 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE);
695 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
696 modest_mail_operation_update_account (mail_op, TNY_STORE_ACCOUNT(tny_account));
698 g_object_unref (G_OBJECT(tny_account));
699 g_object_unref (G_OBJECT (mail_op));
704 /** Check that an appropriate connection is open.
706 gboolean check_for_connection (const gchar *account_name)
708 TnyDevice *device = modest_runtime_get_device ();
711 g_assert (TNY_IS_MAEMO_CONIC_DEVICE (device));
713 TnyMaemoConicDevice *maemo_device = TNY_MAEMO_CONIC_DEVICE (device);
716 if (tny_device_is_online (device))
719 modest_platform_connect_and_wait (NULL);
721 /* TODO: Wait until a result. */
727 do_send_receive_current_or_default (ModestWindow *win)
731 g_message ("%s: online? %s", __FUNCTION__,
732 tny_device_is_online(modest_runtime_get_device()) ? "yes":"no");
734 /* As per the UI spec, only the active account should be affected,
735 * else the default folder if there is no active account: */
737 g_strdup(modest_window_get_active_account(MODEST_WINDOW(win)));
739 account_name = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
741 g_printerr ("modest: cannot get default account\n");
745 /* Do not continue if no suitable connection is open: */
746 if (check_for_connection (account_name)) {
747 /* As per the UI spec,
748 * for POP accounts, we should receive,
749 * for IMAP we should synchronize everything, including receiving,
750 * for SMTP we should send,
751 * first receiving, then sending:
753 if (!action_receive(account_name))
754 g_printerr ("modest: failed to receive\n");
755 if (!action_send(account_name))
756 g_printerr ("modest: failed to send\n");
758 g_free (account_name);
764 do_send_receive_auto (ModestWindow *win)
766 g_message ("%s: online? %s", __FUNCTION__,
767 tny_device_is_online(modest_runtime_get_device()) ? "yes":"no");
769 /* TODO: Delete the item->data strings as well as the list? */
770 GSList *account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
771 TRUE /* enabled accounts only */);
772 GSList *iter = account_names;
774 const gchar * account_name = (const char*) iter->data;
776 /* Do not continue if no suitable connection is open: */
777 if (account_name && check_for_connection (account_name)) {
778 /* As per the UI spec,
779 * for POP accounts, we should receive,
780 * for IMAP we should synchronize everything, including receiving,
781 * for SMTP we should send,
782 * first receiving, then sending:
784 if (!action_receive(account_name))
785 g_printerr ("modest: failed to receive for account %s\n", account_name);
786 if (!action_send(account_name))
787 g_printerr ("modest: failed to send for account %s\n", account_name);
792 g_slist_free (account_names);
796 do_send_receive (ModestWindow *win)
798 const gboolean auto_update = TRUE; /* TODO: Get gconf setting. */
800 do_send_receive_current_or_default (win);
802 do_send_receive_auto (win);
806 modest_ui_actions_on_send_receive (GtkAction *action, ModestWindow *win)
808 /* Check that at least one account exists: */
809 GSList *account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
810 TRUE /* enabled accounts only */);
811 gboolean accounts_exist = account_names != NULL;
812 g_slist_free (account_names);
814 /* If not, allow the user to create an account before trying to send/receive. */
815 if (!accounts_exist) {
816 modest_ui_actions_on_accounts (NULL, win);
819 do_send_receive (win);
826 modest_ui_actions_toggle_header_list_view (GtkAction *action, ModestMainWindow *main_window)
829 GtkWidget *header_view;
831 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
833 header_view = modest_main_window_get_child_widget (main_window,
834 MODEST_WIDGET_TYPE_HEADER_VIEW);
838 conf = modest_runtime_get_conf ();
840 /* what is saved/restored is depending on the style; thus; we save with
841 * old style, then update the style, and restore for this new style
843 modest_widget_memory_save (conf, G_OBJECT(header_view), MODEST_CONF_HEADER_VIEW_KEY);
845 if (modest_header_view_get_style
846 (MODEST_HEADER_VIEW(header_view)) == MODEST_HEADER_VIEW_STYLE_DETAILS)
847 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
848 MODEST_HEADER_VIEW_STYLE_TWOLINES);
850 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
851 MODEST_HEADER_VIEW_STYLE_DETAILS);
853 modest_widget_memory_restore (conf, G_OBJECT(header_view),
854 MODEST_CONF_HEADER_VIEW_KEY);
860 * Marks a message as read and passes it to the msg preview widget
863 read_msg_func (gpointer data, gpointer user_data)
867 GetMsgAsyncHelper *helper;
868 TnyHeaderFlags header_flags;
869 GtkWidget *msg_preview;
871 msg = TNY_MSG (data);
872 helper = (GetMsgAsyncHelper *) user_data;
874 msg_preview = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (helper->window),
875 MODEST_WIDGET_TYPE_MSG_PREVIEW);
879 header = TNY_HEADER (tny_iterator_get_current (helper->iter));
880 header_flags = tny_header_get_flags (header);
881 tny_header_set_flags (header, header_flags | TNY_HEADER_FLAG_SEEN);
882 g_object_unref (G_OBJECT (header));
884 /* Set message on msg view */
885 modest_msg_view_set_message (MODEST_MSG_VIEW(msg_preview), msg);
889 * This function is a generic handler for the tny_folder_get_msg_async
890 * call. It expects as user_data a #GetMsgAsyncHelper. This helper
891 * contains a user provided function that is called inside this
892 * method. This will allow us to use this callback in many different
893 * places. This callback performs the common actions for the
894 * get_msg_async call, more specific actions will be done by the user
898 get_msg_cb (TnyFolder *folder, TnyMsg *msg, GError **err, gpointer user_data)
900 GetMsgAsyncHelper *helper;
902 helper = (GetMsgAsyncHelper *) user_data;
905 if ((*err && ((*err)->code == TNY_FOLDER_ERROR_GET_MSG)) || !msg) {
906 modest_ui_actions_on_item_not_found (NULL,
907 MODEST_ITEM_TYPE_MESSAGE,
912 /* Notify the queue (if neccesary) */
913 if (helper->mail_op != NULL)
914 modest_mail_operation_queue_remove (modest_runtime_get_mail_operation_queue (), helper->mail_op);
916 /* Call user function */
918 helper->func (msg, user_data);
920 /* Process next element (if exists) */
921 tny_iterator_next (helper->iter);
922 if (tny_iterator_is_done (helper->iter)) {
924 headers = tny_iterator_get_list (helper->iter);
926 g_object_unref (G_OBJECT (headers));
927 g_object_unref (G_OBJECT (helper->iter));
928 g_slice_free (GetMsgAsyncHelper, helper);
931 header = TNY_HEADER (tny_iterator_get_current (helper->iter));
932 /* tny_folder_get_msg_async (folder, header, */
933 /* get_msg_cb, NULL, helper); */
934 helper->mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE);
935 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), helper->mail_op);
936 modest_mail_operation_process_msg (helper->mail_op, header, get_msg_cb, helper);
938 g_object_unref (G_OBJECT(header));
943 modest_ui_actions_on_header_selected (ModestHeaderView *header_view,
945 ModestMainWindow *main_window)
947 /* TnyFolder *folder; */
948 GetMsgAsyncHelper *helper;
951 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
953 /* when there's no header, clear the msgview */
955 GtkWidget *msg_preview;
957 /* Clear msg preview if exists */
958 msg_preview = modest_main_window_get_child_widget(main_window,
959 MODEST_WIDGET_TYPE_MSG_PREVIEW);
962 modest_msg_view_set_message (MODEST_MSG_VIEW(msg_preview), NULL);
966 /* Update Main window title */
967 if (GTK_WIDGET_HAS_FOCUS (header_view)) {
968 const gchar *subject = tny_header_get_subject (header);
969 if (subject && strcmp (subject, ""))
970 gtk_window_set_title (GTK_WINDOW (main_window), subject);
972 gtk_window_set_title (GTK_WINDOW (main_window), _("mail_va_no_subject"));
976 list = tny_simple_list_new ();
977 tny_list_prepend (list, G_OBJECT (header));
979 /* Fill helper data */
980 helper = g_slice_new0 (GetMsgAsyncHelper);
981 helper->window = MODEST_WINDOW (main_window);
982 helper->iter = tny_list_create_iterator (list);
983 helper->func = read_msg_func;
985 /* folder = tny_header_get_folder (TNY_HEADER(header)); */
987 /* tny_folder_get_msg_async (TNY_FOLDER(folder), */
988 /* header, get_msg_cb, */
991 helper->mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE);
992 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), helper->mail_op);
993 modest_mail_operation_process_msg (helper->mail_op, header, get_msg_cb, helper);
996 /* g_object_unref (G_OBJECT (folder)); */
1002 modest_ui_actions_on_header_activated (ModestHeaderView *folder_view, TnyHeader *header,
1003 ModestMainWindow *main_window)
1005 ModestWindow *win = NULL;
1006 TnyFolder *folder = NULL;
1008 ModestWindowMgr *mgr;
1009 GtkTreeModel *model;
1011 GtkTreeSelection *sel = NULL;
1012 GList *sel_list = NULL;
1014 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1019 folder = tny_header_get_folder (header);
1021 g_printerr ("modest: cannot get folder for header\n");
1025 /* FIXME: make async?; check error */
1026 msg = tny_folder_get_msg (folder, header, NULL);
1028 g_printerr ("modest: cannot get msg for header\n");
1032 /* Look if we already have a message view for that header */
1033 mgr = modest_runtime_get_window_mgr ();
1034 win = modest_window_mgr_find_window_by_msguid (mgr, tny_header_get_uid (header));
1036 /* If not, create a new window */
1040 account = g_strdup(modest_window_get_active_account(MODEST_WINDOW(main_window)));
1042 account = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
1044 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_view));
1045 sel_list = gtk_tree_selection_get_selected_rows (sel, &model);
1046 if (sel_list != NULL) {
1047 gtk_tree_model_get_iter (model, &iter, (GtkTreePath *) sel_list->data);
1049 win = modest_msg_view_window_new_with_header_model (msg, account, model, iter);
1050 g_list_foreach (sel_list, (GFunc) gtk_tree_path_free, NULL);
1051 g_list_free (sel_list);
1053 win = modest_msg_view_window_new (msg, account);
1055 modest_window_mgr_register_window (mgr, win);
1057 gtk_window_set_transient_for (GTK_WINDOW (win),
1058 GTK_WINDOW (main_window));
1061 gtk_widget_show_all (GTK_WIDGET(win));
1063 g_object_unref (G_OBJECT (msg));
1066 g_object_unref (G_OBJECT (folder));
1070 modest_ui_actions_on_folder_selection_changed (ModestFolderView *folder_view,
1071 TnyFolderStore *folder_store,
1073 ModestMainWindow *main_window)
1076 GtkWidget *header_view;
1078 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1080 header_view = modest_main_window_get_child_widget(main_window,
1081 MODEST_WIDGET_TYPE_HEADER_VIEW);
1085 conf = modest_runtime_get_conf ();
1087 if (TNY_IS_FOLDER (folder_store)) {
1089 modest_main_window_set_contents_style (main_window, MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS);
1092 modest_header_view_set_folder (MODEST_HEADER_VIEW(header_view),
1093 TNY_FOLDER (folder_store));
1094 modest_widget_memory_restore (conf, G_OBJECT(header_view),
1095 MODEST_CONF_HEADER_VIEW_KEY);
1097 modest_widget_memory_save (conf, G_OBJECT (header_view), MODEST_CONF_HEADER_VIEW_KEY);
1098 modest_header_view_set_folder (MODEST_HEADER_VIEW(header_view), NULL);
1100 } else if (TNY_IS_ACCOUNT (folder_store)) {
1102 modest_main_window_set_contents_style (main_window, MODEST_MAIN_WINDOW_CONTENTS_STYLE_DETAILS);
1107 modest_ui_actions_on_item_not_found (ModestHeaderView *header_view,ModestItemType type,
1114 item = (type == MODEST_ITEM_TYPE_FOLDER) ? "folder" : "message";
1116 if (g_main_depth > 0)
1117 gdk_threads_enter ();
1118 online = tny_device_is_online (modest_runtime_get_device());
1121 /* already online -- the item is simply not there... */
1122 dialog = gtk_message_dialog_new (GTK_WINDOW (win),
1124 GTK_MESSAGE_WARNING,
1126 _("The %s you selected cannot be found"),
1128 gtk_dialog_run (GTK_DIALOG(dialog));
1130 dialog = gtk_dialog_new_with_buttons (_("Connection requested"),
1134 GTK_RESPONSE_REJECT,
1136 GTK_RESPONSE_ACCEPT,
1138 txt = g_strdup_printf (_("This %s is not available in offline mode.\n"
1139 "Do you want to get online?"), item);
1140 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
1141 gtk_label_new (txt), FALSE, FALSE, 0);
1142 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
1145 gtk_window_set_default_size (GTK_WINDOW(dialog), 300, 300);
1146 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
1147 // modest_platform_connect_and_wait ();;
1150 gtk_widget_destroy (dialog);
1151 if (g_main_depth > 0)
1152 gdk_threads_leave ();
1156 modest_ui_actions_on_msg_link_hover (ModestMsgView *msgview, const gchar* link,
1159 g_message ("%s %s", __FUNCTION__, link);
1164 modest_ui_actions_on_msg_link_clicked (ModestMsgView *msgview, const gchar* link,
1167 modest_platform_activate_uri (link);
1171 modest_ui_actions_on_msg_link_contextual (ModestMsgView *msgview, const gchar* link,
1174 modest_platform_show_uri_popup (link);
1178 modest_ui_actions_on_msg_attachment_clicked (ModestMsgView *msgview, TnyMimePart *mime_part,
1181 g_message (__FUNCTION__);
1186 modest_ui_actions_on_msg_recpt_activated (ModestMsgView *msgview,
1187 const gchar *address,
1190 g_message ("%s %s", __FUNCTION__, address);
1194 modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edit_window)
1196 TnyTransportAccount *transport_account;
1197 ModestMailOperation *mail_operation;
1199 gchar *account_name, *from;
1200 ModestAccountMgr *account_mgr;
1202 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window));
1204 data = modest_msg_edit_window_get_msg_data (edit_window);
1206 account_mgr = modest_runtime_get_account_mgr();
1207 account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
1209 account_name = modest_account_mgr_get_default_account (account_mgr);
1210 if (!account_name) {
1211 g_printerr ("modest: no account found\n");
1212 modest_msg_edit_window_free_msg_data (edit_window, data);
1216 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_tny_account_by_account
1217 (modest_runtime_get_account_store(),
1219 TNY_ACCOUNT_TYPE_TRANSPORT));
1220 if (!transport_account) {
1221 g_printerr ("modest: no transport account found for '%s'\n", account_name);
1222 g_free (account_name);
1223 modest_msg_edit_window_free_msg_data (edit_window, data);
1226 from = modest_account_mgr_get_from_string (account_mgr, account_name);
1228 /* Create the mail operation */
1229 mail_operation = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE);
1230 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
1232 modest_mail_operation_save_to_drafts (mail_operation,
1242 data->priority_flags);
1245 g_free (account_name);
1246 g_object_unref (G_OBJECT (transport_account));
1247 g_object_unref (G_OBJECT (mail_operation));
1249 modest_msg_edit_window_free_msg_data (edit_window, data);
1251 /* Save settings and close the window */
1252 gtk_widget_destroy (GTK_WIDGET (edit_window));
1255 modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
1257 TnyTransportAccount *transport_account;
1258 ModestMailOperation *mail_operation;
1260 gchar *account_name, *from;
1261 ModestAccountMgr *account_mgr;
1263 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window));
1265 if (!modest_msg_edit_window_check_names (edit_window))
1268 data = modest_msg_edit_window_get_msg_data (edit_window);
1270 /* FIXME: Code added just for testing. The final version will
1271 use the send queue provided by tinymail and some
1273 account_mgr = modest_runtime_get_account_mgr();
1274 account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
1276 account_name = modest_account_mgr_get_default_account (account_mgr);
1277 if (!account_name) {
1278 g_printerr ("modest: no account found\n");
1279 modest_msg_edit_window_free_msg_data (edit_window, data);
1283 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_transport_account_for_open_connection
1284 (modest_runtime_get_account_store(),
1286 if (!transport_account) {
1287 g_printerr ("modest: no transport account found for '%s'\n", account_name);
1288 g_free (account_name);
1289 modest_msg_edit_window_free_msg_data (edit_window, data);
1292 from = modest_account_mgr_get_from_string (account_mgr, account_name);
1294 /* Create the mail operation */
1295 mail_operation = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_SEND);
1296 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
1298 modest_mail_operation_send_new_mail (mail_operation,
1308 data->priority_flags);
1311 g_free (account_name);
1312 g_object_unref (G_OBJECT (transport_account));
1313 g_object_unref (G_OBJECT (mail_operation));
1315 modest_msg_edit_window_free_msg_data (edit_window, data);
1317 /* Save settings and close the window */
1318 gtk_widget_destroy (GTK_WIDGET (edit_window));
1322 modest_ui_actions_on_toggle_bold (GtkToggleAction *action,
1323 ModestMsgEditWindow *window)
1325 ModestMsgEditFormatState *format_state = NULL;
1327 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1328 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
1330 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
1333 format_state = modest_msg_edit_window_get_format_state (window);
1334 g_return_if_fail (format_state != NULL);
1336 format_state->bold = gtk_toggle_action_get_active (action);
1337 modest_msg_edit_window_set_format_state (window, format_state);
1338 g_free (format_state);
1343 modest_ui_actions_on_toggle_italics (GtkToggleAction *action,
1344 ModestMsgEditWindow *window)
1346 ModestMsgEditFormatState *format_state = NULL;
1348 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1349 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
1351 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
1354 format_state = modest_msg_edit_window_get_format_state (window);
1355 g_return_if_fail (format_state != NULL);
1357 format_state->italics = gtk_toggle_action_get_active (action);
1358 modest_msg_edit_window_set_format_state (window, format_state);
1359 g_free (format_state);
1364 modest_ui_actions_on_toggle_bullets (GtkToggleAction *action,
1365 ModestMsgEditWindow *window)
1367 ModestMsgEditFormatState *format_state = NULL;
1369 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1370 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
1372 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
1375 format_state = modest_msg_edit_window_get_format_state (window);
1376 g_return_if_fail (format_state != NULL);
1378 format_state->bullet = gtk_toggle_action_get_active (action);
1379 modest_msg_edit_window_set_format_state (window, format_state);
1380 g_free (format_state);
1385 modest_ui_actions_on_change_justify (GtkRadioAction *action,
1386 GtkRadioAction *selected,
1387 ModestMsgEditWindow *window)
1389 ModestMsgEditFormatState *format_state = NULL;
1390 GtkJustification value;
1392 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1394 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
1397 value = gtk_radio_action_get_current_value (selected);
1399 format_state = modest_msg_edit_window_get_format_state (window);
1400 g_return_if_fail (format_state != NULL);
1402 format_state->justification = value;
1403 modest_msg_edit_window_set_format_state (window, format_state);
1404 g_free (format_state);
1408 modest_ui_actions_on_select_editor_color (GtkAction *action,
1409 ModestMsgEditWindow *window)
1411 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1412 g_return_if_fail (GTK_IS_ACTION (action));
1414 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
1417 modest_msg_edit_window_select_color (window);
1421 modest_ui_actions_on_select_editor_background_color (GtkAction *action,
1422 ModestMsgEditWindow *window)
1424 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1425 g_return_if_fail (GTK_IS_ACTION (action));
1427 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
1430 modest_msg_edit_window_select_background_color (window);
1434 modest_ui_actions_on_insert_image (GtkAction *action,
1435 ModestMsgEditWindow *window)
1437 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1438 g_return_if_fail (GTK_IS_ACTION (action));
1440 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
1443 modest_msg_edit_window_insert_image (window);
1447 * Shows a dialog with an entry that asks for some text. The returned
1448 * value must be freed by the caller. The dialog window title will be
1452 ask_for_folder_name (GtkWindow *parent_window,
1455 GtkWidget *dialog, *entry;
1456 gchar *folder_name = NULL;
1458 /* Ask for folder name */
1459 dialog = gtk_dialog_new_with_buttons (_("New Folder Name"),
1463 GTK_RESPONSE_REJECT,
1465 GTK_RESPONSE_ACCEPT,
1467 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
1468 gtk_label_new(title),
1471 entry = gtk_entry_new_with_max_length (40);
1472 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
1476 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
1478 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
1479 folder_name = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry)));
1481 gtk_widget_destroy (dialog);
1487 modest_ui_actions_on_new_folder (GtkAction *action, ModestMainWindow *main_window)
1489 TnyFolderStore *parent_folder;
1490 GtkWidget *folder_view;
1492 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1494 folder_view = modest_main_window_get_child_widget (main_window,
1495 MODEST_WIDGET_TYPE_FOLDER_VIEW);
1499 parent_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
1501 if (parent_folder) {
1502 gboolean finished = FALSE;
1504 gchar *folder_name = NULL, *suggested_name = NULL;
1506 /* Run the new folder dialog */
1508 result = modest_platform_run_new_folder_dialog (GTK_WINDOW (main_window),
1513 if (result == GTK_RESPONSE_REJECT) {
1516 ModestMailOperation *mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE);
1517 TnyFolder *new_folder = NULL;
1519 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
1522 new_folder = modest_mail_operation_create_folder (mail_op,
1524 (const gchar *) folder_name);
1526 g_object_unref (new_folder);
1530 /* /\* TODO: check error and follow proper actions *\/ */
1531 /* /\* suggested_name = X; *\/ */
1532 /* /\* Show error to the user *\/ */
1533 /* modest_platform_run_information_dialog (GTK_WINDOW (main_window), */
1534 /* MODEST_INFORMATION_CREATE_FOLDER); */
1536 g_object_unref (mail_op);
1538 g_free (folder_name);
1542 g_object_unref (parent_folder);
1547 modest_ui_actions_on_rename_folder (GtkAction *action,
1548 ModestMainWindow *main_window)
1550 TnyFolderStore *folder;
1551 GtkWidget *folder_view;
1553 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1555 folder_view = modest_main_window_get_child_widget (main_window,
1556 MODEST_WIDGET_TYPE_FOLDER_VIEW);
1560 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
1562 if (folder && TNY_IS_FOLDER (folder)) {
1564 folder_name = ask_for_folder_name (GTK_WINDOW (main_window),
1565 _("Please enter a new name for the folder"));
1567 if (folder_name != NULL && strlen (folder_name) > 0) {
1568 ModestMailOperation *mail_op;
1570 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE);
1571 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
1574 modest_mail_operation_rename_folder (mail_op,
1575 TNY_FOLDER (folder),
1576 (const gchar *) folder_name);
1578 g_object_unref (mail_op);
1579 g_free (folder_name);
1581 g_object_unref (folder);
1586 delete_folder (ModestMainWindow *main_window, gboolean move_to_trash)
1588 TnyFolderStore *folder;
1589 GtkWidget *folder_view;
1593 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1595 folder_view = modest_main_window_get_child_widget (main_window,
1596 MODEST_WIDGET_TYPE_FOLDER_VIEW);
1600 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
1603 message = g_strdup_printf (_("mcen_nc_delete_folder_text"),
1604 tny_folder_get_name (TNY_FOLDER (folder)));
1605 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (main_window),
1606 (const gchar *) message);
1609 if (response == GTK_RESPONSE_OK) {
1610 ModestMailOperation *mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_DELETE);
1612 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
1614 modest_mail_operation_remove_folder (mail_op, TNY_FOLDER (folder), move_to_trash);
1616 /* Show error if happened */
1617 if (modest_mail_operation_get_error (mail_op))
1618 modest_platform_run_information_dialog (GTK_WINDOW (main_window),
1619 MODEST_INFORMATION_DELETE_FOLDER);
1621 g_object_unref (G_OBJECT (mail_op));
1624 g_object_unref (G_OBJECT (folder));
1628 modest_ui_actions_on_delete_folder (GtkAction *action,
1629 ModestMainWindow *main_window)
1631 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1633 delete_folder (main_window, FALSE);
1637 modest_ui_actions_on_move_folder_to_trash_folder (GtkAction *action, ModestMainWindow *main_window)
1639 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1641 delete_folder (main_window, TRUE);
1645 modest_ui_actions_on_password_requested (TnyAccountStore *account_store,
1646 const gchar* account_name,
1650 ModestMainWindow *main_window)
1653 GtkWidget *dialog, *entry, *remember_pass_check;
1655 dialog = gtk_dialog_new_with_buttons (_("Password requested"),
1659 GTK_RESPONSE_REJECT,
1661 GTK_RESPONSE_ACCEPT,
1663 gtk_window_set_transient_for (GTK_WINDOW(dialog), GTK_WINDOW(main_window));
1665 txt = g_strdup_printf (_("Please enter your password for %s"), account_name);
1666 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), gtk_label_new(txt),
1670 entry = gtk_entry_new_with_max_length (40);
1671 gtk_entry_set_visibility (GTK_ENTRY(entry), FALSE);
1672 gtk_entry_set_invisible_char (GTK_ENTRY(entry), 0x2022); /* bullet unichar */
1674 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry,
1677 remember_pass_check = gtk_check_button_new_with_label (_("Remember password"));
1678 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), remember_pass_check,
1681 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
1683 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
1684 *password = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry)));
1691 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (remember_pass_check)))
1696 gtk_widget_destroy (dialog);
1700 modest_ui_actions_on_cut (GtkAction *action,
1701 ModestWindow *window)
1703 GtkWidget *focused_widget;
1705 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
1706 if (GTK_IS_EDITABLE (focused_widget)) {
1707 gtk_editable_cut_clipboard (GTK_EDITABLE(focused_widget));
1708 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
1709 GtkTextBuffer *buffer;
1710 GtkClipboard *clipboard;
1712 clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
1713 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
1714 gtk_text_buffer_cut_clipboard (buffer, clipboard, TRUE);
1719 modest_ui_actions_on_copy (GtkAction *action,
1720 ModestWindow *window)
1722 GtkClipboard *clipboard;
1723 GtkWidget *focused_widget;
1725 clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
1726 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
1727 if (GTK_IS_LABEL (focused_widget)) {
1728 gtk_clipboard_set_text (clipboard, gtk_label_get_text (GTK_LABEL (focused_widget)), -1);
1729 } else if (GTK_IS_EDITABLE (focused_widget)) {
1730 gtk_editable_copy_clipboard (GTK_EDITABLE(focused_widget));
1731 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
1732 GtkTextBuffer *buffer;
1734 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
1735 gtk_text_buffer_copy_clipboard (buffer, clipboard);
1740 modest_ui_actions_on_undo (GtkAction *action,
1741 ModestWindow *window)
1743 if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
1744 modest_msg_edit_window_undo (MODEST_MSG_EDIT_WINDOW (window));
1746 g_return_if_reached ();
1751 modest_ui_actions_on_paste (GtkAction *action,
1752 ModestWindow *window)
1754 GtkWidget *focused_widget;
1756 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
1757 if (GTK_IS_EDITABLE (focused_widget)) {
1758 gtk_editable_paste_clipboard (GTK_EDITABLE(focused_widget));
1759 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
1760 GtkTextBuffer *buffer;
1761 GtkClipboard *clipboard;
1763 clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
1764 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
1765 gtk_text_buffer_paste_clipboard (buffer, clipboard, NULL, TRUE);
1770 modest_ui_actions_on_select_all (GtkAction *action,
1771 ModestWindow *window)
1773 GtkWidget *focused_widget;
1775 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
1776 if (GTK_IS_LABEL (focused_widget)) {
1777 gtk_label_select_region (GTK_LABEL (focused_widget), 0, -1);
1778 } else if (GTK_IS_EDITABLE (focused_widget)) {
1779 gtk_editable_select_region (GTK_EDITABLE(focused_widget), 0, -1);
1780 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
1781 GtkTextBuffer *buffer;
1782 GtkTextIter start, end;
1784 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
1785 gtk_text_buffer_get_start_iter (buffer, &start);
1786 gtk_text_buffer_get_end_iter (buffer, &end);
1787 gtk_text_buffer_select_range (buffer, &start, &end);
1792 modest_ui_actions_on_change_zoom (GtkRadioAction *action,
1793 GtkRadioAction *selected,
1794 ModestWindow *window)
1798 value = gtk_radio_action_get_current_value (selected);
1799 if (MODEST_IS_WINDOW (window)) {
1800 modest_window_set_zoom (MODEST_WINDOW (window), ((gdouble)value)/100);
1804 void modest_ui_actions_msg_edit_on_change_priority (GtkRadioAction *action,
1805 GtkRadioAction *selected,
1806 ModestWindow *window)
1808 TnyHeaderFlags flags;
1809 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1811 flags = gtk_radio_action_get_current_value (selected);
1812 modest_msg_edit_window_set_priority_flags (MODEST_MSG_EDIT_WINDOW (window), flags);
1815 void modest_ui_actions_msg_edit_on_change_file_format (GtkRadioAction *action,
1816 GtkRadioAction *selected,
1817 ModestWindow *window)
1821 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1823 file_format = gtk_radio_action_get_current_value (selected);
1824 modest_msg_edit_window_set_file_format (MODEST_MSG_EDIT_WINDOW (window), file_format);
1829 modest_ui_actions_on_zoom_plus (GtkAction *action,
1830 ModestWindow *window)
1832 g_return_if_fail (MODEST_IS_WINDOW (window));
1834 modest_window_zoom_plus (MODEST_WINDOW (window));
1838 modest_ui_actions_on_zoom_minus (GtkAction *action,
1839 ModestWindow *window)
1841 g_return_if_fail (MODEST_IS_WINDOW (window));
1843 modest_window_zoom_minus (MODEST_WINDOW (window));
1847 modest_ui_actions_on_toggle_fullscreen (GtkToggleAction *toggle,
1848 ModestWindow *window)
1850 ModestWindowMgr *mgr;
1851 gboolean fullscreen, active;
1852 g_return_if_fail (MODEST_IS_WINDOW (window));
1854 mgr = modest_runtime_get_window_mgr ();
1856 active = (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle)))?1:0;
1857 fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
1859 if (active != fullscreen) {
1860 modest_window_mgr_set_fullscreen_mode (mgr, active);
1861 gtk_window_present (GTK_WINDOW (window));
1866 modest_ui_actions_on_change_fullscreen (GtkAction *action,
1867 ModestWindow *window)
1869 ModestWindowMgr *mgr;
1870 gboolean fullscreen;
1872 g_return_if_fail (MODEST_IS_WINDOW (window));
1874 mgr = modest_runtime_get_window_mgr ();
1875 fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
1876 modest_window_mgr_set_fullscreen_mode (mgr, !fullscreen);
1878 gtk_window_present (GTK_WINDOW (window));
1882 * Show the header details in a ModestDetailsDialog widget
1885 show_header_details (TnyHeader *header,
1891 dialog = modest_details_dialog_new_with_header (window, header);
1894 gtk_widget_show_all (dialog);
1895 gtk_dialog_run (GTK_DIALOG (dialog));
1897 gtk_widget_destroy (dialog);
1901 * Show the folder details in a ModestDetailsDialog widget
1904 show_folder_details (TnyFolder *folder,
1910 dialog = modest_details_dialog_new_with_folder (window, folder);
1913 gtk_widget_show_all (dialog);
1914 gtk_dialog_run (GTK_DIALOG (dialog));
1916 gtk_widget_destroy (dialog);
1921 modest_ui_actions_on_details (GtkAction *action,
1924 TnyList * headers_list;
1928 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
1931 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW (win));
1935 headers_list = get_selected_headers (win);
1939 iter = tny_list_create_iterator (headers_list);
1941 header = TNY_HEADER (tny_iterator_get_current (iter));
1942 show_header_details (header, GTK_WINDOW (win));
1943 g_object_unref (header);
1945 g_object_unref (iter);
1947 } else if (MODEST_IS_MAIN_WINDOW (win)) {
1948 GtkWidget *folder_view, *header_view;
1950 /* Check which widget has the focus */
1951 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
1952 MODEST_WIDGET_TYPE_FOLDER_VIEW);
1953 if (gtk_widget_is_focus (folder_view)) {
1956 folder = (TnyFolder *) modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
1958 /* Show only when it's a folder */
1959 if (!folder || !TNY_IS_FOLDER (folder))
1962 show_folder_details (folder, GTK_WINDOW (win));
1965 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
1966 MODEST_WIDGET_TYPE_HEADER_VIEW);
1967 if (!gtk_widget_is_focus (header_view))
1970 headers_list = get_selected_headers (win);
1974 iter = tny_list_create_iterator (headers_list);
1975 while (!tny_iterator_is_done (iter)) {
1977 header = TNY_HEADER (tny_iterator_get_current (iter));
1978 show_header_details (header, GTK_WINDOW (win));
1979 g_object_unref (header);
1981 tny_iterator_next (iter);
1983 g_object_unref (iter);
1989 modest_ui_actions_on_toggle_show_cc (GtkToggleAction *toggle,
1990 ModestMsgEditWindow *window)
1992 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1994 modest_msg_edit_window_show_cc (window, gtk_toggle_action_get_active (toggle));
1998 modest_ui_actions_on_toggle_show_bcc (GtkToggleAction *toggle,
1999 ModestMsgEditWindow *window)
2001 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2003 modest_msg_edit_window_show_bcc (window, gtk_toggle_action_get_active (toggle));
2007 modest_ui_actions_toggle_folders_view (GtkAction *action,
2008 ModestMainWindow *main_window)
2012 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2014 conf = modest_runtime_get_conf ();
2016 if (modest_main_window_get_style (main_window) == MODEST_MAIN_WINDOW_STYLE_SPLIT)
2017 modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SIMPLE);
2019 modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SPLIT);
2023 modest_ui_actions_on_toggle_toolbar (GtkToggleAction *toggle,
2024 ModestWindow *window)
2026 gboolean active, fullscreen = FALSE;
2027 ModestWindowMgr *mgr;
2029 active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle));
2031 /* Check if we want to toggle the toolbar vuew in fullscreen
2033 if (!strcmp (gtk_action_get_name (GTK_ACTION (toggle)),
2034 "ViewShowToolbarFullScreen")) {
2038 /* Toggle toolbar */
2039 mgr = modest_runtime_get_window_mgr ();
2040 modest_window_mgr_show_toolbars (mgr, active, fullscreen);
2044 modest_ui_actions_msg_edit_on_select_font (GtkAction *action,
2045 ModestMsgEditWindow *window)
2047 modest_msg_edit_window_select_font (window);
2051 modest_ui_actions_on_folder_display_name_changed (ModestFolderView *folder_view,
2052 const gchar *display_name,
2055 /* Do not change the application name if the widget has not
2056 the focus. This callback could be called even if the folder
2057 view has not the focus, because the handled signal could be
2058 emitted when the folder view is redrawn */
2059 if (gtk_widget_is_focus (GTK_WIDGET (folder_view))) {
2061 gtk_window_set_title (window, display_name);
2063 gtk_window_set_title (window, " ");
2068 modest_ui_actions_on_select_contacts (GtkAction *action, ModestMsgEditWindow *window)
2070 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2071 modest_msg_edit_window_select_contacts (window);
2075 modest_ui_actions_on_check_names (GtkAction *action, ModestMsgEditWindow *window)
2077 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2078 modest_msg_edit_window_check_names (window);
2083 create_move_to_dialog (ModestWindow *win,
2084 GtkWidget *folder_view,
2085 GtkWidget **tree_view)
2087 GtkWidget *dialog, *scroll;
2089 dialog = gtk_dialog_new_with_buttons (_("mcen_ti_moveto_folders_title"),
2091 GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR | GTK_DIALOG_DESTROY_WITH_PARENT,
2093 GTK_RESPONSE_ACCEPT,
2095 GTK_RESPONSE_REJECT,
2098 /* Create scrolled window */
2099 scroll = gtk_scrolled_window_new (NULL, NULL);
2100 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll),
2101 GTK_POLICY_AUTOMATIC,
2102 GTK_POLICY_AUTOMATIC);
2104 /* Create folder view */
2105 *tree_view = modest_folder_view_new (NULL);
2106 gtk_tree_view_set_model (GTK_TREE_VIEW (*tree_view),
2107 gtk_tree_view_get_model (GTK_TREE_VIEW (folder_view)));
2108 gtk_container_add (GTK_CONTAINER (scroll), *tree_view);
2110 /* Add scroll to dialog */
2111 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
2112 scroll, FALSE, FALSE, 0);
2114 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
2120 * Returns TRUE if at least one of the headers of the list belongs to
2121 * a message that has been fully retrieved.
2124 has_retrieved_msgs (TnyList *list)
2127 gboolean found = FALSE;
2129 iter = tny_list_create_iterator (list);
2130 while (tny_iterator_is_done (iter) && !found) {
2132 TnyHeaderFlags flags;
2134 header = TNY_HEADER (tny_iterator_get_current (iter));
2135 flags = tny_header_get_flags (header);
2136 if (!(flags & TNY_HEADER_FLAG_PARTIAL))
2140 tny_iterator_next (iter);
2142 g_object_unref (iter);
2148 * Shows a confirmation dialog to the user when we're moving messages
2149 * from a remote server to the local storage. Returns the dialog
2150 * response. If it's other kind of movement the it always returns
2154 msgs_move_to_confirmation (GtkWindow *win,
2155 TnyFolder *dest_folder,
2158 gint response = GTK_RESPONSE_OK;
2160 /* If the destination is a local folder */
2161 if (modest_tny_folder_is_local_folder (dest_folder)) {
2162 TnyFolder *src_folder;
2166 /* Get source folder */
2167 iter = tny_list_create_iterator (headers);
2168 header = TNY_HEADER (tny_iterator_get_current (iter));
2169 src_folder = tny_header_get_folder (header);
2170 g_object_unref (header);
2171 g_object_unref (iter);
2173 /* If the source is a remote folder */
2174 if (!modest_tny_folder_is_local_folder (src_folder)) {
2175 const gchar *message;
2177 if (tny_list_get_length (headers) == 1)
2178 if (has_retrieved_msgs (headers))
2179 message = _("mcen_nc_move_retrieve");
2181 message = _("mcen_nc_move_header");
2183 if (has_retrieved_msgs (headers))
2184 message = _("mcen_nc_move_retrieves");
2186 message = _("mcen_nc_move_headers");
2188 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
2189 (const gchar *) message);
2196 * UI handler for the "Move to" action when invoked from the
2200 modest_ui_actions_on_main_window_move_to (GtkAction *action,
2201 ModestMainWindow *win)
2203 GtkWidget *dialog, *folder_view, *tree_view = NULL;
2205 TnyFolderStore *folder_store;
2206 ModestMailOperation *mail_op = NULL;
2208 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win));
2210 /* Get the folder view */
2211 folder_view = modest_main_window_get_child_widget (win,
2212 MODEST_WIDGET_TYPE_FOLDER_VIEW);
2214 /* Create and run the dialog */
2215 dialog = create_move_to_dialog (MODEST_WINDOW (win), folder_view, &tree_view);
2216 result = gtk_dialog_run (GTK_DIALOG(dialog));
2218 /* We do this to save an indentation level ;-) */
2219 if (result != GTK_RESPONSE_ACCEPT)
2222 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (tree_view));
2224 if (TNY_IS_ACCOUNT (folder_store))
2227 /* Get folder or messages to transfer */
2228 if (gtk_widget_is_focus (folder_view)) {
2229 TnyFolderStore *src_folder;
2230 src_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
2232 if (TNY_IS_FOLDER (src_folder)) {
2233 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE);
2234 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
2237 modest_mail_operation_xfer_folder (mail_op,
2238 TNY_FOLDER (src_folder),
2241 g_object_unref (G_OBJECT (mail_op));
2245 g_object_unref (G_OBJECT (src_folder));
2247 GtkWidget *header_view;
2248 header_view = modest_main_window_get_child_widget (win,
2249 MODEST_WIDGET_TYPE_HEADER_VIEW);
2250 if (gtk_widget_is_focus (header_view)) {
2254 headers = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW (header_view));
2256 /* Ask for user confirmation */
2257 response = msgs_move_to_confirmation (GTK_WINDOW (win),
2258 TNY_FOLDER (folder_store),
2261 /* Transfer messages */
2262 if (response == GTK_RESPONSE_OK) {
2263 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE);
2264 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
2267 modest_mail_operation_xfer_msgs (mail_op,
2269 TNY_FOLDER (folder_store),
2271 g_object_unref (G_OBJECT (mail_op));
2275 g_object_unref (folder_store);
2278 gtk_widget_destroy (dialog);
2283 * UI handler for the "Move to" action when invoked from the
2284 * ModestMsgViewWindow
2287 modest_ui_actions_on_msg_view_window_move_to (GtkAction *action,
2288 ModestMsgViewWindow *win)
2290 GtkWidget *dialog, *folder_view, *tree_view = NULL;
2292 ModestMainWindow *main_window;
2297 /* Get the folder view */
2298 main_window = MODEST_MAIN_WINDOW (modest_window_mgr_get_main_window (modest_runtime_get_window_mgr ()));
2299 folder_view = modest_main_window_get_child_widget (main_window,
2300 MODEST_WIDGET_TYPE_FOLDER_VIEW);
2302 /* Create and run the dialog */
2303 dialog = create_move_to_dialog (MODEST_WINDOW (win), folder_view, &tree_view);
2304 result = gtk_dialog_run (GTK_DIALOG(dialog));
2306 if (result == GTK_RESPONSE_ACCEPT) {
2307 TnyFolderStore *folder_store;
2310 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (tree_view));
2312 /* Create header list */
2313 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW (win));
2314 header = tny_msg_get_header (msg);
2315 headers = tny_simple_list_new ();
2316 tny_list_prepend (headers, G_OBJECT (header));
2317 g_object_unref (header);
2318 g_object_unref (msg);
2320 /* Ask user for confirmation. MSG-NOT404 */
2321 response = msgs_move_to_confirmation (GTK_WINDOW (win),
2322 TNY_FOLDER (folder_store),
2325 /* Transfer current msg */
2326 if (response == GTK_RESPONSE_OK) {
2327 ModestMailOperation *mail_op;
2329 /* Create mail op */
2330 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE);
2331 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
2334 /* Transfer messages */
2335 modest_mail_operation_xfer_msgs (mail_op,
2337 TNY_FOLDER (folder_store),
2339 g_object_unref (G_OBJECT (mail_op));
2341 g_object_unref (headers);
2343 g_object_unref (folder_store);
2345 gtk_widget_destroy (dialog);
2349 modest_ui_actions_on_move_to (GtkAction *action,
2352 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win) ||
2353 MODEST_IS_MSG_VIEW_WINDOW (win));
2355 if (MODEST_IS_MAIN_WINDOW (win))
2356 modest_ui_actions_on_main_window_move_to (action,
2357 MODEST_MAIN_WINDOW (win));
2359 modest_ui_actions_on_msg_view_window_move_to (action,
2360 MODEST_MSG_VIEW_WINDOW (win));