2018-06-26 15:33:51 +02:00
|
|
|
#include "common/NetworkRequest.hpp"
|
2018-01-19 22:45:33 +01:00
|
|
|
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "Application.hpp"
|
2018-04-27 22:11:19 +02:00
|
|
|
|
2018-01-19 22:45:33 +01:00
|
|
|
namespace chatterino {
|
|
|
|
|
|
|
|
NetworkRequest::NetworkRequest(const char *url)
|
|
|
|
{
|
|
|
|
this->data.request.setUrl(QUrl(url));
|
|
|
|
}
|
|
|
|
|
|
|
|
NetworkRequest::NetworkRequest(const std::string &url)
|
|
|
|
{
|
|
|
|
this->data.request.setUrl(QUrl(QString::fromStdString(url)));
|
|
|
|
}
|
|
|
|
|
|
|
|
NetworkRequest::NetworkRequest(const QString &url)
|
|
|
|
{
|
|
|
|
this->data.request.setUrl(QUrl(url));
|
|
|
|
}
|
|
|
|
|
|
|
|
void NetworkRequest::setUseQuickLoadCache(bool value)
|
|
|
|
{
|
|
|
|
this->data.useQuickLoadCache = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NetworkRequest::Data::writeToCache(const QByteArray &bytes)
|
|
|
|
{
|
|
|
|
if (this->useQuickLoadCache) {
|
2018-04-27 22:11:19 +02:00
|
|
|
auto app = getApp();
|
2018-01-19 22:45:33 +01:00
|
|
|
|
2018-06-21 13:02:34 +02:00
|
|
|
QFile cachedFile(app->paths->cacheDirectory + "/" + this->getHash());
|
2018-01-19 22:45:33 +01:00
|
|
|
|
|
|
|
if (cachedFile.open(QIODevice::WriteOnly)) {
|
|
|
|
cachedFile.write(bytes);
|
|
|
|
|
|
|
|
cachedFile.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace chatterino
|