diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-08-02 12:37:20 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-08-02 12:37:20 +0000 |
commit | cf478fc82697865a857fb2997ff59c978c53bef4 (patch) | |
tree | 36ac00802e607d8e7a50f441a986493b852c37c4 | |
parent | cf346fbf170cf6c8bb497d16a37effe500892ecc (diff) | |
download | gnunet-gtk-cf478fc82697865a857fb2997ff59c978c53bef4.tar.gz gnunet-gtk-cf478fc82697865a857fb2997ff59c978c53bef4.zip |
done
-rw-r--r-- | src/fs_event_handler.c | 166 | ||||
-rw-r--r-- | src/fs_event_handler.h | 6 |
2 files changed, 152 insertions, 20 deletions
diff --git a/src/fs_event_handler.c b/src/fs_event_handler.c index 9e6598d4..dc46c61f 100644 --- a/src/fs_event_handler.c +++ b/src/fs_event_handler.c | |||
@@ -74,6 +74,11 @@ struct PublishEntry | |||
74 | */ | 74 | */ |
75 | GtkTreeRowReference *rr; | 75 | GtkTreeRowReference *rr; |
76 | 76 | ||
77 | /** | ||
78 | * URI of the file (set after completion). | ||
79 | */ | ||
80 | struct GNUNET_FS_Uri *uri; | ||
81 | |||
77 | int is_top; | 82 | int is_top; |
78 | }; | 83 | }; |
79 | 84 | ||
@@ -313,12 +318,40 @@ mark_download_progress (struct DownloadEntry *de, | |||
313 | 318 | ||
314 | 319 | ||
315 | static struct DownloadEntry * | 320 | static struct DownloadEntry * |
321 | mark_download_error (struct DownloadEntry *de, | ||
322 | const char *emsg) | ||
323 | { | ||
324 | GtkTreeIter iter; | ||
325 | GtkTreePath *path; | ||
326 | |||
327 | de = change_download_colour (de, | ||
328 | "red"); | ||
329 | de->is_done = GNUNET_YES; | ||
330 | path = gtk_tree_row_reference_get_path (de->rr); | ||
331 | if (TRUE != gtk_tree_model_get_iter (GTK_TREE_MODEL (de->tab->ts), | ||
332 | &iter, path)) | ||
333 | { | ||
334 | GNUNET_break (0); | ||
335 | gtk_tree_path_free (path); | ||
336 | return de; | ||
337 | } | ||
338 | gtk_tree_path_free (path); | ||
339 | gtk_tree_store_set (de->tab->ts, &iter, | ||
340 | 4, 0, | ||
341 | 7, emsg, | ||
342 | -1); | ||
343 | return de; | ||
344 | } | ||
345 | |||
346 | |||
347 | static struct DownloadEntry * | ||
316 | mark_download_completed (struct DownloadEntry *de, | 348 | mark_download_completed (struct DownloadEntry *de, |
317 | uint64_t size, | 349 | uint64_t size, |
318 | const char *filename) | 350 | const char *filename) |
319 | { | 351 | { |
320 | struct AddDirectoryEntryContext ade; | 352 | struct AddDirectoryEntryContext ade; |
321 | 353 | ||
354 | de->is_done = GNUNET_YES; | ||
322 | (void) mark_download_progress (de, size, size, NULL, 0, 0, 0); | 355 | (void) mark_download_progress (de, size, size, NULL, 0, 0, 0); |
323 | if ( (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (de->meta)) && | 356 | if ( (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (de->meta)) && |
324 | (filename != NULL) ) | 357 | (filename != NULL) ) |
@@ -838,6 +871,32 @@ close_search_tab (struct SearchTab *tab) | |||
838 | } | 871 | } |
839 | 872 | ||
840 | 873 | ||
874 | /** | ||
875 | * Close a publish tab and free associated state. | ||
876 | */ | ||
877 | static struct PublishEntry * | ||
878 | handle_publish_completed (struct PublishEntry *ent, | ||
879 | const struct GNUNET_FS_Uri *uri) | ||
880 | { | ||
881 | ent->uri = GNUNET_FS_uri_dup (uri); | ||
882 | return change_publish_colour (ent, | ||
883 | "green"); | ||
884 | } | ||
885 | |||
886 | |||
887 | |||
888 | /** | ||
889 | * Handle error. | ||
890 | */ | ||
891 | static struct PublishEntry * | ||
892 | handle_publish_error (struct PublishEntry *ent, | ||
893 | const char *emsg) | ||
894 | { | ||
895 | GNUNET_break (0); | ||
896 | return change_publish_colour (ent, | ||
897 | "red"); | ||
898 | } | ||
899 | |||
841 | 900 | ||
842 | /** | 901 | /** |
843 | * Close a publish tab and free associated state. | 902 | * Close a publish tab and free associated state. |
@@ -862,6 +921,8 @@ close_publish_tab (struct PublishEntry *ent) | |||
862 | return; | 921 | return; |
863 | } | 922 | } |
864 | tab = ent->tab; | 923 | tab = ent->tab; |
924 | if (ent->uri != NULL) | ||
925 | GNUNET_FS_uri_destroy (ent->uri); | ||
865 | GNUNET_free (ent); | 926 | GNUNET_free (ent); |
866 | notebook = GTK_NOTEBOOK (GNUNET_GTK_get_main_window_object ("GNUNET_GTK_main_window_notebook")); | 927 | notebook = GTK_NOTEBOOK (GNUNET_GTK_get_main_window_object ("GNUNET_GTK_main_window_notebook")); |
867 | index = -1; | 928 | index = -1; |
@@ -905,8 +966,25 @@ clear_downloads (GtkButton *button, | |||
905 | gpointer user_data) | 966 | gpointer user_data) |
906 | { | 967 | { |
907 | struct SearchTab *tab = user_data; | 968 | struct SearchTab *tab = user_data; |
969 | struct SearchResult *sr; | ||
970 | GtkTreeModel *tm; | ||
971 | GtkTreeIter iter; | ||
908 | 972 | ||
909 | GNUNET_assert (tab != NULL); | 973 | tm = GTK_TREE_MODEL (tab->ts); |
974 | if (TRUE != gtk_tree_model_get_iter_first (tm, &iter)) | ||
975 | return; | ||
976 | do | ||
977 | { | ||
978 | gtk_tree_model_get (tm, &iter, | ||
979 | 9, &sr, | ||
980 | -1); | ||
981 | if ( (sr->download != NULL) && | ||
982 | (sr->download->is_done == GNUNET_YES) ) | ||
983 | GNUNET_FS_download_stop (sr->download->dc, | ||
984 | GNUNET_YES); | ||
985 | } | ||
986 | while (TRUE == gtk_tree_model_iter_next (tm, &iter)); | ||
987 | |||
910 | GNUNET_break (0); /* not implemented */ | 988 | GNUNET_break (0); /* not implemented */ |
911 | } | 989 | } |
912 | 990 | ||
@@ -1010,8 +1088,6 @@ setup_search (struct GNUNET_FS_SearchContext *sc, | |||
1010 | "_search_result_label_clear_button")); | 1088 | "_search_result_label_clear_button")); |
1011 | g_signal_connect(G_OBJECT(tab->clear_button), "clicked", | 1089 | g_signal_connect(G_OBJECT(tab->clear_button), "clicked", |
1012 | G_CALLBACK(clear_downloads), tab); | 1090 | G_CALLBACK(clear_downloads), tab); |
1013 | /* FIXME: clear not implemented, hence not visible... */ | ||
1014 | gtk_widget_set_visible (tab->clear_button, FALSE); | ||
1015 | tab->play_button = GTK_WIDGET (gtk_builder_get_object (tab->builder, | 1091 | tab->play_button = GTK_WIDGET (gtk_builder_get_object (tab->builder, |
1016 | "_search_result_label_play_button")); | 1092 | "_search_result_label_play_button")); |
1017 | g_signal_connect(G_OBJECT(tab->play_button), "clicked", | 1093 | g_signal_connect(G_OBJECT(tab->play_button), "clicked", |
@@ -1247,6 +1323,16 @@ GNUNET_GTK_add_to_uri_tab (GtkTreeIter *iter, | |||
1247 | } | 1323 | } |
1248 | 1324 | ||
1249 | 1325 | ||
1326 | static struct SearchTab * | ||
1327 | handle_search_error (struct SearchTab *sr, | ||
1328 | const char *emsg) | ||
1329 | { | ||
1330 | /* FIXME: implement error handler */ | ||
1331 | GNUNET_break (0); | ||
1332 | return sr; | ||
1333 | } | ||
1334 | |||
1335 | |||
1250 | static struct SearchResult * | 1336 | static struct SearchResult * |
1251 | update_search_result (struct SearchResult *sr, | 1337 | update_search_result (struct SearchResult *sr, |
1252 | const struct GNUNET_CONTAINER_MetaData *meta, | 1338 | const struct GNUNET_CONTAINER_MetaData *meta, |
@@ -1499,6 +1585,8 @@ void* | |||
1499 | GNUNET_GTK_fs_event_handler (void *cls, | 1585 | GNUNET_GTK_fs_event_handler (void *cls, |
1500 | const struct GNUNET_FS_ProgressInfo *info) | 1586 | const struct GNUNET_FS_ProgressInfo *info) |
1501 | { | 1587 | { |
1588 | void *ret; | ||
1589 | |||
1502 | switch (info->status) | 1590 | switch (info->status) |
1503 | { | 1591 | { |
1504 | case GNUNET_FS_STATUS_PUBLISH_START: | 1592 | case GNUNET_FS_STATUS_PUBLISH_START: |
@@ -1507,8 +1595,21 @@ GNUNET_GTK_fs_event_handler (void *cls, | |||
1507 | info->value.publish.size, | 1595 | info->value.publish.size, |
1508 | info->value.publish.pctx); | 1596 | info->value.publish.pctx); |
1509 | case GNUNET_FS_STATUS_PUBLISH_RESUME: | 1597 | case GNUNET_FS_STATUS_PUBLISH_RESUME: |
1510 | GNUNET_break (0); | 1598 | ret = setup_publish (info->value.publish.pc, |
1511 | break; | 1599 | info->value.publish.filename, |
1600 | info->value.publish.size, | ||
1601 | info->value.publish.pctx); | ||
1602 | if (info->value.publish.specifics.resume.message != NULL) | ||
1603 | { | ||
1604 | ret = handle_publish_error (ret, | ||
1605 | info->value.publish.specifics.resume.message); | ||
1606 | } | ||
1607 | else if (info->value.publish.specifics.resume.chk_uri != NULL) | ||
1608 | { | ||
1609 | ret = handle_publish_completed (ret, | ||
1610 | info->value.publish.specifics.resume.chk_uri); | ||
1611 | } | ||
1612 | return ret; | ||
1512 | case GNUNET_FS_STATUS_PUBLISH_SUSPEND: | 1613 | case GNUNET_FS_STATUS_PUBLISH_SUSPEND: |
1513 | close_publish_tab (info->value.publish.cctx); | 1614 | close_publish_tab (info->value.publish.cctx); |
1514 | return NULL; | 1615 | return NULL; |
@@ -1517,11 +1618,11 @@ GNUNET_GTK_fs_event_handler (void *cls, | |||
1517 | info->value.publish.size, | 1618 | info->value.publish.size, |
1518 | info->value.publish.completed); | 1619 | info->value.publish.completed); |
1519 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | 1620 | case GNUNET_FS_STATUS_PUBLISH_ERROR: |
1520 | GNUNET_break (0); | 1621 | return handle_publish_error (info->value.publish.cctx, |
1521 | break; | 1622 | info->value.publish.specifics.error.message); |
1522 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: | 1623 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: |
1523 | return change_publish_colour (info->value.publish.cctx, | 1624 | return handle_publish_completed (info->value.publish.cctx, |
1524 | "green"); | 1625 | info->value.publish.specifics.completed.chk_uri); |
1525 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: | 1626 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: |
1526 | close_publish_tab (info->value.publish.cctx); | 1627 | close_publish_tab (info->value.publish.cctx); |
1527 | return NULL; | 1628 | return NULL; |
@@ -1535,8 +1636,20 @@ GNUNET_GTK_fs_event_handler (void *cls, | |||
1535 | info->value.download.size, | 1636 | info->value.download.size, |
1536 | info->value.download.completed); | 1637 | info->value.download.completed); |
1537 | case GNUNET_FS_STATUS_DOWNLOAD_RESUME: | 1638 | case GNUNET_FS_STATUS_DOWNLOAD_RESUME: |
1538 | GNUNET_break (0); | 1639 | ret = setup_download (info->value.download.cctx, |
1539 | break; | 1640 | info->value.download.pctx, |
1641 | info->value.download.sctx, | ||
1642 | info->value.download.dc, | ||
1643 | info->value.download.uri, | ||
1644 | info->value.download.specifics.resume.meta, | ||
1645 | info->value.download.size, | ||
1646 | info->value.download.completed); | ||
1647 | if (info->value.download.specifics.resume.message != NULL) | ||
1648 | { | ||
1649 | ret = mark_download_error (ret, | ||
1650 | info->value.download.specifics.resume.message); | ||
1651 | } | ||
1652 | return ret; | ||
1540 | case GNUNET_FS_STATUS_DOWNLOAD_SUSPEND: | 1653 | case GNUNET_FS_STATUS_DOWNLOAD_SUSPEND: |
1541 | stop_download (info->value.download.cctx, GNUNET_YES); | 1654 | stop_download (info->value.download.cctx, GNUNET_YES); |
1542 | return NULL; | 1655 | return NULL; |
@@ -1549,8 +1662,8 @@ GNUNET_GTK_fs_event_handler (void *cls, | |||
1549 | info->value.download.specifics.progress.data_len, | 1662 | info->value.download.specifics.progress.data_len, |
1550 | info->value.download.specifics.progress.depth); | 1663 | info->value.download.specifics.progress.depth); |
1551 | case GNUNET_FS_STATUS_DOWNLOAD_ERROR: | 1664 | case GNUNET_FS_STATUS_DOWNLOAD_ERROR: |
1552 | return change_download_colour (info->value.download.cctx, | 1665 | return mark_download_error (info->value.download.cctx, |
1553 | "red"); | 1666 | info->value.download.specifics.error.message); |
1554 | case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: | 1667 | case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: |
1555 | return mark_download_completed (info->value.download.cctx, | 1668 | return mark_download_completed (info->value.download.cctx, |
1556 | info->value.download.size, | 1669 | info->value.download.size, |
@@ -1578,11 +1691,24 @@ GNUNET_GTK_fs_event_handler (void *cls, | |||
1578 | return setup_search (info->value.search.sc, | 1691 | return setup_search (info->value.search.sc, |
1579 | info->value.search.query); | 1692 | info->value.search.query); |
1580 | case GNUNET_FS_STATUS_SEARCH_RESUME: | 1693 | case GNUNET_FS_STATUS_SEARCH_RESUME: |
1581 | GNUNET_break (0); | 1694 | ret = setup_search (info->value.search.sc, |
1582 | break; | 1695 | info->value.search.query); |
1696 | if (info->value.search.specifics.resume.message) | ||
1697 | ret = handle_search_error (ret, | ||
1698 | info->value.search.specifics.resume.message); | ||
1699 | return ret; | ||
1583 | case GNUNET_FS_STATUS_SEARCH_RESUME_RESULT: | 1700 | case GNUNET_FS_STATUS_SEARCH_RESUME_RESULT: |
1584 | GNUNET_break (0); | 1701 | ret = process_search_result (info->value.search.cctx, |
1585 | break; | 1702 | info->value.search.pctx, |
1703 | info->value.search.specifics.resume_result.uri, | ||
1704 | info->value.search.specifics.resume_result.meta, | ||
1705 | info->value.search.specifics.resume_result.result, | ||
1706 | info->value.search.specifics.resume_result.applicability_rank); | ||
1707 | return update_search_result (ret, | ||
1708 | info->value.search.specifics.resume_result.meta, | ||
1709 | info->value.search.specifics.resume_result.applicability_rank, | ||
1710 | info->value.search.specifics.resume_result.availability_certainty, | ||
1711 | info->value.search.specifics.resume_result.availability_rank); | ||
1586 | case GNUNET_FS_STATUS_SEARCH_SUSPEND: | 1712 | case GNUNET_FS_STATUS_SEARCH_SUSPEND: |
1587 | close_search_tab (info->value.search.cctx); | 1713 | close_search_tab (info->value.search.cctx); |
1588 | return NULL; | 1714 | return NULL; |
@@ -1603,8 +1729,8 @@ GNUNET_GTK_fs_event_handler (void *cls, | |||
1603 | info->value.search.specifics.update.availability_certainty, | 1729 | info->value.search.specifics.update.availability_certainty, |
1604 | info->value.search.specifics.update.availability_rank); | 1730 | info->value.search.specifics.update.availability_rank); |
1605 | case GNUNET_FS_STATUS_SEARCH_ERROR: | 1731 | case GNUNET_FS_STATUS_SEARCH_ERROR: |
1606 | GNUNET_break (0); | 1732 | return handle_search_error (info->value.search.cctx, |
1607 | break; | 1733 | info->value.search.specifics.error.message); |
1608 | case GNUNET_FS_STATUS_SEARCH_PAUSED: | 1734 | case GNUNET_FS_STATUS_SEARCH_PAUSED: |
1609 | return info->value.search.cctx; | 1735 | return info->value.search.cctx; |
1610 | case GNUNET_FS_STATUS_SEARCH_CONTINUED: | 1736 | case GNUNET_FS_STATUS_SEARCH_CONTINUED: |
diff --git a/src/fs_event_handler.h b/src/fs_event_handler.h index 155df2cd..c5152ef2 100644 --- a/src/fs_event_handler.h +++ b/src/fs_event_handler.h | |||
@@ -117,6 +117,12 @@ struct DownloadEntry | |||
117 | * Tab where this download is currently on display. | 117 | * Tab where this download is currently on display. |
118 | */ | 118 | */ |
119 | struct SearchTab *tab; | 119 | struct SearchTab *tab; |
120 | |||
121 | /** | ||
122 | * Has the download completed (or errored)? | ||
123 | */ | ||
124 | int is_done; | ||
125 | |||
120 | }; | 126 | }; |
121 | 127 | ||
122 | 128 | ||