Some file info workarounds.
Use default font in emoji picker.
This commit is contained in:
parent
c7afe6b5ad
commit
c88d41f359
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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,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},
|
||||
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()}}};
|
||||
{"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));
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue