diff options
Diffstat (limited to 'src/gmdocument.c')
-rw-r--r-- | src/gmdocument.c | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/src/gmdocument.c b/src/gmdocument.c index f7016ba4..bd54e6e5 100644 --- a/src/gmdocument.c +++ b/src/gmdocument.c | |||
@@ -4,6 +4,8 @@ | |||
4 | #include "ui/text.h" | 4 | #include "ui/text.h" |
5 | #include "ui/metrics.h" | 5 | #include "ui/metrics.h" |
6 | #include "ui/window.h" | 6 | #include "ui/window.h" |
7 | #include "history.h" | ||
8 | #include "app.h" | ||
7 | 9 | ||
8 | #include <the_Foundation/ptrarray.h> | 10 | #include <the_Foundation/ptrarray.h> |
9 | #include <the_Foundation/regexp.h> | 11 | #include <the_Foundation/regexp.h> |
@@ -16,11 +18,13 @@ iDeclareType(GmLink) | |||
16 | 18 | ||
17 | struct Impl_GmLink { | 19 | struct Impl_GmLink { |
18 | iString url; | 20 | iString url; |
21 | iTime when; | ||
19 | int flags; | 22 | int flags; |
20 | }; | 23 | }; |
21 | 24 | ||
22 | void init_GmLink(iGmLink *d) { | 25 | void init_GmLink(iGmLink *d) { |
23 | init_String(&d->url); | 26 | init_String(&d->url); |
27 | iZap(d->when); | ||
24 | d->flags = 0; | 28 | d->flags = 0; |
25 | } | 29 | } |
26 | 30 | ||
@@ -69,10 +73,13 @@ void deinit_GmImage(iGmImage *d) { | |||
69 | 73 | ||
70 | iDefineTypeConstructionArgs(GmImage, (const iBlock *data), data) | 74 | iDefineTypeConstructionArgs(GmImage, (const iBlock *data), data) |
71 | 75 | ||
76 | /*----------------------------------------------------------------------------------------------*/ | ||
77 | |||
72 | struct Impl_GmDocument { | 78 | struct Impl_GmDocument { |
73 | iObject object; | 79 | iObject object; |
74 | enum iGmDocumentFormat format; | 80 | enum iGmDocumentFormat format; |
75 | iString source; | 81 | iString source; |
82 | iString url; /* for resolving relative links */ | ||
76 | iString localHost; | 83 | iString localHost; |
77 | iInt2 size; | 84 | iInt2 size; |
78 | iArray layout; /* contents of source, laid out in document space */ | 85 | iArray layout; /* contents of source, laid out in document space */ |
@@ -200,6 +207,12 @@ static iRangecc addLink_GmDocument_(iGmDocument *d, iRangecc line, iGmLinkId *li | |||
200 | delete_String(path); | 207 | delete_String(path); |
201 | } | 208 | } |
202 | } | 209 | } |
210 | /* Check if visited. */ { | ||
211 | link->when = urlVisitTime_History(history_App(), &link->url); | ||
212 | if (isValid_Time(&link->when)) { | ||
213 | link->flags |= visited_GmLinkFlag; | ||
214 | } | ||
215 | } | ||
203 | pushBack_PtrArray(&d->links, link); | 216 | pushBack_PtrArray(&d->links, link); |
204 | *linkId = size_PtrArray(&d->links); /* index + 1 */ | 217 | *linkId = size_PtrArray(&d->links); /* index + 1 */ |
205 | iRangecc desc = capturedRange_RegExpMatch(&m, 2); | 218 | iRangecc desc = capturedRange_RegExpMatch(&m, 2); |
@@ -474,6 +487,7 @@ static void doLayout_GmDocument_(iGmDocument *d) { | |||
474 | void init_GmDocument(iGmDocument *d) { | 487 | void init_GmDocument(iGmDocument *d) { |
475 | d->format = gemini_GmDocumentFormat; | 488 | d->format = gemini_GmDocumentFormat; |
476 | init_String(&d->source); | 489 | init_String(&d->source); |
490 | init_String(&d->url); | ||
477 | init_String(&d->localHost); | 491 | init_String(&d->localHost); |
478 | d->size = zero_I2(); | 492 | d->size = zero_I2(); |
479 | init_Array(&d->layout, sizeof(iGmRun)); | 493 | init_Array(&d->layout, sizeof(iGmRun)); |
@@ -488,6 +502,7 @@ void deinit_GmDocument(iGmDocument *d) { | |||
488 | deinit_PtrArray(&d->links); | 502 | deinit_PtrArray(&d->links); |
489 | deinit_Array(&d->layout); | 503 | deinit_Array(&d->layout); |
490 | deinit_String(&d->localHost); | 504 | deinit_String(&d->localHost); |
505 | deinit_String(&d->url); | ||
491 | deinit_String(&d->source); | 506 | deinit_String(&d->source); |
492 | } | 507 | } |
493 | 508 | ||
@@ -499,6 +514,8 @@ void reset_GmDocument(iGmDocument *d) { | |||
499 | clear_PtrArray(&d->images); | 514 | clear_PtrArray(&d->images); |
500 | clearLinks_GmDocument_(d); | 515 | clearLinks_GmDocument_(d); |
501 | clear_Array(&d->layout); | 516 | clear_Array(&d->layout); |
517 | clear_String(&d->url); | ||
518 | clear_String(&d->localHost); | ||
502 | } | 519 | } |
503 | 520 | ||
504 | void setFormat_GmDocument(iGmDocument *d, enum iGmDocumentFormat format) { | 521 | void setFormat_GmDocument(iGmDocument *d, enum iGmDocumentFormat format) { |
@@ -570,8 +587,11 @@ static void normalize_GmDocument(iGmDocument *d) { | |||
570 | set_String(&d->source, collect_String(normalized)); | 587 | set_String(&d->source, collect_String(normalized)); |
571 | } | 588 | } |
572 | 589 | ||
573 | void setHost_GmDocument(iGmDocument *d, const iString *host) { | 590 | void setUrl_GmDocument(iGmDocument *d, const iString *url) { |
574 | set_String(&d->localHost, host); | 591 | set_String(&d->url, url); |
592 | iUrl parts; | ||
593 | init_Url(&parts, url); | ||
594 | setRange_String(&d->localHost, parts.host); | ||
575 | } | 595 | } |
576 | 596 | ||
577 | void setSource_GmDocument(iGmDocument *d, const iString *source, int width) { | 597 | void setSource_GmDocument(iGmDocument *d, const iString *source, int width) { |
@@ -698,6 +718,12 @@ int linkFlags_GmDocument(const iGmDocument *d, iGmLinkId linkId) { | |||
698 | return link ? link->flags : 0; | 718 | return link ? link->flags : 0; |
699 | } | 719 | } |
700 | 720 | ||
721 | const iTime *linkTime_GmDocument(const iGmDocument *d, iGmLinkId linkId) { | ||
722 | const iGmLink *link = link_GmDocument_(d, linkId); | ||
723 | return link ? &link->when : NULL; | ||
724 | } | ||
725 | |||
726 | |||
701 | uint16_t linkImage_GmDocument(const iGmDocument *d, iGmLinkId linkId) { | 727 | uint16_t linkImage_GmDocument(const iGmDocument *d, iGmLinkId linkId) { |
702 | size_t index = findLinkImage_GmDocument_(d, linkId); | 728 | size_t index = findLinkImage_GmDocument_(d, linkId); |
703 | if (index != iInvalidPos) { | 729 | if (index != iInvalidPos) { |