diff --git a/imports/Spectral/Panel/RoomPanel.qml b/imports/Spectral/Panel/RoomPanel.qml index 4573481..185e4bd 100644 --- a/imports/Spectral/Panel/RoomPanel.qml +++ b/imports/Spectral/Panel/RoomPanel.qml @@ -23,6 +23,18 @@ Item { room: currentRoom } + DropArea { + anchors.fill: parent + + enabled: currentRoom + + onDropped: { + if (!drop.hasUrls) return + + currentRoom.uploadFile(drop.urls[0]) + } + } + Column { anchors.centerIn: parent diff --git a/src/spectralroom.cpp b/src/spectralroom.cpp index ca5e207..63b3f33 100644 --- a/src/spectralroom.cpp +++ b/src/spectralroom.cpp @@ -47,32 +47,39 @@ inline QSize getImageSize(const QUrl& imageUrl) { void SpectralRoom::chooseAndUploadFile() { auto localFile = QFileDialog::getOpenFileUrl(Q_NULLPTR, tr("Save File as")); if (!localFile.isEmpty()) { - QString txnID = postFile(localFile.fileName(), localFile, false); - setHasFileUploading(true); - connect(this, &Room::fileTransferCompleted, - [=](QString id, QUrl localFile, QUrl mxcUrl) { - if (id == txnID) { - setFileUploadingProgress(0); - setHasFileUploading(false); - } - }); - connect(this, &Room::fileTransferFailed, [=](QString id, QString error) { - if (id == txnID) { - setFileUploadingProgress(0); - setHasFileUploading(false); - } - }); - connect( - this, &Room::fileTransferProgress, - [=](QString id, qint64 progress, qint64 total) { - if (id == txnID) { - qDebug() << "Progress:" << progress << total; - setFileUploadingProgress(int(float(progress) / float(total) * 100)); - } - }); + uploadFile(localFile); } } +void SpectralRoom::uploadFile(const QUrl& url) { + if (url.isEmpty()) + return; + + QString txnID = postFile(url.fileName(), url, false); + setHasFileUploading(true); + connect(this, &Room::fileTransferCompleted, + [=](QString id, QUrl localFile, QUrl mxcUrl) { + if (id == txnID) { + setFileUploadingProgress(0); + setHasFileUploading(false); + } + }); + connect(this, &Room::fileTransferFailed, [=](QString id, QString error) { + if (id == txnID) { + setFileUploadingProgress(0); + setHasFileUploading(false); + } + }); + connect( + this, &Room::fileTransferProgress, + [=](QString id, qint64 progress, qint64 total) { + if (id == txnID) { + qDebug() << "Progress:" << progress << total; + setFileUploadingProgress(int(float(progress) / float(total) * 100)); + } + }); +} + void SpectralRoom::acceptInvitation() { connection()->joinRoom(id()); } diff --git a/src/spectralroom.h b/src/spectralroom.h index 205c3f6..72cc487 100644 --- a/src/spectralroom.h +++ b/src/spectralroom.h @@ -255,6 +255,7 @@ class SpectralRoom : public Room { public slots: void chooseAndUploadFile(); + void uploadFile(const QUrl& url); void acceptInvitation(); void forget(); void sendTypingNotification(bool isTyping);