Sort headers using clang-tidy
[geeqie.git] / src / filedata.cc
index 065f870..14e7d34 100644 (file)
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#include "main.h"
 #include "filedata.h"
 
-#include "filefilter.h"
+#include <config.h>
+
 #include "cache.h"
-#include "thumb-standard.h"
-#include "ui-fileops.h"
-#include "metadata.h"
-#include "trash.h"
+#include "debug.h"
+#include "filefilter.h"
 #include "histogram.h"
+#include "intl.h"
+#include "main-defines.h"
+#include "main.h"
+#include "metadata.h"
+#include "options.h"
 #include "secure-save.h"
+#include "thumb-standard.h"
+#include "trash.h"
+#include "ui-fileops.h"
 
 #include "exif.h"
 #include "misc.h"
 
 #include <grp.h>
+#include <pwd.h>
 
 #ifdef DEBUG_FILEDATA
 gint global_file_data_count = 0;
 #endif
 
-static GHashTable *file_data_pool = NULL;
-static GHashTable *file_data_planned_change_hash = NULL;
+static GHashTable *file_data_pool = nullptr;
+static GHashTable *file_data_planned_change_hash = nullptr;
 
 static gint sidecar_file_priority(const gchar *extension);
 static void file_data_check_sidecars(const GList *basename_list);
@@ -50,6 +57,7 @@ static void file_data_disconnect_sidecar_file(FileData *target, FileData *sfd);
 
 static SortType filelist_sort_method = SORT_NONE;
 static gboolean filelist_sort_ascend = TRUE;
+static gboolean filelist_sort_case = TRUE;
 
 /*
  *-----------------------------------------------------------------------------
@@ -59,9 +67,13 @@ static gboolean filelist_sort_ascend = TRUE;
 
 gchar *text_from_size(gint64 size)
 {
-       gchar *a, *b;
-       gchar *s, *d;
-       gint l, n, i;
+       gchar *a;
+       gchar *b;
+       gchar *s;
+       gchar *d;
+       gint l;
+       gint n;
+       gint i;
 
        /* what I would like to use is printf("%'d", size)
         * BUT: not supported on every libc :(
@@ -69,11 +81,11 @@ gchar *text_from_size(gint64 size)
        if (size > G_MAXINT)
                {
                /* the %lld conversion is not valid in all libcs, so use a simple work-around */
-               a = g_strdup_printf("%d%09d", (guint)(size / 1000000000), (guint)(size % 1000000000));
+               a = g_strdup_printf("%d%09d", static_cast<guint>(size / 1000000000), static_cast<guint>(size % 1000000000));
                }
        else
                {
-               a = g_strdup_printf("%d", (guint)size);
+               a = g_strdup_printf("%d", static_cast<guint>(size));
                }
        l = strlen(a);
        n = (l - 1)/ 3;
