diff options
Diffstat (limited to 'src/plugins/fs/search.c')
-rw-r--r-- | src/plugins/fs/search.c | 164 |
1 files changed, 10 insertions, 154 deletions
diff --git a/src/plugins/fs/search.c b/src/plugins/fs/search.c index f1d7e325..ab78d844 100644 --- a/src/plugins/fs/search.c +++ b/src/plugins/fs/search.c | |||
@@ -61,33 +61,14 @@ on_fssearchSelectionChanged (gpointer signal, gpointer cls) | |||
61 | /* **************** FSUI event handling ****************** */ | 61 | /* **************** FSUI event handling ****************** */ |
62 | 62 | ||
63 | /** | 63 | /** |
64 | * Update the number of results received for the given | 64 | * Update the number of results received in the label of the tab. |
65 | * search in the summary and in the label of the tab. | ||
66 | */ | 65 | */ |
67 | static void | 66 | static void |
68 | updateSearchSummary (SearchList * searchContext) | 67 | updateResultsCount (SearchList * searchContext) |
69 | { | 68 | { |
70 | GtkTreePath *path; | ||
71 | GtkTreeIter iter; | ||
72 | char *new_title; | 69 | char *new_title; |
73 | GtkLabel *label; | 70 | GtkLabel *label; |
74 | 71 | ||
75 | path = | ||
76 | gtk_tree_row_reference_get_path (searchContext->summaryViewRowReference); | ||
77 | if (TRUE != | ||
78 | gtk_tree_model_get_iter (GTK_TREE_MODEL (search_summary), &iter, path)) | ||
79 | { | ||
80 | GNUNET_GE_BREAK (ectx, 0); | ||
81 | return; | ||
82 | } | ||
83 | gtk_tree_path_free (path); | ||
84 | gtk_list_store_set (search_summary, | ||
85 | &iter, | ||
86 | SEARCH_SUMMARY_RESULT_COUNT, | ||
87 | searchContext->resultsReceived, -1); | ||
88 | |||
89 | |||
90 | |||
91 | /* update tab title with the number of results */ | 72 | /* update tab title with the number of results */ |
92 | new_title = | 73 | new_title = |
93 | g_strdup_printf ("%.*s%s (%u)", | 74 | g_strdup_printf ("%.*s%s (%u)", |
@@ -336,7 +317,7 @@ fs_search_result_received (SearchList * searchContext, | |||
336 | gtk_tree_store_append (model, &iter, NULL); | 317 | gtk_tree_store_append (model, &iter, NULL); |
337 | addEntryToSearchTree (searchContext, NULL, info, &iter); | 318 | addEntryToSearchTree (searchContext, NULL, info, &iter); |
338 | searchContext->resultsReceived++; | 319 | searchContext->resultsReceived++; |
339 | updateSearchSummary (searchContext); | 320 | updateResultsCount (searchContext); |
340 | } | 321 | } |
341 | 322 | ||
342 | /** | 323 | /** |
@@ -644,8 +625,7 @@ search_click_handler (void *cls, GdkEvent * event) | |||
644 | } | 625 | } |
645 | 626 | ||
646 | /** | 627 | /** |
647 | * FSUI event: a search was started; create the | 628 | * FSUI event: a search was started; create the tab |
648 | * tab and add an entry to the summary. | ||
649 | */ | 629 | */ |
650 | SearchList * | 630 | SearchList * |
651 | fs_search_started (struct GNUNET_FSUI_SearchList * fsui_list, | 631 | fs_search_started (struct GNUNET_FSUI_SearchList * fsui_list, |
@@ -661,8 +641,6 @@ fs_search_started (struct GNUNET_FSUI_SearchList * fsui_list, | |||
661 | GtkTreeViewColumn *column; | 641 | GtkTreeViewColumn *column; |
662 | GtkCellRenderer *renderer; | 642 | GtkCellRenderer *renderer; |
663 | GtkNotebook *notebook; | 643 | GtkNotebook *notebook; |
664 | GtkTreePath *path; | ||
665 | GtkTreeIter iter; | ||
666 | int col; | 644 | int col; |
667 | unsigned int i; | 645 | unsigned int i; |
668 | 646 | ||
@@ -680,7 +658,7 @@ fs_search_started (struct GNUNET_FSUI_SearchList * fsui_list, | |||
680 | for (i = 0; i < resultCount; i++) | 658 | for (i = 0; i < resultCount; i++) |
681 | fs_search_result_received (list, &results[i], uri); | 659 | fs_search_result_received (list, &results[i], uri); |
682 | if (resultCount == 0) /* otherwise already done! */ | 660 | if (resultCount == 0) /* otherwise already done! */ |
683 | updateSearchSummary (list); | 661 | updateResultsCount (list); |
684 | return list; | 662 | return list; |
685 | } | 663 | } |
686 | list = list->next; | 664 | list = list->next; |
@@ -888,18 +866,6 @@ fs_search_started (struct GNUNET_FSUI_SearchList * fsui_list, | |||
888 | gtk_tree_view_column_set_reorderable (column, TRUE); | 866 | gtk_tree_view_column_set_reorderable (column, TRUE); |
889 | gtk_tree_view_column_set_sort_column_id (column, SEARCH_DESC); | 867 | gtk_tree_view_column_set_sort_column_id (column, SEARCH_DESC); |
890 | 868 | ||
891 | /* add entry in search summary */ | ||
892 | gtk_list_store_append (search_summary, &iter); | ||
893 | gtk_list_store_set (search_summary, | ||
894 | &iter, | ||
895 | SEARCH_SUMMARY_NAME, description, | ||
896 | SEARCH_SUMMARY_RESULT_COUNT, 0, | ||
897 | SEARCH_SUMMARY_INTERNAL, list, -1); | ||
898 | path = gtk_tree_model_get_path (GTK_TREE_MODEL (search_summary), &iter); | ||
899 | list->summaryViewRowReference | ||
900 | = gtk_tree_row_reference_new (GTK_TREE_MODEL (search_summary), path); | ||
901 | gtk_tree_path_free (path); | ||
902 | |||
903 | /* load label */ | 869 | /* load label */ |
904 | list->labelXML | 870 | list->labelXML |
905 | = glade_xml_new (GNUNET_GTK_get_glade_filename (), | 871 | = glade_xml_new (GNUNET_GTK_get_glade_filename (), |
@@ -913,7 +879,7 @@ fs_search_started (struct GNUNET_FSUI_SearchList * fsui_list, | |||
913 | for (i = 0; i < resultCount; i++) | 879 | for (i = 0; i < resultCount; i++) |
914 | fs_search_result_received (list, &results[i], uri); | 880 | fs_search_result_received (list, &results[i], uri); |
915 | if (resultCount == 0) /* otherwise already done! */ | 881 | if (resultCount == 0) /* otherwise already done! */ |
916 | updateSearchSummary (list); | 882 | updateResultsCount (list); |
917 | 883 | ||
918 | /* insert new page into search notebook */ | 884 | /* insert new page into search notebook */ |
919 | notebook | 885 | notebook |
@@ -983,17 +949,15 @@ fs_search_restarted (SearchList * list) | |||
983 | } | 949 | } |
984 | 950 | ||
985 | /** | 951 | /** |
986 | * FSUI event: a search was stopped. Remove the | 952 | * FSUI event: a search was stopped. |
987 | * respective tab and its entry in the summary. | 953 | * Remove the respective tab. |
988 | */ | 954 | */ |
989 | void | 955 | void |
990 | fs_search_stopped (SearchList * list) | 956 | fs_search_stopped (SearchList * list) |
991 | { | 957 | { |
992 | GtkNotebook *notebook; | 958 | GtkNotebook *notebook; |
993 | GtkTreeIter iter; | ||
994 | SearchList *prev; | 959 | SearchList *prev; |
995 | DownloadList *downloads; | 960 | DownloadList *downloads; |
996 | GtkTreePath *path; | ||
997 | int index; | 961 | int index; |
998 | int i; | 962 | int i; |
999 | 963 | ||
@@ -1034,19 +998,9 @@ fs_search_stopped (SearchList * list) | |||
1034 | index = i; | 998 | index = i; |
1035 | GNUNET_GE_BREAK (ectx, index != -1); | 999 | GNUNET_GE_BREAK (ectx, index != -1); |
1036 | gtk_notebook_remove_page (notebook, index); | 1000 | gtk_notebook_remove_page (notebook, index); |
1037 | /* recursively free search model */ | ||
1038 | if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list->tree), &iter)) | ||
1039 | freeIterSubtree (GTK_TREE_MODEL (list->tree), &iter); | ||
1040 | |||
1041 | /* destroy entry in summary */ | ||
1042 | path = gtk_tree_row_reference_get_path (list->summaryViewRowReference); | ||
1043 | gtk_tree_model_get_iter (GTK_TREE_MODEL (search_summary), &iter, path); | ||
1044 | gtk_tree_path_free (path); | ||
1045 | gtk_list_store_remove (search_summary, &iter); | ||
1046 | /* free list state itself */ | 1001 | /* free list state itself */ |
1047 | UNREF (list->searchXML); | 1002 | UNREF (list->searchXML); |
1048 | UNREF (list->labelXML); | 1003 | UNREF (list->labelXML); |
1049 | gtk_tree_row_reference_free (list->summaryViewRowReference); | ||
1050 | GNUNET_free (list->searchString); | 1004 | GNUNET_free (list->searchString); |
1051 | GNUNET_ECRS_uri_destroy (list->uri); | 1005 | GNUNET_ECRS_uri_destroy (list->uri); |
1052 | GNUNET_free (list); | 1006 | GNUNET_free (list); |
@@ -1286,7 +1240,7 @@ on_closeSearchButton_clicked_fs (GtkWidget * searchPage, | |||
1286 | 1240 | ||
1287 | 1241 | ||
1288 | /** | 1242 | /** |
1289 | * The abort button in the search summary was clicked. | 1243 | * The pause button in a search results tab was clicked. |
1290 | */ | 1244 | */ |
1291 | void | 1245 | void |
1292 | on_searchPauseButton_clicked_fs (GtkWidget * searchPage, | 1246 | on_searchPauseButton_clicked_fs (GtkWidget * searchPage, |
@@ -1315,7 +1269,7 @@ on_searchPauseButton_clicked_fs (GtkWidget * searchPage, | |||
1315 | } | 1269 | } |
1316 | 1270 | ||
1317 | /** | 1271 | /** |
1318 | * The abort button in the search summary was clicked. | 1272 | * The resume button in a search results tab was clicked. |
1319 | */ | 1273 | */ |
1320 | void | 1274 | void |
1321 | on_searchResumeButton_clicked_fs (GtkWidget * searchPage, | 1275 | on_searchResumeButton_clicked_fs (GtkWidget * searchPage, |
@@ -1343,102 +1297,4 @@ on_searchResumeButton_clicked_fs (GtkWidget * searchPage, | |||
1343 | } | 1297 | } |
1344 | } | 1298 | } |
1345 | 1299 | ||
1346 | /** | ||
1347 | * The abort button was clicked. Abort the search. | ||
1348 | */ | ||
1349 | void | ||
1350 | on_abortSearchButton_clicked_fs (GtkWidget * searchPage, | ||
1351 | GtkWidget * abortButton) | ||
1352 | { | ||
1353 | SearchList *list; | ||
1354 | struct FCBC fcbc; | ||
1355 | |||
1356 | list = search_head; | ||
1357 | while (list != NULL) | ||
1358 | { | ||
1359 | if (list->searchpage == searchPage) | ||
1360 | break; | ||
1361 | list = list->next; | ||
1362 | } | ||
1363 | GNUNET_GE_ASSERT (ectx, list != NULL); | ||
1364 | gtk_widget_hide (abortButton); | ||
1365 | if (list->fsui_list != NULL) | ||
1366 | { | ||
1367 | fcbc.method = &GNUNET_FSUI_search_abort; | ||
1368 | fcbc.argument = list->fsui_list; | ||
1369 | GNUNET_GTK_run_with_save_calls (&fsui_callback, &fcbc); | ||
1370 | } | ||
1371 | } | ||
1372 | |||
1373 | static void | ||
1374 | stopSearch (GtkTreeModel * model, | ||
1375 | GtkTreePath * path, GtkTreeIter * iter, gpointer unused) | ||
1376 | { | ||
1377 | SearchList *s; | ||
1378 | struct FCBC fcbc; | ||
1379 | |||
1380 | s = NULL; | ||
1381 | gtk_tree_model_get (model, iter, SEARCH_SUMMARY_INTERNAL, &s, -1); | ||
1382 | if (s != NULL) | ||
1383 | { | ||
1384 | if (s->fsui_list == NULL) | ||
1385 | { | ||
1386 | /* open directory - close directly */ | ||
1387 | fs_search_stopped (s); | ||
1388 | } | ||
1389 | else | ||
1390 | { | ||
1391 | fcbc.method = &GNUNET_FSUI_search_abort; | ||
1392 | fcbc.argument = s->fsui_list; | ||
1393 | GNUNET_GTK_run_with_save_calls (&fsui_callback, &fcbc); | ||
1394 | fcbc.method = &GNUNET_FSUI_search_stop; | ||
1395 | GNUNET_GTK_run_with_save_calls (&fsui_callback, &fcbc); | ||
1396 | } | ||
1397 | } | ||
1398 | } | ||
1399 | |||
1400 | /** | ||
1401 | * The stop button in the search summary was clicked. | ||
1402 | */ | ||
1403 | void | ||
1404 | on_closeSearchSummaryButton_clicked_fs (GtkWidget * treeview, | ||
1405 | GtkWidget * closeButton) | ||
1406 | { | ||
1407 | GtkTreeSelection *selection; | ||
1408 | |||
1409 | selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)); | ||
1410 | GNUNET_GTK_tree_selection_selected_foreach (selection, &stopSearch, NULL); | ||
1411 | } | ||
1412 | |||
1413 | static void | ||
1414 | abortSearch (GtkTreeModel * model, | ||
1415 | GtkTreePath * path, GtkTreeIter * iter, gpointer unused) | ||
1416 | { | ||
1417 | SearchList *s; | ||
1418 | struct FCBC fcbc; | ||
1419 | |||
1420 | s = NULL; | ||
1421 | gtk_tree_model_get (model, iter, SEARCH_SUMMARY_INTERNAL, &s, -1); | ||
1422 | if ((s != NULL) && (s->fsui_list != NULL)) | ||
1423 | { | ||
1424 | fcbc.method = &GNUNET_FSUI_search_abort; | ||
1425 | fcbc.argument = s->fsui_list; | ||
1426 | GNUNET_GTK_run_with_save_calls (&fsui_callback, &fcbc); | ||
1427 | } | ||
1428 | } | ||
1429 | |||
1430 | /** | ||
1431 | * The abort button in the search summary was clicked. | ||
1432 | */ | ||
1433 | void | ||
1434 | on_abortSearchSummaryButton_clicked_fs (GtkWidget * treeview, | ||
1435 | GtkWidget * closeButton) | ||
1436 | { | ||
1437 | GtkTreeSelection *selection; | ||
1438 | |||
1439 | selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)); | ||
1440 | GNUNET_GTK_tree_selection_selected_foreach (selection, &abortSearch, NULL); | ||
1441 | } | ||
1442 | |||
1443 | |||
1444 | /* end of search.c */ | 1300 | /* end of search.c */ |