refactor: change settings to use a filename instead
This commit is contained in:
parent
23ca5f9930
commit
db9472bc0b
|
@ -33,7 +33,6 @@ QtObject:
|
||||||
self.appearance = profile.appearance
|
self.appearance = profile.appearance
|
||||||
self.pubKey = profile.id
|
self.pubKey = profile.id
|
||||||
self.address = profile.address
|
self.address = profile.address
|
||||||
debug "Setting account", username = profile.username, pubKey = profile.id, address = profile.address
|
|
||||||
self.profileChanged()
|
self.profileChanged()
|
||||||
|
|
||||||
proc username*(self: ProfileInfoView): string {.slot.} = result = self.username
|
proc username*(self: ProfileInfoView): string {.slot.} = result = self.username
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
import NimQml, chronicles
|
||||||
|
import ../../status/signals/types
|
||||||
|
import ../../status/[status, node, network]
|
||||||
|
import ../../status/libstatus/types as status_types
|
||||||
|
import view
|
||||||
|
|
||||||
|
logScope:
|
||||||
|
topics = "utils"
|
||||||
|
|
||||||
|
type UtilsController* = ref object
|
||||||
|
status*: Status
|
||||||
|
view*: UtilsView
|
||||||
|
variant*: QVariant
|
||||||
|
|
||||||
|
proc newController*(status: Status): UtilsController =
|
||||||
|
result = UtilsController()
|
||||||
|
result.status = status
|
||||||
|
result.view = newUtilsView(status)
|
||||||
|
result.variant = newQVariant(result.view)
|
||||||
|
|
||||||
|
proc delete*(self: UtilsController) =
|
||||||
|
delete self.variant
|
||||||
|
delete self.view
|
||||||
|
|
||||||
|
proc init*(self: UtilsController) =
|
||||||
|
discard
|
|
@ -0,0 +1,29 @@
|
||||||
|
import NimQml, os
|
||||||
|
import ../../status/status
|
||||||
|
import ../../status/libstatus/accounts/constants as accountConstants
|
||||||
|
|
||||||
|
QtObject:
|
||||||
|
type UtilsView* = ref object of QObject
|
||||||
|
status*: Status
|
||||||
|
|
||||||
|
proc setup(self: UtilsView) =
|
||||||
|
self.QObject.setup
|
||||||
|
|
||||||
|
proc delete*(self: UtilsView) =
|
||||||
|
self.QObject.delete
|
||||||
|
|
||||||
|
proc newUtilsView*(status: Status): UtilsView =
|
||||||
|
new(result, delete)
|
||||||
|
result = UtilsView()
|
||||||
|
result.status = status
|
||||||
|
result.setup
|
||||||
|
|
||||||
|
proc getDataDir*(self: UtilsView): string {.slot.} =
|
||||||
|
result = accountConstants.DATADIR
|
||||||
|
|
||||||
|
proc joinPath*(self: UtilsView, start: string, ending: string): string {.slot.} =
|
||||||
|
result = os.joinPath(start, ending)
|
||||||
|
|
||||||
|
proc join3Paths*(self: UtilsView, start: string, middle: string, ending: string): string {.slot.} =
|
||||||
|
result = os.joinPath(start, middle, ending)
|
||||||
|
|
|
@ -3,6 +3,7 @@ import NimQml, eventemitter, chronicles, os, strformat
|
||||||
import app/chat/core as chat
|
import app/chat/core as chat
|
||||||
import app/wallet/core as wallet
|
import app/wallet/core as wallet
|
||||||
import app/node/core as node
|
import app/node/core as node
|
||||||
|
import app/utilsView/core as utilsView
|
||||||
import app/profile/core as profile
|
import app/profile/core as profile
|
||||||
import app/onboarding/core as onboarding
|
import app/onboarding/core as onboarding
|
||||||
import app/login/core as login
|
import app/login/core as login
|
||||||
|
@ -65,6 +66,9 @@ proc mainProc() =
|
||||||
var node = node.newController(status)
|
var node = node.newController(status)
|
||||||
engine.setRootContextProperty("nodeModel", node.variant)
|
engine.setRootContextProperty("nodeModel", node.variant)
|
||||||
|
|
||||||
|
var utilsController = utilsView.newController(status)
|
||||||
|
engine.setRootContextProperty("utilsModel", utilsController.variant)
|
||||||
|
|
||||||
proc changeLanguage(locale: string) =
|
proc changeLanguage(locale: string) =
|
||||||
engine.setTranslationPackage(joinPath(i18nPath, fmt"qml_{locale}.qm"))
|
engine.setTranslationPackage(joinPath(i18nPath, fmt"qml_{locale}.qm"))
|
||||||
|
|
||||||
|
@ -84,6 +88,7 @@ proc mainProc() =
|
||||||
profile.init(args.account)
|
profile.init(args.account)
|
||||||
wallet.init()
|
wallet.init()
|
||||||
chat.init()
|
chat.init()
|
||||||
|
utilsController.init()
|
||||||
|
|
||||||
wallet.checkPendingTransactions()
|
wallet.checkPendingTransactions()
|
||||||
wallet.start()
|
wallet.start()
|
||||||
|
@ -105,6 +110,7 @@ proc mainProc() =
|
||||||
wallet.delete()
|
wallet.delete()
|
||||||
chat.delete()
|
chat.delete()
|
||||||
profile.delete()
|
profile.delete()
|
||||||
|
utilsController.delete()
|
||||||
|
|
||||||
|
|
||||||
# Initialize only controllers whose init functions
|
# Initialize only controllers whose init functions
|
||||||
|
|
|
@ -9,8 +9,14 @@ SplitView {
|
||||||
id: chatView
|
id: chatView
|
||||||
handle: SplitViewHandle {}
|
handle: SplitViewHandle {}
|
||||||
|
|
||||||
Component.onCompleted: this.restoreState(settings.chatSplitView)
|
Connections {
|
||||||
Component.onDestruction: settings.chatSplitView = this.saveState()
|
target: appMain
|
||||||
|
onSettingsLoaded: {
|
||||||
|
// Add recent
|
||||||
|
chatView.restoreState(appSettings.chatSplitView)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Component.onDestruction: appSettings.chatSplitView = this.saveState()
|
||||||
|
|
||||||
ContactsColumn {
|
ContactsColumn {
|
||||||
id: contactsColumn
|
id: contactsColumn
|
||||||
|
|
|
@ -58,11 +58,11 @@ Popup {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
if (recentEmojis.length > MAX_EMOJI_NUMBER) {
|
if (recentEmojis.length > MAX_EMOJI_NUMBER) {
|
||||||
//remove last one
|
// remove last one
|
||||||
recentEmojis.splice(MAX_EMOJI_NUMBER - 1)
|
recentEmojis.splice(MAX_EMOJI_NUMBER - 1)
|
||||||
}
|
}
|
||||||
emojiSectionsRepeater.itemAt(0).allEmojis = recentEmojis
|
emojiSectionsRepeater.itemAt(0).allEmojis = recentEmojis
|
||||||
changeSetting("recentEmojis", recentEmojis)
|
appSettings.recentEmojis = recentEmojis
|
||||||
|
|
||||||
popup.addToChat(Emoji.parse(encodedIcon, "26x26") + ' ') // Adding a space because otherwise, some emojis would fuse since it's just an emoji is just a string
|
popup.addToChat(Emoji.parse(encodedIcon, "26x26") + ' ') // Adding a space because otherwise, some emojis would fuse since it's just an emoji is just a string
|
||||||
popup.close()
|
popup.close()
|
||||||
|
@ -81,11 +81,6 @@ Popup {
|
||||||
newCategories[categoryNames[emoji.category]].push(Object.assign({}, emoji, {filename: emoji.unicode + '.png'}))
|
newCategories[categoryNames[emoji.category]].push(Object.assign({}, emoji, {filename: emoji.unicode + '.png'}))
|
||||||
})
|
})
|
||||||
|
|
||||||
// Add recent
|
|
||||||
appSettings.recentEmojis.forEach(function (emoji) {
|
|
||||||
newCategories[categoryNames.recent].push(Object.assign({}, emoji, {category: "recent"}))
|
|
||||||
})
|
|
||||||
|
|
||||||
if (newCategories[categoryNames.recent].length === 0) {
|
if (newCategories[categoryNames.recent].length === 0) {
|
||||||
newCategories[categoryNames.recent].push({
|
newCategories[categoryNames.recent].push({
|
||||||
category: "recent",
|
category: "recent",
|
||||||
|
@ -95,6 +90,16 @@ Popup {
|
||||||
|
|
||||||
categories = newCategories
|
categories = newCategories
|
||||||
}
|
}
|
||||||
|
Connections {
|
||||||
|
target: appMain
|
||||||
|
onSettingsLoaded: {
|
||||||
|
// Add recent
|
||||||
|
if (!appSettings.recentEmojis || !appSettings.recentEmojis.length) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
emojiSectionsRepeater.itemAt(0).allEmojis = appSettings.recentEmojis
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onOpened: {
|
onOpened: {
|
||||||
searchBox.forceActiveFocus(Qt.MouseFocusReason)
|
searchBox.forceActiveFocus(Qt.MouseFocusReason)
|
||||||
|
|
|
@ -14,8 +14,14 @@ SplitView {
|
||||||
|
|
||||||
handle: SplitViewHandle {}
|
handle: SplitViewHandle {}
|
||||||
|
|
||||||
Component.onCompleted: this.restoreState(settings.profileSplitView)
|
Connections {
|
||||||
Component.onDestruction: settings.profileSplitView = this.saveState()
|
target: appMain
|
||||||
|
onSettingsLoaded: {
|
||||||
|
// Add recent
|
||||||
|
profileView.restoreState(appSettings.profileSplitView)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Component.onDestruction: appSettings.profileSplitView = this.saveState()
|
||||||
|
|
||||||
LeftTab {
|
LeftTab {
|
||||||
id: leftTab
|
id: leftTab
|
||||||
|
|
|
@ -37,7 +37,7 @@ Item {
|
||||||
Switch {
|
Switch {
|
||||||
checked: appSettings.walletEnabled
|
checked: appSettings.walletEnabled
|
||||||
onCheckedChanged: function(value) {
|
onCheckedChanged: function(value) {
|
||||||
changeSetting("walletEnabled", this.checked)
|
appSettings.walletEnabled = this.checked
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
StyledText {
|
StyledText {
|
||||||
|
|
|
@ -62,7 +62,7 @@ Item {
|
||||||
Switch {
|
Switch {
|
||||||
checked: compactModeSetting.isCompactMode
|
checked: compactModeSetting.isCompactMode
|
||||||
onToggled: function() {
|
onToggled: function() {
|
||||||
changeSetting("compactMode", !compactModeSetting.isCompactMode)
|
appSettings.compactMode = !compactModeSetting.isCompactMode
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,7 +62,7 @@ Item {
|
||||||
onTriggered: function () {
|
onTriggered: function () {
|
||||||
const locale = Locales_JSON.locales[index]
|
const locale = Locales_JSON.locales[index]
|
||||||
profileModel.changeLocale(locale)
|
profileModel.changeLocale(locale)
|
||||||
changeSetting("locale", locale)
|
appSettings.locale = locale
|
||||||
}
|
}
|
||||||
|
|
||||||
StyledText {
|
StyledText {
|
||||||
|
|
|
@ -96,7 +96,7 @@ Item {
|
||||||
Switch {
|
Switch {
|
||||||
checked: appSettings.displayChatImages
|
checked: appSettings.displayChatImages
|
||||||
onCheckedChanged: function (value) {
|
onCheckedChanged: function (value) {
|
||||||
changeSetting("displayChatImages", this.checked)
|
appSettings.displayChatImages = this.checked
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
StyledText {
|
StyledText {
|
||||||
|
|
|
@ -12,8 +12,14 @@ SplitView {
|
||||||
|
|
||||||
handle: SplitViewHandle {}
|
handle: SplitViewHandle {}
|
||||||
|
|
||||||
Component.onCompleted: this.restoreState(settings.walletSplitView)
|
Connections {
|
||||||
Component.onDestruction: settings.walletSplitView = this.saveState()
|
target: appMain
|
||||||
|
onSettingsLoaded: {
|
||||||
|
// Add recent
|
||||||
|
walletView.restoreState(appSettings.walletSplitView)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Component.onDestruction: appSettings.walletSplitView = this.saveState()
|
||||||
|
|
||||||
LeftTab {
|
LeftTab {
|
||||||
id: leftTab
|
id: leftTab
|
||||||
|
|
|
@ -6,56 +6,23 @@ import "../shared"
|
||||||
import "./AppLayouts"
|
import "./AppLayouts"
|
||||||
|
|
||||||
RowLayout {
|
RowLayout {
|
||||||
readonly property var defaultSettings: {
|
id: appMain
|
||||||
return {
|
|
||||||
chatSplitView: undefined,
|
|
||||||
walletSplitView: undefined,
|
|
||||||
profileSplitView: undefined,
|
|
||||||
walletEnabled: false,
|
|
||||||
displayChatImages: false,
|
|
||||||
compactMode: false,
|
|
||||||
locale: "en",
|
|
||||||
recentEmojis: []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
property var mainSettings
|
|
||||||
property var userSettings
|
|
||||||
property var appSettings: defaultSettings
|
|
||||||
property string currentAccount
|
|
||||||
|
|
||||||
id: rowLayout
|
|
||||||
Layout.fillHeight: true
|
Layout.fillHeight: true
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
|
|
||||||
|
signal settingsLoaded()
|
||||||
|
|
||||||
Connections {
|
Connections {
|
||||||
target: profileModel
|
target: profileModel
|
||||||
onProfileChanged: {
|
onProfileChanged: {
|
||||||
currentAccount = profileModel.profile.address
|
appSettings.fileName = utilsModel.join3Paths(utilsModel.getDataDir(), 'qt', profileModel.profile.address)
|
||||||
|
settingsLoaded()
|
||||||
if (!mainSettings.userSettings) {
|
|
||||||
mainSettings.userSettings = {}
|
|
||||||
}
|
|
||||||
userSettings = mainSettings.userSettings
|
|
||||||
|
|
||||||
if (!userSettings[currentAccount]) {
|
|
||||||
userSettings[currentAccount] = defaultSettings
|
|
||||||
}
|
|
||||||
appSettings = userSettings[currentAccount]
|
|
||||||
|
|
||||||
if (appSettings.locale !== "en") {
|
if (appSettings.locale !== "en") {
|
||||||
profileModel.changeLocale(appSettings.locale)
|
profileModel.changeLocale(appSettings.locale)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function changeSetting(name, value) {
|
|
||||||
appSettings[name] = value
|
|
||||||
appSettingsChanged()
|
|
||||||
userSettings[currentAccount] = appSettings
|
|
||||||
mainSettings.userSettings = userSettings
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
ToastMessage {
|
ToastMessage {
|
||||||
id: toastMessage
|
id: toastMessage
|
||||||
}
|
}
|
||||||
|
@ -126,7 +93,7 @@ RowLayout {
|
||||||
|
|
||||||
TabButton {
|
TabButton {
|
||||||
id: walletBtn
|
id: walletBtn
|
||||||
enabled: isExperimental === "1" || rowLayout.appSettings.walletEnabled
|
enabled: isExperimental === "1" || appSettings.walletEnabled
|
||||||
visible: this.enabled
|
visible: this.enabled
|
||||||
width: 40
|
width: 40
|
||||||
height: this.enabled ? 40 : 0
|
height: this.enabled ? 40 : 0
|
||||||
|
|
14
ui/main.qml
14
ui/main.qml
|
@ -57,12 +57,16 @@ ApplicationWindow {
|
||||||
}
|
}
|
||||||
|
|
||||||
Settings {
|
Settings {
|
||||||
id: settings
|
id: appSettings
|
||||||
property var userSettings
|
fileName: "data/qt/unknownUser"
|
||||||
// Those can't be in the user settings as they are bytes that JS can't handle
|
|
||||||
property var chatSplitView
|
property var chatSplitView
|
||||||
property var walletSplitView
|
property var walletSplitView
|
||||||
property var profileSplitView
|
property var profileSplitView
|
||||||
|
property bool walletEnabled: false
|
||||||
|
property bool displayChatImages: false
|
||||||
|
property bool compactMode
|
||||||
|
property string locale: "en"
|
||||||
|
property var recentEmojis: []
|
||||||
}
|
}
|
||||||
|
|
||||||
SystemTrayIcon {
|
SystemTrayIcon {
|
||||||
|
@ -188,9 +192,7 @@ ApplicationWindow {
|
||||||
|
|
||||||
Component {
|
Component {
|
||||||
id: app
|
id: app
|
||||||
AppMain {
|
AppMain {}
|
||||||
mainSettings: settings
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Component {
|
Component {
|
||||||
|
|
Loading…
Reference in New Issue