diff --git a/imports/Spectral/Component/Emoji/EmojiPicker.qml b/imports/Spectral/Component/Emoji/EmojiPicker.qml index 526ccb0..c875488 100644 --- a/imports/Spectral/Component/Emoji/EmojiPicker.qml +++ b/imports/Spectral/Component/Emoji/EmojiPicker.qml @@ -42,12 +42,11 @@ ColumnLayout { width: 64 height: 48 - contentItem: Text { + contentItem: Label { horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter font.pixelSize: 24 - font.family: "Emoji" text: label } @@ -92,12 +91,11 @@ ColumnLayout { width: 48 height: 48 - contentItem: Text { + contentItem: Label { horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter font.pixelSize: 32 - font.family: "Emoji" text: modelData.unicode } diff --git a/src/spectralroom.cpp b/src/spectralroom.cpp index 01f38dc..ee7aa44 100644 --- a/src/spectralroom.cpp +++ b/src/spectralroom.cpp @@ -9,6 +9,8 @@ #include "events/typingevent.h" #include +#include +#include #include #include @@ -24,6 +26,20 @@ SpectralRoom::SpectralRoom(Connection* connection, QString roomId, connect(this, &Room::addedMessages, this, [=] { setBusy(false); }); } +inline QString getMIME(const QUrl& fileUrl) { + return QMimeDatabase().mimeTypeForFile(fileUrl.toLocalFile()).name(); +} + +inline QSize getImageSize(const QUrl& imageUrl) { + QImageReader reader(imageUrl.toLocalFile()); + return reader.size(); +} + +inline int getFileSize(const QUrl& url) { + QFileInfo info(url.toLocalFile()); + return int(info.size()); +} + void SpectralRoom::chooseAndUploadFile() { auto localFile = QFileDialog::getOpenFileUrl(Q_NULLPTR, tr("Save File as")); if (!localFile.isEmpty()) { @@ -53,20 +69,37 @@ void SpectralRoom::postFile(const QUrl& localFile, const QUrl& mxcUrl) { const QString mime = getMIME(localFile); const QString fileName = localFile.fileName(); QString msgType = "m.file"; - if (mime.startsWith("image")) msgType = "m.image"; - if (mime.startsWith("video")) msgType = "m.video"; - if (mime.startsWith("audio")) msgType = "m.audio"; - QJsonObject json{QJsonObject{{"msgtype", msgType}, - {"body", fileName}, - {"filename", fileName}, - {"url", mxcUrl.url()}}}; + int fileSize = getFileSize(localFile); + QJsonObject json; + if (mime.startsWith("image")) { + msgType = "m.image"; + QSize imageSize = getImageSize(localFile); + json = {{"msgtype", msgType}, + {"body", fileName}, + {"filename", fileName}, + {"url", mxcUrl.url()}, + {"info", QJsonObject{{"h", imageSize.height()}, + {"w", imageSize.width()}, + {"size", fileSize}, + {"mimetype", mime}, + {"thumbnail_url", mxcUrl.url()}, + {"thumbnail_info", + QJsonObject{{"h", imageSize.height()}, + {"w", imageSize.width()}, + {"size", fileSize}, + {"mimetype", mime}}}}}}; + } else { + if (mime.startsWith("video")) msgType = "m.video"; + if (mime.startsWith("audio")) msgType = "m.audio"; + json = {{"msgtype", msgType}, + {"body", fileName}, + {"filename", fileName}, + {"url", mxcUrl.url()}, + {"info", QJsonObject{{"size", fileSize}, {"mimetype", mime}}}}; + } postJson("m.room.message", json); } -QString SpectralRoom::getMIME(const QUrl& fileUrl) const { - return QMimeDatabase().mimeTypeForFile(fileUrl.toLocalFile()).name(); -} - void SpectralRoom::saveFileAs(QString eventId) { auto fileName = QFileDialog::getSaveFileName(Q_NULLPTR, tr("Save File as"), fileNameToDownload(eventId)); diff --git a/src/spectralroom.h b/src/spectralroom.h index 14866c0..155cb44 100644 --- a/src/spectralroom.h +++ b/src/spectralroom.h @@ -108,7 +108,6 @@ class SpectralRoom : public Room { bool m_busy = false; - QString getMIME(const QUrl& fileUrl) const; void postFile(const QUrl& localFile, const QUrl& mxcUrl); void checkForHighlights(const QMatrixClient::TimelineItem& ti);