diff options
Diffstat (limited to 'src/plugins/fs/search.c')
-rw-r--r-- | src/plugins/fs/search.c | 464 |
1 files changed, 235 insertions, 229 deletions
diff --git a/src/plugins/fs/search.c b/src/plugins/fs/search.c index cb292e22..acb046c6 100644 --- a/src/plugins/fs/search.c +++ b/src/plugins/fs/search.c | |||
@@ -34,235 +34,7 @@ | |||
34 | #include <GNUnet/gnunet_util_crypto.h> | 34 | #include <GNUnet/gnunet_util_crypto.h> |
35 | #include <GNUnet/gnunet_namespace_lib.h> | 35 | #include <GNUnet/gnunet_namespace_lib.h> |
36 | 36 | ||
37 | /** | 37 | /* **************** FSUI event handling ****************** */ |
38 | * The user has clicked the "SEARCH" button. | ||
39 | * Initiate a search. | ||
40 | */ | ||
41 | void on_fssearchbutton_clicked_fs(gpointer dummy2, | ||
42 | GtkWidget * searchButton) { | ||
43 | struct ECRS_URI * uri; | ||
44 | const char * searchString; | ||
45 | gint pages; | ||
46 | gint i; | ||
47 | SearchList * list; | ||
48 | GtkTreeIter iter; | ||
49 | GtkComboBox * searchKeywordGtkCB; | ||
50 | GtkWidget * searchNamespaceGtkCB; | ||
51 | GtkNotebook * notebook; | ||
52 | |||
53 | searchString = getEntryLineValue(getMainXML(), | ||
54 | "fssearchKeywordComboBoxEntry"); | ||
55 | if (searchString == NULL) { | ||
56 | GE_LOG(ectx, | ||
57 | GE_ERROR | GE_USER | GE_IMMEDIATE, | ||
58 | _("Need a keyword to search!\n")); | ||
59 | return; | ||
60 | } | ||
61 | /* add the keyword to the list of keywords that have | ||
62 | been used so far */ | ||
63 | searchKeywordGtkCB | ||
64 | = GTK_COMBO_BOX(glade_xml_get_widget(getMainXML(), | ||
65 | "fssearchKeywordComboBoxEntry")); | ||
66 | i = gtk_combo_box_get_active(searchKeywordGtkCB); | ||
67 | if (i == -1) { | ||
68 | GtkListStore * model; | ||
69 | |||
70 | model = GTK_LIST_STORE(gtk_combo_box_get_model(searchKeywordGtkCB)); | ||
71 | gtk_list_store_prepend(model, | ||
72 | &iter); | ||
73 | gtk_list_store_set(model, | ||
74 | &iter, | ||
75 | 0, searchString, | ||
76 | -1); | ||
77 | } | ||
78 | uri = NULL; | ||
79 | /* check for namespace search */ | ||
80 | searchNamespaceGtkCB | ||
81 | = glade_xml_get_widget(getMainXML(), | ||
82 | "searchNamespaceComboBoxEntry"); | ||
83 | if (TRUE == gtk_combo_box_get_active_iter(GTK_COMBO_BOX(searchNamespaceGtkCB), | ||
84 | &iter)) { | ||
85 | const char * descStr; | ||
86 | const char * ns; | ||
87 | |||
88 | ns = NULL; | ||
89 | descStr = NULL; | ||
90 | gtk_tree_model_get(gtk_combo_box_get_model(GTK_COMBO_BOX(searchNamespaceGtkCB)), | ||
91 | &iter, | ||
92 | NS_SEARCH_DESCRIPTION, &descStr, | ||
93 | NS_SEARCH_ENCNAME, &ns, | ||
94 | -1); | ||
95 | |||
96 | if ( (descStr != NULL) && | ||
97 | (0 == strcmp(descStr, | ||
98 | _("globally"))) ) { | ||
99 | ns = NULL; | ||
100 | } else { | ||
101 | GE_ASSERT(ectx, strlen(ns) == sizeof(EncName) - 1); | ||
102 | if (descStr == NULL) | ||
103 | descStr = ns; | ||
104 | } | ||
105 | if (ns != NULL) { | ||
106 | char * ustring; | ||
107 | |||
108 | ustring = MALLOC(strlen(searchString) + sizeof(EncName) + | ||
109 | strlen(ECRS_URI_PREFIX) + | ||
110 | strlen(ECRS_SUBSPACE_INFIX) + 10); | ||
111 | strcpy(ustring, ECRS_URI_PREFIX); | ||
112 | strcat(ustring, ECRS_SUBSPACE_INFIX); | ||
113 | strcat(ustring, ns); | ||
114 | strcat(ustring, "/"); | ||
115 | strcat(ustring, searchString); | ||
116 | uri = ECRS_stringToUri(ectx, ustring); | ||
117 | if (uri == NULL) { | ||
118 | GE_LOG(ectx, | ||
119 | GE_ERROR | GE_BULK | GE_USER, | ||
120 | _("Failed to create namespace URI from `%s'.\n"), | ||
121 | ustring); | ||
122 | } | ||
123 | FREE(ustring); | ||
124 | } | ||
125 | } | ||
126 | if (uri == NULL) | ||
127 | uri = ECRS_parseCharKeywordURI(ectx, searchString); | ||
128 | if (uri == NULL) { | ||
129 | GE_BREAK(ectx, 0); | ||
130 | return; | ||
131 | } | ||
132 | /* check if search is already running */ | ||
133 | notebook | ||
134 | = GTK_NOTEBOOK(glade_xml_get_widget(getMainXML(), | ||
135 | "downloadNotebook")); | ||
136 | pages = gtk_notebook_get_n_pages(notebook); | ||
137 | list = search_head; | ||
138 | while (list != NULL) { | ||
139 | if (ECRS_equalsUri(list->uri, | ||
140 | uri)) { | ||
141 | for (i=0;i<pages;i++) { | ||
142 | if (gtk_notebook_get_nth_page(notebook, | ||
143 | i) | ||
144 | == list->searchpage) { | ||
145 | gtk_notebook_set_current_page(notebook, | ||
146 | i); | ||
147 | ECRS_freeUri(uri); | ||
148 | return; | ||
149 | } | ||
150 | } | ||
151 | GE_BREAK(ectx, 0); | ||
152 | } | ||
153 | list = list->next; | ||
154 | } | ||
155 | FSUI_startSearch(ctx, | ||
156 | getSpinButtonValue(getMainXML(), | ||
157 | "searchAnonymitySelectionSpinButton"), | ||
158 | getSpinButtonValue(getMainXML(), | ||
159 | "maxResultsSpinButton"), | ||
160 | getSpinButtonValue(getMainXML(), | ||
161 | "searchDelaySpinButton") * cronSECONDS, | ||
162 | uri); | ||
163 | } | ||
164 | |||
165 | /** | ||
166 | * This method is called when the user clicks on either | ||
167 | * the "CLOSE" button (at the bottom of the search page) | ||
168 | * or on the "CANCEL (X)" button in the TAB of the | ||
169 | * search notebook. Note that "searchPage" can thus | ||
170 | * either refer to the main page in the tab or to the | ||
171 | * main entry of the tab label. | ||
172 | */ | ||
173 | void on_closeSearchButton_clicked_fs(GtkWidget * searchPage, | ||
174 | GtkWidget * closeButton) { | ||
175 | SearchList * list; | ||
176 | |||
177 | list = search_head; | ||
178 | while (list != NULL) { | ||
179 | if ( (list->searchpage == searchPage) || | ||
180 | (list->tab_label == searchPage) ) | ||
181 | break; | ||
182 | list = list->next; | ||
183 | } | ||
184 | GE_ASSERT(ectx, list != NULL); | ||
185 | FSUI_stopSearch(ctx, | ||
186 | list->fsui_list); | ||
187 | } | ||
188 | |||
189 | /** | ||
190 | * The abort button was clicked. Abort the search. | ||
191 | */ | ||
192 | void on_abortSearchButton_clicked_fs(GtkWidget * searchPage, | ||
193 | GtkWidget * closeButton) { | ||
194 | SearchList * list; | ||
195 | |||
196 | list = search_head; | ||
197 | while (list != NULL) { | ||
198 | if (list->searchpage == searchPage) | ||
199 | break; | ||
200 | list = list->next; | ||
201 | } | ||
202 | GE_ASSERT(ectx, list != NULL); | ||
203 | FSUI_abortSearch(ctx, | ||
204 | list->fsui_list); | ||
205 | } | ||
206 | |||
207 | static void stopSearch(GtkTreeModel * model, | ||
208 | GtkTreePath * path, | ||
209 | GtkTreeIter * iter, | ||
210 | gpointer unused) { | ||
211 | SearchList * s; | ||
212 | |||
213 | s = NULL; | ||
214 | gtk_tree_model_get(model, | ||
215 | iter, | ||
216 | SEARCH_SUMMARY_INTERNAL, &s, | ||
217 | -1); | ||
218 | if (s != NULL) | ||
219 | FSUI_stopSearch(ctx, | ||
220 | s->fsui_list); | ||
221 | } | ||
222 | |||
223 | /** | ||
224 | * The stop button in the search summary was clicked. | ||
225 | */ | ||
226 | void on_closeSearchSummaryButton_clicked_fs(GtkWidget * treeview, | ||
227 | GtkWidget * closeButton) { | ||
228 | GtkTreeSelection * selection; | ||
229 | |||
230 | selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); | ||
231 | gtk_tree_selection_selected_foreach | ||
232 | (selection, | ||
233 | &stopSearch, | ||
234 | NULL); | ||
235 | } | ||
236 | |||
237 | static void abortSearch(GtkTreeModel * model, | ||
238 | GtkTreePath * path, | ||
239 | GtkTreeIter * iter, | ||
240 | gpointer unused) { | ||
241 | SearchList * s; | ||
242 | |||
243 | s = NULL; | ||
244 | gtk_tree_model_get(model, | ||
245 | iter, | ||
246 | SEARCH_SUMMARY_INTERNAL, &s, | ||
247 | -1); | ||
248 | if (s != NULL) | ||
249 | FSUI_abortSearch(ctx, | ||
250 | s->fsui_list); | ||
251 | } | ||
252 | |||
253 | /** | ||
254 | * The abort button in the search summary was clicked. | ||
255 | */ | ||
256 | void on_abortSearchSummaryButton_clicked_fs(GtkWidget * treeview, | ||
257 | GtkWidget * closeButton) { | ||
258 | GtkTreeSelection * selection; | ||
259 | |||
260 | selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); | ||
261 | gtk_tree_selection_selected_foreach | ||
262 | (selection, | ||
263 | &abortSearch, | ||
264 | NULL); | ||
265 | } | ||
266 | 38 | ||
267 | /** | 39 | /** |
268 | * Update the number of results received for the given | 40 | * Update the number of results received for the given |
@@ -685,5 +457,239 @@ void fs_search_stopped(SearchList * list) { | |||
685 | FREE(list); | 457 | FREE(list); |
686 | } | 458 | } |
687 | 459 | ||
460 | /* ****************** User event handling ************* */ | ||
461 | |||
462 | |||
463 | /** | ||
464 | * The user has clicked the "SEARCH" button. | ||
465 | * Initiate a search. | ||
466 | */ | ||
467 | void on_fssearchbutton_clicked_fs(gpointer dummy2, | ||
468 | GtkWidget * searchButton) { | ||
469 | struct ECRS_URI * uri; | ||
470 | const char * searchString; | ||
471 | gint pages; | ||
472 | gint i; | ||
473 | SearchList * list; | ||
474 | GtkTreeIter iter; | ||
475 | GtkComboBox * searchKeywordGtkCB; | ||
476 | GtkWidget * searchNamespaceGtkCB; | ||
477 | GtkNotebook * notebook; | ||
478 | |||
479 | searchString = getEntryLineValue(getMainXML(), | ||
480 | "fssearchKeywordComboBoxEntry"); | ||
481 | if (searchString == NULL) { | ||
482 | GE_LOG(ectx, | ||
483 | GE_ERROR | GE_USER | GE_IMMEDIATE, | ||
484 | _("Need a keyword to search!\n")); | ||
485 | return; | ||
486 | } | ||
487 | /* add the keyword to the list of keywords that have | ||
488 | been used so far */ | ||
489 | searchKeywordGtkCB | ||
490 | = GTK_COMBO_BOX(glade_xml_get_widget(getMainXML(), | ||
491 | "fssearchKeywordComboBoxEntry")); | ||
492 | i = gtk_combo_box_get_active(searchKeywordGtkCB); | ||
493 | if (i == -1) { | ||
494 | GtkListStore * model; | ||
495 | |||
496 | model = GTK_LIST_STORE(gtk_combo_box_get_model(searchKeywordGtkCB)); | ||
497 | gtk_list_store_prepend(model, | ||
498 | &iter); | ||
499 | gtk_list_store_set(model, | ||
500 | &iter, | ||
501 | 0, searchString, | ||
502 | -1); | ||
503 | } | ||
504 | uri = NULL; | ||
505 | /* check for namespace search */ | ||
506 | searchNamespaceGtkCB | ||
507 | = glade_xml_get_widget(getMainXML(), | ||
508 | "searchNamespaceComboBoxEntry"); | ||
509 | if (TRUE == gtk_combo_box_get_active_iter(GTK_COMBO_BOX(searchNamespaceGtkCB), | ||
510 | &iter)) { | ||
511 | const char * descStr; | ||
512 | const char * ns; | ||
513 | |||
514 | ns = NULL; | ||
515 | descStr = NULL; | ||
516 | gtk_tree_model_get(gtk_combo_box_get_model(GTK_COMBO_BOX(searchNamespaceGtkCB)), | ||
517 | &iter, | ||
518 | NS_SEARCH_DESCRIPTION, &descStr, | ||
519 | NS_SEARCH_ENCNAME, &ns, | ||
520 | -1); | ||
521 | |||
522 | if ( (descStr != NULL) && | ||
523 | (0 == strcmp(descStr, | ||
524 | _("globally"))) ) { | ||
525 | ns = NULL; | ||
526 | } else { | ||
527 | GE_ASSERT(ectx, strlen(ns) == sizeof(EncName) - 1); | ||
528 | if (descStr == NULL) | ||
529 | descStr = ns; | ||
530 | } | ||
531 | if (ns != NULL) { | ||
532 | char * ustring; | ||
533 | |||
534 | ustring = MALLOC(strlen(searchString) + sizeof(EncName) + | ||
535 | strlen(ECRS_URI_PREFIX) + | ||
536 | strlen(ECRS_SUBSPACE_INFIX) + 10); | ||
537 | strcpy(ustring, ECRS_URI_PREFIX); | ||
538 | strcat(ustring, ECRS_SUBSPACE_INFIX); | ||
539 | strcat(ustring, ns); | ||
540 | strcat(ustring, "/"); | ||
541 | strcat(ustring, searchString); | ||
542 | uri = ECRS_stringToUri(ectx, ustring); | ||
543 | if (uri == NULL) { | ||
544 | GE_LOG(ectx, | ||
545 | GE_ERROR | GE_BULK | GE_USER, | ||
546 | _("Failed to create namespace URI from `%s'.\n"), | ||
547 | ustring); | ||
548 | } | ||
549 | FREE(ustring); | ||
550 | } | ||
551 | } | ||
552 | if (uri == NULL) | ||
553 | uri = ECRS_parseCharKeywordURI(ectx, searchString); | ||
554 | if (uri == NULL) { | ||
555 | GE_BREAK(ectx, 0); | ||
556 | return; | ||
557 | } | ||
558 | /* check if search is already running */ | ||
559 | notebook | ||
560 | = GTK_NOTEBOOK(glade_xml_get_widget(getMainXML(), | ||
561 | "downloadNotebook")); | ||
562 | pages = gtk_notebook_get_n_pages(notebook); | ||
563 | list = search_head; | ||
564 | while (list != NULL) { | ||
565 | if (ECRS_equalsUri(list->uri, | ||
566 | uri)) { | ||
567 | for (i=0;i<pages;i++) { | ||
568 | if (gtk_notebook_get_nth_page(notebook, | ||
569 | i) | ||
570 | == list->searchpage) { | ||
571 | gtk_notebook_set_current_page(notebook, | ||
572 | i); | ||
573 | ECRS_freeUri(uri); | ||
574 | return; | ||
575 | } | ||
576 | } | ||
577 | GE_BREAK(ectx, 0); | ||
578 | } | ||
579 | list = list->next; | ||
580 | } | ||
581 | FSUI_startSearch(ctx, | ||
582 | getSpinButtonValue(getMainXML(), | ||
583 | "searchAnonymitySelectionSpinButton"), | ||
584 | getSpinButtonValue(getMainXML(), | ||
585 | "maxResultsSpinButton"), | ||
586 | getSpinButtonValue(getMainXML(), | ||
587 | "searchDelaySpinButton") * cronSECONDS, | ||
588 | uri); | ||
589 | } | ||
590 | |||
591 | /** | ||
592 | * This method is called when the user clicks on either | ||
593 | * the "CLOSE" button (at the bottom of the search page) | ||
594 | * or on the "CANCEL (X)" button in the TAB of the | ||
595 | * search notebook. Note that "searchPage" can thus | ||
596 | * either refer to the main page in the tab or to the | ||
597 | * main entry of the tab label. | ||
598 | */ | ||
599 | void on_closeSearchButton_clicked_fs(GtkWidget * searchPage, | ||
600 | GtkWidget * closeButton) { | ||
601 | SearchList * list; | ||
602 | |||
603 | list = search_head; | ||
604 | while (list != NULL) { | ||
605 | if ( (list->searchpage == searchPage) || | ||
606 | (list->tab_label == searchPage) ) | ||
607 | break; | ||
608 | list = list->next; | ||
609 | } | ||
610 | GE_ASSERT(ectx, list != NULL); | ||
611 | FSUI_stopSearch(ctx, | ||
612 | list->fsui_list); | ||
613 | } | ||
614 | |||
615 | /** | ||
616 | * The abort button was clicked. Abort the search. | ||
617 | */ | ||
618 | void on_abortSearchButton_clicked_fs(GtkWidget * searchPage, | ||
619 | GtkWidget * closeButton) { | ||
620 | SearchList * list; | ||
621 | |||
622 | list = search_head; | ||
623 | while (list != NULL) { | ||
624 | if (list->searchpage == searchPage) | ||
625 | break; | ||
626 | list = list->next; | ||
627 | } | ||
628 | GE_ASSERT(ectx, list != NULL); | ||
629 | FSUI_abortSearch(ctx, | ||
630 | list->fsui_list); | ||
631 | } | ||
632 | |||
633 | static void stopSearch(GtkTreeModel * model, | ||
634 | GtkTreePath * path, | ||
635 | GtkTreeIter * iter, | ||
636 | gpointer unused) { | ||
637 | SearchList * s; | ||
638 | |||
639 | s = NULL; | ||
640 | gtk_tree_model_get(model, | ||
641 | iter, | ||
642 | SEARCH_SUMMARY_INTERNAL, &s, | ||
643 | -1); | ||
644 | if (s != NULL) | ||
645 | FSUI_stopSearch(ctx, | ||
646 | s->fsui_list); | ||
647 | } | ||
648 | |||
649 | /** | ||
650 | * The stop button in the search summary was clicked. | ||
651 | */ | ||
652 | void on_closeSearchSummaryButton_clicked_fs(GtkWidget * treeview, | ||
653 | GtkWidget * closeButton) { | ||
654 | GtkTreeSelection * selection; | ||
655 | |||
656 | selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); | ||
657 | gtk_tree_selection_selected_foreach | ||
658 | (selection, | ||
659 | &stopSearch, | ||
660 | NULL); | ||
661 | } | ||
662 | |||
663 | static void abortSearch(GtkTreeModel * model, | ||
664 | GtkTreePath * path, | ||
665 | GtkTreeIter * iter, | ||
666 | gpointer unused) { | ||
667 | SearchList * s; | ||
668 | |||
669 | s = NULL; | ||
670 | gtk_tree_model_get(model, | ||
671 | iter, | ||
672 | SEARCH_SUMMARY_INTERNAL, &s, | ||
673 | -1); | ||
674 | if (s != NULL) | ||
675 | FSUI_abortSearch(ctx, | ||
676 | s->fsui_list); | ||
677 | } | ||
678 | |||
679 | /** | ||
680 | * The abort button in the search summary was clicked. | ||
681 | */ | ||
682 | void on_abortSearchSummaryButton_clicked_fs(GtkWidget * treeview, | ||
683 | GtkWidget * closeButton) { | ||
684 | GtkTreeSelection * selection; | ||
685 | |||
686 | selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); | ||
687 | gtk_tree_selection_selected_foreach | ||
688 | (selection, | ||
689 | &abortSearch, | ||
690 | NULL); | ||
691 | } | ||
692 | |||
693 | |||
688 | 694 | ||
689 | /* end of search.c */ | 695 | /* end of search.c */ |