From 152ee6945dc5142b5e63f2a6ac6efc2dbb94df0c Mon Sep 17 00:00:00 2001 From: Sergio Villar Senin Date: Fri, 24 Aug 2007 14:01:18 +0000 Subject: [PATCH] * Renamed a function * Added a new define for hildon-libs domain translation * Fixes NB#65969 pmo-trunk-r3067 --- src/maemo/modest-platform.c | 84 ++++++++++++++++++++++++++++++++----------- src/modest-mail-operation.c | 2 +- src/modest-text-utils.h | 1 + src/modest-tny-folder.c | 46 +++++++++--------------- src/modest-tny-folder.h | 14 ++++---- src/modest-ui-actions.c | 9 +++-- 6 files changed, 94 insertions(+), 62 deletions(-) diff --git a/src/maemo/modest-platform.c b/src/maemo/modest-platform.c index a34f0a2..9338c34 100644 --- a/src/maemo/modest-platform.c +++ b/src/maemo/modest-platform.c @@ -51,6 +51,7 @@ #include #include #include +#include "modest-tny-folder.h" #include @@ -760,8 +761,46 @@ launch_sort_headers_dialog (GtkWindow *parent_window, g_list_free(cols); } + + +static void +on_response (GtkDialog *dialog, + gint response, + gpointer user_data) +{ + GList *child_vbox, *child_hbox; + GtkWidget *hbox, *entry; + TnyFolderStore *parent; + + if (response != GTK_RESPONSE_ACCEPT) + return; + + /* Get entry */ + child_vbox = gtk_container_get_children (GTK_CONTAINER (dialog->vbox)); + hbox = child_vbox->data; + child_hbox = gtk_container_get_children (GTK_CONTAINER (hbox)); + entry = child_hbox->next->data; + + parent = TNY_FOLDER_STORE (user_data); + + /* Look for another folder with the same name */ + if (modest_tny_folder_has_subfolder_with_name (parent, + gtk_entry_get_text (GTK_ENTRY (entry)))) { + /* Show an error */ + hildon_banner_show_information (gtk_widget_get_parent (GTK_WIDGET (dialog)), + NULL, _CS("ckdg_ib_folder_already_exists")); + /* Select the text */ + gtk_entry_select_region (GTK_ENTRY (entry), 0, -1); + gtk_widget_grab_focus (entry); + /* Do not close the dialog */ + g_signal_stop_emission_by_name (dialog, "response"); + } +} + + static gint modest_platform_run_folder_name_dialog (GtkWindow *parent_window, + TnyFolderStore *parent, const gchar *dialog_title, const gchar *label_text, const gchar *suggested_name, @@ -797,6 +836,13 @@ modest_platform_run_folder_name_dialog (GtkWindow *parent_window, gtk_entry_set_text (GTK_ENTRY (entry), _("mcen_ia_default_folder_name")); gtk_entry_select_region (GTK_ENTRY (entry), 0, -1); + /* Connect to the response method to avoid closing the dialog + when an invalid name is selected*/ + g_signal_connect (dialog, + "response", + G_CALLBACK (on_response), + parent); + /* Track entry changes */ g_signal_connect (entry, "insert-text", @@ -819,6 +865,9 @@ modest_platform_run_folder_name_dialog (GtkWindow *parent_window, gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox)); gtk_window_set_transient_for (GTK_WINDOW (dialog), parent_window); + + + result = gtk_dialog_run (GTK_DIALOG(dialog)); if (result == GTK_RESPONSE_ACCEPT) *folder_name = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry))); @@ -846,11 +895,8 @@ modest_platform_run_new_folder_dialog (GtkWindow *parent_window, unsigned int i; gchar num_str[3]; - for(i = 0; i < 100; ++ i) - { - TnyList *list = tny_simple_list_new (); - TnyFolderStoreQuery *query = tny_folder_store_query_new (); - guint length; + for(i = 0; i < 100; ++ i) { + gboolean exists = FALSE; sprintf(num_str, "%.2u", i); @@ -860,16 +906,10 @@ modest_platform_run_new_folder_dialog (GtkWindow *parent_window, real_suggested_name = g_strdup_printf (_("mcen_ia_default_folder_name_s"), num_str); - tny_folder_store_query_add_item (query, real_suggested_name, - TNY_FOLDER_STORE_QUERY_OPTION_MATCH_ON_NAME); - - tny_folder_store_get_folders (parent_folder, list, query, NULL); - - length = tny_list_get_length (list); - g_object_unref (query); - g_object_unref (list); + exists = modest_tny_folder_has_subfolder_with_name (parent_folder, + real_suggested_name); - if (length == 0) + if (!exists) break; g_free (real_suggested_name); @@ -878,13 +918,12 @@ modest_platform_run_new_folder_dialog (GtkWindow *parent_window, /* Didn't find a free number */ if (i == 100) real_suggested_name = g_strdup (default_name); - } - else - { + } else { real_suggested_name = suggested_name; } result = modest_platform_run_folder_name_dialog (parent_window, + parent_folder, _("mcen_ti_new_folder"), _("mcen_fi_new_folder_name"), real_suggested_name, @@ -901,11 +940,14 @@ modest_platform_run_rename_folder_dialog (GtkWindow *parent_window, const gchar *suggested_name, gchar **folder_name) { + g_return_val_if_fail (TNY_IS_FOLDER_STORE (parent_folder), GTK_RESPONSE_REJECT); + return modest_platform_run_folder_name_dialog (parent_window, - dgettext("hildon-libs", "ckdg_ti_rename_folder"), - dgettext("hildon-libs", "ckdg_fi_rename_name"), - suggested_name, - folder_name); + parent_folder, + _HL("ckdg_ti_rename_folder"), + _HL("ckdg_fi_rename_name"), + suggested_name, + folder_name); } gint diff --git a/src/modest-mail-operation.c b/src/modest-mail-operation.c index 350a3d1..4f0f942 100644 --- a/src/modest-mail-operation.c +++ b/src/modest-mail-operation.c @@ -1877,7 +1877,7 @@ modest_mail_operation_xfer_folder (ModestMailOperation *self, modest_mail_operation_notify_end (self); } else if (TNY_IS_FOLDER_STORE (parent) && - modest_tny_folder_same_subfolder (parent, folder_name)) { + modest_tny_folder_has_subfolder_with_name (parent, folder_name)) { /* Check that the new folder name is not used by any parent subfolder */ diff --git a/src/modest-text-utils.h b/src/modest-text-utils.h index 64a5a4a..f39dfc2 100644 --- a/src/modest-text-utils.h +++ b/src/modest-text-utils.h @@ -40,6 +40,7 @@ #define _FM(str) dgettext("hildon-fm",str) #define _CS(str) dgettext("hildon-common-strings",str) +#define _HL(str) dgettext("hildon-libs",str) /* Forbidden char arrays */ extern const gchar account_title_forbidden_chars[]; diff --git a/src/modest-tny-folder.c b/src/modest-tny-folder.c index 1dfeefd..9b13e75 100644 --- a/src/modest-tny-folder.c +++ b/src/modest-tny-folder.c @@ -379,39 +379,27 @@ modest_tny_folder_get_account (TnyFolder *folder) } gboolean -modest_tny_folder_same_subfolder (TnyFolderStore *parent, - const gchar *new_name) +modest_tny_folder_has_subfolder_with_name (TnyFolderStore *parent, + const gchar *name) { - TnyList *subfolders = NULL; - TnyIterator *iter = NULL; - TnyFolder *folder = NULL; - GError *err = NULL; - const gchar *name = NULL; - gboolean same_subfolder = FALSE; + TnyList *list; + TnyFolderStoreQuery *query; + guint length; g_return_val_if_fail (TNY_IS_FOLDER_STORE (parent), FALSE); + g_return_val_if_fail (name, FALSE); - /* Get direct subfolders */ - subfolders = tny_simple_list_new (); - tny_folder_store_get_folders (parent, subfolders, NULL, &err); + /* Create the query */ + list = tny_simple_list_new (); + query = tny_folder_store_query_new (); + tny_folder_store_query_add_item (query, name, + TNY_FOLDER_STORE_QUERY_OPTION_MATCH_ON_NAME); - /* Check names */ - iter = tny_list_create_iterator (subfolders); - while (!tny_iterator_is_done (iter) && !same_subfolder) { - folder = TNY_FOLDER(tny_iterator_get_current (iter)); - name = tny_folder_get_name (folder); - - same_subfolder = !strcmp(name, new_name); + /* Get subfolders */ + tny_folder_store_get_folders (parent, list, query, NULL); + length = tny_list_get_length (list); + g_object_unref (query); + g_object_unref (list); - g_object_unref (folder); - tny_iterator_next(iter); - } - - /* free */ - if (iter != NULL) - g_object_unref (iter); - if (subfolders != NULL) - g_object_unref (subfolders); - - return same_subfolder; + return (length > 0) ? TRUE : FALSE; } diff --git a/src/modest-tny-folder.h b/src/modest-tny-folder.h index 274727d..b013d87 100644 --- a/src/modest-tny-folder.h +++ b/src/modest-tny-folder.h @@ -179,19 +179,17 @@ TnyAccount *modest_tny_folder_get_account (TnyFolder *folder); gchar* modest_tny_folder_get_header_unique_id (TnyHeader *header); /** - * modest_tny_msg_get_header_unique_id: + * modest_tny_folder_has_subfolder_with_name: * @folder: a #TnyFolderStore - * @new_name: the new name to check into subfolders. + * @name: the name to check into subfolders. * * This function check if subfolders of @folder has the same - * name as @new_name. + * name as @name. * - * Returns: TRUE if some subfolder has the name @new_name. + * Returns: TRUE if some subfolder has the name @name. **/ -gboolean modest_tny_folder_same_subfolder (TnyFolderStore *folder, - const gchar *new_name); - - +gboolean modest_tny_folder_has_subfolder_with_name (TnyFolderStore *folder, + const gchar *name); G_END_DECLS diff --git a/src/modest-ui-actions.c b/src/modest-ui-actions.c index fceaaf0..7dba805 100644 --- a/src/modest-ui-actions.c +++ b/src/modest-ui-actions.c @@ -403,7 +403,6 @@ modest_ui_actions_on_delete_message (GtkAction *action, ModestWindow *win) tny_list_get_length(header_list)), desc); /* Confirmation dialog */ - printf("DEBUG: %s\n", __FUNCTION__); response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win), message); @@ -2423,10 +2422,14 @@ modest_ui_actions_on_rename_folder (GtkAction *action, gchar *folder_name; gint response; const gchar *current_name; + TnyFolderStore *parent; current_name = tny_folder_get_name (TNY_FOLDER (folder)); - response = modest_platform_run_rename_folder_dialog (GTK_WINDOW (main_window), NULL, - current_name, &folder_name); + parent = tny_folder_get_folder_store (TNY_FOLDER (folder)); + response = modest_platform_run_rename_folder_dialog (GTK_WINDOW (main_window), + parent, current_name, + &folder_name); + g_object_unref (parent); if (response == GTK_RESPONSE_ACCEPT && strlen (folder_name) > 0) { ModestMailOperation *mail_op; -- 1.7.9.5