Browse Source

Nicer settings integration.

cl-refactor
Gav Wood 10 years ago
parent
commit
5e708830a7
  1. 21
      alethzero/LogPanel.cpp
  2. 4
      alethzero/LogPanel.h
  3. 8
      alethzero/MainFace.h
  4. 42
      alethzero/MainWin.cpp
  5. 5
      alethzero/MainWin.h

21
alethzero/LogPanel.cpp

@ -53,15 +53,8 @@ LogPanel::LogPanel(MainFace* _m):
m_logHistory.append(filterOutTerminal(QString::fromStdString(s)) + "\n");
m_logChanged = true;
m_logLock.unlock();
// ui->log->addItem(QString::fromStdString(s));
};
// TODO: refactor
{
QSettings s("ethereum", "alethzero");
m_ui->verbosity->setValue(s.value("verbosity", 1).toInt());
}
on_verbosity_valueChanged();
}
@ -70,12 +63,16 @@ LogPanel::~LogPanel()
// Must do this here since otherwise m_ethereum'll be deleted (and therefore clearWatches() called by the destructor)
// *after* the client is dead.
g_logPost = simpleDebugOut;
}
// TODO: refactor
{
QSettings s("ethereum", "alethzero");
s.setValue("verbosity", m_ui->verbosity->value());
}
void LogPanel::readSettings(QSettings const& _s)
{
m_ui->verbosity->setValue(_s.value("verbosity", 1).toInt());
}
void LogPanel::writeSettings(QSettings& _s)
{
_s.setValue("verbosity", m_ui->verbosity->value());
}
void LogPanel::timerEvent(QTimerEvent*)

4
alethzero/LogPanel.h

@ -49,7 +49,9 @@ private slots:
void on_verbosity_valueChanged();
private:
void timerEvent(QTimerEvent*);
void timerEvent(QTimerEvent*) override;
void readSettings(QSettings const&) override;
void writeSettings(QSettings&) override;
Ui::LogPanel* m_ui;

8
alethzero/MainFace.h

@ -31,6 +31,8 @@
#include <libevm/ExtVMFace.h>
#include "Context.h"
class QSettings;
namespace dev
{
@ -64,6 +66,10 @@ public:
virtual unsigned installWatch(dev::eth::LogFilter const& _tf, WatchHandler const& _f) = 0;
virtual unsigned installWatch(dev::h256 const& _tf, WatchHandler const& _f) = 0;
protected:
template <class F> void forEach(F const& _f) { for (auto const& p: m_plugins) _f(p.second); }
std::shared_ptr<Plugin> takePlugin(std::string const& _name) { auto it = m_plugins.find(_name); std::shared_ptr<Plugin> ret; if (it != m_plugins.end()) { ret = it->second; m_plugins.erase(it); } return ret; }
private:
std::unordered_map<std::string, std::shared_ptr<Plugin>> m_plugins;
};
@ -85,6 +91,8 @@ public:
void addAction(QAction* _a);
virtual void onAllChange() {}
virtual void readSettings(QSettings const&) {}
virtual void writeSettings(QSettings&) {}
private:
MainFace* m_main = nullptr;

42
alethzero/MainWin.cpp

