add profile module; display username from one of the accounts instead of hardcoded one

This commit is contained in:
Iuri Matias 2020-05-19 21:59:15 -04:00
parent 6ed3299c28
commit 24bb268934
5 changed files with 70 additions and 6 deletions

23
src/app/profile/core.nim Normal file
View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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