diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-01-02 05:59:46 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-01-02 05:59:46 +0000 |
commit | 98914cee4ae85f5902e0fcbf3584e4f68d5b8da0 (patch) | |
tree | 33329ee69d137e6f06747251d89c9eb7b04dac70 | |
parent | e8c1862ac85cd97a6a0f4ab50ed5719cf53b31ed (diff) | |
download | gnunet-gtk-98914cee4ae85f5902e0fcbf3584e4f68d5b8da0.tar.gz gnunet-gtk-98914cee4ae85f5902e0fcbf3584e4f68d5b8da0.zip |
-LRN: removing delayed update patch
-rw-r--r-- | src/fs/gnunet-fs-gtk-event_handler.c | 152 |
1 files changed, 33 insertions, 119 deletions
diff --git a/src/fs/gnunet-fs-gtk-event_handler.c b/src/fs/gnunet-fs-gtk-event_handler.c index f083f69b..94558630 100644 --- a/src/fs/gnunet-fs-gtk-event_handler.c +++ b/src/fs/gnunet-fs-gtk-event_handler.c | |||
@@ -113,22 +113,6 @@ struct StartDownloadContext | |||
113 | 113 | ||
114 | static struct PublishTab *publish_tab; | 114 | static struct PublishTab *publish_tab; |
115 | 115 | ||
116 | struct UpdateSearchItem | ||
117 | { | ||
118 | struct UpdateSearchItem *prev; | ||
119 | struct UpdateSearchItem *next; | ||
120 | struct DownloadEntry *de; | ||
121 | uint64_t size; | ||
122 | uint64_t completed; | ||
123 | void *block_data; | ||
124 | uint64_t offset; | ||
125 | uint64_t block_size; | ||
126 | unsigned int depth; | ||
127 | }; | ||
128 | |||
129 | GNUNET_SCHEDULER_TaskIdentifier update_progress_task = GNUNET_SCHEDULER_NO_TASK; | ||
130 | |||
131 | |||
132 | static void | 116 | static void |
133 | closure_notify_free (gpointer data, GClosure *closure) | 117 | closure_notify_free (gpointer data, GClosure *closure) |
134 | { | 118 | { |
@@ -311,120 +295,50 @@ add_directory_entry (void *cls, const char *filename, | |||
311 | } | 295 | } |
312 | 296 | ||
313 | 297 | ||
314 | static void | ||
315 | mark_download_progress_delayed (struct DownloadEntry *de, uint64_t size, | ||
316 | uint64_t completed, const void *block_data, | ||
317 | uint64_t offset, uint64_t block_size, unsigned int depth) | ||
318 | { | ||
319 | GtkTreeIter iter; | ||
320 | GtkTreePath *path; | ||
321 | |||
322 | do | ||
323 | { | ||
324 | path = gtk_tree_row_reference_get_path (de->rr); | ||
325 | if (TRUE != gtk_tree_model_get_iter (GTK_TREE_MODEL (de->ts), &iter, path)) | ||
326 | { | ||
327 | GNUNET_break (0); | ||
328 | gtk_tree_path_free (path); | ||
329 | break; | ||
330 | } | ||
331 | gtk_tree_path_free (path); | ||
332 | gtk_tree_store_set (de->ts, &iter, 4, | ||
333 | (guint) ((size > | ||
334 | 0) ? (100 * completed / | ||
335 | size) : 100) /* progress */ , | ||
336 | 14, completed, -1); | ||
337 | if ((depth == 0) && (block_size > 0) && | ||
338 | (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (de->meta))) | ||
339 | { | ||
340 | struct AddDirectoryEntryContext ade; | ||
341 | ade.de = de; | ||
342 | ade.prr = de->rr; | ||
343 | ade.check_duplicates = GNUNET_NO; | ||
344 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "It is a directory, list its contents\n"); | ||
345 | if (GNUNET_SYSERR == | ||
346 | GNUNET_FS_directory_list_contents ((size_t) block_size, block_data, | ||
347 | offset, &add_directory_entry, &ade)) | ||
348 | { | ||
349 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
350 | _ | ||
351 | ("Metadata wrongly claims that this is a GNUnet directory!\n")); | ||
352 | } | ||
353 | } | ||
354 | } while (0); | ||
355 | } | ||
356 | |||
357 | |||
358 | void | ||
359 | GNUNET_FS_GTK_update_download_progress (void *cls, | ||
360 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
361 | { | ||
362 | struct SearchTab *st; | ||
363 | GtkTreeStore *ts; | ||
364 | struct UpdateSearchItem *usi_head; | ||
365 | struct UpdateSearchItem *usi_tail; | ||
366 | struct UpdateSearchItem *usi; | ||
367 | struct UpdateSearchItem *next; | ||
368 | |||
369 | update_progress_task = GNUNET_SCHEDULER_NO_TASK; | ||
370 | for (st = search_tab_head; st; st = st->next) | ||
371 | { | ||
372 | ts = st->ts; | ||
373 | usi_head = g_object_get_data (G_OBJECT (ts), "usi_head"); | ||
374 | usi_tail = g_object_get_data (G_OBJECT (ts), "usi_tail"); | ||
375 | for (usi = usi_head; NULL != usi; usi = next) | ||
376 | { | ||
377 | next = usi->next; | ||
378 | mark_download_progress_delayed (usi->de, usi->size, | ||
379 | usi->completed, usi->block_data, usi->offset, usi->block_size, | ||
380 | usi->depth); | ||
381 | GNUNET_CONTAINER_DLL_remove (usi_head, usi_tail, usi); | ||
382 | GNUNET_free_non_null (usi->block_data); | ||
383 | GNUNET_free (usi); | ||
384 | } | ||
385 | g_object_set_data (G_OBJECT (ts), "usi_head", usi_head); | ||
386 | g_object_set_data (G_OBJECT (ts), "usi_tail", usi_tail); | ||
387 | } | ||
388 | if (!(tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | ||
389 | update_progress_task = GNUNET_SCHEDULER_add_delayed ( | ||
390 | GNUNET_TIME_UNIT_SECONDS, | ||
391 | GNUNET_FS_GTK_update_download_progress, NULL); | ||
392 | } | ||
393 | |||
394 | |||
395 | static struct DownloadEntry * | 298 | static struct DownloadEntry * |
396 | mark_download_progress (struct DownloadEntry *de, uint64_t size, | 299 | mark_download_progress (struct DownloadEntry *de, uint64_t size, |
397 | uint64_t completed, const void *block_data, | 300 | uint64_t completed, const void *block_data, |
398 | uint64_t offset, uint64_t block_size, | 301 | uint64_t offset, uint64_t block_size, |
399 | unsigned int depth) | 302 | unsigned int depth) |
400 | { | 303 | { |
401 | struct UpdateSearchItem *usi_head; | 304 | GtkTreeIter iter; |
402 | struct UpdateSearchItem *usi_tail; | 305 | GtkTreePath *path; |
403 | struct UpdateSearchItem *usi_new; | ||
404 | 306 | ||
405 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 307 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
406 | "Marking download progress for DE=%p, %llu/%llu, %llu@%llu depth=%u\n", | 308 | "Marking download progress for DE=%p, %llu/%llu, %llu@%llu depth=%u\n", |
407 | de, completed, size, block_size, offset, depth); | 309 | de, completed, size, block_size, offset, depth); |
408 | 310 | ||
409 | usi_head = g_object_get_data (G_OBJECT (de->ts), "usi_head"); | 311 | |
410 | usi_tail = g_object_get_data (G_OBJECT (de->ts), "usi_tail"); | 312 | path = gtk_tree_row_reference_get_path (de->rr); |
411 | usi_new = GNUNET_malloc (sizeof (struct UpdateSearchItem)); | 313 | if (TRUE != gtk_tree_model_get_iter (GTK_TREE_MODEL (de->ts), &iter, path)) |
412 | usi_new->de = de; | 314 | { |
413 | usi_new->size = size; | 315 | GNUNET_break (0); |
414 | usi_new->completed = completed; | 316 | gtk_tree_path_free (path); |
415 | usi_new->block_data = GNUNET_malloc (block_size); | 317 | return de; |
416 | memcpy (usi_new->block_data, block_data, block_size); | 318 | } |
417 | usi_new->offset = offset; | 319 | gtk_tree_path_free (path); |
418 | usi_new->block_size = block_size; | 320 | gtk_tree_store_set (de->ts, &iter, 4, |
419 | usi_new->depth = depth; | 321 | (guint) ((size > |
420 | GNUNET_CONTAINER_DLL_insert_tail (usi_head, usi_tail, usi_new); | 322 | 0) ? (100 * completed / |
421 | g_object_set_data (G_OBJECT (de->ts), "usi_head", usi_head); | 323 | size) : 100) /* progress */ , |
422 | g_object_set_data (G_OBJECT (de->ts), "usi_tail", usi_tail); | 324 | 14, completed, -1); |
423 | 325 | if ((depth == 0) && (block_size > 0) && | |
424 | if (update_progress_task == GNUNET_SCHEDULER_NO_TASK) | 326 | (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (de->meta))) |
425 | update_progress_task = GNUNET_SCHEDULER_add_delayed ( | 327 | { |
426 | GNUNET_TIME_UNIT_SECONDS, | 328 | struct AddDirectoryEntryContext ade; |
427 | GNUNET_FS_GTK_update_download_progress, NULL); | 329 | ade.de = de; |
330 | ade.prr = de->rr; | ||
331 | ade.check_duplicates = GNUNET_NO; | ||
332 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "It is a directory, list its contents\n"); | ||
333 | if (GNUNET_SYSERR == | ||
334 | GNUNET_FS_directory_list_contents ((size_t) block_size, block_data, | ||
335 | offset, &add_directory_entry, &ade)) | ||
336 | { | ||
337 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
338 | _ | ||
339 | ("Metadata wrongly claims that this is a GNUnet directory!\n")); | ||
340 | } | ||
341 | } | ||
428 | return de; | 342 | return de; |
429 | } | 343 | } |
430 | 344 | ||