aboutsummaryrefslogtreecommitdiff
path: root/src/search.c
blob: 5a7eb067d60f10c8d91067f243d23d1f77d8280f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
/*
     This file is part of GNUnet.
     (C) 2005 Christian Grothoff (and other contributing authors)

     GNUnet is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published
     by the Free Software Foundation; either version 2, or (at your
     option) any later version.

     GNUnet is distributed in the hope that it will be useful, but
     WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     General Public License for more details.

     You should have received a copy of the GNU General Public License
     along with GNUnet; see the file COPYING.  If not, write to the
     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
     Boston, MA 02111-1307, USA.
*/

/**
 * @file src/search.c
 * @brief code for searching with gnunet-gtk
 * @author Christian Grothoff
 */

#include "platform.h"
#include "search.h"
#include "helper.h"
#include "main.h"
#include <extractor.h>

/**
 * Add an entry to the search tree.
 *
 * @param model the search model
 * @param pos the position to add the entry
 * @param uri the URI to add
 * @param meta metadata describing the URI
 */
void addEntryToSearchTree(GtkTreeStore * model,
			  GtkTreeIter * pos,
			  const struct ECRS_URI * uri,
			  const struct ECRS_MetaData * meta) {
  char * name;
  char * mime;
  char * desc;
  unsigned char * thumb;
  size_t ts;
  GdkPixbuf * pixbuf;
  GdkPixbufLoader * loader;    
  unsigned long long size;

  mime = ECRS_getFromMetaData(meta,
			      EXTRACTOR_MIMETYPE);
  if (mime == NULL)
    mime = STRDUP(_("unknown"));
  desc = ECRS_getFirstFromMetaData(meta,
				   EXTRACTOR_DESCRIPTION,
				   EXTRACTOR_GENRE,
				   EXTRACTOR_ALBUM,
				   EXTRACTOR_COMMENT,
				   EXTRACTOR_SUBJECT,
				   EXTRACTOR_FORMAT,
				   EXTRACTOR_SIZE,
				   EXTRACTOR_KEYWORDS,
				   -1);
  if (desc == NULL)
    desc = STRDUP("");
  name = ECRS_getFirstFromMetaData(meta,
				   EXTRACTOR_FILENAME,
				   EXTRACTOR_TITLE,
				   EXTRACTOR_ARTIST,
				   EXTRACTOR_AUTHOR,
				   EXTRACTOR_PUBLISHER,
				   EXTRACTOR_CREATOR,
				   EXTRACTOR_PRODUCER,
				   EXTRACTOR_UNKNOWN,
				   -1);
  if (name == NULL)
    name = STRDUP(_("no name given")); 
  size = ECRS_fileSize(uri);
  thumb = NULL;
  ts = ECRS_getThumbnailFromMetaData(meta,
				     &thumb);
  if (ts != 0) {
    loader = gdk_pixbuf_loader_new();
    gdk_pixbuf_loader_write(loader,
			    (const guchar*) thumb,
			    ts,
			    NULL);    
    pixbuf = gdk_pixbuf_loader_get_pixbuf(loader);
    gdk_pixbuf_loader_close(loader,
			    NULL);
  } else {
    pixbuf = NULL;
  }
  gtk_tree_store_set(model,
		     pos,
		     SEARCH_NAME, name,
		     SEARCH_SIZE, size,
		     SEARCH_MIME, mime,
		     SEARCH_DESC, desc,
		     SEARCH_PIXBUF, pixbuf,
		     SEARCH_URI, ECRS_dupUri(uri),
		     SEARCH_META, ECRS_dupMetaData(meta),
		     SEARCH_INTERNAL, NULL, /* internal */
		     -1);
  FREE(mime);
  FREE(desc);
  FREE(name);
  FREENONNULL(thumb);
}
			  


/**
 * @brief linked list of pages in the search notebook
 */
typedef struct SL {
  struct SL * next;
  GtkWidget * treeview;
  GtkWidget * searchpage;
  struct ECRS_URI * uri;
} SearchList;

static SearchList * head;

static GtkListStore * summary;

/**
 * Recursively free the (internal) model data fields
 * (uri and meta) from the search tree model.
 */ 
