diff options
Diffstat (limited to 'examples/dummyresource/resourcefacade.cpp')
-rw-r--r-- | examples/dummyresource/resourcefacade.cpp | 83 |
1 files changed, 83 insertions, 0 deletions
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 | } | ||