summaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/documentwidget.c74
1 files changed, 51 insertions, 23 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c
index 04257a1c..3771dd6c 100644
--- a/src/ui/documentwidget.c
+++ b/src/ui/documentwidget.c
@@ -2260,6 +2260,11 @@ static void showErrorPage_DocumentWidget_(iDocumentWidget *d, enum iGmStatusCode
2260 0, 2260 0,
2261 format_CStr("document.setmediatype mime:%s", mtype) }); 2261 format_CStr("document.setmediatype mime:%s", mtype) });
2262 } 2262 }
2263 pushBack_Array(&items,
2264 &(iMenuItem){ export_Icon " ${menu.open.external}",
2265 SDLK_RETURN,
2266 KMOD_PRIMARY,
2267 "document.save extview:1" });
2263 pushBack_Array( 2268 pushBack_Array(
2264 &items, 2269 &items,
2265 &(iMenuItem){ translateCStr_Lang(download_Icon " " saveToDownloads_Label), 2270 &(iMenuItem){ translateCStr_Lang(download_Icon " " saveToDownloads_Label),
@@ -3337,9 +3342,8 @@ static iBool fetchNextUnfetchedImage_DocumentWidget_(iDocumentWidget *d) {
3337 return iFalse; 3342 return iFalse;
3338} 3343}
3339 3344
3340static const iString *saveToDownloads_(const iString *url, const iString *mime, const iBlock *content, 3345static iBool saveToFile_(const iString *savePath, const iBlock *content, iBool showDialog) {
3341 iBool showDialog) { 3346 iBool ok = iFalse;
3342 const iString *savePath = downloadPathForUrl_App(url, mime);
3343 /* Write the file. */ { 3347 /* Write the file. */ {
3344 iFile *f = new_File(savePath); 3348 iFile *f = new_File(savePath);
3345 if (open_File(f, writeOnly_FileMode)) { 3349 if (open_File(f, writeOnly_FileMode)) {
@@ -3351,21 +3355,21 @@ static const iString *saveToDownloads_(const iString *url, const iString *mime,
3351 exportDownloadedFile_iOS(savePath); 3355 exportDownloadedFile_iOS(savePath);
3352#else 3356#else
3353 if (showDialog) { 3357 if (showDialog) {
3354 const iMenuItem items[2] = { 3358 const iMenuItem items[2] = {
3355 { "${dlg.save.opendownload}", 0, 0, 3359 { "${dlg.save.opendownload}", 0, 0,
3356 format_CStr("!open url:%s", cstrCollect_String(makeFileUrl_String(savePath))) }, 3360 format_CStr("!open url:%s", cstrCollect_String(makeFileUrl_String(savePath))) },
3357 { "${dlg.message.ok}", 0, 0, "message.ok" }, 3361 { "${dlg.message.ok}", 0, 0, "message.ok" },
3358 }; 3362 };
3359 makeMessage_Widget(uiHeading_ColorEscape "${heading.save}", 3363 makeMessage_Widget(uiHeading_ColorEscape "${heading.save}",
3360 format_CStr("%s\n${dlg.save.size} %.3f %s", 3364 format_CStr("%s\n${dlg.save.size} %.3f %s",
3361 cstr_String(path_File(f)), 3365 cstr_String(path_File(f)),
3362 isMega ? size / 1.0e6f : (size / 1.0e3f), 3366 isMega ? size / 1.0e6f : (size / 1.0e3f),
3363 isMega ? "${mb}" : "${kb}"), 3367 isMega ? "${mb}" : "${kb}"),
3364 items, 3368 items,
3365 iElemCount(items)); 3369 iElemCount(items));
3366 } 3370 }
3367#endif 3371#endif
3368 return savePath; 3372 ok = iTrue;
3369 } 3373 }
3370 else { 3374 else {
3371 makeSimpleMessage_Widget(uiTextCaution_ColorEscape "${heading.save.error}", 3375 makeSimpleMessage_Widget(uiTextCaution_ColorEscape "${heading.save.error}",
@@ -3373,7 +3377,16 @@ static const iString *saveToDownloads_(const iString *url, const iString *mime,
3373 } 3377 }
3374 iRelease(f); 3378 iRelease(f);
3375 } 3379 }
3376 return collectNew_String(); 3380 return ok;
3381}
3382
3383static const iString *saveToDownloads_(const iString *url, const iString *mime, const iBlock *content,
3384 iBool showDialog) {
3385 const iString *savePath = downloadPathForUrl_App(url, mime);
3386 if (!saveToFile_(savePath, content, showDialog)) {
3387 return collectNew_String();
3388 }
3389 return savePath;
3377} 3390}
3378 3391
3379static void addAllLinks_(void *context, const iGmRun *run) { 3392static void addAllLinks_(void *context, const iGmRun *run) {
@@ -4111,12 +4124,27 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd)
4111 "${dlg.save.incomplete}"); 4124 "${dlg.save.incomplete}");
4112 } 4125 }
4113 else if (!isEmpty_Block(&d->sourceContent)) { 4126 else if (!isEmpty_Block(&d->sourceContent)) {
4114 const iBool doOpen = argLabel_Command(cmd, "open"); 4127 if (argLabel_Command(cmd, "extview")) {
4115 const iString *savePath = saveToDownloads_(d->mod.url, &d->sourceMime, 4128 iString *tmpPath = collectNewCStr_String(tmpnam(NULL));
4116 &d->sourceContent, !doOpen); 4129 const iRangecc tmpDir = dirName_Path(tmpPath);
4117 if (!isEmpty_String(savePath) && doOpen) { 4130 set_String(
4118 postCommandf_Root( 4131 tmpPath,
4119 w->root, "!open url:%s", cstrCollect_String(makeFileUrl_String(savePath))); 4132 collect_String(concat_Path(collectNewRange_String(tmpDir),
4133 fileNameForUrl_App(d->mod.url, &d->sourceMime))));
4134 if (saveToFile_(tmpPath, &d->sourceContent, iFalse)) {
4135 /* TODO: Remember this temporary path and delete it when quitting the app. */
4136 postCommandf_Root(w->root, "!open default:1 url:%s",
4137 cstrCollect_String(makeFileUrl_String(tmpPath)));
4138 }
4139 }
4140 else {
4141 const iBool doOpen = argLabel_Command(cmd, "open");
4142 const iString *savePath = saveToDownloads_(d->mod.url, &d->sourceMime,
4143 &d->sourceContent, !doOpen);
4144 if (!isEmpty_String(savePath) && doOpen) {
4145 postCommandf_Root(
4146 w->root, "!open url:%s", cstrCollect_String(makeFileUrl_String(savePath)));
4147 }
4120 } 4148 }
4121 } 4149 }
4122 return iTrue; 4150 return iTrue;