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