2 * Copyright (C) 2005 John Ellis
3 * Copyright (C) 2008 - 2016 The Geeqie Team
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.
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.
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.
29 #include "collect-table.h"
33 #include "history_list.h"
34 #include "image-load.h"
37 #include "layout_image.h"
38 #include "layout_util.h"
42 #include "pixbuf_util.h"
45 #include "ui_fileops.h"
48 #include "ui_tree_edit.h"
49 #include "uri_utils.h"
53 #include <gdk/gdkkeysyms.h> /* for keyboard values */
59 #define DUPE_DEF_WIDTH 800
60 #define DUPE_DEF_HEIGHT 400
61 #define DUPE_PROGRESS_PULSE_STEP 0.0001
63 /** column assignment order (simply change them here)
66 DUPE_COLUMN_POINTER = 0,
72 DUPE_COLUMN_DIMENSIONS,
76 DUPE_COLUMN_COUNT /**< total columns */
85 typedef struct _DupeQueueItem DupeQueueItem;
86 /** Used for similarity checks. One for each item pushed
87 * onto the thread pool.
93 GList *work; /**< pointer into \a dw->list or \a dw->second_list (#DupeItem) */
94 gint index; /**< The order items pushed onto thread pool. Used to sort returned matches */
97 typedef struct _DupeSearchMatch DupeSearchMatch;
98 /** Used for similarity checks thread. One for each pair match found.
100 struct _DupeSearchMatch
102 DupeItem *a; /**< \a a / \a b matched pair found */
103 DupeItem *b; /**< \a a / \a b matched pair found */
105 gint index; /**< The order items pushed onto thread pool. Used to sort returned matches */
108 static DupeMatchType param_match_mask;
109 static GList *dupe_window_list = NULL; /**< list of open DupeWindow *s */
112 * Well, after adding the 'compare two sets' option things got a little sloppy in here
113 * because we have to account for two 'modes' everywhere. (be careful).
116 static void dupe_match_unlink(DupeItem *a, DupeItem *b);
117 static DupeItem *dupe_match_find_parent(DupeWindow *dw, DupeItem *child);
119 static gint dupe_match(DupeItem *a, DupeItem *b, DupeMatchType mask, gdouble *rank, gint fast);
121 static void dupe_thumb_step(DupeWindow *dw);
122 static gint dupe_check_cb(gpointer data);
124 static void dupe_second_add(DupeWindow *dw, DupeItem *di);
125 static void dupe_second_remove(DupeWindow *dw, DupeItem *di);
126 static GtkWidget *dupe_menu_popup_second(DupeWindow *dw, DupeItem *di);
128 static void dupe_dnd_init(DupeWindow *dw);
130 static void dupe_notify_cb(FileData *fd, NotifyType type, gpointer data);
131 static void delete_finished_cb(gboolean success, const gchar *dest_path, gpointer data);
133 static GtkWidget *submenu_add_export(GtkWidget *menu, GtkWidget **menu_item, GCallback func, gpointer data);
134 static void dupe_pop_menu_export_cb(GtkWidget *widget, gpointer data);
136 static void dupe_init_list_cache(DupeWindow *dw);
137 static void dupe_destroy_list_cache(DupeWindow *dw);
138 static gboolean dupe_insert_in_list_cache(DupeWindow *dw, FileData *fd);
140 static void dupe_match_link(DupeItem *a, DupeItem *b, gdouble rank);
141 static gint dupe_match_link_exists(DupeItem *child, DupeItem *parent);
144 * @brief The function run in threads for similarity checks
145 * @param d1 #DupeQueueItem
146 * @param d2 #DupeWindow
148 * Used only for similarity checks.\n
149 * Search \a dqi->list for \a dqi->needle and if a match is
150 * found, create a #DupeSearchMatch and add to \a dw->search_matches list\n
151 * If \a dw->abort is set, just increment \a dw->thread_count
153 static void dupe_comparison_func(gpointer d1, gpointer d2)
155 DupeQueueItem *dqi = d1;
157 DupeSearchMatch *dsm;
159 GList *matches = NULL;
164 GList *work = dqi->work;
169 /* forward for second set, back for simple compare */
179 if (dupe_match(di, dqi->needle, dqi->dw->match_mask, &rank, TRUE))
181 dsm = g_new0(DupeSearchMatch, 1);
183 dsm->b = dqi->needle;
185 matches = g_list_prepend(matches, dsm);
186 dsm->index = dqi->index;
195 matches = g_list_reverse(matches);
196 g_mutex_lock(&dw->search_matches_mutex);
197 dw->search_matches = g_list_concat(dw->search_matches, matches);
198 g_mutex_unlock(&dw->search_matches_mutex);
201 g_mutex_lock(&dw->thread_count_mutex);
203 g_mutex_unlock(&dw->thread_count_mutex);
208 * ------------------------------------------------------------------
210 * ------------------------------------------------------------------
214 * @brief Update display of status label
220 static void dupe_window_update_count(DupeWindow *dw, gboolean count_only)
226 text = g_strdup(_("Drop files to compare them."));
230 text = g_strdup_printf(_("%d files"), g_list_length(dw->list));
234 text = g_strdup_printf(_("%d matches found in %d files"), g_list_length(dw->dupes), g_list_length(dw->list));
239 gchar *buf = g_strconcat(text, " ", _("[set 1]"), NULL);
243 gtk_label_set_text(GTK_LABEL(dw->status_label), text);
249 * @brief Returns time in µsec since Epoch
254 static guint64 msec_time(void)
258 if (gettimeofday(&tv, NULL) == -1) return 0;
260 return (guint64)tv.tv_sec * 1000000 + (guint64)tv.tv_usec;
263 static gint dupe_iterations(gint n)
265 return (n * ((n + 1) / 2));
275 * If \a status is blank, clear status bar text and set progress to zero. \n
276 * If \a force is not set, after 2 secs has elapsed, update time-to-go every 250 ms.
278 static void dupe_window_update_progress(DupeWindow *dw, const gchar *status, gdouble value, gboolean force)
280 const gchar *status_text;
284 guint64 new_time = 0;
286 if (dw->setup_n % 10 == 0)
288 new_time = msec_time() - dw->setup_time;
293 dw->setup_count > 0 &&
301 if (new_time - dw->setup_time_count < 250000) return;
302 dw->setup_time_count = new_time;
309 d = dw->setup_count - dw->setup_n;
313 t = dupe_iterations(dw->setup_count);
314 d = dupe_iterations(dw->setup_count - dw->setup_n);
320 d = dw->setup_count - dw->setup_n;
323 rem = (t - d) ? ((gdouble)(dw->setup_time_count / 1000000) / (t - d)) * d : 0;
325 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(dw->extra_label), value);
327 buf = g_strdup_printf("%s %d:%02d ", status, rem / 60, rem % 60);
328 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(dw->extra_label), buf);
335 dw->setup_count == 0 ||
336 dw->setup_time_count == 0 ||
337 (new_time > 0 && new_time - dw->setup_time_count >= 250000))
339 if (dw->setup_time_count == 0) dw->setup_time_count = 1;
340 if (new_time > 0) dw->setup_time_count = new_time;
341 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(dw->extra_label), value);
342 status_text = status;
351 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(dw->extra_label), 0.0);
355 if (status_text) gtk_progress_bar_set_text(GTK_PROGRESS_BAR(dw->extra_label), status_text);
358 static void widget_set_cursor(GtkWidget *widget, gint icon)
362 if (!gtk_widget_get_window(widget)) return;
370 cursor = gdk_cursor_new(icon);
373 gdk_window_set_cursor(gtk_widget_get_window(widget), cursor);
375 if (cursor) gdk_cursor_unref(cursor);
379 * ------------------------------------------------------------------
381 * ------------------------------------------------------------------
384 static void dupe_listview_realign_colors(DupeWindow *dw)
388 gboolean color_set = TRUE;
389 DupeItem *parent = NULL;
392 store = gtk_tree_view_get_model(GTK_TREE_VIEW(dw->listview));
393 valid = gtk_tree_model_get_iter_first(store, &iter);
397 DupeItem *child_parent;
399 gtk_tree_model_get(store, &iter, DUPE_COLUMN_POINTER, &child, -1);
400 child_parent = dupe_match_find_parent(dw, child);
401 if (!parent || parent != child_parent)
405 /* keep the first row as it is */
406 gtk_tree_model_get(store, &iter, DUPE_COLUMN_COLOR, &color_set, -1);
410 color_set = !color_set;
412 parent = dupe_match_find_parent(dw, child);
414 gtk_list_store_set(GTK_LIST_STORE(store), &iter, DUPE_COLUMN_COLOR, color_set, -1);
416 valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter);
421 * ------------------------------------------------------------------
423 * ------------------------------------------------------------------
426 static DupeItem *dupe_item_new(FileData *fd)
430 di = g_new0(DupeItem, 1);
432 di->fd = file_data_ref(fd);
433 di->group_rank = 0.0;
438 static void dupe_item_free(DupeItem *di)
440 file_data_unref(di->fd);
441 image_sim_free(di->simd);
443 if (di->pixbuf) g_object_unref(di->pixbuf);
448 static void dupe_list_free(GList *list)
453 DupeItem *di = work->data;
461 static DupeItem *dupe_item_find_fd_by_list(FileData *fd, GList *work)
465 DupeItem *di = work->data;
467 if (di->fd == fd) return di;
477 static DupeItem *dupe_item_find_fd(DupeWindow *dw, FileData *fd)
481 di = dupe_item_find_fd_by_list(fd, dw->list);
482 if (!di && dw->second_set) di = dupe_item_find_fd_by_list(fd, dw->second_list);
488 static DupeItem *dupe_item_find_path_by_list(const gchar *path, GList *work)
492 DupeItem *di = work->data;
494 if (strcmp(di->fd->path, path) == 0) return di;
502 static DupeItem *dupe_item_find_path(DupeWindow *dw, const gchar *path)
506 di = dupe_item_find_path_by_list(path, dw->list);
507 if (!di && dw->second_set) di = dupe_item_find_path_by_list(path, dw->second_list);
513 * ------------------------------------------------------------------
514 * Image property cache
515 * ------------------------------------------------------------------
518 static void dupe_item_read_cache(DupeItem *di)
525 path = cache_find_location(CACHE_TYPE_SIM, di->fd->path);
528 if (filetime(di->fd->path) != filetime(path))
534 cd = cache_sim_data_load(path);
539 if (!di->simd && cd->sim)
544 if (di->width == 0 && di->height == 0 && cd->dimensions)
546 di->width = cd->width;
547 di->height = cd->height;
548 di->dimensions = (di->width << 16) + di->height;
550 if (!di->md5sum && cd->have_md5sum)
552 di->md5sum = md5_digest_to_text(cd->md5sum);
554 cache_sim_data_free(cd);
558 static void dupe_item_write_cache(DupeItem *di)
565 base = cache_get_location(CACHE_TYPE_SIM, di->fd->path, FALSE, &mode);
566 if (recursive_mkdir_if_not_exists(base, mode))
570 cd = cache_sim_data_new();
571 cd->path = cache_get_location(CACHE_TYPE_SIM, di->fd->path, TRUE, NULL);
573 if (di->width != 0) cache_sim_data_set_dimensions(cd, di->width, di->height);
577 if (md5_digest_from_text(di->md5sum, digest)) cache_sim_data_set_md5sum(cd, digest);
579 if (di->simd) cache_sim_data_set_similarity(cd, di->simd);
581 if (cache_sim_data_save(cd))
583 filetime_set(cd->path, filetime(di->fd->path));
585 cache_sim_data_free(cd);
591 * ------------------------------------------------------------------
593 * ------------------------------------------------------------------
596 static gint dupe_listview_find_item(GtkListStore *store, DupeItem *item, GtkTreeIter *iter)
601 valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), iter);
605 gtk_tree_model_get(GTK_TREE_MODEL(store), iter, DUPE_COLUMN_POINTER, &item_n, -1);
606 if (item_n == item) return row;
608 valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), iter);
615 static void dupe_listview_add(DupeWindow *dw, DupeItem *parent, DupeItem *child)
619 gchar *text[DUPE_COLUMN_COUNT];
622 gboolean color_set = FALSE;
627 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dw->listview)));
633 row = dupe_listview_find_item(store, parent, &iter);
634 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, DUPE_COLUMN_COLOR, &color_set, -1);
640 dm = child->group->data;
641 rank = (gint)floor(dm->rank);
646 log_printf("NULL group in item!\n");
651 if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter))
653 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, DUPE_COLUMN_COLOR, &color_set, -1);
654 color_set = !color_set;
665 di = (child) ? child : parent;
667 if (!child && dw->second_set)
669 text[DUPE_COLUMN_RANK] = g_strdup("[1]");
673 text[DUPE_COLUMN_RANK] = g_strdup((di->second) ? "(2)" : "");
677 text[DUPE_COLUMN_RANK] = g_strdup_printf("%d%s", rank, (di->second) ? " (2)" : "");
680 text[DUPE_COLUMN_THUMB] = "";
681 text[DUPE_COLUMN_NAME] = (gchar *)di->fd->name;
682 text[DUPE_COLUMN_SIZE] = text_from_size(di->fd->size);
683 text[DUPE_COLUMN_DATE] = (gchar *)text_from_time(di->fd->date);
684 if (di->width > 0 && di->height > 0)
686 text[DUPE_COLUMN_DIMENSIONS] = g_strdup_printf("%d x %d", di->width, di->height);
690 text[DUPE_COLUMN_DIMENSIONS] = g_strdup("");
692 text[DUPE_COLUMN_PATH] = di->fd->path;
693 text[DUPE_COLUMN_COLOR] = NULL;
695 gtk_list_store_insert(store, &iter, row);
696 gtk_list_store_set(store, &iter,
697 DUPE_COLUMN_POINTER, di,
698 DUPE_COLUMN_RANK, text[DUPE_COLUMN_RANK],
699 DUPE_COLUMN_THUMB, NULL,
700 DUPE_COLUMN_NAME, text[DUPE_COLUMN_NAME],
701 DUPE_COLUMN_SIZE, text[DUPE_COLUMN_SIZE],
702 DUPE_COLUMN_DATE, text[DUPE_COLUMN_DATE],
703 DUPE_COLUMN_DIMENSIONS, text[DUPE_COLUMN_DIMENSIONS],
704 DUPE_COLUMN_PATH, text[DUPE_COLUMN_PATH],
705 DUPE_COLUMN_COLOR, color_set,
706 DUPE_COLUMN_SET, dw->set_count,
709 g_free(text[DUPE_COLUMN_RANK]);
710 g_free(text[DUPE_COLUMN_SIZE]);
711 g_free(text[DUPE_COLUMN_DIMENSIONS]);
714 static void dupe_listview_select_dupes(DupeWindow *dw, DupeSelectType parents);
716 static void dupe_listview_populate(DupeWindow *dw)
721 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dw->listview)));
722 gtk_list_store_clear(store);
724 work = g_list_last(dw->dupes);
727 DupeItem *parent = work->data;
730 dupe_listview_add(dw, parent, NULL);
732 temp = g_list_last(parent->group);
735 DupeMatch *dm = temp->data;
740 dupe_listview_add(dw, parent, child);
748 gtk_tree_view_columns_autosize(GTK_TREE_VIEW(dw->listview));
750 if (options->duplicates_select_type == DUPE_SELECT_GROUP1)
752 dupe_listview_select_dupes(dw, DUPE_SELECT_GROUP1);
754 else if (options->duplicates_select_type == DUPE_SELECT_GROUP2)
756 dupe_listview_select_dupes(dw, DUPE_SELECT_GROUP2);
761 static void dupe_listview_remove(DupeWindow *dw, DupeItem *di)
769 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dw->listview)));
770 row = dupe_listview_find_item(store, di, &iter);
773 tree_view_move_cursor_away(GTK_TREE_VIEW(dw->listview), &iter, TRUE);
774 gtk_list_store_remove(store, &iter);
776 if (g_list_find(dw->dupes, di) != NULL)
778 if (!dw->color_frozen) dupe_listview_realign_colors(dw);
783 static GList *dupe_listview_get_filelist(DupeWindow *dw, GtkWidget *listview)
790 store = gtk_tree_view_get_model(GTK_TREE_VIEW(listview));
791 valid = gtk_tree_model_get_iter_first(store, &iter);
795 gtk_tree_model_get(store, &iter, DUPE_COLUMN_POINTER, &di, -1);
796 list = g_list_prepend(list, file_data_ref(di->fd));
798 valid = gtk_tree_model_iter_next(store, &iter);
801 return g_list_reverse(list);
805 static GList *dupe_listview_get_selection(DupeWindow *dw, GtkWidget *listview)
808 GtkTreeSelection *selection;
813 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(listview));
814 slist = gtk_tree_selection_get_selected_rows(selection, &store);
818 GtkTreePath *tpath = work->data;
822 gtk_tree_model_get_iter(store, &iter, tpath);
823 gtk_tree_model_get(store, &iter, DUPE_COLUMN_POINTER, &di, -1);
826 list = g_list_prepend(list, file_data_ref(di->fd));
830 g_list_foreach(slist, (GFunc)tree_path_free_wrapper, NULL);
833 return g_list_reverse(list);
836 static gboolean dupe_listview_item_is_selected(DupeWindow *dw, DupeItem *di, GtkWidget *listview)
839 GtkTreeSelection *selection;
842 gboolean found = FALSE;
844 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(listview));
845 slist = gtk_tree_selection_get_selected_rows(selection, &store);
847 while (!found && work)
849 GtkTreePath *tpath = work->data;
853 gtk_tree_model_get_iter(store, &iter, tpath);
854 gtk_tree_model_get(store, &iter, DUPE_COLUMN_POINTER, &di_n, -1);
855 if (di_n == di) found = TRUE;
858 g_list_foreach(slist, (GFunc)tree_path_free_wrapper, NULL);
864 static void dupe_listview_select_dupes(DupeWindow *dw, DupeSelectType parents)
867 GtkTreeSelection *selection;
871 gint set_count_last = -1;
873 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dw->listview));
874 gtk_tree_selection_unselect_all(selection);
876 store = gtk_tree_view_get_model(GTK_TREE_VIEW(dw->listview));
877 valid = gtk_tree_model_get_iter_first(store, &iter);
882 gtk_tree_model_get(store, &iter, DUPE_COLUMN_POINTER, &di, DUPE_COLUMN_SET, &set_count, -1);
883 if (set_count != set_count_last)
885 set_count_last = set_count;
886 if (parents == DUPE_SELECT_GROUP1)
888 gtk_tree_selection_select_iter(selection, &iter);
893 if (parents == DUPE_SELECT_GROUP2)
895 gtk_tree_selection_select_iter(selection, &iter);
898 valid = gtk_tree_model_iter_next(store, &iter);
903 * ------------------------------------------------------------------
904 * Match group manipulation
905 * ------------------------------------------------------------------
909 * @brief Search \a parent->group for \a child (#DupeItem)
915 static DupeMatch *dupe_match_find_match(DupeItem *child, DupeItem *parent)
919 work = parent->group;
922 DupeMatch *dm = work->data;
923 if (dm->di == child) return dm;
930 * @brief Create #DupeMatch structure for \a child, and insert into \a parent->group list.
936 static void dupe_match_link_child(DupeItem *child, DupeItem *parent, gdouble rank)
940 dm = g_new0(DupeMatch, 1);
943 parent->group = g_list_append(parent->group, dm);
947 * @brief Link \a a & \a b as both parent and child
952 * Link \a a as child of \a b, and \a b as child of \a a
954 static void dupe_match_link(DupeItem *a, DupeItem *b, gdouble rank)
956 dupe_match_link_child(a, b, rank);
957 dupe_match_link_child(b, a, rank);
961 * @brief Remove \a child #DupeMatch from \a parent->group list.
966 static void dupe_match_unlink_child(DupeItem *child, DupeItem *parent)
970 dm = dupe_match_find_match(child, parent);
973 parent->group = g_list_remove(parent->group, dm);
979 * @brief Unlink \a a from \a b, and \a b from \a a
983 * Free the relevant #DupeMatch items from the #DupeItem group lists
985 static void dupe_match_unlink(DupeItem *a, DupeItem *b)
987 dupe_match_unlink_child(a, b);
988 dupe_match_unlink_child(b, a);
994 * @param unlink_children
996 * If \a unlink_children is set, unlink all entries in \a parent->group list. \n
997 * Free the \a parent->group list and set group_rank to zero;
999 static void dupe_match_link_clear(DupeItem *parent, gboolean unlink_children)
1003 work = parent->group;
1006 DupeMatch *dm = work->data;
1009 if (unlink_children) dupe_match_unlink_child(parent, dm->di);
1014 g_list_free(parent->group);
1015 parent->group = NULL;
1016 parent->group_rank = 0.0;
1020 * @brief Search \a parent->group list for \a child
1023 * @returns boolean TRUE/FALSE found/not found
1026 static gint dupe_match_link_exists(DupeItem *child, DupeItem *parent)
1028 return (dupe_match_find_match(child, parent) != NULL);
1032 * @brief Search \a parent->group for \a child, and return \a child->rank
1035 * @returns \a dm->di->rank
1038 static gdouble dupe_match_link_rank(DupeItem *child, DupeItem *parent)
1042 dm = dupe_match_find_match(child, parent);
1043 if (dm) return dm->rank;
1049 * @brief Find highest rank in \a child->group
1053 * Search the #DupeMatch entries in the \a child->group list.
1054 * Return the #DupeItem with the highest rank. If more than one have
1055 * the same rank, the first encountered is used.
1057 static DupeItem *dupe_match_highest_rank(DupeItem *child)
1063 work = child->group;
1066 DupeMatch *dm = work->data;
1067 if (!dr || dm->rank > dr->rank)
1074 return (dr) ? dr->di : NULL;
1078 * @brief Compute and store \a parent->group_rank
1081 * Group_rank = (sum of all child ranks) / n
1083 static void dupe_match_rank_update(DupeItem *parent)
1089 work = parent->group;
1092 DupeMatch *dm = work->data;
1100 parent->group_rank = rank / c;
1104 parent->group_rank = 0.0;
1108 static DupeItem *dupe_match_find_parent(DupeWindow *dw, DupeItem *child)
1112 if (g_list_find(dw->dupes, child)) return child;
1114 work = child->group;
1117 DupeMatch *dm = work->data;
1118 if (g_list_find(dw->dupes, dm->di)) return dm->di;
1127 * @param work (#DupeItem) dw->list or dw->second_list
1129 * Unlink all #DupeItem-s in \a work.
1130 * Do not unlink children.
1132 static void dupe_match_reset_list(GList *work)
1136 DupeItem *di = work->data;
1139 dupe_match_link_clear(di, FALSE);
1143 static void dupe_match_reparent(DupeWindow *dw, DupeItem *old, DupeItem *new)
1147 if (!old || !new || !dupe_match_link_exists(old, new)) return;
1149 dupe_match_link_clear(new, TRUE);
1153 DupeMatch *dm = work->data;
1154 dupe_match_unlink_child(old, dm->di);
1155 dupe_match_link_child(new, dm->di, dm->rank);
1159 new->group = old->group;
1162 work = g_list_find(dw->dupes, old);
1163 if (work) work->data = new;
1166 static void dupe_match_print_group(DupeItem *di)
1170 log_printf("+ %f %s\n", di->group_rank, di->fd->name);
1175 DupeMatch *dm = work->data;
1178 log_printf(" %f %s\n", dm->rank, dm->di->fd->name);
1184 static void dupe_match_print_list(GList *list)
1191 DupeItem *di = work->data;
1192 dupe_match_print_group(di);
1197 /* level 3, unlinking and orphan handling */
1201 * @param parent \a di from \a child->group
1202 * @param[inout] list \a dw->list sorted by rank (#DupeItem)
1204 * @returns modified \a list
1206 * Called for each entry in \a child->group (#DupeMatch) with \a parent set to \a dm->di. \n
1207 * Find the highest rank #DupeItem of the \a parent's children. \n
1208 * If that is == \a child OR
1209 * highest rank #DupeItem of \a child == \a parent then FIXME:
1212 static GList *dupe_match_unlink_by_rank(DupeItem *child, DupeItem *parent, GList *list, DupeWindow *dw)
1214 DupeItem *best = NULL;
1216 best = dupe_match_highest_rank(parent); // highest rank in parent->group
1217 if (best == child || dupe_match_highest_rank(child) == parent)
1222 DEBUG_2("link found %s to %s [%d]", child->fd->name, parent->fd->name, g_list_length(parent->group));
1224 work = parent->group;
1227 DupeMatch *dm = work->data;
1232 if (orphan != child && g_list_length(orphan->group) < 2)
1234 dupe_match_link_clear(orphan, TRUE);
1235 if (!dw->second_set || orphan->second)
1237 dupe_match(orphan, child, dw->match_mask, &rank, FALSE);
1238 dupe_match_link(orphan, child, rank);
1240 list = g_list_remove(list, orphan);
1244 rank = dupe_match_link_rank(child, parent); // child->rank
1245 dupe_match_link_clear(parent, TRUE);
1246 dupe_match_link(child, parent, rank);
1247 list = g_list_remove(list, parent);
1251 DEBUG_2("unlinking %s and %s", child->fd->name, parent->fd->name);
1253 dupe_match_unlink(child, parent);
1262 * @param[inout] list \a dw->list sorted by rank (#DupeItem)
1265 * @returns modified \a list
1267 * Called for each entry in \a list.
1268 * Call unlink for each child in \a di->group
1270 static GList *dupe_match_group_filter(GList *list, DupeItem *di, DupeWindow *dw)
1274 work = g_list_last(di->group);
1277 DupeMatch *dm = work->data;
1279 list = dupe_match_unlink_by_rank(di, dm->di, list, dw);
1288 * @param[inout] list \a dw->list sorted by rank (#DupeItem)
1290 * @returns Filtered \a list
1293 * Call group filter for each \a di in \a list
1295 static GList *dupe_match_group_trim(GList *list, DupeWindow *dw)
1302 DupeItem *di = work->data;
1303 if (!di->second) list = dupe_match_group_filter(list, di, dw);
1305 if (di->second) list = g_list_remove(list, di);
1311 static gint dupe_match_sort_groups_cb(gconstpointer a, gconstpointer b)
1313 DupeMatch *da = (DupeMatch *)a;
1314 DupeMatch *db = (DupeMatch *)b;
1316 if (da->rank > db->rank) return -1;
1317 if (da->rank < db->rank) return 1;
1322 * @brief Sorts the children of each #DupeItem in \a list
1323 * @param list #DupeItem
1325 * Sorts the #DupeItem->group children on rank
1327 static void dupe_match_sort_groups(GList *list)
1334 DupeItem *di = work->data;
1335 di->group = g_list_sort(di->group, dupe_match_sort_groups_cb);
1340 static gint dupe_match_totals_sort_cb(gconstpointer a, gconstpointer b)
1342 DupeItem *da = (DupeItem *)a;
1343 DupeItem *db = (DupeItem *)b;
1345 if (g_list_length(da->group) > g_list_length(db->group)) return -1;
1346 if (g_list_length(da->group) < g_list_length(db->group)) return 1;
1348 if (da->group_rank < db->group_rank) return -1;
1349 if (da->group_rank > db->group_rank) return 1;
1355 * @brief Callback for group_rank sort
1362 static gint dupe_match_rank_sort_cb(gconstpointer a, gconstpointer b)
1364 DupeItem *da = (DupeItem *)a;
1365 DupeItem *db = (DupeItem *)b;
1367 if (da->group_rank > db->group_rank) return -1;
1368 if (da->group_rank < db->group_rank) return 1;
1373 * @brief Sorts \a source_list by group-rank
1374 * @param source_list #DupeItem
1377 * Computes group_rank for each #DupeItem. \n
1378 * Items with no group list are ignored.
1379 * Returns allocated GList of #DupeItem-s sorted by group_rank
1381 static GList *dupe_match_rank_sort(GList *source_list)
1389 DupeItem *di = work->data;
1393 dupe_match_rank_update(di); // Compute and store group_rank for di
1394 list = g_list_prepend(list, di);
1400 return g_list_sort(list, dupe_match_rank_sort_cb);
1404 * @brief Returns allocated GList of dupes sorted by totals
1405 * @param source_list
1410 static GList *dupe_match_totals_sort(GList *source_list)
1412 source_list = g_list_sort(source_list, dupe_match_totals_sort_cb);
1414 source_list = g_list_first(source_list);
1415 return g_list_reverse(source_list);
1424 static void dupe_match_rank(DupeWindow *dw)
1428 list = dupe_match_rank_sort(dw->list); // sorted by group_rank, no-matches filtered out
1430 if (required_debug_level(2)) dupe_match_print_list(list);
1432 DEBUG_1("Similar items: %d", g_list_length(list));
1433 list = dupe_match_group_trim(list, dw);
1434 DEBUG_1("Unique groups: %d", g_list_length(list));
1436 dupe_match_sort_groups(list);
1438 if (required_debug_level(2)) dupe_match_print_list(list);
1440 list = dupe_match_rank_sort(list);
1441 if (options->sort_totals)
1443 list = dupe_match_totals_sort(list);
1445 if (required_debug_level(2)) dupe_match_print_list(list);
1447 g_list_free(dw->dupes);
1452 * ------------------------------------------------------------------
1454 * ------------------------------------------------------------------
1466 * For similarity checks, compute rank - (similarity factor between a and b). \n
1467 * If rank < user-set sim value, returns FALSE.
1469 static gboolean dupe_match(DupeItem *a, DupeItem *b, DupeMatchType mask, gdouble *rank, gint fast)
1473 if (a->fd->path == b->fd->path) return FALSE;
1475 if (mask & DUPE_MATCH_ALL)
1479 if (mask & DUPE_MATCH_PATH)
1481 if (utf8_compare(a->fd->path, b->fd->path, TRUE) != 0) return FALSE;
1483 if (mask & DUPE_MATCH_NAME)
1485 if (strcmp(a->fd->collate_key_name, b->fd->collate_key_name) != 0) return FALSE;
1487 if (mask & DUPE_MATCH_NAME_CI)
1489 if (strcmp(a->fd->collate_key_name_nocase, b->fd->collate_key_name_nocase) != 0) return FALSE;
1491 if (mask & DUPE_MATCH_NAME_CONTENT)
1493 if (strcmp(a->fd->collate_key_name, b->fd->collate_key_name) == 0)
1495 if (!a->md5sum) a->md5sum = md5_text_from_file_utf8(a->fd->path, "");
1496 if (!b->md5sum) b->md5sum = md5_text_from_file_utf8(b->fd->path, "");
1497 if (a->md5sum[0] == '\0' ||
1498 b->md5sum[0] == '\0' ||
1499 strcmp(a->md5sum, b->md5sum) != 0)
1513 if (mask & DUPE_MATCH_NAME_CI_CONTENT)
1515 if (strcmp(a->fd->collate_key_name_nocase, b->fd->collate_key_name_nocase) == 0)
1517 if (!a->md5sum) a->md5sum = md5_text_from_file_utf8(a->fd->path, "");
1518 if (!b->md5sum) b->md5sum = md5_text_from_file_utf8(b->fd->path, "");
1519 if (a->md5sum[0] == '\0' ||
1520 b->md5sum[0] == '\0' ||
1521 strcmp(a->md5sum, b->md5sum) != 0)
1535 if (mask & DUPE_MATCH_SIZE)
1537 if (a->fd->size != b->fd->size) return FALSE;
1539 if (mask & DUPE_MATCH_DATE)
1541 if (a->fd->date != b->fd->date) return FALSE;
1543 if (mask & DUPE_MATCH_SUM)
1545 if (!a->md5sum) a->md5sum = md5_text_from_file_utf8(a->fd->path, "");
1546 if (!b->md5sum) b->md5sum = md5_text_from_file_utf8(b->fd->path, "");
1547 if (a->md5sum[0] == '\0' ||
1548 b->md5sum[0] == '\0' ||
1549 strcmp(a->md5sum, b->md5sum) != 0) return FALSE;
1551 if (mask & DUPE_MATCH_DIM)
1553 if (a->width == 0) image_load_dimensions(a->fd, &a->width, &a->height);
1554 if (b->width == 0) image_load_dimensions(b->fd, &b->width, &b->height);
1555 if (a->width != b->width || a->height != b->height) return FALSE;
1557 if (mask & DUPE_MATCH_SIM_HIGH ||
1558 mask & DUPE_MATCH_SIM_MED ||
1559 mask & DUPE_MATCH_SIM_LOW ||
1560 mask & DUPE_MATCH_SIM_CUSTOM)
1565 if (mask & DUPE_MATCH_SIM_HIGH) m = 0.95;
1566 else if (mask & DUPE_MATCH_SIM_MED) m = 0.90;
1567 else if (mask & DUPE_MATCH_SIM_CUSTOM) m = (gdouble)options->duplicates_similarity_threshold / 100.0;
1572 f = image_sim_compare_fast(a->simd, b->simd, m);
1576 f = image_sim_compare(a->simd, b->simd);
1581 if (f < m) return FALSE;
1583 DEBUG_3("similar: %32s %32s = %f", a->fd->name, b->fd->name, f);
1590 * @brief Determine if there is a match
1594 * @returns DUPE_MATCH/DUPE_NO_MATCH/DUPE_NAME_MATCH
1595 * DUPE_NAME_MATCH is used for name != contents searches:
1596 * the name and content match i.e.
1597 * no match, but keep searching
1599 * Called when stepping down the array looking for adjacent matches,
1600 * and from the 2nd set search.
1602 * Is not used for similarity checks.
1604 static DUPE_CHECK_RESULT dupe_match_check(DupeItem *di1, DupeItem *di2, gpointer data)
1606 DupeWindow *dw = data;
1607 DupeMatchType mask = dw->match_mask;
1609 if (mask & DUPE_MATCH_ALL)
1613 if (mask & DUPE_MATCH_PATH)
1615 if (utf8_compare(di1->fd->path, di2->fd->path, TRUE) != 0)
1617 return DUPE_NO_MATCH;
1620 if (mask & DUPE_MATCH_NAME)
1622 if (g_strcmp0(di1->fd->collate_key_name, di2->fd->collate_key_name) != 0)
1624 return DUPE_NO_MATCH;
1627 if (mask & DUPE_MATCH_NAME_CI)
1629 if (g_strcmp0(di1->fd->collate_key_name_nocase, di2->fd->collate_key_name_nocase) != 0 )
1631 return DUPE_NO_MATCH;
1634 if (mask & DUPE_MATCH_NAME_CONTENT)
1636 if (g_strcmp0(di1->fd->collate_key_name, di2->fd->collate_key_name) == 0)
1638 if (g_strcmp0(di1->md5sum, di2->md5sum) == 0)
1640 return DUPE_NAME_MATCH;
1645 return DUPE_NO_MATCH;
1648 if (mask & DUPE_MATCH_NAME_CI_CONTENT)
1650 if (strcmp(di1->fd->collate_key_name_nocase, di2->fd->collate_key_name_nocase) == 0)
1652 if (g_strcmp0(di1->md5sum, di2->md5sum) == 0)
1654 return DUPE_NAME_MATCH;
1659 return DUPE_NO_MATCH;
1662 if (mask & DUPE_MATCH_SIZE)
1664 if (di1->fd->size != di2->fd->size)
1666 return DUPE_NO_MATCH;
1669 if (mask & DUPE_MATCH_DATE)
1671 if (di1->fd->date != di2->fd->date)
1673 return DUPE_NO_MATCH;
1676 if (mask & DUPE_MATCH_SUM)
1678 if (g_strcmp0(di1->md5sum, di2->md5sum) != 0)
1680 return DUPE_NO_MATCH;
1683 if (mask & DUPE_MATCH_DIM)
1685 if (di1->dimensions != di2->dimensions)
1687 return DUPE_NO_MATCH;
1695 * @brief The callback for the binary search
1698 * @param param_match_mask
1699 * @returns negative/0/positive
1701 * Is not used for similarity checks.
1703 * Used only when two file sets are used.
1704 * Requires use of a global for param_match_mask because there is no
1705 * g_array_binary_search_with_data() function in glib.
1707 static gint dupe_match_binary_search_cb(gconstpointer a, gconstpointer b)
1709 const DupeItem *di1 = *((DupeItem **) a);
1710 const DupeItem *di2 = b;
1711 DupeMatchType mask = param_match_mask;
1713 if (mask & DUPE_MATCH_ALL)
1717 if (mask & DUPE_MATCH_PATH)
1719 return utf8_compare(di1->fd->path, di2->fd->path, TRUE);
1721 if (mask & DUPE_MATCH_NAME)
1723 return g_strcmp0(di1->fd->collate_key_name, di2->fd->collate_key_name);
1725 if (mask & DUPE_MATCH_NAME_CI)
1727 return strcmp(di1->fd->collate_key_name_nocase, di2->fd->collate_key_name_nocase);
1729 if (mask & DUPE_MATCH_NAME_CONTENT)
1731 return g_strcmp0(di1->fd->collate_key_name, di2->fd->collate_key_name);
1733 if (mask & DUPE_MATCH_NAME_CI_CONTENT)
1735 return strcmp(di1->fd->collate_key_name_nocase, di2->fd->collate_key_name_nocase);
1737 if (mask & DUPE_MATCH_SIZE)
1739 return (di1->fd->size - di2->fd->size);
1741 if (mask & DUPE_MATCH_DATE)
1743 return (di1->fd->date - di2->fd->date);
1745 if (mask & DUPE_MATCH_SUM)
1747 return g_strcmp0(di1->md5sum, di2->md5sum);
1749 if (mask & DUPE_MATCH_DIM)
1751 return (di1->dimensions - di2->dimensions);
1758 * @brief The callback for the array sort
1762 * @returns negative/0/positive
1764 * Is not used for similarity checks.
1766 static gint dupe_match_sort_cb(gconstpointer a, gconstpointer b, gpointer data)
1768 const DupeItem *di1 = *((DupeItem **) a);
1769 const DupeItem *di2 = *((DupeItem **) b);
1770 DupeWindow *dw = data;
1771 DupeMatchType mask = dw->match_mask;
1773 if (mask & DUPE_MATCH_ALL)
1777 if (mask & DUPE_MATCH_PATH)
1779 return utf8_compare(di1->fd->path, di2->fd->path, TRUE);
1781 if (mask & DUPE_MATCH_NAME)
1783 return g_strcmp0(di1->fd->collate_key_name, di2->fd->collate_key_name);
1785 if (mask & DUPE_MATCH_NAME_CI)
1787 return strcmp(di1->fd->collate_key_name_nocase, di2->fd->collate_key_name_nocase);
1789 if (mask & DUPE_MATCH_NAME_CONTENT)
1791 return g_strcmp0(di1->fd->collate_key_name, di2->fd->collate_key_name);
1793 if (mask & DUPE_MATCH_NAME_CI_CONTENT)
1795 return strcmp(di1->fd->collate_key_name_nocase, di2->fd->collate_key_name_nocase);
1797 if (mask & DUPE_MATCH_SIZE)
1799 return (di1->fd->size - di2->fd->size);
1801 if (mask & DUPE_MATCH_DATE)
1803 return (di1->fd->date - di2->fd->date);
1805 if (mask & DUPE_MATCH_SUM)
1807 if (di1->md5sum[0] == '\0' || di2->md5sum[0] == '\0')
1813 return strcmp(di1->md5sum, di2->md5sum);
1816 if (mask & DUPE_MATCH_DIM)
1818 if (!di1 || !di2 || !di1->width || !di1->height || !di2->width || !di2->height)
1822 return (di1->dimensions - di2->dimensions);
1825 return 0; // should not execute
1829 * @brief Check for duplicate matches
1832 * Is not used for similarity checks.
1834 * Loads the file sets into an array and sorts on the searched
1837 * If one file set, steps down the array looking for adjacent equal values.
1839 * If two file sets, steps down the first set and for each value
1840 * does a binary search for matches in the second set.
1842 static void dupe_array_check(DupeWindow *dw )
1849 DUPE_CHECK_RESULT check_result;
1850 DupeMatchType mask = dw->match_mask;
1851 param_match_mask = dw->match_mask;
1852 guint out_match_index;
1853 gboolean match_found = FALSE;;
1855 if (!dw->list) return;
1857 array_set1 = g_array_new(TRUE, TRUE, sizeof(gpointer));
1858 array_set2 = g_array_new(TRUE, TRUE, sizeof(gpointer));
1859 dupe_match_reset_list(dw->list);
1864 DupeItem *di = work->data;
1865 g_array_append_val(array_set1, di);
1869 g_array_sort_with_data(array_set1, dupe_match_sort_cb, dw);
1873 /* Two sets - nothing can be done until a second set is loaded */
1874 if (dw->second_list)
1876 work = dw->second_list;
1879 DupeItem *di = work->data;
1880 g_array_append_val(array_set2, (work->data));
1883 g_array_sort_with_data(array_set2, dupe_match_sort_cb, dw);
1885 for (i_set1 = 0; i_set1 <= (gint)(array_set1->len) - 1; i_set1++)
1887 DupeItem *di1 = g_array_index(array_set1, gpointer, i_set1);
1888 DupeItem *di2 = NULL;
1889 /* If multiple identical entries in set 1, use the last one */
1890 if (i_set1 < (gint)(array_set1->len) - 2)
1892 di2 = g_array_index(array_set1, gpointer, i_set1 + 1);
1893 check_result = dupe_match_check(di1, di2, dw);
1894 if (check_result == DUPE_MATCH || check_result == DUPE_NAME_MATCH)
1900 #if ((GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION >= 62))
1901 match_found = g_array_binary_search(array_set2, di1, dupe_match_binary_search_cb, &out_match_index);
1905 match_found = FALSE;
1906 for(i=0; i < array_set2->len; i++)
1908 di2 = g_array_index(array_set2, gpointer, i);
1909 check_result = dupe_match_check(di1, di2, dw);
1910 if (check_result == DUPE_MATCH)
1913 out_match_index = i;
1921 di2 = g_array_index(array_set2, gpointer, out_match_index);
1923 check_result = dupe_match_check(di1, di2, dw);
1924 if (check_result == DUPE_MATCH || check_result == DUPE_NAME_MATCH)
1926 if (check_result == DUPE_MATCH)
1928 dupe_match_link(di2, di1, 0.0);
1930 i_set2 = out_match_index + 1;
1932 if (i_set2 > (gint)(array_set2->len) - 1)
1936 /* Look for multiple matches in set 2 for item di1 */
1937 di2 = g_array_index(array_set2, gpointer, i_set2);
1938 check_result = dupe_match_check(di1, di2, dw);
1939 while (check_result == DUPE_MATCH || check_result == DUPE_NAME_MATCH)
1941 if (check_result == DUPE_MATCH)
1943 dupe_match_link(di2, di1, 0.0);
1946 if (i_set2 > (gint)(array_set2->len) - 1)
1950 di2 = g_array_index(array_set2, gpointer, i_set2);
1951 check_result = dupe_match_check(di1, di2, dw);
1960 /* File set 1 only */
1961 g_list_free(dw->dupes);
1964 if ((gint)(array_set1->len) > 1)
1966 for (i_set1 = 0; i_set1 <= (gint)(array_set1->len) - 2; i_set1++)
1968 DupeItem *di1 = g_array_index(array_set1, gpointer, i_set1);
1969 DupeItem *di2 = g_array_index(array_set1, gpointer, i_set1 + 1);
1971 check_result = dupe_match_check(di1, di2, dw);
1972 if (check_result == DUPE_MATCH || check_result == DUPE_NAME_MATCH)
1974 if (check_result == DUPE_MATCH)
1976 dupe_match_link(di2, di1, 0.0);
1980 if ( i_set1 + 1 > (gint)(array_set1->len) - 1)
1984 /* Look for multiple matches for item di1 */
1985 di2 = g_array_index(array_set1, gpointer, i_set1 + 1);
1986 check_result = dupe_match_check(di1, di2, dw);
1987 while (check_result == DUPE_MATCH || check_result == DUPE_NAME_MATCH)
1989 if (check_result == DUPE_MATCH)
1991 dupe_match_link(di2, di1, 0.0);
1995 if (i_set1 + 1 > (gint)(array_set1->len) - 1)
1999 di2 = g_array_index(array_set1, gpointer, i_set1 + 1);
2000 check_result = dupe_match_check(di1, di2, dw);
2006 g_array_free(array_set1, TRUE);
2007 g_array_free(array_set2, TRUE);
2011 * @brief Look for similarity match
2016 * Only used for similarity checks.\n
2017 * Called from dupe_check_cb.
2018 * Called for each entry in the list.
2019 * Steps through the list looking for matches against needle.
2020 * Pushes a #DupeQueueItem onto thread pool queue.
2022 static void dupe_list_check_match(DupeWindow *dw, DupeItem *needle, GList *start)
2029 work = dw->second_list;
2037 work = g_list_last(dw->list);
2040 dqi = g_new0(DupeQueueItem, 1);
2041 dqi->needle = needle;
2044 dqi->index = dw->queue_count;
2045 g_thread_pool_push(dw->dupe_comparison_thread_pool, dqi, NULL);
2049 * ------------------------------------------------------------------
2050 * Thumbnail handling
2051 * ------------------------------------------------------------------
2054 static void dupe_listview_set_thumb(DupeWindow *dw, DupeItem *di, GtkTreeIter *iter)
2056 GtkListStore *store;
2059 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dw->listview)));
2062 if (dupe_listview_find_item(store, di, &iter_n) >= 0)
2068 if (iter) gtk_list_store_set(store, iter, DUPE_COLUMN_THUMB, di->pixbuf, -1);
2071 static void dupe_thumb_do(DupeWindow *dw)
2075 if (!dw->thumb_loader || !dw->thumb_item) return;
2076 di = dw->thumb_item;
2078 if (di->pixbuf) g_object_unref(di->pixbuf);
2079 di->pixbuf = thumb_loader_get_pixbuf(dw->thumb_loader);
2081 dupe_listview_set_thumb(dw, di, NULL);
2084 static void dupe_thumb_error_cb(ThumbLoader *tl, gpointer data)
2086 DupeWindow *dw = data;
2089 dupe_thumb_step(dw);
2092 static void dupe_thumb_done_cb(ThumbLoader *tl, gpointer data)
2094 DupeWindow *dw = data;
2097 dupe_thumb_step(dw);
2100 static void dupe_thumb_step(DupeWindow *dw)
2102 GtkTreeModel *store;
2104 DupeItem *di = NULL;
2109 store = gtk_tree_view_get_model(GTK_TREE_VIEW(dw->listview));
2110 valid = gtk_tree_model_get_iter_first(store, &iter);
2112 while (!di && valid)
2117 gtk_tree_model_get(store, &iter, DUPE_COLUMN_POINTER, &di, DUPE_COLUMN_THUMB, &pixbuf, -1);
2118 if (pixbuf || di->pixbuf)
2120 if (!pixbuf) gtk_list_store_set(GTK_LIST_STORE(store), &iter, DUPE_COLUMN_THUMB, di->pixbuf, -1);
2124 valid = gtk_tree_model_iter_next(store, &iter);
2128 while (gtk_tree_model_iter_next(store, &iter)) length++;
2133 dw->thumb_item = NULL;
2134 thumb_loader_free(dw->thumb_loader);
2135 dw->thumb_loader = NULL;
2137 dupe_window_update_progress(dw, NULL, 0.0, FALSE);
2141 dupe_window_update_progress(dw, _("Loading thumbs..."),
2142 length == 0 ? 0.0 : (gdouble)(row) / length, FALSE);
2144 dw->thumb_item = di;
2145 thumb_loader_free(dw->thumb_loader);
2146 dw->thumb_loader = thumb_loader_new(options->thumbnails.max_width, options->thumbnails.max_height);
2148 thumb_loader_set_callbacks(dw->thumb_loader,
2150 dupe_thumb_error_cb,
2155 if (!thumb_loader_start(dw->thumb_loader, di->fd))
2157 /* error, handle it, do next */
2158 DEBUG_1("error loading thumb for %s", di->fd->path);
2160 dupe_thumb_step(dw);
2165 * ------------------------------------------------------------------
2166 * Dupe checking loop
2167 * ------------------------------------------------------------------
2170 static void dupe_check_stop(DupeWindow *dw)
2172 if (dw->idle_id > 0)
2174 g_source_remove(dw->idle_id);
2180 while (dw->thread_count < dw->queue_count) // Wait for the queue to empty
2182 dupe_window_update_progress(dw, NULL, 0.0, FALSE);
2183 widget_set_cursor(dw->listview, -1);
2186 g_list_free(dw->search_matches);
2187 dw->search_matches = NULL;
2189 if (dw->idle_id || dw->img_loader || dw->thumb_loader)
2191 if (dw->idle_id > 0)
2193 g_source_remove(dw->idle_id);
2196 dupe_window_update_progress(dw, NULL, 0.0, FALSE);
2197 widget_set_cursor(dw->listview, -1);
2200 if (dw->add_files_queue_id)
2202 g_source_remove(dw->add_files_queue_id);
2203 dw->add_files_queue_id = 0;
2204 dupe_destroy_list_cache(dw);
2205 gtk_widget_set_sensitive(dw->controls_box, TRUE);
2206 if (g_list_length(dw->add_files_queue) > 0)
2208 filelist_free(dw->add_files_queue);
2210 dw->add_files_queue = NULL;
2211 dupe_window_update_progress(dw, NULL, 0.0, FALSE);
2212 widget_set_cursor(dw->listview, -1);
2215 thumb_loader_free(dw->thumb_loader);
2216 dw->thumb_loader = NULL;
2218 image_loader_free(dw->img_loader);
2219 dw->img_loader = NULL;
2222 static void dupe_check_stop_cb(GtkWidget *widget, gpointer data)
2224 DupeWindow *dw = data;
2226 dupe_check_stop(dw);
2229 static void dupe_loader_done_cb(ImageLoader *il, gpointer data)
2231 DupeWindow *dw = data;
2234 pixbuf = image_loader_get_pixbuf(il);
2236 if (dw->setup_point)
2238 DupeItem *di = dw->setup_point->data;
2242 di->simd = image_sim_new_from_pixbuf(pixbuf);
2246 image_sim_fill_data(di->simd, pixbuf);
2249 if (di->width == 0 && di->height == 0)
2251 di->width = gdk_pixbuf_get_width(pixbuf);
2252 di->height = gdk_pixbuf_get_height(pixbuf);
2254 if (options->thumbnails.enable_caching)
2256 dupe_item_write_cache(di);
2259 image_sim_alternate_processing(di->simd);
2262 image_loader_free(dw->img_loader);
2263 dw->img_loader = NULL;
2265 dw->idle_id = g_idle_add(dupe_check_cb, dw);
2268 static void dupe_setup_reset(DupeWindow *dw)
2270 dw->setup_point = NULL;
2272 dw->setup_time = msec_time();
2273 dw->setup_time_count = 0;
2276 static GList *dupe_setup_point_step(DupeWindow *dw, GList *p)
2278 if (!p) return NULL;
2280 if (p->next) return p->next;
2282 if (dw->second_set && g_list_first(p) == dw->list) return dw->second_list;
2288 * @brief Generates the sumcheck or dimensions
2289 * @param list Set1 or set2
2290 * @returns TRUE/FALSE = not completed/completed
2292 * Ensures that the DIs contain the MD5SUM or dimensions for all items in
2293 * the list. One item at a time. Re-enters if not completed.
2295 static gboolean create_checksums_dimensions(DupeWindow *dw, GList *list)
2297 if ((dw->match_mask & DUPE_MATCH_SUM) ||
2298 (dw->match_mask & DUPE_MATCH_NAME_CONTENT) ||
2299 (dw->match_mask & DUPE_MATCH_NAME_CI_CONTENT))
2302 if (!dw->setup_point) dw->setup_point = list; // setup_point clear on 1st entry
2304 while (dw->setup_point)
2306 DupeItem *di = dw->setup_point->data;
2308 dw->setup_point = dupe_setup_point_step(dw, dw->setup_point);
2313 dupe_window_update_progress(dw, _("Reading checksums..."),
2314 dw->setup_count == 0 ? 0.0 : (gdouble)(dw->setup_n - 1) / dw->setup_count, FALSE);
2316 if (options->thumbnails.enable_caching)
2318 dupe_item_read_cache(di);
2325 di->md5sum = md5_text_from_file_utf8(di->fd->path, "");
2326 if (options->thumbnails.enable_caching)
2328 dupe_item_write_cache(di);
2333 dupe_setup_reset(dw);
2336 if ((dw->match_mask & DUPE_MATCH_DIM) )
2338 /* Dimensions only */
2339 if (!dw->setup_point) dw->setup_point = list;
2341 while (dw->setup_point)
2343 DupeItem *di = dw->setup_point->data;
2345 dw->setup_point = dupe_setup_point_step(dw, dw->setup_point);
2347 if (di->width == 0 && di->height == 0)
2349 dupe_window_update_progress(dw, _("Reading dimensions..."),
2350 dw->setup_count == 0 ? 0.0 : (gdouble)(dw->setup_n - 1) / dw->setup_count, FALSE);
2352 if (options->thumbnails.enable_caching)
2354 dupe_item_read_cache(di);
2355 if (di->width != 0 || di->height != 0)
2361 image_load_dimensions(di->fd, &di->width, &di->height);
2362 di->dimensions = (di->width << 16) + di->height;
2363 if (options->thumbnails.enable_caching)
2365 dupe_item_write_cache(di);
2370 dupe_setup_reset(dw);
2377 * @brief Compare func. for sorting search matches
2378 * @param a #DupeSearchMatch
2379 * @param b #DupeSearchMatch
2382 * Used only for similarity checks\n
2383 * Sorts search matches on order they were inserted into the pool queue
2385 static gint sort_func(gconstpointer a, gconstpointer b)
2387 return (((DupeSearchMatch *)a)->index - ((DupeSearchMatch *)b)->index);
2391 * @brief Check set 1 (and set 2) for matches
2392 * @param data DupeWindow
2393 * @returns TRUE/FALSE = not completed/completed
2395 * Initiated from start, loader done and item remove
2397 * On first entry generates di->MD5SUM, di->dimensions and sim data,
2398 * and updates the cache.
2400 static gboolean dupe_check_cb(gpointer data)
2402 DupeWindow *dw = data;
2403 DupeSearchMatch *search_match_list_item;
2410 if (!dw->setup_done) /* Clear on 1st entry */
2414 if (create_checksums_dimensions(dw, dw->list))
2419 if (dw->second_list)
2421 if (create_checksums_dimensions(dw, dw->second_list))
2426 if ((dw->match_mask & DUPE_MATCH_SIM_HIGH ||
2427 dw->match_mask & DUPE_MATCH_SIM_MED ||
2428 dw->match_mask & DUPE_MATCH_SIM_LOW ||
2429 dw->match_mask & DUPE_MATCH_SIM_CUSTOM) &&
2430 !(dw->setup_mask & DUPE_MATCH_SIM_MED) )
2432 /* Similarity only */
2433 if (!dw->setup_point) dw->setup_point = dw->list;
2435 while (dw->setup_point)
2437 DupeItem *di = dw->setup_point->data;
2441 dupe_window_update_progress(dw, _("Reading similarity data..."),
2442 dw->setup_count == 0 ? 0.0 : (gdouble)dw->setup_n / dw->setup_count, FALSE);
2444 if (options->thumbnails.enable_caching)
2446 dupe_item_read_cache(di);
2447 if (cache_sim_data_filled(di->simd))
2449 image_sim_alternate_processing(di->simd);
2454 dw->img_loader = image_loader_new(di->fd);
2455 image_loader_set_buffer_size(dw->img_loader, 8);
2456 g_signal_connect(G_OBJECT(dw->img_loader), "error", (GCallback)dupe_loader_done_cb, dw);
2457 g_signal_connect(G_OBJECT(dw->img_loader), "done", (GCallback)dupe_loader_done_cb, dw);
2459 if (!image_loader_start(dw->img_loader))
2461 image_sim_free(di->simd);
2462 di->simd = image_sim_new();
2463 image_loader_free(dw->img_loader);
2464 dw->img_loader = NULL;
2471 dw->setup_point = dupe_setup_point_step(dw, dw->setup_point);
2474 dw->setup_mask |= DUPE_MATCH_SIM_MED;
2475 dupe_setup_reset(dw);
2478 /* End of setup not done */
2479 dupe_window_update_progress(dw, _("Comparing..."), 0.0, FALSE);
2480 dw->setup_done = TRUE;
2481 dupe_setup_reset(dw);
2482 dw->setup_count = g_list_length(dw->list);
2485 /* Setup done - dw->working set to NULL below
2486 * Set before 1st entry: dw->working = g_list_last(dw->list)
2487 * Set before 1st entry: dw->setup_count = g_list_length(dw->list)
2491 /* Similarity check threads may still be running */
2492 if (dw->setup_count > 0 && (dw->match_mask == DUPE_MATCH_SIM_HIGH ||
2493 dw->match_mask == DUPE_MATCH_SIM_MED ||
2494 dw->match_mask == DUPE_MATCH_SIM_LOW ||
2495 dw->match_mask == DUPE_MATCH_SIM_CUSTOM))
2497 if( dw->thread_count < dw->queue_count)
2499 dupe_window_update_progress(dw, _("Comparing..."), 0.0, FALSE);
2504 if (dw->search_matches_sorted == NULL)
2506 dw->search_matches_sorted = g_list_sort(dw->search_matches, sort_func);
2507 dupe_setup_reset(dw);
2510 while (dw->search_matches_sorted)
2513 dupe_window_update_progress(dw, _("Sorting..."), 0.0, FALSE);
2514 search_match_list_item = dw->search_matches_sorted->data;
2516 if (!dupe_match_link_exists(search_match_list_item->a, search_match_list_item->b))
2518 dupe_match_link(search_match_list_item->a, search_match_list_item->b, search_match_list_item->rank);
2521 dw->search_matches_sorted = dw->search_matches_sorted->next;
2523 if (dw->search_matches_sorted != NULL)
2528 g_list_free(dw->search_matches);
2529 dw->search_matches = NULL;
2530 g_list_free(dw->search_matches_sorted);
2531 dw->search_matches_sorted = NULL;
2532 dw->setup_count = 0;
2536 if (dw->setup_count > 0)
2538 dw->setup_count = 0;
2539 dupe_window_update_progress(dw, _("Sorting..."), 1.0, TRUE);
2545 dupe_window_update_progress(dw, NULL, 0.0, FALSE);
2547 dupe_match_rank(dw);
2548 dupe_window_update_count(dw, FALSE);
2550 dupe_listview_populate(dw);
2553 if (dw->show_thumbs) dupe_thumb_step(dw);
2555 widget_set_cursor(dw->listview, -1);
2561 /* Setup done - working */
2562 if (dw->match_mask == DUPE_MATCH_SIM_HIGH ||
2563 dw->match_mask == DUPE_MATCH_SIM_MED ||
2564 dw->match_mask == DUPE_MATCH_SIM_LOW ||
2565 dw->match_mask == DUPE_MATCH_SIM_CUSTOM)
2567 /* This is the similarity comparison */
2568 dupe_list_check_match(dw, (DupeItem *)dw->working->data, dw->working);
2569 dupe_window_update_progress(dw, _("Queuing..."), dw->setup_count == 0 ? 0.0 : (gdouble) dw->setup_n / dw->setup_count, FALSE);
2573 dw->working = dw->working->prev; /* Is NULL when complete */
2577 /* This is the comparison for all other parameters.
2578 * dupe_array_check() processes the entire list in one go
2581 dupe_window_update_progress(dw, _("Comparing..."), 0.0, FALSE);
2582 dupe_array_check(dw);
2588 static void dupe_check_start(DupeWindow *dw)
2590 dw->setup_done = FALSE;
2592 dw->setup_count = g_list_length(dw->list);
2593 if (dw->second_set) dw->setup_count += g_list_length(dw->second_list);
2596 dupe_setup_reset(dw);
2598 dw->working = g_list_last(dw->list);
2600 dupe_window_update_count(dw, TRUE);
2601 widget_set_cursor(dw->listview, GDK_WATCH);
2602 dw->queue_count = 0;
2603 dw->thread_count = 0;
2604 dw->search_matches_sorted = NULL;
2607 if (dw->idle_id) return;
2609 dw->idle_id = g_idle_add(dupe_check_cb, dw);
2612 static gboolean dupe_check_start_cb(gpointer data)
2614 DupeWindow *dw = data;
2616 dupe_check_start(dw);
2622 * ------------------------------------------------------------------
2623 * Item addition, removal
2624 * ------------------------------------------------------------------
2627 static void dupe_item_remove(DupeWindow *dw, DupeItem *di)
2631 /* handle things that may be in progress... */
2632 if (dw->working && dw->working->data == di)
2634 dw->working = dw->working->prev;
2636 if (dw->thumb_loader && dw->thumb_item == di)
2638 dupe_thumb_step(dw);
2640 if (dw->setup_point && dw->setup_point->data == di)
2642 dw->setup_point = dupe_setup_point_step(dw, dw->setup_point);
2645 image_loader_free(dw->img_loader);
2646 dw->img_loader = NULL;
2647 dw->idle_id = g_idle_add(dupe_check_cb, dw);
2651 if (di->group && dw->dupes)
2653 /* is a dupe, must remove from group/reset children if a parent */
2656 parent = dupe_match_find_parent(dw, di);
2659 if (g_list_length(parent->group) < 2)
2663 child = dupe_match_highest_rank(parent);
2664 dupe_match_link_clear(child, TRUE);
2665 dupe_listview_remove(dw, child);
2667 dupe_match_link_clear(parent, TRUE);
2668 dupe_listview_remove(dw, parent);
2669 dw->dupes = g_list_remove(dw->dupes, parent);
2673 DupeItem *new_parent;
2676 dm = parent->group->data;
2677 new_parent = dm->di;
2678 dupe_match_reparent(dw, parent, new_parent);
2679 dupe_listview_remove(dw, parent);
2684 if (g_list_length(parent->group) < 2)
2686 dupe_match_link_clear(parent, TRUE);
2687 dupe_listview_remove(dw, parent);
2688 dw->dupes = g_list_remove(dw->dupes, parent);
2690 dupe_match_link_clear(di, TRUE);
2691 dupe_listview_remove(dw, di);
2696 /* not a dupe, or not sorted yet, simply reset */
2697 dupe_match_link_clear(di, TRUE);
2700 if (dw->second_list && g_list_find(dw->second_list, di))
2702 dupe_second_remove(dw, di);
2706 dw->list = g_list_remove(dw->list, di);
2710 dupe_window_update_count(dw, FALSE);
2713 static gboolean dupe_item_remove_by_path(DupeWindow *dw, const gchar *path)
2717 di = dupe_item_find_path(dw, path);
2718 if (!di) return FALSE;
2720 dupe_item_remove(dw, di);
2725 static gboolean dupe_files_add_queue_cb(gpointer data)
2727 DupeItem *di = NULL;
2728 DupeWindow *dw = data;
2730 GList *queue = dw->add_files_queue;
2732 gtk_progress_bar_pulse(GTK_PROGRESS_BAR(dw->extra_label));
2736 dw->add_files_queue_id = 0;
2737 dupe_destroy_list_cache(dw);
2738 g_idle_add(dupe_check_start_cb, dw);
2739 gtk_widget_set_sensitive(dw->controls_box, TRUE);
2746 if (isfile(fd->path))
2748 di = dupe_item_new(fd);
2750 else if (isdir(fd->path))
2753 dw->add_files_queue = g_list_remove(dw->add_files_queue, g_list_first(dw->add_files_queue)->data);
2755 if (filelist_read(fd, &f, &d))
2757 f = filelist_filter(f, FALSE);
2758 d = filelist_filter(d, TRUE);
2760 dw->add_files_queue = g_list_concat(f, dw->add_files_queue);
2761 dw->add_files_queue = g_list_concat(d, dw->add_files_queue);
2766 /* Not a file and not a dir */
2767 dw->add_files_queue = g_list_remove(dw->add_files_queue, g_list_first(dw->add_files_queue)->data);
2773 /* A dir was found. Process the contents on next entry */
2777 dw->add_files_queue = g_list_remove(dw->add_files_queue, g_list_first(dw->add_files_queue)->data);
2779 dupe_item_read_cache(di);
2781 /* Ensure images in the lists have unique FileDatas */
2782 if (!dupe_insert_in_list_cache(dw, di->fd))
2788 if (dw->second_drop)
2790 dupe_second_add(dw, di);
2794 dw->list = g_list_prepend(dw->list, di);
2797 if (dw->add_files_queue != NULL)
2803 dw->add_files_queue_id = 0;
2804 dupe_destroy_list_cache(dw);
2805 g_idle_add(dupe_check_start_cb, dw);
2806 gtk_widget_set_sensitive(dw->controls_box, TRUE);
2811 static void dupe_files_add(DupeWindow *dw, CollectionData *collection, CollectInfo *info,
2812 FileData *fd, gboolean recurse)
2814 DupeItem *di = NULL;
2818 di = dupe_item_new(info->fd);
2822 if (isfile(fd->path) && !g_file_test(fd->path, G_FILE_TEST_IS_SYMLINK))
2824 di = dupe_item_new(fd);
2826 else if (isdir(fd->path) && recurse)
2829 if (filelist_read(fd, &f, &d))
2833 f = filelist_filter(f, FALSE);
2834 d = filelist_filter(d, TRUE);
2839 dupe_files_add(dw, NULL, NULL, (FileData *)work->data, TRUE);
2846 dupe_files_add(dw, NULL, NULL, (FileData *)work->data, TRUE);
2856 dupe_item_read_cache(di);
2858 /* Ensure images in the lists have unique FileDatas */
2861 work = g_list_first(dw->list);
2864 di_list = work->data;
2865 if (di_list->fd == di->fd)
2875 if (dw->second_list)
2877 work = g_list_first(dw->second_list);
2880 di_list = work->data;
2881 if (di_list->fd == di->fd)
2892 if (dw->second_drop)
2894 dupe_second_add(dw, di);
2898 dw->list = g_list_prepend(dw->list, di);
2902 static void dupe_init_list_cache(DupeWindow *dw)
2904 dw->list_cache = g_hash_table_new(g_direct_hash, g_direct_equal);
2905 dw->second_list_cache = g_hash_table_new(g_direct_hash, g_direct_equal);
2907 for (GList *i = dw->list; i != NULL; i = i->next)
2909 DupeItem *di = i->data;
2911 g_hash_table_add(dw->list_cache, di->fd);
2914 for (GList *i = dw->second_list; i != NULL; i = i->next)
2916 DupeItem *di = i->data;
2918 g_hash_table_add(dw->second_list_cache, di->fd);
2922 static void dupe_destroy_list_cache(DupeWindow *dw)
2924 g_hash_table_destroy(dw->list_cache);
2925 g_hash_table_destroy(dw->second_list_cache);
2929 * @brief Return true if the fd was not in the cache
2936 static gboolean dupe_insert_in_list_cache(DupeWindow *dw, FileData *fd)
2939 dw->second_drop ? dw->second_list_cache : dw->list_cache;
2940 /* We do this as a lookup + add as we don't want to overwrite
2941 items as that would leak the old value. */
2942 if (g_hash_table_lookup(table, fd) != NULL)
2944 return g_hash_table_add(table, fd);
2947 void dupe_window_add_collection(DupeWindow *dw, CollectionData *collection)
2951 info = collection_get_first(collection);
2954 dupe_files_add(dw, collection, info, NULL, FALSE);
2955 info = collection_next_by_info(collection, info);
2958 dupe_check_start(dw);
2961 void dupe_window_add_files(DupeWindow *dw, GList *list, gboolean recurse)
2968 FileData *fd = work->data;
2970 if (isdir(fd->path) && !recurse)
2974 if (filelist_read(fd, &f, &d))
2981 /* Add only the files, ignore the dirs when no recurse */
2982 dw->add_files_queue = g_list_prepend(dw->add_files_queue, work_file->data);
2983 work_file = work_file->next;
2991 dw->add_files_queue = g_list_prepend(dw->add_files_queue, fd);
2994 if (dw->add_files_queue_id == 0)
2996 gtk_progress_bar_pulse(GTK_PROGRESS_BAR(dw->extra_label));
2997 gtk_progress_bar_set_pulse_step(GTK_PROGRESS_BAR(dw->extra_label), DUPE_PROGRESS_PULSE_STEP);
2998 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(dw->extra_label), _("Loading file list"));
3000 dupe_init_list_cache(dw);
3001 dw->add_files_queue_id = g_idle_add(dupe_files_add_queue_cb, dw);
3002 gtk_widget_set_sensitive(dw->controls_box, FALSE);
3006 static void dupe_item_update(DupeWindow *dw, DupeItem *di)
3008 if ( (dw->match_mask & DUPE_MATCH_NAME) || (dw->match_mask & DUPE_MATCH_PATH || (dw->match_mask & DUPE_MATCH_NAME_CI)) )
3010 /* only effects matches on name or path */
3012 FileData *fd = file_data_ref(di->fd);
3015 second = di->second;
3016 dupe_item_remove(dw, di);
3018 dw->second_drop = second;
3019 dupe_files_add(dw, NULL, NULL, fd, FALSE);
3020 dw->second_drop = FALSE;
3022 file_data_unref(fd);
3024 dupe_check_start(dw);
3028 GtkListStore *store;
3031 /* update the listview(s) */
3033 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dw->listview)));
3034 row = dupe_listview_find_item(store, di, &iter);
3037 gtk_list_store_set(store, &iter,
3038 DUPE_COLUMN_NAME, di->fd->name,
3039 DUPE_COLUMN_PATH, di->fd->path, -1);
3042 if (dw->second_listview)
3044 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dw->second_listview)));
3045 row = dupe_listview_find_item(store, di, &iter);
3048 gtk_list_store_set(store, &iter, 1, di->fd->path, -1);
3055 static void dupe_item_update_fd_in_list(DupeWindow *dw, FileData *fd, GList *work)
3059 DupeItem *di = work->data;
3062 dupe_item_update(dw, di);
3068 static void dupe_item_update_fd(DupeWindow *dw, FileData *fd)
3070 dupe_item_update_fd_in_list(dw, fd, dw->list);
3071 if (dw->second_set) dupe_item_update_fd_in_list(dw, fd, dw->second_list);
3076 * ------------------------------------------------------------------
3078 * ------------------------------------------------------------------
3081 static GtkWidget *dupe_display_label(GtkWidget *vbox, const gchar *description, const gchar *text)
3086 hbox = gtk_hbox_new(FALSE, 10);
3088 label = gtk_label_new(description);
3089 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
3090 gtk_widget_show(label);
3092 label = gtk_label_new(text);
3093 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
3094 gtk_widget_show(label);
3096 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
3097 gtk_widget_show(hbox);
3102 static void dupe_display_stats(DupeWindow *dw, DupeItem *di)
3109 gd = file_util_gen_dlg("Image thumbprint debug info", "thumbprint",
3112 generic_dialog_add_button(gd, GTK_STOCK_CLOSE, NULL, NULL, TRUE);
3114 dupe_display_label(gd->vbox, "name:", di->fd->name);
3115 buf = text_from_size(di->fd->size);
3116 dupe_display_label(gd->vbox, "size:", buf);
3118 dupe_display_label(gd->vbox, "date:", text_from_time(di->fd->date));
3119 buf = g_strdup_printf("%d x %d", di->width, di->height);
3120 dupe_display_label(gd->vbox, "dimensions:", buf);
3122 dupe_display_label(gd->vbox, "md5sum:", (di->md5sum) ? di->md5sum : "not generated");
3124 dupe_display_label(gd->vbox, "thumbprint:", (di->simd) ? "" : "not generated");
3135 pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, 32, 32);
3136 rs = gdk_pixbuf_get_rowstride(pixbuf);
3137 d_pix = gdk_pixbuf_get_pixels(pixbuf);
3139 for (y = 0; y < 32; y++)
3141 dp = d_pix + (y * rs);
3143 for (x = 0; x < 32; x++)
3145 *(dp++) = di->simd->avg_r[sp + x];
3146 *(dp++) = di->simd->avg_g[sp + x];
3147 *(dp++) = di->simd->avg_b[sp + x];
3151 image = gtk_image_new_from_pixbuf(pixbuf);
3152 gtk_box_pack_start(GTK_BOX(gd->vbox), image, FALSE, FALSE, 0);
3153 gtk_widget_show(image);
3155 g_object_unref(pixbuf);
3158 gtk_widget_show(gd->dialog);
3161 static void dupe_window_recompare(DupeWindow *dw)
3163 GtkListStore *store;
3165 dupe_check_stop(dw);
3167 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dw->listview)));
3168 gtk_list_store_clear(store);
3170 g_list_free(dw->dupes);
3173 dupe_match_reset_list(dw->list);
3174 dupe_match_reset_list(dw->second_list);
3177 dupe_check_start(dw);
3180 static void dupe_menu_view(DupeWindow *dw, DupeItem *di, GtkWidget *listview, gint new_window)
3184 if (di->collection && collection_info_valid(di->collection, di->info))
3188 view_window_new_from_collection(di->collection, di->info);
3192 layout_image_set_collection(NULL, di->collection, di->info);
3201 list = dupe_listview_get_selection(dw, listview);
3202 view_window_new_from_list(list);
3203 filelist_free(list);
3207 layout_set_fd(NULL, di->fd);
3212 static void dupe_window_remove_selection(DupeWindow *dw, GtkWidget *listview)
3214 GtkTreeSelection *selection;
3215 GtkTreeModel *store;
3221 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(listview));
3222 slist = gtk_tree_selection_get_selected_rows(selection, &store);
3226 GtkTreePath *tpath = work->data;
3227 DupeItem *di = NULL;
3229 gtk_tree_model_get_iter(store, &iter, tpath);
3230 gtk_tree_model_get(store, &iter, DUPE_COLUMN_POINTER, &di, -1);
3231 if (di) list = g_list_prepend(list, di);
3234 g_list_foreach(slist, (GFunc)tree_path_free_wrapper, NULL);
3237 dw->color_frozen = TRUE;
3245 dupe_item_remove(dw, di);
3247 dw->color_frozen = FALSE;
3251 dupe_listview_realign_colors(dw);
3254 static void dupe_window_edit_selected(DupeWindow *dw, const gchar *key)
3256 file_util_start_editor_from_filelist(key, dupe_listview_get_selection(dw, dw->listview), NULL, dw->window);
3259 static void dupe_window_collection_from_selection(DupeWindow *dw)
3264 list = dupe_listview_get_selection(dw, dw->listview);
3265 w = collection_window_new(NULL);
3266 collection_table_add_filelist(w->table, list);
3267 filelist_free(list);
3270 static void dupe_window_append_file_list(DupeWindow *dw, gint on_second)
3274 dw->second_drop = (dw->second_set && on_second);
3276 list = layout_list(NULL);
3277 dupe_window_add_files(dw, list, FALSE);
3278 filelist_free(list);
3282 *-------------------------------------------------------------------
3283 * main pop-up menu callbacks
3284 *-------------------------------------------------------------------
3287 static void dupe_menu_view_cb(GtkWidget *widget, gpointer data)
3289 DupeWindow *dw = data;
3291 if (dw->click_item) dupe_menu_view(dw, dw->click_item, dw->listview, FALSE);
3294 static void dupe_menu_viewnew_cb(GtkWidget *widget, gpointer data)
3296 DupeWindow *dw = data;
3298 if (dw->click_item) dupe_menu_view(dw, dw->click_item, dw->listview, TRUE);
3301 static void dupe_menu_select_all_cb(GtkWidget *widget, gpointer data)
3303 DupeWindow *dw = data;
3304 GtkTreeSelection *selection;
3306 options->duplicates_select_type = DUPE_SELECT_NONE;
3307 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dw->listview));
3308 gtk_tree_selection_select_all(selection);
3311 static void dupe_menu_select_none_cb(GtkWidget *widget, gpointer data)
3313 DupeWindow *dw = data;
3314 GtkTreeSelection *selection;
3316 options->duplicates_select_type = DUPE_SELECT_NONE;
3317 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dw->listview));
3318 gtk_tree_selection_unselect_all(selection);
3321 static void dupe_menu_select_dupes_set1_cb(GtkWidget *widget, gpointer data)
3323 DupeWindow *dw = data;
3325 options->duplicates_select_type = DUPE_SELECT_GROUP1;
3326 dupe_listview_select_dupes(dw, DUPE_SELECT_GROUP1);
3329 static void dupe_menu_select_dupes_set2_cb(GtkWidget *widget, gpointer data)
3331 DupeWindow *dw = data;
3333 options->duplicates_select_type = DUPE_SELECT_GROUP2;
3334 dupe_listview_select_dupes(dw, DUPE_SELECT_GROUP2);
3337 static void dupe_menu_edit_cb(GtkWidget *widget, gpointer data)
3340 const gchar *key = data;
3342 dw = submenu_item_get_data(widget);
3345 dupe_window_edit_selected(dw, key);
3348 static void dupe_menu_print_cb(GtkWidget *widget, gpointer data)
3350 DupeWindow *dw = data;
3353 fd = (dw->click_item) ? dw->click_item->fd : NULL;
3355 print_window_new(fd,
3356 dupe_listview_get_selection(dw, dw->listview),
3357 dupe_listview_get_filelist(dw, dw->listview), dw->window);
3360 static void dupe_menu_copy_cb(GtkWidget *widget, gpointer data)
3362 DupeWindow *dw = data;
3364 file_util_copy(NULL, dupe_listview_get_selection(dw, dw->listview), NULL, dw->window);
3367 static void dupe_menu_move_cb(GtkWidget *widget, gpointer data)
3369 DupeWindow *dw = data;
3371 file_util_move(NULL, dupe_listview_get_selection(dw, dw->listview), NULL, dw->window);
3374 static void dupe_menu_rename_cb(GtkWidget *widget, gpointer data)
3376 DupeWindow *dw = data;
3378 file_util_rename(NULL, dupe_listview_get_selection(dw, dw->listview), dw->window);
3381 static void dupe_menu_delete_cb(GtkWidget *widget, gpointer data)
3383 DupeWindow *dw = data;
3385 options->file_ops.safe_delete_enable = FALSE;
3386 file_util_delete_notify_done(NULL, dupe_listview_get_selection(dw, dw->listview), dw->window, delete_finished_cb, dw);
3389 static void dupe_menu_move_to_trash_cb(GtkWidget *widget, gpointer data)
3391 DupeWindow *dw = data;
3393 options->file_ops.safe_delete_enable = TRUE;
3394 file_util_delete_notify_done(NULL, dupe_listview_get_selection(dw, dw->listview), dw->window, delete_finished_cb, dw);
3397 static void dupe_menu_copy_path_cb(GtkWidget *widget, gpointer data)
3399 DupeWindow *dw = data;
3401 file_util_copy_path_list_to_clipboard(dupe_listview_get_selection(dw, dw->listview), TRUE);
3404 static void dupe_menu_copy_path_unquoted_cb(GtkWidget *widget, gpointer data)
3406 DupeWindow *dw = data;
3408 file_util_copy_path_list_to_clipboard(dupe_listview_get_selection(dw, dw->listview), FALSE);
3411 static void dupe_menu_remove_cb(GtkWidget *widget, gpointer data)
3413 DupeWindow *dw = data;
3415 dupe_window_remove_selection(dw, dw->listview);
3418 static void dupe_menu_clear_cb(GtkWidget *widget, gpointer data)
3420 DupeWindow *dw = data;
3422 dupe_window_clear(dw);
3425 static void dupe_menu_close_cb(GtkWidget *widget, gpointer data)
3427 DupeWindow *dw = data;
3429 dupe_window_close(dw);
3432 static void dupe_menu_popup_destroy_cb(GtkWidget *widget, gpointer data)
3434 GList *editmenu_fd_list = data;
3436 filelist_free(editmenu_fd_list);
3439 static GList *dupe_window_get_fd_list(DupeWindow *dw)
3443 if (gtk_widget_has_focus(dw->second_listview))
3445 list = dupe_listview_get_selection(dw, dw->second_listview);
3449 list = dupe_listview_get_selection(dw, dw->listview);
3456 * @brief Add file selection list to a collection
3458 * @param[in] data Index to the collection list menu item selected, or -1 for new collection
3462 static void dupe_pop_menu_collections_cb(GtkWidget *widget, gpointer data)
3465 GList *selection_list;
3467 dw = submenu_item_get_data(widget);
3468 selection_list = dupe_listview_get_selection(dw, dw->listview);
3469 pop_menu_collections(selection_list, data);
3471 filelist_free(selection_list);
3474 static GtkWidget *dupe_menu_popup_main(DupeWindow *dw, DupeItem *di)
3479 GList *editmenu_fd_list;
3481 on_row = (di != NULL);
3483 menu = popup_menu_short_lived();
3485 menu_item_add_sensitive(menu, _("_View"), on_row,
3486 G_CALLBACK(dupe_menu_view_cb), dw);
3487 menu_item_add_stock_sensitive(menu, _("View in _new window"), GTK_STOCK_NEW, on_row,
3488 G_CALLBACK(dupe_menu_viewnew_cb), dw);
3489 menu_item_add_divider(menu);
3490 menu_item_add_sensitive(menu, _("Select all"), (dw->dupes != NULL),
3491 G_CALLBACK(dupe_menu_select_all_cb), dw);
3492 menu_item_add_sensitive(menu, _("Select none"), (dw->dupes != NULL),
3493 G_CALLBACK(dupe_menu_select_none_cb), dw);
3494 menu_item_add_sensitive(menu, _("Select group _1 duplicates"), (dw->dupes != NULL),
3495 G_CALLBACK(dupe_menu_select_dupes_set1_cb), dw);
3496 menu_item_add_sensitive(menu, _("Select group _2 duplicates"), (dw->dupes != NULL),
3497 G_CALLBACK(dupe_menu_select_dupes_set2_cb), dw);
3498 menu_item_add_divider(menu);
3500 submenu_add_export(menu, &item, G_CALLBACK(dupe_pop_menu_export_cb), dw);
3501 gtk_widget_set_sensitive(item, on_row);
3502 menu_item_add_divider(menu);
3504 editmenu_fd_list = dupe_window_get_fd_list(dw);
3505 g_signal_connect(G_OBJECT(menu), "destroy",
3506 G_CALLBACK(dupe_menu_popup_destroy_cb), editmenu_fd_list);
3507 submenu_add_edit(menu, &item, G_CALLBACK(dupe_menu_edit_cb), dw, editmenu_fd_list);
3508 if (!on_row) gtk_widget_set_sensitive(item, FALSE);
3510 submenu_add_collections(menu, &item,
3511 G_CALLBACK(dupe_pop_menu_collections_cb), dw);
3512 gtk_widget_set_sensitive(item, on_row);
3514 menu_item_add_stock_sensitive(menu, _("Print..."), GTK_STOCK_PRINT, on_row,
3515 G_CALLBACK(dupe_menu_print_cb), dw);
3516 menu_item_add_divider(menu);
3517 menu_item_add_stock_sensitive(menu, _("_Copy..."), GTK_STOCK_COPY, on_row,
3518 G_CALLBACK(dupe_menu_copy_cb), dw);
3519 menu_item_add_sensitive(menu, _("_Move..."), on_row,
3520 G_CALLBACK(dupe_menu_move_cb), dw);
3521 menu_item_add_sensitive(menu, _("_Rename..."), on_row,
3522 G_CALLBACK(dupe_menu_rename_cb), dw);
3523 menu_item_add_sensitive(menu, _("_Copy path"), on_row,
3524 G_CALLBACK(dupe_menu_copy_path_cb), dw);
3525 menu_item_add_sensitive(menu, _("_Copy path unquoted"), on_row,
3526 G_CALLBACK(dupe_menu_copy_path_unquoted_cb), dw);
3528 menu_item_add_divider(menu);
3529 menu_item_add_stock_sensitive(menu,
3530 options->file_ops.confirm_move_to_trash ? _("Move to Trash...") :
3531 _("Move to Trash"), PIXBUF_INLINE_ICON_TRASH, on_row,
3532 G_CALLBACK(dupe_menu_move_to_trash_cb), dw);
3533 menu_item_add_stock_sensitive(menu,
3534 options->file_ops.confirm_delete ? _("_Delete...") :
3535 _("_Delete"), GTK_STOCK_DELETE, on_row,
3536 G_CALLBACK(dupe_menu_delete_cb), dw);
3538 menu_item_add_divider(menu);
3539 menu_item_add_stock_sensitive(menu, _("Rem_ove"), GTK_STOCK_REMOVE, on_row,
3540 G_CALLBACK(dupe_menu_remove_cb), dw);
3541 menu_item_add_stock_sensitive(menu, _("C_lear"), GTK_STOCK_CLEAR, (dw->list != NULL),
3542 G_CALLBACK(dupe_menu_clear_cb), dw);
3543 menu_item_add_divider(menu);
3544 menu_item_add_stock(menu, _("Close _window"), GTK_STOCK_CLOSE,
3545 G_CALLBACK(dupe_menu_close_cb), dw);
3550 static gboolean dupe_listview_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
3552 DupeWindow *dw = data;
3553 GtkTreeModel *store;
3556 DupeItem *di = NULL;
3558 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget));
3560 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bevent->x, bevent->y,
3561 &tpath, NULL, NULL, NULL))
3563 gtk_tree_model_get_iter(store, &iter, tpath);
3564 gtk_tree_model_get(store, &iter, DUPE_COLUMN_POINTER, &di, -1);
3565 gtk_tree_path_free(tpath);
3568 dw->click_item = di;
3570 if (bevent->button == MOUSE_BUTTON_RIGHT)
3572 /* right click menu */
3575 if (bevent->state & GDK_CONTROL_MASK && bevent->state & GDK_SHIFT_MASK)
3577 dupe_display_stats(dw, di);
3580 if (widget == dw->listview)
3582 menu = dupe_menu_popup_main(dw, di);
3586 menu = dupe_menu_popup_second(dw, di);
3588 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, bevent->button, bevent->time);
3591 if (!di) return FALSE;
3593 if (bevent->button == MOUSE_BUTTON_LEFT &&
3594 bevent->type == GDK_2BUTTON_PRESS)
3596 dupe_menu_view(dw, di, widget, FALSE);
3599 if (bevent->button == MOUSE_BUTTON_MIDDLE) return TRUE;
3601 if (bevent->button == MOUSE_BUTTON_RIGHT)
3603 if (!dupe_listview_item_is_selected(dw, di, widget))
3605 GtkTreeSelection *selection;
3607 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
3608 gtk_tree_selection_unselect_all(selection);
3609 gtk_tree_selection_select_iter(selection, &iter);
3611 tpath = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter);
3612 gtk_tree_view_set_cursor(GTK_TREE_VIEW(widget), tpath, NULL, FALSE);
3613 gtk_tree_path_free(tpath);
3619 if (bevent->button == MOUSE_BUTTON_LEFT &&
3620 bevent->type == GDK_BUTTON_PRESS &&
3621 !(bevent->state & GDK_SHIFT_MASK ) &&
3622 !(bevent->state & GDK_CONTROL_MASK ) &&
3623 dupe_listview_item_is_selected(dw, di, widget))
3625 /* this selection handled on release_cb */
3626 gtk_widget_grab_focus(widget);
3633 static gboolean dupe_listview_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
3635 DupeWindow *dw = data;
3636 GtkTreeModel *store;
3639 DupeItem *di = NULL;
3641 if (bevent->button != MOUSE_BUTTON_LEFT && bevent->button != MOUSE_BUTTON_MIDDLE) return TRUE;
3643 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget));
3645 if ((bevent->x != 0 || bevent->y != 0) &&
3646 gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bevent->x, bevent->y,
3647 &tpath, NULL, NULL, NULL))
3649 gtk_tree_model_get_iter(store, &iter, tpath);
3650 gtk_tree_model_get(store, &iter, DUPE_COLUMN_POINTER, &di, -1);
3651 gtk_tree_path_free(tpath);
3654 if (bevent->button == MOUSE_BUTTON_MIDDLE)
3656 if (di && dw->click_item == di)
3658 GtkTreeSelection *selection;
3660 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
3661 if (dupe_listview_item_is_selected(dw, di, widget))
3663 gtk_tree_selection_unselect_iter(selection, &iter);
3667 gtk_tree_selection_select_iter(selection, &iter);
3673 if (di && dw->click_item == di &&
3674 !(bevent->state & GDK_SHIFT_MASK ) &&
3675 !(bevent->state & GDK_CONTROL_MASK ) &&
3676 dupe_listview_item_is_selected(dw, di, widget))
3678 GtkTreeSelection *selection;
3680 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
3681 gtk_tree_selection_unselect_all(selection);
3682 gtk_tree_selection_select_iter(selection, &iter);
3684 tpath = gtk_tree_model_get_path(store, &iter);
3685 gtk_tree_view_set_cursor(GTK_TREE_VIEW(widget), tpath, NULL, FALSE);
3686 gtk_tree_path_free(tpath);
3695 *-------------------------------------------------------------------
3697 *-------------------------------------------------------------------
3700 static void dupe_second_update_status(DupeWindow *dw)
3704 buf = g_strdup_printf(_("%d files (set 2)"), g_list_length(dw->second_list));
3705 gtk_label_set_text(GTK_LABEL(dw->second_status_label), buf);
3709 static void dupe_second_add(DupeWindow *dw, DupeItem *di)
3711 GtkListStore *store;
3717 dw->second_list = g_list_prepend(dw->second_list, di);
3719 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dw->second_listview)));
3720 gtk_list_store_append(store, &iter);
3721 gtk_list_store_set(store, &iter, DUPE_COLUMN_POINTER, di, 1, di->fd->path, -1);
3723 dupe_second_update_status(dw);
3726 static void dupe_second_remove(DupeWindow *dw, DupeItem *di)
3728 GtkListStore *store;
3731 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dw->second_listview)));
3732 if (dupe_listview_find_item(store, di, &iter) >= 0)
3734 tree_view_move_cursor_away(GTK_TREE_VIEW(dw->second_listview), &iter, TRUE);
3735 gtk_list_store_remove(store, &iter);
3738 dw->second_list = g_list_remove(dw->second_list, di);
3740 dupe_second_update_status(dw);
3743 static void dupe_second_clear(DupeWindow *dw)
3745 GtkListStore *store;
3747 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dw->second_listview)));
3748 gtk_list_store_clear(store);
3749 gtk_tree_view_columns_autosize(GTK_TREE_VIEW(dw->second_listview));
3751 g_list_free(dw->dupes);
3754 dupe_list_free(dw->second_list);
3755 dw->second_list = NULL;
3757 dupe_match_reset_list(dw->list);
3759 dupe_second_update_status(dw);
3762 static void dupe_second_menu_view_cb(GtkWidget *widget, gpointer data)
3764 DupeWindow *dw = data;
3766 if (dw->click_item) dupe_menu_view(dw, dw->click_item, dw->second_listview, FALSE);
3769 static void dupe_second_menu_viewnew_cb(GtkWidget *widget, gpointer data)
3771 DupeWindow *dw = data;
3773 if (dw->click_item) dupe_menu_view(dw, dw->click_item, dw->second_listview, TRUE);
3776 static void dupe_second_menu_select_all_cb(GtkWidget *widget, gpointer data)
3778 GtkTreeSelection *selection;
3779 DupeWindow *dw = data;
3781 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dw->second_listview));
3782 gtk_tree_selection_select_all(selection);
3785 static void dupe_second_menu_select_none_cb(GtkWidget *widget, gpointer data)
3787 GtkTreeSelection *selection;
3788 DupeWindow *dw = data;
3790 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dw->second_listview));
3791 gtk_tree_selection_unselect_all(selection);
3794 static void dupe_second_menu_remove_cb(GtkWidget *widget, gpointer data)
3796 DupeWindow *dw = data;
3798 dupe_window_remove_selection(dw, dw->second_listview);
3801 static void dupe_second_menu_clear_cb(GtkWidget *widget, gpointer data)
3803 DupeWindow *dw = data;
3805 dupe_second_clear(dw);
3806 dupe_window_recompare(dw);
3809 static GtkWidget *dupe_menu_popup_second(DupeWindow *dw, DupeItem *di)
3812 gboolean notempty = (dw->second_list != NULL);
3813 gboolean on_row = (di != NULL);
3815 menu = popup_menu_short_lived();
3816 menu_item_add_sensitive(menu, _("_View"), on_row,
3817 G_CALLBACK(dupe_second_menu_view_cb), dw);
3818 menu_item_add_stock_sensitive(menu, _("View in _new window"), GTK_STOCK_NEW, on_row,
3819 G_CALLBACK(dupe_second_menu_viewnew_cb), dw);
3820 menu_item_add_divider(menu);
3821 menu_item_add_sensitive(menu, _("Select all"), notempty,
3822 G_CALLBACK(dupe_second_menu_select_all_cb), dw);
3823 menu_item_add_sensitive(menu, _("Select none"), notempty,
3824 G_CALLBACK(dupe_second_menu_select_none_cb), dw);
3825 menu_item_add_divider(menu);
3826 menu_item_add_stock_sensitive(menu, _("Rem_ove"), GTK_STOCK_REMOVE, on_row,
3827 G_CALLBACK(dupe_second_menu_remove_cb), dw);
3828 menu_item_add_stock_sensitive(menu, _("C_lear"), GTK_STOCK_CLEAR, notempty,
3829 G_CALLBACK(dupe_second_menu_clear_cb), dw);
3830 menu_item_add_divider(menu);
3831 menu_item_add_stock(menu, _("Close _window"), GTK_STOCK_CLOSE,
3832 G_CALLBACK(dupe_menu_close_cb), dw);
3837 static void dupe_second_set_toggle_cb(GtkWidget *widget, gpointer data)
3839 DupeWindow *dw = data;
3841 dw->second_set = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
3845 dupe_second_update_status(dw);
3846 gtk_table_set_col_spacings(GTK_TABLE(dw->table), PREF_PAD_GAP);
3847 gtk_widget_show(dw->second_vbox);
3851 gtk_table_set_col_spacings(GTK_TABLE(dw->table), 0);
3852 gtk_widget_hide(dw->second_vbox);
3853 dupe_second_clear(dw);
3856 dupe_window_recompare(dw);
3859 static void dupe_sort_totals_toggle_cb(GtkWidget *widget, gpointer data)
3861 DupeWindow *dw = data;
3863 options->sort_totals = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
3864 dupe_window_recompare(dw);
3869 *-------------------------------------------------------------------
3871 *-------------------------------------------------------------------
3875 DUPE_MENU_COLUMN_NAME = 0,
3876 DUPE_MENU_COLUMN_MASK
3879 static void dupe_listview_show_rank(GtkWidget *listview, gboolean rank);
3881 static void dupe_menu_type_cb(GtkWidget *combo, gpointer data)
3883 DupeWindow *dw = data;
3884 GtkTreeModel *store;
3887 store = gtk_combo_box_get_model(GTK_COMBO_BOX(combo));
3888 if (!gtk_combo_box_get_active_iter(GTK_COMBO_BOX(combo), &iter)) return;
3889 gtk_tree_model_get(store, &iter, DUPE_MENU_COLUMN_MASK, &dw->match_mask, -1);
3891 options->duplicates_match = dw->match_mask;
3893 if (dw->match_mask & (DUPE_MATCH_SIM_HIGH | DUPE_MATCH_SIM_MED | DUPE_MATCH_SIM_LOW | DUPE_MATCH_SIM_CUSTOM))
3895 dupe_listview_show_rank(dw->listview, TRUE);
3899 dupe_listview_show_rank(dw->listview, FALSE);
3901 dupe_window_recompare(dw);
3904 static void dupe_menu_add_item(GtkListStore *store, const gchar *text, DupeMatchType type, DupeWindow *dw)
3908 gtk_list_store_append(store, &iter);
3909 gtk_list_store_set(store, &iter, DUPE_MENU_COLUMN_NAME, text,
3910 DUPE_MENU_COLUMN_MASK, type, -1);
3912 if (dw->match_mask == type) gtk_combo_box_set_active_iter(GTK_COMBO_BOX(dw->combo), &iter);
3915 static void dupe_menu_setup(DupeWindow *dw)
3917 GtkListStore *store;
3918 GtkCellRenderer *renderer;
3920 store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INT);
3921 dw->combo = gtk_combo_box_new_with_model(GTK_TREE_MODEL(store));
3922 g_object_unref(store);
3924 renderer = gtk_cell_renderer_text_new();
3925 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(dw->combo), renderer, TRUE);
3926 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(dw->combo), renderer,
3927 "text", DUPE_MENU_COLUMN_NAME, NULL);
3929 dupe_menu_add_item(store, _("Name"), DUPE_MATCH_NAME, dw);
3930 dupe_menu_add_item(store, _("Name case-insensitive"), DUPE_MATCH_NAME_CI, dw);
3931 dupe_menu_add_item(store, _("Size"), DUPE_MATCH_SIZE, dw);
3932 dupe_menu_add_item(store, _("Date"), DUPE_MATCH_DATE, dw);
3933 dupe_menu_add_item(store, _("Dimensions"), DUPE_MATCH_DIM, dw);
3934 dupe_menu_add_item(store, _("Checksum"), DUPE_MATCH_SUM, dw);
3935 dupe_menu_add_item(store, _("Path"), DUPE_MATCH_PATH, dw);
3936 dupe_menu_add_item(store, _("Similarity (high - 95)"), DUPE_MATCH_SIM_HIGH, dw);
3937 dupe_menu_add_item(store, _("Similarity (med. - 90)"), DUPE_MATCH_SIM_MED, dw);
3938 dupe_menu_add_item(store, _("Similarity (low - 85)"), DUPE_MATCH_SIM_LOW, dw);
3939 dupe_menu_add_item(store, _("Similarity (custom)"), DUPE_MATCH_SIM_CUSTOM, dw);
3940 dupe_menu_add_item(store, _("Name ≠content"), DUPE_MATCH_NAME_CONTENT, dw);
3941 dupe_menu_add_item(store, _("Name case-insensitive ≠content"), DUPE_MATCH_NAME_CI_CONTENT, dw);
3942 dupe_menu_add_item(store, _("Show all"), DUPE_MATCH_ALL, dw);
3944 g_signal_connect(G_OBJECT(dw->combo), "changed",
3945 G_CALLBACK(dupe_menu_type_cb), dw);
3949 *-------------------------------------------------------------------
3951 *-------------------------------------------------------------------
3954 /* this overrides the low default of a GtkCellRenderer from 100 to CELL_HEIGHT_OVERRIDE, something sane for our purposes */
3956 #define CELL_HEIGHT_OVERRIDE 512
3958 void cell_renderer_height_override(GtkCellRenderer *renderer)
3962 spec = g_object_class_find_property(G_OBJECT_GET_CLASS(G_OBJECT(renderer)), "height");
3963 if (spec && G_IS_PARAM_SPEC_INT(spec))
3965 GParamSpecInt *spec_int;
3967 spec_int = G_PARAM_SPEC_INT(spec);
3968 if (spec_int->maximum < CELL_HEIGHT_OVERRIDE) spec_int->maximum = CELL_HEIGHT_OVERRIDE;
3972 static GdkColor *dupe_listview_color_shifted(GtkWidget *widget)
3974 static GdkColor color;
3975 static GtkWidget *done = NULL;
3981 style = gtk_widget_get_style(widget);
3982 memcpy(&color, &style->base[GTK_STATE_NORMAL], sizeof(color));
3983 shift_color(&color, -1, 0);
3990 static void dupe_listview_color_cb(GtkTreeViewColumn *tree_column, GtkCellRenderer *cell,
3991 GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data)
3993 DupeWindow *dw = data;
3996 gtk_tree_model_get(tree_model, iter, DUPE_COLUMN_COLOR, &set, -1);
3997 g_object_set(G_OBJECT(cell),
3998 "cell-background-gdk", dupe_listview_color_shifted(dw->listview),
3999 "cell-background-set", set, NULL);
4002 static void dupe_listview_add_column(DupeWindow *dw, GtkWidget *listview, gint n, const gchar *title, gboolean image, gboolean right_justify)
4004 GtkTreeViewColumn *column;
4005 GtkCellRenderer *renderer;
4007 column = gtk_tree_view_column_new();
4008 gtk_tree_view_column_set_title(column, title);
4009 gtk_tree_view_column_set_min_width(column, 4);
4010 gtk_tree_view_column_set_sort_column_id(column, n);
4012 if (n != DUPE_COLUMN_RANK &&
4013 n != DUPE_COLUMN_THUMB)
4015 gtk_tree_view_column_set_resizable(column, TRUE);
4020 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_GROW_ONLY);
4021 renderer = gtk_cell_renderer_text_new();
4024 g_object_set(G_OBJECT(renderer), "xalign", 1.0, NULL);
4026 gtk_tree_view_column_pack_start(column, renderer, TRUE);
4027 gtk_tree_view_column_add_attribute(column, renderer, "text", n);
4031 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
4032 renderer = gtk_cell_renderer_pixbuf_new();
4033 cell_renderer_height_override(renderer);
4034 gtk_tree_view_column_pack_start(column, renderer, TRUE);
4035 gtk_tree_view_column_add_attribute(column, renderer, "pixbuf", n);
4038 if (listview == dw->listview)
4040 /* sets background before rendering */
4041 gtk_tree_view_column_set_cell_data_func(column, renderer, dupe_listview_color_cb, dw, NULL);
4044 gtk_tree_view_append_column(GTK_TREE_VIEW(listview), column);
4047 static void dupe_listview_set_height(GtkWidget *listview, gboolean thumb)
4049 GtkTreeViewColumn *column;
4050 GtkCellRenderer *cell;
4053 column = gtk_tree_view_get_column(GTK_TREE_VIEW(listview), DUPE_COLUMN_THUMB - 1);
4054 if (!column) return;
4056 gtk_tree_view_column_set_fixed_width(column, (thumb) ? options->thumbnails.max_width : 4);
4057 gtk_tree_view_column_set_visible(column, thumb);
4059 list = gtk_cell_layout_get_cells(GTK_CELL_LAYOUT(column));
4064 g_object_set(G_OBJECT(cell), "height", (thumb) ? options->thumbnails.max_height : -1, NULL);
4065 gtk_tree_view_columns_autosize(GTK_TREE_VIEW(listview));
4068 static void dupe_listview_show_rank(GtkWidget *listview, gboolean rank)
4070 GtkTreeViewColumn *column;
4072 column = gtk_tree_view_get_column(GTK_TREE_VIEW(listview), DUPE_COLUMN_RANK - 1);
4073 if (!column) return;
4075 gtk_tree_view_column_set_visible(column, rank);
4079 *-------------------------------------------------------------------
4081 *-------------------------------------------------------------------
4084 static void dupe_window_show_thumb_cb(GtkWidget *widget, gpointer data)
4086 DupeWindow *dw = data;
4088 dw->show_thumbs = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
4089 options->duplicates_thumbnails = dw->show_thumbs;
4091 if (dw->show_thumbs)
4093 if (!dw->working) dupe_thumb_step(dw);
4097 GtkTreeModel *store;
4101 thumb_loader_free(dw->thumb_loader);
4102 dw->thumb_loader = NULL;
4104 store = gtk_tree_view_get_model(GTK_TREE_VIEW(dw->listview));
4105 valid = gtk_tree_model_get_iter_first(store, &iter);
4109 gtk_list_store_set(GTK_LIST_STORE(store), &iter, DUPE_COLUMN_THUMB, NULL, -1);
4110 valid = gtk_tree_model_iter_next(store, &iter);
4112 dupe_window_update_progress(dw, NULL, 0.0, FALSE);
4115 dupe_listview_set_height(dw->listview, dw->show_thumbs);
4118 static void dupe_window_rotation_invariant_cb(GtkWidget *widget, gpointer data)
4120 DupeWindow *dw = data;
4122 options->rot_invariant_sim = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
4123 dupe_window_recompare(dw);
4126 static void dupe_window_custom_threshold_cb(GtkWidget *widget, gpointer data)
4128 DupeWindow *dw = data;
4129 DupeMatchType match_type;
4130 GtkTreeModel *store;
4134 options->duplicates_similarity_threshold = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));
4135 dw->match_mask = DUPE_MATCH_SIM_CUSTOM;
4137 store = gtk_combo_box_get_model(GTK_COMBO_BOX(dw->combo));
4138 valid = gtk_tree_model_get_iter_first(store, &iter);
4141 gtk_tree_model_get(store, &iter, DUPE_MENU_COLUMN_MASK, &match_type, -1);
4142 if (match_type == DUPE_MATCH_SIM_CUSTOM)
4146 valid = gtk_tree_model_iter_next(store, &iter);
4149 gtk_combo_box_set_active_iter(GTK_COMBO_BOX(dw->combo), &iter);
4150 dupe_window_recompare(dw);
4153 static void dupe_popup_menu_pos_cb(GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer data)
4155 GtkWidget *view = data;
4157 gint cx, cy, cw, ch;
4160 gtk_tree_view_get_cursor(GTK_TREE_VIEW(view), &tpath, NULL);
4163 if (gtk_tree_view_get_column(GTK_TREE_VIEW(view), DUPE_COLUMN_NAME - 1) != NULL)
4165 column = DUPE_COLUMN_NAME - 1;
4169 /* dw->second_listview */
4172 tree_view_get_cell_clamped(GTK_TREE_VIEW(view), tpath, column, TRUE, &cx, &cy, &cw, &ch);
4173 gtk_tree_path_free(tpath);
4175 popup_menu_position_clamp(menu, &cx, &cy, 0);
4180 static gboolean dupe_window_keypress_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
4182 DupeWindow *dw = data;
4183 gboolean stop_signal = FALSE;
4185 GtkWidget *listview;
4186 GtkTreeModel *store;
4187 GtkTreeSelection *selection;
4189 DupeItem *di = NULL;
4191 on_second = gtk_widget_has_focus(dw->second_listview);
4195 listview = dw->second_listview;
4199 listview = dw->listview;
4202 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(listview));
4203 slist = gtk_tree_selection_get_selected_rows(selection, &store);
4210 last = g_list_last(slist);
4213 /* last is newest selected file */
4214 gtk_tree_model_get_iter(store, &iter, tpath);
4215 gtk_tree_model_get(store, &iter, DUPE_COLUMN_POINTER, &di, -1);
4217 g_list_foreach(slist, (GFunc)tree_path_free_wrapper, NULL);
4220 if (event->state & GDK_CONTROL_MASK)
4225 switch (event->keyval)
4239 file_util_copy(NULL, dupe_listview_get_selection(dw, listview),
4243 file_util_move(NULL, dupe_listview_get_selection(dw, listview),
4247 file_util_rename(NULL, dupe_listview_get_selection(dw, listview), dw->window);
4250 options->file_ops.safe_delete_enable = TRUE;
4251 file_util_delete(NULL, dupe_listview_get_selection(dw, listview), dw->window);
4254 stop_signal = FALSE;
4262 switch (event->keyval)
4265 if (event->state & GDK_SHIFT_MASK)
4267 gtk_tree_selection_unselect_all(selection);
4271 gtk_tree_selection_select_all(selection);
4274 case GDK_KEY_Delete: case GDK_KEY_KP_Delete:
4277 dupe_second_clear(dw);
4278 dupe_window_recompare(dw);
4282 dupe_window_clear(dw);
4286 dupe_window_append_file_list(dw, FALSE);
4289 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dw->button_thumbs),
4290 !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dw->button_thumbs)));
4293 dupe_window_close(dw);
4296 stop_signal = FALSE;
4304 switch (event->keyval)
4306 case GDK_KEY_Return: case GDK_KEY_KP_Enter:
4307 dupe_menu_view(dw, di, listview, FALSE);
4310 dupe_menu_view(dw, di, listview, TRUE);
4312 case GDK_KEY_Delete: case GDK_KEY_KP_Delete:
4313 dupe_window_remove_selection(dw, listview);
4318 dupe_window_collection_from_selection(dw);
4322 options->duplicates_select_type = DUPE_SELECT_NONE;
4323 dupe_listview_select_dupes(dw, DUPE_SELECT_NONE);
4326 options->duplicates_select_type = DUPE_SELECT_GROUP1;
4327 dupe_listview_select_dupes(dw, DUPE_SELECT_GROUP1);
4330 options->duplicates_select_type = DUPE_SELECT_GROUP2;
4331 dupe_listview_select_dupes(dw, DUPE_SELECT_GROUP2);
4339 menu = dupe_menu_popup_main(dw, di);
4340 gtk_menu_popup(GTK_MENU(menu), NULL, NULL,
4341 dupe_popup_menu_pos_cb, listview, 0, GDK_CURRENT_TIME);
4347 menu = dupe_menu_popup_second(dw, di);
4348 gtk_menu_popup(GTK_MENU(menu), NULL, NULL,
4349 dupe_popup_menu_pos_cb, listview, 0, GDK_CURRENT_TIME);
4353 stop_signal = FALSE;
4357 if (!stop_signal && is_help_key(event))
4359 help_window_show("GuideImageSearchFindingDuplicates.html");
4367 void dupe_window_clear(DupeWindow *dw)
4369 GtkListStore *store;
4371 dupe_check_stop(dw);
4373 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dw->listview)));
4374 gtk_list_store_clear(store);
4375 gtk_tree_view_columns_autosize(GTK_TREE_VIEW(dw->listview));
4377 g_list_free(dw->dupes);
4380 dupe_list_free(dw->list);
4384 dupe_match_reset_list(dw->second_list);
4386 dupe_window_update_count(dw, FALSE);
4387 dupe_window_update_progress(dw, NULL, 0.0, FALSE);
4390 static void dupe_window_get_geometry(DupeWindow *dw)
4393 LayoutWindow *lw = NULL;
4397 if (!dw || !lw) return;
4399 window = gtk_widget_get_window(dw->window);
4400 gdk_window_get_position(window, &lw->options.dupe_window.x, &lw->options.dupe_window.y);
4401 lw->options.dupe_window.w = gdk_window_get_width(window);
4402 lw->options.dupe_window.h = gdk_window_get_height(window);
4405 void dupe_window_close(DupeWindow *dw)
4407 dupe_check_stop(dw);
4409 dupe_window_get_geometry(dw);
4411 dupe_window_list = g_list_remove(dupe_window_list, dw);
4412 gtk_widget_destroy(dw->window);
4414 g_list_free(dw->dupes);
4415 dupe_list_free(dw->list);
4417 dupe_list_free(dw->second_list);
4419 file_data_unregister_notify_func(dupe_notify_cb, dw);
4421 g_thread_pool_free(dw->dupe_comparison_thread_pool, TRUE, TRUE);
4426 static gint dupe_window_close_cb(GtkWidget *widget, gpointer data)
4428 DupeWindow *dw = data;
4430 dupe_window_close(dw);
4435 static gint dupe_window_delete(GtkWidget *widget, GdkEvent *event, gpointer data)
4437 DupeWindow *dw = data;
4438 dupe_window_close(dw);
4443 static void dupe_help_cb(GtkAction *action, gpointer data)
4445 help_window_show("GuideImageSearchFindingDuplicates.html");
4448 static gint default_sort_cb(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer data)
4453 static gint column_sort_cb(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer data)
4455 GtkTreeSortable *sortable = data;
4457 gchar *rank_str_a, *rank_str_b;
4462 gint sort_column_id;
4463 GtkSortType sort_order;
4467 gtk_tree_sortable_get_sort_column_id(sortable, &sort_column_id, &sort_order);
4469 gtk_tree_model_get(model, a, DUPE_COLUMN_RANK, &rank_str_a, DUPE_COLUMN_SET, &group_a, DUPE_COLUMN_POINTER, &di_a, -1);
4471 gtk_tree_model_get(model, b, DUPE_COLUMN_RANK, &rank_str_b, DUPE_COLUMN_SET, &group_b, DUPE_COLUMN_POINTER, &di_b, -1);
4473 if (group_a == group_b)
4475 switch (sort_column_id)
4477 case DUPE_COLUMN_NAME:
4478 ret = utf8_compare(di_a->fd->name, di_b->fd->name, TRUE);
4480 case DUPE_COLUMN_SIZE:
4481 if (di_a->fd->size == di_b->fd->size)
4487 ret = (di_a->fd->size > di_b->fd->size) ? 1 : -1;
4490 case DUPE_COLUMN_DATE:
4491 if (di_a->fd->date == di_b->fd->date)
4497 ret = (di_a->fd->date > di_b->fd->date) ? 1 : -1;
4500 case DUPE_COLUMN_DIMENSIONS:
4501 if ((di_a->width == di_b->width) && (di_a->height == di_b->height))
4507 ret = ((di_a->width * di_a->height) > (di_b->width * di_b->height)) ? 1 : -1;
4510 case DUPE_COLUMN_RANK:
4511 rank_int_a = atoi(rank_str_a);
4512 rank_int_b = atoi(rank_str_b);
4513 if (rank_int_a == 0) rank_int_a = 101;
4514 if (rank_int_b == 0) rank_int_b = 101;
4516 if (rank_int_a == rank_int_b)
4522 ret = (rank_int_a > rank_int_b) ? 1 : -1;
4525 case DUPE_COLUMN_PATH:
4526 ret = utf8_compare(di_a->fd->path, di_b->fd->path, TRUE);
4530 else if (group_a < group_b)
4532 ret = (sort_order == GTK_SORT_ASCENDING) ? 1 : -1;
4536 ret = (sort_order == GTK_SORT_ASCENDING) ? -1 : 1;
4542 static void column_clicked_cb(GtkWidget *widget, gpointer data)
4544 DupeWindow *dw = data;
4546 options->duplicates_match = DUPE_SELECT_NONE;
4547 dupe_listview_select_dupes(dw, DUPE_SELECT_NONE);
4550 /* collection and files can be NULL */
4551 DupeWindow *dupe_window_new()
4556 GtkWidget *scrolled;
4558 GtkWidget *status_box;
4559 GtkWidget *controls_box;
4560 GtkWidget *button_box;
4563 GtkListStore *store;
4564 GtkTreeSelection *selection;
4565 GdkGeometry geometry;
4566 LayoutWindow *lw = NULL;
4570 dw = g_new0(DupeWindow, 1);
4571 dw->add_files_queue = NULL;
4572 dw->add_files_queue_id = 0;
4574 dw->match_mask = DUPE_MATCH_NAME;
4575 if (options->duplicates_match == DUPE_MATCH_NAME) dw->match_mask = DUPE_MATCH_NAME;
4576 if (options->duplicates_match == DUPE_MATCH_SIZE) dw->match_mask = DUPE_MATCH_SIZE;
4577 if (options->duplicates_match == DUPE_MATCH_DATE) dw->match_mask = DUPE_MATCH_DATE;
4578 if (options->duplicates_match == DUPE_MATCH_DIM) dw->match_mask = DUPE_MATCH_DIM;
4579 if (options->duplicates_match == DUPE_MATCH_SUM) dw->match_mask = DUPE_MATCH_SUM;
4580 if (options->duplicates_match == DUPE_MATCH_PATH) dw->match_mask = DUPE_MATCH_PATH;
4581 if (options->duplicates_match == DUPE_MATCH_SIM_HIGH) dw->match_mask = DUPE_MATCH_SIM_HIGH;
4582 if (options->duplicates_match == DUPE_MATCH_SIM_MED) dw->match_mask = DUPE_MATCH_SIM_MED;
4583 if (options->duplicates_match == DUPE_MATCH_SIM_LOW) dw->match_mask = DUPE_MATCH_SIM_LOW;
4584 if (options->duplicates_match == DUPE_MATCH_SIM_CUSTOM) dw->match_mask = DUPE_MATCH_SIM_CUSTOM;
4585 if (options->duplicates_match == DUPE_MATCH_NAME_CI) dw->match_mask = DUPE_MATCH_NAME_CI;
4586 if (options->duplicates_match == DUPE_MATCH_NAME_CONTENT) dw->match_mask = DUPE_MATCH_NAME_CONTENT;
4587 if (options->duplicates_match == DUPE_MATCH_NAME_CI_CONTENT) dw->match_mask = DUPE_MATCH_NAME_CI_CONTENT;
4588 if (options->duplicates_match == DUPE_MATCH_ALL) dw->match_mask = DUPE_MATCH_ALL;
4590 dw->window = window_new(GTK_WINDOW_TOPLEVEL, "dupe", NULL, NULL, _("Find duplicates"));
4591 DEBUG_NAME(dw->window);
4593 geometry.min_width = DEFAULT_MINIMAL_WINDOW_SIZE;
4594 geometry.min_height = DEFAULT_MINIMAL_WINDOW_SIZE;
4595 geometry.base_width = DUPE_DEF_WIDTH;
4596 geometry.base_height = DUPE_DEF_HEIGHT;
4597 gtk_window_set_geometry_hints(GTK_WINDOW(dw->window), NULL, &geometry,
4598 GDK_HINT_MIN_SIZE | GDK_HINT_BASE_SIZE);
4600 if (lw && options->save_window_positions)
4602 gtk_window_set_default_size(GTK_WINDOW(dw->window), lw->options.dupe_window.w, lw->options.dupe_window.h);
4603 gtk_window_move(GTK_WINDOW(dw->window), lw->options.dupe_window.x, lw->options.dupe_window.y);
4607 gtk_window_set_default_size(GTK_WINDOW(dw->window), DUPE_DEF_WIDTH, DUPE_DEF_HEIGHT);
4610 gtk_window_set_resizable(GTK_WINDOW(dw->window), TRUE);
4611 gtk_container_set_border_width(GTK_CONTAINER(dw->window), 0);
4613 g_signal_connect(G_OBJECT(dw->window), "delete_event",
4614 G_CALLBACK(dupe_window_delete), dw);
4615 g_signal_connect(G_OBJECT(dw->window), "key_press_event",
4616 G_CALLBACK(dupe_window_keypress_cb), dw);
4618 vbox = gtk_vbox_new(FALSE, 0);
4619 gtk_container_add(GTK_CONTAINER(dw->window), vbox);
4620 gtk_widget_show(vbox);
4622 dw->table = gtk_table_new(1, 3, FALSE);
4623 gtk_box_pack_start(GTK_BOX(vbox), dw->table, TRUE, TRUE, 0);
4624 gtk_widget_show(dw->table);
4626 scrolled = gtk_scrolled_window_new(NULL, NULL);
4627 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN);
4628 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
4629 gtk_table_attach_defaults(GTK_TABLE(dw->table), scrolled, 0, 2, 0, 1);
4630 gtk_widget_show(scrolled);
4632 store = gtk_list_store_new(DUPE_COLUMN_COUNT, G_TYPE_POINTER, G_TYPE_STRING, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_INT, G_TYPE_INT);
4633 dw->listview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
4634 g_object_unref(store);
4636 dw->sortable = GTK_TREE_SORTABLE(store);
4638 gtk_tree_sortable_set_sort_func(dw->sortable, DUPE_COLUMN_RANK, column_sort_cb, dw->sortable, NULL);
4639 gtk_tree_sortable_set_sort_func(dw->sortable, DUPE_COLUMN_SET, default_sort_cb, dw->sortable, NULL);
4640 gtk_tree_sortable_set_sort_func(dw->sortable, DUPE_COLUMN_THUMB, default_sort_cb, dw->sortable, NULL);
4641 gtk_tree_sortable_set_sort_func(dw->sortable, DUPE_COLUMN_NAME, column_sort_cb, dw->sortable, NULL);
4642 gtk_tree_sortable_set_sort_func(dw->sortable, DUPE_COLUMN_SIZE, column_sort_cb, dw->sortable, NULL);
4643 gtk_tree_sortable_set_sort_func(dw->sortable, DUPE_COLUMN_DATE, column_sort_cb, dw->sortable, NULL);
4644 gtk_tree_sortable_set_sort_func(dw->sortable, DUPE_COLUMN_DIMENSIONS, column_sort_cb, dw->sortable, NULL);
4645 gtk_tree_sortable_set_sort_func(dw->sortable, DUPE_COLUMN_PATH, column_sort_cb, dw->sortable, NULL);
4647 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dw->listview));
4648 gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_MULTIPLE);
4649 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(dw->listview), TRUE);
4650 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(dw->listview), FALSE);
4652 dupe_listview_add_column(dw, dw->listview, DUPE_COLUMN_RANK, _("Rank"), FALSE, TRUE);
4653 dupe_listview_add_column(dw, dw->listview, DUPE_COLUMN_THUMB, _("Thumb"), TRUE, FALSE);
4654 dupe_listview_add_column(dw, dw->listview, DUPE_COLUMN_NAME, _("Name"), FALSE, FALSE);
4655 dupe_listview_add_column(dw, dw->listview, DUPE_COLUMN_SIZE, _("Size"), FALSE, TRUE);
4656 dupe_listview_add_column(dw, dw->listview, DUPE_COLUMN_DATE, _("Date"), FALSE, TRUE);
4657 dupe_listview_add_column(dw, dw->listview, DUPE_COLUMN_DIMENSIONS, _("Dimensions"), FALSE, FALSE);
4658 dupe_listview_add_column(dw, dw->listview, DUPE_COLUMN_PATH, _("Path"), FALSE, FALSE);
4659 dupe_listview_add_column(dw, dw->listview, DUPE_COLUMN_SET, _("Set"), FALSE, FALSE);
4661 g_signal_connect(gtk_tree_view_get_column(GTK_TREE_VIEW(dw->listview), DUPE_COLUMN_RANK - 1), "clicked", (GCallback)column_clicked_cb, dw);
4662 g_signal_connect(gtk_tree_view_get_column(GTK_TREE_VIEW(dw->listview), DUPE_COLUMN_NAME - 1), "clicked", (GCallback)column_clicked_cb, dw);
4663 g_signal_connect(gtk_tree_view_get_column(GTK_TREE_VIEW(dw->listview), DUPE_COLUMN_SIZE - 1), "clicked", (GCallback)column_clicked_cb, dw);
4664 g_signal_connect(gtk_tree_view_get_column(GTK_TREE_VIEW(dw->listview), DUPE_COLUMN_DATE - 1), "clicked", (GCallback)column_clicked_cb, dw);
4665 g_signal_connect(gtk_tree_view_get_column(GTK_TREE_VIEW(dw->listview), DUPE_COLUMN_DIMENSIONS - 1), "clicked", (GCallback)column_clicked_cb, dw);
4666 g_signal_connect(gtk_tree_view_get_column(GTK_TREE_VIEW(dw->listview), DUPE_COLUMN_PATH - 1), "clicked", (GCallback)column_clicked_cb, dw);
4668 gtk_container_add(GTK_CONTAINER(scrolled), dw->listview);
4669 gtk_widget_show(dw->listview);
4671 dw->second_vbox = gtk_vbox_new(FALSE, 0);
4672 gtk_table_attach_defaults(GTK_TABLE(dw->table), dw->second_vbox, 2, 3, 0, 1);
4675 gtk_table_set_col_spacings(GTK_TABLE(dw->table), PREF_PAD_GAP);
4676 gtk_widget_show(dw->second_vbox);
4680 gtk_table_set_col_spacings(GTK_TABLE(dw->table), 0);
4683 scrolled = gtk_scrolled_window_new(NULL, NULL);
4684 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN);
4685 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
4686 gtk_box_pack_start(GTK_BOX(dw->second_vbox), scrolled, TRUE, TRUE, 0);
4687 gtk_widget_show(scrolled);
4689 store = gtk_list_store_new(2, G_TYPE_POINTER, G_TYPE_STRING);
4690 dw->second_listview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
4692 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dw->second_listview));
4693 gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_MULTIPLE);
4695 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(dw->second_listview), TRUE);
4696 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(dw->second_listview), FALSE);
4698 dupe_listview_add_column(dw, dw->second_listview, 1, _("Compare to:"), FALSE, FALSE);
4700 gtk_container_add(GTK_CONTAINER(scrolled), dw->second_listview);
4701 gtk_widget_show(dw->second_listview);
4703 dw->second_status_label = gtk_label_new("");
4704 gtk_box_pack_start(GTK_BOX(dw->second_vbox), dw->second_status_label, FALSE, FALSE, 0);
4705 gtk_widget_show(dw->second_status_label);
4707 pref_line(dw->second_vbox, GTK_ORIENTATION_HORIZONTAL);
4709 status_box = gtk_hbox_new(FALSE, 0);
4710 gtk_box_pack_start(GTK_BOX(vbox), status_box, FALSE, FALSE, 0);
4711 gtk_widget_show(status_box);
4713 frame = gtk_frame_new(NULL);
4715 gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN);
4716 gtk_box_pack_start(GTK_BOX(status_box), frame, TRUE, TRUE, 0);
4717 gtk_widget_show(frame);
4719 dw->status_label = gtk_label_new("");
4720 gtk_container_add(GTK_CONTAINER(frame), dw->status_label);
4721 gtk_widget_show(dw->status_label);
4723 dw->extra_label = gtk_progress_bar_new();
4724 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(dw->extra_label), 0.0);
4725 #if GTK_CHECK_VERSION(3,0,0)
4726 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(dw->extra_label), "");
4727 gtk_progress_bar_set_show_text(GTK_PROGRESS_BAR(dw->extra_label), TRUE);
4729 gtk_box_pack_start(GTK_BOX(status_box), dw->extra_label, FALSE, FALSE, PREF_PAD_SPACE);
4730 gtk_widget_show(dw->extra_label);
4732 controls_box = pref_box_new(vbox, FALSE, GTK_ORIENTATION_HORIZONTAL, 0);
4733 dw->controls_box = controls_box;
4735 dw->button_thumbs = gtk_check_button_new_with_label(_("Thumbnails"));
4736 dw->show_thumbs = options->duplicates_thumbnails;
4737 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dw->button_thumbs), dw->show_thumbs);
4738 g_signal_connect(G_OBJECT(dw->button_thumbs), "toggled",
4739 G_CALLBACK(dupe_window_show_thumb_cb), dw);
4740 gtk_box_pack_start(GTK_BOX(controls_box), dw->button_thumbs, FALSE, FALSE, PREF_PAD_SPACE);
4741 gtk_widget_show(dw->button_thumbs);
4743 label = gtk_label_new(_("Compare by:"));
4744 gtk_box_pack_start(GTK_BOX(controls_box), label, FALSE, FALSE, PREF_PAD_SPACE);
4745 gtk_widget_show(label);
4747 dupe_menu_setup(dw);
4748 gtk_box_pack_start(GTK_BOX(controls_box), dw->combo, FALSE, FALSE, 0);
4749 gtk_widget_show(dw->combo);
4751 label = gtk_label_new(_("Custom Threshold"));
4752 gtk_box_pack_start(GTK_BOX(controls_box), label, FALSE, FALSE, PREF_PAD_SPACE);
4753 gtk_widget_show(label);
4754 dw->custom_threshold = gtk_spin_button_new_with_range(1, 100, 1);
4755 gtk_widget_set_tooltip_text(GTK_WIDGET(dw->custom_threshold), "Custom similarity threshold\n(Use tab key to set value)");
4756 gtk_spin_button_set_value(GTK_SPIN_BUTTON(dw->custom_threshold), options->duplicates_similarity_threshold);
4757 g_signal_connect(G_OBJECT(dw->custom_threshold), "value_changed", G_CALLBACK(dupe_window_custom_threshold_cb), dw);
4758 gtk_box_pack_start(GTK_BOX(controls_box), dw->custom_threshold, FALSE, FALSE, PREF_PAD_SPACE);
4759 gtk_widget_show(dw->custom_threshold);
4761 button = gtk_check_button_new_with_label(_("Sort"));
4762 gtk_widget_set_tooltip_text(GTK_WIDGET(button), "Sort by group totals");
4763 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), options->sort_totals);
4764 g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(dupe_sort_totals_toggle_cb), dw);
4765 gtk_box_pack_start(GTK_BOX(controls_box), button, FALSE, FALSE, PREF_PAD_SPACE);
4766 gtk_widget_show(button);
4768 dw->button_rotation_invariant = gtk_check_button_new_with_label(_("Ignore Orientation"));
4769 gtk_widget_set_tooltip_text(GTK_WIDGET(dw->button_rotation_invariant), "Ignore image orientation");
4770 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dw->button_rotation_invariant), options->rot_invariant_sim);
4771 g_signal_connect(G_OBJECT(dw->button_rotation_invariant), "toggled",
4772 G_CALLBACK(dupe_window_rotation_invariant_cb), dw);
4773 gtk_box_pack_start(GTK_BOX(controls_box), dw->button_rotation_invariant, FALSE, FALSE, PREF_PAD_SPACE);
4774 gtk_widget_show(dw->button_rotation_invariant);
4776 button = gtk_check_button_new_with_label(_("Compare two file sets"));
4777 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), dw->second_set);
4778 g_signal_connect(G_OBJECT(button), "toggled",
4779 G_CALLBACK(dupe_second_set_toggle_cb), dw);
4780 gtk_box_pack_start(GTK_BOX(controls_box), button, FALSE, FALSE, PREF_PAD_SPACE);
4781 gtk_widget_show(button);
4783 button_box = gtk_hbox_new(FALSE, 0);
4784 gtk_box_pack_start(GTK_BOX(vbox), button_box, FALSE, FALSE, 0);
4785 gtk_widget_show(button_box);
4787 hbox = gtk_hbutton_box_new();
4788 gtk_button_box_set_layout(GTK_BUTTON_BOX(hbox), GTK_BUTTONBOX_END);
4789 gtk_box_set_spacing(GTK_BOX(hbox), PREF_PAD_SPACE);
4790 gtk_box_pack_end(GTK_BOX(button_box), hbox, FALSE, FALSE, 0);
4791 gtk_widget_show(hbox);
4793 button = pref_button_new(NULL, GTK_STOCK_HELP, NULL, FALSE, G_CALLBACK(dupe_help_cb), NULL);
4794 gtk_container_add(GTK_CONTAINER(hbox), button);
4795 gtk_widget_set_can_default(button, TRUE);
4796 gtk_widget_show(button);
4798 button = pref_button_new(NULL, GTK_STOCK_STOP, NULL, FALSE, G_CALLBACK(dupe_check_stop_cb), dw);
4799 gtk_container_add(GTK_CONTAINER(hbox), button);
4800 gtk_widget_set_can_default(button, TRUE);
4801 gtk_widget_show(button);
4803 button = pref_button_new(NULL, GTK_STOCK_CLOSE, NULL, FALSE, G_CALLBACK(dupe_window_close_cb), dw);
4804 gtk_container_add(GTK_CONTAINER(hbox), button);
4805 gtk_widget_set_can_default(button, TRUE);
4806 gtk_widget_grab_default(button);
4807 gtk_widget_show(button);
4810 /* order is important here, dnd_init should be seeing mouse
4811 * presses before we possibly handle (and stop) the signal
4813 g_signal_connect(G_OBJECT(dw->listview), "button_press_event",
4814 G_CALLBACK(dupe_listview_press_cb), dw);
4815 g_signal_connect(G_OBJECT(dw->listview), "button_release_event",
4816 G_CALLBACK(dupe_listview_release_cb), dw);
4817 g_signal_connect(G_OBJECT(dw->second_listview), "button_press_event",
4818 G_CALLBACK(dupe_listview_press_cb), dw);
4819 g_signal_connect(G_OBJECT(dw->second_listview), "button_release_event",
4820 G_CALLBACK(dupe_listview_release_cb), dw);
4822 gtk_widget_show(dw->window);
4824 dupe_listview_set_height(dw->listview, dw->show_thumbs);
4825 g_signal_emit_by_name(G_OBJECT(dw->combo), "changed");
4827 dupe_window_update_count(dw, TRUE);
4828 dupe_window_update_progress(dw, NULL, 0.0, FALSE);
4830 dupe_window_list = g_list_append(dupe_window_list, dw);
4832 file_data_register_notify_func(dupe_notify_cb, dw, NOTIFY_PRIORITY_MEDIUM);
4834 g_mutex_init(&dw->thread_count_mutex);
4835 g_mutex_init(&dw->search_matches_mutex);
4836 dw->dupe_comparison_thread_pool = g_thread_pool_new(dupe_comparison_func, dw, -1, FALSE, NULL);
4842 *-------------------------------------------------------------------
4844 *-------------------------------------------------------------------
4852 static void confirm_dir_list_cancel(GtkWidget *widget, gpointer data)
4857 static void confirm_dir_list_add(GtkWidget *widget, gpointer data)
4859 CDupeConfirmD *d = data;
4862 dupe_window_add_files(d->dw, d->list, FALSE);
4867 FileData *fd = work->data;
4869 if (isdir(fd->path))
4873 filelist_read(fd, &list, NULL);
4874 list = filelist_filter(list, FALSE);
4877 dupe_window_add_files(d->dw, list, FALSE);
4878 filelist_free(list);
4884 static void confirm_dir_list_recurse(GtkWidget *widget, gpointer data)
4886 CDupeConfirmD *d = data;
4887 dupe_window_add_files(d->dw, d->list, TRUE);
4890 static void confirm_dir_list_skip(GtkWidget *widget, gpointer data)
4892 CDupeConfirmD *d = data;
4893 dupe_window_add_files(d->dw, d->list, FALSE);
4896 static void confirm_dir_list_destroy(GtkWidget *widget, gpointer data)
4898 CDupeConfirmD *d = data;
4899 filelist_free(d->list);
4903 static GtkWidget *dupe_confirm_dir_list(DupeWindow *dw, GList *list)
4908 d = g_new0(CDupeConfirmD, 1);
4912 menu = popup_menu_short_lived();
4913 g_signal_connect(G_OBJECT(menu), "destroy",
4914 G_CALLBACK(confirm_dir_list_destroy), d);
4916 menu_item_add_stock(menu, _("Dropped list includes folders."), GTK_STOCK_DND_MULTIPLE, NULL, NULL);
4917 menu_item_add_divider(menu);
4918 menu_item_add_stock(menu, _("_Add contents"), GTK_STOCK_OK, G_CALLBACK(confirm_dir_list_add), d);
4919 menu_item_add_stock(menu, _("Add contents _recursive"), GTK_STOCK_ADD, G_CALLBACK(confirm_dir_list_recurse), d);
4920 menu_item_add_stock(menu, _("_Skip folders"), GTK_STOCK_REMOVE, G_CALLBACK(confirm_dir_list_skip), d);
4921 menu_item_add_divider(menu);
4922 menu_item_add_stock(menu, _("Cancel"), GTK_STOCK_CANCEL, G_CALLBACK(confirm_dir_list_cancel), d);
4928 *-------------------------------------------------------------------
4930 *-------------------------------------------------------------------
4933 static GtkTargetEntry dupe_drag_types[] = {
4934 { "text/uri-list", 0, TARGET_URI_LIST },
4935 { "text/plain", 0, TARGET_TEXT_PLAIN }
4937 static gint n_dupe_drag_types = 2;
4939 static GtkTargetEntry dupe_drop_types[] = {
4940 { TARGET_APP_COLLECTION_MEMBER_STRING, 0, TARGET_APP_COLLECTION_MEMBER },
4941 { "text/uri-list", 0, TARGET_URI_LIST }
4943 static gint n_dupe_drop_types = 2;
4945 static void dupe_dnd_data_set(GtkWidget *widget, GdkDragContext *context,
4946 GtkSelectionData *selection_data, guint info,
4947 guint time, gpointer data)
4949 DupeWindow *dw = data;
4954 case TARGET_URI_LIST:
4955 case TARGET_TEXT_PLAIN:
4956 list = dupe_listview_get_selection(dw, widget);
4958 uri_selection_data_set_uris_from_filelist(selection_data, list);
4959 filelist_free(list);
4966 static void dupe_dnd_data_get(GtkWidget *widget, GdkDragContext *context,
4968 GtkSelectionData *selection_data, guint info,
4969 guint time, gpointer data)
4971 DupeWindow *dw = data;
4976 if (dw->add_files_queue_id > 0)
4978 warning_dialog(_("Find duplicates"), _("Please wait for the current file selection to be loaded."), GTK_STOCK_DIALOG_INFO, dw->window);
4983 source = gtk_drag_get_source_widget(context);
4984 if (source == dw->listview || source == dw->second_listview) return;
4986 dw->second_drop = (dw->second_set && widget == dw->second_listview);
4990 case TARGET_APP_COLLECTION_MEMBER:
4991 collection_from_dnd_data((gchar *)gtk_selection_data_get_data(selection_data), &list, NULL);
4993 case TARGET_URI_LIST:
4994 list = uri_filelist_from_gtk_selection_data(selection_data);
4998 FileData *fd = work->data;
4999 if (isdir(fd->path))
5002 menu = dupe_confirm_dir_list(dw, list);
5003 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 0, time);
5016 dupe_window_add_files(dw, list, FALSE);
5017 filelist_free(list);
5021 static void dupe_dest_set(GtkWidget *widget, gboolean enable)
5025 gtk_drag_dest_set(widget,
5026 GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_HIGHLIGHT | GTK_DEST_DEFAULT_DROP,
5027 dupe_drop_types, n_dupe_drop_types,
5028 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_ASK);
5033 gtk_drag_dest_unset(widget);
5037 static void dupe_dnd_begin(GtkWidget *widget, GdkDragContext *context, gpointer data)
5039 DupeWindow *dw = data;
5040 dupe_dest_set(dw->listview, FALSE);
5041 dupe_dest_set(dw->second_listview, FALSE);
5043 if (dw->click_item && !dupe_listview_item_is_selected(dw, dw->click_item, widget))
5045 GtkListStore *store;
5048 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(widget)));
5049 if (dupe_listview_find_item(store, dw->click_item, &iter) >= 0)
5051 GtkTreeSelection *selection;
5054 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
5055 gtk_tree_selection_unselect_all(selection);
5056 gtk_tree_selection_select_iter(selection, &iter);
5058 tpath = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter);
5059 gtk_tree_view_set_cursor(GTK_TREE_VIEW(widget), tpath, NULL, FALSE);
5060 gtk_tree_path_free(tpath);
5064 if (dw->show_thumbs &&
5065 widget == dw->listview &&
5066 dw->click_item && dw->click_item->pixbuf)
5068 GtkTreeSelection *selection;
5071 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
5072 items = gtk_tree_selection_count_selected_rows(selection);
5073 dnd_set_drag_icon(widget, context, dw->click_item->pixbuf, items);
5077 static void dupe_dnd_end(GtkWidget *widget, GdkDragContext *context, gpointer data)
5079 DupeWindow *dw = data;
5080 dupe_dest_set(dw->listview, TRUE);
5081 dupe_dest_set(dw->second_listview, TRUE);
5084 static void dupe_dnd_init(DupeWindow *dw)
5086 gtk_drag_source_set(dw->listview, GDK_BUTTON1_MASK | GDK_BUTTON2_MASK,
5087 dupe_drag_types, n_dupe_drag_types,
5088 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK);
5089 g_signal_connect(G_OBJECT(dw->listview), "drag_data_get",
5090 G_CALLBACK(dupe_dnd_data_set), dw);
5091 g_signal_connect(G_OBJECT(dw->listview), "drag_begin",
5092 G_CALLBACK(dupe_dnd_begin), dw);
5093 g_signal_connect(G_OBJECT(dw->listview), "drag_end",
5094 G_CALLBACK(dupe_dnd_end), dw);
5096 dupe_dest_set(dw->listview, TRUE);
5097 g_signal_connect(G_OBJECT(dw->listview), "drag_data_received",
5098 G_CALLBACK(dupe_dnd_data_get), dw);
5100 gtk_drag_source_set(dw->second_listview, GDK_BUTTON1_MASK | GDK_BUTTON2_MASK,
5101 dupe_drag_types, n_dupe_drag_types,
5102 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK);
5103 g_signal_connect(G_OBJECT(dw->second_listview), "drag_data_get",
5104 G_CALLBACK(dupe_dnd_data_set), dw);
5105 g_signal_connect(G_OBJECT(dw->second_listview), "drag_begin",
5106 G_CALLBACK(dupe_dnd_begin), dw);
5107 g_signal_connect(G_OBJECT(dw->second_listview), "drag_end",
5108 G_CALLBACK(dupe_dnd_end), dw);
5110 dupe_dest_set(dw->second_listview, TRUE);
5111 g_signal_connect(G_OBJECT(dw->second_listview), "drag_data_received",
5112 G_CALLBACK(dupe_dnd_data_get), dw);
5116 *-------------------------------------------------------------------
5117 * maintenance (move, delete, etc.)
5118 *-------------------------------------------------------------------
5121 static void dupe_notify_cb(FileData *fd, NotifyType type, gpointer data)
5123 DupeWindow *dw = data;
5125 if (!(type & NOTIFY_CHANGE) || !fd->change) return;
5127 DEBUG_1("Notify dupe: %s %04x", fd->path, type);
5129 switch (fd->change->type)
5131 case FILEDATA_CHANGE_MOVE:
5132 case FILEDATA_CHANGE_RENAME:
5133 dupe_item_update_fd(dw, fd);
5135 case FILEDATA_CHANGE_COPY:
5137 case FILEDATA_CHANGE_DELETE:
5138 /* Update the UI only once, after the operation finishes */
5140 case FILEDATA_CHANGE_UNSPECIFIED:
5141 case FILEDATA_CHANGE_WRITE_METADATA:
5148 * @brief Refresh window after a file delete operation
5149 * @param success (ud->phase != UTILITY_PHASE_CANCEL) #file_util_dialog_run
5150 * @param dest_path Not used
5151 * @param data #DupeWindow
5153 * If the window is refreshed after each file of a large set is deleted,
5154 * the UI slows to an unacceptable level. The #FileUtilDoneFunc is used
5155 * to call this function once, when the entire delete operation is completed.
5157 static void delete_finished_cb(gboolean success, const gchar *dest_path, gpointer data)
5159 DupeWindow *dw = data;
5167 dupe_window_remove_selection(dw, dw->listview);
5171 *-------------------------------------------------------------------
5172 * Export duplicates data
5173 *-------------------------------------------------------------------
5181 typedef struct _ExportDupesData ExportDupesData;
5182 struct _ExportDupesData
5185 SeparatorType separator;
5186 DupeWindow *dupewindow;
5189 static void export_duplicates_close(ExportDupesData *edd)
5191 if (edd->dialog) file_dialog_close(edd->dialog);
5195 static void export_duplicates_data_cancel_cb(FileDialog *fdlg, gpointer data)
5197 ExportDupesData *edd = data;
5199 export_duplicates_close(edd);
5202 static void export_duplicates_data_save_cb(FileDialog *fdlg, gpointer data)
5204 ExportDupesData *edd = data;
5205 GError *error = NULL;
5206 GtkTreeModel *store;
5209 GFileOutputStream *gfstream;
5211 GString *output_string;
5215 GtkTreeSelection *selection;
5220 gboolean color_old = FALSE;
5221 gboolean color_new = FALSE;
5225 history_list_add_to_key("export_duplicates", fdlg->dest_path, -1);
5227 out_file = g_file_new_for_path(fdlg->dest_path);
5229 gfstream = g_file_replace(out_file, NULL, TRUE, G_FILE_CREATE_NONE, NULL, &error);
5232 log_printf(_("Error creating Export duplicates data file: Error: %s\n"), error->message);
5233 g_error_free(error);
5237 sep = g_strdup((edd->separator == EXPORT_CSV) ? "," : "\t");
5238 output_string = g_string_new(g_strjoin(sep, _("Match"), _("Group"), _("Similarity"), _("Set"), _("Thumbnail"), _("Name"), _("Size"), _("Date"), _("Width"), _("Height"), _("Path\n"), NULL));
5240 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(edd->dupewindow->listview));
5241 slist = gtk_tree_selection_get_selected_rows(selection, &store);
5245 gtk_tree_model_get_iter(store, &iter, tpath);
5246 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, DUPE_COLUMN_COLOR, &color_new, -1);
5247 color_old = !color_new;
5253 gtk_tree_model_get_iter(store, &iter, tpath);
5255 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, DUPE_COLUMN_POINTER, &di, -1);
5257 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, DUPE_COLUMN_COLOR, &color_new, -1);
5258 if (color_new != color_old)
5262 color_old = color_new;
5263 output_string = g_string_append(output_string, g_strdup_printf("%d", match_count));
5264 output_string = g_string_append(output_string, sep);
5266 if ((dupe_match_find_parent(edd->dupewindow, di) == di))
5268 output_string = g_string_append(output_string, "1");
5272 output_string = g_string_append(output_string, "2");
5274 output_string = g_string_append(output_string, sep);
5276 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, DUPE_COLUMN_RANK, &rank, -1);
5277 rank_split = g_strsplit_set(rank, " [(", -1);
5278 if (rank_split[0] == NULL)
5280 output_string = g_string_append(output_string, "");
5284 output_string = g_string_append(output_string, g_strdup_printf("%s", rank_split[0]));
5286 output_string = g_string_append(output_string, sep);
5288 g_strfreev(rank_split);
5290 output_string = g_string_append(output_string, g_strdup_printf("%d", (di->second + 1)));
5291 output_string = g_string_append(output_string, sep);
5293 thumb_cache = cache_find_location(CACHE_TYPE_THUMB, di->fd->path);
5296 output_string = g_string_append(output_string, thumb_cache);
5297 g_free(thumb_cache);
5301 output_string = g_string_append(output_string, "");
5303 output_string = g_string_append(output_string, sep);
5305 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, DUPE_COLUMN_NAME, &name, -1);
5306 output_string = g_string_append(output_string, name);
5307 output_string = g_string_append(output_string, sep);
5310 output_string = g_string_append(output_string, g_strdup_printf("%"PRIu64, di->fd->size));
5311 output_string = g_string_append(output_string, sep);
5312 output_string = g_string_append(output_string, text_from_time(di->fd->date));
5313 output_string = g_string_append(output_string, sep);
5314 output_string = g_string_append(output_string, g_strdup_printf("%d", (di->width ? di->width : 0)));
5315 output_string = g_string_append(output_string, sep);
5316 output_string = g_string_append(output_string, g_strdup_printf("%d", (di->height ? di->height : 0)));
5317 output_string = g_string_append(output_string, sep);
5318 output_string = g_string_append(output_string, di->fd->path);
5319 output_string = g_string_append_c(output_string, '\n');
5324 g_output_stream_write(G_OUTPUT_STREAM(gfstream), output_string->str, strlen(output_string->str), NULL, &error);
5327 g_string_free(output_string, TRUE);
5328 g_object_unref(gfstream);
5329 g_object_unref(out_file);
5331 export_duplicates_close(edd);
5334 static void pop_menu_export(GList *selection_list, gpointer dupe_window, gpointer data)
5336 const gint index = GPOINTER_TO_INT(data);
5337 DupeWindow *dw = dupe_window;
5338 gchar *title = "Export duplicates data";
5339 gchar *default_path = "/tmp/";
5340 gchar *file_extension;
5341 const gchar *stock_id;
5342 ExportDupesData *edd;
5343 const gchar *previous_path;
5345 edd = g_new0(ExportDupesData, 1);
5346 edd->dialog = file_util_file_dlg(title, "export_duplicates", NULL, export_duplicates_data_cancel_cb, edd);
5351 edd->separator = EXPORT_CSV;
5352 file_extension = g_strdup(".csv");
5355 edd->separator = EXPORT_TSV;
5356 file_extension = g_strdup(".tsv");
5362 stock_id = GTK_STOCK_SAVE;
5364 generic_dialog_add_message(GENERIC_DIALOG(edd->dialog), NULL, title, NULL, FALSE);
5365 file_dialog_add_button(edd->dialog, stock_id, NULL, export_duplicates_data_save_cb, TRUE);
5367 previous_path = history_list_find_last_path_by_key("export_duplicates");
5369 file_dialog_add_path_widgets(edd->dialog, default_path, previous_path, "export_duplicates", file_extension, _("Export Files"));
5371 edd->dupewindow = dw;
5373 gtk_widget_show(GENERIC_DIALOG(edd->dialog)->dialog);
5375 g_free(file_extension);
5378 static void dupe_pop_menu_export_cb(GtkWidget *widget, gpointer data)
5381 GList *selection_list;
5383 dw = submenu_item_get_data(widget);
5384 selection_list = dupe_listview_get_selection(dw, dw->listview);
5385 pop_menu_export(selection_list, dw, data);
5387 filelist_free(selection_list);
5390 static GtkWidget *submenu_add_export(GtkWidget *menu, GtkWidget **menu_item, GCallback func, gpointer data)
5395 item = menu_item_add(menu, _("Export"), NULL, NULL);
5397 submenu = gtk_menu_new();
5398 g_object_set_data(G_OBJECT(submenu), "submenu_data", data);
5400 menu_item_add_stock_sensitive(submenu, _("Export to csv"),
5401 GTK_STOCK_INDEX, TRUE, G_CALLBACK(func), GINT_TO_POINTER(0));
5402 menu_item_add_stock_sensitive(submenu, _("Export to tab-delimited"),
5403 GTK_STOCK_INDEX, TRUE, G_CALLBACK(func), GINT_TO_POINTER(1));
5405 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu);
5406 if (menu_item) *menu_item = item;
5411 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */