Mercurial > geeqie
annotate src/dupe.c @ 68:c6ff22c968b2
Fri Oct 13 09:25:25 2006 John Ellis <johne@verizon.net>
* pl.po: Update Polish translation,
submitted by Wit Wilinski <madman@linux.bydg.org>.
* README: Updates.
author | gqview |
---|---|
date | Fri, 13 Oct 2006 13:44:30 +0000 |
parents | 04ff0df3ad2f |
children | 9d5c75b5ec28 |
rev | line source |
---|---|
9 | 1 /* |
2 * GQview | |
3 * (C) 2005 John Ellis | |
4 * | |
5 * Author: John Ellis | |
6 * | |
7 * This software is released under the GNU General Public License (GNU GPL). | |
8 * Please read the included file COPYING for more information. | |
9 * This software comes with no warranty of any kind, use at your own risk! | |
10 */ | |
11 | |
12 | |
13 #include "gqview.h" | |
14 #include "dupe.h" | |
15 | |
16 #include "cache.h" | |
17 #include "collect.h" | |
18 #include "collect-table.h" | |
19 #include "dnd.h" | |
20 #include "editors.h" | |
21 #include "filelist.h" | |
22 #include "image-load.h" | |
23 #include "img-view.h" | |
24 #include "info.h" | |
25 #include "layout.h" | |
26 #include "layout_image.h" | |
27 #include "md5-util.h" | |
28 #include "menu.h" | |
29 #include "print.h" | |
30 #include "thumb.h" | |
31 #include "utilops.h" | |
32 #include "ui_bookmark.h" | |
33 #include "ui_fileops.h" | |
34 #include "ui_menu.h" | |
35 #include "ui_misc.h" | |
36 #include "ui_tree_edit.h" | |
37 | |
38 #include <gdk/gdkkeysyms.h> /* for keyboard values */ | |
39 | |
40 | |
41 #include <math.h> | |
42 | |
43 | |
44 #define DUPE_DEF_WIDTH 600 | |
45 #define DUPE_DEF_HEIGHT 400 | |
46 | |
47 /* column assignment order (simply change them here) */ | |
48 enum { | |
49 DUPE_COLUMN_POINTER = 0, | |
50 DUPE_COLUMN_RANK, | |
51 DUPE_COLUMN_THUMB, | |
52 DUPE_COLUMN_NAME, | |
53 DUPE_COLUMN_SIZE, | |
54 DUPE_COLUMN_DATE, | |
55 DUPE_COLUMN_DIMENSIONS, | |
56 DUPE_COLUMN_PATH, | |
57 DUPE_COLUMN_COLOR, | |
58 DUPE_COLUMN_COUNT /* total columns */ | |
59 }; | |
60 | |
61 | |
62 static GList *dupe_window_list = NULL; /* list of open DupeWindow *s */ | |
63 | |
64 /* | |
65 * Well, after adding the 'compare two sets' option things got a little sloppy in here | |
66 * because we have to account for two 'modes' everywhere. (be careful). | |
67 */ | |
68 | |
69 static void dupe_match_unlink(DupeItem *a, DupeItem *b); | |
70 static DupeItem *dupe_match_find_parent(DupeWindow *dw, DupeItem *child); | |
71 | |
72 static gint dupe_match(DupeItem *a, DupeItem *b, DupeMatchType mask, gdouble *rank, gint fast); | |
73 | |
74 static void dupe_thumb_step(DupeWindow *dw); | |
75 static gint dupe_check_cb(gpointer data); | |
76 | |
77 static void dupe_second_add(DupeWindow *dw, DupeItem *di); | |
78 static void dupe_second_remove(DupeWindow *dw, DupeItem *di); | |
79 static GtkWidget *dupe_menu_popup_second(DupeWindow *dw, DupeItem *di); | |
80 | |
81 static void dupe_dnd_init(DupeWindow *dw); | |
82 | |
83 /* | |
84 * ------------------------------------------------------------------ | |
85 * Window updates | |
86 * ------------------------------------------------------------------ | |
87 */ | |
88 | |
89 | |
90 static void dupe_window_update_count(DupeWindow *dw, gint count_only) | |
91 { | |
92 gchar *text; | |
93 | |
94 if (!dw->list) | |
95 { | |
96 text = g_strdup(_("Drop files to compare them.")); | |
97 } | |
98 else if (count_only) | |
99 { | |
100 text = g_strdup_printf(_("%d files"), g_list_length(dw->list)); | |
101 } | |
102 else | |
103 { | |
104 text = g_strdup_printf(_("%d matches found in %d files"), g_list_length(dw->dupes), g_list_length(dw->list)); | |
105 } | |
106 | |
107 if (dw->second_set) | |
108 { | |
109 gchar *buf = g_strconcat(text, " ", _("[set 1]"), NULL); | |
110 g_free(text); | |
111 text = buf; | |
112 } | |
113 gtk_label_set_text(GTK_LABEL(dw->status_label), text); | |
114 | |
115 g_free(text); | |
116 } | |
117 | |
118 static guint64 msec_time(void) | |
119 { | |
120 struct timeval tv; | |
121 | |
122 if (gettimeofday(&tv, NULL) == -1) return 0; | |
123 | |
124 return (guint64)tv.tv_sec * 1000000 + (guint64)tv.tv_usec; | |
125 } | |
126 | |
127 static gint dupe_iterations(gint n) | |
128 { | |
129 return (n * ((n + 1) / 2)); | |
130 } | |
131 | |
132 static void dupe_window_update_progress(DupeWindow *dw, const gchar *status, gdouble value, gint force) | |
133 { | |
134 const gchar *status_text; | |
135 | |
136 if (status) | |
137 { | |
138 guint64 new_time = 0; | |
139 | |
140 if (dw->setup_n % 10 == 0) | |
141 { | |
142 new_time = msec_time() - dw->setup_time; | |
143 } | |
144 | |
145 if (!force && | |
146 value != 0.0 && | |
147 dw->setup_count > 0 && | |
148 new_time > 2000000) | |
149 { | |
150 gchar *buf; | |
151 gint t; | |
152 gint d; | |
153 guint32 rem; | |
154 | |
155 if (new_time - dw->setup_time_count < 250000) return; | |
156 dw->setup_time_count = new_time; | |
157 | |
158 if (dw->setup_done) | |
159 { | |
160 if (dw->second_set) | |
161 { | |
162 t = dw->setup_count; | |
163 d = dw->setup_count - dw->setup_n; | |
164 } | |
165 else | |
166 { | |
167 t = dupe_iterations(dw->setup_count); | |
168 d = dupe_iterations(dw->setup_count - dw->setup_n); | |
169 } | |
170 } | |
171 else | |
172 { | |
173 t = dw->setup_count; | |
174 d = dw->setup_count - dw->setup_n; | |
175 } | |
176 | |
177 rem = (t - d) ? ((gdouble)(dw->setup_time_count / 1000000) / (t - d)) * d : 0; | |
178 | |
179 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(dw->extra_label), value); | |
180 | |
181 buf = g_strdup_printf("%s %d:%02d ", status, rem / 60, rem % 60); | |
182 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(dw->extra_label), buf); | |
183 g_free(buf); | |
184 | |
185 return; | |
186 } | |
187 else if (force || | |
188 value == 0.0 || | |
189 dw->setup_count == 0 || | |
190 dw->setup_time_count == 0 || | |
191 (new_time > 0 && new_time - dw->setup_time_count >= 250000)) | |
192 { | |
193 if (dw->setup_time_count == 0) dw->setup_time_count = 1; | |
194 if (new_time > 0) dw->setup_time_count = new_time; | |
195 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(dw->extra_label), value); | |
196 status_text = status; | |
197 } | |
198 else | |
199 { | |
200 status_text = NULL; | |
201 } | |
202 } | |
203 else | |
204 { | |
205 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(dw->extra_label), 0.0); | |
206 status_text = " "; | |
207 } | |
208 | |
209 if (status_text) gtk_progress_bar_set_text(GTK_PROGRESS_BAR(dw->extra_label), status_text); | |
210 } | |
211 | |
212 static void widget_set_cursor(GtkWidget *widget, gint icon) | |
213 { | |
214 GdkCursor *cursor; | |
215 | |
216 if (!widget->window) return; | |
217 | |
218 if (icon == -1) | |
219 { | |
220 cursor = NULL; | |
221 } | |
222 else | |
223 { | |
224 cursor = gdk_cursor_new (icon); | |
225 } | |
226 | |
227 gdk_window_set_cursor(widget->window, cursor); | |
228 | |
229 if (cursor) gdk_cursor_unref(cursor); | |
230 } | |
231 | |
232 /* | |
233 * ------------------------------------------------------------------ | |
234 * row color utils | |
235 * ------------------------------------------------------------------ | |
236 */ | |
237 | |
238 static void dupe_listview_realign_colors(DupeWindow *dw) | |
239 { | |
240 GtkTreeModel *store; | |
241 GtkTreeIter iter; | |
242 gboolean color_set = TRUE; | |
243 DupeItem *parent = NULL; | |
244 gint valid; | |
245 | |
246 store = gtk_tree_view_get_model(GTK_TREE_VIEW(dw->listview)); | |
247 valid = gtk_tree_model_get_iter_first(store, &iter); | |
248 while (valid) | |
249 { | |
250 DupeItem *child; | |
251 DupeItem *child_parent; | |
252 | |
253 gtk_tree_model_get(store, &iter, DUPE_COLUMN_POINTER, &child, -1); | |
254 child_parent = dupe_match_find_parent(dw, child); | |
255 if (!parent || parent != child_parent) | |
256 { | |
257 if (!parent) | |
258 { | |
259 /* keep the first row as it is */ | |
260 gtk_tree_model_get(store, &iter, DUPE_COLUMN_COLOR, &color_set, -1); | |
261 } | |
262 else | |
263 { | |
264 color_set = !color_set; | |
265 } | |
266 parent = dupe_match_find_parent(dw, child); | |
267 } | |
268 gtk_list_store_set(GTK_LIST_STORE(store), &iter, DUPE_COLUMN_COLOR, color_set, -1); | |
269 | |
270 valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter); | |
271 } | |
272 } | |
273 | |
274 /* | |
275 * ------------------------------------------------------------------ | |
276 * Dupe item utils | |
277 * ------------------------------------------------------------------ | |
278 */ | |
279 | |
280 static DupeItem *dupe_item_new(const gchar *path, gint64 size, time_t date) | |
281 { | |
282 DupeItem *di; | |
283 | |
284 di = g_new0(DupeItem, 1); | |
285 | |
286 di->path = g_strdup(path); | |
287 di->name = filename_from_path(di->path); | |
288 di->size = size; | |
289 di->date = date; | |
290 | |
291 di->group = NULL; | |
292 di->group_rank = 0.0; | |
293 | |
294 di->simd = NULL; | |
295 di->checksum = 0; | |
296 di->md5sum = NULL; | |
297 di->width = 0; | |
298 di->height = 0; | |
299 | |
300 di->second = FALSE; | |
301 | |
302 return di; | |
303 } | |
304 | |
305 static void dupe_item_free(DupeItem *di) | |
306 { | |
307 g_free(di->path); | |
308 image_sim_free(di->simd); | |
309 g_free(di->md5sum); | |
310 if (di->pixbuf) g_object_unref(di->pixbuf); | |
311 | |
312 g_free(di); | |
313 } | |
314 | |
315 static void dupe_list_free(GList *list) | |
316 { | |
317 GList *work = list; | |
318 while (work) | |
319 { | |
320 DupeItem *di = work->data; | |
321 work = work->next; | |
322 dupe_item_free(di); | |
323 } | |
324 g_list_free(list); | |
325 } | |
326 | |
327 static DupeItem *dupe_item_find_path_by_list(const gchar *path, GList *work) | |
328 { | |
329 while (work) | |
330 { | |
331 DupeItem *di = work->data; | |
332 | |
333 if (strcmp(di->path, path) == 0) return di; | |
334 | |
335 work = work->next; | |
336 } | |
337 | |
338 return NULL; | |
339 } | |
340 | |
341 static DupeItem *dupe_item_find_path(DupeWindow *dw, const gchar *path) | |
342 { | |
343 DupeItem *di; | |
344 | |
345 di = dupe_item_find_path_by_list(path, dw->list); | |
346 if (!di && dw->second_set) di = dupe_item_find_path_by_list(path, dw->second_list); | |
347 | |
348 return di; | |
349 } | |
350 | |
351 /* | |
352 * ------------------------------------------------------------------ | |
353 * Image property cache | |
354 * ------------------------------------------------------------------ | |
355 */ | |
356 | |
357 static void dupe_item_read_cache(DupeItem *di) | |
358 { | |
359 gchar *path; | |
360 CacheData *cd; | |
361 | |
362 if (!di) return; | |
363 | |
364 path = cache_find_location(CACHE_TYPE_SIM, di->path); | |
365 if (!path) return; | |
366 | |
367 if (filetime(di->path) != filetime(path)) | |
368 { | |
369 g_free(path); | |
370 return; | |
371 } | |
372 | |
373 cd = cache_sim_data_load(path); | |
374 g_free(path); | |
375 | |
376 if (cd) | |
377 { | |
378 if (!di->simd && cd->sim) | |
379 { | |
380 di->simd = cd->sim; | |
381 cd->sim = NULL; | |
382 } | |
383 if (di->width == 0 && di->height == 0 && cd->dimensions) | |
384 { | |
385 di->width = cd->width; | |
386 di->height = cd->height; | |
387 } | |
388 if (di->checksum == 0 && cd->have_checksum) | |
389 { | |
390 di->checksum = cd->checksum; | |
391 } | |
392 if (!di->md5sum && cd->have_md5sum) | |
393 { | |
394 di->md5sum = md5_digest_to_text(cd->md5sum); | |
395 } | |
396 cache_sim_data_free(cd); | |
397 } | |
398 } | |
399 | |
400 static void dupe_item_write_cache(DupeItem *di) | |
401 { | |
402 gchar *base; | |
403 mode_t mode = 0755; | |
404 | |
405 if (!di) return; | |
406 | |
407 base = cache_get_location(CACHE_TYPE_SIM, di->path, FALSE, &mode); | |
408 if (cache_ensure_dir_exists(base, mode)) | |
409 { | |
410 CacheData *cd; | |
411 | |
412 cd = cache_sim_data_new(); | |
413 cd->path = cache_get_location(CACHE_TYPE_SIM, di->path, TRUE, NULL); | |
414 | |
415 if (di->width != 0) cache_sim_data_set_dimensions(cd, di->width, di->height); | |
416 if (di->checksum != 0) cache_sim_data_set_checksum(cd, di->checksum); | |
417 if (di->md5sum) | |
418 { | |
419 guchar digest[16]; | |
420 if (md5_digest_from_text(di->md5sum, digest)) cache_sim_data_set_md5sum(cd, digest); | |
421 } | |
422 if (di->simd) cache_sim_data_set_similarity(cd, di->simd); | |
423 | |
424 if (cache_sim_data_save(cd)) | |
425 { | |
426 filetime_set(cd->path, filetime(di->path)); | |
427 } | |
428 cache_sim_data_free(cd); | |
429 } | |
430 g_free(base); | |
431 } | |
432 | |
433 /* | |
434 * ------------------------------------------------------------------ | |
435 * Window list utils | |
436 * ------------------------------------------------------------------ | |
437 */ | |
438 | |
439 static gint dupe_listview_find_item(GtkListStore *store, DupeItem *item, GtkTreeIter *iter) | |
440 { | |
441 gint valid; | |
442 gint row = 0; | |
443 | |
444 valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), iter); | |
445 while (valid) | |
446 { | |
447 DupeItem *item_n; | |
448 gtk_tree_model_get(GTK_TREE_MODEL(store), iter, DUPE_COLUMN_POINTER, &item_n, -1); | |
449 if (item_n == item) return row; | |
450 | |
451 valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), iter); | |
452 row++; | |
453 } | |
454 | |
455 return -1; | |
456 } | |
457 | |
458 static void dupe_listview_add(DupeWindow *dw, DupeItem *parent, DupeItem *child) | |
459 { | |
460 DupeItem *di; | |
461 gint row; | |
462 gchar *text[DUPE_COLUMN_COUNT]; | |
463 GtkListStore *store; | |
464 GtkTreeIter iter; | |
465 gboolean color_set = FALSE; | |
466 gint rank; | |
467 | |
468 if (!parent) return; | |
469 | |
470 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dw->listview))); | |
471 | |
472 if (child) | |
473 { | |
474 DupeMatch *dm; | |
475 | |
476 row = dupe_listview_find_item(store, parent, &iter); | |
477 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, DUPE_COLUMN_COLOR, &color_set, -1); | |
478 | |
479 row++; | |
480 | |
481 if (child->group) | |
482 { | |
483 dm = child->group->data; | |
484 rank = (gint)floor(dm->rank); | |
485 } | |
486 else | |
487 { | |
488 rank = 1; | |
489 printf("NULL group in item!\n"); | |
490 } | |
491 } | |
492 else | |
493 { | |
494 if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter)) | |
495 { | |
496 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, DUPE_COLUMN_COLOR, &color_set, -1); | |
497 color_set = !color_set; | |
498 } | |
499 else | |
500 { | |
501 color_set = FALSE; | |
502 } | |
503 row = 0; | |
504 rank = 0; | |
505 } | |
506 | |
507 di = (child) ? child : parent; | |
508 | |
509 if (!child && dw->second_set) | |
510 { | |
511 text[DUPE_COLUMN_RANK] = g_strdup("[1]"); | |
512 } | |
513 else if (rank == 0) | |
514 { | |
515 text[DUPE_COLUMN_RANK] = g_strdup((di->second) ? "(2)" : ""); | |
516 } | |
517 else | |
518 { | |
519 text[DUPE_COLUMN_RANK] = g_strdup_printf("%d%s", rank, (di->second) ? " (2)" : ""); | |
520 } | |
521 | |
522 text[DUPE_COLUMN_THUMB] = ""; | |
523 text[DUPE_COLUMN_NAME] = (gchar *)di->name; | |
524 text[DUPE_COLUMN_SIZE] = text_from_size(di->size); | |
525 text[DUPE_COLUMN_DATE] = (gchar *)text_from_time(di->date); | |
526 if (di->width > 0 && di->height > 0) | |
527 { | |
528 text[DUPE_COLUMN_DIMENSIONS] = g_strdup_printf("%d x %d", di->width, di->height); | |
529 } | |
530 else | |
531 { | |
532 text[DUPE_COLUMN_DIMENSIONS] = g_strdup(""); | |
533 } | |
534 text[DUPE_COLUMN_PATH] = di->path; | |
535 text[DUPE_COLUMN_COLOR] = NULL; | |
536 | |
537 gtk_list_store_insert(store, &iter, row); | |
538 gtk_list_store_set(store, &iter, | |
539 DUPE_COLUMN_POINTER, di, | |
540 DUPE_COLUMN_RANK, text[DUPE_COLUMN_RANK], | |
541 DUPE_COLUMN_THUMB, NULL, | |
542 DUPE_COLUMN_NAME, text[DUPE_COLUMN_NAME], | |
543 DUPE_COLUMN_SIZE, text[DUPE_COLUMN_SIZE], | |
544 DUPE_COLUMN_DATE, text[DUPE_COLUMN_DATE], | |
545 DUPE_COLUMN_DIMENSIONS, text[DUPE_COLUMN_DIMENSIONS], | |
546 DUPE_COLUMN_PATH, text[DUPE_COLUMN_PATH], | |
547 DUPE_COLUMN_COLOR, color_set, | |
548 -1); | |
549 | |
550 g_free(text[DUPE_COLUMN_RANK]); | |
551 g_free(text[DUPE_COLUMN_SIZE]); | |
552 g_free(text[DUPE_COLUMN_DIMENSIONS]); | |
553 } | |
554 | |
555 static void dupe_listview_populate(DupeWindow *dw) | |
556 { | |
557 GtkListStore *store; | |
558 GList *work; | |
559 | |
560 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dw->listview))); | |
561 gtk_list_store_clear(store); | |
562 | |
563 work = g_list_last(dw->dupes); | |
564 while (work) | |
565 { | |
566 DupeItem *parent = work->data; | |
567 GList *temp; | |
568 | |
569 dupe_listview_add(dw, parent, NULL); | |
570 | |
571 temp = g_list_last(parent->group); | |
572 while (temp) | |
573 { | |
574 DupeMatch *dm = temp->data; | |
575 DupeItem *child; | |
576 | |
577 child = dm->di; | |
578 | |
579 dupe_listview_add(dw, parent, child); | |
580 | |
581 temp = temp->prev; | |
582 } | |
583 | |
584 work = work->prev; | |
585 } | |
586 | |
587 gtk_tree_view_columns_autosize(GTK_TREE_VIEW(dw->listview)); | |
588 } | |
589 | |
590 static void dupe_listview_remove(DupeWindow *dw, DupeItem *di) | |
591 { | |
592 GtkListStore *store; | |
593 GtkTreeIter iter; | |
594 gint row; | |
595 | |
596 if (!di) return; | |
597 | |
598 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dw->listview))); | |
599 row = dupe_listview_find_item(store, di, &iter); | |
600 if (row < 0) return; | |
601 | |
602 tree_view_move_cursor_away(GTK_TREE_VIEW(dw->listview), &iter, TRUE); | |
603 gtk_list_store_remove(store, &iter); | |
604 | |
605 if (g_list_find(dw->dupes, di) != NULL) | |
606 { | |
607 if (!dw->color_frozen) dupe_listview_realign_colors(dw); | |
608 } | |
609 } | |
610 | |
611 | |
612 static GList *dupe_listview_get_path_list(DupeWindow *dw, GtkWidget *listview) | |
613 { | |
614 GtkTreeModel *store; | |
615 GtkTreeIter iter; | |
616 gint valid; | |
617 GList *list = NULL; | |
618 | |
619 store = gtk_tree_view_get_model(GTK_TREE_VIEW(listview)); | |
620 valid = gtk_tree_model_get_iter_first(store, &iter); | |
621 while (valid) | |
622 { | |
623 DupeItem *di; | |
624 gtk_tree_model_get(store, &iter, DUPE_COLUMN_POINTER, &di, -1); | |
625 list = g_list_prepend(list, g_strdup(di->path)); | |
626 | |
627 valid = gtk_tree_model_iter_next(store, &iter); | |
628 } | |
629 | |
630 return g_list_reverse(list); | |
631 } | |
632 | |
633 | |
634 static GList *dupe_listview_get_selection(DupeWindow *dw, GtkWidget *listview) | |
635 { | |
636 GtkTreeModel *store; | |
637 GtkTreeSelection *selection; | |
638 GList *slist; | |
639 GList *list = NULL; | |
640 GList *work; | |
641 | |
642 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(listview)); | |
643 slist = gtk_tree_selection_get_selected_rows(selection, &store); | |
644 work = slist; | |
645 while (work) | |
646 { | |
647 GtkTreePath *tpath = work->data; | |
648 DupeItem *di = NULL; | |
649 GtkTreeIter iter; | |
650 | |
651 gtk_tree_model_get_iter(store, &iter, tpath); | |
652 gtk_tree_model_get(store, &iter, DUPE_COLUMN_POINTER, &di, -1); | |
653 if (di) | |
654 { | |
655 list = g_list_prepend(list, g_strdup(di->path)); | |
656 } | |
657 work = work->next; | |
658 } | |
659 g_list_foreach(slist, (GFunc)gtk_tree_path_free, NULL); | |
660 g_list_free(slist); | |
661 | |
662 return g_list_reverse(list); | |
663 } | |
664 | |
665 static gint dupe_listview_item_is_selected(DupeWindow *dw, DupeItem *di, GtkWidget *listview) | |
666 { | |
667 GtkTreeModel *store; | |
668 GtkTreeSelection *selection; | |
669 GList *slist; | |
670 GList *work; | |
671 gint found = FALSE; | |
672 | |
673 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(listview)); | |
674 slist = gtk_tree_selection_get_selected_rows(selection, &store); | |
675 work = slist; | |
676 while (!found && work) | |
677 { | |
678 GtkTreePath *tpath = work->data; | |
679 DupeItem *di_n; | |
680 GtkTreeIter iter; | |
681 | |
682 gtk_tree_model_get_iter(store, &iter, tpath); | |
683 gtk_tree_model_get(store, &iter, DUPE_COLUMN_POINTER, &di_n, -1); | |
684 if (di_n == di) found = TRUE; | |
685 work = work->next; | |
686 } | |
687 g_list_foreach(slist, (GFunc)gtk_tree_path_free, NULL); | |
688 g_list_free(slist); | |
689 | |
690 return found; | |
691 } | |
692 | |
693 static void dupe_listview_select_dupes(DupeWindow *dw, gint parents) | |
694 { | |
695 GtkTreeModel *store; | |
696 GtkTreeSelection *selection; | |
697 GtkTreeIter iter; | |
698 gint valid; | |
699 | |
700 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dw->listview)); | |
701 gtk_tree_selection_unselect_all(selection); | |
702 | |
703 store = gtk_tree_view_get_model(GTK_TREE_VIEW(dw->listview)); | |
704 valid = gtk_tree_model_get_iter_first(store, &iter); | |
705 while (valid) | |
706 { | |
707 DupeItem *di; | |
708 | |
709 gtk_tree_model_get(store, &iter, DUPE_COLUMN_POINTER, &di, -1); | |
710 if ( (dupe_match_find_parent(dw, di) == di) == (parents) ) | |
711 { | |
712 gtk_tree_selection_select_iter(selection, &iter); | |
713 } | |
714 valid = gtk_tree_model_iter_next(store, &iter); | |
715 } | |
716 } | |
717 | |
718 /* | |
719 * ------------------------------------------------------------------ | |
720 * Match group manipulation | |
721 * ------------------------------------------------------------------ | |
722 */ | |
723 | |
724 static DupeMatch *dupe_match_find_match(DupeItem *child, DupeItem *parent) | |
725 { | |
726 GList *work; | |
727 | |
728 work = parent->group; | |
729 while (work) | |
730 { | |
731 DupeMatch *dm = work->data; | |
732 if (dm->di == child) return dm; | |
733 work = work->next; | |
734 } | |
735 return NULL; | |
736 } | |
737 | |
738 static void dupe_match_link_child(DupeItem *child, DupeItem *parent, gdouble rank) | |
739 { | |
740 DupeMatch *dm; | |
741 | |
742 dm = g_new0(DupeMatch, 1); | |
743 dm->di = child; | |
744 dm->rank = rank; | |
745 parent->group = g_list_append(parent->group, dm); | |
746 } | |
747 | |
748 static void dupe_match_link(DupeItem *a, DupeItem *b, gdouble rank) | |
749 { | |
750 dupe_match_link_child(a, b, rank); | |
751 dupe_match_link_child(b, a, rank); | |
752 } | |
753 | |
754 static void dupe_match_unlink_child(DupeItem *child, DupeItem *parent) | |
755 { | |
756 DupeMatch *dm; | |
757 | |
758 dm = dupe_match_find_match(child, parent); | |
759 if (dm) | |
760 { | |
761 parent->group = g_list_remove(parent->group, dm); | |
762 g_free(dm); | |
763 } | |
764 } | |
765 | |
766 static void dupe_match_unlink(DupeItem *a, DupeItem *b) | |
767 { | |
768 dupe_match_unlink_child(a, b); | |
769 dupe_match_unlink_child(b, a); | |
770 } | |
771 | |
772 static void dupe_match_link_clear(DupeItem *parent, gint unlink_children) | |
773 { | |
774 GList *work; | |
775 | |
776 work = parent->group; | |
777 while (work) | |
778 { | |
779 DupeMatch *dm = work->data; | |
780 work = work->next; | |
781 | |
782 if (unlink_children) dupe_match_unlink_child(parent, dm->di); | |
783 | |
784 g_free(dm); | |
785 } | |
786 | |
787 g_list_free(parent->group); | |
788 parent->group = NULL; | |
789 parent->group_rank = 0.0; | |
790 } | |
791 | |
792 static gint dupe_match_link_exists(DupeItem *child, DupeItem *parent) | |
793 { | |
794 return (dupe_match_find_match(child, parent) != NULL); | |
795 } | |
796 | |
797 static gdouble dupe_match_link_rank(DupeItem *child, DupeItem *parent) | |
798 { | |
799 DupeMatch *dm; | |
800 | |
801 dm = dupe_match_find_match(child, parent); | |
802 if (dm) return dm->rank; | |
803 | |
804 return 0.0; | |
805 } | |
806 | |
807 static DupeItem *dupe_match_highest_rank(DupeItem *child) | |
808 { | |
809 DupeMatch *dr; | |
810 GList *work; | |
811 | |
812 dr = NULL; | |
813 work = child->group; | |
814 while (work) | |
815 { | |
816 DupeMatch *dm = work->data; | |
817 if (!dr || dm->rank > dr->rank) dr = dm; | |
818 work = work->next; | |
819 } | |
820 | |
821 return (dr) ? dr->di : NULL; | |
822 } | |
823 | |
824 static void dupe_match_rank_update(DupeItem *parent) | |
825 { | |
826 GList *work; | |
827 gdouble rank = 0.0; | |
828 gint c = 0; | |
829 | |
830 work = parent->group; | |
831 while (work) | |
832 { | |
833 DupeMatch *dm = work->data; | |
834 work = work->next; | |
835 rank += dm->rank; | |
836 c++; | |
837 } | |
838 | |
839 if (c > 0) | |
840 { | |
841 parent->group_rank = rank / c; | |
842 } | |
843 else | |
844 { | |
845 parent->group_rank = 0.0; | |
846 } | |
847 } | |
848 | |
849 static DupeItem *dupe_match_find_parent(DupeWindow *dw, DupeItem *child) | |
850 { | |
851 GList *work; | |
852 | |
853 if (g_list_find(dw->dupes, child)) return child; | |
854 | |
855 work = child->group; | |
856 while (work) | |
857 { | |
858 DupeMatch *dm = work->data; | |
859 if (g_list_find(dw->dupes, dm->di)) return dm->di; | |
860 work = work->next; | |
861 } | |
862 | |
863 return NULL; | |
864 } | |
865 | |
866 static void dupe_match_reset_list(GList *work) | |
867 { | |
868 while (work) | |
869 { | |
870 DupeItem *di = work->data; | |
871 work = work->next; | |
872 | |
873 dupe_match_link_clear(di, FALSE); | |
874 } | |
875 } | |
876 | |
877 static void dupe_match_reparent(DupeWindow *dw, DupeItem *old, DupeItem *new) | |
878 { | |
879 GList *work; | |
880 | |
881 if (!old || !new || !dupe_match_link_exists(old, new)) return; | |
882 | |
883 dupe_match_link_clear(new, TRUE); | |
884 work = old->group; | |
885 while (work) | |
886 { | |
887 DupeMatch *dm = work->data; | |
888 dupe_match_unlink_child(old, dm->di); | |
889 dupe_match_link_child(new, dm->di, dm->rank); | |
890 work = work->next; | |
891 } | |
892 | |
893 new->group = old->group; | |
894 old->group = NULL; | |
895 | |
896 work = g_list_find(dw->dupes, old); | |
897 if (work) work->data = new; | |
898 } | |
899 | |
900 static void dupe_match_print_group(DupeItem *di) | |
901 { | |
902 GList *work; | |
903 | |
904 printf("+ %f %s\n", di->group_rank, di->name); | |
905 | |
906 work = di->group; | |
907 while (work) | |
908 { | |
909 DupeMatch *dm = work->data; | |
910 work = work->next; | |
911 | |
912 printf(" %f %s\n", dm->rank, dm->di->name); | |
913 } | |
914 | |
915 printf("\n"); | |
916 } | |
917 | |
918 static void dupe_match_print_list(GList *list) | |
919 { | |
920 GList *work; | |
921 | |
922 work = list; | |
923 while (work) | |
924 { | |
925 DupeItem *di = work->data; | |
926 dupe_match_print_group(di); | |
927 work = work->next; | |
928 } | |
929 } | |
930 | |
931 /* level 3, unlinking and orphan handling */ | |
932 static GList *dupe_match_unlink_by_rank(DupeItem *child, DupeItem *parent, GList *list, DupeWindow *dw) | |
933 { | |
934 DupeItem *best; | |
935 | |
936 best = dupe_match_highest_rank(parent); | |
937 if (best == child || dupe_match_highest_rank(child) == parent) | |
938 { | |
939 GList *work; | |
940 gdouble rank; | |
941 | |
942 if (debug > 1) printf("link found %s to %s [%d]\n", child->name, parent->name, g_list_length(parent->group)); | |
943 | |
944 work = parent->group; | |
945 while (work) | |
946 { | |
947 DupeMatch *dm = work->data; | |
948 DupeItem *orphan; | |
949 | |
950 work = work->next; | |
951 orphan = dm->di; | |
952 if (orphan != child && g_list_length(orphan->group) < 2) | |
953 { | |
954 dupe_match_link_clear(orphan, TRUE); | |
955 if (!dw->second_set || orphan->second) | |
956 { | |
957 dupe_match(orphan, child, dw->match_mask, &rank, FALSE); | |
958 dupe_match_link(orphan, child, rank); | |
959 } | |
960 list = g_list_remove(list, orphan); | |
961 } | |
962 } | |
963 | |
964 rank = dupe_match_link_rank(child, parent); | |
965 dupe_match_link_clear(parent, TRUE); | |
966 dupe_match_link(child, parent, rank); | |
967 list = g_list_remove(list, parent); | |
968 } | |
969 else | |
970 { | |
971 if (debug > 1) printf("unlinking %s and %s\n", child->name, parent->name); | |
972 | |
973 dupe_match_unlink(child, parent); | |
974 } | |
975 | |
976 return list; | |
977 } | |
978 | |
979 /* level 2 */ | |
980 static GList *dupe_match_group_filter(GList *list, DupeItem *di, DupeWindow *dw) | |
981 { | |
982 GList *work; | |
983 | |
984 work = g_list_last(di->group); | |
985 while (work) | |
986 { | |
987 DupeMatch *dm = work->data; | |
988 work = work->prev; | |
989 list = dupe_match_unlink_by_rank(di, dm->di, list, dw); | |
990 } | |
991 | |
992 return list; | |
993 } | |
994 | |
995 /* level 1 (top) */ | |
996 static GList *dupe_match_group_trim(GList *list, DupeWindow *dw) | |
997 { | |
998 GList *work; | |
999 | |
1000 work = list; | |
1001 while (work) | |
1002 { | |
1003 DupeItem *di = work->data; | |
1004 if (!di->second) list = dupe_match_group_filter(list, di, dw); | |
1005 work = work->next; | |
1006 if (di->second) list = g_list_remove(list, di); | |
1007 } | |
1008 | |
1009 return list; | |
1010 } | |
1011 | |
1012 static gint dupe_match_sort_groups_cb(gconstpointer a, gconstpointer b) | |
1013 { | |
1014 DupeMatch *da = (DupeMatch *)a; | |
1015 DupeMatch *db = (DupeMatch *)b; | |
1016 | |
1017 if (da->rank > db->rank) return -1; | |
1018 if (da->rank < db->rank) return 1; | |
1019 return 0; | |
1020 } | |
1021 | |
1022 static void dupe_match_sort_groups(GList *list) | |
1023 { | |
1024 GList *work; | |
1025 | |
1026 work = list; | |
1027 while (work) | |
1028 { | |
1029 DupeItem *di = work->data; | |
1030 di->group = g_list_sort(di->group, dupe_match_sort_groups_cb); | |
1031 work = work->next; | |
1032 } | |
1033 } | |
1034 | |
1035 static gint dupe_match_rank_sort_cb(gconstpointer a, gconstpointer b) | |
1036 { | |
1037 DupeItem *da = (DupeItem *)a; | |
1038 DupeItem *db = (DupeItem *)b; | |
1039 | |
1040 if (da->group_rank > db->group_rank) return -1; | |
1041 if (da->group_rank < db->group_rank) return 1; | |
1042 return 0; | |
1043 } | |
1044 | |
1045 /* returns allocated GList of dupes sorted by rank */ | |
1046 static GList *dupe_match_rank_sort(GList *source_list) | |
1047 { | |
1048 GList *list = NULL; | |
1049 GList *work; | |
1050 | |
1051 work = source_list; | |
1052 while (work) | |
1053 { | |
1054 DupeItem *di = work->data; | |
1055 | |
1056 if (di->group) | |
1057 { | |
1058 dupe_match_rank_update(di); | |
1059 list = g_list_prepend(list, di); | |
1060 } | |
1061 | |
1062 work = work->next; | |
1063 } | |
1064 | |
1065 return g_list_sort(list, dupe_match_rank_sort_cb); | |
1066 } | |
1067 | |
1068 static void dupe_match_rank(DupeWindow *dw) | |
1069 { | |
1070 GList *list; | |
1071 | |
1072 list = dupe_match_rank_sort(dw->list); | |
1073 | |
1074 if (debug > 1) dupe_match_print_list(list); | |
1075 | |
1076 if (debug) printf("Similar items: %d\n", g_list_length(list)); | |
1077 list = dupe_match_group_trim(list, dw); | |
1078 if (debug) printf("Unique groups: %d\n", g_list_length(list)); | |
1079 | |
1080 dupe_match_sort_groups(list); | |
1081 | |
1082 if (debug) dupe_match_print_list(list); | |
1083 | |
1084 list = dupe_match_rank_sort(list); | |
1085 | |
1086 g_list_free(dw->dupes); | |
1087 dw->dupes = list; | |
1088 } | |
1089 | |
1090 /* | |
1091 * ------------------------------------------------------------------ | |
1092 * Match group tests | |
1093 * ------------------------------------------------------------------ | |
1094 */ | |
1095 | |
1096 static gint dupe_match(DupeItem *a, DupeItem *b, DupeMatchType mask, gdouble *rank, gint fast) | |
1097 { | |
1098 *rank = 0.0; | |
1099 | |
1100 if (a == b) return FALSE; | |
1101 | |
1102 if (mask & DUPE_MATCH_PATH) | |
1103 { | |
1104 if (strcmp(a->path, b->path) != 0) return FALSE; | |
1105 } | |
1106 if (mask & DUPE_MATCH_NAME) | |
1107 { | |
1108 if (strcmp(a->name, b->name) != 0) return FALSE; | |
1109 } | |
1110 if (mask & DUPE_MATCH_SIZE) | |
1111 { | |
1112 if (a->size != b->size) return FALSE; | |
1113 } | |
1114 if (mask & DUPE_MATCH_DATE) | |
1115 { | |
1116 if (a->date != b->date) return FALSE; | |
1117 } | |
1118 if (mask & DUPE_MATCH_SUM) | |
1119 { | |
1120 if (!a->md5sum) a->md5sum = md5_text_from_file_utf8(a->path, ""); | |
1121 if (!b->md5sum) b->md5sum = md5_text_from_file_utf8(b->path, ""); | |
1122 if (a->md5sum[0] == '\0' || | |
1123 b->md5sum[0] == '\0' || | |
1124 strcmp(a->md5sum, b->md5sum) != 0) return FALSE; | |
1125 } | |
1126 if (mask & DUPE_MATCH_DIM) | |
1127 { | |
1128 if (a->width == 0) image_load_dimensions(a->path, &a->width, &a->height); | |
1129 if (b->width == 0) image_load_dimensions(b->path, &b->width, &b->height); | |
1130 if (a->width != b->width || a->height != b->height) return FALSE; | |
1131 } | |
1132 if (mask & DUPE_MATCH_SIM_HIGH || | |
1133 mask & DUPE_MATCH_SIM_MED || | |
1134 mask & DUPE_MATCH_SIM_LOW || | |
1135 mask & DUPE_MATCH_SIM_CUSTOM) | |
1136 { | |
1137 gdouble f; | |
1138 gdouble m; | |
1139 | |
1140 if (mask & DUPE_MATCH_SIM_HIGH) m = 0.95; | |
1141 else if (mask & DUPE_MATCH_SIM_MED) m = 0.90; | |
1142 else if (mask & DUPE_MATCH_SIM_CUSTOM) m = (gdouble)dupe_custom_threshold / 100.0; | |
1143 else m = 0.85; | |
1144 | |
1145 if (fast) | |
1146 { | |
1147 f = image_sim_compare_fast(a->simd, b->simd, m); | |
1148 } | |
1149 else | |
1150 { | |
1151 f = image_sim_compare(a->simd, b->simd); | |
1152 } | |
1153 | |
1154 *rank = f * 100.0; | |
1155 | |
1156 if (f < m) return FALSE; | |
1157 | |
1158 if (debug > 2) printf("similar: %32s %32s = %f\n", a->name, b->name, f); | |
1159 } | |
1160 | |
1161 return TRUE; | |
1162 } | |
1163 | |
1164 static void dupe_list_check_match(DupeWindow *dw, DupeItem *needle, GList *start) | |
1165 { | |
1166 GList *work; | |
1167 | |
1168 if (dw->second_set) | |
1169 { | |
1170 work = dw->second_list; | |
1171 } | |
1172 else if (start) | |
1173 { | |
1174 work = start; | |
1175 } | |
1176 else | |
1177 { | |
1178 work = g_list_last(dw->list); | |
1179 } | |
1180 | |
1181 while (work) | |
1182 { | |
1183 DupeItem *di = work->data; | |
1184 | |
1185 /* speed opt: forward for second set, back for simple compare */ | |
1186 if (dw->second_set) | |
1187 work = work->next; | |
1188 else | |
1189 work = work->prev; | |
1190 | |
1191 if (!dupe_match_link_exists(needle, di)) | |
1192 { | |
1193 gdouble rank; | |
1194 | |
1195 if (dupe_match(di, needle, dw->match_mask, &rank, TRUE)) | |
1196 { | |
1197 dupe_match_link(di, needle, rank); | |
1198 } | |
1199 } | |
1200 } | |
1201 } | |
1202 | |
1203 /* | |
1204 * ------------------------------------------------------------------ | |
1205 * Thumbnail handling | |
1206 * ------------------------------------------------------------------ | |
1207 */ | |
1208 | |
1209 static void dupe_listview_set_thumb(DupeWindow *dw, DupeItem *di, GtkTreeIter *iter) | |
1210 { | |
1211 GtkListStore *store; | |
1212 GtkTreeIter iter_n; | |
1213 | |
1214 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dw->listview))); | |
1215 if (!iter) | |
1216 { | |
1217 if (dupe_listview_find_item(store, di, &iter_n) >= 0) | |
1218 { | |
1219 iter = &iter_n; | |
1220 } | |
1221 } | |
1222 | |
1223 if (iter) gtk_list_store_set(store, iter, DUPE_COLUMN_THUMB, di->pixbuf, -1); | |
1224 } | |
1225 | |
1226 static void dupe_thumb_do(DupeWindow *dw) | |
1227 { | |
1228 DupeItem *di; | |
1229 | |
1230 if (!dw->thumb_loader || !dw->thumb_item) return; | |
1231 di = dw->thumb_item; | |
1232 | |
1233 if (di->pixbuf) g_object_unref(di->pixbuf); | |
1234 di->pixbuf = thumb_loader_get_pixbuf(dw->thumb_loader, TRUE); | |
1235 | |
1236 dupe_listview_set_thumb(dw, di, NULL); | |
1237 } | |
1238 | |
1239 static void dupe_thumb_error_cb(ThumbLoader *tl, gpointer data) | |
1240 { | |
1241 DupeWindow *dw = data; | |
1242 | |
1243 dupe_thumb_do(dw); | |
1244 dupe_thumb_step(dw); | |
1245 } | |
1246 | |
1247 static void dupe_thumb_done_cb(ThumbLoader *tl, gpointer data) | |
1248 { | |
1249 DupeWindow *dw = data; | |
1250 | |
1251 dupe_thumb_do(dw); | |
1252 dupe_thumb_step(dw); | |
1253 } | |
1254 | |
1255 static void dupe_thumb_step(DupeWindow *dw) | |
1256 { | |
1257 GtkTreeModel *store; | |
1258 GtkTreeIter iter; | |
1259 DupeItem *di = NULL; | |
1260 gint valid; | |
1261 gint row = 0; | |
1262 gint length = 0; | |
1263 | |
1264 store = gtk_tree_view_get_model(GTK_TREE_VIEW(dw->listview)); | |
1265 valid = gtk_tree_model_get_iter_first(store, &iter); | |
1266 | |
1267 while (!di && valid) | |
1268 { | |
1269 GdkPixbuf *pixbuf; | |
1270 | |
1271 length++; | |
1272 gtk_tree_model_get(store, &iter, DUPE_COLUMN_POINTER, &di, DUPE_COLUMN_THUMB, &pixbuf, -1); | |
1273 if (pixbuf || di->pixbuf) | |
1274 { | |
1275 if (!pixbuf) gtk_list_store_set(GTK_LIST_STORE(store), &iter, DUPE_COLUMN_THUMB, di->pixbuf, -1); | |
1276 row++; | |
1277 di = NULL; | |
1278 } | |
1279 valid = gtk_tree_model_iter_next(store, &iter); | |
1280 } | |
1281 if (valid) | |
1282 { | |
1283 while (gtk_tree_model_iter_next(store, &iter)) length++; | |
1284 } | |
1285 | |
1286 if (!di) | |
1287 { | |
1288 dw->thumb_item = NULL; | |
1289 thumb_loader_free(dw->thumb_loader); | |
1290 dw->thumb_loader = NULL; | |
1291 | |
1292 dupe_window_update_progress(dw, NULL, 0.0, FALSE); | |
1293 return; | |
1294 } | |
1295 | |
1296 dupe_window_update_progress(dw, _("Loading thumbs..."), | |
1297 length == 0 ? 0.0 : (gdouble)(row) / length, FALSE); | |
1298 | |
1299 dw->thumb_item = di; | |
1300 thumb_loader_free(dw->thumb_loader); | |
1301 dw->thumb_loader = thumb_loader_new(thumb_max_width, thumb_max_height); | |
1302 | |
1303 thumb_loader_set_callbacks(dw->thumb_loader, | |
1304 dupe_thumb_done_cb, | |
1305 dupe_thumb_error_cb, | |
1306 NULL, | |
1307 dw); | |
1308 | |
1309 /* start it */ | |
1310 if (!thumb_loader_start(dw->thumb_loader, di->path)) | |
1311 { | |
1312 /* error, handle it, do next */ | |
1313 if (debug) printf("error loading thumb for %s\n", di->path); | |
1314 dupe_thumb_do(dw); | |
1315 dupe_thumb_step(dw); | |
1316 } | |
1317 } | |
1318 | |
1319 /* | |
1320 * ------------------------------------------------------------------ | |
1321 * Dupe checking loop | |
1322 * ------------------------------------------------------------------ | |
1323 */ | |
1324 | |
1325 static void dupe_check_stop(DupeWindow *dw) | |
1326 { | |
1327 if (dw->idle_id != -1 || dw->img_loader || dw->thumb_loader) | |
1328 { | |
1329 g_source_remove(dw->idle_id); | |
1330 dw->idle_id = -1; | |
1331 dupe_window_update_progress(dw, NULL, 0.0, FALSE); | |
1332 widget_set_cursor(dw->listview, -1); | |
1333 } | |
1334 | |
1335 thumb_loader_free(dw->thumb_loader); | |
1336 dw->thumb_loader = NULL; | |
1337 | |
1338 image_loader_free(dw->img_loader); | |
1339 dw->img_loader = NULL; | |
1340 } | |
1341 | |
1342 static void dupe_loader_done_cb(ImageLoader *il, gpointer data) | |
1343 { | |
1344 DupeWindow *dw = data; | |
1345 GdkPixbuf *pixbuf; | |
1346 | |
1347 pixbuf = image_loader_get_pixbuf(il); | |
1348 | |
1349 if (dw->setup_point) | |
1350 { | |
1351 DupeItem *di = dw->setup_point->data; | |
1352 | |
1353 if (!di->simd) | |
1354 { | |
1355 di->simd = image_sim_new_from_pixbuf(pixbuf); | |
1356 } | |
1357 else | |
1358 { | |
1359 image_sim_fill_data(di->simd, pixbuf); | |
1360 } | |
1361 | |
1362 if (di->width == 0 && di->height == 0) | |
1363 { | |
1364 di->width = gdk_pixbuf_get_width(pixbuf); | |
1365 di->height = gdk_pixbuf_get_height(pixbuf); | |
1366 } | |
1367 if (enable_thumb_caching) | |
1368 { | |
1369 dupe_item_write_cache(di); | |
1370 } | |
1371 | |
1372 image_sim_alternate_processing(di->simd); | |
1373 } | |
1374 | |
1375 image_loader_free(dw->img_loader); | |
1376 dw->img_loader = NULL; | |
1377 | |
1378 dw->idle_id = g_idle_add(dupe_check_cb, dw); | |
1379 } | |
1380 | |
1381 static void dupe_setup_reset(DupeWindow *dw) | |
1382 { | |
1383 dw->setup_point = NULL; | |
1384 dw->setup_n = 0; | |
1385 dw->setup_time = msec_time(); | |
1386 dw->setup_time_count = 0; | |
1387 } | |
1388 | |
1389 static GList *dupe_setup_point_step(DupeWindow *dw, GList *p) | |
1390 { | |
1391 if (!p) return NULL; | |
1392 | |
1393 if (p->next) return p->next; | |
1394 | |
1395 if (dw->second_set && g_list_first(p) == dw->list) return dw->second_list; | |
1396 | |
1397 return NULL; | |
1398 } | |
1399 | |
1400 static gint dupe_check_cb(gpointer data) | |
1401 { | |
1402 DupeWindow *dw = data; | |
1403 | |
1404 if (dw->idle_id == -1) return FALSE; | |
1405 | |
1406 if (!dw->setup_done) | |
1407 { | |
1408 if ((dw->match_mask & DUPE_MATCH_SUM) && | |
1409 !(dw->setup_mask & DUPE_MATCH_SUM) ) | |
1410 { | |
1411 if (!dw->setup_point) dw->setup_point = dw->list; | |
1412 | |
1413 while (dw->setup_point) | |
1414 { | |
1415 DupeItem *di = dw->setup_point->data; | |
1416 | |
1417 dw->setup_point = dupe_setup_point_step(dw, dw->setup_point); | |
1418 dw->setup_n++; | |
1419 | |
1420 if (!di->md5sum) | |
1421 { | |
1422 dupe_window_update_progress(dw, _("Reading checksums..."), | |
1423 dw->setup_count == 0 ? 0.0 : (gdouble)(dw->setup_n - 1) / dw->setup_count, FALSE); | |
1424 | |
1425 if (enable_thumb_caching) | |
1426 { | |
1427 dupe_item_read_cache(di); | |
1428 if (di->md5sum) return TRUE; | |
1429 } | |
1430 | |
1431 di->md5sum = md5_text_from_file_utf8(di->path, ""); | |
1432 if (enable_thumb_caching) | |
1433 { | |
1434 dupe_item_write_cache(di); | |
1435 } | |
1436 return TRUE; | |
1437 } | |
1438 } | |
1439 dw->setup_mask |= DUPE_MATCH_SUM; | |
1440 dupe_setup_reset(dw); | |
1441 } | |
1442 if ((dw->match_mask & DUPE_MATCH_DIM) && | |
1443 !(dw->setup_mask & DUPE_MATCH_DIM) ) | |
1444 { | |
1445 if (!dw->setup_point) dw->setup_point = dw->list; | |
1446 | |
1447 while (dw->setup_point) | |
1448 { | |
1449 DupeItem *di = dw->setup_point->data; | |
1450 | |
1451 dw->setup_point = dupe_setup_point_step(dw, dw->setup_point); | |
1452 dw->setup_n++; | |
1453 if (di->width == 0 && di->height == 0) | |
1454 { | |
1455 dupe_window_update_progress(dw, _("Reading dimensions..."), | |
1456 dw->setup_count == 0 ? 0.0 : (gdouble)(dw->setup_n - 1) / dw->setup_count, FALSE); | |
1457 | |
1458 if (enable_thumb_caching) | |
1459 { | |
1460 dupe_item_read_cache(di); | |
1461 if (di->width != 0 || di->height != 0) return TRUE; | |
1462 } | |
1463 | |
1464 image_load_dimensions(di->path, &di->width, &di->height); | |
1465 if (enable_thumb_caching) | |
1466 { | |
1467 dupe_item_write_cache(di); | |
1468 } | |
1469 return TRUE; | |
1470 } | |
1471 } | |
1472 dw->setup_mask |= DUPE_MATCH_DIM; | |
1473 dupe_setup_reset(dw); | |
1474 } | |
1475 if ((dw->match_mask & DUPE_MATCH_SIM_HIGH || | |
1476 dw->match_mask & DUPE_MATCH_SIM_MED || | |
1477 dw->match_mask & DUPE_MATCH_SIM_LOW || | |
1478 dw->match_mask & DUPE_MATCH_SIM_CUSTOM) && | |
1479 !(dw->setup_mask & DUPE_MATCH_SIM_MED) ) | |
1480 { | |
1481 if (!dw->setup_point) dw->setup_point = dw->list; | |
1482 | |
1483 while (dw->setup_point) | |
1484 { | |
1485 DupeItem *di = dw->setup_point->data; | |
1486 | |
1487 if (!di->simd) | |
1488 { | |
1489 dupe_window_update_progress(dw, _("Reading similarity data..."), | |
1490 dw->setup_count == 0 ? 0.0 : (gdouble)dw->setup_n / dw->setup_count, FALSE); | |
1491 | |
1492 if (enable_thumb_caching) | |
1493 { | |
1494 dupe_item_read_cache(di); | |
1495 if (cache_sim_data_filled(di->simd)) | |
1496 { | |
1497 image_sim_alternate_processing(di->simd); | |
1498 return TRUE; | |
1499 } | |
1500 } | |
1501 | |
1502 dw->img_loader = image_loader_new(di->path); | |
1503 image_loader_set_buffer_size(dw->img_loader, 8); | |
1504 image_loader_set_error_func(dw->img_loader, dupe_loader_done_cb, dw); | |
1505 | |
1506 if (!image_loader_start(dw->img_loader, dupe_loader_done_cb, dw)) | |
1507 { | |
1508 image_sim_free(di->simd); | |
1509 di->simd = image_sim_new(); | |
1510 image_loader_free(dw->img_loader); | |
1511 dw->img_loader = NULL; | |
1512 return TRUE; | |
1513 } | |
1514 dw->idle_id = -1; | |
1515 return FALSE; | |
1516 } | |
1517 | |
1518 dw->setup_point = dupe_setup_point_step(dw, dw->setup_point); | |
1519 dw->setup_n++; | |
1520 } | |
1521 dw->setup_mask |= DUPE_MATCH_SIM_MED; | |
1522 dupe_setup_reset(dw); | |
1523 } | |
1524 dupe_window_update_progress(dw, _("Comparing..."), 0.0, FALSE); | |
1525 dw->setup_done = TRUE; | |
1526 dupe_setup_reset(dw); | |
1527 dw->setup_count = g_list_length(dw->list); | |
1528 } | |
1529 | |
1530 if (!dw->working) | |
1531 { | |
1532 if (dw->setup_count > 0) | |
1533 { | |
1534 dw->setup_count = 0; | |
1535 dupe_window_update_progress(dw, _("Sorting..."), 1.0, TRUE); | |
1536 return TRUE; | |
1537 } | |
1538 dw->idle_id = -1; | |
1539 dupe_window_update_progress(dw, NULL, 0.0, FALSE); | |
1540 | |
1541 dupe_match_rank(dw); | |
1542 dupe_window_update_count(dw, FALSE); | |
1543 | |
1544 dupe_listview_populate(dw); | |
1545 | |
1546 /* check thumbs */ | |
1547 if (dw->show_thumbs) dupe_thumb_step(dw); | |
1548 | |
1549 widget_set_cursor(dw->listview, -1); | |
1550 | |
1551 return FALSE; | |
1552 } | |
1553 | |
1554 dupe_list_check_match(dw, (DupeItem *)dw->working->data, dw->working); | |
1555 dupe_window_update_progress(dw, _("Comparing..."), dw->setup_count == 0 ? 0.0 : (gdouble) dw->setup_n / dw->setup_count, FALSE); | |
1556 dw->setup_n++; | |
1557 | |
1558 dw->working = dw->working->prev; | |
1559 | |
1560 return TRUE; | |
1561 } | |
1562 | |
1563 static void dupe_check_start(DupeWindow *dw) | |
1564 { | |
1565 dw->setup_done = FALSE; | |
1566 | |
1567 dw->setup_count = g_list_length(dw->list); | |
1568 if (dw->second_set) dw->setup_count += g_list_length(dw->second_list); | |
1569 | |
1570 dw->setup_mask = 0; | |
1571 dupe_setup_reset(dw); | |
1572 | |
1573 dw->working = g_list_last(dw->list); | |
1574 | |
1575 dupe_window_update_count(dw, TRUE); | |
1576 widget_set_cursor(dw->listview, GDK_WATCH); | |
1577 | |
1578 if (dw->idle_id != -1) return; | |
1579 | |
1580 dw->idle_id = g_idle_add(dupe_check_cb, dw); | |
1581 } | |
1582 | |
1583 /* | |
1584 * ------------------------------------------------------------------ | |
1585 * Item addition, removal | |
1586 * ------------------------------------------------------------------ | |
1587 */ | |
1588 | |
1589 static void dupe_item_remove(DupeWindow *dw, DupeItem *di) | |
1590 { | |
1591 if (!di) return; | |
1592 | |
1593 /* handle things that may be in progress... */ | |
1594 if (dw->working && dw->working->data == di) | |
1595 { | |
1596 dw->working = dw->working->prev; | |
1597 } | |
1598 if (dw->thumb_loader && dw->thumb_item == di) | |
1599 { | |
1600 dupe_thumb_step(dw); | |
1601 } | |
1602 if (dw->setup_point && dw->setup_point->data == di) | |
1603 { | |
1604 dw->setup_point = dupe_setup_point_step(dw, dw->setup_point); | |
1605 if (dw->img_loader) | |
1606 { | |
1607 image_loader_free(dw->img_loader); | |
1608 dw->img_loader = NULL; | |
1609 dw->idle_id = g_idle_add(dupe_check_cb, dw); | |
1610 } | |
1611 } | |
1612 | |
1613 if (di->group && dw->dupes) | |
1614 { | |
1615 /* is a dupe, must remove from group/reset children if a parent */ | |
1616 DupeItem *parent; | |
1617 | |
1618 parent = dupe_match_find_parent(dw, di); | |
1619 if (di == parent) | |
1620 { | |
1621 if (g_list_length(parent->group) < 2) | |
1622 { | |
1623 DupeItem *child; | |
1624 | |
1625 child = dupe_match_highest_rank(parent); | |
1626 dupe_match_link_clear(child, TRUE); | |
1627 dupe_listview_remove(dw, child); | |
1628 | |
1629 dupe_match_link_clear(parent, TRUE); | |
1630 dupe_listview_remove(dw, parent); | |
1631 dw->dupes = g_list_remove(dw->dupes, parent); | |
1632 } | |
1633 else | |
1634 { | |
1635 DupeItem *new_parent; | |
1636 DupeMatch *dm; | |
1637 | |
1638 dm = parent->group->data; | |
1639 new_parent = dm->di; | |
1640 dupe_match_reparent(dw, parent, new_parent); | |
1641 dupe_listview_remove(dw, parent); | |
1642 } | |
1643 } | |
1644 else | |
1645 { | |
1646 if (g_list_length(parent->group) < 2) | |
1647 { | |
1648 dupe_match_link_clear(parent, TRUE); | |
1649 dupe_listview_remove(dw, parent); | |
1650 dw->dupes = g_list_remove(dw->dupes, parent); | |
1651 } | |
1652 dupe_match_link_clear(di, TRUE); | |
1653 dupe_listview_remove(dw, di); | |
1654 } | |
1655 } | |
1656 else | |
1657 { | |
1658 /* not a dupe, or not sorted yet, simply reset */ | |
1659 dupe_match_link_clear(di, TRUE); | |
1660 } | |
1661 | |
1662 if (dw->second_list && g_list_find(dw->second_list, di)) | |
1663 { | |
1664 dupe_second_remove(dw, di); | |
1665 } | |
1666 else | |
1667 { | |
1668 dw->list = g_list_remove(dw->list, di); | |
1669 } | |
1670 dupe_item_free(di); | |
1671 | |
1672 dupe_window_update_count(dw, FALSE); | |
1673 } | |
1674 | |
1675 static gint dupe_item_remove_by_path(DupeWindow *dw, const gchar *path) | |
1676 { | |
1677 DupeItem *di; | |
1678 | |
1679 di = dupe_item_find_path(dw, path); | |
1680 if (!di) return FALSE; | |
1681 | |
1682 dupe_item_remove(dw, di); | |
1683 | |
1684 return TRUE; | |
1685 } | |
1686 | |
1687 static void dupe_files_add(DupeWindow *dw, CollectionData *collection, CollectInfo *info, | |
1688 const gchar *path, gint recurse) | |
1689 { | |
1690 DupeItem *di = NULL; | |
1691 | |
1692 if (info) | |
1693 { | |
1694 di = dupe_item_new(info->path, info->size, info->date); | |
1695 } | |
1696 else if (path) | |
1697 { | |
1698 if (isfile(path)) | |
1699 { | |
1700 di = dupe_item_new(path, filesize(path), filetime(path)); | |
1701 } | |
1702 else if (isdir(path) && recurse) | |
1703 { | |
1704 GList *f, *d; | |
1705 if (path_list(path, &f, &d)) | |
1706 { | |
1707 GList *work; | |
1708 | |
1709 f = path_list_filter(f, FALSE); | |
1710 d = path_list_filter(d, TRUE); | |
1711 | |
1712 work = f; | |
1713 while(work) | |
1714 { | |
1715 dupe_files_add(dw, NULL, NULL, (gchar *)work->data, TRUE); | |
1716 work = work->next; | |
1717 } | |
1718 path_list_free(f); | |
1719 work = d; | |
1720 while(work) | |
1721 { | |
1722 dupe_files_add(dw, NULL, NULL, (gchar *)work->data, TRUE); | |
1723 work = work->next; | |
1724 } | |
1725 path_list_free(d); | |
1726 } | |
1727 } | |
1728 } | |
1729 | |
1730 if (!di) return; | |
1731 | |
1732 if (dw->second_drop) | |
1733 { | |
1734 dupe_second_add(dw, di); | |
1735 } | |
1736 else | |
1737 { | |
1738 dw->list = g_list_prepend(dw->list, di); | |
1739 } | |
1740 } | |
1741 | |
1742 void dupe_window_add_collection(DupeWindow *dw, CollectionData *collection) | |
1743 { | |
1744 CollectInfo *info; | |
1745 | |
1746 info = collection_get_first(collection); | |
1747 while(info) | |
1748 { | |
1749 dupe_files_add(dw, collection, info, NULL, FALSE); | |
1750 info = collection_next_by_info(collection, info); | |
1751 } | |
1752 | |
1753 dupe_check_start(dw); | |
1754 } | |
1755 | |
1756 void dupe_window_add_files(DupeWindow *dw, GList *list, gint recurse) | |
1757 { | |
1758 GList *work; | |
1759 | |
1760 work = list; | |
1761 while(work) | |
1762 { | |
1763 gchar *path = work->data; | |
1764 work = work->next; | |
1765 | |
1766 dupe_files_add(dw, NULL, NULL, path, recurse); | |
1767 } | |
1768 | |
1769 dupe_check_start(dw); | |
1770 } | |
1771 | |
1772 static gint dupe_item_set_path(DupeWindow *dw, const gchar *source, const gchar *dest) | |
1773 { | |
1774 DupeItem *di; | |
1775 | |
1776 di = dupe_item_find_path(dw, source); | |
1777 if (!di) return FALSE; | |
1778 | |
1779 if ( (dw->match_mask & DUPE_MATCH_NAME) || (dw->match_mask & DUPE_MATCH_PATH) ) | |
1780 { | |
1781 /* only effects matches on name or path */ | |
1782 gint second; | |
1783 | |
1784 second = di->second; | |
1785 dupe_item_remove(dw, di); | |
1786 | |
1787 dw->second_drop = second; | |
1788 dupe_files_add(dw, NULL, NULL, dest, FALSE); | |
1789 dw->second_drop = FALSE; | |
1790 | |
1791 dupe_check_start(dw); | |
1792 } | |
1793 else | |
1794 { | |
1795 GtkListStore *store; | |
1796 GtkTreeIter iter; | |
1797 gint row; | |
1798 | |
1799 g_free(di->path); | |
1800 di->path = g_strdup(dest); | |
1801 di->name = filename_from_path(di->path); | |
1802 | |
1803 /* update the listview(s) */ | |
1804 | |
1805 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dw->listview))); | |
1806 row = dupe_listview_find_item(store, di, &iter); | |
1807 if (row >= 0) | |
1808 { | |
1809 gtk_list_store_set(store, &iter, | |
1810 DUPE_COLUMN_NAME, di->name, | |
1811 DUPE_COLUMN_PATH, di->path, -1); | |
1812 } | |
1813 | |
1814 if (dw->second_listview) | |
1815 { | |
1816 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dw->second_listview))); | |
1817 row = dupe_listview_find_item(store, di, &iter); | |
1818 if (row >= 0) | |
1819 { | |
1820 gtk_list_store_set(store, &iter, 1, di->path, -1); | |
1821 } | |
1822 } | |
1823 } | |
1824 | |
1825 return TRUE; | |
1826 } | |
1827 | |
1828 /* | |
1829 * ------------------------------------------------------------------ | |
1830 * Misc. | |
1831 * ------------------------------------------------------------------ | |
1832 */ | |
1833 | |
1834 static GtkWidget *dupe_display_label(GtkWidget *vbox, const gchar *description, const gchar *text) | |
1835 { | |
1836 GtkWidget *hbox; | |
1837 GtkWidget *label; | |
1838 | |
1839 hbox = gtk_hbox_new(FALSE, 10); | |
1840 | |
1841 label = gtk_label_new(description); | |
1842 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
1843 gtk_widget_show(label); | |
1844 | |
1845 label = gtk_label_new(text); | |
1846 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
1847 gtk_widget_show(label); | |
1848 | |
1849 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
1850 gtk_widget_show(hbox); | |
1851 | |
1852 return label; | |
1853 } | |
1854 | |
1855 static void dupe_display_stats(DupeWindow *dw, DupeItem *di) | |
1856 { | |
1857 GenericDialog *gd; | |
1858 gchar *buf; | |
1859 | |
1860 if (!di) return; | |
1861 | |
1862 gd = file_util_gen_dlg("Image thumbprint debug info", "GQview", "thumbprint", | |
1863 dw->window, TRUE, | |
1864 NULL, NULL); | |
1865 generic_dialog_add_button(gd, GTK_STOCK_CLOSE, NULL, NULL, TRUE); | |
1866 | |
1867 dupe_display_label(gd->vbox, "name:", di->name); | |
1868 buf = text_from_size(di->size); | |
1869 dupe_display_label(gd->vbox, "size:", buf); | |
1870 g_free(buf); | |
1871 dupe_display_label(gd->vbox, "date:", text_from_time(di->date)); | |
1872 buf = g_strdup_printf("%d x %d", di->width, di->height); | |
1873 dupe_display_label(gd->vbox, "dimensions:", buf); | |
1874 g_free(buf); | |
1875 dupe_display_label(gd->vbox, "md5sum:", (di->md5sum) ? di->md5sum : "not generated"); | |
1876 | |
1877 dupe_display_label(gd->vbox, "thumbprint:", (di->simd) ? "" : "not generated"); | |
1878 if (di->simd) | |
1879 { | |
1880 GtkWidget *image; | |
1881 GdkPixbuf *pixbuf; | |
1882 gint x, y; | |
1883 guchar *d_pix; | |
1884 guchar *dp; | |
1885 gint rs; | |
1886 gint sp; | |
1887 | |
1888 pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, 32, 32); | |
1889 rs = gdk_pixbuf_get_rowstride(pixbuf); | |
1890 d_pix = gdk_pixbuf_get_pixels(pixbuf); | |
1891 | |
1892 for (y = 0; y < 32; y++) | |
1893 { | |
1894 dp = d_pix + (y * rs); | |
1895 sp = y * 32; | |
1896 for (x = 0; x < 32; x++) | |
1897 { | |
1898 *(dp++) = di->simd->avg_r[sp + x]; | |
1899 *(dp++) = di->simd->avg_g[sp + x]; | |
1900 *(dp++) = di->simd->avg_b[sp + x]; | |
1901 } | |
1902 } | |
1903 | |
1904 image = gtk_image_new_from_pixbuf(pixbuf); | |
1905 gtk_box_pack_start(GTK_BOX(gd->vbox), image, FALSE, FALSE, 0); | |
1906 gtk_widget_show(image); | |
1907 | |
1908 gdk_pixbuf_unref(pixbuf); | |
1909 } | |
1910 | |
1911 gtk_widget_show(gd->dialog); | |
1912 } | |
1913 | |
1914 static void dupe_window_recompare(DupeWindow *dw) | |
1915 { | |
1916 GtkListStore *store; | |
1917 | |
1918 dupe_check_stop(dw); | |
1919 | |
1920 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dw->listview))); | |
1921 gtk_list_store_clear(store); | |
1922 | |
1923 g_list_free(dw->dupes); | |
1924 dw->dupes = NULL; | |
1925 | |
1926 dupe_match_reset_list(dw->list); | |
1927 dupe_match_reset_list(dw->second_list); | |
1928 | |
1929 dupe_check_start(dw); | |
1930 } | |
1931 | |
1932 static void dupe_menu_view(DupeWindow *dw, DupeItem *di, GtkWidget *listview, gint new_window) | |
1933 { | |
1934 if (!di) return; | |
1935 | |
1936 if (di->collection && collection_info_valid(di->collection, di->info)) | |
1937 { | |
1938 if (new_window) | |
1939 { | |
1940 view_window_new_from_collection(di->collection, di->info); | |
1941 } | |
1942 else | |
1943 { | |
1944 layout_image_set_collection(NULL, di->collection, di->info); | |
1945 } | |
1946 } | |
1947 else | |
1948 { | |
1949 if (new_window) | |
1950 { | |
1951 GList *list; | |
1952 | |
1953 list = dupe_listview_get_selection(dw, listview); | |
1954 view_window_new_from_list(list); | |
1955 path_list_free(list); | |
1956 } | |
1957 else | |
1958 { | |
1959 layout_image_set_path(NULL, di->path); | |
1960 } | |
1961 } | |
1962 } | |
1963 | |
1964 static void dupe_window_remove_selection(DupeWindow *dw, GtkWidget *listview) | |
1965 { | |
1966 GtkTreeSelection *selection; | |
1967 GtkTreeModel *store; | |
1968 GtkTreeIter iter; | |
1969 GList *slist; | |
1970 GList *list = NULL; | |
1971 GList *work; | |
1972 | |
1973 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(listview)); | |
1974 slist = gtk_tree_selection_get_selected_rows(selection, &store); | |
1975 work = slist; | |
1976 while (work) | |
1977 { | |
1978 GtkTreePath *tpath = work->data; | |
1979 DupeItem *di = NULL; | |
1980 | |
1981 gtk_tree_model_get_iter(store, &iter, tpath); | |
1982 gtk_tree_model_get(store, &iter, DUPE_COLUMN_POINTER, &di, -1); | |
1983 if (di) list = g_list_prepend(list, di); | |
1984 work = work->next; | |
1985 } | |
1986 g_list_foreach(slist, (GFunc)gtk_tree_path_free, NULL); | |
1987 g_list_free(slist); | |
1988 | |
1989 dw->color_frozen = TRUE; | |
1990 work = list; | |
1991 while (work) | |
1992 { | |
1993 DupeItem *di; | |
1994 | |
1995 di = work->data; | |
1996 work = work->next; | |
1997 dupe_item_remove(dw, di); | |
1998 } | |
1999 dw->color_frozen = FALSE; | |
2000 | |
2001 g_list_free(list); | |
2002 | |
2003 dupe_listview_realign_colors(dw); | |
2004 } | |
2005 | |
2006 static void dupe_window_edit_selected(DupeWindow *dw, gint n) | |
2007 { | |
2008 GList *list; | |
2009 | |
2010 list = dupe_listview_get_selection(dw, dw->listview); | |
2011 | |
2012 start_editor_from_path_list(n, list); | |
2013 | |
2014 path_list_free(list); | |
2015 } | |
2016 | |
2017 static void dupe_window_collection_from_selection(DupeWindow *dw) | |
2018 { | |
2019 CollectWindow *w; | |
2020 GList *list; | |
2021 | |
2022 list = dupe_listview_get_selection(dw, dw->listview); | |
2023 w = collection_window_new(NULL); | |
2024 collection_table_add_path_list(w->table, list); | |
2025 path_list_free(list); | |
2026 } | |
2027 | |
2028 static void dupe_window_append_file_list(DupeWindow *dw, gint on_second) | |
2029 { | |
2030 GList *list; | |
2031 | |
2032 dw->second_drop = (dw->second_set && on_second); | |
2033 | |
2034 list = layout_list(NULL); | |
2035 dupe_window_add_files(dw, list, FALSE); | |
2036 path_list_free(list); | |
2037 } | |
2038 | |
2039 /* | |
2040 *------------------------------------------------------------------- | |
2041 * main pop-up menu callbacks | |
2042 *------------------------------------------------------------------- | |
2043 */ | |
2044 | |
2045 static void dupe_menu_view_cb(GtkWidget *widget, gpointer data) | |
2046 { | |
2047 DupeWindow *dw = data; | |
2048 | |
2049 if (dw->click_item) dupe_menu_view(dw, dw->click_item, dw->listview, FALSE); | |
2050 } | |
2051 | |
2052 static void dupe_menu_viewnew_cb(GtkWidget *widget, gpointer data) | |
2053 { | |
2054 DupeWindow *dw = data; | |
2055 | |
2056 if (dw->click_item) dupe_menu_view(dw, dw->click_item, dw->listview, TRUE); | |
2057 } | |
2058 | |
2059 static void dupe_menu_select_all_cb(GtkWidget *widget, gpointer data) | |
2060 { | |
2061 DupeWindow *dw = data; | |
2062 GtkTreeSelection *selection; | |
2063 | |
2064 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dw->listview)); | |
2065 gtk_tree_selection_select_all(selection); | |
2066 } | |
2067 | |
2068 static void dupe_menu_select_none_cb(GtkWidget *widget, gpointer data) | |
2069 { | |
2070 DupeWindow *dw = data; | |
2071 GtkTreeSelection *selection; | |
2072 | |
2073 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dw->listview)); | |
2074 gtk_tree_selection_unselect_all(selection); | |
2075 } | |
2076 | |
2077 static void dupe_menu_select_dupes_set1_cb(GtkWidget *widget, gpointer data) | |
2078 { | |
2079 DupeWindow *dw = data; | |
2080 | |
2081 dupe_listview_select_dupes(dw, TRUE); | |
2082 } | |
2083 | |
2084 static void dupe_menu_select_dupes_set2_cb(GtkWidget *widget, gpointer data) | |
2085 { | |
2086 DupeWindow *dw = data; | |
2087 | |
2088 dupe_listview_select_dupes(dw, FALSE); | |
2089 } | |
2090 | |
2091 static void dupe_menu_edit_cb(GtkWidget *widget, gpointer data) | |
2092 { | |
2093 DupeWindow *dw; | |
2094 gint n; | |
2095 | |
2096 dw = submenu_item_get_data(widget); | |
2097 n = GPOINTER_TO_INT(data); | |
2098 if (!dw) return; | |
2099 | |
2100 dupe_window_edit_selected(dw, n); | |
2101 } | |
2102 | |
2103 static void dupe_menu_info_cb(GtkWidget *widget, gpointer data) | |
2104 { | |
2105 DupeWindow *dw = data; | |
2106 | |
2107 info_window_new(NULL, dupe_listview_get_selection(dw, dw->listview)); | |
2108 } | |
2109 | |
2110 static void dupe_menu_collection_cb(GtkWidget *widget, gpointer data) | |
2111 { | |
2112 DupeWindow *dw = data; | |
2113 | |
2114 dupe_window_collection_from_selection(dw); | |
2115 } | |
2116 | |
2117 static void dupe_menu_print_cb(GtkWidget *widget, gpointer data) | |
2118 { | |
2119 DupeWindow *dw = data; | |
2120 const gchar *path; | |
2121 | |
2122 path = (dw->click_item) ? dw->click_item->path : NULL; | |
2123 | |
2124 print_window_new(path, | |
2125 dupe_listview_get_selection(dw, dw->listview), | |
2126 dupe_listview_get_path_list(dw, dw->listview), dw->window); | |
2127 } | |
2128 | |
2129 static void dupe_menu_copy_cb(GtkWidget *widget, gpointer data) | |
2130 { | |
2131 DupeWindow *dw = data; | |
2132 | |
2133 file_util_copy(NULL, dupe_listview_get_selection(dw, dw->listview), NULL, dw->window); | |
2134 } | |
2135 | |
2136 static void dupe_menu_move_cb(GtkWidget *widget, gpointer data) | |
2137 { | |
2138 DupeWindow *dw = data; | |
2139 | |
2140 file_util_move(NULL, dupe_listview_get_selection(dw, dw->listview), NULL, dw->window); | |
2141 } | |
2142 | |
2143 static void dupe_menu_rename_cb(GtkWidget *widget, gpointer data) | |
2144 { | |
2145 DupeWindow *dw = data; | |
2146 | |
2147 file_util_rename(NULL, dupe_listview_get_selection(dw, dw->listview), dw->window); | |
2148 } | |
2149 | |
2150 static void dupe_menu_delete_cb(GtkWidget *widget, gpointer data) | |
2151 { | |
2152 DupeWindow *dw = data; | |
2153 | |
2154 file_util_delete(NULL, dupe_listview_get_selection(dw, dw->listview), dw->window); | |
2155 } | |
2156 | |
2157 static void dupe_menu_remove_cb(GtkWidget *widget, gpointer data) | |
2158 { | |
2159 DupeWindow *dw = data; | |
2160 | |
2161 dupe_window_remove_selection(dw, dw->listview); | |
2162 } | |
2163 | |
2164 static void dupe_menu_clear_cb(GtkWidget *widget, gpointer data) | |
2165 { | |
2166 DupeWindow *dw = data; | |
2167 | |
2168 dupe_window_clear(dw); | |
2169 } | |
2170 | |
2171 static void dupe_menu_close_cb(GtkWidget *widget, gpointer data) | |
2172 { | |
2173 DupeWindow *dw = data; | |
2174 | |
2175 dupe_window_close(dw); | |
2176 } | |
2177 | |
2178 static GtkWidget *dupe_menu_popup_main(DupeWindow *dw, DupeItem *di) | |
2179 { | |
2180 GtkWidget *menu; | |
2181 GtkWidget *item; | |
2182 gint on_row; | |
2183 | |
2184 on_row = (di != NULL); | |
2185 | |
2186 menu = popup_menu_short_lived(); | |
2187 menu_item_add_sensitive(menu, _("_View"), on_row, | |
2188 G_CALLBACK(dupe_menu_view_cb), dw); | |
2189 menu_item_add_stock_sensitive(menu, _("View in _new window"), GTK_STOCK_NEW, on_row, | |
2190 G_CALLBACK(dupe_menu_viewnew_cb), dw); | |
2191 menu_item_add_divider(menu); | |
2192 menu_item_add_sensitive(menu, _("Select all"), (dw->dupes != NULL), | |
2193 G_CALLBACK(dupe_menu_select_all_cb), dw); | |
2194 menu_item_add_sensitive(menu, _("Select none"), (dw->dupes != NULL), | |
2195 G_CALLBACK(dupe_menu_select_none_cb), dw); | |
2196 menu_item_add_sensitive(menu, _("Select group _1 duplicates"), (dw->dupes != NULL), | |
2197 G_CALLBACK(dupe_menu_select_dupes_set1_cb), dw); | |
2198 menu_item_add_sensitive(menu, _("Select group _2 duplicates"), (dw->dupes != NULL), | |
2199 G_CALLBACK(dupe_menu_select_dupes_set2_cb), dw); | |
2200 menu_item_add_divider(menu); | |
2201 submenu_add_edit(menu, &item, G_CALLBACK(dupe_menu_edit_cb), dw); | |
2202 if (!on_row) gtk_widget_set_sensitive(item, FALSE); | |
2203 menu_item_add_stock_sensitive(menu, _("_Properties"), GTK_STOCK_PROPERTIES, on_row, | |
2204 G_CALLBACK(dupe_menu_info_cb), dw); | |
2205 menu_item_add_stock_sensitive(menu, _("Add to new collection"), GTK_STOCK_INDEX, on_row, | |
2206 G_CALLBACK(dupe_menu_collection_cb), dw); | |
2207 menu_item_add_stock_sensitive(menu, _("Print..."), GTK_STOCK_PRINT, on_row, | |
2208 G_CALLBACK(dupe_menu_print_cb), dw); | |
2209 menu_item_add_divider(menu); | |
2210 menu_item_add_stock_sensitive(menu, _("_Copy..."), GTK_STOCK_COPY, on_row, | |
2211 G_CALLBACK(dupe_menu_copy_cb), dw); | |
2212 menu_item_add_sensitive(menu, _("_Move..."), on_row, | |
2213 G_CALLBACK(dupe_menu_move_cb), dw); | |
2214 menu_item_add_sensitive(menu, _("_Rename..."), on_row, | |
2215 G_CALLBACK(dupe_menu_rename_cb), dw); | |
2216 menu_item_add_stock_sensitive(menu, _("_Delete..."), GTK_STOCK_DELETE, on_row, | |
2217 G_CALLBACK(dupe_menu_delete_cb), dw); | |
2218 menu_item_add_divider(menu); | |
2219 menu_item_add_stock_sensitive(menu, _("Rem_ove"), GTK_STOCK_REMOVE, on_row, | |
2220 G_CALLBACK(dupe_menu_remove_cb), dw); | |
2221 menu_item_add_stock_sensitive(menu, _("C_lear"), GTK_STOCK_CLEAR, (dw->list != NULL), | |
2222 G_CALLBACK(dupe_menu_clear_cb), dw); | |
2223 menu_item_add_divider(menu); | |
2224 menu_item_add_stock(menu, _("Close _window"), GTK_STOCK_CLOSE, | |
2225 G_CALLBACK(dupe_menu_close_cb), dw); | |
2226 | |
2227 return menu; | |
2228 } | |
2229 | |
2230 static gint dupe_listview_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data) | |
2231 { | |
2232 DupeWindow *dw = data; | |
2233 GtkTreeModel *store; | |
2234 GtkTreePath *tpath; | |
2235 GtkTreeIter iter; | |
2236 DupeItem *di = NULL; | |
2237 | |
2238 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | |
2239 | |
2240 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bevent->x, bevent->y, | |
2241 &tpath, NULL, NULL, NULL)) | |
2242 { | |
2243 gtk_tree_model_get_iter(store, &iter, tpath); | |
2244 gtk_tree_model_get(store, &iter, DUPE_COLUMN_POINTER, &di, -1); | |
2245 gtk_tree_path_free(tpath); | |
2246 } | |
2247 | |
2248 dw->click_item = di; | |
2249 | |
2250 if (bevent->button == 3) | |
2251 { | |
2252 /* right click menu */ | |
2253 GtkWidget *menu; | |
2254 | |
2255 if (bevent->state & GDK_CONTROL_MASK && bevent->state & GDK_SHIFT_MASK) | |
2256 { | |
2257 dupe_display_stats(dw, di); | |
2258 return TRUE; | |
2259 } | |
2260 if (widget == dw->listview) | |
2261 { | |
2262 menu = dupe_menu_popup_main(dw, di); | |
2263 } | |
2264 else | |
2265 { | |
2266 menu = dupe_menu_popup_second(dw, di); | |
2267 } | |
2268 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, bevent->button, bevent->time); | |
2269 } | |
2270 | |
2271 if (!di) return FALSE; | |
2272 | |
2273 if (bevent->button == 1 && bevent->type == GDK_2BUTTON_PRESS) | |
2274 { | |
2275 dupe_menu_view(dw, di, widget, FALSE); | |
2276 } | |
2277 | |
2278 if (bevent->button == 2) return TRUE; | |
2279 | |
2280 if (bevent->button == 3) | |
2281 { | |
2282 if (!dupe_listview_item_is_selected(dw, di, widget)) | |
2283 { | |
2284 GtkTreeSelection *selection; | |
2285 | |
2286 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget)); | |
2287 gtk_tree_selection_unselect_all(selection); | |
2288 gtk_tree_selection_select_iter(selection, &iter); | |
2289 | |
2290 tpath = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter); | |
2291 gtk_tree_view_set_cursor(GTK_TREE_VIEW(widget), tpath, NULL, FALSE); | |
2292 gtk_tree_path_free(tpath); | |
2293 } | |
2294 | |
2295 return TRUE; | |
2296 } | |
2297 | |
2298 if (bevent->button == 1 && bevent->type == GDK_BUTTON_PRESS && | |
2299 !(bevent->state & GDK_SHIFT_MASK ) && | |
2300 !(bevent->state & GDK_CONTROL_MASK ) && | |
2301 dupe_listview_item_is_selected(dw, di, widget)) | |
2302 { | |
2303 /* this selection handled on release_cb */ | |
2304 gtk_widget_grab_focus(widget); | |
2305 return TRUE; | |
2306 } | |
2307 | |
2308 return FALSE; | |
2309 } | |
2310 | |
2311 static gint dupe_listview_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data) | |
2312 { | |
2313 DupeWindow *dw = data; | |
2314 GtkTreeModel *store; | |
2315 GtkTreePath *tpath; | |
2316 GtkTreeIter iter; | |
2317 DupeItem *di = NULL; | |
2318 | |
2319 if (bevent->button != 1 && bevent->button != 2) return TRUE; | |
2320 | |
2321 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | |
2322 | |
2323 if ((bevent->x != 0 || bevent->y != 0) && | |
2324 gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bevent->x, bevent->y, | |
2325 &tpath, NULL, NULL, NULL)) | |
2326 { | |
2327 gtk_tree_model_get_iter(store, &iter, tpath); | |
2328 gtk_tree_model_get(store, &iter, DUPE_COLUMN_POINTER, &di, -1); | |
2329 gtk_tree_path_free(tpath); | |
2330 } | |
2331 | |
2332 if (bevent->button == 2) | |
2333 { | |
2334 if (di && dw->click_item == di) | |
2335 { | |
2336 GtkTreeSelection *selection; | |
2337 | |
2338 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget)); | |
2339 if (dupe_listview_item_is_selected(dw, di, widget)) | |
2340 { | |
2341 gtk_tree_selection_unselect_iter(selection, &iter); | |
2342 } | |
2343 else | |
2344 { | |
2345 gtk_tree_selection_select_iter(selection, &iter); | |
2346 } | |
2347 } | |
2348 return TRUE; | |
2349 } | |
2350 | |
2351 if (di && dw->click_item == di && | |
2352 !(bevent->state & GDK_SHIFT_MASK ) && | |
2353 !(bevent->state & GDK_CONTROL_MASK ) && | |
2354 dupe_listview_item_is_selected(dw, di, widget)) | |
2355 { | |
2356 GtkTreeSelection *selection; | |
2357 | |
2358 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget)); | |
2359 gtk_tree_selection_unselect_all(selection); | |
2360 gtk_tree_selection_select_iter(selection, &iter); | |
2361 | |
2362 tpath = gtk_tree_model_get_path(store, &iter); | |
2363 gtk_tree_view_set_cursor(GTK_TREE_VIEW(widget), tpath, NULL, FALSE); | |
2364 gtk_tree_path_free(tpath); | |
2365 | |
2366 return TRUE; | |
2367 } | |
2368 | |
2369 return FALSE; | |
2370 } | |
2371 | |
2372 /* | |
2373 *------------------------------------------------------------------- | |
2374 * second set stuff | |
2375 *------------------------------------------------------------------- | |
2376 */ | |
2377 | |
2378 static void dupe_second_update_status(DupeWindow *dw) | |
2379 { | |
2380 gchar *buf; | |
2381 | |
2382 buf = g_strdup_printf(_("%d files (set 2)"), g_list_length(dw->second_list)); | |
2383 gtk_label_set_text(GTK_LABEL(dw->second_status_label), buf); | |
2384 g_free(buf); | |
2385 } | |
2386 | |
2387 static void dupe_second_add(DupeWindow *dw, DupeItem *di) | |
2388 { | |
2389 GtkListStore *store; | |
2390 GtkTreeIter iter; | |
2391 | |
2392 if (!di) return; | |
2393 | |
2394 di->second = TRUE; | |
2395 dw->second_list = g_list_prepend(dw->second_list, di); | |
2396 | |
2397 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dw->second_listview))); | |
2398 gtk_list_store_append(store, &iter); | |
2399 gtk_list_store_set(store, &iter, DUPE_COLUMN_POINTER, di, 1, di->path, -1); | |
2400 | |
2401 dupe_second_update_status(dw); | |
2402 } | |
2403 | |
2404 static void dupe_second_remove(DupeWindow *dw, DupeItem *di) | |
2405 { | |
2406 GtkListStore *store; | |
2407 GtkTreeIter iter; | |
2408 | |
2409 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dw->second_listview))); | |
2410 if (dupe_listview_find_item(store, di, &iter) >= 0) | |
2411 { | |
2412 tree_view_move_cursor_away(GTK_TREE_VIEW(dw->second_listview), &iter, TRUE); | |
2413 gtk_list_store_remove(store, &iter); | |
2414 } | |
2415 | |
2416 dw->second_list = g_list_remove(dw->second_list, di); | |
2417 | |
2418 dupe_second_update_status(dw); | |
2419 } | |
2420 | |
2421 static void dupe_second_clear(DupeWindow *dw) | |
2422 { | |
2423 GtkListStore *store; | |
2424 | |
2425 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dw->second_listview))); | |
2426 gtk_list_store_clear(store); | |
2427 gtk_tree_view_columns_autosize(GTK_TREE_VIEW(dw->second_listview)); | |
2428 | |
2429 g_list_free(dw->dupes); | |
2430 dw->dupes = NULL; | |
2431 | |
2432 dupe_list_free(dw->second_list); | |
2433 dw->second_list = NULL; | |
2434 | |
2435 dupe_match_reset_list(dw->list); | |
2436 | |
2437 dupe_second_update_status(dw); | |
2438 } | |
2439 | |
2440 static void dupe_second_menu_view_cb(GtkWidget *widget, gpointer data) | |
2441 { | |
2442 DupeWindow *dw = data; | |
2443 | |
2444 if (dw->click_item) dupe_menu_view(dw, dw->click_item, dw->second_listview, FALSE); | |
2445 } | |
2446 | |
2447 static void dupe_second_menu_viewnew_cb(GtkWidget *widget, gpointer data) | |
2448 { | |
2449 DupeWindow *dw = data; | |
2450 | |
2451 if (dw->click_item) dupe_menu_view(dw, dw->click_item, dw->second_listview, TRUE); | |
2452 } | |
2453 | |
2454 static void dupe_second_menu_select_all_cb(GtkWidget *widget, gpointer data) | |
2455 { | |
2456 GtkTreeSelection *selection; | |
2457 DupeWindow *dw = data; | |
2458 | |
2459 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dw->second_listview)); | |
2460 gtk_tree_selection_select_all(selection); | |
2461 } | |
2462 | |
2463 static void dupe_second_menu_select_none_cb(GtkWidget *widget, gpointer data) | |
2464 { | |
2465 GtkTreeSelection *selection; | |
2466 DupeWindow *dw = data; | |
2467 | |
2468 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dw->second_listview)); | |
2469 gtk_tree_selection_unselect_all(selection); | |
2470 } | |
2471 | |
2472 static void dupe_second_menu_remove_cb(GtkWidget *widget, gpointer data) | |
2473 { | |
2474 DupeWindow *dw = data; | |
2475 | |
2476 dupe_window_remove_selection(dw, dw->second_listview); | |
2477 } | |
2478 | |
2479 static void dupe_second_menu_clear_cb(GtkWidget *widget, gpointer data) | |
2480 { | |
2481 DupeWindow *dw = data; | |
2482 | |
2483 dupe_second_clear(dw); | |
2484 dupe_window_recompare(dw); | |
2485 } | |
2486 | |
2487 static GtkWidget *dupe_menu_popup_second(DupeWindow *dw, DupeItem *di) | |
2488 { | |
2489 GtkWidget *menu; | |
2490 gint notempty; | |
2491 gint on_row; | |
2492 | |
2493 on_row = (di != NULL); | |
2494 notempty = (dw->second_list != NULL); | |
2495 | |
2496 menu = popup_menu_short_lived(); | |
2497 menu_item_add_sensitive(menu, _("_View"), on_row, | |
2498 G_CALLBACK(dupe_second_menu_view_cb), dw); | |
2499 menu_item_add_stock_sensitive(menu, _("View in _new window"), GTK_STOCK_NEW, on_row, | |
2500 G_CALLBACK(dupe_second_menu_viewnew_cb), dw); | |
2501 menu_item_add_divider(menu); | |
2502 menu_item_add_sensitive(menu, _("Select all"), notempty, | |
2503 G_CALLBACK(dupe_second_menu_select_all_cb), dw); | |
2504 menu_item_add_sensitive(menu, _("Select none"), notempty, | |
2505 G_CALLBACK(dupe_second_menu_select_none_cb), dw); | |
2506 menu_item_add_divider(menu); | |
2507 menu_item_add_stock_sensitive(menu, _("Rem_ove"), GTK_STOCK_REMOVE, on_row, | |
2508 G_CALLBACK(dupe_second_menu_remove_cb), dw); | |
2509 menu_item_add_stock_sensitive(menu, _("C_lear"), GTK_STOCK_CLEAR, notempty, | |
2510 G_CALLBACK(dupe_second_menu_clear_cb), dw); | |
2511 menu_item_add_divider(menu); | |
2512 menu_item_add_stock(menu, _("Close _window"), GTK_STOCK_CLOSE, | |
2513 G_CALLBACK(dupe_menu_close_cb), dw); | |
2514 | |
2515 return menu; | |
2516 } | |
2517 | |
2518 static void dupe_second_set_toggle_cb(GtkWidget *widget, gpointer data) | |
2519 { | |
2520 DupeWindow *dw = data; | |
2521 | |
2522 dw->second_set = GTK_TOGGLE_BUTTON(widget)->active; | |
2523 | |
2524 if (dw->second_set) | |
2525 { | |
2526 dupe_second_update_status(dw); | |
2527 gtk_table_set_col_spacings(GTK_TABLE(dw->table), PREF_PAD_GAP); | |
2528 gtk_widget_show(dw->second_vbox); | |
2529 } | |
2530 else | |
2531 { | |
2532 gtk_table_set_col_spacings(GTK_TABLE(dw->table), 0); | |
2533 gtk_widget_hide(dw->second_vbox); | |
2534 dupe_second_clear(dw); | |
2535 } | |
2536 | |
2537 dupe_window_recompare(dw); | |
2538 } | |
2539 | |
2540 /* | |
2541 *------------------------------------------------------------------- | |
2542 * match type menu | |
2543 *------------------------------------------------------------------- | |
2544 */ | |
2545 | |
2546 enum { | |
2547 DUPE_MENU_COLUMN_NAME = 0, | |
2548 DUPE_MENU_COLUMN_MASK | |
2549 }; | |
2550 | |
2551 static void dupe_menu_type_cb(GtkWidget *combo, gpointer data) | |
2552 { | |
2553 DupeWindow *dw = data; | |
2554 GtkTreeModel *store; | |
2555 GtkTreeIter iter; | |
2556 | |
2557 store = gtk_combo_box_get_model(GTK_COMBO_BOX(combo)); | |
2558 if (!gtk_combo_box_get_active_iter(GTK_COMBO_BOX(combo), &iter)) return; | |
2559 gtk_tree_model_get(store, &iter, DUPE_MENU_COLUMN_MASK, &dw->match_mask, -1); | |
2560 | |
2561 dupe_window_recompare(dw); | |
2562 } | |
2563 | |
2564 static void dupe_menu_add_item(GtkListStore *store, const gchar *text, DupeMatchType type, DupeWindow *dw) | |
2565 { | |
2566 GtkTreeIter iter; | |
2567 | |
2568 gtk_list_store_append(store, &iter); | |
2569 gtk_list_store_set(store, &iter, DUPE_MENU_COLUMN_NAME, text, | |
2570 DUPE_MENU_COLUMN_MASK, type, -1); | |
2571 | |
2572 if (dw->match_mask == type) gtk_combo_box_set_active_iter(GTK_COMBO_BOX(dw->combo), &iter); | |
2573 } | |
2574 | |
2575 static void dupe_menu_setup(DupeWindow *dw) | |
2576 { | |
2577 GtkListStore *store; | |
2578 GtkCellRenderer *renderer; | |
2579 | |
2580 store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INT); | |
2581 dw->combo = gtk_combo_box_new_with_model(GTK_TREE_MODEL(store)); | |
2582 g_object_unref(store); | |
2583 | |
2584 renderer = gtk_cell_renderer_text_new(); | |
2585 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(dw->combo), renderer, TRUE); | |
2586 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(dw->combo), renderer, | |
2587 "text", DUPE_MENU_COLUMN_NAME, NULL); | |
2588 | |
2589 dupe_menu_add_item(store, _("Name"), DUPE_MATCH_NAME, dw); | |
2590 dupe_menu_add_item(store, _("Size"), DUPE_MATCH_SIZE, dw); | |
2591 dupe_menu_add_item(store, _("Date"), DUPE_MATCH_DATE, dw); | |
2592 dupe_menu_add_item(store, _("Dimensions"), DUPE_MATCH_DIM, dw); | |
2593 dupe_menu_add_item(store, _("Checksum"), DUPE_MATCH_SUM, dw); | |
2594 dupe_menu_add_item(store, _("Path"), DUPE_MATCH_PATH, dw); | |
2595 dupe_menu_add_item(store, _("Similarity (high)"), DUPE_MATCH_SIM_HIGH, dw); | |
2596 dupe_menu_add_item(store, _("Similarity"), DUPE_MATCH_SIM_MED, dw); | |
2597 dupe_menu_add_item(store, _("Similarity (low)"), DUPE_MATCH_SIM_LOW, dw); | |
2598 dupe_menu_add_item(store, _("Similarity (custom)"), DUPE_MATCH_SIM_CUSTOM, dw); | |
2599 | |
2600 g_signal_connect(G_OBJECT(dw->combo), "changed", | |
2601 G_CALLBACK(dupe_menu_type_cb), dw); | |
2602 } | |
2603 | |
2604 /* | |
2605 *------------------------------------------------------------------- | |
2606 * list view columns | |
2607 *------------------------------------------------------------------- | |
2608 */ | |
2609 | |
2610 /* this overrides the low default of a GtkCellRenderer from 100 to CELL_HEIGHT_OVERRIDE, something sane for our purposes */ | |
2611 | |
2612 #define CELL_HEIGHT_OVERRIDE 512 | |
2613 | |
2614 void cell_renderer_height_override(GtkCellRenderer *renderer) | |
2615 { | |
2616 GParamSpec *spec; | |
2617 | |
2618 spec = g_object_class_find_property(G_OBJECT_GET_CLASS(G_OBJECT(renderer)), "height"); | |
2619 if (spec && G_IS_PARAM_SPEC_INT(spec)) | |
2620 { | |
2621 GParamSpecInt *spec_int; | |
2622 | |
2623 spec_int = G_PARAM_SPEC_INT(spec); | |
2624 if (spec_int->maximum < CELL_HEIGHT_OVERRIDE) spec_int->maximum = CELL_HEIGHT_OVERRIDE; | |
2625 } | |
2626 } | |
2627 | |
2628 static GdkColor *dupe_listview_color_shifted(GtkWidget *widget) | |
2629 { | |
2630 static GdkColor color; | |
2631 static GtkWidget *done = NULL; | |
2632 | |
2633 if (done != widget) | |
2634 { | |
2635 GtkStyle *style; | |
2636 | |
2637 style = gtk_widget_get_style(widget); | |
2638 memcpy(&color, &style->base[GTK_STATE_NORMAL], sizeof(color)); | |
2639 shift_color(&color, -1, 0); | |
2640 done = widget; | |
2641 } | |
2642 | |
2643 return &color; | |
2644 } | |
2645 | |
2646 static void dupe_listview_color_cb(GtkTreeViewColumn *tree_column, GtkCellRenderer *cell, | |
2647 GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data) | |
2648 { | |
2649 DupeWindow *dw = data; | |
2650 gboolean set; | |
2651 | |
2652 gtk_tree_model_get(tree_model, iter, DUPE_COLUMN_COLOR, &set, -1); | |
2653 g_object_set(G_OBJECT(cell), | |
2654 "cell-background-gdk", dupe_listview_color_shifted(dw->listview), | |
2655 "cell-background-set", set, NULL); | |
2656 } | |
2657 | |
2658 static void dupe_listview_add_column(DupeWindow *dw, GtkWidget *listview, gint n, const gchar *title, gint image, gint right_justify) | |
2659 { | |
2660 GtkTreeViewColumn *column; | |
2661 GtkCellRenderer *renderer; | |
2662 | |
2663 column = gtk_tree_view_column_new(); | |
2664 gtk_tree_view_column_set_title(column, title); | |
2665 gtk_tree_view_column_set_min_width(column, 4); | |
2666 | |
2667 if (n != DUPE_COLUMN_RANK && | |
2668 n != DUPE_COLUMN_THUMB) | |
2669 { | |
2670 gtk_tree_view_column_set_resizable(column, TRUE); | |
2671 } | |
2672 | |
2673 if (!image) | |
2674 { | |
2675 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_GROW_ONLY); | |
2676 renderer = gtk_cell_renderer_text_new(); | |
2677 if (right_justify) | |
2678 { | |
2679 g_object_set(G_OBJECT(renderer), "xalign", 1.0, NULL); | |
2680 } | |
2681 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
2682 gtk_tree_view_column_add_attribute(column, renderer, "text", n); | |
2683 } | |
2684 else | |
2685 { | |
2686 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED); | |
2687 renderer = gtk_cell_renderer_pixbuf_new(); | |
2688 cell_renderer_height_override(renderer); | |
2689 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
2690 gtk_tree_view_column_add_attribute(column, renderer, "pixbuf", n); | |
2691 } | |
2692 | |
2693 if (listview == dw->listview) | |
2694 { | |
2695 /* sets background before rendering */ | |
2696 gtk_tree_view_column_set_cell_data_func(column, renderer, dupe_listview_color_cb, dw, NULL); | |
2697 } | |
2698 | |
2699 gtk_tree_view_append_column(GTK_TREE_VIEW(listview), column); | |
2700 } | |
2701 | |
2702 static void dupe_listview_set_height(GtkWidget *listview, gint thumb) | |
2703 { | |
2704 GtkTreeViewColumn *column; | |
2705 GtkCellRenderer *cell; | |
2706 GList *list; | |
2707 | |
2708 column = gtk_tree_view_get_column(GTK_TREE_VIEW(listview), DUPE_COLUMN_THUMB - 1); | |
2709 if (!column) return; | |
2710 | |
2711 gtk_tree_view_column_set_fixed_width(column, (thumb) ? thumb_max_width : 4); | |
2712 | |
2713 list = gtk_tree_view_column_get_cell_renderers(column); | |
2714 if (!list) return; | |
2715 cell = list->data; | |
2716 g_list_free(list); | |
2717 | |
2718 g_object_set(G_OBJECT(cell), "height", (thumb) ? thumb_max_height : -1, NULL); | |
2719 gtk_tree_view_columns_autosize(GTK_TREE_VIEW(listview)); | |
2720 } | |
2721 | |
2722 | |
2723 /* | |
2724 *------------------------------------------------------------------- | |
2725 * misc cb | |
2726 *------------------------------------------------------------------- | |
2727 */ | |
2728 | |
2729 static void dupe_window_show_thumb_cb(GtkWidget *widget, gpointer data) | |
2730 { | |
2731 DupeWindow *dw = data; | |
2732 | |
2733 dw->show_thumbs = GTK_TOGGLE_BUTTON(widget)->active; | |
2734 | |
2735 if (dw->show_thumbs) | |
2736 { | |
2737 if (!dw->working) dupe_thumb_step(dw); | |
2738 } | |
2739 else | |
2740 { | |
2741 GtkTreeModel *store; | |
2742 GtkTreeIter iter; | |
2743 gint valid; | |
2744 | |
2745 thumb_loader_free(dw->thumb_loader); | |
2746 dw->thumb_loader = NULL; | |
2747 | |
2748 store = gtk_tree_view_get_model(GTK_TREE_VIEW(dw->listview)); | |
2749 valid = gtk_tree_model_get_iter_first(store, &iter); | |
2750 | |
2751 while (valid) | |
2752 { | |
2753 gtk_list_store_set(GTK_LIST_STORE(store), &iter, DUPE_COLUMN_THUMB, NULL, -1); | |
2754 valid = gtk_tree_model_iter_next(store, &iter); | |
2755 } | |
2756 dupe_window_update_progress(dw, NULL, 0.0, FALSE); | |
2757 } | |
2758 | |
2759 dupe_listview_set_height(dw->listview, dw->show_thumbs); | |
2760 } | |
2761 | |
2762 static void dupe_popup_menu_pos_cb(GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer data) | |
2763 { | |
2764 GtkWidget *view = data; | |
2765 GtkTreePath *tpath; | |
2766 gint cx, cy, cw, ch; | |
2767 gint column; | |
2768 | |
2769 gtk_tree_view_get_cursor(GTK_TREE_VIEW(view), &tpath, NULL); | |
2770 if (!tpath) return; | |
2771 | |
2772 if (gtk_tree_view_get_column(GTK_TREE_VIEW(view), DUPE_COLUMN_NAME - 1) != NULL) | |
2773 { | |
2774 column = DUPE_COLUMN_NAME - 1; | |
2775 } | |
2776 else | |
2777 { | |
2778 /* dw->second_listview */ | |
2779 column = 0; | |
2780 } | |
2781 tree_view_get_cell_clamped(GTK_TREE_VIEW(view), tpath, column, TRUE, &cx, &cy, &cw, &ch); | |
2782 gtk_tree_path_free(tpath); | |
2783 cy += ch; | |
2784 popup_menu_position_clamp(menu, &cx, &cy, 0); | |
2785 *x = cx; | |
2786 *y = cy; | |
2787 } | |
2788 | |
2789 static gint dupe_window_keypress_cb(GtkWidget *widget, GdkEventKey *event, gpointer data) | |
2790 { | |
2791 DupeWindow *dw = data; | |
2792 gint stop_signal = FALSE; | |
2793 gint on_second; | |
2794 GtkWidget *listview; | |
2795 GtkTreeModel *store; | |
2796 GtkTreeSelection *selection; | |
2797 GList *slist; | |
2798 DupeItem *di = NULL; | |
2799 | |
2800 on_second = GTK_WIDGET_HAS_FOCUS(dw->second_listview); | |
2801 | |
2802 if (on_second) | |
2803 { | |
2804 listview = dw->second_listview; | |
2805 } | |
2806 else | |
2807 { | |
2808 listview = dw->listview; | |
2809 } | |
2810 | |
2811 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(listview)); | |
2812 slist = gtk_tree_selection_get_selected_rows(selection, &store); | |
2813 if (slist) | |
2814 { | |
2815 GtkTreePath *tpath; | |
2816 GtkTreeIter iter; | |
2817 GList *last; | |
2818 | |
2819 last = g_list_last(slist); | |
2820 tpath = last->data; | |
2821 | |
2822 /* last is newest selected file */ | |
2823 gtk_tree_model_get_iter(store, &iter, tpath); | |
2824 gtk_tree_model_get(store, &iter, DUPE_COLUMN_POINTER, &di, -1); | |
2825 } | |
2826 g_list_foreach(slist, (GFunc)gtk_tree_path_free, NULL); | |
2827 g_list_free(slist); | |
2828 | |
2829 if (event->state & GDK_CONTROL_MASK) | |
2830 { | |
2831 gint edit_val = -1; | |
2832 | |
2833 if (!on_second) | |
2834 switch (event->keyval) | |
2835 { | |
2836 case '1': | |
2837 edit_val = 0; | |
2838 break; | |
2839 case '2': | |
2840 edit_val = 1; | |
2841 break; | |
2842 case '3': | |
2843 edit_val = 2; | |
2844 break; | |
2845 case '4': | |
2846 edit_val = 3; | |
2847 break; | |
2848 case '5': | |
2849 edit_val = 4; | |
2850 break; | |
2851 case '6': | |
2852 edit_val = 5; | |
2853 break; | |
2854 case '7': | |
2855 edit_val = 6; | |
2856 break; | |
2857 case '8': | |
2858 edit_val = 7; | |
2859 break; | |
2860 case '9': | |
2861 edit_val = 8; | |
2862 break; | |
2863 case '0': | |
2864 edit_val = 9; | |
2865 break; | |
2866 case 'C': case 'c': | |
2867 stop_signal = TRUE; | |
2868 file_util_copy(NULL, dupe_listview_get_selection(dw, listview), NULL, dw->window); | |
2869 break; | |
2870 case 'M': case 'm': | |
2871 file_util_move(NULL, dupe_listview_get_selection(dw, listview), NULL, dw->window); | |
2872 stop_signal = TRUE; | |
2873 break; | |
2874 case 'R': case 'r': | |
2875 file_util_rename(NULL, dupe_listview_get_selection(dw, listview), dw->window); | |
2876 stop_signal = TRUE; | |
2877 break; | |
2878 case 'D': case 'd': | |
2879 file_util_delete(NULL, dupe_listview_get_selection(dw, listview), dw->window); | |
2880 stop_signal = TRUE; | |
2881 break; | |
2882 case 'P': case 'p': | |
2883 info_window_new(NULL, dupe_listview_get_selection(dw, listview)); | |
2884 stop_signal = TRUE; | |
2885 break; | |
2886 default: | |
2887 break; | |
2888 } | |
2889 | |
2890 switch (event->keyval) | |
2891 { | |
2892 case 'A': case 'a': | |
2893 if (event->state & GDK_SHIFT_MASK) | |
2894 { | |
2895 gtk_tree_selection_unselect_all(selection); | |
2896 } | |
2897 else | |
2898 { | |
2899 gtk_tree_selection_select_all(selection); | |
2900 } | |
2901 stop_signal = TRUE; | |
2902 break; | |
2903 case GDK_Delete: case GDK_KP_Delete: | |
2904 if (on_second) | |
2905 { | |
2906 dupe_second_clear(dw); | |
2907 dupe_window_recompare(dw); | |
2908 } | |
2909 else | |
2910 { | |
2911 dupe_window_clear(dw); | |
2912 } | |
2913 stop_signal = TRUE; | |
2914 break; | |
2915 case 'L': case 'l': | |
2916 dupe_window_append_file_list(dw, FALSE); | |
2917 stop_signal = TRUE; | |
2918 break; | |
2919 case 'T': case 't': | |
2920 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dw->button_thumbs), | |
2921 !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(dw->button_thumbs))); | |
2922 stop_signal = TRUE; | |
2923 break; | |
2924 case 'W': case 'w': | |
2925 dupe_window_close(dw); | |
2926 stop_signal = TRUE; | |
2927 break; | |
2928 default: | |
2929 break; | |
2930 } | |
2931 | |
2932 if (edit_val >= 0) | |
2933 { | |
2934 dupe_window_edit_selected(dw, edit_val); | |
2935 stop_signal = TRUE; | |
2936 } | |
2937 } | |
2938 else | |
2939 { | |
2940 switch (event->keyval) | |
2941 { | |
2942 case GDK_Return: case GDK_KP_Enter: | |
2943 dupe_menu_view(dw, di, listview, FALSE); | |
2944 stop_signal = TRUE; | |
2945 break; | |
2946 case 'V': case 'v': | |
2947 stop_signal = TRUE; | |
2948 dupe_menu_view(dw, di, listview, TRUE); | |
2949 break; | |
2950 case GDK_Delete: case GDK_KP_Delete: | |
2951 dupe_window_remove_selection(dw, listview); | |
2952 stop_signal = TRUE; | |
2953 break; | |
2954 case 'C': case 'c': | |
2955 if (!on_second) | |
2956 { | |
2957 dupe_window_collection_from_selection(dw); | |
2958 stop_signal = TRUE; | |
2959 } | |
2960 break; | |
2961 case '1': | |
2962 dupe_listview_select_dupes(dw, TRUE); | |
2963 stop_signal = TRUE; | |
2964 break; | |
2965 case '2': | |
2966 dupe_listview_select_dupes(dw, FALSE); | |
2967 stop_signal = TRUE; | |
2968 break; | |
2969 case GDK_Menu: | |
2970 case GDK_F10: | |
2971 if (!on_second) | |
2972 { | |
2973 GtkWidget *menu; | |
2974 | |
2975 menu = dupe_menu_popup_main(dw, di); | |
2976 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, | |
2977 dupe_popup_menu_pos_cb, listview, 0, GDK_CURRENT_TIME); | |
2978 } | |
2979 else | |
2980 { | |
2981 GtkWidget *menu; | |
2982 | |
2983 menu = dupe_menu_popup_second(dw, di); | |
2984 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, | |
2985 dupe_popup_menu_pos_cb, listview, 0, GDK_CURRENT_TIME); | |
2986 } | |
2987 break; | |
2988 default: | |
2989 break; | |
2990 } | |
2991 } | |
2992 | |
2993 return stop_signal; | |
2994 } | |
2995 | |
2996 | |
2997 void dupe_window_clear(DupeWindow *dw) | |
2998 { | |
2999 GtkListStore *store; | |
3000 | |
3001 dupe_check_stop(dw); | |
3002 | |
3003 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dw->listview))); | |
3004 gtk_list_store_clear(store); | |
3005 gtk_tree_view_columns_autosize(GTK_TREE_VIEW(dw->listview)); | |
3006 | |
3007 g_list_free(dw->dupes); | |
3008 dw->dupes = NULL; | |
3009 | |
3010 dupe_list_free(dw->list); | |
3011 dw->list = NULL; | |
3012 | |
3013 dupe_match_reset_list(dw->second_list); | |
3014 | |
3015 dupe_window_update_count(dw, FALSE); | |
3016 dupe_window_update_progress(dw, NULL, 0.0, FALSE); | |
3017 } | |
3018 | |
3019 void dupe_window_close(DupeWindow *dw) | |
3020 { | |
3021 dupe_check_stop(dw); | |
3022 | |
3023 dupe_window_list = g_list_remove(dupe_window_list, dw); | |
3024 gtk_widget_destroy(dw->window); | |
3025 | |
3026 g_list_free(dw->dupes); | |
3027 dupe_list_free(dw->list); | |
3028 | |
3029 dupe_list_free(dw->second_list); | |
3030 | |
3031 g_free(dw); | |
3032 } | |
3033 | |
3034 static gint dupe_window_delete(GtkWidget *widget, GdkEvent *event, gpointer data) | |
3035 { | |
3036 DupeWindow *dw = data; | |
3037 dupe_window_close(dw); | |
3038 | |
3039 return TRUE; | |
3040 } | |
3041 | |
3042 /* collection and files can be NULL */ | |
3043 DupeWindow *dupe_window_new(DupeMatchType match_mask) | |
3044 { | |
3045 DupeWindow *dw; | |
3046 GtkWidget *vbox; | |
3047 GtkWidget *scrolled; | |
3048 GtkWidget *frame; | |
3049 GtkWidget *status_box; | |
3050 GtkWidget *label; | |
3051 GtkWidget *button; | |
3052 GtkListStore *store; | |
3053 GtkTreeSelection *selection; | |
3054 GdkGeometry geometry; | |
3055 | |
3056 dw = g_new0(DupeWindow, 1); | |
3057 | |
3058 dw->list = NULL; | |
3059 dw->dupes = NULL; | |
3060 dw->match_mask = match_mask; | |
3061 dw->show_thumbs = FALSE; | |
3062 | |
3063 dw->idle_id = -1; | |
3064 | |
3065 dw->second_set = FALSE; | |
3066 | |
3067 dw->window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
3068 window_set_icon(dw->window, NULL, NULL); | |
3069 | |
3070 geometry.min_width = 32; | |
3071 geometry.min_height = 32; | |
3072 geometry.base_width = DUPE_DEF_WIDTH; | |
3073 geometry.base_height = DUPE_DEF_HEIGHT; | |
3074 gtk_window_set_geometry_hints(GTK_WINDOW(dw->window), NULL, &geometry, | |
3075 GDK_HINT_MIN_SIZE | GDK_HINT_BASE_SIZE); | |
3076 | |
3077 gtk_window_set_default_size(GTK_WINDOW(dw->window), DUPE_DEF_WIDTH, DUPE_DEF_HEIGHT); | |
3078 | |
3079 gtk_window_set_resizable(GTK_WINDOW(dw->window), TRUE); | |
3080 gtk_window_set_title(GTK_WINDOW(dw->window), _("Find duplicates - GQview")); | |
3081 gtk_window_set_wmclass(GTK_WINDOW(dw->window), "dupe", "GQview"); | |
3082 gtk_container_set_border_width (GTK_CONTAINER (dw->window), 0); | |
3083 | |
3084 g_signal_connect(G_OBJECT(dw->window), "delete_event", | |
3085 G_CALLBACK(dupe_window_delete), dw); | |
3086 g_signal_connect(G_OBJECT(dw->window), "key_press_event", | |
3087 G_CALLBACK(dupe_window_keypress_cb), dw); | |
3088 | |
3089 vbox = gtk_vbox_new(FALSE, 0); | |
3090 gtk_container_add(GTK_CONTAINER(dw->window), vbox); | |
3091 gtk_widget_show(vbox); | |
3092 | |
3093 dw->table = gtk_table_new(1, 3, FALSE); | |
3094 gtk_box_pack_start(GTK_BOX(vbox), dw->table, TRUE, TRUE, 0); | |
3095 gtk_widget_show(dw->table); | |
3096 | |
3097 scrolled = gtk_scrolled_window_new(NULL, NULL); | |
3098 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN); | |
3099 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
3100 gtk_table_attach_defaults(GTK_TABLE(dw->table), scrolled, 0, 2, 0, 1); | |
3101 gtk_widget_show(scrolled); | |
3102 | |
3103 store = gtk_list_store_new(9, G_TYPE_POINTER, G_TYPE_STRING, GDK_TYPE_PIXBUF, | |
3104 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, | |
3105 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN); | |
3106 dw->listview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); | |
3107 g_object_unref(store); | |
3108 | |
3109 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dw->listview)); | |
3110 gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_MULTIPLE); | |
3111 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(dw->listview), TRUE); | |
3112 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(dw->listview), FALSE); | |
3113 | |
3114 dupe_listview_add_column(dw, dw->listview, DUPE_COLUMN_RANK, "", FALSE, TRUE); | |
3115 dupe_listview_add_column(dw, dw->listview, DUPE_COLUMN_THUMB, "", TRUE, FALSE); | |
3116 dupe_listview_add_column(dw, dw->listview, DUPE_COLUMN_NAME, _("Name"), FALSE, FALSE); | |
3117 dupe_listview_add_column(dw, dw->listview, DUPE_COLUMN_SIZE, _("Size"), FALSE, TRUE); | |
3118 dupe_listview_add_column(dw, dw->listview, DUPE_COLUMN_DATE, _("Date"), FALSE, TRUE); | |
3119 dupe_listview_add_column(dw, dw->listview, DUPE_COLUMN_DIMENSIONS, _("Dimensions"), FALSE, FALSE); | |
3120 dupe_listview_add_column(dw, dw->listview, DUPE_COLUMN_PATH, _("Path"), FALSE, FALSE); | |
3121 | |
3122 gtk_container_add(GTK_CONTAINER(scrolled), dw->listview); | |
3123 gtk_widget_show(dw->listview); | |
3124 | |
3125 dw->second_vbox = gtk_vbox_new(FALSE, 0); | |
3126 gtk_table_attach_defaults(GTK_TABLE(dw->table), dw->second_vbox, 2, 3, 0, 1); | |
3127 if (dw->second_set) | |
3128 { | |
3129 gtk_table_set_col_spacings(GTK_TABLE(dw->table), PREF_PAD_GAP); | |
3130 gtk_widget_show(dw->second_vbox); | |
3131 } | |
3132 else | |
3133 { | |
3134 gtk_table_set_col_spacings(GTK_TABLE(dw->table), 0); | |
3135 } | |
3136 | |
3137 scrolled = gtk_scrolled_window_new(NULL, NULL); | |
3138 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN); | |
3139 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
3140 gtk_box_pack_start(GTK_BOX(dw->second_vbox), scrolled, TRUE, TRUE, 0); | |
3141 gtk_widget_show(scrolled); | |
3142 | |
3143 store = gtk_list_store_new(2, G_TYPE_POINTER, G_TYPE_STRING); | |
3144 dw->second_listview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); | |
3145 | |
3146 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dw->second_listview)); | |
3147 gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_MULTIPLE); | |
3148 | |
3149 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(dw->second_listview), TRUE); | |
3150 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(dw->second_listview), FALSE); | |
3151 | |
3152 dupe_listview_add_column(dw, dw->second_listview, 1, _("Compare to:"), FALSE, FALSE); | |
3153 | |
3154 gtk_container_add(GTK_CONTAINER(scrolled), dw->second_listview); | |
3155 gtk_widget_show(dw->second_listview); | |
3156 | |
3157 dw->second_status_label = gtk_label_new(""); | |
3158 gtk_box_pack_start(GTK_BOX(dw->second_vbox), dw->second_status_label, FALSE, FALSE, 0); | |
3159 gtk_widget_show(dw->second_status_label); | |
3160 | |
3161 pref_line(dw->second_vbox, GTK_ORIENTATION_HORIZONTAL); | |
3162 | |
3163 status_box = pref_box_new(vbox, FALSE, GTK_ORIENTATION_HORIZONTAL, 0); | |
3164 | |
3165 label = gtk_label_new(_("Compare by:")); | |
3166 gtk_box_pack_start(GTK_BOX(status_box), label, FALSE, FALSE, PREF_PAD_SPACE); | |
3167 gtk_widget_show(label); | |
3168 | |
3169 dupe_menu_setup(dw); | |
3170 gtk_box_pack_start(GTK_BOX(status_box), dw->combo, FALSE, FALSE, 0); | |
3171 gtk_widget_show(dw->combo); | |
3172 | |
3173 dw->button_thumbs = gtk_check_button_new_with_label(_("Thumbnails")); | |
3174 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dw->button_thumbs), dw->show_thumbs); | |
3175 g_signal_connect(G_OBJECT(dw->button_thumbs), "toggled", | |
3176 G_CALLBACK(dupe_window_show_thumb_cb), dw); | |
3177 gtk_box_pack_start(GTK_BOX(status_box), dw->button_thumbs, FALSE, FALSE, PREF_PAD_SPACE); | |
3178 gtk_widget_show(dw->button_thumbs); | |
3179 | |
3180 button = gtk_check_button_new_with_label(_("Compare two file sets")); | |
3181 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), dw->second_set); | |
3182 g_signal_connect(G_OBJECT(button), "toggled", | |
3183 G_CALLBACK(dupe_second_set_toggle_cb), dw); | |
3184 gtk_box_pack_end(GTK_BOX(status_box), button, FALSE, FALSE, PREF_PAD_SPACE); | |
3185 gtk_widget_show(button); | |
3186 | |
3187 status_box = gtk_hbox_new(FALSE, 0); | |
3188 gtk_box_pack_start(GTK_BOX(vbox), status_box, FALSE, FALSE, 0); | |
3189 gtk_widget_show(status_box); | |
3190 | |
3191 frame = gtk_frame_new(NULL); | |
3192 gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN); | |
3193 gtk_box_pack_start(GTK_BOX(status_box), frame, TRUE, TRUE, 0); | |
3194 gtk_widget_show(frame); | |
3195 | |
3196 dw->status_label = gtk_label_new(""); | |
3197 gtk_container_add(GTK_CONTAINER(frame), dw->status_label); | |
3198 gtk_widget_show(dw->status_label); | |
3199 | |
3200 dw->extra_label = gtk_progress_bar_new(); | |
3201 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(dw->extra_label), 0.0); | |
3202 gtk_box_pack_end(GTK_BOX(status_box), dw->extra_label, FALSE, FALSE, 0); | |
3203 gtk_widget_show(dw->extra_label); | |
3204 | |
3205 dupe_dnd_init(dw); | |
3206 | |
3207 /* order is important here, dnd_init should be seeing mouse | |
3208 * presses before we possibly handle (and stop) the signal | |
3209 */ | |
3210 g_signal_connect(G_OBJECT(dw->listview), "button_press_event", | |
3211 G_CALLBACK(dupe_listview_press_cb), dw); | |
3212 g_signal_connect(G_OBJECT(dw->listview), "button_release_event", | |
3213 G_CALLBACK(dupe_listview_release_cb), dw); | |
3214 g_signal_connect(G_OBJECT(dw->second_listview), "button_press_event", | |
3215 G_CALLBACK(dupe_listview_press_cb), dw); | |
3216 g_signal_connect(G_OBJECT(dw->second_listview), "button_release_event", | |
3217 G_CALLBACK(dupe_listview_release_cb), dw); | |
3218 | |
3219 gtk_widget_show(dw->window); | |
3220 | |
3221 dupe_window_update_count(dw, TRUE); | |
3222 dupe_window_update_progress(dw, NULL, 0.0, FALSE); | |
3223 | |
3224 dupe_window_list = g_list_append(dupe_window_list, dw); | |
3225 | |
3226 return dw; | |
3227 } | |
3228 | |
3229 /* | |
3230 *------------------------------------------------------------------- | |
3231 * dnd confirm dir | |
3232 *------------------------------------------------------------------- | |
3233 */ | |
3234 | |
3235 typedef struct { | |
3236 DupeWindow *dw; | |
3237 GList *list; | |
3238 } CDupeConfirmD; | |
3239 | |
3240 static void confirm_dir_list_cancel(GtkWidget *widget, gpointer data) | |
3241 { | |
3242 /* do nothing */ | |
3243 } | |
3244 | |
3245 static void confirm_dir_list_add(GtkWidget *widget, gpointer data) | |
3246 { | |
3247 CDupeConfirmD *d = data; | |
3248 GList *work; | |
3249 | |
3250 dupe_window_add_files(d->dw, d->list, FALSE); | |
3251 | |
3252 work = d->list; | |
3253 while (work) | |
3254 { | |
3255 gchar *path = work->data; | |
3256 work = work->next; | |
3257 if (isdir(path)) | |
3258 { | |
3259 GList *list = NULL; | |
3260 | |
3261 path_list(path, &list, NULL); | |
3262 list = path_list_filter(list, FALSE); | |
3263 if (list) | |
3264 { | |
3265 dupe_window_add_files(d->dw, list, FALSE); | |
3266 path_list_free(list); | |
3267 } | |
3268 } | |
3269 } | |
3270 } | |
3271 | |
3272 static void confirm_dir_list_recurse(GtkWidget *widget, gpointer data) | |
3273 { | |
3274 CDupeConfirmD *d = data; | |
3275 dupe_window_add_files(d->dw, d->list, TRUE); | |
3276 } | |
3277 | |
3278 static void confirm_dir_list_skip(GtkWidget *widget, gpointer data) | |
3279 { | |
3280 CDupeConfirmD *d = data; | |
3281 dupe_window_add_files(d->dw, d->list, FALSE); | |
3282 } | |
3283 | |
3284 static void confirm_dir_list_destroy(GtkWidget *widget, gpointer data) | |
3285 { | |
3286 CDupeConfirmD *d = data; | |
3287 path_list_free(d->list); | |
3288 g_free(d); | |
3289 } | |
3290 | |
3291 static GtkWidget *dupe_confirm_dir_list(DupeWindow *dw, GList *list) | |
3292 { | |
3293 GtkWidget *menu; | |
3294 CDupeConfirmD *d; | |
3295 | |
3296 d = g_new0(CDupeConfirmD, 1); | |
3297 d->dw = dw; | |
3298 d->list = list; | |
3299 | |
3300 menu = popup_menu_short_lived(); | |
3301 g_signal_connect(G_OBJECT(menu), "destroy", | |
3302 G_CALLBACK(confirm_dir_list_destroy), d); | |
3303 | |
3304 menu_item_add_stock(menu, _("Dropped list includes folders."), GTK_STOCK_DND_MULTIPLE, NULL, NULL); | |
3305 menu_item_add_divider(menu); | |
3306 menu_item_add_stock(menu, _("_Add contents"), GTK_STOCK_OK, G_CALLBACK(confirm_dir_list_add), d); | |
3307 menu_item_add_stock(menu, _("Add contents _recursive"), GTK_STOCK_ADD, G_CALLBACK(confirm_dir_list_recurse), d); | |
3308 menu_item_add_stock(menu, _("_Skip folders"), GTK_STOCK_REMOVE, G_CALLBACK(confirm_dir_list_skip), d); | |
3309 menu_item_add_divider(menu); | |
3310 menu_item_add_stock(menu, _("Cancel"), GTK_STOCK_CANCEL, G_CALLBACK(confirm_dir_list_cancel), d); | |
3311 | |
3312 return menu; | |
3313 } | |
3314 | |
3315 /* | |
3316 *------------------------------------------------------------------- | |
3317 * dnd | |
3318 *------------------------------------------------------------------- | |
3319 */ | |
3320 | |
3321 static GtkTargetEntry dupe_drag_types[] = { | |
3322 { "text/uri-list", 0, TARGET_URI_LIST }, | |
3323 { "text/plain", 0, TARGET_TEXT_PLAIN } | |
3324 }; | |
3325 static gint n_dupe_drag_types = 2; | |
3326 | |
3327 static GtkTargetEntry dupe_drop_types[] = { | |
3328 { "application/x-gqview-collection-member", 0, TARGET_APP_COLLECTION_MEMBER }, | |
3329 { "text/uri-list", 0, TARGET_URI_LIST } | |
3330 }; | |
3331 static gint n_dupe_drop_types = 2; | |
3332 | |
3333 static void dupe_dnd_data_set(GtkWidget *widget, GdkDragContext *context, | |
3334 GtkSelectionData *selection_data, guint info, | |
3335 guint time, gpointer data) | |
3336 { | |
3337 DupeWindow *dw = data; | |
3338 gchar *uri_text; | |
3339 gint length; | |
3340 GList *list; | |
3341 | |
3342 switch (info) | |
3343 { | |
3344 case TARGET_URI_LIST: | |
3345 case TARGET_TEXT_PLAIN: | |
3346 list = dupe_listview_get_selection(dw, widget); | |
3347 if (!list) return; | |
3348 uri_text = uri_text_from_list(list, &length, (info == TARGET_TEXT_PLAIN)); | |
3349 path_list_free(list); | |
3350 break; | |
3351 default: | |
3352 uri_text = NULL; | |
3353 break; | |
3354 } | |
3355 | |
3356 if (uri_text) gtk_selection_data_set(selection_data, selection_data->target, | |
64
04ff0df3ad2f
Mon Aug 15 17:13:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
3357 8, (guchar *)uri_text, length); |
9 | 3358 g_free(uri_text); |
3359 } | |
3360 | |
3361 static void dupe_dnd_data_get(GtkWidget *widget, GdkDragContext *context, | |
3362 gint x, gint y, | |
3363 GtkSelectionData *selection_data, guint info, | |
3364 guint time, gpointer data) | |
3365 { | |
3366 DupeWindow *dw = data; | |
3367 GtkWidget *source; | |
3368 GList *list = NULL; | |
3369 GList *work; | |
3370 | |
3371 source = gtk_drag_get_source_widget(context); | |
3372 if (source == dw->listview || source == dw->second_listview) return; | |
3373 | |
3374 dw->second_drop = (dw->second_set && widget == dw->second_listview); | |
3375 | |
3376 switch (info) | |
3377 { | |
3378 case TARGET_APP_COLLECTION_MEMBER: | |
3379 collection_from_dnd_data((gchar *)selection_data->data, &list, NULL); | |
3380 break; | |
3381 case TARGET_URI_LIST: | |
64
04ff0df3ad2f
Mon Aug 15 17:13:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
3382 list = uri_list_from_text((gchar *)selection_data->data, TRUE); |
9 | 3383 work = list; |
3384 while(work) | |
3385 { | |
3386 if (isdir((gchar *)work->data)) | |
3387 { | |
3388 GtkWidget *menu; | |
3389 menu = dupe_confirm_dir_list(dw, list); | |
3390 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 0, time); | |
3391 return; | |
3392 } | |
3393 work = work->next; | |
3394 } | |
3395 break; | |
3396 default: | |
3397 list = NULL; | |
3398 break; | |
3399 } | |
3400 | |
3401 if (list) | |
3402 { | |
3403 dupe_window_add_files(dw, list, FALSE); | |
3404 path_list_free(list); | |
3405 } | |
3406 } | |
3407 | |
3408 static void dupe_dest_set(GtkWidget *widget, gint enable) | |
3409 { | |
3410 if (enable) | |
3411 { | |
3412 gtk_drag_dest_set(widget, | |
3413 GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_HIGHLIGHT | GTK_DEST_DEFAULT_DROP, | |
3414 dupe_drop_types, n_dupe_drop_types, | |
3415 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_ASK); | |
3416 | |
3417 } | |
3418 else | |
3419 { | |
3420 gtk_drag_dest_unset(widget); | |
3421 } | |
3422 } | |
3423 | |
3424 static void dupe_dnd_begin(GtkWidget *widget, GdkDragContext *context, gpointer data) | |
3425 { | |
3426 DupeWindow *dw = data; | |
3427 dupe_dest_set(dw->listview, FALSE); | |
3428 dupe_dest_set(dw->second_listview, FALSE); | |
3429 | |
3430 if (dw->click_item && !dupe_listview_item_is_selected(dw, dw->click_item, widget)) | |
3431 { | |
3432 GtkListStore *store; | |
3433 GtkTreeIter iter; | |
3434 | |
3435 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(widget))); | |
3436 if (dupe_listview_find_item(store, dw->click_item, &iter) >= 0) | |
3437 { | |
3438 GtkTreeSelection *selection; | |
3439 GtkTreePath *tpath; | |
3440 | |
3441 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget)); | |
3442 gtk_tree_selection_unselect_all(selection); | |
3443 gtk_tree_selection_select_iter(selection, &iter); | |
3444 | |
3445 tpath = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter); | |
3446 gtk_tree_view_set_cursor(GTK_TREE_VIEW(widget), tpath, NULL, FALSE); | |
3447 gtk_tree_path_free(tpath); | |
3448 } | |
3449 } | |
3450 | |
3451 if (dw->show_thumbs && | |
3452 widget == dw->listview && | |
3453 dw->click_item && dw->click_item->pixbuf) | |
3454 { | |
3455 GtkTreeSelection *selection; | |
3456 gint items; | |
3457 | |
3458 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget)); | |
3459 items = gtk_tree_selection_count_selected_rows(selection); | |
3460 dnd_set_drag_icon(widget, context, dw->click_item->pixbuf, items); | |
3461 } | |
3462 } | |
3463 | |
3464 static void dupe_dnd_end(GtkWidget *widget, GdkDragContext *context, gpointer data) | |
3465 { | |
3466 DupeWindow *dw = data; | |
3467 dupe_dest_set(dw->listview, TRUE); | |
3468 dupe_dest_set(dw->second_listview, TRUE); | |
3469 } | |
3470 | |
3471 static void dupe_dnd_init(DupeWindow *dw) | |
3472 { | |
3473 gtk_drag_source_set(dw->listview, GDK_BUTTON1_MASK | GDK_BUTTON2_MASK, | |
3474 dupe_drag_types, n_dupe_drag_types, | |
3475 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK); | |
3476 g_signal_connect(G_OBJECT(dw->listview), "drag_data_get", | |
3477 G_CALLBACK(dupe_dnd_data_set), dw); | |
3478 g_signal_connect(G_OBJECT(dw->listview), "drag_begin", | |
3479 G_CALLBACK(dupe_dnd_begin), dw); | |
3480 g_signal_connect(G_OBJECT(dw->listview), "drag_end", | |
3481 G_CALLBACK(dupe_dnd_end), dw); | |
3482 | |
3483 dupe_dest_set(dw->listview, TRUE); | |
3484 g_signal_connect(G_OBJECT(dw->listview), "drag_data_received", | |
3485 G_CALLBACK(dupe_dnd_data_get), dw); | |
3486 | |
3487 gtk_drag_source_set(dw->second_listview, GDK_BUTTON1_MASK | GDK_BUTTON2_MASK, | |
3488 dupe_drag_types, n_dupe_drag_types, | |
3489 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK); | |
3490 g_signal_connect(G_OBJECT(dw->second_listview), "drag_data_get", | |
3491 G_CALLBACK(dupe_dnd_data_set), dw); | |
3492 g_signal_connect(G_OBJECT(dw->second_listview), "drag_begin", | |
3493 G_CALLBACK(dupe_dnd_begin), dw); | |
3494 g_signal_connect(G_OBJECT(dw->second_listview), "drag_end", | |
3495 G_CALLBACK(dupe_dnd_end), dw); | |
3496 | |
3497 dupe_dest_set(dw->second_listview, TRUE); | |
3498 g_signal_connect(G_OBJECT(dw->second_listview), "drag_data_received", | |
3499 G_CALLBACK(dupe_dnd_data_get), dw); | |
3500 } | |
3501 | |
3502 /* | |
3503 *------------------------------------------------------------------- | |
3504 * maintenance (move, delete, etc.) | |
3505 *------------------------------------------------------------------- | |
3506 */ | |
3507 | |
3508 void dupe_maint_removed(const gchar *path) | |
3509 { | |
3510 GList *work; | |
3511 | |
3512 work = dupe_window_list; | |
3513 while (work) | |
3514 { | |
3515 DupeWindow *dw = work->data; | |
3516 work = work->next; | |
3517 | |
3518 while (dupe_item_remove_by_path(dw, path)); | |
3519 } | |
3520 } | |
3521 | |
3522 void dupe_maint_renamed(const gchar *source, const gchar *dest) | |
3523 { | |
3524 GList *work; | |
3525 | |
3526 work = dupe_window_list; | |
3527 while (work) | |
3528 { | |
3529 DupeWindow *dw = work->data; | |
3530 work = work->next; | |
3531 | |
3532 while (dupe_item_set_path(dw, source, dest)); | |
3533 } | |
3534 | |
3535 } | |
3536 |