Browse Source

Merge pull request #2468 from chriseth/changeUrlOnSiteChange

AlethZero: Change the URL when the page changes.
cl-refactor
Gav Wood 10 years ago
parent
commit
367e7a11e7
  1. 13
      alethzero/DappHost.cpp
  2. 6
      alethzero/DappHost.h
  3. 5
      alethzero/MainWin.cpp

13
alethzero/DappHost.cpp

@ -28,7 +28,11 @@
using namespace dev;
DappHost::DappHost(int _port, int _threads):
m_port(_port), m_threads(_threads), m_running(false), m_daemon(nullptr)
m_port(_port),
m_url(QString("http://localhost:%1/").arg(m_port)),
m_threads(_threads),
m_running(false),
m_daemon(nullptr)
{
startListening();
}
@ -135,5 +139,10 @@ QUrl DappHost::hostDapp(Dapp&& _dapp)
for (ManifestEntry const& entry: m_dapp.manifest.entries)
m_entriesByPath[QString::fromStdString(entry.path)] = &entry;
return QUrl(QString("http://localhost:%1/").arg(m_port));
return m_url;
}
bool DappHost::servesUrl(QUrl const& _url) const
{
return m_url == _url || m_url.isParentOf(_url);
}

6
alethzero/DappHost.h

@ -40,6 +40,9 @@ public:
/// Load and host a dapp. Previsous dapp in discarded. Synchronous
QUrl hostDapp(Dapp&& _dapp);
/// @returns true if the given url is served from this DappHost.
bool servesUrl(QUrl const& _url) const;
private:
void startListening();
void stopListening();
@ -48,7 +51,8 @@ private:
void sendResponse(std::string const& _url, MHD_Connection* _connection);
static int callback(void* _cls, MHD_Connection* _connection, char const* _url, char const* _method, char const* _version, char const* _uploadData, size_t* _uploadDataSize, void** _conCls);
int m_port;
int const m_port;
QUrl const m_url;
int m_threads;
bool m_running;
MHD_Daemon* m_daemon;

5
alethzero/MainWin.cpp

@ -232,6 +232,11 @@ Main::Main(QWidget *parent) :
{
ui->tabWidget->setTabText(0, ui->webView->title());
});
connect(ui->webView, &QWebEngineView::urlChanged, [=](QUrl const& _url)
{
if (!m_dappHost->servesUrl(_url))
ui->urlEdit->setText(_url.toString());
});
m_dappHost.reset(new DappHost(8081));
m_dappLoader = new DappLoader(this, web3(), getNameReg());

Loading…
Cancel
Save