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>
35 #include <glib/gprintf.h>
37 #include <modest-runtime.h>
38 #include <modest-tny-folder.h>
39 #include <modest-tny-msg.h>
40 #include <modest-tny-account.h>
41 #include <modest-address-book.h>
42 #include "modest-error.h"
43 #include "modest-ui-actions.h"
44 #include "modest-protocol-info.h"
45 #include "modest-tny-platform-factory.h"
46 #include "modest-platform.h"
47 #include "modest-debug.h"
48 #include <tny-mime-part.h>
49 #include <tny-camel-folder.h>
50 #include <tny-camel-imap-folder.h>
51 #include <tny-camel-pop-folder.h>
53 #ifdef MODEST_PLATFORM_MAEMO
54 #include "maemo/modest-osso-state-saving.h"
55 #include "maemo/modest-hildon-includes.h"
56 #include "maemo/modest-connection-specific-smtp-window.h"
57 #endif /* MODEST_PLATFORM_MAEMO */
58 #include <modest-utils.h>
60 #include "widgets/modest-ui-constants.h"
61 #include <widgets/modest-main-window.h>
62 #include <widgets/modest-msg-view-window.h>
63 #include <widgets/modest-account-view-window.h>
64 #include <widgets/modest-details-dialog.h>
65 #include <widgets/modest-attachments-view.h>
66 #include "widgets/modest-folder-view.h"
67 #include "widgets/modest-global-settings-dialog.h"
68 #include "modest-account-mgr-helpers.h"
69 #include "modest-mail-operation.h"
70 #include "modest-text-utils.h"
72 #ifdef MODEST_HAVE_EASYSETUP
73 #include "easysetup/modest-easysetup-wizard-dialog.h"
74 #endif /* MODEST_HAVE_EASYSETUP */
76 #include <modest-widget-memory.h>
77 #include <tny-error.h>
78 #include <tny-simple-list.h>
79 #include <tny-msg-view.h>
80 #include <tny-device.h>
81 #include <tny-merge-folder.h>
83 #include <gtkhtml/gtkhtml.h>
85 #define MIN_FREE_SPACE 5 * 1024 * 1024
87 typedef struct _GetMsgAsyncHelper {
89 ModestMailOperation *mail_op;
96 typedef enum _ReplyForwardAction {
100 } ReplyForwardAction;
102 typedef struct _ReplyForwardHelper {
103 guint reply_forward_type;
104 ReplyForwardAction action;
106 GtkWidget *parent_window;
108 } ReplyForwardHelper;
110 typedef struct _MoveToHelper {
111 GtkTreeRowReference *reference;
115 typedef struct _PasteAsAttachmentHelper {
116 ModestMsgEditWindow *window;
118 } PasteAsAttachmentHelper;
122 * The do_headers_action uses this kind of functions to perform some
123 * action to each member of a list of headers
125 typedef void (*HeadersFunc) (TnyHeader *header, ModestWindow *win, gpointer user_data);
127 static void do_headers_action (ModestWindow *win,
131 static void open_msg_cb (ModestMailOperation *mail_op,
138 static void reply_forward_cb (ModestMailOperation *mail_op,
145 static void reply_forward (ReplyForwardAction action, ModestWindow *win);
147 static void folder_refreshed_cb (ModestMailOperation *mail_op,
151 static void on_send_receive_finished (ModestMailOperation *mail_op,
154 static gint header_list_count_uncached_msgs (TnyList *header_list);
156 static gboolean connect_to_get_msg (ModestWindow *win,
157 gint num_of_uncached_msgs,
158 TnyAccount *account);
160 static gboolean remote_folder_is_pop (TnyFolderStore *folder);
162 static void do_create_folder (GtkWindow *window,
163 TnyFolderStore *parent_folder,
164 const gchar *suggested_name);
166 static GtkWidget* get_folder_view_from_move_to_dialog (GtkWidget *move_to_dialog);
168 static TnyAccount *get_account_from_folder_store (TnyFolderStore *folder_store);
171 * This function checks whether a TnyFolderStore is a pop account
174 remote_folder_is_pop (TnyFolderStore *folder)
176 const gchar *proto = NULL;
177 TnyAccount *account = NULL;
179 g_return_val_if_fail (TNY_IS_FOLDER_STORE (folder), FALSE);
181 account = get_account_from_folder_store (folder);
182 proto = tny_account_get_proto (account);
183 g_object_unref (account);
185 return (modest_protocol_info_get_transport_store_protocol (proto) == MODEST_PROTOCOL_STORE_POP);
188 /* FIXME: this should be merged with the similar code in modest-account-view-window */
189 /* Show the account creation wizard dialog.
190 * returns: TRUE if an account was created. FALSE if the user cancelled.
193 modest_ui_actions_run_account_setup_wizard (ModestWindow *win)
195 gboolean result = FALSE;
196 GtkWindow *dialog, *wizard;
197 gint dialog_response;
199 /* Show the easy-setup wizard: */
200 dialog = modest_window_mgr_get_modal (modest_runtime_get_window_mgr());
202 /* old wizard is active already;
204 gtk_window_present (GTK_WINDOW(dialog));
209 /* there is no such wizard yet */
210 wizard = GTK_WINDOW (modest_platform_get_account_settings_wizard ());
211 modest_window_mgr_set_modal (modest_runtime_get_window_mgr(), wizard);
213 /* always present a main window in the background
214 * we do it here, so we cannot end up with two wizards (as this
215 * function might be called in modest_window_mgr_get_main_window as well */
217 win = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr(),
218 TRUE); /* create if not existent */
220 /* make sure the mainwindow is visible */
221 gtk_window_set_transient_for (GTK_WINDOW (wizard), GTK_WINDOW (win));
222 gtk_widget_show_all (GTK_WIDGET(win));
223 gtk_window_present (GTK_WINDOW(win));
225 dialog_response = gtk_dialog_run (GTK_DIALOG (wizard));
226 gtk_widget_destroy (GTK_WIDGET (wizard));
227 if (gtk_events_pending ())
228 gtk_main_iteration ();
230 if (dialog_response == GTK_RESPONSE_CANCEL) {
233 /* Check whether an account was created: */
234 result = modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
241 modest_ui_actions_on_about (GtkAction *action, ModestWindow *win)
244 const gchar *authors[] = {
245 "Dirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>",
248 about = gtk_about_dialog_new ();
249 gtk_about_dialog_set_name (GTK_ABOUT_DIALOG(about), PACKAGE_NAME);
250 gtk_about_dialog_set_version (GTK_ABOUT_DIALOG(about),PACKAGE_VERSION);
251 gtk_about_dialog_set_copyright (GTK_ABOUT_DIALOG(about),
252 _("Copyright (c) 2006, Nokia Corporation\n"
253 "All rights reserved."));
254 gtk_about_dialog_set_comments (GTK_ABOUT_DIALOG(about),
255 _("a modest e-mail client\n\n"
256 "design and implementation: Dirk-Jan C. Binnema\n"
257 "contributions from the fine people at KC and Ig\n"
258 "uses the tinymail email framework written by Philip van Hoof"));
259 gtk_about_dialog_set_authors (GTK_ABOUT_DIALOG(about), authors);
260 gtk_about_dialog_set_website (GTK_ABOUT_DIALOG(about), "http://modest.garage.maemo.org");
261 gtk_window_set_transient_for (GTK_WINDOW (about), GTK_WINDOW (win));
262 gtk_window_set_modal (GTK_WINDOW (about), TRUE);
264 gtk_dialog_run (GTK_DIALOG (about));
265 gtk_widget_destroy(about);
269 * Gets the list of currently selected messages. If the win is the
270 * main window, then it returns a newly allocated list of the headers
271 * selected in the header view. If win is the msg view window, then
272 * the value returned is a list with just a single header.
274 * The caller of this funcion must free the list.
277 get_selected_headers (ModestWindow *win)
279 if (MODEST_IS_MAIN_WINDOW(win)) {
280 GtkWidget *header_view;
282 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
283 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
284 return modest_header_view_get_selected_headers (MODEST_HEADER_VIEW(header_view));
286 } else if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
287 /* for MsgViewWindows, we simply return a list with one element */
289 TnyList *list = NULL;
291 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
292 if (header != NULL) {
293 list = tny_simple_list_new ();
294 tny_list_prepend (list, G_OBJECT(header));
295 g_object_unref (G_OBJECT(header));
304 static GtkTreeRowReference *
305 get_next_after_selected_headers (ModestHeaderView *header_view)
307 GtkTreeSelection *sel;
308 GList *selected_rows, *node;
310 GtkTreeRowReference *result;
313 model = gtk_tree_view_get_model (GTK_TREE_VIEW (header_view));
314 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
315 selected_rows = gtk_tree_selection_get_selected_rows (sel, NULL);
317 if (selected_rows == NULL)
320 node = g_list_last (selected_rows);
321 path = gtk_tree_path_copy ((GtkTreePath *) node->data);
322 gtk_tree_path_next (path);
324 result = gtk_tree_row_reference_new (model, path);
326 gtk_tree_path_free (path);
327 g_list_foreach (selected_rows, (GFunc) gtk_tree_path_free, NULL);
328 g_list_free (selected_rows);
334 headers_action_mark_as_read (TnyHeader *header,
338 TnyHeaderFlags flags;
340 g_return_if_fail (TNY_IS_HEADER(header));
342 flags = tny_header_get_flags (header);
343 if (flags & TNY_HEADER_FLAG_SEEN) return;
344 tny_header_set_flag (header, TNY_HEADER_FLAG_SEEN);
348 headers_action_mark_as_unread (TnyHeader *header,
352 TnyHeaderFlags flags;
354 g_return_if_fail (TNY_IS_HEADER(header));
356 flags = tny_header_get_flags (header);
357 if (flags & TNY_HEADER_FLAG_SEEN) {
358 tny_header_unset_flag (header, TNY_HEADER_FLAG_SEEN);
362 /** After deleing a message that is currently visible in a window,
363 * show the next message from the list, or close the window if there are no more messages.
366 modest_ui_actions_refresh_message_window_after_delete (ModestMsgViewWindow* win)
368 /* Close msg view window or select next */
369 if (!modest_msg_view_window_select_next_message (win) &&
370 !modest_msg_view_window_select_previous_message (win)) {
372 g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value);
378 modest_ui_actions_on_delete_message (GtkAction *action, ModestWindow *win)
380 TnyList *header_list = NULL;
381 TnyIterator *iter = NULL;
382 TnyHeader *header = NULL;
383 gchar *message = NULL;
386 ModestWindowMgr *mgr;
387 GtkWidget *header_view = NULL;
389 g_return_if_fail (MODEST_IS_WINDOW(win));
391 /* Check first if the header view has the focus */
392 if (MODEST_IS_MAIN_WINDOW (win)) {
394 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
395 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
396 if (!gtk_widget_is_focus (header_view))
400 /* Get the headers, either from the header view (if win is the main window),
401 * or from the message view window: */
402 header_list = get_selected_headers (win);
403 if (!header_list) return;
405 /* Check if any of the headers are already opened, or in the process of being opened */
406 if (MODEST_IS_MAIN_WINDOW (win)) {
407 gint opened_headers = 0;
409 iter = tny_list_create_iterator (header_list);
410 mgr = modest_runtime_get_window_mgr ();
411 while (!tny_iterator_is_done (iter)) {
412 header = TNY_HEADER (tny_iterator_get_current (iter));
414 if (modest_window_mgr_find_registered_header (mgr, header, NULL))
416 g_object_unref (header);
418 tny_iterator_next (iter);
420 g_object_unref (iter);
422 if (opened_headers > 0) {
425 msg = g_strdup_printf (_("mcen_nc_unable_to_delete_n_messages"),
428 modest_platform_run_information_dialog (GTK_WINDOW (win), (const gchar *) msg, FALSE);
431 g_object_unref (header_list);
437 if (tny_list_get_length(header_list) == 1) {
438 iter = tny_list_create_iterator (header_list);
439 header = TNY_HEADER (tny_iterator_get_current (iter));
442 subject = tny_header_dup_subject (header);
443 desc = g_strdup_printf ("%s", subject);
445 g_object_unref (header);
448 g_object_unref (iter);
450 message = g_strdup_printf(ngettext("emev_nc_delete_message", "emev_nc_delete_messages",
451 tny_list_get_length(header_list)), desc);
453 /* Confirmation dialog */
454 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
458 if (response == GTK_RESPONSE_OK) {
459 ModestWindow *main_window = NULL;
460 ModestWindowMgr *mgr = NULL;
461 GtkTreeModel *model = NULL;
462 GtkTreeSelection *sel = NULL;
463 GList *sel_list = NULL, *tmp = NULL;
464 GtkTreeRowReference *next_row_reference = NULL;
465 GtkTreeRowReference *prev_row_reference = NULL;
466 GtkTreePath *next_path = NULL;
467 GtkTreePath *prev_path = NULL;
468 ModestMailOperation *mail_op = NULL;
470 /* Find last selected row */
471 if (MODEST_IS_MAIN_WINDOW (win)) {
472 model = gtk_tree_view_get_model (GTK_TREE_VIEW (header_view));
473 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
474 sel_list = gtk_tree_selection_get_selected_rows (sel, &model);
475 for (tmp=sel_list; tmp; tmp=tmp->next) {
476 if (tmp->next == NULL) {
477 prev_path = gtk_tree_path_copy((GtkTreePath *) tmp->data);
478 next_path = gtk_tree_path_copy((GtkTreePath *) tmp->data);
480 gtk_tree_path_prev (prev_path);
481 gtk_tree_path_next (next_path);
483 prev_row_reference = gtk_tree_row_reference_new (model, prev_path);
484 next_row_reference = gtk_tree_row_reference_new (model, next_path);
489 /* Disable window dimming management */
490 modest_window_disable_dimming (MODEST_WINDOW(win));
492 /* Remove each header. If it's a view window header_view == NULL */
493 mail_op = modest_mail_operation_new ((GObject *) win);
494 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
496 modest_mail_operation_remove_msgs (mail_op, header_list, FALSE);
497 g_object_unref (mail_op);
499 /* Enable window dimming management */
501 gtk_tree_selection_unselect_all (sel);
503 modest_window_enable_dimming (MODEST_WINDOW(win));
505 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
506 modest_ui_actions_refresh_message_window_after_delete (MODEST_MSG_VIEW_WINDOW (win));
508 /* Get main window */
509 mgr = modest_runtime_get_window_mgr ();
510 main_window = modest_window_mgr_get_main_window (mgr, FALSE); /* don't create */
512 /* Move cursor to next row */
515 /* Select next or previous row */
516 if (gtk_tree_row_reference_valid (next_row_reference)) {
517 /* next_path = gtk_tree_row_reference_get_path (row_reference); */
518 gtk_tree_selection_select_path (sel, next_path);
520 else if (gtk_tree_row_reference_valid (prev_row_reference)) {
521 gtk_tree_selection_select_path (sel, prev_path);
525 if (next_row_reference != NULL)
526 gtk_tree_row_reference_free (next_row_reference);
527 if (next_path != NULL)
528 gtk_tree_path_free (next_path);
529 if (prev_row_reference != NULL)
530 gtk_tree_row_reference_free (prev_row_reference);
531 if (prev_path != NULL)
532 gtk_tree_path_free (prev_path);
535 /* Update toolbar dimming state */
537 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
540 g_list_foreach (sel_list, (GFunc) gtk_tree_path_free, NULL);
541 g_list_free (sel_list);
547 g_object_unref (header_list);
553 /* delete either message or folder, based on where we are */
555 modest_ui_actions_on_delete_message_or_folder (GtkAction *action, ModestWindow *win)
557 g_return_if_fail (MODEST_IS_WINDOW(win));
559 /* Check first if the header view has the focus */
560 if (MODEST_IS_MAIN_WINDOW (win)) {
562 w = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
563 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
564 if (gtk_widget_is_focus (w)) {
565 modest_ui_actions_on_delete_folder (action, MODEST_MAIN_WINDOW(win));
569 modest_ui_actions_on_delete_message (action, win);
573 modest_ui_actions_on_quit (GtkAction *action, ModestWindow *win)
575 ModestWindowMgr *mgr = NULL;
577 #ifdef MODEST_PLATFORM_MAEMO
578 modest_osso_save_state();
579 #endif /* MODEST_PLATFORM_MAEMO */
581 g_debug ("closing down, clearing %d item(s) from operation queue",
582 modest_mail_operation_queue_num_elements
583 (modest_runtime_get_mail_operation_queue()));
585 /* cancel all outstanding operations */
586 modest_mail_operation_queue_cancel_all
587 (modest_runtime_get_mail_operation_queue());
589 g_debug ("queue has been cleared");
592 /* Check if there are opened editing windows */
593 mgr = modest_runtime_get_window_mgr ();
594 modest_window_mgr_close_all_windows (mgr);
596 /* note: when modest-tny-account-store is finalized,
597 it will automatically set all network connections
600 /* gtk_main_quit (); */
604 modest_ui_actions_on_close_window (GtkAction *action, ModestWindow *win)
608 g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value);
610 /* if (MODEST_IS_MSG_VIEW_WINDOW (win)) { */
611 /* gtk_widget_destroy (GTK_WIDGET (win)); */
612 /* } else if (MODEST_IS_MSG_EDIT_WINDOW (win)) { */
613 /* gboolean ret_value; */
614 /* g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value); */
615 /* } else if (MODEST_IS_WINDOW (win)) { */
616 /* gtk_widget_destroy (GTK_WIDGET (win)); */
618 /* g_return_if_reached (); */
623 modest_ui_actions_on_add_to_contacts (GtkAction *action, ModestWindow *win)
625 GtkClipboard *clipboard = NULL;
626 gchar *selection = NULL;
628 clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
629 selection = gtk_clipboard_wait_for_text (clipboard);
631 /* Question: why is the clipboard being used here?
632 * It doesn't really make a lot of sense. */
636 modest_address_book_add_address (selection);
642 modest_ui_actions_on_accounts (GtkAction *action,
645 /* This is currently only implemented for Maemo */
646 if (!modest_account_mgr_has_accounts (modest_runtime_get_account_mgr(), TRUE)) {
647 if (!modest_ui_actions_run_account_setup_wizard (win))
648 g_debug ("%s: wizard was already running", __FUNCTION__);
652 /* Show the list of accounts */
653 GtkWindow *account_win = GTK_WINDOW (modest_account_view_window_new ());
655 /* The accounts dialog must be modal */
656 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (), account_win);
657 modest_utils_show_dialog_and_forget (GTK_WINDOW (win), GTK_DIALOG (account_win));
662 modest_ui_actions_on_smtp_servers (GtkAction *action, ModestWindow *win)
664 /* This is currently only implemented for Maemo,
665 * because it requires an API (libconic) to detect different connection
668 #ifdef MODEST_PLATFORM_MAEMO /* Defined in config.h */
670 /* Create the window if necessary: */
671 GtkWidget *specific_window = GTK_WIDGET (modest_connection_specific_smtp_window_new ());
672 modest_connection_specific_smtp_window_fill_with_connections (
673 MODEST_CONNECTION_SPECIFIC_SMTP_WINDOW (specific_window),
674 modest_runtime_get_account_mgr());
676 /* Show the window: */
677 modest_window_mgr_set_modal (modest_runtime_get_window_mgr (),
678 GTK_WINDOW (specific_window));
679 gtk_widget_show (specific_window);
680 #endif /* MODEST_PLATFORM_MAEMO */
684 modest_ui_actions_compose_msg(ModestWindow *win,
687 const gchar *bcc_str,
688 const gchar *subject_str,
689 const gchar *body_str,
691 gboolean set_as_modified)
693 gchar *account_name = NULL;
695 TnyAccount *account = NULL;
696 TnyFolder *folder = NULL;
697 gchar *from_str = NULL, *signature = NULL, *body = NULL;
698 gboolean use_signature = FALSE;
699 ModestWindow *msg_win = NULL;
700 ModestAccountMgr *mgr = modest_runtime_get_account_mgr();
701 ModestTnyAccountStore *store = modest_runtime_get_account_store();
702 GnomeVFSFileSize total_size, allowed_size;
704 /* we check for low-mem; in that case, show a warning, and don't allow
705 * composing a message with attachments
707 if (attachments && modest_platform_check_memory_low (win, TRUE))
710 account_name = modest_account_mgr_get_default_account(mgr);
712 g_printerr ("modest: no account found\n");
715 account = modest_tny_account_store_get_server_account (store, account_name, TNY_ACCOUNT_TYPE_STORE);
717 g_printerr ("modest: failed to get tnyaccount for '%s'\n", account_name);
720 folder = modest_tny_account_get_special_folder (account, TNY_FOLDER_TYPE_DRAFTS);
722 g_printerr ("modest: failed to find Drafts folder\n");
725 from_str = modest_account_mgr_get_from_string (mgr, account_name);
727 g_printerr ("modest: failed get from string for '%s'\n", account_name);
731 signature = modest_account_mgr_get_signature (mgr, account_name, &use_signature);
732 if (body_str != NULL) {
733 body = use_signature ? g_strconcat(body_str, "\n", signature, NULL) : g_strdup(body_str);
735 body = use_signature ? g_strconcat("\n", signature, NULL) : g_strdup("");
738 msg = modest_tny_msg_new (to_str, from_str, cc_str, bcc_str, subject_str, body, NULL, NULL, NULL);
740 g_printerr ("modest: failed to create new msg\n");
744 /* Create and register edit window */
745 /* This is destroyed by TODO. */
747 allowed_size = MODEST_MAX_ATTACHMENT_SIZE;
748 msg_win = modest_msg_edit_window_new (msg, account_name, FALSE);
749 while (attachments) {
751 modest_msg_edit_window_attach_file_one(
752 (ModestMsgEditWindow *)msg_win,
753 attachments->data, allowed_size);
755 if (total_size > allowed_size) {
756 g_warning ("%s: total size: %u",
757 __FUNCTION__, (unsigned int)total_size);
760 allowed_size -= total_size;
762 attachments = g_slist_next(attachments);
764 modest_window_mgr_register_window (modest_runtime_get_window_mgr(), msg_win);
765 modest_msg_edit_window_set_modified (MODEST_MSG_EDIT_WINDOW (msg_win), set_as_modified);
767 gtk_widget_show_all (GTK_WIDGET (msg_win));
773 g_free (account_name);
775 g_object_unref (G_OBJECT(account));
777 g_object_unref (G_OBJECT(folder));
779 g_object_unref (G_OBJECT(msg_win));
781 g_object_unref (G_OBJECT(msg));
785 modest_ui_actions_on_new_msg (GtkAction *action, ModestWindow *win)
787 /* if there are no accounts yet, just show the wizard */
788 if (!modest_account_mgr_has_accounts (modest_runtime_get_account_mgr(), TRUE))
789 if (!modest_ui_actions_run_account_setup_wizard (win))
792 modest_ui_actions_compose_msg(win, NULL, NULL, NULL, NULL, NULL, NULL, FALSE);
797 modest_ui_actions_msg_retrieval_check (ModestMailOperation *mail_op,
801 ModestMailOperationStatus status;
803 /* If there is no message or the operation was not successful */
804 status = modest_mail_operation_get_status (mail_op);
805 if (!msg || status != MODEST_MAIL_OPERATION_STATUS_SUCCESS) {
808 /* If it's a memory low issue, then show a banner */
809 error = modest_mail_operation_get_error (mail_op);
810 if (error && error->domain == MODEST_MAIL_OPERATION_ERROR &&
811 error->code == MODEST_MAIL_OPERATION_ERROR_LOW_MEMORY) {
812 GObject *source = modest_mail_operation_get_source (mail_op);
813 modest_platform_run_information_dialog (GTK_IS_WINDOW (source) ? GTK_WINDOW (source) : NULL,
814 dgettext("ke-recv","memr_ib_operation_disabled"),
816 g_object_unref (source);
819 /* Remove the header from the preregistered uids */
820 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (),
838 OpenMsgBannerInfo *banner_info;
839 GHashTable *row_refs_per_header;
843 open_msg_banner_idle (gpointer userdata)
845 OpenMsgBannerInfo *banner_info = (OpenMsgBannerInfo *) userdata;
847 gdk_threads_enter ();
848 banner_info->idle_handler = 0;
849 banner_info->banner = modest_platform_animation_banner (NULL, NULL, banner_info->message);
851 g_object_ref (banner_info->banner);
853 gdk_threads_leave ();
860 open_msg_cb (ModestMailOperation *mail_op,
867 ModestWindowMgr *mgr = NULL;
868 ModestWindow *parent_win = NULL;
869 ModestWindow *win = NULL;
870 TnyFolderType folder_type = TNY_FOLDER_TYPE_UNKNOWN;
871 gchar *account = NULL;
873 gboolean open_in_editor = FALSE;
874 OpenMsgHelper *helper = (OpenMsgHelper *) user_data;
876 /* Do nothing if there was any problem with the mail
877 operation. The error will be shown by the error_handler of
878 the mail operation */
879 if (!modest_ui_actions_msg_retrieval_check (mail_op, header, msg))
882 parent_win = (ModestWindow *) modest_mail_operation_get_source (mail_op);
883 folder = tny_header_get_folder (header);
885 /* Mark header as read */
886 headers_action_mark_as_read (header, MODEST_WINDOW(parent_win), NULL);
888 /* Gets folder type (OUTBOX headers will be opened in edit window */
889 if (modest_tny_folder_is_local_folder (folder)) {
890 folder_type = modest_tny_folder_get_local_or_mmc_folder_type (folder);
891 if (folder_type == TNY_FOLDER_TYPE_INVALID)
892 g_warning ("%s: BUG: TNY_FOLDER_TYPE_INVALID", __FUNCTION__);
896 if (folder_type == TNY_FOLDER_TYPE_OUTBOX) {
897 TnyTransportAccount *traccount = NULL;
898 ModestTnyAccountStore *accstore = modest_runtime_get_account_store();
899 traccount = modest_tny_account_store_get_transport_account_from_outbox_header(accstore, header);
901 ModestTnySendQueue *send_queue = NULL;
902 ModestTnySendQueueStatus status;
904 account = g_strdup(modest_tny_account_get_parent_modest_account_name_for_server_account(
905 TNY_ACCOUNT(traccount)));
906 send_queue = modest_runtime_get_send_queue(traccount, TRUE);
907 if (TNY_IS_SEND_QUEUE (send_queue)) {
908 msg_id = modest_tny_send_queue_get_msg_id (header);
909 status = modest_tny_send_queue_get_msg_status(send_queue, msg_id);
910 /* Only open messages in outbox with the editor if they are in Failed state */
911 if (status == MODEST_TNY_SEND_QUEUE_FAILED) {
912 open_in_editor = TRUE;
916 g_object_unref(traccount);
918 g_warning("Cannot get transport account for message in outbox!!");
920 } else if (folder_type == TNY_FOLDER_TYPE_DRAFTS) {
921 open_in_editor = TRUE; /* Open in editor if the message is in the Drafts folder */
926 account = g_strdup (modest_window_get_active_account (MODEST_WINDOW (parent_win)));
928 account = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
930 if (open_in_editor) {
931 ModestAccountMgr *mgr = modest_runtime_get_account_mgr ();
932 gchar *from_header = NULL;
934 from_header = tny_header_dup_from (header);
936 /* we cannot edit without a valid account... */
937 if (!modest_account_mgr_has_accounts(mgr, TRUE)) {
938 if (!modest_ui_actions_run_account_setup_wizard(parent_win)) {
939 modest_window_mgr_unregister_header (modest_runtime_get_window_mgr (),
941 g_free (from_header);
947 GSList *accounts = modest_account_mgr_account_names (mgr, TRUE);
950 for (node = accounts; node != NULL; node = g_slist_next (node)) {
951 gchar *from = modest_account_mgr_get_from_string (mgr, node->data);
953 if (from && (strcmp (from_header, from) == 0)) {
955 account = g_strdup (node->data);
962 g_free (from_header);
963 g_slist_foreach (accounts, (GFunc) g_free, NULL);
964 g_slist_free (accounts);
967 win = modest_msg_edit_window_new (msg, account, TRUE);
972 gchar *uid = modest_tny_folder_get_header_unique_id (header);
974 if (MODEST_IS_MAIN_WINDOW (parent_win)) {
975 GtkTreeRowReference *row_reference;
977 row_reference = (GtkTreeRowReference *) g_hash_table_lookup (helper->row_refs_per_header, header);
979 win = modest_msg_view_window_new_with_header_model (msg, account, (const gchar*) uid,
980 helper->model, row_reference);
982 win = modest_msg_view_window_new_for_attachment (msg, account, (const gchar*) uid);
987 /* Register and show new window */
989 mgr = modest_runtime_get_window_mgr ();
990 modest_window_mgr_register_window (mgr, win);
991 g_object_unref (win);
992 gtk_widget_show_all (GTK_WIDGET(win));
995 /* Update toolbar dimming state */
996 if (MODEST_IS_MAIN_WINDOW (parent_win)) {
997 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (parent_win));
1003 g_object_unref (parent_win);
1004 g_object_unref (folder);
1008 is_memory_full_error (GError *error)
1010 gboolean enough_free_space = TRUE;
1011 GnomeVFSURI *cache_dir_uri;
1012 const gchar *cache_dir;
1013 GnomeVFSFileSize free_space;
1015 cache_dir = tny_account_store_get_cache_dir (TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()));
1016 cache_dir_uri = gnome_vfs_uri_new (cache_dir);
1017 if (gnome_vfs_get_volume_free_space (cache_dir_uri, &free_space) == GNOME_VFS_OK) {
1018 if (free_space < MIN_FREE_SPACE)
1019 enough_free_space = FALSE;
1021 gnome_vfs_uri_unref (cache_dir_uri);
1023 if ((error->code == TNY_SYSTEM_ERROR_MEMORY ||
1024 error->code == TNY_IO_ERROR_WRITE ||
1025 error->code == TNY_IO_ERROR_READ) &&
1026 !enough_free_space) {
1034 check_memory_full_error (GtkWidget *parent_window, GError *err)
1039 if (is_memory_full_error (err))
1040 modest_platform_information_banner (parent_window,
1041 NULL, dgettext("ke-recv",
1042 "cerm_device_memory_full"));
1043 else if (err->code == TNY_SYSTEM_ERROR_MEMORY)
1044 /* If the account was created in memory full
1045 conditions then tinymail won't be able to
1046 connect so it'll return this error code */
1047 modest_platform_information_banner (parent_window,
1048 NULL, _("emev_ui_imap_inbox_select_error"));
1056 modest_ui_actions_disk_operations_error_handler (ModestMailOperation *mail_op,
1059 const GError *error;
1060 GObject *win = NULL;
1061 ModestMailOperationStatus status;
1063 win = modest_mail_operation_get_source (mail_op);
1064 error = modest_mail_operation_get_error (mail_op);
1065 status = modest_mail_operation_get_status (mail_op);
1067 /* If the mail op has been cancelled then it's not an error:
1068 don't show any message */
1069 if (status != MODEST_MAIL_OPERATION_STATUS_CANCELED) {
1070 if (is_memory_full_error ((GError *) error)) {
1071 modest_platform_information_banner ((GtkWidget *) win,
1072 NULL, dgettext("ke-recv",
1073 "cerm_device_memory_full"));
1074 } else if (error->code == TNY_SYSTEM_ERROR_MEMORY) {
1075 modest_platform_information_banner ((GtkWidget *) win,
1076 NULL, _("emev_ui_imap_inbox_select_error"));
1077 } else if (error->domain == MODEST_MAIL_OPERATION_ERROR &&
1078 error->code == MODEST_MAIL_OPERATION_ERROR_FILE_IO) {
1079 modest_platform_information_banner ((GtkWidget *) win,
1080 NULL, dgettext ("hildon-common-strings", "sfil_ni_unable_to_open_file_not_found"));
1081 } else if (user_data) {
1082 modest_platform_information_banner ((GtkWidget *) win,
1088 g_object_unref (win);
1092 * Returns the account a list of headers belongs to. It returns a
1093 * *new* reference so don't forget to unref it
1096 get_account_from_header_list (TnyList *headers)
1098 TnyAccount *account = NULL;
1100 if (tny_list_get_length (headers) > 0) {
1101 TnyIterator *iter = tny_list_create_iterator (headers);
1102 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter));
1103 TnyFolder *folder = tny_header_get_folder (header);
1106 g_object_unref (header);
1108 while (!tny_iterator_is_done (iter)) {
1109 header = TNY_HEADER (tny_iterator_get_current (iter));
1110 folder = tny_header_get_folder (header);
1113 g_object_unref (header);
1115 tny_iterator_next (iter);
1120 account = tny_folder_get_account (folder);
1121 g_object_unref (folder);
1125 g_object_unref (header);
1127 g_object_unref (iter);
1133 foreach_unregister_headers (gpointer data,
1136 ModestWindowMgr *mgr = (ModestWindowMgr *) user_data;
1137 TnyHeader *header = TNY_HEADER (data);
1139 modest_window_mgr_unregister_header (mgr, header);
1143 open_msgs_helper_destroyer (gpointer user_data)
1145 OpenMsgHelper *helper = (OpenMsgHelper *) user_data;
1147 if (helper->banner_info) {
1148 g_free (helper->banner_info->message);
1149 if (helper->banner_info->idle_handler > 0) {
1150 g_source_remove (helper->banner_info->idle_handler);
1151 helper->banner_info->idle_handler = 0;
1153 if (helper->banner_info->banner != NULL) {
1154 gtk_widget_destroy (helper->banner_info->banner);
1155 g_object_unref (helper->banner_info->banner);
1156 helper->banner_info->banner = NULL;
1158 g_slice_free (OpenMsgBannerInfo, helper->banner_info);
1159 helper->banner_info = NULL;
1161 g_object_unref (helper->model);
1162 g_object_unref (helper->headers);
1163 g_hash_table_destroy (helper->row_refs_per_header);
1164 g_slice_free (OpenMsgHelper, helper);
1168 open_msgs_performer(gboolean canceled,
1170 GtkWindow *parent_window,
1171 TnyAccount *account,
1174 ModestMailOperation *mail_op = NULL;
1175 const gchar *proto_name;
1177 ModestTransportStoreProtocol proto;
1178 TnyList *not_opened_headers;
1179 TnyConnectionStatus status;
1180 gboolean show_open_draft = FALSE;
1181 OpenMsgHelper *helper = NULL;
1183 helper = (OpenMsgHelper *) user_data;
1184 not_opened_headers = helper->headers;
1186 status = tny_account_get_connection_status (account);
1187 if (err || canceled) {
1188 /* Unregister the already registered headers */
1189 tny_list_foreach (not_opened_headers, foreach_unregister_headers,
1190 modest_runtime_get_window_mgr ());
1191 /* Free the helper */
1192 open_msgs_helper_destroyer (helper);
1194 /* In memory full conditions we could get this error here */
1195 check_memory_full_error ((GtkWidget *) parent_window, err);
1200 /* Get the error message depending on the protocol */
1201 proto_name = tny_account_get_proto (account);
1202 if (proto_name != NULL) {
1203 proto = modest_protocol_info_get_transport_store_protocol (proto_name);
1205 proto = MODEST_PROTOCOL_STORE_MAILDIR;
1208 /* Create the error messages */
1209 if (tny_list_get_length (not_opened_headers) == 1) {
1210 if (proto == MODEST_PROTOCOL_STORE_POP) {
1211 error_msg = g_strdup (_("emev_ni_ui_pop3_msg_recv_error"));
1212 } else if (proto == MODEST_PROTOCOL_STORE_IMAP) {
1213 TnyIterator *iter = tny_list_create_iterator (not_opened_headers);
1214 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter));
1215 gchar *subject = tny_header_dup_subject (header);
1216 error_msg = g_strdup_printf (_("emev_ni_ui_imap_message_not_available_in_server"),
1219 g_object_unref (header);
1220 g_object_unref (iter);
1225 TnyFolderType folder_type;
1227 iter = tny_list_create_iterator (not_opened_headers);
1228 header = TNY_HEADER (tny_iterator_get_current (iter));
1229 folder = tny_header_get_folder (header);
1230 folder_type = modest_tny_folder_get_local_or_mmc_folder_type (folder);
1231 show_open_draft = (folder_type == TNY_FOLDER_TYPE_DRAFTS);
1232 g_object_unref (folder);
1233 g_object_unref (header);
1234 g_object_unref (iter);
1235 error_msg = g_strdup (_("mail_ni_ui_folder_get_msg_folder_error"));
1238 error_msg = g_strdup (_("mail_ni_ui_folder_get_msg_folder_error"));
1241 /* Create the mail operation */
1243 modest_mail_operation_new_with_error_handling ((GObject *) parent_window,
1244 modest_ui_actions_disk_operations_error_handler,
1246 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
1249 if (show_open_draft) {
1250 helper->banner_info = g_slice_new (OpenMsgBannerInfo);
1251 helper->banner_info->message = g_strdup (_("mail_ib_opening_draft_message"));
1252 helper->banner_info->banner = NULL;
1253 helper->banner_info->idle_handler = g_timeout_add (500, open_msg_banner_idle,
1254 helper->banner_info);
1257 modest_mail_operation_get_msgs_full (mail_op,
1261 open_msgs_helper_destroyer);
1266 g_object_unref (mail_op);
1267 g_object_unref (account);
1271 * This function is used by both modest_ui_actions_on_open and
1272 * modest_ui_actions_on_header_activated. This way we always do the
1273 * same when trying to open messages.
1276 open_msgs_from_headers (TnyList *headers, ModestWindow *win)
1278 ModestWindowMgr *mgr = NULL;
1279 TnyIterator *iter = NULL, *iter_not_opened = NULL;
1280 TnyList *not_opened_headers = NULL;
1281 TnyHeaderFlags flags = 0;
1282 TnyAccount *account;
1283 gint uncached_msgs = 0;
1284 GtkWidget *header_view;
1285 GtkTreeModel *model;
1286 GHashTable *refs_for_headers;
1287 OpenMsgHelper *helper;
1288 GtkTreeSelection *sel;
1289 GList *sel_list = NULL, *sel_list_iter = NULL;
1291 g_return_if_fail (headers != NULL);
1293 /* Check that only one message is selected for opening */
1294 if (tny_list_get_length (headers) != 1) {
1295 modest_platform_information_banner ((win) ? GTK_WIDGET (win) : NULL,
1296 NULL, _("mcen_ib_select_one_message"));
1300 mgr = modest_runtime_get_window_mgr ();
1301 iter = tny_list_create_iterator (headers);
1303 /* Get the account */
1304 account = get_account_from_header_list (headers);
1309 /* Get the selections, we need to get the references to the
1310 rows here because the treeview/model could dissapear (the
1311 user might want to select another folder)*/
1312 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
1313 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1314 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
1315 model = gtk_tree_view_get_model (GTK_TREE_VIEW (header_view));
1316 sel_list = gtk_tree_selection_get_selected_rows (sel, &model);
1317 refs_for_headers = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL,
1318 (GDestroyNotify) gtk_tree_row_reference_free);
1320 /* Look if we already have a message view for each header. If
1321 true, then remove the header from the list of headers to
1323 sel_list_iter = sel_list;
1324 not_opened_headers = tny_simple_list_new ();
1325 while (!tny_iterator_is_done (iter) && sel_list_iter) {
1327 ModestWindow *window = NULL;
1328 TnyHeader *header = NULL;
1329 gboolean found = FALSE;
1331 header = TNY_HEADER (tny_iterator_get_current (iter));
1333 flags = tny_header_get_flags (header);
1336 found = modest_window_mgr_find_registered_header (mgr, header, &window);
1338 /* Do not open again the message and present the
1339 window to the user */
1342 gtk_window_present (GTK_WINDOW (window));
1344 /* the header has been registered already, we don't do
1345 * anything but wait for the window to come up*/
1346 g_debug ("header %p already registered, waiting for window", header);
1349 GtkTreeRowReference *row_reference;
1351 tny_list_append (not_opened_headers, G_OBJECT (header));
1352 /* Create a new row reference and add it to the hash table */
1353 row_reference = gtk_tree_row_reference_new (model, (GtkTreePath *) sel_list_iter->data);
1354 g_hash_table_insert (refs_for_headers, header, row_reference);
1358 g_object_unref (header);
1361 tny_iterator_next (iter);
1362 sel_list_iter = g_list_next (sel_list_iter);
1364 g_object_unref (iter);
1366 g_list_foreach (sel_list, (GFunc) gtk_tree_path_free, NULL);
1367 g_list_free (sel_list);
1369 /* Open each message */
1370 if (tny_list_get_length (not_opened_headers) == 0) {
1371 g_hash_table_destroy (refs_for_headers);
1375 /* If some messages would have to be downloaded, ask the user to
1376 * make a connection. It's generally easier to do this here (in the mainloop)
1377 * than later in a thread:
1379 if (tny_list_get_length (not_opened_headers) > 0) {
1380 uncached_msgs = header_list_count_uncached_msgs (not_opened_headers);
1382 if (uncached_msgs > 0) {
1383 /* Allways download if we are online. */
1384 if (!tny_device_is_online (modest_runtime_get_device ())) {
1387 /* If ask for user permission to download the messages */
1388 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
1389 ngettext("mcen_nc_get_msg",
1393 /* End if the user does not want to continue */
1394 if (response == GTK_RESPONSE_CANCEL) {
1395 g_hash_table_destroy (refs_for_headers);
1402 /* Register the headers before actually creating the windows: */
1403 iter_not_opened = tny_list_create_iterator (not_opened_headers);
1404 while (!tny_iterator_is_done (iter_not_opened)) {
1405 TnyHeader *header = TNY_HEADER (tny_iterator_get_current (iter_not_opened));
1407 modest_window_mgr_register_header (mgr, header, NULL);
1408 g_object_unref (header);
1410 tny_iterator_next (iter_not_opened);
1412 g_object_unref (iter_not_opened);
1413 iter_not_opened = NULL;
1415 /* Create the helper. We need to get a reference to the model
1416 here because it could change while the message is readed
1417 (the user could switch between folders) */
1418 helper = g_slice_new (OpenMsgHelper);
1419 helper->model = g_object_ref (model);
1420 helper->headers = g_object_ref (not_opened_headers);
1421 helper->row_refs_per_header = refs_for_headers;
1422 helper->banner_info = NULL;
1424 /* Connect to the account and perform */
1425 if (uncached_msgs > 0) {
1426 modest_platform_connect_and_perform ((GtkWindow *) win, TRUE, g_object_ref (account),
1427 open_msgs_performer, helper);
1429 /* Call directly the performer, do not need to connect */
1430 open_msgs_performer (FALSE, NULL, (GtkWindow *) win,
1431 g_object_ref (account), helper);
1436 g_object_unref (account);
1437 if (not_opened_headers)
1438 g_object_unref (not_opened_headers);
1442 modest_ui_actions_on_open (GtkAction *action, ModestWindow *win)
1446 /* we check for low-mem; in that case, show a warning, and don't allow
1449 if (modest_platform_check_memory_low (MODEST_WINDOW(win), TRUE))
1453 headers = get_selected_headers (win);
1458 open_msgs_from_headers (headers, win);
1460 g_object_unref(headers);
1463 static ReplyForwardHelper*
1464 create_reply_forward_helper (ReplyForwardAction action,
1466 guint reply_forward_type,
1469 ReplyForwardHelper *rf_helper = NULL;
1470 const gchar *active_acc = modest_window_get_active_account (win);
1472 rf_helper = g_slice_new0 (ReplyForwardHelper);
1473 rf_helper->reply_forward_type = reply_forward_type;
1474 rf_helper->action = action;
1475 rf_helper->parent_window = (MODEST_IS_WINDOW (win)) ? GTK_WIDGET (win) : NULL;
1476 rf_helper->header = (header) ? g_object_ref (header) : NULL;
1477 rf_helper->account_name = (active_acc) ?
1478 g_strdup (active_acc) :
1479 modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
1485 free_reply_forward_helper (gpointer data)
1487 ReplyForwardHelper *helper;
1489 helper = (ReplyForwardHelper *) data;
1490 g_free (helper->account_name);
1492 g_object_unref (helper->header);
1493 g_slice_free (ReplyForwardHelper, helper);
1497 reply_forward_cb (ModestMailOperation *mail_op,
1504 TnyMsg *new_msg = NULL;
1505 ReplyForwardHelper *rf_helper;
1506 ModestWindow *msg_win = NULL;
1507 ModestEditType edit_type;
1509 TnyAccount *account = NULL;
1510 ModestWindowMgr *mgr = NULL;
1511 gchar *signature = NULL;
1512 gboolean use_signature;
1514 /* If there was any error. The mail operation could be NULL,
1515 this means that we already have the message downloaded and
1516 that we didn't do a mail operation to retrieve it */
1517 rf_helper = (ReplyForwardHelper *) user_data;
1518 if (mail_op && !modest_ui_actions_msg_retrieval_check (mail_op, header, msg))
1521 from = modest_account_mgr_get_from_string (modest_runtime_get_account_mgr(),
1522 rf_helper->account_name);
1523 signature = modest_account_mgr_get_signature (modest_runtime_get_account_mgr(),
1524 rf_helper->account_name,
1527 /* Create reply mail */
1528 switch (rf_helper->action) {
1531 modest_tny_msg_create_reply_msg (msg, header, from,
1532 (use_signature) ? signature : NULL,
1533 rf_helper->reply_forward_type,
1534 MODEST_TNY_MSG_REPLY_MODE_SENDER);
1536 case ACTION_REPLY_TO_ALL:
1538 modest_tny_msg_create_reply_msg (msg, header, from,
1539 (use_signature) ? signature : NULL,
1540 rf_helper->reply_forward_type,
1541 MODEST_TNY_MSG_REPLY_MODE_ALL);
1542 edit_type = MODEST_EDIT_TYPE_REPLY;
1544 case ACTION_FORWARD:
1546 modest_tny_msg_create_forward_msg (msg, from, (use_signature) ? signature : NULL,
1547 rf_helper->reply_forward_type);
1548 edit_type = MODEST_EDIT_TYPE_FORWARD;
1551 g_return_if_reached ();
1559 g_warning ("%s: failed to create message\n", __FUNCTION__);
1563 account = modest_tny_account_store_get_server_account (modest_runtime_get_account_store(),
1564 rf_helper->account_name,
1565 TNY_ACCOUNT_TYPE_STORE);
1567 g_warning ("%s: failed to get tnyaccount for '%s'\n", __FUNCTION__, rf_helper->account_name);
1571 /* Create and register the windows */
1572 msg_win = modest_msg_edit_window_new (new_msg, rf_helper->account_name, FALSE);
1573 mgr = modest_runtime_get_window_mgr ();
1574 modest_window_mgr_register_window (mgr, msg_win);
1576 if (rf_helper->parent_window != NULL) {
1577 gdouble parent_zoom;
1579 parent_zoom = modest_window_get_zoom (MODEST_WINDOW (rf_helper->parent_window));
1580 modest_window_set_zoom (msg_win, parent_zoom);
1583 /* Show edit window */
1584 gtk_widget_show_all (GTK_WIDGET (msg_win));
1588 g_object_unref (msg_win);
1590 g_object_unref (G_OBJECT (new_msg));
1592 g_object_unref (G_OBJECT (account));
1593 free_reply_forward_helper (rf_helper);
1596 /* Checks a list of headers. If any of them are not currently
1597 * downloaded (CACHED) then returns TRUE else returns FALSE.
1600 header_list_count_uncached_msgs (TnyList *header_list)
1603 gint uncached_messages = 0;
1605 iter = tny_list_create_iterator (header_list);
1606 while (!tny_iterator_is_done (iter)) {
1609 header = TNY_HEADER (tny_iterator_get_current (iter));
1611 if (!(tny_header_get_flags (header) & TNY_HEADER_FLAG_CACHED))
1612 uncached_messages ++;
1613 g_object_unref (header);
1616 tny_iterator_next (iter);
1618 g_object_unref (iter);
1620 return uncached_messages;
1623 /* Returns FALSE if the user does not want to download the
1624 * messages. Returns TRUE if the user allowed the download.
1627 connect_to_get_msg (ModestWindow *win,
1628 gint num_of_uncached_msgs,
1629 TnyAccount *account)
1631 GtkResponseType response;
1633 /* Allways download if we are online. */
1634 if (tny_device_is_online (modest_runtime_get_device ()))
1637 /* If offline, then ask for user permission to download the messages */
1638 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
1639 ngettext("mcen_nc_get_msg",
1641 num_of_uncached_msgs));
1643 if (response == GTK_RESPONSE_CANCEL)
1646 return modest_platform_connect_and_wait((GtkWindow *) win, account);
1650 reply_forward_performer (gboolean canceled,
1652 GtkWindow *parent_window,
1653 TnyAccount *account,
1656 ReplyForwardHelper *rf_helper = NULL;
1657 ModestMailOperation *mail_op;
1659 rf_helper = (ReplyForwardHelper *) user_data;
1661 if (canceled || err) {
1662 free_reply_forward_helper (rf_helper);
1666 /* Retrieve the message */
1667 mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT (parent_window),
1668 modest_ui_actions_disk_operations_error_handler,
1670 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
1671 modest_mail_operation_get_msg (mail_op, rf_helper->header, TRUE, reply_forward_cb, rf_helper);
1674 g_object_unref(mail_op);
1678 * Common code for the reply and forward actions
1681 reply_forward (ReplyForwardAction action, ModestWindow *win)
1683 ReplyForwardHelper *rf_helper = NULL;
1684 guint reply_forward_type;
1686 g_return_if_fail (MODEST_IS_WINDOW(win));
1688 /* we check for low-mem; in that case, show a warning, and don't allow
1689 * reply/forward (because it could potentially require a lot of memory */
1690 if (modest_platform_check_memory_low (MODEST_WINDOW(win), TRUE))
1694 /* we need an account when editing */
1695 if (!modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE)) {
1696 if (!modest_ui_actions_run_account_setup_wizard (win))
1700 reply_forward_type =
1701 modest_conf_get_int (modest_runtime_get_conf (),
1702 (action == ACTION_FORWARD) ?
1703 MODEST_CONF_FORWARD_TYPE :
1704 MODEST_CONF_REPLY_TYPE,
1707 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
1709 TnyHeader *header = NULL;
1710 /* Get header and message. Do not free them here, the
1711 reply_forward_cb must do it */
1712 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW(win));
1713 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
1715 if (msg && header) {
1717 rf_helper = create_reply_forward_helper (action, win,
1718 reply_forward_type, header);
1719 reply_forward_cb (NULL, header, FALSE, msg, NULL, rf_helper);
1721 g_warning("%s: no message or header found in viewer\n", __FUNCTION__);
1725 g_object_unref (msg);
1727 g_object_unref (header);
1729 TnyHeader *header = NULL;
1731 gboolean do_retrieve = TRUE;
1732 TnyList *header_list = NULL;
1734 header_list = get_selected_headers (win);
1737 if (tny_list_get_length (header_list) == 0) {
1738 g_object_unref (header_list);
1742 /* Only reply/forward to one message */
1743 iter = tny_list_create_iterator (header_list);
1744 header = TNY_HEADER (tny_iterator_get_current (iter));
1745 g_object_unref (iter);
1747 /* Retrieve messages */
1748 do_retrieve = (action == ACTION_FORWARD) ||
1749 (reply_forward_type != MODEST_TNY_MSG_REPLY_TYPE_CITE);
1752 TnyAccount *account = NULL;
1753 TnyFolder *folder = NULL;
1754 gdouble download = TRUE;
1755 guint uncached_msgs = 0;
1757 folder = tny_header_get_folder (header);
1759 goto do_retrieve_frees;
1760 account = tny_folder_get_account (folder);
1762 goto do_retrieve_frees;
1764 uncached_msgs = header_list_count_uncached_msgs (header_list);
1766 if (uncached_msgs > 0) {
1767 /* Allways download if we are online. */
1768 if (!tny_device_is_online (modest_runtime_get_device ())) {
1771 /* If ask for user permission to download the messages */
1772 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
1773 ngettext("mcen_nc_get_msg",
1777 /* End if the user does not want to continue */
1778 if (response == GTK_RESPONSE_CANCEL)
1785 rf_helper = create_reply_forward_helper (action, win,
1786 reply_forward_type, header);
1787 if (uncached_msgs > 0) {
1788 modest_platform_connect_and_perform (GTK_WINDOW (win),
1790 reply_forward_performer,
1793 reply_forward_performer (FALSE, NULL, GTK_WINDOW (win),
1794 account, rf_helper);
1799 g_object_unref (account);
1801 g_object_unref (folder);
1803 reply_forward_cb (NULL, header, FALSE, NULL, NULL, rf_helper);
1806 g_object_unref (header_list);
1807 g_object_unref (header);
1812 modest_ui_actions_on_reply (GtkAction *action, ModestWindow *win)
1814 g_return_if_fail (MODEST_IS_WINDOW(win));
1816 reply_forward (ACTION_REPLY, win);
1820 modest_ui_actions_on_forward (GtkAction *action, ModestWindow *win)
1822 g_return_if_fail (MODEST_IS_WINDOW(win));
1824 reply_forward (ACTION_FORWARD, win);
1828 modest_ui_actions_on_reply_all (GtkAction *action, ModestWindow *win)
1830 g_return_if_fail (MODEST_IS_WINDOW(win));
1832 reply_forward (ACTION_REPLY_TO_ALL, win);
1836 modest_ui_actions_on_next (GtkAction *action,
1837 ModestWindow *window)
1839 if (MODEST_IS_MAIN_WINDOW (window)) {
1840 GtkWidget *header_view;
1842 header_view = modest_main_window_get_child_widget (
1843 MODEST_MAIN_WINDOW(window),
1844 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1848 modest_header_view_select_next (
1849 MODEST_HEADER_VIEW(header_view));
1850 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
1851 modest_msg_view_window_select_next_message (
1852 MODEST_MSG_VIEW_WINDOW (window));
1854 g_return_if_reached ();
1859 modest_ui_actions_on_prev (GtkAction *action,
1860 ModestWindow *window)
1862 g_return_if_fail (MODEST_IS_WINDOW(window));
1864 if (MODEST_IS_MAIN_WINDOW (window)) {
1865 GtkWidget *header_view;
1866 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
1867 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1871 modest_header_view_select_prev (MODEST_HEADER_VIEW(header_view));
1872 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
1873 modest_msg_view_window_select_previous_message (MODEST_MSG_VIEW_WINDOW (window));
1875 g_return_if_reached ();
1880 modest_ui_actions_on_sort (GtkAction *action,
1881 ModestWindow *window)
1883 g_return_if_fail (MODEST_IS_WINDOW(window));
1885 if (MODEST_IS_MAIN_WINDOW (window)) {
1886 GtkWidget *header_view;
1887 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(window),
1888 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
1890 modest_platform_information_banner (NULL, NULL, _CS("ckdg_ib_nothing_to_sort"));
1895 /* Show sorting dialog */
1896 modest_utils_run_sort_dialog (GTK_WINDOW (window), MODEST_SORT_HEADERS);
1901 new_messages_arrived (ModestMailOperation *self,
1902 TnyList *new_headers,
1906 gboolean show_visual_notifications;
1908 source = modest_mail_operation_get_source (self);
1909 show_visual_notifications = (source) ? FALSE : TRUE;
1911 g_object_unref (source);
1913 /* Notify new messages have been downloaded. If the
1914 send&receive was invoked by the user then do not show any
1915 visual notification, only play a sound and activate the LED
1916 (for the Maemo version) */
1917 if (TNY_IS_LIST(new_headers) && (tny_list_get_length (new_headers)) > 0)
1918 modest_platform_on_new_headers_received (new_headers,
1919 show_visual_notifications);
1924 retrieve_all_messages_cb (GObject *source,
1926 guint retrieve_limit)
1932 window = GTK_WINDOW (source);
1933 msg = g_strdup_printf (_("mail_nc_msg_count_limit_exceeded"),
1934 num_msgs, retrieve_limit);
1936 /* Ask the user if they want to retrieve all the messages */
1938 modest_platform_run_confirmation_dialog_with_buttons (window, msg,
1939 _("mcen_bd_get_all"),
1940 _("mcen_bd_newest_only"));
1941 /* Free and return */
1943 return (response == GTK_RESPONSE_ACCEPT) ? TRUE : FALSE;
1947 TnyAccount *account;
1949 gchar *account_name;
1950 gboolean poke_status;
1951 gboolean interactive;
1952 ModestMailOperation *mail_op;
1956 do_send_receive_performer (gboolean canceled,
1958 GtkWindow *parent_window,
1959 TnyAccount *account,
1962 SendReceiveInfo *info;
1964 info = (SendReceiveInfo *) user_data;
1966 if (err || canceled) {
1967 /* In memory full conditions we could get this error here */
1968 check_memory_full_error ((GtkWidget *) parent_window, err);
1970 if (info->mail_op) {
1971 modest_mail_operation_queue_remove (modest_runtime_get_mail_operation_queue (),
1977 /* Set send/receive operation in progress */
1978 if (info->win && MODEST_IS_MAIN_WINDOW (info->win)) {
1979 modest_main_window_notify_send_receive_initied (MODEST_MAIN_WINDOW (info->win));
1982 if (info->win && MODEST_IS_MAIN_WINDOW (info->win))
1983 g_signal_connect (G_OBJECT (info->mail_op), "operation-finished",
1984 G_CALLBACK (on_send_receive_finished),
1987 /* Send & receive. */
1988 modest_mail_operation_update_account (info->mail_op, info->account_name, info->poke_status, info->interactive,
1989 (info->win) ? retrieve_all_messages_cb : NULL,
1990 new_messages_arrived, info->win);
1995 g_object_unref (G_OBJECT (info->mail_op));
1996 if (info->account_name)
1997 g_free (info->account_name);
1999 g_object_unref (info->win);
2001 g_object_unref (info->account);
2002 g_slice_free (SendReceiveInfo, info);
2006 * This function performs the send & receive required actions. The
2007 * window is used to create the mail operation. Typically it should
2008 * always be the main window, but we pass it as argument in order to
2012 modest_ui_actions_do_send_receive (const gchar *account_name,
2013 gboolean force_connection,
2014 gboolean poke_status,
2015 gboolean interactive,
2018 gchar *acc_name = NULL;
2019 SendReceiveInfo *info;
2020 ModestTnyAccountStore *acc_store;
2022 /* If no account name was provided then get the current account, and if
2023 there is no current account then pick the default one: */
2024 if (!account_name) {
2026 acc_name = g_strdup (modest_window_get_active_account (win));
2028 acc_name = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr());
2030 g_printerr ("modest: cannot get default account\n");
2034 acc_name = g_strdup (account_name);
2037 acc_store = modest_runtime_get_account_store ();
2039 /* Create the info for the connect and perform */
2040 info = g_slice_new (SendReceiveInfo);
2041 info->account_name = acc_name;
2042 info->win = (win) ? g_object_ref (win) : NULL;
2043 info->poke_status = poke_status;
2044 info->interactive = interactive;
2045 info->account = modest_tny_account_store_get_server_account (acc_store, acc_name,
2046 TNY_ACCOUNT_TYPE_STORE);
2047 /* We need to create the operation here, because otherwise it
2048 could happen that the queue emits the queue-empty signal
2049 while we're trying to connect the account */
2050 info->mail_op = modest_mail_operation_new_with_error_handling ((info->win) ? G_OBJECT (info->win) : NULL,
2051 modest_ui_actions_disk_operations_error_handler,
2053 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), info->mail_op);
2055 /* Invoke the connect and perform */
2056 modest_platform_connect_and_perform ((win) ? GTK_WINDOW (win) : NULL,
2057 force_connection, info->account,
2058 do_send_receive_performer, info);
2063 modest_ui_actions_do_cancel_send (const gchar *account_name,
2066 TnyTransportAccount *transport_account;
2067 TnySendQueue *send_queue = NULL;
2068 GError *error = NULL;
2070 /* Get transport account */
2072 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
2073 (modest_runtime_get_account_store(),
2075 TNY_ACCOUNT_TYPE_TRANSPORT));
2076 if (!transport_account) {
2077 g_printerr ("modest: no transport account found for '%s'\n", account_name);
2082 send_queue = TNY_SEND_QUEUE (modest_runtime_get_send_queue (transport_account, TRUE));
2083 if (!TNY_IS_SEND_QUEUE(send_queue)) {
2084 g_set_error (&error, MODEST_MAIL_OPERATION_ERROR,
2085 MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND,
2086 "modest: could not find send queue for account\n");
2088 /* Cancel the current send */
2089 tny_account_cancel (TNY_ACCOUNT (transport_account));
2091 /* Suspend all pending messages */
2092 tny_send_queue_cancel (send_queue, TNY_SEND_QUEUE_CANCEL_ACTION_SUSPEND, &error);
2096 if (transport_account != NULL)
2097 g_object_unref (G_OBJECT (transport_account));
2101 modest_ui_actions_cancel_send_all (ModestWindow *win)
2103 GSList *account_names, *iter;
2105 account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
2108 iter = account_names;
2110 modest_ui_actions_do_cancel_send ((const char*) iter->data, win);
2111 iter = g_slist_next (iter);
2114 modest_account_mgr_free_account_names (account_names);
2115 account_names = NULL;
2119 modest_ui_actions_cancel_send (GtkAction *action, ModestWindow *win)
2122 /* Check if accounts exist */
2123 gboolean accounts_exist =
2124 modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
2126 /* If not, allow the user to create an account before trying to send/receive. */
2127 if (!accounts_exist)
2128 modest_ui_actions_on_accounts (NULL, win);
2130 /* Cancel all sending operaitons */
2131 modest_ui_actions_cancel_send_all (win);
2135 * Refreshes all accounts. This function will be used by automatic
2139 modest_ui_actions_do_send_receive_all (ModestWindow *win,
2140 gboolean force_connection,
2141 gboolean poke_status,
2142 gboolean interactive)
2144 GSList *account_names, *iter;
2146 account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr(),
2149 iter = account_names;
2151 modest_ui_actions_do_send_receive ((const char*) iter->data,
2153 poke_status, interactive, win);
2154 iter = g_slist_next (iter);
2157 modest_account_mgr_free_account_names (account_names);
2158 account_names = NULL;
2162 * Handler of the click on Send&Receive button in the main toolbar
2165 modest_ui_actions_on_send_receive (GtkAction *action, ModestWindow *win)
2167 /* Check if accounts exist */
2168 gboolean accounts_exist;
2171 modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), TRUE);
2173 /* If not, allow the user to create an account before trying to send/receive. */
2174 if (!accounts_exist)
2175 modest_ui_actions_on_accounts (NULL, win);
2177 /* Refresh the current folder. The if is always TRUE it's just an extra check */
2178 if (MODEST_IS_MAIN_WINDOW (win)) {
2179 GtkWidget *folder_view;
2180 TnyFolderStore *folder_store;
2183 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
2184 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2188 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
2191 g_object_unref (folder_store);
2194 /* Refresh the active account. Force the connection if needed
2195 and poke the status of all folders */
2196 modest_ui_actions_do_send_receive (NULL, TRUE, TRUE, TRUE, win);
2201 modest_ui_actions_toggle_header_list_view (GtkAction *action, ModestMainWindow *main_window)
2204 GtkWidget *header_view;
2206 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2208 header_view = modest_main_window_get_child_widget (main_window,
2209 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2213 conf = modest_runtime_get_conf ();
2215 /* what is saved/restored is depending on the style; thus; we save with
2216 * old style, then update the style, and restore for this new style
2218 modest_widget_memory_save (conf, G_OBJECT(header_view), MODEST_CONF_HEADER_VIEW_KEY);
2220 if (modest_header_view_get_style
2221 (MODEST_HEADER_VIEW(header_view)) == MODEST_HEADER_VIEW_STYLE_DETAILS)
2222 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
2223 MODEST_HEADER_VIEW_STYLE_TWOLINES);
2225 modest_header_view_set_style (MODEST_HEADER_VIEW(header_view),
2226 MODEST_HEADER_VIEW_STYLE_DETAILS);
2228 modest_widget_memory_restore (conf, G_OBJECT(header_view),
2229 MODEST_CONF_HEADER_VIEW_KEY);
2234 modest_ui_actions_on_header_selected (ModestHeaderView *header_view,
2236 ModestMainWindow *main_window)
2238 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2239 g_return_if_fail (MODEST_IS_HEADER_VIEW (header_view));
2241 /* in the case the folder is empty, show the empty folder message and focus
2243 if (!header && gtk_widget_is_focus (GTK_WIDGET (header_view))) {
2244 if (modest_header_view_is_empty (header_view)) {
2245 TnyFolder *folder = modest_header_view_get_folder (header_view);
2246 GtkWidget *folder_view =
2247 modest_main_window_get_child_widget (main_window,
2248 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
2249 if (folder != NULL) {
2250 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view), folder, FALSE);
2251 g_object_unref (folder);
2253 gtk_widget_grab_focus (GTK_WIDGET (folder_view));
2257 /* If no header has been selected then exit */
2262 if (!gtk_widget_is_focus (GTK_WIDGET(header_view)))
2263 gtk_widget_grab_focus (GTK_WIDGET(header_view));
2265 /* Update toolbar dimming state */
2266 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (main_window));
2267 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
2271 modest_ui_actions_on_header_activated (ModestHeaderView *header_view,
2273 ModestMainWindow *main_window)
2276 GtkWidget *open_widget;
2278 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2283 if (modest_header_view_count_selected_headers (header_view) > 1) {
2284 modest_platform_information_banner (NULL, NULL, _("mcen_ib_select_one_message"));
2288 /* we check for low-mem; in that case, show a warning, and don't allow
2289 * activating headers
2291 if (modest_platform_check_memory_low (MODEST_WINDOW(main_window), TRUE))
2294 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (main_window));
2295 open_widget = modest_window_get_action_widget (MODEST_WINDOW (main_window), "/MenuBar/EmailMenu/EmailOpenMenu");
2296 if (!GTK_WIDGET_IS_SENSITIVE (open_widget))
2299 headers = modest_header_view_get_selected_headers (header_view);
2301 open_msgs_from_headers (headers, MODEST_WINDOW (main_window));
2303 g_object_unref (headers);
2307 set_active_account_from_tny_account (TnyAccount *account,
2308 ModestWindow *window)
2310 const gchar *server_acc_name = tny_account_get_id (account);
2312 /* We need the TnyAccount provided by the
2313 account store because that is the one that
2314 knows the name of the Modest account */
2315 TnyAccount *modest_server_account = modest_server_account =
2316 modest_tny_account_store_get_tny_account_by (modest_runtime_get_account_store (),
2317 MODEST_TNY_ACCOUNT_STORE_QUERY_ID,
2319 if (!modest_server_account) {
2320 g_warning ("%s: could not get tny account\n", __FUNCTION__);
2324 /* Update active account, but only if it's not a pseudo-account */
2325 if ((!modest_tny_account_is_virtual_local_folders(modest_server_account)) &&
2326 (!modest_tny_account_is_memory_card_account(modest_server_account))) {
2327 const gchar *modest_acc_name =
2328 modest_tny_account_get_parent_modest_account_name_for_server_account (modest_server_account);
2329 if (modest_acc_name)
2330 modest_window_set_active_account (window, modest_acc_name);
2333 g_object_unref (modest_server_account);
2338 folder_refreshed_cb (ModestMailOperation *mail_op,
2342 ModestMainWindow *win = NULL;
2343 GtkWidget *header_view;
2344 const GError *error;
2346 g_return_if_fail (TNY_IS_FOLDER (folder));
2348 win = MODEST_MAIN_WINDOW (user_data);
2350 /* Check if the operation failed due to memory low conditions */
2351 error = modest_mail_operation_get_error (mail_op);
2352 if (error && error->domain == MODEST_MAIL_OPERATION_ERROR &&
2353 error->code == MODEST_MAIL_OPERATION_ERROR_LOW_MEMORY) {
2354 modest_platform_run_information_dialog (GTK_WINDOW (win),
2355 dgettext("ke-recv","memr_ib_operation_disabled"),
2361 modest_main_window_get_child_widget(win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2364 TnyFolder *current_folder;
2366 current_folder = modest_header_view_get_folder (MODEST_HEADER_VIEW (header_view));
2367 if (current_folder != NULL && folder != current_folder) {
2368 g_object_unref (current_folder);
2370 } else if (current_folder)
2371 g_object_unref (current_folder);
2374 /* Check if folder is empty and set headers view contents style */
2375 if (tny_folder_get_all_count (folder) == 0)
2376 modest_main_window_set_contents_style (win,
2377 MODEST_MAIN_WINDOW_CONTENTS_STYLE_EMPTY);
2382 modest_ui_actions_on_folder_selection_changed (ModestFolderView *folder_view,
2383 TnyFolderStore *folder_store,
2385 ModestMainWindow *main_window)
2388 GtkWidget *header_view;
2390 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
2392 header_view = modest_main_window_get_child_widget(main_window,
2393 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2397 conf = modest_runtime_get_conf ();
2399 if (TNY_IS_ACCOUNT (folder_store)) {
2401 set_active_account_from_tny_account (TNY_ACCOUNT (folder_store), MODEST_WINDOW (main_window));
2403 /* Show account details */
2404 modest_main_window_set_contents_style (main_window, MODEST_MAIN_WINDOW_CONTENTS_STYLE_DETAILS);
2407 if (TNY_IS_FOLDER (folder_store) && selected) {
2408 TnyAccount *account;
2409 const gchar *account_name = NULL;
2412 /* Update the active account */
2413 account = modest_tny_folder_get_account (TNY_FOLDER (folder_store));
2415 set_active_account_from_tny_account (account, MODEST_WINDOW (main_window));
2417 modest_tny_account_get_parent_modest_account_name_for_server_account (account);
2418 g_object_unref (account);
2422 /* Set the header style by default, it could
2423 be changed later by the refresh callback to
2425 modest_main_window_set_contents_style (main_window,
2426 MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS);
2428 refresh = !modest_account_mgr_account_is_busy (modest_runtime_get_account_mgr (), account_name);
2430 /* Set folder on header view. This function
2431 will call tny_folder_refresh_async so we
2432 pass a callback that will be called when
2433 finished. We use that callback to set the
2434 empty view if there are no messages */
2435 modest_header_view_set_folder (MODEST_HEADER_VIEW(header_view),
2436 TNY_FOLDER (folder_store),
2438 folder_refreshed_cb,
2441 /* Restore configuration. We need to do this
2442 *after* the set_folder because the widget
2443 memory asks the header view about its
2445 modest_widget_memory_restore (modest_runtime_get_conf (),
2446 G_OBJECT(header_view),
2447 MODEST_CONF_HEADER_VIEW_KEY);
2449 /* No need to save the header view
2450 configuration for Maemo because it only
2451 saves the sorting stuff and that it's
2452 already being done by the sort
2453 dialog. Remove it when the GNOME version
2454 has the same behaviour */
2455 #ifdef MODEST_PLATFORM_GNOME
2456 if (modest_main_window_get_contents_style (main_window) ==
2457 MODEST_MAIN_WINDOW_CONTENTS_STYLE_HEADERS)
2458 modest_widget_memory_save (conf, G_OBJECT (header_view),
2459 MODEST_CONF_HEADER_VIEW_KEY);
2461 modest_header_view_clear (MODEST_HEADER_VIEW(header_view));
2465 /* Update dimming state */
2466 modest_ui_actions_check_menu_dimming_rules (MODEST_WINDOW (main_window));
2467 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
2471 modest_ui_actions_on_item_not_found (ModestHeaderView *header_view,ModestItemType type,
2478 item = (type == MODEST_ITEM_TYPE_FOLDER) ? "folder" : "message";
2480 online = tny_device_is_online (modest_runtime_get_device());
2483 /* already online -- the item is simply not there... */
2484 dialog = gtk_message_dialog_new (GTK_WINDOW (win),
2486 GTK_MESSAGE_WARNING,
2488 _("The %s you selected cannot be found"),
2490 gtk_dialog_add_button (GTK_DIALOG (dialog),_("mcen_bd_dialog_ok"), GTK_RESPONSE_ACCEPT);
2491 gtk_dialog_run (GTK_DIALOG(dialog));
2493 dialog = gtk_dialog_new_with_buttons (_("Connection requested"),
2496 _("mcen_bd_dialog_cancel"),
2497 GTK_RESPONSE_REJECT,
2498 _("mcen_bd_dialog_ok"),
2499 GTK_RESPONSE_ACCEPT,
2501 txt = g_strdup_printf (_("This %s is not available in offline mode.\n"
2502 "Do you want to get online?"), item);
2503 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox),
2504 gtk_label_new (txt), FALSE, FALSE, 0);
2505 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
2508 gtk_window_set_default_size (GTK_WINDOW(dialog), 300, 300);
2509 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
2510 /* TODO: Comment about why is this commented out: */
2511 /* modest_platform_connect_and_wait (); */
2514 gtk_widget_destroy (dialog);
2518 modest_ui_actions_on_msg_link_hover (ModestMsgView *msgview, const gchar* link,
2521 /* g_message ("%s %s", __FUNCTION__, link); */
2526 modest_ui_actions_on_msg_link_clicked (ModestMsgView *msgview, const gchar* link,
2529 modest_platform_activate_uri (link);
2533 modest_ui_actions_on_msg_link_contextual (ModestMsgView *msgview, const gchar* link,
2536 modest_platform_show_uri_popup (link);
2540 modest_ui_actions_on_msg_attachment_clicked (ModestMsgView *msgview, TnyMimePart *mime_part,
2543 /* we check for low-mem; in that case, show a warning, and don't allow
2544 * viewing attachments
2546 if (modest_platform_check_memory_low (MODEST_WINDOW(win), TRUE))
2549 modest_msg_view_window_view_attachment (MODEST_MSG_VIEW_WINDOW (win), mime_part);
2553 modest_ui_actions_on_msg_recpt_activated (ModestMsgView *msgview,
2554 const gchar *address,
2557 /* g_message ("%s %s", __FUNCTION__, address); */
2561 on_save_to_drafts_cb (ModestMailOperation *mail_op,
2562 TnyMsg *saved_draft,
2565 ModestMsgEditWindow *edit_window;
2566 ModestMainWindow *win;
2568 /* FIXME. Make the header view sensitive again. This is a
2569 * temporary hack. See modest_ui_actions_on_save_to_drafts()
2571 win = MODEST_MAIN_WINDOW(modest_window_mgr_get_main_window(
2572 modest_runtime_get_window_mgr(), FALSE));
2574 GtkWidget *hdrview = modest_main_window_get_child_widget(
2575 win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2576 if (hdrview) gtk_widget_set_sensitive(hdrview, TRUE);
2579 edit_window = MODEST_MSG_EDIT_WINDOW (user_data);
2581 /* Set draft is there was no error */
2582 if (!modest_mail_operation_get_error (mail_op))
2583 modest_msg_edit_window_set_draft (edit_window, saved_draft);
2585 g_object_unref(edit_window);
2589 modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edit_window)
2591 TnyTransportAccount *transport_account;
2592 ModestMailOperation *mail_operation;
2594 gchar *account_name, *from;
2595 ModestAccountMgr *account_mgr;
2596 /* char *info_text; */
2597 gboolean had_error = FALSE;
2598 guint64 available_disk, expected_size;
2601 ModestMainWindow *win;
2603 g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window), FALSE);
2605 data = modest_msg_edit_window_get_msg_data (edit_window);
2608 available_disk = modest_folder_available_space (NULL);
2609 modest_msg_edit_window_get_parts_size (edit_window, &parts_count, &parts_size);
2610 expected_size = modest_tny_msg_estimate_size (data->plain_body,
2615 if ((available_disk != -1) && expected_size > available_disk) {
2616 modest_msg_edit_window_free_msg_data (edit_window, data);
2618 modest_platform_information_banner (NULL, NULL, dgettext("ke-recv", "cerm_device_memory_full"));
2623 * djcb: if we're in low-memory state, we only allow for
2624 * saving messages smaller than
2625 * MODEST_MAX_LOW_MEMORY_MESSAGE_SIZE (see modest-defs.h) this
2626 * should still allow for sending anything critical...
2628 if (expected_size > MODEST_MAX_LOW_MEMORY_MESSAGE_SIZE) {
2630 if (modest_platform_check_memory_low (MODEST_WINDOW(edit_window), TRUE)) {
2631 modest_msg_edit_window_free_msg_data (edit_window, data);
2637 * djcb: we also make sure that the attachments are smaller than the max size
2638 * this is for the case where we'd try to forward a message with attachments
2639 * bigger than our max allowed size, or sending an message from drafts which
2640 * somehow got past our checks when attaching.
2642 if (expected_size > MODEST_MAX_ATTACHMENT_SIZE) {
2643 modest_platform_run_information_dialog (
2644 GTK_WINDOW(edit_window),
2645 dgettext("ke-recv","memr_ib_operation_disabled"),
2647 modest_msg_edit_window_free_msg_data (edit_window, data);
2651 account_name = g_strdup (data->account_name);
2652 account_mgr = modest_runtime_get_account_mgr();
2654 account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
2656 account_name = modest_account_mgr_get_default_account (account_mgr);
2657 if (!account_name) {
2658 g_printerr ("modest: no account found\n");
2659 modest_msg_edit_window_free_msg_data (edit_window, data);
2663 if (!strcmp (account_name, MODEST_LOCAL_FOLDERS_ACCOUNT_ID)) {
2664 account_name = g_strdup (data->account_name);
2668 TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
2669 (modest_runtime_get_account_store(),
2671 TNY_ACCOUNT_TYPE_TRANSPORT));
2672 if (!transport_account) {
2673 g_printerr ("modest: no transport account found for '%s'\n", account_name);
2674 g_free (account_name);
2675 modest_msg_edit_window_free_msg_data (edit_window, data);
2678 from = modest_account_mgr_get_from_string (account_mgr, account_name);
2680 /* Create the mail operation */
2681 mail_operation = modest_mail_operation_new_with_error_handling (NULL, modest_ui_actions_disk_operations_error_handler,
2683 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
2685 modest_mail_operation_save_to_drafts (mail_operation,
2697 data->priority_flags,
2698 on_save_to_drafts_cb,
2699 g_object_ref(edit_window));
2701 /* Use the main window as the parent of the banner, if the
2702 main window does not exist it won't be shown, if the parent
2703 window exists then it's properly shown. We don't use the
2704 editor window because it could be closed (save to drafts
2705 could happen after closing the window */
2706 win = (ModestMainWindow *)
2707 modest_window_mgr_get_main_window( modest_runtime_get_window_mgr(), FALSE);
2709 gchar *text = g_strdup_printf (_("mail_va_saved_to_drafts"), _("mcen_me_folder_drafts"));
2710 modest_platform_information_banner (GTK_WIDGET (win), NULL, text);
2713 modest_msg_edit_window_set_modified (edit_window, FALSE);
2717 g_free (account_name);
2718 g_object_unref (G_OBJECT (transport_account));
2719 g_object_unref (G_OBJECT (mail_operation));
2721 modest_msg_edit_window_free_msg_data (edit_window, data);
2724 * If the drafts folder is selected then make the header view
2725 * insensitive while the message is being saved to drafts
2726 * (it'll be sensitive again in on_save_to_drafts_cb()). This
2727 * is not very clean but it avoids letting the drafts folder
2728 * in an inconsistent state: the user could edit the message
2729 * being saved and undesirable things would happen.
2730 * In the average case the user won't notice anything at
2731 * all. In the worst case (the user is editing a really big
2732 * file from Drafts) the header view will be insensitive
2733 * during the saving process (10 or 20 seconds, depending on
2734 * the message). Anyway this is just a quick workaround: once
2735 * we find a better solution it should be removed
2736 * See NB#65125 (commend #18) for details.
2738 if (!had_error && win != NULL) {
2739 ModestFolderView *view = MODEST_FOLDER_VIEW(modest_main_window_get_child_widget(
2740 win, MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW));
2742 TnyFolder *folder = TNY_FOLDER(modest_folder_view_get_selected(view));
2744 if (modest_tny_folder_is_local_folder(folder)) {
2745 TnyFolderType folder_type;
2746 folder_type = modest_tny_folder_get_local_or_mmc_folder_type(folder);
2747 if (folder_type == TNY_FOLDER_TYPE_DRAFTS) {
2748 GtkWidget *hdrview = modest_main_window_get_child_widget(
2749 win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
2750 if (hdrview) gtk_widget_set_sensitive(hdrview, FALSE);
2754 if (folder != NULL) g_object_unref(folder);
2761 /* For instance, when clicking the Send toolbar button when editing a message: */
2763 modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
2765 TnyTransportAccount *transport_account = NULL;
2766 gboolean had_error = FALSE;
2767 guint64 available_disk, expected_size;
2771 g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window), TRUE);
2773 if (!modest_msg_edit_window_check_names (edit_window, TRUE))
2776 MsgData *data = modest_msg_edit_window_get_msg_data (edit_window);
2779 available_disk = modest_folder_available_space (NULL);
2780 modest_msg_edit_window_get_parts_size (edit_window, &parts_count, &parts_size);
2781 expected_size = modest_tny_msg_estimate_size (data->plain_body,
2786 if ((available_disk != -1) && expected_size > available_disk) {
2787 modest_msg_edit_window_free_msg_data (edit_window, data);
2789 modest_platform_information_banner (NULL, NULL, dgettext("ke-recv", "cerm_device_memory_full"));
2795 * djcb: if we're in low-memory state, we only allow for sending messages
2796 * smaller than MODEST_MAX_LOW_MEMORY_MESSAGE_SIZE (see modest-defs.h)
2797 * this should still allow for sending anything critical...
2799 if (expected_size > MODEST_MAX_LOW_MEMORY_MESSAGE_SIZE) {
2800 if (modest_platform_check_memory_low (MODEST_WINDOW(edit_window), TRUE)) {
2801 modest_msg_edit_window_free_msg_data (edit_window, data);
2807 * djcb: we also make sure that the attachments are smaller than the max size
2808 * this is for the case where we'd try to forward a message with attachments
2809 * bigger than our max allowed size, or sending an message from drafts which
2810 * somehow got past our checks when attaching.
2812 if (expected_size > MODEST_MAX_ATTACHMENT_SIZE) {
2813 modest_platform_run_information_dialog (
2814 GTK_WINDOW(edit_window),
2815 dgettext("ke-recv","memr_ib_operation_disabled"),
2817 modest_msg_edit_window_free_msg_data (edit_window, data);
2821 ModestAccountMgr *account_mgr = modest_runtime_get_account_mgr();
2822 gchar *account_name = g_strdup (data->account_name);
2824 account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
2827 account_name = modest_account_mgr_get_default_account (account_mgr);
2829 if (!account_name) {
2830 modest_msg_edit_window_free_msg_data (edit_window, data);
2831 /* Run account setup wizard */
2832 if (!modest_ui_actions_run_account_setup_wizard (MODEST_WINDOW(edit_window))) {
2837 /* Get the currently-active transport account for this modest account: */
2838 if (strcmp (account_name, MODEST_LOCAL_FOLDERS_ACCOUNT_ID) != 0) {
2839 transport_account = TNY_TRANSPORT_ACCOUNT(modest_tny_account_store_get_server_account
2840 (modest_runtime_get_account_store(),
2841 account_name, TNY_ACCOUNT_TYPE_TRANSPORT));
2844 if (!transport_account) {
2845 modest_msg_edit_window_free_msg_data (edit_window, data);
2846 /* Run account setup wizard */
2847 if (!modest_ui_actions_run_account_setup_wizard(MODEST_WINDOW(edit_window)))
2851 gchar *from = modest_account_mgr_get_from_string (account_mgr, account_name);
2853 /* Create the mail operation */
2854 ModestMailOperation *mail_operation = modest_mail_operation_new_with_error_handling (NULL, modest_ui_actions_disk_operations_error_handler, NULL, NULL);
2855 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
2857 modest_mail_operation_send_new_mail (mail_operation,
2869 data->priority_flags);
2871 if (modest_mail_operation_get_status (mail_operation) == MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS)
2872 modest_platform_information_banner (NULL, NULL, _("mcen_ib_outbox_waiting_to_be_sent"));
2875 if (modest_mail_operation_get_error (mail_operation) != NULL) {
2876 const GError *error = modest_mail_operation_get_error (mail_operation);
2877 if (error->domain == MODEST_MAIL_OPERATION_ERROR &&
2878 error->code == MODEST_MAIL_OPERATION_ERROR_INSTANCE_CREATION_FAILED) {
2879 g_warning ("%s failed: %s\n", __FUNCTION__, (modest_mail_operation_get_error (mail_operation))->message);
2880 modest_platform_information_banner (NULL, NULL, _CS("sfil_ni_not_enough_memory"));
2887 g_free (account_name);
2888 g_object_unref (G_OBJECT (transport_account));
2889 g_object_unref (G_OBJECT (mail_operation));
2891 modest_msg_edit_window_free_msg_data (edit_window, data);
2894 modest_msg_edit_window_set_sent (edit_window, TRUE);
2896 /* Save settings and close the window: */
2897 modest_ui_actions_on_close_window (NULL, MODEST_WINDOW (edit_window));
2904 modest_ui_actions_on_toggle_bold (GtkToggleAction *action,
2905 ModestMsgEditWindow *window)
2907 ModestMsgEditFormatState *format_state = NULL;
2909 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2910 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
2912 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2915 format_state = modest_msg_edit_window_get_format_state (window);
2916 g_return_if_fail (format_state != NULL);
2918 format_state->bold = gtk_toggle_action_get_active (action);
2919 modest_msg_edit_window_set_format_state (window, format_state);
2920 g_free (format_state);
2925 modest_ui_actions_on_toggle_italics (GtkToggleAction *action,
2926 ModestMsgEditWindow *window)
2928 ModestMsgEditFormatState *format_state = NULL;
2930 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2931 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
2933 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2936 format_state = modest_msg_edit_window_get_format_state (window);
2937 g_return_if_fail (format_state != NULL);
2939 format_state->italics = gtk_toggle_action_get_active (action);
2940 modest_msg_edit_window_set_format_state (window, format_state);
2941 g_free (format_state);
2946 modest_ui_actions_on_toggle_bullets (GtkToggleAction *action,
2947 ModestMsgEditWindow *window)
2949 ModestMsgEditFormatState *format_state = NULL;
2951 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2952 g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
2954 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2957 format_state = modest_msg_edit_window_get_format_state (window);
2958 g_return_if_fail (format_state != NULL);
2960 format_state->bullet = gtk_toggle_action_get_active (action);
2961 modest_msg_edit_window_set_format_state (window, format_state);
2962 g_free (format_state);
2967 modest_ui_actions_on_change_justify (GtkRadioAction *action,
2968 GtkRadioAction *selected,
2969 ModestMsgEditWindow *window)
2971 ModestMsgEditFormatState *format_state = NULL;
2972 GtkJustification value;
2974 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2976 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2979 value = gtk_radio_action_get_current_value (selected);
2981 format_state = modest_msg_edit_window_get_format_state (window);
2982 g_return_if_fail (format_state != NULL);
2984 format_state->justification = value;
2985 modest_msg_edit_window_set_format_state (window, format_state);
2986 g_free (format_state);
2990 modest_ui_actions_on_select_editor_color (GtkAction *action,
2991 ModestMsgEditWindow *window)
2993 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
2994 g_return_if_fail (GTK_IS_ACTION (action));
2996 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
2999 modest_msg_edit_window_select_color (window);
3003 modest_ui_actions_on_select_editor_background_color (GtkAction *action,
3004 ModestMsgEditWindow *window)
3006 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3007 g_return_if_fail (GTK_IS_ACTION (action));
3009 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3012 modest_msg_edit_window_select_background_color (window);
3016 modest_ui_actions_on_insert_image (GtkAction *action,
3017 ModestMsgEditWindow *window)
3019 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3020 g_return_if_fail (GTK_IS_ACTION (action));
3023 if (modest_platform_check_memory_low (MODEST_WINDOW(window), TRUE))
3026 if (modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW(window)) == MODEST_MSG_EDIT_FORMAT_TEXT)
3029 modest_msg_edit_window_insert_image (window);
3033 modest_ui_actions_on_attach_file (GtkAction *action,
3034 ModestMsgEditWindow *window)
3036 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3037 g_return_if_fail (GTK_IS_ACTION (action));
3039 if (modest_platform_check_memory_low (MODEST_WINDOW(window), TRUE))
3042 modest_msg_edit_window_offer_attach_file (window);
3046 modest_ui_actions_on_remove_attachments (GtkAction *action,
3047 ModestMsgEditWindow *window)
3049 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
3050 g_return_if_fail (GTK_IS_ACTION (action));
3052 modest_msg_edit_window_remove_attachments (window, NULL);
3056 do_create_folder_cb (ModestMailOperation *mail_op,
3057 TnyFolderStore *parent_folder,
3058 TnyFolder *new_folder,
3061 gchar *suggested_name = (gchar *) user_data;
3062 GtkWindow *source_win = (GtkWindow *) modest_mail_operation_get_source (mail_op);
3064 if (modest_mail_operation_get_error (mail_op)) {
3066 /* Show an error. If there was some problem writing to
3067 disk, show it, otherwise show the generic folder
3068 create error. We do it here and not in an error
3069 handler because the call to do_create_folder will
3070 stop the main loop in a gtk_dialog_run and then,
3071 the message won't be shown until that dialog is
3073 modest_ui_actions_disk_operations_error_handler (mail_op,
3074 _("mail_in_ui_folder_create_error"));
3076 /* Try again. Do *NOT* show any error because the mail
3077 operations system will do it for us because we
3078 created the mail_op with new_with_error_handler */
3079 do_create_folder (source_win, parent_folder, (const gchar *) suggested_name);
3081 /* the 'source_win' is either the ModestMainWindow, or the 'Move to folder'-dialog
3082 * FIXME: any other? */
3083 GtkWidget *folder_view;
3085 if (MODEST_IS_MAIN_WINDOW(source_win))
3087 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (source_win),
3088 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3091 get_folder_view_from_move_to_dialog (GTK_WIDGET(source_win));
3093 /* Select the newly created folder. It could happen
3094 that the widget is no longer there (i.e. the window
3095 has been destroyed, so we need to check this */
3097 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view),
3099 g_object_unref (new_folder);
3101 /* Free. Note that the first time it'll be NULL so noop */
3102 g_free (suggested_name);
3103 g_object_unref (source_win);
3107 do_create_folder (GtkWindow *parent_window,
3108 TnyFolderStore *parent_folder,
3109 const gchar *suggested_name)
3112 gchar *folder_name = NULL;
3114 result = modest_platform_run_new_folder_dialog (GTK_WINDOW (parent_window),
3116 (gchar *) suggested_name,
3119 if (result == GTK_RESPONSE_ACCEPT) {
3120 ModestMailOperation *mail_op;
3122 mail_op = modest_mail_operation_new ((GObject *) parent_window);
3123 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
3125 modest_mail_operation_create_folder (mail_op,
3127 (const gchar *) folder_name,
3128 do_create_folder_cb,
3130 g_object_unref (mail_op);
3135 create_folder_performer (gboolean canceled,
3137 GtkWindow *parent_window,
3138 TnyAccount *account,
3141 TnyFolderStore *parent_folder = TNY_FOLDER_STORE (user_data);
3143 if (canceled || err) {
3144 /* In memory full conditions we could get this error here */
3145 check_memory_full_error ((GtkWidget *) parent_window, err);
3149 /* Run the new folder dialog */
3150 do_create_folder (GTK_WINDOW (parent_window), parent_folder, NULL);
3153 g_object_unref (parent_folder);
3157 modest_ui_actions_create_folder(GtkWidget *parent_window,
3158 GtkWidget *folder_view)
3160 TnyFolderStore *parent_folder;
3162 parent_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
3164 if (parent_folder) {
3165 /* The parent folder will be freed in the callback */
3166 modest_platform_connect_if_remote_and_perform (GTK_WINDOW (parent_window),
3169 create_folder_performer,
3175 modest_ui_actions_on_new_folder (GtkAction *action, ModestMainWindow *main_window)
3177 GtkWidget *folder_view;
3179 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
3181 folder_view = modest_main_window_get_child_widget (main_window,
3182 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3186 modest_ui_actions_create_folder (GTK_WIDGET (main_window), folder_view);
3190 modest_ui_actions_rename_folder_error_handler (ModestMailOperation *mail_op,
3193 const GError *error = NULL;
3194 const gchar *message = NULL;
3196 /* Get error message */
3197 error = modest_mail_operation_get_error (mail_op);
3199 g_return_if_reached ();
3201 if (error->domain == MODEST_MAIL_OPERATION_ERROR &&
3202 error->code == MODEST_MAIL_OPERATION_ERROR_FOLDER_EXISTS) {
3203 message = _CS("ckdg_ib_folder_already_exists");
3204 } else if (error->domain == TNY_ERROR_DOMAIN &&
3205 error->code == TNY_SERVICE_ERROR_STATE) {
3206 /* This means that the folder is already in use (a
3207 message is opened for example */
3208 message = _("emev_ni_internal_error");
3210 message = _("emev_ib_ui_imap_unable_to_rename");
3213 /* We don't set a parent for the dialog because the dialog
3214 will be destroyed so the banner won't appear */
3215 modest_platform_information_banner (NULL, NULL, message);
3219 TnyFolderStore *folder;
3224 on_rename_folder_cb (ModestMailOperation *mail_op,
3225 TnyFolder *new_folder,
3228 ModestFolderView *folder_view;
3230 /* If the window was closed when renaming a folder this could
3232 if (!MODEST_IS_FOLDER_VIEW (user_data))
3235 folder_view = MODEST_FOLDER_VIEW (user_data);
3236 /* Note that if the rename fails new_folder will be NULL */
3238 modest_folder_view_select_folder (folder_view, new_folder, FALSE);
3240 modest_folder_view_select_first_inbox_or_local (folder_view);
3242 gtk_widget_grab_focus (GTK_WIDGET (folder_view));
3246 on_rename_folder_performer (gboolean canceled,
3248 GtkWindow *parent_window,
3249 TnyAccount *account,
3252 ModestMailOperation *mail_op = NULL;
3253 GtkTreeSelection *sel = NULL;
3254 GtkWidget *folder_view = NULL;
3255 RenameFolderInfo *data = (RenameFolderInfo*)user_data;
3257 if (canceled || err) {
3258 /* In memory full conditions we could get this error here */
3259 check_memory_full_error ((GtkWidget *) parent_window, err);
3260 } else if (MODEST_IS_MAIN_WINDOW(parent_window)) {
3262 folder_view = modest_main_window_get_child_widget (
3263 MODEST_MAIN_WINDOW (parent_window),
3264 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3267 modest_mail_operation_new_with_error_handling (G_OBJECT(parent_window),
3268 modest_ui_actions_rename_folder_error_handler,
3269 parent_window, NULL);
3271 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
3274 /* Clear the headers view */
3275 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_view));
3276 gtk_tree_selection_unselect_all (sel);
3278 /* Actually rename the folder */
3279 modest_mail_operation_rename_folder (mail_op,
3280 TNY_FOLDER (data->folder),
3281 (const gchar *) (data->new_name),
3282 on_rename_folder_cb,
3284 g_object_unref (mail_op);
3287 g_free (data->new_name);
3292 modest_ui_actions_on_rename_folder (GtkAction *action,
3293 ModestMainWindow *main_window)
3295 TnyFolderStore *folder;
3296 GtkWidget *folder_view;
3297 GtkWidget *header_view;
3299 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
3301 folder_view = modest_main_window_get_child_widget (main_window,
3302 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3306 header_view = modest_main_window_get_child_widget (main_window,
3307 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
3312 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
3317 if (TNY_IS_FOLDER (folder)) {
3320 const gchar *current_name;
3321 TnyFolderStore *parent;
3322 gboolean do_rename = TRUE;
3324 current_name = tny_folder_get_name (TNY_FOLDER (folder));
3325 parent = tny_folder_get_folder_store (TNY_FOLDER (folder));
3326 response = modest_platform_run_rename_folder_dialog (GTK_WINDOW (main_window),
3327 parent, current_name,
3329 g_object_unref (parent);
3331 if (response != GTK_RESPONSE_ACCEPT || strlen (folder_name) == 0) {
3334 RenameFolderInfo *rename_folder_data = g_new0 (RenameFolderInfo, 1);
3335 rename_folder_data->folder = folder;
3336 rename_folder_data->new_name = folder_name;
3337 modest_platform_connect_if_remote_and_perform (GTK_WINDOW(main_window), TRUE,
3338 folder, on_rename_folder_performer, rename_folder_data);
3341 g_object_unref (folder);
3345 modest_ui_actions_delete_folder_error_handler (ModestMailOperation *mail_op,
3348 GObject *win = modest_mail_operation_get_source (mail_op);
3350 modest_platform_run_information_dialog ((win) ? GTK_WINDOW (win) : NULL,
3351 _("mail_in_ui_folder_delete_error"),
3353 g_object_unref (win);
3357 TnyFolderStore *folder;
3358 gboolean move_to_trash;
3362 on_delete_folder_cb (gboolean canceled,
3364 GtkWindow *parent_window,
3365 TnyAccount *account,
3368 DeleteFolderInfo *info = (DeleteFolderInfo*) user_data;
3369 GtkWidget *folder_view;
3370 ModestMailOperation *mail_op;
3371 GtkTreeSelection *sel;
3373 if (!MODEST_IS_MAIN_WINDOW(parent_window) || canceled || (err!=NULL)) {
3374 g_object_unref (G_OBJECT (info->folder));
3379 folder_view = modest_main_window_get_child_widget (
3380 MODEST_MAIN_WINDOW (parent_window),
3381 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3383 /* Unselect the folder before deleting it to free the headers */
3384 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_view));
3385 gtk_tree_selection_unselect_all (sel);
3387 /* Create the mail operation */
3389 modest_mail_operation_new_with_error_handling (G_OBJECT(parent_window),
3390 modest_ui_actions_delete_folder_error_handler,
3393 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
3395 modest_mail_operation_remove_folder (mail_op, TNY_FOLDER (info->folder), info->move_to_trash);
3397 modest_folder_view_select_first_inbox_or_local (MODEST_FOLDER_VIEW (folder_view));
3399 g_object_unref (G_OBJECT (mail_op));
3400 g_object_unref (G_OBJECT (info->folder));
3405 delete_folder (ModestMainWindow *main_window, gboolean move_to_trash)
3407 TnyFolderStore *folder;
3408 GtkWidget *folder_view;
3412 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
3414 folder_view = modest_main_window_get_child_widget (main_window,
3415 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
3419 folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
3421 /* Show an error if it's an account */
3422 if (!TNY_IS_FOLDER (folder)) {
3423 modest_platform_run_information_dialog (GTK_WINDOW (main_window),
3424 _("mail_in_ui_folder_delete_error"),
3426 g_object_unref (G_OBJECT (folder));
3431 message = g_strdup_printf (_("mcen_nc_delete_folder_text"),
3432 tny_folder_get_name (TNY_FOLDER (folder)));
3433 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (main_window),
3434 (const gchar *) message);
3437 if (response == GTK_RESPONSE_OK) {
3438 DeleteFolderInfo *info;
3439 info = g_new0(DeleteFolderInfo, 1);
3440 info->folder = folder;
3441 info->move_to_trash = move_to_trash;
3442 g_object_ref (G_OBJECT (info->folder));
3443 TnyAccount *account = tny_folder_get_account (TNY_FOLDER (folder));
3444 modest_platform_connect_if_remote_and_perform (GTK_WINDOW (main_window),
3446 TNY_FOLDER_STORE (account),
3447 on_delete_folder_cb, info);
3448 g_object_unref (account);
3450 g_object_unref (G_OBJECT (folder));
3454 modest_ui_actions_on_delete_folder (GtkAction *action,
3455 ModestMainWindow *main_window)
3457 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
3459 delete_folder (main_window, FALSE);
3463 modest_ui_actions_on_move_folder_to_trash_folder (GtkAction *action, ModestMainWindow *main_window)
3465 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
3467 delete_folder (main_window, TRUE);
3471 typedef struct _PasswordDialogFields {
3472 GtkWidget *username;
3473 GtkWidget *password;
3475 } PasswordDialogFields;
3478 password_dialog_check_field (GtkEditable *editable,
3479 PasswordDialogFields *fields)
3482 gboolean any_value_empty = FALSE;
3484 value = gtk_entry_get_text (GTK_ENTRY (fields->username));
3485 if ((value == NULL) || value[0] == '\0') {
3486 any_value_empty = TRUE;
3488 value = gtk_entry_get_text (GTK_ENTRY (fields->password));
3489 if ((value == NULL) || value[0] == '\0') {
3490 any_value_empty = TRUE;
3492 gtk_dialog_set_response_sensitive (GTK_DIALOG (fields->dialog), GTK_RESPONSE_ACCEPT, !any_value_empty);
3496 modest_ui_actions_on_password_requested (TnyAccountStore *account_store,
3497 const gchar* server_account_name,
3502 ModestMainWindow *main_window)
3504 g_return_if_fail(server_account_name);
3505 gboolean completed = FALSE;
3506 PasswordDialogFields *fields = NULL;
3508 /* Initalize output parameters: */
3515 #ifdef MODEST_PLATFORM_MAEMO
3516 /* Maemo uses a different (awkward) button order,
3517 * It should probably just use gtk_alternative_dialog_button_order ().
3519 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
3522 _("mcen_bd_dialog_ok"),
3523 GTK_RESPONSE_ACCEPT,
3524 _("mcen_bd_dialog_cancel"),
3525 GTK_RESPONSE_REJECT,
3528 GtkWidget *dialog = gtk_dialog_new_with_buttons (_("mail_ti_password_protected"),
3532 GTK_RESPONSE_REJECT,
3534 GTK_RESPONSE_ACCEPT,
3536 #endif /* MODEST_PLATFORM_MAEMO */
3538 modest_window_mgr_set_modal (modest_runtime_get_window_mgr(), GTK_WINDOW (dialog));
3540 gchar *server_name = modest_account_mgr_get_server_account_hostname (
3541 modest_runtime_get_account_mgr(), server_account_name);
3542 if (!server_name) {/* This happened once, though I don't know why. murrayc. */
3543 g_warning("%s: Could not get server name for server account '%s'", __FUNCTION__, server_account_name);
3549 /* This causes a warning because the logical ID has no %s in it,
3550 * though the translation does, but there is not much we can do about that: */
3551 gchar *txt = g_strdup_printf (_("mail_ia_password_info"), server_name);
3552 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), gtk_label_new(txt),
3555 g_free (server_name);
3559 gchar *initial_username = modest_account_mgr_get_server_account_username (
3560 modest_runtime_get_account_mgr(), server_account_name);
3562 GtkWidget *entry_username = gtk_entry_new ();
3563 if (initial_username)
3564 gtk_entry_set_text (GTK_ENTRY (entry_username), initial_username);
3565 /* Dim this if a connection has ever succeeded with this username,
3566 * as per the UI spec: */
3567 /* const gboolean username_known = */
3568 /* modest_account_mgr_get_server_account_username_has_succeeded( */
3569 /* modest_runtime_get_account_mgr(), server_account_name); */
3570 /* gtk_widget_set_sensitive (entry_username, !username_known); */
3572 /* We drop the username sensitive code and disallow changing it here
3573 * as tinymail does not support really changing the username in the callback
3575 gtk_widget_set_sensitive (entry_username, FALSE);
3577 #ifdef MODEST_PLATFORM_MAEMO
3578 /* Auto-capitalization is the default, so let's turn it off: */
3579 hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_username), HILDON_GTK_INPUT_MODE_FULL);
3581 /* Create a size group to be used by all captions.
3582 * Note that HildonCaption does not create a default size group if we do not specify one.
3583 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
3584 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
3586 GtkWidget *caption = hildon_caption_new (sizegroup,
3587 _("mail_fi_username"), entry_username, NULL, HILDON_CAPTION_MANDATORY);
3588 gtk_widget_show (entry_username);
3589 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
3590 FALSE, FALSE, MODEST_MARGIN_HALF);
3591 gtk_widget_show (caption);
3593 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry_username,
3595 #endif /* MODEST_PLATFORM_MAEMO */
3598 GtkWidget *entry_password = gtk_entry_new ();
3599 gtk_entry_set_visibility (GTK_ENTRY(entry_password), FALSE);
3600 /* gtk_entry_set_invisible_char (GTK_ENTRY(entry_password), "*"); */
3602 #ifdef MODEST_PLATFORM_MAEMO
3603 /* Auto-capitalization is the default, so let's turn it off: */
3604 hildon_gtk_entry_set_input_mode (GTK_ENTRY (entry_password),
3605 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
3607 caption = hildon_caption_new (sizegroup,
3608 _("mail_fi_password"), entry_password, NULL, HILDON_CAPTION_MANDATORY);
3609 gtk_widget_show (entry_password);
3610 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), caption,
3611 FALSE, FALSE, MODEST_MARGIN_HALF);
3612 gtk_widget_show (caption);
3613 g_object_unref (sizegroup);
3615 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), entry_password,
3617 #endif /* MODEST_PLATFORM_MAEMO */
3619 if (initial_username != NULL)
3620 gtk_widget_grab_focus (GTK_WIDGET (entry_password));
3622 /* This is not in the Maemo UI spec:
3623 remember_pass_check = gtk_check_button_new_with_label (_("Remember password"));
3624 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), remember_pass_check,
3628 fields = g_slice_new0 (PasswordDialogFields);
3629 fields->username = entry_username;
3630 fields->password = entry_password;
3631 fields->dialog = dialog;
3633 g_signal_connect (entry_username, "changed", G_CALLBACK (password_dialog_check_field), fields);
3634 g_signal_connect (entry_password, "changed", G_CALLBACK (password_dialog_check_field), fields);
3635 password_dialog_check_field (NULL, fields);
3637 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
3639 while (!completed) {
3641 if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
3643 *username = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_username)));
3645 /* Note that an empty field becomes the "" string */
3646 if (*username && strlen (*username) > 0) {
3647 modest_account_mgr_set_server_account_username (modest_runtime_get_account_mgr(),
3648 server_account_name,
3652 const gboolean username_was_changed =
3653 (strcmp (*username, initial_username) != 0);
3654 if (username_was_changed) {
3655 g_warning ("%s: tinymail does not yet support changing the "
3656 "username in the get_password() callback.\n", __FUNCTION__);
3660 modest_platform_information_banner (GTK_WIDGET (dialog), NULL,
3661 _("mcen_ib_username_pw_incorrect"));
3667 *password = g_strdup (gtk_entry_get_text (GTK_ENTRY(entry_password)));
3669 /* We do not save the password in the configuration,
3670 * because this function is only called for passwords that should
3671 * not be remembered:
3672 modest_server_account_set_password (
3673 modest_runtime_get_account_mgr(), server_account_name,
3680 /* Set parent to NULL or the banner will disappear with its parent dialog */
3681 modest_platform_information_banner(NULL, NULL, _("mail_ib_login_cancelled"));
3692 /* This is not in the Maemo UI spec:
3693 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (remember_pass_check)))
3699 gtk_widget_destroy (dialog);
3700 g_slice_free (PasswordDialogFields, fields);
3702 /* printf ("DEBUG: %s: cancel=%d\n", __FUNCTION__, *cancel); */
3706 modest_ui_actions_on_cut (GtkAction *action,
3707 ModestWindow *window)
3709 GtkWidget *focused_widget;
3710 GtkClipboard *clipboard;
3712 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
3713 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
3714 if (GTK_IS_EDITABLE (focused_widget)) {
3715 gtk_editable_cut_clipboard (GTK_EDITABLE(focused_widget));
3716 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3717 gtk_clipboard_store (clipboard);
3718 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
3719 GtkTextBuffer *buffer;
3721 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
3722 if (modest_text_utils_buffer_selection_is_valid (buffer)) {
3723 gtk_text_buffer_cut_clipboard (buffer, clipboard, TRUE);
3724 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3725 gtk_clipboard_store (clipboard);
3727 } else if (MODEST_IS_HEADER_VIEW (focused_widget)) {
3728 TnyList *header_list = modest_header_view_get_selected_headers (
3729 MODEST_HEADER_VIEW (focused_widget));
3730 gboolean continue_download = FALSE;
3731 gint num_of_unc_msgs;
3733 num_of_unc_msgs = header_list_count_uncached_msgs(header_list);
3735 if (num_of_unc_msgs) {
3736 TnyAccount *account = get_account_from_header_list (header_list);
3738 continue_download = connect_to_get_msg (window, num_of_unc_msgs, account);
3739 g_object_unref (account);
3743 if (num_of_unc_msgs == 0 || continue_download) {
3744 /* modest_platform_information_banner (
3745 NULL, NULL, _CS("mcen_ib_getting_items"));*/
3746 modest_header_view_cut_selection (
3747 MODEST_HEADER_VIEW (focused_widget));
3750 g_object_unref (header_list);
3751 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
3752 modest_folder_view_cut_selection (MODEST_FOLDER_VIEW (focused_widget));
3757 modest_ui_actions_on_copy (GtkAction *action,
3758 ModestWindow *window)
3760 GtkClipboard *clipboard;
3761 GtkWidget *focused_widget;
3762 gboolean copied = TRUE;
3764 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
3765 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
3767 if (GTK_IS_LABEL (focused_widget)) {
3769 selection = modest_text_utils_label_get_selection (GTK_LABEL (focused_widget));
3770 gtk_clipboard_set_text (clipboard, selection, -1);
3772 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3773 gtk_clipboard_store (clipboard);
3774 } else if (GTK_IS_EDITABLE (focused_widget)) {
3775 gtk_editable_copy_clipboard (GTK_EDITABLE(focused_widget));
3776 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3777 gtk_clipboard_store (clipboard);
3778 } else if (GTK_IS_HTML (focused_widget)) {
3779 gtk_html_copy (GTK_HTML (focused_widget));
3780 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3781 gtk_clipboard_store (clipboard);
3782 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
3783 GtkTextBuffer *buffer;
3784 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
3785 if (modest_text_utils_buffer_selection_is_valid (buffer)) {
3786 gtk_text_buffer_copy_clipboard (buffer, clipboard);
3787 gtk_clipboard_set_can_store (clipboard, NULL, 0);
3788 gtk_clipboard_store (clipboard);
3790 } else if (MODEST_IS_HEADER_VIEW (focused_widget)) {
3791 TnyList *header_list = modest_header_view_get_selected_headers (
3792 MODEST_HEADER_VIEW (focused_widget));
3793 gboolean continue_download = FALSE;
3794 gint num_of_unc_msgs;
3796 num_of_unc_msgs = header_list_count_uncached_msgs(header_list);
3798 if (num_of_unc_msgs) {
3799 TnyAccount *account = get_account_from_header_list (header_list);
3801 continue_download = connect_to_get_msg (window, num_of_unc_msgs, account);
3802 g_object_unref (account);
3806 if (num_of_unc_msgs == 0 || continue_download) {
3807 modest_platform_information_banner (
3808 NULL, NULL, _CS("mcen_ib_getting_items"));
3809 modest_header_view_copy_selection (
3810 MODEST_HEADER_VIEW (focused_widget));
3814 g_object_unref (header_list);
3816 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
3817 modest_folder_view_copy_selection (MODEST_FOLDER_VIEW (focused_widget));
3820 /* Show information banner if there was a copy to clipboard */
3822 modest_platform_information_banner (
3823 NULL, NULL, _CS("ecoc_ib_edwin_copied"));
3827 modest_ui_actions_on_undo (GtkAction *action,
3828 ModestWindow *window)
3830 ModestEmailClipboard *clipboard = NULL;
3832 if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
3833 modest_msg_edit_window_undo (MODEST_MSG_EDIT_WINDOW (window));
3834 } else if (MODEST_IS_MAIN_WINDOW (window)) {
3835 /* Clear clipboard source */
3836 clipboard = modest_runtime_get_email_clipboard ();
3837 modest_email_clipboard_clear (clipboard);
3840 g_return_if_reached ();
3845 modest_ui_actions_on_redo (GtkAction *action,
3846 ModestWindow *window)
3848 if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
3849 modest_msg_edit_window_redo (MODEST_MSG_EDIT_WINDOW (window));
3852 g_return_if_reached ();
3858 destroy_information_note (ModestMailOperation *mail_op,
3861 /* destroy information note */
3862 gtk_widget_destroy (GTK_WIDGET(user_data));
3866 destroy_folder_information_note (ModestMailOperation *mail_op,
3867 TnyFolder *new_folder,
3870 /* destroy information note */
3871 gtk_widget_destroy (GTK_WIDGET(user_data));
3876 paste_as_attachment_free (gpointer data)
3878 PasteAsAttachmentHelper *helper = (PasteAsAttachmentHelper *) data;
3880 if (helper->banner) {
3881 gtk_widget_destroy (helper->banner);
3882 g_object_unref (helper->banner);
3888 paste_msg_as_attachment_cb (ModestMailOperation *mail_op,
3893 PasteAsAttachmentHelper *helper = (PasteAsAttachmentHelper *) userdata;
3894 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (helper->window));
3899 modest_msg_edit_window_add_part (MODEST_MSG_EDIT_WINDOW (helper->window), TNY_MIME_PART (msg));
3904 modest_ui_actions_on_paste (GtkAction *action,
3905 ModestWindow *window)
3907 GtkWidget *focused_widget = NULL;
3908 GtkWidget *inf_note = NULL;
3909 ModestMailOperation *mail_op = NULL;
3911 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
3912 if (GTK_IS_EDITABLE (focused_widget)) {
3913 gtk_editable_paste_clipboard (GTK_EDITABLE(focused_widget));
3914 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
3915 ModestEmailClipboard *e_clipboard = NULL;
3916 e_clipboard = modest_runtime_get_email_clipboard ();
3917 if (modest_email_clipboard_cleared (e_clipboard)) {
3918 GtkTextBuffer *buffer;
3919 GtkClipboard *clipboard;
3921 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
3922 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
3923 gtk_text_buffer_paste_clipboard (buffer, clipboard, NULL, TRUE);
3924 } else if (MODEST_IS_MSG_EDIT_WINDOW (window)) {
3925 ModestMailOperation *mail_op;
3926 TnyFolder *src_folder;
3929 PasteAsAttachmentHelper *helper = g_new0 (PasteAsAttachmentHelper, 1);
3930 helper->window = MODEST_MSG_EDIT_WINDOW (window);
3931 helper->banner = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
3932 _CS("ckct_nw_pasting"));
3933 modest_email_clipboard_get_data (e_clipboard, &src_folder, &data, &delete);
3934 mail_op = modest_mail_operation_new (G_OBJECT (window));
3935 if (helper->banner != NULL) {
3936 g_object_ref (G_OBJECT (helper->banner));
3937 gtk_widget_show (GTK_WIDGET (helper->banner));
3941 modest_mail_operation_get_msgs_full (mail_op,
3943 (GetMsgAsyncUserCallback) paste_msg_as_attachment_cb,
3945 paste_as_attachment_free);
3948 } else if (MODEST_IS_FOLDER_VIEW (focused_widget)) {
3949 ModestEmailClipboard *clipboard = NULL;
3950 TnyFolder *src_folder = NULL;
3951 TnyFolderStore *folder_store = NULL;
3952 TnyList *data = NULL;
3953 gboolean delete = FALSE;
3955 /* Check clipboard source */
3956 clipboard = modest_runtime_get_email_clipboard ();
3957 if (modest_email_clipboard_cleared (clipboard))
3960 /* Get elements to paste */
3961 modest_email_clipboard_get_data (clipboard, &src_folder, &data, &delete);
3963 /* Create a new mail operation */
3964 mail_op = modest_mail_operation_new (G_OBJECT(window));
3966 /* Get destination folder */
3967 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (focused_widget));
3969 /* transfer messages */
3973 /* Ask for user confirmation */
3975 modest_ui_actions_msgs_move_to_confirmation (window,
3976 TNY_FOLDER (folder_store),
3980 if (response == GTK_RESPONSE_OK) {
3981 /* Launch notification */
3982 inf_note = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
3983 _CS("ckct_nw_pasting"));
3984 if (inf_note != NULL) {
3985 gtk_window_set_modal (GTK_WINDOW(inf_note), FALSE);
3986 gtk_widget_show (GTK_WIDGET(inf_note));
3989 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
3990 modest_mail_operation_xfer_msgs (mail_op,
3992 TNY_FOLDER (folder_store),
3994 destroy_information_note,
3997 g_object_unref (mail_op);
4000 } else if (src_folder != NULL) {
4001 /* Launch notification */
4002 inf_note = modest_platform_animation_banner (GTK_WIDGET (window), NULL,
4003 _CS("ckct_nw_pasting"));
4004 if (inf_note != NULL) {
4005 gtk_window_set_modal (GTK_WINDOW(inf_note), FALSE);
4006 gtk_widget_show (GTK_WIDGET(inf_note));
4009 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
4010 modest_mail_operation_xfer_folder (mail_op,
4014 destroy_folder_information_note,
4020 g_object_unref (data);
4021 if (src_folder != NULL)
4022 g_object_unref (src_folder);
4023 if (folder_store != NULL)
4024 g_object_unref (folder_store);
4030 modest_ui_actions_on_select_all (GtkAction *action,
4031 ModestWindow *window)
4033 GtkWidget *focused_widget;
4035 focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
4036 if (MODEST_IS_ATTACHMENTS_VIEW (focused_widget)) {
4037 modest_attachments_view_select_all (MODEST_ATTACHMENTS_VIEW (focused_widget));
4038 } else if (GTK_IS_LABEL (focused_widget)) {
4039 gtk_label_select_region (GTK_LABEL (focused_widget), 0, -1);
4040 } else if (GTK_IS_EDITABLE (focused_widget)) {
4041 gtk_editable_select_region (GTK_EDITABLE(focused_widget), 0, -1);
4042 } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
4043 GtkTextBuffer *buffer;
4044 GtkTextIter start, end;
4046 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
4047 gtk_text_buffer_get_start_iter (buffer, &start);
4048 gtk_text_buffer_get_end_iter (buffer, &end);
4049 gtk_text_buffer_select_range (buffer, &start, &end);
4050 } else if (GTK_IS_HTML (focused_widget)) {
4051 gtk_html_select_all (GTK_HTML (focused_widget));
4052 } else if (MODEST_IS_MAIN_WINDOW (window)) {
4053 GtkWidget *header_view = focused_widget;
4054 GtkTreeSelection *selection = NULL;
4056 if (!(MODEST_IS_HEADER_VIEW (focused_widget))) {
4057 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (window),
4058 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
4061 /* Disable window dimming management */
4062 modest_window_disable_dimming (MODEST_WINDOW(window));
4064 /* Select all messages */
4065 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(header_view));
4066 gtk_tree_selection_select_all (selection);
4068 /* Set focuse on header view */
4069 gtk_widget_grab_focus (header_view);
4072 /* Enable window dimming management */
4073 modest_window_enable_dimming (MODEST_WINDOW(window));
4074 modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (window));
4080 modest_ui_actions_on_mark_as_read (GtkAction *action,
4081 ModestWindow *window)
4083 g_return_if_fail (MODEST_IS_WINDOW(window));
4085 /* Mark each header as read */
4086 do_headers_action (window, headers_action_mark_as_read, NULL);
4090 modest_ui_actions_on_mark_as_unread (GtkAction *action,
4091 ModestWindow *window)
4093 g_return_if_fail (MODEST_IS_WINDOW(window));
4095 /* Mark each header as read */
4096 do_headers_action (window, headers_action_mark_as_unread, NULL);
4100 modest_ui_actions_on_change_zoom (GtkRadioAction *action,
4101 GtkRadioAction *selected,
4102 ModestWindow *window)
4106 value = gtk_radio_action_get_current_value (selected);
4107 if (MODEST_IS_WINDOW (window)) {
4108 modest_window_set_zoom (MODEST_WINDOW (window), ((gdouble)value)/100);
4113 modest_ui_actions_msg_edit_on_change_priority (GtkRadioAction *action,
4114 GtkRadioAction *selected,
4115 ModestWindow *window)
4117 TnyHeaderFlags flags;
4118 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4120 flags = gtk_radio_action_get_current_value (selected);
4121 modest_msg_edit_window_set_priority_flags (MODEST_MSG_EDIT_WINDOW (window), flags);
4125 modest_ui_actions_msg_edit_on_change_file_format (GtkRadioAction *action,
4126 GtkRadioAction *selected,
4127 ModestWindow *window)
4131 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4133 file_format = gtk_radio_action_get_current_value (selected);
4134 modest_msg_edit_window_set_file_format (MODEST_MSG_EDIT_WINDOW (window), file_format);
4139 modest_ui_actions_on_zoom_plus (GtkAction *action,
4140 ModestWindow *window)
4142 g_return_if_fail (MODEST_IS_WINDOW (window));
4144 modest_window_zoom_plus (MODEST_WINDOW (window));
4148 modest_ui_actions_on_zoom_minus (GtkAction *action,
4149 ModestWindow *window)
4151 g_return_if_fail (MODEST_IS_WINDOW (window));
4153 modest_window_zoom_minus (MODEST_WINDOW (window));
4157 modest_ui_actions_on_toggle_fullscreen (GtkToggleAction *toggle,
4158 ModestWindow *window)
4160 ModestWindowMgr *mgr;
4161 gboolean fullscreen, active;
4162 g_return_if_fail (MODEST_IS_WINDOW (window));
4164 mgr = modest_runtime_get_window_mgr ();
4166 active = (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle)))?1:0;
4167 fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
4169 if (active != fullscreen) {
4170 modest_window_mgr_set_fullscreen_mode (mgr, active);
4171 gtk_window_present (GTK_WINDOW (window));
4176 modest_ui_actions_on_change_fullscreen (GtkAction *action,
4177 ModestWindow *window)
4179 ModestWindowMgr *mgr;
4180 gboolean fullscreen;
4182 g_return_if_fail (MODEST_IS_WINDOW (window));
4184 mgr = modest_runtime_get_window_mgr ();
4185 fullscreen = modest_window_mgr_get_fullscreen_mode (mgr);
4186 modest_window_mgr_set_fullscreen_mode (mgr, !fullscreen);
4188 gtk_window_present (GTK_WINDOW (window));
4192 * Used by modest_ui_actions_on_details to call do_headers_action
4195 headers_action_show_details (TnyHeader *header,
4196 ModestWindow *window,
4203 dialog = modest_details_dialog_new_with_header (GTK_WINDOW (window), header);
4206 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
4207 gtk_widget_show_all (dialog);
4208 gtk_dialog_run (GTK_DIALOG (dialog));
4210 gtk_widget_destroy (dialog);
4214 * Show the folder details in a ModestDetailsDialog widget
4217 show_folder_details (TnyFolder *folder,
4223 dialog = modest_details_dialog_new_with_folder (window, folder);
4226 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
4227 gtk_widget_show_all (dialog);
4228 gtk_dialog_run (GTK_DIALOG (dialog));
4230 gtk_widget_destroy (dialog);
4234 * Show the header details in a ModestDetailsDialog widget
4237 modest_ui_actions_on_details (GtkAction *action,
4240 TnyList * headers_list;
4244 if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
4247 msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW (win));
4250 g_object_unref (msg);
4252 headers_list = get_selected_headers (win);
4256 iter = tny_list_create_iterator (headers_list);
4258 header = TNY_HEADER (tny_iterator_get_current (iter));
4260 headers_action_show_details (header, win, NULL);
4261 g_object_unref (header);
4264 g_object_unref (iter);
4265 g_object_unref (headers_list);
4267 } else if (MODEST_IS_MAIN_WINDOW (win)) {
4268 GtkWidget *folder_view, *header_view;
4270 /* Check which widget has the focus */
4271 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
4272 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
4273 if (gtk_widget_is_focus (folder_view)) {
4274 TnyFolderStore *folder_store
4275 = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
4276 if (!folder_store) {
4277 g_warning ("%s: No item was selected.\n", __FUNCTION__);
4280 /* Show only when it's a folder */
4281 /* This function should not be called for account items,
4282 * because we dim the menu item for them. */
4283 if (TNY_IS_FOLDER (folder_store)) {
4284 show_folder_details (TNY_FOLDER (folder_store), GTK_WINDOW (win));
4287 g_object_unref (folder_store);
4290 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
4291 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
4292 /* Show details of each header */
4293 do_headers_action (win, headers_action_show_details, header_view);
4299 modest_ui_actions_on_toggle_show_cc (GtkToggleAction *toggle,
4300 ModestMsgEditWindow *window)
4302 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4304 modest_msg_edit_window_show_cc (window, gtk_toggle_action_get_active (toggle));
4308 modest_ui_actions_on_toggle_show_bcc (GtkToggleAction *toggle,
4309 ModestMsgEditWindow *window)
4311 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4313 modest_msg_edit_window_show_bcc (window, gtk_toggle_action_get_active (toggle));
4317 modest_ui_actions_toggle_folders_view (GtkAction *action,
4318 ModestMainWindow *main_window)
4320 g_return_if_fail (MODEST_IS_MAIN_WINDOW(main_window));
4322 if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)))
4323 modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SPLIT);
4325 modest_main_window_set_style (main_window, MODEST_MAIN_WINDOW_STYLE_SIMPLE);
4329 modest_ui_actions_on_toggle_toolbar (GtkToggleAction *toggle,
4330 ModestWindow *window)
4332 gboolean active, fullscreen = FALSE;
4333 ModestWindowMgr *mgr;
4335 active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (toggle));
4337 /* Check if we want to toggle the toolbar vuew in fullscreen
4339 if (!strcmp (gtk_action_get_name (GTK_ACTION (toggle)),
4340 "ViewShowToolbarFullScreen")) {
4344 /* Toggle toolbar */
4345 mgr = modest_runtime_get_window_mgr ();
4346 modest_window_mgr_show_toolbars (mgr, G_TYPE_FROM_INSTANCE (window), active, fullscreen);
4350 modest_ui_actions_msg_edit_on_select_font (GtkAction *action,
4351 ModestMsgEditWindow *window)
4353 modest_msg_edit_window_select_font (window);
4358 modest_ui_actions_on_folder_display_name_changed (ModestFolderView *folder_view,
4359 const gchar *display_name,
4362 /* don't update the display name if it was already set;
4363 * updating the display name apparently is expensive */
4364 const gchar* old_name = gtk_window_get_title (window);
4366 if (display_name == NULL)
4369 if (old_name && display_name && strcmp (old_name, display_name) == 0)
4370 return; /* don't do anything */
4372 /* This is usually used to change the title of the main window, which
4373 * is the one that holds the folder view. Note that this change can
4374 * happen even when the widget doesn't have the focus. */
4375 gtk_window_set_title (window, display_name);
4380 modest_ui_actions_on_select_contacts (GtkAction *action, ModestMsgEditWindow *window)
4382 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4383 modest_msg_edit_window_select_contacts (window);
4387 modest_ui_actions_on_check_names (GtkAction *action, ModestMsgEditWindow *window)
4389 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
4390 modest_msg_edit_window_check_names (window, FALSE);
4394 create_move_to_dialog_on_new_folder(GtkWidget *button, gpointer user_data)
4396 modest_ui_actions_create_folder (gtk_widget_get_toplevel (button),
4397 GTK_WIDGET (user_data));
4401 * This function is used to track changes in the selection of the
4402 * folder view that is inside the "move to" dialog to enable/disable
4403 * the OK button because we do not want the user to select a disallowed
4404 * destination for a folder.
4405 * The user also not desired to be able to use NEW button on items where
4406 * folder creation is not possibel.
4409 on_move_to_dialog_folder_selection_changed (ModestFolderView* self,
4410 TnyFolderStore *folder_store,
4414 GtkWidget *dialog = NULL;
4415 GtkWidget *ok_button = NULL, *new_button = NULL;
4416 GList *children = NULL;
4417 gboolean ok_sensitive = TRUE, new_sensitive = TRUE;
4418 gboolean moving_folder = FALSE;
4419 gboolean is_local_account = TRUE;
4420 GtkWidget *folder_view = NULL;
4421 ModestTnyFolderRules rules;
4423 g_return_if_fail (MODEST_IS_FOLDER_VIEW(self));
4428 /* Get the OK button */
4429 dialog = gtk_widget_get_ancestor (GTK_WIDGET (self), GTK_TYPE_DIALOG);
4433 children = gtk_container_get_children (GTK_CONTAINER (GTK_DIALOG (dialog)->action_area));
4434 #ifdef MODEST_PLATFORM_MAEMO
4435 ok_button = GTK_WIDGET (children->next->next->data);
4436 new_button = GTK_WIDGET (children->next->data);
4438 ok_button = GTK_WIDGET (children->data);
4439 new_button = GTK_WIDGET (children->next->next->data);
4441 g_list_free (children);
4443 /* check if folder_store is an remote account */
4444 if (TNY_IS_ACCOUNT (folder_store)) {
4445 TnyAccount *local_account = NULL;
4446 TnyAccount *mmc_account = NULL;
4447 ModestTnyAccountStore *account_store = NULL;
4449 account_store = modest_runtime_get_account_store ();
4450 local_account = modest_tny_account_store_get_local_folders_account (account_store);
4451 mmc_account = modest_tny_account_store_get_mmc_folders_account (account_store);
4453 if ((gpointer) local_account != (gpointer) folder_store &&
4454 (gpointer) mmc_account != (gpointer) folder_store) {
4455 const char *proto_name = tny_account_get_proto (TNY_ACCOUNT (folder_store));
4456 ModestTransportStoreProtocol proto = MODEST_PROTOCOL_STORE_MAILDIR;
4457 if (proto_name != NULL) {
4458 proto = modest_protocol_info_get_transport_store_protocol (proto_name);
4460 is_local_account = FALSE;
4461 /* New button should be dimmed on remote
4463 new_sensitive = (proto != MODEST_PROTOCOL_STORE_POP);
4465 g_object_unref (local_account);
4466 g_object_unref (mmc_account);
4469 /* Check the target folder rules */
4470 if (TNY_IS_FOLDER (folder_store)) {
4471 rules = modest_tny_folder_get_rules (TNY_FOLDER (folder_store));
4472 if (rules & MODEST_FOLDER_RULES_FOLDER_NON_WRITEABLE) {
4473 ok_sensitive = FALSE;
4474 new_sensitive = FALSE;
4479 /* Check if we're moving a folder */
4480 if (MODEST_IS_MAIN_WINDOW (user_data)) {
4481 /* Get the widgets */
4482 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (user_data),
4483 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
4484 if (gtk_widget_is_focus (folder_view))
4485 moving_folder = TRUE;
4488 if (moving_folder) {
4489 TnyFolderStore *moved_folder = NULL, *parent = NULL;
4491 /* Get the folder to move */
4492 moved_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
4494 /* Check that we're not moving to the same folder */
4495 if (TNY_IS_FOLDER (moved_folder)) {
4496 parent = tny_folder_get_folder_store (TNY_FOLDER (moved_folder));
4497 if (parent == folder_store)
4498 ok_sensitive = FALSE;
4499 g_object_unref (parent);
4502 if (ok_sensitive && TNY_IS_ACCOUNT (folder_store)) {
4503 /* Do not allow to move to an account unless it's the
4504 local folders account */
4505 if (!is_local_account)
4506 ok_sensitive = FALSE;
4509 if (ok_sensitive && (moved_folder == folder_store)) {
4510 /* Do not allow to move to itself */
4511 ok_sensitive = FALSE;
4513 g_object_unref (moved_folder);
4515 TnyFolder *src_folder = NULL;
4517 /* Moving a message */
4518 if (MODEST_IS_MSG_VIEW_WINDOW (user_data)) {
4520 TnyHeader *header = NULL;
4521 header = modest_msg_view_window_get_header
4522 (MODEST_MSG_VIEW_WINDOW (user_data));
4523 if (!TNY_IS_HEADER(header))
4524 g_warning ("%s: could not get source header", __FUNCTION__);
4526 src_folder = tny_header_get_folder (header);
4529 g_object_unref (header);
4532 TNY_FOLDER (modest_folder_view_get_selected
4533 (MODEST_FOLDER_VIEW (folder_view)));
4536 if (TNY_IS_FOLDER(src_folder)) {
4537 /* Do not allow to move the msg to the same folder */
4538 /* Do not allow to move the msg to an account */
4539 if ((gpointer) src_folder == (gpointer) folder_store ||
4540 TNY_IS_ACCOUNT (folder_store))
4541 ok_sensitive = FALSE;
4542 g_object_unref (src_folder);
4544 g_warning ("%s: could not get source folder", __FUNCTION__);
4548 /* Set sensitivity of the OK button */
4549 gtk_widget_set_sensitive (ok_button, ok_sensitive);
4550 /* Set sensitivity of the NEW button */
4551 gtk_widget_set_sensitive (new_button, new_sensitive);
4555 #define MODEST_MOVE_TO_DIALOG_FOLDER_VIEW "move-to-dialog-folder-view"
4558 get_folder_view_from_move_to_dialog (GtkWidget *move_to_dialog)
4560 return GTK_WIDGET(g_object_get_data (G_OBJECT(move_to_dialog),
4561 MODEST_MOVE_TO_DIALOG_FOLDER_VIEW));
4565 create_move_to_dialog (GtkWindow *win,
4566 GtkWidget *folder_view,
4567 GtkWidget **tree_view)
4569 GtkWidget *dialog, *scroll;
4570 GtkWidget *new_button;
4572 dialog = gtk_dialog_new_with_buttons (_("mcen_ti_moveto_folders_title"),
4574 GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR | GTK_DIALOG_DESTROY_WITH_PARENT,
4577 #ifdef MODEST_PLATFORM_MAEMO
4578 gtk_dialog_add_button (GTK_DIALOG (dialog), _("mcen_bd_dialog_ok"), GTK_RESPONSE_ACCEPT);
4579 /* We do this manually so GTK+ does not associate a response ID for
4581 new_button = gtk_button_new_from_stock (_("mcen_bd_new"));
4582 gtk_box_pack_end (GTK_BOX (GTK_DIALOG (dialog)->action_area), new_button, FALSE, FALSE, 0);
4583 gtk_dialog_add_button (GTK_DIALOG (dialog), _("mcen_bd_dialog_cancel"), GTK_RESPONSE_REJECT);
4585 /* We do this manually so GTK+ does not associate a response ID for
4587 new_button = gtk_button_new_with_label (_("mcen_ti_new_folder"));
4588 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area), new_button, FALSE, FALSE, 0);
4589 gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (GTK_DIALOG (dialog)->action_area), new_button, TRUE);
4590 gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT);
4591 gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_OK, GTK_RESPONSE_ACCEPT);
4592 gtk_container_set_border_width (GTK_CONTAINER (dialog), 12);
4593 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 24);
4596 /* Create scrolled window */
4597 scroll = gtk_scrolled_window_new (NULL, NULL);
4598 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll),
4599 GTK_POLICY_AUTOMATIC,
4600 GTK_POLICY_AUTOMATIC);
4602 #ifndef MODEST_PLATFORM_MAEMO
4603 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scroll), GTK_SHADOW_IN);
4606 /* Create folder view */
4607 *tree_view = modest_platform_create_folder_view (NULL);
4609 /* Track changes in the selection to
4610 * disable the OK button whenever "Move to" is not possible
4611 * disbale NEW button whenever New is not possible */
4612 g_signal_connect (*tree_view,
4613 "folder_selection_changed",
4614 G_CALLBACK (on_move_to_dialog_folder_selection_changed),
4617 /* Listen to clicks on New button */
4618 g_signal_connect (G_OBJECT (new_button),
4620 G_CALLBACK(create_move_to_dialog_on_new_folder),
4623 /* It could happen that we're trying to move a message from a
4624 window (msg window for example) after the main window was
4625 closed, so we can not just get the model of the folder
4627 if (MODEST_IS_FOLDER_VIEW (folder_view)) {
4628 const gchar *visible_id = NULL;
4630 modest_folder_view_set_style (MODEST_FOLDER_VIEW (*tree_view),
4631 MODEST_FOLDER_VIEW_STYLE_SHOW_ALL);
4632 modest_folder_view_copy_model (MODEST_FOLDER_VIEW(folder_view),
4633 MODEST_FOLDER_VIEW(*tree_view));
4636 modest_folder_view_get_account_id_of_visible_server_account (MODEST_FOLDER_VIEW(folder_view));
4638 /* Show the same account than the one that is shown in the main window */
4639 modest_folder_view_set_account_id_of_visible_server_account (MODEST_FOLDER_VIEW(*tree_view),
4642 const gchar *active_account_name = NULL;
4643 ModestAccountMgr *mgr = NULL;
4644 ModestAccountSettings *settings = NULL;
4645 ModestServerAccountSettings *store_settings = NULL;
4647 modest_folder_view_set_style (MODEST_FOLDER_VIEW (*tree_view),
4648 MODEST_FOLDER_VIEW_STYLE_SHOW_ALL);
4649 modest_folder_view_update_model (MODEST_FOLDER_VIEW (*tree_view),
4650 TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()));
4652 active_account_name = modest_window_get_active_account (MODEST_WINDOW (win));
4653 mgr = modest_runtime_get_account_mgr ();
4654 settings = modest_account_mgr_load_account_settings (mgr, active_account_name);
4657 const gchar *store_account_name;
4658 store_settings = modest_account_settings_get_store_settings (settings);
4659 store_account_name = modest_server_account_settings_get_account_name (store_settings);
4661 modest_folder_view_set_account_id_of_visible_server_account (MODEST_FOLDER_VIEW (*tree_view),
4662 store_account_name);
4663 g_object_unref (store_settings);
4664 g_object_unref (settings);
4668 /* we keep a pointer to the embedded folder view, so we can retrieve it with
4669 * get_folder_view_from_move_to_dialog
4670 * (see above) later (needed for focus handling)
4672 g_object_set_data (G_OBJECT(dialog), MODEST_MOVE_TO_DIALOG_FOLDER_VIEW, *tree_view);
4675 /* Hide special folders */
4676 modest_folder_view_show_non_move_folders (MODEST_FOLDER_VIEW (*tree_view), FALSE);
4678 gtk_container_add (GTK_CONTAINER (scroll), *tree_view);
4680 /* Add scroll to dialog */
4681 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
4682 scroll, TRUE, TRUE, 0);
4684 gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox));
4685 #ifdef MODEST_PLATFORM_MAEMO
4686 gtk_window_set_default_size (GTK_WINDOW (dialog), 300, 300);
4688 gtk_window_set_default_size (GTK_WINDOW (dialog), 600, 400);
4697 * Shows a confirmation dialog to the user when we're moving messages
4698 * from a remote server to the local storage. Returns the dialog
4699 * response. If it's other kind of movement then it always returns
4702 * This one is used by the next functions:
4703 * modest_ui_actions_on_paste - commented out
4704 * drag_and_drop_from_header_view (for d&d in modest_folder_view.c)
4707 modest_ui_actions_msgs_move_to_confirmation (ModestWindow *win,
4708 TnyFolder *dest_folder,
4712 gint response = GTK_RESPONSE_OK;
4713 TnyAccount *account = NULL;
4714 TnyFolder *src_folder = NULL;
4715 TnyIterator *iter = NULL;
4716 TnyHeader *header = NULL;
4718 /* return with OK if the destination is a remote folder */
4719 if (modest_tny_folder_is_remote_folder (dest_folder))
4720 return GTK_RESPONSE_OK;
4722 /* Get source folder */
4723 iter = tny_list_create_iterator (headers);
4724 header = TNY_HEADER (tny_iterator_get_current (iter));
4726 src_folder = tny_header_get_folder (header);
4727 g_object_unref (header);
4729 g_object_unref (iter);
4731 /* if no src_folder, message may be an attahcment */
4732 if (src_folder == NULL)
4733 return GTK_RESPONSE_CANCEL;
4735 /* If the source is a local or MMC folder */
4736 if (!modest_tny_folder_is_remote_folder (src_folder)) {
4737 g_object_unref (src_folder);
4738 return GTK_RESPONSE_OK;
4741 /* Get the account */
4742 account = tny_folder_get_account (src_folder);
4744 /* now if offline we ask the user */
4745 if(connect_to_get_msg (win, tny_list_get_length (headers), account))
4746 response = GTK_RESPONSE_OK;
4748 response = GTK_RESPONSE_CANCEL;
4751 g_object_unref (src_folder);
4752 g_object_unref (account);
4758 move_to_helper_destroyer (gpointer user_data)
4760 MoveToHelper *helper = (MoveToHelper *) user_data;
4762 /* Close the "Pasting" information banner */
4763 if (helper->banner) {
4764 gtk_widget_destroy (GTK_WIDGET (helper->banner));
4765 g_object_unref (helper->banner);
4767 if (helper->reference != NULL)
4768 gtk_tree_row_reference_free (helper->reference);
4773 move_to_cb (ModestMailOperation *mail_op,
4776 MoveToHelper *helper = (MoveToHelper *) user_data;
4778 /* Note that the operation could have failed, in that case do
4780 if (modest_mail_operation_get_status (mail_op) ==
4781 MODEST_MAIL_OPERATION_STATUS_SUCCESS) {
4783 GObject *object = modest_mail_operation_get_source (mail_op);
4784 if (MODEST_IS_MSG_VIEW_WINDOW (object)) {
4785 ModestMsgViewWindow *self = MODEST_MSG_VIEW_WINDOW (object);
4787 if (!modest_msg_view_window_select_next_message (self) &&
4788 !modest_msg_view_window_select_previous_message (self)) {
4789 /* No more messages to view, so close this window */
4790 modest_ui_actions_on_close_window (NULL, MODEST_WINDOW(self));
4792 } else if (MODEST_IS_MAIN_WINDOW (object) && helper->reference != NULL) {
4793 GtkWidget *header_view;
4795 GtkTreeSelection *sel;
4797 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(object),
4798 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
4799 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (header_view));
4800 path = gtk_tree_row_reference_get_path (helper->reference);
4801 /* We need to unselect the previous one
4802 because we could be copying instead of
4804 gtk_tree_selection_unselect_all (sel);
4805 gtk_tree_selection_select_path (sel, path);
4806 gtk_tree_path_free (path);
4808 g_object_unref (object);
4810 /* Destroy the helper */
4811 move_to_helper_destroyer (helper);
4815 folder_move_to_cb (ModestMailOperation *mail_op,
4816 TnyFolder *new_folder,
4819 GtkWidget *folder_view;
4822 object = modest_mail_operation_get_source (mail_op);
4823 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(object),
4824 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
4825 g_object_ref (folder_view);
4826 g_object_unref (object);
4827 move_to_cb (mail_op, user_data);
4828 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view), new_folder, FALSE);
4829 g_object_unref (folder_view);
4833 msgs_move_to_cb (ModestMailOperation *mail_op,
4836 move_to_cb (mail_op, user_data);
4840 modest_ui_actions_move_folder_error_handler (ModestMailOperation *mail_op,
4843 ModestWindow *main_window = NULL;
4845 /* Disable next automatic folder selection */
4846 main_window = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (),
4847 FALSE); /* don't create */
4849 GObject *win = NULL;
4850 GtkWidget *folder_view = NULL;
4852 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (main_window),
4853 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
4854 modest_folder_view_disable_next_folder_selection (MODEST_FOLDER_VIEW(folder_view));
4856 if (user_data && TNY_IS_FOLDER (user_data)) {
4857 modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view),
4858 TNY_FOLDER (user_data), FALSE);
4861 /* Show notification dialog only if the main window exists */
4862 win = modest_mail_operation_get_source (mail_op);
4863 modest_platform_run_information_dialog ((GtkWindow *) win,
4864 _("mail_in_ui_folder_move_target_error"),
4867 g_object_unref (win);
4872 open_msg_for_purge_cb (ModestMailOperation *mail_op,
4881 gint pending_purges = 0;
4882 gboolean some_purged = FALSE;
4883 ModestWindow *win = MODEST_WINDOW (user_data);
4884 ModestWindowMgr *mgr = modest_runtime_get_window_mgr ();
4886 /* If there was any error */
4887 if (!modest_ui_actions_msg_retrieval_check (mail_op, header, msg)) {
4888 modest_window_mgr_unregister_header (mgr, header);
4892 /* Once the message has been retrieved for purging, we check if
4893 * it's all ok for purging */
4895 parts = tny_simple_list_new ();
4896 tny_mime_part_get_parts (TNY_MIME_PART (msg), parts);
4897 iter = tny_list_create_iterator (parts);
4899 while (!tny_iterator_is_done (iter)) {
4901 part = TNY_MIME_PART (tny_iterator_get_current (iter));
4902 if (part && (tny_mime_part_is_attachment (part) || TNY_IS_MSG (part))) {
4903 if (tny_mime_part_is_purged (part))
4910 g_object_unref (part);
4912 tny_iterator_next (iter);
4914 g_object_unref (iter);
4917 if (pending_purges>0) {
4919 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),_("mcen_nc_purge_file_text_inbox"));
4921 if (response == GTK_RESPONSE_OK) {
4924 modest_platform_animation_banner (GTK_WIDGET (win), NULL, _("mcen_ib_removing_attachment"));
4925 iter = tny_list_create_iterator (parts);
4926 while (!tny_iterator_is_done (iter)) {
4929 part = TNY_MIME_PART (tny_iterator_get_current (iter));
4930 if (part && (tny_mime_part_is_attachment (part) || TNY_IS_MSG (part)))
4931 tny_mime_part_set_purged (part);
4934 g_object_unref (part);
4936 tny_iterator_next (iter);
4938 g_object_unref (iter);
4940 tny_msg_rewrite_cache (msg);
4942 gtk_widget_destroy (info);
4946 modest_window_mgr_unregister_header (mgr, header);
4948 g_object_unref (parts);
4952 modest_ui_actions_on_main_window_remove_attachments (GtkAction *action,
4953 ModestMainWindow *win)
4955 GtkWidget *header_view;
4956 TnyList *header_list;
4958 TnyHeaderFlags flags;
4959 ModestWindow *msg_view_window = NULL;
4962 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win));
4964 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
4965 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
4967 header_list = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW (header_view));
4969 g_warning ("%s: no header selected", __FUNCTION__);
4973 if (tny_list_get_length (header_list) == 1) {
4974 TnyIterator *iter = tny_list_create_iterator (header_list);
4975 header = TNY_HEADER (tny_iterator_get_current (iter));
4976 g_object_unref (iter);
4980 if (!header || !TNY_IS_HEADER(header)) {
4981 g_warning ("%s: header is not valid", __FUNCTION__);
4985 found = modest_window_mgr_find_registered_header (modest_runtime_get_window_mgr (),
4986 header, &msg_view_window);
4987 flags = tny_header_get_flags (header);
4988 if (!(flags & TNY_HEADER_FLAG_CACHED))
4991 if (msg_view_window != NULL)
4992 modest_msg_view_window_remove_attachments (MODEST_MSG_VIEW_WINDOW (msg_view_window), TRUE);
4994 /* do nothing; uid was registered before, so window is probably on it's way */
4995 g_warning ("debug: header %p has already been registered", header);
4998 ModestMailOperation *mail_op = NULL;
4999 modest_window_mgr_register_header (modest_runtime_get_window_mgr (), header, NULL);
5000 mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT (win),
5001 modest_ui_actions_disk_operations_error_handler,
5003 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
5004 modest_mail_operation_get_msg (mail_op, header, FALSE, open_msg_for_purge_cb, win);
5006 g_object_unref (mail_op);
5009 g_object_unref (header);
5011 g_object_unref (header_list);
5015 * Checks if we need a connection to do the transfer and if the user
5016 * wants to connect to complete it
5019 modest_ui_actions_xfer_messages_check (GtkWindow *parent_window,
5020 TnyFolderStore *src_folder,
5022 TnyFolder *dst_folder,
5023 gboolean delete_originals,
5024 gboolean *need_connection,
5027 TnyAccount *src_account;
5028 gint uncached_msgs = 0;
5030 uncached_msgs = header_list_count_uncached_msgs (headers);
5032 /* We don't need any further check if
5034 * 1- the source folder is local OR
5035 * 2- the device is already online
5037 if (!modest_tny_folder_store_is_remote (src_folder) ||
5038 tny_device_is_online (modest_runtime_get_device())) {
5039 *need_connection = FALSE;
5044 /* We must ask for a connection when
5046 * - the message(s) is not already cached OR
5047 * - the message(s) is cached but the leave_on_server setting
5048 * is FALSE (because we need to sync the source folder to
5049 * delete the message from the server (for IMAP we could do it
5050 * offline, it'll take place the next time we get a
5053 src_account = get_account_from_folder_store (src_folder);
5054 if (uncached_msgs > 0) {
5058 *need_connection = TRUE;
5059 num_headers = tny_list_get_length (headers);
5060 msg = ngettext ("mcen_nc_get_msg", "mcen_nc_get_msgs", num_headers);
5062 if (modest_platform_run_confirmation_dialog (parent_window, msg) ==
5063 GTK_RESPONSE_CANCEL) {
5069 /* The transfer is possible and the user wants to */
5072 if (remote_folder_is_pop (src_folder) && delete_originals) {
5073 const gchar *account_name;
5074 gboolean leave_on_server;
5076 account_name = modest_tny_account_get_parent_modest_account_name_for_server_account (src_account);
5077 leave_on_server = modest_account_mgr_get_leave_on_server (modest_runtime_get_account_mgr (),
5080 if (leave_on_server == TRUE) {
5081 *need_connection = FALSE;
5083 *need_connection = TRUE;
5086 *need_connection = FALSE;
5091 g_object_unref (src_account);
5095 xfer_messages_error_handler (ModestMailOperation *mail_op,
5098 ModestWindow *main_window = NULL;
5100 /* Disable next automatic folder selection */
5101 main_window = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (),
5102 FALSE); /* don't create */
5104 GObject *win = modest_mail_operation_get_source (mail_op);
5105 modest_platform_run_information_dialog ((GtkWindow *) win,
5106 _("mail_in_ui_folder_move_target_error"),
5109 g_object_unref (win);
5111 move_to_helper_destroyer (user_data);
5115 TnyFolderStore *dst_folder;
5120 * Utility function that transfer messages from both the main window
5121 * and the msg view window when using the "Move to" dialog
5124 xfer_messages_performer (gboolean canceled,
5126 GtkWindow *parent_window,
5127 TnyAccount *account,
5130 ModestWindow *win = MODEST_WINDOW (parent_window);
5131 TnyAccount *dst_account = NULL;
5132 const gchar *proto_str = NULL;
5133 gboolean dst_is_pop = FALSE;
5134 XferMsgsHelper *helper;
5135 MoveToHelper *movehelper;
5136 ModestMailOperation *mail_op;
5138 helper = (XferMsgsHelper *) user_data;
5140 if (canceled || err) {
5141 if (!check_memory_full_error ((GtkWidget *) parent_window, err)) {
5142 /* Show the proper error message */
5143 modest_ui_actions_on_account_connection_error (parent_window, account);
5148 dst_account = tny_folder_get_account (TNY_FOLDER (helper->dst_folder));
5149 proto_str = tny_account_get_proto (dst_account);
5151 /* tinymail will return NULL for local folders it seems */
5152 dst_is_pop = proto_str &&
5153 (modest_protocol_info_get_transport_store_protocol (proto_str) ==
5154 MODEST_PROTOCOL_STORE_POP);
5156 g_object_unref (dst_account);
5159 modest_platform_information_banner (GTK_WIDGET (win),
5161 ngettext("mail_in_ui_folder_move_target_error",
5162 "mail_in_ui_folder_move_targets_error",
5163 tny_list_get_length (helper->headers)));
5167 movehelper = g_new0 (MoveToHelper, 1);
5168 movehelper->banner = modest_platform_animation_banner (GTK_WIDGET (win), NULL,
5169 _CS("ckct_nw_pasting"));
5170 if (movehelper->banner != NULL) {
5171 g_object_ref (movehelper->banner);
5172 gtk_widget_show (GTK_WIDGET (movehelper->banner));
5175 if (MODEST_IS_MAIN_WINDOW (win)) {
5176 GtkWidget *header_view =
5177 modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
5178 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
5179 movehelper->reference = get_next_after_selected_headers (MODEST_HEADER_VIEW (header_view));
5182 /* Perform the mail operation */
5183 mail_op = modest_mail_operation_new_with_error_handling (G_OBJECT(win),
5184 xfer_messages_error_handler,
5186 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
5189 modest_mail_operation_xfer_msgs (mail_op,
5191 TNY_FOLDER (helper->dst_folder),
5196 g_object_unref (G_OBJECT (mail_op));
5198 g_object_unref (helper->dst_folder);
5199 g_object_unref (helper->headers);
5200 g_slice_free (XferMsgsHelper, helper);
5204 TnyFolder *src_folder;
5205 TnyFolderStore *dst_folder;
5206 gboolean delete_original;
5207 GtkWidget *folder_view;
5211 on_move_folder_cb (gboolean canceled, GError *err, GtkWindow *parent_window,
5212 TnyAccount *account, gpointer user_data)
5214 MoveFolderInfo *info = (MoveFolderInfo*)user_data;
5215 GtkTreeSelection *sel;
5216 ModestMailOperation *mail_op = NULL;
5218 if (canceled || err || !MODEST_IS_MAIN_WINDOW (parent_window)) {
5219 g_object_unref (G_OBJECT (info->src_folder));
5220 g_object_unref (G_OBJECT (info->dst_folder));
5225 MoveToHelper *helper = g_new0 (MoveToHelper, 1);
5226 helper->banner = modest_platform_animation_banner (GTK_WIDGET (parent_window), NULL,
5227 _CS("ckct_nw_pasting"));
5228 if (helper->banner != NULL) {
5229 g_object_ref (helper->banner);
5230 gtk_widget_show (GTK_WIDGET(helper->banner));
5232 /* Clean folder on header view before moving it */
5233 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (info->folder_view));
5234 gtk_tree_selection_unselect_all (sel);
5236 /* Let gtk events run. We need that the folder
5237 view frees its reference to the source
5238 folder *before* issuing the mail operation
5239 so we need the signal handler of selection
5240 changed to happen before the mail
5242 while (gtk_events_pending ())
5243 gtk_main_iteration (); */
5246 modest_mail_operation_new_with_error_handling (G_OBJECT(parent_window),
5247 modest_ui_actions_move_folder_error_handler,
5248 info->src_folder, NULL);
5249 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (),
5252 /* Select *after* the changes */
5253 /* TODO: this function hangs UI after transfer */
5254 /* modest_folder_view_select_folder (MODEST_FOLDER_VIEW(folder_view), */
5255 /* TNY_FOLDER (src_folder), TRUE); */
5257 modest_folder_view_select_folder (MODEST_FOLDER_VIEW(info->folder_view),
5258 TNY_FOLDER (info->dst_folder), TRUE);
5259 modest_mail_operation_xfer_folder (mail_op,
5260 TNY_FOLDER (info->src_folder),
5262 info->delete_original,
5265 g_object_unref (G_OBJECT (info->src_folder));
5267 /* if (modest_mail_operation_get_status (mail_op) == MODEST_MAIL_OPERATION_STATUS_SUCCESS) { */
5270 /* Unref mail operation */
5271 g_object_unref (G_OBJECT (mail_op));
5272 g_object_unref (G_OBJECT (info->dst_folder));
5277 get_account_from_folder_store (TnyFolderStore *folder_store)
5279 if (TNY_IS_ACCOUNT (folder_store))
5280 return g_object_ref (folder_store);
5282 return tny_folder_get_account (TNY_FOLDER (folder_store));
5286 * UI handler for the "Move to" action when invoked from the
5290 modest_ui_actions_on_main_window_move_to (GtkAction *action,
5291 GtkWidget *folder_view,
5292 TnyFolderStore *dst_folder,
5293 ModestMainWindow *win)
5295 ModestHeaderView *header_view = NULL;
5296 TnyFolderStore *src_folder = NULL;
5298 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win));
5300 /* Get the source folder */
5301 src_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
5303 /* Get header view */
5304 header_view = MODEST_HEADER_VIEW(modest_main_window_get_child_widget (win, MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW));
5306 /* Get folder or messages to transfer */
5307 if (gtk_widget_is_focus (folder_view)) {
5308 gboolean do_xfer = TRUE;
5310 /* Allow only to transfer folders to the local root folder */
5311 if (TNY_IS_ACCOUNT (dst_folder) &&
5312 !MODEST_IS_TNY_LOCAL_FOLDERS_ACCOUNT (dst_folder) &&
5313 !modest_tny_account_is_memory_card_account (TNY_ACCOUNT (dst_folder))) {
5315 } else if (!TNY_IS_FOLDER (src_folder)) {
5316 g_warning ("%s: src_folder is not a TnyFolder.\n", __FUNCTION__);
5321 MoveFolderInfo *info = g_new0 (MoveFolderInfo, 1);
5322 DoubleConnectionInfo *connect_info = g_slice_new (DoubleConnectionInfo);
5324 info->src_folder = g_object_ref (src_folder);
5325 info->dst_folder = g_object_ref (dst_folder);
5326 info->delete_original = TRUE;
5327 info->folder_view = folder_view;
5329 connect_info->callback = on_move_folder_cb;
5330 connect_info->dst_account = get_account_from_folder_store (TNY_FOLDER_STORE (dst_folder));
5331 connect_info->data = info;
5333 modest_platform_double_connect_and_perform(GTK_WINDOW (win), TRUE,
5334 TNY_FOLDER_STORE (src_folder),
5337 } else if (gtk_widget_is_focus (GTK_WIDGET(header_view))) {
5340 headers = modest_header_view_get_selected_headers(header_view);
5342 /* Transfer the messages */
5343 modest_ui_actions_transfer_messages_helper (GTK_WINDOW (win), TNY_FOLDER (src_folder),
5344 headers, TNY_FOLDER (dst_folder));
5346 g_object_unref (headers);
5350 g_object_unref (src_folder);
5355 modest_ui_actions_transfer_messages_helper (GtkWindow *win,
5356 TnyFolder *src_folder,
5358 TnyFolder *dst_folder)
5360 gboolean need_connection = TRUE;
5361 gboolean do_xfer = TRUE;
5362 XferMsgsHelper *helper;
5364 modest_ui_actions_xfer_messages_check (win, TNY_FOLDER_STORE (src_folder),
5365 headers, TNY_FOLDER (dst_folder),
5366 TRUE, &need_connection,
5369 /* If we don't want to transfer just return */
5373 /* Create the helper */
5374 helper = g_slice_new (XferMsgsHelper);
5375 helper->dst_folder = g_object_ref (dst_folder);
5376 helper->headers = g_object_ref (headers);
5378 if (need_connection) {
5379 DoubleConnectionInfo *connect_info = g_slice_new (DoubleConnectionInfo);
5380 connect_info->callback = xfer_messages_performer;
5381 connect_info->dst_account = tny_folder_get_account (TNY_FOLDER (dst_folder));
5382 connect_info->data = helper;
5384 modest_platform_double_connect_and_perform(GTK_WINDOW (win), TRUE,
5385 TNY_FOLDER_STORE (src_folder),
5388 TnyAccount *src_account = get_account_from_folder_store (TNY_FOLDER_STORE (src_folder));
5389 xfer_messages_performer (FALSE, NULL, GTK_WINDOW (win),
5390 src_account, helper);
5391 g_object_unref (src_account);
5396 * UI handler for the "Move to" action when invoked from the
5397 * ModestMsgViewWindow
5400 modest_ui_actions_on_msg_view_window_move_to (GtkAction *action,
5401 TnyFolderStore *dst_folder,
5402 ModestMsgViewWindow *win)
5404 TnyList *headers = NULL;
5405 TnyHeader *header = NULL;
5406 TnyFolder *src_folder = NULL;
5408 g_return_if_fail (TNY_IS_FOLDER (dst_folder));
5410 /* Create header list */
5411 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
5412 src_folder = TNY_FOLDER (tny_header_get_folder(header));
5413 headers = tny_simple_list_new ();
5414 tny_list_append (headers, G_OBJECT (header));
5416 /* Transfer the messages */
5417 modest_ui_actions_transfer_messages_helper (GTK_WINDOW (win), src_folder, headers,
5418 TNY_FOLDER (dst_folder));
5421 g_object_unref (header);
5422 g_object_unref (headers);
5426 modest_ui_actions_on_move_to (GtkAction *action,
5429 GtkWidget *dialog = NULL, *folder_view = NULL, *tree_view = NULL;
5431 TnyFolderStore *dst_folder = NULL;
5432 ModestMainWindow *main_window;
5434 g_return_if_fail (MODEST_IS_MAIN_WINDOW (win) ||
5435 MODEST_IS_MSG_VIEW_WINDOW (win));
5437 /* Get the main window if exists */
5438 if (MODEST_IS_MAIN_WINDOW (win))
5439 main_window = MODEST_MAIN_WINDOW (win);
5442 MODEST_MAIN_WINDOW (modest_window_mgr_get_main_window (modest_runtime_get_window_mgr (),
5443 FALSE)); /* don't create */
5445 /* Get the folder view widget if exists */
5447 folder_view = modest_main_window_get_child_widget (main_window,
5448 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
5452 /* Create and run the dialog */
5453 dialog = create_move_to_dialog (GTK_WINDOW (win), folder_view, &tree_view);
5454 modest_folder_view_select_first_inbox_or_local (MODEST_FOLDER_VIEW (tree_view));
5455 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
5456 result = gtk_dialog_run (GTK_DIALOG(dialog));
5457 g_object_ref (tree_view);
5458 gtk_widget_destroy (dialog);
5460 if (result != GTK_RESPONSE_ACCEPT)
5463 dst_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (tree_view));
5464 /* Do window specific stuff */
5465 if (MODEST_IS_MAIN_WINDOW (win)) {
5466 modest_ui_actions_on_main_window_move_to (action,
5469 MODEST_MAIN_WINDOW (win));
5471 modest_ui_actions_on_msg_view_window_move_to (action,
5473 MODEST_MSG_VIEW_WINDOW (win));
5477 g_object_unref (dst_folder);
5481 * Calls #HeadersFunc for each header already selected in the main
5482 * window or the message currently being shown in the msg view window
5485 do_headers_action (ModestWindow *win,
5489 TnyList *headers_list = NULL;
5490 TnyIterator *iter = NULL;
5491 TnyHeader *header = NULL;
5492 TnyFolder *folder = NULL;
5495 headers_list = get_selected_headers (win);
5499 /* Get the folder */
5500 iter = tny_list_create_iterator (headers_list);
5501 header = TNY_HEADER (tny_iterator_get_current (iter));
5503 folder = tny_header_get_folder (header);
5504 g_object_unref (header);
5507 /* Call the function for each header */
5508 while (!tny_iterator_is_done (iter)) {
5509 header = TNY_HEADER (tny_iterator_get_current (iter));
5510 func (header, win, user_data);
5511 g_object_unref (header);
5512 tny_iterator_next (iter);
5515 /* Trick: do a poke status in order to speed up the signaling
5517 tny_folder_poke_status (folder);
5520 g_object_unref (folder);
5521 g_object_unref (iter);
5522 g_object_unref (headers_list);
5526 modest_ui_actions_view_attachment (GtkAction *action,
5527 ModestWindow *window)
5529 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
5530 modest_msg_view_window_view_attachment (MODEST_MSG_VIEW_WINDOW (window), NULL);
5532 /* not supported window for this action */
5533 g_return_if_reached ();
5538 modest_ui_actions_save_attachments (GtkAction *action,
5539 ModestWindow *window)
5541 if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
5543 if (modest_platform_check_memory_low (MODEST_WINDOW(window), TRUE))
5546 modest_msg_view_window_save_attachments (MODEST_MSG_VIEW_WINDOW (window), NULL);
5548 /* not supported window for this action */
5549 g_return_if_reached ();
5554 modest_ui_actions_remove_attachments (GtkAction *action,
5555 ModestWindow *window)
5557 if (MODEST_IS_MAIN_WINDOW (window)) {
5558 modest_ui_actions_on_main_window_remove_attachments (action, MODEST_MAIN_WINDOW (window));
5559 } else if (MODEST_IS_MSG_VIEW_WINDOW (window)) {
5560 modest_msg_view_window_remove_attachments (MODEST_MSG_VIEW_WINDOW (window), FALSE);
5562 /* not supported window for this action */
5563 g_return_if_reached ();
5568 modest_ui_actions_on_settings (GtkAction *action,
5573 dialog = modest_platform_get_global_settings_dialog ();
5574 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (win));
5575 gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
5576 gtk_widget_show_all (dialog);
5578 gtk_dialog_run (GTK_DIALOG (dialog));
5580 gtk_widget_destroy (dialog);
5584 modest_ui_actions_on_help (GtkAction *action,
5587 const gchar *help_id;
5589 g_return_if_fail (win && GTK_IS_WINDOW(win));
5591 help_id = modest_window_mgr_get_help_id (modest_runtime_get_window_mgr(), win);
5594 modest_platform_show_help (GTK_WINDOW (win), help_id);
5598 modest_ui_actions_on_csm_help (GtkAction *action,
5601 const gchar* help_id = NULL;
5602 GtkWidget *folder_view;
5603 TnyFolderStore *folder_store;
5605 g_return_if_fail (win && MODEST_IS_MAIN_WINDOW (win));
5607 /* Get selected folder */
5608 folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
5609 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
5610 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
5612 /* Switch help_id */
5613 if (folder_store && TNY_IS_FOLDER (folder_store))
5614 help_id = modest_tny_folder_get_help_id (TNY_FOLDER (folder_store));
5617 g_object_unref (folder_store);
5620 modest_platform_show_help (GTK_WINDOW (win), help_id);
5622 modest_ui_actions_on_help (action, win);
5626 retrieve_contents_cb (ModestMailOperation *mail_op,
5633 /* We only need this callback to show an error in case of
5634 memory low condition */
5635 modest_ui_actions_msg_retrieval_check (mail_op, header, msg);
5639 retrieve_msg_contents_performer (gboolean canceled,
5641 GtkWindow *parent_window,
5642 TnyAccount *account,
5645 ModestMailOperation *mail_op;
5646 TnyList *headers = TNY_LIST (user_data);
5648 if (err || canceled) {
5649 check_memory_full_error ((GtkWidget *) parent_window, err);
5653 /* Create mail operation */
5654 mail_op = modest_mail_operation_new_with_error_handling ((GObject *) parent_window,
5655 modest_ui_actions_disk_operations_error_handler,
5657 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_op);
5658 modest_mail_operation_get_msgs_full (mail_op, headers, retrieve_contents_cb, NULL, NULL);
5661 g_object_unref (mail_op);
5663 g_object_unref (headers);
5664 g_object_unref (account);
5668 modest_ui_actions_on_retrieve_msg_contents (GtkAction *action,
5669 ModestWindow *window)
5671 TnyList *headers = NULL;
5672 TnyAccount *account = NULL;
5673 TnyIterator *iter = NULL;
5674 TnyHeader *header = NULL;
5675 TnyFolder *folder = NULL;
5678 headers = get_selected_headers (window);
5682 /* Pick the account */
5683 iter = tny_list_create_iterator (headers);
5684 header = TNY_HEADER (tny_iterator_get_current (iter));
5685 folder = tny_header_get_folder (header);
5686 account = tny_folder_get_account (folder);
5687 g_object_unref (folder);
5688 g_object_unref (header);
5689 g_object_unref (iter);
5691 /* Connect and perform the message retrieval */
5692 modest_platform_connect_and_perform ((GtkWindow *) window, TRUE,
5693 g_object_ref (account),
5694 retrieve_msg_contents_performer,
5695 g_object_ref (headers));
5698 g_object_unref (account);
5699 g_object_unref (headers);
5703 modest_ui_actions_check_toolbar_dimming_rules (ModestWindow *window)
5705 g_return_if_fail (MODEST_IS_WINDOW (window));
5708 modest_window_check_dimming_rules_group (window, MODEST_DIMMING_RULES_TOOLBAR);
5712 modest_ui_actions_check_menu_dimming_rules (ModestWindow *window)
5714 g_return_if_fail (MODEST_IS_WINDOW (window));
5717 modest_window_check_dimming_rules_group (window, MODEST_DIMMING_RULES_MENU);
5721 modest_ui_actions_on_email_menu_activated (GtkAction *action,
5722 ModestWindow *window)
5724 g_return_if_fail (MODEST_IS_WINDOW (window));
5727 modest_ui_actions_check_menu_dimming_rules (window);
5731 modest_ui_actions_on_edit_menu_activated (GtkAction *action,
5732 ModestWindow *window)
5734 g_return_if_fail (MODEST_IS_WINDOW (window));
5737 modest_ui_actions_check_menu_dimming_rules (window);
5741 modest_ui_actions_on_view_menu_activated (GtkAction *action,
5742 ModestWindow *window)
5744 g_return_if_fail (MODEST_IS_WINDOW (window));
5747 modest_ui_actions_check_menu_dimming_rules (window);
5751 modest_ui_actions_on_format_menu_activated (GtkAction *action,
5752 ModestWindow *window)
5754 g_return_if_fail (MODEST_IS_WINDOW (window));
5757 modest_ui_actions_check_menu_dimming_rules (window);
5761 modest_ui_actions_on_tools_menu_activated (GtkAction *action,
5762 ModestWindow *window)
5764 g_return_if_fail (MODEST_IS_WINDOW (window));
5767 modest_ui_actions_check_menu_dimming_rules (window);
5771 modest_ui_actions_on_attachment_menu_activated (GtkAction *action,
5772 ModestWindow *window)
5774 g_return_if_fail (MODEST_IS_WINDOW (window));
5777 modest_ui_actions_check_menu_dimming_rules (window);
5781 modest_ui_actions_on_toolbar_csm_menu_activated (GtkAction *action,
5782 ModestWindow *window)
5784 g_return_if_fail (MODEST_IS_WINDOW (window));
5787 modest_ui_actions_check_menu_dimming_rules (window);
5791 modest_ui_actions_on_folder_view_csm_menu_activated (GtkAction *action,
5792 ModestWindow *window)
5794 g_return_if_fail (MODEST_IS_WINDOW (window));
5797 modest_ui_actions_check_menu_dimming_rules (window);
5801 modest_ui_actions_on_header_view_csm_menu_activated (GtkAction *action,
5802 ModestWindow *window)
5804 g_return_if_fail (MODEST_IS_WINDOW (window));
5807 modest_ui_actions_check_menu_dimming_rules (window);
5811 modest_ui_actions_on_search_messages (GtkAction *action, ModestWindow *window)
5813 g_return_if_fail (MODEST_IS_WINDOW (window));
5815 /* we check for low-mem; in that case, show a warning, and don't allow
5818 if (modest_platform_check_memory_low (window, TRUE))
5821 modest_platform_show_search_messages (GTK_WINDOW (window));
5825 modest_ui_actions_on_open_addressbook (GtkAction *action, ModestWindow *win)
5827 g_return_if_fail (MODEST_IS_WINDOW (win));
5830 /* we check for low-mem; in that case, show a warning, and don't allow
5831 * for the addressbook
5833 if (modest_platform_check_memory_low (win, TRUE))
5837 modest_platform_show_addressbook (GTK_WINDOW (win));
5842 modest_ui_actions_on_toggle_find_in_page (GtkToggleAction *action,
5843 ModestWindow *window)
5845 g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW (window));
5847 modest_msg_edit_window_toggle_find_toolbar (MODEST_MSG_EDIT_WINDOW (window), gtk_toggle_action_get_active (action));
5851 on_send_receive_finished (ModestMailOperation *mail_op,
5854 GtkWidget *header_view, *folder_view;
5855 TnyFolderStore *folder_store;
5856 ModestMainWindow *main_win = MODEST_MAIN_WINDOW (user_data);
5858 /* Set send/receive operation finished */
5859 modest_main_window_notify_send_receive_completed (main_win);
5861 /* Don't refresh the current folder if there were any errors */
5862 if (modest_mail_operation_get_status (mail_op) !=
5863 MODEST_MAIL_OPERATION_STATUS_SUCCESS)
5866 /* Refresh the current folder if we're viewing a window. We do
5867 this because the user won't be able to see the new mails in
5868 the selected folder after a Send&Receive because it only
5869 performs a poke_status, i.e, only the number of read/unread
5870 messages is updated, but the new headers are not
5872 folder_view = modest_main_window_get_child_widget (main_win,
5873 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
5877 folder_store = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
5879 /* Do not need to refresh INBOX again because the
5880 update_account does it always automatically */
5881 if (folder_store && TNY_IS_FOLDER (folder_store) &&
5882 tny_folder_get_folder_type (TNY_FOLDER (folder_store)) != TNY_FOLDER_TYPE_INBOX) {
5883 ModestMailOperation *refresh_op;
5885 header_view = modest_main_window_get_child_widget (main_win,
5886 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
5888 /* We do not need to set the contents style
5889 because it hasn't changed. We also do not
5890 need to save the widget status. Just force
5892 refresh_op = modest_mail_operation_new (G_OBJECT (main_win));
5893 modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), refresh_op);
5894 modest_mail_operation_refresh_folder (refresh_op, TNY_FOLDER (folder_store),
5895 folder_refreshed_cb, main_win);
5896 g_object_unref (refresh_op);
5900 g_object_unref (folder_store);
5905 modest_ui_actions_on_send_queue_error_happened (TnySendQueue *self,
5911 const gchar* server_name = NULL;
5912 TnyTransportAccount *server_account;
5913 gchar *message = NULL;
5915 /* Don't show anything if the user cancelled something or the
5916 * send receive request is not interactive. Authentication
5917 * errors are managed by the account store so no need to show
5918 * a dialog here again */
5919 if (err->code == TNY_SYSTEM_ERROR_CANCEL ||
5920 err->code == TNY_SERVICE_ERROR_AUTHENTICATE ||
5921 !modest_tny_send_queue_get_requested_send_receive (MODEST_TNY_SEND_QUEUE (self)))
5925 /* Get the server name: */
5927 TNY_TRANSPORT_ACCOUNT (tny_camel_send_queue_get_transport_account (TNY_CAMEL_SEND_QUEUE (self)));
5929 server_name = tny_account_get_hostname (TNY_ACCOUNT (server_account));
5931 g_return_if_reached ();
5933 /* Show the appropriate message text for the GError: */
5934 switch (err->code) {
5935 case TNY_SERVICE_ERROR_CONNECT:
5936 message = g_strdup_printf (_("emev_ib_ui_smtp_server_invalid"), server_name);
5938 case TNY_SERVICE_ERROR_SEND:
5939 message = g_strdup (dgettext("hildon-common-strings", "sfil_ib_unable_to_send"));
5941 case TNY_SERVICE_ERROR_UNAVAILABLE:
5942 message = g_strdup_printf (_("emev_ib_ui_smtp_server_invalid"), server_name);
5945 g_warning ("%s: unexpected ERROR %d",
5946 __FUNCTION__, err->code);
5947 message = g_strdup (dgettext("hildon-common-strings", "sfil_ib_unable_to_send"));
5951 modest_platform_run_information_dialog (NULL, message, FALSE);
5953 g_object_unref (server_account);
5957 modest_ui_actions_on_send_queue_status_changed (ModestTnySendQueue *send_queue,
5962 ModestMainWindow *main_window = NULL;
5963 ModestWindowMgr *mgr = NULL;
5964 GtkWidget *folder_view = NULL, *header_view = NULL;
5965 TnyFolderStore *selected_folder = NULL;
5966 TnyFolderType folder_type;
5968 mgr = modest_runtime_get_window_mgr ();
5969 main_window = MODEST_MAIN_WINDOW (modest_window_mgr_get_main_window (mgr,
5970 FALSE));/* don't create */
5974 /* Check if selected folder is OUTBOX */
5975 folder_view = modest_main_window_get_child_widget (main_window,
5976 MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
5977 header_view = modest_main_window_get_child_widget (main_window,
5978 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
5980 selected_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
5981 if (!TNY_IS_FOLDER (selected_folder))
5984 /* gtk_tree_view_column_queue_resize is only available in GTK+ 2.8 */
5985 #if GTK_CHECK_VERSION(2, 8, 0)
5986 folder_type = modest_tny_folder_guess_folder_type (TNY_FOLDER (selected_folder));
5987 if (folder_type == TNY_FOLDER_TYPE_OUTBOX) {
5988 GtkTreeViewColumn *tree_column;
5990 tree_column = gtk_tree_view_get_column (GTK_TREE_VIEW (header_view),
5991 TNY_GTK_HEADER_LIST_MODEL_FROM_COLUMN);
5992 gtk_tree_view_column_queue_resize (tree_column);
5995 gtk_widget_queue_draw (header_view);
5998 /* Rerun dimming rules, because the message could become deletable for example */
5999 modest_window_check_dimming_rules_group (MODEST_WINDOW (main_window),
6000 MODEST_DIMMING_RULES_TOOLBAR);
6004 if (selected_folder != NULL)
6005 g_object_unref (selected_folder);
6009 modest_ui_actions_on_account_connection_error (GtkWindow *parent_window,
6010 TnyAccount *account)
6012 ModestTransportStoreProtocol proto;
6013 const gchar *proto_name;
6014 gchar *error_note = NULL;
6016 proto_name = tny_account_get_proto (account);
6017 proto = modest_protocol_info_get_transport_store_protocol (proto_name);
6020 case MODEST_PROTOCOL_STORE_POP:
6021 error_note = g_strdup_printf (_("emev_ni_ui_pop3_msg_connect_error"),
6022 tny_account_get_hostname (account));
6024 case MODEST_PROTOCOL_STORE_IMAP:
6025 error_note = g_strdup_printf (_("emev_ni_ui_imap_connect_server_error"),
6026 tny_account_get_hostname (account));
6028 case MODEST_PROTOCOL_STORE_MAILDIR:
6029 case MODEST_PROTOCOL_STORE_MBOX:
6030 error_note = g_strdup (_("emev_nc_mailbox_notavailable"));
6033 g_warning ("%s: This should not be reached", __FUNCTION__);
6037 modest_platform_run_information_dialog (parent_window, error_note, FALSE);
6038 g_free (error_note);
6043 modest_ui_actions_get_msg_already_deleted_error_msg (ModestWindow *win)
6046 TnyFolderStore *folder = NULL;
6047 TnyAccount *account = NULL;
6048 ModestTransportStoreProtocol proto;
6049 TnyHeader *header = NULL;
6051 if (MODEST_IS_MAIN_WINDOW (win)) {
6052 GtkWidget *header_view;
6053 TnyList* headers = NULL;
6055 header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
6056 MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
6057 headers = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW (header_view));
6058 if (!headers || tny_list_get_length (headers) == 0) {
6060 g_object_unref (headers);
6063 iter = tny_list_create_iterator (headers);
6064 header = TNY_HEADER (tny_iterator_get_current (iter));
6065 folder = TNY_FOLDER_STORE (tny_header_get_folder (header));
6066 g_object_unref (iter);
6067 g_object_unref (headers);
6068 } else if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
6069 header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
6070 folder = TNY_FOLDER_STORE (tny_header_get_folder (header));
6073 /* Get the account type */
6074 account = tny_folder_get_account (TNY_FOLDER (folder));
6075 proto = modest_protocol_info_get_transport_store_protocol (tny_account_get_proto (account));
6076 if (proto == MODEST_PROTOCOL_STORE_POP) {
6077 msg = g_strdup (_("emev_ni_ui_pop3_msg_recv_error"));
6078 } else if (proto == MODEST_PROTOCOL_STORE_IMAP) {
6080 subject = tny_header_dup_subject (header);
6081 msg = g_strdup_printf (_("emev_ni_ui_imap_message_not_available_in_server"),
6085 msg = g_strdup_printf (_("mail_ni_ui_folder_get_msg_folder_error"));
6089 g_object_unref (account);
6090 g_object_unref (folder);
6091 g_object_unref (header);