qml_app.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package ethui
  2. import (
  3. "github.com/ethereum/eth-go/ethchain"
  4. "github.com/ethereum/eth-go/ethpub"
  5. "github.com/ethereum/eth-go/ethutil"
  6. "github.com/go-qml/qml"
  7. )
  8. type QmlApplication struct {
  9. win *qml.Window
  10. engine *qml.Engine
  11. lib *UiLib
  12. path string
  13. }
  14. func NewQmlApplication(path string, lib *UiLib) *QmlApplication {
  15. engine := qml.NewEngine()
  16. return &QmlApplication{engine: engine, path: path, lib: lib}
  17. }
  18. func (app *QmlApplication) Create() error {
  19. component, err := app.engine.LoadFile(app.path)
  20. if err != nil {
  21. logger.Warnln(err)
  22. }
  23. app.win = component.CreateWindow(nil)
  24. return nil
  25. }
  26. func (app *QmlApplication) Destroy() {
  27. app.engine.Destroy()
  28. }
  29. func (app *QmlApplication) NewWatcher(quitChan chan bool) {
  30. }
  31. // Events
  32. func (app *QmlApplication) NewBlock(block *ethchain.Block) {
  33. pblock := &ethpub.PBlock{Number: int(block.BlockInfo().Number), Hash: ethutil.Bytes2Hex(block.Hash())}
  34. app.win.Call("onNewBlockCb", pblock)
  35. }
  36. func (app *QmlApplication) ObjectChanged(stateObject *ethchain.StateObject) {
  37. app.win.Call("onObjectChangeCb", ethpub.NewPStateObject(stateObject))
  38. }
  39. func (app *QmlApplication) StorageChanged(storageObject *ethchain.StorageState) {
  40. app.win.Call("onStorageChangeCb", ethpub.NewPStorageState(storageObject))
  41. }
  42. // Getters
  43. func (app *QmlApplication) Engine() *qml.Engine {
  44. return app.engine
  45. }
  46. func (app *QmlApplication) Window() *qml.Window {
  47. return app.win
  48. }