Commit 6efe01b2 by Paweł Wegner

make_unique -> util::make_unique

For g++ 6.2 compatibility.
parent b9051f19
......@@ -30,7 +30,7 @@
#include "Utility/Utility.h"
#include "Window.h"
using cloudstorage::make_unique;
using cloudstorage::util::make_unique;
DownloadFileCallback::DownloadFileCallback(Window* window, std::string filename)
: window_(window), file_(filename.c_str()), filename_(filename) {
......
......@@ -23,15 +23,12 @@
#include "MockProvider.h"
#include "Utility/Utility.h"
#include <QFile>
namespace cloudstorage {
template <typename T, typename... Args>
std::unique_ptr<T> make_unique(Args&&... args) {
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}
MockProvider::MockProvider() {}
void MockProvider::initialize(InitData&&) {}
......@@ -52,17 +49,18 @@ IItem::Pointer MockProvider::rootDirectory() const {
ICloudProvider::ListDirectoryRequest::Pointer MockProvider::listDirectoryAsync(
IItem::Pointer directory, IListDirectoryCallback::Pointer callback) {
return make_unique<MockListDirectoryRequest>(directory, std::move(callback));
return util::make_unique<MockListDirectoryRequest>(directory,
std::move(callback));
}
ICloudProvider::GetItemRequest::Pointer MockProvider::getItemAsync(
const std::string& absolute_path, GetItemCallback callback) {
return make_unique<MockGetItemRequest>(absolute_path, callback);
return util::make_unique<MockGetItemRequest>(absolute_path, callback);
}
ICloudProvider::DownloadFileRequest::Pointer MockProvider::downloadFileAsync(
IItem::Pointer item, IDownloadFileCallback::Pointer callback) {
return make_unique<MockDownloadFileRequest>(item, std::move(callback));
return util::make_unique<MockDownloadFileRequest>(item, std::move(callback));
}
ICloudProvider::UploadFileRequest::Pointer MockProvider::uploadFileAsync(
......@@ -72,32 +70,32 @@ ICloudProvider::UploadFileRequest::Pointer MockProvider::uploadFileAsync(
ICloudProvider::GetItemDataRequest::Pointer MockProvider::getItemDataAsync(
const std::string& id, GetItemDataCallback callback) {
return make_unique<MockGetItemDataRequest>(id, callback);
return util::make_unique<MockGetItemDataRequest>(id, callback);
}
ICloudProvider::DeleteItemRequest::Pointer MockProvider::deleteItemAsync(
IItem::Pointer, DeleteItemCallback callback) {
callback(false);
return make_unique<MockDeleteItemRequest>();
return util::make_unique<MockDeleteItemRequest>();
}
ICloudProvider::CreateDirectoryRequest::Pointer
MockProvider::createDirectoryAsync(IItem::Pointer parent,
const std::string& name,
CreateDirectoryCallback callback) {
return make_unique<MockCreateDirectoryRequest>(parent, name, callback);
return util::make_unique<MockCreateDirectoryRequest>(parent, name, callback);
}
ICloudProvider::MoveItemRequest::Pointer MockProvider::moveItemAsync(
IItem::Pointer, IItem::Pointer, MoveItemCallback callback) {
callback(false);
return make_unique<MockMoveItemRequest>();
return util::make_unique<MockMoveItemRequest>();
}
ICloudProvider::RenameItemRequest::Pointer MockProvider::renameItemAsync(
IItem::Pointer, const std::string&, RenameItemCallback callback) {
callback(false);
return make_unique<MockMoveItemRequest>();
return util::make_unique<MockMoveItemRequest>();
}
ICloudProvider::ListDirectoryRequest::Pointer MockProvider::listDirectoryAsync(
......@@ -123,7 +121,7 @@ ICloudProvider::UploadFileRequest::Pointer MockProvider::uploadFileAsync(
ICloudProvider::DownloadFileRequest::Pointer MockProvider::getThumbnailAsync(
IItem::Pointer item, IDownloadFileCallback::Pointer callback) {
return make_unique<MockDownloadFileRequest>(item, std::move(callback));
return util::make_unique<MockDownloadFileRequest>(item, std::move(callback));
}
MockProvider::MockListDirectoryRequest::MockListDirectoryRequest(
......@@ -136,11 +134,11 @@ MockProvider::MockListDirectoryRequest::MockListDirectoryRequest(
if (cancelled_) break;
std::this_thread::sleep_for(std::chrono::milliseconds(100));
if (i % 2 == 0)
result.push_back(make_unique<MockItem>(
result.push_back(util::make_unique<MockItem>(
directory->filename() + "_directory_" + std::to_string(i),
IItem::FileType::Directory));
else
result.push_back(make_unique<MockItem>(
result.push_back(util::make_unique<MockItem>(
directory->filename() + "_file_" + std::to_string(i),
IItem::FileType::Unknown));
callback_->receivedItem(result.back());
......@@ -153,18 +151,18 @@ MockProvider::MockListDirectoryRequest::MockListDirectoryRequest(
MockProvider::MockGetItemRequest::MockGetItemRequest(const std::string& path,
GetItemCallback callback) {
if (path.length() % 2 == 0)
result_ = make_unique<MockItem>(path, IItem::FileType::Directory);
result_ = util::make_unique<MockItem>(path, IItem::FileType::Directory);
else
result_ = make_unique<MockItem>(path, IItem::FileType::Unknown);
result_ = util::make_unique<MockItem>(path, IItem::FileType::Unknown);
callback(result_);
}
MockProvider::MockGetItemDataRequest::MockGetItemDataRequest(
const std::string& id, GetItemDataCallback callback) {
if (id.length() % 2 == 0)
result_ = make_unique<MockItem>(id, IItem::FileType::Directory);
result_ = util::make_unique<MockItem>(id, IItem::FileType::Directory);
else
result_ = make_unique<MockItem>(id, IItem::FileType::Unknown);
result_ = util::make_unique<MockItem>(id, IItem::FileType::Unknown);
callback(result_);
}
......
......@@ -38,7 +38,7 @@
#include "Utility/Utility.h"
using cloudstorage::make_unique;
using namespace cloudstorage;
Window::Window(MediaPlayer* media_player)
: cloud_storage_(ICloudStorage::create()),
......@@ -128,7 +128,7 @@ void Window::initializeCloud(QString name) {
if (name != "mock")
cloud_provider_ = cloud_storage_->provider(name.toStdString());
else
cloud_provider_ = make_unique<cloudstorage::MockProvider>();
cloud_provider_ = util::make_unique<cloudstorage::MockProvider>();
current_directory_ = cloud_provider_->rootDirectory();
if (initialized_clouds_.find(name.toStdString()) ==
std::end(initialized_clouds_)) {
......@@ -144,7 +144,7 @@ void Window::initializeCloud(QString name) {
hints["temporary_directory"] =
QDir::toNativeSeparators(QDir::tempPath() + "/").toStdString();
cloud_provider_->initialize({settings.value(name).toString().toStdString(),
make_unique<CloudProviderCallback>(this),
util::make_unique<CloudProviderCallback>(this),
nullptr, nullptr, nullptr, hints});
initialized_clouds_.insert(name.toStdString());
} else if (unauthorized_clouds_.find(name.toStdString()) !=
......@@ -158,7 +158,7 @@ void Window::listDirectory() {
if (!cloud_provider_ || !current_directory_) return;
clearCurrentDirectoryList();
list_directory_request_ = cloud_provider_->listDirectoryAsync(
current_directory_, make_unique<::ListDirectoryCallback>(this));
current_directory_, util::make_unique<::ListDirectoryCallback>(this));
}
void Window::changeCurrentDirectory(int directory_id) {
......@@ -345,13 +345,13 @@ void Window::uploadFile(QString path) {
QUrl url = path;
upload_request_ = cloud_provider_->uploadFileAsync(
current_directory_, url.fileName().toStdString(),
make_unique<::UploadFileCallback>(this, url));
util::make_unique<::UploadFileCallback>(this, url));
}
void Window::downloadFile(int item_id, QUrl path) {
ItemModel* i = directory_model_.get(item_id);
download_request_ = cloud_provider_->downloadFileAsync(
i->item(), make_unique<::DownloadFileCallback>(
i->item(), util::make_unique<::DownloadFileCallback>(
this, path.toLocalFile().toStdString() + "/" +
escapeFileName(i->item()->filename())));
......@@ -429,7 +429,7 @@ void ItemModel::fetchThumbnail() {
thumbnail_ = QUrl::fromLocalFile(cache).toString();
} else if (!thumbnail_request_)
thumbnail_request_ = provider_->getThumbnailAsync(
item_, make_unique<DownloadThumbnailCallback>(this));
item_, util::make_unique<DownloadThumbnailCallback>(this));
}
int DirectoryModel::rowCount(const QModelIndex&) const { return list_.size(); }
......@@ -449,7 +449,7 @@ QVariant DirectoryModel::data(const QModelIndex& id, int) const {
void DirectoryModel::addItem(IItem::Pointer item, Window* w) {
beginInsertRows(QModelIndex(), rowCount(), rowCount());
auto model = make_unique<ItemModel>(item, w->cloud_provider_, w);
auto model = util::make_unique<ItemModel>(item, w->cloud_provider_, w);
list_.push_back(std::move(model));
endInsertRows();
int idx = rowCount() - 1;
......
......@@ -32,7 +32,7 @@ const int THUMBNAIL_SIZE = 64;
namespace cloudstorage {
AmazonDrive::AmazonDrive() : CloudProvider(make_unique<Auth>()) {}
AmazonDrive::AmazonDrive() : CloudProvider(util::make_unique<Auth>()) {}
void AmazonDrive::initialize(InitData&& data) {
{
......@@ -58,12 +58,12 @@ std::string AmazonDrive::name() const { return "amazon"; }
std::string AmazonDrive::endpoint() const { return content_url(); }
IItem::Pointer AmazonDrive::rootDirectory() const {
return make_unique<Item>("root", "root", IItem::FileType::Directory);
return util::make_unique<Item>("root", "root", IItem::FileType::Directory);
}
ICloudProvider::MoveItemRequest::Pointer AmazonDrive::moveItemAsync(
IItem::Pointer s, IItem::Pointer d, MoveItemCallback callback) {
auto r = make_unique<Request<bool>>(shared_from_this());
auto r = util::make_unique<Request<bool>>(shared_from_this());
r->set_resolver([=](Request<bool>* r) -> bool {
Item* source = static_cast<Item*>(s.get());
Item* destination = static_cast<Item*>(d.get());
......@@ -94,7 +94,7 @@ ICloudProvider::MoveItemRequest::Pointer AmazonDrive::moveItemAsync(
}
AuthorizeRequest::Pointer AmazonDrive::authorizeAsync() {
auto r = make_unique<AuthorizeRequest>(
auto r = util::make_unique<AuthorizeRequest>(
shared_from_this(), [this](AuthorizeRequest* r) -> bool {
if (!r->oauth2Authorization()) return false;
auto request = http()->create(
......@@ -234,7 +234,7 @@ IItem::FileType AmazonDrive::type(const Json::Value& v) const {
IItem::Pointer AmazonDrive::toItem(const Json::Value& v) const {
std::string name = v["isRoot"].asBool() ? "root" : v["name"].asString();
auto item = make_unique<Item>(name, v["id"].asString(), type(v));
auto item = util::make_unique<Item>(name, v["id"].asString(), type(v));
item->set_url(v["tempLink"].asString());
if (item->type() == IItem::FileType::Image)
item->set_thumbnail_url(item->url() + "?viewBox=" +
......@@ -306,7 +306,7 @@ IAuth::Token::Pointer AmazonDrive::Auth::exchangeAuthorizationCodeResponse(
std::istream& stream) const {
Json::Value response;
stream >> response;
auto token = make_unique<Token>();
auto token = util::make_unique<Token>();
token->token_ = response["access_token"].asString();
token->refresh_token_ = response["refresh_token"].asString();
token->expires_in_ = response["expires_in"].asInt();
......@@ -317,7 +317,7 @@ IAuth::Token::Pointer AmazonDrive::Auth::refreshTokenResponse(
std::istream& stream) const {
Json::Value response;
stream >> response;
auto token = make_unique<Token>();
auto token = util::make_unique<Token>();
token->refresh_token_ = access_token()->refresh_token_;
token->token_ = response["access_token"].asString();
token->expires_in_ = response["expires_in"].asInt();
......
......@@ -135,7 +135,7 @@ std::string currentDateAndTime() {
} // namespace
AmazonS3::AmazonS3()
: CloudProvider(make_unique<Auth>()), region_(DEFAULT_REGION) {}
: CloudProvider(util::make_unique<Auth>()), region_(DEFAULT_REGION) {}
void AmazonS3::initialize(InitData&& init_data) {
{
......@@ -167,7 +167,7 @@ ICloudProvider::Hints AmazonS3::hints() const {
}
AuthorizeRequest::Pointer AmazonS3::authorizeAsync() {
return make_unique<AuthorizeRequest>(
return util::make_unique<AuthorizeRequest>(
shared_from_this(), [=](AuthorizeRequest* r) -> bool {
if (callback()->userConsentRequired(*this) !=
ICallback::Status::WaitForAuthorizationCode)
......@@ -183,7 +183,7 @@ AuthorizeRequest::Pointer AmazonS3::authorizeAsync() {
ICloudProvider::MoveItemRequest::Pointer AmazonS3::moveItemAsync(
IItem::Pointer source, IItem::Pointer destination,
MoveItemCallback callback) {
auto r = make_unique<Request<bool>>(shared_from_this());
auto r = util::make_unique<Request<bool>>(shared_from_this());
r->set_resolver([=](Request<bool>* r) -> bool {
bool success = rename(r, destination->id() + source->filename(),
source->id(), region_, http());
......@@ -195,7 +195,7 @@ ICloudProvider::MoveItemRequest::Pointer AmazonS3::moveItemAsync(
ICloudProvider::RenameItemRequest::Pointer AmazonS3::renameItemAsync(
IItem::Pointer item, const std::string& name, RenameItemCallback callback) {
auto r = make_unique<Request<bool>>(shared_from_this());
auto r = util::make_unique<Request<bool>>(shared_from_this());
r->set_resolver([=](Request<bool>* r) -> bool {
std::string path = split(item->id()).second;
if (!path.empty() && path.back() == '/') path.pop_back();
......@@ -213,7 +213,7 @@ ICloudProvider::RenameItemRequest::Pointer AmazonS3::renameItemAsync(
ICloudProvider::CreateDirectoryRequest::Pointer AmazonS3::createDirectoryAsync(
IItem::Pointer parent, const std::string& name,
CreateDirectoryCallback callback) {
auto r = make_unique<Request<IItem::Pointer>>(shared_from_this());
auto r = util::make_unique<Request<IItem::Pointer>>(shared_from_this());
r->set_resolver([=](Request<IItem::Pointer>* r) -> IItem::Pointer {
std::stringstream output;
int code = r->sendRequest(
......@@ -243,7 +243,7 @@ ICloudProvider::CreateDirectoryRequest::Pointer AmazonS3::createDirectoryAsync(
ICloudProvider::DeleteItemRequest::Pointer AmazonS3::deleteItemAsync(
IItem::Pointer item, DeleteItemCallback callback) {
auto r = make_unique<Request<bool>>(shared_from_this());
auto r = util::make_unique<Request<bool>>(shared_from_this());
r->set_resolver([=](Request<bool>* r) -> bool {
if (item->type() == IItem::FileType::Directory) {
Request<bool>::Semaphore semaphore(r);
......@@ -290,7 +290,7 @@ ICloudProvider::DeleteItemRequest::Pointer AmazonS3::deleteItemAsync(
ICloudProvider::GetItemDataRequest::Pointer AmazonS3::getItemDataAsync(
const std::string& id, GetItemCallback callback) {
auto r = make_unique<Request<IItem::Pointer>>(shared_from_this());
auto r = util::make_unique<Request<IItem::Pointer>>(shared_from_this());
r->set_resolver([=](Request<IItem::Pointer>* r) -> IItem::Pointer {
if (access_id().empty() || secret().empty()) r->reauthorize();
auto data = split(id);
......@@ -356,8 +356,8 @@ std::vector<IItem::Pointer> AmazonS3::listDirectoryResponse(
for (auto child = buckets->FirstChild(); child;
child = child->NextSibling()) {
std::string name = child->FirstChildElement("Name")->GetText();
auto item = make_unique<Item>(name, name + Auth::SEPARATOR,
IItem::FileType::Directory);
auto item = util::make_unique<Item>(name, name + Auth::SEPARATOR,
IItem::FileType::Directory);
result.push_back(std::move(item));
}
} else if (document.RootElement()->FirstChildElement("Name")) {
......@@ -368,9 +368,9 @@ std::vector<IItem::Pointer> AmazonS3::listDirectoryResponse(
if (child->FirstChildElement("Size")->GetText() == std::string("0"))
continue;
std::string id = child->FirstChildElement("Key")->GetText();
auto item =
make_unique<Item>(getFilename(id), bucket + Auth::SEPARATOR + id,
IItem::FileType::Unknown);
auto item = util::make_unique<Item>(getFilename(id),
bucket + Auth::SEPARATOR + id,
IItem::FileType::Unknown);
item->set_url(getUrl(*item));
result.push_back(std::move(item));
}
......@@ -378,9 +378,9 @@ std::vector<IItem::Pointer> AmazonS3::listDirectoryResponse(
document.RootElement()->FirstChildElement("CommonPrefixes");
child; child = child->NextSiblingElement("CommonPrefixes")) {
std::string id = child->FirstChildElement("Prefix")->GetText();
auto item =
make_unique<Item>(getFilename(id), bucket + Auth::SEPARATOR + id,
IItem::FileType::Directory);
auto item = util::make_unique<Item>(getFilename(id),
bucket + Auth::SEPARATOR + id,
IItem::FileType::Directory);
result.push_back(std::move(item));
}
if (document.RootElement()->FirstChildElement("IsTruncated")->GetText() ==
......
......@@ -33,10 +33,10 @@ const std::string BOXAPI_ENDPOINT = "https://api.box.com";
namespace cloudstorage {
Box::Box() : CloudProvider(make_unique<Auth>()) {}
Box::Box() : CloudProvider(util::make_unique<Auth>()) {}
IItem::Pointer Box::rootDirectory() const {
return make_unique<Item>("root", "0", IItem::FileType::Directory);
return util::make_unique<Item>("root", "0", IItem::FileType::Directory);
}
std::string Box::name() const { return "box"; }
......@@ -49,7 +49,7 @@ bool Box::reauthorize(int code) const {
ICloudProvider::GetItemDataRequest::Pointer Box::getItemDataAsync(
const std::string& id, GetItemDataCallback callback) {
auto r = make_unique<Request<IItem::Pointer>>(shared_from_this());
auto r = util::make_unique<Request<IItem::Pointer>>(shared_from_this());
r->set_resolver(
[id, callback, this](Request<IItem::Pointer>* r) -> IItem::Pointer {
std::stringstream output;
......@@ -217,7 +217,8 @@ std::vector<IItem::Pointer> Box::listDirectoryResponse(
IItem::Pointer Box::toItem(const Json::Value& v) const {
IItem::FileType type = IItem::FileType::Unknown;
if (v["type"].asString() == "folder") type = IItem::FileType::Directory;
auto item = make_unique<Item>(v["name"].asString(), v["id"].asString(), type);
auto item =
util::make_unique<Item>(v["name"].asString(), v["id"].asString(), type);
return std::move(item);
}
......@@ -257,16 +258,18 @@ IAuth::Token::Pointer Box::Auth::exchangeAuthorizationCodeResponse(
std::istream& stream) const {
Json::Value response;
stream >> response;
return make_unique<Token>(Token{response["access_token"].asString(),
response["refresh_token"].asString(), -1});
return util::make_unique<Token>(Token{response["access_token"].asString(),
response["refresh_token"].asString(),
-1});
}
IAuth::Token::Pointer Box::Auth::refreshTokenResponse(
std::istream& stream) const {
Json::Value response;
stream >> response;
return make_unique<Token>(Token{response["access_token"].asString(),
response["refresh_token"].asString(), -1});
return util::make_unique<Token>(Token{response["access_token"].asString(),
response["refresh_token"].asString(),
-1});
}
} // namespace cloudstorage
......@@ -167,15 +167,15 @@ void CloudProvider::initialize(InitData&& data) {
});
#ifdef WITH_CRYPTOPP
if (!crypto_) crypto_ = make_unique<CryptoPP>();
if (!crypto_) crypto_ = util::make_unique<CryptoPP>();
#endif
#ifdef WITH_CURL
if (!http_) http_ = make_unique<CurlHttp>();
if (!http_) http_ = util::make_unique<CurlHttp>();
#endif
#ifdef WITH_THUMBNAILER
if (!thumbnailer_) thumbnailer_ = make_unique<FFmpegThumbnailer>();
if (!thumbnailer_) thumbnailer_ = util::make_unique<FFmpegThumbnailer>();
#endif
if (!http_) throw std::runtime_error("No http module specified.");
......@@ -205,7 +205,7 @@ std::string CloudProvider::token() const {
}
IItem::Pointer CloudProvider::rootDirectory() const {
return make_unique<Item>("/", "root", IItem::FileType::Directory);
return util::make_unique<Item>("/", "root", IItem::FileType::Directory);
}
ICloudProvider::ICallback* CloudProvider::callback() const {
......@@ -220,19 +220,19 @@ IThumbnailer* CloudProvider::thumbnailer() const { return thumbnailer_.get(); }
ICloudProvider::ListDirectoryRequest::Pointer CloudProvider::listDirectoryAsync(
IItem::Pointer item, IListDirectoryCallback::Pointer callback) {
return make_unique<cloudstorage::ListDirectoryRequest>(
return util::make_unique<cloudstorage::ListDirectoryRequest>(
shared_from_this(), std::move(item), std::move(callback));
}
ICloudProvider::GetItemRequest::Pointer CloudProvider::getItemAsync(
const std::string& absolute_path, GetItemCallback callback) {
return make_unique<cloudstorage::GetItemRequest>(shared_from_this(),
absolute_path, callback);
return util::make_unique<cloudstorage::GetItemRequest>(
shared_from_this(), absolute_path, callback);
}
ICloudProvider::DownloadFileRequest::Pointer CloudProvider::downloadFileAsync(
IItem::Pointer file, IDownloadFileCallback::Pointer callback) {
return make_unique<cloudstorage::DownloadFileRequest>(
return util::make_unique<cloudstorage::DownloadFileRequest>(
shared_from_this(), std::move(file), std::move(callback),
std::bind(&CloudProvider::downloadFileRequest, this, _1, _2));
}
......@@ -240,14 +240,14 @@ ICloudProvider::DownloadFileRequest::Pointer CloudProvider::downloadFileAsync(
ICloudProvider::UploadFileRequest::Pointer CloudProvider::uploadFileAsync(
IItem::Pointer directory, const std::string& filename,
IUploadFileCallback::Pointer callback) {
return make_unique<cloudstorage::UploadFileRequest>(
return util::make_unique<cloudstorage::UploadFileRequest>(
shared_from_this(), std::move(directory), filename, std::move(callback));
}
ICloudProvider::GetItemDataRequest::Pointer CloudProvider::getItemDataAsync(
const std::string& id, GetItemDataCallback f) {
return make_unique<cloudstorage::GetItemDataRequest>(shared_from_this(), id,
f);
return util::make_unique<cloudstorage::GetItemDataRequest>(shared_from_this(),
id, f);
}
void CloudProvider::authorizeRequest(IHttpRequest& r) const {
......@@ -259,7 +259,7 @@ bool CloudProvider::reauthorize(int code) const {
}
AuthorizeRequest::Pointer CloudProvider::authorizeAsync() {
return make_unique<AuthorizeRequest>(shared_from_this());
return util::make_unique<AuthorizeRequest>(shared_from_this());
}
std::mutex& CloudProvider::auth_mutex() const { return auth_mutex_; }
......@@ -321,63 +321,64 @@ std::pair<std::string, std::string> CloudProvider::creditentialsFromString(
ICloudProvider::DownloadFileRequest::Pointer CloudProvider::getThumbnailAsync(
IItem::Pointer item, IDownloadFileCallback::Pointer callback) {
return make_unique<cloudstorage::DownloadFileRequest>(
return util::make_unique<cloudstorage::DownloadFileRequest>(
shared_from_this(), item, std::move(callback),
std::bind(&CloudProvider::getThumbnailRequest, this, _1, _2), true);
}
ICloudProvider::DeleteItemRequest::Pointer CloudProvider::deleteItemAsync(
IItem::Pointer item, DeleteItemCallback callback) {
return make_unique<cloudstorage::DeleteItemRequest>(shared_from_this(), item,
callback);
return util::make_unique<cloudstorage::DeleteItemRequest>(shared_from_this(),
item, callback);
}
ICloudProvider::CreateDirectoryRequest::Pointer
CloudProvider::createDirectoryAsync(IItem::Pointer parent,
const std::string& name,
CreateDirectoryCallback callback) {
return make_unique<cloudstorage::CreateDirectoryRequest>(
return util::make_unique<cloudstorage::CreateDirectoryRequest>(
shared_from_this(), parent, name, callback);
}
ICloudProvider::MoveItemRequest::Pointer CloudProvider::moveItemAsync(
IItem::Pointer source, IItem::Pointer destination,
MoveItemCallback callback) {
return make_unique<cloudstorage::MoveItemRequest>(shared_from_this(), source,
destination, callback);
return util::make_unique<cloudstorage::MoveItemRequest>(
shared_from_this(), source, destination, callback);
}
ICloudProvider::RenameItemRequest::Pointer CloudProvider::renameItemAsync(
IItem::Pointer item, const std::string& name, RenameItemCallback callback) {
return make_unique<cloudstorage::RenameItemRequest>(shared_from_this(), item,
name, callback);
return util::make_unique<cloudstorage::RenameItemRequest>(
shared_from_this(), item, name, callback);
}
ICloudProvider::ListDirectoryRequest::Pointer CloudProvider::listDirectoryAsync(
IItem::Pointer item, ListDirectoryCallback callback) {
return listDirectoryAsync(item,
make_unique<::ListDirectoryCallback>(callback));
return listDirectoryAsync(
item, util::make_unique<::ListDirectoryCallback>(callback));
}
ICloudProvider::DownloadFileRequest::Pointer CloudProvider::downloadFileAsync(
IItem::Pointer item, const std::string& filename,
DownloadFileCallback callback) {
return downloadFileAsync(
item, make_unique<::DownloadFileCallback>(filename, callback));
item, util::make_unique<::DownloadFileCallback>(filename, callback));
}
ICloudProvider::DownloadFileRequest::Pointer CloudProvider::getThumbnailAsync(
IItem::Pointer item, const std::string& filename,
GetThumbnailCallback callback) {
return getThumbnailAsync(
item, make_unique<::DownloadFileCallback>(filename, callback));
item, util::make_unique<::DownloadFileCallback>(filename, callback));
}
ICloudProvider::UploadFileRequest::Pointer CloudProvider::uploadFileAsync(
IItem::Pointer parent, const std::string& path, const std::string& filename,
UploadFileCallback callback) {
return uploadFileAsync(parent, filename,
make_unique<::UploadFileCallback>(path, callback));
return uploadFileAsync(
parent, filename,
util::make_unique<::UploadFileCallback>(path, callback));
}
IHttpRequest::Pointer CloudProvider::getItemDataRequest(const std::string&,
......
......@@ -35,21 +35,21 @@ const std::string DROPBOXAPI_ENDPOINT = "https://api.dropboxapi.com";
namespace cloudstorage {
Dropbox::Dropbox() : CloudProvider(make_unique<Auth>()) {}
Dropbox::Dropbox() : CloudProvider(util::make_unique<Auth>()) {}
std::string Dropbox::name() const { return "dropbox"; }
std::string Dropbox::endpoint() const { return DROPBOXAPI_ENDPOINT; }
IItem::Pointer Dropbox::rootDirectory() const {
return make_unique<Item>("/", "", IItem::FileType::Directory);
return util::make_unique<Item>("/", "", IItem::FileType::Directory);
}
bool Dropbox::reauthorize(int code) const { return code == 400 || code == 401; }
ICloudProvider::GetItemDataRequest::Pointer Dropbox::getItemDataAsync(
const std::string& id, GetItemDataCallback callback) {
auto f = make_unique<Request<IItem::Pointer>>(shared_from_this());
auto f = util::make_unique<Request<IItem::Pointer>>(shared_from_this());
f->set_resolver([this, id,
callback](Request<IItem::Pointer>* r) -> IItem::Pointer {
auto item_data = [this, r, id](std::ostream& input) {
......@@ -228,8 +228,8 @@ IItem::Pointer Dropbox::toItem(const Json::Value& v) {
else if (file_type == "photo")
type = IItem::FileType::Image;
}
return make_unique<Item>(v["name"].asString(), v["path_display"].asString(),
type);
return util::make_unique<Item>(v["name"].asString(),
v["path_display"].asString(), type);
}
Dropbox::Auth::Auth() {
......@@ -247,7 +247,7 @@ std::string Dropbox::Auth::authorizeLibraryUrl() const {
IAuth::Token::Pointer Dropbox::Auth::fromTokenString(
const std::string& str) const {
Token::Pointer token = make_unique<Token>();
Token::Pointer token = util::make_unique<Token>();
token->token_ = str;
token->refresh_token_ = str;
token->expires_in_ = -1;
......@@ -275,7 +275,7 @@ IAuth::Token::Pointer Dropbox::Auth::exchangeAuthorizationCodeResponse(
Json::Value response;
stream >> response;
Token::Pointer token = make_unique<Token>();
Token::Pointer token = util::make_unique<Token>();
token->token_ = response["access_token"].asString();
token->refresh_token_ = token->token_;
token->expires_in_ = -1;
......
......@@ -34,7 +34,7 @@ const std::string GOOGLEAPI_ENDPOINT = "https://www.googleapis.com";
namespace cloudstorage {
GoogleDrive::GoogleDrive() : CloudProvider(make_unique<Auth>()) {}
GoogleDrive::GoogleDrive() : CloudProvider(util::make_unique<Auth>()) {}
std::string GoogleDrive::name() const { return "google"; }
......@@ -179,8 +179,8 @@ IItem::FileType GoogleDrive::toFileType(const std::string& mime_type) const {
}
IItem::Pointer GoogleDrive::toItem(const Json::Value& v) const {
auto item = make_unique<Item>(v["name"].asString(), v["id"].asString(),
toFileType(v["mimeType"].asString()));
auto item = util::make_unique<Item>(v["name"].asString(), v["id"].asString(),
toFileType(v["mimeType"].asString()));
item->set_hidden(v["trashed"].asBool());
std::string thumnail_url = v["thumbnailLink"].asString();
if (!thumnail_url.empty() && isGoogleMimeType(v["mimeType"].asString()))
......@@ -243,7 +243,7 @@ IAuth::Token::Pointer GoogleDrive::Auth::exchangeAuthorizationCodeResponse(
Json::Value response;
data >> response;
Token::Pointer token = make_unique<Token>();
Token::Pointer token = util::make_unique<Token>();
token->token_ = response["access_token"].asString();
token->refresh_token_ = response["refresh_token"].asString();
token->expires_in_ = response["expires_in"].asInt();
......@@ -254,7 +254,7 @@ IAuth::Token::Pointer GoogleDrive::Auth::refreshTokenResponse(
std::istream& data) const {
Json::Value response;
data >> response;
Token::Pointer token = make_unique<Token>();
Token::Pointer token = util::make_unique<Token>();
token->token_ = response["access_token"].asString();
token->refresh_token_ = access_token()->refresh_token_;
token->expires_in_ = response["expires_in"].asInt();
......
......@@ -161,10 +161,11 @@ int httpRequestCallback(void* cls, MHD_Connection* connection, const char*,
delete data;
};
HttpData* data = new HttpData;
auto request = make_unique<Request<void>>(
auto request = util::make_unique<Request<void>>(
std::weak_ptr<CloudProvider>(provider->shared_from_this()));
request->set_resolver(provider->downloadResolver(
provider->toItem(node.get()), make_unique<DownloadFileCallback>(data)));
provider->toItem(node.get()),
util::make_unique<DownloadFileCallback>(data)));
data->request_ = std::move(request);
MHD_Response* response = MHD_create_response_from_callback(
node->getSize(), BUFFER_SIZE, data_provider, data, release_data);
......@@ -177,7 +178,7 @@ int httpRequestCallback(void* cls, MHD_Connection* connection, const char*,
} // namespace
MegaNz::MegaNz()
: CloudProvider(make_unique<Auth>()),
: CloudProvider(util::make_unique<Auth>()),
mega_(),
authorized_(),
engine_(device_()),
......@@ -189,10 +190,10 @@ void MegaNz::initialize(InitData&& data) {
{
std::lock_guard<std::mutex> lock(auth_mutex());
if (data.hints_.find("client_id") == std::end(data.hints_))
mega_ = make_unique<MegaApi>("ZVhB0Czb");
mega_ = util::make_unique<MegaApi>("ZVhB0Czb");
else
setWithHint(data.hints_, "client_id", [this](std::string v) {
mega_ = make_unique<MegaApi>(v.c_str());
mega_ = util::make_unique<MegaApi>(v.c_str());
});
setWithHint(data.hints_, "daemon_port",
[this](std::string v) { daemon_port_ = std::atoi(v.c_str()); });
......@@ -212,7 +213,7 @@ std::string MegaNz::name() const { return "mega"; }
std::string MegaNz::endpoint() const { return "http://localhost"; }
IItem::Pointer MegaNz::rootDirectory() const {
return make_unique<Item>("root", "/", IItem::FileType::Directory);
return util::make_unique<Item>("root", "/", IItem::FileType::Directory);
}
ICloudProvider::Hints MegaNz::hints() const {
......@@ -224,7