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