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
{
QSettings settings(this->extensionsSettingsFilePath(), QSettings::IniFormat);
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(
bool qSlicerExtensionsManagerModel::downloadAndInstallExtension(const QString& extensionId)
{
Q_D(qSlicerExtensionsManagerModel);
QString error;
if (!d->checkExtensionSettingsPermissions(error))
{
d->critical(error);
return false;
}
qSlicerExtensionDownloadTask* const task = d->downloadExtension(extensionId);
if (!task)
{
......@@ -1212,7 +1212,6 @@ void qSlicerExtensionsManagerModel::onInstallDownloadFinished(
const QString& extensionName = task->extensionName();
const QString& archiveName = task->archiveName();
QTemporaryFile file(QString("%1/%2.XXXXXX").arg(QDir::tempPath(), archiveName));
if (!file.open())
{
......@@ -1221,7 +1220,6 @@ void qSlicerExtensionsManagerModel::onInstallDownloadFinished(
}
file.write(reply->readAll());
file.close();
const ExtensionMetadataType& extensionMetadata =
this->filterExtensionMetadata(task->metadata());
this->installExtension(extensionName, extensionMetadata, file.fileName());
......@@ -1240,7 +1238,6 @@ bool qSlicerExtensionsManagerModel::installExtension(
QString("Failed to list extension archive '%1'").arg(archiveFile));
return false;
}
for (size_t n = 0; n < archiveContents.size(); ++n)
{
const std::string& s = archiveContents[n];
......
......@@ -29,6 +29,7 @@
#include <QWebView>
#else
#include <QWebEngineView>
#include <QWebChannel>
#endif
// CTK includes
......@@ -73,7 +74,9 @@ qSlicerExtensionsInstallWidgetPrivate::qSlicerExtensionsInstallWidgetPrivate(qSl
// --------------------------------------------------------------------------
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))
url.setQueryItems(
#else
......@@ -85,6 +88,8 @@ QUrl qSlicerExtensionsInstallWidgetPrivate::extensionsListUrl()
<< QPair<QString, QString>("os", this->SlicerOs)
<< QPair<QString, QString>("arch", this->SlicerArch)
<< 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))
url.setQuery(urlQuery);
#endif
......@@ -132,7 +137,7 @@ void qSlicerExtensionsInstallWidgetPrivate::setFailurePage(const QStringList& er
" <!-- It is originally covered by http://mozilla.org/MPL/2.0/ license -->"
" <!-- MPL 2.0 license is compatible with Slicer (BSD-like) license -->"
" <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'>"
" <ul>"
"%1"
......@@ -179,7 +184,6 @@ qSlicerExtensionsManagerModel* qSlicerExtensionsInstallWidget::extensionsManager
void qSlicerExtensionsInstallWidget::setExtensionsManagerModel(qSlicerExtensionsManagerModel* model)
{
Q_D(qSlicerExtensionsInstallWidget);
if (this->extensionsManagerModel() == model)
{
return;
......@@ -278,7 +282,6 @@ void qSlicerExtensionsInstallWidget::onExtensionCancelledScheduleForUninstall(co
void qSlicerExtensionsInstallWidget::onSlicerRequirementsChanged(const QString& revision,const QString& os,const QString& arch)
{
Q_D(qSlicerExtensionsInstallWidget);
this->setSlicerRevision(revision);
this->setSlicerOs(os);
this->setSlicerArch(arch);
......@@ -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));
}
// --------------------------------------------------------------------------
void qSlicerExtensionsInstallWidget::onLoadStarted()
{
Q_D(qSlicerExtensionsInstallWidget);
this->Superclass::onLoadStarted();
this->initJavascript();
}
// --------------------------------------------------------------------------
void qSlicerExtensionsInstallWidget::initJavascript()
{
......@@ -319,7 +330,11 @@ void qSlicerExtensionsInstallWidget::initJavascript()
this->webView()->page()->mainFrame()->addToJavaScriptWindowObject(
"extensions_install_widget", this);
#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
}
......
......@@ -82,7 +82,7 @@ protected slots:
virtual void initJavascript();
virtual void onLoadFinished(bool ok);
virtual void onLinkClicked(const QUrl& url);
virtual void onLoadStarted();
protected:
QScopedPointer<qSlicerExtensionsInstallWidgetPrivate> d_ptr;
......
......@@ -373,7 +373,6 @@ void qSlicerExtensionsManagerWidget::onManageUrlChanged(const QUrl& newUrl)
void qSlicerExtensionsManagerWidget::onInstallUrlChanged(const QUrl& newUrl)
{
Q_D(qSlicerExtensionsManagerWidget);
if (newUrl.path().endsWith("/slicerappstore"))
{
d->toolsWidget->InstallSearchBox->setEnabled(true);
......@@ -419,8 +418,9 @@ void qSlicerExtensionsManagerWidget::timerEvent(QTimerEvent* e)
"midas.slicerappstore.search = " + jsQuote(searchText) + ";"
"midas.slicerappstore.applyFilter();");
#else
qDebug() << "qSlicerExtensionsManagerWidget::timerEvent - "
"Not implemented with Qt5";
d->ExtensionsInstallWidget->webView()->page()->runJavaScript(
"midas.slicerappstore.search = " + jsQuote(searchText) + ";"
"midas.slicerappstore.applyFilter();");
#endif
d->lastSearchText = searchText;
}
......
......@@ -30,6 +30,12 @@
#include <QWebView>
#else
#include <QWebEngineView>
#include <QWebChannel>
#include <QWebEngineScript>
#include <QWebEnginePage>
#include <QWebEngineProfile>
#include <qwebenginescriptcollection.h>
#include <QFile>
#endif
// QtCore includes
......@@ -64,6 +70,7 @@ public:
QWebView* WebView;
#else
QWebEngineView* WebView;
QWebChannel* WebChannel;
#endif
};
......@@ -83,6 +90,39 @@ void qSlicerWebWidgetPrivate::init()
this->WebView = new QWebView();
#else
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
this->verticalLayout->insertWidget(0, this->WebView);
......@@ -92,8 +132,6 @@ void qSlicerWebWidgetPrivate::init()
QNetworkAccessManager * networkAccessManager = this->WebView->page()->networkAccessManager();
Q_ASSERT(networkAccessManager);
networkAccessManager->setCookieJar(new qSlicerPersistentCookieJar());
#else
qDebug() << "Support for qSlicerPersistentCookieJar not implemented";
#endif
QObject::connect(this->WebView, SIGNAL(loadStarted()),
......@@ -179,11 +217,23 @@ qSlicerWebWidget::webView()
QString qSlicerWebWidget::evalJS(const QString &js)
{
Q_D(qSlicerWebWidget);
#if (QT_VERSION < QT_VERSION_CHECK(5, 6, 0))
return d->mainFrame()->evaluateJavaScript(js).toString();
#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
}
// --------------------------------------------------------------------------
......
......@@ -620,6 +620,7 @@ else()
list(APPEND Slicer_REQUIRED_QT_MODULES
WebEngine
WebEngineWidgets
WebChannel
)
endif()
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