Some file info workarounds.

Use default font in emoji picker.
This commit is contained in:
Black Hat 2018-11-23 23:28:04 +08:00
parent c7afe6b5ad
commit c88d41f359
3 changed files with 46 additions and 16 deletions

View File

@ -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
}

View File

@ -9,6 +9,8 @@
#include "events/typingevent.h"
#include <QFileDialog>
#include <QFileInfo>
#include <QImageReader>
#include <QMetaObject>
#include <QMimeDatabase>
@ -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,18 +69,35 @@ 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},
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()}}};
postJson("m.room.message", json);
{"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}}}};
}
QString SpectralRoom::getMIME(const QUrl& fileUrl) const {
return QMimeDatabase().mimeTypeForFile(fileUrl.toLocalFile()).name();
postJson("m.room.message", json);
}
void SpectralRoom::saveFileAs(QString eventId) {

View File

@ -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);