[nautilus/wip/alexpandelea/batchRename] Improve code



commit 77f7363b0b950ce5251d1e009e97dff006bfd4dc
Author: Alexandru Pandelea <alexandru pandelea gmail com>
Date:   Sat Aug 27 16:23:53 2016 +0300

    Improve code
    
    Improve code based on review

 src/nautilus-batch-rename-dialog.c                 |  154 +++++++-----
 src/nautilus-batch-rename-dialog.h                 |    8 +
 src/nautilus-batch-rename-utilities.c              |  263 +++++++++++++-------
 src/resources/ui/nautilus-batch-rename-dialog.ui   |    1 +
 .../ui/nautilus-files-view-context-menus.ui        |    2 +-
 5 files changed, 272 insertions(+), 156 deletions(-)
---
diff --git a/src/nautilus-batch-rename-dialog.c b/src/nautilus-batch-rename-dialog.c
index 9e58be4..42350f6 100644
--- a/src/nautilus-batch-rename-dialog.c
+++ b/src/nautilus-batch-rename-dialog.c
@@ -712,12 +712,12 @@ batch_rename_dialog_get_new_names (NautilusBatchRenameDialog *dialog)
 {
         GList *result = NULL;
         GList *selection;
-        GList *tags_list;
+        GList *text_chunks;
         g_autofree gchar *entry_text;
         g_autofree gchar *replace_text;
 
         selection = dialog->selection;
-        tags_list = NULL;
+        text_chunks = NULL;
 
         if (dialog->mode == NAUTILUS_BATCH_RENAME_DIALOG_REPLACE)
                 entry_text = g_strdup (gtk_entry_get_text (GTK_ENTRY (dialog->find_entry)));
@@ -734,15 +734,15 @@ batch_rename_dialog_get_new_names (NautilusBatchRenameDialog *dialog)
                                                                  entry_text,
                                                                  replace_text);
         } else {
-                tags_list = split_entry_text (dialog, entry_text);
+                text_chunks = split_entry_text (dialog, entry_text);
 
                 result = batch_rename_dialog_get_new_names_list (dialog->mode,
                                                                  selection,
-                                                                 tags_list,
+                                                                 text_chunks,
                                                                  dialog->selection_metadata,
                                                                  entry_text,
                                                                  replace_text);
-                g_list_free_full (tags_list, string_free);
+                g_list_free_full (text_chunks, string_free);
         }
 
         result = g_list_reverse (result);
