Use std::swap instead of temporary values
[geeqie.git] / src / collect.cc
index f42e546..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 "compat.h"
+#include "debug.h"
 #include "filedata.h"
 #include "img-view.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"
 
-#define COLLECT_DEF_WIDTH 440
-#define COLLECT_DEF_HEIGHT 450
+enum {
+       COLLECT_DEF_WIDTH = 440,
+       COLLECT_DEF_HEIGHT = 450
+};
 
 /**
  *  list of paths to collections */
@@ -180,8 +197,8 @@ static gint collection_list_sort_cb(gconstpointer a, gconstpointer b)
 
        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)
@@ -195,9 +212,11 @@ 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 nullptr;
@@ -209,9 +228,7 @@ GList *collection_list_randomize(GList *list)
                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;
@@ -455,8 +472,8 @@ 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->window.width = COLLECT_DEF_WIDTH;
+       cd->window.height = COLLECT_DEF_HEIGHT;
        cd->existence = g_hash_table_new(nullptr, nullptr);
 
        if (path)
@@ -575,8 +592,8 @@ CollectionData *collection_from_dnd_data(const gchar *data, GList **list, GList
                while (*ptr != '\n' && *ptr != '\0') ptr++;
                if (*ptr == '\0')
                        break;
-               else
-                       while (*ptr == '\n') ptr++;
+
+               while (*ptr == '\n') ptr++;
 
                info = static_cast<CollectInfo *>(g_list_nth_data(cd->list, item_number));
                if (!info) continue;
@@ -1088,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;
 }
 
@@ -1191,7 +1208,8 @@ static void collection_close_save_cb(GenericDialog *gd, gpointer data)
                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);
@@ -1330,7 +1348,7 @@ CollectWindow *collection_window_new(const gchar *path)
 
        cw->cd = collection_new(path);
 
-       cw->window = window_new(GTK_WINDOW_TOPLEVEL, "collection", PIXBUF_INLINE_ICON_BOOK, nullptr, nullptr);
+       cw->window = window_new("collection", PIXBUF_INLINE_ICON_BOOK, nullptr, nullptr);
        DEBUG_NAME(cw->window);
 
        geometry.min_width = DEFAULT_MINIMAL_WINDOW_SIZE;
@@ -1347,8 +1365,8 @@ CollectWindow *collection_window_new(const gchar *path)
 
        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
                {