diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-05-09 22:17:28 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-05-09 22:17:28 +0200 |
commit | 4999ec5da028e3b11d9c7b7bc0fe25acdf0a8ddd (patch) | |
tree | 804bc7b4d6469245e84c63d32bd8ffcd19a36033 | |
parent | 367d167aa4d19e43669a42c198d941476f340800 (diff) | |
download | sink-4999ec5da028e3b11d9c7b7bc0fe25acdf0a8ddd.tar.gz sink-4999ec5da028e3b11d9c7b7bc0fe25acdf0a8ddd.zip |
Resource factory methods and capability filter.
-rw-r--r-- | common/domain/applicationdomaintype.cpp | 22 | ||||
-rw-r--r-- | common/domain/applicationdomaintype.h | 7 | ||||
-rw-r--r-- | common/query.cpp | 4 | ||||
-rw-r--r-- | common/query.h | 14 | ||||
-rw-r--r-- | common/test.cpp | 1 |
5 files changed, 45 insertions, 3 deletions
diff --git a/common/domain/applicationdomaintype.cpp b/common/domain/applicationdomaintype.cpp index 27f94ce..166d3e6 100644 --- a/common/domain/applicationdomaintype.cpp +++ b/common/domain/applicationdomaintype.cpp | |||
@@ -239,6 +239,28 @@ Identity::~Identity() | |||
239 | 239 | ||
240 | } | 240 | } |
241 | 241 | ||
242 | namespace MaildirResource { | ||
243 | SinkResource create(const QByteArray &account) | ||
244 | { | ||
245 | auto &&resource = ApplicationDomainType::createEntity<SinkResource>(); | ||
246 | resource.setProperty("type", "org.kde.maildir"); | ||
247 | resource.setProperty("account", account); | ||
248 | resource.setProperty("capabilities", QVariant::fromValue(QByteArrayList() << "storage" << "drafts")); | ||
249 | return resource; | ||
250 | } | ||
251 | } | ||
252 | |||
253 | namespace MailtransportResource { | ||
254 | SinkResource create(const QByteArray &account) | ||
255 | { | ||
256 | auto &&resource = ApplicationDomainType::createEntity<SinkResource>(); | ||
257 | resource.setProperty("type", "org.kde.mailtransport"); | ||
258 | resource.setProperty("account", account); | ||
259 | resource.setProperty("capabilities", QVariant::fromValue(QByteArrayList() << "transport")); | ||
260 | return resource; | ||
261 | } | ||
262 | } | ||
263 | |||
242 | template<> | 264 | template<> |
243 | QByteArray getTypeName<Event>() | 265 | QByteArray getTypeName<Event>() |
244 | { | 266 | { |
diff --git a/common/domain/applicationdomaintype.h b/common/domain/applicationdomaintype.h index 1486f00..eadad00 100644 --- a/common/domain/applicationdomaintype.h +++ b/common/domain/applicationdomaintype.h | |||
@@ -187,6 +187,13 @@ struct SINK_EXPORT Identity : public ApplicationDomainType { | |||
187 | virtual ~Identity(); | 187 | virtual ~Identity(); |
188 | }; | 188 | }; |
189 | 189 | ||
190 | namespace MaildirResource { | ||
191 | SinkResource SINK_EXPORT create(const QByteArray &account); | ||
192 | }; | ||
193 | namespace MailtransportResource { | ||
194 | SinkResource SINK_EXPORT create(const QByteArray &account); | ||
195 | }; | ||
196 | |||
190 | /** | 197 | /** |
191 | * All types need to be registered here an MUST return a different name. | 198 | * All types need to be registered here an MUST return a different name. |
192 | * | 199 | * |
diff --git a/common/query.cpp b/common/query.cpp index eeacd69..5f93c82 100644 --- a/common/query.cpp +++ b/common/query.cpp | |||
@@ -42,6 +42,10 @@ Query::Comparator::Comparator(const QVariant &v) : value(v), comparator(Equals) | |||
42 | { | 42 | { |
43 | } | 43 | } |
44 | 44 | ||
45 | Query::Comparator::Comparator(const QVariant &v, Comparators c) : value(v), comparator(c) | ||
46 | { | ||
47 | } | ||
48 | |||
45 | bool Query::Comparator::matches(const QVariant &v) const | 49 | bool Query::Comparator::matches(const QVariant &v) const |
46 | { | 50 | { |
47 | switch(comparator) { | 51 | switch(comparator) { |
diff --git a/common/query.h b/common/query.h index 5c0d5c9..8a420f9 100644 --- a/common/query.h +++ b/common/query.h | |||
@@ -35,7 +35,7 @@ class SINK_EXPORT Query | |||
35 | public: | 35 | public: |
36 | enum Flag | 36 | enum Flag |
37 | { | 37 | { |
38 | /** Leave the query running an contiously update the result set. */ | 38 | /** Leave the query running and continuously update the result set. */ |
39 | LiveQuery | 39 | LiveQuery |
40 | }; | 40 | }; |
41 | Q_DECLARE_FLAGS(Flags, Flag) | 41 | Q_DECLARE_FLAGS(Flags, Flag) |
@@ -43,14 +43,14 @@ public: | |||
43 | static Query PropertyFilter(const QByteArray &key, const QVariant &value) | 43 | static Query PropertyFilter(const QByteArray &key, const QVariant &value) |
44 | { | 44 | { |
45 | Query query; | 45 | Query query; |
46 | query.propertyFilter.insert(key, value); | 46 | query.propertyFilter.insert(key, Comparator(value)); |
47 | return query; | 47 | return query; |
48 | } | 48 | } |
49 | 49 | ||
50 | static Query PropertyContainsFilter(const QByteArray &key, const QVariant &value) | 50 | static Query PropertyContainsFilter(const QByteArray &key, const QVariant &value) |
51 | { | 51 | { |
52 | Query query; | 52 | Query query; |
53 | query.propertyFilter.insert(key, value); | 53 | query.propertyFilter.insert(key, Comparator(value, Comparator::Contains)); |
54 | return query; | 54 | return query; |
55 | } | 55 | } |
56 | 56 | ||
@@ -85,6 +85,13 @@ public: | |||
85 | return query; | 85 | return query; |
86 | } | 86 | } |
87 | 87 | ||
88 | static Query CapabilityFilter(const QByteArray &capability) | ||
89 | { | ||
90 | Query query; | ||
91 | query.propertyFilter.insert("capabilities", Comparator(capability, Comparator::Contains)); | ||
92 | return query; | ||
93 | } | ||
94 | |||
88 | static Query AccountFilter(const QByteArrayList &identifier) | 95 | static Query AccountFilter(const QByteArrayList &identifier) |
89 | { | 96 | { |
90 | Q_ASSERT(!identifier.isEmpty()); | 97 | Q_ASSERT(!identifier.isEmpty()); |
@@ -167,6 +174,7 @@ public: | |||
167 | 174 | ||
168 | Comparator(); | 175 | Comparator(); |
169 | Comparator(const QVariant &v); | 176 | Comparator(const QVariant &v); |
177 | Comparator(const QVariant &v, Comparators c); | ||
170 | bool matches(const QVariant &v) const; | 178 | bool matches(const QVariant &v) const; |
171 | 179 | ||
172 | QVariant value; | 180 | QVariant value; |
diff --git a/common/test.cpp b/common/test.cpp index c4dac89..1062e21 100644 --- a/common/test.cpp +++ b/common/test.cpp | |||
@@ -127,6 +127,7 @@ Test::TestAccount Sink::Test::TestAccount::registerAccount() | |||
127 | ResourceConfig::addResource(account.identifier, "testresource"); | 127 | ResourceConfig::addResource(account.identifier, "testresource"); |
128 | QMap<QByteArray, QVariant> configuration; | 128 | QMap<QByteArray, QVariant> configuration; |
129 | configuration.insert("account", account.identifier); | 129 | configuration.insert("account", account.identifier); |
130 | configuration.insert("capabilities", QVariant::fromValue(QByteArrayList() << "drafts" << "storage" << "transport")); | ||
130 | ResourceConfig::configureResource(account.identifier, configuration); | 131 | ResourceConfig::configureResource(account.identifier, configuration); |
131 | return account; | 132 | return account; |
132 | } | 133 | } |