Use std::swap instead of temporary values
[geeqie.git] / src / collect.cc
index 8097b94..5b9a62f 100644 (file)
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#include "main.h"
 #include "collect.h"
 
+#include <sys/stat.h>
+
+#include <cstdlib>
+#include <cstring>
+#include <ctime>
+#include <utility>
+
+#include <glib-object.h>
+
 #include "collect-dlg.h"
 #include "collect-io.h"
 #include "collect-table.h"
-#include "editors.h"
+#include "compat.h"
+#include "debug.h"
 #include "filedata.h"
 #include "img-view.h"
-#include "layout.h"
+#include "intl.h"
 #include "layout-image.h"
 #include "layout-util.h"
+#include "layout.h"
+#include "main-defines.h"
 #include "misc.h"
+#include "options.h"
 #include "pixbuf-util.h"
 #include "print.h"
 #include "ui-fileops.h"
 #include "ui-tree-edit.h"
+#include "ui-utildlg.h"
 #include "utilops.h"
 #include "window.h"
 
-#include <gdk/gdkkeysyms.h> /* for keyboard values */
-
-
-#define COLLECT_DEF_WIDTH 440
-#define COLLECT_DEF_HEIGHT 450
+enum {
+       COLLECT_DEF_WIDTH = 440,
+       COLLECT_DEF_HEIGHT = 450
+};
 
 /**
  *  list of paths to collections */
 
 /**
  * @brief  List of currently open Collections.
- * 
- * Type ::_CollectionData 
+ *
+ * Type ::_CollectionData
  */
-static GList *collection_list = NULL;
+static GList *collection_list = nullptr;
 
 /**
  * @brief  List of currently open Collection windows.
- * 
+ *
  * Type ::_CollectWindow
  */
-static GList *collection_window_list = NULL;
+static GList *collection_window_list = nullptr;
 
 static void collection_window_get_geometry(CollectWindow *cw);
 static void collection_window_refresh(CollectWindow *cw);
@@ -80,11 +92,11 @@ static void collection_notify_cb(FileData *fd, NotifyType type, gpointer data);
  *-------------------------------------------------------------------
  */
 
