Use g_list_free_full to free draw_queue and draw_queue_2pass
[geeqie.git] / src / metadata.cc
index 1a6dd1c..2c4f2a3 100644 (file)
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
+#include "metadata.h"
+
+#include <unistd.h>
+
+#include <algorithm>
+#include <array>
 #include <clocale>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
 
-#include "main.h"
-#include "metadata.h"
+#include <glib-object.h>
+
+#include <config.h>
 
 #include "cache.h"
+#include "debug.h"
 #include "exif.h"
 #include "filedata.h"
+#include "intl.h"
+#include "layout-util.h"
+#include "main-defines.h"
 #include "misc.h"
+#include "options.h"
+#include "rcfile.h"
 #include "secure-save.h"
 #include "ui-fileops.h"
 #include "utilops.h"
-#include "layout-util.h"
-#include "rcfile.h"
+
+struct ExifData;
+
+namespace
+{
 
 enum MetadataKey {
        MK_NONE,
@@ -44,7 +63,7 @@ enum MetadataKey {
 /**
  *  @brief Tags that will be written to all files in a group - selected by: options->metadata.sync_grouped_files, Preferences/Metadata/Write The Same Description Tags To All Grouped Sidecars
  */
-static const gchar *group_keys[] = {
+constexpr std::array<const gchar *, 21> group_keys{
        "Xmp.dc.title",
        "Xmp.photoshop.Urgency",
        "Xmp.photoshop.Category",
@@ -66,7 +85,18 @@ static const gchar *group_keys[] = {
        "Xmp.dc.rights",
        "Xmp.dc.description",
        "Xmp.photoshop.CaptionWriter",
-       nullptr};
+};
+
+inline gboolean is_keywords_separator(gchar c)
+{
+       return c == ','
+           || c == ';'
+           || c == '\n'
+           || c == '\r'
+           || c == '\b';
+}
+
+} // namespace
 
 static gboolean metadata_write_queue_idle_cb(gpointer data);
 static gboolean metadata_legacy_write(FileData *fd);
@@ -343,18 +373,6 @@ gint metadata_queue_length()
        return g_list_length(metadata_write_queue);
 }
 
-static gboolean metadata_check_key(const gchar *keys[], const gchar *key)
-{
-       const gchar **k = keys;
-
-       while (*k)
-               {
-               if (strcmp(key, *k) == 0) return TRUE;
-               k++;
-               }
-       return FALSE;
-}
-
 gboolean metadata_write_revert(FileData *fd, const gchar *key)
 {
        if (!fd->modified_xmp) return FALSE;
@@ -392,7 +410,8 @@ gboolean metadata_write_list(FileData *fd, const gchar *key, const GList *values
        file_data_increment_version(fd);
        file_data_send_notification(fd, NOTIFY_METADATA);
 
-       if (options->metadata.sync_grouped_files && metadata_check_key(group_keys, key))
+       auto metadata_check_key = [key](const gchar *k) { return strcmp(key, k) == 0; };
+       if (options->metadata.sync_grouped_files && std::any_of(group_keys.cbegin(), group_keys.cend(), metadata_check_key))
                {
                GList *work = fd->sidecar_files;
 
@@ -606,7 +625,7 @@ static void metadata_legacy_delete(FileData *fd, const gchar *except)
                g_free(metadata_path);
                }
 
-#ifdef HAVE_EXIV2
+#if HAVE_EXIV2
        /* without exiv2: do not delete xmp metadata because we are not able to convert it,
           just ignore it */
        metadata_path = cache_find_location(CACHE_TYPE_XMP_METADATA, fd->path);
@@ -713,7 +732,7 @@ GList *metadata_read_list(FileData *fd, const gchar *key, MetadataFormat format)
                {
                return g_list_append(nullptr, metadata_file_info(fd, key, format));
                }
-#ifdef HAVE_LUA
+#if HAVE_LUA
        else if (strncmp(key, "lua.", 4) == 0)
                {
                return g_list_append(nullptr, metadata_lua_info(fd, key, format));
@@ -1000,8 +1019,6 @@ gchar *find_string_in_list(GList *list, const gchar *string)
        return find_string_in_list_utf8nocase(list, string);
 }
 
-#define KEYWORDS_SEPARATOR(c) ((c) == ',' || (c) == ';' || (c) == '\n' || (c) == '\r' || (c) == '\b')
-
 GList *string_to_keywords_list(const gchar *text)
 {
        GList *list = nullptr;
@@ -1012,9 +1029,9 @@ GList *string_to_keywords_list(const gchar *text)
                const gchar *begin;
                gint l = 0;
 
-               while (KEYWORDS_SEPARATOR(*ptr)) ptr++;
+               while (is_keywords_separator(*ptr)) ptr++;
                begin = ptr;
-               while (*ptr != '\0' && !KEYWORDS_SEPARATOR(*ptr))
+               while (*ptr != '\0' && !is_keywords_separator(*ptr))
                        {
                        ptr++;
                        l++;