diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-11-28 19:33:01 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-11-28 19:33:01 +0100 |
commit | 938554f267193b652478fc12343819fa45d76034 (patch) | |
tree | 1c027f97f3209571740377f1d4b7e6721d8de777 /examples/mailtransportresource/mailtransportresource.cpp | |
parent | 885f185f55249a2e97e9c7c238f89a5d0d99d1df (diff) | |
download | sink-938554f267193b652478fc12343819fa45d76034.tar.gz sink-938554f267193b652478fc12343819fa45d76034.zip |
Moved inspection commands to a separate inspector.
Diffstat (limited to 'examples/mailtransportresource/mailtransportresource.cpp')
-rw-r--r-- | examples/mailtransportresource/mailtransportresource.cpp | 48 |
1 files changed, 27 insertions, 21 deletions
diff --git a/examples/mailtransportresource/mailtransportresource.cpp b/examples/mailtransportresource/mailtransportresource.cpp index c135de9..524b411 100644 --- a/examples/mailtransportresource/mailtransportresource.cpp +++ b/examples/mailtransportresource/mailtransportresource.cpp | |||
@@ -22,7 +22,7 @@ | |||
22 | #include "facadefactory.h" | 22 | #include "facadefactory.h" |
23 | #include "resourceconfig.h" | 23 | #include "resourceconfig.h" |
24 | #include "definitions.h" | 24 | #include "definitions.h" |
25 | #include "domainadaptor.h" | 25 | #include "inspector.h" |
26 | #include <QDir> | 26 | #include <QDir> |
27 | #include <QFileInfo> | 27 | #include <QFileInfo> |
28 | #include <QSettings> | 28 | #include <QSettings> |
@@ -124,6 +124,31 @@ public: | |||
124 | MailtransportResource::Settings mSettings; | 124 | MailtransportResource::Settings mSettings; |
125 | }; | 125 | }; |
126 | 126 | ||
127 | class MailtransportInspector : public Sink::Inspector { | ||
128 | public: | ||
129 | MailtransportInspector(const Sink::ResourceContext &resourceContext) | ||
130 | : Sink::Inspector(resourceContext) | ||
131 | { | ||
132 | |||
133 | } | ||
134 | |||
135 | protected: | ||
136 | KAsync::Job<void> inspect(int inspectionType, const QByteArray &inspectionId, const QByteArray &domainType, const QByteArray &entityId, const QByteArray &property, const QVariant &expectedValue) Q_DECL_OVERRIDE | ||
137 | { | ||
138 | if (domainType == ENTITY_TYPE_MAIL) { | ||
139 | if (inspectionType == Sink::ResourceControl::Inspection::ExistenceInspectionType) { | ||
140 | auto path = resourceStorageLocation(mResourceContext.instanceId()) + "/test/" + entityId; | ||
141 | if (QFileInfo::exists(path)) { | ||
142 | return KAsync::null<void>(); | ||
143 | } | ||
144 | return KAsync::error<void>(1, "Couldn't find message: " + path); | ||
145 | } | ||
146 | } | ||
147 | return KAsync::null<void>(); | ||
148 | } | ||
149 | }; | ||
150 | |||
151 | |||
127 | MailtransportResource::MailtransportResource(const Sink::ResourceContext &resourceContext) | 152 | MailtransportResource::MailtransportResource(const Sink::ResourceContext &resourceContext) |
128 | : Sink::GenericResource(resourceContext) | 153 | : Sink::GenericResource(resourceContext) |
129 | { | 154 | { |
@@ -138,30 +163,11 @@ MailtransportResource::MailtransportResource(const Sink::ResourceContext &resour | |||
138 | auto synchronizer = QSharedPointer<MailtransportSynchronizer>::create(resourceContext); | 163 | auto synchronizer = QSharedPointer<MailtransportSynchronizer>::create(resourceContext); |
139 | synchronizer->mSettings = mSettings; | 164 | synchronizer->mSettings = mSettings; |
140 | setupSynchronizer(synchronizer); | 165 | setupSynchronizer(synchronizer); |
166 | setupInspector(QSharedPointer<MailtransportInspector>::create(resourceContext)); | ||
141 | 167 | ||
142 | setupPreprocessors(ENTITY_TYPE_MAIL, QVector<Sink::Preprocessor*>() << new MimeMessageMover << new MailPropertyExtractor); | 168 | setupPreprocessors(ENTITY_TYPE_MAIL, QVector<Sink::Preprocessor*>() << new MimeMessageMover << new MailPropertyExtractor); |
143 | } | 169 | } |
144 | 170 | ||
145 | void MailtransportResource::removeFromDisk(const QByteArray &instanceIdentifier) | ||
146 | { | ||
147 | GenericResource::removeFromDisk(instanceIdentifier); | ||
148 | Sink::Storage::DataStore(Sink::storageLocation(), instanceIdentifier + ".synchronization", Sink::Storage::DataStore::ReadWrite).removeFromDisk(); | ||
149 | } | ||
150 | |||
151 | KAsync::Job<void> MailtransportResource::inspect(int inspectionType, const QByteArray &inspectionId, const QByteArray &domainType, const QByteArray &entityId, const QByteArray &property, const QVariant &expectedValue) | ||
152 | { | ||
153 | if (domainType == ENTITY_TYPE_MAIL) { | ||
154 | if (inspectionType == Sink::ResourceControl::Inspection::ExistenceInspectionType) { | ||
155 | auto path = resourceStorageLocation(mResourceContext.instanceId()) + "/test/" + entityId; | ||
156 | if (QFileInfo::exists(path)) { | ||
157 | return KAsync::null<void>(); | ||
158 | } | ||
159 | return KAsync::error<void>(1, "Couldn't find message: " + path); | ||
160 | } | ||
161 | } | ||
162 | return KAsync::null<void>(); | ||
163 | } | ||
164 | |||
165 | MailtransportResourceFactory::MailtransportResourceFactory(QObject *parent) | 171 | MailtransportResourceFactory::MailtransportResourceFactory(QObject *parent) |
166 | : Sink::ResourceFactory(parent) | 172 | : Sink::ResourceFactory(parent) |
167 | { | 173 | { |