Implement legacy forge button!
Many refactors of the task system. Progress dialog now accepts generic ProgressProvider objects
This commit is contained in:
@ -7,7 +7,5 @@ BaseUpdate::BaseUpdate ( BaseInstance* inst, QObject* parent ) : Task ( parent )
|
||||
|
||||
void BaseUpdate::updateDownloadProgress(qint64 current, qint64 total)
|
||||
{
|
||||
// The progress on the current file is current / total
|
||||
float currentDLProgress = (float) current / (float) total;
|
||||
setProgress((int)(currentDLProgress * 100)); // convert to percentage
|
||||
emit progress(current, total);
|
||||
}
|
@ -3,7 +3,7 @@
|
||||
|
||||
#include <iostream>
|
||||
#include "gui/logindialog.h"
|
||||
#include "gui/taskdialog.h"
|
||||
#include "gui/ProgressDialog.h"
|
||||
#include "gui/consolewindow.h"
|
||||
#include "logic/tasks/LoginTask.h"
|
||||
#include "logic/MinecraftProcess.h"
|
||||
@ -48,7 +48,7 @@ void InstanceLauncher::doLogin ( const QString& errorMsg )
|
||||
{
|
||||
UserInfo uInfo {loginDlg->getUsername(), loginDlg->getPassword() };
|
||||
|
||||
TaskDialog* tDialog = new TaskDialog ( nullptr );
|
||||
ProgressDialog* tDialog = new ProgressDialog ( nullptr );
|
||||
LoginTask* loginTask = new LoginTask ( uInfo, tDialog );
|
||||
connect ( loginTask, SIGNAL ( succeeded() ),SLOT ( onLoginComplete() ), Qt::QueuedConnection );
|
||||
connect ( loginTask, SIGNAL ( failed ( QString ) ),SLOT ( doLogin ( QString ) ), Qt::QueuedConnection );
|
||||
|
@ -59,7 +59,7 @@ void LegacyUpdate::lwjglStart()
|
||||
QNetworkReply * rep = worker->get ( req );
|
||||
|
||||
m_reply = QSharedPointer<QNetworkReply> (rep, &QObject::deleteLater);
|
||||
connect(rep, SIGNAL(downloadProgress(qint64,qint64)), SLOT(updateDownloadProgress(qint64,qint64)));
|
||||
connect(rep, SIGNAL(downloadProgress(qint64,qint64)), SIGNAL(progress(qint64,qint64)));
|
||||
connect(worker, SIGNAL(finished(QNetworkReply*)), SLOT(lwjglFinished(QNetworkReply*)));
|
||||
//connect(rep, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(downloadError(QNetworkReply::NetworkError)));
|
||||
}
|
||||
@ -97,7 +97,7 @@ void LegacyUpdate::lwjglFinished(QNetworkReply* reply)
|
||||
req.setRawHeader("Host", hostname.toLatin1());
|
||||
req.setHeader(QNetworkRequest::UserAgentHeader, "Wget/1.14 (linux-gnu)");
|
||||
QNetworkReply * rep = worker->get(req);
|
||||
connect(rep, SIGNAL(downloadProgress(qint64,qint64)), SLOT(updateDownloadProgress(qint64,qint64)));
|
||||
connect(rep, SIGNAL(downloadProgress(qint64,qint64)), SIGNAL(progress(qint64,qint64)));
|
||||
m_reply = QSharedPointer<QNetworkReply> (rep, &QObject::deleteLater);
|
||||
return;
|
||||
}
|
||||
@ -232,7 +232,7 @@ void LegacyUpdate::jarStart()
|
||||
legacyDownloadJob.reset(dljob);
|
||||
connect(dljob, SIGNAL(succeeded()), SLOT(jarFinished()));
|
||||
connect(dljob, SIGNAL(failed()), SLOT(jarFailed()));
|
||||
connect(dljob, SIGNAL(progress(qint64,qint64)), SLOT(updateDownloadProgress(qint64,qint64)));
|
||||
connect(dljob, SIGNAL(progress(qint64,qint64)), SIGNAL(progress(qint64,qint64)));
|
||||
legacyDownloadJob->start();
|
||||
}
|
||||
|
||||
|
@ -78,7 +78,7 @@ void OneSixUpdate::versionFileStart()
|
||||
specificVersionDownloadJob.reset(job);
|
||||
connect(specificVersionDownloadJob.data(), SIGNAL(succeeded()), SLOT(versionFileFinished()));
|
||||
connect(specificVersionDownloadJob.data(), SIGNAL(failed()), SLOT(versionFileFailed()));
|
||||
connect(specificVersionDownloadJob.data(), SIGNAL(progress(qint64,qint64)), SLOT(updateDownloadProgress(qint64,qint64)));
|
||||
connect(specificVersionDownloadJob.data(), SIGNAL(progress(qint64,qint64)), SIGNAL(progress(qint64,qint64)));
|
||||
specificVersionDownloadJob->start();
|
||||
}
|
||||
|
||||
@ -171,7 +171,7 @@ void OneSixUpdate::jarlibStart()
|
||||
}
|
||||
connect(jarlibDownloadJob.data(), SIGNAL(succeeded()), SLOT(jarlibFinished()));
|
||||
connect(jarlibDownloadJob.data(), SIGNAL(failed()), SLOT(jarlibFailed()));
|
||||
connect(jarlibDownloadJob.data(), SIGNAL(progress(qint64,qint64)), SLOT(updateDownloadProgress(qint64,qint64)));
|
||||
connect(jarlibDownloadJob.data(), SIGNAL(progress(qint64,qint64)), SIGNAL(progress(qint64,qint64)));
|
||||
|
||||
jarlibDownloadJob->start();
|
||||
}
|
||||
|
@ -50,21 +50,90 @@ int ForgeVersionList::count() const
|
||||
{
|
||||
return m_vlist.count();
|
||||
}
|
||||
/*
|
||||
bool cmpVersions(BaseVersionPtr first, BaseVersionPtr second)
|
||||
|
||||
int ForgeVersionList::columnCount(const QModelIndex& parent) const
|
||||
{
|
||||
const BaseVersion & left = *first;
|
||||
const BaseVersion & right = *second;
|
||||
return left > right;
|
||||
return 3;
|
||||
}
|
||||
|
||||
void MinecraftVersionList::sort()
|
||||
QVariant ForgeVersionList::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
beginResetModel();
|
||||
qSort(m_vlist.begin(), m_vlist.end(), cmpVersions);
|
||||
endResetModel();
|
||||
if (!index.isValid())
|
||||
return QVariant();
|
||||
|
||||
if (index.row() > count())
|
||||
return QVariant();
|
||||
|
||||
auto version = m_vlist[index.row()].dynamicCast<ForgeVersion>();
|
||||
switch (role)
|
||||
{
|
||||
case Qt::DisplayRole:
|
||||
switch (index.column())
|
||||
{
|
||||
case 0:
|
||||
return version->name();
|
||||
|
||||
case 1:
|
||||
return version->mcver;
|
||||
|
||||
case 2:
|
||||
return version->typeString();
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
case Qt::ToolTipRole:
|
||||
return version->descriptor();
|
||||
|
||||
case VersionPointerRole:
|
||||
return qVariantFromValue(m_vlist[index.row()]);
|
||||
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
QVariant ForgeVersionList::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
switch (role)
|
||||
{
|
||||
case Qt::DisplayRole:
|
||||
switch (section)
|
||||
{
|
||||
case 0:
|
||||
return "Version";
|
||||
|
||||
case 1:
|
||||
return "Minecraft";
|
||||
|
||||
case 2:
|
||||
return "Type";
|
||||
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
case Qt::ToolTipRole:
|
||||
switch (section)
|
||||
{
|
||||
case 0:
|
||||
return "The name of the version.";
|
||||
|
||||
case 1:
|
||||
return "Minecraft version";
|
||||
|
||||
case 2:
|
||||
return "The version's type.";
|
||||
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
|
||||
BaseVersionPtr ForgeVersionList::getLatestStable() const
|
||||
{
|
||||
return BaseVersionPtr();
|
||||
@ -99,7 +168,7 @@ void ForgeListLoadTask::executeTask()
|
||||
listJob.reset(job);
|
||||
connect(listJob.data(), SIGNAL(succeeded()), SLOT(list_downloaded()));
|
||||
connect(listJob.data(), SIGNAL(failed()), SLOT(versionFileFailed()));
|
||||
connect(listJob.data(), SIGNAL(progress(qint64,qint64)), SLOT(updateDownloadProgress(qint64,qint64)));
|
||||
connect(listJob.data(), SIGNAL(progress(qint64,qint64)), SIGNAL(progress(qint64,qint64)));
|
||||
listJob->start();
|
||||
}
|
||||
|
||||
@ -148,7 +217,7 @@ void ForgeListLoadTask::list_downloaded()
|
||||
int build_nr = obj.value("build").toDouble(0);
|
||||
if(!build_nr)
|
||||
continue;
|
||||
QJsonArray files = root.value("files").toArray();
|
||||
QJsonArray files = obj.value("files").toArray();
|
||||
QString url, jobbuildver, mcver, buildtype, filename;
|
||||
QString changelog_url, installer_url;
|
||||
bool valid = false;
|
||||
|
@ -26,7 +26,7 @@
|
||||
#include "logic/net/DownloadJob.h"
|
||||
|
||||
class ForgeVersion;
|
||||
typedef QSharedPointer<ForgeVersion> PtrForgeVersion;
|
||||
typedef QSharedPointer<ForgeVersion> ForgeVersionPtr;
|
||||
|
||||
struct ForgeVersion : public BaseVersion
|
||||
{
|
||||
@ -36,7 +36,7 @@ struct ForgeVersion : public BaseVersion
|
||||
};
|
||||
virtual QString name()
|
||||
{
|
||||
return "Forge " + jobbuildver + " (" + mcver + ")";
|
||||
return "Forge " + jobbuildver;
|
||||
};
|
||||
virtual QString typeString() const
|
||||
{
|
||||
@ -71,8 +71,12 @@ public:
|
||||
|
||||
virtual BaseVersionPtr getLatestStable() const;
|
||||
|
||||
virtual QVariant data(const QModelIndex& index, int role) const;
|
||||
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const;
|
||||
virtual int columnCount(const QModelIndex& parent) const;
|
||||
|
||||
protected:
|
||||
QList<BaseVersionPtr > m_vlist;
|
||||
QList<BaseVersionPtr> m_vlist;
|
||||
|
||||
bool m_loaded;
|
||||
|
||||
|
@ -49,7 +49,7 @@ protected:
|
||||
bool m_loaded;
|
||||
|
||||
protected slots:
|
||||
virtual void updateListData(QList<BaseVersionPtr > versions);
|
||||
virtual void updateListData(QList<BaseVersionPtr> versions);
|
||||
};
|
||||
|
||||
class MCVListLoadTask : public Task
|
||||
|
@ -5,6 +5,8 @@
|
||||
#include "ByteArrayDownload.h"
|
||||
#include "CacheDownload.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
ByteArrayDownloadPtr DownloadJob::add ( QUrl url )
|
||||
{
|
||||
ByteArrayDownloadPtr ptr (new ByteArrayDownload(url));
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "FileDownload.h"
|
||||
#include "CacheDownload.h"
|
||||
#include "HttpMetaCache.h"
|
||||
#include "logic/tasks/ProgressProvider.h"
|
||||
|
||||
class DownloadJob;
|
||||
typedef QSharedPointer<DownloadJob> DownloadJobPtr;
|
||||
@ -12,12 +13,12 @@ typedef QSharedPointer<DownloadJob> DownloadJobPtr;
|
||||
/**
|
||||
* A single file for the downloader/cache to process.
|
||||
*/
|
||||
class DownloadJob : public QObject
|
||||
class DownloadJob : public ProgressProvider
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit DownloadJob(QString job_name)
|
||||
:QObject(), m_job_name(job_name){};
|
||||
:ProgressProvider(), m_job_name(job_name){};
|
||||
|
||||
ByteArrayDownloadPtr add(QUrl url);
|
||||
FileDownloadPtr add(QUrl url, QString rel_target_path);
|
||||
@ -37,6 +38,19 @@ public:
|
||||
{
|
||||
return downloads.size();
|
||||
}
|
||||
virtual void getProgress(qint64& current, qint64& total)
|
||||
{
|
||||
current = current_progress;
|
||||
total = total_progress;
|
||||
};
|
||||
virtual QString getStatus() const
|
||||
{
|
||||
return m_job_name;
|
||||
};
|
||||
virtual bool isRunning() const
|
||||
{
|
||||
return m_running;
|
||||
};
|
||||
signals:
|
||||
void started();
|
||||
void progress(qint64 current, qint64 total);
|
||||
@ -56,5 +70,6 @@ private:
|
||||
qint64 total_progress = 0;
|
||||
int num_succeeded = 0;
|
||||
int num_failed = 0;
|
||||
bool m_running = false;
|
||||
};
|
||||
|
||||
|
20
logic/tasks/ProgressProvider.h
Normal file
20
logic/tasks/ProgressProvider.h
Normal file
@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
class ProgressProvider : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
protected:
|
||||
explicit ProgressProvider(QObject* parent = 0): QObject(parent){}
|
||||
signals:
|
||||
void started();
|
||||
void progress(qint64 current, qint64 total);
|
||||
void succeeded();
|
||||
void failed(QString reason);
|
||||
void status(QString status);
|
||||
public:
|
||||
virtual QString getStatus() const = 0;
|
||||
virtual void getProgress(qint64 ¤t, qint64 &total) = 0;
|
||||
virtual bool isRunning() const = 0;
|
||||
public slots:
|
||||
virtual void start() = 0;
|
||||
};
|
@ -16,70 +16,56 @@
|
||||
#include "Task.h"
|
||||
|
||||
Task::Task(QObject *parent) :
|
||||
QObject(parent)
|
||||
ProgressProvider(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QString Task::getStatus() const
|
||||
{
|
||||
return status;
|
||||
return m_status;
|
||||
}
|
||||
|
||||
void Task::setStatus(const QString &status)
|
||||
void Task::setStatus(const QString &new_status)
|
||||
{
|
||||
this->status = status;
|
||||
emitStatusChange(status);
|
||||
m_status = new_status;
|
||||
emit status(new_status);
|
||||
}
|
||||
|
||||
int Task::getProgress() const
|
||||
void Task::setProgress(int new_progress)
|
||||
{
|
||||
return progress;
|
||||
m_progress = new_progress;
|
||||
emit progress(new_progress, 100);
|
||||
}
|
||||
|
||||
void Task::setProgress(int progress)
|
||||
void Task::getProgress(qint64& current, qint64& total)
|
||||
{
|
||||
this->progress = progress;
|
||||
emitProgressChange(progress);
|
||||
current = m_progress;
|
||||
total = 100;
|
||||
}
|
||||
|
||||
void Task::startTask()
|
||||
{
|
||||
emitStarted();
|
||||
executeTask();
|
||||
}
|
||||
|
||||
void Task::emitStarted()
|
||||
void Task::start()
|
||||
{
|
||||
running = true;
|
||||
m_running = true;
|
||||
emit started();
|
||||
executeTask();
|
||||
}
|
||||
|
||||
void Task::emitFailed(QString reason)
|
||||
{
|
||||
running = false;
|
||||
m_running = false;
|
||||
emit failed(reason);
|
||||
}
|
||||
|
||||
void Task::emitSucceeded()
|
||||
{
|
||||
running = false;
|
||||
m_running = false;
|
||||
emit succeeded();
|
||||
}
|
||||
|
||||
|
||||
bool Task::isRunning() const
|
||||
{
|
||||
return running;
|
||||
}
|
||||
|
||||
|
||||
void Task::emitStatusChange(const QString &status)
|
||||
{
|
||||
emit statusChanged(status);
|
||||
}
|
||||
|
||||
void Task::emitProgressChange(int progress)
|
||||
{
|
||||
emit progressChanged(progress);
|
||||
return m_running;
|
||||
}
|
||||
|
@ -13,53 +13,37 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef TASK_H
|
||||
#define TASK_H
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include "ProgressProvider.h"
|
||||
|
||||
class Task : public QObject
|
||||
class Task : public ProgressProvider
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit Task(QObject *parent = 0);
|
||||
|
||||
QString getStatus() const;
|
||||
int getProgress() const;
|
||||
bool isRunning() const;
|
||||
virtual QString getStatus() const;
|
||||
virtual void getProgress(qint64& current, qint64& total);
|
||||
virtual bool isRunning() const;
|
||||
|
||||
public slots:
|
||||
void startTask();
|
||||
|
||||
protected slots:
|
||||
void setStatus(const QString& status);
|
||||
void setProgress(int progress);
|
||||
|
||||
signals:
|
||||
void started();
|
||||
void failed(QString reason);
|
||||
void succeeded();
|
||||
|
||||
void statusChanged(Task* task, const QString& status);
|
||||
void progressChanged(Task* task, int progress);
|
||||
|
||||
void statusChanged(const QString& status);
|
||||
void progressChanged(int progress);
|
||||
virtual void start();
|
||||
|
||||
protected:
|
||||
virtual void executeTask() = 0;
|
||||
|
||||
virtual void emitStarted();
|
||||
virtual void emitFailed(QString reason);
|
||||
virtual void emitSucceeded();
|
||||
|
||||
virtual void emitStatusChange(const QString &status);
|
||||
virtual void emitProgressChange(int progress);
|
||||
|
||||
QString status;
|
||||
int progress;
|
||||
bool running = false;
|
||||
};
|
||||
virtual void emitFailed(QString reason);
|
||||
|
||||
#endif // TASK_H
|
||||
protected slots:
|
||||
void setStatus(const QString& status);
|
||||
void setProgress(int progress);
|
||||
|
||||
protected:
|
||||
QString m_status;
|
||||
int m_progress = 0;
|
||||
bool m_running = false;
|
||||
};
|
||||
|
Reference in New Issue
Block a user