diff -r 7fdf1489b82f -r e92c72705da4 application/download.c --- a/application/download.c Wed Nov 27 17:14:57 2024 +0100 +++ b/application/download.c Wed Nov 27 18:45:08 2024 +0100 @@ -48,6 +48,8 @@ return 1; } + time_t t = time(NULL); + char *sz_total = util_size_str(FALSE, download->progress.total_bytes); char *sz_downloaded = util_size_str2(FALSE, download->progress.transferred_bytes, download->progress.total_bytes, 2); char *sz_downloaded_end = strchr(sz_downloaded, ' '); @@ -56,8 +58,16 @@ } if (download->progress.total_bytes > 0) { - double progress = (double)download->progress.transferred_bytes / (double)download->progress.total_bytes; - ui_set(download->progressbar, progress*100); + double progress = ((double)download->progress.transferred_bytes / (double)download->progress.total_bytes)*100; + ui_set(download->progressbar, progress); + download->trans.progress = progress; + /* + if(t > download->trans.last_update + 2) { + snprintf(download->trans.label+download->trans.label_len, 12, " %d%%", (int)progress); + application_update_transferlist(); + download->trans.last_update = t; + } + */ } @@ -81,7 +91,6 @@ free(label1.ptr); time_t start = download->progress.speedtest_start; - time_t t = time(NULL); if(t >= download->progress.speedtest_start + 4) { uint64_t bytesPerSeconds = dav_transfer_speed(&download->progress, t); if(start > 0) { @@ -263,13 +272,6 @@ } -static void download_window_closed(UiEvent *event, void *data) { - DavFileDownload *download = event->obj->window; - - dav_session_destroy(download->sn); - ui_threadpool_destroy(download->queue); -} - void action_download_cancel(UiEvent *event, void *data) { DavFileDownload *download = event->window; if(!download->cancel) { @@ -278,14 +280,25 @@ } } +static void dav_file_download_cleanup(DavFileDownload *download) { + application_remove_transfer(&download->trans); + ui_object_unref(download->browser->window); +} DavFileDownload* dav_download_create(DavBrowser *browser, UiObject *dialog, DavResource *reslist, const char *local_path) { UiContext *ctx = dialog->ctx; + CxMempool *mp = ui_cx_mempool(ctx); DavFileDownload *download = ui_malloc(ctx, sizeof(DavFileDownload)); memset(download, 0, sizeof(DavFileDownload)); download->dialog = dialog; dialog->window = download; ui_object_ref(dialog); + ui_object_ref(browser->window); + + size_t label_len = strlen(reslist->name) + 16; + download->trans.label = cxCalloc(mp->allocator, label_len, 1); + download->trans.label_len = snprintf(download->trans.label, label_len, "< %s%s", reslist->name, reslist->next ? " ..." : ""); + download->trans.window = dialog; download->browser = browser; download->sn = reslist->session; @@ -295,9 +308,9 @@ download->queue = ui_threadpool_create(1); - CxMempool *mp = ui_cx_mempool(ctx); cxMempoolRegister(mp, download->download_sn, (cx_destructor_func)dav_session_destroy); cxMempoolRegister(mp, download->queue, (cx_destructor_func)ui_threadpool_destroy); + cxMempoolSetDestructor(download, (cx_destructor_func)dav_file_download_cleanup); download->progressbar = ui_double_new(ctx, "progressbar"); download->label_top_left = ui_string_new(ctx, "label_top_left");