feat: make settings user dependant and clean settings uses

This commit is contained in:
Jonathan Rainville 2020-09-15 13:42:23 -04:00 committed by Iuri Matias
parent cebd889fd6
commit 23ca5f9930
17 changed files with 74 additions and 49 deletions

View File

@ -139,11 +139,15 @@ QtObject:
proc getProfile(self: ProfileView): QVariant {.slot.} = proc getProfile(self: ProfileView): QVariant {.slot.} =
return newQVariant(self.profile) return newQVariant(self.profile)
proc profileChanged*(self: ProfileView) {.signal.}
proc setNewProfile*(self: ProfileView, profile: Profile) = proc setNewProfile*(self: ProfileView, profile: Profile) =
self.profile.setProfile(profile) self.profile.setProfile(profile)
self.profileChanged()
QtProperty[QVariant] profile: QtProperty[QVariant] profile:
read = getProfile read = getProfile
notify = profileChanged
proc contactToAddChanged*(self: ProfileView) {.signal.} proc contactToAddChanged*(self: ProfileView) {.signal.}

View File

@ -33,6 +33,7 @@ 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

View File

@ -16,7 +16,6 @@ StackLayout {
property bool isExtendedInput: isReply || isImage property bool isExtendedInput: isReply || isImage
property var appSettings
property bool isConnected: false property bool isConnected: false
property string contactToRemove: "" property string contactToRemove: ""
@ -118,7 +117,6 @@ StackLayout {
ChatMessages { ChatMessages {
id: chatMessages id: chatMessages
messageList: chatsModel.messageList messageList: chatsModel.messageList
appSettings: chatColumnLayout.appSettings
} }
} }

View File

@ -12,7 +12,6 @@ ScrollView {
id: scrollView id: scrollView
property var messageList: MessagesData {} property var messageList: MessagesData {}
property var appSettings
property bool loadingMessages: false property bool loadingMessages: false
property real scrollY: chatLogView.visibleArea.yPosition * chatLogView.contentHeight property real scrollY: chatLogView.visibleArea.yPosition * chatLogView.contentHeight
@ -241,7 +240,6 @@ ScrollView {
} }
return -1; return -1;
} }
appSettings: scrollView.appSettings
scrollToBottom: chatLogView.scrollToBottom scrollToBottom: chatLogView.scrollToBottom
timeout: model.timeout timeout: model.timeout
} }

View File

