aboutsummaryrefslogtreecommitdiff
path: root/src/search.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/search.c')
-rw-r--r--src/search.c204
1 files changed, 112 insertions, 92 deletions
diff --git a/src/search.c b/src/search.c
index 000b7837..3b834e23 100644
--- a/src/search.c
+++ b/src/search.c
@@ -31,6 +31,90 @@
31#include <extractor.h> 31#include <extractor.h>
32 32
33/** 33/**
34 * Add an entry to the search tree.
35 *
36 * @param model the search model
37 * @param pos the position to add the entry
38 * @param uri the URI to add
39 * @param meta metadata describing the URI
40 */
41void addEntryToSearchTree(GtkTreeStore * model,
42 GtkTreeIter * pos,
43 const struct ECRS_URI * uri,
44 const struct ECRS_MetaData * meta) {
45 char * name;
46 char * mime;
47 char * desc;
48 unsigned char * thumb;
49 size_t ts;
50 GdkPixbuf * pixbuf;
51 GdkPixbufLoader * loader;
52 unsigned long long size;
53
54 mime = ECRS_getFromMetaData(meta,
55 EXTRACTOR_MIMETYPE);
56 if (mime == NULL)
57 mime = STRDUP(_("unknown"));
58 desc = ECRS_getFirstFromMetaData(meta,
59 EXTRACTOR_DESCRIPTION,
60 EXTRACTOR_GENRE,
61 EXTRACTOR_ALBUM,
62 EXTRACTOR_COMMENT,
63 EXTRACTOR_SUBJECT,
64 EXTRACTOR_FORMAT,
65 EXTRACTOR_SIZE,
66 EXTRACTOR_KEYWORDS,
67 -1);
68 if (desc == NULL)
69 desc = STRDUP(_(""));
70 name = ECRS_getFirstFromMetaData(meta,
71 EXTRACTOR_FILENAME,
72 EXTRACTOR_TITLE,
73 EXTRACTOR_ARTIST,
74 EXTRACTOR_AUTHOR,
75 EXTRACTOR_PUBLISHER,
76 EXTRACTOR_CREATOR,
77 EXTRACTOR_PRODUCER,
78 EXTRACTOR_UNKNOWN,
79 -1);
80 if (name == NULL)
81 name = STRDUP(_("no name given"));
82 size = ECRS_fileSize(uri);
83 thumb = NULL;
84 ts = ECRS_getThumbnailFromMetaData(meta,
85 &thumb);
86 if (ts != 0) {
87 loader = gdk_pixbuf_loader_new();
88 gdk_pixbuf_loader_write(loader,
89 (const guchar*) thumb,
90 ts,
91 NULL);
92 pixbuf = gdk_pixbuf_loader_get_pixbuf(loader);
93 gdk_pixbuf_loader_close(loader,
94 NULL);
95 } else {
96 pixbuf = NULL;
97 }
98 gtk_tree_store_set(model,
99 pos,
100 SEARCH_NAME, name,
101 SEARCH_SIZE, size,
102 SEARCH_MIME, mime,
103 SEARCH_DESC, desc,
104 SEARCH_PIXBUF, pixbuf,
105 SEARCH_URI, ECRS_dupUri(uri),
106 SEARCH_META, ECRS_dupMetaData(meta),
107 SEARCH_INTERNAL, NULL, /* internal */
108 -1);
109 FREE(mime);
110 FREE(desc);
111 FREE(name);
112 FREENONNULL(thumb);
113}
114
115
116
117/**
34 * @brief linked list of pages in the search notebook 118 * @brief linked list of pages in the search notebook
35 */ 119 */
36typedef struct SL { 120typedef struct SL {
@@ -59,8 +143,8 @@ static void freeIterSubtree(GtkTreeModel * tree,
59 meta = NULL; 143 meta = NULL;
60 gtk_tree_model_get(tree, 144 gtk_tree_model_get(tree,
61 iter, 145 iter,
62 5, &uri, 146 SEARCH_URI, &uri,
63 6, &meta, 147 SEARCH_META, &meta,
64 -1); 148 -1);
65 if (uri != NULL) 149 if (uri != NULL)
66 ECRS_freeUri(uri); 150 ECRS_freeUri(uri);
@@ -68,8 +152,8 @@ static void freeIterSubtree(GtkTreeModel * tree,
68 ECRS_freeMetaData(meta); 152 ECRS_freeMetaData(meta);
69 gtk_tree_store_set(GTK_TREE_STORE(tree), 153 gtk_tree_store_set(GTK_TREE_STORE(tree),
70 iter, 154 iter,
71 5, NULL, 155 SEARCH_URI, NULL,
72 6, NULL, 156 SEARCH_META, NULL,
73 -1); 157 -1);
74 if (gtk_tree_model_iter_children(tree, 158 if (gtk_tree_model_iter_children(tree,
75 &child, 159 &child,
@@ -110,14 +194,6 @@ static void addSearchResultToModel(const ECRS_FileInfo * info,
110 GtkTreeIter parent; 194 GtkTreeIter parent;
111 GtkTreeIter * pparent; 195 GtkTreeIter * pparent;
112 GtkTreePath * path; 196 GtkTreePath * path;
113 unsigned long long size;
114 char * name;
115 char * mime;
116 char * desc;
117 unsigned char * thumb;
118 size_t ts;
119 GdkPixbuf * pixbuf;
120 GdkPixbufLoader * loader;
121 197
122 if (! gtk_tree_row_reference_valid(row)) 198 if (! gtk_tree_row_reference_valid(row))
123 path = NULL; 199 path = NULL;
@@ -135,65 +211,10 @@ static void addSearchResultToModel(const ECRS_FileInfo * info,
135 &iter, 211 &iter,
136 pparent, 212 pparent,
137 0); 213 0);
138 mime = ECRS_getFromMetaData(info->meta, 214 addEntryToSearchTree(model,
139 EXTRACTOR_MIMETYPE); 215 &iter,
140 if (mime == NULL) 216 info->uri,
141 mime = STRDUP(_("unknown")); 217 info->meta);
142 desc = ECRS_getFirstFromMetaData(info->meta,
143 EXTRACTOR_DESCRIPTION,
144 EXTRACTOR_GENRE,
145 EXTRACTOR_ALBUM,
146 EXTRACTOR_COMMENT,
147 EXTRACTOR_SUBJECT,
148 EXTRACTOR_FORMAT,
149 EXTRACTOR_SIZE,
150 EXTRACTOR_KEYWORDS,
151 -1);
152 if (desc == NULL)
153 desc = STRDUP(_(""));
154 name = ECRS_getFirstFromMetaData(info->meta,
155 EXTRACTOR_FILENAME,
156 EXTRACTOR_TITLE,
157 EXTRACTOR_ARTIST,
158 EXTRACTOR_AUTHOR,
159 EXTRACTOR_PUBLISHER,
160 EXTRACTOR_CREATOR,
161 EXTRACTOR_PRODUCER,
162 EXTRACTOR_UNKNOWN,
163 -1);
164 if (name == NULL)
165 name = STRDUP(_("no name given"));
166 size = ECRS_fileSize(info->uri);
167 thumb = NULL;
168 ts = ECRS_getThumbnailFromMetaData(info->meta,
169 &thumb);
170 if (ts != 0) {
171 loader = gdk_pixbuf_loader_new();
172 gdk_pixbuf_loader_write(loader,
173 (const guchar*) thumb,
174 ts,
175 NULL);
176 pixbuf = gdk_pixbuf_loader_get_pixbuf(loader);
177 gdk_pixbuf_loader_close(loader,
178 NULL);
179 } else {
180 pixbuf = NULL;
181 }
182 gtk_tree_store_set(model,
183 &iter,
184 0, name,
185 1, size,
186 2, mime,
187 3, desc,
188 4, pixbuf,
189 5, ECRS_dupUri(info->uri),
190 6, ECRS_dupMetaData(info->meta),
191 7, NULL, /* internal */
192 -1);
193 FREE(mime);
194 FREE(desc);
195 FREE(name);
196 FREENONNULL(thumb);
197} 218}
198 219
199/** 220/**
@@ -236,15 +257,15 @@ void displaySearchResult(const ECRS_FileInfo * info,
236 do { 257 do {
237 gtk_tree_model_get(GTK_TREE_MODEL(summary), 258 gtk_tree_model_get(GTK_TREE_MODEL(summary),
238 &iter, 259 &iter,
239 1, &count, 260 SER_SUM_COUNT, &count,
240 2, &euri, 261 SER_SUM_URI, &euri,
241 -1); 262 -1);
242 if (ECRS_equalsUri(euri, 263 if (ECRS_equalsUri(euri,
243 uri)) { 264 uri)) {
244 count++; 265 count++;
245 gtk_list_store_set(GTK_LIST_STORE(summary), 266 gtk_list_store_set(GTK_LIST_STORE(summary),
246 &iter, 267 &iter,
247 1, count, 268 SER_SUM_COUNT, count,
248 -1); 269 -1);
249 return; 270 return;
250 } 271 }
@@ -308,7 +329,7 @@ void on_closeSearchButton_clicked(GtkWidget * searchPage,
308 do { 329 do {
309 gtk_tree_model_get(GTK_TREE_MODEL(summary), 330 gtk_tree_model_get(GTK_TREE_MODEL(summary),
310 &iter, 331 &iter,
311 2, &euri, 332 SER_SUM_URI, &euri,
312 -1); 333 -1);
313 if (ECRS_equalsUri(euri, 334 if (ECRS_equalsUri(euri,
314 uri)) { 335 uri)) {
@@ -344,7 +365,7 @@ static GtkWidget * makeResultFrame(GtkWidget ** treeview) {
344 if (treeview != NULL) 365 if (treeview != NULL)
345 (*treeview) = GTK_WIDGET(GTK_TREE_VIEW(resultList)); 366 (*treeview) = GTK_WIDGET(GTK_TREE_VIEW(resultList));
346 tree = 367 tree =
347 gtk_tree_store_new(8, 368 gtk_tree_store_new(SEARCH_NUM,
348 G_TYPE_STRING, /* name */ 369 G_TYPE_STRING, /* name */
349 G_TYPE_UINT64, /* size */ 370 G_TYPE_UINT64, /* size */
350 G_TYPE_STRING, /* mime-type */ 371 G_TYPE_STRING, /* mime-type */
@@ -360,35 +381,35 @@ static GtkWidget * makeResultFrame(GtkWidget ** treeview) {
360 -1, 381 -1,
361 _("Name"), 382 _("Name"),
362 renderer, 383 renderer,
363 "text", 0, 384 "text", SEARCH_NAME,
364 NULL); 385 NULL);
365 renderer = gtk_cell_renderer_text_new(); 386 renderer = gtk_cell_renderer_text_new();
366 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(resultList), 387 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(resultList),
367 -1, 388 -1,
368 _("Size"), 389 _("Size"),
369 renderer, 390 renderer,
370 "text", 1, 391 "text", SEARCH_SIZE,
371 NULL); 392 NULL);
372 renderer = gtk_cell_renderer_text_new(); 393 renderer = gtk_cell_renderer_text_new();
373 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(resultList), 394 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(resultList),
374 -1, 395 -1,
375 _("Mime-type"), 396 _("Mime-type"),
376 renderer, 397 renderer,
377 "text", 2, 398 "text", SEARCH_MIME,
378 NULL); 399 NULL);
379 renderer = gtk_cell_renderer_text_new(); 400 renderer = gtk_cell_renderer_text_new();
380 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(resultList), 401 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(resultList),
381 -1, 402 -1,
382 _("Meta-data"), 403 _("Meta-data"),
383 renderer, 404 renderer,
384 "text", 3, 405 "text", SEARCH_DESC,
385 NULL); 406 NULL);
386 renderer = gtk_cell_renderer_pixbuf_new(); 407 renderer = gtk_cell_renderer_pixbuf_new();
387 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(resultList), 408 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(resultList),
388 -1, 409 -1,
389 _("Preview"), 410 _("Preview"),
390 renderer, 411 renderer,
391 "pixbuf", 4, 412 "pixbuf", SEARCH_PIXBUF,
392 NULL); 413 NULL);
393 child = gtk_bin_get_child(GTK_BIN(window)); 414 child = gtk_bin_get_child(GTK_BIN(window));
394 gtk_widget_ref(GTK_WIDGET(child)); 415 gtk_widget_ref(GTK_WIDGET(child));
@@ -435,8 +456,7 @@ void on_fssearchbutton_clicked(gpointer dummy2,
435 &iter); 456 &iter);
436 gtk_list_store_set(model, 457 gtk_list_store_set(model,
437 &iter, 458 &iter,
438 0, 459 0, ss,
439 ss,
440 -1); 460 -1);
441 } 461 }
442 462
@@ -504,9 +524,9 @@ void on_fssearchbutton_clicked(gpointer dummy2,
504 &iter); 524 &iter);
505 gtk_list_store_set(summary, 525 gtk_list_store_set(summary,
506 &iter, 526 &iter,
507 0, tabtxt, 527 SER_SUM_NAME, tabtxt,
508 1, 0, 528 SER_SUM_COUNT, 0,
509 2, ECRS_dupUri(uri), 529 SER_SUM_URI, ECRS_dupUri(uri),
510 -1); 530 -1);
511 531
512 label = gtk_label_new(tabtxt); 532 label = gtk_label_new(tabtxt);
@@ -631,9 +651,9 @@ static int openTabForSearch(void * unused,
631 &iter); 651 &iter);
632 gtk_list_store_set(summary, 652 gtk_list_store_set(summary,
633 &iter, 653 &iter,
634 0, dhead, 654 SER_SUM_NAME, dhead,
635 1, resultCount, 655 SER_SUM_COUNT, resultCount,
636 2, ECRS_dupUri(uri), 656 SER_SUM_URI, ECRS_dupUri(uri),
637 -1); 657 -1);
638 658
639 FREE(description); 659 FREE(description);
@@ -683,7 +703,7 @@ void fs_search_start() {
683 searchList = glade_xml_get_widget(mainXML, 703 searchList = glade_xml_get_widget(mainXML,
684 "activeSearchesSummary"); 704 "activeSearchesSummary");
685 summary = 705 summary =
686 gtk_list_store_new(3, 706 gtk_list_store_new(SER_SUM_NUM,
687 G_TYPE_STRING, /* name */ 707 G_TYPE_STRING, /* name */
688 G_TYPE_INT, /* # results */ 708 G_TYPE_INT, /* # results */
689 G_TYPE_POINTER); /* internal: uri */ 709 G_TYPE_POINTER); /* internal: uri */
@@ -694,14 +714,14 @@ void fs_search_start() {
694 -1, 714 -1,
695 _("Query"), 715 _("Query"),
696 renderer, 716 renderer,
697 "text", 0, 717 "text", SER_SUM_NAME,
698 NULL); 718 NULL);
699 renderer = gtk_cell_renderer_text_new(); 719 renderer = gtk_cell_renderer_text_new();
700 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(searchList), 720 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(searchList),
701 -1, 721 -1,
702 _("Results"), 722 _("Results"),
703 renderer, 723 renderer,
704 "text", 1, 724 "text", SER_SUM_COUNT,
705 NULL); 725 NULL);
706 726
707 FSUI_listSearches(ctx, 727 FSUI_listSearches(ctx,