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