Browse Source

qwebconnector is not being recreated

cl-refactor
Marek Kotewicz 10 years ago
parent
commit
98159091f4
  1. 22
      alethzero/MainWin.cpp
  2. 1
      alethzero/MainWin.h
  3. 16
      libqethereum/QEthereum.cpp
  4. 10
      libqethereum/QEthereum.h
  5. 20
      third/MainWin.cpp
  6. 3
      third/MainWin.h

22
alethzero/MainWin.cpp

@ -84,6 +84,12 @@ static QString fromRaw(dev::h256 _n, unsigned* _inc = nullptr)
return QString();
}
static std::vector<dev::KeyPair> keysAsVector(QList<dev::KeyPair> const& keys)
{
auto list = keys.toStdList();
return {std::begin(list), std::end(list)};
}
Address c_config = Address("661005d2720d855f1d9976f88bb10c1a3398c77f");
Main::Main(QWidget *parent) :
@ -133,20 +139,21 @@ Main::Main(QWidget *parent) :
m_webThree.reset(new WebThreeDirect(string("AlethZero/v") + dev::Version + "/" DEV_QUOTED(ETH_BUILD_TYPE) "/" DEV_QUOTED(ETH_BUILD_PLATFORM), getDataDir() + "/AlethZero", false, {"eth", "shh"}));
m_qwebConnector = new QWebThreeConnector();
m_server = unique_ptr<WebThreeStubServer>(new WebThreeStubServer(m_qwebConnector, *web3(), keysAsVector(owned())));
m_server->StartListening();
connect(ui->webView, &QWebView::loadStarted, [this]()
{
// NOTE: no need to delete as QETH_INSTALL_JS_NAMESPACE adopts it.
m_qweb = new QWebThree(this);
auto qweb = m_qweb;
m_qwebConnector->setQWeb(qweb);
QWebSettings::globalSettings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);
QWebFrame* f = ui->webView->page()->mainFrame();
f->disconnect(SIGNAL(javaScriptWindowObjectCleared()));
auto list = owned().toStdList();
m_server = unique_ptr<WebThreeStubServer>(new WebThreeStubServer(new QWebThreeConnector(qweb), *web3(), {std::begin(list), std::end(list)}));
m_server->StartListening();
connect(f, &QWebFrame::javaScriptWindowObjectCleared, QETH_INSTALL_JS_NAMESPACE(f, this, qweb));
});
@ -1126,10 +1133,7 @@ void Main::ourAccountsRowsMoved()
m_myKeys = myKeys;
if (m_server.get())
{
auto list = owned().toStdList();
m_server->setAccounts({std::begin(list), std::end(list)});
}
m_server->setAccounts(keysAsVector(owned()));
}
void Main::on_inject_triggered()

1
alethzero/MainWin.h

@ -249,5 +249,6 @@ private:
bool m_logChanged = true;
std::unique_ptr<WebThreeStubServer> m_server;
QWebThreeConnector* m_qwebConnector = nullptr;
QWebThree* m_qweb = nullptr;
};

16
libqethereum/QEthereum.cpp

@ -149,7 +149,7 @@ void QWebThree::onDataProcessed(QString _json, QString _addInfo)
response(formatOutput(f));
}
QWebThreeConnector::QWebThreeConnector(QWebThree* _q): m_qweb(_q)
QWebThreeConnector::QWebThreeConnector()
{
}
@ -158,10 +158,24 @@ QWebThreeConnector::~QWebThreeConnector()
StopListening();
}
void QWebThreeConnector::setQWeb(QWebThree* _q)
{
m_qweb = _q;
if (m_isListening)
{
StopListening();
StartListening();
}
}
bool QWebThreeConnector::StartListening()
{
m_isListening = true;
if (m_qweb)
{
connect(m_qweb, SIGNAL(processData(QString, QString)), this, SLOT(onProcessData(QString, QString)));
connect(this, SIGNAL(dataProcessed(QString, QString)), m_qweb, SLOT(onDataProcessed(QString, QString)));
}
return true;
}

10
libqethereum/QEthereum.h

@ -57,13 +57,14 @@ class QWebThreeConnector: public QObject, public jsonrpc::AbstractServerConnecto
Q_OBJECT
public:
QWebThreeConnector(QWebThree* _q);
QWebThreeConnector();
virtual ~QWebThreeConnector();
void setQWeb(QWebThree *_q);
virtual bool StartListening();
virtual bool StopListening();
bool virtual SendResponse(std::string const& _response, void* _addInfo = NULL);
virtual bool SendResponse(std::string const& _response, void* _addInfo = NULL);
public slots:
void onProcessData(QString const& _json, QString const& _addInfo);
@ -72,7 +73,8 @@ signals:
void dataProcessed(QString const& _json, QString const& _addInfo);
private:
QWebThree* m_qweb;
QWebThree* m_qweb = nullptr;
bool m_isListening;
};
#define QETH_INSTALL_JS_NAMESPACE(_frame, _env, qweb) [_frame, _env, qweb]() \

20
third/MainWin.cpp

@ -73,6 +73,11 @@ static QString fromRaw(dev::h256 _n, unsigned* _inc = nullptr)
return QString();
}
static std::vector<dev::KeyPair> keysAsVector(QList<dev::KeyPair> const& keys)
{
auto list = keys.toStdList();
return {std::begin(list), std::end(list)};
}
Address c_config = Address("661005d2720d855f1d9976f88bb10c1a3398c77f");
@ -103,19 +108,19 @@ Main::Main(QWidget *parent) :
m_web3.reset(new WebThreeDirect("Third", getDataDir() + "/Third", false, {"eth", "shh"}));
m_web3->connect(Host::pocHost());
m_qwebConnector = new QWebThreeConnector();
m_server = unique_ptr<WebThreeStubServer>(new WebThreeStubServer(m_qwebConnector, *web3(), keysAsVector(owned())));
m_server->StartListening();
connect(ui->webView, &QWebView::loadStarted, [this]()
{
// NOTE: no need to delete as QETH_INSTALL_JS_NAMESPACE adopts it.
m_qweb = new QWebThree(this);
auto qweb = m_qweb;
m_qwebConnector->setQWeb(qweb);
QWebFrame* f = ui->webView->page()->mainFrame();
f->disconnect(SIGNAL(javaScriptWindowObjectCleared()));
auto list = owned().toStdList();
m_server = auto_ptr<WebThreeStubServer>(new WebThreeStubServer(new QWebThreeConnector(qweb), *web3(), {std::begin(list), std::end(list)}));
m_server->StartListening();
connect(f, &QWebFrame::javaScriptWindowObjectCleared, QETH_INSTALL_JS_NAMESPACE(f, this, qweb));
});
@ -543,10 +548,7 @@ void Main::ourAccountsRowsMoved()
m_myKeys = myKeys;
if (m_server.get())
{
auto list = owned().toStdList();
m_server->setAccounts({std::begin(list), std::end(list)});
}
m_server->setAccounts(keysAsVector(owned()));
}
void Main::on_ourAccounts_doubleClicked()

3
third/MainWin.h

@ -133,6 +133,7 @@ private:
QNetworkAccessManager m_webCtrl;
std::auto_ptr<WebThreeStubServer> m_server;
std::unique_ptr<WebThreeStubServer> m_server;
QWebThreeConnector* m_qwebConnector = nullptr;
QWebThree* m_qweb = nullptr;
};

Loading…
Cancel
Save