--- /dev/null
+#include "diskcache.h"
+#include <QtNetwork>
+
+DiskCache::DiskCache(QObject *parent) : QNetworkDiskCache(parent) { }
+
+QIODevice* DiskCache::prepare(const QNetworkCacheMetaData &metaData) {
+ QString mime;
+ foreach (QNetworkCacheMetaData::RawHeader header, metaData.rawHeaders()) {
+ // qDebug() << header.first << header.second;
+ if (header.first.constData() == QLatin1String("Content-Type")) {
+ mime = header.second;
+ break;
+ }
+ }
+
+ if (mime.startsWith(QLatin1String("image/")))
+ return QNetworkDiskCache::prepare(metaData);
+
+ return 0;
+}
--- /dev/null
+#ifndef DISKCACHE_H
+#define DISKCACHE_H
+
+#include <QNetworkDiskCache>
+
+class DiskCache : public QNetworkDiskCache
+{
+ Q_OBJECT
+public:
+ explicit DiskCache(QObject *parent = 0);
+ QIODevice* prepare(const QNetworkCacheMetaData &metaData);
+
+signals:
+
+public slots:
+
+};
+
+#endif // DISKCACHE_H
#include <QNetworkProxyFactory>
#include <cstdlib>
#include "networkaccess.h"
+#include "diskcache.h"
namespace The {
networkHttpProxySetting();
maybeSetSystemProxy();
nam = new QNetworkAccessManager();
+ QNetworkDiskCache *cache = new DiskCache();
+ QString cacheLocation = QDesktopServices::storageLocation(
+ QDesktopServices::DataLocation);
+ cache->setCacheDirectory(cacheLocation);
+ nam->setCache(cache);
}
return nam;
}
NetworkAccess* http() {
- static NetworkAccess *g_http = 0;
- if (!g_http) {
- // qDebug() << "Creating NetworkAccess";
- g_http = new NetworkAccess();
- }
+ static NetworkAccess *g_http = new NetworkAccess();
return g_http;
}