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.c463
1 files changed, 384 insertions, 79 deletions
diff --git a/src/fs/gnunet-fs-gtk_event-handler.c b/src/fs/gnunet-fs-gtk_event-handler.c
index 6758db12..7c3d55bf 100644
--- a/src/fs/gnunet-fs-gtk_event-handler.c
+++ b/src/fs/gnunet-fs-gtk_event-handler.c
@@ -256,6 +256,11 @@ static struct SearchTab *uri_tab;
256static struct PublishTab *publish_tab; 256static struct PublishTab *publish_tab;
257 257
258/** 258/**
259 * Special tab we use to store publishing operations.
260 */
261static struct SearchTab *current_search_tab = NULL;
262
263/**
259 * Animation to display while publishing. 264 * Animation to display while publishing.
260 */ 265 */
261static struct GNUNET_FS_AnimationContext *animation_publishing; 266static struct GNUNET_FS_AnimationContext *animation_publishing;
@@ -296,6 +301,12 @@ static struct GNUNET_FS_AnimationContext *animation_found_sources;
296static struct GNUNET_FS_AnimationContext *animation_error; 301static struct GNUNET_FS_AnimationContext *animation_error;
297 302
298 303
304struct SearchTab *
305GNUNET_FS_GTK_get_current_search_tab ()
306{
307 return current_search_tab;
308}
309
299 310
300/* ***************** Search event handling ****************** */ 311/* ***************** Search event handling ****************** */
301 312
@@ -323,16 +334,10 @@ load_animation (const char *basename)
323static void 334static void
324clear_metadata_display () 335clear_metadata_display ()
325{ 336{
326 GtkImage *image; 337 struct GNUNET_GTK_MainWindowContext *mctx = GNUNET_FS_GTK_get_main_context ();
327 GtkListStore *ms;
328 338
329 image = 339 gtk_image_clear (mctx->preview_image);
330 GTK_IMAGE (GNUNET_FS_GTK_get_main_window_object 340 gtk_list_store_clear (mctx->md_liststore);
331 ("GNUNET_GTK_main_window_preview_image"));
332 gtk_image_clear (image);
333 ms = GTK_LIST_STORE (GNUNET_FS_GTK_get_main_window_object
334 ("GNUNET_GTK_meta_data_list_store"));
335 gtk_list_store_clear (ms);
336} 341}
337 342
338 343
@@ -494,6 +499,205 @@ get_suggested_filename_anonymity (GtkTreeModel *tm,
494 return NULL; 499 return NULL;
495} 500}
496 501
502/*
503 *
504 * finished_chain - non-NULL for top-level call (for the item we're about to download), NULL otherwise
505 * function sets it to GNUNET_YES if the item we're about to download was, in fact, already downloaded once, and thus we provide a name for it,
506 * returning a finished relative filename that might only need .gnd appended to it, nothing else.
507 * root_directory - top-level download directory to use. Set to the directory into which root of the tree (grand-*-parent item) was downloaded.
508 * If there's no already-downloaded grand-*-parents, set to default download directory (thus it will anways be filled on return).
509 * relative_directory - name of the directory in which we're about to download a file, relative to the root_directory. Whether it includes name of the file itself, depends on finished_chain.
510 * anonymity - anonymity level of one of the *parents. Initialize to -1. If none were downloaded, remains -1.
511 * Returned strings should be freed with GNUNET_free() if not NULL.
512 */
513void
514build_relative_name (GtkTreeModel *tm,
515 GtkTreeIter *iter,
516 int *finished_chain,
517 gchar **root_directory,
518 gchar **relative_directory,
519 int *anonymity)
520{
521 char *filename;
522 int downloaded_anonymity;
523 char *parent_filename;
524 GtkTreeIter parent;
525
526 gtk_tree_model_get (tm, iter,
527 SEARCH_TAB_MC_DOWNLOADED_FILENAME, &filename,
528 SEARCH_TAB_MC_DOWNLOADED_ANONYMITY, &downloaded_anonymity, -1);
529
530 if (!gtk_tree_model_iter_parent (tm, &parent, iter))
531 {
532 /* Ok, we're at the top item.
533 * bottom == GNUNET_YES is a corner case when we only have one
534 * item (top and bottom at the same time), and it was already
535 * downloaded once (has SEARCH_TAB_MC_DOWNLOADED_FILENAME set) and
536 * cleaned up afterwards (downloadable again).
537 */
538 if (filename == NULL)
539 {
540 /* Top-level item is not downloaded yet
541 * (i.e. we only have one item, it's toplevel, and we're
542 * about to start downloading it).
543 * Use default download directory.
544 */
545 char buf[FILENAME_MAX];
546 char *tmp;
547 tmp = get_default_download_directory (buf, sizeof (buf));
548 /* If no download directory is known, try working directory */
549 if (NULL == tmp)
550 tmp = g_strdup (getcwd (buf, sizeof (buf)));
551 *root_directory = g_strdup (tmp);
552 }
553 else
554 {
555 char *dot_gnd;
556 /* Toplevel item is a .gnd file, get its directory,
557 * and use it as download root (for now).
558 */
559 *root_directory = g_path_get_dirname (filename);
560 *relative_directory = g_path_get_basename (filename);
561 dot_gnd = strrchr (*relative_directory, '.');
562 if (NULL != dot_gnd && strcmp (dot_gnd, ".gnd") == 0)
563 *dot_gnd = '\0';
564 if (finished_chain)
565 *finished_chain = GNUNET_YES;
566 }
567 }
568 else
569 {
570 build_relative_name (tm, &parent, NULL, root_directory, relative_directory, anonymity);
571 /* We now know the root directory parent stems from,
572 * and parent's name (without .gnd) relative to the root directory.
573 * Now we need to check that root + reldir = directory
574 * where current item resides (that is, it was not saved in a different directory).
575 */
576 if (NULL != filename)
577 {
578 gchar *our_dirname = g_path_get_dirname (filename);
579 gchar *our_expected_dirname = g_build_filename (*root_directory, *relative_directory, NULL);
580 gchar *bname = g_path_get_basename (filename);
581 int chain_ok;
582 char *dot_gnd;
583#if WINDOWS
584 /* Kind of stricmp() for utf-8 */
585 gchar *tmp = g_utf8_casefold (our_dirname, -1);
586 gchar *tmpd = g_utf8_casefold (our_expected_dirname, -1);
587 chain_ok = 0 == g_utf8_collate (tmp, tmpd);
588 g_free (tmp);
589 g_free (tmpd);
590#else
591 chain_ok = 0 == g_utf8_collate (our_dirname, our_expected_dirname);
592#endif
593 dot_gnd = strrchr (bname, '.');
594 if (NULL != dot_gnd && strcmp (dot_gnd, ".gnd") == 0)
595 *dot_gnd = '\0';
596 if (!chain_ok)
597 {
598 /* User decided to download one of the directories into
599 * a different place - respect that decision, pick that
600 * place as the new root directory, and re-start relative name from here.
601 */
602 g_free (*root_directory);
603 *root_directory = g_strdup (our_dirname);
604 g_free (*relative_directory);
605 *relative_directory = g_strdup (bname);
606 }
607 else
608 {
609 /* Continue the chain from the same root directory */
610 gchar *new_relative_directory = g_build_filename (*relative_directory, bname, NULL);
611 g_free (*relative_directory);
612 *relative_directory = new_relative_directory;
613 }
614 if (finished_chain)
615 *finished_chain = GNUNET_YES;
616 g_free (our_dirname);
617 g_free (our_expected_dirname);
618 g_free (bname);
619 }
620 }
621
622 if ((downloaded_anonymity != -1) && (*anonymity == -1))
623 *anonymity = downloaded_anonymity;
624 g_free (filename);
625}
626
627static char *
628get_suggested_filename_anonymity2 (GtkTreeModel *tm,
629 GtkTreeIter *iter,
630 char **download_directory,
631 int *anonymity)
632{
633 char *result;
634 char *downloaddir;
635 char *relname;
636 char *filename;
637 char *tmp;
638 int downloaded_anonymity;
639 struct GNUNET_CONTAINER_MetaData *meta;
640 GtkTreeIter parent;
641 char *dot;
642 size_t tmplen;
643 int finished_chain;
644
645 downloaddir = NULL;
646 relname = NULL;
647 finished_chain = GNUNET_NO;
648 build_relative_name (tm, iter, &finished_chain, &downloaddir, &relname, &downloaded_anonymity);
649
650 gtk_tree_model_get (tm, iter, SEARCH_TAB_MC_METADATA, &meta, -1);
651
652 filename = GNUNET_FS_meta_data_suggest_filename (meta);
653 /* Don't trust metadata */
654 tmp = (char *) GNUNET_STRINGS_get_short_name (filename);
655
656 /* Really don't trust metadata */
657 if (NULL != tmp)
658 {
659 tmplen = strlen (tmp);
660 if ((1 == tmplen && '.' == tmp[0]) || (2 <= tmplen && '.' == tmp[0] && '.' == tmp[1]))
661 tmp = NULL;
662 else if ((1 == tmplen && ('/' == tmp[0] || '\\' == tmp[0])) || 0 == tmplen)
663 tmp = NULL;
664 }
665 if (NULL != tmp)
666 {
667 /* now, if we have a directory, replace trailing '/' with ".gnd" */
668 if (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (meta))
669 {
670 if ((tmp[tmplen-1] == '/') || (tmp[tmplen-1] == '\\'))
671 tmp[tmplen-1] = '\0';
672 if (relname)
673 {
674 if (finished_chain)
675 GNUNET_asprintf (&result, "%s%s", relname, GNUNET_FS_DIRECTORY_EXT);
676 else
677 GNUNET_asprintf (&result, "%s%s%s%s", relname, DIR_SEPARATOR_STR, tmp, GNUNET_FS_DIRECTORY_EXT);
678 }
679 else
680 GNUNET_asprintf (&result, "%s%s", tmp, GNUNET_FS_DIRECTORY_EXT);
681 }
682 else
683 {
684 if (relname)
685 {
686 if (finished_chain)
687 result = GNUNET_strdup (relname);
688 else
689 GNUNET_asprintf (&result, "%s%s%s", relname, DIR_SEPARATOR_STR, tmp);
690 }
691 else
692 result = GNUNET_strdup (tmp);
693 }
694 }
695 *download_directory = GNUNET_strdup (downloaddir);
696 GNUNET_free (filename);
697 g_free (downloaddir);
698 g_free (relname);
699 return result;
700}
497 701
498/** 702/**
499 * This function is called when the user double-clicks on a search 703 * This function is called when the user double-clicks on a search
@@ -742,6 +946,92 @@ start_download_ctx_menu_helper (struct SearchListPopupContext *spc,
742 gtk_tree_path_free (path); 946 gtk_tree_path_free (path);
743} 947}
744 948
949void
950start_download2 ()
951{
952 struct GNUNET_GTK_MainWindowContext *mctx = GNUNET_FS_GTK_get_main_context ();
953 struct SearchTab *st = GNUNET_FS_GTK_get_current_search_tab ();
954 struct GNUNET_CONTAINER_MetaData *meta;
955 GtkTreeView *tv;
956 GtkTreeSelection *sel;
957 GtkTreeModel *model;
958 GtkTreeIter iter;
959 GtkTreeIter parent_iter;
960 struct SearchResult *sr;
961 struct GNUNET_FS_Uri *uri;
962 GtkTreePath *path;
963 const gchar *filename;
964 gchar *downloaddir;
965 struct DownloadEntry *de;
966 guint anonymity;
967
968 gboolean recursive;
969
970 tv = GTK_TREE_VIEW (gtk_builder_get_object (st->builder, "_search_result_frame"));
971 sel = gtk_tree_view_get_selection (tv);
972 if (!gtk_tree_selection_get_selected (sel, &model, &iter))
973 return;
974
975 meta = NULL;
976
977 gtk_tree_model_get (model, &iter,
978 SEARCH_TAB_MC_METADATA, &meta,
979 SEARCH_TAB_MC_URI, &uri,
980 SEARCH_TAB_MC_SEARCH_RESULT, &sr,
981 -1);
982
983 if (!((NULL == sr->download) && (NULL != uri) &&
984 ((GNUNET_FS_uri_test_chk (uri) || GNUNET_FS_uri_test_loc (uri)))))
985 return;
986
987 path = gtk_tree_model_get_path (model, &iter);
988 recursive = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (mctx->download_recursive_checkbutton));
989 filename = gtk_entry_get_text (mctx->download_name_entry);
990 downloaddir = gtk_file_chooser_get_filename (mctx->download_location_chooser);
991
992 de = GNUNET_malloc (sizeof (struct DownloadEntry));
993
994 if (gtk_tree_model_iter_parent (model, &parent_iter, &iter))
995 {
996 struct SearchResult *psr = NULL;
997 gtk_tree_model_get (model, &parent_iter,
998 SEARCH_TAB_MC_SEARCH_RESULT, &psr,
999 -1);
1000 if (psr)
1001 de->pde = psr->download;
1002 }
1003 /* else pde remains zero */
1004
1005 de->uri = GNUNET_FS_uri_dup (uri);
1006 GNUNET_asprintf (&de->filename, "%s%s%s", downloaddir, DIR_SEPARATOR_STR, filename);
1007 de->sr = sr;
1008 sr->download = de;
1009 if (GNUNET_GTK_get_selected_anonymity_combo_level (mctx->download_anonymity_combo, &anonymity))
1010 de->anonymity = anonymity;
1011 else
1012 de->anonymity = 1;
1013 de->is_recursive = recursive;
1014 de->is_directory = GNUNET_FS_meta_data_test_for_directory (meta);
1015
1016 GNUNET_FS_GTK_download_context_start_download (de);
1017
1018 gtk_tree_path_free (path);
1019 g_free (downloaddir);
1020}
1021
1022/**
1023 * User clicked on "Download!" button at the download options panel.
1024 *
1025 * @param button the "Download!" button
1026 * @param user_data the main window context
1027 */
1028void
1029GNUNET_GTK_search_frame_download_download_button_clicked_cb (
1030 GtkButton *button, gpointer user_data)
1031{
1032 start_download2 ();
1033}
1034
745 1035
746/** 1036/**
747 * "Download" was selected in the current search context menu. 1037 * "Download" was selected in the current search context menu.
@@ -1049,7 +1339,7 @@ update_search_label (struct SearchTab *tab)
1049static void 1339static void
1050close_search_tab (struct SearchTab *tab) 1340close_search_tab (struct SearchTab *tab)
1051{ 1341{
1052 GtkNotebook *notebook; 1342 struct GNUNET_GTK_MainWindowContext *mctx = GNUNET_FS_GTK_get_main_context ();
1053 int index; 1343 int index;
1054 int i; 1344 int i;
1055 1345
@@ -1061,14 +1351,11 @@ close_search_tab (struct SearchTab *tab)
1061 return; 1351 return;
1062 } 1352 }
1063 clear_metadata_display (); 1353 clear_metadata_display ();
1064 notebook =
1065 GTK_NOTEBOOK (GNUNET_FS_GTK_get_main_window_object
1066 ("GNUNET_GTK_main_window_notebook"));
1067 index = -1; 1354 index = -1;
1068 for (i = gtk_notebook_get_n_pages (notebook) - 1; i >= 0; i--) 1355 for (i = gtk_notebook_get_n_pages (mctx->notebook) - 1; i >= 0; i--)
1069 if (tab->frame == gtk_notebook_get_nth_page (notebook, i)) 1356 if (tab->frame == gtk_notebook_get_nth_page (mctx->notebook, i))
1070 index = i; 1357 index = i;
1071 gtk_notebook_remove_page (notebook, index); 1358 gtk_notebook_remove_page (mctx->notebook, index);
1072 g_object_unref (tab->builder); 1359 g_object_unref (tab->builder);
1073 GNUNET_free (tab->query_txt); 1360 GNUNET_free (tab->query_txt);
1074 GNUNET_CONTAINER_DLL_remove (search_tab_head, search_tab_tail, tab); 1361 GNUNET_CONTAINER_DLL_remove (search_tab_head, search_tab_tail, tab);
@@ -1298,6 +1585,9 @@ download_lost_parent (struct DownloadEntry *de)
1298 { 1585 {
1299 GNUNET_break (0); 1586 GNUNET_break (0);
1300 gtk_tree_path_free (path); 1587 gtk_tree_path_free (path);
1588 g_free (filename);
1589 g_free (downloaded_filename);
1590 g_free (status_colour);
1301 return; 1591 return;
1302 } 1592 }
1303 gtk_tree_path_free (path); 1593 gtk_tree_path_free (path);
@@ -1447,43 +1737,80 @@ GNUNET_FS_GTK_search_treeview_cursor_changed (GtkTreeView *tv,
1447 gpointer user_data) 1737 gpointer user_data)
1448{ 1738{
1449 struct SearchTab *tab = user_data; 1739 struct SearchTab *tab = user_data;
1450 GtkImage *image;
1451 GtkListStore *ms;
1452 GtkTreeSelection *sel; 1740 GtkTreeSelection *sel;
1453 GtkTreeModel *model; 1741 GtkTreeModel *model;
1454 GtkTreeIter iter; 1742 GtkTreeIter iter;
1455 struct GNUNET_CONTAINER_MetaData *meta; 1743 struct GNUNET_CONTAINER_MetaData *meta;
1456 GdkPixbuf *pixbuf; 1744 GdkPixbuf *pixbuf;
1745 struct SearchResult *sr;
1746 struct GNUNET_FS_Uri *uri;
1747 gchar *filename;
1748 struct GNUNET_GTK_MainWindowContext *mctx = GNUNET_FS_GTK_get_main_context ();
1457 1749
1458 GNUNET_assert (tab->query_txt != NULL); 1750 GNUNET_assert (tab->query_txt != NULL);
1459 image =
1460 GTK_IMAGE (GNUNET_FS_GTK_get_main_window_object
1461 ("GNUNET_GTK_main_window_preview_image"));
1462 ms = GTK_LIST_STORE (GNUNET_FS_GTK_get_main_window_object
1463 ("GNUNET_GTK_meta_data_list_store"));
1464 sel = gtk_tree_view_get_selection (tv); 1751 sel = gtk_tree_view_get_selection (tv);
1465 gtk_list_store_clear (ms); 1752 gtk_list_store_clear (mctx->md_liststore);
1753 sel = gtk_tree_view_get_selection (tv);
1466 if (! gtk_tree_selection_get_selected (sel, &model, &iter)) 1754 if (! gtk_tree_selection_get_selected (sel, &model, &iter))
1467 { 1755 {
1468 /* nothing selected, clear preview */ 1756 /* nothing selected, clear preview */
1469 gtk_image_clear (image); 1757 gtk_image_clear (mctx->preview_image);
1758 gtk_widget_hide (GTK_WIDGET (mctx->download_panel));
1470 return; 1759 return;
1471 } 1760 }
1472 meta = NULL; 1761 meta = NULL;
1473 pixbuf = NULL; 1762 pixbuf = NULL;
1763
1474 gtk_tree_model_get (model, &iter, 1764 gtk_tree_model_get (model, &iter,
1475 SEARCH_TAB_MC_METADATA, &meta, 1765 SEARCH_TAB_MC_METADATA, &meta,
1476 SEARCH_TAB_MC_PREVIEW, &pixbuf, 1766 SEARCH_TAB_MC_PREVIEW, &pixbuf,
1767 SEARCH_TAB_MC_URI, &uri,
1768 SEARCH_TAB_MC_SEARCH_RESULT, &sr,
1477 -1); 1769 -1);
1770
1771 if ((NULL == sr->download) && (NULL != uri) &&
1772 ((GNUNET_FS_uri_test_chk (uri) || GNUNET_FS_uri_test_loc (uri))))
1773 {
1774 char *download_directory;
1775 char *filename;
1776 int anonymity;
1777 int is_directory;
1778
1779 /* Calculate suggested filename */
1780 anonymity = -1;
1781 download_directory = NULL;
1782 filename = get_suggested_filename_anonymity2 (model, &iter,
1783 &download_directory, &anonymity);
1784
1785 is_directory = GNUNET_FS_meta_data_test_for_directory (meta);
1786 gtk_widget_set_sensitive (GTK_WIDGET (mctx->download_recursive_checkbutton), is_directory);
1787
1788 /* TODO: make this configurable */
1789 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (mctx->download_recursive_checkbutton), is_directory);
1790
1791 /* TODO: make this configurable */
1792 GNUNET_GTK_select_anonymity_combo_level (mctx->download_anonymity_combo, anonymity >= 0 ? anonymity : 1);
1793
1794 gtk_entry_set_text (mctx->download_name_entry, filename != NULL ? filename : NULL);
1795 gtk_file_chooser_set_current_folder (mctx->download_location_chooser, download_directory);
1796 /*gtk_file_chooser_set_current_name (mctx->download_location_chooser, download_directory);*/
1797
1798 gtk_widget_show_all (GTK_WIDGET (mctx->download_panel));
1799 GNUNET_free (filename);
1800 GNUNET_free (download_directory);
1801 }
1802 else
1803 gtk_widget_hide (GTK_WIDGET (mctx->download_panel));
1804
1478 if (NULL != pixbuf) 1805 if (NULL != pixbuf)
1479 { 1806 {
1480 gtk_image_set_from_pixbuf (image, pixbuf); 1807 gtk_image_set_from_pixbuf (mctx->preview_image, pixbuf);
1481 g_object_unref (G_OBJECT (pixbuf)); 1808 g_object_unref (G_OBJECT (pixbuf));
1482 } 1809 }
1483 if (NULL != meta) 1810 if (NULL != meta)
1484 GNUNET_CONTAINER_meta_data_iterate (meta, 1811 GNUNET_CONTAINER_meta_data_iterate (meta,
1485 &GNUNET_FS_GTK_add_meta_data_to_list_store, 1812 &GNUNET_FS_GTK_add_meta_data_to_list_store,
1486 ms); 1813 mctx->md_liststore);
1487} 1814}
1488 1815
1489 1816
@@ -1492,43 +1819,36 @@ GNUNET_FS_GTK_search_treeview_cursor_changed (GtkTreeView *tv,
1492 * metadata views. 1819 * metadata views.
1493 * 1820 *
1494 * @param dummy widget emitting the event, unused 1821 * @param dummy widget emitting the event, unused
1495 * @param data master Gtk builder, unused 1822 * @param data main window context
1496 */ 1823 */
1497void 1824void
1498GNUNET_GTK_main_window_notebook_switch_page_cb (GtkWidget * dummy, 1825GNUNET_GTK_main_window_notebook_switch_page_cb (GtkWidget * dummy,
1499 gpointer data) 1826 gpointer data)
1500{ 1827{
1501 GtkNotebook *notebook;
1502 gint page; 1828 gint page;
1503 GtkWidget *w; 1829 GtkWidget *w;
1504 struct SearchTab *tab; 1830 struct SearchTab *tab;
1505 GtkImage *image;
1506 GtkListStore *ms;
1507 GtkTreeView *tv; 1831 GtkTreeView *tv;
1832 struct GNUNET_GTK_MainWindowContext *mctx = GNUNET_FS_GTK_get_main_context ();
1508 1833
1509 notebook = 1834 page = gtk_notebook_get_current_page (mctx->notebook);
1510 GTK_NOTEBOOK (GNUNET_FS_GTK_get_main_window_object 1835 w = gtk_notebook_get_nth_page (mctx->notebook, page);
1511 ("GNUNET_GTK_main_window_notebook")); 1836 current_search_tab = NULL;
1512 page = gtk_notebook_get_current_page (notebook);
1513 w = gtk_notebook_get_nth_page (notebook, page);
1514 for (tab = search_tab_head; NULL != tab; tab = tab->next) 1837 for (tab = search_tab_head; NULL != tab; tab = tab->next)
1515 { 1838 {
1516 if (tab->frame != w) 1839 if (tab->frame != w)
1517 continue; 1840 continue;
1841 current_search_tab = tab;
1518 tv = GTK_TREE_VIEW (gtk_builder_get_object 1842 tv = GTK_TREE_VIEW (gtk_builder_get_object
1519 (tab->builder, "_search_result_frame")); 1843 (tab->builder, "_search_result_frame"));
1520 GNUNET_FS_GTK_search_treeview_cursor_changed (tv, tab); 1844 GNUNET_FS_GTK_search_treeview_cursor_changed (tv, tab);
1521 return; 1845 return;
1522 } 1846 }
1847 gtk_widget_hide (GTK_WIDGET (mctx->download_panel));
1523 /* active tab is not a search tab (likely the 'publish' tab), 1848 /* active tab is not a search tab (likely the 'publish' tab),
1524 clear meta data and preview widgets */ 1849 clear meta data and preview widgets */
1525 image = 1850 gtk_image_clear (mctx->preview_image);
1526 GTK_IMAGE (GNUNET_FS_GTK_get_main_window_object 1851 gtk_list_store_clear (mctx->md_liststore);
1527 ("GNUNET_GTK_main_window_preview_image"));
1528 gtk_image_clear (image);
1529 ms = GTK_LIST_STORE (GNUNET_FS_GTK_get_main_window_object
1530 ("GNUNET_GTK_meta_data_list_store"));
1531 gtk_list_store_clear (ms);
1532} 1852}
1533 1853
1534 1854
@@ -1752,9 +2072,9 @@ update_search_result (struct SearchResult *sr,
1752 char *mime; 2072 char *mime;
1753 GdkPixbuf *pixbuf; 2073 GdkPixbuf *pixbuf;
1754 guint percent_avail; 2074 guint percent_avail;
1755 GtkNotebook *notebook;
1756 gint page; 2075 gint page;
1757 int desc_is_a_dup; 2076 int desc_is_a_dup;
2077 struct GNUNET_GTK_MainWindowContext *mctx = GNUNET_FS_GTK_get_main_context ();
1758 2078
1759 if (sr == NULL) 2079 if (sr == NULL)
1760 { 2080 {
@@ -1800,11 +2120,8 @@ update_search_result (struct SearchResult *sr,
1800 GNUNET_free (desc); 2120 GNUNET_free (desc);
1801 GNUNET_free_non_null (mime); 2121 GNUNET_free_non_null (mime);
1802 2122
1803 notebook = 2123 page = gtk_notebook_get_current_page (mctx->notebook);
1804 GTK_NOTEBOOK (GNUNET_FS_GTK_get_main_window_object 2124 if (gtk_notebook_get_nth_page (mctx->notebook, page) == sr->tab->frame)
1805 ("GNUNET_GTK_main_window_notebook"));
1806 page = gtk_notebook_get_current_page (notebook);
1807 if (gtk_notebook_get_nth_page (notebook, page) == sr->tab->frame)
1808 { 2125 {
1809 tv = GTK_TREE_VIEW (gtk_builder_get_object 2126 tv = GTK_TREE_VIEW (gtk_builder_get_object
1810 (sr->tab->builder, "_search_result_frame")); 2127 (sr->tab->builder, "_search_result_frame"));
@@ -2006,11 +2323,11 @@ setup_search_tab (struct GNUNET_FS_SearchContext *sc,
2006 const struct GNUNET_FS_Uri *query) 2323 const struct GNUNET_FS_Uri *query)
2007{ 2324{
2008 struct SearchTab *tab; 2325 struct SearchTab *tab;
2009 GtkNotebook *notebook;
2010 GtkWindow *sf; 2326 GtkWindow *sf;
2011 GtkTreeViewColumn *anim_col; 2327 GtkTreeViewColumn *anim_col;
2012 GtkTreeView *tv; 2328 GtkTreeView *tv;
2013 gint pages; 2329 gint pages;
2330 struct GNUNET_GTK_MainWindowContext *mctx = GNUNET_FS_GTK_get_main_context ();
2014 2331
2015 if (NULL == animation_downloading) 2332 if (NULL == animation_downloading)
2016 { 2333 {
@@ -2081,13 +2398,10 @@ setup_search_tab (struct GNUNET_FS_SearchContext *sc,
2081 update_search_label (tab); 2398 update_search_label (tab);
2082 2399
2083 /* make visible */ 2400 /* make visible */
2084 notebook = 2401 pages = gtk_notebook_get_n_pages (mctx->notebook);
2085 GTK_NOTEBOOK (GNUNET_FS_GTK_get_main_window_object 2402 gtk_notebook_insert_page (mctx->notebook, tab->frame, tab->tab_label, pages - 1);
2086 ("GNUNET_GTK_main_window_notebook")); 2403 gtk_notebook_set_current_page (mctx->notebook, pages - 1);
2087 pages = gtk_notebook_get_n_pages (notebook); 2404 gtk_widget_show (GTK_WIDGET (mctx->notebook));
2088 gtk_notebook_insert_page (notebook, tab->frame, tab->tab_label, pages - 1);
2089 gtk_notebook_set_current_page (notebook, pages - 1);
2090 gtk_widget_show (GTK_WIDGET (notebook));
2091 return tab; 2405 return tab;
2092} 2406}
2093 2407
@@ -2149,7 +2463,7 @@ struct SearchResult *
2149GNUNET_GTK_add_to_uri_tab (const struct GNUNET_CONTAINER_MetaData *meta, 2463GNUNET_GTK_add_to_uri_tab (const struct GNUNET_CONTAINER_MetaData *meta,
2150 const struct GNUNET_FS_Uri *uri) 2464 const struct GNUNET_FS_Uri *uri)
2151{ 2465{
2152 GtkNotebook *notebook; 2466 struct GNUNET_GTK_MainWindowContext *mctx = GNUNET_FS_GTK_get_main_context ();
2153 gint page; 2467 gint page;
2154 2468
2155 if (NULL == uri_tab) 2469 if (NULL == uri_tab)
@@ -2159,13 +2473,10 @@ GNUNET_GTK_add_to_uri_tab (const struct GNUNET_CONTAINER_MetaData *meta,
2159 gtk_widget_set_visible (uri_tab->pause_button, FALSE); 2473 gtk_widget_set_visible (uri_tab->pause_button, FALSE);
2160 } 2474 }
2161 /* make 'uri_tab' the current page */ 2475 /* make 'uri_tab' the current page */
2162 notebook = 2476 for (page = 0; page < gtk_notebook_get_n_pages (mctx->notebook); page++)
2163 GTK_NOTEBOOK (GNUNET_FS_GTK_get_main_window_object 2477 if (uri_tab->frame == gtk_notebook_get_nth_page (mctx->notebook, page))
2164 ("GNUNET_GTK_main_window_notebook"));
2165 for (page = 0; page < gtk_notebook_get_n_pages (notebook); page++)
2166 if (uri_tab->frame == gtk_notebook_get_nth_page (notebook, page))
2167 { 2478 {
2168 gtk_notebook_set_current_page (notebook, page); 2479 gtk_notebook_set_current_page (mctx->notebook, page);
2169 break; 2480 break;
2170 } 2481 }
2171 return GNUNET_GTK_add_search_result (uri_tab, NULL, uri, meta, NULL, 0); 2482 return GNUNET_GTK_add_search_result (uri_tab, NULL, uri, meta, NULL, 0);
@@ -2648,7 +2959,7 @@ setup_download (struct DownloadEntry *de, struct DownloadEntry *pde,
2648 SEARCH_TAB_MC_STATUS_COLOUR, "blue", 2959 SEARCH_TAB_MC_STATUS_COLOUR, "blue",
2649 SEARCH_TAB_MC_SEARCH_RESULT, de->sr, 2960 SEARCH_TAB_MC_SEARCH_RESULT, de->sr,
2650 SEARCH_TAB_MC_COMPLETED, (guint64) completed, 2961 SEARCH_TAB_MC_COMPLETED, (guint64) completed,
2651 SEARCH_TAB_MC_FILENAME, de->filename, 2962 SEARCH_TAB_MC_DOWNLOADED_FILENAME, de->filename,
2652 SEARCH_TAB_MC_DOWNLOADED_ANONYMITY, de->anonymity, 2963 SEARCH_TAB_MC_DOWNLOADED_ANONYMITY, de->anonymity,
2653 SEARCH_TAB_MC_STATUS_ICON, 2964 SEARCH_TAB_MC_STATUS_ICON,
2654 GNUNET_GTK_animation_context_get_pixbuf (animation_download_stalled), 2965 GNUNET_GTK_animation_context_get_pixbuf (animation_download_stalled),
@@ -2797,23 +3108,20 @@ handle_publish_error (struct PublishEntry *pe,
2797static void 3108static void
2798delete_publish_tab () 3109delete_publish_tab ()
2799{ 3110{
2800 GtkNotebook *notebook;
2801 struct PublishTab *pt; 3111 struct PublishTab *pt;
2802 int index; 3112 int index;
2803 int i; 3113 int i;
3114 struct GNUNET_GTK_MainWindowContext *mctx = GNUNET_FS_GTK_get_main_context ();
2804 3115
2805 if (NULL == publish_tab) 3116 if (NULL == publish_tab)
2806 return; 3117 return;
2807 pt = publish_tab; 3118 pt = publish_tab;
2808 publish_tab = NULL; 3119 publish_tab = NULL;
2809 notebook =
2810 GTK_NOTEBOOK (GNUNET_FS_GTK_get_main_window_object
2811 ("GNUNET_GTK_main_window_notebook"));
2812 index = -1; 3120 index = -1;
2813 for (i = gtk_notebook_get_n_pages (notebook) - 1; i >= 0; i--) 3121 for (i = gtk_notebook_get_n_pages (mctx->notebook) - 1; i >= 0; i--)
2814 if (pt->frame == gtk_notebook_get_nth_page (notebook, i)) 3122 if (pt->frame == gtk_notebook_get_nth_page (mctx->notebook, i))
2815 index = i; 3123 index = i;
2816 gtk_notebook_remove_page (notebook, index); 3124 gtk_notebook_remove_page (mctx->notebook, index);
2817 3125
2818 /* fully destroy tab */ 3126 /* fully destroy tab */
2819 g_object_unref (pt->builder); 3127 g_object_unref (pt->builder);
@@ -2912,10 +3220,10 @@ setup_publish (struct GNUNET_FS_PublishContext *pc, const char *fn,
2912 GtkTreePath *path; 3220 GtkTreePath *path;
2913 GtkWindow *df; 3221 GtkWindow *df;
2914 GtkWidget *tab_label; 3222 GtkWidget *tab_label;
2915 GtkNotebook *notebook;
2916 char *size_fancy; 3223 char *size_fancy;
2917 GtkTreeView *tv; 3224 GtkTreeView *tv;
2918 GtkTreeViewColumn *anim_col; 3225 GtkTreeViewColumn *anim_col;
3226 struct GNUNET_GTK_MainWindowContext *mctx = GNUNET_FS_GTK_get_main_context ();
2919 3227
2920 if (NULL == publish_tab) 3228 if (NULL == publish_tab)
2921 { 3229 {
@@ -2948,12 +3256,9 @@ setup_publish (struct GNUNET_FS_PublishContext *pc, const char *fn,
2948 anim_col); 3256 anim_col);
2949 3257
2950 /* make visible */ 3258 /* make visible */
2951 notebook = 3259 gtk_notebook_insert_page (mctx->notebook, publish_tab->frame, tab_label, 0);
2952 GTK_NOTEBOOK (GNUNET_FS_GTK_get_main_window_object 3260 gtk_widget_show (GTK_WIDGET (mctx->notebook));
2953 ("GNUNET_GTK_main_window_notebook")); 3261 gtk_notebook_set_current_page (mctx->notebook, 0);
2954 gtk_notebook_insert_page (notebook, publish_tab->frame, tab_label, 0);
2955 gtk_widget_show (GTK_WIDGET (notebook));
2956 gtk_notebook_set_current_page (notebook, 0);
2957 publish_tab->ts = 3262 publish_tab->ts =
2958 GTK_TREE_STORE (gtk_builder_get_object 3263 GTK_TREE_STORE (gtk_builder_get_object
2959 (publish_tab->builder, "_publish_frame_tree_store")); 3264 (publish_tab->builder, "_publish_frame_tree_store"));