feat: put favicon urls in the settings when we fetch them

This commit is contained in:
Jonathan Rainville 2020-10-30 11:46:47 -04:00 committed by Iuri Matias
parent 58db0f144d
commit ea436e79c6
7 changed files with 18 additions and 15 deletions

View File

@ -27,7 +27,7 @@ QtObject:
try:
let bookmarksJSON = status_settings.getSetting[string](Setting.Bookmarks, "[]").parseJson
for bookmark in bookmarksJSON:
bookmarks.add(Bookmark(url: bookmark["url"].getStr, name: bookmark["name"].getStr, image: ""))
bookmarks.add(Bookmark(url: bookmark["url"].getStr, name: bookmark["name"].getStr))
except:
# Bad JSON. Just use the empty array
discard
@ -43,7 +43,7 @@ QtObject:
notify = bookmarksChanged
proc addBookmark*(self: BrowserView, url: string, name: string) {.slot.} =
self.bookmarks.addBookmarkItemToList(Bookmark(url: url, name: name, image: ""))
self.bookmarks.addBookmarkItemToList(Bookmark(url: url, name: name))
discard status_settings.saveSetting(Setting.Bookmarks, $(%self.bookmarks.bookmarks))
self.bookmarksChanged()

View File

@ -5,13 +5,11 @@ import sequtils as sequtils
type Bookmark* = ref object
name*: string
url*: string
image*: string
type
BookmarkRoles {.pure.} = enum
Name = UserRole + 1,
Name = UserRole + 1
Url = UserRole + 2
Image = UserRole + 3
QtObject:
type
@ -38,7 +36,6 @@ QtObject:
case column:
of "name": result = bookmark.name
of "url": result = bookmark.url
of "image": result = bookmark.image
method data(self: BookmarkList, index: QModelIndex, role: int): QVariant =
if not index.isValid:
@ -52,13 +49,11 @@ QtObject:
case bookmarkItemRole:
of BookmarkRoles.Name: result = newQVariant(bookmarkItem.name)
of BookmarkRoles.Url: result = newQVariant(bookmarkItem.url)
of BookmarkRoles.Image: result = newQVariant(bookmarkItem.image)
method roleNames(self: BookmarkList): Table[int, string] =
{
BookmarkRoles.Name.int:"name",
BookmarkRoles.Url.int:"url",
BookmarkRoles.Image.int: "image",
BookmarkRoles.Url.int:"url"
}.toTable
proc addBookmarkItemToList*(self: BookmarkList, bookmark: Bookmark) =
@ -74,7 +69,7 @@ QtObject:
proc modifyBookmarkItemFromList*(self: BookmarkList, index: int, url: string, name: string) =
let topLeft = self.createIndex(index, index, nil)
let bottomRight = self.createIndex(index, index, nil)
self.bookmarks[index] = Bookmark(url: url, name: name, image: "")
self.bookmarks[index] = Bookmark(url: url, name: name)
self.dataChanged(topLeft, bottomRight, @[BookmarkRoles.Name.int, BookmarkRoles.Url.int])
proc setNewData*(self: BookmarkList, bookmarkList: seq[Bookmark]) =

View File

@ -80,7 +80,7 @@ Rectangle {
Connections {
target: browserModel
onBookmarksChanged: {
addressBar.currentFavorite = getCurrentFavorite()
addressBar.currentFavorite = getCurrentFavorite(currentWebView.url)
}
}

View File

@ -99,9 +99,15 @@ Rectangle {
if (index === -1) {
return null
}
const currentFavicon = currentWebView.icon.toString().replace('image://favicon/', '')
if (!appSettings.bookmarkFavicons[url] || appSettings.bookmarkFavicons[url] !== currentFavicon) {
appSettings.bookmarkFavicons[url] = currentFavicon
}
return {
url: url,
name: browserModel.bookmarks.rowData(index, 'name')
name: browserModel.bookmarks.rowData(index, 'name'),
image: appSettings.bookmarkFavicons[url] || ""
}
}
@ -658,6 +664,7 @@ Rectangle {
id: bookmarkBtn
text: name
onClicked: currentWebView.url = url
source: appSettings.bookmarkFavicons[url] || ""
onRightClicked: {
favoriteMenu.url = url
favoriteMenu.x = bookmarkList.x + bookmarkBtn.x + mouse.x

View File

@ -10,5 +10,5 @@ Image {
height: 24
sourceSize: Qt.size(width, height)
// TODO find a better default favicon
source: faviconImage.currentTab && !!faviconImage.currentTab.icon.toString() ? faviconImage.currentTab.icon : "../../img/globe.svg"
source: faviconImage.currentTab && !!faviconImage.currentTab.icon.toString() ? faviconImage.currentTab.icon : "../../img/compassActive.svg"
}

View File

@ -4,7 +4,7 @@ import "../../../../shared/status"
import "../../../../imports"
Item {
property url source: "../../../img/globe.svg"
property url source
property string text
signal clicked(mouse: var)
signal rightClicked(mouse: var)
@ -15,7 +15,7 @@ Item {
SVGImage {
id: bookmarkImage
source: root.source
source: !!root.source && !!root.source.toString() ? root.source :"../../../img/compassActive.svg"
anchors.horizontalCenter: parent.horizontalCenter
width: 48
height: 48

View File

@ -112,6 +112,7 @@ ApplicationWindow {
property int fontSize: Constants.fontSizeM
// Browser settings
property var bookmarkFavicons: ({})
property bool autoLoadImages: true
property bool javaScriptEnabled: true
property bool errorPageEnabled: true