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 #ifdef MODEST_PLATFORM_MAEMO
48 #include "maemo/modest-osso-state-saving.h"
49 #include "maemo/modest-maemo-ui-constants.h"
50 #endif /* MODEST_PLATFORM_MAEMO */
53 #include <widgets/modest-main-window.h>
54 #include <widgets/modest-msg-view-window.h>
55 #include <widgets/modest-account-view-window.h>
56 #include <widgets/modest-details-dialog.h>
58 #include "modest-account-mgr-helpers.h"
59 #include "modest-mail-operation.h"
60 #include "modest-text-utils.h"
62 #ifdef MODEST_HAVE_EASYSETUP
63 #include "easysetup/modest-easysetup-wizard.h"
64 #endif /* MODEST_HAVE_EASYSETUP */
66 #include <modest-widget-memory.h>
67 #include <tny-error.h>
68 #include <tny-simple-list.h>
69 #include <tny-msg-view.h>
70 #include <tny-device.h>
72 typedef struct _GetMsgAsyncHelper {
74 ModestMailOperation *mail_op;
81 typedef enum _ReplyForwardAction {
87 typedef struct _ReplyForwardHelper {
88 guint reply_forward_type;
89 ReplyForwardAction action;
94 typedef struct _HeaderActivatedHelper {
98 } HeaderActivatedHelper;
101 * The do_headers_action uses this kind of functions to perform some
102 * action to each member of a list of headers
104 typedef void (*HeadersFunc) (TnyHeader *header, ModestWindow *win, gpointer user_data);
107 do_headers_action (ModestWindow *win,
112 static void open_msg_func (const GObject *obj, const TnyMsg *msg, gpointer user_data);
114 static void reply_forward_func (const GObject *obj, const TnyMsg *msg, gpointer user_data);
116 static void reply_forward (ReplyForwardAction action, ModestWindow *win);
118 static gchar* ask_for_folder_name (GtkWindow *parent_window, const gchar *title);
121 modest_ui_actions_on_about (GtkAction *action, ModestWindow *win)
124 const gchar *authors[] = {
125 "Dirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>",
128 about = gtk_about_dialog_new ();
129 gtk_about_dialog_set_name (GTK_ABOUT_DIALOG(about), PACKAGE_NAME);
130 gtk_about_dialog_set_version (GTK_ABOUT_DIALOG(about),PACKAGE_VERSION);
131 gtk_about_dialog_set_copyright (GTK_ABOUT_DIALOG(about),
132 _("Copyright (c) 2006, Nokia Corporation\n"
133 "All rights reserved."));
134 gtk_about_dialog_set_comments (GTK_ABOUT_DIALOG(about),
135 _("a modest e-mail client\n\n"
136 "design and implementation: Dirk-Jan C. Binnema\n"
137 "contributions from the fine people at KC and Ig\n"
138 "uses the tinymail email framework written by Philip van Hoof"));
139 gtk_about_dialog_set_authors (GTK_ABOUT_DIALOG(about), authors);
140 gtk_about_dialog_set_website (GTK_ABOUT_DIALOG(about), "http://modest.garage.maemo.org");
142 gtk_dialog_run (GTK_DIALOG (about));
143 gtk_widget_destroy(about);
148 get_selected_headers (ModestWindow *win)
150 if (MODEST_IS_MAIN_WINDOW(win)) {
151 GtkWidget *header_view;
153 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
154 MODEST_WIDGET_TYPE_HEADER_VIEW);
155 return modest_header_view_get_selected_headers (MODEST_HEADER_VIEW(header_view));
157 } else if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
158 /* for MsgViewWindows, we simply return a list with one element */
161 TnyList *list = NULL;
163 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW(win));
165 header = tny_msg_get_header (msg);
166 list = tny_simple_list_new ();
167 tny_list_prepend (list, G_OBJECT(header));
168 g_object_unref (G_OBJECT(header));
177 headers_action_delete (TnyHeader *header,
181 ModestMailOperation *mail_op;
183 /* TODO: add confirmation dialog */
184 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_DELETE, G_OBJECT(win));
185 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
188 /* Always delete. TODO: Move to trash still not supported */
189 modest_mail_operation_remove_msg (mail_op, header, FALSE);
190 g_object_unref (G_OBJECT (mail_op));
194 modest_ui_actions_on_delete (GtkAction *action, ModestWindow *win)
196 g_return_if_fail (MODEST_IS_WINDOW(win));
198 if (MODEST_IS_MSG_EDIT_WINDOW (win)) {
200 g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value);
204 /* Remove each header */
205 do_headers_action (win, headers_action_delete, NULL);
207 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
208 gtk_widget_destroy (GTK_WIDGET(win));
214 modest_ui_actions_on_quit (GtkAction *action, ModestWindow *win)
216 #ifdef MODEST_PLATFORM_MAEMO
217 modest_osso_save_state();
218 #endif /* MODEST_PLATFORM_MAEMO */
224 modest_ui_actions_on_close_window (GtkAction *action, ModestWindow *win)
226 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
227 gtk_widget_destroy (GTK_WIDGET (win));
228 } else if (MODEST_IS_MSG_EDIT_WINDOW (win)) {
230 g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value);
231 } else if (MODEST_IS_WINDOW (win)) {
232 gtk_widget_destroy (GTK_WIDGET (win));
234 g_return_if_reached ();
239 modest_ui_actions_on_add_to_contacts (GtkAction *action, ModestWindow *win)
241 GtkClipboard *clipboard = NULL;
242 gchar *selection = NULL;
244 clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
245 selection = gtk_clipboard_wait_for_text (clipboard);
247 modest_address_book_add_address (selection);
252 modest_ui_actions_on_accounts (GtkAction *action, ModestWindow *win)
255 /* This is currently only implemented for Maemo,
256 * because it requires a providers preset file which is not publically available.
258 #ifdef MODEST_PLATFORM_MAEMO /* Defined in config.h */
259 GSList *account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
260 TRUE /* enabled accounts only */);
261 gboolean accounts_exist = account_names != NULL;
262 g_slist_free (account_names);
264 if (!accounts_exist) {
265 /* If there are no accounts yet, just show the easy-setup wizard, as per the UI spec: */
266 ModestEasysetupWizardDialog *wizard = modest_easysetup_wizard_dialog_new ();
267 gtk_window_set_transient_for (GTK_WINDOW (wizard), GTK_WINDOW (win));
268 gtk_dialog_run (GTK_DIALOG (wizard));
269 gtk_widget_destroy (GTK_WIDGET (wizard));
271 /* Show the list of accounts: */
272 GtkDialog *account_win = GTK_DIALOG(modest_account_view_window_new ());
273 gtk_window_set_transient_for (GTK_WINDOW (account_win), GTK_WINDOW(win));
274 gtk_dialog_run (account_win);
275 gtk_widget_destroy (GTK_WIDGET(account_win));
278 GtkWidget *dialog, *label;
280 /* Create the widgets */
282 dialog = gtk_dialog_new_with_buttons ("Message",
284 GTK_DIALOG_DESTROY_WITH_PARENT,
288 label = gtk_label_new ("Hello World!");
290 /* Ensure that the dialog box is destroyed when the user responds. */
292 g_signal_connect_swapped (dialog, "response",
293 G_CALLBACK (gtk_widget_destroy),
296 /* Add the label, and show everything we've added to the dialog. */
298 gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox),
300 gtk_widget_show_all (dialog);
301 #endif /* MODEST_PLATFORM_MAEMO */
305 modest_ui_actions_on_new_msg (GtkAction *action, ModestWindow *win)
307 ModestWindow *msg_win;
309 TnyFolder *folder = NULL;
310 gchar *account_name = NULL;
311 gchar *from_str = NULL;
312 /* GError *err = NULL; */
313 TnyAccount *account = NULL;
314 ModestWindowMgr *mgr;
315 gchar *signature = NULL;
317 account_name = g_strdup(modest_window_get_active_account (win));
319 account_name = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
321 g_printerr ("modest: no account found\n");
325 account = modest_tny_account_store_get_tny_account_by_account (modest_runtime_get_account_store(),
327 TNY_ACCOUNT_TYPE_STORE);
329 g_printerr ("modest: failed to get tnyaccount for '%s'\n", account_name);
333 from_str = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(), account_name);
335 g_printerr ("modest: failed get from string for '%s'\n", account_name);
339 if (modest_account_mgr_get_bool (modest_runtime_get_account_mgr (), account_name,
340 MODEST_ACCOUNT_USE_SIGNATURE, FALSE)) {
341 signature = modest_account_mgr_get_string (modest_runtime_get_account_mgr (), account_name,
342 MODEST_ACCOUNT_SIGNATURE, FALSE);
344 signature = g_strdup ("");
347 msg = modest_tny_msg_new ("", from_str, "", "", "", signature, NULL);
349 g_printerr ("modest: failed to create new msg\n");
353 folder = modest_tny_account_get_special_folder (account, TNY_FOLDER_TYPE_DRAFTS);
355 g_printerr ("modest: failed to find Drafts folder\n");
359 /* tny_folder_add_msg (folder, msg, &err); */
361 /* g_printerr ("modest: error adding msg to Drafts folder: %s", */
363 /* g_error_free (err); */
367 /* Create and register edit window */
368 msg_win = modest_msg_edit_window_new (msg, account_name);
369 mgr = modest_runtime_get_window_mgr ();
370 modest_window_mgr_register_window (mgr, msg_win);
373 gtk_window_set_transient_for (GTK_WINDOW (msg_win),
375 gtk_widget_show_all (GTK_WIDGET (msg_win));
378 g_free (account_name);
382 g_object_unref (G_OBJECT(account));
384 g_object_unref (G_OBJECT(msg));
386 g_object_unref (G_OBJECT(folder));
390 headers_action_open (TnyHeader *header,
394 modest_ui_actions_on_header_activated (MODEST_HEADER_VIEW (user_data),
396 MODEST_MAIN_WINDOW (win));
400 modest_ui_actions_on_open (GtkAction *action, ModestWindow *win)
402 GtkWidget *header_view;
404 /* Get header view */
405 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
406 MODEST_WIDGET_TYPE_HEADER_VIEW);
408 /* Open each message */
409 do_headers_action (win, headers_action_open, header_view);
414 open_msg_func (const GObject *obj, const TnyMsg *msg, gpointer user_data)
416 ModestWindowMgr *mgr = NULL;
417 ModestWindow *parent_win = NULL;
418 ModestWindow *win = NULL;
419 HeaderActivatedHelper *helper = NULL;
420 TnyFolderType folder_type = TNY_FOLDER_TYPE_UNKNOWN;
421 gchar *account = NULL;
423 g_return_if_fail (MODEST_IS_WINDOW(obj));
424 g_return_if_fail (user_data != NULL);
425 parent_win = MODEST_WINDOW(obj);
426 helper = (HeaderActivatedHelper *) user_data;
429 account = g_strdup(modest_window_get_active_account(MODEST_WINDOW(parent_win)));
431 account = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
433 /* Gets foldert type (OUTBOX headers will be opened in edit window */
434 if (modest_tny_folder_is_local_folder (helper->folder))
435 folder_type = modest_tny_folder_get_local_folder_type (helper->folder);
437 switch (folder_type) {
438 case TNY_FOLDER_TYPE_DRAFTS:
439 win = modest_msg_edit_window_new ((TnyMsg *) msg, account);
442 if (helper->model != NULL)
443 win = modest_msg_view_window_new_with_header_model ((TnyMsg *) msg, account, helper->model, helper->iter);
445 win = modest_msg_view_window_new ((TnyMsg *) msg, account);
448 /* Register and show new window */
450 mgr = modest_runtime_get_window_mgr ();
451 modest_window_mgr_register_window (mgr, win);
452 gtk_window_set_transient_for (GTK_WINDOW (win), GTK_WINDOW (parent_win));
453 gtk_widget_show_all (GTK_WIDGET(win));
458 /* g_object_unref (G_OBJECT(msg)); */
459 g_object_unref (G_OBJECT(helper->folder));
460 g_slice_free (HeaderActivatedHelper, helper);
464 reply_forward_func (const GObject *obj, const TnyMsg *msg, gpointer user_data)
467 ReplyForwardHelper *rf_helper;
468 ModestWindow *msg_win;
469 ModestEditType edit_type;
472 TnyFolder *folder = NULL;
473 TnyAccount *account = NULL;
474 ModestWindowMgr *mgr;
475 gchar *signature = NULL;
477 g_return_if_fail (user_data != NULL);
478 rf_helper = (ReplyForwardHelper *) user_data;
480 rf_helper->pending_ops--;
482 from = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(),
483 rf_helper->account_name);
484 if (modest_account_mgr_get_bool (modest_runtime_get_account_mgr(),
485 rf_helper->account_name,
486 MODEST_ACCOUNT_USE_SIGNATURE, FALSE)) {
487 signature = modest_account_mgr_get_string (modest_runtime_get_account_mgr (),
488 rf_helper->account_name,
489 MODEST_ACCOUNT_SIGNATURE, FALSE);
492 /* Create reply mail */
493 switch (rf_helper->action) {
496 modest_tny_msg_create_reply_msg ((TnyMsg *) msg, from, signature,
497 rf_helper->reply_forward_type,
498 MODEST_TNY_MSG_REPLY_MODE_SENDER);
500 case ACTION_REPLY_TO_ALL:
502 modest_tny_msg_create_reply_msg ((TnyMsg *) msg, from, signature, rf_helper->reply_forward_type,
503 MODEST_TNY_MSG_REPLY_MODE_ALL);
504 edit_type = MODEST_EDIT_TYPE_REPLY;
508 modest_tny_msg_create_forward_msg ((TnyMsg *) msg, from, signature, rf_helper->reply_forward_type);
509 edit_type = MODEST_EDIT_TYPE_FORWARD;
512 g_return_if_reached ();
519 g_printerr ("modest: failed to create message\n");
523 account = modest_tny_account_store_get_tny_account_by_account (modest_runtime_get_account_store(),
524 rf_helper->account_name,
525 TNY_ACCOUNT_TYPE_STORE);
527 g_printerr ("modest: failed to get tnyaccount for '%s'\n", rf_helper->account_name);
531 folder = modest_tny_account_get_special_folder (account, TNY_FOLDER_TYPE_DRAFTS);
533 g_printerr ("modest: failed to find Drafts folder\n");
537 tny_folder_add_msg (folder, (TnyMsg *) msg, &err);
539 g_printerr ("modest: error adding msg to Drafts folder: %s",
545 /* Create and register the windows */
546 msg_win = modest_msg_edit_window_new (new_msg, rf_helper->account_name);
547 mgr = modest_runtime_get_window_mgr ();
548 modest_window_mgr_register_window (mgr, msg_win);
550 /* Show edit window */
551 gtk_widget_show_all (GTK_WIDGET (msg_win));
555 g_object_unref (G_OBJECT (new_msg));
557 g_object_unref (G_OBJECT (folder));
559 g_object_unref (G_OBJECT (account));
561 if (rf_helper->pending_ops == 0) {
562 g_free (rf_helper->account_name);
563 g_slice_free (ReplyForwardHelper, rf_helper);
567 * Common code for the reply and forward actions
570 reply_forward (ReplyForwardAction action, ModestWindow *win)
572 ModestMailOperation *mail_op = NULL;
573 TnyList *header_list = NULL;
574 ReplyForwardHelper *rf_helper = NULL;
575 guint reply_forward_type;
577 g_return_if_fail (MODEST_IS_WINDOW(win));
579 header_list = get_selected_headers (win);
583 reply_forward_type = modest_conf_get_int (modest_runtime_get_conf (),
584 (action == ACTION_FORWARD) ? MODEST_CONF_FORWARD_TYPE : MODEST_CONF_REPLY_TYPE,
586 /* We assume that we can only select messages of the
587 same folder and that we reply all of them from the
588 same account. In fact the interface currently only
589 allows single selection */
592 rf_helper = g_slice_new0 (ReplyForwardHelper);
593 rf_helper->reply_forward_type = reply_forward_type;
594 rf_helper->action = action;
595 rf_helper->pending_ops = tny_list_get_length (header_list);
596 rf_helper->account_name = g_strdup (modest_window_get_active_account (win));
597 if (!rf_helper->account_name)
598 rf_helper->account_name =
599 modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
601 if (MODEST_IS_MSG_VIEW_WINDOW(win)) {
603 msg = modest_msg_view_window_get_message(MODEST_MSG_VIEW_WINDOW(win));
605 g_printerr ("modest: no message found\n");
608 reply_forward_func (G_OBJECT(win), msg, rf_helper);
611 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE, G_OBJECT(win));
612 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
613 modest_mail_operation_process_msg (mail_op, header_list, reply_forward_func, rf_helper);
616 g_object_unref(mail_op);
621 modest_ui_actions_on_reply (GtkAction *action, ModestWindow *win)
623 g_return_if_fail (MODEST_IS_WINDOW(win));
625 reply_forward (ACTION_REPLY, win);
629 modest_ui_actions_on_forward (GtkAction *action, ModestWindow *win)
631 g_return_if_fail (MODEST_IS_WINDOW(win));
633 reply_forward (ACTION_FORWARD, win);
637 modest_ui_actions_on_reply_all (GtkAction *action, ModestWindow *win)
639 g_return_if_fail (MODEST_IS_WINDOW(win));
641 reply_forward (ACTION_REPLY_TO_ALL, win);
645 modest_ui_actions_on_next (GtkAction *action,
646 ModestWindow *window)
648 if (MODEST_IS_MAIN_WINDOW (window)) {
649 GtkWidget *header_view;
651 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
652 MODEST_WIDGET_TYPE_HEADER_VIEW);
656 modest_header_view_select_next (MODEST_HEADER_VIEW(header_view));
657 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
658 modest_msg_view_window_select_next_message (MODEST_MSG_VIEW_WINDOW (window));
660 g_return_if_reached ();
665 modest_ui_actions_on_prev (GtkAction *action,
666 ModestWindow *window)
668 g_return_if_fail (MODEST_IS_WINDOW(window));
670 if (MODEST_IS_MAIN_WINDOW (window)) {
671 GtkWidget *header_view;
672 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
673 MODEST_WIDGET_TYPE_HEADER_VIEW);
677 modest_header_view_select_prev (MODEST_HEADER_VIEW(header_view));
678 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
679 modest_msg_view_window_select_previous_message (MODEST_MSG_VIEW_WINDOW (window));
681 g_return_if_reached ();
686 modest_ui_actions_on_sort (GtkAction *action,
687 ModestWindow *window)
689 g_return_if_fail (MODEST_IS_WINDOW(window));
691 if (MODEST_IS_MAIN_WINDOW (window)) {
692 GtkWidget *header_view;
693 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
694 MODEST_WIDGET_TYPE_HEADER_VIEW);
698 /* Show sorting dialog */
699 modest_platform_run_sort_dialog (GTK_WINDOW (window), MODEST_SORT_HEADERS);
705 action_send (const gchar* account_name)
707 TnyAccount *tny_account;
708 ModestTnySendQueue *send_queue;
710 g_return_val_if_fail (account_name, FALSE);
712 /* Get the transport account according to the open connection,
713 * because the account might specify connection-specific SMTP servers.
716 modest_tny_account_store_get_transport_account_for_open_connection (modest_runtime_get_account_store(),
719 g_printerr ("modest: cannot get tny transport account for %s\n", account_name);
723 send_queue = modest_tny_send_queue_new (TNY_CAMEL_TRANSPORT_ACCOUNT(tny_account));
725 g_object_unref (G_OBJECT(tny_account));
726 g_printerr ("modest: cannot get send queue for %s\n", account_name);
730 modest_tny_send_queue_flush (send_queue);
732 g_object_unref (G_OBJECT(send_queue));
733 g_object_unref (G_OBJECT(tny_account));
740 action_receive (const gchar* account_name,
743 TnyAccount *tny_account;
744 ModestMailOperation *mail_op;
746 g_return_val_if_fail (account_name, FALSE);
749 modest_tny_account_store_get_tny_account_by_account (modest_runtime_get_account_store(),
751 TNY_ACCOUNT_TYPE_STORE);
753 g_printerr ("modest: cannot get tny store account for %s\n", account_name);
757 /* Create the mail operation */
758 /* TODO: The spec wants us to first do any pending deletions, before receiving. */
759 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE, G_OBJECT(win));
760 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
761 modest_mail_operation_update_account (mail_op, TNY_STORE_ACCOUNT(tny_account));
763 g_object_unref (G_OBJECT(tny_account));
764 g_object_unref (G_OBJECT (mail_op));
769 /** Check that an appropriate connection is open.
771 gboolean check_for_connection (const gchar *account_name)
773 TnyDevice *device = modest_runtime_get_device ();
776 g_assert (TNY_IS_MAEMO_CONIC_DEVICE (device));
778 TnyMaemoConicDevice *maemo_device = TNY_MAEMO_CONIC_DEVICE (device);
781 if (tny_device_is_online (device))
784 modest_platform_connect_and_wait (NULL);
786 /* TODO: Wait until a result. */
792 * This function performs the send & receive required actions. The
793 * window it's used to create the mail operation. Tipically it should
794 * be allways the main window, but we pass it as argument in order to
798 modest_ui_actions_do_send_receive (const gchar *account_name, ModestWindow *win)
800 gchar *acc_name = NULL;
802 /* If no account name was provided get the current account, if
803 there is none either then pick the default one */
805 acc_name = g_strdup (modest_window_get_active_account(win));
807 acc_name = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
809 g_printerr ("modest: cannot get default account\n");
813 acc_name = g_strdup (account_name);
816 /* Send & receive. Do not continue if no suitable connection
818 if (check_for_connection (acc_name)) {
819 /* As per the UI spec,
820 * for POP accounts, we should receive,
821 * for IMAP we should synchronize everything, including receiving,
822 * for SMTP we should send,
823 * first receiving, then sending:
825 if (!action_receive(acc_name, win))
826 g_printerr ("modest: failed to receive\n");
827 if (!action_send(acc_name))
828 g_printerr ("modest: failed to send\n");
835 * Refreshes all accounts. This function will be used by automatic
839 modest_ui_actions_do_send_receive_all (ModestWindow *win)
841 GSList *account_names, *iter;
843 account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
846 iter = account_names;
848 modest_ui_actions_do_send_receive ((const char*) iter->data, win);
849 iter = g_slist_next (iter);
852 g_slist_foreach (account_names, (GFunc) g_free, NULL);
853 g_slist_free (account_names);
857 * Handler of the click on Send&Receive button in the main toolbar
860 modest_ui_actions_on_send_receive (GtkAction *action, ModestWindow *win)
862 /* Check that at least one account exists: */
863 GSList *account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
864 TRUE /* enabled accounts only */);
865 gboolean accounts_exist = account_names != NULL;
866 g_slist_free (account_names);
868 /* If not, allow the user to create an account before trying to send/receive. */
870 modest_ui_actions_on_accounts (NULL, win);
872 /* Refresh the active account */
873 modest_ui_actions_do_send_receive (NULL, win);
878 modest_ui_actions_toggle_header_list_view (GtkAction *action, ModestMainWindow *main_window)
881 GtkWidget *header_view;
883 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
885 header_view = modest_main_window_get_child_widget (main_window,
886 MODEST_WIDGET_TYPE_HEADER_VIEW);
890 conf = modest_runtime_get_conf ();
892 /* what is saved/restored is depending on the style; thus; we save with
893 * old style, then update the style, and restore for this new style
895 modest_widget_memory_save (conf, G_OBJECT(header_view), MODEST_CONF_HEADER_VIEW_KEY);
897 if (modest_header_view_get_style
898 (MODEST_HEADER_VIEW(header_view)) == MODEST_HEADER_VIEW_STYLE_DETAILS)
899 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
900 MODEST_HEADER_VIEW_STYLE_TWOLINES);
902 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
903 MODEST_HEADER_VIEW_STYLE_DETAILS);
905 modest_widget_memory_restore (conf, G_OBJECT(header_view),
906 MODEST_CONF_HEADER_VIEW_KEY);
911 modest_ui_actions_on_header_selected (ModestHeaderView *header_view,
913 ModestMainWindow *main_window)
915 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
917 /* If no header has been selected then exit */
921 /* Update Main window title */
922 if (GTK_WIDGET_HAS_FOCUS (header_view)) {
923 const gchar *subject = tny_header_get_subject (header);
924 if (subject && strcmp (subject, ""))
925 gtk_window_set_title (GTK_WINDOW (main_window), subject);
927 gtk_window_set_title (GTK_WINDOW (main_window), _("mail_va_no_subject"));
932 modest_ui_actions_on_header_activated (ModestHeaderView *header_view,
934 ModestMainWindow *main_window)
936 ModestMailOperation *mail_op = NULL;
937 HeaderActivatedHelper *helper = NULL;
938 ModestWindowMgr *mgr = NULL;
939 ModestWindow *win = NULL;
940 GtkTreeModel *model = NULL;
942 GtkTreeSelection *sel = NULL;
943 GList *sel_list = NULL;
945 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
950 /* Look if we already have a message view for that header */
951 mgr = modest_runtime_get_window_mgr ();
952 win = modest_window_mgr_find_window_by_msguid (mgr, tny_header_get_uid (header));
956 helper = g_slice_new0 (HeaderActivatedHelper);
957 helper->folder = tny_header_get_folder (header);
958 helper->model = NULL;
960 /* Get headers tree model and selected iter to build message view */
961 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
962 sel_list = gtk_tree_selection_get_selected_rows (sel, &model);
963 if (sel_list != NULL) {
964 gtk_tree_model_get_iter (model, &iter, (GtkTreePath *) sel_list->data);
967 helper->model = model;
970 g_list_foreach (sel_list, (GFunc) gtk_tree_path_free, NULL);
971 g_list_free (sel_list);
974 /* New mail operation */
975 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE, G_OBJECT(main_window));
976 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
977 modest_mail_operation_get_msg (mail_op, header, open_msg_func, helper);
980 g_object_unref (mail_op);
984 modest_ui_actions_on_folder_selection_changed (ModestFolderView *folder_view,
985 TnyFolderStore *folder_store,
987 ModestMainWindow *main_window)
990 GtkWidget *header_view;
992 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
994 header_view = modest_main_window_get_child_widget(main_window,
995 MODEST_WIDGET_TYPE_HEADER_VIEW);
999 conf = modest_runtime_get_conf ();
1001 if (TNY_IS_FOLDER (folder_store)) {
1004 modest_main_window_set_contents_style (main_window,
1005 MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS);
1006 modest_header_view_set_folder (MODEST_HEADER_VIEW(header_view),
1007 TNY_FOLDER (folder_store));
1008 modest_widget_memory_restore (conf, G_OBJECT(header_view),
1009 MODEST_CONF_HEADER_VIEW_KEY);
1011 modest_widget_memory_save (conf, G_OBJECT (header_view), MODEST_CONF_HEADER_VIEW_KEY);
1012 modest_header_view_set_folder (MODEST_HEADER_VIEW(header_view), NULL);
1014 } else if (TNY_IS_ACCOUNT (folder_store)) {
1016 modest_main_window_set_contents_style (main_window, MODEST_MAIN_WINDOW_CONTENTS_STYLE_DETAILS);
1021 modest_ui_actions_on_item_not_found (ModestHeaderView *header_view,ModestItemType type,
1028 item = (type == MODEST_ITEM_TYPE_FOLDER) ? "folder" : "message";
1030 if (g_main_depth > 0)
1031 gdk_threads_enter ();
1032 online = tny_device_is_online (modest_runtime_get_device());
1035 /* already online -- the item is simply not there... */
1036 dialog = gtk_message_dialog_new (GTK_WINDOW (win),
1038 GTK_MESSAGE_WARNING,
1040 _("The %s you selected cannot be found"),
1042 gtk_dialog_run (GTK_DIALOG(dialog));
1044 dialog = gtk_dialog_new_with_buttons (_("Connection requested"),
1048 GTK_RESPONSE_REJECT,
1050 GTK_RESPONSE_ACCEPT,
1052 txt = g_strdup_printf (_("This %s is not available in offline mode.\n"
1053 "Do you want to get online?"), item);
1054 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
1055 gtk_label_new (txt), FALSE, FALSE, 0);
1056 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
1059 gtk_window_set_default_size (GTK_WINDOW(dialog), 300, 300);
1060 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
1061 // modest_platform_connect_and_wait ();;
1064 gtk_widget_destroy (dialog);
1065 if (g_main_depth > 0)
1066 gdk_threads_leave ();
1070 modest_ui_actions_on_msg_link_hover (ModestMsgView *msgview, const gchar* link,
1073 /* g_message ("%s %s", __FUNCTION__, link); */
1078 modest_ui_actions_on_msg_link_clicked (ModestMsgView *msgview, const gchar* link,
1081 modest_platform_activate_uri (link);
1085 modest_ui_actions_on_msg_link_contextual (ModestMsgView *msgview, const gchar* link,
1088 modest_platform_show_uri_popup (link);
1092 modest_ui_actions_on_msg_attachment_clicked (ModestMsgView *msgview, TnyMimePart *mime_part,
1095 /* g_message (__FUNCTION__); */
1100 modest_ui_actions_on_msg_recpt_activated (ModestMsgView *msgview,
1101 const gchar *address,
1104 /* g_message ("%s %s", __FUNCTION__, address); */
1108 modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edit_window)
1110 TnyTransportAccount *transport_account;
1111 ModestMailOperation *mail_operation;
1113 gchar *account_name, *from;
1114 ModestAccountMgr *account_mgr;
1116 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window));
1118 data = modest_msg_edit_window_get_msg_data (edit_window);
1120 account_mgr = modest_runtime_get_account_mgr();
1121 account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
1123 account_name = modest_account_mgr_get_default_account (account_mgr);
1124 if (!account_name) {
1125 g_printerr ("modest: no account found\n");
1126 modest_msg_edit_window_free_msg_data (edit_window, data);
1130 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_tny_account_by_account
1131 (modest_runtime_get_account_store(),
1133 TNY_ACCOUNT_TYPE_TRANSPORT));
1134 if (!transport_account) {
1135 g_printerr ("modest: no transport account found for '%s'\n", account_name);
1136 g_free (account_name);
1137 modest_msg_edit_window_free_msg_data (edit_window, data);
1140 from = modest_account_mgr_get_from_string (account_mgr, account_name);
1142 /* Create the mail operation */
1143 mail_operation = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_INFO, G_OBJECT(edit_window));
1144 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
1146 modest_mail_operation_save_to_drafts (mail_operation,
1156 data->priority_flags);
1159 g_free (account_name);
1160 g_object_unref (G_OBJECT (transport_account));
1161 g_object_unref (G_OBJECT (mail_operation));
1163 modest_msg_edit_window_free_msg_data (edit_window, data);
1165 /* Save settings and close the window */
1166 gtk_widget_destroy (GTK_WIDGET (edit_window));
1169 modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
1171 TnyTransportAccount *transport_account;
1172 ModestMailOperation *mail_operation;
1174 gchar *account_name, *from;
1175 ModestAccountMgr *account_mgr;
1177 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window));
1179 if (!modest_msg_edit_window_check_names (edit_window))
1182 data = modest_msg_edit_window_get_msg_data (edit_window);
1184 /* FIXME: Code added just for testing. The final version will
1185 use the send queue provided by tinymail and some
1187 account_mgr = modest_runtime_get_account_mgr();
1188 account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
1190 account_name = modest_account_mgr_get_default_account (account_mgr);
1191 if (!account_name) {
1192 g_printerr ("modest: no account found\n");
1193 modest_msg_edit_window_free_msg_data (edit_window, data);
1197 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_transport_account_for_open_connection
1198 (modest_runtime_get_account_store(),
1200 if (!transport_account) {
1201 g_printerr ("modest: no transport account found for '%s'\n", account_name);
1202 g_free (account_name);
1203 modest_msg_edit_window_free_msg_data (edit_window, data);
1206 from = modest_account_mgr_get_from_string (account_mgr, account_name);
1208 /* Create the mail operation */
1209 mail_operation = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_SEND, G_OBJECT(edit_window));
1210 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
1212 modest_mail_operation_send_new_mail (mail_operation,
1222 data->priority_flags);
1225 g_free (account_name);
1226 g_object_unref (G_OBJECT (transport_account));
1227 g_object_unref (G_OBJECT (mail_operation));
1229 modest_msg_edit_window_free_msg_data (edit_window, data);
1231 /* Save settings and close the window */
1232 gtk_widget_destroy (GTK_WIDGET (edit_window));
1236 modest_ui_actions_on_toggle_bold (GtkToggleAction *action,
1237 ModestMsgEditWindow *window)
1239 ModestMsgEditFormatState *format_state = NULL;
1241 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1242 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
1244 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
1247 format_state = modest_msg_edit_window_get_format_state (window);
1248 g_return_if_fail (format_state != NULL);
1250 format_state->bold = gtk_toggle_action_get_active (action);
1251 modest_msg_edit_window_set_format_state (window, format_state);
1252 g_free (format_state);
1257 modest_ui_actions_on_toggle_italics (GtkToggleAction *action,
1258 ModestMsgEditWindow *window)
1260 ModestMsgEditFormatState *format_state = NULL;
1262 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1263 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
1265 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
1268 format_state = modest_msg_edit_window_get_format_state (window);
1269 g_return_if_fail (format_state != NULL);
1271 format_state->italics = gtk_toggle_action_get_active (action);
1272 modest_msg_edit_window_set_format_state (window, format_state);
1273 g_free (format_state);
1278 modest_ui_actions_on_toggle_bullets (GtkToggleAction *action,
1279 ModestMsgEditWindow *window)
1281 ModestMsgEditFormatState *format_state = NULL;
1283 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1284 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
1286 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
1289 format_state = modest_msg_edit_window_get_format_state (window);
1290 g_return_if_fail (format_state != NULL);
1292 format_state->bullet = gtk_toggle_action_get_active (action);
1293 modest_msg_edit_window_set_format_state (window, format_state);
1294 g_free (format_state);
1299 modest_ui_actions_on_change_justify (GtkRadioAction *action,
1300 GtkRadioAction *selected,
1301 ModestMsgEditWindow *window)
1303 ModestMsgEditFormatState *format_state = NULL;
1304 GtkJustification value;
1306 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1308 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
1311 value = gtk_radio_action_get_current_value (selected);
1313 format_state = modest_msg_edit_window_get_format_state (window);
1314 g_return_if_fail (format_state != NULL);
1316 format_state->justification = value;
1317 modest_msg_edit_window_set_format_state (window, format_state);
1318 g_free (format_state);
1322 modest_ui_actions_on_select_editor_color (GtkAction *action,
1323 ModestMsgEditWindow *window)
1325 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1326 g_return_if_fail (GTK_IS_ACTION (action));
1328 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
1331 modest_msg_edit_window_select_color (window);
1335 modest_ui_actions_on_select_editor_background_color (GtkAction *action,
1336 ModestMsgEditWindow *window)
1338 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1339 g_return_if_fail (GTK_IS_ACTION (action));
1341 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
1344 modest_msg_edit_window_select_background_color (window);
1348 modest_ui_actions_on_insert_image (GtkAction *action,
1349 ModestMsgEditWindow *window)
1351 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1352 g_return_if_fail (GTK_IS_ACTION (action));
1354 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
1357 modest_msg_edit_window_insert_image (window);
1361 * Shows a dialog with an entry that asks for some text. The returned
1362 * value must be freed by the caller. The dialog window title will be
1366 ask_for_folder_name (GtkWindow *parent_window,
1369 GtkWidget *dialog, *entry;
1370 gchar *folder_name = NULL;
1372 /* Ask for folder name */
1373 dialog = gtk_dialog_new_with_buttons (_("New Folder Name"),
1377 GTK_RESPONSE_REJECT,
1379 GTK_RESPONSE_ACCEPT,
1381 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
1382 gtk_label_new(title),
1385 entry = gtk_entry_new_with_max_length (40);
1386 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
1390 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
1392 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
1393 folder_name = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry)));
1395 gtk_widget_destroy (dialog);
1401 modest_ui_actions_on_new_folder (GtkAction *action, ModestMainWindow *main_window)
1403 TnyFolderStore *parent_folder;
1404 GtkWidget *folder_view;
1406 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1408 folder_view = modest_main_window_get_child_widget (main_window,
1409 MODEST_WIDGET_TYPE_FOLDER_VIEW);
1413 parent_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
1415 if (parent_folder) {
1416 gboolean finished = FALSE;
1418 gchar *folder_name = NULL, *suggested_name = NULL;
1420 /* Run the new folder dialog */
1422 result = modest_platform_run_new_folder_dialog (GTK_WINDOW (main_window),
1427 if (result == GTK_RESPONSE_REJECT) {
1430 ModestMailOperation *mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_INFO, G_OBJECT(main_window));
1431 TnyFolder *new_folder = NULL;
1433 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
1436 new_folder = modest_mail_operation_create_folder (mail_op,
1438 (const gchar *) folder_name);
1440 g_object_unref (new_folder);
1444 /* /\* TODO: check error and follow proper actions *\/ */
1445 /* /\* suggested_name = X; *\/ */
1446 /* /\* Show error to the user *\/ */
1447 /* modest_platform_run_information_dialog (GTK_WINDOW (main_window), */
1448 /* MODEST_INFORMATION_CREATE_FOLDER); */
1450 g_object_unref (mail_op);
1452 g_free (folder_name);
1456 g_object_unref (parent_folder);
1461 modest_ui_actions_on_rename_folder (GtkAction *action,
1462 ModestMainWindow *main_window)
1464 TnyFolderStore *folder;
1465 GtkWidget *folder_view;
1467 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1469 folder_view = modest_main_window_get_child_widget (main_window,
1470 MODEST_WIDGET_TYPE_FOLDER_VIEW);
1474 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
1476 if (folder && TNY_IS_FOLDER (folder)) {
1478 folder_name = ask_for_folder_name (GTK_WINDOW (main_window),
1479 _("Please enter a new name for the folder"));
1481 if (folder_name != NULL && strlen (folder_name) > 0) {
1482 ModestMailOperation *mail_op;
1484 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_INFO, G_OBJECT(main_window));
1485 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
1488 modest_mail_operation_rename_folder (mail_op,
1489 TNY_FOLDER (folder),
1490 (const gchar *) folder_name);
1492 g_object_unref (mail_op);
1493 g_free (folder_name);
1495 g_object_unref (folder);
1500 delete_folder (ModestMainWindow *main_window, gboolean move_to_trash)
1502 TnyFolderStore *folder;
1503 GtkWidget *folder_view;
1507 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1509 folder_view = modest_main_window_get_child_widget (main_window,
1510 MODEST_WIDGET_TYPE_FOLDER_VIEW);
1514 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
1517 message = g_strdup_printf (_("mcen_nc_delete_folder_text"),
1518 tny_folder_get_name (TNY_FOLDER (folder)));
1519 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (main_window),
1520 (const gchar *) message);
1523 if (response == GTK_RESPONSE_OK) {
1524 ModestMailOperation *mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_DELETE, G_OBJECT(main_window));
1526 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
1528 modest_mail_operation_remove_folder (mail_op, TNY_FOLDER (folder), move_to_trash);
1530 /* Show error if happened */
1531 if (modest_mail_operation_get_error (mail_op))
1532 modest_platform_run_information_dialog (GTK_WINDOW (main_window),
1533 MODEST_INFORMATION_DELETE_FOLDER);
1535 g_object_unref (G_OBJECT (mail_op));
1538 g_object_unref (G_OBJECT (folder));
1542 modest_ui_actions_on_delete_folder (GtkAction *action,
1543 ModestMainWindow *main_window)
1545 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1547 delete_folder (main_window, FALSE);
1551 modest_ui_actions_on_move_folder_to_trash_folder (GtkAction *action, ModestMainWindow *main_window)
1553 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1555 delete_folder (main_window, TRUE);
1559 modest_ui_actions_on_password_requested (TnyAccountStore *account_store,
1560 const gchar* server_account_name,
1565 ModestMainWindow *main_window)
1567 g_return_if_fail(server_account_name);
1568 /* printf("DEBUG: %s: server_account_name=%s\n", __FUNCTION__, server_account_name); */
1570 #ifdef MODEST_PLATFORM_MAEMO
1571 /* Maemo uses a different (awkward) button order,
1572 * It should probably just use gtk_alternative_dialog_button_order ().
1574 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
1578 GTK_RESPONSE_ACCEPT,
1580 GTK_RESPONSE_REJECT,
1583 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
1587 GTK_RESPONSE_REJECT,
1589 GTK_RESPONSE_ACCEPT,
1591 #endif /* MODEST_PLATFORM_MAEMO */
1593 gtk_window_set_transient_for (GTK_WINDOW(dialog), GTK_WINDOW(main_window));
1595 gchar *server_name = modest_server_account_get_hostname (
1596 modest_runtime_get_account_mgr(), server_account_name);
1598 /* This causes a warning because the logical ID has no %s in it,
1599 * though the translation does, but there is not much we can do about that: */
1600 gchar *txt = g_strdup_printf (_("mail_ia_password_info"), server_name);
1601 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), gtk_label_new(txt),
1604 g_free (server_name);
1608 gchar *initial_username = modest_server_account_get_username (
1609 modest_runtime_get_account_mgr(), server_account_name);
1611 GtkWidget *entry_username = gtk_entry_new ();
1612 if (initial_username)
1613 gtk_entry_set_text (GTK_ENTRY (entry_username), initial_username);
1614 /* Dim this if a connection has ever succeeded with this username,
1615 * as per the UI spec: */
1616 const gboolean username_known =
1617 modest_server_account_get_username_has_succeeded(
1618 modest_runtime_get_account_mgr(), server_account_name);
1619 gtk_widget_set_sensitive (entry_username, !username_known);
1621 #ifdef MODEST_PLATFORM_MAEMO
1622 /* Auto-capitalization is the default, so let's turn it off: */
1623 hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_username), HILDON_GTK_INPUT_MODE_FULL);
1625 /* Create a size group to be used by all captions.
1626 * Note that HildonCaption does not create a default size group if we do not specify one.
1627 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
1628 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
1630 GtkWidget *caption = hildon_caption_new (sizegroup,
1631 _("mail_fi_username"), entry_username, NULL, HILDON_CAPTION_MANDATORY);
1632 gtk_widget_show (entry_username);
1633 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
1634 FALSE, FALSE, MODEST_MARGIN_HALF);
1635 gtk_widget_show (caption);
1637 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry_username,
1639 #endif /* MODEST_PLATFORM_MAEMO */
1642 GtkWidget *entry_password = gtk_entry_new ();
1643 gtk_entry_set_visibility (GTK_ENTRY(entry_password), FALSE);
1644 gtk_entry_set_invisible_char (GTK_ENTRY(entry_password), 0x2022); /* bullet unichar */
1646 #ifdef MODEST_PLATFORM_MAEMO
1647 /* Auto-capitalization is the default, so let's turn it off: */
1648 hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_password), HILDON_GTK_INPUT_MODE_FULL);
1650 caption = hildon_caption_new (sizegroup,
1651 _("mail_fi_password"), entry_password, NULL, HILDON_CAPTION_MANDATORY);
1652 gtk_widget_show (entry_password);
1653 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
1654 FALSE, FALSE, MODEST_MARGIN_HALF);
1655 gtk_widget_show (caption);
1657 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry_password,
1659 #endif /* MODEST_PLATFORM_MAEMO */
1661 /* This is not in the Maemo UI spec:
1662 remember_pass_check = gtk_check_button_new_with_label (_("Remember password"));
1663 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), remember_pass_check,
1667 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
1669 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
1671 *username = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_username)));
1673 modest_server_account_set_username (
1674 modest_runtime_get_account_mgr(), server_account_name,
1677 const gboolean username_was_changed =
1678 (strcmp (*username, initial_username) != 0);
1679 if (username_was_changed) {
1680 /* To actually use a changed username,
1681 * we must reset the connection, according to pvanhoof.
1682 * This _might_ be a sensible way to do that: */
1683 TnyDevice *device = modest_runtime_get_device();
1684 tny_device_force_offline (device);
1685 tny_device_force_online (device);
1690 *password = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_password)));
1692 /* We do not save the password in the configuration,
1693 * because this function is only called for passwords that should
1694 * not be remembered:
1695 modest_server_account_set_password (
1696 modest_runtime_get_account_mgr(), server_account_name,
1715 /* This is not in the Maemo UI spec:
1716 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (remember_pass_check)))
1722 gtk_widget_destroy (dialog);
1726 modest_ui_actions_on_cut (GtkAction *action,
1727 ModestWindow *window)
1729 GtkWidget *focused_widget;
1731 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
1732 if (GTK_IS_EDITABLE (focused_widget)) {
1733 gtk_editable_cut_clipboard (GTK_EDITABLE(focused_widget));
1734 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
1735 GtkTextBuffer *buffer;
1736 GtkClipboard *clipboard;
1738 clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
1739 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
1740 gtk_text_buffer_cut_clipboard (buffer, clipboard, TRUE);
1745 modest_ui_actions_on_copy (GtkAction *action,
1746 ModestWindow *window)
1748 GtkClipboard *clipboard;
1749 GtkWidget *focused_widget;
1751 clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
1752 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
1753 if (GTK_IS_LABEL (focused_widget)) {
1754 gtk_clipboard_set_text (clipboard, gtk_label_get_text (GTK_LABEL (focused_widget)), -1);
1755 } else if (GTK_IS_EDITABLE (focused_widget)) {
1756 gtk_editable_copy_clipboard (GTK_EDITABLE(focused_widget));
1757 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
1758 GtkTextBuffer *buffer;
1760 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
1761 gtk_text_buffer_copy_clipboard (buffer, clipboard);
1766 modest_ui_actions_on_undo (GtkAction *action,
1767 ModestWindow *window)
1769 if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
1770 modest_msg_edit_window_undo (MODEST_MSG_EDIT_WINDOW (window));
1772 g_return_if_reached ();
1777 modest_ui_actions_on_paste (GtkAction *action,
1778 ModestWindow *window)
1780 GtkWidget *focused_widget;
1782 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
1783 if (GTK_IS_EDITABLE (focused_widget)) {
1784 gtk_editable_paste_clipboard (GTK_EDITABLE(focused_widget));
1785 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
1786 GtkTextBuffer *buffer;
1787 GtkClipboard *clipboard;
1789 clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
1790 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
1791 gtk_text_buffer_paste_clipboard (buffer, clipboard, NULL, TRUE);
1796 modest_ui_actions_on_select_all (GtkAction *action,
1797 ModestWindow *window)
1799 GtkWidget *focused_widget;
1801 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
1802 if (GTK_IS_LABEL (focused_widget)) {
1803 gtk_label_select_region (GTK_LABEL (focused_widget), 0, -1);
1804 } else if (GTK_IS_EDITABLE (focused_widget)) {
1805 gtk_editable_select_region (GTK_EDITABLE(focused_widget), 0, -1);
1806 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
1807 GtkTextBuffer *buffer;
1808 GtkTextIter start, end;
1810 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
1811 gtk_text_buffer_get_start_iter (buffer, &start);
1812 gtk_text_buffer_get_end_iter (buffer, &end);
1813 gtk_text_buffer_select_range (buffer, &start, &end);
1818 modest_ui_actions_on_change_zoom (GtkRadioAction *action,
1819 GtkRadioAction *selected,
1820 ModestWindow *window)
1824 value = gtk_radio_action_get_current_value (selected);
1825 if (MODEST_IS_WINDOW (window)) {
1826 modest_window_set_zoom (MODEST_WINDOW (window), ((gdouble)value)/100);
1830 void modest_ui_actions_msg_edit_on_change_priority (GtkRadioAction *action,
1831 GtkRadioAction *selected,
1832 ModestWindow *window)
1834 TnyHeaderFlags flags;
1835 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1837 flags = gtk_radio_action_get_current_value (selected);
1838 modest_msg_edit_window_set_priority_flags (MODEST_MSG_EDIT_WINDOW (window), flags);
1841 void modest_ui_actions_msg_edit_on_change_file_format (GtkRadioAction *action,
1842 GtkRadioAction *selected,
1843 ModestWindow *window)
1847 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1849 file_format = gtk_radio_action_get_current_value (selected);
1850 modest_msg_edit_window_set_file_format (MODEST_MSG_EDIT_WINDOW (window), file_format);
1855 modest_ui_actions_on_zoom_plus (GtkAction *action,
1856 ModestWindow *window)
1858 g_return_if_fail (MODEST_IS_WINDOW (window));
1860 modest_window_zoom_plus (MODEST_WINDOW (window));
1864 modest_ui_actions_on_zoom_minus (GtkAction *action,
1865 ModestWindow *window)
1867 g_return_if_fail (MODEST_IS_WINDOW (window));
1869 modest_window_zoom_minus (MODEST_WINDOW (window));
1873 modest_ui_actions_on_toggle_fullscreen (GtkToggleAction *toggle,
1874 ModestWindow *window)
1876 ModestWindowMgr *mgr;
1877 gboolean fullscreen, active;
1878 g_return_if_fail (MODEST_IS_WINDOW (window));
1880 mgr = modest_runtime_get_window_mgr ();
1882 active = (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle)))?1:0;
1883 fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
1885 if (active != fullscreen) {
1886 modest_window_mgr_set_fullscreen_mode (mgr, active);
1887 gtk_window_present (GTK_WINDOW (window));
1892 modest_ui_actions_on_change_fullscreen (GtkAction *action,
1893 ModestWindow *window)
1895 ModestWindowMgr *mgr;
1896 gboolean fullscreen;
1898 g_return_if_fail (MODEST_IS_WINDOW (window));
1900 mgr = modest_runtime_get_window_mgr ();
1901 fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
1902 modest_window_mgr_set_fullscreen_mode (mgr, !fullscreen);
1904 gtk_window_present (GTK_WINDOW (window));
1908 * Used by modest_ui_actions_on_details to call do_headers_action
1911 headers_action_show_details (TnyHeader *header,
1912 ModestWindow *window,
1919 dialog = modest_details_dialog_new_with_header (GTK_WINDOW (window), header);
1922 gtk_widget_show_all (dialog);
1923 gtk_dialog_run (GTK_DIALOG (dialog));
1925 gtk_widget_destroy (dialog);
1929 * Show the folder details in a ModestDetailsDialog widget
1932 show_folder_details (TnyFolder *folder,
1938 dialog = modest_details_dialog_new_with_folder (window, folder);
1941 gtk_widget_show_all (dialog);
1942 gtk_dialog_run (GTK_DIALOG (dialog));
1944 gtk_widget_destroy (dialog);
1948 * Show the header details in a ModestDetailsDialog widget
1951 modest_ui_actions_on_details (GtkAction *action,
1954 TnyList * headers_list;
1958 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
1961 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW (win));
1965 headers_list = get_selected_headers (win);
1969 iter = tny_list_create_iterator (headers_list);
1971 header = TNY_HEADER (tny_iterator_get_current (iter));
1972 headers_action_show_details (header, win, NULL);
1973 g_object_unref (header);
1975 g_object_unref (iter);
1977 } else if (MODEST_IS_MAIN_WINDOW (win)) {
1978 GtkWidget *folder_view, *header_view;
1980 /* Check which widget has the focus */
1981 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
1982 MODEST_WIDGET_TYPE_FOLDER_VIEW);
1983 if (gtk_widget_is_focus (folder_view)) {
1986 folder = (TnyFolder *) modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
1988 /* Show only when it's a folder */
1989 if (!folder || !TNY_IS_FOLDER (folder))
1992 show_folder_details (folder, GTK_WINDOW (win));
1995 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
1996 MODEST_WIDGET_TYPE_HEADER_VIEW);
1997 /* Show details of each header */
1998 do_headers_action (win, headers_action_show_details, header_view);
2004 modest_ui_actions_on_toggle_show_cc (GtkToggleAction *toggle,
2005 ModestMsgEditWindow *window)
2007 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2009 modest_msg_edit_window_show_cc (window, gtk_toggle_action_get_active (toggle));
2013 modest_ui_actions_on_toggle_show_bcc (GtkToggleAction *toggle,
2014 ModestMsgEditWindow *window)
2016 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2018 modest_msg_edit_window_show_bcc (window, gtk_toggle_action_get_active (toggle));
2022 modest_ui_actions_toggle_folders_view (GtkAction *action,
2023 ModestMainWindow *main_window)
2027 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2029 conf = modest_runtime_get_conf ();
2031 if (modest_main_window_get_style (main_window) == MODEST_MAIN_WINDOW_STYLE_SPLIT)
2032 modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SIMPLE);
2034 modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SPLIT);
2038 modest_ui_actions_on_toggle_toolbar (GtkToggleAction *toggle,
2039 ModestWindow *window)
2041 gboolean active, fullscreen = FALSE;
2042 ModestWindowMgr *mgr;
2044 active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle));
2046 /* Check if we want to toggle the toolbar vuew in fullscreen
2048 if (!strcmp (gtk_action_get_name (GTK_ACTION (toggle)),
2049 "ViewShowToolbarFullScreen")) {
2053 /* Toggle toolbar */
2054 mgr = modest_runtime_get_window_mgr ();
2055 modest_window_mgr_show_toolbars (mgr, active, fullscreen);
2059 modest_ui_actions_msg_edit_on_select_font (GtkAction *action,
2060 ModestMsgEditWindow *window)
2062 modest_msg_edit_window_select_font (window);
2066 modest_ui_actions_on_folder_display_name_changed (ModestFolderView *folder_view,
2067 const gchar *display_name,
2070 /* Do not change the application name if the widget has not
2071 the focus. This callback could be called even if the folder
2072 view has not the focus, because the handled signal could be
2073 emitted when the folder view is redrawn */
2074 if (gtk_widget_is_focus (GTK_WIDGET (folder_view))) {
2076 gtk_window_set_title (window, display_name);
2078 gtk_window_set_title (window, " ");
2083 modest_ui_actions_on_select_contacts (GtkAction *action, ModestMsgEditWindow *window)
2085 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2086 modest_msg_edit_window_select_contacts (window);
2090 modest_ui_actions_on_check_names (GtkAction *action, ModestMsgEditWindow *window)
2092 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2093 modest_msg_edit_window_check_names (window);
2098 create_move_to_dialog (ModestWindow *win,
2099 GtkWidget *folder_view,
2100 GtkWidget **tree_view)
2102 GtkWidget *dialog, *scroll;
2104 dialog = gtk_dialog_new_with_buttons (_("mcen_ti_moveto_folders_title"),
2106 GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR | GTK_DIALOG_DESTROY_WITH_PARENT,
2108 GTK_RESPONSE_ACCEPT,
2110 GTK_RESPONSE_REJECT,
2113 /* Create scrolled window */
2114 scroll = gtk_scrolled_window_new (NULL, NULL);
2115 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll),
2116 GTK_POLICY_AUTOMATIC,
2117 GTK_POLICY_AUTOMATIC);
2119 /* Create folder view */
2120 *tree_view = modest_folder_view_new (NULL);
2121 gtk_tree_view_set_model (GTK_TREE_VIEW (*tree_view),
2122 gtk_tree_view_get_model (GTK_TREE_VIEW (folder_view)));
2123 gtk_container_add (GTK_CONTAINER (scroll), *tree_view);
2125 /* Add scroll to dialog */
2126 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
2127 scroll, FALSE, FALSE, 0);
2129 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
2135 * Returns TRUE if at least one of the headers of the list belongs to
2136 * a message that has been fully retrieved.
2139 has_retrieved_msgs (TnyList *list)
2142 gboolean found = FALSE;
2144 iter = tny_list_create_iterator (list);
2145 while (tny_iterator_is_done (iter) && !found) {
2147 TnyHeaderFlags flags;
2149 header = TNY_HEADER (tny_iterator_get_current (iter));
2150 flags = tny_header_get_flags (header);
2151 if (!(flags & TNY_HEADER_FLAG_PARTIAL))
2155 tny_iterator_next (iter);
2157 g_object_unref (iter);
2163 * Shows a confirmation dialog to the user when we're moving messages
2164 * from a remote server to the local storage. Returns the dialog
2165 * response. If it's other kind of movement the it always returns
2169 msgs_move_to_confirmation (GtkWindow *win,
2170 TnyFolder *dest_folder,
2173 gint response = GTK_RESPONSE_OK;
2175 /* If the destination is a local folder */
2176 if (modest_tny_folder_is_local_folder (dest_folder)) {
2177 TnyFolder *src_folder;
2181 /* Get source folder */
2182 iter = tny_list_create_iterator (headers);
2183 header = TNY_HEADER (tny_iterator_get_current (iter));
2184 src_folder = tny_header_get_folder (header);
2185 g_object_unref (header);
2186 g_object_unref (iter);
2188 /* If the source is a remote folder */
2189 if (!modest_tny_folder_is_local_folder (src_folder)) {
2190 const gchar *message;
2192 if (tny_list_get_length (headers) == 1)
2193 if (has_retrieved_msgs (headers))
2194 message = _("mcen_nc_move_retrieve");
2196 message = _("mcen_nc_move_header");
2198 if (has_retrieved_msgs (headers))
2199 message = _("mcen_nc_move_retrieves");
2201 message = _("mcen_nc_move_headers");
2203 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
2204 (const gchar *) message);
2211 * UI handler for the "Move to" action when invoked from the
2215 modest_ui_actions_on_main_window_move_to (GtkAction *action,
2216 ModestMainWindow *win)
2218 GtkWidget *dialog, *folder_view, *tree_view = NULL;
2220 TnyFolderStore *folder_store;
2221 ModestMailOperation *mail_op = NULL;
2223 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win));
2225 /* Get the folder view */
2226 folder_view = modest_main_window_get_child_widget (win,
2227 MODEST_WIDGET_TYPE_FOLDER_VIEW);
2229 /* Create and run the dialog */
2230 dialog = create_move_to_dialog (MODEST_WINDOW (win), folder_view, &tree_view);
2231 result = gtk_dialog_run (GTK_DIALOG(dialog));
2233 /* We do this to save an indentation level ;-) */
2234 if (result != GTK_RESPONSE_ACCEPT)
2237 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (tree_view));
2239 if (TNY_IS_ACCOUNT (folder_store))
2242 /* Get folder or messages to transfer */
2243 if (gtk_widget_is_focus (folder_view)) {
2244 TnyFolderStore *src_folder;
2245 src_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
2247 if (TNY_IS_FOLDER (src_folder)) {
2248 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE, G_OBJECT(win));
2249 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
2252 modest_mail_operation_xfer_folder (mail_op,
2253 TNY_FOLDER (src_folder),
2256 g_object_unref (G_OBJECT (mail_op));
2260 g_object_unref (G_OBJECT (src_folder));
2262 GtkWidget *header_view;
2263 header_view = modest_main_window_get_child_widget (win,
2264 MODEST_WIDGET_TYPE_HEADER_VIEW);
2265 if (gtk_widget_is_focus (header_view)) {
2269 headers = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW (header_view));
2271 /* Ask for user confirmation */
2272 response = msgs_move_to_confirmation (GTK_WINDOW (win),
2273 TNY_FOLDER (folder_store),
2276 /* Transfer messages */
2277 if (response == GTK_RESPONSE_OK) {
2278 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE, G_OBJECT(win));
2279 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
2282 modest_mail_operation_xfer_msgs (mail_op,
2284 TNY_FOLDER (folder_store),
2286 g_object_unref (G_OBJECT (mail_op));
2290 g_object_unref (folder_store);
2293 gtk_widget_destroy (dialog);
2298 * UI handler for the "Move to" action when invoked from the
2299 * ModestMsgViewWindow
2302 modest_ui_actions_on_msg_view_window_move_to (GtkAction *action,
2303 ModestMsgViewWindow *win)
2305 GtkWidget *dialog, *folder_view, *tree_view = NULL;
2307 ModestMainWindow *main_window;
2312 /* Get the folder view */
2313 main_window = MODEST_MAIN_WINDOW (modest_window_mgr_get_main_window (modest_runtime_get_window_mgr ()));
2314 folder_view = modest_main_window_get_child_widget (main_window,
2315 MODEST_WIDGET_TYPE_FOLDER_VIEW);
2317 /* Create and run the dialog */
2318 dialog = create_move_to_dialog (MODEST_WINDOW (win), folder_view, &tree_view);
2319 result = gtk_dialog_run (GTK_DIALOG(dialog));
2321 if (result == GTK_RESPONSE_ACCEPT) {
2322 TnyFolderStore *folder_store;
2325 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (tree_view));
2327 /* Create header list */
2328 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW (win));
2329 header = tny_msg_get_header (msg);
2330 headers = tny_simple_list_new ();
2331 tny_list_prepend (headers, G_OBJECT (header));
2332 g_object_unref (header);
2333 g_object_unref (msg);
2335 /* Ask user for confirmation. MSG-NOT404 */
2336 response = msgs_move_to_confirmation (GTK_WINDOW (win),
2337 TNY_FOLDER (folder_store),
2340 /* Transfer current msg */
2341 if (response == GTK_RESPONSE_OK) {
2342 ModestMailOperation *mail_op;
2344 /* Create mail op */
2345 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE, G_OBJECT(win));
2346 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
2349 /* Transfer messages */
2350 modest_mail_operation_xfer_msgs (mail_op,
2352 TNY_FOLDER (folder_store),
2354 g_object_unref (G_OBJECT (mail_op));
2356 g_object_unref (headers);
2358 g_object_unref (folder_store);
2360 gtk_widget_destroy (dialog);
2364 modest_ui_actions_on_move_to (GtkAction *action,
2367 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win) ||
2368 MODEST_IS_MSG_VIEW_WINDOW (win));
2370 if (MODEST_IS_MAIN_WINDOW (win))
2371 modest_ui_actions_on_main_window_move_to (action,
2372 MODEST_MAIN_WINDOW (win));
2374 modest_ui_actions_on_msg_view_window_move_to (action,
2375 MODEST_MSG_VIEW_WINDOW (win));
2379 * Calls #HeadersFunc for each header already selected in the main
2380 * window or the message currently being shown in the msg view window
2383 do_headers_action (ModestWindow *win,
2387 TnyList *headers_list;
2391 headers_list = get_selected_headers (win);
2395 /* Call the function for each header */
2396 iter = tny_list_create_iterator (headers_list);
2397 while (!tny_iterator_is_done (iter)) {
2400 header = TNY_HEADER (tny_iterator_get_current (iter));
2401 func (header, win, user_data);
2402 g_object_unref (header);
2403 tny_iterator_next (iter);
2405 g_object_unref (iter);