@ -44,7 +44,6 @@ Item {
property var profileClick: function () {} property var profileClick: function () {}
property var imageClick: function () {} property var imageClick: function () {}
property var scrollToBottom: function () {} property var scrollToBottom: function () {}
property var appSettings
id: messageItem id: messageItem
width: parent.width width: parent.width

View File

@ -6,7 +6,7 @@ Item {
property var clickMessage: function () {} property var clickMessage: function () {}
property int chatHorizontalPadding: 12 property int chatHorizontalPadding: 12
property int chatVerticalPadding: 7 property int chatVerticalPadding: 7
property bool showImages: messageItem.appSettings.displayChatImages && imageUrls != "" property bool showImages: appSettings.displayChatImages && imageUrls != ""
id: chatTextItem id: chatTextItem
anchors.top: parent.top anchors.top: parent.top

View File

@ -4,7 +4,7 @@ import "../../../../../imports"
Item { Item {
property var clickMessage: function () {} property var clickMessage: function () {}
property bool showImages: messageItem.appSettings.displayChatImages && imageUrls != "" property bool showImages: appSettings.displayChatImages && imageUrls != ""
id: chatTextItem id: chatTextItem
anchors.top: parent.top anchors.top: parent.top

View File

@ -6,13 +6,11 @@ import "../../../shared"
import "." import "."
SplitView { SplitView {
property var appSettings
id: chatView id: chatView
handle: SplitViewHandle {} handle: SplitViewHandle {}
Component.onCompleted: this.restoreState(appSettings.chatSplitView) Component.onCompleted: this.restoreState(settings.chatSplitView)
Component.onDestruction: appSettings.chatSplitView = this.saveState() Component.onDestruction: settings.chatSplitView = this.saveState()
ContactsColumn { ContactsColumn {
id: contactsColumn id: contactsColumn
@ -24,7 +22,6 @@ SplitView {
ChatColumn { ChatColumn {
id: chatColumn id: chatColumn
chatGroupsListViewCount: contactsColumn.chatGroupsListViewCount chatGroupsListViewCount: contactsColumn.chatGroupsListViewCount
appSettings: chatView.appSettings
} }
} }

View File

@ -49,18 +49,20 @@ Popup {
const encodedIcon = String.fromCodePoint(...codePointParts); const encodedIcon = String.fromCodePoint(...codePointParts);
// Add at the start of the list // Add at the start of the list
appSettings.recentEmojis.unshift(emoji) let recentEmojis = appSettings.recentEmojis
recentEmojis.unshift(emoji)
// Remove duplicates // Remove duplicates
appSettings.recentEmojis = appSettings.recentEmojis.filter(function (e, index) { recentEmojis = recentEmojis.filter(function (e, index) {
return !appSettings.recentEmojis.some(function (e2, index2) { return !recentEmojis.some(function (e2, index2) {
return index2 < index && e2.filename === e.filename return index2 < index && e2.filename === e.filename
}) })
}) })
if (appSettings.recentEmojis.length > MAX_EMOJI_NUMBER) { if (recentEmojis.length > MAX_EMOJI_NUMBER) {
//remove last one //remove last one
appSettings.recentEmojis.splice(MAX_EMOJI_NUMBER - 1) recentEmojis.splice(MAX_EMOJI_NUMBER - 1)
} }
emojiSectionsRepeater.itemAt(0).allEmojis = appSettings.recentEmojis emojiSectionsRepeater.itemAt(0).allEmojis = recentEmojis
changeSetting("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()

View File

@ -6,7 +6,6 @@ import "../../../shared"
import "./Sections" import "./Sections"
SplitView { SplitView {
property var appSettings
property int contentMargin: 120 property int contentMargin: 120
id: profileView id: profileView
@ -15,8 +14,8 @@ SplitView {
handle: SplitViewHandle {} handle: SplitViewHandle {}
Component.onCompleted: this.restoreState(appSettings.profileSplitView) Component.onCompleted: this.restoreState(settings.profileSplitView)
Component.onDestruction: appSettings.profileSplitView = this.saveState() Component.onDestruction: settings.profileSplitView = this.saveState()
LeftTab { LeftTab {
id: leftTab id: leftTab
@ -72,9 +71,7 @@ SplitView {
DevicesContainer {} DevicesContainer {}
AdvancedContainer { AdvancedContainer {}
appSettings: profileView.appSettings
}
HelpContainer {} HelpContainer {}

View File

@ -5,8 +5,6 @@ import "../../../../imports"
import "../../../../shared" import "../../../../shared"
Item { Item {
property var appSettings
id: advancedContainer id: advancedContainer
width: 200 width: 200
height: 200 height: 200
@ -39,7 +37,7 @@ Item {
Switch { Switch {
checked: appSettings.walletEnabled checked: appSettings.walletEnabled
onCheckedChanged: function(value) { onCheckedChanged: function(value) {
appSettings.walletEnabled = this.checked changeSetting("walletEnabled", this.checked)
} }
} }
StyledText { StyledText {

View File

@ -62,7 +62,7 @@ Item {
Switch { Switch {
checked: compactModeSetting.isCompactMode checked: compactModeSetting.isCompactMode
onToggled: function() { onToggled: function() {
appSettings.compactMode = !compactModeSetting.isCompactMode changeSetting("compactMode", !compactModeSetting.isCompactMode)
} }
} }
} }

View File

@ -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)
appSettings.locale = locale changeSetting("locale", locale)
} }
StyledText { StyledText {

View File

@ -96,7 +96,7 @@ Item {
Switch { Switch {
checked: appSettings.displayChatImages checked: appSettings.displayChatImages
onCheckedChanged: function (value) { onCheckedChanged: function (value) {
appSettings.displayChatImages = this.checked changeSetting("displayChatImages", this.checked)
} }
} }
StyledText { StyledText {

View File

@ -6,16 +6,14 @@ import "../../../shared"
import "." import "."
SplitView { SplitView {
property var appSettings
id: walletView id: walletView
Layout.fillHeight: true Layout.fillHeight: true
Layout.fillWidth: true Layout.fillWidth: true
handle: SplitViewHandle {} handle: SplitViewHandle {}
Component.onCompleted: this.restoreState(appSettings.walletSplitView) Component.onCompleted: this.restoreState(settings.walletSplitView)
Component.onDestruction: appSettings.walletSplitView = this.saveState() Component.onDestruction: settings.walletSplitView = this.saveState()
LeftTab { LeftTab {
id: leftTab id: leftTab

View File

@ -6,12 +6,56 @@ import "../shared"
import "./AppLayouts" import "./AppLayouts"
RowLayout { RowLayout {
property var appSettings readonly property var defaultSettings: {
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 id: rowLayout
Layout.fillHeight: true Layout.fillHeight: true
Layout.fillWidth: true Layout.fillWidth: true
Connections {
target: profileModel
onProfileChanged: {
currentAccount = profileModel.profile.address
if (!mainSettings.userSettings) {
mainSettings.userSettings = {}
}
userSettings = mainSettings.userSettings
if (!userSettings[currentAccount]) {
userSettings[currentAccount] = defaultSettings
}
appSettings = userSettings[currentAccount]
if (appSettings.locale !== "en") {
profileModel.changeLocale(appSettings.locale)
}
}
}
function changeSetting(name, value) {
appSettings[name] = value
appSettingsChanged()
userSettings[currentAccount] = appSettings
mainSettings.userSettings = userSettings
}
ToastMessage { ToastMessage {
id: toastMessage id: toastMessage
} }
@ -198,7 +242,6 @@ RowLayout {
Layout.fillWidth: true Layout.fillWidth: true
Layout.alignment: Qt.AlignLeft | Qt.AlignTop Layout.alignment: Qt.AlignLeft | Qt.AlignTop
Layout.fillHeight: true Layout.fillHeight: true
appSettings: rowLayout.appSettings
} }
WalletLayout { WalletLayout {
@ -206,7 +249,6 @@ RowLayout {
Layout.fillWidth: true Layout.fillWidth: true
Layout.alignment: Qt.AlignLeft | Qt.AlignTop Layout.alignment: Qt.AlignLeft | Qt.AlignTop
Layout.fillHeight: true Layout.fillHeight: true
appSettings: rowLayout.appSettings
} }
ProfileLayout { ProfileLayout {
@ -214,7 +256,6 @@ RowLayout {
Layout.fillWidth: true Layout.fillWidth: true
Layout.alignment: Qt.AlignLeft | Qt.AlignTop Layout.alignment: Qt.AlignLeft | Qt.AlignTop
Layout.fillHeight: true Layout.fillHeight: true
appSettings: rowLayout.appSettings
} }
NodeLayout { NodeLayout {

View File

@ -16,7 +16,6 @@ import "./shared"
import "./imports" import "./imports"
ApplicationWindow { ApplicationWindow {
property alias appSettings: settings
property bool hasAccounts: !!loginModel.rowCount() property bool hasAccounts: !!loginModel.rowCount()
id: applicationWindow id: applicationWindow
@ -34,10 +33,6 @@ ApplicationWindow {
visible: true visible: true
Component.onCompleted: { Component.onCompleted: {
if (settings.locale !== "en") {
profileModel.changeLocale(settings.locale)
}
setX(Qt.application.screens[0].width / 2 - width / 2); setX(Qt.application.screens[0].width / 2 - width / 2);
setY(Qt.application.screens[0].height / 2 - height / 2); setY(Qt.application.screens[0].height / 2 - height / 2);
} }
@ -63,14 +58,11 @@ ApplicationWindow {
Settings { Settings {
id: settings id: settings
property var userSettings
// 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 {
@ -197,7 +189,7 @@ ApplicationWindow {
Component { Component {
id: app id: app
AppMain { AppMain {
appSettings: applicationWindow.appSettings mainSettings: settings
} }
} }