NOISSUE Revert all recent changes to NetAction and NetJob

This commit is contained in:
Petr Mrázek 2017-05-03 23:11:52 +02:00
parent 0efa714ba5
commit e76e6329cd
45 changed files with 356 additions and 338 deletions

View File

@ -26,7 +26,7 @@ InstanceCopyTask::InstanceCopyTask(SettingsObjectPtr settings, BaseInstanceProvi
void InstanceCopyTask::executeTask()
{
setStatusText(tr("Copying instance %1").arg(m_origInstance->name()));
setStatus(tr("Copying instance %1").arg(m_origInstance->name()));
m_stagingPath = m_target->getStagedInstancePath();
FS::copy folderCopy(m_origInstance->instanceRoot(), m_stagingPath);
folderCopy.followSymlinks(false).blacklist(m_matcher.get());

View File

@ -19,7 +19,7 @@ InstanceCreationTask::InstanceCreationTask(SettingsObjectPtr settings, BaseInsta
void InstanceCreationTask::executeTask()
{
setStatusText(tr("Creating instance from version %1").arg(m_version->name()));
setStatus(tr("Creating instance from version %1").arg(m_version->name()));
/*
auto minecraftVersion = std::dynamic_pointer_cast<MinecraftVersion>(m_version);
if(!minecraftVersion)

View File

@ -38,7 +38,7 @@ void InstanceImportTask::executeTask()
}
else
{
setStatusText(tr("Downloading modpack:\n%1").arg(m_sourceUrl.toString()));
setStatus(tr("Downloading modpack:\n%1").arg(m_sourceUrl.toString()));
m_downloadRequired = true;
const QString path = m_sourceUrl.host() + '/' + m_sourceUrl.path();
@ -94,7 +94,7 @@ static QFileInfo findRecursive(const QString &dir, const QString &name)
void InstanceImportTask::extractAndTweak()
{
setStatusText(tr("Extracting modpack"));
setStatus(tr("Extracting modpack"));
m_stagingPath = m_target->getStagedInstancePath();
QDir extractDir(m_stagingPath);
qDebug() << "Attempting to create instance from" << m_archivePath;
@ -321,7 +321,7 @@ void InstanceImportTask::processFlame(const QFileInfo & manifest)
{
setProgress(current, total);
});
setStatusText(tr("Downloading mods..."));
setStatus(tr("Downloading mods..."));
m_filesNetJob->start();
}
);
@ -337,7 +337,7 @@ void InstanceImportTask::processFlame(const QFileInfo & manifest)
});
connect(m_modIdResolver.get(), &Flame::FileResolvingTask::status, [&](QString status)
{
setStatusText(status);
setStatus(status);
});
m_modIdResolver->start();
}

View File

@ -144,7 +144,7 @@ JavaListLoadTask::~JavaListLoadTask()
void JavaListLoadTask::executeTask()
{
setStatusText(tr("Detecting Java installations..."));
setStatus(tr("Detecting Java installations..."));
JavaUtils ju;
QList<QString> candidate_paths = ju.FindJavaPaths();

View File

@ -28,7 +28,7 @@ void Update::executeTask()
{
connect(m_updateTask.get(), SIGNAL(finished()), this, SLOT(updateFinished()));
connect(m_updateTask.get(), &Task::progress, this, &Task::setProgress);
connect(m_updateTask.get(), &Task::status, this, &Task::setStatusText);
connect(m_updateTask.get(), &Task::status, this, &Task::setStatus);
emit progressReportingRequest();
return;
}

View File

@ -199,7 +199,7 @@ NetActionPtr AssetObject::getDownloadAction()
auto rawHash = QByteArray::fromHex(hash.toLatin1());
objectDL->addValidator(new Net::ChecksumValidator(QCryptographicHash::Sha1, rawHash));
}
objectDL->setProgress(0, size);
objectDL->m_total_progress = size;
return objectDL;
}
return nullptr;

View File

@ -51,7 +51,7 @@ void Library::getApplicableFiles(OpSys system, QStringList& jar, QStringList& na
}
}
QList<NetActionPtr> Library::getDownloads(OpSys system, class HttpMetaCache* cache,
QList< std::shared_ptr< NetAction > > Library::getDownloads(OpSys system, class HttpMetaCache* cache,
QStringList& failedFiles, const QString & overridePath) const
{
QList<NetActionPtr> out;

View File

@ -43,7 +43,7 @@ void SkinUpload::executeTask()
QNetworkReply *rep = ENV.qnam().put(request, multiPart);
m_reply = std::shared_ptr<QNetworkReply>(rep);
setStatusText(tr("Uploading skin"));
setStatus(tr("Uploading skin"));
connect(rep, &QNetworkReply::uploadProgress, this, &Task::setProgress);
connect(rep, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(downloadError(QNetworkReply::NetworkError)));
connect(rep, SIGNAL(finished()), this, SLOT(downloadFinished()));

View File

@ -237,7 +237,7 @@ QString YggdrasilTask::getStateMessage() const
void YggdrasilTask::changeState(YggdrasilTask::State newState, QString reason)
{
m_state = newState;
setStatusText(getStateMessage());
setStatus(getStateMessage());
if (newState == STATE_SUCCEEDED)
{
emitSucceeded();

View File

@ -10,7 +10,7 @@ Flame::FileResolvingTask::FileResolvingTask(Flame::Manifest& toProcess)
void Flame::FileResolvingTask::executeTask()
{
setStatusText(tr("Resolving mod IDs..."));
setStatus(tr("Resolving mod IDs..."));
setProgress(0, m_toProcess.files.size());
m_dljob.reset(new NetJob("Mod id resolver"));
results.resize(m_toProcess.files.size());

View File

@ -28,31 +28,31 @@ ForgeXzDownload::ForgeXzDownload(QString relative_path, MetaEntryPtr entry) : Ne
m_entry = entry;
m_target_path = entry->getFullPath();
m_pack200_xz_file.setFileTemplate("./dl_temp.XXXXXX");
m_status = Status::NotStarted;
m_status = Job_NotStarted;
m_url_path = relative_path;
m_url = "http://files.minecraftforge.net/maven/" + m_url_path + ".pack.xz";
}
void ForgeXzDownload::executeTask()
void ForgeXzDownload::start()
{
if(m_status == Status::Aborted)
if(m_status == Job_Aborted)
{
qWarning() << "Attempt to start an aborted Download:" << m_url.toString();
emit aborted();
emit aborted(m_index_within_job);
return;
}
m_status = Status::InProgress;
m_status = Job_InProgress;
if (!m_entry->isStale())
{
m_status = Status::Finished;
emit succeeded();
m_status = Job_Finished;
emit succeeded(m_index_within_job);
return;
}
// can we actually create the real, final file?
if (!FS::ensureFilePathExists(m_target_path))
{
m_status = Status::Failed;
emit failed();
m_status = Job_Failed;
emit failed(m_index_within_job);
return;
}
@ -72,9 +72,9 @@ void ForgeXzDownload::executeTask()
void ForgeXzDownload::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
{
m_progressTotal = bytesTotal;
m_total_progress = bytesTotal;
m_progress = bytesReceived;
emit progress(bytesReceived, bytesTotal);
emit netActionProgress(m_index_within_job, bytesReceived, bytesTotal);
}
void ForgeXzDownload::downloadError(QNetworkReply::NetworkError error)
@ -82,29 +82,29 @@ void ForgeXzDownload::downloadError(QNetworkReply::NetworkError error)
if(error == QNetworkReply::OperationCanceledError)
{
qCritical() << "Aborted " << m_url.toString();
m_status = Status::Aborted;
m_status = Job_Aborted;
}
else
{
// error happened during download.
qCritical() << "Failed " << m_url.toString() << " with reason " << error;
m_status = Status::Failed;
m_status = Job_Failed;
}
}
void ForgeXzDownload::failAndTryNextMirror()
{
m_status = Status::Failed;
emit failed();
m_status = Job_Failed;
emit failed(m_index_within_job);
}
void ForgeXzDownload::downloadFinished()
{
// if the download succeeded
if (m_status != Status::Failed && m_status != Status::Aborted)
if (m_status != Job_Failed && m_status != Job_Aborted)
{
// nothing went wrong...
m_status = Status::Finished;
m_status = Job_Finished;
if (m_pack200_xz_file.isOpen())
{
// we actually downloaded something! process and isntall it
@ -114,25 +114,25 @@ void ForgeXzDownload::downloadFinished()
else
{
// something bad happened -- on the local machine!
m_status = Status::Failed;
m_status = Job_Failed;
m_pack200_xz_file.remove();
m_reply.reset();
emit failed();
emit failed(m_index_within_job);
return;
}
}
else if(m_status == Status::Aborted)
else if(m_status == Job_Aborted)
{
m_pack200_xz_file.remove();
m_reply.reset();
emit failed();
emit aborted();
emit failed(m_index_within_job);
emit aborted(m_index_within_job);
return;
}
// else the download failed
else
{
m_status = Status::Failed;
m_status = Job_Failed;
m_pack200_xz_file.close();
m_pack200_xz_file.remove();
m_reply.reset();
@ -152,7 +152,7 @@ void ForgeXzDownload::downloadReadyRead()
* Can't open the file... the job failed
*/
m_reply->abort();
emit failed();
emit failed(m_index_within_job);
return;
}
}
@ -345,7 +345,7 @@ void ForgeXzDownload::decompressAndInstall()
}
catch (std::runtime_error &err)
{
m_status = Status::Failed;
m_status = Job_Failed;
qCritical() << "Error unpacking " << pack200_file.fileName() << " : " << err.what();
QFile f(m_target_path);
if (f.exists())
@ -374,18 +374,18 @@ void ForgeXzDownload::decompressAndInstall()
ENV.metacache()->updateEntry(m_entry);
m_reply.reset();
emit succeeded();
emit succeeded(m_index_within_job);
}
bool ForgeXzDownload::abort()
{
if(m_reply)
m_reply->abort();
m_status = Status::Aborted;
m_status = Job_Aborted;
return true;
}
bool ForgeXzDownload::canAbort() const
bool ForgeXzDownload::canAbort()
{
return true;
}

View File

@ -19,9 +19,8 @@
#include "net/HttpMetaCache.h"
#include <QFile>
#include <QTemporaryFile>
#include "QObjectPtr.h"
typedef shared_qobject_ptr<class ForgeXzDownload> ForgeXzDownloadPtr;
typedef std::shared_ptr<class ForgeXzDownload> ForgeXzDownloadPtr;
class ForgeXzDownload : public NetAction
{
@ -42,7 +41,7 @@ public:
return ForgeXzDownloadPtr(new ForgeXzDownload(relative_path, entry));
}
virtual ~ForgeXzDownload(){};
bool canAbort() const override;
bool canAbort() override;
protected
slots:
@ -53,7 +52,7 @@ slots:
public
slots:
void executeTask() override;
void start() override;
bool abort() override;
private:

View File

@ -131,7 +131,7 @@ std::shared_ptr<Task> LegacyInstance::createJarModdingTask()
return;
}
setStatusText(tr("Installing mods: Backing up minecraft.jar ..."));
setStatus(tr("Installing mods: Backing up minecraft.jar ..."));
if (!baseJar.exists() && !QFile::copy(runnableJar.filePath(), baseJar.filePath()))
{
emitFailed("It seems both the active and base jar are gone. A fresh base jar will "
@ -155,7 +155,7 @@ std::shared_ptr<Task> LegacyInstance::createJarModdingTask()
return;
}
setStatusText(tr("Installing mods: Opening minecraft.jar ..."));
setStatus(tr("Installing mods: Opening minecraft.jar ..."));
QString outputJarPath = runnableJar.filePath();
QString inputJarPath = baseJar.filePath();

View File

@ -58,7 +58,7 @@ void LegacyUpdate::fmllibsStart()
auto &libList = fmlLibsMapping[version];
// determine if we need some libs for FML or forge
setStatusText(tr("Checking for FML libraries..."));
setStatus(tr("Checking for FML libraries..."));
for (unsigned i = 0; i < modList->size(); i++)
{
auto &mod = modList->operator[](i);
@ -105,7 +105,7 @@ void LegacyUpdate::fmllibsStart()
}
// download missing libs to our place
setStatusText(tr("Dowloading FML libraries..."));
setStatus(tr("Dowloading FML libraries..."));
auto dljob = new NetJob("FML libraries");
auto metacache = ENV.metacache();
for (auto &lib : fmlLibsToProcess)
@ -128,7 +128,7 @@ void LegacyUpdate::fmllibsFinished()
legacyDownloadJob.reset();
if(!fmlLibsToProcess.isEmpty())
{
setStatusText(tr("Copying FML libraries into the instance..."));
setStatus(tr("Copying FML libraries into the instance..."));
LegacyInstance *inst = (LegacyInstance *)m_inst;
auto metacache = ENV.metacache();
int index = 0;
@ -183,7 +183,7 @@ void LegacyUpdate::lwjglStart()
return;
}
setStatusText(tr("Downloading new LWJGL..."));
setStatus(tr("Downloading new LWJGL..."));
auto version = std::dynamic_pointer_cast<LWJGLVersion>(list->findVersion(lwjglVersion));
if (!version)
{
@ -247,7 +247,7 @@ void LegacyUpdate::lwjglFinished(QNetworkReply *reply)
saveMe.open(QIODevice::WriteOnly);
saveMe.write(m_reply->readAll());
saveMe.close();
setStatusText(tr("Installing new LWJGL..."));
setStatus(tr("Installing new LWJGL..."));
extractLwjgl();
jarStart();
}
@ -323,7 +323,7 @@ void LegacyUpdate::extractLwjgl()
// Now if destFileName is still empty, go to the next file.
if (!destFileName.isEmpty())
{
setStatusText(tr("Installing new LWJGL - extracting ") + name + "...");
setStatus(tr("Installing new LWJGL - extracting ") + name + "...");
QFile output(destFileName);
output.open(QIODevice::WriteOnly);
output.write(file.readAll());
@ -353,7 +353,7 @@ void LegacyUpdate::jarStart()
return;
}
setStatusText(tr("Checking for jar updates..."));
setStatus(tr("Checking for jar updates..."));
// Make directories
QDir binDir(inst->binRoot());
if (!binDir.exists() && !binDir.mkpath("."))
@ -363,7 +363,7 @@ void LegacyUpdate::jarStart()
}
// Build a list of URLs that will need to be downloaded.
setStatusText(tr("Downloading new minecraft.jar ..."));
setStatus(tr("Downloading new minecraft.jar ..."));
QString version_id = inst->intendedVersionId();

