Simplify util_clip_triangle()
[geeqie.git] / src / metadata.cc
index da7e98f..85b6995 100644 (file)
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#include <locale.h>
-
-#include "main.h"
 #include "metadata.h"
 
+#include <unistd.h>
+
+#include <clocale>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+
+#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;
 
 enum MetadataKey {
        MK_NONE,
@@ -100,7 +114,7 @@ static void metadata_cache_update(FileData *fd, const gchar *key, const GList *v
                        GList *old_values = entry->next;
                        entry->next = nullptr;
                        old_values->prev = nullptr;
-                       string_list_free(old_values);
+                       g_list_free_full(old_values, g_free);
                        work->data = g_list_append(entry, string_list_copy(values));
                        DEBUG_1("updated %s %s\n", key, fd->path);
                        return;
@@ -150,7 +164,7 @@ static void metadata_cache_remove(FileData *fd, const gchar *key)
                if (strcmp(entry_key, key) == 0)
                        {
                        /* key found */
-                       string_list_free(entry);
+                       g_list_free_full(entry, g_free);
                        fd->cached_metadata = g_list_delete_link(fd->cached_metadata, work);
                        DEBUG_1("removed %s %s\n", key, fd->path);
                        return;
@@ -162,18 +176,13 @@ static void metadata_cache_remove(FileData *fd, const gchar *key)
 
 void metadata_cache_free(FileData *fd)
 {
-       GList *work;
        if (fd->cached_metadata) DEBUG_1("freed %s\n", fd->path);
 
-       work = fd->cached_metadata;
-       while (work)
+       g_list_free_full(fd->cached_metadata, [](gpointer data)
                {
-               auto entry = static_cast<GList *>(work->data);
-               string_list_free(entry);
-
-               work = work->next;
-               }
-       g_list_free(fd->cached_metadata);
+               auto entry = static_cast<GList *>(data);
+               g_list_free_full(entry, g_free);
+               });
        fd->cached_metadata = nullptr;
 }
 
@@ -230,22 +239,25 @@ gboolean metadata_write_queue_remove(FileData *fd)
        return TRUE;
 }
 
-//gboolean metadata_write_queue_remove_list(GList *list)
-//{
-       //GList *work;
-       //gboolean ret = TRUE;
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-function"
+gboolean metadata_write_queue_remove_list_unused(GList *list)
+{
+       GList *work;
+       gboolean ret = TRUE;
 
-       //work = list;
-       //while (work)
-               //{
-               //FileData *fd = static_cast<//FileData *>(work->data);
-               //work = work->next;
-               //ret = ret && metadata_write_queue_remove(fd);
-               //}
-       //return ret;
-//}
+       work = list;
+       while (work)
+               {
+               auto *fd = static_cast<FileData *>(work->data);
+               work = work->next;
+               ret = ret && metadata_write_queue_remove(fd);
+               }
+       return ret;
+}
+#pragma GCC diagnostic pop
 
-void metadata_notify_cb(FileData *fd, NotifyType type, gpointer UNUSED(data))
+void metadata_notify_cb(FileData *fd, NotifyType type, gpointer)
 {
        if (type & (NOTIFY_REREAD | NOTIFY_CHANGE))
                {
@@ -291,7 +303,7 @@ gboolean metadata_write_queue_confirm(gboolean force_dialog, FileUtilDoneFunc do
        return (metadata_write_queue != nullptr);
 }
 
-static gboolean metadata_write_queue_idle_cb(gpointer UNUSED(data))
+static gboolean metadata_write_queue_idle_cb(gpointer)
 {
        metadata_write_queue_confirm(FALSE, nullptr, nullptr);
        metadata_write_idle_id = 0;
@@ -417,7 +429,7 @@ gboolean metadata_write_string(FileData *fd, const gchar *key, const char *value
 {
        GList *list = g_list_append(nullptr, g_strdup(value));
        gboolean ret = metadata_write_list(fd, key, list);
-       string_list_free(list);
+       g_list_free_full(list, g_free);
        return ret;
 }
 
@@ -494,7 +506,7 @@ static gboolean metadata_legacy_write(FileData *fd)
 
        g_free(metadata_pathl);
        g_free(orig_comment);
-       string_list_free(orig_keywords);
+       g_list_free_full(orig_keywords, g_free);
 
        return success;
 }
@@ -564,7 +576,7 @@ static gboolean metadata_file_read(gchar *path, GList **keywords, gchar **commen
                }
        else
                {
-               string_list_free(list);
+               g_list_free_full(list, g_free);
                }
 
        if (comment_build)
@@ -608,7 +620,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);
@@ -715,7 +727,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));
@@ -742,7 +754,7 @@ gchar *metadata_read_string(FileData *fd, const gchar *key, MetadataFormat forma
                {
                auto str = static_cast<gchar *>(string_list->data);
                string_list->data = nullptr;
-               string_list_free(string_list);
+               g_list_free_full(string_list, g_free);
                return str;
                }
        return nullptr;
@@ -775,7 +787,9 @@ gdouble metadata_read_GPS_coord(FileData *fd, const gchar *key, gdouble fallback
 {
        gdouble coord;
        gchar *endptr;
-       gdouble deg, min, sec;
+       gdouble deg;
+       gdouble min;
+       gdouble sec;
        gboolean ok = FALSE;
        gchar *string = metadata_read_string(fd, key, METADATA_PLAIN);
        if (!string) return fallback;
@@ -847,14 +861,12 @@ gboolean metadata_append_string(FileData *fd, const gchar *key, const char *valu
                {
                return metadata_write_string(fd, key, value);
                }
-       else
-               {
-               gchar *new_string = g_strconcat(str, value, NULL);
-               gboolean ret = metadata_write_string(fd, key, new_string);
-               g_free(str);
-               g_free(new_string);
-               return ret;
-               }
+
+       gchar *new_string = g_strconcat(str, value, NULL);
+       gboolean ret = metadata_write_string(fd, key, new_string);
+       g_free(str);
+       g_free(new_string);
+       return ret;
 }
 
 gboolean metadata_write_GPS_coord(FileData *fd, const gchar *key, gdouble value)
@@ -865,7 +877,8 @@ gboolean metadata_write_GPS_coord(FileData *fd, const gchar *key, gdouble value)
        char *coordinate;
        const char *ref;
        gboolean ok = TRUE;
-       char *old_locale, *saved_locale;
+       char *old_locale;
+       char *saved_locale;
 
        param = value;
        if (param < 0)
@@ -918,16 +931,14 @@ gboolean metadata_append_list(FileData *fd, const gchar *key, const GList *value
                {
                return metadata_write_list(fd, key, values);
                }
-       else
-               {
-               gboolean ret;
-               list = g_list_concat(list, string_list_copy(values));
-               list = remove_duplicate_strings_from_list(list);
 
-               ret = metadata_write_list(fd, key, list);
-               string_list_free(list);
-               return ret;
-               }
+       gboolean ret;
+       list = g_list_concat(list, string_list_copy(values));
+       list = remove_duplicate_strings_from_list(list);
+
+       ret = metadata_write_list(fd, key, list);
+       g_list_free_full(list, g_free);
+       return ret;
 }
 
 /**
@@ -999,8 +1010,8 @@ gchar *find_string_in_list(GList *list, const gchar *string)
 {
        if (options->metadata.keywords_case_sensitive)
                return find_string_in_list_utf8case(list, string);
-       else
-               return find_string_in_list_utf8nocase(list, string);
+
+       return find_string_in_list_utf8nocase(list, string);
 }
 
 #define KEYWORDS_SEPARATOR(c) ((c) == ',' || (c) == ';' || (c) == '\n' || (c) == '\r' || (c) == '\b')
@@ -1047,7 +1058,7 @@ GList *string_to_keywords_list(const gchar *text)
  */
 
 
-gboolean meta_data_get_keyword_mark(FileData *fd, gint UNUSED(n), gpointer data)
+gboolean meta_data_get_keyword_mark(FileData *fd, gint, gpointer data)
 {
        /** @FIXME do not use global keyword_tree */
        auto path = static_cast<GList *>(data);
@@ -1065,7 +1076,7 @@ gboolean meta_data_get_keyword_mark(FileData *fd, gint UNUSED(n), gpointer data)
        return found;
 }
 
-gboolean meta_data_set_keyword_mark(FileData *fd, gint UNUSED(n), gboolean value, gpointer data)
+gboolean meta_data_set_keyword_mark(FileData *fd, gint, gboolean value, gpointer data)
 {
        auto path = static_cast<GList *>(data);
        GList *keywords = nullptr;
@@ -1088,7 +1099,7 @@ gboolean meta_data_set_keyword_mark(FileData *fd, gint UNUSED(n), gboolean value
                metadata_write_list(fd, KEYWORD_KEY, keywords);
                }
 
-       string_list_free(keywords);
+       g_list_free_full(keywords, g_free);
        return TRUE;
 }
 
@@ -1207,10 +1218,8 @@ gboolean keyword_same_parent(GtkTreeModel *keyword_tree, GtkTreeIter *a, GtkTree
                {
                return keyword_compare(keyword_tree, &parent_a, &parent_b) == 0;
                }
-       else
-               {
-               return (!valid_pa && !valid_pb); /* both are toplevel */
-               }
+
+       return (!valid_pa && !valid_pb); /* both are toplevel */
 }
 
 gboolean keyword_exists(GtkTreeModel *keyword_tree, GtkTreeIter *parent_ptr, GtkTreeIter *sibling, const gchar *name, gboolean exclude_sibling, GtkTreeIter *result)
@@ -1241,7 +1250,7 @@ gboolean keyword_exists(GtkTreeModel *keyword_tree, GtkTreeIter *parent_ptr, Gtk
 
        while (TRUE)
                {
-               if (!(exclude_sibling && sibling && keyword_compare(keyword_tree, &iter, sibling) == 0))
+               if (!exclude_sibling || !sibling || keyword_compare(keyword_tree, &iter, sibling) != 0)
                        {
                        if (options->metadata.keywords_case_sensitive)
                                {
@@ -1271,7 +1280,9 @@ gboolean keyword_exists(GtkTreeModel *keyword_tree, GtkTreeIter *parent_ptr, Gtk
 void keyword_copy(GtkTreeStore *keyword_tree, GtkTreeIter *to, GtkTreeIter *from)
 {
 
-       gchar *mark, *name, *casefold;
+       gchar *mark;
+       gchar *name;
+       gchar *casefold;
        gboolean is_keyword;
 
        /* do not copy KEYWORD_COLUMN_HIDE_IN, it fully shows the new subtree */
@@ -1473,7 +1484,7 @@ gboolean keyword_tree_is_set(GtkTreeModel *keyword_tree, GtkTreeIter *iter, GLis
 
                ret = keyword_tree_is_set_casefold(keyword_tree, *iter, casefold_list);
 
-               string_list_free(casefold_list);
+               g_list_free_full(casefold_list, g_free);
                }
 
        return ret;
@@ -1631,7 +1642,7 @@ gboolean keyword_is_hidden_in(GtkTreeModel *keyword_tree, GtkTreeIter *iter, gpo
        return !!g_list_find(list, id);
 }
 
-static gboolean keyword_show_all_in_cb(GtkTreeModel *model, GtkTreePath *UNUSED(path), GtkTreeIter *iter, gpointer data)
+static gboolean keyword_show_all_in_cb(GtkTreeModel *model, GtkTreePath *, GtkTreeIter *iter, gpointer data)
 {
        keyword_show_in(GTK_TREE_STORE(model), iter, data);
        return FALSE;
@@ -1642,7 +1653,7 @@ void keyword_show_all_in(GtkTreeStore *keyword_tree, gpointer id)
        gtk_tree_model_foreach(GTK_TREE_MODEL(keyword_tree), keyword_show_all_in_cb, id);
 }
 
-static gboolean keyword_revert_hidden_in_cb(GtkTreeModel *model, GtkTreePath *UNUSED(path), GtkTreeIter *iter, gpointer data)
+static gboolean keyword_revert_hidden_in_cb(GtkTreeModel *model, GtkTreePath *, GtkTreeIter *iter, gpointer data)
 {
        if (keyword_is_hidden_in(GTK_TREE_MODEL(keyword_tree), iter, data))
                {
@@ -1685,7 +1696,7 @@ void keyword_hide_unset_in(GtkTreeStore *keyword_tree, gpointer id, GList *keywo
        keyword_hide_unset_in_recursive(keyword_tree, &iter, id, keywords);
 }
 
-static gboolean keyword_show_set_in_cb(GtkTreeModel *model, GtkTreePath *UNUSED(path), GtkTreeIter *iter_ptr, gpointer data)
+static gboolean keyword_show_set_in_cb(GtkTreeModel *model, GtkTreePath *, GtkTreeIter *iter_ptr, gpointer data)
 {
        GtkTreeIter iter = *iter_ptr;
        auto keywords = static_cast<GList *>(data);
@@ -1730,7 +1741,8 @@ static GtkTreeIter keyword_tree_default_append(GtkTreeStore *keyword_tree, GtkTr
 
 void keyword_tree_new_default()
 {
-       GtkTreeIter i1, i2;
+       GtkTreeIter i1;
+       GtkTreeIter i2;
 
        if (!keyword_tree) keyword_tree_new();