use the file selector in the interceptor
we still need at least for kf5 lifetime to use PackageUrlInterceptor so use the selector there this fixes a regression where old plasmoids with javascript in /code/ did break
This commit is contained in:
parent
7a301be293
commit
1da69dd751
@ -27,7 +27,6 @@
|
|||||||
#include <QQmlProperty>
|
#include <QQmlProperty>
|
||||||
#include <QQmlContext>
|
#include <QQmlContext>
|
||||||
#include <QQuickWindow>
|
#include <QQuickWindow>
|
||||||
#include <QQmlFileSelector>
|
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
@ -87,7 +86,6 @@ void AppletQuickItemPrivate::init()
|
|||||||
PackageUrlInterceptor *interceptor = new PackageUrlInterceptor(qmlObject->engine(), KPackage::Package());
|
PackageUrlInterceptor *interceptor = new PackageUrlInterceptor(qmlObject->engine(), KPackage::Package());
|
||||||
interceptor->setForcePlasmaStyle(true);
|
interceptor->setForcePlasmaStyle(true);
|
||||||
qmlObject->engine()->setUrlInterceptor(interceptor);
|
qmlObject->engine()->setUrlInterceptor(interceptor);
|
||||||
new QQmlFileSelector(qmlObject->engine(), qmlObject->engine());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include <QQmlEngine>
|
#include <QQmlEngine>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
|
#include <QFileSelector>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
|
|
||||||
@ -37,22 +38,32 @@ namespace PlasmaQuick
|
|||||||
|
|
||||||
class PackageUrlInterceptorPrivate {
|
class PackageUrlInterceptorPrivate {
|
||||||
public:
|
public:
|
||||||
PackageUrlInterceptorPrivate(QQmlEngine *engine, const KPackage::Package &p)
|
PackageUrlInterceptorPrivate(QQmlEngine *engine, PackageUrlInterceptor *interceptor, const KPackage::Package &p)
|
||||||
: package(p),
|
: q(interceptor),
|
||||||
|
package(p),
|
||||||
engine(engine)
|
engine(engine)
|
||||||
{
|
{
|
||||||
|
selector = new QFileSelector;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
~PackageUrlInterceptorPrivate()
|
||||||
|
{
|
||||||
|
engine->setUrlInterceptor(nullptr);
|
||||||
|
delete selector;
|
||||||
|
}
|
||||||
|
|
||||||
|
PackageUrlInterceptor *q;
|
||||||
KPackage::Package package;
|
KPackage::Package package;
|
||||||
QStringList allowedPaths;
|
QStringList allowedPaths;
|
||||||
QQmlEngine *engine;
|
QQmlEngine *engine;
|
||||||
|
QFileSelector *selector;
|
||||||
bool forcePlasmaStyle = false;
|
bool forcePlasmaStyle = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
PackageUrlInterceptor::PackageUrlInterceptor(QQmlEngine *engine, const KPackage::Package &p)
|
PackageUrlInterceptor::PackageUrlInterceptor(QQmlEngine *engine, const KPackage::Package &p)
|
||||||
: QQmlAbstractUrlInterceptor(),
|
: QQmlAbstractUrlInterceptor(),
|
||||||
d(new PackageUrlInterceptorPrivate(engine, p))
|
d(new PackageUrlInterceptorPrivate(engine, this, p))
|
||||||
{
|
{
|
||||||
//d->allowedPaths << d->engine->importPathList();
|
//d->allowedPaths << d->engine->importPathList();
|
||||||
}
|
}
|
||||||
@ -91,14 +102,18 @@ QUrl PackageUrlInterceptor::intercept(const QUrl &path, QQmlAbstractUrlIntercept
|
|||||||
{
|
{
|
||||||
//qDebug() << "Intercepted URL:" << path << type;
|
//qDebug() << "Intercepted URL:" << path << type;
|
||||||
|
|
||||||
//we assume we never rewritten qml/qmldir files
|
// Don't intercept qmldir files, to prevent double interception
|
||||||
if (path.path().endsWith(QLatin1String("qml")) || path.path().endsWith(QStringLiteral("qmldir"))
|
if (path.path().endsWith(QStringLiteral("qmldir"))) {
|
||||||
|| path.path().endsWith(QLatin1String("/inline"))) {
|
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
// We assume we never rewritten qml/qmldir files
|
||||||
|
if (path.path().endsWith(QLatin1String("qml"))
|
||||||
|
|| path.path().endsWith(QLatin1String("/inline"))) {
|
||||||
|
return d->selector->select(path);
|
||||||
|
}
|
||||||
const QString prefix = QString::fromUtf8(prefixForType(type, path.path()));
|
const QString prefix = QString::fromUtf8(prefixForType(type, path.path()));
|
||||||
QRegularExpression match(QStringLiteral("/ui/(.*)"));
|
QRegularExpression match(QStringLiteral("/ui/(.*)"));
|
||||||
|
// TODO KF6: Kill this hack
|
||||||
QString plainPath = path.toString();
|
QString plainPath = path.toString();
|
||||||
if (plainPath.contains(match)) {
|
if (plainPath.contains(match)) {
|
||||||
QString rewritten = plainPath.replace(match, QStringLiteral("/%1/\\1").arg(prefix));
|
QString rewritten = plainPath.replace(match, QStringLiteral("/%1/\\1").arg(prefix));
|
||||||
@ -107,12 +122,13 @@ QUrl PackageUrlInterceptor::intercept(const QUrl &path, QQmlAbstractUrlIntercept
|
|||||||
if (!(rewritten.contains(QLatin1String("qrc")) &&
|
if (!(rewritten.contains(QLatin1String("qrc")) &&
|
||||||
QFile::exists(QStringLiteral(":") + QUrl(rewritten).path())) &&
|
QFile::exists(QStringLiteral(":") + QUrl(rewritten).path())) &&
|
||||||
!QFile::exists(QUrl(rewritten).path())) {
|
!QFile::exists(QUrl(rewritten).path())) {
|
||||||
return path;
|
return d->selector->select(path);
|
||||||
}
|
}
|
||||||
qWarning()<<"Warning: all files used by qml by the plasmoid should be in ui/. The file in the path" << rewritten << "was expected at" <<path;
|
qWarning()<<"Warning: all files used by qml by the plasmoid should be in ui/. The file in the path" << rewritten << "was expected at" <<path;
|
||||||
|
// This deprecated code path doesn't support selectors
|
||||||
return QUrl(rewritten);
|
return QUrl(rewritten);
|
||||||
}
|
}
|
||||||
return path;
|
return d->selector->select(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user