View File

@ -41,7 +41,7 @@ OneSixUpdate::OneSixUpdate(OneSixInstance *inst, QObject *parent) : Task(parent)
{
// create folders
{
m_tasks.append(new FoldersTask(m_inst));
m_tasks.append(std::make_shared<FoldersTask>(m_inst));
}
// add metadata update tasks, if necessary
@ -66,7 +66,7 @@ OneSixUpdate::OneSixUpdate(OneSixInstance *inst, QObject *parent) : Task(parent)
if(task)
{
qDebug() << "Loading remote meta patch" << id;
m_tasks.append(task);
m_tasks.append(task.unwrap());
}
}
else
@ -78,17 +78,17 @@ OneSixUpdate::OneSixUpdate(OneSixInstance *inst, QObject *parent) : Task(parent)
// libraries download
{
m_tasks.append(new LibrariesTask(m_inst));
m_tasks.append(std::make_shared<LibrariesTask>(m_inst));
}
// FML libraries download and copy into the instance
{
m_tasks.append(new FMLLibrariesTask(m_inst));
m_tasks.append(std::make_shared<FMLLibrariesTask>(m_inst));
}
// assets update
{
m_tasks.append(new AssetUpdateTask(m_inst));
m_tasks.append(std::make_shared<AssetUpdateTask>(m_inst));
}
}
@ -116,7 +116,7 @@ void OneSixUpdate::next()
disconnect(task.get(), &Task::succeeded, this, &OneSixUpdate::subtaskSucceeded);
disconnect(task.get(), &Task::failed, this, &OneSixUpdate::subtaskFailed);
disconnect(task.get(), &Task::progress, this, &OneSixUpdate::progress);
disconnect(task.get(), &Task::status, this, &OneSixUpdate::setStatusText);
disconnect(task.get(), &Task::status, this, &OneSixUpdate::setStatus);
}
if(m_currentTask == m_tasks.size())
{
@ -132,7 +132,7 @@ void OneSixUpdate::next()
connect(task.get(), &Task::succeeded, this, &OneSixUpdate::subtaskSucceeded);
connect(task.get(), &Task::failed, this, &OneSixUpdate::subtaskFailed);
connect(task.get(), &Task::progress, this, &OneSixUpdate::progress);
connect(task.get(), &Task::status, this, &OneSixUpdate::setStatusText);
connect(task.get(), &Task::status, this, &OneSixUpdate::setStatus);
// if the task is already running, do not start it again
if(!task->isRunning())
{

View File

@ -46,7 +46,7 @@ private:
private:
OneSixInstance *m_inst = nullptr;
QList<shared_qobject_ptr<Task>> m_tasks;
QList<std::shared_ptr<Task>> m_tasks;
QString m_preFailure;
int m_currentTask = -1;
bool m_abort = false;

View File

@ -10,7 +10,7 @@ AssetUpdateTask::AssetUpdateTask(OneSixInstance * inst)
}
void AssetUpdateTask::executeTask()
{
setStatusText(tr("Updating assets index..."));
setStatus(tr("Updating assets index..."));
auto profile = m_inst->getMinecraftProfile();
auto assets = profile->getMinecraftAssets();
QUrl indexUrl = assets->url;
@ -63,7 +63,7 @@ void AssetUpdateTask::assetIndexFinished()
auto job = index.getDownloadJob();
if(job)
{
setStatusText(tr("Getting the assets files from Mojang..."));
setStatus(tr("Getting the assets files from Mojang..."));
downloadJob = job;
connect(downloadJob.get(), &NetJob::succeeded, this, &AssetUpdateTask::emitSucceeded);
connect(downloadJob.get(), &NetJob::failed, this, &AssetUpdateTask::assetsFailed);

View File

@ -32,7 +32,7 @@ void FMLLibrariesTask::executeTask()
auto &libList = fmlLibsMapping[version];
// determine if we need some libs for FML or forge
setStatusText(tr("Checking for FML libraries..."));
setStatus(tr("Checking for FML libraries..."));
forge_present = (profile->versionPatch("net.minecraftforge") != nullptr);
// we don't...
if (!forge_present)
@ -58,7 +58,7 @@ void FMLLibrariesTask::executeTask()
}
// download missing libs to our place
setStatusText(tr("Dowloading FML libraries..."));
setStatus(tr("Dowloading FML libraries..."));
auto dljob = new NetJob("FML libraries");
auto metacache = ENV.metacache();
for (auto &lib : fmlLibsToProcess)
@ -86,7 +86,7 @@ void FMLLibrariesTask::fmllibsFinished()
downloadJob.reset();
if (!fmlLibsToProcess.isEmpty())
{
setStatusText(tr("Copying FML libraries into the instance..."));
setStatus(tr("Copying FML libraries into the instance..."));
OneSixInstance *inst = (OneSixInstance *)m_inst;
auto metacache = ENV.metacache();
int index = 0;

View File

@ -9,7 +9,7 @@ LibrariesTask::LibrariesTask(OneSixInstance * inst)
void LibrariesTask::executeTask()
{
setStatusText(tr("Getting the library files from Mojang..."));
setStatus(tr("Getting the library files from Mojang..."));
qDebug() << m_inst->name() << ": downloading libraries";
OneSixInstance *inst = (OneSixInstance *)m_inst;
inst->reloadProfile();

View File

@ -21,34 +21,34 @@ public:
}
public:
Task::Status init(QNetworkRequest & request) override
JobStatus init(QNetworkRequest & request) override
{
m_output->clear();
if(initAllValidators(request))
return Task::Status::InProgress;
return Task::Status::Failed;
return Job_InProgress;
return Job_Failed;
};
Task::Status write(QByteArray & data) override
JobStatus write(QByteArray & data) override
{
m_output->append(data);
if(writeAllValidators(data))
return Task::Status::InProgress;
return Task::Status::Failed;
return Job_InProgress;
return Job_Failed;
}
Task::Status abort() override
JobStatus abort() override
{
m_output->clear();
failAllValidators();
return Task::Status::Failed;
return Job_Failed;
}
Task::Status finalize(QNetworkReply &reply) override
JobStatus finalize(QNetworkReply &reply) override
{
if(finalizeAllValidators(reply))
return Task::Status::Finished;
return Task::Status::Failed;
return Job_Finished;
return Job_Failed;
}
bool hasLocalData() override

View File

@ -28,7 +28,7 @@ namespace Net {
Download::Download():NetAction()
{
m_status = Status::NotStarted;
m_status = Job_NotStarted;
}
Download::Ptr Download::makeCached(QUrl url, MetaEntryPtr entry, Options options)
@ -40,7 +40,7 @@ Download::Ptr Download::makeCached(QUrl url, MetaEntryPtr entry, Options options
auto cachedNode = new MetaCacheSink(entry, md5Node);
dl->m_sink.reset(cachedNode);
dl->m_target_path = entry->getFullPath();
return dl;
return std::shared_ptr<Download>(dl);
}
Download::Ptr Download::makeByteArray(QUrl url, QByteArray *output, Options options)
@ -49,7 +49,7 @@ Download::Ptr Download::makeByteArray(QUrl url, QByteArray *output, Options opti
dl->m_url = url;
dl->m_options = options;
dl->m_sink.reset(new ByteArraySink(output));
return dl;
return std::shared_ptr<Download>(dl);
}
Download::Ptr Download::makeFile(QUrl url, QString path, Options options)
@ -58,7 +58,7 @@ Download::Ptr Download::makeFile(QUrl url, QString path, Options options)
dl->m_url = url;
dl->m_options = options;
dl->m_sink.reset(new FileSink(path));
return dl;
return std::shared_ptr<Download>(dl);
}
void Download::addValidator(Validator * v)
@ -66,30 +66,30 @@ void Download::addValidator(Validator * v)
m_sink->addValidator(v);
}
void Download::executeTask()
void Download::start()
{
if(m_status == Status::Aborted)
if(m_status == Job_Aborted)
{
qWarning() << "Attempt to start an aborted Download:" << m_url.toString();
emit aborted();
emit aborted(m_index_within_job);
return;
}
QNetworkRequest request(m_url);
m_status = m_sink->init(request);
switch(m_status)
{
case Status::Finished:
emit succeeded();
case Job_Finished:
emit succeeded(m_index_within_job);
qDebug() << "Download cache hit " << m_url.toString();
return;
case Status::InProgress:
case Job_InProgress:
qDebug() << "Downloading " << m_url.toString();
break;
case Status::NotStarted:
case Status::Failed:
emit failed();
case Job_NotStarted:
case Job_Failed:
emit failed(m_index_within_job);
return;
case Status::Aborted:
case Job_Aborted:
return;
}
@ -106,20 +106,9 @@ void Download::executeTask()
void Download::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
{
// FIXME: ignore unknown size. for now.
if(bytesTotal == -1)
{
return;
}
// FIXME: ignore redirects... for now.
auto redirectURL = getRedirect();
if(!redirectURL.isEmpty())
{
return;
}
m_progressTotal = bytesTotal;
m_total_progress = bytesTotal;
m_progress = bytesReceived;
emit progress(bytesReceived, bytesTotal);
emit netActionProgress(m_index_within_job, bytesReceived, bytesTotal);
}
void Download::downloadError(QNetworkReply::NetworkError error)
@ -127,7 +116,7 @@ void Download::downloadError(QNetworkReply::NetworkError error)
if(error == QNetworkReply::OperationCanceledError)
{
qCritical() << "Aborted " << m_url.toString();
m_status = Status::Aborted;
m_status = Job_Aborted;
}
else
{
@ -135,17 +124,17 @@ void Download::downloadError(QNetworkReply::NetworkError error)
{
if(m_sink->hasLocalData())
{
m_status = Status::Failed_Proceed;
m_status = Job_Failed_Proceed;
return;
}
}
// error happened during download.
qCritical() << "Failed " << m_url.toString() << " with reason " << error;
m_status = Status::Failed;
m_status = Job_Failed;
}
}
QString Download::getRedirect()
bool Download::handleRedirect()
{
QVariant redirect = m_reply->header(QNetworkRequest::LocationHeader);
QString redirectURL;
@ -162,15 +151,10 @@ QString Download::getRedirect()
redirectURL = m_reply->url().scheme() + ":" + data;
}
}
return redirectURL;
}
bool Download::handleRedirect()
{
auto redirectURL = getRedirect();
if (!redirectURL.isEmpty())
{
m_url = QUrl(redirectURL);
m_url = QUrl(redirect.toString());
qDebug() << "Following redirect to " << m_url.toString();
start();
return true;
}
@ -188,28 +172,28 @@ void Download::downloadFinished()
}
// if the download failed before this point ...
if (m_status == Status::Failed_Proceed)
if (m_status == Job_Failed_Proceed)
{
qDebug() << "Download failed but we are allowed to proceed:" << m_url.toString();
m_sink->abort();
m_reply.reset();
emit succeeded();
emit succeeded(m_index_within_job);
return;
}
else if (m_status == Status::Failed)
else if (m_status == Job_Failed)
{
qDebug() << "Download failed in previous step:" << m_url.toString();
m_sink->abort();
m_reply.reset();
emit failed();
emit failed(m_index_within_job);
return;
}
else if(m_status == Status::Aborted)
else if(m_status == Job_Aborted)
{
qDebug() << "Download aborted in previous step:" << m_url.toString();
m_sink->abort();
m_reply.reset();
emit aborted();
emit aborted(m_index_within_job);
return;
}
@ -223,26 +207,26 @@ void Download::downloadFinished()
// otherwise, finalize the whole graph
m_status = m_sink->finalize(*m_reply.get());
if (m_status != Status::Finished)
if (m_status != Job_Finished)
{
qDebug() << "Download failed to finalize:" << m_url.toString();
m_sink->abort();
m_reply.reset();
emit failed();
emit failed(m_index_within_job);
return;
}
m_reply.reset();
qDebug() << "Download succeeded:" << m_url.toString();
emit succeeded();
emit succeeded(m_index_within_job);
}
void Download::downloadReadyRead()
{
if(m_status == Status::InProgress)
if(m_status == Job_InProgress)
{
auto data = m_reply->readAll();
m_status = m_sink->write(data);
if(m_status == Status::Failed)
if(m_status == Job_Failed)
{
qCritical() << "Failed to process response chunk for " << m_target_path;
}
@ -250,7 +234,7 @@ void Download::downloadReadyRead()
}
else
{
qCritical() << "Cannot write to " << m_target_path << ", illegal status" << int(m_status);
qCritical() << "Cannot write to " << m_target_path << ", illegal status" << m_status;
}
}
@ -264,12 +248,12 @@ bool Net::Download::abort()
}
else
{
m_status = Status::Aborted;
m_status = Job_Aborted;
}
return true;
}
bool Net::Download::canAbort() const
bool Net::Download::canAbort()
{
return true;
}

