summaryrefslogtreecommitdiffstats
path: root/api/logic/net/NetJob.cpp
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2016-08-14 02:33:31 +0200
committerPetr Mrázek <peterix@gmail.com>2016-08-14 23:22:54 +0200
commit042f3ef55c0b469f438542152c4eb02b0789ea3c (patch)
tree03e0c15b200786558babd0fe58edac88ed1bfd1e /api/logic/net/NetJob.cpp
parent2f0441b3c1cd9fc3bcb176d2852da8f92a6e6777 (diff)
downloadMultiMC-042f3ef55c0b469f438542152c4eb02b0789ea3c.tar
MultiMC-042f3ef55c0b469f438542152c4eb02b0789ea3c.tar.gz
MultiMC-042f3ef55c0b469f438542152c4eb02b0789ea3c.tar.lz
MultiMC-042f3ef55c0b469f438542152c4eb02b0789ea3c.tar.xz
MultiMC-042f3ef55c0b469f438542152c4eb02b0789ea3c.zip
GH-352 Make OneSix instance update downloads cancellable
Diffstat (limited to 'api/logic/net/NetJob.cpp')
-rw-r--r--api/logic/net/NetJob.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/api/logic/net/NetJob.cpp b/api/logic/net/NetJob.cpp
index ca86242a..2e375760 100644
--- a/api/logic/net/NetJob.cpp
+++ b/api/logic/net/NetJob.cpp
@@ -47,6 +47,15 @@ void NetJob::partFailed(int index)
startMoreParts();
}
+void NetJob::partAborted(int index)
+{
+ m_aborted = true;
+ m_doing.remove(index);
+ m_failed.insert(index);
+ downloads[index].get()->disconnect(this);
+ startMoreParts();
+}
+
void NetJob::partProgress(int index, qint64 bytesReceived, qint64 bytesTotal)
{
auto &slot = parts_progress[index];
@@ -85,6 +94,11 @@ void NetJob::startMoreParts()
qDebug() << m_job_name << "succeeded.";
emitSucceeded();
}
+ else if(m_aborted)
+ {
+ qDebug() << m_job_name << "aborted.";
+ emitFailed(tr("Job '%1' aborted.").arg(m_job_name));
+ }
else
{
qCritical() << m_job_name << "failed.";
@@ -104,6 +118,7 @@ void NetJob::startMoreParts()
// connect signals :D
connect(part.get(), SIGNAL(succeeded(int)), SLOT(partSucceeded(int)));
connect(part.get(), SIGNAL(failed(int)), SLOT(partFailed(int)));
+ connect(part.get(), SIGNAL(aborted(int)), SLOT(partAborted(int)));
connect(part.get(), SIGNAL(netActionProgress(int, qint64, qint64)),
SLOT(partProgress(int, qint64, qint64)));
part->start();
@@ -121,3 +136,37 @@ QStringList NetJob::getFailedFiles()
failed.sort();
return failed;
}
+
+bool NetJob::canAbort() const
+{
+ bool canFullyAbort = true;
+ // can abort the waiting?
+ for(auto index: m_todo)
+ {
+ auto part = downloads[index];
+ canFullyAbort &= part->canAbort();
+ }
+ // can abort the active?
+ for(auto index: m_doing)
+ {
+ auto part = downloads[index];
+ canFullyAbort &= part->canAbort();
+ }
+ return canFullyAbort;
+}
+
+bool NetJob::abort()
+{
+ bool fullyAborted = true;
+ // fail all waiting
+ m_failed.unite(m_todo.toSet());
+ m_todo.clear();
+ // abort active
+ auto toKill = m_doing.toList();
+ for(auto index: toKill)
+ {
+ auto part = downloads[index];
+ fullyAborted &= part->abort();
+ }
+ return fullyAborted;
+}