Commit a7a7dcef authored by Paweł Wegner's avatar Paweł Wegner

cloudbrowser: save thumbnail to file using thread pool.

parent 4442fe6f
...@@ -349,7 +349,7 @@ void CloudContext::cacheDirectory(CloudItem* directory, ...@@ -349,7 +349,7 @@ void CloudContext::cacheDirectory(CloudItem* directory,
list_directory_cache_[{directory->provider().label_, list_directory_cache_[{directory->provider().label_,
directory->item()->id()}] = lst; directory->item()->id()}] = lst;
} }
thread_pool_->schedule([=] { saveCachedDirectories(); }); schedule([=] { saveCachedDirectories(); });
} }
std::vector<IItem::Pointer> CloudContext::cachedDirectory( std::vector<IItem::Pointer> CloudContext::cachedDirectory(
...@@ -363,6 +363,10 @@ std::vector<IItem::Pointer> CloudContext::cachedDirectory( ...@@ -363,6 +363,10 @@ std::vector<IItem::Pointer> CloudContext::cachedDirectory(
return it->second; return it->second;
} }
void CloudContext::schedule(std::function<void()> f) {
thread_pool_->schedule(f);
}
QString CloudContext::thumbnail_path(const QString& filename) { QString CloudContext::thumbnail_path(const QString& filename) {
return QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + return QStandardPaths::writableLocation(QStandardPaths::CacheLocation) +
QDir::separator() + sanitize(filename) + "-thumbnail"; QDir::separator() + sanitize(filename) + "-thumbnail";
...@@ -732,26 +736,28 @@ void GetThumbnailRequest::update(CloudContext* context, CloudItem* item) { ...@@ -732,26 +736,28 @@ void GetThumbnailRequest::update(CloudContext* context, CloudItem* item) {
} else { } else {
auto object = new RequestNotifier; auto object = new RequestNotifier;
auto provider = item->provider().variant(); auto provider = item->provider().variant();
connect( connect(object, &RequestNotifier::finishedString, this,
object, &RequestNotifier::finishedString, this, [=](EitherError<std::string> e) {
[=](EitherError<std::string> e) { set_done(true);
set_done(true); if (e.left())
if (e.left()) return emit context->errorOccurred(
return emit context->errorOccurred("GetThumbnail", provider, "GetThumbnail", provider, e.left()->code_,
e.left()->code_, e.left()->description_.c_str());
e.left()->description_.c_str()); context->schedule([=] {
QSaveFile file(path); QSaveFile file(path);
if (!file.open(QFile::WriteOnly)) if (!file.open(QFile::WriteOnly))
return emit context->errorOccurred("GetThumbnail", provider, return emit context->errorOccurred("GetThumbnail", provider,
IHttpRequest::Failure, IHttpRequest::Failure,
"couldn't save thumbnail"); "couldn't save thumbnail");
file.write(e.right()->data(), static_cast<qint64>(e.right()->size())); file.write(e.right()->data(),
if (file.commit()) { static_cast<qint64>(e.right()->size()));
source_ = QUrl::fromLocalFile(path).toString(); if (file.commit()) {
context->addCacheSize(e.right()->size()); source_ = QUrl::fromLocalFile(path).toString();
emit sourceChanged(); context->addCacheSize(e.right()->size());
} emit sourceChanged();
}); }
});
});
class DownloadThumbnailCallback : public IDownloadFileCallback { class DownloadThumbnailCallback : public IDownloadFileCallback {
public: public:
DownloadThumbnailCallback(RequestNotifier* notifier, DownloadThumbnailCallback(RequestNotifier* notifier,
......
...@@ -342,6 +342,7 @@ class CloudContext : public QObject { ...@@ -342,6 +342,7 @@ class CloudContext : public QObject {
const std::vector<cloudstorage::IItem::Pointer>&); const std::vector<cloudstorage::IItem::Pointer>&);
std::vector<cloudstorage::IItem::Pointer> cachedDirectory( std::vector<cloudstorage::IItem::Pointer> cachedDirectory(
CloudItem* directory); CloudItem* directory);
void schedule(std::function<void()>);
static QString thumbnail_path(const QString& filename); static QString thumbnail_path(const QString& filename);
......
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