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 mail_op = modest_mail_operation_new ();
163 /* TODO: add confirmation dialog */
165 /* Move to trash. TODO: Still not supported */
166 modest_mail_operation_remove_msg (mail_op, header, FALSE);
168 if (modest_mail_operation_get_status (mail_op) !=
169 MODEST_MAIL_OPERATION_STATUS_SUCCESS) {
171 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 (GtkAction *action, 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_add_to_contacts (GtkAction *action, ModestWindow *win)
196 GtkClipboard *clipboard = NULL;
197 gchar *selection = NULL;
199 clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
200 selection = gtk_clipboard_wait_for_text (clipboard);
202 modest_address_book_add_address (selection);
207 modest_ui_actions_on_accounts (GtkAction *action, ModestWindow *win)
209 /* GtkDialog *account_win; */
210 /* account_win = GTK_DIALOG(modest_account_view_window_new ()); */
213 /* gtk_dialog_run (account_win); */
214 //gtk_widget_destroy (GTK_WIDGET(account_win));
215 GtkWidget *dialog, *label;
217 /* Create the widgets */
219 dialog = gtk_dialog_new_with_buttons ("Message",
221 GTK_DIALOG_DESTROY_WITH_PARENT,
225 label = gtk_label_new ("Hello World!");
227 /* Ensure that the dialog box is destroyed when the user responds. */
229 g_signal_connect_swapped (dialog, "response",
230 G_CALLBACK (gtk_widget_destroy),
233 /* Add the label, and show everything we've added to the dialog. */
235 gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox),
237 gtk_widget_show_all (dialog);
241 modest_ui_actions_on_new_msg (GtkAction *action, ModestWindow *win)
243 ModestWindow *msg_win;
245 TnyFolder *folder = NULL;
246 gchar *account_name = NULL;
247 gchar *from_str = NULL;
251 account_name = g_strdup(modest_window_get_active_account (win));
253 account_name = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
255 account = modest_tny_account_store_get_tny_account_by_account (modest_runtime_get_account_store(),
257 TNY_ACCOUNT_TYPE_STORE);
259 g_printerr ("modest: failed to get tnyaccount for '%s'\n", account_name);
263 from_str = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(), account_name);
265 msg = modest_tny_msg_new ("", from_str, "", "", "", "", NULL);
267 g_printerr ("modest: failed to create new msg\n");
271 folder = modest_tny_account_get_special_folder (account, TNY_FOLDER_TYPE_DRAFTS);
273 g_printerr ("modest: failed to find Drafts folder\n");
277 tny_folder_add_msg (folder, msg, &err);
279 g_printerr ("modest: error adding msg to Drafts folder: %s",
285 msg_win = modest_msg_edit_window_new (msg, account_name);
287 gtk_window_set_transient_for (GTK_WINDOW (msg_win),
289 gtk_widget_show_all (GTK_WIDGET (msg_win));
292 g_free (account_name);
295 g_object_unref (G_OBJECT(account));
297 g_object_unref (G_OBJECT(msg));
299 g_object_unref (G_OBJECT(folder));
304 modest_ui_actions_on_open (GtkAction *action, ModestWindow *win)
306 modest_runtime_not_implemented (GTK_WINDOW(win)); /* FIXME */
312 reply_forward_func (gpointer data, gpointer user_data)
314 TnyMsg *msg, *new_msg;
315 GetMsgAsyncHelper *helper;
316 ReplyForwardHelper *rf_helper;
317 ModestWindow *msg_win;
318 ModestEditType edit_type;
321 TnyFolder *folder = NULL;
322 TnyAccount *account = NULL;
324 msg = TNY_MSG (data);
325 helper = (GetMsgAsyncHelper *) user_data;
326 rf_helper = (ReplyForwardHelper *) helper->user_data;
328 from = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(),
329 rf_helper->account_name);
330 /* Create reply mail */
331 switch (rf_helper->action) {
334 modest_tny_msg_create_reply_msg (msg, from,
335 rf_helper->reply_forward_type,
336 MODEST_TNY_MSG_REPLY_MODE_SENDER);
338 case ACTION_REPLY_TO_ALL:
340 modest_tny_msg_create_reply_msg (msg, from, rf_helper->reply_forward_type,
341 MODEST_TNY_MSG_REPLY_MODE_ALL);
342 edit_type = MODEST_EDIT_TYPE_REPLY;
346 modest_tny_msg_create_forward_msg (msg, from, rf_helper->reply_forward_type);
347 edit_type = MODEST_EDIT_TYPE_FORWARD;
350 g_return_if_reached ();
355 g_printerr ("modest: failed to create message\n");
359 account = modest_tny_account_store_get_tny_account_by_account (modest_runtime_get_account_store(),
360 rf_helper->account_name,
361 TNY_ACCOUNT_TYPE_STORE);
363 g_printerr ("modest: failed to get tnyaccount for '%s'\n", rf_helper->account_name);
367 folder = modest_tny_account_get_special_folder (account, TNY_FOLDER_TYPE_DRAFTS);
369 g_printerr ("modest: failed to find Drafts folder\n");
373 tny_folder_add_msg (folder, msg, &err);
375 g_printerr ("modest: error adding msg to Drafts folder: %s",
381 /* Show edit window */
382 msg_win = modest_msg_edit_window_new (new_msg, rf_helper->account_name);
383 gtk_widget_show_all (GTK_WIDGET (msg_win));
387 g_object_unref (G_OBJECT (new_msg));
389 g_object_unref (G_OBJECT (folder));
391 g_object_unref (G_OBJECT (account));
393 g_free (rf_helper->account_name);
394 g_slice_free (ReplyForwardHelper, rf_helper);
397 * Common code for the reply and forward actions
400 reply_forward (ReplyForwardAction action, ModestWindow *win)
402 TnyList *header_list;
403 guint reply_forward_type;
406 GetMsgAsyncHelper *helper;
407 ReplyForwardHelper *rf_helper;
409 g_return_if_fail (MODEST_IS_WINDOW(win));
411 header_list = get_selected_headers (win);
415 reply_forward_type = modest_conf_get_int (modest_runtime_get_conf (),
416 (action == ACTION_FORWARD) ? MODEST_CONF_FORWARD_TYPE : MODEST_CONF_REPLY_TYPE,
418 /* We assume that we can only select messages of the
419 same folder and that we reply all of them from the
420 same account. In fact the interface currently only
421 allows single selection */
424 rf_helper = g_slice_new0 (ReplyForwardHelper);
425 rf_helper->reply_forward_type = reply_forward_type;
426 rf_helper->action = action;
428 rf_helper->account_name = g_strdup (modest_window_get_active_account (win));
429 if (!rf_helper->account_name)
430 rf_helper->account_name =
431 modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
433 helper = g_slice_new0 (GetMsgAsyncHelper);
434 helper->window = win;
435 helper->func = reply_forward_func;
436 helper->iter = tny_list_create_iterator (header_list);
437 helper->user_data = rf_helper;
439 if (MODEST_IS_MSG_VIEW_WINDOW(win)) {
441 msg = modest_msg_view_window_get_message(MODEST_MSG_VIEW_WINDOW(win));
443 g_printerr ("modest: no message found\n");
446 reply_forward_func (msg, helper);
448 header = TNY_HEADER (tny_iterator_get_current (helper->iter));
449 folder = tny_header_get_folder (header);
451 /* The callback will call it per each header */
452 tny_folder_get_msg_async (folder, header, get_msg_cb, helper);
453 g_object_unref (G_OBJECT (folder));
455 g_printerr ("modest: no folder for header\n");
458 g_object_unref (G_OBJECT (header));
464 modest_ui_actions_on_reply (GtkAction *action, ModestWindow *win)
466 g_return_if_fail (MODEST_IS_WINDOW(win));
468 reply_forward (ACTION_REPLY, win);
472 modest_ui_actions_on_forward (GtkAction *action, ModestWindow *win)
474 g_return_if_fail (MODEST_IS_WINDOW(win));
476 reply_forward (ACTION_FORWARD, win);
480 modest_ui_actions_on_reply_all (GtkAction *action, ModestWindow *win)
482 g_return_if_fail (MODEST_IS_WINDOW(win));
484 reply_forward (ACTION_REPLY_TO_ALL, win);
488 modest_ui_actions_on_next (GtkAction *action,
489 ModestMainWindow *main_window)
491 GtkWidget *header_view;
492 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
494 header_view = modest_main_window_get_child_widget (main_window,
495 MODEST_WIDGET_TYPE_HEADER_VIEW);
499 modest_header_view_select_next (MODEST_HEADER_VIEW(header_view));
503 modest_ui_actions_on_prev (GtkAction *action,
504 ModestMainWindow *main_window)
506 GtkWidget *header_view;
507 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
509 header_view = modest_main_window_get_child_widget (main_window,
510 MODEST_WIDGET_TYPE_HEADER_VIEW);
514 modest_header_view_select_prev (MODEST_HEADER_VIEW(header_view));
519 modest_ui_actions_on_send_receive (GtkAction *action, ModestWindow *win)
522 TnyAccount *tny_account;
523 ModestTnySendQueue *send_queue;
524 ModestMailOperation *mail_op;
527 g_strdup(modest_window_get_active_account(MODEST_WINDOW(win)));
529 account_name = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
531 g_printerr ("modest: cannot get account\n");
536 modest_tny_account_store_get_tny_account_by_account (modest_runtime_get_account_store(),
538 TNY_ACCOUNT_TYPE_TRANSPORT);
540 g_printerr ("modest: cannot get tny transport account for %s\n", account_name);
543 send_queue = modest_tny_send_queue_new (TNY_CAMEL_TRANSPORT_ACCOUNT(tny_account));
545 g_object_unref (G_OBJECT(tny_account));
546 g_printerr ("modest: cannot get send queue for %s\n", account_name);
549 //modest_tny_send_queue_flush (send_queue);
551 g_object_unref (G_OBJECT(send_queue));
552 g_object_unref (G_OBJECT(tny_account));
555 modest_tny_account_store_get_tny_account_by_account (modest_runtime_get_account_store(),
557 TNY_ACCOUNT_TYPE_STORE);
559 g_printerr ("modest: cannot get tny store account for %s\n", account_name);
563 mail_op = modest_mail_operation_new ();
564 modest_mail_operation_update_account (mail_op, TNY_STORE_ACCOUNT(tny_account));
566 g_object_unref (G_OBJECT(tny_account));
567 /* g_object_unref (G_OBJECT(mail_op)); FIXME: this is still in use... */
573 modest_ui_actions_toggle_view (GtkAction *action, ModestMainWindow *main_window)
576 GtkWidget *header_view;
578 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
580 header_view = modest_main_window_get_child_widget (main_window,
581 MODEST_WIDGET_TYPE_HEADER_VIEW);
585 conf = modest_runtime_get_conf ();
587 /* what is saved/restored is depending on the style; thus; we save with
588 * old style, then update the style, and restore for this new style*/
589 modest_widget_memory_save (conf, G_OBJECT(header_view), "header-view");
591 if (modest_header_view_get_style
592 (MODEST_HEADER_VIEW(header_view)) == MODEST_HEADER_VIEW_STYLE_DETAILS)
593 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
594 MODEST_HEADER_VIEW_STYLE_TWOLINES);
596 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
597 MODEST_HEADER_VIEW_STYLE_DETAILS);
599 modest_widget_memory_restore (conf, G_OBJECT(header_view),
606 * Marks a message as read and passes it to the msg preview widget
609 read_msg_func (gpointer data, gpointer user_data)
613 GetMsgAsyncHelper *helper;
614 TnyHeaderFlags header_flags;
615 GtkWidget *msg_preview;
617 msg = TNY_MSG (data);
618 helper = (GetMsgAsyncHelper *) user_data;
620 msg_preview = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (helper->window),
621 MODEST_WIDGET_TYPE_MSG_PREVIEW);
625 header = TNY_HEADER (tny_iterator_get_current (helper->iter));
626 header_flags = tny_header_get_flags (header);
627 tny_header_set_flags (header, header_flags | TNY_HEADER_FLAG_SEEN);
628 g_object_unref (G_OBJECT (header));
630 /* Set message on msg view */
631 modest_msg_view_set_message (MODEST_MSG_VIEW(msg_preview), msg);
635 * This function is a generic handler for the tny_folder_get_msg_async
636 * call. It expects as user_data a #GetMsgAsyncHelper. This helper
637 * contains a user provided function that is called inside this
638 * method. This will allow us to use this callback in many different
639 * places. This callback performs the common actions for the
640 * get_msg_async call, more specific actions will be done by the user
644 get_msg_cb (TnyFolder *folder, TnyMsg *msg, GError **err, gpointer user_data)
646 GetMsgAsyncHelper *helper;
648 helper = (GetMsgAsyncHelper *) user_data;
650 if ((*err && ((*err)->code == TNY_FOLDER_ERROR_GET_MSG)) || !msg) {
651 modest_ui_actions_on_item_not_found (NULL,
652 MODEST_ITEM_TYPE_MESSAGE,
657 /* Call user function */
658 helper->func (msg, user_data);
660 /* Process next element (if exists) */
661 tny_iterator_next (helper->iter);
662 if (tny_iterator_is_done (helper->iter)) {
664 headers = tny_iterator_get_list (helper->iter);
666 g_object_unref (G_OBJECT (headers));
667 g_object_unref (G_OBJECT (helper->iter));
668 g_slice_free (GetMsgAsyncHelper, helper);
671 header = TNY_HEADER (tny_iterator_get_current (helper->iter));
672 tny_folder_get_msg_async (folder, header,
674 g_object_unref (G_OBJECT(header));
679 modest_ui_actions_on_header_selected (ModestHeaderView *folder_view,
681 ModestMainWindow *main_window)
683 GtkWidget *msg_preview;
685 GetMsgAsyncHelper *helper;
688 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
690 msg_preview = modest_main_window_get_child_widget(main_window,
691 MODEST_WIDGET_TYPE_MSG_PREVIEW);
695 /* when there's no header, clear the msgview */
697 modest_msg_view_set_message (MODEST_MSG_VIEW(msg_preview), NULL);
701 folder = tny_header_get_folder (TNY_HEADER(header));
704 list = tny_simple_list_new ();
705 tny_list_prepend (list, G_OBJECT (header));
707 /* Fill helper data */
708 helper = g_slice_new0 (GetMsgAsyncHelper);
709 helper->window = MODEST_WINDOW (main_window);
710 helper->iter = tny_list_create_iterator (list);
711 helper->func = read_msg_func;
713 tny_folder_get_msg_async (TNY_FOLDER(folder),
718 g_object_unref (G_OBJECT (folder));
724 modest_ui_actions_on_header_activated (ModestHeaderView *folder_view, TnyHeader *header,
725 ModestMainWindow *main_window)
728 TnyFolder *folder = NULL;
730 gchar *account = NULL;
732 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
737 folder = tny_header_get_folder (header);
739 g_printerr ("modest: cannot get folder for header\n");
743 /* FIXME: make async?; check error */
744 msg = tny_folder_get_msg (folder, header, NULL);
746 g_printerr ("modest: cannot get msg for header\n");
750 account = g_strdup(modest_window_get_active_account(MODEST_WINDOW(main_window)));
752 account = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
754 win = modest_msg_view_window_new (msg, account);
755 gtk_window_set_transient_for (GTK_WINDOW (win),
756 GTK_WINDOW (main_window));
758 gtk_widget_show_all (GTK_WIDGET(win));
764 g_object_unref (G_OBJECT (folder));
766 g_object_unref (G_OBJECT (msg));
770 modest_ui_actions_on_folder_selection_changed (ModestFolderView *folder_view,
773 ModestMainWindow *main_window)
777 GtkWidget *header_view;
779 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
781 header_view = modest_main_window_get_child_widget(main_window,
782 MODEST_WIDGET_TYPE_HEADER_VIEW);
786 conf = modest_runtime_get_conf ();
788 if (!selected) { /* the folder was unselected; save it's settings */
789 modest_widget_memory_save (conf, G_OBJECT (header_view), "header-view");
790 gtk_window_set_title (GTK_WINDOW(main_window), "Modest");
791 modest_header_view_set_folder (MODEST_HEADER_VIEW(header_view), NULL);
792 } else { /* the folder was selected */
793 if (folder) { /* folder may be NULL */
797 num = tny_folder_get_all_count (folder);
798 unread = tny_folder_get_unread_count (folder);
800 title = g_strdup_printf ("Modest: %s",
801 tny_folder_get_name (folder));
803 gtk_window_set_title (GTK_WINDOW(main_window), title);
806 txt = g_strdup_printf (_("%d %s, %d unread"),
807 num, num==1 ? _("item") : _("items"), unread);
808 //gtk_label_set_label (GTK_LABEL(folder_info_label), txt);
811 modest_header_view_set_folder (MODEST_HEADER_VIEW(header_view), folder);
812 modest_widget_memory_restore (conf, G_OBJECT(header_view),
818 /****************************************************/
820 * below some stuff to clearup statusbar messages after 1,5 seconds....
823 progress_bar_clean (GtkWidget *bar)
825 if (GTK_IS_PROGRESS_BAR(bar)) {
826 gtk_progress_bar_set_text (GTK_PROGRESS_BAR(bar), "");
827 gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(bar), 1.0);
833 statusbar_clean (GtkWidget *bar)
835 if (GTK_IS_STATUSBAR(bar))
836 gtk_statusbar_push (GTK_STATUSBAR(bar), 0, "");
842 statusbar_push (ModestMainWindow *main_window, guint context_id, const gchar *msg)
847 GtkWidget *progress_bar, *status_bar;
849 progress_bar = modest_main_window_get_child_widget (main_window,
850 MODEST_WIDGET_TYPE_PROGRESS_BAR);
851 status_bar = modest_main_window_get_child_widget (main_window,
852 MODEST_WIDGET_TYPE_STATUS_BAR);
854 gtk_widget_show (progress_bar);
855 g_timeout_add (3000, (GSourceFunc)progress_bar_clean, progress_bar);
859 gtk_widget_show (status_bar);
860 gtk_statusbar_push (GTK_STATUSBAR(status_bar), 0, msg);
861 g_timeout_add (2500, (GSourceFunc)statusbar_clean, status_bar);
865 /****************************************************************************/
868 modest_ui_actions_on_item_not_found (ModestHeaderView *header_view,ModestItemType type,
875 item = (type == MODEST_ITEM_TYPE_FOLDER) ? "folder" : "message";
877 if (g_main_depth > 0)
878 gdk_threads_enter ();
879 online = tny_device_is_online (modest_runtime_get_device());
882 /* already online -- the item is simply not there... */
883 dialog = gtk_message_dialog_new (GTK_WINDOW (win),
887 _("The %s you selected cannot be found"),
889 gtk_dialog_run (GTK_DIALOG(dialog));
891 dialog = gtk_dialog_new_with_buttons (_("Connection requested"),
899 txt = g_strdup_printf (_("This %s is not available in offline mode.\n"
900 "Do you want to get online?"), item);
901 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
902 gtk_label_new (txt), FALSE, FALSE, 0);
903 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
906 gtk_window_set_default_size (GTK_WINDOW(dialog), 300, 300);
907 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
908 // tny_device_force_online (modest_runtime_get_device());
911 gtk_widget_destroy (dialog);
912 if (g_main_depth > 0)
913 gdk_threads_leave ();
919 modest_ui_actions_on_header_status_update (ModestHeaderView *header_view,
920 const gchar *msg, gint num,
921 gint total, ModestMainWindow *main_window)
924 GtkWidget *progress_bar;
926 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
928 progress_bar = modest_main_window_get_child_widget (main_window,
929 MODEST_WIDGET_TYPE_PROGRESS_BAR);
934 gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(progress_bar),
935 (gdouble)num/(gdouble)total);
937 gtk_progress_bar_pulse (GTK_PROGRESS_BAR(progress_bar));
939 txt = g_strdup_printf (_("Downloading %d of %d"), num, total);
940 gtk_progress_bar_set_text (GTK_PROGRESS_BAR(progress_bar), txt);
943 statusbar_push (main_window, 0, msg);
948 modest_ui_actions_on_msg_link_hover (ModestMsgView *msgview, const gchar* link,
951 g_message (__FUNCTION__);
956 modest_ui_actions_on_msg_link_clicked (ModestMsgView *msgview, const gchar* link,
959 g_message (__FUNCTION__);
963 modest_ui_actions_on_msg_attachment_clicked (ModestMsgView *msgview, int index,
966 g_message (__FUNCTION__);
971 modest_ui_actions_on_msg_recpt_activated (ModestMsgView *msgview,
972 const gchar *address,
975 g_message ("%s %s", __FUNCTION__, address);
979 modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
981 TnyTransportAccount *transport_account;
982 ModestMailOperation *mail_operation;
984 gchar *account_name, *from;
985 ModestAccountMgr *account_mgr;
987 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window));
989 data = modest_msg_edit_window_get_msg_data (edit_window);
991 /* FIXME: Code added just for testing. The final version will
992 use the send queue provided by tinymail and some
994 account_mgr = modest_runtime_get_account_mgr();
995 account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
997 account_name = modest_account_mgr_get_default_account (account_mgr);
999 g_printerr ("modest: no account found\n");
1000 modest_msg_edit_window_free_msg_data (edit_window, data);
1004 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_tny_account_by_account
1005 (modest_runtime_get_account_store(),
1007 TNY_ACCOUNT_TYPE_TRANSPORT));
1008 if (!transport_account) {
1009 g_printerr ("modest: no transport account found for '%s'\n", account_name);
1010 g_free (account_name);
1011 modest_msg_edit_window_free_msg_data (edit_window, data);
1014 from = modest_account_mgr_get_from_string (account_mgr, account_name);
1016 mail_operation = modest_mail_operation_new ();
1017 modest_mail_operation_send_new_mail (mail_operation,
1028 g_free (account_name);
1029 g_object_unref (G_OBJECT (mail_operation));
1030 g_object_unref (G_OBJECT (transport_account));
1032 modest_msg_edit_window_free_msg_data (edit_window, data);
1034 /* Save settings and close the window */
1035 /* save_settings (edit_window) */
1036 gtk_widget_destroy (GTK_WIDGET (edit_window));
1040 * Shows a dialog with an entry that asks for some text. The returned
1041 * value must be freed by the caller. The dialog window title will be
1045 ask_for_folder_name (GtkWindow *parent_window,
1048 GtkWidget *dialog, *entry;
1049 gchar *folder_name = NULL;
1051 /* Ask for folder name */
1052 dialog = gtk_dialog_new_with_buttons (_("New Folder Name"),
1056 GTK_RESPONSE_REJECT,
1058 GTK_RESPONSE_ACCEPT,
1060 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
1061 gtk_label_new(title),
1064 entry = gtk_entry_new_with_max_length (40);
1065 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
1069 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
1071 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
1072 folder_name = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry)));
1074 gtk_widget_destroy (dialog);
1080 modest_ui_actions_on_new_folder (GtkAction *action, ModestMainWindow *main_window)
1082 TnyFolder *parent_folder;
1083 GtkWidget *folder_view;
1085 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1087 folder_view = modest_main_window_get_child_widget (main_window,
1088 MODEST_WIDGET_TYPE_FOLDER_VIEW);
1092 parent_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
1094 if (parent_folder) {
1097 folder_name = ask_for_folder_name (GTK_WINDOW (main_window),
1098 _("Please enter a name for the new folder"));
1100 if (folder_name != NULL && strlen (folder_name) > 0) {
1101 TnyFolder *new_folder;
1102 ModestMailOperation *mail_op;
1104 mail_op = modest_mail_operation_new ();
1105 new_folder = modest_mail_operation_create_folder (mail_op,
1106 TNY_FOLDER_STORE (parent_folder),
1107 (const gchar *) folder_name);
1109 g_object_unref (new_folder);
1111 const GError *error;
1112 error = modest_mail_operation_get_error (mail_op);
1114 g_warning ("Error adding a subfolder: %s\n", error->message);
1116 g_object_unref (mail_op);
1118 g_object_unref (parent_folder);
1123 modest_ui_actions_on_rename_folder (GtkAction *action,
1124 ModestMainWindow *main_window)
1127 GtkWidget *folder_view;
1129 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1131 folder_view = modest_main_window_get_child_widget (main_window,
1132 MODEST_WIDGET_TYPE_FOLDER_VIEW);
1136 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
1140 folder_name = ask_for_folder_name (GTK_WINDOW (main_window),
1141 _("Please enter a new name for the folder"));
1143 if (folder_name != NULL && strlen (folder_name) > 0) {
1144 ModestMailOperation *mail_op;
1145 const GError *error;
1147 mail_op = modest_mail_operation_new ();
1148 modest_mail_operation_rename_folder (mail_op,
1150 (const gchar *) folder_name);
1152 error = modest_mail_operation_get_error (mail_op);
1154 /* TODO: notify error ? */
1155 g_warning ("Could not rename a folder: %s\n", error->message);
1157 g_object_unref (mail_op);
1159 g_object_unref (folder);
1164 delete_folder (ModestMainWindow *main_window, gboolean move_to_trash)
1167 ModestMailOperation *mail_op;
1168 GtkWidget *folder_view;
1169 const GError *error;
1171 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1173 folder_view = modest_main_window_get_child_widget (main_window,
1174 MODEST_WIDGET_TYPE_FOLDER_VIEW);
1178 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
1180 mail_op = modest_mail_operation_new ();
1181 modest_mail_operation_remove_folder (mail_op, folder, move_to_trash);
1183 error = modest_mail_operation_get_error (mail_op);
1185 g_warning ("%s\n", error->message);
1187 g_object_unref (G_OBJECT (mail_op));
1188 g_object_unref (G_OBJECT (folder));
1192 modest_ui_actions_on_delete_folder (GtkAction *action,
1193 ModestMainWindow *main_window)
1195 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1197 delete_folder (main_window, FALSE);
1201 modest_ui_actions_on_move_folder_to_trash_folder (GtkAction *action, ModestMainWindow *main_window)
1203 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
1205 delete_folder (main_window, TRUE);
1209 modest_ui_actions_on_password_requested (TnyAccountStore *account_store,
1210 const gchar* account_name,
1214 ModestMainWindow *main_window)
1217 GtkWidget *dialog, *entry, *remember_pass_check;
1219 dialog = gtk_dialog_new_with_buttons (_("Password requested"),
1223 GTK_RESPONSE_REJECT,
1225 GTK_RESPONSE_ACCEPT,
1227 gtk_window_set_transient_for (GTK_WINDOW(dialog), GTK_WINDOW(main_window));
1229 txt = g_strdup_printf (_("Please enter your password for %s"), account_name);
1230 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), gtk_label_new(txt),
1234 entry = gtk_entry_new_with_max_length (40);
1235 gtk_entry_set_visibility (GTK_ENTRY(entry), FALSE);
1236 gtk_entry_set_invisible_char (GTK_ENTRY(entry), 0x2022); /* bullet unichar */
1238 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry,
1241 remember_pass_check = gtk_check_button_new_with_label (_("Remember password"));
1242 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), remember_pass_check,
1245 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
1247 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
1248 *password = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry)));
1255 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (remember_pass_check)))
1260 gtk_widget_destroy (dialog);