summaryrefslogtreecommitdiffstats
path: root/logic/resources/WebResourceHandler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'logic/resources/WebResourceHandler.cpp')
-rw-r--r--logic/resources/WebResourceHandler.cpp67
1 files changed, 0 insertions, 67 deletions
diff --git a/logic/resources/WebResourceHandler.cpp b/logic/resources/WebResourceHandler.cpp
deleted file mode 100644
index 7ced5bc6..00000000
--- a/logic/resources/WebResourceHandler.cpp
+++ /dev/null
@@ -1,67 +0,0 @@
-#include "WebResourceHandler.h"
-
-#include "net/CacheDownload.h"
-#include "net/HttpMetaCache.h"
-#include "net/NetJob.h"
-#include "FileSystem.h"
-#include "Env.h"
-
-QMap<QString, NetJob *> WebResourceHandler::m_activeDownloads;
-
-WebResourceHandler::WebResourceHandler(const QString &url)
- : QObject(), m_url(url)
-{
- MetaEntryPtr entry = ENV.metacache()->resolveEntry("icons", url);
- if (!entry->stale)
- {
- setResultFromFile(entry->getFullPath());
- }
- else if (m_activeDownloads.contains(url))
- {
- NetJob *job = m_activeDownloads.value(url);
- connect(job, &NetJob::succeeded, this, &WebResourceHandler::succeeded);
- connect(job, &NetJob::failed, this, [job, this]() {setFailure(job->failReason());});
- connect(job, &NetJob::progress, this, &WebResourceHandler::progress);
- }
- else
- {
- NetJob *job = new NetJob("Icon download");
- job->addNetAction(CacheDownload::make(QUrl(url), entry));
- connect(job, &NetJob::succeeded, this, &WebResourceHandler::succeeded);
- connect(job, &NetJob::failed, this, [job, this]() {setFailure(job->failReason());});
- connect(job, &NetJob::progress, this, &WebResourceHandler::progress);
- connect(job, &NetJob::finished, job, [job](){m_activeDownloads.remove(m_activeDownloads.key(job));job->deleteLater();});
- m_activeDownloads.insert(url, job);
- job->start();
- }
-}
-
-void WebResourceHandler::succeeded()
-{
- MetaEntryPtr entry = ENV.metacache()->resolveEntry("icons", m_url);
- setResultFromFile(entry->getFullPath());
- m_activeDownloads.remove(m_activeDownloads.key(qobject_cast<NetJob *>(sender())));
-}
-void WebResourceHandler::progress(qint64 current, qint64 total)
-{
- if (total == 0)
- {
- setProgress(101);
- }
- else
- {
- setProgress(current / total);
- }
-}
-
-void WebResourceHandler::setResultFromFile(const QString &file)
-{
- try
- {
- setResult(FS::read(file));
- }
- catch (Exception &e)
- {
- setFailure(e.cause());
- }
-}