qml_container.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // Copyright (c) 2013-2014, Jeffrey Wilcke. All rights reserved.
  2. //
  3. // This library is free software; you can redistribute it and/or
  4. // modify it under the terms of the GNU General Public
  5. // License as published by the Free Software Foundation; either
  6. // version 2.1 of the License, or (at your option) any later version.
  7. //
  8. // This library is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. // General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this library; if not, write to the Free Software
  15. // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  16. // MA 02110-1301 USA
  17. package main
  18. import (
  19. "fmt"
  20. "runtime"
  21. "github.com/ethereum/go-ethereum/core/types"
  22. "github.com/ethereum/go-ethereum/ethutil"
  23. "github.com/ethereum/go-ethereum/state"
  24. "github.com/ethereum/go-ethereum/xeth"
  25. "gopkg.in/qml.v1"
  26. )
  27. type QmlApplication struct {
  28. win *qml.Window
  29. engine *qml.Engine
  30. lib *UiLib
  31. path string
  32. }
  33. func NewQmlApplication(path string, lib *UiLib) *QmlApplication {
  34. engine := qml.NewEngine()
  35. return &QmlApplication{engine: engine, path: path, lib: lib}
  36. }
  37. func (app *QmlApplication) Create() error {
  38. path := string(app.path)
  39. // 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
  40. if app.path[0] == '/' && runtime.GOOS == "windows" {
  41. path = app.path[1:]
  42. }
  43. component, err := app.engine.LoadFile(path)
  44. if err != nil {
  45. guilogger.Warnln(err)
  46. }
  47. app.win = component.CreateWindow(nil)
  48. return nil
  49. }
  50. func (app *QmlApplication) Destroy() {
  51. app.engine.Destroy()
  52. }
  53. func (app *QmlApplication) NewWatcher(quitChan chan bool) {
  54. }
  55. // Events
  56. func (app *QmlApplication) NewBlock(block *types.Block) {
  57. pblock := &xeth.JSBlock{Number: int(block.BlockInfo().Number), Hash: ethutil.Bytes2Hex(block.Hash())}
  58. app.win.Call("onNewBlockCb", pblock)
  59. }
  60. func (self *QmlApplication) Messages(msgs state.Messages, id string) {
  61. fmt.Println("IMPLEMENT QML APPLICATION MESSAGES METHOD")
  62. }
  63. // Getters
  64. func (app *QmlApplication) Engine() *qml.Engine {
  65. return app.engine
  66. }
  67. func (app *QmlApplication) Window() *qml.Window {
  68. return app.win
  69. }
  70. func (app *QmlApplication) Post(data string, s int) {}