[gimp/wip/wormnest/iptc-multiple-keys: 8/14] plug-ins: Refactor cleaning xmp values into a separate function in metadata-editor.
- From: Jehan <jehanp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/wip/wormnest/iptc-multiple-keys: 8/14] plug-ins: Refactor cleaning xmp values into a separate function in metadata-editor.
- Date: Thu, 19 Nov 2020 23:25:29 +0000 (UTC)
commit bd2f43bf206c2d833ff848c36fad8db2996b18d6
Author: Jacob Boerema <jgboerema gmail com>
Date: Mon Nov 16 16:36:56 2020 -0500
plug-ins: Refactor cleaning xmp values into a separate function in metadata-editor.
The same code was used several times so we move it to its own function.
plug-ins/metadata/metadata-editor.c | 177 ++++++++++--------------------------
1 file changed, 50 insertions(+), 127 deletions(-)
---
diff --git a/plug-ins/metadata/metadata-editor.c b/plug-ins/metadata/metadata-editor.c
index c8f2c627b5..8350adb6a0 100644
--- a/plug-ins/metadata/metadata-editor.c
+++ b/plug-ins/metadata/metadata-editor.c
@@ -93,6 +93,8 @@ static void gpsaltsys_combo_callback (GtkComboBoxText *combo,
static void remove_substring (const gchar *string,
const gchar *substring);
+static gchar * clean_xmp_string (const gchar *value);
+
gboolean hasCreatorTagData (GtkBuilder *builder);
gboolean hasLocationCreationTagData (GtkBuilder *builder);
gboolean hasImageSupplierTagData (GtkBuilder *builder);
@@ -632,6 +634,47 @@ remove_substring (const gchar *string,
}
}
+static gchar *
+clean_xmp_string (const gchar *value)
+{
+ gchar *value_clean;
+ gchar *value_utf8;
+
+ value_clean = g_strdup (value);
+
+ if (strstr (value_clean, lang_default) != NULL)
+ {
+ remove_substring (value_clean, lang_default);
+ if (strstr (value_clean, " ") != NULL)
+ {
+ remove_substring (value_clean, " ");
+ }
+ }
+
+ if (strstr (value_clean, bag_default) != NULL)
+ {
+ remove_substring (value_clean, bag_default);
+ if (strstr (value_clean, " ") != NULL)
+ {
+ remove_substring (value_clean, " ");
+ }
+ }
+
+ if (strstr (value_clean, seq_default) != NULL)
+ {
+ remove_substring (value_clean, seq_default);
+ if (strstr (value_clean, " ") != NULL)
+ {
+ remove_substring (value_clean, " ");
+ }
+ }
+
+ value_utf8 = g_locale_to_utf8 (value_clean, -1, NULL, NULL, NULL);
+ g_free (value_clean);
+
+ return value_utf8;
+}
+
static gint
count_tags (GExiv2Metadata *metadata,
const gchar *header,
@@ -1777,39 +1820,9 @@ metadata_dialog_editor_set_metadata (GExiv2Metadata *metadata,
if (value)
{
- gchar *value_clean;
gchar *value_utf;
- value_clean = g_strdup (value);
-
- if (strstr (value_clean, lang_default) != NULL)
- {
- remove_substring (value_clean, lang_default);
- if (strstr (value_clean, " ") != NULL)
- {
- remove_substring (value_clean, " ");
- }
- }
-
- if (strstr (value_clean, bag_default) != NULL)
- {
- remove_substring (value_clean, bag_default);
- if (strstr (value_clean, " ") != NULL)
- {
- remove_substring (value_clean, " ");
- }
- }
-
- if (strstr (value_clean, seq_default) != NULL)
- {
- remove_substring (value_clean, seq_default);
- if (strstr (value_clean, " ") != NULL)
- {
- remove_substring (value_clean, " ");
- }
- }
-
- value_utf = g_locale_to_utf8 (value_clean, -1, NULL, NULL, NULL);
+ value_utf = clean_xmp_string (value);
if (! strcmp ("single", imageSupplierInfoTags[i].mode))
{
@@ -1837,39 +1850,9 @@ metadata_dialog_editor_set_metadata (GExiv2Metadata *metadata,
if (value)
{
- gchar *value_clean;
gchar *value_utf;
- value_clean = g_strdup (value);
-
- if (strstr (value_clean, lang_default) != NULL)
- {
- remove_substring (value_clean, lang_default);
- if (strstr (value_clean, " ") != NULL)
- {
- remove_substring (value_clean, " ");
- }
- }
-
- if (strstr (value_clean, bag_default) != NULL)
- {
- remove_substring (value_clean, bag_default);
- if (strstr (value_clean, " ") != NULL)
- {
- remove_substring (value_clean, " ");
- }
- }
-
- if (strstr (value_clean, seq_default) != NULL)
- {
- remove_substring (value_clean, seq_default);
- if (strstr (value_clean, " ") != NULL)
- {
- remove_substring (value_clean, " ");
- }
- }
-
- value_utf = g_locale_to_utf8 (value_clean, -1, NULL, NULL, NULL);
+ value_utf = clean_xmp_string (value);
if (! strcmp ("single", locationCreationInfoTags[i].mode))
{
@@ -1891,39 +1874,9 @@ metadata_dialog_editor_set_metadata (GExiv2Metadata *metadata,
if (value)
{
- gchar *value_clean;
gchar *value_utf;
- value_clean = g_strdup (value);
-
- if (strstr (value_clean, lang_default) != NULL)
- {
- remove_substring (value_clean, lang_default);
- if (strstr (value_clean, " ") != NULL)
- {
- remove_substring (value_clean, " ");
- }
- }
-
- if (strstr (value_clean, bag_default) != NULL)
- {
- remove_substring (value_clean, bag_default);
- if (strstr (value_clean, " ") != NULL)
- {
- remove_substring (value_clean, " ");
- }
- }
-
- if (strstr (value_clean, seq_default) != NULL)
- {
- remove_substring (value_clean, seq_default);
- if (strstr (value_clean, " ") != NULL)
- {
- remove_substring (value_clean, " ");
- }
- }
-
- value_utf = g_locale_to_utf8 (value_clean, -1, NULL, NULL, NULL);
+ value_utf = clean_xmp_string (value);
if (! strcmp ("single", creatorContactInfoTags[i].mode))
{
@@ -1964,50 +1917,20 @@ metadata_dialog_editor_set_metadata (GExiv2Metadata *metadata,
if (value)
{
- gchar *value_clean;
gchar *value_utf;
- value_clean = g_strdup (value);
-
- if (strstr (value_clean, lang_default) != NULL)
- {
- remove_substring (value_clean, lang_default);
- if (strstr (value_clean, " ") != NULL)
- {
- remove_substring (value_clean, " ");
- }
- }
-
- if (strstr (value_clean, bag_default) != NULL)
- {
- remove_substring (value_clean, bag_default);
- if (strstr (value_clean, " ") != NULL)
- {
- remove_substring (value_clean, " ");
- }
- }
-
- if (strstr (value_clean, seq_default) != NULL)
- {
- remove_substring (value_clean, seq_default);
- if (strstr (value_clean, " ") != NULL)
- {
- remove_substring (value_clean, " ");
- }
- }
+ value_utf = clean_xmp_string (value);
if (! strcmp ("Exif.GPSInfo.GPSAltitude",
default_metadata_tags[i].tag) &&
- value_clean)
+ value_utf)
{
gchar *new_value_clean[2];
- new_value_clean[0] = strtok (value_clean, " ");
- strcpy (value_clean, new_value_clean[0]);
+ new_value_clean[0] = strtok (value_utf, " ");
+ strcpy (value_utf, new_value_clean[0]);
}
- value_utf = g_locale_to_utf8 (value_clean, -1, NULL, NULL, NULL);
-
if (! strcmp ("single", default_metadata_tags[i].mode))
{
gtk_entry_set_text (GTK_ENTRY (widget), value_utf);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]