From b4df9eb5f1f4a0ac2b1272fc34d4b8aad473008b Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 5 Jul 2016 15:22:10 +0200 Subject: Prepare for making the resource status available --- common/domain/applicationdomaintype.h | 62 +++++++++++++++++++++++++++++++---- 1 file changed, 55 insertions(+), 7 deletions(-) (limited to 'common/domain') 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 @@ void setExtracted##NAME(const TYPE &value) { setProperty(NAME::name, QVariant::fromValue(value)); } \ TYPE get##NAME() const { return getProperty(NAME::name).value(); } \ +#define SINK_STATUS_PROPERTY(TYPE, NAME, LOWERCASENAME) \ + struct NAME { \ + static constexpr const char *name = #LOWERCASENAME; \ + typedef TYPE Type; \ + }; \ + void setStatus##NAME(const TYPE &value) { setProperty(NAME::name, QVariant::fromValue(value)); } \ + TYPE get##NAME() const { return getProperty(NAME::name).value(); } \ #define SINK_BLOB_PROPERTY(NAME, LOWERCASENAME) \ struct NAME { \ @@ -76,6 +83,14 @@ namespace Sink { namespace ApplicationDomain { +struct SINK_EXPORT Error { + +}; + +struct SINK_EXPORT Progress { + +}; + /** * The domain type interface has two purposes: * * provide a unified interface to read buffers (for zero-copy reading) @@ -214,6 +229,38 @@ struct SINK_EXPORT Mail : public Entity { SINK_PROPERTY(bool, Sent, sent); }; +/** + * The status of an account or resource. + * + * It is set as follows: + * * By default the status is offline. + * * If a connection to the server could be established the status is Connected. + * * If an error occurred that keeps the resource from operating (so non transient), the resource enters the error state. + * * If a long running operation is started the resource goes to the busy state (and return to the previous state after that). + */ +enum SINK_EXPORT Status { + OfflineStatus, + ConnectedStatus, + BusyStatus, + ErrorStatus +}; + +struct SINK_EXPORT SinkAccount : public ApplicationDomainType { + typedef QSharedPointer Ptr; + explicit SinkAccount(const QByteArray &resourceInstanceIdentifier, const QByteArray &identifier, qint64 revision, const QSharedPointer &adaptor); + explicit SinkAccount(const QByteArray &identifier); + SinkAccount(); + virtual ~SinkAccount(); + + SINK_PROPERTY(QString, Name, name); + SINK_PROPERTY(QString, Icon, icon); + SINK_PROPERTY(QString, AccountType, accountType); + SINK_STATUS_PROPERTY(int, Status, status); + SINK_STATUS_PROPERTY(ApplicationDomain::Error, Error, error); + SINK_STATUS_PROPERTY(ApplicationDomain::Progress, Progress, progress); +}; + + /** * Represents an sink resource. * @@ -226,14 +273,13 @@ struct SINK_EXPORT SinkResource : public ApplicationDomainType { explicit SinkResource(const QByteArray &identifier); SinkResource(); virtual ~SinkResource(); -}; -struct SINK_EXPORT SinkAccount : public ApplicationDomainType { - typedef QSharedPointer Ptr; - explicit SinkAccount(const QByteArray &resourceInstanceIdentifier, const QByteArray &identifier, qint64 revision, const QSharedPointer &adaptor); - explicit SinkAccount(const QByteArray &identifier); - SinkAccount(); - virtual ~SinkAccount(); + SINK_REFERENCE_PROPERTY(SinkAccount, Account, account); + SINK_PROPERTY(QString, ResourceType, resourceType); + SINK_PROPERTY(QByteArrayList, Capabilities, capabilities); + SINK_STATUS_PROPERTY(int, Status, status); + SINK_STATUS_PROPERTY(ApplicationDomain::Error, Error, error); + SINK_STATUS_PROPERTY(ApplicationDomain::Progress, Progress, progress); }; struct SINK_EXPORT Identity : public ApplicationDomainType { @@ -330,3 +376,5 @@ Q_DECLARE_METATYPE(Sink::ApplicationDomain::SinkAccount) Q_DECLARE_METATYPE(Sink::ApplicationDomain::SinkAccount::Ptr) Q_DECLARE_METATYPE(Sink::ApplicationDomain::Identity) Q_DECLARE_METATYPE(Sink::ApplicationDomain::Identity::Ptr) +Q_DECLARE_METATYPE(Sink::ApplicationDomain::Error) +Q_DECLARE_METATYPE(Sink::ApplicationDomain::Progress) -- cgit v1.2.3 From da2b049e248c1ad7efeb53685158a205335e4e36 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 7 Jul 2016 22:23:49 +0200 Subject: A new debug system. Instead of a single #define as debug area the new system allows for an identifier for each debug message with the structure component.area. The component is a dot separated identifier of the runtime component, such as the process or the plugin. The area is the code component, and can be as such defined at compiletime. The idea of this system is that it becomes possible to i.e. look at the output of all messages in the query subsystem of a specific resource (something that happens in the client process, but in the resource-specific subcomponent). The new macros are supposed to be less likely to clash with other names, hence the new names. --- common/domain/applicationdomaintype.cpp | 8 +++++--- common/domain/folder.cpp | 4 +++- common/domain/mail.cpp | 4 +++- 3 files changed, 11 insertions(+), 5 deletions(-) (limited to 'common/domain') diff --git a/common/domain/applicationdomaintype.cpp b/common/domain/applicationdomaintype.cpp index 44eeb13..57919ff 100644 --- a/common/domain/applicationdomaintype.cpp +++ b/common/domain/applicationdomaintype.cpp @@ -24,6 +24,8 @@ #include "storage.h" //for generateUid() #include +SINK_DEBUG_AREA("applicationdomaintype"); + namespace Sink { namespace ApplicationDomain { @@ -82,7 +84,7 @@ QVariant ApplicationDomainType::getProperty(const QByteArray &key) const { Q_ASSERT(mAdaptor); if (!mAdaptor->availableProperties().contains(key)) { - Warning() << "No such property available " << key; + SinkWarning() << "No such property available " << key; } return mAdaptor->getProperty(key); } @@ -105,7 +107,7 @@ QByteArray ApplicationDomainType::getBlobProperty(const QByteArray &key) const const auto path = getProperty(key).toByteArray(); QFile file(path); if (!file.open(QIODevice::ReadOnly)) { - ErrorMsg() << "Failed to open the file: " << file.errorString() << path; + SinkError() << "Failed to open the file: " << file.errorString() << path; return QByteArray(); } return file.readAll(); @@ -116,7 +118,7 @@ void ApplicationDomainType::setBlobProperty(const QByteArray &key, const QByteAr const auto path = Sink::temporaryFileLocation() + "/" + QUuid::createUuid().toString(); QFile file(path); if (!file.open(QIODevice::WriteOnly)) { - ErrorMsg() << "Failed to open the file: " << file.errorString() << path; + SinkError() << "Failed to open the file: " << file.errorString() << path; return; } file.write(value); 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 @@ #include "folder_generated.h" +SINK_DEBUG_AREA("folder"); + static QMutex sMutex; using namespace Sink::ApplicationDomain; @@ -58,7 +60,7 @@ ResultSet TypeImplementation::queryIndexes(const Sink::Query &query, con void TypeImplementation::index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction) { - Trace() << "Indexing " << identifier; + SinkTrace() << "Indexing " << identifier; getIndex().add(identifier, bufferAdaptor, transaction); } 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 @@ #include "mail_generated.h" +SINK_DEBUG_AREA("mail"); + static QMutex sMutex; using namespace Sink::ApplicationDomain; @@ -63,7 +65,7 @@ ResultSet TypeImplementation::queryIndexes(const Sink::Query &query, const void TypeImplementation::index(const QByteArray &identifier, const BufferAdaptor &bufferAdaptor, Sink::Storage::Transaction &transaction) { - Trace() << "Indexing " << identifier; + SinkTrace() << "Indexing " << identifier; getIndex().add(identifier, bufferAdaptor, transaction); } -- cgit v1.2.3 From 81fa4c3635a029b1c8f9cc3cd670f0b04f1c3f21 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Fri, 8 Jul 2016 11:22:40 +0200 Subject: Shorten the types to be more distinctive. The org.kde prefix is useless and possibly misleading. Simply prefixing with sink is more unique and shorter. --- common/domain/applicationdomaintype.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'common/domain') diff --git a/common/domain/applicationdomaintype.cpp b/common/domain/applicationdomaintype.cpp index 57919ff..ce113c2 100644 --- a/common/domain/applicationdomaintype.cpp +++ b/common/domain/applicationdomaintype.cpp @@ -253,7 +253,7 @@ namespace DummyResource { SinkResource create(const QByteArray &account) { auto &&resource = ApplicationDomainType::createEntity(); - resource.setProperty("type", "org.kde.dummy"); + resource.setProperty("type", "sink.dummy"); resource.setProperty("account", account); resource.setProperty("capabilities", QVariant::fromValue(QByteArrayList() << ResourceCapabilities::Mail::storage << "-folder.rename")); // resource.setProperty("capabilities", QVariant::fromValue(QByteArrayList() << ResourceCapabilities::Mail::storage << ResourceCapabilities::Mail::drafts << "-folder.rename" << ResourceCapabilities::Mail::trash)); @@ -265,7 +265,7 @@ namespace MaildirResource { SinkResource create(const QByteArray &account) { auto &&resource = ApplicationDomainType::createEntity(); - resource.setProperty("type", "org.kde.maildir"); + resource.setProperty("type", "sink.maildir"); resource.setProperty("account", account); resource.setProperty("capabilities", QVariant::fromValue(QByteArrayList() << ResourceCapabilities::Mail::storage << ResourceCapabilities::Mail::drafts << "-folder.rename" << ResourceCapabilities::Mail::trash)); return resource; @@ -276,7 +276,7 @@ namespace MailtransportResource { SinkResource create(const QByteArray &account) { auto &&resource = ApplicationDomainType::createEntity(); - resource.setProperty("type", "org.kde.mailtransport"); + resource.setProperty("type", "sink.mailtransport"); resource.setProperty("account", account); resource.setProperty("capabilities", QVariant::fromValue(QByteArrayList() << ResourceCapabilities::Mail::transport)); return resource; @@ -287,7 +287,7 @@ namespace ImapResource { SinkResource create(const QByteArray &account) { auto &&resource = ApplicationDomainType::createEntity(); - resource.setProperty("type", "org.kde.imap"); + resource.setProperty("type", "sink.imap"); resource.setProperty("account", account); resource.setProperty("capabilities", QVariant::fromValue(QByteArrayList() << ResourceCapabilities::Mail::storage << ResourceCapabilities::Mail::drafts << ResourceCapabilities::Mail::folderhierarchy << ResourceCapabilities::Mail::trash)); return resource; -- cgit v1.2.3