diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-02-23 11:46:18 +0200 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-02-23 11:46:18 +0200 |
commit | 64b9cea544ecb2c0ae95afae5e84543ac6117f62 (patch) | |
tree | dbe2f0e2a462a14449c3053fdc30ccaf701782e7 | |
parent | 5d8bfceb00d5d6b358b358b76c5828344c179e5d (diff) |
Improved handling of bookmark icons
The effect of a bookmark icon is restricted to URLs that begin with the bookmarked URL.
TODO: Bookmark icon of an URL should affect the whole domain, but this should take into consideration user subdirectories ("~name" or "/users/name").
IssueID #140
-rw-r--r-- | src/bookmarks.c | 9 | ||||
-rw-r--r-- | src/bookmarks.h | 2 | ||||
-rw-r--r-- | src/gmdocument.c | 13 |
3 files changed, 18 insertions, 6 deletions
diff --git a/src/bookmarks.c b/src/bookmarks.c index 7560a24c..60048d36 100644 --- a/src/bookmarks.c +++ b/src/bookmarks.c | |||
@@ -250,8 +250,12 @@ iBool updateBookmarkIcon_Bookmarks(iBookmarks *d, const iString *url, iChar icon | |||
250 | return changed; | 250 | return changed; |
251 | } | 251 | } |
252 | 252 | ||
253 | iChar siteIcon_Bookmarks(const iBookmarks *d, iRangecc hostName) { | 253 | iChar siteIcon_Bookmarks(const iBookmarks *d, const iString *url) { |
254 | if (isEmpty_String(url)) { | ||
255 | return 0; | ||
256 | } | ||
254 | iChar icon = 0; | 257 | iChar icon = 0; |
258 | iRangecc hostName = urlHost_String(url); | ||
255 | const size_t hostSize = size_Range(&hostName); | 259 | const size_t hostSize = size_Range(&hostName); |
256 | size_t matchingSize = iInvalidSize; /* we'll pick the shortest matching */ | 260 | size_t matchingSize = iInvalidSize; /* we'll pick the shortest matching */ |
257 | lock_Mutex(d->mtx); | 261 | lock_Mutex(d->mtx); |
@@ -265,6 +269,9 @@ iChar siteIcon_Bookmarks(const iBookmarks *d, iRangecc hostName) { | |||
265 | if (size_Range(&hostName) == size_Range(&parts.host) && | 269 | if (size_Range(&hostName) == size_Range(&parts.host) && |
266 | iCmpStrNCase(hostName.start, parts.host.start, hostSize) == 0) { | 270 | iCmpStrNCase(hostName.start, parts.host.start, hostSize) == 0) { |
267 | const size_t n = size_String(&bm->url); | 271 | const size_t n = size_String(&bm->url); |
272 | if (n > size_String(url)) { | ||
273 | continue; /* Bookmark must be higher up in the path tree. */ | ||
274 | } | ||
268 | if (n < matchingSize && bm->icon) { | 275 | if (n < matchingSize && bm->icon) { |
269 | matchingSize = n; | 276 | matchingSize = n; |
270 | icon = bm->icon; | 277 | icon = bm->icon; |
diff --git a/src/bookmarks.h b/src/bookmarks.h index 555ff58b..ab9c683b 100644 --- a/src/bookmarks.h +++ b/src/bookmarks.h | |||
@@ -62,7 +62,7 @@ iBookmark * get_Bookmarks (iBookmarks *, uint32_t id); | |||
62 | void fetchRemote_Bookmarks (iBookmarks *); | 62 | void fetchRemote_Bookmarks (iBookmarks *); |
63 | void requestFinished_Bookmarks (iBookmarks *, iGmRequest *req); | 63 | void requestFinished_Bookmarks (iBookmarks *, iGmRequest *req); |
64 | iBool updateBookmarkIcon_Bookmarks(iBookmarks *, const iString *url, iChar icon); | 64 | iBool updateBookmarkIcon_Bookmarks(iBookmarks *, const iString *url, iChar icon); |
65 | iChar siteIcon_Bookmarks (const iBookmarks *, iRangecc hostName); | 65 | iChar siteIcon_Bookmarks (const iBookmarks *, const iString *url); |
66 | 66 | ||
67 | void save_Bookmarks (const iBookmarks *, const char *dirPath); | 67 | void save_Bookmarks (const iBookmarks *, const char *dirPath); |
68 | uint32_t findUrl_Bookmarks (const iBookmarks *, const iString *url); /* O(n) */ | 68 | uint32_t findUrl_Bookmarks (const iBookmarks *, const iString *url); /* O(n) */ |
diff --git a/src/gmdocument.c b/src/gmdocument.c index 3298fecc..ff088ef7 100644 --- a/src/gmdocument.c +++ b/src/gmdocument.c | |||
@@ -720,6 +720,13 @@ static void setDerivedThemeColors_(enum iGmDocumentTheme theme) { | |||
720 | } | 720 | } |
721 | } | 721 | } |
722 | 722 | ||
723 | static void updateIconBasedOnUrl_GmDocument_(iGmDocument *d) { | ||
724 | const iChar userIcon = siteIcon_Bookmarks(bookmarks_App(), &d->url); | ||
725 | if (userIcon) { | ||
726 | d->siteIcon = userIcon; | ||
727 | } | ||
728 | } | ||
729 | |||
723 | void setThemeSeed_GmDocument(iGmDocument *d, const iBlock *seed) { | 730 | void setThemeSeed_GmDocument(iGmDocument *d, const iBlock *seed) { |
724 | const iPrefs * prefs = prefs_App(); | 731 | const iPrefs * prefs = prefs_App(); |
725 | enum iGmDocumentTheme theme = | 732 | enum iGmDocumentTheme theme = |
@@ -1092,10 +1099,7 @@ void setThemeSeed_GmDocument(iGmDocument *d, const iBlock *seed) { | |||
1092 | if (equal_CStr(cstr_Block(seed), "gemini.circumlunar.space")) { | 1099 | if (equal_CStr(cstr_Block(seed), "gemini.circumlunar.space")) { |
1093 | d->siteIcon = 0x264a; /* gemini symbol */ | 1100 | d->siteIcon = 0x264a; /* gemini symbol */ |
1094 | } | 1101 | } |
1095 | const iChar userIcon = siteIcon_Bookmarks(bookmarks_App(), urlHost_String(&d->url)); | 1102 | updateIconBasedOnUrl_GmDocument_(d); |
1096 | if (userIcon) { | ||
1097 | d->siteIcon = userIcon; | ||
1098 | } | ||
1099 | } | 1103 | } |
1100 | #if 0 | 1104 | #if 0 |
1101 | for (int i = tmFirst_ColorId; i < max_ColorId; ++i) { | 1105 | for (int i = tmFirst_ColorId; i < max_ColorId; ++i) { |
@@ -1197,6 +1201,7 @@ void setUrl_GmDocument(iGmDocument *d, const iString *url) { | |||
1197 | iUrl parts; | 1201 | iUrl parts; |
1198 | init_Url(&parts, url); | 1202 | init_Url(&parts, url); |
1199 | setRange_String(&d->localHost, parts.host); | 1203 | setRange_String(&d->localHost, parts.host); |
1204 | updateIconBasedOnUrl_GmDocument_(d); | ||
1200 | } | 1205 | } |
1201 | 1206 | ||
1202 | void setSource_GmDocument(iGmDocument *d, const iString *source, int width) { | 1207 | void setSource_GmDocument(iGmDocument *d, const iString *source, int width) { |