Skip to content

Commit

Permalink
Open files on click after download
Browse files Browse the repository at this point in the history
  • Loading branch information
curoviyxru committed Sep 13, 2023
1 parent 9d8b483 commit 833f877
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
8 changes: 4 additions & 4 deletions messagesmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ void MessagesModel::downloadFile(qint32 index)
qint32 messageId = _history[index]["messageId"].toInt();
qint64 requestId = _client->downloadFile(indexedFilePath, _history[index]["mediaDownload"].toMap()).toLongLong();
_downloadRequests.insert(requestId, messageId);
emit downloadUpdated(messageId, 0);
emit downloadUpdated(messageId, 0, "");
}

void MessagesModel::cancelDownload(qint32 index)
Expand All @@ -686,7 +686,7 @@ void MessagesModel::cancelDownload(qint32 index)
qint64 requestId = _downloadRequests.key(messageId);
_downloadRequests.remove(requestId);
_client->cancelDownload(requestId);
emit downloadUpdated(messageId, -1);
emit downloadUpdated(messageId, -1, "");
}

void MessagesModel::fileDownloaded(TgLongVariant fileId, QString filePath)
Expand All @@ -699,7 +699,7 @@ void MessagesModel::fileDownloaded(TgLongVariant fileId, QString filePath)
return;
}

emit downloadUpdated(messageId.toInt(), 1);
emit downloadUpdated(messageId.toInt(), 1, "file:///" + filePath);
}

void MessagesModel::fileDownloadCanceled(TgLongVariant fileId, QString filePath)
Expand All @@ -712,6 +712,6 @@ void MessagesModel::fileDownloadCanceled(TgLongVariant fileId, QString filePath)
return;
}

emit downloadUpdated(messageId.toInt(), -1);
emit downloadUpdated(messageId.toInt(), -1, "");
}

2 changes: 1 addition & 1 deletion messagesmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class MessagesModel : public QAbstractListModel

signals:
void scrollTo(qint32 index);
void downloadUpdated(qint32 messageId, qint32 state);
void downloadUpdated(qint32 messageId, qint32 state, QString filePath);

public slots:
void authorized(TgLongVariant userId);
Expand Down
7 changes: 6 additions & 1 deletion qml/message/MessageDocument.qml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Rectangle {
height: 40 * kgScaling

property int rowIndex: -1
property string filePath: ""

MouseArea {
anchors.fill: parent
Expand All @@ -18,6 +19,8 @@ Rectangle {

if (attachButton.state == "NOT_DOWNLOADING") {
messagesModel.downloadFile(rowIndex);
} else if (attachButton.state == "DOWNLOADED" && filePath.length != 0) {
messagesModel.openUrl(filePath);
} else {
messagesModel.cancelDownload(rowIndex);
}
Expand All @@ -28,11 +31,13 @@ Rectangle {
messagesModel.downloadUpdated.connect(handleDownload);
}

function handleDownload(mid, state) {
function handleDownload(mid, state, path) {
if (mid != messageId) {
return;
}

filePath = path;

switch (state) {
case 1:
attachButton.state = "DOWNLOADED";
Expand Down

0 comments on commit 833f877

Please sign in to comment.