Bug fix: No toolbars on first entry
[geeqie.git] / src / dupe.cc
index 7da7d98..57f8ba5 100644 (file)
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
+#include "dupe.h"
+
+#include <sys/time.h>
+#include <sys/types.h>
+
 #include <cinttypes>
+#include <cmath>
+#include <cstdlib>
+#include <cstring>
 
-#include "main.h"
-#include "dupe.h"
+#include <gdk/gdk.h>
+#include <gio/gio.h>
+#include <glib-object.h>
 
 #include "cache.h"
 #include "collect-table.h"
+#include "collect.h"
+#include "compat.h"
+#include "debug.h"
 #include "dnd.h"
 #include "filedata.h"
 #include "history-list.h"
 #include "image-load.h"
 #include "img-view.h"
+#include "intl.h"
 #include "layout-image.h"
 #include "layout-util.h"
+#include "layout.h"
+#include "main-defines.h"
 #include "md5-util.h"
 #include "menu.h"
 #include "misc.h"
-#include "pixbuf-util.h"
+#include "options.h"
 #include "print.h"
+#include "similar.h"
 #include "thumb.h"
+#include "typedefs.h"
 #include "ui-fileops.h"
 #include "ui-menu.h"
 #include "ui-misc.h"
 #include "ui-tree-edit.h"
+#include "ui-utildlg.h"
 #include "uri-utils.h"
 #include "utilops.h"
 #include "window.h"
 