View File

@ -27,7 +27,7 @@ class MULTIMC_LOGIC_EXPORT Download : public NetAction
Q_OBJECT
public: /* types */
typedef shared_qobject_ptr<class Download> Ptr;
typedef std::shared_ptr<class Download> Ptr;
enum class Option
{
NoOptions = 0,
@ -50,10 +50,9 @@ public: /* methods */
}
void addValidator(Validator * v);
bool abort() override;
bool canAbort() const override;
bool canAbort() override;
private: /* methods */
QString getRedirect();
bool handleRedirect();
protected slots:
@ -63,7 +62,7 @@ protected slots:
void downloadReadyRead() override;
public slots:
void executeTask() override;
void start() override;
private: /* data */
// FIXME: remove this, it has no business being here.

View File

@ -17,10 +17,10 @@ FileSink::~FileSink()
// nil
};
Task::Status FileSink::init(QNetworkRequest& request)
JobStatus FileSink::init(QNetworkRequest& request)
{
auto result = initCache(request);
if(result != Task::Status::InProgress)
if(result != Job_InProgress)
{
return result;
}
@ -28,27 +28,27 @@ Task::Status FileSink::init(QNetworkRequest& request)
if (!FS::ensureFilePathExists(m_filename))
{
qCritical() << "Could not create folder for " + m_filename;
return Task::Status::Failed;
return Job_Failed;
}
wroteAnyData = false;
m_output_file.reset(new QSaveFile(m_filename));
if (!m_output_file->open(QIODevice::WriteOnly))
{
qCritical() << "Could not open " + m_filename + " for writing";
return Task::Status::Failed;
return Job_Failed;
}
if(initAllValidators(request))
return Task::Status::InProgress;
return Task::Status::Failed;
return Job_InProgress;
return Job_Failed;
}
Task::Status FileSink::initCache(QNetworkRequest &)
JobStatus FileSink::initCache(QNetworkRequest &)
{
return Task::Status::InProgress;
return Job_InProgress;
}
Task::Status FileSink::write(QByteArray& data)
JobStatus FileSink::write(QByteArray& data)
{
if (!writeAllValidators(data) || m_output_file->write(data) != data.size())
{
@ -56,20 +56,20 @@ Task::Status FileSink::write(QByteArray& data)
m_output_file->cancelWriting();
m_output_file.reset();
wroteAnyData = false;
return Task::Status::Failed;
return Job_Failed;
}
wroteAnyData = true;
return Task::Status::InProgress;
return Job_InProgress;
}
Task::Status FileSink::abort()
JobStatus FileSink::abort()
{
m_output_file->cancelWriting();
failAllValidators();
return Task::Status::Failed;
return Job_Failed;
}
Task::Status FileSink::finalize(QNetworkReply& reply)
JobStatus FileSink::finalize(QNetworkReply& reply)
{
// if we wrote any data to the save file, we try to commit the data to the real file.
if (wroteAnyData)
@ -77,13 +77,13 @@ Task::Status FileSink::finalize(QNetworkReply& reply)
// ask validators for data consistency
// we only do this for actual downloads, not 'your data is still the same' cache hits
if(!finalizeAllValidators(reply))
return Task::Status::Failed;
return Job_Failed;
// nothing went wrong...
if (!m_output_file->commit())
{
qCritical() << "Failed to commit changes to " << m_filename;
m_output_file->cancelWriting();
return Task::Status::Failed;
return Job_Failed;
}
}
// then get rid of the save file
@ -92,9 +92,9 @@ Task::Status FileSink::finalize(QNetworkReply& reply)
return finalizeCache(reply);
}
Task::Status FileSink::finalizeCache(QNetworkReply &)
JobStatus FileSink::finalizeCache(QNetworkReply &)
{
return Task::Status::Finished;
return Job_Finished;
}
bool FileSink::hasLocalData()

