Handle transfer job being canceled
Set KilledJobError to indicate it was canceled by the user to avoid a bogus "finished" notification. Sadly, fileTransferCanceled has been removed from libQuotient so this lambda botch checking transfer status needs to be done.
This commit is contained in:
@@ -41,6 +41,15 @@ void FileTransferPseudoJob::fileTransferFailed(const QString &id, const QString
|
|||||||
emitResult();
|
emitResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FileTransferPseudoJob::fileTransferCanceled(const QString &id)
|
||||||
|
{
|
||||||
|
if (id != m_eventId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setError(KJob::KilledJobError);
|
||||||
|
emitResult();
|
||||||
|
}
|
||||||
|
|
||||||
void FileTransferPseudoJob::start()
|
void FileTransferPseudoJob::start()
|
||||||
{
|
{
|
||||||
setTotalAmount(Unit::Files, 1);
|
setTotalAmount(Unit::Files, 1);
|
||||||
|
|||||||
@@ -38,6 +38,11 @@ public:
|
|||||||
*/
|
*/
|
||||||
void fileTransferFailed(const QString &id, const QString &errorMessage = {});
|
void fileTransferFailed(const QString &id, const QString &errorMessage = {});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set the file transfer as canceled.
|
||||||
|
*/
|
||||||
|
void fileTransferCanceled(const QString &id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Start the file transfer.
|
* @brief Start the file transfer.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -256,7 +256,14 @@ QCoro::Task<void> NeoChatRoom::doUploadFile(QUrl url, QString body)
|
|||||||
auto job = new FileTransferPseudoJob(FileTransferPseudoJob::Upload, url.toLocalFile(), txnId);
|
auto job = new FileTransferPseudoJob(FileTransferPseudoJob::Upload, url.toLocalFile(), txnId);
|
||||||
connect(this, &Room::fileTransferProgress, job, &FileTransferPseudoJob::fileTransferProgress);
|
connect(this, &Room::fileTransferProgress, job, &FileTransferPseudoJob::fileTransferProgress);
|
||||||
connect(this, &Room::fileTransferCompleted, job, &FileTransferPseudoJob::fileTransferCompleted);
|
connect(this, &Room::fileTransferCompleted, job, &FileTransferPseudoJob::fileTransferCompleted);
|
||||||
connect(this, &Room::fileTransferFailed, job, &FileTransferPseudoJob::fileTransferFailed);
|
connect(this, &Room::fileTransferFailed, job, [this, job, txnId] {
|
||||||
|
auto info = fileTransferInfo(txnId);
|
||||||
|
if (info.status == FileTransferInfo::Cancelled) {
|
||||||
|
job->fileTransferCanceled(txnId);
|
||||||
|
} else {
|
||||||
|
job->fileTransferFailed(txnId);
|
||||||
|
}
|
||||||
|
});
|
||||||
KIO::getJobTracker()->registerJob(job);
|
KIO::getJobTracker()->registerJob(job);
|
||||||
job->start();
|
job->start();
|
||||||
#endif
|
#endif
|
||||||
@@ -1511,7 +1518,14 @@ void NeoChatRoom::download(const QString &eventId, const QUrl &localFilename)
|
|||||||
auto job = new FileTransferPseudoJob(FileTransferPseudoJob::Download, localFilename.toLocalFile(), eventId);
|
auto job = new FileTransferPseudoJob(FileTransferPseudoJob::Download, localFilename.toLocalFile(), eventId);
|
||||||
connect(this, &Room::fileTransferProgress, job, &FileTransferPseudoJob::fileTransferProgress);
|
connect(this, &Room::fileTransferProgress, job, &FileTransferPseudoJob::fileTransferProgress);
|
||||||
connect(this, &Room::fileTransferCompleted, job, &FileTransferPseudoJob::fileTransferCompleted);
|
connect(this, &Room::fileTransferCompleted, job, &FileTransferPseudoJob::fileTransferCompleted);
|
||||||
connect(this, &Room::fileTransferFailed, job, &FileTransferPseudoJob::fileTransferFailed);
|
connect(this, &Room::fileTransferFailed, job, [this, job, eventId] {
|
||||||
|
auto info = fileTransferInfo(eventId);
|
||||||
|
if (info.status == FileTransferInfo::Cancelled) {
|
||||||
|
job->fileTransferCanceled(eventId);
|
||||||
|
} else {
|
||||||
|
job->fileTransferFailed(eventId);
|
||||||
|
}
|
||||||
|
});
|
||||||
KIO::getJobTracker()->registerJob(job);
|
KIO::getJobTracker()->registerJob(job);
|
||||||
job->start();
|
job->start();
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user