static void freeIterSubtree(GtkTreeModel * tree,
			    GtkTreeIter * iter) {
  GtkTreeIter child;
  struct ECRS_URI * uri;
  struct ECRS_MetaData * meta;

  do {
    uri = NULL;
    meta = NULL;
    gtk_tree_model_get(tree,
		       iter,
		       SEARCH_URI, &uri,
		       SEARCH_META, &meta,
		       -1);
    if (uri != NULL)
      ECRS_freeUri(uri);
    if (meta != NULL)
      ECRS_freeMetaData(meta);
    gtk_tree_store_set(GTK_TREE_STORE(tree),
		       iter,
		       SEARCH_URI, NULL,
		       SEARCH_META, NULL,
		       -1);
    if (gtk_tree_model_iter_children(tree,
				     &child,
				     iter))
      freeIterSubtree(tree, &child);
  } while (gtk_tree_model_iter_next(tree,
				    iter));
    
				 
}

void on_searchResults_destroy(GtkWidget * dummy,
			      GtkWidget * treeview) {
  GtkTreeStore * tree;
  GtkTreeIter iter;
  
  tree = GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(treeview)));
  if (! gtk_tree_model_get_iter_first(GTK_TREE_MODEL(tree),
				      &iter))
    return; /* tree empty */
  freeIterSubtree(GTK_TREE_MODEL(tree),
		  &iter);
}

/**
 * Add the given result to the model (search result
 * list).
 * @param info the information to add to the model
 * @param treeview the page from which to obtain the model
 * @param path the tree path that selects where to add
 *        the information
 */
static void addSearchResultToModel(const ECRS_FileInfo * info,
				   GtkWidget * treeview,
				   GtkTreeRowReference * row) {
  GtkTreeStore * model;
  GtkTreeIter iter;
  GtkTreeIter parent;
  GtkTreeIter * pparent;
  GtkTreePath * path;

  if (! gtk_tree_row_reference_valid(row))
    path = NULL;
  else
    path = gtk_tree_row_reference_get_path(row);
  model = GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(treeview))); 
  if (path != NULL) {
    gtk_tree_model_get_iter(GTK_TREE_MODEL(model),
			    &parent,
			    path);
    pparent = &parent;
  } else      
    pparent = NULL;
  gtk_tree_store_insert(model,
			&iter,
			pparent,
			0);
  addEntryToSearchTree(model,
		       &iter,
		       info->uri,
		       info->meta);
}

/**
 * Add the given result to the model (search result
 * list).
 * @param info the information to add to the model
 * @param uri the search URI
 * @param path the tree path that selects where to add
 *        the information, NULL for top-level
 */
void displaySearchResult(const ECRS_FileInfo * info,
			 const struct ECRS_URI * uri,
			 GtkTreeRowReference * row) {  
  SearchList * list;
  struct ECRS_URI * euri;
  unsigned int count;    
  GtkTreeIter iter;

  list = head;
  while (list != NULL) {
    if (ECRS_equalsUri(list->uri,
		       uri))
      break;
    list = list->next;
  }
  if (list == NULL) {
    BREAK();
    return;
  }
  addSearchResultToModel(info,
			 list->treeview,
			 row);
  
  if (! gtk_tree_model_get_iter_first(GTK_TREE_MODEL(summary),
				      &iter)) {
    BREAK();
    return;
  }
  
  do {	
    gtk_tree_model_get(GTK_TREE_MODEL(summary),
		       &iter,
		       SER_SUM_COUNT, &count,
		       SER_SUM_URI, &euri,
		       -1);
    if (ECRS_equalsUri(euri,
		       uri)) {
      count++;
      gtk_list_store_set(GTK_LIST_STORE(summary),
			 &iter,
			 SER_SUM_COUNT, count,
			 -1);
      return;
    }

  } while (gtk_tree_model_iter_next(GTK_TREE_MODEL(summary),
				    &iter));
  BREAK();
}

void on_closeSearchButton_clicked(GtkWidget * searchPage,
				  GtkWidget * closeButton) {
  GtkWidget * notebook;
  int index;
  int i;
  struct ECRS_URI * uri;
  SearchList * list;
  SearchList * prev;
  GtkTreeIter iter;
  struct ECRS_URI * euri;

  list = head;
  prev = NULL;
  while (list != NULL) {
    if (list->searchpage == searchPage)
      break;
    prev = list;
    list = list->next;
  }
  GNUNET_ASSERT(list != NULL);
  uri = list->uri;
  FSUI_stopSearch(ctx,
		  uri);
  if (prev == NULL)
    head = list->next;
  else
    prev->next = list->next;
  FREE(list);
  
  notebook
    = glade_xml_get_widget(mainXML,
			   "downloadNotebook");
  index = -1;
  for (i=gtk_notebook_get_n_pages(GTK_NOTEBOOK(notebook))-1;i>=0;i--)
    if (searchPage == gtk_notebook_get_nth_page(GTK_NOTEBOOK(notebook),
						i))
      index = i;

  if (index != -1) {
    gtk_notebook_remove_page(GTK_NOTEBOOK(notebook),
			     index);
  } else {
    BREAK();
  }

  if (! gtk_tree_model_get_iter_first(GTK_TREE_MODEL(summary),
				      &iter)) {
    BREAK();
    ECRS_freeUri(uri);
    return;
  }
  do {	
    gtk_tree_model_get(GTK_TREE_MODEL(summary),
		       &iter,
		       SER_SUM_URI, &euri,
		       -1);
    if (ECRS_equalsUri(euri,
		       uri)) {
      gtk_list_store_remove(GTK_LIST_STORE(summary),
			    &iter);
      ECRS_freeUri(euri);
      ECRS_freeUri(uri);
      return;
    }
  } while (gtk_tree_model_iter_next(GTK_TREE_MODEL(summary),
				    &iter));
  ECRS_freeUri(uri);
  BREAK();
}

