summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2020-09-18 10:35:32 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2020-09-18 10:35:32 +0300
commit24769923618c19e7c4634f6dbdcc7ed087918a9c (patch)
tree938c8598058c76e90cd9884419dd8fa63f8567c9
parentd45b2fd2da5183610aef250becd1d32dab46dcae (diff)
Improved download indicator and stop/reload button
Follow which tab is open and actually stop ongoing requests instead of restarting them.
-rw-r--r--src/ui/documentwidget.c26
-rw-r--r--src/ui/util.c20
2 files changed, 31 insertions, 15 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c
index 26fd81cf..33b419c8 100644
--- a/src/ui/documentwidget.c
+++ b/src/ui/documentwidget.c
@@ -146,7 +146,7 @@ struct Impl_DocumentWidget {
146 iObjectList * media; 146 iObjectList * media;
147 iString sourceMime; 147 iString sourceMime;
148 iBlock sourceContent; /* original content as received, for saving */ 148 iBlock sourceContent; /* original content as received, for saving */
149 iGmDocument * doc; 149 iGmDocument * doc;
150 int certFlags; 150 int certFlags;
151 iDate certExpiry; 151 iDate certExpiry;
152 iString * certSubject; 152 iString * certSubject;
@@ -782,7 +782,9 @@ void setRedirectCount_DocumentWidget(iDocumentWidget *d, int count) {
782} 782}
783 783
784iBool isRequestOngoing_DocumentWidget(const iDocumentWidget *d) { 784iBool isRequestOngoing_DocumentWidget(const iDocumentWidget *d) {
785 return d->state == fetching_RequestState || d->state == receivedPartialResponse_RequestState; 785 /*return d->state == fetching_RequestState ||
786 d->state == receivedPartialResponse_RequestState;*/
787 return d->request != NULL;
786} 788}
787 789
788static void scroll_DocumentWidget_(iDocumentWidget *d, int offset) { 790static void scroll_DocumentWidget_(iDocumentWidget *d, int offset) {
@@ -1072,12 +1074,12 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd)
1072 } 1074 }
1073 else if (equal_Command(cmd, "tabs.changed")) { 1075 else if (equal_Command(cmd, "tabs.changed")) {
1074 d->showLinkNumbers = iFalse; 1076 d->showLinkNumbers = iFalse;
1075 updateFetchProgress_DocumentWidget_(d);
1076 if (cmp_String(id_Widget(w), suffixPtr_Command(cmd, "id")) == 0) { 1077 if (cmp_String(id_Widget(w), suffixPtr_Command(cmd, "id")) == 0) {
1077 /* Set palette for our document. */ 1078 /* Set palette for our document. */
1078 updateTheme_DocumentWidget_(d); 1079 updateTheme_DocumentWidget_(d);
1079 updateTrust_DocumentWidget_(d, NULL); 1080 updateTrust_DocumentWidget_(d, NULL);
1080 updateSize_DocumentWidget(d); 1081 updateSize_DocumentWidget(d);
1082 updateFetchProgress_DocumentWidget_(d);
1081 } 1083 }
1082 updateWindowTitle_DocumentWidget_(d); 1084 updateWindowTitle_DocumentWidget_(d);
1083 allocVisBuffer_DocumentWidget_(d); 1085 allocVisBuffer_DocumentWidget_(d);
@@ -1160,7 +1162,9 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd)
1160 else if (equalWidget_Command(cmd, w, "document.request.updated") && 1162 else if (equalWidget_Command(cmd, w, "document.request.updated") &&
1161 pointerLabel_Command(cmd, "request") == d->request) { 1163 pointerLabel_Command(cmd, "request") == d->request) {
1162 set_Block(&d->sourceContent, body_GmRequest(d->request)); 1164 set_Block(&d->sourceContent, body_GmRequest(d->request));
1163 updateFetchProgress_DocumentWidget_(d); 1165 if (document_App() == d) {
1166 updateFetchProgress_DocumentWidget_(d);
1167 }
1164 checkResponse_DocumentWidget_(d); 1168 checkResponse_DocumentWidget_(d);
1165 set_Atomic(&d->isRequestUpdated, iFalse); /* ready to be notified again */ 1169 set_Atomic(&d->isRequestUpdated, iFalse); /* ready to be notified again */
1166 return iFalse; 1170 return iFalse;
@@ -1189,18 +1193,24 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd)
1189 cancel_GmRequest(d->request); 1193 cancel_GmRequest(d->request);
1190 return iFalse; 1194 return iFalse;
1191 } 1195 }
1196 /*
1192 else if (equal_Command(cmd, "document.request.cancelled") && document_Command(cmd) == d) { 1197 else if (equal_Command(cmd, "document.request.cancelled") && document_Command(cmd) == d) {
1193 postCommand_App("navigate.back"); 1198 postCommand_App("navigate.back");
1194 return iFalse; 1199 return iFalse;
1195 } 1200 }
1201 */
1196 else if (equal_Command(cmd, "media.updated") || equal_Command(cmd, "media.finished")) { 1202 else if (equal_Command(cmd, "media.updated") || equal_Command(cmd, "media.finished")) {
1197 return handleMediaCommand_DocumentWidget_(d, cmd); 1203 return handleMediaCommand_DocumentWidget_(d, cmd);
1198 } 1204 }
1199 else if (equal_Command(cmd, "document.stop") && document_App() == d) { 1205 else if (equal_Command(cmd, "document.stop") && document_App() == d) {
1200 if (d->request) { 1206 if (d->request) {
1201 postCommandf_App("document.request.cancelled doc:%p url:%s", d, cstr_String(d->mod.url)); 1207 postCommandf_App(
1208 "document.request.cancelled doc:%p url:%s", d, cstr_String(d->mod.url));
1202 iReleasePtr(&d->request); 1209 iReleasePtr(&d->request);
1203 d->state = ready_RequestState; 1210 if (d->state != ready_RequestState) {
1211 d->state = ready_RequestState;
1212 postCommand_App("navigate.back");
1213 }
1204 updateFetchProgress_DocumentWidget_(d); 1214 updateFetchProgress_DocumentWidget_(d);
1205 return iTrue; 1215 return iTrue;
1206 } 1216 }
@@ -1554,8 +1564,10 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e
1554 'c', 1564 'c',
1555 KMOD_PRIMARY, 1565 KMOD_PRIMARY,
1556 "copy" }, 1566 "copy" },
1567 { "---", 0, 0, NULL },
1568 { "Save to Downloads", SDLK_s, KMOD_PRIMARY, "document.save" },
1557 }, 1569 },
1558 6); 1570 8);
1559 d->menu = makeMenu_Widget(w, data_Array(&items), size_Array(&items)); 1571 d->menu = makeMenu_Widget(w, data_Array(&items), size_Array(&items));
1560 deinit_Array(&items); 1572 deinit_Array(&items);
1561 } 1573 }
diff --git a/src/ui/util.c b/src/ui/util.c
index f1cab9ba..ff6f8822 100644
--- a/src/ui/util.c
+++ b/src/ui/util.c
@@ -243,6 +243,12 @@ iWidget *addAction_Widget(iWidget *parent, int key, int kmods, const char *comma
243 243
244/*-----------------------------------------------------------------------------------------------*/ 244/*-----------------------------------------------------------------------------------------------*/
245 245
246static iBool isCommandIgnoredByMenus_(const char *cmd) {
247 return equal_Command(cmd, "media.updated") || equal_Command(cmd, "document.request.updated") ||
248 equal_Command(cmd, "window.resized") ||
249 (equal_Command(cmd, "mouse.clicked") && !arg_Command(cmd)); /* button released */
250}
251
246static iBool menuHandler_(iWidget *menu, const char *cmd) { 252static iBool menuHandler_(iWidget *menu, const char *cmd) {
247 if (isVisible_Widget(menu)) { 253 if (isVisible_Widget(menu)) {
248 if (equalWidget_Command(cmd, menu, "menu.opened")) { 254 if (equalWidget_Command(cmd, menu, "menu.opened")) {
@@ -258,8 +264,7 @@ static iBool menuHandler_(iWidget *menu, const char *cmd) {
258 closeMenu_Widget(menu); 264 closeMenu_Widget(menu);
259 return iTrue; 265 return iTrue;
260 } 266 }
261 if (!equal_Command(cmd, "window.resized") && 267 if (!isCommandIgnoredByMenus_(cmd)) {
262 !(equal_Command(cmd, "mouse.clicked") && !arg_Command(cmd)) /* ignore button release */) {
263 closeMenu_Widget(menu); 268 closeMenu_Widget(menu);
264 } 269 }
265 } 270 }
@@ -734,10 +739,9 @@ void updateValueInput_Widget(iWidget *d, const char *title, const char *prompt)
734 739
735static iBool messageHandler_(iWidget *msg, const char *cmd) { 740static iBool messageHandler_(iWidget *msg, const char *cmd) {
736 /* Almost any command dismisses the sheet. */ 741 /* Almost any command dismisses the sheet. */
737// if (equal_Command(cmd, "menu.closed")) { 742 if (!(equal_Command(cmd, "media.updated") || equal_Command(cmd, "document.request.updated"))) {
738// return iFalse; 743 destroy_Widget(msg);
739// } 744 }
740 destroy_Widget(msg);
741 return iFalse; 745 return iFalse;
742} 746}
743 747
@@ -808,7 +812,7 @@ iWidget *makePreferences_Widget(void) {
808 addChild_Widget(dlg, iClob(page)); 812 addChild_Widget(dlg, iClob(page));
809 setFlags_Widget(page, arrangeHorizontal_WidgetFlag | arrangeSize_WidgetFlag, iTrue); 813 setFlags_Widget(page, arrangeHorizontal_WidgetFlag | arrangeSize_WidgetFlag, iTrue);
810 iWidget *headings = addChildFlags_Widget( 814 iWidget *headings = addChildFlags_Widget(
811 page, iClob(new_Widget()), arrangeVertical_WidgetFlag | arrangeSize_WidgetFlag); 815 page, iClob(new_Widget()), arrangeVertical_WidgetFlag | arrangeSize_WidgetFlag);
812 iWidget *values = addChildFlags_Widget( 816 iWidget *values = addChildFlags_Widget(
813 page, iClob(new_Widget()), arrangeVertical_WidgetFlag | arrangeSize_WidgetFlag); 817 page, iClob(new_Widget()), arrangeVertical_WidgetFlag | arrangeSize_WidgetFlag);
814 addChild_Widget(headings, iClob(makeHeading_Widget("Downloads folder:"))); 818 addChild_Widget(headings, iClob(makeHeading_Widget("Downloads folder:")));
@@ -817,7 +821,7 @@ iWidget *makePreferences_Widget(void) {
817 addChild_Widget(headings, iClob(makeHeading_Widget("Use system theme:"))); 821 addChild_Widget(headings, iClob(makeHeading_Widget("Use system theme:")));
818 addChild_Widget(values, iClob(makeToggle_Widget("prefs.ostheme"))); 822 addChild_Widget(values, iClob(makeToggle_Widget("prefs.ostheme")));
819#endif 823#endif
820 addChild_Widget(headings, iClob(makeHeading_Widget("Theme:"))); 824 addChild_Widget(headings, iClob(makeHeading_Widget("Theme:")));
821 iWidget *themes = new_Widget(); 825 iWidget *themes = new_Widget();
822 /* Themes. */ { 826 /* Themes. */ {
823 setId_Widget(addChild_Widget(themes, iClob(new_LabelWidget("Pure Black", 0, 0, "theme.set arg:0"))), "prefs.theme.0"); 827 setId_Widget(addChild_Widget(themes, iClob(new_LabelWidget("Pure Black", 0, 0, "theme.set arg:0"))), "prefs.theme.0");