Various task related improvements.
* Errors are reported back to task users via Failure signals. * Lwjgl doesn't download on each legacy instance start anymore. * Tasks were unified when it comes to success/failure. * Task dialogs don't get spawned after short tasks finish anymore.
This commit is contained in:
parent
c8925e0f66
commit
bf5f5091ef
@ -5,11 +5,6 @@ BaseUpdate::BaseUpdate ( BaseInstance* inst, QObject* parent ) : Task ( parent )
|
|||||||
m_inst = inst;
|
m_inst = inst;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseUpdate::error ( const QString& msg )
|
|
||||||
{
|
|
||||||
emit gameUpdateError(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
void BaseUpdate::updateDownloadProgress(qint64 current, qint64 total)
|
void BaseUpdate::updateDownloadProgress(qint64 current, qint64 total)
|
||||||
{
|
{
|
||||||
// The progress on the current file is current / total
|
// The progress on the current file is current / total
|
||||||
|
@ -38,20 +38,8 @@ public:
|
|||||||
|
|
||||||
virtual void executeTask() = 0;
|
virtual void executeTask() = 0;
|
||||||
|
|
||||||
signals:
|
|
||||||
/*!
|
|
||||||
* \brief Signal emitted when the game update is complete.
|
|
||||||
*/
|
|
||||||
void gameUpdateComplete();
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* \brief Signal emitted if an error occurrs during the update.
|
|
||||||
* \param errorMsg An error message to be displayed to the user.
|
|
||||||
*/
|
|
||||||
void gameUpdateError(const QString &errorMsg);
|
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
virtual void error(const QString &msg);
|
//virtual void error(const QString &msg);
|
||||||
void updateDownloadProgress(qint64 current, qint64 total);
|
void updateDownloadProgress(qint64 current, qint64 total);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -18,21 +18,33 @@ void LegacyUpdate::executeTask()
|
|||||||
void LegacyUpdate::lwjglStart()
|
void LegacyUpdate::lwjglStart()
|
||||||
{
|
{
|
||||||
LegacyInstance * inst = (LegacyInstance *) m_inst;
|
LegacyInstance * inst = (LegacyInstance *) m_inst;
|
||||||
|
|
||||||
|
lwjglVersion = inst->lwjglVersion();
|
||||||
|
lwjglTargetPath = PathCombine("lwjgl", lwjglVersion );
|
||||||
|
lwjglNativesPath = PathCombine( lwjglTargetPath, "natives/");
|
||||||
|
|
||||||
|
// if the 'done' file exists, we don't have to download this again
|
||||||
|
QFileInfo doneFile(PathCombine(lwjglTargetPath, "done"));
|
||||||
|
if(doneFile.exists())
|
||||||
|
{
|
||||||
|
emitSucceeded();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
auto &list = LWJGLVersionList::get();
|
auto &list = LWJGLVersionList::get();
|
||||||
if(!list.isLoaded())
|
if(!list.isLoaded())
|
||||||
{
|
{
|
||||||
error("Too soon! Let the LWJGL list load :)");
|
emitFailed("Too soon! Let the LWJGL list load :)");
|
||||||
emitEnded();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QString lwjglVer = inst->lwjglVersion();
|
|
||||||
auto version = list.getVersion(lwjglVer);
|
auto version = list.getVersion(lwjglVersion);
|
||||||
if(!version)
|
if(!version)
|
||||||
{
|
{
|
||||||
error("Game update failed: the selected LWJGL version is invalid.");
|
emitFailed("Game update failed: the selected LWJGL version is invalid.");
|
||||||
emitEnded();
|
return;
|
||||||
}
|
}
|
||||||
lwjglVersion = version->name();
|
|
||||||
QString url = version->url();
|
QString url = version->url();
|
||||||
QUrl realUrl(url);
|
QUrl realUrl(url);
|
||||||
QString hostname = realUrl.host();
|
QString hostname = realUrl.host();
|
||||||
@ -56,8 +68,9 @@ void LegacyUpdate::lwjglFinished(QNetworkReply* reply)
|
|||||||
}
|
}
|
||||||
if(reply->error() != QNetworkReply::NoError)
|
if(reply->error() != QNetworkReply::NoError)
|
||||||
{
|
{
|
||||||
error("Failed to download: " + reply->errorString() + "\nSometimes you have to wait a bit if you download many LWJGL versions in a row. YMMV");
|
emitFailed( "Failed to download: "+
|
||||||
emitEnded();
|
reply->errorString()+
|
||||||
|
"\nSometimes you have to wait a bit if you download many LWJGL versions in a row. YMMV");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto &worker = NetWorker::spawn();
|
auto &worker = NetWorker::spawn();
|
||||||
@ -95,22 +108,19 @@ void LegacyUpdate::lwjglFinished(QNetworkReply* reply)
|
|||||||
void LegacyUpdate::extractLwjgl()
|
void LegacyUpdate::extractLwjgl()
|
||||||
{
|
{
|
||||||
// make sure the directories are there
|
// make sure the directories are there
|
||||||
QString lwjgl_base = PathCombine("lwjgl", lwjglVersion );
|
|
||||||
QString nativesPath = PathCombine( lwjgl_base, "natives/");
|
bool success = ensurePathExists(lwjglNativesPath);
|
||||||
bool success = ensurePathExists(nativesPath);
|
|
||||||
|
|
||||||
if(!success)
|
if(!success)
|
||||||
{
|
{
|
||||||
error("Failed to extract the lwjgl libs - error when creating required folders.");
|
emitFailed("Failed to extract the lwjgl libs - error when creating required folders.");
|
||||||
emitEnded();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QuaZip zip("lwjgl.zip");
|
QuaZip zip("lwjgl.zip");
|
||||||
if(!zip.open(QuaZip::mdUnzip))
|
if(!zip.open(QuaZip::mdUnzip))
|
||||||
{
|
{
|
||||||
error("Failed to extract the lwjgl libs - not a valid archive.");
|
emitFailed("Failed to extract the lwjgl libs - not a valid archive.");
|
||||||
emitEnded();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,8 +132,7 @@ void LegacyUpdate::extractLwjgl()
|
|||||||
if(!file.open(QIODevice::ReadOnly))
|
if(!file.open(QIODevice::ReadOnly))
|
||||||
{
|
{
|
||||||
zip.close();
|
zip.close();
|
||||||
error("Failed to extract the lwjgl libs - error while reading archive.");
|
emitFailed("Failed to extract the lwjgl libs - error while reading archive.");
|
||||||
emitEnded();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QuaZipFileInfo info;
|
QuaZipFileInfo info;
|
||||||
@ -139,7 +148,7 @@ void LegacyUpdate::extractLwjgl()
|
|||||||
{
|
{
|
||||||
if (name.endsWith(jarNames[i]))
|
if (name.endsWith(jarNames[i]))
|
||||||
{
|
{
|
||||||
destFileName = PathCombine(lwjgl_base, jarNames[i]);
|
destFileName = PathCombine(lwjglTargetPath, jarNames[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Not found? look for the natives
|
// Not found? look for the natives
|
||||||
@ -160,7 +169,7 @@ void LegacyUpdate::extractLwjgl()
|
|||||||
name = name.mid(lastSlash+1);
|
name = name.mid(lastSlash+1);
|
||||||
else if(lastBackSlash != -1)
|
else if(lastBackSlash != -1)
|
||||||
name = name.mid(lastBackSlash+1);
|
name = name.mid(lastBackSlash+1);
|
||||||
destFileName = PathCombine(nativesPath, name);
|
destFileName = PathCombine(lwjglNativesPath, name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Now if destFileName is still empty, go to the next file.
|
// Now if destFileName is still empty, go to the next file.
|
||||||
@ -176,13 +185,15 @@ void LegacyUpdate::extractLwjgl()
|
|||||||
}
|
}
|
||||||
zip.close();
|
zip.close();
|
||||||
m_reply.clear();
|
m_reply.clear();
|
||||||
emit gameUpdateComplete();
|
QFile doneFile(PathCombine(lwjglTargetPath, "done"));
|
||||||
emitEnded();
|
doneFile.open(QIODevice::WriteOnly);
|
||||||
|
doneFile.write("done.");
|
||||||
|
doneFile.close();
|
||||||
|
emitSucceeded();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LegacyUpdate::lwjglFailed()
|
void LegacyUpdate::lwjglFailed()
|
||||||
{
|
{
|
||||||
error("Bad stuff happened while trying to get the lwjgl libs...");
|
emitFailed("Bad stuff happened while trying to get the lwjgl libs...");
|
||||||
emitEnded();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,6 +47,9 @@ private:
|
|||||||
// MinecraftVersion *targetVersion;
|
// MinecraftVersion *targetVersion;
|
||||||
QString lwjglURL;
|
QString lwjglURL;
|
||||||
QString lwjglVersion;
|
QString lwjglVersion;
|
||||||
|
|
||||||
|
QString lwjglTargetPath;
|
||||||
|
QString lwjglNativesPath;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ void OneSixUpdate::executeTask()
|
|||||||
if(targetVersion == nullptr)
|
if(targetVersion == nullptr)
|
||||||
{
|
{
|
||||||
// don't do anything if it was invalid
|
// don't do anything if it was invalid
|
||||||
emit gameUpdateComplete();
|
emitSucceeded();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,8 +104,7 @@ void OneSixUpdate::versionFileFinished()
|
|||||||
|
|
||||||
void OneSixUpdate::versionFileFailed()
|
void OneSixUpdate::versionFileFailed()
|
||||||
{
|
{
|
||||||
error("Failed to download the version description. Try again.");
|
emitFailed("Failed to download the version description. Try again.");
|
||||||
emitEnded();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OneSixUpdate::jarlibStart()
|
void OneSixUpdate::jarlibStart()
|
||||||
@ -114,8 +113,7 @@ void OneSixUpdate::jarlibStart()
|
|||||||
bool successful = inst->reloadFullVersion();
|
bool successful = inst->reloadFullVersion();
|
||||||
if(!successful)
|
if(!successful)
|
||||||
{
|
{
|
||||||
error("Failed to load the version description file (version.json). It might be corrupted, missing or simply too new.");
|
emitFailed("Failed to load the version description file (version.json). It might be corrupted, missing or simply too new.");
|
||||||
emitEnded();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,13 +147,11 @@ void OneSixUpdate::jarlibStart()
|
|||||||
|
|
||||||
void OneSixUpdate::jarlibFinished()
|
void OneSixUpdate::jarlibFinished()
|
||||||
{
|
{
|
||||||
emit gameUpdateComplete();
|
emitSucceeded();
|
||||||
emitEnded();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OneSixUpdate::jarlibFailed()
|
void OneSixUpdate::jarlibFailed()
|
||||||
{
|
{
|
||||||
error("Failed to download the binary garbage. Try again. Maybe. IF YOU DARE");
|
emitFailed("Failed to download the binary garbage. Try again. Maybe. IF YOU DARE");
|
||||||
emitEnded();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,8 +119,7 @@ void LWJGLVersionList::netRequestComplete()
|
|||||||
int errorLine;
|
int errorLine;
|
||||||
if (!doc.setContent(reply->readAll(), false, &xmlErrorMsg, &errorLine))
|
if (!doc.setContent(reply->readAll(), false, &xmlErrorMsg, &errorLine))
|
||||||
{
|
{
|
||||||
failed("Failed to load LWJGL list. XML error: " + xmlErrorMsg +
|
failed("Failed to load LWJGL list. XML error: " + xmlErrorMsg + " at line " + QString::number(errorLine));
|
||||||
" at line " + QString::number(errorLine));
|
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -179,9 +179,8 @@ void MCVListLoadTask::list_downloaded()
|
|||||||
{
|
{
|
||||||
if(vlistReply->error() != QNetworkReply::QNetworkReply::NoError)
|
if(vlistReply->error() != QNetworkReply::QNetworkReply::NoError)
|
||||||
{
|
{
|
||||||
qDebug() << "Failed to load Minecraft main version list" << vlistReply->errorString();
|
|
||||||
vlistReply->deleteLater();
|
vlistReply->deleteLater();
|
||||||
emitEnded();
|
emitFailed("Failed to load Minecraft main version list" + vlistReply->errorString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,15 +190,13 @@ void MCVListLoadTask::list_downloaded()
|
|||||||
|
|
||||||
if (jsonError.error != QJsonParseError::NoError)
|
if (jsonError.error != QJsonParseError::NoError)
|
||||||
{
|
{
|
||||||
qDebug() << "Error parsing version list JSON:" << jsonError.errorString();
|
emitFailed("Error parsing version list JSON:" + jsonError.errorString());
|
||||||
emitEnded();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!jsonDoc.isObject())
|
if(!jsonDoc.isObject())
|
||||||
{
|
{
|
||||||
qDebug() << "Error parsing version list JSON: " << "jsonDoc is not an object";
|
emitFailed("Error parsing version list JSON: jsonDoc is not an object");
|
||||||
emitEnded();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,8 +205,7 @@ void MCVListLoadTask::list_downloaded()
|
|||||||
// Get the ID of the latest release and the latest snapshot.
|
// Get the ID of the latest release and the latest snapshot.
|
||||||
if(!root.value("latest").isObject())
|
if(!root.value("latest").isObject())
|
||||||
{
|
{
|
||||||
qDebug() << "Error parsing version list JSON: " << "version list is missing 'latest' object";
|
emitFailed("Error parsing version list JSON: version list is missing 'latest' object");
|
||||||
emitEnded();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -219,22 +215,19 @@ void MCVListLoadTask::list_downloaded()
|
|||||||
QString latestSnapshotID = latest.value("snapshot").toString("");
|
QString latestSnapshotID = latest.value("snapshot").toString("");
|
||||||
if(latestReleaseID.isEmpty())
|
if(latestReleaseID.isEmpty())
|
||||||
{
|
{
|
||||||
qDebug() << "Error parsing version list JSON: " << "latest release field is missing";
|
emitFailed("Error parsing version list JSON: latest release field is missing");
|
||||||
emitEnded();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(latestSnapshotID.isEmpty())
|
if(latestSnapshotID.isEmpty())
|
||||||
{
|
{
|
||||||
qDebug() << "Error parsing version list JSON: " << "latest snapshot field is missing";
|
emitFailed("Error parsing version list JSON: latest snapshot field is missing");
|
||||||
emitEnded();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now, get the array of versions.
|
// Now, get the array of versions.
|
||||||
if(!root.value("versions").isArray())
|
if(!root.value("versions").isArray())
|
||||||
{
|
{
|
||||||
qDebug() << "Error parsing version list JSON: " << "version list object is missing 'versions' array";
|
emitFailed("Error parsing version list JSON: version list object is missing 'versions' array");
|
||||||
emitEnded();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QJsonArray versions = root.value("versions").toArray();
|
QJsonArray versions = root.value("versions").toArray();
|
||||||
@ -308,7 +301,7 @@ void MCVListLoadTask::list_downloaded()
|
|||||||
#ifdef PRINT_VERSIONS
|
#ifdef PRINT_VERSIONS
|
||||||
m_list->printToStdOut();
|
m_list->printToStdOut();
|
||||||
#endif
|
#endif
|
||||||
emitEnded();
|
emitSucceeded();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,44 +71,41 @@ void LoginTask::processNetReply(QNetworkReply *reply)
|
|||||||
QString username = strings[2];
|
QString username = strings[2];
|
||||||
QString sessionID = strings[3];
|
QString sessionID = strings[3];
|
||||||
|
|
||||||
LoginResponse response{username, sessionID, latestVersion};
|
result = {username, sessionID, latestVersion};
|
||||||
emit loginComplete(response);
|
emitSucceeded();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
emit loginFailed("Failed to parse Minecraft version string.");
|
emitFailed("Failed to parse Minecraft version string.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (responseStr.toLower() == "bad login")
|
if (responseStr.toLower() == "bad login")
|
||||||
emit loginFailed("Invalid username or password.");
|
emitFailed("Invalid username or password.");
|
||||||
else if (responseStr.toLower() == "old version")
|
else if (responseStr.toLower() == "old version")
|
||||||
emit loginFailed("Launcher outdated, please update.");
|
emitFailed("Launcher outdated, please update.");
|
||||||
else
|
else
|
||||||
emit loginFailed("Login failed: " + responseStr);
|
emitFailed("Login failed: " + responseStr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (responseCode == 503)
|
else if (responseCode == 503)
|
||||||
{
|
{
|
||||||
emit loginFailed("The login servers are currently unavailable. "
|
emitFailed("The login servers are currently unavailable. Check http://help.mojang.com/ for more info.");
|
||||||
"Check http://help.mojang.com/ for more info.");
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
emit loginFailed(QString("Login failed: Unknown HTTP error %1 occurred.").
|
emitFailed(QString("Login failed: Unknown HTTP error %1 occurred.").arg(QString::number(responseCode)));
|
||||||
arg(QString::number(responseCode)));
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case QNetworkReply::OperationCanceledError:
|
case QNetworkReply::OperationCanceledError:
|
||||||
emit loginFailed("Login canceled.");
|
emitFailed("Login canceled.");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
emit loginFailed("Login failed: " + reply->errorString());
|
emitFailed("Login failed: " + reply->errorString());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
emitEnded();
|
|
||||||
}
|
}
|
||||||
|
@ -40,17 +40,18 @@ class LIBMULTIMC_EXPORT LoginTask : public Task
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit LoginTask(const UserInfo& uInfo, QObject *parent = 0);
|
explicit LoginTask(const UserInfo& uInfo, QObject *parent = 0);
|
||||||
|
LoginResponse getResult()
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
public slots:
|
protected slots:
|
||||||
void processNetReply(QNetworkReply* reply);
|
void processNetReply(QNetworkReply* reply);
|
||||||
|
|
||||||
signals:
|
|
||||||
void loginComplete(LoginResponse loginResponse);
|
|
||||||
void loginFailed(const QString& errorMsg);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void executeTask();
|
void executeTask();
|
||||||
|
|
||||||
|
LoginResponse result;
|
||||||
QNetworkReply* netReply;
|
QNetworkReply* netReply;
|
||||||
UserInfo uInfo;
|
UserInfo uInfo;
|
||||||
};
|
};
|
||||||
|
@ -37,11 +37,6 @@ int Task::getProgress() const
|
|||||||
return progress;
|
return progress;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Task::calcProgress(int parts, int whole)
|
|
||||||
{
|
|
||||||
setProgress((int)((((float)parts) / ((float)whole))*100)); // Not sure if C++ or LISP...
|
|
||||||
}
|
|
||||||
|
|
||||||
void Task::setProgress(int progress)
|
void Task::setProgress(int progress)
|
||||||
{
|
{
|
||||||
this->progress = progress;
|
this->progress = progress;
|
||||||
@ -58,16 +53,21 @@ void Task::emitStarted()
|
|||||||
{
|
{
|
||||||
running = true;
|
running = true;
|
||||||
emit started();
|
emit started();
|
||||||
emit started(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Task::emitEnded()
|
void Task::emitFailed(QString reason)
|
||||||
{
|
{
|
||||||
running = false;
|
running = false;
|
||||||
emit ended();
|
emit failed(reason);
|
||||||
emit ended(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Task::emitSucceeded()
|
||||||
|
{
|
||||||
|
running = false;
|
||||||
|
emit succeeded();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Task::isRunning() const
|
bool Task::isRunning() const
|
||||||
{
|
{
|
||||||
return running;
|
return running;
|
||||||
|
@ -27,33 +27,21 @@ class LIBMULTIMC_EXPORT Task : public QObject
|
|||||||
public:
|
public:
|
||||||
explicit Task(QObject *parent = 0);
|
explicit Task(QObject *parent = 0);
|
||||||
|
|
||||||
// Starts the task.
|
|
||||||
void startTask();
|
|
||||||
|
|
||||||
QString getStatus() const;
|
QString getStatus() const;
|
||||||
int getProgress() const;
|
int getProgress() const;
|
||||||
|
|
||||||
bool isRunning() const;
|
bool isRunning() const;
|
||||||
|
|
||||||
/*!
|
public slots:
|
||||||
* \brief Calculates and sets the task's progress based on the number of parts completed out of the total number to complete.
|
void startTask();
|
||||||
* This is essentially just shorthand for setProgress((parts / whole) * 100);
|
|
||||||
* \param parts The parts out of the whole completed. This parameter should
|
|
||||||
* be less than whole. If it is greater than whole, progress is set to 100.
|
|
||||||
* \param whole The total number of things that need to be completed.
|
|
||||||
*/
|
|
||||||
void calcProgress(int parts, int whole);
|
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void setStatus(const QString& status);
|
void setStatus(const QString& status);
|
||||||
void setProgress(int progress);
|
void setProgress(int progress);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void started(Task* task);
|
|
||||||
void ended(Task* task);
|
|
||||||
|
|
||||||
void started();
|
void started();
|
||||||
void ended();
|
void failed(QString reason);
|
||||||
|
void succeeded();
|
||||||
|
|
||||||
void statusChanged(Task* task, const QString& status);
|
void statusChanged(Task* task, const QString& status);
|
||||||
void progressChanged(Task* task, int progress);
|
void progressChanged(Task* task, int progress);
|
||||||
@ -65,7 +53,8 @@ protected:
|
|||||||
virtual void executeTask() = 0;
|
virtual void executeTask() = 0;
|
||||||
|
|
||||||
virtual void emitStarted();
|
virtual void emitStarted();
|
||||||
virtual void emitEnded();
|
virtual void emitFailed(QString reason);
|
||||||
|
virtual void emitSucceeded();
|
||||||
|
|
||||||
virtual void emitStatusChange(const QString &status);
|
virtual void emitStatusChange(const QString &status);
|
||||||
virtual void emitProgressChange(int progress);
|
virtual void emitProgressChange(int progress);
|
||||||
|
@ -173,7 +173,8 @@ void MainWindow::on_actionAddInstance_triggered()
|
|||||||
m_versionLoadTask && m_versionLoadTask->isRunning())
|
m_versionLoadTask && m_versionLoadTask->isRunning())
|
||||||
{
|
{
|
||||||
QEventLoop waitLoop;
|
QEventLoop waitLoop;
|
||||||
waitLoop.connect(m_versionLoadTask, SIGNAL(ended()), SLOT(quit()));
|
waitLoop.connect(m_versionLoadTask, SIGNAL(failed(QString)), SLOT(quit()));
|
||||||
|
waitLoop.connect(m_versionLoadTask, SIGNAL(succeeded()), SLOT(quit()));
|
||||||
waitLoop.exec();
|
waitLoop.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -260,13 +261,11 @@ void MainWindow::on_actionSettings_triggered()
|
|||||||
|
|
||||||
void MainWindow::on_actionReportBug_triggered()
|
void MainWindow::on_actionReportBug_triggered()
|
||||||
{
|
{
|
||||||
//QDesktopServices::openUrl(QUrl("http://bugs.forkk.net/"));
|
openWebPage ( QUrl ( "http://jira.forkk.net/browse/MMC" ) );
|
||||||
openWebPage ( QUrl ( "http://bugs.forkk.net/" ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionNews_triggered()
|
void MainWindow::on_actionNews_triggered()
|
||||||
{
|
{
|
||||||
//QDesktopServices::openUrl(QUrl("http://news.forkk.net/"));
|
|
||||||
openWebPage ( QUrl ( "http://news.forkk.net/" ) );
|
openWebPage ( QUrl ( "http://news.forkk.net/" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -397,20 +396,19 @@ void MainWindow::doLogin(const QString& errorMsg)
|
|||||||
|
|
||||||
TaskDialog* tDialog = new TaskDialog(this);
|
TaskDialog* tDialog = new TaskDialog(this);
|
||||||
LoginTask* loginTask = new LoginTask(uInfo, tDialog);
|
LoginTask* loginTask = new LoginTask(uInfo, tDialog);
|
||||||
connect(loginTask, SIGNAL(loginComplete(LoginResponse)),
|
connect(loginTask, SIGNAL(succeeded()),SLOT(onLoginComplete()), Qt::QueuedConnection);
|
||||||
SLOT(onLoginComplete(LoginResponse)), Qt::QueuedConnection);
|
connect(loginTask, SIGNAL(failed(QString)), SLOT(doLogin(QString)), Qt::QueuedConnection);
|
||||||
connect(loginTask, SIGNAL(loginFailed(QString)),
|
|
||||||
SLOT(doLogin(QString)), Qt::QueuedConnection);
|
|
||||||
m_activeInst = selectedInstance();
|
m_activeInst = selectedInstance();
|
||||||
tDialog->exec(loginTask);
|
tDialog->exec(loginTask);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onLoginComplete(LoginResponse response)
|
void MainWindow::onLoginComplete()
|
||||||
{
|
{
|
||||||
if(!m_activeInst)
|
if(!m_activeInst)
|
||||||
return;
|
return;
|
||||||
m_activeLogin = LoginResponse(response);
|
LoginTask * task = (LoginTask *) QObject::sender();
|
||||||
|
m_activeLogin = task->getResult();
|
||||||
|
|
||||||
BaseUpdate *updateTask = m_activeInst->doUpdate();
|
BaseUpdate *updateTask = m_activeInst->doUpdate();
|
||||||
if(!updateTask)
|
if(!updateTask)
|
||||||
@ -420,8 +418,8 @@ void MainWindow::onLoginComplete(LoginResponse response)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
TaskDialog *tDialog = new TaskDialog(this);
|
TaskDialog *tDialog = new TaskDialog(this);
|
||||||
connect(updateTask, SIGNAL(gameUpdateComplete()),SLOT(onGameUpdateComplete()));
|
connect(updateTask, SIGNAL(succeeded()),SLOT(onGameUpdateComplete()));
|
||||||
connect(updateTask, SIGNAL(gameUpdateError(QString)), SLOT(onGameUpdateError(QString)));
|
connect(updateTask, SIGNAL(failed(QString)), SLOT(onGameUpdateError(QString)));
|
||||||
tDialog->exec(updateTask);
|
tDialog->exec(updateTask);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -451,23 +449,25 @@ void MainWindow::launchInstance(BaseInstance *instance, LoginResponse response)
|
|||||||
proc->launch();
|
proc->launch();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::taskStart(Task *task)
|
void MainWindow::taskStart()
|
||||||
{
|
{
|
||||||
// Nothing to do here yet.
|
// Nothing to do here yet.
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::taskEnd(Task *task)
|
void MainWindow::taskEnd()
|
||||||
{
|
{
|
||||||
if (task == m_versionLoadTask)
|
QObject *sender = QObject::sender();
|
||||||
|
if (sender == m_versionLoadTask)
|
||||||
m_versionLoadTask = NULL;
|
m_versionLoadTask = NULL;
|
||||||
|
|
||||||
delete task;
|
sender->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::startTask(Task *task)
|
void MainWindow::startTask(Task *task)
|
||||||
{
|
{
|
||||||
connect(task, SIGNAL(started(Task*)), SLOT(taskStart(Task*)));
|
connect(task, SIGNAL(started()), SLOT(taskStart()));
|
||||||
connect(task, SIGNAL(ended(Task*)), SLOT(taskEnd(Task*)));
|
connect(task, SIGNAL(succeeded()), SLOT(taskEnd()));
|
||||||
|
connect(task, SIGNAL(failed(QString)), SLOT(taskEnd()));
|
||||||
task->startTask();
|
task->startTask();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,14 +98,14 @@ private slots:
|
|||||||
void doLogin(const QString& errorMsg = "");
|
void doLogin(const QString& errorMsg = "");
|
||||||
|
|
||||||
|
|
||||||
void onLoginComplete(LoginResponse response);
|
void onLoginComplete();
|
||||||
|
|
||||||
|
|
||||||
void onGameUpdateComplete();
|
void onGameUpdateComplete();
|
||||||
void onGameUpdateError(QString error);
|
void onGameUpdateError(QString error);
|
||||||
|
|
||||||
void taskStart(Task *task);
|
void taskStart();
|
||||||
void taskEnd(Task *task);
|
void taskEnd();
|
||||||
|
|
||||||
void on_actionChangeInstLWJGLVersion_triggered();
|
void on_actionChangeInstLWJGLVersion_triggered();
|
||||||
|
|
||||||
|
@ -45,12 +45,14 @@ void TaskDialog::exec(Task *task)
|
|||||||
this->task = task;
|
this->task = task;
|
||||||
|
|
||||||
// Connect signals.
|
// Connect signals.
|
||||||
connect(task, SIGNAL(started(Task*)), SLOT(onTaskStarted(Task*)));
|
connect(task, SIGNAL(started()), SLOT(onTaskStarted()));
|
||||||
connect(task, SIGNAL(ended(Task*)), SLOT(onTaskEnded(Task*)));
|
connect(task, SIGNAL(failed(QString)), SLOT(onTaskEnded()));
|
||||||
|
connect(task, SIGNAL(succeeded()), SLOT(onTaskEnded()));
|
||||||
connect(task, SIGNAL(statusChanged(const QString&)), SLOT(changeStatus(const QString&)));
|
connect(task, SIGNAL(statusChanged(const QString&)), SLOT(changeStatus(const QString&)));
|
||||||
connect(task, SIGNAL(progressChanged(int)), SLOT(changeProgress(int)));
|
connect(task, SIGNAL(progressChanged(int)), SLOT(changeProgress(int)));
|
||||||
|
|
||||||
task->startTask();
|
// this makes sure that the task is started after the dialog is created
|
||||||
|
QMetaObject::invokeMethod(task, "startTask", Qt::QueuedConnection);
|
||||||
QDialog::exec();
|
QDialog::exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,12 +61,12 @@ Task* TaskDialog::getTask()
|
|||||||
return task;
|
return task;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TaskDialog::onTaskStarted(Task*)
|
void TaskDialog::onTaskStarted()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TaskDialog::onTaskEnded(Task*)
|
void TaskDialog::onTaskEnded()
|
||||||
{
|
{
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
@ -39,8 +39,8 @@ public:
|
|||||||
Task* getTask();
|
Task* getTask();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void onTaskStarted(Task*);
|
void onTaskStarted();
|
||||||
void onTaskEnded(Task*);
|
void onTaskEnded();
|
||||||
|
|
||||||
void changeStatus(const QString& status);
|
void changeStatus(const QString& status);
|
||||||
void changeProgress(int progress);
|
void changeProgress(int progress);
|
||||||
|
16
main.cpp
16
main.cpp
@ -61,9 +61,11 @@ private slots:
|
|||||||
QApplication::instance()->quit();
|
QApplication::instance()->quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void onLoginComplete(QString instId, LoginResponse response)
|
void onLoginComplete()
|
||||||
{
|
{
|
||||||
proc = instance->prepareForLaunch(response.username, response.sessionID);
|
LoginTask * task = (LoginTask *) QObject::sender();
|
||||||
|
auto result = task->getResult();
|
||||||
|
proc = instance->prepareForLaunch(result.username, result.sessionID);
|
||||||
if(!proc)
|
if(!proc)
|
||||||
{
|
{
|
||||||
//FIXME: report error
|
//FIXME: report error
|
||||||
@ -78,7 +80,7 @@ private slots:
|
|||||||
proc->launch();
|
proc->launch();
|
||||||
}
|
}
|
||||||
|
|
||||||
void doLogin(QString instId, const QString &errorMsg)
|
void doLogin(const QString &errorMsg)
|
||||||
{
|
{
|
||||||
LoginDialog* loginDlg = new LoginDialog(nullptr, errorMsg);
|
LoginDialog* loginDlg = new LoginDialog(nullptr, errorMsg);
|
||||||
if (loginDlg->exec())
|
if (loginDlg->exec())
|
||||||
@ -87,10 +89,8 @@ private slots:
|
|||||||
|
|
||||||
TaskDialog* tDialog = new TaskDialog(nullptr);
|
TaskDialog* tDialog = new TaskDialog(nullptr);
|
||||||
LoginTask* loginTask = new LoginTask(uInfo, tDialog);
|
LoginTask* loginTask = new LoginTask(uInfo, tDialog);
|
||||||
connect(loginTask, SIGNAL(loginComplete(QString, LoginResponse)),
|
connect(loginTask, SIGNAL(succeeded()),SLOT(onLoginComplete()), Qt::QueuedConnection);
|
||||||
SLOT(onLoginComplete(QString, LoginResponse)), Qt::QueuedConnection);
|
connect(loginTask, SIGNAL(failed(QString)),SLOT(doLogin(QString)), Qt::QueuedConnection);
|
||||||
connect(loginTask, SIGNAL(loginFailed(QString, QString)),
|
|
||||||
SLOT(doLogin(QString, QString)), Qt::QueuedConnection);
|
|
||||||
tDialog->exec(loginTask);
|
tDialog->exec(loginTask);
|
||||||
}
|
}
|
||||||
//onLoginComplete(LoginResponse("Offline","Offline", 1));
|
//onLoginComplete(LoginResponse("Offline","Offline", 1));
|
||||||
@ -111,7 +111,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "Logging in..." << std::endl;
|
std::cout << "Logging in..." << std::endl;
|
||||||
doLogin(instance->id(),"");
|
doLogin("");
|
||||||
|
|
||||||
return QApplication::instance()->exec();
|
return QApplication::instance()->exec();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user