View File

@ -10,15 +10,15 @@ public: /* con/des */
virtual ~FileSink();
public: /* methods */
Task::Status init(QNetworkRequest & request) override;
Task::Status write(QByteArray & data) override;
Task::Status abort() override;
Task::Status finalize(QNetworkReply & reply) override;
JobStatus init(QNetworkRequest & request) override;
JobStatus write(QByteArray & data) override;
JobStatus abort() override;
JobStatus finalize(QNetworkReply & reply) override;
bool hasLocalData() override;
protected: /* methods */
virtual Task::Status initCache(QNetworkRequest &);
virtual Task::Status finalizeCache(QNetworkReply &reply);
virtual JobStatus initCache(QNetworkRequest &);
virtual JobStatus finalizeCache(QNetworkReply &reply);
protected: /* data */
QString m_filename;

View File

@ -17,11 +17,11 @@ MetaCacheSink::~MetaCacheSink()
// nil
};
Task::Status MetaCacheSink::initCache(QNetworkRequest& request)
JobStatus MetaCacheSink::initCache(QNetworkRequest& request)
{
if (!m_entry->isStale())
{
return Task::Status::Finished;
return Job_Finished;
}
// check if file exists, if it does, use its information for the request
QFile current(m_filename);
@ -36,10 +36,10 @@ Task::Status MetaCacheSink::initCache(QNetworkRequest& request)
request.setRawHeader(QString("If-None-Match").toLatin1(), m_entry->getETag().toLatin1());
}
}
return Task::Status::InProgress;
return Job_InProgress;
}
Task::Status MetaCacheSink::finalizeCache(QNetworkReply & reply)
JobStatus MetaCacheSink::finalizeCache(QNetworkReply & reply)
{
QFileInfo output_file_info(m_filename);
if(wroteAnyData)
@ -54,7 +54,7 @@ Task::Status MetaCacheSink::finalizeCache(QNetworkReply & reply)
m_entry->setLocalChangedTimestamp(output_file_info.lastModified().toUTC().toMSecsSinceEpoch());
m_entry->setStale(false);
ENV.metacache()->updateEntry(m_entry);
return Task::Status::Finished;
return Job_Finished;
}
bool MetaCacheSink::hasLocalData()

