diff options
author | Trial97 <alexandru.tripon97@gmail.com> | 2023-05-31 20:12:12 +0300 |
---|---|---|
committer | Trial97 <alexandru.tripon97@gmail.com> | 2023-05-31 20:12:12 +0300 |
commit | 29c3dc40ef7f5b1fce5ab5970a39613d0f7f5089 (patch) | |
tree | ce92f8a86d08531879105a16194a14391c0ae2ea /launcher/tasks/Task.h | |
parent | e8ee4497f77a571b305a48b70f84c8729b800859 (diff) | |
parent | 954d4d701a136e79c25b58f9680d26a555a6e6fe (diff) | |
download | PrismLauncher-29c3dc40ef7f5b1fce5ab5970a39613d0f7f5089.tar.gz PrismLauncher-29c3dc40ef7f5b1fce5ab5970a39613d0f7f5089.tar.bz2 PrismLauncher-29c3dc40ef7f5b1fce5ab5970a39613d0f7f5089.zip |
Merge branch 'develop' of https://github.com/PrismLauncher/PrismLauncher into logdir
Diffstat (limited to 'launcher/tasks/Task.h')
-rw-r--r-- | launcher/tasks/Task.h | 66 |
1 files changed, 61 insertions, 5 deletions
diff --git a/launcher/tasks/Task.h b/launcher/tasks/Task.h index 3d607dca..6d8bbbb4 100644 --- a/launcher/tasks/Task.h +++ b/launcher/tasks/Task.h @@ -1,7 +1,8 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * PrismLauncher - Minecraft Launcher * Copyright (c) 2022 flowln <flowlnlnln@gmail.com> + * Copyright (c) 2023 Rachel Powers <508861+Ryex@users.noreply.github.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -36,9 +37,54 @@ #pragma once #include <QRunnable> +#include <QUuid> +#include <QLoggingCategory> #include "QObjectPtr.h" +Q_DECLARE_LOGGING_CATEGORY(taskLogC) + +enum class TaskStepState { + Waiting, + Running, + Failed, + Succeeded +}; + +Q_DECLARE_METATYPE(TaskStepState) + +struct TaskStepProgress { + QUuid uid; + qint64 current = 0; + qint64 total = -1; + + qint64 old_current = 0; + qint64 old_total = -1; + + QString status = ""; + QString details = ""; + TaskStepState state = TaskStepState::Waiting; + TaskStepProgress() { + this->uid = QUuid::createUuid(); + } + TaskStepProgress(QUuid uid) { + this->uid = uid; + } + bool isDone() const { return (state == TaskStepState::Failed) || (state == TaskStepState::Succeeded); } + void update(qint64 current, qint64 total) { + this->old_current = this->current; + this->old_total = this->total; + + this->current = current; + this->total = total; + this->state = TaskStepState::Running; + } +}; + +Q_DECLARE_METATYPE(TaskStepProgress) + +typedef QList<std::shared_ptr<TaskStepProgress>> TaskStepProgressList; + class Task : public QObject, public QRunnable { Q_OBJECT public: @@ -73,12 +119,15 @@ class Task : public QObject, public QRunnable { auto getState() const -> State { return m_state; } QString getStatus() { return m_status; } - virtual auto getStepStatus() const -> QString { return m_status; } + QString getDetails() { return m_details; } qint64 getProgress() { return m_progress; } qint64 getTotalProgress() { return m_progressTotal; } - virtual auto getStepProgress() const -> qint64 { return 0; } - virtual auto getStepTotalProgress() const -> qint64 { return 100; } + virtual auto getStepProgress() const -> TaskStepProgressList { return {}; } + + + + QUuid getUid() { return m_uid; } protected: void logWarning(const QString& line); @@ -94,7 +143,8 @@ class Task : public QObject, public QRunnable { void aborted(); void failed(QString reason); void status(QString status); - void stepStatus(QString status); + void details(QString details); + void stepProgress(TaskStepProgress const& task_progress); /** Emitted when the canAbort() status has changed. */ @@ -117,8 +167,11 @@ class Task : public QObject, public QRunnable { virtual void emitAborted(); virtual void emitFailed(QString reason = ""); + virtual void propogateStepProgress(TaskStepProgress const& task_progress); + public slots: void setStatus(const QString& status); + void setDetails(const QString& details); void setProgress(qint64 current, qint64 total); protected: @@ -126,6 +179,7 @@ class Task : public QObject, public QRunnable { QStringList m_Warnings; QString m_failReason = ""; QString m_status; + QString m_details; int m_progress = 0; int m_progressTotal = 100; @@ -135,4 +189,6 @@ class Task : public QObject, public QRunnable { private: // Change using setAbortStatus bool m_can_abort = false; + QUuid m_uid; + }; |