feat: save and get appearance from the settings
This commit is contained in:
parent
881f6dbe80
commit
0f9a79e214
|
@ -1,4 +1,5 @@
|
||||||
import NimQml, json, eventemitter, strutils
|
import NimQml, json, eventemitter, strutils
|
||||||
|
import json_serialization
|
||||||
import ../../status/libstatus/mailservers as status_mailservers
|
import ../../status/libstatus/mailservers as status_mailservers
|
||||||
import ../../signals/types
|
import ../../signals/types
|
||||||
import ../../status/libstatus/types as status_types
|
import ../../status/libstatus/types as status_types
|
||||||
|
@ -8,6 +9,7 @@ import ../../status/[status, contacts]
|
||||||
import ../../status/chat as status_chat
|
import ../../status/chat as status_chat
|
||||||
import ../../status/chat/chat
|
import ../../status/chat/chat
|
||||||
import view
|
import view
|
||||||
|
import chronicles
|
||||||
|
|
||||||
type ProfileController* = ref object of SignalSubscriber
|
type ProfileController* = ref object of SignalSubscriber
|
||||||
view*: ProfileView
|
view*: ProfileView
|
||||||
|
@ -33,6 +35,8 @@ proc init*(self: ProfileController, account: Account) =
|
||||||
let response = status_settings.getSettings()
|
let response = status_settings.getSettings()
|
||||||
let pubKey = status_settings.getSetting[string]("public-key", "0x0")
|
let pubKey = status_settings.getSetting[string]("public-key", "0x0")
|
||||||
let mnemonic = status_settings.getSetting[string]("mnemonic", "")
|
let mnemonic = status_settings.getSetting[string]("mnemonic", "")
|
||||||
|
let appearance = Json.decode($response["appearance"], int)
|
||||||
|
profile.appearance = appearance
|
||||||
profile.id = pubKey
|
profile.id = pubKey
|
||||||
|
|
||||||
self.view.setNewProfile(profile)
|
self.view.setNewProfile(profile)
|
||||||
|
|
|
@ -97,3 +97,7 @@ QtObject:
|
||||||
|
|
||||||
proc qrCode*(self: ProfileView, text:string): string {.slot.} =
|
proc qrCode*(self: ProfileView, text:string): string {.slot.} =
|
||||||
result = "data:image/svg+xml;utf8," & generateQRCodeSVG(text, 2)
|
result = "data:image/svg+xml;utf8," & generateQRCodeSVG(text, 2)
|
||||||
|
|
||||||
|
proc changeTheme*(self: ProfileView, theme: int) {.slot.} =
|
||||||
|
self.profile.setAppearance(theme)
|
||||||
|
self.status.saveSetting("appearance", $theme)
|
||||||
|
|
|
@ -6,6 +6,7 @@ QtObject:
|
||||||
username*: string
|
username*: string
|
||||||
identicon*: string
|
identicon*: string
|
||||||
pubKey*: string
|
pubKey*: string
|
||||||
|
appearance*: int
|
||||||
|
|
||||||
proc setup(self: ProfileInfoView) =
|
proc setup(self: ProfileInfoView) =
|
||||||
self.QObject.setup
|
self.QObject.setup
|
||||||
|
@ -19,6 +20,7 @@ QtObject:
|
||||||
result.pubKey = ""
|
result.pubKey = ""
|
||||||
result.username = ""
|
result.username = ""
|
||||||
result.identicon = ""
|
result.identicon = ""
|
||||||
|
result.appearance = 0
|
||||||
result.setup
|
result.setup
|
||||||
|
|
||||||
proc profileChanged*(self: ProfileInfoView) {.signal.}
|
proc profileChanged*(self: ProfileInfoView) {.signal.}
|
||||||
|
@ -26,6 +28,7 @@ QtObject:
|
||||||
proc setProfile*(self: ProfileInfoView, profile: Profile) =
|
proc setProfile*(self: ProfileInfoView, profile: Profile) =
|
||||||
self.username = profile.username
|
self.username = profile.username
|
||||||
self.identicon = profile.identicon
|
self.identicon = profile.identicon
|
||||||
|
self.appearance = profile.appearance
|
||||||
self.pubKey = profile.id
|
self.pubKey = profile.id
|
||||||
self.profileChanged()
|
self.profileChanged()
|
||||||
|
|
||||||
|
@ -34,6 +37,15 @@ QtObject:
|
||||||
read = username
|
read = username
|
||||||
notify = profileChanged
|
notify = profileChanged
|
||||||
|
|
||||||
|
proc appearance*(self: ProfileInfoView): int {.slot.} = result = self.appearance
|
||||||
|
proc setAppearance*(self: ProfileInfoView, appearance: int) {.slot.} =
|
||||||
|
self.appearance = appearance
|
||||||
|
self.profileChanged()
|
||||||
|
QtProperty[int] appearance:
|
||||||
|
read = appearance
|
||||||
|
write = setAppearance
|
||||||
|
notify = profileChanged
|
||||||
|
|
||||||
proc identicon*(self: ProfileInfoView): string {.slot.} = result = self.identicon
|
proc identicon*(self: ProfileInfoView): string {.slot.} = result = self.identicon
|
||||||
QtProperty[string] identicon:
|
QtProperty[string] identicon:
|
||||||
read = identicon
|
read = identicon
|
||||||
|
|
|
@ -4,7 +4,7 @@ import ../libstatus/types
|
||||||
type Profile* = ref object
|
type Profile* = ref object
|
||||||
id*, alias*, username*, identicon*, address*, ensName*: string
|
id*, alias*, username*, identicon*, address*, ensName*: string
|
||||||
ensVerified*: bool
|
ensVerified*: bool
|
||||||
ensVerifiedAt*, ensVerificationRetries*: int
|
ensVerifiedAt*, ensVerificationRetries*, appearance*: int
|
||||||
systemTags*: seq[string]
|
systemTags*: seq[string]
|
||||||
|
|
||||||
proc isContact*(self: Profile): bool =
|
proc isContact*(self: Profile): bool =
|
||||||
|
@ -22,6 +22,7 @@ proc toProfileModel*(account: Account): Profile =
|
||||||
ensName: "",
|
ensName: "",
|
||||||
ensVerified: false,
|
ensVerified: false,
|
||||||
ensVerifiedAt: 0,
|
ensVerifiedAt: 0,
|
||||||
|
appearance: 0,
|
||||||
ensVerificationRetries: 0,
|
ensVerificationRetries: 0,
|
||||||
systemTags: @[]
|
systemTags: @[]
|
||||||
)
|
)
|
||||||
|
@ -39,6 +40,7 @@ proc toProfileModel*(profile: JsonNode): Profile =
|
||||||
alias: profile["alias"].str,
|
alias: profile["alias"].str,
|
||||||
ensName: "",
|
ensName: "",
|
||||||
ensVerified: profile["ensVerified"].getBool,
|
ensVerified: profile["ensVerified"].getBool,
|
||||||
|
appearance: 0,
|
||||||
ensVerifiedAt: profile["ensVerifiedAt"].getInt,
|
ensVerifiedAt: profile["ensVerifiedAt"].getInt,
|
||||||
ensVerificationRetries: profile["ensVerificationRetries"].getInt,
|
ensVerificationRetries: profile["ensVerificationRetries"].getInt,
|
||||||
systemTags: systemTags
|
systemTags: systemTags
|
||||||
|
|
|
@ -57,3 +57,6 @@ proc reset*(self: Status) =
|
||||||
|
|
||||||
proc getNodeVersion*(self: Status): string =
|
proc getNodeVersion*(self: Status): string =
|
||||||
libstatus_settings.getWeb3ClientVersion()
|
libstatus_settings.getWeb3ClientVersion()
|
||||||
|
|
||||||
|
proc saveSetting*(self: Status, setting: string, value: string) =
|
||||||
|
discard libstatus_settings.saveSettings(setting, value)
|
||||||
|
|
|
@ -24,7 +24,15 @@ Item {
|
||||||
|
|
||||||
RowLayout {
|
RowLayout {
|
||||||
// TODO move this to a new panel once we have the appearance panel
|
// TODO move this to a new panel once we have the appearance panel
|
||||||
property bool isDarkTheme: false
|
property bool isDarkTheme: {
|
||||||
|
const isDarkTheme = profileModel.profile.appearance === 1
|
||||||
|
if (isDarkTheme) {
|
||||||
|
Style.changeTheme('dark')
|
||||||
|
} else {
|
||||||
|
Style.changeTheme('light')
|
||||||
|
}
|
||||||
|
return isDarkTheme
|
||||||
|
}
|
||||||
id: themeSetting
|
id: themeSetting
|
||||||
anchors.top: title.bottom
|
anchors.top: title.bottom
|
||||||
anchors.topMargin: 20
|
anchors.topMargin: 20
|
||||||
|
@ -36,12 +44,7 @@ Item {
|
||||||
Switch {
|
Switch {
|
||||||
checked: themeSetting.isDarkTheme
|
checked: themeSetting.isDarkTheme
|
||||||
onCheckedChanged: function(value) {
|
onCheckedChanged: function(value) {
|
||||||
themeSetting.isDarkTheme = !themeSetting.isDarkTheme
|
profileModel.changeTheme(themeSetting.isDarkTheme ? 0 : 1)
|
||||||
if (themeSetting.isDarkTheme) {
|
|
||||||
Style.changeTheme('dark')
|
|
||||||
} else {
|
|
||||||
Style.changeTheme('light')
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue