Mercurial > geeqie
annotate src/dupe.c @ 429:831035240885
Let toggle marks with numeric keypad.
author | zas_ |
---|---|
date | Sat, 19 Apr 2008 20:53:12 +0000 |
parents | 07490120df2d |
children | 4b2d7f9af171 |
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 | |
281 | 13 #include "main.h" |
9 | 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 } |
264
1015282898fe
Add the possibility to match duplicates on the name but ignoring the case.
zas_
parents:
259
diff
changeset
|
1135 if (mask & DUPE_MATCH_NAME_CI) |
1015282898fe
Add the possibility to match duplicates on the name but ignoring the case.
zas_
parents:
259
diff
changeset
|
1136 { |
1015282898fe
Add the possibility to match duplicates on the name but ignoring the case.
zas_
parents:
259
diff
changeset
|
1137 if (strcasecmp(a->fd->name, b->fd->name) != 0) return FALSE; |
1015282898fe
Add the possibility to match duplicates on the name but ignoring the case.
zas_
parents:
259
diff
changeset
|
1138 } |
9 | 1139 if (mask & DUPE_MATCH_SIZE) |
1140 { | |
138 | 1141 if (a->fd->size != b->fd->size) return FALSE; |
9 | 1142 } |
1143 if (mask & DUPE_MATCH_DATE) | |
1144 { | |
138 | 1145 if (a->fd->date != b->fd->date) return FALSE; |
9 | 1146 } |
1147 if (mask & DUPE_MATCH_SUM) | |
1148 { | |
138 | 1149 if (!a->md5sum) a->md5sum = md5_text_from_file_utf8(a->fd->path, ""); |
1150 if (!b->md5sum) b->md5sum = md5_text_from_file_utf8(b->fd->path, ""); | |
9 | 1151 if (a->md5sum[0] == '\0' || |
1152 b->md5sum[0] == '\0' || | |
1153 strcmp(a->md5sum, b->md5sum) != 0) return FALSE; | |
1154 } | |
1155 if (mask & DUPE_MATCH_DIM) | |
1156 { | |
138 | 1157 if (a->width == 0) image_load_dimensions(a->fd, &a->width, &a->height); |
1158 if (b->width == 0) image_load_dimensions(b->fd, &b->width, &b->height); | |
9 | 1159 if (a->width != b->width || a->height != b->height) return FALSE; |
1160 } | |
1161 if (mask & DUPE_MATCH_SIM_HIGH || | |
1162 mask & DUPE_MATCH_SIM_MED || | |
1163 mask & DUPE_MATCH_SIM_LOW || | |
1164 mask & DUPE_MATCH_SIM_CUSTOM) | |
1165 { | |
1166 gdouble f; | |
1167 gdouble m; | |
1168 | |
1169 if (mask & DUPE_MATCH_SIM_HIGH) m = 0.95; | |
1170 else if (mask & DUPE_MATCH_SIM_MED) m = 0.90; | |
342
07490120df2d
Rename dupe_custom_threshold option to duplicates_similarity_threshold.
zas_
parents:
333
diff
changeset
|
1171 else if (mask & DUPE_MATCH_SIM_CUSTOM) m = (gdouble)options->duplicates_similarity_threshold / 100.0; |
9 | 1172 else m = 0.85; |
1173 | |
1174 if (fast) | |
1175 { | |
1176 f = image_sim_compare_fast(a->simd, b->simd, m); | |
1177 } | |
1178 else | |
1179 { | |
1180 f = image_sim_compare(a->simd, b->simd); | |
1181 } | |
1182 | |
1183 *rank = f * 100.0; | |
1184 | |
1185 if (f < m) return FALSE; | |
1186 | |
138 | 1187 if (debug > 2) printf("similar: %32s %32s = %f\n", a->fd->name, b->fd->name, f); |
9 | 1188 } |
1189 | |
1190 return TRUE; | |
1191 } | |
1192 | |
1193 static void dupe_list_check_match(DupeWindow *dw, DupeItem *needle, GList *start) | |
1194 { | |
1195 GList *work; | |
1196 | |
1197 if (dw->second_set) | |
1198 { | |
1199 work = dw->second_list; | |
1200 } | |
1201 else if (start) | |
1202 { | |
1203 work = start; | |
1204 } | |
1205 else | |
1206 { | |
1207 work = g_list_last(dw->list); | |
1208 } | |
1209 | |
1210 while (work) | |
1211 { | |
1212 DupeItem *di = work->data; | |
1213 | |
1214 /* speed opt: forward for second set, back for simple compare */ | |
1215 if (dw->second_set) | |
1216 work = work->next; | |
1217 else | |
1218 work = work->prev; | |
1219 | |
1220 if (!dupe_match_link_exists(needle, di)) | |
1221 { | |
1222 gdouble rank; | |
1223 | |
1224 if (dupe_match(di, needle, dw->match_mask, &rank, TRUE)) | |
1225 { | |
1226 dupe_match_link(di, needle, rank); | |
1227 } | |
1228 } | |
1229 } | |
1230 } | |
1231 | |
1232 /* | |
1233 * ------------------------------------------------------------------ | |
1234 * Thumbnail handling | |
1235 * ------------------------------------------------------------------ | |
1236 */ | |
1237 | |
1238 static void dupe_listview_set_thumb(DupeWindow *dw, DupeItem *di, GtkTreeIter *iter) | |
1239 { | |
1240 GtkListStore *store; | |
1241 GtkTreeIter iter_n; | |
1242 | |
1243 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dw->listview))); | |
1244 if (!iter) | |
1245 { | |
1246 if (dupe_listview_find_item(store, di, &iter_n) >= 0) | |
1247 { | |
1248 iter = &iter_n; | |
1249 } | |
1250 } | |
1251 | |
1252 if (iter) gtk_list_store_set(store, iter, DUPE_COLUMN_THUMB, di->pixbuf, -1); | |
1253 } | |
1254 | |
1255 static void dupe_thumb_do(DupeWindow *dw) | |
1256 { | |
1257 DupeItem *di; | |
1258 | |
1259 if (!dw->thumb_loader || !dw->thumb_item) return; | |
1260 di = dw->thumb_item; | |
1261 | |
1262 if (di->pixbuf) g_object_unref(di->pixbuf); | |
1263 di->pixbuf = thumb_loader_get_pixbuf(dw->thumb_loader, TRUE); | |
1264 | |
1265 dupe_listview_set_thumb(dw, di, NULL); | |
1266 } | |
1267 | |
1268 static void dupe_thumb_error_cb(ThumbLoader *tl, gpointer data) | |
1269 { | |
1270 DupeWindow *dw = data; | |
1271 | |
1272 dupe_thumb_do(dw); | |
1273 dupe_thumb_step(dw); | |
1274 } | |
1275 | |
1276 static void dupe_thumb_done_cb(ThumbLoader *tl, gpointer data) | |
1277 { | |
1278 DupeWindow *dw = data; | |
1279 | |
1280 dupe_thumb_do(dw); | |
1281 dupe_thumb_step(dw); | |
1282 } | |
1283 | |
1284 static void dupe_thumb_step(DupeWindow *dw) | |
1285 { | |
1286 GtkTreeModel *store; | |
1287 GtkTreeIter iter; | |
1288 DupeItem *di = NULL; | |
1289 gint valid; | |
1290 gint row = 0; | |
1291 gint length = 0; | |
1292 | |
1293 store = gtk_tree_view_get_model(GTK_TREE_VIEW(dw->listview)); | |
1294 valid = gtk_tree_model_get_iter_first(store, &iter); | |
1295 | |
1296 while (!di && valid) | |
1297 { | |
1298 GdkPixbuf *pixbuf; | |
1299 | |
1300 length++; | |
1301 gtk_tree_model_get(store, &iter, DUPE_COLUMN_POINTER, &di, DUPE_COLUMN_THUMB, &pixbuf, -1); | |
1302 if (pixbuf || di->pixbuf) | |
1303 { | |
1304 if (!pixbuf) gtk_list_store_set(GTK_LIST_STORE(store), &iter, DUPE_COLUMN_THUMB, di->pixbuf, -1); | |
1305 row++; | |
1306 di = NULL; | |
1307 } | |
1308 valid = gtk_tree_model_iter_next(store, &iter); | |
1309 } | |
1310 if (valid) | |
1311 { | |
1312 while (gtk_tree_model_iter_next(store, &iter)) length++; | |
1313 } | |
1314 | |
1315 if (!di) | |
1316 { | |
1317 dw->thumb_item = NULL; | |
1318 thumb_loader_free(dw->thumb_loader); | |
1319 dw->thumb_loader = NULL; | |
1320 | |
1321 dupe_window_update_progress(dw, NULL, 0.0, FALSE); | |
1322 return; | |
1323 } | |
1324 | |
1325 dupe_window_update_progress(dw, _("Loading thumbs..."), | |
1326 length == 0 ? 0.0 : (gdouble)(row) / length, FALSE); | |
1327 | |
1328 dw->thumb_item = di; | |
1329 thumb_loader_free(dw->thumb_loader); | |
333 | 1330 dw->thumb_loader = thumb_loader_new(options->thumbnails.max_width, options->thumbnails.max_height); |
9 | 1331 |
1332 thumb_loader_set_callbacks(dw->thumb_loader, | |
1333 dupe_thumb_done_cb, | |
1334 dupe_thumb_error_cb, | |
1335 NULL, | |
1336 dw); | |
1337 | |
1338 /* start it */ | |
138 | 1339 if (!thumb_loader_start(dw->thumb_loader, di->fd->path)) |
9 | 1340 { |
1341 /* error, handle it, do next */ | |
138 | 1342 if (debug) printf("error loading thumb for %s\n", di->fd->path); |
9 | 1343 dupe_thumb_do(dw); |
1344 dupe_thumb_step(dw); | |
1345 } | |
1346 } | |
1347 | |
1348 /* | |
1349 * ------------------------------------------------------------------ | |
1350 * Dupe checking loop | |
1351 * ------------------------------------------------------------------ | |
1352 */ | |
1353 | |
1354 static void dupe_check_stop(DupeWindow *dw) | |
1355 { | |
1356 if (dw->idle_id != -1 || dw->img_loader || dw->thumb_loader) | |
1357 { | |
1358 g_source_remove(dw->idle_id); | |
1359 dw->idle_id = -1; | |
1360 dupe_window_update_progress(dw, NULL, 0.0, FALSE); | |
1361 widget_set_cursor(dw->listview, -1); | |
1362 } | |
1363 | |
1364 thumb_loader_free(dw->thumb_loader); | |
1365 dw->thumb_loader = NULL; | |
1366 | |
1367 image_loader_free(dw->img_loader); | |
1368 dw->img_loader = NULL; | |
1369 } | |
1370 | |
1371 static void dupe_loader_done_cb(ImageLoader *il, gpointer data) | |
1372 { | |
1373 DupeWindow *dw = data; | |
1374 GdkPixbuf *pixbuf; | |
1375 | |
1376 pixbuf = image_loader_get_pixbuf(il); | |
1377 | |
1378 if (dw->setup_point) | |
1379 { | |
1380 DupeItem *di = dw->setup_point->data; | |
1381 | |
1382 if (!di->simd) | |
1383 { | |
1384 di->simd = image_sim_new_from_pixbuf(pixbuf); | |
1385 } | |
1386 else | |
1387 { | |
1388 image_sim_fill_data(di->simd, pixbuf); | |
1389 } | |
1390 | |
1391 if (di->width == 0 && di->height == 0) | |
1392 { | |
1393 di->width = gdk_pixbuf_get_width(pixbuf); | |
1394 di->height = gdk_pixbuf_get_height(pixbuf); | |
1395 } | |
333 | 1396 if (options->thumbnails.enable_caching) |
9 | 1397 { |
1398 dupe_item_write_cache(di); | |
1399 } | |
1400 | |
1401 image_sim_alternate_processing(di->simd); | |
1402 } | |
1403 | |
1404 image_loader_free(dw->img_loader); | |
1405 dw->img_loader = NULL; | |
1406 | |
1407 dw->idle_id = g_idle_add(dupe_check_cb, dw); | |
1408 } | |
1409 | |
1410 static void dupe_setup_reset(DupeWindow *dw) | |
1411 { | |
1412 dw->setup_point = NULL; | |
1413 dw->setup_n = 0; | |
1414 dw->setup_time = msec_time(); | |
1415 dw->setup_time_count = 0; | |
1416 } | |
1417 | |
1418 static GList *dupe_setup_point_step(DupeWindow *dw, GList *p) | |
1419 { | |
1420 if (!p) return NULL; | |
1421 | |
1422 if (p->next) return p->next; | |
1423 | |
1424 if (dw->second_set && g_list_first(p) == dw->list) return dw->second_list; | |
1425 | |
1426 return NULL; | |
1427 } | |
1428 | |
1429 static gint dupe_check_cb(gpointer data) | |
1430 { | |
1431 DupeWindow *dw = data; | |
1432 | |
1433 if (dw->idle_id == -1) return FALSE; | |
1434 | |
1435 if (!dw->setup_done) | |
1436 { | |
1437 if ((dw->match_mask & DUPE_MATCH_SUM) && | |
1438 !(dw->setup_mask & DUPE_MATCH_SUM) ) | |
1439 { | |
1440 if (!dw->setup_point) dw->setup_point = dw->list; | |
1441 | |
1442 while (dw->setup_point) | |
1443 { | |
1444 DupeItem *di = dw->setup_point->data; | |
1445 | |
1446 dw->setup_point = dupe_setup_point_step(dw, dw->setup_point); | |
1447 dw->setup_n++; | |
1448 | |
1449 if (!di->md5sum) | |
1450 { | |
1451 dupe_window_update_progress(dw, _("Reading checksums..."), | |
1452 dw->setup_count == 0 ? 0.0 : (gdouble)(dw->setup_n - 1) / dw->setup_count, FALSE); | |
1453 | |
333 | 1454 if (options->thumbnails.enable_caching) |
9 | 1455 { |
1456 dupe_item_read_cache(di); | |
1457 if (di->md5sum) return TRUE; | |
1458 } | |
1459 | |
138 | 1460 di->md5sum = md5_text_from_file_utf8(di->fd->path, ""); |
333 | 1461 if (options->thumbnails.enable_caching) |
9 | 1462 { |
1463 dupe_item_write_cache(di); | |
1464 } | |
1465 return TRUE; | |
1466 } | |
1467 } | |
1468 dw->setup_mask |= DUPE_MATCH_SUM; | |
1469 dupe_setup_reset(dw); | |
1470 } | |
1471 if ((dw->match_mask & DUPE_MATCH_DIM) && | |
1472 !(dw->setup_mask & DUPE_MATCH_DIM) ) | |
1473 { | |
1474 if (!dw->setup_point) dw->setup_point = dw->list; | |
1475 | |
1476 while (dw->setup_point) | |
1477 { | |
1478 DupeItem *di = dw->setup_point->data; | |
1479 | |
1480 dw->setup_point = dupe_setup_point_step(dw, dw->setup_point); | |
1481 dw->setup_n++; | |
1482 if (di->width == 0 && di->height == 0) | |
1483 { | |
1484 dupe_window_update_progress(dw, _("Reading dimensions..."), | |
1485 dw->setup_count == 0 ? 0.0 : (gdouble)(dw->setup_n - 1) / dw->setup_count, FALSE); | |
1486 | |
333 | 1487 if (options->thumbnails.enable_caching) |
9 | 1488 { |
1489 dupe_item_read_cache(di); | |
1490 if (di->width != 0 || di->height != 0) return TRUE; | |
1491 } | |
1492 | |
138 | 1493 image_load_dimensions(di->fd, &di->width, &di->height); |
333 | 1494 if (options->thumbnails.enable_caching) |
9 | 1495 { |
1496 dupe_item_write_cache(di); | |
1497 } | |
1498 return TRUE; | |
1499 } | |
1500 } | |
1501 dw->setup_mask |= DUPE_MATCH_DIM; | |
1502 dupe_setup_reset(dw); | |
1503 } | |
1504 if ((dw->match_mask & DUPE_MATCH_SIM_HIGH || | |
1505 dw->match_mask & DUPE_MATCH_SIM_MED || | |
1506 dw->match_mask & DUPE_MATCH_SIM_LOW || | |
1507 dw->match_mask & DUPE_MATCH_SIM_CUSTOM) && | |
1508 !(dw->setup_mask & DUPE_MATCH_SIM_MED) ) | |
1509 { | |
1510 if (!dw->setup_point) dw->setup_point = dw->list; | |
1511 | |
1512 while (dw->setup_point) | |
1513 { | |
1514 DupeItem *di = dw->setup_point->data; | |
1515 | |
1516 if (!di->simd) | |
1517 { | |
1518 dupe_window_update_progress(dw, _("Reading similarity data..."), | |
1519 dw->setup_count == 0 ? 0.0 : (gdouble)dw->setup_n / dw->setup_count, FALSE); | |
1520 | |
333 | 1521 if (options->thumbnails.enable_caching) |
9 | 1522 { |
1523 dupe_item_read_cache(di); | |
1524 if (cache_sim_data_filled(di->simd)) | |
1525 { | |
1526 image_sim_alternate_processing(di->simd); | |
1527 return TRUE; | |
1528 } | |
1529 } | |
1530 | |
138 | 1531 dw->img_loader = image_loader_new(di->fd); |
9 | 1532 image_loader_set_buffer_size(dw->img_loader, 8); |
1533 image_loader_set_error_func(dw->img_loader, dupe_loader_done_cb, dw); | |
1534 | |
1535 if (!image_loader_start(dw->img_loader, dupe_loader_done_cb, dw)) | |
1536 { | |
1537 image_sim_free(di->simd); | |
1538 di->simd = image_sim_new(); | |
1539 image_loader_free(dw->img_loader); | |
1540 dw->img_loader = NULL; | |
1541 return TRUE; | |
1542 } | |
1543 dw->idle_id = -1; | |
1544 return FALSE; | |
1545 } | |
1546 | |
1547 dw->setup_point = dupe_setup_point_step(dw, dw->setup_point); | |
1548 dw->setup_n++; | |
1549 } | |
1550 dw->setup_mask |= DUPE_MATCH_SIM_MED; | |
1551 dupe_setup_reset(dw); | |
1552 } | |
1553 dupe_window_update_progress(dw, _("Comparing..."), 0.0, FALSE); | |
1554 dw->setup_done = TRUE; | |
1555 dupe_setup_reset(dw); | |
1556 dw->setup_count = g_list_length(dw->list); | |
1557 } | |
1558 | |
1559 if (!dw->working) | |
1560 { | |
1561 if (dw->setup_count > 0) | |
1562 { | |
1563 dw->setup_count = 0; | |
1564 dupe_window_update_progress(dw, _("Sorting..."), 1.0, TRUE); | |
1565 return TRUE; | |
1566 } | |
1567 dw->idle_id = -1; | |
1568 dupe_window_update_progress(dw, NULL, 0.0, FALSE); | |
1569 | |
1570 dupe_match_rank(dw); | |
1571 dupe_window_update_count(dw, FALSE); | |
1572 | |
1573 dupe_listview_populate(dw); | |
1574 | |
1575 /* check thumbs */ | |
1576 if (dw->show_thumbs) dupe_thumb_step(dw); | |
1577 | |
1578 widget_set_cursor(dw->listview, -1); | |
1579 | |
1580 return FALSE; | |
1581 } | |
1582 | |
1583 dupe_list_check_match(dw, (DupeItem *)dw->working->data, dw->working); | |
1584 dupe_window_update_progress(dw, _("Comparing..."), dw->setup_count == 0 ? 0.0 : (gdouble) dw->setup_n / dw->setup_count, FALSE); | |
1585 dw->setup_n++; | |
1586 | |
1587 dw->working = dw->working->prev; | |
1588 | |
1589 return TRUE; | |
1590 } | |
1591 | |
1592 static void dupe_check_start(DupeWindow *dw) | |
1593 { | |
1594 dw->setup_done = FALSE; | |
1595 | |
1596 dw->setup_count = g_list_length(dw->list); | |
1597 if (dw->second_set) dw->setup_count += g_list_length(dw->second_list); | |
1598 | |
1599 dw->setup_mask = 0; | |
1600 dupe_setup_reset(dw); | |
1601 | |
1602 dw->working = g_list_last(dw->list); | |
1603 | |
1604 dupe_window_update_count(dw, TRUE); | |
1605 widget_set_cursor(dw->listview, GDK_WATCH); | |
1606 | |
1607 if (dw->idle_id != -1) return; | |
1608 | |
1609 dw->idle_id = g_idle_add(dupe_check_cb, dw); | |
1610 } | |
1611 | |
1612 /* | |
1613 * ------------------------------------------------------------------ | |
1614 * Item addition, removal | |
1615 * ------------------------------------------------------------------ | |
1616 */ | |
1617 | |
1618 static void dupe_item_remove(DupeWindow *dw, DupeItem *di) | |
1619 { | |
1620 if (!di) return; | |
1621 | |
1622 /* handle things that may be in progress... */ | |
1623 if (dw->working && dw->working->data == di) | |
1624 { | |
1625 dw->working = dw->working->prev; | |
1626 } | |
1627 if (dw->thumb_loader && dw->thumb_item == di) | |
1628 { | |
1629 dupe_thumb_step(dw); | |
1630 } | |
1631 if (dw->setup_point && dw->setup_point->data == di) | |
1632 { | |
1633 dw->setup_point = dupe_setup_point_step(dw, dw->setup_point); | |
1634 if (dw->img_loader) | |
1635 { | |
1636 image_loader_free(dw->img_loader); | |
1637 dw->img_loader = NULL; | |
1638 dw->idle_id = g_idle_add(dupe_check_cb, dw); | |
1639 } | |
1640 } | |
1641 | |
1642 if (di->group && dw->dupes) | |
1643 { | |
1644 /* is a dupe, must remove from group/reset children if a parent */ | |
1645 DupeItem *parent; | |
1646 | |
1647 parent = dupe_match_find_parent(dw, di); | |
1648 if (di == parent) | |
1649 { | |
1650 if (g_list_length(parent->group) < 2) | |
1651 { | |
1652 DupeItem *child; | |
1653 | |
1654 child = dupe_match_highest_rank(parent); | |
1655 dupe_match_link_clear(child, TRUE); | |
1656 dupe_listview_remove(dw, child); | |
1657 | |
1658 dupe_match_link_clear(parent, TRUE); | |
1659 dupe_listview_remove(dw, parent); | |
1660 dw->dupes = g_list_remove(dw->dupes, parent); | |
1661 } | |
1662 else | |
1663 { | |
1664 DupeItem *new_parent; | |
1665 DupeMatch *dm; | |
1666 | |
1667 dm = parent->group->data; | |
1668 new_parent = dm->di; | |
1669 dupe_match_reparent(dw, parent, new_parent); | |
1670 dupe_listview_remove(dw, parent); | |
1671 } | |
1672 } | |
1673 else | |
1674 { | |
1675 if (g_list_length(parent->group) < 2) | |
1676 { | |
1677 dupe_match_link_clear(parent, TRUE); | |
1678 dupe_listview_remove(dw, parent); | |
1679 dw->dupes = g_list_remove(dw->dupes, parent); | |
1680 } | |
1681 dupe_match_link_clear(di, TRUE); | |
1682 dupe_listview_remove(dw, di); | |
1683 } | |
1684 } | |
1685 else | |
1686 { | |
1687 /* not a dupe, or not sorted yet, simply reset */ | |
1688 dupe_match_link_clear(di, TRUE); | |
1689 } | |
1690 | |
1691 if (dw->second_list && g_list_find(dw->second_list, di)) | |
1692 { | |
1693 dupe_second_remove(dw, di); | |
1694 } | |
1695 else | |
1696 { | |
1697 dw->list = g_list_remove(dw->list, di); | |
1698 } | |
1699 dupe_item_free(di); | |
1700 | |
1701 dupe_window_update_count(dw, FALSE); | |
1702 } | |
1703 | |
1704 static gint dupe_item_remove_by_path(DupeWindow *dw, const gchar *path) | |
1705 { | |
1706 DupeItem *di; | |
1707 | |
1708 di = dupe_item_find_path(dw, path); | |
1709 if (!di) return FALSE; | |
1710 | |
1711 dupe_item_remove(dw, di); | |
1712 | |
1713 return TRUE; | |
1714 } | |
1715 | |
1716 static void dupe_files_add(DupeWindow *dw, CollectionData *collection, CollectInfo *info, | |
138 | 1717 FileData *fd, gint recurse) |
9 | 1718 { |
1719 DupeItem *di = NULL; | |
1720 | |
1721 if (info) | |
1722 { | |
138 | 1723 di = dupe_item_new(info->fd); |
9 | 1724 } |
138 | 1725 else if (fd) |
9 | 1726 { |
138 | 1727 if (isfile(fd->path)) |
9 | 1728 { |
138 | 1729 di = dupe_item_new(fd); |
9 | 1730 } |
138 | 1731 else if (isdir(fd->path) && recurse) |
9 | 1732 { |
1733 GList *f, *d; | |
138 | 1734 if (filelist_read(fd->path, &f, &d)) |
9 | 1735 { |
1736 GList *work; | |
1737 | |
138 | 1738 f = filelist_filter(f, FALSE); |
1739 d = filelist_filter(d, TRUE); | |
9 | 1740 |
1741 work = f; | |
1742 while(work) | |
1743 { | |
138 | 1744 dupe_files_add(dw, NULL, NULL, (FileData *)work->data, TRUE); |
9 | 1745 work = work->next; |
1746 } | |
138 | 1747 filelist_free(f); |
9 | 1748 work = d; |
1749 while(work) | |
1750 { | |
138 | 1751 dupe_files_add(dw, NULL, NULL, (FileData *)work->data, TRUE); |
9 | 1752 work = work->next; |
1753 } | |
138 | 1754 filelist_free(d); |
9 | 1755 } |
1756 } | |
1757 } | |
1758 | |
1759 if (!di) return; | |
1760 | |
1761 if (dw->second_drop) | |
1762 { | |
1763 dupe_second_add(dw, di); | |
1764 } | |
1765 else | |
1766 { | |
1767 dw->list = g_list_prepend(dw->list, di); | |
1768 } | |
1769 } | |
1770 | |
1771 void dupe_window_add_collection(DupeWindow *dw, CollectionData *collection) | |
1772 { | |
1773 CollectInfo *info; | |
1774 | |
1775 info = collection_get_first(collection); | |
1776 while(info) | |
1777 { | |
1778 dupe_files_add(dw, collection, info, NULL, FALSE); | |
1779 info = collection_next_by_info(collection, info); | |
1780 } | |
1781 | |
1782 dupe_check_start(dw); | |
1783 } | |
1784 | |
1785 void dupe_window_add_files(DupeWindow *dw, GList *list, gint recurse) | |
1786 { | |
1787 GList *work; | |
1788 | |
1789 work = list; | |
1790 while(work) | |
1791 { | |
138 | 1792 FileData *fd = work->data; |
9 | 1793 work = work->next; |
1794 | |
138 | 1795 dupe_files_add(dw, NULL, NULL, fd, recurse); |
9 | 1796 } |
1797 | |
1798 dupe_check_start(dw); | |
1799 } | |
1800 | |
138 | 1801 static void dupe_item_update(DupeWindow *dw, DupeItem *di) |
9 | 1802 { |
264
1015282898fe
Add the possibility to match duplicates on the name but ignoring the case.
zas_
parents:
259
diff
changeset
|
1803 if ( (dw->match_mask & DUPE_MATCH_NAME) || (dw->match_mask & DUPE_MATCH_PATH || (dw->match_mask & DUPE_MATCH_NAME_CI)) ) |
9 | 1804 { |
1805 /* only effects matches on name or path */ | |
138 | 1806 /* |
1807 FileData *fd = file_data_ref(di->fd); | |
9 | 1808 gint second; |
1809 | |
1810 second = di->second; | |
1811 dupe_item_remove(dw, di); | |
1812 | |
1813 dw->second_drop = second; | |
138 | 1814 dupe_files_add(dw, NULL, NULL, fd, FALSE); |
9 | 1815 dw->second_drop = FALSE; |
138 | 1816 |
1817 file_data_unref(fd); | |
1818 */ | |
9 | 1819 dupe_check_start(dw); |
1820 } | |
1821 else | |
1822 { | |
1823 GtkListStore *store; | |
1824 GtkTreeIter iter; | |
1825 gint row; | |
1826 /* update the listview(s) */ | |
1827 | |
1828 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dw->listview))); | |
1829 row = dupe_listview_find_item(store, di, &iter); | |
1830 if (row >= 0) | |
1831 { | |
1832 gtk_list_store_set(store, &iter, | |
138 | 1833 DUPE_COLUMN_NAME, di->fd->name, |
1834 DUPE_COLUMN_PATH, di->fd->path, -1); | |
9 | 1835 } |
1836 | |
1837 if (dw->second_listview) | |
1838 { | |
1839 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dw->second_listview))); | |
1840 row = dupe_listview_find_item(store, di, &iter); | |
1841 if (row >= 0) | |
1842 { | |
138 | 1843 gtk_list_store_set(store, &iter, 1, di->fd->path, -1); |
9 | 1844 } |
1845 } | |
1846 } | |
1847 | |
1848 } | |
1849 | |
138 | 1850 static void dupe_item_update_fd_in_list(DupeWindow *dw, FileData *fd, GList *work) |
1851 { | |
1852 while (work) | |
1853 { | |
1854 DupeItem *di = work->data; | |
1855 | |
1856 if (di->fd == fd) | |
1857 dupe_item_update(dw, di); | |
1858 | |
1859 work = work->next; | |
1860 } | |
1861 } | |
1862 | |
1863 static void dupe_item_update_fd(DupeWindow *dw, FileData *fd) | |
1864 { | |
1865 dupe_item_update_fd_in_list(dw, fd, dw->list); | |
1866 if (dw->second_set) dupe_item_update_fd_in_list(dw, fd, dw->second_list); | |
1867 } | |
1868 | |
1869 | |
9 | 1870 /* |
1871 * ------------------------------------------------------------------ | |
1872 * Misc. | |
1873 * ------------------------------------------------------------------ | |
1874 */ | |
1875 | |
1876 static GtkWidget *dupe_display_label(GtkWidget *vbox, const gchar *description, const gchar *text) | |
1877 { | |
1878 GtkWidget *hbox; | |
1879 GtkWidget *label; | |
1880 | |
1881 hbox = gtk_hbox_new(FALSE, 10); | |
1882 | |
1883 label = gtk_label_new(description); | |
1884 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
1885 gtk_widget_show(label); | |
1886 | |
1887 label = gtk_label_new(text); | |
1888 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
1889 gtk_widget_show(label); | |
1890 | |
1891 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
1892 gtk_widget_show(hbox); | |
1893 | |
1894 return label; | |
1895 } | |
1896 | |
1897 static void dupe_display_stats(DupeWindow *dw, DupeItem *di) | |
1898 { | |
1899 GenericDialog *gd; | |
1900 gchar *buf; | |
1901 | |
1902 if (!di) return; | |
1903 | |
254
9faf34f047b1
Make the wmclass value unique among the code by defining
zas_
parents:
196
diff
changeset
|
1904 gd = file_util_gen_dlg("Image thumbprint debug info", GQ_WMCLASS, "thumbprint", |
9 | 1905 dw->window, TRUE, |
1906 NULL, NULL); | |
1907 generic_dialog_add_button(gd, GTK_STOCK_CLOSE, NULL, NULL, TRUE); | |
1908 | |
138 | 1909 dupe_display_label(gd->vbox, "name:", di->fd->name); |
1910 buf = text_from_size(di->fd->size); | |
9 | 1911 dupe_display_label(gd->vbox, "size:", buf); |
1912 g_free(buf); | |
138 | 1913 dupe_display_label(gd->vbox, "date:", text_from_time(di->fd->date)); |
9 | 1914 buf = g_strdup_printf("%d x %d", di->width, di->height); |
1915 dupe_display_label(gd->vbox, "dimensions:", buf); | |
1916 g_free(buf); | |
1917 dupe_display_label(gd->vbox, "md5sum:", (di->md5sum) ? di->md5sum : "not generated"); | |
1918 | |
1919 dupe_display_label(gd->vbox, "thumbprint:", (di->simd) ? "" : "not generated"); | |
1920 if (di->simd) | |
1921 { | |
1922 GtkWidget *image; | |
1923 GdkPixbuf *pixbuf; | |
1924 gint x, y; | |
1925 guchar *d_pix; | |
1926 guchar *dp; | |
1927 gint rs; | |
1928 gint sp; | |
1929 | |
1930 pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, 32, 32); | |
1931 rs = gdk_pixbuf_get_rowstride(pixbuf); | |
1932 d_pix = gdk_pixbuf_get_pixels(pixbuf); | |
1933 | |
1934 for (y = 0; y < 32; y++) | |
1935 { | |
1936 dp = d_pix + (y * rs); | |
1937 sp = y * 32; | |
1938 for (x = 0; x < 32; x++) | |
1939 { | |
1940 *(dp++) = di->simd->avg_r[sp + x]; | |
1941 *(dp++) = di->simd->avg_g[sp + x]; | |
1942 *(dp++) = di->simd->avg_b[sp + x]; | |
1943 } | |
1944 } | |
1945 | |
1946 image = gtk_image_new_from_pixbuf(pixbuf); | |
1947 gtk_box_pack_start(GTK_BOX(gd->vbox), image, FALSE, FALSE, 0); | |
1948 gtk_widget_show(image); | |
1949 | |
1950 gdk_pixbuf_unref(pixbuf); | |
1951 } | |
1952 | |
1953 gtk_widget_show(gd->dialog); | |
1954 } | |
1955 | |
1956 static void dupe_window_recompare(DupeWindow *dw) | |
1957 { | |
1958 GtkListStore *store; | |
1959 | |
1960 dupe_check_stop(dw); | |
1961 | |
1962 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dw->listview))); | |
1963 gtk_list_store_clear(store); | |
1964 | |
1965 g_list_free(dw->dupes); | |
1966 dw->dupes = NULL; | |
1967 | |
1968 dupe_match_reset_list(dw->list); | |
1969 dupe_match_reset_list(dw->second_list); | |
1970 | |
1971 dupe_check_start(dw); | |
1972 } | |
1973 | |
1974 static void dupe_menu_view(DupeWindow *dw, DupeItem *di, GtkWidget *listview, gint new_window) | |
1975 { | |
1976 if (!di) return; | |
1977 | |
1978 if (di->collection && collection_info_valid(di->collection, di->info)) | |
1979 { | |
1980 if (new_window) | |
1981 { | |
1982 view_window_new_from_collection(di->collection, di->info); | |
1983 } | |
1984 else | |
1985 { | |
1986 layout_image_set_collection(NULL, di->collection, di->info); | |
1987 } | |
1988 } | |
1989 else | |
1990 { | |
1991 if (new_window) | |
1992 { | |
1993 GList *list; | |
1994 | |
1995 list = dupe_listview_get_selection(dw, listview); | |
1996 view_window_new_from_list(list); | |
138 | 1997 filelist_free(list); |
9 | 1998 } |
1999 else | |
2000 { | |
138 | 2001 layout_image_set_fd(NULL, di->fd); |
9 | 2002 } |
2003 } | |
2004 } | |
2005 | |
2006 static void dupe_window_remove_selection(DupeWindow *dw, GtkWidget *listview) | |
2007 { | |
2008 GtkTreeSelection *selection; | |
2009 GtkTreeModel *store; | |
2010 GtkTreeIter iter; | |
2011 GList *slist; | |
2012 GList *list = NULL; | |
2013 GList *work; | |
2014 | |
2015 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(listview)); | |
2016 slist = gtk_tree_selection_get_selected_rows(selection, &store); | |
2017 work = slist; | |
2018 while (work) | |
2019 { | |
2020 GtkTreePath *tpath = work->data; | |
2021 DupeItem *di = NULL; | |
2022 | |
2023 gtk_tree_model_get_iter(store, &iter, tpath); | |
2024 gtk_tree_model_get(store, &iter, DUPE_COLUMN_POINTER, &di, -1); | |
2025 if (di) list = g_list_prepend(list, di); | |
2026 work = work->next; | |
2027 } | |
2028 g_list_foreach(slist, (GFunc)gtk_tree_path_free, NULL); | |
2029 g_list_free(slist); | |
2030 | |
2031 dw->color_frozen = TRUE; | |
2032 work = list; | |
2033 while (work) | |
2034 { | |
2035 DupeItem *di; | |
2036 | |
2037 di = work->data; | |
2038 work = work->next; | |
2039 dupe_item_remove(dw, di); | |
2040 } | |
2041 dw->color_frozen = FALSE; | |
2042 | |
2043 g_list_free(list); | |
2044 | |
2045 dupe_listview_realign_colors(dw); | |
2046 } | |
2047 | |
2048 static void dupe_window_edit_selected(DupeWindow *dw, gint n) | |
2049 { | |
2050 GList *list; | |
2051 | |
2052 list = dupe_listview_get_selection(dw, dw->listview); | |
2053 | |
138 | 2054 start_editor_from_filelist(n, list); |
2055 | |
2056 filelist_free(list); | |
9 | 2057 } |
2058 | |
2059 static void dupe_window_collection_from_selection(DupeWindow *dw) | |
2060 { | |
2061 CollectWindow *w; | |
2062 GList *list; | |
2063 | |
2064 list = dupe_listview_get_selection(dw, dw->listview); | |
2065 w = collection_window_new(NULL); | |
138 | 2066 collection_table_add_filelist(w->table, list); |
2067 filelist_free(list); | |
9 | 2068 } |
2069 | |
2070 static void dupe_window_append_file_list(DupeWindow *dw, gint on_second) | |
2071 { | |
2072 GList *list; | |
2073 | |
2074 dw->second_drop = (dw->second_set && on_second); | |
2075 | |
2076 list = layout_list(NULL); | |
2077 dupe_window_add_files(dw, list, FALSE); | |
138 | 2078 filelist_free(list); |
9 | 2079 } |
2080 | |
2081 /* | |
2082 *------------------------------------------------------------------- | |
2083 * main pop-up menu callbacks | |
2084 *------------------------------------------------------------------- | |
2085 */ | |
2086 | |
2087 static void dupe_menu_view_cb(GtkWidget *widget, gpointer data) | |
2088 { | |
2089 DupeWindow *dw = data; | |
2090 | |
2091 if (dw->click_item) dupe_menu_view(dw, dw->click_item, dw->listview, FALSE); | |
2092 } | |
2093 | |
2094 static void dupe_menu_viewnew_cb(GtkWidget *widget, gpointer data) | |
2095 { | |
2096 DupeWindow *dw = data; | |
2097 | |
2098 if (dw->click_item) dupe_menu_view(dw, dw->click_item, dw->listview, TRUE); | |
2099 } | |
2100 | |
2101 static void dupe_menu_select_all_cb(GtkWidget *widget, gpointer data) | |
2102 { | |
2103 DupeWindow *dw = data; | |
2104 GtkTreeSelection *selection; | |
2105 | |
2106 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dw->listview)); | |
2107 gtk_tree_selection_select_all(selection); | |
2108 } | |
2109 | |
2110 static void dupe_menu_select_none_cb(GtkWidget *widget, gpointer data) | |
2111 { | |
2112 DupeWindow *dw = data; | |
2113 GtkTreeSelection *selection; | |
2114 | |
2115 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dw->listview)); | |
2116 gtk_tree_selection_unselect_all(selection); | |
2117 } | |
2118 | |
2119 static void dupe_menu_select_dupes_set1_cb(GtkWidget *widget, gpointer data) | |
2120 { | |
2121 DupeWindow *dw = data; | |
2122 | |
2123 dupe_listview_select_dupes(dw, TRUE); | |
2124 } | |
2125 | |
2126 static void dupe_menu_select_dupes_set2_cb(GtkWidget *widget, gpointer data) | |
2127 { | |
2128 DupeWindow *dw = data; | |
2129 | |
2130 dupe_listview_select_dupes(dw, FALSE); | |
2131 } | |
2132 | |
2133 static void dupe_menu_edit_cb(GtkWidget *widget, gpointer data) | |
2134 { | |
2135 DupeWindow *dw; | |
2136 gint n; | |
2137 | |
2138 dw = submenu_item_get_data(widget); | |
2139 n = GPOINTER_TO_INT(data); | |
2140 if (!dw) return; | |
2141 | |
2142 dupe_window_edit_selected(dw, n); | |
2143 } | |
2144 | |
2145 static void dupe_menu_info_cb(GtkWidget *widget, gpointer data) | |
2146 { | |
2147 DupeWindow *dw = data; | |
2148 | |
2149 info_window_new(NULL, dupe_listview_get_selection(dw, dw->listview)); | |
2150 } | |
2151 | |
2152 static void dupe_menu_collection_cb(GtkWidget *widget, gpointer data) | |
2153 { | |
2154 DupeWindow *dw = data; | |
2155 | |
2156 dupe_window_collection_from_selection(dw); | |
2157 } | |
2158 | |
2159 static void dupe_menu_print_cb(GtkWidget *widget, gpointer data) | |
2160 { | |
2161 DupeWindow *dw = data; | |
138 | 2162 FileData *fd; |
2163 | |
2164 fd = (dw->click_item) ? dw->click_item->fd : NULL; | |
2165 | |
2166 print_window_new(fd, | |
9 | 2167 dupe_listview_get_selection(dw, dw->listview), |
138 | 2168 dupe_listview_get_filelist(dw, dw->listview), dw->window); |
9 | 2169 } |
2170 | |
2171 static void dupe_menu_copy_cb(GtkWidget *widget, gpointer data) | |
2172 { | |
2173 DupeWindow *dw = data; | |
2174 | |
2175 file_util_copy(NULL, dupe_listview_get_selection(dw, dw->listview), NULL, dw->window); | |
2176 } | |
2177 | |
2178 static void dupe_menu_move_cb(GtkWidget *widget, gpointer data) | |
2179 { | |
2180 DupeWindow *dw = data; | |
2181 | |
2182 file_util_move(NULL, dupe_listview_get_selection(dw, dw->listview), NULL, dw->window); | |
2183 } | |
2184 | |
2185 static void dupe_menu_rename_cb(GtkWidget *widget, gpointer data) | |
2186 { | |
2187 DupeWindow *dw = data; | |
2188 | |
2189 file_util_rename(NULL, dupe_listview_get_selection(dw, dw->listview), dw->window); | |
2190 } | |
2191 | |
2192 static void dupe_menu_delete_cb(GtkWidget *widget, gpointer data) | |
2193 { | |
2194 DupeWindow *dw = data; | |
2195 | |
2196 file_util_delete(NULL, dupe_listview_get_selection(dw, dw->listview), dw->window); | |
2197 } | |
2198 | |
2199 static void dupe_menu_remove_cb(GtkWidget *widget, gpointer data) | |
2200 { | |
2201 DupeWindow *dw = data; | |
2202 | |
2203 dupe_window_remove_selection(dw, dw->listview); | |
2204 } | |
2205 | |
2206 static void dupe_menu_clear_cb(GtkWidget *widget, gpointer data) | |
2207 { | |
2208 DupeWindow *dw = data; | |
2209 | |
2210 dupe_window_clear(dw); | |
2211 } | |
2212 | |
2213 static void dupe_menu_close_cb(GtkWidget *widget, gpointer data) | |
2214 { | |
2215 DupeWindow *dw = data; | |
2216 | |
2217 dupe_window_close(dw); | |
2218 } | |
2219 | |
2220 static GtkWidget *dupe_menu_popup_main(DupeWindow *dw, DupeItem *di) | |
2221 { | |
2222 GtkWidget *menu; | |
2223 GtkWidget *item; | |
2224 gint on_row; | |
2225 | |
2226 on_row = (di != NULL); | |
2227 | |
2228 menu = popup_menu_short_lived(); | |
2229 menu_item_add_sensitive(menu, _("_View"), on_row, | |
2230 G_CALLBACK(dupe_menu_view_cb), dw); | |
2231 menu_item_add_stock_sensitive(menu, _("View in _new window"), GTK_STOCK_NEW, on_row, | |
2232 G_CALLBACK(dupe_menu_viewnew_cb), dw); | |
2233 menu_item_add_divider(menu); | |
2234 menu_item_add_sensitive(menu, _("Select all"), (dw->dupes != NULL), | |
2235 G_CALLBACK(dupe_menu_select_all_cb), dw); | |
2236 menu_item_add_sensitive(menu, _("Select none"), (dw->dupes != NULL), | |
2237 G_CALLBACK(dupe_menu_select_none_cb), dw); | |
2238 menu_item_add_sensitive(menu, _("Select group _1 duplicates"), (dw->dupes != NULL), | |
2239 G_CALLBACK(dupe_menu_select_dupes_set1_cb), dw); | |
2240 menu_item_add_sensitive(menu, _("Select group _2 duplicates"), (dw->dupes != NULL), | |
2241 G_CALLBACK(dupe_menu_select_dupes_set2_cb), dw); | |
2242 menu_item_add_divider(menu); | |
2243 submenu_add_edit(menu, &item, G_CALLBACK(dupe_menu_edit_cb), dw); | |
2244 if (!on_row) gtk_widget_set_sensitive(item, FALSE); | |
2245 menu_item_add_stock_sensitive(menu, _("_Properties"), GTK_STOCK_PROPERTIES, on_row, | |
2246 G_CALLBACK(dupe_menu_info_cb), dw); | |
2247 menu_item_add_stock_sensitive(menu, _("Add to new collection"), GTK_STOCK_INDEX, on_row, | |
2248 G_CALLBACK(dupe_menu_collection_cb), dw); | |
2249 menu_item_add_stock_sensitive(menu, _("Print..."), GTK_STOCK_PRINT, on_row, | |
2250 G_CALLBACK(dupe_menu_print_cb), dw); | |
2251 menu_item_add_divider(menu); | |
2252 menu_item_add_stock_sensitive(menu, _("_Copy..."), GTK_STOCK_COPY, on_row, | |
2253 G_CALLBACK(dupe_menu_copy_cb), dw); | |
2254 menu_item_add_sensitive(menu, _("_Move..."), on_row, | |
2255 G_CALLBACK(dupe_menu_move_cb), dw); | |
2256 menu_item_add_sensitive(menu, _("_Rename..."), on_row, | |
2257 G_CALLBACK(dupe_menu_rename_cb), dw); | |
2258 menu_item_add_stock_sensitive(menu, _("_Delete..."), GTK_STOCK_DELETE, on_row, | |
2259 G_CALLBACK(dupe_menu_delete_cb), dw); | |
2260 menu_item_add_divider(menu); | |
2261 menu_item_add_stock_sensitive(menu, _("Rem_ove"), GTK_STOCK_REMOVE, on_row, | |
2262 G_CALLBACK(dupe_menu_remove_cb), dw); | |
2263 menu_item_add_stock_sensitive(menu, _("C_lear"), GTK_STOCK_CLEAR, (dw->list != NULL), | |
2264 G_CALLBACK(dupe_menu_clear_cb), dw); | |
2265 menu_item_add_divider(menu); | |
2266 menu_item_add_stock(menu, _("Close _window"), GTK_STOCK_CLOSE, | |
2267 G_CALLBACK(dupe_menu_close_cb), dw); | |
2268 | |
2269 return menu; | |
2270 } | |
2271 | |
2272 static gint dupe_listview_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data) | |
2273 { | |
2274 DupeWindow *dw = data; | |
2275 GtkTreeModel *store; | |
2276 GtkTreePath *tpath; | |
2277 GtkTreeIter iter; | |
2278 DupeItem *di = NULL; | |
2279 | |
2280 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | |
2281 | |
2282 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bevent->x, bevent->y, | |
2283 &tpath, NULL, NULL, NULL)) | |
2284 { | |
2285 gtk_tree_model_get_iter(store, &iter, tpath); | |
2286 gtk_tree_model_get(store, &iter, DUPE_COLUMN_POINTER, &di, -1); | |
2287 gtk_tree_path_free(tpath); | |
2288 } | |
2289 | |
2290 dw->click_item = di; | |
2291 | |
2292 if (bevent->button == 3) | |
2293 { | |
2294 /* right click menu */ | |
2295 GtkWidget *menu; | |
2296 | |
2297 if (bevent->state & GDK_CONTROL_MASK && bevent->state & GDK_SHIFT_MASK) | |
2298 { | |
2299 dupe_display_stats(dw, di); | |
2300 return TRUE; | |
2301 } | |
2302 if (widget == dw->listview) | |
2303 { | |
2304 menu = dupe_menu_popup_main(dw, di); | |
2305 } | |
2306 else | |
2307 { | |
2308 menu = dupe_menu_popup_second(dw, di); | |
2309 } | |
2310 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, bevent->button, bevent->time); | |
2311 } | |
2312 | |
2313 if (!di) return FALSE; | |
2314 | |
2315 if (bevent->button == 1 && bevent->type == GDK_2BUTTON_PRESS) | |
2316 { | |
2317 dupe_menu_view(dw, di, widget, FALSE); | |
2318 } | |
2319 | |
2320 if (bevent->button == 2) return TRUE; | |
2321 | |
2322 if (bevent->button == 3) | |
2323 { | |
2324 if (!dupe_listview_item_is_selected(dw, di, widget)) | |
2325 { | |
2326 GtkTreeSelection *selection; | |
2327 | |
2328 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget)); | |
2329 gtk_tree_selection_unselect_all(selection); | |
2330 gtk_tree_selection_select_iter(selection, &iter); | |
2331 | |
2332 tpath = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter); | |
2333 gtk_tree_view_set_cursor(GTK_TREE_VIEW(widget), tpath, NULL, FALSE); | |
2334 gtk_tree_path_free(tpath); | |
2335 } | |
2336 | |
2337 return TRUE; | |
2338 } | |
2339 | |
2340 if (bevent->button == 1 && bevent->type == GDK_BUTTON_PRESS && | |
2341 !(bevent->state & GDK_SHIFT_MASK ) && | |
2342 !(bevent->state & GDK_CONTROL_MASK ) && | |
2343 dupe_listview_item_is_selected(dw, di, widget)) | |
2344 { | |
2345 /* this selection handled on release_cb */ | |
2346 gtk_widget_grab_focus(widget); | |
2347 return TRUE; | |
2348 } | |
2349 | |
2350 return FALSE; | |
2351 } | |
2352 | |
2353 static gint dupe_listview_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data) | |
2354 { | |
2355 DupeWindow *dw = data; | |
2356 GtkTreeModel *store; | |
2357 GtkTreePath *tpath; | |
2358 GtkTreeIter iter; | |
2359 DupeItem *di = NULL; | |
2360 | |
2361 if (bevent->button != 1 && bevent->button != 2) return TRUE; | |
2362 | |
2363 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | |
2364 | |
2365 if ((bevent->x != 0 || bevent->y != 0) && | |
2366 gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bevent->x, bevent->y, | |
2367 &tpath, NULL, NULL, NULL)) | |
2368 { | |
2369 gtk_tree_model_get_iter(store, &iter, tpath); | |
2370 gtk_tree_model_get(store, &iter, DUPE_COLUMN_POINTER, &di, -1); | |
2371 gtk_tree_path_free(tpath); | |
2372 } | |
2373 | |
2374 if (bevent->button == 2) | |
2375 { | |
2376 if (di && dw->click_item == di) | |
2377 { | |
2378 GtkTreeSelection *selection; | |
2379 | |
2380 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget)); | |
2381 if (dupe_listview_item_is_selected(dw, di, widget)) | |
2382 { | |
2383 gtk_tree_selection_unselect_iter(selection, &iter); | |
2384 } | |
2385 else | |
2386 { | |
2387 gtk_tree_selection_select_iter(selection, &iter); | |
2388 } | |
2389 } | |
2390 return TRUE; | |
2391 } | |
2392 | |
2393 if (di && dw->click_item == di && | |
2394 !(bevent->state & GDK_SHIFT_MASK ) && | |
2395 !(bevent->state & GDK_CONTROL_MASK ) && | |
2396 dupe_listview_item_is_selected(dw, di, widget)) | |
2397 { | |
2398 GtkTreeSelection *selection; | |
2399 | |
2400 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget)); | |
2401 gtk_tree_selection_unselect_all(selection); | |
2402 gtk_tree_selection_select_iter(selection, &iter); | |
2403 | |
2404 tpath = gtk_tree_model_get_path(store, &iter); | |
2405 gtk_tree_view_set_cursor(GTK_TREE_VIEW(widget), tpath, NULL, FALSE); | |
2406 gtk_tree_path_free(tpath); | |
2407 | |
2408 return TRUE; | |
2409 } | |
2410 | |
2411 return FALSE; | |
2412 } | |
2413 | |
2414 /* | |
2415 *------------------------------------------------------------------- | |
2416 * second set stuff | |
2417 *------------------------------------------------------------------- | |
2418 */ | |
2419 | |
2420 static void dupe_second_update_status(DupeWindow *dw) | |
2421 { | |
2422 gchar *buf; | |
2423 | |
2424 buf = g_strdup_printf(_("%d files (set 2)"), g_list_length(dw->second_list)); | |
2425 gtk_label_set_text(GTK_LABEL(dw->second_status_label), buf); | |
2426 g_free(buf); | |
2427 } | |
2428 | |
2429 static void dupe_second_add(DupeWindow *dw, DupeItem *di) | |
2430 { | |
2431 GtkListStore *store; | |
2432 GtkTreeIter iter; | |
2433 | |
2434 if (!di) return; | |
2435 | |
2436 di->second = TRUE; | |
2437 dw->second_list = g_list_prepend(dw->second_list, di); | |
2438 | |
2439 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dw->second_listview))); | |
2440 gtk_list_store_append(store, &iter); | |
138 | 2441 gtk_list_store_set(store, &iter, DUPE_COLUMN_POINTER, di, 1, di->fd->path, -1); |
9 | 2442 |
2443 dupe_second_update_status(dw); | |
2444 } | |
2445 | |
2446 static void dupe_second_remove(DupeWindow *dw, DupeItem *di) | |
2447 { | |
2448 GtkListStore *store; | |
2449 GtkTreeIter iter; | |
2450 | |
2451 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dw->second_listview))); | |
2452 if (dupe_listview_find_item(store, di, &iter) >= 0) | |
2453 { | |
2454 tree_view_move_cursor_away(GTK_TREE_VIEW(dw->second_listview), &iter, TRUE); | |
2455 gtk_list_store_remove(store, &iter); | |
2456 } | |
2457 | |
2458 dw->second_list = g_list_remove(dw->second_list, di); | |
2459 | |
2460 dupe_second_update_status(dw); | |
2461 } | |
2462 | |
2463 static void dupe_second_clear(DupeWindow *dw) | |
2464 { | |
2465 GtkListStore *store; | |
2466 | |
2467 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dw->second_listview))); | |
2468 gtk_list_store_clear(store); | |
2469 gtk_tree_view_columns_autosize(GTK_TREE_VIEW(dw->second_listview)); | |
2470 | |
2471 g_list_free(dw->dupes); | |
2472 dw->dupes = NULL; | |
2473 | |
2474 dupe_list_free(dw->second_list); | |
2475 dw->second_list = NULL; | |
2476 | |
2477 dupe_match_reset_list(dw->list); | |
2478 | |
2479 dupe_second_update_status(dw); | |
2480 } | |
2481 | |
2482 static void dupe_second_menu_view_cb(GtkWidget *widget, gpointer data) | |
2483 { | |
2484 DupeWindow *dw = data; | |
2485 | |
2486 if (dw->click_item) dupe_menu_view(dw, dw->click_item, dw->second_listview, FALSE); | |
2487 } | |
2488 | |
2489 static void dupe_second_menu_viewnew_cb(GtkWidget *widget, gpointer data) | |
2490 { | |
2491 DupeWindow *dw = data; | |
2492 | |
2493 if (dw->click_item) dupe_menu_view(dw, dw->click_item, dw->second_listview, TRUE); | |
2494 } | |
2495 | |
2496 static void dupe_second_menu_select_all_cb(GtkWidget *widget, gpointer data) | |
2497 { | |
2498 GtkTreeSelection *selection; | |
2499 DupeWindow *dw = data; | |
2500 | |
2501 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dw->second_listview)); | |
2502 gtk_tree_selection_select_all(selection); | |
2503 } | |
2504 | |
2505 static void dupe_second_menu_select_none_cb(GtkWidget *widget, gpointer data) | |
2506 { | |
2507 GtkTreeSelection *selection; | |
2508 DupeWindow *dw = data; | |
2509 | |
2510 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dw->second_listview)); | |
2511 gtk_tree_selection_unselect_all(selection); | |
2512 } | |
2513 | |
2514 static void dupe_second_menu_remove_cb(GtkWidget *widget, gpointer data) | |
2515 { | |
2516 DupeWindow *dw = data; | |
2517 | |
2518 dupe_window_remove_selection(dw, dw->second_listview); | |
2519 } | |
2520 | |
2521 static void dupe_second_menu_clear_cb(GtkWidget *widget, gpointer data) | |
2522 { | |
2523 DupeWindow *dw = data; | |
2524 | |
2525 dupe_second_clear(dw); | |
2526 dupe_window_recompare(dw); | |
2527 } | |
2528 | |
2529 static GtkWidget *dupe_menu_popup_second(DupeWindow *dw, DupeItem *di) | |
2530 { | |
2531 GtkWidget *menu; | |
2532 gint notempty; | |
2533 gint on_row; | |
2534 | |
2535 on_row = (di != NULL); | |
2536 notempty = (dw->second_list != NULL); | |
2537 | |
2538 menu = popup_menu_short_lived(); | |
2539 menu_item_add_sensitive(menu, _("_View"), on_row, | |
2540 G_CALLBACK(dupe_second_menu_view_cb), dw); | |
2541 menu_item_add_stock_sensitive(menu, _("View in _new window"), GTK_STOCK_NEW, on_row, | |
2542 G_CALLBACK(dupe_second_menu_viewnew_cb), dw); | |
2543 menu_item_add_divider(menu); | |
2544 menu_item_add_sensitive(menu, _("Select all"), notempty, | |
2545 G_CALLBACK(dupe_second_menu_select_all_cb), dw); | |
2546 menu_item_add_sensitive(menu, _("Select none"), notempty, | |
2547 G_CALLBACK(dupe_second_menu_select_none_cb), dw); | |
2548 menu_item_add_divider(menu); | |
2549 menu_item_add_stock_sensitive(menu, _("Rem_ove"), GTK_STOCK_REMOVE, on_row, | |
2550 G_CALLBACK(dupe_second_menu_remove_cb), dw); | |
2551 menu_item_add_stock_sensitive(menu, _("C_lear"), GTK_STOCK_CLEAR, notempty, | |
2552 G_CALLBACK(dupe_second_menu_clear_cb), dw); | |
2553 menu_item_add_divider(menu); | |
2554 menu_item_add_stock(menu, _("Close _window"), GTK_STOCK_CLOSE, | |
2555 G_CALLBACK(dupe_menu_close_cb), dw); | |
2556 | |
2557 return menu; | |
2558 } | |
2559 | |
2560 static void dupe_second_set_toggle_cb(GtkWidget *widget, gpointer data) | |
2561 { | |
2562 DupeWindow *dw = data; | |
2563 | |
2564 dw->second_set = GTK_TOGGLE_BUTTON(widget)->active; | |
2565 | |
2566 if (dw->second_set) | |
2567 { | |
2568 dupe_second_update_status(dw); | |
2569 gtk_table_set_col_spacings(GTK_TABLE(dw->table), PREF_PAD_GAP); | |
2570 gtk_widget_show(dw->second_vbox); | |
2571 } | |
2572 else | |
2573 { | |
2574 gtk_table_set_col_spacings(GTK_TABLE(dw->table), 0); | |
2575 gtk_widget_hide(dw->second_vbox); | |
2576 dupe_second_clear(dw); | |
2577 } | |
2578 | |
2579 dupe_window_recompare(dw); | |
2580 } | |
2581 | |
2582 /* | |
2583 *------------------------------------------------------------------- | |
2584 * match type menu | |
2585 *------------------------------------------------------------------- | |
2586 */ | |
2587 | |
2588 enum { | |
2589 DUPE_MENU_COLUMN_NAME = 0, | |
2590 DUPE_MENU_COLUMN_MASK | |
2591 }; | |
2592 | |
2593 static void dupe_menu_type_cb(GtkWidget *combo, gpointer data) | |
2594 { | |
2595 DupeWindow *dw = data; | |
2596 GtkTreeModel *store; | |
2597 GtkTreeIter iter; | |
2598 | |
2599 store = gtk_combo_box_get_model(GTK_COMBO_BOX(combo)); | |
2600 if (!gtk_combo_box_get_active_iter(GTK_COMBO_BOX(combo), &iter)) return; | |
2601 gtk_tree_model_get(store, &iter, DUPE_MENU_COLUMN_MASK, &dw->match_mask, -1); | |
2602 | |
2603 dupe_window_recompare(dw); | |
2604 } | |
2605 | |
2606 static void dupe_menu_add_item(GtkListStore *store, const gchar *text, DupeMatchType type, DupeWindow *dw) | |
2607 { | |
2608 GtkTreeIter iter; | |
2609 | |
2610 gtk_list_store_append(store, &iter); | |
2611 gtk_list_store_set(store, &iter, DUPE_MENU_COLUMN_NAME, text, | |
2612 DUPE_MENU_COLUMN_MASK, type, -1); | |
2613 | |
2614 if (dw->match_mask == type) gtk_combo_box_set_active_iter(GTK_COMBO_BOX(dw->combo), &iter); | |
2615 } | |
2616 | |
2617 static void dupe_menu_setup(DupeWindow *dw) | |
2618 { | |
2619 GtkListStore *store; | |
2620 GtkCellRenderer *renderer; | |
2621 | |
2622 store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INT); | |
2623 dw->combo = gtk_combo_box_new_with_model(GTK_TREE_MODEL(store)); | |
2624 g_object_unref(store); | |
2625 | |
2626 renderer = gtk_cell_renderer_text_new(); | |
2627 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(dw->combo), renderer, TRUE); | |
2628 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(dw->combo), renderer, | |
2629 "text", DUPE_MENU_COLUMN_NAME, NULL); | |
2630 | |
2631 dupe_menu_add_item(store, _("Name"), DUPE_MATCH_NAME, dw); | |
264
1015282898fe
Add the possibility to match duplicates on the name but ignoring the case.
zas_
parents:
259
diff
changeset
|
2632 dupe_menu_add_item(store, _("Name case-insensitive"), DUPE_MATCH_NAME_CI, dw); |
9 | 2633 dupe_menu_add_item(store, _("Size"), DUPE_MATCH_SIZE, dw); |
2634 dupe_menu_add_item(store, _("Date"), DUPE_MATCH_DATE, dw); | |
2635 dupe_menu_add_item(store, _("Dimensions"), DUPE_MATCH_DIM, dw); | |
2636 dupe_menu_add_item(store, _("Checksum"), DUPE_MATCH_SUM, dw); | |
2637 dupe_menu_add_item(store, _("Path"), DUPE_MATCH_PATH, dw); | |
2638 dupe_menu_add_item(store, _("Similarity (high)"), DUPE_MATCH_SIM_HIGH, dw); | |
2639 dupe_menu_add_item(store, _("Similarity"), DUPE_MATCH_SIM_MED, dw); | |
2640 dupe_menu_add_item(store, _("Similarity (low)"), DUPE_MATCH_SIM_LOW, dw); | |
2641 dupe_menu_add_item(store, _("Similarity (custom)"), DUPE_MATCH_SIM_CUSTOM, dw); | |
2642 | |
2643 g_signal_connect(G_OBJECT(dw->combo), "changed", | |
2644 G_CALLBACK(dupe_menu_type_cb), dw); | |
2645 } | |
2646 | |
2647 /* | |
2648 *------------------------------------------------------------------- | |
2649 * list view columns | |
2650 *------------------------------------------------------------------- | |
2651 */ | |
2652 | |
2653 /* this overrides the low default of a GtkCellRenderer from 100 to CELL_HEIGHT_OVERRIDE, something sane for our purposes */ | |
2654 | |
2655 #define CELL_HEIGHT_OVERRIDE 512 | |
2656 | |
2657 void cell_renderer_height_override(GtkCellRenderer *renderer) | |
2658 { | |
2659 GParamSpec *spec; | |
2660 | |
2661 spec = g_object_class_find_property(G_OBJECT_GET_CLASS(G_OBJECT(renderer)), "height"); | |
2662 if (spec && G_IS_PARAM_SPEC_INT(spec)) | |
2663 { | |
2664 GParamSpecInt *spec_int; | |
2665 | |
2666 spec_int = G_PARAM_SPEC_INT(spec); | |
2667 if (spec_int->maximum < CELL_HEIGHT_OVERRIDE) spec_int->maximum = CELL_HEIGHT_OVERRIDE; | |
2668 } | |
2669 } | |
2670 | |
2671 static GdkColor *dupe_listview_color_shifted(GtkWidget *widget) | |
2672 { | |
2673 static GdkColor color; | |
2674 static GtkWidget *done = NULL; | |
2675 | |
2676 if (done != widget) | |
2677 { | |
2678 GtkStyle *style; | |
2679 | |
2680 style = gtk_widget_get_style(widget); | |
2681 memcpy(&color, &style->base[GTK_STATE_NORMAL], sizeof(color)); | |
2682 shift_color(&color, -1, 0); | |
2683 done = widget; | |
2684 } | |
2685 | |
2686 return &color; | |
2687 } | |
2688 | |
2689 static void dupe_listview_color_cb(GtkTreeViewColumn *tree_column, GtkCellRenderer *cell, | |
2690 GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data) | |
2691 { | |
2692 DupeWindow *dw = data; | |
2693 gboolean set; | |
2694 | |
2695 gtk_tree_model_get(tree_model, iter, DUPE_COLUMN_COLOR, &set, -1); | |
2696 g_object_set(G_OBJECT(cell), | |
2697 "cell-background-gdk", dupe_listview_color_shifted(dw->listview), | |
2698 "cell-background-set", set, NULL); | |
2699 } | |
2700 | |
2701 static void dupe_listview_add_column(DupeWindow *dw, GtkWidget *listview, gint n, const gchar *title, gint image, gint right_justify) | |
2702 { | |
2703 GtkTreeViewColumn *column; | |
2704 GtkCellRenderer *renderer; | |
2705 | |
2706 column = gtk_tree_view_column_new(); | |
2707 gtk_tree_view_column_set_title(column, title); | |
2708 gtk_tree_view_column_set_min_width(column, 4); | |
2709 | |
2710 if (n != DUPE_COLUMN_RANK && | |
2711 n != DUPE_COLUMN_THUMB) | |
2712 { | |
2713 gtk_tree_view_column_set_resizable(column, TRUE); | |
2714 } | |
2715 | |
2716 if (!image) | |
2717 { | |
2718 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_GROW_ONLY); | |
2719 renderer = gtk_cell_renderer_text_new(); | |
2720 if (right_justify) | |
2721 { | |
2722 g_object_set(G_OBJECT(renderer), "xalign", 1.0, NULL); | |
2723 } | |
2724 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
2725 gtk_tree_view_column_add_attribute(column, renderer, "text", n); | |
2726 } | |
2727 else | |
2728 { | |
2729 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED); | |
2730 renderer = gtk_cell_renderer_pixbuf_new(); | |
2731 cell_renderer_height_override(renderer); | |
2732 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
2733 gtk_tree_view_column_add_attribute(column, renderer, "pixbuf", n); | |
2734 } | |
2735 | |
2736 if (listview == dw->listview) | |
2737 { | |
2738 /* sets background before rendering */ | |
2739 gtk_tree_view_column_set_cell_data_func(column, renderer, dupe_listview_color_cb, dw, NULL); | |
2740 } | |
2741 | |
2742 gtk_tree_view_append_column(GTK_TREE_VIEW(listview), column); | |
2743 } | |
2744 | |
2745 static void dupe_listview_set_height(GtkWidget *listview, gint thumb) | |
2746 { | |
2747 GtkTreeViewColumn *column; | |
2748 GtkCellRenderer *cell; | |
2749 GList *list; | |
2750 | |
2751 column = gtk_tree_view_get_column(GTK_TREE_VIEW(listview), DUPE_COLUMN_THUMB - 1); | |
2752 if (!column) return; | |
2753 | |
333 | 2754 gtk_tree_view_column_set_fixed_width(column, (thumb) ? options->thumbnails.max_width : 4); |
9 | 2755 |
2756 list = gtk_tree_view_column_get_cell_renderers(column); | |
2757 if (!list) return; | |
2758 cell = list->data; | |
2759 g_list_free(list); | |
2760 | |
333 | 2761 g_object_set(G_OBJECT(cell), "height", (thumb) ? options->thumbnails.max_height : -1, NULL); |
9 | 2762 gtk_tree_view_columns_autosize(GTK_TREE_VIEW(listview)); |
2763 } | |
2764 | |
2765 | |
2766 /* | |
2767 *------------------------------------------------------------------- | |
2768 * misc cb | |
2769 *------------------------------------------------------------------- | |
2770 */ | |
2771 | |
2772 static void dupe_window_show_thumb_cb(GtkWidget *widget, gpointer data) | |
2773 { | |
2774 DupeWindow *dw = data; | |
2775 | |
2776 dw->show_thumbs = GTK_TOGGLE_BUTTON(widget)->active; | |
2777 | |
2778 if (dw->show_thumbs) | |
2779 { | |
2780 if (!dw->working) dupe_thumb_step(dw); | |
2781 } | |
2782 else | |
2783 { | |
2784 GtkTreeModel *store; | |
2785 GtkTreeIter iter; | |
2786 gint valid; | |
2787 | |
2788 thumb_loader_free(dw->thumb_loader); | |
2789 dw->thumb_loader = NULL; | |
2790 | |
2791 store = gtk_tree_view_get_model(GTK_TREE_VIEW(dw->listview)); | |
2792 valid = gtk_tree_model_get_iter_first(store, &iter); | |
2793 | |
2794 while (valid) | |
2795 { | |
2796 gtk_list_store_set(GTK_LIST_STORE(store), &iter, DUPE_COLUMN_THUMB, NULL, -1); | |
2797 valid = gtk_tree_model_iter_next(store, &iter); | |
2798 } | |
2799 dupe_window_update_progress(dw, NULL, 0.0, FALSE); | |
2800 } | |
2801 | |
2802 dupe_listview_set_height(dw->listview, dw->show_thumbs); | |
2803 } | |
2804 | |
2805 static void dupe_popup_menu_pos_cb(GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer data) | |
2806 { | |
2807 GtkWidget *view = data; | |
2808 GtkTreePath *tpath; | |
2809 gint cx, cy, cw, ch; | |
2810 gint column; | |
2811 | |
2812 gtk_tree_view_get_cursor(GTK_TREE_VIEW(view), &tpath, NULL); | |
2813 if (!tpath) return; | |
2814 | |
2815 if (gtk_tree_view_get_column(GTK_TREE_VIEW(view), DUPE_COLUMN_NAME - 1) != NULL) | |
2816 { | |
2817 column = DUPE_COLUMN_NAME - 1; | |
2818 } | |
2819 else | |
2820 { | |
2821 /* dw->second_listview */ | |
2822 column = 0; | |
2823 } | |
2824 tree_view_get_cell_clamped(GTK_TREE_VIEW(view), tpath, column, TRUE, &cx, &cy, &cw, &ch); | |
2825 gtk_tree_path_free(tpath); | |
2826 cy += ch; | |
2827 popup_menu_position_clamp(menu, &cx, &cy, 0); | |
2828 *x = cx; | |
2829 *y = cy; | |
2830 } | |
2831 | |
2832 static gint dupe_window_keypress_cb(GtkWidget *widget, GdkEventKey *event, gpointer data) | |
2833 { | |
2834 DupeWindow *dw = data; | |
2835 gint stop_signal = FALSE; | |
2836 gint on_second; | |
2837 GtkWidget *listview; | |
2838 GtkTreeModel *store; | |
2839 GtkTreeSelection *selection; | |
2840 GList *slist; | |
2841 DupeItem *di = NULL; | |
2842 | |
2843 on_second = GTK_WIDGET_HAS_FOCUS(dw->second_listview); | |
2844 | |
2845 if (on_second) | |
2846 { | |
2847 listview = dw->second_listview; | |
2848 } | |
2849 else | |
2850 { | |
2851 listview = dw->listview; | |
2852 } | |
2853 | |
2854 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(listview)); | |
2855 slist = gtk_tree_selection_get_selected_rows(selection, &store); | |
2856 if (slist) | |
2857 { | |
2858 GtkTreePath *tpath; | |
2859 GtkTreeIter iter; | |
2860 GList *last; | |
2861 | |
2862 last = g_list_last(slist); | |
2863 tpath = last->data; | |
2864 | |
2865 /* last is newest selected file */ | |
2866 gtk_tree_model_get_iter(store, &iter, tpath); | |
2867 gtk_tree_model_get(store, &iter, DUPE_COLUMN_POINTER, &di, -1); | |
2868 } | |
2869 g_list_foreach(slist, (GFunc)gtk_tree_path_free, NULL); | |
2870 g_list_free(slist); | |
2871 | |
2872 if (event->state & GDK_CONTROL_MASK) | |
2873 { | |
2874 gint edit_val = -1; | |
2875 | |
2876 if (!on_second) | |
2877 { | |
85
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2878 stop_signal = TRUE; |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2879 switch (event->keyval) |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2880 { |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2881 case '1': |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2882 edit_val = 0; |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2883 break; |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2884 case '2': |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2885 edit_val = 1; |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2886 break; |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2887 case '3': |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2888 edit_val = 2; |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2889 break; |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2890 case '4': |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2891 edit_val = 3; |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2892 break; |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2893 case '5': |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2894 edit_val = 4; |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2895 break; |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2896 case '6': |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2897 edit_val = 5; |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2898 break; |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2899 case '7': |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2900 edit_val = 6; |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2901 break; |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2902 case '8': |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2903 edit_val = 7; |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2904 break; |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2905 case '9': |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2906 edit_val = 8; |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2907 break; |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2908 case '0': |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2909 edit_val = 9; |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2910 break; |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2911 case 'C': case 'c': |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2912 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
|
2913 NULL, dw->window); |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2914 break; |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2915 case 'M': case 'm': |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2916 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
|
2917 NULL, dw->window); |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2918 break; |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2919 case 'R': case 'r': |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2920 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
|
2921 break; |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2922 case 'D': case 'd': |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2923 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
|
2924 break; |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2925 case 'P': case 'p': |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2926 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
|
2927 break; |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2928 default: |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2929 stop_signal = FALSE; |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2930 break; |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2931 } |
9 | 2932 } |
2933 | |
85
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2934 if (!stop_signal) |
9 | 2935 { |
85
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2936 stop_signal = TRUE; |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2937 switch (event->keyval) |
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 case 'A': case 'a': |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2940 if (event->state & GDK_SHIFT_MASK) |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2941 { |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2942 gtk_tree_selection_unselect_all(selection); |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2943 } |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2944 else |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2945 { |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2946 gtk_tree_selection_select_all(selection); |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2947 } |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2948 break; |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2949 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
|
2950 if (on_second) |
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_second_clear(dw); |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2953 dupe_window_recompare(dw); |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2954 } |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2955 else |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2956 { |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2957 dupe_window_clear(dw); |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2958 } |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2959 break; |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2960 case 'L': case 'l': |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2961 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
|
2962 break; |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2963 case 'T': case 't': |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2964 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
|
2965 !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
|
2966 break; |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2967 case 'W': case 'w': |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2968 dupe_window_close(dw); |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2969 break; |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2970 default: |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2971 stop_signal = FALSE; |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2972 break; |
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2973 } |
9 | 2974 } |
2975 | |
2976 if (edit_val >= 0) | |
2977 { | |
2978 dupe_window_edit_selected(dw, edit_val); | |
2979 } | |
2980 } | |
2981 else | |
2982 { | |
85
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
2983 stop_signal = TRUE; |
9 | 2984 switch (event->keyval) |
2985 { | |
2986 case GDK_Return: case GDK_KP_Enter: | |
2987 dupe_menu_view(dw, di, listview, FALSE); | |
2988 break; | |
2989 case 'V': case 'v': | |
2990 dupe_menu_view(dw, di, listview, TRUE); | |
2991 break; | |
2992 case GDK_Delete: case GDK_KP_Delete: | |
2993 dupe_window_remove_selection(dw, listview); | |
2994 break; | |
2995 case 'C': case 'c': | |
2996 if (!on_second) | |
2997 { | |
2998 dupe_window_collection_from_selection(dw); | |
2999 } | |
3000 break; | |
3001 case '1': | |
3002 dupe_listview_select_dupes(dw, TRUE); | |
3003 break; | |
3004 case '2': | |
3005 dupe_listview_select_dupes(dw, FALSE); | |
3006 break; | |
3007 case GDK_Menu: | |
3008 case GDK_F10: | |
3009 if (!on_second) | |
3010 { | |
3011 GtkWidget *menu; | |
3012 | |
3013 menu = dupe_menu_popup_main(dw, di); | |
3014 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, | |
3015 dupe_popup_menu_pos_cb, listview, 0, GDK_CURRENT_TIME); | |
3016 } | |
3017 else | |
3018 { | |
3019 GtkWidget *menu; | |
3020 | |
3021 menu = dupe_menu_popup_second(dw, di); | |
3022 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, | |
3023 dupe_popup_menu_pos_cb, listview, 0, GDK_CURRENT_TIME); | |
3024 } | |
3025 break; | |
3026 default: | |
85
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
3027 stop_signal = FALSE; |
9 | 3028 break; |
3029 } | |
3030 } | |
3031 | |
3032 return stop_signal; | |
3033 } | |
3034 | |
3035 | |
3036 void dupe_window_clear(DupeWindow *dw) | |
3037 { | |
3038 GtkListStore *store; | |
3039 | |
3040 dupe_check_stop(dw); | |
3041 | |
3042 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(dw->listview))); | |
3043 gtk_list_store_clear(store); | |
3044 gtk_tree_view_columns_autosize(GTK_TREE_VIEW(dw->listview)); | |
3045 | |
3046 g_list_free(dw->dupes); | |
3047 dw->dupes = NULL; | |
3048 | |
3049 dupe_list_free(dw->list); | |
3050 dw->list = NULL; | |
3051 | |
3052 dupe_match_reset_list(dw->second_list); | |
3053 | |
3054 dupe_window_update_count(dw, FALSE); | |
3055 dupe_window_update_progress(dw, NULL, 0.0, FALSE); | |
3056 } | |
3057 | |
3058 void dupe_window_close(DupeWindow *dw) | |
3059 { | |
3060 dupe_check_stop(dw); | |
3061 | |
3062 dupe_window_list = g_list_remove(dupe_window_list, dw); | |
3063 gtk_widget_destroy(dw->window); | |
3064 | |
3065 g_list_free(dw->dupes); | |
3066 dupe_list_free(dw->list); | |
3067 | |
3068 dupe_list_free(dw->second_list); | |
3069 | |
3070 g_free(dw); | |
3071 } | |
3072 | |
3073 static gint dupe_window_delete(GtkWidget *widget, GdkEvent *event, gpointer data) | |
3074 { | |
3075 DupeWindow *dw = data; | |
3076 dupe_window_close(dw); | |
3077 | |
3078 return TRUE; | |
3079 } | |
3080 | |
3081 /* collection and files can be NULL */ | |
3082 DupeWindow *dupe_window_new(DupeMatchType match_mask) | |
3083 { | |
3084 DupeWindow *dw; | |
3085 GtkWidget *vbox; | |
3086 GtkWidget *scrolled; | |
3087 GtkWidget *frame; | |
3088 GtkWidget *status_box; | |
3089 GtkWidget *label; | |
3090 GtkWidget *button; | |
3091 GtkListStore *store; | |
3092 GtkTreeSelection *selection; | |
3093 GdkGeometry geometry; | |
3094 | |
3095 dw = g_new0(DupeWindow, 1); | |
3096 | |
3097 dw->list = NULL; | |
3098 dw->dupes = NULL; | |
3099 dw->match_mask = match_mask; | |
3100 dw->show_thumbs = FALSE; | |
3101 | |
3102 dw->idle_id = -1; | |
3103 | |
3104 dw->second_set = FALSE; | |
3105 | |
289
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
3106 dw->window = window_new(GTK_WINDOW_TOPLEVEL, "dupe", NULL, NULL, _("Find duplicates")); |
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
3107 |
9 | 3108 geometry.min_width = 32; |
3109 geometry.min_height = 32; | |
3110 geometry.base_width = DUPE_DEF_WIDTH; | |
3111 geometry.base_height = DUPE_DEF_HEIGHT; | |
3112 gtk_window_set_geometry_hints(GTK_WINDOW(dw->window), NULL, &geometry, | |
3113 GDK_HINT_MIN_SIZE | GDK_HINT_BASE_SIZE); | |
3114 | |
3115 gtk_window_set_default_size(GTK_WINDOW(dw->window), DUPE_DEF_WIDTH, DUPE_DEF_HEIGHT); | |
3116 | |
3117 gtk_window_set_resizable(GTK_WINDOW(dw->window), TRUE); | |
3118 gtk_container_set_border_width (GTK_CONTAINER (dw->window), 0); | |
3119 | |
3120 g_signal_connect(G_OBJECT(dw->window), "delete_event", | |
3121 G_CALLBACK(dupe_window_delete), dw); | |
3122 g_signal_connect(G_OBJECT(dw->window), "key_press_event", | |
3123 G_CALLBACK(dupe_window_keypress_cb), dw); | |
3124 | |
3125 vbox = gtk_vbox_new(FALSE, 0); | |
3126 gtk_container_add(GTK_CONTAINER(dw->window), vbox); | |
3127 gtk_widget_show(vbox); | |
3128 | |
3129 dw->table = gtk_table_new(1, 3, FALSE); | |
3130 gtk_box_pack_start(GTK_BOX(vbox), dw->table, TRUE, TRUE, 0); | |
3131 gtk_widget_show(dw->table); | |
3132 | |
3133 scrolled = gtk_scrolled_window_new(NULL, NULL); | |
3134 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN); | |
3135 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
3136 gtk_table_attach_defaults(GTK_TABLE(dw->table), scrolled, 0, 2, 0, 1); | |
3137 gtk_widget_show(scrolled); | |
3138 | |
3139 store = gtk_list_store_new(9, G_TYPE_POINTER, G_TYPE_STRING, GDK_TYPE_PIXBUF, | |
3140 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, | |
3141 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN); | |
3142 dw->listview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); | |
3143 g_object_unref(store); | |
3144 | |
3145 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dw->listview)); | |
3146 gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_MULTIPLE); | |
3147 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(dw->listview), TRUE); | |
3148 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(dw->listview), FALSE); | |
3149 | |
3150 dupe_listview_add_column(dw, dw->listview, DUPE_COLUMN_RANK, "", FALSE, TRUE); | |
3151 dupe_listview_add_column(dw, dw->listview, DUPE_COLUMN_THUMB, "", TRUE, FALSE); | |
3152 dupe_listview_add_column(dw, dw->listview, DUPE_COLUMN_NAME, _("Name"), FALSE, FALSE); | |
3153 dupe_listview_add_column(dw, dw->listview, DUPE_COLUMN_SIZE, _("Size"), FALSE, TRUE); | |
3154 dupe_listview_add_column(dw, dw->listview, DUPE_COLUMN_DATE, _("Date"), FALSE, TRUE); | |
3155 dupe_listview_add_column(dw, dw->listview, DUPE_COLUMN_DIMENSIONS, _("Dimensions"), FALSE, FALSE); | |
3156 dupe_listview_add_column(dw, dw->listview, DUPE_COLUMN_PATH, _("Path"), FALSE, FALSE); | |
3157 | |
3158 gtk_container_add(GTK_CONTAINER(scrolled), dw->listview); | |
3159 gtk_widget_show(dw->listview); | |
3160 | |
3161 dw->second_vbox = gtk_vbox_new(FALSE, 0); | |
3162 gtk_table_attach_defaults(GTK_TABLE(dw->table), dw->second_vbox, 2, 3, 0, 1); | |
3163 if (dw->second_set) | |
3164 { | |
3165 gtk_table_set_col_spacings(GTK_TABLE(dw->table), PREF_PAD_GAP); | |
3166 gtk_widget_show(dw->second_vbox); | |
3167 } | |
3168 else | |
3169 { | |
3170 gtk_table_set_col_spacings(GTK_TABLE(dw->table), 0); | |
3171 } | |
3172 | |
3173 scrolled = gtk_scrolled_window_new(NULL, NULL); | |
3174 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN); | |
3175 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
3176 gtk_box_pack_start(GTK_BOX(dw->second_vbox), scrolled, TRUE, TRUE, 0); | |
3177 gtk_widget_show(scrolled); | |
3178 | |
3179 store = gtk_list_store_new(2, G_TYPE_POINTER, G_TYPE_STRING); | |
3180 dw->second_listview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); | |
3181 | |
3182 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(dw->second_listview)); | |
3183 gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_MULTIPLE); | |
3184 | |
3185 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(dw->second_listview), TRUE); | |
3186 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(dw->second_listview), FALSE); | |
3187 | |
3188 dupe_listview_add_column(dw, dw->second_listview, 1, _("Compare to:"), FALSE, FALSE); | |
3189 | |
3190 gtk_container_add(GTK_CONTAINER(scrolled), dw->second_listview); | |
3191 gtk_widget_show(dw->second_listview); | |
3192 | |
3193 dw->second_status_label = gtk_label_new(""); | |
3194 gtk_box_pack_start(GTK_BOX(dw->second_vbox), dw->second_status_label, FALSE, FALSE, 0); | |
3195 gtk_widget_show(dw->second_status_label); | |
3196 | |
3197 pref_line(dw->second_vbox, GTK_ORIENTATION_HORIZONTAL); | |
3198 | |
3199 status_box = pref_box_new(vbox, FALSE, GTK_ORIENTATION_HORIZONTAL, 0); | |
3200 | |
3201 label = gtk_label_new(_("Compare by:")); | |
3202 gtk_box_pack_start(GTK_BOX(status_box), label, FALSE, FALSE, PREF_PAD_SPACE); | |
3203 gtk_widget_show(label); | |
3204 | |
3205 dupe_menu_setup(dw); | |
3206 gtk_box_pack_start(GTK_BOX(status_box), dw->combo, FALSE, FALSE, 0); | |
3207 gtk_widget_show(dw->combo); | |
3208 | |
3209 dw->button_thumbs = gtk_check_button_new_with_label(_("Thumbnails")); | |
3210 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dw->button_thumbs), dw->show_thumbs); | |
3211 g_signal_connect(G_OBJECT(dw->button_thumbs), "toggled", | |
3212 G_CALLBACK(dupe_window_show_thumb_cb), dw); | |
3213 gtk_box_pack_start(GTK_BOX(status_box), dw->button_thumbs, FALSE, FALSE, PREF_PAD_SPACE); | |
3214 gtk_widget_show(dw->button_thumbs); | |
3215 | |
3216 button = gtk_check_button_new_with_label(_("Compare two file sets")); | |
3217 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), dw->second_set); | |
3218 g_signal_connect(G_OBJECT(button), "toggled", | |
3219 G_CALLBACK(dupe_second_set_toggle_cb), dw); | |
3220 gtk_box_pack_end(GTK_BOX(status_box), button, FALSE, FALSE, PREF_PAD_SPACE); | |
3221 gtk_widget_show(button); | |
3222 | |
3223 status_box = gtk_hbox_new(FALSE, 0); | |
3224 gtk_box_pack_start(GTK_BOX(vbox), status_box, FALSE, FALSE, 0); | |
3225 gtk_widget_show(status_box); | |
3226 | |
3227 frame = gtk_frame_new(NULL); | |
3228 gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN); | |
3229 gtk_box_pack_start(GTK_BOX(status_box), frame, TRUE, TRUE, 0); | |
3230 gtk_widget_show(frame); | |
3231 | |
3232 dw->status_label = gtk_label_new(""); | |
3233 gtk_container_add(GTK_CONTAINER(frame), dw->status_label); | |
3234 gtk_widget_show(dw->status_label); | |
3235 | |
3236 dw->extra_label = gtk_progress_bar_new(); | |
3237 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(dw->extra_label), 0.0); | |
3238 gtk_box_pack_end(GTK_BOX(status_box), dw->extra_label, FALSE, FALSE, 0); | |
3239 gtk_widget_show(dw->extra_label); | |
3240 | |
3241 dupe_dnd_init(dw); | |
3242 | |
3243 /* order is important here, dnd_init should be seeing mouse | |
3244 * presses before we possibly handle (and stop) the signal | |
3245 */ | |
3246 g_signal_connect(G_OBJECT(dw->listview), "button_press_event", | |
3247 G_CALLBACK(dupe_listview_press_cb), dw); | |
3248 g_signal_connect(G_OBJECT(dw->listview), "button_release_event", | |
3249 G_CALLBACK(dupe_listview_release_cb), dw); | |
3250 g_signal_connect(G_OBJECT(dw->second_listview), "button_press_event", | |
3251 G_CALLBACK(dupe_listview_press_cb), dw); | |
3252 g_signal_connect(G_OBJECT(dw->second_listview), "button_release_event", | |
3253 G_CALLBACK(dupe_listview_release_cb), dw); | |
3254 | |
3255 gtk_widget_show(dw->window); | |
3256 | |
3257 dupe_window_update_count(dw, TRUE); | |
3258 dupe_window_update_progress(dw, NULL, 0.0, FALSE); | |
3259 | |
3260 dupe_window_list = g_list_append(dupe_window_list, dw); | |
3261 | |
3262 return dw; | |
3263 } | |
3264 | |
3265 /* | |
3266 *------------------------------------------------------------------- | |
3267 * dnd confirm dir | |
3268 *------------------------------------------------------------------- | |
3269 */ | |
3270 | |
3271 typedef struct { | |
3272 DupeWindow *dw; | |
3273 GList *list; | |
3274 } CDupeConfirmD; | |
3275 | |
3276 static void confirm_dir_list_cancel(GtkWidget *widget, gpointer data) | |
3277 { | |
3278 /* do nothing */ | |
3279 } | |
3280 | |
3281 static void confirm_dir_list_add(GtkWidget *widget, gpointer data) | |
3282 { | |
3283 CDupeConfirmD *d = data; | |
3284 GList *work; | |
3285 | |
3286 dupe_window_add_files(d->dw, d->list, FALSE); | |
3287 | |
3288 work = d->list; | |
3289 while (work) | |
3290 { | |
138 | 3291 FileData *fd = work->data; |
9 | 3292 work = work->next; |
138 | 3293 if (isdir(fd->path)) |
9 | 3294 { |
3295 GList *list = NULL; | |
3296 | |
138 | 3297 filelist_read(fd->path, &list, NULL); |
3298 list = filelist_filter(list, FALSE); | |
9 | 3299 if (list) |
3300 { | |
3301 dupe_window_add_files(d->dw, list, FALSE); | |
138 | 3302 filelist_free(list); |
9 | 3303 } |
3304 } | |
3305 } | |
3306 } | |
3307 | |
3308 static void confirm_dir_list_recurse(GtkWidget *widget, gpointer data) | |
3309 { | |
3310 CDupeConfirmD *d = data; | |
3311 dupe_window_add_files(d->dw, d->list, TRUE); | |
3312 } | |
3313 | |
3314 static void confirm_dir_list_skip(GtkWidget *widget, gpointer data) | |
3315 { | |
3316 CDupeConfirmD *d = data; | |
3317 dupe_window_add_files(d->dw, d->list, FALSE); | |
3318 } | |
3319 | |
3320 static void confirm_dir_list_destroy(GtkWidget *widget, gpointer data) | |
3321 { | |
3322 CDupeConfirmD *d = data; | |
138 | 3323 filelist_free(d->list); |
9 | 3324 g_free(d); |
3325 } | |
3326 | |
3327 static GtkWidget *dupe_confirm_dir_list(DupeWindow *dw, GList *list) | |
3328 { | |
3329 GtkWidget *menu; | |
3330 CDupeConfirmD *d; | |
3331 | |
3332 d = g_new0(CDupeConfirmD, 1); | |
3333 d->dw = dw; | |
3334 d->list = list; | |
3335 | |
3336 menu = popup_menu_short_lived(); | |
3337 g_signal_connect(G_OBJECT(menu), "destroy", | |
3338 G_CALLBACK(confirm_dir_list_destroy), d); | |
3339 | |
3340 menu_item_add_stock(menu, _("Dropped list includes folders."), GTK_STOCK_DND_MULTIPLE, NULL, NULL); | |
3341 menu_item_add_divider(menu); | |
3342 menu_item_add_stock(menu, _("_Add contents"), GTK_STOCK_OK, G_CALLBACK(confirm_dir_list_add), d); | |
3343 menu_item_add_stock(menu, _("Add contents _recursive"), GTK_STOCK_ADD, G_CALLBACK(confirm_dir_list_recurse), d); | |
3344 menu_item_add_stock(menu, _("_Skip folders"), GTK_STOCK_REMOVE, G_CALLBACK(confirm_dir_list_skip), d); | |
3345 menu_item_add_divider(menu); | |
3346 menu_item_add_stock(menu, _("Cancel"), GTK_STOCK_CANCEL, G_CALLBACK(confirm_dir_list_cancel), d); | |
3347 | |
3348 return menu; | |
3349 } | |
3350 | |
3351 /* | |
3352 *------------------------------------------------------------------- | |
3353 * dnd | |
3354 *------------------------------------------------------------------- | |
3355 */ | |
3356 | |
3357 static GtkTargetEntry dupe_drag_types[] = { | |
3358 { "text/uri-list", 0, TARGET_URI_LIST }, | |
3359 { "text/plain", 0, TARGET_TEXT_PLAIN } | |
3360 }; | |
3361 static gint n_dupe_drag_types = 2; | |
3362 | |
3363 static GtkTargetEntry dupe_drop_types[] = { | |
316 | 3364 { TARGET_APP_COLLECTION_MEMBER_STRING, 0, TARGET_APP_COLLECTION_MEMBER }, |
9 | 3365 { "text/uri-list", 0, TARGET_URI_LIST } |
3366 }; | |
3367 static gint n_dupe_drop_types = 2; | |
3368 | |
3369 static void dupe_dnd_data_set(GtkWidget *widget, GdkDragContext *context, | |
3370 GtkSelectionData *selection_data, guint info, | |
3371 guint time, gpointer data) | |
3372 { | |
3373 DupeWindow *dw = data; | |
3374 gchar *uri_text; | |
3375 gint length; | |
3376 GList *list; | |
3377 | |
3378 switch (info) | |
3379 { | |
3380 case TARGET_URI_LIST: | |
3381 case TARGET_TEXT_PLAIN: | |
3382 list = dupe_listview_get_selection(dw, widget); | |
3383 if (!list) return; | |
138 | 3384 uri_text = uri_text_from_filelist(list, &length, (info == TARGET_TEXT_PLAIN)); |
3385 filelist_free(list); | |
9 | 3386 break; |
3387 default: | |
3388 uri_text = NULL; | |
3389 break; | |
3390 } | |
3391 | |
3392 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
|
3393 8, (guchar *)uri_text, length); |
9 | 3394 g_free(uri_text); |
3395 } | |
3396 | |
3397 static void dupe_dnd_data_get(GtkWidget *widget, GdkDragContext *context, | |
3398 gint x, gint y, | |
3399 GtkSelectionData *selection_data, guint info, | |
3400 guint time, gpointer data) | |
3401 { | |
3402 DupeWindow *dw = data; | |
3403 GtkWidget *source; | |
3404 GList *list = NULL; | |
3405 GList *work; | |
3406 | |
3407 source = gtk_drag_get_source_widget(context); | |
3408 if (source == dw->listview || source == dw->second_listview) return; | |
3409 | |
3410 dw->second_drop = (dw->second_set && widget == dw->second_listview); | |
3411 | |
3412 switch (info) | |
3413 { | |
3414 case TARGET_APP_COLLECTION_MEMBER: | |
3415 collection_from_dnd_data((gchar *)selection_data->data, &list, NULL); | |
3416 break; | |
3417 case TARGET_URI_LIST: | |
138 | 3418 list = uri_filelist_from_text((gchar *)selection_data->data, TRUE); |
9 | 3419 work = list; |
3420 while(work) | |
3421 { | |
138 | 3422 FileData *fd = work->data; |
3423 if (isdir(fd->path)) | |
9 | 3424 { |
3425 GtkWidget *menu; | |
3426 menu = dupe_confirm_dir_list(dw, list); | |
3427 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 0, time); | |
3428 return; | |
3429 } | |
3430 work = work->next; | |
3431 } | |
3432 break; | |
3433 default: | |
3434 list = NULL; | |
3435 break; | |
3436 } | |
3437 | |
3438 if (list) | |
3439 { | |
3440 dupe_window_add_files(dw, list, FALSE); | |
138 | 3441 filelist_free(list); |
9 | 3442 } |
3443 } | |
3444 | |
3445 static void dupe_dest_set(GtkWidget *widget, gint enable) | |
3446 { | |
3447 if (enable) | |
3448 { | |
3449 gtk_drag_dest_set(widget, | |
3450 GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_HIGHLIGHT | GTK_DEST_DEFAULT_DROP, | |
3451 dupe_drop_types, n_dupe_drop_types, | |
3452 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_ASK); | |
3453 | |
3454 } | |
3455 else | |
3456 { | |
3457 gtk_drag_dest_unset(widget); | |
3458 } | |
3459 } | |
3460 | |
3461 static void dupe_dnd_begin(GtkWidget *widget, GdkDragContext *context, gpointer data) | |
3462 { | |
3463 DupeWindow *dw = data; | |
3464 dupe_dest_set(dw->listview, FALSE); | |
3465 dupe_dest_set(dw->second_listview, FALSE); | |
3466 | |
3467 if (dw->click_item && !dupe_listview_item_is_selected(dw, dw->click_item, widget)) | |
3468 { | |
3469 GtkListStore *store; | |
3470 GtkTreeIter iter; | |
3471 | |
3472 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(widget))); | |
3473 if (dupe_listview_find_item(store, dw->click_item, &iter) >= 0) | |
3474 { | |
3475 GtkTreeSelection *selection; | |
3476 GtkTreePath *tpath; | |
3477 | |
3478 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget)); | |
3479 gtk_tree_selection_unselect_all(selection); | |
3480 gtk_tree_selection_select_iter(selection, &iter); | |
3481 | |
3482 tpath = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter); | |
3483 gtk_tree_view_set_cursor(GTK_TREE_VIEW(widget), tpath, NULL, FALSE); | |
3484 gtk_tree_path_free(tpath); | |
3485 } | |
3486 } | |
3487 | |
3488 if (dw->show_thumbs && | |
3489 widget == dw->listview && | |
3490 dw->click_item && dw->click_item->pixbuf) | |
3491 { | |
3492 GtkTreeSelection *selection; | |
3493 gint items; | |
3494 | |
3495 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget)); | |
3496 items = gtk_tree_selection_count_selected_rows(selection); | |
3497 dnd_set_drag_icon(widget, context, dw->click_item->pixbuf, items); | |
3498 } | |
3499 } | |
3500 | |
3501 static void dupe_dnd_end(GtkWidget *widget, GdkDragContext *context, gpointer data) | |
3502 { | |
3503 DupeWindow *dw = data; | |
3504 dupe_dest_set(dw->listview, TRUE); | |
3505 dupe_dest_set(dw->second_listview, TRUE); | |
3506 } | |
3507 | |
3508 static void dupe_dnd_init(DupeWindow *dw) | |
3509 { | |
3510 gtk_drag_source_set(dw->listview, GDK_BUTTON1_MASK | GDK_BUTTON2_MASK, | |
3511 dupe_drag_types, n_dupe_drag_types, | |
3512 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK); | |
3513 g_signal_connect(G_OBJECT(dw->listview), "drag_data_get", | |
3514 G_CALLBACK(dupe_dnd_data_set), dw); | |
3515 g_signal_connect(G_OBJECT(dw->listview), "drag_begin", | |
3516 G_CALLBACK(dupe_dnd_begin), dw); | |
3517 g_signal_connect(G_OBJECT(dw->listview), "drag_end", | |
3518 G_CALLBACK(dupe_dnd_end), dw); | |
3519 | |
3520 dupe_dest_set(dw->listview, TRUE); | |
3521 g_signal_connect(G_OBJECT(dw->listview), "drag_data_received", | |
3522 G_CALLBACK(dupe_dnd_data_get), dw); | |
3523 | |
3524 gtk_drag_source_set(dw->second_listview, GDK_BUTTON1_MASK | GDK_BUTTON2_MASK, | |
3525 dupe_drag_types, n_dupe_drag_types, | |
3526 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK); | |
3527 g_signal_connect(G_OBJECT(dw->second_listview), "drag_data_get", | |
3528 G_CALLBACK(dupe_dnd_data_set), dw); | |
3529 g_signal_connect(G_OBJECT(dw->second_listview), "drag_begin", | |
3530 G_CALLBACK(dupe_dnd_begin), dw); | |
3531 g_signal_connect(G_OBJECT(dw->second_listview), "drag_end", | |
3532 G_CALLBACK(dupe_dnd_end), dw); | |
3533 | |
3534 dupe_dest_set(dw->second_listview, TRUE); | |
3535 g_signal_connect(G_OBJECT(dw->second_listview), "drag_data_received", | |
3536 G_CALLBACK(dupe_dnd_data_get), dw); | |
3537 } | |
3538 | |
3539 /* | |
3540 *------------------------------------------------------------------- | |
3541 * maintenance (move, delete, etc.) | |
3542 *------------------------------------------------------------------- | |
3543 */ | |
3544 | |
138 | 3545 void dupe_maint_removed(FileData *fd) |
9 | 3546 { |
3547 GList *work; | |
3548 | |
3549 work = dupe_window_list; | |
3550 while (work) | |
3551 { | |
3552 DupeWindow *dw = work->data; | |
3553 work = work->next; | |
3554 | |
138 | 3555 while (dupe_item_remove_by_path(dw, fd->path)); |
9 | 3556 } |
3557 } | |
3558 | |
138 | 3559 void dupe_maint_renamed(FileData *fd) |
9 | 3560 { |
3561 GList *work; | |
3562 | |
3563 work = dupe_window_list; | |
3564 while (work) | |
3565 { | |
3566 DupeWindow *dw = work->data; | |
3567 work = work->next; | |
3568 | |
138 | 3569 dupe_item_update_fd(dw, fd); |
9 | 3570 } |
3571 | |
3572 } | |
3573 |