This repository has been archived by the owner on Jul 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
gui.go
249 lines (192 loc) · 9.7 KB
/
gui.go
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
// Copyright 2017-2018 DERO Project. All rights reserved.
// Use of this source code in any form is governed by GPL 3 license.
// license can be found in the LICENSE file.
// GPG: 0F39 E425 8C65 3947 702A 8234 08B2 0360 A03A 9DE8
//
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// use this command to create logo ico for windows
// convert images/dero-front-logo.png -define icon:auto-resize=16,48,64,128,256 -compress zip logo.ico
// use mingw windres i686-w64-mingw32-windres icon.rc -o icon_windows_386.syso
// use mingw windres x86_64-w64-mingw32-windres icon.rc -o icon_windows_amd64.syso
package main
import (
"fmt"
"log"
"os"
"runtime"
"sync"
"github.com/therecipe/qt/core"
"github.com/therecipe/qt/gui"
"github.com/therecipe/qt/qml"
"github.com/therecipe/qt/quickcontrols2"
)
import "github.com/docopt/docopt-go"
import "github.com/deroproject/derosuite/config"
import "github.com/deroproject/derosuite/globals"
import "github.com/deroproject/derosuite/walletapi"
var command_line string = `dero-wallet-gui
DERO Wallet gui: A secure, private blockchain with smart-contracts
Usage:
dero-wallet-gui [--help] [--version] [--debug] [--testnet] [--noopengl] [--vmmode]
dero-wallet-gui -h | --help
dero-wallet-gui --version
Options:
-h --help Show this screen.
--version Show version.
--debug Debug mode enabled, print log messages
--testnet Enable testnet mode
--noopengl Enable minimal UI using software rendering
--vmmode Enable minimal UI using software rendering`
type CtxObject struct {
core.QObject
walletptr *walletapi.Wallet
_ string `property:"version"`
_ func() `constructor:"init"`
remote_server string `property:"remote_server"` // remote server
_ bool `property:"wallet_online"` // remote server
_ func(string) `signal:"setwalletonline,auto"` // used to set wallet online
_ func() `signal:"setwalletoffline,auto"` // used to set wallet offline
_ bool `property:"wallet_valid"` // is wallet valid and has been successfully opened
_ string `property:"wallet_address"` // wallet address
_ string `property:"someString"`
_ string `property:"initerr"` // used to track error when initially opening or creating database
_ func(string) `signal:"checkpassword,auto"` // used to check password
_ func(string, string) `signal:"setpassword,auto"` // used to set new password
// property related to to outgoing tx
_ string `property:"tx_hex"` // wallet address
_ string `property:"txid_hex"` // wallet address
_ string `property:"tx_total"`
_ string `property:"tx_transfer_amount"`
_ string `property:"tx_change"`
_ string `property:"tx_fees"`
_ string `property:"tx_relayed"`
_ func(string, string, string) `signal:"build_tx,auto"` // used to build up tx
_ func(string) `signal:"relay_tx,auto"` // used to relay tx
_ string `property:"seed"` // seed in localised language
_ func(string) `signal:"seed_language,auto"` // used to request seed in language
_ func(string, string) `signal:"openwallet,auto"` // used to openwallet
_ func(string, string) `signal:"createnewwallet,auto"` // used to openwallet
_ func(string, string, string) `signal:"recoverusingseedwords,auto"` // used to recover using seed words
_ func(string, string, string) `signal:"recoverusingkey,auto"` // used to recoverkey
_ func() `signal:"closewallet,auto"` // used to closewallet
height int64 `property:"height"` // wallet height
topoheight int64 `property:"topoheight"` // wallet topoheight
nwheight int64 `property:"nwheight"` // network height
nwtopoheight int64 `property:"nwtopoheight"` // network topoheight
_ string `property:"height_str"` // height localised string
_ string `property:"topoheight_str"` // topoheight localised string
_ string `property:"total_balance"` // wallet total balance
_ string `property:"unlocked_balance"` // wallet unlocked balance
_ string `property:"locked_balance"` // network locked balance
_ func() `signal:"clicked,auto"`
_ func(string) `signal:"sendString,auto"`
_ func(string) `signal:"addressVerify,auto"` // used to verify address
_ bool `property:"addressverified"` // is address verfied
_ bool `property:"addressintegrated"` // is address integrated
_ string `property:"addressipaymentid"` // integrated payment ID in hex form
_ func(string) `signal:"paymentidVerify,auto"` // used to verify payment id
_ bool `property:"paymentidverified"` // is payment id verfied
_ func(string) `signal:"amountVerify,auto"` // used to verify amount
_ bool `property:"amountverified"` // is amount verified
_ func() `signal:"genintegratedaddress,auto"` // used to verify amount
_ string `property:"integrated_32_address"` // integrated i32 address
_ string `property:"integrated_32_address_paymentid"` // integrated i32 address
_ string `property:"integrated_8_address"` // integrated i8 address
_ string `property:"integrated_8_address_paymentid"` // integrated i32 address
_ func(bool, bool, bool, int64) `signal:"reloadhistory,auto"` // used to reload history, available,in,out
_ []string `property:"historyListHeight"`
_ []string `property:"historyListTopoHeight"`
_ []string `property:"historyListTXID"`
_ []string `property:"historyListAmount"`
_ []string `property:"historyListPaymentID"`
_ []string `property:"historyListStatus"`
_ []string `property:"historyListUnlockTime"`
_ []string `property:"historyListOutDetails"` // contains json string
sync.Mutex
}
var count int
func (t *CtxObject) init() {
global_object = t // capture reference to original object
/*
var err error
global_object.walletptr ,err = walletapi.Open_Encrypted_Wallet("/tmp/tmp2.db", "")
if err != nil {
fmt.Printf("Wallet opened successfully")
}
addr := global_object.walletptr.GetAddress()
global_object.SetWallet_address(addr.String())
global_object.SetWallet_valid(true) // mark wallet as valid
*/
global_object.SetWallet_valid(false)
t.SetVersion(Version.String())
t.SetSomeString(fmt.Sprintf("%d times", count))
}
func (t *CtxObject) clicked() {
t.SetSomeString(fmt.Sprintf("%d times", count))
count++
fmt.Printf("clicked qml button\n")
}
func (t *CtxObject) sendString(a string) {
fmt.Println("sendString:", a)
}
var global_object *CtxObject
var global_gui *gui.QGuiApplication
func main() {
var err error
globals.Arguments, err = docopt.Parse(command_line, nil, true, "DERO atlantis wallet : work in progress", false)
//globals.Arguments, err = docopt.ParseArgs(command_line, os.Args[1:], "DERO daemon : work in progress")
if err != nil {
log.Fatalf("Error while parsing options err: %s\n", err)
}
globals.Init_rlog()
// parse arguments and setup testnet mainnet
globals.Initialize() // setup network and proxy
//globals.Logger.Infof("") // a dummy write is required to fully activate logrus
// all screen output must go through the readline
//globals.Logger.Out = l.Stdout()
if globals.Arguments["--noopengl"].(bool) == true || globals.Arguments["--vmmode"].(bool) == true { // setup software rendering if requested
os.Setenv("QT_QUICK_BACKEND", "software")
}
//QT_QUICK_BACKEND=software
globals.Logger.Infof("Arguments %+v", globals.Arguments)
globals.Logger.Infof("DERO GUI Wallet : %s This version is under heavy development, use it for testing/evaluations purpose only", Version.String())
globals.Logger.Infof("DERO Wallet API : %s This version is under heavy development, use it for testing/evaluations purpose only", config.Version.String())
globals.Logger.Infof("Copyright 2017-2018 DERO Project. All rights reserved.")
globals.Logger.Infof("OS:%s ARCH:%s GOMAXPROCS:%d", runtime.GOOS, runtime.GOARCH, runtime.GOMAXPROCS(0))
globals.Logger.Infof("Wallet in %s mode", globals.Config.Name)
core.QCoreApplication_SetApplicationName("DERO-WALLET-GUI")
core.QCoreApplication_SetOrganizationName("DERO PROJECT")
core.QCoreApplication_SetAttribute(core.Qt__AA_EnableHighDpiScaling, true)
guiptr := gui.NewQGuiApplication(len(os.Args), os.Args)
_ = guiptr
//guiptr.SetWindowIcon(gui.NewQIcon5("copy.svg"))
// guiptr.SetWindowIcon(gui.NewQIcon5(":/images/copy.svg"))
guiptr.SetWindowIcon(gui.NewQIcon5(":/images/dero-front-logo.png"))
/*var (
settings = core.NewQSettings5(nil)
style = quickcontrols2.QQuickStyle_Name()
)
if style != "" {
settings.SetValue("style", core.NewQVariant14(style))
} else {
quickcontrols2.QQuickStyle_SetStyle(settings.Value("style", core.NewQVariant14("")).ToString())
}*/
go update_heights_balances() // handle wallet in another goroutine
// use the material style
// the other inbuild styles are:
// Default, Fusion, Imagine, Universal
quickcontrols2.QQuickStyle_SetStyle("Material")
var engine = qml.NewQQmlApplicationEngine(nil)
engine.RootContext().SetContextProperty("ctxObject", NewCtxObject(nil))
engine.Load(core.NewQUrl3("qrc:/main.qml", 0))
gui.QGuiApplication_Exec()
}