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.h40
-rw-r--r--common/domain/propertyregistry.cpp9
-rw-r--r--common/domain/propertyregistry.h3
4 files changed, 5 insertions, 92 deletions
diff --git a/common/domain/applicationdomaintype.cpp b/common/domain/applicationdomaintype.cpp
index c1ac7e8..8bb74e3 100644
--- a/common/domain/applicationdomaintype.cpp
+++ b/common/domain/applicationdomaintype.cpp
@@ -58,12 +58,6 @@ QDebug Sink::ApplicationDomain::operator<< (QDebug d, const Sink::ApplicationDom
58 return d; 58 return d;
59} 59}
60 60
61QDebug Sink::ApplicationDomain::operator<< (QDebug d, const Sink::ApplicationDomain::BLOB &blob)
62{
63 d << blob.value << "external:" << blob.isExternal ;
64 return d;
65}
66
67template <typename DomainType, typename Property> 61template <typename DomainType, typename Property>
68int registerProperty() { 62int registerProperty() {
69 Sink::Private::PropertyRegistry::instance().registerProperty<Property>(Sink::ApplicationDomain::getTypeName<DomainType>()); 63 Sink::Private::PropertyRegistry::instance().registerProperty<Property>(Sink::ApplicationDomain::getTypeName<DomainType>());
@@ -130,13 +124,12 @@ static const int foo = [] {
130 QMetaType::registerEqualsComparator<Reference>(); 124 QMetaType::registerEqualsComparator<Reference>();
131 QMetaType::registerDebugStreamOperator<Reference>(); 125 QMetaType::registerDebugStreamOperator<Reference>();
132 QMetaType::registerConverter<Reference, QByteArray>(); 126 QMetaType::registerConverter<Reference, QByteArray>();
133 QMetaType::registerDebugStreamOperator<BLOB>();
134 QMetaType::registerDebugStreamOperator<Mail::Contact>(); 127 QMetaType::registerDebugStreamOperator<Mail::Contact>();
135 qRegisterMetaTypeStreamOperators<Sink::ApplicationDomain::Reference>(); 128 qRegisterMetaTypeStreamOperators<Sink::ApplicationDomain::Reference>();
136 return 0; 129 return 0;
137}(); 130}();
138 131
139void copyBuffer(Sink::ApplicationDomain::BufferAdaptor &buffer, Sink::ApplicationDomain::BufferAdaptor &memoryAdaptor, const QList<QByteArray> &properties, bool copyBlobs, bool pruneReferences) 132void copyBuffer(Sink::ApplicationDomain::BufferAdaptor &buffer, Sink::ApplicationDomain::BufferAdaptor &memoryAdaptor, const QList<QByteArray> &properties, bool pruneReferences)
140{ 133{
141 auto propertiesToCopy = properties; 134 auto propertiesToCopy = properties;
142 if (properties.isEmpty()) { 135 if (properties.isEmpty()) {
@@ -144,14 +137,7 @@ void copyBuffer(Sink::ApplicationDomain::BufferAdaptor &buffer, Sink::Applicatio
144 } 137 }
145 for (const auto &property : propertiesToCopy) { 138 for (const auto &property : propertiesToCopy) {
146 const auto value = buffer.getProperty(property); 139 const auto value = buffer.getProperty(property);
147 if (copyBlobs && value.canConvert<BLOB>()) { 140 if (pruneReferences && value.canConvert<Reference>()) {
148 const auto oldPath = value.value<BLOB>().value;
149 const auto newPath = Sink::temporaryFileLocation() + "/" + createUuid();
150 if (!QFile::copy(oldPath, newPath)) {
151 SinkWarning() << "Failed to copy file from: " << oldPath << "to: " << newPath;
152 }
153 memoryAdaptor.setProperty(property, QVariant::fromValue(BLOB{newPath}));
154 } else if (pruneReferences && value.canConvert<Reference>()) {
155 continue; 141 continue;
156 } else { 142 } else {
157 memoryAdaptor.setProperty(property, value); 143 memoryAdaptor.setProperty(property, value);
@@ -245,33 +231,6 @@ void ApplicationDomainType::setProperty(const QByteArray &key, const Application
245 setProperty(key, QVariant::fromValue(Reference{value.identifier()})); 231 setProperty(key, QVariant::fromValue(Reference{value.identifier()}));
246} 232}
247 233
248QByteArray ApplicationDomainType::getBlobProperty(const QByteArray &key) const
249{
250 const auto path = getProperty(key).value<BLOB>().value;
251 QFile file(path);
252 if (!file.open(QIODevice::ReadOnly)) {
253 SinkError() << "Failed to open the file for reading: " << file.errorString() << "Path:" << path << " For property:" << key;
254 return QByteArray();
255 }
256 return file.readAll();
257}
258
259void ApplicationDomainType::setBlobProperty(const QByteArray &key, const QByteArray &value)
260{
261 const auto path = Sink::temporaryFileLocation() + "/" + createUuid();
262 QFile file(path);
263 if (!file.open(QIODevice::WriteOnly)) {
264 SinkError() << "Failed to open the file for writing: " << file.errorString() << path << " For property " << key;
265 return;
266 }
267 if (file.write(value) < 0) {
268 SinkError() << "Failed to write to file: " << file.errorString() << path << " For property " << key;
269 }
270 //Ensure that the file is written to disk immediately
271 file.close();
272 setProperty(key, QVariant::fromValue(BLOB{path}));
273}
274
275void ApplicationDomainType::setChangedProperties(const QSet<QByteArray> &changeset) 234void ApplicationDomainType::setChangedProperties(const QSet<QByteArray> &changeset)
276{ 235{
277 *mChangeSet = changeset; 236 *mChangeSet = changeset;
diff --git a/common/domain/applicationdomaintype.h b/common/domain/applicationdomaintype.h
index 8a0daef..b4db54e 100644
--- a/common/domain/applicationdomaintype.h
+++ b/common/domain/applicationdomaintype.h
@@ -62,16 +62,6 @@
62 void setStatus##NAME(const TYPE &value) { setProperty(NAME::name, QVariant::fromValue(value)); } \ 62 void setStatus##NAME(const TYPE &value) { setProperty(NAME::name, QVariant::fromValue(value)); } \
63 TYPE get##NAME() const { return getProperty(NAME::name).value<TYPE>(); } \ 63 TYPE get##NAME() const { return getProperty(NAME::name).value<TYPE>(); } \
64 64
65#define SINK_BLOB_PROPERTY(NAME, LOWERCASENAME) \
66 struct NAME { \
67 static constexpr const char *name = #LOWERCASENAME; \
68 typedef BLOB Type; \
69 }; \
70 void set##NAME(const QByteArray &value) { setBlobProperty(NAME::name, value); } \
71 void set##NAME##Path(const QString &path) { setProperty(NAME::name, QVariant::fromValue(BLOB{path})); } \
72 QByteArray get##NAME() const { return getBlobProperty(NAME::name); } \
73 QString get##NAME##Path() const { return getProperty(NAME::name).value<BLOB>().value; } \
74
75#define SINK_REFERENCE_PROPERTY(TYPE, NAME, LOWERCASENAME) \ 65#define SINK_REFERENCE_PROPERTY(TYPE, NAME, LOWERCASENAME) \
76 struct NAME { \ 66 struct NAME { \
77 static constexpr const char *name = #LOWERCASENAME; \ 67 static constexpr const char *name = #LOWERCASENAME; \
@@ -145,23 +135,6 @@ struct SINK_EXPORT Progress {
145/** 135/**
146 * Internal type. 136 * Internal type.
147 * 137 *
148 * Represents a BLOB property.
149 */
150struct BLOB {
151 BLOB() = default;
152 BLOB(const BLOB &) = default;
153 BLOB(const QString &id) : value(id) {};
154 ~BLOB() = default;
155 bool operator==(const BLOB &other) const {
156 return value == other.value && isExternal == other.isExternal;
157 }
158 QString value;
159 bool isExternal = true;
160};
161
162/**
163 * Internal type.
164 *
165 * Represents a reference to another entity in the same resource. 138 * Represents a reference to another entity in the same resource.
166 */ 139 */
167struct Reference { 140struct Reference {
@@ -179,7 +152,7 @@ struct Reference {
179 QByteArray value; 152 QByteArray value;
180}; 153};
181 154
182void copyBuffer(Sink::ApplicationDomain::BufferAdaptor &buffer, Sink::ApplicationDomain::BufferAdaptor &memoryAdaptor, const QList<QByteArray> &properties = QList<QByteArray>(), bool copyBlobs = false, bool pruneReferences = false); 155void copyBuffer(Sink::ApplicationDomain::BufferAdaptor &buffer, Sink::ApplicationDomain::BufferAdaptor &memoryAdaptor, const QList<QByteArray> &properties = QList<QByteArray>(), bool pruneReferences = false);
183 156
184/** 157/**
185 * The domain type interface has two purposes: 158 * The domain type interface has two purposes:
@@ -223,7 +196,7 @@ public:
223 static typename DomainType::Ptr getInMemoryRepresentation(const ApplicationDomainType &domainType, const QList<QByteArray> properties = QList<QByteArray>()) 196 static typename DomainType::Ptr getInMemoryRepresentation(const ApplicationDomainType &domainType, const QList<QByteArray> properties = QList<QByteArray>())
224 { 197 {
225 auto memoryAdaptor = QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create(); 198 auto memoryAdaptor = QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create();
226 copyBuffer(*(domainType.mAdaptor), *memoryAdaptor, properties, false, false); 199 copyBuffer(*(domainType.mAdaptor), *memoryAdaptor, properties, false);
227 //mIdentifier internally still refers to the memory-mapped memory, we need to copy the memory or it will become invalid 200 //mIdentifier internally still refers to the memory-mapped memory, we need to copy the memory or it will become invalid
228 return QSharedPointer<DomainType>::create(domainType.mResourceInstanceIdentifier, QByteArray(domainType.mIdentifier.constData(), domainType.mIdentifier.size()), domainType.mRevision, memoryAdaptor); 201 return QSharedPointer<DomainType>::create(domainType.mResourceInstanceIdentifier, QByteArray(domainType.mIdentifier.constData(), domainType.mIdentifier.size()), domainType.mRevision, memoryAdaptor);
229 } 202 }
@@ -236,7 +209,7 @@ public:
236 { 209 {
237 auto memoryAdaptor = QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create(); 210 auto memoryAdaptor = QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create();
238 Q_ASSERT(domainType.mAdaptor); 211 Q_ASSERT(domainType.mAdaptor);
239 copyBuffer(*(domainType.mAdaptor), *memoryAdaptor, properties, true, true); 212 copyBuffer(*(domainType.mAdaptor), *memoryAdaptor, properties, true);
240 return QSharedPointer<DomainType>::create(QByteArray{}, QByteArray{}, 0, memoryAdaptor); 213 return QSharedPointer<DomainType>::create(QByteArray{}, QByteArray{}, 0, memoryAdaptor);
241 } 214 }
242 215
@@ -287,9 +260,6 @@ public:
287 */ 260 */
288 void setProperty(const QByteArray &key, const ApplicationDomainType &value); 261 void setProperty(const QByteArray &key, const ApplicationDomainType &value);
289 262
290 QByteArray getBlobProperty(const QByteArray &key) const;
291 void setBlobProperty(const QByteArray &key, const QByteArray &value);
292
293 void setChangedProperties(const QSet<QByteArray> &changeset); 263 void setChangedProperties(const QSet<QByteArray> &changeset);
294 QByteArrayList changedProperties() const; 264 QByteArrayList changedProperties() const;
295 QByteArrayList availableProperties() const; 265 QByteArrayList availableProperties() const;
@@ -321,7 +291,6 @@ inline bool operator==(const ApplicationDomainType& lhs, const ApplicationDomain
321 291
322SINK_EXPORT QDebug operator<< (QDebug d, const ApplicationDomainType &type); 292SINK_EXPORT QDebug operator<< (QDebug d, const ApplicationDomainType &type);
323SINK_EXPORT QDebug operator<< (QDebug d, const Reference &ref); 293SINK_EXPORT QDebug operator<< (QDebug d, const Reference &ref);
324SINK_EXPORT QDebug operator<< (QDebug d, const BLOB &blob);
325 294
326 295
327struct SINK_EXPORT SinkAccount : public ApplicationDomainType { 296struct SINK_EXPORT SinkAccount : public ApplicationDomainType {
@@ -439,7 +408,6 @@ struct SINK_EXPORT Mail : public Entity {
439 SINK_PROPERTY(bool, Unread, unread); 408 SINK_PROPERTY(bool, Unread, unread);
440 SINK_PROPERTY(bool, Important, important); 409 SINK_PROPERTY(bool, Important, important);
441 SINK_REFERENCE_PROPERTY(Folder, Folder, folder); 410 SINK_REFERENCE_PROPERTY(Folder, Folder, folder);
442 // SINK_BLOB_PROPERTY(MimeMessage, mimeMessage);
443 SINK_PROPERTY(QByteArray, MimeMessage, mimeMessage); 411 SINK_PROPERTY(QByteArray, MimeMessage, mimeMessage);
444 SINK_EXTRACTED_PROPERTY(bool, FullPayloadAvailable, fullPayloadAvailable); 412 SINK_EXTRACTED_PROPERTY(bool, FullPayloadAvailable, fullPayloadAvailable);
445 SINK_PROPERTY(bool, Draft, draft); 413 SINK_PROPERTY(bool, Draft, draft);
@@ -542,7 +510,6 @@ class SINK_EXPORT TypeImplementation;
542#undef SINK_ENTITY 510#undef SINK_ENTITY
543#undef SINK_PROPERTY 511#undef SINK_PROPERTY
544#undef SINK_EXTRACTED_PROPERTY 512#undef SINK_EXTRACTED_PROPERTY
545#undef SINK_BLOB_PROPERTY
546#undef SINK_REFERENCE_PROPERTY 513#undef SINK_REFERENCE_PROPERTY
547#undef SINK_INDEX_PROPERTY 514#undef SINK_INDEX_PROPERTY
548 515
@@ -576,5 +543,4 @@ Q_DECLARE_METATYPE(Sink::ApplicationDomain::Mail::Contact)
576Q_DECLARE_METATYPE(Sink::ApplicationDomain::Contact::Email) 543Q_DECLARE_METATYPE(Sink::ApplicationDomain::Contact::Email)
577Q_DECLARE_METATYPE(Sink::ApplicationDomain::Error) 544Q_DECLARE_METATYPE(Sink::ApplicationDomain::Error)
578Q_DECLARE_METATYPE(Sink::ApplicationDomain::Progress) 545Q_DECLARE_METATYPE(Sink::ApplicationDomain::Progress)
579Q_DECLARE_METATYPE(Sink::ApplicationDomain::BLOB)
580Q_DECLARE_METATYPE(Sink::ApplicationDomain::Reference) 546Q_DECLARE_METATYPE(Sink::ApplicationDomain::Reference)
diff --git a/common/domain/propertyregistry.cpp b/common/domain/propertyregistry.cpp
index 7b9b61a..755e7b4 100644
--- a/common/domain/propertyregistry.cpp
+++ b/common/domain/propertyregistry.cpp
@@ -46,15 +46,6 @@ QVariant parseString<Sink::ApplicationDomain::Reference>(const QString &s)
46} 46}
47 47
48template <> 48template <>
49QVariant parseString<Sink::ApplicationDomain::BLOB>(const QString &s)
50{
51 //TODO copy path
52 // return QVariant::fromValue(Sink::ApplicationDomain::BLOB{s.toLatin1()});
53 Q_ASSERT(false);
54 return QVariant{};
55}
56
57template <>
58QVariant parseString<bool>(const QString &s) 49QVariant parseString<bool>(const QString &s)
59{ 50{
60 if (s == "true") { 51 if (s == "true") {
diff --git a/common/domain/propertyregistry.h b/common/domain/propertyregistry.h
index 758c10d..be63989 100644
--- a/common/domain/propertyregistry.h
+++ b/common/domain/propertyregistry.h
@@ -43,9 +43,6 @@ template <>
43QVariant parseString<Sink::ApplicationDomain::Reference>(const QString &s); 43QVariant parseString<Sink::ApplicationDomain::Reference>(const QString &s);
44 44
45template <> 45template <>
46QVariant parseString<Sink::ApplicationDomain::BLOB>(const QString &s);
47
48template <>
49QVariant parseString<bool>(const QString &s); 46QVariant parseString<bool>(const QString &s);
50 47
51template <> 48template <>