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