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 <QQmlContext>
|
||||
#include <QQuickWindow>
|
||||
#include <QQmlFileSelector>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
@ -87,7 +86,6 @@ void AppletQuickItemPrivate::init()
|
||||
PackageUrlInterceptor *interceptor = new PackageUrlInterceptor(qmlObject->engine(), KPackage::Package());
|
||||
interceptor->setForcePlasmaStyle(true);
|
||||
qmlObject->engine()->setUrlInterceptor(interceptor);
|
||||
new QQmlFileSelector(qmlObject->engine(), qmlObject->engine());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include <QQmlEngine>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QFileSelector>
|
||||
#include <QStandardPaths>
|
||||
#include <QRegularExpression>
|
||||
|
||||
@ -37,22 +38,32 @@ namespace PlasmaQuick
|
||||
|
||||
class PackageUrlInterceptorPrivate {
|
||||
public:
|
||||
PackageUrlInterceptorPrivate(QQmlEngine *engine, const KPackage::Package &p)
|
||||
: package(p),
|
||||
PackageUrlInterceptorPrivate(QQmlEngine *engine, PackageUrlInterceptor *interceptor, const KPackage::Package &p)
|
||||
: q(interceptor),
|
||||
package(p),
|
||||
engine(engine)
|
||||
{
|
||||
selector = new QFileSelector;
|
||||
}
|
||||
|
||||
~PackageUrlInterceptorPrivate()
|
||||
{
|
||||
engine->setUrlInterceptor(nullptr);
|
||||
delete selector;
|
||||
}
|
||||
|
||||
PackageUrlInterceptor *q;
|
||||
KPackage::Package package;
|
||||
QStringList allowedPaths;
|
||||
QQmlEngine *engine;
|
||||
QFileSelector *selector;
|
||||
bool forcePlasmaStyle = false;
|
||||
};
|
||||
|
||||
|
||||
PackageUrlInterceptor::PackageUrlInterceptor(QQmlEngine *engine, const KPackage::Package &p)
|
||||
: QQmlAbstractUrlInterceptor(),
|
||||
d(new PackageUrlInterceptorPrivate(engine, p))
|
||||
d(new PackageUrlInterceptorPrivate(engine, this, p))
|
||||
{
|
||||
//d->allowedPaths << d->engine->importPathList();
|
||||
}
|
||||
@ -91,14 +102,18 @@ QUrl PackageUrlInterceptor::intercept(const QUrl &path, QQmlAbstractUrlIntercept
|
||||
{
|
||||
//qDebug() << "Intercepted URL:" << path << type;
|
||||
|
||||
//we assume we never rewritten qml/qmldir files
|
||||
if (path.path().endsWith(QLatin1String("qml")) || path.path().endsWith(QStringLiteral("qmldir"))
|
||||
|| path.path().endsWith(QLatin1String("/inline"))) {
|
||||
// Don't intercept qmldir files, to prevent double interception
|
||||
if (path.path().endsWith(QStringLiteral("qmldir"))) {
|
||||
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()));
|
||||
QRegularExpression match(QStringLiteral("/ui/(.*)"));
|
||||
|
||||
// TODO KF6: Kill this hack
|
||||
QString plainPath = path.toString();
|
||||
if (plainPath.contains(match)) {
|
||||
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")) &&
|
||||
QFile::exists(QStringLiteral(":") + 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;
|
||||
// This deprecated code path doesn't support selectors
|
||||
return QUrl(rewritten);
|
||||
}
|
||||
return path;
|
||||
return d->selector->select(path);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user