qml_container.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. This file is part of go-ethereum
  3. go-ethereum is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. go-ethereum is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. /**
  15. * @authors
  16. * Jeffrey Wilcke <i@jev.io>
  17. */
  18. package main
  19. import (
  20. "runtime"
  21. "github.com/ethereum/go-ethereum/core/types"
  22. "github.com/ethereum/go-ethereum/common"
  23. "github.com/ethereum/go-ethereum/xeth"
  24. "github.com/obscuren/qml"
  25. )
  26. type QmlApplication struct {
  27. win *qml.Window
  28. engine *qml.Engine
  29. lib *UiLib
  30. path string
  31. }
  32. func NewQmlApplication(path string, lib *UiLib) *QmlApplication {
  33. engine := qml.NewEngine()
  34. return &QmlApplication{engine: engine, path: path, lib: lib}
  35. }
  36. func (app *QmlApplication) Create() error {
  37. path := string(app.path)
  38. // For some reason for windows we get /c:/path/to/something, windows doesn't like the first slash but is fine with the others so we are removing it
  39. if app.path[0] == '/' && runtime.GOOS == "windows" {
  40. path = app.path[1:]
  41. }
  42. component, err := app.engine.LoadFile(path)
  43. if err != nil {
  44. guilogger.Warnln(err)
  45. }
  46. app.win = component.CreateWindow(nil)
  47. return nil
  48. }
  49. func (app *QmlApplication) Destroy() {
  50. app.engine.Destroy()
  51. }
  52. func (app *QmlApplication) NewWatcher(quitChan chan bool) {
  53. }
  54. // Events
  55. func (app *QmlApplication) NewBlock(block *types.Block) {
  56. pblock := &xeth.Block{Number: int(block.NumberU64()), Hash: common.Bytes2Hex(block.Hash())}
  57. app.win.Call("onNewBlockCb", pblock)
  58. }
  59. // Getters
  60. func (app *QmlApplication) Engine() *qml.Engine {
  61. return app.engine
  62. }
  63. func (app *QmlApplication) Window() *qml.Window {
  64. return app.win
  65. }
  66. func (app *QmlApplication) Post(data string, s int) {}