2
* Copyright (C) 2016 Canonical Ltd
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU Lesser General Public License version 3 as
6
* published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU Lesser General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authors: Michi Henning <michi.henning@canonical.com>
21
#include <unity/storage/internal/ItemMetadata.h>
22
#include <unity/storage/qt/Account.h>
23
#include <unity/storage/qt/internal/AccountImpl.h>
24
#include <unity/storage/qt/internal/RuntimeImpl.h>
25
#include <unity/storage/qt/internal/StorageErrorImpl.h>
26
#include <unity/storage/qt/Item.h>
40
class ItemImpl : public std::enable_shared_from_this<ItemImpl>
44
ItemImpl(storage::internal::ItemMetadata const& md,
45
std::shared_ptr<AccountImpl> const& account_impl);
46
ItemImpl(ItemImpl const&) = default;
47
ItemImpl(ItemImpl&&) = delete;
48
~ItemImpl() = default;
49
ItemImpl& operator=(ItemImpl const&) = default;
50
ItemImpl& operator=(ItemImpl&&) = delete;
52
QString itemId() const;
54
Account account() const;
56
Item::Type type() const;
57
QVariantMap metadata() const;
58
qint64 sizeInBytes() const;
59
QDateTime lastModifiedTime() const;
60
QList<QString> parentIds() const;
62
ItemListJob* parents(QStringList const& keys) const;
63
ItemJob* copy(Item const& newParent, QString const& newName, QStringList const& keys) const;
64
ItemJob* move(Item const& newParent, QString const& newName, QStringList const& keys) const;
65
VoidJob* deleteItem() const;
66
Uploader* createUploader(Item::ConflictPolicy policy, qint64 sizeInBytes, QStringList const& keys) const;
67
Downloader* createDownloader(Item::ConflictPolicy policy) const;
68
ItemListJob* list(QStringList const& keys) const;
69
ItemListJob* lookup(QString const& name, QStringList const& keys) const;
70
ItemJob* createFolder(QString const& name, QStringList const& keys) const;
71
Uploader* createFile(QString const& name) const;
72
Uploader* createFile(QString const& name,
73
Item::ConflictPolicy policy,
75
QString const& contentType,
76
QStringList const& keys) const;
78
bool operator==(ItemImpl const&) const;
79
bool operator!=(ItemImpl const&) const;
80
bool operator<(ItemImpl const&) const;
81
bool operator<=(ItemImpl const&) const;
82
bool operator>(ItemImpl const&) const;
83
bool operator>=(ItemImpl const&) const;
87
static Item make_item(QString const& method,
88
storage::internal::ItemMetadata const& md,
89
std::shared_ptr<AccountImpl> const& account_impl);
91
std::shared_ptr<RuntimeImpl> runtime_impl() const;
92
std::shared_ptr<AccountImpl> account_impl() const;
96
decltype(T::make_job(StorageError())) check_invalid_or_destroyed(QString const& method) const;
99
decltype(T::make_job(StorageError())) check_copy_move_precondition(QString const& method,
100
Item const& newParent,
101
QString const& newName) const;
104
storage::internal::ItemMetadata md_;
105
std::shared_ptr<AccountImpl> account_impl_;
107
friend class unity::storage::qt::Item;
111
decltype(T::make_job(StorageError())) ItemImpl::check_invalid_or_destroyed(QString const& method) const
115
auto e = StorageErrorImpl::logic_error(method + ": cannot create job from invalid item");
116
return T::make_job(e);
118
auto runtime = account_impl_->runtime_impl();
119
if (!runtime || !runtime->isValid())
121
auto e = StorageErrorImpl::runtime_destroyed_error(method + ": Runtime was destroyed previously");
122
return T::make_job(e);
128
decltype(T::make_job(StorageError())) ItemImpl::check_copy_move_precondition(QString const& method,
129
Item const& newParent,
130
QString const& newName) const
132
auto invalid_job = check_invalid_or_destroyed<T>(method);
137
if (!newParent.isValid())
139
auto e = StorageErrorImpl::invalid_argument_error(method + ": newParent is invalid");
140
return T::make_job(e);
142
if (newName.isEmpty())
144
auto e = StorageErrorImpl::invalid_argument_error(method + ": newName cannot be empty");
145
return T::make_job(e);
147
if (account() != newParent.account())
149
auto e = StorageErrorImpl::logic_error(method + ": source and target must belong to the same account");
150
return T::make_job(e);
152
if (newParent.type() == Item::Type::File)
154
auto e = StorageErrorImpl::logic_error(method + ": newParent cannot be a file");
155
return T::make_job(e);
160
} // namespace internal
162
} // namespace storage