Commit 93709635 authored by JanKusanagi's avatar JanKusanagi

Abort ongoing file upload when cancelling post, if there is one

parent 841a3bc9
......@@ -118,6 +118,7 @@ Publisher::Publisher(PumpController *pumpController,
m_uploadProgressBar = new QProgressBar(this);
m_uploading = false;
// Set default pixmap and "media not set" message
......@@ -938,6 +939,19 @@ void Publisher::setMinimumMode()
// Re-enable stuff just in case the POST request never finished
this->toggleWidgetsWhileSending(true);
if (m_uploading)
{
qDebug() << "Aborting ongoing upload...";
// Should use m_uploadNetworkReply->abort(), but that causes
// PumpController to report error and set Publisher to "posting failed"
m_uploadNetworkReply->deleteLater();
m_uploading = false; // Need to set it manually since the connect()s
// for the QNetworkReply are gone at this point
m_pumpController->showStatusMessageAndLogIt(tr("Attachment upload "
"was cancelled."));
}
#ifdef GROUPSUPPORT
m_groupIdLabel->hide();
m_groupIdLineEdit->hide();
......@@ -1587,6 +1601,7 @@ void Publisher::sendPost()
}
else
{
m_uploading = true;
m_uploadNetworkReply = m_pumpController->postMedia(audienceMap,
cleanHtmlString,
postTitle,
......@@ -1595,8 +1610,10 @@ void Publisher::sendPost()
m_mediaContentType);
connect(m_uploadNetworkReply, &QNetworkReply::uploadProgress,
this, &Publisher::updateProgressBar);
// This will be automatically disconnected when
// the QNetworkReply is automatically deleted!
connect(m_uploadNetworkReply, &QNetworkReply::finished,
this, &Publisher::onUploadFinished);
// These will be automatically disconnected when
// the QNetworkReply is automatically deleted
// The "remove" button uses the same space as the progress bar
m_removeMediaButton->hide();
......@@ -1657,6 +1674,12 @@ void Publisher::updateProgressBar(qint64 sent, qint64 total)
.toString(total / 1024)));
}
void Publisher::onUploadFinished()
{
qDebug() << "File upload finished in some way";
m_uploading = false;
}
void Publisher::updateCharacterCounter()
{
......
......@@ -120,6 +120,7 @@ public slots:
void onSelectMediaFilePressed();
void updateProgressBar(qint64 sent, qint64 total);
void onUploadFinished();
void updateCharacterCounter();
......@@ -192,6 +193,7 @@ private:
bool m_fullMode;
QNetworkReply *m_uploadNetworkReply;
bool m_uploading;
PumpController *m_pumpController;
GlobalObject *m_globalObject;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment