add transfer speed indicator

Wed, 27 Nov 2024 14:06:56 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Wed, 27 Nov 2024 14:06:56 +0100
changeset 91
7ee944cf53de
parent 90
f501f0efc9a8
child 92
43aee6c8c166

add transfer speed indicator

application/davcontroller.c file | annotate | diff | comparison | revisions
application/davcontroller.h file | annotate | diff | comparison | revisions
application/download.c file | annotate | diff | comparison | revisions
application/upload.c file | annotate | diff | comparison | revisions
--- 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;
+}
--- 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
--- 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;
 }
--- 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);
+        }
+    }
 }
 
 

mercurial