forked from carver/mix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
StateDialog.qml
560 lines (511 loc) · 13.3 KB
/
StateDialog.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
/*
This file is part of cpp-ethereum.
cpp-ethereum is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
cpp-ethereum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file StateDialog.qml
* @author Yann [email protected]
* @author Arkadiy Paronyan [email protected]
* @date 2015
* Ethereum IDE client.
*/
import QtQuick 2.2
import QtQuick.Controls 1.1
import QtQuick.Dialogs 1.2
import QtQuick.Layouts 1.1
import QtQuick.Window 2.0
import QtQuick.Controls.Styles 1.3
import org.ethereum.qml.QEther 1.0
import org.ethereum.qml.InverseMouseArea 1.0
import "js/QEtherHelper.js" as QEtherHelper
import "js/TransactionHelper.js" as TransactionHelper
import "."
Dialog {
id: modalStateDialog
modality: Qt.ApplicationModal
width: 630
height: 480
title: qsTr("Edit Starting Parameters")
visible: false
property alias minerComboBox: comboMiner
property int minerIndex
property int stateIndex
property var stateTransactions: []
property var stateAccounts: []
property var stateContracts: []
signal accepted
signal closed
StateDialogStyle {
id: stateDialogStyle
}
function open(index, item) {
if (mainApplication.systemPointSize >= appSettings.systemPointSize)
{
width = 630
height = 480
}
else
{
width = 630 + (11 * appSettings.systemPointSize)
height = 480 + (7 * appSettings.systemPointSize)
}
stateIndex = index
accountsModel.clear()
stateAccounts = []
minerIndex = 0
for (var k = 0; k < item.accounts.length; k++) {
accountsModel.append(item.accounts[k])
stateAccounts.push(item.accounts[k])
if (item.miner && item.accounts[k].name === item.miner.name)
minerIndex = k
}
contractsModel.clear()
stateContracts = []
if (item.contracts) {
for (k = 0; k < item.contracts.length; k++) {
contractsModel.append(item.contracts[k])
stateContracts.push(item.contracts[k])
}
}
visible = true
updateMinerList()
forceActiveFocus()
}
function updateMinerList()
{
comboMiner.model = stateAccounts
comboMiner.currentIndex = minerIndex
}
function acceptAndClose() {
close()
accepted()
}
function close() {
visible = false
closed()
}
function getItem() {
var item = {
accounts: stateAccounts,
contracts: stateContracts
}
for (var k = 0; k < stateAccounts.length; k++) {
if (stateAccounts[k].name === comboMiner.currentText) {
item.miner = stateAccounts[k]
break
}
}
return item
}
contentItem: ColumnLayout {
implicitHeight: modalStateDialog.height
implicitWidth: modalStateDialog.width
anchors.fill: parent
anchors.margins: 10
ListModel {
id: contractsModel
function removeContract(_i) {
contractsModel.remove(_i)
stateContracts.splice(_i, 1)
}
}
ListModel {
id: accountsModel
function removeAccount(_i) {
accountsModel.remove(_i)
stateAccounts.splice(_i, 1)
}
}
ColumnLayout {
id: dialogContent
anchors.top: parent.top
width: parent.width
ColumnLayout {
Layout.fillWidth: true
RowLayout {
Layout.preferredWidth: parent.width
DefaultLabel {
id: contractsLabel
text: qsTr("Genesis Contracts")
}
DefaultButton {
Layout.alignment: Qt.AlignRight
id: importStateButton
tooltip: qsTr("Import genesis state from JSON file")
text: qsTr("Import...")
onClicked: {
importJsonFileDialog.open()
}
}
QFileDialog {
id: importJsonFileDialog
visible: false
title: qsTr("Select State File")
nameFilters: Qt.platform.os === "osx" ? [] : [qsTr("JSON files (*.json)", "All files (*)")] //qt 5.4 segfaults with filter string on OSX
onAccepted: {
var path = importJsonFileDialog.fileUrl.toString()
var jsonData = fileIo.readFile(path)
if (jsonData) {
var json = JSON.parse(jsonData)
for (var address in json) {
var account = {
address: address,
name: (json[address].name ? json[address].name : address),
balance: QEtherHelper.createEther(json[address].wei, QEther.Wei),
code: json[address].code,
storage: json[address].storage
}
if (account.code) {
contractsModel.append(account)
stateContracts.push(account)
} else {
accountsModel.append(account)
stateAccounts.push(account)
}
}
}
}
}
}
TableView {
id: genesisContractsView
Layout.fillWidth: true
Layout.fillHeight: true
model: contractsModel
headerVisible: false
TableViewColumn {
role: "name"
title: qsTr("Name")
width: 260
delegate: Item {
RowLayout {
height: 25
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
width: parent.width - 20
Button {
height: 25
width: 25
anchors.verticalCenter: parent.verticalCenter
tooltip: qsTr("Delete Contract")
onClicked: {
stateContracts.splice(styleData.row, 1)
contractsModel.remove(styleData.row)
}
Image {
height: 25
width: 25
anchors.centerIn: parent
source: "qrc:/qml/img/[email protected]"
}
}
DefaultTextField {
Layout.fillWidth: true
anchors.verticalCenter: parent.verticalCenter
onTextChanged: {
if (styleData.row > -1)
stateContracts[styleData.row].name = text
}
text: styleData.value
}
}
}
}
TableViewColumn {
role: "balance"
title: qsTr("Balance")
width: 230
delegate: Item {
Ether {
width: parent.width
anchors.verticalCenter: parent.verticalCenter
edit: true
displayFormattedValue: false
value: styleData.value
}
}
}
rowDelegate: Rectangle {
color: styleData.alternate ? "transparent" : "#f0f0f0"
height: 60
}
}
}
ColumnLayout {
Layout.fillWidth: true
RowLayout {
Layout.preferredWidth: parent.width
DefaultLabel {
id: accountsLabel
Layout.preferredWidth: 85
text: qsTr("Accounts")
}
Row
{
Layout.alignment: Qt.AlignRight
spacing: 5
DefaultButton
{
id: addAccount
Image
{
anchors.centerIn: parent
source: "qrc:/qml/img/[email protected]"
}
width: 35
height: 28
anchors.verticalCenter: parent.verticalCenter
tooltip: qsTr("Add new account")
onClicked:
{
newAddressWin.accounts = stateAccounts
newAddressWin.open()
}
}
CopyButton
{
id: cpBtn
tooltip: qsTr("Copy All Users Details to Clipboard")
getContent: function() {
return JSON.stringify(stateAccounts, null, "\t");
}
}
}
}
MessageDialog {
id: alertAlreadyUsed
text: qsTr("This account is in use. You cannot remove it. The first account is used to deploy config contract and cannot be removed.")
icon: StandardIcon.Warning
standardButtons: StandardButton.Ok
}
TableView {
Layout.fillWidth: true
Layout.fillHeight: true
id: accountsView
model: accountsModel
headerVisible: false
TableViewColumn {
role: "name"
title: qsTr("Name")
delegate: Item {
Rectangle
{
anchors.fill: parent
color: "transparent"
RowLayout {
anchors.top: parent.top
anchors.topMargin: 10
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
width: parent.width - 20
MessageDialog
{
id: deleteAccountMsg
text: qsTr("Are you sure you want to delete this account?")
onYes:
{
stateAccounts.splice(styleData.row, 1)
accountsView.model.remove(styleData.row)
updateMinerList()
}
standardButtons: StandardButton.Yes | StandardButton.No
}
Component.onCompleted:
{
addressCopy.originalText = stateAccounts[styleData.row].address
}
Layout.preferredWidth: parent.width
Layout.minimumHeight: 20
spacing: 5
Rectangle
{
Layout.fillWidth: true
Rectangle
{
border.color: "#cccccc"
border.width: 1
width: parent.width
color: "transparent"
radius: 4
height: labelUser.height + 5
anchors.verticalCenter: parent.verticalCenter
DefaultText
{
anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left
anchors.leftMargin: 2
id: labelUser
text: styleData.value
width: parent.width
elide: Text.ElideRight
MouseArea
{
anchors.fill: parent
onDoubleClicked:
{
parent.visible = false
parent.parent.visible = false
addressField.visible = true
inverseMouseArea.active = true
addressField.forceActiveFocus()
}
}
}
}
DefaultTextField
{
id: addressField
property bool first: true
visible: false
anchors.verticalCenter: parent.verticalCenter
width: parent.width
onTextChanged: {
if (styleData.row > -1 && stateAccounts[styleData.row])
{
stateAccounts[styleData.row].name = text
var index = comboMiner.currentIndex
comboMiner.model = stateAccounts
comboMiner.currentIndex = index
}
if (first)
{
addressField.cursorPosition = 0
first = false
}
}
text: {
return styleData.value
}
Keys.onEnterPressed: {
hide()
}
Keys.onReturnPressed: {
hide()
}
function hide()
{
labelUser.visible = true
labelUser.parent.visible = true
addressField.visible = false
labelUser.text = addressField.text
inverseMouseArea.active = false
}
InverseMouseArea
{
id: inverseMouseArea
anchors.fill: parent
active: false
onClickedOutside: {
parent.hide()
}
}
}
}
Ether {
anchors.verticalCenter: parent.verticalCenter
inputWidth: 100
Layout.minimumWidth: 210
edit: true
displayFormattedValue: false
value: {
if (stateAccounts[styleData.row])
return stateAccounts[styleData.row].balance
}
displayUnitSelection: true
Component.onCompleted: {
formatInput()
}
}
DisableInput
{
anchors.verticalCenter: parent.verticalCenter
id: addressCopy
Layout.preferredWidth: 150
tooltip: qsTr("Copy User Address to Clipboard")
DefaultButton {
width: 35
height: parent.height
anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.right
anchors.leftMargin: 5
tooltip: qsTr("Delete Account")
onClicked: if (stateAccounts.length > 1) { deleteAccountMsg.open() }
enabled: accountsView.model.count > 1
Image {
width: 25
height: 25
anchors.centerIn: parent
source: "qrc:/qml/img/[email protected]"
}
}
}
Rectangle
{
Layout.preferredWidth: 85
}
}
}
}
}
rowDelegate: Rectangle {
color: styleData.alternate ? "transparent" : "#f0f0f0"
height: 60
}
}
}
NewAccount
{
id: newAddressWin
onAccepted:
{
accountsModel.append(ac)
stateAccounts.push(ac)
clientModel.addAccount(ac.secret);
projectModel.saveProject()
}
}
ColumnLayout {
DefaultLabel {
Layout.preferredWidth: 50
text: qsTr("Miner")
}
DefaultCombobox {
id: comboMiner
textRole: "name"
Layout.fillWidth: true
rootItem: modalStateDialog
}
}
}
Row {
id: validationRow
anchors.bottom: parent.bottom
layoutDirection: Qt.RightToLeft
width: parent.width
anchors.right: parent.right
spacing: 10
height: 40
DefaultButton {
anchors.top: parent.top
text: qsTr("Cancel")
onClicked: close()
}
DefaultButton {
anchors.top: parent.top
text: qsTr("OK")
onClicked: {
close()
accepted()
}
}
}
}
}