diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-05-01 16:21:28 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-05-01 16:21:28 +0200 |
commit | c1475df297975b403d991f69ef9436cd576c1e46 (patch) | |
tree | 40c4101ce7569c6bebb508ff9e9aa50716120d92 | |
parent | 9040c66f5fb617a057b9c362ac9a937fe9dd0739 (diff) | |
download | sink-c1475df297975b403d991f69ef9436cd576c1e46.tar.gz sink-c1475df297975b403d991f69ef9436cd576c1e46.zip |
Setter and getter for blob properties
-rw-r--r-- | common/domain/applicationdomaintype.cpp | 25 | ||||
-rw-r--r-- | common/domain/applicationdomaintype.h | 5 |
2 files changed, 30 insertions, 0 deletions
diff --git a/common/domain/applicationdomaintype.cpp b/common/domain/applicationdomaintype.cpp index 73143e8..23a63a7 100644 --- a/common/domain/applicationdomaintype.cpp +++ b/common/domain/applicationdomaintype.cpp | |||
@@ -20,6 +20,8 @@ | |||
20 | #include "applicationdomaintype.h" | 20 | #include "applicationdomaintype.h" |
21 | #include "log.h" | 21 | #include "log.h" |
22 | #include "../bufferadaptor.h" | 22 | #include "../bufferadaptor.h" |
23 | #include "definitions.h" | ||
24 | #include <QFile> | ||
23 | 25 | ||
24 | namespace Sink { | 26 | namespace Sink { |
25 | namespace ApplicationDomain { | 27 | namespace ApplicationDomain { |
@@ -86,6 +88,29 @@ void ApplicationDomainType::setProperty(const QByteArray &key, const QVariant &v | |||
86 | mAdaptor->setProperty(key, value); | 88 | mAdaptor->setProperty(key, value); |
87 | } | 89 | } |
88 | 90 | ||
91 | QByteArray ApplicationDomainType::getBlobProperty(const QByteArray &key) const | ||
92 | { | ||
93 | const auto path = getProperty(key).toByteArray(); | ||
94 | QFile file(path); | ||
95 | if (!file.open(QIODevice::ReadOnly)) { | ||
96 | ErrorMsg() << "Failed to open the file: " << file.errorString() << path; | ||
97 | return QByteArray(); | ||
98 | } | ||
99 | return file.readAll(); | ||
100 | } | ||
101 | |||
102 | void ApplicationDomainType::setBlobProperty(const QByteArray &key, const QByteArray &value) | ||
103 | { | ||
104 | const auto path = Sink::temporaryFileLocation() + "/" + QUuid::createUuid().toString(); | ||
105 | QFile file(path); | ||
106 | if (!file.open(QIODevice::WriteOnly)) { | ||
107 | ErrorMsg() << "Failed to open the file: " << file.errorString() << path; | ||
108 | return; | ||
109 | } | ||
110 | file.write(value); | ||
111 | setProperty(key, path); | ||
112 | } | ||
113 | |||
89 | void ApplicationDomainType::setChangedProperties(const QSet<QByteArray> &changeset) | 114 | void ApplicationDomainType::setChangedProperties(const QSet<QByteArray> &changeset) |
90 | { | 115 | { |
91 | mChangeSet = changeset; | 116 | mChangeSet = changeset; |
diff --git a/common/domain/applicationdomaintype.h b/common/domain/applicationdomaintype.h index c94a987..e00b244 100644 --- a/common/domain/applicationdomaintype.h +++ b/common/domain/applicationdomaintype.h | |||
@@ -67,8 +67,13 @@ public: | |||
67 | virtual ~ApplicationDomainType(); | 67 | virtual ~ApplicationDomainType(); |
68 | 68 | ||
69 | bool hasProperty(const QByteArray &key) const; | 69 | bool hasProperty(const QByteArray &key) const; |
70 | |||
70 | QVariant getProperty(const QByteArray &key) const; | 71 | QVariant getProperty(const QByteArray &key) const; |
71 | void setProperty(const QByteArray &key, const QVariant &value); | 72 | void setProperty(const QByteArray &key, const QVariant &value); |
73 | |||
74 | QByteArray getBlobProperty(const QByteArray &key) const; | ||
75 | void setBlobProperty(const QByteArray &key, const QByteArray &value); | ||
76 | |||
72 | void setChangedProperties(const QSet<QByteArray> &changeset); | 77 | void setChangedProperties(const QSet<QByteArray> &changeset); |
73 | QByteArrayList changedProperties() const; | 78 | QByteArrayList changedProperties() const; |
74 | QByteArrayList availableProperties() const; | 79 | QByteArrayList availableProperties() const; |