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,
86 ModestMainWindow *main_window)
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);
112 modest_ui_actions_on_delete (GtkWidget *widget, ModestMainWindow *main_window)
114 TnyList *header_list;
118 if (!main_window->header_view)
121 header_list = modest_header_view_get_selected_headers (main_window->header_view);
124 iter = tny_list_create_iterator (header_list);
125 model = gtk_tree_view_get_model (GTK_TREE_VIEW (main_window->header_view));
126 if (GTK_IS_TREE_MODEL_SORT (model))
127 model = gtk_tree_model_sort_get_model (GTK_TREE_MODEL_SORT (model));
130 ModestMailOperation *mail_op;
132 header = TNY_HEADER (tny_iterator_get_current (iter));
133 /* TODO: thick grain mail operation involving
134 a list of objects. Composite pattern ??? */
135 mail_op = modest_mail_operation_new ();
137 /* TODO: add confirmation dialog */
140 modest_mail_operation_remove_msg (mail_op, header, TRUE);
142 /* Remove from tree model */
143 if (modest_mail_operation_get_status (mail_op) ==
144 MODEST_MAIL_OPERATION_STATUS_SUCCESS)
145 tny_list_remove (TNY_LIST (model), G_OBJECT (header));
147 /* TODO: error handling management */
149 error = modest_mail_operation_get_error (mail_op);
150 g_warning (error->message);
153 g_object_unref (G_OBJECT (mail_op));
154 g_object_unref (header);
155 tny_iterator_next (iter);
157 } while (!tny_iterator_is_done (iter));
162 modest_ui_actions_on_quit (GtkWidget *widget,
163 ModestMainWindow *main_window)
165 /* FIXME: save size of main window */
166 /* save_sizes (main_window); */
167 gtk_widget_destroy (GTK_WIDGET (main_window));
171 modest_ui_actions_on_accounts (GtkWidget *widget,
172 ModestMainWindow *main_window)
174 GtkWidget *account_win;
175 account_win = modest_account_view_window_new ();
177 gtk_window_set_transient_for (GTK_WINDOW (account_win), GTK_WINDOW (main_window));
178 gtk_widget_show (account_win);
182 modest_ui_actions_on_new_msg (GtkWidget *widget,
183 ModestMainWindow *main_window)
185 ModestWindow *msg_win;
186 msg_win = modest_msg_edit_window_new (MODEST_EDIT_TYPE_NEW);
187 gtk_widget_show_all (GTK_WIDGET (msg_win));
192 modest_ui_actions_on_open (GtkWidget *widget,
193 ModestMainWindow *main_window)
201 reply_forward_func (gpointer data, gpointer user_data)
203 TnyMsg *msg, *new_msg;
204 GetMsgAsyncHelper *helper;
205 ReplyForwardHelper *rf_helper;
206 ModestWindow *msg_win;
207 ModestEditType edit_type;
209 msg = TNY_MSG (data);
210 helper = (GetMsgAsyncHelper *) user_data;
211 rf_helper = (ReplyForwardHelper *) helper->user_data;
213 /* Create reply mail */
214 switch (rf_helper->action) {
217 modest_mail_operation_create_reply_mail (msg,
219 rf_helper->reply_forward_type,
220 MODEST_MAIL_OPERATION_REPLY_MODE_SENDER);
222 case ACTION_REPLY_TO_ALL:
224 modest_mail_operation_create_reply_mail (msg, rf_helper->from, rf_helper->reply_forward_type,
225 MODEST_MAIL_OPERATION_REPLY_MODE_ALL);
226 edit_type = MODEST_EDIT_TYPE_REPLY;
230 modest_mail_operation_create_forward_mail (msg, rf_helper->from, rf_helper->reply_forward_type);
231 edit_type = MODEST_EDIT_TYPE_FORWARD;
234 g_return_if_reached ();
238 g_warning ("Unable to create a message");
242 /* Show edit window */
243 msg_win = modest_msg_edit_window_new (MODEST_EDIT_TYPE_NEW);
244 modest_msg_edit_window_set_msg (MODEST_MSG_EDIT_WINDOW (msg_win),
246 gtk_widget_show_all (GTK_WIDGET (msg_win));
249 g_object_unref (G_OBJECT (new_msg));
252 g_free (rf_helper->from);
253 g_slice_free (ReplyForwardHelper, rf_helper);
257 * Common code for the reply and forward actions
260 reply_forward (GtkWidget *widget, ReplyForwardAction action,
261 ModestMainWindow *main_window)
263 ModestAccountMgr *account_mgr;
264 TnyList *header_list;
265 guint reply_forward_type;
267 ModestAccountData *default_account_data;
270 gchar *from, *key, *default_account_name;
271 GetMsgAsyncHelper *helper;
272 ReplyForwardHelper *rf_helper;
274 if (!main_window->header_view)
277 header_list = modest_header_view_get_selected_headers (main_window->header_view);
281 conf = modest_runtime_get_conf ();
283 /* Get reply or forward type */
284 key = g_strdup_printf ("%s/%s", MODEST_CONF_NAMESPACE,
285 (action == ACTION_FORWARD) ? MODEST_CONF_FORWARD_TYPE : MODEST_CONF_REPLY_TYPE);
286 reply_forward_type = modest_conf_get_int (conf, key, NULL);
289 /* We assume that we can only select messages of the
290 same folder and that we reply all of them from the
291 same account. In fact the interface currently only
292 allows single selection */
293 account_mgr = modest_runtime_get_account_mgr();
294 default_account_name = modest_account_mgr_get_default_account (account_mgr);
295 default_account_data =
296 modest_account_mgr_get_account_data (account_mgr,
297 (const gchar*) default_account_name);
298 from = g_strdup (default_account_data->email);
299 modest_account_mgr_free_account_data (account_mgr, default_account_data);
300 g_free (default_account_name);
303 rf_helper = g_slice_new0 (ReplyForwardHelper);
304 rf_helper->reply_forward_type = reply_forward_type;
305 rf_helper->action = action;
306 rf_helper->from = from;
308 helper = g_slice_new0 (GetMsgAsyncHelper);
309 helper->main_window = main_window;
310 helper->func = reply_forward_func;
311 helper->iter = tny_list_create_iterator (header_list);
312 helper->user_data = rf_helper;
314 header = TNY_HEADER (tny_iterator_get_current (helper->iter));
315 folder = tny_header_get_folder (header);
317 /* The callback will call it per each header */
318 tny_folder_get_msg_async (folder, header, get_msg_cb, helper);
321 g_object_unref (G_OBJECT (header));
322 g_object_unref (G_OBJECT (folder));
326 modest_ui_actions_on_reply (GtkWidget *widget, ModestMainWindow *main_window)
328 reply_forward (widget, ACTION_REPLY, main_window);
332 modest_ui_actions_on_forward (GtkWidget *widget, ModestMainWindow *main_window)
334 reply_forward (widget, ACTION_FORWARD, main_window);
338 modest_ui_actions_on_reply_all (GtkWidget *widget,ModestMainWindow *main_window)
340 reply_forward (widget, ACTION_REPLY_TO_ALL, main_window);
344 modest_ui_actions_on_next (GtkWidget *widget,
345 ModestMainWindow *main_window)
347 if (main_window->header_view)
348 modest_header_view_select_next (main_window->header_view);
352 modest_ui_actions_toggle_view (GtkWidget *widget,
353 ModestMainWindow *main_window)
357 if (!main_window->header_view)
359 conf = modest_runtime_get_conf ();
361 /* what is saved/restored is depending on the style; thus; we save with
362 * old style, then update the style, and restore for this new style*/
363 modest_widget_memory_save (conf, G_OBJECT(main_window->header_view), "header-view");
365 if (modest_header_view_get_style (main_window->header_view) == MODEST_HEADER_VIEW_STYLE_DETAILS)
366 modest_header_view_set_style (main_window->header_view,
367 MODEST_HEADER_VIEW_STYLE_TWOLINES);
369 modest_header_view_set_style (main_window->header_view,
370 MODEST_HEADER_VIEW_STYLE_DETAILS);
372 modest_widget_memory_restore (conf, G_OBJECT(main_window->header_view),
379 * Marks a message as read and passes it to the msg preview widget
382 read_msg_func (gpointer data, gpointer user_data)
386 GetMsgAsyncHelper *helper;
387 TnyHeaderFlags header_flags;
389 msg = TNY_MSG (data);
390 helper = (GetMsgAsyncHelper *) user_data;
392 if (!helper->main_window->msg_preview)
395 /* mark message as seen; _set_flags crashes, bug in tinymail? */
396 header = TNY_HEADER (tny_iterator_get_current (helper->iter));
397 header_flags = tny_header_get_flags (header);
398 tny_header_set_flags (header, header_flags | TNY_HEADER_FLAG_SEEN);
399 g_object_unref (G_OBJECT (header));
401 /* Set message on msg view */
402 modest_msg_view_set_message (helper->main_window->msg_preview,
407 * This function is a generic handler for the tny_folder_get_msg_async
408 * call. It expects as user_data a #GetMsgAsyncHelper. This helper
409 * contains a user provided function that is called inside this
410 * method. This will allow us to use this callback in many different
411 * places. This callback performs the common actions for the
412 * get_msg_async call, more specific actions will be done by the user
416 get_msg_cb (TnyFolder *folder, TnyMsg *msg, GError **err, gpointer user_data)
418 GetMsgAsyncHelper *helper;
420 helper = (GetMsgAsyncHelper *) user_data;
422 if ((*err && ((*err)->code == TNY_FOLDER_ERROR_GET_MSG)) || !msg) {
423 ModestHeaderView *header_view =
424 helper->main_window->header_view;
426 modest_ui_actions_on_item_not_found (header_view,
427 MODEST_ITEM_TYPE_MESSAGE,
428 helper->main_window);
432 /* Call user function */
433 helper->func (msg, user_data);
435 /* Process next element (if exists) */
436 tny_iterator_next (helper->iter);
437 if (tny_iterator_is_done (helper->iter)) {
439 headers = tny_iterator_get_list (helper->iter);
441 g_object_unref (G_OBJECT (headers));
442 g_object_unref (G_OBJECT (helper->iter));
443 g_slice_free (GetMsgAsyncHelper, helper);
446 header = TNY_HEADER (tny_iterator_get_current (helper->iter));
447 tny_folder_get_msg_async (folder, header,
449 g_object_unref (G_OBJECT(header));
454 modest_ui_actions_on_header_selected (ModestHeaderView *folder_view,
456 ModestMainWindow *main_window)
459 GetMsgAsyncHelper *helper;
462 if (!main_window->msg_preview)
465 /* when there's no header, clear the msgview */
467 modest_msg_view_set_message (main_window->msg_preview, NULL);
471 folder = tny_header_get_folder (TNY_HEADER(header));
474 list = tny_simple_list_new ();
475 tny_list_prepend (list, G_OBJECT (header));
477 /* Fill helper data */
478 helper = g_slice_new0 (GetMsgAsyncHelper);
479 helper->main_window = main_window;
480 helper->iter = tny_list_create_iterator (list);
481 helper->func = read_msg_func;
483 tny_folder_get_msg_async (TNY_FOLDER(folder),
488 g_object_unref (G_OBJECT (folder));
494 modest_ui_actions_on_header_activated (ModestHeaderView *folder_view,
496 ModestMainWindow *main_window)
499 TnyFolder *folder = NULL;
505 folder = tny_header_get_folder (header);
507 g_printerr ("modest: cannot get folder for header\n");
511 /* FIXME: make async?; check error */
512 msg = tny_folder_get_msg (folder, header, NULL);
514 g_printerr ("modest: cannot get msg for header\n");
518 win = modest_msg_view_window_new (msg);
519 gtk_window_set_transient_for (GTK_WINDOW (win),
520 GTK_WINDOW (main_window));
522 gtk_widget_show_all (GTK_WIDGET(win));
526 g_object_unref (G_OBJECT (folder));
528 g_object_unref (G_OBJECT (folder));
536 modest_ui_actions_on_folder_selection_changed (ModestFolderView *folder_view,
539 ModestMainWindow *main_window)
541 // GtkLabel *folder_info_label;
545 /* folder_info_label = */
546 /* GTK_LABEL (modest_widget_factory_get_folder_info_label */
547 /* (modest_runtime_get_widget_factory())); */
550 /* gtk_label_set_label (GTK_LABEL(folder_info_label), ""); */
555 if (!main_window->header_view)
558 conf = modest_runtime_get_conf ();
560 if (!selected) { /* the folder was unselected; save it's settings */
561 modest_widget_memory_save (conf, G_OBJECT (main_window->header_view),
563 gtk_window_set_title (GTK_WINDOW(main_window), "Modest");
564 modest_header_view_set_folder (main_window->header_view, NULL);
565 } else { /* the folder was selected */
566 if (folder) { /* folder may be NULL */
570 num = tny_folder_get_all_count (folder);
571 unread = tny_folder_get_unread_count (folder);
573 title = g_strdup_printf ("Modest: %s",
574 tny_folder_get_name (folder));
576 gtk_window_set_title (GTK_WINDOW(main_window), title);
579 txt = g_strdup_printf (_("%d %s, %d unread"),
580 num, num==1 ? _("item") : _("items"), unread);
581 //gtk_label_set_label (GTK_LABEL(folder_info_label), txt);
584 modest_header_view_set_folder (main_window->header_view, folder);
585 modest_widget_memory_restore (conf, G_OBJECT(main_window->header_view),
591 /****************************************************/
593 * below some stuff to clearup statusbar messages after 1,5 seconds....
596 progress_bar_clean (GtkWidget *bar)
598 if (GTK_IS_PROGRESS_BAR(bar)) {
599 gtk_progress_bar_set_text (GTK_PROGRESS_BAR(bar), "");
600 gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(bar), 1.0);
606 statusbar_clean (GtkWidget *bar)
608 if (GTK_IS_STATUSBAR(bar))
609 gtk_statusbar_push (GTK_STATUSBAR(bar), 0, "");
615 statusbar_push (ModestMainWindow *main_window, guint context_id, const gchar *msg)
620 if (main_window->progress_bar) {
621 gtk_widget_show (main_window->progress_bar);
622 g_timeout_add (3000, (GSourceFunc)progress_bar_clean,
623 main_window->progress_bar);
626 if (main_window->status_bar) {
627 gtk_widget_show (main_window->status_bar);
628 gtk_statusbar_push (GTK_STATUSBAR(main_window->status_bar), 0, msg);
629 g_timeout_add (1500, (GSourceFunc)statusbar_clean, main_window->status_bar);
633 /****************************************************************************/
636 modest_ui_actions_on_item_not_found (ModestHeaderView *header_view,
638 ModestMainWindow *main_window)
644 TnyAccountStore *account_store;
646 item = (type == MODEST_ITEM_TYPE_FOLDER) ? "folder" : "message";
648 /* Get device. Do not ask the platform factory for it, because
649 it returns always a new one */
650 account_store = TNY_ACCOUNT_STORE (modest_runtime_get_account_store ());
651 device = tny_account_store_get_device (account_store);
653 if (g_main_depth > 0)
654 gdk_threads_enter ();
655 online = tny_device_is_online (device);
658 /* already online -- the item is simply not there... */
659 dialog = gtk_message_dialog_new (GTK_WINDOW (main_window),
663 _("The %s you selected cannot be found"),
665 gtk_dialog_run (GTK_DIALOG(dialog));
668 dialog = gtk_dialog_new_with_buttons (_("Connection requested"),
669 GTK_WINDOW (main_window),
677 txt = g_strdup_printf (_("This %s is not available in offline mode.\n"
678 "Do you want to get online?"), item);
679 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
680 gtk_label_new (txt), FALSE, FALSE, 0);
681 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
684 gtk_window_set_default_size (GTK_WINDOW(dialog), 300, 300);
685 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
686 tny_device_force_online (device);
689 gtk_widget_destroy (dialog);
690 if (g_main_depth > 0)
691 gdk_threads_leave ();
697 modest_ui_actions_on_header_status_update (ModestHeaderView *header_view,
698 const gchar *msg, gint num,
699 gint total, ModestMainWindow *main_window)
703 if (!main_window->progress_bar)
707 gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(main_window->progress_bar),
708 (gdouble)num/(gdouble)total);
710 gtk_progress_bar_pulse (GTK_PROGRESS_BAR(main_window->progress_bar));
712 txt = g_strdup_printf (_("Downloading %d of %d"), num, total);
713 gtk_progress_bar_set_text (GTK_PROGRESS_BAR(main_window->progress_bar), txt);
716 statusbar_push (main_window, 0, msg);
721 modest_ui_actions_on_msg_link_hover (ModestMsgView *msgview, const gchar* link,
722 ModestMainWindow *main_window)
724 statusbar_push (main_window, 0, link);
726 /* TODO: do something */
731 modest_ui_actions_on_msg_link_clicked (ModestMsgView *msgview, const gchar* link,
732 ModestMainWindow *main_window)
736 msg = g_strdup_printf (_("Opening %s..."), link);
737 statusbar_push (main_window, 0, msg);
740 /* TODO: do something */
744 modest_ui_actions_on_msg_attachment_clicked (ModestMsgView *msgview,
746 ModestMainWindow *main_window)
750 msg = g_strdup_printf (_("Opening attachment %d..."), index);
751 statusbar_push (main_window, 0, msg);
754 /* TODO: do something */
758 modest_ui_actions_on_send (GtkWidget *widget,
759 ModestMsgEditWindow *edit_window)
761 TnyTransportAccount *transport_account;
762 ModestMailOperation *mail_operation;
764 gchar *account_name, *from;
765 ModestAccountMgr *account_mgr;
768 data = modest_msg_edit_window_get_msg_data (edit_window);
770 /* FIXME: Code added just for testing. The final version will
771 use the send queue provided by tinymail and some
773 account_mgr = modest_runtime_get_account_mgr();
774 account_name = modest_account_mgr_get_default_account (account_mgr);
776 g_printerr ("modest: no default account found\n");
777 modest_msg_edit_window_free_msg_data (edit_window, data);
781 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_tny_account_by_account
782 (modest_runtime_get_account_store(),
784 TNY_ACCOUNT_TYPE_TRANSPORT));
785 if (!transport_account) {
786 g_printerr ("modest: no transport account found for '%s'\n", account_name);
787 g_free (account_name);
788 modest_msg_edit_window_free_msg_data (edit_window, data);
791 from = modest_account_mgr_get_from_string (account_mgr, account_name);
793 mail_operation = modest_mail_operation_new ();
794 modest_mail_operation_send_new_mail (mail_operation,
805 g_free (account_name);
806 g_object_unref (G_OBJECT (mail_operation));
807 g_object_unref (G_OBJECT (transport_account));
809 modest_msg_edit_window_free_msg_data (edit_window, data);
811 /* Save settings and close the window */
812 /* save_settings (edit_window) */
813 gtk_widget_destroy (GTK_WIDGET (edit_window));
817 * Shows a dialog with an entry that asks for some text. The returned
818 * value must be freed by the caller. The dialog window title will be
822 ask_for_folder_name (GtkWindow *parent_window,
825 GtkWidget *dialog, *entry;
826 gchar *folder_name = NULL;
828 /* Ask for folder name */
829 dialog = gtk_dialog_new_with_buttons (_("New Folder Name"),
837 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
838 gtk_label_new(title),
841 entry = gtk_entry_new_with_max_length (40);
842 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
846 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
848 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
849 folder_name = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry)));
851 gtk_widget_destroy (dialog);
857 modest_ui_actions_on_new_folder (GtkWidget *widget,
858 ModestMainWindow *main_window)
860 TnyFolder *parent_folder;
862 if (!main_window->folder_view)
865 parent_folder = modest_folder_view_get_selected (main_window->folder_view);
870 folder_name = ask_for_folder_name (GTK_WINDOW (main_window),
871 _("Please enter a name for the new folder"));
873 if (folder_name != NULL && strlen (folder_name) > 0) {
874 TnyFolder *new_folder;
875 ModestMailOperation *mail_op;
877 mail_op = modest_mail_operation_new ();
878 new_folder = modest_mail_operation_create_folder (mail_op,
879 TNY_FOLDER_STORE (parent_folder),
880 (const gchar *) folder_name);
882 /* TODO: tinymail should do this.
884 modest_folder_view_add_subfolder (main_window->folder_view, new_folder);
886 /* Free new folder */
887 g_object_unref (new_folder);
889 g_object_unref (mail_op);
891 g_object_unref (parent_folder);
896 modest_ui_actions_on_rename_folder (GtkWidget *widget,
897 ModestMainWindow *main_window)
901 if (!main_window->folder_view)
904 folder = modest_folder_view_get_selected (main_window->folder_view);
909 folder_name = ask_for_folder_name (GTK_WINDOW (main_window),
910 _("Please enter a new name for the folder"));
912 if (folder_name != NULL && strlen (folder_name) > 0) {
913 ModestMailOperation *mail_op;
916 mail_op = modest_mail_operation_new ();
917 modest_mail_operation_rename_folder (mail_op,
919 (const gchar *) folder_name);
921 error = modest_mail_operation_get_error (mail_op);
923 /* TODO: tinymail should do this.
925 modest_folder_view_rename (main_window->folder_view);
927 /* TODO: else ? notify error ? */
929 g_object_unref (mail_op);
931 g_object_unref (folder);
936 delete_folder (ModestMainWindow *main_window,
937 gboolean move_to_trash)
940 ModestMailOperation *mail_op;
942 if (!main_window->folder_view)
945 folder = modest_folder_view_get_selected (main_window->folder_view);
947 mail_op = modest_mail_operation_new ();
948 modest_mail_operation_remove_folder (mail_op, folder, move_to_trash);
949 g_object_unref (mail_op);
953 modest_ui_actions_on_delete_folder (GtkWidget *widget,
954 ModestMainWindow *main_window)
956 delete_folder (main_window, FALSE);
960 modest_ui_actions_on_move_to_trash_folder (GtkWidget *widget,
961 ModestMainWindow *main_window)
963 delete_folder (main_window, TRUE);
967 modest_ui_actions_on_accounts_reloaded (TnyAccountStore *store, gpointer user_data)
970 /* ModestFolderView *folder_view; */
972 /* folder_view = modest_widget_factory_get_folder_view (modest_runtime_get_widget_factory()); */
973 /* modest_folder_view_update_model (folder_view, store); */
977 modest_ui_actions_on_folder_moved (ModestFolderView *folder_view, TnyFolder *folder,
978 TnyFolderStore *parent, gboolean *done,
981 ModestMailOperation *mail_op;
986 /* Try to move the folder */
987 mail_op = modest_mail_operation_new ();
988 modest_mail_operation_move_folder (mail_op, folder, parent);
990 error = modest_mail_operation_get_error (mail_op);
994 g_object_unref (G_OBJECT (mail_op));