From f79e6735864a16c20d0ed0cc9d79c8c20aeb4816 Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Tue, 23 Feb 2021 06:10:40 +0200 Subject: Editing bookmark icons IssueID #140 --- src/bookmarks.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/bookmarks.c') diff --git a/src/bookmarks.c b/src/bookmarks.c index da53b645..5815f447 100644 --- a/src/bookmarks.c +++ b/src/bookmarks.c @@ -248,6 +248,31 @@ iBool updateBookmarkIcon_Bookmarks(iBookmarks *d, const iString *url, iChar icon return changed; } +iChar siteIcon_Bookmarks(const iBookmarks *d, iRangecc hostName) { + iChar icon = 0; + const size_t hostSize = size_Range(&hostName); + size_t matchingSize = iInvalidSize; /* we'll pick the shortest matching */ + lock_Mutex(d->mtx); + iConstForEach(Hash, i, &d->bookmarks) { + const iBookmark *bm = (const iBookmark *) i.value; + iUrl parts; + init_Url(&parts, &bm->url); + if (!hasTag_Bookmark(bm, "usericon")) { /* TODO: Inefficient! RegExp rebuilt every time. */ + continue; + } + if (size_Range(&hostName) == size_Range(&parts.host) && + iCmpStrNCase(hostName.start, parts.host.start, hostSize) == 0) { + const size_t n = size_String(&bm->url); + if (n < matchingSize && bm->icon) { + matchingSize = n; + icon = bm->icon; + } + } + } + unlock_Mutex(d->mtx); + return icon; +} + iBookmark *get_Bookmarks(iBookmarks *d, uint32_t id) { return (iBookmark *) value_Hash(&d->bookmarks, id); } -- cgit v1.2.3