Add multiaccount write-as alias account setting
This commit is contained in:
parent
4f1884b121
commit
93bc2ff5a9
2
TODO.md
2
TODO.md
|
@ -1,4 +1,4 @@
|
||||||
- aiofiles Thumbnails
|
- Set Qt.application.* stuff from C++
|
||||||
- Devices and client settings in edit account page
|
- Devices and client settings in edit account page
|
||||||
- Multiaccount aliases
|
- Multiaccount aliases
|
||||||
- If avatar is set, name color from average color?
|
- If avatar is set, name color from average color?
|
||||||
|
|
|
@ -11,6 +11,8 @@ from dataclasses import dataclass, field
|
||||||
|
|
||||||
from .backend import Backend
|
from .backend import Backend
|
||||||
|
|
||||||
|
JsonData = Dict[str, Any]
|
||||||
|
|
||||||
WRITE_LOCK = asyncio.Lock()
|
WRITE_LOCK = asyncio.Lock()
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,14 +29,18 @@ class ConfigFile:
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class JSONConfigFile(ConfigFile):
|
class JSONConfigFile(ConfigFile):
|
||||||
async def read(self) -> Dict[str, Any]:
|
async def default_data(self) -> JsonData:
|
||||||
|
return {}
|
||||||
|
|
||||||
|
|
||||||
|
async def read(self) -> JsonData:
|
||||||
try:
|
try:
|
||||||
return json.loads(self.path.read_text())
|
return json.loads(self.path.read_text())
|
||||||
except (json.JSONDecodeError, FileNotFoundError):
|
except (json.JSONDecodeError, FileNotFoundError):
|
||||||
return {}
|
return await self.default_data()
|
||||||
|
|
||||||
|
|
||||||
async def write(self, data: Dict[str, Any]) -> None:
|
async def write(self, data: JsonData) -> None:
|
||||||
js = json.dumps(data, indent=4, ensure_ascii=False, sort_keys=True)
|
js = json.dumps(data, indent=4, ensure_ascii=False, sort_keys=True)
|
||||||
|
|
||||||
async with WRITE_LOCK:
|
async with WRITE_LOCK:
|
||||||
|
@ -76,3 +82,8 @@ class Accounts(JSONConfigFile):
|
||||||
@dataclass
|
@dataclass
|
||||||
class UISettings(JSONConfigFile):
|
class UISettings(JSONConfigFile):
|
||||||
filename: str = "ui-settings.json"
|
filename: str = "ui-settings.json"
|
||||||
|
|
||||||
|
async def default_data(self) -> JsonData:
|
||||||
|
return {
|
||||||
|
"write_aliases": {}
|
||||||
|
}
|
||||||
|
|
|
@ -19,6 +19,11 @@ HGridLayout {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (aliasField.changed) {
|
||||||
|
window.settings.write_aliases[userId] = aliasField.field.text
|
||||||
|
window.settingsChanged()
|
||||||
|
}
|
||||||
|
|
||||||
if (avatar.changed) {
|
if (avatar.changed) {
|
||||||
saveButton.avatarChangeRunning = true
|
saveButton.avatarChangeRunning = true
|
||||||
let path = Qt.resolvedUrl(avatar.imageUrl).replace(/^file:/, "")
|
let path = Qt.resolvedUrl(avatar.imageUrl).replace(/^file:/, "")
|
||||||
|
@ -32,6 +37,13 @@ HGridLayout {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function cancelChanges() {
|
||||||
|
nameField.field.text = userInfo.displayName
|
||||||
|
aliasField.field.text = aliasField.currentAlias
|
||||||
|
fileDialog.selectedFile = ""
|
||||||
|
fileDialog.file = ""
|
||||||
|
}
|
||||||
|
|
||||||
columns: 2
|
columns: 2
|
||||||
flow: window.isWide ? GridLayout.LeftToRight : GridLayout.TopToBottom
|
flow: window.isWide ? GridLayout.LeftToRight : GridLayout.TopToBottom
|
||||||
rowSpacing: currentSpacing
|
rowSpacing: currentSpacing
|
||||||
|
@ -123,6 +135,21 @@ HGridLayout {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.maximumWidth: 480
|
Layout.maximumWidth: 480
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HLabeledTextField {
|
||||||
|
property string currentAlias:
|
||||||
|
window.settings.write_aliases[userId] || ""
|
||||||
|
|
||||||
|
property bool changed: field.text != currentAlias
|
||||||
|
|
||||||
|
id: aliasField
|
||||||
|
label.text: qsTr("Write alias:")
|
||||||
|
field.text: currentAlias
|
||||||
|
field.onAccepted: applyChanges()
|
||||||
|
|
||||||
|
Layout.fillWidth: true
|
||||||
|
Layout.maximumWidth: 480
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HSpacer {}
|
HSpacer {}
|
||||||
|
@ -138,7 +165,8 @@ HGridLayout {
|
||||||
iconName: "apply"
|
iconName: "apply"
|
||||||
text: qsTr("Apply")
|
text: qsTr("Apply")
|
||||||
loading: nameChangeRunning || avatarChangeRunning
|
loading: nameChangeRunning || avatarChangeRunning
|
||||||
enabled: nameField.changed || avatar.changed
|
enabled:
|
||||||
|
nameField.changed || aliasField.changed || avatar.changed
|
||||||
|
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.alignment: Qt.AlignBottom
|
Layout.alignment: Qt.AlignBottom
|
||||||
|
@ -149,16 +177,12 @@ HGridLayout {
|
||||||
HUIButton {
|
HUIButton {
|
||||||
iconName: "cancel"
|
iconName: "cancel"
|
||||||
text: qsTr("Cancel")
|
text: qsTr("Cancel")
|
||||||
|
enabled: saveButton.enabled && ! saveButton.loading
|
||||||
|
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.alignment: Qt.AlignBottom
|
Layout.alignment: Qt.AlignBottom
|
||||||
enabled: saveButton.enabled && ! saveButton.loading
|
|
||||||
|
|
||||||
onClicked: {
|
onClicked: cancelChanges()
|
||||||
nameField.field.text = userInfo.displayName
|
|
||||||
fileDialog.selectedFile = ""
|
|
||||||
fileDialog.file = ""
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,11 @@ Python {
|
||||||
call("APP.call_client_coro", [accountId, name, uuid, args])
|
call("APP.call_client_coro", [accountId, name, uuid, args])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function saveSettings(callback=null) {
|
||||||
|
if (! py.ready) { return } // config not loaded yet
|
||||||
|
callCoro("ui_settings.write", [window.settings], callback)
|
||||||
|
}
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
for (var func in EventHandlers) {
|
for (var func in EventHandlers) {
|
||||||
if (EventHandlers.hasOwnProperty(func)) {
|
if (EventHandlers.hasOwnProperty(func)) {
|
||||||
|
@ -46,16 +51,20 @@ Python {
|
||||||
call("APP.is_debug_on", [Qt.application.arguments], on => {
|
call("APP.is_debug_on", [Qt.application.arguments], on => {
|
||||||
window.debug = on
|
window.debug = on
|
||||||
|
|
||||||
callCoro("saved_accounts.any_saved", [], any => {
|
callCoro("ui_settings.read", [], settings => {
|
||||||
py.ready = true
|
window.settings = settings
|
||||||
willLoadAccounts(any)
|
|
||||||
|
|
||||||
if (any) {
|
callCoro("saved_accounts.any_saved", [], any => {
|
||||||
py.loadingAccounts = true
|
py.ready = true
|
||||||
py.callCoro("load_saved_accounts", [], () => {
|
willLoadAccounts(any)
|
||||||
py.loadingAccounts = false
|
|
||||||
})
|
if (any) {
|
||||||
}
|
py.loadingAccounts = true
|
||||||
|
py.callCoro("load_saved_accounts", [], () => {
|
||||||
|
py.loadingAccounts = false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -16,10 +16,6 @@ ApplicationWindow {
|
||||||
title: "Harmony QML"
|
title: "Harmony QML"
|
||||||
color: "black"
|
color: "black"
|
||||||
|
|
||||||
property bool debug: false
|
|
||||||
property bool ready: false
|
|
||||||
property bool isWide: width > theme.isWideAbove
|
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
Qt.application.organization = "harmonyqml"
|
Qt.application.organization = "harmonyqml"
|
||||||
Qt.application.name = "harmonyqml"
|
Qt.application.name = "harmonyqml"
|
||||||
|
@ -28,6 +24,14 @@ ApplicationWindow {
|
||||||
window.ready = true
|
window.ready = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
property bool debug: false
|
||||||
|
property bool ready: false
|
||||||
|
property bool isWide: width > theme.isWideAbove
|
||||||
|
|
||||||
|
// Note: window.settingsChanged() must be called manually
|
||||||
|
property var settings: ({})
|
||||||
|
onSettingsChanged: py.saveSettings()
|
||||||
|
|
||||||
Theme { id: theme }
|
Theme { id: theme }
|
||||||
|
|
||||||
Python { id: py }
|
Python { id: py }
|
||||||
|
|
Loading…
Reference in New Issue
Block a user