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 #endif /* MODEST_PLATFORM_MAEMO */
51 #include "widgets/modest-ui-constants.h"
52 #include <widgets/modest-main-window.h>
53 #include <widgets/modest-msg-view-window.h>
54 #include <widgets/modest-account-view-window.h>
55 #include <widgets/modest-details-dialog.h>
56 #include <widgets/modest-attachments-view.h>
57 #include "widgets/modest-global-settings-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 {
96 GtkTreeRowReference *row_reference;
99 } HeaderActivatedHelper;
102 * The do_headers_action uses this kind of functions to perform some
103 * action to each member of a list of headers
105 typedef void (*HeadersFunc) (TnyHeader *header, ModestWindow *win, gpointer user_data);
108 do_headers_action (ModestWindow *win,
113 static void open_msg_func (const GObject *obj, const TnyMsg *msg, gpointer user_data);
115 static void reply_forward_func (const GObject *obj, const TnyMsg *msg, gpointer user_data);
117 static void reply_forward (ReplyForwardAction action, ModestWindow *win);
119 static gchar* ask_for_folder_name (GtkWindow *parent_window, const gchar *title);
122 modest_ui_actions_on_about (GtkAction *action, ModestWindow *win)
125 const gchar *authors[] = {
126 "Dirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>",
129 about = gtk_about_dialog_new ();
130 gtk_about_dialog_set_name (GTK_ABOUT_DIALOG(about), PACKAGE_NAME);
131 gtk_about_dialog_set_version (GTK_ABOUT_DIALOG(about),PACKAGE_VERSION);
132 gtk_about_dialog_set_copyright (GTK_ABOUT_DIALOG(about),
133 _("Copyright (c) 2006, Nokia Corporation\n"
134 "All rights reserved."));
135 gtk_about_dialog_set_comments (GTK_ABOUT_DIALOG(about),
136 _("a modest e-mail client\n\n"
137 "design and implementation: Dirk-Jan C. Binnema\n"
138 "contributions from the fine people at KC and Ig\n"
139 "uses the tinymail email framework written by Philip van Hoof"));
140 gtk_about_dialog_set_authors (GTK_ABOUT_DIALOG(about), authors);
141 gtk_about_dialog_set_website (GTK_ABOUT_DIALOG(about), "http://modest.garage.maemo.org");
143 gtk_dialog_run (GTK_DIALOG (about));
144 gtk_widget_destroy(about);
149 get_selected_headers (ModestWindow *win)
151 if (MODEST_IS_MAIN_WINDOW(win)) {
152 GtkWidget *header_view;
154 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
155 MODEST_WIDGET_TYPE_HEADER_VIEW);
156 return modest_header_view_get_selected_headers (MODEST_HEADER_VIEW(header_view));
158 } else if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
159 /* for MsgViewWindows, we simply return a list with one element */
162 TnyList *list = NULL;
164 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW(win));
166 header = tny_msg_get_header (msg);
167 list = tny_simple_list_new ();
168 tny_list_prepend (list, G_OBJECT(header));
169 g_object_unref (G_OBJECT(header));
178 headers_action_mark_as_read (TnyHeader *header,
182 TnyHeaderFlags flags;
184 g_return_if_fail (TNY_IS_HEADER(header));
186 flags = tny_header_get_flags (header);
187 if (flags & TNY_HEADER_FLAG_SEEN) return;
188 tny_header_set_flags (header, TNY_HEADER_FLAG_SEEN);
192 headers_action_mark_as_unread (TnyHeader *header,
196 TnyHeaderFlags flags;
198 g_return_if_fail (TNY_IS_HEADER(header));
200 flags = tny_header_get_flags (header);
201 if (flags & TNY_HEADER_FLAG_SEEN) {
202 tny_header_unset_flags (header, TNY_HEADER_FLAG_SEEN);
208 headers_action_delete (TnyHeader *header,
212 ModestMailOperation *mail_op = NULL;
214 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_DELETE, G_OBJECT(win));
215 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
218 /* Always delete. TODO: Move to trash still not supported */
219 modest_mail_operation_remove_msg (mail_op, header, FALSE);
220 g_object_unref (G_OBJECT (mail_op));
224 modest_ui_actions_on_delete (GtkAction *action, ModestWindow *win)
226 TnyList *header_list = NULL;
227 TnyIterator *iter = NULL;
228 TnyHeader *header = NULL;
229 gchar *message = NULL;
233 g_return_if_fail (MODEST_IS_WINDOW(win));
235 header_list = get_selected_headers (win);
236 if (!header_list) return;
239 if (tny_list_get_length(header_list) > 1)
240 message = g_strdup(_("emev_nc_delete_messages"));
242 iter = tny_list_create_iterator (header_list);
243 header = TNY_HEADER (tny_iterator_get_current (iter));
244 desc = g_strdup_printf ("%s", tny_header_get_subject (header));
245 message = g_strdup_printf(_("emev_nc_delete_message"), desc);
248 /* Confirmation dialog */
249 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
253 if (response == GTK_RESPONSE_OK) {
254 if (MODEST_IS_MSG_EDIT_WINDOW (win)) {
256 g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value);
260 /* Remove each header */
261 do_headers_action (win, headers_action_delete, NULL);
263 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
264 gtk_widget_destroy (GTK_WIDGET(win));
271 g_object_unref (header_list);
272 g_object_unref (iter);
277 modest_ui_actions_on_quit (GtkAction *action, ModestWindow *win)
279 #ifdef MODEST_PLATFORM_MAEMO
280 modest_osso_save_state();
281 #endif /* MODEST_PLATFORM_MAEMO */
287 modest_ui_actions_on_close_window (GtkAction *action, ModestWindow *win)
289 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
290 gtk_widget_destroy (GTK_WIDGET (win));
291 } else if (MODEST_IS_MSG_EDIT_WINDOW (win)) {
293 g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value);
294 } else if (MODEST_IS_WINDOW (win)) {
295 gtk_widget_destroy (GTK_WIDGET (win));
297 g_return_if_reached ();
302 modest_ui_actions_on_add_to_contacts (GtkAction *action, ModestWindow *win)
304 GtkClipboard *clipboard = NULL;
305 gchar *selection = NULL;
307 clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
308 selection = gtk_clipboard_wait_for_text (clipboard);
310 modest_address_book_add_address (selection);
315 modest_ui_actions_on_accounts (GtkAction *action, ModestWindow *win)
318 /* This is currently only implemented for Maemo,
319 * because it requires a providers preset file which is not publically available.
321 #ifdef MODEST_PLATFORM_MAEMO /* Defined in config.h */
322 GSList *account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
323 TRUE /* enabled accounts only */);
324 gboolean accounts_exist = account_names != NULL;
325 g_slist_free (account_names);
327 if (!accounts_exist) {
328 /* If there are no accounts yet, just show the easy-setup wizard, as per the UI spec: */
329 ModestEasysetupWizardDialog *wizard = modest_easysetup_wizard_dialog_new ();
330 gtk_window_set_transient_for (GTK_WINDOW (wizard), GTK_WINDOW (win));
331 gtk_dialog_run (GTK_DIALOG (wizard));
332 gtk_widget_destroy (GTK_WIDGET (wizard));
334 /* Show the list of accounts: */
335 GtkDialog *account_win = GTK_DIALOG(modest_account_view_window_new ());
336 gtk_window_set_transient_for (GTK_WINDOW (account_win), GTK_WINDOW(win));
337 gtk_dialog_run (account_win);
338 gtk_widget_destroy (GTK_WIDGET(account_win));
341 GtkWidget *dialog, *label;
343 /* Create the widgets */
345 dialog = gtk_dialog_new_with_buttons ("Message",
347 GTK_DIALOG_DESTROY_WITH_PARENT,
351 label = gtk_label_new ("Hello World!");
353 /* Ensure that the dialog box is destroyed when the user responds. */
355 g_signal_connect_swapped (dialog, "response",
356 G_CALLBACK (gtk_widget_destroy),
359 /* Add the label, and show everything we've added to the dialog. */
361 gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox),
363 gtk_widget_show_all (dialog);
364 #endif /* MODEST_PLATFORM_MAEMO */
368 modest_ui_actions_on_new_msg (GtkAction *action, ModestWindow *win)
370 ModestWindow *msg_win;
372 TnyFolder *folder = NULL;
373 gchar *account_name = NULL;
374 gchar *from_str = NULL;
375 /* GError *err = NULL; */
376 TnyAccount *account = NULL;
377 ModestWindowMgr *mgr;
378 gchar *signature = NULL;
380 account_name = g_strdup(modest_window_get_active_account (win));
382 account_name = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
384 g_printerr ("modest: no account found\n");
388 account = modest_tny_account_store_get_tny_account_by_account (modest_runtime_get_account_store(),
390 TNY_ACCOUNT_TYPE_STORE);
392 g_printerr ("modest: failed to get tnyaccount for '%s'\n", account_name);
396 from_str = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(), account_name);
398 g_printerr ("modest: failed get from string for '%s'\n", account_name);
402 if (modest_account_mgr_get_bool (modest_runtime_get_account_mgr (), account_name,
403 MODEST_ACCOUNT_USE_SIGNATURE, FALSE)) {
404 signature = modest_account_mgr_get_string (modest_runtime_get_account_mgr (), account_name,
405 MODEST_ACCOUNT_SIGNATURE, FALSE);
407 signature = g_strdup ("");
410 msg = modest_tny_msg_new ("", from_str, "", "", "", signature, NULL);
412 g_printerr ("modest: failed to create new msg\n");
416 folder = modest_tny_account_get_special_folder (account, TNY_FOLDER_TYPE_DRAFTS);
418 g_printerr ("modest: failed to find Drafts folder\n");
422 /* tny_folder_add_msg (folder, msg, &err); */
424 /* g_printerr ("modest: error adding msg to Drafts folder: %s", */
426 /* g_error_free (err); */
430 /* Create and register edit window */
431 msg_win = modest_msg_edit_window_new (msg, account_name);
432 mgr = modest_runtime_get_window_mgr ();
433 modest_window_mgr_register_window (mgr, msg_win);
436 gtk_window_set_transient_for (GTK_WINDOW (msg_win),
438 gtk_widget_show_all (GTK_WIDGET (msg_win));
441 g_free (account_name);
445 g_object_unref (G_OBJECT(account));
447 g_object_unref (G_OBJECT(msg));
449 g_object_unref (G_OBJECT(folder));
453 headers_action_open (TnyHeader *header,
457 modest_ui_actions_on_header_activated (MODEST_HEADER_VIEW (user_data),
459 MODEST_MAIN_WINDOW (win));
463 modest_ui_actions_on_open (GtkAction *action, ModestWindow *win)
465 GtkWidget *header_view;
467 /* Get header view */
468 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
469 MODEST_WIDGET_TYPE_HEADER_VIEW);
471 /* Open each message */
472 do_headers_action (win, headers_action_open, header_view);
477 open_msg_func (const GObject *obj, const TnyMsg *msg, gpointer user_data)
479 ModestWindowMgr *mgr = NULL;
480 ModestWindow *parent_win = NULL;
481 ModestWindow *win = NULL;
482 HeaderActivatedHelper *helper = NULL;
483 TnyFolderType folder_type = TNY_FOLDER_TYPE_UNKNOWN;
484 gchar *account = NULL;
486 g_return_if_fail (MODEST_IS_WINDOW(obj));
487 g_return_if_fail (user_data != NULL);
489 /* TODO: Show an error? (review the specs) */
493 parent_win = MODEST_WINDOW(obj);
494 helper = (HeaderActivatedHelper *) user_data;
496 /* Mark header as read */
497 headers_action_mark_as_read (helper->header, MODEST_WINDOW(parent_win), NULL);
500 account = g_strdup(modest_window_get_active_account(MODEST_WINDOW(parent_win)));
502 account = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
504 /* Gets foldert type (OUTBOX headers will be opened in edit window */
505 if (modest_tny_folder_is_local_folder (helper->folder))
506 folder_type = modest_tny_folder_get_local_folder_type (helper->folder);
508 switch (folder_type) {
509 case TNY_FOLDER_TYPE_DRAFTS:
510 win = modest_msg_edit_window_new ((TnyMsg *) msg, account);
513 if (helper->model != NULL)
514 win = modest_msg_view_window_new_with_header_model ((TnyMsg *) msg, account, helper->model, helper->row_reference);
516 win = modest_msg_view_window_new ((TnyMsg *) msg, account);
519 /* Register and show new window */
521 mgr = modest_runtime_get_window_mgr ();
522 modest_window_mgr_register_window (mgr, win);
523 gtk_window_set_transient_for (GTK_WINDOW (win), GTK_WINDOW (parent_win));
524 gtk_widget_show_all (GTK_WIDGET(win));
529 /* g_object_unref (G_OBJECT(msg)); */
530 g_object_unref (G_OBJECT(helper->folder));
531 g_object_unref (G_OBJECT(helper->header));
532 gtk_tree_row_reference_free (helper->row_reference);
533 g_slice_free (HeaderActivatedHelper, helper);
537 reply_forward_func (const GObject *obj, const TnyMsg *msg, gpointer user_data)
540 ReplyForwardHelper *rf_helper;
541 ModestWindow *msg_win;
542 ModestEditType edit_type;
545 TnyFolder *folder = NULL;
546 TnyAccount *account = NULL;
547 ModestWindowMgr *mgr;
548 gchar *signature = NULL;
550 g_return_if_fail (user_data != NULL);
551 rf_helper = (ReplyForwardHelper *) user_data;
553 rf_helper->pending_ops--;
555 from = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(),
556 rf_helper->account_name);
557 if (modest_account_mgr_get_bool (modest_runtime_get_account_mgr(),
558 rf_helper->account_name,
559 MODEST_ACCOUNT_USE_SIGNATURE, FALSE)) {
560 signature = modest_account_mgr_get_string (modest_runtime_get_account_mgr (),
561 rf_helper->account_name,
562 MODEST_ACCOUNT_SIGNATURE, FALSE);
565 /* Create reply mail */
566 switch (rf_helper->action) {
569 modest_tny_msg_create_reply_msg ((TnyMsg *) msg, from, signature,
570 rf_helper->reply_forward_type,
571 MODEST_TNY_MSG_REPLY_MODE_SENDER);
573 case ACTION_REPLY_TO_ALL:
575 modest_tny_msg_create_reply_msg ((TnyMsg *) msg, from, signature, rf_helper->reply_forward_type,
576 MODEST_TNY_MSG_REPLY_MODE_ALL);
577 edit_type = MODEST_EDIT_TYPE_REPLY;
581 modest_tny_msg_create_forward_msg ((TnyMsg *) msg, from, signature, rf_helper->reply_forward_type);
582 edit_type = MODEST_EDIT_TYPE_FORWARD;
585 g_return_if_reached ();
592 g_printerr ("modest: failed to create message\n");
596 account = modest_tny_account_store_get_tny_account_by_account (modest_runtime_get_account_store(),
597 rf_helper->account_name,
598 TNY_ACCOUNT_TYPE_STORE);
600 g_printerr ("modest: failed to get tnyaccount for '%s'\n", rf_helper->account_name);
604 folder = modest_tny_account_get_special_folder (account, TNY_FOLDER_TYPE_DRAFTS);
606 g_printerr ("modest: failed to find Drafts folder\n");
610 tny_folder_add_msg (folder, (TnyMsg *) msg, &err);
612 g_printerr ("modest: error adding msg to Drafts folder: %s",
618 /* Create and register the windows */
619 msg_win = modest_msg_edit_window_new (new_msg, rf_helper->account_name);
620 mgr = modest_runtime_get_window_mgr ();
621 modest_window_mgr_register_window (mgr, msg_win);
623 /* Show edit window */
624 gtk_widget_show_all (GTK_WIDGET (msg_win));
628 g_object_unref (G_OBJECT (new_msg));
630 g_object_unref (G_OBJECT (folder));
632 g_object_unref (G_OBJECT (account));
634 if (rf_helper->pending_ops == 0) {
635 g_free (rf_helper->account_name);
636 g_slice_free (ReplyForwardHelper, rf_helper);
640 * Common code for the reply and forward actions
643 reply_forward (ReplyForwardAction action, ModestWindow *win)
645 ModestMailOperation *mail_op = NULL;
646 TnyList *header_list = NULL;
647 ReplyForwardHelper *rf_helper = NULL;
648 guint reply_forward_type;
650 g_return_if_fail (MODEST_IS_WINDOW(win));
652 header_list = get_selected_headers (win);
656 reply_forward_type = modest_conf_get_int (modest_runtime_get_conf (),
657 (action == ACTION_FORWARD) ? MODEST_CONF_FORWARD_TYPE : MODEST_CONF_REPLY_TYPE,
659 /* We assume that we can only select messages of the
660 same folder and that we reply all of them from the
661 same account. In fact the interface currently only
662 allows single selection */
665 rf_helper = g_slice_new0 (ReplyForwardHelper);
666 rf_helper->reply_forward_type = reply_forward_type;
667 rf_helper->action = action;
668 rf_helper->pending_ops = tny_list_get_length (header_list);
669 rf_helper->account_name = g_strdup (modest_window_get_active_account (win));
670 if (!rf_helper->account_name)
671 rf_helper->account_name =
672 modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
674 if (MODEST_IS_MSG_VIEW_WINDOW(win)) {
676 msg = modest_msg_view_window_get_message(MODEST_MSG_VIEW_WINDOW(win));
678 g_printerr ("modest: no message found\n");
681 reply_forward_func (G_OBJECT(win), msg, rf_helper);
684 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE, G_OBJECT(win));
685 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
686 modest_mail_operation_process_msg (mail_op, header_list, reply_forward_func, rf_helper);
689 g_object_unref(mail_op);
694 modest_ui_actions_on_reply (GtkAction *action, ModestWindow *win)
696 g_return_if_fail (MODEST_IS_WINDOW(win));
698 reply_forward (ACTION_REPLY, win);
702 modest_ui_actions_on_forward (GtkAction *action, ModestWindow *win)
704 g_return_if_fail (MODEST_IS_WINDOW(win));
706 reply_forward (ACTION_FORWARD, win);
710 modest_ui_actions_on_reply_all (GtkAction *action, ModestWindow *win)
712 g_return_if_fail (MODEST_IS_WINDOW(win));
714 reply_forward (ACTION_REPLY_TO_ALL, win);
718 modest_ui_actions_on_next (GtkAction *action,
719 ModestWindow *window)
721 if (MODEST_IS_MAIN_WINDOW (window)) {
722 GtkWidget *header_view;
724 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
725 MODEST_WIDGET_TYPE_HEADER_VIEW);
729 modest_header_view_select_next (MODEST_HEADER_VIEW(header_view));
730 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
731 modest_msg_view_window_select_next_message (MODEST_MSG_VIEW_WINDOW (window));
733 g_return_if_reached ();
738 modest_ui_actions_on_prev (GtkAction *action,
739 ModestWindow *window)
741 g_return_if_fail (MODEST_IS_WINDOW(window));
743 if (MODEST_IS_MAIN_WINDOW (window)) {
744 GtkWidget *header_view;
745 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
746 MODEST_WIDGET_TYPE_HEADER_VIEW);
750 modest_header_view_select_prev (MODEST_HEADER_VIEW(header_view));
751 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
752 modest_msg_view_window_select_previous_message (MODEST_MSG_VIEW_WINDOW (window));
754 g_return_if_reached ();
759 modest_ui_actions_on_sort (GtkAction *action,
760 ModestWindow *window)
762 g_return_if_fail (MODEST_IS_WINDOW(window));
764 if (MODEST_IS_MAIN_WINDOW (window)) {
765 GtkWidget *header_view;
766 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
767 MODEST_WIDGET_TYPE_HEADER_VIEW);
771 /* Show sorting dialog */
772 modest_platform_run_sort_dialog (GTK_WINDOW (window), MODEST_SORT_HEADERS);
776 /** Check that an appropriate connection is open.
778 gboolean check_for_connection (const gchar *account_name)
780 TnyDevice *device = modest_runtime_get_device ();
783 g_assert (TNY_IS_MAEMO_CONIC_DEVICE (device));
785 TnyMaemoConicDevice *maemo_device = TNY_MAEMO_CONIC_DEVICE (device);
788 if (tny_device_is_online (device))
791 modest_platform_connect_and_wait (NULL);
793 /* TODO: Wait until a result. */
799 * This function performs the send & receive required actions. The
800 * window it's used to create the mail operation. Tipically it should
801 * be allways the main window, but we pass it as argument in order to
805 modest_ui_actions_do_send_receive (const gchar *account_name, ModestWindow *win)
807 gchar *acc_name = NULL;
809 /* If no account name was provided get the current account, if
810 there is none either then pick the default one */
812 acc_name = g_strdup (modest_window_get_active_account(win));
814 acc_name = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
816 g_printerr ("modest: cannot get default account\n");
820 acc_name = g_strdup (account_name);
823 /* Send & receive. Do not continue if no suitable connection
825 if (check_for_connection (acc_name)) {
826 /* As per the UI spec,
827 * for POP accounts, we should receive,
828 * for IMAP we should synchronize everything, including receiving,
829 * for SMTP we should send,
830 * first receiving, then sending:
832 /* Create the mail operation */
833 /* TODO: The spec wants us to first do any pending deletions, before receiving. */
834 ModestMailOperation *mail_op;
835 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE, G_OBJECT(win));
836 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
837 modest_mail_operation_update_account (mail_op, acc_name);
838 g_object_unref (G_OBJECT (mail_op));
845 * Refreshes all accounts. This function will be used by automatic
849 modest_ui_actions_do_send_receive_all (ModestWindow *win)
851 GSList *account_names, *iter;
853 account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
856 iter = account_names;
858 modest_ui_actions_do_send_receive ((const char*) iter->data, win);
859 iter = g_slist_next (iter);
862 g_slist_foreach (account_names, (GFunc) g_free, NULL);
863 g_slist_free (account_names);
867 * Handler of the click on Send&Receive button in the main toolbar
870 modest_ui_actions_on_send_receive (GtkAction *action, ModestWindow *win)
872 /* Check that at least one account exists: */
873 GSList *account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
874 TRUE /* enabled accounts only */);
875 gboolean accounts_exist = account_names != NULL;
876 g_slist_free (account_names);
878 /* If not, allow the user to create an account before trying to send/receive. */
880 modest_ui_actions_on_accounts (NULL, win);
882 /* Refresh the active account */
883 modest_ui_actions_do_send_receive (NULL, win);
888 modest_ui_actions_toggle_header_list_view (GtkAction *action, ModestMainWindow *main_window)
891 GtkWidget *header_view;
893 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
895 header_view = modest_main_window_get_child_widget (main_window,
896 MODEST_WIDGET_TYPE_HEADER_VIEW);
900 conf = modest_runtime_get_conf ();
902 /* what is saved/restored is depending on the style; thus; we save with
903 * old style, then update the style, and restore for this new style
905 modest_widget_memory_save (conf, G_OBJECT(header_view), MODEST_CONF_HEADER_VIEW_KEY);
907 if (modest_header_view_get_style
908 (MODEST_HEADER_VIEW(header_view)) == MODEST_HEADER_VIEW_STYLE_DETAILS)
909 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
910 MODEST_HEADER_VIEW_STYLE_TWOLINES);
912 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
913 MODEST_HEADER_VIEW_STYLE_DETAILS);
915 modest_widget_memory_restore (conf, G_OBJECT(header_view),
916 MODEST_CONF_HEADER_VIEW_KEY);
921 modest_ui_actions_on_header_selected (ModestHeaderView *header_view,
923 ModestMainWindow *main_window)
925 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
927 /* If no header has been selected then exit */
931 /* Update Main window title */
932 if (GTK_WIDGET_HAS_FOCUS (header_view)) {
933 const gchar *subject = tny_header_get_subject (header);
934 if (subject && strcmp (subject, ""))
935 gtk_window_set_title (GTK_WINDOW (main_window), subject);
937 gtk_window_set_title (GTK_WINDOW (main_window), _("mail_va_no_subject"));
942 modest_ui_actions_on_header_activated (ModestHeaderView *header_view,
944 ModestMainWindow *main_window)
946 ModestMailOperation *mail_op = NULL;
947 HeaderActivatedHelper *helper = NULL;
948 ModestWindowMgr *mgr = NULL;
949 ModestWindow *win = NULL;
950 GtkTreeModel *model = NULL;
951 GtkTreeSelection *sel = NULL;
952 GList *sel_list = NULL;
954 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
959 /* Look if we already have a message view for that header */
960 mgr = modest_runtime_get_window_mgr ();
961 win = modest_window_mgr_find_window_by_msguid (mgr, tny_header_get_uid (header));
965 helper = g_slice_new0 (HeaderActivatedHelper);
966 helper->folder = tny_header_get_folder (header);
967 helper->header = g_object_ref(header);
968 helper->model = NULL;
970 /* Get headers tree model and selected row reference to build message view */
971 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
972 sel_list = gtk_tree_selection_get_selected_rows (sel, &model);
973 if (sel_list != NULL) {
976 helper->model = model;
977 helper->row_reference = gtk_tree_row_reference_new (model, (GtkTreePath *) sel_list->data);
979 g_list_foreach (sel_list, (GFunc) gtk_tree_path_free, NULL);
980 g_list_free (sel_list);
983 /* New mail operation */
984 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE, G_OBJECT(main_window));
985 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
986 modest_mail_operation_get_msg (mail_op, header, open_msg_func, helper);
989 g_object_unref (mail_op);
993 set_active_account_from_tny_account (TnyAccount *account,
994 ModestWindow *window)
996 TnyAccount *modest_server_account;
997 const gchar *server_acc_name;
998 gchar *modest_acc_name;
1000 server_acc_name = tny_account_get_id (account);
1001 /* We need the TnyAccount provided by the
1002 account store because that is the one that
1003 knows the name of the Modest account */
1004 modest_server_account =
1005 modest_tny_account_store_get_tny_account_by_id (modest_runtime_get_account_store (),
1007 modest_acc_name = (gchar *) g_object_get_data (G_OBJECT (modest_server_account), "modest_account");
1008 modest_window_set_active_account (window, modest_acc_name);
1009 g_object_unref (modest_server_account);
1013 modest_ui_actions_on_folder_selection_changed (ModestFolderView *folder_view,
1014 TnyFolderStore *folder_store,
1016 ModestMainWindow *main_window)
1019 GtkWidget *header_view;
1020 TnyAccount *account;
1022 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1024 header_view = modest_main_window_get_child_widget(main_window,
1025 MODEST_WIDGET_TYPE_HEADER_VIEW);
1029 conf = modest_runtime_get_conf ();
1031 if (TNY_IS_FOLDER (folder_store)) {
1034 /* Update the active account */
1035 account = tny_folder_get_account (TNY_FOLDER (folder_store));
1036 set_active_account_from_tny_account (account, MODEST_WINDOW (main_window));
1037 g_object_unref (account);
1039 /* Set folder on header view */
1040 modest_main_window_set_contents_style (main_window,
1041 MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS);
1042 modest_header_view_set_folder (MODEST_HEADER_VIEW(header_view),
1043 TNY_FOLDER (folder_store));
1044 modest_widget_memory_restore (conf, G_OBJECT(header_view),
1045 MODEST_CONF_HEADER_VIEW_KEY);
1047 /* Update the active account */
1048 modest_window_set_active_account (MODEST_WINDOW (main_window), NULL);
1049 /* Do not show folder */
1050 modest_widget_memory_save (conf, G_OBJECT (header_view), MODEST_CONF_HEADER_VIEW_KEY);
1051 modest_header_view_set_folder (MODEST_HEADER_VIEW(header_view), NULL);
1053 } else if (TNY_IS_ACCOUNT (folder_store)) {
1054 /* Update active account */
1055 set_active_account_from_tny_account (TNY_ACCOUNT (folder_store), MODEST_WINDOW (main_window));
1056 /* Show account details */
1057 modest_main_window_set_contents_style (main_window, MODEST_MAIN_WINDOW_CONTENTS_STYLE_DETAILS);
1062 modest_ui_actions_on_item_not_found (ModestHeaderView *header_view,ModestItemType type,
1069 item = (type == MODEST_ITEM_TYPE_FOLDER) ? "folder" : "message";
1071 if (g_main_depth > 0)
1072 gdk_threads_enter ();
1073 online = tny_device_is_online (modest_runtime_get_device());
1076 /* already online -- the item is simply not there... */
1077 dialog = gtk_message_dialog_new (GTK_WINDOW (win),
1079 GTK_MESSAGE_WARNING,
1081 _("The %s you selected cannot be found"),
1083 gtk_dialog_run (GTK_DIALOG(dialog));
1085 dialog = gtk_dialog_new_with_buttons (_("Connection requested"),
1089 GTK_RESPONSE_REJECT,
1091 GTK_RESPONSE_ACCEPT,
1093 txt = g_strdup_printf (_("This %s is not available in offline mode.\n"
1094 "Do you want to get online?"), item);
1095 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
1096 gtk_label_new (txt), FALSE, FALSE, 0);
1097 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
1100 gtk_window_set_default_size (GTK_WINDOW(dialog), 300, 300);
1101 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
1102 // modest_platform_connect_and_wait ();;
1105 gtk_widget_destroy (dialog);
1106 if (g_main_depth > 0)
1107 gdk_threads_leave ();
1111 modest_ui_actions_on_msg_link_hover (ModestMsgView *msgview, const gchar* link,
1114 /* g_message ("%s %s", __FUNCTION__, link); */
1119 modest_ui_actions_on_msg_link_clicked (ModestMsgView *msgview, const gchar* link,
1122 modest_platform_activate_uri (link);
1126 modest_ui_actions_on_msg_link_contextual (ModestMsgView *msgview, const gchar* link,
1129 modest_platform_show_uri_popup (link);
1133 modest_ui_actions_on_msg_attachment_clicked (ModestMsgView *msgview, TnyMimePart *mime_part,
1136 modest_msg_view_window_view_attachment (MODEST_MSG_VIEW_WINDOW (win), mime_part);
1140 modest_ui_actions_on_msg_recpt_activated (ModestMsgView *msgview,
1141 const gchar *address,
1144 /* g_message ("%s %s", __FUNCTION__, address); */
1148 modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edit_window)
1150 TnyTransportAccount *transport_account;
1151 ModestMailOperation *mail_operation;
1153 gchar *account_name, *from;
1154 ModestAccountMgr *account_mgr;
1156 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window));
1158 data = modest_msg_edit_window_get_msg_data (edit_window);
1160 account_mgr = modest_runtime_get_account_mgr();
1161 account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
1163 account_name = modest_account_mgr_get_default_account (account_mgr);
1164 if (!account_name) {
1165 g_printerr ("modest: no account found\n");
1166 modest_msg_edit_window_free_msg_data (edit_window, data);
1170 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_tny_account_by_account
1171 (modest_runtime_get_account_store(),
1173 TNY_ACCOUNT_TYPE_TRANSPORT));
1174 if (!transport_account) {
1175 g_printerr ("modest: no transport account found for '%s'\n", account_name);
1176 g_free (account_name);
1177 modest_msg_edit_window_free_msg_data (edit_window, data);
1180 from = modest_account_mgr_get_from_string (account_mgr, account_name);
1182 /* Create the mail operation */
1183 mail_operation = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_INFO, G_OBJECT(edit_window));
1184 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
1186 modest_mail_operation_save_to_drafts (mail_operation,
1196 data->priority_flags);
1199 g_free (account_name);
1200 g_object_unref (G_OBJECT (transport_account));
1201 g_object_unref (G_OBJECT (mail_operation));
1203 modest_msg_edit_window_free_msg_data (edit_window, data);
1205 /* Save settings and close the window */
1206 gtk_widget_destroy (GTK_WIDGET (edit_window));
1209 modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
1211 TnyTransportAccount *transport_account;
1212 ModestMailOperation *mail_operation;
1214 gchar *account_name, *from;
1215 ModestAccountMgr *account_mgr;
1217 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window));
1219 if (!modest_msg_edit_window_check_names (edit_window))
1222 data = modest_msg_edit_window_get_msg_data (edit_window);
1224 /* FIXME: Code added just for testing. The final version will
1225 use the send queue provided by tinymail and some
1227 account_mgr = modest_runtime_get_account_mgr();
1228 account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
1230 account_name = modest_account_mgr_get_default_account (account_mgr);
1231 if (!account_name) {
1232 g_printerr ("modest: no account found\n");
1233 modest_msg_edit_window_free_msg_data (edit_window, data);
1237 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_transport_account_for_open_connection
1238 (modest_runtime_get_account_store(),
1240 if (!transport_account) {
1241 g_printerr ("modest: no transport account found for '%s'\n", account_name);
1242 g_free (account_name);
1243 modest_msg_edit_window_free_msg_data (edit_window, data);
1246 from = modest_account_mgr_get_from_string (account_mgr, account_name);
1248 /* Create the mail operation */
1249 mail_operation = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_SEND, G_OBJECT(edit_window));
1250 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
1252 modest_mail_operation_send_new_mail (mail_operation,
1262 data->priority_flags);
1265 g_free (account_name);
1266 g_object_unref (G_OBJECT (transport_account));
1267 g_object_unref (G_OBJECT (mail_operation));
1269 modest_msg_edit_window_free_msg_data (edit_window, data);
1271 /* Save settings and close the window */
1272 gtk_widget_destroy (GTK_WIDGET (edit_window));
1276 modest_ui_actions_on_toggle_bold (GtkToggleAction *action,
1277 ModestMsgEditWindow *window)
1279 ModestMsgEditFormatState *format_state = NULL;
1281 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1282 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
1284 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
1287 format_state = modest_msg_edit_window_get_format_state (window);
1288 g_return_if_fail (format_state != NULL);
1290 format_state->bold = gtk_toggle_action_get_active (action);
1291 modest_msg_edit_window_set_format_state (window, format_state);
1292 g_free (format_state);
1297 modest_ui_actions_on_toggle_italics (GtkToggleAction *action,
1298 ModestMsgEditWindow *window)
1300 ModestMsgEditFormatState *format_state = NULL;
1302 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1303 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
1305 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
1308 format_state = modest_msg_edit_window_get_format_state (window);
1309 g_return_if_fail (format_state != NULL);
1311 format_state->italics = gtk_toggle_action_get_active (action);
1312 modest_msg_edit_window_set_format_state (window, format_state);
1313 g_free (format_state);
1318 modest_ui_actions_on_toggle_bullets (GtkToggleAction *action,
1319 ModestMsgEditWindow *window)
1321 ModestMsgEditFormatState *format_state = NULL;
1323 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1324 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
1326 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
1329 format_state = modest_msg_edit_window_get_format_state (window);
1330 g_return_if_fail (format_state != NULL);
1332 format_state->bullet = gtk_toggle_action_get_active (action);
1333 modest_msg_edit_window_set_format_state (window, format_state);
1334 g_free (format_state);
1339 modest_ui_actions_on_change_justify (GtkRadioAction *action,
1340 GtkRadioAction *selected,
1341 ModestMsgEditWindow *window)
1343 ModestMsgEditFormatState *format_state = NULL;
1344 GtkJustification value;
1346 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1348 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
1351 value = gtk_radio_action_get_current_value (selected);
1353 format_state = modest_msg_edit_window_get_format_state (window);
1354 g_return_if_fail (format_state != NULL);
1356 format_state->justification = value;
1357 modest_msg_edit_window_set_format_state (window, format_state);
1358 g_free (format_state);
1362 modest_ui_actions_on_select_editor_color (GtkAction *action,
1363 ModestMsgEditWindow *window)
1365 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1366 g_return_if_fail (GTK_IS_ACTION (action));
1368 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
1371 modest_msg_edit_window_select_color (window);
1375 modest_ui_actions_on_select_editor_background_color (GtkAction *action,
1376 ModestMsgEditWindow *window)
1378 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1379 g_return_if_fail (GTK_IS_ACTION (action));
1381 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
1384 modest_msg_edit_window_select_background_color (window);
1388 modest_ui_actions_on_insert_image (GtkAction *action,
1389 ModestMsgEditWindow *window)
1391 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1392 g_return_if_fail (GTK_IS_ACTION (action));
1394 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
1397 modest_msg_edit_window_insert_image (window);
1401 modest_ui_actions_on_attach_file (GtkAction *action,
1402 ModestMsgEditWindow *window)
1404 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1405 g_return_if_fail (GTK_IS_ACTION (action));
1407 modest_msg_edit_window_attach_file (window);
1411 modest_ui_actions_on_remove_attachments (GtkAction *action,
1412 ModestMsgEditWindow *window)
1414 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1415 g_return_if_fail (GTK_IS_ACTION (action));
1417 modest_msg_edit_window_remove_attachments (window, NULL);
1421 * Shows a dialog with an entry that asks for some text. The returned
1422 * value must be freed by the caller. The dialog window title will be
1426 ask_for_folder_name (GtkWindow *parent_window,
1429 GtkWidget *dialog, *entry;
1430 gchar *folder_name = NULL;
1432 /* Ask for folder name */
1433 dialog = gtk_dialog_new_with_buttons (_("New Folder Name"),
1437 GTK_RESPONSE_REJECT,
1439 GTK_RESPONSE_ACCEPT,
1441 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
1442 gtk_label_new(title),
1445 entry = gtk_entry_new_with_max_length (40);
1446 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
1450 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
1452 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
1453 folder_name = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry)));
1455 gtk_widget_destroy (dialog);
1461 modest_ui_actions_on_new_folder (GtkAction *action, ModestMainWindow *main_window)
1463 TnyFolderStore *parent_folder;
1464 GtkWidget *folder_view;
1466 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1468 folder_view = modest_main_window_get_child_widget (main_window,
1469 MODEST_WIDGET_TYPE_FOLDER_VIEW);
1473 parent_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
1475 if (parent_folder) {
1476 gboolean finished = FALSE;
1478 gchar *folder_name = NULL, *suggested_name = NULL;
1480 /* Run the new folder dialog */
1482 result = modest_platform_run_new_folder_dialog (GTK_WINDOW (main_window),
1487 if (result == GTK_RESPONSE_REJECT) {
1490 ModestMailOperation *mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_INFO, G_OBJECT(main_window));
1491 TnyFolder *new_folder = NULL;
1493 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
1496 new_folder = modest_mail_operation_create_folder (mail_op,
1498 (const gchar *) folder_name);
1500 g_object_unref (new_folder);
1504 /* /\* TODO: check error and follow proper actions *\/ */
1505 /* /\* suggested_name = X; *\/ */
1506 /* /\* Show error to the user *\/ */
1507 /* modest_platform_run_information_dialog (GTK_WINDOW (main_window), */
1508 /* _("mail_in_ui_folder_create_error")); */
1510 g_object_unref (mail_op);
1512 g_free (folder_name);
1516 g_object_unref (parent_folder);
1521 modest_ui_actions_on_rename_folder (GtkAction *action,
1522 ModestMainWindow *main_window)
1524 TnyFolderStore *folder;
1525 GtkWidget *folder_view;
1527 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1529 folder_view = modest_main_window_get_child_widget (main_window,
1530 MODEST_WIDGET_TYPE_FOLDER_VIEW);
1534 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
1536 if (folder && TNY_IS_FOLDER (folder)) {
1538 folder_name = ask_for_folder_name (GTK_WINDOW (main_window),
1539 _("Please enter a new name for the folder"));
1541 if (folder_name != NULL && strlen (folder_name) > 0) {
1542 ModestMailOperation *mail_op;
1544 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_INFO, G_OBJECT(main_window));
1545 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
1548 modest_mail_operation_rename_folder (mail_op,
1549 TNY_FOLDER (folder),
1550 (const gchar *) folder_name);
1552 g_object_unref (mail_op);
1553 g_free (folder_name);
1555 g_object_unref (folder);
1560 delete_folder (ModestMainWindow *main_window, gboolean move_to_trash)
1562 TnyFolderStore *folder;
1563 GtkWidget *folder_view;
1567 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1569 folder_view = modest_main_window_get_child_widget (main_window,
1570 MODEST_WIDGET_TYPE_FOLDER_VIEW);
1574 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
1576 /* Show an error if it's an account */
1577 if (!TNY_IS_FOLDER (folder)) {
1578 modest_platform_run_information_dialog (GTK_WINDOW (main_window),
1579 _("mail_in_ui_folder_delete_error"));
1584 message = g_strdup_printf (_("mcen_nc_delete_folder_text"),
1585 tny_folder_get_name (TNY_FOLDER (folder)));
1586 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (main_window),
1587 (const gchar *) message);
1590 if (response == GTK_RESPONSE_OK) {
1591 ModestMailOperation *mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_DELETE, G_OBJECT(main_window));
1593 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
1595 modest_mail_operation_remove_folder (mail_op, TNY_FOLDER (folder), move_to_trash);
1597 /* Show error if happened */
1598 if (modest_mail_operation_get_error (mail_op))
1599 modest_platform_run_information_dialog (GTK_WINDOW (main_window),
1600 _("mail_in_ui_folder_delete_error"));
1602 g_object_unref (G_OBJECT (mail_op));
1605 g_object_unref (G_OBJECT (folder));
1609 modest_ui_actions_on_delete_folder (GtkAction *action,
1610 ModestMainWindow *main_window)
1612 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1614 delete_folder (main_window, FALSE);
1618 modest_ui_actions_on_move_folder_to_trash_folder (GtkAction *action, ModestMainWindow *main_window)
1620 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1622 delete_folder (main_window, TRUE);
1626 modest_ui_actions_on_password_requested (TnyAccountStore *account_store,
1627 const gchar* server_account_name,
1632 ModestMainWindow *main_window)
1634 g_return_if_fail(server_account_name);
1635 /* printf("DEBUG: %s: server_account_name=%s\n", __FUNCTION__, server_account_name); */
1637 #ifdef MODEST_PLATFORM_MAEMO
1638 /* Maemo uses a different (awkward) button order,
1639 * It should probably just use gtk_alternative_dialog_button_order ().
1641 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
1645 GTK_RESPONSE_ACCEPT,
1647 GTK_RESPONSE_REJECT,
1650 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
1654 GTK_RESPONSE_REJECT,
1656 GTK_RESPONSE_ACCEPT,
1658 #endif /* MODEST_PLATFORM_MAEMO */
1660 gtk_window_set_transient_for (GTK_WINDOW(dialog), GTK_WINDOW(main_window));
1662 gchar *server_name = modest_server_account_get_hostname (
1663 modest_runtime_get_account_mgr(), server_account_name);
1665 /* This causes a warning because the logical ID has no %s in it,
1666 * though the translation does, but there is not much we can do about that: */
1667 gchar *txt = g_strdup_printf (_("mail_ia_password_info"), server_name);
1668 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), gtk_label_new(txt),
1671 g_free (server_name);
1675 gchar *initial_username = modest_server_account_get_username (
1676 modest_runtime_get_account_mgr(), server_account_name);
1678 GtkWidget *entry_username = gtk_entry_new ();
1679 if (initial_username)
1680 gtk_entry_set_text (GTK_ENTRY (entry_username), initial_username);
1681 /* Dim this if a connection has ever succeeded with this username,
1682 * as per the UI spec: */
1683 const gboolean username_known =
1684 modest_server_account_get_username_has_succeeded(
1685 modest_runtime_get_account_mgr(), server_account_name);
1686 gtk_widget_set_sensitive (entry_username, !username_known);
1688 #ifdef MODEST_PLATFORM_MAEMO
1689 /* Auto-capitalization is the default, so let's turn it off: */
1690 hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_username), HILDON_GTK_INPUT_MODE_FULL);
1692 /* Create a size group to be used by all captions.
1693 * Note that HildonCaption does not create a default size group if we do not specify one.
1694 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
1695 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
1697 GtkWidget *caption = hildon_caption_new (sizegroup,
1698 _("mail_fi_username"), entry_username, NULL, HILDON_CAPTION_MANDATORY);
1699 gtk_widget_show (entry_username);
1700 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
1701 FALSE, FALSE, MODEST_MARGIN_HALF);
1702 gtk_widget_show (caption);
1704 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry_username,
1706 #endif /* MODEST_PLATFORM_MAEMO */
1709 GtkWidget *entry_password = gtk_entry_new ();
1710 gtk_entry_set_visibility (GTK_ENTRY(entry_password), FALSE);
1711 /* gtk_entry_set_invisible_char (GTK_ENTRY(entry_password), "*"); */
1713 #ifdef MODEST_PLATFORM_MAEMO
1714 /* Auto-capitalization is the default, so let's turn it off: */
1715 hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_password),
1716 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
1718 caption = hildon_caption_new (sizegroup,
1719 _("mail_fi_password"), entry_password, NULL, HILDON_CAPTION_MANDATORY);
1720 gtk_widget_show (entry_password);
1721 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
1722 FALSE, FALSE, MODEST_MARGIN_HALF);
1723 gtk_widget_show (caption);
1724 g_object_unref (sizegroup);
1726 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry_password,
1728 #endif /* MODEST_PLATFORM_MAEMO */
1730 /* This is not in the Maemo UI spec:
1731 remember_pass_check = gtk_check_button_new_with_label (_("Remember password"));
1732 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), remember_pass_check,
1736 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
1738 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
1740 *username = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_username)));
1742 modest_server_account_set_username (
1743 modest_runtime_get_account_mgr(), server_account_name,
1746 const gboolean username_was_changed =
1747 (strcmp (*username, initial_username) != 0);
1748 if (username_was_changed) {
1749 /* To actually use a changed username,
1750 * we must reset the connection, according to pvanhoof.
1751 * This _might_ be a sensible way to do that: */
1752 TnyDevice *device = modest_runtime_get_device();
1753 tny_device_force_offline (device);
1754 tny_device_force_online (device);
1759 *password = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_password)));
1761 /* We do not save the password in the configuration,
1762 * because this function is only called for passwords that should
1763 * not be remembered:
1764 modest_server_account_set_password (
1765 modest_runtime_get_account_mgr(), server_account_name,
1784 /* This is not in the Maemo UI spec:
1785 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (remember_pass_check)))
1791 gtk_widget_destroy (dialog);
1795 modest_ui_actions_on_cut (GtkAction *action,
1796 ModestWindow *window)
1798 GtkWidget *focused_widget;
1800 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
1801 if (GTK_IS_EDITABLE (focused_widget)) {
1802 gtk_editable_cut_clipboard (GTK_EDITABLE(focused_widget));
1803 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
1804 GtkTextBuffer *buffer;
1805 GtkClipboard *clipboard;
1807 clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
1808 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
1809 gtk_text_buffer_cut_clipboard (buffer, clipboard, TRUE);
1814 modest_ui_actions_on_copy (GtkAction *action,
1815 ModestWindow *window)
1817 GtkClipboard *clipboard;
1818 GtkWidget *focused_widget;
1820 clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
1821 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
1822 if (GTK_IS_LABEL (focused_widget)) {
1823 gtk_clipboard_set_text (clipboard, gtk_label_get_text (GTK_LABEL (focused_widget)), -1);
1824 } else if (GTK_IS_EDITABLE (focused_widget)) {
1825 gtk_editable_copy_clipboard (GTK_EDITABLE(focused_widget));
1826 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
1827 GtkTextBuffer *buffer;
1829 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
1830 gtk_text_buffer_copy_clipboard (buffer, clipboard);
1835 modest_ui_actions_on_undo (GtkAction *action,
1836 ModestWindow *window)
1838 if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
1839 modest_msg_edit_window_undo (MODEST_MSG_EDIT_WINDOW (window));
1841 g_return_if_reached ();
1846 modest_ui_actions_on_paste (GtkAction *action,
1847 ModestWindow *window)
1849 GtkWidget *focused_widget;
1851 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
1852 if (GTK_IS_EDITABLE (focused_widget)) {
1853 gtk_editable_paste_clipboard (GTK_EDITABLE(focused_widget));
1854 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
1855 GtkTextBuffer *buffer;
1856 GtkClipboard *clipboard;
1858 clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
1859 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
1860 gtk_text_buffer_paste_clipboard (buffer, clipboard, NULL, TRUE);
1865 modest_ui_actions_on_select_all (GtkAction *action,
1866 ModestWindow *window)
1868 GtkWidget *focused_widget;
1870 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
1871 if (MODEST_IS_ATTACHMENTS_VIEW (focused_widget)) {
1872 modest_attachments_view_select_all (MODEST_ATTACHMENTS_VIEW (focused_widget));
1873 } else if (GTK_IS_LABEL (focused_widget)) {
1874 gtk_label_select_region (GTK_LABEL (focused_widget), 0, -1);
1875 } else if (GTK_IS_EDITABLE (focused_widget)) {
1876 gtk_editable_select_region (GTK_EDITABLE(focused_widget), 0, -1);
1877 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
1878 GtkTextBuffer *buffer;
1879 GtkTextIter start, end;
1881 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
1882 gtk_text_buffer_get_start_iter (buffer, &start);
1883 gtk_text_buffer_get_end_iter (buffer, &end);
1884 gtk_text_buffer_select_range (buffer, &start, &end);
1889 modest_ui_actions_on_mark_as_read (GtkAction *action,
1890 ModestWindow *window)
1892 g_return_if_fail (MODEST_IS_WINDOW(window));
1894 /* Mark each header as read */
1895 do_headers_action (window, headers_action_mark_as_read, NULL);
1899 modest_ui_actions_on_mark_as_unread (GtkAction *action,
1900 ModestWindow *window)
1902 g_return_if_fail (MODEST_IS_WINDOW(window));
1904 /* Mark each header as read */
1905 do_headers_action (window, headers_action_mark_as_unread, NULL);
1909 modest_ui_actions_on_change_zoom (GtkRadioAction *action,
1910 GtkRadioAction *selected,
1911 ModestWindow *window)
1915 value = gtk_radio_action_get_current_value (selected);
1916 if (MODEST_IS_WINDOW (window)) {
1917 modest_window_set_zoom (MODEST_WINDOW (window), ((gdouble)value)/100);
1921 void modest_ui_actions_msg_edit_on_change_priority (GtkRadioAction *action,
1922 GtkRadioAction *selected,
1923 ModestWindow *window)
1925 TnyHeaderFlags flags;
1926 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1928 flags = gtk_radio_action_get_current_value (selected);
1929 modest_msg_edit_window_set_priority_flags (MODEST_MSG_EDIT_WINDOW (window), flags);
1932 void modest_ui_actions_msg_edit_on_change_file_format (GtkRadioAction *action,
1933 GtkRadioAction *selected,
1934 ModestWindow *window)
1938 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1940 file_format = gtk_radio_action_get_current_value (selected);
1941 modest_msg_edit_window_set_file_format (MODEST_MSG_EDIT_WINDOW (window), file_format);
1946 modest_ui_actions_on_zoom_plus (GtkAction *action,
1947 ModestWindow *window)
1949 g_return_if_fail (MODEST_IS_WINDOW (window));
1951 modest_window_zoom_plus (MODEST_WINDOW (window));
1955 modest_ui_actions_on_zoom_minus (GtkAction *action,
1956 ModestWindow *window)
1958 g_return_if_fail (MODEST_IS_WINDOW (window));
1960 modest_window_zoom_minus (MODEST_WINDOW (window));
1964 modest_ui_actions_on_toggle_fullscreen (GtkToggleAction *toggle,
1965 ModestWindow *window)
1967 ModestWindowMgr *mgr;
1968 gboolean fullscreen, active;
1969 g_return_if_fail (MODEST_IS_WINDOW (window));
1971 mgr = modest_runtime_get_window_mgr ();
1973 active = (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle)))?1:0;
1974 fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
1976 if (active != fullscreen) {
1977 modest_window_mgr_set_fullscreen_mode (mgr, active);
1978 gtk_window_present (GTK_WINDOW (window));
1983 modest_ui_actions_on_change_fullscreen (GtkAction *action,
1984 ModestWindow *window)
1986 ModestWindowMgr *mgr;
1987 gboolean fullscreen;
1989 g_return_if_fail (MODEST_IS_WINDOW (window));
1991 mgr = modest_runtime_get_window_mgr ();
1992 fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
1993 modest_window_mgr_set_fullscreen_mode (mgr, !fullscreen);
1995 gtk_window_present (GTK_WINDOW (window));
1999 * Used by modest_ui_actions_on_details to call do_headers_action
2002 headers_action_show_details (TnyHeader *header,
2003 ModestWindow *window,
2010 dialog = modest_details_dialog_new_with_header (GTK_WINDOW (window), header);
2013 gtk_widget_show_all (dialog);
2014 gtk_dialog_run (GTK_DIALOG (dialog));
2016 gtk_widget_destroy (dialog);
2020 * Show the folder details in a ModestDetailsDialog widget
2023 show_folder_details (TnyFolder *folder,
2029 dialog = modest_details_dialog_new_with_folder (window, folder);
2032 gtk_widget_show_all (dialog);
2033 gtk_dialog_run (GTK_DIALOG (dialog));
2035 gtk_widget_destroy (dialog);
2039 * Show the header details in a ModestDetailsDialog widget
2042 modest_ui_actions_on_details (GtkAction *action,
2045 TnyList * headers_list;
2049 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
2052 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW (win));
2056 headers_list = get_selected_headers (win);
2060 iter = tny_list_create_iterator (headers_list);
2062 header = TNY_HEADER (tny_iterator_get_current (iter));
2063 headers_action_show_details (header, win, NULL);
2064 g_object_unref (header);
2066 g_object_unref (iter);
2068 } else if (MODEST_IS_MAIN_WINDOW (win)) {
2069 GtkWidget *folder_view, *header_view;
2071 /* Check which widget has the focus */
2072 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
2073 MODEST_WIDGET_TYPE_FOLDER_VIEW);
2074 if (gtk_widget_is_focus (folder_view)) {
2077 folder = (TnyFolder *) modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
2079 /* Show only when it's a folder */
2080 if (!folder || !TNY_IS_FOLDER (folder))
2083 show_folder_details (folder, GTK_WINDOW (win));
2086 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
2087 MODEST_WIDGET_TYPE_HEADER_VIEW);
2088 /* Show details of each header */
2089 do_headers_action (win, headers_action_show_details, header_view);
2095 modest_ui_actions_on_toggle_show_cc (GtkToggleAction *toggle,
2096 ModestMsgEditWindow *window)
2098 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2100 modest_msg_edit_window_show_cc (window, gtk_toggle_action_get_active (toggle));
2104 modest_ui_actions_on_toggle_show_bcc (GtkToggleAction *toggle,
2105 ModestMsgEditWindow *window)
2107 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2109 modest_msg_edit_window_show_bcc (window, gtk_toggle_action_get_active (toggle));
2113 modest_ui_actions_toggle_folders_view (GtkAction *action,
2114 ModestMainWindow *main_window)
2118 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2120 conf = modest_runtime_get_conf ();
2122 if (modest_main_window_get_style (main_window) == MODEST_MAIN_WINDOW_STYLE_SPLIT)
2123 modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SIMPLE);
2125 modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SPLIT);
2129 modest_ui_actions_on_toggle_toolbar (GtkToggleAction *toggle,
2130 ModestWindow *window)
2132 gboolean active, fullscreen = FALSE;
2133 ModestWindowMgr *mgr;
2135 active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle));
2137 /* Check if we want to toggle the toolbar vuew in fullscreen
2139 if (!strcmp (gtk_action_get_name (GTK_ACTION (toggle)),
2140 "ViewShowToolbarFullScreen")) {
2144 /* Toggle toolbar */
2145 mgr = modest_runtime_get_window_mgr ();
2146 modest_window_mgr_show_toolbars (mgr, active, fullscreen);
2150 modest_ui_actions_msg_edit_on_select_font (GtkAction *action,
2151 ModestMsgEditWindow *window)
2153 modest_msg_edit_window_select_font (window);
2157 modest_ui_actions_on_folder_display_name_changed (ModestFolderView *folder_view,
2158 const gchar *display_name,
2161 /* Do not change the application name if the widget has not
2162 the focus. This callback could be called even if the folder
2163 view has not the focus, because the handled signal could be
2164 emitted when the folder view is redrawn */
2165 if (gtk_widget_is_focus (GTK_WIDGET (folder_view))) {
2167 gtk_window_set_title (window, display_name);
2169 gtk_window_set_title (window, " ");
2174 modest_ui_actions_on_select_contacts (GtkAction *action, ModestMsgEditWindow *window)
2176 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2177 modest_msg_edit_window_select_contacts (window);
2181 modest_ui_actions_on_check_names (GtkAction *action, ModestMsgEditWindow *window)
2183 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2184 modest_msg_edit_window_check_names (window);
2189 create_move_to_dialog (ModestWindow *win,
2190 GtkWidget *folder_view,
2191 GtkWidget **tree_view)
2193 GtkWidget *dialog, *scroll;
2195 dialog = gtk_dialog_new_with_buttons (_("mcen_ti_moveto_folders_title"),
2197 GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR | GTK_DIALOG_DESTROY_WITH_PARENT,
2199 GTK_RESPONSE_ACCEPT,
2201 GTK_RESPONSE_REJECT,
2204 /* Create scrolled window */
2205 scroll = gtk_scrolled_window_new (NULL, NULL);
2206 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll),
2207 GTK_POLICY_AUTOMATIC,
2208 GTK_POLICY_AUTOMATIC);
2210 /* Create folder view */
2211 *tree_view = modest_folder_view_new (NULL);
2212 gtk_tree_view_set_model (GTK_TREE_VIEW (*tree_view),
2213 gtk_tree_view_get_model (GTK_TREE_VIEW (folder_view)));
2214 gtk_container_add (GTK_CONTAINER (scroll), *tree_view);
2216 /* Add scroll to dialog */
2217 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
2218 scroll, FALSE, FALSE, 0);
2220 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
2226 * Returns TRUE if at least one of the headers of the list belongs to
2227 * a message that has been fully retrieved.
2230 has_retrieved_msgs (TnyList *list)
2233 gboolean found = FALSE;
2235 iter = tny_list_create_iterator (list);
2236 while (tny_iterator_is_done (iter) && !found) {
2238 TnyHeaderFlags flags;
2240 header = TNY_HEADER (tny_iterator_get_current (iter));
2241 flags = tny_header_get_flags (header);
2242 if (!(flags & TNY_HEADER_FLAG_PARTIAL))
2246 tny_iterator_next (iter);
2248 g_object_unref (iter);
2254 * Shows a confirmation dialog to the user when we're moving messages
2255 * from a remote server to the local storage. Returns the dialog
2256 * response. If it's other kind of movement the it always returns
2260 msgs_move_to_confirmation (GtkWindow *win,
2261 TnyFolder *dest_folder,
2264 gint response = GTK_RESPONSE_OK;
2266 /* If the destination is a local folder */
2267 if (modest_tny_folder_is_local_folder (dest_folder)) {
2268 TnyFolder *src_folder;
2272 /* Get source folder */
2273 iter = tny_list_create_iterator (headers);
2274 header = TNY_HEADER (tny_iterator_get_current (iter));
2275 src_folder = tny_header_get_folder (header);
2276 g_object_unref (header);
2277 g_object_unref (iter);
2279 /* If the source is a remote folder */
2280 if (!modest_tny_folder_is_local_folder (src_folder)) {
2281 const gchar *message;
2283 if (tny_list_get_length (headers) == 1)
2284 if (has_retrieved_msgs (headers))
2285 message = _("mcen_nc_move_retrieve");
2287 message = _("mcen_nc_move_header");
2289 if (has_retrieved_msgs (headers))
2290 message = _("mcen_nc_move_retrieves");
2292 message = _("mcen_nc_move_headers");
2294 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
2295 (const gchar *) message);
2303 tranasfer_msgs_from_viewer_cb (const GObject *object, gpointer user_data)
2305 ModestMsgViewWindow *self = NULL;
2306 gboolean found = FALSE;
2308 g_return_if_fail (MODEST_IS_MSG_VIEW_WINDOW (object));
2309 self = MODEST_MSG_VIEW_WINDOW (object);
2311 found = modest_msg_view_window_select_first_message (self);
2312 g_return_if_fail (found);
2316 * UI handler for the "Move to" action when invoked from the
2320 modest_ui_actions_on_main_window_move_to (GtkAction *action,
2321 ModestMainWindow *win)
2323 GtkWidget *dialog, *folder_view, *tree_view = NULL;
2325 TnyFolderStore *folder_store;
2326 ModestMailOperation *mail_op = NULL;
2328 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win));
2330 /* Get the folder view */
2331 folder_view = modest_main_window_get_child_widget (win,
2332 MODEST_WIDGET_TYPE_FOLDER_VIEW);
2334 /* Create and run the dialog */
2335 dialog = create_move_to_dialog (MODEST_WINDOW (win), folder_view, &tree_view);
2336 result = gtk_dialog_run (GTK_DIALOG(dialog));
2337 g_object_ref (tree_view);
2339 /* We do this to save an indentation level ;-) */
2340 if (result != GTK_RESPONSE_ACCEPT)
2343 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (tree_view));
2345 if (TNY_IS_ACCOUNT (folder_store))
2348 /* Get folder or messages to transfer */
2349 if (gtk_widget_is_focus (folder_view)) {
2350 TnyFolderStore *src_folder;
2351 src_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
2353 if (TNY_IS_FOLDER (src_folder)) {
2354 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE, G_OBJECT(win));
2355 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
2358 modest_mail_operation_xfer_folder_async (mail_op,
2359 TNY_FOLDER (src_folder),
2362 g_object_unref (G_OBJECT (mail_op));
2366 g_object_unref (G_OBJECT (src_folder));
2368 GtkWidget *header_view;
2369 header_view = modest_main_window_get_child_widget (win,
2370 MODEST_WIDGET_TYPE_HEADER_VIEW);
2371 if (gtk_widget_is_focus (header_view)) {
2375 headers = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW (header_view));
2377 /* Ask for user confirmation */
2378 response = msgs_move_to_confirmation (GTK_WINDOW (win),
2379 TNY_FOLDER (folder_store),
2382 /* Transfer messages */
2383 if (response == GTK_RESPONSE_OK) {
2384 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE, G_OBJECT(win));
2385 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
2388 modest_mail_operation_xfer_msgs (mail_op,
2390 TNY_FOLDER (folder_store),
2394 g_object_unref (G_OBJECT (mail_op));
2396 g_object_unref (headers);
2399 g_object_unref (folder_store);
2402 gtk_widget_destroy (dialog);
2407 * UI handler for the "Move to" action when invoked from the
2408 * ModestMsgViewWindow
2411 modest_ui_actions_on_msg_view_window_move_to (GtkAction *action,
2412 ModestMsgViewWindow *win)
2414 GtkWidget *dialog, *folder_view, *tree_view = NULL;
2416 ModestMainWindow *main_window;
2420 /* Get the folder view */
2421 main_window = MODEST_MAIN_WINDOW (modest_window_mgr_get_main_window (modest_runtime_get_window_mgr ()));
2422 folder_view = modest_main_window_get_child_widget (main_window,
2423 MODEST_WIDGET_TYPE_FOLDER_VIEW);
2425 /* Create and run the dialog */
2426 dialog = create_move_to_dialog (MODEST_WINDOW (win), folder_view, &tree_view);
2427 result = gtk_dialog_run (GTK_DIALOG(dialog));
2428 g_object_ref (tree_view);
2430 if (result == GTK_RESPONSE_ACCEPT) {
2431 TnyFolderStore *folder_store;
2434 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (tree_view));
2436 /* Create header list */
2437 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
2438 headers = tny_simple_list_new ();
2439 tny_list_prepend (headers, G_OBJECT (header));
2440 g_object_unref (header);
2442 /* Ask user for confirmation. MSG-NOT404 */
2443 response = msgs_move_to_confirmation (GTK_WINDOW (win),
2444 TNY_FOLDER (folder_store),
2447 /* Transfer current msg */
2448 if (response == GTK_RESPONSE_OK) {
2449 ModestMailOperation *mail_op;
2451 /* Create mail op */
2452 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE, G_OBJECT(win));
2453 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
2456 /* Transfer messages */
2457 modest_mail_operation_xfer_msgs (mail_op,
2459 TNY_FOLDER (folder_store),
2461 tranasfer_msgs_from_viewer_cb,
2463 g_object_unref (G_OBJECT (mail_op));
2465 g_object_unref (headers);
2466 g_object_unref (folder_store);
2468 gtk_widget_destroy (dialog);
2472 modest_ui_actions_on_move_to (GtkAction *action,
2475 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win) ||
2476 MODEST_IS_MSG_VIEW_WINDOW (win));
2478 if (MODEST_IS_MAIN_WINDOW (win))
2479 modest_ui_actions_on_main_window_move_to (action,
2480 MODEST_MAIN_WINDOW (win));
2482 modest_ui_actions_on_msg_view_window_move_to (action,
2483 MODEST_MSG_VIEW_WINDOW (win));
2487 * Calls #HeadersFunc for each header already selected in the main
2488 * window or the message currently being shown in the msg view window
2491 do_headers_action (ModestWindow *win,
2495 TnyList *headers_list;
2499 headers_list = get_selected_headers (win);
2503 /* Call the function for each header */
2504 iter = tny_list_create_iterator (headers_list);
2505 while (!tny_iterator_is_done (iter)) {
2508 header = TNY_HEADER (tny_iterator_get_current (iter));
2509 func (header, win, user_data);
2510 g_object_unref (header);
2511 tny_iterator_next (iter);
2513 g_object_unref (iter);
2517 modest_ui_actions_view_attachment (GtkAction *action,
2518 ModestWindow *window)
2520 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
2521 modest_msg_view_window_view_attachment (MODEST_MSG_VIEW_WINDOW (window), NULL);
2523 /* not supported window for this action */
2524 g_return_if_reached ();
2529 modest_ui_actions_save_attachments (GtkAction *action,
2530 ModestWindow *window)
2532 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
2533 modest_msg_view_window_save_attachments (MODEST_MSG_VIEW_WINDOW (window), NULL);
2535 /* not supported window for this action */
2536 g_return_if_reached ();
2541 modest_ui_actions_remove_attachments (GtkAction *action,
2542 ModestWindow *window)
2544 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
2545 modest_msg_view_window_remove_attachments (MODEST_MSG_VIEW_WINDOW (window), NULL);
2547 /* not supported window for this action */
2548 g_return_if_reached ();
2553 modest_ui_actions_on_settings (GtkAction *action,
2558 dialog = modest_platform_get_global_settings_dialog ();
2559 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (win));
2560 gtk_widget_show (dialog);
2562 gtk_dialog_run (GTK_DIALOG (dialog));
2564 gtk_widget_destroy (dialog);