-CollectInfo *collection_info_new(FileData *fd, struct stat *UNUSED(st), GdkPixbuf *pixbuf)
+CollectInfo *collection_info_new(FileData *fd, struct stat *, GdkPixbuf *pixbuf)
 {
        CollectInfo *ci;
 
-       if (!fd) return NULL;
+       if (!fd) return nullptr;
 
        ci = g_new0(CollectInfo, 1);
        ci->fd = file_data_ref(fd);
@@ -98,7 +110,7 @@ CollectInfo *collection_info_new(FileData *fd, struct stat *UNUSED(st), GdkPixbu
 void collection_info_free_thumb(CollectInfo *ci)
 {
        if (ci->pixbuf) g_object_unref(ci->pixbuf);
-       ci->pixbuf = NULL;
+       ci->pixbuf = nullptr;
 }
 
 void collection_info_free(CollectInfo *ci)
@@ -117,7 +129,9 @@ void collection_info_set_thumb(CollectInfo *ci, GdkPixbuf *pixbuf)
        ci->pixbuf = pixbuf;
 }
 
-gboolean collection_info_load_thumb(CollectInfo *ci)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-function"
+gboolean collection_info_load_thumb_unused(CollectInfo *ci)
 {
        if (!ci) return FALSE;
 
@@ -126,26 +140,15 @@ gboolean collection_info_load_thumb(CollectInfo *ci)
        log_printf("collection_info_load_thumb not implemented!\n(because an instant thumb loader not implemented)");
        return FALSE;
 }
-
-void collection_list_free(GList *list)
-{
-       GList *work;
-       work = list;
-       while (work)
-               {
-               collection_info_free((CollectInfo *)work->data);
-               work = work->next;
-               }
-       g_list_free(list);
-}
+#pragma GCC diagnostic pop
 
 /* an ugly static var, well what ya gonna do ? */
 static SortType collection_list_sort_method = SORT_NAME;
 
 static gint collection_list_sort_cb(gconstpointer a, gconstpointer b)
 {
-       const CollectInfo *cia = a;
-       const CollectInfo *cib = b;
+       auto cia = static_cast<const CollectInfo *>(a);
+       auto cib = static_cast<const CollectInfo *>(b);
 
        switch (collection_list_sort_method)
                {
@@ -188,19 +191,14 @@ static gint collection_list_sort_cb(gconstpointer a, gconstpointer b)
                        if (cia->fd->format_class < cib->fd->format_class) return -1;
                        if (cia->fd->format_class > cib->fd->format_class) return 1;
                        break;
-#ifdef HAVE_STRVERSCMP
-               case SORT_NUMBER:
-                       return strverscmp(cia->fd->name, cib->fd->name);
-                       break;
-#endif
                default:
                        break;
                }
 
        if (options->file_sort.case_sensitive)
                return strcmp(cia->fd->collate_key_name, cib->fd->collate_key_name);
-       else
-               return strcmp(cia->fd->collate_key_name_nocase, cib->fd->collate_key_name_nocase);
+
+       return strcmp(cia->fd->collate_key_name_nocase, cib->fd->collate_key_name_nocase);
 }
 
 GList *collection_list_sort(GList *list, SortType method)
@@ -214,23 +212,23 @@ GList *collection_list_sort(GList *list, SortType method)
 
 GList *collection_list_randomize(GList *list)
 {
-       guint random, length, i;
-       gpointer tmp;
-       GList *nlist, *olist;
+       guint random;
+       guint length;
+       guint i;
+       GList *nlist;
+       GList *olist;
 
        length = g_list_length(list);
-       if (!length) return NULL;
+       if (!length) return nullptr;
 
-       srand((unsigned int)time(NULL)); // Initialize random generator (hasn't to be that much strong)
+       srand(static_cast<unsigned int>(time(nullptr))); // Initialize random generator (hasn't to be that much strong)
 
        for (i = 0; i < length; i++)
                {
-               random = (guint) (1.0 * length * rand()/(RAND_MAX + 1.0));
+               random = static_cast<guint>(1.0 * length * rand()/(RAND_MAX + 1.0));
                olist = g_list_nth(list, i);
                nlist = g_list_nth(list, random);
-               tmp = olist->data;
-               olist->data = nlist->data;
-               nlist->data = tmp;
+               std::swap(olist->data, nlist->data);
                }
 
        return list;
@@ -282,22 +280,22 @@ CollectInfo *collection_list_find_fd(GList *list, FileData *fd)
 
        while (work)
                {
-               CollectInfo *ci = work->data;
+               auto ci = static_cast<CollectInfo *>(work->data);
                if (ci->fd == fd) return ci;
                work = work->next;
                }
 
-       return NULL;
+       return nullptr;
 }
 
 GList *collection_list_to_filelist(GList *list)
 {
-       GList *filelist = NULL;
+       GList *filelist = nullptr;
        GList *work = list;
 
        while (work)
                {
-               CollectInfo *info = work->data;
+               auto info = static_cast<CollectInfo *>(work->data);
                filelist = g_list_prepend(filelist, file_data_ref(info->fd));
                work = work->next;
                }
@@ -313,48 +311,48 @@ CollectWindow *collection_window_find(CollectionData *cd)
        work = collection_window_list;
        while (work)
                {
-               CollectWindow *cw = work->data;
+               auto cw = static_cast<CollectWindow *>(work->data);
                if (cw->cd == cd) return cw;
                work = work->next;
                }
 
-       return NULL;
+       return nullptr;
 }
 
 CollectWindow *collection_window_find_by_path(const gchar *path)
 {
        GList *work;
 
-       if (!path) return NULL;
+       if (!path) return nullptr;
 
        work = collection_window_list;
        while (work)
                {
-               CollectWindow *cw = work->data;
+               auto cw = static_cast<CollectWindow *>(work->data);
                if (cw->cd->path && strcmp(cw->cd->path, path) == 0) return cw;
                work = work->next;
                }
 
-       return NULL;
+       return nullptr;
 }
 
 /**
  * @brief Checks string for existence of Collection.
  * @param[in] param Filename, with or without extension of any collection
  * @returns full pathname if found or NULL
- * 
+ *
  * Return value must be freed with g_free()
  */
 gchar *collection_path(const gchar *param)
 {
-       gchar *path = NULL;
-       gchar *full_name = NULL;
+       gchar *path = nullptr;
+       gchar *full_name = nullptr;
 
        if (file_extension_match(param, GQ_COLLECTION_EXT))
                {
                path = g_build_filename(get_collections_dir(), param, NULL);
                }
-       else if (file_extension_match(param, NULL))
+       else if (file_extension_match(param, nullptr))
                {
                full_name = g_strconcat(param, GQ_COLLECTION_EXT, NULL);
                path = g_build_filename(get_collections_dir(), full_name, NULL);
@@ -363,7 +361,7 @@ gchar *collection_path(const gchar *param)
        if (!isfile(path))
                {
                g_free(path);
-               path = NULL;
+               path = nullptr;
                }
 
        g_free(full_name);
@@ -374,12 +372,12 @@ gchar *collection_path(const gchar *param)
  * @brief Checks input string for existence of Collection.
  * @param[in] param Filename with or without extension of any collection
  * @returns TRUE if found
- * 
- * 
+ *
+ *
  */
 gboolean is_collection(const gchar *param)
 {
-       gchar *name = NULL;
+       gchar *name = nullptr;
 
        name = collection_path(param);
        if (name)
@@ -394,8 +392,8 @@ gboolean is_collection(const gchar *param)
  * @brief Creates a text list of the image paths of the contents of a Collection
  * @param[in] name The name of the collection, with or without extension
  * @param[inout] contents A GString to which the image paths are appended
- * 
- * 
+ *
+ *
  */
 void collection_contents(const gchar *name, GString **contents)
 {
@@ -413,9 +411,9 @@ void collection_contents(const gchar *name, GString **contents)
                work = cd->list;
                while (work)
                        {
-                       ci = work->data;
+                       ci = static_cast<CollectInfo *>(work->data);
                        fd = ci->fd;
-                       *contents = g_string_append(*contents, g_strdup(fd->path));
+                       *contents = g_string_append(*contents, fd->path);
                        *contents = g_string_append(*contents, "\n");
 
                        work = work->next;
@@ -428,8 +426,8 @@ void collection_contents(const gchar *name, GString **contents)
 /**
  * @brief Returns a list of filedatas of the contents of a Collection
  * @param[in] name The name of the collection, with or without extension
- * 
- * 
+ *
+ *
  */
 GList *collection_contents_fd(const gchar *name)
 {
@@ -437,7 +435,7 @@ GList *collection_contents_fd(const gchar *name)
        CollectionData *cd;
        CollectInfo *ci;
        GList *work;
-       GList *list = NULL;
+       GList *list = nullptr;
 
        if (is_collection(name))
                {
@@ -447,7 +445,7 @@ GList *collection_contents_fd(const gchar *name)
                work = cd->list;
                while (work)
                        {
-                       ci = work->data;
+                       ci = static_cast<CollectInfo *>(work->data);
                        list = g_list_append(list, ci->fd);
 
                        work = work->next;
@@ -474,9 +472,9 @@ CollectionData *collection_new(const gchar *path)
 
        cd->ref = 1;    /* starts with a ref of 1 */
        cd->sort_method = SORT_NONE;
-       cd->window_w = COLLECT_DEF_WIDTH;
-       cd->window_h = COLLECT_DEF_HEIGHT;
-       cd->existence = g_hash_table_new(NULL, NULL);
+       cd->window.width = COLLECT_DEF_WIDTH;
+       cd->window.height = COLLECT_DEF_HEIGHT;
+       cd->existence = g_hash_table_new(nullptr, nullptr);
 
        if (path)
                {
@@ -513,7 +511,7 @@ void collection_free(CollectionData *cd)
        DEBUG_1("collection \"%s\" freed", cd->name);
 
        collection_load_stop(cd);
-       collection_list_free(cd->list);
+       g_list_free_full(cd->list, reinterpret_cast<GDestroyNotify>(collection_info_free));
 
        file_data_unregister_notify_func(collection_notify_cb, cd);
 
@@ -521,6 +519,7 @@ void collection_free(CollectionData *cd)
 
        g_hash_table_destroy(cd->existence);
 
+       g_free(cd->collection_path);
        g_free(cd->path);
        g_free(cd->name);
 
@@ -558,7 +557,7 @@ gint collection_to_number(CollectionData *cd)
 
 CollectionData *collection_from_number(gint n)
 {
-       return g_list_nth_data(collection_list, n);
+       return static_cast<CollectionData *>(g_list_nth_data(collection_list, n));
 }
 
 CollectionData *collection_from_dnd_data(const gchar *data, GList **list, GList **info_list)
@@ -567,16 +566,16 @@ CollectionData *collection_from_dnd_data(const gchar *data, GList **list, GList
        gint collection_number;
        const gchar *ptr;
 
-       if (list) *list = NULL;
-       if (info_list) *info_list = NULL;
+       if (list) *list = nullptr;
+       if (info_list) *info_list = nullptr;
 
-       if (strncmp(data, "COLLECTION:", 11) != 0) return NULL;
+       if (strncmp(data, "COLLECTION:", 11) != 0) return nullptr;
 
        ptr = data + 11;
 
        collection_number = atoi(ptr);
        cd = collection_from_number(collection_number);
-       if (!cd) return NULL;
+       if (!cd) return nullptr;
 
        if (!list && !info_list) return cd;
 
@@ -589,14 +588,14 @@ CollectionData *collection_from_dnd_data(const gchar *data, GList **list, GList
                guint item_number;
                CollectInfo *info;
 
-               item_number = (guint) atoi(ptr);
+               item_number = static_cast<guint>(atoi(ptr));
                while (*ptr != '\n' && *ptr != '\0') ptr++;
                if (*ptr == '\0')
                        break;
-               else
-                       while (*ptr == '\n') ptr++;
 
-               info = g_list_nth_data(cd->list, item_number);
+               while (*ptr == '\n') ptr++;
+
+               info = static_cast<CollectInfo *>(g_list_nth_data(cd->list, item_number));
                if (!info) continue;
 
                if (list) *list = g_list_append(*list, file_data_ref(info->fd));
@@ -609,17 +608,17 @@ CollectionData *collection_from_dnd_data(const gchar *data, GList **list, GList
 gchar *collection_info_list_to_dnd_data(CollectionData *cd, GList *list, gint *length)
 {
        GList *work;
-       GList *temp = NULL;
+       GList *temp = nullptr;
        gchar *ptr;
        gchar *text;
        gchar *uri_text;
        gint collection_number;
 
        *length = 0;
-       if (!list) return NULL;
+       if (!list) return nullptr;
 
        collection_number = collection_to_number(cd);
-       if (collection_number < 0) return NULL;
+       if (collection_number < 0) return nullptr;
 
        text = g_strdup_printf("COLLECTION:%d\n", collection_number);
        *length += strlen(text);
@@ -641,14 +640,14 @@ gchar *collection_info_list_to_dnd_data(CollectionData *cd, GList *list, gint *l
 
        *length += 1; /* ending nul char */
 
-       uri_text = g_malloc(*length);
+       uri_text = static_cast<gchar *>(g_malloc(*length));
        ptr = uri_text;
 
        work = g_list_last(temp);
        while (work)
                {
                gint len;
-               gchar *text = work->data;
+               auto text = static_cast<gchar *>(work->data);
 
                work = work->prev;
 
@@ -659,7 +658,7 @@ gchar *collection_info_list_to_dnd_data(CollectionData *cd, GList *list, gint *l
 
        ptr[0] = '\0';
 
-       string_list_free(temp);
+       g_list_free_full(temp, g_free);
 
        return uri_text;
 }
@@ -677,10 +676,10 @@ CollectInfo *collection_next_by_info(CollectionData *cd, CollectInfo *info)
 
        work = g_list_find(cd->list, info);
 
-       if (!work) return NULL;
+       if (!work) return nullptr;
        work = work->next;
-       if (work) return work->data;
-       return NULL;
+       if (work) return static_cast<CollectInfo *>(work->data);
+       return nullptr;
 }
 
 CollectInfo *collection_prev_by_info(CollectionData *cd, CollectInfo *info)
@@ -689,17 +688,17 @@ CollectInfo *collection_prev_by_info(CollectionData *cd, CollectInfo *info)
 
        work = g_list_find(cd->list, info);
 
-       if (!work) return NULL;
+       if (!work) return nullptr;
        work = work->prev;
-       if (work) return work->data;
-       return NULL;
+       if (work) return static_cast<CollectInfo *>(work->data);
+       return nullptr;
 }
 
 CollectInfo *collection_get_first(CollectionData *cd)
 {
-       if (cd->list) return cd->list->data;
+       if (cd->list) return static_cast<CollectInfo *>(cd->list->data);
 
-       return NULL;
+       return nullptr;
 }
 
 CollectInfo *collection_get_last(CollectionData *cd)
@@ -708,9 +707,9 @@ CollectInfo *collection_get_last(CollectionData *cd)
 
        list = g_list_last(cd->list);
 
-       if (list) return list->data;
+       if (list) return static_cast<CollectInfo *>(list->data);
 
-       return NULL;
+       return nullptr;
 }
 
 void collection_set_sort_method(CollectionData *cd, SortType method)
@@ -748,10 +747,13 @@ static CollectInfo *collection_info_new_if_not_exists(CollectionData *cd, struct
 {
        CollectInfo *ci;
 
-       if (g_hash_table_lookup(cd->existence, fd->path)) return NULL;
+       if (!options->collections_duplicates)
+               {
+               if (g_hash_table_lookup(cd->existence, fd->path)) return nullptr;
+               }
 
-       ci = collection_info_new(fd, st, NULL);
-       if (ci) g_hash_table_insert(cd->existence, fd->path, "");
+       ci = collection_info_new(fd, st, nullptr);
+       if (ci) g_hash_table_insert(cd->existence, fd->path, g_strdup(""));
        return ci;
 }
 
@@ -854,7 +856,7 @@ static void collection_remove_by_info(CollectionData *cd, CollectInfo *info)
        if (!info || !g_list_find(cd->list, info)) return;
 
        cd->list = g_list_remove(cd->list, info);
-       cd->changed = (cd->list != NULL);
+       cd->changed = (cd->list != nullptr);
 
        collection_window_remove(collection_window_find(cd), info);
        collection_info_free(info);
@@ -869,17 +871,17 @@ void collection_remove_by_info_list(CollectionData *cd, GList *list)
        if (!list->next)
                {
                /* more efficient (in collect-table) to remove a single item this way */
-               collection_remove_by_info(cd, (CollectInfo *)list->data);
+               collection_remove_by_info(cd, static_cast<CollectInfo *>(list->data));
                return;
                }
 
        work = list;
        while (work)
                {
-               cd->list = collection_list_remove(cd->list, work->data);
+               cd->list = collection_list_remove(cd->list, static_cast<CollectInfo *>(work->data));
                work = work->next;
                }
-       cd->changed = (cd->list != NULL);
+       cd->changed = (cd->list != nullptr);
 
        collection_window_refresh(collection_window_find(cd));
 }
@@ -911,7 +913,7 @@ void collection_update_geometry(CollectionData *cd)
 
 static void collection_notify_cb(FileData *fd, NotifyType type, gpointer data)
 {
-       CollectionData *cd = data;
+       auto cd = static_cast<CollectionData *>(data);
 
        if (!(type & NOTIFY_CHANGE) || !fd->change) return;
 
@@ -942,9 +944,9 @@ static void collection_notify_cb(FileData *fd, NotifyType type, gpointer data)
  *-------------------------------------------------------------------
  */
 
-static gboolean collection_window_keypress(GtkWidget *UNUSED(widget), GdkEventKey *event, gpointer data)
+static gboolean collection_window_keypress(GtkWidget *, GdkEventKey *event, gpointer data)
 {
-       CollectWindow *cw = data;
+       auto cw = static_cast<CollectWindow *>(data);
        gboolean stop_signal = FALSE;
        GList *list;
 
@@ -975,7 +977,7 @@ static gboolean collection_window_keypress(GtkWidget *UNUSED(widget), GdkEventKe
                                        }
                                break;
                        case 'L': case 'l':
-                               list = layout_list(NULL);
+                               list = layout_list(nullptr);
                                if (list)
                                        {
                                        collection_table_add_filelist(cw->table, list);
@@ -983,20 +985,20 @@ static gboolean collection_window_keypress(GtkWidget *UNUSED(widget), GdkEventKe
                                        }
                                break;
                        case 'C': case 'c':
-                               file_util_copy(NULL, collection_table_selection_get_list(cw->table), NULL, cw->window);
+                               file_util_copy(nullptr, collection_table_selection_get_list(cw->table), nullptr, cw->window);
                                break;
                        case 'M': case 'm':
-                               file_util_move(NULL, collection_table_selection_get_list(cw->table), NULL, cw->window);
+                               file_util_move(nullptr, collection_table_selection_get_list(cw->table), nullptr, cw->window);
                                break;
                        case 'R': case 'r':
-                               file_util_rename(NULL, collection_table_selection_get_list(cw->table), cw->window);
+                               file_util_rename(nullptr, collection_table_selection_get_list(cw->table), cw->window);
                                break;
                        case 'D': case 'd':
                                options->file_ops.safe_delete_enable = TRUE;
-                               file_util_delete(NULL, collection_table_selection_get_list(cw->table), cw->window);
+                               file_util_delete(nullptr, collection_table_selection_get_list(cw->table), cw->window);
                                break;
                        case 'S': case 's':
-                               collection_dialog_save_as(NULL, cw->cd);
+                               collection_dialog_save_as(cw->cd);
                                break;
                        case 'W': case 'w':
                                collection_window_close(cw);
@@ -1012,7 +1014,7 @@ static gboolean collection_window_keypress(GtkWidget *UNUSED(widget), GdkEventKe
                switch (event->keyval)
                        {
                        case GDK_KEY_Return: case GDK_KEY_KP_Enter:
-                               layout_image_set_collection(NULL, cw->cd,
+                               layout_image_set_collection(nullptr, cw->cd,
                                        collection_table_get_focus_info(cw->table));
                                break;
                        case 'V': case 'v':
@@ -1022,7 +1024,7 @@ static gboolean collection_window_keypress(GtkWidget *UNUSED(widget), GdkEventKe
                        case 'S': case 's':
                                if (!cw->cd->path)
                                        {
-                                       collection_dialog_save_as(NULL, cw->cd);
+                                       collection_dialog_save_as(cw->cd);
                                        }
                                else if (!collection_save(cw->cd, cw->cd->path))
                                        {
@@ -1030,16 +1032,11 @@ static gboolean collection_window_keypress(GtkWidget *UNUSED(widget), GdkEventKe
                                        }
                                break;
                        case 'A': case 'a':
-                               collection_dialog_append(NULL, cw->cd);
+                               collection_dialog_append(cw->cd);
                                break;
                        case 'N': case 'n':
                                collection_set_sort_method(cw->cd, SORT_NAME);
                                break;
-#ifdef HAVE_STRVERSCMP
-                       case 'I': case 'i':
-                               collection_set_sort_method(cw->cd, SORT_NUMBER);
-                               break;
-#endif
                        case 'D': case 'd':
                                collection_set_sort_method(cw->cd, SORT_TIME);
                                break;
@@ -1072,6 +1069,7 @@ static gboolean collection_window_keypress(GtkWidget *UNUSED(widget), GdkEventKe
                                if (list)
                                        {
                                        collection_remove_by_info_list(cw->cd, list);
+                                       collection_table_refresh(cw->table);
                                        g_list_free(list);
                                        }
                                else
@@ -1107,9 +1105,9 @@ static void collection_window_get_geometry(CollectWindow *cw)
 
        cd = cw->cd;
        window = gtk_widget_get_window(cw->window);
-       gdk_window_get_position(window, &cd->window_x, &cd->window_y);
-       cd->window_w = gdk_window_get_width(window);
-       cd->window_h = gdk_window_get_height(window);
+       gdk_window_get_position(window, &cd->window.x, &cd->window.y);
+       cd->window.width = gdk_window_get_width(window);
+       cd->window.height = gdk_window_get_height(window);
        cd->window_read = TRUE;
 }
 
@@ -1144,9 +1142,9 @@ static void collection_window_update_title(CollectWindow *cw)
        g_free(buf);
 }
 
-static void collection_window_update_info(CollectionData *UNUSED(cd), CollectInfo *ci, gpointer data)
+static void collection_window_update_info(CollectionData *, CollectInfo *ci, gpointer data)
 {
-       CollectWindow *cw = data;
+       auto cw = static_cast<CollectWindow *>(data);
 
        collection_table_file_update(cw->table, ci);
 }
@@ -1180,7 +1178,7 @@ static void collection_window_update(CollectWindow *cw, CollectInfo *ci)
        if (!cw) return;
 
        collection_table_file_update(cw->table, ci);
-       collection_table_file_update(cw->table, NULL);
+       collection_table_file_update(cw->table, nullptr);
 }
 
 static void collection_window_close_final(CollectWindow *cw)
@@ -1190,9 +1188,9 @@ static void collection_window_close_final(CollectWindow *cw)
        collection_window_list = g_list_remove(collection_window_list, cw);
        collection_window_get_geometry(cw);
 
-       gtk_widget_destroy(cw->window);
+       gq_gtk_widget_destroy(cw->window);
 
-       collection_set_update_info_func(cw->cd, NULL, NULL);
+       collection_set_update_info_func(cw->cd, nullptr, nullptr);
        collection_unref(cw->cd);
 
        g_free(cw);
@@ -1200,21 +1198,22 @@ static void collection_window_close_final(CollectWindow *cw)
 
 static void collection_close_save_cb(GenericDialog *gd, gpointer data)
 {
-       CollectWindow *cw = data;
+       auto cw = static_cast<CollectWindow *>(data);
 
-       cw->close_dialog = NULL;
+       cw->close_dialog = nullptr;
        generic_dialog_close(gd);
 
        if (!cw->cd->path)
                {
-               collection_dialog_save_close(NULL, cw->cd);
+               collection_dialog_save_close(cw->cd);
                return;
                }
-       else if (!collection_save(cw->cd, cw->cd->path))
+
+       if (!collection_save(cw->cd, cw->cd->path))
                {
                gchar *buf;
                buf = g_strdup_printf(_("Failed to save the collection:\n%s"), cw->cd->path);
-               warning_dialog(_("Save Failed"), buf, GTK_STOCK_DIALOG_ERROR, cw->window);
+               warning_dialog(_("Save Failed"), buf, GQ_ICON_DIALOG_ERROR, cw->window);
                g_free(buf);
                return;
                }
@@ -1224,9 +1223,9 @@ static void collection_close_save_cb(GenericDialog *gd, gpointer data)
 
 static void collection_close_close_cb(GenericDialog *gd, gpointer data)
 {
-       CollectWindow *cw = data;
+       auto cw = static_cast<CollectWindow *>(data);
 
-       cw->close_dialog = NULL;
+       cw->close_dialog = nullptr;
        generic_dialog_close(gd);
 
        collection_window_close_final(cw);
@@ -1234,9 +1233,9 @@ static void collection_close_close_cb(GenericDialog *gd, gpointer data)
 
 static void collection_close_cancel_cb(GenericDialog *gd, gpointer data)
 {
-       CollectWindow *cw = data;
+       auto cw = static_cast<CollectWindow *>(data);
 
-       cw->close_dialog = NULL;
+       cw->close_dialog = nullptr;
        generic_dialog_close(gd);
 }
 
@@ -1253,12 +1252,12 @@ static void collection_close_dlg_show(CollectWindow *cw)
        gd = generic_dialog_new(_("Close collection"),
                                "close_collection", cw->window, FALSE,
                                collection_close_cancel_cb, cw);
-       generic_dialog_add_message(gd, GTK_STOCK_DIALOG_QUESTION,
+       generic_dialog_add_message(gd, GQ_ICON_DIALOG_QUESTION,
                                   _("Close collection"),
                                   _("Collection has been modified.\nSave first?"), TRUE);
 
-       generic_dialog_add_button(gd, GTK_STOCK_SAVE, NULL, collection_close_save_cb, TRUE);
-       generic_dialog_add_button(gd, GTK_STOCK_DELETE, _("_Discard"), collection_close_close_cb, FALSE);
+       generic_dialog_add_button(gd, GQ_ICON_SAVE, _("Save"), collection_close_save_cb, TRUE);
+       generic_dialog_add_button(gd, GQ_ICON_DELETE, _("_Discard"), collection_close_close_cb, FALSE);
 
        cw->close_dialog = gd->dialog;
 
@@ -1287,11 +1286,11 @@ void collection_window_close_by_collection(CollectionData *cd)
 /**
  * @brief Check if any Collection windows have unsaved data
  * @returns TRUE if unsaved data exists
- * 
+ *
  * Also saves window geometry for Collection windows that have
  * no unsaved data
  */
-gboolean collection_window_modified_exists(void)
+gboolean collection_window_modified_exists()
 {
        GList *work;
        gboolean ret;
@@ -1301,7 +1300,7 @@ gboolean collection_window_modified_exists(void)
        work = collection_window_list;
        while (work)
                {
-               CollectWindow *cw = work->data;
+               auto cw = static_cast<CollectWindow *>(work->data);
                if (cw->cd->changed)
                        {
                        ret = TRUE;
@@ -1319,9 +1318,9 @@ gboolean collection_window_modified_exists(void)
        return ret;
 }
 
-static gboolean collection_window_delete(GtkWidget *UNUSED(widget), GdkEvent *UNUSED(event), gpointer data)
+static gboolean collection_window_delete(GtkWidget *, GdkEvent *, gpointer data)
 {
-       CollectWindow *cw = data;
+       auto cw = static_cast<CollectWindow *>(data);
        collection_window_close(cw);
 
        return TRUE;
@@ -1349,25 +1348,25 @@ CollectWindow *collection_window_new(const gchar *path)
 
        cw->cd = collection_new(path);
 
-       cw->window = window_new(GTK_WINDOW_TOPLEVEL, "collection", PIXBUF_INLINE_ICON_BOOK, NULL, NULL);
+       cw->window = window_new("collection", PIXBUF_INLINE_ICON_BOOK, nullptr, nullptr);
        DEBUG_NAME(cw->window);
 
        geometry.min_width = DEFAULT_MINIMAL_WINDOW_SIZE;
        geometry.min_height = DEFAULT_MINIMAL_WINDOW_SIZE;
        geometry.base_width = COLLECT_DEF_WIDTH;
        geometry.base_height = COLLECT_DEF_HEIGHT;
-       gtk_window_set_geometry_hints(GTK_WINDOW(cw->window), NULL, &geometry,
-                                     GDK_HINT_MIN_SIZE | GDK_HINT_BASE_SIZE);
+       gtk_window_set_geometry_hints(GTK_WINDOW(cw->window), nullptr, &geometry,
+                                     static_cast<GdkWindowHints>(GDK_HINT_MIN_SIZE | GDK_HINT_BASE_SIZE));
 
        if (options->collections_on_top)
                {
-               gtk_window_set_keep_above(GTK_WINDOW(cw->window), TRUE);
+               gq_gtk_window_set_keep_above(GTK_WINDOW(cw->window), TRUE);
                }
 
        if (options->save_window_positions && path && collection_load_only_geometry(cw->cd, path))
                {
-               gtk_window_set_default_size(GTK_WINDOW(cw->window), cw->cd->window_w, cw->cd->window_h);
-               gtk_window_move(GTK_WINDOW(cw->window), cw->cd->window_x, cw->cd->window_y);
+               gtk_window_set_default_size(GTK_WINDOW(cw->window), cw->cd->window.width, cw->cd->window.height);
+               gq_gtk_window_move(GTK_WINDOW(cw->window), cw->cd->window.x, cw->cd->window.y);
                }
        else
                {
@@ -1385,25 +1384,25 @@ CollectWindow *collection_window_new(const gchar *path)
                         G_CALLBACK(collection_window_keypress), cw);
 
        vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
-       gtk_container_add(GTK_CONTAINER(cw->window), vbox);
+       gq_gtk_container_add(GTK_WIDGET(cw->window), vbox);
        gtk_widget_show(vbox);
 
        cw->table = collection_table_new(cw->cd);
-       gtk_box_pack_start(GTK_BOX(vbox), cw->table->scrolled, TRUE, TRUE, 0);
+       gq_gtk_box_pack_start(GTK_BOX(vbox), cw->table->scrolled, TRUE, TRUE, 0);
        gtk_widget_show(cw->table->scrolled);
 
        cw->status_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
-       gtk_box_pack_start(GTK_BOX(vbox), cw->status_box, FALSE, FALSE, 0);
+       gq_gtk_box_pack_start(GTK_BOX(vbox), cw->status_box, FALSE, FALSE, 0);
        gtk_widget_show(cw->status_box);
 
-       frame = gtk_frame_new(NULL);
+       frame = gtk_frame_new(nullptr);
        DEBUG_NAME(frame);
-       gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN);
-       gtk_box_pack_start(GTK_BOX(cw->status_box), frame, TRUE, TRUE, 0);
+       gq_gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN);
+       gq_gtk_box_pack_start(GTK_BOX(cw->status_box), frame, TRUE, TRUE, 0);
        gtk_widget_show(frame);
 
        status_label = gtk_label_new("");
-       gtk_container_add(GTK_CONTAINER(frame), status_label);
+       gq_gtk_container_add(GTK_WIDGET(frame), status_label);
        gtk_widget_show(status_label);
 
        extra_label = gtk_progress_bar_new();
@@ -1411,7 +1410,7 @@ CollectWindow *collection_window_new(const gchar *path)
        gtk_progress_bar_set_text(GTK_PROGRESS_BAR(extra_label), "");
        gtk_progress_bar_set_show_text(GTK_PROGRESS_BAR(extra_label), TRUE);
 
-       gtk_box_pack_start(GTK_BOX(cw->status_box), extra_label, TRUE, TRUE, 0);
+       gq_gtk_box_pack_start(GTK_BOX(cw->status_box), extra_label, TRUE, TRUE, 0);
        gtk_widget_show(extra_label);
 
        collection_table_set_labels(cw->table, status_label, extra_label);
@@ -1421,7 +1420,7 @@ CollectWindow *collection_window_new(const gchar *path)
 
        collection_set_update_info_func(cw->cd, collection_window_update_info, cw);
 
-       if (path && *path == G_DIR_SEPARATOR) collection_load_begin(cw->cd, NULL, COLLECTION_LOAD_NONE);
+       if (path && *path == G_DIR_SEPARATOR) collection_load_begin(cw->cd, nullptr, COLLECTION_LOAD_NONE);
 
        return cw;
 }