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