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-ui-actions.h"
40 #include "modest-tny-platform-factory.h"
42 #include <widgets/modest-main-window.h>
43 #include <widgets/modest-msg-view-window.h>
44 #include <widgets/modest-account-view-window.h>
46 #include "modest-account-mgr-helpers.h"
47 #include "modest-mail-operation.h"
48 #include <modest-widget-memory.h>
49 #include <tny-error.h>
50 #include <tny-simple-list.h>
51 #include <tny-msg-view.h>
52 #include <tny-device.h>
55 typedef struct _GetMsgAsyncHelper {
56 ModestMainWindow *main_window;
62 typedef enum _ReplyForwardAction {
68 typedef struct _ReplyForwardHelper {
69 guint reply_forward_type;
70 ReplyForwardAction action;
75 static void reply_forward_func (gpointer data, gpointer user_data);
76 static void read_msg_func (gpointer data, gpointer user_data);
77 static void get_msg_cb (TnyFolder *folder, TnyMsg *msg, GError **err,
79 static void reply_forward (GtkWidget *widget, ReplyForwardAction action,
81 static gchar* ask_for_folder_name (GtkWindow *parent_window, const gchar *title);
85 modest_ui_actions_on_about (GtkWidget *widget, ModestWindow *win)
88 const gchar *authors[] = {
89 "Dirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>",
92 about = gtk_about_dialog_new ();
93 gtk_about_dialog_set_name (GTK_ABOUT_DIALOG(about), PACKAGE_NAME);
94 gtk_about_dialog_set_version (GTK_ABOUT_DIALOG(about),PACKAGE_VERSION);
95 gtk_about_dialog_set_copyright (GTK_ABOUT_DIALOG(about),
96 _("Copyright (c) 2006, Nokia Corporation\n"
97 "All rights reserved."));
98 gtk_about_dialog_set_comments (GTK_ABOUT_DIALOG(about),
99 _("a modest e-mail client\n\n"
100 "design and implementation: Dirk-Jan C. Binnema\n"
101 "contributions from the fine people at KernelConcepts and Igalia\n"
102 "uses the tinymail email framework written by Philip van Hoof"));
103 gtk_about_dialog_set_authors (GTK_ABOUT_DIALOG(about), authors);
104 gtk_about_dialog_set_website (GTK_ABOUT_DIALOG(about), "http://modest.garage.maemo.org");
106 gtk_dialog_run (GTK_DIALOG (about));
107 gtk_widget_destroy(about);
112 get_selected_headers (ModestWindow *win)
114 if (MODEST_IS_MAIN_WINDOW(win)) {
115 GtkWidget *header_view;
117 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
118 MODEST_WIDGET_TYPE_HEADER_VIEW);
119 return modest_header_view_get_selected_headers (MODEST_HEADER_VIEW(header_view));
121 } else if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
122 /* for MsgViewWindows, we simply return a list with one element */
126 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW(win));
127 list = tny_simple_list_new ();
128 tny_list_prepend (list, G_OBJECT(msg));
136 modest_ui_actions_on_delete (GtkWidget *widget, ModestWindow *win)
138 TnyList *header_list;
140 // GtkTreeModel *model;
142 g_return_if_fail (MODEST_IS_WINDOW(win));
144 header_list = get_selected_headers (win);
147 iter = tny_list_create_iterator (header_list);
148 /* model = gtk_tree_view_get_model (GTK_TREE_VIEW (header_view)); */
149 /* if (GTK_IS_TREE_MODEL_SORT (model)) */
150 /* model = gtk_tree_model_sort_get_model (GTK_TREE_MODEL_SORT (model)); */
153 ModestMailOperation *mail_op;
155 header = TNY_HEADER (tny_iterator_get_current (iter));
156 /* TODO: thick grain mail operation involving
157 a list of objects. Composite pattern ??? */
158 mail_op = modest_mail_operation_new ();
160 /* TODO: add confirmation dialog */
163 modest_mail_operation_remove_msg (mail_op, header, TRUE);
165 /* Remove from tree model */
166 if (modest_mail_operation_get_status (mail_op) ==
167 MODEST_MAIL_OPERATION_STATUS_SUCCESS) {
168 /* tny_list_remove (TNY_LIST (model), G_OBJECT (header)); */
170 /* TODO: error handling management */
172 error = modest_mail_operation_get_error (mail_op);
173 g_warning (error->message);
176 g_object_unref (G_OBJECT (mail_op));
177 g_object_unref (header);
178 tny_iterator_next (iter);
180 } while (!tny_iterator_is_done (iter));
186 modest_ui_actions_on_quit (GtkWidget *widget, ModestWindow *win)
188 /* FIXME: save size of main window */
189 /* save_sizes (main_window); */
190 gtk_widget_destroy (GTK_WIDGET (win));
194 modest_ui_actions_on_accounts (GtkWidget *widget, ModestWindow *win)
196 GtkWidget *account_win;
197 account_win = modest_account_view_window_new ();
200 gtk_window_set_transient_for (GTK_WINDOW (account_win), GTK_WINDOW (win));
202 gtk_widget_show (account_win);
206 modest_ui_actions_on_new_msg (GtkWidget *widget, ModestWindow *win)
208 ModestWindow *msg_win;
213 account = g_strdup(modest_window_get_active_account (win));
215 account = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
217 from_str = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(),
220 msg = modest_tny_msg_new ("", from_str, "", "", "", "", NULL);
221 msg_win = modest_msg_edit_window_new (msg, account);
223 gtk_window_set_transient_for (GTK_WINDOW (msg_win),
227 g_object_unref (G_OBJECT(msg));
229 gtk_widget_show_all (GTK_WIDGET (msg_win));
234 modest_ui_actions_on_open (GtkWidget *widget, ModestWindow *win)
244 reply_forward_func (gpointer data, gpointer user_data)
246 TnyMsg *msg, *new_msg;
247 GetMsgAsyncHelper *helper;
248 ReplyForwardHelper *rf_helper;
249 ModestWindow *msg_win;
250 ModestEditType edit_type;
253 msg = TNY_MSG (data);
254 helper = (GetMsgAsyncHelper *) user_data;
255 rf_helper = (ReplyForwardHelper *) helper->user_data;
257 from = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(),
259 /* Create reply mail */
260 switch (rf_helper->action) {
263 modest_mail_operation_create_reply_mail (msg,
265 rf_helper->reply_forward_type,
266 MODEST_MAIL_OPERATION_REPLY_MODE_SENDER);
268 case ACTION_REPLY_TO_ALL:
270 modest_mail_operation_create_reply_mail (msg, from, rf_helper->reply_forward_type,
271 MODEST_MAIL_OPERATION_REPLY_MODE_ALL);
272 edit_type = MODEST_EDIT_TYPE_REPLY;
276 modest_mail_operation_create_forward_mail (msg, from, rf_helper->reply_forward_type);
277 edit_type = MODEST_EDIT_TYPE_FORWARD;
280 g_return_if_reached ();
284 g_warning ("Unable to create a message");
288 /* Show edit window */
289 msg_win = modest_msg_edit_window_new (new_msg, rf_helper->account);
290 gtk_widget_show_all (GTK_WIDGET (msg_win));
293 g_object_unref (G_OBJECT (new_msg));
296 g_free (rf_helper->account);
297 g_slice_free (ReplyForwardHelper, rf_helper);
301 * Common code for the reply and forward actions
304 reply_forward (GtkWidget *widget, ReplyForwardAction action, ModestWindow *win)
306 TnyList *header_list;
307 guint reply_forward_type;
310 GetMsgAsyncHelper *helper;
311 ReplyForwardHelper *rf_helper;
313 g_return_if_fail (MODEST_IS_WINDOW(win));
315 header_list = get_selected_headers (win);
319 reply_forward_type = modest_conf_get_int (modest_runtime_get_conf (),
320 (action == ACTION_FORWARD) ? MODEST_CONF_FORWARD_TYPE : MODEST_CONF_REPLY_TYPE,
323 /* We assume that we can only select messages of the
324 same folder and that we reply all of them from the
325 same account. In fact the interface currently only
326 allows single selection */
329 rf_helper = g_slice_new0 (ReplyForwardHelper);
330 rf_helper->reply_forward_type = reply_forward_type;
331 rf_helper->action = action;
332 rf_helper->account = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());;
334 helper = g_slice_new0 (GetMsgAsyncHelper);
335 //helper->main_window = NULL;
336 helper->func = reply_forward_func;
337 helper->iter = tny_list_create_iterator (header_list);
338 helper->user_data = rf_helper;
340 header = TNY_HEADER (tny_iterator_get_current (helper->iter));
341 folder = tny_header_get_folder (header);
343 /* The callback will call it per each header */
344 tny_folder_get_msg_async (folder, header, get_msg_cb, helper);
347 g_object_unref (G_OBJECT (header));
348 g_object_unref (G_OBJECT (folder));
352 modest_ui_actions_on_reply (GtkWidget *widget, ModestWindow *win)
354 g_return_if_fail (MODEST_IS_WINDOW(win));
356 reply_forward (widget, ACTION_REPLY, win);
360 modest_ui_actions_on_forward (GtkWidget *widget, ModestWindow *win)
362 g_return_if_fail (MODEST_IS_WINDOW(win));
364 reply_forward (widget, ACTION_FORWARD, win);
368 modest_ui_actions_on_reply_all (GtkWidget *widget,ModestWindow *win)
370 g_return_if_fail (MODEST_IS_WINDOW(win));
372 reply_forward (widget, ACTION_REPLY_TO_ALL, win);
376 modest_ui_actions_on_next (GtkWidget *widget,
377 ModestMainWindow *main_window)
379 GtkWidget *header_view;
380 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
382 header_view = modest_main_window_get_child_widget (main_window,
383 MODEST_WIDGET_TYPE_HEADER_VIEW);
387 modest_header_view_select_next (MODEST_HEADER_VIEW(header_view));
391 modest_ui_actions_on_prev (GtkWidget *widget,
392 ModestMainWindow *main_window)
394 GtkWidget *header_view;
395 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
397 header_view = modest_main_window_get_child_widget (main_window,
398 MODEST_WIDGET_TYPE_HEADER_VIEW);
402 modest_header_view_select_prev (MODEST_HEADER_VIEW(header_view));
407 modest_ui_actions_on_send_receive (GtkWidget *widget, ModestWindow *win)
410 TnyAccountStore *account_store;
412 /* Get device. Do not ask the platform factory for it, because
413 it returns always a new one */
414 account_store = TNY_ACCOUNT_STORE (modest_runtime_get_account_store ());
415 device = tny_account_store_get_device (account_store);
417 tny_device_force_online (device);
419 /* FIXME: refresh the folders */
425 modest_ui_actions_toggle_view (GtkWidget *widget, ModestMainWindow *main_window)
428 GtkWidget *header_view;
430 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
432 header_view = modest_main_window_get_child_widget (main_window,
433 MODEST_WIDGET_TYPE_HEADER_VIEW);
437 conf = modest_runtime_get_conf ();
439 /* what is saved/restored is depending on the style; thus; we save with
440 * old style, then update the style, and restore for this new style*/
441 modest_widget_memory_save (conf, G_OBJECT(header_view), "header-view");
443 if (modest_header_view_get_style
444 (MODEST_HEADER_VIEW(header_view)) == MODEST_HEADER_VIEW_STYLE_DETAILS)
445 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
446 MODEST_HEADER_VIEW_STYLE_TWOLINES);
448 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
449 MODEST_HEADER_VIEW_STYLE_DETAILS);
451 modest_widget_memory_restore (conf, G_OBJECT(header_view),
458 * Marks a message as read and passes it to the msg preview widget
461 read_msg_func (gpointer data, gpointer user_data)
465 GetMsgAsyncHelper *helper;
466 TnyHeaderFlags header_flags;
467 GtkWidget *msg_preview;
469 msg = TNY_MSG (data);
470 helper = (GetMsgAsyncHelper *) user_data;
472 msg_preview = modest_main_window_get_child_widget (helper->main_window,
473 MODEST_WIDGET_TYPE_MSG_PREVIEW);
477 /* mark message as seen; _set_flags crashes, bug in tinymail? */
478 header = TNY_HEADER (tny_iterator_get_current (helper->iter));
479 header_flags = tny_header_get_flags (header);
480 tny_header_set_flags (header, header_flags | TNY_HEADER_FLAG_SEEN);
481 g_object_unref (G_OBJECT (header));
483 /* Set message on msg view */
484 modest_msg_view_set_message (MODEST_MSG_VIEW(msg_preview), msg);
488 * This function is a generic handler for the tny_folder_get_msg_async
489 * call. It expects as user_data a #GetMsgAsyncHelper. This helper
490 * contains a user provided function that is called inside this
491 * method. This will allow us to use this callback in many different
492 * places. This callback performs the common actions for the
493 * get_msg_async call, more specific actions will be done by the user
497 get_msg_cb (TnyFolder *folder, TnyMsg *msg, GError **err, gpointer user_data)
499 GetMsgAsyncHelper *helper;
501 helper = (GetMsgAsyncHelper *) user_data;
503 if ((*err && ((*err)->code == TNY_FOLDER_ERROR_GET_MSG)) || !msg) {
504 GtkWidget *header_view =
505 modest_main_window_get_child_widget(helper->main_window,
506 MODEST_WIDGET_TYPE_HEADER_VIEW);
508 modest_ui_actions_on_item_not_found (MODEST_HEADER_VIEW(header_view),
509 MODEST_ITEM_TYPE_MESSAGE,
510 MODEST_WINDOW(helper->main_window));
514 /* Call user function */
515 helper->func (msg, user_data);
517 /* Process next element (if exists) */
518 tny_iterator_next (helper->iter);
519 if (tny_iterator_is_done (helper->iter)) {
521 headers = tny_iterator_get_list (helper->iter);
523 g_object_unref (G_OBJECT (headers));
524 g_object_unref (G_OBJECT (helper->iter));
525 g_slice_free (GetMsgAsyncHelper, helper);
528 header = TNY_HEADER (tny_iterator_get_current (helper->iter));
529 tny_folder_get_msg_async (folder, header,
531 g_object_unref (G_OBJECT(header));
536 modest_ui_actions_on_header_selected (ModestHeaderView *folder_view,
538 ModestMainWindow *main_window)
540 GtkWidget *msg_preview;
542 GetMsgAsyncHelper *helper;
545 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
547 msg_preview = modest_main_window_get_child_widget(main_window,
548 MODEST_WIDGET_TYPE_MSG_PREVIEW);
552 /* when there's no header, clear the msgview */
554 modest_msg_view_set_message (MODEST_MSG_VIEW(msg_preview), NULL);
558 folder = tny_header_get_folder (TNY_HEADER(header));
561 list = tny_simple_list_new ();
562 tny_list_prepend (list, G_OBJECT (header));
564 /* Fill helper data */
565 helper = g_slice_new0 (GetMsgAsyncHelper);
566 helper->main_window = main_window;
567 helper->iter = tny_list_create_iterator (list);
568 helper->func = read_msg_func;
570 tny_folder_get_msg_async (TNY_FOLDER(folder),
575 g_object_unref (G_OBJECT (folder));
581 modest_ui_actions_on_header_activated (ModestHeaderView *folder_view, TnyHeader *header,
582 ModestMainWindow *main_window)
585 TnyFolder *folder = NULL;
587 gchar *account = NULL;
589 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
594 folder = tny_header_get_folder (header);
596 g_printerr ("modest: cannot get folder for header\n");
600 /* FIXME: make async?; check error */
601 msg = tny_folder_get_msg (folder, header, NULL);
603 g_printerr ("modest: cannot get msg for header\n");
607 account = g_strdup(modest_window_get_active_account(MODEST_WINDOW(main_window)));
609 account = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
611 win = modest_msg_view_window_new (msg, account);
612 gtk_window_set_transient_for (GTK_WINDOW (win),
613 GTK_WINDOW (main_window));
615 gtk_widget_show_all (GTK_WIDGET(win));
621 g_object_unref (G_OBJECT (folder));
623 g_object_unref (G_OBJECT (folder));
631 modest_ui_actions_on_folder_selection_changed (ModestFolderView *folder_view,
634 ModestMainWindow *main_window)
636 // GtkLabel *folder_info_label;
639 GtkWidget *header_view;
641 /* folder_info_label = */
642 /* GTK_LABEL (modest_widget_factory_get_folder_info_label */
643 /* (modest_runtime_get_widget_factory())); */
646 /* gtk_label_set_label (GTK_LABEL(folder_info_label), ""); */
650 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
652 header_view = modest_main_window_get_child_widget(main_window,
653 MODEST_WIDGET_TYPE_HEADER_VIEW);
657 conf = modest_runtime_get_conf ();
659 if (!selected) { /* the folder was unselected; save it's settings */
660 modest_widget_memory_save (conf, G_OBJECT (header_view), "header-view");
661 gtk_window_set_title (GTK_WINDOW(main_window), "Modest");
662 modest_header_view_set_folder (MODEST_HEADER_VIEW(header_view), NULL);
663 } else { /* the folder was selected */
664 if (folder) { /* folder may be NULL */
668 num = tny_folder_get_all_count (folder);
669 unread = tny_folder_get_unread_count (folder);
671 title = g_strdup_printf ("Modest: %s",
672 tny_folder_get_name (folder));
674 gtk_window_set_title (GTK_WINDOW(main_window), title);
677 txt = g_strdup_printf (_("%d %s, %d unread"),
678 num, num==1 ? _("item") : _("items"), unread);
679 //gtk_label_set_label (GTK_LABEL(folder_info_label), txt);
682 modest_header_view_set_folder (MODEST_HEADER_VIEW(header_view), folder);
683 modest_widget_memory_restore (conf, G_OBJECT(header_view),
689 /****************************************************/
691 * below some stuff to clearup statusbar messages after 1,5 seconds....
694 progress_bar_clean (GtkWidget *bar)
696 if (GTK_IS_PROGRESS_BAR(bar)) {
697 gtk_progress_bar_set_text (GTK_PROGRESS_BAR(bar), "");
698 gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(bar), 1.0);
704 statusbar_clean (GtkWidget *bar)
706 if (GTK_IS_STATUSBAR(bar))
707 gtk_statusbar_push (GTK_STATUSBAR(bar), 0, "");
713 statusbar_push (ModestMainWindow *main_window, guint context_id, const gchar *msg)
718 GtkWidget *progress_bar, *status_bar;
720 progress_bar = modest_main_window_get_child_widget (main_window,
721 MODEST_WIDGET_TYPE_PROGRESS_BAR);
722 status_bar = modest_main_window_get_child_widget (main_window,
723 MODEST_WIDGET_TYPE_STATUS_BAR);
725 gtk_widget_show (progress_bar);
726 g_timeout_add (3000, (GSourceFunc)progress_bar_clean, progress_bar);
730 gtk_widget_show (status_bar);
731 gtk_statusbar_push (GTK_STATUSBAR(status_bar), 0, msg);
732 g_timeout_add (1500, (GSourceFunc)statusbar_clean, status_bar);
736 /****************************************************************************/
739 modest_ui_actions_on_item_not_found (ModestHeaderView *header_view,ModestItemType type,
746 TnyAccountStore *account_store;
748 item = (type == MODEST_ITEM_TYPE_FOLDER) ? "folder" : "message";
750 /* Get device. Do not ask the platform factory for it, because
751 it returns always a new one */
752 account_store = TNY_ACCOUNT_STORE (modest_runtime_get_account_store ());
753 device = tny_account_store_get_device (account_store);
755 if (g_main_depth > 0)
756 gdk_threads_enter ();
757 online = tny_device_is_online (device);
760 /* already online -- the item is simply not there... */
761 dialog = gtk_message_dialog_new (GTK_WINDOW (win),
765 _("The %s you selected cannot be found"),
767 gtk_dialog_run (GTK_DIALOG(dialog));
769 dialog = gtk_dialog_new_with_buttons (_("Connection requested"),
777 txt = g_strdup_printf (_("This %s is not available in offline mode.\n"
778 "Do you want to get online?"), item);
779 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
780 gtk_label_new (txt), FALSE, FALSE, 0);
781 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
784 gtk_window_set_default_size (GTK_WINDOW(dialog), 300, 300);
785 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
786 tny_device_force_online (device);
789 gtk_widget_destroy (dialog);
790 if (g_main_depth > 0)
791 gdk_threads_leave ();
797 modest_ui_actions_on_header_status_update (ModestHeaderView *header_view,
798 const gchar *msg, gint num,
799 gint total, ModestMainWindow *main_window)
802 GtkWidget *progress_bar;
804 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
806 progress_bar = modest_main_window_get_child_widget (main_window,
807 MODEST_WIDGET_TYPE_PROGRESS_BAR);
812 gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(progress_bar),
813 (gdouble)num/(gdouble)total);
815 gtk_progress_bar_pulse (GTK_PROGRESS_BAR(progress_bar));
817 txt = g_strdup_printf (_("Downloading %d of %d"), num, total);
818 gtk_progress_bar_set_text (GTK_PROGRESS_BAR(progress_bar), txt);
821 statusbar_push (main_window, 0, msg);
826 modest_ui_actions_on_msg_link_hover (ModestMsgView *msgview, const gchar* link,
829 g_message (__FUNCTION__);
834 modest_ui_actions_on_msg_link_clicked (ModestMsgView *msgview, const gchar* link,
837 g_message (__FUNCTION__);
841 modest_ui_actions_on_msg_attachment_clicked (ModestMsgView *msgview, int index,
844 g_message (__FUNCTION__);
849 modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
851 TnyTransportAccount *transport_account;
852 ModestMailOperation *mail_operation;
854 gchar *account_name, *from;
855 ModestAccountMgr *account_mgr;
857 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window));
859 data = modest_msg_edit_window_get_msg_data (edit_window);
861 /* FIXME: Code added just for testing. The final version will
862 use the send queue provided by tinymail and some
864 account_mgr = modest_runtime_get_account_mgr();
865 account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
867 account_name = modest_account_mgr_get_default_account (account_mgr);
869 g_printerr ("modest: no account found\n");
870 modest_msg_edit_window_free_msg_data (edit_window, data);
874 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_tny_account_by_account
875 (modest_runtime_get_account_store(),
877 TNY_ACCOUNT_TYPE_TRANSPORT));
878 if (!transport_account) {
879 g_printerr ("modest: no transport account found for '%s'\n", account_name);
880 g_free (account_name);
881 modest_msg_edit_window_free_msg_data (edit_window, data);
884 from = modest_account_mgr_get_from_string (account_mgr, account_name);
886 mail_operation = modest_mail_operation_new ();
887 modest_mail_operation_send_new_mail (mail_operation,
898 g_free (account_name);
899 g_object_unref (G_OBJECT (mail_operation));
900 g_object_unref (G_OBJECT (transport_account));
902 modest_msg_edit_window_free_msg_data (edit_window, data);
904 /* Save settings and close the window */
905 /* save_settings (edit_window) */
906 gtk_widget_destroy (GTK_WIDGET (edit_window));
910 * Shows a dialog with an entry that asks for some text. The returned
911 * value must be freed by the caller. The dialog window title will be
915 ask_for_folder_name (GtkWindow *parent_window,
918 GtkWidget *dialog, *entry;
919 gchar *folder_name = NULL;
921 /* Ask for folder name */
922 dialog = gtk_dialog_new_with_buttons (_("New Folder Name"),
930 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
931 gtk_label_new(title),
934 entry = gtk_entry_new_with_max_length (40);
935 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
939 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
941 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
942 folder_name = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry)));
944 gtk_widget_destroy (dialog);
950 modest_ui_actions_on_new_folder (GtkWidget *widget, ModestMainWindow *main_window)
952 TnyFolder *parent_folder;
953 GtkWidget *folder_view;
955 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
957 folder_view = modest_main_window_get_child_widget (main_window,
958 MODEST_WIDGET_TYPE_FOLDER_VIEW);
962 parent_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
967 folder_name = ask_for_folder_name (GTK_WINDOW (main_window),
968 _("Please enter a name for the new folder"));
970 if (folder_name != NULL && strlen (folder_name) > 0) {
971 TnyFolder *new_folder;
972 ModestMailOperation *mail_op;
974 mail_op = modest_mail_operation_new ();
975 new_folder = modest_mail_operation_create_folder (mail_op,
976 TNY_FOLDER_STORE (parent_folder),
977 (const gchar *) folder_name);
979 /* TODO: tinymail should do this.
981 modest_folder_view_add_subfolder (MODEST_FOLDER_VIEW(folder_view),
984 /* Free new folder */
985 g_object_unref (new_folder);
987 g_object_unref (mail_op);
989 g_object_unref (parent_folder);
994 modest_ui_actions_on_rename_folder (GtkWidget *widget,
995 ModestMainWindow *main_window)
998 GtkWidget *folder_view;
1000 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1002 folder_view = modest_main_window_get_child_widget (main_window,
1003 MODEST_WIDGET_TYPE_FOLDER_VIEW);
1007 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
1011 folder_name = ask_for_folder_name (GTK_WINDOW (main_window),
1012 _("Please enter a new name for the folder"));
1014 if (folder_name != NULL && strlen (folder_name) > 0) {
1015 ModestMailOperation *mail_op;
1016 const GError *error;
1018 mail_op = modest_mail_operation_new ();
1019 modest_mail_operation_rename_folder (mail_op,
1021 (const gchar *) folder_name);
1023 error = modest_mail_operation_get_error (mail_op);
1025 /* TODO: tinymail should do this.
1027 modest_folder_view_rename (MODEST_FOLDER_VIEW(folder_view));
1029 /* TODO: else ? notify error ? */
1031 g_object_unref (mail_op);
1033 g_object_unref (folder);
1038 delete_folder (ModestMainWindow *main_window, gboolean move_to_trash)
1041 ModestMailOperation *mail_op;
1042 GtkWidget *folder_view;
1044 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1046 folder_view = modest_main_window_get_child_widget (main_window,
1047 MODEST_WIDGET_TYPE_FOLDER_VIEW);
1051 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
1053 mail_op = modest_mail_operation_new ();
1054 modest_mail_operation_remove_folder (mail_op, folder, move_to_trash);
1055 g_object_unref (mail_op);
1059 modest_ui_actions_on_delete_folder (GtkWidget *widget,
1060 ModestMainWindow *main_window)
1062 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1064 delete_folder (main_window, FALSE);
1068 modest_ui_actions_on_move_folder_to_trash_folder (GtkWidget *widget, ModestMainWindow *main_window)
1070 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1072 delete_folder (main_window, TRUE);
1076 modest_ui_actions_on_accounts_reloaded (TnyAccountStore *store, gpointer user_data)
1079 /* ModestFolderView *folder_view; */
1081 /* folder_view = modest_widget_factory_get_folder_view (modest_runtime_get_widget_factory()); */
1082 /* modest_folder_view_update_model (folder_view, store); */
1086 modest_ui_actions_on_folder_moved (ModestFolderView *folder_view, TnyFolder *folder,
1087 TnyFolderStore *parent, gboolean *done,
1090 ModestMailOperation *mail_op;
1091 const GError *error;
1095 /* Try to move the folder */
1096 mail_op = modest_mail_operation_new ();
1097 modest_mail_operation_move_folder (mail_op, folder, parent);
1099 error = modest_mail_operation_get_error (mail_op);
1103 g_object_unref (G_OBJECT (mail_op));
1109 modest_ui_actions_on_password_requested (TnyAccountStore *account_store,
1110 const gchar* account_name,
1114 ModestMainWindow *main_window)
1117 GtkWidget *dialog, *entry, *remember_pass_check;
1119 dialog = gtk_dialog_new_with_buttons (_("Password requested"),
1123 GTK_RESPONSE_REJECT,
1125 GTK_RESPONSE_ACCEPT,
1127 gtk_window_set_transient_for (GTK_WINDOW(dialog), GTK_WINDOW(main_window));
1129 txt = g_strdup_printf (_("Please enter your password for %s"), account_name);
1130 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), gtk_label_new(txt),
1134 entry = gtk_entry_new_with_max_length (40);
1135 gtk_entry_set_visibility (GTK_ENTRY(entry), FALSE);
1136 gtk_entry_set_invisible_char (GTK_ENTRY(entry), 0x2022); /* bullet unichar */
1138 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry,
1141 remember_pass_check = gtk_check_button_new_with_label (_("Remember password"));
1142 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), remember_pass_check,
1145 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
1147 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
1148 *password = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry)));
1155 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (remember_pass_check)))
1160 gtk_widget_destroy (dialog);