From 380b3a82049788a649336e8f391729c065237af2 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Sun, 2 Aug 2015 13:54:57 +0100 Subject: [PATCH] Build fixes for plugin stuff. --- alethzero/AllAccounts.cpp | 17 +++++++++-------- alethzero/AllAccounts.h | 2 +- alethzero/MainFace.cpp | 10 +++++++--- alethzero/MainFace.h | 17 ++++++++++++----- alethzero/MainWin.cpp | 2 +- alethzero/MainWin.h | 6 ++---- 6 files changed, 32 insertions(+), 22 deletions(-) diff --git a/alethzero/AllAccounts.cpp b/alethzero/AllAccounts.cpp index d93cd1322..fcb673775 100644 --- a/alethzero/AllAccounts.cpp +++ b/alethzero/AllAccounts.cpp @@ -21,6 +21,7 @@ #include "AllAccounts.h" #include +#include #include #include #include @@ -46,8 +47,8 @@ AllAccounts::~AllAccounts() void AllAccounts::installWatches() { - installWatch(ChainChangedFilter, [=](LocalisedLogEntries const&){ onAllChange(); }); - installWatch(PendingChangedFilter, [=](LocalisedLogEntries const&){ onAllChange(); }); + main()->installWatch(ChainChangedFilter, [=](LocalisedLogEntries const&){ onAllChange(); }); + main()->installWatch(PendingChangedFilter, [=](LocalisedLogEntries const&){ onAllChange(); }); } void AllAccounts::refresh() @@ -64,10 +65,10 @@ void AllAccounts::refresh() bool isContract = (ethereum()->codeHashAt(i) != EmptySHA3); if (!((showContract && isContract) || (showBasic && !isContract))) continue; - string r = render(i); + string r = static_cast(main())->render(i); if (onlyNamed && !(r.find('"') != string::npos || r.substr(0, 2) == "XE")) continue; - (new QListWidgetItem(QString("%2: %1 [%3]").arg(formatBalance(ethereum()->balanceAt(i)).c_str()).arg(QString::fromStdString(r)).arg((unsigned)ethereum()->countAt(i)), ui->accounts)) + (new QListWidgetItem(QString("%2: %1 [%3]").arg(formatBalance(ethereum()->balanceAt(i)).c_str()).arg(QString::fromStdString(r)).arg((unsigned)ethereum()->countAt(i)), m_ui->accounts)) ->setData(Qt::UserRole, QByteArray((char const*)i.data(), Address::size)); } #endif @@ -76,7 +77,7 @@ void AllAccounts::refresh() void AllAccounts::onAllChange() { - ui->refreshAccounts->setEnabled(true); + m_ui->refreshAccounts->setEnabled(true); } void AllAccounts::on_accounts_currentItemChanged() @@ -102,15 +103,15 @@ void AllAccounts::on_accounts_currentItemChanged() { m_ui->accountInfo->appendHtml("Corrupted trie."); } - ui->accountInfo->moveCursor(QTextCursor::Start); + m_ui->accountInfo->moveCursor(QTextCursor::Start); } } void AllAccounts::on_accounts_doubleClicked() { - if (ui->accounts->count()) + if (m_ui->accounts->count()) { - auto hba = ui->accounts->currentItem()->data(Qt::UserRole).toByteArray(); + auto hba = m_ui->accounts->currentItem()->data(Qt::UserRole).toByteArray(); auto h = Address((byte const*)hba.data(), Address::ConstructFromPointer); qApp->clipboard()->setText(QString::fromStdString(toHex(h.asArray()))); } diff --git a/alethzero/AllAccounts.h b/alethzero/AllAccounts.h index e9ded1999..72f97d882 100644 --- a/alethzero/AllAccounts.h +++ b/alethzero/AllAccounts.h @@ -37,7 +37,7 @@ namespace az class AllAccounts: public Plugin { public: - AllAccounts(MainFace* _m): Plugin(_m, "AllAccounts") {} + AllAccounts(MainFace* _m); ~AllAccounts(); private slots: diff --git a/alethzero/MainFace.cpp b/alethzero/MainFace.cpp index 97a615008..45669626b 100644 --- a/alethzero/MainFace.cpp +++ b/alethzero/MainFace.cpp @@ -20,7 +20,7 @@ */ #include "MainFace.h" - +using namespace std; using namespace dev; using namespace az; @@ -31,7 +31,6 @@ Plugin::Plugin(MainFace* _f, std::string const& _name): _f->adoptPlugin(this); } - QDockWidget* Plugin::dock(Qt::DockWidgetArea _area, QString _title) { if (_title.isEmpty()) @@ -46,7 +45,7 @@ QDockWidget* Plugin::dock(Qt::DockWidgetArea _area, QString _title) void Plugin::addToDock(Qt::DockWidgetArea _area, QDockWidget* _dockwidget, Qt::Orientation _orientation) { - m_main->addDockWidget(_area, m_dock, _orientation); + m_main->addDockWidget(_area, _dockwidget, _orientation); } void Plugin::addAction(QAction* _a) @@ -54,6 +53,11 @@ void Plugin::addAction(QAction* _a) m_main->addAction(_a); } +void MainFace::adoptPlugin(Plugin* _p) +{ + m_plugins[_p->name()] = shared_ptr(_p); +} + void MainFace::killPlugins() { m_plugins.clear(); diff --git a/alethzero/MainFace.h b/alethzero/MainFace.h index 2104ea05b..c5ea23798 100644 --- a/alethzero/MainFace.h +++ b/alethzero/MainFace.h @@ -24,16 +24,18 @@ #include #include #include +#include #include #include #include +#include #include "Context.h" namespace dev { -namespace web3 { class WebThreeDirect; } -namespace eth { class Client; } +class WebThreeDirect; +namespace eth { class Client; class LogFilter; } namespace shh { class WhisperHost; } namespace az @@ -41,22 +43,27 @@ namespace az class Plugin; +using WatchHandler = std::function; + class MainFace: public QMainWindow, public Context { public: explicit MainFace(QWidget* _parent = nullptr): QMainWindow(_parent) {} - void adoptPlugin(Plugin* _p) { m_plugins.insert(_p->name(), std::shared_ptr(_p)); } + void adoptPlugin(Plugin* _p); void killPlugins(); void allChange(); // TODO: tidy - all should be references that throw if module unavailable. // TODO: provide a set of available web3 modules. - virtual dev::web3::WebThreeDirect* web3() const = 0; + virtual dev::WebThreeDirect* web3() const = 0; virtual dev::eth::Client* ethereum() const = 0; virtual std::shared_ptr whisper() const = 0; + virtual unsigned installWatch(dev::eth::LogFilter const& _tf, WatchHandler const& _f) = 0; + virtual unsigned installWatch(dev::h256 const& _tf, WatchHandler const& _f) = 0; + private: std::unordered_map> m_plugins; }; @@ -69,7 +76,7 @@ public: std::string const& name() const { return m_name; } - dev::web3::WebThreeDirect* web3() const { return m_main->web3(); } + dev::WebThreeDirect* web3() const { return m_main->web3(); } dev::eth::Client* ethereum() const { return m_main->ethereum(); } std::shared_ptr whisper() const { return m_main->whisper(); } MainFace* main() { return m_main; } diff --git a/alethzero/MainWin.cpp b/alethzero/MainWin.cpp index 72271bcef..3b28cc7b3 100644 --- a/alethzero/MainWin.cpp +++ b/alethzero/MainWin.cpp @@ -418,7 +418,7 @@ unsigned Main::installWatch(LogFilter const& _tf, WatchHandler const& _f) return ret; } -unsigned Main::installWatch(dev::h256 _tf, WatchHandler const& _f) +unsigned Main::installWatch(h256 const& _tf, WatchHandler const& _f) { auto ret = ethereum()->installWatch(_tf, Reaping::Manual); m_handlers[ret] = _f; diff --git a/alethzero/MainWin.h b/alethzero/MainWin.h index f1e11cea6..74352ba9e 100644 --- a/alethzero/MainWin.h +++ b/alethzero/MainWin.h @@ -26,7 +26,6 @@ #endif #include - #include #include #include @@ -132,7 +131,6 @@ private slots: // View void on_refresh_triggered(); void on_showAll_triggered() { refreshBlockChain(); } - void on_showAllAccounts_triggered() { refreshAccounts(); } void on_preview_triggered(); // Account management @@ -221,8 +219,8 @@ private: void setPrivateChain(QString const& _private, bool _forceConfigure = false); - unsigned installWatch(dev::eth::LogFilter const& _tf, WatchHandler const& _f); - unsigned installWatch(dev::h256 _tf, WatchHandler const& _f); + unsigned installWatch(dev::eth::LogFilter const& _tf, WatchHandler const& _f) override; + unsigned installWatch(dev::h256 const& _tf, WatchHandler const& _f) override; void uninstallWatch(unsigned _w); void keysChanged();