diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-12-15 17:26:59 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-12-15 17:26:59 +0100 |
commit | 7bd037fae43c963d5f67e9447b3ee6875591a2c7 (patch) | |
tree | e2537369bb21d12e77668f0b2e878cffc1b9b423 | |
parent | 20b4d255509d5a490619afef50e49477ea09c71d (diff) | |
download | sink-7bd037fae43c963d5f67e9447b3ee6875591a2c7.tar.gz sink-7bd037fae43c963d5f67e9447b3ee6875591a2c7.zip |
Don't set capabilities as property on creation.
Instead we make it part of the plugin.
This ensure we also have access to the proper capabilities when creating
a resource via sinksh.
-rw-r--r-- | common/domain/applicationdomaintype.cpp | 5 | ||||
-rw-r--r-- | common/resource.cpp | 12 | ||||
-rw-r--r-- | common/resource.h | 3 | ||||
-rw-r--r-- | common/resourcefacade.cpp | 43 | ||||
-rw-r--r-- | examples/dummyresource/resourcefactory.cpp | 3 | ||||
-rw-r--r-- | examples/imapresource/imapresource.cpp | 9 | ||||
-rw-r--r-- | examples/maildirresource/maildirresource.cpp | 10 | ||||
-rw-r--r-- | examples/mailtransportresource/mailtransportresource.cpp | 2 | ||||
-rw-r--r-- | sinksh/sinksh_utils.cpp | 2 | ||||
-rw-r--r-- | tests/mailsynctest.cpp | 4 | ||||
-rw-r--r-- | tests/mailtest.cpp | 3 |
11 files changed, 70 insertions, 26 deletions
diff --git a/common/domain/applicationdomaintype.cpp b/common/domain/applicationdomaintype.cpp index c59a01e..60f5311 100644 --- a/common/domain/applicationdomaintype.cpp +++ b/common/domain/applicationdomaintype.cpp | |||
@@ -297,8 +297,6 @@ SinkResource DummyResource::create(const QByteArray &account) | |||
297 | auto &&resource = ApplicationDomainType::createEntity<SinkResource>(); | 297 | auto &&resource = ApplicationDomainType::createEntity<SinkResource>(); |
298 | resource.setResourceType("sink.dummy"); | 298 | resource.setResourceType("sink.dummy"); |
299 | resource.setAccount(account); | 299 | resource.setAccount(account); |
300 | resource.setCapabilities(QByteArrayList() << ResourceCapabilities::Mail::storage << "-folder.rename" << ResourceCapabilities::Mail::sent); | ||
301 | // resource.setProperty("capabilities", QVariant::fromValue(QByteArrayList() << ResourceCapabilities::Mail::storage << ResourceCapabilities::Mail::drafts << "-folder.rename" << ResourceCapabilities::Mail::trash)); | ||
302 | return resource; | 300 | return resource; |
303 | } | 301 | } |
304 | 302 | ||
@@ -307,7 +305,6 @@ SinkResource MaildirResource::create(const QByteArray &account) | |||
307 | auto &&resource = ApplicationDomainType::createEntity<SinkResource>(); | 305 | auto &&resource = ApplicationDomainType::createEntity<SinkResource>(); |
308 | resource.setResourceType("sink.maildir"); | 306 | resource.setResourceType("sink.maildir"); |
309 | resource.setAccount(account); | 307 | resource.setAccount(account); |
310 | resource.setCapabilities(QByteArrayList() << ResourceCapabilities::Mail::storage << ResourceCapabilities::Mail::drafts << "-folder.rename" << ResourceCapabilities::Mail::trash << ResourceCapabilities::Mail::sent); | ||
311 | return resource; | 308 | return resource; |
312 | } | 309 | } |
313 | 310 | ||
@@ -316,7 +313,6 @@ SinkResource MailtransportResource::create(const QByteArray &account) | |||
316 | auto &&resource = ApplicationDomainType::createEntity<SinkResource>(); | 313 | auto &&resource = ApplicationDomainType::createEntity<SinkResource>(); |
317 | resource.setResourceType("sink.mailtransport"); | 314 | resource.setResourceType("sink.mailtransport"); |
318 | resource.setAccount(account); | 315 | resource.setAccount(account); |
319 | resource.setCapabilities(QByteArrayList() << ResourceCapabilities::Mail::transport); | ||
320 | return resource; | 316 | return resource; |
321 | } | 317 | } |
322 | 318 | ||
@@ -325,7 +321,6 @@ SinkResource ImapResource::create(const QByteArray &account) | |||
325 | auto &&resource = ApplicationDomainType::createEntity<SinkResource>(); | 321 | auto &&resource = ApplicationDomainType::createEntity<SinkResource>(); |
326 | resource.setResourceType("sink.imap"); | 322 | resource.setResourceType("sink.imap"); |
327 | resource.setAccount(account); | 323 | resource.setAccount(account); |
328 | resource.setCapabilities(QByteArrayList() << ResourceCapabilities::Mail::storage << ResourceCapabilities::Mail::drafts << ResourceCapabilities::Mail::folderhierarchy << ResourceCapabilities::Mail::trash << ResourceCapabilities::Mail::sent); | ||
329 | return resource; | 324 | return resource; |
330 | } | 325 | } |
331 | 326 | ||
diff --git a/common/resource.cpp b/common/resource.cpp index 533a132..32a92ca 100644 --- a/common/resource.cpp +++ b/common/resource.cpp | |||
@@ -55,19 +55,20 @@ void Resource::setLowerBoundRevision(qint64 revision) | |||
55 | class ResourceFactory::Private | 55 | class ResourceFactory::Private |
56 | { | 56 | { |
57 | public: | 57 | public: |
58 | QByteArrayList capabilities; | ||
58 | static QHash<QString, QPointer<ResourceFactory>> s_loadedFactories; | 59 | static QHash<QString, QPointer<ResourceFactory>> s_loadedFactories; |
59 | }; | 60 | }; |
60 | 61 | ||
61 | QHash<QString, QPointer<ResourceFactory>> ResourceFactory::Private::s_loadedFactories; | 62 | QHash<QString, QPointer<ResourceFactory>> ResourceFactory::Private::s_loadedFactories; |
62 | 63 | ||
63 | ResourceFactory::ResourceFactory(QObject *parent) : QObject(parent), d(0) | 64 | ResourceFactory::ResourceFactory(QObject *parent, const QByteArrayList &capabilities) : QObject(parent), d(new ResourceFactory::Private) |
64 | { | 65 | { |
65 | Q_UNUSED(d); | 66 | d->capabilities = capabilities; |
66 | } | 67 | } |
67 | 68 | ||
68 | ResourceFactory::~ResourceFactory() | 69 | ResourceFactory::~ResourceFactory() |
69 | { | 70 | { |
70 | // delete d; | 71 | delete d; |
71 | } | 72 | } |
72 | 73 | ||
73 | ResourceFactory *ResourceFactory::load(const QByteArray &resourceName) | 74 | ResourceFactory *ResourceFactory::load(const QByteArray &resourceName) |
@@ -117,6 +118,11 @@ ResourceFactory *ResourceFactory::load(const QByteArray &resourceName) | |||
117 | return nullptr; | 118 | return nullptr; |
118 | } | 119 | } |
119 | 120 | ||
121 | QByteArrayList ResourceFactory::capabilities() const | ||
122 | { | ||
123 | return d->capabilities; | ||
124 | } | ||
125 | |||
120 | } // namespace Sink | 126 | } // namespace Sink |
121 | 127 | ||
122 | // Ignore warning I don't know how to fix in a moc file | 128 | // Ignore warning I don't know how to fix in a moc file |
diff --git a/common/resource.h b/common/resource.h index 7789c53..d756521 100644 --- a/common/resource.h +++ b/common/resource.h | |||
@@ -64,13 +64,14 @@ class SINK_EXPORT ResourceFactory : public QObject | |||
64 | public: | 64 | public: |
65 | static ResourceFactory *load(const QByteArray &resourceName); | 65 | static ResourceFactory *load(const QByteArray &resourceName); |
66 | 66 | ||
67 | ResourceFactory(QObject *parent); | 67 | ResourceFactory(QObject *parent, const QByteArrayList &capabilities); |
68 | virtual ~ResourceFactory(); | 68 | virtual ~ResourceFactory(); |
69 | 69 | ||
70 | virtual Resource *createResource(const ResourceContext &context) = 0; | 70 | virtual Resource *createResource(const ResourceContext &context) = 0; |
71 | virtual void registerFacades(const QByteArray &resourceName, FacadeFactory &factory) = 0; | 71 | virtual void registerFacades(const QByteArray &resourceName, FacadeFactory &factory) = 0; |
72 | virtual void registerAdaptorFactories(const QByteArray &resourceName, AdaptorFactoryRegistry ®istry) {}; | 72 | virtual void registerAdaptorFactories(const QByteArray &resourceName, AdaptorFactoryRegistry ®istry) {}; |
73 | virtual void removeDataFromDisk(const QByteArray &instanceIdentifier) = 0; | 73 | virtual void removeDataFromDisk(const QByteArray &instanceIdentifier) = 0; |
74 | QByteArrayList capabilities() const; | ||
74 | 75 | ||
75 | private: | 76 | private: |
76 | class Private; | 77 | class Private; |
diff --git a/common/resourcefacade.cpp b/common/resourcefacade.cpp index c4e16b1..ea4218d 100644 --- a/common/resourcefacade.cpp +++ b/common/resourcefacade.cpp | |||
@@ -24,6 +24,7 @@ | |||
24 | #include "storage.h" | 24 | #include "storage.h" |
25 | #include "store.h" | 25 | #include "store.h" |
26 | #include "resourceaccess.h" | 26 | #include "resourceaccess.h" |
27 | #include "resource.h" | ||
27 | #include <QDir> | 28 | #include <QDir> |
28 | 29 | ||
29 | using namespace Sink; | 30 | using namespace Sink; |
@@ -33,25 +34,50 @@ SINK_DEBUG_AREA("ResourceFacade") | |||
33 | template<typename DomainType> | 34 | template<typename DomainType> |
34 | ConfigNotifier LocalStorageFacade<DomainType>::sConfigNotifier; | 35 | ConfigNotifier LocalStorageFacade<DomainType>::sConfigNotifier; |
35 | 36 | ||
37 | static void applyConfig(ConfigStore &configStore, const QByteArray &id, ApplicationDomain::ApplicationDomainType &object) | ||
38 | { | ||
39 | const auto configurationValues = configStore.get(id); | ||
40 | for (auto it = configurationValues.constBegin(); it != configurationValues.constEnd(); it++) { | ||
41 | object.setProperty(it.key(), it.value()); | ||
42 | } | ||
43 | } | ||
44 | |||
36 | template <typename DomainType> | 45 | template <typename DomainType> |
37 | static typename DomainType::Ptr readFromConfig(ConfigStore &configStore, const QByteArray &id, const QByteArray &type) | 46 | static typename DomainType::Ptr readFromConfig(ConfigStore &configStore, const QByteArray &id, const QByteArray &type) |
38 | { | 47 | { |
39 | auto object = DomainType::Ptr::create(id); | 48 | auto object = DomainType::Ptr::create(id); |
49 | applyConfig(configStore, id, *object); | ||
50 | return object; | ||
51 | } | ||
52 | |||
53 | template <> | ||
54 | typename ApplicationDomain::SinkAccount::Ptr readFromConfig<ApplicationDomain::SinkAccount>(ConfigStore &configStore, const QByteArray &id, const QByteArray &type) | ||
55 | { | ||
56 | auto object = ApplicationDomain::SinkAccount::Ptr::create(id); | ||
57 | object->setProperty(ApplicationDomain::SinkAccount::AccountType::name, type); | ||
58 | applyConfig(configStore, id, *object); | ||
59 | return object; | ||
60 | } | ||
61 | |||
62 | template <> | ||
63 | typename ApplicationDomain::SinkResource::Ptr readFromConfig<ApplicationDomain::SinkResource>(ConfigStore &configStore, const QByteArray &id, const QByteArray &type) | ||
64 | { | ||
65 | auto object = ApplicationDomain::SinkResource::Ptr::create(id); | ||
40 | object->setProperty(ApplicationDomain::SinkResource::ResourceType::name, type); | 66 | object->setProperty(ApplicationDomain::SinkResource::ResourceType::name, type); |
41 | const auto configurationValues = configStore.get(id); | 67 | if (auto res = ResourceFactory::load(type)) { |
42 | for (auto it = configurationValues.constBegin(); it != configurationValues.constEnd(); it++) { | 68 | object->setCapabilities(res->capabilities()); |
43 | object->setProperty(it.key(), it.value()); | ||
44 | } | 69 | } |
70 | applyConfig(configStore, id, *object); | ||
45 | return object; | 71 | return object; |
46 | } | 72 | } |
47 | 73 | ||
48 | static bool matchesFilter(const QHash<QByteArray, Query::Comparator> &filter, const QMap<QByteArray, QVariant> &properties) | 74 | static bool matchesFilter(const QHash<QByteArray, Query::Comparator> &filter, const ApplicationDomain::ApplicationDomainType &entity) |
49 | { | 75 | { |
50 | for (const auto &filterProperty : filter.keys()) { | 76 | for (const auto &filterProperty : filter.keys()) { |
51 | if (filterProperty == ApplicationDomain::SinkResource::ResourceType::name) { | 77 | if (filterProperty == ApplicationDomain::SinkResource::ResourceType::name) { |
52 | continue; | 78 | continue; |
53 | } | 79 | } |
54 | if (!filter.value(filterProperty).matches(properties.value(filterProperty))) { | 80 | if (!filter.value(filterProperty).matches(entity.getProperty(filterProperty))) { |
55 | return false; | 81 | return false; |
56 | } | 82 | } |
57 | } | 83 | } |
@@ -75,13 +101,12 @@ LocalStorageQueryRunner<DomainType>::LocalStorageQueryRunner(const Query &query, | |||
75 | if (!query.ids().isEmpty() && !query.ids().contains(res)) { | 101 | if (!query.ids().isEmpty() && !query.ids().contains(res)) { |
76 | continue; | 102 | continue; |
77 | } | 103 | } |
78 | const auto configurationValues = mConfigStore.get(res); | 104 | auto entity = readFromConfig<DomainType>(mConfigStore, res, type); |
79 | if (!matchesFilter(query.getBaseFilters(), configurationValues)){ | 105 | if (!matchesFilter(query.getBaseFilters(), *entity)){ |
80 | SinkTrace() << "Skipping due to filter."; | 106 | SinkTrace() << "Skipping due to filter." << res; |
81 | continue; | 107 | continue; |
82 | } | 108 | } |
83 | SinkTrace() << "Found match " << res; | 109 | SinkTrace() << "Found match " << res; |
84 | auto entity = readFromConfig<DomainType>(mConfigStore, res, type); | ||
85 | updateStatus(*entity); | 110 | updateStatus(*entity); |
86 | mResultProvider->add(entity); | 111 | mResultProvider->add(entity); |
87 | } | 112 | } |
diff --git a/examples/dummyresource/resourcefactory.cpp b/examples/dummyresource/resourcefactory.cpp index 03238ef..0663bdb 100644 --- a/examples/dummyresource/resourcefactory.cpp +++ b/examples/dummyresource/resourcefactory.cpp | |||
@@ -176,7 +176,7 @@ DummyResource::~DummyResource() | |||
176 | } | 176 | } |
177 | 177 | ||
178 | DummyResourceFactory::DummyResourceFactory(QObject *parent) | 178 | DummyResourceFactory::DummyResourceFactory(QObject *parent) |
179 | : Sink::ResourceFactory(parent) | 179 | : Sink::ResourceFactory(parent, QByteArrayList() << Sink::ApplicationDomain::ResourceCapabilities::Mail::storage << "-folder.rename" << Sink::ApplicationDomain::ResourceCapabilities::Mail::sent) |
180 | { | 180 | { |
181 | 181 | ||
182 | } | 182 | } |
@@ -204,3 +204,4 @@ void DummyResourceFactory::removeDataFromDisk(const QByteArray &instanceIdentifi | |||
204 | { | 204 | { |
205 | DummyResource::removeFromDisk(instanceIdentifier); | 205 | DummyResource::removeFromDisk(instanceIdentifier); |
206 | } | 206 | } |
207 | |||
diff --git a/examples/imapresource/imapresource.cpp b/examples/imapresource/imapresource.cpp index 252b910..04781ef 100644 --- a/examples/imapresource/imapresource.cpp +++ b/examples/imapresource/imapresource.cpp | |||
@@ -742,7 +742,13 @@ ImapResource::ImapResource(const ResourceContext &resourceContext) | |||
742 | } | 742 | } |
743 | 743 | ||
744 | ImapResourceFactory::ImapResourceFactory(QObject *parent) | 744 | ImapResourceFactory::ImapResourceFactory(QObject *parent) |
745 | : Sink::ResourceFactory(parent) | 745 | : Sink::ResourceFactory(parent, |
746 | {Sink::ApplicationDomain::ResourceCapabilities::Mail::storage, | ||
747 | Sink::ApplicationDomain::ResourceCapabilities::Mail::drafts, | ||
748 | Sink::ApplicationDomain::ResourceCapabilities::Mail::folderhierarchy, | ||
749 | Sink::ApplicationDomain::ResourceCapabilities::Mail::trash, | ||
750 | Sink::ApplicationDomain::ResourceCapabilities::Mail::sent} | ||
751 | ) | ||
746 | { | 752 | { |
747 | 753 | ||
748 | } | 754 | } |
@@ -768,3 +774,4 @@ void ImapResourceFactory::removeDataFromDisk(const QByteArray &instanceIdentifie | |||
768 | { | 774 | { |
769 | ImapResource::removeFromDisk(instanceIdentifier); | 775 | ImapResource::removeFromDisk(instanceIdentifier); |
770 | } | 776 | } |
777 | |||
diff --git a/examples/maildirresource/maildirresource.cpp b/examples/maildirresource/maildirresource.cpp index 6a03263..997ddef 100644 --- a/examples/maildirresource/maildirresource.cpp +++ b/examples/maildirresource/maildirresource.cpp | |||
@@ -570,9 +570,14 @@ MaildirResource::MaildirResource(const Sink::ResourceContext &resourceContext) | |||
570 | 570 | ||
571 | 571 | ||
572 | MaildirResourceFactory::MaildirResourceFactory(QObject *parent) | 572 | MaildirResourceFactory::MaildirResourceFactory(QObject *parent) |
573 | : Sink::ResourceFactory(parent) | 573 | : Sink::ResourceFactory(parent, |
574 | {Sink::ApplicationDomain::ResourceCapabilities::Mail::storage, | ||
575 | Sink::ApplicationDomain::ResourceCapabilities::Mail::drafts, | ||
576 | "-folder.rename", | ||
577 | Sink::ApplicationDomain::ResourceCapabilities::Mail::trash, | ||
578 | Sink::ApplicationDomain::ResourceCapabilities::Mail::sent} | ||
579 | ) | ||
574 | { | 580 | { |
575 | |||
576 | } | 581 | } |
577 | 582 | ||
578 | Sink::Resource *MaildirResourceFactory::createResource(const ResourceContext &context) | 583 | Sink::Resource *MaildirResourceFactory::createResource(const ResourceContext &context) |
@@ -596,4 +601,3 @@ void MaildirResourceFactory::removeDataFromDisk(const QByteArray &instanceIdenti | |||
596 | { | 601 | { |
597 | MaildirResource::removeFromDisk(instanceIdentifier); | 602 | MaildirResource::removeFromDisk(instanceIdentifier); |
598 | } | 603 | } |
599 | |||
diff --git a/examples/mailtransportresource/mailtransportresource.cpp b/examples/mailtransportresource/mailtransportresource.cpp index b7ee77a..cf657f3 100644 --- a/examples/mailtransportresource/mailtransportresource.cpp +++ b/examples/mailtransportresource/mailtransportresource.cpp | |||
@@ -186,7 +186,7 @@ MailtransportResource::MailtransportResource(const Sink::ResourceContext &resour | |||
186 | } | 186 | } |
187 | 187 | ||
188 | MailtransportResourceFactory::MailtransportResourceFactory(QObject *parent) | 188 | MailtransportResourceFactory::MailtransportResourceFactory(QObject *parent) |
189 | : Sink::ResourceFactory(parent) | 189 | : Sink::ResourceFactory(parent, {Sink::ApplicationDomain::ResourceCapabilities::Mail::transport}) |
190 | { | 190 | { |
191 | 191 | ||
192 | } | 192 | } |
diff --git a/sinksh/sinksh_utils.cpp b/sinksh/sinksh_utils.cpp index c42fad3..1ee5997 100644 --- a/sinksh/sinksh_utils.cpp +++ b/sinksh/sinksh_utils.cpp | |||
@@ -76,7 +76,7 @@ QList<QByteArray> requestedProperties(const QString &type) | |||
76 | } else if (type == getTypeName<Event>()) { | 76 | } else if (type == getTypeName<Event>()) { |
77 | return QList<QByteArray>() << Event::Summary::name; | 77 | return QList<QByteArray>() << Event::Summary::name; |
78 | } else if (type == getTypeName<SinkResource>()) { | 78 | } else if (type == getTypeName<SinkResource>()) { |
79 | return QList<QByteArray>() << SinkResource::ResourceType::name << SinkResource::Account::name; | 79 | return QList<QByteArray>() << SinkResource::ResourceType::name << SinkResource::Account::name << SinkResource::Capabilities::name; |
80 | } else if (type == getTypeName<SinkAccount>()) { | 80 | } else if (type == getTypeName<SinkAccount>()) { |
81 | return QList<QByteArray>() << SinkAccount::AccountType::name << SinkAccount::Name::name; | 81 | return QList<QByteArray>() << SinkAccount::AccountType::name << SinkAccount::Name::name; |
82 | } else if (type == getTypeName<Identity>()) { | 82 | } else if (type == getTypeName<Identity>()) { |
diff --git a/tests/mailsynctest.cpp b/tests/mailsynctest.cpp index 6658d8b..31e40c4 100644 --- a/tests/mailsynctest.cpp +++ b/tests/mailsynctest.cpp | |||
@@ -46,7 +46,9 @@ void MailSyncTest::initTestCase() | |||
46 | VERIFYEXEC(Store::create(resource)); | 46 | VERIFYEXEC(Store::create(resource)); |
47 | 47 | ||
48 | mResourceInstanceIdentifier = resource.identifier(); | 48 | mResourceInstanceIdentifier = resource.identifier(); |
49 | mCapabilities = resource.getProperty("capabilities").value<QByteArrayList>(); | 49 | //Load the capabilities |
50 | resource = Store::readOne<Sink::ApplicationDomain::SinkResource>(Sink::Query{resource}); | ||
51 | mCapabilities = resource.getCapabilities(); | ||
50 | } | 52 | } |
51 | 53 | ||
52 | void MailSyncTest::cleanup() | 54 | void MailSyncTest::cleanup() |
diff --git a/tests/mailtest.cpp b/tests/mailtest.cpp index ae5295e..fe28cde 100644 --- a/tests/mailtest.cpp +++ b/tests/mailtest.cpp | |||
@@ -45,6 +45,9 @@ void MailTest::initTestCase() | |||
45 | VERIFYEXEC(Store::create(resource)); | 45 | VERIFYEXEC(Store::create(resource)); |
46 | 46 | ||
47 | mResourceInstanceIdentifier = resource.identifier(); | 47 | mResourceInstanceIdentifier = resource.identifier(); |
48 | |||
49 | //Load the capabilities | ||
50 | resource = Store::readOne<Sink::ApplicationDomain::SinkResource>(Sink::Query{resource}); | ||
48 | mCapabilities = resource.getCapabilities(); | 51 | mCapabilities = resource.getCapabilities(); |
49 | } | 52 | } |
50 | 53 | ||