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-ui-actions.h"
38 #include "modest-tny-platform-factory.h"
40 #include <widgets/modest-main-window.h>
41 #include "modest-account-view-window.h"
42 #include <widgets/modest-msg-view-window.h>
44 #include "modest-account-mgr-helpers.h"
45 #include "modest-mail-operation.h"
46 #include <modest-widget-memory.h>
47 #include <tny-error.h>
48 #include <tny-simple-list.h>
49 #include <tny-msg-view.h>
50 #include <tny-device.h>
53 typedef struct _GetMsgAsyncHelper {
54 ModestMainWindow *main_window;
60 typedef enum _ReplyForwardAction {
66 typedef struct _ReplyForwardHelper {
67 guint reply_forward_type;
68 ReplyForwardAction action;
73 static void reply_forward_func (gpointer data, gpointer user_data);
74 static void read_msg_func (gpointer data, gpointer user_data);
75 static void get_msg_cb (TnyFolder *folder, TnyMsg *msg, GError **err,
78 static void reply_forward (GtkWidget *widget, ReplyForwardAction action,
79 ModestMainWindow *main_window);
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);
111 modest_ui_actions_on_delete (GtkWidget *widget, ModestMainWindow *main_window)
113 TnyList *header_list;
117 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
119 if (!main_window->header_view)
122 header_list = modest_header_view_get_selected_headers (main_window->header_view);
125 iter = tny_list_create_iterator (header_list);
126 model = gtk_tree_view_get_model (GTK_TREE_VIEW (main_window->header_view));
127 if (GTK_IS_TREE_MODEL_SORT (model))
128 model = gtk_tree_model_sort_get_model (GTK_TREE_MODEL_SORT (model));
131 ModestMailOperation *mail_op;
133 header = TNY_HEADER (tny_iterator_get_current (iter));
134 /* TODO: thick grain mail operation involving
135 a list of objects. Composite pattern ??? */
136 mail_op = modest_mail_operation_new ();
138 /* TODO: add confirmation dialog */
141 modest_mail_operation_remove_msg (mail_op, header, TRUE);
143 /* Remove from tree model */
144 if (modest_mail_operation_get_status (mail_op) ==
145 MODEST_MAIL_OPERATION_STATUS_SUCCESS)
146 tny_list_remove (TNY_LIST (model), G_OBJECT (header));
148 /* TODO: error handling management */
150 error = modest_mail_operation_get_error (mail_op);
151 g_warning (error->message);
154 g_object_unref (G_OBJECT (mail_op));
155 g_object_unref (header);
156 tny_iterator_next (iter);
158 } while (!tny_iterator_is_done (iter));
164 modest_ui_actions_on_quit (GtkWidget *widget, ModestWindow *win)
166 /* FIXME: save size of main window */
167 /* save_sizes (main_window); */
168 gtk_widget_destroy (GTK_WIDGET (win));
172 modest_ui_actions_on_accounts (GtkWidget *widget, ModestWindow *win)
174 GtkWidget *account_win;
175 account_win = modest_account_view_window_new ();
178 gtk_window_set_transient_for (GTK_WINDOW (account_win), GTK_WINDOW (win));
180 gtk_widget_show (account_win);
184 modest_ui_actions_on_new_msg (GtkWidget *widget, ModestWindow *win)
186 ModestWindow *msg_win;
187 msg_win = modest_msg_edit_window_new (MODEST_EDIT_TYPE_NEW);
189 gtk_window_set_transient_for (GTK_WINDOW (msg_win),
192 gtk_widget_show_all (GTK_WIDGET (msg_win));
197 modest_ui_actions_on_open (GtkWidget *widget, ModestWindow *win)
205 reply_forward_func (gpointer data, gpointer user_data)
207 TnyMsg *msg, *new_msg;
208 GetMsgAsyncHelper *helper;
209 ReplyForwardHelper *rf_helper;
210 ModestWindow *msg_win;
211 ModestEditType edit_type;
213 msg = TNY_MSG (data);
214 helper = (GetMsgAsyncHelper *) user_data;
215 rf_helper = (ReplyForwardHelper *) helper->user_data;
217 /* Create reply mail */
218 switch (rf_helper->action) {
221 modest_mail_operation_create_reply_mail (msg,
223 rf_helper->reply_forward_type,
224 MODEST_MAIL_OPERATION_REPLY_MODE_SENDER);
226 case ACTION_REPLY_TO_ALL:
228 modest_mail_operation_create_reply_mail (msg, rf_helper->from, rf_helper->reply_forward_type,
229 MODEST_MAIL_OPERATION_REPLY_MODE_ALL);
230 edit_type = MODEST_EDIT_TYPE_REPLY;
234 modest_mail_operation_create_forward_mail (msg, rf_helper->from, rf_helper->reply_forward_type);
235 edit_type = MODEST_EDIT_TYPE_FORWARD;
238 g_return_if_reached ();
242 g_warning ("Unable to create a message");
246 /* Show edit window */
247 msg_win = modest_msg_edit_window_new (MODEST_EDIT_TYPE_NEW);
248 modest_msg_edit_window_set_msg (MODEST_MSG_EDIT_WINDOW (msg_win),
250 gtk_widget_show_all (GTK_WIDGET (msg_win));
253 g_object_unref (G_OBJECT (new_msg));
256 g_free (rf_helper->from);
257 g_slice_free (ReplyForwardHelper, rf_helper);
261 * Common code for the reply and forward actions
264 reply_forward (GtkWidget *widget, ReplyForwardAction action,
265 ModestMainWindow *main_window)
267 ModestAccountMgr *account_mgr;
268 TnyList *header_list;
269 guint reply_forward_type;
271 ModestAccountData *default_account_data;
274 gchar *from, *key, *default_account_name;
275 GetMsgAsyncHelper *helper;
276 ReplyForwardHelper *rf_helper;
278 if (!main_window->header_view)
281 header_list = modest_header_view_get_selected_headers (main_window->header_view);
285 conf = modest_runtime_get_conf ();
287 /* Get reply or forward type */
288 key = g_strdup_printf ("%s/%s", MODEST_CONF_NAMESPACE,
289 (action == ACTION_FORWARD) ? MODEST_CONF_FORWARD_TYPE : MODEST_CONF_REPLY_TYPE);
290 reply_forward_type = modest_conf_get_int (conf, key, NULL);
293 /* We assume that we can only select messages of the
294 same folder and that we reply all of them from the
295 same account. In fact the interface currently only
296 allows single selection */
297 account_mgr = modest_runtime_get_account_mgr();
298 default_account_name = modest_account_mgr_get_default_account (account_mgr);
299 default_account_data =
300 modest_account_mgr_get_account_data (account_mgr,
301 (const gchar*) default_account_name);
302 from = g_strdup (default_account_data->email);
303 modest_account_mgr_free_account_data (account_mgr, default_account_data);
304 g_free (default_account_name);
307 rf_helper = g_slice_new0 (ReplyForwardHelper);
308 rf_helper->reply_forward_type = reply_forward_type;
309 rf_helper->action = action;
310 rf_helper->from = from;
312 helper = g_slice_new0 (GetMsgAsyncHelper);
313 helper->main_window = main_window;
314 helper->func = reply_forward_func;
315 helper->iter = tny_list_create_iterator (header_list);
316 helper->user_data = rf_helper;
318 header = TNY_HEADER (tny_iterator_get_current (helper->iter));
319 folder = tny_header_get_folder (header);
321 /* The callback will call it per each header */
322 tny_folder_get_msg_async (folder, header, get_msg_cb, helper);
325 g_object_unref (G_OBJECT (header));
326 g_object_unref (G_OBJECT (folder));
330 modest_ui_actions_on_reply (GtkWidget *widget, ModestMainWindow *main_window)
332 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
334 reply_forward (widget, ACTION_REPLY, main_window);
338 modest_ui_actions_on_forward (GtkWidget *widget, ModestMainWindow *main_window)
340 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
342 reply_forward (widget, ACTION_FORWARD, main_window);
346 modest_ui_actions_on_reply_all (GtkWidget *widget,ModestMainWindow *main_window)
348 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
350 reply_forward (widget, ACTION_REPLY_TO_ALL, main_window);
354 modest_ui_actions_on_next (GtkWidget *widget,
355 ModestMainWindow *main_window)
357 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
359 if (main_window->header_view)
360 modest_header_view_select_next (main_window->header_view);
364 modest_ui_actions_on_prev (GtkWidget *widget,
365 ModestMainWindow *main_window)
367 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
369 if (main_window->header_view)
370 modest_header_view_select_prev (main_window->header_view);
375 modest_ui_actions_toggle_view (GtkWidget *widget, ModestMainWindow *main_window)
379 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
381 if (!main_window->header_view)
383 conf = modest_runtime_get_conf ();
385 /* what is saved/restored is depending on the style; thus; we save with
386 * old style, then update the style, and restore for this new style*/
387 modest_widget_memory_save (conf, G_OBJECT(main_window->header_view), "header-view");
389 if (modest_header_view_get_style (main_window->header_view) == MODEST_HEADER_VIEW_STYLE_DETAILS)
390 modest_header_view_set_style (main_window->header_view,
391 MODEST_HEADER_VIEW_STYLE_TWOLINES);
393 modest_header_view_set_style (main_window->header_view,
394 MODEST_HEADER_VIEW_STYLE_DETAILS);
396 modest_widget_memory_restore (conf, G_OBJECT(main_window->header_view),
403 * Marks a message as read and passes it to the msg preview widget
406 read_msg_func (gpointer data, gpointer user_data)
410 GetMsgAsyncHelper *helper;
411 TnyHeaderFlags header_flags;
413 msg = TNY_MSG (data);
414 helper = (GetMsgAsyncHelper *) user_data;
416 if (!helper->main_window->msg_preview)
419 /* mark message as seen; _set_flags crashes, bug in tinymail? */
420 header = TNY_HEADER (tny_iterator_get_current (helper->iter));
421 header_flags = tny_header_get_flags (header);
422 tny_header_set_flags (header, header_flags | TNY_HEADER_FLAG_SEEN);
423 g_object_unref (G_OBJECT (header));
425 /* Set message on msg view */
426 modest_msg_view_set_message (helper->main_window->msg_preview,
431 * This function is a generic handler for the tny_folder_get_msg_async
432 * call. It expects as user_data a #GetMsgAsyncHelper. This helper
433 * contains a user provided function that is called inside this
434 * method. This will allow us to use this callback in many different
435 * places. This callback performs the common actions for the
436 * get_msg_async call, more specific actions will be done by the user
440 get_msg_cb (TnyFolder *folder, TnyMsg *msg, GError **err, gpointer user_data)
442 GetMsgAsyncHelper *helper;
444 helper = (GetMsgAsyncHelper *) user_data;
446 if ((*err && ((*err)->code == TNY_FOLDER_ERROR_GET_MSG)) || !msg) {
447 ModestHeaderView *header_view =
448 helper->main_window->header_view;
450 modest_ui_actions_on_item_not_found (header_view,
451 MODEST_ITEM_TYPE_MESSAGE,
452 MODEST_WINDOW(helper->main_window));
456 /* Call user function */
457 helper->func (msg, user_data);
459 /* Process next element (if exists) */
460 tny_iterator_next (helper->iter);
461 if (tny_iterator_is_done (helper->iter)) {
463 headers = tny_iterator_get_list (helper->iter);
465 g_object_unref (G_OBJECT (headers));
466 g_object_unref (G_OBJECT (helper->iter));
467 g_slice_free (GetMsgAsyncHelper, helper);
470 header = TNY_HEADER (tny_iterator_get_current (helper->iter));
471 tny_folder_get_msg_async (folder, header,
473 g_object_unref (G_OBJECT(header));
478 modest_ui_actions_on_header_selected (ModestHeaderView *folder_view, TnyHeader *header,
479 ModestMainWindow *main_window)
482 GetMsgAsyncHelper *helper;
485 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
487 if (!main_window->msg_preview)
490 /* when there's no header, clear the msgview */
492 modest_msg_view_set_message (main_window->msg_preview, NULL);
496 folder = tny_header_get_folder (TNY_HEADER(header));
499 list = tny_simple_list_new ();
500 tny_list_prepend (list, G_OBJECT (header));
502 /* Fill helper data */
503 helper = g_slice_new0 (GetMsgAsyncHelper);
504 helper->main_window = main_window;
505 helper->iter = tny_list_create_iterator (list);
506 helper->func = read_msg_func;
508 tny_folder_get_msg_async (TNY_FOLDER(folder),
513 g_object_unref (G_OBJECT (folder));
519 modest_ui_actions_on_header_activated (ModestHeaderView *folder_view, TnyHeader *header,
520 ModestMainWindow *main_window)
523 TnyFolder *folder = NULL;
526 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
531 folder = tny_header_get_folder (header);
533 g_printerr ("modest: cannot get folder for header\n");
537 /* FIXME: make async?; check error */
538 msg = tny_folder_get_msg (folder, header, NULL);
540 g_printerr ("modest: cannot get msg for header\n");
544 win = modest_msg_view_window_new (msg);
545 gtk_window_set_transient_for (GTK_WINDOW (win),
546 GTK_WINDOW (main_window));
548 gtk_widget_show_all (GTK_WIDGET(win));
552 g_object_unref (G_OBJECT (folder));
554 g_object_unref (G_OBJECT (folder));
562 modest_ui_actions_on_folder_selection_changed (ModestFolderView *folder_view,
565 ModestMainWindow *main_window)
567 // GtkLabel *folder_info_label;
571 /* folder_info_label = */
572 /* GTK_LABEL (modest_widget_factory_get_folder_info_label */
573 /* (modest_runtime_get_widget_factory())); */
576 /* gtk_label_set_label (GTK_LABEL(folder_info_label), ""); */
580 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
582 if (!main_window->header_view)
585 conf = modest_runtime_get_conf ();
587 if (!selected) { /* the folder was unselected; save it's settings */
588 modest_widget_memory_save (conf, G_OBJECT (main_window->header_view),
590 gtk_window_set_title (GTK_WINDOW(main_window), "Modest");
591 modest_header_view_set_folder (main_window->header_view, NULL);
592 } else { /* the folder was selected */
593 if (folder) { /* folder may be NULL */
597 num = tny_folder_get_all_count (folder);
598 unread = tny_folder_get_unread_count (folder);
600 title = g_strdup_printf ("Modest: %s",
601 tny_folder_get_name (folder));
603 gtk_window_set_title (GTK_WINDOW(main_window), title);
606 txt = g_strdup_printf (_("%d %s, %d unread"),
607 num, num==1 ? _("item") : _("items"), unread);
608 //gtk_label_set_label (GTK_LABEL(folder_info_label), txt);
611 modest_header_view_set_folder (main_window->header_view, folder);
612 modest_widget_memory_restore (conf, G_OBJECT(main_window->header_view),
618 /****************************************************/
620 * below some stuff to clearup statusbar messages after 1,5 seconds....
623 progress_bar_clean (GtkWidget *bar)
625 if (GTK_IS_PROGRESS_BAR(bar)) {
626 gtk_progress_bar_set_text (GTK_PROGRESS_BAR(bar), "");
627 gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(bar), 1.0);
633 statusbar_clean (GtkWidget *bar)
635 if (GTK_IS_STATUSBAR(bar))
636 gtk_statusbar_push (GTK_STATUSBAR(bar), 0, "");
642 statusbar_push (ModestMainWindow *main_window, guint context_id, const gchar *msg)
647 if (main_window->progress_bar) {
648 gtk_widget_show (main_window->progress_bar);
649 g_timeout_add (3000, (GSourceFunc)progress_bar_clean,
650 main_window->progress_bar);
653 if (main_window->status_bar) {
654 gtk_widget_show (main_window->status_bar);
655 gtk_statusbar_push (GTK_STATUSBAR(main_window->status_bar), 0, msg);
656 g_timeout_add (1500, (GSourceFunc)statusbar_clean, main_window->status_bar);
660 /****************************************************************************/
663 modest_ui_actions_on_item_not_found (ModestHeaderView *header_view,ModestItemType type,
670 TnyAccountStore *account_store;
672 item = (type == MODEST_ITEM_TYPE_FOLDER) ? "folder" : "message";
674 /* Get device. Do not ask the platform factory for it, because
675 it returns always a new one */
676 account_store = TNY_ACCOUNT_STORE (modest_runtime_get_account_store ());
677 device = tny_account_store_get_device (account_store);
679 if (g_main_depth > 0)
680 gdk_threads_enter ();
681 online = tny_device_is_online (device);
684 /* already online -- the item is simply not there... */
685 dialog = gtk_message_dialog_new (GTK_WINDOW (win),
689 _("The %s you selected cannot be found"),
691 gtk_dialog_run (GTK_DIALOG(dialog));
694 dialog = gtk_dialog_new_with_buttons (_("Connection requested"),
703 txt = g_strdup_printf (_("This %s is not available in offline mode.\n"
704 "Do you want to get online?"), item);
705 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
706 gtk_label_new (txt), FALSE, FALSE, 0);
707 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
710 gtk_window_set_default_size (GTK_WINDOW(dialog), 300, 300);
711 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
712 tny_device_force_online (device);
715 gtk_widget_destroy (dialog);
716 if (g_main_depth > 0)
717 gdk_threads_leave ();
723 modest_ui_actions_on_header_status_update (ModestHeaderView *header_view,
724 const gchar *msg, gint num,
725 gint total, ModestMainWindow *main_window)
729 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
731 if (!main_window->progress_bar)
735 gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(main_window->progress_bar),
736 (gdouble)num/(gdouble)total);
738 gtk_progress_bar_pulse (GTK_PROGRESS_BAR(main_window->progress_bar));
740 txt = g_strdup_printf (_("Downloading %d of %d"), num, total);
741 gtk_progress_bar_set_text (GTK_PROGRESS_BAR(main_window->progress_bar), txt);
744 statusbar_push (main_window, 0, msg);
749 modest_ui_actions_on_msg_link_hover (ModestMsgView *msgview, const gchar* link,
752 g_warning (__FUNCTION__);
757 modest_ui_actions_on_msg_link_clicked (ModestMsgView *msgview, const gchar* link,
760 g_warning (__FUNCTION__);
764 modest_ui_actions_on_msg_attachment_clicked (ModestMsgView *msgview, int index,
767 g_warning (__FUNCTION__);
772 modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
774 TnyTransportAccount *transport_account;
775 ModestMailOperation *mail_operation;
777 gchar *account_name, *from;
778 ModestAccountMgr *account_mgr;
780 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window));
782 data = modest_msg_edit_window_get_msg_data (edit_window);
784 /* FIXME: Code added just for testing. The final version will
785 use the send queue provided by tinymail and some
787 account_mgr = modest_runtime_get_account_mgr();
788 account_name = modest_account_mgr_get_default_account (account_mgr);
790 g_printerr ("modest: no default account found\n");
791 modest_msg_edit_window_free_msg_data (edit_window, data);
795 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_tny_account_by_account
796 (modest_runtime_get_account_store(),
798 TNY_ACCOUNT_TYPE_TRANSPORT));
799 if (!transport_account) {
800 g_printerr ("modest: no transport account found for '%s'\n", account_name);
801 g_free (account_name);
802 modest_msg_edit_window_free_msg_data (edit_window, data);
805 from = modest_account_mgr_get_from_string (account_mgr, account_name);
807 mail_operation = modest_mail_operation_new ();
808 modest_mail_operation_send_new_mail (mail_operation,
819 g_free (account_name);
820 g_object_unref (G_OBJECT (mail_operation));
821 g_object_unref (G_OBJECT (transport_account));
823 modest_msg_edit_window_free_msg_data (edit_window, data);
825 /* Save settings and close the window */
826 /* save_settings (edit_window) */
827 gtk_widget_destroy (GTK_WIDGET (edit_window));
831 * Shows a dialog with an entry that asks for some text. The returned
832 * value must be freed by the caller. The dialog window title will be
836 ask_for_folder_name (GtkWindow *parent_window,
839 GtkWidget *dialog, *entry;
840 gchar *folder_name = NULL;
842 /* Ask for folder name */
843 dialog = gtk_dialog_new_with_buttons (_("New Folder Name"),
851 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
852 gtk_label_new(title),
855 entry = gtk_entry_new_with_max_length (40);
856 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
860 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
862 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
863 folder_name = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry)));
865 gtk_widget_destroy (dialog);
871 modest_ui_actions_on_new_folder (GtkWidget *widget, ModestMainWindow *main_window)
873 TnyFolder *parent_folder;
875 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
877 if (!main_window->folder_view)
880 parent_folder = modest_folder_view_get_selected (main_window->folder_view);
885 folder_name = ask_for_folder_name (GTK_WINDOW (main_window),
886 _("Please enter a name for the new folder"));
888 if (folder_name != NULL && strlen (folder_name) > 0) {
889 TnyFolder *new_folder;
890 ModestMailOperation *mail_op;
892 mail_op = modest_mail_operation_new ();
893 new_folder = modest_mail_operation_create_folder (mail_op,
894 TNY_FOLDER_STORE (parent_folder),
895 (const gchar *) folder_name);
897 /* TODO: tinymail should do this.
899 modest_folder_view_add_subfolder (main_window->folder_view, new_folder);
901 /* Free new folder */
902 g_object_unref (new_folder);
904 g_object_unref (mail_op);
906 g_object_unref (parent_folder);
911 modest_ui_actions_on_rename_folder (GtkWidget *widget,
912 ModestMainWindow *main_window)
916 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
918 if (!main_window->folder_view)
921 folder = modest_folder_view_get_selected (main_window->folder_view);
926 folder_name = ask_for_folder_name (GTK_WINDOW (main_window),
927 _("Please enter a new name for the folder"));
929 if (folder_name != NULL && strlen (folder_name) > 0) {
930 ModestMailOperation *mail_op;
933 mail_op = modest_mail_operation_new ();
934 modest_mail_operation_rename_folder (mail_op,
936 (const gchar *) folder_name);
938 error = modest_mail_operation_get_error (mail_op);
940 /* TODO: tinymail should do this.
942 modest_folder_view_rename (main_window->folder_view);
944 /* TODO: else ? notify error ? */
946 g_object_unref (mail_op);
948 g_object_unref (folder);
953 delete_folder (ModestMainWindow *main_window, gboolean move_to_trash)
956 ModestMailOperation *mail_op;
958 if (!main_window->folder_view)
961 folder = modest_folder_view_get_selected (main_window->folder_view);
963 mail_op = modest_mail_operation_new ();
964 modest_mail_operation_remove_folder (mail_op, folder, move_to_trash);
965 g_object_unref (mail_op);
969 modest_ui_actions_on_delete_folder (GtkWidget *widget,
970 ModestMainWindow *main_window)
972 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
974 delete_folder (main_window, FALSE);
978 modest_ui_actions_on_move_folder_to_trash_folder (GtkWidget *widget, ModestMainWindow *main_window)
980 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
982 delete_folder (main_window, TRUE);
986 modest_ui_actions_on_accounts_reloaded (TnyAccountStore *store, gpointer user_data)
989 /* ModestFolderView *folder_view; */
991 /* folder_view = modest_widget_factory_get_folder_view (modest_runtime_get_widget_factory()); */
992 /* modest_folder_view_update_model (folder_view, store); */
996 modest_ui_actions_on_folder_moved (ModestFolderView *folder_view, TnyFolder *folder,
997 TnyFolderStore *parent, gboolean *done,
1000 ModestMailOperation *mail_op;
1001 const GError *error;
1005 /* Try to move the folder */
1006 mail_op = modest_mail_operation_new ();
1007 modest_mail_operation_move_folder (mail_op, folder, parent);
1009 error = modest_mail_operation_get_error (mail_op);
1013 g_object_unref (G_OBJECT (mail_op));