Allow to open file directly
Fix #506 Signed-off-by: Carl Schwan <carl@carlschwan.eu>
This commit is contained in:
committed by
Tobias Fella
parent
3e5421604b
commit
ffa8fbf365
@@ -6,6 +6,7 @@
|
|||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QMetaObject>
|
#include <QMetaObject>
|
||||||
#include <QMimeDatabase>
|
#include <QMimeDatabase>
|
||||||
|
#include <QTemporaryFile>
|
||||||
#include <QTextDocument>
|
#include <QTextDocument>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
@@ -1241,3 +1242,15 @@ PollHandler *NeoChatRoom::poll(const QString &eventId)
|
|||||||
return m_polls[eventId];
|
return m_polls[eventId];
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
bool NeoChatRoom::downloadTempFile(const QString &eventId)
|
||||||
|
{
|
||||||
|
QTemporaryFile file;
|
||||||
|
file.setAutoRemove(false);
|
||||||
|
if (!file.open()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
downloadFile(eventId, file.fileName());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|||||||
@@ -39,8 +39,6 @@ struct Mention {
|
|||||||
|
|
||||||
class NeoChatRoom : public Quotient::Room
|
class NeoChatRoom : public Quotient::Room
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(QVariantList usersTyping READ getUsersTyping NOTIFY typingChanged)
|
Q_PROPERTY(QVariantList usersTyping READ getUsersTyping NOTIFY typingChanged)
|
||||||
Q_PROPERTY(bool hasFileUploading READ hasFileUploading WRITE setHasFileUploading NOTIFY hasFileUploadingChanged)
|
Q_PROPERTY(bool hasFileUploading READ hasFileUploading WRITE setHasFileUploading NOTIFY hasFileUploadingChanged)
|
||||||
@@ -195,6 +193,8 @@ public:
|
|||||||
|
|
||||||
bool canEncryptRoom() const;
|
bool canEncryptRoom() const;
|
||||||
|
|
||||||
|
Q_INVOKABLE bool downloadTempFile(const QString &eventId);
|
||||||
|
|
||||||
#ifdef QUOTIENT_07
|
#ifdef QUOTIENT_07
|
||||||
Q_INVOKABLE PollHandler *poll(const QString &eventId);
|
Q_INVOKABLE PollHandler *poll(const QString &eventId);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -16,6 +16,11 @@ TimelineContainer {
|
|||||||
onOpenContextMenu: openFileContext(model, fileDelegate)
|
onOpenContextMenu: openFileContext(model, fileDelegate)
|
||||||
|
|
||||||
readonly property bool downloaded: progressInfo && progressInfo.completed
|
readonly property bool downloaded: progressInfo && progressInfo.completed
|
||||||
|
property bool autoOpenFile: false
|
||||||
|
|
||||||
|
onDownloadedChanged: if (autoOpenFile) {
|
||||||
|
openSavedFile();
|
||||||
|
}
|
||||||
|
|
||||||
function saveFileAs() {
|
function saveFileAs() {
|
||||||
const dialog = fileDialog.createObject(QQC2.ApplicationWindow.overlay)
|
const dialog = fileDialog.createObject(QQC2.ApplicationWindow.overlay)
|
||||||
@@ -41,13 +46,17 @@ TimelineContainer {
|
|||||||
name: "downloaded"
|
name: "downloaded"
|
||||||
when: progressInfo.completed
|
when: progressInfo.completed
|
||||||
|
|
||||||
|
PropertyChanges {
|
||||||
|
target: openButton
|
||||||
|
visible: false
|
||||||
|
}
|
||||||
|
|
||||||
PropertyChanges {
|
PropertyChanges {
|
||||||
target: downloadButton
|
target: downloadButton
|
||||||
|
|
||||||
icon.name: "document-open"
|
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.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()
|
onClicked: openSavedFile()
|
||||||
}
|
}
|
||||||
@@ -56,6 +65,11 @@ TimelineContainer {
|
|||||||
name: "downloading"
|
name: "downloading"
|
||||||
when: progressInfo.active
|
when: progressInfo.active
|
||||||
|
|
||||||
|
PropertyChanges {
|
||||||
|
target: openButton
|
||||||
|
visible: false
|
||||||
|
}
|
||||||
|
|
||||||
PropertyChanges {
|
PropertyChanges {
|
||||||
target: sizeLabel
|
target: sizeLabel
|
||||||
text: i18nc("file download progress", "%1 / %2", Controller.formatByteSize(progressInfo.progress), Controller.formatByteSize(progressInfo.total))
|
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"
|
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.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)
|
onClicked: currentRoom.cancelFileTransfer(eventId)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -82,10 +95,10 @@ TimelineContainer {
|
|||||||
]
|
]
|
||||||
|
|
||||||
Kirigami.Icon {
|
Kirigami.Icon {
|
||||||
id: ikon
|
|
||||||
source: model.fileMimetypeIcon
|
source: model.fileMimetypeIcon
|
||||||
fallback: "unknown"
|
fallback: "unknown"
|
||||||
}
|
}
|
||||||
|
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
Layout.alignment: Qt.AlignVCenter
|
Layout.alignment: Qt.AlignVCenter
|
||||||
Layout.fillWidth: true
|
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 {
|
QQC2.Button {
|
||||||
id: downloadButton
|
id: downloadButton
|
||||||
icon.name: "download"
|
icon.name: "download"
|
||||||
|
|
||||||
QQC2.ToolTip.text: i18nc("tooltip for a button on a message; offers ability to download its file", "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.visible: hovered
|
||||||
|
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
|
||||||
}
|
}
|
||||||
|
|
||||||
Component {
|
Component {
|
||||||
@@ -122,9 +149,7 @@ TimelineContainer {
|
|||||||
FileDialog {
|
FileDialog {
|
||||||
fileMode: FileDialog.SaveFile
|
fileMode: FileDialog.SaveFile
|
||||||
folder: StandardPaths.writableLocation(StandardPaths.DownloadLocation)
|
folder: StandardPaths.writableLocation(StandardPaths.DownloadLocation)
|
||||||
onAccepted: {
|
onAccepted: currentRoom.downloadFile(eventId, file)
|
||||||
currentRoom.downloadFile(eventId, file)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user