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