Commit 2bc3c735 authored by jcfr's avatar jcfr

ENH: WIP - WebEngine support for extension manager

From: Hina Shah <hina.shah@kitware.com>

git-svn-id: http://svn.slicer.org/Slicer4/trunk@26254 3bd1e089-480b-0410-8dfb-8563597acbee
parent 38d9add4
...@@ -873,6 +873,8 @@ QUrl qSlicerExtensionsManagerModel::serverUrl()const ...@@ -873,6 +873,8 @@ QUrl qSlicerExtensionsManagerModel::serverUrl()const
{ {
QSettings settings(this->extensionsSettingsFilePath(), QSettings::IniFormat); QSettings settings(this->extensionsSettingsFilePath(), QSettings::IniFormat);
return QUrl(settings.value("Extensions/ServerUrl").toString()); return QUrl(settings.value("Extensions/ServerUrl").toString());
//HS Uncomment the following line for debugging and comment above line.
//return QUrl("http://10.171.2.133:8080");
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
...@@ -1167,14 +1169,12 @@ qSlicerExtensionsManagerModelPrivate::downloadExtension( ...@@ -1167,14 +1169,12 @@ qSlicerExtensionsManagerModelPrivate::downloadExtension(
bool qSlicerExtensionsManagerModel::downloadAndInstallExtension(const QString& extensionId) bool qSlicerExtensionsManagerModel::downloadAndInstallExtension(const QString& extensionId)
{ {
Q_D(qSlicerExtensionsManagerModel); Q_D(qSlicerExtensionsManagerModel);
QString error; QString error;
if (!d->checkExtensionSettingsPermissions(error)) if (!d->checkExtensionSettingsPermissions(error))
{ {
d->critical(error); d->critical(error);
return false; return false;
} }
qSlicerExtensionDownloadTask* const task = d->downloadExtension(extensionId); qSlicerExtensionDownloadTask* const task = d->downloadExtension(extensionId);
if (!task) if (!task)
{ {
...@@ -1212,7 +1212,6 @@ void qSlicerExtensionsManagerModel::onInstallDownloadFinished( ...@@ -1212,7 +1212,6 @@ void qSlicerExtensionsManagerModel::onInstallDownloadFinished(
const QString& extensionName = task->extensionName(); const QString& extensionName = task->extensionName();
const QString& archiveName = task->archiveName(); const QString& archiveName = task->archiveName();
QTemporaryFile file(QString("%1/%2.XXXXXX").arg(QDir::tempPath(), archiveName)); QTemporaryFile file(QString("%1/%2.XXXXXX").arg(QDir::tempPath(), archiveName));
if (!file.open()) if (!file.open())
{ {
...@@ -1221,7 +1220,6 @@ void qSlicerExtensionsManagerModel::onInstallDownloadFinished( ...@@ -1221,7 +1220,6 @@ void qSlicerExtensionsManagerModel::onInstallDownloadFinished(
} }
file.write(reply->readAll()); file.write(reply->readAll());
file.close(); file.close();
const ExtensionMetadataType& extensionMetadata = const ExtensionMetadataType& extensionMetadata =
this->filterExtensionMetadata(task->metadata()); this->filterExtensionMetadata(task->metadata());
this->installExtension(extensionName, extensionMetadata, file.fileName()); this->installExtension(extensionName, extensionMetadata, file.fileName());
...@@ -1240,7 +1238,6 @@ bool qSlicerExtensionsManagerModel::installExtension( ...@@ -1240,7 +1238,6 @@ bool qSlicerExtensionsManagerModel::installExtension(
QString("Failed to list extension archive '%1'").arg(archiveFile)); QString("Failed to list extension archive '%1'").arg(archiveFile));
return false; return false;
} }
for (size_t n = 0; n < archiveContents.size(); ++n) for (size_t n = 0; n < archiveContents.size(); ++n)
{ {
const std::string& s = archiveContents[n]; const std::string& s = archiveContents[n];
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include <QWebView> #include <QWebView>
#else #else
#include <QWebEngineView> #include <QWebEngineView>
#include <QWebChannel>
#endif #endif
// CTK includes // CTK includes
...@@ -73,7 +74,9 @@ qSlicerExtensionsInstallWidgetPrivate::qSlicerExtensionsInstallWidgetPrivate(qSl ...@@ -73,7 +74,9 @@ qSlicerExtensionsInstallWidgetPrivate::qSlicerExtensionsInstallWidgetPrivate(qSl
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
QUrl qSlicerExtensionsInstallWidgetPrivate::extensionsListUrl() QUrl qSlicerExtensionsInstallWidgetPrivate::extensionsListUrl()
{ {
QUrl url(this->ExtensionsManagerModel->serverUrlWithExtensionsStorePath()); QUrl url(this->ExtensionsManagerModel->serverUrlWithExtensionsStorePath());
//HS Uncomment the following line for debugging and comment above
//QUrl url("http://10.171.2.133:8080/slicerappstore");
#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0)) #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
url.setQueryItems( url.setQueryItems(
#else #else
...@@ -85,6 +88,8 @@ QUrl qSlicerExtensionsInstallWidgetPrivate::extensionsListUrl() ...@@ -85,6 +88,8 @@ QUrl qSlicerExtensionsInstallWidgetPrivate::extensionsListUrl()
<< QPair<QString, QString>("os", this->SlicerOs) << QPair<QString, QString>("os", this->SlicerOs)
<< QPair<QString, QString>("arch", this->SlicerArch) << QPair<QString, QString>("arch", this->SlicerArch)
<< QPair<QString, QString>("revision", this->SlicerRevision)); << QPair<QString, QString>("revision", this->SlicerRevision));
//HS Uncomment the following line for debugging and comment above
//<< QPair<QString, QString>("revision", "19291"));
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
url.setQuery(urlQuery); url.setQuery(urlQuery);
#endif #endif
...@@ -132,7 +137,7 @@ void qSlicerExtensionsInstallWidgetPrivate::setFailurePage(const QStringList& er ...@@ -132,7 +137,7 @@ void qSlicerExtensionsInstallWidgetPrivate::setFailurePage(const QStringList& er
" <!-- It is originally covered by http://mozilla.org/MPL/2.0/ license -->" " <!-- It is originally covered by http://mozilla.org/MPL/2.0/ license -->"
" <!-- MPL 2.0 license is compatible with Slicer (BSD-like) license -->" " <!-- MPL 2.0 license is compatible with Slicer (BSD-like) license -->"
" <div class='error'>" " <div class='error'>"
" <div id='errorTitle'><h1>Ooop. Extensions can not be installed !</h1></div>" " <div id='errorTitle'><h1>Ooops. Extensions can not be installed !</h1></div>"
" <div id='errorDescription'>" " <div id='errorDescription'>"
" <ul>" " <ul>"
"%1" "%1"
...@@ -179,7 +184,6 @@ qSlicerExtensionsManagerModel* qSlicerExtensionsInstallWidget::extensionsManager ...@@ -179,7 +184,6 @@ qSlicerExtensionsManagerModel* qSlicerExtensionsInstallWidget::extensionsManager
void qSlicerExtensionsInstallWidget::setExtensionsManagerModel(qSlicerExtensionsManagerModel* model) void qSlicerExtensionsInstallWidget::setExtensionsManagerModel(qSlicerExtensionsManagerModel* model)
{ {
Q_D(qSlicerExtensionsInstallWidget); Q_D(qSlicerExtensionsInstallWidget);
if (this->extensionsManagerModel() == model) if (this->extensionsManagerModel() == model)
{ {
return; return;
...@@ -278,7 +282,6 @@ void qSlicerExtensionsInstallWidget::onExtensionCancelledScheduleForUninstall(co ...@@ -278,7 +282,6 @@ void qSlicerExtensionsInstallWidget::onExtensionCancelledScheduleForUninstall(co
void qSlicerExtensionsInstallWidget::onSlicerRequirementsChanged(const QString& revision,const QString& os,const QString& arch) void qSlicerExtensionsInstallWidget::onSlicerRequirementsChanged(const QString& revision,const QString& os,const QString& arch)
{ {
Q_D(qSlicerExtensionsInstallWidget); Q_D(qSlicerExtensionsInstallWidget);
this->setSlicerRevision(revision); this->setSlicerRevision(revision);
this->setSlicerOs(os); this->setSlicerOs(os);
this->setSlicerArch(arch); this->setSlicerArch(arch);
...@@ -307,6 +310,14 @@ void qSlicerExtensionsInstallWidget::onMessageLogged(const QString& text, ctkErr ...@@ -307,6 +310,14 @@ void qSlicerExtensionsInstallWidget::onMessageLogged(const QString& text, ctkErr
this->evalJS(QString("midas.createNotice('%1', %2, '%3')").arg(text).arg(delay).arg(state)); this->evalJS(QString("midas.createNotice('%1', %2, '%3')").arg(text).arg(delay).arg(state));
} }
// --------------------------------------------------------------------------
void qSlicerExtensionsInstallWidget::onLoadStarted()
{
Q_D(qSlicerExtensionsInstallWidget);
this->Superclass::onLoadStarted();
this->initJavascript();
}
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
void qSlicerExtensionsInstallWidget::initJavascript() void qSlicerExtensionsInstallWidget::initJavascript()
{ {
...@@ -319,7 +330,11 @@ void qSlicerExtensionsInstallWidget::initJavascript() ...@@ -319,7 +330,11 @@ void qSlicerExtensionsInstallWidget::initJavascript()
this->webView()->page()->mainFrame()->addToJavaScriptWindowObject( this->webView()->page()->mainFrame()->addToJavaScriptWindowObject(
"extensions_install_widget", this); "extensions_install_widget", this);
#else #else
qDebug() << "qSlicerExtensionsInstallWidget::initJavascript - Not implemented"; this->webView()->page()->webChannel()->registerObject(
"extensions_manager_model", d->ExtensionsManagerModel);
this->webView()->page()->webChannel()->registerObject(
"extensions_install_widget", this);
#endif #endif
} }
......
...@@ -82,7 +82,7 @@ protected slots: ...@@ -82,7 +82,7 @@ protected slots:
virtual void initJavascript(); virtual void initJavascript();
virtual void onLoadFinished(bool ok); virtual void onLoadFinished(bool ok);
virtual void onLinkClicked(const QUrl& url); virtual void onLinkClicked(const QUrl& url);
virtual void onLoadStarted();
protected: protected:
QScopedPointer<qSlicerExtensionsInstallWidgetPrivate> d_ptr; QScopedPointer<qSlicerExtensionsInstallWidgetPrivate> d_ptr;
......
...@@ -373,7 +373,6 @@ void qSlicerExtensionsManagerWidget::onManageUrlChanged(const QUrl& newUrl) ...@@ -373,7 +373,6 @@ void qSlicerExtensionsManagerWidget::onManageUrlChanged(const QUrl& newUrl)
void qSlicerExtensionsManagerWidget::onInstallUrlChanged(const QUrl& newUrl) void qSlicerExtensionsManagerWidget::onInstallUrlChanged(const QUrl& newUrl)
{ {
Q_D(qSlicerExtensionsManagerWidget); Q_D(qSlicerExtensionsManagerWidget);
if (newUrl.path().endsWith("/slicerappstore")) if (newUrl.path().endsWith("/slicerappstore"))
{ {
d->toolsWidget->InstallSearchBox->setEnabled(true); d->toolsWidget->InstallSearchBox->setEnabled(true);
...@@ -419,8 +418,9 @@ void qSlicerExtensionsManagerWidget::timerEvent(QTimerEvent* e) ...@@ -419,8 +418,9 @@ void qSlicerExtensionsManagerWidget::timerEvent(QTimerEvent* e)
"midas.slicerappstore.search = " + jsQuote(searchText) + ";" "midas.slicerappstore.search = " + jsQuote(searchText) + ";"
"midas.slicerappstore.applyFilter();"); "midas.slicerappstore.applyFilter();");
#else #else
qDebug() << "qSlicerExtensionsManagerWidget::timerEvent - " d->ExtensionsInstallWidget->webView()->page()->runJavaScript(
"Not implemented with Qt5"; "midas.slicerappstore.search = " + jsQuote(searchText) + ";"
"midas.slicerappstore.applyFilter();");
#endif #endif
d->lastSearchText = searchText; d->lastSearchText = searchText;
} }
......
...@@ -30,6 +30,12 @@ ...@@ -30,6 +30,12 @@
#include <QWebView> #include <QWebView>
#else #else
#include <QWebEngineView> #include <QWebEngineView>
#include <QWebChannel>
#include <QWebEngineScript>
#include <QWebEnginePage>
#include <QWebEngineProfile>
#include <qwebenginescriptcollection.h>
#include <QFile>
#endif #endif
// QtCore includes // QtCore includes
...@@ -64,6 +70,7 @@ public: ...@@ -64,6 +70,7 @@ public:
QWebView* WebView; QWebView* WebView;
#else #else
QWebEngineView* WebView; QWebEngineView* WebView;
QWebChannel* WebChannel;
#endif #endif
}; };
...@@ -83,6 +90,39 @@ void qSlicerWebWidgetPrivate::init() ...@@ -83,6 +90,39 @@ void qSlicerWebWidgetPrivate::init()
this->WebView = new QWebView(); this->WebView = new QWebView();
#else #else
this->WebView = new QWebEngineView(); this->WebView = new QWebEngineView();
QWebEngineProfile *profile = new QWebEngineProfile("MyWebChannelProfile", q);
QFile webChannelJsFile(":/qtwebchannel/qwebchannel.js");
if (!webChannelJsFile.open(QIODevice::ReadOnly))
{
qDebug() << QString("Couldn't open qwebchannel.js file: %1").arg(webChannelJsFile.errorString());
}
else
{
qDebug() << "OK webEngineProfile";
QByteArray webChannelJs = webChannelJsFile.readAll();
webChannelJs.append(
"\n"
"new QWebChannel(qt.webChannelTransport, function(channel) {"
" window.extensions_install_widget = channel.objects.extensions_install_widget;"
" console.log('From core: ' + extensions_install_widget.slicerOs);"
"});"
);
QWebEngineScript script;
script.setSourceCode(webChannelJs);
script.setName("qwebchannel_appended.js");
script.setWorldId(QWebEngineScript::MainWorld);
script.setInjectionPoint(QWebEngineScript::DocumentCreation);
script.setRunsOnSubFrames(false);
profile->scripts()->insert(script);
}
QWebEnginePage *myPage = new QWebEnginePage(profile, this->WebView);
this->WebView->setPage(myPage);
this->WebChannel = new QWebChannel(this->WebView->page());
this->WebView->page()->setWebChannel(this->WebChannel);
#endif #endif
this->verticalLayout->insertWidget(0, this->WebView); this->verticalLayout->insertWidget(0, this->WebView);
...@@ -92,8 +132,6 @@ void qSlicerWebWidgetPrivate::init() ...@@ -92,8 +132,6 @@ void qSlicerWebWidgetPrivate::init()
QNetworkAccessManager * networkAccessManager = this->WebView->page()->networkAccessManager(); QNetworkAccessManager * networkAccessManager = this->WebView->page()->networkAccessManager();
Q_ASSERT(networkAccessManager); Q_ASSERT(networkAccessManager);
networkAccessManager->setCookieJar(new qSlicerPersistentCookieJar()); networkAccessManager->setCookieJar(new qSlicerPersistentCookieJar());
#else
qDebug() << "Support for qSlicerPersistentCookieJar not implemented";
#endif #endif
QObject::connect(this->WebView, SIGNAL(loadStarted()), QObject::connect(this->WebView, SIGNAL(loadStarted()),
...@@ -179,11 +217,23 @@ qSlicerWebWidget::webView() ...@@ -179,11 +217,23 @@ qSlicerWebWidget::webView()
QString qSlicerWebWidget::evalJS(const QString &js) QString qSlicerWebWidget::evalJS(const QString &js)
{ {
Q_D(qSlicerWebWidget); Q_D(qSlicerWebWidget);
#if (QT_VERSION < QT_VERSION_CHECK(5, 6, 0)) #if (QT_VERSION < QT_VERSION_CHECK(5, 6, 0))
return d->mainFrame()->evaluateJavaScript(js).toString(); return d->mainFrame()->evaluateJavaScript(js).toString();
#else #else
return QString(); // XXX Not implemented // NOTE: Beginning Qt5.7, the call to runJavaScript becomes asynchronous,
// and generally it takes a function lambda which is called once
// the script evaluation is completed. This takes in the result string
// as an argument.
// Since the result of JavaScript evaluation is not used anywhere
// in the code base, the function lambda is not supplied here,
// and an empty string is returned instead.
// When the need arises to use the result string, function lambdas
// and resulting infrastructure will have to be provided.
d->WebView->page()->runJavaScript(js);
return QString();
#endif #endif
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
......
...@@ -620,6 +620,7 @@ else() ...@@ -620,6 +620,7 @@ else()
list(APPEND Slicer_REQUIRED_QT_MODULES list(APPEND Slicer_REQUIRED_QT_MODULES
WebEngine WebEngine
WebEngineWidgets WebEngineWidgets
WebChannel
) )
endif() endif()
if(Slicer_BUILD_EXTENSIONMANAGER_SUPPORT) if(Slicer_BUILD_EXTENSIONMANAGER_SUPPORT)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment