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}
PaginateModel.cpp
UnityLauncher.cpp
ReadFile.cpp
CachedNetworkAccessManager.cpp
resources.qrc
assets.qrc
......
......@@ -27,9 +27,10 @@
#include <QStorageInfo>
CachedNetworkAccessManager::CachedNetworkAccessManager(const QString &path, QObject *parent)
: QNetworkAccessManager(parent)
: KIO::AccessManager(parent)
{
const QString cacheDir = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + QLatin1Char('/') + path;
qDebug() << "wooooooooo" << cacheDir;
QNetworkDiskCache *cache = new QNetworkDiskCache(this);
QStorageInfo storageInfo(cacheDir);
cache->setCacheDirectory(cacheDir);
......
......@@ -22,20 +22,20 @@
#ifndef CACHEDNETWORKACCESSMANAGER_H
#define CACHEDNETWORKACCESSMANAGER_H
#include "discovercommon_export.h"
#include <QNetworkAccessManager>
#include <QQmlNetworkAccessManagerFactory>
#include <KIO/AccessManager>
class DISCOVERCOMMON_EXPORT CachedNetworkAccessManager : public QNetworkAccessManager
class CachedNetworkAccessManager : public KIO::AccessManager
{
Q_OBJECT
public:
explicit CachedNetworkAccessManager(const QString &path, QObject *parent = nullptr);
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;
};
......
......@@ -52,7 +52,6 @@
#include <KSharedConfig>
#include <KConfigGroup>
#include <KStandardAction>
#include <KIO/AccessManager>
#include <kcoreaddons_version.h>
// #include <KSwitchLanguageDialog>
......@@ -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)
: QObject()
, m_engine(new QQmlApplicationEngine)
......@@ -104,7 +92,7 @@ DiscoverObject::DiscoverObject(CompactMode mode)
auto factory = m_engine->networkAccessManagerFactory();
m_engine->setNetworkAccessManagerFactory(nullptr);
delete factory;
m_engine->setNetworkAccessManagerFactory(new KIOAccessManagerFactory());
m_engine->setNetworkAccessManagerFactory(m_networkAccessManagerFactory.data());
qmlRegisterType<UnityLauncher>("org.kde.discover.app", 1, 0, "UnityLauncher");
qmlRegisterType<PaginateModel>("org.kde.discover.app", 1, 0, "PaginateModel");
......@@ -128,9 +116,6 @@ DiscoverObject::DiscoverObject(CompactMode mode)
plugin->initializeEngine(m_engine, 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("discoverAboutData"), QVariant::fromValue(KAboutData::applicationData()));
......
......@@ -29,7 +29,6 @@ set(discovercommon_SRCS
resources/AbstractBackendUpdater.cpp
resources/AbstractSourcesBackend.cpp
resources/StoredResultsStream.cpp
CachedNetworkAccessManager.cpp
ActionsModel.cpp
DiscoverBackendsFactory.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