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