diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-02-04 19:47:27 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-02-04 19:47:27 +0000 |
commit | 785147dfcaf577169a840f8e54ba8775c64e6592 (patch) | |
tree | 97140bdd002980476835dc7dc9d8722ca2f6f5ba | |
parent | 283a796b4c7f91e46360ae2984d4bf556ec9111b (diff) | |
download | gnunet-gtk-785147dfcaf577169a840f8e54ba8775c64e6592.tar.gz gnunet-gtk-785147dfcaf577169a840f8e54ba8775c64e6592.zip |
-simplify code some more
-rw-r--r-- | src/fs/gnunet-fs-gtk_event-handler.c | 36 | ||||
-rw-r--r-- | src/fs/gnunet-fs-gtk_event-handler.h | 6 | ||||
-rw-r--r-- | src/fs/gnunet-fs-gtk_open-directory.c | 30 |
3 files changed, 29 insertions, 43 deletions
diff --git a/src/fs/gnunet-fs-gtk_event-handler.c b/src/fs/gnunet-fs-gtk_event-handler.c index ae0ab3db..376fba44 100644 --- a/src/fs/gnunet-fs-gtk_event-handler.c +++ b/src/fs/gnunet-fs-gtk_event-handler.c | |||
@@ -1180,7 +1180,6 @@ update_search_result (struct SearchResult *sr, | |||
1180 | * are being opened and if the user manually enters a URI. | 1180 | * are being opened and if the user manually enters a URI. |
1181 | * | 1181 | * |
1182 | * @param tab search tab to extend, never NULL | 1182 | * @param tab search tab to extend, never NULL |
1183 | * @param iter set to position where search result is added (OUT only) | ||
1184 | * @param parent_rr reference to parent entry in search tab, NULL for normal | 1183 | * @param parent_rr reference to parent entry in search tab, NULL for normal |
1185 | * search results, | 1184 | * search results, |
1186 | * @param uri uri to add, can be NULL for top-level entry of a directory opened from disk | 1185 | * @param uri uri to add, can be NULL for top-level entry of a directory opened from disk |
@@ -1195,7 +1194,6 @@ update_search_result (struct SearchResult *sr, | |||
1195 | */ | 1194 | */ |
1196 | struct SearchResult * | 1195 | struct SearchResult * |
1197 | GNUNET_GTK_add_search_result (struct SearchTab *tab, | 1196 | GNUNET_GTK_add_search_result (struct SearchTab *tab, |
1198 | GtkTreeIter *iter, | ||
1199 | GtkTreeRowReference *parent_rr, | 1197 | GtkTreeRowReference *parent_rr, |
1200 | const struct GNUNET_FS_Uri *uri, | 1198 | const struct GNUNET_FS_Uri *uri, |
1201 | const struct GNUNET_CONTAINER_MetaData *meta, | 1199 | const struct GNUNET_CONTAINER_MetaData *meta, |
@@ -1209,6 +1207,7 @@ GNUNET_GTK_add_search_result (struct SearchTab *tab, | |||
1209 | char *mime; | 1207 | char *mime; |
1210 | char *uris; | 1208 | char *uris; |
1211 | GdkPixbuf *pixbuf; | 1209 | GdkPixbuf *pixbuf; |
1210 | GtkTreeIter iter; | ||
1212 | GtkTreeIter *pitr; | 1211 | GtkTreeIter *pitr; |
1213 | GtkTreeIter pmem; | 1212 | GtkTreeIter pmem; |
1214 | GtkTreePath *path; | 1213 | GtkTreePath *path; |
@@ -1276,7 +1275,7 @@ GNUNET_GTK_add_search_result (struct SearchTab *tab, | |||
1276 | pitr = NULL; | 1275 | pitr = NULL; |
1277 | ts = tab->ts; | 1276 | ts = tab->ts; |
1278 | } | 1277 | } |
1279 | gtk_tree_store_insert_with_values (ts, iter, pitr, G_MAXINT, | 1278 | gtk_tree_store_insert_with_values (ts, &iter, pitr, G_MAXINT, |
1280 | 0, GNUNET_CONTAINER_meta_data_duplicate (meta), | 1279 | 0, GNUNET_CONTAINER_meta_data_duplicate (meta), |
1281 | 1, (uri == NULL) ? NULL : GNUNET_FS_uri_dup (uri), | 1280 | 1, (uri == NULL) ? NULL : GNUNET_FS_uri_dup (uri), |
1282 | 2, fsize, | 1281 | 2, fsize, |
@@ -1302,7 +1301,7 @@ GNUNET_GTK_add_search_result (struct SearchTab *tab, | |||
1302 | GNUNET_free_non_null (mime); | 1301 | GNUNET_free_non_null (mime); |
1303 | 1302 | ||
1304 | /* remember in 'sr' where we added the result */ | 1303 | /* remember in 'sr' where we added the result */ |
1305 | tp = gtk_tree_model_get_path (GTK_TREE_MODEL (ts), iter); | 1304 | tp = gtk_tree_model_get_path (GTK_TREE_MODEL (ts), &iter); |
1306 | sr->rr = gtk_tree_row_reference_new (GTK_TREE_MODEL (ts), tp); | 1305 | sr->rr = gtk_tree_row_reference_new (GTK_TREE_MODEL (ts), tp); |
1307 | gtk_tree_path_free (tp); | 1306 | gtk_tree_path_free (tp); |
1308 | 1307 | ||
@@ -1341,9 +1340,8 @@ process_search_result (struct SearchTab *tab, | |||
1341 | uint32_t applicability_rank) | 1340 | uint32_t applicability_rank) |
1342 | { | 1341 | { |
1343 | struct SearchResult *sr; | 1342 | struct SearchResult *sr; |
1344 | GtkTreeIter iter; | ||
1345 | 1343 | ||
1346 | sr = GNUNET_GTK_add_search_result (tab, &iter, | 1344 | sr = GNUNET_GTK_add_search_result (tab, |
1347 | (parent != NULL) ? parent->rr : NULL, | 1345 | (parent != NULL) ? parent->rr : NULL, |
1348 | uri, | 1346 | uri, |
1349 | meta, result, applicability_rank); | 1347 | meta, result, applicability_rank); |
@@ -1483,14 +1481,12 @@ setup_inner_search (struct GNUNET_FS_SearchContext *sc, | |||
1483 | * Setup a new top-level entry in the URI/orphan tab. If necessary, create | 1481 | * Setup a new top-level entry in the URI/orphan tab. If necessary, create |
1484 | * the URI tab first. | 1482 | * the URI tab first. |
1485 | * | 1483 | * |
1486 | * @param iter set to the new entry (OUT only) -- FIXME: remove, obtainable as 'RETVAL->rr' | ||
1487 | * @param meta metadata for the new entry | 1484 | * @param meta metadata for the new entry |
1488 | * @param uri URI for the new entry | 1485 | * @param uri URI for the new entry |
1489 | * @return the search result that was set up | 1486 | * @return the search result that was set up |
1490 | */ | 1487 | */ |
1491 | struct SearchResult * | 1488 | struct SearchResult * |
1492 | GNUNET_GTK_add_to_uri_tab (GtkTreeIter *iter, | 1489 | GNUNET_GTK_add_to_uri_tab (const struct GNUNET_CONTAINER_MetaData *meta, |
1493 | const struct GNUNET_CONTAINER_MetaData *meta, | ||
1494 | const struct GNUNET_FS_Uri *uri) | 1490 | const struct GNUNET_FS_Uri *uri) |
1495 | { | 1491 | { |
1496 | GtkNotebook *notebook; | 1492 | GtkNotebook *notebook; |
@@ -1512,7 +1508,7 @@ GNUNET_GTK_add_to_uri_tab (GtkTreeIter *iter, | |||
1512 | gtk_notebook_set_current_page (notebook, page); | 1508 | gtk_notebook_set_current_page (notebook, page); |
1513 | break; | 1509 | break; |
1514 | } | 1510 | } |
1515 | return GNUNET_GTK_add_search_result (uri_tab, iter, NULL, uri, meta, NULL, 0); | 1511 | return GNUNET_GTK_add_search_result (uri_tab, NULL, uri, meta, NULL, 0); |
1516 | } | 1512 | } |
1517 | 1513 | ||
1518 | 1514 | ||
@@ -1660,7 +1656,7 @@ add_directory_entry (void *cls, const char *filename, | |||
1660 | while (TRUE == gtk_tree_model_iter_next (tm, &iter)); | 1656 | while (TRUE == gtk_tree_model_iter_next (tm, &iter)); |
1661 | } | 1657 | } |
1662 | } | 1658 | } |
1663 | GNUNET_GTK_add_search_result (ade->tab, &iter, ade->prr, uri, meta, NULL, | 1659 | GNUNET_GTK_add_search_result (ade->tab, ade->prr, uri, meta, NULL, |
1664 | 0); | 1660 | 0); |
1665 | } | 1661 | } |
1666 | 1662 | ||
@@ -1918,15 +1914,13 @@ download_lost_parent (struct DownloadEntry *de) | |||
1918 | 1914 | ||
1919 | /* first, move the root of the respective 'de'-tree */ | 1915 | /* first, move the root of the respective 'de'-tree */ |
1920 | rr_old = de->sr->rr; | 1916 | rr_old = de->sr->rr; |
1921 | de->sr = GNUNET_GTK_add_to_uri_tab (&iter, de->meta, de->uri); | 1917 | de->sr = GNUNET_GTK_add_to_uri_tab (de->meta, de->uri); |
1922 | de->sr->download = de; | 1918 | de->sr->download = de; |
1923 | 1919 | ||
1924 | model = GTK_TREE_MODEL (de->sr->tab->ts); | ||
1925 | 1920 | ||
1926 | tm_old = gtk_tree_row_reference_get_model (rr_old); | 1921 | tm_old = gtk_tree_row_reference_get_model (rr_old); |
1927 | path = gtk_tree_row_reference_get_path (rr_old); | 1922 | path = gtk_tree_row_reference_get_path (rr_old); |
1928 | gtk_tree_row_reference_free (rr_old); | 1923 | gtk_tree_row_reference_free (rr_old); |
1929 | |||
1930 | if (! gtk_tree_model_get_iter (tm_old, &iter_old, path)) | 1924 | if (! gtk_tree_model_get_iter (tm_old, &iter_old, path)) |
1931 | { | 1925 | { |
1932 | GNUNET_break (0); | 1926 | GNUNET_break (0); |
@@ -1935,6 +1929,16 @@ download_lost_parent (struct DownloadEntry *de) | |||
1935 | } | 1929 | } |
1936 | gtk_tree_path_free (path); | 1930 | gtk_tree_path_free (path); |
1937 | 1931 | ||
1932 | model = GTK_TREE_MODEL (de->sr->tab->ts); | ||
1933 | path = gtk_tree_row_reference_get_path (de->sr->rr); | ||
1934 | if (! gtk_tree_model_get_iter (model, &iter, path)) | ||
1935 | { | ||
1936 | GNUNET_break (0); | ||
1937 | gtk_tree_path_free (path); | ||
1938 | return; | ||
1939 | } | ||
1940 | gtk_tree_path_free (path); | ||
1941 | |||
1938 | /* finally, move all children over as well */ | 1942 | /* finally, move all children over as well */ |
1939 | copy_children (tm_old, &iter_old, model, &iter); | 1943 | copy_children (tm_old, &iter_old, model, &iter); |
1940 | while (gtk_tree_model_iter_children (model, &child, &iter)) | 1944 | while (gtk_tree_model_iter_children (model, &child, &iter)) |
@@ -2003,7 +2007,7 @@ setup_download (struct DownloadEntry *de, struct DownloadEntry *pde, | |||
2003 | /* Stand-alone download with no 'row'/search result affiliated | 2007 | /* Stand-alone download with no 'row'/search result affiliated |
2004 | with the download so far; create a fresh entry for this | 2008 | with the download so far; create a fresh entry for this |
2005 | download in the URI tab */ | 2009 | download in the URI tab */ |
2006 | de->sr = GNUNET_GTK_add_to_uri_tab (&iter, meta, uri); | 2010 | de->sr = GNUNET_GTK_add_to_uri_tab (meta, uri); |
2007 | de->sr->download = de; | 2011 | de->sr->download = de; |
2008 | } | 2012 | } |
2009 | path = gtk_tree_row_reference_get_path (de->sr->rr); | 2013 | path = gtk_tree_row_reference_get_path (de->sr->rr); |
@@ -2020,7 +2024,7 @@ setup_download (struct DownloadEntry *de, struct DownloadEntry *pde, | |||
2020 | size) : 100) /* progress */ , | 2024 | size) : 100) /* progress */ , |
2021 | 6, filename /* filename/description */ , | 2025 | 6, filename /* filename/description */ , |
2022 | 8, "blue" /* status colour: pending */ , | 2026 | 8, "blue" /* status colour: pending */ , |
2023 | 9, de->sr, | 2027 | 9, de->sr, |
2024 | 14, completed, | 2028 | 14, completed, |
2025 | 15, de->filename, | 2029 | 15, de->filename, |
2026 | 16, de->anonymity, | 2030 | 16, de->anonymity, |
diff --git a/src/fs/gnunet-fs-gtk_event-handler.h b/src/fs/gnunet-fs-gtk_event-handler.h index bfd667de..a3c579b7 100644 --- a/src/fs/gnunet-fs-gtk_event-handler.h +++ b/src/fs/gnunet-fs-gtk_event-handler.h | |||
@@ -212,14 +212,12 @@ struct SearchResult | |||
212 | * Setup a new top-level entry in the URI/orphan tab. If necessary, create | 212 | * Setup a new top-level entry in the URI/orphan tab. If necessary, create |
213 | * the URI tab first. | 213 | * the URI tab first. |
214 | * | 214 | * |
215 | * @param iter set to the new entry (OUT only) | ||
216 | * @param meta metadata for the new entry | 215 | * @param meta metadata for the new entry |
217 | * @param uri URI for the new entry | 216 | * @param uri URI for the new entry |
218 | * @return the search result that was set up | 217 | * @return the search result that was set up |
219 | */ | 218 | */ |
220 | struct SearchResult * | 219 | struct SearchResult * |
221 | GNUNET_GTK_add_to_uri_tab (GtkTreeIter * iter, | 220 | GNUNET_GTK_add_to_uri_tab (const struct GNUNET_CONTAINER_MetaData *meta, |
222 | const struct GNUNET_CONTAINER_MetaData *meta, | ||
223 | const struct GNUNET_FS_Uri *uri); | 221 | const struct GNUNET_FS_Uri *uri); |
224 | 222 | ||
225 | 223 | ||
@@ -227,7 +225,6 @@ GNUNET_GTK_add_to_uri_tab (GtkTreeIter * iter, | |||
227 | * Add a search result to the given search tab. | 225 | * Add a search result to the given search tab. |
228 | * | 226 | * |
229 | * @param tab search tab to extend, never NULL | 227 | * @param tab search tab to extend, never NULL |
230 | * @param iter set to position where search result is added (OUT only) | ||
231 | * @param parent_rr reference to parent entry in search tab, NULL for normal | 228 | * @param parent_rr reference to parent entry in search tab, NULL for normal |
232 | * search results, | 229 | * search results, |
233 | * @param uri uri to add, can be NULL for top-level entry of a directory opened from disk | 230 | * @param uri uri to add, can be NULL for top-level entry of a directory opened from disk |
@@ -242,7 +239,6 @@ GNUNET_GTK_add_to_uri_tab (GtkTreeIter * iter, | |||
242 | */ | 239 | */ |
243 | struct SearchResult * | 240 | struct SearchResult * |
244 | GNUNET_GTK_add_search_result (struct SearchTab *tab, | 241 | GNUNET_GTK_add_search_result (struct SearchTab *tab, |
245 | GtkTreeIter *iter, | ||
246 | GtkTreeRowReference *parent_rr, | 242 | GtkTreeRowReference *parent_rr, |
247 | const struct GNUNET_FS_Uri *uri, | 243 | const struct GNUNET_FS_Uri *uri, |
248 | const struct GNUNET_CONTAINER_MetaData *meta, | 244 | const struct GNUNET_CONTAINER_MetaData *meta, |
diff --git a/src/fs/gnunet-fs-gtk_open-directory.c b/src/fs/gnunet-fs-gtk_open-directory.c index 0c13f7f3..fec36b7c 100644 --- a/src/fs/gnunet-fs-gtk_open-directory.c +++ b/src/fs/gnunet-fs-gtk_open-directory.c | |||
@@ -37,19 +37,9 @@ struct AddChildContext | |||
37 | const char *filename; | 37 | const char *filename; |
38 | 38 | ||
39 | /** | 39 | /** |
40 | * Tree store where we will add entries. | 40 | * Reference to the directorie's search result. |
41 | */ | 41 | */ |
42 | GtkTreeStore *ts; | 42 | struct SearchResult *sr; |
43 | |||
44 | /** | ||
45 | * Tab we've opened for the directory. | ||
46 | */ | ||
47 | struct SearchTab *tab; | ||
48 | |||
49 | /** | ||
50 | * Row reference to the directorie's parent entry. | ||
51 | */ | ||
52 | GtkTreeRowReference *prr; | ||
53 | 43 | ||
54 | }; | 44 | }; |
55 | 45 | ||
@@ -76,13 +66,11 @@ add_child (void *cls, const char *filename, const struct GNUNET_FS_Uri *uri, | |||
76 | const void *data) | 66 | const void *data) |
77 | { | 67 | { |
78 | struct AddChildContext *acc = cls; | 68 | struct AddChildContext *acc = cls; |
79 | GtkTreeIter iter; | ||
80 | 69 | ||
81 | if (NULL == uri) | 70 | if (NULL == uri) |
82 | { | 71 | { |
83 | /* directory meta data itself, create parent entry */ | 72 | /* directory meta data itself, create parent entry */ |
84 | struct GNUNET_CONTAINER_MetaData *dmeta; | 73 | struct GNUNET_CONTAINER_MetaData *dmeta; |
85 | GtkTreePath *tp; | ||
86 | 74 | ||
87 | dmeta = GNUNET_CONTAINER_meta_data_duplicate (meta); | 75 | dmeta = GNUNET_CONTAINER_meta_data_duplicate (meta); |
88 | GNUNET_CONTAINER_meta_data_insert (dmeta, "<user>", | 76 | GNUNET_CONTAINER_meta_data_insert (dmeta, "<user>", |
@@ -90,21 +78,19 @@ add_child (void *cls, const char *filename, const struct GNUNET_FS_Uri *uri, | |||
90 | EXTRACTOR_METAFORMAT_UTF8, "text/plain", | 78 | EXTRACTOR_METAFORMAT_UTF8, "text/plain", |
91 | acc->filename, | 79 | acc->filename, |
92 | strlen (acc->filename) + 1); | 80 | strlen (acc->filename) + 1); |
93 | acc->tab = GNUNET_GTK_add_to_uri_tab (&iter, dmeta, NULL)->tab; | 81 | acc->sr = GNUNET_GTK_add_to_uri_tab (dmeta, NULL); |
94 | tp = gtk_tree_model_get_path (GTK_TREE_MODEL (acc->tab->ts), &iter); | ||
95 | acc->prr = gtk_tree_row_reference_new (GTK_TREE_MODEL (acc->tab->ts), tp); | ||
96 | gtk_tree_path_free (tp); | ||
97 | acc->ts = acc->tab->ts; | ||
98 | GNUNET_CONTAINER_meta_data_destroy (dmeta); | 82 | GNUNET_CONTAINER_meta_data_destroy (dmeta); |
99 | return; | 83 | return; |
100 | } | 84 | } |
101 | if (NULL == acc->ts) | 85 | if (NULL == acc->sr) |
102 | { | 86 | { |
103 | GNUNET_break (0); | 87 | GNUNET_break (0); |
104 | return; | 88 | return; |
105 | } | 89 | } |
106 | GNUNET_assert (NULL != | 90 | GNUNET_assert (NULL != |
107 | GNUNET_GTK_add_search_result (acc->tab, &iter, acc->prr, uri, | 91 | GNUNET_GTK_add_search_result (acc->sr->tab, |
92 | acc->sr->rr, | ||
93 | uri, | ||
108 | meta, NULL, 0)); | 94 | meta, NULL, 0)); |
109 | } | 95 | } |
110 | 96 | ||
@@ -135,7 +121,7 @@ GNUNET_GTK_open_directory_dialog_response_cb (GtkDialog * dialog, | |||
135 | gtk_widget_destroy (GTK_WIDGET (dialog)); | 121 | gtk_widget_destroy (GTK_WIDGET (dialog)); |
136 | g_object_unref (G_OBJECT (builder)); | 122 | g_object_unref (G_OBJECT (builder)); |
137 | acc.filename = filename; | 123 | acc.filename = filename; |
138 | acc.ts = NULL; | 124 | acc.sr = NULL; |
139 | GNUNET_FS_GTK_mmap_and_scan (filename, &add_child, &acc); | 125 | GNUNET_FS_GTK_mmap_and_scan (filename, &add_child, &acc); |
140 | g_free (filename); | 126 | g_free (filename); |
141 | } | 127 | } |