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