summaryrefslogtreecommitdiffstats
path: root/gui
diff options
context:
space:
mode:
Diffstat (limited to 'gui')
-rw-r--r--gui/mainwindow.cpp108
-rw-r--r--gui/mainwindow.h31
2 files changed, 96 insertions, 43 deletions
diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp
index 22055b51..47753b37 100644
--- a/gui/mainwindow.cpp
+++ b/gui/mainwindow.cpp
@@ -50,7 +50,9 @@
#include "version.h"
#include "logintask.h"
-#include <instance.h>
+#include "gameupdatetask.h"
+
+#include "instance.h"
#include "minecraftprocess.h"
#include "instancemodel.h"
@@ -68,6 +70,10 @@ MainWindow::MainWindow ( QWidget *parent ) :
instList ( globalSettings->get ( "InstanceDir" ).toString() )
{
ui->setupUi ( this );
+
+ // Set active instance to null.
+ m_activeInst = NULL;
+
// Create the widget
view = new KCategorizedView ( ui->centralWidget );
drawer = new KCategoryDrawer ( view );
@@ -149,7 +155,7 @@ void MainWindow::instanceActivated ( QModelIndex index )
if(!index.isValid())
return;
Instance * inst = (Instance *) index.data(InstanceModel::InstancePointerRole).value<void *>();
- doLogin(inst->id());
+ doLogin();
}
void MainWindow::on_actionAddInstance_triggered()
@@ -313,55 +319,86 @@ void MainWindow::on_actionLaunchInstance_triggered()
Instance* inst = selectedInstance();
if(inst)
{
- doLogin(inst->id());
+ doLogin();
}
}
-void MainWindow::doLogin ( QString inst, const QString& errorMsg )
+void MainWindow::doLogin(const QString& errorMsg)
{
- LoginDialog* loginDlg = new LoginDialog ( this, errorMsg );
- if ( loginDlg->exec() )
+ if (!selectedInstance())
+ return;
+
+ LoginDialog* loginDlg = new LoginDialog(this, errorMsg);
+ if (loginDlg->exec())
{
- UserInfo uInfo ( loginDlg->getUsername(), loginDlg->getPassword() );
-
- TaskDialog* tDialog = new TaskDialog ( this );
- LoginTask* loginTask = new LoginTask ( uInfo, inst, tDialog );
- connect ( loginTask, SIGNAL ( loginComplete ( QString, LoginResponse ) ),
- SLOT ( onLoginComplete ( QString, LoginResponse ) ), Qt::QueuedConnection );
- connect ( loginTask, SIGNAL ( loginFailed ( QString, QString ) ),
- SLOT ( onLoginFailed( QString, QString ) ), Qt::QueuedConnection );
- tDialog->exec ( loginTask );
+ UserInfo uInfo(loginDlg->getUsername(), loginDlg->getPassword());
+
+ TaskDialog* tDialog = new TaskDialog(this);
+ LoginTask* loginTask = new LoginTask(uInfo, tDialog);
+ connect(loginTask, SIGNAL(loginComplete(LoginResponse)),
+ SLOT(onLoginComplete(LoginResponse)), Qt::QueuedConnection);
+ connect(loginTask, SIGNAL(loginFailed(QString)),
+ SLOT(doLogin(QString)), Qt::QueuedConnection);
+ m_activeInst = selectedInstance();
+ tDialog->exec(loginTask);
}
}
-void MainWindow::onLoginComplete ( QString inst, LoginResponse response )
+void MainWindow::onLoginComplete(LoginResponse response)
{
- // TODO: console
- console = new ConsoleWindow();
- auto instance = instList.getInstanceById(inst);
- if(instance)
+ Q_ASSERT_X(m_activeInst != NULL, "onLoginComplete", "no active instance is set");
+
+ if (!m_activeInst->shouldUpdateGame())
{
- proc = new MinecraftProcess(instance, response.username(), response.sessionID());
-
- console->show();
- //connect(proc, SIGNAL(ended()), SLOT(onTerminated()));
- connect(proc, SIGNAL(log(QString,MessageLevel::Enum)), console, SLOT(write(QString,MessageLevel::Enum)));
- proc->launch();
+ launchInstance(m_activeInst, response);
}
else
{
-
+ TaskDialog *tDialog = new TaskDialog(this);
+ GameUpdateTask *updateTask = new GameUpdateTask(response, m_activeInst);
+ connect(updateTask, SIGNAL(gameUpdateComplete(LoginResponse)),
+ SLOT(onGameUpdateComplete(LoginResponse)));
+ connect(updateTask, SIGNAL(gameUpdateError(QString)), SLOT(onGameUpdateError(QString)));
+ tDialog->exec(updateTask);
}
- /*
- QMessageBox::information ( this, "Login Successful",
- QString ( "Logged in as %1 with session ID %2. Instance: %3" ).
- arg ( response.username(), response.sessionID(), inst ) );
- */
}
-void MainWindow::onLoginFailed ( QString inst, const QString& errorMsg )
+void MainWindow::onGameUpdateComplete(LoginResponse response)
+{
+ launchInstance(response);
+}
+
+void MainWindow::onGameUpdateError(QString error)
{
- doLogin(inst, errorMsg);
+ QMessageBox::warning(this, "Error downloading instance", error);
+}
+
+
+void MainWindow::launchInstance(LoginResponse response)
+{
+ Q_ASSERT_X(m_activeInst != NULL, "onLoginComplete", "no active instance is set");
+ launchInstance(m_activeInst, response);
+}
+
+void MainWindow::launchInstance(QString instID, LoginResponse response)
+{
+ Instance *instance = instList.getInstanceById(instID).data();
+ Q_ASSERT_X(instance != NULL, "launchInstance", "instance ID does not correspond to a valid instance");
+ launchInstance(instance, response);
+}
+
+void MainWindow::launchInstance(Instance *instance, LoginResponse response)
+{
+ Q_ASSERT_X(instance != NULL, "launchInstance", "instance is NULL");
+
+ console = new ConsoleWindow();
+ proc = new MinecraftProcess(instance, response.username(), response.sessionID());
+
+ console->show();
+ //connect(proc, SIGNAL(ended()), SLOT(onTerminated()));
+ connect(proc, SIGNAL(log(QString, MessageLevel::Enum)),
+ console, SLOT(write(QString, MessageLevel::Enum)));
+ proc->launch();
}
void MainWindow::taskStart(Task *task)
@@ -415,8 +452,7 @@ void MainWindow::on_actionChangeInstMCVersion_triggered()
if (view->selectionModel()->selectedIndexes().count() < 1)
return;
- QModelIndex index = view->selectionModel()->selectedIndexes().at(0);
- Instance *inst = (Instance *)index.data(InstanceModel::InstancePointerRole).value<void *>();
+ Instance *inst = selectedInstance();
VersionSelectDialog *vselect = new VersionSelectDialog(inst->versionList(), this);
if (vselect->exec() && vselect->selectedVersion())
diff --git a/gui/mainwindow.h b/gui/mainwindow.h
index bc35038e..192cdbc4 100644
--- a/gui/mainwindow.h
+++ b/gui/mainwindow.h
@@ -38,16 +38,21 @@ class MainWindow : public QMainWindow
{
Q_OBJECT
+ /*!
+ * The currently selected instance.
+ */
+ Q_PROPERTY(Instance* selectedInstance READ selectedInstance STORED false)
+
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
void closeEvent(QCloseEvent *event);
- // Browser Dialog
- void openWebPage(QUrl url);
-
-private:
+ // Browser Dialog
+ void openWebPage(QUrl url);
+
+
Instance *selectedInstance();
private slots:
@@ -82,11 +87,14 @@ private slots:
void on_actionChangeInstMCVersion_triggered();
- void doLogin( QString inst, const QString& errorMsg = "" );
+ void doLogin(const QString& errorMsg = "");
- void onLoginComplete( QString inst, LoginResponse response );
- void onLoginFailed( QString inst, const QString& errorMsg );
+ void onLoginComplete(LoginResponse response);
+
+
+ void onGameUpdateComplete(LoginResponse response);
+ void onGameUpdateError(QString error);
void taskStart(Task *task);
void taskEnd(Task *task);
@@ -95,6 +103,10 @@ public slots:
void instanceActivated ( QModelIndex );
void startTask(Task *task);
+
+ void launchInstance(LoginResponse response);
+ void launchInstance(QString instID, LoginResponse response);
+ void launchInstance(Instance *inst, LoginResponse response);
private:
Ui::MainWindow *ui;
@@ -106,6 +118,11 @@ private:
MinecraftProcess *proc;
ConsoleWindow *console;
+ // A pointer to the instance we are actively doing stuff with.
+ // This is set when the user launches an instance and is used to refer to that
+ // instance throughout the launching process.
+ Instance *m_activeInst;
+
Task *m_versionLoadTask;
};