Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit ff25b3df authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

Make it easier to reuse the CachedNetworkAccessManager

parent f67710cd
......@@ -26,9 +26,16 @@
#include <QStandardPaths>
#include <QStorageInfo>
CachedNetworkAccessManager::CachedNetworkAccessManager(QObject *parent)
CachedNetworkAccessManager::CachedNetworkAccessManager(const QString &path, QObject *parent)
: QNetworkAccessManager(parent)
{ }
{
const QString cacheDir = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + QLatin1Char('/') + path;
QNetworkDiskCache *cache = new QNetworkDiskCache(this);
QStorageInfo storageInfo(cacheDir);
cache->setCacheDirectory(cacheDir);
cache->setMaximumCacheSize(storageInfo.bytesTotal() / 1000);
setCache(cache);
}
QNetworkReply * CachedNetworkAccessManager::createRequest(Operation op, const QNetworkRequest &request, QIODevice *outgoingData)
{
......@@ -39,13 +46,6 @@ QNetworkReply * CachedNetworkAccessManager::createRequest(Operation op, const QN
QNetworkAccessManager * CachedNetworkAccessManagerFactory::create(QObject *parent)
{
const QString cacheDir = QStringLiteral("%1/images").arg(QStandardPaths::writableLocation(QStandardPaths::CacheLocation));
CachedNetworkAccessManager *ret = new CachedNetworkAccessManager(parent);
QNetworkDiskCache *cache = new QNetworkDiskCache(ret);
QStorageInfo storageInfo(cacheDir);
cache->setCacheDirectory(cacheDir);
cache->setMaximumCacheSize(storageInfo.bytesTotal() / 1000);
ret->setCache(cache);
return ret;
return new CachedNetworkAccessManager(QStringLiteral("images"), parent);
}
......@@ -30,7 +30,7 @@
class DISCOVERCOMMON_EXPORT CachedNetworkAccessManager : public QNetworkAccessManager
{
public:
explicit CachedNetworkAccessManager(QObject *parent = 0);
explicit CachedNetworkAccessManager(const QString &path, QObject *parent = nullptr);
virtual QNetworkReply * createRequest(Operation op, const QNetworkRequest &request, QIODevice *outgoingData = nullptr) override;
};
......
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