Runnable 1.6 instances!
This commit is contained in:
@ -27,16 +27,14 @@
|
||||
LoginTask::LoginTask( const UserInfo& uInfo, QObject* parent ) :
|
||||
Task(parent), uInfo(uInfo)
|
||||
{
|
||||
|
||||
netMgr.reset(new QNetworkAccessManager());
|
||||
}
|
||||
|
||||
void LoginTask::executeTask()
|
||||
{
|
||||
setStatus("Logging in...");
|
||||
|
||||
QNetworkAccessManager netMgr;
|
||||
connect(&netMgr, SIGNAL(finished(QNetworkReply*)),
|
||||
SLOT(processNetReply(QNetworkReply*)));
|
||||
connect(netMgr.data(), SIGNAL(finished(QNetworkReply*)), this, SLOT(processNetReply(QNetworkReply*)));
|
||||
|
||||
QUrl loginURL("https://login.minecraft.net/");
|
||||
QNetworkRequest netRequest(loginURL);
|
||||
@ -47,8 +45,7 @@ void LoginTask::executeTask()
|
||||
params.addQueryItem("password", uInfo.password);
|
||||
params.addQueryItem("version", "13");
|
||||
|
||||
netReply = netMgr.post(netRequest, params.query(QUrl::EncodeSpaces).toUtf8());
|
||||
exec();
|
||||
netReply = netMgr->post(netRequest, params.query(QUrl::EncodeSpaces).toUtf8());
|
||||
}
|
||||
|
||||
void LoginTask::processNetReply(QNetworkReply *reply)
|
||||
@ -115,6 +112,5 @@ void LoginTask::processNetReply(QNetworkReply *reply)
|
||||
emit loginFailed("Login failed: " + reply->errorString());
|
||||
break;
|
||||
}
|
||||
|
||||
quit();
|
||||
emitEnded();
|
||||
}
|
||||
|
@ -17,7 +17,7 @@
|
||||
#define LOGINTASK_H
|
||||
|
||||
#include "Task.h"
|
||||
|
||||
#include <QSharedPointer>
|
||||
#include "libmmc_config.h"
|
||||
|
||||
struct UserInfo
|
||||
@ -33,7 +33,7 @@ struct LoginResponse
|
||||
qint64 latestVersion;
|
||||
};
|
||||
|
||||
//class QNetworkAccessManager;
|
||||
class QNetworkAccessManager;
|
||||
class QNetworkReply;
|
||||
|
||||
class LIBMULTIMC_EXPORT LoginTask : public Task
|
||||
@ -54,6 +54,8 @@ protected:
|
||||
|
||||
QNetworkReply* netReply;
|
||||
UserInfo uInfo;
|
||||
private:
|
||||
QSharedPointer<QNetworkAccessManager> netMgr;
|
||||
};
|
||||
|
||||
#endif // LOGINTASK_H
|
||||
|
@ -16,7 +16,7 @@
|
||||
#include "Task.h"
|
||||
|
||||
Task::Task(QObject *parent) :
|
||||
QThread(parent)
|
||||
QObject(parent)
|
||||
{
|
||||
|
||||
}
|
||||
@ -49,29 +49,31 @@ void Task::setProgress(int progress)
|
||||
}
|
||||
|
||||
void Task::startTask()
|
||||
{
|
||||
start();
|
||||
}
|
||||
|
||||
void Task::run()
|
||||
{
|
||||
emitStarted();
|
||||
executeTask();
|
||||
emitEnded();
|
||||
}
|
||||
|
||||
void Task::emitStarted()
|
||||
{
|
||||
running = true;
|
||||
emit started();
|
||||
emit started(this);
|
||||
}
|
||||
|
||||
void Task::emitEnded()
|
||||
{
|
||||
running = false;
|
||||
emit ended();
|
||||
emit ended(this);
|
||||
}
|
||||
|
||||
bool Task::isRunning() const
|
||||
{
|
||||
return running;
|
||||
}
|
||||
|
||||
|
||||
void Task::emitStatusChange(const QString &status)
|
||||
{
|
||||
emit statusChanged(status);
|
||||
|
@ -17,12 +17,11 @@
|
||||
#define TASK_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QThread>
|
||||
#include <QString>
|
||||
|
||||
#include "libmmc_config.h"
|
||||
|
||||
class LIBMULTIMC_EXPORT Task : public QThread
|
||||
class LIBMULTIMC_EXPORT Task : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
@ -34,6 +33,8 @@ public:
|
||||
QString getStatus() const;
|
||||
int getProgress() const;
|
||||
|
||||
bool isRunning() const;
|
||||
|
||||
/*!
|
||||
* \brief Calculates and sets the task's progress based on the number of parts completed out of the total number to complete.
|
||||
* This is essentially just shorthand for setProgress((parts / whole) * 100);
|
||||
@ -43,7 +44,7 @@ public:
|
||||
*/
|
||||
void calcProgress(int parts, int whole);
|
||||
|
||||
public slots:
|
||||
protected slots:
|
||||
void setStatus(const QString& status);
|
||||
void setProgress(int progress);
|
||||
|
||||
@ -54,7 +55,6 @@ signals:
|
||||
void started();
|
||||
void ended();
|
||||
|
||||
|
||||
void statusChanged(Task* task, const QString& status);
|
||||
void progressChanged(Task* task, int progress);
|
||||
|
||||
@ -62,7 +62,6 @@ signals:
|
||||
void progressChanged(int progress);
|
||||
|
||||
protected:
|
||||
virtual void run();
|
||||
virtual void executeTask() = 0;
|
||||
|
||||
virtual void emitStarted();
|
||||
@ -73,6 +72,7 @@ protected:
|
||||
|
||||
QString status;
|
||||
int progress;
|
||||
bool running = false;
|
||||
};
|
||||
|
||||
#endif // TASK_H
|
||||
|
Reference in New Issue
Block a user