diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-02-01 16:35:15 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-02-01 16:35:15 +0000 |
commit | d7432b30dd45a0178ef6401a09ffc39300d26393 (patch) | |
tree | fb07520cd13074921666c9716e0450a9b30dfd02 | |
parent | fab274034be61b23004791888bc7a7f622df90d7 (diff) | |
download | gnunet-gtk-d7432b30dd45a0178ef6401a09ffc39300d26393.tar.gz gnunet-gtk-d7432b30dd45a0178ef6401a09ffc39300d26393.zip |
-more publish handling cleanup
-rw-r--r-- | contrib/gnunet_fs_gtk_publish_tab.glade | 109 | ||||
-rw-r--r-- | src/fs/gnunet-fs-gtk-event_handler.c | 264 |
2 files changed, 205 insertions, 168 deletions
diff --git a/contrib/gnunet_fs_gtk_publish_tab.glade b/contrib/gnunet_fs_gtk_publish_tab.glade index 4ef49c98..94f3d812 100644 --- a/contrib/gnunet_fs_gtk_publish_tab.glade +++ b/contrib/gnunet_fs_gtk_publish_tab.glade | |||
@@ -1,70 +1,89 @@ | |||
1 | <?xml version="1.0" encoding="UTF-8"?> | 1 | <?xml version="1.0" encoding="UTF-8"?> |
2 | <interface> | 2 | <interface> |
3 | <requires lib="gtk+" version="2.20"/> | 3 | <requires lib="gtk+" version="2.20"/> |
4 | <!-- interface-naming-policy project-wide --> | 4 | <object class="GtkTreeStore" id="_publish_frame_tree_store"> |
5 | <columns> | ||
6 | <!-- column-name filename --> | ||
7 | <column type="gchararray"/> | ||
8 | <!-- column-name filesize --> | ||
9 | <column type="gchararray"/> | ||
10 | <!-- column-name bgcolour --> | ||
11 | <column type="gchararray"/> | ||
12 | <!-- column-name progress --> | ||
13 | <column type="guint"/> | ||
14 | <!-- column-name ent --> | ||
15 | <column type="gpointer"/> | ||
16 | <!-- column-name result_string --> | ||
17 | <column type="gchararray"/> | ||
18 | </columns> | ||
19 | </object> | ||
5 | <object class="GtkWindow" id="_publish_frame_window"> | 20 | <object class="GtkWindow" id="_publish_frame_window"> |
21 | <property name="can_focus">False</property> | ||
6 | <property name="title">You should never see this</property> | 22 | <property name="title">You should never see this</property> |
7 | |||
8 | <child> | ||
9 | <object class="GtkScrolledWindow" id="_publish_frame_scrolled_window"> | ||
10 | <property name="height_request">100</property> | ||
11 | <property name="visible">True</property> | ||
12 | <property name="can_focus">True</property> | ||
13 | <property name="hscrollbar_policy">automatic</property> | ||
14 | <property name="vscrollbar_policy">automatic</property> | ||
15 | |||
16 | <child> | 23 | <child> |
17 | <object class="GtkTreeView" id="_publish_frame"> | 24 | <object class="GtkScrolledWindow" id="_publish_frame_scrolled_window"> |
25 | <property name="height_request">100</property> | ||
18 | <property name="visible">True</property> | 26 | <property name="visible">True</property> |
19 | <property name="can_focus">True</property> | 27 | <property name="can_focus">True</property> |
20 | <property name="model">_publish_frame_tree_store</property> | ||
21 | <property name="reorderable">True</property> | ||
22 | <property name="enable_tree_lines">True</property> | ||
23 | <child> | 28 | <child> |
24 | <object class="GtkTreeViewColumn" id="filename"> | 29 | <object class="GtkTreeView" id="_publish_frame"> |
25 | <property name="sizing">autosize</property> | 30 | <property name="visible">True</property> |
26 | <property name="title" translatable="yes">Filename</property> | 31 | <property name="can_focus">True</property> |
27 | <property name="expand">True</property> | 32 | <property name="model">_publish_frame_tree_store</property> |
33 | <property name="reorderable">True</property> | ||
34 | <property name="enable_tree_lines">True</property> | ||
35 | <child internal-child="selection"> | ||
36 | <object class="GtkTreeSelection" id="treeview-selection1"/> | ||
37 | </child> | ||
28 | <child> | 38 | <child> |
29 | <object class="GtkCellRendererProgress" id="filename_renderer"/> | 39 | <object class="GtkTreeViewColumn" id="filename"> |
30 | <attributes> | 40 | <property name="sizing">autosize</property> |
31 | <attribute name="cell-background">2</attribute> | 41 | <property name="title" translatable="yes">Filename</property> |
32 | <attribute name="text">0</attribute> | 42 | <property name="expand">True</property> |
33 | <attribute name="value">3</attribute> | 43 | <child> |
34 | </attributes> | 44 | <object class="GtkCellRendererProgress" id="filename_renderer"/> |
45 | <attributes> | ||
46 | <attribute name="cell-background">2</attribute> | ||
47 | <attribute name="text">0</attribute> | ||
48 | <attribute name="value">3</attribute> | ||
49 | </attributes> | ||
50 | </child> | ||
51 | </object> | ||
35 | </child> | 52 | </child> |
36 | </object> | ||
37 | </child> | ||
38 | <child> | ||
39 | <object class="GtkTreeViewColumn" id="filesize"> | ||
40 | <property name="sizing">autosize</property> | ||
41 | <property name="title" translatable="yes">Size</property> | ||
42 | <child> | 53 | <child> |
43 | <object class="GtkCellRendererText" id="size_renderer"/> | 54 | <object class="GtkTreeViewColumn" id="filesize"> |
44 | <attributes> | 55 | <property name="sizing">autosize</property> |
45 | <attribute name="background">2</attribute> | 56 | <property name="title" translatable="yes">Size</property> |
46 | <attribute name="text">1</attribute> | 57 | <child> |
47 | </attributes> | 58 | <object class="GtkCellRendererText" id="size_renderer"/> |
59 | <attributes> | ||
60 | <attribute name="background">2</attribute> | ||
61 | <attribute name="text">1</attribute> | ||
62 | </attributes> | ||
63 | </child> | ||
64 | </object> | ||
48 | </child> | 65 | </child> |
49 | </object> | 66 | </object> |
50 | </child> | 67 | </child> |
51 | </object> | 68 | </object> |
52 | </child> | 69 | </child> |
53 | </object> | 70 | </object> |
54 | </child> | ||
55 | </object> | ||
56 | <object class="GtkWindow" id="_publish_label_window"> | 71 | <object class="GtkWindow" id="_publish_label_window"> |
72 | <property name="can_focus">False</property> | ||
57 | <child> | 73 | <child> |
58 | <object class="GtkHBox" id="_publish_label_hbox"> | 74 | <object class="GtkHBox" id="_publish_label_hbox"> |
59 | <property name="visible">True</property> | 75 | <property name="visible">True</property> |
76 | <property name="can_focus">False</property> | ||
60 | <property name="border_width">5</property> | 77 | <property name="border_width">5</property> |
61 | <child> | 78 | <child> |
62 | <object class="GtkLabel" id="_publish_label_window_label"> | 79 | <object class="GtkLabel" id="_publish_label_window_label"> |
63 | <property name="height_request">30</property> | 80 | <property name="height_request">30</property> |
64 | <property name="visible">True</property> | 81 | <property name="visible">True</property> |
82 | <property name="can_focus">False</property> | ||
65 | <property name="label" translatable="yes">Publishing</property> | 83 | <property name="label" translatable="yes">Publishing</property> |
66 | </object> | 84 | </object> |
67 | <packing> | 85 | <packing> |
86 | <property name="expand">True</property> | ||
68 | <property name="fill">False</property> | 87 | <property name="fill">False</property> |
69 | <property name="padding">5</property> | 88 | <property name="padding">5</property> |
70 | <property name="position">0</property> | 89 | <property name="position">0</property> |
@@ -72,6 +91,7 @@ | |||
72 | </child> | 91 | </child> |
73 | <child> | 92 | <child> |
74 | <object class="GtkButton" id="_publish_label_close_button"> | 93 | <object class="GtkButton" id="_publish_label_close_button"> |
94 | <property name="use_action_appearance">False</property> | ||
75 | <property name="visible">True</property> | 95 | <property name="visible">True</property> |
76 | <property name="can_focus">True</property> | 96 | <property name="can_focus">True</property> |
77 | <property name="receives_default">True</property> | 97 | <property name="receives_default">True</property> |
@@ -80,6 +100,7 @@ | |||
80 | <child> | 100 | <child> |
81 | <object class="GtkImage" id="close_icon_stock_image"> | 101 | <object class="GtkImage" id="close_icon_stock_image"> |
82 | <property name="visible">True</property> | 102 | <property name="visible">True</property> |
103 | <property name="can_focus">False</property> | ||
83 | <property name="stock">gtk-close</property> | 104 | <property name="stock">gtk-close</property> |
84 | <property name="icon-size">2</property> | 105 | <property name="icon-size">2</property> |
85 | </object> | 106 | </object> |
@@ -94,18 +115,4 @@ | |||
94 | </object> | 115 | </object> |
95 | </child> | 116 | </child> |
96 | </object> | 117 | </object> |
97 | <object class="GtkTreeStore" id="_publish_frame_tree_store"> | ||
98 | <columns> | ||
99 | <!-- column-name filename --> | ||
100 | <column type="gchararray"/> | ||
101 | <!-- column-name filesize --> | ||
102 | <column type="gchararray"/> | ||
103 | <!-- column-name bgcolour --> | ||
104 | <column type="gchararray"/> | ||
105 | <!-- column-name progress --> | ||
106 | <column type="guint"/> | ||
107 | <!-- column-name ent --> | ||
108 | <column type="gpointer"/> | ||
109 | </columns> | ||
110 | </object> | ||
111 | </interface> | 118 | </interface> |
diff --git a/src/fs/gnunet-fs-gtk-event_handler.c b/src/fs/gnunet-fs-gtk-event_handler.c index 23681bdd..91c80eec 100644 --- a/src/fs/gnunet-fs-gtk-event_handler.c +++ b/src/fs/gnunet-fs-gtk-event_handler.c | |||
@@ -1061,7 +1061,7 @@ clear_downloads (GtkButton * button, gpointer user_data) | |||
1061 | * We received a search error message from the FS library. | 1061 | * We received a search error message from the FS library. |
1062 | * Present it to the user in an appropriate form. | 1062 | * Present it to the user in an appropriate form. |
1063 | * | 1063 | * |
1064 | * @param tab search tab affected by the error message | 1064 | * @param tab search tab affected by the error |
1065 | * @param emsg the error message | 1065 | * @param emsg the error message |
1066 | */ | 1066 | */ |
1067 | static void | 1067 | static void |
@@ -2155,23 +2155,27 @@ change_publish_color (struct PublishEntry *pe, | |||
2155 | } | 2155 | } |
2156 | 2156 | ||
2157 | 2157 | ||
2158 | static struct PublishEntry * | 2158 | /** |
2159 | * We got an event that some publishing operation is progressing. | ||
2160 | * Update the tree model accordingly. | ||
2161 | * | ||
2162 | * @param pe publish entry that is progressing | ||
2163 | * @param size overall size of the file or directory | ||
2164 | * @param completed number of bytes we have completed | ||
2165 | */ | ||
2166 | static void | ||
2159 | mark_publish_progress (struct PublishEntry *pe, uint64_t size, | 2167 | mark_publish_progress (struct PublishEntry *pe, uint64_t size, |
2160 | uint64_t completed) | 2168 | uint64_t completed) |
2161 | { | 2169 | { |
2162 | GtkTreeIter iter; | 2170 | GtkTreeIter iter; |
2163 | GtkTreePath *path; | 2171 | GtkTreePath *path; |
2164 | 2172 | ||
2165 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2166 | "Marking publicaation progress for PE=%p, %llu/%llu\n", | ||
2167 | pe, completed, size); | ||
2168 | path = gtk_tree_row_reference_get_path (pe->rr); | 2173 | path = gtk_tree_row_reference_get_path (pe->rr); |
2169 | if (TRUE != | 2174 | if (! gtk_tree_model_get_iter (GTK_TREE_MODEL (pe->tab->ts), &iter, path)) |
2170 | gtk_tree_model_get_iter (GTK_TREE_MODEL (pe->tab->ts), &iter, path)) | ||
2171 | { | 2175 | { |
2172 | GNUNET_break (0); | 2176 | GNUNET_break (0); |
2173 | gtk_tree_path_free (path); | 2177 | gtk_tree_path_free (path); |
2174 | return pe; | 2178 | return; |
2175 | } | 2179 | } |
2176 | gtk_tree_path_free (path); | 2180 | gtk_tree_path_free (path); |
2177 | gtk_tree_store_set (pe->tab->ts, &iter, 3, | 2181 | gtk_tree_store_set (pe->tab->ts, &iter, 3, |
@@ -2179,98 +2183,114 @@ mark_publish_progress (struct PublishEntry *pe, uint64_t size, | |||
2179 | 0) ? (100 * completed / | 2183 | 0) ? (100 * completed / |
2180 | size) : 100) /* progress */ , | 2184 | size) : 100) /* progress */ , |
2181 | -1); | 2185 | -1); |
2182 | return pe; | ||
2183 | } | 2186 | } |
2184 | 2187 | ||
2185 | 2188 | ||
2186 | /** | 2189 | /** |
2187 | * Close a publish tab and free associated state. | 2190 | * FS-API notified us that we're done with some publish operation. |
2191 | * Update the view accordingly. | ||
2192 | * | ||
2193 | * @param pe publish operation that has finished | ||
2194 | * @param uri resulting URI | ||
2188 | */ | 2195 | */ |
2189 | static void | 2196 | static void |
2190 | handle_publish_completed (struct PublishEntry *pe, | 2197 | handle_publish_completed (struct PublishEntry *pe, |
2191 | const struct GNUNET_FS_Uri *uri) | 2198 | const struct GNUNET_FS_Uri *uri) |
2192 | { | 2199 | { |
2200 | GtkTreeIter iter; | ||
2201 | GtkTreePath *path; | ||
2202 | char *uris; | ||
2203 | |||
2204 | path = gtk_tree_row_reference_get_path (pe->rr); | ||
2205 | if (! gtk_tree_model_get_iter (GTK_TREE_MODEL (pe->tab->ts), &iter, path)) | ||
2206 | { | ||
2207 | GNUNET_break (0); | ||
2208 | gtk_tree_path_free (path); | ||
2209 | return; | ||
2210 | } | ||
2211 | gtk_tree_path_free (path); | ||
2193 | pe->uri = GNUNET_FS_uri_dup (uri); | 2212 | pe->uri = GNUNET_FS_uri_dup (uri); |
2213 | uris = GNUNET_FS_uri_to_string (uri); | ||
2214 | gtk_tree_store_set (pe->tab->ts, &iter, | ||
2215 | 5, uris, | ||
2216 | -1); | ||
2217 | GNUNET_free (uris); | ||
2194 | change_publish_color (pe, "green"); | 2218 | change_publish_color (pe, "green"); |
2195 | } | 2219 | } |
2196 | 2220 | ||
2197 | 2221 | ||
2198 | |||
2199 | /** | 2222 | /** |
2200 | * Handle error. | 2223 | * We received a publish error message from the FS library. |
2224 | * Present it to the user in an appropriate form. | ||
2225 | * | ||
2226 | * @param pe publishing operation affected by the error | ||
2227 | * @param emsg the error message | ||
2201 | */ | 2228 | */ |
2202 | static void | 2229 | static void |
2203 | handle_publish_error (struct PublishEntry *ent, | 2230 | handle_publish_error (struct PublishEntry *pe, |
2204 | const char *emsg) | 2231 | const char *emsg) |
2205 | { | 2232 | { |
2206 | GNUNET_break (0); | 2233 | GtkTreeIter iter; |
2207 | change_publish_color (ent, "red"); | 2234 | GtkTreePath *path; |
2235 | |||
2236 | path = gtk_tree_row_reference_get_path (pe->rr); | ||
2237 | if (! gtk_tree_model_get_iter (GTK_TREE_MODEL (pe->tab->ts), &iter, path)) | ||
2238 | { | ||
2239 | GNUNET_break (0); | ||
2240 | gtk_tree_path_free (path); | ||
2241 | return; | ||
2242 | } | ||
2243 | gtk_tree_path_free (path); | ||
2244 | gtk_tree_store_set (pe->tab->ts, &iter, | ||
2245 | 5, emsg, | ||
2246 | -1); | ||
2247 | change_publish_color (pe, "red"); | ||
2208 | } | 2248 | } |
2209 | 2249 | ||
2210 | 2250 | ||
2211 | /** | 2251 | /** |
2212 | * Close free an entry in the publish tab and free associated state. | 2252 | * A publishing operation was stopped (in FS API). Free an entry in |
2253 | * the publish tab and its associated state. | ||
2254 | * | ||
2255 | * @param pe publishing operation that was stopped | ||
2213 | */ | 2256 | */ |
2214 | static void | 2257 | static void |
2215 | handle_publish_stop (struct PublishEntry *ent) | 2258 | handle_publish_stop (struct PublishEntry *pe) |
2216 | { | 2259 | { |
2217 | GtkTreeIter iter; | 2260 | GtkTreeIter iter; |
2218 | GtkTreePath *path; | 2261 | GtkTreePath *path; |
2219 | GtkTreeModel *tm; | ||
2220 | 2262 | ||
2221 | if (ent == NULL) | 2263 | path = gtk_tree_row_reference_get_path (pe->rr); |
2264 | /* This is a child of a directory, and we've had that directory | ||
2265 | free'd already */ | ||
2266 | if (! gtk_tree_model_get_iter (GTK_TREE_MODEL (pe->tab->ts), &iter, path)) | ||
2222 | { | 2267 | { |
2223 | GNUNET_break (0); | 2268 | GNUNET_break (0); |
2224 | return; | 2269 | return; |
2225 | } | 2270 | } |
2226 | if (NULL != ent->pc) | 2271 | (void) gtk_tree_store_remove (pe->tab->ts, &iter); |
2227 | { | 2272 | gtk_tree_path_free (path); |
2228 | /* get piter from parent */ | 2273 | gtk_tree_row_reference_free (pe->rr); |
2229 | path = gtk_tree_row_reference_get_path (ent->rr); | 2274 | if (pe->uri != NULL) |
2230 | tm = gtk_tree_row_reference_get_model (ent->rr); | ||
2231 | /* This is a child of a directory, and we've had that directory | ||
2232 | * freed already | ||
2233 | */ | ||
2234 | if (path != NULL) | ||
2235 | { | ||
2236 | if (TRUE != gtk_tree_model_get_iter (tm, &iter, path)) | ||
2237 | GNUNET_break (0); | ||
2238 | else | ||
2239 | (void) gtk_tree_store_remove (GTK_TREE_STORE (tm), &iter); | ||
2240 | gtk_tree_path_free (path); | ||
2241 | } | ||
2242 | } | ||
2243 | gtk_tree_row_reference_free (ent->rr); | ||
2244 | if (ent->uri != NULL) | ||
2245 | { | 2275 | { |
2246 | GNUNET_FS_uri_destroy (ent->uri); | 2276 | GNUNET_FS_uri_destroy (pe->uri); |
2247 | ent->uri = NULL; | 2277 | pe->uri = NULL; |
2248 | } | 2278 | } |
2249 | GNUNET_free (ent); | 2279 | GNUNET_free (pe); |
2250 | } | 2280 | } |
2251 | 2281 | ||
2252 | 2282 | ||
2253 | |||
2254 | |||
2255 | |||
2256 | |||
2257 | |||
2258 | |||
2259 | |||
2260 | |||
2261 | |||
2262 | |||
2263 | |||
2264 | |||
2265 | |||
2266 | /** | 2283 | /** |
2284 | * The user clicked on the "close" button of the publishing tab. | ||
2267 | * Tell FS to stop all active publish operations. Then close the tab. | 2285 | * Tell FS to stop all active publish operations. Then close the tab. |
2286 | * | ||
2287 | * @param button the stop button | ||
2288 | * @param user_data the 'struct PublishTab' that is being closed | ||
2268 | */ | 2289 | */ |
2269 | static void | 2290 | static void |
2270 | stop_publishing (GtkButton * button, gpointer user_data) | 2291 | stop_publishing (GtkButton * button, gpointer user_data) |
2271 | { | 2292 | { |
2272 | struct PublishTab *tab = user_data; | 2293 | struct PublishTab *tab = user_data; |
2273 | struct GNUNET_FS_PublishContext *pc; | ||
2274 | struct PublishEntry *ent; | 2294 | struct PublishEntry *ent; |
2275 | GtkTreeIter iter; | 2295 | GtkTreeIter iter; |
2276 | GtkTreeModel *tm; | 2296 | GtkTreeModel *tm; |
@@ -2279,20 +2299,20 @@ stop_publishing (GtkButton * button, gpointer user_data) | |||
2279 | int i; | 2299 | int i; |
2280 | 2300 | ||
2281 | GNUNET_assert (tab == publish_tab); | 2301 | GNUNET_assert (tab == publish_tab); |
2302 | /* stop all active operations */ | ||
2282 | tm = GTK_TREE_MODEL (publish_tab->ts); | 2303 | tm = GTK_TREE_MODEL (publish_tab->ts); |
2283 | if (TRUE == gtk_tree_model_iter_children (tm, &iter, NULL)) | 2304 | if (gtk_tree_model_iter_children (tm, &iter, NULL)) |
2284 | { | 2305 | { |
2285 | do | 2306 | do |
2286 | { | 2307 | { |
2287 | gtk_tree_model_get (tm, &iter, 4, &ent, -1); | 2308 | gtk_tree_model_get (tm, &iter, 4, &ent, -1); |
2288 | if (NULL != (pc = ent->pc)) | 2309 | GNUNET_FS_publish_stop (ent->pc); |
2289 | { | 2310 | ent->pc = NULL; |
2290 | ent->pc = NULL; | ||
2291 | GNUNET_FS_publish_stop (pc); | ||
2292 | } | ||
2293 | } | 2311 | } |
2294 | while (TRUE == gtk_tree_model_iter_next (tm, &iter)); | 2312 | while (TRUE == gtk_tree_model_iter_next (tm, &iter)); |
2295 | } | 2313 | } |
2314 | |||
2315 | /* remove tab from notebook */ | ||
2296 | notebook = | 2316 | notebook = |
2297 | GTK_NOTEBOOK (GNUNET_FS_GTK_get_main_window_object | 2317 | GTK_NOTEBOOK (GNUNET_FS_GTK_get_main_window_object |
2298 | ("GNUNET_GTK_main_window_notebook")); | 2318 | ("GNUNET_GTK_main_window_notebook")); |
@@ -2301,12 +2321,24 @@ stop_publishing (GtkButton * button, gpointer user_data) | |||
2301 | if (publish_tab->frame == gtk_notebook_get_nth_page (notebook, i)) | 2321 | if (publish_tab->frame == gtk_notebook_get_nth_page (notebook, i)) |
2302 | index = i; | 2322 | index = i; |
2303 | gtk_notebook_remove_page (notebook, index); | 2323 | gtk_notebook_remove_page (notebook, index); |
2324 | |||
2325 | /* fully destroy tab */ | ||
2304 | g_object_unref (publish_tab->builder); | 2326 | g_object_unref (publish_tab->builder); |
2305 | GNUNET_free (publish_tab); | 2327 | GNUNET_free (publish_tab); |
2306 | publish_tab = NULL; | 2328 | publish_tab = NULL; |
2307 | } | 2329 | } |
2308 | 2330 | ||
2309 | 2331 | ||
2332 | /** | ||
2333 | * The user started a publishing operation. Add it to the publishing | ||
2334 | * tab. If needed, create the publishing tab. | ||
2335 | * | ||
2336 | * @param pc the FS-API's publishing context for the operation | ||
2337 | * @param fn the name of the file (or directory) that is being published | ||
2338 | * @param fsize size of the file | ||
2339 | * @param parent parent of this publishing operation (for recursive operations), NULL for top-level operations | ||
2340 | * @return the publishing entry that will represent this operation | ||
2341 | */ | ||
2310 | static struct PublishEntry * | 2342 | static struct PublishEntry * |
2311 | setup_publish (struct GNUNET_FS_PublishContext *pc, const char *fn, | 2343 | setup_publish (struct GNUNET_FS_PublishContext *pc, const char *fn, |
2312 | uint64_t fsize, struct PublishEntry *parent) | 2344 | uint64_t fsize, struct PublishEntry *parent) |
@@ -2321,57 +2353,52 @@ setup_publish (struct GNUNET_FS_PublishContext *pc, const char *fn, | |||
2321 | GtkWidget *close_button; | 2353 | GtkWidget *close_button; |
2322 | GtkNotebook *notebook; | 2354 | GtkNotebook *notebook; |
2323 | char *size_fancy; | 2355 | char *size_fancy; |
2356 | |||
2357 | if (NULL == publish_tab) | ||
2358 | { | ||
2359 | /* create new tab */ | ||
2360 | publish_tab = GNUNET_malloc (sizeof (struct PublishTab)); | ||
2361 | publish_tab->builder = | ||
2362 | GNUNET_GTK_get_new_builder ("gnunet_fs_gtk_publish_tab.glade", | ||
2363 | publish_tab); | ||
2364 | df = GTK_WINDOW (gtk_builder_get_object | ||
2365 | (publish_tab->builder, "_publish_frame_window")); | ||
2366 | publish_tab->frame = gtk_bin_get_child (GTK_BIN (df)); | ||
2367 | g_object_ref (publish_tab->frame); | ||
2368 | gtk_container_remove (GTK_CONTAINER (df), publish_tab->frame); | ||
2369 | gtk_widget_destroy (GTK_WIDGET (df)); | ||
2370 | |||
2371 | /* load tab_label */ | ||
2372 | df = GTK_WINDOW (gtk_builder_get_object | ||
2373 | (publish_tab->builder, "_publish_label_window")); | ||
2374 | tab_label = gtk_bin_get_child (GTK_BIN (df)); | ||
2375 | g_object_ref (tab_label); | ||
2376 | gtk_container_remove (GTK_CONTAINER (df), tab_label); | ||
2377 | gtk_widget_destroy (GTK_WIDGET (df)); | ||
2378 | |||
2379 | /* FIXME: connect these signals using GLADE!!! */ | ||
2380 | /* get refs to widgets */ | ||
2381 | close_button = | ||
2382 | GTK_WIDGET (gtk_builder_get_object | ||
2383 | (publish_tab->builder, "_publish_label_close_button")); | ||
2384 | g_signal_connect (G_OBJECT (close_button), "clicked", | ||
2385 | G_CALLBACK (stop_publishing), publish_tab); | ||
2386 | /* make visible */ | ||
2387 | notebook = | ||
2388 | GTK_NOTEBOOK (GNUNET_FS_GTK_get_main_window_object | ||
2389 | ("GNUNET_GTK_main_window_notebook")); | ||
2390 | gtk_notebook_insert_page (notebook, publish_tab->frame, tab_label, 0); | ||
2391 | gtk_widget_show (GTK_WIDGET (notebook)); | ||
2392 | gtk_notebook_set_current_page (notebook, 0); | ||
2393 | publish_tab->ts = | ||
2394 | GTK_TREE_STORE (gtk_builder_get_object | ||
2395 | (publish_tab->builder, "_publish_frame_tree_store")); | ||
2396 | } | ||
2324 | 2397 | ||
2398 | /* decide where to insert in the tab */ | ||
2325 | if (NULL == parent) | 2399 | if (NULL == parent) |
2326 | { | 2400 | { |
2327 | if (NULL == publish_tab) | 2401 | pitrptr = NULL; |
2328 | { | ||
2329 | /* create new tab */ | ||
2330 | publish_tab = GNUNET_malloc (sizeof (struct PublishTab)); | ||
2331 | publish_tab->builder = | ||
2332 | GNUNET_GTK_get_new_builder ("gnunet_fs_gtk_publish_tab.glade", | ||
2333 | publish_tab); | ||
2334 | df = GTK_WINDOW (gtk_builder_get_object | ||
2335 | (publish_tab->builder, "_publish_frame_window")); | ||
2336 | publish_tab->frame = gtk_bin_get_child (GTK_BIN (df)); | ||
2337 | g_object_ref (publish_tab->frame); | ||
2338 | gtk_container_remove (GTK_CONTAINER (df), publish_tab->frame); | ||
2339 | gtk_widget_destroy (GTK_WIDGET (df)); | ||
2340 | |||
2341 | /* load tab_label */ | ||
2342 | df = GTK_WINDOW (gtk_builder_get_object | ||
2343 | (publish_tab->builder, "_publish_label_window")); | ||
2344 | tab_label = gtk_bin_get_child (GTK_BIN (df)); | ||
2345 | g_object_ref (tab_label); | ||
2346 | gtk_container_remove (GTK_CONTAINER (df), tab_label); | ||
2347 | gtk_widget_destroy (GTK_WIDGET (df)); | ||
2348 | |||
2349 | /* FIXME: connect these signals using GLADE!!! */ | ||
2350 | /* get refs to widgets */ | ||
2351 | close_button = | ||
2352 | GTK_WIDGET (gtk_builder_get_object | ||
2353 | (publish_tab->builder, "_publish_label_close_button")); | ||
2354 | g_signal_connect (G_OBJECT (close_button), "clicked", | ||
2355 | G_CALLBACK (stop_publishing), publish_tab); | ||
2356 | /* FIXME: we don't actually need the closure anymore, | ||
2357 | * so we could have glade connect the above signal... */ | ||
2358 | /* make visible */ | ||
2359 | notebook = | ||
2360 | GTK_NOTEBOOK (GNUNET_FS_GTK_get_main_window_object | ||
2361 | ("GNUNET_GTK_main_window_notebook")); | ||
2362 | gtk_notebook_insert_page (notebook, publish_tab->frame, tab_label, 0); | ||
2363 | gtk_widget_show (GTK_WIDGET (notebook)); | ||
2364 | gtk_notebook_set_current_page (notebook, 0); | ||
2365 | publish_tab->ts = | ||
2366 | GTK_TREE_STORE (gtk_builder_get_object | ||
2367 | (publish_tab->builder, "_publish_frame_tree_store")); | ||
2368 | pitrptr = NULL; | ||
2369 | } | ||
2370 | else | ||
2371 | { | ||
2372 | /* use existing TAB, but create fresh entry */ | ||
2373 | pitrptr = NULL; | ||
2374 | } | ||
2375 | } | 2402 | } |
2376 | else | 2403 | else |
2377 | { | 2404 | { |
@@ -2386,28 +2413,30 @@ setup_publish (struct GNUNET_FS_PublishContext *pc, const char *fn, | |||
2386 | } | 2413 | } |
2387 | pitrptr = &piter; | 2414 | pitrptr = &piter; |
2388 | } | 2415 | } |
2389 | size_fancy = GNUNET_STRINGS_byte_size_fancy (fsize); | 2416 | |
2417 | /* create entry and perform insertion */ | ||
2390 | ent = GNUNET_malloc (sizeof (struct PublishEntry)); | 2418 | ent = GNUNET_malloc (sizeof (struct PublishEntry)); |
2391 | ent->is_top = (parent == NULL) ? GNUNET_YES : GNUNET_NO; | 2419 | ent->is_top = (parent == NULL) ? GNUNET_YES : GNUNET_NO; |
2392 | ent->tab = publish_tab; | 2420 | ent->tab = publish_tab; |
2421 | ent->pc = pc; | ||
2422 | size_fancy = GNUNET_STRINGS_byte_size_fancy (fsize); | ||
2393 | gtk_tree_store_insert_with_values (publish_tab->ts, &iter, pitrptr, G_MAXINT, | 2423 | gtk_tree_store_insert_with_values (publish_tab->ts, &iter, pitrptr, G_MAXINT, |
2394 | 0, fn, 1, size_fancy, 2, "white", 3, | 2424 | 0, fn, 1, size_fancy, 2, "white", 3, |
2395 | (guint) 0 /* progress */ , | 2425 | (guint) 0 /* progress */ , |
2396 | 4, ent, -1); | 2426 | 4, ent, -1); |
2427 | GNUNET_free (size_fancy); | ||
2397 | path = gtk_tree_model_get_path (GTK_TREE_MODEL (publish_tab->ts), &iter); | 2428 | path = gtk_tree_model_get_path (GTK_TREE_MODEL (publish_tab->ts), &iter); |
2398 | GNUNET_assert (NULL != path); | ||
2399 | ent->rr = gtk_tree_row_reference_new (GTK_TREE_MODEL (publish_tab->ts), path); | 2429 | ent->rr = gtk_tree_row_reference_new (GTK_TREE_MODEL (publish_tab->ts), path); |
2400 | gtk_tree_path_free (path); | 2430 | gtk_tree_path_free (path); |
2401 | ent->pc = pc; | ||
2402 | GNUNET_free (size_fancy); | ||
2403 | return ent; | 2431 | return ent; |
2404 | } | 2432 | } |
2405 | 2433 | ||
2406 | 2434 | ||
2407 | 2435 | ||
2408 | |||
2409 | /* ***************** Master event handler ****************** */ | 2436 | /* ***************** Master event handler ****************** */ |
2410 | 2437 | ||
2438 | |||
2439 | |||
2411 | /** | 2440 | /** |
2412 | * Notification of FS to a client about the progress of an | 2441 | * Notification of FS to a client about the progress of an |
2413 | * operation. Callbacks of this type will be used for uploads, | 2442 | * operation. Callbacks of this type will be used for uploads, |
@@ -2455,9 +2484,10 @@ GNUNET_GTK_fs_event_handler (void *cls, | |||
2455 | handle_publish_stop (info->value.publish.cctx); | 2484 | handle_publish_stop (info->value.publish.cctx); |
2456 | return NULL; | 2485 | return NULL; |
2457 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: | 2486 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: |
2458 | return mark_publish_progress (info->value.publish.cctx, | 2487 | mark_publish_progress (info->value.publish.cctx, |
2459 | info->value.publish.size, | 2488 | info->value.publish.size, |
2460 | info->value.publish.completed); | 2489 | info->value.publish.completed); |
2490 | return info->value.publish.cctx; | ||
2461 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | 2491 | case GNUNET_FS_STATUS_PUBLISH_ERROR: |
2462 | handle_publish_error (info->value.publish.cctx, | 2492 | handle_publish_error (info->value.publish.cctx, |
2463 | info->value.publish.specifics.error.message); | 2493 | info->value.publish.specifics.error.message); |