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