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