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