Compile modules based on HAVE_* features
[geeqie.git] / src / dupe.h
1 /*
2  * Copyright (C) 2004 John Ellis
3  * Copyright (C) 2008 - 2016 The Geeqie Team
4  *
5  * Author: John Ellis
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21
22 #ifndef DUPE_H
23 #define DUPE_H
24
25 #include <gdk-pixbuf/gdk-pixbuf.h>
26 #include <glib.h>
27 #include <gtk/gtk.h>
28
29 struct CollectInfo;
30 struct CollectionData;
31 struct FileData;
32 struct ImageLoader;
33 struct ImageSimilarityData;
34 struct ThumbLoader;
35
36 /** @enum DupeMatchType
37  *  match methods
38  */
39 enum DupeMatchType
40 {
41         DUPE_MATCH_NONE = 0,
42         DUPE_MATCH_NAME = 1 << 0,
43         DUPE_MATCH_SIZE = 1 << 1,
44         DUPE_MATCH_DATE = 1 << 2,
45         DUPE_MATCH_DIM  = 1 << 3,       /**< image dimensions */
46         DUPE_MATCH_SUM  = 1 << 4,       /**< MD5sum */
47         DUPE_MATCH_PATH = 1 << 5,
48         DUPE_MATCH_SIM_HIGH = 1 << 6,   /**< similarity */
49         DUPE_MATCH_SIM_MED  = 1 << 7,
50         DUPE_MATCH_SIM_LOW  = 1 << 8,
51         DUPE_MATCH_SIM_CUSTOM = 1 << 9,
52         DUPE_MATCH_NAME_CI = 1 << 10,   /**< same as name, but case insensitive */
53         DUPE_MATCH_NAME_CONTENT = 1 << 11,      /**< same name, but different content */
54         DUPE_MATCH_NAME_CI_CONTENT = 1 << 12,   /**< same name - case insensitive, but different content */
55         DUPE_MATCH_ALL = 1 << 13 /**< N.B. this is used as a clamp value in rcfile.cc */
56 };
57
58 enum DupeSelectType
59 {
60         DUPE_SELECT_NONE,
61         DUPE_SELECT_GROUP1,
62         DUPE_SELECT_GROUP2
63 };
64
65 struct DupeItem
66 {
67         CollectionData *collection;     /**< NULL if from #DupeWindow->files */
68         CollectInfo *info;
69
70         FileData *fd;
71
72         gchar *md5sum;
73         gint width;
74         gint height;
75         gint dimensions; /**< Computed as (#DupeItem->width << 16) + #DupeItem->height */
76
77         ImageSimilarityData *simd;
78
79         GdkPixbuf *pixbuf; /**< thumb */
80
81         GList *group;           /**< List of match data (#DupeMatch) */
82         gdouble group_rank;     /**< (sum of all child ranks) / n */
83
84         gint second;
85 };
86
87 struct DupeMatch
88 {
89         DupeItem *di;
90         gdouble rank;
91 };
92
93 struct DupeWindow
94 {
95         GList *list;    /**< one entry for each dropped file in 1st set window (#DupeItem) */
96         GList *dupes;                   /**< list of dupes (#DupeItem, grouping the #DupeMatch-es) */
97         DupeMatchType match_mask;       /**< mask of things to check for match */
98
99         GtkWidget *window;
100         GtkWidget *table;
101         GtkWidget *listview;
102         GtkWidget *combo;
103         GtkWidget *status_label;
104         GtkWidget *extra_label; /**< Progress bar widget */
105         GtkWidget *button_thumbs;
106         GtkWidget *button_rotation_invariant;
107         GtkWidget *custom_threshold;
108         GList *add_files_queue;
109         guint add_files_queue_id;
110         GHashTable *list_cache; /**< Caches the #DupeItem-s of all items in list. Used when ensuring #FileData-s are unique */
111         GHashTable *second_list_cache; /**< Caches the #DupeItem-s of all items in second_list. Used when ensuring #FileData-s are unique */
112         GtkWidget *controls_box;
113
114         gboolean show_thumbs;
115
116         guint idle_id; /**< event source id */
117         GList *working;
118         gint setup_done; /**< Boolean. Set TRUE when all checksums/dimensions/similarity data have been read or created */
119         gint setup_count; /**< length of set1 or if 2 sets, total length of both */
120         gint setup_n;                   /**< Set to zero on start/reset. These are merely for speed optimization */
121         GList *setup_point;             /**< these are merely for speed optimization */
122         DupeMatchType setup_mask;       /**< these are merely for speed optimization */
123         guint64 setup_time; /**< Time in µsec since Epoch, restored at each phase of operation */
124         guint64 setup_time_count; /**< Time in µsec since time-to-go status display was updated */
125
126         DupeItem *click_item;           /**< for popup menu */
127
128         ThumbLoader *thumb_loader;
129         DupeItem *thumb_item;
130
131         ImageLoader *img_loader;
132
133         GtkTreeSortable *sortable;
134         gint set_count; /**< Index/counter for number of duplicate sets found */
135
136         /* second set comparison stuff */
137
138         gboolean second_set;            /**< second set enabled ? */
139         GList *second_list;             /**< second set dropped files */
140         gboolean second_drop;           /**< drop is on second set */
141
142         GtkWidget *second_vbox;         /**< box of second widgets */
143         GtkWidget *second_listview;
144         GtkWidget *second_status_label;
145
146         gboolean color_frozen;
147
148         /* required for similarity threads */
149         GThreadPool *dupe_comparison_thread_pool;
150         GList *search_matches; /**< List of similarity matches (#DupeSearchMatch) */
151         GMutex search_matches_mutex;
152         GList *search_matches_sorted; /**< \a search_matches sorted by order of entry into thread pool */
153         gint queue_count; /**< Incremented each time an item is pushed onto the similarity thread pool */
154         gint thread_count; /**< Incremented each time a similarity check thread item is completed */
155         GMutex thread_count_mutex;
156         gboolean abort; /**< Stop the similarity check thread queue */
157 };
158
159
160 DupeWindow *dupe_window_new();
161
162 void dupe_window_clear(DupeWindow *dw);
163 void dupe_window_close(DupeWindow *dw);
164
165 void dupe_window_add_collection(DupeWindow *dw, CollectionData *collection);
166 void dupe_window_add_files(DupeWindow *dw, GList *list, gboolean recurse);
167
168 void cell_renderer_height_override(GtkCellRenderer *renderer); /**< cell max with/height hack utility */
169
170 #endif
171 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */