summaryrefslogtreecommitdiff
path: root/src/ui/documentwidget.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/documentwidget.c')
-rw-r--r--src/ui/documentwidget.c63
1 files changed, 54 insertions, 9 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c
index 8072a025..0c4dee89 100644
--- a/src/ui/documentwidget.c
+++ b/src/ui/documentwidget.c
@@ -48,6 +48,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
48#include "scrollwidget.h" 48#include "scrollwidget.h"
49#include "touch.h" 49#include "touch.h"
50#include "translation.h" 50#include "translation.h"
51#include "uploadwidget.h"
51#include "util.h" 52#include "util.h"
52#include "visbuf.h" 53#include "visbuf.h"
53#include "visited.h" 54#include "visited.h"
@@ -2426,6 +2427,24 @@ static iBool handleSwipe_DocumentWidget_(iDocumentWidget *d, const char *cmd) {
2426 return iFalse; 2427 return iFalse;
2427} 2428}
2428 2429
2430static iBool cancelRequest_DocumentWidget_(iDocumentWidget *d, iBool postBack) {
2431 if (d->request) {
2432 iWidget *w = as_Widget(d);
2433 postCommandf_Root(w->root,
2434 "document.request.cancelled doc:%p url:%s", d, cstr_String(d->mod.url));
2435 iReleasePtr(&d->request);
2436 if (d->state != ready_RequestState) {
2437 d->state = ready_RequestState;
2438 if (postBack) {
2439 postCommand_Root(w->root, "navigate.back");
2440 }
2441 }
2442 updateFetchProgress_DocumentWidget_(d);
2443 return iTrue;
2444 }
2445 return iFalse;
2446}
2447
2429static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd) { 2448static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd) {
2430 iWidget *w = as_Widget(d); 2449 iWidget *w = as_Widget(d);
2431 if (equal_Command(cmd, "document.openurls.changed")) { 2450 if (equal_Command(cmd, "document.openurls.changed")) {
@@ -2792,6 +2811,18 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd)
2792 } 2811 }
2793 return wasHandled; 2812 return wasHandled;
2794 } 2813 }
2814 else if (equal_Command(cmd, "document.upload") && d == document_App()) {
2815 if (equalCase_Rangecc(urlScheme_String(d->mod.url), "gemini") ||
2816 equalCase_Rangecc(urlScheme_String(d->mod.url), "titan")) {
2817 iUploadWidget *upload = new_UploadWidget();
2818 setUrl_UploadWidget(upload, d->mod.url);
2819 setResponseViewer_UploadWidget(upload, d);
2820 addChild_Widget(get_Root()->widget, iClob(upload));
2821 finalizeSheet_Mobile(as_Widget(upload));
2822 postRefresh_App();
2823 }
2824 return iTrue;
2825 }
2795 else if (equal_Command(cmd, "media.updated") || equal_Command(cmd, "media.finished")) { 2826 else if (equal_Command(cmd, "media.updated") || equal_Command(cmd, "media.finished")) {
2796 return handleMediaCommand_DocumentWidget_(d, cmd); 2827 return handleMediaCommand_DocumentWidget_(d, cmd);
2797 } 2828 }
@@ -2812,15 +2843,7 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd)
2812 return iFalse; 2843 return iFalse;
2813 } 2844 }
2814 else if (equal_Command(cmd, "document.stop") && document_App() == d) { 2845 else if (equal_Command(cmd, "document.stop") && document_App() == d) {
2815 if (d->request) { 2846 if (cancelRequest_DocumentWidget_(d, iTrue /* navigate back */)) {
2816 postCommandf_Root(w->root,
2817 "document.request.cancelled doc:%p url:%s", d, cstr_String(d->mod.url));
2818 iReleasePtr(&d->request);
2819 if (d->state != ready_RequestState) {
2820 d->state = ready_RequestState;
2821 postCommand_Root(w->root, "navigate.back");
2822 }
2823 updateFetchProgress_DocumentWidget_(d);
2824 return iTrue; 2847 return iTrue;
2825 } 2848 }
2826 } 2849 }
@@ -3613,6 +3636,7 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e
3613 { "---", 0, 0, NULL }, 3636 { "---", 0, 0, NULL },
3614 { book_Icon " ${menu.page.import}", 0, 0, "bookmark.links confirm:1" }, 3637 { book_Icon " ${menu.page.import}", 0, 0, "bookmark.links confirm:1" },
3615 { globe_Icon " ${menu.page.translate}", 0, 0, "document.translate" }, 3638 { globe_Icon " ${menu.page.translate}", 0, 0, "document.translate" },
3639 { upload_Icon " ${menu.page.upload}", 0, 0, "document.upload" },
3616 { "---", 0, 0, NULL }, 3640 { "---", 0, 0, NULL },
3617 { "${menu.page.copyurl}", 0, 0, "document.copylink" } }, 3641 { "${menu.page.copyurl}", 0, 0, "document.copylink" } },
3618 15); 3642 15);
@@ -3642,6 +3666,11 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e
3642 } 3666 }
3643 d->menu = makeMenu_Widget(w, data_Array(&items), size_Array(&items)); 3667 d->menu = makeMenu_Widget(w, data_Array(&items), size_Array(&items));
3644 deinit_Array(&items); 3668 deinit_Array(&items);
3669 setMenuItemDisabled_Widget(
3670 d->menu,
3671 "document.upload",
3672 !equalCase_Rangecc(urlScheme_String(d->mod.url), "gemini") &&
3673 !equalCase_Rangecc(urlScheme_String(d->mod.url), "titan"));
3645 } 3674 }
3646 processContextMenuEvent_Widget(d->menu, ev, {}); 3675 processContextMenuEvent_Widget(d->menu, ev, {});
3647 } 3676 }
@@ -5004,6 +5033,22 @@ iBool isRequestOngoing_DocumentWidget(const iDocumentWidget *d) {
5004 return d->request != NULL; 5033 return d->request != NULL;
5005} 5034}
5006 5035
5036void takeRequest_DocumentWidget(iDocumentWidget *d, iGmRequest *finishedRequest) {
5037 cancelRequest_DocumentWidget_(d, iFalse /* don't post anything */);
5038 const iString *url = url_GmRequest(finishedRequest);
5039
5040 add_History(d->mod.history, url);
5041 setUrl_DocumentWidget_(d, url);
5042 d->state = fetching_RequestState;
5043 iAssert(d->request == NULL);
5044 d->request = finishedRequest;
5045 postCommand_Widget(d,
5046 "document.request.finished doc:%p reqid:%u request:%p",
5047 d,
5048 id_GmRequest(d->request),
5049 d->request);
5050}
5051
5007void updateSize_DocumentWidget(iDocumentWidget *d) { 5052void updateSize_DocumentWidget(iDocumentWidget *d) {
5008 updateDocumentWidthRetainingScrollPosition_DocumentWidget_(d, iFalse); 5053 updateDocumentWidthRetainingScrollPosition_DocumentWidget_(d, iFalse);
5009 resetWideRuns_DocumentWidget_(d); 5054 resetWideRuns_DocumentWidget_(d);