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>
40 #include "modest-ui-actions.h"
42 #include "modest-tny-platform-factory.h"
44 #include <widgets/modest-main-window.h>
45 #include <widgets/modest-msg-view-window.h>
46 #include <widgets/modest-account-view-window.h>
48 #include "modest-account-mgr-helpers.h"
49 #include "modest-mail-operation.h"
50 #include <modest-widget-memory.h>
51 #include <tny-error.h>
52 #include <tny-simple-list.h>
53 #include <tny-msg-view.h>
54 #include <tny-device.h>
57 typedef struct _GetMsgAsyncHelper {
64 typedef enum _ReplyForwardAction {
70 typedef struct _ReplyForwardHelper {
71 guint reply_forward_type;
72 ReplyForwardAction action;
77 static void reply_forward_func (gpointer data, gpointer user_data);
78 static void read_msg_func (gpointer data, gpointer user_data);
79 static void get_msg_cb (TnyFolder *folder, TnyMsg *msg, GError **err,
81 static void reply_forward (ReplyForwardAction action, ModestWindow *win);
82 static gchar* ask_for_folder_name (GtkWindow *parent_window, const gchar *title);
86 modest_ui_actions_on_about (GtkAction *action, ModestWindow *win)
89 const gchar *authors[] = {
90 "Dirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>",
93 about = gtk_about_dialog_new ();
94 gtk_about_dialog_set_name (GTK_ABOUT_DIALOG(about), PACKAGE_NAME);
95 gtk_about_dialog_set_version (GTK_ABOUT_DIALOG(about),PACKAGE_VERSION);
96 gtk_about_dialog_set_copyright (GTK_ABOUT_DIALOG(about),
97 _("Copyright (c) 2006, Nokia Corporation\n"
98 "All rights reserved."));
99 gtk_about_dialog_set_comments (GTK_ABOUT_DIALOG(about),
100 _("a modest e-mail client\n\n"
101 "design and implementation: Dirk-Jan C. Binnema\n"
102 "contributions from the fine people at KernelConcepts and Igalia\n"
103 "uses the tinymail email framework written by Philip van Hoof"));
104 gtk_about_dialog_set_authors (GTK_ABOUT_DIALOG(about), authors);
105 gtk_about_dialog_set_website (GTK_ABOUT_DIALOG(about), "http://modest.garage.maemo.org");
107 gtk_dialog_run (GTK_DIALOG (about));
108 gtk_widget_destroy(about);
113 get_selected_headers (ModestWindow *win)
115 if (MODEST_IS_MAIN_WINDOW(win)) {
116 GtkWidget *header_view;
118 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
119 MODEST_WIDGET_TYPE_HEADER_VIEW);
120 return modest_header_view_get_selected_headers (MODEST_HEADER_VIEW(header_view));
122 } else if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
123 /* for MsgViewWindows, we simply return a list with one element */
126 TnyList *list = NULL;
128 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW(win));
130 header = tny_msg_get_header (msg);
131 list = tny_simple_list_new ();
132 tny_list_prepend (list, G_OBJECT(header));
133 g_object_unref (G_OBJECT(header));
142 modest_ui_actions_on_delete (GtkAction *action, ModestWindow *win)
144 TnyList *header_list;
147 g_return_if_fail (MODEST_IS_WINDOW(win));
149 header_list = get_selected_headers (win);
152 iter = tny_list_create_iterator (header_list);
155 ModestMailOperation *mail_op;
157 header = TNY_HEADER (tny_iterator_get_current (iter));
158 /* TODO: thick grain mail operation involving
159 a list of objects. Composite pattern ??? */
160 mail_op = modest_mail_operation_new ();
162 /* TODO: add confirmation dialog */
164 /* Move to trash. TODO: Still not supported */
165 modest_mail_operation_remove_msg (mail_op, header, FALSE);
167 if (modest_mail_operation_get_status (mail_op) !=
168 MODEST_MAIL_OPERATION_STATUS_SUCCESS) {
170 error = modest_mail_operation_get_error (mail_op);
172 g_warning (error->message);
175 g_object_unref (G_OBJECT (mail_op));
176 g_object_unref (header);
177 tny_iterator_next (iter);
179 } while (!tny_iterator_is_done (iter));
185 modest_ui_actions_on_quit (GtkAction *action, ModestWindow *win)
187 /* FIXME: save size of main window */
188 /* save_sizes (main_window); */
189 gtk_widget_destroy (GTK_WIDGET (win));
193 modest_ui_actions_on_accounts (GtkAction *action, ModestWindow *win)
195 /* GtkDialog *account_win; */
196 /* account_win = GTK_DIALOG(modest_account_view_window_new ()); */
199 /* gtk_dialog_run (account_win); */
200 //gtk_widget_destroy (GTK_WIDGET(account_win));
201 GtkWidget *dialog, *label;
203 /* Create the widgets */
205 dialog = gtk_dialog_new_with_buttons ("Message",
207 GTK_DIALOG_DESTROY_WITH_PARENT,
211 label = gtk_label_new ("Hello World!");
213 /* Ensure that the dialog box is destroyed when the user responds. */
215 g_signal_connect_swapped (dialog, "response",
216 G_CALLBACK (gtk_widget_destroy),
219 /* Add the label, and show everything we've added to the dialog. */
221 gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox),
223 gtk_widget_show_all (dialog);
227 modest_ui_actions_on_new_msg (GtkAction *action, ModestWindow *win)
229 ModestWindow *msg_win;
231 TnyFolder *folder = NULL;
232 gchar *account_name = NULL;
233 gchar *from_str = NULL;
237 account_name = g_strdup(modest_window_get_active_account (win));
239 account_name = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
241 account = modest_tny_account_store_get_tny_account_by_account (modest_runtime_get_account_store(),
243 TNY_ACCOUNT_TYPE_STORE);
245 g_printerr ("modest: failed to get tnyaccount for '%s'\n", account_name);
249 from_str = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(), account_name);
251 msg = modest_tny_msg_new ("", from_str, "", "", "", "", NULL);
253 g_printerr ("modest: failed to create new msg\n");
257 folder = modest_tny_account_get_special_folder (account, TNY_FOLDER_TYPE_DRAFTS);
259 g_printerr ("modest: failed to find Drafts folder\n");
263 tny_folder_add_msg (folder, msg, &err);
265 g_printerr ("modest: error adding msg to Drafts folder: %s",
271 msg_win = modest_msg_edit_window_new (msg, account_name);
273 gtk_window_set_transient_for (GTK_WINDOW (msg_win),
275 gtk_widget_show_all (GTK_WIDGET (msg_win));
278 g_free (account_name);
281 g_object_unref (G_OBJECT(account));
283 g_object_unref (G_OBJECT(msg));
285 g_object_unref (G_OBJECT(folder));
290 modest_ui_actions_on_open (GtkAction *action, ModestWindow *win)
292 modest_runtime_not_implemented (GTK_WINDOW(win)); /* FIXME */
298 reply_forward_func (gpointer data, gpointer user_data)
300 TnyMsg *msg, *new_msg;
301 GetMsgAsyncHelper *helper;
302 ReplyForwardHelper *rf_helper;
303 ModestWindow *msg_win;
304 ModestEditType edit_type;
307 TnyFolder *folder = NULL;
308 TnyAccount *account = NULL;
310 msg = TNY_MSG (data);
311 helper = (GetMsgAsyncHelper *) user_data;
312 rf_helper = (ReplyForwardHelper *) helper->user_data;
314 from = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(),
315 rf_helper->account_name);
316 /* Create reply mail */
317 switch (rf_helper->action) {
320 modest_mail_operation_create_reply_mail (msg, from,
321 rf_helper->reply_forward_type,
322 MODEST_MAIL_OPERATION_REPLY_MODE_SENDER);
324 case ACTION_REPLY_TO_ALL:
326 modest_mail_operation_create_reply_mail (msg, from, rf_helper->reply_forward_type,
327 MODEST_MAIL_OPERATION_REPLY_MODE_ALL);
328 edit_type = MODEST_EDIT_TYPE_REPLY;
332 modest_mail_operation_create_forward_mail (msg, from, rf_helper->reply_forward_type);
333 edit_type = MODEST_EDIT_TYPE_FORWARD;
336 g_return_if_reached ();
341 g_printerr ("modest: failed to create message\n");
345 account = modest_tny_account_store_get_tny_account_by_account (modest_runtime_get_account_store(),
346 rf_helper->account_name,
347 TNY_ACCOUNT_TYPE_STORE);
349 g_printerr ("modest: failed to get tnyaccount for '%s'\n", rf_helper->account_name);
353 folder = modest_tny_account_get_special_folder (account, TNY_FOLDER_TYPE_DRAFTS);
355 g_printerr ("modest: failed to find Drafts folder\n");
359 tny_folder_add_msg (folder, msg, &err);
361 g_printerr ("modest: error adding msg to Drafts folder: %s",
367 /* Show edit window */
368 msg_win = modest_msg_edit_window_new (new_msg, rf_helper->account_name);
369 gtk_widget_show_all (GTK_WIDGET (msg_win));
373 g_object_unref (G_OBJECT (new_msg));
375 g_object_unref (G_OBJECT (folder));
377 g_object_unref (G_OBJECT (account));
379 g_free (rf_helper->account_name);
380 g_slice_free (ReplyForwardHelper, rf_helper);
383 * Common code for the reply and forward actions
386 reply_forward (ReplyForwardAction action, ModestWindow *win)
388 TnyList *header_list;
389 guint reply_forward_type;
392 GetMsgAsyncHelper *helper;
393 ReplyForwardHelper *rf_helper;
395 g_return_if_fail (MODEST_IS_WINDOW(win));
397 header_list = get_selected_headers (win);
401 reply_forward_type = modest_conf_get_int (modest_runtime_get_conf (),
402 (action == ACTION_FORWARD) ? MODEST_CONF_FORWARD_TYPE : MODEST_CONF_REPLY_TYPE,
404 /* We assume that we can only select messages of the
405 same folder and that we reply all of them from the
406 same account. In fact the interface currently only
407 allows single selection */
410 rf_helper = g_slice_new0 (ReplyForwardHelper);
411 rf_helper->reply_forward_type = reply_forward_type;
412 rf_helper->action = action;
414 rf_helper->account_name = g_strdup (modest_window_get_active_account (win));
415 if (!rf_helper->account_name)
416 rf_helper->account_name =
417 modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
419 helper = g_slice_new0 (GetMsgAsyncHelper);
420 helper->window = win;
421 helper->func = reply_forward_func;
422 helper->iter = tny_list_create_iterator (header_list);
423 helper->user_data = rf_helper;
425 if (MODEST_IS_MSG_VIEW_WINDOW(win)) {
427 msg = modest_msg_view_window_get_message(MODEST_MSG_VIEW_WINDOW(win));
429 g_printerr ("modest: no message found\n");
432 reply_forward_func (msg, helper);
434 header = TNY_HEADER (tny_iterator_get_current (helper->iter));
435 folder = tny_header_get_folder (header);
437 /* The callback will call it per each header */
438 tny_folder_get_msg_async (folder, header, get_msg_cb, helper);
439 g_object_unref (G_OBJECT (folder));
441 g_printerr ("modest: no folder for header\n");
444 g_object_unref (G_OBJECT (header));
450 modest_ui_actions_on_reply (GtkAction *action, ModestWindow *win)
452 g_return_if_fail (MODEST_IS_WINDOW(win));
454 reply_forward (ACTION_REPLY, win);
458 modest_ui_actions_on_forward (GtkAction *action, ModestWindow *win)
460 g_return_if_fail (MODEST_IS_WINDOW(win));
462 reply_forward (ACTION_FORWARD, win);
466 modest_ui_actions_on_reply_all (GtkAction *action, ModestWindow *win)
468 g_return_if_fail (MODEST_IS_WINDOW(win));
470 reply_forward (ACTION_REPLY_TO_ALL, win);
474 modest_ui_actions_on_next (GtkAction *action,
475 ModestMainWindow *main_window)
477 GtkWidget *header_view;
478 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
480 header_view = modest_main_window_get_child_widget (main_window,
481 MODEST_WIDGET_TYPE_HEADER_VIEW);
485 modest_header_view_select_next (MODEST_HEADER_VIEW(header_view));
489 modest_ui_actions_on_prev (GtkAction *action,
490 ModestMainWindow *main_window)
492 GtkWidget *header_view;
493 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
495 header_view = modest_main_window_get_child_widget (main_window,
496 MODEST_WIDGET_TYPE_HEADER_VIEW);
500 modest_header_view_select_prev (MODEST_HEADER_VIEW(header_view));
505 modest_ui_actions_on_send_receive (GtkAction *action, ModestWindow *win)
508 TnyAccount *tny_account;
509 //ModestTnySendQueue *send_queue;
510 ModestMailOperation *mail_op;
513 g_strdup(modest_window_get_active_account(MODEST_WINDOW(win)));
515 account_name = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
517 g_printerr ("modest: cannot get account\n");
523 modest_tny_account_store_get_tny_account_by_account (modest_runtime_get_account_store(),
525 TNY_ACCOUNT_TYPE_TRANSPORT);
527 g_printerr ("modest: cannot get tny transport account for %s\n", account_name);
531 send_queue = modest_tny_send_queue_new (TNY_CAMEL_TRANSPORT_ACCOUNT(tny_account));
533 g_object_unref (G_OBJECT(tny_account));
534 g_printerr ("modest: cannot get send queue for %s\n", account_name);
537 modest_tny_send_queue_flush (send_queue);
539 g_object_unref (G_OBJECT(send_queue));
540 g_object_unref (G_OBJECT(tny_account));
543 modest_tny_account_store_get_tny_account_by_account (modest_runtime_get_account_store(),
545 TNY_ACCOUNT_TYPE_STORE);
547 g_printerr ("modest: cannot get tny store account for %s\n", account_name);
551 mail_op = modest_mail_operation_new ();
552 modest_mail_operation_update_account (mail_op, TNY_STORE_ACCOUNT(tny_account));
554 g_object_unref (G_OBJECT(tny_account));
555 /* g_object_unref (G_OBJECT(mail_op)); FIXME: this is still in use... */
561 modest_ui_actions_toggle_view (GtkAction *action, ModestMainWindow *main_window)
564 GtkWidget *header_view;
566 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
568 header_view = modest_main_window_get_child_widget (main_window,
569 MODEST_WIDGET_TYPE_HEADER_VIEW);
573 conf = modest_runtime_get_conf ();
575 /* what is saved/restored is depending on the style; thus; we save with
576 * old style, then update the style, and restore for this new style*/
577 modest_widget_memory_save (conf, G_OBJECT(header_view), "header-view");
579 if (modest_header_view_get_style
580 (MODEST_HEADER_VIEW(header_view)) == MODEST_HEADER_VIEW_STYLE_DETAILS)
581 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
582 MODEST_HEADER_VIEW_STYLE_TWOLINES);
584 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
585 MODEST_HEADER_VIEW_STYLE_DETAILS);
587 modest_widget_memory_restore (conf, G_OBJECT(header_view),
594 * Marks a message as read and passes it to the msg preview widget
597 read_msg_func (gpointer data, gpointer user_data)
601 GetMsgAsyncHelper *helper;
602 TnyHeaderFlags header_flags;
603 GtkWidget *msg_preview;
605 msg = TNY_MSG (data);
606 helper = (GetMsgAsyncHelper *) user_data;
608 msg_preview = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (helper->window),
609 MODEST_WIDGET_TYPE_MSG_PREVIEW);
613 header = TNY_HEADER (tny_iterator_get_current (helper->iter));
614 header_flags = tny_header_get_flags (header);
615 tny_header_set_flags (header, header_flags | TNY_HEADER_FLAG_SEEN);
616 g_object_unref (G_OBJECT (header));
618 /* Set message on msg view */
619 modest_msg_view_set_message (MODEST_MSG_VIEW(msg_preview), msg);
623 * This function is a generic handler for the tny_folder_get_msg_async
624 * call. It expects as user_data a #GetMsgAsyncHelper. This helper
625 * contains a user provided function that is called inside this
626 * method. This will allow us to use this callback in many different
627 * places. This callback performs the common actions for the
628 * get_msg_async call, more specific actions will be done by the user
632 get_msg_cb (TnyFolder *folder, TnyMsg *msg, GError **err, gpointer user_data)
634 GetMsgAsyncHelper *helper;
636 helper = (GetMsgAsyncHelper *) user_data;
638 if ((*err && ((*err)->code == TNY_FOLDER_ERROR_GET_MSG)) || !msg) {
639 modest_ui_actions_on_item_not_found (NULL,
640 MODEST_ITEM_TYPE_MESSAGE,
645 /* Call user function */
646 helper->func (msg, user_data);
648 /* Process next element (if exists) */
649 tny_iterator_next (helper->iter);
650 if (tny_iterator_is_done (helper->iter)) {
652 headers = tny_iterator_get_list (helper->iter);
654 g_object_unref (G_OBJECT (headers));
655 g_object_unref (G_OBJECT (helper->iter));
656 g_slice_free (GetMsgAsyncHelper, helper);
659 header = TNY_HEADER (tny_iterator_get_current (helper->iter));
660 tny_folder_get_msg_async (folder, header,
662 g_object_unref (G_OBJECT(header));
667 modest_ui_actions_on_header_selected (ModestHeaderView *folder_view,
669 ModestMainWindow *main_window)
671 GtkWidget *msg_preview;
673 GetMsgAsyncHelper *helper;
676 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
678 msg_preview = modest_main_window_get_child_widget(main_window,
679 MODEST_WIDGET_TYPE_MSG_PREVIEW);
683 /* when there's no header, clear the msgview */
685 modest_msg_view_set_message (MODEST_MSG_VIEW(msg_preview), NULL);
689 folder = tny_header_get_folder (TNY_HEADER(header));
692 list = tny_simple_list_new ();
693 tny_list_prepend (list, G_OBJECT (header));
695 /* Fill helper data */
696 helper = g_slice_new0 (GetMsgAsyncHelper);
697 helper->window = MODEST_WINDOW (main_window);
698 helper->iter = tny_list_create_iterator (list);
699 helper->func = read_msg_func;
701 tny_folder_get_msg_async (TNY_FOLDER(folder),
706 g_object_unref (G_OBJECT (folder));
712 modest_ui_actions_on_header_activated (ModestHeaderView *folder_view, TnyHeader *header,
713 ModestMainWindow *main_window)
716 TnyFolder *folder = NULL;
718 gchar *account = NULL;
720 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
725 folder = tny_header_get_folder (header);
727 g_printerr ("modest: cannot get folder for header\n");
731 /* FIXME: make async?; check error */
732 msg = tny_folder_get_msg (folder, header, NULL);
734 g_printerr ("modest: cannot get msg for header\n");
738 account = g_strdup(modest_window_get_active_account(MODEST_WINDOW(main_window)));
740 account = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
742 win = modest_msg_view_window_new (msg, account);
743 gtk_window_set_transient_for (GTK_WINDOW (win),
744 GTK_WINDOW (main_window));
746 gtk_widget_show_all (GTK_WIDGET(win));
752 g_object_unref (G_OBJECT (folder));
754 g_object_unref (G_OBJECT (msg));
758 modest_ui_actions_on_folder_selection_changed (ModestFolderView *folder_view,
761 ModestMainWindow *main_window)
763 // GtkLabel *folder_info_label;
766 GtkWidget *header_view;
768 /* folder_info_label = */
769 /* GTK_LABEL (modest_widget_factory_get_folder_info_label */
770 /* (modest_runtime_get_widget_factory())); */
773 /* gtk_label_set_label (GTK_LABEL(folder_info_label), ""); */
777 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
779 header_view = modest_main_window_get_child_widget(main_window,
780 MODEST_WIDGET_TYPE_HEADER_VIEW);
784 conf = modest_runtime_get_conf ();
786 if (!selected) { /* the folder was unselected; save it's settings */
787 modest_widget_memory_save (conf, G_OBJECT (header_view), "header-view");
788 gtk_window_set_title (GTK_WINDOW(main_window), "Modest");
789 modest_header_view_set_folder (MODEST_HEADER_VIEW(header_view), NULL);
790 } else { /* the folder was selected */
791 if (folder) { /* folder may be NULL */
795 num = tny_folder_get_all_count (folder);
796 unread = tny_folder_get_unread_count (folder);
798 title = g_strdup_printf ("Modest: %s",
799 tny_folder_get_name (folder));
801 gtk_window_set_title (GTK_WINDOW(main_window), title);
804 txt = g_strdup_printf (_("%d %s, %d unread"),
805 num, num==1 ? _("item") : _("items"), unread);
806 //gtk_label_set_label (GTK_LABEL(folder_info_label), txt);
809 modest_header_view_set_folder (MODEST_HEADER_VIEW(header_view), folder);
810 modest_widget_memory_restore (conf, G_OBJECT(header_view),
816 /****************************************************/
818 * below some stuff to clearup statusbar messages after 1,5 seconds....
821 progress_bar_clean (GtkWidget *bar)
823 if (GTK_IS_PROGRESS_BAR(bar)) {
824 gtk_progress_bar_set_text (GTK_PROGRESS_BAR(bar), "");
825 gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(bar), 1.0);
831 statusbar_clean (GtkWidget *bar)
833 if (GTK_IS_STATUSBAR(bar))
834 gtk_statusbar_push (GTK_STATUSBAR(bar), 0, "");
840 statusbar_push (ModestMainWindow *main_window, guint context_id, const gchar *msg)
845 GtkWidget *progress_bar, *status_bar;
847 progress_bar = modest_main_window_get_child_widget (main_window,
848 MODEST_WIDGET_TYPE_PROGRESS_BAR);
849 status_bar = modest_main_window_get_child_widget (main_window,
850 MODEST_WIDGET_TYPE_STATUS_BAR);
852 gtk_widget_show (progress_bar);
853 g_timeout_add (3000, (GSourceFunc)progress_bar_clean, progress_bar);
857 gtk_widget_show (status_bar);
858 gtk_statusbar_push (GTK_STATUSBAR(status_bar), 0, msg);
859 g_timeout_add (2500, (GSourceFunc)statusbar_clean, status_bar);
863 /****************************************************************************/
866 modest_ui_actions_on_item_not_found (ModestHeaderView *header_view,ModestItemType type,
873 item = (type == MODEST_ITEM_TYPE_FOLDER) ? "folder" : "message";
875 if (g_main_depth > 0)
876 gdk_threads_enter ();
877 online = tny_device_is_online (modest_runtime_get_device());
880 /* already online -- the item is simply not there... */
881 dialog = gtk_message_dialog_new (GTK_WINDOW (win),
885 _("The %s you selected cannot be found"),
887 gtk_dialog_run (GTK_DIALOG(dialog));
889 dialog = gtk_dialog_new_with_buttons (_("Connection requested"),
897 txt = g_strdup_printf (_("This %s is not available in offline mode.\n"
898 "Do you want to get online?"), item);
899 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
900 gtk_label_new (txt), FALSE, FALSE, 0);
901 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
904 gtk_window_set_default_size (GTK_WINDOW(dialog), 300, 300);
905 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
906 tny_device_force_online (modest_runtime_get_device());
909 gtk_widget_destroy (dialog);
910 if (g_main_depth > 0)
911 gdk_threads_leave ();
917 modest_ui_actions_on_header_status_update (ModestHeaderView *header_view,
918 const gchar *msg, gint num,
919 gint total, ModestMainWindow *main_window)
922 GtkWidget *progress_bar;
924 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
926 progress_bar = modest_main_window_get_child_widget (main_window,
927 MODEST_WIDGET_TYPE_PROGRESS_BAR);
932 gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(progress_bar),
933 (gdouble)num/(gdouble)total);
935 gtk_progress_bar_pulse (GTK_PROGRESS_BAR(progress_bar));
937 txt = g_strdup_printf (_("Downloading %d of %d"), num, total);
938 gtk_progress_bar_set_text (GTK_PROGRESS_BAR(progress_bar), txt);
941 statusbar_push (main_window, 0, msg);
946 modest_ui_actions_on_msg_link_hover (ModestMsgView *msgview, const gchar* link,
949 g_message (__FUNCTION__);
954 modest_ui_actions_on_msg_link_clicked (ModestMsgView *msgview, const gchar* link,
957 g_message (__FUNCTION__);
961 modest_ui_actions_on_msg_attachment_clicked (ModestMsgView *msgview, int index,
964 g_message (__FUNCTION__);
969 modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
971 TnyTransportAccount *transport_account;
972 ModestMailOperation *mail_operation;
974 gchar *account_name, *from;
975 ModestAccountMgr *account_mgr;
977 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window));
979 data = modest_msg_edit_window_get_msg_data (edit_window);
981 /* FIXME: Code added just for testing. The final version will
982 use the send queue provided by tinymail and some
984 account_mgr = modest_runtime_get_account_mgr();
985 account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
987 account_name = modest_account_mgr_get_default_account (account_mgr);
989 g_printerr ("modest: no account found\n");
990 modest_msg_edit_window_free_msg_data (edit_window, data);
994 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_tny_account_by_account
995 (modest_runtime_get_account_store(),
997 TNY_ACCOUNT_TYPE_TRANSPORT));
998 if (!transport_account) {
999 g_printerr ("modest: no transport account found for '%s'\n", account_name);
1000 g_free (account_name);
1001 modest_msg_edit_window_free_msg_data (edit_window, data);
1004 from = modest_account_mgr_get_from_string (account_mgr, account_name);
1006 mail_operation = modest_mail_operation_new ();
1007 modest_mail_operation_send_new_mail (mail_operation,
1018 g_free (account_name);
1019 g_object_unref (G_OBJECT (mail_operation));
1020 g_object_unref (G_OBJECT (transport_account));
1022 modest_msg_edit_window_free_msg_data (edit_window, data);
1024 /* Save settings and close the window */
1025 /* save_settings (edit_window) */
1026 gtk_widget_destroy (GTK_WIDGET (edit_window));
1030 * Shows a dialog with an entry that asks for some text. The returned
1031 * value must be freed by the caller. The dialog window title will be
1035 ask_for_folder_name (GtkWindow *parent_window,
1038 GtkWidget *dialog, *entry;
1039 gchar *folder_name = NULL;
1041 /* Ask for folder name */
1042 dialog = gtk_dialog_new_with_buttons (_("New Folder Name"),
1046 GTK_RESPONSE_REJECT,
1048 GTK_RESPONSE_ACCEPT,
1050 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
1051 gtk_label_new(title),
1054 entry = gtk_entry_new_with_max_length (40);
1055 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
1059 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
1061 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
1062 folder_name = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry)));
1064 gtk_widget_destroy (dialog);
1070 modest_ui_actions_on_new_folder (GtkAction *action, ModestMainWindow *main_window)
1072 TnyFolder *parent_folder;
1073 GtkWidget *folder_view;
1075 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1077 folder_view = modest_main_window_get_child_widget (main_window,
1078 MODEST_WIDGET_TYPE_FOLDER_VIEW);
1082 parent_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
1084 if (parent_folder) {
1087 folder_name = ask_for_folder_name (GTK_WINDOW (main_window),
1088 _("Please enter a name for the new folder"));
1090 if (folder_name != NULL && strlen (folder_name) > 0) {
1091 TnyFolder *new_folder;
1092 ModestMailOperation *mail_op;
1094 mail_op = modest_mail_operation_new ();
1095 new_folder = modest_mail_operation_create_folder (mail_op,
1096 TNY_FOLDER_STORE (parent_folder),
1097 (const gchar *) folder_name);
1099 g_object_unref (new_folder);
1101 const GError *error;
1102 error = modest_mail_operation_get_error (mail_op);
1104 g_warning ("Error adding a subfolder: %s\n", error->message);
1106 g_object_unref (mail_op);
1108 g_object_unref (parent_folder);
1113 modest_ui_actions_on_rename_folder (GtkAction *action,
1114 ModestMainWindow *main_window)
1117 GtkWidget *folder_view;
1119 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1121 folder_view = modest_main_window_get_child_widget (main_window,
1122 MODEST_WIDGET_TYPE_FOLDER_VIEW);
1126 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
1130 folder_name = ask_for_folder_name (GTK_WINDOW (main_window),
1131 _("Please enter a new name for the folder"));
1133 if (folder_name != NULL && strlen (folder_name) > 0) {
1134 ModestMailOperation *mail_op;
1135 const GError *error;
1137 mail_op = modest_mail_operation_new ();
1138 modest_mail_operation_rename_folder (mail_op,
1140 (const gchar *) folder_name);
1142 error = modest_mail_operation_get_error (mail_op);
1144 /* TODO: notify error ? */
1145 g_warning ("Could not rename a folder: %s\n", error->message);
1147 g_object_unref (mail_op);
1149 g_object_unref (folder);
1154 delete_folder (ModestMainWindow *main_window, gboolean move_to_trash)
1157 ModestMailOperation *mail_op;
1158 GtkWidget *folder_view;
1159 const GError *error;
1161 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1163 folder_view = modest_main_window_get_child_widget (main_window,
1164 MODEST_WIDGET_TYPE_FOLDER_VIEW);
1168 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
1170 mail_op = modest_mail_operation_new ();
1171 modest_mail_operation_remove_folder (mail_op, folder, move_to_trash);
1173 error = modest_mail_operation_get_error (mail_op);
1175 g_warning ("%s\n", error->message);
1177 g_object_unref (mail_op);
1181 modest_ui_actions_on_delete_folder (GtkAction *action,
1182 ModestMainWindow *main_window)
1184 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1186 delete_folder (main_window, FALSE);
1190 modest_ui_actions_on_move_folder_to_trash_folder (GtkAction *action, ModestMainWindow *main_window)
1192 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1194 delete_folder (main_window, TRUE);
1198 modest_ui_actions_on_password_requested (TnyAccountStore *account_store,
1199 const gchar* account_name,
1203 ModestMainWindow *main_window)
1206 GtkWidget *dialog, *entry, *remember_pass_check;
1208 dialog = gtk_dialog_new_with_buttons (_("Password requested"),
1212 GTK_RESPONSE_REJECT,
1214 GTK_RESPONSE_ACCEPT,
1216 gtk_window_set_transient_for (GTK_WINDOW(dialog), GTK_WINDOW(main_window));
1218 txt = g_strdup_printf (_("Please enter your password for %s"), account_name);
1219 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), gtk_label_new(txt),
1223 entry = gtk_entry_new_with_max_length (40);
1224 gtk_entry_set_visibility (GTK_ENTRY(entry), FALSE);
1225 gtk_entry_set_invisible_char (GTK_ENTRY(entry), 0x2022); /* bullet unichar */
1227 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry,
1230 remember_pass_check = gtk_check_button_new_with_label (_("Remember password"));
1231 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), remember_pass_check,
1234 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
1236 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
1237 *password = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry)));
1244 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (remember_pass_check)))
1249 gtk_widget_destroy (dialog);