fix: abort and fail logic in tasks

Also sets up correctly the status connections
This commit is contained in:
flow
2022-05-01 11:05:31 -03:00
parent 040ee919e5
commit 57d65177c8
4 changed files with 11 additions and 4 deletions

View File

@@ -69,6 +69,8 @@ void Download::addValidator(Validator* v)
void Download::executeTask()
{
setStatus(tr("Downloading %1").arg(m_url.toString()));
if (getState() == Task::State::AbortedByUser) {
qWarning() << "Attempt to start an aborted Download:" << m_url.toString();
emitAborted();
@@ -90,6 +92,7 @@ void Download::executeTask()
emitFailed();
return;
case State::AbortedByUser:
emitAborted();
return;
}
@@ -216,13 +219,13 @@ void Download::downloadFinished()
qDebug() << "Download failed in previous step:" << m_url.toString();
m_sink->abort();
m_reply.reset();
emitFailed();
emit failed("");
return;
} else if (m_state == State::AbortedByUser) {
qDebug() << "Download aborted in previous step:" << m_url.toString();
m_sink->abort();
m_reply.reset();
emitAborted();
emit aborted();
return;
}
@@ -239,7 +242,7 @@ void Download::downloadFinished()
qDebug() << "Download failed to finalize:" << m_url.toString();
m_sink->abort();
m_reply.reset();
emitFailed();
emit failed("");
return;
}

View File

@@ -47,7 +47,9 @@ auto NetJob::addNetAction(NetAction::Ptr action) -> bool
if (action->isRunning()) {
connect(action.get(), &NetAction::succeeded, [this, action]{ partSucceeded(action->index()); });
connect(action.get(), &NetAction::failed, [this, action](QString){ partFailed(action->index()); });
connect(action.get(), &NetAction::aborted, [this, action](){ partAborted(action->index()); });
connect(action.get(), &NetAction::progress, [this, action](qint64 done, qint64 total) { partProgress(action->index(), done, total); });
connect(action.get(), &NetAction::status, this, &NetJob::status);
} else {
m_todo.append(m_parts_progress.size() - 1);
}
@@ -222,6 +224,7 @@ void NetJob::startMoreParts()
connect(part.get(), &NetAction::failed, this, [this, part](QString){ partFailed(part->index()); });
connect(part.get(), &NetAction::aborted, this, [this, part]{ partAborted(part->index()); });
connect(part.get(), &NetAction::progress, this, [this, part](qint64 done, qint64 total) { partProgress(part->index(), done, total); });
connect(part.get(), &NetAction::status, this, &NetJob::status);
part->startAction(m_network);
}