refactor: get the bookmark image from status-go instead

This commit is contained in:
Jonathan Rainville 2020-11-02 14:20:39 -05:00 committed by Iuri Matias
parent ea436e79c6
commit 724b73072f
7 changed files with 45 additions and 22 deletions

View File

@ -1,7 +1,7 @@
import NimQml, json, chronicles
import ../../status/status
import ../../status/libstatus/types as status_types
import ../../status/libstatus/settings as status_settings
import ../../status/libstatus/browser as status_browser
import ../../status/libstatus/types
import views/bookmark_list
QtObject:
@ -25,9 +25,10 @@ QtObject:
proc init*(self: BrowserView) =
var bookmarks: seq[Bookmark] = @[]
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))
let responseResult = status_browser.getBookmarks().parseJson["result"]
if responseResult.kind != JNull:
for bookmark in responseResult:
bookmarks.add(Bookmark(url: bookmark["url"].getStr, name: bookmark["name"].getStr, imageUrl: bookmark["imageUrl"].getStr))
except:
# Bad JSON. Just use the empty array
discard
@ -43,8 +44,8 @@ QtObject:
notify = bookmarksChanged
proc addBookmark*(self: BrowserView, url: string, name: string) {.slot.} =
self.bookmarks.addBookmarkItemToList(Bookmark(url: url, name: name))
discard status_settings.saveSetting(Setting.Bookmarks, $(%self.bookmarks.bookmarks))
let bookmark = status_browser.storeBookmark(url, name)
self.bookmarks.addBookmarkItemToList(bookmark)
self.bookmarksChanged()
proc removeBookmark*(self: BrowserView, url: string) {.slot.} =
@ -52,7 +53,7 @@ QtObject:
if index == -1:
return
self.bookmarks.removeBookmarkItemFromList(index)
discard status_settings.saveSetting(Setting.Bookmarks, $(%self.bookmarks.bookmarks))
status_browser.deleteBookmark(url)
self.bookmarksChanged()
proc modifyBookmark*(self: BrowserView, ogUrl: string, newUrl: string, newName: string) {.slot.} =
@ -62,5 +63,5 @@ QtObject:
self.addBookmark(newUrl, newName)
return
self.bookmarks.modifyBookmarkItemFromList(index, newUrl, newName)
discard status_settings.saveSetting(Setting.Bookmarks, $(%self.bookmarks.bookmarks))
status_browser.updateBookmark(ogUrl, newUrl, newName)
self.bookmarksChanged()

View File

@ -1,15 +1,12 @@
import NimQml, Tables, chronicles
import sequtils as sequtils
type Bookmark* = ref object
name*: string
url*: string
import ../../../status/libstatus/types
type
BookmarkRoles {.pure.} = enum
Name = UserRole + 1
Url = UserRole + 2
ImageUrl = UserRole + 3
QtObject:
type
@ -36,6 +33,7 @@ QtObject:
case column:
of "name": result = bookmark.name
of "url": result = bookmark.url
of "imageUrl": result = bookmark.imageUrl
method data(self: BookmarkList, index: QModelIndex, role: int): QVariant =
if not index.isValid:
@ -49,10 +47,12 @@ QtObject:
case bookmarkItemRole:
of BookmarkRoles.Name: result = newQVariant(bookmarkItem.name)
of BookmarkRoles.Url: result = newQVariant(bookmarkItem.url)
of BookmarkRoles.ImageUrl: result = newQVariant(bookmarkItem.imageUrl)
method roleNames(self: BookmarkList): Table[int, string] =
{
BookmarkRoles.Name.int:"name",
BookmarkRoles.ImageUrl.int:"imageUrl",
BookmarkRoles.Url.int:"url"
}.toTable

View File

@ -0,0 +1,22 @@
import core, types, utils, strutils, strformat, json, chronicles
proc storeBookmark*(url: string, name: string): Bookmark =
let payload = %* [{"url": url, "name": name}]
result = Bookmark(name: name, url: url)
try:
let resp = callPrivateRPC("browsers_storeBookmark", payload).parseJson["result"]
result.imageUrl = resp["imageUrl"].getStr
except:
discard
proc updateBookmark*(ogUrl: string, url: string, name: string) =
let payload = %* [ogUrl, {"url": url, "name": name}]
discard callPrivateRPC("browsers_updateBookmark", payload)
proc getBookmarks*(): string =
let payload = %* []
result = callPrivateRPC("browsers_getBookmarks", payload)
proc deleteBookmark*(url: string) =
let payload = %* [url]
discard callPrivateRPC("browsers_deleteBookmark", payload)

View File

@ -192,6 +192,11 @@ type PendingTransactionType* {.pure.} = enum
BuyStickerPack = "BuyStickerPack"
WalletTransfer = "WalletTransfer"
type Bookmark* = ref object
name*: string
url*: string
imageUrl*: string
type
Fleet* {.pure.} = enum
Prod = "eth.prod",

View File

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

View File

@ -99,15 +99,11 @@ 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'),
image: appSettings.bookmarkFavicons[url] || ""
image: browserModel.bookmarks.rowData(index, 'imageUrl')
}
}
@ -664,7 +660,7 @@ Rectangle {
id: bookmarkBtn
text: name
onClicked: currentWebView.url = url
source: appSettings.bookmarkFavicons[url] || ""
source: imageUrl
onRightClicked: {
favoriteMenu.url = url
favoriteMenu.x = bookmarkList.x + bookmarkBtn.x + mouse.x

View File

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