summaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2020-09-17 20:54:05 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2020-09-17 20:54:05 +0300
commitcd88a87cbef2200e3d22f7d891124559e17e662a (patch)
tree52094f86733364b66681d7f9a6b6fb05b551edee /src/ui
parent198c289c807fff495881b05e3d03485a53487ea7 (diff)
Download progress indicator for large downloads
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/documentwidget.c24
-rw-r--r--src/ui/inputwidget.c1
-rw-r--r--src/ui/window.c24
3 files changed, 41 insertions, 8 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c
index 23f34577..76ceebcd 100644
--- a/src/ui/documentwidget.c
+++ b/src/ui/documentwidget.c
@@ -554,6 +554,20 @@ static void updateTheme_DocumentWidget_(iDocumentWidget *d) {
554 } 554 }
555} 555}
556 556
557static void updateFetchProgress_DocumentWidget_(iDocumentWidget *d) {
558 iLabelWidget *prog = findWidget_App("document.progress");
559 const size_t dlSize = d->request ? size_Block(body_GmRequest(d->request)) : 0;
560 setFlags_Widget(as_Widget(prog), hidden_WidgetFlag, dlSize < 250000);
561 if (isVisible_Widget(prog)) {
562 updateText_LabelWidget(prog,
563 collectNewFormat_String("%s%.3f MB",
564 isFinished_GmRequest(d->request)
565 ? uiHeading_ColorEscape
566 : uiTextCaution_ColorEscape,
567 dlSize / 1.0e6f));
568 }
569}
570
557static void updateDocument_DocumentWidget_(iDocumentWidget *d, const iGmResponse *response) { 571static void updateDocument_DocumentWidget_(iDocumentWidget *d, const iGmResponse *response) {
558 if (d->state == ready_RequestState) { 572 if (d->state == ready_RequestState) {
559 return; 573 return;
@@ -566,7 +580,7 @@ static void updateDocument_DocumentWidget_(iDocumentWidget *d, const iGmResponse
566 invalidate_DocumentWidget_(d); 580 invalidate_DocumentWidget_(d);
567 updateTheme_DocumentWidget_(d); 581 updateTheme_DocumentWidget_(d);
568 clear_String(&d->sourceMime); 582 clear_String(&d->sourceMime);
569 set_Block(&d->sourceContent, &response->body); 583// set_Block(&d->sourceContent, &response->body);
570 initBlock_String(&str, &response->body); 584 initBlock_String(&str, &response->body);
571 if (category_GmStatusCode(statusCode) == categorySuccess_GmStatusCode) { 585 if (category_GmStatusCode(statusCode) == categorySuccess_GmStatusCode) {
572 /* Check the MIME type. */ 586 /* Check the MIME type. */
@@ -867,7 +881,6 @@ static void checkResponse_DocumentWidget_(iDocumentWidget *d) {
867 case categorySuccess_GmStatusCode: 881 case categorySuccess_GmStatusCode:
868 d->scrollY = 0; 882 d->scrollY = 0;
869 resetSmoothScroll_DocumentWidget_(d); 883 resetSmoothScroll_DocumentWidget_(d);
870 clear_Block(&d->sourceContent);
871 reset_GmDocument(d->doc); /* new content incoming */ 884 reset_GmDocument(d->doc); /* new content incoming */
872 updateDocument_DocumentWidget_(d, response_GmRequest(d->request)); 885 updateDocument_DocumentWidget_(d, response_GmRequest(d->request));
873 break; 886 break;
@@ -1062,6 +1075,7 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd)
1062 } 1075 }
1063 else if (equal_Command(cmd, "tabs.changed")) { 1076 else if (equal_Command(cmd, "tabs.changed")) {
1064 d->showLinkNumbers = iFalse; 1077 d->showLinkNumbers = iFalse;
1078 updateFetchProgress_DocumentWidget_(d);
1065 if (cmp_String(id_Widget(w), suffixPtr_Command(cmd, "id")) == 0) { 1079 if (cmp_String(id_Widget(w), suffixPtr_Command(cmd, "id")) == 0) {
1066 /* Set palette for our document. */ 1080 /* Set palette for our document. */
1067 updateTheme_DocumentWidget_(d); 1081 updateTheme_DocumentWidget_(d);
@@ -1148,11 +1162,16 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd)
1148 } 1162 }
1149 else if (equalWidget_Command(cmd, w, "document.request.updated") && 1163 else if (equalWidget_Command(cmd, w, "document.request.updated") &&
1150 pointerLabel_Command(cmd, "request") == d->request) { 1164 pointerLabel_Command(cmd, "request") == d->request) {
1165 set_Block(&d->sourceContent, body_GmRequest(d->request));
1166 updateFetchProgress_DocumentWidget_(d);
1151 checkResponse_DocumentWidget_(d); 1167 checkResponse_DocumentWidget_(d);
1168 set_Atomic(&d->isRequestUpdated, iFalse); /* ready to be notified again */
1152 return iFalse; 1169 return iFalse;
1153 } 1170 }
1154 else if (equalWidget_Command(cmd, w, "document.request.finished") && 1171 else if (equalWidget_Command(cmd, w, "document.request.finished") &&
1155 pointerLabel_Command(cmd, "request") == d->request) { 1172 pointerLabel_Command(cmd, "request") == d->request) {
1173 set_Block(&d->sourceContent, body_GmRequest(d->request));
1174 updateFetchProgress_DocumentWidget_(d);
1156 checkResponse_DocumentWidget_(d); 1175 checkResponse_DocumentWidget_(d);
1157 resetSmoothScroll_DocumentWidget_(d); 1176 resetSmoothScroll_DocumentWidget_(d);
1158 d->scrollY = d->initNormScrollY * size_GmDocument(d->doc).y; 1177 d->scrollY = d->initNormScrollY * size_GmDocument(d->doc).y;
@@ -1185,6 +1204,7 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd)
1185 postCommandf_App("document.request.cancelled doc:%p url:%s", d, cstr_String(d->mod.url)); 1204 postCommandf_App("document.request.cancelled doc:%p url:%s", d, cstr_String(d->mod.url));
1186 iReleasePtr(&d->request); 1205 iReleasePtr(&d->request);
1187 d->state = ready_RequestState; 1206 d->state = ready_RequestState;
1207 updateFetchProgress_DocumentWidget_(d);
1188 return iTrue; 1208 return iTrue;
1189 } 1209 }
1190 } 1210 }
diff --git a/src/ui/inputwidget.c b/src/ui/inputwidget.c
index 11098c80..320f21ce 100644
--- a/src/ui/inputwidget.c
+++ b/src/ui/inputwidget.c
@@ -733,6 +733,7 @@ static void draw_InputWidget_(const iInputWidget *d) {
733 deinit_String(&cur); 733 deinit_String(&cur);
734 } 734 }
735 delete_String(text); 735 delete_String(text);
736 drawChildren_Widget(w);
736} 737}
737 738
738iBeginDefineSubclass(InputWidget, Widget) 739iBeginDefineSubclass(InputWidget, Widget)
diff --git a/src/ui/window.c b/src/ui/window.c
index fbcf42fe..5e64cf9e 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -367,12 +367,24 @@ static void setupUserInterface_Window(iWindow *d) {
367 setId_Widget(as_Widget(lock), "navbar.lock"); 367 setId_Widget(as_Widget(lock), "navbar.lock");
368 setFont_LabelWidget(lock, defaultSymbols_FontId); 368 setFont_LabelWidget(lock, defaultSymbols_FontId);
369 updateTextCStr_LabelWidget(lock, "\U0001f512"); 369 updateTextCStr_LabelWidget(lock, "\U0001f512");
370 iInputWidget *url = new_InputWidget(0); 370 /* URL input field. */ {
371 setSelectAllOnFocus_InputWidget(url, iTrue); 371 iInputWidget *url = new_InputWidget(0);
372 setId_Widget(as_Widget(url), "url"); 372 setSelectAllOnFocus_InputWidget(url, iTrue);
373 setNotifyEdits_InputWidget(url, iTrue); 373 setId_Widget(as_Widget(url), "url");
374 setTextCStr_InputWidget(url, "gemini://"); 374 setNotifyEdits_InputWidget(url, iTrue);
375 addChildFlags_Widget(navBar, iClob(url), expand_WidgetFlag); 375 setTextCStr_InputWidget(url, "gemini://");
376 addChildFlags_Widget(navBar, iClob(url), expand_WidgetFlag);
377 /* Download progress indicator is inside the input field, but hidden normally. */
378 setPadding_Widget(as_Widget(url),0, 0, gap_UI * 1, 0);
379 iLabelWidget *progress = new_LabelWidget(uiTextCaution_ColorEscape "00.000 MB", 0, 0, NULL);
380 setId_Widget(as_Widget(progress), "document.progress");
381 setAlignVisually_LabelWidget(progress, iTrue);
382 shrink_Rect(&as_Widget(progress)->rect, init_I2(0, gap_UI));
383 addChildFlags_Widget(as_Widget(url),
384 iClob(progress),
385 moveToParentRightEdge_WidgetFlag);
386 setBackgroundColor_Widget(as_Widget(progress), uiBackground_ColorId);
387 }
376 setId_Widget(addChild_Widget( 388 setId_Widget(addChild_Widget(
377 navBar, iClob(newIcon_LabelWidget(reloadCStr_, 0, 0, "navigate.reload"))), 389 navBar, iClob(newIcon_LabelWidget(reloadCStr_, 0, 0, "navigate.reload"))),
378 "reload"); 390 "reload");