Mercurial > geeqie.yaz
annotate src/dupe.c @ 780:44128da39e13
Drop initialization to NULL since filelist_read() will take care of it.
author | zas_ |
---|---|
date | Tue, 03 Jun 2008 11:24:16 +0000 |
parents | 477f48ba28d8 |
children | d6a7fb4b8e7c |
rev | line source |
---|---|
9 | 1 /* |
196 | 2 * Geeqie |
9 | 3 * (C) 2005 John Ellis |
475 | 4 * Copyright (C) 2008 The Geeqie Team |
9 | 5 * |
6 * Author: John Ellis | |
7 * | |
8 * This software is released under the GNU General Public License (GNU GPL). | |
9 * Please read the included file COPYING for more information. | |
10 * This software comes with no warranty of any kind, use at your own risk! | |
11 */ | |
12 | |
13 | |
281 | 14 #include "main.h" |
9 | 15 #include "dupe.h" |
16 | |
17 #include "cache.h" | |
18 #include "collect.h" | |
19 #include "collect-table.h" | |
20 #include "dnd.h" | |
21 #include "editors.h" | |
586 | 22 #include "filedata.h" |
9 | 23 #include "image-load.h" |
24 #include "img-view.h" | |
25 #include "info.h" | |
26 #include "layout.h" | |
27 #include "layout_image.h" | |
28 #include "md5-util.h" | |
29 #include "menu.h" | |
30 #include "print.h" | |
31 #include "thumb.h" | |
32 #include "utilops.h" | |
33 #include "ui_bookmark.h" | |
34 #include "ui_fileops.h" | |
35 #include "ui_menu.h" | |
36 #include "ui_misc.h" | |
37 #include "ui_tree_edit.h" | |
648
e34c1002e553
Move some functions from main.[ch] to new window.[ch].
zas_
parents:
586
diff
changeset
|
38 #include "window.h" |
9 | 39 |
40 #include <gdk/gdkkeysyms.h> /* for keyboard values */ | |
41 | |
42 | |
43 #include <math.h> | |
44 | |
45 | |
46 #define DUPE_DEF_WIDTH 600 | |
47 #define DUPE_DEF_HEIGHT 400 | |
48 | |
49 /* column assignment order (simply change them here) */ | |
50 enum { | |
51 DUPE_COLUMN_POINTER = 0, | |
52 DUPE_COLUMN_RANK, | |
53 DUPE_COLUMN_THUMB, | |
54 DUPE_COLUMN_NAME, | |
55 DUPE_COLUMN_SIZE, | |
56 DUPE_COLUMN_DATE, | |
57 DUPE_COLUMN_DIMENSIONS, | |
58 DUPE_COLUMN_PATH, | |
59 DUPE_COLUMN_COLOR, | |
60 DUPE_COLUMN_COUNT /* total columns */ | |
61 }; | |
62 | |
63 | |
64 static GList *dupe_window_list = NULL; /* list of open DupeWindow *s */ | |
65 | |
66 /* | |
67 * Well, after adding the 'compare two sets' option things got a little sloppy in here | |
68 * because we have to account for two 'modes' everywhere. (be careful). | |
69 */ | |
70 | |
71 static void dupe_match_unlink(DupeItem *a, DupeItem *b); | |
72 static DupeItem *dupe_match_find_parent(DupeWindow *dw, DupeItem *child); | |
73 | |
74 static gint dupe_match(DupeItem *a, DupeItem *b, DupeMatchType mask, gdouble *rank, gint fast); | |
75 | |
76 static void dupe_thumb_step(DupeWindow *dw); | |
77 static gint dupe_check_cb(gpointer data); | |
78 | |
79 static void dupe_second_add(DupeWindow *dw, DupeItem *di); | |
80 static void dupe_second_remove(DupeWindow *dw, DupeItem *di); | |
81 static GtkWidget *dupe_menu_popup_second(DupeWindow *dw, DupeItem *di); | |
82 | |
83 static void dupe_dnd_init(DupeWindow *dw); | |
84 | |
85 /* | |
86 * ------------------------------------------------------------------ | |
87 * Window updates | |
88 * ------------------------------------------------------------------ | |
89 */ | |
90 | |
91 | |
92 static void dupe_window_update_count(DupeWindow *dw, gint count_only) | |
93 { | |
94 gchar *text; | |
95 | |
96 if (!dw->list) | |
97 { | |
98 text = g_strdup(_("Drop files to compare them.")); | |
99 } | |
100 else if (count_only) | |
101 { | |
102 text = g_strdup_printf(_("%d files"), g_list_length(dw->list)); | |
103 } | |
104 else | |
105 { | |
106 text = g_strdup_printf(_("%d matches found in %d files"), g_list_length(dw->dupes), g_list_length(dw->list)); | |
107 } | |
108 | |
109 if (dw->second_set) | |
110 { | |
111 gchar *buf = g_strconcat(text, " ", _("[set 1]"), NULL); | |
112 g_free(text); | |
113 text = buf; | |
114 } | |
115 gtk_label_set_text(GTK_LABEL(dw->status_label), text); | |
116 | |
117 g_free(text); | |
118 } | |
119 | |
120 static guint64 msec_time(void) | |
121 { | |
122 struct timeval tv; | |
123 | |
124 if (gettimeofday(&tv, NULL) == -1) return 0; | |
125 | |
126 return (guint64)tv.tv_sec * 1000000 + (guint64)tv.tv_usec; | |
127 } | |
128 | |
129 static gint dupe_iterations(gint n) | |
130 { | |
131 return (n * ((n + 1) / 2)); | |
132 } | |
133 | |
134 static void dupe_window_update_progress(DupeWindow *dw, const gchar *status, gdouble value, gint force) | |
135 { | |
136 const gchar *status_text; | |
137 | |
138 if (status) | |
139 { | |
140 guint64 new_time = 0; | |
141 | |
142 if (dw->setup_n % 10 == 0) | |
143 { | |
144 new_time = msec_time() - dw->setup_time; | |
145 } | |
442 | 146 |
9 | 147 if (!force && |
148 value != 0.0 && | |
149 dw->setup_count > 0 && | |
150 new_time > 2000000) | |
151 { | |
152 gchar *buf; | |
153 gint t; | |
154 gint d; | |
155 guint32 rem; | |
156 | |
157 if (new_time - dw->setup_time_count < 250000) return; | |
158 dw->setup_time_count = new_time; | |
159 | |
160 if (dw->setup_done) | |
161 { | |
162 if (dw->second_set) | |
163 { | |
164 t = dw->setup_count; | |
165 d = dw->setup_count - dw->setup_n; | |
166 } | |
167 else | |
168 { | |
169 t = dupe_iterations(dw->setup_count); | |
170 d = dupe_iterations(dw->setup_count - dw->setup_n); | |
171 } | |
172 } | |
173 else | |
174 { | |
175 t = dw->setup_count; | |
176 d = dw->setup_count - dw->setup_n; | |
177 } | |
178 | |
179 rem = (t - d) ? ((gdouble)(dw->setup_time_count / 1000000) / (t - d)) * d : 0; | |
180 | |
181 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(dw->extra_label), value); | |
182 | |
183 buf = g_strdup_printf("%s %d:%02d ", status, rem / 60, rem % 60); | |
184 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(dw->extra_label), buf); | |
185 g_free(buf); | |
186 | |
187 return; | |
188 } | |
189 else if (force || | |
190 value == 0.0 || | |
191 dw->setup_count == 0 || | |
192 dw->setup_time_count == 0 || | |
193 (new_time > 0 && new_time - dw->setup_time_count >= 250000)) | |
194 { | |
195 if (dw->setup_time_count == 0) dw->setup_time_count = 1; | |
196 if (new_time > 0) dw->setup_time_count = new_time; | |
197 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(dw->extra_label), value); | |
198 status_text = status; | |
199 } | |
200 else | |
201 { | |
202 status_text = NULL; | |
203 } | |
442 | 204 } |
9 | 205 else |
206 { | |
207 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(dw->extra_label), 0.0); | |
208 status_text = " "; | |
209 } | |
210 | |
211 if (status_text) gtk_progress_bar_set_text(GTK_PROGRESS_BAR(dw->extra_label), status_text); | |
212 } | |
213 | |
214 static void widget_set_cursor(GtkWidget *widget, gint icon) | |
215 { | |
216 GdkCursor *cursor; | |
217 | |
218 if (!widget->window) return; | |
442 | 219 |
9 | 220 if (icon == -1) |
221 { | |
222 cursor = NULL; | |
223 } | |
224 else | |
225 { | |
513
985fdfebd89e
Remove whitespace between function name and first parenthesis for the sake of consistency. (pass 2)
zas_
parents:
512
diff
changeset
|
226 cursor = gdk_cursor_new(icon); |
9 | 227 } |
442 | 228 |
9 | 229 gdk_window_set_cursor(widget->window, cursor); |
442 | 230 |
9 | 231 if (cursor) gdk_cursor_unref(cursor); |
232 } | |
233 | |
234 /* | |
235 * ------------------------------------------------------------------ | |
236 * row color utils | |
237 * ------------------------------------------------------------------ | |
238 */ | |
239 | |
240 static void dupe_listview_realign_colors(DupeWindow *dw) | |
241 { | |
242 GtkTreeModel *store; | |
243 GtkTreeIter iter; | |
244 gboolean color_set = TRUE; | |
245 DupeItem *parent = NULL; | |
246 gint valid; | |
247 | |
248 store = gtk_tree_view_get_model(GTK_TREE_VIEW(dw->listview)); | |
249 valid = gtk_tree_model_get_iter_first(store, &iter); | |
250 while (valid) | |
251 { | |
252 DupeItem *child; | |
253 DupeItem *child_parent; | |
254 | |
255 gtk_tree_model_get(store, &iter, DUPE_COLUMN_POINTER, &child, -1); | |
256 child_parent = dupe_match_find_parent(dw, child); | |
257 if (!parent || parent != child_parent) | |
258 { | |
259 if (!parent) | |
260 { | |
261 /* keep the first row as it is */ | |
262 gtk_tree_model_get(store, &iter, DUPE_COLUMN_COLOR, &color_set, -1); | |
263 } | |
264 else | |
265 { | |
266 color_set = !color_set; | |
267 } | |
268 parent = dupe_match_find_parent(dw, child); | |
269 } | |
270 gtk_list_store_set(GTK_LIST_STORE(store), &iter, DUPE_COLUMN_COLOR, color_set, -1); | |
271 | |
272 valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter); | |
273 } | |
274 } | |
275 | |
276 /* | |
277 * ------------------------------------------------------------------ | |
278 * Dupe item utils | |
279 * ------------------------------------------------------------------ | |
280 */ | |
281 | |
138 | 282 static DupeItem *dupe_item_new(FileData *fd) |
9 | 283 { |
284 DupeItem *di; | |
285 | |
286 di = g_new0(DupeItem, 1); | |
287 | |
138 | 288 di->fd = file_data_ref(fd); |
9 | 289 |
290 di->group = NULL; | |
291 di->group_rank = 0.0; | |
292 | |
293 di->simd = NULL; | |
294 di->checksum = 0; | |
295 di->md5sum = NULL; | |
296 di->width = 0; | |
297 di->height = 0; | |
298 | |
299 di->second = FALSE; | |
300 | |
301 return di; | |
302 } | |
303 | |
304 static void dupe_item_free(DupeItem *di) | |
305 { | |
138 | 306 file_data_unref(di->fd); |
9 | 307 image_sim_free(di->simd); |
308 g_free(di->md5sum); | |
309 if (di->pixbuf) g_object_unref(di->pixbuf); | |
310 | |
311 g_free(di); | |
312 } | |
313 | |
314 static void dupe_list_free(GList *list) | |
315 { | |
316 GList *work = list; | |
317 while (work) | |
318 { | |
319 DupeItem *di = work->data; | |
320 work = work->next; | |
321 dupe_item_free(di); | |
322 } | |
323 g_list_free(list); | |
324 } | |
325 | |
259 | 326 /* |
138 | 327 static DupeItem *dupe_item_find_fd_by_list(FileData *fd, GList *work) |
328 { | |
329 while (work) | |
330 { | |
331 DupeItem *di = work->data; | |
332 | |
333 if (di->fd == fd) return di; | |
334 | |
335 work = work->next; | |
336 } | |
337 | |
338 return NULL; | |
339 } | |
259 | 340 */ |
341 | |
342 /* | |
138 | 343 static DupeItem *dupe_item_find_fd(DupeWindow *dw, FileData *fd) |
344 { | |
345 DupeItem *di; | |
346 | |
347 di = dupe_item_find_fd_by_list(fd, dw->list); | |
348 if (!di && dw->second_set) di = dupe_item_find_fd_by_list(fd, dw->second_list); | |
349 | |
350 return di; | |
351 } | |
259 | 352 */ |
138 | 353 |
9 | 354 static DupeItem *dupe_item_find_path_by_list(const gchar *path, GList *work) |
355 { | |
356 while (work) | |
357 { | |
358 DupeItem *di = work->data; | |
359 | |
138 | 360 if (strcmp(di->fd->path, path) == 0) return di; |
9 | 361 |
362 work = work->next; | |
363 } | |
364 | |
365 return NULL; | |
366 } | |
367 | |
368 static DupeItem *dupe_item_find_path(DupeWindow *dw, const gchar *path) | |
369 { | |
370 DupeItem *di; | |
371 | |
372 di = dupe_item_find_path_by_list(path, dw->list); | |
373 if (!di && dw->second_set) di = dupe_item_find_path_by_list(path, dw->second_list); | |
374 | |
375 return di; | |
376 } | |
377 | |
378 /* | |
379 * ------------------------------------------------------------------ | |
380 * Image property cache | |
381 * ------------------------------------------------------------------ | |
382 */ | |
383 | |
384 static void dupe_item_read_cache(DupeItem *di) | |
385 { | |
386 gchar *path; | |
387 CacheData *cd; | |
388 | |
389 if (!di) return; | |
390 | |
138 | 391 path = cache_find_location(CACHE_TYPE_SIM, di->fd->path); |
9 | 392 if (!path) return; |
393 | |
138 | 394 if (filetime(di->fd->path) != filetime(path)) |
9 | 395 { |
396 g_free(path); | |
397 return; | |
398 } | |
399 | |
400 cd = cache_sim_data_load(path); | |
401 g_free(path); | |
402 | |
403 if (cd) | |
404 { | |
405 if (!di->simd && cd->sim) | |
406 { | |
407 di->simd = cd->sim; | |
408 cd->sim = NULL; | |
409 } | |
410 if (di->width == 0 && di->height == 0 && cd->dimensions) | |
411 { | |
412 di->width = cd->width; | |
413 di->height = cd->height; | |
414 } | |
415 if (di->checksum == 0 && cd->have_checksum) | |
416 { | |
417 di->checksum = cd->checksum; | |
418 } | |
419 if (!di->md5sum && cd->have_md5sum) | |
420 { | |
421 di->md5sum = md5_digest_to_text(cd->md5sum); | |
422 } | |
423 cache_sim_data_free(cd); | |
424 } | |
425 } | |
426 | |
427 static void dupe_item_write_cache(DupeItem *di) | |
428 { | |
429 gchar *base; | |
430 mode_t mode = 0755; | |
431 | |
432 if (!di) return; | |
433 | |
138 | 434 base = cache_get_location(CACHE_TYPE_SIM, di->fd->path, FALSE, &mode); |
9 | 435 if (cache_ensure_dir_exists(base, mode)) |
436 { | |
437 CacheData *cd; | |
438 | |
439 cd = cache_sim_data_new(); | |
138 | 440 cd->path = cache_get_location(CACHE_TYPE_SIM, di->fd->path, TRUE, NULL); |
9 | 441 |
442 if (di->width != 0) cache_sim_data_set_dimensions(cd, di->width, di->height); | |
443 if (di->checksum != 0) cache_sim_data_set_checksum(cd, di->checksum); | |
444 if (di->md5sum) | |
445 { | |
446 guchar digest[16]; | |
447 if (md5_digest_from_text(di->md5sum, digest)) cache_sim_data_set_md5sum(cd, digest); | |
448 } | |
449 if (di->simd) cache_sim_data_set_similarity(cd, di->simd); | |
450 | |
451 if (cache_sim_data_save(cd)) | |
452 { | |
138 | 453 filetime_set(cd->path, filetime(di->fd->path)); |
9 | 454 } |
455 cache_sim_data_free(cd); | |
456 } | |
457 g_free(base); | |
458 } | |
459 | |
460 /* | |
461 * ------------------------------------------------------------------ | |
462 * Window list utils | |
463 * ------------------------------------------------------------------ | |
464 */ | |
465 | |
466 static gint dupe_listview_find_item(GtkListStore *store, DupeItem *item, GtkTreeIter *iter) | |
467 { | |
468 gint valid; | |
469 gint row = 0; | |
470 | |
471 valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), iter); | |
472 while (valid) | |
473 { | |
474 DupeItem *item_n; | |
475 gtk_tree_model_get(GTK_TREE_MODEL(store), iter, DUPE_COLUMN_POINTER, &item_n, -1); | |
476 if (item_n == item) return row; | |
477 | |
478 valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), iter); | |
479 row++; | |
480 } | |
481 | |
482 return -1; | |
483 } | |
484 | |
485 static void dupe_listview_add(DupeWindow *dw, DupeItem *parent, DupeItem *child) | |
486 { | |
487 DupeItem *di; | |
488 gint row; | |
489 gchar *text[DUPE_COLUMN_COUNT]; | |
490 GtkListStore *store; | |
491 GtkTreeIter iter; | |
492 gboolean color_set = FALSE; | |
493 gint rank; | |
494 | |
495 if (!parent) return; | |
496 | |
497 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dw->listview))); | |
498 | |
499 if (child) | |
500 { | |
501 DupeMatch *dm; | |
502 | |
503 row = dupe_listview_find_item(store, parent, &iter); | |
504 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, DUPE_COLUMN_COLOR, &color_set, -1); | |
505 | |
506 row++; | |
507 | |
508 if (child->group) | |
509 { | |
510 dm = child->group->data; | |
511 rank = (gint)floor(dm->rank); | |
512 } | |
513 else | |
514 { | |
515 rank = 1; | |
673
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
516 log_printf("NULL group in item!\n"); |
9 | 517 } |
518 } | |
519 else | |
520 { | |
521 if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter)) | |
522 { | |
523 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, DUPE_COLUMN_COLOR, &color_set, -1); | |
524 color_set = !color_set; | |
525 } | |
526 else | |
527 { | |
528 color_set = FALSE; | |
529 } | |
530 row = 0; | |
531 rank = 0; | |
532 } | |
533 | |
534 di = (child) ? child : parent; | |
535 | |
536 if (!child && dw->second_set) | |
537 { | |
538 text[DUPE_COLUMN_RANK] = g_strdup("[1]"); | |
539 } | |
540 else if (rank == 0) | |
541 { | |
542 text[DUPE_COLUMN_RANK] = g_strdup((di->second) ? "(2)" : ""); | |
543 } | |
544 else | |
545 { | |
546 text[DUPE_COLUMN_RANK] = g_strdup_printf("%d%s", rank, (di->second) ? " (2)" : ""); | |
547 } | |
548 | |
549 text[DUPE_COLUMN_THUMB] = ""; | |
138 | 550 text[DUPE_COLUMN_NAME] = (gchar *)di->fd->name; |
551 text[DUPE_COLUMN_SIZE] = text_from_size(di->fd->size); | |
552 text[DUPE_COLUMN_DATE] = (gchar *)text_from_time(di->fd->date); | |
9 | 553 if (di->width > 0 && di->height > 0) |
554 { | |
555 text[DUPE_COLUMN_DIMENSIONS] = g_strdup_printf("%d x %d", di->width, di->height); | |
556 } | |
557 else | |
558 { | |
559 text[DUPE_COLUMN_DIMENSIONS] = g_strdup(""); | |
560 } | |
138 | 561 text[DUPE_COLUMN_PATH] = di->fd->path; |
9 | 562 text[DUPE_COLUMN_COLOR] = NULL; |
563 | |
564 gtk_list_store_insert(store, &iter, row); | |
565 gtk_list_store_set(store, &iter, | |
566 DUPE_COLUMN_POINTER, di, | |
567 DUPE_COLUMN_RANK, text[DUPE_COLUMN_RANK], | |
568 DUPE_COLUMN_THUMB, NULL, | |
569 DUPE_COLUMN_NAME, text[DUPE_COLUMN_NAME], | |
570 DUPE_COLUMN_SIZE, text[DUPE_COLUMN_SIZE], | |
571 DUPE_COLUMN_DATE, text[DUPE_COLUMN_DATE], | |
572 DUPE_COLUMN_DIMENSIONS, text[DUPE_COLUMN_DIMENSIONS], | |
573 DUPE_COLUMN_PATH, text[DUPE_COLUMN_PATH], | |
574 DUPE_COLUMN_COLOR, color_set, | |
575 -1); | |
576 | |
577 g_free(text[DUPE_COLUMN_RANK]); | |
578 g_free(text[DUPE_COLUMN_SIZE]); | |
579 g_free(text[DUPE_COLUMN_DIMENSIONS]); | |
580 } | |
581 | |
582 static void dupe_listview_populate(DupeWindow *dw) | |
583 { | |
584 GtkListStore *store; | |
585 GList *work; | |
586 | |
587 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dw->listview))); | |
588 gtk_list_store_clear(store); | |
589 | |
590 work = g_list_last(dw->dupes); | |
591 while (work) | |
592 { | |
593 DupeItem *parent = work->data; | |
594 GList *temp; | |
595 | |
596 dupe_listview_add(dw, parent, NULL); | |
597 | |
598 temp = g_list_last(parent->group); | |
599 while (temp) | |
600 { | |
601 DupeMatch *dm = temp->data; | |
602 DupeItem *child; | |
603 | |
604 child = dm->di; | |
605 | |
606 dupe_listview_add(dw, parent, child); | |
607 | |
608 temp = temp->prev; | |
609 } | |
610 | |
611 work = work->prev; | |
612 } | |
613 | |
614 gtk_tree_view_columns_autosize(GTK_TREE_VIEW(dw->listview)); | |
615 } | |
616 | |
617 static void dupe_listview_remove(DupeWindow *dw, DupeItem *di) | |
618 { | |
619 GtkListStore *store; | |
620 GtkTreeIter iter; | |
621 gint row; | |
622 | |
623 if (!di) return; | |
624 | |
625 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dw->listview))); | |
626 row = dupe_listview_find_item(store, di, &iter); | |
627 if (row < 0) return; | |
628 | |
629 tree_view_move_cursor_away(GTK_TREE_VIEW(dw->listview), &iter, TRUE); | |
630 gtk_list_store_remove(store, &iter); | |
631 | |
632 if (g_list_find(dw->dupes, di) != NULL) | |
633 { | |
634 if (!dw->color_frozen) dupe_listview_realign_colors(dw); | |
635 } | |
636 } | |
637 | |
638 | |
138 | 639 static GList *dupe_listview_get_filelist(DupeWindow *dw, GtkWidget *listview) |
9 | 640 { |
641 GtkTreeModel *store; | |
642 GtkTreeIter iter; | |
643 gint valid; | |
644 GList *list = NULL; | |
645 | |
646 store = gtk_tree_view_get_model(GTK_TREE_VIEW(listview)); | |
647 valid = gtk_tree_model_get_iter_first(store, &iter); | |
648 while (valid) | |
649 { | |
650 DupeItem *di; | |
651 gtk_tree_model_get(store, &iter, DUPE_COLUMN_POINTER, &di, -1); | |
138 | 652 list = g_list_prepend(list, file_data_ref(di->fd)); |
9 | 653 |
654 valid = gtk_tree_model_iter_next(store, &iter); | |
655 } | |
656 | |
657 return g_list_reverse(list); | |
658 } | |
659 | |
660 | |
661 static GList *dupe_listview_get_selection(DupeWindow *dw, GtkWidget *listview) | |
662 { | |
663 GtkTreeModel *store; | |
664 GtkTreeSelection *selection; | |
665 GList *slist; | |
666 GList *list = NULL; | |
667 GList *work; | |
668 | |
669 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(listview)); | |
670 slist = gtk_tree_selection_get_selected_rows(selection, &store); | |
671 work = slist; | |
672 while (work) | |
673 { | |
674 GtkTreePath *tpath = work->data; | |
675 DupeItem *di = NULL; | |
676 GtkTreeIter iter; | |
677 | |
678 gtk_tree_model_get_iter(store, &iter, tpath); | |
679 gtk_tree_model_get(store, &iter, DUPE_COLUMN_POINTER, &di, -1); | |
680 if (di) | |
681 { | |
138 | 682 list = g_list_prepend(list, file_data_ref(di->fd)); |
9 | 683 } |
684 work = work->next; | |
685 } | |
686 g_list_foreach(slist, (GFunc)gtk_tree_path_free, NULL); | |
687 g_list_free(slist); | |
688 | |
689 return g_list_reverse(list); | |
690 } | |
691 | |
692 static gint dupe_listview_item_is_selected(DupeWindow *dw, DupeItem *di, GtkWidget *listview) | |
693 { | |
694 GtkTreeModel *store; | |
695 GtkTreeSelection *selection; | |
696 GList *slist; | |
697 GList *work; | |
698 gint found = FALSE; | |
699 | |
700 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(listview)); | |
701 slist = gtk_tree_selection_get_selected_rows(selection, &store); | |
702 work = slist; | |
703 while (!found && work) | |
704 { | |
705 GtkTreePath *tpath = work->data; | |
706 DupeItem *di_n; | |
707 GtkTreeIter iter; | |
708 | |
709 gtk_tree_model_get_iter(store, &iter, tpath); | |
710 gtk_tree_model_get(store, &iter, DUPE_COLUMN_POINTER, &di_n, -1); | |
711 if (di_n == di) found = TRUE; | |
712 work = work->next; | |
713 } | |
714 g_list_foreach(slist, (GFunc)gtk_tree_path_free, NULL); | |
715 g_list_free(slist); | |
716 | |
717 return found; | |
718 } | |
719 | |
720 static void dupe_listview_select_dupes(DupeWindow *dw, gint parents) | |
721 { | |
722 GtkTreeModel *store; | |
723 GtkTreeSelection *selection; | |
724 GtkTreeIter iter; | |
725 gint valid; | |
726 | |
727 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dw->listview)); | |
728 gtk_tree_selection_unselect_all(selection); | |
729 | |
730 store = gtk_tree_view_get_model(GTK_TREE_VIEW(dw->listview)); | |
731 valid = gtk_tree_model_get_iter_first(store, &iter); | |
732 while (valid) | |
733 { | |
734 DupeItem *di; | |
735 | |
736 gtk_tree_model_get(store, &iter, DUPE_COLUMN_POINTER, &di, -1); | |
737 if ( (dupe_match_find_parent(dw, di) == di) == (parents) ) | |
738 { | |
739 gtk_tree_selection_select_iter(selection, &iter); | |
740 } | |
741 valid = gtk_tree_model_iter_next(store, &iter); | |
742 } | |
743 } | |
744 | |
745 /* | |
746 * ------------------------------------------------------------------ | |
747 * Match group manipulation | |
748 * ------------------------------------------------------------------ | |
749 */ | |
750 | |
751 static DupeMatch *dupe_match_find_match(DupeItem *child, DupeItem *parent) | |
752 { | |
753 GList *work; | |
754 | |
755 work = parent->group; | |
756 while (work) | |
757 { | |
758 DupeMatch *dm = work->data; | |
759 if (dm->di == child) return dm; | |
760 work = work->next; | |
761 } | |
762 return NULL; | |
763 } | |
764 | |
765 static void dupe_match_link_child(DupeItem *child, DupeItem *parent, gdouble rank) | |
766 { | |
767 DupeMatch *dm; | |
768 | |
769 dm = g_new0(DupeMatch, 1); | |
770 dm->di = child; | |
771 dm->rank = rank; | |
772 parent->group = g_list_append(parent->group, dm); | |
773 } | |
774 | |
775 static void dupe_match_link(DupeItem *a, DupeItem *b, gdouble rank) | |
776 { | |
777 dupe_match_link_child(a, b, rank); | |
778 dupe_match_link_child(b, a, rank); | |
779 } | |
780 | |
781 static void dupe_match_unlink_child(DupeItem *child, DupeItem *parent) | |
782 { | |
783 DupeMatch *dm; | |
784 | |
785 dm = dupe_match_find_match(child, parent); | |
786 if (dm) | |
787 { | |
788 parent->group = g_list_remove(parent->group, dm); | |
789 g_free(dm); | |
790 } | |
791 } | |
792 | |
793 static void dupe_match_unlink(DupeItem *a, DupeItem *b) | |
794 { | |
795 dupe_match_unlink_child(a, b); | |
796 dupe_match_unlink_child(b, a); | |
797 } | |
798 | |
799 static void dupe_match_link_clear(DupeItem *parent, gint unlink_children) | |
800 { | |
801 GList *work; | |
442 | 802 |
9 | 803 work = parent->group; |
804 while (work) | |
805 { | |
806 DupeMatch *dm = work->data; | |
807 work = work->next; | |
808 | |
809 if (unlink_children) dupe_match_unlink_child(parent, dm->di); | |
810 | |
811 g_free(dm); | |
812 } | |
813 | |
814 g_list_free(parent->group); | |
815 parent->group = NULL; | |
816 parent->group_rank = 0.0; | |
817 } | |
818 | |
819 static gint dupe_match_link_exists(DupeItem *child, DupeItem *parent) | |
820 { | |
821 return (dupe_match_find_match(child, parent) != NULL); | |
822 } | |
823 | |
824 static gdouble dupe_match_link_rank(DupeItem *child, DupeItem *parent) | |
825 { | |
826 DupeMatch *dm; | |
827 | |
828 dm = dupe_match_find_match(child, parent); | |
829 if (dm) return dm->rank; | |
830 | |
831 return 0.0; | |
832 } | |
833 | |
834 static DupeItem *dupe_match_highest_rank(DupeItem *child) | |
835 { | |
836 DupeMatch *dr; | |
837 GList *work; | |
838 | |
839 dr = NULL; | |
840 work = child->group; | |
841 while (work) | |
842 { | |
843 DupeMatch *dm = work->data; | |
844 if (!dr || dm->rank > dr->rank) dr = dm; | |
845 work = work->next; | |
846 } | |
847 | |
848 return (dr) ? dr->di : NULL; | |
849 } | |
850 | |
851 static void dupe_match_rank_update(DupeItem *parent) | |
852 { | |
853 GList *work; | |
854 gdouble rank = 0.0; | |
855 gint c = 0; | |
856 | |
857 work = parent->group; | |
858 while (work) | |
859 { | |
860 DupeMatch *dm = work->data; | |
861 work = work->next; | |
862 rank += dm->rank; | |
863 c++; | |
864 } | |
865 | |
866 if (c > 0) | |
867 { | |
868 parent->group_rank = rank / c; | |
869 } | |
870 else | |
871 { | |
872 parent->group_rank = 0.0; | |
873 } | |
874 } | |
875 | |
876 static DupeItem *dupe_match_find_parent(DupeWindow *dw, DupeItem *child) | |
877 { | |
878 GList *work; | |
879 | |
880 if (g_list_find(dw->dupes, child)) return child; | |
881 | |
882 work = child->group; | |
883 while (work) | |
884 { | |
885 DupeMatch *dm = work->data; | |
886 if (g_list_find(dw->dupes, dm->di)) return dm->di; | |
887 work = work->next; | |
888 } | |
889 | |
890 return NULL; | |
891 } | |
892 | |
893 static void dupe_match_reset_list(GList *work) | |
894 { | |
895 while (work) | |
896 { | |
897 DupeItem *di = work->data; | |
898 work = work->next; | |
899 | |
900 dupe_match_link_clear(di, FALSE); | |
901 } | |
902 } | |
903 | |
904 static void dupe_match_reparent(DupeWindow *dw, DupeItem *old, DupeItem *new) | |
905 { | |
906 GList *work; | |
907 | |
908 if (!old || !new || !dupe_match_link_exists(old, new)) return; | |
909 | |
910 dupe_match_link_clear(new, TRUE); | |
911 work = old->group; | |
912 while (work) | |
913 { | |
914 DupeMatch *dm = work->data; | |
915 dupe_match_unlink_child(old, dm->di); | |
916 dupe_match_link_child(new, dm->di, dm->rank); | |
917 work = work->next; | |
918 } | |
919 | |
920 new->group = old->group; | |
921 old->group = NULL; | |
922 | |
923 work = g_list_find(dw->dupes, old); | |
924 if (work) work->data = new; | |
925 } | |
926 | |
927 static void dupe_match_print_group(DupeItem *di) | |
928 { | |
929 GList *work; | |
930 | |
673
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
931 log_printf("+ %f %s\n", di->group_rank, di->fd->name); |
9 | 932 |
933 work = di->group; | |
934 while (work) | |
935 { | |
936 DupeMatch *dm = work->data; | |
937 work = work->next; | |
938 | |
673
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
939 log_printf(" %f %s\n", dm->rank, dm->di->fd->name); |
9 | 940 } |
941 | |
673
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
942 log_printf("\n"); |
9 | 943 } |
944 | |
945 static void dupe_match_print_list(GList *list) | |
946 { | |
947 GList *work; | |
948 | |
949 work = list; | |
950 while (work) | |
951 { | |
952 DupeItem *di = work->data; | |
953 dupe_match_print_group(di); | |
954 work = work->next; | |
955 } | |
956 } | |
957 | |
958 /* level 3, unlinking and orphan handling */ | |
959 static GList *dupe_match_unlink_by_rank(DupeItem *child, DupeItem *parent, GList *list, DupeWindow *dw) | |
960 { | |
961 DupeItem *best; | |
962 | |
963 best = dupe_match_highest_rank(parent); | |
964 if (best == child || dupe_match_highest_rank(child) == parent) | |
965 { | |
966 GList *work; | |
967 gdouble rank; | |
968 | |
506
fc9c8a3e1a8b
Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents:
497
diff
changeset
|
969 DEBUG_2("link found %s to %s [%d]", child->fd->name, parent->fd->name, g_list_length(parent->group)); |
9 | 970 |
971 work = parent->group; | |
972 while (work) | |
973 { | |
974 DupeMatch *dm = work->data; | |
975 DupeItem *orphan; | |
976 | |
977 work = work->next; | |
978 orphan = dm->di; | |
979 if (orphan != child && g_list_length(orphan->group) < 2) | |
980 { | |
981 dupe_match_link_clear(orphan, TRUE); | |
982 if (!dw->second_set || orphan->second) | |
983 { | |
984 dupe_match(orphan, child, dw->match_mask, &rank, FALSE); | |
985 dupe_match_link(orphan, child, rank); | |
986 } | |
987 list = g_list_remove(list, orphan); | |
988 } | |
989 } | |
442 | 990 |
9 | 991 rank = dupe_match_link_rank(child, parent); |
992 dupe_match_link_clear(parent, TRUE); | |
993 dupe_match_link(child, parent, rank); | |
994 list = g_list_remove(list, parent); | |
995 } | |
996 else | |
997 { | |
506
fc9c8a3e1a8b
Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents:
497
diff
changeset
|
998 DEBUG_2("unlinking %s and %s", child->fd->name, parent->fd->name); |
442 | 999 |
9 | 1000 dupe_match_unlink(child, parent); |
1001 } | |
1002 | |
1003 return list; | |
1004 } | |
1005 | |
1006 /* level 2 */ | |
1007 static GList *dupe_match_group_filter(GList *list, DupeItem *di, DupeWindow *dw) | |
1008 { | |
1009 GList *work; | |
1010 | |
1011 work = g_list_last(di->group); | |
1012 while (work) | |
1013 { | |
1014 DupeMatch *dm = work->data; | |
1015 work = work->prev; | |
1016 list = dupe_match_unlink_by_rank(di, dm->di, list, dw); | |
1017 } | |
1018 | |
1019 return list; | |
1020 } | |
1021 | |
1022 /* level 1 (top) */ | |
1023 static GList *dupe_match_group_trim(GList *list, DupeWindow *dw) | |
1024 { | |
1025 GList *work; | |
1026 | |
1027 work = list; | |
1028 while (work) | |
1029 { | |
1030 DupeItem *di = work->data; | |
1031 if (!di->second) list = dupe_match_group_filter(list, di, dw); | |
1032 work = work->next; | |
1033 if (di->second) list = g_list_remove(list, di); | |
1034 } | |
1035 | |
1036 return list; | |
1037 } | |
1038 | |
1039 static gint dupe_match_sort_groups_cb(gconstpointer a, gconstpointer b) | |
1040 { | |
1041 DupeMatch *da = (DupeMatch *)a; | |
1042 DupeMatch *db = (DupeMatch *)b; | |
1043 | |
1044 if (da->rank > db->rank) return -1; | |
1045 if (da->rank < db->rank) return 1; | |
1046 return 0; | |
1047 } | |
1048 | |
1049 static void dupe_match_sort_groups(GList *list) | |
1050 { | |
1051 GList *work; | |
1052 | |
1053 work = list; | |
1054 while (work) | |
1055 { | |
1056 DupeItem *di = work->data; | |
1057 di->group = g_list_sort(di->group, dupe_match_sort_groups_cb); | |
1058 work = work->next; | |
1059 } | |
1060 } | |
1061 | |
1062 static gint dupe_match_rank_sort_cb(gconstpointer a, gconstpointer b) | |
1063 { | |
1064 DupeItem *da = (DupeItem *)a; | |
1065 DupeItem *db = (DupeItem *)b; | |
1066 | |
1067 if (da->group_rank > db->group_rank) return -1; | |
1068 if (da->group_rank < db->group_rank) return 1; | |
1069 return 0; | |
1070 } | |
1071 | |
1072 /* returns allocated GList of dupes sorted by rank */ | |
1073 static GList *dupe_match_rank_sort(GList *source_list) | |
1074 { | |
1075 GList *list = NULL; | |
1076 GList *work; | |
1077 | |
1078 work = source_list; | |
1079 while (work) | |
1080 { | |
1081 DupeItem *di = work->data; | |
1082 | |
1083 if (di->group) | |
1084 { | |
1085 dupe_match_rank_update(di); | |
1086 list = g_list_prepend(list, di); | |
1087 } | |
442 | 1088 |
9 | 1089 work = work->next; |
1090 } | |
1091 | |
1092 return g_list_sort(list, dupe_match_rank_sort_cb); | |
1093 } | |
1094 | |
1095 static void dupe_match_rank(DupeWindow *dw) | |
1096 { | |
1097 GList *list; | |
1098 | |
1099 list = dupe_match_rank_sort(dw->list); | |
1100 | |
507 | 1101 if (required_debug_level(2)) dupe_match_print_list(list); |
495 | 1102 |
506
fc9c8a3e1a8b
Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents:
497
diff
changeset
|
1103 DEBUG_1("Similar items: %d", g_list_length(list)); |
9 | 1104 list = dupe_match_group_trim(list, dw); |
506
fc9c8a3e1a8b
Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents:
497
diff
changeset
|
1105 DEBUG_1("Unique groups: %d", g_list_length(list)); |
9 | 1106 |
1107 dupe_match_sort_groups(list); | |
1108 | |
507 | 1109 if (required_debug_level(2)) dupe_match_print_list(list); |
9 | 1110 |
1111 list = dupe_match_rank_sort(list); | |
1112 | |
1113 g_list_free(dw->dupes); | |
1114 dw->dupes = list; | |
1115 } | |
1116 | |
1117 /* | |
1118 * ------------------------------------------------------------------ | |
1119 * Match group tests | |
1120 * ------------------------------------------------------------------ | |
1121 */ | |
1122 | |
1123 static gint dupe_match(DupeItem *a, DupeItem *b, DupeMatchType mask, gdouble *rank, gint fast) | |
1124 { | |
1125 *rank = 0.0; | |
1126 | |
1127 if (a == b) return FALSE; | |
1128 | |
1129 if (mask & DUPE_MATCH_PATH) | |
1130 { | |
138 | 1131 if (strcmp(a->fd->path, b->fd->path) != 0) return FALSE; |
9 | 1132 } |
1133 if (mask & DUPE_MATCH_NAME) | |
1134 { | |
138 | 1135 if (strcmp(a->fd->name, b->fd->name) != 0) return FALSE; |
9 | 1136 } |
264
1015282898fe
Add the possibility to match duplicates on the name but ignoring the case.
zas_
parents:
259
diff
changeset
|
1137 if (mask & DUPE_MATCH_NAME_CI) |
1015282898fe
Add the possibility to match duplicates on the name but ignoring the case.
zas_
parents:
259
diff
changeset
|
1138 { |
1015282898fe
Add the possibility to match duplicates on the name but ignoring the case.
zas_
parents:
259
diff
changeset
|
1139 if (strcasecmp(a->fd->name, b->fd->name) != 0) return FALSE; |
1015282898fe
Add the possibility to match duplicates on the name but ignoring the case.
zas_
parents:
259
diff
changeset
|
1140 } |
9 | 1141 if (mask & DUPE_MATCH_SIZE) |
1142 { | |
138 | 1143 if (a->fd->size != b->fd->size) return FALSE; |
9 | 1144 } |
1145 if (mask & DUPE_MATCH_DATE) | |
1146 { | |
138 | 1147 if (a->fd->date != b->fd->date) return FALSE; |
9 | 1148 } |
1149 if (mask & DUPE_MATCH_SUM) | |
1150 { | |
138 | 1151 if (!a->md5sum) a->md5sum = md5_text_from_file_utf8(a->fd->path, ""); |
1152 if (!b->md5sum) b->md5sum = md5_text_from_file_utf8(b->fd->path, ""); | |
9 | 1153 if (a->md5sum[0] == '\0' || |
1154 b->md5sum[0] == '\0' || | |
1155 strcmp(a->md5sum, b->md5sum) != 0) return FALSE; | |
1156 } | |
1157 if (mask & DUPE_MATCH_DIM) | |
1158 { | |
138 | 1159 if (a->width == 0) image_load_dimensions(a->fd, &a->width, &a->height); |
1160 if (b->width == 0) image_load_dimensions(b->fd, &b->width, &b->height); | |
9 | 1161 if (a->width != b->width || a->height != b->height) return FALSE; |
1162 } | |
1163 if (mask & DUPE_MATCH_SIM_HIGH || | |
1164 mask & DUPE_MATCH_SIM_MED || | |
1165 mask & DUPE_MATCH_SIM_LOW || | |
1166 mask & DUPE_MATCH_SIM_CUSTOM) | |
1167 { | |
1168 gdouble f; | |
1169 gdouble m; | |
1170 | |
1171 if (mask & DUPE_MATCH_SIM_HIGH) m = 0.95; | |
1172 else if (mask & DUPE_MATCH_SIM_MED) m = 0.90; | |
342
07490120df2d
Rename dupe_custom_threshold option to duplicates_similarity_threshold.
zas_
parents:
333
diff
changeset
|
1173 else if (mask & DUPE_MATCH_SIM_CUSTOM) m = (gdouble)options->duplicates_similarity_threshold / 100.0; |
9 | 1174 else m = 0.85; |
1175 | |
1176 if (fast) | |
1177 { | |
1178 f = image_sim_compare_fast(a->simd, b->simd, m); | |
1179 } | |
1180 else | |
1181 { | |
1182 f = image_sim_compare(a->simd, b->simd); | |
1183 } | |
1184 | |
1185 *rank = f * 100.0; | |
1186 | |
1187 if (f < m) return FALSE; | |
1188 | |
506
fc9c8a3e1a8b
Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents:
497
diff
changeset
|
1189 DEBUG_3("similar: %32s %32s = %f", a->fd->name, b->fd->name, f); |
9 | 1190 } |
1191 | |
1192 return TRUE; | |
1193 } | |
1194 | |
1195 static void dupe_list_check_match(DupeWindow *dw, DupeItem *needle, GList *start) | |
1196 { | |
1197 GList *work; | |
1198 | |
1199 if (dw->second_set) | |
1200 { | |
1201 work = dw->second_list; | |
1202 } | |
1203 else if (start) | |
1204 { | |
1205 work = start; | |
1206 } | |
1207 else | |
1208 { | |
1209 work = g_list_last(dw->list); | |
1210 } | |
1211 | |
1212 while (work) | |
1213 { | |
1214 DupeItem *di = work->data; | |
1215 | |
1216 /* speed opt: forward for second set, back for simple compare */ | |
1217 if (dw->second_set) | |
1218 work = work->next; | |
1219 else | |
1220 work = work->prev; | |
1221 | |
1222 if (!dupe_match_link_exists(needle, di)) | |
1223 { | |
1224 gdouble rank; | |
1225 | |
1226 if (dupe_match(di, needle, dw->match_mask, &rank, TRUE)) | |
1227 { | |
1228 dupe_match_link(di, needle, rank); | |
1229 } | |
1230 } | |
1231 } | |
1232 } | |
1233 | |
1234 /* | |
1235 * ------------------------------------------------------------------ | |
1236 * Thumbnail handling | |
1237 * ------------------------------------------------------------------ | |
1238 */ | |
1239 | |
1240 static void dupe_listview_set_thumb(DupeWindow *dw, DupeItem *di, GtkTreeIter *iter) | |
1241 { | |
1242 GtkListStore *store; | |
1243 GtkTreeIter iter_n; | |
1244 | |
1245 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dw->listview))); | |
1246 if (!iter) | |
1247 { | |
1248 if (dupe_listview_find_item(store, di, &iter_n) >= 0) | |
1249 { | |
1250 iter = &iter_n; | |
1251 } | |
1252 } | |
1253 | |
1254 if (iter) gtk_list_store_set(store, iter, DUPE_COLUMN_THUMB, di->pixbuf, -1); | |
1255 } | |
1256 | |
1257 static void dupe_thumb_do(DupeWindow *dw) | |
1258 { | |
1259 DupeItem *di; | |
1260 | |
1261 if (!dw->thumb_loader || !dw->thumb_item) return; | |
1262 di = dw->thumb_item; | |
1263 | |
1264 if (di->pixbuf) g_object_unref(di->pixbuf); | |
1265 di->pixbuf = thumb_loader_get_pixbuf(dw->thumb_loader, TRUE); | |
1266 | |
1267 dupe_listview_set_thumb(dw, di, NULL); | |
1268 } | |
1269 | |
1270 static void dupe_thumb_error_cb(ThumbLoader *tl, gpointer data) | |
1271 { | |
1272 DupeWindow *dw = data; | |
1273 | |
1274 dupe_thumb_do(dw); | |
1275 dupe_thumb_step(dw); | |
1276 } | |
1277 | |
1278 static void dupe_thumb_done_cb(ThumbLoader *tl, gpointer data) | |
1279 { | |
1280 DupeWindow *dw = data; | |
1281 | |
1282 dupe_thumb_do(dw); | |
1283 dupe_thumb_step(dw); | |
1284 } | |
1285 | |
1286 static void dupe_thumb_step(DupeWindow *dw) | |
1287 { | |
1288 GtkTreeModel *store; | |
1289 GtkTreeIter iter; | |
1290 DupeItem *di = NULL; | |
1291 gint valid; | |
1292 gint row = 0; | |
1293 gint length = 0; | |
1294 | |
1295 store = gtk_tree_view_get_model(GTK_TREE_VIEW(dw->listview)); | |
1296 valid = gtk_tree_model_get_iter_first(store, &iter); | |
1297 | |
1298 while (!di && valid) | |
1299 { | |
1300 GdkPixbuf *pixbuf; | |
1301 | |
1302 length++; | |
1303 gtk_tree_model_get(store, &iter, DUPE_COLUMN_POINTER, &di, DUPE_COLUMN_THUMB, &pixbuf, -1); | |
1304 if (pixbuf || di->pixbuf) | |
1305 { | |
1306 if (!pixbuf) gtk_list_store_set(GTK_LIST_STORE(store), &iter, DUPE_COLUMN_THUMB, di->pixbuf, -1); | |
1307 row++; | |
1308 di = NULL; | |
1309 } | |
1310 valid = gtk_tree_model_iter_next(store, &iter); | |
1311 } | |
1312 if (valid) | |
1313 { | |
1314 while (gtk_tree_model_iter_next(store, &iter)) length++; | |
1315 } | |
1316 | |
1317 if (!di) | |
1318 { | |
1319 dw->thumb_item = NULL; | |
1320 thumb_loader_free(dw->thumb_loader); | |
1321 dw->thumb_loader = NULL; | |
1322 | |
1323 dupe_window_update_progress(dw, NULL, 0.0, FALSE); | |
1324 return; | |
1325 } | |
1326 | |
1327 dupe_window_update_progress(dw, _("Loading thumbs..."), | |
1328 length == 0 ? 0.0 : (gdouble)(row) / length, FALSE); | |
1329 | |
1330 dw->thumb_item = di; | |
1331 thumb_loader_free(dw->thumb_loader); | |
333 | 1332 dw->thumb_loader = thumb_loader_new(options->thumbnails.max_width, options->thumbnails.max_height); |
9 | 1333 |
1334 thumb_loader_set_callbacks(dw->thumb_loader, | |
1335 dupe_thumb_done_cb, | |
1336 dupe_thumb_error_cb, | |
1337 NULL, | |
1338 dw); | |
1339 | |
1340 /* start it */ | |
138 | 1341 if (!thumb_loader_start(dw->thumb_loader, di->fd->path)) |
9 | 1342 { |
1343 /* error, handle it, do next */ | |
506
fc9c8a3e1a8b
Handle the newline in DEBUG_N() macro instead of adding one
zas_
parents:
497
diff
changeset
|
1344 DEBUG_1("error loading thumb for %s", di->fd->path); |
9 | 1345 dupe_thumb_do(dw); |
1346 dupe_thumb_step(dw); | |
1347 } | |
1348 } | |
1349 | |
1350 /* | |
1351 * ------------------------------------------------------------------ | |
1352 * Dupe checking loop | |
1353 * ------------------------------------------------------------------ | |
1354 */ | |
1355 | |
1356 static void dupe_check_stop(DupeWindow *dw) | |
1357 { | |
1358 if (dw->idle_id != -1 || dw->img_loader || dw->thumb_loader) | |
1359 { | |
1360 g_source_remove(dw->idle_id); | |
1361 dw->idle_id = -1; | |
1362 dupe_window_update_progress(dw, NULL, 0.0, FALSE); | |
1363 widget_set_cursor(dw->listview, -1); | |
1364 } | |
1365 | |
1366 thumb_loader_free(dw->thumb_loader); | |
1367 dw->thumb_loader = NULL; | |
1368 | |
1369 image_loader_free(dw->img_loader); | |
1370 dw->img_loader = NULL; | |
1371 } | |
1372 | |
1373 static void dupe_loader_done_cb(ImageLoader *il, gpointer data) | |
1374 { | |
1375 DupeWindow *dw = data; | |
1376 GdkPixbuf *pixbuf; | |
1377 | |
1378 pixbuf = image_loader_get_pixbuf(il); | |
1379 | |
1380 if (dw->setup_point) | |
1381 { | |
1382 DupeItem *di = dw->setup_point->data; | |
1383 | |
1384 if (!di->simd) | |
1385 { | |
1386 di->simd = image_sim_new_from_pixbuf(pixbuf); | |
1387 } | |
1388 else | |
1389 { | |
1390 image_sim_fill_data(di->simd, pixbuf); | |
1391 } | |
1392 | |
1393 if (di->width == 0 && di->height == 0) | |
1394 { | |
1395 di->width = gdk_pixbuf_get_width(pixbuf); | |
1396 di->height = gdk_pixbuf_get_height(pixbuf); | |
1397 } | |
333 | 1398 if (options->thumbnails.enable_caching) |
9 | 1399 { |
1400 dupe_item_write_cache(di); | |
1401 } | |
1402 | |
1403 image_sim_alternate_processing(di->simd); | |
1404 } | |
1405 | |
1406 image_loader_free(dw->img_loader); | |
1407 dw->img_loader = NULL; | |
1408 | |
1409 dw->idle_id = g_idle_add(dupe_check_cb, dw); | |
1410 } | |
1411 | |
1412 static void dupe_setup_reset(DupeWindow *dw) | |
1413 { | |
1414 dw->setup_point = NULL; | |
1415 dw->setup_n = 0; | |
1416 dw->setup_time = msec_time(); | |
1417 dw->setup_time_count = 0; | |
1418 } | |
1419 | |
1420 static GList *dupe_setup_point_step(DupeWindow *dw, GList *p) | |
1421 { | |
1422 if (!p) return NULL; | |
1423 | |
1424 if (p->next) return p->next; | |
1425 | |
1426 if (dw->second_set && g_list_first(p) == dw->list) return dw->second_list; | |
1427 | |
1428 return NULL; | |
1429 } | |
1430 | |
1431 static gint dupe_check_cb(gpointer data) | |
1432 { | |
1433 DupeWindow *dw = data; | |
1434 | |
1435 if (dw->idle_id == -1) return FALSE; | |
1436 | |
1437 if (!dw->setup_done) | |
1438 { | |
1439 if ((dw->match_mask & DUPE_MATCH_SUM) && | |
1440 !(dw->setup_mask & DUPE_MATCH_SUM) ) | |
1441 { | |
1442 if (!dw->setup_point) dw->setup_point = dw->list; | |
1443 | |
1444 while (dw->setup_point) | |
1445 { | |
1446 DupeItem *di = dw->setup_point->data; | |
1447 | |
1448 dw->setup_point = dupe_setup_point_step(dw, dw->setup_point); | |
1449 dw->setup_n++; | |
1450 | |
1451 if (!di->md5sum) | |
1452 { | |
1453 dupe_window_update_progress(dw, _("Reading checksums..."), | |
1454 dw->setup_count == 0 ? 0.0 : (gdouble)(dw->setup_n - 1) / dw->setup_count, FALSE); | |
1455 | |
333 | 1456 if (options->thumbnails.enable_caching) |
9 | 1457 { |
1458 dupe_item_read_cache(di); | |
1459 if (di->md5sum) return TRUE; | |
1460 } | |
1461 | |
138 | 1462 di->md5sum = md5_text_from_file_utf8(di->fd->path, ""); |
333 | 1463 if (options->thumbnails.enable_caching) |
9 | 1464 { |
1465 dupe_item_write_cache(di); | |
1466 } | |
1467 return TRUE; | |
1468 } | |
1469 } | |
1470 dw->setup_mask |= DUPE_MATCH_SUM; | |
1471 dupe_setup_reset(dw); | |
1472 } | |
1473 if ((dw->match_mask & DUPE_MATCH_DIM) && | |
1474 !(dw->setup_mask & DUPE_MATCH_DIM) ) | |
1475 { | |
1476 if (!dw->setup_point) dw->setup_point = dw->list; | |
1477 | |
1478 while (dw->setup_point) | |
1479 { | |
1480 DupeItem *di = dw->setup_point->data; | |
1481 | |
1482 dw->setup_point = dupe_setup_point_step(dw, dw->setup_point); | |
1483 dw->setup_n++; | |
1484 if (di->width == 0 && di->height == 0) | |
1485 { | |
1486 dupe_window_update_progress(dw, _("Reading dimensions..."), | |
1487 dw->setup_count == 0 ? 0.0 : (gdouble)(dw->setup_n - 1) / dw->setup_count, FALSE); | |
1488 | |
333 | 1489 if (options->thumbnails.enable_caching) |
9 | 1490 { |
1491 dupe_item_read_cache(di); | |
1492 if (di->width != 0 || di->height != 0) return TRUE; | |
1493 } | |
1494 | |
138 | 1495 image_load_dimensions(di->fd, &di->width, &di->height); |
333 | 1496 if (options->thumbnails.enable_caching) |
9 | 1497 { |
1498 dupe_item_write_cache(di); | |
1499 } | |
1500 return TRUE; | |
1501 } | |
1502 } | |
1503 dw->setup_mask |= DUPE_MATCH_DIM; | |
1504 dupe_setup_reset(dw); | |
1505 } | |
1506 if ((dw->match_mask & DUPE_MATCH_SIM_HIGH || | |
1507 dw->match_mask & DUPE_MATCH_SIM_MED || | |
1508 dw->match_mask & DUPE_MATCH_SIM_LOW || | |
1509 dw->match_mask & DUPE_MATCH_SIM_CUSTOM) && | |
1510 !(dw->setup_mask & DUPE_MATCH_SIM_MED) ) | |
1511 { | |
1512 if (!dw->setup_point) dw->setup_point = dw->list; | |
1513 | |
1514 while (dw->setup_point) | |
1515 { | |
1516 DupeItem *di = dw->setup_point->data; | |
1517 | |
1518 if (!di->simd) | |
1519 { | |
1520 dupe_window_update_progress(dw, _("Reading similarity data..."), | |
1521 dw->setup_count == 0 ? 0.0 : (gdouble)dw->setup_n / dw->setup_count, FALSE); | |
1522 | |
333 | 1523 if (options->thumbnails.enable_caching) |
9 | 1524 { |
1525 dupe_item_read_cache(di); | |
1526 if (cache_sim_data_filled(di->simd)) | |
1527 { | |
1528 image_sim_alternate_processing(di->simd); | |
1529 return TRUE; | |
1530 } | |
1531 } | |
1532 | |
138 | 1533 dw->img_loader = image_loader_new(di->fd); |
9 | 1534 image_loader_set_buffer_size(dw->img_loader, 8); |
1535 image_loader_set_error_func(dw->img_loader, dupe_loader_done_cb, dw); | |
1536 | |
1537 if (!image_loader_start(dw->img_loader, dupe_loader_done_cb, dw)) | |
1538 { | |
1539 image_sim_free(di->simd); | |
1540 di->simd = image_sim_new(); | |
1541 image_loader_free(dw->img_loader); | |
1542 dw->img_loader = NULL; | |
1543 return TRUE; | |
1544 } | |
1545 dw->idle_id = -1; | |
1546 return FALSE; | |
1547 } | |
1548 | |
1549 dw->setup_point = dupe_setup_point_step(dw, dw->setup_point); | |
1550 dw->setup_n++; | |
1551 } | |
1552 dw->setup_mask |= DUPE_MATCH_SIM_MED; | |
1553 dupe_setup_reset(dw); | |
1554 } | |
1555 dupe_window_update_progress(dw, _("Comparing..."), 0.0, FALSE); | |
1556 dw->setup_done = TRUE; | |
1557 dupe_setup_reset(dw); | |
1558 dw->setup_count = g_list_length(dw->list); | |
1559 } | |
1560 | |
1561 if (!dw->working) | |
1562 { | |
1563 if (dw->setup_count > 0) | |
1564 { | |
1565 dw->setup_count = 0; | |
1566 dupe_window_update_progress(dw, _("Sorting..."), 1.0, TRUE); | |
1567 return TRUE; | |
1568 } | |
1569 dw->idle_id = -1; | |
1570 dupe_window_update_progress(dw, NULL, 0.0, FALSE); | |
1571 | |
1572 dupe_match_rank(dw); | |
1573 dupe_window_update_count(dw, FALSE); | |
1574 | |
1575 dupe_listview_populate(dw); | |
1576 | |
1577 /* check thumbs */ | |
1578 if (dw->show_thumbs) dupe_thumb_step(dw); | |
1579 | |
1580 widget_set_cursor(dw->listview, -1); | |
1581 | |
1582 return FALSE; | |
1583 } | |
1584 | |
1585 dupe_list_check_match(dw, (DupeItem *)dw->working->data, dw->working); | |
1586 dupe_window_update_progress(dw, _("Comparing..."), dw->setup_count == 0 ? 0.0 : (gdouble) dw->setup_n / dw->setup_count, FALSE); | |
1587 dw->setup_n++; | |
1588 | |
1589 dw->working = dw->working->prev; | |
1590 | |
1591 return TRUE; | |
1592 } | |
1593 | |
1594 static void dupe_check_start(DupeWindow *dw) | |
1595 { | |
1596 dw->setup_done = FALSE; | |
1597 | |
1598 dw->setup_count = g_list_length(dw->list); | |
1599 if (dw->second_set) dw->setup_count += g_list_length(dw->second_list); | |
1600 | |
1601 dw->setup_mask = 0; | |
1602 dupe_setup_reset(dw); | |
1603 | |
1604 dw->working = g_list_last(dw->list); | |
1605 | |
1606 dupe_window_update_count(dw, TRUE); | |
1607 widget_set_cursor(dw->listview, GDK_WATCH); | |
1608 | |
1609 if (dw->idle_id != -1) return; | |
1610 | |
1611 dw->idle_id = g_idle_add(dupe_check_cb, dw); | |
1612 } | |
1613 | |
1614 /* | |
1615 * ------------------------------------------------------------------ | |
1616 * Item addition, removal | |
1617 * ------------------------------------------------------------------ | |
1618 */ | |
1619 | |
1620 static void dupe_item_remove(DupeWindow *dw, DupeItem *di) | |
1621 { | |
1622 if (!di) return; | |
1623 | |
1624 /* handle things that may be in progress... */ | |
1625 if (dw->working && dw->working->data == di) | |
1626 { | |
1627 dw->working = dw->working->prev; | |
1628 } | |
1629 if (dw->thumb_loader && dw->thumb_item == di) | |
1630 { | |
1631 dupe_thumb_step(dw); | |
1632 } | |
1633 if (dw->setup_point && dw->setup_point->data == di) | |
1634 { | |
1635 dw->setup_point = dupe_setup_point_step(dw, dw->setup_point); | |
1636 if (dw->img_loader) | |
1637 { | |
1638 image_loader_free(dw->img_loader); | |
1639 dw->img_loader = NULL; | |
1640 dw->idle_id = g_idle_add(dupe_check_cb, dw); | |
1641 } | |
1642 } | |
1643 | |
1644 if (di->group && dw->dupes) | |
1645 { | |
1646 /* is a dupe, must remove from group/reset children if a parent */ | |
1647 DupeItem *parent; | |
1648 | |
1649 parent = dupe_match_find_parent(dw, di); | |
1650 if (di == parent) | |
1651 { | |
1652 if (g_list_length(parent->group) < 2) | |
1653 { | |
1654 DupeItem *child; | |
1655 | |
1656 child = dupe_match_highest_rank(parent); | |
1657 dupe_match_link_clear(child, TRUE); | |
1658 dupe_listview_remove(dw, child); | |
1659 | |
1660 dupe_match_link_clear(parent, TRUE); | |
1661 dupe_listview_remove(dw, parent); | |
1662 dw->dupes = g_list_remove(dw->dupes, parent); | |
1663 } | |
1664 else | |
1665 { | |
1666 DupeItem *new_parent; | |
1667 DupeMatch *dm; | |
442 | 1668 |
9 | 1669 dm = parent->group->data; |
1670 new_parent = dm->di; | |
1671 dupe_match_reparent(dw, parent, new_parent); | |
1672 dupe_listview_remove(dw, parent); | |
1673 } | |
1674 } | |
1675 else | |
1676 { | |
1677 if (g_list_length(parent->group) < 2) | |
1678 { | |
1679 dupe_match_link_clear(parent, TRUE); | |
1680 dupe_listview_remove(dw, parent); | |
1681 dw->dupes = g_list_remove(dw->dupes, parent); | |
1682 } | |
1683 dupe_match_link_clear(di, TRUE); | |
1684 dupe_listview_remove(dw, di); | |
1685 } | |
1686 } | |
1687 else | |
1688 { | |
1689 /* not a dupe, or not sorted yet, simply reset */ | |
1690 dupe_match_link_clear(di, TRUE); | |
1691 } | |
1692 | |
1693 if (dw->second_list && g_list_find(dw->second_list, di)) | |
1694 { | |
1695 dupe_second_remove(dw, di); | |
1696 } | |
1697 else | |
1698 { | |
1699 dw->list = g_list_remove(dw->list, di); | |
1700 } | |
1701 dupe_item_free(di); | |
1702 | |
1703 dupe_window_update_count(dw, FALSE); | |
1704 } | |
1705 | |
1706 static gint dupe_item_remove_by_path(DupeWindow *dw, const gchar *path) | |
1707 { | |
1708 DupeItem *di; | |
1709 | |
1710 di = dupe_item_find_path(dw, path); | |
1711 if (!di) return FALSE; | |
1712 | |
1713 dupe_item_remove(dw, di); | |
1714 | |
1715 return TRUE; | |
1716 } | |
1717 | |
1718 static void dupe_files_add(DupeWindow *dw, CollectionData *collection, CollectInfo *info, | |
138 | 1719 FileData *fd, gint recurse) |
9 | 1720 { |
1721 DupeItem *di = NULL; | |
1722 | |
1723 if (info) | |
1724 { | |
138 | 1725 di = dupe_item_new(info->fd); |
9 | 1726 } |
138 | 1727 else if (fd) |
9 | 1728 { |
138 | 1729 if (isfile(fd->path)) |
9 | 1730 { |
138 | 1731 di = dupe_item_new(fd); |
9 | 1732 } |
138 | 1733 else if (isdir(fd->path) && recurse) |
9 | 1734 { |
1735 GList *f, *d; | |
780
44128da39e13
Drop initialization to NULL since filelist_read() will take care of it.
zas_
parents:
753
diff
changeset
|
1736 |
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 | |
753 | 2057 file_util_start_editor_from_filelist(n, list, dw->window); |
138 | 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 { |
780
44128da39e13
Drop initialization to NULL since filelist_read() will take care of it.
zas_
parents:
753
diff
changeset
|
3310 GList *list; |
9 | 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 } |