@@ -106,32 +118,32 @@ gchar *text_from_size(gint64 size)
 
 gchar *text_from_size_abrev(gint64 size)
 {
-       if (size < (gint64)1024)
+       if (size < static_cast<gint64>(1024))
                {
-               return g_strdup_printf(_("%d bytes"), (gint)size);
+               return g_strdup_printf(_("%d bytes"), static_cast<gint>(size));
                }
-       if (size < (gint64)1048576)
+       if (size < static_cast<gint64>(1048576))
                {
-               return g_strdup_printf(_("%.1f KiB"), (gdouble)size / 1024.0);
+               return g_strdup_printf(_("%.1f KiB"), static_cast<gdouble>(size) / 1024.0);
                }
-       if (size < (gint64)1073741824)
+       if (size < static_cast<gint64>(1073741824))
                {
-               return g_strdup_printf(_("%.1f MiB"), (gdouble)size / 1048576.0);
+               return g_strdup_printf(_("%.1f MiB"), static_cast<gdouble>(size) / 1048576.0);
                }
 
        /* to avoid overflowing the gdouble, do division in two steps */
        size /= 1048576;
-       return g_strdup_printf(_("%.1f GiB"), (gdouble)size / 1024.0);
+       return g_strdup_printf(_("%.1f GiB"), static_cast<gdouble>(size) / 1024.0);
 }
 
 /* note: returned string is valid until next call to text_from_time() */
 const gchar *text_from_time(time_t t)
 {
-       static gchar *ret = NULL;
+       static gchar *ret = nullptr;
        gchar buf[128];
        gint buflen;
        struct tm *btime;
-       GError *error = NULL;
+       GError *error = nullptr;
 
        btime = localtime(&t);
 
@@ -140,7 +152,7 @@ const gchar *text_from_time(time_t t)
        if (buflen < 1) return "";
 
        g_free(ret);
-       ret = g_locale_to_utf8(buf, buflen, NULL, NULL, &error);
+       ret = g_locale_to_utf8(buf, buflen, nullptr, nullptr, &error);
        if (error)
                {
                log_printf("Error converting locale strftime to UTF-8: %s\n", error->message);
@@ -178,7 +190,7 @@ static gboolean file_data_check_changed_single_file(FileData *fd, struct stat *s
                fd->cdate = st->st_ctime;
                fd->mode = st->st_mode;
                if (fd->thumb_pixbuf) g_object_unref(fd->thumb_pixbuf);
-               fd->thumb_pixbuf = NULL;
+               fd->thumb_pixbuf = nullptr;
                file_data_increment_version(fd);
                file_data_send_notification(fd, NOTIFY_REREAD);
                return TRUE;
@@ -196,7 +208,7 @@ static gboolean file_data_check_changed_files_recursive(FileData *fd, struct sta
        work = fd->sidecar_files;
        while (work)
                {
-               FileData *sfd = static_cast<FileData *>(work->data);
+               auto sfd = static_cast<FileData *>(work->data);
                struct stat st;
                work = work->next;
 
@@ -230,7 +242,7 @@ gboolean file_data_check_changed_files(FileData *fd)
                {
                GList *sidecars;
                GList *work;
-               FileData *sfd = NULL;
+               FileData *sfd = nullptr;
 
                /* parent is missing, we have to rebuild whole group */
                ret = TRUE;
@@ -281,16 +293,10 @@ static void file_data_set_collate_keys(FileData *fd)
        g_free(fd->collate_key_name);
        g_free(fd->collate_key_name_nocase);
 
-       if (options->file_sort.natural)
-               {
-               fd->collate_key_name = g_utf8_collate_key_for_filename(fd->name, -1);
-               fd->collate_key_name_nocase = g_utf8_collate_key_for_filename(caseless_name, -1);
-               }
-       else
-               {
-               fd->collate_key_name = g_utf8_collate_key(valid_name, -1);
-               fd->collate_key_name_nocase = g_utf8_collate_key(caseless_name, -1);
-               }
+       fd->collate_key_name_natural = g_utf8_collate_key_for_filename(fd->name, -1);
+       fd->collate_key_name_nocase_natural = g_utf8_collate_key_for_filename(caseless_name, -1);
+       fd->collate_key_name = g_utf8_collate_key(valid_name, -1);
+       fd->collate_key_name_nocase = g_utf8_collate_key(caseless_name, -1);
 
        g_free(valid_name);
        g_free(caseless_name);
@@ -337,7 +343,8 @@ static void file_data_set_path(FileData *fd, const gchar *path)
                file_data_set_collate_keys(fd);
                return;
                }
-       else if (strcmp(fd->name, ".") == 0)
+
+       if (strcmp(fd->name, ".") == 0)
                {
                g_free(fd->path);
                fd->path = remove_level_from_path(path);
@@ -348,7 +355,7 @@ static void file_data_set_path(FileData *fd, const gchar *path)
                }
 
        fd->extension = registered_extension_from_path(fd->path);
-       if (fd->extension == NULL)
+       if (fd->extension == nullptr)
                {
                fd->extension = fd->name + strlen(fd->name);
                }
@@ -395,19 +402,19 @@ static FileData *file_data_new(const gchar *path_utf8, struct stat *st, gboolean
                                }
                        else
                                {
-                               fd = NULL;
+                               fd = nullptr;
                                }
                        }
                }
 
        if (fd)
                {
-               gboolean changed;
-
                if (disable_sidecars) file_data_disable_grouping(fd, TRUE);
 
-
-               changed = file_data_check_changed_single_file(fd, st);
+#ifdef DEBUG_FILEDATA
+               gboolean changed =
+#endif
+               file_data_check_changed_single_file(fd, st);
 
                DEBUG_2("file_data_pool hit: '%s' %s", fd->path, changed ? "(changed)" : "");
 
@@ -512,7 +519,12 @@ void read_exif_time_data(FileData *file)
                if (tmp)
                        {
                        struct tm time_str;
-                       uint year, month, day, hour, min, sec;
+                       uint year;
+                       uint month;
+                       uint day;
+                       uint hour;
+                       uint min;
+                       uint sec;
 
                        sscanf(tmp, "%4u:%2u:%2u %2u:%2u:%2u", &year, &month, &day, &hour, &min, &sec);
                        time_str.tm_year  = year - 1900;
@@ -550,7 +562,12 @@ void read_exif_time_digitized_data(FileData *file)
                if (tmp)
                        {
                        struct tm time_str;
-                       uint year, month, day, hour, min, sec;
+                       uint year;
+                       uint month;
+                       uint day;
+                       uint hour;
+                       uint min;
+                       uint sec;
 
                        sscanf(tmp, "%4u:%2u:%2u %2u:%2u:%2u", &year, &month, &day, &hour, &min, &sec);
                        time_str.tm_year  = year - 1900;
@@ -583,49 +600,52 @@ void read_rating_data(FileData *file)
                }
 }
 
-//void set_exif_time_data(GList *files)
-//{
-       //DEBUG_1("%s set_exif_time_data: ...", get_exec_time());
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-function"
+void set_exif_time_data_unused(GList *files)
+{
+       DEBUG_1("%s set_exif_time_data: ...", get_exec_time());
 
-       //while (files)
-               //{
-               //FileData *file = files->data;
+       while (files)
+               {
+               auto *file = static_cast<FileData *>(files->data);
 
-               //read_exif_time_data(file);
-               //files = files->next;
-               //}
-//}
+               read_exif_time_data(file);
+               files = files->next;
+               }
+}
 
-//void set_exif_time_digitized_data(GList *files)
-//{
-       //DEBUG_1("%s set_exif_time_digitized_data: ...", get_exec_time());
+void set_exif_time_digitized_data_unused(GList *files)
+{
+       DEBUG_1("%s set_exif_time_digitized_data: ...", get_exec_time());
 
-       //while (files)
-               //{
-               //FileData *file = files->data;
+       while (files)
+               {
+               auto *file = static_cast<FileData *>(files->data);
 
-               //read_exif_time_digitized_data(file);
-               //files = files->next;
-               //}
-//}
+               read_exif_time_digitized_data(file);
+               files = files->next;
+               }
+}
 
-//void set_rating_data(GList *files)
-//{
-       //gchar *rating_str;
-       //DEBUG_1("%s set_rating_data: ...", get_exec_time());
+void set_rating_data_unused(GList *files)
+{
+       gchar *rating_str;
+       DEBUG_1("%s set_rating_data: ...", get_exec_time());
 
-       //while (files)
-               //{
-               //FileData *file = files->data;
-               //rating_str = metadata_read_string(file, RATING_KEY, METADATA_PLAIN);
-               //if (rating_str )
-                       //{
-                       //file->rating = atoi(rating_str);
-                       //g_free(rating_str);
-                       //}
-               //files = files->next;
-               //}
-//}
+       while (files)
+               {
+               auto *file = static_cast<FileData *>(files->data);
+               rating_str = metadata_read_string(file, RATING_KEY, METADATA_PLAIN);
+               if (rating_str )
+                       {
+                       file->rating = atoi(rating_str);
+                       g_free(rating_str);
+                       }
+               files = files->next;
+               }
+}
+#pragma GCC diagnostic pop
 
 FileData *file_data_new_no_grouping(const gchar *path_utf8)
 {
@@ -668,7 +688,7 @@ FileData *file_data_ref_debug(const gchar *file, gint line, FileData *fd)
 FileData *file_data_ref(FileData *fd)
 #endif
 {
-       if (fd == NULL) return NULL;
+       if (fd == nullptr) return nullptr;
        if (fd->magick != FD_MAGICK)
 #ifdef DEBUG_FILEDATA
                log_printf("Error: fd magick mismatch @ %s:%d  fd=%p", file, line, (void *)fd);
@@ -688,8 +708,8 @@ FileData *file_data_ref(FileData *fd)
 
 /**
  * @brief Print ref. count and image name
- * @param  
- * 
+ * @param
+ *
  * Print image ref. count and full path name of all images in
  * the file_data_pool.
  *
@@ -708,11 +728,12 @@ void file_data_dump()
                log_printf("%d", global_file_data_count);
                log_printf("%d", g_list_length(list));
 
-               while (list)
+               GList *work = list;
+               while (work)
                        {
-                       fd = static_cast<FileData *>(list->data);
+                       fd = static_cast<FileData *>(work->data);
                        log_printf("%-4d %s", fd->ref, fd->path);
-                       list = list->next;
+                       work = work->next;
                        }
 
                g_list_free(list);
@@ -745,9 +766,9 @@ static void file_data_free(FileData *fd)
        g_free(fd->group);
        g_free(fd->sym_link);
        g_free(fd->format_name);
-       g_assert(fd->sidecar_files == NULL); /* sidecar files must be freed before calling this */
+       g_assert(fd->sidecar_files == nullptr); /* sidecar files must be freed before calling this */
 
-       file_data_change_info_free(NULL, fd);
+       file_data_change_info_free(nullptr, fd);
        g_free(fd);
 }
 
@@ -779,7 +800,7 @@ static void file_data_consider_free(FileData *fd)
        work = parent->sidecar_files;
        while (work)
                {
-               FileData *sfd = static_cast<FileData *>(work->data);
+               auto sfd = static_cast<FileData *>(work->data);
                if (file_data_check_has_ref(sfd)) return;
                work = work->next;
                }
@@ -788,16 +809,8 @@ static void file_data_consider_free(FileData *fd)
        DEBUG_2("file_data_consider_free: deleting '%s', parent '%s'",
                fd->path, fd->parent ? parent->path : "-");
 
-       work = parent->sidecar_files;
-       while (work)
-               {
-               FileData *sfd = static_cast<FileData *>(work->data);
-               file_data_free(sfd);
-               work = work->next;
-               }
-
-       g_list_free(parent->sidecar_files);
-       parent->sidecar_files = NULL;
+       g_list_free_full(parent->sidecar_files, reinterpret_cast<GDestroyNotify>(file_data_free));
+       parent->sidecar_files = nullptr;
 
        file_data_free(parent);
 }
@@ -808,7 +821,7 @@ void file_data_unref_debug(const gchar *file, gint line, FileData *fd)
 void file_data_unref(FileData *fd)
 #endif
 {
-       if (fd == NULL) return;
+       if (fd == nullptr) return;
        if (fd->magick != FD_MAGICK)
 #ifdef DEBUG_FILEDATA
                log_printf("Error: fd magick mismatch @ %s:%d  fd=%p", file, line, (void *)fd);
@@ -842,7 +855,7 @@ void file_data_unref(FileData *fd)
  */
 void file_data_lock(FileData *fd)
 {
-       if (fd == NULL) return;
+       if (fd == nullptr) return;
        if (fd->magick != FD_MAGICK) log_printf("Error: fd magick mismatch fd=%p", (void *)fd);
 
        g_assert(fd->magick == FD_MAGICK);
@@ -860,7 +873,7 @@ void file_data_lock(FileData *fd)
  */
 void file_data_unlock(FileData *fd)
 {
-       if (fd == NULL) return;
+       if (fd == nullptr) return;
        if (fd->magick != FD_MAGICK) log_printf("Error: fd magick mismatch fd=%p", (void *)fd);
 
        g_assert(fd->magick == FD_MAGICK);
@@ -882,7 +895,7 @@ void file_data_lock_list(GList *list)
        work = list;
        while (work)
                {
-               FileData *fd = static_cast<FileData *>(work->data);
+               auto fd = static_cast<FileData *>(work->data);
                work = work->next;
                file_data_lock(fd);
                }
@@ -900,7 +913,7 @@ void file_data_unlock_list(GList *list)
        work = list;
        while (work)
                {
-               FileData *fd = static_cast<FileData *>(work->data);
+               auto fd = static_cast<FileData *>(work->data);
                work = work->next;
                file_data_unlock(fd);
                }
@@ -914,8 +927,8 @@ void file_data_unlock_list(GList *list)
 
 static gint file_data_sort_by_ext(gconstpointer a, gconstpointer b)
 {
-       const FileData *fda = static_cast<const FileData *>(a);
-       const FileData *fdb = static_cast<const FileData *>(b);
+       auto fda = static_cast<const FileData *>(a);
+       auto fdb = static_cast<const FileData *>(b);
 
        if (fda->sidecar_priority < fdb->sidecar_priority) return -1;
        if (fda->sidecar_priority > fdb->sidecar_priority) return 1;
@@ -929,13 +942,13 @@ static gint sidecar_file_priority(const gchar *extension)
        gint i = 1;
        GList *work;
 
-       if (extension == NULL)
+       if (extension == nullptr)
                return 0;
 
        work = sidecar_ext_get_list();
 
        while (work) {
-               gchar *ext = static_cast<gchar *>(work->data);
+               auto ext = static_cast<gchar *>(work->data);
 
                work = work->next;
                if (g_ascii_strcasecmp(extension, ext) == 0) return i;
@@ -950,7 +963,8 @@ static void file_data_check_sidecars(const GList *basename_list)
        /* all files in the list have ref count > 0 */
 
        const GList *work;
-       GList *s_work, *new_sidecars;
+       GList *s_work;
+       GList *new_sidecars;
        FileData *parent_fd;
 
        if (!basename_list) return;
@@ -960,7 +974,7 @@ static void file_data_check_sidecars(const GList *basename_list)
        work = basename_list;
        while (work)
                {
-               FileData *fd = static_cast<FileData *>(work->data);
+               auto fd = static_cast<FileData *>(work->data);
                work = work->next;
                g_assert(fd->magick == FD_MAGICK);
                DEBUG_2("basename: %p %s", (void *)fd, fd->name);
@@ -972,13 +986,13 @@ static void file_data_check_sidecars(const GList *basename_list)
                s_work = fd->sidecar_files;
                while (s_work)
                        {
-                       FileData *sfd = static_cast<FileData *>(s_work->data);
+                       auto sfd = static_cast<FileData *>(s_work->data);
                        s_work = s_work->next;
                        g_assert(sfd->magick == FD_MAGICK);
                        DEBUG_2("                  sidecar: %p %s", (void *)sfd, sfd->name);
                        }
 
-               g_assert(fd->parent == NULL || fd->sidecar_files == NULL);
+               g_assert(fd->parent == nullptr || fd->sidecar_files == nullptr);
                }
 
        parent_fd = static_cast<FileData *>(basename_list->data);
@@ -1008,14 +1022,14 @@ static void file_data_check_sidecars(const GList *basename_list)
        work = basename_list;
        while (work)
                {
-               FileData *fd = static_cast<FileData *>(work->data);
+               auto fd = static_cast<FileData *>(work->data);
                work = work->next;
-               g_assert(fd->parent == NULL || fd->sidecar_files == NULL);
+               g_assert(fd->parent == nullptr || fd->sidecar_files == nullptr);
 
                if (fd->parent)
                        {
                        FileData *old_parent = fd->parent;
-                       g_assert(old_parent->parent == NULL || old_parent->sidecar_files == NULL);
+                       g_assert(old_parent->parent == nullptr || old_parent->sidecar_files == nullptr);
                        file_data_ref(old_parent);
                        file_data_disconnect_sidecar_file(old_parent, fd);
                        file_data_send_notification(old_parent, NOTIFY_REREAD);
@@ -1024,8 +1038,8 @@ static void file_data_check_sidecars(const GList *basename_list)
 
                while (fd->sidecar_files)
                        {
-                       FileData *sfd = static_cast<FileData *>(fd->sidecar_files->data);
-                       g_assert(sfd->parent == NULL || sfd->sidecar_files == NULL);
+                       auto sfd = static_cast<FileData *>(fd->sidecar_files->data);
+                       g_assert(sfd->parent == nullptr || sfd->sidecar_files == nullptr);
                        file_data_ref(sfd);
                        file_data_disconnect_sidecar_file(fd, sfd);
                        file_data_send_notification(sfd, NOTIFY_REREAD);
@@ -1033,22 +1047,22 @@ static void file_data_check_sidecars(const GList *basename_list)
                        }
                file_data_send_notification(fd, NOTIFY_GROUPING);
 
-               g_assert(fd->parent == NULL && fd->sidecar_files == NULL);
+               g_assert(fd->parent == nullptr && fd->sidecar_files == nullptr);
                }
 
        /* now we can form the new group */
        work = basename_list->next;
-       new_sidecars = NULL;
+       new_sidecars = nullptr;
        while (work)
                {
-               FileData *sfd = static_cast<FileData *>(work->data);
+               auto sfd = static_cast<FileData *>(work->data);
                g_assert(sfd->magick == FD_MAGICK);
-               g_assert(sfd->parent == NULL && sfd->sidecar_files == NULL);
+               g_assert(sfd->parent == nullptr && sfd->sidecar_files == nullptr);
                sfd->parent = parent_fd;
                new_sidecars = g_list_prepend(new_sidecars, sfd);
                work = work->next;
                }
-       g_assert(parent_fd->sidecar_files == NULL);
+       g_assert(parent_fd->sidecar_files == nullptr);
        parent_fd->sidecar_files = g_list_reverse(new_sidecars);
        DEBUG_1("basename group changed for %s", parent_fd->path);
 }
@@ -1068,9 +1082,9 @@ static void file_data_disconnect_sidecar_file(FileData *target, FileData *sfd)
        file_data_increment_version(sfd); /* increments both sfd and target */
 
        target->sidecar_files = g_list_remove(target->sidecar_files, sfd);
-       sfd->parent = NULL;
+       sfd->parent = nullptr;
        g_free(sfd->extended_extension);
-       sfd->extended_extension = NULL;
+       sfd->extended_extension = nullptr;
 
        file_data_unref(target);
        file_data_unref(sfd);
@@ -1098,7 +1112,7 @@ void file_data_disable_grouping(FileData *fd, gboolean disable)
                        GList *work = sidecar_files;
                        while (work)
                                {
-                               FileData *sfd = static_cast<FileData *>(work->data);
+                               auto sfd = static_cast<FileData *>(work->data);
                                work = work->next;
                                file_data_disconnect_sidecar_file(fd, sfd);
                                file_data_send_notification(sfd, NOTIFY_GROUPING);
@@ -1126,7 +1140,7 @@ void file_data_disable_grouping_list(GList *fd_list, gboolean disable)
        work = fd_list;
        while (work)
                {
-               FileData *fd = static_cast<FileData *>(work->data);
+               auto fd = static_cast<FileData *>(work->data);
 
                file_data_disable_grouping(fd, disable);
                work = work->next;
@@ -1191,11 +1205,16 @@ gint filelist_sort_compare_filedata(FileData *fa, FileData *fb)
                        if (fa->format_class > fb->format_class) return 1;
                        /* fall back to name */
                        break;
+               case SORT_NUMBER:
+                       ret = strcmp(fa->collate_key_name_natural, fb->collate_key_name_natural);
+                       if (ret != 0) return ret;
+                       /* fall back to name */
+                       break;
                default:
                        break;
                }
 
-       if (options->file_sort.case_sensitive)
+       if (filelist_sort_case)
                ret = strcmp(fa->collate_key_name, fb->collate_key_name);
        else
                ret = strcmp(fa->collate_key_name_nocase, fb->collate_key_name_nocase);
@@ -1220,29 +1239,34 @@ static gint filelist_sort_file_cb(gpointer a, gpointer b)
        return filelist_sort_compare_filedata(static_cast<FileData *>(a), static_cast<FileData *>(b));
 }
 
-GList *filelist_sort_full(GList *list, SortType method, gboolean ascend, GCompareFunc cb)
+GList *filelist_sort_full(GList *list, SortType method, gboolean ascend, gboolean case_sensitive, GCompareFunc cb)
 {
        filelist_sort_method = method;
        filelist_sort_ascend = ascend;
+       filelist_sort_case = case_sensitive;
        return g_list_sort(list, cb);
 }
 
-GList *filelist_insert_sort_full(GList *list, gpointer data, SortType method, gboolean ascend, GCompareFunc cb)
+GList *filelist_insert_sort_full(GList *list, gpointer data, SortType method, gboolean ascend, gboolean case_sensitive, GCompareFunc cb)
 {
        filelist_sort_method = method;
        filelist_sort_ascend = ascend;
+       filelist_sort_case = case_sensitive;
        return g_list_insert_sorted(list, data, cb);
 }
 
-GList *filelist_sort(GList *list, SortType method, gboolean ascend)
+GList *filelist_sort(GList *list, SortType method, gboolean ascend, gboolean case_sensitive)
 {
-       return filelist_sort_full(list, method, ascend, (GCompareFunc) filelist_sort_file_cb);
+       return filelist_sort_full(list, method, ascend, case_sensitive, reinterpret_cast<GCompareFunc>(filelist_sort_file_cb));
 }
 
-//GList *filelist_insert_sort(GList *list, FileData *fd, SortType method, gboolean ascend)
-//{
-       //return filelist_insert_sort_full(list, fd, method, ascend, (GCompareFunc) filelist_sort_file_cb);
-//}
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-function"
+GList *filelist_insert_sort_unused(GList *list, FileData *fd, SortType method, gboolean ascend)
+{
+       return filelist_insert_sort_full(list, fd, method, ascend, ascend, (GCompareFunc) filelist_sort_file_cb);
+}
+#pragma GCC diagnostic pop
 
 /*
  *-----------------------------------------------------------------------------
@@ -1251,9 +1275,9 @@ GList *filelist_sort(GList *list, SortType method, gboolean ascend)
  */
 
 
-static GHashTable *file_data_basename_hash_new(void)
+static GHashTable *file_data_basename_hash_new()
 {
-       return g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
+       return g_hash_table_new_full(g_str_hash, g_str_equal, g_free, nullptr);
 }
 
 static GList * file_data_basename_hash_insert(GHashTable *basename_hash, FileData *fd)
@@ -1273,7 +1297,7 @@ static GList * file_data_basename_hash_insert(GHashTable *basename_hash, FileDat
                        DEBUG_1("TG: parent extension %s",parent_extension);
                        gchar *parent_basename = g_strndup(basename, parent_extension - basename);
                        DEBUG_1("TG: parent basename %s",parent_basename);
-                       FileData *parent_fd = static_cast<FileData *>(g_hash_table_lookup(file_data_pool, basename));
+                       auto parent_fd = static_cast<FileData *>(g_hash_table_lookup(file_data_pool, basename));
                        if (parent_fd)
                                {
                                DEBUG_1("TG: parent fd found");
@@ -1282,7 +1306,7 @@ static GList * file_data_basename_hash_insert(GHashTable *basename_hash, FileDat
                                        {
                                        DEBUG_1("TG: parent fd doesn't fit");
                                        g_free(parent_basename);
-                                       list = NULL;
+                                       list = nullptr;
                                        }
                                else
                                        {
@@ -1308,17 +1332,17 @@ static GList * file_data_basename_hash_insert(GHashTable *basename_hash, FileDat
 
 static void file_data_basename_hash_insert_cb(gpointer fd, gpointer basename_hash)
 {
-       file_data_basename_hash_insert((GHashTable *)basename_hash, (FileData *)fd);
+       file_data_basename_hash_insert(static_cast<GHashTable *>(basename_hash), static_cast<FileData *>(fd));
 }
 
-static void file_data_basename_hash_remove_list(gpointer UNUSED(key), gpointer value, gpointer UNUSED(data))
+static void file_data_basename_hash_remove_list(gpointer, gpointer value, gpointer)
 {
-       filelist_free((GList *)value);
+       filelist_free(static_cast<GList *>(value));
 }
 
 static void file_data_basename_hash_free(GHashTable *basename_hash)
 {
-       g_hash_table_foreach(basename_hash, file_data_basename_hash_remove_list, NULL);
+       g_hash_table_foreach(basename_hash, file_data_basename_hash_remove_list, nullptr);
        g_hash_table_destroy(basename_hash);
 }
 
@@ -1331,11 +1355,11 @@ static void file_data_basename_hash_free(GHashTable *basename_hash)
 static GList *filelist_filter_out_sidecars(GList *flist)
 {
        GList *work = flist;
-       GList *flist_filtered = NULL;
+       GList *flist_filtered = nullptr;
 
        while (work)
                {
-               FileData *fd = static_cast<FileData *>(work->data);
+               auto fd = static_cast<FileData *>(work->data);
 
                work = work->next;
                if (fd->parent) /* remove fd's that are children */
@@ -1348,9 +1372,9 @@ static GList *filelist_filter_out_sidecars(GList *flist)
        return flist_filtered;
 }
 
-static void file_data_basename_hash_to_sidecars(gpointer UNUSED(key), gpointer value, gpointer UNUSED(data))
+static void file_data_basename_hash_to_sidecars(gpointer, gpointer value, gpointer)
 {
-       GList *basename_list = (GList *)value;
+       auto basename_list = static_cast<GList *>(value);
        file_data_check_sidecars(basename_list);
 }
 
@@ -1373,22 +1397,22 @@ static gboolean filelist_read_real(const gchar *dir_path, GList **files, GList *
        DIR *dp;
        struct dirent *dir;
        gchar *pathl;
-       GList *dlist = NULL;
-       GList *flist = NULL;
-       GList *xmp_files = NULL;
+       GList *dlist = nullptr;
+       GList *flist = nullptr;
+       GList *xmp_files = nullptr;
        gint (*stat_func)(const gchar *path, struct stat *buf);
-       GHashTable *basename_hash = NULL;
+       GHashTable *basename_hash = nullptr;
 
        g_assert(files || dirs);
 
-       if (files) *files = NULL;
-       if (dirs) *dirs = NULL;
+       if (files) *files = nullptr;
+       if (dirs) *dirs = nullptr;
 
        pathl = path_from_utf8(dir_path);
        if (!pathl) return FALSE;
 
        dp = opendir(pathl);
-       if (dp == NULL)
+       if (dp == nullptr)
                {
                g_free(pathl);
                return FALSE;
@@ -1401,7 +1425,7 @@ static gboolean filelist_read_real(const gchar *dir_path, GList **files, GList *
        else
                stat_func = lstat;
 
-       while ((dir = readdir(dp)) != NULL)
+       while ((dir = readdir(dp)) != nullptr)
                {
                struct stat ent_sbuf;
                const gchar *name = dir->d_name;
@@ -1417,7 +1441,7 @@ static gboolean filelist_read_real(const gchar *dir_path, GList **files, GList *
                                {
                                /* we ignore the .thumbnails dir for cleanliness */
                                if (dirs &&
-                                   !(name[0] == '.' && (name[1] == '\0' || (name[1] == '.' && name[2] == '\0'))) &&
+                                   (name[0] != '.' || (name[1] != '\0' && (name[1] != '.' || name[2] != '\0'))) &&
                                    strcmp(name, GQ_CACHE_LOCAL_THUMB) != 0 &&
                                    strcmp(name, GQ_CACHE_LOCAL_METADATA) != 0 &&
                                    strcmp(name, THUMB_FOLDER_LOCAL) != 0)
@@ -1465,7 +1489,7 @@ static gboolean filelist_read_real(const gchar *dir_path, GList **files, GList *
 
        if (files)
                {
-               g_hash_table_foreach(basename_hash, file_data_basename_hash_to_sidecars, NULL);
+               g_hash_table_foreach(basename_hash, file_data_basename_hash_to_sidecars, nullptr);
 
                *files = filelist_filter_out_sidecars(flist);
                }
@@ -1507,7 +1531,7 @@ FileData *file_data_new_group(const gchar *path_utf8)
 
        dir = remove_level_from_path(path_utf8);
 
-       filelist_read_real(dir, &files, NULL, TRUE);
+       filelist_read_real(dir, &files, nullptr, TRUE);
 
        fd = static_cast<FileData *>(g_hash_table_lookup(file_data_pool, path_utf8));
        if (!fd) fd = file_data_new(path_utf8, &st, TRUE);
@@ -1539,16 +1563,11 @@ void filelist_free(GList *list)
 
 GList *filelist_copy(GList *list)
 {
-       GList *new_list = NULL;
-       GList *work;
+       GList *new_list = nullptr;
 
-       work = list;
-       while (work)
+       for (GList *work = list; work; work = work->next)
                {
-               FileData *fd;
-
-               fd = static_cast<FileData *>(work->data);
-               work = work->next;
+               auto fd = static_cast<FileData *>(work->data);
 
                new_list = g_list_prepend(new_list, file_data_ref(fd));
                }
@@ -1558,7 +1577,7 @@ GList *filelist_copy(GList *list)
 
 GList *filelist_from_path_list(GList *list)
 {
-       GList *new_list = NULL;
+       GList *new_list = nullptr;
        GList *work;
 
        work = list;
@@ -1577,7 +1596,7 @@ GList *filelist_from_path_list(GList *list)
 
 GList *filelist_to_path_list(GList *list)
 {
-       GList *new_list = NULL;
+       GList *new_list = nullptr;
        GList *work;
 
        work = list;
@@ -1603,22 +1622,20 @@ GList *filelist_filter(GList *list, gboolean is_dir_list)
        work = list;
        while (work)
                {
-               FileData *fd = (FileData *)(work->data);
+               auto fd = static_cast<FileData *>(work->data);
                const gchar *name = fd->name;
+               GList *link = work;
+               work = work->next;
 
                if ((!options->file_filter.show_hidden_files && is_hidden_file(name)) ||
                    (!is_dir_list && !filter_name_exists(name)) ||
                    (is_dir_list && name[0] == '.' && (strcmp(name, GQ_CACHE_LOCAL_THUMB) == 0 ||
                                                       strcmp(name, GQ_CACHE_LOCAL_METADATA) == 0)) )
                        {
-                       GList *link = work;
-
                        list = g_list_remove_link(list, link);
                        file_data_unref(fd);
                        g_list_free(link);
                        }
-
-               work = work->next;
                }
 
        return list;
@@ -1647,7 +1664,7 @@ static void filelist_recursive_append(GList **list, GList *dirs)
        work = dirs;
        while (work)
                {
-               FileData *fd = (FileData *)(work->data);
+               auto fd = static_cast<FileData *>(work->data);
                GList *f;
                GList *d;
 
@@ -1667,26 +1684,26 @@ static void filelist_recursive_append(GList **list, GList *dirs)
                }
 }
 
-static void filelist_recursive_append_full(GList **list, GList *dirs, SortType method, gboolean ascend)
+static void filelist_recursive_append_full(GList **list, GList *dirs, SortType method, gboolean ascend, gboolean case_sensitive)
 {
        GList *work;
 
        work = dirs;
        while (work)
                {
-               FileData *fd = (FileData *)(work->data);
+               auto fd = static_cast<FileData *>(work->data);
                GList *f;
                GList *d;
 
                if (filelist_read(fd, &f, &d))
                        {
                        f = filelist_filter(f, FALSE);
-                       f = filelist_sort_full(f, method, ascend, (GCompareFunc) filelist_sort_file_cb);
+                       f = filelist_sort_full(f, method, ascend, case_sensitive, reinterpret_cast<GCompareFunc>(filelist_sort_file_cb));
                        *list = g_list_concat(*list, f);
 
                        d = filelist_filter(d, TRUE);
                        d = filelist_sort_path(d);
-                       filelist_recursive_append_full(list, d, method, ascend);
+                       filelist_recursive_append_full(list, d, method, ascend, case_sensitive);
                        filelist_free(d);
                        }
 
@@ -1699,7 +1716,7 @@ GList *filelist_recursive(FileData *dir_fd)
        GList *list;
        GList *d;
 
-       if (!filelist_read(dir_fd, &list, &d)) return NULL;
+       if (!filelist_read(dir_fd, &list, &d)) return nullptr;
        list = filelist_filter(list, FALSE);
        list = filelist_sort_path(list);
 
@@ -1711,18 +1728,18 @@ GList *filelist_recursive(FileData *dir_fd)
        return list;
 }
 
-GList *filelist_recursive_full(FileData *dir_fd, SortType method, gboolean ascend)
+GList *filelist_recursive_full(FileData *dir_fd, SortType method, gboolean ascend, gboolean case_sensitive)
 {
        GList *list;
        GList *d;
 
-       if (!filelist_read(dir_fd, &list, &d)) return NULL;
+       if (!filelist_read(dir_fd, &list, &d)) return nullptr;
        list = filelist_filter(list, FALSE);
-       list = filelist_sort_full(list, method, ascend, (GCompareFunc) filelist_sort_file_cb);
+       list = filelist_sort_full(list, method, ascend, case_sensitive, reinterpret_cast<GCompareFunc>(filelist_sort_file_cb));
 
        d = filelist_filter(d, TRUE);
        d = filelist_sort_path(d);
-       filelist_recursive_append_full(&list, d, method, ascend);
+       filelist_recursive_append_full(&list, d, method, ascend, case_sensitive);
        filelist_free(d);
 
        return list;
@@ -1746,7 +1763,7 @@ void file_data_change_info_free(FileDataChangeInfo *fdci, FileData *fd)
 
        g_free(fdci);
 
-       if (fd) fd->change = NULL;
+       if (fd) fd->change = nullptr;
 }
 
 static gboolean file_data_can_write_directly(FileData *fd)
@@ -1761,16 +1778,16 @@ static gboolean file_data_can_write_sidecar(FileData *fd)
 
 gchar *file_data_get_sidecar_path(FileData *fd, gboolean existing_only)
 {
-       gchar *sidecar_path = NULL;
+       gchar *sidecar_path = nullptr;
        GList *work;
 
-       if (!file_data_can_write_sidecar(fd)) return NULL;
+       if (!file_data_can_write_sidecar(fd)) return nullptr;
 
        work = fd->parent ? fd->parent->sidecar_files : fd->sidecar_files;
        gchar *extended_extension = g_strconcat(fd->parent ? fd->parent->extension : fd->extension, ".xmp", NULL);
        while (work)
                {
-               FileData *sfd = static_cast<FileData *>(work->data);
+               auto sfd = static_cast<FileData *>(work->data);
                work = work->next;
                if (g_ascii_strcasecmp(sfd->extension, ".xmp") == 0 || g_ascii_strcasecmp(sfd->extension, extended_extension) == 0)
                        {
@@ -1880,7 +1897,7 @@ GList *file_data_filter_marks_list(GList *list, guint filter)
        work = list;
        while (work)
                {
-               FileData *fd = static_cast<FileData *>(work->data);
+               auto fd = static_cast<FileData *>(work->data);
                GList *link = work;
                work = work->next;
 
@@ -1897,7 +1914,7 @@ GList *file_data_filter_marks_list(GList *list, guint filter)
 
 gboolean file_data_filter_file_filter(FileData *fd, GRegex *filter)
 {
-       return g_regex_match(filter, fd->name, (GRegexMatchFlags)0, NULL);
+       return g_regex_match(filter, fd->name, static_cast<GRegexMatchFlags>(0), nullptr);
 }
 
 GList *file_data_filter_file_filter_list(GList *list, GRegex *filter)
@@ -1907,7 +1924,7 @@ GList *file_data_filter_file_filter_list(GList *list, GRegex *filter)
        work = list;
        while (work)
                {
-               FileData *fd = static_cast<FileData *>(work->data);
+               auto fd = static_cast<FileData *>(work->data);
                GList *link = work;
                work = work->next;
 
@@ -1930,7 +1947,7 @@ static gboolean file_data_filter_class(FileData *fd, guint filter)
                {
                if (filter & (1 << i))
                        {
-                       if ((FileFormatClass)i == filter_file_get_class(fd->path))
+                       if (static_cast<FileFormatClass>(i) == filter_file_get_class(fd->path))
                                {
                                return TRUE;
                                }
@@ -1947,7 +1964,7 @@ GList *file_data_filter_class_list(GList *list, guint filter)
        work = list;
        while (work)
                {
-               FileData *fd = static_cast<FileData *>(work->data);
+               auto fd = static_cast<FileData *>(work->data);
                GList *link = work;
                work = work->next;
 
@@ -1962,9 +1979,9 @@ GList *file_data_filter_class_list(GList *list, guint filter)
        return list;
 }
 
-static void file_data_notify_mark_func(gpointer UNUSED(key), gpointer value, gpointer UNUSED(user_data))
+static void file_data_notify_mark_func(gpointer, gpointer value, gpointer)
 {
-       FileData *fd = static_cast<FileData *>(value);
+       auto fd = static_cast<FileData *>(value);
        file_data_increment_version(fd);
        file_data_send_notification(fd, NOTIFY_MARKS);
 }
@@ -1983,7 +2000,7 @@ gboolean file_data_register_mark_func(gint n, FileDataGetMarkFunc get_mark_func,
        if (get_mark_func && file_data_pool)
                {
                /* this effectively changes all known files */
-               g_hash_table_foreach(file_data_pool, file_data_notify_mark_func, NULL);
+               g_hash_table_foreach(file_data_pool, file_data_notify_mark_func, nullptr);
                }
 
         return TRUE;
@@ -1996,19 +2013,22 @@ void file_data_get_registered_mark_func(gint n, FileDataGetMarkFunc *get_mark_fu
        if (data) *data = file_data_mark_func_data[n];
 }
 
-//gint file_data_get_user_orientation(FileData *fd)
-//{
-       //return fd->user_orientation;
-//}
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-function"
+gint file_data_get_user_orientation_unused(FileData *fd)
+{
+       return fd->user_orientation;
+}
 
-//void file_data_set_user_orientation(FileData *fd, gint value)
-//{
-       //if (fd->user_orientation == value) return;
+void file_data_set_user_orientation_unused(FileData *fd, gint value)
+{
+       if (fd->user_orientation == value) return;
 
-       //fd->user_orientation = value;
-       //file_data_increment_version(fd);
-       //file_data_send_notification(fd, NOTIFY_ORIENTATION);
-//}
+       fd->user_orientation = value;
+       file_data_increment_version(fd);
+       file_data_send_notification(fd, NOTIFY_ORIENTATION);
+}
+#pragma GCC diagnostic pop
 
 
 /*
@@ -2026,7 +2046,7 @@ gchar *file_data_sc_list_to_string(FileData *fd)
        work = fd->sidecar_files;
        while (work)
                {
-               FileData *sfd = static_cast<FileData *>(work->data);
+               auto sfd = static_cast<FileData *>(work->data);
 
                result = g_string_append(result, "+ ");
                result = g_string_append(result, sfd->extension);
@@ -2097,7 +2117,7 @@ static void file_data_planned_change_remove(FileData *fd)
                        if (g_hash_table_size(file_data_planned_change_hash) == 0)
                                {
                                g_hash_table_destroy(file_data_planned_change_hash);
-                               file_data_planned_change_hash = NULL;
+                               file_data_planned_change_hash = nullptr;
                                DEBUG_1("planned change: empty");
                                }
                        }
@@ -2120,7 +2140,7 @@ void file_data_free_ci(FileData *fd)
 
        g_free(fdci);
 
-       fd->change = NULL;
+       fd->change = nullptr;
 }
 
 void file_data_set_regroup_when_finished(FileData *fd, gboolean enable)
@@ -2141,20 +2161,20 @@ static gboolean file_data_sc_add_ci(FileData *fd, FileDataChangeType type)
        work = fd->sidecar_files;
        while (work)
                {
-               FileData *sfd = static_cast<FileData *>(work->data);
+               auto sfd = static_cast<FileData *>(work->data);
 
                if (sfd->change) return FALSE;
                work = work->next;
                }
 
-       file_data_add_ci(fd, type, NULL, NULL);
+       file_data_add_ci(fd, type, nullptr, nullptr);
 
        work = fd->sidecar_files;
        while (work)
                {
-               FileData *sfd = static_cast<FileData *>(work->data);
+               auto sfd = static_cast<FileData *>(work->data);
 
-               file_data_add_ci(sfd, type, NULL, NULL);
+               file_data_add_ci(sfd, type, nullptr, nullptr);
                work = work->next;
                }
 
@@ -2172,7 +2192,7 @@ static gboolean file_data_sc_check_ci(FileData *fd, FileDataChangeType type)
        work = fd->sidecar_files;
        while (work)
                {
-               FileData *sfd = static_cast<FileData *>(work->data);
+               auto sfd = static_cast<FileData *>(work->data);
 
                if (!sfd->change || sfd->change->type != type) return FALSE;
                work = work->next;
@@ -2217,7 +2237,7 @@ gboolean file_data_sc_add_ci_unspecified(FileData *fd, const gchar *dest_path)
 
 gboolean file_data_add_ci_write_metadata(FileData *fd)
 {
-       return file_data_add_ci(fd, FILEDATA_CHANGE_WRITE_METADATA, NULL, NULL);
+       return file_data_add_ci(fd, FILEDATA_CHANGE_WRITE_METADATA, nullptr, nullptr);
 }
 
 void file_data_sc_free_ci(FileData *fd)
@@ -2231,7 +2251,7 @@ void file_data_sc_free_ci(FileData *fd)
        work = fd->sidecar_files;
        while (work)
                {
-               FileData *sfd = static_cast<FileData *>(work->data);
+               auto sfd = static_cast<FileData *>(work->data);
 
                file_data_free_ci(sfd);
                work = work->next;
@@ -2246,7 +2266,7 @@ gboolean file_data_sc_add_ci_delete_list(GList *fd_list)
        work = fd_list;
        while (work)
                {
-               FileData *fd = static_cast<FileData *>(work->data);
+               auto fd = static_cast<FileData *>(work->data);
 
                if (!file_data_sc_add_ci_delete(fd)) ret = FALSE;
                work = work->next;
@@ -2262,7 +2282,7 @@ static void file_data_sc_revert_ci_list(GList *fd_list)
        work = fd_list;
        while (work)
                {
-               FileData *fd = static_cast<FileData *>(work->data);
+               auto fd = static_cast<FileData *>(work->data);
 
                file_data_sc_free_ci(fd);
                work = work->prev;
@@ -2276,7 +2296,7 @@ static gboolean file_data_sc_add_ci_list_call_func(GList *fd_list, const gchar *
        work = fd_list;
        while (work)
                {
-               FileData *fd = static_cast<FileData *>(work->data);
+               auto fd = static_cast<FileData *>(work->data);
 
                if (!func(fd, dest))
                        {
@@ -2317,7 +2337,7 @@ gboolean file_data_add_ci_write_metadata_list(GList *fd_list)
        work = fd_list;
        while (work)
                {
-               FileData *fd = static_cast<FileData *>(work->data);
+               auto fd = static_cast<FileData *>(work->data);
 
                if (!file_data_add_ci_write_metadata(fd)) ret = FALSE;
                work = work->next;
@@ -2333,7 +2353,7 @@ void file_data_free_ci_list(GList *fd_list)
        work = fd_list;
        while (work)
                {
-               FileData *fd = static_cast<FileData *>(work->data);
+               auto fd = static_cast<FileData *>(work->data);
 
                file_data_free_ci(fd);
                work = work->next;
@@ -2347,7 +2367,7 @@ void file_data_sc_free_ci_list(GList *fd_list)
        work = fd_list;
        while (work)
                {
-               FileData *fd = static_cast<FileData *>(work->data);
+               auto fd = static_cast<FileData *>(work->data);
 
                file_data_sc_free_ci(fd);
                work = work->next;
@@ -2419,7 +2439,7 @@ static void file_data_update_ci_dest_preserve_ext(FileData *fd, const gchar *des
 static void file_data_sc_update_ci(FileData *fd, const gchar *dest_path)
 {
        GList *work;
-       gchar *dest_path_full = NULL;
+       gchar *dest_path_full = nullptr;
 
        if (fd->parent) fd = fd->parent;
 
@@ -2446,7 +2466,7 @@ static void file_data_sc_update_ci(FileData *fd, const gchar *dest_path)
        work = fd->sidecar_files;
        while (work)
                {
-               FileData *sfd = static_cast<FileData *>(work->data);
+               auto sfd = static_cast<FileData *>(work->data);
 
                file_data_update_ci_dest_preserve_ext(sfd, dest_path);
                work = work->next;
@@ -2492,7 +2512,7 @@ static gboolean file_data_sc_update_ci_list_call_func(GList *fd_list,
        work = fd_list;
        while (work)
                {
-               FileData *fd = static_cast<FileData *>(work->data);
+               auto fd = static_cast<FileData *>(work->data);
 
                if (!func(fd, dest)) ret = FALSE;
                work = work->next;
@@ -2526,8 +2546,8 @@ gint file_data_verify_ci(FileData *fd, GList *list)
 {
        gint ret = CHANGE_OK;
        gchar *dir;
-       GList *work = NULL;
-       FileData *fd1 = NULL;
+       GList *work = nullptr;
+       FileData *fd1 = nullptr;
 
        if (!fd->change)
                {
@@ -2584,7 +2604,7 @@ gint file_data_verify_ci(FileData *fd, GList *list)
                {
                /* determine destination file */
                gboolean have_dest = FALSE;
-               gchar *dest_dir = NULL;
+               gchar *dest_dir = nullptr;
 
                if (options->metadata.save_in_image_file)
                        {
@@ -2632,7 +2652,7 @@ gint file_data_verify_ci(FileData *fd, GList *list)
                        /* If an existing metadata file exists, we will try writing to
                         * it's location regardless of the user's preference.
                         */
-                       gchar *metadata_path = NULL;
+                       gchar *metadata_path = nullptr;
 #ifdef HAVE_EXIV2
                        /* but ignore XMP if we are not able to write it */
                        metadata_path = cache_find_location(CACHE_TYPE_XMP_METADATA, fd->path);
@@ -2642,7 +2662,7 @@ gint file_data_verify_ci(FileData *fd, GList *list)
                        if (metadata_path && !access_file(metadata_path, W_OK))
                                {
                                g_free(metadata_path);
-                               metadata_path = NULL;
+                               metadata_path = nullptr;
                                }
 
                        if (!metadata_path)
@@ -2661,7 +2681,6 @@ gint file_data_verify_ci(FileData *fd, GList *list)
                        if (access_file(metadata_path, W_OK) || (!isname(metadata_path) && access_file(dest_dir, W_OK)))
                                {
                                file_data_update_ci_dest(fd, metadata_path);
-                               have_dest = TRUE;
                                }
                        else
                                {
@@ -2751,7 +2770,7 @@ gint file_data_verify_ci(FileData *fd, GList *list)
                        {
                        fd1 = static_cast<FileData *>(work->data);
                        work = work->next;
-                       if (fd1 != NULL && fd != fd1 )
+                       if (fd1 != nullptr && fd != fd1 )
                                {
                                if (!strcmp(fd->change->dest, fd1->change->dest))
                                        {
@@ -2779,7 +2798,7 @@ gint file_data_sc_verify_ci(FileData *fd, GList *list)
        work = fd->sidecar_files;
        while (work)
                {
-               FileData *sfd = static_cast<FileData *>(work->data);
+               auto sfd = static_cast<FileData *>(work->data);
 
                ret |= file_data_verify_ci(sfd, list);
                work = work->next;
@@ -2969,15 +2988,25 @@ static gboolean file_data_perform_delete(FileData *fd)
 {
        if (isdir(fd->path) && !islink(fd->path))
                return rmdir_utf8(fd->path);
-       else
-               if (options->file_ops.safe_delete_enable)
-                       return file_util_safe_unlink(fd->path);
-               else
-                       return unlink_file(fd->path);
+
+       if (options->file_ops.safe_delete_enable)
+               return file_util_safe_unlink(fd->path);
+
+       return unlink_file(fd->path);
 }
 
 gboolean file_data_perform_ci(FileData *fd)
 {
+       /** @FIXME When a directory that is a symbolic link is deleted,
+        * at this point fd->change is null because no FileDataChangeInfo
+        * has been set up. Therefore there is a seg. fault.
+        * This code simply aborts the delete.
+        */
+       if (!fd->change)
+               {
+               return FALSE;
+               }
+
        FileDataChangeType type = fd->change->type;
 
        switch (type)
@@ -3012,7 +3041,7 @@ gboolean file_data_sc_perform_ci(FileData *fd)
        work = fd->sidecar_files;
        while (work)
                {
-               FileData *sfd = static_cast<FileData *>(work->data);
+               auto sfd = static_cast<FileData *>(work->data);
 
                if (!file_data_perform_ci(sfd)) ret = FALSE;
                work = work->next;
@@ -3068,7 +3097,7 @@ gboolean file_data_sc_apply_ci(FileData *fd)
        work = fd->sidecar_files;
        while (work)
                {
-               FileData *sfd = static_cast<FileData *>(work->data);
+               auto sfd = static_cast<FileData *>(work->data);
 
                file_data_apply_ci(sfd);
                work = work->next;
@@ -3096,7 +3125,7 @@ static gboolean file_data_list_contains_whole_group(GList *list, FileData *fd)
 
 GList *file_data_process_groups_in_selection(GList *list, gboolean ungroup, GList **ungrouped_list)
 {
-       GList *out = NULL;
+       GList *out = nullptr;
        GList *work = list;
 
        /* change partial groups to independent files */
@@ -3104,7 +3133,7 @@ GList *file_data_process_groups_in_selection(GList *list, gboolean ungroup, GLis
                {
                while (work)
                        {
-                       FileData *fd = static_cast<FileData *>(work->data);
+                       auto fd = static_cast<FileData *>(work->data);
                        work = work->next;
 
                        if (!file_data_list_contains_whole_group(list, fd))
@@ -3123,7 +3152,7 @@ GList *file_data_process_groups_in_selection(GList *list, gboolean ungroup, GLis
        work = list;
        while (work)
                {
-               FileData *fd = static_cast<FileData *>(work->data);
+               auto fd = static_cast<FileData *>(work->data);
                work = work->next;
 
                if (!fd->parent ||
@@ -3152,28 +3181,24 @@ GList *file_data_process_groups_in_selection(GList *list, gboolean ungroup, GLis
    implementation in view-file-list.cc */
 
 
-typedef struct _NotifyIdleData NotifyIdleData;
-
-struct _NotifyIdleData {
+struct NotifyIdleData {
        FileData *fd;
        NotifyType type;
 };
 
 
-typedef struct _NotifyData NotifyData;
-
-struct _NotifyData {
+struct NotifyData {
        FileDataNotifyFunc func;
        gpointer data;
        NotifyPriority priority;
 };
 
-static GList *notify_func_list = NULL;
+static GList *notify_func_list = nullptr;
 
 static gint file_data_notify_sort(gconstpointer a, gconstpointer b)
 {
-       NotifyData *nda = (NotifyData *)a;
-       NotifyData *ndb = (NotifyData *)b;
+       auto nda = static_cast<const NotifyData *>(a);
+       auto ndb = static_cast<const NotifyData *>(b);
 
        if (nda->priority < ndb->priority) return -1;
        if (nda->priority > ndb->priority) return 1;
@@ -3187,7 +3212,7 @@ gboolean file_data_register_notify_func(FileDataNotifyFunc func, gpointer data,
 
        while (work)
                {
-               NotifyData *nd = (NotifyData *)work->data;
+               auto nd = static_cast<NotifyData *>(work->data);
 
                if (nd->func == func && nd->data == data)
                        {
@@ -3214,13 +3239,13 @@ gboolean file_data_unregister_notify_func(FileDataNotifyFunc func, gpointer data
 
        while (work)
                {
-               NotifyData *nd = (NotifyData *)work->data;
+               auto nd = static_cast<NotifyData *>(work->data);
 
                if (nd->func == func && nd->data == data)
                        {
                        notify_func_list = g_list_delete_link(notify_func_list, work);
-                       g_free(nd);
                        DEBUG_2("Notify func unregistered: %p", (void *)nd);
+                       g_free(nd);
                        return TRUE;
                        }
                work = work->next;
@@ -3230,23 +3255,25 @@ gboolean file_data_unregister_notify_func(FileDataNotifyFunc func, gpointer data
        return FALSE;
 }
 
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-function"
+gboolean file_data_send_notification_idle_cb_unused(gpointer data)
+{
+       auto *nid = (NotifyIdleData *)data;
+       GList *work = notify_func_list;
 
-//gboolean file_data_send_notification_idle_cb(gpointer data)
-//{
-       //NotifyIdleData *nid = (NotifyIdleData *)data;
-       //GList *work = notify_func_list;
-
-       //while (work)
-               //{
-               //NotifyData *nd = (NotifyData *)work->data;
+       while (work)
+               {
+               auto *nd = (NotifyData *)work->data;
 
-               //nd->func(nid->fd, nid->type, nd->data);
-               //work = work->next;
-               //}
-       //file_data_unref(nid->fd);
-       //g_free(nid);
-       //return FALSE;
-//}
+               nd->func(nid->fd, nid->type, nd->data);
+               work = work->next;
+               }
+       file_data_unref(nid->fd);
+       g_free(nid);
+       return FALSE;
+}
+#pragma GCC diagnostic pop
 
 void file_data_send_notification(FileData *fd, NotifyType type)
 {
@@ -3254,7 +3281,7 @@ void file_data_send_notification(FileData *fd, NotifyType type)
 
        while (work)
                {
-               NotifyData *nd = (NotifyData *)work->data;
+               auto nd = static_cast<NotifyData *>(work->data);
 
                nd->func(fd, type, nd->data);
                work = work->next;
@@ -3267,22 +3294,22 @@ void file_data_send_notification(FileData *fd, NotifyType type)
     */
 }
 
-static GHashTable *file_data_monitor_pool = NULL;
+static GHashTable *file_data_monitor_pool = nullptr;
 static guint realtime_monitor_id = 0; /* event source id */
 
-static void realtime_monitor_check_cb(gpointer key, gpointer UNUSED(value), gpointer UNUSED(data))
+static void realtime_monitor_check_cb(gpointer key, gpointer, gpointer)
 {
-       FileData *fd = static_cast<FileData *>(key);
+       auto fd = static_cast<FileData *>(key);
 
        file_data_check_changed_files(fd);
 
        DEBUG_1("monitor %s", fd->path);
 }
 
-static gboolean realtime_monitor_cb(gpointer UNUSED(data))
+static gboolean realtime_monitor_cb(gpointer)
 {
        if (!options->update_on_time_change) return TRUE;
-       g_hash_table_foreach(file_data_monitor_pool, realtime_monitor_check_cb, NULL);
+       g_hash_table_foreach(file_data_monitor_pool, realtime_monitor_check_cb, nullptr);
        return TRUE;
 }
 
@@ -3304,7 +3331,7 @@ gboolean file_data_register_real_time_monitor(FileData *fd)
 
        if (!realtime_monitor_id)
                {
-               realtime_monitor_id = g_timeout_add(5000, realtime_monitor_cb, NULL);
+               realtime_monitor_id = g_timeout_add(5000, realtime_monitor_cb, nullptr);
                }
 
        return TRUE;
@@ -3350,8 +3377,8 @@ gboolean file_data_unregister_real_time_monitor(FileData *fd)
 
 static void marks_get_files(gpointer key, gpointer value, gpointer userdata)
 {
-       gchar *file_name = static_cast<gchar *>(key);
-       GString *result = static_cast<GString *>(userdata);
+       auto file_name = static_cast<gchar *>(key);
+       auto result = static_cast<GString *>(userdata);
        FileData *fd;
 
        if (isfile(file_name))
@@ -3389,7 +3416,7 @@ gboolean marks_list_load(const gchar *path)
                {
                if (s_buf[0]=='#') continue;
                        file_path = strtok(s_buf, ",");
-                       marks_value = strtok(NULL, ",");
+                       marks_value = strtok(nullptr, ",");
                        if (isfile(file_path))
                                {
                                FileData *fd = file_data_new_no_grouping(file_path);
@@ -3415,7 +3442,6 @@ gboolean marks_list_save(gchar *path, gboolean save)
 {
        SecureSaveInfo *ssi;
        gchar *pathl;
-       GString  *marks = g_string_new("");
 
        pathl = path_from_utf8(path);
        ssi = secure_open(pathl);
@@ -3428,20 +3454,21 @@ gboolean marks_list_save(gchar *path, gboolean save)
 
        secure_fprintf(ssi, "#Marks lists\n");
 
+       GString *marks = g_string_new("");
        if (save)
                {
                g_hash_table_foreach(file_data_pool, marks_get_files, marks);
                }
        secure_fprintf(ssi, "%s", marks->str);
-       g_string_free(marks, FALSE);
+       g_string_free(marks, TRUE);
 
        secure_fprintf(ssi, "#end\n");
        return (secure_close(ssi) == 0);
 }
 
-static void marks_clear(gpointer key, gpointer value, gpointer UNUSED(userdata))
+static void marks_clear(gpointer key, gpointer value, gpointer)
 {
-       gchar *file_name = static_cast<gchar *>(key);
+       auto file_name = static_cast<gchar *>(key);
        gint mark_no;
        gint n;
        FileData *fd;
@@ -3467,7 +3494,7 @@ static void marks_clear(gpointer key, gpointer value, gpointer UNUSED(userdata))
 
 void marks_clear_all()
 {
-       g_hash_table_foreach(file_data_pool, marks_clear, NULL);
+       g_hash_table_foreach(file_data_pool, marks_clear, nullptr);
 }
 
 void file_data_set_page_num(FileData *fd, gint page_num)