# HG changeset patch # User Olaf Wintermann # Date 1732712816 -3600 # Node ID 7ee944cf53de75a3c4cd2f71c3077e61c5f9c9c6 # Parent f501f0efc9a84b23369b21793604c1ab19098030 add transfer speed indicator diff -r f501f0efc9a8 -r 7ee944cf53de application/davcontroller.c --- a/application/davcontroller.c Wed Nov 27 13:27:30 2024 +0100 +++ b/application/davcontroller.c Wed Nov 27 14:06:56 2024 +0100 @@ -1107,3 +1107,14 @@ void dav_resourceviewer_destroy(DavResourceViewer *res) { } + + +uint64_t dav_transfer_speed(TransferProgress *progress, time_t current) { + size_t bytes = progress->transferred_bytes - progress->speedtest_bytes; + time_t t = current - progress->speedtest_start; + + progress->speedtest_start = current; + progress->speedtest_bytes = progress->transferred_bytes; + + return bytes/t; +} diff -r f501f0efc9a8 -r 7ee944cf53de application/davcontroller.h --- a/application/davcontroller.h Wed Nov 27 13:27:30 2024 +0100 +++ b/application/davcontroller.h Wed Nov 27 14:06:56 2024 +0100 @@ -51,6 +51,9 @@ size_t current_file_size; size_t current_file_transferred; + + time_t speedtest_start; + size_t speedtest_bytes; } TransferProgress; DavBrowser* davbrowser_create(UiObject *toplevel); @@ -96,6 +99,8 @@ void dav_resourceviewer_destroy(DavResourceViewer *res); +uint64_t dav_transfer_speed(TransferProgress *progress, time_t current); + #ifdef __cplusplus } #endif diff -r f501f0efc9a8 -r 7ee944cf53de application/download.c --- a/application/download.c Wed Nov 27 13:27:30 2024 +0100 +++ b/application/download.c Wed Nov 27 14:06:56 2024 +0100 @@ -80,6 +80,18 @@ free(sz_total); 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) { + char *szps = util_size_str(FALSE, bytesPerSeconds); + cxmutstr label3 = cx_asprintf("%s/s", szps); + free(szps); + ui_set(download->label_bottom_left, label3.ptr); + free(label3.ptr); + } + } return 1; } diff -r f501f0efc9a8 -r 7ee944cf53de application/upload.c --- a/application/upload.c Wed Nov 27 13:27:30 2024 +0100 +++ b/application/upload.c Wed Nov 27 14:06:56 2024 +0100 @@ -82,6 +82,19 @@ ui_set(upload->label_top_right, file_label.ptr); free(file_label.ptr); } + + time_t start = upload->progress.speedtest_start; + time_t t = time(NULL); + if(t >= upload->progress.speedtest_start + 4) { + uint64_t bytesPerSeconds = dav_transfer_speed(&upload->progress, t); + if(start > 0) { + char *szps = util_size_str(FALSE, bytesPerSeconds); + cxmutstr label3 = cx_asprintf("%s/s", szps); + free(szps); + ui_set(upload->label_bottom_left, label3.ptr); + free(label3.ptr); + } + } }