Sort headers using clang-tidy
[geeqie.git] / src / view-file / view-file-list.cc
index 8b446e5..bcd1145 100644 (file)
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#include "main.h"
 #include "view-file-list.h"
 
+#include <config.h>
+
 #include "collect.h"
+#include "debug.h"
 #include "dnd.h"
 #include "img-view.h"
-#include "layout.h"
+#include "intl.h"
 #include "layout-image.h"
+#include "layout.h"
+#include "main-defines.h"
 #include "metadata.h"
 #include "misc.h"
-#include "utilops.h"
 #include "ui-fileops.h"
 #include "ui-misc.h"
 #include "ui-tree-edit.h"
 #include "uri-utils.h"
+#include "utilops.h"
 #include "view-file.h"
 
+#include <vector>
+
 /* Index to tree store */
 enum {
        FILE_COLUMN_POINTER = 0,
@@ -83,16 +89,16 @@ static void vflist_set_expanded(ViewFile *vf, GtkTreeIter *iter, gboolean expand
  * misc
  *-----------------------------------------------------------------------------
  */
-typedef struct {
-       FileData *fd;
+struct ViewFileFindRowData {
+       const FileData *fd;
        GtkTreeIter *iter;
        gboolean found;
        gint row;
-} ViewFileFindRowData;
+};
 
-static gboolean vflist_find_row_cb(GtkTreeModel *model, GtkTreePath *UNUSED(path), GtkTreeIter *iter, gpointer data)
+static gboolean vflist_find_row_cb(GtkTreeModel *model, GtkTreePath *, GtkTreeIter *iter, gpointer data)
 {
-       ViewFileFindRowData *find = data;
+       auto find = static_cast<ViewFileFindRowData *>(data);
        FileData *fd;
        gtk_tree_model_get(model, iter, FILE_COLUMN_POINTER, &fd, -1);
        if (fd == find->fd)
@@ -105,7 +111,7 @@ static gboolean vflist_find_row_cb(GtkTreeModel *model, GtkTreePath *UNUSED(path
        return FALSE;
 }
 
-static gint vflist_find_row(ViewFile *vf, FileData *fd, GtkTreeIter *iter)
+static gint vflist_find_row(const ViewFile *vf, const FileData *fd, GtkTreeIter *iter)
 {
        GtkTreeModel *store;
        ViewFileFindRowData data = {fd, iter, FALSE, 0};
@@ -121,13 +127,13 @@ static gint vflist_find_row(ViewFile *vf, FileData *fd, GtkTreeIter *iter)
        return -1;
 }
 
-static FileData *vflist_find_data_by_coord(ViewFile *vf, gint x, gint y, GtkTreeIter *UNUSED(iter))
+static FileData *vflist_find_data_by_coord(ViewFile *vf, gint x, gint y, GtkTreeIter *)
 {
        GtkTreePath *tpath;
        GtkTreeViewColumn *column;
 
        if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(vf->listview), x, y,
-                                         &tpath, &column, NULL, NULL))
+                                         &tpath, &column, nullptr, nullptr))
                {
                GtkTreeModel *store;
                GtkTreeIter row;
@@ -141,10 +147,10 @@ static FileData *vflist_find_data_by_coord(ViewFile *vf, gint x, gint y, GtkTree
                return fd;
                }
 
-       return NULL;
+       return nullptr;
 }
 
-static gboolean vflist_store_clear_cb(GtkTreeModel *model, GtkTreePath *UNUSED(path), GtkTreeIter *iter, gpointer UNUSED(data))
+static gboolean vflist_store_clear_cb(GtkTreeModel *model, GtkTreePath *, GtkTreeIter *iter, gpointer)
 {
        FileData *fd;
        gtk_tree_model_get(model, iter, FILE_COLUMN_POINTER, &fd, -1);
@@ -159,16 +165,17 @@ static gboolean vflist_store_clear_cb(GtkTreeModel *model, GtkTreePath *UNUSED(p
 static void vflist_store_clear(ViewFile *vf, gboolean unlock_files)
 {
        GtkTreeModel *store;
-       GList *files = NULL;
+       GList *files = nullptr;
 
        if (unlock_files && vf->marks_enabled)
                {
                // unlock locked files in this directory
-               filelist_read(vf->dir_fd, &files, NULL);
-               while (files)
+               filelist_read(vf->dir_fd, &files, nullptr);
+               GList *work = files;
+               while (work)
                        {
-                       FileData *fd = files->data;
-                       files = files->next;
+                       auto fd = static_cast<FileData *>(work->data);
+                       work = work->next;
                        file_data_unlock(fd);
                        file_data_unref(fd);  // undo the ref that got added in filelist_read
                        }
@@ -176,7 +183,7 @@ static void vflist_store_clear(ViewFile *vf, gboolean unlock_files)
 
        g_list_free(files);
        store = gtk_tree_view_get_model(GTK_TREE_VIEW(vf->listview));
-       gtk_tree_model_foreach(store, vflist_store_clear_cb, NULL);
+       gtk_tree_model_foreach(store, vflist_store_clear_cb, nullptr);
        gtk_tree_store_clear(GTK_TREE_STORE(store));
 }
 
@@ -198,7 +205,7 @@ static void vflist_move_cursor(ViewFile *vf, GtkTreeIter *iter)
        store = gtk_tree_view_get_model(GTK_TREE_VIEW(vf->listview));
 
        tpath = gtk_tree_model_get_path(store, iter);
-       gtk_tree_view_set_cursor(GTK_TREE_VIEW(vf->listview), tpath, NULL, FALSE);
+       gtk_tree_view_set_cursor(GTK_TREE_VIEW(vf->listview), tpath, nullptr, FALSE);
        gtk_tree_path_free(tpath);
 }
 
@@ -209,12 +216,12 @@ static void vflist_move_cursor(ViewFile *vf, GtkTreeIter *iter)
  *-----------------------------------------------------------------------------
  */
 
-static void vflist_dnd_get(GtkWidget *UNUSED(widget), GdkDragContext *UNUSED(context),
-                          GtkSelectionData *selection_data, guint UNUSED(info),
-                          guint UNUSED(time), gpointer data)
+static void vflist_dnd_get(GtkWidget *, GdkDragContext *,
+                          GtkSelectionData *selection_data, guint,
+                          guint, gpointer data)
 {
-       ViewFile *vf = data;
-       GList *list = NULL;
+       auto vf = static_cast<ViewFile *>(data);
+       GList *list = nullptr;
 
        if (!VFLIST(vf)->click_fd) return;
 
@@ -224,7 +231,7 @@ static void vflist_dnd_get(GtkWidget *UNUSED(widget), GdkDragContext *UNUSED(con
                }
        else
                {
-               list = g_list_append(NULL, file_data_ref(VFLIST(vf)->click_fd));
+               list = g_list_append(nullptr, file_data_ref(VFLIST(vf)->click_fd));
                }
 
        if (!list) return;
@@ -234,7 +241,7 @@ static void vflist_dnd_get(GtkWidget *UNUSED(widget), GdkDragContext *UNUSED(con
 
 static void vflist_dnd_begin(GtkWidget *widget, GdkDragContext *context, gpointer data)
 {
-       ViewFile *vf = data;
+       auto vf = static_cast<ViewFile *>(data);
 
        vflist_color_set(vf, VFLIST(vf)->click_fd, TRUE);
 
@@ -244,7 +251,7 @@ static void vflist_dnd_begin(GtkWidget *widget, GdkDragContext *context, gpointe
                guint items;
 
                if (vflist_row_is_selected(vf, VFLIST(vf)->click_fd))
-                       items = vf_selection_count(vf, NULL);
+                       items = vf_selection_count(vf, nullptr);
                else
                        items = 1;
 
@@ -252,9 +259,9 @@ static void vflist_dnd_begin(GtkWidget *widget, GdkDragContext *context, gpointe
                }
 }
 
-static void vflist_dnd_end(GtkWidget *UNUSED(widget), GdkDragContext *context, gpointer data)
+static void vflist_dnd_end(GtkWidget *, GdkDragContext *context, gpointer data)
 {
-       ViewFile *vf = data;
+       auto vf = static_cast<ViewFile *>(data);
 
        vflist_color_set(vf, VFLIST(vf)->click_fd, FALSE);
 
@@ -264,22 +271,22 @@ static void vflist_dnd_end(GtkWidget *UNUSED(widget), GdkDragContext *context, g
                }
 }
 
-static void vflist_drag_data_received(GtkWidget *UNUSED(entry_widget), GdkDragContext *UNUSED(context),
+static void vflist_drag_data_received(GtkWidget *, GdkDragContext *,
                                      int x, int y, GtkSelectionData *selection,
-                                     guint info, guint UNUSED(time), gpointer data)
+                                     guint info, guint, gpointer data)
 {
-       ViewFile *vf = data;
+       auto vf = static_cast<ViewFile *>(data);
 
        if (info == TARGET_TEXT_PLAIN) {
-               FileData *fd = vflist_find_data_by_coord(vf, x, y, NULL);
+               FileData *fd = vflist_find_data_by_coord(vf, x, y, nullptr);
 
                if (fd) {
                        /* Add keywords to file */
-                       gchar *str = (gchar *) gtk_selection_data_get_text(selection);
+                       auto str = reinterpret_cast<gchar *>(gtk_selection_data_get_text(selection));
                        GList *kw_list = string_to_keywords_list(str);
 
                        metadata_append_list(fd, KEYWORD_KEY, kw_list);
-                       string_list_free(kw_list);
+                       g_list_free_full(kw_list, g_free);
                        g_free(str);
                }
        }
@@ -287,12 +294,12 @@ static void vflist_drag_data_received(GtkWidget *UNUSED(entry_widget), GdkDragCo
 
 void vflist_dnd_init(ViewFile *vf)
 {
-       gtk_drag_source_set(vf->listview, GDK_BUTTON1_MASK | GDK_BUTTON2_MASK,
+       gtk_drag_source_set(vf->listview, static_cast<GdkModifierType>(GDK_BUTTON1_MASK | GDK_BUTTON2_MASK),
                            dnd_file_drag_types, dnd_file_drag_types_count,
-                           GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK);
+                           static_cast<GdkDragAction>(GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK));
        gtk_drag_dest_set(vf->listview, GTK_DEST_DEFAULT_ALL,
                            dnd_file_drag_types, dnd_file_drag_types_count,
-                           GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK);
+                           static_cast<GdkDragAction>(GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK));
 
        g_signal_connect(G_OBJECT(vf->listview), "drag_data_get",
                         G_CALLBACK(vflist_dnd_get), vf);
@@ -312,7 +319,7 @@ void vflist_dnd_init(ViewFile *vf)
 
 GList *vflist_selection_get_one(ViewFile *vf, FileData *fd)
 {
-       GList *list = g_list_append(NULL, file_data_ref(fd));
+       GList *list = nullptr;
 
        if (fd->sidecar_files)
                {
@@ -329,25 +336,18 @@ GList *vflist_selection_get_one(ViewFile *vf, FileData *fd)
                        if (!gtk_tree_view_row_expanded(GTK_TREE_VIEW(vf->listview), tpath))
                                {
                                /* unexpanded - add whole group */
-                               GList *work = fd->sidecar_files;
-                               while (work)
-                                       {
-                                       FileData *sfd = work->data;
-                                       list = g_list_prepend(list, file_data_ref(sfd));
-                                       work = work->next;
-                                       }
+                               list = filelist_copy(fd->sidecar_files);
                                }
                        gtk_tree_path_free(tpath);
                        }
-               list = g_list_reverse(list);
                }
 
-       return list;
+       return g_list_prepend(list, file_data_ref(fd));
 }
 
 GList *vflist_pop_menu_file_list(ViewFile *vf)
 {
-       if (!VFLIST(vf)->click_fd) return NULL;
+       if (!VFLIST(vf)->click_fd) return nullptr;
 
        if (vflist_row_is_selected(vf, VFLIST(vf)->click_fd))
                {
@@ -357,9 +357,9 @@ GList *vflist_pop_menu_file_list(ViewFile *vf)
 }
 
 
-void vflist_pop_menu_view_cb(GtkWidget *UNUSED(widget), gpointer data)
+void vflist_pop_menu_view_cb(GtkWidget *, gpointer data)
 {
-       ViewFile *vf = data;
+       auto vf = static_cast<ViewFile *>(data);
 
        if (vflist_row_is_selected(vf, VFLIST(vf)->click_fd))
                {
@@ -375,9 +375,9 @@ void vflist_pop_menu_view_cb(GtkWidget *UNUSED(widget), gpointer data)
                }
 }
 
-void vflist_pop_menu_rename_cb(GtkWidget *UNUSED(widget), gpointer data)
+void vflist_pop_menu_rename_cb(GtkWidget *, gpointer data)
 {
-       ViewFile *vf = data;
+       auto vf = static_cast<ViewFile *>(data);
        GList *list;
 
        list = vf_pop_menu_file_list(vf);
@@ -403,12 +403,12 @@ void vflist_pop_menu_rename_cb(GtkWidget *UNUSED(widget), gpointer data)
                return;
                }
 
-       file_util_rename(NULL, list, vf->listview);
+       file_util_rename(nullptr, list, vf->listview);
 }
 
-void vflist_pop_menu_thumbs_cb(GtkWidget *UNUSED(widget), gpointer data)
+void vflist_pop_menu_thumbs_cb(GtkWidget *, gpointer data)
 {
-       ViewFile *vf = data;
+       auto vf = static_cast<ViewFile *>(data);
 
        vflist_color_set(vf, VFLIST(vf)->click_fd, FALSE);
        if (vf->layout)
@@ -423,14 +423,15 @@ void vflist_pop_menu_thumbs_cb(GtkWidget *UNUSED(widget), gpointer data)
 
 void vflist_star_rating_set(ViewFile *vf, gboolean enable)
 {
-       GList *columns, *work;
+       GList *columns;
+       GList *work;
 
        columns = gtk_tree_view_get_columns(GTK_TREE_VIEW(vf->listview));
 
        work = columns;
        while (work)
                {
-               GtkTreeViewColumn *column = work->data;
+               auto column = static_cast<GtkTreeViewColumn *>(work->data);
                gint col_idx = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(column), "column_store_idx"));
                work = work->next;
 
@@ -456,9 +457,9 @@ void vflist_star_rating_set(ViewFile *vf, gboolean enable)
        g_list_free(columns);
 }
 
-void vflist_pop_menu_show_star_rating_cb(GtkWidget *UNUSED(widget), gpointer data)
+void vflist_pop_menu_show_star_rating_cb(GtkWidget *, gpointer data)
 {
-       ViewFile *vf = data;
+       auto vf = static_cast<ViewFile *>(data);
 
        options->show_star_rating = !options->show_star_rating;
 
@@ -468,21 +469,21 @@ void vflist_pop_menu_show_star_rating_cb(GtkWidget *UNUSED(widget), gpointer dat
        vflist_star_rating_set(vf, options->show_star_rating);
 }
 
-void vflist_pop_menu_refresh_cb(GtkWidget *UNUSED(widget), gpointer data)
+void vflist_pop_menu_refresh_cb(GtkWidget *, gpointer data)
 {
-       ViewFile *vf = data;
+       auto vf = static_cast<ViewFile *>(data);
 
        vflist_color_set(vf, VFLIST(vf)->click_fd, FALSE);
        vf_refresh(vf);
        gtk_tree_view_columns_autosize(GTK_TREE_VIEW(vf->listview));
 }
 
-void vflist_popup_destroy_cb(GtkWidget *UNUSED(widget), gpointer data)
+void vflist_popup_destroy_cb(GtkWidget *, gpointer data)
 {
-       ViewFile *vf = data;
+       auto vf = static_cast<ViewFile *>(data);
        vflist_color_set(vf, VFLIST(vf)->click_fd, FALSE);
-       VFLIST(vf)->click_fd = NULL;
-       vf->popup = NULL;
+       VFLIST(vf)->click_fd = nullptr;
+       vf->popup = nullptr;
 }
 
 
@@ -492,19 +493,19 @@ void vflist_popup_destroy_cb(GtkWidget *UNUSED(widget), gpointer data)
  *-----------------------------------------------------------------------------
  */
 
-static gboolean vflist_row_rename_cb(TreeEditData *UNUSED(td), const gchar *old_name, const gchar *new_name, gpointer data)
+static gboolean vflist_row_rename_cb(TreeEditData *, const gchar *old_name, const gchar *new_name, gpointer data)
 {
-       ViewFile *vf = data;
+       auto vf = static_cast<ViewFile *>(data);
        gchar *new_path;
 
        if (!new_name || !new_name[0]) return FALSE;
 
        new_path = g_build_filename(vf->dir_fd->path, new_name, NULL);
 
-       if (strchr(new_name, G_DIR_SEPARATOR) != NULL)
+       if (strchr(new_name, G_DIR_SEPARATOR) != nullptr)
                {
                gchar *text = g_strdup_printf(_("Invalid file name:\n%s"), new_name);
-               file_util_warning_dialog(_("Error renaming file"), text, GTK_STOCK_DIALOG_ERROR, vf->listview);
+               file_util_warning_dialog(_("Error renaming file"), text, GQ_ICON_DIALOG_ERROR, vf->listview);
                g_free(text);
                }
        else
@@ -523,12 +524,12 @@ static gboolean vflist_row_rename_cb(TreeEditData *UNUSED(td), const gchar *old_
 
 gboolean vflist_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
 {
-       ViewFile *vf = data;
+       auto vf = static_cast<ViewFile *>(data);
        GtkTreePath *tpath;
 
        if (event->keyval != GDK_KEY_Menu) return FALSE;
 
-       gtk_tree_view_get_cursor(GTK_TREE_VIEW(vf->listview), &tpath, NULL);
+       gtk_tree_view_get_cursor(GTK_TREE_VIEW(vf->listview), &tpath, nullptr);
        if (tpath)
                {
                GtkTreeModel *store;
@@ -541,27 +542,27 @@ gboolean vflist_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer dat
                }
        else
                {
-               VFLIST(vf)->click_fd = NULL;
+               VFLIST(vf)->click_fd = nullptr;
                }
 
        vf->popup = vf_pop_menu(vf);
-       gtk_menu_popup_at_widget(GTK_MENU(vf->popup), widget, GDK_GRAVITY_EAST, GDK_GRAVITY_CENTER, NULL);
+       gtk_menu_popup_at_widget(GTK_MENU(vf->popup), widget, GDK_GRAVITY_EAST, GDK_GRAVITY_CENTER, nullptr);
 
        return TRUE;
 }
 
 gboolean vflist_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
 {
-       ViewFile *vf = data;
+       auto vf = static_cast<ViewFile *>(data);
        GtkTreePath *tpath;
        GtkTreeIter iter;
-       FileData *fd = NULL;
+       FileData *fd = nullptr;
        GtkTreeViewColumn *column;
 
        vf->clicked_mark = 0;
 
        if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bevent->x, bevent->y,
-                                         &tpath, &column, NULL, NULL))
+                                         &tpath, &column, nullptr, nullptr))
                {
                GtkTreeModel *store;
                gint col_idx = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(column), "column_store_idx"));
@@ -585,7 +586,7 @@ gboolean vflist_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer dat
        if (bevent->button == MOUSE_BUTTON_RIGHT)
                {
                vf->popup = vf_pop_menu(vf);
-               gtk_menu_popup_at_pointer(GTK_MENU(vf->popup), NULL);
+               gtk_menu_popup_at_pointer(GTK_MENU(vf->popup), nullptr);
                return TRUE;
                }
 
@@ -636,10 +637,10 @@ gboolean vflist_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer dat
 
 gboolean vflist_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
 {
-       ViewFile *vf = data;
+       auto vf = static_cast<ViewFile *>(data);
        GtkTreePath *tpath;
        GtkTreeIter iter;
-       FileData *fd = NULL;
+       FileData *fd = nullptr;
 
        if (defined_mouse_buttons(widget, bevent, vf->layout))
                {
@@ -658,7 +659,7 @@ gboolean vflist_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer d
 
        if ((bevent->x != 0 || bevent->y != 0) &&
            gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bevent->x, bevent->y,
-                                         &tpath, NULL, NULL, NULL))
+                                         &tpath, nullptr, nullptr, nullptr))
                {
                GtkTreeModel *store;
 
@@ -705,7 +706,7 @@ gboolean vflist_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer d
 
 static void vflist_select_image(ViewFile *vf, FileData *sel_fd)
 {
-       FileData *read_ahead_fd = NULL;
+       FileData *read_ahead_fd = nullptr;
        gint row;
        FileData *cur_fd;
 
@@ -720,7 +721,7 @@ static void vflist_select_image(ViewFile *vf, FileData *sel_fd)
        if (sel_fd && options->image.enable_read_ahead && row >= 0)
                {
                if (row > g_list_index(vf->list, cur_fd) &&
-                   (guint) (row + 1) < vf_count(vf, NULL))
+                   static_cast<guint>(row + 1) < vf_count(vf, nullptr))
                        {
                        read_ahead_fd = vf_index_get_data(vf, row + 1);
                        }
@@ -735,12 +736,12 @@ static void vflist_select_image(ViewFile *vf, FileData *sel_fd)
 
 static gboolean vflist_select_idle_cb(gpointer data)
 {
-       ViewFile *vf = data;
+       auto vf = static_cast<ViewFile *>(data);
 
        if (!vf->layout)
                {
                VFLIST(vf)->select_idle_id = 0;
-               return FALSE;
+               return G_SOURCE_REMOVE;
                }
 
        vf_send_update(vf);
@@ -748,11 +749,11 @@ static gboolean vflist_select_idle_cb(gpointer data)
        if (VFLIST(vf)->select_fd)
                {
                vflist_select_image(vf, VFLIST(vf)->select_fd);
-               VFLIST(vf)->select_fd = NULL;
+               VFLIST(vf)->select_fd = nullptr;
                }
 
        VFLIST(vf)->select_idle_id = 0;
-       return FALSE;
+       return G_SOURCE_REMOVE;
 }
 
 static void vflist_select_idle_cancel(ViewFile *vf)
@@ -764,17 +765,17 @@ static void vflist_select_idle_cancel(ViewFile *vf)
                }
 }
 
-static gboolean vflist_select_cb(GtkTreeSelection *UNUSED(selection), GtkTreeModel *store, GtkTreePath *tpath, gboolean path_currently_selected, gpointer data)
+static gboolean vflist_select_cb(GtkTreeSelection *, GtkTreeModel *store, GtkTreePath *tpath, gboolean path_currently_selected, gpointer data)
 {
-       ViewFile *vf = data;
+       auto vf = static_cast<ViewFile *>(data);
        GtkTreeIter iter;
        GtkTreePath *cursor_path;
 
-       VFLIST(vf)->select_fd = NULL;
+       VFLIST(vf)->select_fd = nullptr;
 
        if (!path_currently_selected && gtk_tree_model_get_iter(store, &iter, tpath))
                {
-               gtk_tree_view_get_cursor(GTK_TREE_VIEW(vf->listview), &cursor_path, NULL);
+               gtk_tree_view_get_cursor(GTK_TREE_VIEW(vf->listview), &cursor_path, nullptr);
                if (cursor_path)
                        {
                        gtk_tree_model_get_iter(store, &iter, cursor_path);
@@ -792,15 +793,15 @@ static gboolean vflist_select_cb(GtkTreeSelection *UNUSED(selection), GtkTreeMod
        return TRUE;
 }
 
-static void vflist_expand_cb(GtkTreeView *UNUSED(tree_view), GtkTreeIter *iter, GtkTreePath *UNUSED(path), gpointer data)
+static void vflist_expand_cb(GtkTreeView *, GtkTreeIter *iter, GtkTreePath *, gpointer data)
 {
-       ViewFile *vf = data;
+       auto vf = static_cast<ViewFile *>(data);
        vflist_set_expanded(vf, iter, TRUE);
 }
 
-static void vflist_collapse_cb(GtkTreeView *UNUSED(tree_view), GtkTreeIter *iter, GtkTreePath *UNUSED(path), gpointer data)
+static void vflist_collapse_cb(GtkTreeView *, GtkTreeIter *iter, GtkTreePath *, gpointer data)
 {
-       ViewFile *vf = data;
+       auto vf = static_cast<ViewFile *>(data);
        vflist_set_expanded(vf, iter, FALSE);
 }
 
@@ -854,7 +855,7 @@ static void vflist_set_expanded(ViewFile *vf, GtkTreeIter *iter, gboolean expand
                                        FILE_COLUMN_STAR_RATING, &star_rating,
                                        -1);
 
-       formatted = vflist_get_formatted(vf, name, sidecars, size, time, expanded, FALSE, NULL);
+       formatted = vflist_get_formatted(vf, name, sidecars, size, time, expanded, FALSE, nullptr);
        formatted_with_stars = vflist_get_formatted(vf, name, sidecars, size, time, expanded, TRUE, star_rating);
 
        gtk_tree_store_set(store, iter, FILE_COLUMN_FORMATTED, formatted,
@@ -874,10 +875,10 @@ static void vflist_set_expanded(ViewFile *vf, GtkTreeIter *iter, gboolean expand
 static void vflist_setup_iter(ViewFile *vf, GtkTreeStore *store, GtkTreeIter *iter, FileData *fd)
 {
        gchar *size;
-       gchar *sidecars = NULL;
+       gchar *sidecars = nullptr;
        gchar *name;
        const gchar *time = text_from_time(fd->date);
-       gchar *link = islink(fd->path) ? GQ_LINK_STR : "";
+       const gchar *link = islink(fd->path) ? GQ_LINK_STR : "";
        const gchar *disabled_grouping;
        gchar *formatted;
        gchar *formatted_with_stars;
@@ -890,7 +891,7 @@ static void vflist_setup_iter(ViewFile *vf, GtkTreeStore *store, GtkTreeIter *it
                }
        else
                {
-               star_rating = NULL;
+               star_rating = nullptr;
                }
 
        if (fd->sidecar_files) /* expanded has no effect on files without sidecars */
@@ -904,7 +905,7 @@ static void vflist_setup_iter(ViewFile *vf, GtkTreeStore *store, GtkTreeIter *it
        name = g_strdup_printf("%s%s%s", link, fd->name, disabled_grouping);
        size = text_from_size(fd->size);
 
-       formatted = vflist_get_formatted(vf, name, sidecars, size, time, expanded, FALSE, NULL);
+       formatted = vflist_get_formatted(vf, name, sidecars, size, time, expanded, FALSE, nullptr);
        formatted_with_stars = vflist_get_formatted(vf, name, sidecars, size, time, expanded, TRUE, star_rating);
 
        gtk_tree_store_set(store, iter, FILE_COLUMN_POINTER, fd,
@@ -963,12 +964,12 @@ static void vflist_setup_iter_recursive(ViewFile *vf, GtkTreeStore *store, GtkTr
        while (work)
                {
                gint match;
-               FileData *fd = work->data;
+               auto fd = static_cast<FileData *>(work->data);
                gboolean done = FALSE;
 
                while (!done)
                        {
-                       FileData *old_fd = NULL;
+                       FileData *old_fd = nullptr;
                        gint old_version = 0;
 
                        if (valid)
@@ -1064,39 +1065,37 @@ static void vflist_setup_iter_recursive(ViewFile *vf, GtkTreeStore *store, GtkTr
        /* move the prepended entries to the correct position */
        if (num_prepended)
                {
-               gint i;
                gint num_total = num_prepended + num_ordered;
-               gint *new_order = g_malloc(num_total * sizeof(gint));
+               std::vector<gint> new_order;
+               new_order.reserve(num_total);
 
-               for (i = 0; i < num_total; i++)
+               for (gint i = 0; i < num_ordered; i++)
                        {
-                       if (i < num_ordered)
-                               new_order[i] = num_prepended + i;
-                       else
-                               new_order[i] = num_total - 1 - i;
+                       new_order.push_back(num_prepended + i);
                        }
-               gtk_tree_store_reorder(store, parent_iter, new_order);
-
-               g_free(new_order);
+               for (gint i = num_ordered; i < num_total; i++)
+                       {
+                       new_order.push_back(num_total - 1 - i);
+                       }
+               gtk_tree_store_reorder(store, parent_iter, new_order.data());
                }
 }
 
-void vflist_sort_set(ViewFile *vf, SortType type, gboolean ascend)
+void vflist_sort_set(ViewFile *vf, SortType type, gboolean ascend, gboolean case_sensitive)
 {
        gint i;
-       GHashTable *fd_idx_hash = g_hash_table_new(NULL, NULL);
-       gint *new_order;
+       GHashTable *fd_idx_hash = g_hash_table_new(nullptr, nullptr);
        GtkTreeStore *store;
        GList *work;
 
-       if (vf->sort_method == type && vf->sort_ascend == ascend) return;
+       if (vf->sort_method == type && vf->sort_ascend == ascend && vf->sort_case == case_sensitive) return;
        if (!vf->list) return;
 
        work = vf->list;
        i = 0;
        while (work)
                {
-               FileData *fd = work->data;
+               auto fd = static_cast<FileData *>(work->data);
                g_hash_table_insert(fd_idx_hash, fd, GINT_TO_POINTER(i));
                i++;
                work = work->next;
@@ -1104,25 +1103,24 @@ void vflist_sort_set(ViewFile *vf, SortType type, gboolean ascend)
 
        vf->sort_method = type;
        vf->sort_ascend = ascend;
+       vf->sort_case = case_sensitive;
 
-       vf->list = filelist_sort(vf->list, vf->sort_method, vf->sort_ascend);
+       vf->list = filelist_sort(vf->list, vf->sort_method, vf->sort_ascend, vf->sort_case);
 
-       new_order = g_malloc(i * sizeof(gint));
+       std::vector<gint> new_order;
+       new_order.reserve(i);
 
        work = vf->list;
-       i = 0;
        while (work)
                {
-               FileData *fd = work->data;
-               new_order[i] = GPOINTER_TO_INT(g_hash_table_lookup(fd_idx_hash, fd));
-               i++;
+               auto fd = static_cast<FileData *>(work->data);
+               new_order.push_back(GPOINTER_TO_INT(g_hash_table_lookup(fd_idx_hash, fd)));
                work = work->next;
                }
 
        store = GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(vf->listview)));
-       gtk_tree_store_reorder(store, NULL, new_order);
+       gtk_tree_store_reorder(store, nullptr, new_order.data());
 
-       g_free(new_order);
        g_hash_table_destroy(fd_idx_hash);
 }
 
@@ -1138,7 +1136,7 @@ void vflist_thumb_progress_count(GList *list, gint *count, gint *done)
        GList *work = list;
        while (work)
                {
-               FileData *fd = work->data;
+               auto fd = static_cast<FileData *>(work->data);
                work = work->next;
 
                if (fd->thumb_pixbuf) (*done)++;
@@ -1156,7 +1154,7 @@ void vflist_read_metadata_progress_count(GList *list, gint *count, gint *done)
        GList *work = list;
        while (work)
                {
-               FileData *fd = work->data;
+               auto fd = static_cast<FileData *>(work->data);
                work = work->next;
 
                if (fd->metadata_in_idle_loaded) (*done)++;
@@ -1183,11 +1181,11 @@ void vflist_set_thumb_fd(ViewFile *vf, FileData *fd)
 FileData *vflist_thumb_next_fd(ViewFile *vf)
 {
        GtkTreePath *tpath;
-       FileData *fd = NULL;
+       FileData *fd = nullptr;
 
        /* first check the visible files */
 
-       if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(vf->listview), 0, 0, &tpath, NULL, NULL, NULL))
+       if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(vf->listview), 0, 0, &tpath, nullptr, nullptr, nullptr))
                {
                GtkTreeModel *store;
                GtkTreeIter iter;
@@ -1196,7 +1194,7 @@ FileData *vflist_thumb_next_fd(ViewFile *vf)
                store = gtk_tree_view_get_model(GTK_TREE_VIEW(vf->listview));
                gtk_tree_model_get_iter(store, &iter, tpath);
                gtk_tree_path_free(tpath);
-               tpath = NULL;
+               tpath = nullptr;
 
                while (!fd && valid && tree_view_row_get_visibility(GTK_TREE_VIEW(vf->listview), &iter, FALSE) == 0)
                        {
@@ -1217,7 +1215,7 @@ FileData *vflist_thumb_next_fd(ViewFile *vf)
                GList *work = vf->list;
                while (work && !fd)
                        {
-                       FileData *fd_p = work->data;
+                       auto fd_p = static_cast<FileData *>(work->data);
                        if (!fd_p->thumb_pixbuf)
                                fd = fd_p;
                        else
@@ -1226,7 +1224,7 @@ FileData *vflist_thumb_next_fd(ViewFile *vf)
 
                                while (work2 && !fd)
                                        {
-                                       fd_p = work2->data;
+                                       fd_p = static_cast<FileData *>(work2->data);
                                        if (!fd_p->thumb_pixbuf) fd = fd_p;
                                        work2 = work2->next;
                                        }
@@ -1278,12 +1276,12 @@ void vflist_set_star_fd(ViewFile *vf, FileData *fd)
 FileData *vflist_star_next_fd(ViewFile *vf)
 {
        GtkTreePath *tpath;
-       FileData *fd = NULL;
-       FileData *nfd = NULL;
+       FileData *fd = nullptr;
+       FileData *nfd = nullptr;
 
        /* first check the visible files */
 
-       if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(vf->listview), 0, 0, &tpath, NULL, NULL, NULL))
+       if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(vf->listview), 0, 0, &tpath, nullptr, nullptr, nullptr))
                {
                GtkTreeModel *store;
                GtkTreeIter iter;
@@ -1292,7 +1290,7 @@ FileData *vflist_star_next_fd(ViewFile *vf)
                store = gtk_tree_view_get_model(GTK_TREE_VIEW(vf->listview));
                gtk_tree_model_get_iter(store, &iter, tpath);
                gtk_tree_path_free(tpath);
-               tpath = NULL;
+               tpath = nullptr;
 
                while (!fd && valid && tree_view_row_get_visibility(GTK_TREE_VIEW(vf->listview), &iter, FALSE) == 0)
                        {
@@ -1312,7 +1310,7 @@ FileData *vflist_star_next_fd(ViewFile *vf)
 
                        if (vf->stars_id == 0)
                                {
-                               vf->stars_id = g_idle_add_full(G_PRIORITY_LOW, vf_stars_cb, vf, NULL);
+                               vf->stars_id = g_idle_add_full(G_PRIORITY_LOW, vf_stars_cb, vf, nullptr);
                                }
                        }
                }
@@ -1325,7 +1323,7 @@ FileData *vflist_star_next_fd(ViewFile *vf)
 
                while (work && !fd)
                        {
-                       FileData *fd_p = work->data;
+                       auto fd_p = static_cast<FileData *>(work->data);
 
                        if (fd_p && fd_p->rating == STAR_RATING_NOT_READ)
                                {
@@ -1333,7 +1331,7 @@ FileData *vflist_star_next_fd(ViewFile *vf)
                                }
                        else
                                {
-                               fd = NULL;
+                               fd = nullptr;
                                }
 
                        work = work->next;
@@ -1345,7 +1343,7 @@ FileData *vflist_star_next_fd(ViewFile *vf)
 
                        if (vf->stars_id == 0)
                                {
-                               vf->stars_id = g_idle_add_full(G_PRIORITY_LOW, vf_stars_cb, vf, NULL);
+                               vf->stars_id = g_idle_add_full(G_PRIORITY_LOW, vf_stars_cb, vf, nullptr);
                                }
                        }
                }
@@ -1362,12 +1360,13 @@ FileData *vflist_star_next_fd(ViewFile *vf)
 gint vflist_index_by_fd(ViewFile *vf, FileData *fd)
 {
        gint p = 0;
-       GList *work, *work2;
+       GList *work;
+       GList *work2;
 
        work = vf->list;
        while (work)
                {
-               FileData *list_fd = work->data;
+               auto list_fd = static_cast<FileData *>(work->data);
                if (list_fd == fd) return p;
 
                work2 = list_fd->sidecar_files;
@@ -1377,7 +1376,7 @@ gint vflist_index_by_fd(ViewFile *vf, FileData *fd)
                           it is sufficient for next/prev navigation but it should be rewritten
                           without using indexes at all
                        */
-                       FileData *sidecar_fd = work2->data;
+                       auto sidecar_fd = static_cast<FileData *>(work2->data);
                        if (sidecar_fd == fd) return p;
                        work2 = work2->next;
                        }
@@ -1408,7 +1407,7 @@ static gboolean vflist_row_is_selected(ViewFile *vf, FileData *fd)
        work = slist;
        while (!found && work)
                {
-               GtkTreePath *tpath = work->data;
+               auto tpath = static_cast<GtkTreePath *>(work->data);
                FileData *fd_n;
                GtkTreeIter iter;
 
@@ -1417,19 +1416,21 @@ static gboolean vflist_row_is_selected(ViewFile *vf, FileData *fd)
                if (fd_n == fd) found = TRUE;
                work = work->next;
                }
-       g_list_foreach(slist, (GFunc)tree_path_free_wrapper, NULL);
-       g_list_free(slist);
+       g_list_free_full(slist, reinterpret_cast<GDestroyNotify>(gtk_tree_path_free));
 
        return found;
 }
 
-gboolean vflist_index_is_selected(ViewFile *vf, gint row)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-function"
+gboolean vflist_index_is_selected_unused(ViewFile *vf, gint row)
 {
        FileData *fd;
 
        fd = vf_index_get_data(vf, row);
        return vflist_row_is_selected(vf, fd);
 }
+#pragma GCC diagnostic pop
 
 guint vflist_selection_count(ViewFile *vf, gint64 *bytes)
 {
@@ -1449,7 +1450,7 @@ guint vflist_selection_count(ViewFile *vf, gint64 *bytes)
                work = slist;
                while (work)
                        {
-                       GtkTreePath *tpath = work->data;
+                       auto tpath = static_cast<GtkTreePath *>(work->data);
                        GtkTreeIter iter;
                        FileData *fd;
 
@@ -1464,8 +1465,7 @@ guint vflist_selection_count(ViewFile *vf, gint64 *bytes)
                }
 
        count = g_list_length(slist);
-       g_list_foreach(slist, (GFunc)tree_path_free_wrapper, NULL);
-       g_list_free(slist);
+       g_list_free_full(slist, reinterpret_cast<GDestroyNotify>(gtk_tree_path_free));
 
        return count;
 }
@@ -1475,41 +1475,30 @@ GList *vflist_selection_get_list(ViewFile *vf)
        GtkTreeModel *store;
        GtkTreeSelection *selection;
        GList *slist;
-       GList *list = NULL;
-       GList *work;
+       GList *list = nullptr;
 
        selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vf->listview));
        slist = gtk_tree_selection_get_selected_rows(selection, &store);
-       work = slist;
-       while (work)
+       for (GList *work = g_list_last(slist); work; work = work->prev)
                {
-               GtkTreePath *tpath = work->data;
+               auto tpath = static_cast<GtkTreePath *>(work->data);
                FileData *fd;
                GtkTreeIter iter;
 
                gtk_tree_model_get_iter(store, &iter, tpath);
                gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &fd, -1);
 
-               list = g_list_prepend(list, file_data_ref(fd));
-
                if (!fd->parent && !gtk_tree_view_row_expanded(GTK_TREE_VIEW(vf->listview), tpath))
                        {
                        /* unexpanded - add whole group */
-                       GList *work2 = fd->sidecar_files;
-                       while (work2)
-                               {
-                               FileData *sfd = work2->data;
-                               list = g_list_prepend(list, file_data_ref(sfd));
-                               work2 = work2->next;
-                               }
+                       list = g_list_concat(filelist_copy(fd->sidecar_files), list);
                        }
 
-               work = work->next;
+               list = g_list_prepend(list, file_data_ref(fd));
                }
-       g_list_foreach(slist, (GFunc)tree_path_free_wrapper, NULL);
-       g_list_free(slist);
+       g_list_free_full(slist, reinterpret_cast<GDestroyNotify>(gtk_tree_path_free));
 
-       return g_list_reverse(list);
+       return list;
 }
 
 GList *vflist_selection_get_list_by_index(ViewFile *vf)
@@ -1517,7 +1506,7 @@ GList *vflist_selection_get_list_by_index(ViewFile *vf)
        GtkTreeModel *store;
        GtkTreeSelection *selection;
        GList *slist;
-       GList *list = NULL;
+       GList *list = nullptr;
        GList *work;
 
        selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vf->listview));
@@ -1525,7 +1514,7 @@ GList *vflist_selection_get_list_by_index(ViewFile *vf)
        work = slist;
        while (work)
                {
-               GtkTreePath *tpath = work->data;
+               auto tpath = static_cast<GtkTreePath *>(work->data);
                FileData *fd;
                GtkTreeIter iter;
 
@@ -1536,8 +1525,7 @@ GList *vflist_selection_get_list_by_index(ViewFile *vf)
 
                work = work->next;
                }
-       g_list_foreach(slist, (GFunc)tree_path_free_wrapper, NULL);
-       g_list_free(slist);
+       g_list_free_full(slist, reinterpret_cast<GDestroyNotify>(gtk_tree_path_free));
 
        return g_list_reverse(list);
 }
@@ -1549,7 +1537,7 @@ void vflist_select_all(ViewFile *vf)
        selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vf->listview));
        gtk_tree_selection_select_all(selection);
 
-       VFLIST(vf)->select_fd = NULL;
+       VFLIST(vf)->select_fd = nullptr;
 }
 
 void vflist_select_none(ViewFile *vf)
@@ -1641,7 +1629,7 @@ void vflist_select_by_fd(ViewFile *vf, FileData *fd)
 
                store = gtk_tree_view_get_model(GTK_TREE_VIEW(vf->listview));
                tpath = gtk_tree_model_get_path(store, &iter);
-               gtk_tree_view_set_cursor(GTK_TREE_VIEW(vf->listview), tpath, NULL, FALSE);
+               gtk_tree_view_set_cursor(GTK_TREE_VIEW(vf->listview), tpath, nullptr, FALSE);
                gtk_tree_path_free(tpath);
                }
 }
@@ -1657,7 +1645,7 @@ void vflist_select_list(ViewFile *vf, GList *list)
                {
                FileData *fd;
 
-               fd = work->data;
+               fd = static_cast<FileData *>(work->data);
 
                if (vflist_find_row(vf, fd, &iter) < 0) return;
                if (!vflist_row_is_selected(vf, fd))
@@ -1674,7 +1662,7 @@ void vflist_select_list(ViewFile *vf, GList *list)
 static void vflist_select_closest(ViewFile *vf, FileData *sel_fd)
 {
        GList *work;
-       FileData *fd = NULL;
+       FileData *fd = nullptr;
 
        if (sel_fd->parent) sel_fd = sel_fd->parent;
        work = vf->list;
@@ -1682,7 +1670,7 @@ static void vflist_select_closest(ViewFile *vf, FileData *sel_fd)
        while (work)
                {
                gint match;
-               fd = work->data;
+               fd = static_cast<FileData *>(work->data);
                work = work->next;
 
                match = filelist_sort_compare_filedata_full(fd, sel_fd, vf->sort_method, vf->sort_ascend);
@@ -1711,7 +1699,8 @@ void vflist_mark_to_selection(ViewFile *vf, gint mark, MarkToSelectionMode mode)
        while (valid)
                {
                FileData *fd;
-               gboolean mark_val, selected;
+               gboolean mark_val;
+               gboolean selected;
                gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, FILE_COLUMN_POINTER, &fd, -1);
 
                mark_val = file_data_get_mark(fd, n);
@@ -1753,7 +1742,7 @@ void vflist_selection_to_mark(ViewFile *vf, gint mark, SelectionToMarkMode mode)
        work = slist;
        while (work)
                {
-               GtkTreePath *tpath = work->data;
+               auto tpath = static_cast<GtkTreePath *>(work->data);
                FileData *fd;
                GtkTreeIter iter;
 
@@ -1783,7 +1772,7 @@ void vflist_selection_to_mark(ViewFile *vf, gint mark, SelectionToMarkMode mode)
                        /* mark functions can have various side effects - update all columns to be sure */
                        vflist_setup_iter(vf, GTK_TREE_STORE(store), &iter, fd);
                        /* mark functions can change sidecars too */
-                       vflist_setup_iter_recursive(vf, GTK_TREE_STORE(store), &iter, fd->sidecar_files, NULL, FALSE);
+                       vflist_setup_iter_recursive(vf, GTK_TREE_STORE(store), &iter, fd->sidecar_files, nullptr, FALSE);
                        }
 
 
@@ -1791,8 +1780,7 @@ void vflist_selection_to_mark(ViewFile *vf, gint mark, SelectionToMarkMode mode)
 
                work = work->next;
                }
-       g_list_foreach(slist, (GFunc)tree_path_free_wrapper, NULL);
-       g_list_free(slist);
+       g_list_free_full(slist, reinterpret_cast<GDestroyNotify>(gtk_tree_path_free));
 }
 
 /*
@@ -1814,7 +1802,7 @@ static void vflist_listview_set_columns(GtkWidget *listview, gboolean thumb, gbo
 
        list = gtk_cell_layout_get_cells(GTK_CELL_LAYOUT(column));
        if (!list) return;
-       cell = list->data;
+       cell = static_cast<GtkCellRenderer *>(list->data);
        g_list_free(list);
 
        g_object_set(G_OBJECT(cell), "height", options->thumbnails.max_height, NULL);
@@ -1883,12 +1871,12 @@ static void vflist_populate_view(ViewFile *vf, gboolean force)
 
        selected = vflist_selection_get_list(vf);
 
-       vflist_setup_iter_recursive(vf, store, NULL, vf->list, selected, force);
+       vflist_setup_iter_recursive(vf, store, nullptr, vf->list, selected, force);
 
-       if (selected && vflist_selection_count(vf, NULL) == 0)
+       if (selected && vflist_selection_count(vf, nullptr) == 0)
                {
                /* all selected files disappeared */
-               vflist_select_closest(vf, selected->data);
+               vflist_select_closest(vf, static_cast<FileData *>(selected->data));
                }
 
        filelist_free(selected);
@@ -1904,22 +1892,22 @@ gboolean vflist_refresh(ViewFile *vf)
        gboolean ret = TRUE;
 
        old_list = vf->list;
-       vf->list = NULL;
+       vf->list = nullptr;
 
        DEBUG_1("%s vflist_refresh: read dir", get_exec_time());
        if (vf->dir_fd)
                {
                file_data_unregister_notify_func(vf_notify_cb, vf); /* we don't need the notification of changes detected by filelist_read */
 
-               ret = filelist_read(vf->dir_fd, &vf->list, NULL);
+               ret = filelist_read(vf->dir_fd, &vf->list, nullptr);
 
                if (vf->marks_enabled)
-                       {
-                       // When marks are enabled, lock FileDatas so that we don't end up re-parsing XML
-                       // each time a mark is changed.
-                       file_data_lock_list(vf->list);
-                       }
-               else
+                       {
+                       // When marks are enabled, lock FileDatas so that we don't end up re-parsing XML
+                       // each time a mark is changed.
+                       file_data_lock_list(vf->list);
+                       }
+               else
                        {
                        /** @FIXME only do this when needed (aka when we just switched from */
                        /** @FIXME marks-enabled to marks-disabled) */
@@ -1936,7 +1924,7 @@ gboolean vflist_refresh(ViewFile *vf)
                file_data_register_notify_func(vf_notify_cb, vf, NOTIFY_PRIORITY_MEDIUM);
 
                DEBUG_1("%s vflist_refresh: sort", get_exec_time());
-               vf->list = filelist_sort(vf->list, vf->sort_method, vf->sort_ascend);
+               vf->list = filelist_sort(vf->list, vf->sort_method, vf->sort_ascend, vf->sort_case);
                }
 
        DEBUG_1("%s vflist_refresh: populate view", get_exec_time());
@@ -1955,7 +1943,9 @@ gboolean vflist_refresh(ViewFile *vf)
 
 /* this overrides the low default of a GtkCellRenderer from 100 to CELL_HEIGHT_OVERRIDE, something sane for our purposes */
 
-#define CELL_HEIGHT_OVERRIDE 512
+enum {
+       CELL_HEIGHT_OVERRIDE = 512
+};
 
 static void cell_renderer_height_override(GtkCellRenderer *renderer)
 {
@@ -1971,17 +1961,20 @@ static void cell_renderer_height_override(GtkCellRenderer *renderer)
                }
 }
 
-static GdkColor *vflist_listview_color_shifted(GtkWidget *widget)
+static GdkRGBA *vflist_listview_color_shifted(GtkWidget *widget)
 {
-       static GdkColor color;
-       static GtkWidget *done = NULL;
+       static GdkRGBA color;
+       static GdkRGBA color_style;
+       static GtkWidget *done = nullptr;
 
        if (done != widget)
                {
                GtkStyle *style;
 
                style = gtk_widget_get_style(widget);
-               memcpy(&color, &style->base[GTK_STATE_NORMAL], sizeof(color));
+               convert_gdkcolor_to_gdkrgba(&style->base[GTK_STATE_NORMAL], &color_style);
+
+               memcpy(&color, &color_style, sizeof(color));
                shift_color(&color, -1, 0);
                done = widget;
                }
@@ -1989,15 +1982,15 @@ static GdkColor *vflist_listview_color_shifted(GtkWidget *widget)
        return &color;
 }
 
-static void vflist_listview_color_cb(GtkTreeViewColumn *UNUSED(tree_column), GtkCellRenderer *cell,
+static void vflist_listview_color_cb(GtkTreeViewColumn *, GtkCellRenderer *cell,
                                     GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data)
 {
-       ViewFile *vf = data;
+       auto vf = static_cast<ViewFile *>(data);
        gboolean set;
 
        gtk_tree_model_get(tree_model, iter, FILE_COLUMN_COLOR, &set, -1);
        g_object_set(G_OBJECT(cell),
-                    "cell-background-gdk", vflist_listview_color_shifted(vf->listview),
+                    "cell-background-rgba", vflist_listview_color_shifted(vf->listview),
                     "cell-background-set", set, NULL);
 }
 
@@ -2032,7 +2025,7 @@ static void vflist_listview_add_column(ViewFile *vf, gint n, const gchar *title,
                gtk_tree_view_column_add_attribute(column, renderer, "pixbuf", n);
                }
 
-       gtk_tree_view_column_set_cell_data_func(column, renderer, vflist_listview_color_cb, vf, NULL);
+       gtk_tree_view_column_set_cell_data_func(column, renderer, vflist_listview_color_cb, vf, nullptr);
        g_object_set_data(G_OBJECT(column), "column_store_idx", GUINT_TO_POINTER(n));
        g_object_set_data(G_OBJECT(renderer), "column_store_idx", GUINT_TO_POINTER(n));
 
@@ -2041,7 +2034,7 @@ static void vflist_listview_add_column(ViewFile *vf, gint n, const gchar *title,
 
 static void vflist_listview_mark_toggled_cb(GtkCellRendererToggle *cell, gchar *path_str, gpointer data)
 {
-       ViewFile *vf = data;
+       auto vf = static_cast<ViewFile *>(data);
        GtkTreeStore *store;
        GtkTreePath *path = gtk_tree_path_new_from_string(path_str);
        GtkTreeIter iter;
@@ -2073,7 +2066,7 @@ static void vflist_listview_mark_toggled_cb(GtkCellRendererToggle *cell, gchar *
                /* mark functions can have various side effects - update all columns to be sure */
                vflist_setup_iter(vf, GTK_TREE_STORE(store), &iter, fd);
                /* mark functions can change sidecars too */
-               vflist_setup_iter_recursive(vf, GTK_TREE_STORE(store), &iter, fd->sidecar_files, NULL, FALSE);
+               vflist_setup_iter_recursive(vf, GTK_TREE_STORE(store), &iter, fd->sidecar_files, nullptr, FALSE);
                }
        file_data_register_notify_func(vf_notify_cb, vf, NOTIFY_PRIORITY_MEDIUM);
 
@@ -2119,16 +2112,16 @@ gboolean vflist_set_fd(ViewFile *vf, FileData *dir_fd)
        vflist_store_clear(vf, TRUE);
 
        filelist_free(vf->list);
-       vf->list = NULL;
+       vf->list = nullptr;
 
        ret = vf_refresh(vf);
        gtk_tree_view_columns_autosize(GTK_TREE_VIEW(vf->listview));
        return ret;
 }
 
-void vflist_destroy_cb(GtkWidget *UNUSED(widget), gpointer data)
+void vflist_destroy_cb(GtkWidget *, gpointer data)
 {
-       ViewFile *vf = data;
+       auto vf = static_cast<ViewFile *>(data);
 
        file_data_unregister_notify_func(vf_notify_cb, vf);
 
@@ -2140,7 +2133,7 @@ void vflist_destroy_cb(GtkWidget *UNUSED(widget), gpointer data)
        filelist_free(vf->list);
 }
 
-ViewFile *vflist_new(ViewFile *vf, FileData *UNUSED(dir_fd))
+ViewFile *vflist_new(ViewFile *vf, FileData *)
 {
        GtkTreeStore *store;
        GtkTreeSelection *selection;
@@ -2178,7 +2171,7 @@ ViewFile *vflist_new(ViewFile *vf, FileData *UNUSED(dir_fd))
 
        selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vf->listview));
        gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_MULTIPLE);
-       gtk_tree_selection_set_select_function(selection, vflist_select_cb, vf, NULL);
+       gtk_tree_selection_set_select_function(selection, vflist_select_cb, vf, nullptr);
 
        gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(vf->listview), FALSE);
        gtk_tree_view_set_enable_search(GTK_TREE_VIEW(vf->listview), FALSE);
@@ -2241,14 +2234,15 @@ void vflist_thumb_set(ViewFile *vf, gboolean enable)
 
 void vflist_marks_set(ViewFile *vf, gboolean enable)
 {
-       GList *columns, *work;
+       GList *columns;
+       GList *work;
 
        columns = gtk_tree_view_get_columns(GTK_TREE_VIEW(vf->listview));
 
        work = columns;
        while (work)
                {
-               GtkTreeViewColumn *column = work->data;
+               auto column = static_cast<GtkTreeViewColumn *>(work->data);
                gint col_idx = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(column), "column_store_idx"));
                work = work->next;