summaryrefslogtreecommitdiff
path: root/src/gempub.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-05-02 17:36:21 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-05-02 17:36:21 +0300
commit7584277f59646fb38c80242a2503176e073be367 (patch)
tree410d5f25b1a76c277f6f437be55f00b3d0069b8c /src/gempub.c
parentd6d3cfd9c1a16172bdcb8cbe8e09e77212f7094c (diff)
DocumentWidget: Retain Gempub data; cleanup
Keep hold of the `Gempub` data while the page is open so it can be used for other purposes.
Diffstat (limited to 'src/gempub.c')
-rw-r--r--src/gempub.c29
1 files changed, 25 insertions, 4 deletions
diff --git a/src/gempub.c b/src/gempub.c
index 45a4c1b3..448349c8 100644
--- a/src/gempub.c
+++ b/src/gempub.c
@@ -24,6 +24,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
24#include "gmutil.h" 24#include "gmutil.h"
25#include "lang.h" 25#include "lang.h"
26#include "defs.h" 26#include "defs.h"
27#include "gmdocument.h"
27#include "ui/util.h" 28#include "ui/util.h"
28 29
29#include <the_Foundation/archive.h> 30#include <the_Foundation/archive.h>
@@ -162,7 +163,7 @@ static iBool isRemote_Gempub_(const iGempub *d) {
162 return !equalCase_Rangecc(urlScheme_String(&d->baseUrl), "file"); 163 return !equalCase_Rangecc(urlScheme_String(&d->baseUrl), "file");
163} 164}
164 165
165iBlock *coverPageSource_Gempub(const iGempub *d) { 166iString *coverPageSource_Gempub(const iGempub *d) {
166 iAssert(!isEmpty_String(&d->baseUrl)); 167 iAssert(!isEmpty_String(&d->baseUrl));
167 const iString *baseUrl = withSpacesEncoded_String(&d->baseUrl); 168 const iString *baseUrl = withSpacesEncoded_String(&d->baseUrl);
168 iString *out = new_String(); 169 iString *out = new_String();
@@ -204,7 +205,27 @@ iBlock *coverPageSource_Gempub(const iGempub *d) {
204 appendProperty_Gempub_(d, "Language:", language_GempubProperty, out); 205 appendProperty_Gempub_(d, "Language:", language_GempubProperty, out);
205 appendProperty_Gempub_(d, "License:", license_GempubProperty, out); 206 appendProperty_Gempub_(d, "License:", license_GempubProperty, out);
206 appendProperty_Gempub_(d, "\u00a9", copyright_GempubProperty, out); 207 appendProperty_Gempub_(d, "\u00a9", copyright_GempubProperty, out);
207 iBlock *output = copy_Block(utf8_String(out)); 208 return out;
208 delete_String(out); 209}
209 return output; 210
211iBool preloadCoverImage_Gempub(const iGempub *d, iGmDocument *doc) {
212 iBool haveImage = iFalse;
213 for (size_t linkId = 1; ; linkId++) {
214 const iString *linkUrl = linkUrl_GmDocument(doc, linkId);
215 if (!linkUrl) break;
216 if (findLinkImage_Media(media_GmDocument(doc), linkId)) {
217 continue; /* got this already */
218 }
219 if (linkFlags_GmDocument(doc, linkId) & imageFileExtension_GmLinkFlag) {
220 iString *imgEntryPath = collect_String(copy_String(linkUrl));
221 remove_Block(&imgEntryPath->chars, 0, size_String(&d->baseUrl) + 1 /* slash, too */);
222 setData_Media(media_GmDocument(doc),
223 linkId,
224 collectNewCStr_String(mediaType_Path(linkUrl)),
225 data_Archive(d->arch, imgEntryPath),
226 0);
227 haveImage = iTrue;
228 }
229 }
230 return haveImage;
210} 231}