From a2e8dc72d76c5f8b3648e0c54d52f362a5dcefc7 Mon Sep 17 00:00:00 2001 From: Armin Burgmeier Date: Thu, 12 Jul 2007 13:20:03 +0000 Subject: [PATCH] 2007-07-12 Armin Burgmeier * src/modest-error.h: Added MODEST_MAIL_OPERATION_FOLDER_EXISTS error. * src/modest-mail-operation.c: * src/modest-ui-actions.c: Check for already existing folder before querying the server, show error message from camel if the request still fails. This fixes projects.maemo.org bug NB#58701. pmo-trunk-r2726 --- ChangeLog2 | 9 +++++++++ src/modest-error.h | 1 + src/modest-mail-operation.c | 17 +++++++++++++++++ src/modest-ui-actions.c | 17 ++++++----------- 4 files changed, 33 insertions(+), 11 deletions(-) diff --git a/ChangeLog2 b/ChangeLog2 index 9d1c67e..1801ce7 100644 --- a/ChangeLog2 +++ b/ChangeLog2 @@ -1,3 +1,12 @@ +2007-07-12 Armin Burgmeier + + * src/modest-error.h: Added MODEST_MAIL_OPERATION_FOLDER_EXISTS error. + + * src/modest-mail-operation.c: + * src/modest-ui-actions.c: Check for already existing folder before + querying the server, show error message from camel if the request + still fails. This fixes projects.maemo.org bug NB#58701. + 2007-07-12 Murray Cumming * src/modest-tny-account-store.h: diff --git a/src/modest-error.h b/src/modest-error.h index 0a883c6..cba6d3f 100644 --- a/src/modest-error.h +++ b/src/modest-error.h @@ -44,6 +44,7 @@ typedef enum _ModestErrorCode { MODEST_MAIL_OPERATION_ERROR_OPERATION_CANCELED, MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND, MODEST_MAIL_OPERATION_ERROR_FOLDER_RULES, + MODEST_MAIL_OPERATION_ERROR_FOLDER_EXISTS, /* Folder to be created exists already. */ MODEST_MAIL_OPERATION_ERROR_MESSAGE_SIZE_LIMIT, /* A message was too big to retrieve. */ MODEST_MAIL_OPERATION_ERROR_RETRIEVAL_NUMBER_LIMIT, /* There were too many messages to retrieve. */ MODEST_MAIL_OPERATION_ERROR_INSTANCE_CREATION_FAILED, diff --git a/src/modest-mail-operation.c b/src/modest-mail-operation.c index 8e94e38..df94621 100644 --- a/src/modest-mail-operation.c +++ b/src/modest-mail-operation.c @@ -1474,11 +1474,28 @@ modest_mail_operation_create_folder (ModestMailOperation *self, ModestMailOperationPrivate *priv; TnyFolder *new_folder = NULL; + TnyList *list = tny_simple_list_new (); + TnyFolderStoreQuery *query = tny_folder_store_query_new (); + g_return_val_if_fail (TNY_IS_FOLDER_STORE (parent), NULL); g_return_val_if_fail (name, NULL); priv = MODEST_MAIL_OPERATION_GET_PRIVATE (self); + /* Check for already existing folder */ + tny_folder_store_query_add_item (query, name, TNY_FOLDER_STORE_QUERY_OPTION_MATCH_ON_NAME); + tny_folder_store_get_folders (parent, list, query, NULL); + g_object_unref (G_OBJECT (query)); + + if (tny_list_get_length (list) > 0) { + priv->status = MODEST_MAIL_OPERATION_STATUS_FAILED; + g_set_error (&(priv->error), MODEST_MAIL_OPERATION_ERROR, + MODEST_MAIL_OPERATION_ERROR_FOLDER_EXISTS, + _CS("ckdg_ib_folder_already_exists")); + } + + g_object_unref (G_OBJECT (list)); + /* Check parent */ if (TNY_IS_FOLDER (parent)) { /* Check folder rules */ diff --git a/src/modest-ui-actions.c b/src/modest-ui-actions.c index ddf9368..61b68e3 100644 --- a/src/modest-ui-actions.c +++ b/src/modest-ui-actions.c @@ -2171,18 +2171,13 @@ modest_ui_actions_new_folder_error_handler (ModestMailOperation *mail_op, gpointer user_data) { ModestMainWindow *window = MODEST_MAIN_WINDOW (user_data); + const GError *error = modest_mail_operation_get_error (mail_op); - /* TODO: Note that folder creation might go wrong due to other - * failures such as when the parent folder is non-writable. We can - * query a GError* with modest_mail_operation_get_error(), but the - * the error code (from tinymail) does not give us a clue about what - * has gone wrong. We might use the error->message but it might come - * from camel and not be suitable to show to the user directly. */ - modest_platform_information_banner (GTK_WIDGET (window), NULL, - _CS("ckdg_ib_folder_already_exists")); - -/* modest_platform_information_banner (GTK_WIDGET (window), NULL, - modest_mail_operation_get_error (mail_op)->message);*/ + if(error) + { + modest_platform_information_banner (GTK_WIDGET (window), NULL, + modest_mail_operation_get_error (mail_op)->message); + } } -- 1.7.9.5