diff --git a/src/app/profile/core.nim b/src/app/profile/core.nim new file mode 100644 index 0000000000..64768a7953 --- /dev/null +++ b/src/app/profile/core.nim @@ -0,0 +1,23 @@ +import NimQml +import json +import "../../status/core" as status +import ../signals/types +import profileView + +type ProfileController* = ref object of SignalSubscriber + view*: ProfileView + variant*: QVariant + +proc newController*(): ProfileController = + result = ProfileController() + result.view = newProfileView() + result.variant = newQVariant(result.view) + +proc delete*(self: ProfileController) = + delete self.view + delete self.variant + +proc init*(self: ProfileController, accounts: string) = + var chatAccount = parseJSON(accounts)[1] + + self.view.username = chatAccount["name"].str diff --git a/src/app/profile/profileView.nim b/src/app/profile/profileView.nim new file mode 100644 index 0000000000..ea9cdfb16a --- /dev/null +++ b/src/app/profile/profileView.nim @@ -0,0 +1,30 @@ +import NimQml + +QtObject: + type ProfileView* = ref object of QObject + username*: string + + proc setup(self: ProfileView) = + self.QObject.setup + + proc newProfileView*(): ProfileView = + new(result) + result.username = "" + result.setup + + proc delete*(self: ProfileView) = + self.QObject.delete + + proc username*(self: ProfileView): string {.slot.} = + result = self.username + + proc receivedUsername*(self: ProfileView, username: string) {.signal.} + + proc setUsername*(self: ProfileView, username: string) {.slot.} = + self.username = username + self.receivedUsername(username) + + QtProperty[string] username: + read = username + write = setUsername + notify = receivedUsername diff --git a/src/nim_status_client.nim b/src/nim_status_client.nim index 445d2ca3ed..dff03d5008 100644 --- a/src/nim_status_client.nim +++ b/src/nim_status_client.nim @@ -2,10 +2,12 @@ import NimQml import app/chat/core as chat import app/wallet/core as wallet import app/node/core as node +import app/profile/core as profile import app/signals/core as signals import state import strformat import strutils +import json import status/core as status import status/chat as status_chat import status/test as status_test @@ -33,7 +35,11 @@ proc mainProc() = var appState = state.newAppState() echo appState.title - status_test.setupNewAccount() + var accounts = status_test.setupNewAccount() + echo "---------" + echo parseJSON(accounts)[0] + echo parseJSON(accounts)[1] + echo "---------" status_chat.startMessenger() @@ -49,6 +55,10 @@ proc mainProc() = node.init() engine.setRootContextProperty("nodeModel", node.variant) + var profile = profile.newController() + profile.init(accounts) + engine.setRootContextProperty("profileModel", profile.variant) + signalController.init() signalController.addSubscriber(SignalType.Wallet, wallet) signalController.addSubscriber(SignalType.Wallet, node) diff --git a/src/status/test.nim b/src/status/test.nim index 812a67804b..7a8acda94c 100644 --- a/src/status/test.nim +++ b/src/status/test.nim @@ -29,7 +29,7 @@ proc queryAccounts*(): string = echo response result = parseJson(response)["result"][0].getStr() -proc setupNewAccount*() = +proc setupNewAccount*(): string = # Deleting directories recreateDir(datadir) recreateDir(keystoredir) @@ -291,12 +291,13 @@ proc setupNewAccount*() = } ] - result = $libstatus.saveAccountAndLogin($accountData, password, $settingsJSON, + var savedResult = $libstatus.saveAccountAndLogin($accountData, password, $settingsJSON, $configJSON, $subaccountData) - let saveResult = result.parseJson + let parsedSavedResult = savedResult.parseJson - if saveResult["error"].getStr == "": + if parsedSavedResult["error"].getStr == "": echo "Account saved succesfully" + $subaccountData proc addPeer*(peer: string): string = return $libstatus.addPeer(peer) diff --git a/ui/app/AppLayouts/Profile/LeftTab.qml b/ui/app/AppLayouts/Profile/LeftTab.qml index 87f307134b..be060996d0 100644 --- a/ui/app/AppLayouts/Profile/LeftTab.qml +++ b/ui/app/AppLayouts/Profile/LeftTab.qml @@ -68,7 +68,7 @@ ColumnLayout { Text { id: profileName - text: qsTr("Happy Extraneous Dancer") + text: profileModel.username anchors.top: profileImg.bottom anchors.topMargin: 10 anchors.horizontalCenterOffset: 0