diff options
Diffstat (limited to 'src/plugins/fs/search.c')
-rw-r--r-- | src/plugins/fs/search.c | 133 |
1 files changed, 119 insertions, 14 deletions
diff --git a/src/plugins/fs/search.c b/src/plugins/fs/search.c index ea21c639..a78dd430 100644 --- a/src/plugins/fs/search.c +++ b/src/plugins/fs/search.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) 2005, 2006, 2007 Christian Grothoff (and other contributing authors) | 3 | (C) 2005, 2006, 2007, 2008 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -164,6 +164,7 @@ fs_search_result_received (SearchList * searchContext, | |||
164 | GtkTreeStore *model; | 164 | GtkTreeStore *model; |
165 | GtkTreeIter iter; | 165 | GtkTreeIter iter; |
166 | enum GNUNET_URITRACK_STATE state; | 166 | enum GNUNET_URITRACK_STATE state; |
167 | struct GNUNET_ECRS_URI * have; | ||
167 | 168 | ||
168 | state = GNUNET_URITRACK_get_state (ectx, cfg, info->uri); | 169 | state = GNUNET_URITRACK_get_state (ectx, cfg, info->uri); |
169 | if ((state & (GNUNET_URITRACK_INSERTED | | 170 | if ((state & (GNUNET_URITRACK_INSERTED | |
@@ -174,6 +175,20 @@ fs_search_result_received (SearchList * searchContext, | |||
174 | GNUNET_YES))) | 175 | GNUNET_YES))) |
175 | return; | 176 | return; |
176 | model = GTK_TREE_STORE (gtk_tree_view_get_model (searchContext->treeview)); | 177 | model = GTK_TREE_STORE (gtk_tree_view_get_model (searchContext->treeview)); |
178 | /* Check that the entry does not already exist (for resume!) */ | ||
179 | if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (model), &iter)) | ||
180 | { | ||
181 | do | ||
182 | { | ||
183 | have = NULL; | ||
184 | gtk_tree_model_get (GTK_TREE_MODEL(model), | ||
185 | &iter, SEARCH_URI, &have, -1); | ||
186 | if ( (have != NULL) && | ||
187 | (GNUNET_ECRS_uri_test_equal(have, uri)) ) | ||
188 | return; /* duplicate */ | ||
189 | } | ||
190 | while (gtk_tree_model_iter_next (GTK_TREE_MODEL(model), &iter)); | ||
191 | } | ||
177 | gtk_tree_store_append (model, &iter, NULL); | 192 | gtk_tree_store_append (model, &iter, NULL); |
178 | addEntryToSearchTree (searchContext, NULL, info, &iter); | 193 | addEntryToSearchTree (searchContext, NULL, info, &iter); |
179 | searchContext->resultsReceived++; | 194 | searchContext->resultsReceived++; |
@@ -384,6 +399,28 @@ fs_search_started (struct GNUNET_FSUI_SearchList * fsui_list, | |||
384 | int col; | 399 | int col; |
385 | int i; | 400 | int i; |
386 | 401 | ||
402 | /* check that search does not already exist | ||
403 | with fsui_list == NULL; | ||
404 | (and if so, hijack!) */ | ||
405 | list = search_head; | ||
406 | while (list != NULL) | ||
407 | { | ||
408 | if ( (list->fsui_list == NULL) && | ||
409 | (list->uri != NULL) && | ||
410 | (GNUNET_ECRS_uri_test_equal(list->uri, | ||
411 | uri)) ) | ||
412 | { | ||
413 | list->fsui_list = fsui_list; | ||
414 | for (i = 0; i < resultCount; i++) | ||
415 | fs_search_result_received (list, &results[i], uri); | ||
416 | if (resultCount == 0) /* otherwise already done! */ | ||
417 | updateSearchSummary (list); | ||
418 | return list; | ||
419 | } | ||
420 | list = list->next; | ||
421 | } | ||
422 | |||
423 | /* build new entry */ | ||
387 | description = GNUNET_ECRS_uri_to_string (uri); | 424 | description = GNUNET_ECRS_uri_to_string (uri); |
388 | if (description == NULL) | 425 | if (description == NULL) |
389 | { | 426 | { |
@@ -407,6 +444,8 @@ fs_search_started (struct GNUNET_FSUI_SearchList * fsui_list, | |||
407 | list->uri = GNUNET_ECRS_uri_duplicate (uri); | 444 | list->uri = GNUNET_ECRS_uri_duplicate (uri); |
408 | list->fsui_list = fsui_list; | 445 | list->fsui_list = fsui_list; |
409 | list->next = search_head; | 446 | list->next = search_head; |
447 | list->anonymityLevel = anonymityLevel; | ||
448 | |||
410 | search_head = list; | 449 | search_head = list; |
411 | list->searchXML | 450 | list->searchXML |
412 | = | 451 | = |
@@ -604,7 +643,12 @@ freeIterSubtree (GtkTreeModel * tree, GtkTreeIter * iter) | |||
604 | void | 643 | void |
605 | fs_search_aborted (SearchList * list) | 644 | fs_search_aborted (SearchList * list) |
606 | { | 645 | { |
607 | /* FIXME: show aborted status somehow! */ | 646 | gtk_widget_show(glade_xml_get_widget(list->searchXML, |
647 | "searchResumeButton")); | ||
648 | gtk_widget_show(glade_xml_get_widget(list->searchXML, | ||
649 | "searchAbortButton")); | ||
650 | gtk_widget_show(glade_xml_get_widget(list->searchXML, | ||
651 | "searchPauseButton")); | ||
608 | } | 652 | } |
609 | 653 | ||
610 | /** | 654 | /** |
@@ -622,6 +666,14 @@ fs_search_stopped (SearchList * list) | |||
622 | int index; | 666 | int index; |
623 | int i; | 667 | int i; |
624 | 668 | ||
669 | if (list->is_paused == GNUNET_YES) | ||
670 | { | ||
671 | /* if this was just a request to pause, | ||
672 | then simply ignore the FS-stopped event */ | ||
673 | list->fsui_list = NULL; | ||
674 | list->is_paused = GNUNET_NO; | ||
675 | return; | ||
676 | } | ||
625 | /* remove from linked list */ | 677 | /* remove from linked list */ |
626 | if (search_head == list) | 678 | if (search_head == list) |
627 | { | 679 | { |
@@ -701,8 +753,6 @@ on_fssearchKeywordComboBoxEntry_changed_fs (gpointer dummy2, | |||
701 | typedef struct | 753 | typedef struct |
702 | { | 754 | { |
703 | unsigned int anonymity; | 755 | unsigned int anonymity; |
704 | unsigned int max; | ||
705 | GNUNET_CronTime delay; | ||
706 | struct GNUNET_ECRS_URI *uri; | 756 | struct GNUNET_ECRS_URI *uri; |
707 | } FSSS; | 757 | } FSSS; |
708 | 758 | ||
@@ -710,7 +760,7 @@ static void * | |||
710 | search_start_helper (void *cls) | 760 | search_start_helper (void *cls) |
711 | { | 761 | { |
712 | FSSS *fsss = cls; | 762 | FSSS *fsss = cls; |
713 | GNUNET_FSUI_search_start (ctx, fsss->anonymity, fsss->max, fsss->delay, | 763 | GNUNET_FSUI_search_start (ctx, fsss->anonymity, |
714 | fsss->uri); | 764 | fsss->uri); |
715 | return NULL; | 765 | return NULL; |
716 | } | 766 | } |
@@ -846,13 +896,7 @@ on_fssearchbutton_clicked_fs (gpointer dummy2, GtkWidget * searchButton) | |||
846 | list = list->next; | 896 | list = list->next; |
847 | } | 897 | } |
848 | fsss.anonymity = getSpinButtonValue (GNUNET_GTK_get_main_glade_XML (), | 898 | fsss.anonymity = getSpinButtonValue (GNUNET_GTK_get_main_glade_XML (), |
849 | "searchAnonymitySelectionSpinButton"); | 899 | "searchAnonymitySelectionSpinButton"); |
850 | fsss.max = | ||
851 | getSpinButtonValue (GNUNET_GTK_get_main_glade_XML (), | ||
852 | "maxResultsSpinButton"); | ||
853 | fsss.delay = | ||
854 | getSpinButtonValue (GNUNET_GTK_get_main_glade_XML (), | ||
855 | "searchDelaySpinButton") * GNUNET_CRON_SECONDS; | ||
856 | GNUNET_GTK_run_with_save_calls (search_start_helper, &fsss); | 900 | GNUNET_GTK_run_with_save_calls (search_start_helper, &fsss); |
857 | GNUNET_ECRS_uri_destroy (fsss.uri); | 901 | GNUNET_ECRS_uri_destroy (fsss.uri); |
858 | } | 902 | } |
@@ -897,7 +941,8 @@ on_closeSearchButton_clicked_fs (GtkWidget * searchPage, | |||
897 | GNUNET_GE_ASSERT (ectx, list != NULL); | 941 | GNUNET_GE_ASSERT (ectx, list != NULL); |
898 | if (list->fsui_list == NULL) | 942 | if (list->fsui_list == NULL) |
899 | { | 943 | { |
900 | /* open directory - close directly */ | 944 | /* open directory or paused search; |
945 | close directly */ | ||
901 | fs_search_stopped (list); | 946 | fs_search_stopped (list); |
902 | } | 947 | } |
903 | else | 948 | else |
@@ -911,12 +956,70 @@ on_closeSearchButton_clicked_fs (GtkWidget * searchPage, | |||
911 | } | 956 | } |
912 | } | 957 | } |
913 | 958 | ||
959 | |||
960 | /** | ||
961 | * The abort button in the search summary was clicked. | ||
962 | */ | ||
963 | void | ||
964 | on_searchPauseButton_clicked_fs (GtkWidget * searchPage, | ||
965 | GtkWidget * pauseButton) | ||
966 | { | ||
967 | SearchList *list; | ||
968 | struct FCBC fcbc; | ||
969 | |||
970 | list = search_head; | ||
971 | while (list != NULL) | ||
972 | { | ||
973 | if (list->searchpage == searchPage) | ||
974 | break; | ||
975 | list = list->next; | ||
976 | } | ||
977 | GNUNET_GE_ASSERT (ectx, list != NULL); | ||
978 | gtk_widget_hide(pauseButton); | ||
979 | gtk_widget_show(glade_xml_get_widget(list->searchXML, | ||
980 | "searchResumeButton")); | ||
981 | if (list->fsui_list != NULL) | ||
982 | { | ||
983 | list->is_paused = GNUNET_YES; | ||
984 | fcbc.method = &GNUNET_FSUI_search_stop; | ||
985 | fcbc.argument = list->fsui_list; | ||
986 | GNUNET_GTK_run_with_save_calls (&fsui_callback, &fcbc); | ||
987 | } | ||
988 | } | ||
989 | |||
990 | /** | ||
991 | * The abort button in the search summary was clicked. | ||
992 | */ | ||
993 | void | ||
994 | on_searchResumeButton_clicked_fs (GtkWidget * searchPage, | ||
995 | GtkWidget * resumeButton) | ||
996 | { | ||
997 | FSSS fsss; | ||
998 | SearchList *list; | ||
999 | |||
1000 | list = search_head; | ||
1001 | while (list != NULL) | ||
1002 | { | ||
1003 | if (list->searchpage == searchPage) | ||
1004 | break; | ||
1005 | list = list->next; | ||
1006 | } | ||
1007 | GNUNET_GE_ASSERT (ectx, list != NULL); | ||
1008 | gtk_widget_hide(resumeButton); | ||
1009 | gtk_widget_show(glade_xml_get_widget(list->searchXML, | ||
1010 | "searchPauseButton")); | ||
1011 | fsss.anonymity = getSpinButtonValue (GNUNET_GTK_get_main_glade_XML (), | ||
1012 | "searchAnonymitySelectionSpinButton"); | ||
1013 | fsss.uri = list->uri; | ||
1014 | GNUNET_GTK_run_with_save_calls (search_start_helper, &fsss); | ||
1015 | } | ||
1016 | |||
914 | /** | 1017 | /** |
915 | * The abort button was clicked. Abort the search. | 1018 | * The abort button was clicked. Abort the search. |
916 | */ | 1019 | */ |
917 | void | 1020 | void |
918 | on_abortSearchButton_clicked_fs (GtkWidget * searchPage, | 1021 | on_abortSearchButton_clicked_fs (GtkWidget * searchPage, |
919 | GtkWidget * closeButton) | 1022 | GtkWidget * abortButton) |
920 | { | 1023 | { |
921 | SearchList *list; | 1024 | SearchList *list; |
922 | struct FCBC fcbc; | 1025 | struct FCBC fcbc; |
@@ -929,6 +1032,7 @@ on_abortSearchButton_clicked_fs (GtkWidget * searchPage, | |||
929 | list = list->next; | 1032 | list = list->next; |
930 | } | 1033 | } |
931 | GNUNET_GE_ASSERT (ectx, list != NULL); | 1034 | GNUNET_GE_ASSERT (ectx, list != NULL); |
1035 | gtk_widget_hide(abortButton); | ||
932 | if (list->fsui_list != NULL) | 1036 | if (list->fsui_list != NULL) |
933 | { | 1037 | { |
934 | fcbc.method = &GNUNET_FSUI_search_abort; | 1038 | fcbc.method = &GNUNET_FSUI_search_abort; |
@@ -1007,4 +1111,5 @@ on_abortSearchSummaryButton_clicked_fs (GtkWidget * treeview, | |||
1007 | GNUNET_GTK_tree_selection_selected_foreach (selection, &abortSearch, NULL); | 1111 | GNUNET_GTK_tree_selection_selected_foreach (selection, &abortSearch, NULL); |
1008 | } | 1112 | } |
1009 | 1113 | ||
1114 | |||
1010 | /* end of search.c */ | 1115 | /* end of search.c */ |