Mercurial > geeqie.yaz
annotate src/search.c @ 1675:717374fb1bbd
fixed destroying of menu data
Make sure that menu destroy functions do not access parent widget
structures that are already destroyed
There are 2 ways to achieve this:
- use g_signal_handlers_disconnect_matched() like in vf_destroy_cb()
- use separate data structure passed to *_popup_menu_destroy_cb()
like in img-view.
author | nadvornik |
---|---|
date | Tue, 21 Jul 2009 14:17:01 +0000 |
parents | 24a12aa0cb54 |
children | 760e8d68290c |
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 { |
661 GList *list; | |
662 | |
663 list = search_result_selection_list(sd); | |
1272 | 664 file_util_start_editor_from_filelist(key, list, sd->window); |
138 | 665 filelist_free(list); |
9 | 666 } |
667 | |
668 static void search_result_collection_from_selection(SearchData *sd) | |
669 { | |
670 CollectWindow *w; | |
671 GList *list; | |
672 | |
673 list = search_result_selection_list(sd); | |
674 w = collection_window_new(NULL); | |
138 | 675 collection_table_add_filelist(w->table, list); |
676 filelist_free(list); | |
9 | 677 } |
678 | |
1444 | 679 static gboolean search_result_update_idle_cb(gpointer data) |
9 | 680 { |
681 SearchData *sd = data; | |
682 | |
683 search_status_update(sd); | |
684 | |
1523 | 685 sd->update_idle_id = 0; |
9 | 686 return FALSE; |
687 } | |
688 | |
689 static void search_result_update_idle_cancel(SearchData *sd) | |
690 { | |
1523 | 691 if (sd->update_idle_id) |
692 { | |
693 g_source_remove(sd->update_idle_id); | |
694 sd->update_idle_id = 0; | |
695 } | |
9 | 696 } |
697 | |
698 static gboolean search_result_select_cb(GtkTreeSelection *selection, GtkTreeModel *store, | |
699 GtkTreePath *tpath, gboolean selected, gpointer data) | |
700 { | |
701 SearchData *sd = data; | |
702 | |
1523 | 703 if (!sd->update_idle_id) |
9 | 704 { |
705 sd->update_idle_id = g_idle_add(search_result_update_idle_cb, sd); | |
706 } | |
707 | |
708 return TRUE; | |
709 } | |
710 | |
711 /* | |
712 *------------------------------------------------------------------- | |
713 * result list thumbs | |
714 *------------------------------------------------------------------- | |
715 */ | |
716 | |
717 static void search_result_thumb_step(SearchData *sd); | |
718 | |
719 | |
720 static void search_result_thumb_set(SearchData *sd, FileData *fd, GtkTreeIter *iter) | |
721 { | |
722 GtkListStore *store; | |
723 GtkTreeIter iter_n; | |
724 | |
725 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(sd->result_view))); | |
726 if (!iter) | |
727 { | |
728 if (search_result_find_row(sd, fd, &iter_n) >= 0) iter = &iter_n; | |
729 } | |
730 | |
845 | 731 if (iter) gtk_list_store_set(store, iter, SEARCH_COLUMN_THUMB, fd->thumb_pixbuf, -1); |
9 | 732 } |
733 | |
734 static void search_result_thumb_do(SearchData *sd) | |
735 { | |
736 FileData *fd; | |
737 | |
738 if (!sd->thumb_loader || !sd->thumb_fd) return; | |
739 fd = sd->thumb_fd; | |
740 | |
741 search_result_thumb_set(sd, fd, NULL); | |
742 } | |
743 | |
744 static void search_result_thumb_done_cb(ThumbLoader *tl, gpointer data) | |
745 { | |
746 SearchData *sd = data; | |
747 | |
748 search_result_thumb_do(sd); | |
749 search_result_thumb_step(sd); | |
750 } | |
751 | |
752 static void search_result_thumb_step(SearchData *sd) | |
753 { | |
754 GtkTreeModel *store; | |
755 GtkTreeIter iter; | |
138 | 756 MatchFileData *mfd = NULL; |
1444 | 757 gboolean valid; |
9 | 758 gint row = 0; |
759 gint length = 0; | |
760 | |
761 store = gtk_tree_view_get_model(GTK_TREE_VIEW(sd->result_view)); | |
762 valid = gtk_tree_model_get_iter_first(store, &iter); | |
607 | 763 if (!sd->thumb_enable) |
764 { | |
765 while (valid) | |
766 { | |
767 gtk_list_store_set(GTK_LIST_STORE(store), &iter, SEARCH_COLUMN_THUMB, NULL, -1); | |
768 valid = gtk_tree_model_iter_next(store, &iter); | |
769 } | |
770 return; | |
771 } | |
772 | |
138 | 773 while (!mfd && valid) |
9 | 774 { |
775 GdkPixbuf *pixbuf; | |
776 | |
777 length++; | |
138 | 778 gtk_tree_model_get(store, &iter, SEARCH_COLUMN_POINTER, &mfd, SEARCH_COLUMN_THUMB, &pixbuf, -1); |
845 | 779 if (pixbuf || mfd->fd->thumb_pixbuf) |
9 | 780 { |
845 | 781 if (!pixbuf) gtk_list_store_set(GTK_LIST_STORE(store), &iter, SEARCH_COLUMN_THUMB, mfd->fd->thumb_pixbuf, -1); |
9 | 782 row++; |
138 | 783 mfd = NULL; |
9 | 784 } |
785 valid = gtk_tree_model_iter_next(store, &iter); | |
786 } | |
787 if (valid) | |
788 { | |
789 while (gtk_tree_model_iter_next(store, &iter)) length++; | |
790 } | |
791 | |
138 | 792 if (!mfd) |
9 | 793 { |
794 sd->thumb_fd = NULL; | |
795 thumb_loader_free(sd->thumb_loader); | |
796 sd->thumb_loader = NULL; | |
797 | |
798 search_progress_update(sd, TRUE, -1.0); | |
799 return; | |
800 } | |
801 | |
802 search_progress_update(sd, FALSE, (gdouble)row/length); | |
803 | |
138 | 804 sd->thumb_fd = mfd->fd; |
9 | 805 thumb_loader_free(sd->thumb_loader); |
333 | 806 sd->thumb_loader = thumb_loader_new(options->thumbnails.max_width, options->thumbnails.max_height); |
9 | 807 |
808 thumb_loader_set_callbacks(sd->thumb_loader, | |
809 search_result_thumb_done_cb, | |
810 search_result_thumb_done_cb, | |
811 NULL, | |
812 sd); | |
838 | 813 if (!thumb_loader_start(sd->thumb_loader, mfd->fd)) |
9 | 814 { |
815 search_result_thumb_do(sd); | |
816 search_result_thumb_step(sd); | |
817 } | |
818 } | |
819 | |
820 static void search_result_thumb_height(SearchData *sd) | |
821 { | |
822 GtkTreeViewColumn *column; | |
823 GtkCellRenderer *cell; | |
824 GList *list; | |
825 | |
826 column = gtk_tree_view_get_column(GTK_TREE_VIEW(sd->result_view), SEARCH_COLUMN_THUMB - 1); | |
827 if (!column) return; | |
828 | |
333 | 829 gtk_tree_view_column_set_fixed_width(column, (sd->thumb_enable) ? options->thumbnails.max_width : 4); |
9 | 830 |
831 list = gtk_tree_view_column_get_cell_renderers(column); | |
832 if (!list) return; | |
833 cell = list->data; | |
834 g_list_free(list); | |
835 | |
333 | 836 g_object_set(G_OBJECT(cell), "height", (sd->thumb_enable) ? options->thumbnails.max_height : -1, NULL); |
9 | 837 gtk_tree_view_columns_autosize(GTK_TREE_VIEW(sd->result_view)); |
838 } | |
839 | |
1444 | 840 static void search_result_thumb_enable(SearchData *sd, gboolean enable) |
9 | 841 { |
842 if (sd->thumb_enable == enable) return; | |
843 | |
844 if (sd->thumb_enable) | |
845 { | |
846 GtkTreeModel *store; | |
847 GtkTreeIter iter; | |
1444 | 848 gboolean valid; |
9 | 849 |
850 thumb_loader_free(sd->thumb_loader); | |
851 sd->thumb_loader = NULL; | |
852 | |
853 store = gtk_tree_view_get_model(GTK_TREE_VIEW(sd->result_view)); | |
854 valid = gtk_tree_model_get_iter_first(store, &iter); | |
855 while (valid) | |
856 { | |
857 gtk_list_store_set(GTK_LIST_STORE(store), &iter, SEARCH_COLUMN_THUMB, NULL, -1); | |
858 valid = gtk_tree_model_iter_next(store, &iter); | |
859 } | |
860 search_progress_update(sd, TRUE, -1.0); | |
861 } | |
862 | |
863 sd->thumb_enable = enable; | |
864 | |
865 search_result_thumb_height(sd); | |
866 if (!sd->search_folder_list && !sd->search_file_list) search_result_thumb_step(sd); | |
867 } | |
868 | |
869 /* | |
870 *------------------------------------------------------------------- | |
871 * result list menu | |
872 *------------------------------------------------------------------- | |
873 */ | |
874 | |
875 static void sr_menu_view_cb(GtkWidget *widget, gpointer data) | |
876 { | |
877 SearchData *sd = data; | |
878 | |
1445
cb0040be832e
fixed viewing image from dupe and search windows
nadvornik
parents:
1444
diff
changeset
|
879 if (sd->click_fd) layout_set_fd(NULL, sd->click_fd); |
9 | 880 } |
881 | |
882 static void sr_menu_viewnew_cb(GtkWidget *widget, gpointer data) | |
883 { | |
884 SearchData *sd = data; | |
885 GList *list; | |
886 | |
887 list = search_result_selection_list(sd); | |
888 view_window_new_from_list(list); | |
138 | 889 filelist_free(list); |
9 | 890 } |
891 | |
892 static void sr_menu_select_all_cb(GtkWidget *widget, gpointer data) | |
893 { | |
894 SearchData *sd = data; | |
895 GtkTreeSelection *selection; | |
896 | |
897 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(sd->result_view)); | |
898 gtk_tree_selection_select_all(selection); | |
899 } | |
900 | |
901 static void sr_menu_select_none_cb(GtkWidget *widget, gpointer data) | |
902 { | |
903 SearchData *sd = data; | |
904 GtkTreeSelection *selection; | |
905 | |
906 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(sd->result_view)); | |
907 gtk_tree_selection_unselect_all(selection); | |
908 } | |
909 | |
910 static void sr_menu_edit_cb(GtkWidget *widget, gpointer data) | |
911 { | |
912 SearchData *sd; | |
1272 | 913 const gchar *key = data; |
9 | 914 |
915 sd = submenu_item_get_data(widget); | |
916 if (!sd) return; | |
917 | |
1272 | 918 search_result_edit_selected(sd, key); |
9 | 919 } |
920 | |
921 static void sr_menu_collection_cb(GtkWidget *widget, gpointer data) | |
922 { | |
923 SearchData *sd = data; | |
924 | |
925 search_result_collection_from_selection(sd); | |
926 } | |
927 | |
928 static void sr_menu_print_cb(GtkWidget *widget, gpointer data) | |
929 { | |
930 SearchData *sd = data; | |
442 | 931 |
138 | 932 print_window_new(sd->click_fd, search_result_selection_list(sd), |
933 search_result_get_filelist(sd), sd->window); | |
9 | 934 } |
935 | |
936 static void sr_menu_copy_cb(GtkWidget *widget, gpointer data) | |
937 { | |
938 SearchData *sd = data; | |
939 | |
940 file_util_copy(NULL, search_result_selection_list(sd), NULL, sd->window); | |
941 } | |
942 | |
943 static void sr_menu_move_cb(GtkWidget *widget, gpointer data) | |
944 { | |
945 SearchData *sd = data; | |
946 | |
947 file_util_move(NULL, search_result_selection_list(sd), NULL, sd->window); | |
948 } | |
949 | |
950 static void sr_menu_rename_cb(GtkWidget *widget, gpointer data) | |
951 { | |
952 SearchData *sd = data; | |
953 | |
954 file_util_rename(NULL, search_result_selection_list(sd), sd->window); | |
955 } | |
956 | |
957 static void sr_menu_delete_cb(GtkWidget *widget, gpointer data) | |
958 { | |
959 SearchData *sd = data; | |
960 | |
961 file_util_delete(NULL, search_result_selection_list(sd), sd->window); | |
962 } | |
963 | |
497 | 964 static void sr_menu_copy_path_cb(GtkWidget *widget, gpointer data) |
965 { | |
966 SearchData *sd = data; | |
967 | |
968 file_util_copy_path_list_to_clipboard(search_result_selection_list(sd)); | |
969 } | |
970 | |
9 | 971 static void sr_menu_remove_cb(GtkWidget *widget, gpointer data) |
972 { | |
973 SearchData *sd = data; | |
974 | |
975 search_result_remove_selection(sd); | |
976 } | |
977 | |
978 static void sr_menu_clear_cb(GtkWidget *widget, gpointer data) | |
979 { | |
980 SearchData *sd = data; | |
981 | |
982 search_result_clear(sd); | |
983 } | |
984 | |
1397
a0bd58a6535f
In various Edit context menus, only display editors that match the file types in the selection.
zas_
parents:
1367
diff
changeset
|
985 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
|
986 { |
1675 | 987 GList *editmenu_fd_list = data; |
988 | |
989 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
|
990 } |
a0bd58a6535f
In various Edit context menus, only display editors that match the file types in the selection.
zas_
parents:
1367
diff
changeset
|
991 |
1444 | 992 static GtkWidget *search_result_menu(SearchData *sd, gboolean on_row, gboolean empty) |
9 | 993 { |
994 GtkWidget *menu; | |
995 GtkWidget *item; | |
1675 | 996 GList *editmenu_fd_list; |
9 | 997 |
998 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
|
999 |
9 | 1000 menu_item_add_sensitive(menu, _("_View"), on_row, |
1001 G_CALLBACK(sr_menu_view_cb), sd); | |
1002 menu_item_add_stock_sensitive(menu, _("View in _new window"), GTK_STOCK_NEW, on_row, | |
1003 G_CALLBACK(sr_menu_viewnew_cb), sd); | |
1004 menu_item_add_divider(menu); | |
1005 menu_item_add_sensitive(menu, _("Select all"), !empty, | |
1006 G_CALLBACK(sr_menu_select_all_cb), sd); | |
1007 menu_item_add_sensitive(menu, _("Select none"), !empty, | |
1008 G_CALLBACK(sr_menu_select_none_cb), sd); | |
1009 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
|
1010 |
1675 | 1011 editmenu_fd_list = search_result_selection_list(sd); |
1012 g_signal_connect(G_OBJECT(menu), "destroy", | |
1013 G_CALLBACK(search_result_menu_destroy_cb), editmenu_fd_list); | |
1014 submenu_add_edit(menu, &item, G_CALLBACK(sr_menu_edit_cb), sd, editmenu_fd_list); | |
9 | 1015 if (!on_row) gtk_widget_set_sensitive(item, FALSE); |
1016 menu_item_add_stock_sensitive(menu, _("Add to new collection"), GTK_STOCK_INDEX, on_row, | |
1017 G_CALLBACK(sr_menu_collection_cb), sd); | |
1018 menu_item_add_stock_sensitive(menu, _("Print..."), GTK_STOCK_PRINT, on_row, | |
1019 G_CALLBACK(sr_menu_print_cb), sd); | |
1020 menu_item_add_divider(menu); | |
1021 menu_item_add_stock_sensitive(menu, _("_Copy..."), GTK_STOCK_COPY, on_row, | |
1022 G_CALLBACK(sr_menu_copy_cb), sd); | |
1023 menu_item_add_sensitive(menu, _("_Move..."), on_row, | |
1024 G_CALLBACK(sr_menu_move_cb), sd); | |
1025 menu_item_add_sensitive(menu, _("_Rename..."), on_row, | |
1026 G_CALLBACK(sr_menu_rename_cb), sd); | |
1027 menu_item_add_stock_sensitive(menu, _("_Delete..."), GTK_STOCK_DELETE, on_row, | |
1028 G_CALLBACK(sr_menu_delete_cb), sd); | |
1513 | 1029 menu_item_add_sensitive(menu, _("_Copy path"), on_row, |
1030 G_CALLBACK(sr_menu_copy_path_cb), sd); | |
9 | 1031 menu_item_add_divider(menu); |
1032 menu_item_add_stock_sensitive(menu, _("Rem_ove"), GTK_STOCK_REMOVE, on_row, | |
1033 G_CALLBACK(sr_menu_remove_cb), sd); | |
1034 menu_item_add_stock_sensitive(menu, _("C_lear"), GTK_STOCK_CLEAR, !empty, | |
1035 G_CALLBACK(sr_menu_clear_cb), sd); | |
1036 | |
1037 return menu; | |
1038 } | |
1039 | |
1040 static void search_result_menu_pos_cb(GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer data) | |
1041 { | |
1042 SearchData *sd = data; | |
1043 GtkTreePath *tpath; | |
1044 gint cx, cy, cw, ch; | |
1045 | |
1046 gtk_tree_view_get_cursor(GTK_TREE_VIEW(sd->result_view), &tpath, NULL); | |
1047 if (!tpath) return; | |
1048 | |
1049 tree_view_get_cell_clamped(GTK_TREE_VIEW(sd->result_view), tpath, | |
1050 SEARCH_COLUMN_NAME - 1, TRUE, &cx, &cy, &cw, &ch); | |
1051 gtk_tree_path_free(tpath); | |
1052 cy += ch; | |
1053 popup_menu_position_clamp(menu, &cx, &cy, 0); | |
1054 *x = cx; | |
1055 *y = cy; | |
1056 } | |
1057 | |
1058 /* | |
1059 *------------------------------------------------------------------- | |
1060 * result list input | |
1061 *------------------------------------------------------------------- | |
1062 */ | |
1063 | |
1444 | 1064 static gboolean search_result_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data) |
9 | 1065 { |
1066 SearchData *sd = data; | |
1067 GtkTreeModel *store; | |
1068 GtkTreePath *tpath; | |
1069 GtkTreeIter iter; | |
138 | 1070 MatchFileData *mfd = NULL; |
9 | 1071 |
1072 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | |
1073 | |
1074 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bevent->x, bevent->y, | |
1075 &tpath, NULL, NULL, NULL)) | |
1076 { | |
1077 gtk_tree_model_get_iter(store, &iter, tpath); | |
138 | 1078 gtk_tree_model_get(store, &iter, SEARCH_COLUMN_POINTER, &mfd, -1); |
9 | 1079 gtk_tree_path_free(tpath); |
1080 } | |
1081 | |
138 | 1082 sd->click_fd = mfd ? mfd->fd : NULL; |
9 | 1083 |
448
a73cc0fa14d0
Use explicit names for mouse buttons instead of numbers.
zas_
parents:
446
diff
changeset
|
1084 if (bevent->button == MOUSE_BUTTON_RIGHT) |
9 | 1085 { |
1086 GtkWidget *menu; | |
1087 | |
138 | 1088 menu = search_result_menu(sd, (mfd != NULL), (search_result_count(sd, NULL) == 0)); |
9 | 1089 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, bevent->button, bevent->time); |
1090 } | |
1091 | |
138 | 1092 if (!mfd) return FALSE; |
9 | 1093 |
448
a73cc0fa14d0
Use explicit names for mouse buttons instead of numbers.
zas_
parents:
446
diff
changeset
|
1094 if (bevent->button == MOUSE_BUTTON_LEFT && bevent->type == GDK_2BUTTON_PRESS) |
9 | 1095 { |
1445
cb0040be832e
fixed viewing image from dupe and search windows
nadvornik
parents:
1444
diff
changeset
|
1096 layout_set_fd(NULL, mfd->fd); |
9 | 1097 } |
1098 | |
448
a73cc0fa14d0
Use explicit names for mouse buttons instead of numbers.
zas_
parents:
446
diff
changeset
|
1099 if (bevent->button == MOUSE_BUTTON_MIDDLE) return TRUE; |
a73cc0fa14d0
Use explicit names for mouse buttons instead of numbers.
zas_
parents:
446
diff
changeset
|
1100 |
a73cc0fa14d0
Use explicit names for mouse buttons instead of numbers.
zas_
parents:
446
diff
changeset
|
1101 if (bevent->button == MOUSE_BUTTON_RIGHT) |
9 | 1102 { |
138 | 1103 if (!search_result_row_selected(sd, mfd->fd)) |
9 | 1104 { |
1105 GtkTreeSelection *selection; | |
1106 | |
1107 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget)); | |
1108 gtk_tree_selection_unselect_all(selection); | |
1109 gtk_tree_selection_select_iter(selection, &iter); | |
1110 | |
1111 tpath = gtk_tree_model_get_path(store, &iter); | |
1112 gtk_tree_view_set_cursor(GTK_TREE_VIEW(widget), tpath, NULL, FALSE); | |
1113 gtk_tree_path_free(tpath); | |
1114 } | |
1115 return TRUE; | |
1116 } | |
1117 | |
448
a73cc0fa14d0
Use explicit names for mouse buttons instead of numbers.
zas_
parents:
446
diff
changeset
|
1118 if (bevent->button == MOUSE_BUTTON_LEFT && bevent->type == GDK_BUTTON_PRESS && |
9 | 1119 !(bevent->state & GDK_SHIFT_MASK ) && |
1120 !(bevent->state & GDK_CONTROL_MASK ) && | |
138 | 1121 search_result_row_selected(sd, mfd->fd)) |
9 | 1122 { |
1123 /* this selection handled on release_cb */ | |
1124 gtk_widget_grab_focus(widget); | |
1125 return TRUE; | |
1126 } | |
1127 | |
1128 return FALSE; | |
1129 } | |
1130 | |
1444 | 1131 static gboolean search_result_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data) |
9 | 1132 { |
1133 SearchData *sd = data; | |
1134 GtkTreeModel *store; | |
1135 GtkTreePath *tpath; | |
1136 GtkTreeIter iter; | |
1137 | |
138 | 1138 MatchFileData *mfd = NULL; |
9 | 1139 |
448
a73cc0fa14d0
Use explicit names for mouse buttons instead of numbers.
zas_
parents:
446
diff
changeset
|
1140 if (bevent->button != MOUSE_BUTTON_LEFT && bevent->button != MOUSE_BUTTON_MIDDLE) return TRUE; |
9 | 1141 |
1142 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | |
1143 | |
1144 if ((bevent->x != 0 || bevent->y != 0) && | |
1145 gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bevent->x, bevent->y, | |
1146 &tpath, NULL, NULL, NULL)) | |
1147 { | |
1148 gtk_tree_model_get_iter(store, &iter, tpath); | |
138 | 1149 gtk_tree_model_get(store, &iter, SEARCH_COLUMN_POINTER, &mfd, -1); |
9 | 1150 gtk_tree_path_free(tpath); |
1151 } | |
1152 | |
448
a73cc0fa14d0
Use explicit names for mouse buttons instead of numbers.
zas_
parents:
446
diff
changeset
|
1153 if (bevent->button == MOUSE_BUTTON_MIDDLE) |
9 | 1154 { |
138 | 1155 if (mfd && sd->click_fd == mfd->fd) |
9 | 1156 { |
1157 GtkTreeSelection *selection; | |
1158 | |
1159 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget)); | |
138 | 1160 if (search_result_row_selected(sd, mfd->fd)) |
9 | 1161 { |
1162 gtk_tree_selection_unselect_iter(selection, &iter); | |
1163 } | |
1164 else | |
1165 { | |
1166 gtk_tree_selection_select_iter(selection, &iter); | |
1167 } | |
1168 } | |
1169 return TRUE; | |
1170 } | |
1171 | |
138 | 1172 if (mfd && sd->click_fd == mfd->fd && |
9 | 1173 !(bevent->state & GDK_SHIFT_MASK ) && |
1174 !(bevent->state & GDK_CONTROL_MASK ) && | |
138 | 1175 search_result_row_selected(sd, mfd->fd)) |
9 | 1176 { |
1177 GtkTreeSelection *selection; | |
1178 | |
1179 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget)); | |
1180 gtk_tree_selection_unselect_all(selection); | |
1181 gtk_tree_selection_select_iter(selection, &iter); | |
1182 | |
1183 tpath = gtk_tree_model_get_path(store, &iter); | |
1184 gtk_tree_view_set_cursor(GTK_TREE_VIEW(widget), tpath, NULL, FALSE); | |
1185 gtk_tree_path_free(tpath); | |
1186 | |
1187 return TRUE; | |
1188 } | |
1189 | |
1190 return FALSE; | |
1191 } | |
1192 | |
1444 | 1193 static gboolean search_result_keypress_cb(GtkWidget *widget, GdkEventKey *event, gpointer data) |
9 | 1194 { |
1195 SearchData *sd = data; | |
1437 | 1196 gboolean stop_signal = FALSE; |
9 | 1197 GtkTreeModel *store; |
1198 GtkTreeSelection *selection; | |
1199 GList *slist; | |
138 | 1200 MatchFileData *mfd = NULL; |
9 | 1201 |
1202 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(sd->result_view)); | |
1203 slist = gtk_tree_selection_get_selected_rows(selection, &store); | |
1204 if (slist) | |
1205 { | |
1206 GtkTreePath *tpath; | |
1207 GtkTreeIter iter; | |
1208 GList *last; | |
1209 | |
1210 last = g_list_last(slist); | |
1211 tpath = last->data; | |
1212 | |
1213 /* last is newest selected file */ | |
1214 gtk_tree_model_get_iter(store, &iter, tpath); | |
138 | 1215 gtk_tree_model_get(store, &iter, SEARCH_COLUMN_POINTER, &mfd, -1); |
9 | 1216 } |
1217 g_list_foreach(slist, (GFunc)gtk_tree_path_free, NULL); | |
1218 g_list_free(slist); | |
1219 | |
1220 if (event->state & GDK_CONTROL_MASK) | |
1221 { | |
1222 gint edit_val = -1; | |
1223 | |
85
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
1224 stop_signal = TRUE; |
9 | 1225 switch (event->keyval) |
1226 { | |
1227 case '1': | |
1228 edit_val = 0; | |
1229 break; | |
1230 case '2': | |
1231 edit_val = 1; | |
1232 break; | |
1233 case '3': | |
1234 edit_val = 2; | |
1235 break; | |
1236 case '4': | |
1237 edit_val = 3; | |
1238 break; | |
1239 case '5': | |
1240 edit_val = 4; | |
1241 break; | |
1242 case '6': | |
1243 edit_val = 5; | |
1244 break; | |
1245 case '7': | |
1246 edit_val = 6; | |
1247 break; | |
1248 case '8': | |
1249 edit_val = 7; | |
1250 break; | |
1251 case '9': | |
1252 edit_val = 8; | |
1253 break; | |
1254 case '0': | |
1255 edit_val = 9; | |
1256 break; | |
1257 case 'C': case 'c': | |
1258 file_util_copy(NULL, search_result_selection_list(sd), NULL, widget); | |
1259 break; | |
1260 case 'M': case 'm': | |
1261 file_util_move(NULL, search_result_selection_list(sd), NULL, widget); | |
1262 break; | |
1263 case 'R': case 'r': | |
1264 file_util_rename(NULL, search_result_selection_list(sd), widget); | |
1265 break; | |
1266 case 'D': case 'd': | |
1267 file_util_delete(NULL, search_result_selection_list(sd), widget); | |
1268 break; | |
1269 case 'A': case 'a': | |
1270 if (event->state & GDK_SHIFT_MASK) | |
1271 { | |
1272 gtk_tree_selection_unselect_all(selection); | |
1273 } | |
1274 else | |
1275 { | |
1276 gtk_tree_selection_select_all(selection); | |
1277 } | |
1278 break; | |
1279 case GDK_Delete: case GDK_KP_Delete: | |
1280 search_result_clear(sd); | |
1281 break; | |
1282 default: | |
85
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
1283 stop_signal = FALSE; |
9 | 1284 break; |
1285 } | |
1272 | 1286 #if 0 |
9 | 1287 if (edit_val >= 0) |
1288 { | |
1289 search_result_edit_selected(sd, edit_val); | |
1290 } | |
1272 | 1291 #endif |
9 | 1292 } |
1293 else | |
1294 { | |
85
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
1295 stop_signal = TRUE; |
9 | 1296 switch (event->keyval) |
1297 { | |
1298 case GDK_Return: case GDK_KP_Enter: | |
1445
cb0040be832e
fixed viewing image from dupe and search windows
nadvornik
parents:
1444
diff
changeset
|
1299 if (mfd) layout_set_fd(NULL, mfd->fd); |
9 | 1300 break; |
1301 case 'V': case 'v': | |
1302 { | |
1303 GList *list; | |
1304 | |
1305 list = search_result_selection_list(sd); | |
1306 view_window_new_from_list(list); | |
138 | 1307 filelist_free(list); |
9 | 1308 } |
1309 break; | |
1310 case GDK_Delete: case GDK_KP_Delete: | |
1311 search_result_remove_selection(sd); | |
1312 break; | |
1313 case 'C': case 'c': | |
1314 search_result_collection_from_selection(sd); | |
1315 break; | |
1316 case GDK_Menu: | |
1317 case GDK_F10: | |
1318 { | |
1319 GtkWidget *menu; | |
1320 | |
138 | 1321 sd->click_fd = mfd->fd; |
1322 menu = search_result_menu(sd, (mfd != NULL), (search_result_count(sd, NULL) > 0)); | |
9 | 1323 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, |
1324 search_result_menu_pos_cb, sd, 0, GDK_CURRENT_TIME); | |
1325 } | |
1326 break; | |
1327 default: | |
85
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
1328 stop_signal = FALSE; |
9 | 1329 break; |
1330 } | |
1331 } | |
442 | 1332 |
9 | 1333 return stop_signal; |
1334 } | |
1335 | |
1444 | 1336 static gboolean search_window_keypress_cb(GtkWidget *widget, GdkEventKey *event, gpointer data) |
9 | 1337 { |
1338 SearchData *sd = data; | |
1437 | 1339 gboolean stop_signal = FALSE; |
9 | 1340 |
1341 if (event->state & GDK_CONTROL_MASK) | |
1342 { | |
85
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
1343 stop_signal = TRUE; |
9 | 1344 switch (event->keyval) |
1345 { | |
1346 case 'T': case 't': | |
1347 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(sd->button_thumbs), | |
1348 !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(sd->button_thumbs))); | |
1349 break; | |
1350 case 'W': case 'w': | |
1351 search_window_close(sd); | |
1352 break; | |
1353 default: | |
85
9d5c75b5ec28
Fri Oct 20 09:20:10 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
1354 stop_signal = FALSE; |
9 | 1355 break; |
1356 } | |
1357 } | |
1358 | |
1359 return stop_signal; | |
1360 } | |
1361 | |
1362 /* | |
1363 *------------------------------------------------------------------- | |
1364 * dnd | |
1365 *------------------------------------------------------------------- | |
1366 */ | |
1367 | |
1368 static GtkTargetEntry result_drag_types[] = { | |
1369 { "text/uri-list", 0, TARGET_URI_LIST }, | |
1370 { "text/plain", 0, TARGET_TEXT_PLAIN } | |
1371 }; | |
1372 static gint n_result_drag_types = 2; | |
1373 | |
1374 static void search_dnd_data_set(GtkWidget *widget, GdkDragContext *context, | |
1375 GtkSelectionData *selection_data, guint info, | |
1376 guint time, gpointer data) | |
1377 { | |
1378 SearchData *sd = data; | |
1379 gchar *uri_text; | |
1380 gint length; | |
1381 GList *list; | |
1382 | |
1383 switch (info) | |
1384 { | |
1385 case TARGET_URI_LIST: | |
1386 case TARGET_TEXT_PLAIN: | |
1387 list = search_result_selection_list(sd); | |
1388 if (!list) return; | |
138 | 1389 uri_text = uri_text_from_filelist(list, &length, (info == TARGET_TEXT_PLAIN)); |
1390 filelist_free(list); | |
9 | 1391 break; |
1392 default: | |
1393 uri_text = NULL; | |
1394 break; | |
1395 } | |
1396 | |
1397 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
|
1398 8, (guchar *)uri_text, length); |
9 | 1399 g_free(uri_text); |
1400 } | |
1401 | |
1402 static void search_dnd_begin(GtkWidget *widget, GdkDragContext *context, gpointer data) | |
1403 { | |
1404 SearchData *sd = data; | |
1405 | |
1406 if (sd->click_fd && !search_result_row_selected(sd, sd->click_fd)) | |
1407 { | |
1408 GtkListStore *store; | |
1409 GtkTreeIter iter; | |
1410 | |
1411 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(widget))); | |
1412 if (search_result_find_row(sd, sd->click_fd, &iter) >= 0) | |
1413 { | |
1414 GtkTreeSelection *selection; | |
1415 GtkTreePath *tpath; | |
1416 | |
1417 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget)); | |
1418 gtk_tree_selection_unselect_all(selection); | |
1419 gtk_tree_selection_select_iter(selection, &iter); | |
1420 | |
1421 tpath = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter); | |
1422 gtk_tree_view_set_cursor(GTK_TREE_VIEW(widget), tpath, NULL, FALSE); | |
1423 gtk_tree_path_free(tpath); | |
1424 } | |
1425 } | |
1426 | |
1427 if (sd->thumb_enable && | |
845 | 1428 sd->click_fd && sd->click_fd->thumb_pixbuf) |
9 | 1429 { |
845 | 1430 dnd_set_drag_icon(widget, context, sd->click_fd->thumb_pixbuf, search_result_selection_count(sd, NULL)); |
9 | 1431 } |
1432 } | |
1433 | |
1434 static void search_dnd_init(SearchData *sd) | |
1435 { | |
1436 gtk_drag_source_set(sd->result_view, GDK_BUTTON1_MASK | GDK_BUTTON2_MASK, | |
1437 result_drag_types, n_result_drag_types, | |
1438 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK); | |
1439 g_signal_connect(G_OBJECT(sd->result_view), "drag_data_get", | |
1440 G_CALLBACK(search_dnd_data_set), sd); | |
1441 g_signal_connect(G_OBJECT(sd->result_view), "drag_begin", | |
1442 G_CALLBACK(search_dnd_begin), sd); | |
1443 #if 0 | |
1444 g_signal_connect(G_OBJECT(sd->result_view), "drag_end", | |
1445 G_CALLBACK(search_dnd_end), sd); | |
1446 #endif | |
442 | 1447 |
9 | 1448 } |
1449 | |
1450 /* | |
1451 *------------------------------------------------------------------- | |
1452 * search core | |
1453 *------------------------------------------------------------------- | |
1454 */ | |
1455 | |
1456 #define MATCH_IS_BETWEEN(val, a, b) (b > a ? (val >= a && val <= b) : (val >= b && val <= a)) | |
1457 | |
1444 | 1458 static gboolean search_step_cb(gpointer data); |
9 | 1459 |
1460 | |
1461 static void search_buffer_flush(SearchData *sd) | |
1462 { | |
1463 GList *work; | |
1464 | |
1465 work = g_list_last(sd->search_buffer_list); | |
1466 while (work) | |
1467 { | |
1468 MatchFileData *mfd = work->data; | |
1469 work = work->prev; | |
1470 | |
1471 search_result_append(sd, mfd); | |
1472 } | |
1473 | |
1474 g_list_free(sd->search_buffer_list); | |
1475 sd->search_buffer_list = NULL; | |
1476 sd->search_buffer_count = 0; | |
1477 } | |
1478 | |
1479 static void search_stop(SearchData *sd) | |
1480 { | |
1523 | 1481 if (sd->search_idle_id) |
9 | 1482 { |
1483 g_source_remove(sd->search_idle_id); | |
1523 | 1484 sd->search_idle_id = 0; |
9 | 1485 } |
1486 | |
1487 image_loader_free(sd->img_loader); | |
1488 sd->img_loader = NULL; | |
1489 cache_sim_data_free(sd->img_cd); | |
1490 sd->img_cd = NULL; | |
1491 | |
1492 cache_sim_data_free(sd->search_similarity_cd); | |
1493 sd->search_similarity_cd = NULL; | |
1494 | |
1495 search_buffer_flush(sd); | |
1496 | |
1497 filelist_free(sd->search_folder_list); | |
1498 sd->search_folder_list = NULL; | |
1499 | |
1500 g_list_free(sd->search_done_list); | |
1501 sd->search_done_list = NULL; | |
1502 | |
1503 filelist_free(sd->search_file_list); | |
1504 sd->search_file_list = NULL; | |
1505 | |
1506 gtk_widget_set_sensitive(sd->box_search, TRUE); | |
1507 spinner_set_interval(sd->spinner, -1); | |
1508 gtk_widget_set_sensitive(sd->button_start, TRUE); | |
1509 gtk_widget_set_sensitive(sd->button_stop, FALSE); | |
1510 search_progress_update(sd, TRUE, -1.0); | |
1511 search_status_update(sd); | |
1512 } | |
1513 | |
1514 static void search_file_load_process(SearchData *sd, CacheData *cd) | |
1515 { | |
1516 GdkPixbuf *pixbuf; | |
1517 | |
1518 pixbuf = image_loader_get_pixbuf(sd->img_loader); | |
1519 | |
1520 if (cd && pixbuf) | |
1521 { | |
1522 if (!cd->dimensions) | |
1523 { | |
1524 cache_sim_data_set_dimensions(cd, gdk_pixbuf_get_width(pixbuf), | |
1525 gdk_pixbuf_get_height(pixbuf)); | |
1526 } | |
1527 | |
1528 if (sd->match_similarity_enable && !cd->similarity) | |
1529 { | |
1530 ImageSimilarityData *sim; | |
1531 | |
1532 sim = image_sim_new_from_pixbuf(pixbuf); | |
1533 cache_sim_data_set_similarity(cd, sim); | |
1534 image_sim_free(sim); | |
1535 } | |
1536 | |
333 | 1537 if (options->thumbnails.enable_caching && |
1011 | 1538 sd->img_loader && image_loader_get_fd(sd->img_loader)) |
9 | 1539 { |
1540 gchar *base; | |
1541 const gchar *path; | |
1542 mode_t mode = 0755; | |
1543 | |
1011 | 1544 path = image_loader_get_fd(sd->img_loader)->path; |
9 | 1545 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
|
1546 if (recursive_mkdir_if_not_exists(base, mode)) |
9 | 1547 { |
1548 g_free(cd->path); | |
1549 cd->path = cache_get_location(CACHE_TYPE_SIM, path, TRUE, NULL); | |
1550 if (cache_sim_data_save(cd)) | |
1551 { | |
1011 | 1552 filetime_set(cd->path, filetime(image_loader_get_fd(sd->img_loader)->path)); |
9 | 1553 } |
1554 } | |
1555 g_free(base); | |
1556 } | |
1557 } | |
1558 | |
1559 image_loader_free(sd->img_loader); | |
1560 sd->img_loader = NULL; | |
1561 | |
1562 sd->search_idle_id = g_idle_add(search_step_cb, sd); | |
1563 } | |
1564 | |
1565 static void search_file_load_done_cb(ImageLoader *il, gpointer data) | |
1566 { | |
442 | 1567 SearchData *sd = data; |
9 | 1568 search_file_load_process(sd, sd->img_cd); |
1569 } | |
1570 | |
1444 | 1571 static gboolean search_file_do_extra(SearchData *sd, FileData *fd, gint *match, |
1572 gint *width, gint *height, gint *simval) | |
9 | 1573 { |
1437 | 1574 gboolean new_data = FALSE; |
1575 gboolean tmatch = TRUE; | |
1576 gboolean tested = FALSE; | |
9 | 1577 |
1578 if (!sd->img_cd) | |
1579 { | |
1580 gchar *cd_path; | |
1581 | |
1582 new_data = TRUE; | |
1583 | |
1584 cd_path = cache_find_location(CACHE_TYPE_SIM, fd->path); | |
1585 if (cd_path && filetime(fd->path) == filetime(cd_path)) | |
1586 { | |
1587 sd->img_cd = cache_sim_data_load(cd_path); | |
1588 } | |
1589 g_free(cd_path); | |
1590 } | |
1591 | |
1592 if (!sd->img_cd) | |
1593 { | |
1594 sd->img_cd = cache_sim_data_new(); | |
1595 } | |
1596 | |
1597 if (new_data) | |
1598 { | |
1599 if ((sd->match_dimensions_enable && !sd->img_cd->dimensions) || | |
1600 (sd->match_similarity_enable && !sd->img_cd->similarity)) | |
1601 { | |
138 | 1602 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
|
1603 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
|
1604 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
|
1605 if (image_loader_start(sd->img_loader)) |
9 | 1606 { |
1607 return TRUE; | |
1608 } | |
1609 else | |
1610 { | |
1611 image_loader_free(sd->img_loader); | |
1612 sd->img_loader = NULL; | |
1613 } | |
1614 } | |
1615 } | |
1616 | |
1617 if (tmatch && sd->match_dimensions_enable && sd->img_cd->dimensions) | |
1618 { | |
1619 CacheData *cd = sd->img_cd; | |
1620 | |
1621 tmatch = FALSE; | |
1622 tested = TRUE; | |
1623 | |
1624 if (sd->match_dimensions == SEARCH_MATCH_EQUAL) | |
1625 { | |
1626 tmatch = (cd->width == sd->search_width && cd->height == sd->search_height); | |
1627 } | |
1628 else if (sd->match_dimensions == SEARCH_MATCH_UNDER) | |
1629 { | |
1630 tmatch = (cd->width < sd->search_width && cd->height < sd->search_height); | |
1631 } | |
1632 else if (sd->match_dimensions == SEARCH_MATCH_OVER) | |
1633 { | |
1634 tmatch = (cd->width > sd->search_width && cd->height > sd->search_height); | |
1635 } | |
1636 else if (sd->match_dimensions == SEARCH_MATCH_BETWEEN) | |
1637 { | |
1638 tmatch = (MATCH_IS_BETWEEN(cd->width, sd->search_width, sd->search_width_end) && | |
1639 MATCH_IS_BETWEEN(cd->height, sd->search_height, sd->search_height_end)); | |
1640 } | |
1641 } | |
1642 | |
1643 if (tmatch && sd->match_similarity_enable && sd->img_cd->similarity) | |
1644 { | |
1645 gdouble value = 0.0; | |
1646 | |
1647 tmatch = FALSE; | |
1648 tested = TRUE; | |
1649 | |
1650 /* fixme: implement similarity checking */ | |
1651 if (sd->search_similarity_cd && sd->search_similarity_cd->similarity) | |
1652 { | |
1653 gdouble result; | |
1654 | |
1655 result = image_sim_compare_fast(sd->search_similarity_cd->sim, sd->img_cd->sim, | |
1656 (gdouble)sd->search_similarity / 100.0); | |
1657 result *= 100.0; | |
1658 if (result >= (gdouble)sd->search_similarity) | |
1659 { | |
1660 tmatch = TRUE; | |
1661 value = (gint)result; | |
1662 } | |
1663 } | |
442 | 1664 |
9 | 1665 if (simval) *simval = value; |
1666 } | |
1667 | |
1668 if (sd->img_cd->dimensions) | |
1669 { | |
1670 if (width) *width = sd->img_cd->width; | |
1671 if (height) *height = sd->img_cd->height; | |
1672 } | |
1673 | |
1674 cache_sim_data_free(sd->img_cd); | |
1675 sd->img_cd = NULL; | |
1676 | |
1677 *match = (tmatch && tested); | |
1678 | |
1679 return FALSE; | |
1680 } | |
1681 | |
1444 | 1682 static gboolean search_file_next(SearchData *sd) |
9 | 1683 { |
1684 FileData *fd; | |
1437 | 1685 gboolean match = TRUE; |
1686 gboolean tested = FALSE; | |
1687 gboolean extra_only = FALSE; | |
9 | 1688 gint width = 0; |
1689 gint height = 0; | |
1690 gint sim = 0; | |
1691 | |
1692 if (!sd->search_file_list) return FALSE; | |
1693 | |
1694 if (sd->img_cd) | |
1695 { | |
1696 /* on end of a CacheData load, skip recomparing non-extra match types */ | |
1697 extra_only = TRUE; | |
1698 match = FALSE; | |
1699 } | |
1700 else | |
1701 { | |
1702 sd->search_total++; | |
1703 } | |
1704 | |
1705 fd = sd->search_file_list->data; | |
1706 | |
1707 if (match && sd->match_name_enable && sd->search_name) | |
1708 { | |
1709 tested = TRUE; | |
1710 match = FALSE; | |
1711 | |
1712 if (sd->match_name == SEARCH_MATCH_EQUAL) | |
1713 { | |
1714 if (sd->search_name_match_case) | |
1715 { | |
1716 match = (strcmp(fd->name, sd->search_name) == 0); | |
1717 } | |
1718 else | |
1719 { | |
1307 | 1720 match = (g_ascii_strcasecmp(fd->name, sd->search_name) == 0); |
9 | 1721 } |
1722 } | |
1723 else if (sd->match_name == SEARCH_MATCH_CONTAINS) | |
1724 { | |
1725 if (sd->search_name_match_case) | |
1726 { | |
1727 match = (strstr(fd->name, sd->search_name) != NULL); | |
1728 } | |
1729 else | |
1730 { | |
1731 /* sd->search_name is converted in search_start() */ | |
1732 gchar *haystack = g_utf8_strdown(fd->name, -1); | |
1733 match = (strstr(haystack, sd->search_name) != NULL); | |
1734 g_free(haystack); | |
1735 } | |
1736 } | |
1737 } | |
1738 | |
1739 if (match && sd->match_size_enable) | |
1740 { | |
1741 tested = TRUE; | |
1742 match = FALSE; | |
1743 | |
1744 if (sd->match_size == SEARCH_MATCH_EQUAL) | |
1745 { | |
1746 match = (fd->size == sd->search_size); | |
1747 } | |
1748 else if (sd->match_size == SEARCH_MATCH_UNDER) | |
1749 { | |
1750 match = (fd->size < sd->search_size); | |
1751 } | |
1752 else if (sd->match_size == SEARCH_MATCH_OVER) | |
1753 { | |
1754 match = (fd->size > sd->search_size); | |
1755 } | |
1756 else if (sd->match_size == SEARCH_MATCH_BETWEEN) | |
1757 { | |
1758 match = MATCH_IS_BETWEEN(fd->size, sd->search_size, sd->search_size_end); | |
1759 } | |
1760 } | |
1761 | |
1762 if (match && sd->match_date_enable) | |
1763 { | |
1764 tested = TRUE; | |
1765 match = FALSE; | |
1766 | |
1767 if (sd->match_date == SEARCH_MATCH_EQUAL) | |
1768 { | |
1769 struct tm *lt; | |
1770 | |
1771 lt = localtime(&fd->date); | |
1772 match = (lt && | |
1773 lt->tm_year == sd->search_date_y - 1900 && | |
1774 lt->tm_mon == sd->search_date_m - 1 && | |
1775 lt->tm_mday == sd->search_date_d); | |
1776 } | |
1777 else if (sd->match_date == SEARCH_MATCH_UNDER) | |
1778 { | |
1779 match = (fd->date < convert_dmy_to_time(sd->search_date_d, sd->search_date_m, sd->search_date_y)); | |
1780 } | |
1781 else if (sd->match_date == SEARCH_MATCH_OVER) | |
1782 { | |
1783 match = (fd->date > convert_dmy_to_time(sd->search_date_d, sd->search_date_m, sd->search_date_y) + 60 * 60 * 24 - 1); | |
1784 } | |
1785 else if (sd->match_date == SEARCH_MATCH_BETWEEN) | |
1786 { | |
1787 time_t a = convert_dmy_to_time(sd->search_date_d, sd->search_date_m, sd->search_date_y); | |
1788 time_t b = convert_dmy_to_time(sd->search_date_end_d, sd->search_date_end_m, sd->search_date_end_y); | |
1789 | |
1790 if (b >= a) | |
1791 { | |
1792 b += 60 * 60 * 24 - 1; | |
1793 } | |
1794 else | |
1795 { | |
1796 a += 60 * 60 * 24 - 1; | |
1797 } | |
1798 match = MATCH_IS_BETWEEN(fd->date, a, b); | |
1799 } | |
1800 } | |
1801 | |
1802 if (match && sd->match_keywords_enable && sd->search_keyword_list) | |
1803 { | |
1804 GList *list; | |
1805 | |
1806 tested = TRUE; | |
1807 match = FALSE; | |
1808 | |
1288 | 1809 list = metadata_read_list(fd, KEYWORD_KEY, METADATA_PLAIN); |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1211
diff
changeset
|
1810 |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1211
diff
changeset
|
1811 if (list) |
9 | 1812 { |
1813 GList *needle; | |
1814 GList *haystack; | |
1815 | |
1816 if (sd->match_keywords == SEARCH_MATCH_ALL) | |
1817 { | |
1437 | 1818 gboolean found = TRUE; |
9 | 1819 |
1820 needle = sd->search_keyword_list; | |
1821 while (needle && found) | |
1822 { | |
1823 found = FALSE; | |
1824 haystack = list; | |
1825 while (haystack && !found) | |
1826 { | |
1307 | 1827 found = (g_ascii_strcasecmp((gchar *)needle->data, |
9 | 1828 (gchar *)haystack->data) == 0); |
1829 haystack = haystack->next; | |
1830 } | |
1831 needle = needle->next; | |
1832 } | |
1833 | |
1834 match = found; | |
1835 } | |
1836 else if (sd->match_keywords == SEARCH_MATCH_ANY) | |
1837 { | |
1437 | 1838 gboolean found = FALSE; |
9 | 1839 |
1840 needle = sd->search_keyword_list; | |
1841 while (needle && !found) | |
1842 { | |
1843 haystack = list; | |
1844 while (haystack && !found) | |
1845 { | |
1307 | 1846 found = (g_ascii_strcasecmp((gchar *)needle->data, |
9 | 1847 (gchar *)haystack->data) == 0); |
1848 haystack = haystack->next; | |
1849 } | |
1850 needle = needle->next; | |
1851 } | |
1852 | |
1853 match = found; | |
1854 } | |
1855 else if (sd->match_keywords == SEARCH_MATCH_NONE) | |
1856 { | |
1437 | 1857 gboolean found = FALSE; |
9 | 1858 |
1859 needle = sd->search_keyword_list; | |
1860 while (needle && !found) | |
1861 { | |
1862 haystack = list; | |
1863 while (haystack && !found) | |
1864 { | |
1307 | 1865 found = (g_ascii_strcasecmp((gchar *)needle->data, |
9 | 1866 (gchar *)haystack->data) == 0); |
1867 haystack = haystack->next; | |
1868 } | |
1869 needle = needle->next; | |
1870 } | |
1871 | |
1872 match = !found; | |
1873 } | |
138 | 1874 string_list_free(list); |
9 | 1875 } |
1876 else | |
1877 { | |
1073
577d726e32f0
Fix a cut and paste error when implementing the comment search (Klaus
nadvornik
parents:
1057
diff
changeset
|
1878 match = (sd->match_keywords == SEARCH_MATCH_NONE); |
1057
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 } |
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 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
|
1883 { |
c28eb027dd5b
Implement the search for image comment - patch by Klaus Ethgen
nadvornik
parents:
1055
diff
changeset
|
1884 gchar *comment; |
c28eb027dd5b
Implement the search for image comment - patch by Klaus Ethgen
nadvornik
parents:
1055
diff
changeset
|
1885 |
c28eb027dd5b
Implement the search for image comment - patch by Klaus Ethgen
nadvornik
parents:
1055
diff
changeset
|
1886 tested = TRUE; |
c28eb027dd5b
Implement the search for image comment - patch by Klaus Ethgen
nadvornik
parents:
1055
diff
changeset
|
1887 match = FALSE; |
c28eb027dd5b
Implement the search for image comment - patch by Klaus Ethgen
nadvornik
parents:
1055
diff
changeset
|
1888 |
1288 | 1889 comment = metadata_read_string(fd, COMMENT_KEY, METADATA_PLAIN); |
1238
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1211
diff
changeset
|
1890 |
947e603a52c6
simplified metadata interface, dropped metadata_read,
nadvornik
parents:
1211
diff
changeset
|
1891 if (comment) |
1057
c28eb027dd5b
Implement the search for image comment - patch by Klaus Ethgen
nadvornik
parents:
1055
diff
changeset
|
1892 { |
1444 | 1893 if (!sd->search_comment_match_case) |
1057
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 gchar *tmp = g_utf8_strdown(comment, -1); |
c28eb027dd5b
Implement the search for image comment - patch by Klaus Ethgen
nadvornik
parents:
1055
diff
changeset
|
1896 g_free(comment); |
c28eb027dd5b
Implement the search for image comment - patch by Klaus Ethgen
nadvornik
parents:
1055
diff
changeset
|
1897 comment = tmp; |
c28eb027dd5b
Implement the search for image comment - patch by Klaus Ethgen
nadvornik
parents:
1055
diff
changeset
|
1898 } |
c28eb027dd5b
Implement the search for image comment - patch by Klaus Ethgen
nadvornik
parents:
1055
diff
changeset
|
1899 |
c28eb027dd5b
Implement the search for image comment - patch by Klaus Ethgen
nadvornik
parents:
1055
diff
changeset
|
1900 if (sd->match_comment == SEARCH_MATCH_CONTAINS) |
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 else if (sd->match_comment == SEARCH_MATCH_NONE) |
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 match = (strstr(comment, sd->search_comment) == NULL); |
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 g_free(comment); |
c28eb027dd5b
Implement the search for image comment - patch by Klaus Ethgen
nadvornik
parents:
1055
diff
changeset
|
1909 } |
c28eb027dd5b
Implement the search for image comment - patch by Klaus Ethgen
nadvornik
parents:
1055
diff
changeset
|
1910 else |
c28eb027dd5b
Implement the search for image comment - patch by Klaus Ethgen
nadvornik
parents:
1055
diff
changeset
|
1911 { |
c28eb027dd5b
Implement the search for image comment - patch by Klaus Ethgen
nadvornik
parents:
1055
diff
changeset
|
1912 match = (sd->match_comment == SEARCH_MATCH_NONE); |
9 | 1913 } |
1914 } | |
1915 | |
1916 if ((match || extra_only) && | |
1917 (sd->match_dimensions_enable || sd->match_similarity_enable)) | |
1918 { | |
1919 tested = TRUE; | |
1920 | |
1921 if (search_file_do_extra(sd, fd, &match, &width, &height, &sim)) | |
1922 { | |
1923 sd->search_buffer_count += SEARCH_BUFFER_MATCH_LOAD; | |
1924 return TRUE; | |
1925 } | |
1926 } | |
1927 | |
1928 sd->search_file_list = g_list_remove(sd->search_file_list, fd); | |
1929 | |
1930 if (tested && match) | |
1931 { | |
1932 MatchFileData *mfd; | |
1933 | |
1934 mfd = g_new(MatchFileData, 1); | |
138 | 1935 mfd->fd = fd; |
9 | 1936 |
1937 mfd->width = width; | |
1938 mfd->height = height; | |
1939 mfd->rank = sim; | |
1940 | |
1941 sd->search_buffer_list = g_list_prepend(sd->search_buffer_list, mfd); | |
1942 sd->search_buffer_count += SEARCH_BUFFER_MATCH_HIT; | |
1943 sd->search_count++; | |
1944 search_progress_update(sd, TRUE, -1.0); | |
1945 } | |
1946 else | |
1947 { | |
138 | 1948 file_data_unref(fd); |
9 | 1949 sd->search_buffer_count += SEARCH_BUFFER_MATCH_MISS; |
1950 } | |
1951 | |
1952 return FALSE; | |
1953 } | |
1954 | |
1444 | 1955 static gboolean search_step_cb(gpointer data) |
9 | 1956 { |
1957 SearchData *sd = data; | |
1958 FileData *fd; | |
1959 | |
1960 if (sd->search_buffer_count > SEARCH_BUFFER_FLUSH_SIZE) | |
1961 { | |
1962 search_buffer_flush(sd); | |
1963 search_progress_update(sd, TRUE, -1.0); | |
1964 } | |
1965 | |
1966 if (sd->search_file_list) | |
1967 { | |
1968 if (search_file_next(sd)) | |
1969 { | |
1523 | 1970 sd->search_idle_id = 0; |
9 | 1971 return FALSE; |
1972 } | |
1973 return TRUE; | |
1974 } | |
1975 | |
1976 if (!sd->search_file_list && !sd->search_folder_list) | |
1977 { | |
1523 | 1978 sd->search_idle_id = 0; |
9 | 1979 |
1980 search_stop(sd); | |
1981 search_result_thumb_step(sd); | |
1982 | |
1983 return FALSE; | |
1984 } | |
1985 | |
1986 fd = sd->search_folder_list->data; | |
1987 | |
1988 if (g_list_find(sd->search_done_list, fd) == NULL) | |
1989 { | |
1990 GList *list = NULL; | |
1991 GList *dlist = NULL; | |
1437 | 1992 gboolean success = FALSE; |
9 | 1993 |
1994 sd->search_done_list = g_list_prepend(sd->search_done_list, fd); | |
1995 | |
1996 if (sd->search_type == SEARCH_MATCH_NONE) | |
1997 { | |
783 | 1998 success = filelist_read(fd, &list, &dlist); |
9 | 1999 } |
2000 else if (sd->search_type == SEARCH_MATCH_ALL && | |
783 | 2001 sd->search_dir_fd && |
2002 strlen(fd->path) >= strlen(sd->search_dir_fd->path)) | |
9 | 2003 { |
2004 const gchar *path; | |
2005 | |
783 | 2006 path = fd->path + strlen(sd->search_dir_fd->path); |
2007 if (path != fd->path) | |
2008 { | |
2009 FileData *dir_fd = file_data_new_simple(path); | |
2010 success = filelist_read(dir_fd, &list, NULL); | |
2011 file_data_unref(dir_fd); | |
2012 } | |
2013 success |= filelist_read(fd, NULL, &dlist); | |
9 | 2014 if (success) |
2015 { | |
2016 GList *work; | |
2017 | |
2018 work = list; | |
2019 while (work) | |
2020 { | |
2021 FileData *fdp; | |
2022 GList *link; | |
2023 gchar *meta_path; | |
2024 | |
2025 fdp = work->data; | |
2026 link = work; | |
2027 work = work->next; | |
2028 | |
2029 meta_path = cache_find_location(CACHE_TYPE_METADATA, fdp->path); | |
2030 if (!meta_path) | |
2031 { | |
2032 list = g_list_delete_link(list, link); | |
138 | 2033 file_data_unref(fdp); |
9 | 2034 } |
2035 g_free(meta_path); | |
2036 } | |
2037 } | |
2038 } | |
2039 | |
2040 if (success) | |
2041 { | |
2042 list = filelist_sort(list, SORT_NAME, TRUE); | |
2043 sd->search_file_list = list; | |
2044 | |
2045 if (sd->search_path_recurse) | |
2046 { | |
2047 dlist = filelist_sort(dlist, SORT_NAME, TRUE); | |
2048 sd->search_folder_list = g_list_concat(dlist, sd->search_folder_list); | |
2049 } | |
2050 else | |
2051 { | |
2052 filelist_free(dlist); | |
2053 } | |
2054 } | |
2055 } | |
2056 else | |
2057 { | |
2058 sd->search_folder_list = g_list_remove(sd->search_folder_list, fd); | |
2059 sd->search_done_list = g_list_remove(sd->search_done_list, fd); | |
138 | 2060 file_data_unref(fd); |
9 | 2061 } |
2062 | |
2063 return TRUE; | |
2064 } | |
2065 | |
2066 static void search_similarity_load_done_cb(ImageLoader *il, gpointer data) | |
2067 { | |
2068 SearchData *sd = data; | |
2069 search_file_load_process(sd, sd->search_similarity_cd); | |
2070 } | |
2071 | |
2072 static void search_start(SearchData *sd) | |
2073 { | |
2074 search_stop(sd); | |
2075 search_result_clear(sd); | |
2076 | |
783 | 2077 if (sd->search_dir_fd) |
9 | 2078 { |
909 | 2079 sd->search_folder_list = g_list_prepend(sd->search_folder_list, file_data_ref(sd->search_dir_fd)); |
9 | 2080 } |
2081 | |
2082 if (!sd->search_name_match_case) | |
2083 { | |
2084 /* convert to lowercase here, so that this is only done once per search */ | |
2085 gchar *tmp = g_utf8_strdown(sd->search_name, -1); | |
2086 g_free(sd->search_name); | |
2087 sd->search_name = tmp; | |
2088 } | |
2089 | |
1057
c28eb027dd5b
Implement the search for image comment - patch by Klaus Ethgen
nadvornik
parents:
1055
diff
changeset
|
2090 if (!sd->search_comment_match_case) |
c28eb027dd5b
Implement the search for image comment - patch by Klaus Ethgen
nadvornik
parents:
1055
diff
changeset
|
2091 { |
c28eb027dd5b
Implement the search for image comment - patch by Klaus Ethgen
nadvornik
parents:
1055
diff
changeset
|
2092 /* 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
|
2093 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
|
2094 g_free(sd->search_comment); |
c28eb027dd5b
Implement the search for image comment - patch by Klaus Ethgen
nadvornik
parents:
1055
diff
changeset
|
2095 sd->search_comment = tmp; |
c28eb027dd5b
Implement the search for image comment - patch by Klaus Ethgen
nadvornik
parents:
1055
diff
changeset
|
2096 } |
c28eb027dd5b
Implement the search for image comment - patch by Klaus Ethgen
nadvornik
parents:
1055
diff
changeset
|
2097 |
9 | 2098 sd->search_count = 0; |
2099 sd->search_total = 0; | |
2100 | |
2101 gtk_widget_set_sensitive(sd->box_search, FALSE); | |
2102 spinner_set_interval(sd->spinner, SPINNER_SPEED); | |
2103 gtk_widget_set_sensitive(sd->button_start, FALSE); | |
2104 gtk_widget_set_sensitive(sd->button_stop, TRUE); | |
2105 search_progress_update(sd, TRUE, -1.0); | |
2106 | |
2107 if (sd->match_similarity_enable && | |
2108 !sd->search_similarity_cd && | |
2109 isfile(sd->search_similarity_path)) | |
2110 { | |
2111 gchar *cd_path; | |
2112 | |
2113 cd_path = cache_find_location(CACHE_TYPE_SIM, sd->search_similarity_path); | |
2114 if (cd_path && filetime(sd->search_similarity_path) == filetime(cd_path)) | |
2115 { | |
2116 sd->search_similarity_cd = cache_sim_data_load(cd_path); | |
2117 } | |
2118 g_free(cd_path); | |
2119 | |
2120 if (!sd->search_similarity_cd || !sd->search_similarity_cd->similarity) | |
2121 { | |
2122 if (!sd->search_similarity_cd) | |
2123 { | |
2124 sd->search_similarity_cd = cache_sim_data_new(); | |
2125 } | |
2126 | |
138 | 2127 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
|
2128 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
|
2129 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
|
2130 if (image_loader_start(sd->img_loader)) |
9 | 2131 { |
2132 return; | |
2133 } | |
2134 image_loader_free(sd->img_loader); | |
2135 sd->img_loader = NULL; | |
2136 } | |
442 | 2137 |
9 | 2138 } |
2139 | |
2140 sd->search_idle_id = g_idle_add(search_step_cb, sd); | |
2141 } | |
2142 | |
2143 static void search_start_cb(GtkWidget *widget, gpointer data) | |
2144 { | |
2145 SearchData *sd = data; | |
2146 GtkTreeViewColumn *column; | |
2147 gchar *path; | |
2148 | |
2149 if (sd->search_folder_list) | |
2150 { | |
2151 search_stop(sd); | |
2152 search_result_thumb_step(sd); | |
2153 return; | |
2154 } | |
2155 | |
2156 if (sd->match_name_enable) history_combo_append_history(sd->entry_name, NULL); | |
2157 g_free(sd->search_name); | |
2158 sd->search_name = g_strdup(gtk_entry_get_text(GTK_ENTRY(sd->entry_name))); | |
2159 | |
1057
c28eb027dd5b
Implement the search for image comment - patch by Klaus Ethgen
nadvornik
parents:
1055
diff
changeset
|
2160 /* XXX */ |
c28eb027dd5b
Implement the search for image comment - patch by Klaus Ethgen
nadvornik
parents:
1055
diff
changeset
|
2161 g_free(sd->search_comment); |
c28eb027dd5b
Implement the search for image comment - patch by Klaus Ethgen
nadvornik
parents:
1055
diff
changeset
|
2162 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
|
2163 |
9 | 2164 g_free(sd->search_similarity_path); |
2165 sd->search_similarity_path = g_strdup(gtk_entry_get_text(GTK_ENTRY(sd->entry_similarity))); | |
2166 if (sd->match_similarity_enable) | |
2167 { | |
2168 if (!isfile(sd->search_similarity_path)) | |
2169 { | |
2170 file_util_warning_dialog(_("File not found"), | |
2171 _("Please enter an existing file for image content."), | |
2172 GTK_STOCK_DIALOG_WARNING, sd->window); | |
2173 return; | |
2174 } | |
2175 tab_completion_append_to_history(sd->entry_similarity, sd->search_similarity_path); | |
2176 } | |
2177 | |
138 | 2178 string_list_free(sd->search_keyword_list); |
9 | 2179 sd->search_keyword_list = keyword_list_pull(sd->entry_keywords); |
2180 | |
2181 date_selection_get(sd->date_sel, &sd->search_date_d, &sd->search_date_m, &sd->search_date_y); | |
2182 date_selection_get(sd->date_sel_end, &sd->search_date_end_d, &sd->search_date_end_m, &sd->search_date_end_y); | |
2183 | |
608
be8b2516359d
In the search results view, hide dimensions column instead of
zas_
parents:
607
diff
changeset
|
2184 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
|
2185 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
|
2186 |
9 | 2187 column = gtk_tree_view_get_column(GTK_TREE_VIEW(sd->result_view), SEARCH_COLUMN_RANK - 1); |
2188 gtk_tree_view_column_set_visible(column, sd->match_similarity_enable); | |
2189 if (!sd->match_similarity_enable) | |
2190 { | |
2191 GtkTreeSortable *sortable; | |
2192 gint id; | |
2193 GtkSortType order; | |
2194 | |
2195 sortable = GTK_TREE_SORTABLE(gtk_tree_view_get_model(GTK_TREE_VIEW(sd->result_view))); | |
2196 if (gtk_tree_sortable_get_sort_column_id(sortable, &id, &order) && | |
2197 id == SEARCH_COLUMN_RANK) | |
2198 { | |
2199 gtk_tree_sortable_set_sort_column_id(sortable, SEARCH_COLUMN_PATH, GTK_SORT_ASCENDING); | |
2200 } | |
2201 } | |
2202 | |
2203 if (sd->search_type == SEARCH_MATCH_NONE) | |
2204 { | |
2205 /* search path */ | |
2206 | |
2207 path = remove_trailing_slash(gtk_entry_get_text(GTK_ENTRY(sd->path_entry))); | |
2208 if (isdir(path)) | |
2209 { | |
783 | 2210 file_data_unref(sd->search_dir_fd); |
2211 sd->search_dir_fd = file_data_new_simple(path); | |
2212 | |
2213 tab_completion_append_to_history(sd->path_entry, sd->search_dir_fd->path); | |
9 | 2214 |
2215 search_start(sd); | |
2216 } | |
2217 else | |
2218 { | |
2219 file_util_warning_dialog(_("Folder not found"), | |
2220 _("Please enter an existing folder to search."), | |
2221 GTK_STOCK_DIALOG_WARNING, sd->window); | |
2222 } | |
2223 | |
2224 g_free(path); | |
2225 } | |
2226 else if (sd->search_type == SEARCH_MATCH_ALL) | |
2227 { | |
2228 /* search metadata */ | |
783 | 2229 file_data_unref(sd->search_dir_fd); |
1145
3a7af6a8cd5f
Use functions to return directories instead of constants.
zas_
parents:
1073
diff
changeset
|
2230 sd->search_dir_fd = file_data_new_simple(get_metadata_cache_dir()); |
9 | 2231 search_start(sd); |
2232 } | |
2233 else if (sd->search_type == SEARCH_MATCH_CONTAINS) | |
2234 { | |
2235 /* search current result list */ | |
2236 GList *list; | |
2237 | |
2238 list = search_result_refine_list(sd); | |
2239 | |
783 | 2240 file_data_unref(sd->search_dir_fd); |
2241 sd->search_dir_fd = NULL; | |
9 | 2242 |
2243 search_start(sd); | |
2244 | |
2245 sd->search_file_list = g_list_concat(sd->search_file_list, list); | |
2246 } | |
2247 } | |
2248 | |
2249 /* | |
2250 *------------------------------------------------------------------- | |
2251 * window construct | |
2252 *------------------------------------------------------------------- | |
2253 */ | |
2254 | |
2255 enum { | |
2256 MENU_CHOICE_COLUMN_NAME = 0, | |
2257 MENU_CHOICE_COLUMN_VALUE | |
2258 }; | |
2259 | |
2260 static void search_thumb_toggle_cb(GtkWidget *button, gpointer data) | |
2261 { | |
2262 SearchData *sd = data; | |
2263 | |
2264 search_result_thumb_enable(sd, gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button))); | |
2265 } | |
2266 | |
2267 static gint sort_matchdata_dimensions(MatchFileData *a, MatchFileData *b) | |
2268 { | |
2269 gint sa; | |
2270 gint sb; | |
2271 | |
2272 sa = a->width * a->height; | |
2273 sb = b->width * b->height; | |
2274 | |
2275 if (sa > sb) return 1; | |
2276 if (sa < sb) return -1; | |
2277 return 0; | |
2278 } | |
2279 | |
2280 static gint search_result_sort_cb(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer data) | |
2281 { | |
2282 gint n = GPOINTER_TO_INT(data); | |
138 | 2283 MatchFileData *fda; |
2284 MatchFileData *fdb; | |
9 | 2285 |
2286 gtk_tree_model_get(model, a, SEARCH_COLUMN_POINTER, &fda, -1); | |
2287 gtk_tree_model_get(model, b, SEARCH_COLUMN_POINTER, &fdb, -1); | |
2288 | |
2289 if (!fda || !fdb) return 0; | |
2290 | |
2291 switch (n) | |
2292 { | |
2293 case SEARCH_COLUMN_RANK: | |
138 | 2294 if (((MatchFileData *)fda)->rank > (fdb)->rank) return 1; |
2295 if (((MatchFileData *)fda)->rank < (fdb)->rank) return -1; | |
9 | 2296 return 0; |
2297 break; | |
2298 case SEARCH_COLUMN_NAME: | |
785 | 2299 if (options->file_sort.case_sensitive) |
2300 return strcmp(fda->fd->collate_key_name, fdb->fd->collate_key_name); | |
2301 else | |
2302 return strcmp(fda->fd->collate_key_name_nocase, fdb->fd->collate_key_name_nocase); | |
9 | 2303 break; |
2304 case SEARCH_COLUMN_SIZE: | |
138 | 2305 if (fda->fd->size > fdb->fd->size) return 1; |
2306 if (fda->fd->size < fdb->fd->size) return -1; | |
9 | 2307 return 0; |
2308 break; | |
2309 case SEARCH_COLUMN_DATE: | |
138 | 2310 if (fda->fd->date > fdb->fd->date) return 1; |
2311 if (fda->fd->date < fdb->fd->date) return -1; | |
9 | 2312 return 0; |
2313 break; | |
2314 case SEARCH_COLUMN_DIMENSIONS: | |
138 | 2315 return sort_matchdata_dimensions(fda, fdb); |
9 | 2316 break; |
2317 case SEARCH_COLUMN_PATH: | |
786
a20ff446347e
Compare paths using utf8_collate_key() since paths are utf8-encoded.
zas_
parents:
785
diff
changeset
|
2318 return utf8_compare(fda->fd->path, fdb->fd->path, options->file_sort.case_sensitive); |
9 | 2319 break; |
2320 default: | |
2321 break; | |
2322 } | |
2323 | |
2324 return 0; | |
2325 } | |
2326 | |
1444 | 2327 static void search_result_add_column(SearchData * sd, gint n, const gchar *title, gboolean image, gboolean right_justify) |
9 | 2328 { |
2329 GtkTreeViewColumn *column; | |
2330 GtkCellRenderer *renderer; | |
2331 | |
2332 column = gtk_tree_view_column_new(); | |
2333 gtk_tree_view_column_set_title(column, title); | |
2334 gtk_tree_view_column_set_min_width(column, 4); | |
2335 | |
2336 if (n != SEARCH_COLUMN_THUMB) gtk_tree_view_column_set_resizable(column, TRUE); | |
2337 | |
2338 if (!image) | |
2339 { | |
2340 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_GROW_ONLY); | |
2341 renderer = gtk_cell_renderer_text_new(); | |
2342 if (right_justify) g_object_set(G_OBJECT(renderer), "xalign", 1.0, NULL); | |
2343 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
2344 gtk_tree_view_column_add_attribute(column, renderer, "text", n); | |
2345 | |
2346 gtk_tree_view_column_set_sort_column_id(column, n); | |
2347 } | |
2348 else | |
2349 { | |
2350 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED); | |
2351 renderer = gtk_cell_renderer_pixbuf_new(); | |
2352 cell_renderer_height_override(renderer); | |
2353 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
2354 gtk_tree_view_column_add_attribute(column, renderer, "pixbuf", n); | |
2355 } | |
2356 | |
2357 gtk_tree_view_append_column(GTK_TREE_VIEW(sd->result_view), column); | |
2358 } | |
2359 | |
1444 | 2360 static void menu_choice_set_visible(GtkWidget *widget, gboolean visible) |
9 | 2361 { |
2362 if (visible) | |
2363 { | |
2364 if (!GTK_WIDGET_VISIBLE(widget)) gtk_widget_show(widget); | |
2365 } | |
2366 else | |
2367 { | |
2368 if (GTK_WIDGET_VISIBLE(widget)) gtk_widget_hide(widget); | |
2369 } | |
2370 } | |
2371 | |
889
cb3b6238782a
Reduce code redundancy by moving common code to new menu_choice_get_match_type().
zas_
parents:
845
diff
changeset
|
2372 static gboolean menu_choice_get_match_type(GtkWidget *combo, MatchType *type) |
9 | 2373 { |
2374 GtkTreeModel *store; | |
2375 GtkTreeIter iter; | |
2376 | |
2377 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
|
2378 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
|
2379 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
|
2380 return TRUE; |
cb3b6238782a
Reduce code redundancy by moving common code to new menu_choice_get_match_type().
zas_
parents:
845
diff
changeset
|
2381 } |
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 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
|
2384 { |
cb3b6238782a
Reduce code redundancy by moving common code to new menu_choice_get_match_type().
zas_
parents:
845
diff
changeset
|
2385 SearchData *sd = data; |
cb3b6238782a
Reduce code redundancy by moving common code to new menu_choice_get_match_type().
zas_
parents:
845
diff
changeset
|
2386 |
cb3b6238782a
Reduce code redundancy by moving common code to new menu_choice_get_match_type().
zas_
parents:
845
diff
changeset
|
2387 if (!menu_choice_get_match_type(combo, &sd->search_type)) return; |
9 | 2388 |
2389 menu_choice_set_visible(gtk_widget_get_parent(sd->check_recurse), | |
2390 (sd->search_type == SEARCH_MATCH_NONE)); | |
2391 } | |
2392 | |
2393 static void menu_choice_name_cb(GtkWidget *combo, gpointer data) | |
2394 { | |
2395 SearchData *sd = data; | |
889
cb3b6238782a
Reduce code redundancy by moving common code to new menu_choice_get_match_type().
zas_
parents:
845
diff
changeset
|
2396 |
cb3b6238782a
Reduce code redundancy by moving common code to new menu_choice_get_match_type().
zas_
parents:
845
diff
changeset
|
2397 if (!menu_choice_get_match_type(combo, &sd->match_name)) return; |
9 | 2398 } |
2399 | |
2400 static void menu_choice_size_cb(GtkWidget *combo, gpointer data) | |
2401 { | |
2402 SearchData *sd = data; | |
889
cb3b6238782a
Reduce code redundancy by moving common code to new menu_choice_get_match_type().
zas_
parents:
845
diff
changeset
|
2403 |
cb3b6238782a
Reduce code redundancy by moving common code to new menu_choice_get_match_type().
zas_
parents:
845
diff
changeset
|
2404 if (!menu_choice_get_match_type(combo, &sd->match_size)) return; |
9 | 2405 |
2406 menu_choice_set_visible(gtk_widget_get_parent(sd->spin_size_end), | |
2407 (sd->match_size == SEARCH_MATCH_BETWEEN)); | |
2408 } | |
2409 | |
2410 static void menu_choice_date_cb(GtkWidget *combo, gpointer data) | |
2411 { | |
2412 SearchData *sd = data; | |
889
cb3b6238782a
Reduce code redundancy by moving common code to new menu_choice_get_match_type().
zas_
parents:
845
diff
changeset
|
2413 |
cb3b6238782a
Reduce code redundancy by moving common code to new menu_choice_get_match_type().
zas_
parents:
845
diff
changeset
|
2414 if (!menu_choice_get_match_type(combo, &sd->match_date)) return; |
9 | 2415 |
2416 menu_choice_set_visible(gtk_widget_get_parent(sd->date_sel_end), | |
2417 (sd->match_date == SEARCH_MATCH_BETWEEN)); | |
2418 } | |
2419 | |
2420 static void menu_choice_dimensions_cb(GtkWidget *combo, gpointer data) | |
2421 { | |
2422 SearchData *sd = data; | |
889
cb3b6238782a
Reduce code redundancy by moving common code to new menu_choice_get_match_type().
zas_
parents:
845
diff
changeset
|
2423 |
cb3b6238782a
Reduce code redundancy by moving common code to new menu_choice_get_match_type().
zas_
parents:
845
diff
changeset
|
2424 if (!menu_choice_get_match_type(combo, &sd->match_dimensions)) return; |
9 | 2425 |
2426 menu_choice_set_visible(gtk_widget_get_parent(sd->spin_width_end), | |
2427 (sd->match_dimensions == SEARCH_MATCH_BETWEEN)); | |
2428 } | |
2429 | |
2430 static void menu_choice_keyword_cb(GtkWidget *combo, gpointer data) | |
2431 { | |
2432 SearchData *sd = data; | |
889
cb3b6238782a
Reduce code redundancy by moving common code to new menu_choice_get_match_type().
zas_
parents:
845
diff
changeset
|
2433 |
cb3b6238782a
Reduce code redundancy by moving common code to new menu_choice_get_match_type().
zas_
parents:
845
diff
changeset
|
2434 if (!menu_choice_get_match_type(combo, &sd->match_keywords)) return; |
9 | 2435 } |
2436 | |
1057
c28eb027dd5b
Implement the search for image comment - patch by Klaus Ethgen
nadvornik
parents:
1055
diff
changeset
|
2437 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
|
2438 { |
c28eb027dd5b
Implement the search for image comment - patch by Klaus Ethgen
nadvornik
parents:
1055
diff
changeset
|
2439 SearchData *sd = data; |
c28eb027dd5b
Implement the search for image comment - patch by Klaus Ethgen
nadvornik
parents:
1055
diff
changeset
|
2440 |
c28eb027dd5b
Implement the search for image comment - patch by Klaus Ethgen
nadvornik
parents:
1055
diff
changeset
|
2441 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
|
2442 } |
c28eb027dd5b
Implement the search for image comment - patch by Klaus Ethgen
nadvornik
parents:
1055
diff
changeset
|
2443 |
9 | 2444 static void menu_choice_spin_cb(GtkAdjustment *adjustment, gpointer data) |
2445 { | |
2446 gint *value = data; | |
2447 | |
2448 *value = (gint)gtk_adjustment_get_value(adjustment); | |
2449 } | |
2450 | |
2451 static GtkWidget *menu_spin(GtkWidget *box, gdouble min, gdouble max, gint value, | |
2452 GCallback func, gpointer data) | |
2453 { | |
2454 GtkWidget *spin; | |
2455 GtkAdjustment *adj; | |
2456 | |
2457 spin = gtk_spin_button_new_with_range(min, max, 1); | |
2458 gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin), (gdouble)value); | |
2459 adj = gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(spin)); | |
2460 if (func) g_signal_connect(G_OBJECT(adj), "value_changed", | |
2461 G_CALLBACK(func), data); | |
2462 gtk_box_pack_start(GTK_BOX(box), spin, FALSE, FALSE, 0); | |
2463 gtk_widget_show(spin); | |
2464 | |
2465 return spin; | |
2466 } | |
2467 | |
2468 static void menu_choice_check_cb(GtkWidget *button, gpointer data) | |
2469 { | |
2470 GtkWidget *widget = data; | |
2471 gboolean active; | |
2472 gboolean *value; | |
2473 | |
2474 active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)); | |
2475 gtk_widget_set_sensitive(widget, active); | |
2476 | |
2477 value = g_object_get_data(G_OBJECT(button), "check_var"); | |
2478 if (value) *value = active; | |
2479 } | |
2480 | |
2481 static GtkWidget *menu_choice_menu(const MatchList *items, gint item_count, | |
2482 GCallback func, gpointer data) | |
2483 { | |
2484 GtkWidget *combo; | |
2485 GtkCellRenderer *renderer; | |
2486 GtkListStore *store; | |
2487 gint i; | |
2488 | |
2489 store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INT); | |
2490 combo = gtk_combo_box_new_with_model(GTK_TREE_MODEL(store)); | |
2491 g_object_unref(store); | |
2492 | |
2493 renderer = gtk_cell_renderer_text_new(); | |
2494 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), renderer, TRUE); | |
2495 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), renderer, | |
2496 "text", MENU_CHOICE_COLUMN_NAME, NULL); | |
2497 | |
2498 for (i = 0; i < item_count; i++) | |
2499 { | |
2500 GtkTreeIter iter; | |
2501 | |
2502 gtk_list_store_append(store, &iter); | |
2503 gtk_list_store_set(store, &iter, MENU_CHOICE_COLUMN_NAME, _(items[i].text), | |
2504 MENU_CHOICE_COLUMN_VALUE, items[i].type, -1); | |
2505 } | |
2506 | |
2507 gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0); | |
2508 | |
2509 if (func) g_signal_connect(G_OBJECT(combo), "changed", | |
2510 G_CALLBACK(func), data); | |
2511 | |
2512 return combo; | |
2513 } | |
2514 | |
2515 static GtkWidget *menu_choice(GtkWidget *box, GtkWidget **check, GtkWidget **menu, | |
2516 const gchar *text, gboolean *value, | |
2517 const MatchList *items, gint item_count, | |
2518 GCallback func, gpointer data) | |
2519 { | |
2520 GtkWidget *base_box; | |
2521 GtkWidget *hbox; | |
2522 GtkWidget *button; | |
2523 GtkWidget *option; | |
2524 | |
2525 base_box = gtk_hbox_new(FALSE, PREF_PAD_GAP); | |
2526 gtk_box_pack_start(GTK_BOX(box), base_box, FALSE, FALSE, 0); | |
2527 gtk_widget_show(base_box); | |
2528 | |
2529 button = gtk_check_button_new(); | |
2530 if (value) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), *value); | |
2531 gtk_box_pack_start(GTK_BOX(base_box), button, FALSE, FALSE, 0); | |
2532 gtk_widget_show(button); | |
2533 if (check) *check = button; | |
2534 if (value) g_object_set_data(G_OBJECT(button), "check_var", value); | |
2535 | |
2536 hbox = gtk_hbox_new(FALSE, PREF_PAD_SPACE); | |
2537 gtk_box_pack_start(GTK_BOX(base_box), hbox, TRUE, TRUE, 0); | |
2538 gtk_widget_show(hbox); | |
2539 | |
2540 g_signal_connect(G_OBJECT(button), "toggled", | |
2541 G_CALLBACK(menu_choice_check_cb), hbox); | |
2542 gtk_widget_set_sensitive(hbox, (value) ? *value : FALSE); | |
2543 | |
2544 pref_label_new(hbox, text); | |
2545 | |
2546 if (!items && !menu) return hbox; | |
2547 | |
2548 option = menu_choice_menu(items, item_count, func, data); | |
2549 gtk_box_pack_start(GTK_BOX(hbox), option, FALSE, FALSE, 0); | |
2550 gtk_widget_show(option); | |
2551 if (menu) *menu = option; | |
2552 | |
2553 return hbox; | |
2554 } | |
2555 | |
2556 static void search_window_close(SearchData *sd) | |
2557 { | |
2558 gtk_widget_destroy(sd->window); | |
2559 } | |
2560 | |
1444 | 2561 static gboolean search_window_delete_cb(GtkWidget *widget, GdkEventAny *event, gpointer data) |
9 | 2562 { |
2563 SearchData *sd = data; | |
2564 | |
2565 search_window_close(sd); | |
2566 return TRUE; | |
2567 } | |
2568 | |
2569 static void search_window_destroy_cb(GtkWidget *widget, gpointer data) | |
2570 { | |
2571 SearchData *sd = data; | |
2572 | |
2573 search_window_list = g_list_remove(search_window_list, sd); | |
2574 | |
2575 search_result_update_idle_cancel(sd); | |
2576 | |
2577 filelist_free(sd->search_buffer_list); | |
2578 sd->search_buffer_list = NULL; | |
2579 | |
2580 search_stop(sd); | |
2581 search_result_clear(sd); | |
2582 | |
783 | 2583 file_data_unref(sd->search_dir_fd); |
2584 | |
9 | 2585 g_free(sd->search_name); |
1057
c28eb027dd5b
Implement the search for image comment - patch by Klaus Ethgen
nadvornik
parents:
1055
diff
changeset
|
2586 g_free(sd->search_comment); |
9 | 2587 g_free(sd->search_similarity_path); |
138 | 2588 string_list_free(sd->search_keyword_list); |
9 | 2589 |
795 | 2590 file_data_unregister_notify_func(search_notify_cb, sd); |
2591 | |
9 | 2592 g_free(sd); |
2593 } | |
2594 | |
783 | 2595 void search_new(FileData *dir_fd, FileData *example_file) |
9 | 2596 { |
2597 SearchData *sd; | |
2598 GtkWidget *vbox; | |
2599 GtkWidget *hbox; | |
2600 GtkWidget *hbox2; | |
2601 GtkWidget *pad_box; | |
2602 GtkWidget *frame; | |
2603 GtkWidget *scrolled; | |
2604 GtkListStore *store; | |
2605 GtkTreeSortable *sortable; | |
2606 GtkTreeSelection *selection; | |
2607 GtkWidget *combo; | |
2608 GdkGeometry geometry; | |
2609 | |
2610 sd = g_new0(SearchData, 1); | |
2611 | |
783 | 2612 sd->search_dir_fd = file_data_ref(dir_fd); |
9 | 2613 sd->search_path_recurse = TRUE; |
2614 sd->search_size = 0; | |
2615 sd->search_width = 640; | |
2616 sd->search_height = 480; | |
2617 sd->search_width_end = 1024; | |
2618 sd->search_height_end = 768; | |
2619 | |
2620 sd->search_type = SEARCH_MATCH_NONE; | |
2621 | |
2622 sd->match_name = SEARCH_MATCH_CONTAINS; | |
2623 sd->match_size = SEARCH_MATCH_EQUAL; | |
2624 sd->match_date = SEARCH_MATCH_EQUAL; | |
2625 sd->match_dimensions = SEARCH_MATCH_EQUAL; | |
2626 sd->match_keywords = SEARCH_MATCH_ALL; | |
1057
c28eb027dd5b
Implement the search for image comment - patch by Klaus Ethgen
nadvornik
parents:
1055
diff
changeset
|
2627 sd->match_comment = SEARCH_MATCH_CONTAINS; |
9 | 2628 |
2629 sd->match_name_enable = TRUE; | |
2630 | |
2631 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
|
2632 |
fe4da037be21
When g_new0() is used, drop redundant initializations to NULL, FALSE or 0, second pass.
zas_
parents:
1347
diff
changeset
|
2633 if (example_file) |
fe4da037be21
When g_new0() is used, drop redundant initializations to NULL, FALSE or 0, second pass.
zas_
parents:
1347
diff
changeset
|
2634 { |
fe4da037be21
When g_new0() is used, drop redundant initializations to NULL, FALSE or 0, second pass.
zas_
parents:
1347
diff
changeset
|
2635 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
|
2636 } |
9 | 2637 |
289
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
288
diff
changeset
|
2638 sd->window = window_new(GTK_WINDOW_TOPLEVEL, "search", NULL, NULL, _("Image search")); |
9 | 2639 |
2640 gtk_window_set_resizable(GTK_WINDOW(sd->window), TRUE); | |
2641 | |
1029
1a4b18c58556
Use a constant for minimal window size. Set it to 32 for all dialogs.
zas_
parents:
1022
diff
changeset
|
2642 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
|
2643 geometry.min_height = DEFAULT_MINIMAL_WINDOW_SIZE; |
9 | 2644 geometry.base_width = DEF_SEARCH_WIDTH; |
2645 geometry.base_height = DEF_SEARCH_HEIGHT; | |
2646 gtk_window_set_geometry_hints(GTK_WINDOW(sd->window), NULL, &geometry, | |
2647 GDK_HINT_MIN_SIZE | GDK_HINT_BASE_SIZE); | |
2648 | |
2649 gtk_window_set_default_size(GTK_WINDOW(sd->window), DEF_SEARCH_WIDTH, DEF_SEARCH_HEIGHT); | |
2650 | |
2651 g_signal_connect(G_OBJECT(sd->window), "delete_event", | |
2652 G_CALLBACK(search_window_delete_cb), sd); | |
2653 g_signal_connect(G_OBJECT(sd->window), "destroy", | |
2654 G_CALLBACK(search_window_destroy_cb), sd); | |
2655 | |
2656 g_signal_connect(G_OBJECT(sd->window), "key_press_event", | |
2657 G_CALLBACK(search_window_keypress_cb), sd); | |
2658 | |
2659 vbox = gtk_vbox_new(FALSE, PREF_PAD_GAP); | |
2660 gtk_container_set_border_width(GTK_CONTAINER(vbox), PREF_PAD_GAP); | |
2661 gtk_container_add(GTK_CONTAINER(sd->window), vbox); | |
2662 gtk_widget_show(vbox); | |
2663 | |
2664 sd->box_search = pref_box_new(vbox, FALSE, GTK_ORIENTATION_VERTICAL, PREF_PAD_GAP); | |
2665 | |
2666 hbox = pref_box_new(sd->box_search, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_SPACE); | |
2667 | |
2668 pref_label_new(hbox, _("Search:")); | |
2669 | |
2670 sd->menu_path = menu_choice_menu(text_search_menu_path, sizeof(text_search_menu_path) / sizeof(MatchList), | |
2671 G_CALLBACK(menu_choice_path_cb), sd); | |
2672 gtk_box_pack_start(GTK_BOX(hbox), sd->menu_path, FALSE, FALSE, 0); | |
2673 gtk_widget_show(sd->menu_path); | |
2674 | |
2675 hbox2 = pref_box_new(hbox, TRUE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_SPACE); | |
783 | 2676 combo = tab_completion_new_with_history(&sd->path_entry, sd->search_dir_fd->path, |
9 | 2677 "search_path", -1, |
2678 NULL, NULL); | |
2679 tab_completion_add_select_button(sd->path_entry, NULL, TRUE); | |
2680 gtk_box_pack_start(GTK_BOX(hbox2), combo, TRUE, TRUE, 0); | |
2681 gtk_widget_show(combo); | |
2682 sd->check_recurse = pref_checkbox_new_int(hbox2, _("Recurse"), | |
2683 sd->search_path_recurse, &sd->search_path_recurse); | |
2684 | |
1057
c28eb027dd5b
Implement the search for image comment - patch by Klaus Ethgen
nadvornik
parents:
1055
diff
changeset
|
2685 /* Search for file name */ |
9 | 2686 hbox = menu_choice(sd->box_search, &sd->check_name, &sd->menu_name, |
2687 _("File name"), &sd->match_name_enable, | |
2688 text_search_menu_name, sizeof(text_search_menu_name) / sizeof(MatchList), | |
2689 G_CALLBACK(menu_choice_name_cb), sd); | |
2690 combo = history_combo_new(&sd->entry_name, "", "search_name", -1); | |
2691 gtk_box_pack_start(GTK_BOX(hbox), combo, TRUE, TRUE, 0); | |
2692 gtk_widget_show(combo); | |
2693 pref_checkbox_new_int(hbox, _("Match case"), | |
2694 sd->search_name_match_case, &sd->search_name_match_case); | |
2695 | |
1057
c28eb027dd5b
Implement the search for image comment - patch by Klaus Ethgen
nadvornik
parents:
1055
diff
changeset
|
2696 /* Search for file size */ |
9 | 2697 hbox = menu_choice(sd->box_search, &sd->check_size, &sd->menu_size, |
2698 _("File size is"), &sd->match_size_enable, | |
2699 text_search_menu_size, sizeof(text_search_menu_size) / sizeof(MatchList), | |
2700 G_CALLBACK(menu_choice_size_cb), sd); | |
2701 sd->spin_size = menu_spin(hbox, 0, 1024*1024*1024, sd->search_size, | |
2702 G_CALLBACK(menu_choice_spin_cb), &sd->search_size); | |
2703 hbox2 = gtk_hbox_new(FALSE, PREF_PAD_SPACE); | |
2704 gtk_box_pack_start(GTK_BOX(hbox), hbox2, FALSE, FALSE, 0); | |
2705 pref_label_new(hbox2, _("and")); | |
2706 sd->spin_size_end = menu_spin(hbox2, 0, 1024*1024*1024, sd->search_size_end, | |
2707 G_CALLBACK(menu_choice_spin_cb), &sd->search_size_end); | |
2708 | |
1057
c28eb027dd5b
Implement the search for image comment - patch by Klaus Ethgen
nadvornik
parents:
1055
diff
changeset
|
2709 /* Search for file date */ |
9 | 2710 hbox = menu_choice(sd->box_search, &sd->check_date, &sd->menu_date, |
2711 _("File date is"), &sd->match_date_enable, | |
2712 text_search_menu_date, sizeof(text_search_menu_date) / sizeof(MatchList), | |
2713 G_CALLBACK(menu_choice_date_cb), sd); | |
2714 sd->date_sel = date_selection_new(); | |
2715 date_selection_time_set(sd->date_sel, time(NULL)); | |
2716 gtk_box_pack_start(GTK_BOX(hbox), sd->date_sel, FALSE, FALSE, 0); | |
2717 gtk_widget_show(sd->date_sel); | |
2718 | |
2719 hbox2 = gtk_hbox_new(FALSE, PREF_PAD_SPACE); | |
2720 gtk_box_pack_start(GTK_BOX(hbox), hbox2, FALSE, FALSE, 0); | |
2721 pref_label_new(hbox2, _("and")); | |
2722 sd->date_sel_end = date_selection_new(); | |
2723 date_selection_time_set(sd->date_sel_end, time(NULL)); | |
2724 gtk_box_pack_start(GTK_BOX(hbox2), sd->date_sel_end, FALSE, FALSE, 0); | |
2725 gtk_widget_show(sd->date_sel_end); | |
2726 | |
1057
c28eb027dd5b
Implement the search for image comment - patch by Klaus Ethgen
nadvornik
parents:
1055
diff
changeset
|
2727 /* Search for image dimensions */ |
9 | 2728 hbox = menu_choice(sd->box_search, &sd->check_dimensions, &sd->menu_dimensions, |
2729 _("Image dimensions are"), &sd->match_dimensions_enable, | |
2730 text_search_menu_size, sizeof(text_search_menu_size) / sizeof(MatchList), | |
2731 G_CALLBACK(menu_choice_dimensions_cb), sd); | |
2732 pad_box = pref_box_new(hbox, FALSE, GTK_ORIENTATION_HORIZONTAL, 2); | |
2733 sd->spin_width = menu_spin(pad_box, 0, 1000000, sd->search_width, | |
2734 G_CALLBACK(menu_choice_spin_cb), &sd->search_width); | |
2735 pref_label_new(pad_box, "x"); | |
2736 sd->spin_height = menu_spin(pad_box, 0, 1000000, sd->search_height, | |
2737 G_CALLBACK(menu_choice_spin_cb), &sd->search_height); | |
2738 hbox2 = gtk_hbox_new(FALSE, 2); | |
2739 gtk_box_pack_start(GTK_BOX(hbox), hbox2, FALSE, FALSE, 0); | |
2740 pref_label_new(hbox2, _("and")); | |
2741 pref_spacer(hbox2, PREF_PAD_SPACE - 2*2); | |
2742 sd->spin_width_end = menu_spin(hbox2, 0, 1000000, sd->search_width_end, | |
2743 G_CALLBACK(menu_choice_spin_cb), &sd->search_width_end); | |
2744 pref_label_new(hbox2, "x"); | |
2745 sd->spin_height_end = menu_spin(hbox2, 0, 1000000, sd->search_height_end, | |
2746 G_CALLBACK(menu_choice_spin_cb), &sd->search_height_end); | |
2747 | |
1057
c28eb027dd5b
Implement the search for image comment - patch by Klaus Ethgen
nadvornik
parents:
1055
diff
changeset
|
2748 /* Search for image similarity */ |
9 | 2749 hbox = menu_choice(sd->box_search, &sd->check_similarity, NULL, |
2750 _("Image content is"), &sd->match_similarity_enable, | |
2751 NULL, 0, NULL, sd); | |
2752 sd->spin_similarity = menu_spin(hbox, 80, 100, sd->search_similarity, | |
2753 G_CALLBACK(menu_choice_spin_cb), &sd->search_similarity); | |
2754 | |
2755 /* xgettext:no-c-format */ | |
2756 pref_label_new(hbox, _("% similar to")); | |
2757 | |
2758 combo = tab_completion_new_with_history(&sd->entry_similarity, | |
2759 (sd->search_similarity_path) ? sd->search_similarity_path : "", | |
2760 "search_similarity_path", -1, NULL, NULL); | |
2761 tab_completion_add_select_button(sd->entry_similarity, NULL, FALSE); | |
2762 gtk_box_pack_start(GTK_BOX(hbox), combo, TRUE, TRUE, 0); | |
2763 gtk_widget_show(combo); | |
2764 | |
1057
c28eb027dd5b
Implement the search for image comment - patch by Klaus Ethgen
nadvornik
parents:
1055
diff
changeset
|
2765 /* Search for image keywords */ |
9 | 2766 hbox = menu_choice(sd->box_search, &sd->check_keywords, &sd->menu_keywords, |
2767 _("Keywords"), &sd->match_keywords_enable, | |
2768 text_search_menu_keyword, sizeof(text_search_menu_keyword) / sizeof(MatchList), | |
2769 G_CALLBACK(menu_choice_keyword_cb), sd); | |
2770 sd->entry_keywords = gtk_entry_new(); | |
2771 gtk_box_pack_start(GTK_BOX(hbox), sd->entry_keywords, TRUE, TRUE, 0); | |
2772 gtk_widget_set_sensitive(sd->entry_keywords, sd->match_keywords_enable); | |
2773 g_signal_connect(G_OBJECT(sd->check_keywords), "toggled", | |
2774 G_CALLBACK(menu_choice_check_cb), sd->entry_keywords); | |
2775 gtk_widget_show(sd->entry_keywords); | |
2776 | |
1057
c28eb027dd5b
Implement the search for image comment - patch by Klaus Ethgen
nadvornik
parents:
1055
diff
changeset
|
2777 /* Search for image comment */ |
c28eb027dd5b
Implement the search for image comment - patch by Klaus Ethgen
nadvornik
parents:
1055
diff
changeset
|
2778 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
|
2779 _("Comment"), &sd->match_comment_enable, |
c28eb027dd5b
Implement the search for image comment - patch by Klaus Ethgen
nadvornik
parents:
1055
diff
changeset
|
2780 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
|
2781 G_CALLBACK(menu_choice_comment_cb), sd); |
c28eb027dd5b
Implement the search for image comment - patch by Klaus Ethgen
nadvornik
parents:
1055
diff
changeset
|
2782 sd->entry_comment = gtk_entry_new(); |
c28eb027dd5b
Implement the search for image comment - patch by Klaus Ethgen
nadvornik
parents:
1055
diff
changeset
|
2783 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
|
2784 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
|
2785 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
|
2786 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
|
2787 gtk_widget_show(sd->entry_comment); |
c28eb027dd5b
Implement the search for image comment - patch by Klaus Ethgen
nadvornik
parents:
1055
diff
changeset
|
2788 pref_checkbox_new_int(hbox, _("Match case"), |
c28eb027dd5b
Implement the search for image comment - patch by Klaus Ethgen
nadvornik
parents:
1055
diff
changeset
|
2789 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
|
2790 |
c28eb027dd5b
Implement the search for image comment - patch by Klaus Ethgen
nadvornik
parents:
1055
diff
changeset
|
2791 /* Done the types of searches */ |
c28eb027dd5b
Implement the search for image comment - patch by Klaus Ethgen
nadvornik
parents:
1055
diff
changeset
|
2792 |
9 | 2793 scrolled = gtk_scrolled_window_new(NULL, NULL); |
2794 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN); | |
2795 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), | |
2796 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
2797 gtk_box_pack_start(GTK_BOX(vbox), scrolled, TRUE, TRUE, 0); | |
2798 gtk_widget_show(scrolled); | |
2799 | |
2800 store = gtk_list_store_new(8, G_TYPE_POINTER, G_TYPE_INT, GDK_TYPE_PIXBUF, | |
2801 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, | |
2802 G_TYPE_STRING, G_TYPE_STRING); | |
2803 | |
2804 /* set up sorting */ | |
2805 sortable = GTK_TREE_SORTABLE(store); | |
2806 gtk_tree_sortable_set_sort_func(sortable, SEARCH_COLUMN_RANK, search_result_sort_cb, | |
2807 GINT_TO_POINTER(SEARCH_COLUMN_RANK), NULL); | |
2808 gtk_tree_sortable_set_sort_func(sortable, SEARCH_COLUMN_NAME, search_result_sort_cb, | |
2809 GINT_TO_POINTER(SEARCH_COLUMN_NAME), NULL); | |
2810 gtk_tree_sortable_set_sort_func(sortable, SEARCH_COLUMN_SIZE, search_result_sort_cb, | |
2811 GINT_TO_POINTER(SEARCH_COLUMN_SIZE), NULL); | |
2812 gtk_tree_sortable_set_sort_func(sortable, SEARCH_COLUMN_DATE, search_result_sort_cb, | |
2813 GINT_TO_POINTER(SEARCH_COLUMN_DATE), NULL); | |
2814 gtk_tree_sortable_set_sort_func(sortable, SEARCH_COLUMN_DIMENSIONS, search_result_sort_cb, | |
2815 GINT_TO_POINTER(SEARCH_COLUMN_DIMENSIONS), NULL); | |
2816 gtk_tree_sortable_set_sort_func(sortable, SEARCH_COLUMN_PATH, search_result_sort_cb, | |
2817 GINT_TO_POINTER(SEARCH_COLUMN_PATH), NULL); | |
2818 | |
2819 #if 0 | |
2820 /* by default, search results are unsorted until user selects a sort column - for speed, | |
2821 * using sort slows search speed by an order of magnitude with 1000's of results :-/ | |
2822 */ | |
2823 gtk_tree_sortable_set_sort_column_id(sortable, SEARCH_COLUMN_PATH, GTK_SORT_ASCENDING); | |
2824 #endif | |
2825 | |
2826 sd->result_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); | |
2827 g_object_unref(store); | |
2828 gtk_container_add(GTK_CONTAINER(scrolled), sd->result_view); | |
2829 gtk_widget_show(sd->result_view); | |
2830 | |
2831 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(sd->result_view)); | |
2832 gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_MULTIPLE); | |
2833 gtk_tree_selection_set_select_function(selection, search_result_select_cb, sd, NULL); | |
2834 | |
2835 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(sd->result_view), TRUE); | |
2836 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(sd->result_view), FALSE); | |
2837 | |
2838 #if 0 | |
2839 gtk_tree_view_set_search_column(GTK_TREE_VIEW(sd->result_view), SEARCH_COLUMN_NAME); | |
2840 #endif | |
2841 | |
2842 search_result_add_column(sd, SEARCH_COLUMN_RANK, _("Rank"), FALSE, FALSE); | |
2843 search_result_add_column(sd, SEARCH_COLUMN_THUMB, "", TRUE, FALSE); | |
2844 search_result_add_column(sd, SEARCH_COLUMN_NAME, _("Name"), FALSE, FALSE); | |
2845 search_result_add_column(sd, SEARCH_COLUMN_SIZE, _("Size"), FALSE, TRUE); | |
2846 search_result_add_column(sd, SEARCH_COLUMN_DATE, _("Date"), FALSE, TRUE); | |
2847 search_result_add_column(sd, SEARCH_COLUMN_DIMENSIONS, _("Dimensions"), FALSE, FALSE); | |
2848 search_result_add_column(sd, SEARCH_COLUMN_PATH, _("Path"), FALSE, FALSE); | |
2849 | |
2850 search_dnd_init(sd); | |
2851 | |
2852 g_signal_connect(G_OBJECT(sd->result_view), "button_press_event", | |
2853 G_CALLBACK(search_result_press_cb), sd); | |
2854 g_signal_connect(G_OBJECT(sd->result_view), "button_release_event", | |
2855 G_CALLBACK(search_result_release_cb), sd); | |
2856 g_signal_connect(G_OBJECT(sd->result_view), "key_press_event", | |
2857 G_CALLBACK(search_result_keypress_cb), sd); | |
2858 | |
2859 hbox = pref_box_new(vbox, FALSE, GTK_ORIENTATION_HORIZONTAL, 0); | |
2860 | |
2861 sd->button_thumbs = pref_checkbox_new(hbox, _("Thumbnails"), FALSE, | |
2862 G_CALLBACK(search_thumb_toggle_cb), sd); | |
2863 | |
2864 frame = gtk_frame_new(NULL); | |
2865 gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN); | |
2866 gtk_box_pack_start(GTK_BOX(hbox), frame, TRUE, TRUE, PREF_PAD_SPACE); | |
2867 gtk_widget_show(frame); | |
2868 | |
2869 sd->label_status = gtk_label_new(""); | |
2870 gtk_widget_set_size_request(sd->label_status, 50, -1); | |
2871 gtk_container_add(GTK_CONTAINER(frame), sd->label_status); | |
2872 gtk_widget_show(sd->label_status); | |
2873 | |
2874 sd->label_progress = gtk_progress_bar_new(); | |
2875 gtk_widget_set_size_request(sd->label_progress, 50, -1); | |
2876 gtk_box_pack_start(GTK_BOX(hbox), sd->label_progress, TRUE, TRUE, 0); | |
2877 gtk_widget_show(sd->label_progress); | |
2878 | |
2879 sd->spinner = spinner_new(NULL, -1); | |
2880 gtk_box_pack_start(GTK_BOX(hbox), sd->spinner, FALSE, FALSE, 0); | |
2881 gtk_widget_show(sd->spinner); | |
2882 | |
2883 sd->button_start = pref_button_new(hbox, GTK_STOCK_FIND, NULL, FALSE, | |
2884 G_CALLBACK(search_start_cb), sd); | |
2885 pref_spacer(hbox, PREF_PAD_BUTTON_GAP); | |
2886 sd->button_stop = pref_button_new(hbox, GTK_STOCK_STOP, NULL, FALSE, | |
2887 G_CALLBACK(search_start_cb), sd); | |
2888 gtk_widget_set_sensitive(sd->button_stop, FALSE); | |
2889 | |
2890 search_status_update(sd); | |
2891 search_progress_update(sd, FALSE, -1.0); | |
2892 | |
2893 search_window_list = g_list_append(search_window_list, sd); | |
2894 | |
795 | 2895 file_data_register_notify_func(search_notify_cb, sd, NOTIFY_PRIORITY_MEDIUM); |
2896 | |
9 | 2897 gtk_widget_show(sd->window); |
2898 } | |
2899 | |
2900 /* | |
2901 *------------------------------------------------------------------- | |
2902 * maintenance (move, delete, etc.) | |
2903 *------------------------------------------------------------------- | |
2904 */ | |
2905 | |
138 | 2906 static void search_result_change_path(SearchData *sd, FileData *fd) |
9 | 2907 { |
2908 GtkTreeModel *store; | |
2909 GtkTreeIter iter; | |
1444 | 2910 gboolean valid; |
9 | 2911 |
2912 store = gtk_tree_view_get_model(GTK_TREE_VIEW(sd->result_view)); | |
2913 valid = gtk_tree_model_get_iter_first(store, &iter); | |
2914 while (valid) | |
2915 { | |
2916 GtkTreeIter current; | |
138 | 2917 MatchFileData *mfd; |
9 | 2918 |
2919 current = iter; | |
2920 valid = gtk_tree_model_iter_next(store, &iter); | |
2921 | |
138 | 2922 gtk_tree_model_get(store, ¤t, SEARCH_COLUMN_POINTER, &mfd, -1); |
2923 if (mfd->fd == fd) | |
9 | 2924 { |
138 | 2925 if (fd->change && fd->change->dest) |
9 | 2926 { |
2927 gtk_list_store_set(GTK_LIST_STORE(store), ¤t, | |
138 | 2928 SEARCH_COLUMN_NAME, mfd->fd->name, |
2929 SEARCH_COLUMN_PATH, mfd->fd->path, -1); | |
9 | 2930 } |
2931 else | |
2932 { | |
138 | 2933 search_result_remove_item(sd, mfd, ¤t); |
9 | 2934 } |
2935 } | |
2936 } | |
2937 } | |
2938 | |
795 | 2939 static void search_notify_cb(FileData *fd, NotifyType type, gpointer data) |
9 | 2940 { |
795 | 2941 SearchData *sd = data; |
2942 | |
1432 | 2943 if (!(type & NOTIFY_CHANGE) || !fd->change) return; |
1498 | 2944 |
2945 DEBUG_1("Notify search: %s %04x", fd->path, type); | |
795 | 2946 |
1347
79937bc55f3a
Add missing space between switch and first parenthesis.
zas_
parents:
1346
diff
changeset
|
2947 switch (fd->change->type) |
9 | 2948 { |
795 | 2949 case FILEDATA_CHANGE_MOVE: |
2950 case FILEDATA_CHANGE_RENAME: | |
2951 case FILEDATA_CHANGE_DELETE: | |
2952 search_result_change_path(sd, fd); | |
2953 break; | |
2954 case FILEDATA_CHANGE_COPY: | |
2955 case FILEDATA_CHANGE_UNSPECIFIED: | |
1211 | 2956 case FILEDATA_CHANGE_WRITE_METADATA: |
795 | 2957 break; |
9 | 2958 } |
2959 } | |
1055
1646720364cf
Adding a vim modeline to all files - patch by Klaus Ethgen
nadvornik
parents:
1029
diff
changeset
|
2960 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ |