Commit 40c723e1 authored by Paweł Wegner's avatar Paweł Wegner

cloudbrowser: moved thumbnail_path to GetThumbnailRequest.

parent 3651067e
......@@ -10,6 +10,7 @@
#include <QtAndroid>
#include "CloudContext.h"
#include "Request/GetThumbnail.h"
#include "Utility/Utility.h"
const int RECEIVER_CODE = 43;
......@@ -66,8 +67,8 @@ void AndroidUtility::defaultOrientation() {
void AndroidUtility::showPlayerNotification(bool playing, QString filename,
QString title) {
auto arg0 =
QAndroidJniObject::fromString(CloudContext::thumbnail_path(filename));
auto arg0 = QAndroidJniObject::fromString(
GetThumbnailRequest::thumbnail_path(filename));
auto arg1 = QAndroidJniObject::fromString(filename);
auto arg2 = QAndroidJniObject::fromString(title);
QAndroidJniObject::callStaticMethod<void>(
......
......@@ -21,21 +21,6 @@
using namespace cloudstorage;
namespace {
QString sanitize(const QString& name) {
const QString forbidden = "~\"#%&*:<>?/\\{|}";
QString result;
for (auto&& c : name)
if (forbidden.indexOf(c) == -1)
result += c;
else
result += '_';
return result;
}
} // namespace
int ProviderListModel::rowCount(const QModelIndex&) const {
return provider_.size();
}
......@@ -368,11 +353,6 @@ void CloudContext::schedule(std::function<void()> f) {
thread_pool_->schedule(f);
}
QString CloudContext::thumbnail_path(const QString& filename) {
return QStandardPaths::writableLocation(QStandardPaths::CacheLocation) +
QDir::separator() + sanitize(filename) + "-thumbnail";
}
void CloudContext::receivedCode(std::string provider, std::string code) {
auto p = ICloudStorage::create()->provider(provider, init_data(provider));
auto r = p->exchangeCodeAsync(code, [=](EitherError<Token> e) {
......
......@@ -90,8 +90,6 @@ class CloudContext : public QObject {
ListDirectoryCacheKey);
void schedule(std::function<void()>);
static QString thumbnail_path(const QString& filename);
signals:
void receivedCode(QString provider);
void errorOccurred(QString operation, QVariantMap provider, int code,
......
#include "GetThumbnail.h"
#include <QDir>
#include <QFile>
#include <QSaveFile>
#include <QStandardPaths>
#include <QUrl>
#include "CloudContext.h"
#include "GenerateThumbnail.h"
#include "Utility/Utility.h"
......@@ -11,6 +14,17 @@ using namespace cloudstorage;
namespace {
QString sanitize(const QString& name) {
const QString forbidden = "~\"#%&*:<>?/\\{|}";
QString result;
for (auto&& c : name)
if (forbidden.indexOf(c) == -1)
result += c;
else
result += '_';
return result;
}
class DownloadToString : public IDownloadFileCallback {
public:
void receivedData(const char* data, uint32_t length) override {
......@@ -73,7 +87,8 @@ class DownloadThumbnailCallback : public IDownloadFileCallback {
#ifdef WITH_THUMBNAILER
if (e.left() && (item_->type() == IItem::FileType::Image ||
item_->type() == IItem::FileType::Video)) {
auto path = CloudContext::thumbnail_path(item_->filename().c_str());
auto path =
GetThumbnailRequest::thumbnail_path(item_->filename().c_str());
auto provider = provider_;
auto item = item_;
auto notifier = notifier_;
......@@ -111,7 +126,8 @@ class DownloadThumbnailCallback : public IDownloadFileCallback {
emit notifier_->finishedVariant(e.left());
else {
auto notifier = notifier_;
auto path = CloudContext::thumbnail_path(item_->filename().c_str());
auto path =
GetThumbnailRequest::thumbnail_path(item_->filename().c_str());
auto data = std::move(data_);
context_->schedule(
[notifier, path, data] { submit(notifier, path, std::move(data)); });
......@@ -131,7 +147,7 @@ class DownloadThumbnailCallback : public IDownloadFileCallback {
void GetThumbnailRequest::update(CloudContext* context, CloudItem* item) {
if (item->type() == "directory") return set_done(true);
set_done(false);
auto path = CloudContext::thumbnail_path(item->filename());
auto path = thumbnail_path(item->filename());
QFile file(path);
if (file.exists() && file.size() > 0) {
source_ = QUrl::fromLocalFile(path).toString();
......@@ -165,3 +181,8 @@ void GetThumbnailRequest::update(CloudContext* context, CloudItem* item) {
context->add(p, std::move(r));
}
}
QString GetThumbnailRequest::thumbnail_path(const QString& filename) {
return QStandardPaths::writableLocation(QStandardPaths::CacheLocation) +
QDir::separator() + sanitize(filename) + "-thumbnail";
}
......@@ -15,6 +15,7 @@ class GetThumbnailRequest : public Request {
QString source() const { return source_; }
Q_INVOKABLE void update(CloudContext* context, CloudItem* item);
static QString thumbnail_path(const QString& filename);
signals:
void sourceChanged();
......
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