diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/clientapi.cpp | 2 | ||||
-rw-r--r-- | common/clientapi.h | 32 | ||||
-rw-r--r-- | common/resourceconfig.cpp | 33 | ||||
-rw-r--r-- | common/resourceconfig.h | 5 | ||||
-rw-r--r-- | common/resourcefacade.cpp | 14 |
5 files changed, 61 insertions, 25 deletions
diff --git a/common/clientapi.cpp b/common/clientapi.cpp index 88349db..06bf5ab 100644 --- a/common/clientapi.cpp +++ b/common/clientapi.cpp | |||
@@ -19,7 +19,7 @@ namespace Akonadi2 | |||
19 | 19 | ||
20 | void FacadeFactory::registerStaticFacades() | 20 | void FacadeFactory::registerStaticFacades() |
21 | { | 21 | { |
22 | FacadeFactory::instance().registerFacade<Akonadi2::ApplicationDomain::AkonadiResource, ResourceFacade>("resourceconfig"); | 22 | registerFacade<Akonadi2::ApplicationDomain::AkonadiResource, ResourceFacade>("resourceconfig"); |
23 | } | 23 | } |
24 | 24 | ||
25 | void Store::shutdown(const QByteArray &identifier) | 25 | void Store::shutdown(const QByteArray &identifier) |
diff --git a/common/clientapi.h b/common/clientapi.h index d658003..a01db23 100644 --- a/common/clientapi.h +++ b/common/clientapi.h | |||
@@ -34,6 +34,7 @@ | |||
34 | #include "threadboundary.h" | 34 | #include "threadboundary.h" |
35 | #include "resultprovider.h" | 35 | #include "resultprovider.h" |
36 | #include "domain/applicationdomaintype.h" | 36 | #include "domain/applicationdomaintype.h" |
37 | #include "resourceconfig.h" | ||
37 | 38 | ||
38 | namespace async { | 39 | namespace async { |
39 | //This should abstract if we execute from eventloop or in thread. | 40 | //This should abstract if we execute from eventloop or in thread. |
@@ -110,7 +111,7 @@ class FacadeFactory { | |||
110 | public: | 111 | public: |
111 | typedef std::function<std::shared_ptr<void>(const QByteArray &)> FactoryFunction; | 112 | typedef std::function<std::shared_ptr<void>(const QByteArray &)> FactoryFunction; |
112 | 113 | ||
113 | static void registerStaticFacades(); | 114 | void registerStaticFacades(); |
114 | 115 | ||
115 | //FIXME: proper singleton implementation | 116 | //FIXME: proper singleton implementation |
116 | static FacadeFactory &instance() | 117 | static FacadeFactory &instance() |
@@ -165,6 +166,11 @@ public: | |||
165 | } | 166 | } |
166 | 167 | ||
167 | private: | 168 | private: |
169 | FacadeFactory() | ||
170 | { | ||
171 | registerStaticFacades(); | ||
172 | } | ||
173 | |||
168 | QHash<QByteArray, FactoryFunction> mFacadeRegistry; | 174 | QHash<QByteArray, FactoryFunction> mFacadeRegistry; |
169 | }; | 175 | }; |
170 | 176 | ||
@@ -188,6 +194,27 @@ public: | |||
188 | return split.join('.'); | 194 | return split.join('.'); |
189 | } | 195 | } |
190 | 196 | ||
197 | static QList<QByteArray> getResources(const QList<QByteArray> &resourceFilter) | ||
198 | { | ||
199 | QList<QByteArray> resources; | ||
200 | const auto configuredResources = ResourceConfig::getResources(); | ||
201 | if (resourceFilter.isEmpty()) { | ||
202 | for (const auto &res : configuredResources) { | ||
203 | //TODO filter by type | ||
204 | resources << res; | ||
205 | } | ||
206 | } else { | ||
207 | for (const auto &res : resourceFilter) { | ||
208 | if (configuredResources.contains(res)) { | ||
209 | resources << res; | ||
210 | } else { | ||
211 | qWarning() << "Resource is not existing: " << res; | ||
212 | } | ||
213 | } | ||
214 | } | ||
215 | return resources; | ||
216 | } | ||
217 | |||
191 | /** | 218 | /** |
192 | * Asynchronusly load a dataset | 219 | * Asynchronusly load a dataset |
193 | */ | 220 | */ |
@@ -200,9 +227,8 @@ public: | |||
200 | //We must guarantee that the emitter is returned before the first result is emitted. | 227 | //We must guarantee that the emitter is returned before the first result is emitted. |
201 | //The result provider must be threadsafe. | 228 | //The result provider must be threadsafe. |
202 | async::run([query, resultSet](){ | 229 | async::run([query, resultSet](){ |
203 | //TODO if query.resources is empty, search for all resource that provide the type we're looking for | ||
204 | // Query all resources and aggregate results | 230 | // Query all resources and aggregate results |
205 | KAsync::iterate(query.resources) | 231 | KAsync::iterate(getResources(query.resources)) |
206 | .template each<void, QByteArray>([query, resultSet](const QByteArray &resource, KAsync::Future<void> &future) { | 232 | .template each<void, QByteArray>([query, resultSet](const QByteArray &resource, KAsync::Future<void> &future) { |
207 | //TODO pass resource identifier to factory | 233 | //TODO pass resource identifier to factory |
208 | auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceName(resource), resource); | 234 | auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceName(resource), resource); |
diff --git a/common/resourceconfig.cpp b/common/resourceconfig.cpp index 1f8fcda..ec72fb9 100644 --- a/common/resourceconfig.cpp +++ b/common/resourceconfig.cpp | |||
@@ -30,33 +30,38 @@ static QSharedPointer<QSettings> getSettings() | |||
30 | void ResourceConfig::addResource(const QByteArray &identifier, const QByteArray &type) | 30 | void ResourceConfig::addResource(const QByteArray &identifier, const QByteArray &type) |
31 | { | 31 | { |
32 | auto settings = getSettings(); | 32 | auto settings = getSettings(); |
33 | settings->beginGroup("resources"); | 33 | settings->beginGroup(QString::fromLatin1(identifier)); |
34 | settings->setValue(QString::fromLatin1(identifier), type); | 34 | settings->setValue("type", type); |
35 | settings->setValue("enabled", true); | ||
35 | settings->endGroup(); | 36 | settings->endGroup(); |
36 | // settings->beginGroup(identifier); | ||
37 | // //Add some settings? | ||
38 | // settings->endGroup(); | ||
39 | settings->sync(); | 37 | settings->sync(); |
40 | } | 38 | } |
41 | 39 | ||
42 | void ResourceConfig::removeResource(const QByteArray &identifier) | 40 | void ResourceConfig::removeResource(const QByteArray &identifier) |
43 | { | 41 | { |
44 | auto settings = getSettings(); | 42 | auto settings = getSettings(); |
45 | settings->beginGroup("resources"); | 43 | settings->beginGroup(QString::fromLatin1(identifier)); |
46 | settings->remove(QString::fromLatin1(identifier)); | 44 | settings->remove(""); |
47 | settings->endGroup(); | 45 | settings->endGroup(); |
48 | settings->sync(); | 46 | settings->sync(); |
49 | } | 47 | } |
50 | 48 | ||
51 | QList<QPair<QByteArray, QByteArray> > ResourceConfig::getResources() | 49 | QMap<QByteArray, QByteArray> ResourceConfig::getResources() |
52 | { | 50 | { |
53 | QList<QPair<QByteArray, QByteArray> > resources; | 51 | QMap<QByteArray, QByteArray> resources; |
54 | auto settings = getSettings(); | 52 | auto settings = getSettings(); |
55 | settings->beginGroup("resources"); | 53 | for (const auto &identifier : settings->childGroups()) { |
56 | for (const auto &identifier : settings->childKeys()) { | 54 | settings->beginGroup(identifier); |
57 | const auto type = settings->value(identifier).toByteArray(); | 55 | const auto type = settings->value("type").toByteArray(); |
58 | resources << qMakePair<QByteArray, QByteArray>(identifier.toLatin1(), type); | 56 | resources.insert(identifier.toLatin1(), type); |
57 | settings->endGroup(); | ||
59 | } | 58 | } |
60 | settings->endGroup(); | ||
61 | return resources; | 59 | return resources; |
62 | } | 60 | } |
61 | |||
62 | void ResourceConfig::clear() | ||
63 | { | ||
64 | auto settings = getSettings(); | ||
65 | settings->clear(); | ||
66 | settings->sync(); | ||
67 | } | ||
diff --git a/common/resourceconfig.h b/common/resourceconfig.h index eda870f..e1ba2bc 100644 --- a/common/resourceconfig.h +++ b/common/resourceconfig.h | |||
@@ -21,12 +21,13 @@ | |||
21 | 21 | ||
22 | #include <QList> | 22 | #include <QList> |
23 | #include <QByteArray> | 23 | #include <QByteArray> |
24 | #include <QPair> | 24 | #include <QMap> |
25 | 25 | ||
26 | class ResourceConfig | 26 | class ResourceConfig |
27 | { | 27 | { |
28 | public: | 28 | public: |
29 | static QList<QPair<QByteArray, QByteArray> > getResources(); | 29 | static QMap<QByteArray, QByteArray> getResources(); |
30 | static void addResource(const QByteArray &identifier, const QByteArray &type); | 30 | static void addResource(const QByteArray &identifier, const QByteArray &type); |
31 | static void removeResource(const QByteArray &identifier); | 31 | static void removeResource(const QByteArray &identifier); |
32 | static void clear(); | ||
32 | }; | 33 | }; |
diff --git a/common/resourcefacade.cpp b/common/resourcefacade.cpp index 63b3126..9792934 100644 --- a/common/resourcefacade.cpp +++ b/common/resourcefacade.cpp | |||
@@ -56,11 +56,15 @@ KAsync::Job<void> ResourceFacade::remove(const Akonadi2::ApplicationDomain::Akon | |||
56 | KAsync::Job<void> ResourceFacade::load(const Akonadi2::Query &query, const QSharedPointer<Akonadi2::ResultProvider<typename Akonadi2::ApplicationDomain::AkonadiResource::Ptr> > &resultProvider) | 56 | KAsync::Job<void> ResourceFacade::load(const Akonadi2::Query &query, const QSharedPointer<Akonadi2::ResultProvider<typename Akonadi2::ApplicationDomain::AkonadiResource::Ptr> > &resultProvider) |
57 | { | 57 | { |
58 | return KAsync::start<void>([query, resultProvider]() { | 58 | return KAsync::start<void>([query, resultProvider]() { |
59 | for (const auto &res : ResourceConfig::getResources()) { | 59 | const auto configuredResources = ResourceConfig::getResources(); |
60 | auto resource = Akonadi2::ApplicationDomain::AkonadiResource::Ptr::create(); | 60 | for (const auto &res : configuredResources.keys()) { |
61 | resource->setProperty("identifier", res.first); | 61 | const auto type = configuredResources.value(res); |
62 | resource->setProperty("type", res.second); | 62 | if (!query.propertyFilter.contains("type") || query.propertyFilter.value("type").toByteArray() == type) { |
63 | resultProvider->add(resource); | 63 | auto resource = Akonadi2::ApplicationDomain::AkonadiResource::Ptr::create(); |
64 | resource->setProperty("identifier", res); | ||
65 | resource->setProperty("type", type); | ||
66 | resultProvider->add(resource); | ||
67 | } | ||
64 | } | 68 | } |
65 | //TODO initialResultSetComplete should be implicit | 69 | //TODO initialResultSetComplete should be implicit |
66 | resultProvider->initialResultSetComplete(); | 70 | resultProvider->initialResultSetComplete(); |