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.} =
return newQVariant(self.profile)
proc profileChanged*(self: ProfileView) {.signal.}
proc setNewProfile*(self: ProfileView, profile: Profile) =
self.profile.setProfile(profile)
self.profileChanged()
QtProperty[QVariant] profile:
read = getProfile
notify = profileChanged
proc contactToAddChanged*(self: ProfileView) {.signal.}

View File

@ -33,6 +33,7 @@ QtObject:
self.appearance = profile.appearance
self.pubKey = profile.id
self.address = profile.address
debug "Setting account", username = profile.username, pubKey = profile.id, address = profile.address
self.profileChanged()
proc username*(self: ProfileInfoView): string {.slot.} = result = self.username

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -62,7 +62,7 @@ Item {
onTriggered: function () {
const locale = Locales_JSON.locales[index]
profileModel.changeLocale(locale)
appSettings.locale = locale
changeSetting("locale", locale)
}
StyledText {

View File

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

View File

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

View File

@ -6,12 +6,56 @@ import "../shared"
import "./AppLayouts"
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
Layout.fillHeight: 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 {
id: toastMessage
}
@ -198,7 +242,6 @@ RowLayout {
Layout.fillWidth: true
Layout.alignment: Qt.AlignLeft | Qt.AlignTop
Layout.fillHeight: true
appSettings: rowLayout.appSettings
}
WalletLayout {
@ -206,7 +249,6 @@ RowLayout {
Layout.fillWidth: true
Layout.alignment: Qt.AlignLeft | Qt.AlignTop
Layout.fillHeight: true
appSettings: rowLayout.appSettings
}
ProfileLayout {
@ -214,7 +256,6 @@ RowLayout {
Layout.fillWidth: true
Layout.alignment: Qt.AlignLeft | Qt.AlignTop
Layout.fillHeight: true
appSettings: rowLayout.appSettings
}
NodeLayout {

View File

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