-#include <cmath>
-
-
-#define DUPE_DEF_WIDTH 800
-#define DUPE_DEF_HEIGHT 400
+enum {
+       DUPE_DEF_WIDTH = 800,
+       DUPE_DEF_HEIGHT = 400
+};
 #define DUPE_PROGRESS_PULSE_STEP 0.0001
 
 /** column assignment order (simply change them here)
@@ -341,7 +358,7 @@ static void dupe_window_update_progress(DupeWindow *dw, const gchar *status, gdo
                                d = dw->setup_count - dw->setup_n;
                                }
 
-                       rem = (t - d) ? (static_cast<gdouble>(dw->setup_time_count / 1000000) / (t - d)) * d : 0;
+                       rem = (t - d) ? (static_cast<gdouble>(dw->setup_time_count / 1000000.0) / (t - d)) * d : 0;
 
                        gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(dw->extra_label), value);
 
@@ -351,7 +368,8 @@ static void dupe_window_update_progress(DupeWindow *dw, const gchar *status, gdo
 
                        return;
                        }
-               else if (force ||
+
+               if (force ||
                         value == 0.0 ||
                         dw->setup_count == 0 ||
                         dw->setup_time_count == 0 ||
@@ -474,7 +492,7 @@ static DupeItem *dupe_item_find_fd_by_list_unused(FileData *fd, GList *work)
 {
        while (work)
                {
-               DupeItem *di = static_cast<DupeItem *>(work->data);
+               auto *di = static_cast<DupeItem *>(work->data);
 
                if (di->fd == fd) return di;
 
@@ -498,7 +516,7 @@ static DupeItem *dupe_item_find_path_by_list_unused(const gchar *path, GList *wo
 {
        while (work)
                {
-               DupeItem *di = static_cast<DupeItem *>(work->data);
+               auto *di = static_cast<DupeItem *>(work->data);
 
                if (strcmp(di->fd->path, path) == 0) return di;
 
@@ -1509,15 +1527,10 @@ static gboolean dupe_match(DupeItem *a, DupeItem *b, DupeMatchType mask, gdouble
                                {
                                return TRUE;
                                }
-                       else
-                               {
-                               return FALSE;
-                               }
-                       }
-               else
-                       {
+
                        return FALSE;
                        }
+               return FALSE;
                }
        if (mask & DUPE_MATCH_NAME_CI_CONTENT)
                {
@@ -1531,15 +1544,11 @@ static gboolean dupe_match(DupeItem *a, DupeItem *b, DupeMatchType mask, gdouble
                                {
                                return TRUE;
                                }
-                       else
-                               {
-                               return FALSE;
-                               }
-                       }
-               else
-                       {
+
                        return FALSE;
                        }
+               return FALSE;
+               
                }
        if (mask & DUPE_MATCH_SIZE)
                {
@@ -1817,10 +1826,8 @@ static gint dupe_match_sort_cb(gconstpointer a, gconstpointer b, gpointer data)
                    {
                        return -1;
                        }
-               else
-                       {
-                       return strcmp(di1->md5sum, di2->md5sum);
-                       }
+
+               return strcmp(di1->md5sum, di2->md5sum);
                }
        if (mask & DUPE_MATCH_DIM)
                {
@@ -2764,7 +2771,8 @@ static gboolean dupe_files_add_queue_cb(gpointer data)
                        }
                else if (isdir(fd->path))
                        {
-                       GList *f, *d;
+                       GList *f;
+                       GList *d;
                        dw->add_files_queue = g_list_remove(dw->add_files_queue, g_list_first(dw->add_files_queue)->data);
 
                        if (filelist_read(fd, &f, &d))
@@ -2813,14 +2821,12 @@ static gboolean dupe_files_add_queue_cb(gpointer data)
                {
                return TRUE;
                }
-       else
-               {
-               dw->add_files_queue_id = 0;
-               dupe_destroy_list_cache(dw);
-               g_idle_add(dupe_check_start_cb, dw);
-               gtk_widget_set_sensitive(dw->controls_box, TRUE);
-               return FALSE;
-               }
+
+       dw->add_files_queue_id = 0;
+       dupe_destroy_list_cache(dw);
+       g_idle_add(dupe_check_start_cb, dw);
+       gtk_widget_set_sensitive(dw->controls_box, TRUE);
+       return FALSE;
 }
 
 static void dupe_files_add(DupeWindow *dw, CollectionData *, CollectInfo *info,
@@ -2840,7 +2846,8 @@ static void dupe_files_add(DupeWindow *dw, CollectionData *, CollectInfo *info,
                        }
                else if (isdir(fd->path) && recurse)
                        {
-                       GList *f, *d;
+                       GList *f;
+                       GList *d;
                        if (filelist_read(fd, &f, &d))
                                {
                                GList *work;
@@ -2881,10 +2888,8 @@ static void dupe_files_add(DupeWindow *dw, CollectionData *, CollectInfo *info,
                        {
                        return;
                        }
-               else
-                       {
-                       work = work->next;
-                       }
+
+               work = work->next;
                }
 
        if (dw->second_list)
@@ -2897,10 +2902,8 @@ static void dupe_files_add(DupeWindow *dw, CollectionData *, CollectInfo *info,
                                {
                                return;
                                }
-                       else
-                               {
-                               work = work->next;
-                               }
+
+                       work = work->next;
                        }
                }
 
@@ -2984,7 +2987,8 @@ void dupe_window_add_files(DupeWindow *dw, GList *list, gboolean recurse)
                work = work->next;
                if (isdir(fd->path) && !recurse)
                        {
-                       GList *f, *d;
+                       GList *f;
+                       GList *d;
 
                        if (filelist_read(fd, &f, &d))
                                {
@@ -3123,7 +3127,7 @@ static void dupe_display_stats(DupeWindow *dw, DupeItem *di)
 
        if (!di) return;
 
-       gd = file_util_gen_dlg("Image thumbprint debug info", "thumbprint",
+       gd = file_util_gen_dlg(_("Image thumbprint debug info"), "thumbprint",
                               dw->window, TRUE,
                               nullptr, nullptr);
        generic_dialog_add_button(gd, GQ_ICON_CLOSE, _("Close"), nullptr, TRUE);
@@ -3143,7 +3147,8 @@ static void dupe_display_stats(DupeWindow *dw, DupeItem *di)
                {
                GtkWidget *image;
                GdkPixbuf *pixbuf;
-               gint x, y;
+               gint x;
+               gint y;
                guchar *d_pix;
                guchar *dp;
                gint rs;
@@ -3983,7 +3988,9 @@ static void dupe_menu_setup(DupeWindow *dw)
 
 /* 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
+};
 
 void cell_renderer_height_override(GtkCellRenderer *renderer)
 {
@@ -4002,7 +4009,6 @@ void cell_renderer_height_override(GtkCellRenderer *renderer)
 static GdkRGBA *dupe_listview_color_shifted(GtkWidget *widget)
 {
        static GdkRGBA color;
-       static GdkRGBA color_style;
        static GtkWidget *done = nullptr;
 
        if (done != widget)
@@ -4010,9 +4016,8 @@ static GdkRGBA *dupe_listview_color_shifted(GtkWidget *widget)
                GtkStyle *style;
 
                style = gtk_widget_get_style(widget);
-               convert_gdkcolor_to_gdkrgba(&style->base[GTK_STATE_NORMAL], &color_style);
+               convert_gdkcolor_to_gdkrgba(&style->base[GTK_STATE_NORMAL], &color);
 
-               memcpy(&color, &color_style, sizeof(color));
                shift_color(&color, -1, 0);
                done = widget;
                }
@@ -4472,7 +4477,8 @@ static gint column_sort_cb(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b,
 {
        auto sortable = static_cast<GtkTreeSortable *>(data);
        gint ret = 0;
-       gchar *rank_str_a, *rank_str_b;
+       gchar *rank_str_a;
+       gchar *rank_str_b;
        gint rank_int_a;
        gint rank_int_b;
        gint group_a;
@@ -4778,14 +4784,14 @@ DupeWindow *dupe_window_new()
        gtk_widget_show(dw->custom_threshold);
 
        button = gtk_check_button_new_with_label(_("Sort"));
-       gtk_widget_set_tooltip_text(GTK_WIDGET(button), "Sort by group totals");
+       gtk_widget_set_tooltip_text(GTK_WIDGET(button), _("Sort by group totals"));
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), options->sort_totals);
        g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(dupe_sort_totals_toggle_cb), dw);
        gq_gtk_box_pack_start(GTK_BOX(controls_box), button, FALSE, FALSE, PREF_PAD_SPACE);
        gtk_widget_show(button);
 
        dw->button_rotation_invariant = gtk_check_button_new_with_label(_("Ignore Orientation"));
-       gtk_widget_set_tooltip_text(GTK_WIDGET(dw->button_rotation_invariant), "Ignore image orientation");
+       gtk_widget_set_tooltip_text(GTK_WIDGET(dw->button_rotation_invariant), _("Ignore image orientation"));
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dw->button_rotation_invariant), options->rot_invariant_sim);
        g_signal_connect(G_OBJECT(dw->button_rotation_invariant), "toggled",
                         G_CALLBACK(dupe_window_rotation_invariant_cb), dw);
@@ -5352,7 +5358,7 @@ static void pop_menu_export(GList *, gpointer dupe_window, gpointer data)
 {
        const gint index = GPOINTER_TO_INT(data);
        auto dw = static_cast<DupeWindow *>(dupe_window);
-       const gchar *title = "Export duplicates data";
+       const gchar *title = _("Export duplicates data");
        const gchar *default_path = "/tmp/";
        gchar *file_extension;
        ExportDupesData *edd;