summaryrefslogtreecommitdiffstats
path: root/gui
diff options
context:
space:
mode:
Diffstat (limited to 'gui')
-rw-r--r--gui/ConsoleWindow.cpp15
-rw-r--r--gui/ConsoleWindow.h2
-rw-r--r--gui/ConsoleWindow.ui7
-rw-r--r--gui/MainWindow.cpp94
-rw-r--r--gui/MainWindow.h9
-rw-r--r--gui/dialogs/AccountListDialog.cpp18
-rw-r--r--gui/dialogs/AccountSelectDialog.cpp2
-rw-r--r--gui/dialogs/ProgressDialog.cpp26
-rw-r--r--gui/dialogs/ProgressDialog.h6
-rw-r--r--gui/dialogs/ProgressDialog.ui21
10 files changed, 115 insertions, 85 deletions
diff --git a/gui/ConsoleWindow.cpp b/gui/ConsoleWindow.cpp
index d0210df6..5db4442e 100644
--- a/gui/ConsoleWindow.cpp
+++ b/gui/ConsoleWindow.cpp
@@ -22,6 +22,9 @@
#include <gui/Platform.h>
#include <gui/dialogs/CustomMessageBox.h>
+#include <gui/dialogs/ProgressDialog.h>
+
+#include "logic/net/PasteUpload.h"
ConsoleWindow::ConsoleWindow(MinecraftProcess *mcproc, QWidget *parent)
: QMainWindow(parent), ui(new Ui::ConsoleWindow), proc(mcproc)
@@ -179,3 +182,15 @@ void ConsoleWindow::onLaunchFailed(BaseInstance *instance)
if(!isVisible())
show();
}
+
+void ConsoleWindow::on_btnPaste_clicked()
+{
+ auto text = ui->text->toPlainText();
+ ProgressDialog dialog(this);
+ PasteUpload* paste=new PasteUpload(this, text);
+ dialog.exec(paste);
+ if(!paste->successful())
+ {
+ CustomMessageBox::selectable(this, "Upload failed", paste->failReason(), QMessageBox::Critical)->exec();
+ }
+}
diff --git a/gui/ConsoleWindow.h b/gui/ConsoleWindow.h
index 2d948484..731c616c 100644
--- a/gui/ConsoleWindow.h
+++ b/gui/ConsoleWindow.h
@@ -76,6 +76,8 @@ slots:
// FIXME: add handlers for the other MinecraftProcess signals (pre/post launch command
// failures)
+ void on_btnPaste_clicked();
+
protected:
void closeEvent(QCloseEvent *);
diff --git a/gui/ConsoleWindow.ui b/gui/ConsoleWindow.ui
index ed1b627b..62cc89ac 100644
--- a/gui/ConsoleWindow.ui
+++ b/gui/ConsoleWindow.ui
@@ -48,6 +48,13 @@
<number>6</number>
</property>
<item>
+ <widget class="QPushButton" name="btnPaste">
+ <property name="text">
+ <string>Upload Log</string>
+ </property>
+ </widget>
+ </item>
+ <item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp
index 7ea5c291..94527b93 100644
--- a/gui/MainWindow.cpp
+++ b/gui/MainWindow.cpp
@@ -215,9 +215,9 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
for(AccountProfile profile : account->profiles())
{
- auto meta = MMC->metacache()->resolveEntry("skins", profile.name() + ".png");
+ auto meta = MMC->metacache()->resolveEntry("skins", profile.name + ".png");
auto action = CacheDownload::make(
- QUrl("http://skins.minecraft.net/MinecraftSkins/" + profile.name() + ".png"),
+ QUrl("http://skins.minecraft.net/MinecraftSkins/" + profile.name + ".png"),
meta);
job->addNetAction(action);
meta->stale = true;
@@ -322,9 +322,9 @@ void MainWindow::repopulateAccountsMenu()
section->setEnabled(false);
accountMenu->addAction(section);
- for (AccountProfile profile : account->profiles())
+ for (auto profile : account->profiles())
{
- QAction *action = new QAction(profile.name(), this);
+ QAction *action = new QAction(profile.name, this);
action->setData(account->username());
action->setCheckable(true);
if(active_username == account->username())
@@ -332,7 +332,7 @@ void MainWindow::repopulateAccountsMenu()
action->setChecked(true);
}
- action->setIcon(SkinUtils::getFaceFromCache(profile.name()));
+ action->setIcon(SkinUtils::getFaceFromCache(profile.name));
accountMenu->addAction(action);
connect(action, SIGNAL(triggered(bool)), SLOT(changeActiveAccount()));
}
@@ -390,7 +390,7 @@ void MainWindow::activeAccountChanged()
const AccountProfile *profile = account->currentProfile();
if (profile != nullptr)
{
- accountMenuButton->setIcon(SkinUtils::getFaceFromCache(profile->name()));
+ accountMenuButton->setIcon(SkinUtils::getFaceFromCache(profile->name));
return;
}
}
@@ -830,79 +830,58 @@ void MainWindow::doLaunch()
accounts->setActiveAccount(account->username());
}
- if (account.get() != nullptr)
- {
- doLaunchInst(m_selectedInstance, account);
- }
-}
-
-void MainWindow::doLaunchInst(BaseInstance* instance, MojangAccountPtr account)
-{
- // We'll need to validate the access token to make sure the account is still logged in.
- ProgressDialog progDialog(this);
- RefreshTask refreshtask(account, &progDialog);
- progDialog.exec(&refreshtask);
+ // if no account is selected, we bail
+ if (!account.get())
+ return;
- if (refreshtask.successful())
- {
- prepareLaunch(m_selectedInstance, account);
- }
- else
+ // do the login. if the account has an access token, try to refresh it first.
+ if(account->accountStatus() != NotVerified)
{
- YggdrasilTask::Error *error = refreshtask.getError();
+ // We'll need to validate the access token to make sure the account is still logged in.
+ ProgressDialog progDialog(this);
+ progDialog.setSkipButton(true, tr("Play Offline"));
+ auto task = account->login();
+ progDialog.exec(task.get());
- if (error != nullptr)
+ auto status = account->accountStatus();
+ if(status == Online) // Online mode! Refresh the token.
{
- if (error->getErrorMessage().contains("invalid token", Qt::CaseInsensitive))
- {
- // TODO: Allow the user to enter their password and "refresh" their access token.
- if (doRefreshToken(account, tr("Your account's access token is invalid. Please enter your password to log in again.")))
- doLaunchInst(instance, account);
- }
- else
- {
- CustomMessageBox::selectable(
- this, tr("Access Token Validation Error"),
- tr("There was an error when trying to validate your access token.\n"
- "Details: %s").arg(error->getDisplayMessage()),
- QMessageBox::Warning, QMessageBox::Ok)->exec();
- }
+ updateInstance(m_selectedInstance, account);
+ return;
}
- else
+ else if(status == Verified) // Offline mode with a verified account
{
- CustomMessageBox::selectable(
- this, tr("Access Token Validation Error"),
- tr("There was an unknown error when trying to validate your access token."
- "The authentication server might be down, or you might not be connected to "
- "the Internet."),
- QMessageBox::Warning, QMessageBox::Ok)->exec();
+ launchInstance(m_selectedInstance, account);
+ return;
}
}
+ if (loginWithPassword(account, tr("Your account is currently not logged in. Please enter your password to log in again.")))
+ updateInstance(m_selectedInstance, account);
}
-bool MainWindow::doRefreshToken(MojangAccountPtr account, const QString& errorMsg)
+bool MainWindow::loginWithPassword(MojangAccountPtr account, const QString& errorMsg)
{
EditAccountDialog passDialog(errorMsg, this, EditAccountDialog::PasswordField);
if (passDialog.exec() == QDialog::Accepted)
{
// To refresh the token, we just create an authenticate task with the given account and the user's password.
ProgressDialog progDialog(this);
- AuthenticateTask authTask(account, passDialog.password(), &progDialog);
- progDialog.exec(&authTask);
- if (authTask.successful())
+ auto task = account->login(passDialog.password());
+ progDialog.exec(task.get());
+ if(task->successful())
return true;
else
{
// If the authentication task failed, recurse with the task's error message.
- return doRefreshToken(account, authTask.failReason());
+ return loginWithPassword(account, task->failReason());
}
}
- else return false;
+ return false;
}
-void MainWindow::prepareLaunch(BaseInstance* instance, MojangAccountPtr account)
+void MainWindow::updateInstance(BaseInstance* instance, MojangAccountPtr account)
{
- Task *updateTask = instance->doUpdate(true);
+ auto updateTask = instance->doUpdate(true);
if (!updateTask)
{
launchInstance(instance, account);
@@ -910,10 +889,9 @@ void MainWindow::prepareLaunch(BaseInstance* instance, MojangAccountPtr account)
else
{
ProgressDialog tDialog(this);
- connect(updateTask, &Task::succeeded, [this, instance, account] { launchInstance(instance, account); });
- connect(updateTask, SIGNAL(failed(QString)), SLOT(onGameUpdateError(QString)));
- tDialog.exec(updateTask);
- delete updateTask;
+ connect(updateTask.get(), &Task::succeeded, [this, instance, account] { launchInstance(instance, account); });
+ connect(updateTask.get(), SIGNAL(failed(QString)), SLOT(onGameUpdateError(QString)));
+ tDialog.exec(updateTask.get());
}
}
diff --git a/gui/MainWindow.h b/gui/MainWindow.h
index b99c54ee..aa9dae75 100644
--- a/gui/MainWindow.h
+++ b/gui/MainWindow.h
@@ -110,18 +110,13 @@ slots:
* If no default account is selected, prompts the user to pick an account.
*/
void doLaunch();
-
- /*!
- * Launches the given instance with the given account.
- */
- void doLaunchInst(BaseInstance* instance, MojangAccountPtr account);
/*!
* Opens an input dialog, allowing the user to input their password and refresh its access token.
* This function will execute the proper Yggdrasil task to refresh the access token.
* Returns true if successful. False if the user cancelled.
*/
- bool doRefreshToken(MojangAccountPtr account, const QString& errorMsg="");
+ bool loginWithPassword(MojangAccountPtr account, const QString& errorMsg="");
/*!
* Launches the given instance with the given account.
@@ -132,7 +127,7 @@ slots:
/*!
* Prepares the given instance for launch with the given account.
*/
- void prepareLaunch(BaseInstance* instance, MojangAccountPtr account);
+ void updateInstance(BaseInstance* instance, MojangAccountPtr account);
void onGameUpdateError(QString error);
diff --git a/gui/dialogs/AccountListDialog.cpp b/gui/dialogs/AccountListDialog.cpp
index f5268b61..8dae5f07 100644
--- a/gui/dialogs/AccountListDialog.cpp
+++ b/gui/dialogs/AccountListDialog.cpp
@@ -20,12 +20,12 @@
#include <logger/QsLog.h>
-#include <logic/auth/flows/AuthenticateTask.h>
#include <logic/net/NetJob.h>
#include <gui/dialogs/EditAccountDialog.h>
#include <gui/dialogs/ProgressDialog.h>
#include <gui/dialogs/AccountSelectDialog.h>
+#include <logic/tasks/Task.h>
#include <MultiMC.h>
@@ -117,24 +117,24 @@ void AccountListDialog::addAccount(const QString& errMsg)
QString username(loginDialog.username());
QString password(loginDialog.password());
- MojangAccountPtr account = MojangAccountPtr(new MojangAccount(username));
-
+ MojangAccountPtr account = MojangAccount::createFromUsername(username);
ProgressDialog progDialog(this);
- AuthenticateTask authTask(account, password, &progDialog);
- if (progDialog.exec(&authTask))
+ auto task = account->login(password);
+ progDialog.exec(task.get());
+ if(task->successful())
{
- // Add the authenticated account to the accounts list.
- MojangAccountPtr account = authTask.getMojangAccount();
m_accounts->addAccount(account);
+ if (m_accounts->count() == 1)
+ m_accounts->setActiveAccount(account->username());
// Grab associated player skins
auto job = new NetJob("Player skins: " + account->username());
for(AccountProfile profile : account->profiles())
{
- auto meta = MMC->metacache()->resolveEntry("skins", profile.name() + ".png");
+ auto meta = MMC->metacache()->resolveEntry("skins", profile.name + ".png");
auto action = CacheDownload::make(
- QUrl("http://skins.minecraft.net/MinecraftSkins/" + profile.name() + ".png"),
+ QUrl("http://skins.minecraft.net/MinecraftSkins/" + profile.name + ".png"),
meta);
job->addNetAction(action);
meta->stale = true;
diff --git a/gui/dialogs/AccountSelectDialog.cpp b/gui/dialogs/AccountSelectDialog.cpp
index b8fa9e42..ec2f09be 100644
--- a/gui/dialogs/AccountSelectDialog.cpp
+++ b/gui/dialogs/AccountSelectDialog.cpp
@@ -20,8 +20,6 @@
#include <logger/QsLog.h>
-#include <logic/auth/flows/AuthenticateTask.h>
-
#include <gui/dialogs/ProgressDialog.h>
#include <MultiMC.h>
diff --git a/gui/dialogs/ProgressDialog.cpp b/gui/dialogs/ProgressDialog.cpp
index ca433dab..ba14cca2 100644
--- a/gui/dialogs/ProgressDialog.cpp
+++ b/gui/dialogs/ProgressDialog.cpp
@@ -25,9 +25,23 @@ ProgressDialog::ProgressDialog(QWidget *parent) : QDialog(parent), ui(new Ui::Pr
{
MultiMCPlatform::fixWM_CLASS(this);
ui->setupUi(this);
+ this->setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint);
+ setSkipButton(false);
+ changeProgress(0, 100);
+}
+
+void ProgressDialog::setSkipButton(bool present, QString label)
+{
+ ui->skipButton->setEnabled(present);
+ ui->skipButton->setVisible(present);
+ ui->skipButton->setText(label);
updateSize();
+}
- changeProgress(0, 100);
+void ProgressDialog::on_skipButton_clicked(bool checked)
+{
+ Q_UNUSED(checked);
+ task->abort();
}
ProgressDialog::~ProgressDialog()
@@ -51,9 +65,13 @@ int ProgressDialog::exec(ProgressProvider *task)
connect(task, SIGNAL(status(QString)), SLOT(changeStatus(const QString &)));
connect(task, SIGNAL(progress(qint64, qint64)), SLOT(changeProgress(qint64, qint64)));
- // this makes sure that the task is started after the dialog is created
- QMetaObject::invokeMethod(task, "start", Qt::QueuedConnection);
- return QDialog::exec();
+ // if this didn't connect to an already running task, invoke start
+ if(!task->isRunning())
+ task->start();
+ if(task->isRunning())
+ return QDialog::exec();
+ else
+ return 0;
}
ProgressProvider *ProgressDialog::getTask()
diff --git a/gui/dialogs/ProgressDialog.h b/gui/dialogs/ProgressDialog.h
index 0029d3ec..fe63a826 100644
--- a/gui/dialogs/ProgressDialog.h
+++ b/gui/dialogs/ProgressDialog.h
@@ -35,6 +35,7 @@ public:
void updateSize();
int exec(ProgressProvider *task);
+ void setSkipButton(bool present, QString label = QString());
ProgressProvider *getTask();
@@ -47,7 +48,10 @@ slots:
void changeStatus(const QString &status);
void changeProgress(qint64 current, qint64 total);
-signals:
+
+private
+slots:
+ void on_skipButton_clicked(bool checked);
protected:
virtual void keyPressEvent(QKeyEvent *e);
diff --git a/gui/dialogs/ProgressDialog.ui b/gui/dialogs/ProgressDialog.ui
index a56d2a92..04b8fef3 100644
--- a/gui/dialogs/ProgressDialog.ui
+++ b/gui/dialogs/ProgressDialog.ui
@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>400</width>
- <height>68</height>
+ <height>100</height>
</rect>
</property>
<property name="minimumSize">
@@ -25,8 +25,8 @@
<property name="windowTitle">
<string>Please wait...</string>
</property>
- <layout class="QVBoxLayout" name="verticalLayout">
- <item>
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="0">
<widget class="QLabel" name="statusLabel">
<property name="text">
<string>Task Status...</string>
@@ -36,7 +36,7 @@
</property>
</widget>
</item>
- <item>
+ <item row="1" column="0">
<widget class="QProgressBar" name="taskProgressBar">
<property name="value">
<number>24</number>
@@ -46,6 +46,19 @@
</property>
</widget>
</item>
+ <item row="2" column="0">
+ <widget class="QPushButton" name="skipButton">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>Skip</string>
+ </property>
+ </widget>
+ </item>
</layout>
</widget>
<resources/>