Sync from quickmods

This commit is contained in:
Petr Mrázek
2014-09-06 18:16:56 +02:00
parent 36efcf8d3c
commit 20cb97a35a
57 changed files with 569 additions and 326 deletions

View File

@ -1,31 +1,7 @@
#include "SequentialTask.h"
SequentialTask::SequentialTask(QObject *parent) :
Task(parent), m_currentIndex(-1)
SequentialTask::SequentialTask(QObject *parent) : Task(parent), m_currentIndex(-1)
{
}
QString SequentialTask::getStatus() const
{
if (m_queue.isEmpty() || m_currentIndex >= m_queue.size())
{
return QString();
}
return m_queue.at(m_currentIndex)->getStatus();
}
void SequentialTask::getProgress(qint64 &current, qint64 &total)
{
current = 0;
total = 0;
for (int i = 0; i < m_queue.size(); ++i)
{
qint64 subCurrent, subTotal;
m_queue.at(i)->getProgress(subCurrent, subTotal);
current += subCurrent;
total += subTotal;
}
}
void SequentialTask::addTask(std::shared_ptr<ProgressProvider> task)
@ -55,10 +31,9 @@ void SequentialTask::startNext()
std::shared_ptr<ProgressProvider> next = m_queue[m_currentIndex];
connect(next.get(), SIGNAL(failed(QString)), this, SLOT(subTaskFailed(QString)));
connect(next.get(), SIGNAL(status(QString)), this, SLOT(subTaskStatus(QString)));
connect(next.get(), SIGNAL(progress(qint64,qint64)), this, SLOT(subTaskProgress()));
connect(next.get(), SIGNAL(progress(qint64, qint64)), this, SLOT(subTaskProgress(qint64, qint64)));
connect(next.get(), SIGNAL(succeeded()), this, SLOT(startNext()));
next->start();
emit status(getStatus());
}
void SequentialTask::subTaskFailed(const QString &msg)
@ -69,16 +44,16 @@ void SequentialTask::subTaskStatus(const QString &msg)
{
setStatus(msg);
}
void SequentialTask::subTaskProgress()
void SequentialTask::subTaskProgress(qint64 current, qint64 total)
{
qint64 current, total;
getProgress(current, total);
if (total == 0)
if(total == 0)
{
setProgress(0);
return;
}
else
{
setProgress(100 * current / total);
}
auto dcurrent = (double) current;
auto dtotal = (double) total;
auto partial = ((dcurrent / dtotal) * 100.0f)/* / double(m_queue.size())*/;
// auto bigpartial = double(m_currentIndex) * 100.0f / double(m_queue.size());
setProgress(partial);
}