From 95854555f038708ddb3fe2e7244deaa57e9a4b8c Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 6 Feb 2018 08:18:38 +0100 Subject: Removed all traces of BLOB properties --- common/domain/applicationdomaintype.cpp | 45 ++------------------------------- common/domain/applicationdomaintype.h | 40 +++-------------------------- common/domain/propertyregistry.cpp | 9 ------- common/domain/propertyregistry.h | 3 --- 4 files changed, 5 insertions(+), 92 deletions(-) (limited to 'common/domain') 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 return d; } -QDebug Sink::ApplicationDomain::operator<< (QDebug d, const Sink::ApplicationDomain::BLOB &blob) -{ - d << blob.value << "external:" << blob.isExternal ; - return d; -} - template int registerProperty() { Sink::Private::PropertyRegistry::instance().registerProperty(Sink::ApplicationDomain::getTypeName()); @@ -130,13 +124,12 @@ static const int foo = [] { QMetaType::registerEqualsComparator(); QMetaType::registerDebugStreamOperator(); QMetaType::registerConverter(); - QMetaType::registerDebugStreamOperator(); QMetaType::registerDebugStreamOperator(); qRegisterMetaTypeStreamOperators(); return 0; }(); -void copyBuffer(Sink::ApplicationDomain::BufferAdaptor &buffer, Sink::ApplicationDomain::BufferAdaptor &memoryAdaptor, const QList &properties, bool copyBlobs, bool pruneReferences) +void copyBuffer(Sink::ApplicationDomain::BufferAdaptor &buffer, Sink::ApplicationDomain::BufferAdaptor &memoryAdaptor, const QList &properties, bool pruneReferences) { auto propertiesToCopy = properties; if (properties.isEmpty()) { @@ -144,14 +137,7 @@ void copyBuffer(Sink::ApplicationDomain::BufferAdaptor &buffer, Sink::Applicatio } for (const auto &property : propertiesToCopy) { const auto value = buffer.getProperty(property); - if (copyBlobs && value.canConvert()) { - const auto oldPath = value.value().value; - const auto newPath = Sink::temporaryFileLocation() + "/" + createUuid(); - if (!QFile::copy(oldPath, newPath)) { - SinkWarning() << "Failed to copy file from: " << oldPath << "to: " << newPath; - } - memoryAdaptor.setProperty(property, QVariant::fromValue(BLOB{newPath})); - } else if (pruneReferences && value.canConvert()) { + if (pruneReferences && value.canConvert()) { continue; } else { memoryAdaptor.setProperty(property, value); @@ -245,33 +231,6 @@ void ApplicationDomainType::setProperty(const QByteArray &key, const Application setProperty(key, QVariant::fromValue(Reference{value.identifier()})); } -QByteArray ApplicationDomainType::getBlobProperty(const QByteArray &key) const -{ - const auto path = getProperty(key).value().value; - QFile file(path); - if (!file.open(QIODevice::ReadOnly)) { - SinkError() << "Failed to open the file for reading: " << file.errorString() << "Path:" << path << " For property:" << key; - return QByteArray(); - } - return file.readAll(); -} - -void ApplicationDomainType::setBlobProperty(const QByteArray &key, const QByteArray &value) -{ - const auto path = Sink::temporaryFileLocation() + "/" + createUuid(); - QFile file(path); - if (!file.open(QIODevice::WriteOnly)) { - SinkError() << "Failed to open the file for writing: " << file.errorString() << path << " For property " << key; - return; - } - if (file.write(value) < 0) { - SinkError() << "Failed to write to file: " << file.errorString() << path << " For property " << key; - } - //Ensure that the file is written to disk immediately - file.close(); - setProperty(key, QVariant::fromValue(BLOB{path})); -} - void ApplicationDomainType::setChangedProperties(const QSet &changeset) { *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 @@ 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 { \ - static constexpr const char *name = #LOWERCASENAME; \ - typedef BLOB Type; \ - }; \ - void set##NAME(const QByteArray &value) { setBlobProperty(NAME::name, value); } \ - void set##NAME##Path(const QString &path) { setProperty(NAME::name, QVariant::fromValue(BLOB{path})); } \ - QByteArray get##NAME() const { return getBlobProperty(NAME::name); } \ - QString get##NAME##Path() const { return getProperty(NAME::name).value().value; } \ - #define SINK_REFERENCE_PROPERTY(TYPE, NAME, LOWERCASENAME) \ struct NAME { \ static constexpr const char *name = #LOWERCASENAME; \ @@ -142,23 +132,6 @@ struct SINK_EXPORT Progress { }; -/** - * Internal type. - * - * Represents a BLOB property. - */ -struct BLOB { - BLOB() = default; - BLOB(const BLOB &) = default; - BLOB(const QString &id) : value(id) {}; - ~BLOB() = default; - bool operator==(const BLOB &other) const { - return value == other.value && isExternal == other.isExternal; - } - QString value; - bool isExternal = true; -}; - /** * Internal type. * @@ -179,7 +152,7 @@ struct Reference { QByteArray value; }; -void copyBuffer(Sink::ApplicationDomain::BufferAdaptor &buffer, Sink::ApplicationDomain::BufferAdaptor &memoryAdaptor, const QList &properties = QList(), bool copyBlobs = false, bool pruneReferences = false); +void copyBuffer(Sink::ApplicationDomain::BufferAdaptor &buffer, Sink::ApplicationDomain::BufferAdaptor &memoryAdaptor, const QList &properties = QList(), bool pruneReferences = false); /** * The domain type interface has two purposes: @@ -223,7 +196,7 @@ public: static typename DomainType::Ptr getInMemoryRepresentation(const ApplicationDomainType &domainType, const QList properties = QList()) { auto memoryAdaptor = QSharedPointer::create(); - copyBuffer(*(domainType.mAdaptor), *memoryAdaptor, properties, false, false); + copyBuffer(*(domainType.mAdaptor), *memoryAdaptor, properties, false); //mIdentifier internally still refers to the memory-mapped memory, we need to copy the memory or it will become invalid return QSharedPointer::create(domainType.mResourceInstanceIdentifier, QByteArray(domainType.mIdentifier.constData(), domainType.mIdentifier.size()), domainType.mRevision, memoryAdaptor); } @@ -236,7 +209,7 @@ public: { auto memoryAdaptor = QSharedPointer::create(); Q_ASSERT(domainType.mAdaptor); - copyBuffer(*(domainType.mAdaptor), *memoryAdaptor, properties, true, true); + copyBuffer(*(domainType.mAdaptor), *memoryAdaptor, properties, true); return QSharedPointer::create(QByteArray{}, QByteArray{}, 0, memoryAdaptor); } @@ -287,9 +260,6 @@ public: */ void setProperty(const QByteArray &key, const ApplicationDomainType &value); - QByteArray getBlobProperty(const QByteArray &key) const; - void setBlobProperty(const QByteArray &key, const QByteArray &value); - void setChangedProperties(const QSet &changeset); QByteArrayList changedProperties() const; QByteArrayList availableProperties() const; @@ -321,7 +291,6 @@ inline bool operator==(const ApplicationDomainType& lhs, const ApplicationDomain SINK_EXPORT QDebug operator<< (QDebug d, const ApplicationDomainType &type); SINK_EXPORT QDebug operator<< (QDebug d, const Reference &ref); -SINK_EXPORT QDebug operator<< (QDebug d, const BLOB &blob); struct SINK_EXPORT SinkAccount : public ApplicationDomainType { @@ -439,7 +408,6 @@ struct SINK_EXPORT Mail : public Entity { SINK_PROPERTY(bool, Unread, unread); SINK_PROPERTY(bool, Important, important); SINK_REFERENCE_PROPERTY(Folder, Folder, folder); - // SINK_BLOB_PROPERTY(MimeMessage, mimeMessage); SINK_PROPERTY(QByteArray, MimeMessage, mimeMessage); SINK_EXTRACTED_PROPERTY(bool, FullPayloadAvailable, fullPayloadAvailable); SINK_PROPERTY(bool, Draft, draft); @@ -542,7 +510,6 @@ class SINK_EXPORT TypeImplementation; #undef SINK_ENTITY #undef SINK_PROPERTY #undef SINK_EXTRACTED_PROPERTY -#undef SINK_BLOB_PROPERTY #undef SINK_REFERENCE_PROPERTY #undef SINK_INDEX_PROPERTY @@ -576,5 +543,4 @@ Q_DECLARE_METATYPE(Sink::ApplicationDomain::Mail::Contact) Q_DECLARE_METATYPE(Sink::ApplicationDomain::Contact::Email) Q_DECLARE_METATYPE(Sink::ApplicationDomain::Error) Q_DECLARE_METATYPE(Sink::ApplicationDomain::Progress) -Q_DECLARE_METATYPE(Sink::ApplicationDomain::BLOB) Q_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 @@ -45,15 +45,6 @@ QVariant parseString(const QString &s) return QVariant::fromValue(Sink::ApplicationDomain::Reference{s.toLatin1()}); } -template <> -QVariant parseString(const QString &s) -{ - //TODO copy path - // return QVariant::fromValue(Sink::ApplicationDomain::BLOB{s.toLatin1()}); - Q_ASSERT(false); - return QVariant{}; -} - template <> QVariant parseString(const QString &s) { 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 @@ -42,9 +42,6 @@ QVariant parseString(const QString &s); template <> QVariant parseString(const QString &s); -template <> -QVariant parseString(const QString &s); - template <> QVariant parseString(const QString &s); -- cgit v1.2.3