summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gmrequest.c15
-rw-r--r--src/gmrequest.h3
-rw-r--r--src/ui/uploadwidget.c26
3 files changed, 39 insertions, 5 deletions
diff --git a/src/gmrequest.c b/src/gmrequest.c
index cd193627..1d2790cc 100644
--- a/src/gmrequest.c
+++ b/src/gmrequest.c
@@ -170,6 +170,7 @@ struct Impl_GmRequest {
170 iAtomicInt allowUpdate; 170 iAtomicInt allowUpdate;
171 iAudience * updated; 171 iAudience * updated;
172 iAudience * finished; 172 iAudience * finished;
173 iGmRequestProgressFunc sendProgress;
173}; 174};
174 175
175iDefineObjectConstructionArgs(GmRequest, (iGmCerts *certs), certs) 176iDefineObjectConstructionArgs(GmRequest, (iGmCerts *certs), certs)
@@ -538,11 +539,13 @@ void init_GmRequest(iGmRequest *d, iGmCerts *certs) {
538 d->req = NULL; 539 d->req = NULL;
539 d->updated = NULL; 540 d->updated = NULL;
540 d->finished = NULL; 541 d->finished = NULL;
542 d->sendProgress = NULL;
541 d->state = initialized_GmRequestState; 543 d->state = initialized_GmRequestState;
542} 544}
543 545
544void deinit_GmRequest(iGmRequest *d) { 546void deinit_GmRequest(iGmRequest *d) {
545 if (d->req) { 547 if (d->req) {
548 iDisconnectObject(TlsRequest, d->req, sent, d);
546 iDisconnectObject(TlsRequest, d->req, readyRead, d); 549 iDisconnectObject(TlsRequest, d->req, readyRead, d);
547 iDisconnectObject(TlsRequest, d->req, finished, d); 550 iDisconnectObject(TlsRequest, d->req, finished, d);
548 } 551 }
@@ -595,6 +598,17 @@ void setTitanData_GmRequest(iGmRequest *d, const iString *mime, const iBlock *pa
595 set_String(&d->titan->token, token); 598 set_String(&d->titan->token, token);
596} 599}
597 600
601void setSendProgressFunc_GmRequest(iGmRequest *d, iGmRequestProgressFunc func) {
602 d->sendProgress = func;
603}
604
605static void bytesSent_GmRequest_(iGmRequest *d, iTlsRequest *req, size_t sent, size_t toSend) {
606 iUnused(req);
607 if (d->sendProgress) {
608 d->sendProgress(d, sent, toSend);
609 }
610}
611
598static iBool isDirectory_(const iString *path) { 612static iBool isDirectory_(const iString *path) {
599 /* TODO: move this to the_Foundation */ 613 /* TODO: move this to the_Foundation */
600 iFileInfo *info = new_FileInfo(path); 614 iFileInfo *info = new_FileInfo(path);
@@ -893,6 +907,7 @@ void submit_GmRequest(iGmRequest *d) {
893 setCertificate_TlsRequest(d->req, identity->cert); 907 setCertificate_TlsRequest(d->req, identity->cert);
894 } 908 }
895 iConnect(TlsRequest, d->req, readyRead, d, readIncoming_GmRequest_); 909 iConnect(TlsRequest, d->req, readyRead, d, readIncoming_GmRequest_);
910 iConnect(TlsRequest, d->req, sent, d, bytesSent_GmRequest_);
896 iConnect(TlsRequest, d->req, finished, d, requestFinished_GmRequest_); 911 iConnect(TlsRequest, d->req, finished, d, requestFinished_GmRequest_);
897 if (port == 0) { 912 if (port == 0) {
898 port = GEMINI_DEFAULT_PORT; /* default Gemini port */ 913 port = GEMINI_DEFAULT_PORT; /* default Gemini port */
diff --git a/src/gmrequest.h b/src/gmrequest.h
index 2b1f1bdd..97b23f3c 100644
--- a/src/gmrequest.h
+++ b/src/gmrequest.h
@@ -64,11 +64,14 @@ iDeclareNotifyFunc(GmRequest, Updated)
64iDeclareNotifyFunc(GmRequest, Finished) 64iDeclareNotifyFunc(GmRequest, Finished)
65iDeclareAudienceGetter(GmRequest, updated) 65iDeclareAudienceGetter(GmRequest, updated)
66iDeclareAudienceGetter(GmRequest, finished) 66iDeclareAudienceGetter(GmRequest, finished)
67
68typedef void (*iGmRequestProgressFunc)(iGmRequest *, size_t current, size_t total);
67 69
68void enableFilters_GmRequest (iGmRequest *, iBool enable); 70void enableFilters_GmRequest (iGmRequest *, iBool enable);
69void setUrl_GmRequest (iGmRequest *, const iString *url); 71void setUrl_GmRequest (iGmRequest *, const iString *url);
70void setTitanData_GmRequest (iGmRequest *, const iString *mime, 72void setTitanData_GmRequest (iGmRequest *, const iString *mime,
71 const iBlock *payload, const iString *token); 73 const iBlock *payload, const iString *token);
74void setSendProgressFunc_GmRequest(iGmRequest *, iGmRequestProgressFunc func);
72void submit_GmRequest (iGmRequest *); 75void submit_GmRequest (iGmRequest *);
73void cancel_GmRequest (iGmRequest *); 76void cancel_GmRequest (iGmRequest *);
74 77
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
54static 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
53void init_UploadWidget(iUploadWidget *d) { 63void 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
147static void requestUpdated_UploadWidget_(iUploadWidget *d, iGmRequest *req) { 158static 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
153static void requestFinished_UploadWidget_(iUploadWidget *d, iGmRequest *req) { 165static 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")) {