diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/client/main.cpp | 3 | ||||
-rw-r--r-- | examples/dummyresource/resourcefactory.cpp | 16 | ||||
-rw-r--r-- | examples/dummyresource/resourcefactory.h | 1 | ||||
-rw-r--r-- | examples/maildirresource/libmaildir/maildir.cpp | 2 | ||||
-rw-r--r-- | examples/maildirresource/libmaildir/maildir.h | 2 | ||||
-rw-r--r-- | examples/maildirresource/maildirresource.cpp | 30 | ||||
-rw-r--r-- | examples/maildirresource/maildirresource.h | 1 |
7 files changed, 50 insertions, 5 deletions
diff --git a/examples/client/main.cpp b/examples/client/main.cpp index 127fd2f..6660f86 100644 --- a/examples/client/main.cpp +++ b/examples/client/main.cpp | |||
@@ -120,7 +120,6 @@ public: | |||
120 | QObject::connect(syncButton, &QPushButton::pressed, []() { | 120 | QObject::connect(syncButton, &QPushButton::pressed, []() { |
121 | Akonadi2::Query query; | 121 | Akonadi2::Query query; |
122 | query.resources << "org.kde.dummy.instance1"; | 122 | query.resources << "org.kde.dummy.instance1"; |
123 | query.syncOnDemand = true; | ||
124 | Akonadi2::Store::synchronize(query).exec(); | 123 | Akonadi2::Store::synchronize(query).exec(); |
125 | }); | 124 | }); |
126 | 125 | ||
@@ -198,8 +197,6 @@ int main(int argc, char *argv[]) | |||
198 | for (const auto &res : resources) { | 197 | for (const auto &res : resources) { |
199 | query.resources << res.toLatin1(); | 198 | query.resources << res.toLatin1(); |
200 | } | 199 | } |
201 | query.syncOnDemand = false; | ||
202 | query.processAll = false; | ||
203 | query.liveQuery = true; | 200 | query.liveQuery = true; |
204 | if (type == "folder") { | 201 | if (type == "folder") { |
205 | query.parentProperty = "parent"; | 202 | query.parentProperty = "parent"; |
diff --git a/examples/dummyresource/resourcefactory.cpp b/examples/dummyresource/resourcefactory.cpp index a984097..c43b5e6 100644 --- a/examples/dummyresource/resourcefactory.cpp +++ b/examples/dummyresource/resourcefactory.cpp | |||
@@ -134,6 +134,22 @@ void DummyResource::removeFromDisk(const QByteArray &instanceIdentifier) | |||
134 | Akonadi2::Storage(Akonadi2::storageLocation(), instanceIdentifier + ".synchronization", Akonadi2::Storage::ReadWrite).removeFromDisk(); | 134 | Akonadi2::Storage(Akonadi2::storageLocation(), instanceIdentifier + ".synchronization", Akonadi2::Storage::ReadWrite).removeFromDisk(); |
135 | } | 135 | } |
136 | 136 | ||
137 | KAsync::Job<void> DummyResource::inspect(int inspectionType, const QByteArray &inspectionId, const QByteArray &domainType, const QByteArray &entityId, const QByteArray &property, const QVariant &expectedValue) | ||
138 | { | ||
139 | |||
140 | Trace() << "Inspecting " << inspectionType << domainType << entityId << property << expectedValue; | ||
141 | if (property == "testInspection") { | ||
142 | if (expectedValue.toBool()) { | ||
143 | //Success | ||
144 | return KAsync::null<void>(); | ||
145 | } else { | ||
146 | //Failure | ||
147 | return KAsync::error<void>(1, "Failed."); | ||
148 | } | ||
149 | } | ||
150 | return KAsync::null<void>(); | ||
151 | } | ||
152 | |||
137 | DummyResourceFactory::DummyResourceFactory(QObject *parent) | 153 | DummyResourceFactory::DummyResourceFactory(QObject *parent) |
138 | : Akonadi2::ResourceFactory(parent) | 154 | : Akonadi2::ResourceFactory(parent) |
139 | { | 155 | { |
diff --git a/examples/dummyresource/resourcefactory.h b/examples/dummyresource/resourcefactory.h index 2ed4c5d..634829e 100644 --- a/examples/dummyresource/resourcefactory.h +++ b/examples/dummyresource/resourcefactory.h | |||
@@ -40,6 +40,7 @@ public: | |||
40 | KAsync::Job<void> synchronizeWithSource(Akonadi2::Storage &mainStore, Akonadi2::Storage &synchronizationStore) Q_DECL_OVERRIDE; | 40 | KAsync::Job<void> synchronizeWithSource(Akonadi2::Storage &mainStore, Akonadi2::Storage &synchronizationStore) Q_DECL_OVERRIDE; |
41 | using GenericResource::synchronizeWithSource; | 41 | using GenericResource::synchronizeWithSource; |
42 | static void removeFromDisk(const QByteArray &instanceIdentifier); | 42 | static void removeFromDisk(const QByteArray &instanceIdentifier); |
43 | KAsync::Job<void> inspect(int inspectionType, const QByteArray &inspectionId, const QByteArray &domainType, const QByteArray &entityId, const QByteArray &property, const QVariant &expectedValue) Q_DECL_OVERRIDE; | ||
43 | private: | 44 | private: |
44 | KAsync::Job<void> replay(Akonadi2::Storage &synchronizationStore, const QByteArray &type, const QByteArray &key, const QByteArray &value) Q_DECL_OVERRIDE; | 45 | KAsync::Job<void> replay(Akonadi2::Storage &synchronizationStore, const QByteArray &type, const QByteArray &key, const QByteArray &value) Q_DECL_OVERRIDE; |
45 | Akonadi2::ApplicationDomain::Event::Ptr createEvent(const QByteArray &rid, const QMap<QString, QVariant> &data, Akonadi2::Storage::Transaction &); | 46 | Akonadi2::ApplicationDomain::Event::Ptr createEvent(const QByteArray &rid, const QMap<QString, QVariant> &data, Akonadi2::Storage::Transaction &); |
diff --git a/examples/maildirresource/libmaildir/maildir.cpp b/examples/maildirresource/libmaildir/maildir.cpp index 94363b8..28cf46e 100644 --- a/examples/maildirresource/libmaildir/maildir.cpp +++ b/examples/maildirresource/libmaildir/maildir.cpp | |||
@@ -770,7 +770,7 @@ bool Maildir::removeEntry(const QString& key) | |||
770 | // return newUniqueKey; | 770 | // return newUniqueKey; |
771 | // } | 771 | // } |
772 | // | 772 | // |
773 | Maildir::Flags Maildir::readEntryFlags(const QString& key) const | 773 | Maildir::Flags Maildir::readEntryFlags(const QString& key) |
774 | { | 774 | { |
775 | Flags flags; | 775 | Flags flags; |
776 | const QRegExp rx = *(statusSeparatorRx()); | 776 | const QRegExp rx = *(statusSeparatorRx()); |
diff --git a/examples/maildirresource/libmaildir/maildir.h b/examples/maildirresource/libmaildir/maildir.h index f80ba5d..fefd5a7 100644 --- a/examples/maildirresource/libmaildir/maildir.h +++ b/examples/maildirresource/libmaildir/maildir.h | |||
@@ -178,7 +178,7 @@ public: | |||
178 | /** | 178 | /** |
179 | * Return the flags encoded in the maildir file name for an entry | 179 | * Return the flags encoded in the maildir file name for an entry |
180 | **/ | 180 | **/ |
181 | Flags readEntryFlags( const QString& key ) const; | 181 | static Flags readEntryFlags( const QString& key ); |
182 | 182 | ||
183 | /** | 183 | /** |
184 | * Return the contents of the headers section of the file the maildir with the given @p file, that | 184 | * Return the contents of the headers section of the file the maildir with the given @p file, that |
diff --git a/examples/maildirresource/maildirresource.cpp b/examples/maildirresource/maildirresource.cpp index 70f6ae5..9280bdc 100644 --- a/examples/maildirresource/maildirresource.cpp +++ b/examples/maildirresource/maildirresource.cpp | |||
@@ -35,6 +35,7 @@ | |||
35 | #include "facadefactory.h" | 35 | #include "facadefactory.h" |
36 | #include "indexupdater.h" | 36 | #include "indexupdater.h" |
37 | #include "libmaildir/maildir.h" | 37 | #include "libmaildir/maildir.h" |
38 | #include "inspection.h" | ||
38 | #include <QDate> | 39 | #include <QDate> |
39 | #include <QUuid> | 40 | #include <QUuid> |
40 | #include <QDir> | 41 | #include <QDir> |
@@ -292,6 +293,35 @@ void MaildirResource::removeFromDisk(const QByteArray &instanceIdentifier) | |||
292 | Akonadi2::Storage(Akonadi2::storageLocation(), instanceIdentifier + ".synchronization", Akonadi2::Storage::ReadWrite).removeFromDisk(); | 293 | Akonadi2::Storage(Akonadi2::storageLocation(), instanceIdentifier + ".synchronization", Akonadi2::Storage::ReadWrite).removeFromDisk(); |
293 | } | 294 | } |
294 | 295 | ||
296 | KAsync::Job<void> MaildirResource::inspect(int inspectionType, const QByteArray &inspectionId, const QByteArray &domainType, const QByteArray &entityId, const QByteArray &property, const QVariant &expectedValue) | ||
297 | { | ||
298 | auto synchronizationStore = QSharedPointer<Akonadi2::Storage>::create(Akonadi2::storageLocation(), mResourceInstanceIdentifier + ".synchronization", Akonadi2::Storage::ReadOnly); | ||
299 | auto synchronizationTransaction = synchronizationStore->createTransaction(Akonadi2::Storage::ReadOnly); | ||
300 | Trace() << "Inspecting " << inspectionType << domainType << entityId << property << expectedValue; | ||
301 | if (domainType == ENTITY_TYPE_MAIL) { | ||
302 | if (inspectionType == Akonadi2::Resources::Inspection::PropertyInspectionType) { | ||
303 | if (property == "unread") { | ||
304 | const auto remoteId = resolveLocalId(ENTITY_TYPE_MAIL, entityId, synchronizationTransaction); | ||
305 | const auto flags = KPIM::Maildir::readEntryFlags(remoteId.split('/').last()); | ||
306 | if (expectedValue.toBool() && !(flags & KPIM::Maildir::Seen)) { | ||
307 | return KAsync::error<void>(1, "Expected seen but couldn't find it."); | ||
308 | } | ||
309 | if (!expectedValue.toBool() && (flags & KPIM::Maildir::Seen)) { | ||
310 | return KAsync::error<void>(1, "Expected seen but couldn't find it."); | ||
311 | } | ||
312 | return KAsync::null<void>(); | ||
313 | } | ||
314 | } | ||
315 | if (inspectionType == Akonadi2::Resources::Inspection::ExistenceInspectionType) { | ||
316 | const auto remoteId = resolveLocalId(ENTITY_TYPE_MAIL, entityId, synchronizationTransaction); | ||
317 | if (QFileInfo(remoteId).exists() != expectedValue.toBool()) { | ||
318 | return KAsync::error<void>(1, "Wrong file existence: " + remoteId); | ||
319 | } | ||
320 | } | ||
321 | } | ||
322 | return KAsync::null<void>(); | ||
323 | } | ||
324 | |||
295 | MaildirResourceFactory::MaildirResourceFactory(QObject *parent) | 325 | MaildirResourceFactory::MaildirResourceFactory(QObject *parent) |
296 | : Akonadi2::ResourceFactory(parent) | 326 | : Akonadi2::ResourceFactory(parent) |
297 | { | 327 | { |
diff --git a/examples/maildirresource/maildirresource.h b/examples/maildirresource/maildirresource.h index 21ee637..5f7795b 100644 --- a/examples/maildirresource/maildirresource.h +++ b/examples/maildirresource/maildirresource.h | |||
@@ -44,6 +44,7 @@ class MaildirResource : public Akonadi2::GenericResource | |||
44 | public: | 44 | public: |
45 | MaildirResource(const QByteArray &instanceIdentifier, const QSharedPointer<Akonadi2::Pipeline> &pipeline = QSharedPointer<Akonadi2::Pipeline>()); | 45 | MaildirResource(const QByteArray &instanceIdentifier, const QSharedPointer<Akonadi2::Pipeline> &pipeline = QSharedPointer<Akonadi2::Pipeline>()); |
46 | KAsync::Job<void> synchronizeWithSource(Akonadi2::Storage &mainStore, Akonadi2::Storage &synchronizationStore) Q_DECL_OVERRIDE; | 46 | KAsync::Job<void> synchronizeWithSource(Akonadi2::Storage &mainStore, Akonadi2::Storage &synchronizationStore) Q_DECL_OVERRIDE; |
47 | KAsync::Job<void> inspect(int inspectionType, const QByteArray &inspectionId, const QByteArray &domainType, const QByteArray &entityId, const QByteArray &property, const QVariant &expectedValue) Q_DECL_OVERRIDE; | ||
47 | static void removeFromDisk(const QByteArray &instanceIdentifier); | 48 | static void removeFromDisk(const QByteArray &instanceIdentifier); |
48 | private: | 49 | private: |
49 | KAsync::Job<void> replay(Akonadi2::Storage &synchronizationStore, const QByteArray &type, const QByteArray &key, const QByteArray &value) Q_DECL_OVERRIDE; | 50 | KAsync::Job<void> replay(Akonadi2::Storage &synchronizationStore, const QByteArray &type, const QByteArray &key, const QByteArray &value) Q_DECL_OVERRIDE; |