From 0057bb4ef6d55b5d580a4e0421526a477ef93de9 Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 19 Feb 2015 11:51:38 +0100 Subject: [PATCH] WIP QT Clipboard --- cmd/mist/assets/qml/main.qml | 1 + cmd/mist/gui.go | 1 + rpc/util.go | 6 +++--- ui/qt/clipboard/capi.hpp | 11 +++++++++++ ui/qt/clipboard/clipboard.cpp | 20 ++++++++++++++++++++ ui/qt/clipboard/clipboard.go | 15 +++++++++++++++ ui/qt/clipboard/clipboard.hpp | 23 +++++++++++++++++++++++ xeth/types.go | 2 +- 8 files changed, 75 insertions(+), 4 deletions(-) create mode 100644 ui/qt/clipboard/capi.hpp create mode 100644 ui/qt/clipboard/clipboard.cpp create mode 100644 ui/qt/clipboard/clipboard.go create mode 100644 ui/qt/clipboard/clipboard.hpp diff --git a/cmd/mist/assets/qml/main.qml b/cmd/mist/assets/qml/main.qml index f9bfd9b8d2..5f7f05d835 100644 --- a/cmd/mist/assets/qml/main.qml +++ b/cmd/mist/assets/qml/main.qml @@ -246,6 +246,7 @@ ApplicationWindow { } } } + } property var blockModel: ListModel { diff --git a/cmd/mist/gui.go b/cmd/mist/gui.go index c9419473ce..1e3efd269f 100644 --- a/cmd/mist/gui.go +++ b/cmd/mist/gui.go @@ -131,6 +131,7 @@ func (gui *Gui) Start(assetPath string) { context.SetVar("gui", gui) context.SetVar("eth", gui.uiLib) context.SetVar("shh", gui.whisper) + //clipboard.SetQMLClipboard(context) win, err := gui.showWallet(context) if err != nil { diff --git a/rpc/util.go b/rpc/util.go index 679d83754d..366e315ac2 100644 --- a/rpc/util.go +++ b/rpc/util.go @@ -80,7 +80,7 @@ type RpcServer interface { type Log struct { Address string `json:"address"` - Topics []string `json:"topics"` + Topic []string `json:"topics"` Data string `json:"data"` } @@ -89,11 +89,11 @@ func toLogs(logs state.Logs) (ls []Log) { for i, log := range logs { var l Log - l.Topics = make([]string, len(log.Topics())) + l.Topic = make([]string, len(log.Topics())) l.Address = toHex(log.Address()) l.Data = toHex(log.Data()) for j, topic := range log.Topics() { - l.Topics[j] = toHex(topic) + l.Topic[j] = toHex(topic) } ls[i] = l } diff --git a/ui/qt/clipboard/capi.hpp b/ui/qt/clipboard/capi.hpp new file mode 100644 index 0000000000..2026134691 --- /dev/null +++ b/ui/qt/clipboard/capi.hpp @@ -0,0 +1,11 @@ +#pragma once + +#include "clipboard.hpp" + +typedef void Clipboard_; + +Clipboard_ *initClipboard() +{ + Clipboard *clipboard = new(Clipboard); + return static_cast(clipboard); +} diff --git a/ui/qt/clipboard/clipboard.cpp b/ui/qt/clipboard/clipboard.cpp new file mode 100644 index 0000000000..192aa7a2b9 --- /dev/null +++ b/ui/qt/clipboard/clipboard.cpp @@ -0,0 +1,20 @@ +#include "clipboard.h" + +#include + +Clipboard::Clipboard() +{ + connect(QApplication::clipboard(), &QClipboard::dataChanged, [this] { emit clipboardChanged();}); +} + +QString Clipboard::get() const +{ + QClipboard *clipboard = QApplication::clipboard(); + return clipboard->text(); +} + +void Clipboard::toClipboard(QString _text) +{ + QClipboard *clipboard = QApplicationion::clipboard(); + clipboard->setText(_text); +} diff --git a/ui/qt/clipboard/clipboard.go b/ui/qt/clipboard/clipboard.go new file mode 100644 index 0000000000..064ee954d0 --- /dev/null +++ b/ui/qt/clipboard/clipboard.go @@ -0,0 +1,15 @@ +package clipboard + +// #cgo CPPFLAGS: -I./ +// #cgo CXXFLAGS: -std=c++0x -pedantic-errors -Wall -fno-strict-aliasing +// #cgo LDFLAGS: -lstdc++ +// #cgo pkg-config: Qt5Quick +// +// #include "capi.hpp" +import "C" + +import "github.com/obscuren/qml" + +func SetQMLClipboard(context *qml.Context) { + context.SetVar("clipboard", (unsafe.Pointer)(C.initClipboard())) +} diff --git a/ui/qt/clipboard/clipboard.hpp b/ui/qt/clipboard/clipboard.hpp new file mode 100644 index 0000000000..1aa213ceb1 --- /dev/null +++ b/ui/qt/clipboard/clipboard.hpp @@ -0,0 +1,23 @@ +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +class Clipboard : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString get READ get WRITE toClipboard NOTIFY clipboardChanged) +public: + Clipboard(); + virtual ~Clipboard(){} + + Q_INVOKABLE void toClipboard(QString _text); + +signals: + void clipboardChanged(); +}; + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/xeth/types.go b/xeth/types.go index a903fccbbf..5b2d160180 100644 --- a/xeth/types.go +++ b/xeth/types.go @@ -150,7 +150,7 @@ type Transaction struct { func NewTx(tx *types.Transaction) *Transaction { hash := toHex(tx.Hash()) receiver := toHex(tx.To()) - if receiver == "0000000000000000000000000000000000000000" { + if len(receiver) == 0 { receiver = toHex(core.AddressFromMessage(tx)) } sender := toHex(tx.From())