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