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