diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-01-13 19:42:37 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-01-13 19:42:37 +0900 |
commit | 32d2673ff6268ad00c2b80912e7675673480096c (patch) | |
tree | 685ab7a115f2bfc4be0c293c3965e8bd9ced614e /events/eventcontent.cpp | |
parent | 8f4a940d70cdcfc34a2ffe2d9a9561c0d821c56e (diff) | |
download | libquotient-32d2673ff6268ad00c2b80912e7675673480096c.tar.gz libquotient-32d2673ff6268ad00c2b80912e7675673480096c.zip |
Refactor EventContent; allow to easily check files out of message events
The whole inheritance/templating structure has been considerably simplified by using a trick with mixin classes; thanks to that, *Info classes are no more templated, they are just mixed together by the almighty UrlBasedContent<> template (but the same can easily be done outside of it, as LocationContent implementation shows). RoomMessageEvent has gained hasFileContent(); it's also possible to easily get a FileInfo core object just by calling msgEvent->content()->fileInfo().
Diffstat (limited to 'events/eventcontent.cpp')
-rw-r--r-- | events/eventcontent.cpp | 51 |
1 files changed, 38 insertions, 13 deletions
diff --git a/events/eventcontent.cpp b/events/eventcontent.cpp index dcbccf08..271669e2 100644 --- a/events/eventcontent.cpp +++ b/events/eventcontent.cpp @@ -30,27 +30,21 @@ QJsonObject Base::toJson() const return o; } -QJsonObject InfoBase::toInfoJson() const -{ - QJsonObject info; - fillInfoJson(&info); - return info; -} - -void InfoBase::fillInfoJson(QJsonObject*) const { } - FileInfo::FileInfo(const QUrl& u, int payloadSize, const QMimeType& mimeType, const QString& originalFilename) - : InfoBase(mimeType), url(u), payloadSize(payloadSize) + : mimeType(mimeType), url(u), payloadSize(payloadSize) , originalName(originalFilename) { } FileInfo::FileInfo(const QUrl& u, const QJsonObject& infoJson, const QString& originalFilename) - : FileInfo(u, infoJson["size"].toInt(), - QMimeDatabase().mimeTypeForName(infoJson["mimetype"].toString()), - originalFilename) + : originalInfoJson(infoJson) + , mimeType(QMimeDatabase().mimeTypeForName(infoJson["mimetype"].toString())) + , url(u) + , payloadSize(infoJson["size"].toInt()) + , originalName(originalFilename) { + originalInfoJson.insert("mediaId", url.authority() + url.path()); if (!mimeType.isValid()) mimeType = QMimeDatabase().mimeTypeForData(QByteArray()); } @@ -61,3 +55,34 @@ void FileInfo::fillInfoJson(QJsonObject* infoJson) const infoJson->insert("size", payloadSize); infoJson->insert("mimetype", mimeType.name()); } + +ImageInfo::ImageInfo(const QUrl& u, int fileSize, QMimeType mimeType, + const QSize& imageSize) + : FileInfo(u, fileSize, mimeType), imageSize(imageSize) +{ } + +ImageInfo::ImageInfo(const QUrl& u, const QJsonObject& infoJson, + const QString& originalFilename) + : FileInfo(u, infoJson, originalFilename) + , imageSize(infoJson["w"].toInt(), infoJson["h"].toInt()) +{ } + +void ImageInfo::fillInfoJson(QJsonObject* infoJson) const +{ + FileInfo::fillInfoJson(infoJson); + infoJson->insert("w", imageSize.width()); + infoJson->insert("h", imageSize.height()); +} + +WithThumbnail::WithThumbnail(const QJsonObject& infoJson) + : thumbnail(infoJson["thumbnail_url"].toString(), + infoJson["thumbnail_info"].toObject()) +{ } + +void WithThumbnail::fillInfoJson(QJsonObject* infoJson) const +{ + infoJson->insert("thumbnail_url", thumbnail.url.toString()); + QJsonObject thumbnailInfoJson; + thumbnail.fillInfoJson(&thumbnailInfoJson); + infoJson->insert("thumbnail_info", thumbnailInfoJson); +} |