aboutsummaryrefslogtreecommitdiff
path: root/src/fs/gnunet-fs-gtk-event_handler.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/gnunet-fs-gtk-event_handler.c')
-rw-r--r--src/fs/gnunet-fs-gtk-event_handler.c210
1 files changed, 115 insertions, 95 deletions
diff --git a/src/fs/gnunet-fs-gtk-event_handler.c b/src/fs/gnunet-fs-gtk-event_handler.c
index 0e6d6f1b..77508240 100644
--- a/src/fs/gnunet-fs-gtk-event_handler.c
+++ b/src/fs/gnunet-fs-gtk-event_handler.c
@@ -34,25 +34,20 @@ static struct SearchTab *search_tab_tail;
34 34
35struct PublishTab 35struct PublishTab
36{ 36{
37 /**
38 * This is a doubly-linked list.
39 */
40 struct PublishTab *next;
41 37
42 /** 38 /**
43 * This is a doubly-linked list. 39 * Frame for the tab.
44 */ 40 */
45 struct PublishTab *prev;
46
47 GtkWidget *frame; 41 GtkWidget *frame;
48 42
43 /**
44 * Associated builder.
45 */
49 GtkBuilder *builder; 46 GtkBuilder *builder;
50 47
51 /** 48 /**
52 * Associated (top-level) FS publish operation. 49 * Associated tree store.
53 */ 50 */
54 struct GNUNET_FS_PublishContext *pc;
55
56 GtkTreeStore *ts; 51 GtkTreeStore *ts;
57}; 52};
58 53
@@ -109,9 +104,7 @@ struct SearchResult
109 104
110 105
111 106
112static struct PublishTab *publish_tab_head; 107static struct PublishTab *publish_tab;
113
114static struct PublishTab *publish_tab_tail;
115 108
116 109
117static struct DownloadEntry * 110static struct DownloadEntry *
@@ -923,42 +916,38 @@ handle_publish_error (struct PublishEntry *ent, const char *emsg)
923 916
924 917
925/** 918/**
926 * Close a publish tab and free associated state. 919 * Close free an entry in the publish tab and free associated state.
927 */ 920 */
928static void 921static void
929close_publish_tab (struct PublishEntry *ent) 922handle_publish_stop (struct PublishEntry *ent)
930{ 923{
931 struct PublishTab *tab; 924 GtkTreeIter iter;
932 GtkNotebook *notebook; 925 GtkTreePath *path;
933 int index; 926 GtkTreeModel *tm;
934 int i;
935 927
936 if (ent == NULL) 928 if (ent == NULL)
937 { 929 {
938 GNUNET_break (0); 930 GNUNET_break (0);
939 return; 931 return;
940 } 932 }
941 gtk_tree_row_reference_free (ent->rr); 933 if (NULL != ent->pc)
942 if (GNUNET_YES != ent->is_top)
943 { 934 {
944 GNUNET_free (ent); 935 /* get piter from parent */
945 return; 936 path = gtk_tree_row_reference_get_path (ent->rr);
937 tm = gtk_tree_row_reference_get_model (ent->rr);
938 if (TRUE != gtk_tree_model_get_iter (tm, &iter, path))
939 GNUNET_break (0);
940 else
941 (void) gtk_tree_store_remove (GTK_TREE_STORE (tm), &iter);
942 gtk_tree_path_free (path);
946 } 943 }
947 tab = ent->tab; 944 gtk_tree_row_reference_free (ent->rr);
948 if (ent->uri != NULL) 945 if (ent->uri != NULL)
946 {
949 GNUNET_FS_uri_destroy (ent->uri); 947 GNUNET_FS_uri_destroy (ent->uri);
948 ent->uri = NULL;
949 }
950 GNUNET_free (ent); 950 GNUNET_free (ent);
951 notebook =
952 GTK_NOTEBOOK (GNUNET_FS_GTK_get_main_window_object
953 ("GNUNET_GTK_main_window_notebook"));
954 index = -1;
955 for (i = gtk_notebook_get_n_pages (notebook) - 1; i >= 0; i--)
956 if (tab->frame == gtk_notebook_get_nth_page (notebook, i))
957 index = i;
958 gtk_notebook_remove_page (notebook, index);
959 g_object_unref (tab->builder);
960 GNUNET_CONTAINER_DLL_remove (publish_tab_head, publish_tab_tail, tab);
961 GNUNET_free (tab);
962} 951}
963 952
964 953
@@ -1517,19 +1506,46 @@ free_search_result (struct SearchResult *sr)
1517 1506
1518 1507
1519/** 1508/**
1520 * Tell FS to stop publishing. 1509 * Tell FS to stop all active publish operations. Then close the tab.
1521 */ 1510 */
1522static void 1511static void
1523stop_publishing (GtkButton * button, gpointer user_data) 1512stop_publishing (GtkButton * button, gpointer user_data)
1524{ 1513{
1525 struct PublishTab *tab = user_data; 1514 struct PublishTab *tab = user_data;
1526 struct GNUNET_FS_PublishContext *pc; 1515 struct GNUNET_FS_PublishContext *pc;
1527 1516 struct PublishEntry *ent;
1528 if (NULL != (pc = tab->pc)) 1517 GtkTreeIter iter;
1518 GtkTreeModel *tm;
1519 GtkNotebook *notebook;
1520 int index;
1521 int i;
1522
1523 GNUNET_assert (tab == publish_tab);
1524 tm = GTK_TREE_MODEL (publish_tab->ts);
1525 if (TRUE == gtk_tree_model_iter_children (tm, &iter, NULL))
1529 { 1526 {
1530 tab->pc = NULL; 1527 do
1531 GNUNET_FS_publish_stop (pc); 1528 {
1529 gtk_tree_model_get (tm, &iter, 4, &ent, -1);
1530 if (NULL != (pc = ent->pc))
1531 {
1532 ent->pc = NULL;
1533 GNUNET_FS_publish_stop (pc);
1534 }
1535 }
1536 while (TRUE == gtk_tree_model_iter_next (tm, &iter));
1532 } 1537 }
1538 notebook =
1539 GTK_NOTEBOOK (GNUNET_FS_GTK_get_main_window_object
1540 ("GNUNET_GTK_main_window_notebook"));
1541 index = -1;
1542 for (i = gtk_notebook_get_n_pages (notebook) - 1; i >= 0; i--)
1543 if (publish_tab->frame == gtk_notebook_get_nth_page (notebook, i))
1544 index = i;
1545 gtk_notebook_remove_page (notebook, index);
1546 g_object_unref (publish_tab->builder);
1547 GNUNET_free (publish_tab);
1548 publish_tab = NULL;
1533} 1549}
1534 1550
1535 1551
@@ -1537,7 +1553,6 @@ static struct PublishEntry *
1537setup_publish (struct GNUNET_FS_PublishContext *pc, const char *fn, 1553setup_publish (struct GNUNET_FS_PublishContext *pc, const char *fn,
1538 uint64_t fsize, struct PublishEntry *parent) 1554 uint64_t fsize, struct PublishEntry *parent)
1539{ 1555{
1540 struct PublishTab *tab;
1541 struct PublishEntry *ent; 1556 struct PublishEntry *ent;
1542 GtkTreeIter *pitrptr; 1557 GtkTreeIter *pitrptr;
1543 GtkTreeIter iter; 1558 GtkTreeIter iter;
@@ -1545,7 +1560,6 @@ setup_publish (struct GNUNET_FS_PublishContext *pc, const char *fn,
1545 GtkTreePath *path; 1560 GtkTreePath *path;
1546 GtkWindow *df; 1561 GtkWindow *df;
1547 GtkWidget *tab_label; 1562 GtkWidget *tab_label;
1548 GtkLabel *fn_label;
1549 GtkWidget *close_button; 1563 GtkWidget *close_button;
1550 GtkNotebook *notebook; 1564 GtkNotebook *notebook;
1551 gint pages; 1565 gint pages;
@@ -1553,56 +1567,60 @@ setup_publish (struct GNUNET_FS_PublishContext *pc, const char *fn,
1553 1567
1554 if (NULL == parent) 1568 if (NULL == parent)
1555 { 1569 {
1556 /* create new tab */ 1570 if (NULL == publish_tab)
1557 tab = GNUNET_malloc (sizeof (struct PublishTab)); 1571 {
1558 tab->pc = pc; 1572 /* create new tab */
1559 GNUNET_CONTAINER_DLL_insert (publish_tab_head, publish_tab_tail, tab); 1573 publish_tab = GNUNET_malloc (sizeof (struct PublishTab));
1560 tab->builder = 1574 publish_tab->builder =
1561 GNUNET_GTK_get_new_builder ("gnunet_fs_gtk_publish_tab.glade"); 1575 GNUNET_GTK_get_new_builder ("gnunet_fs_gtk_publish_tab.glade");
1562 df = GTK_WINDOW (gtk_builder_get_object 1576 df = GTK_WINDOW (gtk_builder_get_object
1563 (tab->builder, "_publish_frame_window")); 1577 (publish_tab->builder, "_publish_frame_window"));
1564 tab->frame = gtk_bin_get_child (GTK_BIN (df)); 1578 publish_tab->frame = gtk_bin_get_child (GTK_BIN (df));
1565 g_object_ref (tab->frame); 1579 g_object_ref (publish_tab->frame);
1566 gtk_container_remove (GTK_CONTAINER (df), tab->frame); 1580 gtk_container_remove (GTK_CONTAINER (df), publish_tab->frame);
1567 gtk_widget_destroy (GTK_WIDGET (df)); 1581 gtk_widget_destroy (GTK_WIDGET (df));
1568 1582
1569 /* load tab_label */ 1583 /* load tab_label */
1570 df = GTK_WINDOW (gtk_builder_get_object 1584 df = GTK_WINDOW (gtk_builder_get_object
1571 (tab->builder, "_publish_label_window")); 1585 (publish_tab->builder, "_publish_label_window"));
1572 tab_label = gtk_bin_get_child (GTK_BIN (df)); 1586 tab_label = gtk_bin_get_child (GTK_BIN (df));
1573 g_object_ref (tab_label); 1587 g_object_ref (tab_label);
1574 gtk_container_remove (GTK_CONTAINER (df), tab_label); 1588 gtk_container_remove (GTK_CONTAINER (df), tab_label);
1575 gtk_widget_destroy (GTK_WIDGET (df)); 1589 gtk_widget_destroy (GTK_WIDGET (df));
1576 1590
1577 /* get refs to widgets */ 1591 /* get refs to widgets */
1578 fn_label = 1592 close_button =
1579 GTK_LABEL (gtk_builder_get_object 1593 GTK_WIDGET (gtk_builder_get_object
1580 (tab->builder, "_publish_label_window_label")); 1594 (publish_tab->builder, "_publish_label_close_button"));
1581 gtk_label_set_text (fn_label, fn); 1595 g_signal_connect (G_OBJECT (close_button), "clicked",
1582 close_button = 1596 G_CALLBACK (stop_publishing), publish_tab);
1583 GTK_WIDGET (gtk_builder_get_object 1597 /* FIXME: we don't actually need the closure anymore,
1584 (tab->builder, "_publish_label_close_button")); 1598 so we could have glade connect the above signal... */
1585 g_signal_connect (G_OBJECT (close_button), "clicked", 1599 /* make visible */
1586 G_CALLBACK (stop_publishing), tab); 1600 notebook =
1587 /* make visible */ 1601 GTK_NOTEBOOK (GNUNET_FS_GTK_get_main_window_object
1588 notebook = 1602 ("GNUNET_GTK_main_window_notebook"));
1589 GTK_NOTEBOOK (GNUNET_FS_GTK_get_main_window_object 1603 pages = gtk_notebook_get_n_pages (notebook);
1590 ("GNUNET_GTK_main_window_notebook")); 1604 gtk_notebook_insert_page (notebook, publish_tab->frame, tab_label, 0);
1591 pages = gtk_notebook_get_n_pages (notebook); 1605 gtk_widget_show (GTK_WIDGET (notebook));
1592 gtk_notebook_insert_page (notebook, tab->frame, tab_label, pages - 1); 1606 gtk_notebook_set_current_page (notebook, 0);
1593 gtk_widget_show (GTK_WIDGET (notebook)); 1607 publish_tab->ts =
1594 tab->ts = 1608 GTK_TREE_STORE (gtk_builder_get_object
1595 GTK_TREE_STORE (gtk_builder_get_object 1609 (publish_tab->builder, "_publish_frame_tree_store"));
1596 (tab->builder, "_publish_frame_tree_store")); 1610 pitrptr = NULL;
1597 pitrptr = NULL; 1611 }
1612 else
1613 {
1614 /* use existing TAB, but create fresh entry */
1615 pitrptr = NULL;
1616 }
1598 } 1617 }
1599 else 1618 else
1600 { 1619 {
1601 /* create new iter from parent */ 1620 /* create new iter from parent */
1602 tab = parent->tab;
1603 path = gtk_tree_row_reference_get_path (parent->rr); 1621 path = gtk_tree_row_reference_get_path (parent->rr);
1604 if (TRUE != 1622 if (TRUE !=
1605 gtk_tree_model_get_iter (GTK_TREE_MODEL (tab->ts), &piter, path)) 1623 gtk_tree_model_get_iter (GTK_TREE_MODEL (publish_tab->ts), &piter, path))
1606 { 1624 {
1607 GNUNET_break (0); 1625 GNUNET_break (0);
1608 return NULL; 1626 return NULL;
@@ -1610,18 +1628,20 @@ setup_publish (struct GNUNET_FS_PublishContext *pc, const char *fn,
1610 pitrptr = &piter; 1628 pitrptr = &piter;
1611 } 1629 }
1612 size_fancy = GNUNET_STRINGS_byte_size_fancy (fsize); 1630 size_fancy = GNUNET_STRINGS_byte_size_fancy (fsize);
1613 gtk_tree_store_insert_with_values (tab->ts, &iter, pitrptr, G_MAXINT, 0, fn, 1631 ent = GNUNET_malloc (sizeof (struct PublishEntry));
1632 ent->is_top = (parent == NULL) ? GNUNET_YES : GNUNET_NO;
1633 ent->tab = publish_tab;
1634 gtk_tree_store_insert_with_values (publish_tab->ts, &iter, pitrptr, G_MAXINT, 0, fn,
1614 1, size_fancy, 2, "white", 3, 1635 1, size_fancy, 2, "white", 3,
1615 (guint) 0 /* progress */ , 1636 (guint) 0 /* progress */ ,
1637 4, ent,
1616 -1); 1638 -1);
1617 GNUNET_free (size_fancy); 1639 path = gtk_tree_model_get_path (GTK_TREE_MODEL (publish_tab->ts), &iter);
1618 ent = GNUNET_malloc (sizeof (struct PublishEntry)); 1640 GNUNET_assert (NULL != path);
1619 ent->is_top = (parent == NULL) ? GNUNET_YES : GNUNET_NO; 1641 ent->rr = gtk_tree_row_reference_new (GTK_TREE_MODEL (publish_tab->ts), path);
1620 ent->tab = tab;
1621 path = gtk_tree_model_get_path (GTK_TREE_MODEL (tab->ts), &iter);
1622 ent->rr = gtk_tree_row_reference_new (GTK_TREE_MODEL (tab->ts), path);
1623 gtk_tree_path_free (path); 1642 gtk_tree_path_free (path);
1624 ent->pc = pc; 1643 ent->pc = pc;
1644 GNUNET_free (size_fancy);
1625 return ent; 1645 return ent;
1626} 1646}
1627 1647
@@ -1673,7 +1693,7 @@ GNUNET_GTK_fs_event_handler (void *cls,
1673 } 1693 }
1674 return ret; 1694 return ret;
1675 case GNUNET_FS_STATUS_PUBLISH_SUSPEND: 1695 case GNUNET_FS_STATUS_PUBLISH_SUSPEND:
1676 close_publish_tab (info->value.publish.cctx); 1696 handle_publish_stop (info->value.publish.cctx);
1677 return NULL; 1697 return NULL;
1678 case GNUNET_FS_STATUS_PUBLISH_PROGRESS: 1698 case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
1679 return mark_publish_progress (info->value.publish.cctx, 1699 return mark_publish_progress (info->value.publish.cctx,
@@ -1687,7 +1707,7 @@ GNUNET_GTK_fs_event_handler (void *cls,
1687 info->value.publish.specifics.completed. 1707 info->value.publish.specifics.completed.
1688 chk_uri); 1708 chk_uri);
1689 case GNUNET_FS_STATUS_PUBLISH_STOPPED: 1709 case GNUNET_FS_STATUS_PUBLISH_STOPPED:
1690 close_publish_tab (info->value.publish.cctx); 1710 handle_publish_stop (info->value.publish.cctx);
1691 return NULL; 1711 return NULL;
1692 case GNUNET_FS_STATUS_DOWNLOAD_START: 1712 case GNUNET_FS_STATUS_DOWNLOAD_START:
1693 return setup_download (info->value.download.cctx, info->value.download.pctx, 1713 return setup_download (info->value.download.cctx, info->value.download.pctx,