View File

@ -12,8 +12,8 @@ public: /* con/des */
bool hasLocalData() override;
protected: /* methods */
Task::Status initCache(QNetworkRequest & request) override;
Task::Status finalizeCache(QNetworkReply & reply) override;
JobStatus initCache(QNetworkRequest & request) override;
JobStatus finalizeCache(QNetworkReply & reply) override;
private: /* data */
MetaEntryPtr m_entry;

View File

@ -15,8 +15,6 @@
#pragma once
#include "tasks/Task.h"
#include <QObject>
#include <QUrl>
#include <memory>
@ -25,29 +23,82 @@
#include "multimc_logic_export.h"
typedef shared_qobject_ptr<class NetAction> NetActionPtr;
class MULTIMC_LOGIC_EXPORT NetAction : public Task
enum JobStatus
{
Job_NotStarted,
Job_InProgress,
Job_Finished,
Job_Failed,
Job_Aborted,
Job_Failed_Proceed
};
typedef std::shared_ptr<class NetAction> NetActionPtr;
class MULTIMC_LOGIC_EXPORT NetAction : public QObject
{
Q_OBJECT
protected:
explicit NetAction(QObject *parent = 0) : Task(parent) {};
explicit NetAction() : QObject(0) {};
public:
virtual ~NetAction() {};
public:
virtual qint64 totalProgress() const
{
return m_total_progress;
}
virtual qint64 currentProgress() const
{
return m_progress;
}
virtual qint64 numberOfFailures() const
{
return m_failures;
}
virtual bool abort()
{
return false;
}
virtual bool canAbort()
{
return false;
}
public:
/// the network reply
unique_qobject_ptr<QNetworkReply> m_reply;
/// source URL
QUrl m_url;
// FIXME: pull this up into Task
Status m_status = Status::NotStarted;
/// The file's status
JobStatus m_status = Job_NotStarted;
/// index within the parent job
int m_index_within_job = 0;
qint64 m_progress = 0;
qint64 m_total_progress = 1;
/// number of failures up to this point
int m_failures = 0;
signals:
void failed();
void aborted();
void started(int index);
void netActionProgress(int index, qint64 current, qint64 total);
void succeeded(int index);
void failed(int index);
void aborted(int index);
protected slots:
protected
slots:
virtual void downloadProgress(qint64 bytesReceived, qint64 bytesTotal) = 0;
virtual void downloadError(QNetworkReply::NetworkError error) = 0;
virtual void downloadFinished() = 0;
virtual void downloadReadyRead() = 0;
public
slots:
virtual void start() = 0;
};

