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