Mercurial > geeqie.yaz
annotate src/search.c @ 876:2d8705f33da5
set fallback thumbnail pixbuf only if the loading really fails
author | nadvornik |
---|---|
date | Thu, 03 Jul 2008 19:38:19 +0000 |
parents | 06929cbcd796 |
children | cb3b6238782a |
rev | line source |
---|---|
9 | 1 /* |
196 | 2 * Geeqie |
9 | 3 * (C) 2005 John Ellis |
475 | 4 * Copyright (C) 2008 The Geeqie Team |
9 | 5 * |
6 * Author: John Ellis | |
7 * | |
8 * This software is released under the GNU General Public License (GNU GPL). | |
9 * Please read the included file COPYING for more information. | |
10 * This software comes with no warranty of any kind, use at your own risk! | |
11 */ | |
12 | |
13 | |
281 | 14 #include "main.h" |
9 | 15 #include "search.h" |
16 | |
17 #include "bar_info.h" | |
18 #include "cache.h" | |
19 #include "collect.h" | |
20 #include "collect-table.h" | |
21 #include "dnd.h" | |
22 #include "dupe.h" | |
23 #include "image-load.h" | |
24 #include "info.h" | |
25 #include "editors.h" | |
26 #include "img-view.h" | |
586 | 27 #include "filedata.h" |
9 | 28 #include "layout_image.h" |
29 #include "menu.h" | |
30 #include "print.h" | |
31 #include "thumb.h" | |
32 #include "utilops.h" | |
33 #include "ui_bookmark.h" | |
34 #include "ui_fileops.h" | |
35 #include "ui_menu.h" | |
36 #include "ui_misc.h" | |
37 #include "ui_spinner.h" | |
38 #include "ui_tabcomp.h" | |
39 #include "ui_tree_edit.h" | |
648
e34c1002e553
Move some functions from main.[ch] to new window.[ch].
zas_
parents:
608
diff
changeset
|
40 #include "window.h" |
9 | 41 |
42 #include <gdk/gdkkeysyms.h> /* for keyboard values */ | |
43 | |
44 | |
45 #define DEF_SEARCH_WIDTH 700 | |
46 #define DEF_SEARCH_HEIGHT 450 | |
47 | |
48 #define SEARCH_BUFFER_MATCH_LOAD 20 | |
49 #define SEARCH_BUFFER_MATCH_HIT 5 | |
50 #define SEARCH_BUFFER_MATCH_MISS 1 | |
51 #define SEARCH_BUFFER_FLUSH_SIZE 99 | |
52 | |
53 | |
54 typedef enum { | |
55 SEARCH_MATCH_NONE, | |
56 SEARCH_MATCH_EQUAL, | |
57 SEARCH_MATCH_CONTAINS, | |
58 SEARCH_MATCH_UNDER, | |
59 SEARCH_MATCH_OVER, | |
60 SEARCH_MATCH_BETWEEN, | |
61 SEARCH_MATCH_ALL, | |
62 SEARCH_MATCH_ANY | |
63 } MatchType; | |
64 | |
65 enum { | |
66 SEARCH_COLUMN_POINTER = 0, | |
67 SEARCH_COLUMN_RANK, | |
68 SEARCH_COLUMN_THUMB, | |
69 SEARCH_COLUMN_NAME, | |
70 SEARCH_COLUMN_SIZE, | |
71 SEARCH_COLUMN_DATE, | |
72 SEARCH_COLUMN_DIMENSIONS, | |
73 SEARCH_COLUMN_PATH, | |
74 SEARCH_COLUMN_COUNT /* total columns */ | |
75 }; | |
76 | |
77 typedef struct _SearchData SearchData; | |
78 struct _SearchData | |
79 { | |
80 GtkWidget *window; | |
81 | |
82 GtkWidget *button_thumbs; | |
83 GtkWidget *label_status; | |
84 GtkWidget *label_progress; | |
85 GtkWidget *button_start; | |
86 GtkWidget *button_stop; | |
87 GtkWidget *spinner; | |
88 | |
89 GtkWidget *box_search; | |
90 | |
91 GtkWidget *menu_path; | |
92 GtkWidget *path_entry; | |
93 GtkWidget *check_recurse; | |
94 | |
95 GtkWidget *result_view; | |
96 | |
97 GtkWidget *check_name; | |
98 GtkWidget *menu_name; | |
99 GtkWidget *entry_name; | |
100 GtkWidget *check_name_match_case; | |
101 | |
102 GtkWidget *check_size; | |
103 GtkWidget *menu_size; | |
104 GtkWidget *spin_size; | |
105 GtkWidget *spin_size_end; | |
106 | |
107 GtkWidget *check_date; | |
108 GtkWidget *menu_date; | |
109 GtkWidget *date_sel; | |
110 GtkWidget *date_sel_end; | |
111 | |
112 GtkWidget *check_dimensions; | |
113 GtkWidget *menu_dimensions; | |
114 GtkWidget *spin_width; | |
115 GtkWidget *spin_height; | |
116 GtkWidget *spin_width_end; | |
117 GtkWidget *spin_height_end; | |
118 | |
119 GtkWidget *check_similarity; | |
120 GtkWidget *spin_similarity; | |
121 GtkWidget *entry_similarity; | |
122 | |
123 GtkWidget *check_keywords; | |
124 GtkWidget *menu_keywords; | |
125 GtkWidget *entry_keywords; | |
126 | |
783 | 127 FileData *search_dir_fd; |
9 | 128 gint search_path_recurse; |
129 gchar *search_name; | |
130 gint search_name_match_case; | |
131 gint64 search_size; | |
132 gint64 search_size_end; | |
133 gint search_date_y; | |
134 gint search_date_m; | |
135 gint search_date_d; | |
136 gint search_date_end_y; | |
137 gint search_date_end_m; | |
138 gint search_date_end_d; | |
139 gint search_width; | |
140 gint search_height; | |
141 gint search_width_end; | |
142 gint search_height_end; | |
143 gint search_similarity; | |
144 gchar *search_similarity_path; | |
145 CacheData *search_similarity_cd; | |
146 GList *search_keyword_list; | |
147 | |
148 MatchType search_type; | |
149 | |
150 MatchType match_name; | |
151 MatchType match_size; | |
152 MatchType match_date; | |
153 MatchType match_dimensions; | |
154 MatchType match_keywords; | |
155 | |
156 gboolean match_name_enable; | |
157 gboolean match_size_enable; | |
158 gboolean match_date_enable; | |
159 gboolean match_dimensions_enable; | |
160 gboolean match_similarity_enable; | |
161 gboolean match_keywords_enable; | |
162 | |
163 GList *search_folder_list; | |
164 GList *search_done_list; | |
165 GList *search_file_list; | |
166 GList *search_buffer_list; | |
167 | |
168 gint search_count; | |
169 gint search_total; | |
170 gint search_buffer_count; | |
171 | |
172 gint search_idle_id; | |
173 gint update_idle_id; | |
174 | |
175 ImageLoader *img_loader; | |
176 CacheData *img_cd; | |
177 | |
178 FileData *click_fd; | |
179 | |
180 ThumbLoader *thumb_loader; | |
181 gint thumb_enable; | |
182 FileData *thumb_fd; | |
183 }; | |
184 | |
185 typedef struct _MatchFileData MatchFileData; | |
186 struct _MatchFileData | |
187 { | |
138 | 188 FileData *fd; |
9 | 189 gint width; |
190 gint height; | |
191 gint rank; | |
192 }; | |
193 | |
194 typedef struct _MatchList MatchList; | |
195 struct _MatchList | |
196 { | |
197 const gchar *text; | |
198 const MatchType type; | |
199 }; | |
200 | |
201 static const MatchList text_search_menu_path[] = { | |
202 { N_("folder"), SEARCH_MATCH_NONE }, | |
203 { N_("comments"), SEARCH_MATCH_ALL }, | |
204 { N_("results"), SEARCH_MATCH_CONTAINS } | |
205 }; | |
206 | |
207 static const MatchList text_search_menu_name[] = { | |
208 { N_("contains"), SEARCH_MATCH_CONTAINS }, | |
209 { N_("is"), SEARCH_MATCH_EQUAL } | |
210 }; | |
211 | |
212 static const MatchList text_search_menu_size[] = { | |
213 { N_("equal to"), SEARCH_MATCH_EQUAL }, | |
214 { N_("less than"), SEARCH_MATCH_UNDER }, | |
215 { N_("greater than"), SEARCH_MATCH_OVER }, | |
216 { N_("between"), SEARCH_MATCH_BETWEEN } | |
217 }; | |
218 | |
219 static const MatchList text_search_menu_date[] = { | |
220 { N_("equal to"), SEARCH_MATCH_EQUAL }, | |
221 { N_("before"), SEARCH_MATCH_UNDER }, | |
222 { N_("after"), SEARCH_MATCH_OVER }, | |
223 { N_("between"), SEARCH_MATCH_BETWEEN } | |
224 }; | |
225 | |
226 static const MatchList text_search_menu_keyword[] = { | |
227 { N_("match all"), SEARCH_MATCH_ALL }, | |
228 { N_("match any"), SEARCH_MATCH_ANY }, | |
229 { N_("exclude"), SEARCH_MATCH_NONE } | |
230 }; | |
231 | |
232 static GList *search_window_list = NULL; | |
233 | |
234 | |
235 static gint search_result_selection_count(SearchData *sd, gint64 *bytes); | |
236 static gint search_result_count(SearchData *sd, gint64 *bytes); | |
237 | |
238 static void search_window_close(SearchData *sd); | |
239 | |
795 | 240 static void search_notify_cb(FileData *fd, NotifyType type, gpointer data); |
9 | 241 |
242 /* | |
243 *------------------------------------------------------------------- | |
244 * utils | |
245 *------------------------------------------------------------------- | |
246 */ | |
247 | |
248 static time_t convert_dmy_to_time(gint day, gint month, gint year) | |
249 { | |
250 struct tm lt; | |
251 | |
252 lt.tm_sec = 0; | |
253 lt.tm_min = 0; | |
254 lt.tm_hour = 0; | |
255 lt.tm_mday = day; | |
256 lt.tm_mon = month - 1; | |
257 lt.tm_year = year - 1900; | |
258 lt.tm_isdst = 0; | |
259 | |
260 return mktime(<); | |
261 } | |
262 | |
263 static void search_status_update(SearchData *sd) | |
264 { | |
265 gchar *buf; | |
266 gint t; | |
267 gint s; | |
268 gint64 t_bytes; | |
269 gint64 s_bytes; | |
270 gchar *tt; | |
271 | |
272 t = search_result_count(sd, &t_bytes); | |
273 s = search_result_selection_count(sd, &s_bytes); | |
606
408f36d536a5
search_status_update(): slightly reduce code redundancy.
zas_
parents:
586
diff
changeset
|
274 |
408f36d536a5
search_status_update(): slightly reduce code redundancy.
zas_
parents:
586
diff
changeset
|
275 tt = text_from_size_abrev(t_bytes); |
9 | 276 |
277 if (s > 0) | |
278 { | |
606
408f36d536a5
search_status_update(): slightly reduce code redundancy.
zas_
parents:
586
diff
changeset
|
279 gchar *ts = text_from_size_abrev(s_bytes); |
9 | 280 buf = g_strdup_printf(_("%s, %d files (%s, %d)"), tt, t, ts, s); |
281 g_free(ts); | |
282 } | |
283 else | |
284 { | |
285 buf = g_strdup_printf(_("%s, %d files"), tt, t); | |
286 } | |
287 | |
606
408f36d536a5
search_status_update(): slightly reduce code redundancy.
zas_
parents:
586
diff
changeset
|
288 g_free(tt); |
408f36d536a5
search_status_update(): slightly reduce code redundancy.
zas_
parents:
586
diff
changeset
|
289 |
9 | 290 gtk_label_set_text(GTK_LABEL(sd->label_status), buf); |
291 g_free(buf); | |
292 } | |
293 | |
294 static void search_progress_update(SearchData *sd, gint search, gdouble thumbs) | |
295 { | |
296 | |
297 if (search || thumbs >= 0.0) | |
298 { | |
299 gchar *buf; | |
300 const gchar *message; | |
301 | |
302 if (search && (sd->search_folder_list || sd->search_file_list)) | |
303 message = _("Searching..."); | |
304 else if (thumbs >= 0.0) | |
305 message = _("Loading thumbs..."); | |
306 else | |
307 message = ""; | |
308 | |
309 buf = g_strdup_printf("%s(%d / %d)", message, sd->search_count, sd->search_total); | |
310 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(sd->label_progress), buf); | |
311 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(sd->label_progress), | |
312 (thumbs >= 0.0) ? thumbs : 0.0); | |
313 g_free(buf); | |
314 } | |
315 else | |
316 { | |
317 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(sd->label_progress), ""); | |
318 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(sd->label_progress), 0.0); | |
319 } | |
320 } | |
321 | |
322 /* | |
323 *------------------------------------------------------------------- | |
324 * result list | |
325 *------------------------------------------------------------------- | |
326 */ | |
327 | |
328 static gint search_result_find_row(SearchData *sd, FileData *fd, GtkTreeIter *iter) | |
329 { | |
330 GtkTreeModel *store; | |
331 gint valid; | |
332 gint n = 0; | |
333 | |
334 store = gtk_tree_view_get_model(GTK_TREE_VIEW(sd->result_view)); | |
335 valid = gtk_tree_model_get_iter_first(store, iter); | |
336 while (valid) | |
337 { | |
138 | 338 MatchFileData *mfd; |
9 | 339 n++; |
340 | |
138 | 341 gtk_tree_model_get(store, iter, SEARCH_COLUMN_POINTER, &mfd, -1); |
342 if (mfd->fd == fd) return n; | |
9 | 343 valid = gtk_tree_model_iter_next(store, iter); |
344 } | |
345 | |
346 return -1; | |
347 } | |
348 | |
349 static gint search_result_row_selected(SearchData *sd, FileData *fd) | |
350 { | |
351 GtkTreeModel *store; | |
352 GtkTreeSelection *selection; | |
353 GList *slist; | |
354 GList *work; | |
355 gint found = FALSE; | |
356 | |
357 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(sd->result_view)); | |
358 slist = gtk_tree_selection_get_selected_rows(selection, &store); | |
359 work = slist; | |
360 while (!found && work) | |
361 { | |
362 GtkTreePath *tpath = work->data; | |
138 | 363 MatchFileData *mfd_n; |
9 | 364 GtkTreeIter iter; |
365 | |
366 gtk_tree_model_get_iter(store, &iter, tpath); | |
138 | 367 gtk_tree_model_get(store, &iter, SEARCH_COLUMN_POINTER, &mfd_n, -1); |
368 if (mfd_n->fd == fd) found = TRUE; | |
9 | 369 work = work->next; |
370 } | |
371 g_list_foreach(slist, (GFunc)gtk_tree_path_free, NULL); | |
372 g_list_free(slist); | |
373 | |
374 return found; | |
375 } | |
376 | |
377 static gint search_result_selection_util(SearchData *sd, gint64 *bytes, GList **list) | |
378 { | |
379 GtkTreeModel *store; | |
380 GtkTreeSelection *selection; | |
381 GList *slist; | |
382 GList *work; | |
383 gint n = 0; | |
384 gint64 total = 0; | |
385 GList *plist = NULL; | |
386 | |
387 store = gtk_tree_view_get_model(GTK_TREE_VIEW(sd->result_view)); | |
388 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(sd->result_view)); | |
389 slist = gtk_tree_selection_get_selected_rows(selection, &store); | |
390 work = slist; | |
391 while (work) | |
392 { | |
393 n++; | |
394 | |
395 if (bytes || list) | |
396 { | |
397 GtkTreePath *tpath = work->data; | |
138 | 398 MatchFileData *mfd; |
9 | 399 GtkTreeIter iter; |
400 | |
401 gtk_tree_model_get_iter(store, &iter, tpath); | |
138 | 402 gtk_tree_model_get(store, &iter, SEARCH_COLUMN_POINTER, &mfd, -1); |
403 total += mfd->fd->size; | |
404 | |
405 if (list) plist = g_list_prepend(plist, file_data_ref(mfd->fd)); | |
9 | 406 } |
442 | 407 |
9 | 408 work = work->next; |
409 } | |
410 g_list_foreach(slist, (GFunc)gtk_tree_path_free, NULL); | |
411 g_list_free(slist); | |
412 | |
413 if (bytes) *bytes = total; | |
414 if (list) *list = g_list_reverse(plist); | |
415 | |
416 return n; | |
417 } | |
418 | |
419 static GList *search_result_selection_list(SearchData *sd) | |
420 { | |
421 GList *list; | |
422 | |
423 search_result_selection_util(sd, NULL, &list); | |
424 return list; | |
425 } | |
426 | |
427 static gint search_result_selection_count(SearchData *sd, gint64 *bytes) | |
428 { | |
429 return search_result_selection_util(sd, bytes, NULL); | |
430 } | |
431 | |
432 static gint search_result_util(SearchData *sd, gint64 *bytes, GList **list) | |
433 { | |
434 GtkTreeModel *store; | |
435 GtkTreeIter iter; | |
436 gint valid; | |
437 gint n = 0; | |
438 gint64 total = 0; | |
439 GList *plist = NULL; | |
440 | |
441 store = gtk_tree_view_get_model(GTK_TREE_VIEW(sd->result_view)); | |
442 | |
443 valid = gtk_tree_model_get_iter_first(store, &iter); | |
444 while (valid) | |
445 { | |
446 n++; | |
447 if (bytes || list) | |
448 { | |
138 | 449 MatchFileData *mfd; |
450 | |
451 gtk_tree_model_get(store, &iter, SEARCH_COLUMN_POINTER, &mfd, -1); | |
452 total += mfd->fd->size; | |
453 | |
454 if (list) plist = g_list_prepend(plist, file_data_ref(mfd->fd)); | |
9 | 455 } |
456 valid = gtk_tree_model_iter_next(store, &iter); | |
457 } | |
458 | |
459 if (bytes) *bytes = total; | |
460 if (list) *list = g_list_reverse(plist); | |
461 | |
462 return n; | |
463 } | |
464 | |
138 | 465 static GList *search_result_get_filelist(SearchData *sd) |
9 | 466 { |
467 GList *list = NULL; | |
468 | |
469 search_result_util(sd, NULL, &list); | |
470 return list; | |
471 } | |
472 | |
473 static gint search_result_count(SearchData *sd, gint64 *bytes) | |
474 { | |
475 return search_result_util(sd, bytes, NULL); | |
476 } | |
477 | |
478 static void search_result_append(SearchData *sd, MatchFileData *mfd) | |
479 { | |
480 FileData *fd; | |
481 GtkListStore *store; | |
482 GtkTreeIter iter; | |
483 gchar *text_size; | |
484 gchar *text_dim = NULL; | |
485 | |
138 | 486 fd = mfd->fd; |
9 | 487 |
488 if (!fd) return; | |
489 | |
490 text_size = text_from_size(fd->size); | |
491 if (mfd->width > 0 && mfd->height > 0) text_dim = g_strdup_printf("%d x %d", mfd->width, mfd->height); | |
492 | |
493 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(sd->result_view))); | |
494 gtk_list_store_append(store, &iter); | |
495 gtk_list_store_set(store, &iter, | |
138 | 496 SEARCH_COLUMN_POINTER, mfd, |
9 | 497 SEARCH_COLUMN_RANK, mfd->rank, |
845 | 498 SEARCH_COLUMN_THUMB, fd->thumb_pixbuf, |
9 | 499 SEARCH_COLUMN_NAME, fd->name, |
500 SEARCH_COLUMN_SIZE, text_size, | |
501 SEARCH_COLUMN_DATE, text_from_time(fd->date), | |
502 SEARCH_COLUMN_DIMENSIONS, text_dim, | |
503 SEARCH_COLUMN_PATH, fd->path, | |
504 -1); | |
505 | |
506 g_free(text_size); | |
507 g_free(text_dim); | |
508 } | |
509 | |
510 static GList *search_result_refine_list(SearchData *sd) | |
511 { | |
512 GList *list = NULL; | |
513 GtkTreeModel *store; | |
514 GtkTreeIter iter; | |
515 gint valid; | |
516 | |
517 store = gtk_tree_view_get_model(GTK_TREE_VIEW(sd->result_view)); | |
518 | |
519 valid = gtk_tree_model_get_iter_first(store, &iter); | |
520 while (valid) | |
521 { | |
138 | 522 MatchFileData *mfd; |
523 | |
524 gtk_tree_model_get(store, &iter, SEARCH_COLUMN_POINTER, &mfd, -1); | |
525 list = g_list_prepend(list, mfd->fd); | |
9 | 526 |
527 valid = gtk_tree_model_iter_next(store, &iter); | |
528 } | |
529 | |
530 /* clear it here, so that the FileData in list is not freed */ | |
531 gtk_list_store_clear(GTK_LIST_STORE(store)); | |
532 | |
533 return g_list_reverse(list); | |
534 } | |
535 | |
536 static gboolean search_result_free_node(GtkTreeModel *store, GtkTreePath *tpath, | |
537 GtkTreeIter *iter, gpointer data) | |
538 { | |
138 | 539 MatchFileData *mfd; |
540 | |
541 gtk_tree_model_get(store, iter, SEARCH_COLUMN_POINTER, &mfd, -1); | |
542 file_data_unref(mfd->fd); | |
543 g_free(mfd); | |
9 | 544 |
545 return FALSE; | |
546 } | |
547 | |
548 static void search_result_clear(SearchData *sd) | |
549 { | |
550 GtkListStore *store; | |
551 | |
552 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(sd->result_view))); | |
553 | |
554 gtk_tree_model_foreach(GTK_TREE_MODEL(store), search_result_free_node, sd); | |
555 gtk_list_store_clear(store); | |
556 | |
557 sd->click_fd = NULL; | |
558 | |
559 thumb_loader_free(sd->thumb_loader); | |
560 sd->thumb_loader = NULL; | |
561 sd->thumb_fd = NULL; | |
562 | |
563 search_status_update(sd); | |
564 } | |
565 | |
138 | 566 static void search_result_remove_item(SearchData *sd, MatchFileData *mfd, GtkTreeIter *iter) |
9 | 567 { |
568 GtkTreeModel *store; | |
569 | |
138 | 570 if (!mfd || !iter) return; |
9 | 571 |
572 store = gtk_tree_view_get_model(GTK_TREE_VIEW(sd->result_view)); | |
573 | |
574 tree_view_move_cursor_away(GTK_TREE_VIEW(sd->result_view), iter, TRUE); | |
575 | |
576 gtk_list_store_remove(GTK_LIST_STORE(store), iter); | |
138 | 577 if (sd->click_fd == mfd->fd) sd->click_fd = NULL; |
578 if (sd->thumb_fd == mfd->fd) sd->thumb_fd = NULL; | |
579 file_data_unref(mfd->fd); | |
580 g_free(mfd); | |
9 | 581 } |
582 | |
583 static void search_result_remove(SearchData *sd, FileData *fd) | |
584 { | |
585 GtkTreeModel *store; | |
586 GtkTreeIter iter; | |
587 gint valid; | |
588 | |
589 store = gtk_tree_view_get_model(GTK_TREE_VIEW(sd->result_view)); | |
590 valid = gtk_tree_model_get_iter_first(store, &iter); | |
591 while (valid) | |
592 { | |
138 | 593 MatchFileData *mfd; |
594 | |
595 gtk_tree_model_get(store, &iter, SEARCH_COLUMN_POINTER, &mfd, -1); | |
596 if (mfd->fd == fd) | |
9 | 597 { |
138 | 598 search_result_remove_item(sd, mfd, &iter); |
9 | 599 return; |
600 } | |
601 | |
602 valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter); | |
603 } | |
604 } | |
605 | |
606 static void search_result_remove_selection(SearchData *sd) | |
607 { | |
608 GtkTreeSelection *selection; | |
609 GtkTreeModel *store; | |
610 GList *slist; | |
611 GList *flist = NULL; | |
612 GList *work; | |
613 | |
614 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(sd->result_view)); | |
615 slist = gtk_tree_selection_get_selected_rows(selection, &store); | |
616 work = slist; | |
617 while (work) | |
618 { | |
619 GtkTreePath *tpath = work->data; | |
620 GtkTreeIter iter; | |
138 | 621 MatchFileData *mfd; |
9 | 622 |
623 gtk_tree_model_get_iter(store, &iter, tpath); | |
138 | 624 gtk_tree_model_get(store, &iter, SEARCH_COLUMN_POINTER, &mfd, -1); |
625 flist = g_list_prepend(flist, mfd->fd); | |
9 | 626 work = work->next; |
627 } | |
628 g_list_foreach(slist, (GFunc)gtk_tree_path_free, NULL); | |
629 g_list_free(slist); | |
630 | |
631 work = flist; | |
632 while (work) | |
633 { | |
634 FileData *fd = work->data; | |
635 work = work->next; | |
636 | |
637 search_result_remove(sd, fd); | |
638 } | |
639 g_list_free(flist); | |
640 | |
641 search_status_update(sd); | |
642 } | |
643 | |
644 static void search_result_edit_selected(SearchData *sd, gint n) | |
645 { | |
646 GList *list; | |
647 | |
648 list = search_result_selection_list(sd); | |
753 | 649 file_util_start_editor_from_filelist(n, list, sd->window); |
138 | 650 filelist_free(list); |
9 | 651 } |
652 | |
653 static void search_result_collection_from_selection(SearchData *sd) | |
654 { | |
655 CollectWindow *w; | |
656 GList *list; | |
657 | |
658 list = search_result_selection_list(sd); | |
659 w = collection_window_new(NULL); | |
138 | 660 collection_table_add_filelist(w->table, list); |
661 filelist_free(list); | |
9 | 662 } |
663 | |
664 static gint search_result_update_idle_cb(gpointer data) | |
665 { | |
666 SearchData *sd = data; | |
667 | |
668 search_status_update(sd); | |
669 | |
670 sd->update_idle_id = -1; | |
671 return FALSE; | |
672 } | |
673 | |
674 static void search_result_update_idle_cancel(SearchData *sd) | |
675 { | |
676 if (sd->update_idle_id != -1) g_source_remove(sd->update_idle_id); | |
677 sd->update_idle_id = -1; | |
678 } | |
679 | |
680 static gboolean search_result_select_cb(GtkTreeSelection *selection, GtkTreeModel *store, | |
681 GtkTreePath *tpath, gboolean selected, gpointer data) | |
682 { | |
683 SearchData *sd = data; | |
684 | |
685 if (sd->update_idle_id == -1) | |
686 { | |
687 sd->update_idle_id = g_idle_add(search_result_update_idle_cb, sd); | |
688 } | |
689 | |
690 return TRUE; | |
691 } | |
692 | |
693 /* | |
694 *------------------------------------------------------------------- | |
695 * result list thumbs | |
696 *------------------------------------------------------------------- | |
697 */ | |
698 | |
699 static void search_result_thumb_step(SearchData *sd); | |
700 | |
701 | |
702 static void search_result_thumb_set(SearchData *sd, FileData *fd, GtkTreeIter *iter) | |
703 { | |
704 GtkListStore *store; | |
705 GtkTreeIter iter_n; | |
706 | |
707 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(sd->result_view))); | |
708 if (!iter) | |
709 { | |
710 if (search_result_find_row(sd, fd, &iter_n) >= 0) iter = &iter_n; | |
711 } | |
712 | |
845 | 713 if (iter) gtk_list_store_set(store, iter, SEARCH_COLUMN_THUMB, fd->thumb_pixbuf, -1); |
9 | 714 } |
715 | |
716 static void search_result_thumb_do(SearchData *sd) | |
717 { | |
718 FileData *fd; | |
719 | |
720 if (!sd->thumb_loader || !sd->thumb_fd) return; | |
721 fd = sd->thumb_fd; | |
722 | |
723 search_result_thumb_set(sd, fd, NULL); | |
724 } | |
725 | |
726 static void search_result_thumb_done_cb(ThumbLoader *tl, gpointer data) | |
727 { | |
728 SearchData *sd = data; | |
729 | |
730 search_result_thumb_do(sd); | |
731 search_result_thumb_step(sd); | |
732 } | |
733 | |
734 static void search_result_thumb_step(SearchData *sd) | |
735 { | |
736 GtkTreeModel *store; | |
737 GtkTreeIter iter; | |
138 | 738 MatchFileData *mfd = NULL; |
9 | 739 gint valid; |
740 gint row = 0; | |
741 gint length = 0; | |
742 | |
743 store = gtk_tree_view_get_model(GTK_TREE_VIEW(sd->result_view)); | |
744 valid = gtk_tree_model_get_iter_first(store, &iter); | |
607 | 745 if (!sd->thumb_enable) |
746 { | |
747 while (valid) | |
748 { | |
749 gtk_list_store_set(GTK_LIST_STORE(store), &iter, SEARCH_COLUMN_THUMB, NULL, -1); | |
750 valid = gtk_tree_model_iter_next(store, &iter); | |
751 } | |
752 return; | |
753 } | |
754 | |
138 | 755 while (!mfd && valid) |
9 | 756 { |
757 GdkPixbuf *pixbuf; | |
758 | |
759 length++; | |
138 | 760 gtk_tree_model_get(store, &iter, SEARCH_COLUMN_POINTER, &mfd, SEARCH_COLUMN_THUMB, &pixbuf, -1); |
845 | 761 if (pixbuf || mfd->fd->thumb_pixbuf) |
9 | 762 { |
845 | 763 if (!pixbuf) gtk_list_store_set(GTK_LIST_STORE(store), &iter, SEARCH_COLUMN_THUMB, mfd->fd->thumb_pixbuf, -1); |
9 | 764 row++; |
138 | 765 mfd = NULL; |
9 | 766 } |
767 valid = gtk_tree_model_iter_next(store, &iter); | |
768 } | |
769 if (valid) | |
770 { | |
771 while (gtk_tree_model_iter_next(store, &iter)) length++; | |
772 } | |
773 | |
138 | 774 if (!mfd) |
9 | 775 { |
776 sd->thumb_fd = NULL; | |
777 thumb_loader_free(sd->thumb_loader); | |
778 sd->thumb_loader = NULL; | |
779 | |
780 search_progress_update(sd, TRUE, -1.0); | |
781 return; | |
782 } | |
783 | |
784 search_progress_update(sd, FALSE, (gdouble)row/length); | |
785 | |
138 | 786 sd->thumb_fd = mfd->fd; |
9 | 787 thumb_loader_free(sd->thumb_loader); |
333 | 788 sd->thumb_loader = thumb_loader_new(options->thumbnails.max_width, options->thumbnails.max_height); |
9 | 789 |
790 thumb_loader_set_callbacks(sd->thumb_loader, | |
791 search_result_thumb_done_cb, | |
792 search_result_thumb_done_cb, | |
793 NULL, | |
794 sd); | |
838 | 795 if (!thumb_loader_start(sd->thumb_loader, mfd->fd)) |
9 | 796 { |
797 search_result_thumb_do(sd); | |
798 search_result_thumb_step(sd); | |
799 } | |
800 } | |
801 | |
802 static void search_result_thumb_height(SearchData *sd) | |
803 { | |
804 GtkTreeViewColumn *column; | |
805 GtkCellRenderer *cell; | |
806 GList *list; | |
807 | |
808 column = gtk_tree_view_get_column(GTK_TREE_VIEW(sd->result_view), SEARCH_COLUMN_THUMB - 1); | |
809 if (!column) return; | |
810 | |
333 | 811 gtk_tree_view_column_set_fixed_width(column, (sd->thumb_enable) ? options->thumbnails.max_width : 4); |
9 | 812 |
813 list = gtk_tree_view_column_get_cell_renderers(column); | |
814 if (!list) return; | |
815 cell = list->data; | |
816 g_list_free(list); | |
817 | |
333 | 818 g_object_set(G_OBJECT(cell), "height", (sd->thumb_enable) ? options->thumbnails.max_height : -1, NULL); |
9 | 819 gtk_tree_view_columns_autosize(GTK_TREE_VIEW(sd->result_view)); |
820 } | |
821 | |
822 static void search_result_thumb_enable(SearchData *sd, gint enable) | |
823 { | |
824 if (sd->thumb_enable == enable) return; | |
825 | |
826 if (sd->thumb_enable) | |
827 { | |
828 GtkTreeModel *store; | |
829 GtkTreeIter iter; | |
830 gint valid; | |
831 | |
832 thumb_loader_free(sd->thumb_loader); | |
833 sd->thumb_loader = NULL; | |
834 | |
835 store = gtk_tree_view_get_model(GTK_TREE_VIEW(sd->result_view)); | |
836 valid = gtk_tree_model_get_iter_first(store, &iter); | |
837 while (valid) | |
838 { | |
839 gtk_list_store_set(GTK_LIST_STORE(store), &iter, SEARCH_COLUMN_THUMB, NULL, -1); | |
840 valid = gtk_tree_model_iter_next(store, &iter); | |
841 } | |
842 search_progress_update(sd, TRUE, -1.0); | |
843 } | |
844 | |
845 sd->thumb_enable = enable; | |
846 | |
847 search_result_thumb_height(sd); | |
848 if (!sd->search_folder_list && !sd->search_file_list) search_result_thumb_step(sd); | |
849 } | |
850 | |
851 /* | |
852 *------------------------------------------------------------------- | |
853 * result list menu | |
854 *------------------------------------------------------------------- | |
855 */ | |
856 | |
857 static void sr_menu_view_cb(GtkWidget *widget, gpointer data) | |
858 { | |
859 SearchData *sd = data; | |
860 | |
138 | 861 if (sd->click_fd) layout_image_set_fd(NULL, sd->click_fd); |
9 | 862 } |
863 | |
864 static void sr_menu_viewnew_cb(GtkWidget *widget, gpointer data) | |
865 { | |
866 SearchData *sd = data; | |
867 GList *list; | |
868 | |
869 list = search_result_selection_list(sd); | |
870 view_window_new_from_list(list); | |
138 | 871 filelist_free(list); |
9 | 872 } |
873 | |
874 static void sr_menu_select_all_cb(GtkWidget *widget, gpointer data) | |
875 { | |
876 SearchData *sd = data; | |
877 GtkTreeSelection *selection; | |
878 | |
879 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(sd->result_view)); | |
880 gtk_tree_selection_select_all(selection); | |
881 } | |
882 | |
883 static void sr_menu_select_none_cb(GtkWidget *widget, gpointer data) | |
884 { | |
885 SearchData *sd = data; | |
886 GtkTreeSelection *selection; | |
887 | |
888 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(sd->result_view)); | |
889 gtk_tree_selection_unselect_all(selection); | |
890 } | |
891 | |
892 static void sr_menu_edit_cb(GtkWidget *widget, gpointer data) | |
893 { | |
894 SearchData *sd; | |
895 gint n; | |
896 | |
897 sd = submenu_item_get_data(widget); | |
898 n = GPOINTER_TO_INT(data); | |
899 if (!sd) return; | |
900 | |
901 search_result_edit_selected(sd, n); | |
902 } | |
903 | |
904 static void sr_menu_info_cb(GtkWidget *widget, gpointer data) | |
905 { | |
906 SearchData *sd = data; | |
907 | |
479
5212d4fed37f
Ensure Properties dialog is displayed above fullscreen window.
zas_
parents:
475
diff
changeset
|
908 info_window_new(NULL, search_result_selection_list(sd), NULL); |
9 | 909 } |
910 | |
911 static void sr_menu_collection_cb(GtkWidget *widget, gpointer data) | |
912 { | |
913 SearchData *sd = data; | |
914 | |
915 search_result_collection_from_selection(sd); | |
916 } | |
917 | |
918 static void sr_menu_print_cb(GtkWidget *widget, gpointer data) | |
919 { | |
920 SearchData *sd = data; | |
442 | 921 |
138 | 922 print_window_new(sd->click_fd, search_result_selection_list(sd), |
923 search_result_get_filelist(sd), sd->window); | |
9 | 924 } |
925 | |
926 static void sr_menu_copy_cb(GtkWidget *widget, gpointer data) | |
927 { | |
928 SearchData *sd = data; | |
929 | |
930 file_util_copy(NULL, search_result_selection_list(sd), NULL, sd->window); | |
931 } | |
932 | |
933 static void sr_menu_move_cb(GtkWidget *widget, gpointer data) | |
934 { | |
935 SearchData *sd = data; | |
936 | |
937 file_util_move(NULL, search_result_selection_list(sd), NULL, sd->window); | |
938 } | |
939 | |
940 static void sr_menu_rename_cb(GtkWidget *widget, gpointer data) | |
941 { | |
942 SearchData *sd = data; | |
943 | |
944 file_util_rename(NULL, search_result_selection_list(sd), sd->window); | |
945 } | |
946 | |
947 static void sr_menu_delete_cb(GtkWidget *widget, gpointer data) | |
948 { | |
949 SearchData *sd = data; | |
950 | |
951 file_util_delete(NULL, search_result_selection_list(sd), sd->window); | |
952 } | |
953 | |
497 | 954 static void sr_menu_copy_path_cb(GtkWidget *widget, gpointer data) |
955 { | |
956 SearchData *sd = data; | |
957 | |
958 file_util_copy_path_list_to_clipboard(search_result_selection_list(sd)); | |
959 } | |
960 | |
9 | 961 static void sr_menu_remove_cb(GtkWidget *widget, gpointer data) |
962 { | |
963 SearchData *sd = data; | |
964 | |
965 search_result_remove_selection(sd); | |
966 } | |
967 | |
968 static void sr_menu_clear_cb(GtkWidget *widget, gpointer data) | |
969 { | |
970 SearchData *sd = data; | |
971 | |
972 search_result_clear(sd); | |
973 } | |
974 | |
975 static GtkWidget *search_result_menu(SearchData *sd, gint on_row, gint empty) | |
976 { | |
977 GtkWidget *menu; | |
978 GtkWidget *item; | |
979 | |
980 menu = popup_menu_short_lived(); | |
981 menu_item_add_sensitive(menu, _("_View"), on_row, | |
982 G_CALLBACK(sr_menu_view_cb), sd); | |
983 menu_item_add_stock_sensitive(menu, _("View in _new window"), GTK_STOCK_NEW, on_row, | |
984 G_CALLBACK(sr_menu_viewnew_cb), sd); | |
985 menu_item_add_divider(menu); | |
986 menu_item_add_sensitive(menu, _("Select all"), !empty, | |
987 G_CALLBACK(sr_menu_select_all_cb), sd); | |
988 menu_item_add_sensitive(menu, _("Select none"), !empty, | |
989 G_CALLBACK(sr_menu_select_none_cb), sd); | |
990 menu_item_add_divider(menu); | |
991 submenu_add_edit(menu, &item, G_CALLBACK(sr_menu_edit_cb), sd); | |
992 if (!on_row) gtk_widget_set_sensitive(item, FALSE); | |
993 menu_item_add_stock_sensitive(menu, _("_Properties"), GTK_STOCK_PROPERTIES, on_row, | |
994 G_CALLBACK(sr_menu_info_cb), sd); | |
995 menu_item_add_stock_sensitive(menu, _("Add to new collection"), GTK_STOCK_INDEX, on_row, | |
996 G_CALLBACK(sr_menu_collection_cb), sd); | |
997 menu_item_add_stock_sensitive(menu, _("Print..."), GTK_STOCK_PRINT, on_row, | |
998 G_CALLBACK(sr_menu_print_cb), sd); | |
999 menu_item_add_divider(menu); | |
1000 menu_item_add_stock_sensitive(menu, _("_Copy..."), GTK_STOCK_COPY, on_row, | |
1001 G_CALLBACK(sr_menu_copy_cb), sd); | |
1002 menu_item_add_sensitive(menu, _("_Move..."), on_row, | |
1003 G_CALLBACK(sr_menu_move_cb), sd); | |
1004 menu_item_add_sensitive(menu, _("_Rename..."), on_row, | |
1005 G_CALLBACK(sr_menu_rename_cb), sd); | |
1006 menu_item_add_stock_sensitive(menu, _("_Delete..."), GTK_STOCK_DELETE, on_row, | |
1007 G_CALLBACK(sr_menu_delete_cb), sd); | |
497 | 1008 if (options->show_copy_path) |
1009 menu_item_add_sensitive(menu, _("_Copy path"), on_row, | |
1010 G_CALLBACK(sr_menu_copy_path_cb), sd); | |
9 | 1011 menu_item_add_divider(menu); |
1012 menu_item_add_stock_sensitive(menu, _("Rem_ove"), GTK_STOCK_REMOVE, on_row, | |
1013 G_CALLBACK(sr_menu_remove_cb), sd); | |
1014 menu_item_add_stock_sensitive(menu, _("C_lear"), GTK_STOCK_CLEAR, !empty, | |
1015 G_CALLBACK(sr_menu_clear_cb), sd); | |
1016 | |
1017 return menu; | |
1018 } | |
1019 | |
1020 static void search_result_menu_pos_cb(GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer data) | |
1021 { | |
1022 SearchData *sd = data; | |
1023 GtkTreePath *tpath; | |
1024 gint cx, cy, cw, ch; | |
1025 | |
1026 gtk_tree_view_get_cursor(GTK_TREE_VIEW(sd->result_view), &tpath, NULL); | |
1027 if (!tpath) return; | |
1028 | |
1029 tree_view_get_cell_clamped(GTK_TREE_VIEW(sd->result_view), tpath, | |
1030 SEARCH_COLUMN_NAME - 1, TRUE, &cx, &cy, &cw, &ch); | |
1031 gtk_tree_path_free(tpath); | |
1032 cy += ch; | |
1033 popup_menu_position_clamp(menu, &cx, &cy, 0); | |
1034 *x = cx; | |
1035 *y = cy; | |
1036 } | |
1037 | |
1038 /* | |
1039 *------------------------------------------------------------------- | |
1040 * result list input | |
1041 *------------------------------------------------------------------- | |
1042 */ | |
1043 | |
1044 static gint search_result_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data) | |
1045 { | |
1046 SearchData *sd = data; | |
1047 GtkTreeModel *store; | |
1048 GtkTreePath *tpath; | |
1049 GtkTreeIter iter; | |
138 | 1050 MatchFileData *mfd = NULL; |
9 | 1051 |
1052 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | |
1053 | |
1054 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bevent->x, bevent->y, | |
1055 &tpath, NULL, NULL, NULL)) | |
1056 { | |
1057 gtk_tree_model_get_iter(store, &iter, tpath); | |
138 | 1058 gtk_tree_model_get(store, &iter, SEARCH_COLUMN_POINTER, &mfd, -1); |
9 | 1059 gtk_tree_path_free(tpath); |
1060 } | |
1061 | |
138 | 1062 sd->click_fd = mfd ? mfd->fd : NULL; |
9 | 1063 |
448
a73cc0fa14d0
Use explicit names for mouse buttons instead of numbers.
zas_
parents:
446
diff
changeset
|
1064 if (bevent->button == MOUSE_BUTTON_RIGHT) |
9 | 1065 { |
1066 GtkWidget *menu; | |
1067 | |
138 | 1068 menu = search_result_menu(sd, (mfd != NULL), (search_result_count(sd, NULL) == 0)); |
9 | 1069 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, bevent->button, bevent->time); |
1070 } | |
1071 | |
138 | 1072 if (!mfd) return FALSE; |
9 | 1073 |
448
a73cc0fa14d0
Use explicit names for mouse buttons instead of numbers.
zas_
parents:
446
diff
changeset
|
1074 if (bevent->button == MOUSE_BUTTON_LEFT && bevent->type == GDK_2BUTTON_PRESS) |
9 | 1075 { |
138 | 1076 layout_image_set_fd(NULL, mfd->fd); |
9 | 1077 } |
1078 | |
448
a73cc0fa14d0
Use explicit names for mouse buttons instead of numbers.
zas_
parents:
446
diff
changeset
|
1079 if (bevent->button == MOUSE_BUTTON_MIDDLE) return TRUE; |
a73cc0fa14d0
Use explicit names for mouse buttons instead of numbers.
zas_
parents:
446
diff
changeset
|
1080 |
a73cc0fa14d0
Use explicit names for mouse buttons instead of numbers.
zas_
parents:
446
diff
changeset
|
1081 if (bevent->button == MOUSE_BUTTON_RIGHT) |
9 | 1082 { |
138 | 1083 if (!search_result_row_selected(sd, mfd->fd)) |
9 | 1084 { |
1085 GtkTreeSelection *selection; | |
1086 | |
1087 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget)); | |
1088 gtk_tree_selection_unselect_all(selection); | |
1089 gtk_tree_selection_select_iter(selection, &iter); | |
1090 | |
1091 tpath = gtk_tree_model_get_path(store, &iter); | |
1092 gtk_tree_view_set_cursor(GTK_TREE_VIEW(widget), tpath, NULL, FALSE); | |
1093 gtk_tree_path_free(tpath); | |
1094 } | |
1095 return TRUE; | |
1096 } | |
1097 | |
448
a73cc0fa14d0
Use explicit names for mouse buttons instead of numbers.
zas_
parents:
446
diff
changeset
|
1098 if (bevent->button == MOUSE_BUTTON_LEFT && bevent->type == GDK_BUTTON_PRESS && |
9 | 1099 !(bevent->state & GDK_SHIFT_MASK ) && |
1100 !(bevent->state & GDK_CONTROL_MASK ) && | |
138 | 1101 search_result_row_selected(sd, mfd->fd)) |
9 | 1102 { |
1103 /* this selection handled on release_cb */ | |
1104 gtk_widget_grab_focus(widget); | |
1105 return TRUE; | |
1106 } | |
1107 | |
1108 return FALSE; | |
1109 } | |
1110 | |
1111 static gint search_result_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data) | |
1112 { | |
1113 SearchData *sd = data; | |
1114 GtkTreeModel *store; | |
1115 GtkTreePath *tpath; | |
1116 GtkTreeIter iter; | |
1117 | |
138 | 1118 MatchFileData *mfd = NULL; |
9 | 1119 |
448
a73cc0fa14d0
Use explicit names for mouse buttons instead of numbers.
zas_
parents:
446
diff
changeset
|
1120 if (bevent->button != MOUSE_BUTTON_LEFT && bevent->button != MOUSE_BUTTON_MIDDLE) return TRUE; |
9 | 1121 |
1122 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | |
1123 | |
1124 if ((bevent->x != 0 || bevent->y != 0) && | |
1125 gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bevent->x, bevent->y, | |
1126 &tpath, NULL, NULL, NULL)) | |
1127 { | |
1128 gtk_tree_model_get_iter(store, &iter, tpath); | |
138 | 1129 gtk_tree_model_get(store, &iter, SEARCH_COLUMN_POINTER, &mfd, -1); |
9 | 1130 gtk_tree_path_free(tpath); |
1131 } | |
1132 | |
448
a73cc0fa14d0
Use explicit names for mouse buttons instead of numbers.
zas_
parents:
446
diff
changeset
|
1133 if (bevent->button == MOUSE_BUTTON_MIDDLE) |
9 | 1134 { |
138 | 1135 if (mfd && sd->click_fd == mfd->fd) |
9 | 1136 { |
1137 GtkTreeSelection *selection; | |
1138 | |
1139 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget)); | |
138 | 1140 if (search_result_row_selected(sd, mfd->fd)) |
9 | 1141 { |
1142 gtk_tree_selection_unselect_iter(selection, &iter); | |
1143 } | |
1144 else | |
1145 { | |
1146 gtk_tree_selection_select_iter(selection, &iter); | |
1147 } | |
1148 } | |
1149 return TRUE; | |
1150 } | |
1151 | |
138 | 1152 if (mfd && sd->click_fd == mfd->fd && |
9 | 1153 !(bevent->state & GDK_SHIFT_MASK ) && |
1154 !(bevent->state & GDK_CONTROL_MASK ) && | |
138 | 1155 search_result_row_selected(sd, mfd->fd)) |
9 | 1156 { |
1157 GtkTreeSelection *selection; | |
1158 | |
1159 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget)); | |
1160 gtk_tree_selection_unselect_all(selection); | |
1161 gtk_tree_selection_select_iter(selection, &iter); | |
1162 | |
1163 tpath = gtk_tree_model_get_path(store, &iter); | |
1164 gtk_tree_view_set_cursor(GTK_TREE_VIEW(widget), tpath, NULL, FALSE); | |
1165 gtk_tree_path_free(tpath); | |
1166 | |
1167 return TRUE; | |
1168 } | |
1169 | |
1170 return FALSE; | |
1171 } | |
1172 | |
1173 static gint search_result_keypress_cb(GtkWidget *widget, GdkEventKey *event, gpointer data) | |
1174 { | |
1175 SearchData *sd = data; | |
1176 gint stop_signal = FALSE; | |
1177 GtkTreeModel *store; | |
1178 GtkTreeSelection *selection; | |
1179 GList *slist; | |
138 | 1180 MatchFileData *mfd = NULL; |
9 | 1181 |
1182 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(sd->result_view)); | |
1183 slist = gtk_tree_selection_get_selected_rows(selection, &store); | |
1184 if (slist) | |
1185 { | |
1186 GtkTreePath *tpath; | |
1187 GtkTreeIter iter; | |
1188 GList *last; | |
1189 | |
1190 last = g_list_last(slist); | |
1191 tpath = last->data; | |
1192 | |
1193 /* last is newest selected file */ | |
1194 gtk_tree_model_get_iter(store, &iter, tpath); | |
138 | 1195 gtk_tree_model_get(store, &iter, SEARCH_COLUMN_POINTER, &mfd, -1); |
9 | 1196 } |
1197 g_list_foreach(slist, (GFunc)gtk_tree_path_free, NULL); | |
1198 g_list_free(slist); | |
1199 | |
1200 if (event->state & GDK_CONTROL_MASK) | |
1201 { | |
1202 gint edit_val = -1; | |
1203 | |
85
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
1204 stop_signal = TRUE; |
9 | 1205 switch (event->keyval) |
1206 { | |
1207 case '1': | |
1208 edit_val = 0; | |
1209 break; | |
1210 case '2': | |
1211 edit_val = 1; | |
1212 break; | |
1213 case '3': | |
1214 edit_val = 2; | |
1215 break; | |
1216 case '4': | |
1217 edit_val = 3; | |
1218 break; | |
1219 case '5': | |
1220 edit_val = 4; | |
1221 break; | |
1222 case '6': | |
1223 edit_val = 5; | |
1224 break; | |
1225 case '7': | |
1226 edit_val = 6; | |
1227 break; | |
1228 case '8': | |
1229 edit_val = 7; | |
1230 break; | |
1231 case '9': | |
1232 edit_val = 8; | |
1233 break; | |
1234 case '0': | |
1235 edit_val = 9; | |
1236 break; | |
1237 case 'C': case 'c': | |
1238 file_util_copy(NULL, search_result_selection_list(sd), NULL, widget); | |
1239 break; | |
1240 case 'M': case 'm': | |
1241 file_util_move(NULL, search_result_selection_list(sd), NULL, widget); | |
1242 break; | |
1243 case 'R': case 'r': | |
1244 file_util_rename(NULL, search_result_selection_list(sd), widget); | |
1245 break; | |
1246 case 'D': case 'd': | |
1247 file_util_delete(NULL, search_result_selection_list(sd), widget); | |
1248 break; | |
1249 case 'P': case 'p': | |
479
5212d4fed37f
Ensure Properties dialog is displayed above fullscreen window.
zas_
parents:
475
diff
changeset
|
1250 info_window_new(NULL, search_result_selection_list(sd), NULL); |
9 | 1251 break; |
1252 case 'A': case 'a': | |
1253 if (event->state & GDK_SHIFT_MASK) | |
1254 { | |
1255 gtk_tree_selection_unselect_all(selection); | |
1256 } | |
1257 else | |
1258 { | |
1259 gtk_tree_selection_select_all(selection); | |
1260 } | |
1261 break; | |
1262 case GDK_Delete: case GDK_KP_Delete: | |
1263 search_result_clear(sd); | |
1264 break; | |
1265 default: | |
85
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
1266 stop_signal = FALSE; |
9 | 1267 break; |
1268 } | |
1269 | |
1270 if (edit_val >= 0) | |
1271 { | |
1272 search_result_edit_selected(sd, edit_val); | |
1273 } | |
1274 } | |
1275 else | |
1276 { | |
85
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
1277 stop_signal = TRUE; |
9 | 1278 switch (event->keyval) |
1279 { | |
1280 case GDK_Return: case GDK_KP_Enter: | |
138 | 1281 if (mfd) layout_image_set_fd(NULL, mfd->fd); |
9 | 1282 break; |
1283 case 'V': case 'v': | |
1284 { | |
1285 GList *list; | |
1286 | |
1287 list = search_result_selection_list(sd); | |
1288 view_window_new_from_list(list); | |
138 | 1289 filelist_free(list); |
9 | 1290 } |
1291 break; | |
1292 case GDK_Delete: case GDK_KP_Delete: | |
1293 search_result_remove_selection(sd); | |
1294 break; | |
1295 case 'C': case 'c': | |
1296 search_result_collection_from_selection(sd); | |
1297 break; | |
1298 case GDK_Menu: | |
1299 case GDK_F10: | |
1300 { | |
1301 GtkWidget *menu; | |
1302 | |
138 | 1303 sd->click_fd = mfd->fd; |
1304 menu = search_result_menu(sd, (mfd != NULL), (search_result_count(sd, NULL) > 0)); | |
9 | 1305 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, |
1306 search_result_menu_pos_cb, sd, 0, GDK_CURRENT_TIME); | |
1307 } | |
1308 break; | |
1309 default: | |
85
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
1310 stop_signal = FALSE; |
9 | 1311 break; |
1312 } | |
1313 } | |
442 | 1314 |
9 | 1315 return stop_signal; |
1316 } | |
1317 | |
1318 static gint search_window_keypress_cb(GtkWidget *widget, GdkEventKey *event, gpointer data) | |
1319 { | |
1320 SearchData *sd = data; | |
1321 gint stop_signal = FALSE; | |
1322 | |
1323 if (event->state & GDK_CONTROL_MASK) | |
1324 { | |
85
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
1325 stop_signal = TRUE; |
9 | 1326 switch (event->keyval) |
1327 { | |
1328 case 'T': case 't': | |
1329 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(sd->button_thumbs), | |
1330 !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(sd->button_thumbs))); | |
1331 break; | |
1332 case 'W': case 'w': | |
1333 search_window_close(sd); | |
1334 break; | |
1335 default: | |
85
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
1336 stop_signal = FALSE; |
9 | 1337 break; |
1338 } | |
1339 } | |
1340 | |
1341 return stop_signal; | |
1342 } | |
1343 | |
1344 /* | |
1345 *------------------------------------------------------------------- | |
1346 * dnd | |
1347 *------------------------------------------------------------------- | |
1348 */ | |
1349 | |
1350 static GtkTargetEntry result_drag_types[] = { | |
1351 { "text/uri-list", 0, TARGET_URI_LIST }, | |
1352 { "text/plain", 0, TARGET_TEXT_PLAIN } | |
1353 }; | |
1354 static gint n_result_drag_types = 2; | |
1355 | |
1356 static void search_dnd_data_set(GtkWidget *widget, GdkDragContext *context, | |
1357 GtkSelectionData *selection_data, guint info, | |
1358 guint time, gpointer data) | |
1359 { | |
1360 SearchData *sd = data; | |
1361 gchar *uri_text; | |
1362 gint length; | |
1363 GList *list; | |
1364 | |
1365 switch (info) | |
1366 { | |
1367 case TARGET_URI_LIST: | |
1368 case TARGET_TEXT_PLAIN: | |
1369 list = search_result_selection_list(sd); | |
1370 if (!list) return; | |
138 | 1371 uri_text = uri_text_from_filelist(list, &length, (info == TARGET_TEXT_PLAIN)); |
1372 filelist_free(list); | |
9 | 1373 break; |
1374 default: | |
1375 uri_text = NULL; | |
1376 break; | |
1377 } | |
1378 | |
1379 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
|
1380 8, (guchar *)uri_text, length); |
9 | 1381 g_free(uri_text); |
1382 } | |
1383 | |
1384 static void search_dnd_begin(GtkWidget *widget, GdkDragContext *context, gpointer data) | |
1385 { | |
1386 SearchData *sd = data; | |
1387 | |
1388 if (sd->click_fd && !search_result_row_selected(sd, sd->click_fd)) | |
1389 { | |
1390 GtkListStore *store; | |
1391 GtkTreeIter iter; | |
1392 | |
1393 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(widget))); | |
1394 if (search_result_find_row(sd, sd->click_fd, &iter) >= 0) | |
1395 { | |
1396 GtkTreeSelection *selection; | |
1397 GtkTreePath *tpath; | |
1398 | |
1399 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget)); | |
1400 gtk_tree_selection_unselect_all(selection); | |
1401 gtk_tree_selection_select_iter(selection, &iter); | |
1402 | |
1403 tpath = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter); | |
1404 gtk_tree_view_set_cursor(GTK_TREE_VIEW(widget), tpath, NULL, FALSE); | |
1405 gtk_tree_path_free(tpath); | |
1406 } | |
1407 } | |
1408 | |
1409 if (sd->thumb_enable && | |
845 | 1410 sd->click_fd && sd->click_fd->thumb_pixbuf) |
9 | 1411 { |
845 | 1412 dnd_set_drag_icon(widget, context, sd->click_fd->thumb_pixbuf, search_result_selection_count(sd, NULL)); |
9 | 1413 } |
1414 } | |
1415 | |
1416 static void search_dnd_init(SearchData *sd) | |
1417 { | |
1418 gtk_drag_source_set(sd->result_view, GDK_BUTTON1_MASK | GDK_BUTTON2_MASK, | |
1419 result_drag_types, n_result_drag_types, | |
1420 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK); | |
1421 g_signal_connect(G_OBJECT(sd->result_view), "drag_data_get", | |
1422 G_CALLBACK(search_dnd_data_set), sd); | |
1423 g_signal_connect(G_OBJECT(sd->result_view), "drag_begin", | |
1424 G_CALLBACK(search_dnd_begin), sd); | |
1425 #if 0 | |
1426 g_signal_connect(G_OBJECT(sd->result_view), "drag_end", | |
1427 G_CALLBACK(search_dnd_end), sd); | |
1428 #endif | |
442 | 1429 |
9 | 1430 } |
1431 | |
1432 /* | |
1433 *------------------------------------------------------------------- | |
1434 * search core | |
1435 *------------------------------------------------------------------- | |
1436 */ | |
1437 | |
1438 #define MATCH_IS_BETWEEN(val, a, b) (b > a ? (val >= a && val <= b) : (val >= b && val <= a)) | |
1439 | |
1440 static gint search_step_cb(gpointer data); | |
1441 | |
1442 | |
1443 static void search_buffer_flush(SearchData *sd) | |
1444 { | |
1445 GList *work; | |
1446 | |
1447 work = g_list_last(sd->search_buffer_list); | |
1448 while (work) | |
1449 { | |
1450 MatchFileData *mfd = work->data; | |
1451 work = work->prev; | |
1452 | |
1453 search_result_append(sd, mfd); | |
1454 } | |
1455 | |
1456 g_list_free(sd->search_buffer_list); | |
1457 sd->search_buffer_list = NULL; | |
1458 sd->search_buffer_count = 0; | |
1459 } | |
1460 | |
1461 static void search_stop(SearchData *sd) | |
1462 { | |
1463 if (sd->search_idle_id != -1) | |
1464 { | |
1465 g_source_remove(sd->search_idle_id); | |
1466 sd->search_idle_id = -1; | |
1467 } | |
1468 | |
1469 image_loader_free(sd->img_loader); | |
1470 sd->img_loader = NULL; | |
1471 cache_sim_data_free(sd->img_cd); | |
1472 sd->img_cd = NULL; | |
1473 | |
1474 cache_sim_data_free(sd->search_similarity_cd); | |
1475 sd->search_similarity_cd = NULL; | |
1476 | |
1477 search_buffer_flush(sd); | |
1478 | |
1479 filelist_free(sd->search_folder_list); | |
1480 sd->search_folder_list = NULL; | |
1481 | |
1482 g_list_free(sd->search_done_list); | |
1483 sd->search_done_list = NULL; | |
1484 | |
1485 filelist_free(sd->search_file_list); | |
1486 sd->search_file_list = NULL; | |
1487 | |
1488 gtk_widget_set_sensitive(sd->box_search, TRUE); | |
1489 spinner_set_interval(sd->spinner, -1); | |
1490 gtk_widget_set_sensitive(sd->button_start, TRUE); | |
1491 gtk_widget_set_sensitive(sd->button_stop, FALSE); | |
1492 search_progress_update(sd, TRUE, -1.0); | |
1493 search_status_update(sd); | |
1494 } | |
1495 | |
1496 static void search_file_load_process(SearchData *sd, CacheData *cd) | |
1497 { | |
1498 GdkPixbuf *pixbuf; | |
1499 | |
1500 pixbuf = image_loader_get_pixbuf(sd->img_loader); | |
1501 | |
1502 if (cd && pixbuf) | |
1503 { | |
1504 if (!cd->dimensions) | |
1505 { | |
1506 cache_sim_data_set_dimensions(cd, gdk_pixbuf_get_width(pixbuf), | |
1507 gdk_pixbuf_get_height(pixbuf)); | |
1508 } | |
1509 | |
1510 if (sd->match_similarity_enable && !cd->similarity) | |
1511 { | |
1512 ImageSimilarityData *sim; | |
1513 | |
1514 sim = image_sim_new_from_pixbuf(pixbuf); | |
1515 cache_sim_data_set_similarity(cd, sim); | |
1516 image_sim_free(sim); | |
1517 } | |
1518 | |
333 | 1519 if (options->thumbnails.enable_caching && |
138 | 1520 sd->img_loader && sd->img_loader->fd) |
9 | 1521 { |
1522 gchar *base; | |
1523 const gchar *path; | |
1524 mode_t mode = 0755; | |
1525 | |
138 | 1526 path = sd->img_loader->fd->path; |
9 | 1527 base = cache_get_location(CACHE_TYPE_SIM, path, FALSE, &mode); |
1528 if (cache_ensure_dir_exists(base, mode)) | |
1529 { | |
1530 g_free(cd->path); | |
1531 cd->path = cache_get_location(CACHE_TYPE_SIM, path, TRUE, NULL); | |
1532 if (cache_sim_data_save(cd)) | |
1533 { | |
138 | 1534 filetime_set(cd->path, filetime(sd->img_loader->fd->path)); |
9 | 1535 } |
1536 } | |
1537 g_free(base); | |
1538 } | |
1539 } | |
1540 | |
1541 image_loader_free(sd->img_loader); | |
1542 sd->img_loader = NULL; | |
1543 | |
1544 sd->search_idle_id = g_idle_add(search_step_cb, sd); | |
1545 } | |
1546 | |
1547 static void search_file_load_done_cb(ImageLoader *il, gpointer data) | |
1548 { | |
442 | 1549 SearchData *sd = data; |
9 | 1550 search_file_load_process(sd, sd->img_cd); |
1551 } | |
1552 | |
1553 static gint search_file_do_extra(SearchData *sd, FileData *fd, gint *match, | |
1554 gint *width, gint *height, gint *simval) | |
1555 { | |
1556 gint new_data = FALSE; | |
1557 gint tmatch = TRUE; | |
1558 gint tested = FALSE; | |
1559 | |
1560 if (!sd->img_cd) | |
1561 { | |
1562 gchar *cd_path; | |
1563 | |
1564 new_data = TRUE; | |
1565 | |
1566 cd_path = cache_find_location(CACHE_TYPE_SIM, fd->path); | |
1567 if (cd_path && filetime(fd->path) == filetime(cd_path)) | |
1568 { | |
1569 sd->img_cd = cache_sim_data_load(cd_path); | |
1570 } | |
1571 g_free(cd_path); | |
1572 } | |
1573 | |
1574 if (!sd->img_cd) | |
1575 { | |
1576 sd->img_cd = cache_sim_data_new(); | |
1577 } | |
1578 | |
1579 if (new_data) | |
1580 { | |
1581 if ((sd->match_dimensions_enable && !sd->img_cd->dimensions) || | |
1582 (sd->match_similarity_enable && !sd->img_cd->similarity)) | |
1583 { | |
138 | 1584 sd->img_loader = image_loader_new(fd); |
9 | 1585 image_loader_set_error_func(sd->img_loader, search_file_load_done_cb, sd); |
1586 if (image_loader_start(sd->img_loader, search_file_load_done_cb, sd)) | |
1587 { | |
1588 return TRUE; | |
1589 } | |
1590 else | |
1591 { | |
1592 image_loader_free(sd->img_loader); | |
1593 sd->img_loader = NULL; | |
1594 } | |
1595 } | |
1596 } | |
1597 | |
1598 if (tmatch && sd->match_dimensions_enable && sd->img_cd->dimensions) | |
1599 { | |
1600 CacheData *cd = sd->img_cd; | |
1601 | |
1602 tmatch = FALSE; | |
1603 tested = TRUE; | |
1604 | |
1605 if (sd->match_dimensions == SEARCH_MATCH_EQUAL) | |
1606 { | |
1607 tmatch = (cd->width == sd->search_width && cd->height == sd->search_height); | |
1608 } | |
1609 else if (sd->match_dimensions == SEARCH_MATCH_UNDER) | |
1610 { | |
1611 tmatch = (cd->width < sd->search_width && cd->height < sd->search_height); | |
1612 } | |
1613 else if (sd->match_dimensions == SEARCH_MATCH_OVER) | |
1614 { | |
1615 tmatch = (cd->width > sd->search_width && cd->height > sd->search_height); | |
1616 } | |
1617 else if (sd->match_dimensions == SEARCH_MATCH_BETWEEN) | |
1618 { | |
1619 tmatch = (MATCH_IS_BETWEEN(cd->width, sd->search_width, sd->search_width_end) && | |
1620 MATCH_IS_BETWEEN(cd->height, sd->search_height, sd->search_height_end)); | |
1621 } | |
1622 } | |
1623 | |
1624 if (tmatch && sd->match_similarity_enable && sd->img_cd->similarity) | |
1625 { | |
1626 gdouble value = 0.0; | |
1627 | |
1628 tmatch = FALSE; | |
1629 tested = TRUE; | |
1630 | |
1631 /* fixme: implement similarity checking */ | |
1632 if (sd->search_similarity_cd && sd->search_similarity_cd->similarity) | |
1633 { | |
1634 gdouble result; | |
1635 | |
1636 result = image_sim_compare_fast(sd->search_similarity_cd->sim, sd->img_cd->sim, | |
1637 (gdouble)sd->search_similarity / 100.0); | |
1638 result *= 100.0; | |
1639 if (result >= (gdouble)sd->search_similarity) | |
1640 { | |
1641 tmatch = TRUE; | |
1642 value = (gint)result; | |
1643 } | |
1644 } | |
442 | 1645 |
9 | 1646 if (simval) *simval = value; |
1647 } | |
1648 | |
1649 if (sd->img_cd->dimensions) | |
1650 { | |
1651 if (width) *width = sd->img_cd->width; | |
1652 if (height) *height = sd->img_cd->height; | |
1653 } | |
1654 | |
1655 cache_sim_data_free(sd->img_cd); | |
1656 sd->img_cd = NULL; | |
1657 | |
1658 *match = (tmatch && tested); | |
1659 | |
1660 return FALSE; | |
1661 } | |
1662 | |
1663 static gint search_file_next(SearchData *sd) | |
1664 { | |
1665 FileData *fd; | |
1666 gint match = TRUE; | |
1667 gint tested = FALSE; | |
1668 gint extra_only = FALSE; | |
1669 gint width = 0; | |
1670 gint height = 0; | |
1671 gint sim = 0; | |
1672 | |
1673 if (!sd->search_file_list) return FALSE; | |
1674 | |
1675 if (sd->img_cd) | |
1676 { | |
1677 /* on end of a CacheData load, skip recomparing non-extra match types */ | |
1678 extra_only = TRUE; | |
1679 match = FALSE; | |
1680 } | |
1681 else | |
1682 { | |
1683 sd->search_total++; | |
1684 } | |
1685 | |
1686 fd = sd->search_file_list->data; | |
1687 | |
1688 if (match && sd->match_name_enable && sd->search_name) | |
1689 { | |
1690 tested = TRUE; | |
1691 match = FALSE; | |
1692 | |
1693 if (sd->match_name == SEARCH_MATCH_EQUAL) | |
1694 { | |
1695 if (sd->search_name_match_case) | |
1696 { | |
1697 match = (strcmp(fd->name, sd->search_name) == 0); | |
1698 } | |
1699 else | |
1700 { | |
1701 match = (strcasecmp(fd->name, sd->search_name) == 0); | |
1702 } | |
1703 } | |
1704 else if (sd->match_name == SEARCH_MATCH_CONTAINS) | |
1705 { | |
1706 if (sd->search_name_match_case) | |
1707 { | |
1708 match = (strstr(fd->name, sd->search_name) != NULL); | |
1709 } | |
1710 else | |
1711 { | |
1712 /* sd->search_name is converted in search_start() */ | |
1713 gchar *haystack = g_utf8_strdown(fd->name, -1); | |
1714 match = (strstr(haystack, sd->search_name) != NULL); | |
1715 g_free(haystack); | |
1716 } | |
1717 } | |
1718 } | |
1719 | |
1720 if (match && sd->match_size_enable) | |
1721 { | |
1722 tested = TRUE; | |
1723 match = FALSE; | |
1724 | |
1725 if (sd->match_size == SEARCH_MATCH_EQUAL) | |
1726 { | |
1727 match = (fd->size == sd->search_size); | |
1728 } | |
1729 else if (sd->match_size == SEARCH_MATCH_UNDER) | |
1730 { | |
1731 match = (fd->size < sd->search_size); | |
1732 } | |
1733 else if (sd->match_size == SEARCH_MATCH_OVER) | |
1734 { | |
1735 match = (fd->size > sd->search_size); | |
1736 } | |
1737 else if (sd->match_size == SEARCH_MATCH_BETWEEN) | |
1738 { | |
1739 match = MATCH_IS_BETWEEN(fd->size, sd->search_size, sd->search_size_end); | |
1740 } | |
1741 } | |
1742 | |
1743 if (match && sd->match_date_enable) | |
1744 { | |
1745 tested = TRUE; | |
1746 match = FALSE; | |
1747 | |
1748 if (sd->match_date == SEARCH_MATCH_EQUAL) | |
1749 { | |
1750 struct tm *lt; | |
1751 | |
1752 lt = localtime(&fd->date); | |
1753 match = (lt && | |
1754 lt->tm_year == sd->search_date_y - 1900 && | |
1755 lt->tm_mon == sd->search_date_m - 1 && | |
1756 lt->tm_mday == sd->search_date_d); | |
1757 } | |
1758 else if (sd->match_date == SEARCH_MATCH_UNDER) | |
1759 { | |
1760 match = (fd->date < convert_dmy_to_time(sd->search_date_d, sd->search_date_m, sd->search_date_y)); | |
1761 } | |
1762 else if (sd->match_date == SEARCH_MATCH_OVER) | |
1763 { | |
1764 match = (fd->date > convert_dmy_to_time(sd->search_date_d, sd->search_date_m, sd->search_date_y) + 60 * 60 * 24 - 1); | |
1765 } | |
1766 else if (sd->match_date == SEARCH_MATCH_BETWEEN) | |
1767 { | |
1768 time_t a = convert_dmy_to_time(sd->search_date_d, sd->search_date_m, sd->search_date_y); | |
1769 time_t b = convert_dmy_to_time(sd->search_date_end_d, sd->search_date_end_m, sd->search_date_end_y); | |
1770 | |
1771 if (b >= a) | |
1772 { | |
1773 b += 60 * 60 * 24 - 1; | |
1774 } | |
1775 else | |
1776 { | |
1777 a += 60 * 60 * 24 - 1; | |
1778 } | |
1779 match = MATCH_IS_BETWEEN(fd->date, a, b); | |
1780 } | |
1781 } | |
1782 | |
1783 if (match && sd->match_keywords_enable && sd->search_keyword_list) | |
1784 { | |
1785 GList *list; | |
1786 | |
1787 tested = TRUE; | |
1788 match = FALSE; | |
1789 | |
188
0584cb78aa14
write comment and keywords to xmp, sidecars are used if exist
nadvornik
parents:
138
diff
changeset
|
1790 if (comment_read(fd, &list, NULL)) |
9 | 1791 { |
1792 GList *needle; | |
1793 GList *haystack; | |
1794 | |
1795 if (sd->match_keywords == SEARCH_MATCH_ALL) | |
1796 { | |
1797 gint found = TRUE; | |
1798 | |
1799 needle = sd->search_keyword_list; | |
1800 while (needle && found) | |
1801 { | |
1802 found = FALSE; | |
1803 haystack = list; | |
1804 while (haystack && !found) | |
1805 { | |
1806 found = (strcasecmp((gchar *)needle->data, | |
1807 (gchar *)haystack->data) == 0); | |
1808 haystack = haystack->next; | |
1809 } | |
1810 needle = needle->next; | |
1811 } | |
1812 | |
1813 match = found; | |
1814 } | |
1815 else if (sd->match_keywords == SEARCH_MATCH_ANY) | |
1816 { | |
1817 gint found = FALSE; | |
1818 | |
1819 needle = sd->search_keyword_list; | |
1820 while (needle && !found) | |
1821 { | |
1822 haystack = list; | |
1823 while (haystack && !found) | |
1824 { | |
1825 found = (strcasecmp((gchar *)needle->data, | |
1826 (gchar *)haystack->data) == 0); | |
1827 haystack = haystack->next; | |
1828 } | |
1829 needle = needle->next; | |
1830 } | |
1831 | |
1832 match = found; | |
1833 } | |
1834 else if (sd->match_keywords == SEARCH_MATCH_NONE) | |
1835 { | |
1836 gint found = FALSE; | |
1837 | |
1838 needle = sd->search_keyword_list; | |
1839 while (needle && !found) | |
1840 { | |
1841 haystack = list; | |
1842 while (haystack && !found) | |
1843 { | |
1844 found = (strcasecmp((gchar *)needle->data, | |
1845 (gchar *)haystack->data) == 0); | |
1846 haystack = haystack->next; | |
1847 } | |
1848 needle = needle->next; | |
1849 } | |
1850 | |
1851 match = !found; | |
1852 } | |
138 | 1853 string_list_free(list); |
9 | 1854 } |
1855 else | |
1856 { | |
1857 match = (sd->match_keywords == SEARCH_MATCH_NONE); | |
1858 } | |
1859 } | |
1860 | |
1861 if ((match || extra_only) && | |
1862 (sd->match_dimensions_enable || sd->match_similarity_enable)) | |
1863 { | |
1864 tested = TRUE; | |
1865 | |
1866 if (search_file_do_extra(sd, fd, &match, &width, &height, &sim)) | |
1867 { | |
1868 sd->search_buffer_count += SEARCH_BUFFER_MATCH_LOAD; | |
1869 return TRUE; | |
1870 } | |
1871 } | |
1872 | |
1873 sd->search_file_list = g_list_remove(sd->search_file_list, fd); | |
1874 | |
1875 if (tested && match) | |
1876 { | |
1877 MatchFileData *mfd; | |
1878 | |
1879 mfd = g_new(MatchFileData, 1); | |
138 | 1880 mfd->fd = fd; |
9 | 1881 |
1882 mfd->width = width; | |
1883 mfd->height = height; | |
1884 mfd->rank = sim; | |
1885 | |
1886 sd->search_buffer_list = g_list_prepend(sd->search_buffer_list, mfd); | |
1887 sd->search_buffer_count += SEARCH_BUFFER_MATCH_HIT; | |
1888 sd->search_count++; | |
1889 search_progress_update(sd, TRUE, -1.0); | |
1890 } | |
1891 else | |
1892 { | |
138 | 1893 file_data_unref(fd); |
9 | 1894 sd->search_buffer_count += SEARCH_BUFFER_MATCH_MISS; |
1895 } | |
1896 | |
1897 return FALSE; | |
1898 } | |
1899 | |
1900 static gint search_step_cb(gpointer data) | |
1901 { | |
1902 SearchData *sd = data; | |
1903 FileData *fd; | |
1904 | |
1905 if (sd->search_buffer_count > SEARCH_BUFFER_FLUSH_SIZE) | |
1906 { | |
1907 search_buffer_flush(sd); | |
1908 search_progress_update(sd, TRUE, -1.0); | |
1909 } | |
1910 | |
1911 if (sd->search_file_list) | |
1912 { | |
1913 if (search_file_next(sd)) | |
1914 { | |
1915 sd->search_idle_id = -1; | |
1916 return FALSE; | |
1917 } | |
1918 return TRUE; | |
1919 } | |
1920 | |
1921 if (!sd->search_file_list && !sd->search_folder_list) | |
1922 { | |
1923 sd->search_idle_id = -1; | |
1924 | |
1925 search_stop(sd); | |
1926 search_result_thumb_step(sd); | |
1927 | |
1928 return FALSE; | |
1929 } | |
1930 | |
1931 fd = sd->search_folder_list->data; | |
1932 | |
1933 if (g_list_find(sd->search_done_list, fd) == NULL) | |
1934 { | |
1935 GList *list = NULL; | |
1936 GList *dlist = NULL; | |
1937 gint success = FALSE; | |
1938 | |
1939 sd->search_done_list = g_list_prepend(sd->search_done_list, fd); | |
1940 | |
1941 if (sd->search_type == SEARCH_MATCH_NONE) | |
1942 { | |
783 | 1943 success = filelist_read(fd, &list, &dlist); |
9 | 1944 } |
1945 else if (sd->search_type == SEARCH_MATCH_ALL && | |
783 | 1946 sd->search_dir_fd && |
1947 strlen(fd->path) >= strlen(sd->search_dir_fd->path)) | |
9 | 1948 { |
1949 const gchar *path; | |
1950 | |
783 | 1951 path = fd->path + strlen(sd->search_dir_fd->path); |
1952 if (path != fd->path) | |
1953 { | |
1954 FileData *dir_fd = file_data_new_simple(path); | |
1955 success = filelist_read(dir_fd, &list, NULL); | |
1956 file_data_unref(dir_fd); | |
1957 } | |
1958 success |= filelist_read(fd, NULL, &dlist); | |
9 | 1959 if (success) |
1960 { | |
1961 GList *work; | |
1962 | |
1963 work = list; | |
1964 while (work) | |
1965 { | |
1966 FileData *fdp; | |
1967 GList *link; | |
1968 gchar *meta_path; | |
1969 | |
1970 fdp = work->data; | |
1971 link = work; | |
1972 work = work->next; | |
1973 | |
1974 meta_path = cache_find_location(CACHE_TYPE_METADATA, fdp->path); | |
1975 if (!meta_path) | |
1976 { | |
1977 list = g_list_delete_link(list, link); | |
138 | 1978 file_data_unref(fdp); |
9 | 1979 } |
1980 g_free(meta_path); | |
1981 } | |
1982 } | |
1983 } | |
1984 | |
1985 if (success) | |
1986 { | |
1987 list = filelist_sort(list, SORT_NAME, TRUE); | |
1988 sd->search_file_list = list; | |
1989 | |
1990 if (sd->search_path_recurse) | |
1991 { | |
1992 dlist = filelist_sort(dlist, SORT_NAME, TRUE); | |
1993 sd->search_folder_list = g_list_concat(dlist, sd->search_folder_list); | |
1994 } | |
1995 else | |
1996 { | |
1997 filelist_free(dlist); | |
1998 } | |
1999 } | |
2000 } | |
2001 else | |
2002 { | |
2003 sd->search_folder_list = g_list_remove(sd->search_folder_list, fd); | |
2004 sd->search_done_list = g_list_remove(sd->search_done_list, fd); | |
138 | 2005 file_data_unref(fd); |
9 | 2006 } |
2007 | |
2008 return TRUE; | |
2009 } | |
2010 | |
2011 static void search_similarity_load_done_cb(ImageLoader *il, gpointer data) | |
2012 { | |
2013 SearchData *sd = data; | |
2014 search_file_load_process(sd, sd->search_similarity_cd); | |
2015 } | |
2016 | |
2017 static void search_start(SearchData *sd) | |
2018 { | |
2019 search_stop(sd); | |
2020 search_result_clear(sd); | |
2021 | |
783 | 2022 if (sd->search_dir_fd) |
9 | 2023 { |
783 | 2024 sd->search_folder_list = g_list_prepend(sd->search_folder_list, sd->search_dir_fd); |
9 | 2025 } |
2026 | |
2027 if (!sd->search_name_match_case) | |
2028 { | |
2029 /* convert to lowercase here, so that this is only done once per search */ | |
2030 gchar *tmp = g_utf8_strdown(sd->search_name, -1); | |
2031 g_free(sd->search_name); | |
2032 sd->search_name = tmp; | |
2033 } | |
2034 | |
2035 sd->search_count = 0; | |
2036 sd->search_total = 0; | |
2037 | |
2038 gtk_widget_set_sensitive(sd->box_search, FALSE); | |
2039 spinner_set_interval(sd->spinner, SPINNER_SPEED); | |
2040 gtk_widget_set_sensitive(sd->button_start, FALSE); | |
2041 gtk_widget_set_sensitive(sd->button_stop, TRUE); | |
2042 search_progress_update(sd, TRUE, -1.0); | |
2043 | |
2044 if (sd->match_similarity_enable && | |
2045 !sd->search_similarity_cd && | |
2046 isfile(sd->search_similarity_path)) | |
2047 { | |
2048 gchar *cd_path; | |
2049 | |
2050 cd_path = cache_find_location(CACHE_TYPE_SIM, sd->search_similarity_path); | |
2051 if (cd_path && filetime(sd->search_similarity_path) == filetime(cd_path)) | |
2052 { | |
2053 sd->search_similarity_cd = cache_sim_data_load(cd_path); | |
2054 } | |
2055 g_free(cd_path); | |
2056 | |
2057 if (!sd->search_similarity_cd || !sd->search_similarity_cd->similarity) | |
2058 { | |
2059 if (!sd->search_similarity_cd) | |
2060 { | |
2061 sd->search_similarity_cd = cache_sim_data_new(); | |
2062 } | |
2063 | |
138 | 2064 sd->img_loader = image_loader_new(file_data_new_simple(sd->search_similarity_path)); |
9 | 2065 image_loader_set_error_func(sd->img_loader, search_similarity_load_done_cb, sd); |
2066 if (image_loader_start(sd->img_loader, search_similarity_load_done_cb, sd)) | |
2067 { | |
2068 return; | |
2069 } | |
2070 image_loader_free(sd->img_loader); | |
2071 sd->img_loader = NULL; | |
2072 } | |
442 | 2073 |
9 | 2074 } |
2075 | |
2076 sd->search_idle_id = g_idle_add(search_step_cb, sd); | |
2077 } | |
2078 | |
2079 static void search_start_cb(GtkWidget *widget, gpointer data) | |
2080 { | |
2081 SearchData *sd = data; | |
2082 GtkTreeViewColumn *column; | |
2083 gchar *path; | |
2084 | |
2085 if (sd->search_folder_list) | |
2086 { | |
2087 search_stop(sd); | |
2088 search_result_thumb_step(sd); | |
2089 return; | |
2090 } | |
2091 | |
2092 if (sd->match_name_enable) history_combo_append_history(sd->entry_name, NULL); | |
2093 g_free(sd->search_name); | |
2094 sd->search_name = g_strdup(gtk_entry_get_text(GTK_ENTRY(sd->entry_name))); | |
2095 | |
2096 g_free(sd->search_similarity_path); | |
2097 sd->search_similarity_path = g_strdup(gtk_entry_get_text(GTK_ENTRY(sd->entry_similarity))); | |
2098 if (sd->match_similarity_enable) | |
2099 { | |
2100 if (!isfile(sd->search_similarity_path)) | |
2101 { | |
2102 file_util_warning_dialog(_("File not found"), | |
2103 _("Please enter an existing file for image content."), | |
2104 GTK_STOCK_DIALOG_WARNING, sd->window); | |
2105 return; | |
2106 } | |
2107 tab_completion_append_to_history(sd->entry_similarity, sd->search_similarity_path); | |
2108 } | |
2109 | |
138 | 2110 string_list_free(sd->search_keyword_list); |
9 | 2111 sd->search_keyword_list = keyword_list_pull(sd->entry_keywords); |
2112 | |
2113 date_selection_get(sd->date_sel, &sd->search_date_d, &sd->search_date_m, &sd->search_date_y); | |
2114 date_selection_get(sd->date_sel_end, &sd->search_date_end_d, &sd->search_date_end_m, &sd->search_date_end_y); | |
2115 | |
608
be8b2516359d
In the search results view, hide dimensions column instead of
zas_
parents:
607
diff
changeset
|
2116 column = gtk_tree_view_get_column(GTK_TREE_VIEW(sd->result_view), SEARCH_COLUMN_DIMENSIONS - 1); |
be8b2516359d
In the search results view, hide dimensions column instead of
zas_
parents:
607
diff
changeset
|
2117 gtk_tree_view_column_set_visible(column, sd->match_dimensions_enable); |
be8b2516359d
In the search results view, hide dimensions column instead of
zas_
parents:
607
diff
changeset
|
2118 |
9 | 2119 column = gtk_tree_view_get_column(GTK_TREE_VIEW(sd->result_view), SEARCH_COLUMN_RANK - 1); |
2120 gtk_tree_view_column_set_visible(column, sd->match_similarity_enable); | |
2121 if (!sd->match_similarity_enable) | |
2122 { | |
2123 GtkTreeSortable *sortable; | |
2124 gint id; | |
2125 GtkSortType order; | |
2126 | |
2127 sortable = GTK_TREE_SORTABLE(gtk_tree_view_get_model(GTK_TREE_VIEW(sd->result_view))); | |
2128 if (gtk_tree_sortable_get_sort_column_id(sortable, &id, &order) && | |
2129 id == SEARCH_COLUMN_RANK) | |
2130 { | |
2131 gtk_tree_sortable_set_sort_column_id(sortable, SEARCH_COLUMN_PATH, GTK_SORT_ASCENDING); | |
2132 } | |
2133 } | |
2134 | |
2135 if (sd->search_type == SEARCH_MATCH_NONE) | |
2136 { | |
2137 /* search path */ | |
2138 | |
2139 path = remove_trailing_slash(gtk_entry_get_text(GTK_ENTRY(sd->path_entry))); | |
2140 if (isdir(path)) | |
2141 { | |
783 | 2142 file_data_unref(sd->search_dir_fd); |
2143 sd->search_dir_fd = file_data_new_simple(path); | |
2144 | |
2145 tab_completion_append_to_history(sd->path_entry, sd->search_dir_fd->path); | |
9 | 2146 |
2147 search_start(sd); | |
2148 } | |
2149 else | |
2150 { | |
2151 file_util_warning_dialog(_("Folder not found"), | |
2152 _("Please enter an existing folder to search."), | |
2153 GTK_STOCK_DIALOG_WARNING, sd->window); | |
2154 } | |
2155 | |
2156 g_free(path); | |
2157 } | |
2158 else if (sd->search_type == SEARCH_MATCH_ALL) | |
2159 { | |
2160 /* search metadata */ | |
783 | 2161 path = g_build_filename(homedir(), GQ_CACHE_RC_METADATA, NULL); |
2162 | |
2163 file_data_unref(sd->search_dir_fd); | |
2164 sd->search_dir_fd = file_data_new_simple(path); | |
2165 g_free(path); | |
9 | 2166 |
2167 search_start(sd); | |
2168 } | |
2169 else if (sd->search_type == SEARCH_MATCH_CONTAINS) | |
2170 { | |
2171 /* search current result list */ | |
2172 GList *list; | |
2173 | |
2174 list = search_result_refine_list(sd); | |
2175 | |
783 | 2176 file_data_unref(sd->search_dir_fd); |
2177 sd->search_dir_fd = NULL; | |
9 | 2178 |
2179 search_start(sd); | |
2180 | |
2181 sd->search_file_list = g_list_concat(sd->search_file_list, list); | |
2182 } | |
2183 } | |
2184 | |
2185 /* | |
2186 *------------------------------------------------------------------- | |
2187 * window construct | |
2188 *------------------------------------------------------------------- | |
2189 */ | |
2190 | |
2191 enum { | |
2192 MENU_CHOICE_COLUMN_NAME = 0, | |
2193 MENU_CHOICE_COLUMN_VALUE | |
2194 }; | |
2195 | |
2196 static void search_thumb_toggle_cb(GtkWidget *button, gpointer data) | |
2197 { | |
2198 SearchData *sd = data; | |
2199 | |
2200 search_result_thumb_enable(sd, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button))); | |
2201 } | |
2202 | |
2203 static gint sort_matchdata_dimensions(MatchFileData *a, MatchFileData *b) | |
2204 { | |
2205 gint sa; | |
2206 gint sb; | |
2207 | |
2208 sa = a->width * a->height; | |
2209 sb = b->width * b->height; | |
2210 | |
2211 if (sa > sb) return 1; | |
2212 if (sa < sb) return -1; | |
2213 return 0; | |
2214 } | |
2215 | |
2216 static gint search_result_sort_cb(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer data) | |
2217 { | |
2218 gint n = GPOINTER_TO_INT(data); | |
138 | 2219 MatchFileData *fda; |
2220 MatchFileData *fdb; | |
9 | 2221 |
2222 gtk_tree_model_get(model, a, SEARCH_COLUMN_POINTER, &fda, -1); | |
2223 gtk_tree_model_get(model, b, SEARCH_COLUMN_POINTER, &fdb, -1); | |
2224 | |
2225 if (!fda || !fdb) return 0; | |
2226 | |
2227 switch (n) | |
2228 { | |
2229 case SEARCH_COLUMN_RANK: | |
138 | 2230 if (((MatchFileData *)fda)->rank > (fdb)->rank) return 1; |
2231 if (((MatchFileData *)fda)->rank < (fdb)->rank) return -1; | |
9 | 2232 return 0; |
2233 break; | |
2234 case SEARCH_COLUMN_NAME: | |
785 | 2235 if (options->file_sort.case_sensitive) |
2236 return strcmp(fda->fd->collate_key_name, fdb->fd->collate_key_name); | |
2237 else | |
2238 return strcmp(fda->fd->collate_key_name_nocase, fdb->fd->collate_key_name_nocase); | |
9 | 2239 break; |
2240 case SEARCH_COLUMN_SIZE: | |
138 | 2241 if (fda->fd->size > fdb->fd->size) return 1; |
2242 if (fda->fd->size < fdb->fd->size) return -1; | |
9 | 2243 return 0; |
2244 break; | |
2245 case SEARCH_COLUMN_DATE: | |
138 | 2246 if (fda->fd->date > fdb->fd->date) return 1; |
2247 if (fda->fd->date < fdb->fd->date) return -1; | |
9 | 2248 return 0; |
2249 break; | |
2250 case SEARCH_COLUMN_DIMENSIONS: | |
138 | 2251 return sort_matchdata_dimensions(fda, fdb); |
9 | 2252 break; |
2253 case SEARCH_COLUMN_PATH: | |
786
a20ff446347e
Compare paths using utf8_collate_key() since paths are utf8-encoded.
zas_
parents:
785
diff
changeset
|
2254 return utf8_compare(fda->fd->path, fdb->fd->path, options->file_sort.case_sensitive); |
9 | 2255 break; |
2256 default: | |
2257 break; | |
2258 } | |
2259 | |
2260 return 0; | |
2261 } | |
2262 | |
2263 static void search_result_add_column(SearchData * sd, gint n, const gchar *title, gint image, gint right_justify) | |
2264 { | |
2265 GtkTreeViewColumn *column; | |
2266 GtkCellRenderer *renderer; | |
2267 | |
2268 column = gtk_tree_view_column_new(); | |
2269 gtk_tree_view_column_set_title(column, title); | |
2270 gtk_tree_view_column_set_min_width(column, 4); | |
2271 | |
2272 if (n != SEARCH_COLUMN_THUMB) gtk_tree_view_column_set_resizable(column, TRUE); | |
2273 | |
2274 if (!image) | |
2275 { | |
2276 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_GROW_ONLY); | |
2277 renderer = gtk_cell_renderer_text_new(); | |
2278 if (right_justify) g_object_set(G_OBJECT(renderer), "xalign", 1.0, NULL); | |
2279 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
2280 gtk_tree_view_column_add_attribute(column, renderer, "text", n); | |
2281 | |
2282 gtk_tree_view_column_set_sort_column_id(column, n); | |
2283 } | |
2284 else | |
2285 { | |
2286 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED); | |
2287 renderer = gtk_cell_renderer_pixbuf_new(); | |
2288 cell_renderer_height_override(renderer); | |
2289 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
2290 gtk_tree_view_column_add_attribute(column, renderer, "pixbuf", n); | |
2291 } | |
2292 | |
2293 gtk_tree_view_append_column(GTK_TREE_VIEW(sd->result_view), column); | |
2294 } | |
2295 | |
2296 static void menu_choice_set_visible(GtkWidget *widget, gint visible) | |
2297 { | |
2298 if (visible) | |
2299 { | |
2300 if (!GTK_WIDGET_VISIBLE(widget)) gtk_widget_show(widget); | |
2301 } | |
2302 else | |
2303 { | |
2304 if (GTK_WIDGET_VISIBLE(widget)) gtk_widget_hide(widget); | |
2305 } | |
2306 } | |
2307 | |
2308 static void menu_choice_path_cb(GtkWidget *combo, gpointer data) | |
2309 { | |
2310 SearchData *sd = data; | |
2311 GtkTreeModel *store; | |
2312 GtkTreeIter iter; | |
2313 | |
2314 store = gtk_combo_box_get_model(GTK_COMBO_BOX(combo)); | |
2315 if (!gtk_combo_box_get_active_iter(GTK_COMBO_BOX(combo), &iter)) return; | |
2316 gtk_tree_model_get(store, &iter, MENU_CHOICE_COLUMN_VALUE, &sd->search_type, -1); | |
2317 | |
2318 menu_choice_set_visible(gtk_widget_get_parent(sd->check_recurse), | |
2319 (sd->search_type == SEARCH_MATCH_NONE)); | |
2320 } | |
2321 | |
2322 static void menu_choice_name_cb(GtkWidget *combo, gpointer data) | |
2323 { | |
2324 SearchData *sd = data; | |
2325 GtkTreeModel *store; | |
2326 GtkTreeIter iter; | |
2327 | |
2328 store = gtk_combo_box_get_model(GTK_COMBO_BOX(combo)); | |
2329 if (!gtk_combo_box_get_active_iter(GTK_COMBO_BOX(combo), &iter)) return; | |
2330 gtk_tree_model_get(store, &iter, MENU_CHOICE_COLUMN_VALUE, &sd->match_name, -1); | |
2331 } | |
2332 | |
2333 static void menu_choice_size_cb(GtkWidget *combo, gpointer data) | |
2334 { | |
2335 SearchData *sd = data; | |
2336 GtkTreeModel *store; | |
2337 GtkTreeIter iter; | |
2338 | |
2339 store = gtk_combo_box_get_model(GTK_COMBO_BOX(combo)); | |
2340 if (!gtk_combo_box_get_active_iter(GTK_COMBO_BOX(combo), &iter)) return; | |
2341 gtk_tree_model_get(store, &iter, MENU_CHOICE_COLUMN_VALUE, &sd->match_size, -1); | |
2342 | |
2343 menu_choice_set_visible(gtk_widget_get_parent(sd->spin_size_end), | |
2344 (sd->match_size == SEARCH_MATCH_BETWEEN)); | |
2345 } | |
2346 | |
2347 static void menu_choice_date_cb(GtkWidget *combo, gpointer data) | |
2348 { | |
2349 SearchData *sd = data; | |
2350 GtkTreeModel *store; | |
2351 GtkTreeIter iter; | |
2352 | |
2353 store = gtk_combo_box_get_model(GTK_COMBO_BOX(combo)); | |
2354 if (!gtk_combo_box_get_active_iter(GTK_COMBO_BOX(combo), &iter)) return; | |
2355 gtk_tree_model_get(store, &iter, MENU_CHOICE_COLUMN_VALUE, &sd->match_date, -1); | |
2356 | |
2357 menu_choice_set_visible(gtk_widget_get_parent(sd->date_sel_end), | |
2358 (sd->match_date == SEARCH_MATCH_BETWEEN)); | |
2359 } | |
2360 | |
2361 static void menu_choice_dimensions_cb(GtkWidget *combo, gpointer data) | |
2362 { | |
2363 SearchData *sd = data; | |
2364 GtkTreeModel *store; | |
2365 GtkTreeIter iter; | |
2366 | |
2367 store = gtk_combo_box_get_model(GTK_COMBO_BOX(combo)); | |
2368 if (!gtk_combo_box_get_active_iter(GTK_COMBO_BOX(combo), &iter)) return; | |
2369 gtk_tree_model_get(store, &iter, MENU_CHOICE_COLUMN_VALUE, &sd->match_dimensions, -1); | |
2370 | |
2371 menu_choice_set_visible(gtk_widget_get_parent(sd->spin_width_end), | |
2372 (sd->match_dimensions == SEARCH_MATCH_BETWEEN)); | |
2373 } | |
2374 | |
2375 static void menu_choice_keyword_cb(GtkWidget *combo, gpointer data) | |
2376 { | |
2377 SearchData *sd = data; | |
2378 GtkTreeModel *store; | |
2379 GtkTreeIter iter; | |
2380 | |
2381 store = gtk_combo_box_get_model(GTK_COMBO_BOX(combo)); | |
2382 if (!gtk_combo_box_get_active_iter(GTK_COMBO_BOX(combo), &iter)) return; | |
2383 gtk_tree_model_get(store, &iter, MENU_CHOICE_COLUMN_VALUE, &sd->match_keywords, -1); | |
2384 } | |
2385 | |
2386 static void menu_choice_spin_cb(GtkAdjustment *adjustment, gpointer data) | |
2387 { | |
2388 gint *value = data; | |
2389 | |
2390 *value = (gint)gtk_adjustment_get_value(adjustment); | |
2391 } | |
2392 | |
2393 static GtkWidget *menu_spin(GtkWidget *box, gdouble min, gdouble max, gint value, | |
2394 GCallback func, gpointer data) | |
2395 { | |
2396 GtkWidget *spin; | |
2397 GtkAdjustment *adj; | |
2398 | |
2399 spin = gtk_spin_button_new_with_range(min, max, 1); | |
2400 gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin), (gdouble)value); | |
2401 adj = gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(spin)); | |
2402 if (func) g_signal_connect(G_OBJECT(adj), "value_changed", | |
2403 G_CALLBACK(func), data); | |
2404 gtk_box_pack_start(GTK_BOX(box), spin, FALSE, FALSE, 0); | |
2405 gtk_widget_show(spin); | |
2406 | |
2407 return spin; | |
2408 } | |
2409 | |
2410 static void menu_choice_check_cb(GtkWidget *button, gpointer data) | |
2411 { | |
2412 GtkWidget *widget = data; | |
2413 gboolean active; | |
2414 gboolean *value; | |
2415 | |
2416 active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)); | |
2417 gtk_widget_set_sensitive(widget, active); | |
2418 | |
2419 value = g_object_get_data(G_OBJECT(button), "check_var"); | |
2420 if (value) *value = active; | |
2421 } | |
2422 | |
2423 static GtkWidget *menu_choice_menu(const MatchList *items, gint item_count, | |
2424 GCallback func, gpointer data) | |
2425 { | |
2426 GtkWidget *combo; | |
2427 GtkCellRenderer *renderer; | |
2428 GtkListStore *store; | |
2429 gint i; | |
2430 | |
2431 store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INT); | |
2432 combo = gtk_combo_box_new_with_model(GTK_TREE_MODEL(store)); | |
2433 g_object_unref(store); | |
2434 | |
2435 renderer = gtk_cell_renderer_text_new(); | |
2436 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), renderer, TRUE); | |
2437 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), renderer, | |
2438 "text", MENU_CHOICE_COLUMN_NAME, NULL); | |
2439 | |
2440 for (i = 0; i < item_count; i++) | |
2441 { | |
2442 GtkTreeIter iter; | |
2443 | |
2444 gtk_list_store_append(store, &iter); | |
2445 gtk_list_store_set(store, &iter, MENU_CHOICE_COLUMN_NAME, _(items[i].text), | |
2446 MENU_CHOICE_COLUMN_VALUE, items[i].type, -1); | |
2447 } | |
2448 | |
2449 gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0); | |
2450 | |
2451 if (func) g_signal_connect(G_OBJECT(combo), "changed", | |
2452 G_CALLBACK(func), data); | |
2453 | |
2454 return combo; | |
2455 } | |
2456 | |
2457 static GtkWidget *menu_choice(GtkWidget *box, GtkWidget **check, GtkWidget **menu, | |
2458 const gchar *text, gboolean *value, | |
2459 const MatchList *items, gint item_count, | |
2460 GCallback func, gpointer data) | |
2461 { | |
2462 GtkWidget *base_box; | |
2463 GtkWidget *hbox; | |
2464 GtkWidget *button; | |
2465 GtkWidget *option; | |
2466 | |
2467 base_box = gtk_hbox_new(FALSE, PREF_PAD_GAP); | |
2468 gtk_box_pack_start(GTK_BOX(box), base_box, FALSE, FALSE, 0); | |
2469 gtk_widget_show(base_box); | |
2470 | |
2471 button = gtk_check_button_new(); | |
2472 if (value) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), *value); | |
2473 gtk_box_pack_start(GTK_BOX(base_box), button, FALSE, FALSE, 0); | |
2474 gtk_widget_show(button); | |
2475 if (check) *check = button; | |
2476 if (value) g_object_set_data(G_OBJECT(button), "check_var", value); | |
2477 | |
2478 hbox = gtk_hbox_new(FALSE, PREF_PAD_SPACE); | |
2479 gtk_box_pack_start(GTK_BOX(base_box), hbox, TRUE, TRUE, 0); | |
2480 gtk_widget_show(hbox); | |
2481 | |
2482 g_signal_connect(G_OBJECT(button), "toggled", | |
2483 G_CALLBACK(menu_choice_check_cb), hbox); | |
2484 gtk_widget_set_sensitive(hbox, (value) ? *value : FALSE); | |
2485 | |
2486 pref_label_new(hbox, text); | |
2487 | |
2488 if (!items && !menu) return hbox; | |
2489 | |
2490 option = menu_choice_menu(items, item_count, func, data); | |
2491 gtk_box_pack_start(GTK_BOX(hbox), option, FALSE, FALSE, 0); | |
2492 gtk_widget_show(option); | |
2493 if (menu) *menu = option; | |
2494 | |
2495 return hbox; | |
2496 } | |
2497 | |
2498 static void search_window_close(SearchData *sd) | |
2499 { | |
2500 gtk_widget_destroy(sd->window); | |
2501 } | |
2502 | |
2503 static gint search_window_delete_cb(GtkWidget *widget, GdkEventAny *event, gpointer data) | |
2504 { | |
2505 SearchData *sd = data; | |
2506 | |
2507 search_window_close(sd); | |
2508 return TRUE; | |
2509 } | |
2510 | |
2511 static void search_window_destroy_cb(GtkWidget *widget, gpointer data) | |
2512 { | |
2513 SearchData *sd = data; | |
2514 | |
2515 search_window_list = g_list_remove(search_window_list, sd); | |
2516 | |
2517 search_result_update_idle_cancel(sd); | |
2518 | |
2519 filelist_free(sd->search_buffer_list); | |
2520 sd->search_buffer_list = NULL; | |
2521 | |
2522 search_stop(sd); | |
2523 search_result_clear(sd); | |
2524 | |
783 | 2525 file_data_unref(sd->search_dir_fd); |
2526 | |
9 | 2527 g_free(sd->search_name); |
2528 g_free(sd->search_similarity_path); | |
138 | 2529 string_list_free(sd->search_keyword_list); |
9 | 2530 |
795 | 2531 file_data_unregister_notify_func(search_notify_cb, sd); |
2532 | |
9 | 2533 g_free(sd); |
2534 } | |
2535 | |
783 | 2536 void search_new(FileData *dir_fd, FileData *example_file) |
9 | 2537 { |
2538 SearchData *sd; | |
2539 GtkWidget *vbox; | |
2540 GtkWidget *hbox; | |
2541 GtkWidget *hbox2; | |
2542 GtkWidget *pad_box; | |
2543 GtkWidget *frame; | |
2544 GtkWidget *scrolled; | |
2545 GtkListStore *store; | |
2546 GtkTreeSortable *sortable; | |
2547 GtkTreeSelection *selection; | |
2548 GtkWidget *combo; | |
2549 GdkGeometry geometry; | |
2550 | |
2551 sd = g_new0(SearchData, 1); | |
2552 | |
783 | 2553 sd->search_dir_fd = file_data_ref(dir_fd); |
9 | 2554 sd->search_path_recurse = TRUE; |
2555 sd->search_size = 0; | |
2556 sd->search_width = 640; | |
2557 sd->search_height = 480; | |
2558 sd->search_width_end = 1024; | |
2559 sd->search_height_end = 768; | |
2560 sd->search_name = NULL; | |
2561 sd->search_name_match_case = FALSE; | |
2562 | |
2563 sd->search_type = SEARCH_MATCH_NONE; | |
2564 | |
2565 sd->match_name = SEARCH_MATCH_CONTAINS; | |
2566 sd->match_size = SEARCH_MATCH_EQUAL; | |
2567 sd->match_date = SEARCH_MATCH_EQUAL; | |
2568 sd->match_dimensions = SEARCH_MATCH_EQUAL; | |
2569 sd->match_keywords = SEARCH_MATCH_ALL; | |
2570 | |
2571 sd->match_name_enable = TRUE; | |
2572 sd->match_size_enable = FALSE; | |
2573 sd->match_date_enable = FALSE; | |
2574 sd->match_dimensions_enable = FALSE; | |
2575 sd->match_similarity_enable = FALSE; | |
2576 sd->match_keywords_enable = FALSE; | |
2577 | |
2578 sd->search_similarity = 95; | |
783 | 2579 sd->search_similarity_path = g_strdup(example_file->path); |
9 | 2580 sd->search_similarity_cd = NULL; |
2581 | |
2582 sd->search_idle_id = -1; | |
2583 sd->update_idle_id = -1; | |
2584 | |
289
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
2585 sd->window = window_new(GTK_WINDOW_TOPLEVEL, "search", NULL, NULL, _("Image search")); |
9 | 2586 |
2587 gtk_window_set_resizable(GTK_WINDOW(sd->window), TRUE); | |
2588 | |
2589 geometry.min_width = 32; | |
2590 geometry.min_height = 32; | |
2591 geometry.base_width = DEF_SEARCH_WIDTH; | |
2592 geometry.base_height = DEF_SEARCH_HEIGHT; | |
2593 gtk_window_set_geometry_hints(GTK_WINDOW(sd->window), NULL, &geometry, | |
2594 GDK_HINT_MIN_SIZE | GDK_HINT_BASE_SIZE); | |
2595 | |
2596 gtk_window_set_default_size(GTK_WINDOW(sd->window), DEF_SEARCH_WIDTH, DEF_SEARCH_HEIGHT); | |
2597 | |
2598 g_signal_connect(G_OBJECT(sd->window), "delete_event", | |
2599 G_CALLBACK(search_window_delete_cb), sd); | |
2600 g_signal_connect(G_OBJECT(sd->window), "destroy", | |
2601 G_CALLBACK(search_window_destroy_cb), sd); | |
2602 | |
2603 g_signal_connect(G_OBJECT(sd->window), "key_press_event", | |
2604 G_CALLBACK(search_window_keypress_cb), sd); | |
2605 | |
2606 vbox = gtk_vbox_new(FALSE, PREF_PAD_GAP); | |
2607 gtk_container_set_border_width(GTK_CONTAINER(vbox), PREF_PAD_GAP); | |
2608 gtk_container_add(GTK_CONTAINER(sd->window), vbox); | |
2609 gtk_widget_show(vbox); | |
2610 | |
2611 sd->box_search = pref_box_new(vbox, FALSE, GTK_ORIENTATION_VERTICAL, PREF_PAD_GAP); | |
2612 | |
2613 hbox = pref_box_new(sd->box_search, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_SPACE); | |
2614 | |
2615 pref_label_new(hbox, _("Search:")); | |
2616 | |
2617 sd->menu_path = menu_choice_menu(text_search_menu_path, sizeof(text_search_menu_path) / sizeof(MatchList), | |
2618 G_CALLBACK(menu_choice_path_cb), sd); | |
2619 gtk_box_pack_start(GTK_BOX(hbox), sd->menu_path, FALSE, FALSE, 0); | |
2620 gtk_widget_show(sd->menu_path); | |
2621 | |
2622 hbox2 = pref_box_new(hbox, TRUE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_SPACE); | |
783 | 2623 combo = tab_completion_new_with_history(&sd->path_entry, sd->search_dir_fd->path, |
9 | 2624 "search_path", -1, |
2625 NULL, NULL); | |
2626 tab_completion_add_select_button(sd->path_entry, NULL, TRUE); | |
2627 gtk_box_pack_start(GTK_BOX(hbox2), combo, TRUE, TRUE, 0); | |
2628 gtk_widget_show(combo); | |
2629 sd->check_recurse = pref_checkbox_new_int(hbox2, _("Recurse"), | |
2630 sd->search_path_recurse, &sd->search_path_recurse); | |
2631 | |
2632 hbox = menu_choice(sd->box_search, &sd->check_name, &sd->menu_name, | |
2633 _("File name"), &sd->match_name_enable, | |
2634 text_search_menu_name, sizeof(text_search_menu_name) / sizeof(MatchList), | |
2635 G_CALLBACK(menu_choice_name_cb), sd); | |
2636 combo = history_combo_new(&sd->entry_name, "", "search_name", -1); | |
2637 gtk_box_pack_start(GTK_BOX(hbox), combo, TRUE, TRUE, 0); | |
2638 gtk_widget_show(combo); | |
2639 pref_checkbox_new_int(hbox, _("Match case"), | |
2640 sd->search_name_match_case, &sd->search_name_match_case); | |
2641 | |
2642 hbox = menu_choice(sd->box_search, &sd->check_size, &sd->menu_size, | |
2643 _("File size is"), &sd->match_size_enable, | |
2644 text_search_menu_size, sizeof(text_search_menu_size) / sizeof(MatchList), | |
2645 G_CALLBACK(menu_choice_size_cb), sd); | |
2646 sd->spin_size = menu_spin(hbox, 0, 1024*1024*1024, sd->search_size, | |
2647 G_CALLBACK(menu_choice_spin_cb), &sd->search_size); | |
2648 hbox2 = gtk_hbox_new(FALSE, PREF_PAD_SPACE); | |
2649 gtk_box_pack_start(GTK_BOX(hbox), hbox2, FALSE, FALSE, 0); | |
2650 pref_label_new(hbox2, _("and")); | |
2651 sd->spin_size_end = menu_spin(hbox2, 0, 1024*1024*1024, sd->search_size_end, | |
2652 G_CALLBACK(menu_choice_spin_cb), &sd->search_size_end); | |
2653 | |
2654 hbox = menu_choice(sd->box_search, &sd->check_date, &sd->menu_date, | |
2655 _("File date is"), &sd->match_date_enable, | |
2656 text_search_menu_date, sizeof(text_search_menu_date) / sizeof(MatchList), | |
2657 G_CALLBACK(menu_choice_date_cb), sd); | |
2658 sd->date_sel = date_selection_new(); | |
2659 date_selection_time_set(sd->date_sel, time(NULL)); | |
2660 gtk_box_pack_start(GTK_BOX(hbox), sd->date_sel, FALSE, FALSE, 0); | |
2661 gtk_widget_show(sd->date_sel); | |
2662 | |
2663 hbox2 = gtk_hbox_new(FALSE, PREF_PAD_SPACE); | |
2664 gtk_box_pack_start(GTK_BOX(hbox), hbox2, FALSE, FALSE, 0); | |
2665 pref_label_new(hbox2, _("and")); | |
2666 sd->date_sel_end = date_selection_new(); | |
2667 date_selection_time_set(sd->date_sel_end, time(NULL)); | |
2668 gtk_box_pack_start(GTK_BOX(hbox2), sd->date_sel_end, FALSE, FALSE, 0); | |
2669 gtk_widget_show(sd->date_sel_end); | |
2670 | |
2671 hbox = menu_choice(sd->box_search, &sd->check_dimensions, &sd->menu_dimensions, | |
2672 _("Image dimensions are"), &sd->match_dimensions_enable, | |
2673 text_search_menu_size, sizeof(text_search_menu_size) / sizeof(MatchList), | |
2674 G_CALLBACK(menu_choice_dimensions_cb), sd); | |
2675 pad_box = pref_box_new(hbox, FALSE, GTK_ORIENTATION_HORIZONTAL, 2); | |
2676 sd->spin_width = menu_spin(pad_box, 0, 1000000, sd->search_width, | |
2677 G_CALLBACK(menu_choice_spin_cb), &sd->search_width); | |
2678 pref_label_new(pad_box, "x"); | |
2679 sd->spin_height = menu_spin(pad_box, 0, 1000000, sd->search_height, | |
2680 G_CALLBACK(menu_choice_spin_cb), &sd->search_height); | |
2681 hbox2 = gtk_hbox_new(FALSE, 2); | |
2682 gtk_box_pack_start(GTK_BOX(hbox), hbox2, FALSE, FALSE, 0); | |
2683 pref_label_new(hbox2, _("and")); | |
2684 pref_spacer(hbox2, PREF_PAD_SPACE - 2*2); | |
2685 sd->spin_width_end = menu_spin(hbox2, 0, 1000000, sd->search_width_end, | |
2686 G_CALLBACK(menu_choice_spin_cb), &sd->search_width_end); | |
2687 pref_label_new(hbox2, "x"); | |
2688 sd->spin_height_end = menu_spin(hbox2, 0, 1000000, sd->search_height_end, | |
2689 G_CALLBACK(menu_choice_spin_cb), &sd->search_height_end); | |
2690 | |
2691 hbox = menu_choice(sd->box_search, &sd->check_similarity, NULL, | |
2692 _("Image content is"), &sd->match_similarity_enable, | |
2693 NULL, 0, NULL, sd); | |
2694 sd->spin_similarity = menu_spin(hbox, 80, 100, sd->search_similarity, | |
2695 G_CALLBACK(menu_choice_spin_cb), &sd->search_similarity); | |
2696 | |
2697 /* xgettext:no-c-format */ | |
2698 pref_label_new(hbox, _("% similar to")); | |
2699 | |
2700 combo = tab_completion_new_with_history(&sd->entry_similarity, | |
2701 (sd->search_similarity_path) ? sd->search_similarity_path : "", | |
2702 "search_similarity_path", -1, NULL, NULL); | |
2703 tab_completion_add_select_button(sd->entry_similarity, NULL, FALSE); | |
2704 gtk_box_pack_start(GTK_BOX(hbox), combo, TRUE, TRUE, 0); | |
2705 gtk_widget_show(combo); | |
2706 | |
2707 hbox = menu_choice(sd->box_search, &sd->check_keywords, &sd->menu_keywords, | |
2708 _("Keywords"), &sd->match_keywords_enable, | |
2709 text_search_menu_keyword, sizeof(text_search_menu_keyword) / sizeof(MatchList), | |
2710 G_CALLBACK(menu_choice_keyword_cb), sd); | |
2711 sd->entry_keywords = gtk_entry_new(); | |
2712 gtk_box_pack_start(GTK_BOX(hbox), sd->entry_keywords, TRUE, TRUE, 0); | |
2713 gtk_widget_set_sensitive(sd->entry_keywords, sd->match_keywords_enable); | |
2714 g_signal_connect(G_OBJECT(sd->check_keywords), "toggled", | |
2715 G_CALLBACK(menu_choice_check_cb), sd->entry_keywords); | |
2716 gtk_widget_show(sd->entry_keywords); | |
2717 | |
2718 scrolled = gtk_scrolled_window_new(NULL, NULL); | |
2719 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN); | |
2720 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), | |
2721 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
2722 gtk_box_pack_start(GTK_BOX(vbox), scrolled, TRUE, TRUE, 0); | |
2723 gtk_widget_show(scrolled); | |
2724 | |
2725 store = gtk_list_store_new(8, G_TYPE_POINTER, G_TYPE_INT, GDK_TYPE_PIXBUF, | |
2726 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, | |
2727 G_TYPE_STRING, G_TYPE_STRING); | |
2728 | |
2729 /* set up sorting */ | |
2730 sortable = GTK_TREE_SORTABLE(store); | |
2731 gtk_tree_sortable_set_sort_func(sortable, SEARCH_COLUMN_RANK, search_result_sort_cb, | |
2732 GINT_TO_POINTER(SEARCH_COLUMN_RANK), NULL); | |
2733 gtk_tree_sortable_set_sort_func(sortable, SEARCH_COLUMN_NAME, search_result_sort_cb, | |
2734 GINT_TO_POINTER(SEARCH_COLUMN_NAME), NULL); | |
2735 gtk_tree_sortable_set_sort_func(sortable, SEARCH_COLUMN_SIZE, search_result_sort_cb, | |
2736 GINT_TO_POINTER(SEARCH_COLUMN_SIZE), NULL); | |
2737 gtk_tree_sortable_set_sort_func(sortable, SEARCH_COLUMN_DATE, search_result_sort_cb, | |
2738 GINT_TO_POINTER(SEARCH_COLUMN_DATE), NULL); | |
2739 gtk_tree_sortable_set_sort_func(sortable, SEARCH_COLUMN_DIMENSIONS, search_result_sort_cb, | |
2740 GINT_TO_POINTER(SEARCH_COLUMN_DIMENSIONS), NULL); | |
2741 gtk_tree_sortable_set_sort_func(sortable, SEARCH_COLUMN_PATH, search_result_sort_cb, | |
2742 GINT_TO_POINTER(SEARCH_COLUMN_PATH), NULL); | |
2743 | |
2744 #if 0 | |
2745 /* by default, search results are unsorted until user selects a sort column - for speed, | |
2746 * using sort slows search speed by an order of magnitude with 1000's of results :-/ | |
2747 */ | |
2748 gtk_tree_sortable_set_sort_column_id(sortable, SEARCH_COLUMN_PATH, GTK_SORT_ASCENDING); | |
2749 #endif | |
2750 | |
2751 sd->result_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); | |
2752 g_object_unref(store); | |
2753 gtk_container_add(GTK_CONTAINER(scrolled), sd->result_view); | |
2754 gtk_widget_show(sd->result_view); | |
2755 | |
2756 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(sd->result_view)); | |
2757 gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_MULTIPLE); | |
2758 gtk_tree_selection_set_select_function(selection, search_result_select_cb, sd, NULL); | |
2759 | |
2760 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(sd->result_view), TRUE); | |
2761 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(sd->result_view), FALSE); | |
2762 | |
2763 #if 0 | |
2764 gtk_tree_view_set_search_column(GTK_TREE_VIEW(sd->result_view), SEARCH_COLUMN_NAME); | |
2765 #endif | |
2766 | |
2767 search_result_add_column(sd, SEARCH_COLUMN_RANK, _("Rank"), FALSE, FALSE); | |
2768 search_result_add_column(sd, SEARCH_COLUMN_THUMB, "", TRUE, FALSE); | |
2769 search_result_add_column(sd, SEARCH_COLUMN_NAME, _("Name"), FALSE, FALSE); | |
2770 search_result_add_column(sd, SEARCH_COLUMN_SIZE, _("Size"), FALSE, TRUE); | |
2771 search_result_add_column(sd, SEARCH_COLUMN_DATE, _("Date"), FALSE, TRUE); | |
2772 search_result_add_column(sd, SEARCH_COLUMN_DIMENSIONS, _("Dimensions"), FALSE, FALSE); | |
2773 search_result_add_column(sd, SEARCH_COLUMN_PATH, _("Path"), FALSE, FALSE); | |
2774 | |
2775 search_dnd_init(sd); | |
2776 | |
2777 g_signal_connect(G_OBJECT(sd->result_view), "button_press_event", | |
2778 G_CALLBACK(search_result_press_cb), sd); | |
2779 g_signal_connect(G_OBJECT(sd->result_view), "button_release_event", | |
2780 G_CALLBACK(search_result_release_cb), sd); | |
2781 g_signal_connect(G_OBJECT(sd->result_view), "key_press_event", | |
2782 G_CALLBACK(search_result_keypress_cb), sd); | |
2783 | |
2784 hbox = pref_box_new(vbox, FALSE, GTK_ORIENTATION_HORIZONTAL, 0); | |
2785 | |
2786 sd->button_thumbs = pref_checkbox_new(hbox, _("Thumbnails"), FALSE, | |
2787 G_CALLBACK(search_thumb_toggle_cb), sd); | |
2788 | |
2789 frame = gtk_frame_new(NULL); | |
2790 gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN); | |
2791 gtk_box_pack_start(GTK_BOX(hbox), frame, TRUE, TRUE, PREF_PAD_SPACE); | |
2792 gtk_widget_show(frame); | |
2793 | |
2794 sd->label_status = gtk_label_new(""); | |
2795 gtk_widget_set_size_request(sd->label_status, 50, -1); | |
2796 gtk_container_add(GTK_CONTAINER(frame), sd->label_status); | |
2797 gtk_widget_show(sd->label_status); | |
2798 | |
2799 sd->label_progress = gtk_progress_bar_new(); | |
2800 gtk_widget_set_size_request(sd->label_progress, 50, -1); | |
2801 gtk_box_pack_start(GTK_BOX(hbox), sd->label_progress, TRUE, TRUE, 0); | |
2802 gtk_widget_show(sd->label_progress); | |
2803 | |
2804 sd->spinner = spinner_new(NULL, -1); | |
2805 gtk_box_pack_start(GTK_BOX(hbox), sd->spinner, FALSE, FALSE, 0); | |
2806 gtk_widget_show(sd->spinner); | |
2807 | |
2808 sd->button_start = pref_button_new(hbox, GTK_STOCK_FIND, NULL, FALSE, | |
2809 G_CALLBACK(search_start_cb), sd); | |
2810 pref_spacer(hbox, PREF_PAD_BUTTON_GAP); | |
2811 sd->button_stop = pref_button_new(hbox, GTK_STOCK_STOP, NULL, FALSE, | |
2812 G_CALLBACK(search_start_cb), sd); | |
2813 gtk_widget_set_sensitive(sd->button_stop, FALSE); | |
2814 | |
2815 search_status_update(sd); | |
2816 search_progress_update(sd, FALSE, -1.0); | |
2817 | |
2818 search_window_list = g_list_append(search_window_list, sd); | |
2819 | |
795 | 2820 file_data_register_notify_func(search_notify_cb, sd, NOTIFY_PRIORITY_MEDIUM); |
2821 | |
9 | 2822 gtk_widget_show(sd->window); |
2823 } | |
2824 | |
2825 /* | |
2826 *------------------------------------------------------------------- | |
2827 * maintenance (move, delete, etc.) | |
2828 *------------------------------------------------------------------- | |
2829 */ | |
2830 | |
138 | 2831 static void search_result_change_path(SearchData *sd, FileData *fd) |
9 | 2832 { |
2833 GtkTreeModel *store; | |
2834 GtkTreeIter iter; | |
2835 gint valid; | |
2836 | |
2837 store = gtk_tree_view_get_model(GTK_TREE_VIEW(sd->result_view)); | |
2838 valid = gtk_tree_model_get_iter_first(store, &iter); | |
2839 while (valid) | |
2840 { | |
2841 GtkTreeIter current; | |
138 | 2842 MatchFileData *mfd; |
9 | 2843 |
2844 current = iter; | |
2845 valid = gtk_tree_model_iter_next(store, &iter); | |
2846 | |
138 | 2847 gtk_tree_model_get(store, ¤t, SEARCH_COLUMN_POINTER, &mfd, -1); |
2848 if (mfd->fd == fd) | |
9 | 2849 { |
138 | 2850 if (fd->change && fd->change->dest) |
9 | 2851 { |
2852 gtk_list_store_set(GTK_LIST_STORE(store), ¤t, | |
138 | 2853 SEARCH_COLUMN_NAME, mfd->fd->name, |
2854 SEARCH_COLUMN_PATH, mfd->fd->path, -1); | |
9 | 2855 } |
2856 else | |
2857 { | |
138 | 2858 search_result_remove_item(sd, mfd, ¤t); |
9 | 2859 } |
2860 } | |
2861 } | |
2862 } | |
2863 | |
795 | 2864 static void search_notify_cb(FileData *fd, NotifyType type, gpointer data) |
9 | 2865 { |
795 | 2866 SearchData *sd = data; |
2867 | |
803 | 2868 if (type != NOTIFY_TYPE_CHANGE || !fd->change) return; |
795 | 2869 |
2870 switch(fd->change->type) | |
9 | 2871 { |
795 | 2872 case FILEDATA_CHANGE_MOVE: |
2873 case FILEDATA_CHANGE_RENAME: | |
2874 case FILEDATA_CHANGE_DELETE: | |
2875 search_result_change_path(sd, fd); | |
2876 break; | |
2877 case FILEDATA_CHANGE_COPY: | |
2878 case FILEDATA_CHANGE_UNSPECIFIED: | |
2879 break; | |
9 | 2880 } |
2881 } |