Allow to open file directly

Fix #506

Signed-off-by: Carl Schwan <carl@carlschwan.eu>
This commit is contained in:
Carl Schwan
2022-11-16 20:44:34 +01:00
committed by Tobias Fella
parent 3e5421604b
commit ffa8fbf365
3 changed files with 46 additions and 8 deletions

View File

@@ -6,6 +6,7 @@
#include <QFileInfo>
#include <QMetaObject>
#include <QMimeDatabase>
#include <QTemporaryFile>
#include <QTextDocument>
#include <functional>
@@ -1241,3 +1242,15 @@ PollHandler *NeoChatRoom::poll(const QString &eventId)
return m_polls[eventId];
}
#endif
bool NeoChatRoom::downloadTempFile(const QString &eventId)
{
QTemporaryFile file;
file.setAutoRemove(false);
if (!file.open()) {
return false;
}
downloadFile(eventId, file.fileName());
return true;
}

View File

@@ -39,8 +39,6 @@ struct Mention {
class NeoChatRoom : public Quotient::Room
{
Q_OBJECT
Q_PROPERTY(QVariantList usersTyping READ getUsersTyping NOTIFY typingChanged)
Q_PROPERTY(bool hasFileUploading READ hasFileUploading WRITE setHasFileUploading NOTIFY hasFileUploadingChanged)
@@ -195,6 +193,8 @@ public:
bool canEncryptRoom() const;
Q_INVOKABLE bool downloadTempFile(const QString &eventId);
#ifdef QUOTIENT_07
Q_INVOKABLE PollHandler *poll(const QString &eventId);
#endif

View File

@@ -16,6 +16,11 @@ TimelineContainer {
onOpenContextMenu: openFileContext(model, fileDelegate)
readonly property bool downloaded: progressInfo && progressInfo.completed
property bool autoOpenFile: false
onDownloadedChanged: if (autoOpenFile) {
openSavedFile();
}
function saveFileAs() {
const dialog = fileDialog.createObject(QQC2.ApplicationWindow.overlay)
@@ -41,13 +46,17 @@ TimelineContainer {
name: "downloaded"
when: progressInfo.completed
PropertyChanges {
target: openButton
visible: false
}
PropertyChanges {
target: downloadButton
icon.name: "document-open"
QQC2.ToolTip.text: i18nc("tooltip for a button on a message; offers ability to open its downloaded file with an appropriate application", "Open File")
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
onClicked: openSavedFile()
}
@@ -56,6 +65,11 @@ TimelineContainer {
name: "downloading"
when: progressInfo.active
PropertyChanges {
target: openButton
visible: false
}
PropertyChanges {
target: sizeLabel
text: i18nc("file download progress", "%1 / %2", Controller.formatByteSize(progressInfo.progress), Controller.formatByteSize(progressInfo.total))
@@ -65,7 +79,6 @@ TimelineContainer {
icon.name: "media-playback-stop"
QQC2.ToolTip.text: i18nc("tooltip for a button on a message; stops downloading the message's file", "Stop Download")
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
onClicked: currentRoom.cancelFileTransfer(eventId)
}
},
@@ -82,10 +95,10 @@ TimelineContainer {
]
Kirigami.Icon {
id: ikon
source: model.fileMimetypeIcon
fallback: "unknown"
}
ColumnLayout {
Layout.alignment: Qt.AlignVCenter
Layout.fillWidth: true
@@ -108,12 +121,26 @@ TimelineContainer {
}
}
QQC2.Button {
id: openButton
icon.name: "document-open"
onClicked: {
autoOpenFile = true;
currentRoom.downloadTempFile(eventId);
}
QQC2.ToolTip.text: i18nc("tooltip for a button on a message; offers ability to open its downloaded file with an appropriate application", "Open File")
QQC2.ToolTip.visible: hovered
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
}
QQC2.Button {
id: downloadButton
icon.name: "download"
QQC2.ToolTip.text: i18nc("tooltip for a button on a message; offers ability to download its file", "Download")
QQC2.ToolTip.visible: hovered
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
}
Component {
@@ -122,9 +149,7 @@ TimelineContainer {
FileDialog {
fileMode: FileDialog.SaveFile
folder: StandardPaths.writableLocation(StandardPaths.DownloadLocation)
onAccepted: {
currentRoom.downloadFile(eventId, file)
}
onAccepted: currentRoom.downloadFile(eventId, file)
}
}
}