2021-12-16 23:48:52 +01:00
|
|
|
#include <hex/api/task.hpp>
|
|
|
|
|
|
|
|
#include <hex/helpers/shared_data.hpp>
|
|
|
|
|
|
|
|
namespace hex {
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
Task::Task(const std::string &unlocalizedName, u64 maxValue) : m_name(LangEntry(unlocalizedName)), m_maxValue(maxValue), m_currValue(0) {
|
2021-12-16 23:48:52 +01:00
|
|
|
SharedData::runningTasks.push_back(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
Task::~Task() {
|
|
|
|
this->finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Task::finish() {
|
|
|
|
SharedData::runningTasks.remove(this);
|
|
|
|
}
|
|
|
|
|
2022-01-09 21:27:59 +01:00
|
|
|
void Task::setMaxValue(u64 maxValue) {
|
|
|
|
this->m_maxValue = maxValue;
|
|
|
|
}
|
|
|
|
|
2021-12-16 23:48:52 +01:00
|
|
|
void Task::update(u64 currValue) {
|
|
|
|
if (this->m_currValue < this->m_maxValue)
|
|
|
|
this->m_currValue = currValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
double Task::getProgress() const {
|
2022-01-09 21:27:59 +01:00
|
|
|
if (this->m_maxValue == 0)
|
|
|
|
return 100;
|
|
|
|
|
2021-12-16 23:48:52 +01:00
|
|
|
return static_cast<double>(this->m_currValue) / static_cast<double>(this->m_maxValue);
|
|
|
|
}
|
|
|
|
|
2022-01-09 21:27:59 +01:00
|
|
|
bool Task::isPending() const {
|
|
|
|
return this->m_maxValue == 0;
|
|
|
|
}
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
const std::string &Task::getName() const {
|
2021-12-16 23:48:52 +01:00
|
|
|
return this->m_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|