static GtkWidget * makeResultFrame(GtkWidget ** treeview) {
  GtkWidget * window;
  GtkWidget * child;
  GtkWidget * resultList;
  GtkCellRenderer * renderer;
  GtkTreeStore * tree;
  GladeXML * searchXML;

  searchXML
    = glade_xml_new(gladeFile,
		    "searchResultsFrame", 
		    NULL);
  glade_xml_signal_autoconnect(searchXML);
  window = glade_xml_get_widget(searchXML,
			       "searchResultsFrame");
  resultList = glade_xml_get_widget(searchXML,
				    "searchResults");
  if (treeview != NULL)
    (*treeview) = GTK_WIDGET(GTK_TREE_VIEW(resultList));
  tree =
    gtk_tree_store_new(SEARCH_NUM,
		       G_TYPE_STRING, /* name */
		       G_TYPE_UINT64,  /* size */
		       G_TYPE_STRING, /* mime-type */			     
		       G_TYPE_STRING, /* meta-data (some) */			     
		       GDK_TYPE_PIXBUF, /* preview */			     
		       G_TYPE_POINTER,  /* url */
		       G_TYPE_POINTER,  /* meta */
		       G_TYPE_POINTER); /* internal: download info/NULL */
  gtk_tree_view_set_model(GTK_TREE_VIEW(resultList),
			  GTK_TREE_MODEL(tree));
  renderer = gtk_cell_renderer_text_new();
  gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(resultList),
					      -1,
					      _("Name"),
					      renderer,
					      "text", SEARCH_NAME, 
					      NULL);
  renderer = gtk_cell_renderer_text_new();
  gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(resultList),
					      -1,
					      _("Size"),
					      renderer,
					      "text", SEARCH_SIZE,
					      NULL);
  renderer = gtk_cell_renderer_text_new();
  gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(resultList),
					      -1,
					      _("Mime-type"),
					      renderer,
					      "text", SEARCH_MIME,
					      NULL);
  renderer = gtk_cell_renderer_text_new();
  gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(resultList),
					      -1,
					      _("Meta-data"),
					      renderer,
					      "text", SEARCH_DESC,
					      NULL);
  renderer = gtk_cell_renderer_pixbuf_new();
  gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(resultList),
					      -1,
					      _("Preview"),
					      renderer,
					      "pixbuf", SEARCH_PIXBUF,
					      NULL);
  child = gtk_bin_get_child(GTK_BIN(window));
  gtk_widget_ref(GTK_WIDGET(child));
  gtk_container_remove(GTK_CONTAINER(window),
		       child);
  gtk_widget_destroy(window);
  UNREF(searchXML);

  return child;
}

