peerplays_migrated/programs/light_client/qml/main.qml

208 lines
5.8 KiB
QML
Raw Normal View History

2015-07-10 21:37:22 +00:00
import QtQuick 2.5
import QtQuick.Controls 1.4
import QtQuick.Dialogs 1.2
import QtQuick.Window 2.2
2015-07-10 21:37:22 +00:00
import Qt.labs.settings 1.0
2015-07-10 21:37:22 +00:00
import Graphene.Client 0.1
ApplicationWindow {
id: window
2015-07-10 21:37:22 +00:00
visible: true
width: 640
height: 480
title: qsTr("Hello World")
menuBar: MenuBar {
Menu {
title: qsTr("File")
MenuItem {
text: qsTr("&Open")
onTriggered: console.log("Open action triggered");
}
MenuItem {
text: qsTr("Exit")
onTriggered: Qt.quit();
2015-07-14 17:06:32 +00:00
shortcut: "Ctrl+Q"
2015-07-10 21:37:22 +00:00
}
}
}
statusBar: StatusBar {
Label {
anchors.right: parent.right
text: qsTr("Network: %1 Wallet: %2").arg(app.isConnected? qsTr("Connected") : qsTr("Disconnected"))
.arg(app.wallet.isLocked? qsTr("Locked") : qsTr("Unlocked"))
}
}
2015-07-10 21:37:22 +00:00
2015-07-13 17:19:07 +00:00
GrapheneApplication {
id: app
Component.onCompleted: {
var walletFile = appSettings.walletPath + "/wallet.json"
if (!wallet.open(walletFile)) {
// TODO: onboarding experience
wallet.create(walletFile, "default password", "default brain key")
}
}
}
Timer {
running: !app.isConnected
interval: 5000
repeat: true
onTriggered: app.start("ws://localhost:8090", "user", "pass")
triggeredOnStart: true
2015-07-10 21:37:22 +00:00
}
Settings {
id: appSettings
category: "appSettings"
property string walletPath: app.defaultDataPath()
2015-07-10 21:37:22 +00:00
}
Connections {
target: app
onExceptionThrown: console.log("Exception from app: " + message)
}
2015-07-10 21:37:22 +00:00
Column {
anchors.centerIn: parent
enabled: app.isConnected
Button {
text: "Transfer"
onClicked: {
var front = Qt.createComponent("TransferForm.qml")
// TODO: make back into a preview and confirm dialog
var back = Qt.createComponent("TransactionConfirmationForm.qml")
formBox.showForm(Qt.createComponent("FormFlipper.qml"), {frontComponent: front, backComponent: back},
function(arg) {
console.log("Closed form: " + JSON.stringify(arg))
})
}
}
TextField {
id: nameField
2015-07-14 13:46:38 +00:00
onAccepted: lookupNameButton.clicked()
focus: true
}
Button {
2015-07-14 13:46:38 +00:00
id: lookupNameButton
text: "Lookup Name"
onClicked: {
var acct = app.model.getAccount(nameField.text)
2015-07-13 21:24:25 +00:00
console.log(JSON.stringify(acct))
// @disable-check M126
if (acct == null)
console.log("Got back null account")
else if (acct.id >= 0)
2015-07-13 21:24:25 +00:00
{
console.log("ID ALREADY SET" );
console.log(JSON.stringify(acct))
2015-07-13 21:24:25 +00:00
}
else
2015-07-13 21:24:25 +00:00
{
console.log("Waiting for result...")
2015-07-14 21:30:15 +00:00
acct.idChanged.connect(function() {
2015-07-13 21:24:25 +00:00
console.log( "ID CHANGED" );
2015-07-14 21:30:15 +00:00
console.log(JSON.stringify(acct))
})
2015-07-13 21:24:25 +00:00
}
}
}
2015-07-14 13:46:38 +00:00
TextField {
2015-07-14 21:30:15 +00:00
id: accountIdField
onAccepted: lookupAccountIdButton.clicked()
2015-07-14 13:46:38 +00:00
focus: true
}
Button {
2015-07-14 21:30:15 +00:00
id: lookupAccountIdButton
text: "Lookup Account ID"
2015-07-14 13:46:38 +00:00
onClicked: {
2015-07-14 21:30:15 +00:00
var acct = app.model.getAccount(parseInt(accountIdField.text))
2015-07-14 13:46:38 +00:00
console.log(JSON.stringify(acct))
// @disable-check M126
if (acct == null)
console.log("Got back null account")
else if ( !(parseInt(acct.name) <= 0) )
console.log(JSON.stringify(acct))
else {
2015-07-14 13:46:38 +00:00
console.log("Waiting for result...")
2015-07-14 21:30:15 +00:00
acct.nameChanged.connect(function() {
console.log(JSON.stringify(acct))
})
}
}
}
TextField {
id: assetIdField
onAccepted: lookupassetIdButton.clicked()
focus: true
}
Button {
id: lookupassetIdButton
text: "Lookup Asset ID"
onClicked: {
var acct = app.model.getAsset(parseInt(assetIdField.text))
console.log(JSON.stringify(acct))
// @disable-check M126
if (acct == null)
console.log("Got back null asset")
else if ( !(parseInt(acct.name) <= 0) )
{
console.log(JSON.stringify(acct))
}
else
{
console.log("Waiting for result...")
acct.nameChanged.connect(function() {
2015-07-14 13:46:38 +00:00
console.log(JSON.stringify(acct))
})
}
}
}
TextField {
id: passwordField
echoMode: TextInput.Password
}
Button {
text: app.wallet.isLocked? "Unlock wallet" : "Lock wallet"
onClicked: {
if (app.wallet.isLocked)
app.wallet.unlock(passwordField.text)
else
app.wallet.lock()
}
}
TextField {
id: keyField
placeholderText: "Private key"
}
TextField {
id: keyLabelField
placeholderText: "Key label"
}
Button {
text: "Import key"
enabled: !app.wallet.isLocked && keyField.text && keyLabelField.text
onClicked: app.wallet.importPrivateKey(keyField.text, keyLabelField.text)
}
2015-07-13 18:16:02 +00:00
}
FormBox {
id: formBox
anchors.fill: parent
z: 10
}
2015-07-10 21:37:22 +00:00
// This Settings is only for geometry -- it doesn't get an id. See appSettings for normal settings
Settings {
category: "windowGeometry"
property alias x: window.x
property alias y: window.y
property alias width: window.width
property alias height: window.height
2015-07-10 21:37:22 +00:00
}
}