feat: put favicon urls in the settings when we fetch them
This commit is contained in:
parent
58db0f144d
commit
ea436e79c6
|
@ -27,7 +27,7 @@ QtObject:
|
||||||
try:
|
try:
|
||||||
let bookmarksJSON = status_settings.getSetting[string](Setting.Bookmarks, "[]").parseJson
|
let bookmarksJSON = status_settings.getSetting[string](Setting.Bookmarks, "[]").parseJson
|
||||||
for bookmark in bookmarksJSON:
|
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:
|
except:
|
||||||
# Bad JSON. Just use the empty array
|
# Bad JSON. Just use the empty array
|
||||||
discard
|
discard
|
||||||
|
@ -43,7 +43,7 @@ QtObject:
|
||||||
notify = bookmarksChanged
|
notify = bookmarksChanged
|
||||||
|
|
||||||
proc addBookmark*(self: BrowserView, url: string, name: string) {.slot.} =
|
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))
|
discard status_settings.saveSetting(Setting.Bookmarks, $(%self.bookmarks.bookmarks))
|
||||||
self.bookmarksChanged()
|
self.bookmarksChanged()
|
||||||
|
|
||||||
|
|
|
@ -5,13 +5,11 @@ import sequtils as sequtils
|
||||||
type Bookmark* = ref object
|
type Bookmark* = ref object
|
||||||
name*: string
|
name*: string
|
||||||
url*: string
|
url*: string
|
||||||
image*: string
|
|
||||||
|
|
||||||
type
|
type
|
||||||
BookmarkRoles {.pure.} = enum
|
BookmarkRoles {.pure.} = enum
|
||||||
Name = UserRole + 1,
|
Name = UserRole + 1
|
||||||
Url = UserRole + 2
|
Url = UserRole + 2
|
||||||
Image = UserRole + 3
|
|
||||||
|
|
||||||
QtObject:
|
QtObject:
|
||||||
type
|
type
|
||||||
|
@ -38,7 +36,6 @@ QtObject:
|
||||||
case column:
|
case column:
|
||||||
of "name": result = bookmark.name
|
of "name": result = bookmark.name
|
||||||
of "url": result = bookmark.url
|
of "url": result = bookmark.url
|
||||||
of "image": result = bookmark.image
|
|
||||||
|
|
||||||
method data(self: BookmarkList, index: QModelIndex, role: int): QVariant =
|
method data(self: BookmarkList, index: QModelIndex, role: int): QVariant =
|
||||||
if not index.isValid:
|
if not index.isValid:
|
||||||
|
@ -52,13 +49,11 @@ QtObject:
|
||||||
case bookmarkItemRole:
|
case bookmarkItemRole:
|
||||||
of BookmarkRoles.Name: result = newQVariant(bookmarkItem.name)
|
of BookmarkRoles.Name: result = newQVariant(bookmarkItem.name)
|
||||||
of BookmarkRoles.Url: result = newQVariant(bookmarkItem.url)
|
of BookmarkRoles.Url: result = newQVariant(bookmarkItem.url)
|
||||||
of BookmarkRoles.Image: result = newQVariant(bookmarkItem.image)
|
|
||||||
|
|
||||||
method roleNames(self: BookmarkList): Table[int, string] =
|
method roleNames(self: BookmarkList): Table[int, string] =
|
||||||
{
|
{
|
||||||
BookmarkRoles.Name.int:"name",
|
BookmarkRoles.Name.int:"name",
|
||||||
BookmarkRoles.Url.int:"url",
|
BookmarkRoles.Url.int:"url"
|
||||||
BookmarkRoles.Image.int: "image",
|
|
||||||
}.toTable
|
}.toTable
|
||||||
|
|
||||||
proc addBookmarkItemToList*(self: BookmarkList, bookmark: Bookmark) =
|
proc addBookmarkItemToList*(self: BookmarkList, bookmark: Bookmark) =
|
||||||
|
@ -74,7 +69,7 @@ QtObject:
|
||||||
proc modifyBookmarkItemFromList*(self: BookmarkList, index: int, url: string, name: string) =
|
proc modifyBookmarkItemFromList*(self: BookmarkList, index: int, url: string, name: string) =
|
||||||
let topLeft = self.createIndex(index, index, nil)
|
let topLeft = self.createIndex(index, index, nil)
|
||||||
let bottomRight = 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])
|
self.dataChanged(topLeft, bottomRight, @[BookmarkRoles.Name.int, BookmarkRoles.Url.int])
|
||||||
|
|
||||||
proc setNewData*(self: BookmarkList, bookmarkList: seq[Bookmark]) =
|
proc setNewData*(self: BookmarkList, bookmarkList: seq[Bookmark]) =
|
||||||
|
|
|
@ -80,7 +80,7 @@ Rectangle {
|
||||||
Connections {
|
Connections {
|
||||||
target: browserModel
|
target: browserModel
|
||||||
onBookmarksChanged: {
|
onBookmarksChanged: {
|
||||||
addressBar.currentFavorite = getCurrentFavorite()
|
addressBar.currentFavorite = getCurrentFavorite(currentWebView.url)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -99,9 +99,15 @@ Rectangle {
|
||||||
if (index === -1) {
|
if (index === -1) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
const currentFavicon = currentWebView.icon.toString().replace('image://favicon/', '')
|
||||||
|
if (!appSettings.bookmarkFavicons[url] || appSettings.bookmarkFavicons[url] !== currentFavicon) {
|
||||||
|
appSettings.bookmarkFavicons[url] = currentFavicon
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
url: url,
|
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
|
id: bookmarkBtn
|
||||||
text: name
|
text: name
|
||||||
onClicked: currentWebView.url = url
|
onClicked: currentWebView.url = url
|
||||||
|
source: appSettings.bookmarkFavicons[url] || ""
|
||||||
onRightClicked: {
|
onRightClicked: {
|
||||||
favoriteMenu.url = url
|
favoriteMenu.url = url
|
||||||
favoriteMenu.x = bookmarkList.x + bookmarkBtn.x + mouse.x
|
favoriteMenu.x = bookmarkList.x + bookmarkBtn.x + mouse.x
|
||||||
|
|
|
@ -10,5 +10,5 @@ Image {
|
||||||
height: 24
|
height: 24
|
||||||
sourceSize: Qt.size(width, height)
|
sourceSize: Qt.size(width, height)
|
||||||
// TODO find a better default favicon
|
// 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"
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import "../../../../shared/status"
|
||||||
import "../../../../imports"
|
import "../../../../imports"
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
property url source: "../../../img/globe.svg"
|
property url source
|
||||||
property string text
|
property string text
|
||||||
signal clicked(mouse: var)
|
signal clicked(mouse: var)
|
||||||
signal rightClicked(mouse: var)
|
signal rightClicked(mouse: var)
|
||||||
|
@ -15,7 +15,7 @@ Item {
|
||||||
|
|
||||||
SVGImage {
|
SVGImage {
|
||||||
id: bookmarkImage
|
id: bookmarkImage
|
||||||
source: root.source
|
source: !!root.source && !!root.source.toString() ? root.source :"../../../img/compassActive.svg"
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
width: 48
|
width: 48
|
||||||
height: 48
|
height: 48
|
||||||
|
|
|
@ -112,6 +112,7 @@ ApplicationWindow {
|
||||||
property int fontSize: Constants.fontSizeM
|
property int fontSize: Constants.fontSizeM
|
||||||
|
|
||||||
// Browser settings
|
// Browser settings
|
||||||
|
property var bookmarkFavicons: ({})
|
||||||
property bool autoLoadImages: true
|
property bool autoLoadImages: true
|
||||||
property bool javaScriptEnabled: true
|
property bool javaScriptEnabled: true
|
||||||
property bool errorPageEnabled: true
|
property bool errorPageEnabled: true
|
||||||
|
|
Loading…
Reference in New Issue