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, TnyHeader *header,
537 ModestMainWindow *main_window)
539 GtkWidget *msg_preview;
541 GetMsgAsyncHelper *helper;
544 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
546 msg_preview = modest_main_window_get_child_widget(main_window,
547 MODEST_WIDGET_TYPE_MSG_PREVIEW);
551 /* when there's no header, clear the msgview */
553 modest_msg_view_set_message (MODEST_MSG_VIEW(msg_preview), NULL);
557 folder = tny_header_get_folder (TNY_HEADER(header));
560 list = tny_simple_list_new ();
561 tny_list_prepend (list, G_OBJECT (header));
563 /* Fill helper data */
564 helper = g_slice_new0 (GetMsgAsyncHelper);
565 helper->main_window = main_window;
566 helper->iter = tny_list_create_iterator (list);
567 helper->func = read_msg_func;
569 tny_folder_get_msg_async (TNY_FOLDER(folder),
574 g_object_unref (G_OBJECT (folder));
580 modest_ui_actions_on_header_activated (ModestHeaderView *folder_view, TnyHeader *header,
581 ModestMainWindow *main_window)
584 TnyFolder *folder = NULL;
586 gchar *account = NULL;
588 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
593 folder = tny_header_get_folder (header);
595 g_printerr ("modest: cannot get folder for header\n");
599 /* FIXME: make async?; check error */
600 msg = tny_folder_get_msg (folder, header, NULL);
602 g_printerr ("modest: cannot get msg for header\n");
606 account = g_strdup(modest_window_get_active_account(MODEST_WINDOW(main_window)));
608 account = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
610 win = modest_msg_view_window_new (msg, account);
611 gtk_window_set_transient_for (GTK_WINDOW (win),
612 GTK_WINDOW (main_window));
614 gtk_widget_show_all (GTK_WIDGET(win));
620 g_object_unref (G_OBJECT (folder));
622 g_object_unref (G_OBJECT (folder));
630 modest_ui_actions_on_folder_selection_changed (ModestFolderView *folder_view,
633 ModestMainWindow *main_window)
635 // GtkLabel *folder_info_label;
638 GtkWidget *header_view;
640 /* folder_info_label = */
641 /* GTK_LABEL (modest_widget_factory_get_folder_info_label */
642 /* (modest_runtime_get_widget_factory())); */
645 /* gtk_label_set_label (GTK_LABEL(folder_info_label), ""); */
649 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
651 header_view = modest_main_window_get_child_widget(main_window,
652 MODEST_WIDGET_TYPE_HEADER_VIEW);
656 conf = modest_runtime_get_conf ();
658 if (!selected) { /* the folder was unselected; save it's settings */
659 modest_widget_memory_save (conf, G_OBJECT (header_view), "header-view");
660 gtk_window_set_title (GTK_WINDOW(main_window), "Modest");
661 modest_header_view_set_folder (MODEST_HEADER_VIEW(header_view), NULL);
662 } else { /* the folder was selected */
663 if (folder) { /* folder may be NULL */
667 num = tny_folder_get_all_count (folder);
668 unread = tny_folder_get_unread_count (folder);
670 title = g_strdup_printf ("Modest: %s",
671 tny_folder_get_name (folder));
673 gtk_window_set_title (GTK_WINDOW(main_window), title);
676 txt = g_strdup_printf (_("%d %s, %d unread"),
677 num, num==1 ? _("item") : _("items"), unread);
678 //gtk_label_set_label (GTK_LABEL(folder_info_label), txt);
681 modest_header_view_set_folder (MODEST_HEADER_VIEW(header_view), folder);
682 modest_widget_memory_restore (conf, G_OBJECT(header_view),
688 /****************************************************/
690 * below some stuff to clearup statusbar messages after 1,5 seconds....
693 progress_bar_clean (GtkWidget *bar)
695 if (GTK_IS_PROGRESS_BAR(bar)) {
696 gtk_progress_bar_set_text (GTK_PROGRESS_BAR(bar), "");
697 gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(bar), 1.0);
703 statusbar_clean (GtkWidget *bar)
705 if (GTK_IS_STATUSBAR(bar))
706 gtk_statusbar_push (GTK_STATUSBAR(bar), 0, "");
712 statusbar_push (ModestMainWindow *main_window, guint context_id, const gchar *msg)
717 GtkWidget *progress_bar, *status_bar;
719 progress_bar = modest_main_window_get_child_widget (main_window,
720 MODEST_WIDGET_TYPE_PROGRESS_BAR);
721 status_bar = modest_main_window_get_child_widget (main_window,
722 MODEST_WIDGET_TYPE_STATUS_BAR);
724 gtk_widget_show (progress_bar);
725 g_timeout_add (3000, (GSourceFunc)progress_bar_clean, progress_bar);
729 gtk_widget_show (status_bar);
730 gtk_statusbar_push (GTK_STATUSBAR(status_bar), 0, msg);
731 g_timeout_add (1500, (GSourceFunc)statusbar_clean, status_bar);
735 /****************************************************************************/
738 modest_ui_actions_on_item_not_found (ModestHeaderView *header_view,ModestItemType type,
745 TnyAccountStore *account_store;
747 item = (type == MODEST_ITEM_TYPE_FOLDER) ? "folder" : "message";
749 /* Get device. Do not ask the platform factory for it, because
750 it returns always a new one */
751 account_store = TNY_ACCOUNT_STORE (modest_runtime_get_account_store ());
752 device = tny_account_store_get_device (account_store);
754 if (g_main_depth > 0)
755 gdk_threads_enter ();
756 online = tny_device_is_online (device);
759 /* already online -- the item is simply not there... */
760 dialog = gtk_message_dialog_new (GTK_WINDOW (win),
764 _("The %s you selected cannot be found"),
766 gtk_dialog_run (GTK_DIALOG(dialog));
768 dialog = gtk_dialog_new_with_buttons (_("Connection requested"),
776 txt = g_strdup_printf (_("This %s is not available in offline mode.\n"
777 "Do you want to get online?"), item);
778 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
779 gtk_label_new (txt), FALSE, FALSE, 0);
780 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
783 gtk_window_set_default_size (GTK_WINDOW(dialog), 300, 300);
784 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
785 tny_device_force_online (device);
788 gtk_widget_destroy (dialog);
789 if (g_main_depth > 0)
790 gdk_threads_leave ();
796 modest_ui_actions_on_header_status_update (ModestHeaderView *header_view,
797 const gchar *msg, gint num,
798 gint total, ModestMainWindow *main_window)
801 GtkWidget *progress_bar;
803 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
805 progress_bar = modest_main_window_get_child_widget (main_window,
806 MODEST_WIDGET_TYPE_PROGRESS_BAR);
811 gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(progress_bar),
812 (gdouble)num/(gdouble)total);
814 gtk_progress_bar_pulse (GTK_PROGRESS_BAR(progress_bar));
816 txt = g_strdup_printf (_("Downloading %d of %d"), num, total);
817 gtk_progress_bar_set_text (GTK_PROGRESS_BAR(progress_bar), txt);
820 statusbar_push (main_window, 0, msg);
825 modest_ui_actions_on_msg_link_hover (ModestMsgView *msgview, const gchar* link,
828 g_warning (__FUNCTION__);
833 modest_ui_actions_on_msg_link_clicked (ModestMsgView *msgview, const gchar* link,
836 g_warning (__FUNCTION__);
840 modest_ui_actions_on_msg_attachment_clicked (ModestMsgView *msgview, int index,
843 g_warning (__FUNCTION__);
848 modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
850 TnyTransportAccount *transport_account;
851 ModestMailOperation *mail_operation;
853 gchar *account_name, *from;
854 ModestAccountMgr *account_mgr;
856 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window));
858 data = modest_msg_edit_window_get_msg_data (edit_window);
860 /* FIXME: Code added just for testing. The final version will
861 use the send queue provided by tinymail and some
863 account_mgr = modest_runtime_get_account_mgr();
864 account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
866 account_name = modest_account_mgr_get_default_account (account_mgr);
868 g_printerr ("modest: no account found\n");
869 modest_msg_edit_window_free_msg_data (edit_window, data);
873 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_tny_account_by_account
874 (modest_runtime_get_account_store(),
876 TNY_ACCOUNT_TYPE_TRANSPORT));
877 if (!transport_account) {
878 g_printerr ("modest: no transport account found for '%s'\n", account_name);
879 g_free (account_name);
880 modest_msg_edit_window_free_msg_data (edit_window, data);
883 from = modest_account_mgr_get_from_string (account_mgr, account_name);
885 mail_operation = modest_mail_operation_new ();
886 modest_mail_operation_send_new_mail (mail_operation,
897 g_free (account_name);
898 g_object_unref (G_OBJECT (mail_operation));
899 g_object_unref (G_OBJECT (transport_account));
901 modest_msg_edit_window_free_msg_data (edit_window, data);
903 /* Save settings and close the window */
904 /* save_settings (edit_window) */
905 gtk_widget_destroy (GTK_WIDGET (edit_window));
909 * Shows a dialog with an entry that asks for some text. The returned
910 * value must be freed by the caller. The dialog window title will be
914 ask_for_folder_name (GtkWindow *parent_window,
917 GtkWidget *dialog, *entry;
918 gchar *folder_name = NULL;
920 /* Ask for folder name */
921 dialog = gtk_dialog_new_with_buttons (_("New Folder Name"),
929 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
930 gtk_label_new(title),
933 entry = gtk_entry_new_with_max_length (40);
934 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
938 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
940 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
941 folder_name = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry)));
943 gtk_widget_destroy (dialog);
949 modest_ui_actions_on_new_folder (GtkWidget *widget, ModestMainWindow *main_window)
951 TnyFolder *parent_folder;
952 GtkWidget *folder_view;
954 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
956 folder_view = modest_main_window_get_child_widget (main_window,
957 MODEST_WIDGET_TYPE_FOLDER_VIEW);
961 parent_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
966 folder_name = ask_for_folder_name (GTK_WINDOW (main_window),
967 _("Please enter a name for the new folder"));
969 if (folder_name != NULL && strlen (folder_name) > 0) {
970 TnyFolder *new_folder;
971 ModestMailOperation *mail_op;
973 mail_op = modest_mail_operation_new ();
974 new_folder = modest_mail_operation_create_folder (mail_op,
975 TNY_FOLDER_STORE (parent_folder),
976 (const gchar *) folder_name);
978 /* TODO: tinymail should do this.
980 modest_folder_view_add_subfolder (MODEST_FOLDER_VIEW(folder_view),
983 /* Free new folder */
984 g_object_unref (new_folder);
986 g_object_unref (mail_op);
988 g_object_unref (parent_folder);
993 modest_ui_actions_on_rename_folder (GtkWidget *widget,
994 ModestMainWindow *main_window)
997 GtkWidget *folder_view;
999 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1001 folder_view = modest_main_window_get_child_widget (main_window,
1002 MODEST_WIDGET_TYPE_FOLDER_VIEW);
1006 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
1010 folder_name = ask_for_folder_name (GTK_WINDOW (main_window),
1011 _("Please enter a new name for the folder"));
1013 if (folder_name != NULL && strlen (folder_name) > 0) {
1014 ModestMailOperation *mail_op;
1015 const GError *error;
1017 mail_op = modest_mail_operation_new ();
1018 modest_mail_operation_rename_folder (mail_op,
1020 (const gchar *) folder_name);
1022 error = modest_mail_operation_get_error (mail_op);
1024 /* TODO: tinymail should do this.
1026 modest_folder_view_rename (MODEST_FOLDER_VIEW(folder_view));
1028 /* TODO: else ? notify error ? */
1030 g_object_unref (mail_op);
1032 g_object_unref (folder);
1037 delete_folder (ModestMainWindow *main_window, gboolean move_to_trash)
1040 ModestMailOperation *mail_op;
1041 GtkWidget *folder_view;
1043 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1045 folder_view = modest_main_window_get_child_widget (main_window,
1046 MODEST_WIDGET_TYPE_FOLDER_VIEW);
1050 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
1052 mail_op = modest_mail_operation_new ();
1053 modest_mail_operation_remove_folder (mail_op, folder, move_to_trash);
1054 g_object_unref (mail_op);
1058 modest_ui_actions_on_delete_folder (GtkWidget *widget,
1059 ModestMainWindow *main_window)
1061 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1063 delete_folder (main_window, FALSE);
1067 modest_ui_actions_on_move_folder_to_trash_folder (GtkWidget *widget, ModestMainWindow *main_window)
1069 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1071 delete_folder (main_window, TRUE);
1075 modest_ui_actions_on_accounts_reloaded (TnyAccountStore *store, gpointer user_data)
1078 /* ModestFolderView *folder_view; */
1080 /* folder_view = modest_widget_factory_get_folder_view (modest_runtime_get_widget_factory()); */
1081 /* modest_folder_view_update_model (folder_view, store); */
1085 modest_ui_actions_on_folder_moved (ModestFolderView *folder_view, TnyFolder *folder,
1086 TnyFolderStore *parent, gboolean *done,
1089 ModestMailOperation *mail_op;
1090 const GError *error;
1094 /* Try to move the folder */
1095 mail_op = modest_mail_operation_new ();
1096 modest_mail_operation_move_folder (mail_op, folder, parent);
1098 error = modest_mail_operation_get_error (mail_op);
1102 g_object_unref (G_OBJECT (mail_op));
1108 modest_ui_actions_on_password_requested (TnyAccountStore *account_store,
1109 const gchar* account_name,
1113 ModestMainWindow *main_window)
1116 GtkWidget *dialog, *entry, *remember_pass_check;
1118 dialog = gtk_dialog_new_with_buttons (_("Password requested"),
1122 GTK_RESPONSE_REJECT,
1124 GTK_RESPONSE_ACCEPT,
1126 gtk_window_set_transient_for (GTK_WINDOW(dialog), GTK_WINDOW(main_window));
1128 txt = g_strdup_printf (_("Please enter your password for %s"), account_name);
1129 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), gtk_label_new(txt),
1133 entry = gtk_entry_new_with_max_length (40);
1134 gtk_entry_set_visibility (GTK_ENTRY(entry), FALSE);
1135 gtk_entry_set_invisible_char (GTK_ENTRY(entry), 0x2022); /* bullet unichar */
1137 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry,
1140 remember_pass_check = gtk_check_button_new_with_label (_("Remember password"));
1141 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), remember_pass_check,
1144 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
1146 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
1147 *password = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry)));
1154 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (remember_pass_check)))
1159 gtk_widget_destroy (dialog);