diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-12-06 18:32:32 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-12-06 18:32:32 +0100 |
commit | 319a303bdceba18d0e5629f3de7a2b85646223be (patch) | |
tree | 7e4ccb76fa5ee875f49ea3d65e9e519e90573354 /common/domain/applicationdomaintype.cpp | |
parent | 59aa460cf704d5f1a1fb1fe6b8ede4457da083ff (diff) | |
download | sink-319a303bdceba18d0e5629f3de7a2b85646223be.tar.gz sink-319a303bdceba18d0e5629f3de7a2b85646223be.zip |
Wrap blob properties in type so we can distinguish it from other properties.
When moving an entity to another resource we have to move the blob
properties to a temporary directory first, and that requires that we are
able to distinguish blob properties from the rest at runtime.
Diffstat (limited to 'common/domain/applicationdomaintype.cpp')
-rw-r--r-- | common/domain/applicationdomaintype.cpp | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/common/domain/applicationdomaintype.cpp b/common/domain/applicationdomaintype.cpp index 105ae56..1e54622 100644 --- a/common/domain/applicationdomaintype.cpp +++ b/common/domain/applicationdomaintype.cpp | |||
@@ -31,6 +31,25 @@ namespace ApplicationDomain { | |||
31 | 31 | ||
32 | constexpr const char *Mail::ThreadId::name; | 32 | constexpr const char *Mail::ThreadId::name; |
33 | 33 | ||
34 | void copyBuffer(Sink::ApplicationDomain::BufferAdaptor &buffer, Sink::ApplicationDomain::BufferAdaptor &memoryAdaptor, const QList<QByteArray> &properties, bool copyBlobs) | ||
35 | { | ||
36 | auto propertiesToCopy = properties; | ||
37 | if (properties.isEmpty()) { | ||
38 | propertiesToCopy = buffer.availableProperties(); | ||
39 | } | ||
40 | for (const auto &property : propertiesToCopy) { | ||
41 | const auto value = buffer.getProperty(property); | ||
42 | if (copyBlobs && value.canConvert<BLOB>()) { | ||
43 | auto oldPath = value.value<BLOB>().value; | ||
44 | auto newPath = oldPath + "copy"; | ||
45 | QFile::copy(oldPath, newPath); | ||
46 | memoryAdaptor.setProperty(property, QVariant::fromValue(BLOB{newPath})); | ||
47 | } else { | ||
48 | memoryAdaptor.setProperty(property, value); | ||
49 | } | ||
50 | } | ||
51 | } | ||
52 | |||
34 | ApplicationDomainType::ApplicationDomainType() | 53 | ApplicationDomainType::ApplicationDomainType() |
35 | :mAdaptor(new MemoryBufferAdaptor()) | 54 | :mAdaptor(new MemoryBufferAdaptor()) |
36 | { | 55 | { |
@@ -85,9 +104,6 @@ bool ApplicationDomainType::hasProperty(const QByteArray &key) const | |||
85 | QVariant ApplicationDomainType::getProperty(const QByteArray &key) const | 104 | QVariant ApplicationDomainType::getProperty(const QByteArray &key) const |
86 | { | 105 | { |
87 | Q_ASSERT(mAdaptor); | 106 | Q_ASSERT(mAdaptor); |
88 | if (!mAdaptor->availableProperties().contains(key)) { | ||
89 | return QVariant(); | ||
90 | } | ||
91 | return mAdaptor->getProperty(key); | 107 | return mAdaptor->getProperty(key); |
92 | } | 108 | } |
93 | 109 | ||
@@ -111,7 +127,7 @@ void ApplicationDomainType::setProperty(const QByteArray &key, const Application | |||
111 | 127 | ||
112 | QByteArray ApplicationDomainType::getBlobProperty(const QByteArray &key) const | 128 | QByteArray ApplicationDomainType::getBlobProperty(const QByteArray &key) const |
113 | { | 129 | { |
114 | const auto path = getProperty(key).toByteArray(); | 130 | const auto path = getProperty(key).value<BLOB>().value; |
115 | QFile file(path); | 131 | QFile file(path); |
116 | if (!file.open(QIODevice::ReadOnly)) { | 132 | if (!file.open(QIODevice::ReadOnly)) { |
117 | SinkError() << "Failed to open the file: " << file.errorString() << path; | 133 | SinkError() << "Failed to open the file: " << file.errorString() << path; |
@@ -131,7 +147,7 @@ void ApplicationDomainType::setBlobProperty(const QByteArray &key, const QByteAr | |||
131 | file.write(value); | 147 | file.write(value); |
132 | //Ensure that the file is written to disk immediately | 148 | //Ensure that the file is written to disk immediately |
133 | file.close(); | 149 | file.close(); |
134 | setProperty(key, path); | 150 | setProperty(key, QVariant::fromValue(BLOB{path})); |
135 | } | 151 | } |
136 | 152 | ||
137 | void ApplicationDomainType::setChangedProperties(const QSet<QByteArray> &changeset) | 153 | void ApplicationDomainType::setChangedProperties(const QSet<QByteArray> &changeset) |