aboutsummaryrefslogtreecommitdiff
path: root/launcher/tasks/ConcurrentTask.cpp
diff options
context:
space:
mode:
authorRachel Powers <508861+Ryex@users.noreply.github.com>2023-03-30 23:50:29 -0700
committerRachel Powers <508861+Ryex@users.noreply.github.com>2023-05-01 10:47:20 -0700
commit9d2f0e4dc8fc3995052770c6a7948cb0372fdcbb (patch)
tree4daee3300ac1b7ad650e715395434d5277027bdf /launcher/tasks/ConcurrentTask.cpp
parentf997529cd4fb077b06d05da9c6ff0c23b85b4ebb (diff)
downloadPrismLauncher-9d2f0e4dc8fc3995052770c6a7948cb0372fdcbb.tar.gz
PrismLauncher-9d2f0e4dc8fc3995052770c6a7948cb0372fdcbb.tar.bz2
PrismLauncher-9d2f0e4dc8fc3995052770c6a7948cb0372fdcbb.zip
feat: Propogated subtask progress
Oh boy this is big. > TaskStepProgress struct is now QMetaObject compatabile and can be sent through signals > Task now has a method to propogates sub task progress it must be signal bound by each task containing a task wishing to report progress of it's children. > Downloads report speed > Tasks now have UUIDS to track them - use when reporting - use when logging - use when storeing them or objects related to them Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com>
Diffstat (limited to 'launcher/tasks/ConcurrentTask.cpp')
-rw-r--r--launcher/tasks/ConcurrentTask.cpp44
1 files changed, 26 insertions, 18 deletions
diff --git a/launcher/tasks/ConcurrentTask.cpp b/launcher/tasks/ConcurrentTask.cpp
index 48e1bc18..fde7d0ad 100644
--- a/launcher/tasks/ConcurrentTask.cpp
+++ b/launcher/tasks/ConcurrentTask.cpp
@@ -2,6 +2,7 @@
#include <QDebug>
#include <QCoreApplication>
+#include "tasks/Task.h"
ConcurrentTask::ConcurrentTask(QObject* parent, QString task_name, int max_concurrent)
: Task(parent), m_name(task_name), m_total_max_size(max_concurrent)
@@ -15,13 +16,9 @@ ConcurrentTask::~ConcurrentTask()
}
}
-auto ConcurrentTask::getStepProgress() const -> QList<TaskStepProgress>
+auto ConcurrentTask::getStepProgress() const -> TaskStepProgressList
{
- QList<TaskStepProgress> task_progress;
- for (auto progress : task_progress) {
- task_progress.append(task_progress);
- }
- return task_progress;
+ return m_task_progress.values();
}
void ConcurrentTask::addTask(Task::Ptr task)
@@ -103,7 +100,7 @@ void ConcurrentTask::startNext()
connect(next.get(), &Task::failed, this, [this, next](QString msg) { subTaskFailed(next, msg); });
connect(next.get(), &Task::status, this, [this, next](QString msg){ subTaskStatus(next, msg); });
- connect(next.get(), &Task::stepProgress, this, [this, next](QList<TaskStepProgress> tp){ subTaskStepProgress(next, tp); });
+ connect(next.get(), &Task::stepProgress, this, [this, next](TaskStepProgressList tp){ subTaskStepProgress(next, tp); });
connect(next.get(), &Task::progress, this, [this, next](qint64 current, qint64 total){ subTaskProgress(next, current, total); });
@@ -112,6 +109,7 @@ void ConcurrentTask::startNext()
updateState();
+ updateStepProgress();
QCoreApplication::processEvents();
@@ -129,12 +127,12 @@ void ConcurrentTask::subTaskSucceeded(Task::Ptr task)
m_succeeded.insert(task.get(), task);
m_doing.remove(task.get());
- m_task_progress.value(task->getUid())->state = TaskState::Succeeded;
+ m_task_progress.value(task->getUid())->state = TaskStepState::Succeeded;
disconnect(task.get(), 0, this, 0);
updateState();
-
+ updateStepProgress();
startNext();
}
@@ -144,20 +142,22 @@ void ConcurrentTask::subTaskFailed(Task::Ptr task, const QString& msg)
m_failed.insert(task.get(), task);
m_doing.remove(task.get());
- m_task_progress.value(task->getUid())->state = TaskState::Failed;
+ m_task_progress.value(task->getUid())->state = TaskStepState::Failed;
disconnect(task.get(), 0, this, 0);
updateState();
-
+ updateStepProgress();
startNext();
}
void ConcurrentTask::subTaskStatus(Task::Ptr task, const QString& msg)
{
auto taskProgress = m_task_progress.value(task->getUid());
- taskProgress->status = msg;
+ taskProgress->status = msg;
+ taskProgress->state = TaskStepState::Running;
updateState();
+ updateStepProgress();
}
void ConcurrentTask::subTaskProgress(Task::Ptr task, qint64 current, qint64 total)
@@ -166,21 +166,28 @@ void ConcurrentTask::subTaskProgress(Task::Ptr task, qint64 current, qint64 tota
taskProgress->current = current;
taskProgress->total = total;
-
+ taskProgress->state = TaskStepState::Running;
taskProgress->details = task->getDetails();
updateStepProgress();
updateState();
}
-void ConcurrentTask::subTaskStepProgress(Task::Ptr task, QList<TaskStepProgress> task_step_progress)
+void ConcurrentTask::subTaskStepProgress(Task::Ptr task, TaskStepProgressList task_step_progress)
{
for (auto progress : task_step_progress) {
- if (!m_task_progress.contains(progress.uid))
- m_task_progress.insert(progress.uid, std::make_shared<TaskStepProgress>(progress));
-
-
+ if (!m_task_progress.contains(progress->uid)) {
+ m_task_progress.insert(progress->uid, progress);
+ } else {
+ auto tp = m_task_progress.value(progress->uid);
+ tp->current = progress->current;
+ tp->total = progress->total;
+ tp->status = progress->status;
+ tp->details = progress->details;
+ }
}
+
+ updateStepProgress();
}
@@ -194,6 +201,7 @@ void ConcurrentTask::updateStepProgress()
m_stepProgress = current;
m_stepTotalProgress = total;
+ emit stepProgress(m_task_progress.values());
}
void ConcurrentTask::updateState()