Auto identify file type as m.image.
This commit is contained in:
parent
cf84320794
commit
c10c3b1d1d
|
@ -20,7 +20,7 @@ AvatarContainer {
|
||||||
|
|
||||||
Image {
|
Image {
|
||||||
id: messageImage
|
id: messageImage
|
||||||
source: "image://mxc/" + content.url
|
source: "image://mxc/" + (content.thumbnail_url ? content.thumbnail_url : content.url)
|
||||||
|
|
||||||
MouseArea {
|
MouseArea {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
|
|
@ -150,12 +150,12 @@ Item {
|
||||||
folder: shortcuts.home
|
folder: shortcuts.home
|
||||||
selectMultiple: false
|
selectMultiple: false
|
||||||
onAccepted: {
|
onAccepted: {
|
||||||
currentRoom.uploadFile(fileDialog.fileUrl, fileDialog.fileUrl)
|
currentRoom.uploadFile(fileUrl, fileUrl, matriqueController.getMIME(fileUrl))
|
||||||
var fileTransferProgressCallback = function(id, sent, total) {
|
var fileTransferProgressCallback = function(id, sent, total) {
|
||||||
if (id == fileDialog.fileUrl) { inputField.progress = sent / total }
|
if (id == fileUrl) { inputField.progress = sent / total }
|
||||||
}
|
}
|
||||||
var completedCallback = function(id, localFile, mxcUrl) {
|
var completedCallback = function(id, localFile, mxcUrl) {
|
||||||
if (id == fileDialog.fileUrl) {
|
if (id == fileUrl) {
|
||||||
matriqueController.postFile(currentRoom, localFile, mxcUrl)
|
matriqueController.postFile(currentRoom, localFile, mxcUrl)
|
||||||
inputField.progress = 0
|
inputField.progress = 0
|
||||||
currentRoom.fileTransferCompleted.disconnect(fileTransferProgressCallback)
|
currentRoom.fileTransferCompleted.disconnect(fileTransferProgressCallback)
|
||||||
|
|
|
@ -4,6 +4,10 @@
|
||||||
#include "events/eventcontent.h"
|
#include "events/eventcontent.h"
|
||||||
#include "events/roommessageevent.h"
|
#include "events/roommessageevent.h"
|
||||||
|
|
||||||
|
#include <QFile>
|
||||||
|
#include <QImage>
|
||||||
|
#include <QMimeDatabase>
|
||||||
|
|
||||||
Controller::Controller(QObject* parent) : QObject(parent) {
|
Controller::Controller(QObject* parent) : QObject(parent) {
|
||||||
connect(m_connection, &QMatrixClient::Connection::connected, this,
|
connect(m_connection, &QMatrixClient::Connection::connected, this,
|
||||||
&Controller::connected);
|
&Controller::connected);
|
||||||
|
@ -22,7 +26,11 @@ Controller::Controller(QObject* parent) : QObject(parent) {
|
||||||
[=] { setBusy(false); });
|
[=] { setBusy(false); });
|
||||||
}
|
}
|
||||||
|
|
||||||
Controller::~Controller() { m_connection->stopSync(); }
|
Controller::~Controller() {
|
||||||
|
m_connection->saveState();
|
||||||
|
m_connection->stopSync();
|
||||||
|
m_connection->deleteLater();
|
||||||
|
}
|
||||||
|
|
||||||
void Controller::login() {
|
void Controller::login() {
|
||||||
if (!isLogin) {
|
if (!isLogin) {
|
||||||
|
@ -81,10 +89,22 @@ void Controller::reconnect() {
|
||||||
|
|
||||||
void Controller::postFile(QMatrixClient::Room* room, const QUrl& localFile,
|
void Controller::postFile(QMatrixClient::Room* room, const QUrl& localFile,
|
||||||
const QUrl& mxcUrl) {
|
const QUrl& mxcUrl) {
|
||||||
QJsonObject json{{"body", localFile.fileName()},
|
const QString mime = getMIME(localFile);
|
||||||
{"filename", localFile.fileName()},
|
const QString fileName = localFile.toLocalFile();
|
||||||
{"url", mxcUrl.url()}};
|
QString msgType = "m.file";
|
||||||
room->postMessage(QMatrixClient::RoomMessageEvent{
|
if (mime.startsWith("image")) msgType = "m.image";
|
||||||
localFile.fileName(), "m.file",
|
if (mime.startsWith("video")) msgType = "m.video";
|
||||||
new QMatrixClient::EventContent::FileContent(json)});
|
if (mime.startsWith("audio")) msgType = "m.audio";
|
||||||
|
QJsonObject json{{"content", QJsonObject{{"msgtype", msgType},
|
||||||
|
{"body", fileName},
|
||||||
|
{"filename", fileName},
|
||||||
|
{"url", mxcUrl.url()}}}};
|
||||||
|
room->postMessage(QMatrixClient::RoomMessageEvent(json));
|
||||||
|
}
|
||||||
|
|
||||||
|
QString Controller::getMIME(const QUrl& fileUrl) const {
|
||||||
|
QMimeDatabase* db = new QMimeDatabase();
|
||||||
|
const QString mime = db->mimeTypeForFile(fileUrl.toLocalFile()).name();
|
||||||
|
free(db);
|
||||||
|
return mime;
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,6 +99,7 @@ class Controller : public QObject {
|
||||||
public slots:
|
public slots:
|
||||||
void postFile(QMatrixClient::Room* room, const QUrl& localFile,
|
void postFile(QMatrixClient::Room* room, const QUrl& localFile,
|
||||||
const QUrl& mxcUrl);
|
const QUrl& mxcUrl);
|
||||||
|
QString getMIME(const QUrl& fileUrl) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CONTROLLER_H
|
#endif // CONTROLLER_H
|
||||||
|
|
Loading…
Reference in New Issue