refactor: use profileSettingsFile QtProperty instead of profile directly

This commit is contained in:
Jonathan Rainville 2020-09-16 10:28:03 -04:00 committed by Iuri Matias
parent db9472bc0b
commit bcbcd13611
7 changed files with 33 additions and 19 deletions

View File

@ -1,4 +1,4 @@
import NimQml, sequtils, strutils, sugar
import NimQml, sequtils, strutils, sugar, os
import views/[mailservers_list, ens_manager, contact_list, profile_info, device_list]
import ../../status/profile/[mailserver, profile, devices]
import ../../status/profile as status_profile
@ -10,6 +10,7 @@ import ../../status/devices as status_devices
import ../../status/ens as status_ens
import ../../status/chat/chat
import ../../status/libstatus/types
import ../../status/libstatus/accounts/constants as accountConstants
import qrcode/qrcode
QtObject:
@ -136,6 +137,21 @@ QtObject:
write = setNetworkAndPersist
notify = networkChanged
proc profileSettingsFileChanged*(self: ProfileView) {.signal.}
proc getProfileSettingsFile(self: ProfileView): string {.slot.} =
let address =
if (self.profile.address == ""):
"unknownAccount"
else:
self.profile.address
return os.joinPath(accountConstants.DATADIR, "qt", address)
QtProperty[string] profileSettingsFile:
read = getProfileSettingsFile
notify = profileSettingsFileChanged
proc getProfile(self: ProfileView): QVariant {.slot.} =
return newQVariant(self.profile)
@ -144,6 +160,7 @@ QtObject:
proc setNewProfile*(self: ProfileView, profile: Profile) =
self.profile.setProfile(profile)
self.profileChanged()
self.profileSettingsFileChanged()
QtProperty[QVariant] profile:
read = getProfile

View File

@ -10,7 +10,7 @@ SplitView {
handle: SplitViewHandle {}
Connections {
target: appMain
target: applicationWindow
onSettingsLoaded: {
// Add recent
chatView.restoreState(appSettings.chatSplitView)

View File

@ -91,7 +91,7 @@ Popup {
categories = newCategories
}
Connections {
target: appMain
target: applicationWindow
onSettingsLoaded: {
// Add recent
if (!appSettings.recentEmojis || !appSettings.recentEmojis.length) {

View File

@ -15,7 +15,7 @@ SplitView {
handle: SplitViewHandle {}
Connections {
target: appMain
target: applicationWindow
onSettingsLoaded: {
// Add recent
profileView.restoreState(appSettings.profileSplitView)

View File

@ -13,7 +13,7 @@ SplitView {
handle: SplitViewHandle {}
Connections {
target: appMain
target: applicationWindow
onSettingsLoaded: {
// Add recent
walletView.restoreState(appSettings.walletSplitView)

View File

@ -10,19 +10,6 @@ RowLayout {
Layout.fillHeight: true
Layout.fillWidth: true
signal settingsLoaded()
Connections {
target: profileModel
onProfileChanged: {
appSettings.fileName = utilsModel.join3Paths(utilsModel.getDataDir(), 'qt', profileModel.profile.address)
settingsLoaded()
if (appSettings.locale !== "en") {
profileModel.changeLocale(appSettings.locale)
}
}
}
ToastMessage {
id: toastMessage
}

View File

@ -56,9 +56,10 @@ ApplicationWindow {
volume: 0.2
}
signal settingsLoaded()
Settings {
id: appSettings
fileName: "data/qt/unknownUser"
fileName: profileModel.profileSettingsFile
property var chatSplitView
property var walletSplitView
property var profileSplitView
@ -68,6 +69,15 @@ ApplicationWindow {
property string locale: "en"
property var recentEmojis: []
}
Connections {
target: profileModel
onProfileSettingsFileChanged: {
settingsLoaded()
if (appSettings.locale !== "en") {
profileModel.changeLocale(appSettings.locale)
}
}
}
SystemTrayIcon {
visible: true