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