summaryrefslogtreecommitdiffstats
path: root/common/domain
diff options
context:
space:
mode:
Diffstat (limited to 'common/domain')
-rw-r--r--common/domain/applicationdomaintype.cpp45
-rw-r--r--common/domain/applicationdomaintype.h60
-rw-r--r--common/domain/event.cpp2
3 files changed, 86 insertions, 21 deletions
diff --git a/common/domain/applicationdomaintype.cpp b/common/domain/applicationdomaintype.cpp
index b0433be..df10327 100644
--- a/common/domain/applicationdomaintype.cpp
+++ b/common/domain/applicationdomaintype.cpp
@@ -64,6 +64,12 @@ ApplicationDomainType::~ApplicationDomainType()
64{ 64{
65} 65}
66 66
67bool ApplicationDomainType::hasProperty(const QByteArray &key) const
68{
69 Q_ASSERT(mAdaptor);
70 return mAdaptor->availableProperties().contains(key);
71}
72
67QVariant ApplicationDomainType::getProperty(const QByteArray &key) const 73QVariant ApplicationDomainType::getProperty(const QByteArray &key) const
68{ 74{
69 Q_ASSERT(mAdaptor); 75 Q_ASSERT(mAdaptor);
@@ -76,13 +82,18 @@ QVariant ApplicationDomainType::getProperty(const QByteArray &key) const
76void ApplicationDomainType::setProperty(const QByteArray &key, const QVariant &value) 82void ApplicationDomainType::setProperty(const QByteArray &key, const QVariant &value)
77{ 83{
78 Q_ASSERT(mAdaptor); 84 Q_ASSERT(mAdaptor);
79 mChangeSet.insert(key, value); 85 mChangeSet.insert(key);
80 mAdaptor->setProperty(key, value); 86 mAdaptor->setProperty(key, value);
81} 87}
82 88
89void ApplicationDomainType::setChangedProperties(const QSet<QByteArray> &changeset)
90{
91 mChangeSet = changeset;
92}
93
83QByteArrayList ApplicationDomainType::changedProperties() const 94QByteArrayList ApplicationDomainType::changedProperties() const
84{ 95{
85 return mChangeSet.keys(); 96 return mChangeSet.toList();
86} 97}
87 98
88qint64 ApplicationDomainType::revision() const 99qint64 ApplicationDomainType::revision() const
@@ -100,6 +111,36 @@ QByteArray ApplicationDomainType::identifier() const
100 return mIdentifier; 111 return mIdentifier;
101} 112}
102 113
114Entity::~Entity()
115{
116
117}
118
119Event::~Event()
120{
121
122}
123
124Todo::~Todo()
125{
126
127}
128
129Mail::~Mail()
130{
131
132}
133
134Folder::~Folder()
135{
136
137}
138
139SinkResource::~SinkResource()
140{
141
142}
143
103template<> 144template<>
104QByteArray getTypeName<Event>() 145QByteArray getTypeName<Event>()
105{ 146{
diff --git a/common/domain/applicationdomaintype.h b/common/domain/applicationdomaintype.h
index 63f030c..32d8999 100644
--- a/common/domain/applicationdomaintype.h
+++ b/common/domain/applicationdomaintype.h
@@ -19,9 +19,11 @@
19 */ 19 */
20#pragma once 20#pragma once
21 21
22#include "sink_export.h"
22#include <QSharedPointer> 23#include <QSharedPointer>
23#include <QVariant> 24#include <QVariant>
24#include <QByteArray> 25#include <QByteArray>
26#include <QDebug>
25#include "bufferadaptor.h" 27#include "bufferadaptor.h"
26 28
27namespace Sink { 29namespace Sink {
@@ -35,7 +37,7 @@ namespace ApplicationDomain {
35 * 37 *
36 * ApplicationDomainTypes don't adhere to any standard and are meant to be extended frequently (hence the non-typesafe interface). 38 * ApplicationDomainTypes don't adhere to any standard and are meant to be extended frequently (hence the non-typesafe interface).
37 */ 39 */
38class ApplicationDomainType { 40class SINK_EXPORT ApplicationDomainType {
39public: 41public:
40 typedef QSharedPointer<ApplicationDomainType> Ptr; 42 typedef QSharedPointer<ApplicationDomainType> Ptr;
41 43
@@ -55,16 +57,19 @@ public:
55 57
56 virtual ~ApplicationDomainType(); 58 virtual ~ApplicationDomainType();
57 59
58 virtual QVariant getProperty(const QByteArray &key) const; 60 bool hasProperty(const QByteArray &key) const;
59 virtual void setProperty(const QByteArray &key, const QVariant &value); 61 QVariant getProperty(const QByteArray &key) const;
60 virtual QByteArrayList changedProperties() const; 62 void setProperty(const QByteArray &key, const QVariant &value);
63 void setChangedProperties(const QSet<QByteArray> &changeset);
64 QByteArrayList changedProperties() const;
61 qint64 revision() const; 65 qint64 revision() const;
62 QByteArray resourceInstanceIdentifier() const; 66 QByteArray resourceInstanceIdentifier() const;
63 QByteArray identifier() const; 67 QByteArray identifier() const;
64 68
65private: 69private:
70 friend QDebug operator<<(QDebug, const ApplicationDomainType &);
66 QSharedPointer<BufferAdaptor> mAdaptor; 71 QSharedPointer<BufferAdaptor> mAdaptor;
67 QHash<QByteArray, QVariant> mChangeSet; 72 QSet<QByteArray> mChangeSet;
68 /* 73 /*
69 * Each domain object needs to store the resource, identifier, revision triple so we can link back to the storage location. 74 * Each domain object needs to store the resource, identifier, revision triple so we can link back to the storage location.
70 */ 75 */
@@ -82,34 +87,50 @@ inline bool operator==(const ApplicationDomainType& lhs, const ApplicationDomain
82 && lhs.resourceInstanceIdentifier() == rhs.resourceInstanceIdentifier(); 87 && lhs.resourceInstanceIdentifier() == rhs.resourceInstanceIdentifier();
83} 88}
84 89
85struct Entity : public ApplicationDomainType { 90inline QDebug operator<< (QDebug d, const ApplicationDomainType &type)
91{
92 d << "ApplicationDomainType(\n";
93 for (const auto &property : type.mAdaptor->availableProperties()) {
94 d << " " << property << "\t" << type.getProperty(property) << "\n";
95 }
96 d << ")";
97 return d;
98}
99
100struct SINK_EXPORT Entity : public ApplicationDomainType {
86 typedef QSharedPointer<Entity> Ptr; 101 typedef QSharedPointer<Entity> Ptr;
87 using ApplicationDomainType::ApplicationDomainType; 102 using ApplicationDomainType::ApplicationDomainType;
103 virtual ~Entity();
88}; 104};
89 105
90struct Event : public Entity { 106struct SINK_EXPORT Event : public Entity {
91 typedef QSharedPointer<Event> Ptr; 107 typedef QSharedPointer<Event> Ptr;
92 using Entity::Entity; 108 using Entity::Entity;
109 virtual ~Event();
93}; 110};
94 111
95struct Todo : public Entity { 112struct SINK_EXPORT Todo : public Entity {
96 typedef QSharedPointer<Todo> Ptr; 113 typedef QSharedPointer<Todo> Ptr;
97 using Entity::Entity; 114 using Entity::Entity;
115 virtual ~Todo();
98}; 116};
99 117
100struct Calendar : public Entity { 118struct SINK_EXPORT Calendar : public Entity {
101 typedef QSharedPointer<Calendar> Ptr; 119 typedef QSharedPointer<Calendar> Ptr;
102 using Entity::Entity; 120 using Entity::Entity;
121 virtual ~Calendar();
103}; 122};
104 123
105struct Mail : public Entity { 124struct SINK_EXPORT Mail : public Entity {
106 typedef QSharedPointer<Mail> Ptr; 125 typedef QSharedPointer<Mail> Ptr;
107 using Entity::Entity; 126 using Entity::Entity;
127 virtual ~Mail();
108}; 128};
109 129
110struct Folder : public Entity { 130struct SINK_EXPORT Folder : public Entity {
111 typedef QSharedPointer<Folder> Ptr; 131 typedef QSharedPointer<Folder> Ptr;
112 using Entity::Entity; 132 using Entity::Entity;
133 virtual ~Folder();
113}; 134};
114 135
115/** 136/**
@@ -118,9 +139,10 @@ struct Folder : public Entity {
118 * This type is used for configuration of resources, 139 * This type is used for configuration of resources,
119 * and for creating and removing resource instances. 140 * and for creating and removing resource instances.
120 */ 141 */
121struct SinkResource : public ApplicationDomainType { 142struct SINK_EXPORT SinkResource : public ApplicationDomainType {
122 typedef QSharedPointer<SinkResource> Ptr; 143 typedef QSharedPointer<SinkResource> Ptr;
123 using ApplicationDomainType::ApplicationDomainType; 144 using ApplicationDomainType::ApplicationDomainType;
145 virtual ~SinkResource();
124}; 146};
125 147
126/** 148/**
@@ -129,22 +151,22 @@ struct SinkResource : public ApplicationDomainType {
129 * Do not store these types to disk, they may change over time. 151 * Do not store these types to disk, they may change over time.
130 */ 152 */
131template<class DomainType> 153template<class DomainType>
132QByteArray getTypeName(); 154QByteArray SINK_EXPORT getTypeName();
133 155
134template<> 156template<>
135QByteArray getTypeName<Event>(); 157QByteArray SINK_EXPORT getTypeName<Event>();
136 158
137template<> 159template<>
138QByteArray getTypeName<Todo>(); 160QByteArray SINK_EXPORT getTypeName<Todo>();
139 161
140template<> 162template<>
141QByteArray getTypeName<SinkResource>(); 163QByteArray SINK_EXPORT getTypeName<SinkResource>();
142 164
143template<> 165template<>
144QByteArray getTypeName<Mail>(); 166QByteArray SINK_EXPORT getTypeName<Mail>();
145 167
146template<> 168template<>
147QByteArray getTypeName<Folder>(); 169QByteArray SINK_EXPORT getTypeName<Folder>();
148 170
149/** 171/**
150 * Type implementation. 172 * Type implementation.
@@ -153,7 +175,7 @@ QByteArray getTypeName<Folder>();
153 * Contains all non-resource specific, but type-specific code. 175 * Contains all non-resource specific, but type-specific code.
154 */ 176 */
155template<typename DomainType> 177template<typename DomainType>
156class TypeImplementation; 178class SINK_EXPORT TypeImplementation;
157 179
158} 180}
159} 181}
diff --git a/common/domain/event.cpp b/common/domain/event.cpp
index 9f81eb8..4210125 100644
--- a/common/domain/event.cpp
+++ b/common/domain/event.cpp
@@ -69,6 +69,7 @@ QSharedPointer<ReadPropertyMapper<TypeImplementation<Event>::Buffer> > TypeImple
69{ 69{
70 auto propertyMapper = QSharedPointer<ReadPropertyMapper<Buffer> >::create(); 70 auto propertyMapper = QSharedPointer<ReadPropertyMapper<Buffer> >::create();
71 propertyMapper->addMapping<QString, Buffer>("summary", &Buffer::summary); 71 propertyMapper->addMapping<QString, Buffer>("summary", &Buffer::summary);
72 propertyMapper->addMapping<QString, Buffer>("description", &Buffer::description);
72 propertyMapper->addMapping<QString, Buffer>("uid", &Buffer::uid); 73 propertyMapper->addMapping<QString, Buffer>("uid", &Buffer::uid);
73 propertyMapper->addMapping<QByteArray, Buffer>("attachment", &Buffer::attachment); 74 propertyMapper->addMapping<QByteArray, Buffer>("attachment", &Buffer::attachment);
74 return propertyMapper; 75 return propertyMapper;
@@ -78,6 +79,7 @@ QSharedPointer<WritePropertyMapper<TypeImplementation<Event>::BufferBuilder> > T
78{ 79{
79 auto propertyMapper = QSharedPointer<WritePropertyMapper<BufferBuilder> >::create(); 80 auto propertyMapper = QSharedPointer<WritePropertyMapper<BufferBuilder> >::create();
80 propertyMapper->addMapping<QString>("summary", &BufferBuilder::add_summary); 81 propertyMapper->addMapping<QString>("summary", &BufferBuilder::add_summary);
82 propertyMapper->addMapping<QString>("description", &BufferBuilder::add_description);
81 propertyMapper->addMapping<QString>("uid", &BufferBuilder::add_uid); 83 propertyMapper->addMapping<QString>("uid", &BufferBuilder::add_uid);
82 propertyMapper->addMapping<QByteArray>("attachment", &BufferBuilder::add_attachment); 84 propertyMapper->addMapping<QByteArray>("attachment", &BufferBuilder::add_attachment);
83 return propertyMapper; 85 return propertyMapper;