View File

@ -18,24 +18,22 @@
#include <QDebug>
void NetJob::partSucceeded()
void NetJob::partSucceeded(int index)
{
auto index = m_partsIndex[(NetAction *)QObject::sender()];
// do progress. all slots are 1 in size at least
auto &slot = m_parts[index];
setPartProgress(index, slot.total_progress, slot.total_progress);
auto &slot = parts_progress[index];
partProgress(index, slot.total_progress, slot.total_progress);
m_doing.remove(index);
m_done.insert(index);
slot.download->disconnect(this);
downloads[index].get()->disconnect(this);
startMoreParts();
}
void NetJob::partFailed()
void NetJob::partFailed(int index)
{
auto index = m_partsIndex[(NetAction *)QObject::sender()];
m_doing.remove(index);
auto &slot = m_parts[index];
auto &slot = parts_progress[index];
if (slot.failures == 3)
{
m_failed.insert(index);
@ -45,47 +43,38 @@ void NetJob::partFailed()
slot.failures++;
m_todo.enqueue(index);
}
slot.download->disconnect(this);
downloads[index].get()->disconnect(this);
startMoreParts();
}
void NetJob::partAborted()
void NetJob::partAborted(int index)
{
auto index = m_partsIndex[(NetAction *)QObject::sender()];
m_aborted = true;
m_doing.remove(index);
auto &slot = m_parts[index];
m_failed.insert(index);
slot.download->disconnect(this);
downloads[index].get()->disconnect(this);
startMoreParts();
}
void NetJob::partProgress(qint64 bytesReceived, qint64 bytesTotal)
void NetJob::partProgress(int index, qint64 bytesReceived, qint64 bytesTotal)
{
auto index = m_partsIndex[(NetAction *)QObject::sender()];
setPartProgress(index, bytesReceived, bytesTotal);
}
auto &slot = parts_progress[index];
void NetJob::setPartProgress(int index, qint64 bytesReceived, qint64 bytesTotal)
{
auto &slot = m_parts[index];
current_progress -= slot.current_progress;
slot.current_progress = bytesReceived;
current_progress += slot.current_progress;
total_progress -= slot.total_progress;
slot.total_progress = bytesTotal;
qint64 current_progress = m_done.count() * 100;
qint64 total_progress = m_parts.count() * 100;
for(auto iter = m_doing.begin(); iter != m_doing.end(); iter++)
{
auto &part = m_parts[*iter];
float percentage = (float(part.current_progress) / float(part.total_progress)) * 100.0f;
current_progress += (qint64) percentage;
}
total_progress += slot.total_progress;
setProgress(current_progress, total_progress);
}
void NetJob::executeTask()
{
qDebug() << m_job_name.toLocal8Bit() << " started.";
for (int i = 0; i < m_parts.size(); i++)
m_running = true;
for (int i = 0; i < downloads.size(); i++)
{
m_todo.enqueue(i);
}
@ -125,28 +114,24 @@ void NetJob::startMoreParts()
return;
int doThis = m_todo.dequeue();
m_doing.insert(doThis);
auto part = m_parts[doThis].download;
auto part = downloads[doThis];
// connect signals :D
connectAction(part.get());
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();
}
}
void NetJob::connectAction(NetAction* action)
{
connect(action, &NetAction::succeeded, this, &NetJob::partSucceeded);
connect(action, &NetAction::failed, this, &NetJob::partFailed);
connect(action, &NetAction::aborted, this, &NetJob::partAborted);
connect(action, &NetAction::progress, this, &NetJob::partProgress);
}
QStringList NetJob::getFailedFiles()
{
QStringList failed;
for (auto index: m_failed)
{
failed.push_back(m_parts[index].download->m_url.toString());
failed.push_back(downloads[index]->m_url.toString());
}
failed.sort();
return failed;
@ -158,13 +143,13 @@ bool NetJob::canAbort() const
// can abort the waiting?
for(auto index: m_todo)
{
auto part = m_parts[index].download;
auto part = downloads[index];
canFullyAbort &= part->canAbort();
}
// can abort the active?
for(auto index: m_doing)
{
auto part = m_parts[index].download;
auto part = downloads[index];
canFullyAbort &= part->canAbort();
}
return canFullyAbort;
@ -180,26 +165,8 @@ bool NetJob::abort()
auto toKill = m_doing.toList();
for(auto index: toKill)
{
auto part = m_parts[index].download;
auto part = downloads[index];
fullyAborted &= part->abort();
}
return fullyAborted;
}
void NetJob::addNetAction(NetActionPtr action)
{
m_partsIndex[action.get()] = m_parts.count();
part_info pi;
{
pi.current_progress = action->getProgress();
pi.total_progress = action->getTotalProgress();
pi.failures = 0;
pi.download = action;
}
m_parts.append(pi);
if (isRunning())
{
m_todo.enqueue(m_parts.size() - 1);
}
}

View File

@ -32,12 +32,52 @@ class MULTIMC_LOGIC_EXPORT NetJob : public Task
public:
explicit NetJob(QString job_name) : Task(), m_job_name(job_name) {}
virtual ~NetJob() {}
bool addNetAction(NetActionPtr action)
{
action->m_index_within_job = downloads.size();
downloads.append(action);
part_info pi;
{
pi.current_progress = action->currentProgress();
pi.total_progress = action->totalProgress();
pi.failures = action->numberOfFailures();
}
parts_progress.append(pi);
total_progress += pi.total_progress;
// if this is already running, the action needs to be started right away!
if (isRunning())
{
setProgress(current_progress, total_progress);
connect(action.get(), SIGNAL(succeeded(int)), SLOT(partSucceeded(int)));
connect(action.get(), SIGNAL(failed(int)), SLOT(partFailed(int)));
connect(action.get(), SIGNAL(netActionProgress(int, qint64, qint64)),
SLOT(partProgress(int, qint64, qint64)));
action->start();
}
return true;
}
void addNetAction(NetActionPtr action);
NetActionPtr operator[](int index)
{
return downloads[index];
}
const NetActionPtr at(const int index)
{
return downloads.at(index);
}
NetActionPtr first()
{
if (downloads.size())
return downloads[0];
return NetActionPtr();
}
int size() const
{
return m_parts.size();
return downloads.size();
}
virtual bool isRunning() const override
{
return m_running;
}
QStringList getFailedFiles();
@ -51,32 +91,28 @@ public slots:
virtual bool abort() override;
private slots:
void partProgress(qint64 bytesReceived, qint64 bytesTotal);
void partSucceeded();
void partFailed();
void partAborted();
private:
void setPartProgress(int index, qint64 bytesReceived, qint64 bytesTotal);
void connectAction(NetAction * action);
void partProgress(int index, qint64 bytesReceived, qint64 bytesTotal);
void partSucceeded(int index);
void partFailed(int index);
void partAborted(int index);
private:
struct part_info
{
NetActionPtr download;
qint64 current_progress = 0;
qint64 total_progress = 1;
int failures = 0;
bool connected = false;
};
QString m_job_name;
QVector<part_info> m_parts;
QMap<NetAction *, int> m_partsIndex;
QList<NetActionPtr> downloads;
QList<part_info> parts_progress;
QQueue<int> m_todo;
QSet<int> m_doing;
QSet<int> m_done;
QSet<int> m_failed;
//qint64 current_progress = 0;
//qint64 total_progress = 0;
qint64 current_progress = 0;
qint64 total_progress = 0;
bool m_running = false;
bool m_aborted = false;
};