@ -288,18 +288,23 @@ Main::Main(QWidget* _parent):
QSettings s("ethereum", "alethzero");
if (s.value("splashMessage", true).toBool())
{
QMessageBox::information(this, "Here Be Dragons!", "This is proof-of-concept software. The project as a whole is not even at the alpha-testing stage. It is here to show you, if you have a technical bent, the sort of thing that might be possible down the line.\nPlease don't blame us if it does something unexpected or if you're underwhelmed with the user-experience. We have great plans for it in terms of UX down the line but right now we just want to get the groundwork sorted. We welcome contributions, be they in code, testing or documentation!\nAfter you close this message it won't appear again.");
QMessageBox::information(this, "Here Be Dragons!", "This is beta software: it is not yet at the release stage.\nPlease don't blame us if it does something unexpected or if you're underwhelmed with the user-experience. We have great plans for it in terms of UX down the line but right now we just want to make sure everything works roughly as expected. We welcome contributions, be they in code, testing or documentation!\nAfter you close this message it won't appear again.");
s.setValue("splashMessage", false);
}
}
new dev::az::AllAccounts(this);
new dev::az::LogPanel(this);
loadPlugin<dev::az::AllAccounts>();
loadPlugin<dev::az::LogPanel>();
}
Main::~Main()
{
m_httpConnector->StopListening();
// save all settings here so we don't have to explicitly finalise plugins.
// NOTE: as soon as plugin finalisation means anything more than saving settings, this will
// need to be rethought into something more like:
// forEach([&](shared_ptr<Plugin> const& p){ finalisePlugin(p.get()); });
writeSettings();
}
@ -752,6 +757,11 @@ void Main::writeSettings()
s.setValue("identities", b);
}
forEach([&](std::shared_ptr<Plugin> p)
{
p->writeSettings(s);
});
s.setValue("askPrice", QString::fromStdString(toString(static_cast<TrivialGasPricer*>(ethereum()->gasPricer().get())->ask())));
s.setValue("bidPrice", QString::fromStdString(toString(static_cast<TrivialGasPricer*>(ethereum()->gasPricer().get())->bid())));
s.setValue("upnp", ui->upnp->isChecked());
@ -762,7 +772,6 @@ void Main::writeSettings()
s.setValue("paranoia", ui->paranoia->isChecked());
s.setValue("natSpec", ui->natSpec->isChecked());
s.setValue("showAll", ui->showAll->isChecked());
s.setValue("showAllAccounts", ui->showAllAccounts->isChecked());
s.setValue("clientName", ui->clientName->text());
s.setValue("idealPeers", ui->idealPeers->value());
s.setValue("listenIP", ui->listenIP->text());
@ -847,6 +856,11 @@ void Main::readSettings(bool _skipGeometry)
}
}
forEach([&](std::shared_ptr<Plugin> p)
{
p->readSettings(s);
});
static_cast<TrivialGasPricer*>(ethereum()->gasPricer().get())->setAsk(u256(s.value("askPrice", "500000000000").toString().toStdString()));
static_cast<TrivialGasPricer*>(ethereum()->gasPricer().get())->setBid(u256(s.value("bidPrice", "500000000000").toString().toStdString()));
@ -861,7 +875,6 @@ void Main::readSettings(bool _skipGeometry)
ui->paranoia->setChecked(s.value("paranoia", false).toBool());
ui->natSpec->setChecked(s.value("natSpec", true).toBool());
ui->showAll->setChecked(s.value("showAll", false).toBool());
ui->showAllAccounts->setChecked(s.value("showAllAccounts", false).toBool());
ui->clientName->setText(s.value("clientName", "").toString());
if (ui->clientName->text().isEmpty())
ui->clientName->setText(QInputDialog::getText(nullptr, "Enter identity", "Enter a name that will identify you on the peer network"));
@ -2272,3 +2285,22 @@ void Main::pageLoaded(QByteArray const& _content, QString const& _mimeType, QUrl
{
ui->webView->page()->setContent(_content, _mimeType, _uri);
}
void Main::initPlugin(Plugin* _p)
{
QSettings s("ethereum", "alethzero");
_p->readSettings(s);
}
void Main::finalisePlugin(Plugin* _p)
{
QSettings s("ethereum", "alethzero");
_p->writeSettings(s);
}
void Main::unloadPlugin(string const& _name)
{
shared_ptr<Plugin> p = takePlugin(_name);
if (p)
finalisePlugin(p.get());
}

5
alethzero/MainWin.h

@ -199,6 +199,11 @@ signals:
void poll();
private:
template <class P> void loadPlugin() { dev::az::Plugin* p = new P(this); initPlugin(p); }
void initPlugin(dev::az::Plugin* _p);
void finalisePlugin(dev::az::Plugin* _p);
void unloadPlugin(std::string const& _name);
void debugDumpState(int _add);
dev::p2p::NetworkPreferences netPrefs() const;

Loading…
Cancel
Save