Commit 63d8dc77 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

Fix qml image caching

Don't provide two disjoint qnam factories that fight each other.

BUG: 401700
parent 9db0919d
...@@ -16,6 +16,7 @@ add_executable(plasma-discover ${plasma_discover_SRCS} ...@@ -16,6 +16,7 @@ add_executable(plasma-discover ${plasma_discover_SRCS}
PaginateModel.cpp PaginateModel.cpp
UnityLauncher.cpp UnityLauncher.cpp
ReadFile.cpp ReadFile.cpp
CachedNetworkAccessManager.cpp
resources.qrc resources.qrc
assets.qrc assets.qrc
......
...@@ -27,9 +27,10 @@ ...@@ -27,9 +27,10 @@
#include <QStorageInfo> #include <QStorageInfo>
CachedNetworkAccessManager::CachedNetworkAccessManager(const QString &path, QObject *parent) CachedNetworkAccessManager::CachedNetworkAccessManager(const QString &path, QObject *parent)
: QNetworkAccessManager(parent) : KIO::AccessManager(parent)
{ {
const QString cacheDir = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + QLatin1Char('/') + path; const QString cacheDir = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + QLatin1Char('/') + path;
qDebug() << "wooooooooo" << cacheDir;
QNetworkDiskCache *cache = new QNetworkDiskCache(this); QNetworkDiskCache *cache = new QNetworkDiskCache(this);
QStorageInfo storageInfo(cacheDir); QStorageInfo storageInfo(cacheDir);
cache->setCacheDirectory(cacheDir); cache->setCacheDirectory(cacheDir);
......
...@@ -22,20 +22,20 @@ ...@@ -22,20 +22,20 @@
#ifndef CACHEDNETWORKACCESSMANAGER_H #ifndef CACHEDNETWORKACCESSMANAGER_H
#define CACHEDNETWORKACCESSMANAGER_H #define CACHEDNETWORKACCESSMANAGER_H
#include "discovercommon_export.h"
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
#include <QQmlNetworkAccessManagerFactory> #include <QQmlNetworkAccessManagerFactory>
#include <KIO/AccessManager>
class DISCOVERCOMMON_EXPORT CachedNetworkAccessManager : public QNetworkAccessManager class CachedNetworkAccessManager : public KIO::AccessManager
{ {
Q_OBJECT
public: public:
explicit CachedNetworkAccessManager(const QString &path, QObject *parent = nullptr); explicit CachedNetworkAccessManager(const QString &path, QObject *parent = nullptr);
virtual QNetworkReply * createRequest(Operation op, const QNetworkRequest &request, QIODevice *outgoingData = nullptr) override; virtual QNetworkReply * createRequest(Operation op, const QNetworkRequest &request, QIODevice *outgoingData = nullptr) override;
}; };
class DISCOVERCOMMON_EXPORT CachedNetworkAccessManagerFactory : public QQmlNetworkAccessManagerFactory class CachedNetworkAccessManagerFactory : public QQmlNetworkAccessManagerFactory
{ {
virtual QNetworkAccessManager * create(QObject *parent) override; virtual QNetworkAccessManager * create(QObject *parent) override;
}; };
......
...@@ -52,7 +52,6 @@ ...@@ -52,7 +52,6 @@
#include <KSharedConfig> #include <KSharedConfig>
#include <KConfigGroup> #include <KConfigGroup>
#include <KStandardAction> #include <KStandardAction>
#include <KIO/AccessManager>
#include <kcoreaddons_version.h> #include <kcoreaddons_version.h>
// #include <KSwitchLanguageDialog> // #include <KSwitchLanguageDialog>
...@@ -82,17 +81,6 @@ public: ...@@ -82,17 +81,6 @@ public:
} }
}; };
class KIOAccessManagerFactory : public QQmlNetworkAccessManagerFactory
{
public:
KIOAccessManagerFactory() = default;
~KIOAccessManagerFactory() = default;
QNetworkAccessManager *create(QObject *parent) override
{
return new KIO::AccessManager(parent);
}
};
DiscoverObject::DiscoverObject(CompactMode mode) DiscoverObject::DiscoverObject(CompactMode mode)
: QObject() : QObject()
, m_engine(new QQmlApplicationEngine) , m_engine(new QQmlApplicationEngine)
...@@ -104,7 +92,7 @@ DiscoverObject::DiscoverObject(CompactMode mode) ...@@ -104,7 +92,7 @@ DiscoverObject::DiscoverObject(CompactMode mode)
auto factory = m_engine->networkAccessManagerFactory(); auto factory = m_engine->networkAccessManagerFactory();
m_engine->setNetworkAccessManagerFactory(nullptr); m_engine->setNetworkAccessManagerFactory(nullptr);
delete factory; delete factory;
m_engine->setNetworkAccessManagerFactory(new KIOAccessManagerFactory()); m_engine->setNetworkAccessManagerFactory(m_networkAccessManagerFactory.data());
qmlRegisterType<UnityLauncher>("org.kde.discover.app", 1, 0, "UnityLauncher"); qmlRegisterType<UnityLauncher>("org.kde.discover.app", 1, 0, "UnityLauncher");
qmlRegisterType<PaginateModel>("org.kde.discover.app", 1, 0, "PaginateModel"); qmlRegisterType<PaginateModel>("org.kde.discover.app", 1, 0, "PaginateModel");
...@@ -128,9 +116,6 @@ DiscoverObject::DiscoverObject(CompactMode mode) ...@@ -128,9 +116,6 @@ DiscoverObject::DiscoverObject(CompactMode mode)
plugin->initializeEngine(m_engine, uri); plugin->initializeEngine(m_engine, uri);
plugin->registerTypes(uri); plugin->registerTypes(uri);
//Here we set up a cache for the screenshots
delete m_engine->networkAccessManagerFactory();
m_engine->setNetworkAccessManagerFactory(m_networkAccessManagerFactory.data());
m_engine->rootContext()->setContextProperty(QStringLiteral("app"), this); m_engine->rootContext()->setContextProperty(QStringLiteral("app"), this);
m_engine->rootContext()->setContextProperty(QStringLiteral("discoverAboutData"), QVariant::fromValue(KAboutData::applicationData())); m_engine->rootContext()->setContextProperty(QStringLiteral("discoverAboutData"), QVariant::fromValue(KAboutData::applicationData()));
......
...@@ -29,7 +29,6 @@ set(discovercommon_SRCS ...@@ -29,7 +29,6 @@ set(discovercommon_SRCS
resources/AbstractBackendUpdater.cpp resources/AbstractBackendUpdater.cpp
resources/AbstractSourcesBackend.cpp resources/AbstractSourcesBackend.cpp
resources/StoredResultsStream.cpp resources/StoredResultsStream.cpp
CachedNetworkAccessManager.cpp
ActionsModel.cpp ActionsModel.cpp
DiscoverBackendsFactory.cpp DiscoverBackendsFactory.cpp
ScreenshotsModel.cpp ScreenshotsModel.cpp
......
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