2 * Copyright (C) 2005 John Ellis
3 * Copyright (C) 2008 - 2016 The Geeqie Team
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 #include "collect-table.h"
33 #include "history_list.h"
34 #include "image-load.h"
37 #include "layout_image.h"
38 #include "layout_util.h"
42 #include "pixbuf_util.h"
45 #include "ui_fileops.h"
48 #include "ui_tree_edit.h"
49 #include "uri_utils.h"
53 #include <gdk/gdkkeysyms.h> /* for keyboard values */
59 #define DUPE_DEF_WIDTH 800
60 #define DUPE_DEF_HEIGHT 400
61 #define DUPE_PROGRESS_PULSE_STEP 0.0001
63 /** column assignment order (simply change them here)
66 DUPE_COLUMN_POINTER = 0,
72 DUPE_COLUMN_DIMENSIONS,
76 DUPE_COLUMN_COUNT /**< total columns */
85 typedef struct _DupeQueueItem DupeQueueItem;
86 /** Used for similarity checks. One for each item pushed
87 * onto the thread pool.
93 GList *work; /**< pointer into \a dw->list or \a dw->second_list (#DupeItem) */
94 gint index; /**< The order items pushed onto thread pool. Used to sort returned matches */
97 typedef struct _DupeSearchMatch DupeSearchMatch;
98 /** Used for similarity checks thread. One for each pair match found.
100 struct _DupeSearchMatch
102 DupeItem *a; /**< \a a / \a b matched pair found */
103 DupeItem *b; /**< \a a / \a b matched pair found */
105 gint index; /**< The order items pushed onto thread pool. Used to sort returned matches */
108 static DupeMatchType param_match_mask;
109 static GList *dupe_window_list = NULL; /**< list of open DupeWindow *s */
112 * Well, after adding the 'compare two sets' option things got a little sloppy in here
113 * because we have to account for two 'modes' everywhere. (be careful).
116 static void dupe_match_unlink(DupeItem *a, DupeItem *b);
117 static DupeItem *dupe_match_find_parent(DupeWindow *dw, DupeItem *child);
119 static gint dupe_match(DupeItem *a, DupeItem *b, DupeMatchType mask, gdouble *rank, gint fast);
121 static void dupe_thumb_step(DupeWindow *dw);
122 static gint dupe_check_cb(gpointer data);
124 static void dupe_second_add(DupeWindow *dw, DupeItem *di);
125 static void dupe_second_remove(DupeWindow *dw, DupeItem *di);
126 static GtkWidget *dupe_menu_popup_second(DupeWindow *dw, DupeItem *di);
128 static void dupe_dnd_init(DupeWindow *dw);
130 static void dupe_notify_cb(FileData *fd, NotifyType type, gpointer data);
131 static void delete_finished_cb(gboolean success, const gchar *dest_path, gpointer data);
133 static GtkWidget *submenu_add_export(GtkWidget *menu, GtkWidget **menu_item, GCallback func, gpointer data);
134 static void dupe_pop_menu_export_cb(GtkWidget *widget, gpointer data);
136 static void dupe_init_list_cache(DupeWindow *dw);
137 static void dupe_destroy_list_cache(DupeWindow *dw);
138 static gboolean dupe_insert_in_list_cache(DupeWindow *dw, FileData *fd);
140 static void dupe_match_link(DupeItem *a, DupeItem *b, gdouble rank);
141 static gint dupe_match_link_exists(DupeItem *child, DupeItem *parent);
144 * @brief The function run in threads for similarity checks
145 * @param d1 #DupeQueueItem
146 * @param d2 #DupeWindow
148 * Used only for similarity checks.\n
149 * Search \a dqi->list for \a dqi->needle and if a match is
150 * found, create a #DupeSearchMatch and add to \a dw->search_matches list\n
151 * If \a dw->abort is set, just increment \a dw->thread_count
153 static void dupe_comparison_func(gpointer d1, gpointer d2)
155 DupeQueueItem *dqi = d1;
157 DupeSearchMatch *dsm;
159 GList *matches = NULL;
164 GList *work = dqi->work;
169 /* forward for second set, back for simple compare */
179 if (dupe_match(di, dqi->needle, dqi->dw->match_mask, &rank, TRUE))
181 dsm = g_new0(DupeSearchMatch, 1);
183 dsm->b = dqi->needle;
185 matches = g_list_prepend(matches, dsm);
186 dsm->index = dqi->index;
195 matches = g_list_reverse(matches);
196 g_mutex_lock(&dw->search_matches_mutex);
197 dw->search_matches = g_list_concat(dw->search_matches, matches);
198 g_mutex_unlock(&dw->search_matches_mutex);
201 g_mutex_lock(&dw->thread_count_mutex);
203 g_mutex_unlock(&dw->thread_count_mutex);
208 * ------------------------------------------------------------------
210 * ------------------------------------------------------------------
214 * @brief Update display of status label
220 static void dupe_window_update_count(DupeWindow *dw, gboolean count_only)
226 text = g_strdup(_("Drop files to compare them."));
230 text = g_strdup_printf(_("%d files"), g_list_length(dw->list));
234 text = g_strdup_printf(_("%d matches found in %d files"), g_list_length(dw->dupes), g_list_length(dw->list));
239 gchar *buf = g_strconcat(text, " ", _("[set 1]"), NULL);
243 gtk_label_set_text(GTK_LABEL(dw->status_label), text);
249 * @brief Returns time in µsec since Epoch
254 static guint64 msec_time(void)
258 if (gettimeofday(&tv, NULL) == -1) return 0;
260 return (guint64)tv.tv_sec * 1000000 + (guint64)tv.tv_usec;
263 static gint dupe_iterations(gint n)
265 return (n * ((n + 1) / 2));
275 * If \a status is blank, clear status bar text and set progress to zero. \n
276 * If \a force is not set, after 2 secs has elapsed, update time-to-go every 250 ms.
278 static void dupe_window_update_progress(DupeWindow *dw, const gchar *status, gdouble value, gboolean force)
280 const gchar *status_text;
284 guint64 new_time = 0;
286 if (dw->setup_n % 10 == 0)
288 new_time = msec_time() - dw->setup_time;
293 dw->setup_count > 0 &&
301 if (new_time - dw->setup_time_count < 250000) return;
302 dw->setup_time_count = new_time;
309 d = dw->setup_count - dw->setup_n;
313 t = dupe_iterations(dw->setup_count);
314 d = dupe_iterations(dw->setup_count - dw->setup_n);
320 d = dw->setup_count - dw->setup_n;
323 rem = (t - d) ? ((gdouble)(dw->setup_time_count / 1000000) / (t - d)) * d : 0;
325 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(dw->extra_label), value);
327 buf = g_strdup_printf("%s %d:%02d ", status, rem / 60, rem % 60);
328 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(dw->extra_label), buf);
335 dw->setup_count == 0 ||
336 dw->setup_time_count == 0 ||
337 (new_time > 0 && new_time - dw->setup_time_count >= 250000))
339 if (dw->setup_time_count == 0) dw->setup_time_count = 1;
340 if (new_time > 0) dw->setup_time_count = new_time;
341 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(dw->extra_label), value);
342 status_text = status;
351 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(dw->extra_label), 0.0);
355 if (status_text) gtk_progress_bar_set_text(GTK_PROGRESS_BAR(dw->extra_label), status_text);
358 static void widget_set_cursor(GtkWidget *widget, gint icon)
362 if (!gtk_widget_get_window(widget)) return;
370 cursor = gdk_cursor_new(icon);
373 gdk_window_set_cursor(gtk_widget_get_window(widget), cursor);
375 if (cursor) gdk_cursor_unref(cursor);
379 * ------------------------------------------------------------------
381 * ------------------------------------------------------------------
384 static void dupe_listview_realign_colors(DupeWindow *dw)
388 gboolean color_set = TRUE;
389 DupeItem *parent = NULL;
392 store = gtk_tree_view_get_model(GTK_TREE_VIEW(dw->listview));
393 valid = gtk_tree_model_get_iter_first(store, &iter);
397 DupeItem *child_parent;
399 gtk_tree_model_get(store, &iter, DUPE_COLUMN_POINTER, &child, -1);
400 child_parent = dupe_match_find_parent(dw, child);
401 if (!parent || parent != child_parent)
405 /* keep the first row as it is */
406 gtk_tree_model_get(store, &iter, DUPE_COLUMN_COLOR, &color_set, -1);
410 color_set = !color_set;
412 parent = dupe_match_find_parent(dw, child);
414 gtk_list_store_set(GTK_LIST_STORE(store), &iter, DUPE_COLUMN_COLOR, color_set, -1);
416 valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter);
421 * ------------------------------------------------------------------
423 * ------------------------------------------------------------------
426 static DupeItem *dupe_item_new(FileData *fd)
430 di = g_new0(DupeItem, 1);
432 di->fd = file_data_ref(fd);
433 di->group_rank = 0.0;
438 static void dupe_item_free(DupeItem *di)
440 file_data_unref(di->fd);
441 image_sim_free(di->simd);
443 if (di->pixbuf) g_object_unref(di->pixbuf);
448 static void dupe_list_free(GList *list)
453 DupeItem *di = work->data;
461 static DupeItem *dupe_item_find_fd_by_list(FileData *fd, GList *work)
465 DupeItem *di = work->data;
467 if (di->fd == fd) return di;
477 static DupeItem *dupe_item_find_fd(DupeWindow *dw, FileData *fd)
481 di = dupe_item_find_fd_by_list(fd, dw->list);
482 if (!di && dw->second_set) di = dupe_item_find_fd_by_list(fd, dw->second_list);
488 static DupeItem *dupe_item_find_path_by_list(const gchar *path, GList *work)
492 DupeItem *di = work->data;
494 if (strcmp(di->fd->path, path) == 0) return di;
502 static DupeItem *dupe_item_find_path(DupeWindow *dw, const gchar *path)
506 di = dupe_item_find_path_by_list(path, dw->list);
507 if (!di && dw->second_set) di = dupe_item_find_path_by_list(path, dw->second_list);
513 * ------------------------------------------------------------------
514 * Image property cache
515 * ------------------------------------------------------------------
518 static void dupe_item_read_cache(DupeItem *di)
525 path = cache_find_location(CACHE_TYPE_SIM, di->fd->path);
528 if (filetime(di->fd->path) != filetime(path))
534 cd = cache_sim_data_load(path);
539 if (!di->simd && cd->sim)
544 if (di->width == 0 && di->height == 0 && cd->dimensions)
546 di->width = cd->width;
547 di->height = cd->height;
548 di->dimensions = (di->width << 16) + di->height;
550 if (!di->md5sum && cd->have_md5sum)
552 di->md5sum = md5_digest_to_text(cd->md5sum);
554 cache_sim_data_free(cd);
558 static void dupe_item_write_cache(DupeItem *di)
565 base = cache_get_location(CACHE_TYPE_SIM, di->fd->path, FALSE, &mode);
566 if (recursive_mkdir_if_not_exists(base, mode))
570 cd = cache_sim_data_new();
571 cd->path = cache_get_location(CACHE_TYPE_SIM, di->fd->path, TRUE, NULL);
573 if (di->width != 0) cache_sim_data_set_dimensions(cd, di->width, di->height);
577 if (md5_digest_from_text(di->md5sum, digest)) cache_sim_data_set_md5sum(cd, digest);
579 if (di->simd) cache_sim_data_set_similarity(cd, di->simd);
581 if (cache_sim_data_save(cd))
583 filetime_set(cd->path, filetime(di->fd->path));
585 cache_sim_data_free(cd);
591 * ------------------------------------------------------------------
593 * ------------------------------------------------------------------
596 static gint dupe_listview_find_item(GtkListStore *store, DupeItem *item, GtkTreeIter *iter)
601 valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), iter);
605 gtk_tree_model_get(GTK_TREE_MODEL(store), iter, DUPE_COLUMN_POINTER, &item_n, -1);
606 if (item_n == item) return row;
608 valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), iter);
615 static void dupe_listview_add(DupeWindow *dw, DupeItem *parent, DupeItem *child)
619 gchar *text[DUPE_COLUMN_COUNT];
622 gboolean color_set = FALSE;
627 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dw->listview)));
633 row = dupe_listview_find_item(store, parent, &iter);
634 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, DUPE_COLUMN_COLOR, &color_set, -1);
640 dm = child->group->data;
641 rank = (gint)floor(dm->rank);
646 log_printf("NULL group in item!\n");
651 if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter))
653 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, DUPE_COLUMN_COLOR, &color_set, -1);
654 color_set = !color_set;
665 di = (child) ? child : parent;
667 if (!child && dw->second_set)
669 text[DUPE_COLUMN_RANK] = g_strdup("[1]");
673 text[DUPE_COLUMN_RANK] = g_strdup((di->second) ? "(2)" : "");
677 text[DUPE_COLUMN_RANK] = g_strdup_printf("%d%s", rank, (di->second) ? " (2)" : "");
680 text[DUPE_COLUMN_THUMB] = "";
681 text[DUPE_COLUMN_NAME] = (gchar *)di->fd->name;
682 text[DUPE_COLUMN_SIZE] = text_from_size(di->fd->size);
683 text[DUPE_COLUMN_DATE] = (gchar *)text_from_time(di->fd->date);
684 if (di->width > 0 && di->height > 0)
686 text[DUPE_COLUMN_DIMENSIONS] = g_strdup_printf("%d x %d", di->width, di->height);
690 text[DUPE_COLUMN_DIMENSIONS] = g_strdup("");
692 text[DUPE_COLUMN_PATH] = di->fd->path;
693 text[DUPE_COLUMN_COLOR] = NULL;
695 gtk_list_store_insert(store, &iter, row);
696 gtk_list_store_set(store, &iter,
697 DUPE_COLUMN_POINTER, di,
698 DUPE_COLUMN_RANK, text[DUPE_COLUMN_RANK],
699 DUPE_COLUMN_THUMB, NULL,
700 DUPE_COLUMN_NAME, text[DUPE_COLUMN_NAME],
701 DUPE_COLUMN_SIZE, text[DUPE_COLUMN_SIZE],
702 DUPE_COLUMN_DATE, text[DUPE_COLUMN_DATE],
703 DUPE_COLUMN_DIMENSIONS, text[DUPE_COLUMN_DIMENSIONS],
704 DUPE_COLUMN_PATH, text[DUPE_COLUMN_PATH],
705 DUPE_COLUMN_COLOR, color_set,
706 DUPE_COLUMN_SET, dw->set_count,
709 g_free(text[DUPE_COLUMN_RANK]);
710 g_free(text[DUPE_COLUMN_SIZE]);
711 g_free(text[DUPE_COLUMN_DIMENSIONS]);
714 static void dupe_listview_select_dupes(DupeWindow *dw, DupeSelectType parents);
716 static void dupe_listview_populate(DupeWindow *dw)
721 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dw->listview)));
722 gtk_list_store_clear(store);
724 work = g_list_last(dw->dupes);
727 DupeItem *parent = work->data;
730 dupe_listview_add(dw, parent, NULL);
732 temp = g_list_last(parent->group);
735 DupeMatch *dm = temp->data;
740 dupe_listview_add(dw, parent, child);
748 gtk_tree_view_columns_autosize(GTK_TREE_VIEW(dw->listview));
750 if (options->duplicates_select_type == DUPE_SELECT_GROUP1)
752 dupe_listview_select_dupes(dw, DUPE_SELECT_GROUP1);
754 else if (options->duplicates_select_type == DUPE_SELECT_GROUP2)
756 dupe_listview_select_dupes(dw, DUPE_SELECT_GROUP2);
761 static void dupe_listview_remove(DupeWindow *dw, DupeItem *di)
769 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dw->listview)));
770 row = dupe_listview_find_item(store, di, &iter);
773 tree_view_move_cursor_away(GTK_TREE_VIEW(dw->listview), &iter, TRUE);
774 gtk_list_store_remove(store, &iter);
776 if (g_list_find(dw->dupes, di) != NULL)
778 if (!dw->color_frozen) dupe_listview_realign_colors(dw);
783 static GList *dupe_listview_get_filelist(DupeWindow *dw, GtkWidget *listview)
790 store = gtk_tree_view_get_model(GTK_TREE_VIEW(listview));
791 valid = gtk_tree_model_get_iter_first(store, &iter);
795 gtk_tree_model_get(store, &iter, DUPE_COLUMN_POINTER, &di, -1);
796 list = g_list_prepend(list, file_data_ref(di->fd));
798 valid = gtk_tree_model_iter_next(store, &iter);
801 return g_list_reverse(list);
805 static GList *dupe_listview_get_selection(DupeWindow *dw, GtkWidget *listview)
808 GtkTreeSelection *selection;
813 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(listview));
814 slist = gtk_tree_selection_get_selected_rows(selection, &store);
818 GtkTreePath *tpath = work->data;
822 gtk_tree_model_get_iter(store, &iter, tpath);
823 gtk_tree_model_get(store, &iter, DUPE_COLUMN_POINTER, &di, -1);
826 list = g_list_prepend(list, file_data_ref(di->fd));
830 g_list_foreach(slist, (GFunc)tree_path_free_wrapper, NULL);
833 return g_list_reverse(list);
836 static gboolean dupe_listview_item_is_selected(DupeWindow *dw, DupeItem *di, GtkWidget *listview)
839 GtkTreeSelection *selection;
842 gboolean found = FALSE;
844 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(listview));
845 slist = gtk_tree_selection_get_selected_rows(selection, &store);
847 while (!found && work)
849 GtkTreePath *tpath = work->data;
853 gtk_tree_model_get_iter(store, &iter, tpath);
854 gtk_tree_model_get(store, &iter, DUPE_COLUMN_POINTER, &di_n, -1);
855 if (di_n == di) found = TRUE;
858 g_list_foreach(slist, (GFunc)tree_path_free_wrapper, NULL);
864 static void dupe_listview_select_dupes(DupeWindow *dw, DupeSelectType parents)
867 GtkTreeSelection *selection;
871 gint set_count_last = -1;
873 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dw->listview));
874 gtk_tree_selection_unselect_all(selection);
876 store = gtk_tree_view_get_model(GTK_TREE_VIEW(dw->listview));
877 valid = gtk_tree_model_get_iter_first(store, &iter);
882 gtk_tree_model_get(store, &iter, DUPE_COLUMN_POINTER, &di, DUPE_COLUMN_SET, &set_count, -1);
883 if (set_count != set_count_last)
885 set_count_last = set_count;
886 if (parents == DUPE_SELECT_GROUP1)
888 gtk_tree_selection_select_iter(selection, &iter);
893 if (parents == DUPE_SELECT_GROUP2)
895 gtk_tree_selection_select_iter(selection, &iter);
898 valid = gtk_tree_model_iter_next(store, &iter);
903 * ------------------------------------------------------------------
904 * Match group manipulation
905 * ------------------------------------------------------------------
909 * @brief Search \a parent->group for \a child (#DupeItem)
915 static DupeMatch *dupe_match_find_match(DupeItem *child, DupeItem *parent)
919 work = parent->group;
922 DupeMatch *dm = work->data;
923 if (dm->di == child) return dm;
930 * @brief Create #DupeMatch structure for \a child, and insert into \a parent->group list.
936 static void dupe_match_link_child(DupeItem *child, DupeItem *parent, gdouble rank)
940 dm = g_new0(DupeMatch, 1);
943 parent->group = g_list_append(parent->group, dm);
947 * @brief Link \a a & \a b as both parent and child
952 * Link \a a as child of \a b, and \a b as child of \a a
954 static void dupe_match_link(DupeItem *a, DupeItem *b, gdouble rank)
956 dupe_match_link_child(a, b, rank);
957 dupe_match_link_child(b, a, rank);
961 * @brief Remove \a child #DupeMatch from \a parent->group list.
966 static void dupe_match_unlink_child(DupeItem *child, DupeItem *parent)
970 dm = dupe_match_find_match(child, parent);
973 parent->group = g_list_remove(parent->group, dm);
979 * @brief Unlink \a a from \a b, and \a b from \a a
983 * Free the relevant #DupeMatch items from the #DupeItem group lists
985 static void dupe_match_unlink(DupeItem *a, DupeItem *b)
987 dupe_match_unlink_child(a, b);
988 dupe_match_unlink_child(b, a);
994 * @param unlink_children
996 * If \a unlink_children is set, unlink all entries in \a parent->group list. \n
997 * Free the \a parent->group list and set group_rank to zero;
999 static void dupe_match_link_clear(DupeItem *parent, gboolean unlink_children)
1003 work = parent->group;
1006 DupeMatch *dm = work->data;
1009 if (unlink_children) dupe_match_unlink_child(parent, dm->di);
1014 g_list_free(parent->group);
1015 parent->group = NULL;
1016 parent->group_rank = 0.0;
1020 * @brief Search \a parent->group list for \a child
1023 * @returns boolean TRUE/FALSE found/not found
1026 static gint dupe_match_link_exists(DupeItem *child, DupeItem *parent)
1028 return (dupe_match_find_match(child, parent) != NULL);
1032 * @brief Search \a parent->group for \a child, and return \a child->rank
1035 * @returns \a dm->di->rank
1038 static gdouble dupe_match_link_rank(DupeItem *child, DupeItem *parent)
1042 dm = dupe_match_find_match(child, parent);
1043 if (dm) return dm->rank;
1049 * @brief Find highest rank in \a child->group
1053 * Search the #DupeMatch entries in the \a child->group list.
1054 * Return the #DupeItem with the highest rank. If more than one have
1055 * the same rank, the first encountered is used.
1057 static DupeItem *dupe_match_highest_rank(DupeItem *child)
1063 work = child->group;
1066 DupeMatch *dm = work->data;
1067 if (!dr || dm->rank > dr->rank)
1074 return (dr) ? dr->di : NULL;
1078 * @brief Compute and store \a parent->group_rank
1081 * Group_rank = (sum of all child ranks) / n
1083 static void dupe_match_rank_update(DupeItem *parent)
1089 work = parent->group;
1092 DupeMatch *dm = work->data;
1100 parent->group_rank = rank / c;
1104 parent->group_rank = 0.0;
1108 static DupeItem *dupe_match_find_parent(DupeWindow *dw, DupeItem *child)
1112 if (g_list_find(dw->dupes, child)) return child;
1114 work = child->group;
1117 DupeMatch *dm = work->data;
1118 if (g_list_find(dw->dupes, dm->di)) return dm->di;
1127 * @param work (#DupeItem) dw->list or dw->second_list
1129 * Unlink all #DupeItem-s in \a work.
1130 * Do not unlink children.
1132 static void dupe_match_reset_list(GList *work)
1136 DupeItem *di = work->data;
1139 dupe_match_link_clear(di, FALSE);
1143 static void dupe_match_reparent(DupeWindow *dw, DupeItem *old, DupeItem *new)
1147 if (!old || !new || !dupe_match_link_exists(old, new)) return;
1149 dupe_match_link_clear(new, TRUE);
1153 DupeMatch *dm = work->data;
1154 dupe_match_unlink_child(old, dm->di);
1155 dupe_match_link_child(new, dm->di, dm->rank);
1159 new->group = old->group;
1162 work = g_list_find(dw->dupes, old);
1163 if (work) work->data = new;
1166 static void dupe_match_print_group(DupeItem *di)
1170 log_printf("+ %f %s\n", di->group_rank, di->fd->name);
1175 DupeMatch *dm = work->data;
1178 log_printf(" %f %s\n", dm->rank, dm->di->fd->name);
1184 static void dupe_match_print_list(GList *list)
1191 DupeItem *di = work->data;
1192 dupe_match_print_group(di);
1197 /* level 3, unlinking and orphan handling */
1201 * @param parent \a di from \a child->group
1202 * @param[inout] list \a dw->list sorted by rank (#DupeItem)
1204 * @returns modified \a list
1206 * Called for each entry in \a child->group (#DupeMatch) with \a parent set to \a dm->di. \n
1207 * Find the highest rank #DupeItem of the \a parent's children. \n
1208 * If that is == \a child OR
1209 * highest rank #DupeItem of \a child == \a parent then FIXME:
1212 static GList *dupe_match_unlink_by_rank(DupeItem *child, DupeItem *parent, GList *list, DupeWindow *dw)
1214 DupeItem *best = NULL;
1216 best = dupe_match_highest_rank(parent); // highest rank in parent->group
1217 if (best == child || dupe_match_highest_rank(child) == parent)
1222 DEBUG_2("link found %s to %s [%d]", child->fd->name, parent->fd->name, g_list_length(parent->group));
1224 work = parent->group;
1227 DupeMatch *dm = work->data;
1232 if (orphan != child && g_list_length(orphan->group) < 2)
1234 dupe_match_link_clear(orphan, TRUE);
1235 if (!dw->second_set || orphan->second)
1237 dupe_match(orphan, child, dw->match_mask, &rank, FALSE);
1238 dupe_match_link(orphan, child, rank);
1240 list = g_list_remove(list, orphan);
1244 rank = dupe_match_link_rank(child, parent); // child->rank
1245 dupe_match_link_clear(parent, TRUE);
1246 dupe_match_link(child, parent, rank);
1247 list = g_list_remove(list, parent);
1251 DEBUG_2("unlinking %s and %s", child->fd->name, parent->fd->name);
1253 dupe_match_unlink(child, parent);
1262 * @param[inout] list \a dw->list sorted by rank (#DupeItem)
1265 * @returns modified \a list
1267 * Called for each entry in \a list.
1268 * Call unlink for each child in \a di->group
1270 static GList *dupe_match_group_filter(GList *list, DupeItem *di, DupeWindow *dw)
1274 work = g_list_last(di->group);
1277 DupeMatch *dm = work->data;
1279 list = dupe_match_unlink_by_rank(di, dm->di, list, dw);
1288 * @param[inout] list \a dw->list sorted by rank (#DupeItem)
1290 * @returns Filtered \a list
1293 * Call group filter for each \a di in \a list
1295 static GList *dupe_match_group_trim(GList *list, DupeWindow *dw)
1302 DupeItem *di = work->data;
1303 if (!di->second) list = dupe_match_group_filter(list, di, dw);
1305 if (di->second) list = g_list_remove(list, di);
1311 static gint dupe_match_sort_groups_cb(gconstpointer a, gconstpointer b)
1313 DupeMatch *da = (DupeMatch *)a;
1314 DupeMatch *db = (DupeMatch *)b;
1316 if (da->rank > db->rank) return -1;
1317 if (da->rank < db->rank) return 1;
1322 * @brief Sorts the children of each #DupeItem in \a list
1323 * @param list #DupeItem
1325 * Sorts the #DupeItem->group children on rank
1327 static void dupe_match_sort_groups(GList *list)
1334 DupeItem *di = work->data;
1335 di->group = g_list_sort(di->group, dupe_match_sort_groups_cb);
1340 static gint dupe_match_totals_sort_cb(gconstpointer a, gconstpointer b)
1342 DupeItem *da = (DupeItem *)a;
1343 DupeItem *db = (DupeItem *)b;
1345 if (g_list_length(da->group) > g_list_length(db->group)) return -1;
1346 if (g_list_length(da->group) < g_list_length(db->group)) return 1;
1348 if (da->group_rank < db->group_rank) return -1;
1349 if (da->group_rank > db->group_rank) return 1;
1355 * @brief Callback for group_rank sort
1362 static gint dupe_match_rank_sort_cb(gconstpointer a, gconstpointer b)
1364 DupeItem *da = (DupeItem *)a;
1365 DupeItem *db = (DupeItem *)b;
1367 if (da->group_rank > db->group_rank) return -1;
1368 if (da->group_rank < db->group_rank) return 1;
1373 * @brief Sorts \a source_list by group-rank
1374 * @param source_list #DupeItem
1377 * Computes group_rank for each #DupeItem. \n
1378 * Items with no group list are ignored.
1379 * Returns allocated GList of #DupeItem-s sorted by group_rank
1381 static GList *dupe_match_rank_sort(GList *source_list)
1389 DupeItem *di = work->data;
1393 dupe_match_rank_update(di); // Compute and store group_rank for di
1394 list = g_list_prepend(list, di);
1400 return g_list_sort(list, dupe_match_rank_sort_cb);
1404 * @brief Returns allocated GList of dupes sorted by totals
1405 * @param source_list
1410 static GList *dupe_match_totals_sort(GList *source_list)
1412 source_list = g_list_sort(source_list, dupe_match_totals_sort_cb);
1414 source_list = g_list_first(source_list);
1415 return g_list_reverse(source_list);
1424 static void dupe_match_rank(DupeWindow *dw)
1428 list = dupe_match_rank_sort(dw->list); // sorted by group_rank, no-matches filtered out
1430 if (required_debug_level(2)) dupe_match_print_list(list);
1432 DEBUG_1("Similar items: %d", g_list_length(list));
1433 list = dupe_match_group_trim(list, dw);
1434 DEBUG_1("Unique groups: %d", g_list_length(list));
1436 dupe_match_sort_groups(list);
1438 if (required_debug_level(2)) dupe_match_print_list(list);
1440 list = dupe_match_rank_sort(list);
1441 if (options->sort_totals)
1443 list = dupe_match_totals_sort(list);
1445 if (required_debug_level(2)) dupe_match_print_list(list);
1447 g_list_free(dw->dupes);
1452 * ------------------------------------------------------------------
1454 * ------------------------------------------------------------------
1466 * For similarity checks, compute rank - (similarity factor between a and b). \n
1467 * If rank < user-set sim value, returns FALSE.
1469 static gboolean dupe_match(DupeItem *a, DupeItem *b, DupeMatchType mask, gdouble *rank, gint fast)
1473 if (a->fd->path == b->fd->path) return FALSE;
1475 if (mask & DUPE_MATCH_ALL)
1479 if (mask & DUPE_MATCH_PATH)
1481 if (utf8_compare(a->fd->path, b->fd->path, TRUE) != 0) return FALSE;
1483 if (mask & DUPE_MATCH_NAME)
1485 if (strcmp(a->fd->collate_key_name, b->fd->collate_key_name) != 0) return FALSE;
1487 if (mask & DUPE_MATCH_NAME_CI)
1489 if (strcmp(a->fd->collate_key_name_nocase, b->fd->collate_key_name_nocase) != 0) return FALSE;
1491 if (mask & DUPE_MATCH_NAME_CONTENT)
1493 if (strcmp(a->fd->collate_key_name, b->fd->collate_key_name) == 0)
1495 if (!a->md5sum) a->md5sum = md5_text_from_file_utf8(a->fd->path, "");
1496 if (!b->md5sum) b->md5sum = md5_text_from_file_utf8(b->fd->path, "");
1497 if (a->md5sum[0] == '\0' ||
1498 b->md5sum[0] == '\0' ||
1499 strcmp(a->md5sum, b->md5sum) != 0)
1513 if (mask & DUPE_MATCH_NAME_CI_CONTENT)
1515 if (strcmp(a->fd->collate_key_name_nocase, b->fd->collate_key_name_nocase) == 0)
1517 if (!a->md5sum) a->md5sum = md5_text_from_file_utf8(a->fd->path, "");
1518 if (!b->md5sum) b->md5sum = md5_text_from_file_utf8(b->fd->path, "");
1519 if (a->md5sum[0] == '\0' ||
1520 b->md5sum[0] == '\0' ||
1521 strcmp(a->md5sum, b->md5sum) != 0)
1535 if (mask & DUPE_MATCH_SIZE)
1537 if (a->fd->size != b->fd->size) return FALSE;
1539 if (mask & DUPE_MATCH_DATE)
1541 if (a->fd->date != b->fd->date) return FALSE;
1543 if (mask & DUPE_MATCH_SUM)
1545 if (!a->md5sum) a->md5sum = md5_text_from_file_utf8(a->fd->path, "");
1546 if (!b->md5sum) b->md5sum = md5_text_from_file_utf8(b->fd->path, "");
1547 if (a->md5sum[0] == '\0' ||
1548 b->md5sum[0] == '\0' ||
1549 strcmp(a->md5sum, b->md5sum) != 0) return FALSE;
1551 if (mask & DUPE_MATCH_DIM)
1553 if (a->width == 0) image_load_dimensions(a->fd, &a->width, &a->height);
1554 if (b->width == 0) image_load_dimensions(b->fd, &b->width, &b->height);
1555 if (a->width != b->width || a->height != b->height) return FALSE;
1557 if (mask & DUPE_MATCH_SIM_HIGH ||
1558 mask & DUPE_MATCH_SIM_MED ||
1559 mask & DUPE_MATCH_SIM_LOW ||
1560 mask & DUPE_MATCH_SIM_CUSTOM)
1565 if (mask & DUPE_MATCH_SIM_HIGH) m = 0.95;
1566 else if (mask & DUPE_MATCH_SIM_MED) m = 0.90;
1567 else if (mask & DUPE_MATCH_SIM_CUSTOM) m = (gdouble)options->duplicates_similarity_threshold / 100.0;
1572 f = image_sim_compare_fast(a->simd, b->simd, m);
1576 f = image_sim_compare(a->simd, b->simd);
1581 if (f < m) return FALSE;
1583 DEBUG_3("similar: %32s %32s = %f", a->fd->name, b->fd->name, f);
1590 * @brief Determine if there is a match
1594 * @returns DUPE_MATCH/DUPE_NO_MATCH/DUPE_NAME_MATCH
1595 * DUPE_NAME_MATCH is used for name != contents searches:
1596 * the name and content match i.e.
1597 * no match, but keep searching
1599 * Called when stepping down the array looking for adjacent matches,
1600 * and from the 2nd set search.
1602 * Is not used for similarity checks.
1604 static DUPE_CHECK_RESULT dupe_match_check(DupeItem *di1, DupeItem *di2, gpointer data)
1606 DupeWindow *dw = data;
1607 DupeMatchType mask = dw->match_mask;
1609 if (mask & DUPE_MATCH_ALL)
1613 if (mask & DUPE_MATCH_PATH)
1615 if (utf8_compare(di1->fd->path, di2->fd->path, TRUE) != 0)
1617 return DUPE_NO_MATCH;
1620 if (mask & DUPE_MATCH_NAME)
1622 if (g_strcmp0(di1->fd->collate_key_name, di2->fd->collate_key_name) != 0)
1624 return DUPE_NO_MATCH;
1627 if (mask & DUPE_MATCH_NAME_CI)
1629 if (g_strcmp0(di1->fd->collate_key_name_nocase, di2->fd->collate_key_name_nocase) != 0 )
1631 return DUPE_NO_MATCH;
1634 if (mask & DUPE_MATCH_NAME_CONTENT)
1636 if (g_strcmp0(di1->fd->collate_key_name, di2->fd->collate_key_name) == 0)
1638 if (g_strcmp0(di1->md5sum, di2->md5sum) == 0)
1640 return DUPE_NAME_MATCH;
1645 return DUPE_NO_MATCH;
1648 if (mask & DUPE_MATCH_NAME_CI_CONTENT)
1650 if (strcmp(di1->fd->collate_key_name_nocase, di2->fd->collate_key_name_nocase) == 0)
1652 if (g_strcmp0(di1->md5sum, di2->md5sum) == 0)
1654 return DUPE_NAME_MATCH;
1659 return DUPE_NO_MATCH;
1662 if (mask & DUPE_MATCH_SIZE)
1664 if (di1->fd->size != di2->fd->size)
1666 return DUPE_NO_MATCH;
1669 if (mask & DUPE_MATCH_DATE)
1671 if (di1->fd->date != di2->fd->date)
1673 return DUPE_NO_MATCH;
1676 if (mask & DUPE_MATCH_SUM)
1678 if (g_strcmp0(di1->md5sum, di2->md5sum) != 0)
1680 return DUPE_NO_MATCH;
1683 if (mask & DUPE_MATCH_DIM)
1685 if (di1->dimensions != di2->dimensions)
1687 return DUPE_NO_MATCH;
1695 * @brief The callback for the binary search
1698 * @param param_match_mask
1699 * @returns negative/0/positive
1701 * Is not used for similarity checks.
1703 * Used only when two file sets are used.
1704 * Requires use of a global for param_match_mask because there is no
1705 * g_array_binary_search_with_data() function in glib.
1707 static gint dupe_match_binary_search_cb(gconstpointer a, gconstpointer b)
1709 const DupeItem *di1 = *((DupeItem **) a);
1710 const DupeItem *di2 = b;
1711 DupeMatchType mask = param_match_mask;
1713 if (mask & DUPE_MATCH_ALL)
1717 if (mask & DUPE_MATCH_PATH)
1719 return utf8_compare(di1->fd->path, di2->fd->path, TRUE);
1721 if (mask & DUPE_MATCH_NAME)
1723 return g_strcmp0(di1->fd->collate_key_name, di2->fd->collate_key_name);
1725 if (mask & DUPE_MATCH_NAME_CI)
1727 return strcmp(di1->fd->collate_key_name_nocase, di2->fd->collate_key_name_nocase);
1729 if (mask & DUPE_MATCH_NAME_CONTENT)
1731 return g_strcmp0(di1->fd->collate_key_name, di2->fd->collate_key_name);
1733 if (mask & DUPE_MATCH_NAME_CI_CONTENT)
1735 return strcmp(di1->fd->collate_key_name_nocase, di2->fd->collate_key_name_nocase);
1737 if (mask & DUPE_MATCH_SIZE)
1739 return (di1->fd->size - di2->fd->size);
1741 if (mask & DUPE_MATCH_DATE)
1743 return (di1->fd->date - di2->fd->date);
1745 if (mask & DUPE_MATCH_SUM)
1747 return g_strcmp0(di1->md5sum, di2->md5sum);
1749 if (mask & DUPE_MATCH_DIM)
1751 return (di1->dimensions - di2->dimensions);
1758 * @brief The callback for the array sort
1762 * @returns negative/0/positive
1764 * Is not used for similarity checks.
1766 static gint dupe_match_sort_cb(gconstpointer a, gconstpointer b, gpointer data)
1768 const DupeItem *di1 = *((DupeItem **) a);
1769 const DupeItem *di2 = *((DupeItem **) b);
1770 DupeWindow *dw = data;
1771 DupeMatchType mask = dw->match_mask;
1773 if (mask & DUPE_MATCH_ALL)
1777 if (mask & DUPE_MATCH_PATH)
1779 return utf8_compare(di1->fd->path, di2->fd->path, TRUE);
1781 if (mask & DUPE_MATCH_NAME)
1783 return g_strcmp0(di1->fd->collate_key_name, di2->fd->collate_key_name);
1785 if (mask & DUPE_MATCH_NAME_CI)
1787 return strcmp(di1->fd->collate_key_name_nocase, di2->fd->collate_key_name_nocase);
1789 if (mask & DUPE_MATCH_NAME_CONTENT)
1791 return g_strcmp0(di1->fd->collate_key_name, di2->fd->collate_key_name);
1793 if (mask & DUPE_MATCH_NAME_CI_CONTENT)
1795 return strcmp(di1->fd->collate_key_name_nocase, di2->fd->collate_key_name_nocase);
1797 if (mask & DUPE_MATCH_SIZE)
1799 return (di1->fd->size - di2->fd->size);
1801 if (mask & DUPE_MATCH_DATE)
1803 return (di1->fd->date - di2->fd->date);
1805 if (mask & DUPE_MATCH_SUM)
1807 if (di1->md5sum[0] == '\0' || di2->md5sum[0] == '\0')
1813 return strcmp(di1->md5sum, di2->md5sum);
1816 if (mask & DUPE_MATCH_DIM)
1818 if (!di1 || !di2 || !di1->width || !di1->height || !di2->width || !di2->height)
1822 return (di1->dimensions - di2->dimensions);
1825 return 0; // should not execute
1829 * @brief Check for duplicate matches
1832 * Is not used for similarity checks.
1834 * Loads the file sets into an array and sorts on the searched
1837 * If one file set, steps down the array looking for adjacent equal values.
1839 * If two file sets, steps down the first set and for each value
1840 * does a binary search for matches in the second set.
1842 static void dupe_array_check(DupeWindow *dw )
1849 DUPE_CHECK_RESULT check_result;
1850 DupeMatchType mask = dw->match_mask;
1851 param_match_mask = dw->match_mask;
1852 guint out_match_index;
1854 if (!dw->list) return;
1856 array_set1 = g_array_new(TRUE, TRUE, sizeof(gpointer));
1857 array_set2 = g_array_new(TRUE, TRUE, sizeof(gpointer));
1858 dupe_match_reset_list(dw->list);
1863 DupeItem *di = work->data;
1864 g_array_append_val(array_set1, di);
1868 g_array_sort_with_data(array_set1, dupe_match_sort_cb, dw);
1872 /* Two sets - nothing can be done until a second set is loaded */
1873 if (dw->second_list)
1875 work = dw->second_list;
1878 DupeItem *di = work->data;
1879 g_array_append_val(array_set2, (work->data));
1882 g_array_sort_with_data(array_set2, dupe_match_sort_cb, dw);
1884 for (i_set1 = 0; i_set1 <= (gint)(array_set1->len) - 1; i_set1++)
1886 DupeItem *di1 = g_array_index(array_set1, gpointer, i_set1);
1887 DupeItem *di2 = NULL;
1888 /* If multiple identical entries in set 1, use the last one */
1889 if (i_set1 < (gint)(array_set1->len) - 2)
1891 di2 = g_array_index(array_set1, gpointer, i_set1 + 1);
1892 check_result = dupe_match_check(di1, di2, dw);
1893 if (check_result == DUPE_MATCH || check_result == DUPE_NAME_MATCH)
1898 if (g_array_binary_search(array_set2, di1, dupe_match_binary_search_cb, &out_match_index))
1900 di2 = g_array_index(array_set2, gpointer, out_match_index);
1902 check_result = dupe_match_check(di1, di2, dw);
1903 if (check_result == DUPE_MATCH || check_result == DUPE_NAME_MATCH)
1905 if (check_result == DUPE_MATCH)
1907 dupe_match_link(di2, di1, 0.0);
1909 i_set2 = out_match_index + 1;
1911 if (i_set2 > (gint)(array_set2->len) - 1)
1915 /* Look for multiple matches in set 2 for item di1 */
1916 di2 = g_array_index(array_set2, gpointer, i_set2);
1917 check_result = dupe_match_check(di1, di2, dw);
1918 while (check_result == DUPE_MATCH || check_result == DUPE_NAME_MATCH)
1920 if (check_result == DUPE_MATCH)
1922 dupe_match_link(di2, di1, 0.0);
1925 if (i_set2 > (gint)(array_set2->len) - 1)
1929 di2 = g_array_index(array_set2, gpointer, i_set2);
1930 check_result = dupe_match_check(di1, di2, dw);
1939 /* File set 1 only */
1940 g_list_free(dw->dupes);
1943 if ((gint)(array_set1->len) > 1)
1945 for (i_set1 = 0; i_set1 <= (gint)(array_set1->len) - 2; i_set1++)
1947 DupeItem *di1 = g_array_index(array_set1, gpointer, i_set1);
1948 DupeItem *di2 = g_array_index(array_set1, gpointer, i_set1 + 1);
1950 check_result = dupe_match_check(di1, di2, dw);
1951 if (check_result == DUPE_MATCH || check_result == DUPE_NAME_MATCH)
1953 if (check_result == DUPE_MATCH)
1955 dupe_match_link(di2, di1, 0.0);
1959 if ( i_set1 + 1 > (gint)(array_set1->len) - 1)
1963 /* Look for multiple matches for item di1 */
1964 di2 = g_array_index(array_set1, gpointer, i_set1 + 1);
1965 check_result = dupe_match_check(di1, di2, dw);
1966 while (check_result == DUPE_MATCH || check_result == DUPE_NAME_MATCH)
1968 if (check_result == DUPE_MATCH)
1970 dupe_match_link(di2, di1, 0.0);
1974 if (i_set1 + 1 > (gint)(array_set1->len) - 1)
1978 di2 = g_array_index(array_set1, gpointer, i_set1 + 1);
1979 check_result = dupe_match_check(di1, di2, dw);
1985 g_array_free(array_set1, TRUE);
1986 g_array_free(array_set2, TRUE);
1990 * @brief Look for similarity match
1995 * Only used for similarity checks.\n
1996 * Called from dupe_check_cb.
1997 * Called for each entry in the list.
1998 * Steps through the list looking for matches against needle.
1999 * Pushes a #DupeQueueItem onto thread pool queue.
2001 static void dupe_list_check_match(DupeWindow *dw, DupeItem *needle, GList *start)
2008 work = dw->second_list;
2016 work = g_list_last(dw->list);
2019 dqi = g_new0(DupeQueueItem, 1);
2020 dqi->needle = needle;
2023 dqi->index = dw->queue_count;
2024 g_thread_pool_push(dw->dupe_comparison_thread_pool, dqi, NULL);
2028 * ------------------------------------------------------------------
2029 * Thumbnail handling
2030 * ------------------------------------------------------------------
2033 static void dupe_listview_set_thumb(DupeWindow *dw, DupeItem *di, GtkTreeIter *iter)
2035 GtkListStore *store;
2038 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dw->listview)));
2041 if (dupe_listview_find_item(store, di, &iter_n) >= 0)
2047 if (iter) gtk_list_store_set(store, iter, DUPE_COLUMN_THUMB, di->pixbuf, -1);
2050 static void dupe_thumb_do(DupeWindow *dw)
2054 if (!dw->thumb_loader || !dw->thumb_item) return;
2055 di = dw->thumb_item;
2057 if (di->pixbuf) g_object_unref(di->pixbuf);
2058 di->pixbuf = thumb_loader_get_pixbuf(dw->thumb_loader);
2060 dupe_listview_set_thumb(dw, di, NULL);
2063 static void dupe_thumb_error_cb(ThumbLoader *tl, gpointer data)
2065 DupeWindow *dw = data;
2068 dupe_thumb_step(dw);
2071 static void dupe_thumb_done_cb(ThumbLoader *tl, gpointer data)
2073 DupeWindow *dw = data;
2076 dupe_thumb_step(dw);
2079 static void dupe_thumb_step(DupeWindow *dw)
2081 GtkTreeModel *store;
2083 DupeItem *di = NULL;
2088 store = gtk_tree_view_get_model(GTK_TREE_VIEW(dw->listview));
2089 valid = gtk_tree_model_get_iter_first(store, &iter);
2091 while (!di && valid)
2096 gtk_tree_model_get(store, &iter, DUPE_COLUMN_POINTER, &di, DUPE_COLUMN_THUMB, &pixbuf, -1);
2097 if (pixbuf || di->pixbuf)
2099 if (!pixbuf) gtk_list_store_set(GTK_LIST_STORE(store), &iter, DUPE_COLUMN_THUMB, di->pixbuf, -1);
2103 valid = gtk_tree_model_iter_next(store, &iter);
2107 while (gtk_tree_model_iter_next(store, &iter)) length++;
2112 dw->thumb_item = NULL;
2113 thumb_loader_free(dw->thumb_loader);
2114 dw->thumb_loader = NULL;
2116 dupe_window_update_progress(dw, NULL, 0.0, FALSE);
2120 dupe_window_update_progress(dw, _("Loading thumbs..."),
2121 length == 0 ? 0.0 : (gdouble)(row) / length, FALSE);
2123 dw->thumb_item = di;
2124 thumb_loader_free(dw->thumb_loader);
2125 dw->thumb_loader = thumb_loader_new(options->thumbnails.max_width, options->thumbnails.max_height);
2127 thumb_loader_set_callbacks(dw->thumb_loader,
2129 dupe_thumb_error_cb,
2134 if (!thumb_loader_start(dw->thumb_loader, di->fd))
2136 /* error, handle it, do next */
2137 DEBUG_1("error loading thumb for %s", di->fd->path);
2139 dupe_thumb_step(dw);
2144 * ------------------------------------------------------------------
2145 * Dupe checking loop
2146 * ------------------------------------------------------------------
2149 static void dupe_check_stop(DupeWindow *dw)
2151 if (dw->idle_id > 0)
2153 g_source_remove(dw->idle_id);
2159 while (dw->thread_count < dw->queue_count) // Wait for the queue to empty
2161 dupe_window_update_progress(dw, NULL, 0.0, FALSE);
2162 widget_set_cursor(dw->listview, -1);
2165 g_list_free(dw->search_matches);
2166 dw->search_matches = NULL;
2168 if (dw->idle_id || dw->img_loader || dw->thumb_loader)
2170 if (dw->idle_id > 0)
2172 g_source_remove(dw->idle_id);
2175 dupe_window_update_progress(dw, NULL, 0.0, FALSE);
2176 widget_set_cursor(dw->listview, -1);
2179 if (dw->add_files_queue_id)
2181 g_source_remove(dw->add_files_queue_id);
2182 dw->add_files_queue_id = 0;
2183 dupe_destroy_list_cache(dw);
2184 gtk_widget_set_sensitive(dw->controls_box, TRUE);
2185 if (g_list_length(dw->add_files_queue) > 0)
2187 filelist_free(dw->add_files_queue);
2189 dw->add_files_queue = NULL;
2190 dupe_window_update_progress(dw, NULL, 0.0, FALSE);
2191 widget_set_cursor(dw->listview, -1);
2194 thumb_loader_free(dw->thumb_loader);
2195 dw->thumb_loader = NULL;
2197 image_loader_free(dw->img_loader);
2198 dw->img_loader = NULL;
2201 static void dupe_check_stop_cb(GtkWidget *widget, gpointer data)
2203 DupeWindow *dw = data;
2205 dupe_check_stop(dw);
2208 static void dupe_loader_done_cb(ImageLoader *il, gpointer data)
2210 DupeWindow *dw = data;
2213 pixbuf = image_loader_get_pixbuf(il);
2215 if (dw->setup_point)
2217 DupeItem *di = dw->setup_point->data;
2221 di->simd = image_sim_new_from_pixbuf(pixbuf);
2225 image_sim_fill_data(di->simd, pixbuf);
2228 if (di->width == 0 && di->height == 0)
2230 di->width = gdk_pixbuf_get_width(pixbuf);
2231 di->height = gdk_pixbuf_get_height(pixbuf);
2233 if (options->thumbnails.enable_caching)
2235 dupe_item_write_cache(di);
2238 image_sim_alternate_processing(di->simd);
2241 image_loader_free(dw->img_loader);
2242 dw->img_loader = NULL;
2244 dw->idle_id = g_idle_add(dupe_check_cb, dw);
2247 static void dupe_setup_reset(DupeWindow *dw)
2249 dw->setup_point = NULL;
2251 dw->setup_time = msec_time();
2252 dw->setup_time_count = 0;
2255 static GList *dupe_setup_point_step(DupeWindow *dw, GList *p)
2257 if (!p) return NULL;
2259 if (p->next) return p->next;
2261 if (dw->second_set && g_list_first(p) == dw->list) return dw->second_list;
2267 * @brief Generates the sumcheck or dimensions
2268 * @param list Set1 or set2
2269 * @returns TRUE/FALSE = not completed/completed
2271 * Ensures that the DIs contain the MD5SUM or dimensions for all items in
2272 * the list. One item at a time. Re-enters if not completed.
2274 static gboolean create_checksums_dimensions(DupeWindow *dw, GList *list)
2276 if ((dw->match_mask & DUPE_MATCH_SUM) ||
2277 (dw->match_mask & DUPE_MATCH_NAME_CONTENT) ||
2278 (dw->match_mask & DUPE_MATCH_NAME_CI_CONTENT))
2281 if (!dw->setup_point) dw->setup_point = list; // setup_point clear on 1st entry
2283 while (dw->setup_point)
2285 DupeItem *di = dw->setup_point->data;
2287 dw->setup_point = dupe_setup_point_step(dw, dw->setup_point);
2292 dupe_window_update_progress(dw, _("Reading checksums..."),
2293 dw->setup_count == 0 ? 0.0 : (gdouble)(dw->setup_n - 1) / dw->setup_count, FALSE);
2295 if (options->thumbnails.enable_caching)
2297 dupe_item_read_cache(di);
2304 di->md5sum = md5_text_from_file_utf8(di->fd->path, "");
2305 if (options->thumbnails.enable_caching)
2307 dupe_item_write_cache(di);
2312 dupe_setup_reset(dw);
2315 if ((dw->match_mask & DUPE_MATCH_DIM) )
2317 /* Dimensions only */
2318 if (!dw->setup_point) dw->setup_point = list;
2320 while (dw->setup_point)
2322 DupeItem *di = dw->setup_point->data;
2324 dw->setup_point = dupe_setup_point_step(dw, dw->setup_point);
2326 if (di->width == 0 && di->height == 0)
2328 dupe_window_update_progress(dw, _("Reading dimensions..."),
2329 dw->setup_count == 0 ? 0.0 : (gdouble)(dw->setup_n - 1) / dw->setup_count, FALSE);
2331 if (options->thumbnails.enable_caching)
2333 dupe_item_read_cache(di);
2334 if (di->width != 0 || di->height != 0)
2340 image_load_dimensions(di->fd, &di->width, &di->height);
2341 di->dimensions = (di->width << 16) + di->height;
2342 if (options->thumbnails.enable_caching)
2344 dupe_item_write_cache(di);
2349 dupe_setup_reset(dw);
2356 * @brief Compare func. for sorting search matches
2357 * @param a #DupeSearchMatch
2358 * @param b #DupeSearchMatch
2361 * Used only for similarity checks\n
2362 * Sorts search matches on order they were inserted into the pool queue
2364 static gint sort_func(gconstpointer a, gconstpointer b)
2366 return (((DupeSearchMatch *)a)->index - ((DupeSearchMatch *)b)->index);
2370 * @brief Check set 1 (and set 2) for matches
2371 * @param data DupeWindow
2372 * @returns TRUE/FALSE = not completed/completed
2374 * Initiated from start, loader done and item remove
2376 * On first entry generates di->MD5SUM, di->dimensions and sim data,
2377 * and updates the cache.
2379 static gboolean dupe_check_cb(gpointer data)
2381 DupeWindow *dw = data;
2382 DupeSearchMatch *search_match_list_item;
2389 if (!dw->setup_done) /* Clear on 1st entry */
2393 if (create_checksums_dimensions(dw, dw->list))
2398 if (dw->second_list)
2400 if (create_checksums_dimensions(dw, dw->second_list))
2405 if ((dw->match_mask & DUPE_MATCH_SIM_HIGH ||
2406 dw->match_mask & DUPE_MATCH_SIM_MED ||
2407 dw->match_mask & DUPE_MATCH_SIM_LOW ||
2408 dw->match_mask & DUPE_MATCH_SIM_CUSTOM) &&
2409 !(dw->setup_mask & DUPE_MATCH_SIM_MED) )
2411 /* Similarity only */
2412 if (!dw->setup_point) dw->setup_point = dw->list;
2414 while (dw->setup_point)
2416 DupeItem *di = dw->setup_point->data;
2420 dupe_window_update_progress(dw, _("Reading similarity data..."),
2421 dw->setup_count == 0 ? 0.0 : (gdouble)dw->setup_n / dw->setup_count, FALSE);
2423 if (options->thumbnails.enable_caching)
2425 dupe_item_read_cache(di);
2426 if (cache_sim_data_filled(di->simd))
2428 image_sim_alternate_processing(di->simd);
2433 dw->img_loader = image_loader_new(di->fd);
2434 image_loader_set_buffer_size(dw->img_loader, 8);
2435 g_signal_connect(G_OBJECT(dw->img_loader), "error", (GCallback)dupe_loader_done_cb, dw);
2436 g_signal_connect(G_OBJECT(dw->img_loader), "done", (GCallback)dupe_loader_done_cb, dw);
2438 if (!image_loader_start(dw->img_loader))
2440 image_sim_free(di->simd);
2441 di->simd = image_sim_new();
2442 image_loader_free(dw->img_loader);
2443 dw->img_loader = NULL;
2450 dw->setup_point = dupe_setup_point_step(dw, dw->setup_point);
2453 dw->setup_mask |= DUPE_MATCH_SIM_MED;
2454 dupe_setup_reset(dw);
2457 /* End of setup not done */
2458 dupe_window_update_progress(dw, _("Comparing..."), 0.0, FALSE);
2459 dw->setup_done = TRUE;
2460 dupe_setup_reset(dw);
2461 dw->setup_count = g_list_length(dw->list);
2464 /* Setup done - dw->working set to NULL below
2465 * Set before 1st entry: dw->working = g_list_last(dw->list)
2466 * Set before 1st entry: dw->setup_count = g_list_length(dw->list)
2470 /* Similarity check threads may still be running */
2471 if (dw->setup_count > 0 && (dw->match_mask == DUPE_MATCH_SIM_HIGH ||
2472 dw->match_mask == DUPE_MATCH_SIM_MED ||
2473 dw->match_mask == DUPE_MATCH_SIM_LOW ||
2474 dw->match_mask == DUPE_MATCH_SIM_CUSTOM))
2476 if( dw->thread_count < dw->queue_count)
2478 dupe_window_update_progress(dw, _("Comparing..."), 0.0, FALSE);
2483 if (dw->search_matches_sorted == NULL)
2485 dw->search_matches_sorted = g_list_sort(dw->search_matches, sort_func);
2486 dupe_setup_reset(dw);
2489 while (dw->search_matches_sorted)
2492 dupe_window_update_progress(dw, _("Sorting..."), 0.0, FALSE);
2493 search_match_list_item = dw->search_matches_sorted->data;
2495 if (!dupe_match_link_exists(search_match_list_item->a, search_match_list_item->b))
2497 dupe_match_link(search_match_list_item->a, search_match_list_item->b, search_match_list_item->rank);
2500 dw->search_matches_sorted = dw->search_matches_sorted->next;
2502 if (dw->search_matches_sorted != NULL)
2507 g_list_free(dw->search_matches);
2508 dw->search_matches = NULL;
2509 g_list_free(dw->search_matches_sorted);
2510 dw->search_matches_sorted = NULL;
2511 dw->setup_count = 0;
2515 if (dw->setup_count > 0)
2517 dw->setup_count = 0;
2518 dupe_window_update_progress(dw, _("Sorting..."), 1.0, TRUE);
2524 dupe_window_update_progress(dw, NULL, 0.0, FALSE);
2526 dupe_match_rank(dw);
2527 dupe_window_update_count(dw, FALSE);
2529 dupe_listview_populate(dw);
2532 if (dw->show_thumbs) dupe_thumb_step(dw);
2534 widget_set_cursor(dw->listview, -1);
2540 /* Setup done - working */
2541 if (dw->match_mask == DUPE_MATCH_SIM_HIGH ||
2542 dw->match_mask == DUPE_MATCH_SIM_MED ||
2543 dw->match_mask == DUPE_MATCH_SIM_LOW ||
2544 dw->match_mask == DUPE_MATCH_SIM_CUSTOM)
2546 /* This is the similarity comparison */
2547 dupe_list_check_match(dw, (DupeItem *)dw->working->data, dw->working);
2548 dupe_window_update_progress(dw, _("Queuing..."), dw->setup_count == 0 ? 0.0 : (gdouble) dw->setup_n / dw->setup_count, FALSE);
2552 dw->working = dw->working->prev; /* Is NULL when complete */
2556 /* This is the comparison for all other parameters.
2557 * dupe_array_check() processes the entire list in one go
2560 dupe_window_update_progress(dw, _("Comparing..."), 0.0, FALSE);
2561 dupe_array_check(dw);
2567 static void dupe_check_start(DupeWindow *dw)
2569 dw->setup_done = FALSE;
2571 dw->setup_count = g_list_length(dw->list);
2572 if (dw->second_set) dw->setup_count += g_list_length(dw->second_list);
2575 dupe_setup_reset(dw);
2577 dw->working = g_list_last(dw->list);
2579 dupe_window_update_count(dw, TRUE);
2580 widget_set_cursor(dw->listview, GDK_WATCH);
2581 dw->queue_count = 0;
2582 dw->thread_count = 0;
2583 dw->search_matches_sorted = NULL;
2586 if (dw->idle_id) return;
2588 dw->idle_id = g_idle_add(dupe_check_cb, dw);
2591 static gboolean dupe_check_start_cb(gpointer data)
2593 DupeWindow *dw = data;
2595 dupe_check_start(dw);
2601 * ------------------------------------------------------------------
2602 * Item addition, removal
2603 * ------------------------------------------------------------------
2606 static void dupe_item_remove(DupeWindow *dw, DupeItem *di)
2610 /* handle things that may be in progress... */
2611 if (dw->working && dw->working->data == di)
2613 dw->working = dw->working->prev;
2615 if (dw->thumb_loader && dw->thumb_item == di)
2617 dupe_thumb_step(dw);
2619 if (dw->setup_point && dw->setup_point->data == di)
2621 dw->setup_point = dupe_setup_point_step(dw, dw->setup_point);
2624 image_loader_free(dw->img_loader);
2625 dw->img_loader = NULL;
2626 dw->idle_id = g_idle_add(dupe_check_cb, dw);
2630 if (di->group && dw->dupes)
2632 /* is a dupe, must remove from group/reset children if a parent */
2635 parent = dupe_match_find_parent(dw, di);
2638 if (g_list_length(parent->group) < 2)
2642 child = dupe_match_highest_rank(parent);
2643 dupe_match_link_clear(child, TRUE);
2644 dupe_listview_remove(dw, child);
2646 dupe_match_link_clear(parent, TRUE);
2647 dupe_listview_remove(dw, parent);
2648 dw->dupes = g_list_remove(dw->dupes, parent);
2652 DupeItem *new_parent;
2655 dm = parent->group->data;
2656 new_parent = dm->di;
2657 dupe_match_reparent(dw, parent, new_parent);
2658 dupe_listview_remove(dw, parent);
2663 if (g_list_length(parent->group) < 2)
2665 dupe_match_link_clear(parent, TRUE);
2666 dupe_listview_remove(dw, parent);
2667 dw->dupes = g_list_remove(dw->dupes, parent);
2669 dupe_match_link_clear(di, TRUE);
2670 dupe_listview_remove(dw, di);
2675 /* not a dupe, or not sorted yet, simply reset */
2676 dupe_match_link_clear(di, TRUE);
2679 if (dw->second_list && g_list_find(dw->second_list, di))
2681 dupe_second_remove(dw, di);
2685 dw->list = g_list_remove(dw->list, di);
2689 dupe_window_update_count(dw, FALSE);
2692 static gboolean dupe_item_remove_by_path(DupeWindow *dw, const gchar *path)
2696 di = dupe_item_find_path(dw, path);
2697 if (!di) return FALSE;
2699 dupe_item_remove(dw, di);
2704 static gboolean dupe_files_add_queue_cb(gpointer data)
2706 DupeItem *di = NULL;
2707 DupeWindow *dw = data;
2709 GList *queue = dw->add_files_queue;
2711 gtk_progress_bar_pulse(GTK_PROGRESS_BAR(dw->extra_label));
2715 dw->add_files_queue_id = 0;
2716 dupe_destroy_list_cache(dw);
2717 g_idle_add(dupe_check_start_cb, dw);
2718 gtk_widget_set_sensitive(dw->controls_box, TRUE);
2725 if (isfile(fd->path))
2727 di = dupe_item_new(fd);
2729 else if (isdir(fd->path))
2732 dw->add_files_queue = g_list_remove(dw->add_files_queue, g_list_first(dw->add_files_queue)->data);
2734 if (filelist_read(fd, &f, &d))
2736 f = filelist_filter(f, FALSE);
2737 d = filelist_filter(d, TRUE);
2739 dw->add_files_queue = g_list_concat(f, dw->add_files_queue);
2740 dw->add_files_queue = g_list_concat(d, dw->add_files_queue);
2745 /* Not a file and not a dir */
2746 dw->add_files_queue = g_list_remove(dw->add_files_queue, g_list_first(dw->add_files_queue)->data);
2752 /* A dir was found. Process the contents on next entry */
2756 dw->add_files_queue = g_list_remove(dw->add_files_queue, g_list_first(dw->add_files_queue)->data);
2758 dupe_item_read_cache(di);
2760 /* Ensure images in the lists have unique FileDatas */
2761 if (!dupe_insert_in_list_cache(dw, di->fd))
2767 if (dw->second_drop)
2769 dupe_second_add(dw, di);
2773 dw->list = g_list_prepend(dw->list, di);
2776 if (dw->add_files_queue != NULL)
2782 dw->add_files_queue_id = 0;
2783 dupe_destroy_list_cache(dw);
2784 g_idle_add(dupe_check_start_cb, dw);
2785 gtk_widget_set_sensitive(dw->controls_box, TRUE);
2790 static void dupe_files_add(DupeWindow *dw, CollectionData *collection, CollectInfo *info,
2791 FileData *fd, gboolean recurse)
2793 DupeItem *di = NULL;
2797 di = dupe_item_new(info->fd);
2801 if (isfile(fd->path) && !g_file_test(fd->path, G_FILE_TEST_IS_SYMLINK))
2803 di = dupe_item_new(fd);
2805 else if (isdir(fd->path) && recurse)
2808 if (filelist_read(fd, &f, &d))
2812 f = filelist_filter(f, FALSE);
2813 d = filelist_filter(d, TRUE);
2818 dupe_files_add(dw, NULL, NULL, (FileData *)work->data, TRUE);
2825 dupe_files_add(dw, NULL, NULL, (FileData *)work->data, TRUE);
2835 dupe_item_read_cache(di);
2837 /* Ensure images in the lists have unique FileDatas */
2840 work = g_list_first(dw->list);
2843 di_list = work->data;
2844 if (di_list->fd == di->fd)
2854 if (dw->second_list)
2856 work = g_list_first(dw->second_list);
2859 di_list = work->data;
2860 if (di_list->fd == di->fd)
2871 if (dw->second_drop)
2873 dupe_second_add(dw, di);
2877 dw->list = g_list_prepend(dw->list, di);
2881 static void dupe_init_list_cache(DupeWindow *dw)
2883 dw->list_cache = g_hash_table_new(g_direct_hash, g_direct_equal);
2884 dw->second_list_cache = g_hash_table_new(g_direct_hash, g_direct_equal);
2886 for (GList *i = dw->list; i != NULL; i = i->next)
2888 DupeItem *di = i->data;
2890 g_hash_table_add(dw->list_cache, di->fd);
2893 for (GList *i = dw->second_list; i != NULL; i = i->next)
2895 DupeItem *di = i->data;
2897 g_hash_table_add(dw->second_list_cache, di->fd);
2901 static void dupe_destroy_list_cache(DupeWindow *dw)
2903 g_hash_table_destroy(dw->list_cache);
2904 g_hash_table_destroy(dw->second_list_cache);
2908 * @brief Return true if the fd was not in the cache
2915 static gboolean dupe_insert_in_list_cache(DupeWindow *dw, FileData *fd)
2918 dw->second_drop ? dw->second_list_cache : dw->list_cache;
2919 /* We do this as a lookup + add as we don't want to overwrite
2920 items as that would leak the old value. */
2921 if (g_hash_table_lookup(table, fd) != NULL)
2923 return g_hash_table_add(table, fd);
2926 void dupe_window_add_collection(DupeWindow *dw, CollectionData *collection)
2930 info = collection_get_first(collection);
2933 dupe_files_add(dw, collection, info, NULL, FALSE);
2934 info = collection_next_by_info(collection, info);
2937 dupe_check_start(dw);
2940 void dupe_window_add_files(DupeWindow *dw, GList *list, gboolean recurse)
2947 FileData *fd = work->data;
2949 if (isdir(fd->path) && !recurse)
2953 if (filelist_read(fd, &f, &d))
2960 /* Add only the files, ignore the dirs when no recurse */
2961 dw->add_files_queue = g_list_prepend(dw->add_files_queue, work_file->data);
2962 work_file = work_file->next;
2970 dw->add_files_queue = g_list_prepend(dw->add_files_queue, fd);
2973 if (dw->add_files_queue_id == 0)
2975 gtk_progress_bar_pulse(GTK_PROGRESS_BAR(dw->extra_label));
2976 gtk_progress_bar_set_pulse_step(GTK_PROGRESS_BAR(dw->extra_label), DUPE_PROGRESS_PULSE_STEP);
2977 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(dw->extra_label), _("Loading file list"));
2979 dupe_init_list_cache(dw);
2980 dw->add_files_queue_id = g_idle_add(dupe_files_add_queue_cb, dw);
2981 gtk_widget_set_sensitive(dw->controls_box, FALSE);
2985 static void dupe_item_update(DupeWindow *dw, DupeItem *di)
2987 if ( (dw->match_mask & DUPE_MATCH_NAME) || (dw->match_mask & DUPE_MATCH_PATH || (dw->match_mask & DUPE_MATCH_NAME_CI)) )
2989 /* only effects matches on name or path */
2991 FileData *fd = file_data_ref(di->fd);
2994 second = di->second;
2995 dupe_item_remove(dw, di);
2997 dw->second_drop = second;
2998 dupe_files_add(dw, NULL, NULL, fd, FALSE);
2999 dw->second_drop = FALSE;
3001 file_data_unref(fd);
3003 dupe_check_start(dw);
3007 GtkListStore *store;
3010 /* update the listview(s) */
3012 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dw->listview)));
3013 row = dupe_listview_find_item(store, di, &iter);
3016 gtk_list_store_set(store, &iter,
3017 DUPE_COLUMN_NAME, di->fd->name,
3018 DUPE_COLUMN_PATH, di->fd->path, -1);
3021 if (dw->second_listview)
3023 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dw->second_listview)));
3024 row = dupe_listview_find_item(store, di, &iter);
3027 gtk_list_store_set(store, &iter, 1, di->fd->path, -1);
3034 static void dupe_item_update_fd_in_list(DupeWindow *dw, FileData *fd, GList *work)
3038 DupeItem *di = work->data;
3041 dupe_item_update(dw, di);
3047 static void dupe_item_update_fd(DupeWindow *dw, FileData *fd)
3049 dupe_item_update_fd_in_list(dw, fd, dw->list);
3050 if (dw->second_set) dupe_item_update_fd_in_list(dw, fd, dw->second_list);
3055 * ------------------------------------------------------------------
3057 * ------------------------------------------------------------------
3060 static GtkWidget *dupe_display_label(GtkWidget *vbox, const gchar *description, const gchar *text)
3065 hbox = gtk_hbox_new(FALSE, 10);
3067 label = gtk_label_new(description);
3068 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
3069 gtk_widget_show(label);
3071 label = gtk_label_new(text);
3072 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
3073 gtk_widget_show(label);
3075 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
3076 gtk_widget_show(hbox);
3081 static void dupe_display_stats(DupeWindow *dw, DupeItem *di)
3088 gd = file_util_gen_dlg("Image thumbprint debug info", "thumbprint",
3091 generic_dialog_add_button(gd, GTK_STOCK_CLOSE, NULL, NULL, TRUE);
3093 dupe_display_label(gd->vbox, "name:", di->fd->name);
3094 buf = text_from_size(di->fd->size);
3095 dupe_display_label(gd->vbox, "size:", buf);
3097 dupe_display_label(gd->vbox, "date:", text_from_time(di->fd->date));
3098 buf = g_strdup_printf("%d x %d", di->width, di->height);
3099 dupe_display_label(gd->vbox, "dimensions:", buf);
3101 dupe_display_label(gd->vbox, "md5sum:", (di->md5sum) ? di->md5sum : "not generated");
3103 dupe_display_label(gd->vbox, "thumbprint:", (di->simd) ? "" : "not generated");
3114 pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, 32, 32);
3115 rs = gdk_pixbuf_get_rowstride(pixbuf);
3116 d_pix = gdk_pixbuf_get_pixels(pixbuf);
3118 for (y = 0; y < 32; y++)
3120 dp = d_pix + (y * rs);
3122 for (x = 0; x < 32; x++)
3124 *(dp++) = di->simd->avg_r[sp + x];
3125 *(dp++) = di->simd->avg_g[sp + x];
3126 *(dp++) = di->simd->avg_b[sp + x];
3130 image = gtk_image_new_from_pixbuf(pixbuf);
3131 gtk_box_pack_start(GTK_BOX(gd->vbox), image, FALSE, FALSE, 0);
3132 gtk_widget_show(image);
3134 g_object_unref(pixbuf);
3137 gtk_widget_show(gd->dialog);
3140 static void dupe_window_recompare(DupeWindow *dw)
3142 GtkListStore *store;
3144 dupe_check_stop(dw);
3146 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dw->listview)));
3147 gtk_list_store_clear(store);
3149 g_list_free(dw->dupes);
3152 dupe_match_reset_list(dw->list);
3153 dupe_match_reset_list(dw->second_list);
3156 dupe_check_start(dw);
3159 static void dupe_menu_view(DupeWindow *dw, DupeItem *di, GtkWidget *listview, gint new_window)
3163 if (di->collection && collection_info_valid(di->collection, di->info))
3167 view_window_new_from_collection(di->collection, di->info);
3171 layout_image_set_collection(NULL, di->collection, di->info);
3180 list = dupe_listview_get_selection(dw, listview);
3181 view_window_new_from_list(list);
3182 filelist_free(list);
3186 layout_set_fd(NULL, di->fd);
3191 static void dupe_window_remove_selection(DupeWindow *dw, GtkWidget *listview)
3193 GtkTreeSelection *selection;
3194 GtkTreeModel *store;
3200 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(listview));
3201 slist = gtk_tree_selection_get_selected_rows(selection, &store);
3205 GtkTreePath *tpath = work->data;
3206 DupeItem *di = NULL;
3208 gtk_tree_model_get_iter(store, &iter, tpath);
3209 gtk_tree_model_get(store, &iter, DUPE_COLUMN_POINTER, &di, -1);
3210 if (di) list = g_list_prepend(list, di);
3213 g_list_foreach(slist, (GFunc)tree_path_free_wrapper, NULL);
3216 dw->color_frozen = TRUE;
3224 dupe_item_remove(dw, di);
3226 dw->color_frozen = FALSE;
3230 dupe_listview_realign_colors(dw);
3233 static void dupe_window_edit_selected(DupeWindow *dw, const gchar *key)
3235 file_util_start_editor_from_filelist(key, dupe_listview_get_selection(dw, dw->listview), NULL, dw->window);
3238 static void dupe_window_collection_from_selection(DupeWindow *dw)
3243 list = dupe_listview_get_selection(dw, dw->listview);
3244 w = collection_window_new(NULL);
3245 collection_table_add_filelist(w->table, list);
3246 filelist_free(list);
3249 static void dupe_window_append_file_list(DupeWindow *dw, gint on_second)
3253 dw->second_drop = (dw->second_set && on_second);
3255 list = layout_list(NULL);
3256 dupe_window_add_files(dw, list, FALSE);
3257 filelist_free(list);
3261 *-------------------------------------------------------------------
3262 * main pop-up menu callbacks
3263 *-------------------------------------------------------------------
3266 static void dupe_menu_view_cb(GtkWidget *widget, gpointer data)
3268 DupeWindow *dw = data;
3270 if (dw->click_item) dupe_menu_view(dw, dw->click_item, dw->listview, FALSE);
3273 static void dupe_menu_viewnew_cb(GtkWidget *widget, gpointer data)
3275 DupeWindow *dw = data;
3277 if (dw->click_item) dupe_menu_view(dw, dw->click_item, dw->listview, TRUE);
3280 static void dupe_menu_select_all_cb(GtkWidget *widget, gpointer data)
3282 DupeWindow *dw = data;
3283 GtkTreeSelection *selection;
3285 options->duplicates_select_type = DUPE_SELECT_NONE;
3286 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dw->listview));
3287 gtk_tree_selection_select_all(selection);
3290 static void dupe_menu_select_none_cb(GtkWidget *widget, gpointer data)
3292 DupeWindow *dw = data;
3293 GtkTreeSelection *selection;
3295 options->duplicates_select_type = DUPE_SELECT_NONE;
3296 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dw->listview));
3297 gtk_tree_selection_unselect_all(selection);
3300 static void dupe_menu_select_dupes_set1_cb(GtkWidget *widget, gpointer data)
3302 DupeWindow *dw = data;
3304 options->duplicates_select_type = DUPE_SELECT_GROUP1;
3305 dupe_listview_select_dupes(dw, DUPE_SELECT_GROUP1);
3308 static void dupe_menu_select_dupes_set2_cb(GtkWidget *widget, gpointer data)
3310 DupeWindow *dw = data;
3312 options->duplicates_select_type = DUPE_SELECT_GROUP2;
3313 dupe_listview_select_dupes(dw, DUPE_SELECT_GROUP2);
3316 static void dupe_menu_edit_cb(GtkWidget *widget, gpointer data)
3319 const gchar *key = data;
3321 dw = submenu_item_get_data(widget);
3324 dupe_window_edit_selected(dw, key);
3327 static void dupe_menu_print_cb(GtkWidget *widget, gpointer data)
3329 DupeWindow *dw = data;
3332 fd = (dw->click_item) ? dw->click_item->fd : NULL;
3334 print_window_new(fd,
3335 dupe_listview_get_selection(dw, dw->listview),
3336 dupe_listview_get_filelist(dw, dw->listview), dw->window);
3339 static void dupe_menu_copy_cb(GtkWidget *widget, gpointer data)
3341 DupeWindow *dw = data;
3343 file_util_copy(NULL, dupe_listview_get_selection(dw, dw->listview), NULL, dw->window);
3346 static void dupe_menu_move_cb(GtkWidget *widget, gpointer data)
3348 DupeWindow *dw = data;
3350 file_util_move(NULL, dupe_listview_get_selection(dw, dw->listview), NULL, dw->window);
3353 static void dupe_menu_rename_cb(GtkWidget *widget, gpointer data)
3355 DupeWindow *dw = data;
3357 file_util_rename(NULL, dupe_listview_get_selection(dw, dw->listview), dw->window);
3360 static void dupe_menu_delete_cb(GtkWidget *widget, gpointer data)
3362 DupeWindow *dw = data;
3364 options->file_ops.safe_delete_enable = FALSE;
3365 file_util_delete_notify_done(NULL, dupe_listview_get_selection(dw, dw->listview), dw->window, delete_finished_cb, dw);
3368 static void dupe_menu_move_to_trash_cb(GtkWidget *widget, gpointer data)
3370 DupeWindow *dw = data;
3372 options->file_ops.safe_delete_enable = TRUE;
3373 file_util_delete_notify_done(NULL, dupe_listview_get_selection(dw, dw->listview), dw->window, delete_finished_cb, dw);
3376 static void dupe_menu_copy_path_cb(GtkWidget *widget, gpointer data)
3378 DupeWindow *dw = data;
3380 file_util_copy_path_list_to_clipboard(dupe_listview_get_selection(dw, dw->listview), TRUE);
3383 static void dupe_menu_copy_path_unquoted_cb(GtkWidget *widget, gpointer data)
3385 DupeWindow *dw = data;
3387 file_util_copy_path_list_to_clipboard(dupe_listview_get_selection(dw, dw->listview), FALSE);
3390 static void dupe_menu_remove_cb(GtkWidget *widget, gpointer data)
3392 DupeWindow *dw = data;
3394 dupe_window_remove_selection(dw, dw->listview);
3397 static void dupe_menu_clear_cb(GtkWidget *widget, gpointer data)
3399 DupeWindow *dw = data;
3401 dupe_window_clear(dw);
3404 static void dupe_menu_close_cb(GtkWidget *widget, gpointer data)
3406 DupeWindow *dw = data;
3408 dupe_window_close(dw);
3411 static void dupe_menu_popup_destroy_cb(GtkWidget *widget, gpointer data)
3413 GList *editmenu_fd_list = data;
3415 filelist_free(editmenu_fd_list);
3418 static GList *dupe_window_get_fd_list(DupeWindow *dw)
3422 if (gtk_widget_has_focus(dw->second_listview))
3424 list = dupe_listview_get_selection(dw, dw->second_listview);
3428 list = dupe_listview_get_selection(dw, dw->listview);
3435 * @brief Add file selection list to a collection
3437 * @param[in] data Index to the collection list menu item selected, or -1 for new collection
3441 static void dupe_pop_menu_collections_cb(GtkWidget *widget, gpointer data)
3444 GList *selection_list;
3446 dw = submenu_item_get_data(widget);
3447 selection_list = dupe_listview_get_selection(dw, dw->listview);
3448 pop_menu_collections(selection_list, data);
3450 filelist_free(selection_list);
3453 static GtkWidget *dupe_menu_popup_main(DupeWindow *dw, DupeItem *di)
3458 GList *editmenu_fd_list;
3460 on_row = (di != NULL);
3462 menu = popup_menu_short_lived();
3464 menu_item_add_sensitive(menu, _("_View"), on_row,
3465 G_CALLBACK(dupe_menu_view_cb), dw);
3466 menu_item_add_stock_sensitive(menu, _("View in _new window"), GTK_STOCK_NEW, on_row,
3467 G_CALLBACK(dupe_menu_viewnew_cb), dw);
3468 menu_item_add_divider(menu);
3469 menu_item_add_sensitive(menu, _("Select all"), (dw->dupes != NULL),
3470 G_CALLBACK(dupe_menu_select_all_cb), dw);
3471 menu_item_add_sensitive(menu, _("Select none"), (dw->dupes != NULL),
3472 G_CALLBACK(dupe_menu_select_none_cb), dw);
3473 menu_item_add_sensitive(menu, _("Select group _1 duplicates"), (dw->dupes != NULL),
3474 G_CALLBACK(dupe_menu_select_dupes_set1_cb), dw);
3475 menu_item_add_sensitive(menu, _("Select group _2 duplicates"), (dw->dupes != NULL),
3476 G_CALLBACK(dupe_menu_select_dupes_set2_cb), dw);
3477 menu_item_add_divider(menu);
3479 submenu_add_export(menu, &item, G_CALLBACK(dupe_pop_menu_export_cb), dw);
3480 gtk_widget_set_sensitive(item, on_row);
3481 menu_item_add_divider(menu);
3483 editmenu_fd_list = dupe_window_get_fd_list(dw);
3484 g_signal_connect(G_OBJECT(menu), "destroy",
3485 G_CALLBACK(dupe_menu_popup_destroy_cb), editmenu_fd_list);
3486 submenu_add_edit(menu, &item, G_CALLBACK(dupe_menu_edit_cb), dw, editmenu_fd_list);
3487 if (!on_row) gtk_widget_set_sensitive(item, FALSE);
3489 submenu_add_collections(menu, &item,
3490 G_CALLBACK(dupe_pop_menu_collections_cb), dw);
3491 gtk_widget_set_sensitive(item, on_row);
3493 menu_item_add_stock_sensitive(menu, _("Print..."), GTK_STOCK_PRINT, on_row,
3494 G_CALLBACK(dupe_menu_print_cb), dw);
3495 menu_item_add_divider(menu);
3496 menu_item_add_stock_sensitive(menu, _("_Copy..."), GTK_STOCK_COPY, on_row,
3497 G_CALLBACK(dupe_menu_copy_cb), dw);
3498 menu_item_add_sensitive(menu, _("_Move..."), on_row,
3499 G_CALLBACK(dupe_menu_move_cb), dw);
3500 menu_item_add_sensitive(menu, _("_Rename..."), on_row,
3501 G_CALLBACK(dupe_menu_rename_cb), dw);
3502 menu_item_add_sensitive(menu, _("_Copy path"), on_row,
3503 G_CALLBACK(dupe_menu_copy_path_cb), dw);
3504 menu_item_add_sensitive(menu, _("_Copy path unquoted"), on_row,
3505 G_CALLBACK(dupe_menu_copy_path_unquoted_cb), dw);
3507 menu_item_add_divider(menu);
3508 menu_item_add_stock_sensitive(menu,
3509 options->file_ops.confirm_move_to_trash ? _("Move to Trash...") :
3510 _("Move to Trash"), PIXBUF_INLINE_ICON_TRASH, on_row,
3511 G_CALLBACK(dupe_menu_move_to_trash_cb), dw);
3512 menu_item_add_stock_sensitive(menu,
3513 options->file_ops.confirm_delete ? _("_Delete...") :
3514 _("_Delete"), GTK_STOCK_DELETE, on_row,
3515 G_CALLBACK(dupe_menu_delete_cb), dw);
3517 menu_item_add_divider(menu);
3518 menu_item_add_stock_sensitive(menu, _("Rem_ove"), GTK_STOCK_REMOVE, on_row,
3519 G_CALLBACK(dupe_menu_remove_cb), dw);
3520 menu_item_add_stock_sensitive(menu, _("C_lear"), GTK_STOCK_CLEAR, (dw->list != NULL),
3521 G_CALLBACK(dupe_menu_clear_cb), dw);
3522 menu_item_add_divider(menu);
3523 menu_item_add_stock(menu, _("Close _window"), GTK_STOCK_CLOSE,
3524 G_CALLBACK(dupe_menu_close_cb), dw);
3529 static gboolean dupe_listview_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
3531 DupeWindow *dw = data;
3532 GtkTreeModel *store;
3535 DupeItem *di = NULL;
3537 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget));
3539 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bevent->x, bevent->y,
3540 &tpath, NULL, NULL, NULL))
3542 gtk_tree_model_get_iter(store, &iter, tpath);
3543 gtk_tree_model_get(store, &iter, DUPE_COLUMN_POINTER, &di, -1);
3544 gtk_tree_path_free(tpath);
3547 dw->click_item = di;
3549 if (bevent->button == MOUSE_BUTTON_RIGHT)
3551 /* right click menu */
3554 if (bevent->state & GDK_CONTROL_MASK && bevent->state & GDK_SHIFT_MASK)
3556 dupe_display_stats(dw, di);
3559 if (widget == dw->listview)
3561 menu = dupe_menu_popup_main(dw, di);
3565 menu = dupe_menu_popup_second(dw, di);
3567 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, bevent->button, bevent->time);
3570 if (!di) return FALSE;
3572 if (bevent->button == MOUSE_BUTTON_LEFT &&
3573 bevent->type == GDK_2BUTTON_PRESS)
3575 dupe_menu_view(dw, di, widget, FALSE);
3578 if (bevent->button == MOUSE_BUTTON_MIDDLE) return TRUE;
3580 if (bevent->button == MOUSE_BUTTON_RIGHT)
3582 if (!dupe_listview_item_is_selected(dw, di, widget))
3584 GtkTreeSelection *selection;
3586 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
3587 gtk_tree_selection_unselect_all(selection);
3588 gtk_tree_selection_select_iter(selection, &iter);
3590 tpath = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter);
3591 gtk_tree_view_set_cursor(GTK_TREE_VIEW(widget), tpath, NULL, FALSE);
3592 gtk_tree_path_free(tpath);
3598 if (bevent->button == MOUSE_BUTTON_LEFT &&
3599 bevent->type == GDK_BUTTON_PRESS &&
3600 !(bevent->state & GDK_SHIFT_MASK ) &&
3601 !(bevent->state & GDK_CONTROL_MASK ) &&
3602 dupe_listview_item_is_selected(dw, di, widget))
3604 /* this selection handled on release_cb */
3605 gtk_widget_grab_focus(widget);
3612 static gboolean dupe_listview_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data)
3614 DupeWindow *dw = data;
3615 GtkTreeModel *store;
3618 DupeItem *di = NULL;
3620 if (bevent->button != MOUSE_BUTTON_LEFT && bevent->button != MOUSE_BUTTON_MIDDLE) return TRUE;
3622 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget));
3624 if ((bevent->x != 0 || bevent->y != 0) &&
3625 gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bevent->x, bevent->y,
3626 &tpath, NULL, NULL, NULL))
3628 gtk_tree_model_get_iter(store, &iter, tpath);
3629 gtk_tree_model_get(store, &iter, DUPE_COLUMN_POINTER, &di, -1);
3630 gtk_tree_path_free(tpath);
3633 if (bevent->button == MOUSE_BUTTON_MIDDLE)
3635 if (di && dw->click_item == di)
3637 GtkTreeSelection *selection;
3639 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
3640 if (dupe_listview_item_is_selected(dw, di, widget))
3642 gtk_tree_selection_unselect_iter(selection, &iter);
3646 gtk_tree_selection_select_iter(selection, &iter);
3652 if (di && dw->click_item == di &&
3653 !(bevent->state & GDK_SHIFT_MASK ) &&
3654 !(bevent->state & GDK_CONTROL_MASK ) &&
3655 dupe_listview_item_is_selected(dw, di, widget))
3657 GtkTreeSelection *selection;
3659 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
3660 gtk_tree_selection_unselect_all(selection);
3661 gtk_tree_selection_select_iter(selection, &iter);
3663 tpath = gtk_tree_model_get_path(store, &iter);
3664 gtk_tree_view_set_cursor(GTK_TREE_VIEW(widget), tpath, NULL, FALSE);
3665 gtk_tree_path_free(tpath);
3674 *-------------------------------------------------------------------
3676 *-------------------------------------------------------------------
3679 static void dupe_second_update_status(DupeWindow *dw)
3683 buf = g_strdup_printf(_("%d files (set 2)"), g_list_length(dw->second_list));
3684 gtk_label_set_text(GTK_LABEL(dw->second_status_label), buf);
3688 static void dupe_second_add(DupeWindow *dw, DupeItem *di)
3690 GtkListStore *store;
3696 dw->second_list = g_list_prepend(dw->second_list, di);
3698 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dw->second_listview)));
3699 gtk_list_store_append(store, &iter);
3700 gtk_list_store_set(store, &iter, DUPE_COLUMN_POINTER, di, 1, di->fd->path, -1);
3702 dupe_second_update_status(dw);
3705 static void dupe_second_remove(DupeWindow *dw, DupeItem *di)
3707 GtkListStore *store;
3710 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dw->second_listview)));
3711 if (dupe_listview_find_item(store, di, &iter) >= 0)
3713 tree_view_move_cursor_away(GTK_TREE_VIEW(dw->second_listview), &iter, TRUE);
3714 gtk_list_store_remove(store, &iter);
3717 dw->second_list = g_list_remove(dw->second_list, di);
3719 dupe_second_update_status(dw);
3722 static void dupe_second_clear(DupeWindow *dw)
3724 GtkListStore *store;
3726 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dw->second_listview)));
3727 gtk_list_store_clear(store);
3728 gtk_tree_view_columns_autosize(GTK_TREE_VIEW(dw->second_listview));
3730 g_list_free(dw->dupes);
3733 dupe_list_free(dw->second_list);
3734 dw->second_list = NULL;
3736 dupe_match_reset_list(dw->list);
3738 dupe_second_update_status(dw);
3741 static void dupe_second_menu_view_cb(GtkWidget *widget, gpointer data)
3743 DupeWindow *dw = data;
3745 if (dw->click_item) dupe_menu_view(dw, dw->click_item, dw->second_listview, FALSE);
3748 static void dupe_second_menu_viewnew_cb(GtkWidget *widget, gpointer data)
3750 DupeWindow *dw = data;
3752 if (dw->click_item) dupe_menu_view(dw, dw->click_item, dw->second_listview, TRUE);
3755 static void dupe_second_menu_select_all_cb(GtkWidget *widget, gpointer data)
3757 GtkTreeSelection *selection;
3758 DupeWindow *dw = data;
3760 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dw->second_listview));
3761 gtk_tree_selection_select_all(selection);
3764 static void dupe_second_menu_select_none_cb(GtkWidget *widget, gpointer data)
3766 GtkTreeSelection *selection;
3767 DupeWindow *dw = data;
3769 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dw->second_listview));
3770 gtk_tree_selection_unselect_all(selection);
3773 static void dupe_second_menu_remove_cb(GtkWidget *widget, gpointer data)
3775 DupeWindow *dw = data;
3777 dupe_window_remove_selection(dw, dw->second_listview);
3780 static void dupe_second_menu_clear_cb(GtkWidget *widget, gpointer data)
3782 DupeWindow *dw = data;
3784 dupe_second_clear(dw);
3785 dupe_window_recompare(dw);
3788 static GtkWidget *dupe_menu_popup_second(DupeWindow *dw, DupeItem *di)
3791 gboolean notempty = (dw->second_list != NULL);
3792 gboolean on_row = (di != NULL);
3794 menu = popup_menu_short_lived();
3795 menu_item_add_sensitive(menu, _("_View"), on_row,
3796 G_CALLBACK(dupe_second_menu_view_cb), dw);
3797 menu_item_add_stock_sensitive(menu, _("View in _new window"), GTK_STOCK_NEW, on_row,
3798 G_CALLBACK(dupe_second_menu_viewnew_cb), dw);
3799 menu_item_add_divider(menu);
3800 menu_item_add_sensitive(menu, _("Select all"), notempty,
3801 G_CALLBACK(dupe_second_menu_select_all_cb), dw);
3802 menu_item_add_sensitive(menu, _("Select none"), notempty,
3803 G_CALLBACK(dupe_second_menu_select_none_cb), dw);
3804 menu_item_add_divider(menu);
3805 menu_item_add_stock_sensitive(menu, _("Rem_ove"), GTK_STOCK_REMOVE, on_row,
3806 G_CALLBACK(dupe_second_menu_remove_cb), dw);
3807 menu_item_add_stock_sensitive(menu, _("C_lear"), GTK_STOCK_CLEAR, notempty,
3808 G_CALLBACK(dupe_second_menu_clear_cb), dw);
3809 menu_item_add_divider(menu);
3810 menu_item_add_stock(menu, _("Close _window"), GTK_STOCK_CLOSE,
3811 G_CALLBACK(dupe_menu_close_cb), dw);
3816 static void dupe_second_set_toggle_cb(GtkWidget *widget, gpointer data)
3818 DupeWindow *dw = data;
3820 dw->second_set = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
3824 dupe_second_update_status(dw);
3825 gtk_table_set_col_spacings(GTK_TABLE(dw->table), PREF_PAD_GAP);
3826 gtk_widget_show(dw->second_vbox);
3830 gtk_table_set_col_spacings(GTK_TABLE(dw->table), 0);
3831 gtk_widget_hide(dw->second_vbox);
3832 dupe_second_clear(dw);
3835 dupe_window_recompare(dw);
3838 static void dupe_sort_totals_toggle_cb(GtkWidget *widget, gpointer data)
3840 DupeWindow *dw = data;
3842 options->sort_totals = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
3843 dupe_window_recompare(dw);
3848 *-------------------------------------------------------------------
3850 *-------------------------------------------------------------------
3854 DUPE_MENU_COLUMN_NAME = 0,
3855 DUPE_MENU_COLUMN_MASK
3858 static void dupe_listview_show_rank(GtkWidget *listview, gboolean rank);
3860 static void dupe_menu_type_cb(GtkWidget *combo, gpointer data)
3862 DupeWindow *dw = data;
3863 GtkTreeModel *store;
3866 store = gtk_combo_box_get_model(GTK_COMBO_BOX(combo));
3867 if (!gtk_combo_box_get_active_iter(GTK_COMBO_BOX(combo), &iter)) return;
3868 gtk_tree_model_get(store, &iter, DUPE_MENU_COLUMN_MASK, &dw->match_mask, -1);
3870 options->duplicates_match = dw->match_mask;
3872 if (dw->match_mask & (DUPE_MATCH_SIM_HIGH | DUPE_MATCH_SIM_MED | DUPE_MATCH_SIM_LOW | DUPE_MATCH_SIM_CUSTOM))
3874 dupe_listview_show_rank(dw->listview, TRUE);
3878 dupe_listview_show_rank(dw->listview, FALSE);
3880 dupe_window_recompare(dw);
3883 static void dupe_menu_add_item(GtkListStore *store, const gchar *text, DupeMatchType type, DupeWindow *dw)
3887 gtk_list_store_append(store, &iter);
3888 gtk_list_store_set(store, &iter, DUPE_MENU_COLUMN_NAME, text,
3889 DUPE_MENU_COLUMN_MASK, type, -1);
3891 if (dw->match_mask == type) gtk_combo_box_set_active_iter(GTK_COMBO_BOX(dw->combo), &iter);
3894 static void dupe_menu_setup(DupeWindow *dw)
3896 GtkListStore *store;
3897 GtkCellRenderer *renderer;
3899 store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INT);
3900 dw->combo = gtk_combo_box_new_with_model(GTK_TREE_MODEL(store));
3901 g_object_unref(store);
3903 renderer = gtk_cell_renderer_text_new();
3904 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(dw->combo), renderer, TRUE);
3905 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(dw->combo), renderer,
3906 "text", DUPE_MENU_COLUMN_NAME, NULL);
3908 dupe_menu_add_item(store, _("Name"), DUPE_MATCH_NAME, dw);
3909 dupe_menu_add_item(store, _("Name case-insensitive"), DUPE_MATCH_NAME_CI, dw);
3910 dupe_menu_add_item(store, _("Size"), DUPE_MATCH_SIZE, dw);
3911 dupe_menu_add_item(store, _("Date"), DUPE_MATCH_DATE, dw);
3912 dupe_menu_add_item(store, _("Dimensions"), DUPE_MATCH_DIM, dw);
3913 dupe_menu_add_item(store, _("Checksum"), DUPE_MATCH_SUM, dw);
3914 dupe_menu_add_item(store, _("Path"), DUPE_MATCH_PATH, dw);
3915 dupe_menu_add_item(store, _("Similarity (high - 95)"), DUPE_MATCH_SIM_HIGH, dw);
3916 dupe_menu_add_item(store, _("Similarity (med. - 90)"), DUPE_MATCH_SIM_MED, dw);
3917 dupe_menu_add_item(store, _("Similarity (low - 85)"), DUPE_MATCH_SIM_LOW, dw);
3918 dupe_menu_add_item(store, _("Similarity (custom)"), DUPE_MATCH_SIM_CUSTOM, dw);
3919 dupe_menu_add_item(store, _("Name ≠content"), DUPE_MATCH_NAME_CONTENT, dw);
3920 dupe_menu_add_item(store, _("Name case-insensitive ≠content"), DUPE_MATCH_NAME_CI_CONTENT, dw);
3921 dupe_menu_add_item(store, _("Show all"), DUPE_MATCH_ALL, dw);
3923 g_signal_connect(G_OBJECT(dw->combo), "changed",
3924 G_CALLBACK(dupe_menu_type_cb), dw);
3928 *-------------------------------------------------------------------
3930 *-------------------------------------------------------------------
3933 /* this overrides the low default of a GtkCellRenderer from 100 to CELL_HEIGHT_OVERRIDE, something sane for our purposes */
3935 #define CELL_HEIGHT_OVERRIDE 512
3937 void cell_renderer_height_override(GtkCellRenderer *renderer)
3941 spec = g_object_class_find_property(G_OBJECT_GET_CLASS(G_OBJECT(renderer)), "height");
3942 if (spec && G_IS_PARAM_SPEC_INT(spec))
3944 GParamSpecInt *spec_int;
3946 spec_int = G_PARAM_SPEC_INT(spec);
3947 if (spec_int->maximum < CELL_HEIGHT_OVERRIDE) spec_int->maximum = CELL_HEIGHT_OVERRIDE;
3951 static GdkColor *dupe_listview_color_shifted(GtkWidget *widget)
3953 static GdkColor color;
3954 static GtkWidget *done = NULL;
3960 style = gtk_widget_get_style(widget);
3961 memcpy(&color, &style->base[GTK_STATE_NORMAL], sizeof(color));
3962 shift_color(&color, -1, 0);
3969 static void dupe_listview_color_cb(GtkTreeViewColumn *tree_column, GtkCellRenderer *cell,
3970 GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data)
3972 DupeWindow *dw = data;
3975 gtk_tree_model_get(tree_model, iter, DUPE_COLUMN_COLOR, &set, -1);
3976 g_object_set(G_OBJECT(cell),
3977 "cell-background-gdk", dupe_listview_color_shifted(dw->listview),
3978 "cell-background-set", set, NULL);
3981 static void dupe_listview_add_column(DupeWindow *dw, GtkWidget *listview, gint n, const gchar *title, gboolean image, gboolean right_justify)
3983 GtkTreeViewColumn *column;
3984 GtkCellRenderer *renderer;
3986 column = gtk_tree_view_column_new();
3987 gtk_tree_view_column_set_title(column, title);
3988 gtk_tree_view_column_set_min_width(column, 4);
3989 gtk_tree_view_column_set_sort_column_id(column, n);
3991 if (n != DUPE_COLUMN_RANK &&
3992 n != DUPE_COLUMN_THUMB)
3994 gtk_tree_view_column_set_resizable(column, TRUE);
3999 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_GROW_ONLY);
4000 renderer = gtk_cell_renderer_text_new();
4003 g_object_set(G_OBJECT(renderer), "xalign", 1.0, NULL);
4005 gtk_tree_view_column_pack_start(column, renderer, TRUE);
4006 gtk_tree_view_column_add_attribute(column, renderer, "text", n);
4010 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
4011 renderer = gtk_cell_renderer_pixbuf_new();
4012 cell_renderer_height_override(renderer);
4013 gtk_tree_view_column_pack_start(column, renderer, TRUE);
4014 gtk_tree_view_column_add_attribute(column, renderer, "pixbuf", n);
4017 if (listview == dw->listview)
4019 /* sets background before rendering */
4020 gtk_tree_view_column_set_cell_data_func(column, renderer, dupe_listview_color_cb, dw, NULL);
4023 gtk_tree_view_append_column(GTK_TREE_VIEW(listview), column);
4026 static void dupe_listview_set_height(GtkWidget *listview, gboolean thumb)
4028 GtkTreeViewColumn *column;
4029 GtkCellRenderer *cell;
4032 column = gtk_tree_view_get_column(GTK_TREE_VIEW(listview), DUPE_COLUMN_THUMB - 1);
4033 if (!column) return;
4035 gtk_tree_view_column_set_fixed_width(column, (thumb) ? options->thumbnails.max_width : 4);
4036 gtk_tree_view_column_set_visible(column, thumb);
4038 list = gtk_cell_layout_get_cells(GTK_CELL_LAYOUT(column));
4043 g_object_set(G_OBJECT(cell), "height", (thumb) ? options->thumbnails.max_height : -1, NULL);
4044 gtk_tree_view_columns_autosize(GTK_TREE_VIEW(listview));
4047 static void dupe_listview_show_rank(GtkWidget *listview, gboolean rank)
4049 GtkTreeViewColumn *column;
4051 column = gtk_tree_view_get_column(GTK_TREE_VIEW(listview), DUPE_COLUMN_RANK - 1);
4052 if (!column) return;
4054 gtk_tree_view_column_set_visible(column, rank);
4058 *-------------------------------------------------------------------
4060 *-------------------------------------------------------------------
4063 static void dupe_window_show_thumb_cb(GtkWidget *widget, gpointer data)
4065 DupeWindow *dw = data;
4067 dw->show_thumbs = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
4068 options->duplicates_thumbnails = dw->show_thumbs;
4070 if (dw->show_thumbs)
4072 if (!dw->working) dupe_thumb_step(dw);
4076 GtkTreeModel *store;
4080 thumb_loader_free(dw->thumb_loader);
4081 dw->thumb_loader = NULL;
4083 store = gtk_tree_view_get_model(GTK_TREE_VIEW(dw->listview));
4084 valid = gtk_tree_model_get_iter_first(store, &iter);
4088 gtk_list_store_set(GTK_LIST_STORE(store), &iter, DUPE_COLUMN_THUMB, NULL, -1);
4089 valid = gtk_tree_model_iter_next(store, &iter);
4091 dupe_window_update_progress(dw, NULL, 0.0, FALSE);
4094 dupe_listview_set_height(dw->listview, dw->show_thumbs);
4097 static void dupe_window_rotation_invariant_cb(GtkWidget *widget, gpointer data)
4099 DupeWindow *dw = data;
4101 options->rot_invariant_sim = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
4102 dupe_window_recompare(dw);
4105 static void dupe_window_custom_threshold_cb(GtkWidget *widget, gpointer data)
4107 DupeWindow *dw = data;
4108 DupeMatchType match_type;
4109 GtkTreeModel *store;
4113 options->duplicates_similarity_threshold = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));
4114 dw->match_mask = DUPE_MATCH_SIM_CUSTOM;
4116 store = gtk_combo_box_get_model(GTK_COMBO_BOX(dw->combo));
4117 valid = gtk_tree_model_get_iter_first(store, &iter);
4120 gtk_tree_model_get(store, &iter, DUPE_MENU_COLUMN_MASK, &match_type, -1);
4121 if (match_type == DUPE_MATCH_SIM_CUSTOM)
4125 valid = gtk_tree_model_iter_next(store, &iter);
4128 gtk_combo_box_set_active_iter(GTK_COMBO_BOX(dw->combo), &iter);
4129 dupe_window_recompare(dw);
4132 static void dupe_popup_menu_pos_cb(GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer data)
4134 GtkWidget *view = data;
4136 gint cx, cy, cw, ch;
4139 gtk_tree_view_get_cursor(GTK_TREE_VIEW(view), &tpath, NULL);
4142 if (gtk_tree_view_get_column(GTK_TREE_VIEW(view), DUPE_COLUMN_NAME - 1) != NULL)
4144 column = DUPE_COLUMN_NAME - 1;
4148 /* dw->second_listview */
4151 tree_view_get_cell_clamped(GTK_TREE_VIEW(view), tpath, column, TRUE, &cx, &cy, &cw, &ch);
4152 gtk_tree_path_free(tpath);
4154 popup_menu_position_clamp(menu, &cx, &cy, 0);
4159 static gboolean dupe_window_keypress_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
4161 DupeWindow *dw = data;
4162 gboolean stop_signal = FALSE;
4164 GtkWidget *listview;
4165 GtkTreeModel *store;
4166 GtkTreeSelection *selection;
4168 DupeItem *di = NULL;
4170 on_second = gtk_widget_has_focus(dw->second_listview);
4174 listview = dw->second_listview;
4178 listview = dw->listview;
4181 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(listview));
4182 slist = gtk_tree_selection_get_selected_rows(selection, &store);
4189 last = g_list_last(slist);
4192 /* last is newest selected file */
4193 gtk_tree_model_get_iter(store, &iter, tpath);
4194 gtk_tree_model_get(store, &iter, DUPE_COLUMN_POINTER, &di, -1);
4196 g_list_foreach(slist, (GFunc)tree_path_free_wrapper, NULL);
4199 if (event->state & GDK_CONTROL_MASK)
4204 switch (event->keyval)
4218 file_util_copy(NULL, dupe_listview_get_selection(dw, listview),
4222 file_util_move(NULL, dupe_listview_get_selection(dw, listview),
4226 file_util_rename(NULL, dupe_listview_get_selection(dw, listview), dw->window);
4229 options->file_ops.safe_delete_enable = TRUE;
4230 file_util_delete(NULL, dupe_listview_get_selection(dw, listview), dw->window);
4233 stop_signal = FALSE;
4241 switch (event->keyval)
4244 if (event->state & GDK_SHIFT_MASK)
4246 gtk_tree_selection_unselect_all(selection);
4250 gtk_tree_selection_select_all(selection);
4253 case GDK_KEY_Delete: case GDK_KEY_KP_Delete:
4256 dupe_second_clear(dw);
4257 dupe_window_recompare(dw);
4261 dupe_window_clear(dw);
4265 dupe_window_append_file_list(dw, FALSE);
4268 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dw->button_thumbs),
4269 !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dw->button_thumbs)));
4272 dupe_window_close(dw);
4275 stop_signal = FALSE;
4283 switch (event->keyval)
4285 case GDK_KEY_Return: case GDK_KEY_KP_Enter:
4286 dupe_menu_view(dw, di, listview, FALSE);
4289 dupe_menu_view(dw, di, listview, TRUE);
4291 case GDK_KEY_Delete: case GDK_KEY_KP_Delete:
4292 dupe_window_remove_selection(dw, listview);
4297 dupe_window_collection_from_selection(dw);
4301 options->duplicates_select_type = DUPE_SELECT_NONE;
4302 dupe_listview_select_dupes(dw, DUPE_SELECT_NONE);
4305 options->duplicates_select_type = DUPE_SELECT_GROUP1;
4306 dupe_listview_select_dupes(dw, DUPE_SELECT_GROUP1);
4309 options->duplicates_select_type = DUPE_SELECT_GROUP2;
4310 dupe_listview_select_dupes(dw, DUPE_SELECT_GROUP2);
4318 menu = dupe_menu_popup_main(dw, di);
4319 gtk_menu_popup(GTK_MENU(menu), NULL, NULL,
4320 dupe_popup_menu_pos_cb, listview, 0, GDK_CURRENT_TIME);
4326 menu = dupe_menu_popup_second(dw, di);
4327 gtk_menu_popup(GTK_MENU(menu), NULL, NULL,
4328 dupe_popup_menu_pos_cb, listview, 0, GDK_CURRENT_TIME);
4332 stop_signal = FALSE;
4336 if (!stop_signal && is_help_key(event))
4338 help_window_show("GuideImageSearchFindingDuplicates.html");
4346 void dupe_window_clear(DupeWindow *dw)
4348 GtkListStore *store;
4350 dupe_check_stop(dw);
4352 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dw->listview)));
4353 gtk_list_store_clear(store);
4354 gtk_tree_view_columns_autosize(GTK_TREE_VIEW(dw->listview));
4356 g_list_free(dw->dupes);
4359 dupe_list_free(dw->list);
4363 dupe_match_reset_list(dw->second_list);
4365 dupe_window_update_count(dw, FALSE);
4366 dupe_window_update_progress(dw, NULL, 0.0, FALSE);
4369 static void dupe_window_get_geometry(DupeWindow *dw)
4372 LayoutWindow *lw = NULL;
4376 if (!dw || !lw) return;
4378 window = gtk_widget_get_window(dw->window);
4379 gdk_window_get_position(window, &lw->options.dupe_window.x, &lw->options.dupe_window.y);
4380 lw->options.dupe_window.w = gdk_window_get_width(window);
4381 lw->options.dupe_window.h = gdk_window_get_height(window);
4384 void dupe_window_close(DupeWindow *dw)
4386 dupe_check_stop(dw);
4388 dupe_window_get_geometry(dw);
4390 dupe_window_list = g_list_remove(dupe_window_list, dw);
4391 gtk_widget_destroy(dw->window);
4393 g_list_free(dw->dupes);
4394 dupe_list_free(dw->list);
4396 dupe_list_free(dw->second_list);
4398 file_data_unregister_notify_func(dupe_notify_cb, dw);
4400 g_thread_pool_free(dw->dupe_comparison_thread_pool, TRUE, TRUE);
4405 static gint dupe_window_close_cb(GtkWidget *widget, gpointer data)
4407 DupeWindow *dw = data;
4409 dupe_window_close(dw);
4414 static gint dupe_window_delete(GtkWidget *widget, GdkEvent *event, gpointer data)
4416 DupeWindow *dw = data;
4417 dupe_window_close(dw);
4422 static void dupe_help_cb(GtkAction *action, gpointer data)
4424 help_window_show("GuideImageSearchFindingDuplicates.html");
4427 static gint default_sort_cb(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer data)
4432 static gint column_sort_cb(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer data)
4434 GtkTreeSortable *sortable = data;
4436 gchar *rank_str_a, *rank_str_b;
4441 gint sort_column_id;
4442 GtkSortType sort_order;
4446 gtk_tree_sortable_get_sort_column_id(sortable, &sort_column_id, &sort_order);
4448 gtk_tree_model_get(model, a, DUPE_COLUMN_RANK, &rank_str_a, DUPE_COLUMN_SET, &group_a, DUPE_COLUMN_POINTER, &di_a, -1);
4450 gtk_tree_model_get(model, b, DUPE_COLUMN_RANK, &rank_str_b, DUPE_COLUMN_SET, &group_b, DUPE_COLUMN_POINTER, &di_b, -1);
4452 if (group_a == group_b)
4454 switch (sort_column_id)
4456 case DUPE_COLUMN_NAME:
4457 ret = utf8_compare(di_a->fd->name, di_b->fd->name, TRUE);
4459 case DUPE_COLUMN_SIZE:
4460 if (di_a->fd->size == di_b->fd->size)
4466 ret = (di_a->fd->size > di_b->fd->size) ? 1 : -1;
4469 case DUPE_COLUMN_DATE:
4470 if (di_a->fd->date == di_b->fd->date)
4476 ret = (di_a->fd->date > di_b->fd->date) ? 1 : -1;
4479 case DUPE_COLUMN_DIMENSIONS:
4480 if ((di_a->width == di_b->width) && (di_a->height == di_b->height))
4486 ret = ((di_a->width * di_a->height) > (di_b->width * di_b->height)) ? 1 : -1;
4489 case DUPE_COLUMN_RANK:
4490 rank_int_a = atoi(rank_str_a);
4491 rank_int_b = atoi(rank_str_b);
4492 if (rank_int_a == 0) rank_int_a = 101;
4493 if (rank_int_b == 0) rank_int_b = 101;
4495 if (rank_int_a == rank_int_b)
4501 ret = (rank_int_a > rank_int_b) ? 1 : -1;
4504 case DUPE_COLUMN_PATH:
4505 ret = utf8_compare(di_a->fd->path, di_b->fd->path, TRUE);
4509 else if (group_a < group_b)
4511 ret = (sort_order == GTK_SORT_ASCENDING) ? 1 : -1;
4515 ret = (sort_order == GTK_SORT_ASCENDING) ? -1 : 1;
4521 static void column_clicked_cb(GtkWidget *widget, gpointer data)
4523 DupeWindow *dw = data;
4525 options->duplicates_match = DUPE_SELECT_NONE;
4526 dupe_listview_select_dupes(dw, DUPE_SELECT_NONE);
4529 /* collection and files can be NULL */
4530 DupeWindow *dupe_window_new()
4535 GtkWidget *scrolled;
4537 GtkWidget *status_box;
4538 GtkWidget *controls_box;
4539 GtkWidget *button_box;
4542 GtkListStore *store;
4543 GtkTreeSelection *selection;
4544 GdkGeometry geometry;
4545 LayoutWindow *lw = NULL;
4549 dw = g_new0(DupeWindow, 1);
4550 dw->add_files_queue = NULL;
4551 dw->add_files_queue_id = 0;
4553 dw->match_mask = DUPE_MATCH_NAME;
4554 if (options->duplicates_match == DUPE_MATCH_NAME) dw->match_mask = DUPE_MATCH_NAME;
4555 if (options->duplicates_match == DUPE_MATCH_SIZE) dw->match_mask = DUPE_MATCH_SIZE;
4556 if (options->duplicates_match == DUPE_MATCH_DATE) dw->match_mask = DUPE_MATCH_DATE;
4557 if (options->duplicates_match == DUPE_MATCH_DIM) dw->match_mask = DUPE_MATCH_DIM;
4558 if (options->duplicates_match == DUPE_MATCH_SUM) dw->match_mask = DUPE_MATCH_SUM;
4559 if (options->duplicates_match == DUPE_MATCH_PATH) dw->match_mask = DUPE_MATCH_PATH;
4560 if (options->duplicates_match == DUPE_MATCH_SIM_HIGH) dw->match_mask = DUPE_MATCH_SIM_HIGH;
4561 if (options->duplicates_match == DUPE_MATCH_SIM_MED) dw->match_mask = DUPE_MATCH_SIM_MED;
4562 if (options->duplicates_match == DUPE_MATCH_SIM_LOW) dw->match_mask = DUPE_MATCH_SIM_LOW;
4563 if (options->duplicates_match == DUPE_MATCH_SIM_CUSTOM) dw->match_mask = DUPE_MATCH_SIM_CUSTOM;
4564 if (options->duplicates_match == DUPE_MATCH_NAME_CI) dw->match_mask = DUPE_MATCH_NAME_CI;
4565 if (options->duplicates_match == DUPE_MATCH_NAME_CONTENT) dw->match_mask = DUPE_MATCH_NAME_CONTENT;
4566 if (options->duplicates_match == DUPE_MATCH_NAME_CI_CONTENT) dw->match_mask = DUPE_MATCH_NAME_CI_CONTENT;
4567 if (options->duplicates_match == DUPE_MATCH_ALL) dw->match_mask = DUPE_MATCH_ALL;
4569 dw->window = window_new(GTK_WINDOW_TOPLEVEL, "dupe", NULL, NULL, _("Find duplicates"));
4570 DEBUG_NAME(dw->window);
4572 geometry.min_width = DEFAULT_MINIMAL_WINDOW_SIZE;
4573 geometry.min_height = DEFAULT_MINIMAL_WINDOW_SIZE;
4574 geometry.base_width = DUPE_DEF_WIDTH;
4575 geometry.base_height = DUPE_DEF_HEIGHT;
4576 gtk_window_set_geometry_hints(GTK_WINDOW(dw->window), NULL, &geometry,
4577 GDK_HINT_MIN_SIZE | GDK_HINT_BASE_SIZE);
4579 if (lw && options->save_window_positions)
4581 gtk_window_set_default_size(GTK_WINDOW(dw->window), lw->options.dupe_window.w, lw->options.dupe_window.h);
4582 gtk_window_move(GTK_WINDOW(dw->window), lw->options.dupe_window.x, lw->options.dupe_window.y);
4586 gtk_window_set_default_size(GTK_WINDOW(dw->window), DUPE_DEF_WIDTH, DUPE_DEF_HEIGHT);
4589 gtk_window_set_resizable(GTK_WINDOW(dw->window), TRUE);
4590 gtk_container_set_border_width(GTK_CONTAINER(dw->window), 0);
4592 g_signal_connect(G_OBJECT(dw->window), "delete_event",
4593 G_CALLBACK(dupe_window_delete), dw);
4594 g_signal_connect(G_OBJECT(dw->window), "key_press_event",
4595 G_CALLBACK(dupe_window_keypress_cb), dw);
4597 vbox = gtk_vbox_new(FALSE, 0);
4598 gtk_container_add(GTK_CONTAINER(dw->window), vbox);
4599 gtk_widget_show(vbox);
4601 dw->table = gtk_table_new(1, 3, FALSE);
4602 gtk_box_pack_start(GTK_BOX(vbox), dw->table, TRUE, TRUE, 0);
4603 gtk_widget_show(dw->table);
4605 scrolled = gtk_scrolled_window_new(NULL, NULL);
4606 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN);
4607 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
4608 gtk_table_attach_defaults(GTK_TABLE(dw->table), scrolled, 0, 2, 0, 1);
4609 gtk_widget_show(scrolled);
4611 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);
4612 dw->listview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
4613 g_object_unref(store);
4615 dw->sortable = GTK_TREE_SORTABLE(store);
4617 gtk_tree_sortable_set_sort_func(dw->sortable, DUPE_COLUMN_RANK, column_sort_cb, dw->sortable, NULL);
4618 gtk_tree_sortable_set_sort_func(dw->sortable, DUPE_COLUMN_SET, default_sort_cb, dw->sortable, NULL);
4619 gtk_tree_sortable_set_sort_func(dw->sortable, DUPE_COLUMN_THUMB, default_sort_cb, dw->sortable, NULL);
4620 gtk_tree_sortable_set_sort_func(dw->sortable, DUPE_COLUMN_NAME, column_sort_cb, dw->sortable, NULL);
4621 gtk_tree_sortable_set_sort_func(dw->sortable, DUPE_COLUMN_SIZE, column_sort_cb, dw->sortable, NULL);
4622 gtk_tree_sortable_set_sort_func(dw->sortable, DUPE_COLUMN_DATE, column_sort_cb, dw->sortable, NULL);
4623 gtk_tree_sortable_set_sort_func(dw->sortable, DUPE_COLUMN_DIMENSIONS, column_sort_cb, dw->sortable, NULL);
4624 gtk_tree_sortable_set_sort_func(dw->sortable, DUPE_COLUMN_PATH, column_sort_cb, dw->sortable, NULL);
4626 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dw->listview));
4627 gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_MULTIPLE);
4628 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(dw->listview), TRUE);
4629 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(dw->listview), FALSE);
4631 dupe_listview_add_column(dw, dw->listview, DUPE_COLUMN_RANK, _("Rank"), FALSE, TRUE);
4632 dupe_listview_add_column(dw, dw->listview, DUPE_COLUMN_THUMB, _("Thumb"), TRUE, FALSE);
4633 dupe_listview_add_column(dw, dw->listview, DUPE_COLUMN_NAME, _("Name"), FALSE, FALSE);
4634 dupe_listview_add_column(dw, dw->listview, DUPE_COLUMN_SIZE, _("Size"), FALSE, TRUE);
4635 dupe_listview_add_column(dw, dw->listview, DUPE_COLUMN_DATE, _("Date"), FALSE, TRUE);
4636 dupe_listview_add_column(dw, dw->listview, DUPE_COLUMN_DIMENSIONS, _("Dimensions"), FALSE, FALSE);
4637 dupe_listview_add_column(dw, dw->listview, DUPE_COLUMN_PATH, _("Path"), FALSE, FALSE);
4638 dupe_listview_add_column(dw, dw->listview, DUPE_COLUMN_SET, _("Set"), FALSE, FALSE);
4640 g_signal_connect(gtk_tree_view_get_column(GTK_TREE_VIEW(dw->listview), DUPE_COLUMN_RANK - 1), "clicked", (GCallback)column_clicked_cb, dw);
4641 g_signal_connect(gtk_tree_view_get_column(GTK_TREE_VIEW(dw->listview), DUPE_COLUMN_NAME - 1), "clicked", (GCallback)column_clicked_cb, dw);
4642 g_signal_connect(gtk_tree_view_get_column(GTK_TREE_VIEW(dw->listview), DUPE_COLUMN_SIZE - 1), "clicked", (GCallback)column_clicked_cb, dw);
4643 g_signal_connect(gtk_tree_view_get_column(GTK_TREE_VIEW(dw->listview), DUPE_COLUMN_DATE - 1), "clicked", (GCallback)column_clicked_cb, dw);
4644 g_signal_connect(gtk_tree_view_get_column(GTK_TREE_VIEW(dw->listview), DUPE_COLUMN_DIMENSIONS - 1), "clicked", (GCallback)column_clicked_cb, dw);
4645 g_signal_connect(gtk_tree_view_get_column(GTK_TREE_VIEW(dw->listview), DUPE_COLUMN_PATH - 1), "clicked", (GCallback)column_clicked_cb, dw);
4647 gtk_container_add(GTK_CONTAINER(scrolled), dw->listview);
4648 gtk_widget_show(dw->listview);
4650 dw->second_vbox = gtk_vbox_new(FALSE, 0);
4651 gtk_table_attach_defaults(GTK_TABLE(dw->table), dw->second_vbox, 2, 3, 0, 1);
4654 gtk_table_set_col_spacings(GTK_TABLE(dw->table), PREF_PAD_GAP);
4655 gtk_widget_show(dw->second_vbox);
4659 gtk_table_set_col_spacings(GTK_TABLE(dw->table), 0);
4662 scrolled = gtk_scrolled_window_new(NULL, NULL);
4663 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN);
4664 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
4665 gtk_box_pack_start(GTK_BOX(dw->second_vbox), scrolled, TRUE, TRUE, 0);
4666 gtk_widget_show(scrolled);
4668 store = gtk_list_store_new(2, G_TYPE_POINTER, G_TYPE_STRING);
4669 dw->second_listview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
4671 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dw->second_listview));
4672 gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_MULTIPLE);
4674 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(dw->second_listview), TRUE);
4675 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(dw->second_listview), FALSE);
4677 dupe_listview_add_column(dw, dw->second_listview, 1, _("Compare to:"), FALSE, FALSE);
4679 gtk_container_add(GTK_CONTAINER(scrolled), dw->second_listview);
4680 gtk_widget_show(dw->second_listview);
4682 dw->second_status_label = gtk_label_new("");
4683 gtk_box_pack_start(GTK_BOX(dw->second_vbox), dw->second_status_label, FALSE, FALSE, 0);
4684 gtk_widget_show(dw->second_status_label);
4686 pref_line(dw->second_vbox, GTK_ORIENTATION_HORIZONTAL);
4688 status_box = gtk_hbox_new(FALSE, 0);
4689 gtk_box_pack_start(GTK_BOX(vbox), status_box, FALSE, FALSE, 0);
4690 gtk_widget_show(status_box);
4692 frame = gtk_frame_new(NULL);
4694 gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN);
4695 gtk_box_pack_start(GTK_BOX(status_box), frame, TRUE, TRUE, 0);
4696 gtk_widget_show(frame);
4698 dw->status_label = gtk_label_new("");
4699 gtk_container_add(GTK_CONTAINER(frame), dw->status_label);
4700 gtk_widget_show(dw->status_label);
4702 dw->extra_label = gtk_progress_bar_new();
4703 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(dw->extra_label), 0.0);
4704 #if GTK_CHECK_VERSION(3,0,0)
4705 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(dw->extra_label), "");
4706 gtk_progress_bar_set_show_text(GTK_PROGRESS_BAR(dw->extra_label), TRUE);
4708 gtk_box_pack_start(GTK_BOX(status_box), dw->extra_label, FALSE, FALSE, PREF_PAD_SPACE);
4709 gtk_widget_show(dw->extra_label);
4711 controls_box = pref_box_new(vbox, FALSE, GTK_ORIENTATION_HORIZONTAL, 0);
4712 dw->controls_box = controls_box;
4714 dw->button_thumbs = gtk_check_button_new_with_label(_("Thumbnails"));
4715 dw->show_thumbs = options->duplicates_thumbnails;
4716 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dw->button_thumbs), dw->show_thumbs);
4717 g_signal_connect(G_OBJECT(dw->button_thumbs), "toggled",
4718 G_CALLBACK(dupe_window_show_thumb_cb), dw);
4719 gtk_box_pack_start(GTK_BOX(controls_box), dw->button_thumbs, FALSE, FALSE, PREF_PAD_SPACE);
4720 gtk_widget_show(dw->button_thumbs);
4722 label = gtk_label_new(_("Compare by:"));
4723 gtk_box_pack_start(GTK_BOX(controls_box), label, FALSE, FALSE, PREF_PAD_SPACE);
4724 gtk_widget_show(label);
4726 dupe_menu_setup(dw);
4727 gtk_box_pack_start(GTK_BOX(controls_box), dw->combo, FALSE, FALSE, 0);
4728 gtk_widget_show(dw->combo);
4730 label = gtk_label_new(_("Custom Threshold"));
4731 gtk_box_pack_start(GTK_BOX(controls_box), label, FALSE, FALSE, PREF_PAD_SPACE);
4732 gtk_widget_show(label);
4733 dw->custom_threshold = gtk_spin_button_new_with_range(1, 100, 1);
4734 gtk_widget_set_tooltip_text(GTK_WIDGET(dw->custom_threshold), "Custom similarity threshold\n(Use tab key to set value)");
4735 gtk_spin_button_set_value(GTK_SPIN_BUTTON(dw->custom_threshold), options->duplicates_similarity_threshold);
4736 g_signal_connect(G_OBJECT(dw->custom_threshold), "value_changed", G_CALLBACK(dupe_window_custom_threshold_cb), dw);
4737 gtk_box_pack_start(GTK_BOX(controls_box), dw->custom_threshold, FALSE, FALSE, PREF_PAD_SPACE);
4738 gtk_widget_show(dw->custom_threshold);
4740 button = gtk_check_button_new_with_label(_("Sort"));
4741 gtk_widget_set_tooltip_text(GTK_WIDGET(button), "Sort by group totals");
4742 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), options->sort_totals);
4743 g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(dupe_sort_totals_toggle_cb), dw);
4744 gtk_box_pack_start(GTK_BOX(controls_box), button, FALSE, FALSE, PREF_PAD_SPACE);
4745 gtk_widget_show(button);
4747 dw->button_rotation_invariant = gtk_check_button_new_with_label(_("Ignore Orientation"));
4748 gtk_widget_set_tooltip_text(GTK_WIDGET(dw->button_rotation_invariant), "Ignore image orientation");
4749 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dw->button_rotation_invariant), options->rot_invariant_sim);
4750 g_signal_connect(G_OBJECT(dw->button_rotation_invariant), "toggled",
4751 G_CALLBACK(dupe_window_rotation_invariant_cb), dw);
4752 gtk_box_pack_start(GTK_BOX(controls_box), dw->button_rotation_invariant, FALSE, FALSE, PREF_PAD_SPACE);
4753 gtk_widget_show(dw->button_rotation_invariant);
4755 button = gtk_check_button_new_with_label(_("Compare two file sets"));
4756 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), dw->second_set);
4757 g_signal_connect(G_OBJECT(button), "toggled",
4758 G_CALLBACK(dupe_second_set_toggle_cb), dw);
4759 gtk_box_pack_start(GTK_BOX(controls_box), button, FALSE, FALSE, PREF_PAD_SPACE);
4760 gtk_widget_show(button);
4762 button_box = gtk_hbox_new(FALSE, 0);
4763 gtk_box_pack_start(GTK_BOX(vbox), button_box, FALSE, FALSE, 0);
4764 gtk_widget_show(button_box);
4766 hbox = gtk_hbutton_box_new();
4767 gtk_button_box_set_layout(GTK_BUTTON_BOX(hbox), GTK_BUTTONBOX_END);
4768 gtk_box_set_spacing(GTK_BOX(hbox), PREF_PAD_SPACE);
4769 gtk_box_pack_end(GTK_BOX(button_box), hbox, FALSE, FALSE, 0);
4770 gtk_widget_show(hbox);
4772 button = pref_button_new(NULL, GTK_STOCK_HELP, NULL, FALSE, G_CALLBACK(dupe_help_cb), NULL);
4773 gtk_container_add(GTK_CONTAINER(hbox), button);
4774 gtk_widget_set_can_default(button, TRUE);
4775 gtk_widget_show(button);
4777 button = pref_button_new(NULL, GTK_STOCK_STOP, NULL, FALSE, G_CALLBACK(dupe_check_stop_cb), dw);
4778 gtk_container_add(GTK_CONTAINER(hbox), button);
4779 gtk_widget_set_can_default(button, TRUE);
4780 gtk_widget_show(button);
4782 button = pref_button_new(NULL, GTK_STOCK_CLOSE, NULL, FALSE, G_CALLBACK(dupe_window_close_cb), dw);
4783 gtk_container_add(GTK_CONTAINER(hbox), button);
4784 gtk_widget_set_can_default(button, TRUE);
4785 gtk_widget_grab_default(button);
4786 gtk_widget_show(button);
4789 /* order is important here, dnd_init should be seeing mouse
4790 * presses before we possibly handle (and stop) the signal
4792 g_signal_connect(G_OBJECT(dw->listview), "button_press_event",
4793 G_CALLBACK(dupe_listview_press_cb), dw);
4794 g_signal_connect(G_OBJECT(dw->listview), "button_release_event",
4795 G_CALLBACK(dupe_listview_release_cb), dw);
4796 g_signal_connect(G_OBJECT(dw->second_listview), "button_press_event",
4797 G_CALLBACK(dupe_listview_press_cb), dw);
4798 g_signal_connect(G_OBJECT(dw->second_listview), "button_release_event",
4799 G_CALLBACK(dupe_listview_release_cb), dw);
4801 gtk_widget_show(dw->window);
4803 dupe_listview_set_height(dw->listview, dw->show_thumbs);
4804 g_signal_emit_by_name(G_OBJECT(dw->combo), "changed");
4806 dupe_window_update_count(dw, TRUE);
4807 dupe_window_update_progress(dw, NULL, 0.0, FALSE);
4809 dupe_window_list = g_list_append(dupe_window_list, dw);
4811 file_data_register_notify_func(dupe_notify_cb, dw, NOTIFY_PRIORITY_MEDIUM);
4813 g_mutex_init(&dw->thread_count_mutex);
4814 g_mutex_init(&dw->search_matches_mutex);
4815 dw->dupe_comparison_thread_pool = g_thread_pool_new(dupe_comparison_func, dw, -1, FALSE, NULL);
4821 *-------------------------------------------------------------------
4823 *-------------------------------------------------------------------
4831 static void confirm_dir_list_cancel(GtkWidget *widget, gpointer data)
4836 static void confirm_dir_list_add(GtkWidget *widget, gpointer data)
4838 CDupeConfirmD *d = data;
4841 dupe_window_add_files(d->dw, d->list, FALSE);
4846 FileData *fd = work->data;
4848 if (isdir(fd->path))
4852 filelist_read(fd, &list, NULL);
4853 list = filelist_filter(list, FALSE);
4856 dupe_window_add_files(d->dw, list, FALSE);
4857 filelist_free(list);
4863 static void confirm_dir_list_recurse(GtkWidget *widget, gpointer data)
4865 CDupeConfirmD *d = data;
4866 dupe_window_add_files(d->dw, d->list, TRUE);
4869 static void confirm_dir_list_skip(GtkWidget *widget, gpointer data)
4871 CDupeConfirmD *d = data;
4872 dupe_window_add_files(d->dw, d->list, FALSE);
4875 static void confirm_dir_list_destroy(GtkWidget *widget, gpointer data)
4877 CDupeConfirmD *d = data;
4878 filelist_free(d->list);
4882 static GtkWidget *dupe_confirm_dir_list(DupeWindow *dw, GList *list)
4887 d = g_new0(CDupeConfirmD, 1);
4891 menu = popup_menu_short_lived();
4892 g_signal_connect(G_OBJECT(menu), "destroy",
4893 G_CALLBACK(confirm_dir_list_destroy), d);
4895 menu_item_add_stock(menu, _("Dropped list includes folders."), GTK_STOCK_DND_MULTIPLE, NULL, NULL);
4896 menu_item_add_divider(menu);
4897 menu_item_add_stock(menu, _("_Add contents"), GTK_STOCK_OK, G_CALLBACK(confirm_dir_list_add), d);
4898 menu_item_add_stock(menu, _("Add contents _recursive"), GTK_STOCK_ADD, G_CALLBACK(confirm_dir_list_recurse), d);
4899 menu_item_add_stock(menu, _("_Skip folders"), GTK_STOCK_REMOVE, G_CALLBACK(confirm_dir_list_skip), d);
4900 menu_item_add_divider(menu);
4901 menu_item_add_stock(menu, _("Cancel"), GTK_STOCK_CANCEL, G_CALLBACK(confirm_dir_list_cancel), d);
4907 *-------------------------------------------------------------------
4909 *-------------------------------------------------------------------
4912 static GtkTargetEntry dupe_drag_types[] = {
4913 { "text/uri-list", 0, TARGET_URI_LIST },
4914 { "text/plain", 0, TARGET_TEXT_PLAIN }
4916 static gint n_dupe_drag_types = 2;
4918 static GtkTargetEntry dupe_drop_types[] = {
4919 { TARGET_APP_COLLECTION_MEMBER_STRING, 0, TARGET_APP_COLLECTION_MEMBER },
4920 { "text/uri-list", 0, TARGET_URI_LIST }
4922 static gint n_dupe_drop_types = 2;
4924 static void dupe_dnd_data_set(GtkWidget *widget, GdkDragContext *context,
4925 GtkSelectionData *selection_data, guint info,
4926 guint time, gpointer data)
4928 DupeWindow *dw = data;
4933 case TARGET_URI_LIST:
4934 case TARGET_TEXT_PLAIN:
4935 list = dupe_listview_get_selection(dw, widget);
4937 uri_selection_data_set_uris_from_filelist(selection_data, list);
4938 filelist_free(list);
4945 static void dupe_dnd_data_get(GtkWidget *widget, GdkDragContext *context,
4947 GtkSelectionData *selection_data, guint info,
4948 guint time, gpointer data)
4950 DupeWindow *dw = data;
4955 if (dw->add_files_queue_id > 0)
4957 warning_dialog(_("Find duplicates"), _("Please wait for the current file selection to be loaded."), GTK_STOCK_DIALOG_INFO, dw->window);
4962 source = gtk_drag_get_source_widget(context);
4963 if (source == dw->listview || source == dw->second_listview) return;
4965 dw->second_drop = (dw->second_set && widget == dw->second_listview);
4969 case TARGET_APP_COLLECTION_MEMBER:
4970 collection_from_dnd_data((gchar *)gtk_selection_data_get_data(selection_data), &list, NULL);
4972 case TARGET_URI_LIST:
4973 list = uri_filelist_from_gtk_selection_data(selection_data);
4977 FileData *fd = work->data;
4978 if (isdir(fd->path))
4981 menu = dupe_confirm_dir_list(dw, list);
4982 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 0, time);
4995 dupe_window_add_files(dw, list, FALSE);
4996 filelist_free(list);
5000 static void dupe_dest_set(GtkWidget *widget, gboolean enable)
5004 gtk_drag_dest_set(widget,
5005 GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_HIGHLIGHT | GTK_DEST_DEFAULT_DROP,
5006 dupe_drop_types, n_dupe_drop_types,
5007 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_ASK);
5012 gtk_drag_dest_unset(widget);
5016 static void dupe_dnd_begin(GtkWidget *widget, GdkDragContext *context, gpointer data)
5018 DupeWindow *dw = data;
5019 dupe_dest_set(dw->listview, FALSE);
5020 dupe_dest_set(dw->second_listview, FALSE);
5022 if (dw->click_item && !dupe_listview_item_is_selected(dw, dw->click_item, widget))
5024 GtkListStore *store;
5027 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(widget)));
5028 if (dupe_listview_find_item(store, dw->click_item, &iter) >= 0)
5030 GtkTreeSelection *selection;
5033 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
5034 gtk_tree_selection_unselect_all(selection);
5035 gtk_tree_selection_select_iter(selection, &iter);
5037 tpath = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter);
5038 gtk_tree_view_set_cursor(GTK_TREE_VIEW(widget), tpath, NULL, FALSE);
5039 gtk_tree_path_free(tpath);
5043 if (dw->show_thumbs &&
5044 widget == dw->listview &&
5045 dw->click_item && dw->click_item->pixbuf)
5047 GtkTreeSelection *selection;
5050 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget));
5051 items = gtk_tree_selection_count_selected_rows(selection);
5052 dnd_set_drag_icon(widget, context, dw->click_item->pixbuf, items);
5056 static void dupe_dnd_end(GtkWidget *widget, GdkDragContext *context, gpointer data)
5058 DupeWindow *dw = data;
5059 dupe_dest_set(dw->listview, TRUE);
5060 dupe_dest_set(dw->second_listview, TRUE);
5063 static void dupe_dnd_init(DupeWindow *dw)
5065 gtk_drag_source_set(dw->listview, GDK_BUTTON1_MASK | GDK_BUTTON2_MASK,
5066 dupe_drag_types, n_dupe_drag_types,
5067 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK);
5068 g_signal_connect(G_OBJECT(dw->listview), "drag_data_get",
5069 G_CALLBACK(dupe_dnd_data_set), dw);
5070 g_signal_connect(G_OBJECT(dw->listview), "drag_begin",
5071 G_CALLBACK(dupe_dnd_begin), dw);
5072 g_signal_connect(G_OBJECT(dw->listview), "drag_end",
5073 G_CALLBACK(dupe_dnd_end), dw);
5075 dupe_dest_set(dw->listview, TRUE);
5076 g_signal_connect(G_OBJECT(dw->listview), "drag_data_received",
5077 G_CALLBACK(dupe_dnd_data_get), dw);
5079 gtk_drag_source_set(dw->second_listview, GDK_BUTTON1_MASK | GDK_BUTTON2_MASK,
5080 dupe_drag_types, n_dupe_drag_types,
5081 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK);
5082 g_signal_connect(G_OBJECT(dw->second_listview), "drag_data_get",
5083 G_CALLBACK(dupe_dnd_data_set), dw);
5084 g_signal_connect(G_OBJECT(dw->second_listview), "drag_begin",
5085 G_CALLBACK(dupe_dnd_begin), dw);
5086 g_signal_connect(G_OBJECT(dw->second_listview), "drag_end",
5087 G_CALLBACK(dupe_dnd_end), dw);
5089 dupe_dest_set(dw->second_listview, TRUE);
5090 g_signal_connect(G_OBJECT(dw->second_listview), "drag_data_received",
5091 G_CALLBACK(dupe_dnd_data_get), dw);
5095 *-------------------------------------------------------------------
5096 * maintenance (move, delete, etc.)
5097 *-------------------------------------------------------------------
5100 static void dupe_notify_cb(FileData *fd, NotifyType type, gpointer data)
5102 DupeWindow *dw = data;
5104 if (!(type & NOTIFY_CHANGE) || !fd->change) return;
5106 DEBUG_1("Notify dupe: %s %04x", fd->path, type);
5108 switch (fd->change->type)
5110 case FILEDATA_CHANGE_MOVE:
5111 case FILEDATA_CHANGE_RENAME:
5112 dupe_item_update_fd(dw, fd);
5114 case FILEDATA_CHANGE_COPY:
5116 case FILEDATA_CHANGE_DELETE:
5117 /* Update the UI only once, after the operation finishes */
5119 case FILEDATA_CHANGE_UNSPECIFIED:
5120 case FILEDATA_CHANGE_WRITE_METADATA:
5127 * @brief Refresh window after a file delete operation
5128 * @param success (ud->phase != UTILITY_PHASE_CANCEL) #file_util_dialog_run
5129 * @param dest_path Not used
5130 * @param data #DupeWindow
5132 * If the window is refreshed after each file of a large set is deleted,
5133 * the UI slows to an unacceptable level. The #FileUtilDoneFunc is used
5134 * to call this function once, when the entire delete operation is completed.
5136 static void delete_finished_cb(gboolean success, const gchar *dest_path, gpointer data)
5138 DupeWindow *dw = data;
5146 dupe_window_remove_selection(dw, dw->listview);
5150 *-------------------------------------------------------------------
5151 * Export duplicates data
5152 *-------------------------------------------------------------------
5160 typedef struct _ExportDupesData ExportDupesData;
5161 struct _ExportDupesData
5164 SeparatorType separator;
5165 DupeWindow *dupewindow;
5168 static void export_duplicates_close(ExportDupesData *edd)
5170 if (edd->dialog) file_dialog_close(edd->dialog);
5174 static void export_duplicates_data_cancel_cb(FileDialog *fdlg, gpointer data)
5176 ExportDupesData *edd = data;
5178 export_duplicates_close(edd);
5181 static void export_duplicates_data_save_cb(FileDialog *fdlg, gpointer data)
5183 ExportDupesData *edd = data;
5184 GError *error = NULL;
5185 GtkTreeModel *store;
5188 GFileOutputStream *gfstream;
5190 GString *output_string;
5194 GtkTreeSelection *selection;
5199 gboolean color_old = FALSE;
5200 gboolean color_new = FALSE;
5204 history_list_add_to_key("export_duplicates", fdlg->dest_path, -1);
5206 out_file = g_file_new_for_path(fdlg->dest_path);
5208 gfstream = g_file_replace(out_file, NULL, TRUE, G_FILE_CREATE_NONE, NULL, &error);
5211 log_printf(_("Error creating Export duplicates data file: Error: %s\n"), error->message);
5212 g_error_free(error);
5216 sep = g_strdup((edd->separator == EXPORT_CSV) ? "," : "\t");
5217 output_string = g_string_new(g_strjoin(sep, _("Match"), _("Group"), _("Similarity"), _("Set"), _("Thumbnail"), _("Name"), _("Size"), _("Date"), _("Width"), _("Height"), _("Path\n"), NULL));
5219 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(edd->dupewindow->listview));
5220 slist = gtk_tree_selection_get_selected_rows(selection, &store);
5224 gtk_tree_model_get_iter(store, &iter, tpath);
5225 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, DUPE_COLUMN_COLOR, &color_new, -1);
5226 color_old = !color_new;
5232 gtk_tree_model_get_iter(store, &iter, tpath);
5234 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, DUPE_COLUMN_POINTER, &di, -1);
5236 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, DUPE_COLUMN_COLOR, &color_new, -1);
5237 if (color_new != color_old)
5241 color_old = color_new;
5242 output_string = g_string_append(output_string, g_strdup_printf("%d", match_count));
5243 output_string = g_string_append(output_string, sep);
5245 if ((dupe_match_find_parent(edd->dupewindow, di) == di))
5247 output_string = g_string_append(output_string, "1");
5251 output_string = g_string_append(output_string, "2");
5253 output_string = g_string_append(output_string, sep);
5255 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, DUPE_COLUMN_RANK, &rank, -1);
5256 rank_split = g_strsplit_set(rank, " [(", -1);
5257 if (rank_split[0] == NULL)
5259 output_string = g_string_append(output_string, "");
5263 output_string = g_string_append(output_string, g_strdup_printf("%s", rank_split[0]));
5265 output_string = g_string_append(output_string, sep);
5267 g_strfreev(rank_split);
5269 output_string = g_string_append(output_string, g_strdup_printf("%d", (di->second + 1)));
5270 output_string = g_string_append(output_string, sep);
5272 thumb_cache = cache_find_location(CACHE_TYPE_THUMB, di->fd->path);
5275 output_string = g_string_append(output_string, thumb_cache);
5276 g_free(thumb_cache);
5280 output_string = g_string_append(output_string, "");
5282 output_string = g_string_append(output_string, sep);
5284 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, DUPE_COLUMN_NAME, &name, -1);
5285 output_string = g_string_append(output_string, name);
5286 output_string = g_string_append(output_string, sep);
5289 output_string = g_string_append(output_string, g_strdup_printf("%"PRIu64, di->fd->size));
5290 output_string = g_string_append(output_string, sep);
5291 output_string = g_string_append(output_string, text_from_time(di->fd->date));
5292 output_string = g_string_append(output_string, sep);
5293 output_string = g_string_append(output_string, g_strdup_printf("%d", (di->width ? di->width : 0)));
5294 output_string = g_string_append(output_string, sep);
5295 output_string = g_string_append(output_string, g_strdup_printf("%d", (di->height ? di->height : 0)));
5296 output_string = g_string_append(output_string, sep);
5297 output_string = g_string_append(output_string, di->fd->path);
5298 output_string = g_string_append_c(output_string, '\n');
5303 g_output_stream_write(G_OUTPUT_STREAM(gfstream), output_string->str, strlen(output_string->str), NULL, &error);
5306 g_string_free(output_string, TRUE);
5307 g_object_unref(gfstream);
5308 g_object_unref(out_file);
5310 export_duplicates_close(edd);
5313 static void pop_menu_export(GList *selection_list, gpointer dupe_window, gpointer data)
5315 const gint index = GPOINTER_TO_INT(data);
5316 DupeWindow *dw = dupe_window;
5317 gchar *title = "Export duplicates data";
5318 gchar *default_path = "/tmp/";
5319 gchar *file_extension;
5320 const gchar *stock_id;
5321 ExportDupesData *edd;
5322 const gchar *previous_path;
5324 edd = g_new0(ExportDupesData, 1);
5325 edd->dialog = file_util_file_dlg(title, "export_duplicates", NULL, export_duplicates_data_cancel_cb, edd);
5330 edd->separator = EXPORT_CSV;
5331 file_extension = g_strdup(".csv");
5334 edd->separator = EXPORT_TSV;
5335 file_extension = g_strdup(".tsv");
5341 stock_id = GTK_STOCK_SAVE;
5343 generic_dialog_add_message(GENERIC_DIALOG(edd->dialog), NULL, title, NULL, FALSE);
5344 file_dialog_add_button(edd->dialog, stock_id, NULL, export_duplicates_data_save_cb, TRUE);
5346 previous_path = history_list_find_last_path_by_key("export_duplicates");
5348 file_dialog_add_path_widgets(edd->dialog, default_path, previous_path, "export_duplicates", file_extension, _("Export Files"));
5350 edd->dupewindow = dw;
5352 gtk_widget_show(GENERIC_DIALOG(edd->dialog)->dialog);
5354 g_free(file_extension);
5357 static void dupe_pop_menu_export_cb(GtkWidget *widget, gpointer data)
5360 GList *selection_list;
5362 dw = submenu_item_get_data(widget);
5363 selection_list = dupe_listview_get_selection(dw, dw->listview);
5364 pop_menu_export(selection_list, dw, data);
5366 filelist_free(selection_list);
5369 static GtkWidget *submenu_add_export(GtkWidget *menu, GtkWidget **menu_item, GCallback func, gpointer data)
5374 item = menu_item_add(menu, _("Export"), NULL, NULL);
5376 submenu = gtk_menu_new();
5377 g_object_set_data(G_OBJECT(submenu), "submenu_data", data);
5379 menu_item_add_stock_sensitive(submenu, _("Export to csv"),
5380 GTK_STOCK_INDEX, TRUE, G_CALLBACK(func), GINT_TO_POINTER(0));
5381 menu_item_add_stock_sensitive(submenu, _("Export to tab-delimited"),
5382 GTK_STOCK_INDEX, TRUE, G_CALLBACK(func), GINT_TO_POINTER(1));
5384 gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), submenu);
5385 if (menu_item) *menu_item = item;
5390 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */