summaryrefslogtreecommitdiff
path: root/src/ui/uploadwidget.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/uploadwidget.c')
-rw-r--r--src/ui/uploadwidget.c32
1 files changed, 25 insertions, 7 deletions
diff --git a/src/ui/uploadwidget.c b/src/ui/uploadwidget.c
index 58106dcb..9e86741e 100644
--- a/src/ui/uploadwidget.c
+++ b/src/ui/uploadwidget.c
@@ -56,6 +56,7 @@ struct Impl_UploadWidget {
56 iDocumentWidget *viewer; 56 iDocumentWidget *viewer;
57 iGmRequest * request; 57 iGmRequest * request;
58 iLabelWidget * info; 58 iLabelWidget * info;
59 iInputWidget * path;
59 iInputWidget * mime; 60 iInputWidget * mime;
60 iInputWidget * token; 61 iInputWidget * token;
61 iLabelWidget * ident; 62 iLabelWidget * ident;
@@ -192,14 +193,17 @@ void init_UploadWidget(iUploadWidget *d) {
192 initPanels_Mobile(w, NULL, (iMenuItem[]){ 193 initPanels_Mobile(w, NULL, (iMenuItem[]){
193 { "title id:heading.upload" }, 194 { "title id:heading.upload" },
194 { "label id:upload.info" }, 195 { "label id:upload.info" },
195 { "panel id:dlg.upload.text icon:0x1f5b9 noscroll:1", 0, 0, (const void *) textItems }, 196 { "input id:upload.path hint:hint.upload.path noheading:1 url:1 text:" },
196 { "panel id:dlg.upload.file icon:0x1f4c1", 0, 0, (const void *) fileItems },
197 { "heading text:${heading.upload.id}" }, 197 { "heading text:${heading.upload.id}" },
198 { "dropdown id:upload.id icon:0x1f464 text:", 0, 0, constData_Array(makeIdentityItems_UploadWidget_(d)) }, 198 { "dropdown id:upload.id icon:0x1f464 text:", 0, 0, constData_Array(makeIdentityItems_UploadWidget_(d)) },
199 { "input id:upload.token hint:hint.upload.token.long icon:0x1f516 text:" }, 199 { "input id:upload.token hint:hint.upload.token.long icon:0x1f516 text:" },
200 { "padding" },
201 { "panel id:dlg.upload.text icon:0x1f5b9 noscroll:1", 0, 0, (const void *) textItems },
202 { "panel id:dlg.upload.file icon:0x1f4c1", 0, 0, (const void *) fileItems },
200 { NULL } 203 { NULL }
201 }, actions, iElemCount(actions)); 204 }, actions, iElemCount(actions));
202 d->info = findChild_Widget(w, "upload.info"); 205 d->info = findChild_Widget(w, "upload.info");
206 d->path = findChild_Widget(w, "upload.path");
203 d->input = findChild_Widget(w, "upload.text"); 207 d->input = findChild_Widget(w, "upload.text");
204 d->filePathLabel = findChild_Widget(w, "upload.filepathlabel"); 208 d->filePathLabel = findChild_Widget(w, "upload.filepathlabel");
205 d->fileSizeLabel = findChild_Widget(w, "upload.filesizelabel"); 209 d->fileSizeLabel = findChild_Widget(w, "upload.filesizelabel");
@@ -360,7 +364,10 @@ static void setUrlPort_UploadWidget_(iUploadWidget *d, const iString *url, uint1
360 appendRange_String(&d->url, (iRangecc){ parts.scheme.end, parts.host.end }); 364 appendRange_String(&d->url, (iRangecc){ parts.scheme.end, parts.host.end });
361 appendFormat_String(&d->url, ":%u", overridePort ? overridePort : titanPortForUrl_(url)); 365 appendFormat_String(&d->url, ":%u", overridePort ? overridePort : titanPortForUrl_(url));
362 appendRange_String(&d->url, (iRangecc){ parts.path.start, constEnd_String(url) }); 366 appendRange_String(&d->url, (iRangecc){ parts.path.start, constEnd_String(url) });
363 setText_LabelWidget(d->info, &d->url); 367 const iRangecc siteRoot = urlRoot_String(&d->url);
368 setTextCStr_LabelWidget(d->info, cstr_Rangecc((iRangecc){ constBegin_String(&d->url), siteRoot.end }));
369 /* From root onwards, the URL is editable. */
370 setTextCStr_InputWidget(d->path, cstr_Rangecc((iRangecc){ siteRoot.end, constEnd_String(&d->url) }));
364 arrange_Widget(as_Widget(d)); 371 arrange_Widget(as_Widget(d));
365} 372}
366 373
@@ -417,6 +424,18 @@ static void showOrHideUploadButton_UploadWidget_(iUploadWidget *d) {
417 } 424 }
418} 425}
419 426
427static const iString *requestUrl_UploadWidget_(const iUploadWidget *d) {
428 const iRangecc siteRoot = urlRoot_String(&d->url);
429 iString *reqUrl = collectNew_String();
430 setRange_String(reqUrl, (iRangecc){ constBegin_String(&d->url), siteRoot.end });
431 const iString *path = text_InputWidget(d->path);
432 if (!startsWith_String(path, "/")) {
433 appendCStr_String(reqUrl, "/");
434 }
435 append_String(reqUrl, path);
436 return reqUrl;
437}
438
420static iBool processEvent_UploadWidget_(iUploadWidget *d, const SDL_Event *ev) { 439static iBool processEvent_UploadWidget_(iUploadWidget *d, const SDL_Event *ev) {
421 iWidget *w = as_Widget(d); 440 iWidget *w = as_Widget(d);
422 const char *cmd = command_UserEvent(ev); 441 const char *cmd = command_UserEvent(ev);
@@ -503,11 +522,10 @@ static iBool processEvent_UploadWidget_(iUploadWidget *d, const SDL_Event *ev) {
503 setFocus_Widget(as_Widget(d->input)); 522 setFocus_Widget(as_Widget(d->input));
504 } 523 }
505 else { 524 else {
506 iWidget *confirm = makeMenu_Widget(root_Widget(w), (iMenuItem[]){ 525 openMenu_Widget(makeMenu_Widget(root_Widget(w), (iMenuItem[]){
507 { delete_Icon " " uiTextCaution_ColorEscape "${menu.upload.delete.confirm}", 0, 0, 526 { delete_Icon " " uiTextCaution_ColorEscape "${menu.upload.delete.confirm}", 0, 0,
508 "upload.text.delete confirmed:1" } 527 "upload.text.delete confirmed:1" }
509 }, 1); 528 }, 1), zero_I2());
510 openMenu_Widget(confirm, zero_I2());
511 } 529 }
512 return iTrue; 530 return iTrue;
513 } 531 }
@@ -537,7 +555,7 @@ static iBool processEvent_UploadWidget_(iUploadWidget *d, const SDL_Event *ev) {
537 d->request = new_GmRequest(certs_App()); 555 d->request = new_GmRequest(certs_App());
538 setSendProgressFunc_GmRequest(d->request, updateProgress_UploadWidget_); 556 setSendProgressFunc_GmRequest(d->request, updateProgress_UploadWidget_);
539 setUserData_Object(d->request, d); 557 setUserData_Object(d->request, d);
540 setUrl_GmRequest(d->request, &d->url); 558 setUrl_GmRequest(d->request, requestUrl_UploadWidget_(d));
541 const iString *site = collectNewRange_String(urlRoot_String(&d->url)); 559 const iString *site = collectNewRange_String(urlRoot_String(&d->url));
542 switch (d->idMode) { 560 switch (d->idMode) {
543 case none_UploadIdentity: 561 case none_UploadIdentity: