diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-07-18 07:57:49 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-07-18 07:57:49 +0300 |
commit | d6542ff3cfd852102d025a06d3f55002047aed1e (patch) | |
tree | f0fc1a70956764cdbfca5751fb2af843ddb72058 /src/ui | |
parent | 9f1c07241a39d4aa2ebc34986731bba8467d4d19 (diff) |
UploadWidget: Monitoring progress
Socket can now tell us how much data is being sent, so the upload progress can be monitored.
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/uploadwidget.c | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/src/ui/uploadwidget.c b/src/ui/uploadwidget.c index 968b3775..f2ddda98 100644 --- a/src/ui/uploadwidget.c +++ b/src/ui/uploadwidget.c | |||
@@ -45,11 +45,21 @@ struct Impl_UploadWidget { | |||
45 | iInputWidget * input; | 45 | iInputWidget * input; |
46 | iLabelWidget * filePathLabel; | 46 | iLabelWidget * filePathLabel; |
47 | iLabelWidget * fileSizeLabel; | 47 | iLabelWidget * fileSizeLabel; |
48 | iLabelWidget * counter; | ||
48 | iString filePath; | 49 | iString filePath; |
49 | size_t fileSize; | 50 | size_t fileSize; |
50 | iAtomicInt isRequestUpdated; | 51 | iAtomicInt isRequestUpdated; |
51 | }; | 52 | }; |
52 | 53 | ||
54 | static void updateProgress_UploadWidget_(iGmRequest *request, size_t current, size_t total) { | ||
55 | iUploadWidget *d = userData_Object(request); | ||
56 | postCommand_Widget(d, | ||
57 | "upload.request.updated reqid:%u arg:%zu total:%zu", | ||
58 | id_GmRequest(request), | ||
59 | current, | ||
60 | total); | ||
61 | } | ||
62 | |||
53 | void init_UploadWidget(iUploadWidget *d) { | 63 | void init_UploadWidget(iUploadWidget *d) { |
54 | iWidget *w = as_Widget(d); | 64 | iWidget *w = as_Widget(d); |
55 | init_Widget(w); | 65 | init_Widget(w); |
@@ -113,9 +123,9 @@ void init_UploadWidget(iUploadWidget *d) { | |||
113 | "upload.accept" } }, | 123 | "upload.accept" } }, |
114 | 2); | 124 | 2); |
115 | setId_Widget(addChildPosFlags_Widget(buttons, | 125 | setId_Widget(addChildPosFlags_Widget(buttons, |
116 | iClob(new_LabelWidget("0", NULL)), | 126 | iClob(d->counter = new_LabelWidget("", NULL)), |
117 | front_WidgetAddPos, frameless_WidgetFlag), | 127 | front_WidgetAddPos, frameless_WidgetFlag), |
118 | "upload.pending"); | 128 | "upload.counter"); |
119 | addChild_Widget(w, iClob(buttons)); | 129 | addChild_Widget(w, iClob(buttons)); |
120 | } | 130 | } |
121 | resizeToLargestPage_Widget(tabs); | 131 | resizeToLargestPage_Widget(tabs); |
@@ -144,11 +154,13 @@ static iWidget *acceptButton_UploadWidget_(iUploadWidget *d) { | |||
144 | return lastChild_Widget(findChild_Widget(as_Widget(d), "dialogbuttons")); | 154 | return lastChild_Widget(findChild_Widget(as_Widget(d), "dialogbuttons")); |
145 | } | 155 | } |
146 | 156 | ||
157 | #if 0 | ||
147 | static void requestUpdated_UploadWidget_(iUploadWidget *d, iGmRequest *req) { | 158 | static void requestUpdated_UploadWidget_(iUploadWidget *d, iGmRequest *req) { |
148 | if (!exchange_Atomic(&d->isRequestUpdated, iTrue)) { | 159 | if (!exchange_Atomic(&d->isRequestUpdated, iTrue)) { |
149 | postCommand_Widget(d, "upload.request.updated reqid:%u", id_GmRequest(req)); | 160 | postCommand_Widget(d, "upload.request.updated reqid:%u", id_GmRequest(req)); |
150 | } | 161 | } |
151 | } | 162 | } |
163 | #endif | ||
152 | 164 | ||
153 | static void requestFinished_UploadWidget_(iUploadWidget *d, iGmRequest *req) { | 165 | static void requestFinished_UploadWidget_(iUploadWidget *d, iGmRequest *req) { |
154 | postCommand_Widget(d, "upload.request.finished reqid:%u", id_GmRequest(req)); | 166 | postCommand_Widget(d, "upload.request.finished reqid:%u", id_GmRequest(req)); |
@@ -170,6 +182,8 @@ static iBool processEvent_UploadWidget_(iUploadWidget *d, const SDL_Event *ev) { | |||
170 | iAssert(d->request == NULL); | 182 | iAssert(d->request == NULL); |
171 | iAssert(!isEmpty_String(&d->url)); | 183 | iAssert(!isEmpty_String(&d->url)); |
172 | d->request = new_GmRequest(certs_App()); | 184 | d->request = new_GmRequest(certs_App()); |
185 | setSendProgressFunc_GmRequest(d->request, updateProgress_UploadWidget_); | ||
186 | setUserData_Object(d->request, d); | ||
173 | setUrl_GmRequest(d->request, &d->url); | 187 | setUrl_GmRequest(d->request, &d->url); |
174 | if (tabIndex == 0) { | 188 | if (tabIndex == 0) { |
175 | /* Uploading text. */ | 189 | /* Uploading text. */ |
@@ -194,7 +208,7 @@ static iBool processEvent_UploadWidget_(iUploadWidget *d, const SDL_Event *ev) { | |||
194 | text_InputWidget(d->token)); | 208 | text_InputWidget(d->token)); |
195 | close_File(f); | 209 | close_File(f); |
196 | } | 210 | } |
197 | iConnect(GmRequest, d->request, updated, d, requestUpdated_UploadWidget_); | 211 | // iConnect(GmRequest, d->request, updated, d, requestUpdated_UploadWidget_); |
198 | iConnect(GmRequest, d->request, finished, d, requestFinished_UploadWidget_); | 212 | iConnect(GmRequest, d->request, finished, d, requestFinished_UploadWidget_); |
199 | submit_GmRequest(d->request); | 213 | submit_GmRequest(d->request); |
200 | /* The dialog will remain open until the request finishes, showing upload progress. */ | 214 | /* The dialog will remain open until the request finishes, showing upload progress. */ |
@@ -204,8 +218,10 @@ static iBool processEvent_UploadWidget_(iUploadWidget *d, const SDL_Event *ev) { | |||
204 | setFlags_Widget(acceptButton_UploadWidget_(d), disabled_WidgetFlag, iTrue); | 218 | setFlags_Widget(acceptButton_UploadWidget_(d), disabled_WidgetFlag, iTrue); |
205 | return iTrue; | 219 | return iTrue; |
206 | } | 220 | } |
207 | else if (isCommand_Widget(w, ev, "upload.request.updated")) { | 221 | else if (isCommand_Widget(w, ev, "upload.request.updated") && |
208 | /* TODO: Upload progress update? */ | 222 | id_GmRequest(d->request) == argU32Label_Command(cmd, "reqid")) { |
223 | setText_LabelWidget(d->counter, | ||
224 | collectNewFormat_String("%u", argU32Label_Command(cmd, "arg"))); | ||
209 | } | 225 | } |
210 | else if (isCommand_Widget(w, ev, "upload.request.finished") && | 226 | else if (isCommand_Widget(w, ev, "upload.request.finished") && |
211 | id_GmRequest(d->request) == argU32Label_Command(cmd, "reqid")) { | 227 | id_GmRequest(d->request) == argU32Label_Command(cmd, "reqid")) { |