View File

@ -39,7 +39,7 @@ void PasteUpload::executeTask()
QNetworkReply *rep = ENV.qnam().post(request, buf);
m_reply = std::shared_ptr<QNetworkReply>(rep);
setStatusText(tr("Uploading to paste.ee"));
setStatus(tr("Uploading to paste.ee"));
connect(rep, &QNetworkReply::uploadProgress, this, &Task::setProgress);
connect(rep, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(downloadError(QNetworkReply::NetworkError)));
connect(rep, SIGNAL(finished()), this, SLOT(downloadFinished()));

View File

@ -13,10 +13,10 @@ public: /* con/des */
virtual ~Sink() {};
public: /* methods */
virtual Task::Status init(QNetworkRequest & request) = 0;
virtual Task::Status write(QByteArray & data) = 0;
virtual Task::Status abort() = 0;
virtual Task::Status finalize(QNetworkReply & reply) = 0;
virtual JobStatus init(QNetworkRequest & request) = 0;
virtual JobStatus write(QByteArray & data) = 0;
virtual JobStatus abort() = 0;
virtual JobStatus finalize(QNetworkReply & reply) = 0;
virtual bool hasLocalData() = 0;
void addValidator(Validator * validator)

View File

@ -60,7 +60,7 @@ void NotificationChecker::checkForNotifications()
m_checkJob->start();
}
void NotificationChecker::downloadSucceeded()
void NotificationChecker::downloadSucceeded(int)
{
m_entries.clear();

View File

@ -43,7 +43,7 @@ slots:
private
slots:
void downloadSucceeded();
void downloadSucceeded(int);
signals:
void notificationCheckFinished();

View File

@ -13,12 +13,12 @@
ImgurAlbumCreation::ImgurAlbumCreation(QList<ScreenshotPtr> screenshots) : NetAction(), m_screenshots(screenshots)
{
m_url = URLConstants::IMGUR_BASE_URL + "album.json";
m_status = Status::NotStarted;
m_status = Job_NotStarted;
}
void ImgurAlbumCreation::executeTask()
void ImgurAlbumCreation::start()
{
m_status = Status::InProgress;
m_status = Job_InProgress;
QNetworkRequest request(m_url);
request.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Uncached)");
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
@ -43,11 +43,11 @@ void ImgurAlbumCreation::executeTask()
void ImgurAlbumCreation::downloadError(QNetworkReply::NetworkError error)
{
qDebug() << m_reply->errorString();
m_status = Status::Failed;
m_status = Job_Failed;
}
void ImgurAlbumCreation::downloadFinished()
{
if (m_status != Status::Failed)
if (m_status != Job_Failed)
{
QByteArray data = m_reply->readAll();
m_reply.reset();
@ -56,33 +56,33 @@ void ImgurAlbumCreation::downloadFinished()
if (jsonError.error != QJsonParseError::NoError)
{
qDebug() << jsonError.errorString();
emit failed();
emit failed(m_index_within_job);
return;
}
auto object = doc.object();
if (!object.value("success").toBool())
{
qDebug() << doc.toJson();
emit failed();
emit failed(m_index_within_job);
return;
}
m_deleteHash = object.value("data").toObject().value("deletehash").toString();
m_id = object.value("data").toObject().value("id").toString();
m_status = Status::Finished;
emit succeeded();
m_status = Job_Finished;
emit succeeded(m_index_within_job);
return;
}
else
{
qDebug() << m_reply->readAll();
m_reply.reset();
emit failed();
emit failed(m_index_within_job);
return;
}
}
void ImgurAlbumCreation::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
{
m_progressTotal = bytesTotal;
m_total_progress = bytesTotal;
m_progress = bytesReceived;
emit progress(bytesReceived, bytesTotal);
emit netActionProgress(m_index_within_job, bytesReceived, bytesTotal);
}

View File

@ -4,7 +4,7 @@
#include "multimc_logic_export.h"
typedef shared_qobject_ptr<class ImgurAlbumCreation> ImgurAlbumCreationPtr;
typedef std::shared_ptr<class ImgurAlbumCreation> ImgurAlbumCreationPtr;
class MULTIMC_LOGIC_EXPORT ImgurAlbumCreation : public NetAction
{
public:
@ -34,7 +34,7 @@ slots:
public
slots:
virtual void executeTask();
virtual void start();
private:
QList<ScreenshotPtr> m_screenshots;

View File

@ -15,13 +15,13 @@
ImgurUpload::ImgurUpload(ScreenshotPtr shot) : NetAction(), m_shot(shot)
{
m_url = URLConstants::IMGUR_BASE_URL + "upload.json";
m_status = Status::NotStarted;
m_status = Job_NotStarted;
}
void ImgurUpload::executeTask()
void ImgurUpload::start()
{
finished = false;
m_status = Status::InProgress;
m_status = Job_InProgress;
QNetworkRequest request(m_url);
request.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Uncached)");
request.setRawHeader("Authorization", "Client-ID 5b97b0713fba4a3");
@ -30,7 +30,7 @@ void ImgurUpload::executeTask()
QFile f(m_shot->m_file.absoluteFilePath());
if (!f.open(QFile::ReadOnly))
{
emit failed();
emit failed(m_index_within_job);
return;
}
@ -65,10 +65,10 @@ void ImgurUpload::downloadError(QNetworkReply::NetworkError error)
qCritical() << "Double finished ImgurUpload!";
return;
}
m_status = Status::Failed;
m_status = Job_Failed;
finished = true;
m_reply.reset();
emit failed();
emit failed(m_index_within_job);
}
void ImgurUpload::downloadFinished()
{
@ -86,7 +86,7 @@ void ImgurUpload::downloadFinished()
qDebug() << "imgur server did not reply with JSON" << jsonError.errorString();
finished = true;
m_reply.reset();
emit failed();
emit failed(m_index_within_job);
return;
}
auto object = doc.object();
@ -95,19 +95,19 @@ void ImgurUpload::downloadFinished()
qDebug() << "Screenshot upload not successful:" << doc.toJson();
finished = true;
m_reply.reset();
emit failed();
emit failed(m_index_within_job);
return;
}
m_shot->m_imgurId = object.value("data").toObject().value("id").toString();
m_shot->m_url = object.value("data").toObject().value("link").toString();
m_status = Status::Finished;
m_status = Job_Finished;
finished = true;
emit succeeded();
emit succeeded(m_index_within_job);
return;
}
void ImgurUpload::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
{
m_progressTotal = bytesTotal;
m_total_progress = bytesTotal;
m_progress = bytesReceived;
emit progress(bytesReceived, bytesTotal);
emit netActionProgress(m_index_within_job, bytesReceived, bytesTotal);
}

View File

