55 *sz_uploaded_end = 0; |
55 *sz_uploaded_end = 0; |
56 } |
56 } |
57 |
57 |
58 double progress = upload_progress(upload); |
58 double progress = upload_progress(upload); |
59 ui_set(upload->progressbar, progress); |
59 ui_set(upload->progressbar, progress); |
|
60 upload->trans.progress = progress; |
|
61 time_t t = time(NULL); |
|
62 /* |
|
63 if(t > upload->trans.last_update + 2) { |
|
64 snprintf(upload->trans.label+upload->trans.label_len, 12, " %d%%", (int)progress); |
|
65 application_update_transferlist(); |
|
66 upload->trans.last_update = t; |
|
67 } |
|
68 */ |
60 |
69 |
61 cxmutstr label1; |
70 cxmutstr label1; |
62 if (upload->progress.total_files + upload->progress.total_directories > 1) { |
71 if (upload->progress.total_files + upload->progress.total_directories > 1) { |
63 label1 = cx_asprintf( |
72 label1 = cx_asprintf( |
64 "%s/%s %zu/%zu files", |
73 "%s/%s %zu/%zu files", |
82 ui_set(upload->label_top_right, file_label.ptr); |
91 ui_set(upload->label_top_right, file_label.ptr); |
83 free(file_label.ptr); |
92 free(file_label.ptr); |
84 } |
93 } |
85 |
94 |
86 time_t start = upload->progress.speedtest_start; |
95 time_t start = upload->progress.speedtest_start; |
87 time_t t = time(NULL); |
|
88 if(t >= upload->progress.speedtest_start + 4) { |
96 if(t >= upload->progress.speedtest_start + 4) { |
89 uint64_t bytesPerSeconds = dav_transfer_speed(&upload->progress, t); |
97 uint64_t bytesPerSeconds = dav_transfer_speed(&upload->progress, t); |
90 if(start > 0) { |
98 if(start > 0) { |
91 char *szps = util_size_str(FALSE, bytesPerSeconds); |
99 char *szps = util_size_str(FALSE, bytesPerSeconds); |
92 cxmutstr label3 = cx_asprintf("%s/s", szps); |
100 cxmutstr label3 = cx_asprintf("%s/s", szps); |
405 ui_set(upload->label_bottom_left, "Cancel..."); |
413 ui_set(upload->label_bottom_left, "Cancel..."); |
406 upload->cancel = TRUE; |
414 upload->cancel = TRUE; |
407 } |
415 } |
408 } |
416 } |
409 |
417 |
|
418 static void dav_file_upload_cleanup(DavFileUpload *upload) { |
|
419 application_remove_transfer(&upload->trans); |
|
420 ui_object_unref(upload->browser->window); |
|
421 } |
|
422 |
410 DavFileUpload* dav_upload_create(DavBrowser *browser, UiObject *obj, UiFileList files) { |
423 DavFileUpload* dav_upload_create(DavBrowser *browser, UiObject *obj, UiFileList files) { |
411 UiContext *ctx = obj->ctx; |
424 UiContext *ctx = obj->ctx; |
|
425 CxMempool *mp = ui_cx_mempool(ctx); |
412 DavFileUpload *upload = ui_malloc(ctx, sizeof(DavFileUpload)); |
426 DavFileUpload *upload = ui_malloc(ctx, sizeof(DavFileUpload)); |
413 memset(upload, 0, sizeof(DavFileUpload)); |
427 memset(upload, 0, sizeof(DavFileUpload)); |
414 upload->dialog = obj; |
428 upload->dialog = obj; |
415 obj->window = upload; |
429 obj->window = upload; |
416 ui_object_ref(obj); |
430 ui_object_ref(obj); |
|
431 ui_object_ref(browser->window); |
|
432 |
|
433 size_t label_len = strlen(util_resource_name(files.files[0])) + 16; |
|
434 upload->trans.label = cxCalloc(mp->allocator, label_len, 1); |
|
435 upload->trans.label_len = snprintf(upload->trans.label, label_len, "> %s%s", util_resource_name(files.files[0]), files.nfiles > 1 ? " ..." : ""); |
|
436 upload->trans.window = obj; |
417 |
437 |
418 upload->progressbar = ui_double_new(ctx, "progressbar"); |
438 upload->progressbar = ui_double_new(ctx, "progressbar"); |
419 upload->label_top_left = ui_string_new(ctx, "label_top_left"); |
439 upload->label_top_left = ui_string_new(ctx, "label_top_left"); |
420 upload->label_top_right = ui_string_new(ctx, "label_top_right"); |
440 upload->label_top_right = ui_string_new(ctx, "label_top_right"); |
421 upload->label_bottom_left = ui_string_new(ctx, "label_bottom_left"); |
441 upload->label_bottom_left = ui_string_new(ctx, "label_bottom_left"); |
434 upload->queue = ui_threadpool_create(1); |
454 upload->queue = ui_threadpool_create(1); |
435 |
455 |
436 upload->collection = browser->current; |
456 upload->collection = browser->current; |
437 upload->collection_ctn = browser->res_counter; |
457 upload->collection_ctn = browser->res_counter; |
438 |
458 |
439 CxMempool *mp = ui_cx_mempool(ctx); |
|
440 cxMempoolRegister(mp, upload_session, (cx_destructor_func)dav_session_destroy); |
459 cxMempoolRegister(mp, upload_session, (cx_destructor_func)dav_session_destroy); |
441 cxMempoolRegister(mp, upload->queue, (cx_destructor_func)ui_threadpool_destroy); |
460 cxMempoolRegister(mp, upload->queue, (cx_destructor_func)ui_threadpool_destroy); |
|
461 cxMempoolSetDestructor(upload, (cx_destructor_func)dav_file_upload_cleanup); |
442 |
462 |
443 ui_set(upload->label_top_left, ""); |
463 ui_set(upload->label_top_left, ""); |
444 ui_set(upload->label_top_right, ""); |
464 ui_set(upload->label_top_right, ""); |
445 ui_set(upload->label_bottom_left, ""); |
465 ui_set(upload->label_bottom_left, ""); |
446 ui_set(upload->label_bottom_right, ""); |
466 ui_set(upload->label_bottom_right, ""); |