void on_fssearchbutton_clicked(gpointer dummy2,
			       GtkWidget * searchButton) {
  GtkWidget * searchKeywordGtkCB;
  GtkWidget * searchNamespaceGtkCB;
  GtkWidget * notebook;
  GtkWidget * page;
  GtkWidget * label;
  GtkWidget * entry;
  GtkListStore * model;
  GtkTreeIter iter;
  struct ECRS_URI * uri;
  const char * ss;
  const char * ns;
  gint pages;
  gint i;
  char * tabtxt;
  SearchList * list;

  searchKeywordGtkCB
    = glade_xml_get_widget(mainXML,
			   "fssearchKeywordComboBoxEntry");
  entry = gtk_bin_get_child(GTK_BIN(searchKeywordGtkCB));
  ss = gtk_entry_get_text(GTK_ENTRY(entry));
  if (ss == NULL) {
    LOG(LOG_ERROR,
	"Need a keyword to search!\n");
    return;
  }
  i = gtk_combo_box_get_active(GTK_COMBO_BOX(searchKeywordGtkCB));
  if (i == -1) {
    model = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(searchKeywordGtkCB)));
    gtk_list_store_prepend(model,
			   &iter);
    gtk_list_store_set(model,
		       &iter,
		       0, ss,
		       -1);
  }

  searchNamespaceGtkCB
    = glade_xml_get_widget(mainXML,
			   "searchNamespaceComboBoxEntry");
  entry = gtk_bin_get_child(GTK_BIN(searchNamespaceGtkCB));
  ns = gtk_entry_get_text(GTK_ENTRY(entry));
  if ( (ns != NULL) &&
       (0 == strcmp(ns,
		    _("globally"))) )
    ns = NULL;
  ns = NULL; /* FIXME! */
  if (ns != NULL) {    
    /* FIXME */
  } else {
    uri = FSUI_parseCharKeywordURI(ss);   
  }
  if (uri == NULL)
    return;
  if (ns == NULL) {
    tabtxt = STRDUP(ss);
  } else {
    tabtxt = MALLOC(strlen(ss) + strlen(ns) + 2);
    SNPRINTF(tabtxt,
	     strlen(ss) + strlen(ns) + 2,
	     "%s/%s",
	     ns,
	     ss);
  }
  notebook
    = glade_xml_get_widget(mainXML,
			   "downloadNotebook");
  list = head;
  pages = gtk_notebook_get_n_pages(GTK_NOTEBOOK(notebook));
  while (list != NULL) {
    if (ECRS_equalsUri(list->uri,
		       uri)) {      
      for (i=0;i<pages;i++) {
	page = gtk_notebook_get_nth_page(GTK_NOTEBOOK(notebook),
					 i);
	if (page == list->searchpage) {
	  gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook),
					i);
	  ECRS_freeUri(uri);
	  FREE(tabtxt);
	  return;
	}
      }
      BREAK();
    }
    list = list->next;
  }
  list
    = MALLOC(sizeof(SearchList));
  list->searchpage
    = makeResultFrame(&list->treeview);
  list->next 
    = head;
  list->uri
    = uri;
  head = list;

  gtk_list_store_append(summary,
			&iter);
  gtk_list_store_set(summary,
		     &iter,
		     SER_SUM_NAME, tabtxt,
		     SER_SUM_COUNT, 0,
		     SER_SUM_URI, ECRS_dupUri(uri),
		     -1);

  label = gtk_label_new(tabtxt);
  gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
			   list->searchpage,
			   label);
  gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook),
				pages);
  gtk_widget_show(notebook);
  /* FIXME (later):
     add widget to allow anonymity level specification! */
  FSUI_startSearch(ctx,
		   getConfigurationInt("GNUNET-GTK",
				       "ANONYMITY-LEVEL"),
		   uri);
  FREE(tabtxt);
}

static int addNamespace(GtkListStore * model,
			const char * namespaceName,
			const HashCode512 * namespaceId,
			const struct ECRS_MetaData * md,
			int rating) {
  GtkTreeIter iter;
  EncName enc;
  char * name;
  
  hash2enc(namespaceId,
	   &enc);
  name = MALLOC(strlen(namespaceName) + sizeof(EncName) + 2);
  SNPRINTF(name,
	   strlen(namespaceName) + sizeof(EncName) + 2,
	   "%s: %s",
	   &enc,
	   namespaceName);
  gtk_list_store_append(model,
			&iter);
  gtk_list_store_set(model,
		     &iter,
		     0,
		     name,
		     -1);
  FREE(name);		     
  return OK;
}

/**
 * cron job that periodically updates the model for the
 * namespace selection in the search vbox.
 */
static gint updateNCBModelSafe(SaveCall * call) {
  GtkWidget * searchNamespaceCB;
  GtkListStore * model;
  GtkTreeIter iter;
 
  model = gtk_list_store_new(1, G_TYPE_STRING);
  gtk_list_store_append(model,
			&iter);
  gtk_list_store_set(model,
		     &iter,
		     0, _("globally"),
		     -1);
  FSUI_listNamespaces(ctx,
		      NO,
		      (FSUI_NamespaceIterator)&addNamespace,
		      model);
  searchNamespaceCB
    = glade_xml_get_widget(mainXML,
			   "searchNamespaceComboBoxEntry");
  gtk_combo_box_set_model(GTK_COMBO_BOX(searchNamespaceCB),
			  GTK_TREE_MODEL(model));
  if (gtk_combo_box_entry_get_text_column(GTK_COMBO_BOX_ENTRY(searchNamespaceCB)) == -1)
    gtk_combo_box_entry_set_text_column(GTK_COMBO_BOX_ENTRY(searchNamespaceCB),
					0);
  if (-1 == gtk_combo_box_get_active(GTK_COMBO_BOX(searchNamespaceCB)))
    gtk_combo_box_set_active(GTK_COMBO_BOX(searchNamespaceCB),
			     0);
  gtkSaveCallDone(call->sem);
  return FALSE;
}