@ -1,11 +1,10 @@
#pragma once
#include "net/NetAction.h"
#include "Screenshot.h"
#include "QObjectPtr.h"
#include "multimc_logic_export.h"
typedef shared_qobject_ptr<class ImgurUpload> ImgurUploadPtr;
typedef std::shared_ptr<class ImgurUpload> ImgurUploadPtr;
class MULTIMC_LOGIC_EXPORT ImgurUpload : public NetAction
{
public:
@ -26,7 +25,7 @@ slots:
public
slots:
virtual void executeTask();
virtual void start();
private:
ScreenshotPtr m_shot;

View File

@ -42,7 +42,7 @@ void SequentialTask::subTaskFailed(const QString &msg)
}
void SequentialTask::subTaskStatus(const QString &msg)
{
setStatusText(msg);
setStatus(msg);
}
void SequentialTask::subTaskProgress(qint64 current, qint64 total)
{

View File

@ -21,12 +21,12 @@ Task::Task(QObject *parent) : QObject(parent)
{
}
void Task::setStatusText(const QString &new_status)
void Task::setStatus(const QString &new_status)
{
if(m_statusText != new_status)
if(m_status != new_status)
{
m_statusText = new_status;
emit status(m_statusText);
m_status = new_status;
emit status(m_status);
}
}

View File

@ -23,16 +23,6 @@
class MULTIMC_LOGIC_EXPORT Task : public QObject
{
Q_OBJECT
public:
enum class Status
{
NotStarted,
InProgress,
Finished,
Failed,
Aborted,
Failed_Proceed
};
public:
explicit Task(QObject *parent = 0);
virtual ~Task() {};
@ -53,22 +43,19 @@ public:
*/
virtual QString failReason() const;
virtual bool canAbort() const
virtual bool canAbort() const { return false; }
QString getStatus()
{
return false;
return m_status;
}
QString getStatusText()
{
return m_statusText;
}
virtual qint64 getProgress()
qint64 getProgress()
{
return m_progress;
}
virtual qint64 getTotalProgress()
qint64 getTotalProgress()
{
return m_progressTotal;
}
@ -81,12 +68,10 @@ signals:
void failed(QString reason);
void status(QString status);
public slots:
public
slots:
virtual void start();
virtual bool abort()
{
return false;
};
virtual bool abort() { return false; };
protected:
virtual void executeTask() = 0;
@ -96,18 +81,16 @@ protected slots:
virtual void emitFailed(QString reason);
public slots:
void setStatusText(const QString &status);
void setStatus(const QString &status);
void setProgress(qint64 current, qint64 total);
protected:
// FIXME: replace these with the m_status from NetAction
bool m_running = false;
bool m_finished = false;
bool m_succeeded = false;
QString m_failReason = "";
QString m_statusText;
qint64 m_progress = 0;
qint64 m_progressTotal = 1;
QString m_status;
int m_progress = 0;
int m_progressTotal = 100;
};

View File

@ -32,7 +32,7 @@ void ThreadTask::iternal_started()
void ThreadTask::iternal_status(QString status)
{
setStatusText(status);
setStatus(status);
}
void ThreadTask::iternal_succeeded()

View File

@ -30,7 +30,7 @@ struct TranslationsModel::Private
std::unique_ptr<QTranslator> m_qt_translator;
std::unique_ptr<QTranslator> m_app_translator;
Net::Download::Ptr m_index_task;
std::shared_ptr<Net::Download> m_index_task;
QString m_downloadingTranslation;
NetJobPtr m_dl_job;
NetJobPtr m_index_job;

View File

@ -26,7 +26,7 @@
namespace GoUpdate
{
DownloadTask::DownloadTask(GoUpdate::Status status, QString target, QObject *parent)
DownloadTask::DownloadTask(Status status, QString target, QObject *parent)
: Task(parent), m_updateFilesDir(target)
{
m_status = status;
@ -41,7 +41,7 @@ void DownloadTask::executeTask()
void DownloadTask::loadVersionInfo()
{
setStatusText(tr("Loading version information..."));
setStatus(tr("Loading version information..."));
NetJob *netJob = new NetJob("Version Info");
@ -70,7 +70,7 @@ void DownloadTask::vinfoDownloadFailed()
{
// Something failed. We really need the second download (current version info), so parse
// downloads anyways as long as the first one succeeded.
if (m_newVersionFileListDownload->m_status != Status::Failed)
if (m_newVersionFileListDownload->m_status != Job_Failed)
{
processDownloadedVersionInfo();
return;
@ -86,7 +86,7 @@ void DownloadTask::processDownloadedVersionInfo()
VersionFileList m_currentVersionFileList;
VersionFileList m_newVersionFileList;
setStatusText(tr("Reading file list for new version..."));
setStatus(tr("Reading file list for new version..."));
qDebug() << "Reading file list for new version...";
QString error;
if (!parseVersionInfo(newVersionFileListData, m_newVersionFileList, error))
@ -97,9 +97,9 @@ void DownloadTask::processDownloadedVersionInfo()
}
// if we have the current version info, use it.
if (m_currentVersionFileListDownload && m_currentVersionFileListDownload->m_status != Status::Failed)
if (m_currentVersionFileListDownload && m_currentVersionFileListDownload->m_status != Job_Failed)
{
setStatusText(tr("Reading file list for current version..."));
setStatus(tr("Reading file list for current version..."));
qDebug() << "Reading file list for current version...";
// if this fails, it's not a complete loss.
QString error;
@ -114,7 +114,7 @@ void DownloadTask::processDownloadedVersionInfo()
m_newVersionFileListDownload.reset();
m_vinfoNetJob.reset();
setStatusText(tr("Processing file lists - figuring out how to install the update..."));
setStatus(tr("Processing file lists - figuring out how to install the update..."));
// make a new netjob for the actual update files
NetJobPtr netJob (new NetJob("Update Files"));
@ -131,7 +131,7 @@ void DownloadTask::processDownloadedVersionInfo()
QObject::connect(netJob.get(), &NetJob::progress, this, &DownloadTask::fileDownloadProgressChanged);
QObject::connect(netJob.get(), &NetJob::failed, this, &DownloadTask::fileDownloadFailed);
setStatusText(tr("Downloading %1 update files.").arg(QString::number(netJob->size())));
setStatus(tr("Downloading %1 update files.").arg(QString::number(netJob->size())));
qDebug() << "Begin downloading update files to" << m_updateFilesDir.path();
m_filesNetJob = netJob;
m_filesNetJob->start();

View File

@ -37,7 +37,7 @@ public:
*
* target is a template - XXXXXX at the end will be replaced with a random generated string, ensuring uniqueness
*/
explicit DownloadTask(GoUpdate::Status status, QString target, QObject* parent = 0);
explicit DownloadTask(Status status, QString target, QObject* parent = 0);
/// Get the directory that will contain the update files.
QString updateFilesDir();
@ -71,7 +71,7 @@ protected:
NetJobPtr m_filesNetJob;
GoUpdate::Status m_status;
Status m_status;
OperationList m_operations;

View File

@ -87,7 +87,7 @@ int ProgressDialog::execWithTask(Task *task)
if(task->isRunning())
{
changeProgress(task->getProgress(), task->getTotalProgress());
changeStatus(task->getStatusText());
changeStatus(task->getStatus());
return QDialog::exec();
}
else if(handleImmediateResult(result))