Merge pull request #4394 from Janrupf/develop

GH-4299 Fix Screenshot upload
This commit is contained in:
Petr Mrázek 2021-12-30 19:58:16 +01:00 committed by GitHub
commit 5e909a4e85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 9 deletions

View File

@ -98,6 +98,12 @@ void NetJob::partProgress(int index, qint64 bytesReceived, qint64 bytesTotal)
void NetJob::executeTask()
{
if(!m_network) {
qCritical() << "Attempted to start NetJob" << objectName() << "without the network set!";
emitFailed(tr("Internal error: NetJob '%1' has been started without a network pointer!").arg(objectName()));
return;
}
// hack that delays early failures so they can be caught easier
QMetaObject::invokeMethod(this, "startMoreParts", Qt::QueuedConnection);
}

View File

@ -35,6 +35,11 @@ public:
}
virtual ~NetJob();
void setNetwork(shared_qobject_ptr<QNetworkAccessManager> network)
{
m_network = network;
}
bool addNetAction(NetAction::Ptr action);
NetAction::Ptr operator[](int index)
@ -67,15 +72,6 @@ public slots:
virtual bool abort() override;
virtual void start(shared_qobject_ptr<QNetworkAccessManager> network) {
m_network = network;
start();
}
protected slots:
void start() override {
if(!m_network) {
throw "Missing network while trying to start " + objectName();
return;
}
Task::start();
}

View File

@ -314,6 +314,8 @@ void ScreenshotsPage::on_actionUpload_triggered()
m_uploadActive = true;
ProgressDialog dialog(this);
job->setNetwork(APPLICATION->network());
if(dialog.execWithTask(job.get()) != QDialog::Accepted)
{
CustomMessageBox::selectable(this, tr("Failed to upload screenshots!"),
@ -348,7 +350,9 @@ void ScreenshotsPage::on_actionUpload_triggered()
auto albumTask = NetJob::Ptr(new NetJob("Imgur Album Creation"));
auto imgurAlbum = ImgurAlbumCreation::make(uploaded);
albumTask->addNetAction(imgurAlbum);
job->setNetwork(APPLICATION->network());
task.addTask(job);
albumTask->setNetwork(APPLICATION->network());
task.addTask(albumTask);
m_uploadActive = true;
ProgressDialog prog(this);