aboutsummaryrefslogtreecommitdiffstats
path: root/ethereal/html_container.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-07-02 06:13:50 +0800
committerobscuren <geffobscura@gmail.com>2014-07-02 06:13:50 +0800
commitc4f9151c67b1481490978a9dca0599b3e92680d5 (patch)
treef02199cf5a2f87595937c5f8c94bda343347fa9f /ethereal/html_container.go
parent283532137713d20ca82d264bd105cf7cb0e47b65 (diff)
downloadgo-tangerine-c4f9151c67b1481490978a9dca0599b3e92680d5.tar
go-tangerine-c4f9151c67b1481490978a9dca0599b3e92680d5.tar.gz
go-tangerine-c4f9151c67b1481490978a9dca0599b3e92680d5.tar.bz2
go-tangerine-c4f9151c67b1481490978a9dca0599b3e92680d5.tar.lz
go-tangerine-c4f9151c67b1481490978a9dca0599b3e92680d5.tar.xz
go-tangerine-c4f9151c67b1481490978a9dca0599b3e92680d5.tar.zst
go-tangerine-c4f9151c67b1481490978a9dca0599b3e92680d5.zip
Moved files
Diffstat (limited to 'ethereal/html_container.go')
-rw-r--r--ethereal/html_container.go133
1 files changed, 133 insertions, 0 deletions
diff --git a/ethereal/html_container.go b/ethereal/html_container.go
new file mode 100644
index 000000000..1e835eebc
--- /dev/null
+++ b/ethereal/html_container.go
@@ -0,0 +1,133 @@
+package main
+
+import (
+ "errors"
+ "github.com/ethereum/eth-go/ethchain"
+ "github.com/ethereum/eth-go/ethpub"
+ "github.com/ethereum/eth-go/ethutil"
+ "github.com/go-qml/qml"
+ "github.com/howeyc/fsnotify"
+ "io/ioutil"
+ "log"
+ "net/url"
+ "os"
+ "path"
+ "path/filepath"
+)
+
+type HtmlApplication struct {
+ win *qml.Window
+ webView qml.Object
+ engine *qml.Engine
+ lib *UiLib
+ path string
+ watcher *fsnotify.Watcher
+}
+
+func NewHtmlApplication(path string, lib *UiLib) *HtmlApplication {
+ engine := qml.NewEngine()
+
+ return &HtmlApplication{engine: engine, lib: lib, path: path}
+
+}
+
+func (app *HtmlApplication) Create() error {
+ component, err := app.engine.LoadFile(app.lib.AssetPath("qml/webapp.qml"))
+ if err != nil {
+ return err
+ }
+
+ if filepath.Ext(app.path) == "eth" {
+ return errors.New("Ethereum package not yet supported")
+
+ // TODO
+ ethutil.OpenPackage(app.path)
+ }
+
+ win := component.CreateWindow(nil)
+ win.Set("url", app.path)
+ webView := win.ObjectByName("webView")
+
+ app.win = win
+ app.webView = webView
+
+ return nil
+}
+
+func (app *HtmlApplication) RootFolder() string {
+ folder, err := url.Parse(app.path)
+ if err != nil {
+ return ""
+ }
+ return path.Dir(folder.RequestURI())
+}
+func (app *HtmlApplication) RecursiveFolders() []os.FileInfo {
+ files, _ := ioutil.ReadDir(app.RootFolder())
+ var folders []os.FileInfo
+ for _, file := range files {
+ if file.IsDir() {
+ folders = append(folders, file)
+ }
+ }
+ return folders
+}
+
+func (app *HtmlApplication) NewWatcher(quitChan chan bool) {
+ var err error
+
+ app.watcher, err = fsnotify.NewWatcher()
+ if err != nil {
+ return
+ }
+ err = app.watcher.Watch(app.RootFolder())
+ if err != nil {
+ log.Fatal(err)
+ }
+ for _, folder := range app.RecursiveFolders() {
+ fullPath := app.RootFolder() + "/" + folder.Name()
+ app.watcher.Watch(fullPath)
+ }
+
+ go func() {
+ out:
+ for {
+ select {
+ case <-quitChan:
+ app.watcher.Close()
+ break out
+ case <-app.watcher.Event:
+ //logger.Debugln("Got event:", ev)
+ app.webView.Call("reload")
+ case err := <-app.watcher.Error:
+ // TODO: Do something here
+ logger.Infoln("Watcher error:", err)
+ }
+ }
+ }()
+
+}
+
+func (app *HtmlApplication) Engine() *qml.Engine {
+ return app.engine
+}
+
+func (app *HtmlApplication) Window() *qml.Window {
+ return app.win
+}
+
+func (app *HtmlApplication) NewBlock(block *ethchain.Block) {
+ b := &ethpub.PBlock{Number: int(block.BlockInfo().Number), Hash: ethutil.Bytes2Hex(block.Hash())}
+ app.webView.Call("onNewBlockCb", b)
+}
+
+func (app *HtmlApplication) ObjectChanged(stateObject *ethchain.StateObject) {
+ app.webView.Call("onObjectChangeCb", ethpub.NewPStateObject(stateObject))
+}
+
+func (app *HtmlApplication) StorageChanged(storageObject *ethchain.StorageState) {
+ app.webView.Call("onStorageChangeCb", ethpub.NewPStorageState(storageObject))
+}
+
+func (app *HtmlApplication) Destroy() {
+ app.engine.Destroy()
+}