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);
489 static DupeItem *dupe_item_find_path_by_list(const gchar *path, GList *work)
493 DupeItem *di = work->data;
495 if (strcmp(di->fd->path, path) == 0) return di;
505 static DupeItem *dupe_item_find_path(DupeWindow *dw, const gchar *path)
509 di = dupe_item_find_path_by_list(path, dw->list);
510 if (!di && dw->second_set) di = dupe_item_find_path_by_list(path, dw->second_list);
517 * ------------------------------------------------------------------
518 * Image property cache
519 * ------------------------------------------------------------------
522 static void dupe_item_read_cache(DupeItem *di)
529 path = cache_find_location(CACHE_TYPE_SIM, di->fd->path);
532 if (filetime(di->fd->path) != filetime(path))
538 cd = cache_sim_data_load(path);
543 if (!di->simd && cd->sim)
548 if (di->width == 0 && di->height == 0 && cd->dimensions)
550 di->width = cd->width;
551 di->height = cd->height;
552 di->dimensions = (di->width << 16) + di->height;
554 if (!di->md5sum && cd->have_md5sum)
556 di->md5sum = md5_digest_to_text(cd->md5sum);
558 cache_sim_data_free(cd);
562 static void dupe_item_write_cache(DupeItem *di)
569 base = cache_get_location(CACHE_TYPE_SIM, di->fd->path, FALSE, &mode);
570 if (recursive_mkdir_if_not_exists(base, mode))
574 cd = cache_sim_data_new();
575 cd->path = cache_get_location(CACHE_TYPE_SIM, di->fd->path, TRUE, NULL);
577 if (di->width != 0) cache_sim_data_set_dimensions(cd, di->width, di->height);
581 if (md5_digest_from_text(di->md5sum, digest)) cache_sim_data_set_md5sum(cd, digest);
583 if (di->simd) cache_sim_data_set_similarity(cd, di->simd);
585 if (cache_sim_data_save(cd))
587 filetime_set(cd->path, filetime(di->fd->path));
589 cache_sim_data_free(cd);
595 * ------------------------------------------------------------------
597 * ------------------------------------------------------------------
600 static gint dupe_listview_find_item(GtkListStore *store, DupeItem *item, GtkTreeIter *iter)
605 valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), iter);
609 gtk_tree_model_get(GTK_TREE_MODEL(store), iter, DUPE_COLUMN_POINTER, &item_n, -1);
610 if (item_n == item) return row;
612 valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), iter);
619 static void dupe_listview_add(DupeWindow *dw, DupeItem *parent, DupeItem *child)
623 gchar *text[DUPE_COLUMN_COUNT];
626 gboolean color_set = FALSE;
631 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dw->listview)));
637 row = dupe_listview_find_item(store, parent, &iter);
638 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, DUPE_COLUMN_COLOR, &color_set, -1);
644 dm = child->group->data;
645 rank = (gint)floor(dm->rank);
650 log_printf("NULL group in item!\n");
655 if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter))
657 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, DUPE_COLUMN_COLOR, &color_set, -1);
658 color_set = !color_set;
669 di = (child) ? child : parent;
671 if (!child && dw->second_set)
673 text[DUPE_COLUMN_RANK] = g_strdup("[1]");
677 text[DUPE_COLUMN_RANK] = g_strdup((di->second) ? "(2)" : "");
681 text[DUPE_COLUMN_RANK] = g_strdup_printf("%d%s", rank, (di->second) ? " (2)" : "");
684 text[DUPE_COLUMN_THUMB] = "";
685 text[DUPE_COLUMN_NAME] = (gchar *)di->fd->name;
686 text[DUPE_COLUMN_SIZE] = text_from_size(di->fd->size);
687 text[DUPE_COLUMN_DATE] = (gchar *)text_from_time(di->fd->date);
688 if (di->width > 0 && di->height > 0)
690 text[DUPE_COLUMN_DIMENSIONS] = g_strdup_printf("%d x %d", di->width, di->height);
694 text[DUPE_COLUMN_DIMENSIONS] = g_strdup("");
696 text[DUPE_COLUMN_PATH] = di->fd->path;
697 text[DUPE_COLUMN_COLOR] = NULL;
699 gtk_list_store_insert(store, &iter, row);
700 gtk_list_store_set(store, &iter,
701 DUPE_COLUMN_POINTER, di,
702 DUPE_COLUMN_RANK, text[DUPE_COLUMN_RANK],
703 DUPE_COLUMN_THUMB, NULL,
704 DUPE_COLUMN_NAME, text[DUPE_COLUMN_NAME],
705 DUPE_COLUMN_SIZE, text[DUPE_COLUMN_SIZE],
706 DUPE_COLUMN_DATE, text[DUPE_COLUMN_DATE],
707 DUPE_COLUMN_DIMENSIONS, text[DUPE_COLUMN_DIMENSIONS],
708 DUPE_COLUMN_PATH, text[DUPE_COLUMN_PATH],
709 DUPE_COLUMN_COLOR, color_set,
710 DUPE_COLUMN_SET, dw->set_count,
713 g_free(text[DUPE_COLUMN_RANK]);
714 g_free(text[DUPE_COLUMN_SIZE]);
715 g_free(text[DUPE_COLUMN_DIMENSIONS]);
718 static void dupe_listview_select_dupes(DupeWindow *dw, DupeSelectType parents);
720 static void dupe_listview_populate(DupeWindow *dw)
725 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dw->listview)));
726 gtk_list_store_clear(store);
728 work = g_list_last(dw->dupes);
731 DupeItem *parent = work->data;
734 dupe_listview_add(dw, parent, NULL);
736 temp = g_list_last(parent->group);
739 DupeMatch *dm = temp->data;
744 dupe_listview_add(dw, parent, child);
752 gtk_tree_view_columns_autosize(GTK_TREE_VIEW(dw->listview));
754 if (options->duplicates_select_type == DUPE_SELECT_GROUP1)
756 dupe_listview_select_dupes(dw, DUPE_SELECT_GROUP1);
758 else if (options->duplicates_select_type == DUPE_SELECT_GROUP2)
760 dupe_listview_select_dupes(dw, DUPE_SELECT_GROUP2);
765 static void dupe_listview_remove(DupeWindow *dw, DupeItem *di)
773 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dw->listview)));
774 row = dupe_listview_find_item(store, di, &iter);
777 tree_view_move_cursor_away(GTK_TREE_VIEW(dw->listview), &iter, TRUE);
778 gtk_list_store_remove(store, &iter);
780 if (g_list_find(dw->dupes, di) != NULL)
782 if (!dw->color_frozen) dupe_listview_realign_colors(dw);
787 static GList *dupe_listview_get_filelist(DupeWindow *dw, GtkWidget *listview)
794 store = gtk_tree_view_get_model(GTK_TREE_VIEW(listview));
795 valid = gtk_tree_model_get_iter_first(store, &iter);
799 gtk_tree_model_get(store, &iter, DUPE_COLUMN_POINTER, &di, -1);
800 list = g_list_prepend(list, file_data_ref(di->fd));
802 valid = gtk_tree_model_iter_next(store, &iter);
805 return g_list_reverse(list);
809 static GList *dupe_listview_get_selection(DupeWindow *dw, GtkWidget *listview)
812 GtkTreeSelection *selection;
817 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(listview));
818 slist = gtk_tree_selection_get_selected_rows(selection, &store);
822 GtkTreePath *tpath = work->data;
826 gtk_tree_model_get_iter(store, &iter, tpath);
827 gtk_tree_model_get(store, &iter, DUPE_COLUMN_POINTER, &di, -1);
830 list = g_list_prepend(list, file_data_ref(di->fd));
834 g_list_foreach(slist, (GFunc)tree_path_free_wrapper, NULL);
837 return g_list_reverse(list);
840 static gboolean dupe_listview_item_is_selected(DupeWindow *dw, DupeItem *di, GtkWidget *listview)
843 GtkTreeSelection *selection;
846 gboolean found = FALSE;
848 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(listview));
849 slist = gtk_tree_selection_get_selected_rows(selection, &store);
851 while (!found && work)
853 GtkTreePath *tpath = work->data;
857 gtk_tree_model_get_iter(store, &iter, tpath);
858 gtk_tree_model_get(store, &iter, DUPE_COLUMN_POINTER, &di_n, -1);
859 if (di_n == di) found = TRUE;
862 g_list_foreach(slist, (GFunc)tree_path_free_wrapper, NULL);
868 static void dupe_listview_select_dupes(DupeWindow *dw, DupeSelectType parents)
871 GtkTreeSelection *selection;
875 gint set_count_last = -1;
877 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dw->listview));
878 gtk_tree_selection_unselect_all(selection);
880 store = gtk_tree_view_get_model(GTK_TREE_VIEW(dw->listview));
881 valid = gtk_tree_model_get_iter_first(store, &iter);
886 gtk_tree_model_get(store, &iter, DUPE_COLUMN_POINTER, &di, DUPE_COLUMN_SET, &set_count, -1);
887 if (set_count != set_count_last)
889 set_count_last = set_count;
890 if (parents == DUPE_SELECT_GROUP1)
892 gtk_tree_selection_select_iter(selection, &iter);
897 if (parents == DUPE_SELECT_GROUP2)
899 gtk_tree_selection_select_iter(selection, &iter);
902 valid = gtk_tree_model_iter_next(store, &iter);
907 * ------------------------------------------------------------------
908 * Match group manipulation
909 * ------------------------------------------------------------------
913 * @brief Search \a parent->group for \a child (#DupeItem)
919 static DupeMatch *dupe_match_find_match(DupeItem *child, DupeItem *parent)
923 work = parent->group;
926 DupeMatch *dm = work->data;
927 if (dm->di == child) return dm;
934 * @brief Create #DupeMatch structure for \a child, and insert into \a parent->group list.
940 static void dupe_match_link_child(DupeItem *child, DupeItem *parent, gdouble rank)
944 dm = g_new0(DupeMatch, 1);
947 parent->group = g_list_append(parent->group, dm);
951 * @brief Link \a a & \a b as both parent and child
956 * Link \a a as child of \a b, and \a b as child of \a a
958 static void dupe_match_link(DupeItem *a, DupeItem *b, gdouble rank)
960 dupe_match_link_child(a, b, rank);
961 dupe_match_link_child(b, a, rank);
965 * @brief Remove \a child #DupeMatch from \a parent->group list.
970 static void dupe_match_unlink_child(DupeItem *child, DupeItem *parent)
974 dm = dupe_match_find_match(child, parent);
977 parent->group = g_list_remove(parent->group, dm);
983 * @brief Unlink \a a from \a b, and \a b from \a a
987 * Free the relevant #DupeMatch items from the #DupeItem group lists
989 static void dupe_match_unlink(DupeItem *a, DupeItem *b)
991 dupe_match_unlink_child(a, b);
992 dupe_match_unlink_child(b, a);
998 * @param unlink_children
1000 * If \a unlink_children is set, unlink all entries in \a parent->group list. \n
1001 * Free the \a parent->group list and set group_rank to zero;
1003 static void dupe_match_link_clear(DupeItem *parent, gboolean unlink_children)
1007 work = parent->group;
1010 DupeMatch *dm = work->data;
1013 if (unlink_children) dupe_match_unlink_child(parent, dm->di);
1018 g_list_free(parent->group);
1019 parent->group = NULL;
1020 parent->group_rank = 0.0;
1024 * @brief Search \a parent->group list for \a child
1027 * @returns boolean TRUE/FALSE found/not found
1030 static gint dupe_match_link_exists(DupeItem *child, DupeItem *parent)
1032 return (dupe_match_find_match(child, parent) != NULL);
1036 * @brief Search \a parent->group for \a child, and return \a child->rank
1039 * @returns \a dm->di->rank
1042 static gdouble dupe_match_link_rank(DupeItem *child, DupeItem *parent)
1046 dm = dupe_match_find_match(child, parent);
1047 if (dm) return dm->rank;
1053 * @brief Find highest rank in \a child->group
1057 * Search the #DupeMatch entries in the \a child->group list.
1058 * Return the #DupeItem with the highest rank. If more than one have
1059 * the same rank, the first encountered is used.
1061 static DupeItem *dupe_match_highest_rank(DupeItem *child)
1067 work = child->group;
1070 DupeMatch *dm = work->data;
1071 if (!dr || dm->rank > dr->rank)
1078 return (dr) ? dr->di : NULL;
1082 * @brief Compute and store \a parent->group_rank
1085 * Group_rank = (sum of all child ranks) / n
1087 static void dupe_match_rank_update(DupeItem *parent)
1093 work = parent->group;
1096 DupeMatch *dm = work->data;
1104 parent->group_rank = rank / c;
1108 parent->group_rank = 0.0;
1112 static DupeItem *dupe_match_find_parent(DupeWindow *dw, DupeItem *child)
1116 if (g_list_find(dw->dupes, child)) return child;
1118 work = child->group;
1121 DupeMatch *dm = work->data;
1122 if (g_list_find(dw->dupes, dm->di)) return dm->di;
1131 * @param work (#DupeItem) dw->list or dw->second_list
1133 * Unlink all #DupeItem-s in \a work.
1134 * Do not unlink children.
1136 static void dupe_match_reset_list(GList *work)
1140 DupeItem *di = work->data;
1143 dupe_match_link_clear(di, FALSE);
1147 static void dupe_match_reparent(DupeWindow *dw, DupeItem *old, DupeItem *new)
1151 if (!old || !new || !dupe_match_link_exists(old, new)) return;
1153 dupe_match_link_clear(new, TRUE);
1157 DupeMatch *dm = work->data;
1158 dupe_match_unlink_child(old, dm->di);
1159 dupe_match_link_child(new, dm->di, dm->rank);
1163 new->group = old->group;
1166 work = g_list_find(dw->dupes, old);
1167 if (work) work->data = new;
1170 static void dupe_match_print_group(DupeItem *di)
1174 log_printf("+ %f %s\n", di->group_rank, di->fd->name);
1179 DupeMatch *dm = work->data;
1182 log_printf(" %f %s\n", dm->rank, dm->di->fd->name);
1188 static void dupe_match_print_list(GList *list)
1195 DupeItem *di = work->data;
1196 dupe_match_print_group(di);
1201 /* level 3, unlinking and orphan handling */
1205 * @param parent \a di from \a child->group
1206 * @param[inout] list \a dw->list sorted by rank (#DupeItem)
1208 * @returns modified \a list
1210 * Called for each entry in \a child->group (#DupeMatch) with \a parent set to \a dm->di. \n
1211 * Find the highest rank #DupeItem of the \a parent's children. \n
1212 * If that is == \a child OR
1213 * highest rank #DupeItem of \a child == \a parent then FIXME:
1216 static GList *dupe_match_unlink_by_rank(DupeItem *child, DupeItem *parent, GList *list, DupeWindow *dw)
1218 DupeItem *best = NULL;
1220 best = dupe_match_highest_rank(parent); // highest rank in parent->group
1221 if (best == child || dupe_match_highest_rank(child) == parent)
1226 DEBUG_2("link found %s to %s [%d]", child->fd->name, parent->fd->name, g_list_length(parent->group));
1228 work = parent->group;
1231 DupeMatch *dm = work->data;
1236 if (orphan != child && g_list_length(orphan->group) < 2)
1238 dupe_match_link_clear(orphan, TRUE);
1239 if (!dw->second_set || orphan->second)
1241 dupe_match(orphan, child, dw->match_mask, &rank, FALSE);
1242 dupe_match_link(orphan, child, rank);
1244 list = g_list_remove(list, orphan);
1248 rank = dupe_match_link_rank(child, parent); // child->rank
1249 dupe_match_link_clear(parent, TRUE);
1250 dupe_match_link(child, parent, rank);
1251 list = g_list_remove(list, parent);
1255 DEBUG_2("unlinking %s and %s", child->fd->name, parent->fd->name);
1257 dupe_match_unlink(child, parent);
1266 * @param[inout] list \a dw->list sorted by rank (#DupeItem)
1269 * @returns modified \a list
1271 * Called for each entry in \a list.
1272 * Call unlink for each child in \a di->group
1274 static GList *dupe_match_group_filter(GList *list, DupeItem *di, DupeWindow *dw)
1278 work = g_list_last(di->group);
1281 DupeMatch *dm = work->data;
1283 list = dupe_match_unlink_by_rank(di, dm->di, list, dw);
1292 * @param[inout] list \a dw->list sorted by rank (#DupeItem)
1294 * @returns Filtered \a list
1297 * Call group filter for each \a di in \a list
1299 static GList *dupe_match_group_trim(GList *list, DupeWindow *dw)
1306 DupeItem *di = work->data;
1307 if (!di->second) list = dupe_match_group_filter(list, di, dw);
1309 if (di->second) list = g_list_remove(list, di);
1315 static gint dupe_match_sort_groups_cb(gconstpointer a, gconstpointer b)
1317 DupeMatch *da = (DupeMatch *)a;
1318 DupeMatch *db = (DupeMatch *)b;
1320 if (da->rank > db->rank) return -1;
1321 if (da->rank < db->rank) return 1;
1326 * @brief Sorts the children of each #DupeItem in \a list
1327 * @param list #DupeItem
1329 * Sorts the #DupeItem->group children on rank
1331 static void dupe_match_sort_groups(GList *list)
1338 DupeItem *di = work->data;
1339 di->group = g_list_sort(di->group, dupe_match_sort_groups_cb);
1344 static gint dupe_match_totals_sort_cb(gconstpointer a, gconstpointer b)
1346 DupeItem *da = (DupeItem *)a;
1347 DupeItem *db = (DupeItem *)b;
1349 if (g_list_length(da->group) > g_list_length(db->group)) return -1;
1350 if (g_list_length(da->group) < g_list_length(db->group)) return 1;
1352 if (da->group_rank < db->group_rank) return -1;
1353 if (da->group_rank > db->group_rank) return 1;
1359 * @brief Callback for group_rank sort
1366 static gint dupe_match_rank_sort_cb(gconstpointer a, gconstpointer b)
1368 DupeItem *da = (DupeItem *)a;
1369 DupeItem *db = (DupeItem *)b;
1371 if (da->group_rank > db->group_rank) return -1;
1372 if (da->group_rank < db->group_rank) return 1;
1377 * @brief Sorts \a source_list by group-rank
1378 * @param source_list #DupeItem
1381 * Computes group_rank for each #DupeItem. \n
1382 * Items with no group list are ignored.
1383 * Returns allocated GList of #DupeItem-s sorted by group_rank
1385 static GList *dupe_match_rank_sort(GList *source_list)
1393 DupeItem *di = work->data;
1397 dupe_match_rank_update(di); // Compute and store group_rank for di
1398 list = g_list_prepend(list, di);
1404 return g_list_sort(list, dupe_match_rank_sort_cb);
1408 * @brief Returns allocated GList of dupes sorted by totals
1409 * @param source_list
1414 static GList *dupe_match_totals_sort(GList *source_list)
1416 source_list = g_list_sort(source_list, dupe_match_totals_sort_cb);
1418 source_list = g_list_first(source_list);
1419 return g_list_reverse(source_list);
1428 static void dupe_match_rank(DupeWindow *dw)
1432 list = dupe_match_rank_sort(dw->list); // sorted by group_rank, no-matches filtered out
1434 if (required_debug_level(2)) dupe_match_print_list(list);
1436 DEBUG_1("Similar items: %d", g_list_length(list));
1437 list = dupe_match_group_trim(list, dw);
1438 DEBUG_1("Unique groups: %d", g_list_length(list));
1440 dupe_match_sort_groups(list);
1442 if (required_debug_level(2)) dupe_match_print_list(list);
1444 list = dupe_match_rank_sort(list);
1445 if (options->sort_totals)
1447 list = dupe_match_totals_sort(list);
1449 if (required_debug_level(2)) dupe_match_print_list(list);
1451 g_list_free(dw->dupes);
1456 * ------------------------------------------------------------------
1458 * ------------------------------------------------------------------
1470 * For similarity checks, compute rank - (similarity factor between a and b). \n
1471 * If rank < user-set sim value, returns FALSE.
1473 static gboolean dupe_match(DupeItem *a, DupeItem *b, DupeMatchType mask, gdouble *rank, gint fast)
1477 if (a->fd->path == b->fd->path) return FALSE;
1479 if (mask & DUPE_MATCH_ALL)
1483 if (mask & DUPE_MATCH_PATH)
1485 if (utf8_compare(a->fd->path, b->fd->path, TRUE) != 0) return FALSE;
1487 if (mask & DUPE_MATCH_NAME)
1489 if (strcmp(a->fd->collate_key_name, b->fd->collate_key_name) != 0) return FALSE;
1491 if (mask & DUPE_MATCH_NAME_CI)
1493 if (strcmp(a->fd->collate_key_name_nocase, b->fd->collate_key_name_nocase) != 0) return FALSE;
1495 if (mask & DUPE_MATCH_NAME_CONTENT)
1497 if (strcmp(a->fd->collate_key_name, b->fd->collate_key_name) == 0)
1499 if (!a->md5sum) a->md5sum = md5_text_from_file_utf8(a->fd->path, "");
1500 if (!b->md5sum) b->md5sum = md5_text_from_file_utf8(b->fd->path, "");
1501 if (a->md5sum[0] == '\0' ||
1502 b->md5sum[0] == '\0' ||
1503 strcmp(a->md5sum, b->md5sum) != 0)
1517 if (mask & DUPE_MATCH_NAME_CI_CONTENT)
1519 if (strcmp(a->fd->collate_key_name_nocase, b->fd->collate_key_name_nocase) == 0)
1521 if (!a->md5sum) a->md5sum = md5_text_from_file_utf8(a->fd->path, "");
1522 if (!b->md5sum) b->md5sum = md5_text_from_file_utf8(b->fd->path, "");
1523 if (a->md5sum[0] == '\0' ||
1524 b->md5sum[0] == '\0' ||
1525 strcmp(a->md5sum, b->md5sum) != 0)
1539 if (mask & DUPE_MATCH_SIZE)
1541 if (a->fd->size != b->fd->size) return FALSE;
1543 if (mask & DUPE_MATCH_DATE)
1545 if (a->fd->date != b->fd->date) return FALSE;
1547 if (mask & DUPE_MATCH_SUM)
1549 if (!a->md5sum) a->md5sum = md5_text_from_file_utf8(a->fd->path, "");
1550 if (!b->md5sum) b->md5sum = md5_text_from_file_utf8(b->fd->path, "");
1551 if (a->md5sum[0] == '\0' ||
1552 b->md5sum[0] == '\0' ||
1553 strcmp(a->md5sum, b->md5sum) != 0) return FALSE;
1555 if (mask & DUPE_MATCH_DIM)
1557 if (a->width == 0) image_load_dimensions(a->fd, &a->width, &a->height);
1558 if (b->width == 0) image_load_dimensions(b->fd, &b->width, &b->height);
1559 if (a->width != b->width || a->height != b->height) return FALSE;
1561 if (mask & DUPE_MATCH_SIM_HIGH ||
1562 mask & DUPE_MATCH_SIM_MED ||
1563 mask & DUPE_MATCH_SIM_LOW ||
1564 mask & DUPE_MATCH_SIM_CUSTOM)
1569 if (mask & DUPE_MATCH_SIM_HIGH) m = 0.95;
1570 else if (mask & DUPE_MATCH_SIM_MED) m = 0.90;
1571 else if (mask & DUPE_MATCH_SIM_CUSTOM) m = (gdouble)options->duplicates_similarity_threshold / 100.0;
1576 f = image_sim_compare_fast(a->simd, b->simd, m);
1580 f = image_sim_compare(a->simd, b->simd);
1585 if (f < m) return FALSE;
1587 DEBUG_3("similar: %32s %32s = %f", a->fd->name, b->fd->name, f);
1594 * @brief Determine if there is a match
1598 * @returns DUPE_MATCH/DUPE_NO_MATCH/DUPE_NAME_MATCH
1599 * DUPE_NAME_MATCH is used for name != contents searches:
1600 * the name and content match i.e.
1601 * no match, but keep searching
1603 * Called when stepping down the array looking for adjacent matches,
1604 * and from the 2nd set search.
1606 * Is not used for similarity checks.
1608 static DUPE_CHECK_RESULT dupe_match_check(DupeItem *di1, DupeItem *di2, gpointer data)
1610 DupeWindow *dw = data;
1611 DupeMatchType mask = dw->match_mask;
1613 if (mask & DUPE_MATCH_ALL)
1617 if (mask & DUPE_MATCH_PATH)
1619 if (utf8_compare(di1->fd->path, di2->fd->path, TRUE) != 0)
1621 return DUPE_NO_MATCH;
1624 if (mask & DUPE_MATCH_NAME)
1626 if (g_strcmp0(di1->fd->collate_key_name, di2->fd->collate_key_name) != 0)
1628 return DUPE_NO_MATCH;
1631 if (mask & DUPE_MATCH_NAME_CI)
1633 if (g_strcmp0(di1->fd->collate_key_name_nocase, di2->fd->collate_key_name_nocase) != 0 )
1635 return DUPE_NO_MATCH;
1638 if (mask & DUPE_MATCH_NAME_CONTENT)
1640 if (g_strcmp0(di1->fd->collate_key_name, di2->fd->collate_key_name) == 0)
1642 if (g_strcmp0(di1->md5sum, di2->md5sum) == 0)
1644 return DUPE_NAME_MATCH;
1649 return DUPE_NO_MATCH;
1652 if (mask & DUPE_MATCH_NAME_CI_CONTENT)
1654 if (strcmp(di1->fd->collate_key_name_nocase, di2->fd->collate_key_name_nocase) == 0)
1656 if (g_strcmp0(di1->md5sum, di2->md5sum) == 0)
1658 return DUPE_NAME_MATCH;
1663 return DUPE_NO_MATCH;
1666 if (mask & DUPE_MATCH_SIZE)
1668 if (di1->fd->size != di2->fd->size)
1670 return DUPE_NO_MATCH;
1673 if (mask & DUPE_MATCH_DATE)
1675 if (di1->fd->date != di2->fd->date)
1677 return DUPE_NO_MATCH;
1680 if (mask & DUPE_MATCH_SUM)
1682 if (g_strcmp0(di1->md5sum, di2->md5sum) != 0)
1684 return DUPE_NO_MATCH;
1687 if (mask & DUPE_MATCH_DIM)
1689 if (di1->dimensions != di2->dimensions)
1691 return DUPE_NO_MATCH;
1699 * @brief The callback for the binary search
1702 * @param param_match_mask
1703 * @returns negative/0/positive
1705 * Is not used for similarity checks.
1707 * Used only when two file sets are used.
1708 * Requires use of a global for param_match_mask because there is no
1709 * g_array_binary_search_with_data() function in glib.
1711 static gint dupe_match_binary_search_cb(gconstpointer a, gconstpointer b)
1713 const DupeItem *di1 = *((DupeItem **) a);
1714 const DupeItem *di2 = b;
1715 DupeMatchType mask = param_match_mask;
1717 if (mask & DUPE_MATCH_ALL)
1721 if (mask & DUPE_MATCH_PATH)
1723 return utf8_compare(di1->fd->path, di2->fd->path, TRUE);
1725 if (mask & DUPE_MATCH_NAME)
1727 return g_strcmp0(di1->fd->collate_key_name, di2->fd->collate_key_name);
1729 if (mask & DUPE_MATCH_NAME_CI)
1731 return strcmp(di1->fd->collate_key_name_nocase, di2->fd->collate_key_name_nocase);
1733 if (mask & DUPE_MATCH_NAME_CONTENT)
1735 return g_strcmp0(di1->fd->collate_key_name, di2->fd->collate_key_name);
1737 if (mask & DUPE_MATCH_NAME_CI_CONTENT)
1739 return strcmp(di1->fd->collate_key_name_nocase, di2->fd->collate_key_name_nocase);
1741 if (mask & DUPE_MATCH_SIZE)
1743 return (di1->fd->size - di2->fd->size);
1745 if (mask & DUPE_MATCH_DATE)
1747 return (di1->fd->date - di2->fd->date);
1749 if (mask & DUPE_MATCH_SUM)
1751 return g_strcmp0(di1->md5sum, di2->md5sum);
1753 if (mask & DUPE_MATCH_DIM)
1755 return (di1->dimensions - di2->dimensions);
1762 * @brief The callback for the array sort
1766 * @returns negative/0/positive
1768 * Is not used for similarity checks.
1770 static gint dupe_match_sort_cb(gconstpointer a, gconstpointer b, gpointer data)
1772 const DupeItem *di1 = *((DupeItem **) a);
1773 const DupeItem *di2 = *((DupeItem **) b);
1774 DupeWindow *dw = data;
1775 DupeMatchType mask = dw->match_mask;
1777 if (mask & DUPE_MATCH_ALL)
1781 if (mask & DUPE_MATCH_PATH)
1783 return utf8_compare(di1->fd->path, di2->fd->path, TRUE);
1785 if (mask & DUPE_MATCH_NAME)
1787 return g_strcmp0(di1->fd->collate_key_name, di2->fd->collate_key_name);
1789 if (mask & DUPE_MATCH_NAME_CI)
1791 return strcmp(di1->fd->collate_key_name_nocase, di2->fd->collate_key_name_nocase);
1793 if (mask & DUPE_MATCH_NAME_CONTENT)
1795 return g_strcmp0(di1->fd->collate_key_name, di2->fd->collate_key_name);
1797 if (mask & DUPE_MATCH_NAME_CI_CONTENT)
1799 return strcmp(di1->fd->collate_key_name_nocase, di2->fd->collate_key_name_nocase);
1801 if (mask & DUPE_MATCH_SIZE)
1803 return (di1->fd->size - di2->fd->size);
1805 if (mask & DUPE_MATCH_DATE)
1807 return (di1->fd->date - di2->fd->date);
1809 if (mask & DUPE_MATCH_SUM)
1811 if (di1->md5sum[0] == '\0' || di2->md5sum[0] == '\0')
1817 return strcmp(di1->md5sum, di2->md5sum);
1820 if (mask & DUPE_MATCH_DIM)
1822 if (!di1 || !di2 || !di1->width || !di1->height || !di2->width || !di2->height)
1826 return (di1->dimensions - di2->dimensions);
1829 return 0; // should not execute
1833 * @brief Check for duplicate matches
1836 * Is not used for similarity checks.
1838 * Loads the file sets into an array and sorts on the searched
1841 * If one file set, steps down the array looking for adjacent equal values.
1843 * If two file sets, steps down the first set and for each value
1844 * does a binary search for matches in the second set.
1846 static void dupe_array_check(DupeWindow *dw )
1853 DUPE_CHECK_RESULT check_result;
1854 param_match_mask = dw->match_mask;
1855 guint out_match_index;
1856 gboolean match_found = FALSE;;
1858 if (!dw->list) return;
1860 array_set1 = g_array_new(TRUE, TRUE, sizeof(gpointer));
1861 array_set2 = g_array_new(TRUE, TRUE, sizeof(gpointer));
1862 dupe_match_reset_list(dw->list);
1867 DupeItem *di = work->data;
1868 g_array_append_val(array_set1, di);
1872 g_array_sort_with_data(array_set1, dupe_match_sort_cb, dw);
1876 /* Two sets - nothing can be done until a second set is loaded */
1877 if (dw->second_list)
1879 work = dw->second_list;
1882 g_array_append_val(array_set2, (work->data));
1885 g_array_sort_with_data(array_set2, dupe_match_sort_cb, dw);
1887 for (i_set1 = 0; i_set1 <= (gint)(array_set1->len) - 1; i_set1++)
1889 DupeItem *di1 = g_array_index(array_set1, gpointer, i_set1);
1890 DupeItem *di2 = NULL;
1891 /* If multiple identical entries in set 1, use the last one */
1892 if (i_set1 < (gint)(array_set1->len) - 2)
1894 di2 = g_array_index(array_set1, gpointer, i_set1 + 1);
1895 check_result = dupe_match_check(di1, di2, dw);
1896 if (check_result == DUPE_MATCH || check_result == DUPE_NAME_MATCH)
1902 #if ((GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION >= 62))
1903 match_found = g_array_binary_search(array_set2, di1, dupe_match_binary_search_cb, &out_match_index);
1907 match_found = FALSE;
1908 for(i=0; i < array_set2->len; i++)
1910 di2 = g_array_index(array_set2, gpointer, i);
1911 check_result = dupe_match_check(di1, di2, dw);
1912 if (check_result == DUPE_MATCH)
1915 out_match_index = i;
1923 di2 = g_array_index(array_set2, gpointer, out_match_index);
1925 check_result = dupe_match_check(di1, di2, dw);
1926 if (check_result == DUPE_MATCH || check_result == DUPE_NAME_MATCH)
1928 if (check_result == DUPE_MATCH)
1930 dupe_match_link(di2, di1, 0.0);
1932 i_set2 = out_match_index + 1;
1934 if (i_set2 > (gint)(array_set2->len) - 1)
1938 /* Look for multiple matches in set 2 for item di1 */
1939 di2 = g_array_index(array_set2, gpointer, i_set2);
1940 check_result = dupe_match_check(di1, di2, dw);
1941 while (check_result == DUPE_MATCH || check_result == DUPE_NAME_MATCH)
1943 if (check_result == DUPE_MATCH)
1945 dupe_match_link(di2, di1, 0.0);
1948 if (i_set2 > (gint)(array_set2->len) - 1)
1952 di2 = g_array_index(array_set2, gpointer, i_set2);
1953 check_result = dupe_match_check(di1, di2, dw);
1962 /* File set 1 only */
1963 g_list_free(dw->dupes);
1966 if ((gint)(array_set1->len) > 1)
1968 for (i_set1 = 0; i_set1 <= (gint)(array_set1->len) - 2; i_set1++)
1970 DupeItem *di1 = g_array_index(array_set1, gpointer, i_set1);
1971 DupeItem *di2 = g_array_index(array_set1, gpointer, i_set1 + 1);
1973 check_result = dupe_match_check(di1, di2, dw);
1974 if (check_result == DUPE_MATCH || check_result == DUPE_NAME_MATCH)
1976 if (check_result == DUPE_MATCH)
1978 dupe_match_link(di2, di1, 0.0);
1982 if ( i_set1 + 1 > (gint)(array_set1->len) - 1)
1986 /* Look for multiple matches for item di1 */
1987 di2 = g_array_index(array_set1, gpointer, i_set1 + 1);
1988 check_result = dupe_match_check(di1, di2, dw);
1989 while (check_result == DUPE_MATCH || check_result == DUPE_NAME_MATCH)
1991 if (check_result == DUPE_MATCH)
1993 dupe_match_link(di2, di1, 0.0);
1997 if (i_set1 + 1 > (gint)(array_set1->len) - 1)
2001 di2 = g_array_index(array_set1, gpointer, i_set1 + 1);
2002 check_result = dupe_match_check(di1, di2, dw);
2008 g_array_free(array_set1, TRUE);
2009 g_array_free(array_set2, TRUE);
2013 * @brief Look for similarity match
2018 * Only used for similarity checks.\n
2019 * Called from dupe_check_cb.
2020 * Called for each entry in the list.
2021 * Steps through the list looking for matches against needle.
2022 * Pushes a #DupeQueueItem onto thread pool queue.
2024 static void dupe_list_check_match(DupeWindow *dw, DupeItem *needle, GList *start)
2031 work = dw->second_list;
2039 work = g_list_last(dw->list);
2042 dqi = g_new0(DupeQueueItem, 1);
2043 dqi->needle = needle;
2046 dqi->index = dw->queue_count;
2047 g_thread_pool_push(dw->dupe_comparison_thread_pool, dqi, NULL);
2051 * ------------------------------------------------------------------
2052 * Thumbnail handling
2053 * ------------------------------------------------------------------
2056 static void dupe_listview_set_thumb(DupeWindow *dw, DupeItem *di, GtkTreeIter *iter)
2058 GtkListStore *store;
2061 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dw->listview)));
2064 if (dupe_listview_find_item(store, di, &iter_n) >= 0)
2070 if (iter) gtk_list_store_set(store, iter, DUPE_COLUMN_THUMB, di->pixbuf, -1);
2073 static void dupe_thumb_do(DupeWindow *dw)
2077 if (!dw->thumb_loader || !dw->thumb_item) return;
2078 di = dw->thumb_item;
2080 if (di->pixbuf) g_object_unref(di->pixbuf);
2081 di->pixbuf = thumb_loader_get_pixbuf(dw->thumb_loader);
2083 dupe_listview_set_thumb(dw, di, NULL);
2086 static void dupe_thumb_error_cb(ThumbLoader *tl, gpointer data)
2088 DupeWindow *dw = data;
2091 dupe_thumb_step(dw);
2094 static void dupe_thumb_done_cb(ThumbLoader *tl, gpointer data)
2096 DupeWindow *dw = data;
2099 dupe_thumb_step(dw);
2102 static void dupe_thumb_step(DupeWindow *dw)
2104 GtkTreeModel *store;
2106 DupeItem *di = NULL;
2111 store = gtk_tree_view_get_model(GTK_TREE_VIEW(dw->listview));
2112 valid = gtk_tree_model_get_iter_first(store, &iter);
2114 while (!di && valid)
2119 gtk_tree_model_get(store, &iter, DUPE_COLUMN_POINTER, &di, DUPE_COLUMN_THUMB, &pixbuf, -1);
2120 if (pixbuf || di->pixbuf)
2122 if (!pixbuf) gtk_list_store_set(GTK_LIST_STORE(store), &iter, DUPE_COLUMN_THUMB, di->pixbuf, -1);
2126 valid = gtk_tree_model_iter_next(store, &iter);
2130 while (gtk_tree_model_iter_next(store, &iter)) length++;
2135 dw->thumb_item = NULL;
2136 thumb_loader_free(dw->thumb_loader);
2137 dw->thumb_loader = NULL;
2139 dupe_window_update_progress(dw, NULL, 0.0, FALSE);
2143 dupe_window_update_progress(dw, _("Loading thumbs..."),
2144 length == 0 ? 0.0 : (gdouble)(row) / length, FALSE);
2146 dw->thumb_item = di;
2147 thumb_loader_free(dw->thumb_loader);
2148 dw->thumb_loader = thumb_loader_new(options->thumbnails.max_width, options->thumbnails.max_height);
2150 thumb_loader_set_callbacks(dw->thumb_loader,
2152 dupe_thumb_error_cb,
2157 if (!thumb_loader_start(dw->thumb_loader, di->fd))
2159 /* error, handle it, do next */
2160 DEBUG_1("error loading thumb for %s", di->fd->path);
2162 dupe_thumb_step(dw);
2167 * ------------------------------------------------------------------
2168 * Dupe checking loop
2169 * ------------------------------------------------------------------
2172 static void dupe_check_stop(DupeWindow *dw)
2174 if (dw->idle_id > 0)
2176 g_source_remove(dw->idle_id);
2182 while (dw->thread_count < dw->queue_count) // Wait for the queue to empty
2184 dupe_window_update_progress(dw, NULL, 0.0, FALSE);
2185 widget_set_cursor(dw->listview, -1);
2188 g_list_free(dw->search_matches);
2189 dw->search_matches = NULL;
2191 if (dw->idle_id || dw->img_loader || dw->thumb_loader)
2193 if (dw->idle_id > 0)
2195 g_source_remove(dw->idle_id);
2198 dupe_window_update_progress(dw, NULL, 0.0, FALSE);
2199 widget_set_cursor(dw->listview, -1);
2202 if (dw->add_files_queue_id)
2204 g_source_remove(dw->add_files_queue_id);
2205 dw->add_files_queue_id = 0;
2206 dupe_destroy_list_cache(dw);
2207 gtk_widget_set_sensitive(dw->controls_box, TRUE);
2208 if (g_list_length(dw->add_files_queue) > 0)
2210 filelist_free(dw->add_files_queue);
2212 dw->add_files_queue = NULL;
2213 dupe_window_update_progress(dw, NULL, 0.0, FALSE);
2214 widget_set_cursor(dw->listview, -1);
2217 thumb_loader_free(dw->thumb_loader);
2218 dw->thumb_loader = NULL;
2220 image_loader_free(dw->img_loader);
2221 dw->img_loader = NULL;
2224 static void dupe_check_stop_cb(GtkWidget *widget, gpointer data)
2226 DupeWindow *dw = data;
2228 dupe_check_stop(dw);
2231 static void dupe_loader_done_cb(ImageLoader *il, gpointer data)
2233 DupeWindow *dw = data;
2236 pixbuf = image_loader_get_pixbuf(il);
2238 if (dw->setup_point)
2240 DupeItem *di = dw->setup_point->data;
2244 di->simd = image_sim_new_from_pixbuf(pixbuf);
2248 image_sim_fill_data(di->simd, pixbuf);
2251 if (di->width == 0 && di->height == 0)
2253 di->width = gdk_pixbuf_get_width(pixbuf);
2254 di->height = gdk_pixbuf_get_height(pixbuf);
2256 if (options->thumbnails.enable_caching)
2258 dupe_item_write_cache(di);
2261 image_sim_alternate_processing(di->simd);
2264 image_loader_free(dw->img_loader);
2265 dw->img_loader = NULL;
2267 dw->idle_id = g_idle_add(dupe_check_cb, dw);
2270 static void dupe_setup_reset(DupeWindow *dw)
2272 dw->setup_point = NULL;
2274 dw->setup_time = msec_time();
2275 dw->setup_time_count = 0;
2278 static GList *dupe_setup_point_step(DupeWindow *dw, GList *p)
2280 if (!p) return NULL;
2282 if (p->next) return p->next;
2284 if (dw->second_set && g_list_first(p) == dw->list) return dw->second_list;
2290 * @brief Generates the sumcheck or dimensions
2291 * @param list Set1 or set2
2292 * @returns TRUE/FALSE = not completed/completed
2294 * Ensures that the DIs contain the MD5SUM or dimensions for all items in
2295 * the list. One item at a time. Re-enters if not completed.
2297 static gboolean create_checksums_dimensions(DupeWindow *dw, GList *list)
2299 if ((dw->match_mask & DUPE_MATCH_SUM) ||
2300 (dw->match_mask & DUPE_MATCH_NAME_CONTENT) ||
2301 (dw->match_mask & DUPE_MATCH_NAME_CI_CONTENT))
2304 if (!dw->setup_point) dw->setup_point = list; // setup_point clear on 1st entry
2306 while (dw->setup_point)
2308 DupeItem *di = dw->setup_point->data;
2310 dw->setup_point = dupe_setup_point_step(dw, dw->setup_point);
2315 dupe_window_update_progress(dw, _("Reading checksums..."),
2316 dw->setup_count == 0 ? 0.0 : (gdouble)(dw->setup_n - 1) / dw->setup_count, FALSE);
2318 if (options->thumbnails.enable_caching)
2320 dupe_item_read_cache(di);
2327 di->md5sum = md5_text_from_file_utf8(di->fd->path, "");
2328 if (options->thumbnails.enable_caching)
2330 dupe_item_write_cache(di);
2335 dupe_setup_reset(dw);
2338 if ((dw->match_mask & DUPE_MATCH_DIM) )
2340 /* Dimensions only */
2341 if (!dw->setup_point) dw->setup_point = list;
2343 while (dw->setup_point)
2345 DupeItem *di = dw->setup_point->data;
2347 dw->setup_point = dupe_setup_point_step(dw, dw->setup_point);
2349 if (di->width == 0 && di->height == 0)
2351 dupe_window_update_progress(dw, _("Reading dimensions..."),
2352 dw->setup_count == 0 ? 0.0 : (gdouble)(dw->setup_n - 1) / dw->setup_count, FALSE);
2354 if (options->thumbnails.enable_caching)
2356 dupe_item_read_cache(di);
2357 if (di->width != 0 || di->height != 0)
2363 image_load_dimensions(di->fd, &di->width, &di->height);
2364 di->dimensions = (di->width << 16) + di->height;
2365 if (options->thumbnails.enable_caching)
2367 dupe_item_write_cache(di);
2372 dupe_setup_reset(dw);
2379 * @brief Compare func. for sorting search matches
2380 * @param a #DupeSearchMatch
2381 * @param b #DupeSearchMatch
2384 * Used only for similarity checks\n
2385 * Sorts search matches on order they were inserted into the pool queue
2387 static gint sort_func(gconstpointer a, gconstpointer b)
2389 return (((DupeSearchMatch *)a)->index - ((DupeSearchMatch *)b)->index);
2393 * @brief Check set 1 (and set 2) for matches
2394 * @param data DupeWindow
2395 * @returns TRUE/FALSE = not completed/completed
2397 * Initiated from start, loader done and item remove
2399 * On first entry generates di->MD5SUM, di->dimensions and sim data,
2400 * and updates the cache.
2402 static gboolean dupe_check_cb(gpointer data)
2404 DupeWindow *dw = data;
2405 DupeSearchMatch *search_match_list_item;
2412 if (!dw->setup_done) /* Clear on 1st entry */
2416 if (create_checksums_dimensions(dw, dw->list))
2421 if (dw->second_list)
2423 if (create_checksums_dimensions(dw, dw->second_list))
2428 if ((dw->match_mask & DUPE_MATCH_SIM_HIGH ||
2429 dw->match_mask & DUPE_MATCH_SIM_MED ||
2430 dw->match_mask & DUPE_MATCH_SIM_LOW ||
2431 dw->match_mask & DUPE_MATCH_SIM_CUSTOM) &&
2432 !(dw->setup_mask & DUPE_MATCH_SIM_MED) )
2434 /* Similarity only */
2435 if (!dw->setup_point) dw->setup_point = dw->list;
2437 while (dw->setup_point)
2439 DupeItem *di = dw->setup_point->data;
2443 dupe_window_update_progress(dw, _("Reading similarity data..."),
2444 dw->setup_count == 0 ? 0.0 : (gdouble)dw->setup_n / dw->setup_count, FALSE);
2446 if (options->thumbnails.enable_caching)
2448 dupe_item_read_cache(di);
2449 if (cache_sim_data_filled(di->simd))
2451 image_sim_alternate_processing(di->simd);
2456 dw->img_loader = image_loader_new(di->fd);
2457 image_loader_set_buffer_size(dw->img_loader, 8);
2458 g_signal_connect(G_OBJECT(dw->img_loader), "error", (GCallback)dupe_loader_done_cb, dw);
2459 g_signal_connect(G_OBJECT(dw->img_loader), "done", (GCallback)dupe_loader_done_cb, dw);
2461 if (!image_loader_start(dw->img_loader))
2463 image_sim_free(di->simd);
2464 di->simd = image_sim_new();
2465 image_loader_free(dw->img_loader);
2466 dw->img_loader = NULL;
2473 dw->setup_point = dupe_setup_point_step(dw, dw->setup_point);
2476 dw->setup_mask |= DUPE_MATCH_SIM_MED;
2477 dupe_setup_reset(dw);
2480 /* End of setup not done */
2481 dupe_window_update_progress(dw, _("Comparing..."), 0.0, FALSE);
2482 dw->setup_done = TRUE;
2483 dupe_setup_reset(dw);
2484 dw->setup_count = g_list_length(dw->list);
2487 /* Setup done - dw->working set to NULL below
2488 * Set before 1st entry: dw->working = g_list_last(dw->list)
2489 * Set before 1st entry: dw->setup_count = g_list_length(dw->list)
2493 /* Similarity check threads may still be running */
2494 if (dw->setup_count > 0 && (dw->match_mask == DUPE_MATCH_SIM_HIGH ||
2495 dw->match_mask == DUPE_MATCH_SIM_MED ||
2496 dw->match_mask == DUPE_MATCH_SIM_LOW ||
2497 dw->match_mask == DUPE_MATCH_SIM_CUSTOM))
2499 if( dw->thread_count < dw->queue_count)
2501 dupe_window_update_progress(dw, _("Comparing..."), 0.0, FALSE);
2506 if (dw->search_matches_sorted == NULL)
2508 dw->search_matches_sorted = g_list_sort(dw->search_matches, sort_func);
2509 dupe_setup_reset(dw);
2512 while (dw->search_matches_sorted)
2515 dupe_window_update_progress(dw, _("Sorting..."), 0.0, FALSE);
2516 search_match_list_item = dw->search_matches_sorted->data;
2518 if (!dupe_match_link_exists(search_match_list_item->a, search_match_list_item->b))
2520 dupe_match_link(search_match_list_item->a, search_match_list_item->b, search_match_list_item->rank);
2523 dw->search_matches_sorted = dw->search_matches_sorted->next;
2525 if (dw->search_matches_sorted != NULL)
2530 g_list_free(dw->search_matches);
2531 dw->search_matches = NULL;
2532 g_list_free(dw->search_matches_sorted);
2533 dw->search_matches_sorted = NULL;
2534 dw->setup_count = 0;
2538 if (dw->setup_count > 0)
2540 dw->setup_count = 0;
2541 dupe_window_update_progress(dw, _("Sorting..."), 1.0, TRUE);
2547 dupe_window_update_progress(dw, NULL, 0.0, FALSE);
2549 dupe_match_rank(dw);
2550 dupe_window_update_count(dw, FALSE);
2552 dupe_listview_populate(dw);
2555 if (dw->show_thumbs) dupe_thumb_step(dw);
2557 widget_set_cursor(dw->listview, -1);
2563 /* Setup done - working */
2564 if (dw->match_mask == DUPE_MATCH_SIM_HIGH ||
2565 dw->match_mask == DUPE_MATCH_SIM_MED ||
2566 dw->match_mask == DUPE_MATCH_SIM_LOW ||
2567 dw->match_mask == DUPE_MATCH_SIM_CUSTOM)
2569 /* This is the similarity comparison */
2570 dupe_list_check_match(dw, (DupeItem *)dw->working->data, dw->working);
2571 dupe_window_update_progress(dw, _("Queuing..."), dw->setup_count == 0 ? 0.0 : (gdouble) dw->setup_n / dw->setup_count, FALSE);
2575 dw->working = dw->working->prev; /* Is NULL when complete */
2579 /* This is the comparison for all other parameters.
2580 * dupe_array_check() processes the entire list in one go
2583 dupe_window_update_progress(dw, _("Comparing..."), 0.0, FALSE);
2584 dupe_array_check(dw);
2590 static void dupe_check_start(DupeWindow *dw)
2592 dw->setup_done = FALSE;
2594 dw->setup_count = g_list_length(dw->list);
2595 if (dw->second_set) dw->setup_count += g_list_length(dw->second_list);
2598 dupe_setup_reset(dw);
2600 dw->working = g_list_last(dw->list);
2602 dupe_window_update_count(dw, TRUE);
2603 widget_set_cursor(dw->listview, GDK_WATCH);
2604 dw->queue_count = 0;
2605 dw->thread_count = 0;
2606 dw->search_matches_sorted = NULL;
2609 if (dw->idle_id) return;
2611 dw->idle_id = g_idle_add(dupe_check_cb, dw);
2614 static gboolean dupe_check_start_cb(gpointer data)
2616 DupeWindow *dw = data;
2618 dupe_check_start(dw);
2624 * ------------------------------------------------------------------
2625 * Item addition, removal
2626 * ------------------------------------------------------------------
2629 static void dupe_item_remove(DupeWindow *dw, DupeItem *di)
2633 /* handle things that may be in progress... */
2634 if (dw->working && dw->working->data == di)
2636 dw->working = dw->working->prev;
2638 if (dw->thumb_loader && dw->thumb_item == di)
2640 dupe_thumb_step(dw);
2642 if (dw->setup_point && dw->setup_point->data == di)
2644 dw->setup_point = dupe_setup_point_step(dw, dw->setup_point);
2647 image_loader_free(dw->img_loader);
2648 dw->img_loader = NULL;
2649 dw->idle_id = g_idle_add(dupe_check_cb, dw);
2653 if (di->group && dw->dupes)
2655 /* is a dupe, must remove from group/reset children if a parent */
2658 parent = dupe_match_find_parent(dw, di);
2661 if (g_list_length(parent->group) < 2)
2665 child = dupe_match_highest_rank(parent);
2666 dupe_match_link_clear(child, TRUE);
2667 dupe_listview_remove(dw, child);
2669 dupe_match_link_clear(parent, TRUE);
2670 dupe_listview_remove(dw, parent);
2671 dw->dupes = g_list_remove(dw->dupes, parent);
2675 DupeItem *new_parent;
2678 dm = parent->group->data;
2679 new_parent = dm->di;
2680 dupe_match_reparent(dw, parent, new_parent);
2681 dupe_listview_remove(dw, parent);
2686 if (g_list_length(parent->group) < 2)
2688 dupe_match_link_clear(parent, TRUE);
2689 dupe_listview_remove(dw, parent);
2690 dw->dupes = g_list_remove(dw->dupes, parent);
2692 dupe_match_link_clear(di, TRUE);
2693 dupe_listview_remove(dw, di);
2698 /* not a dupe, or not sorted yet, simply reset */
2699 dupe_match_link_clear(di, TRUE);
2702 if (dw->second_list && g_list_find(dw->second_list, di))
2704 dupe_second_remove(dw, di);
2708 dw->list = g_list_remove(dw->list, di);
2712 dupe_window_update_count(dw, FALSE);
2716 static gboolean dupe_item_remove_by_path(DupeWindow *dw, const gchar *path)
2720 di = dupe_item_find_path(dw, path);
2721 if (!di) return FALSE;
2723 dupe_item_remove(dw, di);
2729 static gboolean dupe_files_add_queue_cb(gpointer data)
2731 DupeItem *di = NULL;
2732 DupeWindow *dw = data;
2734 GList *queue = dw->add_files_queue;
2736 gtk_progress_bar_pulse(GTK_PROGRESS_BAR(dw->extra_label));
2740 dw->add_files_queue_id = 0;
2741 dupe_destroy_list_cache(dw);
2742 g_idle_add(dupe_check_start_cb, dw);
2743 gtk_widget_set_sensitive(dw->controls_box, TRUE);
2750 if (isfile(fd->path))
2752 di = dupe_item_new(fd);
2754 else if (isdir(fd->path))
2757 dw->add_files_queue = g_list_remove(dw->add_files_queue, g_list_first(dw->add_files_queue)->data);
2759 if (filelist_read(fd, &f, &d))
2761 f = filelist_filter(f, FALSE);
2762 d = filelist_filter(d, TRUE);
2764 dw->add_files_queue = g_list_concat(f, dw->add_files_queue);
2765 dw->add_files_queue = g_list_concat(d, dw->add_files_queue);
2770 /* Not a file and not a dir */
2771 dw->add_files_queue = g_list_remove(dw->add_files_queue, g_list_first(dw->add_files_queue)->data);
2777 /* A dir was found. Process the contents on next entry */
2781 dw->add_files_queue = g_list_remove(dw->add_files_queue, g_list_first(dw->add_files_queue)->data);
2783 dupe_item_read_cache(di);
2785 /* Ensure images in the lists have unique FileDatas */
2786 if (!dupe_insert_in_list_cache(dw, di->fd))
2792 if (dw->second_drop)
2794 dupe_second_add(dw, di);
2798 dw->list = g_list_prepend(dw->list, di);
2801 if (dw->add_files_queue != NULL)
2807 dw->add_files_queue_id = 0;
2808 dupe_destroy_list_cache(dw);
2809 g_idle_add(dupe_check_start_cb, dw);
2810 gtk_widget_set_sensitive(dw->controls_box, TRUE);
2815 static void dupe_files_add(DupeWindow *dw, CollectionData *collection, CollectInfo *info,
2816 FileData *fd, gboolean recurse)
2818 DupeItem *di = NULL;
2822 di = dupe_item_new(info->fd);
2826 if (isfile(fd->path) && !g_file_test(fd->path, G_FILE_TEST_IS_SYMLINK))
2828 di = dupe_item_new(fd);
2830 else if (isdir(fd->path) && recurse)
2833 if (filelist_read(fd, &f, &d))
2837 f = filelist_filter(f, FALSE);
2838 d = filelist_filter(d, TRUE);
2843 dupe_files_add(dw, NULL, NULL, (FileData *)work->data, TRUE);
2850 dupe_files_add(dw, NULL, NULL, (FileData *)work->data, TRUE);
2860 dupe_item_read_cache(di);
2862 /* Ensure images in the lists have unique FileDatas */
2865 work = g_list_first(dw->list);
2868 di_list = work->data;
2869 if (di_list->fd == di->fd)
2879 if (dw->second_list)
2881 work = g_list_first(dw->second_list);
2884 di_list = work->data;
2885 if (di_list->fd == di->fd)
2896 if (dw->second_drop)
2898 dupe_second_add(dw, di);
2902 dw->list = g_list_prepend(dw->list, di);
2906 static void dupe_init_list_cache(DupeWindow *dw)
2908 dw->list_cache = g_hash_table_new(g_direct_hash, g_direct_equal);
2909 dw->second_list_cache = g_hash_table_new(g_direct_hash, g_direct_equal);
2911 for (GList *i = dw->list; i != NULL; i = i->next)
2913 DupeItem *di = i->data;
2915 g_hash_table_add(dw->list_cache, di->fd);
2918 for (GList *i = dw->second_list; i != NULL; i = i->next)
2920 DupeItem *di = i->data;
2922 g_hash_table_add(dw->second_list_cache, di->fd);
2926 static void dupe_destroy_list_cache(DupeWindow *dw)
2928 g_hash_table_destroy(dw->list_cache);
2929 g_hash_table_destroy(dw->second_list_cache);
2933 * @brief Return true if the fd was not in the cache
2940 static gboolean dupe_insert_in_list_cache(DupeWindow *dw, FileData *fd)
2943 dw->second_drop ? dw->second_list_cache : dw->list_cache;
2944 /* We do this as a lookup + add as we don't want to overwrite
2945 items as that would leak the old value. */
2946 if (g_hash_table_lookup(table, fd) != NULL)
2948 return g_hash_table_add(table, fd);
2951 void dupe_window_add_collection(DupeWindow *dw, CollectionData *collection)
2955 info = collection_get_first(collection);
2958 dupe_files_add(dw, collection, info, NULL, FALSE);
2959 info = collection_next_by_info(collection, info);
2962 dupe_check_start(dw);
2965 void dupe_window_add_files(DupeWindow *dw, GList *list, gboolean recurse)
2972 FileData *fd = work->data;
2974 if (isdir(fd->path) && !recurse)
2978 if (filelist_read(fd, &f, &d))
2985 /* Add only the files, ignore the dirs when no recurse */
2986 dw->add_files_queue = g_list_prepend(dw->add_files_queue, work_file->data);
2987 work_file = work_file->next;
2995 dw->add_files_queue = g_list_prepend(dw->add_files_queue, fd);
2998 if (dw->add_files_queue_id == 0)
3000 gtk_progress_bar_pulse(GTK_PROGRESS_BAR(dw->extra_label));
3001 gtk_progress_bar_set_pulse_step(GTK_PROGRESS_BAR(dw->extra_label), DUPE_PROGRESS_PULSE_STEP);
3002 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(dw->extra_label), _("Loading file list"));
3004 dupe_init_list_cache(dw);
3005 dw->add_files_queue_id = g_idle_add(dupe_files_add_queue_cb, dw);
3006 gtk_widget_set_sensitive(dw->controls_box, FALSE);
3010 static void dupe_item_update(DupeWindow *dw, DupeItem *di)
3012 if ( (dw->match_mask & DUPE_MATCH_NAME) || (dw->match_mask & DUPE_MATCH_PATH || (dw->match_mask & DUPE_MATCH_NAME_CI)) )
3014 /* only effects matches on name or path */
3016 FileData *fd = file_data_ref(di->fd);
3019 second = di->second;
3020 dupe_item_remove(dw, di);
3022 dw->second_drop = second;
3023 dupe_files_add(dw, NULL, NULL, fd, FALSE);
3024 dw->second_drop = FALSE;
3026 file_data_unref(fd);
3028 dupe_check_start(dw);
3032 GtkListStore *store;
3035 /* update the listview(s) */
3037 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dw->listview)));
3038 row = dupe_listview_find_item(store, di, &iter);
3041 gtk_list_store_set(store, &iter,
3042 DUPE_COLUMN_NAME, di->fd->name,
3043 DUPE_COLUMN_PATH, di->fd->path, -1);
3046 if (dw->second_listview)
3048 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dw->second_listview)));
3049 row = dupe_listview_find_item(store, di, &iter);
3052 gtk_list_store_set(store, &iter, 1, di->fd->path, -1);
3059 static void dupe_item_update_fd_in_list(DupeWindow *dw, FileData *fd, GList *work)
3063 DupeItem *di = work->data;
3066 dupe_item_update(dw, di);
3072 static void dupe_item_update_fd(DupeWindow *dw, FileData *fd)
3074 dupe_item_update_fd_in_list(dw, fd, dw->list);
3075 if (dw->second_set) dupe_item_update_fd_in_list(dw, fd, dw->second_list);
3080 * ------------------------------------------------------------------
3082 * ------------------------------------------------------------------
3085 static GtkWidget *dupe_display_label(GtkWidget *vbox, const gchar *description, const gchar *text)
3090 hbox = gtk_hbox_new(FALSE, 10);
3092 label = gtk_label_new(description);
3093 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
3094 gtk_widget_show(label);
3096 label = gtk_label_new(text);
3097 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
3098 gtk_widget_show(label);
3100 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
3101 gtk_widget_show(hbox);
3106 static void dupe_display_stats(DupeWindow *dw, DupeItem *di)
3113 gd = file_util_gen_dlg("Image thumbprint debug info", "thumbprint",
3116 generic_dialog_add_button(gd, GTK_STOCK_CLOSE, NULL, NULL, TRUE);
3118 dupe_display_label(gd->vbox, "name:", di->fd->name);
3119 buf = text_from_size(di->fd->size);
3120 dupe_display_label(gd->vbox, "size:", buf);
3122 dupe_display_label(gd->vbox, "date:", text_from_time(di->fd->date));
3123 buf = g_strdup_printf("%d x %d", di->width, di->height);
3124 dupe_display_label(gd->vbox, "dimensions:", buf);
3126 dupe_display_label(gd->vbox, "md5sum:", (di->md5sum) ? di->md5sum : "not generated");
3128 dupe_display_label(gd->vbox, "thumbprint:", (di->simd) ? "" : "not generated");
3139 pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, 32, 32);
3140 rs = gdk_pixbuf_get_rowstride(pixbuf);
3141 d_pix = gdk_pixbuf_get_pixels(pixbuf);
3143 for (y = 0; y < 32; y++)
3145 dp = d_pix + (y * rs);
3147 for (x = 0; x < 32; x++)
3149 *(dp++) = di->simd->avg_r[sp + x];
3150 *(dp++) = di->simd->avg_g[sp + x];
3151 *(dp++) = di->simd->avg_b[sp + x];
3155 image = gtk_image_new_from_pixbuf(pixbuf);
3156 gtk_box_pack_start(GTK_BOX(gd->vbox), image, FALSE, FALSE, 0);
3157 gtk_widget_show(image);
3159 g_object_unref(pixbuf);
3162 gtk_widget_show(gd->dialog);
3165 static void dupe_window_recompare(DupeWindow *dw)
3167 GtkListStore *store;
3169 dupe_check_stop(dw);
3171 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dw->listview)));
3172 gtk_list_store_clear(store);
3174 g_list_free(dw->dupes);
3177 dupe_match_reset_list(dw->list);
3178 dupe_match_reset_list(dw->second_list);
3181 dupe_check_start(dw);
3184 static void dupe_menu_view(DupeWindow *dw, DupeItem *di, GtkWidget *listview, gint new_window)
3188 if (di->collection && collection_info_valid(di->collection, di->info))
3192 view_window_new_from_collection(di->collection, di->info);
3196 layout_image_set_collection(NULL, di->collection, di->info);
3205 list = dupe_listview_get_selection(dw, listview);
3206 view_window_new_from_list(list);
3207 filelist_free(list);
3211 layout_set_fd(NULL, di->fd);
3216 static void dupe_window_remove_selection(DupeWindow *dw, GtkWidget *listview)
3218 GtkTreeSelection *selection;
3219 GtkTreeModel *store;
3225 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(listview));
3226 slist = gtk_tree_selection_get_selected_rows(selection, &store);
3230 GtkTreePath *tpath = work->data;
3231 DupeItem *di = NULL;
3233 gtk_tree_model_get_iter(store, &iter, tpath);
3234 gtk_tree_model_get(store, &iter, DUPE_COLUMN_POINTER, &di, -1);
3235 if (di) list = g_list_prepend(list, di);
3238 g_list_foreach(slist, (GFunc)tree_path_free_wrapper, NULL);
3241 dw->color_frozen = TRUE;
3249 dupe_item_remove(dw, di);
3251 dw->color_frozen = FALSE;
3255 dupe_listview_realign_colors(dw);
3258 static void dupe_window_edit_selected(DupeWindow *dw, const gchar *key)
3260 file_util_start_editor_from_filelist(key, dupe_listview_get_selection(dw, dw->listview), NULL, dw->window);
3263 static void dupe_window_collection_from_selection(DupeWindow *dw)
3268 list = dupe_listview_get_selection(dw, dw->listview);
3269 w = collection_window_new(NULL);
3270 collection_table_add_filelist(w->table, list);
3271 filelist_free(list);
3274 static void dupe_window_append_file_list(DupeWindow *dw, gint on_second)
3278 dw->second_drop = (dw->second_set && on_second);
3280 list = layout_list(NULL);
3281 dupe_window_add_files(dw, list, FALSE);
3282 filelist_free(list);
3286 *-------------------------------------------------------------------
3287 * main pop-up menu callbacks
3288 *-------------------------------------------------------------------
3291 static void dupe_menu_view_cb(GtkWidget *widget, gpointer data)
3293 DupeWindow *dw = data;
3295 if (dw->click_item) dupe_menu_view(dw, dw->click_item, dw->listview, FALSE);
3298 static void dupe_menu_viewnew_cb(GtkWidget *widget, gpointer data)
3300 DupeWindow *dw = data;
3302 if (dw->click_item) dupe_menu_view(dw, dw->click_item, dw->listview, TRUE);
3305 static void dupe_menu_select_all_cb(GtkWidget *widget, gpointer data)
3307 DupeWindow *dw = data;
3308 GtkTreeSelection *selection;
3310 options->duplicates_select_type = DUPE_SELECT_NONE;
3311 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dw->listview));
3312 gtk_tree_selection_select_all(selection);
3315 static void dupe_menu_select_none_cb(GtkWidget *widget, gpointer data)
3317 DupeWindow *dw = data;
3318 GtkTreeSelection *selection;
3320 options->duplicates_select_type = DUPE_SELECT_NONE;
3321 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dw->listview));
3322 gtk_tree_selection_unselect_all(selection);
3325 static void dupe_menu_select_dupes_set1_cb(GtkWidget *widget, gpointer data)
3327 DupeWindow *dw = data;
3329 options->duplicates_select_type = DUPE_SELECT_GROUP1;
3330 dupe_listview_select_dupes(dw, DUPE_SELECT_GROUP1);
3333 static void dupe_menu_select_dupes_set2_cb(GtkWidget *widget, gpointer data)
3335 DupeWindow *dw = data;
3337 options->duplicates_select_type = DUPE_SELECT_GROUP2;
3338 dupe_listview_select_dupes(dw, DUPE_SELECT_GROUP2);
3341 static void dupe_menu_edit_cb(GtkWidget *widget, gpointer data)
3344 const gchar *key = data;
3346 dw = submenu_item_get_data(widget);
3349 dupe_window_edit_selected(dw, key);
3352 static void dupe_menu_print_cb(GtkWidget *widget, gpointer data)
3354 DupeWindow *dw = data;
3357 fd = (dw->click_item) ? dw->click_item->fd : NULL;
3359 print_window_new(fd,
3360 dupe_listview_get_selection(dw, dw->listview),
3361 dupe_listview_get_filelist(dw, dw->listview), dw->window);
3364 static void dupe_menu_copy_cb(GtkWidget *widget, gpointer data)
3366 DupeWindow *dw = data;
3368 file_util_copy(NULL, dupe_listview_get_selection(dw, dw->listview), NULL, dw->window);
3371 static void dupe_menu_move_cb(GtkWidget *widget, gpointer data)
3373 DupeWindow *dw = data;
3375 file_util_move(NULL, dupe_listview_get_selection(dw, dw->listview), NULL, dw->window);
3378 static void dupe_menu_rename_cb(GtkWidget *widget, gpointer data)
3380 DupeWindow *dw = data;
3382 file_util_rename(NULL, dupe_listview_get_selection(dw, dw->listview), dw->window);
3385 static void dupe_menu_delete_cb(GtkWidget *widget, gpointer data)
3387 DupeWindow *dw = data;
3389 options->file_ops.safe_delete_enable = FALSE;
3390 file_util_delete_notify_done(NULL, dupe_listview_get_selection(dw, dw->listview), dw->window, delete_finished_cb, dw);
3393 static void dupe_menu_move_to_trash_cb(GtkWidget *widget, gpointer data)
3395 DupeWindow *dw = data;
3397 options->file_ops.safe_delete_enable = TRUE;
3398 file_util_delete_notify_done(NULL, dupe_listview_get_selection(dw, dw->listview), dw->window, delete_finished_cb, dw);
3401 static void dupe_menu_copy_path_cb(GtkWidget *widget, gpointer data)
3403 DupeWindow *dw = data;
3405 file_util_copy_path_list_to_clipboard(dupe_listview_get_selection(dw, dw->listview), TRUE);
3408 static void dupe_menu_copy_path_unquoted_cb(GtkWidget *widget, gpointer data)
3410 DupeWindow *dw = data;
3412 file_util_copy_path_list_to_clipboard(dupe_listview_get_selection(dw, dw->listview), FALSE);
3415 static void dupe_menu_remove_cb(GtkWidget *widget, gpointer data)
3417 DupeWindow *dw = data;
3419 dupe_window_remove_selection(dw, dw->listview);
3422 static void dupe_menu_clear_cb(GtkWidget *widget, gpointer data)
3424 DupeWindow *dw = data;
3426 dupe_window_clear(dw);
3429 static void dupe_menu_close_cb(GtkWidget *widget, gpointer data)
3431 DupeWindow *dw = data;
3433 dupe_window_close(dw);
3436 static void dupe_menu_popup_destroy_cb(GtkWidget *widget, gpointer data)
3438 GList *editmenu_fd_list = data;
3440 filelist_free(editmenu_fd_list);
3443 static GList *dupe_window_get_fd_list(DupeWindow *dw)
3447 if (gtk_widget_has_focus(dw->second_listview))
3449 list = dupe_listview_get_selection(dw, dw->second_listview);
3453 list = dupe_listview_get_selection(dw, dw->listview);
3460 * @brief Add file selection list to a collection
3462 * @param[in] data Index to the collection list menu item selected, or -1 for new collection
3466 static void dupe_pop_menu_collections_cb(GtkWidget *widget, gpointer data)
3469 GList *selection_list;
3471 dw = submenu_item_get_data(widget);
3472 selection_list = dupe_listview_get_selection(dw, dw->listview);
3473 pop_menu_collections(selection_list, data);
3475 filelist_free(selection_list);
3478 static GtkWidget *dupe_menu_popup_main(DupeWindow *dw, DupeItem *di)
3483 GList *editmenu_fd_list;
3485 on_row = (di != NULL);
3487 menu = popup_menu_short_lived();
3489 menu_item_add_sensitive(menu, _("_View"), on_row,
3490 G_CALLBACK(dupe_menu_view_cb), dw);
3491 menu_item_add_stock_sensitive(menu, _("View in _new window"), GTK_STOCK_NEW, on_row,
3492 G_CALLBACK(dupe_menu_viewnew_cb), dw);
3493 menu_item_add_divider(menu);
3494 menu_item_add_sensitive(menu, _("Select all"), (dw->dupes != NULL),
3495 G_CALLBACK(dupe_menu_select_all_cb), dw);
3496 menu_item_add_sensitive(menu, _("Select none"), (dw->dupes != NULL),
3497 G_CALLBACK(dupe_menu_select_none_cb), dw);
3498 menu_item_add_sensitive(menu, _("Select group _1 duplicates"), (dw->dupes != NULL),
3499 G_CALLBACK(dupe_menu_select_dupes_set1_cb), dw);
3500 menu_item_add_sensitive(menu, _("Select group _2 duplicates"), (dw->dupes != NULL),
3501 G_CALLBACK(dupe_menu_select_dupes_set2_cb), dw);
3502 menu_item_add_divider(menu);
3504 submenu_add_export(menu, &item, G_CALLBACK(dupe_pop_menu_export_cb), dw);
3505 gtk_widget_set_sensitive(item, on_row);
3506 menu_item_add_divider(menu);
3508 editmenu_fd_list = dupe_window_get_fd_list(dw);
3509 g_signal_connect(G_OBJECT(menu), "destroy",
3510 G_CALLBACK(dupe_menu_popup_destroy_cb), editmenu_fd_list);
3511 submenu_add_edit(menu, &item, G_CALLBACK(dupe_menu_edit_cb), dw, editmenu_fd_list);
3512 if (!on_row) gtk_widget_set_sensitive(item, FALSE);
3514 submenu_add_collections(menu, &item,
3515 G_CALLBACK(dupe_pop_menu_collections_cb), dw);
3516 gtk_widget_set_sensitive(item, on_row);
3518 menu_item_add_stock_sensitive(menu, _("Print..."), GTK_STOCK_PRINT, on_row,
3519 G_CALLBACK(dupe_menu_print_cb), dw);
3520 menu_item_add_divider(menu);
3521 menu_item_add_stock_sensitive(menu, _("_Copy..."), GTK_STOCK_COPY, on_row,
3522 G_CALLBACK(dupe_menu_copy_cb), dw);
3523 menu_item_add_sensitive(menu, _("_Move..."), on_row,
3524 G_CALLBACK(dupe_menu_move_cb), dw);
3525 menu_item_add_sensitive(menu, _("_Rename..."), on_row,
3526 G_CALLBACK(dupe_menu_rename_cb), dw);
3527 menu_item_add_sensitive(menu, _("_Copy path"), on_row,
3528 G_CALLBACK(dupe_menu_copy_path_cb), dw);
3529 menu_item_add_sensitive(menu, _("_Copy path unquoted"), on_row,
3530 G_CALLBACK(dupe_menu_copy_path_unquoted_cb), dw);
3532 menu_item_add_divider(menu);
3533 menu_item_add_stock_sensitive(menu,
3534 options->file_ops.confirm_move_to_trash ? _("Move to Trash...") :
3535 _("Move to Trash"), PIXBUF_INLINE_ICON_TRASH, on_row,
3536 G_CALLBACK(dupe_menu_move_to_trash_cb), dw);
3537 menu_item_add_stock_sensitive(menu,
3538 options->file_ops.confirm_delete ? _("_Delete...") :
3539 _("_Delete"), GTK_STOCK_DELETE, on_row,
3540 G_CALLBACK(dupe_menu_delete_cb), dw);
3542 menu_item_add_divider(menu);
3543 menu_item_add_stock_sensitive(menu, _("Rem_ove"), GTK_STOCK_REMOVE, on_row,
3544 G_CALLBACK(dupe_menu_remove_cb), dw);
3545 menu_item_add_stock_sensitive(menu, _("C_lear"), GTK_STOCK_CLEAR, (dw->list != NULL),
3546 G_CALLBACK(dupe_menu_clear_cb), dw);
3547 menu_item_add_divider(menu);
3548 menu_item_add_stock(menu, _("Close _window"), GTK_STOCK_CLOSE,
3549 G_CALLBACK(dupe_menu_close_cb), dw);
3554 static gboolean dupe_listview_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
3556 DupeWindow *dw = data;
3557 GtkTreeModel *store;
3560 DupeItem *di = NULL;
3562 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget));
3564 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bevent->x, bevent->y,
3565 &tpath, NULL, NULL, NULL))
3567 gtk_tree_model_get_iter(store, &iter, tpath);
3568 gtk_tree_model_get(store, &iter, DUPE_COLUMN_POINTER, &di, -1);
3569 gtk_tree_path_free(tpath);
3572 dw->click_item = di;
3574 if (bevent->button == MOUSE_BUTTON_RIGHT)
3576 /* right click menu */
3579 if (bevent->state & GDK_CONTROL_MASK && bevent->state & GDK_SHIFT_MASK)
3581 dupe_display_stats(dw, di);
3584 if (widget == dw->listview)
3586 menu = dupe_menu_popup_main(dw, di);
3590 menu = dupe_menu_popup_second(dw, di);
3592 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, bevent->button, bevent->time);
3595 if (!di) return FALSE;
3597 if (bevent->button == MOUSE_BUTTON_LEFT &&
3598 bevent->type == GDK_2BUTTON_PRESS)
3600 dupe_menu_view(dw, di, widget, FALSE);
3603 if (bevent->button == MOUSE_BUTTON_MIDDLE) return TRUE;
3605 if (bevent->button == MOUSE_BUTTON_RIGHT)
3607 if (!dupe_listview_item_is_selected(dw, di, widget))
3609 GtkTreeSelection *selection;
3611 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
3612 gtk_tree_selection_unselect_all(selection);
3613 gtk_tree_selection_select_iter(selection, &iter);
3615 tpath = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter);
3616 gtk_tree_view_set_cursor(GTK_TREE_VIEW(widget), tpath, NULL, FALSE);
3617 gtk_tree_path_free(tpath);
3623 if (bevent->button == MOUSE_BUTTON_LEFT &&
3624 bevent->type == GDK_BUTTON_PRESS &&
3625 !(bevent->state & GDK_SHIFT_MASK ) &&
3626 !(bevent->state & GDK_CONTROL_MASK ) &&
3627 dupe_listview_item_is_selected(dw, di, widget))
3629 /* this selection handled on release_cb */
3630 gtk_widget_grab_focus(widget);
3637 static gboolean dupe_listview_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
3639 DupeWindow *dw = data;
3640 GtkTreeModel *store;
3643 DupeItem *di = NULL;
3645 if (bevent->button != MOUSE_BUTTON_LEFT && bevent->button != MOUSE_BUTTON_MIDDLE) return TRUE;
3647 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget));
3649 if ((bevent->x != 0 || bevent->y != 0) &&
3650 gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bevent->x, bevent->y,
3651 &tpath, NULL, NULL, NULL))
3653 gtk_tree_model_get_iter(store, &iter, tpath);
3654 gtk_tree_model_get(store, &iter, DUPE_COLUMN_POINTER, &di, -1);
3655 gtk_tree_path_free(tpath);
3658 if (bevent->button == MOUSE_BUTTON_MIDDLE)
3660 if (di && dw->click_item == di)
3662 GtkTreeSelection *selection;
3664 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
3665 if (dupe_listview_item_is_selected(dw, di, widget))
3667 gtk_tree_selection_unselect_iter(selection, &iter);
3671 gtk_tree_selection_select_iter(selection, &iter);
3677 if (di && dw->click_item == di &&
3678 !(bevent->state & GDK_SHIFT_MASK ) &&
3679 !(bevent->state & GDK_CONTROL_MASK ) &&
3680 dupe_listview_item_is_selected(dw, di, widget))
3682 GtkTreeSelection *selection;
3684 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
3685 gtk_tree_selection_unselect_all(selection);
3686 gtk_tree_selection_select_iter(selection, &iter);
3688 tpath = gtk_tree_model_get_path(store, &iter);
3689 gtk_tree_view_set_cursor(GTK_TREE_VIEW(widget), tpath, NULL, FALSE);
3690 gtk_tree_path_free(tpath);
3699 *-------------------------------------------------------------------
3701 *-------------------------------------------------------------------
3704 static void dupe_second_update_status(DupeWindow *dw)
3708 buf = g_strdup_printf(_("%d files (set 2)"), g_list_length(dw->second_list));
3709 gtk_label_set_text(GTK_LABEL(dw->second_status_label), buf);
3713 static void dupe_second_add(DupeWindow *dw, DupeItem *di)
3715 GtkListStore *store;
3721 dw->second_list = g_list_prepend(dw->second_list, di);
3723 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dw->second_listview)));
3724 gtk_list_store_append(store, &iter);
3725 gtk_list_store_set(store, &iter, DUPE_COLUMN_POINTER, di, 1, di->fd->path, -1);
3727 dupe_second_update_status(dw);
3730 static void dupe_second_remove(DupeWindow *dw, DupeItem *di)
3732 GtkListStore *store;
3735 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dw->second_listview)));
3736 if (dupe_listview_find_item(store, di, &iter) >= 0)
3738 tree_view_move_cursor_away(GTK_TREE_VIEW(dw->second_listview), &iter, TRUE);
3739 gtk_list_store_remove(store, &iter);
3742 dw->second_list = g_list_remove(dw->second_list, di);
3744 dupe_second_update_status(dw);
3747 static void dupe_second_clear(DupeWindow *dw)
3749 GtkListStore *store;
3751 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dw->second_listview)));
3752 gtk_list_store_clear(store);
3753 gtk_tree_view_columns_autosize(GTK_TREE_VIEW(dw->second_listview));
3755 g_list_free(dw->dupes);
3758 dupe_list_free(dw->second_list);
3759 dw->second_list = NULL;
3761 dupe_match_reset_list(dw->list);
3763 dupe_second_update_status(dw);
3766 static void dupe_second_menu_view_cb(GtkWidget *widget, gpointer data)
3768 DupeWindow *dw = data;
3770 if (dw->click_item) dupe_menu_view(dw, dw->click_item, dw->second_listview, FALSE);
3773 static void dupe_second_menu_viewnew_cb(GtkWidget *widget, gpointer data)
3775 DupeWindow *dw = data;
3777 if (dw->click_item) dupe_menu_view(dw, dw->click_item, dw->second_listview, TRUE);
3780 static void dupe_second_menu_select_all_cb(GtkWidget *widget, gpointer data)
3782 GtkTreeSelection *selection;
3783 DupeWindow *dw = data;
3785 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dw->second_listview));
3786 gtk_tree_selection_select_all(selection);
3789 static void dupe_second_menu_select_none_cb(GtkWidget *widget, gpointer data)
3791 GtkTreeSelection *selection;
3792 DupeWindow *dw = data;
3794 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dw->second_listview));
3795 gtk_tree_selection_unselect_all(selection);
3798 static void dupe_second_menu_remove_cb(GtkWidget *widget, gpointer data)
3800 DupeWindow *dw = data;
3802 dupe_window_remove_selection(dw, dw->second_listview);
3805 static void dupe_second_menu_clear_cb(GtkWidget *widget, gpointer data)
3807 DupeWindow *dw = data;
3809 dupe_second_clear(dw);
3810 dupe_window_recompare(dw);
3813 static GtkWidget *dupe_menu_popup_second(DupeWindow *dw, DupeItem *di)
3816 gboolean notempty = (dw->second_list != NULL);
3817 gboolean on_row = (di != NULL);
3819 menu = popup_menu_short_lived();
3820 menu_item_add_sensitive(menu, _("_View"), on_row,
3821 G_CALLBACK(dupe_second_menu_view_cb), dw);
3822 menu_item_add_stock_sensitive(menu, _("View in _new window"), GTK_STOCK_NEW, on_row,
3823 G_CALLBACK(dupe_second_menu_viewnew_cb), dw);
3824 menu_item_add_divider(menu);
3825 menu_item_add_sensitive(menu, _("Select all"), notempty,
3826 G_CALLBACK(dupe_second_menu_select_all_cb), dw);
3827 menu_item_add_sensitive(menu, _("Select none"), notempty,
3828 G_CALLBACK(dupe_second_menu_select_none_cb), dw);
3829 menu_item_add_divider(menu);
3830 menu_item_add_stock_sensitive(menu, _("Rem_ove"), GTK_STOCK_REMOVE, on_row,
3831 G_CALLBACK(dupe_second_menu_remove_cb), dw);
3832 menu_item_add_stock_sensitive(menu, _("C_lear"), GTK_STOCK_CLEAR, notempty,
3833 G_CALLBACK(dupe_second_menu_clear_cb), dw);
3834 menu_item_add_divider(menu);
3835 menu_item_add_stock(menu, _("Close _window"), GTK_STOCK_CLOSE,
3836 G_CALLBACK(dupe_menu_close_cb), dw);
3841 static void dupe_second_set_toggle_cb(GtkWidget *widget, gpointer data)
3843 DupeWindow *dw = data;
3845 dw->second_set = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
3849 dupe_second_update_status(dw);
3850 gtk_table_set_col_spacings(GTK_TABLE(dw->table), PREF_PAD_GAP);
3851 gtk_widget_show(dw->second_vbox);
3855 gtk_table_set_col_spacings(GTK_TABLE(dw->table), 0);
3856 gtk_widget_hide(dw->second_vbox);
3857 dupe_second_clear(dw);
3860 dupe_window_recompare(dw);
3863 static void dupe_sort_totals_toggle_cb(GtkWidget *widget, gpointer data)
3865 DupeWindow *dw = data;
3867 options->sort_totals = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
3868 dupe_window_recompare(dw);
3873 *-------------------------------------------------------------------
3875 *-------------------------------------------------------------------
3879 DUPE_MENU_COLUMN_NAME = 0,
3880 DUPE_MENU_COLUMN_MASK
3883 static void dupe_listview_show_rank(GtkWidget *listview, gboolean rank);
3885 static void dupe_menu_type_cb(GtkWidget *combo, gpointer data)
3887 DupeWindow *dw = data;
3888 GtkTreeModel *store;
3891 store = gtk_combo_box_get_model(GTK_COMBO_BOX(combo));
3892 if (!gtk_combo_box_get_active_iter(GTK_COMBO_BOX(combo), &iter)) return;
3893 gtk_tree_model_get(store, &iter, DUPE_MENU_COLUMN_MASK, &dw->match_mask, -1);
3895 options->duplicates_match = dw->match_mask;
3897 if (dw->match_mask & (DUPE_MATCH_SIM_HIGH | DUPE_MATCH_SIM_MED | DUPE_MATCH_SIM_LOW | DUPE_MATCH_SIM_CUSTOM))
3899 dupe_listview_show_rank(dw->listview, TRUE);
3903 dupe_listview_show_rank(dw->listview, FALSE);
3905 dupe_window_recompare(dw);
3908 static void dupe_menu_add_item(GtkListStore *store, const gchar *text, DupeMatchType type, DupeWindow *dw)
3912 gtk_list_store_append(store, &iter);
3913 gtk_list_store_set(store, &iter, DUPE_MENU_COLUMN_NAME, text,
3914 DUPE_MENU_COLUMN_MASK, type, -1);
3916 if (dw->match_mask == type) gtk_combo_box_set_active_iter(GTK_COMBO_BOX(dw->combo), &iter);
3919 static void dupe_menu_setup(DupeWindow *dw)
3921 GtkListStore *store;
3922 GtkCellRenderer *renderer;
3924 store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INT);
3925 dw->combo = gtk_combo_box_new_with_model(GTK_TREE_MODEL(store));
3926 g_object_unref(store);
3928 renderer = gtk_cell_renderer_text_new();
3929 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(dw->combo), renderer, TRUE);
3930 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(dw->combo), renderer,
3931 "text", DUPE_MENU_COLUMN_NAME, NULL);
3933 dupe_menu_add_item(store, _("Name"), DUPE_MATCH_NAME, dw);
3934 dupe_menu_add_item(store, _("Name case-insensitive"), DUPE_MATCH_NAME_CI, dw);
3935 dupe_menu_add_item(store, _("Size"), DUPE_MATCH_SIZE, dw);
3936 dupe_menu_add_item(store, _("Date"), DUPE_MATCH_DATE, dw);
3937 dupe_menu_add_item(store, _("Dimensions"), DUPE_MATCH_DIM, dw);
3938 dupe_menu_add_item(store, _("Checksum"), DUPE_MATCH_SUM, dw);
3939 dupe_menu_add_item(store, _("Path"), DUPE_MATCH_PATH, dw);
3940 dupe_menu_add_item(store, _("Similarity (high - 95)"), DUPE_MATCH_SIM_HIGH, dw);
3941 dupe_menu_add_item(store, _("Similarity (med. - 90)"), DUPE_MATCH_SIM_MED, dw);
3942 dupe_menu_add_item(store, _("Similarity (low - 85)"), DUPE_MATCH_SIM_LOW, dw);
3943 dupe_menu_add_item(store, _("Similarity (custom)"), DUPE_MATCH_SIM_CUSTOM, dw);
3944 dupe_menu_add_item(store, _("Name ≠content"), DUPE_MATCH_NAME_CONTENT, dw);
3945 dupe_menu_add_item(store, _("Name case-insensitive ≠content"), DUPE_MATCH_NAME_CI_CONTENT, dw);
3946 dupe_menu_add_item(store, _("Show all"), DUPE_MATCH_ALL, dw);
3948 g_signal_connect(G_OBJECT(dw->combo), "changed",
3949 G_CALLBACK(dupe_menu_type_cb), dw);
3953 *-------------------------------------------------------------------
3955 *-------------------------------------------------------------------
3958 /* this overrides the low default of a GtkCellRenderer from 100 to CELL_HEIGHT_OVERRIDE, something sane for our purposes */
3960 #define CELL_HEIGHT_OVERRIDE 512
3962 void cell_renderer_height_override(GtkCellRenderer *renderer)
3966 spec = g_object_class_find_property(G_OBJECT_GET_CLASS(G_OBJECT(renderer)), "height");
3967 if (spec && G_IS_PARAM_SPEC_INT(spec))
3969 GParamSpecInt *spec_int;
3971 spec_int = G_PARAM_SPEC_INT(spec);
3972 if (spec_int->maximum < CELL_HEIGHT_OVERRIDE) spec_int->maximum = CELL_HEIGHT_OVERRIDE;
3976 static GdkColor *dupe_listview_color_shifted(GtkWidget *widget)
3978 static GdkColor color;
3979 static GtkWidget *done = NULL;
3985 style = gtk_widget_get_style(widget);
3986 memcpy(&color, &style->base[GTK_STATE_NORMAL], sizeof(color));
3987 shift_color(&color, -1, 0);
3994 static void dupe_listview_color_cb(GtkTreeViewColumn *tree_column, GtkCellRenderer *cell,
3995 GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data)
3997 DupeWindow *dw = data;
4000 gtk_tree_model_get(tree_model, iter, DUPE_COLUMN_COLOR, &set, -1);
4001 g_object_set(G_OBJECT(cell),
4002 "cell-background-gdk", dupe_listview_color_shifted(dw->listview),
4003 "cell-background-set", set, NULL);
4006 static void dupe_listview_add_column(DupeWindow *dw, GtkWidget *listview, gint n, const gchar *title, gboolean image, gboolean right_justify)
4008 GtkTreeViewColumn *column;
4009 GtkCellRenderer *renderer;
4011 column = gtk_tree_view_column_new();
4012 gtk_tree_view_column_set_title(column, title);
4013 gtk_tree_view_column_set_min_width(column, 4);
4014 gtk_tree_view_column_set_sort_column_id(column, n);
4016 if (n != DUPE_COLUMN_RANK &&
4017 n != DUPE_COLUMN_THUMB)
4019 gtk_tree_view_column_set_resizable(column, TRUE);
4024 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_GROW_ONLY);
4025 renderer = gtk_cell_renderer_text_new();
4028 g_object_set(G_OBJECT(renderer), "xalign", 1.0, NULL);
4030 gtk_tree_view_column_pack_start(column, renderer, TRUE);
4031 gtk_tree_view_column_add_attribute(column, renderer, "text", n);
4035 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
4036 renderer = gtk_cell_renderer_pixbuf_new();
4037 cell_renderer_height_override(renderer);
4038 gtk_tree_view_column_pack_start(column, renderer, TRUE);
4039 gtk_tree_view_column_add_attribute(column, renderer, "pixbuf", n);
4042 if (listview == dw->listview)
4044 /* sets background before rendering */
4045 gtk_tree_view_column_set_cell_data_func(column, renderer, dupe_listview_color_cb, dw, NULL);
4048 gtk_tree_view_append_column(GTK_TREE_VIEW(listview), column);
4051 static void dupe_listview_set_height(GtkWidget *listview, gboolean thumb)
4053 GtkTreeViewColumn *column;
4054 GtkCellRenderer *cell;
4057 column = gtk_tree_view_get_column(GTK_TREE_VIEW(listview), DUPE_COLUMN_THUMB - 1);
4058 if (!column) return;
4060 gtk_tree_view_column_set_fixed_width(column, (thumb) ? options->thumbnails.max_width : 4);
4061 gtk_tree_view_column_set_visible(column, thumb);
4063 list = gtk_cell_layout_get_cells(GTK_CELL_LAYOUT(column));
4068 g_object_set(G_OBJECT(cell), "height", (thumb) ? options->thumbnails.max_height : -1, NULL);
4069 gtk_tree_view_columns_autosize(GTK_TREE_VIEW(listview));
4072 static void dupe_listview_show_rank(GtkWidget *listview, gboolean rank)
4074 GtkTreeViewColumn *column;
4076 column = gtk_tree_view_get_column(GTK_TREE_VIEW(listview), DUPE_COLUMN_RANK - 1);
4077 if (!column) return;
4079 gtk_tree_view_column_set_visible(column, rank);
4083 *-------------------------------------------------------------------
4085 *-------------------------------------------------------------------
4088 static void dupe_window_show_thumb_cb(GtkWidget *widget, gpointer data)
4090 DupeWindow *dw = data;
4092 dw->show_thumbs = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
4093 options->duplicates_thumbnails = dw->show_thumbs;
4095 if (dw->show_thumbs)
4097 if (!dw->working) dupe_thumb_step(dw);
4101 GtkTreeModel *store;
4105 thumb_loader_free(dw->thumb_loader);
4106 dw->thumb_loader = NULL;
4108 store = gtk_tree_view_get_model(GTK_TREE_VIEW(dw->listview));
4109 valid = gtk_tree_model_get_iter_first(store, &iter);
4113 gtk_list_store_set(GTK_LIST_STORE(store), &iter, DUPE_COLUMN_THUMB, NULL, -1);
4114 valid = gtk_tree_model_iter_next(store, &iter);
4116 dupe_window_update_progress(dw, NULL, 0.0, FALSE);
4119 dupe_listview_set_height(dw->listview, dw->show_thumbs);
4122 static void dupe_window_rotation_invariant_cb(GtkWidget *widget, gpointer data)
4124 DupeWindow *dw = data;
4126 options->rot_invariant_sim = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
4127 dupe_window_recompare(dw);
4130 static void dupe_window_custom_threshold_cb(GtkWidget *widget, gpointer data)
4132 DupeWindow *dw = data;
4133 DupeMatchType match_type;
4134 GtkTreeModel *store;
4138 options->duplicates_similarity_threshold = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));
4139 dw->match_mask = DUPE_MATCH_SIM_CUSTOM;
4141 store = gtk_combo_box_get_model(GTK_COMBO_BOX(dw->combo));
4142 valid = gtk_tree_model_get_iter_first(store, &iter);
4145 gtk_tree_model_get(store, &iter, DUPE_MENU_COLUMN_MASK, &match_type, -1);
4146 if (match_type == DUPE_MATCH_SIM_CUSTOM)
4150 valid = gtk_tree_model_iter_next(store, &iter);
4153 gtk_combo_box_set_active_iter(GTK_COMBO_BOX(dw->combo), &iter);
4154 dupe_window_recompare(dw);
4157 static void dupe_popup_menu_pos_cb(GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer data)
4159 GtkWidget *view = data;
4161 gint cx, cy, cw, ch;
4164 gtk_tree_view_get_cursor(GTK_TREE_VIEW(view), &tpath, NULL);
4167 if (gtk_tree_view_get_column(GTK_TREE_VIEW(view), DUPE_COLUMN_NAME - 1) != NULL)
4169 column = DUPE_COLUMN_NAME - 1;
4173 /* dw->second_listview */
4176 tree_view_get_cell_clamped(GTK_TREE_VIEW(view), tpath, column, TRUE, &cx, &cy, &cw, &ch);
4177 gtk_tree_path_free(tpath);
4179 popup_menu_position_clamp(menu, &cx, &cy, 0);
4184 static gboolean dupe_window_keypress_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
4186 DupeWindow *dw = data;
4187 gboolean stop_signal = FALSE;
4189 GtkWidget *listview;
4190 GtkTreeModel *store;
4191 GtkTreeSelection *selection;
4193 DupeItem *di = NULL;
4195 on_second = gtk_widget_has_focus(dw->second_listview);
4199 listview = dw->second_listview;
4203 listview = dw->listview;
4206 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(listview));
4207 slist = gtk_tree_selection_get_selected_rows(selection, &store);
4214 last = g_list_last(slist);
4217 /* last is newest selected file */
4218 gtk_tree_model_get_iter(store, &iter, tpath);
4219 gtk_tree_model_get(store, &iter, DUPE_COLUMN_POINTER, &di, -1);
4221 g_list_foreach(slist, (GFunc)tree_path_free_wrapper, NULL);
4224 if (event->state & GDK_CONTROL_MASK)
4229 switch (event->keyval)
4243 file_util_copy(NULL, dupe_listview_get_selection(dw, listview),
4247 file_util_move(NULL, dupe_listview_get_selection(dw, listview),
4251 file_util_rename(NULL, dupe_listview_get_selection(dw, listview), dw->window);
4254 options->file_ops.safe_delete_enable = TRUE;
4255 file_util_delete(NULL, dupe_listview_get_selection(dw, listview), dw->window);
4258 stop_signal = FALSE;
4266 switch (event->keyval)
4269 if (event->state & GDK_SHIFT_MASK)
4271 gtk_tree_selection_unselect_all(selection);
4275 gtk_tree_selection_select_all(selection);
4278 case GDK_KEY_Delete: case GDK_KEY_KP_Delete:
4281 dupe_second_clear(dw);
4282 dupe_window_recompare(dw);
4286 dupe_window_clear(dw);
4290 dupe_window_append_file_list(dw, FALSE);
4293 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dw->button_thumbs),
4294 !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dw->button_thumbs)));
4297 dupe_window_close(dw);
4300 stop_signal = FALSE;
4308 switch (event->keyval)
4310 case GDK_KEY_Return: case GDK_KEY_KP_Enter:
4311 dupe_menu_view(dw, di, listview, FALSE);
4314 dupe_menu_view(dw, di, listview, TRUE);
4316 case GDK_KEY_Delete: case GDK_KEY_KP_Delete:
4317 dupe_window_remove_selection(dw, listview);
4322 dupe_window_collection_from_selection(dw);
4326 options->duplicates_select_type = DUPE_SELECT_NONE;
4327 dupe_listview_select_dupes(dw, DUPE_SELECT_NONE);
4330 options->duplicates_select_type = DUPE_SELECT_GROUP1;
4331 dupe_listview_select_dupes(dw, DUPE_SELECT_GROUP1);
4334 options->duplicates_select_type = DUPE_SELECT_GROUP2;
4335 dupe_listview_select_dupes(dw, DUPE_SELECT_GROUP2);
4343 menu = dupe_menu_popup_main(dw, di);
4344 gtk_menu_popup(GTK_MENU(menu), NULL, NULL,
4345 dupe_popup_menu_pos_cb, listview, 0, GDK_CURRENT_TIME);
4351 menu = dupe_menu_popup_second(dw, di);
4352 gtk_menu_popup(GTK_MENU(menu), NULL, NULL,
4353 dupe_popup_menu_pos_cb, listview, 0, GDK_CURRENT_TIME);
4357 stop_signal = FALSE;
4361 if (!stop_signal && is_help_key(event))
4363 help_window_show("GuideImageSearchFindingDuplicates.html");
4371 void dupe_window_clear(DupeWindow *dw)
4373 GtkListStore *store;
4375 dupe_check_stop(dw);
4377 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dw->listview)));
4378 gtk_list_store_clear(store);
4379 gtk_tree_view_columns_autosize(GTK_TREE_VIEW(dw->listview));
4381 g_list_free(dw->dupes);
4384 dupe_list_free(dw->list);
4388 dupe_match_reset_list(dw->second_list);
4390 dupe_window_update_count(dw, FALSE);
4391 dupe_window_update_progress(dw, NULL, 0.0, FALSE);
4394 static void dupe_window_get_geometry(DupeWindow *dw)
4397 LayoutWindow *lw = NULL;
4401 if (!dw || !lw) return;
4403 window = gtk_widget_get_window(dw->window);
4404 gdk_window_get_position(window, &lw->options.dupe_window.x, &lw->options.dupe_window.y);
4405 lw->options.dupe_window.w = gdk_window_get_width(window);
4406 lw->options.dupe_window.h = gdk_window_get_height(window);
4409 void dupe_window_close(DupeWindow *dw)
4411 dupe_check_stop(dw);
4413 dupe_window_get_geometry(dw);
4415 dupe_window_list = g_list_remove(dupe_window_list, dw);
4416 gtk_widget_destroy(dw->window);
4418 g_list_free(dw->dupes);
4419 dupe_list_free(dw->list);
4421 dupe_list_free(dw->second_list);
4423 file_data_unregister_notify_func(dupe_notify_cb, dw);
4425 g_thread_pool_free(dw->dupe_comparison_thread_pool, TRUE, TRUE);
4430 static gint dupe_window_close_cb(GtkWidget *widget, gpointer data)
4432 DupeWindow *dw = data;
4434 dupe_window_close(dw);
4439 static gint dupe_window_delete(GtkWidget *widget, GdkEvent *event, gpointer data)
4441 DupeWindow *dw = data;
4442 dupe_window_close(dw);
4447 static void dupe_help_cb(GtkAction *action, gpointer data)
4449 help_window_show("GuideImageSearchFindingDuplicates.html");
4452 static gint default_sort_cb(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer data)
4457 static gint column_sort_cb(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer data)
4459 GtkTreeSortable *sortable = data;
4461 gchar *rank_str_a, *rank_str_b;
4466 gint sort_column_id;
4467 GtkSortType sort_order;
4471 gtk_tree_sortable_get_sort_column_id(sortable, &sort_column_id, &sort_order);
4473 gtk_tree_model_get(model, a, DUPE_COLUMN_RANK, &rank_str_a, DUPE_COLUMN_SET, &group_a, DUPE_COLUMN_POINTER, &di_a, -1);
4475 gtk_tree_model_get(model, b, DUPE_COLUMN_RANK, &rank_str_b, DUPE_COLUMN_SET, &group_b, DUPE_COLUMN_POINTER, &di_b, -1);
4477 if (group_a == group_b)
4479 switch (sort_column_id)
4481 case DUPE_COLUMN_NAME:
4482 ret = utf8_compare(di_a->fd->name, di_b->fd->name, TRUE);
4484 case DUPE_COLUMN_SIZE:
4485 if (di_a->fd->size == di_b->fd->size)
4491 ret = (di_a->fd->size > di_b->fd->size) ? 1 : -1;
4494 case DUPE_COLUMN_DATE:
4495 if (di_a->fd->date == di_b->fd->date)
4501 ret = (di_a->fd->date > di_b->fd->date) ? 1 : -1;
4504 case DUPE_COLUMN_DIMENSIONS:
4505 if ((di_a->width == di_b->width) && (di_a->height == di_b->height))
4511 ret = ((di_a->width * di_a->height) > (di_b->width * di_b->height)) ? 1 : -1;
4514 case DUPE_COLUMN_RANK:
4515 rank_int_a = atoi(rank_str_a);
4516 rank_int_b = atoi(rank_str_b);
4517 if (rank_int_a == 0) rank_int_a = 101;
4518 if (rank_int_b == 0) rank_int_b = 101;
4520 if (rank_int_a == rank_int_b)
4526 ret = (rank_int_a > rank_int_b) ? 1 : -1;
4529 case DUPE_COLUMN_PATH:
4530 ret = utf8_compare(di_a->fd->path, di_b->fd->path, TRUE);
4534 else if (group_a < group_b)
4536 ret = (sort_order == GTK_SORT_ASCENDING) ? 1 : -1;
4540 ret = (sort_order == GTK_SORT_ASCENDING) ? -1 : 1;
4546 static void column_clicked_cb(GtkWidget *widget, gpointer data)
4548 DupeWindow *dw = data;
4550 options->duplicates_match = DUPE_SELECT_NONE;
4551 dupe_listview_select_dupes(dw, DUPE_SELECT_NONE);
4554 /* collection and files can be NULL */
4555 DupeWindow *dupe_window_new()
4560 GtkWidget *scrolled;
4562 GtkWidget *status_box;
4563 GtkWidget *controls_box;
4564 GtkWidget *button_box;
4567 GtkListStore *store;
4568 GtkTreeSelection *selection;
4569 GdkGeometry geometry;
4570 LayoutWindow *lw = NULL;
4574 dw = g_new0(DupeWindow, 1);
4575 dw->add_files_queue = NULL;
4576 dw->add_files_queue_id = 0;
4578 dw->match_mask = DUPE_MATCH_NAME;
4579 if (options->duplicates_match == DUPE_MATCH_NAME) dw->match_mask = DUPE_MATCH_NAME;
4580 if (options->duplicates_match == DUPE_MATCH_SIZE) dw->match_mask = DUPE_MATCH_SIZE;
4581 if (options->duplicates_match == DUPE_MATCH_DATE) dw->match_mask = DUPE_MATCH_DATE;
4582 if (options->duplicates_match == DUPE_MATCH_DIM) dw->match_mask = DUPE_MATCH_DIM;
4583 if (options->duplicates_match == DUPE_MATCH_SUM) dw->match_mask = DUPE_MATCH_SUM;
4584 if (options->duplicates_match == DUPE_MATCH_PATH) dw->match_mask = DUPE_MATCH_PATH;
4585 if (options->duplicates_match == DUPE_MATCH_SIM_HIGH) dw->match_mask = DUPE_MATCH_SIM_HIGH;
4586 if (options->duplicates_match == DUPE_MATCH_SIM_MED) dw->match_mask = DUPE_MATCH_SIM_MED;
4587 if (options->duplicates_match == DUPE_MATCH_SIM_LOW) dw->match_mask = DUPE_MATCH_SIM_LOW;
4588 if (options->duplicates_match == DUPE_MATCH_SIM_CUSTOM) dw->match_mask = DUPE_MATCH_SIM_CUSTOM;
4589 if (options->duplicates_match == DUPE_MATCH_NAME_CI) dw->match_mask = DUPE_MATCH_NAME_CI;
4590 if (options->duplicates_match == DUPE_MATCH_NAME_CONTENT) dw->match_mask = DUPE_MATCH_NAME_CONTENT;
4591 if (options->duplicates_match == DUPE_MATCH_NAME_CI_CONTENT) dw->match_mask = DUPE_MATCH_NAME_CI_CONTENT;
4592 if (options->duplicates_match == DUPE_MATCH_ALL) dw->match_mask = DUPE_MATCH_ALL;
4594 dw->window = window_new(GTK_WINDOW_TOPLEVEL, "dupe", NULL, NULL, _("Find duplicates"));
4595 DEBUG_NAME(dw->window);
4597 geometry.min_width = DEFAULT_MINIMAL_WINDOW_SIZE;
4598 geometry.min_height = DEFAULT_MINIMAL_WINDOW_SIZE;
4599 geometry.base_width = DUPE_DEF_WIDTH;
4600 geometry.base_height = DUPE_DEF_HEIGHT;
4601 gtk_window_set_geometry_hints(GTK_WINDOW(dw->window), NULL, &geometry,
4602 GDK_HINT_MIN_SIZE | GDK_HINT_BASE_SIZE);
4604 if (lw && options->save_window_positions)
4606 gtk_window_set_default_size(GTK_WINDOW(dw->window), lw->options.dupe_window.w, lw->options.dupe_window.h);
4607 gtk_window_move(GTK_WINDOW(dw->window), lw->options.dupe_window.x, lw->options.dupe_window.y);
4611 gtk_window_set_default_size(GTK_WINDOW(dw->window), DUPE_DEF_WIDTH, DUPE_DEF_HEIGHT);
4614 gtk_window_set_resizable(GTK_WINDOW(dw->window), TRUE);
4615 gtk_container_set_border_width(GTK_CONTAINER(dw->window), 0);
4617 g_signal_connect(G_OBJECT(dw->window), "delete_event",
4618 G_CALLBACK(dupe_window_delete), dw);
4619 g_signal_connect(G_OBJECT(dw->window), "key_press_event",
4620 G_CALLBACK(dupe_window_keypress_cb), dw);
4622 vbox = gtk_vbox_new(FALSE, 0);
4623 gtk_container_add(GTK_CONTAINER(dw->window), vbox);
4624 gtk_widget_show(vbox);
4626 dw->table = gtk_table_new(1, 3, FALSE);
4627 gtk_box_pack_start(GTK_BOX(vbox), dw->table, TRUE, TRUE, 0);
4628 gtk_widget_show(dw->table);
4630 scrolled = gtk_scrolled_window_new(NULL, NULL);
4631 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN);
4632 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
4633 gtk_table_attach_defaults(GTK_TABLE(dw->table), scrolled, 0, 2, 0, 1);
4634 gtk_widget_show(scrolled);
4636 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);
4637 dw->listview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
4638 g_object_unref(store);
4640 dw->sortable = GTK_TREE_SORTABLE(store);
4642 gtk_tree_sortable_set_sort_func(dw->sortable, DUPE_COLUMN_RANK, column_sort_cb, dw->sortable, NULL);
4643 gtk_tree_sortable_set_sort_func(dw->sortable, DUPE_COLUMN_SET, default_sort_cb, dw->sortable, NULL);
4644 gtk_tree_sortable_set_sort_func(dw->sortable, DUPE_COLUMN_THUMB, default_sort_cb, dw->sortable, NULL);
4645 gtk_tree_sortable_set_sort_func(dw->sortable, DUPE_COLUMN_NAME, column_sort_cb, dw->sortable, NULL);
4646 gtk_tree_sortable_set_sort_func(dw->sortable, DUPE_COLUMN_SIZE, column_sort_cb, dw->sortable, NULL);
4647 gtk_tree_sortable_set_sort_func(dw->sortable, DUPE_COLUMN_DATE, column_sort_cb, dw->sortable, NULL);
4648 gtk_tree_sortable_set_sort_func(dw->sortable, DUPE_COLUMN_DIMENSIONS, column_sort_cb, dw->sortable, NULL);
4649 gtk_tree_sortable_set_sort_func(dw->sortable, DUPE_COLUMN_PATH, column_sort_cb, dw->sortable, NULL);
4651 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dw->listview));
4652 gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_MULTIPLE);
4653 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(dw->listview), TRUE);
4654 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(dw->listview), FALSE);
4656 dupe_listview_add_column(dw, dw->listview, DUPE_COLUMN_RANK, _("Rank"), FALSE, TRUE);
4657 dupe_listview_add_column(dw, dw->listview, DUPE_COLUMN_THUMB, _("Thumb"), TRUE, FALSE);
4658 dupe_listview_add_column(dw, dw->listview, DUPE_COLUMN_NAME, _("Name"), FALSE, FALSE);
4659 dupe_listview_add_column(dw, dw->listview, DUPE_COLUMN_SIZE, _("Size"), FALSE, TRUE);
4660 dupe_listview_add_column(dw, dw->listview, DUPE_COLUMN_DATE, _("Date"), FALSE, TRUE);
4661 dupe_listview_add_column(dw, dw->listview, DUPE_COLUMN_DIMENSIONS, _("Dimensions"), FALSE, FALSE);
4662 dupe_listview_add_column(dw, dw->listview, DUPE_COLUMN_PATH, _("Path"), FALSE, FALSE);
4663 dupe_listview_add_column(dw, dw->listview, DUPE_COLUMN_SET, _("Set"), FALSE, FALSE);
4665 g_signal_connect(gtk_tree_view_get_column(GTK_TREE_VIEW(dw->listview), DUPE_COLUMN_RANK - 1), "clicked", (GCallback)column_clicked_cb, dw);
4666 g_signal_connect(gtk_tree_view_get_column(GTK_TREE_VIEW(dw->listview), DUPE_COLUMN_NAME - 1), "clicked", (GCallback)column_clicked_cb, dw);
4667 g_signal_connect(gtk_tree_view_get_column(GTK_TREE_VIEW(dw->listview), DUPE_COLUMN_SIZE - 1), "clicked", (GCallback)column_clicked_cb, dw);
4668 g_signal_connect(gtk_tree_view_get_column(GTK_TREE_VIEW(dw->listview), DUPE_COLUMN_DATE - 1), "clicked", (GCallback)column_clicked_cb, dw);
4669 g_signal_connect(gtk_tree_view_get_column(GTK_TREE_VIEW(dw->listview), DUPE_COLUMN_DIMENSIONS - 1), "clicked", (GCallback)column_clicked_cb, dw);
4670 g_signal_connect(gtk_tree_view_get_column(GTK_TREE_VIEW(dw->listview), DUPE_COLUMN_PATH - 1), "clicked", (GCallback)column_clicked_cb, dw);
4672 gtk_container_add(GTK_CONTAINER(scrolled), dw->listview);
4673 gtk_widget_show(dw->listview);
4675 dw->second_vbox = gtk_vbox_new(FALSE, 0);
4676 gtk_table_attach_defaults(GTK_TABLE(dw->table), dw->second_vbox, 2, 3, 0, 1);
4679 gtk_table_set_col_spacings(GTK_TABLE(dw->table), PREF_PAD_GAP);
4680 gtk_widget_show(dw->second_vbox);
4684 gtk_table_set_col_spacings(GTK_TABLE(dw->table), 0);
4687 scrolled = gtk_scrolled_window_new(NULL, NULL);
4688 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN);
4689 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
4690 gtk_box_pack_start(GTK_BOX(dw->second_vbox), scrolled, TRUE, TRUE, 0);
4691 gtk_widget_show(scrolled);
4693 store = gtk_list_store_new(2, G_TYPE_POINTER, G_TYPE_STRING);
4694 dw->second_listview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
4696 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dw->second_listview));
4697 gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_MULTIPLE);
4699 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(dw->second_listview), TRUE);
4700 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(dw->second_listview), FALSE);
4702 dupe_listview_add_column(dw, dw->second_listview, 1, _("Compare to:"), FALSE, FALSE);
4704 gtk_container_add(GTK_CONTAINER(scrolled), dw->second_listview);
4705 gtk_widget_show(dw->second_listview);
4707 dw->second_status_label = gtk_label_new("");
4708 gtk_box_pack_start(GTK_BOX(dw->second_vbox), dw->second_status_label, FALSE, FALSE, 0);
4709 gtk_widget_show(dw->second_status_label);
4711 pref_line(dw->second_vbox, GTK_ORIENTATION_HORIZONTAL);
4713 status_box = gtk_hbox_new(FALSE, 0);
4714 gtk_box_pack_start(GTK_BOX(vbox), status_box, FALSE, FALSE, 0);
4715 gtk_widget_show(status_box);
4717 frame = gtk_frame_new(NULL);
4719 gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN);
4720 gtk_box_pack_start(GTK_BOX(status_box), frame, TRUE, TRUE, 0);
4721 gtk_widget_show(frame);
4723 dw->status_label = gtk_label_new("");
4724 gtk_container_add(GTK_CONTAINER(frame), dw->status_label);
4725 gtk_widget_show(dw->status_label);
4727 dw->extra_label = gtk_progress_bar_new();
4728 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(dw->extra_label), 0.0);
4729 #if GTK_CHECK_VERSION(3,0,0)
4730 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(dw->extra_label), "");
4731 gtk_progress_bar_set_show_text(GTK_PROGRESS_BAR(dw->extra_label), TRUE);
4733 gtk_box_pack_start(GTK_BOX(status_box), dw->extra_label, FALSE, FALSE, PREF_PAD_SPACE);
4734 gtk_widget_show(dw->extra_label);
4736 controls_box = pref_box_new(vbox, FALSE, GTK_ORIENTATION_HORIZONTAL, 0);
4737 dw->controls_box = controls_box;
4739 dw->button_thumbs = gtk_check_button_new_with_label(_("Thumbnails"));
4740 dw->show_thumbs = options->duplicates_thumbnails;
4741 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dw->button_thumbs), dw->show_thumbs);
4742 g_signal_connect(G_OBJECT(dw->button_thumbs), "toggled",
4743 G_CALLBACK(dupe_window_show_thumb_cb), dw);
4744 gtk_box_pack_start(GTK_BOX(controls_box), dw->button_thumbs, FALSE, FALSE, PREF_PAD_SPACE);
4745 gtk_widget_show(dw->button_thumbs);
4747 label = gtk_label_new(_("Compare by:"));
4748 gtk_box_pack_start(GTK_BOX(controls_box), label, FALSE, FALSE, PREF_PAD_SPACE);
4749 gtk_widget_show(label);
4751 dupe_menu_setup(dw);
4752 gtk_box_pack_start(GTK_BOX(controls_box), dw->combo, FALSE, FALSE, 0);
4753 gtk_widget_show(dw->combo);
4755 label = gtk_label_new(_("Custom Threshold"));
4756 gtk_box_pack_start(GTK_BOX(controls_box), label, FALSE, FALSE, PREF_PAD_SPACE);
4757 gtk_widget_show(label);
4758 dw->custom_threshold = gtk_spin_button_new_with_range(1, 100, 1);
4759 gtk_widget_set_tooltip_text(GTK_WIDGET(dw->custom_threshold), "Custom similarity threshold\n(Use tab key to set value)");
4760 gtk_spin_button_set_value(GTK_SPIN_BUTTON(dw->custom_threshold), options->duplicates_similarity_threshold);
4761 g_signal_connect(G_OBJECT(dw->custom_threshold), "value_changed", G_CALLBACK(dupe_window_custom_threshold_cb), dw);
4762 gtk_box_pack_start(GTK_BOX(controls_box), dw->custom_threshold, FALSE, FALSE, PREF_PAD_SPACE);
4763 gtk_widget_show(dw->custom_threshold);
4765 button = gtk_check_button_new_with_label(_("Sort"));
4766 gtk_widget_set_tooltip_text(GTK_WIDGET(button), "Sort by group totals");
4767 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), options->sort_totals);
4768 g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(dupe_sort_totals_toggle_cb), dw);
4769 gtk_box_pack_start(GTK_BOX(controls_box), button, FALSE, FALSE, PREF_PAD_SPACE);
4770 gtk_widget_show(button);
4772 dw->button_rotation_invariant = gtk_check_button_new_with_label(_("Ignore Orientation"));
4773 gtk_widget_set_tooltip_text(GTK_WIDGET(dw->button_rotation_invariant), "Ignore image orientation");
4774 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dw->button_rotation_invariant), options->rot_invariant_sim);
4775 g_signal_connect(G_OBJECT(dw->button_rotation_invariant), "toggled",
4776 G_CALLBACK(dupe_window_rotation_invariant_cb), dw);
4777 gtk_box_pack_start(GTK_BOX(controls_box), dw->button_rotation_invariant, FALSE, FALSE, PREF_PAD_SPACE);
4778 gtk_widget_show(dw->button_rotation_invariant);
4780 button = gtk_check_button_new_with_label(_("Compare two file sets"));
4781 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), dw->second_set);
4782 g_signal_connect(G_OBJECT(button), "toggled",
4783 G_CALLBACK(dupe_second_set_toggle_cb), dw);
4784 gtk_box_pack_start(GTK_BOX(controls_box), button, FALSE, FALSE, PREF_PAD_SPACE);
4785 gtk_widget_show(button);
4787 button_box = gtk_hbox_new(FALSE, 0);
4788 gtk_box_pack_start(GTK_BOX(vbox), button_box, FALSE, FALSE, 0);
4789 gtk_widget_show(button_box);
4791 hbox = gtk_hbutton_box_new();
4792 gtk_button_box_set_layout(GTK_BUTTON_BOX(hbox), GTK_BUTTONBOX_END);
4793 gtk_box_set_spacing(GTK_BOX(hbox), PREF_PAD_SPACE);
4794 gtk_box_pack_end(GTK_BOX(button_box), hbox, FALSE, FALSE, 0);
4795 gtk_widget_show(hbox);
4797 button = pref_button_new(NULL, GTK_STOCK_HELP, NULL, FALSE, G_CALLBACK(dupe_help_cb), NULL);
4798 gtk_container_add(GTK_CONTAINER(hbox), button);
4799 gtk_widget_set_can_default(button, TRUE);
4800 gtk_widget_show(button);
4802 button = pref_button_new(NULL, GTK_STOCK_STOP, NULL, FALSE, G_CALLBACK(dupe_check_stop_cb), dw);
4803 gtk_container_add(GTK_CONTAINER(hbox), button);
4804 gtk_widget_set_can_default(button, TRUE);
4805 gtk_widget_show(button);
4807 button = pref_button_new(NULL, GTK_STOCK_CLOSE, NULL, FALSE, G_CALLBACK(dupe_window_close_cb), dw);
4808 gtk_container_add(GTK_CONTAINER(hbox), button);
4809 gtk_widget_set_can_default(button, TRUE);
4810 gtk_widget_grab_default(button);
4811 gtk_widget_show(button);
4814 /* order is important here, dnd_init should be seeing mouse
4815 * presses before we possibly handle (and stop) the signal
4817 g_signal_connect(G_OBJECT(dw->listview), "button_press_event",
4818 G_CALLBACK(dupe_listview_press_cb), dw);
4819 g_signal_connect(G_OBJECT(dw->listview), "button_release_event",
4820 G_CALLBACK(dupe_listview_release_cb), dw);
4821 g_signal_connect(G_OBJECT(dw->second_listview), "button_press_event",
4822 G_CALLBACK(dupe_listview_press_cb), dw);
4823 g_signal_connect(G_OBJECT(dw->second_listview), "button_release_event",
4824 G_CALLBACK(dupe_listview_release_cb), dw);
4826 gtk_widget_show(dw->window);
4828 dupe_listview_set_height(dw->listview, dw->show_thumbs);
4829 g_signal_emit_by_name(G_OBJECT(dw->combo), "changed");
4831 dupe_window_update_count(dw, TRUE);
4832 dupe_window_update_progress(dw, NULL, 0.0, FALSE);
4834 dupe_window_list = g_list_append(dupe_window_list, dw);
4836 file_data_register_notify_func(dupe_notify_cb, dw, NOTIFY_PRIORITY_MEDIUM);
4838 g_mutex_init(&dw->thread_count_mutex);
4839 g_mutex_init(&dw->search_matches_mutex);
4840 dw->dupe_comparison_thread_pool = g_thread_pool_new(dupe_comparison_func, dw, options->threads.duplicates, FALSE, NULL);
4846 *-------------------------------------------------------------------
4848 *-------------------------------------------------------------------
4856 static void confirm_dir_list_cancel(GtkWidget *widget, gpointer data)
4861 static void confirm_dir_list_add(GtkWidget *widget, gpointer data)
4863 CDupeConfirmD *d = data;
4866 dupe_window_add_files(d->dw, d->list, FALSE);
4871 FileData *fd = work->data;
4873 if (isdir(fd->path))
4877 filelist_read(fd, &list, NULL);
4878 list = filelist_filter(list, FALSE);
4881 dupe_window_add_files(d->dw, list, FALSE);
4882 filelist_free(list);
4888 static void confirm_dir_list_recurse(GtkWidget *widget, gpointer data)
4890 CDupeConfirmD *d = data;
4891 dupe_window_add_files(d->dw, d->list, TRUE);
4894 static void confirm_dir_list_skip(GtkWidget *widget, gpointer data)
4896 CDupeConfirmD *d = data;
4897 dupe_window_add_files(d->dw, d->list, FALSE);
4900 static void confirm_dir_list_destroy(GtkWidget *widget, gpointer data)
4902 CDupeConfirmD *d = data;
4903 filelist_free(d->list);
4907 static GtkWidget *dupe_confirm_dir_list(DupeWindow *dw, GList *list)
4912 d = g_new0(CDupeConfirmD, 1);
4916 menu = popup_menu_short_lived();
4917 g_signal_connect(G_OBJECT(menu), "destroy",
4918 G_CALLBACK(confirm_dir_list_destroy), d);
4920 menu_item_add_stock(menu, _("Dropped list includes folders."), GTK_STOCK_DND_MULTIPLE, NULL, NULL);
4921 menu_item_add_divider(menu);
4922 menu_item_add_stock(menu, _("_Add contents"), GTK_STOCK_OK, G_CALLBACK(confirm_dir_list_add), d);
4923 menu_item_add_stock(menu, _("Add contents _recursive"), GTK_STOCK_ADD, G_CALLBACK(confirm_dir_list_recurse), d);
4924 menu_item_add_stock(menu, _("_Skip folders"), GTK_STOCK_REMOVE, G_CALLBACK(confirm_dir_list_skip), d);
4925 menu_item_add_divider(menu);
4926 menu_item_add_stock(menu, _("Cancel"), GTK_STOCK_CANCEL, G_CALLBACK(confirm_dir_list_cancel), d);
4932 *-------------------------------------------------------------------
4934 *-------------------------------------------------------------------
4937 static GtkTargetEntry dupe_drag_types[] = {
4938 { "text/uri-list", 0, TARGET_URI_LIST },
4939 { "text/plain", 0, TARGET_TEXT_PLAIN }
4941 static gint n_dupe_drag_types = 2;
4943 static GtkTargetEntry dupe_drop_types[] = {
4944 { TARGET_APP_COLLECTION_MEMBER_STRING, 0, TARGET_APP_COLLECTION_MEMBER },
4945 { "text/uri-list", 0, TARGET_URI_LIST }
4947 static gint n_dupe_drop_types = 2;
4949 static void dupe_dnd_data_set(GtkWidget *widget, GdkDragContext *context,
4950 GtkSelectionData *selection_data, guint info,
4951 guint time, gpointer data)
4953 DupeWindow *dw = data;
4958 case TARGET_URI_LIST:
4959 case TARGET_TEXT_PLAIN:
4960 list = dupe_listview_get_selection(dw, widget);
4962 uri_selection_data_set_uris_from_filelist(selection_data, list);
4963 filelist_free(list);
4970 static void dupe_dnd_data_get(GtkWidget *widget, GdkDragContext *context,
4972 GtkSelectionData *selection_data, guint info,
4973 guint time, gpointer data)
4975 DupeWindow *dw = data;
4980 if (dw->add_files_queue_id > 0)
4982 warning_dialog(_("Find duplicates"), _("Please wait for the current file selection to be loaded."), GTK_STOCK_DIALOG_INFO, dw->window);
4987 source = gtk_drag_get_source_widget(context);
4988 if (source == dw->listview || source == dw->second_listview) return;
4990 dw->second_drop = (dw->second_set && widget == dw->second_listview);
4994 case TARGET_APP_COLLECTION_MEMBER:
4995 collection_from_dnd_data((gchar *)gtk_selection_data_get_data(selection_data), &list, NULL);
4997 case TARGET_URI_LIST:
4998 list = uri_filelist_from_gtk_selection_data(selection_data);
5002 FileData *fd = work->data;
5003 if (isdir(fd->path))
5006 menu = dupe_confirm_dir_list(dw, list);
5007 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 0, time);
5020 dupe_window_add_files(dw, list, FALSE);
5021 filelist_free(list);
5025 static void dupe_dest_set(GtkWidget *widget, gboolean enable)
5029 gtk_drag_dest_set(widget,
5030 GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_HIGHLIGHT | GTK_DEST_DEFAULT_DROP,
5031 dupe_drop_types, n_dupe_drop_types,
5032 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_ASK);
5037 gtk_drag_dest_unset(widget);
5041 static void dupe_dnd_begin(GtkWidget *widget, GdkDragContext *context, gpointer data)
5043 DupeWindow *dw = data;
5044 dupe_dest_set(dw->listview, FALSE);
5045 dupe_dest_set(dw->second_listview, FALSE);
5047 if (dw->click_item && !dupe_listview_item_is_selected(dw, dw->click_item, widget))
5049 GtkListStore *store;
5052 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(widget)));
5053 if (dupe_listview_find_item(store, dw->click_item, &iter) >= 0)
5055 GtkTreeSelection *selection;
5058 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
5059 gtk_tree_selection_unselect_all(selection);
5060 gtk_tree_selection_select_iter(selection, &iter);
5062 tpath = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter);
5063 gtk_tree_view_set_cursor(GTK_TREE_VIEW(widget), tpath, NULL, FALSE);
5064 gtk_tree_path_free(tpath);
5068 if (dw->show_thumbs &&
5069 widget == dw->listview &&
5070 dw->click_item && dw->click_item->pixbuf)
5072 GtkTreeSelection *selection;
5075 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
5076 items = gtk_tree_selection_count_selected_rows(selection);
5077 dnd_set_drag_icon(widget, context, dw->click_item->pixbuf, items);
5081 static void dupe_dnd_end(GtkWidget *widget, GdkDragContext *context, gpointer data)
5083 DupeWindow *dw = data;
5084 dupe_dest_set(dw->listview, TRUE);
5085 dupe_dest_set(dw->second_listview, TRUE);
5088 static void dupe_dnd_init(DupeWindow *dw)
5090 gtk_drag_source_set(dw->listview, GDK_BUTTON1_MASK | GDK_BUTTON2_MASK,
5091 dupe_drag_types, n_dupe_drag_types,
5092 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK);
5093 g_signal_connect(G_OBJECT(dw->listview), "drag_data_get",
5094 G_CALLBACK(dupe_dnd_data_set), dw);
5095 g_signal_connect(G_OBJECT(dw->listview), "drag_begin",
5096 G_CALLBACK(dupe_dnd_begin), dw);
5097 g_signal_connect(G_OBJECT(dw->listview), "drag_end",
5098 G_CALLBACK(dupe_dnd_end), dw);
5100 dupe_dest_set(dw->listview, TRUE);
5101 g_signal_connect(G_OBJECT(dw->listview), "drag_data_received",
5102 G_CALLBACK(dupe_dnd_data_get), dw);
5104 gtk_drag_source_set(dw->second_listview, GDK_BUTTON1_MASK | GDK_BUTTON2_MASK,
5105 dupe_drag_types, n_dupe_drag_types,
5106 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK);
5107 g_signal_connect(G_OBJECT(dw->second_listview), "drag_data_get",
5108 G_CALLBACK(dupe_dnd_data_set), dw);
5109 g_signal_connect(G_OBJECT(dw->second_listview), "drag_begin",
5110 G_CALLBACK(dupe_dnd_begin), dw);
5111 g_signal_connect(G_OBJECT(dw->second_listview), "drag_end",
5112 G_CALLBACK(dupe_dnd_end), dw);
5114 dupe_dest_set(dw->second_listview, TRUE);
5115 g_signal_connect(G_OBJECT(dw->second_listview), "drag_data_received",
5116 G_CALLBACK(dupe_dnd_data_get), dw);
5120 *-------------------------------------------------------------------
5121 * maintenance (move, delete, etc.)
5122 *-------------------------------------------------------------------
5125 static void dupe_notify_cb(FileData *fd, NotifyType type, gpointer data)
5127 DupeWindow *dw = data;
5129 if (!(type & NOTIFY_CHANGE) || !fd->change) return;
5131 DEBUG_1("Notify dupe: %s %04x", fd->path, type);
5133 switch (fd->change->type)
5135 case FILEDATA_CHANGE_MOVE:
5136 case FILEDATA_CHANGE_RENAME:
5137 dupe_item_update_fd(dw, fd);
5139 case FILEDATA_CHANGE_COPY:
5141 case FILEDATA_CHANGE_DELETE:
5142 /* Update the UI only once, after the operation finishes */
5144 case FILEDATA_CHANGE_UNSPECIFIED:
5145 case FILEDATA_CHANGE_WRITE_METADATA:
5152 * @brief Refresh window after a file delete operation
5153 * @param success (ud->phase != UTILITY_PHASE_CANCEL) #file_util_dialog_run
5154 * @param dest_path Not used
5155 * @param data #DupeWindow
5157 * If the window is refreshed after each file of a large set is deleted,
5158 * the UI slows to an unacceptable level. The #FileUtilDoneFunc is used
5159 * to call this function once, when the entire delete operation is completed.
5161 static void delete_finished_cb(gboolean success, const gchar *dest_path, gpointer data)
5163 DupeWindow *dw = data;
5170 dupe_window_remove_selection(dw, dw->listview);
5174 *-------------------------------------------------------------------
5175 * Export duplicates data
5176 *-------------------------------------------------------------------
5184 typedef struct _ExportDupesData ExportDupesData;
5185 struct _ExportDupesData
5188 SeparatorType separator;
5189 DupeWindow *dupewindow;
5192 static void export_duplicates_close(ExportDupesData *edd)
5194 if (edd->dialog) file_dialog_close(edd->dialog);
5198 static void export_duplicates_data_cancel_cb(FileDialog *fdlg, gpointer data)
5200 ExportDupesData *edd = data;
5202 export_duplicates_close(edd);
5205 static void export_duplicates_data_save_cb(FileDialog *fdlg, gpointer data)
5207 ExportDupesData *edd = data;
5208 GError *error = NULL;
5209 GtkTreeModel *store;
5212 GFileOutputStream *gfstream;
5214 GString *output_string;
5218 GtkTreeSelection *selection;
5223 gboolean color_old = FALSE;
5224 gboolean color_new = FALSE;
5228 history_list_add_to_key("export_duplicates", fdlg->dest_path, -1);
5230 out_file = g_file_new_for_path(fdlg->dest_path);
5232 gfstream = g_file_replace(out_file, NULL, TRUE, G_FILE_CREATE_NONE, NULL, &error);
5235 log_printf(_("Error creating Export duplicates data file: Error: %s\n"), error->message);
5236 g_error_free(error);
5240 sep = g_strdup((edd->separator == EXPORT_CSV) ? "," : "\t");
5241 output_string = g_string_new(g_strjoin(sep, _("Match"), _("Group"), _("Similarity"), _("Set"), _("Thumbnail"), _("Name"), _("Size"), _("Date"), _("Width"), _("Height"), _("Path\n"), NULL));
5243 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(edd->dupewindow->listview));
5244 slist = gtk_tree_selection_get_selected_rows(selection, &store);
5248 gtk_tree_model_get_iter(store, &iter, tpath);
5249 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, DUPE_COLUMN_COLOR, &color_new, -1);
5250 color_old = !color_new;
5256 gtk_tree_model_get_iter(store, &iter, tpath);
5258 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, DUPE_COLUMN_POINTER, &di, -1);
5260 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, DUPE_COLUMN_COLOR, &color_new, -1);
5261 if (color_new != color_old)
5265 color_old = color_new;
5266 output_string = g_string_append(output_string, g_strdup_printf("%d", match_count));
5267 output_string = g_string_append(output_string, sep);
5269 if ((dupe_match_find_parent(edd->dupewindow, di) == di))
5271 output_string = g_string_append(output_string, "1");
5275 output_string = g_string_append(output_string, "2");
5277 output_string = g_string_append(output_string, sep);
5279 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, DUPE_COLUMN_RANK, &rank, -1);
5280 rank_split = g_strsplit_set(rank, " [(", -1);
5281 if (rank_split[0] == NULL)
5283 output_string = g_string_append(output_string, "");
5287 output_string = g_string_append(output_string, g_strdup_printf("%s", rank_split[0]));
5289 output_string = g_string_append(output_string, sep);
5291 g_strfreev(rank_split);
5293 output_string = g_string_append(output_string, g_strdup_printf("%d", (di->second + 1)));
5294 output_string = g_string_append(output_string, sep);
5296 thumb_cache = cache_find_location(CACHE_TYPE_THUMB, di->fd->path);
5299 output_string = g_string_append(output_string, thumb_cache);
5300 g_free(thumb_cache);
5304 output_string = g_string_append(output_string, "");
5306 output_string = g_string_append(output_string, sep);
5308 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, DUPE_COLUMN_NAME, &name, -1);
5309 output_string = g_string_append(output_string, name);
5310 output_string = g_string_append(output_string, sep);
5313 output_string = g_string_append(output_string, g_strdup_printf("%"PRIu64, di->fd->size));
5314 output_string = g_string_append(output_string, sep);
5315 output_string = g_string_append(output_string, text_from_time(di->fd->date));
5316 output_string = g_string_append(output_string, sep);
5317 output_string = g_string_append(output_string, g_strdup_printf("%d", (di->width ? di->width : 0)));
5318 output_string = g_string_append(output_string, sep);
5319 output_string = g_string_append(output_string, g_strdup_printf("%d", (di->height ? di->height : 0)));
5320 output_string = g_string_append(output_string, sep);
5321 output_string = g_string_append(output_string, di->fd->path);
5322 output_string = g_string_append_c(output_string, '\n');
5327 g_output_stream_write(G_OUTPUT_STREAM(gfstream), output_string->str, strlen(output_string->str), NULL, &error);
5330 g_string_free(output_string, TRUE);
5331 g_object_unref(gfstream);
5332 g_object_unref(out_file);
5334 export_duplicates_close(edd);
5337 static void pop_menu_export(GList *selection_list, gpointer dupe_window, gpointer data)
5339 const gint index = GPOINTER_TO_INT(data);
5340 DupeWindow *dw = dupe_window;
5341 gchar *title = "Export duplicates data";
5342 gchar *default_path = "/tmp/";
5343 gchar *file_extension;
5344 const gchar *stock_id;
5345 ExportDupesData *edd;
5346 const gchar *previous_path;
5348 edd = g_new0(ExportDupesData, 1);
5349 edd->dialog = file_util_file_dlg(title, "export_duplicates", NULL, export_duplicates_data_cancel_cb, edd);
5354 edd->separator = EXPORT_CSV;
5355 file_extension = g_strdup(".csv");
5358 edd->separator = EXPORT_TSV;
5359 file_extension = g_strdup(".tsv");
5365 stock_id = GTK_STOCK_SAVE;
5367 generic_dialog_add_message(GENERIC_DIALOG(edd->dialog), NULL, title, NULL, FALSE);
5368 file_dialog_add_button(edd->dialog, stock_id, NULL, export_duplicates_data_save_cb, TRUE);
5370 previous_path = history_list_find_last_path_by_key("export_duplicates");
5372 file_dialog_add_path_widgets(edd->dialog, default_path, previous_path, "export_duplicates", file_extension, _("Export Files"));
5374 edd->dupewindow = dw;
5376 gtk_widget_show(GENERIC_DIALOG(edd->dialog)->dialog);
5378 g_free(file_extension);
5381 static void dupe_pop_menu_export_cb(GtkWidget *widget, gpointer data)
5384 GList *selection_list;
5386 dw = submenu_item_get_data(widget);
5387 selection_list = dupe_listview_get_selection(dw, dw->listview);
5388 pop_menu_export(selection_list, dw, data);
5390 filelist_free(selection_list);
5393 static GtkWidget *submenu_add_export(GtkWidget *menu, GtkWidget **menu_item, GCallback func, gpointer data)
5398 item = menu_item_add(menu, _("Export"), NULL, NULL);
5400 submenu = gtk_menu_new();
5401 g_object_set_data(G_OBJECT(submenu), "submenu_data", data);
5403 menu_item_add_stock_sensitive(submenu, _("Export to csv"),
5404 GTK_STOCK_INDEX, TRUE, G_CALLBACK(func), GINT_TO_POINTER(0));
5405 menu_item_add_stock_sensitive(submenu, _("Export to tab-delimited"),
5406 GTK_STOCK_INDEX, TRUE, G_CALLBACK(func), GINT_TO_POINTER(1));
5408 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu);
5409 if (menu_item) *menu_item = item;
5414 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */