* 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,
/**
* @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",
"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);
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;
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;
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);
{
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));
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;
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++;