From: Alberto Garcia Date: Wed, 29 Aug 2007 14:12:33 +0000 (+0000) Subject: * src/modest-platform.h X-Git-Tag: git_migration_finished~2483 X-Git-Url: http://git.maemo.org/git/?p=modest;a=commitdiff_plain;h=706edd7e97d7e319c03249acb0fc2d98f89e471d * src/modest-platform.h * src/modest-platform.c (modest_platform_is_network_folderstore): Checks whether a folder store is remote * src/modest-ui-actions.c (modest_ui_actions_on_move_to): Don't try to connect to the internet, leave that for the following functions. (modest_ui_actions_on_main_window_move_to): (modest_ui_actions_on_msg_view_window_move_to): Ask for confirmation if the device is offline and the source folder is remote pmo-trunk-r3130 --- diff --git a/src/maemo/modest-platform.c b/src/maemo/modest-platform.c index 2bdfcee..cb07e6c 100644 --- a/src/maemo/modest-platform.c +++ b/src/maemo/modest-platform.c @@ -1192,6 +1192,38 @@ gboolean modest_platform_connect_and_wait_if_network_folderstore (GtkWindow *par return result; } +gboolean modest_platform_is_network_folderstore (TnyFolderStore *folder_store) +{ + TnyAccount *account = NULL; + gboolean result = TRUE; + + g_return_val_if_fail(TNY_IS_FOLDER_STORE(folder_store), FALSE); + + if (TNY_IS_FOLDER (folder_store)) { + /* Get the folder's parent account: */ + account = tny_folder_get_account(TNY_FOLDER(folder_store)); + } else if (TNY_IS_ACCOUNT (folder_store)) { + account = TNY_ACCOUNT(folder_store); + g_object_ref(account); + } + + if (account != NULL) { + if (tny_account_get_account_type (account) == TNY_ACCOUNT_TYPE_STORE) { + if (!TNY_IS_CAMEL_POP_STORE_ACCOUNT (account) && + !TNY_IS_CAMEL_IMAP_STORE_ACCOUNT (account)) { + /* This must be a maildir account, which does + * not require a connection: */ + result = FALSE; + } + } + g_object_unref (account); + } else { + result = FALSE; + } + + return result; +} + void modest_platform_run_sort_dialog (GtkWindow *parent_window, ModestSortDialogType type) diff --git a/src/modest-platform.h b/src/modest-platform.h index f12069e..c6d8913 100644 --- a/src/modest-platform.h +++ b/src/modest-platform.h @@ -249,6 +249,14 @@ gboolean modest_platform_connect_and_wait_if_network_account (GtkWindow *parent_ gboolean modest_platform_connect_and_wait_if_network_folderstore (GtkWindow *parent_window, TnyFolderStore *folder_store); /** + * modest_platform_is_network_folderstore: + * @folder_store: The folder store (folder or account) that needs to + * decide if need a connection in subsequent operations. + * @return value: Whether a connection is necessary for this folder_store. + */ +gboolean modest_platform_is_network_folderstore (TnyFolderStore *folder_store); + +/** * modest_platform_set_update_interval: * @minutes: The number of minutes between updates, or 0 for no updates. * diff --git a/src/modest-ui-actions.c b/src/modest-ui-actions.c index b564cf0..5218516 100644 --- a/src/modest-ui-actions.c +++ b/src/modest-ui-actions.c @@ -4080,61 +4080,71 @@ modest_ui_actions_on_main_window_move_to (GtkAction *action, TnyFolderStore *dst_folder, ModestMainWindow *win) { - GtkWidget *header_view = NULL; + ModestHeaderView *header_view = NULL; ModestMailOperation *mail_op = NULL; TnyFolderStore *src_folder; + gboolean online = (tny_device_is_online (modest_runtime_get_device())); g_return_if_fail (MODEST_IS_MAIN_WINDOW (win)); /* Get the source folder */ src_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view)); - - /* Offer the connection dialog if necessary, if the source folder is in a networked account: */ - if (!modest_platform_connect_and_wait_if_network_folderstore (GTK_WINDOW (win), - src_folder)) - goto end; /* Get header view */ - header_view = - modest_main_window_get_child_widget (win, MODEST_WIDGET_TYPE_HEADER_VIEW); + header_view = MODEST_HEADER_VIEW(modest_main_window_get_child_widget (win, MODEST_WIDGET_TYPE_HEADER_VIEW)); /* Get folder or messages to transfer */ if (gtk_widget_is_focus (folder_view)) { GtkTreeSelection *sel; + gboolean do_xfer = TRUE; /* Allow only to transfer folders to the local root folder */ if (TNY_IS_ACCOUNT (dst_folder) && - !MODEST_IS_TNY_LOCAL_FOLDERS_ACCOUNT (dst_folder)) - goto end; - - /* Clean folder on header view before moving it */ - sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_view)); - gtk_tree_selection_unselect_all (sel); - - if (TNY_IS_FOLDER (src_folder)) { - mail_op = - modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE, - G_OBJECT(win), - modest_ui_actions_move_folder_error_handler, - NULL); - modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), - mail_op); - - modest_mail_operation_xfer_folder (mail_op, - TNY_FOLDER (src_folder), - dst_folder, - TRUE, NULL, NULL); - /* Unref mail operation */ - g_object_unref (G_OBJECT (mail_op)); - } else { - g_warning ("%s: src_folder is not a TnyFolder.\n", __FUNCTION__); - } - } else if (gtk_widget_is_focus (header_view)) { - /* Transfer messages */ - modest_ui_actions_xfer_messages_from_move_to (dst_folder, MODEST_WINDOW (win)); + !MODEST_IS_TNY_LOCAL_FOLDERS_ACCOUNT (dst_folder)) { + do_xfer = FALSE; + } else if (!TNY_IS_FOLDER (src_folder)) { + g_warning ("%s: src_folder is not a TnyFolder.\n", __FUNCTION__); + do_xfer = FALSE; + } else if (!online && modest_platform_is_network_folderstore(src_folder)) { + guint num_headers = tny_folder_get_all_count(TNY_FOLDER(src_folder)); + if (!connect_to_get_msg(GTK_WINDOW(win), num_headers)) { + do_xfer = FALSE; + } + } + + if (do_xfer) { + /* Clean folder on header view before moving it */ + sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_view)); + gtk_tree_selection_unselect_all (sel); + + mail_op = + modest_mail_operation_new_with_error_handling (MODEST_MAIL_OPERATION_TYPE_RECEIVE, + G_OBJECT(win), + modest_ui_actions_move_folder_error_handler, + NULL); + modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), + mail_op); + + modest_mail_operation_xfer_folder (mail_op, + TNY_FOLDER (src_folder), + dst_folder, + TRUE, NULL, NULL); + /* Unref mail operation */ + g_object_unref (G_OBJECT (mail_op)); + } + } else if (gtk_widget_is_focus (GTK_WIDGET(header_view))) { + gboolean do_xfer = TRUE; + /* Ask for confirmation if the source folder is remote and we're not connected */ + if (!online && modest_platform_is_network_folderstore(src_folder)) { + guint num_headers = modest_header_view_count_selected_headers(header_view); + if (!connect_to_get_msg(GTK_WINDOW(win), num_headers)) { + do_xfer = FALSE; + } + } + if (do_xfer) /* Transfer messages */ + modest_ui_actions_xfer_messages_from_move_to (dst_folder, MODEST_WINDOW (win)); } - - end: + if (src_folder) g_object_unref (src_folder); } @@ -4150,16 +4160,18 @@ modest_ui_actions_on_msg_view_window_move_to (GtkAction *action, ModestMsgViewWindow *win) { TnyHeader *header = NULL; - TnyFolder *src_folder; + TnyFolderStore *src_folder; /* Create header list */ header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win)); - src_folder = tny_header_get_folder(header); + src_folder = TNY_FOLDER_STORE(tny_header_get_folder(header)); g_object_unref (header); - /* Transfer the message */ - if (modest_platform_connect_and_wait_if_network_folderstore (NULL, TNY_FOLDER_STORE (src_folder))) + /* Transfer the message if online or confirmed by the user */ + if (tny_device_is_online (modest_runtime_get_device()) || + (modest_platform_is_network_folderstore(src_folder) && connect_to_get_msg(GTK_WINDOW(win), 1))) { modest_ui_actions_xfer_messages_from_move_to (dst_folder, MODEST_WINDOW (win)); + } g_object_unref (src_folder); } @@ -4202,21 +4214,18 @@ modest_ui_actions_on_move_to (GtkAction *action, return; dst_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW (tree_view)); - /* Offer the connection dialog if necessary: */ - if (modest_platform_connect_and_wait_if_network_folderstore (GTK_WINDOW (win), - dst_folder)) { - - /* Do window specific stuff */ - if (MODEST_IS_MAIN_WINDOW (win)) - modest_ui_actions_on_main_window_move_to (action, - folder_view, - dst_folder, - MODEST_MAIN_WINDOW (win)); - else - modest_ui_actions_on_msg_view_window_move_to (action, - dst_folder, - MODEST_MSG_VIEW_WINDOW (win)); - } + /* Do window specific stuff */ + if (MODEST_IS_MAIN_WINDOW (win)) { + modest_ui_actions_on_main_window_move_to (action, + folder_view, + dst_folder, + MODEST_MAIN_WINDOW (win)); + } else { + modest_ui_actions_on_msg_view_window_move_to (action, + dst_folder, + MODEST_MSG_VIEW_WINDOW (win)); + } + if (dst_folder) g_object_unref (dst_folder); }