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_toggle_view (GtkWidget *widget, ModestMainWindow *main_window)
368 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
370 if (!main_window->header_view)
372 conf = modest_runtime_get_conf ();
374 /* what is saved/restored is depending on the style; thus; we save with
375 * old style, then update the style, and restore for this new style*/
376 modest_widget_memory_save (conf, G_OBJECT(main_window->header_view), "header-view");
378 if (modest_header_view_get_style (main_window->header_view) == MODEST_HEADER_VIEW_STYLE_DETAILS)
379 modest_header_view_set_style (main_window->header_view,
380 MODEST_HEADER_VIEW_STYLE_TWOLINES);
382 modest_header_view_set_style (main_window->header_view,
383 MODEST_HEADER_VIEW_STYLE_DETAILS);
385 modest_widget_memory_restore (conf, G_OBJECT(main_window->header_view),
392 * Marks a message as read and passes it to the msg preview widget
395 read_msg_func (gpointer data, gpointer user_data)
399 GetMsgAsyncHelper *helper;
400 TnyHeaderFlags header_flags;
402 msg = TNY_MSG (data);
403 helper = (GetMsgAsyncHelper *) user_data;
405 if (!helper->main_window->msg_preview)
408 /* mark message as seen; _set_flags crashes, bug in tinymail? */
409 header = TNY_HEADER (tny_iterator_get_current (helper->iter));
410 header_flags = tny_header_get_flags (header);
411 tny_header_set_flags (header, header_flags | TNY_HEADER_FLAG_SEEN);
412 g_object_unref (G_OBJECT (header));
414 /* Set message on msg view */
415 modest_msg_view_set_message (helper->main_window->msg_preview,
420 * This function is a generic handler for the tny_folder_get_msg_async
421 * call. It expects as user_data a #GetMsgAsyncHelper. This helper
422 * contains a user provided function that is called inside this
423 * method. This will allow us to use this callback in many different
424 * places. This callback performs the common actions for the
425 * get_msg_async call, more specific actions will be done by the user
429 get_msg_cb (TnyFolder *folder, TnyMsg *msg, GError **err, gpointer user_data)
431 GetMsgAsyncHelper *helper;
433 helper = (GetMsgAsyncHelper *) user_data;
435 if ((*err && ((*err)->code == TNY_FOLDER_ERROR_GET_MSG)) || !msg) {
436 ModestHeaderView *header_view =
437 helper->main_window->header_view;
439 modest_ui_actions_on_item_not_found (header_view,
440 MODEST_ITEM_TYPE_MESSAGE,
441 MODEST_WINDOW(helper->main_window));
445 /* Call user function */
446 helper->func (msg, user_data);
448 /* Process next element (if exists) */
449 tny_iterator_next (helper->iter);
450 if (tny_iterator_is_done (helper->iter)) {
452 headers = tny_iterator_get_list (helper->iter);
454 g_object_unref (G_OBJECT (headers));
455 g_object_unref (G_OBJECT (helper->iter));
456 g_slice_free (GetMsgAsyncHelper, helper);
459 header = TNY_HEADER (tny_iterator_get_current (helper->iter));
460 tny_folder_get_msg_async (folder, header,
462 g_object_unref (G_OBJECT(header));
467 modest_ui_actions_on_header_selected (ModestHeaderView *folder_view, TnyHeader *header,
468 ModestMainWindow *main_window)
471 GetMsgAsyncHelper *helper;
474 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
476 if (!main_window->msg_preview)
479 /* when there's no header, clear the msgview */
481 modest_msg_view_set_message (main_window->msg_preview, NULL);
485 folder = tny_header_get_folder (TNY_HEADER(header));
488 list = tny_simple_list_new ();
489 tny_list_prepend (list, G_OBJECT (header));
491 /* Fill helper data */
492 helper = g_slice_new0 (GetMsgAsyncHelper);
493 helper->main_window = main_window;
494 helper->iter = tny_list_create_iterator (list);
495 helper->func = read_msg_func;
497 tny_folder_get_msg_async (TNY_FOLDER(folder),
502 g_object_unref (G_OBJECT (folder));
508 modest_ui_actions_on_header_activated (ModestHeaderView *folder_view, TnyHeader *header,
509 ModestMainWindow *main_window)
512 TnyFolder *folder = NULL;
515 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
520 folder = tny_header_get_folder (header);
522 g_printerr ("modest: cannot get folder for header\n");
526 /* FIXME: make async?; check error */
527 msg = tny_folder_get_msg (folder, header, NULL);
529 g_printerr ("modest: cannot get msg for header\n");
533 win = modest_msg_view_window_new (msg);
534 gtk_window_set_transient_for (GTK_WINDOW (win),
535 GTK_WINDOW (main_window));
537 gtk_widget_show_all (GTK_WIDGET(win));
541 g_object_unref (G_OBJECT (folder));
543 g_object_unref (G_OBJECT (folder));
551 modest_ui_actions_on_folder_selection_changed (ModestFolderView *folder_view,
554 ModestMainWindow *main_window)
556 // GtkLabel *folder_info_label;
560 /* folder_info_label = */
561 /* GTK_LABEL (modest_widget_factory_get_folder_info_label */
562 /* (modest_runtime_get_widget_factory())); */
565 /* gtk_label_set_label (GTK_LABEL(folder_info_label), ""); */
569 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
571 if (!main_window->header_view)
574 conf = modest_runtime_get_conf ();
576 if (!selected) { /* the folder was unselected; save it's settings */
577 modest_widget_memory_save (conf, G_OBJECT (main_window->header_view),
579 gtk_window_set_title (GTK_WINDOW(main_window), "Modest");
580 modest_header_view_set_folder (main_window->header_view, NULL);
581 } else { /* the folder was selected */
582 if (folder) { /* folder may be NULL */
586 num = tny_folder_get_all_count (folder);
587 unread = tny_folder_get_unread_count (folder);
589 title = g_strdup_printf ("Modest: %s",
590 tny_folder_get_name (folder));
592 gtk_window_set_title (GTK_WINDOW(main_window), title);
595 txt = g_strdup_printf (_("%d %s, %d unread"),
596 num, num==1 ? _("item") : _("items"), unread);
597 //gtk_label_set_label (GTK_LABEL(folder_info_label), txt);
600 modest_header_view_set_folder (main_window->header_view, folder);
601 modest_widget_memory_restore (conf, G_OBJECT(main_window->header_view),
607 /****************************************************/
609 * below some stuff to clearup statusbar messages after 1,5 seconds....
612 progress_bar_clean (GtkWidget *bar)
614 if (GTK_IS_PROGRESS_BAR(bar)) {
615 gtk_progress_bar_set_text (GTK_PROGRESS_BAR(bar), "");
616 gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(bar), 1.0);
622 statusbar_clean (GtkWidget *bar)
624 if (GTK_IS_STATUSBAR(bar))
625 gtk_statusbar_push (GTK_STATUSBAR(bar), 0, "");
631 statusbar_push (ModestMainWindow *main_window, guint context_id, const gchar *msg)
636 if (main_window->progress_bar) {
637 gtk_widget_show (main_window->progress_bar);
638 g_timeout_add (3000, (GSourceFunc)progress_bar_clean,
639 main_window->progress_bar);
642 if (main_window->status_bar) {
643 gtk_widget_show (main_window->status_bar);
644 gtk_statusbar_push (GTK_STATUSBAR(main_window->status_bar), 0, msg);
645 g_timeout_add (1500, (GSourceFunc)statusbar_clean, main_window->status_bar);
649 /****************************************************************************/
652 modest_ui_actions_on_item_not_found (ModestHeaderView *header_view,ModestItemType type,
659 TnyAccountStore *account_store;
661 item = (type == MODEST_ITEM_TYPE_FOLDER) ? "folder" : "message";
663 /* Get device. Do not ask the platform factory for it, because
664 it returns always a new one */
665 account_store = TNY_ACCOUNT_STORE (modest_runtime_get_account_store ());
666 device = tny_account_store_get_device (account_store);
668 if (g_main_depth > 0)
669 gdk_threads_enter ();
670 online = tny_device_is_online (device);
673 /* already online -- the item is simply not there... */
674 dialog = gtk_message_dialog_new (GTK_WINDOW (win),
678 _("The %s you selected cannot be found"),
680 gtk_dialog_run (GTK_DIALOG(dialog));
683 dialog = gtk_dialog_new_with_buttons (_("Connection requested"),
692 txt = g_strdup_printf (_("This %s is not available in offline mode.\n"
693 "Do you want to get online?"), item);
694 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
695 gtk_label_new (txt), FALSE, FALSE, 0);
696 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
699 gtk_window_set_default_size (GTK_WINDOW(dialog), 300, 300);
700 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
701 tny_device_force_online (device);
704 gtk_widget_destroy (dialog);
705 if (g_main_depth > 0)
706 gdk_threads_leave ();
712 modest_ui_actions_on_header_status_update (ModestHeaderView *header_view,
713 const gchar *msg, gint num,
714 gint total, ModestMainWindow *main_window)
718 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
720 if (!main_window->progress_bar)
724 gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(main_window->progress_bar),
725 (gdouble)num/(gdouble)total);
727 gtk_progress_bar_pulse (GTK_PROGRESS_BAR(main_window->progress_bar));
729 txt = g_strdup_printf (_("Downloading %d of %d"), num, total);
730 gtk_progress_bar_set_text (GTK_PROGRESS_BAR(main_window->progress_bar), txt);
733 statusbar_push (main_window, 0, msg);
738 modest_ui_actions_on_msg_link_hover (ModestMsgView *msgview, const gchar* link,
741 g_warning (__FUNCTION__);
746 modest_ui_actions_on_msg_link_clicked (ModestMsgView *msgview, const gchar* link,
749 g_warning (__FUNCTION__);
753 modest_ui_actions_on_msg_attachment_clicked (ModestMsgView *msgview, int index,
756 g_warning (__FUNCTION__);
761 modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
763 TnyTransportAccount *transport_account;
764 ModestMailOperation *mail_operation;
766 gchar *account_name, *from;
767 ModestAccountMgr *account_mgr;
769 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window));
771 data = modest_msg_edit_window_get_msg_data (edit_window);
773 /* FIXME: Code added just for testing. The final version will
774 use the send queue provided by tinymail and some
776 account_mgr = modest_runtime_get_account_mgr();
777 account_name = modest_account_mgr_get_default_account (account_mgr);
779 g_printerr ("modest: no default account found\n");
780 modest_msg_edit_window_free_msg_data (edit_window, data);
784 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_tny_account_by_account
785 (modest_runtime_get_account_store(),
787 TNY_ACCOUNT_TYPE_TRANSPORT));
788 if (!transport_account) {
789 g_printerr ("modest: no transport account found for '%s'\n", account_name);
790 g_free (account_name);
791 modest_msg_edit_window_free_msg_data (edit_window, data);
794 from = modest_account_mgr_get_from_string (account_mgr, account_name);
796 mail_operation = modest_mail_operation_new ();
797 modest_mail_operation_send_new_mail (mail_operation,
808 g_free (account_name);
809 g_object_unref (G_OBJECT (mail_operation));
810 g_object_unref (G_OBJECT (transport_account));
812 modest_msg_edit_window_free_msg_data (edit_window, data);
814 /* Save settings and close the window */
815 /* save_settings (edit_window) */
816 gtk_widget_destroy (GTK_WIDGET (edit_window));
820 * Shows a dialog with an entry that asks for some text. The returned
821 * value must be freed by the caller. The dialog window title will be
825 ask_for_folder_name (GtkWindow *parent_window,
828 GtkWidget *dialog, *entry;
829 gchar *folder_name = NULL;
831 /* Ask for folder name */
832 dialog = gtk_dialog_new_with_buttons (_("New Folder Name"),
840 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
841 gtk_label_new(title),
844 entry = gtk_entry_new_with_max_length (40);
845 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
849 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
851 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
852 folder_name = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry)));
854 gtk_widget_destroy (dialog);
860 modest_ui_actions_on_new_folder (GtkWidget *widget, ModestMainWindow *main_window)
862 TnyFolder *parent_folder;
864 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
866 if (!main_window->folder_view)
869 parent_folder = modest_folder_view_get_selected (main_window->folder_view);
874 folder_name = ask_for_folder_name (GTK_WINDOW (main_window),
875 _("Please enter a name for the new folder"));
877 if (folder_name != NULL && strlen (folder_name) > 0) {
878 TnyFolder *new_folder;
879 ModestMailOperation *mail_op;
881 mail_op = modest_mail_operation_new ();
882 new_folder = modest_mail_operation_create_folder (mail_op,
883 TNY_FOLDER_STORE (parent_folder),
884 (const gchar *) folder_name);
886 /* TODO: tinymail should do this.
888 modest_folder_view_add_subfolder (main_window->folder_view, new_folder);
890 /* Free new folder */
891 g_object_unref (new_folder);
893 g_object_unref (mail_op);
895 g_object_unref (parent_folder);
900 modest_ui_actions_on_rename_folder (GtkWidget *widget,
901 ModestMainWindow *main_window)
905 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
907 if (!main_window->folder_view)
910 folder = modest_folder_view_get_selected (main_window->folder_view);
915 folder_name = ask_for_folder_name (GTK_WINDOW (main_window),
916 _("Please enter a new name for the folder"));
918 if (folder_name != NULL && strlen (folder_name) > 0) {
919 ModestMailOperation *mail_op;
922 mail_op = modest_mail_operation_new ();
923 modest_mail_operation_rename_folder (mail_op,
925 (const gchar *) folder_name);
927 error = modest_mail_operation_get_error (mail_op);
929 /* TODO: tinymail should do this.
931 modest_folder_view_rename (main_window->folder_view);
933 /* TODO: else ? notify error ? */
935 g_object_unref (mail_op);
937 g_object_unref (folder);
942 delete_folder (ModestMainWindow *main_window, gboolean move_to_trash)
945 ModestMailOperation *mail_op;
947 if (!main_window->folder_view)
950 folder = modest_folder_view_get_selected (main_window->folder_view);
952 mail_op = modest_mail_operation_new ();
953 modest_mail_operation_remove_folder (mail_op, folder, move_to_trash);
954 g_object_unref (mail_op);
958 modest_ui_actions_on_delete_folder (GtkWidget *widget,
959 ModestMainWindow *main_window)
961 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
963 delete_folder (main_window, FALSE);
967 modest_ui_actions_on_move_folder_to_trash_folder (GtkWidget *widget, ModestMainWindow *main_window)
969 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
971 delete_folder (main_window, TRUE);
975 modest_ui_actions_on_accounts_reloaded (TnyAccountStore *store, gpointer user_data)
978 /* ModestFolderView *folder_view; */
980 /* folder_view = modest_widget_factory_get_folder_view (modest_runtime_get_widget_factory()); */
981 /* modest_folder_view_update_model (folder_view, store); */
985 modest_ui_actions_on_folder_moved (ModestFolderView *folder_view, TnyFolder *folder,
986 TnyFolderStore *parent, gboolean *done,
989 ModestMailOperation *mail_op;
994 /* Try to move the folder */
995 mail_op = modest_mail_operation_new ();
996 modest_mail_operation_move_folder (mail_op, folder, parent);
998 error = modest_mail_operation_get_error (mail_op);
1002 g_object_unref (G_OBJECT (mail_op));