* Renamed a function
authorSergio Villar Senin <svillar@igalia.com>
Fri, 24 Aug 2007 14:01:18 +0000 (14:01 +0000)
committerSergio Villar Senin <svillar@igalia.com>
Fri, 24 Aug 2007 14:01:18 +0000 (14:01 +0000)
* Added a new define for hildon-libs domain translation
* Fixes NB#65969

pmo-trunk-r3067

src/maemo/modest-platform.c
src/modest-mail-operation.c
src/modest-text-utils.h
src/modest-tny-folder.c
src/modest-tny-folder.h
src/modest-ui-actions.c

index a34f0a2..9338c34 100644 (file)
@@ -51,6 +51,7 @@
 #include <gtk/gtkmenuitem.h>
 #include <gtk/gtkmain.h>
 #include <modest-text-utils.h>
 #include <gtk/gtkmenuitem.h>
 #include <gtk/gtkmain.h>
 #include <modest-text-utils.h>
+#include "modest-tny-folder.h"
 #include <string.h>
 
 
 #include <string.h>
 
 
@@ -760,8 +761,46 @@ launch_sort_headers_dialog (GtkWindow *parent_window,
        g_list_free(cols);      
 }
 
        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,
 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,
                                        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);
 
                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",
        /* 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);
        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)));
        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];
 
                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);
 
 
                        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);
 
                                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);
                                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);
                /* 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, 
                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,
                                                         _("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)
 {
                                           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, 
        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
 }
 
 gint
index 350a3d1..4f0f942 100644 (file)
@@ -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_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 */
 
                /* Check that the new folder name is not used by any
                    parent subfolder */
 
index 64a5a4a..f39dfc2 100644 (file)
@@ -40,6 +40,7 @@
 
 #define _FM(str) dgettext("hildon-fm",str)
 #define _CS(str) dgettext("hildon-common-strings",str)
 
 #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[];
 
 /* Forbidden char arrays */
 extern const gchar account_title_forbidden_chars[];
index 1dfeefd..9b13e75 100644 (file)
@@ -379,39 +379,27 @@ modest_tny_folder_get_account (TnyFolder *folder)
 }
 
 gboolean 
 }
 
 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 (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;
 }
 }
index 274727d..b013d87 100644 (file)
@@ -179,19 +179,17 @@ TnyAccount *modest_tny_folder_get_account (TnyFolder *folder);
 gchar* modest_tny_folder_get_header_unique_id (TnyHeader *header);
 
 /**
 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 
  * @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
  *   
  * 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
 
 
 G_END_DECLS
index fceaaf0..7dba805 100644 (file)
@@ -403,7 +403,6 @@ modest_ui_actions_on_delete_message (GtkAction *action, ModestWindow *win)
                                           tny_list_get_length(header_list)), desc);
 
        /* Confirmation dialog */
                                           tny_list_get_length(header_list)), desc);
 
        /* Confirmation dialog */
-       printf("DEBUG: %s\n", __FUNCTION__);    
        response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
                                                            message);
        
        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;
                gchar *folder_name;
                gint response;
                const gchar *current_name;
+               TnyFolderStore *parent;
 
                current_name = tny_folder_get_name (TNY_FOLDER (folder));
 
                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;
 
                if (response == GTK_RESPONSE_ACCEPT && strlen (folder_name) > 0) {
                        ModestMailOperation *mail_op;