static void updateNCBModel(void * call) {
  gtkSaveCall((GtkFunction) updateNCBModelSafe, NULL);
}

/**
 * Open a tab for the given search
 * (and display the results).
 */
static int openTabForSearch(void * unused,
			    const struct ECRS_URI * uri,
			    unsigned int anonymityLevel,
			    unsigned int resultCount,
			    const ECRS_FileInfo * results) {
  SearchList * list;
  char * description;
  char * dhead;
  GtkWidget * label;
  GtkWidget * notebook;
  GtkTreeStore * model;
  GtkTreeIter iter;
  int i;

  description = ECRS_uriToString(uri);
  if (description == NULL) {
    BREAK();
    return SYSERR;
  }
  GNUNET_ASSERT(strlen(description) >= strlen(ECRS_URI_PREFIX));
  dhead = &description[strlen(ECRS_URI_PREFIX)];
  if (0 == strncmp(dhead,
		   ECRS_SEARCH_INFIX,
		   strlen(ECRS_SEARCH_INFIX)))
    dhead = &dhead[strlen(ECRS_SEARCH_INFIX)];
  else if (0 == strncmp(dhead,
			ECRS_SUBSPACE_INFIX,
			strlen(ECRS_SUBSPACE_INFIX)))
    dhead = &dhead[strlen(ECRS_SUBSPACE_INFIX)];    
  label = gtk_label_new(dhead);

  gtk_list_store_append(summary,
			&iter);
  gtk_list_store_set(summary,
		     &iter,
		     SER_SUM_NAME, dhead,
		     SER_SUM_COUNT, resultCount,
		     SER_SUM_URI, ECRS_dupUri(uri),
		     -1);

  FREE(description);
  list = MALLOC(sizeof(SearchList));
  list->uri = ECRS_dupUri(uri);
  list->next = head;
  list->searchpage
    = makeResultFrame(&list->treeview);
  notebook
    = glade_xml_get_widget(mainXML,
			   "downloadNotebook");
  gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
			   list->searchpage,
			   label);
  gtk_widget_show(notebook);
  head = list;
  model = GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(list->treeview)));
  for (i=0;i<resultCount;i++) {
    addSearchResultToModel(&results[i],
			   list->treeview,
			   NULL);
  }
  return OK;
}


void fs_search_start() {
  GtkWidget * searchCB;
  GtkListStore * model;
  GtkWidget * searchList;
  GtkCellRenderer * renderer;

  searchCB
    = glade_xml_get_widget(mainXML,
			   "fssearchKeywordComboBoxEntry");

  model = gtk_list_store_new(1, G_TYPE_STRING);
  gtk_combo_box_set_model(GTK_COMBO_BOX(searchCB),
			  GTK_TREE_MODEL(model));
  gtk_combo_box_entry_set_text_column(GTK_COMBO_BOX_ENTRY(searchCB),
				      0);
  addCronJob(&updateNCBModel,
	     0,
	     5 * cronMINUTES,
	     NULL);

  searchList = glade_xml_get_widget(mainXML,
				    "activeSearchesSummary");
  summary =
    gtk_list_store_new(SER_SUM_NUM,
		       G_TYPE_STRING, /* name */
		       G_TYPE_INT,    /* # results */
		       G_TYPE_POINTER);  /* internal: uri */
  gtk_tree_view_set_model(GTK_TREE_VIEW(searchList),
			  GTK_TREE_MODEL(summary));
  renderer = gtk_cell_renderer_text_new();
  gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(searchList),
					      -1,
					      _("Query"),
					      renderer,
					      "text", SER_SUM_NAME,
					      NULL);
  renderer = gtk_cell_renderer_text_new();
  gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(searchList),
					      -1,
					      _("Results"),
					      renderer,
					      "text", SER_SUM_COUNT,
					      NULL);

  FSUI_listSearches(ctx,
		    &openTabForSearch,
		    NULL);
}

void fs_search_stop() {
  SearchList * list;

  delCronJob(&updateNCBModel,
	     5 * cronMINUTES,
	     NULL);
  while (head != NULL) {
    list = head;
    head = head->next;
    ECRS_freeUri(list->uri);
    FREE(list);
  }
  
}

/* end of search.c */