github.com/jonasnick/go-ethereum@v0.7.12-0.20150216215225-22176f05d387/cmd/mist/qml_container.go (about)

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