summaryrefslogtreecommitdiffstats
path: root/common/domain
diff options
context:
space:
mode:
Diffstat (limited to 'common/domain')
-rw-r--r--common/domain/applicationdomaintype.cpp16
-rw-r--r--common/domain/applicationdomaintype.h62
-rw-r--r--common/domain/folder.cpp4
-rw-r--r--common/domain/mail.cpp4
4 files changed, 70 insertions, 16 deletions
diff --git a/common/domain/applicationdomaintype.cpp b/common/domain/applicationdomaintype.cpp
index 44eeb13..ce113c2 100644
--- a/common/domain/applicationdomaintype.cpp
+++ b/common/domain/applicationdomaintype.cpp
@@ -24,6 +24,8 @@
24#include "storage.h" //for generateUid() 24#include "storage.h" //for generateUid()
25#include <QFile> 25#include <QFile>
26 26
27SINK_DEBUG_AREA("applicationdomaintype");
28
27namespace Sink { 29namespace Sink {
28namespace ApplicationDomain { 30namespace ApplicationDomain {
29 31
@@ -82,7 +84,7 @@ QVariant ApplicationDomainType::getProperty(const QByteArray &key) const
82{ 84{
83 Q_ASSERT(mAdaptor); 85 Q_ASSERT(mAdaptor);
84 if (!mAdaptor->availableProperties().contains(key)) { 86 if (!mAdaptor->availableProperties().contains(key)) {
85 Warning() << "No such property available " << key; 87 SinkWarning() << "No such property available " << key;
86 } 88 }
87 return mAdaptor->getProperty(key); 89 return mAdaptor->getProperty(key);
88} 90}
@@ -105,7 +107,7 @@ QByteArray ApplicationDomainType::getBlobProperty(const QByteArray &key) const
105 const auto path = getProperty(key).toByteArray(); 107 const auto path = getProperty(key).toByteArray();
106 QFile file(path); 108 QFile file(path);
107 if (!file.open(QIODevice::ReadOnly)) { 109 if (!file.open(QIODevice::ReadOnly)) {
108 ErrorMsg() << "Failed to open the file: " << file.errorString() << path; 110 SinkError() << "Failed to open the file: " << file.errorString() << path;
109 return QByteArray(); 111 return QByteArray();
110 } 112 }
111 return file.readAll(); 113 return file.readAll();
@@ -116,7 +118,7 @@ void ApplicationDomainType::setBlobProperty(const QByteArray &key, const QByteAr
116 const auto path = Sink::temporaryFileLocation() + "/" + QUuid::createUuid().toString(); 118 const auto path = Sink::temporaryFileLocation() + "/" + QUuid::createUuid().toString();
117 QFile file(path); 119 QFile file(path);
118 if (!file.open(QIODevice::WriteOnly)) { 120 if (!file.open(QIODevice::WriteOnly)) {
119 ErrorMsg() << "Failed to open the file: " << file.errorString() << path; 121 SinkError() << "Failed to open the file: " << file.errorString() << path;
120 return; 122 return;
121 } 123 }
122 file.write(value); 124 file.write(value);
@@ -251,7 +253,7 @@ namespace DummyResource {
251 SinkResource create(const QByteArray &account) 253 SinkResource create(const QByteArray &account)
252 { 254 {
253 auto &&resource = ApplicationDomainType::createEntity<SinkResource>(); 255 auto &&resource = ApplicationDomainType::createEntity<SinkResource>();
254 resource.setProperty("type", "org.kde.dummy"); 256 resource.setProperty("type", "sink.dummy");
255 resource.setProperty("account", account); 257 resource.setProperty("account", account);
256 resource.setProperty("capabilities", QVariant::fromValue(QByteArrayList() << ResourceCapabilities::Mail::storage << "-folder.rename")); 258 resource.setProperty("capabilities", QVariant::fromValue(QByteArrayList() << ResourceCapabilities::Mail::storage << "-folder.rename"));
257 // resource.setProperty("capabilities", QVariant::fromValue(QByteArrayList() << ResourceCapabilities::Mail::storage << ResourceCapabilities::Mail::drafts << "-folder.rename" << ResourceCapabilities::Mail::trash)); 259 // resource.setProperty("capabilities", QVariant::fromValue(QByteArrayList() << ResourceCapabilities::Mail::storage << ResourceCapabilities::Mail::drafts << "-folder.rename" << ResourceCapabilities::Mail::trash));
@@ -263,7 +265,7 @@ namespace MaildirResource {
263 SinkResource create(const QByteArray &account) 265 SinkResource create(const QByteArray &account)
264 { 266 {
265 auto &&resource = ApplicationDomainType::createEntity<SinkResource>(); 267 auto &&resource = ApplicationDomainType::createEntity<SinkResource>();
266 resource.setProperty("type", "org.kde.maildir"); 268 resource.setProperty("type", "sink.maildir");
267 resource.setProperty("account", account); 269 resource.setProperty("account", account);
268 resource.setProperty("capabilities", QVariant::fromValue(QByteArrayList() << ResourceCapabilities::Mail::storage << ResourceCapabilities::Mail::drafts << "-folder.rename" << ResourceCapabilities::Mail::trash)); 270 resource.setProperty("capabilities", QVariant::fromValue(QByteArrayList() << ResourceCapabilities::Mail::storage << ResourceCapabilities::Mail::drafts << "-folder.rename" << ResourceCapabilities::Mail::trash));
269 return resource; 271 return resource;
@@ -274,7 +276,7 @@ namespace MailtransportResource {
274 SinkResource create(const QByteArray &account) 276 SinkResource create(const QByteArray &account)
275 { 277 {
276 auto &&resource = ApplicationDomainType::createEntity<SinkResource>(); 278 auto &&resource = ApplicationDomainType::createEntity<SinkResource>();
277 resource.setProperty("type", "org.kde.mailtransport"); 279 resource.setProperty("type", "sink.mailtransport");
278 resource.setProperty("account", account); 280 resource.setProperty("account", account);
279 resource.setProperty("capabilities", QVariant::fromValue(QByteArrayList() << ResourceCapabilities::Mail::transport)); 281 resource.setProperty("capabilities", QVariant::fromValue(QByteArrayList() << ResourceCapabilities::Mail::transport));
280 return resource; 282 return resource;
@@ -285,7 +287,7 @@ namespace ImapResource {
285 SinkResource create(const QByteArray &account) 287 SinkResource create(const QByteArray &account)
286 { 288 {
287 auto &&resource = ApplicationDomainType::createEntity<SinkResource>(); 289 auto &&resource = ApplicationDomainType::createEntity<SinkResource>();
288 resource.setProperty("type", "org.kde.imap"); 290 resource.setProperty("type", "sink.imap");
289 resource.setProperty("account", account); 291 resource.setProperty("account", account);
290 resource.setProperty("capabilities", QVariant::fromValue(QByteArrayList() << ResourceCapabilities::Mail::storage << ResourceCapabilities::Mail::drafts << ResourceCapabilities::Mail::folderhierarchy << ResourceCapabilities::Mail::trash)); 292 resource.setProperty("capabilities", QVariant::fromValue(QByteArrayList() << ResourceCapabilities::Mail::storage << ResourceCapabilities::Mail::drafts << ResourceCapabilities::Mail::folderhierarchy << ResourceCapabilities::Mail::trash));
291 return resource; 293 return resource;
diff --git a/common/domain/applicationdomaintype.h b/common/domain/applicationdomaintype.h
index 849c3e2..5efb936 100644
--- a/common/domain/applicationdomaintype.h
+++ b/common/domain/applicationdomaintype.h
@@ -52,6 +52,13 @@
52 void setExtracted##NAME(const TYPE &value) { setProperty(NAME::name, QVariant::fromValue(value)); } \ 52 void setExtracted##NAME(const TYPE &value) { setProperty(NAME::name, QVariant::fromValue(value)); } \
53 TYPE get##NAME() const { return getProperty(NAME::name).value<TYPE>(); } \ 53 TYPE get##NAME() const { return getProperty(NAME::name).value<TYPE>(); } \
54 54
55#define SINK_STATUS_PROPERTY(TYPE, NAME, LOWERCASENAME) \
56 struct NAME { \
57 static constexpr const char *name = #LOWERCASENAME; \
58 typedef TYPE Type; \
59 }; \
60 void setStatus##NAME(const TYPE &value) { setProperty(NAME::name, QVariant::fromValue(value)); } \
61 TYPE get##NAME() const { return getProperty(NAME::name).value<TYPE>(); } \
55 62
56#define SINK_BLOB_PROPERTY(NAME, LOWERCASENAME) \ 63#define SINK_BLOB_PROPERTY(NAME, LOWERCASENAME) \
57 struct NAME { \ 64 struct NAME { \
@@ -76,6 +83,14 @@
76namespace Sink { 83namespace Sink {
77namespace ApplicationDomain { 84namespace ApplicationDomain {
78 85
86struct SINK_EXPORT Error {
87
88};
89
90struct SINK_EXPORT Progress {
91
92};
93
79/** 94/**
80 * The domain type interface has two purposes: 95 * The domain type interface has two purposes:
81 * * provide a unified interface to read buffers (for zero-copy reading) 96 * * provide a unified interface to read buffers (for zero-copy reading)
@@ -215,6 +230,38 @@ struct SINK_EXPORT Mail : public Entity {
215}; 230};
216 231
217/** 232/**
233 * The status of an account or resource.
234 *
235 * It is set as follows:
236 * * By default the status is offline.
237 * * If a connection to the server could be established the status is Connected.
238 * * If an error occurred that keeps the resource from operating (so non transient), the resource enters the error state.
239 * * If a long running operation is started the resource goes to the busy state (and return to the previous state after that).
240 */
241enum SINK_EXPORT Status {
242 OfflineStatus,
243 ConnectedStatus,
244 BusyStatus,
245 ErrorStatus
246};
247
248struct SINK_EXPORT SinkAccount : public ApplicationDomainType {
249 typedef QSharedPointer<SinkAccount> Ptr;
250 explicit SinkAccount(const QByteArray &resourceInstanceIdentifier, const QByteArray &identifier, qint64 revision, const QSharedPointer<BufferAdaptor> &adaptor);
251 explicit SinkAccount(const QByteArray &identifier);
252 SinkAccount();
253 virtual ~SinkAccount();
254
255 SINK_PROPERTY(QString, Name, name);
256 SINK_PROPERTY(QString, Icon, icon);
257 SINK_PROPERTY(QString, AccountType, accountType);
258 SINK_STATUS_PROPERTY(int, Status, status);
259 SINK_STATUS_PROPERTY(ApplicationDomain::Error, Error, error);
260 SINK_STATUS_PROPERTY(ApplicationDomain::Progress, Progress, progress);
261};
262
263
264/**
218 * Represents an sink resource. 265 * Represents an sink resource.
219 * 266 *
220 * This type is used for configuration of resources, 267 * This type is used for configuration of resources,
@@ -226,14 +273,13 @@ struct SINK_EXPORT SinkResource : public ApplicationDomainType {
226 explicit SinkResource(const QByteArray &identifier); 273 explicit SinkResource(const QByteArray &identifier);
227 SinkResource(); 274 SinkResource();
228 virtual ~SinkResource(); 275 virtual ~SinkResource();
229};
230 276
231struct SINK_EXPORT SinkAccount : public ApplicationDomainType { 277 SINK_REFERENCE_PROPERTY(SinkAccount, Account, account);
232 typedef QSharedPointer<SinkAccount> Ptr; 278 SINK_PROPERTY(QString, ResourceType, resourceType);
233 explicit SinkAccount(const QByteArray &resourceInstanceIdentifier, const QByteArray &identifier, qint64 revision, const QSharedPointer<BufferAdaptor> &adaptor); 279 SINK_PROPERTY(QByteArrayList, Capabilities, capabilities);
234 explicit SinkAccount(const QByteArray &identifier); 280 SINK_STATUS_PROPERTY(int, Status, status);
235 SinkAccount(); 281 SINK_STATUS_PROPERTY(ApplicationDomain::Error, Error, error);
236 virtual ~SinkAccount(); 282 SINK_STATUS_PROPERTY(ApplicationDomain::Progress, Progress, progress);
237}; 283};
238 284
239struct SINK_EXPORT Identity : public ApplicationDomainType { 285struct SINK_EXPORT Identity : public ApplicationDomainType {
@@ -330,3 +376,5 @@ Q_DECLARE_METATYPE(Sink::ApplicationDomain::SinkAccount)
330Q_DECLARE_METATYPE(Sink::ApplicationDomain::SinkAccount::Ptr) 376Q_DECLARE_METATYPE(Sink::ApplicationDomain::SinkAccount::Ptr)
331Q_DECLARE_METATYPE(Sink::ApplicationDomain::Identity) 377Q_DECLARE_METATYPE(Sink::ApplicationDomain::Identity)
332Q_DECLARE_METATYPE(Sink::ApplicationDomain::Identity::Ptr) 378Q_DECLARE_METATYPE(Sink::ApplicationDomain::Identity::Ptr)
379Q_DECLARE_METATYPE(Sink::ApplicationDomain::Error)
380Q_DECLARE_METATYPE(Sink::ApplicationDomain::Progress)
diff --git a/common/domain/folder.cpp b/common/domain/folder.cpp
index 309ca3f..ddb0c10 100644
--- a/common/domain/folder.cpp
+++ b/common/domain/folder.cpp
@@ -35,6 +35,8 @@
35 35
36#include "folder_generated.h" 36#include "folder_generated.h"
37 37
38SINK_DEBUG_AREA("folder");
39
38static QMutex sMutex; 40static QMutex sMutex;
39 41
40using namespace Sink::ApplicationDomain; 42using namespace Sink::ApplicationDomain;
@@ -58,7 +60,7 @@ ResultSet TypeImplementation<Folder>::queryIndexes(const Sink::Query &query, con
58 60
59void TypeImplementation<Folder>::index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction) 61void TypeImplementation<Folder>::index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction)
60{ 62{
61 Trace() << "Indexing " << identifier; 63 SinkTrace() << "Indexing " << identifier;
62 getIndex().add(identifier, bufferAdaptor, transaction); 64 getIndex().add(identifier, bufferAdaptor, transaction);
63} 65}
64 66
diff --git a/common/domain/mail.cpp b/common/domain/mail.cpp
index 5b35a9a..13e1305 100644
--- a/common/domain/mail.cpp
+++ b/common/domain/mail.cpp
@@ -35,6 +35,8 @@
35 35
36#include "mail_generated.h" 36#include "mail_generated.h"
37 37
38SINK_DEBUG_AREA("mail");
39
38static QMutex sMutex; 40static QMutex sMutex;
39 41
40using namespace Sink::ApplicationDomain; 42using namespace Sink::ApplicationDomain;
@@ -63,7 +65,7 @@ ResultSet TypeImplementation<Mail>::queryIndexes(const Sink::Query &query, const
63 65
64void TypeImplementation<Mail>::index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction) 66void TypeImplementation<Mail>::index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction)
65{ 67{
66 Trace() << "Indexing " << identifier; 68 SinkTrace() << "Indexing " << identifier;
67 getIndex().add(identifier, bufferAdaptor, transaction); 69 getIndex().add(identifier, bufferAdaptor, transaction);
68} 70}
69 71