@@ -897,12 +897,10 @@ create_original_name_row_for_label (NautilusBatchRenameDialog *dialog,
 
         g_object_set_data (G_OBJECT (row), "show-separator", GINT_TO_POINTER (show_separator));
 
-        label_old = g_object_new (GTK_TYPE_LABEL,
-                                  "label",old_text,
-                                  "hexpand", TRUE,
-                                  "xalign", 0.0,
-                                  "margin-start", 6,
-                                  NULL);
+        label_old = gtk_label_new (old_text);
+        gtk_label_set_xalign (GTK_LABEL (label_old), 0.0);
+        gtk_widget_set_hexpand (label_old, TRUE);
+        gtk_widget_set_margin_start (label_old, 6);
 
         gtk_label_set_ellipsize (GTK_LABEL (label_old), PANGO_ELLIPSIZE_END);
 
@@ -926,12 +924,10 @@ create_result_row_for_label (NautilusBatchRenameDialog *dialog,
 
         g_object_set_data (G_OBJECT (row), "show-separator", GINT_TO_POINTER (show_separator));
 
-        label_new = g_object_new (GTK_TYPE_LABEL,
-                                  "label",new_text,
-                                  "hexpand", TRUE,
-                                  "xalign", 0.0,
-                                  "margin-start", 6,
-                                  NULL);
+        label_new = gtk_label_new (new_text);
+        gtk_label_set_xalign (GTK_LABEL (label_new), 0.0);
+        gtk_widget_set_hexpand (label_new, TRUE);
+        gtk_widget_set_margin_start (label_new, 6);
 
         gtk_label_set_ellipsize (GTK_LABEL (label_new), PANGO_ELLIPSIZE_END);
 
@@ -954,12 +950,10 @@ create_arrow_row_for_label (NautilusBatchRenameDialog *dialog,
 
         g_object_set_data (G_OBJECT (row), "show-separator", GINT_TO_POINTER (show_separator));
 
-        icon = g_object_new (GTK_TYPE_LABEL,
-                             "label","→",
-                             "hexpand", FALSE,
-                             "xalign", 1.0,
-                             "margin-start", 6,
-                             NULL);
+        icon = gtk_label_new ("→");
+        gtk_label_set_xalign (GTK_LABEL (icon), 1.0);
+        gtk_widget_set_hexpand (icon, FALSE);
+        gtk_widget_set_margin_start (icon, 6);
 
         dialog->listbox_icons = g_list_prepend (dialog->listbox_icons, icon);
 
@@ -1325,6 +1319,8 @@ check_conflict_for_files (NautilusBatchRenameDialog *dialog,
                                                        (GDestroyNotify) g_free,
                                                        (GDestroyNotify) g_free);
 
+        /* names_conflicts_table is used for knowing which names from the list are not unique,
+         * so that they can easily be reached when needed */
         for (l1 = dialog->new_names, l2 = dialog->selection;
              l1 != NULL && l2 != NULL;
              l1 = l1->next, l2 = l2->next) {
@@ -2146,7 +2142,7 @@ static gboolean
 remove_tag (NautilusBatchRenameDialog *dialog,
             gchar                     *tag_name,
             gchar                     *action_name,
-            gchar                     *keyval_name,
+            gint                       keyval,
             gboolean                   is_modifier)
 {
         TagData *tag_data;
@@ -2167,14 +2163,14 @@ remove_tag (NautilusBatchRenameDialog *dialog,
         if (!tag_data->set)
                 return FALSE;
 
-        if (g_strcmp0(keyval_name, "BackSpace") == 0) {
+        if (keyval == GDK_KEY_BackSpace) {
                 if (cursor_position > tag_data->position &&
                     cursor_position <= tag_data->position + g_utf8_strlen (tag_name, -1)) {
                         delete_tag = TRUE;
                 }
         }
 
-        if (g_strcmp0(keyval_name, "Delete") == 0) {
+        if (keyval == GDK_KEY_Delete) {
                 if (cursor_position >= tag_data->position &&
                     cursor_position < tag_data->position + g_utf8_strlen (tag_name, -1)) {
                         delete_tag = TRUE;
@@ -2182,11 +2178,12 @@ remove_tag (NautilusBatchRenameDialog *dialog,
         }
 
         if (!is_modifier &&
-            g_strcmp0 (keyval_name, "Left") != 0 &&
-            g_strcmp0 (keyval_name, "Right") != 0 &&
-            g_strcmp0 (keyval_name, "Return") != 0 &&
-            g_strcmp0 (keyval_name, "Escape") != 0 &&
-            g_strcmp0 (keyval_name, "Tab") != 0) {
+            keyval != GDK_KEY_Left &&
+            keyval != GDK_KEY_Right &&
+            keyval != GDK_KEY_Delete &&
+            keyval != GDK_KEY_Return &&
+            keyval != GDK_KEY_Escape &&
+            keyval != GDK_KEY_Tab) {
                 if (cursor_position > tag_data->position &&
                     cursor_position < tag_data->position + g_utf8_strlen (tag_name, -1)) {
                         delete_tag = TRUE;
@@ -2282,7 +2279,7 @@ on_key_press_event (GtkWidget    *widget,
                     gpointer      user_data)
 {
         NautilusBatchRenameDialog *dialog;
-        gchar* keyval_name;
+        gint keyval;
         GdkEvent *gdk_event;
         GString *old_entry_text;
         GString *new_entry_text;
@@ -2298,7 +2295,7 @@ on_key_press_event (GtkWidget    *widget,
 
         dialog = NAUTILUS_BATCH_RENAME_DIALOG (user_data);
 
-        keyval_name = gdk_keyval_name (event->keyval);
+        keyval = event->keyval;
 
         entry_has_selection =  (gtk_editable_get_selection_bounds (GTK_EDITABLE (dialog->name_entry),
                                                                    &start,
@@ -2308,13 +2305,13 @@ on_key_press_event (GtkWidget    *widget,
                 return GDK_EVENT_PROPAGATE;
 
         if (entry_has_selection &&
-            ((g_strcmp0 (keyval_name, "Delete") == 0 || g_strcmp0 (keyval_name, "BackSpace") == 0) ||
+            ((keyval == GDK_KEY_Delete || keyval == GDK_KEY_BackSpace) ||
             (!gdk_event->key.is_modifier &&
-            g_strcmp0(keyval_name, "Left") != 0 &&
-            g_strcmp0(keyval_name, "Right") != 0 &&
-            g_strcmp0(keyval_name, "Return") != 0 &&
-            g_strcmp0 (keyval_name, "Escape") != 0 &&
-            g_strcmp0 (keyval_name, "Tab") != 0))) {
+            keyval != GDK_KEY_Left &&
+            keyval != GDK_KEY_Right &&
+            keyval != GDK_KEY_Return &&
+            keyval != GDK_KEY_Escape &&
+            keyval != GDK_KEY_Tab))) {
                 old_entry_text = g_string_new (gtk_entry_get_text (GTK_ENTRY (dialog->name_entry)));
 
                 minimum_tag_position = G_MAXINT;
@@ -2597,7 +2594,7 @@ on_key_press_event (GtkWidget    *widget,
                         g_string_free (new_entry_text, TRUE);
                 }
 
-                if ((g_strcmp0 (keyval_name, "Delete") == 0 || g_strcmp0 (keyval_name, "BackSpace") == 0) &&
+                if ((keyval == GDK_KEY_Delete || keyval == GDK_KEY_BackSpace) &&
                     tag_removed)
                         return TRUE;
 
@@ -2609,89 +2606,113 @@ on_key_press_event (GtkWidget    *widget,
         if (remove_tag (dialog,
                         ORIGINAL_FILE_NAME,
                         "add-original-file-name-tag",
-                        keyval_name,
+                        keyval,
                         gdk_event->key.is_modifier))
                 tag_removed = TRUE;
 
         if (remove_tag (dialog,
                         CREATION_DATE,
                         "add-creation-date-tag",
-                        keyval_name,
+                        keyval,
                         gdk_event->key.is_modifier))
                 tag_removed = TRUE;
 
         if (remove_tag (dialog,
                         NUMBERING,
                         "add-numbering-tag-zero",
-                        keyval_name,
-                        gdk_event->key.is_modifier))
+                        keyval,
+                        gdk_event->key.is_modifier)) {
                 tag_removed = TRUE;
+                action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
+                                                                   "add-numbering-tag-one");
+                g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
+
+                action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
+                                                                   "add-numbering-tag-two");
+                g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
+        }
 
         if (remove_tag (dialog,
                         NUMBERING0,
                         "add-numbering-tag-one",
-                        keyval_name,
-                        gdk_event->key.is_modifier))
+                        keyval,
+                        gdk_event->key.is_modifier)) {
                 tag_removed = TRUE;
+                action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
+                                                                   "add-numbering-tag-zero");
+                g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
+
+                action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
+                                                                   "add-numbering-tag-two");
+                g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
+        }
 
         if (remove_tag (dialog,
                         NUMBERING00,
                         "add-numbering-tag-two",
-                        keyval_name,
-                        gdk_event->key.is_modifier))
+                        keyval,
+                        gdk_event->key.is_modifier)) {
                 tag_removed = TRUE;
+                action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
+                                                                   "add-numbering-tag-one");
+                g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
+
+                action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
+                                                                   "add-numbering-tag-zero");
+                g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
+        }
 
         if (remove_tag (dialog,
                         CAMERA_MODEL,
                         "add-equipment-tag",
-                        keyval_name,
+                        keyval,
                         gdk_event->key.is_modifier))
                 tag_removed = TRUE;
 
         if (remove_tag (dialog,
                         SEASON_NUMBER,
                         "add-season-tag",
-                        keyval_name,
+                        keyval,
                         gdk_event->key.is_modifier))
                 tag_removed = TRUE;
 
         if (remove_tag (dialog,
                         EPISODE_NUMBER,
                         "add-episode-tag",
-                        keyval_name,
+                        keyval,
                         gdk_event->key.is_modifier))
                 tag_removed = TRUE;
 
         if (remove_tag (dialog,
                         TRACK_NUMBER,
                         "add-track-number-tag",
-                        keyval_name,
+                        keyval,
                         gdk_event->key.is_modifier))
                 tag_removed = TRUE;
 
         if (remove_tag (dialog,
                         ARTIST_NAME,
                         "add-artist-name-tag",
-                        keyval_name,
+                        keyval,
                         gdk_event->key.is_modifier))
                 tag_removed = TRUE;
 
         if (remove_tag (dialog,
                         TITLE,
                         "add-title-tag",
-                        keyval_name,
+                        keyval,
                         gdk_event->key.is_modifier))
                 tag_removed = TRUE;
 
         if (remove_tag (dialog,
                         ALBUM_NAME,
                         "add-album-name-tag",
-                        keyval_name,
+                        keyval,
                         gdk_event->key.is_modifier))
                 tag_removed = TRUE;
 
         if (tag_removed) {
-                if (g_strcmp0 (keyval_name, "Delete") == 0 || g_strcmp0 (keyval_name, "BackSpace") == 0)
+                if (keyval == GDK_KEY_Delete || keyval == GDK_KEY_BackSpace)
                         return TRUE;
 
                 return GDK_EVENT_PROPAGATE;
@@ -2741,6 +2762,18 @@ nautilus_batch_rename_dialog_finalize (GObject *object)
                         g_string_free (metadata->artist_name, TRUE);
                 if (metadata->album_name != NULL)
                         g_string_free (metadata->album_name, TRUE);
+                if (metadata->year != NULL)
+                        g_string_free (metadata->season, TRUE);
+                if (metadata->month != NULL)
+                        g_string_free (metadata->season, TRUE);
+                if (metadata->day != NULL)
+                        g_string_free (metadata->season, TRUE);
+                if (metadata->hours != NULL)
+                        g_string_free (metadata->season, TRUE);
+                if (metadata->minutes != NULL)
+                        g_string_free (metadata->season, TRUE);
+                if (metadata->seconds != NULL)
+                        g_string_free (metadata->season, TRUE);
         }
 
         if (dialog->create_date != NULL)
@@ -2811,8 +2844,6 @@ nautilus_batch_rename_dialog_new (GList             *selection,
                                   NautilusWindow    *window)
 {
         NautilusBatchRenameDialog *dialog;
-        gint files_number;
-        GList *l;
         GString *dialog_title;
 
         dialog = g_object_new (NAUTILUS_TYPE_BATCH_RENAME_DIALOG, "use-header-bar", TRUE, NULL);
@@ -2824,13 +2855,8 @@ nautilus_batch_rename_dialog_new (GList             *selection,
         gtk_window_set_transient_for (GTK_WINDOW (dialog),
                                       GTK_WINDOW (window));
 
-        files_number = 0;
-
-        for (l = dialog->selection; l != NULL; l = l->next)
-                files_number++;
-
         dialog_title = g_string_new ("");
-        g_string_append_printf (dialog_title, "Rename %d Files", files_number);
+        g_string_append_printf (dialog_title, "Rename %d Files", g_list_length (selection));
         gtk_window_set_title (GTK_WINDOW (dialog), dialog_title->str);
 
         nautilus_batch_rename_dialog_initialize_actions (dialog);
diff --git a/src/nautilus-batch-rename-dialog.h b/src/nautilus-batch-rename-dialog.h
index e1e7c3d..7f15959 100644
--- a/src/nautilus-batch-rename-dialog.h
+++ b/src/nautilus-batch-rename-dialog.h
@@ -77,6 +77,14 @@ typedef struct {
         GString *artist_name;
         GString *title;
         GString *album_name;
+
+        GString *year;
+        GString *month;
+        GString *day;
+        GString *hours;
+        GString *minutes;
+        GString *seconds;
+        GString *timezone;
 } FileMetadata;
 
 #define NAUTILUS_TYPE_BATCH_RENAME_DIALOG (nautilus_batch_rename_dialog_get_type())
diff --git a/src/nautilus-batch-rename-utilities.c b/src/nautilus-batch-rename-utilities.c
index ae45896..f218de5 100644
--- a/src/nautilus-batch-rename-utilities.c
+++ b/src/nautilus-batch-rename-utilities.c
@@ -49,6 +49,26 @@ typedef struct {
         gboolean have_album_name;
 } QueryData;
 
+enum {
+       FILE_NAME_INDEX,
+       CREATION_DATE_INDEX,
+       YEAR_INDEX,
+       MONTH_INDEX,
+       DAY_INDEX,
+       HOURS_INDEX,
+       MINUTES_INDEX,
+       SECONDS_INDEX,
+       //TIMEZONE_INDEX,
+       CAMERA_MODEL_INDEX,
+       SEASON_INDEX,
+       EPISODE_NUMBER_INDEX,
+       TRACK_NUMBER_INDEX,
+       ARTIST_NAME_INDEX,
+       TITLE_INDEX,
+       ALBUM_NAME_INDEX,
+
+} QueryMetadata;
+
 static void on_cursor_callback (GObject      *object,
                                 GAsyncResult *result,
                                 gpointer      user_data);
@@ -70,9 +90,9 @@ conflict_data_free (gpointer mem)
 }
 
 static GString*
-batch_rename_dialog_replace (gchar *string,
-                             gchar *substring,
-                             gchar *replacement)
+batch_rename_replace (gchar *string,
+                      gchar *substring,
+                      gchar *replacement)
 {
         GString *new_string;
         gchar **splitted_string;
@@ -113,6 +133,7 @@ batch_rename_dialog_replace (gchar *string,
         return new_string;
 }
 
+/* This function changes the background color of the replaced part of the name */
 GString*
 batch_rename_replace_label_text (gchar       *label,
                                  const gchar *substring)
@@ -214,6 +235,36 @@ get_metadata (GList *selection_metadata,
                             file_metadata->album_name != NULL &&
                             file_metadata->album_name->len != 0)
                                 return file_metadata->album_name->str;
+
+                        if (g_strcmp0 (metadata, "year") == 0 &&
+                            file_metadata->creation_date != NULL &&
+                            file_metadata->creation_date->len != 0)
+                                return file_metadata->year->str;
+
+                        if (g_strcmp0 (metadata, "month") == 0 &&
+                            file_metadata->creation_date != NULL &&
+                            file_metadata->creation_date->len != 0)
+                                return file_metadata->month->str;
+
+                        if (g_strcmp0 (metadata, "day") == 0 &&
+                            file_metadata->creation_date != NULL &&
+                            file_metadata->creation_date->len != 0)
+                                return file_metadata->day->str;
+
+                        if (g_strcmp0 (metadata, "hours") == 0 &&
+                            file_metadata->creation_date != NULL &&
+                            file_metadata->creation_date->len != 0)
+                                return file_metadata->hours->str;
+
+                        if (g_strcmp0 (metadata, "minutes") == 0 &&
+                            file_metadata->creation_date != NULL &&
+                            file_metadata->creation_date->len != 0)
+                                return file_metadata->minutes->str;
+
+                        if (g_strcmp0 (metadata, "seconds") == 0 &&
+                            file_metadata->creation_date != NULL &&
+                            file_metadata->creation_date->len != 0)
+                                return file_metadata->seconds->str;
                 }
         }
 
@@ -221,10 +272,10 @@ get_metadata (GList *selection_metadata,
 }
 
 static GString*
-batch_rename_dialog_format (NautilusFile *file,
-                            GList        *tags_list,
-                            GList        *selection_metadata,
-                            gint          count)
+batch_rename_format (NautilusFile *file,
+                     GList        *text_chunks,
+                     GList        *selection_metadata,
+                     gint          count)
 {
         GDateTime *datetime;
         GList *l;
@@ -235,7 +286,6 @@ batch_rename_dialog_format (NautilusFile *file,
         g_autofree gchar *file_name;
         g_autofree gchar *extension;
         gchar *metadata;
-        gchar **splitted_date;
         gchar *base_name;
         gchar *date;
 
@@ -244,7 +294,7 @@ batch_rename_dialog_format (NautilusFile *file,
 
         new_name = g_string_new ("");
 
-        for (l = tags_list; l != NULL; l = l->next) {
+        for (l = text_chunks; l != NULL; l = l->next) {
                 tag = l->data;
                 added_tag = FALSE;
 
@@ -263,25 +313,13 @@ batch_rename_dialog_format (NautilusFile *file,
                 }
 
                 if (!added_tag && g_strcmp0 (tag->str, NUMBERING0) == 0) {
-                        if (count < 10) {
-                                g_string_append_printf (new_name, "0%d", count);
-                        } else {
-                                g_string_append_printf (new_name, "%d", count);
-                        }
+                        g_string_append_printf (new_name, "%02d", count);
 
                         added_tag = TRUE;
                 }
 
                 if (!added_tag && g_strcmp0 (tag->str, NUMBERING00) == 0) {
-                        if (count < 10) {
-                                g_string_append_printf (new_name, "00%d", count);
-                        } else {
-                                if (count < 100) {
-                                        g_string_append_printf (new_name, "0%d", count);
-                                } else {
-                                        g_string_append_printf (new_name, "%d", count);
-                                }
-                        }
+                        g_string_append_printf (new_name, "%03d", count);
 
                         added_tag = TRUE;
                 }
@@ -299,19 +337,23 @@ batch_rename_dialog_format (NautilusFile *file,
                         metadata = get_metadata (selection_metadata, file_name, "creation_date");
 
                         if (metadata != NULL) {
-                                splitted_date = g_strsplit_set (metadata, "T:-Z", -1);
-
-                                datetime = g_date_time_new_local (atoi (splitted_date[0]),
-                                                                  atoi (splitted_date[1]),
-                                                                  atoi (splitted_date[2]),
-                                                                  atoi (splitted_date[3]),
-                                                                  atoi (splitted_date[4]),
-                                                                  atoi (splitted_date[5]));
+                                g_message ("%s", get_metadata (selection_metadata, file_name, "year"));
+                                g_message ("%s", get_metadata (selection_metadata, file_name, "month"));
+                                g_message ("%s", get_metadata (selection_metadata, file_name, "day"));
+                                g_message ("%s", get_metadata (selection_metadata, file_name, "hour"));
+                                g_message ("%s", get_metadata (selection_metadata, file_name, "minutes"));
+                                g_message ("%s", get_metadata (selection_metadata, file_name, "seconds"));
+                                datetime = g_date_time_new_local (atoi (get_metadata (selection_metadata, 
file_name, "year")),
+                                                                  atoi (get_metadata (selection_metadata, 
file_name, "month")),
+                                                                  atoi (get_metadata (selection_metadata, 
file_name, "day")),
+                                                                  atoi (get_metadata (selection_metadata, 
file_name, "hour")),
+                                                                  atoi (get_metadata (selection_metadata, 
file_name, "minutes")),
+                                                                  atoi (get_metadata (selection_metadata, 
file_name, "seconds")));
 
                                 date = g_date_time_format (datetime, "%x");
 
                                 if (strstr (date, "/") != NULL) {
-                                        create_date = batch_rename_dialog_replace (date, "/", "-");
+                                        create_date = batch_rename_replace (date, "/", "-");
                                         new_name = g_string_append (new_name, create_date->str);
 
                                         g_string_free (create_date, TRUE);
@@ -322,7 +364,8 @@ batch_rename_dialog_format (NautilusFile *file,
                                 added_tag = TRUE;
 
                                 g_free (date);
-                                g_strfreev (splitted_date);
+
+                                added_tag = TRUE;
                         }
                 }
 
@@ -397,7 +440,7 @@ batch_rename_dialog_format (NautilusFile *file,
 GList*
 batch_rename_dialog_get_new_names_list (NautilusBatchRenameDialogMode mode,
                                         GList                        *selection,
-                                        GList                        *tags_list,
+                                        GList                        *text_chunks,
                                         GList                        *selection_metadata,
                                         gchar                        *entry_text,
                                         gchar                        *replace_text)
@@ -423,17 +466,17 @@ batch_rename_dialog_get_new_names_list (NautilusBatchRenameDialogMode mode,
 
                 /* get the new name here and add it to the list*/
                 if (mode == NAUTILUS_BATCH_RENAME_DIALOG_FORMAT) {
-                        new_name = batch_rename_dialog_format (file,
-                                                        tags_list,
+                        new_name = batch_rename_format (file,
+                                                        text_chunks,
                                                         selection_metadata,
                                                         count++);
                         result = g_list_prepend (result, new_name);
                 }
 
                 if (mode == NAUTILUS_BATCH_RENAME_DIALOG_REPLACE) {
-                        new_name = batch_rename_dialog_replace (file_name->str,
-                                                                entry_text,
-                                                                replace_text);
+                        new_name = batch_rename_replace (file_name->str,
+                                                         entry_text,
+                                                         replace_text);
                         result = g_list_prepend (result, new_name);
                 }
                 
@@ -483,7 +526,8 @@ file_name_conflicts_with_results (GList        *selection,
                 g_free (selection_parent_uri);
         }
 
-        /* such a file doesn't exist so there actually is a conflict */
+        /* the case this function searched for doesn't exist, so the file
+         * has a conlfict */
         return FALSE;
 }
 
@@ -659,6 +703,13 @@ on_cursor_callback (GObject      *object,
         FileMetadata *metadata_clear;
         const gchar *file_name;
         const gchar *creation_date;
+        const gchar *year;
+        const gchar *month;
+        const gchar *day;
+        const gchar *hours;
+        const gchar *minutes;
+        const gchar *seconds;
+        const gchar *timezone;
         const gchar *equipment;
         const gchar *season_number;
         const gchar *episode_number;
@@ -686,14 +737,22 @@ on_cursor_callback (GObject      *object,
                 return;
         }
 
-        creation_date = tracker_sparql_cursor_get_string (cursor, 1, NULL);
-        equipment = tracker_sparql_cursor_get_string (cursor, 2, NULL);
-        season_number = tracker_sparql_cursor_get_string (cursor, 3, NULL);
-        episode_number = tracker_sparql_cursor_get_string (cursor, 4, NULL);
-        track_number = tracker_sparql_cursor_get_string (cursor, 5, NULL);
-        artist_name = tracker_sparql_cursor_get_string (cursor, 6, NULL);
-        title = tracker_sparql_cursor_get_string (cursor, 7, NULL);
-        album_name = tracker_sparql_cursor_get_string (cursor, 8, NULL);
+        creation_date = tracker_sparql_cursor_get_string (cursor, CREATION_DATE_INDEX, NULL);
+
+        year = tracker_sparql_cursor_get_string (cursor, YEAR_INDEX, NULL);
+        month = tracker_sparql_cursor_get_string (cursor, MONTH_INDEX, NULL);
+        day = tracker_sparql_cursor_get_string (cursor, DAY_INDEX, NULL);
+        hours = tracker_sparql_cursor_get_string (cursor, HOURS_INDEX, NULL);
+        minutes = tracker_sparql_cursor_get_string (cursor, MINUTES_INDEX, NULL);
+        seconds = tracker_sparql_cursor_get_string (cursor, SECONDS_INDEX, NULL);
+        //timezone = tracker_sparql_cursor_get_string (cursor, TIMEZONE_INDEX, NULL);
+        equipment = tracker_sparql_cursor_get_string (cursor, CAMERA_MODEL_INDEX, NULL);
+        season_number = tracker_sparql_cursor_get_string (cursor, SEASON_INDEX, NULL);
+        episode_number = tracker_sparql_cursor_get_string (cursor, EPISODE_NUMBER_INDEX, NULL);
+        track_number = tracker_sparql_cursor_get_string (cursor, TRACK_NUMBER_INDEX, NULL);
+        artist_name = tracker_sparql_cursor_get_string (cursor, ARTIST_NAME_INDEX, NULL);
+        title = tracker_sparql_cursor_get_string (cursor, TITLE_INDEX, NULL);
+        album_name = tracker_sparql_cursor_get_string (cursor, ALBUM_NAME_INDEX, NULL);
 
         /* creation date used for sorting criteria */
         if (creation_date == NULL) {
@@ -709,7 +768,7 @@ on_cursor_callback (GObject      *object,
                         GINT_TO_POINTER (g_hash_table_size (hash_table)));
                 }
         }
-        file_name = tracker_sparql_cursor_get_string (cursor, 0, NULL);
+        file_name = tracker_sparql_cursor_get_string (cursor, FILE_NAME_INDEX, NULL);
         for (l = query_data->selection_metadata; l != NULL; l = l->next) {
                 metadata = l->data;
 
@@ -720,18 +779,26 @@ on_cursor_callback (GObject      *object,
         /* Metadata to be used in file name
          * creation date */
         if (query_data->have_creation_date) {
-                if (creation_date == NULL) {
+                if (!creation_date) {
                         query_data->have_creation_date = FALSE;
 
                         for (l = query_data->selection_metadata; l != NULL; l = l->next) {
                                 metadata_clear = l->data;
 
-                                g_string_free (metadata_clear->creation_date, TRUE);
-                                metadata_clear->creation_date = NULL;
+                                if (metadata_clear->creation_date != NULL) {
+                                        g_string_free (metadata_clear->creation_date, TRUE);
+                                        metadata_clear->creation_date = NULL;
+                                }
                         }
                 } else {
-                        g_string_append (metadata->creation_date,
-                                         creation_date);
+                        metadata->year = g_string_new (year);
+                        metadata->month = g_string_new (month);
+                        metadata->day = g_string_new (day);
+                        metadata->hours = g_string_new (hours);
+                        metadata->minutes = g_string_new (minutes);
+                        metadata->seconds = g_string_new (seconds);
+
+                        metadata->creation_date = g_string_new (creation_date);
                 }
         }
 
@@ -743,12 +810,13 @@ on_cursor_callback (GObject      *object,
                         for (l = query_data->selection_metadata; l != NULL; l = l->next) {
                                 metadata_clear = l->data;
 
-                                g_string_free (metadata_clear->equipment, TRUE);
-                                metadata_clear->equipment = NULL;
+                                if (metadata_clear->equipment != NULL) {
+                                        g_string_free (metadata_clear->equipment, TRUE);
+                                        metadata_clear->equipment = NULL;
+                                }
                         }
                 } else {
-                        g_string_append (metadata->equipment,
-                                         equipment);
+                        metadata->equipment = g_string_new (equipment);
                 }
         }
 
@@ -760,12 +828,13 @@ on_cursor_callback (GObject      *object,
                         for (l = query_data->selection_metadata; l != NULL; l = l->next) {
                                 metadata_clear = l->data;
 
-                                g_string_free (metadata_clear->season, TRUE);
-                                metadata_clear->season = NULL;
+                                if (metadata_clear->season != NULL) {
+                                        g_string_free (metadata_clear->season, TRUE);
+                                        metadata_clear->season = NULL;
+                                }
                         }
                 } else {
-                        g_string_append (metadata->season,
-                                         season_number);
+                        metadata->season = g_string_new (season_number);
                 }
         }
 
@@ -777,12 +846,13 @@ on_cursor_callback (GObject      *object,
                         for (l = query_data->selection_metadata; l != NULL; l = l->next) {
                                 metadata_clear = l->data;
 
-                                g_string_free (metadata_clear->episode_number, TRUE);
-                                metadata_clear->episode_number = NULL;
+                                if (metadata_clear->episode_number != NULL) {
+                                        g_string_free (metadata_clear->episode_number, TRUE);
+                                        metadata_clear->episode_number = NULL;
+                                }
                         }
                 } else {
-                        g_string_append (metadata->episode_number,
-                                         episode_number);
+                        metadata->episode_number = g_string_new (episode_number);
                 }
         }
 
@@ -793,12 +863,13 @@ on_cursor_callback (GObject      *object,
                         for (l = query_data->selection_metadata; l != NULL; l = l->next) {
                                 metadata_clear = l->data;
 
-                                g_string_free (metadata_clear->track_number, TRUE);
-                                metadata_clear->track_number = NULL;
+                                if (metadata_clear->track_number != NULL) {
+                                        g_string_free (metadata_clear->track_number, TRUE);
+                                        metadata_clear->track_number = NULL;
+                                }
                         }
                 } else {
-                        g_string_append (metadata->track_number,
-                                         track_number);
+                        metadata->track_number = g_string_new (track_number);
                 }
         }
 
@@ -810,12 +881,13 @@ on_cursor_callback (GObject      *object,
                         for (l = query_data->selection_metadata; l != NULL; l = l->next) {
                                 metadata_clear = l->data;
 
-                                g_string_free (metadata_clear->artist_name, TRUE);
-                                metadata_clear->artist_name = NULL;
+                                if (metadata_clear->artist_name != NULL) {
+                                        g_string_free (metadata_clear->artist_name, TRUE);
+                                        metadata_clear->artist_name = NULL;
+                                }
                         }
                 } else {
-                        g_string_append (metadata->artist_name,
-                                         artist_name);
+                        metadata->artist_name = g_string_new (artist_name);
                 }
         }
 
@@ -827,12 +899,13 @@ on_cursor_callback (GObject      *object,
                         for (l = query_data->selection_metadata; l != NULL; l = l->next) {
                                 metadata_clear = l->data;
 
-                                g_string_free (metadata_clear->title, TRUE);
-                                metadata_clear->title = NULL;
+                                if (metadata_clear->title != NULL) {
+                                        g_string_free (metadata_clear->title, TRUE);
+                                        metadata_clear->title = NULL;
+                                }
                         }
                 } else {
-                        g_string_append (metadata->title,
-                                         title);
+                        metadata->title = g_string_new (title);
                 }
         }
 
@@ -844,12 +917,13 @@ on_cursor_callback (GObject      *object,
                         for (l = query_data->selection_metadata; l != NULL; l = l->next) {
                                 metadata_clear = l->data;
 
-                                g_string_free (metadata_clear->album_name, TRUE);
-                                metadata_clear->album_name = NULL;
+                                if (metadata_clear->album_name != NULL) {
+                                        g_string_free (metadata_clear->album_name, TRUE);
+                                        metadata_clear->album_name = NULL;
+                                }
                         }
                 } else {
-                        g_string_append (metadata->album_name,
-                                         album_name);
+                        metadata->album_name = g_string_new (album_name);
                 }
         }
 
@@ -877,7 +951,7 @@ batch_rename_dialog_query_callback (GObject      *object,
                                                          &error);
 
         if (error != NULL) {
-                g_warning ("Error on batch rename query for metadata");
+                g_warning ("Error on batch rename query for metadata: %s", error->message);
                 g_error_free (error);
 
                 nautilus_batch_rename_dialog_query_finished (query_data->dialog,
@@ -909,6 +983,13 @@ check_metadata_for_selection (NautilusBatchRenameDialog *dialog,
         query = g_string_new ("SELECT "
                               "nfo:fileName(?file) "
                               "nie:contentCreated(?file) "
+                              "year(nie:contentCreated(?file)) "
+                              "month(nie:contentCreated(?file)) "
+                              "day(nie:contentCreated(?file)) "
+                              "hours(nie:contentCreated(?file)) "
+                              "minutes(nie:contentCreated(?file)) "
+                              "seconds(nie:contentCreated(?file)) "
+                              //"timezone(nie:contentCreated(?file)) "
                               "nfo:model(nfo:equipment(?file)) "
                               "nmm:season(?file) "
                               "nmm:episodeNumber(?file) "
@@ -937,14 +1018,14 @@ check_metadata_for_selection (NautilusBatchRenameDialog *dialog,
 
                 metadata = g_new (FileMetadata, 1);
                 metadata->file_name = g_string_new (file_name);
-                metadata->creation_date = g_string_new ("");
-                metadata->equipment = g_string_new ("");
-                metadata->season = g_string_new ("");
-                metadata->episode_number = g_string_new ("");
-                metadata->track_number = g_string_new ("");
-                metadata->artist_name = g_string_new ("");
-                metadata->title = g_string_new ("");
-                metadata->album_name = g_string_new ("");
+                metadata->creation_date = NULL;
+                metadata->equipment = NULL;
+                metadata->season = NULL;
+                metadata->episode_number = NULL;
+                metadata->track_number = NULL;
+                metadata->artist_name = NULL;
+                metadata->title = NULL;
+                metadata->album_name = NULL;
 
                 selection_metadata = g_list_append (selection_metadata, metadata);
 
diff --git a/src/resources/ui/nautilus-batch-rename-dialog.ui 
b/src/resources/ui/nautilus-batch-rename-dialog.ui
index 4e2de2f..6628abf 100644
--- a/src/resources/ui/nautilus-batch-rename-dialog.ui
+++ b/src/resources/ui/nautilus-batch-rename-dialog.ui
@@ -32,6 +32,7 @@
     </action-widgets>
     <child internal-child="vbox">
       <object class="GtkBox" id="vbox">
+        <property name="border-width">0</property>
         <child>
           <object class="GtkGrid" id="grid">
             <property name="visible">True</property>
diff --git a/src/resources/ui/nautilus-files-view-context-menus.ui 
b/src/resources/ui/nautilus-files-view-context-menus.ui
index b40d242..b2698dc 100644
--- a/src/resources/ui/nautilus-files-view-context-menus.ui
+++ b/src/resources/ui/nautilus-files-view-context-menus.ui
@@ -215,7 +215,7 @@
     </section>
     <section>
       <item>
-        <attribute name="label" translatable="yes">Rena_me</attribute>
+        <attribute name="label" translatable="yes">Rena_me…</attribute>
         <attribute name="action">view.rename</attribute>
       </item>
     </section>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]