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-connection-specific-smtp-window.h"
59 #include "modest-account-mgr-helpers.h"
60 #include "modest-mail-operation.h"
61 #include "modest-text-utils.h"
63 #ifdef MODEST_HAVE_EASYSETUP
64 #include "easysetup/modest-easysetup-wizard.h"
65 #endif /* MODEST_HAVE_EASYSETUP */
67 #include <modest-widget-memory.h>
68 #include <tny-error.h>
69 #include <tny-simple-list.h>
70 #include <tny-msg-view.h>
71 #include <tny-device.h>
73 typedef struct _GetMsgAsyncHelper {
75 ModestMailOperation *mail_op;
82 typedef enum _ReplyForwardAction {
88 typedef struct _ReplyForwardHelper {
89 guint reply_forward_type;
90 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, TnyMsg *msg, gpointer user_data);
115 static void reply_forward_func (const GObject *obj, 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)
317 /* This is currently only implemented for Maemo,
318 * because it requires a providers preset file which is not publically available.
320 #ifdef MODEST_PLATFORM_MAEMO /* Defined in config.h */
321 GSList *account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
322 TRUE /* enabled accounts only */);
323 gboolean accounts_exist = account_names != NULL;
324 g_slist_free (account_names);
326 if (!accounts_exist) {
327 /* If there are no accounts yet, just show the easy-setup wizard, as per the UI spec: */
328 ModestEasysetupWizardDialog *wizard = modest_easysetup_wizard_dialog_new ();
329 gtk_window_set_transient_for (GTK_WINDOW (wizard), GTK_WINDOW (win));
330 gtk_dialog_run (GTK_DIALOG (wizard));
331 gtk_widget_destroy (GTK_WIDGET (wizard));
333 /* Show the list of accounts: */
334 GtkDialog *account_win = GTK_DIALOG(modest_account_view_window_new ());
335 gtk_window_set_transient_for (GTK_WINDOW (account_win), GTK_WINDOW(win));
336 gtk_dialog_run (account_win);
337 gtk_widget_destroy (GTK_WIDGET(account_win));
340 GtkWidget *dialog, *label;
342 /* Create the widgets */
344 dialog = gtk_dialog_new_with_buttons ("Message",
346 GTK_DIALOG_DESTROY_WITH_PARENT,
350 label = gtk_label_new ("Hello World!");
352 /* Ensure that the dialog box is destroyed when the user responds. */
354 g_signal_connect_swapped (dialog, "response",
355 G_CALLBACK (gtk_widget_destroy),
358 /* Add the label, and show everything we've added to the dialog. */
360 gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox),
362 gtk_widget_show_all (dialog);
363 #endif /* MODEST_PLATFORM_MAEMO */
367 on_smtp_servers_window_hide (GtkWindow* window, gpointer user_data)
369 ModestWindow *main_window = MODEST_WINDOW (user_data);
371 /* Save any changes. */
372 modest_connection_specific_smtp_window_save_server_accounts (
373 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (window),
374 modest_window_get_active_account (main_window));
375 gtk_widget_destroy (GTK_WIDGET (window));
379 modest_ui_actions_on_smtp_servers (GtkAction *action, ModestWindow *win)
381 /* This is currently only implemented for Maemo,
382 * because it requires an API (libconic) to detect different connection
385 #ifdef MODEST_PLATFORM_MAEMO /* Defined in config.h */
387 /* Create the window if necessary: */
388 GtkWidget *specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
389 modest_connection_specific_smtp_window_fill_with_connections (
390 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (specific_window),
391 modest_runtime_get_account_mgr(),
392 modest_window_get_active_account (win));
394 /* Show the window: */
395 gtk_window_set_transient_for (GTK_WINDOW (specific_window), GTK_WINDOW (win));
396 gtk_window_set_modal (GTK_WINDOW (specific_window), TRUE);
397 gtk_widget_show (specific_window);
399 /* Save changes when the window is hidden: */
400 g_signal_connect (specific_window, "hide",
401 G_CALLBACK (on_smtp_servers_window_hide), win);
402 #endif /* MODEST_PLATFORM_MAEMO */
406 modest_ui_actions_on_new_msg (GtkAction *action, ModestWindow *win)
408 ModestWindow *msg_win;
410 TnyFolder *folder = NULL;
411 gchar *account_name = NULL;
412 gchar *from_str = NULL;
413 /* GError *err = NULL; */
414 TnyAccount *account = NULL;
415 ModestWindowMgr *mgr;
416 gchar *signature = NULL;
418 account_name = g_strdup(modest_window_get_active_account (win));
420 account_name = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
422 g_printerr ("modest: no account found\n");
426 account = modest_tny_account_store_get_tny_account_by_account (modest_runtime_get_account_store(),
428 TNY_ACCOUNT_TYPE_STORE);
430 g_printerr ("modest: failed to get tnyaccount for '%s'\n", account_name);
434 from_str = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(), account_name);
436 g_printerr ("modest: failed get from string for '%s'\n", account_name);
440 if (modest_account_mgr_get_bool (modest_runtime_get_account_mgr (), account_name,
441 MODEST_ACCOUNT_USE_SIGNATURE, FALSE)) {
442 signature = modest_account_mgr_get_string (modest_runtime_get_account_mgr (), account_name,
443 MODEST_ACCOUNT_SIGNATURE, FALSE);
445 signature = g_strdup ("");
448 msg = modest_tny_msg_new ("", from_str, "", "", "", signature, NULL);
450 g_printerr ("modest: failed to create new msg\n");
454 folder = modest_tny_account_get_special_folder (account, TNY_FOLDER_TYPE_DRAFTS);
456 g_printerr ("modest: failed to find Drafts folder\n");
460 /* tny_folder_add_msg (folder, msg, &err); */
462 /* g_printerr ("modest: error adding msg to Drafts folder: %s", */
464 /* g_error_free (err); */
468 /* Create and register edit window */
469 msg_win = modest_msg_edit_window_new (msg, account_name);
470 mgr = modest_runtime_get_window_mgr ();
471 modest_window_mgr_register_window (mgr, msg_win);
474 gtk_window_set_transient_for (GTK_WINDOW (msg_win),
476 gtk_widget_show_all (GTK_WIDGET (msg_win));
479 g_free (account_name);
483 g_object_unref (G_OBJECT(account));
485 g_object_unref (G_OBJECT(msg));
487 g_object_unref (G_OBJECT(folder));
491 headers_action_open (TnyHeader *header,
495 modest_ui_actions_on_header_activated (MODEST_HEADER_VIEW (user_data),
497 MODEST_MAIN_WINDOW (win));
501 modest_ui_actions_on_open (GtkAction *action, ModestWindow *win)
503 GtkWidget *header_view;
505 /* Get header view */
506 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
507 MODEST_WIDGET_TYPE_HEADER_VIEW);
509 /* Open each message */
510 do_headers_action (win, headers_action_open, header_view);
515 open_msg_func (const GObject *obj, TnyMsg *msg, gpointer user_data)
517 ModestWindowMgr *mgr = NULL;
518 ModestWindow *parent_win = NULL;
519 ModestWindow *win = NULL;
520 HeaderActivatedHelper *helper = NULL;
521 TnyFolderType folder_type = TNY_FOLDER_TYPE_UNKNOWN;
522 gchar *account = NULL;
524 g_return_if_fail (MODEST_IS_WINDOW(obj));
525 g_return_if_fail (user_data != NULL);
527 /* TODO: Show an error? (review the specs) */
531 parent_win = MODEST_WINDOW(obj);
532 helper = (HeaderActivatedHelper *) user_data;
534 /* Mark header as read */
535 headers_action_mark_as_read (helper->header, MODEST_WINDOW(parent_win), NULL);
538 account = g_strdup(modest_window_get_active_account(MODEST_WINDOW(parent_win)));
540 account = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
542 /* Gets foldert type (OUTBOX headers will be opened in edit window */
543 if (modest_tny_folder_is_local_folder (helper->folder))
544 folder_type = modest_tny_folder_get_local_folder_type (helper->folder);
546 switch (folder_type) {
547 case TNY_FOLDER_TYPE_DRAFTS:
548 win = modest_msg_edit_window_new ((TnyMsg *) msg, account);
551 if (helper->model != NULL)
552 win = modest_msg_view_window_new_with_header_model ((TnyMsg *) msg, account, helper->model, helper->row_reference);
554 win = modest_msg_view_window_new ((TnyMsg *) msg, account);
557 /* Register and show new window */
559 mgr = modest_runtime_get_window_mgr ();
560 modest_window_mgr_register_window (mgr, win);
561 gtk_window_set_transient_for (GTK_WINDOW (win), GTK_WINDOW (parent_win));
562 gtk_widget_show_all (GTK_WIDGET(win));
567 /* g_object_unref (G_OBJECT(msg)); */
568 g_object_unref (G_OBJECT(helper->folder));
569 g_object_unref (G_OBJECT(helper->header));
570 gtk_tree_row_reference_free (helper->row_reference);
571 g_slice_free (HeaderActivatedHelper, helper);
575 free_reply_forward_helper (gpointer data)
577 ReplyForwardHelper *helper;
579 helper = (ReplyForwardHelper *) data;
580 g_free (helper->account_name);
581 g_slice_free (ReplyForwardHelper, helper);
585 reply_forward_func (const GObject *obj, TnyMsg *msg, gpointer user_data)
588 ReplyForwardHelper *rf_helper;
589 ModestWindow *msg_win;
590 ModestEditType edit_type;
593 TnyFolder *folder = NULL;
594 TnyAccount *account = NULL;
595 ModestWindowMgr *mgr;
596 gchar *signature = NULL;
598 g_return_if_fail (user_data != NULL);
599 rf_helper = (ReplyForwardHelper *) user_data;
601 from = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(),
602 rf_helper->account_name);
603 if (modest_account_mgr_get_bool (modest_runtime_get_account_mgr(),
604 rf_helper->account_name,
605 MODEST_ACCOUNT_USE_SIGNATURE, FALSE)) {
606 signature = modest_account_mgr_get_string (modest_runtime_get_account_mgr (),
607 rf_helper->account_name,
608 MODEST_ACCOUNT_SIGNATURE, FALSE);
611 /* Create reply mail */
612 switch (rf_helper->action) {
615 modest_tny_msg_create_reply_msg ((TnyMsg *) msg, from, signature,
616 rf_helper->reply_forward_type,
617 MODEST_TNY_MSG_REPLY_MODE_SENDER);
619 case ACTION_REPLY_TO_ALL:
621 modest_tny_msg_create_reply_msg ((TnyMsg *) msg, from, signature, rf_helper->reply_forward_type,
622 MODEST_TNY_MSG_REPLY_MODE_ALL);
623 edit_type = MODEST_EDIT_TYPE_REPLY;
627 modest_tny_msg_create_forward_msg ((TnyMsg *) msg, from, signature, rf_helper->reply_forward_type);
628 edit_type = MODEST_EDIT_TYPE_FORWARD;
631 g_return_if_reached ();
638 g_printerr ("modest: failed to create message\n");
642 account = modest_tny_account_store_get_tny_account_by_account (modest_runtime_get_account_store(),
643 rf_helper->account_name,
644 TNY_ACCOUNT_TYPE_STORE);
646 g_printerr ("modest: failed to get tnyaccount for '%s'\n", rf_helper->account_name);
650 folder = modest_tny_account_get_special_folder (account, TNY_FOLDER_TYPE_DRAFTS);
652 g_printerr ("modest: failed to find Drafts folder\n");
656 tny_folder_add_msg (folder, (TnyMsg *) msg, &err);
657 g_object_unref (msg);
659 g_printerr ("modest: error adding msg to Drafts folder: %s",
665 /* Create and register the windows */
666 msg_win = modest_msg_edit_window_new (new_msg, rf_helper->account_name);
667 mgr = modest_runtime_get_window_mgr ();
668 modest_window_mgr_register_window (mgr, msg_win);
670 /* Show edit window */
671 gtk_widget_show_all (GTK_WIDGET (msg_win));
675 g_object_unref (G_OBJECT (new_msg));
677 g_object_unref (G_OBJECT (folder));
679 g_object_unref (G_OBJECT (account));
683 * Common code for the reply and forward actions
686 reply_forward (ReplyForwardAction action, ModestWindow *win)
688 ModestMailOperation *mail_op = NULL;
689 TnyList *header_list = NULL;
690 ReplyForwardHelper *rf_helper = NULL;
691 guint reply_forward_type;
693 g_return_if_fail (MODEST_IS_WINDOW(win));
695 header_list = get_selected_headers (win);
699 reply_forward_type = modest_conf_get_int (modest_runtime_get_conf (),
700 (action == ACTION_FORWARD) ? MODEST_CONF_FORWARD_TYPE : MODEST_CONF_REPLY_TYPE,
702 /* We assume that we can only select messages of the
703 same folder and that we reply all of them from the
704 same account. In fact the interface currently only
705 allows single selection */
708 rf_helper = g_slice_new0 (ReplyForwardHelper);
709 rf_helper->reply_forward_type = reply_forward_type;
710 rf_helper->action = action;
711 rf_helper->account_name = g_strdup (modest_window_get_active_account (win));
712 if (!rf_helper->account_name)
713 rf_helper->account_name =
714 modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
716 if (MODEST_IS_MSG_VIEW_WINDOW(win)) {
718 msg = modest_msg_view_window_get_message(MODEST_MSG_VIEW_WINDOW(win));
720 g_printerr ("modest: no message found\n");
723 reply_forward_func (G_OBJECT(win), g_object_ref (msg), rf_helper);
725 /* Retrieve messages */
726 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE, G_OBJECT(win));
727 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
728 modest_mail_operation_get_msgs_full (mail_op,
732 free_reply_forward_helper);
735 g_object_unref(mail_op);
740 modest_ui_actions_on_reply (GtkAction *action, ModestWindow *win)
742 g_return_if_fail (MODEST_IS_WINDOW(win));
744 reply_forward (ACTION_REPLY, win);
748 modest_ui_actions_on_forward (GtkAction *action, ModestWindow *win)
750 g_return_if_fail (MODEST_IS_WINDOW(win));
752 reply_forward (ACTION_FORWARD, win);
756 modest_ui_actions_on_reply_all (GtkAction *action, ModestWindow *win)
758 g_return_if_fail (MODEST_IS_WINDOW(win));
760 reply_forward (ACTION_REPLY_TO_ALL, win);
764 modest_ui_actions_on_next (GtkAction *action,
765 ModestWindow *window)
767 if (MODEST_IS_MAIN_WINDOW (window)) {
768 GtkWidget *header_view;
770 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
771 MODEST_WIDGET_TYPE_HEADER_VIEW);
775 modest_header_view_select_next (MODEST_HEADER_VIEW(header_view));
776 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
777 modest_msg_view_window_select_next_message (MODEST_MSG_VIEW_WINDOW (window));
779 g_return_if_reached ();
784 modest_ui_actions_on_prev (GtkAction *action,
785 ModestWindow *window)
787 g_return_if_fail (MODEST_IS_WINDOW(window));
789 if (MODEST_IS_MAIN_WINDOW (window)) {
790 GtkWidget *header_view;
791 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
792 MODEST_WIDGET_TYPE_HEADER_VIEW);
796 modest_header_view_select_prev (MODEST_HEADER_VIEW(header_view));
797 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
798 modest_msg_view_window_select_previous_message (MODEST_MSG_VIEW_WINDOW (window));
800 g_return_if_reached ();
805 modest_ui_actions_on_sort (GtkAction *action,
806 ModestWindow *window)
808 g_return_if_fail (MODEST_IS_WINDOW(window));
810 if (MODEST_IS_MAIN_WINDOW (window)) {
811 GtkWidget *header_view;
812 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
813 MODEST_WIDGET_TYPE_HEADER_VIEW);
817 /* Show sorting dialog */
818 modest_platform_run_sort_dialog (GTK_WINDOW (window), MODEST_SORT_HEADERS);
822 /** Check that an appropriate connection is open.
824 gboolean check_for_connection (const gchar *account_name)
826 TnyDevice *device = modest_runtime_get_device ();
829 g_assert (TNY_IS_MAEMO_CONIC_DEVICE (device));
831 TnyMaemoConicDevice *maemo_device = TNY_MAEMO_CONIC_DEVICE (device);
834 if (tny_device_is_online (device))
837 modest_platform_connect_and_wait (NULL);
839 /* TODO: Wait until a result. */
845 * This function performs the send & receive required actions. The
846 * window it's used to create the mail operation. Tipically it should
847 * be allways the main window, but we pass it as argument in order to
851 modest_ui_actions_do_send_receive (const gchar *account_name, ModestWindow *win)
853 gchar *acc_name = NULL;
855 /* If no account name was provided get the current account, if
856 there is none either then pick the default one */
858 acc_name = g_strdup (modest_window_get_active_account(win));
860 acc_name = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
862 g_printerr ("modest: cannot get default account\n");
866 acc_name = g_strdup (account_name);
869 /* Send & receive. Do not continue if no suitable connection
871 if (check_for_connection (acc_name)) {
872 /* As per the UI spec,
873 * for POP accounts, we should receive,
874 * for IMAP we should synchronize everything, including receiving,
875 * for SMTP we should send,
876 * first receiving, then sending:
878 /* Create the mail operation */
879 /* TODO: The spec wants us to first do any pending deletions, before receiving. */
880 ModestMailOperation *mail_op;
881 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE, G_OBJECT(win));
882 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
883 modest_mail_operation_update_account (mail_op, acc_name);
884 g_object_unref (G_OBJECT (mail_op));
891 * Refreshes all accounts. This function will be used by automatic
895 modest_ui_actions_do_send_receive_all (ModestWindow *win)
897 GSList *account_names, *iter;
899 account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
902 iter = account_names;
904 modest_ui_actions_do_send_receive ((const char*) iter->data, win);
905 iter = g_slist_next (iter);
908 g_slist_foreach (account_names, (GFunc) g_free, NULL);
909 g_slist_free (account_names);
913 * Handler of the click on Send&Receive button in the main toolbar
916 modest_ui_actions_on_send_receive (GtkAction *action, ModestWindow *win)
918 /* Check that at least one account exists: */
919 GSList *account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
920 TRUE /* enabled accounts only */);
921 gboolean accounts_exist = account_names != NULL;
922 g_slist_free (account_names);
924 /* If not, allow the user to create an account before trying to send/receive. */
926 modest_ui_actions_on_accounts (NULL, win);
928 /* Refresh the active account */
929 modest_ui_actions_do_send_receive (NULL, win);
934 modest_ui_actions_toggle_header_list_view (GtkAction *action, ModestMainWindow *main_window)
937 GtkWidget *header_view;
939 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
941 header_view = modest_main_window_get_child_widget (main_window,
942 MODEST_WIDGET_TYPE_HEADER_VIEW);
946 conf = modest_runtime_get_conf ();
948 /* what is saved/restored is depending on the style; thus; we save with
949 * old style, then update the style, and restore for this new style
951 modest_widget_memory_save (conf, G_OBJECT(header_view), MODEST_CONF_HEADER_VIEW_KEY);
953 if (modest_header_view_get_style
954 (MODEST_HEADER_VIEW(header_view)) == MODEST_HEADER_VIEW_STYLE_DETAILS)
955 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
956 MODEST_HEADER_VIEW_STYLE_TWOLINES);
958 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
959 MODEST_HEADER_VIEW_STYLE_DETAILS);
961 modest_widget_memory_restore (conf, G_OBJECT(header_view),
962 MODEST_CONF_HEADER_VIEW_KEY);
967 modest_ui_actions_on_header_selected (ModestHeaderView *header_view,
969 ModestMainWindow *main_window)
971 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
973 /* If no header has been selected then exit */
977 /* Update Main window title */
978 if (GTK_WIDGET_HAS_FOCUS (header_view)) {
979 const gchar *subject = tny_header_get_subject (header);
980 if (subject && strcmp (subject, ""))
981 gtk_window_set_title (GTK_WINDOW (main_window), subject);
983 gtk_window_set_title (GTK_WINDOW (main_window), _("mail_va_no_subject"));
988 modest_ui_actions_on_header_activated (ModestHeaderView *header_view,
990 ModestMainWindow *main_window)
992 ModestMailOperation *mail_op = NULL;
993 HeaderActivatedHelper *helper = NULL;
994 ModestWindowMgr *mgr = NULL;
995 ModestWindow *win = NULL;
996 GtkTreeModel *model = NULL;
997 GtkTreeSelection *sel = NULL;
998 GList *sel_list = NULL;
1000 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1005 /* Look if we already have a message view for that header */
1006 mgr = modest_runtime_get_window_mgr ();
1007 win = modest_window_mgr_find_window_by_msguid (mgr, tny_header_get_uid (header));
1011 helper = g_slice_new0 (HeaderActivatedHelper);
1012 helper->folder = tny_header_get_folder (header);
1013 helper->header = g_object_ref(header);
1014 helper->model = NULL;
1016 /* Get headers tree model and selected row reference to build message view */
1017 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
1018 sel_list = gtk_tree_selection_get_selected_rows (sel, &model);
1019 if (sel_list != NULL) {
1022 helper->model = model;
1023 helper->row_reference = gtk_tree_row_reference_new (model, (GtkTreePath *) sel_list->data);
1025 g_list_foreach (sel_list, (GFunc) gtk_tree_path_free, NULL);
1026 g_list_free (sel_list);
1029 /* New mail operation */
1030 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE, G_OBJECT(main_window));
1031 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
1032 modest_mail_operation_get_msg (mail_op, header, open_msg_func, helper);
1035 g_object_unref (mail_op);
1039 set_active_account_from_tny_account (TnyAccount *account,
1040 ModestWindow *window)
1042 TnyAccount *modest_server_account;
1043 const gchar *server_acc_name;
1044 gchar *modest_acc_name;
1046 server_acc_name = tny_account_get_id (account);
1047 /* We need the TnyAccount provided by the
1048 account store because that is the one that
1049 knows the name of the Modest account */
1050 modest_server_account =
1051 modest_tny_account_store_get_tny_account_by_id (modest_runtime_get_account_store (),
1053 modest_acc_name = (gchar *) g_object_get_data (G_OBJECT (modest_server_account), "modest_account");
1054 modest_window_set_active_account (window, modest_acc_name);
1055 g_object_unref (modest_server_account);
1059 modest_ui_actions_on_folder_selection_changed (ModestFolderView *folder_view,
1060 TnyFolderStore *folder_store,
1062 ModestMainWindow *main_window)
1065 GtkWidget *header_view;
1066 TnyAccount *account;
1068 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1070 header_view = modest_main_window_get_child_widget(main_window,
1071 MODEST_WIDGET_TYPE_HEADER_VIEW);
1075 conf = modest_runtime_get_conf ();
1077 if (TNY_IS_FOLDER (folder_store)) {
1080 /* Update the active account */
1081 account = tny_folder_get_account (TNY_FOLDER (folder_store));
1082 set_active_account_from_tny_account (account, MODEST_WINDOW (main_window));
1083 g_object_unref (account);
1085 /* Set folder on header view */
1086 modest_main_window_set_contents_style (main_window,
1087 MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS);
1088 modest_header_view_set_folder (MODEST_HEADER_VIEW(header_view),
1089 TNY_FOLDER (folder_store));
1090 modest_widget_memory_restore (conf, G_OBJECT(header_view),
1091 MODEST_CONF_HEADER_VIEW_KEY);
1093 /* Update the active account */
1094 modest_window_set_active_account (MODEST_WINDOW (main_window), NULL);
1095 /* Do not show folder */
1096 modest_widget_memory_save (conf, G_OBJECT (header_view), MODEST_CONF_HEADER_VIEW_KEY);
1097 modest_header_view_set_folder (MODEST_HEADER_VIEW(header_view), NULL);
1099 } else if (TNY_IS_ACCOUNT (folder_store)) {
1100 /* Update active account */
1101 set_active_account_from_tny_account (TNY_ACCOUNT (folder_store), MODEST_WINDOW (main_window));
1102 /* Show account details */
1103 modest_main_window_set_contents_style (main_window, MODEST_MAIN_WINDOW_CONTENTS_STYLE_DETAILS);
1108 modest_ui_actions_on_item_not_found (ModestHeaderView *header_view,ModestItemType type,
1115 item = (type == MODEST_ITEM_TYPE_FOLDER) ? "folder" : "message";
1117 if (g_main_depth > 0)
1118 gdk_threads_enter ();
1119 online = tny_device_is_online (modest_runtime_get_device());
1122 /* already online -- the item is simply not there... */
1123 dialog = gtk_message_dialog_new (GTK_WINDOW (win),
1125 GTK_MESSAGE_WARNING,
1127 _("The %s you selected cannot be found"),
1129 gtk_dialog_run (GTK_DIALOG(dialog));
1131 dialog = gtk_dialog_new_with_buttons (_("Connection requested"),
1135 GTK_RESPONSE_REJECT,
1137 GTK_RESPONSE_ACCEPT,
1139 txt = g_strdup_printf (_("This %s is not available in offline mode.\n"
1140 "Do you want to get online?"), item);
1141 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
1142 gtk_label_new (txt), FALSE, FALSE, 0);
1143 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
1146 gtk_window_set_default_size (GTK_WINDOW(dialog), 300, 300);
1147 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
1148 // modest_platform_connect_and_wait ();;
1151 gtk_widget_destroy (dialog);
1152 if (g_main_depth > 0)
1153 gdk_threads_leave ();
1157 modest_ui_actions_on_msg_link_hover (ModestMsgView *msgview, const gchar* link,
1160 /* g_message ("%s %s", __FUNCTION__, link); */
1165 modest_ui_actions_on_msg_link_clicked (ModestMsgView *msgview, const gchar* link,
1168 modest_platform_activate_uri (link);
1172 modest_ui_actions_on_msg_link_contextual (ModestMsgView *msgview, const gchar* link,
1175 modest_platform_show_uri_popup (link);
1179 modest_ui_actions_on_msg_attachment_clicked (ModestMsgView *msgview, TnyMimePart *mime_part,
1182 modest_msg_view_window_view_attachment (MODEST_MSG_VIEW_WINDOW (win), mime_part);
1186 modest_ui_actions_on_msg_recpt_activated (ModestMsgView *msgview,
1187 const gchar *address,
1190 /* g_message ("%s %s", __FUNCTION__, address); */
1194 modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edit_window)
1196 TnyTransportAccount *transport_account;
1197 ModestMailOperation *mail_operation;
1199 gchar *account_name, *from;
1200 ModestAccountMgr *account_mgr;
1202 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window));
1204 data = modest_msg_edit_window_get_msg_data (edit_window);
1206 account_mgr = modest_runtime_get_account_mgr();
1207 account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
1209 account_name = modest_account_mgr_get_default_account (account_mgr);
1210 if (!account_name) {
1211 g_printerr ("modest: no account found\n");
1212 modest_msg_edit_window_free_msg_data (edit_window, data);
1216 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_tny_account_by_account
1217 (modest_runtime_get_account_store(),
1219 TNY_ACCOUNT_TYPE_TRANSPORT));
1220 if (!transport_account) {
1221 g_printerr ("modest: no transport account found for '%s'\n", account_name);
1222 g_free (account_name);
1223 modest_msg_edit_window_free_msg_data (edit_window, data);
1226 from = modest_account_mgr_get_from_string (account_mgr, account_name);
1228 /* Create the mail operation */
1229 mail_operation = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_INFO, G_OBJECT(edit_window));
1230 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
1232 modest_mail_operation_save_to_drafts (mail_operation,
1242 data->priority_flags);
1245 g_free (account_name);
1246 g_object_unref (G_OBJECT (transport_account));
1247 g_object_unref (G_OBJECT (mail_operation));
1249 modest_msg_edit_window_free_msg_data (edit_window, data);
1251 /* Save settings and close the window */
1252 gtk_widget_destroy (GTK_WIDGET (edit_window));
1255 modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
1257 TnyTransportAccount *transport_account;
1258 ModestMailOperation *mail_operation;
1260 gchar *account_name, *from;
1261 ModestAccountMgr *account_mgr;
1263 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window));
1265 if (!modest_msg_edit_window_check_names (edit_window))
1268 data = modest_msg_edit_window_get_msg_data (edit_window);
1270 /* FIXME: Code added just for testing. The final version will
1271 use the send queue provided by tinymail and some
1273 account_mgr = modest_runtime_get_account_mgr();
1274 account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
1276 account_name = modest_account_mgr_get_default_account (account_mgr);
1277 if (!account_name) {
1278 g_printerr ("modest: no account found\n");
1279 modest_msg_edit_window_free_msg_data (edit_window, data);
1283 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_transport_account_for_open_connection
1284 (modest_runtime_get_account_store(),
1286 if (!transport_account) {
1287 g_printerr ("modest: no transport account found for '%s'\n", account_name);
1288 g_free (account_name);
1289 modest_msg_edit_window_free_msg_data (edit_window, data);
1292 from = modest_account_mgr_get_from_string (account_mgr, account_name);
1294 /* Create the mail operation */
1295 mail_operation = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_SEND, G_OBJECT(edit_window));
1296 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
1298 modest_mail_operation_send_new_mail (mail_operation,
1308 data->priority_flags);
1311 g_free (account_name);
1312 g_object_unref (G_OBJECT (transport_account));
1313 g_object_unref (G_OBJECT (mail_operation));
1315 modest_msg_edit_window_free_msg_data (edit_window, data);
1317 /* Save settings and close the window */
1318 gtk_widget_destroy (GTK_WIDGET (edit_window));
1322 modest_ui_actions_on_toggle_bold (GtkToggleAction *action,
1323 ModestMsgEditWindow *window)
1325 ModestMsgEditFormatState *format_state = NULL;
1327 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1328 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
1330 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
1333 format_state = modest_msg_edit_window_get_format_state (window);
1334 g_return_if_fail (format_state != NULL);
1336 format_state->bold = gtk_toggle_action_get_active (action);
1337 modest_msg_edit_window_set_format_state (window, format_state);
1338 g_free (format_state);
1343 modest_ui_actions_on_toggle_italics (GtkToggleAction *action,
1344 ModestMsgEditWindow *window)
1346 ModestMsgEditFormatState *format_state = NULL;
1348 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1349 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
1351 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
1354 format_state = modest_msg_edit_window_get_format_state (window);
1355 g_return_if_fail (format_state != NULL);
1357 format_state->italics = gtk_toggle_action_get_active (action);
1358 modest_msg_edit_window_set_format_state (window, format_state);
1359 g_free (format_state);
1364 modest_ui_actions_on_toggle_bullets (GtkToggleAction *action,
1365 ModestMsgEditWindow *window)
1367 ModestMsgEditFormatState *format_state = NULL;
1369 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1370 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
1372 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
1375 format_state = modest_msg_edit_window_get_format_state (window);
1376 g_return_if_fail (format_state != NULL);
1378 format_state->bullet = gtk_toggle_action_get_active (action);
1379 modest_msg_edit_window_set_format_state (window, format_state);
1380 g_free (format_state);
1385 modest_ui_actions_on_change_justify (GtkRadioAction *action,
1386 GtkRadioAction *selected,
1387 ModestMsgEditWindow *window)
1389 ModestMsgEditFormatState *format_state = NULL;
1390 GtkJustification value;
1392 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1394 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
1397 value = gtk_radio_action_get_current_value (selected);
1399 format_state = modest_msg_edit_window_get_format_state (window);
1400 g_return_if_fail (format_state != NULL);
1402 format_state->justification = value;
1403 modest_msg_edit_window_set_format_state (window, format_state);
1404 g_free (format_state);
1408 modest_ui_actions_on_select_editor_color (GtkAction *action,
1409 ModestMsgEditWindow *window)
1411 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1412 g_return_if_fail (GTK_IS_ACTION (action));
1414 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
1417 modest_msg_edit_window_select_color (window);
1421 modest_ui_actions_on_select_editor_background_color (GtkAction *action,
1422 ModestMsgEditWindow *window)
1424 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1425 g_return_if_fail (GTK_IS_ACTION (action));
1427 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
1430 modest_msg_edit_window_select_background_color (window);
1434 modest_ui_actions_on_insert_image (GtkAction *action,
1435 ModestMsgEditWindow *window)
1437 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1438 g_return_if_fail (GTK_IS_ACTION (action));
1440 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
1443 modest_msg_edit_window_insert_image (window);
1447 modest_ui_actions_on_attach_file (GtkAction *action,
1448 ModestMsgEditWindow *window)
1450 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1451 g_return_if_fail (GTK_IS_ACTION (action));
1453 modest_msg_edit_window_attach_file (window);
1457 modest_ui_actions_on_remove_attachments (GtkAction *action,
1458 ModestMsgEditWindow *window)
1460 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1461 g_return_if_fail (GTK_IS_ACTION (action));
1463 modest_msg_edit_window_remove_attachments (window, NULL);
1467 * Shows a dialog with an entry that asks for some text. The returned
1468 * value must be freed by the caller. The dialog window title will be
1472 ask_for_folder_name (GtkWindow *parent_window,
1475 GtkWidget *dialog, *entry;
1476 gchar *folder_name = NULL;
1478 /* Ask for folder name */
1479 dialog = gtk_dialog_new_with_buttons (_("New Folder Name"),
1483 GTK_RESPONSE_REJECT,
1485 GTK_RESPONSE_ACCEPT,
1487 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
1488 gtk_label_new(title),
1491 entry = gtk_entry_new_with_max_length (40);
1492 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
1496 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
1498 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
1499 folder_name = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry)));
1501 gtk_widget_destroy (dialog);
1507 modest_ui_actions_on_new_folder (GtkAction *action, ModestMainWindow *main_window)
1509 TnyFolderStore *parent_folder;
1510 GtkWidget *folder_view;
1512 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1514 folder_view = modest_main_window_get_child_widget (main_window,
1515 MODEST_WIDGET_TYPE_FOLDER_VIEW);
1519 parent_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
1521 if (parent_folder) {
1522 gboolean finished = FALSE;
1524 gchar *folder_name = NULL, *suggested_name = NULL;
1526 /* Run the new folder dialog */
1528 result = modest_platform_run_new_folder_dialog (GTK_WINDOW (main_window),
1533 if (result == GTK_RESPONSE_REJECT) {
1536 ModestMailOperation *mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_INFO, G_OBJECT(main_window));
1537 TnyFolder *new_folder = NULL;
1539 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
1542 new_folder = modest_mail_operation_create_folder (mail_op,
1544 (const gchar *) folder_name);
1546 g_object_unref (new_folder);
1550 /* /\* TODO: check error and follow proper actions *\/ */
1551 /* /\* suggested_name = X; *\/ */
1552 /* /\* Show error to the user *\/ */
1553 /* modest_platform_run_information_dialog (GTK_WINDOW (main_window), */
1554 /* _("mail_in_ui_folder_create_error")); */
1556 g_object_unref (mail_op);
1558 g_free (folder_name);
1562 g_object_unref (parent_folder);
1567 modest_ui_actions_on_rename_folder (GtkAction *action,
1568 ModestMainWindow *main_window)
1570 TnyFolderStore *folder;
1571 GtkWidget *folder_view;
1572 GtkWidget *header_view;
1574 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1576 folder_view = modest_main_window_get_child_widget (main_window,
1577 MODEST_WIDGET_TYPE_FOLDER_VIEW);
1581 header_view = modest_main_window_get_child_widget (main_window,
1582 MODEST_WIDGET_TYPE_HEADER_VIEW);
1587 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
1589 if (folder && TNY_IS_FOLDER (folder)) {
1591 folder_name = ask_for_folder_name (GTK_WINDOW (main_window),
1592 _("Please enter a new name for the folder"));
1594 if (folder_name != NULL && strlen (folder_name) > 0) {
1595 ModestMailOperation *mail_op;
1597 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_INFO, G_OBJECT(main_window));
1598 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
1601 modest_header_view_set_folder (MODEST_HEADER_VIEW (header_view), NULL);
1603 modest_mail_operation_rename_folder (mail_op,
1604 TNY_FOLDER (folder),
1605 (const gchar *) folder_name);
1607 g_object_unref (mail_op);
1608 g_free (folder_name);
1610 g_object_unref (folder);
1615 delete_folder (ModestMainWindow *main_window, gboolean move_to_trash)
1617 TnyFolderStore *folder;
1618 GtkWidget *folder_view;
1622 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1624 folder_view = modest_main_window_get_child_widget (main_window,
1625 MODEST_WIDGET_TYPE_FOLDER_VIEW);
1629 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
1631 /* Show an error if it's an account */
1632 if (!TNY_IS_FOLDER (folder)) {
1633 modest_platform_run_information_dialog (GTK_WINDOW (main_window),
1634 _("mail_in_ui_folder_delete_error"));
1639 message = g_strdup_printf (_("mcen_nc_delete_folder_text"),
1640 tny_folder_get_name (TNY_FOLDER (folder)));
1641 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (main_window),
1642 (const gchar *) message);
1645 if (response == GTK_RESPONSE_OK) {
1646 ModestMailOperation *mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_DELETE, G_OBJECT(main_window));
1648 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
1650 modest_mail_operation_remove_folder (mail_op, TNY_FOLDER (folder), move_to_trash);
1652 /* Show error if happened */
1653 if (modest_mail_operation_get_error (mail_op))
1654 modest_platform_run_information_dialog (GTK_WINDOW (main_window),
1655 _("mail_in_ui_folder_delete_error"));
1657 g_object_unref (G_OBJECT (mail_op));
1660 g_object_unref (G_OBJECT (folder));
1664 modest_ui_actions_on_delete_folder (GtkAction *action,
1665 ModestMainWindow *main_window)
1667 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1669 delete_folder (main_window, FALSE);
1673 modest_ui_actions_on_move_folder_to_trash_folder (GtkAction *action, ModestMainWindow *main_window)
1675 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1677 delete_folder (main_window, TRUE);
1681 modest_ui_actions_on_password_requested (TnyAccountStore *account_store,
1682 const gchar* server_account_name,
1687 ModestMainWindow *main_window)
1689 g_return_if_fail(server_account_name);
1690 /* printf("DEBUG: %s: server_account_name=%s\n", __FUNCTION__, server_account_name); */
1692 #ifdef MODEST_PLATFORM_MAEMO
1693 /* Maemo uses a different (awkward) button order,
1694 * It should probably just use gtk_alternative_dialog_button_order ().
1696 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
1700 GTK_RESPONSE_ACCEPT,
1702 GTK_RESPONSE_REJECT,
1705 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
1709 GTK_RESPONSE_REJECT,
1711 GTK_RESPONSE_ACCEPT,
1713 #endif /* MODEST_PLATFORM_MAEMO */
1715 gtk_window_set_transient_for (GTK_WINDOW(dialog), GTK_WINDOW(main_window));
1717 gchar *server_name = modest_server_account_get_hostname (
1718 modest_runtime_get_account_mgr(), server_account_name);
1720 /* This causes a warning because the logical ID has no %s in it,
1721 * though the translation does, but there is not much we can do about that: */
1722 gchar *txt = g_strdup_printf (_("mail_ia_password_info"), server_name);
1723 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), gtk_label_new(txt),
1726 g_free (server_name);
1730 gchar *initial_username = modest_server_account_get_username (
1731 modest_runtime_get_account_mgr(), server_account_name);
1733 GtkWidget *entry_username = gtk_entry_new ();
1734 if (initial_username)
1735 gtk_entry_set_text (GTK_ENTRY (entry_username), initial_username);
1736 /* Dim this if a connection has ever succeeded with this username,
1737 * as per the UI spec: */
1738 const gboolean username_known =
1739 modest_server_account_get_username_has_succeeded(
1740 modest_runtime_get_account_mgr(), server_account_name);
1741 gtk_widget_set_sensitive (entry_username, !username_known);
1743 #ifdef MODEST_PLATFORM_MAEMO
1744 /* Auto-capitalization is the default, so let's turn it off: */
1745 hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_username), HILDON_GTK_INPUT_MODE_FULL);
1747 /* Create a size group to be used by all captions.
1748 * Note that HildonCaption does not create a default size group if we do not specify one.
1749 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
1750 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
1752 GtkWidget *caption = hildon_caption_new (sizegroup,
1753 _("mail_fi_username"), entry_username, NULL, HILDON_CAPTION_MANDATORY);
1754 gtk_widget_show (entry_username);
1755 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
1756 FALSE, FALSE, MODEST_MARGIN_HALF);
1757 gtk_widget_show (caption);
1759 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry_username,
1761 #endif /* MODEST_PLATFORM_MAEMO */
1764 GtkWidget *entry_password = gtk_entry_new ();
1765 gtk_entry_set_visibility (GTK_ENTRY(entry_password), FALSE);
1766 /* gtk_entry_set_invisible_char (GTK_ENTRY(entry_password), "*"); */
1768 #ifdef MODEST_PLATFORM_MAEMO
1769 /* Auto-capitalization is the default, so let's turn it off: */
1770 hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_password),
1771 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
1773 caption = hildon_caption_new (sizegroup,
1774 _("mail_fi_password"), entry_password, NULL, HILDON_CAPTION_MANDATORY);
1775 gtk_widget_show (entry_password);
1776 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
1777 FALSE, FALSE, MODEST_MARGIN_HALF);
1778 gtk_widget_show (caption);
1779 g_object_unref (sizegroup);
1781 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry_password,
1783 #endif /* MODEST_PLATFORM_MAEMO */
1785 /* This is not in the Maemo UI spec:
1786 remember_pass_check = gtk_check_button_new_with_label (_("Remember password"));
1787 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), remember_pass_check,
1791 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
1793 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
1795 *username = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_username)));
1797 modest_server_account_set_username (
1798 modest_runtime_get_account_mgr(), server_account_name,
1801 const gboolean username_was_changed =
1802 (strcmp (*username, initial_username) != 0);
1803 if (username_was_changed) {
1804 /* To actually use a changed username,
1805 * we must reset the connection, according to pvanhoof.
1806 * This _might_ be a sensible way to do that: */
1807 TnyDevice *device = modest_runtime_get_device();
1808 tny_device_force_offline (device);
1809 tny_device_force_online (device);
1814 *password = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_password)));
1816 /* We do not save the password in the configuration,
1817 * because this function is only called for passwords that should
1818 * not be remembered:
1819 modest_server_account_set_password (
1820 modest_runtime_get_account_mgr(), server_account_name,
1839 /* This is not in the Maemo UI spec:
1840 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (remember_pass_check)))
1846 gtk_widget_destroy (dialog);
1850 modest_ui_actions_on_cut (GtkAction *action,
1851 ModestWindow *window)
1853 GtkWidget *focused_widget;
1855 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
1856 if (GTK_IS_EDITABLE (focused_widget)) {
1857 gtk_editable_cut_clipboard (GTK_EDITABLE(focused_widget));
1858 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
1859 GtkTextBuffer *buffer;
1860 GtkClipboard *clipboard;
1862 clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
1863 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
1864 gtk_text_buffer_cut_clipboard (buffer, clipboard, TRUE);
1869 modest_ui_actions_on_copy (GtkAction *action,
1870 ModestWindow *window)
1872 GtkClipboard *clipboard;
1873 GtkWidget *focused_widget;
1875 clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
1876 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
1877 if (GTK_IS_LABEL (focused_widget)) {
1878 gtk_clipboard_set_text (clipboard, gtk_label_get_text (GTK_LABEL (focused_widget)), -1);
1879 } else if (GTK_IS_EDITABLE (focused_widget)) {
1880 gtk_editable_copy_clipboard (GTK_EDITABLE(focused_widget));
1881 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
1882 GtkTextBuffer *buffer;
1884 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
1885 gtk_text_buffer_copy_clipboard (buffer, clipboard);
1890 modest_ui_actions_on_undo (GtkAction *action,
1891 ModestWindow *window)
1893 if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
1894 modest_msg_edit_window_undo (MODEST_MSG_EDIT_WINDOW (window));
1896 g_return_if_reached ();
1901 modest_ui_actions_on_paste (GtkAction *action,
1902 ModestWindow *window)
1904 GtkWidget *focused_widget;
1906 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
1907 if (GTK_IS_EDITABLE (focused_widget)) {
1908 gtk_editable_paste_clipboard (GTK_EDITABLE(focused_widget));
1909 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
1910 GtkTextBuffer *buffer;
1911 GtkClipboard *clipboard;
1913 clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
1914 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
1915 gtk_text_buffer_paste_clipboard (buffer, clipboard, NULL, TRUE);
1920 modest_ui_actions_on_select_all (GtkAction *action,
1921 ModestWindow *window)
1923 GtkWidget *focused_widget;
1925 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
1926 if (MODEST_IS_ATTACHMENTS_VIEW (focused_widget)) {
1927 modest_attachments_view_select_all (MODEST_ATTACHMENTS_VIEW (focused_widget));
1928 } else if (GTK_IS_LABEL (focused_widget)) {
1929 gtk_label_select_region (GTK_LABEL (focused_widget), 0, -1);
1930 } else if (GTK_IS_EDITABLE (focused_widget)) {
1931 gtk_editable_select_region (GTK_EDITABLE(focused_widget), 0, -1);
1932 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
1933 GtkTextBuffer *buffer;
1934 GtkTextIter start, end;
1936 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
1937 gtk_text_buffer_get_start_iter (buffer, &start);
1938 gtk_text_buffer_get_end_iter (buffer, &end);
1939 gtk_text_buffer_select_range (buffer, &start, &end);
1944 modest_ui_actions_on_mark_as_read (GtkAction *action,
1945 ModestWindow *window)
1947 g_return_if_fail (MODEST_IS_WINDOW(window));
1949 /* Mark each header as read */
1950 do_headers_action (window, headers_action_mark_as_read, NULL);
1954 modest_ui_actions_on_mark_as_unread (GtkAction *action,
1955 ModestWindow *window)
1957 g_return_if_fail (MODEST_IS_WINDOW(window));
1959 /* Mark each header as read */
1960 do_headers_action (window, headers_action_mark_as_unread, NULL);
1964 modest_ui_actions_on_change_zoom (GtkRadioAction *action,
1965 GtkRadioAction *selected,
1966 ModestWindow *window)
1970 value = gtk_radio_action_get_current_value (selected);
1971 if (MODEST_IS_WINDOW (window)) {
1972 modest_window_set_zoom (MODEST_WINDOW (window), ((gdouble)value)/100);
1976 void modest_ui_actions_msg_edit_on_change_priority (GtkRadioAction *action,
1977 GtkRadioAction *selected,
1978 ModestWindow *window)
1980 TnyHeaderFlags flags;
1981 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1983 flags = gtk_radio_action_get_current_value (selected);
1984 modest_msg_edit_window_set_priority_flags (MODEST_MSG_EDIT_WINDOW (window), flags);
1987 void modest_ui_actions_msg_edit_on_change_file_format (GtkRadioAction *action,
1988 GtkRadioAction *selected,
1989 ModestWindow *window)
1993 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1995 file_format = gtk_radio_action_get_current_value (selected);
1996 modest_msg_edit_window_set_file_format (MODEST_MSG_EDIT_WINDOW (window), file_format);
2001 modest_ui_actions_on_zoom_plus (GtkAction *action,
2002 ModestWindow *window)
2004 g_return_if_fail (MODEST_IS_WINDOW (window));
2006 modest_window_zoom_plus (MODEST_WINDOW (window));
2010 modest_ui_actions_on_zoom_minus (GtkAction *action,
2011 ModestWindow *window)
2013 g_return_if_fail (MODEST_IS_WINDOW (window));
2015 modest_window_zoom_minus (MODEST_WINDOW (window));
2019 modest_ui_actions_on_toggle_fullscreen (GtkToggleAction *toggle,
2020 ModestWindow *window)
2022 ModestWindowMgr *mgr;
2023 gboolean fullscreen, active;
2024 g_return_if_fail (MODEST_IS_WINDOW (window));
2026 mgr = modest_runtime_get_window_mgr ();
2028 active = (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle)))?1:0;
2029 fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
2031 if (active != fullscreen) {
2032 modest_window_mgr_set_fullscreen_mode (mgr, active);
2033 gtk_window_present (GTK_WINDOW (window));
2038 modest_ui_actions_on_change_fullscreen (GtkAction *action,
2039 ModestWindow *window)
2041 ModestWindowMgr *mgr;
2042 gboolean fullscreen;
2044 g_return_if_fail (MODEST_IS_WINDOW (window));
2046 mgr = modest_runtime_get_window_mgr ();
2047 fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
2048 modest_window_mgr_set_fullscreen_mode (mgr, !fullscreen);
2050 gtk_window_present (GTK_WINDOW (window));
2054 * Used by modest_ui_actions_on_details to call do_headers_action
2057 headers_action_show_details (TnyHeader *header,
2058 ModestWindow *window,
2065 dialog = modest_details_dialog_new_with_header (GTK_WINDOW (window), header);
2068 gtk_widget_show_all (dialog);
2069 gtk_dialog_run (GTK_DIALOG (dialog));
2071 gtk_widget_destroy (dialog);
2075 * Show the folder details in a ModestDetailsDialog widget
2078 show_folder_details (TnyFolder *folder,
2084 dialog = modest_details_dialog_new_with_folder (window, folder);
2087 gtk_widget_show_all (dialog);
2088 gtk_dialog_run (GTK_DIALOG (dialog));
2090 gtk_widget_destroy (dialog);
2094 * Show the header details in a ModestDetailsDialog widget
2097 modest_ui_actions_on_details (GtkAction *action,
2100 TnyList * headers_list;
2104 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
2107 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW (win));
2111 headers_list = get_selected_headers (win);
2115 iter = tny_list_create_iterator (headers_list);
2117 header = TNY_HEADER (tny_iterator_get_current (iter));
2118 headers_action_show_details (header, win, NULL);
2119 g_object_unref (header);
2121 g_object_unref (iter);
2123 } else if (MODEST_IS_MAIN_WINDOW (win)) {
2124 GtkWidget *folder_view, *header_view;
2126 /* Check which widget has the focus */
2127 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
2128 MODEST_WIDGET_TYPE_FOLDER_VIEW);
2129 if (gtk_widget_is_focus (folder_view)) {
2132 folder = (TnyFolder *) modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
2134 /* Show only when it's a folder */
2135 if (!folder || !TNY_IS_FOLDER (folder))
2138 show_folder_details (folder, GTK_WINDOW (win));
2141 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
2142 MODEST_WIDGET_TYPE_HEADER_VIEW);
2143 /* Show details of each header */
2144 do_headers_action (win, headers_action_show_details, header_view);
2150 modest_ui_actions_on_toggle_show_cc (GtkToggleAction *toggle,
2151 ModestMsgEditWindow *window)
2153 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2155 modest_msg_edit_window_show_cc (window, gtk_toggle_action_get_active (toggle));
2159 modest_ui_actions_on_toggle_show_bcc (GtkToggleAction *toggle,
2160 ModestMsgEditWindow *window)
2162 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2164 modest_msg_edit_window_show_bcc (window, gtk_toggle_action_get_active (toggle));
2168 modest_ui_actions_toggle_folders_view (GtkAction *action,
2169 ModestMainWindow *main_window)
2173 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2175 conf = modest_runtime_get_conf ();
2177 if (modest_main_window_get_style (main_window) == MODEST_MAIN_WINDOW_STYLE_SPLIT)
2178 modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SIMPLE);
2180 modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SPLIT);
2184 modest_ui_actions_on_toggle_toolbar (GtkToggleAction *toggle,
2185 ModestWindow *window)
2187 gboolean active, fullscreen = FALSE;
2188 ModestWindowMgr *mgr;
2190 active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle));
2192 /* Check if we want to toggle the toolbar vuew in fullscreen
2194 if (!strcmp (gtk_action_get_name (GTK_ACTION (toggle)),
2195 "ViewShowToolbarFullScreen")) {
2199 /* Toggle toolbar */
2200 mgr = modest_runtime_get_window_mgr ();
2201 modest_window_mgr_show_toolbars (mgr, active, fullscreen);
2205 modest_ui_actions_msg_edit_on_select_font (GtkAction *action,
2206 ModestMsgEditWindow *window)
2208 modest_msg_edit_window_select_font (window);
2212 modest_ui_actions_on_folder_display_name_changed (ModestFolderView *folder_view,
2213 const gchar *display_name,
2216 /* Do not change the application name if the widget has not
2217 the focus. This callback could be called even if the folder
2218 view has not the focus, because the handled signal could be
2219 emitted when the folder view is redrawn */
2220 if (gtk_widget_is_focus (GTK_WIDGET (folder_view))) {
2222 gtk_window_set_title (window, display_name);
2224 gtk_window_set_title (window, " ");
2229 modest_ui_actions_on_select_contacts (GtkAction *action, ModestMsgEditWindow *window)
2231 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2232 modest_msg_edit_window_select_contacts (window);
2236 modest_ui_actions_on_check_names (GtkAction *action, ModestMsgEditWindow *window)
2238 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2239 modest_msg_edit_window_check_names (window);
2244 create_move_to_dialog (ModestWindow *win,
2245 GtkWidget *folder_view,
2246 GtkWidget **tree_view)
2248 GtkWidget *dialog, *scroll;
2250 dialog = gtk_dialog_new_with_buttons (_("mcen_ti_moveto_folders_title"),
2252 GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR | GTK_DIALOG_DESTROY_WITH_PARENT,
2254 GTK_RESPONSE_ACCEPT,
2256 GTK_RESPONSE_REJECT,
2259 /* Create scrolled window */
2260 scroll = gtk_scrolled_window_new (NULL, NULL);
2261 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll),
2262 GTK_POLICY_AUTOMATIC,
2263 GTK_POLICY_AUTOMATIC);
2265 /* Create folder view */
2266 *tree_view = modest_folder_view_new (NULL);
2267 gtk_tree_view_set_model (GTK_TREE_VIEW (*tree_view),
2268 gtk_tree_view_get_model (GTK_TREE_VIEW (folder_view)));
2269 gtk_container_add (GTK_CONTAINER (scroll), *tree_view);
2271 /* Add scroll to dialog */
2272 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
2273 scroll, FALSE, FALSE, 0);
2275 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
2281 * Returns TRUE if at least one of the headers of the list belongs to
2282 * a message that has been fully retrieved.
2285 has_retrieved_msgs (TnyList *list)
2288 gboolean found = FALSE;
2290 iter = tny_list_create_iterator (list);
2291 while (tny_iterator_is_done (iter) && !found) {
2293 TnyHeaderFlags flags;
2295 header = TNY_HEADER (tny_iterator_get_current (iter));
2296 flags = tny_header_get_flags (header);
2297 if (!(flags & TNY_HEADER_FLAG_PARTIAL))
2301 tny_iterator_next (iter);
2303 g_object_unref (iter);
2309 * Shows a confirmation dialog to the user when we're moving messages
2310 * from a remote server to the local storage. Returns the dialog
2311 * response. If it's other kind of movement the it always returns
2315 msgs_move_to_confirmation (GtkWindow *win,
2316 TnyFolder *dest_folder,
2319 gint response = GTK_RESPONSE_OK;
2321 /* If the destination is a local folder */
2322 if (modest_tny_folder_is_local_folder (dest_folder)) {
2323 TnyFolder *src_folder;
2327 /* Get source folder */
2328 iter = tny_list_create_iterator (headers);
2329 header = TNY_HEADER (tny_iterator_get_current (iter));
2330 src_folder = tny_header_get_folder (header);
2331 g_object_unref (header);
2332 g_object_unref (iter);
2334 /* If the source is a remote folder */
2335 if (!modest_tny_folder_is_local_folder (src_folder)) {
2336 const gchar *message;
2338 if (tny_list_get_length (headers) == 1)
2339 if (has_retrieved_msgs (headers))
2340 message = _("mcen_nc_move_retrieve");
2342 message = _("mcen_nc_move_header");
2344 if (has_retrieved_msgs (headers))
2345 message = _("mcen_nc_move_retrieves");
2347 message = _("mcen_nc_move_headers");
2349 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
2350 (const gchar *) message);
2358 tranasfer_msgs_from_viewer_cb (const GObject *object, gpointer user_data)
2360 ModestMsgViewWindow *self = NULL;
2361 gboolean found = FALSE;
2363 g_return_if_fail (MODEST_IS_MSG_VIEW_WINDOW (object));
2364 self = MODEST_MSG_VIEW_WINDOW (object);
2366 found = modest_msg_view_window_select_first_message (self);
2367 g_return_if_fail (found);
2371 * UI handler for the "Move to" action when invoked from the
2375 modest_ui_actions_on_main_window_move_to (GtkAction *action,
2376 ModestMainWindow *win)
2378 GtkWidget *dialog, *folder_view, *tree_view = NULL;
2380 TnyFolderStore *folder_store;
2381 ModestMailOperation *mail_op = NULL;
2383 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win));
2385 /* Get the folder view */
2386 folder_view = modest_main_window_get_child_widget (win,
2387 MODEST_WIDGET_TYPE_FOLDER_VIEW);
2389 /* Create and run the dialog */
2390 dialog = create_move_to_dialog (MODEST_WINDOW (win), folder_view, &tree_view);
2391 result = gtk_dialog_run (GTK_DIALOG(dialog));
2392 g_object_ref (tree_view);
2394 /* We do this to save an indentation level ;-) */
2395 if (result != GTK_RESPONSE_ACCEPT)
2398 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (tree_view));
2400 if (TNY_IS_ACCOUNT (folder_store))
2403 /* Get folder or messages to transfer */
2404 if (gtk_widget_is_focus (folder_view)) {
2405 TnyFolderStore *src_folder;
2406 src_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
2408 if (TNY_IS_FOLDER (src_folder)) {
2409 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE, G_OBJECT(win));
2410 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
2413 modest_mail_operation_xfer_folder_async (mail_op,
2414 TNY_FOLDER (src_folder),
2417 g_object_unref (G_OBJECT (mail_op));
2421 g_object_unref (G_OBJECT (src_folder));
2423 GtkWidget *header_view;
2424 header_view = modest_main_window_get_child_widget (win,
2425 MODEST_WIDGET_TYPE_HEADER_VIEW);
2426 if (gtk_widget_is_focus (header_view)) {
2430 headers = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW (header_view));
2432 /* Ask for user confirmation */
2433 response = msgs_move_to_confirmation (GTK_WINDOW (win),
2434 TNY_FOLDER (folder_store),
2437 /* Transfer messages */
2438 if (response == GTK_RESPONSE_OK) {
2439 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE, G_OBJECT(win));
2440 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
2443 modest_mail_operation_xfer_msgs (mail_op,
2445 TNY_FOLDER (folder_store),
2449 g_object_unref (G_OBJECT (mail_op));
2451 g_object_unref (headers);
2454 g_object_unref (folder_store);
2457 gtk_widget_destroy (dialog);
2462 * UI handler for the "Move to" action when invoked from the
2463 * ModestMsgViewWindow
2466 modest_ui_actions_on_msg_view_window_move_to (GtkAction *action,
2467 ModestMsgViewWindow *win)
2469 GtkWidget *dialog, *folder_view, *tree_view = NULL;
2471 ModestMainWindow *main_window;
2475 /* Get the folder view */
2476 main_window = MODEST_MAIN_WINDOW (modest_window_mgr_get_main_window (modest_runtime_get_window_mgr ()));
2477 folder_view = modest_main_window_get_child_widget (main_window,
2478 MODEST_WIDGET_TYPE_FOLDER_VIEW);
2480 /* Create and run the dialog */
2481 dialog = create_move_to_dialog (MODEST_WINDOW (win), folder_view, &tree_view);
2482 result = gtk_dialog_run (GTK_DIALOG(dialog));
2483 g_object_ref (tree_view);
2485 if (result == GTK_RESPONSE_ACCEPT) {
2486 TnyFolderStore *folder_store;
2489 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (tree_view));
2491 /* Create header list */
2492 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
2493 headers = tny_simple_list_new ();
2494 tny_list_prepend (headers, G_OBJECT (header));
2495 g_object_unref (header);
2497 /* Ask user for confirmation. MSG-NOT404 */
2498 response = msgs_move_to_confirmation (GTK_WINDOW (win),
2499 TNY_FOLDER (folder_store),
2502 /* Transfer current msg */
2503 if (response == GTK_RESPONSE_OK) {
2504 ModestMailOperation *mail_op;
2506 /* Create mail op */
2507 mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_ID_RECEIVE, G_OBJECT(win));
2508 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
2511 /* Transfer messages */
2512 modest_mail_operation_xfer_msgs (mail_op,
2514 TNY_FOLDER (folder_store),
2516 tranasfer_msgs_from_viewer_cb,
2518 g_object_unref (G_OBJECT (mail_op));
2520 g_object_unref (headers);
2521 g_object_unref (folder_store);
2523 gtk_widget_destroy (dialog);
2527 modest_ui_actions_on_move_to (GtkAction *action,
2530 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win) ||
2531 MODEST_IS_MSG_VIEW_WINDOW (win));
2533 if (MODEST_IS_MAIN_WINDOW (win))
2534 modest_ui_actions_on_main_window_move_to (action,
2535 MODEST_MAIN_WINDOW (win));
2537 modest_ui_actions_on_msg_view_window_move_to (action,
2538 MODEST_MSG_VIEW_WINDOW (win));
2542 * Calls #HeadersFunc for each header already selected in the main
2543 * window or the message currently being shown in the msg view window
2546 do_headers_action (ModestWindow *win,
2550 TnyList *headers_list;
2554 headers_list = get_selected_headers (win);
2558 /* Call the function for each header */
2559 iter = tny_list_create_iterator (headers_list);
2560 while (!tny_iterator_is_done (iter)) {
2563 header = TNY_HEADER (tny_iterator_get_current (iter));
2564 func (header, win, user_data);
2565 g_object_unref (header);
2566 tny_iterator_next (iter);
2568 g_object_unref (iter);
2572 modest_ui_actions_view_attachment (GtkAction *action,
2573 ModestWindow *window)
2575 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
2576 modest_msg_view_window_view_attachment (MODEST_MSG_VIEW_WINDOW (window), NULL);
2578 /* not supported window for this action */
2579 g_return_if_reached ();
2584 modest_ui_actions_save_attachments (GtkAction *action,
2585 ModestWindow *window)
2587 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
2588 modest_msg_view_window_save_attachments (MODEST_MSG_VIEW_WINDOW (window), NULL);
2590 /* not supported window for this action */
2591 g_return_if_reached ();
2596 modest_ui_actions_remove_attachments (GtkAction *action,
2597 ModestWindow *window)
2599 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
2600 modest_msg_view_window_remove_attachments (MODEST_MSG_VIEW_WINDOW (window), NULL);
2602 /* not supported window for this action */
2603 g_return_if_reached ();
2608 modest_ui_actions_on_settings (GtkAction *action,
2613 dialog = modest_platform_get_global_settings_dialog ();
2614 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (win));
2615 gtk_widget_show (dialog);
2617 gtk_dialog_run (GTK_DIALOG (dialog));
2619 gtk_widget_destroy (dialog);