[nautilus/wip/csoriano/batch-refactoring: 3/3] batch-rename-dialog: major refactoring
- From: Carlos Soriano Sánchez <csoriano src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/csoriano/batch-refactoring: 3/3] batch-rename-dialog: major refactoring
- Date: Fri, 9 Sep 2016 21:15:01 +0000 (UTC)
commit dfb5cfb05cfb93d07a461a9e8e09e648cd421140
Author: Carlos Soriano <csoriano gnome org>
Date: Fri Sep 9 23:09:08 2016 +0200
batch-rename-dialog: major refactoring
This is a refactoring that is difficult to split in several pieces.
This patch implements the following changes:
- Use loops instead of serie of if/elses.
- Use enums and static arrays to define a static serie of tag types
and properties.
- Use enums for ordering and retrieval of properties of tags instead of
searching.
- Merge common code.
- Extract common code in functions.
- Mark for translation some strings.
- Plug some leaks.
- Fix some free-after-free.
src/nautilus-batch-rename-dialog.c | 1450 ++++------------------
src/nautilus-batch-rename-dialog.h | 193 +++-
src/resources/ui/nautilus-batch-rename-dialog.ui | 6 +-
3 files changed, 397 insertions(+), 1252 deletions(-)
---
diff --git a/src/nautilus-batch-rename-dialog.c b/src/nautilus-batch-rename-dialog.c
index 9f3b80c..dfb4bb9 100644
--- a/src/nautilus-batch-rename-dialog.c
+++ b/src/nautilus-batch-rename-dialog.c
@@ -118,64 +118,18 @@ typedef struct
gint new_position;
/* if the tag was just added, then we shouldn't update it's position */
gboolean just_added;
+ TagConstants tag_constants;
} TagData;
-typedef struct
-{
- const gchar *action_target_name;
- const gchar *tag_text_represencation;
- const gchar *label;
-} TagConstants;
-
-typedef struct
-{
- const gchar *action_target_name;
- const gchar *label;
- const SortMode sort_mode;
-} SortConstants;
-
-static const SortConstants sorts_constants[] =
-{
- {
- "name-ascending",
- N_("Original Name (Ascending)"),
- ORIGINAL_ASCENDING,
- },
- {
- "name-descending",
- N_("Original Name (Descending)"),
- ORIGINAL_DESCENDING,
- },
- {
- "first-modified",
- N_("First Modified"),
- FIRST_MODIFIED,
- },
- {
- "last-modified",
- N_("Last Modified"),
- LAST_MODIFIED,
- },
- {
- "first-created",
- N_("First Created"),
- FIRST_CREATED,
- },
- {
- "last-created",
- N_("Last Created"),
- LAST_CREATED,
- },
-};
static void update_display_text (NautilusBatchRenameDialog *dialog);
G_DEFINE_TYPE (NautilusBatchRenameDialog, nautilus_batch_rename_dialog, GTK_TYPE_DIALOG);
static void
-add_numbering_order (GSimpleAction *action,
- GVariant *value,
- gpointer user_data)
+change_numbering_order (GSimpleAction *action,
+ GVariant *value,
+ gpointer user_data)
{
NautilusBatchRenameDialog *dialog;
const gchar *target_name;
@@ -194,6 +148,7 @@ add_numbering_order (GSimpleAction *action,
dialog->selection = nautilus_batch_rename_dialog_sort (dialog->selection,
sorts_constants[i].sort_mode,
NULL);
+ break;
}
}
@@ -205,33 +160,14 @@ add_numbering_order (GSimpleAction *action,
}
static void
-add_original_file_name_tag (GSimpleAction *action,
- GVariant *value,
- gpointer user_data)
+enable_action (NautilusBatchRenameDialog *self,
+ gchar *action_name)
{
- NautilusBatchRenameDialog *dialog;
- gint cursor_position;
- TagData *tag_data;
-
- dialog = NAUTILUS_BATCH_RENAME_DIALOG (user_data);
-
- g_object_get (dialog->name_entry, "cursor-position", &cursor_position, NULL);
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, ORIGINAL_FILE_NAME);
- tag_data->set = TRUE;
- tag_data->just_added = TRUE;
- tag_data->position = cursor_position;
-
- gtk_editable_insert_text (GTK_EDITABLE (dialog->name_entry),
- ORIGINAL_FILE_NAME,
- g_utf8_strlen (ORIGINAL_FILE_NAME, -1),
- &cursor_position);
-
- gtk_editable_set_position (GTK_EDITABLE (dialog->name_entry), cursor_position);
-
- gtk_entry_grab_focus_without_selecting (GTK_ENTRY (dialog->name_entry));
+ GAction *action;
- g_simple_action_set_enabled (G_SIMPLE_ACTION (action), FALSE);
+ action = g_action_map_lookup_action (G_ACTION_MAP (self->action_group),
+ action_name);
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
}
static void
@@ -246,149 +182,51 @@ disable_action (NautilusBatchRenameDialog *dialog,
}
static void
-add_metadata_tag (GSimpleAction *action,
- GVariant *value,
- gpointer user_data)
+add_tag (NautilusBatchRenameDialog *self,
+ TagConstants tag_constants)
{
- NautilusBatchRenameDialog *dialog;
- const gchar *action_name;
+ const gchar *translated_tag;
gint cursor_position;
TagData *tag_data;
- dialog = NAUTILUS_BATCH_RENAME_DIALOG (user_data);
-
- action_name = g_action_get_name (G_ACTION (action));
- g_object_get (dialog->name_entry, "cursor-position", &cursor_position, NULL);
-
- if (g_strrstr (action_name, "creation-date"))
- {
- tag_data = g_hash_table_lookup (dialog->tag_info_table, CREATION_DATE);
- tag_data->available = TRUE;
- tag_data->set = TRUE;
- tag_data->just_added = TRUE;
- tag_data->position = cursor_position;
-
- gtk_editable_insert_text (GTK_EDITABLE (dialog->name_entry),
- CREATION_DATE,
- g_utf8_strlen (CREATION_DATE, -1),
- &cursor_position);
- gtk_editable_set_position (GTK_EDITABLE (dialog->name_entry), cursor_position);
- disable_action (dialog, "add-creation-date-tag");
- }
-
- if (g_strrstr (action_name, "equipment"))
- {
- tag_data = g_hash_table_lookup (dialog->tag_info_table, CAMERA_MODEL);
- tag_data->available = TRUE;
- tag_data->set = TRUE;
- tag_data->just_added = TRUE;
- tag_data->position = cursor_position;
-
- gtk_editable_insert_text (GTK_EDITABLE (dialog->name_entry),
- CAMERA_MODEL,
- g_utf8_strlen (CAMERA_MODEL, -1),
- &cursor_position);
- gtk_editable_set_position (GTK_EDITABLE (dialog->name_entry), cursor_position);
- disable_action (dialog, "add-equipment-tag");
- }
-
- if (g_strrstr (action_name, "season"))
- {
- tag_data = g_hash_table_lookup (dialog->tag_info_table, SEASON_NUMBER);
- tag_data->available = TRUE;
- tag_data->set = TRUE;
- tag_data->just_added = TRUE;
- tag_data->position = cursor_position;
-
- gtk_editable_insert_text (GTK_EDITABLE (dialog->name_entry),
- SEASON_NUMBER,
- g_utf8_strlen (SEASON_NUMBER, -1),
- &cursor_position);
- gtk_editable_set_position (GTK_EDITABLE (dialog->name_entry), cursor_position);
- disable_action (dialog, "add-season-tag");
- }
-
- if (g_strrstr (action_name, "episode"))
- {
- tag_data = g_hash_table_lookup (dialog->tag_info_table, EPISODE_NUMBER);
- tag_data->available = TRUE;
- tag_data->set = TRUE;
- tag_data->just_added = TRUE;
- tag_data->position = cursor_position;
-
- gtk_editable_insert_text (GTK_EDITABLE (dialog->name_entry),
- EPISODE_NUMBER,
- g_utf8_strlen (EPISODE_NUMBER, -1),
- &cursor_position);
- gtk_editable_set_position (GTK_EDITABLE (dialog->name_entry), cursor_position);
- disable_action (dialog, "add-episode-tag");
- }
-
- if (g_strrstr (action_name, "track"))
- {
- tag_data = g_hash_table_lookup (dialog->tag_info_table, TRACK_NUMBER);
- tag_data->available = TRUE;
- tag_data->set = TRUE;
- tag_data->just_added = TRUE;
- tag_data->position = cursor_position;
-
- gtk_editable_insert_text (GTK_EDITABLE (dialog->name_entry),
- TRACK_NUMBER,
- g_utf8_strlen (TRACK_NUMBER, -1),
- &cursor_position);
- gtk_editable_set_position (GTK_EDITABLE (dialog->name_entry), cursor_position);
- disable_action (dialog, "add-track-number-tag");
- }
+ translated_tag = gettext (tag_constants.text_representation);
+ tag_data = g_hash_table_lookup (self->tag_info_table, translated_tag);
+ tag_data->available = TRUE;
+ tag_data->set = TRUE;
+ tag_data->just_added = TRUE;
+ tag_data->position = cursor_position;
- if (g_strrstr (action_name, "artist"))
- {
- tag_data = g_hash_table_lookup (dialog->tag_info_table, ARTIST_NAME);
- tag_data->available = TRUE;
- tag_data->set = TRUE;
- tag_data->just_added = TRUE;
- tag_data->position = cursor_position;
+ gtk_editable_insert_text (GTK_EDITABLE (self->name_entry),
+ translated_tag,
+ g_utf8_strlen (translated_tag, -1),
+ &cursor_position);
+ gtk_editable_set_position (GTK_EDITABLE (self->name_entry), cursor_position);
- gtk_editable_insert_text (GTK_EDITABLE (dialog->name_entry),
- ARTIST_NAME,
- g_utf8_strlen (ARTIST_NAME, -1),
- &cursor_position);
- gtk_editable_set_position (GTK_EDITABLE (dialog->name_entry), cursor_position);
- disable_action (dialog, "add-artist-name-tag");
- }
+ gtk_entry_grab_focus_without_selecting (GTK_ENTRY (self->name_entry));
+}
- if (g_strrstr (action_name, "title"))
- {
- tag_data = g_hash_table_lookup (dialog->tag_info_table, TITLE);
- tag_data->available = TRUE;
- tag_data->set = TRUE;
- tag_data->just_added = TRUE;
- tag_data->position = cursor_position;
+static void
+add_metadata_tag (GSimpleAction *action,
+ GVariant *value,
+ gpointer user_data)
+{
+ NautilusBatchRenameDialog *self;
+ const gchar *action_name;
+ guint i;
- gtk_editable_insert_text (GTK_EDITABLE (dialog->name_entry),
- TITLE,
- g_utf8_strlen (TITLE, -1),
- &cursor_position);
- gtk_editable_set_position (GTK_EDITABLE (dialog->name_entry), cursor_position);
- disable_action (dialog, "add-title-tag");
- }
+ self = NAUTILUS_BATCH_RENAME_DIALOG (user_data);
+ action_name = g_action_get_name (G_ACTION (action));
- if (g_strrstr (action_name, "album"))
+ for (i = 0; i < G_N_ELEMENTS (metadata_tags_constants); i++)
{
- tag_data = g_hash_table_lookup (dialog->tag_info_table, ALBUM_NAME);
- tag_data->available = TRUE;
- tag_data->set = TRUE;
- tag_data->just_added = TRUE;
- tag_data->position = cursor_position;
+ if (g_strcmp0 (metadata_tags_constants[i].action_name, action_name) == 0)
+ {
+ add_tag (self, metadata_tags_constants[i]);
+ disable_action (self, metadata_tag_constants[i].action_name);
- gtk_editable_insert_text (GTK_EDITABLE (dialog->name_entry),
- ALBUM_NAME,
- g_utf8_strlen (ALBUM_NAME, -1),
- &cursor_position);
- gtk_editable_set_position (GTK_EDITABLE (dialog->name_entry), cursor_position);
- disable_action (dialog, "add-album-name-tag");
+ break;
+ }
}
-
- gtk_entry_grab_focus_without_selecting (GTK_ENTRY (dialog->name_entry));
}
static void
@@ -396,80 +234,32 @@ add_numbering_tag (GSimpleAction *action,
GVariant *value,
gpointer user_data)
{
- NautilusBatchRenameDialog *dialog;
+ NautilusBatchRenameDialog *self;
const gchar *action_name;
- gint cursor_position;
- GAction *add_numbering_action;
- TagData *tag_data;
-
- dialog = NAUTILUS_BATCH_RENAME_DIALOG (user_data);
+ guint i;
+ self = NAUTILUS_BATCH_RENAME_DIALOG (user_data);
action_name = g_action_get_name (G_ACTION (action));
- g_object_get (dialog->name_entry, "cursor-position", &cursor_position, NULL);
-
- if (g_strrstr (action_name, "zero"))
- {
- tag_data = g_hash_table_lookup (dialog->tag_info_table, NUMBERING);
- tag_data->set = TRUE;
- tag_data->just_added = TRUE;
- tag_data->position = cursor_position;
-
- gtk_editable_insert_text (GTK_EDITABLE (dialog->name_entry),
- NUMBERING,
- g_utf8_strlen (NUMBERING, -1),
- &cursor_position);
- gtk_editable_set_position (GTK_EDITABLE (dialog->name_entry), cursor_position);
- }
-
- if (g_strrstr (action_name, "one"))
- {
- tag_data = g_hash_table_lookup (dialog->tag_info_table, NUMBERING0);
- tag_data->set = TRUE;
- tag_data->just_added = TRUE;
- tag_data->position = cursor_position;
-
- gtk_editable_insert_text (GTK_EDITABLE (dialog->name_entry),
- NUMBERING0,
- g_utf8_strlen (NUMBERING0, -1),
- &cursor_position);
- gtk_editable_set_position (GTK_EDITABLE (dialog->name_entry), cursor_position);
- }
- if (g_strrstr (action_name, "two"))
+ for (i = 0; i < G_N_ELEMENTS (numbering_tags_constants); i++)
{
- tag_data = g_hash_table_lookup (dialog->tag_info_table, NUMBERING00);
- tag_data->set = TRUE;
- tag_data->just_added = TRUE;
- tag_data->position = cursor_position;
-
- gtk_editable_insert_text (GTK_EDITABLE (dialog->name_entry),
- NUMBERING00,
- g_utf8_strlen (NUMBERING00, -1),
- &cursor_position);
- gtk_editable_set_position (GTK_EDITABLE (dialog->name_entry), cursor_position);
+ if (g_strcmp0 (numbering_tags_constants[i].action_name, action_name) == 0)
+ {
+ add_tag (self, numbering_tags_constants[i]);
+ }
+ /* We want to allow only one tag of numbering type, so we disable all
+ * of them */
+ disable_action (self, numbering_tag_constants[i].action_name);
}
-
- add_numbering_action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
- "add-numbering-tag-zero");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (add_numbering_action), FALSE);
- add_numbering_action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
- "add-numbering-tag-one");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (add_numbering_action), FALSE);
-
- add_numbering_action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
- "add-numbering-tag-two");
- g_simple_action_set_enabled (G_SIMPLE_ACTION (add_numbering_action), FALSE);
-
- gtk_entry_grab_focus_without_selecting (GTK_ENTRY (dialog->name_entry));
}
const GActionEntry dialog_entries[] =
{
- { "numbering-order-changed", NULL, "s", "'name-ascending'", add_numbering_order },
- { "add-original-file-name-tag", add_original_file_name_tag },
- { "add-numbering-tag-zero", add_numbering_tag },
- { "add-numbering-tag-one", add_numbering_tag },
- { "add-numbering-tag-two", add_numbering_tag },
+ { "numbering-order-changed", NULL, "s", "'name-ascending'", change_numbering_order },
+ { "add-numbering-no-zero-pad-tag", add_numbering_tag },
+ { "add-numbering-one-zero-pad-tag", add_numbering_tag },
+ { "add-numbering-two-zero-pad-tag", add_numbering_tag },
+ { "add-original-file-name-tag", add_metadata_tag },
{ "add-creation-date-tag", add_metadata_tag },
{ "add-equipment-tag", add_metadata_tag },
{ "add-season-tag", add_metadata_tag },
@@ -543,105 +333,36 @@ compare_tag_position (gconstpointer a,
* For instance, "[1, 2, 3]Paris[Creation date]" would result in:
* "[1, 2, 3]", "Paris", "[Creation date]" */
static GList *
-split_entry_text (NautilusBatchRenameDialog *dialog,
+split_entry_text (NautilusBatchRenameDialog *self,
gchar *entry_text)
{
GString *normal_text;
GString *tag;
GArray *tag_positions;
+ g_autoptr (GList) tag_info_keys = NULL;
+ GList *l;
gint tags;
gint i;
gchar *substring;
gint tag_end_position;
GList *result = NULL;
TagData *tag_data;
+ gchar *translated_tag;
tags = 0;
tag_end_position = 0;
tag_positions = g_array_new (FALSE, FALSE, sizeof (gint));
- tag_data = g_hash_table_lookup (dialog->tag_info_table, NUMBERING);
- if (tag_data->set)
- {
- g_array_append_val (tag_positions, tag_data->position);
- tags++;
- }
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, NUMBERING0);
- if (tag_data->set)
- {
- g_array_append_val (tag_positions, tag_data->position);
- tags++;
- }
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, NUMBERING00);
- if (tag_data->set)
- {
- g_array_append_val (tag_positions, tag_data->position);
- tags++;
- }
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, ORIGINAL_FILE_NAME);
- if (tag_data->set)
- {
- g_array_append_val (tag_positions, tag_data->position);
- tags++;
- }
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, CREATION_DATE);
- if (tag_data->set)
- {
- g_array_append_val (tag_positions, tag_data->position);
- tags++;
- }
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, CAMERA_MODEL);
- if (tag_data->set)
- {
- g_array_append_val (tag_positions, tag_data->position);
- tags++;
- }
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, SEASON_NUMBER);
- if (tag_data->set)
- {
- g_array_append_val (tag_positions, tag_data->position);
- tags++;
- }
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, EPISODE_NUMBER);
- if (tag_data->set)
- {
- g_array_append_val (tag_positions, tag_data->position);
- tags++;
- }
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, TRACK_NUMBER);
- if (tag_data->set)
- {
- g_array_append_val (tag_positions, tag_data->position);
- tags++;
- }
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, ARTIST_NAME);
- if (tag_data->set)
- {
- g_array_append_val (tag_positions, tag_data->position);
- tags++;
- }
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, TITLE);
- if (tag_data->set)
- {
- g_array_append_val (tag_positions, tag_data->position);
- tags++;
- }
+ tag_info_keys = g_hash_table_get_keys (self->tag_info_table);
- tag_data = g_hash_table_lookup (dialog->tag_info_table, ALBUM_NAME);
- if (tag_data->set)
+ for (l = tag_info_keys; l != NULL; l = l->next)
{
- g_array_append_val (tag_positions, tag_data->position);
- tags++;
+ tag_data = g_hash_table_lookup (self->tag_info_table, l->data);
+ if (tag_data->set)
+ {
+ g_array_append_val (tag_positions, tag_data->position);
+ tags++;
+ }
}
g_array_sort (tag_positions, compare_tag_position);
@@ -660,96 +381,23 @@ split_entry_text (NautilusBatchRenameDialog *dialog,
result = g_list_prepend (result, normal_text);
}
- tag_data = g_hash_table_lookup (dialog->tag_info_table, ORIGINAL_FILE_NAME);
- if (tag_data->set && g_array_index (tag_positions, gint, i) == tag_data->position)
+ for (l = tag_info_keys; l != NULL; l = l->next)
{
- tag_end_position = g_array_index (tag_positions, gint, i) +
- g_utf8_strlen (ORIGINAL_FILE_NAME, -1);
- tag = g_string_append (tag, ORIGINAL_FILE_NAME);
- }
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, NUMBERING);
- if (tag_data->set && g_array_index (tag_positions, gint, i) == tag_data->position)
- {
- tag_end_position = g_array_index (tag_positions, gint, i) +
- g_utf8_strlen (NUMBERING, -1);
- tag = g_string_append (tag, NUMBERING);
- }
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, NUMBERING0);
- if (tag_data->set && g_array_index (tag_positions, gint, i) == tag_data->position)
- {
- tag_end_position = g_array_index (tag_positions, gint, i) +
- g_utf8_strlen (NUMBERING0, -1);
- tag = g_string_append (tag, NUMBERING0);
- }
+ tag_data = g_hash_table_lookup (self->tag_info_table, l->data);
+ if (tag_data->set && g_array_index (tag_positions, gint, i) == tag_data->position)
+ {
+ translated_tag = gettext (tad_data->tag_constants.text_representation);
+ tag_end_position = g_array_index (tag_positions, gint, i) +
+ g_utf8_strlen (translated_tag, -1);
+ tag = g_string_append (tag, translated_tag);
- tag_data = g_hash_table_lookup (dialog->tag_info_table, NUMBERING00);
- if (tag_data->set && g_array_index (tag_positions, gint, i) == tag_data->position)
- {
- tag_end_position = g_array_index (tag_positions, gint, i) +
- g_utf8_strlen (NUMBERING00, -1);
- tag = g_string_append (tag, NUMBERING00);
- }
- tag_data = g_hash_table_lookup (dialog->tag_info_table, CREATION_DATE);
- if (tag_data->set && g_array_index (tag_positions, gint, i) == tag_data->position)
- {
- tag_end_position = g_array_index (tag_positions, gint, i) +
- g_utf8_strlen (CREATION_DATE, -1);
- tag = g_string_append (tag, CREATION_DATE);
- }
- tag_data = g_hash_table_lookup (dialog->tag_info_table, CAMERA_MODEL);
- if (tag_data->set && g_array_index (tag_positions, gint, i) == tag_data->position)
- {
- tag_end_position = g_array_index (tag_positions, gint, i) +
- g_utf8_strlen (CAMERA_MODEL, -1);
- tag = g_string_append (tag, CAMERA_MODEL);
- }
- tag_data = g_hash_table_lookup (dialog->tag_info_table, SEASON_NUMBER);
- if (tag_data->set && g_array_index (tag_positions, gint, i) == tag_data->position)
- {
- tag_end_position = g_array_index (tag_positions, gint, i) +
- g_utf8_strlen (SEASON_NUMBER, -1);
- tag = g_string_append (tag, SEASON_NUMBER);
- }
- tag_data = g_hash_table_lookup (dialog->tag_info_table, EPISODE_NUMBER);
- if (tag_data->set && g_array_index (tag_positions, gint, i) == tag_data->position)
- {
- tag_end_position = g_array_index (tag_positions, gint, i) +
- g_utf8_strlen (EPISODE_NUMBER, -1);
- tag = g_string_append (tag, EPISODE_NUMBER);
- }
- tag_data = g_hash_table_lookup (dialog->tag_info_table, TRACK_NUMBER);
- if (tag_data->set && g_array_index (tag_positions, gint, i) == tag_data->position)
- {
- tag_end_position = g_array_index (tag_positions, gint, i) +
- g_utf8_strlen (TRACK_NUMBER, -1);
- tag = g_string_append (tag, TRACK_NUMBER);
- }
- tag_data = g_hash_table_lookup (dialog->tag_info_table, ARTIST_NAME);
- if (tag_data->set && g_array_index (tag_positions, gint, i) == tag_data->position)
- {
- tag_end_position = g_array_index (tag_positions, gint, i) +
- g_utf8_strlen (ARTIST_NAME, -1);
- tag = g_string_append (tag, ARTIST_NAME);
- }
- tag_data = g_hash_table_lookup (dialog->tag_info_table, TITLE);
- if (tag_data->set && g_array_index (tag_positions, gint, i) == tag_data->position)
- {
- tag_end_position = g_array_index (tag_positions, gint, i) +
- g_utf8_strlen (TITLE, -1);
- tag = g_string_append (tag, TITLE);
- }
- tag_data = g_hash_table_lookup (dialog->tag_info_table, ALBUM_NAME);
- if (tag_data->set && g_array_index (tag_positions, gint, i) == tag_data->position)
- {
- tag_end_position = g_array_index (tag_positions, gint, i) +
- g_utf8_strlen (ALBUM_NAME, -1);
- tag = g_string_append (tag, ALBUM_NAME);
+ break;
+ }
}
result = g_list_prepend (result, tag);
}
+
normal_text = g_string_new (g_utf8_offset_to_pointer (entry_text, tag_end_position));
if (g_strcmp0 (normal_text->str, "") != 0)
@@ -1708,6 +1356,7 @@ update_tags (NautilusBatchRenameDialog *dialog)
{
TagData *tag_data;
const gchar *entry_text;
+ g_autoptr (GList) tag_info_keys = NULL;
gint character_difference;
gint cursor_position;
@@ -1725,165 +1374,26 @@ update_tags (NautilusBatchRenameDialog *dialog)
gtk_editable_set_position (GTK_EDITABLE (dialog->name_entry),
g_utf8_strlen (entry_text, -1));
}
-
+\
g_object_get (dialog->name_entry, "cursor-position", &cursor_position, NULL);
character_difference = g_utf8_strlen (entry_text, -1) - dialog->name_entry_characters;
dialog->name_entry_characters = g_utf8_strlen (entry_text, -1);
- tag_data = g_hash_table_lookup (dialog->tag_info_table, ORIGINAL_FILE_NAME);
- if (tag_data->just_added)
- {
- tag_data->just_added = FALSE;
- }
- else
- {
- if (tag_data->set && cursor_position <= tag_data->position)
- {
- tag_data->position += character_difference;
- }
- }
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, CREATION_DATE);
- if (tag_data->just_added)
+ tag_info_keys = g_hash_table_get_keys (self->tag_info_table);
+ for (l = tag_info_keys; l != NULL; l = l->next)
{
- tag_data->just_added = FALSE;
- }
- else
- {
- if (tag_data->set && cursor_position <= tag_data->position)
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, l->data);
+ if (tag_data->just_added)
{
- tag_data->position += character_difference;
+ tag_data->just_added = FALSE;
}
- }
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, CAMERA_MODEL);
- if (tag_data->just_added)
- {
- tag_data->just_added = FALSE;
- }
- else
- {
- if (tag_data->set && cursor_position <= tag_data->position)
- {
- tag_data->position += character_difference;
- }
- }
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, SEASON_NUMBER);
- if (tag_data->just_added)
- {
- tag_data->just_added = FALSE;
- }
- else
- {
- if (tag_data->set && cursor_position <= tag_data->position)
- {
- tag_data->position += character_difference;
- }
- }
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, EPISODE_NUMBER);
- if (tag_data->just_added)
- {
- tag_data->just_added = FALSE;
- }
- else
- {
- if (tag_data->set && cursor_position <= tag_data->position)
- {
- tag_data->position += character_difference;
- }
- }
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, TRACK_NUMBER);
- if (tag_data->just_added)
- {
- tag_data->just_added = FALSE;
- }
- else
- {
- if (tag_data->set && cursor_position <= tag_data->position)
- {
- tag_data->position += character_difference;
- }
- }
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, ARTIST_NAME);
- if (tag_data->just_added)
- {
- tag_data->just_added = FALSE;
- }
- else
- {
- if (tag_data->set && cursor_position <= tag_data->position)
- {
- tag_data->position += character_difference;
- }
- }
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, TITLE);
- if (tag_data->just_added)
- {
- tag_data->just_added = FALSE;
- }
- else
- {
- if (tag_data->set && cursor_position <= tag_data->position)
- {
- tag_data->position += character_difference;
- }
- }
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, ALBUM_NAME);
- if (tag_data->just_added)
- {
- tag_data->just_added = FALSE;
- }
- else
- {
- if (tag_data->set && cursor_position <= tag_data->position)
- {
- tag_data->position += character_difference;
- }
- }
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, NUMBERING);
- if (tag_data->just_added)
- {
- tag_data->just_added = FALSE;
- }
- else
- {
- if (tag_data->set && cursor_position <= tag_data->position)
- {
- tag_data->position += character_difference;
- }
- }
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, NUMBERING0);
- if (tag_data->just_added)
- {
- tag_data->just_added = FALSE;
- }
- else
- {
- if (tag_data->set && cursor_position <= tag_data->position)
- {
- tag_data->position += character_difference;
- }
- }
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, NUMBERING00);
- if (tag_data->just_added)
- {
- tag_data->just_added = FALSE;
- }
- else
- {
- if (tag_data->set && cursor_position <= tag_data->position)
+ else
{
- tag_data->position += character_difference;
+ if (tag_data->set && cursor_position <= tag_data->position)
+ {
+ tag_data->position += character_difference;
+ }
}
}
}
@@ -1902,8 +1412,6 @@ have_unallowed_character (NautilusBatchRenameDialog *dialog)
have_unallowed_character_dot = FALSE;
have_unallowed_character_dotdot = FALSE;
-
-
if (dialog->mode == NAUTILUS_BATCH_RENAME_DIALOG_FORMAT)
{
entry_text = gtk_entry_get_text (GTK_ENTRY (dialog->name_entry));
@@ -1990,17 +1498,29 @@ have_unallowed_character (NautilusBatchRenameDialog *dialog)
}
}
-static void
-update_display_text (NautilusBatchRenameDialog *dialog)
+static gboolean
+numbering_tag_is_some_added (NautilusBatchRenameDialog *self)
{
+ guint i;
+ const gchar *translated_tag;
TagData *tag_data;
- TagData *tag_data0;
- TagData *tag_data00;
- tag_data = g_hash_table_lookup (dialog->tag_info_table, NUMBERING);
- tag_data0 = g_hash_table_lookup (dialog->tag_info_table, NUMBERING0);
- tag_data00 = g_hash_table_lookup (dialog->tag_info_table, NUMBERING00);
+ for (i = 0; i < G_N_ELEMENTS (numbering_tags_constants); i++)
+ {
+ translated_tag = gettext (numbering_tags_constants[i].text_representation);
+ tag_data = g_hash_table_lookup (self->tag_info_table, translated_tag);
+ if (tag_data->set)
+ {
+ return TRUE
+ }
+ }
+
+ return FALSE;
+}
+static void
+update_display_text (NautilusBatchRenameDialog *dialog)
+{
if (dialog->conflict_cancellable != NULL)
{
g_cancellable_cancel (dialog->conflict_cancellable);
@@ -2024,7 +1544,7 @@ update_display_text (NautilusBatchRenameDialog *dialog)
g_list_free_full (dialog->new_names, string_free);
}
- if (!tag_data->set && !tag_data0->set && !tag_data00->set)
+ if (numbering_tag_is_some_added (dialog))
{
gtk_label_set_label (GTK_LABEL (dialog->numbering_label), "");
gtk_widget_hide (dialog->numbering_order_button);
@@ -2121,8 +1641,11 @@ nautilus_batch_rename_dialog_query_finished (NautilusBatchRenameDialog *dialog,
{
GMenuItem *first_created;
GMenuItem *last_created;
- FileMetadata *metadata;
+ FileMetadata *file_metadata;
+ MetadataType metadata_type;
+ gboolean is_metadata;
TagData *tag_data;
+ g_autoptr (GList) tag_info_keys = NULL;
/* for files with no metadata */
if (hash_table != NULL && g_hash_table_size (hash_table) == 0)
@@ -2155,94 +1678,29 @@ nautilus_batch_rename_dialog_query_finished (NautilusBatchRenameDialog *dialog,
}
dialog->selection_metadata = selection_metadata;
- metadata = selection_metadata->data;
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, CREATION_DATE);
- if (metadata->creation_date == NULL || g_strcmp0 (metadata->creation_date->str, "") == 0)
- {
- disable_action (dialog, "add-creation-date-tag");
- tag_data->available = FALSE;
- }
- else
- {
- tag_data->set = FALSE;
- }
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, CAMERA_MODEL);
- if (metadata->equipment == NULL || g_strcmp0 (metadata->equipment->str, "") == 0)
- {
- disable_action (dialog, "add-equipment-tag");
- tag_data->available = FALSE;
- }
- else
- {
- tag_data->set = FALSE;
- }
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, SEASON_NUMBER);
- if (metadata->season == NULL || g_strcmp0 (metadata->season->str, "") == 0)
- {
- disable_action (dialog, "add-season-tag");
- tag_data->available = FALSE;
- }
- else
- {
- tag_data->set = FALSE;
- }
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, EPISODE_NUMBER);
- if (metadata->episode_number == NULL || g_strcmp0 (metadata->episode_number->str, "") == 0)
- {
- disable_action (dialog, "add-episode-tag");
- tag_data->available = FALSE;
- }
- else
- {
- tag_data->set = FALSE;
- }
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, TRACK_NUMBER);
- if (metadata->track_number == NULL || g_strcmp0 (metadata->track_number->str, "") == 0)
- {
- disable_action (dialog, "add-track-number-tag");
- tag_data->available = FALSE;
- }
- else
- {
- tag_data->set = FALSE;
- }
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, ARTIST_NAME);
- if (metadata->artist_name == NULL || g_strcmp0 (metadata->artist_name->str, "") == 0)
+ file_metadata = selection_metadata->data;
+ tag_info_keys = g_hash_table_get_keys (self->tag_info_table);
+ for (l = tag_info_keys; l != NULL; l = l->next)
{
- disable_action (dialog, "add-artist-name-tag");
- tag_data->available = FALSE;
- }
- else
- {
- tag_data->set = FALSE;
- }
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, TITLE);
- if (metadata->title == NULL || g_strcmp0 (metadata->title->str, "") == 0)
- {
- disable_action (dialog, "add-title-tag");
- tag_data->available = FALSE;
- }
- else
- {
- tag_data->set = FALSE;
- }
+ /* Only metadata has to be handled here. */
+ is_metadata = tag_data->tag_constants.is_metadata;
+ if (!is_metadata)
+ {
+ continue;
+ }
- tag_data = g_hash_table_lookup (dialog->tag_info_table, ALBUM_NAME);
- if (metadata->album_name == NULL || g_strcmp0 (metadata->album_name->str, "") == 0)
- {
- disable_action (dialog, "add-album-name-tag");
- tag_data->available = FALSE;
- }
- else
- {
- tag_data->set = FALSE;
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, l->data);
+ metadata_type = tag_data->tag_constants.metadata_type;
+ if (file_metadata->metadata[metadata_type] == NULL ||
+ g_strcmp0 (file_metadata->metadata[metadata_type], "") == 0)
+ {
+ disable_action (dialog, tag_data->tag_constants.action_name);
+ tag_data->available = FALSE;
+ }
+ else
+ {
+ tag_data->set = FALSE;
+ }
}
}
@@ -2359,7 +1817,7 @@ nautilus_batch_rename_dialog_initialize_actions (NautilusBatchRenameDialog *dial
G_ACTION_GROUP (dialog->action_group));
action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
- "add-original-file-name-tag");
+ metadata_tags_constants[ORIGINAL_FILE_NAME].action_name);
g_simple_action_set_enabled (G_SIMPLE_ACTION (action), FALSE);
check_metadata_for_selection (dialog, dialog->selection);
@@ -2388,9 +1846,7 @@ remove_tag (NautilusBatchRenameDialog *dialog,
delete_tag = FALSE;
g_object_get (dialog->name_entry, "cursor-position", &cursor_position, NULL);
-
tag_data = g_hash_table_lookup (dialog->tag_info_table, tag_name);
-
entry_text = g_string_new (gtk_entry_get_text (GTK_ENTRY (dialog->name_entry)));
if (!tag_data->set)
@@ -2536,15 +1992,15 @@ on_key_press_event (GtkWidget *widget,
gint end;
gboolean tag_removed = FALSE;
TagData *tag_data;
+ const gchar *translated_tag;
+ gchar *action_name;
gint minimum_tag_position;
GAction *action;
gdk_event = (GdkEvent *) event;
-
dialog = NAUTILUS_BATCH_RENAME_DIALOG (user_data);
-
keyval = event->keyval;
-
+ tag_info_keys = g_hash_table_get_keys (self->tag_info_table);
entry_has_selection = (gtk_editable_get_selection_bounds (GTK_EDITABLE (dialog->name_entry),
&start,
&end));
@@ -2554,6 +2010,7 @@ on_key_press_event (GtkWidget *widget,
return GDK_EVENT_PROPAGATE;
}
+
if (entry_has_selection &&
((keyval == GDK_KEY_Delete || keyval == GDK_KEY_BackSpace) ||
(!gdk_event->key.is_modifier &&
@@ -2569,317 +2026,43 @@ on_key_press_event (GtkWidget *widget,
minimum_tag_position = G_MAXINT;
- tag_data = g_hash_table_lookup (dialog->tag_info_table, ORIGINAL_FILE_NAME);
- if (tag_data->set)
- {
- update_tag_position (dialog, ORIGINAL_FILE_NAME, old_entry_text);
- new_entry_text = remove_tag_selection (dialog,
- old_entry_text,
- "add-original-file-name-tag",
- ORIGINAL_FILE_NAME,
- start,
- end);
-
- if (!g_string_equal (new_entry_text, old_entry_text))
- {
- if (tag_data->position < minimum_tag_position)
- {
- minimum_tag_position = tag_data->position;
- }
-
- tag_removed = TRUE;
- }
- g_string_free (old_entry_text, TRUE);
- old_entry_text = new_entry_text;
- }
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, CREATION_DATE);
- if (tag_data->set)
- {
- update_tag_position (dialog, CREATION_DATE, old_entry_text);
- new_entry_text = remove_tag_selection (dialog,
- old_entry_text,
- "add-creation-date-tag",
- CREATION_DATE,
- start,
- end);
-
- if (!g_string_equal (new_entry_text, old_entry_text))
- {
- if (tag_data->position < minimum_tag_position)
- {
- minimum_tag_position = tag_data->position;
- }
-
- tag_removed = TRUE;
- }
-
- g_string_free (old_entry_text, TRUE);
- old_entry_text = new_entry_text;
- }
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, NUMBERING);
- if (tag_data->set)
- {
- update_tag_position (dialog, NUMBERING, old_entry_text);
- new_entry_text = remove_tag_selection (dialog,
- old_entry_text,
- "add-numbering-tag-zero",
- NUMBERING,
- start,
- end);
-
- 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 (!g_string_equal (new_entry_text, old_entry_text))
- {
- if (tag_data->position < minimum_tag_position)
- {
- minimum_tag_position = tag_data->position;
- }
-
- tag_removed = TRUE;
- }
- g_string_free (old_entry_text, TRUE);
- old_entry_text = new_entry_text;
- }
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, NUMBERING0);
- if (tag_data->set)
- {
- update_tag_position (dialog, NUMBERING0, old_entry_text);
- new_entry_text = remove_tag_selection (dialog,
- old_entry_text,
- "add-numbering-tag-one",
- NUMBERING0,
- start,
- end);
-
- 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 (!g_string_equal (new_entry_text, old_entry_text))
- {
- if (tag_data->position < minimum_tag_position)
- {
- minimum_tag_position = tag_data->position;
- }
-
- tag_removed = TRUE;
- }
- g_string_free (old_entry_text, TRUE);
- old_entry_text = new_entry_text;
- }
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, NUMBERING00);
- if (tag_data->set)
- {
- update_tag_position (dialog, NUMBERING00, old_entry_text);
- new_entry_text = remove_tag_selection (dialog,
- old_entry_text,
- "add-numbering-tag-two",
- NUMBERING0,
- start,
- end);
-
- 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 (!g_string_equal (new_entry_text, old_entry_text))
- {
- if (tag_data->position < minimum_tag_position)
- {
- minimum_tag_position = tag_data->position;
- }
-
- tag_removed = TRUE;
- }
- g_string_free (old_entry_text, TRUE);
- old_entry_text = new_entry_text;
- }
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, CAMERA_MODEL);
- if (tag_data->set)
- {
- update_tag_position (dialog, CAMERA_MODEL, old_entry_text);
- new_entry_text = remove_tag_selection (dialog,
- old_entry_text,
- "add-equipment-tag",
- CAMERA_MODEL,
- start,
- end);
-
- if (!g_string_equal (new_entry_text, old_entry_text))
- {
- if (tag_data->position < minimum_tag_position)
- {
- minimum_tag_position = tag_data->position;
- }
-
- tag_removed = TRUE;
- }
- g_string_free (old_entry_text, TRUE);
- old_entry_text = new_entry_text;
- }
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, TRACK_NUMBER);
- if (tag_data->set)
- {
- update_tag_position (dialog, TRACK_NUMBER, old_entry_text);
- new_entry_text = remove_tag_selection (dialog,
- old_entry_text,
- "add-track-number-tag",
- TRACK_NUMBER,
- start,
- end);
-
- if (!g_string_equal (new_entry_text, old_entry_text))
- {
- if (tag_data->position < minimum_tag_position)
- {
- minimum_tag_position = tag_data->position;
- }
-
- tag_removed = TRUE;
- }
- g_string_free (old_entry_text, TRUE);
- old_entry_text = new_entry_text;
- }
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, SEASON_NUMBER);
- if (tag_data->set)
- {
- update_tag_position (dialog, SEASON_NUMBER, old_entry_text);
- new_entry_text = remove_tag_selection (dialog,
- old_entry_text,
- "add-season-tag",
- SEASON_NUMBER,
- start,
- end);
-
- if (!g_string_equal (new_entry_text, old_entry_text))
- {
- if (tag_data->position < minimum_tag_position)
- {
- minimum_tag_position = tag_data->position;
- }
-
- tag_removed = TRUE;
- }
- g_string_free (old_entry_text, TRUE);
- old_entry_text = new_entry_text;
- }
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, EPISODE_NUMBER);
- if (tag_data->set)
+ for (l = tag_info_keys; l != NULL; l = l->next)
{
- update_tag_position (dialog, EPISODE_NUMBER, old_entry_text);
- new_entry_text = remove_tag_selection (dialog,
- old_entry_text,
- "add-episode-tag",
- EPISODE_NUMBER,
- start,
- end);
-
- if (!g_string_equal (new_entry_text, old_entry_text))
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, l->data);
+ translated_tag = gettext (tag_data->tag_constants.text_representation);
+ if (tag_data->set)
{
- if (tag_data->position < minimum_tag_position)
+ update_tag_position (dialog, translated_tag, old_entry_text);
+ new_entry_text = remove_tag_selection (dialog,
+ old_entry_text,
+ tag_data->tag_constants.action_name,
+ translated_tag,
+ start,
+ end);
+
+ if (!g_string_equal (new_entry_text, old_entry_text))
{
- minimum_tag_position = tag_data->position;
- }
+ if (tag_data->position < minimum_tag_position)
+ {
+ minimum_tag_position = tag_data->position;
+ }
- tag_removed = TRUE;
- }
- g_string_free (old_entry_text, TRUE);
- old_entry_text = new_entry_text;
- }
-
- tag_data = g_hash_table_lookup (dialog->tag_info_table, ARTIST_NAME);
- if (tag_data->set)
- {
- update_tag_position (dialog, ARTIST_NAME, old_entry_text);
- new_entry_text = remove_tag_selection (dialog,
- old_entry_text,
- "add-artist-name-tag",
- ARTIST_NAME,
- start,
- end);
-
- if (!g_string_equal (new_entry_text, old_entry_text))
- {
- if (tag_data->position < minimum_tag_position)
- {
- minimum_tag_position = tag_data->position;
+ tag_removed = TRUE;
}
-
- tag_removed = TRUE;
+ g_string_free (old_entry_text, TRUE);
+ old_entry_text = new_entry_text;
}
- g_string_free (old_entry_text, TRUE);
- old_entry_text = new_entry_text;
}
- tag_data = g_hash_table_lookup (dialog->tag_info_table, TITLE);
- if (tag_data->set)
+ /* If we removed the numbering tag, we want to enable all numbering actions */
+ if (!numbering_tag_is_some_added (dialog))
{
- update_tag_position (dialog, TITLE, old_entry_text);
- new_entry_text = remove_tag_selection (dialog,
- old_entry_text,
- "add-title-tag",
- TITLE,
- start,
- end);
-
- if (!g_string_equal (new_entry_text, old_entry_text))
- {
- if (tag_data->position < minimum_tag_position)
- {
- minimum_tag_position = tag_data->position;
- }
-
- tag_removed = TRUE;
- }
- g_string_free (old_entry_text, TRUE);
- old_entry_text = new_entry_text;
- }
+ guint i;
- tag_data = g_hash_table_lookup (dialog->tag_info_table, ALBUM_NAME);
- if (tag_data->set)
- {
- update_tag_position (dialog, ALBUM_NAME, old_entry_text);
- new_entry_text = remove_tag_selection (dialog,
- old_entry_text,
- "add-album-name-tag",
- ALBUM_NAME,
- start,
- end);
-
- if (!g_string_equal (new_entry_text, old_entry_text))
+ for (i = 0; i < G_N_ELEMENTS (numbering_tags_constants); i++)
{
- if (tag_data->position < minimum_tag_position)
- {
- minimum_tag_position = tag_data->position;
- }
-
- tag_removed = TRUE;
+ enable_action (dialog, numbering_tags_constants[i].action_name);
}
- g_string_free (old_entry_text, TRUE);
- old_entry_text = new_entry_text;
}
if (minimum_tag_position != G_MAXINT)
@@ -2894,148 +2077,38 @@ on_key_press_event (GtkWidget *widget,
g_string_free (new_entry_text, TRUE);
}
-
- if ((keyval == GDK_KEY_Delete || keyval == GDK_KEY_BackSpace) &&
- tag_removed)
- {
- return GDK_EVENT_STOP;
- }
}
else
{
- if (remove_tag (dialog,
- ORIGINAL_FILE_NAME,
- "add-original-file-name-tag",
- keyval,
- gdk_event->key.is_modifier))
- {
- tag_removed = TRUE;
- }
-
- if (!tag_removed && remove_tag (dialog,
- CREATION_DATE,
- "add-creation-date-tag",
- keyval,
- gdk_event->key.is_modifier))
+ for (l = tag_info_keys; l != NULL; l = l->next)
{
- tag_removed = TRUE;
- }
-
- if (!tag_removed && remove_tag (dialog,
- NUMBERING,
- "add-numbering-tag-zero",
- 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 (!tag_removed && remove_tag (dialog,
- NUMBERING0,
- "add-numbering-tag-one",
- 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 (!tag_removed && remove_tag (dialog,
- NUMBERING00,
- "add-numbering-tag-two",
- 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 (!tag_removed && remove_tag (dialog,
- CAMERA_MODEL,
- "add-equipment-tag",
- keyval,
- gdk_event->key.is_modifier))
- {
- tag_removed = TRUE;
- }
-
- if (!tag_removed && remove_tag (dialog,
- SEASON_NUMBER,
- "add-season-tag",
- keyval,
- gdk_event->key.is_modifier))
- {
- tag_removed = TRUE;
- }
-
- if (!tag_removed && remove_tag (dialog,
- EPISODE_NUMBER,
- "add-episode-tag",
- keyval,
- gdk_event->key.is_modifier))
- {
- tag_removed = TRUE;
- }
-
- if (!tag_removed && remove_tag (dialog,
- TRACK_NUMBER,
- "add-track-number-tag",
- keyval,
- gdk_event->key.is_modifier))
- {
- tag_removed = TRUE;
- }
+ tag_data = g_hash_table_lookup (dialog->tag_info_table, l->data);
+ action_name = tag_data->tag_constants.action_name;
+ translated_tag = gettext (tag_data->tag_constants.text_representation);
+ if (remove_tag (dialog, translated_tag, action_name,
+ keyval, gdk_event->key.is_modifier))
+ {
+ tag_removed = TRUE;
- if (!tag_removed && remove_tag (dialog,
- ARTIST_NAME,
- "add-artist-name-tag",
- keyval,
- gdk_event->key.is_modifier))
- {
- tag_removed = TRUE;
+ break;
+ }
}
- if (!tag_removed && remove_tag (dialog,
- TITLE,
- "add-title-tag",
- keyval,
- gdk_event->key.is_modifier))
+ /* If we removed the numbering tag, we want to enable all numbering actions */
+ if (!numbering_tag_is_some_added (dialog))
{
- tag_removed = TRUE;
- }
+ guint i;
- if (!tag_removed && remove_tag (dialog,
- ALBUM_NAME,
- "add-album-name-tag",
- keyval,
- gdk_event->key.is_modifier))
- {
- tag_removed = TRUE;
+ for (i = 0; i < G_N_ELEMENTS (numbering_tags_constants); i++)
+ {
+ enable_action (dialog, numbering_tags_constants[i].action_name);
+ }
}
+ }
- if (tag_removed && (keyval == GDK_KEY_Delete || keyval == GDK_KEY_BackSpace))
- {
- return GDK_EVENT_STOP;
- }
+ if ((keyval == GDK_KEY_Delete || keyval == GDK_KEY_BackSpace) && tag_removed)
+ {
+ return GDK_EVENT_STOP;
}
return GDK_EVENT_PROPAGATE;
@@ -3046,6 +2119,7 @@ nautilus_batch_rename_dialog_finalize (GObject *object)
{
NautilusBatchRenameDialog *dialog;
GList *l;
+ guint i;
dialog = NAUTILUS_BATCH_RENAME_DIALOG (object);
@@ -3064,42 +2138,18 @@ nautilus_batch_rename_dialog_finalize (GObject *object)
for (l = dialog->selection_metadata; l != NULL; l = l->next)
{
- FileMetadata *metadata;
-
- metadata = l->data;
+ FileMetadata *file_metadata;
- if (metadata->file_name != NULL)
- {
- g_string_free (metadata->file_name, TRUE);
- }
- if (metadata->creation_date != NULL)
- {
- g_string_free (metadata->creation_date, TRUE);
- }
- if (metadata->equipment != NULL)
- {
- g_string_free (metadata->equipment, TRUE);
- }
- if (metadata->season != NULL)
- {
- g_string_free (metadata->season, TRUE);
- }
- if (metadata->episode_number != NULL)
- {
- g_string_free (metadata->episode_number, TRUE);
- }
- if (metadata->track_number != NULL)
- {
- g_string_free (metadata->track_number, TRUE);
- }
- if (metadata->artist_name != NULL)
- {
- g_string_free (metadata->artist_name, TRUE);
- }
- if (metadata->album_name != NULL)
+ file_metadata = l->data;
+ for (i = 0; i < G_N_ELEMENTS (file_metadata->metadata); i++)
{
- g_string_free (metadata->album_name, TRUE);
+ if (file_metadata->metadata[i] != NULL)
+ {
+ g_string_free (file_metadata->metadata[i], TRUE);
+ }
}
+
+ g_free (file_metadata);
}
if (dialog->create_date != NULL)
@@ -3205,6 +2255,7 @@ static void
nautilus_batch_rename_dialog_init (NautilusBatchRenameDialog *self)
{
TagData *tag_data;
+ const gchar *translated_tag;
gtk_widget_init_template (GTK_WIDGET (self));
@@ -3246,80 +2297,35 @@ nautilus_batch_rename_dialog_init (NautilusBatchRenameDialog *self)
g_str_equal,
(GDestroyNotify) g_free,
(GDestroyNotify) g_free);
- tag_data = g_new (TagData, 1);
- tag_data->available = TRUE;
- tag_data->set = TRUE;
- tag_data->position = 0;
- g_hash_table_insert (self->tag_info_table, g_strdup (ORIGINAL_FILE_NAME), tag_data);
- tag_data = g_new (TagData, 1);
- tag_data->available = TRUE;
- tag_data->set = FALSE;
- tag_data->position = 0;
- g_hash_table_insert (self->tag_info_table, g_strdup (NUMBERING), tag_data);
+ for (i = 0; i < G_N_ELEMENTS (numbering_tags_constants); i++)
+ {
+ translated_tag = gettext (numbering_tags_constants[i].text_representation);
+ tag_data = g_new (TagData, 1);
+ tag_data->available = TRUE;
+ tag_data->set = FALSE;
+ tag_data->position = 0;
+ g_hash_table_insert (self->tag_info_table, g_strdup (translated_tag), tag_data);
+ }
- tag_data = g_new (TagData, 1);
- tag_data->available = TRUE;
- tag_data->set = FALSE;
- tag_data->position = 0;
- g_hash_table_insert (self->tag_info_table, g_strdup (NUMBERING0), tag_data);
+ for (i = 0; i < G_N_ELEMENTS (metadata_tags_constants); i++)
+ {
+ gboolean is_original_name;
- tag_data = g_new (TagData, 1);
- tag_data->available = TRUE;
- tag_data->set = FALSE;
- tag_data->position = 0;
- g_hash_table_insert (self->tag_info_table, g_strdup (NUMBERING00), tag_data);
-
- tag_data = g_new (TagData, 1);
- tag_data->available = FALSE;
- tag_data->set = FALSE;
- tag_data->position = 0;
- g_hash_table_insert (self->tag_info_table, g_strdup (CREATION_DATE), tag_data);
-
- tag_data = g_new (TagData, 1);
- tag_data->available = FALSE;
- tag_data->set = FALSE;
- tag_data->position = 0;
- g_hash_table_insert (self->tag_info_table, g_strdup (CAMERA_MODEL), tag_data);
-
- tag_data = g_new (TagData, 1);
- tag_data->available = FALSE;
- tag_data->set = FALSE;
- tag_data->position = 0;
- g_hash_table_insert (self->tag_info_table, g_strdup (SEASON_NUMBER), tag_data);
-
- tag_data = g_new (TagData, 1);
- tag_data->available = FALSE;
- tag_data->set = FALSE;
- tag_data->position = 0;
- g_hash_table_insert (self->tag_info_table, g_strdup (EPISODE_NUMBER), tag_data);
-
- tag_data = g_new (TagData, 1);
- tag_data->available = FALSE;
- tag_data->set = FALSE;
- tag_data->position = 0;
- g_hash_table_insert (self->tag_info_table, g_strdup (TRACK_NUMBER), tag_data);
-
- tag_data = g_new (TagData, 1);
- tag_data->available = FALSE;
- tag_data->set = FALSE;
- tag_data->position = 0;
- g_hash_table_insert (self->tag_info_table, g_strdup (ARTIST_NAME), tag_data);
-
- tag_data = g_new (TagData, 1);
- tag_data->available = FALSE;
- tag_data->set = FALSE;
- tag_data->position = 0;
- g_hash_table_insert (self->tag_info_table, g_strdup (TITLE), tag_data);
-
- tag_data = g_new (TagData, 1);
- tag_data->available = FALSE;
- tag_data->set = FALSE;
- tag_data->position = 0;
- g_hash_table_insert (self->tag_info_table, g_strdup (ALBUM_NAME), tag_data);
-
- gtk_entry_set_text (GTK_ENTRY (self->name_entry), ORIGINAL_FILE_NAME);
- self->name_entry_characters = g_utf8_strlen (ORIGINAL_FILE_NAME, -1);
+ /* Only the original name is available and set at the start */
+ is_original_name = metadata_tags_constants[i].metadata_type == ORIGINAL_FILE_NAME;
+ translated_tag = gettext (metadata_tags_constants[i].text_representation);
+
+ tag_data = g_new (TagData, 1);
+ tag_data->available = is_original_name;
+ tag_data->set = is_original_name;
+ tag_data->position = 0;
+ g_hash_table_insert (self->tag_info_table, g_strdup (translated_tag), tag_data);
+ }
+
+ translated_tag = gettext (metadata_tags_constants[ORIGINAL_FILE_NAME].text_representation);
+ gtk_entry_set_text (GTK_ENTRY (self->name_entry), tranlated_tag);
+ self->name_entry_characters = g_utf8_strlen (translated_tag, -1);
self->row_height = -1;
diff --git a/src/nautilus-batch-rename-dialog.h b/src/nautilus-batch-rename-dialog.h
index e5084c3..503b171 100644
--- a/src/nautilus-batch-rename-dialog.h
+++ b/src/nautilus-batch-rename-dialog.h
@@ -21,23 +21,33 @@
#include <glib.h>
#include <glib/gprintf.h>
+#include <glib/gi18n.h>
#include <gtk/gtk.h>
#include "nautilus-files-view.h"
G_BEGIN_DECLS
-#define ORIGINAL_FILE_NAME "[Original file name]"
-#define NUMBERING "[1, 2, 3]"
-#define NUMBERING0 "[01, 02, 03]"
-#define NUMBERING00 "[001, 002, 003]"
-#define CAMERA_MODEL "[Camera model]"
-#define CREATION_DATE "[Creation date]"
-#define SEASON_NUMBER "[Season number]"
-#define EPISODE_NUMBER "[Episode number]"
-#define TRACK_NUMBER "[Track number]"
-#define ARTIST_NAME "[Artist name]"
-#define TITLE "[Title]"
-#define ALBUM_NAME "[Album name]"
+typedef enum
+{
+ EQUIPMENT,
+ CREATION_DATE,
+ SEASON_NUMBER,
+ EPISODE_NUMBER,
+ TRACK_NUMBER,
+ ARTIST_NAME,
+ TITLE,
+ ALBUM_NAME,
+ ORIGINAL_FILE_NAME,
+ METADATA_INVALID,
+} MetadataType;
+
+typedef enum
+{
+ NUMBERING_NO_ZERO_PAD,
+ NUMBERING_ONE_ZERO_PAD,
+ NUMBERING_TWO_ZERO_PAD,
+ NUMBERING_INVALID,
+} NumberingType;
typedef enum {
NAUTILUS_BATCH_RENAME_DIALOG_APPEND = 0,
@@ -57,26 +67,155 @@ typedef enum {
typedef struct
{
+ const gchar *action_name;
+ const gchar *text_representation;
+ MetadataType metadata_type;
+ NumberingType numbering_type;
+ gboolean is_metadata;
+} TagConstants;
+
+typedef struct
+{
+ const gchar *action_target_name;
+ const gchar *label;
+ const SortMode sort_mode;
+} SortConstants;
+
+static const SortConstants sorts_constants[] =
+{
+ {
+ "name-ascending",
+ N_("Original Name (Ascending)"),
+ ORIGINAL_ASCENDING,
+ },
+ {
+ "name-descending",
+ N_("Original Name (Descending)"),
+ ORIGINAL_DESCENDING,
+ },
+ {
+ "first-modified",
+ N_("First Modified"),
+ FIRST_MODIFIED,
+ },
+ {
+ "last-modified",
+ N_("Last Modified"),
+ LAST_MODIFIED,
+ },
+ {
+ "first-created",
+ N_("First Created"),
+ FIRST_CREATED,
+ },
+ {
+ "last-created",
+ N_("Last Created"),
+ LAST_CREATED,
+ },
+};
+
+static const TagConstants metadata_tags_constants[] =
+{
+ {
+ "add-equipment-tag",
+ N_("[Camera model]"),
+ EQUIPMENT,
+ NUMBERING_INVALID,
+ TRUE,
+ },
+ {
+ "add-creation-date",
+ N_("[Creation date]"),
+ CREATION_DATE,
+ NUMBERING_INVALID,
+ TRUE,
+ },
+ {
+ "add-season-number",
+ N_("[Season number]"),
+ SEASON_NUMBER,
+ NUMBERING_INVALID,
+ TRUE,
+ },
+ {
+ "add-episode-number",
+ N_("[Episode number]"),
+ EPISODE_NUMBER,
+ NUMBERING_INVALID,
+ TRUE,
+ },
+ {
+ "add-track-number",
+ N_("[Track number]"),
+ TRACK_NUMBER,
+ NUMBERING_INVALID,
+ TRUE,
+ },
+ {
+ "add-artist-name",
+ N_("[Artist name]"),
+ ARTIST_NAME,
+ NUMBERING_INVALID,
+ TRUE,
+ },
+ {
+ "add-title-tag",
+ N_("[Title]"),
+ TITLE,
+ NUMBERING_INVALID,
+ TRUE,
+ },
+ {
+ "add-album-name-tag",
+ N_("[Album name]"),
+ ALBUM_NAME,
+ NUMBERING_INVALID,
+ TRUE,
+ },
+ {
+ "add-original-file-name-tag",
+ N_("[Original file name]"),
+ ORIGINAL_FILE_NAME,
+ NUMBERING_INVALID,
+ TRUE,
+ },
+};
+
+static const TagConstants numbering_tags_constants[] =
+{
+ {
+ "add-numbering-no-zero-pag-tag",
+ N_("[1, 2, 3]"),
+ METADATA_INVALID,
+ NUMBERING_NO_ZERO_PAD,
+ FALSE,
+ },
+ {
+ "add-numbering-one-zero-pag-tag",
+ N_("[01, 02, 03]"),
+ METADATA_INVALID,
+ NUMBERING_ONE_ZERO_PAD,
+ FALSE,
+ },
+ {
+ "add-numbering-two-zero-pag-tag",
+ N_("[001, 002, 003]"),
+ METADATA_INVALID,
+ NUMBERING_TWO_ZERO_PAD,
+ FALSE,
+ },
+};
+
+typedef struct
+{
gchar *name;
gint index;
} ConflictData;
typedef struct {
- GString *file_name;
-
- /* Photo */
- GString *creation_date;
- GString *equipment;
-
- /* Video */
- GString *season;
- GString *episode_number;
-
- /* Music */
- GString *track_number;
- GString *artist_name;
- GString *title;
- GString *album_name;
+ GString *file_name;
+ GString metadata [G_N_ELEMENTS (metadata_tags_constants)];
} FileMetadata;
#define NAUTILUS_TYPE_BATCH_RENAME_DIALOG (nautilus_batch_rename_dialog_get_type())
diff --git a/src/resources/ui/nautilus-batch-rename-dialog.ui
b/src/resources/ui/nautilus-batch-rename-dialog.ui
index 51ef0b7..4d4a6ec 100644
--- a/src/resources/ui/nautilus-batch-rename-dialog.ui
+++ b/src/resources/ui/nautilus-batch-rename-dialog.ui
@@ -406,15 +406,15 @@
<attribute name="label" translatable="yes">Automatic Numbers</attribute>
<item>
<attribute name="label" translatable="yes">1, 2, 3, 4</attribute>
- <attribute name="action">dialog.add-numbering-tag-zero</attribute>
+ <attribute name="action">dialog.add-numbering-no-zero-pad-tag</attribute>
</item>
<item>
<attribute name="label" translatable="yes">01, 02, 03, 04</attribute>
- <attribute name="action">dialog.add-numbering-tag-one</attribute>
+ <attribute name="action">dialog.add-numbering-one-zero-pad-tag</attribute>
</item>
<item>
<attribute name="label" translatable="yes">001, 002, 003, 004</attribute>
- <attribute name="action">dialog.add-numbering-tag-two</attribute>
+ <attribute name="action">dialog.add-numbering-two-zero-pad-tag</attribute>
</item>
</section>
<section>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]