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-msg.h>
38 #include <modest-tny-account.h>
39 #include <modest-address-book.h>
41 #include "modest-ui-actions.h"
43 #include "modest-tny-platform-factory.h"
45 #include <widgets/modest-main-window.h>
46 #include <widgets/modest-msg-view-window.h>
47 #include <widgets/modest-account-view-window.h>
49 #include "modest-account-mgr-helpers.h"
50 #include "modest-mail-operation.h"
51 #include <modest-widget-memory.h>
52 #include <tny-error.h>
53 #include <tny-simple-list.h>
54 #include <tny-msg-view.h>
55 #include <tny-device.h>
58 typedef struct _GetMsgAsyncHelper {
65 typedef enum _ReplyForwardAction {
71 typedef struct _ReplyForwardHelper {
72 guint reply_forward_type;
73 ReplyForwardAction action;
78 static void reply_forward_func (gpointer data, gpointer user_data);
79 static void read_msg_func (gpointer data, gpointer user_data);
80 static void get_msg_cb (TnyFolder *folder, TnyMsg *msg, GError **err,
82 static void reply_forward (ReplyForwardAction action, ModestWindow *win);
83 static gchar* ask_for_folder_name (GtkWindow *parent_window, const gchar *title);
87 modest_ui_actions_on_about (GtkAction *action, ModestWindow *win)
90 const gchar *authors[] = {
91 "Dirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>",
94 about = gtk_about_dialog_new ();
95 gtk_about_dialog_set_name (GTK_ABOUT_DIALOG(about), PACKAGE_NAME);
96 gtk_about_dialog_set_version (GTK_ABOUT_DIALOG(about),PACKAGE_VERSION);
97 gtk_about_dialog_set_copyright (GTK_ABOUT_DIALOG(about),
98 _("Copyright (c) 2006, Nokia Corporation\n"
99 "All rights reserved."));
100 gtk_about_dialog_set_comments (GTK_ABOUT_DIALOG(about),
101 _("a modest e-mail client\n\n"
102 "design and implementation: Dirk-Jan C. Binnema\n"
103 "contributions from the fine people at KernelConcepts and Igalia\n"
104 "uses the tinymail email framework written by Philip van Hoof"));
105 gtk_about_dialog_set_authors (GTK_ABOUT_DIALOG(about), authors);
106 gtk_about_dialog_set_website (GTK_ABOUT_DIALOG(about), "http://modest.garage.maemo.org");
108 gtk_dialog_run (GTK_DIALOG (about));
109 gtk_widget_destroy(about);
114 get_selected_headers (ModestWindow *win)
116 if (MODEST_IS_MAIN_WINDOW(win)) {
117 GtkWidget *header_view;
119 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
120 MODEST_WIDGET_TYPE_HEADER_VIEW);
121 return modest_header_view_get_selected_headers (MODEST_HEADER_VIEW(header_view));
123 } else if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
124 /* for MsgViewWindows, we simply return a list with one element */
127 TnyList *list = NULL;
129 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW(win));
131 header = tny_msg_get_header (msg);
132 list = tny_simple_list_new ();
133 tny_list_prepend (list, G_OBJECT(header));
134 g_object_unref (G_OBJECT(header));
143 modest_ui_actions_on_delete (GtkAction *action, ModestWindow *win)
145 TnyList *header_list;
148 g_return_if_fail (MODEST_IS_WINDOW(win));
150 header_list = get_selected_headers (win);
153 iter = tny_list_create_iterator (header_list);
156 ModestMailOperation *mail_op;
158 header = TNY_HEADER (tny_iterator_get_current (iter));
159 /* TODO: thick grain mail operation involving
160 a list of objects. Composite pattern ??? */
161 /* TODO: add confirmation dialog */
162 mail_op = modest_mail_operation_new ();
163 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
166 /* Always delete. TODO: Move to trash still not supported */
167 modest_mail_operation_remove_msg (mail_op, header, FALSE);
170 g_object_unref (G_OBJECT (mail_op));
171 g_object_unref (G_OBJECT (header));
173 tny_iterator_next (iter);
175 } while (!tny_iterator_is_done (iter));
178 g_object_unref (G_OBJECT (iter));
184 modest_ui_actions_on_quit (GtkAction *action, ModestWindow *win)
186 /* FIXME: save size of main window */
187 /* save_sizes (main_window); */
188 gtk_widget_destroy (GTK_WIDGET (win));
192 modest_ui_actions_on_add_to_contacts (GtkAction *action, ModestWindow *win)
194 GtkClipboard *clipboard = NULL;
195 gchar *selection = NULL;
197 clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
198 selection = gtk_clipboard_wait_for_text (clipboard);
200 modest_address_book_add_address (selection);
205 modest_ui_actions_on_accounts (GtkAction *action, ModestWindow *win)
207 /* GtkDialog *account_win; */
208 /* account_win = GTK_DIALOG(modest_account_view_window_new ()); */
211 /* gtk_dialog_run (account_win); */
212 //gtk_widget_destroy (GTK_WIDGET(account_win));
213 GtkWidget *dialog, *label;
215 /* Create the widgets */
217 dialog = gtk_dialog_new_with_buttons ("Message",
219 GTK_DIALOG_DESTROY_WITH_PARENT,
223 label = gtk_label_new ("Hello World!");
225 /* Ensure that the dialog box is destroyed when the user responds. */
227 g_signal_connect_swapped (dialog, "response",
228 G_CALLBACK (gtk_widget_destroy),
231 /* Add the label, and show everything we've added to the dialog. */
233 gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox),
235 gtk_widget_show_all (dialog);
239 modest_ui_actions_on_new_msg (GtkAction *action, ModestWindow *win)
241 ModestWindow *msg_win;
243 TnyFolder *folder = NULL;
244 gchar *account_name = NULL;
245 gchar *from_str = NULL;
249 account_name = g_strdup(modest_window_get_active_account (win));
251 account_name = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
253 account = modest_tny_account_store_get_tny_account_by_account (modest_runtime_get_account_store(),
255 TNY_ACCOUNT_TYPE_STORE);
257 g_printerr ("modest: failed to get tnyaccount for '%s'\n", account_name);
261 from_str = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(), account_name);
263 msg = modest_tny_msg_new ("", from_str, "", "", "", "", NULL);
265 g_printerr ("modest: failed to create new msg\n");
269 folder = modest_tny_account_get_special_folder (account, TNY_FOLDER_TYPE_DRAFTS);
271 g_printerr ("modest: failed to find Drafts folder\n");
275 tny_folder_add_msg (folder, msg, &err);
277 g_printerr ("modest: error adding msg to Drafts folder: %s",
283 msg_win = modest_msg_edit_window_new (msg, account_name);
285 gtk_window_set_transient_for (GTK_WINDOW (msg_win),
287 gtk_widget_show_all (GTK_WIDGET (msg_win));
290 g_free (account_name);
293 g_object_unref (G_OBJECT(account));
295 g_object_unref (G_OBJECT(msg));
297 g_object_unref (G_OBJECT(folder));
302 modest_ui_actions_on_open (GtkAction *action, ModestWindow *win)
304 modest_runtime_not_implemented (GTK_WINDOW(win)); /* FIXME */
310 reply_forward_func (gpointer data, gpointer user_data)
312 TnyMsg *msg, *new_msg;
313 GetMsgAsyncHelper *helper;
314 ReplyForwardHelper *rf_helper;
315 ModestWindow *msg_win;
316 ModestEditType edit_type;
319 TnyFolder *folder = NULL;
320 TnyAccount *account = NULL;
322 msg = TNY_MSG (data);
323 helper = (GetMsgAsyncHelper *) user_data;
324 rf_helper = (ReplyForwardHelper *) helper->user_data;
326 from = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(),
327 rf_helper->account_name);
328 /* Create reply mail */
329 switch (rf_helper->action) {
332 modest_tny_msg_create_reply_msg (msg, from,
333 rf_helper->reply_forward_type,
334 MODEST_TNY_MSG_REPLY_MODE_SENDER);
336 case ACTION_REPLY_TO_ALL:
338 modest_tny_msg_create_reply_msg (msg, from, rf_helper->reply_forward_type,
339 MODEST_TNY_MSG_REPLY_MODE_ALL);
340 edit_type = MODEST_EDIT_TYPE_REPLY;
344 modest_tny_msg_create_forward_msg (msg, from, rf_helper->reply_forward_type);
345 edit_type = MODEST_EDIT_TYPE_FORWARD;
348 g_return_if_reached ();
353 g_printerr ("modest: failed to create message\n");
357 account = modest_tny_account_store_get_tny_account_by_account (modest_runtime_get_account_store(),
358 rf_helper->account_name,
359 TNY_ACCOUNT_TYPE_STORE);
361 g_printerr ("modest: failed to get tnyaccount for '%s'\n", rf_helper->account_name);
365 folder = modest_tny_account_get_special_folder (account, TNY_FOLDER_TYPE_DRAFTS);
367 g_printerr ("modest: failed to find Drafts folder\n");
371 tny_folder_add_msg (folder, msg, &err);
373 g_printerr ("modest: error adding msg to Drafts folder: %s",
379 /* Show edit window */
380 msg_win = modest_msg_edit_window_new (new_msg, rf_helper->account_name);
381 gtk_widget_show_all (GTK_WIDGET (msg_win));
385 g_object_unref (G_OBJECT (new_msg));
387 g_object_unref (G_OBJECT (folder));
389 g_object_unref (G_OBJECT (account));
391 g_free (rf_helper->account_name);
392 g_slice_free (ReplyForwardHelper, rf_helper);
395 * Common code for the reply and forward actions
398 reply_forward (ReplyForwardAction action, ModestWindow *win)
400 TnyList *header_list;
401 guint reply_forward_type;
404 GetMsgAsyncHelper *helper;
405 ReplyForwardHelper *rf_helper;
407 g_return_if_fail (MODEST_IS_WINDOW(win));
409 header_list = get_selected_headers (win);
413 reply_forward_type = modest_conf_get_int (modest_runtime_get_conf (),
414 (action == ACTION_FORWARD) ? MODEST_CONF_FORWARD_TYPE : MODEST_CONF_REPLY_TYPE,
416 /* We assume that we can only select messages of the
417 same folder and that we reply all of them from the
418 same account. In fact the interface currently only
419 allows single selection */
422 rf_helper = g_slice_new0 (ReplyForwardHelper);
423 rf_helper->reply_forward_type = reply_forward_type;
424 rf_helper->action = action;
426 rf_helper->account_name = g_strdup (modest_window_get_active_account (win));
427 if (!rf_helper->account_name)
428 rf_helper->account_name =
429 modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
431 helper = g_slice_new0 (GetMsgAsyncHelper);
432 helper->window = win;
433 helper->func = reply_forward_func;
434 helper->iter = tny_list_create_iterator (header_list);
435 helper->user_data = rf_helper;
437 if (MODEST_IS_MSG_VIEW_WINDOW(win)) {
439 msg = modest_msg_view_window_get_message(MODEST_MSG_VIEW_WINDOW(win));
441 g_printerr ("modest: no message found\n");
444 reply_forward_func (msg, helper);
446 header = TNY_HEADER (tny_iterator_get_current (helper->iter));
447 folder = tny_header_get_folder (header);
449 /* The callback will call it per each header */
450 tny_folder_get_msg_async (folder, header, get_msg_cb, helper);
451 g_object_unref (G_OBJECT (folder));
453 g_printerr ("modest: no folder for header\n");
456 g_object_unref (G_OBJECT (header));
462 modest_ui_actions_on_reply (GtkAction *action, ModestWindow *win)
464 g_return_if_fail (MODEST_IS_WINDOW(win));
466 reply_forward (ACTION_REPLY, win);
470 modest_ui_actions_on_forward (GtkAction *action, ModestWindow *win)
472 g_return_if_fail (MODEST_IS_WINDOW(win));
474 reply_forward (ACTION_FORWARD, win);
478 modest_ui_actions_on_reply_all (GtkAction *action, ModestWindow *win)
480 g_return_if_fail (MODEST_IS_WINDOW(win));
482 reply_forward (ACTION_REPLY_TO_ALL, win);
486 modest_ui_actions_on_next (GtkAction *action,
487 ModestMainWindow *main_window)
489 GtkWidget *header_view;
490 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
492 header_view = modest_main_window_get_child_widget (main_window,
493 MODEST_WIDGET_TYPE_HEADER_VIEW);
497 modest_header_view_select_next (MODEST_HEADER_VIEW(header_view));
501 modest_ui_actions_on_prev (GtkAction *action,
502 ModestMainWindow *main_window)
504 GtkWidget *header_view;
505 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
507 header_view = modest_main_window_get_child_widget (main_window,
508 MODEST_WIDGET_TYPE_HEADER_VIEW);
512 modest_header_view_select_prev (MODEST_HEADER_VIEW(header_view));
517 modest_ui_actions_on_send_receive (GtkAction *action, ModestWindow *win)
520 TnyAccount *tny_account;
521 ModestTnySendQueue *send_queue;
522 ModestMailOperation *mail_op;
525 g_strdup(modest_window_get_active_account(MODEST_WINDOW(win)));
527 account_name = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
529 g_printerr ("modest: cannot get account\n");
534 modest_tny_account_store_get_tny_account_by_account (modest_runtime_get_account_store(),
536 TNY_ACCOUNT_TYPE_TRANSPORT);
538 g_printerr ("modest: cannot get tny transport account for %s\n", account_name);
541 send_queue = modest_tny_send_queue_new (TNY_CAMEL_TRANSPORT_ACCOUNT(tny_account));
543 g_object_unref (G_OBJECT(tny_account));
544 g_printerr ("modest: cannot get send queue for %s\n", account_name);
547 //modest_tny_send_queue_flush (send_queue);
549 g_object_unref (G_OBJECT(send_queue));
550 g_object_unref (G_OBJECT(tny_account));
553 modest_tny_account_store_get_tny_account_by_account (modest_runtime_get_account_store(),
555 TNY_ACCOUNT_TYPE_STORE);
557 g_printerr ("modest: cannot get tny store account for %s\n", account_name);
561 /* Create the mail operation */
562 mail_op = modest_mail_operation_new ();
563 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
564 modest_mail_operation_update_account (mail_op, TNY_STORE_ACCOUNT(tny_account));
567 g_object_unref (G_OBJECT (tny_account));
568 g_object_unref (G_OBJECT (mail_op));
574 modest_ui_actions_toggle_view (GtkAction *action, ModestMainWindow *main_window)
577 GtkWidget *header_view;
579 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
581 header_view = modest_main_window_get_child_widget (main_window,
582 MODEST_WIDGET_TYPE_HEADER_VIEW);
586 conf = modest_runtime_get_conf ();
588 /* what is saved/restored is depending on the style; thus; we save with
589 * old style, then update the style, and restore for this new style
591 modest_widget_memory_save (conf, G_OBJECT(header_view), "header-view");
593 if (modest_header_view_get_style
594 (MODEST_HEADER_VIEW(header_view)) == MODEST_HEADER_VIEW_STYLE_DETAILS)
595 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
596 MODEST_HEADER_VIEW_STYLE_TWOLINES);
598 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
599 MODEST_HEADER_VIEW_STYLE_DETAILS);
601 modest_widget_memory_restore (conf, G_OBJECT(header_view),
608 * Marks a message as read and passes it to the msg preview widget
611 read_msg_func (gpointer data, gpointer user_data)
615 GetMsgAsyncHelper *helper;
616 TnyHeaderFlags header_flags;
617 GtkWidget *msg_preview;
619 msg = TNY_MSG (data);
620 helper = (GetMsgAsyncHelper *) user_data;
622 msg_preview = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (helper->window),
623 MODEST_WIDGET_TYPE_MSG_PREVIEW);
627 header = TNY_HEADER (tny_iterator_get_current (helper->iter));
628 header_flags = tny_header_get_flags (header);
629 tny_header_set_flags (header, header_flags | TNY_HEADER_FLAG_SEEN);
630 g_object_unref (G_OBJECT (header));
632 /* Set message on msg view */
633 modest_msg_view_set_message (MODEST_MSG_VIEW(msg_preview), msg);
637 * This function is a generic handler for the tny_folder_get_msg_async
638 * call. It expects as user_data a #GetMsgAsyncHelper. This helper
639 * contains a user provided function that is called inside this
640 * method. This will allow us to use this callback in many different
641 * places. This callback performs the common actions for the
642 * get_msg_async call, more specific actions will be done by the user
646 get_msg_cb (TnyFolder *folder, TnyMsg *msg, GError **err, gpointer user_data)
648 GetMsgAsyncHelper *helper;
650 helper = (GetMsgAsyncHelper *) user_data;
652 if ((*err && ((*err)->code == TNY_FOLDER_ERROR_GET_MSG)) || !msg) {
653 modest_ui_actions_on_item_not_found (NULL,
654 MODEST_ITEM_TYPE_MESSAGE,
659 /* Call user function */
660 helper->func (msg, user_data);
662 /* Process next element (if exists) */
663 tny_iterator_next (helper->iter);
664 if (tny_iterator_is_done (helper->iter)) {
666 headers = tny_iterator_get_list (helper->iter);
668 g_object_unref (G_OBJECT (headers));
669 g_object_unref (G_OBJECT (helper->iter));
670 g_slice_free (GetMsgAsyncHelper, helper);
673 header = TNY_HEADER (tny_iterator_get_current (helper->iter));
674 tny_folder_get_msg_async (folder, header,
676 g_object_unref (G_OBJECT(header));
681 modest_ui_actions_on_header_selected (ModestHeaderView *folder_view,
683 ModestMainWindow *main_window)
685 GtkWidget *msg_preview;
687 GetMsgAsyncHelper *helper;
690 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
692 msg_preview = modest_main_window_get_child_widget(main_window,
693 MODEST_WIDGET_TYPE_MSG_PREVIEW);
697 /* when there's no header, clear the msgview */
699 modest_msg_view_set_message (MODEST_MSG_VIEW(msg_preview), NULL);
703 folder = tny_header_get_folder (TNY_HEADER(header));
706 list = tny_simple_list_new ();
707 tny_list_prepend (list, G_OBJECT (header));
709 /* Fill helper data */
710 helper = g_slice_new0 (GetMsgAsyncHelper);
711 helper->window = MODEST_WINDOW (main_window);
712 helper->iter = tny_list_create_iterator (list);
713 helper->func = read_msg_func;
715 tny_folder_get_msg_async (TNY_FOLDER(folder),
720 g_object_unref (G_OBJECT (folder));
726 modest_ui_actions_on_header_activated (ModestHeaderView *folder_view, TnyHeader *header,
727 ModestMainWindow *main_window)
730 TnyFolder *folder = NULL;
732 gchar *account = NULL;
734 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
739 folder = tny_header_get_folder (header);
741 g_printerr ("modest: cannot get folder for header\n");
745 /* FIXME: make async?; check error */
746 msg = tny_folder_get_msg (folder, header, NULL);
748 g_printerr ("modest: cannot get msg for header\n");
752 account = g_strdup(modest_window_get_active_account(MODEST_WINDOW(main_window)));
754 account = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
756 win = modest_msg_view_window_new (msg, account);
757 gtk_window_set_transient_for (GTK_WINDOW (win),
758 GTK_WINDOW (main_window));
760 gtk_widget_show_all (GTK_WIDGET(win));
766 g_object_unref (G_OBJECT (folder));
768 g_object_unref (G_OBJECT (msg));
772 modest_ui_actions_on_folder_selection_changed (ModestFolderView *folder_view,
775 ModestMainWindow *main_window)
779 GtkWidget *header_view;
781 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
783 header_view = modest_main_window_get_child_widget(main_window,
784 MODEST_WIDGET_TYPE_HEADER_VIEW);
788 conf = modest_runtime_get_conf ();
790 if (!selected) { /* the folder was unselected; save it's settings */
791 modest_widget_memory_save (conf, G_OBJECT (header_view), "header-view");
792 gtk_window_set_title (GTK_WINDOW(main_window), "Modest");
793 modest_header_view_set_folder (MODEST_HEADER_VIEW(header_view), NULL);
794 } else { /* the folder was selected */
795 if (folder) { /* folder may be NULL */
799 num = tny_folder_get_all_count (folder);
800 unread = tny_folder_get_unread_count (folder);
802 title = g_strdup_printf ("Modest: %s",
803 tny_folder_get_name (folder));
805 gtk_window_set_title (GTK_WINDOW(main_window), title);
808 txt = g_strdup_printf (_("%d %s, %d unread"),
809 num, num==1 ? _("item") : _("items"), unread);
810 //gtk_label_set_label (GTK_LABEL(folder_info_label), txt);
813 modest_header_view_set_folder (MODEST_HEADER_VIEW(header_view), folder);
814 modest_widget_memory_restore (conf, G_OBJECT(header_view),
820 modest_ui_actions_on_item_not_found (ModestHeaderView *header_view,ModestItemType type,
827 item = (type == MODEST_ITEM_TYPE_FOLDER) ? "folder" : "message";
829 if (g_main_depth > 0)
830 gdk_threads_enter ();
831 online = tny_device_is_online (modest_runtime_get_device());
834 /* already online -- the item is simply not there... */
835 dialog = gtk_message_dialog_new (GTK_WINDOW (win),
839 _("The %s you selected cannot be found"),
841 gtk_dialog_run (GTK_DIALOG(dialog));
843 dialog = gtk_dialog_new_with_buttons (_("Connection requested"),
851 txt = g_strdup_printf (_("This %s is not available in offline mode.\n"
852 "Do you want to get online?"), item);
853 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
854 gtk_label_new (txt), FALSE, FALSE, 0);
855 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
858 gtk_window_set_default_size (GTK_WINDOW(dialog), 300, 300);
859 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
860 // tny_device_force_online (modest_runtime_get_device());
863 gtk_widget_destroy (dialog);
864 if (g_main_depth > 0)
865 gdk_threads_leave ();
869 modest_ui_actions_on_msg_link_hover (ModestMsgView *msgview, const gchar* link,
872 g_message (__FUNCTION__);
877 modest_ui_actions_on_msg_link_clicked (ModestMsgView *msgview, const gchar* link,
880 g_message (__FUNCTION__);
884 modest_ui_actions_on_msg_attachment_clicked (ModestMsgView *msgview, TnyMimePart *mime_part,
887 g_message (__FUNCTION__);
892 modest_ui_actions_on_msg_recpt_activated (ModestMsgView *msgview,
893 const gchar *address,
896 g_message ("%s %s", __FUNCTION__, address);
900 modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
902 TnyTransportAccount *transport_account;
903 ModestMailOperation *mail_operation;
905 gchar *account_name, *from;
906 ModestAccountMgr *account_mgr;
908 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window));
910 data = modest_msg_edit_window_get_msg_data (edit_window);
912 /* FIXME: Code added just for testing. The final version will
913 use the send queue provided by tinymail and some
915 account_mgr = modest_runtime_get_account_mgr();
916 account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
918 account_name = modest_account_mgr_get_default_account (account_mgr);
920 g_printerr ("modest: no account found\n");
921 modest_msg_edit_window_free_msg_data (edit_window, data);
925 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_tny_account_by_account
926 (modest_runtime_get_account_store(),
928 TNY_ACCOUNT_TYPE_TRANSPORT));
929 if (!transport_account) {
930 g_printerr ("modest: no transport account found for '%s'\n", account_name);
931 g_free (account_name);
932 modest_msg_edit_window_free_msg_data (edit_window, data);
935 from = modest_account_mgr_get_from_string (account_mgr, account_name);
937 /* Create the mail operation */
938 mail_operation = modest_mail_operation_new ();
939 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
941 modest_mail_operation_send_new_mail (mail_operation,
953 g_free (account_name);
954 g_object_unref (G_OBJECT (transport_account));
955 g_object_unref (G_OBJECT (mail_operation));
957 modest_msg_edit_window_free_msg_data (edit_window, data);
959 /* Save settings and close the window */
960 gtk_widget_destroy (GTK_WIDGET (edit_window));
964 modest_ui_actions_on_toggle_bold (GtkToggleAction *action,
965 ModestMsgEditWindow *window)
967 ModestMsgEditFormatState *format_state = NULL;
969 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
970 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
972 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
975 format_state = modest_msg_edit_window_get_format_state (window);
976 g_return_if_fail (format_state != NULL);
978 format_state->bold = gtk_toggle_action_get_active (action);
979 modest_msg_edit_window_set_format_state (window, format_state);
980 g_free (format_state);
985 modest_ui_actions_on_toggle_italics (GtkToggleAction *action,
986 ModestMsgEditWindow *window)
988 ModestMsgEditFormatState *format_state = NULL;
990 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
991 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
993 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
996 format_state = modest_msg_edit_window_get_format_state (window);
997 g_return_if_fail (format_state != NULL);
999 format_state->italics = gtk_toggle_action_get_active (action);
1000 modest_msg_edit_window_set_format_state (window, format_state);
1001 g_free (format_state);
1006 modest_ui_actions_on_toggle_bullets (GtkToggleAction *action,
1007 ModestMsgEditWindow *window)
1009 ModestMsgEditFormatState *format_state = NULL;
1011 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1012 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
1014 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
1017 format_state = modest_msg_edit_window_get_format_state (window);
1018 g_return_if_fail (format_state != NULL);
1020 format_state->bullet = gtk_toggle_action_get_active (action);
1021 modest_msg_edit_window_set_format_state (window, format_state);
1022 g_free (format_state);
1027 modest_ui_actions_on_change_justify (GtkRadioAction *action,
1028 GtkRadioAction *selected,
1029 ModestMsgEditWindow *window)
1031 ModestMsgEditFormatState *format_state = NULL;
1032 GtkJustification value;
1034 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1036 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
1039 value = gtk_radio_action_get_current_value (selected);
1041 format_state = modest_msg_edit_window_get_format_state (window);
1042 g_return_if_fail (format_state != NULL);
1044 format_state->justification = value;
1045 modest_msg_edit_window_set_format_state (window, format_state);
1046 g_free (format_state);
1050 modest_ui_actions_on_select_editor_color (GtkAction *action,
1051 ModestMsgEditWindow *window)
1053 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1054 g_return_if_fail (GTK_IS_ACTION (action));
1056 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
1059 modest_msg_edit_window_select_color (window);
1063 modest_ui_actions_on_select_editor_background_color (GtkAction *action,
1064 ModestMsgEditWindow *window)
1066 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1067 g_return_if_fail (GTK_IS_ACTION (action));
1069 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
1072 modest_msg_edit_window_select_background_color (window);
1076 modest_ui_actions_on_insert_image (GtkAction *action,
1077 ModestMsgEditWindow *window)
1079 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
1080 g_return_if_fail (GTK_IS_ACTION (action));
1082 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
1085 modest_msg_edit_window_insert_image (window);
1089 * Shows a dialog with an entry that asks for some text. The returned
1090 * value must be freed by the caller. The dialog window title will be
1094 ask_for_folder_name (GtkWindow *parent_window,
1097 GtkWidget *dialog, *entry;
1098 gchar *folder_name = NULL;
1100 /* Ask for folder name */
1101 dialog = gtk_dialog_new_with_buttons (_("New Folder Name"),
1105 GTK_RESPONSE_REJECT,
1107 GTK_RESPONSE_ACCEPT,
1109 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
1110 gtk_label_new(title),
1113 entry = gtk_entry_new_with_max_length (40);
1114 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
1118 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
1120 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
1121 folder_name = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry)));
1123 gtk_widget_destroy (dialog);
1129 modest_ui_actions_on_new_folder (GtkAction *action, ModestMainWindow *main_window)
1131 TnyFolder *parent_folder;
1132 GtkWidget *folder_view;
1134 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1136 folder_view = modest_main_window_get_child_widget (main_window,
1137 MODEST_WIDGET_TYPE_FOLDER_VIEW);
1141 parent_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
1143 if (parent_folder) {
1146 folder_name = ask_for_folder_name (GTK_WINDOW (main_window),
1147 _("Please enter a name for the new folder"));
1149 if (folder_name != NULL && strlen (folder_name) > 0) {
1150 TnyFolder *new_folder;
1151 ModestMailOperation *mail_op;
1153 mail_op = modest_mail_operation_new ();
1154 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
1157 new_folder = modest_mail_operation_create_folder (mail_op,
1158 TNY_FOLDER_STORE (parent_folder),
1159 (const gchar *) folder_name);
1161 g_object_unref (new_folder);
1162 g_object_unref (mail_op);
1163 g_free (folder_name);
1165 g_object_unref (parent_folder);
1170 modest_ui_actions_on_rename_folder (GtkAction *action,
1171 ModestMainWindow *main_window)
1174 GtkWidget *folder_view;
1176 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1178 folder_view = modest_main_window_get_child_widget (main_window,
1179 MODEST_WIDGET_TYPE_FOLDER_VIEW);
1183 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
1187 folder_name = ask_for_folder_name (GTK_WINDOW (main_window),
1188 _("Please enter a new name for the folder"));
1190 if (folder_name != NULL && strlen (folder_name) > 0) {
1191 ModestMailOperation *mail_op;
1193 mail_op = modest_mail_operation_new ();
1194 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
1197 modest_mail_operation_rename_folder (mail_op,
1199 (const gchar *) folder_name);
1201 g_object_unref (mail_op);
1202 g_free (folder_name);
1204 g_object_unref (folder);
1209 delete_folder (ModestMainWindow *main_window, gboolean move_to_trash)
1212 ModestMailOperation *mail_op;
1213 GtkWidget *folder_view;
1215 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1217 folder_view = modest_main_window_get_child_widget (main_window,
1218 MODEST_WIDGET_TYPE_FOLDER_VIEW);
1222 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
1224 mail_op = modest_mail_operation_new ();
1225 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
1227 modest_mail_operation_remove_folder (mail_op, folder, move_to_trash);
1229 g_object_unref (G_OBJECT (mail_op));
1230 g_object_unref (G_OBJECT (folder));
1234 modest_ui_actions_on_delete_folder (GtkAction *action,
1235 ModestMainWindow *main_window)
1237 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1239 delete_folder (main_window, FALSE);
1243 modest_ui_actions_on_move_folder_to_trash_folder (GtkAction *action, ModestMainWindow *main_window)
1245 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1247 delete_folder (main_window, TRUE);
1251 modest_ui_actions_on_password_requested (TnyAccountStore *account_store,
1252 const gchar* account_name,
1256 ModestMainWindow *main_window)
1259 GtkWidget *dialog, *entry, *remember_pass_check;
1261 dialog = gtk_dialog_new_with_buttons (_("Password requested"),
1265 GTK_RESPONSE_REJECT,
1267 GTK_RESPONSE_ACCEPT,
1269 gtk_window_set_transient_for (GTK_WINDOW(dialog), GTK_WINDOW(main_window));
1271 txt = g_strdup_printf (_("Please enter your password for %s"), account_name);
1272 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), gtk_label_new(txt),
1276 entry = gtk_entry_new_with_max_length (40);
1277 gtk_entry_set_visibility (GTK_ENTRY(entry), FALSE);
1278 gtk_entry_set_invisible_char (GTK_ENTRY(entry), 0x2022); /* bullet unichar */
1280 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry,
1283 remember_pass_check = gtk_check_button_new_with_label (_("Remember password"));
1284 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), remember_pass_check,
1287 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
1289 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
1290 *password = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry)));
1297 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (remember_pass_check)))
1302 gtk_widget_destroy (dialog);