diff options
-rw-r--r-- | examples/dummyresource/CMakeLists.txt | 2 | ||||
-rw-r--r-- | examples/dummyresource/resourcefacade.cpp | 83 | ||||
-rw-r--r-- | examples/dummyresource/resourcefacade.h | 43 |
3 files changed, 127 insertions, 1 deletions
diff --git a/examples/dummyresource/CMakeLists.txt b/examples/dummyresource/CMakeLists.txt index abd315f..5e911d2 100644 --- a/examples/dummyresource/CMakeLists.txt +++ b/examples/dummyresource/CMakeLists.txt | |||
@@ -5,7 +5,7 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) | |||
5 | 5 | ||
6 | generate_flatbuffers(dummycalendar) | 6 | generate_flatbuffers(dummycalendar) |
7 | 7 | ||
8 | add_library(${PROJECT_NAME} SHARED facade.cpp resourcefactory.cpp domainadaptor.cpp) | 8 | add_library(${PROJECT_NAME} SHARED facade.cpp resourcefactory.cpp domainadaptor.cpp resourcefacade.cpp) |
9 | qt5_use_modules(${PROJECT_NAME} Core Network) | 9 | qt5_use_modules(${PROJECT_NAME} Core Network) |
10 | target_link_libraries(${PROJECT_NAME} akonadi2common) | 10 | target_link_libraries(${PROJECT_NAME} akonadi2common) |
11 | 11 | ||
diff --git a/examples/dummyresource/resourcefacade.cpp b/examples/dummyresource/resourcefacade.cpp new file mode 100644 index 0000000..870bea2 --- /dev/null +++ b/examples/dummyresource/resourcefacade.cpp | |||
@@ -0,0 +1,83 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2014 Christian Mollekopf <chrigi_1@fastmail.fm> | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License as published by | ||
6 | * the Free Software Foundation; either version 2 of the License, or | ||
7 | * (at your option) any later version. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program; if not, write to the | ||
16 | * Free Software Foundation, Inc., | ||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
18 | */ | ||
19 | |||
20 | #include "resourcefacade.h" | ||
21 | |||
22 | #include <QSettings> | ||
23 | |||
24 | DummyResourceConfigFacade::DummyResourceConfigFacade() | ||
25 | : Akonadi2::StoreFacade<Akonadi2::ApplicationDomain::AkonadiResource>() | ||
26 | { | ||
27 | |||
28 | } | ||
29 | |||
30 | DummyResourceConfigFacade::~DummyResourceConfigFacade() | ||
31 | { | ||
32 | |||
33 | } | ||
34 | |||
35 | QSharedPointer<QSettings> DummyResourceConfigFacade::getSettings() | ||
36 | { | ||
37 | //FIXME deal with resource instances | ||
38 | const QString instanceIdentifier = "dummyresource.instance1"; | ||
39 | //FIXME Use config location | ||
40 | return QSharedPointer<QSettings>::create(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/akonadi2/" + "org.kde." + instanceIdentifier + "/settings.ini", QSettings::IniFormat); | ||
41 | } | ||
42 | |||
43 | Async::Job<void> DummyResourceConfigFacade::create(const Akonadi2::ApplicationDomain::AkonadiResource &domainObject) | ||
44 | { | ||
45 | //TODO create resource instance | ||
46 | //This can be generalized in a base implementation | ||
47 | return Async::null<void>(); | ||
48 | } | ||
49 | |||
50 | Async::Job<void> DummyResourceConfigFacade::modify(const Akonadi2::ApplicationDomain::AkonadiResource &domainObject) | ||
51 | { | ||
52 | //modify configuration | ||
53 | //This part is likely resource specific, but could be partially generalized | ||
54 | return Async::start<void>([domainObject, this]() { | ||
55 | auto settings = getSettings(); | ||
56 | //TODO Write properties to file | ||
57 | }); | ||
58 | } | ||
59 | |||
60 | Async::Job<void> DummyResourceConfigFacade::remove(const Akonadi2::ApplicationDomain::AkonadiResource &domainObject) | ||
61 | { | ||
62 | //TODO remove resource instance | ||
63 | //This can be generalized in a base implementation | ||
64 | return Async::null<void>(); | ||
65 | } | ||
66 | |||
67 | Async::Job<void> DummyResourceConfigFacade::load(const Akonadi2::Query &query, const QSharedPointer<async::ResultProvider<typename Akonadi2::ApplicationDomain::AkonadiResource::Ptr> > &resultProvider) | ||
68 | { | ||
69 | //Read configuration and list all available instances. | ||
70 | //This includes runtime information about runing instances etc. | ||
71 | //Part of this is generic, and part is accessing the resource specific configuration. | ||
72 | //FIXME this currently does not support live queries (because we're not inheriting from GenericFacade) | ||
73 | //FIXME only read what was requested in the query? | ||
74 | return Async::start<void>([resultProvider, this]() { | ||
75 | auto settings = getSettings(); | ||
76 | auto memoryAdaptor = QSharedPointer<Akonadi2::ApplicationDomain::MemoryBufferAdaptor>::create(); | ||
77 | //TODO copy settings to adaptor | ||
78 | // | ||
79 | //TODO use correct instance identifier | ||
80 | //TODO key == instance identifier ? | ||
81 | resultProvider->add(QSharedPointer<Akonadi2::ApplicationDomain::AkonadiResource>::create("org.kde.dummy", "org.kde.dummy.config", 0, memoryAdaptor)); | ||
82 | }); | ||
83 | } | ||
diff --git a/examples/dummyresource/resourcefacade.h b/examples/dummyresource/resourcefacade.h new file mode 100644 index 0000000..0ba60ab --- /dev/null +++ b/examples/dummyresource/resourcefacade.h | |||
@@ -0,0 +1,43 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2014 Christian Mollekopf <chrigi_1@fastmail.fm> | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License as published by | ||
6 | * the Free Software Foundation; either version 2 of the License, or | ||
7 | * (at your option) any later version. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program; if not, write to the | ||
16 | * Free Software Foundation, Inc., | ||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
18 | */ | ||
19 | |||
20 | #pragma once | ||
21 | |||
22 | #include "common/clientapi.h" | ||
23 | #include "async/src/async.h" | ||
24 | |||
25 | class QSettings; | ||
26 | |||
27 | class DummyResourceConfigFacade : public Akonadi2::StoreFacade<Akonadi2::ApplicationDomain::AkonadiResource> | ||
28 | { | ||
29 | public: | ||
30 | DummyResourceConfigFacade(); | ||
31 | ~DummyResourceConfigFacade(); | ||
32 | //Create an instance | ||
33 | Async::Job<void> create(const Akonadi2::ApplicationDomain::AkonadiResource &domainObject) Q_DECL_OVERRIDE; | ||
34 | //Modify configuration | ||
35 | Async::Job<void> modify(const Akonadi2::ApplicationDomain::AkonadiResource &domainObject) Q_DECL_OVERRIDE; | ||
36 | //Remove instance | ||
37 | Async::Job<void> remove(const Akonadi2::ApplicationDomain::AkonadiResource &domainObject) Q_DECL_OVERRIDE; | ||
38 | //Read configuration and available instances | ||
39 | Async::Job<void> load(const Akonadi2::Query &query, const QSharedPointer<async::ResultProvider<typename Akonadi2::ApplicationDomain::AkonadiResource::Ptr> > &resultProvider) Q_DECL_OVERRIDE; | ||
40 | |||
41 | private: | ||
42 | QSharedPointer<QSettings> getSettings(); | ||
43 | }; | ||