summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/app.c4
-rw-r--r--src/ui/documentwidget.c61
2 files changed, 61 insertions, 4 deletions
diff --git a/src/app.c b/src/app.c
index c33664f9..3cc587e9 100644
--- a/src/app.c
+++ b/src/app.c
@@ -413,6 +413,10 @@ const iString *dataDir_App(void) {
413 return collect_String(cleanedCStr_Path(dataDir_App_)); 413 return collect_String(cleanedCStr_Path(dataDir_App_));
414} 414}
415 415
416const iString *downloadDir_App(void) {
417 return collect_String(cleaned_Path(&app_.downloadDir));
418}
419
416const iString *debugInfo_App(void) { 420const iString *debugInfo_App(void) {
417 iApp *d = &app_; 421 iApp *d = &app_;
418 iString *msg = collectNew_String(); 422 iString *msg = collectNew_String();
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c
index 0233eb1e..73d2676b 100644
--- a/src/ui/documentwidget.c
+++ b/src/ui/documentwidget.c
@@ -46,6 +46,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
46#include <SDL_timer.h> 46#include <SDL_timer.h>
47#include <SDL_render.h> 47#include <SDL_render.h>
48#include <ctype.h> 48#include <ctype.h>
49#include <errno.h>
49 50
50iDeclareClass(MediaRequest) 51iDeclareClass(MediaRequest)
51 52
@@ -147,7 +148,8 @@ struct Impl_DocumentWidget {
147 iGmRequest * request; 148 iGmRequest * request;
148 iAtomicInt isRequestUpdated; /* request has new content, need to parse it */ 149 iAtomicInt isRequestUpdated; /* request has new content, need to parse it */
149 iObjectList * media; 150 iObjectList * media;
150 iGmDocument * doc; 151 iBlock sourceContent; /* original content as received, for saving */
152 iGmDocument * doc;
151 int certFlags; 153 int certFlags;
152 iDate certExpiry; 154 iDate certExpiry;
153 iString * certSubject; 155 iString * certSubject;
@@ -208,6 +210,7 @@ void init_DocumentWidget(iDocumentWidget *d) {
208 d->showLinkNumbers = iFalse; 210 d->showLinkNumbers = iFalse;
209 d->visBuf = new_VisBuf(); 211 d->visBuf = new_VisBuf();
210 d->invalidRuns = new_PtrSet(); 212 d->invalidRuns = new_PtrSet();
213 init_Block(&d->sourceContent, 0);
211 init_PtrArray(&d->visibleLinks); 214 init_PtrArray(&d->visibleLinks);
212 init_Click(&d->click, d, SDL_BUTTON_LEFT); 215 init_Click(&d->click, d, SDL_BUTTON_LEFT);
213 addChild_Widget(w, iClob(d->scroll = new_ScrollWidget())); 216 addChild_Widget(w, iClob(d->scroll = new_ScrollWidget()));
@@ -225,6 +228,7 @@ void deinit_DocumentWidget(iDocumentWidget *d) {
225 delete_PtrSet(d->invalidRuns); 228 delete_PtrSet(d->invalidRuns);
226 iRelease(d->media); 229 iRelease(d->media);
227 iRelease(d->request); 230 iRelease(d->request);
231 deinit_Block(&d->sourceContent);
228 iRelease(d->doc); 232 iRelease(d->doc);
229 deinit_PtrArray(&d->visibleLinks); 233 deinit_PtrArray(&d->visibleLinks);
230 delete_String(d->certSubject); 234 delete_String(d->certSubject);
@@ -555,6 +559,7 @@ static void updateDocument_DocumentWidget_(iDocumentWidget *d, const iGmResponse
555 iString str; 559 iString str;
556 invalidate_DocumentWidget_(d); 560 invalidate_DocumentWidget_(d);
557 updateTheme_DocumentWidget_(d); 561 updateTheme_DocumentWidget_(d);
562 set_Block(&d->sourceContent, &response->body);
558 initBlock_String(&str, &response->body); 563 initBlock_String(&str, &response->body);
559 if (category_GmStatusCode(statusCode) == categorySuccess_GmStatusCode) { 564 if (category_GmStatusCode(statusCode) == categorySuccess_GmStatusCode) {
560 /* Check the MIME type. */ 565 /* Check the MIME type. */
@@ -583,9 +588,9 @@ static void updateDocument_DocumentWidget_(iDocumentWidget *d, const iGmResponse
583 imageTitle = 588 imageTitle =
584 baseName_Path(collect_String(newRange_String(parts.path))).start; 589 baseName_Path(collect_String(newRange_String(parts.path))).start;
585 } 590 }
586 format_String( 591 format_String(&str, "=> %s %s\n", cstr_String(d->mod.url), imageTitle);
587 &str, "=> %s %s\n", cstr_String(d->mod.url), imageTitle); 592 setImage_GmDocument(
588 setImage_GmDocument(d->doc, 1, mimeStr, &response->body, iFalse /* it's fixed */); 593 d->doc, 1, mimeStr, &response->body, iFalse /* it's fixed */);
589 } 594 }
590 else { 595 else {
591 clear_String(&str); 596 clear_String(&str);
@@ -851,6 +856,7 @@ static void checkResponse_DocumentWidget_(iDocumentWidget *d) {
851 case categorySuccess_GmStatusCode: 856 case categorySuccess_GmStatusCode:
852 d->scrollY = 0; 857 d->scrollY = 0;
853 resetSmoothScroll_DocumentWidget_(d); 858 resetSmoothScroll_DocumentWidget_(d);
859 clear_Block(&d->sourceContent);
854 reset_GmDocument(d->doc); /* new content incoming */ 860 reset_GmDocument(d->doc); /* new content incoming */
855 updateDocument_DocumentWidget_(d, response_GmRequest(d->request)); 861 updateDocument_DocumentWidget_(d, response_GmRequest(d->request));
856 break; 862 break;
@@ -1186,6 +1192,53 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd)
1186 } 1192 }
1187 } 1193 }
1188 else if (equal_Command(cmd, "document.save") && document_App() == d) { 1194 else if (equal_Command(cmd, "document.save") && document_App() == d) {
1195 if (d->request) {
1196 makeMessage_Widget(uiTextCaution_ColorEscape "PAGE INCOMPLETE",
1197 "The page contents are still being downloaded.");
1198 }
1199 else if (!isEmpty_Block(&d->sourceContent)) {
1200 /* Figure out a file name from the URL. */
1201 /* TODO: Make this a utility function. */
1202#if 0
1203 iUrl parts;
1204 init_Url(&parts, d->mod.url);
1205 if (endsWith_Rangecc(parts.path, "/")) {
1206 parts.path.end--;
1207 }
1208 iString *name = collectNew_String();
1209 if (isEmpty_Range(&parts.path)) {
1210 if (isEmpty_String(name)) {
1211 setCStr_String(name, "pagecontent");
1212 }
1213 else {
1214 setRange_String(name, parts.host);
1215 }
1216 }
1217 else {
1218
1219 size_t slashPos = lastIndexOfCStr_Rangecc(parts.path, "/");
1220 if (slashPos == size_Range(&parts.path) - 1) {
1221 slashPos = lastIndexOfCStr_Rangecc(parts.path - 1, "/");
1222 }
1223 }
1224 }
1225 iAssert(!isEmpty_Range(&name));
1226 /* Write the file. */ {
1227 iFile *f =
1228 new_File(collect_String(concat_Path(downloadDir_App(), string_Rangecc(name))));
1229 if (open_File(f, writeOnly_FileMode)) {
1230 write_File(f, &d->sourceContent);
1231 makeMessage_Widget(uiHeading_ColorEscape "PAGE SAVED",
1232 cstr_String(path_File(f)));
1233 }
1234 else {
1235 makeMessage_Widget(uiTextCaution_ColorEscape "ERROR SAVING PAGE",
1236 strerror(errno));
1237 }
1238 iRelease(f);
1239 }
1240#endif
1241 }
1189 return iTrue; 1242 return iTrue;
1190 } 1243 }
1191 else if (equal_Command(cmd, "document.reload") && document_App() == d) { 1244 else if (equal_Command(cmd, "document.reload") && document_App() == d) {